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
|
@@ -2,18 +2,10 @@ import { contractValidationError } from '../errors.js';
|
|
|
2
2
|
import { reviewPageUrl } from './page.js';
|
|
3
3
|
import { requireNonEmptyString } from './shared.js';
|
|
4
4
|
import { assertContractDocument, uploadFile } from './upload.js';
|
|
5
|
+
import { AI_REVIEW_PREWARM_FLOW_ID, ensurePrewarmed, prewarmAll } from '../prewarm.js';
|
|
5
6
|
/** 固定 AI 审查助手 ID,只用于导出审查记录接口,不要拼到审查页地址上。 */
|
|
6
7
|
export const AI_REVIEW_ASSISTANT_ID = '1326842382967570463';
|
|
7
|
-
|
|
8
|
-
* 预审预热流程 ID(固定业务常量,禁止替换)。
|
|
9
|
-
*
|
|
10
|
-
* `saveInternalRecord` 是合同预审的预处理接口:调用后服务端即开始跑预审,
|
|
11
|
-
* 用户真正打开审查页时结果已就绪。因为预审耗时较长,故在上传成功那一刻就触发。
|
|
12
|
-
*/
|
|
13
|
-
export const AI_REVIEW_PREWARM_FLOW_ID = '1269716062340284522';
|
|
14
|
-
const PREWARM_PATH = '/api/ebd/contract/ai/saveInternalRecord';
|
|
15
|
-
const PREWARM_TIMEOUT_MS = 30_000;
|
|
16
|
-
const PREWARM_ERROR = 'prewarm_error';
|
|
8
|
+
export { AI_REVIEW_PREWARM_FLOW_ID };
|
|
17
9
|
const MAX_FILES = 10;
|
|
18
10
|
/** 合同预审固定只走风险审查,sclx 取值为 8(2026-11-09 用户确认)。 */
|
|
19
11
|
export const CONTRACT_REVIEW_SCLX = '8';
|
|
@@ -22,39 +14,6 @@ export const CONTRACT_REVIEW_SCLX = '8';
|
|
|
22
14
|
* 代码保留备查,但对应触发入口已全部屏蔽,不再作为 sclx 的合法取值。
|
|
23
15
|
*/
|
|
24
16
|
export const LEGACY_SCLX_PATTERN = /^[1-3](?:,[1-3]){0,2}$/u;
|
|
25
|
-
/**
|
|
26
|
-
* 触发预审预热。
|
|
27
|
-
*
|
|
28
|
-
* 刻意**不抛出异常**:预热只是加速手段,失败不影响上传与后续审查,
|
|
29
|
-
* 因此把失败收敛成 `{ ok: false, error }` 交给调用方汇总成 warnings。
|
|
30
|
-
*/
|
|
31
|
-
async function prewarmOne(host, fileId) {
|
|
32
|
-
try {
|
|
33
|
-
await host.contractRequest({
|
|
34
|
-
method: 'POST',
|
|
35
|
-
path: PREWARM_PATH,
|
|
36
|
-
body: { flowId: AI_REVIEW_PREWARM_FLOW_ID, fileId },
|
|
37
|
-
timeoutMs: PREWARM_TIMEOUT_MS,
|
|
38
|
-
// 触发型接口:成功时响应体为空,代表"预审已在执行"。
|
|
39
|
-
// 不能走业务码判定,否则空体会被判成业务失败。
|
|
40
|
-
okOnHttpSuccess: true,
|
|
41
|
-
});
|
|
42
|
-
return { fileId, ok: true };
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
-
const structured = error;
|
|
47
|
-
const code = structured?.code === undefined ? '' : ` code=${String(structured.code)}`;
|
|
48
|
-
const raw = typeof structured?.details?.raw === 'string'
|
|
49
|
-
? ` raw=${String(structured.details.raw).slice(0, 300)}`
|
|
50
|
-
: '';
|
|
51
|
-
return { fileId, ok: false, error: `${message}${code}${raw}` };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** 多文件并行预热,避免串行累加等待。 */
|
|
55
|
-
async function prewarmAll(host, fileIds) {
|
|
56
|
-
return Promise.all(fileIds.map((fileId) => prewarmOne(host, fileId)));
|
|
57
|
-
}
|
|
58
17
|
function normalizeSclx(value) {
|
|
59
18
|
if (value === undefined || value === null || value === '')
|
|
60
19
|
return CONTRACT_REVIEW_SCLX;
|
|
@@ -79,9 +38,61 @@ export const contractReviewOperations = [
|
|
|
79
38
|
{
|
|
80
39
|
name: 'contract.review.upload',
|
|
81
40
|
async execute(input, { host }) {
|
|
41
|
+
const prewarmEnabled = input.prewarm !== false;
|
|
42
|
+
const existingIds = input.fileIds;
|
|
43
|
+
// ---- 路径一:复用当前会话已有的 fileId(2026-11-12 用户定稿)----
|
|
44
|
+
// 预审与 module 无关,所以只要手上已有 fileId 就直接用,不必重新上传。
|
|
45
|
+
// 典型场景:发起流程时已经上传过,点「预审」时不该再传一遍。
|
|
46
|
+
if (existingIds !== undefined) {
|
|
47
|
+
if (input.paths !== undefined) {
|
|
48
|
+
throw contractValidationError('input_conflict', 'paths 与 fileIds 只能二选一:要么本地上传,要么复用已有 fileId');
|
|
49
|
+
}
|
|
50
|
+
if (!Array.isArray(existingIds) || existingIds.length === 0) {
|
|
51
|
+
throw contractValidationError('file_ids_required', 'fileIds 必须是非空的 fileId 数组');
|
|
52
|
+
}
|
|
53
|
+
if (existingIds.length > MAX_FILES) {
|
|
54
|
+
throw contractValidationError('file_ids_too_many', `一次最多处理 ${MAX_FILES} 份合同`);
|
|
55
|
+
}
|
|
56
|
+
const names = Array.isArray(input.fileNames) ? input.fileNames : [];
|
|
57
|
+
const files = existingIds.map((rawItem, index) => {
|
|
58
|
+
const fileId = requireNonEmptyString(rawItem, `fileIds[${index}]`, 64).trim();
|
|
59
|
+
const name = typeof names[index] === 'string' ? String(names[index]) : '';
|
|
60
|
+
return { fileId, name, size: 0, md5: '', reused: true };
|
|
61
|
+
});
|
|
62
|
+
const prewarm = prewarmEnabled ? await ensurePrewarmed(host, files.map((file) => file.fileId)) : null;
|
|
63
|
+
const warnings = (prewarm?.results ?? [])
|
|
64
|
+
.filter((item) => !item.ok)
|
|
65
|
+
.map((item) => `预审预热失败(fileId ${item.fileId}):${item.error}`);
|
|
66
|
+
if (!prewarmEnabled) {
|
|
67
|
+
warnings.push('已按 prewarm=false 跳过预审预热,打开审查页时才会开始跑预审');
|
|
68
|
+
}
|
|
69
|
+
const session = await host.getSession();
|
|
70
|
+
return {
|
|
71
|
+
status: 'COMPLETE',
|
|
72
|
+
data: {
|
|
73
|
+
files,
|
|
74
|
+
reusedFileIds: true,
|
|
75
|
+
prewarm: prewarm
|
|
76
|
+
? {
|
|
77
|
+
flowId: AI_REVIEW_PREWARM_FLOW_ID,
|
|
78
|
+
enabled: true,
|
|
79
|
+
okCount: prewarm.okCount,
|
|
80
|
+
failCount: prewarm.failCount,
|
|
81
|
+
skippedCount: prewarm.skippedCount,
|
|
82
|
+
results: prewarm.results,
|
|
83
|
+
}
|
|
84
|
+
: { flowId: AI_REVIEW_PREWARM_FLOW_ID, enabled: false },
|
|
85
|
+
warnings,
|
|
86
|
+
url: reviewPageUrl(session.baseUrl, files),
|
|
87
|
+
page: { width: 1000 },
|
|
88
|
+
note: '已复用会话中已有的 fileId,未重新上传;预审与 module 无关,可直接打开审查页',
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// ---- 路径二:本地上传(uploadFile 内部已触发预热)----
|
|
82
93
|
const paths = input.paths;
|
|
83
94
|
if (!Array.isArray(paths) || paths.length === 0) {
|
|
84
|
-
throw contractValidationError('paths_required', 'paths
|
|
95
|
+
throw contractValidationError('paths_required', 'paths 必须是非空的本地合同文件路径数组,或改用 fileIds 复用已有文件');
|
|
85
96
|
}
|
|
86
97
|
if (paths.length > MAX_FILES) {
|
|
87
98
|
throw contractValidationError('paths_too_many', `一次最多上传 ${MAX_FILES} 份合同`);
|
|
@@ -90,16 +101,14 @@ export const contractReviewOperations = [
|
|
|
90
101
|
for (const rawPath of paths) {
|
|
91
102
|
const path = requireNonEmptyString(rawPath, 'paths[]', 1000);
|
|
92
103
|
assertContractDocument(path);
|
|
93
|
-
files.push(await uploadFile(host, { path, module: 'ebContract' }));
|
|
104
|
+
files.push(await uploadFile(host, { path, module: 'ebContract', prewarm: prewarmEnabled }));
|
|
94
105
|
}
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
// 预热失败不影响上传结果,只记 warning(用户仍可正常打开审查页,只是要等)。
|
|
98
|
-
const prewarmEnabled = input.prewarm !== false;
|
|
106
|
+
// uploadFile 已在上传成功那一刻触发过预热;这里再调一次 ensurePrewarmed 只是兜底,
|
|
107
|
+
// 命中"本轮已预热"会直接跳过,不会重复请求接口。
|
|
99
108
|
const prewarm = prewarmEnabled
|
|
100
|
-
? await
|
|
109
|
+
? await ensurePrewarmed(host, files.map((file) => file.fileId))
|
|
101
110
|
: null;
|
|
102
|
-
const warnings = (prewarm ?? [])
|
|
111
|
+
const warnings = (prewarm?.results ?? [])
|
|
103
112
|
.filter((item) => !item.ok)
|
|
104
113
|
.map((item) => `预审预热失败(fileId ${item.fileId}):${item.error}`);
|
|
105
114
|
if (!prewarmEnabled) {
|
|
@@ -110,19 +119,21 @@ export const contractReviewOperations = [
|
|
|
110
119
|
status: 'COMPLETE',
|
|
111
120
|
data: {
|
|
112
121
|
files,
|
|
122
|
+
reusedFileIds: false,
|
|
113
123
|
prewarm: prewarm
|
|
114
124
|
? {
|
|
115
125
|
flowId: AI_REVIEW_PREWARM_FLOW_ID,
|
|
116
126
|
enabled: true,
|
|
117
|
-
okCount: prewarm.
|
|
118
|
-
failCount: prewarm.
|
|
119
|
-
|
|
127
|
+
okCount: prewarm.okCount,
|
|
128
|
+
failCount: prewarm.failCount,
|
|
129
|
+
skippedCount: prewarm.skippedCount,
|
|
130
|
+
results: prewarm.results,
|
|
120
131
|
}
|
|
121
132
|
: { flowId: AI_REVIEW_PREWARM_FLOW_ID, enabled: false },
|
|
122
133
|
warnings,
|
|
123
134
|
url: reviewPageUrl(session.baseUrl, files),
|
|
124
135
|
page: { width: 1000 },
|
|
125
|
-
note: '
|
|
136
|
+
note: '上传完成并已触发预审预热(同一 fileId 只触发一次);把 url 原样放进 browsertool 的 arguments.url,并带 width: 1000;不要做整体编码',
|
|
126
137
|
},
|
|
127
138
|
};
|
|
128
139
|
},
|
|
@@ -134,10 +145,13 @@ export const contractReviewOperations = [
|
|
|
134
145
|
if (input.fileIds !== undefined) {
|
|
135
146
|
throw contractValidationError('input_conflict', 'fileId 与 fileIds 只能二选一');
|
|
136
147
|
}
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
// 显式补触发:默认绕过本地去重,确保真的发一次请求。
|
|
149
|
+
const force = input.force !== false;
|
|
150
|
+
const summary = await ensurePrewarmed(host, [fileId], { force });
|
|
151
|
+
const result = summary.results[0];
|
|
152
|
+
if (!result || !result.ok) {
|
|
139
153
|
// 独立调用时用户是显式要预热,失败要如实报错而不是静默吞掉。
|
|
140
|
-
throw new Error(`预审预热失败:${result
|
|
154
|
+
throw new Error(`预审预热失败:${result?.error ?? '未知原因'}`);
|
|
141
155
|
}
|
|
142
156
|
return {
|
|
143
157
|
status: 'COMPLETE',
|
|
@@ -183,6 +197,7 @@ export const contractReviewOperations = [
|
|
|
183
197
|
const sclx = normalizeSclx(input.sclx);
|
|
184
198
|
// 请求体与前端实际调用保持一致:flowId + sclx + fileId。
|
|
185
199
|
// 注意:不要带 ai_id —— 带上会导致服务端返回空记录(2026-11-09 实测)。
|
|
200
|
+
// 预审与文件上传时的 module 无关,任何来源的 fileId 都可导出。
|
|
186
201
|
const flowId = (input.flowId === undefined || input.flowId === null || input.flowId === '')
|
|
187
202
|
? AI_REVIEW_PREWARM_FLOW_ID
|
|
188
203
|
: requireNonEmptyString(input.flowId, 'flowId', 64);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { contractValidationError } from '../errors.js';
|
|
2
|
+
import { FLOW_PRESETS } from './flow.js';
|
|
3
|
+
import { requireNonEmptyString } from './shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* 智能填单识别记录保存接口。
|
|
6
|
+
*
|
|
7
|
+
* 合同流程发起前的要素抽取结果**不再**以「字段ID:字段值」写进 `customParams`,
|
|
8
|
+
* 而是先由本接口落库,再用返回的 `aiExtraId` 回传流程组件。
|
|
9
|
+
*
|
|
10
|
+
* `customParams` 组成(2026-11-10 修正):
|
|
11
|
+
* - `aiExtraId`:本接口返回的识别记录 ID;
|
|
12
|
+
* - `openSource`:固定 `xiaoE`;
|
|
13
|
+
* - **合同文件字段**:附件字段 ID → fileId。文件必须走 `customParams` 传给流程组件,
|
|
14
|
+
* 只传 `attachmentIds` 不足以让附件挂到表单字段上(2026-11-10 用户指定)。
|
|
15
|
+
* 其余要素字段仍不走 `customParams`。
|
|
16
|
+
*/
|
|
17
|
+
export const SAVE_RECOGNIZE_PATH = '/api/ai/application/smartfill/data/saveRecognizeRecord';
|
|
18
|
+
/** 回传 E10 流程组件时固定使用的来源标识。 */
|
|
19
|
+
export const OPEN_SOURCE = 'xiaoE';
|
|
20
|
+
function asPlainObject(value, name) {
|
|
21
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
22
|
+
throw contractValidationError('recognize_result_invalid', `${name} 必须是 JSON 对象`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 校验识别结果的顶层结构,返回可直接作为接口入参的 JSON 字符串。
|
|
28
|
+
*
|
|
29
|
+
* 接口要求 `recognizeResult` 是**字符串**(不是嵌套对象),且顶层固定
|
|
30
|
+
* `isSuccess` / `mainTable` / `subTables` 三个字段;`subTables` 无明细时必须是 `[]`。
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeRecognizeResult(value) {
|
|
33
|
+
let parsed;
|
|
34
|
+
if (typeof value === 'string') {
|
|
35
|
+
const text = value.trim();
|
|
36
|
+
if (!text)
|
|
37
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult 不能为空');
|
|
38
|
+
try {
|
|
39
|
+
parsed = asPlainObject(JSON.parse(text), 'recognizeResult');
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof Error && error.name === 'ContractCliError')
|
|
43
|
+
throw error;
|
|
44
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult 不是合法 JSON');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
parsed = asPlainObject(value, 'recognizeResult');
|
|
49
|
+
}
|
|
50
|
+
if (typeof parsed.isSuccess !== 'boolean') {
|
|
51
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.isSuccess 必须是布尔值');
|
|
52
|
+
}
|
|
53
|
+
const mainTable = asPlainObject(parsed.mainTable, 'recognizeResult.mainTable');
|
|
54
|
+
if (!Array.isArray(mainTable.rows)) {
|
|
55
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.mainTable.rows 必须是数组');
|
|
56
|
+
}
|
|
57
|
+
if (!Array.isArray(parsed.subTables)) {
|
|
58
|
+
throw contractValidationError('recognize_result_invalid', 'recognizeResult.subTables 必须是数组(无明细传 [])');
|
|
59
|
+
}
|
|
60
|
+
return JSON.stringify({ isSuccess: parsed.isSuccess, mainTable, subTables: parsed.subTables });
|
|
61
|
+
}
|
|
62
|
+
function extractAiExtraId(value) {
|
|
63
|
+
const root = (value ?? {});
|
|
64
|
+
const data = (root.data ?? root);
|
|
65
|
+
const candidate = data.aiExtraId ?? data.id ?? root.aiExtraId ?? root.id;
|
|
66
|
+
const text = candidate === undefined || candidate === null ? '' : String(candidate).trim();
|
|
67
|
+
if (!text) {
|
|
68
|
+
throw contractValidationError('ai_extra_id_missing', '保存接口未返回 aiExtraId,不能继续打开流程页');
|
|
69
|
+
}
|
|
70
|
+
return text;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 解析可选的流程预设。
|
|
74
|
+
*
|
|
75
|
+
* 与 `flow.ts` 的 `resolveFlow` 不同:**不再强制限定四个预设**。
|
|
76
|
+
* 四类以外的流程(如测试环境的「销售合同起草流程」)可以传自定义名称,
|
|
77
|
+
* 只要同时用 `workflowId` 明确流程模板 ID 即可;不传 `flow` 也允许。
|
|
78
|
+
*/
|
|
79
|
+
function resolveFlowPreset(value) {
|
|
80
|
+
if (value === undefined || value === null || value === '')
|
|
81
|
+
return undefined;
|
|
82
|
+
const raw = requireNonEmptyString(value, 'flow', 64).trim();
|
|
83
|
+
const exact = FLOW_PRESETS.find((preset) => preset.key === raw || preset.label === raw);
|
|
84
|
+
if (exact)
|
|
85
|
+
return { key: exact.key, label: exact.label, workflowId: exact.workflowId };
|
|
86
|
+
const fuzzy = FLOW_PRESETS.filter((preset) => raw.includes(preset.key) || preset.label.includes(raw));
|
|
87
|
+
if (fuzzy.length === 1) {
|
|
88
|
+
return { key: fuzzy[0].key, label: fuzzy[0].label, workflowId: fuzzy[0].workflowId };
|
|
89
|
+
}
|
|
90
|
+
// 非四类预设:当作自定义流程名,workflowId 必须由调用方显式提供。
|
|
91
|
+
return { key: raw, label: raw, workflowId: '' };
|
|
92
|
+
}
|
|
93
|
+
export const contractSaveRecognizeOperations = [
|
|
94
|
+
{
|
|
95
|
+
name: 'contract.flow.save-recognize-record',
|
|
96
|
+
async execute(input, { host }) {
|
|
97
|
+
const flow = resolveFlowPreset(input.flow);
|
|
98
|
+
const explicitWorkflowId = input.workflowId === undefined || input.workflowId === null || input.workflowId === ''
|
|
99
|
+
? ''
|
|
100
|
+
: requireNonEmptyString(input.workflowId, 'workflowId', 64).trim();
|
|
101
|
+
const workflowId = explicitWorkflowId || flow?.workflowId || '';
|
|
102
|
+
if (!workflowId) {
|
|
103
|
+
throw contractValidationError('workflow_id_required', 'flow 与 workflowId 至少传一个;四类预设之外的流程(如销售合同起草流程)必须显式传 workflowId');
|
|
104
|
+
}
|
|
105
|
+
if (!/^[1-9]\d*$/.test(workflowId)) {
|
|
106
|
+
throw contractValidationError('workflow_id_invalid', 'workflowId 必须是纯数字的流程模板 ID');
|
|
107
|
+
}
|
|
108
|
+
const recognizeResult = normalizeRecognizeResult(input.recognizeResult);
|
|
109
|
+
const body = { workflowId, recognizeResult };
|
|
110
|
+
const attachmentIds = typeof input.attachmentIds === 'string' ? input.attachmentIds.trim() : '';
|
|
111
|
+
if (attachmentIds)
|
|
112
|
+
body.attachmentIds = attachmentIds;
|
|
113
|
+
// 合同文件字段:必须随 customParams 交给流程组件,否则附件挂不到表单字段上。
|
|
114
|
+
// 未显式传 attachmentFileId 时,取 attachmentIds 的首个文件。
|
|
115
|
+
const attachmentFieldId = input.attachmentFieldId === undefined
|
|
116
|
+
|| input.attachmentFieldId === null
|
|
117
|
+
|| input.attachmentFieldId === ''
|
|
118
|
+
? ''
|
|
119
|
+
: requireNonEmptyString(input.attachmentFieldId, 'attachmentFieldId', 64).trim();
|
|
120
|
+
if (attachmentFieldId && !/^[1-9]\d*$/.test(attachmentFieldId)) {
|
|
121
|
+
throw contractValidationError('attachment_field_id_invalid', 'attachmentFieldId 必须是从表单字段定义中取得的纯数字字段 ID');
|
|
122
|
+
}
|
|
123
|
+
const explicitFileId = typeof input.attachmentFileId === 'string' ? input.attachmentFileId.trim() : '';
|
|
124
|
+
const attachmentFileId = explicitFileId || (attachmentIds ? attachmentIds.split(',')[0].trim() : '');
|
|
125
|
+
if (attachmentFieldId && !attachmentFileId) {
|
|
126
|
+
throw contractValidationError('attachment_file_id_missing', '传了 attachmentFieldId 就必须有文件 ID:请传 attachmentFileId,或在 attachmentIds 里带上本次文件');
|
|
127
|
+
}
|
|
128
|
+
const response = await host.contractRequest({
|
|
129
|
+
method: 'POST',
|
|
130
|
+
path: SAVE_RECOGNIZE_PATH,
|
|
131
|
+
body,
|
|
132
|
+
});
|
|
133
|
+
const aiExtraId = extractAiExtraId(response);
|
|
134
|
+
const customParams = { aiExtraId, openSource: OPEN_SOURCE };
|
|
135
|
+
if (attachmentFieldId)
|
|
136
|
+
customParams[attachmentFieldId] = attachmentFileId;
|
|
137
|
+
return {
|
|
138
|
+
status: 'COMPLETE',
|
|
139
|
+
data: {
|
|
140
|
+
flow: flow?.key ?? null,
|
|
141
|
+
flowLabel: flow?.label ?? null,
|
|
142
|
+
workflowId,
|
|
143
|
+
aiExtraId,
|
|
144
|
+
attachmentFieldId: attachmentFieldId || null,
|
|
145
|
+
attachmentFileId: attachmentFileId || null,
|
|
146
|
+
customParams,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
];
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { contractValidationError } from '../errors.js';
|
|
4
|
+
import { requireNonEmptyString } from './shared.js';
|
|
5
|
+
/**
|
|
6
|
+
* 合同摘要数据校验(本地,零依赖)。
|
|
7
|
+
*
|
|
8
|
+
* 迁移自 `scripts/validate_summary.py`(2026-11-12 第一批)。
|
|
9
|
+
* 定位不变:合同措辞千变万化,要素与摘要由模型读正文后生成;
|
|
10
|
+
* 本 operation 只做「校验兜底」,拦截已知会污染审批单的错误,**不替模型取值**。
|
|
11
|
+
*
|
|
12
|
+
* 输出与 Python 版逐字段一致(ok / merged / sectionCount / rowCount / fails / warns),
|
|
13
|
+
* 以便新旧两版可直接 diff。
|
|
14
|
+
*
|
|
15
|
+
* 语义说明:信封 `ok=true` 表示「命令执行成功」;`data.ok=false` 表示「摘要校验不通过」。
|
|
16
|
+
* 校验不通过不是执行失败,因此不抛错,把 fails / warns 完整交给调用方判断。
|
|
17
|
+
*/
|
|
18
|
+
const SUPPORTED_TYPES = ['alert', 'reasons', 'grid', 'table', 'checks', 'list', 'next'];
|
|
19
|
+
const REQUIRED_ROWS = ['合同类型', '合同总额', '甲方', '乙方'];
|
|
20
|
+
const TAX_WORDS = ['增值税', '税率', '发票', '含税'];
|
|
21
|
+
const RICHNESS_BASELINE = 14;
|
|
22
|
+
/** Python `str()` 的常见分支。 */
|
|
23
|
+
function pyStr(value) {
|
|
24
|
+
if (value === null || value === undefined)
|
|
25
|
+
return 'None';
|
|
26
|
+
if (value === true)
|
|
27
|
+
return 'True';
|
|
28
|
+
if (value === false)
|
|
29
|
+
return 'False';
|
|
30
|
+
if (typeof value === 'string')
|
|
31
|
+
return value;
|
|
32
|
+
if (typeof value === 'number')
|
|
33
|
+
return String(value);
|
|
34
|
+
if (Array.isArray(value))
|
|
35
|
+
return `[${value.map((item) => pyRepr(item)).join(', ')}]`;
|
|
36
|
+
if (typeof value === 'object') {
|
|
37
|
+
return `{${Object.entries(value)
|
|
38
|
+
.map(([key, val]) => `${pyRepr(key)}: ${pyRepr(val)}`)
|
|
39
|
+
.join(', ')}}`;
|
|
40
|
+
}
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
function pyRepr(value) {
|
|
44
|
+
if (typeof value === 'string')
|
|
45
|
+
return `'${value}'`;
|
|
46
|
+
return pyStr(value);
|
|
47
|
+
}
|
|
48
|
+
/** Python `x or ""` 后取值。 */
|
|
49
|
+
function textOr(value) {
|
|
50
|
+
return value === null || value === undefined || value === false || value === '' || value === 0
|
|
51
|
+
? ''
|
|
52
|
+
: pyStr(value);
|
|
53
|
+
}
|
|
54
|
+
function loadJson(path) {
|
|
55
|
+
const raw = readFileSync(path, 'utf8').replace(/^\uFEFF/u, '');
|
|
56
|
+
const parsed = JSON.parse(raw);
|
|
57
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
58
|
+
throw new Error('JSON 根节点不是对象');
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
}
|
|
62
|
+
function isFile(path) {
|
|
63
|
+
try {
|
|
64
|
+
return existsSync(path) && statSync(path).isFile();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** 把各 section 摊平成 (label, value) 列表,便于统一校验。 */
|
|
71
|
+
function collectRows(summary) {
|
|
72
|
+
const rows = [];
|
|
73
|
+
const sections = Array.isArray(summary.sections) ? summary.sections : [];
|
|
74
|
+
for (const section of sections) {
|
|
75
|
+
if (!section || typeof section !== 'object' || Array.isArray(section))
|
|
76
|
+
continue;
|
|
77
|
+
const sec = section;
|
|
78
|
+
const type = String(sec.type ?? '').toLowerCase();
|
|
79
|
+
const sectionTitle = textOr(sec.title);
|
|
80
|
+
if (type === 'table') {
|
|
81
|
+
const items = Array.isArray(sec.rows) ? sec.rows : [];
|
|
82
|
+
for (const row of items) {
|
|
83
|
+
if (Array.isArray(row) && row.length >= 2) {
|
|
84
|
+
rows.push({ label: pyStr(row[0]), value: pyStr(row[1]), section: sectionTitle });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (type === 'grid' || type === 'checks') {
|
|
89
|
+
const items = Array.isArray(sec.items) ? sec.items : [];
|
|
90
|
+
for (const item of items) {
|
|
91
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
92
|
+
const record = item;
|
|
93
|
+
rows.push({
|
|
94
|
+
label: textOr(record.label),
|
|
95
|
+
value: textOr(record.value),
|
|
96
|
+
section: sectionTitle,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (type === 'list') {
|
|
102
|
+
const items = Array.isArray(sec.items) ? sec.items : [];
|
|
103
|
+
for (const item of items) {
|
|
104
|
+
rows.push({ label: '', value: pyStr(item), section: sectionTitle });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return rows;
|
|
109
|
+
}
|
|
110
|
+
function textBlob(summary, rows) {
|
|
111
|
+
const parts = [textOr(summary.title), textOr(summary.subtitle)];
|
|
112
|
+
for (const row of rows)
|
|
113
|
+
parts.push(row.value);
|
|
114
|
+
return parts.join('\n');
|
|
115
|
+
}
|
|
116
|
+
/** 去掉千分位逗号、空白与中文逗号,供金额回查使用。 */
|
|
117
|
+
function flatten(text) {
|
|
118
|
+
return text.replace(/[,\s,]/gu, '');
|
|
119
|
+
}
|
|
120
|
+
export function validateSummaryData(summary, text, triagePath, elementsPath, outSummaryPath) {
|
|
121
|
+
const fails = [];
|
|
122
|
+
const warns = [];
|
|
123
|
+
const rows = collectRows(summary);
|
|
124
|
+
const sections = Array.isArray(summary.sections) ? summary.sections : [];
|
|
125
|
+
// S1 结构
|
|
126
|
+
if (!summary.title)
|
|
127
|
+
fails.push('S1 缺少 title');
|
|
128
|
+
if (!Array.isArray(summary.sections) || summary.sections.length === 0) {
|
|
129
|
+
fails.push('S1 sections 为空或不是数组');
|
|
130
|
+
}
|
|
131
|
+
// S2 / S3 / S4
|
|
132
|
+
sections.forEach((section, index) => {
|
|
133
|
+
const sec = (section && typeof section === 'object' ? section : {});
|
|
134
|
+
const type = String(sec.type ?? '').toLowerCase();
|
|
135
|
+
const name = textOr(sec.title) || `第${index + 1}节`;
|
|
136
|
+
if (!SUPPORTED_TYPES.includes(type)) {
|
|
137
|
+
fails.push(`S2 [${name}] 未知 type=${type}(支持 ${[...SUPPORTED_TYPES].sort().join(' / ')})`);
|
|
138
|
+
}
|
|
139
|
+
if (type === 'grid') {
|
|
140
|
+
fails.push(`S3 [${name}] 使用 grid:CLI 渲染器只输出空容器,内容会整段丢失;请改 table`);
|
|
141
|
+
}
|
|
142
|
+
if (type === 'alert' || type === 'checks') {
|
|
143
|
+
warns.push(`S4 [${name}] 使用 ${type}:摘要只做客观呈现,风险提示应归「合同预审」`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
// S5 丰富度
|
|
147
|
+
if (rows.length < RICHNESS_BASELINE) {
|
|
148
|
+
warns.push(`S5 要素仅 ${rows.length} 行,低于文档 §5.2 的 ${RICHNESS_BASELINE} 行基线`);
|
|
149
|
+
}
|
|
150
|
+
// S6 金额回查
|
|
151
|
+
if (text) {
|
|
152
|
+
const flatSource = flatten(text);
|
|
153
|
+
for (const row of rows) {
|
|
154
|
+
const numbers = flatten(row.value).match(/[0-9]{4,}(?:\.[0-9]{1,2})?/gu) ?? [];
|
|
155
|
+
for (const number of numbers) {
|
|
156
|
+
if (!flatSource.includes(number)) {
|
|
157
|
+
warns.push(`S6 [${row.label || row.section}] 金额 ${number} 未在原文中找到,疑似换算或编造`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// S7 / S8 付款比例
|
|
163
|
+
for (const row of rows) {
|
|
164
|
+
const joined = `${row.label} ${row.value}`;
|
|
165
|
+
const isPayRow = row.label.includes('付款')
|
|
166
|
+
|| row.label.includes('阶段')
|
|
167
|
+
|| (row.label.includes('比例') && !row.label.includes('税'));
|
|
168
|
+
const percents = joined.match(/(\d{1,3})\s*%/gu) ?? [];
|
|
169
|
+
for (const raw of percents) {
|
|
170
|
+
const digit = /(\d{1,3})/u.exec(raw);
|
|
171
|
+
const value = digit ? Number.parseInt(digit[1], 10) : 0;
|
|
172
|
+
if (value > 100) {
|
|
173
|
+
fails.push(`S7 [${row.label || row.section}] 比例 ${value}% 超过 100%`);
|
|
174
|
+
}
|
|
175
|
+
// 仅在「付款类行」且该行标签不是税率/发票口径时告警,
|
|
176
|
+
// 避免「按付款进度开具 13% 增值税发票」这类正常表述被误报
|
|
177
|
+
const hasTaxWord = TAX_WORDS.some((word) => joined.includes(word));
|
|
178
|
+
const labelSaysTax = row.label.includes('税') || row.label.includes('发票');
|
|
179
|
+
if (isPayRow && hasTaxWord && !labelSaysTax) {
|
|
180
|
+
warns.push(`S8 [${row.label || row.section}] 付款与税率混写(${value}%),确认不是把税率当付款比例`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// S9 必填行(标签列宽同义词;合同总额额外允许在内容列命中)
|
|
185
|
+
const labelsBlob = rows.map((row) => row.label).join(' ');
|
|
186
|
+
const valuesBlob = rows.map((row) => row.value).join(' ');
|
|
187
|
+
const labelAlternatives = {
|
|
188
|
+
合同类型: ['合同类型', '合同类别', '类型'],
|
|
189
|
+
合同总额: ['合同总额', '合同标的总额', '标的总额', '总额', '合同总价', '合同价款'],
|
|
190
|
+
甲方: ['甲方', '需方', '买方'],
|
|
191
|
+
乙方: ['乙方', '供方', '卖方'],
|
|
192
|
+
};
|
|
193
|
+
const valueAlternatives = {
|
|
194
|
+
合同总额: ['合同总额', '合同标的总额', '标的总额', '合同总价', '合同价款'],
|
|
195
|
+
};
|
|
196
|
+
for (const key of REQUIRED_ROWS) {
|
|
197
|
+
if ((labelAlternatives[key] ?? [key]).some((word) => labelsBlob.includes(word)))
|
|
198
|
+
continue;
|
|
199
|
+
if ((valueAlternatives[key] ?? []).some((word) => valuesBlob.includes(word)))
|
|
200
|
+
continue;
|
|
201
|
+
warns.push(`S9 缺少必填行「${key}」`);
|
|
202
|
+
}
|
|
203
|
+
// S10 交付地点口径
|
|
204
|
+
let place = '';
|
|
205
|
+
let signPlace = '';
|
|
206
|
+
for (const row of rows) {
|
|
207
|
+
if (row.label.includes('交付') && row.label.includes('地点'))
|
|
208
|
+
place = row.value;
|
|
209
|
+
if (row.label.includes('签订') && row.label.includes('地点'))
|
|
210
|
+
signPlace = row.value;
|
|
211
|
+
}
|
|
212
|
+
if (place && signPlace && place.trim() === signPlace.trim()) {
|
|
213
|
+
warns.push(`S10 「交付地点」与「签订地点」取值相同(${place}),确认是否用签订地点顶替`);
|
|
214
|
+
}
|
|
215
|
+
// elements 合流
|
|
216
|
+
let merged = false;
|
|
217
|
+
if (triagePath && elementsPath) {
|
|
218
|
+
if (!isFile(triagePath)) {
|
|
219
|
+
warns.push(`合流跳过:triage.json 不存在 ${triagePath}`);
|
|
220
|
+
}
|
|
221
|
+
else if (!isFile(elementsPath)) {
|
|
222
|
+
warns.push(`合流跳过:elements.json 不存在 ${elementsPath}`);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
try {
|
|
226
|
+
const triage = loadJson(triagePath);
|
|
227
|
+
const elements = loadJson(elementsPath);
|
|
228
|
+
triage.elements = elements;
|
|
229
|
+
triage.elementsSource = 'ai_semantic';
|
|
230
|
+
writeFileSync(triagePath, JSON.stringify(triage, null, 2), 'utf8');
|
|
231
|
+
merged = true;
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
235
|
+
warns.push(`合流失败:${message}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// 落地
|
|
240
|
+
let outSummary;
|
|
241
|
+
if (outSummaryPath && fails.length === 0) {
|
|
242
|
+
writeFileSync(outSummaryPath, JSON.stringify(summary, null, 2), 'utf8');
|
|
243
|
+
outSummary = outSummaryPath;
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
ok: fails.length === 0,
|
|
247
|
+
merged,
|
|
248
|
+
sectionCount: sections.length,
|
|
249
|
+
rowCount: rows.length,
|
|
250
|
+
fails,
|
|
251
|
+
warns,
|
|
252
|
+
...(outSummary ? { outSummary } : {}),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
export const contractSummaryValidateOperation = {
|
|
256
|
+
name: 'contract.summary.validate',
|
|
257
|
+
async execute(input) {
|
|
258
|
+
const summaryPath = resolve(requireNonEmptyString(input.summary, 'summary', 4096).trim());
|
|
259
|
+
if (!isFile(summaryPath)) {
|
|
260
|
+
throw contractValidationError('summary_not_found', `摘要数据文件不存在:${summaryPath}`);
|
|
261
|
+
}
|
|
262
|
+
let summary;
|
|
263
|
+
try {
|
|
264
|
+
summary = loadJson(summaryPath);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
268
|
+
throw contractValidationError('summary_parse_fail', `摘要数据不是合法 JSON 对象:${message}`);
|
|
269
|
+
}
|
|
270
|
+
const textPath = typeof input.text === 'string' && input.text.trim() ? resolve(input.text.trim()) : '';
|
|
271
|
+
const triagePath = typeof input.triage === 'string' && input.triage.trim() ? resolve(input.triage.trim()) : '';
|
|
272
|
+
const elementsPath = typeof input.elements === 'string' && input.elements.trim() ? resolve(input.elements.trim()) : '';
|
|
273
|
+
const outSummaryPath = typeof input.outSummary === 'string' && input.outSummary.trim()
|
|
274
|
+
? resolve(input.outSummary.trim())
|
|
275
|
+
: '';
|
|
276
|
+
let text = '';
|
|
277
|
+
if (textPath && isFile(textPath)) {
|
|
278
|
+
text = readFileSync(textPath, 'utf8');
|
|
279
|
+
}
|
|
280
|
+
const result = validateSummaryData(summary, text, triagePath, elementsPath, outSummaryPath);
|
|
281
|
+
const strict = input.strict === true;
|
|
282
|
+
return {
|
|
283
|
+
status: 'COMPLETE',
|
|
284
|
+
data: {
|
|
285
|
+
...result,
|
|
286
|
+
strict,
|
|
287
|
+
pass: result.ok && !(strict && result.warns.length > 0),
|
|
288
|
+
note: '信封 ok 表示命令执行成功;data.ok 表示摘要校验通过。FAIL 时不得渲染摘要',
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
export const contractSummaryValidateOperations = [contractSummaryValidateOperation];
|
|
@@ -138,11 +138,13 @@ export function renderSummaryHtml(data) {
|
|
|
138
138
|
throw contractValidationError('section_type_unknown', `未知的 section 类型:${[...new Set(unknownTypes)].join(', ')};支持 ${SECTION_TYPES.join(' / ')}`);
|
|
139
139
|
}
|
|
140
140
|
const badge = esc(data.badge ?? '合同');
|
|
141
|
-
|
|
141
|
+
// 2026-11-11:标题按对象取,报价单阶段不得显示「合同摘要」
|
|
142
|
+
const label = String(data.summaryLabel ?? '合同摘要');
|
|
143
|
+
const title = esc(data.title ?? label);
|
|
142
144
|
const meta = esc(data.meta ?? '');
|
|
143
145
|
const body = sections.map((section) => sectionHtml(section)).join('');
|
|
144
146
|
return `<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">`
|
|
145
|
-
+ `<title
|
|
147
|
+
+ `<title>${label} - ${title}</title><style>${CSS}</style></head><body><div class="w">`
|
|
146
148
|
+ `<div class="hd"><span class="bd">${badge}</span><h1>${title}</h1><div class="mt">${meta}</div></div>`
|
|
147
149
|
+ `${body}</div></body></html>`;
|
|
148
150
|
}
|