npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ai_ishop_engine

v5.1.1

Published

AI引擎

Readme

AI开单引擎

AI开单引擎是运行在前端的AI调用、业务处理引擎。需要依赖AI后端服务和前端运行环境提供基础信息(比如商品档案、客户、店仓、业务员、供应商等)。

运行环境

编译后支持兼容 es5 的浏览器、JS引擎。

开发环境 node 版本为 v16.18.0

调试运行

npm run dev

编译输出

npm run build

主要功能

调度AI开单功能。

使用简介

安装 npm 包

npm i ai_ishop_engine

使用示例

实例化AI引擎

import 'ai_ishop_engine'

// 实例化 ('xxx' 请替换为实际的参数值)
const engine = new AIBillEngine({
    cfg: {
        /** 解析模式:0 快速解析(默认),1 完整解析 */
        mode: 0,
        baseInfo_endPoint: 'https://xxx:8035/v775/',
        ai_endPoint: 'http://127.0.0.1:8080/ai/',
        httpHeaders: {
            'Accept': '*/*',

            /** PC端 */
            'client-src': 'pcweb',
            'esn': 'xxx',
            'token': 'xxx',
            /** PC端部署走网关时需要 */
            'Authorization': 'Bearer xxx',

            /** 移动端 */
            'version': 'V1.0',
            'appkey': 'xxx',
            'code': 'xxx',
            'timestamp': 1695370413,
            'esn': 'xxx',
            'clienttype': 'xxx',
            'ver': 'xxx',
            'apid': 'xxx',
            'clientver': 'xxx',
            'token': 'xxxx',
            'secret': 'xxx',
        },
        /** 是否是移动端使用,移动端必须设为 true, 默认 false */
        is_mobile_device: false,
        /** 是否允许退货,默认允许 */
        allow_return: false,
        /** 数量小数位数, 默认不处理 */
        qty_decimal_precision: 2,
        /** 金额小数位数, 默认不处理 */
        total_decimal_precision: 2,
    },
    // 其它参数
})

AI开单(旧方法)

旧方法只支持AI开销售单。保留仅为提供兼容支持。

// AI开单
const result = await engine.sellAdd('小明:你好老板,来一手加绒卫衣,送到成都。从1店发货。')
console.log(result)

// AI开单 - OCR图像识别
const result = await engine.sellAdd_OCR([{fileName: '666.jpg', imageUrl: 'https://xxx/xxx.jpg'}])
console.log(result)

// AI开单 - OCR图像识别 - 多图开一单
const images = [{fileName: '1.jpg', imageUrl: 'http.../x.jpg'},{fileName: '2.jpg', imageUrl: 'http.../x.jpg'}]
const result = await engine.sellAdd_OCR({list: images, flag: 0 })
console.log(result)

// AI开单 - OCR图像识别 - 多图开多单
const result = await engine.sellAdd_OCR({list: images, flag: 1 })
console.log(result)

// AI开单 - 语音开单
const result = await engine.sellAdd_Audio('语音消息', 'http://图像URL地址')
console.log(result)

AI开单(新)

新的AI开单支持更多单据。引擎方法具体调用方式如下。

  • AI开单支持的单据类型 (AIBillType 枚举类型)
/** AI开单类型 */
export enum AIBillType {
  /** 新增销售单(默认) */
  ai_sell_add = 0,
  /** 新增销售订单 */
  ai_sell_order = 1,
  /** 新增销售退货单 */
  ai_sell_order_return = 2,
  /** 新增进货单 */
  ai_purchase_add = 3,
  /** 新增进货订单 */
  ai_purchase_order = 4,
  /** 新增进货退货单 */
  ai_purchase_order_return = 5,
  /** 其他入库单 */
  ai_stock_other_instock = 10,
  /** 其他出库单 */
  ai_stock_other_outstock=11,
  /** 库存调整单*/
  ai_stock_adjustment = 12,
  /** 成本调整单 */
  ai_cost_adjustment = 13,
  /** 拆装单 */
  ai_tear_pack = 14,
  /** 移仓单 */
  ai_move_depot = 15,
  /** 收款单 */
  ai_collection = 16,
  /** 预收款单 */
  ai_ready_collection = 17,
  /** 付款单 */
  ai_payment = 18,
  /** 预付款单 */
  ai_ready_payment=19,
  /** 账户转款单 */
  ai_account_transfer = 20,
  /** 账户调整单 */
  ai_account_adjustment = 21,
  /** 会计凭证 */
  ai_account_vouchers = 22,
  /** 其他费用单 */
  ai_other_cost = 23,
  /** 其他收入单 */
  ai_other_income = 24,
  /** 固定资产购入单 */
  ai_fix_purchase = 25,
  /** 固定资产变卖单 */
  ai_fix_selling=26,
  /** 固定资产折旧单 */
  ai_fix_depreciation = 27
}
  • 参数说明:
    /**
     * 清理缓存,用于环境变化(如切换账号、基础档案变更、商品规格变更后)
     */
    static clearCache(): void;
    /**
     * AI 开单
     * @param type 开单类型 (枚举值 AIBillType )
     * @param msg 对话消息内容
     * @param billType 单据类型
     * @param cancelFlag 取消标识
     * @returns
     */
    bill(type: AIBillType, msg: string, billType?: string, cancelFlag?: string | number): Promise<any>;
    /**
     * AI 开单 - OCR 识别
     * @param type 开单类型 (枚举值 AIBillType )
     * @param imgs 图像列表数组 或 对象 { `list`: 图像列表数组; `flag`: 开单类型 `0` 多个图开一张单; `1` 多个图开多个单; `handWrite` 是否图像手写体识别(默认`false`) }
     * @param billType 单据类型
     * @param cancelFlag 取消标识
     * @returns
     */
    bill_OCR(type: AIBillType, imgs: {
        fileName: string;
        imageUrl: string;
    }[] | {
        list: {
            fileName: string;
            imageUrl: string;
        }[];
        flag?: number;
        handWrite?: boolean;
    }, billType?: string, cancelFlag?: string | number): Promise<any>;
    /**
     * AI 开单 - 语音开单
     * @param type 开单类型 (枚举值 AIBillType )
     * @param msg 语音识别后的文本消息
     * @param audioUrl 语音文件URL地址
     * @param billType 单据类型
     * @param cancelFlag 取消标识
     * @returns
     */
    bill_Audio(type: AIBillType, msg: string, audioUrl: string | undefined, billType?: string, cancelFlag?: string | number): Promise<any>;
    /**
     * 取消 AI 开单
     * @param type 开单类型 (枚举值 AIBillType )
     * @param cancelFlag 取消标记。如果未设置,只取消未设置取消标记的请求
     */
    cancelBill(type: AIBillType, cancelFlag?: string | number): void;
  • 示例:
// AI开单
const result = await engine.bill(AIBillType.ai_sell_add, '小明:你好老板,来一手男士卫衣。从1店发货。')
console.log(result)

// AI开单 - OCR图像识别
const result = await engine.bill_OCR(AIBillType.ai_sell_add, [{fileName: '666.jpg', imageUrl: 'https://xxx/xxx.jpg'}])
console.log(result)

// AI开单 - OCR图像识别 - 多图开一单
const images = [{fileName: '1.jpg', imageUrl: 'http.../x.jpg'},{fileName: '2.jpg', imageUrl: 'http.../x.jpg'}]
const result = await engine.bill_OCR(AIBillType.ai_sell_add, {list: images, flag: 0 })
console.log(result)

// AI开单 - OCR图像识别 - 多图开多单
const result = await engine.bill_OCR(AIBillType.ai_sell_add, {list: images, flag: 1 })
console.log(result)

// AI开单 - 语音开单
const result = await engine.bill_Audio(AIBillType.ai_sell_add, '语音消息', 'http://语音文件URL地址')
console.log(result)

// 取消 AI 开单
engine.cancelBill(AIBillType.ai_sell_add)

const cancelFlag = 'cancelFlag'
engine.cancelBill(AIBillType.ai_sell_add, cancelFlag)

其它

// 获取历史记录
const billType = '5'
const pageIndex = 1
const pageSize = 20
const searchKey = null
const msgList = await engine.getMsgLogList(billType, pageIndex, pageSize, searchKey)
console.log(msgList)

// 保存语料信息
const billData = JSON.stringify({})
await engine.saveCorpusData(billType, billData, result.log)

// 停止AI开单
engine.cancelSellAdd()

// 停止指定cancelFlag的AI开单
const cancelFlag = 'cancelFlag'
engine.sellAdd_OCR({list: images, flag: 1 }, billType, cancelFlag).then(result => console.log(result))
engine.cancelSellAdd(cancelFlag)

// 直接设置商品数据
const goodsData: GoodsItem[] = []
engine.setGoodsData(goodsData)

// 清理所有缓存
AIBillEngine.clearCache()
// 或
engine.clearCache()

// 直接设置基础档案数据
const customerData: CustomerItem[] = []
engine.setCustomerData(customerData)

const employeeData: EmployeeItem[] = []
engine.setEmployeeData(employeeData)

const supplierData: SupplierItem[] = []
engine.setSupplierData(supplierData)

const skuTypeData: SkuTypeItem[] = []
engine.setSkuTypeData(skuTypeData)

const storeData: StoreItem[] = []
engine.setSotreData(storeData)

const goodsData: GoodsItem[] = []
engine.setGoodsData(goodsData)

注意事项

  1. 在 flutter 项目中,使用 flutter_js 插件引擎加载时,由于此插件存在一个bug,会导致如 {"data": "a\"bc"} 丢失 \ ,变成 {"data": "a"bc"} 而不符合 JSON 规格无法正确解析。