weaver-work-cli 0.1.50 → 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.
Files changed (167) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{attachment-content-EJYIOJPH.js → attachment-content-MBYYSQIX.js} +3 -3
  3. package/dist/chunks/{chunk-RYFRGTUV.js → chunk-7UOXOGFL.js} +4 -4
  4. package/dist/chunks/{chunk-BFKLQLBK.js → chunk-D3TDNRFE.js} +7 -7
  5. package/dist/chunks/{chunk-3NCFFHB2.js → chunk-DZOC77ZD.js} +1 -1
  6. package/dist/chunks/{chunk-K67FODVC.js → chunk-IRMA3GVP.js} +1 -1
  7. package/dist/chunks/{chunk-WNJUGI2F.js → chunk-KLZ3ULQQ.js} +1 -1
  8. package/dist/chunks/{chunk-6T53BSWZ.js → chunk-LALWNK6M.js} +9 -0
  9. package/dist/chunks/{chunk-HARQF5IP.js → chunk-LM2H7SZI.js} +25 -25
  10. package/dist/chunks/{chunk-YB3AJYPY.js → chunk-LTRLF6MM.js} +4 -4
  11. package/dist/chunks/{chunk-7ECB22G3.js → chunk-RPRFIG6I.js} +23 -23
  12. package/dist/chunks/{chunk-MCZG6HPM.js → chunk-RWFRZSIP.js} +2 -2
  13. package/dist/chunks/{chunk-7AYQJSFY.js → chunk-ZRHKGQRQ.js} +2 -2
  14. package/dist/chunks/{conflict-C4UDHCWV.js → conflict-D2HYKBMH.js} +2 -2
  15. package/dist/chunks/{contract-VUC6JOPG.js → contract-MFOFMM2J.js} +3837 -262
  16. package/dist/chunks/{create-flow-6OG2LYBD.js → create-flow-7ZATJVTM.js} +6 -6
  17. package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
  18. package/dist/chunks/{env-WP57TF2S.js → env-5DO4YENS.js} +2 -2
  19. package/dist/chunks/{factory-VUXI7N5C.js → factory-3M7D7WJC.js} +1 -1
  20. package/dist/chunks/{group-chat-UQRGXILK.js → group-chat-B2HT5NEO.js} +3 -3
  21. package/dist/chunks/{invoice-E7GOITEU.js → invoice-V7ZTITUO.js} +725 -205
  22. package/dist/chunks/{meeting-4BBLVAWM.js → meeting-HZOX3CBB.js} +10 -10
  23. package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
  24. package/dist/chunks/{registry-V4CHRQDI.js → registry-KYPFFQIH.js} +1 -1
  25. package/dist/chunks/{registry-5CRCN2TV.js → registry-SJHSBO5G.js} +10 -10
  26. package/dist/chunks/{room-recommend-AYR3UG7R.js → room-recommend-5AHR4YQV.js} +4 -4
  27. package/dist/chunks/{schedule-JZEFIXUS.js → schedule-KZPJUPC2.js} +4 -4
  28. package/dist/chunks/smart-extract-IXHCZE4R.js +2846 -0
  29. package/dist/chunks/{workflow-3ZAF2J5E.js → workflow-UHKCZJMY.js} +1 -1
  30. package/dist/index.js +11 -6
  31. package/dist/shortcuts/contract/manifest.js +151 -0
  32. package/dist/shortcuts/contract/operations/card-action.js +585 -0
  33. package/dist/shortcuts/contract/operations/card-ebdf-list.js +315 -0
  34. package/dist/shortcuts/contract/operations/card-plan.js +327 -0
  35. package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
  36. package/dist/shortcuts/contract/operations/elements-build.js +714 -0
  37. package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
  38. package/dist/shortcuts/contract/operations/first-screen.js +563 -0
  39. package/dist/shortcuts/contract/operations/flow.js +81 -25
  40. package/dist/shortcuts/contract/operations/modeltext.js +132 -0
  41. package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
  42. package/dist/shortcuts/contract/operations/quote.js +131 -25
  43. package/dist/shortcuts/contract/operations/registry.js +20 -0
  44. package/dist/shortcuts/contract/operations/review.js +73 -58
  45. package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
  46. package/dist/shortcuts/contract/operations/summary.js +4 -2
  47. package/dist/shortcuts/contract/operations/upload.js +48 -7
  48. package/dist/shortcuts/contract/prewarm-cache.js +90 -0
  49. package/dist/shortcuts/contract/prewarm.js +88 -0
  50. package/dist/shortcuts/contract/upload-cache.js +49 -4
  51. package/dist/shortcuts/data/index.js +1 -6
  52. package/dist/shortcuts/data/manifest.js +2 -2
  53. package/dist/shortcuts/data/operations/index.js +1 -1
  54. package/dist/shortcuts/data/operations/query.js +23 -46
  55. package/dist/shortcuts/index.js +5 -0
  56. package/dist/shortcuts/invoice/index.js +0 -12
  57. package/dist/shortcuts/invoice/manifest.js +200 -49
  58. package/dist/shortcuts/invoice/operations/registry.js +4 -2
  59. package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
  60. package/dist/shortcuts/invoice/operations/shared.js +3 -19
  61. package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
  62. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
  63. package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
  64. package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
  65. package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
  66. package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
  67. package/dist/shortcuts/recruit-stage/shared.js +5 -0
  68. package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
  69. package/dist/shortcuts/smart-extract/constants.js +79 -0
  70. package/dist/shortcuts/smart-extract/continuation.js +71 -0
  71. package/dist/shortcuts/smart-extract/errors.js +68 -0
  72. package/dist/shortcuts/smart-extract/host.js +191 -0
  73. package/dist/shortcuts/smart-extract/index.js +105 -0
  74. package/dist/shortcuts/smart-extract/ledger.js +70 -0
  75. package/dist/shortcuts/smart-extract/manifest.js +35 -0
  76. package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
  77. package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
  78. package/dist/shortcuts/smart-extract/operations/config.js +118 -0
  79. package/dist/shortcuts/smart-extract/operations/fill.js +489 -0
  80. package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
  81. package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
  82. package/dist/shortcuts/smart-extract/operations/save.js +355 -0
  83. package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
  84. package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
  85. package/dist/shortcuts/smart-extract/operations/target.js +167 -0
  86. package/dist/shortcuts/smart-extract/operations/types.js +22 -0
  87. package/dist/shortcuts/smart-extract/operations/validate.js +408 -0
  88. package/dist/shortcuts/workflow/operations/read.js +19 -1
  89. package/docs/SKILL.md +1 -1
  90. package/docs/_catalog.md +3 -0
  91. package/docs/agent-invoice.md +5 -7
  92. package/docs/data.md +5 -1
  93. package/docs/fna.md +14 -1
  94. package/docs/invoice.md +7 -5
  95. package/docs/smart-extract.md +156 -0
  96. package/package.json +1 -1
  97. package/skill-template/business-info.json +16 -1
  98. package/skill-template/domains/qiyecheng.md +2 -0
  99. package/skill-template/domains/smart-extract.md +16 -0
  100. package/skill-template/domains/yepiaotong.md +2 -2
  101. package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
  102. package/skills/weaver-e10-jinchengda/SKILL.md +159 -11
  103. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +8 -3
  104. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +4 -3
  105. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +8 -7
  106. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +21 -6
  107. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +3 -1
  108. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  109. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
  110. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +90 -0
  111. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +124 -5
  112. package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +200 -0
  113. package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +572 -0
  114. package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +560 -0
  115. package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +894 -0
  116. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +10 -0
  117. package/skills/weaver-e10-qiyecheng/SKILL.md +37 -0
  118. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +14 -0
  119. package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
  120. package/skills/weaver-e10-qiyecheng/references/catalog.md +25 -0
  121. package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
  122. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
  123. package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
  124. package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
  125. package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
  126. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +34 -27
  127. package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
  128. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
  129. package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
  130. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
  131. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
  132. package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
  133. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
  134. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  135. package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
  136. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -42
  137. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
  138. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
  139. package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
  140. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
  141. package/skills/weaver-e10-smart-extract/SKILL.md +169 -0
  142. package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
  143. package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
  144. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +105 -0
  145. package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
  146. package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
  147. package/skills/weaver-e10-yepiaotong/SKILL.md +46 -33
  148. package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
  149. package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
  150. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
  151. package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
  152. package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
  153. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +12 -8
  154. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
  155. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +91 -2
  156. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +1 -1
  157. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +12 -12
  158. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
  159. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +136 -91
  160. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +109 -23
  161. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
  162. package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
  163. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
  164. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
  165. package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +0 -265
  166. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
  167. 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 prewarmAll(host, files.map((file) => file.fileId))
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.filter((item) => item.ok).length,
118
- failCount: prewarm.filter((item) => !item.ok).length,
119
- results: prewarm,
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: '上传完成并已触发预审预热;把 url 原样放进 browsertool 的 arguments.url,并带 width: 1000;不要做整体编码',
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
- const result = await prewarmOne(host, fileId);
138
- if (!result.ok) {
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.error}`);
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,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
- const title = esc(data.title ?? '合同摘要');
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>合同摘要 - ${title}</title><style>${CSS}</style></head><body><div class="w">`
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
  }
@@ -2,7 +2,8 @@ import { createHash } from 'node:crypto';
2
2
  import { readFile, stat } from 'node:fs/promises';
3
3
  import { basename, resolve } from 'node:path';
4
4
  import { contractPolicyError, contractValidationError } from '../errors.js';
5
- import { fingerprintKey, isCacheEnabled, lookupUpload, rememberUpload, sha256Of, } from '../upload-cache.js';
5
+ import { fingerprintKey, isCacheEnabled, lookupUpload, rememberFileModule, rememberUpload, sha256Of, } from '../upload-cache.js';
6
+ import { ensurePrewarmed } from '../prewarm.js';
6
7
  const MAX_FILE_BYTES = 200 * 1024 * 1024;
7
8
  const DEFAULT_UPLOAD_TIMEOUT_MS = 120_000;
8
9
  const DOC_EXTENSIONS = new Set(['.doc', '.docx']);
@@ -22,6 +23,9 @@ function pickFileId(payload) {
22
23
  /**
23
24
  * 两段式文件上传:preUploadCheck 预检(命中秒传直接返回 fileId)→ module/upload 实传。
24
25
  * 成功判据是拿到非空 fileId,HTTP 200 不算成功。
26
+ *
27
+ * 上传成功后**立即触发预审预热**(与 module 无关),由 `ensurePrewarmed` 做整轮去重:
28
+ * 后续预审复用同一个 fileId 时不会再重复调用预热接口。
25
29
  */
26
30
  export async function uploadFile(host, options) {
27
31
  const absolutePath = resolve(options.path);
@@ -55,7 +59,7 @@ export async function uploadFile(host, options) {
55
59
  });
56
60
  const hit = await lookupUpload(reuseKey);
57
61
  if (hit) {
58
- return {
62
+ return await finish({
59
63
  fileId: hit.fileId,
60
64
  docId: hit.docId,
61
65
  name: hit.name || name,
@@ -63,7 +67,7 @@ export async function uploadFile(host, options) {
63
67
  md5: hit.md5,
64
68
  sha256,
65
69
  reused: true,
66
- };
70
+ });
67
71
  }
68
72
  }
69
73
  catch {
@@ -105,7 +109,7 @@ export async function uploadFile(host, options) {
105
109
  sha256,
106
110
  });
107
111
  }
108
- return {
112
+ return await finish({
109
113
  fileId: secondUploadId,
110
114
  docId: reusedDocId,
111
115
  name: reusedName,
@@ -113,7 +117,7 @@ export async function uploadFile(host, options) {
113
117
  md5,
114
118
  sha256,
115
119
  reused: false,
116
- };
120
+ });
117
121
  }
118
122
  const preUploadId = text(precheckData.preUploadId);
119
123
  const uploadType = text(precheckData.uploadType) ?? 'common';
@@ -148,7 +152,7 @@ export async function uploadFile(host, options) {
148
152
  sha256,
149
153
  });
150
154
  }
151
- return {
155
+ return await finish({
152
156
  fileId,
153
157
  docId: finalDocId,
154
158
  name: finalName,
@@ -156,7 +160,44 @@ export async function uploadFile(host, options) {
156
160
  md5,
157
161
  sha256,
158
162
  reused: false,
159
- };
163
+ });
164
+ /**
165
+ * 上传收口:三条返回路径共用。
166
+ * 1. 补记 fileId → module,供流程侧判断附件能否直接复用;
167
+ * 2. 触发预审预热(与 module 无关,默认开;同一 fileId 只触发一次)。
168
+ */
169
+ async function finish(file) {
170
+ file.module = options.module;
171
+ const prewarmEnabled = options.prewarm !== false;
172
+ if (!prewarmEnabled)
173
+ return file;
174
+ try {
175
+ const session = await host.getSession();
176
+ await rememberFileModule({
177
+ fileId: file.fileId,
178
+ module: options.module,
179
+ baseUrl: session.baseUrl,
180
+ userId: session.userId ?? '',
181
+ });
182
+ }
183
+ catch {
184
+ // 记录失败只影响"能否复用",不影响上传结果。
185
+ }
186
+ try {
187
+ const summary = await ensurePrewarmed(host, [file.fileId]);
188
+ const result = summary.results[0];
189
+ const ok = result?.ok === true;
190
+ file.prewarmed = ok;
191
+ file.prewarmSkipped = result?.skipped === true;
192
+ if (!ok)
193
+ file.prewarmError = result?.error ?? '未知原因';
194
+ }
195
+ catch (error) {
196
+ file.prewarmed = false;
197
+ file.prewarmError = error instanceof Error ? error.message : String(error);
198
+ }
199
+ return file;
200
+ }
160
201
  }
161
202
  export function assertContractDocument(path) {
162
203
  const lower = path.toLowerCase();