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,585 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { Script } from 'node:vm';
|
|
4
|
+
import { contractValidationError } from '../errors.js';
|
|
5
|
+
import { planActions } from './card-plan.js';
|
|
6
|
+
/**
|
|
7
|
+
* 行为卡片渲染器(本地,零依赖)。
|
|
8
|
+
*
|
|
9
|
+
* 迁移自 `scripts/render_action_card.py`(2026-11-12 第三批)。
|
|
10
|
+
*
|
|
11
|
+
* 历史背景(保留,避免重复踩坑):此前模板只是「可照抄的样例」,卡片与 handler
|
|
12
|
+
* 全部写死,于是反复出现同一类偏差——sendQuestion 写成 plugin.sendQuestion、
|
|
13
|
+
* e10Sdk 漏 params.compName、只绑 click 无 hover、width 沿用旧值、
|
|
14
|
+
* 摘要内嵌时引号/换行/`</script>` 未转义导致整段脚本失效。
|
|
15
|
+
* 本 operation 把「算卡片 → 生成 HTML → 绑交互 → 组装外层 JSON → 自检」全部固化。
|
|
16
|
+
*
|
|
17
|
+
* 三处历史修复必须在迁移后保持:
|
|
18
|
+
* 1. `__W__` 必须在**拼完所有 handler 之后**统一替换,否则 handler 里的
|
|
19
|
+
* `width:__W__` 残留,点击抛 ReferenceError 被 try/catch 吞成「面板打开失败」;
|
|
20
|
+
* 2. 模板正文起点按「section 开标签含 id 属性」定位,不能用 `indexOf('<section')`,
|
|
21
|
+
* 注释里出现该字样会误命中,多出一个未闭合开标签;
|
|
22
|
+
* 3. `js_str` 的转义顺序不可调整(先处理 `</script>`,再归零双引号,最后转义反斜杠与单引号)。
|
|
23
|
+
*/
|
|
24
|
+
const DEFAULT_BASE = 'https://www.e-cology.com.cn';
|
|
25
|
+
const DEFAULT_AIID = '1326842382967570463';
|
|
26
|
+
const WIDTH = 1200;
|
|
27
|
+
/** flowKey → workflowId(与 contract-flow-launch.md 保持一致)。 */
|
|
28
|
+
const FLOW_IDS = new Map([
|
|
29
|
+
['契约锁', '100003460000002066'],
|
|
30
|
+
['新客户', '1269716062340284522'],
|
|
31
|
+
['老客户增值', '1283761429944369334'],
|
|
32
|
+
['常规二次销售', '1283761687634100307'],
|
|
33
|
+
]);
|
|
34
|
+
const SVG = {
|
|
35
|
+
launch: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M22 2 11 13'/><path d='M22 2 15 22l-4-9-9-4z'/></svg>",
|
|
36
|
+
doc: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z'/><path d='M14 3v5h5'/><path d='M9 13h6'/><path d='M9 17h4'/></svg>",
|
|
37
|
+
eye: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z'/><circle cx='12' cy='12' r='3'/></svg>",
|
|
38
|
+
search: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='M16.5 16.5 21 21'/></svg>",
|
|
39
|
+
list: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><rect x='4' y='3' width='16' height='18' rx='2'/><path d='M8 8h8'/><path d='M8 12h8'/><path d='M8 16h5'/></svg>",
|
|
40
|
+
swap: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M7 4v16'/><path d='M4 17l3 3 3-3'/><path d='M17 20V4'/><path d='M14 7l3-3 3 3'/></svg>",
|
|
41
|
+
edit: "<svg width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='#7b8cf0' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M12 20h9'/><path d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z'/></svg>",
|
|
42
|
+
};
|
|
43
|
+
/** action id → [dom 后缀, 图标, 走法] */
|
|
44
|
+
const ACTION_META = new Map([
|
|
45
|
+
['launch-flow', ['launch', 'launch', 'e10Sdk']],
|
|
46
|
+
['generate-contract', ['gen', 'doc', 'sendQuestion']],
|
|
47
|
+
['review', ['review', 'doc', 'sendQuestion']],
|
|
48
|
+
['export-review', ['report', 'list', 'artifact']],
|
|
49
|
+
['view-review', ['detail', 'eye', 'e10Sdk']],
|
|
50
|
+
['credit', ['credit', 'search', 'e10Sdk']],
|
|
51
|
+
['view-compare', ['cmpview', 'eye', 'e10Sdk']],
|
|
52
|
+
['export-compare-report', ['cmpreport', 'list', 'artifact']],
|
|
53
|
+
['compare', ['cmp', 'swap', 'sendQuestion']],
|
|
54
|
+
['clause-rewrite', ['rewrite', 'edit', 'sendQuestion']],
|
|
55
|
+
['request-status', ['status', 'search', 'sendQuestion']],
|
|
56
|
+
['summary', ['summary', 'list', 'artifact']],
|
|
57
|
+
['element-extract', ['extract', 'doc', 'sendQuestion']],
|
|
58
|
+
['supervise', ['supervise', 'launch', 'sendQuestion']],
|
|
59
|
+
['template-recommend', ['tpl', 'doc', 'sendQuestion']],
|
|
60
|
+
['performance', ['perf', 'list', 'sendQuestion']],
|
|
61
|
+
['retry-upload', ['retry', 'doc', 'sendQuestion']],
|
|
62
|
+
]);
|
|
63
|
+
/** 兜底 sendQuestion 指令。 */
|
|
64
|
+
const SEND_TEXT = new Map([
|
|
65
|
+
['generate-contract', '按这份报价单生成合同'],
|
|
66
|
+
['review', '对这份合同做合同预审,输出风险条款与修改建议'],
|
|
67
|
+
['clause-rewrite', '按预审建议修改合同条款'],
|
|
68
|
+
['request-status', '查一下这份合同的审批进度'],
|
|
69
|
+
['compare', '比对这两份合同的差异'],
|
|
70
|
+
['element-extract', '从这份合同里抽取要素'],
|
|
71
|
+
['supervise', '催办一下当前合同的审批'],
|
|
72
|
+
['template-recommend', '推荐几个适合的合同模板'],
|
|
73
|
+
['performance', '查一下这份合同的业绩核算'],
|
|
74
|
+
['retry-upload', '换一份文件重新解析'],
|
|
75
|
+
]);
|
|
76
|
+
const CARD_TPL = "<div id='{dom_id}' role='button' tabindex='0' style='display:flex;align-items:center;gap:12px;"
|
|
77
|
+
+ "background:#fff;border:1px solid #e8ebf2;border-radius:12px;padding:16px;{mb}cursor:pointer'>"
|
|
78
|
+
+ "<span style='flex:0 0 auto;width:44px;height:44px;border-radius:10px;background:#eef1fb;"
|
|
79
|
+
+ "display:flex;align-items:center;justify-content:center'>{icon}</span>"
|
|
80
|
+
+ "<span style='min-width:0'>"
|
|
81
|
+
+ "<span style='display:block;font-size:15px;font-weight:700;color:#1f2430;margin-bottom:6px'>{title}{badge}</span>"
|
|
82
|
+
+ "<span style='display:block;font-size:13px;color:#7a8497;line-height:1.5'>{desc}</span>"
|
|
83
|
+
+ '</span></div>';
|
|
84
|
+
const BADGE = "<span style='font-size:11px;color:#3b6fe0;background:#eaf0fe;border-radius:10px;"
|
|
85
|
+
+ "padding:2px 8px;line-height:1.4;margin-left:8px'>推荐</span>";
|
|
86
|
+
/** 交互脚本基础件(ES5、零双引号)。 */
|
|
87
|
+
const JS_BASE = "var P=window.xiaoePlugin||(window.rawWindow&&window.rawWindow.xiaoePlugin);"
|
|
88
|
+
+ "var tip=document.getElementById('tip');"
|
|
89
|
+
+ 'function say(m){if(tip){tip.textContent=m;}}'
|
|
90
|
+
+ "function hasP(){if(!P||!P.rightPanel||typeof P.rightPanel.open!=='function'){"
|
|
91
|
+
+ "say('当前环境没有小e右侧面板');return false;}return true;}"
|
|
92
|
+
+ "function op(cfg){if(!hasP()){return;}try{P.rightPanel.open(cfg);say('已打开');}"
|
|
93
|
+
+ "catch(e){say('面板打开失败,请确认右侧面板已挂载');}}"
|
|
94
|
+
+ "function send(q){if(!P||!P.session||typeof P.session.sendQuestion!=='function'){"
|
|
95
|
+
+ "say('当前环境不支持发送会话消息');return;}"
|
|
96
|
+
+ "try{P.session.sendQuestion({question:q,files:[]});say('已发送,正在处理…');}"
|
|
97
|
+
+ "catch(e){say('发送失败,请重试');}}"
|
|
98
|
+
+ "function art(html,title,key){if(!hasP()){return;}if(!html){say('内容为空');return;}"
|
|
99
|
+
+ "try{P.rightPanel.open({type:'artifact',width:__W__,title:title,contentProps:{"
|
|
100
|
+
+ "artifacts:[{id:key,name:title,fileType:'html',raw:{html:html}}],"
|
|
101
|
+
+ "initialArtifactKeys:[key]}});}catch(e){say('面板打开失败,请确认右侧面板已挂载');}}"
|
|
102
|
+
+ 'function bind(id,fn){var el=document.getElementById(id);if(!el){return;}el.onclick=fn;'
|
|
103
|
+
+ "el.onmouseenter=function(){el.style.borderColor='#1d6fd8';"
|
|
104
|
+
+ "el.style.boxShadow='0 2px 8px rgba(29,111,216,.12)';};"
|
|
105
|
+
+ "el.onmouseleave=function(){el.style.borderColor='#e8ebf2';el.style.boxShadow='none';};"
|
|
106
|
+
+ "el.onkeydown=function(e){if(e.key==='Enter'||e.key===' '){e.preventDefault();fn();}};}";
|
|
107
|
+
/** 内嵌模板(与 references/contract-action-card-template.html 一致)。 */
|
|
108
|
+
const CARD_TEMPLATE = `<!--
|
|
109
|
+
行为卡片内层模板(contract-action-card-template.html)
|
|
110
|
+
2026-11-09 重写:由「可照抄的样例」改为「供 render_action_card.py 填充的真模板」
|
|
111
|
+
|
|
112
|
+
旧版问题:卡片与 handler 全部写死、button 布局不符合标准卡、只绑 click 无 hover、
|
|
113
|
+
review 缺 params.compName、残留调试文案。照抄必错。
|
|
114
|
+
|
|
115
|
+
占位符(全部由 render_action_card.py 替换):
|
|
116
|
+
{{CARD_ID}} {{CARDS}} {{SUMMARY_JS}} {{COMPARE_JS}} {{REPORT_JS}} {{BODY}}
|
|
117
|
+
|
|
118
|
+
注意:本注释块在渲染时会被丢弃,脚本按「section 开标签含 id 属性」定位正文起点。
|
|
119
|
+
-->
|
|
120
|
+
<section id='{{CARD_ID}}' style='padding:4px 2px;font-family:Microsoft YaHei,PingFang SC,sans-serif'>
|
|
121
|
+
{{CARDS}}
|
|
122
|
+
<p id='tip' style='margin:8px 0 0;color:#b45309;font-size:12px'></p>
|
|
123
|
+
</section>
|
|
124
|
+
<script>(function(){var S={{SUMMARY_JS}};var C={{COMPARE_JS}};var R={{REPORT_JS}};{{BODY}}})();</script>
|
|
125
|
+
`;
|
|
126
|
+
function truthyText(value) {
|
|
127
|
+
if (value === null || value === undefined || value === false || value === '' || value === 0)
|
|
128
|
+
return '';
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
function pad2(value) {
|
|
132
|
+
return String(value).padStart(2, '0');
|
|
133
|
+
}
|
|
134
|
+
function stampNow() {
|
|
135
|
+
const now = new Date();
|
|
136
|
+
return `${now.getFullYear()}${pad2(now.getMonth() + 1)}${pad2(now.getDate())}`
|
|
137
|
+
+ `${pad2(now.getHours())}${pad2(now.getMinutes())}`;
|
|
138
|
+
}
|
|
139
|
+
/** 把文本变成 JS 字符串字面量(单引号包裹),保证零双引号、无裸换行。 */
|
|
140
|
+
function jsStr(text) {
|
|
141
|
+
let s = truthyText(text);
|
|
142
|
+
s = s.split('\r\n').join(' ').split('\n').join(' ').split('\r').join(' ');
|
|
143
|
+
s = s.replace(/ {2,}/gu, ' ');
|
|
144
|
+
s = s.split('</script>').join('<\\/script>'); // 防止外层 script 提前闭合
|
|
145
|
+
s = s.split('"').join("'"); // 双引号归零
|
|
146
|
+
s = s.split('\\').join('\\\\'); // 先转义已有反斜杠
|
|
147
|
+
s = s.split('<\\\\/script>').join('<\\/script>'); // 恢复 script 转义
|
|
148
|
+
s = s.split("'").join("\\'"); // 单引号转义
|
|
149
|
+
return `'${s}'`;
|
|
150
|
+
}
|
|
151
|
+
/** Python `str(x or '').replace("'", '').replace(chr(92), '')`:去掉单引号与反斜杠。 */
|
|
152
|
+
function safeInline(value) {
|
|
153
|
+
return truthyText(value).split("'").join('').split('\\').join('');
|
|
154
|
+
}
|
|
155
|
+
/** 按 action id 生成 handler 函数体;返回 null 表示缺关键参数、该卡不进。 */
|
|
156
|
+
function buildHandler(action, cfg) {
|
|
157
|
+
const aid = String(action.id ?? '');
|
|
158
|
+
const meta = ACTION_META.get(aid) ?? [aid, 'doc', 'sendQuestion'];
|
|
159
|
+
const dom = `c-${meta[0]}`;
|
|
160
|
+
if (aid === 'launch-flow') {
|
|
161
|
+
const wid = FLOW_IDS.get(cfg.flow_key || '');
|
|
162
|
+
if (!wid)
|
|
163
|
+
return { dom, body: null };
|
|
164
|
+
let src = `${cfg.base}/sp/workflow/flowpage/create/${wid}?workflowId=${wid}&isCreate=1`;
|
|
165
|
+
if (cfg.file_id)
|
|
166
|
+
src += `&fileId=${cfg.file_id}`;
|
|
167
|
+
// 要素预填走 params.customParams(aiExtraId + openSource + 合同文件字段),
|
|
168
|
+
// 与 SKILL.md 红线14 一致;缺 aiExtraId 时退回「只带附件预览」的旧行为。
|
|
169
|
+
let rawKeys = cfg.field_assign_keys || '';
|
|
170
|
+
if (Array.isArray(rawKeys))
|
|
171
|
+
rawKeys = rawKeys.map((item) => String(item)).join(',');
|
|
172
|
+
let keyStr = String(rawKeys ?? '')
|
|
173
|
+
.split(',')
|
|
174
|
+
.map((item) => item.trim())
|
|
175
|
+
.filter((item) => item.length > 0)
|
|
176
|
+
.join(',');
|
|
177
|
+
if (!keyStr && cfg.attachment_field_id)
|
|
178
|
+
keyStr = safeInline(cfg.attachment_field_id);
|
|
179
|
+
const cp = [];
|
|
180
|
+
const extraQ = [];
|
|
181
|
+
if (cfg.ai_extra_id) {
|
|
182
|
+
cp.push(`aiExtraId:'${safeInline(cfg.ai_extra_id)}'`);
|
|
183
|
+
cp.push("openSource:'xiaoE'");
|
|
184
|
+
extraQ.push(`aiExtraId=${safeInline(cfg.ai_extra_id)}`);
|
|
185
|
+
extraQ.push('openSource=xiaoE');
|
|
186
|
+
if (cfg.attachment_field_id && cfg.file_id) {
|
|
187
|
+
cp.push(`'${safeInline(cfg.attachment_field_id)}':'${safeInline(cfg.file_id)}'`);
|
|
188
|
+
extraQ.push(`${safeInline(cfg.attachment_field_id)}=${safeInline(cfg.file_id)}`);
|
|
189
|
+
}
|
|
190
|
+
// fieldAssignKeys / initialCovertName:customParams 与 src 两处同值
|
|
191
|
+
if (keyStr) {
|
|
192
|
+
cp.push(`fieldAssignKeys:'${keyStr}'`);
|
|
193
|
+
cp.push('initialCovertName:1');
|
|
194
|
+
extraQ.push(`fieldAssignKeys=${keyStr}`);
|
|
195
|
+
extraQ.push('initialCovertName=1');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// 逐值拼接,不做整体编码(值均为数字/固定串)
|
|
199
|
+
if (extraQ.length)
|
|
200
|
+
src += `&${extraQ.join('&')}`;
|
|
201
|
+
// customParams 放在 sdkOptions.params 下,params_pc / params_mobile 只放 app 与 compName
|
|
202
|
+
let params = "params_pc:{app:'@weapp/workflow',compName:'Comp.WffpRoute'},"
|
|
203
|
+
+ "params_mobile:{app:'@weapp/workflow',compName:'Comp.MWffpRoute',noMDialog:true}";
|
|
204
|
+
if (cp.length)
|
|
205
|
+
params += `,params:{customParams:{${cp.join(',')}}}`;
|
|
206
|
+
const body = `function(){op({type:'e10Sdk',width:__W__,contentProps:{src:'${src}',`
|
|
207
|
+
+ "sdkOptions:{compName:'ui.CorsComponent',routerType:'MemoryRouter',"
|
|
208
|
+
+ `routerProps_pc:{initialEntries:['/flowpage/create/${wid}']},`
|
|
209
|
+
+ `routerProps_mobile:{initialEntries:['/flowpage/create/${wid}']},`
|
|
210
|
+
+ `${params}}}});}`;
|
|
211
|
+
return { dom, body };
|
|
212
|
+
}
|
|
213
|
+
if (aid === 'view-review') {
|
|
214
|
+
const fileName = (cfg.file_name || '').split("'").join('');
|
|
215
|
+
const body = "function(){op({type:'e10Sdk',width:__W__,contentProps:{"
|
|
216
|
+
+ `src:'${cfg.base}/sp/contract/business/ai-contract',`
|
|
217
|
+
+ "sdkOptions:{compName:'ui.CorsComponent',routerType:'MemoryRouter',"
|
|
218
|
+
+ "routerProps:{initialEntries:['/sp/contract/business/ai-contract']},"
|
|
219
|
+
+ "params:{app:'@weapp/contract',compName:'AIContractV2',"
|
|
220
|
+
+ `aiProps:{aiid:'${cfg.aiid}',fileId:'${cfg.file_id || ''}',fileName:'${fileName}'}}}}});}`;
|
|
221
|
+
return { dom, body };
|
|
222
|
+
}
|
|
223
|
+
if (aid === 'credit') {
|
|
224
|
+
const company = cfg.company_name;
|
|
225
|
+
if (!company)
|
|
226
|
+
return { dom, body: null };
|
|
227
|
+
const body = "function(){op({type:'e10Sdk',width:__W__,contentProps:{"
|
|
228
|
+
+ `src:'${cfg.base}/sp/contract/business/credit',`
|
|
229
|
+
+ "sdkOptions:{compName:'ui.CorsComponent',routerType:'MemoryRouter',"
|
|
230
|
+
+ "routerProps:{initialEntries:['/sp/contract/business/credit']},"
|
|
231
|
+
+ "params:{app:'@weapp/contract',compName:'ContractCreditDetail',"
|
|
232
|
+
+ `companyName:['${company.split("'").join('')}']}}}});}`;
|
|
233
|
+
return { dom, body };
|
|
234
|
+
}
|
|
235
|
+
if (aid === 'view-compare') {
|
|
236
|
+
const body = "function(){op({type:'e10Sdk',width:__W__,contentProps:{"
|
|
237
|
+
+ `src:'${cfg.base}/sp/contract/business/doc-compare',`
|
|
238
|
+
+ "sdkOptions:{compName:'ui.CorsComponent',routerType:'MemoryRouter',"
|
|
239
|
+
+ "routerProps:{initialEntries:['/sp/contract/business/doc-compare']},"
|
|
240
|
+
+ "params:{app:'@weapp/contract',compName:'AIDocCompare'}}}});}";
|
|
241
|
+
return { dom, body };
|
|
242
|
+
}
|
|
243
|
+
if (aid === 'export-review') {
|
|
244
|
+
return { dom, body: "function(){art(R,'合同风险审查报告.html','report-1');}" };
|
|
245
|
+
}
|
|
246
|
+
if (aid === 'summary') {
|
|
247
|
+
return { dom, body: "function(){art(S,'合同摘要.html','summary-1');}" };
|
|
248
|
+
}
|
|
249
|
+
if (aid === 'export-compare-report') {
|
|
250
|
+
return { dom, body: "function(){art(C,'合同比对报告.html','compare-1');}" };
|
|
251
|
+
}
|
|
252
|
+
// 其余走 sendQuestion
|
|
253
|
+
const text = SEND_TEXT.get(aid) || String(action.title ?? '');
|
|
254
|
+
return { dom, body: `function(){send('${text.split("'").join('')}');}` };
|
|
255
|
+
}
|
|
256
|
+
export function renderActionCard(ctx, cfg, template) {
|
|
257
|
+
const plan = planActions(ctx);
|
|
258
|
+
let cards = plan.cards;
|
|
259
|
+
// 支持只输出指定动作(only),用于单独出「发起流程」卡;仍由本渲染器生成,禁止手写卡片。
|
|
260
|
+
if (cfg.only.length) {
|
|
261
|
+
cards = cards.filter((card) => cfg.only.includes(String(card.id)));
|
|
262
|
+
}
|
|
263
|
+
const parts = [];
|
|
264
|
+
const handlers = [];
|
|
265
|
+
cards.forEach((card, index) => {
|
|
266
|
+
const meta = ACTION_META.get(String(card.id)) ?? [String(card.id), 'doc', 'sendQuestion'];
|
|
267
|
+
const { dom, body } = buildHandler(card, cfg);
|
|
268
|
+
// 缺关键参数(如 flowKey 未映射、无企业全称)→ 该卡不进
|
|
269
|
+
if (body === null)
|
|
270
|
+
return;
|
|
271
|
+
parts.push(CARD_TPL
|
|
272
|
+
.split('{dom_id}').join(dom)
|
|
273
|
+
.split('{mb}').join(index === cards.length - 1 ? '' : 'margin-bottom:12px;')
|
|
274
|
+
.split('{icon}').join(SVG[meta[1]] ?? SVG.doc)
|
|
275
|
+
.split('{title}').join(String(card.title ?? ''))
|
|
276
|
+
.split('{badge}').join(index === 0 ? BADGE : '')
|
|
277
|
+
.split('{desc}').join(String(card.desc ?? '')));
|
|
278
|
+
handlers.push({ dom, body });
|
|
279
|
+
});
|
|
280
|
+
if (!parts.length) {
|
|
281
|
+
return { payload: null, planned: cards.map((card) => String(card.id)), cardCount: 0, hint: plan.hint };
|
|
282
|
+
}
|
|
283
|
+
let bodyJs = JS_BASE;
|
|
284
|
+
// hb 本身已是 function(){...},这里只做赋值,不要再包一层 function hN(){}
|
|
285
|
+
handlers.forEach((handler, index) => {
|
|
286
|
+
bodyJs += `var h${index}=${handler.body};`;
|
|
287
|
+
});
|
|
288
|
+
handlers.forEach((handler, index) => {
|
|
289
|
+
bodyJs += `bind('${handler.dom}',h${index});`;
|
|
290
|
+
});
|
|
291
|
+
bodyJs += `say('就绪,共 ${handlers.length} 个动作');`;
|
|
292
|
+
// 必须拼完全部脚本后统一替换,覆盖 JS_BASE 与所有 handler(否则 handler 里的
|
|
293
|
+
// width:__W__ 残留,点击抛 ReferenceError 被 try/catch 吞成「面板打开失败」)
|
|
294
|
+
bodyJs = bodyJs.split('__W__').join(String(WIDTH));
|
|
295
|
+
const summaryJs = jsStr(cfg.summary_html || '');
|
|
296
|
+
const reportJs = jsStr(cfg.report_html || '');
|
|
297
|
+
const compareJs = jsStr(cfg.compare_html || '');
|
|
298
|
+
// 只取正文起点:模板头部是说明注释,不能进 customParams.html。
|
|
299
|
+
// 必须按「section 开标签且带 id 属性」定位,不能 indexOf('<section')——
|
|
300
|
+
// 注释里只要出现该字样就会误命中,导致多出一个未闭合的开标签。
|
|
301
|
+
const match = /<section\s+id=/u.exec(template);
|
|
302
|
+
if (!match) {
|
|
303
|
+
throw contractValidationError('template_invalid', '模板缺少带 id 的 section,无法渲染');
|
|
304
|
+
}
|
|
305
|
+
const body = template.slice(match.index);
|
|
306
|
+
const html = body
|
|
307
|
+
.split('{{CARD_ID}}').join(cfg.card_id)
|
|
308
|
+
.split('{{CARDS}}').join(parts.join('\n'))
|
|
309
|
+
.split('{{SUMMARY_JS}}').join(summaryJs)
|
|
310
|
+
.split('{{COMPARE_JS}}').join(compareJs)
|
|
311
|
+
.split('{{REPORT_JS}}').join(reportJs)
|
|
312
|
+
.split('{{BODY}}').join(bodyJs);
|
|
313
|
+
const count = handlers.length;
|
|
314
|
+
let title = cfg.title ? cfg.title : `可做的 ${count} 件事`;
|
|
315
|
+
title = title.replace(/[\\/:*?"<>|]/gu, ' ');
|
|
316
|
+
const payload = {
|
|
317
|
+
version: 1,
|
|
318
|
+
callId: cfg.call_id,
|
|
319
|
+
toolId: 'fill_form',
|
|
320
|
+
arguments: {
|
|
321
|
+
type: 'e10',
|
|
322
|
+
title,
|
|
323
|
+
src: `${cfg.base}/sp/contract/xiaoe-custom-page`,
|
|
324
|
+
width: WIDTH,
|
|
325
|
+
sdkRenderType: 'inline',
|
|
326
|
+
sdkOptions: {
|
|
327
|
+
compName: 'ui.CorsComponent',
|
|
328
|
+
routerType: 'MemoryRouter',
|
|
329
|
+
routerProps_pc: { initialEntries: ['/sp/contract/xiaoe-custom-page'] },
|
|
330
|
+
params_pc: {
|
|
331
|
+
app: '@weapp/contract',
|
|
332
|
+
compName: 'xiaoeCustomPage',
|
|
333
|
+
customParams: { html },
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
return { payload, planned: cards.map((card) => String(card.id)), cardCount: count };
|
|
339
|
+
}
|
|
340
|
+
/** 交付前自检:引号、反斜杠、`__W__` 残留、ES5、hover 绑定、脚本语法。 */
|
|
341
|
+
export function selfCheckActionCard(payload) {
|
|
342
|
+
const problems = [];
|
|
343
|
+
const html = String(payload.arguments?.sdkOptions?.params_pc?.customParams?.html ?? '');
|
|
344
|
+
const doubleQuotes = (html.match(/"/gu) ?? []).length;
|
|
345
|
+
if (doubleQuotes !== 0)
|
|
346
|
+
problems.push(`html 内双引号 ${doubleQuotes} 个(应为 0)`);
|
|
347
|
+
const unsafe = (html.match(/\\(?!\/script>|')/gu) ?? []).length;
|
|
348
|
+
if (unsafe)
|
|
349
|
+
problems.push(`非安全转义反斜杠 ${unsafe} 处`);
|
|
350
|
+
const scriptMatch = /<script>([\s\S]*)<\/script>/u.exec(html);
|
|
351
|
+
// ES5 只扫脚本正文:html 里可能有说明文字/属性,不能当语法看
|
|
352
|
+
const jsCode = scriptMatch ? scriptMatch[1] : html;
|
|
353
|
+
// 宽度占位符必须已全部替换。残留时点击抛 ReferenceError,又被 handler 的
|
|
354
|
+
// try/catch 吞掉,只显示「面板打开失败」,属静默故障。
|
|
355
|
+
const placeholders = (jsCode.split('__W__').length - 1);
|
|
356
|
+
if (placeholders)
|
|
357
|
+
problems.push(`残留未替换的宽度占位符 __W__ ${placeholders} 处(点击会 ReferenceError)`);
|
|
358
|
+
const esPatterns = [
|
|
359
|
+
[/=>/u, 'arrow'],
|
|
360
|
+
[/\bconst\b/u, 'const'],
|
|
361
|
+
[/\blet\b/u, 'let'],
|
|
362
|
+
[/\?\?/u, '??'],
|
|
363
|
+
[/\?\./u, '?.'],
|
|
364
|
+
];
|
|
365
|
+
for (const [pattern, name] of esPatterns) {
|
|
366
|
+
if (pattern.test(jsCode))
|
|
367
|
+
problems.push(`ES5 违规:${name}`);
|
|
368
|
+
}
|
|
369
|
+
if (!jsCode.includes('mouseenter'))
|
|
370
|
+
problems.push('缺少 hover 绑定(mouseenter)');
|
|
371
|
+
if (!scriptMatch) {
|
|
372
|
+
problems.push('未找到 script');
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
try {
|
|
376
|
+
// 等价 `node --check`:按 script 语义解析,不执行
|
|
377
|
+
// eslint-disable-next-line no-new
|
|
378
|
+
new Script(jsCode);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
382
|
+
problems.push(`node --check 失败:${message.split('\n').slice(0, 3).join(' / ')}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const cardCount = (html.match(/role='button'/gu) ?? []).length;
|
|
386
|
+
return { problems, cardCount, htmlLength: html.length };
|
|
387
|
+
}
|
|
388
|
+
function isFile(path) {
|
|
389
|
+
try {
|
|
390
|
+
return existsSync(path) && statSync(path).isFile();
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function readTextOrThrow(path, label) {
|
|
397
|
+
if (!path)
|
|
398
|
+
return '';
|
|
399
|
+
if (!isFile(path)) {
|
|
400
|
+
throw contractValidationError('file_not_found', `${label} 文件不存在:${path}`);
|
|
401
|
+
}
|
|
402
|
+
return readFileSync(path, 'utf8');
|
|
403
|
+
}
|
|
404
|
+
function loadContext(input) {
|
|
405
|
+
const direct = input.context;
|
|
406
|
+
if (direct && typeof direct === 'object' && !Array.isArray(direct)) {
|
|
407
|
+
return { ctx: direct, source: 'context' };
|
|
408
|
+
}
|
|
409
|
+
const inline = typeof input.contextJson === 'string' && input.contextJson.trim() ? input.contextJson.trim() : '';
|
|
410
|
+
const file = typeof input.contextFile === 'string' && input.contextFile.trim() ? resolve(input.contextFile.trim()) : '';
|
|
411
|
+
if (file) {
|
|
412
|
+
if (!isFile(file))
|
|
413
|
+
throw contractValidationError('context_unreadable', `上下文文件不存在:${file}`);
|
|
414
|
+
try {
|
|
415
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8').replace(/^\uFEFF/u, ''));
|
|
416
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
417
|
+
throw new Error('上下文必须是 JSON 对象');
|
|
418
|
+
}
|
|
419
|
+
return { ctx: parsed, source: file };
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
423
|
+
throw contractValidationError('context_invalid', `上下文不是合法 JSON 对象:${message}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (inline) {
|
|
427
|
+
try {
|
|
428
|
+
const parsed = JSON.parse(inline);
|
|
429
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
430
|
+
throw new Error('上下文必须是 JSON 对象');
|
|
431
|
+
}
|
|
432
|
+
return { ctx: parsed, source: 'contextJson' };
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
436
|
+
throw contractValidationError('context_invalid', `上下文不是合法 JSON 对象:${message}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// 兜底:按产物所在目录找 card_context.json / first_screen_result.json
|
|
440
|
+
const dirs = [];
|
|
441
|
+
for (const key of ['out', 'summaryHtml', 'reportHtml', 'compareHtml']) {
|
|
442
|
+
const value = input[key];
|
|
443
|
+
if (typeof value === 'string' && value.trim())
|
|
444
|
+
dirs.push(dirname(resolve(value.trim())));
|
|
445
|
+
}
|
|
446
|
+
dirs.push(process.cwd());
|
|
447
|
+
const seen = new Set();
|
|
448
|
+
for (const dir of dirs) {
|
|
449
|
+
if (!dir || seen.has(dir) || !existsSync(dir))
|
|
450
|
+
continue;
|
|
451
|
+
seen.add(dir);
|
|
452
|
+
for (const name of ['card_context.json', 'first_screen_result.json']) {
|
|
453
|
+
const path = join(dir, name);
|
|
454
|
+
if (!isFile(path))
|
|
455
|
+
continue;
|
|
456
|
+
try {
|
|
457
|
+
let parsed = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/u, ''));
|
|
458
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
459
|
+
continue;
|
|
460
|
+
if (name === 'first_screen_result.json') {
|
|
461
|
+
const ctx = { scene: 'doc', docType: 'contract' };
|
|
462
|
+
if (parsed.workflowFileId || parsed.reviewFileId)
|
|
463
|
+
ctx.hasFileId = true;
|
|
464
|
+
if (parsed.flow)
|
|
465
|
+
ctx.flowKey = parsed.flow;
|
|
466
|
+
if (parsed.summaryHtml)
|
|
467
|
+
ctx.summaryReady = true;
|
|
468
|
+
if (parsed.reportHtml)
|
|
469
|
+
ctx.reviewed = true;
|
|
470
|
+
parsed = ctx;
|
|
471
|
+
}
|
|
472
|
+
return { ctx: parsed, source: path };
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return { ctx: {}, source: 'minimal' };
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 渲染行为卡片(browsertool payload)。
|
|
483
|
+
*
|
|
484
|
+
* 产出可直接裸输出的 `<browsertool>...</browsertool>`(`out` 指定时写入文件)。
|
|
485
|
+
* `selfCheck` 非空表示结构不达标,禁止交付。
|
|
486
|
+
*/
|
|
487
|
+
export const contractCardActionOperation = {
|
|
488
|
+
name: 'contract.card.action',
|
|
489
|
+
async execute(input) {
|
|
490
|
+
const { ctx, source } = loadContext(input);
|
|
491
|
+
// 命令行已给出的产物视为对应状态已达成,避免动作被误过滤
|
|
492
|
+
const fileId = truthyText(input.fileId);
|
|
493
|
+
const flowKey = truthyText(input.flowKey);
|
|
494
|
+
const companyName = truthyText(input.companyName);
|
|
495
|
+
const summaryPath = truthyText(input.summaryHtml);
|
|
496
|
+
const reportPath = truthyText(input.reportHtml);
|
|
497
|
+
const comparePath = truthyText(input.compareHtml);
|
|
498
|
+
const setDefault = (key, value) => {
|
|
499
|
+
if (!(key in ctx) || ctx[key] === undefined || ctx[key] === null)
|
|
500
|
+
ctx[key] = value;
|
|
501
|
+
};
|
|
502
|
+
if (fileId) {
|
|
503
|
+
setDefault('hasFileId', true);
|
|
504
|
+
setDefault('fileId', fileId);
|
|
505
|
+
}
|
|
506
|
+
if (flowKey)
|
|
507
|
+
setDefault('flowKey', flowKey);
|
|
508
|
+
if (companyName)
|
|
509
|
+
setDefault('hasCounterparty', true);
|
|
510
|
+
if (summaryPath)
|
|
511
|
+
setDefault('summaryReady', true);
|
|
512
|
+
if (reportPath)
|
|
513
|
+
setDefault('reviewed', true);
|
|
514
|
+
if (comparePath)
|
|
515
|
+
setDefault('compared', true);
|
|
516
|
+
setDefault('scene', 'doc');
|
|
517
|
+
const stamp = stampNow();
|
|
518
|
+
const cfg = {
|
|
519
|
+
file_id: fileId || undefined,
|
|
520
|
+
file_name: truthyText(input.fileName) || undefined,
|
|
521
|
+
flow_key: flowKey || truthyText(ctx.flowKey) || undefined,
|
|
522
|
+
company_name: companyName || undefined,
|
|
523
|
+
summary_html: readTextOrThrow(summaryPath, 'summaryHtml'),
|
|
524
|
+
report_html: readTextOrThrow(reportPath, 'reportHtml'),
|
|
525
|
+
compare_html: readTextOrThrow(comparePath, 'compareHtml'),
|
|
526
|
+
base: (truthyText(input.baseUrl) || DEFAULT_BASE).replace(/\/+$/u, ''),
|
|
527
|
+
aiid: truthyText(input.aiid) || DEFAULT_AIID,
|
|
528
|
+
ai_extra_id: truthyText(input.aiExtraId) || truthyText(ctx.aiExtraId) || '',
|
|
529
|
+
attachment_field_id: truthyText(input.attachmentFieldId) || truthyText(ctx.attachmentFieldId) || '',
|
|
530
|
+
field_assign_keys: ctx.fieldAssignKeys || '',
|
|
531
|
+
card_id: truthyText(input.cardId) || `card-${stamp}`,
|
|
532
|
+
call_id: truthyText(input.callId) || `contract-card-${stamp}-01`,
|
|
533
|
+
title: truthyText(input.title) || undefined,
|
|
534
|
+
only: truthyText(input.only)
|
|
535
|
+
.split(',')
|
|
536
|
+
.map((item) => item.trim())
|
|
537
|
+
.filter((item) => item.length > 0),
|
|
538
|
+
};
|
|
539
|
+
const templatePath = truthyText(input.template);
|
|
540
|
+
const template = templatePath ? readTextOrThrow(resolve(templatePath), 'template') : CARD_TEMPLATE;
|
|
541
|
+
const { payload, planned, cardCount, hint } = renderActionCard(ctx, cfg, template);
|
|
542
|
+
if (!payload) {
|
|
543
|
+
// NO_CARD 属正常收口:按 contract-action-engine.md §7 处理,不写文件
|
|
544
|
+
return {
|
|
545
|
+
status: 'COMPLETE',
|
|
546
|
+
data: {
|
|
547
|
+
noCard: true,
|
|
548
|
+
planned,
|
|
549
|
+
cardCount: 0,
|
|
550
|
+
contextSource: source,
|
|
551
|
+
hint: hint || '过滤后无可用动作(按 contract-action-engine.md §7 处理)',
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
const check = selfCheckActionCard(payload);
|
|
556
|
+
const text = `<browsertool>\n${JSON.stringify(payload, null, 1)}\n</browsertool>`;
|
|
557
|
+
let output;
|
|
558
|
+
const outPath = truthyText(input.out);
|
|
559
|
+
if (outPath) {
|
|
560
|
+
output = resolve(outPath);
|
|
561
|
+
mkdirSync(dirname(output), { recursive: true });
|
|
562
|
+
writeFileSync(output, text, 'utf8');
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
status: 'COMPLETE',
|
|
566
|
+
data: {
|
|
567
|
+
noCard: false,
|
|
568
|
+
planned,
|
|
569
|
+
cardCount,
|
|
570
|
+
contextSource: source,
|
|
571
|
+
title: payload.arguments.title,
|
|
572
|
+
callId: payload.callId,
|
|
573
|
+
htmlLength: check.htmlLength,
|
|
574
|
+
selfCheck: check.problems,
|
|
575
|
+
selfCheckPassed: check.problems.length === 0,
|
|
576
|
+
bytes: Buffer.byteLength(text, 'utf8'),
|
|
577
|
+
...(output ? { output, browsertool: text } : { browsertool: text }),
|
|
578
|
+
note: check.problems.length
|
|
579
|
+
? '自检未通过,禁止交付;请按 selfCheck 修正后重跑'
|
|
580
|
+
: 'browsertool 可直接裸输出;禁止再手写卡片 HTML',
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
export const contractCardActionOperations = [contractCardActionOperation];
|