weaver-work-cli 0.1.49 → 0.1.50

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 (103) hide show
  1. package/dist/chunks/{attachment-content-MU2LPI5P.js → attachment-content-EJYIOJPH.js} +3 -3
  2. package/dist/chunks/{chunk-6GWU63YF.js → chunk-3NCFFHB2.js} +1 -1
  3. package/dist/chunks/{chunk-NBEWUR7L.js → chunk-6T53BSWZ.js} +158 -44
  4. package/dist/chunks/{chunk-EJVA5ZVB.js → chunk-7AYQJSFY.js} +2 -2
  5. package/dist/chunks/{chunk-D2QRZUW4.js → chunk-7ECB22G3.js} +35 -28
  6. package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
  7. package/dist/chunks/{chunk-3NV2ETZR.js → chunk-BFKLQLBK.js} +8 -8
  8. package/dist/chunks/{chunk-BRRW7CWA.js → chunk-HARQF5IP.js} +26 -26
  9. package/dist/chunks/{chunk-K3BT54CU.js → chunk-K67FODVC.js} +1 -1
  10. package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
  11. package/dist/chunks/{chunk-GEOMANP7.js → chunk-MCZG6HPM.js} +2 -2
  12. package/dist/chunks/{chunk-ZKEUGS2U.js → chunk-RYFRGTUV.js} +4 -4
  13. package/dist/chunks/{chunk-3X7VOSBA.js → chunk-WNJUGI2F.js} +1 -1
  14. package/dist/chunks/{chunk-KV5SOWMS.js → chunk-YB3AJYPY.js} +4 -4
  15. package/dist/chunks/{conflict-6347A7YK.js → conflict-C4UDHCWV.js} +2 -2
  16. package/dist/chunks/{contract-N6P2HIIE.js → contract-VUC6JOPG.js} +464 -9
  17. package/dist/chunks/{create-flow-7WG7LVX5.js → create-flow-6OG2LYBD.js} +6 -6
  18. package/dist/chunks/{env-LHRKSLG6.js → env-WP57TF2S.js} +2 -2
  19. package/dist/chunks/{factory-2H7Z4RWJ.js → factory-VUXI7N5C.js} +1 -1
  20. package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
  21. package/dist/chunks/{group-chat-EW6PNDDT.js → group-chat-UQRGXILK.js} +3 -3
  22. package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
  23. package/dist/chunks/{invoice-FXWH5GPO.js → invoice-E7GOITEU.js} +1 -1
  24. package/dist/chunks/{meeting-N2FQBHXI.js → meeting-4BBLVAWM.js} +10 -10
  25. package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
  26. package/dist/chunks/{reception-MYOKJULO.js → reception-QGPNTGHG.js} +98 -82
  27. package/dist/chunks/{registry-CKUVBS53.js → registry-5CRCN2TV.js} +10 -10
  28. package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
  29. package/dist/chunks/{registry-7VZ6YJUF.js → registry-V4CHRQDI.js} +1 -1
  30. package/dist/chunks/{room-recommend-MBCYENQ2.js → room-recommend-AYR3UG7R.js} +4 -4
  31. package/dist/chunks/{schedule-5IFMCXME.js → schedule-JZEFIXUS.js} +4 -4
  32. package/dist/chunks/{workflow-2TRU2ZSP.js → workflow-3ZAF2J5E.js} +1 -1
  33. package/dist/index.js +7 -7
  34. package/dist/shortcuts/contract/host.js +11 -0
  35. package/dist/shortcuts/contract/index.js +13 -0
  36. package/dist/shortcuts/contract/manifest.js +53 -0
  37. package/dist/shortcuts/contract/operations/performance.js +58 -7
  38. package/dist/shortcuts/contract/operations/quote.js +283 -1
  39. package/dist/shortcuts/contract/operations/registry.js +2 -0
  40. package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
  41. package/dist/shortcuts/fna/host.js +4 -2
  42. package/dist/shortcuts/fna/manifest.js +14 -5
  43. package/dist/shortcuts/fna/operations/audit.js +334 -0
  44. package/dist/shortcuts/fna/operations/registry.js +2 -0
  45. package/dist/shortcuts/im/operations/at-mention.js +6 -3
  46. package/dist/shortcuts/im/operations/msg-parse.js +35 -5
  47. package/dist/shortcuts/im/operations/msg-sync.js +3 -1
  48. package/dist/shortcuts/im/operations/msg-write.js +57 -9
  49. package/dist/shortcuts/invoice/manifest.js +1 -1
  50. package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
  51. package/dist/shortcuts/reception/constants.js +3 -7
  52. package/dist/shortcuts/reception/operations/leads.js +30 -6
  53. package/dist/shortcuts/reception/operations/panels.js +3 -2
  54. package/dist/shortcuts/workflow/operations/read.js +58 -14
  55. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
  56. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
  57. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
  58. package/docs/SKILL.md +1 -1
  59. package/docs/_catalog.md +1 -1
  60. package/docs/fna.md +11 -4
  61. package/package.json +1 -1
  62. package/skill-template/business-info.json +6 -1
  63. package/skill-template/domains/qiyecheng.md +4 -2
  64. package/skills/weaver-e10-jinchengda/SKILL.md +1 -1
  65. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -5
  66. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +1 -1
  67. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
  68. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  69. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +219 -0
  70. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +50 -30
  71. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +24 -15
  72. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  73. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
  74. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +43 -0
  75. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
  76. package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +265 -0
  77. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +83 -0
  78. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
  79. package/skills/weaver-e10-qiyecheng/SKILL.md +21 -7
  80. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +104 -0
  81. package/skills/weaver-e10-qiyecheng/references/catalog.md +17 -3
  82. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +136 -30
  83. package/skills/weaver-e10-reception-flow/SKILL.md +43 -6
  84. package/skills/weaver-e10-reception-flow/references/guide.md +1 -1
  85. package/skills/weaver-e10-recruit-stage/SKILL.md +1 -1
  86. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +3 -3
  87. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +6 -4
  88. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +3 -3
  89. package/skills/weaver-e10-workflow/SKILL.md +2 -1
  90. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
  91. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
  92. package/skills/weaver-e10-yepiaotong/SKILL.md +10 -5
  93. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
  94. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +6 -45
  95. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +5 -5
  96. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +4 -37
  97. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +2 -2
  98. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +4 -4
  99. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +22 -35
  100. package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
  101. package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
  102. package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
  103. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
@@ -15,6 +15,7 @@ import { contractValidationError } from '../errors.js';
15
15
  import { requireNonEmptyString } from './shared.js';
16
16
  import { listSheetNames, readGrid } from '../ooxml/xlsx.js';
17
17
  import { fillDocx, labelBefore } from '../ooxml/docx.js';
18
+ import { readZipEntry } from '../ooxml/zip.js';
18
19
  // ---------------------------------------------------------------- 人民币大写
19
20
  const DIGITS = '零壹贰叁肆伍陆柒捌玖';
20
21
  const UNITS = ['', '拾', '佰', '仟'];
@@ -278,6 +279,8 @@ export function parseQuote(buffer, sheetName, keepRemark = false, includeZero =
278
279
  checks.push({ section: `${s.code}、${s.title}`, sheet_total: s.total, sum_items: s.sum_items, diff: s.sum_items - s.total });
279
280
  }
280
281
  }
282
+ // 费用总表本身是各明细的汇总,若再累加会与合计额重复计算(实测差额等于合计值),
283
+ // 因此它只用于提供 standard_total / final_total,不参与明细求和。
281
284
  const grand = sections.reduce((acc, s) => acc + (s.sum_items ?? 0), 0);
282
285
  totals.sum_items_grand = grand;
283
286
  const standard = totals.standard_total;
@@ -299,6 +302,207 @@ export function parseQuote(buffer, sheetName, keepRemark = false, includeZero =
299
302
  warnings.push('报价单未填写『客户名称』,签约主体必须由用户提供');
300
303
  return { source_sheet: sheet, available_sheets: names, meta, totals, sections, checks, warnings };
301
304
  }
305
+ // ---------------------------------------------------------------- docx 报价书解析
306
+ /**
307
+ * Word 版报价书解析(2026-11-09 补充)。
308
+ *
309
+ * 背景:`contract.quote.parse` 原先只认 .xlsx,客户实际提交的报价书多为 .docx,
310
+ * 只能报错或让用户手工转格式。本文按「表头识别」而非固定表序解析,兼容
311
+ * 软件功能费用 / 用户授权许可 / 实施服务费用 / 费用总表四类常见表。
312
+ */
313
+ function decodeXmlEntities(s) {
314
+ return s
315
+ .replace(/&lt;/gu, '<')
316
+ .replace(/&gt;/gu, '>')
317
+ .replace(/&quot;/gu, '"')
318
+ .replace(/&apos;/gu, "'")
319
+ .replace(/&amp;/gu, '&');
320
+ }
321
+ /** 取单元格纯文本:只认 <w:t> / <w:t xml:space="preserve">,不能写成 <w:t[^>]*>(会吞掉 <w:tcPr>)。 */
322
+ function cellText(fragment) {
323
+ const re = /<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/gu;
324
+ const out = [];
325
+ let m;
326
+ while ((m = re.exec(fragment)) !== null)
327
+ out.push(m[1] ?? '');
328
+ return decodeXmlEntities(out.join('')).replace(/\s+/gu, ' ').trim();
329
+ }
330
+ /** 从 document.xml 提取全部表格为「行 → 单元格文本」二维数组。 */
331
+ export function readDocxTablesFromXml(xml) {
332
+ const tables = [];
333
+ const tblRe = /<w:tbl>[\s\S]*?<\/w:tbl>/gu;
334
+ let tm;
335
+ while ((tm = tblRe.exec(xml)) !== null) {
336
+ const rows = [];
337
+ const trRe = /<w:tr[ >][\s\S]*?<\/w:tr>/gu;
338
+ let rm;
339
+ while ((rm = trRe.exec(tm[0])) !== null) {
340
+ const cells = [];
341
+ const tcRe = /<w:tc>[\s\S]*?<\/w:tc>/gu;
342
+ let cm;
343
+ while ((cm = tcRe.exec(rm[0])) !== null)
344
+ cells.push(cellText(cm[0]));
345
+ rows.push(cells);
346
+ }
347
+ if (rows.length)
348
+ tables.push(rows);
349
+ }
350
+ return tables;
351
+ }
352
+ /** 表格以外的段落文本(用于客户名、有效期、备注)。 */
353
+ function docxParagraphs(xml) {
354
+ const noTbl = xml.replace(/<w:tbl>[\s\S]*?<\/w:tbl>/gu, '');
355
+ const re = /<w:p[ >][\s\S]*?<\/w:p>/gu;
356
+ const out = [];
357
+ let m;
358
+ while ((m = re.exec(noTbl)) !== null) {
359
+ const t = cellText(m[0]);
360
+ if (t)
361
+ out.push(t);
362
+ }
363
+ return out;
364
+ }
365
+ function numLoose(s) {
366
+ const t = (s ?? '').replace(/,/gu, '');
367
+ const m = /(-?\d+(?:\.\d+)?)/u.exec(t);
368
+ if (!m)
369
+ return null;
370
+ const v = Number(m[1]);
371
+ return Number.isFinite(v) ? v : null;
372
+ }
373
+ /** 把 Word 报价书无损提取为「表格二维数组 + 段落文本」,不做任何语义判断。 */
374
+ export function extractQuoteDocx(buffer) {
375
+ const xml = readZipEntry(buffer, 'word/document.xml');
376
+ if (!xml) {
377
+ throw contractValidationError('docx_invalid', 'Word 文件缺少 word/document.xml,可能不是合法的 .docx。');
378
+ }
379
+ const tables = readDocxTablesFromXml(xml);
380
+ const paragraphs = docxParagraphs(xml);
381
+ return {
382
+ kind: 'docx',
383
+ tables: tables.map((rows, index) => ({ index, rows })),
384
+ paragraphs,
385
+ counts: { tables: tables.length, paragraphs: paragraphs.length },
386
+ note: '已按原样提取表格与段落,未做语义判断。请由模型理解后产出 ParsedQuote 结构' +
387
+ '(meta.customer/title/validity/tax,sections[].title/items[].name/price/qty/amount/total,' +
388
+ '汇总表所在 section 需标 is_summary=true),再调用 contract.quote.normalize 做校验。',
389
+ };
390
+ }
391
+ function asNumber(v) {
392
+ if (v === null || v === undefined || v === '')
393
+ return null;
394
+ if (typeof v === 'number')
395
+ return Number.isFinite(v) ? v : null;
396
+ return numLoose(String(v));
397
+ }
398
+ function asText(v) {
399
+ return typeof v === 'string' ? v.replace(/\s+/gu, ' ').trim() : v === null || v === undefined ? '' : String(v);
400
+ }
401
+ /**
402
+ * 校验并归一化模型给出的报价结构。
403
+ *
404
+ * 职责边界:**只验不算语义**——不猜哪张表是什么,只检查模型给的结构是否自洽:
405
+ * - sections 不能为空,items 必须是数组
406
+ * - 金额字段统一转成 number,缺失按 price × qty 补齐
407
+ * - 逐节重算 sum_items 并与 total 比对;汇总表(is_summary)不参与总计
408
+ * - 明细求和与合计额不一致时写入 warnings,供上游决定是否需要人工核对
409
+ */
410
+ export function normalizeParsedQuote(input) {
411
+ const rawSections = Array.isArray(input.sections) ? input.sections : [];
412
+ if (rawSections.length === 0) {
413
+ throw contractValidationError('quote_normalize_invalid', 'sections 为空:模型必须给出至少一节费用明细(含 title 与 items)。');
414
+ }
415
+ const sections = [];
416
+ const checks = [];
417
+ const summaryCodes = new Set();
418
+ let seq = 0;
419
+ for (const s of rawSections) {
420
+ seq += 1;
421
+ const code = asText(s.code) || `S${seq}`;
422
+ const title = asText(s.title) || `第 ${seq} 节`;
423
+ const rawItems = Array.isArray(s.items) ? s.items : [];
424
+ const items = [];
425
+ for (const it of rawItems) {
426
+ const name = asText(it.name);
427
+ const price = asNumber(it.price);
428
+ const qty = asNumber(it.qty);
429
+ let amount = asNumber(it.amount);
430
+ if (amount === null && price !== null)
431
+ amount = price * (qty ?? 1);
432
+ if (!name && amount === null)
433
+ continue;
434
+ items.push({
435
+ no: asText(it.no),
436
+ name,
437
+ way: asText(it.way),
438
+ desc: asText(it.desc),
439
+ price,
440
+ qty,
441
+ amount,
442
+ });
443
+ }
444
+ const total = asNumber(s.total);
445
+ const section = { code, title, items, total };
446
+ section.sum_items = items.reduce((acc, i) => acc + (Number(i.amount) || 0), 0);
447
+ sections.push(section);
448
+ if (s.is_summary)
449
+ summaryCodes.add(code);
450
+ if (total !== null && section.sum_items !== total) {
451
+ checks.push({
452
+ section: `${code}、${title}`,
453
+ table_total: total,
454
+ sum_items: section.sum_items,
455
+ diff: section.sum_items - total,
456
+ });
457
+ }
458
+ }
459
+ const totalIn = (input.totals ?? {});
460
+ const standard = asNumber(totalIn.standard_total) ?? asNumber(totalIn.final_total) ?? undefined;
461
+ // 汇总表只提供合计额,不参与明细求和;否则会与合计重复计算
462
+ const grand = sections
463
+ .filter((s) => !summaryCodes.has(s.code))
464
+ .reduce((acc, s) => acc + (s.sum_items ?? 0), 0);
465
+ const totals = {
466
+ standard_total: standard ?? null,
467
+ final_total: asNumber(totalIn.final_total) ?? standard ?? null,
468
+ sum_items_grand: grand,
469
+ has_mismatch: false,
470
+ diff_vs_standard: standard === undefined ? null : grand - standard,
471
+ };
472
+ if (totalIn.discount !== undefined)
473
+ totals.discount = totalIn.discount;
474
+ totals.has_mismatch = checks.length > 0 || (standard !== undefined && grand !== standard);
475
+ const warnings = Array.isArray(input.warnings) ? input.warnings.map(asText).filter(Boolean) : [];
476
+ if (checks.length) {
477
+ warnings.push('分节明细求和与所给合计不一致,请与报价人核对:' +
478
+ checks
479
+ .map((c) => `${String(c.section)} 合计${String(c.table_total)}/明细${String(c.sum_items)}`)
480
+ .join(';'));
481
+ }
482
+ if (totals.diff_vs_standard) {
483
+ warnings.push(`全部明细求和 ${grand} 与合计额 ${String(standard)} 不一致,差额 ${String(totals.diff_vs_standard)};` +
484
+ '可能存在没有独立明细表的分项,请核对。');
485
+ }
486
+ const metaRaw = (input.meta ?? {});
487
+ const meta = {};
488
+ for (const [k, v] of Object.entries(metaRaw)) {
489
+ const t = asText(v);
490
+ if (t)
491
+ meta[k] = t;
492
+ }
493
+ if (!meta.customer)
494
+ warnings.push('报价书未给出客户名称,签约主体必须由用户提供');
495
+ return {
496
+ source_sheet: 'docx',
497
+ available_sheets: ['正文'],
498
+ meta,
499
+ totals,
500
+ sections,
501
+ checks,
502
+ warnings,
503
+ };
504
+ }
505
+ // ----------------------------------------------------------------
302
506
  // ---------------------------------------------------------------- docx 填充(字段打分)
303
507
  const FIELD_ALIASES = {
304
508
  party_a: ['甲方', '买方', '客户名称', '客户', '采购方', '需方', '购货方', '甲方名称', '买方名称'],
@@ -450,10 +654,70 @@ export const contractQuoteOperations = [
450
654
  },
451
655
  async execute(input) {
452
656
  const path = resolve(String(input.path));
657
+ // 2026-11-09 用户定稿:报价书格式无法穷举,语义映射交给模型。
658
+ // .docx 到 parse 只做无损提取并明确提示走模型链路,不再由代码猜表头含义。
659
+ if (/\.docx$/iu.test(path)) {
660
+ const extracted = extractQuoteDocx(readFileSync(path));
661
+ return {
662
+ status: 'DONE',
663
+ data: {
664
+ ...extracted,
665
+ next_step: 'Word 报价书已无损提取。请模型理解表格与段落语义后产出 meta/sections(汇总表标 is_summary=true),' +
666
+ '再调用 contract.quote.normalize 校验金额与结构。代码不再做表头语义映射。',
667
+ },
668
+ };
669
+ }
670
+ if (!/\.xlsx$/iu.test(path)) {
671
+ throw contractValidationError('file_type_unsupported', '报价单只支持 .xlsx 或 .docx;.xls / .doc 老格式请先另存为新格式。');
672
+ }
453
673
  const parsed = parseQuote(readFileSync(path), input.sheet ? String(input.sheet) : null, Boolean(input.keepRemark), Boolean(input.includeZero));
454
674
  return { status: 'DONE', data: parsed };
455
675
  },
456
676
  },
677
+ {
678
+ name: 'contract.quote.extract',
679
+ risk: 'read-with-upload',
680
+ inputSchema: {
681
+ type: 'object',
682
+ additionalProperties: false,
683
+ properties: {
684
+ path: { type: 'string', description: '.docx 报价书路径' },
685
+ },
686
+ required: ['path'],
687
+ },
688
+ async execute(input) {
689
+ const path = resolve(String(input.path));
690
+ if (!/\.docx$/iu.test(path)) {
691
+ throw contractValidationError('file_type_unsupported', '无损提取只针对 .docx 报价书;.xlsx 结构规整,请直接用 contract.quote.parse。');
692
+ }
693
+ const extracted = extractQuoteDocx(readFileSync(path));
694
+ return { status: 'DONE', data: extracted };
695
+ },
696
+ },
697
+ {
698
+ name: 'contract.quote.normalize',
699
+ risk: 'read',
700
+ inputSchema: {
701
+ type: 'object',
702
+ additionalProperties: false,
703
+ properties: {
704
+ data: { type: 'string', description: '模型产出的报价 JSON 文件路径' },
705
+ },
706
+ required: ['data'],
707
+ },
708
+ async execute(input) {
709
+ const p = resolve(String(input.data));
710
+ let raw;
711
+ try {
712
+ raw = JSON.parse(readFileSync(p, 'utf8'));
713
+ }
714
+ catch (e) {
715
+ throw contractValidationError('quote_normalize_invalid', `读取模型 JSON 失败:${e instanceof Error ? e.message : String(e)}`);
716
+ }
717
+ const normalized = normalizeParsedQuote(raw);
718
+ return { status: 'DONE', data: normalized };
719
+ },
720
+ },
457
721
  {
458
722
  name: 'contract.quote.fill',
459
723
  risk: 'read-with-upload',
@@ -530,7 +794,7 @@ export function quoteContractContracts() {
530
794
  },
531
795
  {
532
796
  name: 'contract.quote.parse',
533
- summary: '解析报价单 xlsx:元信息/总价/分节明细/一致性校验',
797
+ summary: '解析报价单:xlsx 确定性解析;docx 仅无损提取(语义交给模型)',
534
798
  risk: 'read-with-upload',
535
799
  inputSchema: {
536
800
  type: 'object', additionalProperties: false,
@@ -540,6 +804,24 @@ export function quoteContractContracts() {
540
804
  }, required: ['path'],
541
805
  },
542
806
  },
807
+ {
808
+ name: 'contract.quote.extract',
809
+ summary: '把 .docx 报价书无损提取为表格与段落(零语义判断)',
810
+ risk: 'read-with-upload',
811
+ inputSchema: {
812
+ type: 'object', additionalProperties: false,
813
+ properties: { path: { type: 'string' } }, required: ['path'],
814
+ },
815
+ },
816
+ {
817
+ name: 'contract.quote.normalize',
818
+ summary: '校验并归一化模型产出的报价 JSON(结构 + 金额自校验)',
819
+ risk: 'read',
820
+ inputSchema: {
821
+ type: 'object', additionalProperties: false,
822
+ properties: { data: { type: 'string' } }, required: ['data'],
823
+ },
824
+ },
543
825
  {
544
826
  name: 'contract.quote.fill',
545
827
  summary: '用真实 .docx 模板 + 数据 JSON 生成合同 docx',
@@ -15,6 +15,7 @@ import { contractQuoteOperations } from './quote.js';
15
15
  import { contractRecommendOperations } from './recommend.js';
16
16
  import { contractRequestOperations } from './request.js';
17
17
  import { contractReviewOperations } from './review.js';
18
+ import { contractSaveRecognizeOperations } from './save-recognize.js';
18
19
  import { contractSubjectOperations } from './subject.js';
19
20
  import { contractSummaryOperations } from './summary.js';
20
21
  import { contractTemplateOperations } from './template.js';
@@ -33,6 +34,7 @@ function buildRegistry() {
33
34
  ...contractReviewOperations,
34
35
  ...contractFileDownloadOperations,
35
36
  ...contractFlowOperations,
37
+ ...contractSaveRecognizeOperations,
36
38
  ...contractRecommendOperations,
37
39
  ...contractCompareOperations,
38
40
  ...contractCreditPageOperations,
@@ -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
+ ];
@@ -52,8 +52,10 @@ export function assertPath(requestPath) {
52
52
  }
53
53
  if (!requestPath.startsWith('/api/fna/')
54
54
  && !requestPath.startsWith('/api/app/fna/')
55
- && !requestPath.startsWith('/api/secondev/fna/')) {
56
- throw fnaValidationError('path_not_allowed', 'FNA 费控中心只能调用 /api/fna/、/api/app/fna/ 或 /api/secondev/fna/ 路径');
55
+ && !requestPath.startsWith('/api/secondev/fna/')
56
+ // AI 规则预审挂在 ai/application 下(非 fna 命名空间),只放行该 Controller 的 rule/check 路径
57
+ && !requestPath.startsWith('/api/ai/application/rule/check/')) {
58
+ throw fnaValidationError('path_not_allowed', 'FNA 费控中心只能调用 /api/fna/、/api/app/fna/、/api/secondev/fna/ 或 /api/ai/application/rule/check/ 路径');
57
59
  }
58
60
  }
59
61
  function omitEmptyQueryValues(query) {
@@ -1,11 +1,12 @@
1
1
  import { fnaOperationDefinitions } from './operations/registry.js';
2
2
  /**
3
3
  * FNA 费控中心(齐业成)模块禁用/暂缓边界。
4
- * 12 个源接口全部落地;以下几类能力不在本 CLI,写入 manifest 供 Agent 判断,
4
+ * 13 个源接口全部落地;以下几类能力不在本 CLI,写入 manifest 供 Agent 判断,
5
5
  * 不得编造 operation 或绕过 CLI 直连接口:
6
6
  * - 姓名/流程名 → employeeId/workflowId 的人员与流程解析不在本模块;
7
7
  * - 借款「确认已还 confirmRepay」、核销明细等页面按钮能力未随源资料提供接口,未实现;
8
- * - 报销报表 AI 问答只暴露自然语言问题,不接受也不回传 AI 生成的 SQL。
8
+ * - 报销报表 AI 问答只暴露自然语言问题,不接受也不回传 AI 生成的 SQL;
9
+ * - AI 规则预审只执行流程配置的规则,不支持增删改规则配置,也不回传 formDataList 明细。
9
10
  */
10
11
  const FNA_WITHHELD = [
11
12
  {
@@ -20,6 +21,14 @@ const FNA_WITHHELD = [
20
21
  name: 'fna.expense.chart.raw.sql',
21
22
  reason: '报销报表 AI 问答由服务端生成 SQL 并做租户隔离改写与安全校验;CLI 只接受 userInput,不暴露、不回传 SQL,也不允许调用方绕过安全校验自写 SQL。',
22
23
  },
24
+ {
25
+ name: 'fna.audit.rule.configure',
26
+ reason: 'AI 规则预审只按流程已配置的规则执行(可传 ruleList/settingId 指定),不支持新增、编辑、删除规则配置或规则设置;源资料未提供规则维护接口。',
27
+ },
28
+ {
29
+ name: 'fna.audit.formdata.raw',
30
+ reason: 'aiCheckAudit 返回的 data.formDataList 含完整主表/明细/发票数据,体积大且含业务敏感字段;CLI 只回传 id/refId/title 摘要,不把整段表单数据暴露给 Agent。',
31
+ },
23
32
  ];
24
33
  function buildOperations() {
25
34
  return fnaOperationDefinitions().map((definition) => ({
@@ -35,12 +44,12 @@ function buildOperations() {
35
44
  export const fnaManifest = {
36
45
  schemaVersion: 1,
37
46
  name: 'fna',
38
- title: '泛微E10齐业成费控中心(预算查询/费用中心/报销报表/借款管理/发票核销)',
39
- version: '0.1.1',
47
+ title: '泛微E10齐业成费控中心(预算查询/费用中心/报销报表/AI规则预审/借款管理/发票核销)',
48
+ version: '0.1.2',
40
49
  host: 'e10-fna',
41
50
  status: 'builtin',
42
51
  sourceSkill: 'weaver-e10-qiyecheng',
43
- capabilities: ['budget', 'expense', 'expense-chart', 'loan', 'invoice-writeoff'],
52
+ capabilities: ['budget', 'expense', 'expense-chart', 'audit', 'loan', 'invoice-writeoff'],
44
53
  operations: buildOperations(),
45
54
  withheldOperations: FNA_WITHHELD,
46
55
  };