weaver-work-cli 0.1.49 → 0.1.52
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/README.md +1 -1
- package/dist/chunks/{attachment-content-MU2LPI5P.js → attachment-content-MBYYSQIX.js} +3 -3
- package/dist/chunks/{chunk-ZKEUGS2U.js → chunk-7UOXOGFL.js} +4 -4
- package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
- package/dist/chunks/{chunk-3NV2ETZR.js → chunk-D3TDNRFE.js} +8 -8
- package/dist/chunks/{chunk-6GWU63YF.js → chunk-DZOC77ZD.js} +1 -1
- package/dist/chunks/{chunk-K3BT54CU.js → chunk-IRMA3GVP.js} +1 -1
- package/dist/chunks/{chunk-3X7VOSBA.js → chunk-KLZ3ULQQ.js} +1 -1
- package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
- package/dist/chunks/{chunk-NBEWUR7L.js → chunk-LALWNK6M.js} +167 -44
- package/dist/chunks/{chunk-BRRW7CWA.js → chunk-LM2H7SZI.js} +26 -26
- package/dist/chunks/{chunk-KV5SOWMS.js → chunk-LTRLF6MM.js} +4 -4
- package/dist/chunks/{chunk-D2QRZUW4.js → chunk-RPRFIG6I.js} +35 -28
- package/dist/chunks/{chunk-GEOMANP7.js → chunk-RWFRZSIP.js} +2 -2
- package/dist/chunks/{chunk-EJVA5ZVB.js → chunk-ZRHKGQRQ.js} +2 -2
- package/dist/chunks/{conflict-6347A7YK.js → conflict-D2HYKBMH.js} +2 -2
- package/dist/chunks/{contract-N6P2HIIE.js → contract-MFOFMM2J.js} +4284 -254
- package/dist/chunks/{create-flow-7WG7LVX5.js → create-flow-7ZATJVTM.js} +6 -6
- package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
- package/dist/chunks/{env-LHRKSLG6.js → env-5DO4YENS.js} +2 -2
- package/dist/chunks/{factory-2H7Z4RWJ.js → factory-3M7D7WJC.js} +1 -1
- package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
- package/dist/chunks/{group-chat-EW6PNDDT.js → group-chat-B2HT5NEO.js} +3 -3
- package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
- package/dist/chunks/{invoice-FXWH5GPO.js → invoice-V7ZTITUO.js} +726 -206
- package/dist/chunks/{meeting-N2FQBHXI.js → meeting-HZOX3CBB.js} +10 -10
- package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
- package/dist/chunks/{reception-MYOKJULO.js → reception-QGPNTGHG.js} +98 -82
- package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
- package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
- package/dist/chunks/{registry-7VZ6YJUF.js → registry-KYPFFQIH.js} +1 -1
- package/dist/chunks/{registry-CKUVBS53.js → registry-SJHSBO5G.js} +10 -10
- package/dist/chunks/{room-recommend-MBCYENQ2.js → room-recommend-5AHR4YQV.js} +4 -4
- package/dist/chunks/{schedule-5IFMCXME.js → schedule-KZPJUPC2.js} +4 -4
- package/dist/chunks/smart-extract-IXHCZE4R.js +2846 -0
- package/dist/chunks/{workflow-2TRU2ZSP.js → workflow-UHKCZJMY.js} +1 -1
- package/dist/index.js +14 -9
- package/dist/shortcuts/contract/host.js +11 -0
- package/dist/shortcuts/contract/index.js +13 -0
- package/dist/shortcuts/contract/manifest.js +204 -0
- package/dist/shortcuts/contract/operations/card-action.js +585 -0
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +315 -0
- package/dist/shortcuts/contract/operations/card-plan.js +327 -0
- package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
- package/dist/shortcuts/contract/operations/elements-build.js +714 -0
- package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
- package/dist/shortcuts/contract/operations/first-screen.js +563 -0
- package/dist/shortcuts/contract/operations/flow.js +81 -25
- package/dist/shortcuts/contract/operations/modeltext.js +132 -0
- package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
- package/dist/shortcuts/contract/operations/performance.js +58 -7
- package/dist/shortcuts/contract/operations/quote.js +410 -22
- package/dist/shortcuts/contract/operations/registry.js +22 -0
- package/dist/shortcuts/contract/operations/review.js +73 -58
- package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
- package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
- package/dist/shortcuts/contract/operations/summary.js +4 -2
- package/dist/shortcuts/contract/operations/upload.js +48 -7
- package/dist/shortcuts/contract/prewarm-cache.js +90 -0
- package/dist/shortcuts/contract/prewarm.js +88 -0
- package/dist/shortcuts/contract/upload-cache.js +49 -4
- package/dist/shortcuts/data/index.js +1 -6
- package/dist/shortcuts/data/manifest.js +2 -2
- package/dist/shortcuts/data/operations/index.js +1 -1
- package/dist/shortcuts/data/operations/query.js +23 -46
- package/dist/shortcuts/fna/host.js +4 -2
- package/dist/shortcuts/fna/manifest.js +14 -5
- package/dist/shortcuts/fna/operations/audit.js +334 -0
- package/dist/shortcuts/fna/operations/registry.js +2 -0
- package/dist/shortcuts/im/operations/at-mention.js +6 -3
- package/dist/shortcuts/im/operations/msg-parse.js +35 -5
- package/dist/shortcuts/im/operations/msg-sync.js +3 -1
- package/dist/shortcuts/im/operations/msg-write.js +57 -9
- package/dist/shortcuts/index.js +5 -0
- package/dist/shortcuts/invoice/index.js +0 -12
- package/dist/shortcuts/invoice/manifest.js +201 -50
- package/dist/shortcuts/invoice/operations/registry.js +4 -2
- package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
- package/dist/shortcuts/invoice/operations/shared.js +3 -19
- package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
- package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
- package/dist/shortcuts/reception/constants.js +3 -7
- package/dist/shortcuts/reception/operations/leads.js +30 -6
- package/dist/shortcuts/reception/operations/panels.js +3 -2
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
- package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
- package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
- package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
- package/dist/shortcuts/recruit-stage/shared.js +5 -0
- package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
- package/dist/shortcuts/smart-extract/constants.js +79 -0
- package/dist/shortcuts/smart-extract/continuation.js +71 -0
- package/dist/shortcuts/smart-extract/errors.js +68 -0
- package/dist/shortcuts/smart-extract/host.js +191 -0
- package/dist/shortcuts/smart-extract/index.js +105 -0
- package/dist/shortcuts/smart-extract/ledger.js +70 -0
- package/dist/shortcuts/smart-extract/manifest.js +35 -0
- package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
- package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
- package/dist/shortcuts/smart-extract/operations/config.js +118 -0
- package/dist/shortcuts/smart-extract/operations/fill.js +489 -0
- package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
- package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
- package/dist/shortcuts/smart-extract/operations/save.js +355 -0
- package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
- package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
- package/dist/shortcuts/smart-extract/operations/target.js +167 -0
- package/dist/shortcuts/smart-extract/operations/types.js +22 -0
- package/dist/shortcuts/smart-extract/operations/validate.js +408 -0
- package/dist/shortcuts/workflow/operations/read.js +77 -15
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
- package/docs/SKILL.md +1 -1
- package/docs/_catalog.md +4 -1
- package/docs/agent-invoice.md +5 -7
- package/docs/data.md +5 -1
- package/docs/fna.md +24 -4
- package/docs/invoice.md +7 -5
- package/docs/smart-extract.md +156 -0
- package/package.json +1 -1
- package/skill-template/business-info.json +21 -1
- package/skill-template/domains/qiyecheng.md +6 -2
- package/skill-template/domains/smart-extract.md +16 -0
- package/skill-template/domains/yepiaotong.md +2 -2
- package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
- package/skills/weaver-e10-jinchengda/SKILL.md +159 -11
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +13 -8
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +5 -4
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +220 -0
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +68 -33
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +26 -15
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +90 -0
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +167 -5
- package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +200 -0
- package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +572 -0
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
- package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +560 -0
- package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +894 -0
- package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +93 -0
- package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
- package/skills/weaver-e10-qiyecheng/SKILL.md +58 -7
- package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +118 -0
- package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
- package/skills/weaver-e10-qiyecheng/references/catalog.md +42 -3
- package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
- package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
- package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
- package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
- package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +153 -40
- package/skills/weaver-e10-reception-flow/SKILL.md +43 -6
- package/skills/weaver-e10-reception-flow/references/guide.md +1 -1
- package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
- package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
- package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -40
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
- package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
- package/skills/weaver-e10-smart-extract/SKILL.md +169 -0
- package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
- package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
- package/skills/weaver-e10-smart-extract/references/troubleshooting.md +105 -0
- package/skills/weaver-e10-workflow/SKILL.md +2 -1
- package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
- package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
- package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
- package/skills/weaver-e10-yepiaotong/SKILL.md +53 -35
- package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
- package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
- package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
- package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
- package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +18 -53
- package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +96 -7
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +5 -38
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +14 -14
- package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
- package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +139 -94
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +131 -58
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
- package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
- package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
- package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
- package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
- package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
- package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
- package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
- package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
- package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { contractValidationError } from '../errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* 业绩核算六菜单 ebdf 列表组件卡生成器(本地,零依赖)。
|
|
6
|
+
*
|
|
7
|
+
* 迁移自 `scripts/render_ebdf_list_card.py`(2026-11-12 第二批)。
|
|
8
|
+
*
|
|
9
|
+
* 为什么固化:这六类列表以前用外部浏览器打开,用户拿不到 E10 列表组件;
|
|
10
|
+
* 改造成 ebdf 列表页组件卡后,pageId / 组件名极易抄错,因此全部固化,
|
|
11
|
+
* 模型不再手写卡片。
|
|
12
|
+
*
|
|
13
|
+
* 语义对齐:menu/pageId 解析、别名、origin 校验、comParams 键格式与
|
|
14
|
+
* 12 项自检全部与 Python 版一致。
|
|
15
|
+
*/
|
|
16
|
+
/** 菜单 → pageId(2026-11-10 用户确认,勿改)。用 Map 保持插入顺序,子串匹配依赖该顺序。 */
|
|
17
|
+
const MENU_PAGES = new Map([
|
|
18
|
+
['直销合同', '881124906081886244'],
|
|
19
|
+
['直销业绩', '846297265322576586'],
|
|
20
|
+
['合同收款', '846297265322576589'],
|
|
21
|
+
['项目验收', '846297265322576590'],
|
|
22
|
+
['渠道订单', '881210951456350225'],
|
|
23
|
+
['渠道订单-商务', '881211329321197671'],
|
|
24
|
+
]);
|
|
25
|
+
const ALIASES = new Map([
|
|
26
|
+
['e-cology合同', '直销合同'],
|
|
27
|
+
['e-cology 合同', '直销合同'],
|
|
28
|
+
['合同数据', '直销合同'],
|
|
29
|
+
['直销合同数据', '直销合同'],
|
|
30
|
+
['业绩', '直销业绩'],
|
|
31
|
+
['个人业绩', '直销业绩'],
|
|
32
|
+
['机构业绩', '直销业绩'],
|
|
33
|
+
['大区业绩', '直销业绩'],
|
|
34
|
+
['团队业绩', '直销业绩'],
|
|
35
|
+
['合同收款信息', '合同收款'],
|
|
36
|
+
['收款', '合同收款'],
|
|
37
|
+
['验收', '项目验收'],
|
|
38
|
+
['项目验收数据', '项目验收'],
|
|
39
|
+
['渠道订单数据', '渠道订单'],
|
|
40
|
+
['e-office合同', '渠道订单'],
|
|
41
|
+
['e-teams合同', '渠道订单'],
|
|
42
|
+
['渠道协议', '渠道订单-商务'],
|
|
43
|
+
['e-office协议订单', '渠道订单-商务'],
|
|
44
|
+
['商务渠道订单', '渠道订单-商务'],
|
|
45
|
+
['渠道订单商务', '渠道订单-商务'],
|
|
46
|
+
]);
|
|
47
|
+
const FIELD_KEY = /^field_\d+$/u;
|
|
48
|
+
const PAGE_ID = /^\d{6,}$/u;
|
|
49
|
+
const ORIGIN = /^https?:\/\/[^/]+$/u;
|
|
50
|
+
/** Python `str()` 的常见分支(comParams 值强制转字符串时使用)。 */
|
|
51
|
+
function pyStr(value) {
|
|
52
|
+
if (value === null || value === undefined)
|
|
53
|
+
return 'None';
|
|
54
|
+
if (value === true)
|
|
55
|
+
return 'True';
|
|
56
|
+
if (value === false)
|
|
57
|
+
return 'False';
|
|
58
|
+
if (typeof value === 'string')
|
|
59
|
+
return value;
|
|
60
|
+
if (typeof value === 'number')
|
|
61
|
+
return String(value);
|
|
62
|
+
if (Array.isArray(value))
|
|
63
|
+
return `[${value.map((item) => pyRepr(item)).join(', ')}]`;
|
|
64
|
+
if (typeof value === 'object') {
|
|
65
|
+
return `{${Object.entries(value)
|
|
66
|
+
.map(([key, val]) => `${pyRepr(key)}: ${pyRepr(val)}`)
|
|
67
|
+
.join(', ')}}`;
|
|
68
|
+
}
|
|
69
|
+
return String(value);
|
|
70
|
+
}
|
|
71
|
+
function pyRepr(value) {
|
|
72
|
+
return typeof value === 'string' ? `'${value}'` : pyStr(value);
|
|
73
|
+
}
|
|
74
|
+
/** Python `%r` 对字符串的呈现(错误信息里用)。 */
|
|
75
|
+
function pyReprText(value) {
|
|
76
|
+
return typeof value === 'string' ? `'${value}'` : pyStr(value);
|
|
77
|
+
}
|
|
78
|
+
/** Python `(raw or "").strip()`:非字符串的假值一律视为空串。 */
|
|
79
|
+
function stripOrEmpty(value) {
|
|
80
|
+
if (typeof value !== 'string') {
|
|
81
|
+
if (value === null || value === undefined || value === false || value === 0)
|
|
82
|
+
return '';
|
|
83
|
+
return String(value).trim();
|
|
84
|
+
}
|
|
85
|
+
return value.trim();
|
|
86
|
+
}
|
|
87
|
+
function resolveMenu(raw) {
|
|
88
|
+
const name = stripOrEmpty(raw);
|
|
89
|
+
if (MENU_PAGES.has(name)) {
|
|
90
|
+
return { menu: name, pageId: MENU_PAGES.get(name) };
|
|
91
|
+
}
|
|
92
|
+
if (ALIASES.has(name)) {
|
|
93
|
+
const real = ALIASES.get(name);
|
|
94
|
+
return { menu: real, pageId: MENU_PAGES.get(real) };
|
|
95
|
+
}
|
|
96
|
+
const hits = [];
|
|
97
|
+
for (const key of MENU_PAGES.keys()) {
|
|
98
|
+
if (name && (key.includes(name) || name.includes(key)))
|
|
99
|
+
hits.push(key);
|
|
100
|
+
}
|
|
101
|
+
if (hits.length === 1) {
|
|
102
|
+
return { menu: hits[0], pageId: MENU_PAGES.get(hits[0]) };
|
|
103
|
+
}
|
|
104
|
+
const options = [...MENU_PAGES.keys()].join('、');
|
|
105
|
+
throw contractValidationError('menu_unknown', `未知菜单 ${pyReprText(raw)},可选:${options}`);
|
|
106
|
+
}
|
|
107
|
+
function cleanOrigin(raw) {
|
|
108
|
+
const origin = stripOrEmpty(raw).replace(/\/+$/u, '');
|
|
109
|
+
if (!origin)
|
|
110
|
+
throw contractValidationError('origin_required', '缺少 origin');
|
|
111
|
+
if (origin.includes('{baseUrl}')) {
|
|
112
|
+
throw contractValidationError('origin_placeholder', 'origin 仍是占位符 {baseUrl}');
|
|
113
|
+
}
|
|
114
|
+
if (!ORIGIN.test(origin)) {
|
|
115
|
+
throw contractValidationError('origin_invalid', 'origin 只能是 scheme+host,不能带路径、query 或用户信息');
|
|
116
|
+
}
|
|
117
|
+
return origin;
|
|
118
|
+
}
|
|
119
|
+
function parseComParams(pairs, rawJson) {
|
|
120
|
+
const pairList = Array.isArray(pairs) ? pairs : [];
|
|
121
|
+
const jsonText = typeof rawJson === 'string' && rawJson.trim() ? rawJson : '';
|
|
122
|
+
if (pairList.length && jsonText) {
|
|
123
|
+
throw contractValidationError('com_params_conflict', 'comParamPairs 与 comParamsJson 只能二选一');
|
|
124
|
+
}
|
|
125
|
+
const merged = {};
|
|
126
|
+
if (jsonText) {
|
|
127
|
+
let parsed;
|
|
128
|
+
try {
|
|
129
|
+
parsed = JSON.parse(jsonText);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
133
|
+
throw contractValidationError('com_params_invalid', `comParamsJson 不是合法 JSON:${message}`);
|
|
134
|
+
}
|
|
135
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
136
|
+
throw contractValidationError('com_params_invalid', 'comParamsJson 必须是对象');
|
|
137
|
+
}
|
|
138
|
+
Object.assign(merged, parsed);
|
|
139
|
+
}
|
|
140
|
+
for (const item of pairList) {
|
|
141
|
+
const text = typeof item === 'string' ? item : pyStr(item);
|
|
142
|
+
const index = text.indexOf('=');
|
|
143
|
+
if (index < 0) {
|
|
144
|
+
throw contractValidationError('com_param_invalid', `comParamPairs 需要 key=value,收到 ${pyReprText(item)}`);
|
|
145
|
+
}
|
|
146
|
+
const key = text.slice(0, index).trim();
|
|
147
|
+
merged[key] = text.slice(index + 1);
|
|
148
|
+
}
|
|
149
|
+
const out = {};
|
|
150
|
+
for (const [key, value] of Object.entries(merged)) {
|
|
151
|
+
if (!FIELD_KEY.test(String(key))) {
|
|
152
|
+
throw contractValidationError('com_param_key_invalid', `条件键必须是 field_<字段id>,收到 ${pyReprText(key)}`);
|
|
153
|
+
}
|
|
154
|
+
out[String(key)] = typeof value === 'string' ? value : pyStr(value);
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
function pad2(value) {
|
|
159
|
+
return String(value).padStart(2, '0');
|
|
160
|
+
}
|
|
161
|
+
/** 等价 Python `datetime.now().strftime('%Y%m%d%H%M')`(本地时间)。 */
|
|
162
|
+
function stampNow() {
|
|
163
|
+
const now = new Date();
|
|
164
|
+
return `${now.getFullYear()}${pad2(now.getMonth() + 1)}${pad2(now.getDate())}`
|
|
165
|
+
+ `${pad2(now.getHours())}${pad2(now.getMinutes())}`;
|
|
166
|
+
}
|
|
167
|
+
function buildCard(pageId, origin, title, callId, comParams) {
|
|
168
|
+
const route = `/list/${pageId}`;
|
|
169
|
+
return {
|
|
170
|
+
version: 1,
|
|
171
|
+
callId,
|
|
172
|
+
toolId: 'fill_form',
|
|
173
|
+
arguments: {
|
|
174
|
+
type: 'e10',
|
|
175
|
+
title,
|
|
176
|
+
src: `${origin}/sp/ebdfpage/list/${pageId}`,
|
|
177
|
+
sdkRenderType: 'inline',
|
|
178
|
+
sdkOptions: {
|
|
179
|
+
compName: 'ui.CorsComponent',
|
|
180
|
+
routerType: 'MemoryRouter',
|
|
181
|
+
routerProps_pc: { initialEntries: [route] },
|
|
182
|
+
routerProps_mobile: { initialEntries: [route] },
|
|
183
|
+
params_pc: {
|
|
184
|
+
app: '@weapp/ebdfpage',
|
|
185
|
+
compName: 'TableViewList',
|
|
186
|
+
noMDialog: true,
|
|
187
|
+
},
|
|
188
|
+
params_mobile: {
|
|
189
|
+
app: '@weapp/ebdfpage',
|
|
190
|
+
compName: 'MTableViewList',
|
|
191
|
+
noMDialog: true,
|
|
192
|
+
},
|
|
193
|
+
params: {
|
|
194
|
+
pageId,
|
|
195
|
+
comParams,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** 按 validate 的 ebdf 分支逐项核对,返回问题列表(空数组即通过)。 */
|
|
202
|
+
function selfCheck(card, pageId) {
|
|
203
|
+
const bad = [];
|
|
204
|
+
const args = card.arguments ?? {};
|
|
205
|
+
const options = args.sdkOptions ?? {};
|
|
206
|
+
const pc = options.params_pc ?? {};
|
|
207
|
+
const mobile = options.params_mobile ?? {};
|
|
208
|
+
const params = options.params ?? {};
|
|
209
|
+
const routerPc = options.routerProps_pc ?? {};
|
|
210
|
+
const routerMobile = options.routerProps_mobile ?? {};
|
|
211
|
+
if (card.version !== 1)
|
|
212
|
+
bad.push('version != 1');
|
|
213
|
+
if (card.toolId !== 'fill_form')
|
|
214
|
+
bad.push('toolId != fill_form');
|
|
215
|
+
if (!card.callId)
|
|
216
|
+
bad.push('callId 为空');
|
|
217
|
+
if (args.type !== 'e10')
|
|
218
|
+
bad.push('arguments.type != e10');
|
|
219
|
+
if (args.sdkRenderType !== 'inline')
|
|
220
|
+
bad.push('sdkRenderType != inline');
|
|
221
|
+
if ('width' in args)
|
|
222
|
+
bad.push('ebdf 列表卡不应带 arguments.width');
|
|
223
|
+
if (!String(args.src ?? '').endsWith(`/sp/ebdfpage/list/${pageId}`))
|
|
224
|
+
bad.push('src 与 pageId 不一致');
|
|
225
|
+
if (options.compName !== 'ui.CorsComponent')
|
|
226
|
+
bad.push('sdkOptions.compName != ui.CorsComponent');
|
|
227
|
+
if (options.routerType !== 'MemoryRouter')
|
|
228
|
+
bad.push('routerType != MemoryRouter');
|
|
229
|
+
if (pc.app !== '@weapp/ebdfpage' || pc.compName !== 'TableViewList')
|
|
230
|
+
bad.push('params_pc 组件不对');
|
|
231
|
+
if (mobile.app !== '@weapp/ebdfpage' || mobile.compName !== 'MTableViewList')
|
|
232
|
+
bad.push('params_mobile 组件不对');
|
|
233
|
+
if (pc.noMDialog !== true || mobile.noMDialog !== true)
|
|
234
|
+
bad.push('noMDialog 未同时为 true');
|
|
235
|
+
if (params.pageId !== pageId)
|
|
236
|
+
bad.push('params.pageId 与 pageId 不一致');
|
|
237
|
+
const want = [`/list/${pageId}`];
|
|
238
|
+
if (JSON.stringify(routerPc.initialEntries) !== JSON.stringify(want)
|
|
239
|
+
|| JSON.stringify(routerMobile.initialEntries) !== JSON.stringify(want)) {
|
|
240
|
+
bad.push('initialEntries 与 pageId 不一致');
|
|
241
|
+
}
|
|
242
|
+
const comParams = params.comParams;
|
|
243
|
+
if (!comParams || typeof comParams !== 'object' || Array.isArray(comParams)) {
|
|
244
|
+
bad.push('comParams 不是对象');
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
for (const [key, value] of Object.entries(comParams)) {
|
|
248
|
+
if (!FIELD_KEY.test(key))
|
|
249
|
+
bad.push(`comParams 键格式错误:${pyReprText(key)}`);
|
|
250
|
+
if (typeof value !== 'string')
|
|
251
|
+
bad.push(`comParams 值不是字符串:${pyReprText(key)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return bad;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 生成 ebdf 列表组件卡。
|
|
258
|
+
*
|
|
259
|
+
* 注意:returned `card` 可直接作为 `<browsertool>` 内的 JSON 使用;
|
|
260
|
+
* `selfCheck` 非空表示结构不达标,禁止交付。
|
|
261
|
+
*/
|
|
262
|
+
export const contractCardEbdfListOperation = {
|
|
263
|
+
name: 'contract.card.ebdf-list',
|
|
264
|
+
async execute(input) {
|
|
265
|
+
const rawPageId = stripOrEmpty(input.pageId);
|
|
266
|
+
let menu;
|
|
267
|
+
let pageId;
|
|
268
|
+
if (rawPageId) {
|
|
269
|
+
if (!PAGE_ID.test(rawPageId)) {
|
|
270
|
+
throw contractValidationError('page_id_invalid', `pageId 必须是数字串,收到 ${pyReprText(rawPageId)}`);
|
|
271
|
+
}
|
|
272
|
+
pageId = rawPageId;
|
|
273
|
+
const menuInput = stripOrEmpty(input.menu);
|
|
274
|
+
menu = menuInput || pageId;
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const resolved = resolveMenu(input.menu);
|
|
278
|
+
menu = resolved.menu;
|
|
279
|
+
pageId = resolved.pageId;
|
|
280
|
+
}
|
|
281
|
+
const origin = cleanOrigin(input.origin);
|
|
282
|
+
const comParams = parseComParams(input.comParamPairs, input.comParamsJson);
|
|
283
|
+
const titleInput = stripOrEmpty(input.title);
|
|
284
|
+
const title = titleInput || menu;
|
|
285
|
+
if (!title)
|
|
286
|
+
throw contractValidationError('title_required', 'title 不能为空');
|
|
287
|
+
const callIdInput = stripOrEmpty(input.callId);
|
|
288
|
+
const callId = callIdInput || `ebdf-list-${menu}-${stampNow()}-01`;
|
|
289
|
+
const card = buildCard(pageId, origin, title, callId, comParams);
|
|
290
|
+
const problems = selfCheck(card, pageId);
|
|
291
|
+
if (problems.length) {
|
|
292
|
+
throw contractValidationError('self_check_failed', `ebdf 列表卡自检未通过:${problems.join(';')}`);
|
|
293
|
+
}
|
|
294
|
+
let output;
|
|
295
|
+
if (typeof input.out === 'string' && input.out.trim()) {
|
|
296
|
+
output = resolve(input.out.trim());
|
|
297
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
298
|
+
writeFileSync(output, `${JSON.stringify(card, null, 2)}\n`, 'utf8');
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
status: 'COMPLETE',
|
|
302
|
+
data: {
|
|
303
|
+
menu,
|
|
304
|
+
pageId,
|
|
305
|
+
callId,
|
|
306
|
+
comParams,
|
|
307
|
+
card,
|
|
308
|
+
selfCheck: problems,
|
|
309
|
+
...(output ? { output } : {}),
|
|
310
|
+
note: 'ebdf 列表卡不带 arguments.width;comParams 键必须是 field_<字段id>',
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
export const contractCardEbdfListOperations = [contractCardEbdfListOperation];
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { contractValidationError } from '../errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* 合同动作推荐引擎(本地,零依赖)。
|
|
6
|
+
*
|
|
7
|
+
* 迁移自 `scripts/plan_actions.py`(2026-11-12 第一批)。
|
|
8
|
+
* 原脚本把注册表、requires、抑制、排序、截断固化为可执行逻辑,
|
|
9
|
+
* 模型只提供上下文状态 JSON,不再自行推断卡片条数。
|
|
10
|
+
*
|
|
11
|
+
* 语义对齐要求:本实现与 Python 版**逐字段等价**,包括
|
|
12
|
+
* Python 的真值规则(`[]` / `{}` 为假)、`"set"` 判定(`0` 视为未设置)、
|
|
13
|
+
* 以及 `(-weight, id)` 的排序与 4 张卡片截断。
|
|
14
|
+
*/
|
|
15
|
+
const MAX_CARDS = 4;
|
|
16
|
+
const EMPTY_HINT = '按 contract-action-engine.md §7 空结果处理:不出卡片,说明缺什么与补法';
|
|
17
|
+
/** scene = doc(默认)时的动作域。 */
|
|
18
|
+
const ACTIONS = [
|
|
19
|
+
{
|
|
20
|
+
id: 'generate-contract',
|
|
21
|
+
title: '按报价单生成合同',
|
|
22
|
+
weight: 100,
|
|
23
|
+
walk: 'sendQuestion',
|
|
24
|
+
desc: '用真实模板把标的与金额填成合同 docx | 缺 .docx 模板 | 3~5 步 · 确认 1 次',
|
|
25
|
+
requires: { docType: ['quote', 'tender'] },
|
|
26
|
+
blocked: ['generatedDocx'],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'launch-flow',
|
|
30
|
+
title: '发起「{flowKey}」合同流程',
|
|
31
|
+
weight: 100,
|
|
32
|
+
walk: 'e10Sdk',
|
|
33
|
+
desc: '生成正式审批单并进入流转 | 证据齐 | 4~7 步 · 确认 2 次',
|
|
34
|
+
requires: { flowKey: 'set', hasFileId: true },
|
|
35
|
+
blocked: ['submitted'],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'review',
|
|
39
|
+
title: '合同预审',
|
|
40
|
+
weight: 92,
|
|
41
|
+
walk: 'sendQuestion',
|
|
42
|
+
desc: '发消息让 AI 出风险条款与修改建议 | 只读,不改原文',
|
|
43
|
+
requires: { hasFileId: true },
|
|
44
|
+
// 已经触发过审查(reviewStarted)就不再给「合同预审」,避免重复触发
|
|
45
|
+
blocked: ['reviewed', 'reviewStarted'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 'export-review',
|
|
49
|
+
title: '导出审查报告',
|
|
50
|
+
weight: 84,
|
|
51
|
+
walk: 'artifact',
|
|
52
|
+
desc: '查看风险条款、问题说明与建议修改 | 只读 | 点开即看',
|
|
53
|
+
// 只有「已拿到审查结果」才允许导出;reviewStarted 但无结果时不得出现
|
|
54
|
+
requires: { reviewed: true },
|
|
55
|
+
blocked: [],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'view-compare',
|
|
59
|
+
title: '查看比对详情',
|
|
60
|
+
weight: 82,
|
|
61
|
+
walk: 'e10Sdk',
|
|
62
|
+
desc: '左右对照看两版差异 | 只读,仅开页面',
|
|
63
|
+
requires: { compared: true },
|
|
64
|
+
blocked: [],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'view-review',
|
|
68
|
+
title: '查看审查详情',
|
|
69
|
+
weight: 80,
|
|
70
|
+
walk: 'e10Sdk',
|
|
71
|
+
desc: '打开 AI 审查页看逐条判定与原文定位 | 只读,不改原文',
|
|
72
|
+
// 审查进行中(reviewStarted)与已出结果(reviewed)两种情况都要给:
|
|
73
|
+
// 前者是用户稍后回来看进度的唯一入口,后者可看逐条判定
|
|
74
|
+
requires: {},
|
|
75
|
+
any_of: [{ reviewed: true }, { reviewStarted: true }],
|
|
76
|
+
blocked: [],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'export-compare-report',
|
|
80
|
+
title: '生成比对报告',
|
|
81
|
+
weight: 78,
|
|
82
|
+
walk: 'artifact',
|
|
83
|
+
desc: '出四指标统计与差异清单 | 只读 | 点开即看',
|
|
84
|
+
requires: { compared: true },
|
|
85
|
+
blocked: [],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'credit',
|
|
89
|
+
title: '查对方资信',
|
|
90
|
+
weight: 72,
|
|
91
|
+
walk: 'e10Sdk',
|
|
92
|
+
desc: '看诉讼/被执行/工商变更 | 只开页面,只读',
|
|
93
|
+
requires: { hasCounterparty: true },
|
|
94
|
+
blocked: [],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'request-status',
|
|
98
|
+
title: '查这份合同的审批进度',
|
|
99
|
+
weight: 70,
|
|
100
|
+
walk: 'sendQuestion',
|
|
101
|
+
desc: '看当前节点与审批意见 | 只读 | 1~2 步',
|
|
102
|
+
requires: { submitted: true, requestId: 'set' },
|
|
103
|
+
blocked: [],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'compare',
|
|
107
|
+
title: '比对两份合同',
|
|
108
|
+
weight: 60,
|
|
109
|
+
walk: 'e10Sdk',
|
|
110
|
+
desc: '逐条比差异 | 需两份文件 | 2~3 步',
|
|
111
|
+
requires: { otherVersionAvailable: true },
|
|
112
|
+
blocked: ['compared'],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 'clause-rewrite',
|
|
116
|
+
title: '按建议改条款',
|
|
117
|
+
weight: 56,
|
|
118
|
+
walk: 'sendQuestion',
|
|
119
|
+
desc: '把建议条款写回合同 | 会改原文 | 需确认 2 次',
|
|
120
|
+
requires: { reviewed: true },
|
|
121
|
+
blocked: [],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'summary',
|
|
125
|
+
title: '查看合同摘要',
|
|
126
|
+
weight: 28,
|
|
127
|
+
walk: 'artifact',
|
|
128
|
+
desc: '要素、标的与关键条款 | 只读 | 点开即看',
|
|
129
|
+
requires: { summaryReady: true },
|
|
130
|
+
blocked: [],
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
/** scene ≠ doc 时的动作域(query / config 不处理合同文件)。 */
|
|
134
|
+
const QUERY_ACTIONS = [
|
|
135
|
+
{
|
|
136
|
+
id: 'query-contracts',
|
|
137
|
+
title: '查我负责的合同',
|
|
138
|
+
weight: 100,
|
|
139
|
+
walk: 'sendQuestion',
|
|
140
|
+
desc: '按负责人查合同列表 | 只读',
|
|
141
|
+
requires: {},
|
|
142
|
+
blocked: [],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
id: 'query-performance',
|
|
146
|
+
title: '查直销业绩',
|
|
147
|
+
weight: 90,
|
|
148
|
+
walk: 'sendQuestion',
|
|
149
|
+
desc: '按期间汇总直销业绩 | 只读',
|
|
150
|
+
requires: {},
|
|
151
|
+
blocked: [],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'query-receipts',
|
|
155
|
+
title: '查合同收款',
|
|
156
|
+
weight: 80,
|
|
157
|
+
walk: 'sendQuestion',
|
|
158
|
+
desc: '按合同号查收款台账 | 只读',
|
|
159
|
+
requires: {},
|
|
160
|
+
blocked: [],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'query-channel',
|
|
164
|
+
title: '查渠道订单',
|
|
165
|
+
weight: 70,
|
|
166
|
+
walk: 'sendQuestion',
|
|
167
|
+
desc: '按渠道查订单 | 只读',
|
|
168
|
+
requires: {},
|
|
169
|
+
blocked: [],
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
/** Python 真值语义:None/False/0/""/[]/{} 均为假。 */
|
|
173
|
+
function pyTruthy(value) {
|
|
174
|
+
if (value === null || value === undefined || value === false)
|
|
175
|
+
return false;
|
|
176
|
+
if (value === true)
|
|
177
|
+
return true;
|
|
178
|
+
if (typeof value === 'number')
|
|
179
|
+
return value !== 0 && !Number.isNaN(value);
|
|
180
|
+
if (typeof value === 'string')
|
|
181
|
+
return value.length > 0;
|
|
182
|
+
if (Array.isArray(value))
|
|
183
|
+
return value.length > 0;
|
|
184
|
+
if (typeof value === 'object')
|
|
185
|
+
return Object.keys(value).length > 0;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
/** Python `==`:数字与布尔可互相相等(0 == False、1 == True)。 */
|
|
189
|
+
function pyEq(left, right) {
|
|
190
|
+
const toNum = (value) => {
|
|
191
|
+
if (typeof value === 'boolean')
|
|
192
|
+
return value ? 1 : 0;
|
|
193
|
+
if (typeof value === 'number')
|
|
194
|
+
return value;
|
|
195
|
+
return null;
|
|
196
|
+
};
|
|
197
|
+
const ln = toNum(left);
|
|
198
|
+
const rn = toNum(right);
|
|
199
|
+
if (ln !== null && rn !== null)
|
|
200
|
+
return ln === rn;
|
|
201
|
+
if (left === null || left === undefined)
|
|
202
|
+
return right === null || right === undefined;
|
|
203
|
+
return left === right;
|
|
204
|
+
}
|
|
205
|
+
function asText(value) {
|
|
206
|
+
if (value === null || value === undefined)
|
|
207
|
+
return '';
|
|
208
|
+
return String(value);
|
|
209
|
+
}
|
|
210
|
+
/** 单个条件组:全部为真才通过。 */
|
|
211
|
+
function matchOne(cond, ctx) {
|
|
212
|
+
for (const [key, expect] of Object.entries(cond)) {
|
|
213
|
+
const actual = ctx[key];
|
|
214
|
+
if (expect === 'set') {
|
|
215
|
+
// Python: actual in (None, "", False),其中 0 == False 也视为未设置
|
|
216
|
+
if (actual === null || actual === undefined || actual === '' || actual === false)
|
|
217
|
+
return false;
|
|
218
|
+
if (typeof actual === 'number' && actual === 0)
|
|
219
|
+
return false;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (Array.isArray(expect)) {
|
|
223
|
+
if (!expect.some((item) => pyEq(actual, item)))
|
|
224
|
+
return false;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (pyTruthy(actual) !== pyTruthy(expect))
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
/** requires 判定:requires 全真 且(无 any_of 或任一分支全真)。 */
|
|
233
|
+
function matches(action, ctx) {
|
|
234
|
+
if (!matchOne(action.requires ?? {}, ctx))
|
|
235
|
+
return false;
|
|
236
|
+
const anyOf = action.any_of;
|
|
237
|
+
if (anyOf && anyOf.length) {
|
|
238
|
+
if (!anyOf.some((cond) => matchOne(cond, ctx)))
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
/** 抑制判定:终态不回推、已完成不重复、本轮刚执行的不立刻回推。 */
|
|
244
|
+
function suppressed(action, ctx) {
|
|
245
|
+
for (const key of action.blocked ?? []) {
|
|
246
|
+
if (pyTruthy(ctx[key]))
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return ctx.lastAction === action.id;
|
|
250
|
+
}
|
|
251
|
+
export function planActions(ctx) {
|
|
252
|
+
const rawScene = ctx.scene;
|
|
253
|
+
const scene = pyTruthy(rawScene) ? String(rawScene) : 'doc';
|
|
254
|
+
const pool = scene === 'query' || scene === 'config' ? QUERY_ACTIONS : ACTIONS;
|
|
255
|
+
const scored = pool.filter((action) => matches(action, ctx) && !suppressed(action, ctx));
|
|
256
|
+
scored.sort((left, right) => {
|
|
257
|
+
if (right.weight !== left.weight)
|
|
258
|
+
return right.weight - left.weight;
|
|
259
|
+
if (left.id < right.id)
|
|
260
|
+
return -1;
|
|
261
|
+
if (left.id > right.id)
|
|
262
|
+
return 1;
|
|
263
|
+
return 0;
|
|
264
|
+
});
|
|
265
|
+
const picked = scored.slice(0, MAX_CARDS);
|
|
266
|
+
const flowKey = pyTruthy(ctx.flowKey) ? String(ctx.flowKey) : '';
|
|
267
|
+
const cards = picked.map((action) => ({
|
|
268
|
+
id: action.id,
|
|
269
|
+
title: action.title.split('{flowKey}').join(flowKey),
|
|
270
|
+
weight: action.weight,
|
|
271
|
+
walk: action.walk,
|
|
272
|
+
desc: action.desc,
|
|
273
|
+
}));
|
|
274
|
+
return {
|
|
275
|
+
scene,
|
|
276
|
+
count: cards.length,
|
|
277
|
+
title: `可做的 ${cards.length} 件事`,
|
|
278
|
+
cards,
|
|
279
|
+
dropped: scored.slice(MAX_CARDS).map((action) => action.id),
|
|
280
|
+
hint: cards.length ? '' : EMPTY_HINT,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function resolveContext(input) {
|
|
284
|
+
const direct = input.context;
|
|
285
|
+
if (direct && typeof direct === 'object' && !Array.isArray(direct)) {
|
|
286
|
+
return direct;
|
|
287
|
+
}
|
|
288
|
+
const file = typeof input.contextFile === 'string' && input.contextFile.trim() ? input.contextFile.trim() : '';
|
|
289
|
+
const inline = typeof input.contextJson === 'string' && input.contextJson.trim() ? input.contextJson.trim() : '';
|
|
290
|
+
if (!file && !inline) {
|
|
291
|
+
throw contractValidationError('context_required', '必须提供上下文:context(对象)、contextFile(JSON 文件路径)或 contextJson(JSON 字符串)三选一');
|
|
292
|
+
}
|
|
293
|
+
let raw;
|
|
294
|
+
if (file) {
|
|
295
|
+
try {
|
|
296
|
+
raw = readFileSync(resolve(file), 'utf8').replace(/^\uFEFF/u, '');
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
300
|
+
throw contractValidationError('context_unreadable', `无法读取上下文 JSON:${message}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
raw = inline;
|
|
305
|
+
}
|
|
306
|
+
let parsed;
|
|
307
|
+
try {
|
|
308
|
+
parsed = JSON.parse(raw);
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
312
|
+
throw contractValidationError('context_invalid', `上下文不是合法 JSON:${message}`);
|
|
313
|
+
}
|
|
314
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
315
|
+
throw contractValidationError('context_invalid', '上下文必须是 JSON 对象');
|
|
316
|
+
}
|
|
317
|
+
return parsed;
|
|
318
|
+
}
|
|
319
|
+
export const contractCardPlanOperation = {
|
|
320
|
+
name: 'contract.card.plan',
|
|
321
|
+
async execute(input) {
|
|
322
|
+
const ctx = resolveContext(input);
|
|
323
|
+
return { status: 'COMPLETE', data: planActions(ctx) };
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
export const contractCardPlanOperations = [contractCardPlanOperation];
|
|
327
|
+
export { asText };
|