weaver-work-cli 0.1.52 → 0.1.54

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 (84) hide show
  1. package/dist/chunks/{attachment-content-MBYYSQIX.js → attachment-content-2EPEI4HV.js} +3 -3
  2. package/dist/chunks/{chunk-DZOC77ZD.js → chunk-6LGLI46Q.js} +1 -1
  3. package/dist/chunks/{chunk-RWFRZSIP.js → chunk-7KKI5KDY.js} +2 -2
  4. package/dist/chunks/{chunk-KLZ3ULQQ.js → chunk-CNVZETM5.js} +1 -1
  5. package/dist/chunks/{chunk-RPRFIG6I.js → chunk-FE3CQAAM.js} +23 -23
  6. package/dist/chunks/{chunk-ZRHKGQRQ.js → chunk-JJRIT2ZN.js} +2 -2
  7. package/dist/chunks/{chunk-LTRLF6MM.js → chunk-LYOFRYC4.js} +4 -4
  8. package/dist/chunks/{chunk-7UOXOGFL.js → chunk-O6RIBG5E.js} +4 -4
  9. package/dist/chunks/{chunk-LM2H7SZI.js → chunk-QUDHSMG3.js} +37 -25
  10. package/dist/chunks/{chunk-IRMA3GVP.js → chunk-XHMJBRLZ.js} +1 -1
  11. package/dist/chunks/{chunk-LALWNK6M.js → chunk-XPQN4E5O.js} +41 -19
  12. package/dist/chunks/{chunk-D3TDNRFE.js → chunk-Z7B7QSR2.js} +7 -7
  13. package/dist/chunks/{conflict-D2HYKBMH.js → conflict-K2IAKKFR.js} +2 -2
  14. package/dist/chunks/{contract-MFOFMM2J.js → contract-LJRAXVZU.js} +5448 -1857
  15. package/dist/chunks/{create-flow-7ZATJVTM.js → create-flow-UL37MZGP.js} +6 -6
  16. package/dist/chunks/{env-5DO4YENS.js → env-BZDB5OVZ.js} +2 -2
  17. package/dist/chunks/{factory-3M7D7WJC.js → factory-VD3YI6N7.js} +1 -1
  18. package/dist/chunks/{group-chat-B2HT5NEO.js → group-chat-DHNVO76L.js} +3 -3
  19. package/dist/chunks/{meeting-HZOX3CBB.js → meeting-OWG4O2XH.js} +10 -10
  20. package/dist/chunks/{registry-SJHSBO5G.js → registry-ASYCWF2U.js} +10 -10
  21. package/dist/chunks/{registry-KYPFFQIH.js → registry-CJOVECZD.js} +1 -1
  22. package/dist/chunks/{room-recommend-5AHR4YQV.js → room-recommend-LSVAMGKV.js} +4 -4
  23. package/dist/chunks/{schedule-KZPJUPC2.js → schedule-7QOPRUU4.js} +4 -4
  24. package/dist/chunks/{smart-extract-IXHCZE4R.js → smart-extract-FOUYNIG3.js} +44 -8
  25. package/dist/chunks/{workflow-UHKCZJMY.js → workflow-YHXFIU63.js} +1 -1
  26. package/dist/index.js +4 -4
  27. package/dist/shortcuts/contract/manifest.js +105 -5
  28. package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
  29. package/dist/shortcuts/contract/operations/card-action.js +597 -17
  30. package/dist/shortcuts/contract/operations/card-ebdf-list.js +258 -2
  31. package/dist/shortcuts/contract/operations/card.js +6 -5
  32. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
  33. package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
  34. package/dist/shortcuts/contract/operations/elements-build.js +47 -0
  35. package/dist/shortcuts/contract/operations/first-screen.js +28 -3
  36. package/dist/shortcuts/contract/operations/ledger.js +438 -0
  37. package/dist/shortcuts/contract/operations/performance.js +104 -3
  38. package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
  39. package/dist/shortcuts/contract/operations/registry.js +10 -0
  40. package/dist/shortcuts/contract/operations/triage.js +1100 -0
  41. package/dist/shortcuts/meeting/operations/eb/create-flow.js +21 -0
  42. package/dist/shortcuts/smart-extract/operations/fill.js +10 -7
  43. package/dist/shortcuts/smart-extract/operations/validate.js +49 -3
  44. package/dist/shortcuts/workflow/operations/form.js +68 -33
  45. package/docs/smart-extract.md +5 -5
  46. package/package.json +1 -1
  47. package/skills/weaver-e10-jinchengda/SKILL.md +139 -99
  48. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +43 -482
  49. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +7 -8
  50. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
  51. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  52. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
  53. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
  54. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  55. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
  56. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
  57. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +13 -9
  58. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
  59. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +2 -2
  60. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +3 -3
  61. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
  62. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
  63. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
  64. package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
  65. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +1 -1
  66. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +3 -6
  67. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
  68. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +53 -76
  69. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
  70. package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
  71. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
  72. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
  73. package/skills/weaver-e10-meeting/SKILL.md +2 -1
  74. package/skills/weaver-e10-smart-extract/SKILL.md +15 -4
  75. package/skills/weaver-e10-smart-extract/references/result-format.md +2 -2
  76. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +2 -1
  77. package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
  78. package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
  79. package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +0 -200
  80. package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +0 -572
  81. package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +0 -560
  82. package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +0 -894
  83. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -598
  84. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
@@ -0,0 +1,529 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { basename, join, resolve } from 'node:path';
3
+ import { contractValidationError } from '../errors.js';
4
+ import { resolveOperation } from './op-resolver.js';
5
+ /**
6
+ * 报价单首屏:sheets → extract → parse → 自动识客户 → 金额矛盾校验 → 出动作卡片。
7
+ *
8
+ * 迁移自 `scripts/quote_screen.py`(2026-11-13 第七批下沉)。
9
+ *
10
+ * 迁移理由(这是最该消除的一处反模式):
11
+ * 原脚本本身不访问业务接口,它用 `subprocess` 去调 `weaver-work-cli contract run`,
12
+ * 而这些 operation(quote.sheets / quote.extract / quote.parse / card.action)
13
+ * **早已存在**。于是形成「Python 包一层 CLI」:额外的进程启动、额外的 Python 运行时依赖、
14
+ * 参数文件往返落盘,而且 Windows 下还要靠 shutil.which 绕 PATHEXT 才能启动。
15
+ * 改为进程内 `resolveOperation(...).execute(...)` 后,链路与原 contract.firstscreen.run 同构。
16
+ *
17
+ * 语义边界不变:客户名称、税率、汇总表标记一律由模型读 raw_grid 判定,
18
+ * 本 operation 只做无损提取、金额结构、自动识「标签:值」、金额矛盾校验与卡片渲染。
19
+ * 报价单不出摘要 HTML、不出摘要卡(2026-11-11 用户指定),只产出文字摘要。
20
+ */
21
+ const DEFAULT_BASE = 'https://www.e-cology.com.cn';
22
+ // ---------------------------------------------------------------- 通用工具
23
+ function isRecord(value) {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
25
+ }
26
+ function text(value) {
27
+ return typeof value === 'string' ? value : '';
28
+ }
29
+ function writeJson(path, value) {
30
+ writeFileSync(path, JSON.stringify(value, null, 2), 'utf8');
31
+ }
32
+ /** 进程内调用其它 operation,返回其 data(失败时抛错,由调用方决定如何降级)。 */
33
+ async function callOperation(name, input, context) {
34
+ const operation = resolveOperation(name);
35
+ const result = await operation.execute(input, context);
36
+ return (result?.data ?? {});
37
+ }
38
+ function groupThousands(value, decimals) {
39
+ return value.toLocaleString('en-US', {
40
+ minimumFractionDigits: decimals,
41
+ maximumFractionDigits: decimals,
42
+ });
43
+ }
44
+ /** 金额展示(对应脚本 _money):整数加千分位,非数字原样返回。 */
45
+ function moneyText(value) {
46
+ if (value === null || value === undefined || value === '')
47
+ return '';
48
+ const num = Number(String(value).replace(/,/gu, ''));
49
+ if (!Number.isFinite(num))
50
+ return String(value);
51
+ if (Math.abs(num - Math.trunc(num)) < 1e-9)
52
+ return groupThousands(Math.trunc(num), 0);
53
+ return groupThousands(num, 2);
54
+ }
55
+ /** 金额展示(对应脚本 _money0):缺值给破折号。 */
56
+ function moneyPlain(value) {
57
+ if (value === null || value === undefined || value === '')
58
+ return '—';
59
+ const num = Number(String(value).replace(/,/gu, ''));
60
+ if (!Number.isFinite(num))
61
+ return String(value);
62
+ if (Math.abs(num - Math.round(num)) < 0.005)
63
+ return groupThousands(Math.round(num), 0);
64
+ return groupThousands(num, 2);
65
+ }
66
+ /** 文件名 → 可读标题:去【】前缀、去 _日期_ 后缀与尾部编号。 */
67
+ function cleanTitle(filePath) {
68
+ let base = basename(filePath).replace(/\.[^.]+$/u, '');
69
+ base = base.replace(/^【[^】]*】/u, '');
70
+ base = base.replace(/_[0-9]{6,}.*$/u, '');
71
+ base = base.replace(/\s*\(\d+\)\s*$/u, '');
72
+ base = base.replace(/_\d+$/u, '');
73
+ return base.trim() || '报价单';
74
+ }
75
+ // ---------------------------------------------------------------- 网格预览
76
+ /** 模型判定客户/税率/汇总表只需这些行,直接带回可省一次读 raw_grid 的往返。 */
77
+ const PREVIEW_KEYS = [
78
+ '客户',
79
+ '用户名称',
80
+ '甲方',
81
+ '报价日期',
82
+ '有效',
83
+ '税率',
84
+ '合计',
85
+ '标准价',
86
+ '最终优惠',
87
+ '总价',
88
+ '汇总',
89
+ '总计',
90
+ ];
91
+ function formatGridRow(index, row) {
92
+ const cells = row
93
+ .filter((cell) => String(cell ?? '').trim().length > 0)
94
+ .map((cell) => [...String(cell).trim()].slice(0, 40).join(''));
95
+ return `r${String(index + 1).padEnd(3, ' ')} ${cells.join(' | ')}`;
96
+ }
97
+ /** 头部若干行 + 关键词命中行,供模型直接判语义。 */
98
+ function buildPreview(rows, head = 12) {
99
+ const lines = [];
100
+ const total = rows.length;
101
+ lines.push('---- GRID HEAD ----');
102
+ for (let i = 0; i < Math.min(head, total); i += 1) {
103
+ const row = Array.isArray(rows[i]) ? rows[i] : [];
104
+ const line = formatGridRow(i, row);
105
+ if (line.trim())
106
+ lines.push(line);
107
+ }
108
+ lines.push('---- GRID KEY HITS ----');
109
+ const shown = new Set();
110
+ for (let i = 0; i < total; i += 1) {
111
+ const row = Array.isArray(rows[i]) ? rows[i] : [];
112
+ const joined = row.map((cell) => String(cell ?? '')).join('');
113
+ if (!PREVIEW_KEYS.some((key) => joined.includes(key)))
114
+ continue;
115
+ if (shown.has(i))
116
+ continue;
117
+ shown.add(i);
118
+ lines.push(formatGridRow(i, row));
119
+ }
120
+ if (total > head) {
121
+ lines.push(`NOTE 完整网格共 ${total} 行,见 raw_grid.json;上面只给头部与关键词行`);
122
+ }
123
+ return lines;
124
+ }
125
+ // ---------------------------------------------------------------- 自动识要素
126
+ const META_LABELS = [
127
+ { key: 'customer', pat: /客户(?:名称|全称)?\s*[::]\s*([^\s::||]+)/u },
128
+ { key: 'quote_date', pat: /报价日期\s*[::]\s*([0-9]{4}\s*[-/年]\s*[0-9]{1,2}\s*[-/月]\s*[0-9]{1,2})/u },
129
+ { key: 'sales', pat: /客户经理\s*[::]\s*([^\s::||]+)/u },
130
+ { key: 'phone', pat: /联系电话\s*[::]\s*([0-9-]{6,})/u },
131
+ ];
132
+ /** 从原始网格的「标签:值」单元格取客户/日期/经理/电话;取不到留空,不编造。 */
133
+ function autoMeta(rows) {
134
+ const meta = { customer: '', quote_date: '', sales: '', phone: '' };
135
+ for (const row of rows ?? []) {
136
+ if (!Array.isArray(row))
137
+ continue;
138
+ for (const cell of row) {
139
+ if (cell === null || cell === undefined)
140
+ continue;
141
+ const value = String(cell).trim();
142
+ if (!value)
143
+ continue;
144
+ for (const { key, pat } of META_LABELS) {
145
+ if (meta[key])
146
+ continue;
147
+ const matched = value.match(pat);
148
+ if (matched?.[1])
149
+ meta[key] = matched[1].trim();
150
+ }
151
+ }
152
+ }
153
+ return meta;
154
+ }
155
+ /** 脚本能确定的部分全部自动填好;模型只需在需要时覆盖。 */
156
+ function autoSummary(filePath, raw, parsed, docType) {
157
+ const data = parsed ?? {};
158
+ const meta = autoMeta(Array.isArray(raw?.rows) ? raw.rows : []);
159
+ const parsedMeta = isRecord(data.meta) ? data.meta : {};
160
+ for (const key of ['customer', 'quote_date', 'sales', 'phone']) {
161
+ if (!meta[key] && parsedMeta[key])
162
+ meta[key] = String(parsedMeta[key]);
163
+ }
164
+ const totals = isRecord(data.totals) ? data.totals : {};
165
+ const rows = [];
166
+ const points = [];
167
+ const sections = Array.isArray(data.sections) ? data.sections : [];
168
+ for (const section of sections) {
169
+ if (!isRecord(section))
170
+ continue;
171
+ const code = text(section.code);
172
+ const name = text(section.title);
173
+ const items = Array.isArray(section.items) ? section.items : [];
174
+ rows.push([`${code}${name}`, moneyPlain(section.total)]);
175
+ if (name)
176
+ points.push(`${code}${name}:${items.length} 项,${moneyPlain(section.total)} 元`);
177
+ }
178
+ let warnings = (Array.isArray(data.warnings) ? data.warnings : [])
179
+ .map((item) => String(item))
180
+ .filter((item) => item.trim().length > 0);
181
+ // 客户名已自动取到时,「未能定位 / 未识别到客户名称」类告警已失效,不能带给用户
182
+ if (meta.customer) {
183
+ warnings = warnings.filter((warn) => !(warn.includes('客户名称') && (warn.includes('未能') || warn.includes('未从') || warn.includes('未识别'))));
184
+ }
185
+ const checks = Array.isArray(data.checks) ? data.checks : [];
186
+ for (const check of checks) {
187
+ if (!isRecord(check))
188
+ continue;
189
+ const diff = check.diff;
190
+ if (!diff)
191
+ continue;
192
+ const secKey = text(check.section).replace(/、/gu, '');
193
+ if (secKey) {
194
+ warnings = warnings.filter((warn) => !(warn.includes('表内') && warn.replace(/、/gu, '').includes(secKey)));
195
+ }
196
+ const message = `${text(check.section) || '某分项'} 明细求和 ${moneyPlain(check.sum_items)} 元` +
197
+ `与表内合计 ${moneyPlain(check.sheet_total)} 元相差 ${moneyPlain(Math.abs(Number(diff)))} 元`;
198
+ if (!warnings.includes(message))
199
+ warnings.push(message);
200
+ }
201
+ const totalsOut = {
202
+ standard_total: totals.standard_total ?? null,
203
+ final_total: totals.final_total ?? null,
204
+ };
205
+ if (totals.sum_items_grand !== null && totals.sum_items_grand !== undefined && totals.sum_items_grand !== '') {
206
+ const std = totals.standard_total;
207
+ const grand = totals.sum_items_grand;
208
+ if (std !== null && std !== undefined && std !== '') {
209
+ const grandNum = Number(String(grand).replace(/,/gu, ''));
210
+ const stdNum = Number(String(std).replace(/,/gu, ''));
211
+ if (Number.isFinite(grandNum) && Number.isFinite(stdNum) && grandNum !== stdNum) {
212
+ warnings.push(`全部明细求和 ${moneyPlain(grand)} 元与标准价合计 ${moneyPlain(std)} 元不一致,` +
213
+ `差额 ${moneyPlain(grandNum - stdNum)} 元`);
214
+ }
215
+ }
216
+ }
217
+ return {
218
+ title: cleanTitle(filePath),
219
+ doc_type: docType,
220
+ meta,
221
+ totals: totalsOut,
222
+ sections: [
223
+ { type: 'table', title: '费用构成', rows, total: moneyPlain(totals.final_total) },
224
+ { type: 'list', title: '要点', items: points },
225
+ ],
226
+ warnings,
227
+ };
228
+ }
229
+ // ---------------------------------------------------------------- 文字摘要
230
+ /** 把 summary_data 压成对话可直接使用的纯文字摘要(不出 HTML、不出卡片)。 */
231
+ function buildTextSummary(input) {
232
+ const sd = isRecord(input) ? input : {};
233
+ const lines = [];
234
+ lines.push(`报价单:${text(sd.title) || '报价单'}`);
235
+ const meta = isRecord(sd.meta) ? sd.meta : {};
236
+ const totals = isRecord(sd.totals) ? sd.totals : {};
237
+ const who = [];
238
+ if (meta.customer)
239
+ who.push(`客户:${meta.customer}`);
240
+ if (meta.quote_date)
241
+ who.push(`报价日期:${meta.quote_date}`);
242
+ if (meta.sales)
243
+ who.push(`客户经理:${meta.sales}`);
244
+ if (who.length > 0)
245
+ lines.push(who.join(' | '));
246
+ const std = totals.standard_total;
247
+ const fin = totals.final_total;
248
+ const hasStd = std !== null && std !== undefined && std !== '';
249
+ const hasFin = fin !== null && fin !== undefined && fin !== '';
250
+ if (hasStd || hasFin) {
251
+ const seg = [];
252
+ if (hasStd)
253
+ seg.push(`标准价合计 ${moneyText(std)} 元`);
254
+ if (hasFin)
255
+ seg.push(`最终优惠报价 ${moneyText(fin)} 元`);
256
+ if (hasStd && hasFin) {
257
+ const a = Number(String(fin).replace(/,/gu, ''));
258
+ const b = Number(String(std).replace(/,/gu, ''));
259
+ if (Number.isFinite(a) && Number.isFinite(b) && a === b)
260
+ seg.push('未让价');
261
+ }
262
+ lines.push(`金额:${seg.join(',')}`);
263
+ }
264
+ const sections = Array.isArray(sd.sections) ? sd.sections : [];
265
+ // 费用构成:只认 >=3 列的明细表;2 列键值表不是费用构成
266
+ for (const section of sections) {
267
+ if (!isRecord(section))
268
+ continue;
269
+ const rows = Array.isArray(section.rows) ? section.rows : [];
270
+ if (section.type !== 'table' || rows.length === 0)
271
+ continue;
272
+ const first = rows[0];
273
+ if (!Array.isArray(first) || first.length < 3)
274
+ continue;
275
+ const parts = [];
276
+ for (const row of rows) {
277
+ if (!Array.isArray(row) || row.length < 2)
278
+ continue;
279
+ const name = String(row[1] ?? '').trim();
280
+ const amount = String(row[row.length - 1] ?? '').trim();
281
+ if (name)
282
+ parts.push(`${name} ${amount} 元`);
283
+ }
284
+ if (parts.length > 0)
285
+ lines.push(`构成:${parts.join(';')}`);
286
+ break;
287
+ }
288
+ // 要点:list / reasons 型 section 的 items(每段最多 5 条,输出最多 5 条)
289
+ const points = [];
290
+ for (const section of sections) {
291
+ if (!isRecord(section))
292
+ continue;
293
+ if (section.type !== 'list' && section.type !== 'reasons')
294
+ continue;
295
+ const items = Array.isArray(section.items) ? section.items.slice(0, 5) : [];
296
+ for (const item of items) {
297
+ const value = String(item).trim();
298
+ if (value && !points.includes(value))
299
+ points.push(value);
300
+ }
301
+ }
302
+ if (points.length > 0)
303
+ lines.push(`要点:${points.slice(0, 5).join(';')}`);
304
+ const warns = (Array.isArray(sd.warnings) ? sd.warnings : [])
305
+ .map((item) => String(item).trim())
306
+ .filter((item) => item.length > 0);
307
+ if (warns.length > 0)
308
+ lines.push(`待核对:${warns.slice(0, 3).join(';')}`);
309
+ return lines.join('\n');
310
+ }
311
+ function normalizeMode(raw) {
312
+ const value = text(raw).trim().toLowerCase();
313
+ if (!value)
314
+ return 'auto';
315
+ if (value === 'auto' || value === 'stage1' || value === 'stage2')
316
+ return value;
317
+ throw contractValidationError('mode_invalid', 'mode 只能是 auto / stage1 / stage2');
318
+ }
319
+ export const contractQuoteScreenOperations = [
320
+ {
321
+ name: 'contract.quotescreen.run',
322
+ async execute(input, context) {
323
+ const fileInput = text(input.file).trim();
324
+ if (!fileInput)
325
+ throw contractValidationError('file_required', 'file 必须是报价单 .xlsx 的绝对路径');
326
+ const filePath = resolve(fileInput);
327
+ if (!existsSync(filePath)) {
328
+ throw contractValidationError('file_not_found', `报价单文件不存在:${filePath}`);
329
+ }
330
+ const outDirInput = text(input.outDir).trim();
331
+ if (!outDirInput)
332
+ throw contractValidationError('out_dir_required', 'outDir 必须是产物目录');
333
+ const outDir = resolve(outDirInput);
334
+ mkdirSync(outDir, { recursive: true });
335
+ const mode = normalizeMode(input.mode);
336
+ const docType = text(input.docType).trim() || 'quote';
337
+ const title = text(input.title).trim();
338
+ let companyName = text(input.companyName).trim();
339
+ const summaryArg = text(input.summaryData).trim();
340
+ const baseUrl = (text(input.baseUrl) || DEFAULT_BASE).replace(/\/+$/u, '');
341
+ const headRaw = input.head;
342
+ const head = typeof headRaw === 'number' && Number.isFinite(headRaw) && headRaw > 0 ? Math.floor(headRaw) : 12;
343
+ const fwd = filePath;
344
+ const warnings = [];
345
+ const result = {
346
+ ok: true,
347
+ mode,
348
+ file: fwd,
349
+ outDir,
350
+ sheets: [],
351
+ sheet: null,
352
+ outputs: {},
353
+ previewLines: [],
354
+ auto: null,
355
+ textSummary: null,
356
+ cardPath: null,
357
+ cardHtml: null,
358
+ cardSelfCheckPassed: null,
359
+ warnings,
360
+ };
361
+ // 显式阶段2:只需 summaryData,不必重跑 sheets/extract/parse
362
+ if (mode === 'stage2') {
363
+ if (!summaryArg) {
364
+ throw contractValidationError('summary_data_required', 'mode=stage2 时必须提供 summaryData');
365
+ }
366
+ const summaryPath = resolve(summaryArg);
367
+ if (!existsSync(summaryPath)) {
368
+ throw contractValidationError('summary_data_not_found', `summaryData 不存在:${summaryPath}`);
369
+ }
370
+ const summary = JSON.parse(readFileSync(summaryPath, 'utf8').replace(/^\uFEFF/u, ''));
371
+ if (!companyName && isRecord(summary) && isRecord(summary.meta)) {
372
+ companyName = text(summary.meta.customer).trim();
373
+ }
374
+ const stage2 = await runStage2({
375
+ summary,
376
+ outDir,
377
+ docType,
378
+ title,
379
+ companyName,
380
+ baseUrl,
381
+ context,
382
+ warnings,
383
+ });
384
+ Object.assign(result, stage2.data);
385
+ warnings.push(...stage2.warnings);
386
+ result.warnings = warnings;
387
+ return { status: 'COMPLETE', data: result };
388
+ }
389
+ // ── sheets:多 sheet 时列出让用户选,默认取第一个
390
+ const sheetsData = await callOperation('contract.quote.sheets', { path: fwd }, context);
391
+ const sheets = (Array.isArray(sheetsData.sheets) ? sheetsData.sheets : []).map((item) => String(item));
392
+ if (sheets.length === 0) {
393
+ throw contractValidationError('sheets_empty', '未能从报价单读取到任何工作表');
394
+ }
395
+ const requestedSheet = text(input.sheet).trim();
396
+ if (requestedSheet && !sheets.includes(requestedSheet)) {
397
+ throw contractValidationError('sheet_not_found', `工作表「${requestedSheet}」不存在;可选:${sheets.join('、')}`);
398
+ }
399
+ const sheet = requestedSheet || sheets[0];
400
+ result.sheets = sheets;
401
+ result.sheet = sheet;
402
+ if (sheets.length > 1) {
403
+ warnings.push(requestedSheet
404
+ ? `文件含 ${sheets.length} 个工作表,已按指定使用「${sheet}」`
405
+ : `文件含 ${sheets.length} 个工作表,已取第一个「${sheet}」;需要换表请传 sheet`);
406
+ }
407
+ // ── extract:无损还原网格
408
+ const raw = await callOperation('contract.quote.extract', { path: fwd, sheet }, context);
409
+ const rawGridPath = join(outDir, 'raw_grid.json');
410
+ writeJson(rawGridPath, raw);
411
+ result.outputs.rawGrid = rawGridPath;
412
+ result.previewLines = buildPreview(Array.isArray(raw.rows) ? raw.rows : [], head);
413
+ // ── parse:金额结构(含 checks / warnings)
414
+ const parsed = await callOperation('contract.quote.parse', { path: fwd, sheet }, context);
415
+ const parsedPath = join(outDir, 'parsed.json');
416
+ writeJson(parsedPath, parsed);
417
+ result.outputs.parsed = parsedPath;
418
+ if (mode === 'stage1') {
419
+ const skeleton = {
420
+ kind: 'quote',
421
+ file: fwd,
422
+ sheet,
423
+ sheets,
424
+ meta: {
425
+ customer: '',
426
+ quote_date: '',
427
+ sales: '',
428
+ phone: '',
429
+ _note: '读 raw_grid.json 后由模型填写;取不到写空串,不要编造',
430
+ },
431
+ totals: { standard_total: null, final_total: null },
432
+ sections: [],
433
+ _next: '模型填好本骨架后产出 summaryData,再以 mode=stage2 进入阶段2',
434
+ };
435
+ const skeletonPath = join(outDir, 'elements_skeleton.json');
436
+ writeJson(skeletonPath, skeleton);
437
+ result.outputs.skeleton = skeletonPath;
438
+ return { status: 'COMPLETE', data: result };
439
+ }
440
+ // ── auto:自动识要素 → 金额矛盾校验 → 文字摘要 → 卡片
441
+ const summary = autoSummary(fwd, raw, parsed, docType);
442
+ if (companyName)
443
+ summary.meta.customer = companyName;
444
+ else
445
+ companyName = summary.meta.customer;
446
+ const summaryPath = join(outDir, 'summary_data.json');
447
+ writeJson(summaryPath, summary);
448
+ result.outputs.summaryData = summaryPath;
449
+ result.auto = {
450
+ customer: summary.meta.customer,
451
+ quoteDate: summary.meta.quote_date,
452
+ sales: summary.meta.sales,
453
+ standardTotal: summary.totals.standard_total,
454
+ finalTotal: summary.totals.final_total,
455
+ checks: summary.warnings,
456
+ };
457
+ const stage2 = await runStage2({
458
+ summary,
459
+ outDir,
460
+ docType,
461
+ title,
462
+ companyName,
463
+ baseUrl,
464
+ context,
465
+ warnings,
466
+ });
467
+ Object.assign(result, stage2.data);
468
+ warnings.push(...stage2.warnings);
469
+ result.warnings = warnings;
470
+ return { status: 'COMPLETE', data: result };
471
+ },
472
+ },
473
+ ];
474
+ /** 阶段2:文字摘要 + 动作卡片。报价单不出摘要 HTML、不出摘要卡。 */
475
+ async function runStage2(options) {
476
+ const { summary, outDir, docType, title, companyName, baseUrl, context } = options;
477
+ const warnings = [];
478
+ const textSummary = buildTextSummary(summary);
479
+ const textPath = join(outDir, 'text_summary.txt');
480
+ writeFileSync(textPath, textSummary, 'utf8');
481
+ const cardContext = {
482
+ scene: 'doc',
483
+ docType,
484
+ stage: 'quote',
485
+ hasFileId: false,
486
+ // 报价单写明对方企业全称时,按规则可追加「查对方资信」
487
+ hasCounterparty: Boolean(companyName),
488
+ // 报价单不出摘要卡:固定 false,动作引擎据此不生成「查看合同摘要」
489
+ summaryReady: false,
490
+ flowKey: null,
491
+ };
492
+ const cardPath = join(outDir, 'card.html');
493
+ const cardArgs = { context: cardContext, out: cardPath, baseUrl };
494
+ if (title)
495
+ cardArgs.title = title;
496
+ if (companyName)
497
+ cardArgs.companyName = companyName;
498
+ let cardHtml = null;
499
+ let selfCheckPassed = null;
500
+ try {
501
+ const cardData = await callOperation('contract.card.action', cardArgs, context);
502
+ if (existsSync(cardPath)) {
503
+ cardHtml = readFileSync(cardPath, 'utf8');
504
+ }
505
+ else if (typeof cardData.browsertool === 'string') {
506
+ cardHtml = cardData.browsertool;
507
+ }
508
+ selfCheckPassed = cardData.selfCheckPassed === true;
509
+ if (!selfCheckPassed) {
510
+ const fails = Array.isArray(cardData.selfCheck) ? cardData.selfCheck.join('; ') : '';
511
+ warnings.push(`卡片自检未通过${fails ? `:${fails}` : ''}`);
512
+ }
513
+ }
514
+ catch (error) {
515
+ const message = error instanceof Error ? error.message : String(error);
516
+ warnings.push(`动作卡片渲染失败:${message.slice(0, 200)}`);
517
+ }
518
+ return {
519
+ data: {
520
+ textSummary,
521
+ outputs: { textSummary: textPath, card: existsSync(cardPath) ? cardPath : '' },
522
+ cardPath: existsSync(cardPath) ? cardPath : null,
523
+ cardHtml,
524
+ cardSelfCheckPassed: selfCheckPassed,
525
+ cardContext,
526
+ },
527
+ warnings,
528
+ };
529
+ }
@@ -12,14 +12,18 @@ import { contractCardActionOperations } from './card-action.js';
12
12
  import { contractCompareOperations } from './compare.js';
13
13
  import { contractCreditPageOperations } from './credit-page.js';
14
14
  import { contractCustomerOperations } from './customer.js';
15
+ import { contractDocxVerifyOperations } from './docx-verify.js';
16
+ import { contractDocxFillFromQuoteOperations } from './docx-fillfromquote.js';
15
17
  import { contractElementsBuildOperations } from './elements-build.js';
16
18
  import { contractFileDownloadOperations } from './file-download.js';
17
19
  import { contractFirstScreenOperations } from './first-screen.js';
18
20
  import { setOperationResolver } from './op-resolver.js';
19
21
  import { contractFlowOperations } from './flow.js';
22
+ import { contractLedgerOperations } from './ledger.js';
20
23
  import { contractModelTextOperations } from './modeltext.js';
21
24
  import { contractPerformanceOperations } from './performance.js';
22
25
  import { contractQuoteOperations } from './quote.js';
26
+ import { contractQuoteScreenOperations } from './quotescreen.js';
23
27
  import { contractRecommendOperations } from './recommend.js';
24
28
  import { contractRequestOperations } from './request.js';
25
29
  import { contractReviewOperations } from './review.js';
@@ -28,17 +32,21 @@ import { contractSubjectOperations } from './subject.js';
28
32
  import { contractSummaryOperations } from './summary.js';
29
33
  import { contractSummaryValidateOperations } from './summary-validate.js';
30
34
  import { contractTemplateOperations } from './template.js';
35
+ import { contractTriageOperations } from './triage.js';
31
36
  import { contractWorkflowOperations } from './workflow.js';
32
37
  function buildRegistry() {
33
38
  const registry = new Map();
34
39
  const handlers = [
35
40
  ...contractTemplateOperations,
41
+ ...contractTriageOperations,
36
42
  ...contractModelTextOperations,
37
43
  ...contractClauseLibraryOperations,
38
44
  ...contractClauseInsertOperations,
39
45
  ...contractClauseReferenceOperations,
40
46
  ...contractSubjectOperations,
41
47
  ...contractCustomerOperations,
48
+ ...contractDocxVerifyOperations,
49
+ ...contractDocxFillFromQuoteOperations,
42
50
  ...contractElementsBuildOperations,
43
51
  ...contractFirstScreenOperations,
44
52
  ...contractWorkflowOperations,
@@ -52,6 +60,7 @@ function buildRegistry() {
52
60
  ...contractCreditPageOperations,
53
61
  ...contractAssistantOperations,
54
62
  ...contractPerformanceOperations,
63
+ ...contractLedgerOperations,
55
64
  ...contractSummaryOperations,
56
65
  ...contractSummaryValidateOperations,
57
66
  ...contractCardOperations,
@@ -60,6 +69,7 @@ function buildRegistry() {
60
69
  ...contractCardRiskReportOperations,
61
70
  ...contractCardActionOperations,
62
71
  ...contractQuoteOperations,
72
+ ...contractQuoteScreenOperations,
63
73
  ];
64
74
  for (const handler of handlers) {
65
75
  if (registry.has(handler.name))