@alipay/alipay-aipay 1.8.3 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/install.js +10 -2
- package/dist/index.js +6 -1
- package/dist/utils/file.js +11 -2
- package/dist/utils/profile.js +64 -0
- package/package.json +3 -3
- package/skill/SKILL.md +2 -0
- package/skill/VERSION +1 -1
- package/skill/references/integration/flow.md +1 -1
- package/skill/references/integration/modules/sandbox/alipay-sandbox-tool.md +2 -2
- package/skill/references/normal/alipay-cli-env.md +2 -2
- package/skill/references/normal/scripts/common.sh +6 -2
- package/skill/references/normal/scripts/onboarding_message_runner.mjs +80 -250
- package/skill/references/normal/scripts/profile.mjs +53 -0
- package/skill/references/normal/scripts/session_skill.mjs +17 -2
- package/skill/references/normal/self-update.md +2 -0
- package/skill/references/onboarding/flow.md +11 -11
- package/skill/references/onboarding/modules/product-sign.md +1 -1
- package/skill/references/onboarding/modules/scripts/mcc.sh +151 -290
- package/skill/references/runtime-entry.md +1 -1
- package/skill-pre/SKILL.md +2 -0
- package/skill-pre/VERSION +1 -1
- package/skill-pre/references/integration/flow.md +1 -1
- package/skill-pre/references/integration/modules/sandbox/alipay-sandbox-tool.md +2 -2
- package/skill-pre/references/normal/alipay-cli-env.md +2 -2
- package/skill-pre/references/normal/scripts/common.sh +6 -2
- package/skill-pre/references/normal/scripts/onboarding_message_runner.mjs +80 -250
- package/skill-pre/references/normal/scripts/profile.mjs +53 -0
- package/skill-pre/references/normal/scripts/session_skill.mjs +17 -2
- package/skill-pre/references/normal/self-update.md +2 -0
- package/skill-pre/references/onboarding/flow.md +11 -11
- package/skill-pre/references/onboarding/modules/product-sign.md +1 -1
- package/skill-pre/references/onboarding/modules/scripts/mcc.sh +151 -290
- package/skill-pre/references/runtime-entry.md +1 -1
|
@@ -82,7 +82,7 @@ node "<SKILL_DIR>/references/normal/scripts/runtime.mjs" telemetry resolve-sessi
|
|
|
82
82
|
|
|
83
83
|
每个登记 stage 动作前,Agent 回顾当前可见历史并得到 `HISTORY_COUNT`;只统计本 run `clarify_intent` 后的用户角色消息,无法可靠回顾时使用 `null`。调用能生成 stage 的业务命令时追加 `--telemetry-run-id "$RUN_ID" --telemetry-history-count "$HISTORY_COUNT"`,由统一 gateway 在业务 parser 前剥离并传给唯一 stage 责任方,Agent 不再额外调用 `telemetry stage`。首次在产品/MCC 确认命令内部新建 run 时尚无 marker,该进程使用刚创建的 active run 且本次 history 固定为 0。`c4` 只承载 `user_input_after_clarify_intent`、`history_count`、`root_intent` 和按唯一非 summary event 数计算的 `progress_pct`;正式计数始终取 runtime counter,history 只诊断、不纠偏。
|
|
84
84
|
|
|
85
|
-
三种入口均只在无法确定产品时执行 `product-clarify` runner;产品明确但缺 MCC 用 `mcc-clarify`,且必须携带当前 `ROOT_INTENT`,由 runner 先创建或复用正式 telemetry run。已有经营描述、名称或编码时只执行 `node "<SKILL_DIR>/references/normal/scripts/runtime.mjs" mcc resolve-plan --query "$MCC_SEARCH_QUERY" --product-type "$PRODUCT_TYPE" --root-intent "$ROOT_INTENT" [--
|
|
85
|
+
三种入口均只在无法确定产品时执行 `product-clarify` runner;产品明确但缺 MCC 用 `mcc-clarify`,且必须携带当前 `ROOT_INTENT`,由 runner 先创建或复用正式 telemetry run。已有经营描述、名称或编码时只执行 `node "<SKILL_DIR>/references/normal/scripts/runtime.mjs" mcc resolve-plan --query "$MCC_SEARCH_QUERY" --product-type "$PRODUCT_TYPE" --root-intent "$ROOT_INTENT" [--agent-candidate-refs-json "$MCC_AGENT_CANDIDATE_REFS_JSON"] --input-id "$USER_INPUT_ID" --agent-platform "<AGENT_PLATFORM>" --session-id "<SESSION_ID>"`。`ROOT_INTENT` 缺失或非法时 runner 必须停止,禁止依赖跨进程环境变量静默推断或在没有正式 run 的情况下继续 MCC 查询。合法 MCC 编码和规范化后的完整二级类目名称由 runner 直接匹配;其他自然语言只在同一次 `queryMcc` 返回的当前产品完整目录上触发一次受限 Agent 判断,Agent 根据用户完整原话返回按相关度排序的 0 到 8 个稳定目录引用。用户明确说明的行业、商品、服务对象、经营方式和场景必须作为约束;未说明的细分维度保持开放。非法结果只允许一次协议修复,修复不得重新解释用户意图;第二次非法、重复判断、结果变更、同一 `USER_INPUT_ID` 改写 query、动态目录变化或状态不可安全记录时立即停止,不回退字符匹配、不再次调用 Agent,也不进入授权或签约。首次合法结果与同一 `run + 产品 + USER_INPUT_ID + 原始 query + 动态目录摘要` 绑定;网络恢复时只允许同一结果幂等重放。目录判断和修复不新增 MCP、网络调用或用户确认。禁止业务词到 MCC 的硬编码映射、自由提交 MCC code、远程语义或手拼候选。runner 只为最终候选中 `needSpecialQual=true` 的 MCC 调用一次 `batchQueryMcc`,并复用有效的同 run/产品候选快照。
|
|
86
86
|
|
|
87
87
|
代码开发或完整接入缺项目位置/服务端语言时,使用 `integration.context.required` 或 `integration.project_path.required` 标准消息;框架缺失不触发补问。先区分新建/复用,`PROJECT_INPUT` 保留原话。Agent 确定两类项目的真实 `PROJECT_PATH`,以 `resolve-project --project-path "$PROJECT_PATH" --intent <existing|new>` 交 runner 校验;`PROJECT_INPUT` 不得代替路径。默认新建也先选安全路径并显式传入。现有项目位置未知时先定位候选;路径经 `resolve-project` 后再用 `framework-resolve`。补齐前不初始化、装依赖或改文件。
|
|
88
88
|
|
package/skill-pre/SKILL.md
CHANGED
|
@@ -32,6 +32,8 @@ powershell.exe -NoProfile -NonInteractive -File "<SKILL_DIR>/references/normal/s
|
|
|
32
32
|
|
|
33
33
|
本目录的 `references/normal/json/release-channel.json` 固定当前渠道;正式版为 `stable`,预发版为 `pre`。自更新只比较 npm latest 元数据中的本渠道 Skill 版本与本地 `VERSION`,不以 npm 包版本判断是否需要更新,不切换或扫描另一渠道。缺少合法渠道元数据时保留当前版本。 本地 beta 测试版本固定使用当前版本,不查询 npm、不自动升级或转正;常规版本只接收本渠道非 beta 版本。此判断由同一自更新命令完成,Agent 不自行判断或修改 VERSION。
|
|
34
34
|
|
|
35
|
+
用户主动执行公开 npm `install` 时,安装器在已安装 Skill 根目录创建或字段级合并与 `VERSION` 并列的 `PROFILE`;`chinfo` 显式传值时更新为该值,未传时更新为 `origin`,只有显式 `--vid <值>` 才新增或更新 `vid`,未传时保留已有 `vid`,其他已有扩展字段也保留。npm 包内的 `skill/`、`skill-pre/` 源目录不得预置 `PROFILE`。自更新、普通 `update`、内部 `install-current` 和 Windows 会话副本只原样迁移已有普通 `PROFILE`:原来有则保留全部 JSON 字段,原来没有则继续没有,禁止因内部使用 npm/npx 创建 `origin` 或修改 `vid`。
|
|
36
|
+
|
|
35
37
|
本次 Agent 对话首次使用 `alipay-aipay-pre` 时,先把本文件所在目录解析为规范化绝对路径 `<SKILL_DIR>`,记录一次性事实 `ALIPAY_AIPAY_PRE_SELF_UPDATE_CHECKED=true`,再执行以下单条命令。`<SKILL_DIR>` 是执行时替换的路径占位符;禁止用 shell 变量赋值、命令替换或依赖特定 shell:
|
|
36
38
|
|
|
37
39
|
```text
|
package/skill-pre/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.8.
|
|
1
|
+
1.8.4-pre
|
|
@@ -165,7 +165,7 @@ node "<SKILL_DIR>/references/normal/scripts/runtime.mjs" integration-message win
|
|
|
165
165
|
资料校验通过后必须建立适用的版本控制忽略和访问保护。该例外只适用于当前沙箱资料;生产环境应用私钥和密码禁止提供给 Agent。Agent 不得在回复、摘要或普通日志中复述收到的值;仅 AI 网页应用收款在本步骤 5 已校验后,允许登记沙箱摘要展示买家账号及两个密码,最终 summary 只展示这三项。
|
|
166
166
|
|
|
167
167
|
5. Unix/macOS/Linux 或 Windows READY 的 `ensure` 只依据同一目标项目的 `.alipay-sandbox.json` 当前事实分流:文件不存在时执行既有 `create`;文件存在或为符号链接时执行既有 `verify` 安全路径。已存在配置不得再次调用 `createAnonymousSandbox`、不得覆盖,也不得因为中断重来要求用户删除配置;无效、不安全或被 Git 跟踪时不得使用,脚本按待配置终态统一输出后继续代码开发。
|
|
168
|
-
6. 只有 Unix/macOS/Linux 或 Windows READY 创建分支会调用冻结的 `alipay-anonymous-sandbox.createAnonymousSandbox`、`{"request":{"appType":"PUBLICAPP"}}`、`PLATFORM`、`PLATFORM_ID`、`ALIPAYCLI_BIZ_INFO` 环境变量和 `result.content[0].text -> success -> data` 解包逻辑;`ALIPAYCLI_BIZ_INFO` 固定标识当前调用方 Skill
|
|
168
|
+
6. 只有 Unix/macOS/Linux 或 Windows READY 创建分支会调用冻结的 `alipay-anonymous-sandbox.createAnonymousSandbox`、`{"request":{"appType":"PUBLICAPP"}}`、`PLATFORM`、`PLATFORM_ID`、`ALIPAYCLI_BIZ_INFO` 环境变量和 `result.content[0].text -> success -> data` 解包逻辑;`ALIPAYCLI_BIZ_INFO` 固定标识当前调用方 Skill、当前生效版本、匿名 `skill_user_id` 及合法 `PROFILE` 中可选的 `chinfo`、`vid`,各字段缺少时分别省略且不回填,禁止传入 `PRODUCT`。Windows LEGACY/CODE_ONLY 不调用该方法或 `sandbox_config.sh`。
|
|
169
169
|
7. Unix/macOS/Linux 或 Windows READY 只接受以下互斥最终结果和一个临时恢复结果;待配置不算成功:
|
|
170
170
|
- `READY`:退出码为 0;唯一带 `ALIPAY_AIPAY_INTERNAL:` 前缀的 `SANDBOX_ENSURE_ACTION=CREATED|VERIFIED`、`SANDBOX_CONFIG_PATH=<同一目标项目绝对路径>/.alipay-sandbox.json` 和 `FLOW:SANDBOX_CONFIG_READY` 内部事实。
|
|
171
171
|
- `CREATE_PENDING`:退出码为 0;脚本 stdout 已渲染唯一 `sandbox.configuration.pending/CREATE` 正文,并产生唯一 `ALIPAY_AIPAY_INTERNAL:CUSTOMER_MESSAGE_DELIVERY_REQUIRED=sandbox.configuration.pending`;另有唯一带 `ALIPAY_AIPAY_INTERNAL:` 前缀的 `SANDBOX_PENDING_PATH=<同一目标项目绝对路径>/.alipay-sandbox.json` 和 `FLOW:SANDBOX_CONFIG_PENDING_CREATE` 内部事实;不得出现 READY 标记。
|
|
@@ -18,7 +18,7 @@ which alipay-cli 2>/dev/null && alipay-cli version
|
|
|
18
18
|
|
|
19
19
|
**重要:工具返回的 `data` 只是候选沙箱配置;必须先按 `sandbox-setup-guide.md` 完成字段完整性校验,校验通过后再写入正式本地配置文件。创建阶段不对客输出字段核对表、独立校验结论或沙箱环境摘要表;代码开发完成并通过配置后置校验后,才按该指南输出一张沙箱环境摘要表。该结果不代表沙箱支付测试通过。privateKey、publicKey 等密钥字段不得展开。**
|
|
20
20
|
|
|
21
|
-
`createAnonymousSandbox` 的 MCP 请求体只有业务入参 `request.appType`,当前固定为 `PUBLICAPP`。`PLATFORM`、`PLATFORM_ID` 和 `ALIPAYCLI_BIZ_INFO` 是 alipay-cli 上下文环境变量,禁止写入 `--data` 的 JSON。匿名沙箱创建不依赖本轮最终选择的支付产品,因此不得为了创建沙箱先编造或强行确认 `PRODUCT`。
|
|
21
|
+
`createAnonymousSandbox` 的 MCP 请求体只有业务入参 `request.appType`,当前固定为 `PUBLICAPP`。`PLATFORM`、`PLATFORM_ID` 和 `ALIPAYCLI_BIZ_INFO` 是 alipay-cli 上下文环境变量,禁止写入 `--data` 的 JSON。匿名沙箱创建不依赖本轮最终选择的支付产品,因此不得为了创建沙箱先编造或强行确认 `PRODUCT`。 下列命令展示无合法 `PROFILE.chinfo` 和 `PROFILE.vid` 的技能市场来源示例;存在合法值时 `common.sh` 会在同一 JSON 中分别追加 `"chinfo":"<来源>"` 和 `"vid":"<来源>"`。
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
24
|
PLATFORM="<PLATFORM>" \
|
|
@@ -41,7 +41,7 @@ alipay-cli mcp call alipay-anonymous-sandbox.createAnonymousSandbox \
|
|
|
41
41
|
|------|------|----------|
|
|
42
42
|
| `PLATFORM` | AI 编程工具识别结果 | 参考通用脚本 `../../../normal/scripts/detect_dev_tool.sh` 识别当前工具后使用其输出值;缺失时使用 `unknown`。例如 Codex 环境检测结果为 `codex` |
|
|
43
43
|
| `PLATFORM_ID` | 第三方项目 ID;缺失时为当前逻辑 `run_id` | 由 `sandbox_config.sh` 通过 `common.sh` 读取,遥测开启或关闭都不影响该值;第三方项目 ID 只用于项目维度,不能生成逻辑 `run_id`,缺失时才保持 `PLATFORM_ID <- run_id` fallback,且不阻断沙箱创建 |
|
|
44
|
-
| `ALIPAYCLI_BIZ_INFO` | 当前生效 Skill 的 `VERSION
|
|
44
|
+
| `ALIPAYCLI_BIZ_INFO` | 当前生效 Skill 的 `VERSION`、匿名机器哈希及可选来源字段 | 由 `common.sh` 动态生成 JSON:基础字段为 `{"skill":"alipay-aipay","skill_version":"v<当前 VERSION>","skill_user_id":"machine_<32位匿名机器哈希>"}`;Skill 根目录存在合法 `PROFILE.chinfo` 或 `PROFILE.vid` 时分别追加对应字段,任一字段缺少时仅省略该字段,且不以 `PLATFORM` 回填 `chinfo`。`skill_user_id` 复用 telemetry 的 `machineUserID`,极端环境无法取得合法 `machine_` 标识时省略该字段;禁止由 Agent 手写或沿用外部同名值 |
|
|
45
45
|
| `PRODUCT` | 不再传入 | 该 MCP 方法当前不需要产品上下文;不得把产品名写入 `--data` 或 CLI 环境变量 |
|
|
46
46
|
|
|
47
47
|
**Codex 环境示例:**
|
|
@@ -143,12 +143,12 @@ source ~/.bashrc # Linux/bash
|
|
|
143
143
|
|
|
144
144
|
> ⚠️ **强制规范:检测结果仅供内部使用,禁止向用户输出!**
|
|
145
145
|
|
|
146
|
-
AI 工具由 `scripts/detect_dev_tool.sh` 检测;`init_alipay_cli_context` 设置 `DEV_TOOL_NAME`、`PLATFORM`。`run_id` 在根意图与产品首次唯一确定时由 runtime 生成 UUID;同一组合的 active run 复用,组合变化或旧 run 已关闭时生成新 UUID,第三方项目 ID 不参与生成。`common.sh` 为业务 `PLATFORM_ID` 优先使用有效的第三方项目 ID(`COZE_PROJECT_ID`、`MEOO_PROJECT_ID` 或 MIAODA 的 `VITE_APP_ID`/`PLATFORM_ID`),缺失时回退当前 `run_id
|
|
146
|
+
AI 工具由 `scripts/detect_dev_tool.sh` 检测;`init_alipay_cli_context` 设置 `DEV_TOOL_NAME`、`PLATFORM`。`run_id` 在根意图与产品首次唯一确定时由 runtime 生成 UUID;同一组合的 active run 复用,组合变化或旧 run 已关闭时生成新 UUID,第三方项目 ID 不参与生成。`common.sh` 为业务 `PLATFORM_ID` 优先使用有效的第三方项目 ID(`COZE_PROJECT_ID`、`MEOO_PROJECT_ID` 或 MIAODA 的 `VITE_APP_ID`/`PLATFORM_ID`),缺失时回退当前 `run_id`;遥测开关不改变该回退规则。脚本从当前生效 Skill 的 `VERSION` 和同源 `machineUserID` 动态生成 `ALIPAYCLI_BIZ_INFO={"skill":"alipay-aipay","skill_version":"v<当前 VERSION>","skill_user_id":"machine_<32位匿名机器哈希>"}`;若 Skill 根目录存在普通、合法且不超过 64 KiB 的 `PROFILE`,并且其中 `schemaVersion=1`,则分别校验可选 `chinfo` 和 `vid` 是否为 1 至 128 个无首尾空白和控制字符的 Unicode 字符,并把各自合法值追加到同一 JSON。任一字段缺少或无效时仅省略该字段;`PROFILE` 无法解析时两者都省略,且不得用 `PLATFORM` 回填 `chinfo`;极端环境无法取得合法 `machine_` 标识时只省略 `skill_user_id`,不写 `anonymous_uid` 且不阻断业务调用。所有携带 `PLATFORM` 的 Skill 业务 CLI 调用均携带该 JSON,外部同名值会被覆盖;`alipay-cli version` 等不携带 `PLATFORM` 的安装和环境探测不注入该变量。产品确认后,Onboarding 还严格映射 `aipay|webpay|apppay` 为 `PRODUCT=AIPAY|WEBPAY|APPPAY`,其环境检查、登录、查询、写入和上传均携带该值,但 `PRODUCT` 和 `ALIPAYCLI_BIZ_INFO` 都不写入 MCP JSON;Integration 产品确定前的环境检查和快速沙箱不传 `PRODUCT`。
|
|
147
147
|
|
|
148
148
|
```
|
|
149
149
|
❌ 禁止:向用户输出"环境检查完成,检测到您正在使用 Claude Code 环境"等检测结果
|
|
150
150
|
❌ 禁止:向用户透出任何关于 AI 编程工具检测的信息
|
|
151
|
-
✅ 正确:检测结果仅供内部使用,只用于脚本设置 `PLATFORM`;`PLATFORM_ID` 优先使用有效第三方项目 ID,缺失时回退当前 `run_id`;`ALIPAYCLI_BIZ_INFO` 由当前 Skill
|
|
151
|
+
✅ 正确:检测结果仅供内部使用,只用于脚本设置 `PLATFORM`;`PLATFORM_ID` 优先使用有效第三方项目 ID,缺失时回退当前 `run_id`;`ALIPAYCLI_BIZ_INFO` 由当前 Skill 版本、匿名 `skill_user_id` 及可选 `PROFILE.chinfo`、`PROFILE.vid` 派生,各字段缺少时分别省略;Onboarding 的 `PRODUCT` 由已确认产品映射
|
|
152
152
|
✅ 正确:静默完成检测,直接进入下一步流程
|
|
153
153
|
```
|
|
154
154
|
|
|
@@ -265,10 +265,11 @@ init_platform_id() {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
init_alipay_cli_biz_info() {
|
|
268
|
-
local common_dir version_file version skill_user_id
|
|
268
|
+
local common_dir skill_dir version_file version skill_user_id profile_script merged
|
|
269
269
|
|
|
270
270
|
common_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
271
|
-
|
|
271
|
+
skill_dir="$(cd "${common_dir}/../../.." && pwd)"
|
|
272
|
+
version_file="${skill_dir}/VERSION"
|
|
272
273
|
if [ ! -f "$version_file" ]; then
|
|
273
274
|
echo "❌ 无法读取当前 alipay-aipay Skill 版本" >&2
|
|
274
275
|
return 1
|
|
@@ -281,11 +282,14 @@ init_alipay_cli_biz_info() {
|
|
|
281
282
|
fi
|
|
282
283
|
|
|
283
284
|
skill_user_id="$(machine_user_id_for_biz_info "$common_dir" || true)"
|
|
285
|
+
profile_script="${common_dir}/profile.mjs"
|
|
284
286
|
if [[ "$skill_user_id" =~ ^machine_[0-9a-f]{32}$ ]]; then
|
|
285
287
|
printf -v ALIPAYCLI_BIZ_INFO '{"skill":"alipay-aipay","skill_version":"v%s","skill_user_id":"%s"}' "$version" "$skill_user_id"
|
|
286
288
|
else
|
|
287
289
|
printf -v ALIPAYCLI_BIZ_INFO '{"skill":"alipay-aipay","skill_version":"v%s"}' "$version"
|
|
288
290
|
fi
|
|
291
|
+
merged="$(node "$profile_script" merge-biz-info --skill-dir "$skill_dir" --base-json "$ALIPAYCLI_BIZ_INFO" 2>/dev/null || true)"
|
|
292
|
+
if [ -n "$merged" ]; then ALIPAYCLI_BIZ_INFO="$merged"; fi
|
|
289
293
|
export ALIPAYCLI_BIZ_INFO
|
|
290
294
|
}
|
|
291
295
|
|
|
@@ -259,13 +259,6 @@ function assertMccQuery(query) {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
const mccSelectionReceiptPrefix = 'AIPAY_MCC_SELECTION_V1.';
|
|
262
|
-
const ignoredMccQueryTokens = new Set([
|
|
263
|
-
'服务', '企业', '个人', '提供', '适用', '用于', '平台', '项目', '申请', '商家', '公司',
|
|
264
|
-
'互联', '联网', '互联网', '在线', '用品', '收费', '缴费', '费用', '适用于', '经营',
|
|
265
|
-
'业务', '相关', '主体', '从事', '网站', '网页', '购买', '买票', '购票', '票务', '售票',
|
|
266
|
-
'预约', '预定', '退票', '支付', '付款', '收款', '下单', '订单', '交易', '销售', '售卖',
|
|
267
|
-
'商品', '产品'
|
|
268
|
-
]);
|
|
269
262
|
|
|
270
263
|
function activeMccRunId(env = process.env) {
|
|
271
264
|
const candidate = env.ALIPAY_AIPAY_RUN_ID
|
|
@@ -397,8 +390,10 @@ function mccCatalogForAgent(records) {
|
|
|
397
390
|
}
|
|
398
391
|
|
|
399
392
|
function parseAgentCandidateRefs(args, records) {
|
|
400
|
-
|
|
401
|
-
|
|
393
|
+
if (!Object.prototype.hasOwnProperty.call(args, 'agent-candidate-refs-json')) {
|
|
394
|
+
return { provided: false, codes: [] };
|
|
395
|
+
}
|
|
396
|
+
const raw = args['agent-candidate-refs-json'];
|
|
402
397
|
let parsed;
|
|
403
398
|
try {
|
|
404
399
|
parsed = JSON.parse(raw);
|
|
@@ -416,7 +411,7 @@ function parseAgentCandidateRefs(args, records) {
|
|
|
416
411
|
}
|
|
417
412
|
codes.push(refs.get(ref));
|
|
418
413
|
}
|
|
419
|
-
return { codes };
|
|
414
|
+
return { provided: true, codes };
|
|
420
415
|
}
|
|
421
416
|
|
|
422
417
|
function mccTableSummary(records) {
|
|
@@ -454,190 +449,12 @@ function directMccCode(query, records) {
|
|
|
454
449
|
return { isCode: true, matches: [...records.keys()].filter((code) => code.endsWith(`_${raw}`)) };
|
|
455
450
|
}
|
|
456
451
|
|
|
457
|
-
function
|
|
458
|
-
const grams = new Set();
|
|
459
|
-
const searchableText = meaningfulMccSearch(value);
|
|
460
|
-
for (const segment of searchableText.split(/\s+/u).filter(Boolean)) {
|
|
461
|
-
const characters = [...segment];
|
|
462
|
-
for (let index = 0; index <= characters.length - size; index += 1) {
|
|
463
|
-
const gram = characters.slice(index, index + size).join('');
|
|
464
|
-
if (/^[\p{L}\p{N}]+$/u.test(gram)) grams.add(gram);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return grams;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function meaningfulMccSearch(value) {
|
|
471
|
-
let searchableText = normalizeSearch(value);
|
|
472
|
-
const ignoredTerms = [...ignoredMccQueryTokens]
|
|
473
|
-
.sort((left, right) => [...right].length - [...left].length);
|
|
474
|
-
for (const term of ignoredTerms) searchableText = searchableText.replaceAll(term, ' ');
|
|
475
|
-
return searchableText
|
|
476
|
-
.trim()
|
|
477
|
-
.replace(/\s+/gu, ' ')
|
|
478
|
-
.split(' ')
|
|
479
|
-
.filter((segment) => [...segment].length >= 2)
|
|
480
|
-
.join(' ');
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function parseMccSemanticTerms(args) {
|
|
484
|
-
const raw = optional(args, 'semantic-terms-json');
|
|
485
|
-
if (raw === undefined) return [];
|
|
486
|
-
let parsed;
|
|
487
|
-
try {
|
|
488
|
-
parsed = JSON.parse(raw);
|
|
489
|
-
} catch {
|
|
490
|
-
throw new Error('semantic-terms-json 必须是合法 JSON 字符串数组');
|
|
491
|
-
}
|
|
492
|
-
if (!Array.isArray(parsed) || parsed.length > 12 || parsed.some((term) => typeof term !== 'string')) {
|
|
493
|
-
throw new Error('semantic-terms-json 必须是最多 12 项的 JSON 字符串数组');
|
|
494
|
-
}
|
|
495
|
-
const normalized = [];
|
|
496
|
-
let totalLength = 0;
|
|
497
|
-
for (const rawTerm of parsed) {
|
|
498
|
-
if (/\u0000|[\u0001-\u001f\u007f]/u.test(rawTerm)) {
|
|
499
|
-
throw new Error('semantic-terms-json 包含控制字符');
|
|
500
|
-
}
|
|
501
|
-
const term = normalizeSearch(rawTerm);
|
|
502
|
-
const termLength = [...term.replace(/\s+/gu, '')].length;
|
|
503
|
-
if (termLength < 2 || termLength > 40) {
|
|
504
|
-
throw new Error('semantic-terms-json 每项长度必须为 2 到 40 个字符');
|
|
505
|
-
}
|
|
506
|
-
if (/(?:A\d{4}\s*)?B\d{4}/iu.test(term)) {
|
|
507
|
-
throw new Error('semantic-terms-json 只能包含业务概念词,禁止提供 MCC 编码');
|
|
508
|
-
}
|
|
509
|
-
totalLength += termLength;
|
|
510
|
-
if (!normalized.includes(term)) normalized.push(term);
|
|
511
|
-
}
|
|
512
|
-
if (totalLength > 240) throw new Error('semantic-terms-json 总长度不得超过 240 个字符');
|
|
513
|
-
return normalized.sort((left, right) => (left < right ? -1 : left > right ? 1 : 0));
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
function mccDocumentFrequency(indexedRecords) {
|
|
517
|
-
const frequencies = new Map();
|
|
518
|
-
for (const indexed of indexedRecords) {
|
|
519
|
-
const documentGrams = new Set([
|
|
520
|
-
...indexed.nameBigrams,
|
|
521
|
-
...indexed.nameTrigrams,
|
|
522
|
-
...indexed.businessBigrams,
|
|
523
|
-
...indexed.businessTrigrams
|
|
524
|
-
]);
|
|
525
|
-
for (const gram of documentGrams) frequencies.set(gram, (frequencies.get(gram) || 0) + 1);
|
|
526
|
-
}
|
|
527
|
-
return frequencies;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function weightedMccOverlap(queryGrams, documentGrams, frequencies, recordCount, size) {
|
|
531
|
-
let weight = 0;
|
|
532
|
-
for (const gram of queryGrams) {
|
|
533
|
-
if (!documentGrams.has(gram)) continue;
|
|
534
|
-
const documentCount = frequencies.get(gram) || 0;
|
|
535
|
-
weight += (Math.log((recordCount + 1) / (documentCount + 1)) + 1) * (size === 3 ? 1.6 : 1);
|
|
536
|
-
}
|
|
537
|
-
return weight;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
function mccPhraseCoverage(haystackSegments, needleSegments) {
|
|
541
|
-
let coverage = 0;
|
|
542
|
-
for (const needle of needleSegments) {
|
|
543
|
-
if (ignoredMccQueryTokens.has(needle)) continue;
|
|
544
|
-
const needleLength = [...needle].length;
|
|
545
|
-
for (const haystack of haystackSegments) {
|
|
546
|
-
if (!haystack.includes(needle)) continue;
|
|
547
|
-
coverage = Math.max(coverage, needleLength / [...haystack].length);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return coverage;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function mccTextEvidence(value, indexed, frequencies, recordCount) {
|
|
554
|
-
const normalizedValue = normalizeSearch(value);
|
|
555
|
-
const valueSegments = meaningfulMccSearch(normalizedValue).split(' ').filter(Boolean);
|
|
556
|
-
const valueBigrams = mccNgrams(normalizedValue, 2);
|
|
557
|
-
const valueTrigrams = mccNgrams(normalizedValue, 3);
|
|
558
|
-
const exactName = indexed.name === normalizedValue
|
|
559
|
-
|| (normalizedValue.split(' ').length === 1 && indexed.nameSegments.includes(normalizedValue));
|
|
560
|
-
const nameContainsValueCoverage = mccPhraseCoverage(indexed.nameEvidenceSegments, valueSegments);
|
|
561
|
-
const valueContainsNameCoverage = mccPhraseCoverage(valueSegments, indexed.nameEvidenceSegments);
|
|
562
|
-
const businessContainsValueCoverage = mccPhraseCoverage(indexed.businessEvidenceSegments, valueSegments);
|
|
563
|
-
const nameBigram = weightedMccOverlap(valueBigrams, indexed.nameBigrams, frequencies, recordCount, 2);
|
|
564
|
-
const nameTrigram = weightedMccOverlap(valueTrigrams, indexed.nameTrigrams, frequencies, recordCount, 3);
|
|
565
|
-
const businessBigram = weightedMccOverlap(valueBigrams, indexed.businessBigrams, frequencies, recordCount, 2);
|
|
566
|
-
const businessTrigram = weightedMccOverlap(valueTrigrams, indexed.businessTrigrams, frequencies, recordCount, 3);
|
|
567
|
-
const matchedBigrams = new Set([
|
|
568
|
-
...[...valueBigrams].filter((gram) => indexed.nameBigrams.has(gram)),
|
|
569
|
-
...[...valueBigrams].filter((gram) => indexed.businessBigrams.has(gram))
|
|
570
|
-
]);
|
|
571
|
-
const matchedTrigrams = new Set([
|
|
572
|
-
...[...valueTrigrams].filter((gram) => indexed.nameTrigrams.has(gram)),
|
|
573
|
-
...[...valueTrigrams].filter((gram) => indexed.businessTrigrams.has(gram))
|
|
574
|
-
]);
|
|
575
|
-
const rareBigramDocumentLimit = Math.max(1, Math.ceil(recordCount * 0.02));
|
|
576
|
-
const hasRareBigram = [...matchedBigrams].some((gram) => (
|
|
577
|
-
(frequencies.get(gram) || recordCount) <= rareBigramDocumentLimit
|
|
578
|
-
));
|
|
579
|
-
const hasLexicalEvidence = matchedTrigrams.size > 0
|
|
580
|
-
|| matchedBigrams.size >= 2
|
|
581
|
-
|| (valueBigrams.size <= 2 && hasRareBigram);
|
|
582
|
-
const phraseEvidence = nameContainsValueCoverage > 0
|
|
583
|
-
|| valueContainsNameCoverage > 0
|
|
584
|
-
|| businessContainsValueCoverage > 0;
|
|
585
|
-
return {
|
|
586
|
-
eligible: exactName || phraseEvidence || hasLexicalEvidence,
|
|
587
|
-
exactName,
|
|
588
|
-
score: (exactName ? 100000 : 0)
|
|
589
|
-
+ (nameContainsValueCoverage * 6000)
|
|
590
|
-
+ (valueContainsNameCoverage * 3000)
|
|
591
|
-
+ (businessContainsValueCoverage * 2500)
|
|
592
|
-
+ ((nameBigram + nameTrigram) * 120)
|
|
593
|
-
+ ((businessBigram + businessTrigram) * 40)
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
function deterministicMccMatches(query, records, { limit = 8, semanticTerms = [] } = {}) {
|
|
452
|
+
function directMccName(query, records) {
|
|
598
453
|
const normalizedQuery = assertMccQuery(query);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
record,
|
|
604
|
-
name,
|
|
605
|
-
nameSegments: name.split(' ').filter(Boolean),
|
|
606
|
-
nameEvidenceSegments: meaningfulMccSearch(name).split(' ').filter(Boolean),
|
|
607
|
-
businessEvidenceSegments: meaningfulMccSearch(businesses).split(' ').filter(Boolean),
|
|
608
|
-
nameBigrams: mccNgrams(name, 2),
|
|
609
|
-
nameTrigrams: mccNgrams(name, 3),
|
|
610
|
-
businessBigrams: mccNgrams(businesses, 2),
|
|
611
|
-
businessTrigrams: mccNgrams(businesses, 3)
|
|
612
|
-
};
|
|
613
|
-
});
|
|
614
|
-
const frequencies = mccDocumentFrequency(indexedRecords);
|
|
615
|
-
const scored = [];
|
|
616
|
-
|
|
617
|
-
for (const indexed of indexedRecords) {
|
|
618
|
-
const originalEvidence = mccTextEvidence(normalizedQuery, indexed, frequencies, indexedRecords.length);
|
|
619
|
-
const semanticEvidence = semanticTerms
|
|
620
|
-
.map((term) => mccTextEvidence(term, indexed, frequencies, indexedRecords.length))
|
|
621
|
-
.filter((evidence) => evidence.eligible)
|
|
622
|
-
.sort((left, right) => right.score - left.score)[0];
|
|
623
|
-
if (!originalEvidence.eligible && !semanticEvidence) continue;
|
|
624
|
-
scored.push({
|
|
625
|
-
record: indexed.record,
|
|
626
|
-
score: originalEvidence.score + ((semanticEvidence?.score || 0) * 0.7),
|
|
627
|
-
exactName: originalEvidence.exactName,
|
|
628
|
-
originalEligible: originalEvidence.eligible,
|
|
629
|
-
semanticEligible: Boolean(semanticEvidence),
|
|
630
|
-
semanticExactName: Boolean(semanticEvidence?.exactName)
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
const exactMatches = scored.filter(({ exactName }) => exactName);
|
|
635
|
-
const ranked = exactMatches.length > 0
|
|
636
|
-
? exactMatches
|
|
637
|
-
: scored;
|
|
638
|
-
return ranked
|
|
639
|
-
.sort((left, right) => right.score - left.score || left.record.code.localeCompare(right.record.code))
|
|
640
|
-
.slice(0, limit);
|
|
454
|
+
return sortedMccRecords(records)
|
|
455
|
+
.filter((record) => normalizeSearch(record.name) === normalizedQuery)
|
|
456
|
+
.map((record) => record.code)
|
|
457
|
+
.slice(0, 8);
|
|
641
458
|
}
|
|
642
459
|
|
|
643
460
|
function createMccSelectionReceipt(productType, query, result, mccRunContext = captureMccRunContext()) {
|
|
@@ -647,7 +464,6 @@ function createMccSelectionReceipt(productType, query, result, mccRunContext = c
|
|
|
647
464
|
mccRunContext.runId,
|
|
648
465
|
productType,
|
|
649
466
|
assertMccQuery(query),
|
|
650
|
-
JSON.stringify(result.semanticTerms || []),
|
|
651
467
|
table.sha256,
|
|
652
468
|
table.recordCount,
|
|
653
469
|
codes
|
|
@@ -655,8 +471,8 @@ function createMccSelectionReceipt(productType, query, result, mccRunContext = c
|
|
|
655
471
|
return `${mccSelectionReceiptPrefix}${codes}.${createHash('sha256').update(binding).digest('base64url')}`;
|
|
656
472
|
}
|
|
657
473
|
|
|
658
|
-
function resolveMccSelection(productType, query, selectedInput, receipt, records,
|
|
659
|
-
const candidateCodes = mccSelectionReceiptCodes(productType, query, receipt, records,
|
|
474
|
+
function resolveMccSelection(productType, query, selectedInput, receipt, records, mccRunContext) {
|
|
475
|
+
const candidateCodes = mccSelectionReceiptCodes(productType, query, receipt, records, mccRunContext);
|
|
660
476
|
if (!candidateCodes) {
|
|
661
477
|
const semanticStatus = typeof receipt === 'string' && receipt.startsWith(mccSelectionReceiptPrefix)
|
|
662
478
|
? 'SELECTION_RECEIPT_STALE'
|
|
@@ -665,10 +481,8 @@ function resolveMccSelection(productType, query, selectedInput, receipt, records
|
|
|
665
481
|
query,
|
|
666
482
|
productType,
|
|
667
483
|
records,
|
|
668
|
-
semanticTerms,
|
|
669
484
|
semanticStatus,
|
|
670
|
-
mccRunContext
|
|
671
|
-
agentCandidateCodes
|
|
485
|
+
mccRunContext
|
|
672
486
|
);
|
|
673
487
|
return {
|
|
674
488
|
...refreshed,
|
|
@@ -685,8 +499,7 @@ function resolveMccSelection(productType, query, selectedInput, receipt, records
|
|
|
685
499
|
deterministicCandidateCodes: [],
|
|
686
500
|
deterministicStrongCandidateCodes: [],
|
|
687
501
|
deterministicWeakCandidateCodes: [],
|
|
688
|
-
|
|
689
|
-
semanticTerms,
|
|
502
|
+
agentCandidateCodes: [],
|
|
690
503
|
mergedCandidateCodes: candidateCodes,
|
|
691
504
|
mccTableSummary: currentTable,
|
|
692
505
|
candidates: candidateCodes.map((code) => mccCandidateFromRecord(records.get(code), productType, mccRunContext))
|
|
@@ -699,15 +512,14 @@ function resolveMccSelection(productType, query, selectedInput, receipt, records
|
|
|
699
512
|
deterministicCandidateCodes: [],
|
|
700
513
|
deterministicStrongCandidateCodes: [],
|
|
701
514
|
deterministicWeakCandidateCodes: [],
|
|
702
|
-
|
|
703
|
-
semanticTerms,
|
|
515
|
+
agentCandidateCodes: [],
|
|
704
516
|
mergedCandidateCodes: [selectedCode],
|
|
705
517
|
mccTableSummary: currentTable,
|
|
706
518
|
candidates: [candidate]
|
|
707
519
|
};
|
|
708
520
|
}
|
|
709
521
|
|
|
710
|
-
function mccSelectionReceiptCodes(productType, query, receipt, records,
|
|
522
|
+
function mccSelectionReceiptCodes(productType, query, receipt, records, mccRunContext = captureMccRunContext()) {
|
|
711
523
|
if (typeof receipt !== 'string' || !receipt.startsWith(mccSelectionReceiptPrefix)) return null;
|
|
712
524
|
const body = receipt.slice(mccSelectionReceiptPrefix.length);
|
|
713
525
|
const separator = body.lastIndexOf('.');
|
|
@@ -718,8 +530,7 @@ function mccSelectionReceiptCodes(productType, query, receipt, records, semantic
|
|
|
718
530
|
|| candidateCodes.some((code) => !records.has(code))
|
|
719
531
|
|| receipt !== createMccSelectionReceipt(productType, query, {
|
|
720
532
|
mergedCandidateCodes: candidateCodes,
|
|
721
|
-
mccTableSummary: currentTable
|
|
722
|
-
semanticTerms
|
|
533
|
+
mccTableSummary: currentTable
|
|
723
534
|
}, mccRunContext)) {
|
|
724
535
|
return null;
|
|
725
536
|
}
|
|
@@ -730,10 +541,9 @@ function resolveMccResultFromRecords(
|
|
|
730
541
|
query,
|
|
731
542
|
productType,
|
|
732
543
|
records,
|
|
733
|
-
semanticTerms = [],
|
|
734
544
|
semanticStatus,
|
|
735
545
|
mccRunContext = captureMccRunContext(),
|
|
736
|
-
|
|
546
|
+
agentReview = { provided: false, codes: [] }
|
|
737
547
|
) {
|
|
738
548
|
const directCode = directMccCode(query, records);
|
|
739
549
|
if (directCode.isCode) {
|
|
@@ -746,9 +556,7 @@ function resolveMccResultFromRecords(
|
|
|
746
556
|
deterministicCandidateCodes: [code],
|
|
747
557
|
deterministicStrongCandidateCodes: [code],
|
|
748
558
|
deterministicWeakCandidateCodes: [],
|
|
749
|
-
semanticCandidateCodes: [],
|
|
750
559
|
agentCandidateCodes: [],
|
|
751
|
-
semanticTerms,
|
|
752
560
|
mergedCandidateCodes: [code],
|
|
753
561
|
mccTableSummary: mccTableSummary(records),
|
|
754
562
|
candidates: [candidate]
|
|
@@ -761,52 +569,69 @@ function resolveMccResultFromRecords(
|
|
|
761
569
|
deterministicCandidateCodes: finalCodes,
|
|
762
570
|
deterministicStrongCandidateCodes: finalCodes,
|
|
763
571
|
deterministicWeakCandidateCodes: [],
|
|
764
|
-
semanticCandidateCodes: [],
|
|
765
572
|
agentCandidateCodes: [],
|
|
766
|
-
semanticTerms,
|
|
767
573
|
mergedCandidateCodes: finalCodes,
|
|
768
574
|
mccTableSummary: mccTableSummary(records),
|
|
769
575
|
candidates: finalCodes.map((code) => mccCandidateFromRecord(records.get(code), productType, mccRunContext))
|
|
770
576
|
};
|
|
771
577
|
}
|
|
772
578
|
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
579
|
+
const exactNameCodes = directMccName(query, records);
|
|
580
|
+
if (exactNameCodes.length > 0) {
|
|
581
|
+
const candidates = exactNameCodes.map((code) => mccCandidateFromRecord(records.get(code), productType, mccRunContext));
|
|
582
|
+
return {
|
|
583
|
+
matchType: candidates.length === 1 ? 'UNIQUE' : 'MULTIPLE',
|
|
584
|
+
semanticStatus: 'NOT_REQUIRED_EXACT_NAME',
|
|
585
|
+
deterministicCandidateCodes: exactNameCodes,
|
|
586
|
+
deterministicStrongCandidateCodes: exactNameCodes,
|
|
587
|
+
deterministicWeakCandidateCodes: [],
|
|
588
|
+
agentCandidateCodes: [],
|
|
589
|
+
mergedCandidateCodes: exactNameCodes,
|
|
590
|
+
mccTableSummary: mccTableSummary(records),
|
|
591
|
+
candidates
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (!agentReview.provided) {
|
|
596
|
+
return {
|
|
597
|
+
matchType: 'NONE',
|
|
598
|
+
semanticStatus: semanticStatus || 'AGENT_CATALOG_REVIEW_REQUIRED',
|
|
599
|
+
deterministicCandidateCodes: [],
|
|
600
|
+
deterministicStrongCandidateCodes: [],
|
|
601
|
+
deterministicWeakCandidateCodes: [],
|
|
602
|
+
agentCandidateCodes: [],
|
|
603
|
+
mergedCandidateCodes: [],
|
|
604
|
+
mccTableSummary: mccTableSummary(records),
|
|
605
|
+
candidates: [],
|
|
606
|
+
agentReview: {
|
|
607
|
+
required: true,
|
|
608
|
+
attempt: 1,
|
|
609
|
+
maxAttempts: 2,
|
|
610
|
+
reason: 'NATURAL_LANGUAGE_MATCH',
|
|
611
|
+
instructions: {
|
|
612
|
+
keepExplicitConstraints: true,
|
|
613
|
+
keepUnspecifiedDimensionsOpen: true,
|
|
614
|
+
excludeContradictions: true,
|
|
615
|
+
rankByRelevance: true,
|
|
616
|
+
maxCandidates: 8
|
|
617
|
+
},
|
|
618
|
+
catalog: mccCatalogForAgent(records)
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const finalCodes = agentReview.codes;
|
|
781
624
|
const candidates = finalCodes.map((code) => mccCandidateFromRecord(records.get(code), productType, mccRunContext));
|
|
782
|
-
const needsAgentReview = agentCandidateCodes.length === 0
|
|
783
|
-
&& (
|
|
784
|
-
matches.length === 0
|
|
785
|
-
|| deterministicCodes.length !== 1
|
|
786
|
-
|| (semanticTerms.length > 0 && deterministicCodes.length === 0 && !hasExactSemanticName)
|
|
787
|
-
);
|
|
788
625
|
return {
|
|
789
626
|
matchType: candidates.length === 1 ? 'UNIQUE' : candidates.length === 0 ? 'NONE' : 'MULTIPLE',
|
|
790
|
-
semanticStatus: semanticStatus
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
deterministicStrongCandidateCodes: deterministicCodes,
|
|
627
|
+
semanticStatus: semanticStatus || 'AGENT_CATALOG_REVIEW_USED',
|
|
628
|
+
deterministicCandidateCodes: [],
|
|
629
|
+
deterministicStrongCandidateCodes: [],
|
|
794
630
|
deterministicWeakCandidateCodes: [],
|
|
795
|
-
|
|
796
|
-
agentCandidateCodes,
|
|
797
|
-
semanticTerms,
|
|
631
|
+
agentCandidateCodes: finalCodes,
|
|
798
632
|
mergedCandidateCodes: finalCodes,
|
|
799
633
|
mccTableSummary: mccTableSummary(records),
|
|
800
|
-
candidates
|
|
801
|
-
...(needsAgentReview ? {
|
|
802
|
-
agentReview: {
|
|
803
|
-
required: true,
|
|
804
|
-
attempt: 1,
|
|
805
|
-
maxAttempts: 1,
|
|
806
|
-
reason: 'LOW_CONFIDENCE_LOCAL_MATCH',
|
|
807
|
-
catalog: mccCatalogForAgent(records)
|
|
808
|
-
}
|
|
809
|
-
} : {})
|
|
634
|
+
candidates
|
|
810
635
|
};
|
|
811
636
|
}
|
|
812
637
|
|
|
@@ -856,7 +681,9 @@ async function runMccResolvePlan(args) {
|
|
|
856
681
|
const selected = optional(args, 'select');
|
|
857
682
|
const selectionReceipt = optional(args, 'selection-receipt');
|
|
858
683
|
const selectionState = optional(args, 'selection-state');
|
|
859
|
-
|
|
684
|
+
if (args['semantic-terms-json'] !== undefined) {
|
|
685
|
+
throw new Error('mcc-resolve-plan 不再接受 --semantic-terms-json;自然语言只使用一次受限目录判断');
|
|
686
|
+
}
|
|
860
687
|
if ((selected === undefined) !== (selectionReceipt === undefined)) {
|
|
861
688
|
throw new Error('--select 与 --selection-receipt 必须同时提供');
|
|
862
689
|
}
|
|
@@ -872,8 +699,8 @@ async function runMccResolvePlan(args) {
|
|
|
872
699
|
const records = recordsForArgs(args);
|
|
873
700
|
const agentReview = parseAgentCandidateRefs(args, records);
|
|
874
701
|
let result = selected === undefined
|
|
875
|
-
? resolveMccResultFromRecords(query, productType, records,
|
|
876
|
-
: resolveMccSelection(productType, query, selected, selectionReceipt, records,
|
|
702
|
+
? resolveMccResultFromRecords(query, productType, records, undefined, mccRunContext, agentReview)
|
|
703
|
+
: resolveMccSelection(productType, query, selected, selectionReceipt, records, mccRunContext);
|
|
877
704
|
if (selectionState === 'STALE') {
|
|
878
705
|
result = {
|
|
879
706
|
...result,
|
|
@@ -910,14 +737,16 @@ async function runMccMatchCodes(args) {
|
|
|
910
737
|
}
|
|
911
738
|
await startTelemetryRun(rootIntent, productType);
|
|
912
739
|
const query = required(args, 'query');
|
|
913
|
-
|
|
740
|
+
if (args['semantic-terms-json'] !== undefined) {
|
|
741
|
+
throw new Error('mcc-match-codes 不再接受 --semantic-terms-json;自然语言只使用一次受限目录判断');
|
|
742
|
+
}
|
|
914
743
|
if (args['agent-mcc-status'] !== undefined || args['agent-mcc-codes'] !== undefined) {
|
|
915
744
|
throw new Error('mcc-match-codes 不接受 --agent-mcc-status 或 --agent-mcc-codes;MCC 匹配只使用本轮动态 catalog');
|
|
916
745
|
}
|
|
917
746
|
const records = recordsForArgs(args);
|
|
918
747
|
const agentReview = parseAgentCandidateRefs(args, records);
|
|
919
748
|
const mccRunContext = captureMccRunContext();
|
|
920
|
-
const result = resolveMccResultFromRecords(query, productType, records,
|
|
749
|
+
const result = resolveMccResultFromRecords(query, productType, records, undefined, mccRunContext, agentReview);
|
|
921
750
|
const { candidates: _internalCandidates, ...controlResult } = result;
|
|
922
751
|
process.stderr.write(`ALIPAY_AIPAY_INTERNAL:MCC_RESOLUTION=${JSON.stringify(controlResult)}\n`);
|
|
923
752
|
return '';
|
|
@@ -927,14 +756,15 @@ function runMccValidateSelectionCache(args) {
|
|
|
927
756
|
const productType = required(args, 'product-type');
|
|
928
757
|
productFor({ ...args, 'product-type': productType });
|
|
929
758
|
const records = recordsForArgs(args);
|
|
930
|
-
|
|
759
|
+
if (args['semantic-terms-json'] !== undefined) {
|
|
760
|
+
throw new Error('mcc-validate-selection-cache 不再接受 --semantic-terms-json');
|
|
761
|
+
}
|
|
931
762
|
const mccRunContext = captureMccRunContext();
|
|
932
763
|
if (!mccSelectionReceiptCodes(
|
|
933
764
|
productType,
|
|
934
765
|
required(args, 'query'),
|
|
935
766
|
required(args, 'selection-receipt'),
|
|
936
767
|
records,
|
|
937
|
-
semanticTerms,
|
|
938
768
|
mccRunContext
|
|
939
769
|
)) {
|
|
940
770
|
throw new Error('MCC 候选详情缓存与本轮选择回执不一致');
|