weaver-work-cli 0.1.53 → 0.1.56
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/chunks/{archive-ZQ4A4TV6.js → archive-4SQAVTIB.js} +3 -2
- package/dist/chunks/{archive-oa-57R2FYHV.js → archive-oa-W2UEJ67L.js} +137 -8
- package/dist/chunks/{asset-ZOJVBWZH.js → asset-EGZEABBI.js} +3 -2
- package/dist/chunks/{asset-idle-XGB5IPGT.js → asset-idle-EBUZBB6M.js} +3 -2
- package/dist/chunks/{attachment-content-W3TSJC3Y.js → attachment-content-QGM5MLQE.js} +4 -3
- package/dist/chunks/{blog-QSHLZSFW.js → blog-2YKMWOWI.js} +3 -2
- package/dist/chunks/{caizhilian-KCQYFH72.js → caizhilian-QJ4FLSQJ.js} +5 -4
- package/dist/chunks/{calendar-DLGMRJQA.js → calendar-H4QTJCUY.js} +3 -2
- package/dist/chunks/{chunk-XPQN4E5O.js → chunk-44KJ7WFA.js} +300 -55
- package/dist/chunks/{chunk-CZNZKOHR.js → chunk-4GG72JAT.js} +2 -2
- package/dist/chunks/{chunk-YIKSL36S.js → chunk-5N222HK6.js} +2 -2
- package/dist/chunks/{chunk-6GCXWKG6.js → chunk-6DVL5IN5.js} +4 -1
- package/dist/chunks/{chunk-WTLQGS6D.js → chunk-6MS3RLPO.js} +5 -334
- package/dist/chunks/{chunk-Z4G7LLDD.js → chunk-7EBV7Q3R.js} +124 -27
- package/dist/chunks/{chunk-76PRVYH4.js → chunk-AHJZIMCX.js} +1 -1
- package/dist/chunks/{chunk-TGAGQV4I.js → chunk-CQ4OVCKG.js} +2 -2
- package/dist/chunks/{chunk-2BQESR2U.js → chunk-DVR2EDUU.js} +99 -34
- package/dist/chunks/{chunk-QQXMHM3J.js → chunk-FDAJC7R4.js} +4 -4
- package/dist/chunks/{chunk-GR76ZDDX.js → chunk-FMNCSYIG.js} +2 -2
- package/dist/chunks/{chunk-IF33CG4V.js → chunk-L2LMBFG5.js} +1 -1
- package/dist/chunks/{chunk-DLY5GUXX.js → chunk-PH7N4UFT.js} +1 -1
- package/dist/chunks/{chunk-U6R6FZHD.js → chunk-SFM3M2L3.js} +286 -93
- package/dist/chunks/chunk-SHYQUBY3.js +48 -0
- package/dist/chunks/{chunk-HFXK54M4.js → chunk-TGM7BWEH.js} +2 -2
- package/dist/chunks/{chunk-2J3XY4ED.js → chunk-TJUAGZU7.js} +11 -11
- package/dist/chunks/{chunk-PE334WL3.js → chunk-UI66EMOR.js} +4 -4
- package/dist/chunks/{chunk-762M5XJS.js → chunk-VMCCRWFO.js} +2 -2
- package/dist/chunks/{chunk-U7ROML5E.js → chunk-WHJIUKJW.js} +681 -48
- package/dist/chunks/{chunk-PGO4ILMQ.js → chunk-WMB3SMXI.js} +1 -1
- package/dist/chunks/chunk-WMRNO6IU.js +337 -0
- package/dist/chunks/{chunk-6NXT4ICB.js → chunk-WVH5ESDA.js} +1 -1
- package/dist/chunks/{chunk-DEHJ7PMA.js → chunk-XU3FL3AW.js} +4 -4
- package/dist/chunks/{chunk-Z6UUBY37.js → chunk-Z4IPY5GV.js} +2 -2
- package/dist/chunks/{conflict-57WDJWL7.js → conflict-VAFFPUY3.js} +2 -2
- package/dist/chunks/{contract-LJRAXVZU.js → contract-LLRKMLQQ.js} +2655 -1319
- package/dist/chunks/{cowork-3ACICHDQ.js → cowork-2RDFBZWB.js} +3 -2
- package/dist/chunks/{create-flow-3FMMZBCA.js → create-flow-TVYE3IOH.js} +6 -6
- package/dist/chunks/{data-WK5CQXNF.js → data-WVICO3DT.js} +57 -11
- package/dist/chunks/{ebuilder-form-CBYI6CQ6.js → ebuilder-form-TWSXS5NA.js} +7 -6
- package/dist/chunks/{ehr-XI4BIVR2.js → ehr-52GBKNJR.js} +3 -2
- package/dist/chunks/{env-JYZE3BZB.js → env-BVVFIN4P.js} +2 -2
- package/dist/chunks/{esb-4BQHNP5C.js → esb-HJSXCEOM.js} +5 -4
- package/dist/chunks/{factory-66SCIKW3.js → factory-RCQ36LLE.js} +1 -1
- package/dist/chunks/{fna-ECOYBQYL.js → fna-OBACRT3J.js} +72 -3
- package/dist/chunks/{group-chat-MNRYMLNG.js → group-chat-YFZDUUY3.js} +3 -3
- package/dist/chunks/{host-TUOIOEMC.js → host-2BKMPWDH.js} +4 -3
- package/dist/chunks/{host-3TNBMDTR.js → host-KJT3G5D2.js} +4 -3
- package/dist/chunks/{host-7OWWPLM4.js → host-KOWUMNAY.js} +4 -3
- package/dist/chunks/{host-M4XP5URR.js → host-MFXRA2MY.js} +4 -3
- package/dist/chunks/{host-7NTIBSPK.js → host-TTSGY5NZ.js} +4 -3
- package/dist/chunks/{host-G3VU7SDW.js → host-W4JCNRFS.js} +4 -3
- package/dist/chunks/{hrm-YGIR3HGF.js → hrm-AK3WGBMN.js} +4 -3
- package/dist/chunks/{im-TN2JYVGJ.js → im-JZSBPO4Z.js} +4 -3
- package/dist/chunks/{invoice-V7ZTITUO.js → invoice-V6KD4TZE.js} +4 -3
- package/dist/chunks/{jiuchuanhui-ASFZBMPU.js → jiuchuanhui-K4EQU6GK.js} +3 -2
- package/dist/chunks/{lazy-dispatch-XSAHDK6Z.js → lazy-dispatch-JHGFCKJN.js} +5 -4
- package/dist/chunks/{mail-M3HJF5ER.js → mail-IKVCQCVZ.js} +3 -2
- package/dist/chunks/{meeting-IIY4UAJL.js → meeting-JOHV4RH3.js} +14 -12
- package/dist/chunks/minute-doc-JLS4KMFZ.js +156 -0
- package/dist/chunks/{okr-EVX7FB5G.js → okr-KV43FPPX.js} +3 -2
- package/dist/chunks/{operations-J7PUIVWZ.js → operations-ZPWBMYKE.js} +5 -4
- package/dist/chunks/{plan-2QJQEPBO.js → plan-WOYR4WEG.js} +3 -2
- package/dist/chunks/{project-XELELW2T.js → project-CQJKBUIL.js} +3 -2
- package/dist/chunks/{reception-QGPNTGHG.js → reception-MPBU3JXC.js} +3 -2
- package/dist/chunks/{recruit-stage-XCMVEQA2.js → recruit-stage-USTTRHOX.js} +3 -2
- package/dist/chunks/{registry-CJOVECZD.js → registry-GURQG4ZV.js} +3 -2
- package/dist/chunks/{registry-METZ2LWE.js → registry-LITYOH2W.js} +12 -10
- package/dist/chunks/{registry-QJCZ2GVG.js → registry-SS5J2FZQ.js} +5 -4
- package/dist/chunks/{room-recommend-YFY7HTOF.js → room-recommend-62MECG4J.js} +4 -4
- package/dist/chunks/{schedule-6I63TERA.js → schedule-6QRXIBGU.js} +4 -4
- package/dist/chunks/{smart-extract-FOUYNIG3.js → smart-extract-APX2PNIN.js} +3 -2
- package/dist/chunks/{workflow-YHXFIU63.js → workflow-WMPW3WSB.js} +5 -4
- package/dist/index.js +33 -32
- package/dist/internal/e10/auth/agent-host-key.js +68 -0
- package/dist/internal/e10/auth/agent-hosts.js +250 -0
- package/dist/internal/e10/auth/commands.js +99 -30
- package/dist/internal/e10/auth/paths.js +9 -0
- package/dist/internal/e10/auth/session.js +17 -0
- package/dist/internal/e10/auth/xiaoe.js +37 -3
- package/dist/shortcuts/archive-oa/operations/contract-modules.js +106 -0
- package/dist/shortcuts/archive-oa/operations/contract.js +38 -4
- package/dist/shortcuts/archive-oa/operations/registry.js +2 -1
- package/dist/shortcuts/contract/index.js +6 -7
- package/dist/shortcuts/contract/manifest.js +101 -24
- package/dist/shortcuts/contract/ooxml/docx-table.js +75 -3
- package/dist/shortcuts/contract/ooxml/xlsx.js +49 -13
- package/dist/shortcuts/contract/operations/card-action.js +113 -12
- package/dist/shortcuts/contract/operations/card-ebdf-list.js +29 -7
- package/dist/shortcuts/contract/operations/card-plan.js +75 -9
- package/dist/shortcuts/contract/operations/card-risk-report.js +2 -2
- package/dist/shortcuts/contract/operations/card.js +1 -1
- package/dist/shortcuts/contract/operations/clause-library.js +88 -16
- package/dist/shortcuts/contract/operations/compare-screen.js +378 -0
- package/dist/shortcuts/contract/operations/compare.js +1 -1
- package/dist/shortcuts/contract/operations/credit-page.js +1 -1
- package/dist/shortcuts/contract/operations/docx-slots.js +1000 -0
- package/dist/shortcuts/contract/operations/flow.js +2 -2
- package/dist/shortcuts/contract/operations/quote-to-contract.js +495 -0
- package/dist/shortcuts/contract/operations/quote.js +2 -229
- package/dist/shortcuts/contract/operations/recommend.js +1 -1
- package/dist/shortcuts/contract/operations/registry.js +6 -2
- package/dist/shortcuts/contract/operations/review.js +230 -4
- package/dist/shortcuts/contract/operations/save-recognize.js +122 -3
- package/dist/shortcuts/contract/operations/template.js +11 -10
- package/dist/shortcuts/data/operations/ds.js +5 -5
- package/dist/shortcuts/data/operations/shared.js +76 -4
- package/dist/shortcuts/fna/manifest.js +7 -2
- package/dist/shortcuts/fna/operations/budget.js +68 -0
- package/dist/shortcuts/meeting/minute-doc.js +153 -0
- package/dist/shortcuts/meeting/operations/compose-outcome.js +176 -0
- package/dist/shortcuts/meeting/operations/eb/catalog.js +1 -1
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +47 -0
- package/dist/shortcuts/meeting/operations/eb/decision-task-batch.js +144 -0
- package/dist/shortcuts/meeting/operations/eb/decision.js +92 -4
- package/dist/shortcuts/meeting/operations/eb/index.js +133 -4
- package/dist/shortcuts/meeting/operations/eb/meeting-link.js +90 -0
- package/dist/shortcuts/meeting/operations/from-group-chat.js +46 -0
- package/dist/shortcuts/meeting/operations/minute-content.js +61 -0
- package/dist/shortcuts/meeting/operations/registry.js +14 -1
- package/dist/shortcuts/meeting/operations/self-check.js +49 -0
- package/dist/shortcuts/workflow/endpoints.js +2 -0
- package/dist/shortcuts/workflow/operations/read.js +114 -8
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +72 -46
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +41 -0
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +46 -11
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +18 -1
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroupAdd.js +51 -0
- package/docs/e10-auth.md +78 -0
- package/docs/fna.md +8 -3
- package/package.json +4 -2
- package/scripts/pack-offline.mjs +228 -0
- package/scripts/package-skill.mjs +14 -5
- package/skill-template/business-info.json +3 -0
- package/skill-template/domains/qiyecheng.md +4 -3
- package/skills/weaver-e10-archive-oa/SKILL.md +6 -1
- package/skills/weaver-e10-archive-oa/references/contract-search.md +91 -4
- package/skills/weaver-e10-jinchengda/SKILL.md +100 -81
- package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +11 -6
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -4
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +38 -12
- package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +20 -6
- package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +8 -3
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +56 -13
- package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +7 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +11 -5
- package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +38 -7
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +13 -25
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +9 -8
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +8 -6
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +10 -7
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +3 -1
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +26 -18
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +4 -4
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +18 -13
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +5 -3
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +105 -49
- package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +3 -6
- package/skills/weaver-e10-meeting/SKILL.md +48 -9
- package/skills/weaver-e10-qiyecheng/SKILL.md +16 -7
- package/skills/weaver-e10-qiyecheng/references/budget.md +77 -3
- package/skills/weaver-e10-qiyecheng/references/catalog.md +6 -4
- package/skills/weaver-e10-qiyecheng/references/getEnabledTemplate-api.md +255 -0
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +70 -25
- package/skills/weaver-e10-workflow/SKILL.md +54 -40
- package/skills/weaver-e10-workflow/references/todo-dialogue.md +134 -0
- package/skills/weaver-e10-workflow/references/todo-smart-convert.md +102 -80
- package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +23 -13
- package/skills/weaver-e10-workflow/references/workflow-query.md +68 -46
- package/skills/weaver-e10-workflow/references/workflow-view.md +21 -13
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +317 -332
- package/dist/shortcuts/contract/ooxml/docx.js +0 -295
- package/dist/shortcuts/contract/operations/docx-fillfromquote.js +0 -532
- package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +0 -178
- package/skills/weaver-e10-jinchengda/references/source-manifest.json +0 -1270
- package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +0 -998
- package/skills/weaver-e10-workflow/tools/todo-serve.cjs +0 -327
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
* - 纵向合并:文本列可继承、数值列只归首行(防止 20 万被重复计成 200 万)。
|
|
10
10
|
* - 一致性校验:分节明细求和 vs 表内合计、明细总计 vs 标准价合计、折扣提示。
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
14
|
import { contractValidationError } from '../errors.js';
|
|
15
15
|
import { requireNonEmptyString } from './shared.js';
|
|
16
16
|
import { listSheetNames, readGrid } from '../ooxml/xlsx.js';
|
|
17
|
-
import { fillDocx, labelBefore } from '../ooxml/docx.js';
|
|
18
17
|
import { readZipEntry } from '../ooxml/zip.js';
|
|
19
18
|
// ---------------------------------------------------------------- 人民币大写
|
|
20
19
|
const DIGITS = '零壹贰叁肆伍陆柒捌玖';
|
|
@@ -108,15 +107,6 @@ function toNum(s) {
|
|
|
108
107
|
const f = parseFloat(t);
|
|
109
108
|
return Number.isInteger(f) ? f : f;
|
|
110
109
|
}
|
|
111
|
-
function fmtNum(v) {
|
|
112
|
-
if (v === null || v === undefined || v === '')
|
|
113
|
-
return '';
|
|
114
|
-
const s = String(v).replace(/[,¥¥]/gu, '').trim();
|
|
115
|
-
const f = Number(s);
|
|
116
|
-
if (!Number.isFinite(f))
|
|
117
|
-
return String(v);
|
|
118
|
-
return f === Math.trunc(f) ? f.toLocaleString('en-US') : f.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
119
|
-
}
|
|
120
110
|
const META_FIELDS = [
|
|
121
111
|
{
|
|
122
112
|
key: 'customer',
|
|
@@ -573,106 +563,7 @@ export function normalizeParsedQuote(input) {
|
|
|
573
563
|
warnings,
|
|
574
564
|
};
|
|
575
565
|
}
|
|
576
|
-
// ----------------------------------------------------------------
|
|
577
|
-
// ---------------------------------------------------------------- docx 填充(字段打分)
|
|
578
|
-
const FIELD_ALIASES = {
|
|
579
|
-
party_a: ['甲方', '买方', '客户名称', '客户', '采购方', '需方', '购货方', '甲方名称', '买方名称'],
|
|
580
|
-
party_a_addr: ['甲方地址', '买方地址', '客户地址', '甲方住所', '注册地址'],
|
|
581
|
-
party_a_contact: ['甲方联系人', '买方联系人', '客户联系人', '项目联系人'],
|
|
582
|
-
party_a_phone: ['甲方电话', '买方电话', '联系电话', '客户电话', '甲方联系方式'],
|
|
583
|
-
party_b: ['乙方', '卖方', '供方', '销售方', '乙方名称', '卖方名称'],
|
|
584
|
-
party_b_addr: ['乙方地址', '卖方地址', '乙方住所'],
|
|
585
|
-
party_b_contact: ['乙方联系人', '卖方联系人', '客户经理', '销售经理'],
|
|
586
|
-
party_b_phone: ['乙方电话', '卖方电话'],
|
|
587
|
-
sign_date: ['签订日期', '签署日期', '签订时间', '合同日期', '日期'],
|
|
588
|
-
quote_date: ['报价日期', '报价时间'],
|
|
589
|
-
amount: ['合同总金额', '合同金额', '总金额', '合同总价', '项目总价', '金额合计', '合同总价款', '总价'],
|
|
590
|
-
amount_upper: ['大写金额', '金额大写', '人民币大写', '大写'],
|
|
591
|
-
software_fee: ['软件功能模块费用', '软件功能费用', '软件费用', '模块费用'],
|
|
592
|
-
license_fee: ['使用授权许可费用', '授权许可费用', '许可费用', '授权费用'],
|
|
593
|
-
license_qty: ['许可数量', '用户数', '授权用户数', '注册用户数'],
|
|
594
|
-
implement_fee: ['项目实施服务费用', '实施服务费用', '实施费用'],
|
|
595
|
-
ai_fee: ['合同AI扩展能力费用', 'AI扩展能力费用', 'AI能力费用', '智能助手费用'],
|
|
596
|
-
thirdparty_fee: ['第三方费用', '第三方产品费用'],
|
|
597
|
-
project_name: ['项目名称', '项目名称及内容', '合同名称'],
|
|
598
|
-
delivery: ['交付期限', '交付时间', '实施周期', '项目周期', '履行期限'],
|
|
599
|
-
payment: ['付款方式', '支付方式', '结算方式', '付款条件'],
|
|
600
|
-
sales: ['客户经理', '报价人', '销售代表'],
|
|
601
|
-
};
|
|
602
|
-
const NUMERIC_KEYS = new Set(['amount', 'software_fee', 'license_fee', 'license_qty', 'implement_fee', 'ai_fee', 'thirdparty_fee']);
|
|
603
|
-
function cleanLabel(label) {
|
|
604
|
-
let lab = label.replace(/\u00a0/gu, ' ').trim();
|
|
605
|
-
for (const ch of [':', ':', '(买方)', '(买方)', '(卖方)', '(卖方)'])
|
|
606
|
-
lab = lab.split(ch).join('');
|
|
607
|
-
return lab.replace(/[((]/gu, '').replace(/[))]/gu, '').trim();
|
|
608
|
-
}
|
|
609
|
-
export function scoreLabel(label, key) {
|
|
610
|
-
const lab = cleanLabel(label);
|
|
611
|
-
if (!lab)
|
|
612
|
-
return 0;
|
|
613
|
-
if (lab in FIELD_ALIASES)
|
|
614
|
-
return lab === key ? 100 : 0;
|
|
615
|
-
if (lab.includes('大写') && key !== 'amount_upper')
|
|
616
|
-
return 0;
|
|
617
|
-
if (lab.includes('小写') && key === 'amount_upper')
|
|
618
|
-
return 0;
|
|
619
|
-
const aliases = FIELD_ALIASES[key] ?? [];
|
|
620
|
-
if (aliases.includes(lab))
|
|
621
|
-
return 100;
|
|
622
|
-
for (const a of aliases) {
|
|
623
|
-
if (lab === a.replace(/[((]/gu, '').replace(/[))]/gu, ''))
|
|
624
|
-
return 98;
|
|
625
|
-
}
|
|
626
|
-
let best = 0;
|
|
627
|
-
for (const a of aliases) {
|
|
628
|
-
if (a.length >= 2 && lab.includes(a)) {
|
|
629
|
-
best = Math.max(best, Math.min(95, 70 + Math.floor((30 * a.length) / Math.max(lab.length, 1))));
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
for (const a of aliases) {
|
|
633
|
-
if (lab.length >= 3 && a.includes(lab))
|
|
634
|
-
best = Math.max(best, 60);
|
|
635
|
-
}
|
|
636
|
-
if (best)
|
|
637
|
-
return best;
|
|
638
|
-
for (const a of aliases) {
|
|
639
|
-
const common = [...new Set(a)].filter((ch) => lab.includes(ch)).length;
|
|
640
|
-
if (common >= 2)
|
|
641
|
-
best = Math.max(best, 40);
|
|
642
|
-
}
|
|
643
|
-
return best;
|
|
644
|
-
}
|
|
645
|
-
export function makeFiller(data) {
|
|
646
|
-
const valOf = (k) => {
|
|
647
|
-
const v = data[k];
|
|
648
|
-
if (v === null || v === undefined || v === '')
|
|
649
|
-
return '';
|
|
650
|
-
return NUMERIC_KEYS.has(k) ? fmtNum(v) : String(v);
|
|
651
|
-
};
|
|
652
|
-
return {
|
|
653
|
-
bestKey(label, floor) {
|
|
654
|
-
let bk = null;
|
|
655
|
-
let bs = 0;
|
|
656
|
-
for (const k of Object.keys(FIELD_ALIASES)) {
|
|
657
|
-
const s = scoreLabel(label, k);
|
|
658
|
-
if (s > bs) {
|
|
659
|
-
bk = k;
|
|
660
|
-
bs = s;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
return bs >= floor ? { key: bk, score: bs } : { key: null, score: bs };
|
|
664
|
-
},
|
|
665
|
-
valOf,
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
566
|
// ---------------------------------------------------------------- 操作定义
|
|
669
|
-
function assertContractDocument(path) {
|
|
670
|
-
const absolute = resolve(path);
|
|
671
|
-
if (!/\.(docx)$/iu.test(absolute)) {
|
|
672
|
-
throw contractValidationError('bad_document', '只支持 .docx 模板;.doc 老格式请先另存为 .docx。');
|
|
673
|
-
}
|
|
674
|
-
return absolute;
|
|
675
|
-
}
|
|
676
567
|
export const contractQuoteOperations = [
|
|
677
568
|
{
|
|
678
569
|
name: 'contract.quote.rmb',
|
|
@@ -824,122 +715,4 @@ export const contractQuoteOperations = [
|
|
|
824
715
|
return { status: 'DONE', data: normalized };
|
|
825
716
|
},
|
|
826
717
|
},
|
|
827
|
-
{
|
|
828
|
-
name: 'contract.quote.fill',
|
|
829
|
-
risk: 'read-with-upload',
|
|
830
|
-
inputSchema: {
|
|
831
|
-
type: 'object',
|
|
832
|
-
additionalProperties: false,
|
|
833
|
-
properties: {
|
|
834
|
-
template: { type: 'string', description: '真实合同模板 .docx 路径(必须)' },
|
|
835
|
-
data: { type: 'string', description: '数据 JSON 文件路径;含 __sections 时追加明细表' },
|
|
836
|
-
out: { type: 'string' },
|
|
837
|
-
detail: { type: 'string', enum: ['append', 'none'] },
|
|
838
|
-
mapOut: { type: 'string', description: '映射日志输出路径(filled/unfilled)' },
|
|
839
|
-
},
|
|
840
|
-
required: ['template', 'data', 'out'],
|
|
841
|
-
},
|
|
842
|
-
async execute(input) {
|
|
843
|
-
const template = assertContractDocument(String(input.template));
|
|
844
|
-
if (!existsSync(template)) {
|
|
845
|
-
throw contractValidationError('template_missing', '合同模板缺失:必须先取到真实的 .docx 模板才能生成合同。取不到就停止并请用户提供模板文件;禁止把报价单内容直接生成成一份合同。');
|
|
846
|
-
}
|
|
847
|
-
let data;
|
|
848
|
-
try {
|
|
849
|
-
data = JSON.parse(readFileSync(resolve(String(input.data)), 'utf8'));
|
|
850
|
-
}
|
|
851
|
-
catch (error) {
|
|
852
|
-
throw contractValidationError('bad_data', `数据 JSON 无法读取或解析:${error instanceof Error ? error.message : String(error)}`);
|
|
853
|
-
}
|
|
854
|
-
const detail = input.detail === 'none' ? 'none' : 'append';
|
|
855
|
-
const filler = makeFiller(data);
|
|
856
|
-
const { buffer, result } = fillDocx(template, filler, {
|
|
857
|
-
detail,
|
|
858
|
-
sections: (data['__sections'] ?? undefined),
|
|
859
|
-
amount: (data['amount'] ?? null),
|
|
860
|
-
});
|
|
861
|
-
const out = resolve(String(input.out));
|
|
862
|
-
writeFileSync(out, buffer);
|
|
863
|
-
const response = {
|
|
864
|
-
out,
|
|
865
|
-
template: basename(template),
|
|
866
|
-
filled_count: result.filled.length,
|
|
867
|
-
filled: result.filled,
|
|
868
|
-
unfilled: result.unfilled,
|
|
869
|
-
warning: result.unfilled.length > 0
|
|
870
|
-
? '存在未填充占位/空白:请把 unfilled 列表给用户确认,缺的信息让用户补充后再填,不要编造。'
|
|
871
|
-
: null,
|
|
872
|
-
};
|
|
873
|
-
if (input.mapOut) {
|
|
874
|
-
writeFileSync(resolve(String(input.mapOut)), JSON.stringify({ filled: result.filled, unfilled: result.unfilled }, null, 2), 'utf8');
|
|
875
|
-
response.map_out = resolve(String(input.mapOut));
|
|
876
|
-
}
|
|
877
|
-
return { status: 'DONE', data: response };
|
|
878
|
-
},
|
|
879
|
-
},
|
|
880
718
|
];
|
|
881
|
-
export function quoteContractContracts() {
|
|
882
|
-
return [
|
|
883
|
-
{
|
|
884
|
-
name: 'contract.quote.rmb',
|
|
885
|
-
summary: '数字转人民币大写(纯本地)',
|
|
886
|
-
risk: 'read',
|
|
887
|
-
inputSchema: {
|
|
888
|
-
type: 'object', additionalProperties: false,
|
|
889
|
-
properties: { num: { type: 'string' } }, required: ['num'],
|
|
890
|
-
},
|
|
891
|
-
},
|
|
892
|
-
{
|
|
893
|
-
name: 'contract.quote.sheets',
|
|
894
|
-
summary: '列出报价单 xlsx 的全部 sheet 名',
|
|
895
|
-
risk: 'read-with-upload',
|
|
896
|
-
inputSchema: {
|
|
897
|
-
type: 'object', additionalProperties: false,
|
|
898
|
-
properties: { path: { type: 'string' } }, required: ['path'],
|
|
899
|
-
},
|
|
900
|
-
},
|
|
901
|
-
{
|
|
902
|
-
name: 'contract.quote.parse',
|
|
903
|
-
summary: '解析报价单:xlsx 确定性解析;docx 仅无损提取(语义交给模型)',
|
|
904
|
-
risk: 'read-with-upload',
|
|
905
|
-
inputSchema: {
|
|
906
|
-
type: 'object', additionalProperties: false,
|
|
907
|
-
properties: {
|
|
908
|
-
path: { type: 'string' }, sheet: { type: 'string' },
|
|
909
|
-
keepRemark: { type: 'boolean' }, includeZero: { type: 'boolean' },
|
|
910
|
-
}, required: ['path'],
|
|
911
|
-
},
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
name: 'contract.quote.extract',
|
|
915
|
-
summary: '把 .docx 报价书无损提取为表格与段落(零语义判断)',
|
|
916
|
-
risk: 'read-with-upload',
|
|
917
|
-
inputSchema: {
|
|
918
|
-
type: 'object', additionalProperties: false,
|
|
919
|
-
properties: { path: { type: 'string' } }, required: ['path'],
|
|
920
|
-
},
|
|
921
|
-
},
|
|
922
|
-
{
|
|
923
|
-
name: 'contract.quote.normalize',
|
|
924
|
-
summary: '校验并归一化模型产出的报价 JSON(结构 + 金额自校验)',
|
|
925
|
-
risk: 'read',
|
|
926
|
-
inputSchema: {
|
|
927
|
-
type: 'object', additionalProperties: false,
|
|
928
|
-
properties: { data: { type: 'string' } }, required: ['data'],
|
|
929
|
-
},
|
|
930
|
-
},
|
|
931
|
-
{
|
|
932
|
-
name: 'contract.quote.fill',
|
|
933
|
-
summary: '用真实 .docx 模板 + 数据 JSON 生成合同 docx',
|
|
934
|
-
risk: 'read-with-upload',
|
|
935
|
-
inputSchema: {
|
|
936
|
-
type: 'object', additionalProperties: false,
|
|
937
|
-
properties: {
|
|
938
|
-
template: { type: 'string' }, data: { type: 'string' }, out: { type: 'string' },
|
|
939
|
-
detail: { type: 'string', enum: ['append', 'none'] }, mapOut: { type: 'string' },
|
|
940
|
-
}, required: ['template', 'data', 'out'],
|
|
941
|
-
},
|
|
942
|
-
},
|
|
943
|
-
];
|
|
944
|
-
}
|
|
945
|
-
export { labelBefore };
|
|
@@ -10,10 +10,11 @@ import { contractCardEbdfListOperations } from './card-ebdf-list.js';
|
|
|
10
10
|
import { contractCardRiskReportOperations } from './card-risk-report.js';
|
|
11
11
|
import { contractCardActionOperations } from './card-action.js';
|
|
12
12
|
import { contractCompareOperations } from './compare.js';
|
|
13
|
+
import { contractCompareScreenOperations } from './compare-screen.js';
|
|
13
14
|
import { contractCreditPageOperations } from './credit-page.js';
|
|
14
15
|
import { contractCustomerOperations } from './customer.js';
|
|
15
16
|
import { contractDocxVerifyOperations } from './docx-verify.js';
|
|
16
|
-
import {
|
|
17
|
+
import { contractDocxSlotsOperations } from './docx-slots.js';
|
|
17
18
|
import { contractElementsBuildOperations } from './elements-build.js';
|
|
18
19
|
import { contractFileDownloadOperations } from './file-download.js';
|
|
19
20
|
import { contractFirstScreenOperations } from './first-screen.js';
|
|
@@ -23,6 +24,7 @@ import { contractLedgerOperations } from './ledger.js';
|
|
|
23
24
|
import { contractModelTextOperations } from './modeltext.js';
|
|
24
25
|
import { contractPerformanceOperations } from './performance.js';
|
|
25
26
|
import { contractQuoteOperations } from './quote.js';
|
|
27
|
+
import { contractQuoteToContractOperations } from './quote-to-contract.js';
|
|
26
28
|
import { contractQuoteScreenOperations } from './quotescreen.js';
|
|
27
29
|
import { contractRecommendOperations } from './recommend.js';
|
|
28
30
|
import { contractRequestOperations } from './request.js';
|
|
@@ -46,7 +48,7 @@ function buildRegistry() {
|
|
|
46
48
|
...contractSubjectOperations,
|
|
47
49
|
...contractCustomerOperations,
|
|
48
50
|
...contractDocxVerifyOperations,
|
|
49
|
-
...
|
|
51
|
+
...contractDocxSlotsOperations,
|
|
50
52
|
...contractElementsBuildOperations,
|
|
51
53
|
...contractFirstScreenOperations,
|
|
52
54
|
...contractWorkflowOperations,
|
|
@@ -57,6 +59,7 @@ function buildRegistry() {
|
|
|
57
59
|
...contractSaveRecognizeOperations,
|
|
58
60
|
...contractRecommendOperations,
|
|
59
61
|
...contractCompareOperations,
|
|
62
|
+
...contractCompareScreenOperations,
|
|
60
63
|
...contractCreditPageOperations,
|
|
61
64
|
...contractAssistantOperations,
|
|
62
65
|
...contractPerformanceOperations,
|
|
@@ -69,6 +72,7 @@ function buildRegistry() {
|
|
|
69
72
|
...contractCardRiskReportOperations,
|
|
70
73
|
...contractCardActionOperations,
|
|
71
74
|
...contractQuoteOperations,
|
|
75
|
+
...contractQuoteToContractOperations,
|
|
72
76
|
...contractQuoteScreenOperations,
|
|
73
77
|
];
|
|
74
78
|
for (const handler of handlers) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
1
3
|
import { contractValidationError } from '../errors.js';
|
|
2
4
|
import { reviewPageUrl } from './page.js';
|
|
3
5
|
import { requireNonEmptyString } from './shared.js';
|
|
@@ -34,6 +36,133 @@ function collectRecords(value) {
|
|
|
34
36
|
}
|
|
35
37
|
return [];
|
|
36
38
|
}
|
|
39
|
+
/** 摘要里单条风险原文/说明/建议的截断长度,避免摘要本身又变成大结果。 */
|
|
40
|
+
const DIGEST_FIELD_LIMIT = 600;
|
|
41
|
+
/** 风险条目上限,超出只保留前 N 条并标注。 */
|
|
42
|
+
const DIGEST_MAX_RISKS = 50;
|
|
43
|
+
function isFile(path) {
|
|
44
|
+
try {
|
|
45
|
+
return existsSync(path) && statSync(path).isFile();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function clipText(value, limit = DIGEST_FIELD_LIMIT) {
|
|
52
|
+
const text = typeof value === 'string' ? value : value === null || value === undefined ? '' : String(value);
|
|
53
|
+
const flat = text.replace(/\s+/gu, ' ').trim();
|
|
54
|
+
return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 从规则标题里取规则名。
|
|
58
|
+
*
|
|
59
|
+
* 服务端把整条规则说明塞进 `title`(`【规则名称】X 【触发条件】…`),
|
|
60
|
+
* 直接展示会让摘要比原记录还长,因此统一抽成短名。
|
|
61
|
+
*/
|
|
62
|
+
export function ruleNameOf(title) {
|
|
63
|
+
const text = typeof title === 'string' ? title : String(title ?? '');
|
|
64
|
+
const hit = /【规则名称】\s*([^\s【]+)/u.exec(text);
|
|
65
|
+
if (hit)
|
|
66
|
+
return hit[1].trim();
|
|
67
|
+
const head = text.split('【')[0]?.trim();
|
|
68
|
+
return (head || text).replace(/\s+/gu, ' ').trim().slice(0, 60);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 把审查记录体(`scnr` 解析后的对象)压成摘要。
|
|
72
|
+
*
|
|
73
|
+
* 判读口径与 SKILL 一致:`customRuleNoRisk === true` 才算「判定无风险」,
|
|
74
|
+
* `null` / 缺省一律计入待关注;不按引擎未输出的风险等级自造高中低。
|
|
75
|
+
*/
|
|
76
|
+
export function buildReviewDigest(scnr, options = {}) {
|
|
77
|
+
const includePass = options.includePass !== false;
|
|
78
|
+
const includeOriginal = options.includeOriginal !== false;
|
|
79
|
+
const resultsByRole = (scnr.resultsByRole ?? {});
|
|
80
|
+
const roleNames = Object.keys(resultsByRole);
|
|
81
|
+
const role = String(scnr.currentRole ?? scnr.entryRole ?? roleNames[0] ?? '');
|
|
82
|
+
const selected = Array.isArray(scnr.rules?.selected) ? scnr.rules.selected : [];
|
|
83
|
+
const roles = {};
|
|
84
|
+
const risks = [];
|
|
85
|
+
const passed = [];
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
let total = 0;
|
|
88
|
+
let noRiskTotal = 0;
|
|
89
|
+
for (const name of roleNames) {
|
|
90
|
+
const items = Array.isArray(resultsByRole[name]) ? resultsByRole[name] : [];
|
|
91
|
+
const noRiskCount = items.filter((item) => item?.customRuleNoRisk === true).length;
|
|
92
|
+
roles[name] = { total: items.length, noRisk: noRiskCount, risk: items.length - noRiskCount };
|
|
93
|
+
total += items.length;
|
|
94
|
+
noRiskTotal += noRiskCount;
|
|
95
|
+
for (const item of items) {
|
|
96
|
+
const rule = ruleNameOf(item?.title);
|
|
97
|
+
if (item?.customRuleNoRisk === true) {
|
|
98
|
+
if (includePass && !passed.includes(rule))
|
|
99
|
+
passed.push(rule);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const dedupeKey = `${rule}||${clipText(item?.originalContent, 120)}`;
|
|
103
|
+
if (seen.has(dedupeKey))
|
|
104
|
+
continue;
|
|
105
|
+
seen.add(dedupeKey);
|
|
106
|
+
risks.push({
|
|
107
|
+
no: risks.length + 1,
|
|
108
|
+
rule,
|
|
109
|
+
status: String(item?.ruleStatus ?? '').trim(),
|
|
110
|
+
original: includeOriginal ? clipText(item?.originalContent, 300) : '',
|
|
111
|
+
explanation: clipText(item?.explanation),
|
|
112
|
+
suggestion: clipText(item?.suggestion),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const truncated = risks.length > DIGEST_MAX_RISKS;
|
|
117
|
+
return {
|
|
118
|
+
hasContent: total > 0,
|
|
119
|
+
role,
|
|
120
|
+
ruleTotal: selected.length || total,
|
|
121
|
+
noRisk: noRiskTotal,
|
|
122
|
+
risk: risks.length,
|
|
123
|
+
roles,
|
|
124
|
+
risks: truncated ? risks.slice(0, DIGEST_MAX_RISKS) : risks,
|
|
125
|
+
passed,
|
|
126
|
+
successList: Array.isArray(scnr.successList) ? scnr.successList.map((item) => clipText(item, 200)) : [],
|
|
127
|
+
risksTruncated: truncated,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** 从审查记录数组里取出第一条可解析的 `scnr`。 */
|
|
131
|
+
function parseScnrFromRecords(records) {
|
|
132
|
+
for (const record of records) {
|
|
133
|
+
const value = record?.scnr;
|
|
134
|
+
if (value === null || value === undefined || value === '')
|
|
135
|
+
continue;
|
|
136
|
+
if (typeof value === 'object')
|
|
137
|
+
return { parsed: value, reason: '' };
|
|
138
|
+
const text = String(value).trim();
|
|
139
|
+
if (!text)
|
|
140
|
+
continue;
|
|
141
|
+
// 预览被截断的残句解析必然失败,这里要给出可行动的原因,而不是抛语法错。
|
|
142
|
+
try {
|
|
143
|
+
return { parsed: JSON.parse(text), reason: '' };
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return { parsed: null, reason: `scnr 不是合法 JSON(${text.length} 字符,疑似预览截断),请改用 ref 指向落盘文件` };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { parsed: null, reason: '记录里没有 scnr' };
|
|
150
|
+
}
|
|
151
|
+
/** 读取落盘的导出结果文件,兼容 `{envelope:...}` 与裸 envelope 两种层级。 */
|
|
152
|
+
function readPersistedEnvelope(path) {
|
|
153
|
+
if (!isFile(path))
|
|
154
|
+
throw contractValidationError('ref_not_found', `落盘结果文件不存在:${path}`);
|
|
155
|
+
let parsed;
|
|
156
|
+
try {
|
|
157
|
+
parsed = JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/u, ''));
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
161
|
+
throw contractValidationError('ref_invalid', `落盘结果不是合法 JSON:${message}`);
|
|
162
|
+
}
|
|
163
|
+
const envelope = parsed?.envelope;
|
|
164
|
+
return envelope && typeof envelope === 'object' ? envelope : parsed;
|
|
165
|
+
}
|
|
37
166
|
export const contractReviewOperations = [
|
|
38
167
|
{
|
|
39
168
|
name: 'contract.review.upload',
|
|
@@ -84,7 +213,7 @@ export const contractReviewOperations = [
|
|
|
84
213
|
: { flowId: AI_REVIEW_PREWARM_FLOW_ID, enabled: false },
|
|
85
214
|
warnings,
|
|
86
215
|
url: reviewPageUrl(session.baseUrl, files),
|
|
87
|
-
page: { width:
|
|
216
|
+
page: { width: 1300 },
|
|
88
217
|
note: '已复用会话中已有的 fileId,未重新上传;预审与 module 无关,可直接打开审查页',
|
|
89
218
|
},
|
|
90
219
|
};
|
|
@@ -132,8 +261,8 @@ export const contractReviewOperations = [
|
|
|
132
261
|
: { flowId: AI_REVIEW_PREWARM_FLOW_ID, enabled: false },
|
|
133
262
|
warnings,
|
|
134
263
|
url: reviewPageUrl(session.baseUrl, files),
|
|
135
|
-
page: { width:
|
|
136
|
-
note: '上传完成并已触发预审预热(同一 fileId 只触发一次);把 url 原样放进 browsertool 的 arguments.url,并带 width:
|
|
264
|
+
page: { width: 1300 },
|
|
265
|
+
note: '上传完成并已触发预审预热(同一 fileId 只触发一次);把 url 原样放进 browsertool 的 arguments.url,并带 width: 1300;不要做整体编码',
|
|
137
266
|
},
|
|
138
267
|
};
|
|
139
268
|
},
|
|
@@ -208,6 +337,10 @@ export const contractReviewOperations = [
|
|
|
208
337
|
timeoutMs: 120_000,
|
|
209
338
|
});
|
|
210
339
|
const records = collectRecords(value);
|
|
340
|
+
const scnrChars = records.reduce((sum, item) => {
|
|
341
|
+
const scnr = item?.scnr;
|
|
342
|
+
return sum + (typeof scnr === 'string' ? scnr.length : 0);
|
|
343
|
+
}, 0);
|
|
211
344
|
return {
|
|
212
345
|
status: records.length ? 'COMPLETE' : 'EMPTY',
|
|
213
346
|
data: {
|
|
@@ -216,7 +349,100 @@ export const contractReviewOperations = [
|
|
|
216
349
|
aiId: AI_REVIEW_ASSISTANT_ID,
|
|
217
350
|
hasContent: records.length > 0,
|
|
218
351
|
records,
|
|
219
|
-
raw
|
|
352
|
+
// 2026-11-16:有记录时不再回传 raw。审查记录常达 20 万字符,而 raw 与 records
|
|
353
|
+
// 内容几乎完全重复,双双回传会让输出翻倍并撞上 stdout 预算被截断——
|
|
354
|
+
// 截断后 scnr 会变成「看起来像 JSON 的残句」,调用方直接 parse 极易误判。
|
|
355
|
+
...(records.length ? {} : { raw: value }),
|
|
356
|
+
scnrChars,
|
|
357
|
+
...(records.length
|
|
358
|
+
? { nextStep: '要看结论请看 digest 字段或改跑 contract.review.digest(一条命令出摘要,约 8KB)' }
|
|
359
|
+
: {}),
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: 'contract.review.digest',
|
|
366
|
+
async execute(input, { host }) {
|
|
367
|
+
// 一条命令完成「取记录 → 解析 scnr → 压摘要」。
|
|
368
|
+
// 本 operation 存在的原因(2026-11-16 实测):审查记录 18 万字符、导出信封 1MB,
|
|
369
|
+
// 编排层要自己解嵌在字符串里的 JSON,连踩「stdio 污染 / BOM / 预览截断 / 缓存层级」
|
|
370
|
+
// 四类坑,单次预审为此多耗 9 轮工具往返。摘要后约 8KB,一轮即可拿到结论。
|
|
371
|
+
const refPath = typeof input.ref === 'string' && input.ref.trim() ? resolve(input.ref.trim()) : '';
|
|
372
|
+
const rawFileId = input.fileId;
|
|
373
|
+
const fileId = refPath
|
|
374
|
+
? (rawFileId === undefined || rawFileId === null || rawFileId === ''
|
|
375
|
+
? ''
|
|
376
|
+
: requireNonEmptyString(rawFileId, 'fileId', 64))
|
|
377
|
+
: requireNonEmptyString(rawFileId, 'fileId', 64);
|
|
378
|
+
const includePass = input.includePass !== false;
|
|
379
|
+
const includeOriginal = input.includeOriginal !== false;
|
|
380
|
+
let records;
|
|
381
|
+
let sclx = CONTRACT_REVIEW_SCLX;
|
|
382
|
+
let source = 'api';
|
|
383
|
+
if (refPath) {
|
|
384
|
+
const envelope = readPersistedEnvelope(refPath);
|
|
385
|
+
records = collectRecords(envelope);
|
|
386
|
+
const fromRecords = records[0]?.sclx;
|
|
387
|
+
if (typeof fromRecords === 'string' && fromRecords.trim())
|
|
388
|
+
sclx = fromRecords.trim();
|
|
389
|
+
source = 'ref';
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
sclx = normalizeSclx(input.sclx);
|
|
393
|
+
const flowId = (input.flowId === undefined || input.flowId === null || input.flowId === '')
|
|
394
|
+
? AI_REVIEW_PREWARM_FLOW_ID
|
|
395
|
+
: requireNonEmptyString(input.flowId, 'flowId', 64);
|
|
396
|
+
const value = await host.contractRequest({
|
|
397
|
+
method: 'POST',
|
|
398
|
+
path: '/api/ebd/contract/ai/getAiReviewRecord',
|
|
399
|
+
body: { flowId, sclx, fileId },
|
|
400
|
+
timeoutMs: 120_000,
|
|
401
|
+
});
|
|
402
|
+
records = collectRecords(value);
|
|
403
|
+
}
|
|
404
|
+
if (!records.length) {
|
|
405
|
+
return {
|
|
406
|
+
status: 'EMPTY',
|
|
407
|
+
data: {
|
|
408
|
+
fileId,
|
|
409
|
+
sclx,
|
|
410
|
+
source,
|
|
411
|
+
hasContent: false,
|
|
412
|
+
note: '该文件暂无审查结果:若刚触发预审,需等待审查跑完再取;确认 sclx=8 且未带 ai_id',
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const { parsed, reason } = parseScnrFromRecords(records);
|
|
417
|
+
if (!parsed) {
|
|
418
|
+
throw contractValidationError('scnr_unparsable', `审查记录无法解析:${reason}`);
|
|
419
|
+
}
|
|
420
|
+
const digest = buildReviewDigest(parsed, { includePass, includeOriginal });
|
|
421
|
+
const outPath = typeof input.out === 'string' && input.out.trim() ? resolve(input.out.trim()) : '';
|
|
422
|
+
if (outPath) {
|
|
423
|
+
const { writeFileSync, mkdirSync } = await import('node:fs');
|
|
424
|
+
const { dirname } = await import('node:path');
|
|
425
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
426
|
+
writeFileSync(outPath, JSON.stringify(digest, null, 2), 'utf8');
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
status: 'COMPLETE',
|
|
430
|
+
data: {
|
|
431
|
+
fileId,
|
|
432
|
+
sclx,
|
|
433
|
+
source,
|
|
434
|
+
hasContent: digest.hasContent,
|
|
435
|
+
role: digest.role,
|
|
436
|
+
ruleTotal: digest.ruleTotal,
|
|
437
|
+
noRisk: digest.noRisk,
|
|
438
|
+
risk: digest.risk,
|
|
439
|
+
roles: digest.roles,
|
|
440
|
+
risks: digest.risks,
|
|
441
|
+
passed: digest.passed,
|
|
442
|
+
successList: digest.successList,
|
|
443
|
+
risksTruncated: digest.risksTruncated,
|
|
444
|
+
...(outPath ? { out: outPath } : {}),
|
|
445
|
+
note: '摘要已按「customRuleNoRisk === true 才算无风险」口径生成;风险条目含原文/说明/建议,可直接用于改条款',
|
|
220
446
|
},
|
|
221
447
|
};
|
|
222
448
|
},
|