weaver-work-cli 0.1.50 → 0.1.53

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 (191) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{attachment-content-EJYIOJPH.js → attachment-content-W3TSJC3Y.js} +3 -3
  3. package/dist/chunks/{chunk-BFKLQLBK.js → chunk-2J3XY4ED.js} +7 -7
  4. package/dist/chunks/{chunk-K67FODVC.js → chunk-6GCXWKG6.js} +1 -1
  5. package/dist/chunks/{chunk-WNJUGI2F.js → chunk-76PRVYH4.js} +1 -1
  6. package/dist/chunks/{chunk-RYFRGTUV.js → chunk-DEHJ7PMA.js} +4 -4
  7. package/dist/chunks/{chunk-3NCFFHB2.js → chunk-IF33CG4V.js} +1 -1
  8. package/dist/chunks/{chunk-YB3AJYPY.js → chunk-PE334WL3.js} +4 -4
  9. package/dist/chunks/{chunk-MCZG6HPM.js → chunk-QQXMHM3J.js} +2 -2
  10. package/dist/chunks/{chunk-7ECB22G3.js → chunk-U7ROML5E.js} +23 -23
  11. package/dist/chunks/{chunk-7AYQJSFY.js → chunk-WTLQGS6D.js} +2 -2
  12. package/dist/chunks/{chunk-6T53BSWZ.js → chunk-XPQN4E5O.js} +50 -19
  13. package/dist/chunks/{chunk-HARQF5IP.js → chunk-Z4G7LLDD.js} +25 -25
  14. package/dist/chunks/{conflict-C4UDHCWV.js → conflict-57WDJWL7.js} +2 -2
  15. package/dist/chunks/{contract-VUC6JOPG.js → contract-LJRAXVZU.js} +8587 -1421
  16. package/dist/chunks/{create-flow-6OG2LYBD.js → create-flow-3FMMZBCA.js} +6 -6
  17. package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
  18. package/dist/chunks/{env-WP57TF2S.js → env-JYZE3BZB.js} +2 -2
  19. package/dist/chunks/{factory-VUXI7N5C.js → factory-66SCIKW3.js} +1 -1
  20. package/dist/chunks/{group-chat-UQRGXILK.js → group-chat-MNRYMLNG.js} +3 -3
  21. package/dist/chunks/{invoice-E7GOITEU.js → invoice-V7ZTITUO.js} +725 -205
  22. package/dist/chunks/{meeting-4BBLVAWM.js → meeting-IIY4UAJL.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-CJOVECZD.js} +1 -1
  25. package/dist/chunks/{registry-5CRCN2TV.js → registry-METZ2LWE.js} +10 -10
  26. package/dist/chunks/{room-recommend-AYR3UG7R.js → room-recommend-YFY7HTOF.js} +4 -4
  27. package/dist/chunks/{schedule-JZEFIXUS.js → schedule-6I63TERA.js} +4 -4
  28. package/dist/chunks/smart-extract-FOUYNIG3.js +2882 -0
  29. package/dist/chunks/{workflow-3ZAF2J5E.js → workflow-YHXFIU63.js} +1 -1
  30. package/dist/index.js +11 -6
  31. package/dist/shortcuts/contract/manifest.js +251 -0
  32. package/dist/shortcuts/contract/ooxml/docx-table.js +233 -0
  33. package/dist/shortcuts/contract/operations/card-action.js +1165 -0
  34. package/dist/shortcuts/contract/operations/card-ebdf-list.js +571 -0
  35. package/dist/shortcuts/contract/operations/card-plan.js +327 -0
  36. package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
  37. package/dist/shortcuts/contract/operations/card.js +6 -5
  38. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +532 -0
  39. package/dist/shortcuts/contract/operations/docx-verify.js +258 -0
  40. package/dist/shortcuts/contract/operations/elements-build.js +761 -0
  41. package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
  42. package/dist/shortcuts/contract/operations/first-screen.js +588 -0
  43. package/dist/shortcuts/contract/operations/flow.js +81 -25
  44. package/dist/shortcuts/contract/operations/ledger.js +438 -0
  45. package/dist/shortcuts/contract/operations/modeltext.js +132 -0
  46. package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
  47. package/dist/shortcuts/contract/operations/performance.js +104 -3
  48. package/dist/shortcuts/contract/operations/quote.js +131 -25
  49. package/dist/shortcuts/contract/operations/quotescreen.js +529 -0
  50. package/dist/shortcuts/contract/operations/registry.js +30 -0
  51. package/dist/shortcuts/contract/operations/review.js +73 -58
  52. package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
  53. package/dist/shortcuts/contract/operations/summary.js +4 -2
  54. package/dist/shortcuts/contract/operations/triage.js +1100 -0
  55. package/dist/shortcuts/contract/operations/upload.js +48 -7
  56. package/dist/shortcuts/contract/prewarm-cache.js +90 -0
  57. package/dist/shortcuts/contract/prewarm.js +88 -0
  58. package/dist/shortcuts/contract/upload-cache.js +49 -4
  59. package/dist/shortcuts/data/index.js +1 -6
  60. package/dist/shortcuts/data/manifest.js +2 -2
  61. package/dist/shortcuts/data/operations/index.js +1 -1
  62. package/dist/shortcuts/data/operations/query.js +23 -46
  63. package/dist/shortcuts/index.js +5 -0
  64. package/dist/shortcuts/invoice/index.js +0 -12
  65. package/dist/shortcuts/invoice/manifest.js +200 -49
  66. package/dist/shortcuts/invoice/operations/registry.js +4 -2
  67. package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
  68. package/dist/shortcuts/invoice/operations/shared.js +3 -19
  69. package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
  70. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
  71. package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
  72. package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
  73. package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
  74. package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
  75. package/dist/shortcuts/recruit-stage/shared.js +5 -0
  76. package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
  77. package/dist/shortcuts/smart-extract/constants.js +79 -0
  78. package/dist/shortcuts/smart-extract/continuation.js +71 -0
  79. package/dist/shortcuts/smart-extract/errors.js +68 -0
  80. package/dist/shortcuts/smart-extract/host.js +191 -0
  81. package/dist/shortcuts/smart-extract/index.js +105 -0
  82. package/dist/shortcuts/smart-extract/ledger.js +70 -0
  83. package/dist/shortcuts/smart-extract/manifest.js +35 -0
  84. package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
  85. package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
  86. package/dist/shortcuts/smart-extract/operations/config.js +118 -0
  87. package/dist/shortcuts/smart-extract/operations/fill.js +492 -0
  88. package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
  89. package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
  90. package/dist/shortcuts/smart-extract/operations/save.js +355 -0
  91. package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
  92. package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
  93. package/dist/shortcuts/smart-extract/operations/target.js +167 -0
  94. package/dist/shortcuts/smart-extract/operations/types.js +22 -0
  95. package/dist/shortcuts/smart-extract/operations/validate.js +454 -0
  96. package/dist/shortcuts/workflow/operations/form.js +68 -33
  97. package/dist/shortcuts/workflow/operations/read.js +19 -1
  98. package/docs/SKILL.md +1 -1
  99. package/docs/_catalog.md +3 -0
  100. package/docs/agent-invoice.md +5 -7
  101. package/docs/data.md +5 -1
  102. package/docs/fna.md +14 -1
  103. package/docs/invoice.md +7 -5
  104. package/docs/smart-extract.md +156 -0
  105. package/package.json +1 -1
  106. package/skill-template/business-info.json +16 -1
  107. package/skill-template/domains/qiyecheng.md +2 -0
  108. package/skill-template/domains/smart-extract.md +16 -0
  109. package/skill-template/domains/yepiaotong.md +2 -2
  110. package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
  111. package/skills/weaver-e10-jinchengda/SKILL.md +223 -35
  112. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +47 -481
  113. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +11 -11
  114. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +3 -3
  115. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  116. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +32 -16
  117. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +478 -0
  118. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  119. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +2 -2
  120. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +39 -61
  121. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +18 -13
  122. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +2 -2
  123. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +21 -6
  124. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +6 -4
  125. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +3 -3
  126. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +263 -0
  127. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +525 -0
  128. package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +36 -0
  129. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
  130. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +87 -0
  131. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +80 -54
  132. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +110 -14
  133. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +19 -21
  134. package/skills/weaver-e10-jinchengda/references/orchestration.md +12 -12
  135. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1 -6
  136. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +2 -1
  137. package/skills/weaver-e10-qiyecheng/SKILL.md +37 -0
  138. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +14 -0
  139. package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
  140. package/skills/weaver-e10-qiyecheng/references/catalog.md +25 -0
  141. package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
  142. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
  143. package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
  144. package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
  145. package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
  146. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +34 -27
  147. package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
  148. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
  149. package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
  150. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
  151. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
  152. package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
  153. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
  154. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  155. package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
  156. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -42
  157. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
  158. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
  159. package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
  160. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
  161. package/skills/weaver-e10-smart-extract/SKILL.md +180 -0
  162. package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
  163. package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
  164. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +106 -0
  165. package/skills/weaver-e10-workflow/references/workflow-create.md +6 -5
  166. package/skills/weaver-e10-workflow/references/workflow-edit.md +1 -1
  167. package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
  168. package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
  169. package/skills/weaver-e10-yepiaotong/SKILL.md +46 -33
  170. package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
  171. package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
  172. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
  173. package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
  174. package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
  175. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +12 -8
  176. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
  177. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +91 -2
  178. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +1 -1
  179. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +12 -12
  180. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
  181. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +136 -91
  182. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +109 -23
  183. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
  184. package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
  185. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
  186. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
  187. package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +0 -265
  188. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
  189. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +0 -588
  190. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +0 -118
  191. package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
@@ -14,7 +14,7 @@ import {
14
14
  validateRuleFile,
15
15
  workflowOperationDefinitions,
16
16
  workflowSuccess
17
- } from "./chunk-6T53BSWZ.js";
17
+ } from "./chunk-XPQN4E5O.js";
18
18
  import {
19
19
  createWorkflowHost
20
20
  } from "./chunk-HFXK54M4.js";
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ var builtinShortcuts = [
40
40
  lazyShortcut({
41
41
  name: "invoice",
42
42
  description: "E10 \u4E1A\u7968\u901A\u53D1\u7968\u7BA1\u7406 CLI",
43
- load: async () => (await import("./chunks/invoice-E7GOITEU.js")).invoiceShortcut
43
+ load: async () => (await import("./chunks/invoice-V7ZTITUO.js")).invoiceShortcut
44
44
  }),
45
45
  lazyShortcut({
46
46
  name: "ehr",
@@ -50,7 +50,7 @@ var builtinShortcuts = [
50
50
  lazyShortcut({
51
51
  name: "recruit-stage",
52
52
  description: "\u6CDB\u5FAEE10\u62DB\u8058\u52A9\u624B\uFF08JD\u751F\u6210/\u7B80\u5386\u5EFA\u6863/AI\u9762\u8BD5\u9080\u7EA6\uFF09CLI",
53
- load: async () => (await import("./chunks/recruit-stage-FKWS5UQF.js")).recruitStageShortcut
53
+ load: async () => (await import("./chunks/recruit-stage-XCMVEQA2.js")).recruitStageShortcut
54
54
  }),
55
55
  lazyShortcut({
56
56
  name: "cowork",
@@ -90,7 +90,7 @@ var builtinShortcuts = [
90
90
  lazyShortcut({
91
91
  name: "meeting",
92
92
  description: "\u6CDB\u5FAEE10\u4F1A\u8BAE\u7BA1\u7406 CLI\uFF08\u6807\u51C6\u7248\uFF1A\u67E5\u8BE2/\u51B2\u7A81/\u9884\u7EA6/\u56DE\u6267/\u7B7E\u5230\uFF09",
93
- load: async () => (await import("./chunks/meeting-4BBLVAWM.js")).meetingShortcut
93
+ load: async () => (await import("./chunks/meeting-IIY4UAJL.js")).meetingShortcut
94
94
  }),
95
95
  lazyShortcut({
96
96
  name: "okr",
@@ -140,7 +140,7 @@ var builtinShortcuts = [
140
140
  lazyShortcut({
141
141
  name: "workflow",
142
142
  description: "\u6CDB\u5FAEE10\u6D41\u7A0B\u667A\u80FD\u52A9\u624B CLI\uFF08\u67E5\u8BE2/\u67E5\u770B/\u64CD\u4F5C/\u6279\u91CF/\u53D1\u8D77/\u4FEE\u6539\uFF09",
143
- load: async () => (await import("./chunks/workflow-3ZAF2J5E.js")).workflowShortcut
143
+ load: async () => (await import("./chunks/workflow-YHXFIU63.js")).workflowShortcut
144
144
  }),
145
145
  lazyShortcut({
146
146
  name: "blog",
@@ -155,17 +155,22 @@ var builtinShortcuts = [
155
155
  lazyShortcut({
156
156
  name: "contract",
157
157
  description: "\u6CDB\u5FAEE10\u4ECA\u627F\u8FBE\u5408\u540C\u7BA1\u7406 CLI",
158
- load: async () => (await import("./chunks/contract-VUC6JOPG.js")).contractShortcut
158
+ load: async () => (await import("./chunks/contract-LJRAXVZU.js")).contractShortcut
159
159
  }),
160
160
  lazyShortcut({
161
161
  name: "reception",
162
162
  description: "\u6CDB\u5FAE\u5BA2\u6237\u53C2\u89C2\u63A5\u5F85\u6D41\u7A0B CLI\uFF08\u9762\u677F/\u884C\u7A0B\u5355\u4E0E\u5185\u90E8\u65B9\u6848/\u586B\u5355\u9875\u9884\u586B\uFF09",
163
163
  load: async () => (await import("./chunks/reception-QGPNTGHG.js")).receptionShortcut
164
164
  }),
165
+ lazyShortcut({
166
+ name: "smart-extract",
167
+ description: "\u6CDB\u5FAEE10\u667A\u80FD\u62BD\u53D6 CLI\uFF08\u8868\u5355\u7ED3\u6784 / \u9644\u4EF6\u6B63\u6587 / \u6821\u9A8C\u5E76\u843D\u5E93\uFF0C\u8FD4\u56DE aiExtraId\uFF09",
168
+ load: async () => (await import("./chunks/smart-extract-FOUYNIG3.js")).smartExtractShortcut
169
+ }),
165
170
  lazyShortcut({
166
171
  name: "data",
167
172
  description: "\u6CDB\u5FAEE10\u6570\u636E\u52A9\u624B CLI\uFF08\u6570\u636E\u6E90\u67E5\u8BE2 / \u914D\u7F6E\u4E2D\u5FC3 / \u573A\u666F\u5B9A\u4F4D\uFF09",
168
- load: async () => (await import("./chunks/data-QO7QWOIV.js")).dataShortcut
173
+ load: async () => (await import("./chunks/data-WK5CQXNF.js")).dataShortcut
169
174
  })
170
175
  ];
171
176
  function shortcutMetadata() {
@@ -434,6 +434,105 @@ const quoteContracts = [
434
434
  fixed: { local: true, kind: 'rmb-upper' },
435
435
  inputSchema: readSchema({ num: { type: 'string', minLength: 1 } }, ['num']),
436
436
  },
437
+ {
438
+ name: 'contract.docx.fillfromquote',
439
+ risk: 'local-file-write',
440
+ fixed: { local: true, kind: 'docx-fill-from-quote' },
441
+ inputSchema: readSchema({
442
+ template: { type: 'string', minLength: 1, maxLength: 4096, description: '模板 docx 绝对路径' },
443
+ data: {
444
+ anyOf: [{ type: 'object' }, { type: 'string' }],
445
+ description: '报价数据对象,或其 JSON 文件路径(customer/our_company/sign_date/sign_place/title/product_total/service_total/grand_total/product_items/service_items/payment_ratios)',
446
+ },
447
+ out: { type: 'string', maxLength: 4096, description: '输出 docx 绝对路径(scanOnly / dryRun 时可省)' },
448
+ scanOnly: { type: 'boolean', description: '只扫描占位符清单,不做任何替换' },
449
+ dryRun: { type: 'boolean', description: '只填不存,用于确认行位' },
450
+ expect: { type: 'array', items: { type: 'string' }, description: '追加需要扫描/校验的占位模式' },
451
+ detailTable: { type: 'integer', minimum: 0, description: '明细表索引(0 基);不传按表头特征探测' },
452
+ titleCount: { type: 'integer', minimum: 0, description: '合同名称期望出现次数;不传只要求 >=1' },
453
+ }, ['template']),
454
+ },
455
+ {
456
+ name: 'contract.docx.verify',
457
+ risk: 'read',
458
+ fixed: { local: true, kind: 'docx-verify' },
459
+ inputSchema: readSchema({
460
+ path: { type: 'string', minLength: 1, maxLength: 4096, description: 'docx 绝对路径' },
461
+ patterns: { type: 'array', items: { type: 'string' }, description: '需要检查残留的占位文本;缺省用内置集合(xxx公司/***有限公司/年 月 日/【】/____/{{ 等)' },
462
+ title: { type: 'string', description: '应出现的合同名称,用于校验标题替换是否完整' },
463
+ titleCount: { type: 'integer', minimum: 0, description: '标题期望出现次数;传了就要求精确相等,不传只要求至少 1 次' },
464
+ out: { type: 'string', maxLength: 4096, description: '可选:校验报告 JSON 输出路径' },
465
+ }, ['path']),
466
+ },
467
+ {
468
+ name: 'contract.quotescreen.run',
469
+ risk: 'local-file-write',
470
+ fixed: { local: true, kind: 'quote-screen' },
471
+ inputSchema: readSchema({
472
+ file: { type: 'string', minLength: 1, maxLength: 4096, description: '报价单 .xlsx 绝对路径' },
473
+ outDir: { type: 'string', minLength: 1, maxLength: 4096, description: '中间产物与卡片输出目录' },
474
+ mode: { type: 'string', enum: ['auto', 'stage1', 'stage2'], description: '默认 auto:提取→解析→自动识客户→金额校验→出卡片;stage1 只出网格与骨架;stage2 只出文字摘要与卡片' },
475
+ sheet: { type: 'string', description: '指定工作表名;不传取第一个(多 sheet 时会写 warnings 提示)' },
476
+ summaryData: { type: 'string', maxLength: 4096, description: 'mode=stage2 时的摘要 JSON 路径(模型产出)' },
477
+ docType: { type: 'string', description: 'quote | tender,默认 quote' },
478
+ title: { type: 'string', description: '卡片标题,默认由动作引擎计算' },
479
+ companyName: { type: 'string', description: '对方企业全称(模型判定后传入),用于追加「查对方资信」卡' },
480
+ baseUrl: { type: 'string', description: '当前环境 baseUrl;缺省取内置默认值' },
481
+ head: { type: 'integer', minimum: 1, maximum: 200, description: '网格预览头部行数,默认 12' },
482
+ }, ['file', 'outDir']),
483
+ },
484
+ {
485
+ name: 'contract.triage.extract',
486
+ risk: 'local-file-write',
487
+ fixed: { local: true, kind: 'triage-extract' },
488
+ inputSchema: readSchema({
489
+ file: { type: 'string', minLength: 1, maxLength: 4096, description: '主合同文件绝对路径(.docx/.doc/.txt/.md;.pdf 需先用 parse_document 兜底)' },
490
+ attach: { type: 'array', items: { type: 'string' }, description: '随附文件(补充协议/清单等);正文按序合并在主文件之后,flowKey 判定仍只看主文件' },
491
+ outDir: { type: 'string', minLength: 1, maxLength: 4096, description: '产物目录:contract_text.txt / triage.json / summary_skeleton.json / ai_fill.json / contract_sections.txt / text_sources.json' },
492
+ elements: { type: 'string', maxLength: 4096, description: '模型语义提取的 elements.json;给了就合并进 triage.json 供 elements.build 使用' },
493
+ summaryData: { type: 'string', maxLength: 4096, description: '模型语义生成的 summary_data.json;给了就落地为最终摘要数据' },
494
+ aiFill: { type: 'string', maxLength: 4096, description: '模型填好的 ai_fill.json(含 elements + summary);等价于同时传 elements 与 summaryData' },
495
+ reuse: { type: 'boolean', description: '阶段2 复用已有 triage.json:只合并 elements/summary_data,跳过正文抽取与指纹打分' },
496
+ }, ['file', 'outDir']),
497
+ },
498
+ {
499
+ name: 'contract.ledger.aggregate',
500
+ risk: 'read',
501
+ fixed: { local: true, kind: 'ledger-aggregate' },
502
+ inputSchema: readSchema({
503
+ ref: { type: 'string', minLength: 1, description: '单个 refId(weaver-work-cli refs 暂存结果)' },
504
+ refs: { type: 'array', items: { type: 'string' }, description: '多个 refId:分批取数后合并统计' },
505
+ file: { type: 'string', maxLength: 4096, description: '直接给结果 JSON 文件路径(与 ref/refs 可同时使用)' },
506
+ refsDir: { type: 'string', maxLength: 4096, description: 'refs 根目录;默认 ~/.weaver-work-cli/state/refs' },
507
+ by: { type: 'array', items: { type: 'string' }, description: '分组字段(语义键,如 xsjl / khmc);不传只出总计' },
508
+ sum: { type: 'array', items: { type: 'string' }, description: '求和字段(金额,如 htzje / yxje)' },
509
+ where: { type: 'array', items: { type: 'string' }, description: '过滤条件,形如 xsjl=吴洋洋(子串匹配)' },
510
+ dedupe: { type: 'boolean', description: '按 id / form_data_id / rowKey / ebrecord_rowkey 去重(分批窗口重叠时使用)' },
511
+ detail: { type: 'boolean', description: '输出命中明细(签订日期/合同号/客户/销售经理/合同总金额)' },
512
+ limit: { type: 'integer', minimum: 1, maximum: 1000, description: '明细最多返回条数,默认 20' },
513
+ }),
514
+ },
515
+ {
516
+ name: 'contract.ledger.guard',
517
+ risk: 'read',
518
+ fixed: { local: true, kind: 'ledger-guard' },
519
+ inputSchema: readSchema({
520
+ menu: { type: 'string', minLength: 1, description: '台账名(直销合同/直销业绩/合同收款/项目验收/渠道订单/渠道订单-商务)' },
521
+ total: { type: 'integer', minimum: 0, description: '探量(pageSize=1&maxPages=1)得到的真实总数 getListDataCount' },
522
+ condition: {
523
+ type: 'string',
524
+ enum: ['none', 'time', 'person', 'customer', 'contract'],
525
+ description: '本次已带的约束类型;none 表示无条件,直接拒绝',
526
+ },
527
+ rowsPerRecord: { type: 'number', description: '单条记录体积估算(KB),默认 3.3' },
528
+ comParams: {
529
+ anyOf: [{ type: 'string' }, { type: 'object' }],
530
+ description: '兜底卡片要预置的筛选条件(JSON 对象或其字符串);ebdf 列表卡必须用 field_<字段id>',
531
+ },
532
+ comParamsFile: { type: 'string', maxLength: 4096, description: '同 comParams,但从 UTF-8 JSON 文件读取' },
533
+ origin: { type: 'string', description: '兜底卡片的 scheme+host;不传时取当前会话 baseUrl' },
534
+ }, ['menu', 'total']),
535
+ },
437
536
  {
438
537
  name: 'contract.summary.render',
439
538
  risk: 'local-file-write',
@@ -455,6 +554,135 @@ const quoteContracts = [
455
554
  baseUrl: { type: 'string', minLength: 1, maxLength: 2048, description: '可选:当前 E10 环境地址,缺省取登录会话' },
456
555
  }, ['data', 'out']),
457
556
  },
557
+ {
558
+ name: 'contract.card.plan',
559
+ risk: 'read',
560
+ fixed: { local: true, kind: 'card-plan' },
561
+ inputSchema: readSchema({
562
+ context: {
563
+ type: 'object',
564
+ description: '上下文状态对象(scene / docType / flowKey / reviewed / submitted 等);优先于 contextFile / contextJson',
565
+ },
566
+ contextFile: { type: 'string', minLength: 1, maxLength: 4096, description: '上下文状态 JSON 文件路径' },
567
+ contextJson: { type: 'string', minLength: 1, description: '上下文状态 JSON 字符串' },
568
+ }),
569
+ },
570
+ {
571
+ name: 'contract.card.ebdf-list',
572
+ risk: 'local-file-write',
573
+ fixed: { local: true, kind: 'ebdf-list-card' },
574
+ inputSchema: readSchema({
575
+ menu: { type: 'string', description: '菜单名或别名(直销合同/直销业绩/合同收款/项目验收/渠道订单/渠道订单-商务);前四个用台账页卡,合同收款与项目验收用列表卡' },
576
+ pageId: { type: 'string', pattern: '^\\d{6,}$', description: '直接给 pageId;与 menu 二选一,同时给时以 pageId 为准(按列表卡生成)' },
577
+ origin: { type: 'string', minLength: 1, description: '必填:scheme+host,不带路径或 query,不含 {baseUrl}' },
578
+ title: { type: 'string', description: '卡片标题,默认取菜单名' },
579
+ callId: { type: 'string', description: '默认 ledger-<菜单>-<YYYYMMDDHHmm>-01;列表卡为 ebdf-list-<菜单>-<YYYYMMDDHHmm>-01' },
580
+ comParamPairs: { type: 'array', items: { type: 'string' }, description: '台账页:形如 khmc=泛微 的台账键(日期/金额区间请用 comParamsJson);列表卡:形如 field_<字段id>=<值>;与 comParamsJson 互斥' },
581
+ comParamsJson: { type: 'string', description: '筛选对象的 JSON 字符串:台账页传 { "khmc": "泛微", "qdrq": ["2024-01-01", "2024-12-31"] };列表卡传 comParams 对象;与 comParamPairs 互斥' },
582
+ out: { type: 'string', maxLength: 4096, description: '可选:卡片 JSON 输出路径' },
583
+ }, ['origin']),
584
+ },
585
+ {
586
+ name: 'contract.card.risk-report',
587
+ risk: 'local-file-write',
588
+ fixed: { local: true, kind: 'risk-report-card' },
589
+ inputSchema: readSchema({
590
+ ref: { type: 'string', maxLength: 4096, description: 'CLI 落盘的审查结果 JSON(含 envelope);与 data 二选一' },
591
+ data: { type: 'string', maxLength: 4096, description: '已归一化的 report_data.json;与 ref 二选一' },
592
+ out: { type: 'string', maxLength: 4096, description: '可选:HTML 输出路径(不传则不落盘,报告仅作卡片交付)' },
593
+ payload: { type: 'string', maxLength: 4096, description: '可选:同时输出 browsertool payload JSON 的路径' },
594
+ dumpData: { type: 'string', maxLength: 4096, description: '可选:只抽取数据并保存到此路径' },
595
+ template: { type: 'string', maxLength: 4096, description: '可选:自定义模板路径;缺省用内置模板' },
596
+ contract: { type: 'string', description: '合同名称' },
597
+ partyA: { type: 'string', description: '甲方' },
598
+ partyB: { type: 'string', description: '乙方' },
599
+ reviewDate: { type: 'string', description: '审查日期' },
600
+ fileId: { type: 'string', description: '审查 fileId(打开详情用)' },
601
+ fileName: { type: 'string', description: '审查文件名' },
602
+ aiid: { type: 'string', description: '审查助手 id,默认 1326842382967570463' },
603
+ baseUrl: { type: 'string', maxLength: 2048, description: 'E10 地址,默认 https://www.e-cology.com.cn' },
604
+ cardId: { type: 'string', description: '卡片唯一 id' },
605
+ callId: { type: 'string', description: 'payload callId' },
606
+ title: { type: 'string', description: '卡片标题' },
607
+ }),
608
+ },
609
+ {
610
+ name: 'contract.card.action',
611
+ risk: 'local-file-write',
612
+ fixed: { local: true, kind: 'action-card-render' },
613
+ inputSchema: readSchema({
614
+ context: { type: 'object', description: '上下文状态对象(scene / docType / flowKey / reviewed / submitted 等);优先于 contextFile / contextJson' },
615
+ contextFile: { type: 'string', maxLength: 4096, description: '上下文状态 JSON 文件路径;都缺省时按产物目录找 card_context.json / first_screen_result.json' },
616
+ contextJson: { type: 'string', description: '上下文状态 JSON 字符串' },
617
+ fileId: { type: 'string', description: '审查/流程用的 fileId' },
618
+ fileName: { type: 'string', description: '合同文件名(打开审查详情用)' },
619
+ flowKey: { type: 'string', enum: ['契约锁', '新客户', '常规二次销售', '老客户增值'], description: '合同流程类型;决定「发起流程」卡是否生成' },
620
+ companyName: { type: 'string', description: '对方企业全称;决定「查对方资信」卡是否生成' },
621
+ summaryHtml: { type: 'string', maxLength: 4096, description: '摘要 HTML 文件路径(内嵌为「查看合同摘要」内容)' },
622
+ reportHtml: { type: 'string', maxLength: 4096, description: '审查报告 HTML 文件路径(内嵌为「导出审查报告」内容)' },
623
+ compareHtml: { type: 'string', maxLength: 4096, description: '比对报告 HTML 文件路径(内嵌为「生成比对报告」内容)' },
624
+ aiExtraId: { type: 'string', description: '要素预填识别记录 ID;缺省从 context 的 aiExtraId 取' },
625
+ attachmentFieldId: { type: 'string', description: '合同文件在表单上的附件字段 ID;缺省从 context 取' },
626
+ fieldAssignKeys: { type: 'string', description: '赋值字段 ID,逗号拼接字符串(非数组);缺省取合同文件字段或 context 的 fieldAssignKeys' },
627
+ baseUrl: { type: 'string', maxLength: 2048, description: 'E10 地址,默认 https://www.e-cology.com.cn' },
628
+ aiid: { type: 'string', description: '审查助手 id,默认 1326842382967570463' },
629
+ cardId: { type: 'string', description: '卡片唯一 id,默认 card-<YYYYMMDDHHmm>' },
630
+ callId: { type: 'string', description: 'payload callId,默认 contract-card-<stamp>-01' },
631
+ title: { type: 'string', description: '卡片标题,默认「可做的 N 件事」' },
632
+ only: { type: 'string', description: '只输出指定动作,逗号分隔(如 launch-flow);仍由本操作生成' },
633
+ template: { type: 'string', maxLength: 4096, description: '可选:自定义模板路径;缺省用内置模板' },
634
+ out: { type: 'string', maxLength: 4096, description: '可选:写入 browsertool 文件;不传则只在结果中返回' },
635
+ }),
636
+ },
637
+ {
638
+ name: 'contract.elements.build',
639
+ risk: 'local-file-write',
640
+ fixed: { local: true, kind: 'elements-build' },
641
+ inputSchema: readSchema({
642
+ triage: { type: 'string', minLength: 1, maxLength: 4096, description: 'triage.json 路径(抽正文与要素的产物)' },
643
+ fileId: { type: 'string', minLength: 1, description: 'flow.launch 返回的 workflow fileId' },
644
+ flow: { type: 'string', minLength: 1, description: '新客户 / 契约锁 / 常规二次销售 / 老客户增值' },
645
+ sourceText: { type: 'string', maxLength: 4096, description: '合同正文纯文本路径;缺省取 triage 同目录 contract_text.txt' },
646
+ fileIds: { type: 'array', items: { type: 'string' }, description: '多文件时的附件 ID 列表(与 text_sources.json 文件数一致才用于 origin 归属)' },
647
+ workflowId: { type: 'string', description: '流程 ID;无内置字段表时配合 attachmentFieldId 出最小记录' },
648
+ attachmentFieldId: { type: 'string', description: '合同文件字段 ID;无内置字段表时必填,仅登记附件兜底' },
649
+ out: { type: 'string', maxLength: 4096, description: '可选:recognize.json 输出路径' },
650
+ }, ['triage', 'fileId', 'flow']),
651
+ },
652
+ {
653
+ name: 'contract.firstscreen.run',
654
+ risk: 'local-file-write',
655
+ fixed: { local: true, kind: 'first-screen-orchestration' },
656
+ inputSchema: readSchema({
657
+ file: { type: 'string', minLength: 1, maxLength: 4096, description: '主合同文件绝对路径' },
658
+ outDir: { type: 'string', minLength: 1, maxLength: 4096, description: '产物目录(放中间 JSON、summary.html、card.html)' },
659
+ attach: { type: 'array', items: { type: 'string' }, description: '随附文件(协议/补充协议/清单);预审一并上传,发起流程的附件字段只挂主文件' },
660
+ flow: { type: 'string', enum: ['契约锁', '新客户', '常规二次销售', '老客户增值'], description: '留空则从 triage.json 的 flowKey 读取' },
661
+ triage: { type: 'string', maxLength: 4096, description: 'triage.json 路径;缺省取 outDir/triage.json' },
662
+ aiFill: { type: 'string', maxLength: 4096, description: 'ai_fill.json(elements + summary 合并);给了就自动拆出 summary_data.json' },
663
+ summaryData: { type: 'string', maxLength: 4096, description: 'summary_data.json 路径;不传则跳过摘要渲染' },
664
+ recognizeFile: { type: 'string', maxLength: 4096, description: 'recognizeResult 的 JSON 文件;不传则用内置字段表自动组装,拿不到就降级' },
665
+ companyName: { type: 'string', description: '对方主体全称,用于资信卡' },
666
+ counterparty: { type: 'boolean', description: '是否存在可查的对方主体' },
667
+ skipUpload: { type: 'boolean', description: '跳过预审上传(仅需流程页时)' },
668
+ baseUrl: { type: 'string', maxLength: 2048, description: 'E10 地址,默认 https://www.e-cology.com.cn' },
669
+ aiid: { type: 'string', description: '审查助手 id(透传给卡片)' },
670
+ printCard: { type: 'boolean', description: '把成品卡片 HTML 一并返回(data.cardHtmlContent)' },
671
+ }, ['file', 'outDir']),
672
+ },
673
+ {
674
+ name: 'contract.summary.validate',
675
+ risk: 'local-file-write',
676
+ fixed: { local: true, kind: 'summary-validate' },
677
+ inputSchema: readSchema({
678
+ summary: { type: 'string', minLength: 1, maxLength: 4096, description: '模型生成的 summary_data.json 路径' },
679
+ text: { type: 'string', maxLength: 4096, description: '可选:contract_text.txt,用于金额回查' },
680
+ triage: { type: 'string', maxLength: 4096, description: '可选:triage.json;配合 elements 合流要素' },
681
+ elements: { type: 'string', maxLength: 4096, description: '可选:模型语义提取的 elements.json' },
682
+ outSummary: { type: 'string', maxLength: 4096, description: '可选:校验通过后落地的 summary_data.json 路径' },
683
+ strict: { type: 'boolean', description: '可选:WARN 也视为不通过(仅影响 data.pass,不改变 fails)' },
684
+ }, ['summary']),
685
+ },
458
686
  {
459
687
  name: 'contract.file.download',
460
688
  risk: 'local-file-write',
@@ -592,6 +820,29 @@ export const contractOperations = [
592
820
  fixed: { method: 'GET', path: '/api/ebd/contract/tplinfo/getById' },
593
821
  inputSchema: readSchema({ id: idString }, ['id']),
594
822
  },
823
+ {
824
+ // 范文库(「合同范文管理」EB 表单)。本技能内「模板」== 「范文」,
825
+ // 与合同模板库 tplinfo(contract.template.*)是互不相通的两个对象。
826
+ name: 'contract.modeltext.list',
827
+ risk: 'read',
828
+ auth: AUTH,
829
+ fixed: {
830
+ method: 'POST',
831
+ path: '/api/ebuilder/form/list/getListDatas',
832
+ defaults: {
833
+ passid: '1290191829260230657',
834
+ cid: '1290191829260230657',
835
+ listId: '1290191833571975256',
836
+ },
837
+ headers: { ebbusinessid: '1290191833571975256' },
838
+ note: '分页以 body.current 传页码;真实总数取 pagination.mainRecordTotal',
839
+ },
840
+ inputSchema: readSchema({
841
+ pageNo: { type: 'integer', minimum: 1, default: 1 },
842
+ pageSize: { type: 'integer', minimum: 1, maximum: 200, default: 50 },
843
+ tableuid: { type: 'string', description: '数据表 uid;省略时由服务端按视图解析' },
844
+ }),
845
+ },
595
846
  {
596
847
  name: 'contract.clause.tree',
597
848
  risk: 'read',
@@ -0,0 +1,233 @@
1
+ /**
2
+ * OOXML 表格结构操作(2026-11-13 新增,P3 能力补齐)。
3
+ *
4
+ * 背景:`scripts/fill_contract_from_quote.py` 的 `reshape_rows()` 需要「把明细区
5
+ * 压缩为 N 行」——即删除多余的 `<w:tr>`。此前这一步只能靠 python-docx,属
6
+ * Node 侧的能力缺口;技能文档多次警告过「用正则重建 `<w:tr>` 会丢 `<w:tc>`、
7
+ * 表格塌成 0 格」,所以这里不做重建,只做**按边界整体切除**:
8
+ * 定位 `<w:tr>` 的起止偏移,原样切除区间,其余 XML 一个字节都不动。
9
+ *
10
+ * 与 python-docx `table.rows[idx]._tr.getparent().remove(tr)` 的语义一致:
11
+ * 只删行,不新增行、不改 `w:tcPr`、不重排 `w:gridSpan` / `w:vMerge`。
12
+ * 因此「行数不足需要新增」仍属不支持场景,必须由调用方按 not_enough_rows 处理。
13
+ */
14
+ /** 段落纯文本:只取 `<w:t>`,与 python-docx 的 paragraph.text 口径一致。 */
15
+ export function paragraphText(xml) {
16
+ let out = '';
17
+ for (const match of xml.matchAll(/<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/gu)) {
18
+ out += decodeXml(match[1] ?? '');
19
+ }
20
+ return out;
21
+ }
22
+ export function decodeXml(text) {
23
+ let out = text;
24
+ out = out.split('&lt;').join('<');
25
+ out = out.split('&gt;').join('>');
26
+ out = out.split('&quot;').join('"');
27
+ out = out.split('&apos;').join("'");
28
+ out = out.split('&amp;').join('&');
29
+ return out;
30
+ }
31
+ export function encodeXml(text) {
32
+ let out = text;
33
+ out = out.split('&').join('&amp;');
34
+ out = out.split('<').join('&lt;');
35
+ out = out.split('>').join('&gt;');
36
+ return out;
37
+ }
38
+ /** 收集指定标签的**成对**区间(含嵌套,按 start 升序)。 */
39
+ export function collectRanges(xml, tag) {
40
+ const ranges = [];
41
+ const open = new RegExp(`<${tag}(?:\\s[^>]*)?>`, 'gu');
42
+ const close = new RegExp(`</${tag}>`, 'gu');
43
+ const events = [];
44
+ for (const m of xml.matchAll(open))
45
+ events.push({ pos: m.index ?? 0, open: true });
46
+ for (const m of xml.matchAll(close))
47
+ events.push({ pos: m.index ?? 0, open: false });
48
+ events.sort((a, b) => a.pos - b.pos);
49
+ const stack = [];
50
+ for (const event of events) {
51
+ if (event.open) {
52
+ stack.push(event.pos);
53
+ }
54
+ else {
55
+ const start = stack.pop();
56
+ if (start === undefined)
57
+ continue;
58
+ const end = event.pos + `</${tag}>`.length;
59
+ // 只保留最外层:内层区间一定被外层覆盖
60
+ if (!ranges.some((r) => start >= r.start && end <= r.end))
61
+ ranges.push({ start, end });
62
+ }
63
+ }
64
+ ranges.sort((a, b) => a.start - b.start);
65
+ return ranges;
66
+ }
67
+ /** 解析**顶层**表格(`depth=1`),行与单元格都不含嵌套表格内部结构。 */
68
+ export function parseTables(xml) {
69
+ const tables = [];
70
+ const topTables = collectRanges(xml, 'w:tbl');
71
+ topTables.forEach((tableRange, tableIndex) => {
72
+ const tableXml = xml.slice(tableRange.start, tableRange.end);
73
+ const rows = [];
74
+ // 在 tableXml 内按深度扫描,只收 depth===1 的 <w:tr>
75
+ const tokens = /<w:tbl(?:\s[^>]*)?>|<\/w:tbl>|<w:tr(?:\s[^>]*)?>|<\/w:tr>|<w:tc(?:\s[^>]*)?>|<\/w:tc>|<w:gridCol(?:\s[^>]*)?\/?>/gu;
76
+ let depth = 0;
77
+ let rowOpen = -1;
78
+ let cellOpen = -1;
79
+ let cols = 0;
80
+ const rawRows = [];
81
+ let currentCells = [];
82
+ let match;
83
+ while ((match = tokens.exec(tableXml)) !== null) {
84
+ const token = match[0];
85
+ const pos = match.index ?? 0;
86
+ if (token.startsWith('<w:tbl')) {
87
+ depth += 1;
88
+ }
89
+ else if (token === '</w:tbl>') {
90
+ depth -= 1;
91
+ }
92
+ else if (depth !== 1) {
93
+ continue;
94
+ }
95
+ else if (token.startsWith('<w:tr')) {
96
+ rowOpen = pos;
97
+ currentCells = [];
98
+ }
99
+ else if (token === '</w:tr>') {
100
+ if (rowOpen >= 0) {
101
+ rawRows.push({ start: rowOpen, end: pos + '</w:tr>'.length, cells: currentCells });
102
+ rowOpen = -1;
103
+ }
104
+ }
105
+ else if (token.startsWith('<w:tc')) {
106
+ cellOpen = pos;
107
+ }
108
+ else if (token === '</w:tc>') {
109
+ if (cellOpen >= 0) {
110
+ currentCells.push({ start: cellOpen, end: pos + '</w:tc>'.length });
111
+ cellOpen = -1;
112
+ }
113
+ }
114
+ else if (token.startsWith('<w:gridCol')) {
115
+ cols += 1;
116
+ }
117
+ }
118
+ rawRows.forEach((raw, rowIndex) => {
119
+ const rowXml = tableXml.slice(raw.start, raw.end);
120
+ const cells = raw.cells.map((cellRange, cellIndex) => {
121
+ const cellXml = tableXml.slice(cellRange.start, cellRange.end);
122
+ return {
123
+ index: cellIndex,
124
+ start: cellRange.start,
125
+ end: cellRange.end,
126
+ xml: cellXml,
127
+ text: paragraphText(cellXml),
128
+ };
129
+ });
130
+ const texts = cells.map((cell) => cell.text.trim());
131
+ rows.push({
132
+ index: rowIndex,
133
+ start: raw.start,
134
+ end: raw.end,
135
+ xml: rowXml,
136
+ cells,
137
+ text: texts.join(' | '),
138
+ uniqueCellCount: new Set(texts).size,
139
+ });
140
+ });
141
+ tables.push({
142
+ index: tableIndex,
143
+ start: tableRange.start,
144
+ end: tableRange.end,
145
+ rows,
146
+ text: rows.map((row) => row.text).join('\n'),
147
+ cols,
148
+ });
149
+ });
150
+ return tables;
151
+ }
152
+ /**
153
+ * 设置段落文本:首个 `<w:t>` 写新值(保留其 run 格式),其余 `<w:t>` 清空。
154
+ * 与脚本 `set_para_text()` 完全一致——不清除 run,避免丢失字体字号。
155
+ */
156
+ export function setParagraphText(pXml, value) {
157
+ const hits = [...pXml.matchAll(/<w:t(?:\s[^>]*)?>([\s\S]*?)<\/w:t>/gu)];
158
+ if (hits.length === 0)
159
+ return pXml;
160
+ let out = pXml;
161
+ // 从后往前替换,避免偏移漂移
162
+ for (let i = hits.length - 1; i >= 0; i -= 1) {
163
+ const hit = hits[i];
164
+ const start = hit.index ?? 0;
165
+ const end = start + hit[0].length;
166
+ const next = i === 0 ? encodeXml(value) : '';
167
+ let openTag = /^<w:t(?:\s[^>]*)?>/u.exec(hit[0])[0];
168
+ if (!/xml:space=/u.test(openTag)) {
169
+ openTag = openTag.replace('<w:t', '<w:t xml:space="preserve"');
170
+ }
171
+ out = out.slice(0, start) + `${openTag}${next}</w:t>` + out.slice(end);
172
+ }
173
+ return out;
174
+ }
175
+ /** 单元格整体替换:首个段落写值,清空其余段落(对应脚本 `set_cell()`)。 */
176
+ export function setCellText(cellXml, value) {
177
+ const paragraphs = collectRanges(cellXml, 'w:p');
178
+ if (paragraphs.length === 0) {
179
+ // 空单元格:在 </w:tc> 前插一个段落
180
+ const run = `<w:p><w:r><w:t xml:space="preserve">${encodeXml(value)}</w:t></w:r></w:p>`;
181
+ const closeIdx = cellXml.lastIndexOf('</w:tc>');
182
+ if (closeIdx < 0)
183
+ return cellXml;
184
+ return cellXml.slice(0, closeIdx) + run + cellXml.slice(closeIdx);
185
+ }
186
+ const first = paragraphs[0];
187
+ let firstXml = cellXml.slice(first.start, first.end);
188
+ if (/<w:t(?:\s[^>]*)?>/u.test(firstXml)) {
189
+ firstXml = setParagraphText(firstXml, value);
190
+ }
191
+ else {
192
+ firstXml =
193
+ firstXml.slice(0, -'</w:p>'.length) +
194
+ `<w:r><w:t xml:space="preserve">${encodeXml(value)}</w:t></w:r></w:p>`;
195
+ }
196
+ // 保留首个段落,删除其余段落(从后往前)
197
+ let out = cellXml.slice(0, first.start) + firstXml + cellXml.slice(first.end);
198
+ const extra = collectRanges(out, 'w:p').slice(1);
199
+ for (let i = extra.length - 1; i >= 0; i -= 1) {
200
+ const range = extra[i];
201
+ out = out.slice(0, range.start) + out.slice(range.end);
202
+ }
203
+ return out;
204
+ }
205
+ /**
206
+ * 把表格某区域压缩为 `keep` 行:删除 `[startRow, startRow+count)` 里多余的行。
207
+ *
208
+ * 只删除、不新增(新增需重建 `<w:tr>`,会破坏合并单元格)。
209
+ * 从后往前删,前面的行号不受影响;只切 `<w:tr>` 的原始区间,不重建 XML。
210
+ */
211
+ export function deleteTableRows(xml, tableIndex, startRow, keep, count) {
212
+ const tables = parseTables(xml);
213
+ const table = tables[tableIndex];
214
+ if (!table) {
215
+ return { xml, removed: 0, ok: false, reason: 'table_not_found' };
216
+ }
217
+ if (count < keep) {
218
+ return { xml, removed: 0, ok: false, reason: 'not_enough_rows' };
219
+ }
220
+ let out = xml;
221
+ let removed = 0;
222
+ // 从后往前:删除区间内最后一行,逐次前移,不影响未删行的偏移
223
+ for (let i = startRow + count - 1; i >= startRow + keep; i -= 1) {
224
+ const row = table.rows[i];
225
+ if (!row)
226
+ continue;
227
+ const absStart = table.start + row.start;
228
+ const absEnd = table.start + row.end;
229
+ out = out.slice(0, absStart) + out.slice(absEnd);
230
+ removed += 1;
231
+ }
232
+ return { xml: out, removed, ok: true };
233
+ }