weaver-work-cli 0.1.44 → 0.1.45

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 (179) hide show
  1. package/README.md +9 -5
  2. package/dist/chunks/{archive-P6TBQGKL.js → archive-ZQ4A4TV6.js} +388 -44
  3. package/dist/chunks/{archive-oa-7TQ2NXOH.js → archive-oa-BBDP7AKJ.js} +2 -2
  4. package/dist/chunks/{asset-3ELRG37G.js → asset-ZOJVBWZH.js} +2 -2
  5. package/dist/chunks/{asset-idle-WIGMUFMD.js → asset-idle-XGB5IPGT.js} +2 -2
  6. package/dist/chunks/{attachment-content-E3276UOV.js → attachment-content-CE3GMWTS.js} +3 -3
  7. package/dist/chunks/{blog-C5NMZAAC.js → blog-QSHLZSFW.js} +2 -2
  8. package/dist/chunks/caizhilian-KCQYFH72.js +204 -0
  9. package/dist/chunks/{calendar-FI2WNSBO.js → calendar-DLGMRJQA.js} +2 -2
  10. package/dist/chunks/{chunk-CWYGFU5B.js → chunk-3WBIQLMB.js} +2 -2
  11. package/dist/chunks/{chunk-PUQS5MWL.js → chunk-3YV7PKRL.js} +1 -1
  12. package/dist/chunks/{chunk-PC7VKEB5.js → chunk-3ZMAQQ3W.js} +161 -33
  13. package/dist/chunks/{chunk-GM6J7Q4B.js → chunk-4EXOIQDI.js} +40 -10
  14. package/dist/chunks/{chunk-ETNJSKMM.js → chunk-6NXT4ICB.js} +148 -21
  15. package/dist/chunks/chunk-762M5XJS.js +215 -0
  16. package/dist/chunks/{chunk-GAMZLAG2.js → chunk-77YP6I52.js} +1 -1
  17. package/dist/chunks/{chunk-WSF4NNMR.js → chunk-CZNZKOHR.js} +2 -2
  18. package/dist/chunks/{chunk-Z7VYWPZV.js → chunk-DGMYACGJ.js} +1 -1
  19. package/dist/chunks/{chunk-TA7FXXJD.js → chunk-DLY5GUXX.js} +1 -1
  20. package/dist/chunks/{chunk-BCVYBYYT.js → chunk-GR76ZDDX.js} +2 -2
  21. package/dist/chunks/{chunk-GRDRG6HP.js → chunk-HFXK54M4.js} +2 -2
  22. package/dist/chunks/{chunk-XNIK66I4.js → chunk-JB34OE7R.js} +790 -77
  23. package/dist/chunks/{chunk-QVSWRLLU.js → chunk-JWWTI63L.js} +55 -5
  24. package/dist/chunks/{chunk-FRZKBMSW.js → chunk-LGKWL4OH.js} +176 -39
  25. package/dist/chunks/{chunk-XHK4MDR5.js → chunk-LRCPNDZA.js} +38 -6
  26. package/dist/chunks/{chunk-OF4S23UB.js → chunk-LXFVWZLM.js} +4 -4
  27. package/dist/chunks/{chunk-D4ADSZ7H.js → chunk-O6CMPO65.js} +24 -1
  28. package/dist/chunks/{chunk-N4M2DDFE.js → chunk-OAE3AZBQ.js} +11 -11
  29. package/dist/chunks/chunk-P5GQRWDC.js +60 -0
  30. package/dist/chunks/{caizhilian-5XSM2DFP.js → chunk-PGO4ILMQ.js} +41 -521
  31. package/dist/chunks/{chunk-HIT4Y6OI.js → chunk-T4MWQAQB.js} +7 -5
  32. package/dist/chunks/{chunk-F4E4EM35.js → chunk-TGAGQV4I.js} +2 -2
  33. package/dist/chunks/{chunk-UFIT2UU3.js → chunk-U6R6FZHD.js} +168 -14
  34. package/dist/chunks/{chunk-FAZTGX7S.js → chunk-VIMCY4DI.js} +5 -5
  35. package/dist/chunks/chunk-VRPH24IC.js +76 -0
  36. package/dist/chunks/{chunk-3YBDYOC4.js → chunk-YIKSL36S.js} +2 -2
  37. package/dist/chunks/{chunk-IAZ3UPY6.js → chunk-Z6UUBY37.js} +2 -2
  38. package/dist/chunks/{conflict-ARLSZJ6V.js → conflict-IYJETSGT.js} +2 -2
  39. package/dist/chunks/continuation-GW6PRWK3.js +12 -0
  40. package/dist/chunks/{contract-DNIIW5VJ.js → contract-3QLAGYQL.js} +5793 -4591
  41. package/dist/chunks/{cowork-GMLRGVIW.js → cowork-3ACICHDQ.js} +2 -2
  42. package/dist/chunks/{create-flow-J22BO65E.js → create-flow-7JLC7UID.js} +6 -6
  43. package/dist/chunks/{ebuilder-form-ANV2FHYV.js → ebuilder-form-GWDTKEI2.js} +5 -5
  44. package/dist/chunks/{ehr-GSTGAIY3.js → ehr-MYRDCHZ4.js} +121 -49
  45. package/dist/chunks/{employee-22BGJ3QS.js → employee-NOHNXC46.js} +1 -1
  46. package/dist/chunks/{env-BX3VRFS7.js → env-3MBHAWBL.js} +2 -2
  47. package/dist/chunks/{esb-ATAIASX2.js → esb-4BQHNP5C.js} +4 -4
  48. package/dist/chunks/{factory-PETTFME6.js → factory-TZEVU4DU.js} +1 -1
  49. package/dist/chunks/{fna-YEKBSFSX.js → fna-ZVB2IILI.js} +2 -2
  50. package/dist/chunks/{group-chat-BFVXAYFX.js → group-chat-KL3HFKRM.js} +3 -3
  51. package/dist/chunks/{host-WIKN2EJ5.js → host-3TNBMDTR.js} +3 -3
  52. package/dist/chunks/host-7NTIBSPK.js +25 -0
  53. package/dist/chunks/{host-SZGV4UNT.js → host-7OWWPLM4.js} +3 -3
  54. package/dist/chunks/{host-HRBXEPDQ.js → host-G3VU7SDW.js} +3 -3
  55. package/dist/chunks/{host-LR55CTHP.js → host-M4XP5URR.js} +3 -3
  56. package/dist/chunks/{host-SUOY6VYQ.js → host-TUOIOEMC.js} +3 -3
  57. package/dist/chunks/{hrm-NRDO4W5G.js → hrm-UNKCCCGP.js} +5 -5
  58. package/dist/chunks/{im-IQ2HN23S.js → im-NJB7ZYMH.js} +3 -3
  59. package/dist/chunks/{invoice-MNRW76PP.js → invoice-OQP3TMKQ.js} +3 -3
  60. package/dist/chunks/{jiuchuanhui-DTRBAX4N.js → jiuchuanhui-ASFZBMPU.js} +2 -2
  61. package/dist/chunks/{lazy-dispatch-ZVWAI25B.js → lazy-dispatch-UH6HGK2I.js} +4 -4
  62. package/dist/chunks/{mail-ZVAUXOJA.js → mail-M3HJF5ER.js} +2 -2
  63. package/dist/chunks/{meeting-FEVPZ67S.js → meeting-C67EHQ4Z.js} +12 -12
  64. package/dist/chunks/{okr-SDH3E5RA.js → okr-EVX7FB5G.js} +2 -2
  65. package/dist/chunks/operations-J7PUIVWZ.js +15 -0
  66. package/dist/chunks/{plan-E35JFDI7.js → plan-2QJQEPBO.js} +2 -2
  67. package/dist/chunks/{project-73QXBAB2.js → project-XELELW2T.js} +2 -2
  68. package/dist/chunks/{reception-UWZVACBN.js → reception-5WITA44R.js} +2 -2
  69. package/dist/chunks/{recruit-stage-4MAOCKFY.js → recruit-stage-AHY5QAMF.js} +450 -117
  70. package/dist/chunks/{registry-JDUS4E7D.js → registry-AQVGHUM6.js} +2 -2
  71. package/dist/chunks/{registry-KNKSCJNT.js → registry-QJCZ2GVG.js} +4 -4
  72. package/dist/chunks/{registry-PO7SI256.js → registry-VWXWPVAG.js} +2 -2
  73. package/dist/chunks/{registry-IM5G23LS.js → registry-XPWPGHYE.js} +10 -10
  74. package/dist/chunks/{room-recommend-H7KLXA5R.js → room-recommend-CNWE5WQK.js} +6 -4
  75. package/dist/chunks/{schedule-ESZIBAUO.js → schedule-YYNYBQIE.js} +4 -4
  76. package/dist/chunks/{workflow-CWJFJLQU.js → workflow-BSYT5TGL.js} +6 -4
  77. package/dist/index.js +30 -30
  78. package/dist/internal/e10/auth/commands.js +32 -0
  79. package/dist/internal/e10/auth/error-log.js +156 -26
  80. package/dist/internal/e10/auth/xiaoe.js +176 -13
  81. package/dist/internal/e10/context.js +12 -1
  82. package/dist/shortcuts/archive/operations/borrow-list.js +105 -14
  83. package/dist/shortcuts/archive/operations/flow-url.js +182 -22
  84. package/dist/shortcuts/archive/operations/getPageUrl.js +75 -0
  85. package/dist/shortcuts/archive/operations/prelib.js +33 -4
  86. package/dist/shortcuts/archive/operations/shared.js +52 -0
  87. package/dist/shortcuts/contract/host.js +111 -4
  88. package/dist/shortcuts/contract/index.js +19 -0
  89. package/dist/shortcuts/contract/manifest.js +125 -0
  90. package/dist/shortcuts/contract/ooxml/clause-insert.js +249 -0
  91. package/dist/shortcuts/contract/operations/clause-insert.js +56 -0
  92. package/dist/shortcuts/contract/operations/customer.js +192 -0
  93. package/dist/shortcuts/contract/operations/file-download.js +75 -0
  94. package/dist/shortcuts/contract/operations/flow.js +44 -2
  95. package/dist/shortcuts/contract/operations/form-info.js +162 -62
  96. package/dist/shortcuts/contract/operations/registry.js +8 -0
  97. package/dist/shortcuts/contract/operations/review.js +116 -1
  98. package/dist/shortcuts/contract/operations/summary.js +177 -0
  99. package/dist/shortcuts/contract/operations/upload.js +64 -4
  100. package/dist/shortcuts/contract/upload-cache.js +104 -0
  101. package/dist/shortcuts/ehr/operations/recruit-candidate-import.js +4 -2
  102. package/dist/shortcuts/ehr/operations/recruit-position.js +136 -35
  103. package/dist/shortcuts/ehr/operations/recruit-write.js +17 -18
  104. package/dist/shortcuts/ehr/operations/recruit.js +17 -5
  105. package/dist/shortcuts/hrm/operations/employee.js +29 -1
  106. package/dist/shortcuts/meeting/operations/eb/create-flow.js +182 -58
  107. package/dist/shortcuts/meeting/operations/eb/draft-memory.js +56 -0
  108. package/dist/shortcuts/meeting/operations/eb/factory.js +58 -3
  109. package/dist/shortcuts/meeting/operations/eb/person-cache.js +2 -2
  110. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +47 -5
  111. package/dist/shortcuts/meeting/operations/invitation-publish.js +132 -0
  112. package/dist/shortcuts/meeting/operations/registry.js +2 -0
  113. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +86 -16
  114. package/dist/shortcuts/recruit-stage/operations/interview-feedback.js +6 -4
  115. package/dist/shortcuts/recruit-stage/operations/jd-create.js +208 -56
  116. package/dist/shortcuts/recruit-stage/operations/resume-import.js +42 -16
  117. package/dist/shortcuts/recruit-stage/shared.js +161 -18
  118. package/dist/shortcuts/workflow/index.js +2 -0
  119. package/dist/shortcuts/workflow/operations/read.js +8 -3
  120. package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupRules.js +92 -5
  121. package/dist/shortcuts/workflow/operations/todoSmartConvert/priorityExpr.js +509 -0
  122. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoListRows.js +22 -1
  123. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +32 -6
  124. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +57 -11
  125. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +165 -52
  126. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +57 -14
  127. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +44 -18
  128. package/docs/contract.md +1 -0
  129. package/docs/e10-auth.md +4 -2
  130. package/docs/todo-smart-convert/data-contract.md +7 -0
  131. package/package.json +1 -1
  132. package/skill-template/domains/jinchengda.md +2 -0
  133. package/skills/weaver-e10-jinchengda/SKILL.md +198 -205
  134. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +759 -0
  135. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +250 -0
  136. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +146 -7
  137. package/skills/weaver-e10-jinchengda/references/contract-clause-insert.md +178 -0
  138. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +75 -0
  139. package/skills/weaver-e10-jinchengda/references/contract-compare-report-template.html +137 -0
  140. package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +163 -0
  141. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +52 -3
  142. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +92 -5
  143. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +602 -0
  144. package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +209 -0
  145. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +126 -0
  146. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +312 -0
  147. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +555 -0
  148. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +47 -12
  149. package/skills/weaver-e10-jinchengda/references/contract-object-detect.md +469 -0
  150. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +154 -1
  151. package/skills/weaver-e10-jinchengda/references/contract-type-fingerprints.md +224 -0
  152. package/skills/weaver-e10-jinchengda/references/orchestration.md +355 -0
  153. package/skills/weaver-e10-jucailin/references/recruit-create.md +5 -3
  154. package/skills/weaver-e10-jucailin/references/recruit-write.md +2 -2
  155. package/skills/weaver-e10-meeting/SKILL.md +57 -9
  156. package/skills/weaver-e10-recruit-stage/SKILL.md +11 -6
  157. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +10 -2
  158. package/skills/weaver-e10-recruit-stage/references/position-templates.md +3 -1
  159. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +13 -1
  160. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +19 -18
  161. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +27 -14
  162. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +7 -1
  163. package/skills/weaver-e10-shared/references/e10-auth-and-session.md +4 -2
  164. package/skills/weaver-e10-wenshuding/SKILL.md +17 -7
  165. package/skills/weaver-e10-wenshuding/references/archive-borrow-list.md +28 -0
  166. package/skills/weaver-e10-wenshuding/references/archive-flow.md +24 -8
  167. package/skills/weaver-e10-wenshuding/references/archive-prelib-list.md +3 -0
  168. package/skills/weaver-e10-wenshuding/references/archive-prelib-open.md +4 -0
  169. package/skills/weaver-e10-wenshuding/references/archive-search.md +3 -1
  170. package/skills/weaver-e10-workflow/SKILL.md +19 -17
  171. package/skills/weaver-e10-workflow/aigroup/default.json +10 -6
  172. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +36 -3
  173. package/skills/weaver-e10-workflow/references/workflow-memory.md +1 -1
  174. package/skills/weaver-e10-workflow/references/workflow-query.md +9 -6
  175. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +152 -1
  176. package/skills/weaver-e10-yimiaoban/SKILL.md +17 -5
  177. package/skills/weaver-e10-yimiaoban/references/msg-write.md +30 -0
  178. package/skills/weaver-e10-yimiaoban/references/session-sysmsg.md +72 -0
  179. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +7 -7
@@ -0,0 +1,56 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { contractValidationError } from '../errors.js';
4
+ import { insertClausesIntoDocx } from '../ooxml/clause-insert.js';
5
+ import { requireNonEmptyString } from './shared.js';
6
+ const MAX_CLAUSES = 30;
7
+ function normalizeClauses(raw) {
8
+ if (!Array.isArray(raw) || raw.length === 0) {
9
+ throw contractValidationError('clauses_required', 'clauses 必须是非空数组,每项含 name 与 content');
10
+ }
11
+ if (raw.length > MAX_CLAUSES) {
12
+ throw contractValidationError('clauses_too_many', `一次最多插入 ${MAX_CLAUSES} 条条款`);
13
+ }
14
+ return raw.map((item, index) => {
15
+ const obj = (item ?? {});
16
+ const name = requireNonEmptyString(obj.name, `clauses[${index}].name`, 200).trim();
17
+ const content = requireNonEmptyString(obj.content, `clauses[${index}].content`, 20000).trim();
18
+ const anchor = typeof obj.anchor === 'string' && obj.anchor.trim() ? obj.anchor.trim() : undefined;
19
+ return { name, content, anchor };
20
+ });
21
+ }
22
+ export const contractClauseInsertOperations = [
23
+ {
24
+ name: 'contract.clause.insert',
25
+ async execute(input) {
26
+ const path = resolve(requireNonEmptyString(input.path, 'path', 4096).trim());
27
+ const clauses = normalizeClauses(input.clauses);
28
+ const dryRun = input.dryRun === true;
29
+ const out = input.out
30
+ ? resolve(String(input.out))
31
+ : path;
32
+ const { buffer, result } = insertClausesIntoDocx(path, clauses, out, dryRun);
33
+ if (!dryRun && buffer) {
34
+ writeFileSync(out, buffer);
35
+ }
36
+ const duplicates = result.outcomes.filter((o) => o.status === 'duplicate');
37
+ const notFound = result.outcomes.filter((o) => o.status === 'anchor_not_found');
38
+ return {
39
+ status: dryRun ? 'DRYRUN' : 'COMPLETE',
40
+ data: {
41
+ dryRun,
42
+ output: dryRun ? null : out,
43
+ chapters: result.chapters,
44
+ outcomes: result.outcomes,
45
+ insertedCount: result.insertedCount,
46
+ skippedCount: result.skippedCount,
47
+ duplicates: duplicates.map((o) => ({ name: o.name, reason: o.reason })),
48
+ anchorNotFound: notFound.map((o) => ({ name: o.name, reason: o.reason })),
49
+ note: dryRun
50
+ ? '仅做位置与去重分析,未写入文件;确认后再以 dryRun=false 执行'
51
+ : '条款已插入并覆盖写出;同名或实质相同条款已自动跳过',
52
+ },
53
+ };
54
+ },
55
+ },
56
+ ];
@@ -0,0 +1,192 @@
1
+ import { contractPolicyError, contractValidationError } from '../errors.js';
2
+ import { formCustomParam, loadFormContext } from './form-info.js';
3
+ import { requireId } from './shared.js';
4
+ /**
5
+ * 客户主数据查询(表单浏览按钮的补全接口)——**按客户全称查询**。
6
+ *
7
+ * 只接受全称:空关键词在这条接口上等价于"按顺序返回前若干条",会把任意不相干主体当成命中,
8
+ * 直接判错新老客户,所以空串一律拒绝(见 queryCustomers)。
9
+ *
10
+ * 为什么必须走这条接口而不是 `contract.subject.query`:
11
+ * 客户主数据的 objId / appId 是**环境值**(实测 appId 980180677416657173、ebObjId 1173221220888059964),
12
+ * 换租户就变;`getObjsByTag` 也查不到它(客户主数据挂在另一个应用下,不在「合同管理」应用的表单 Tag 里)。
13
+ * 而 browser/complete 由服务端从 **fieldId** 现场解析出对象,天然没有硬编码——这是它唯一正确的入口。
14
+ *
15
+ * 为什么必须带完整 customParam:`permissionType` 是客户字段的数据权限开关,其余键共同构成
16
+ * 授权上下文。少一个不会报错,只会**静默少返回条目**,把「新客户 / 老客户」判错。
17
+ * 因此这里直接复用 `formCustomParam`(与已验证可用的 getFormLayout 请求逐键一致),不自己裁剪。
18
+ */
19
+ const BROWSER_COMPLETE_PATH = '/api/ebuilder/form/common/browser/complete/ebuilder';
20
+ /** 字段名候选,按优先级排列;命中多个时不自动取第一条,交回调用方定。 */
21
+ const CUSTOMER_FIELD_NAME_HINTS = ['客户名称', '最终用户名称', '最终用户', '客户'];
22
+ /** 能挂客户主数据的浏览组件。`Ebuilder` 是建模对象浏览,`Customer` 是原生客户,`Browser` 是通用浏览。 */
23
+ const CUSTOMER_BROWSER_COMPONENTS = new Set(['ebuilder', 'customer', 'browser']);
24
+ const DEFAULT_PAGE_SIZE = 20;
25
+ function asArray(value) {
26
+ return Array.isArray(value) ? value.filter((item) => item && typeof item === 'object') : [];
27
+ }
28
+ function toCustomerField(field) {
29
+ return {
30
+ id: String(field.id),
31
+ name: String(field.name ?? ''),
32
+ componentKey: String(field.componentKey ?? ''),
33
+ isMultiple: Boolean(field.isMultiple),
34
+ };
35
+ }
36
+ /** 主表上、组件类型能承载客户主数据的浏览字段——只有这些才可能一点就出客户列表。 */
37
+ function customerBrowserFields(fields) {
38
+ return fields.filter((field) => !field.subFormId
39
+ && field.isBrowser
40
+ && CUSTOMER_BROWSER_COMPONENTS.has(String(field.componentKey ?? '').toLowerCase()));
41
+ }
42
+ /**
43
+ * 定位客户字段。
44
+ *
45
+ * 三种冲突都**不猜**:显式 fieldId 找不到、显式 fieldName 命中多个、按候选名命中多个——
46
+ * 一律抛 policy error 并把候选摊给调用方。客户名称/最终用户认错,后面新老客户全错。
47
+ */
48
+ function resolveCustomerField(fields, input) {
49
+ const explicitId = input.fieldId === undefined || input.fieldId === null || input.fieldId === ''
50
+ ? undefined
51
+ : requireId(input.fieldId, 'fieldId');
52
+ if (explicitId) {
53
+ const matched = fields.find((field) => String(field.id) === explicitId);
54
+ if (!matched) {
55
+ throw contractValidationError('field_not_found', `表单里没有 fieldId=${explicitId} 的字段`);
56
+ }
57
+ return toCustomerField(matched);
58
+ }
59
+ const eligible = customerBrowserFields(fields);
60
+ const explicitName = typeof input.fieldName === 'string' && input.fieldName.trim()
61
+ ? input.fieldName.trim()
62
+ : undefined;
63
+ if (explicitName) {
64
+ const matched = eligible.filter((field) => String(field.name ?? '').trim() === explicitName);
65
+ if (matched.length === 1)
66
+ return toCustomerField(matched[0]);
67
+ throw contractPolicyError(matched.length === 0 ? 'customer_field_not_found' : 'customer_field_ambiguous', matched.length === 0
68
+ ? `表单里没有名为「${explicitName}」的客户浏览字段,请从 candidates 里指定 fieldId`
69
+ : `名为「${explicitName}」的客户浏览字段有 ${matched.length} 个,请指定 fieldId`, { fieldName: explicitName, candidates: (matched.length ? matched : eligible).map(toCustomerField) });
70
+ }
71
+ for (const hint of CUSTOMER_FIELD_NAME_HINTS) {
72
+ const matched = eligible.filter((field) => String(field.name ?? '').trim() === hint);
73
+ if (matched.length === 1)
74
+ return toCustomerField(matched[0]);
75
+ if (matched.length > 1) {
76
+ throw contractPolicyError('customer_field_ambiguous', `按「${hint}」匹配到 ${matched.length} 个客户字段,无法判断哪一个承载最终用户,请指定 fieldId`, { hint, candidates: matched.map(toCustomerField) });
77
+ }
78
+ }
79
+ throw contractPolicyError('customer_field_not_found', `该流程表单里没有识别到客户浏览字段(候选名:${CUSTOMER_FIELD_NAME_HINTS.join(' / ')}),请用 fieldId 指定`, { hints: CUSTOMER_FIELD_NAME_HINTS, candidates: eligible.map(toCustomerField) });
80
+ }
81
+ /** 补全接口的返回体层级在不同版本上略有差异,按已知形状兜底取行。 */
82
+ function extractRows(value) {
83
+ const data = (value ?? {}).data;
84
+ if (Array.isArray(data))
85
+ return asArray(data);
86
+ if (data && typeof data === 'object') {
87
+ const root = data;
88
+ for (const key of ['data', 'list', 'rows', 'datas']) {
89
+ const rows = asArray(root[key]);
90
+ if (rows.length)
91
+ return rows;
92
+ if (Array.isArray(root[key]))
93
+ return rows;
94
+ }
95
+ }
96
+ return [];
97
+ }
98
+ function projectCustomer(row) {
99
+ return {
100
+ id: row.id === undefined ? undefined : String(row.id),
101
+ name: row.name ?? row.title ?? row.showName ?? undefined,
102
+ ebObjId: row.ebObjId === undefined ? (row.objId === undefined ? undefined : String(row.objId)) : String(row.ebObjId),
103
+ isLeaf: row.isLeaf,
104
+ disabled: row.disabled,
105
+ };
106
+ }
107
+ /**
108
+ * 组 customParam:直接复用 `formCustomParam`——与已验证可用的 getFormLayout 请求**逐键一致**。
109
+ * 签名取不到时**不伪造**,降级成最小集并把 permissionContext 标成 minimal 透给调用方。
110
+ */
111
+ function buildCustomParam(runtime, frame, workflowId) {
112
+ const authStr = String(runtime.auth_str ?? '');
113
+ const authSignatureStr = String(runtime.auth_signature ?? '');
114
+ const warnings = [];
115
+ if (!authStr || !authSignatureStr) {
116
+ const permissionType = frame.permission_type === undefined ? 1 : Number(frame.permission_type);
117
+ warnings.push('未取到 authStr/authSignature,已按最小权限上下文查询:返回条目可能少于页面可见数量,判定新老客户前请人工确认');
118
+ return { customParam: { permissionType }, permissionContext: 'minimal', warnings };
119
+ }
120
+ return {
121
+ customParam: formCustomParam(workflowId, runtime, frame),
122
+ permissionContext: 'full',
123
+ warnings,
124
+ };
125
+ }
126
+ async function queryCustomers(host, input) {
127
+ const workflowId = requireId(input.workflowId, 'workflowId');
128
+ // 只做全称查询:空串在这个接口上是"按顺序返回前若干条",不是模糊匹配,
129
+ // 拿它当"列出全部客户"用会把任意一个不相干主体当成命中,直接判错新老客户。所以一律拒绝。
130
+ const searchValue = typeof input.searchValue === 'string' ? input.searchValue.trim() : '';
131
+ if (!searchValue) {
132
+ throw contractValidationError('input_invalid', 'searchValue 必须是客户全称(不能为空):本操作只做全称查询,空关键词会返回无关的前若干条');
133
+ }
134
+ const pageSize = input.pageSize === undefined ? DEFAULT_PAGE_SIZE : Number(input.pageSize);
135
+ if (!Number.isInteger(pageSize) || pageSize < 1 || pageSize > 50) {
136
+ throw contractValidationError('input_invalid', 'pageSize 必须是 1~50 的整数');
137
+ }
138
+ const context = await loadFormContext(host, workflowId);
139
+ const field = resolveCustomerField(context.fields, input);
140
+ const layoutId = String((context.layout.formLayout ?? {}).id ?? '');
141
+ const { customParam, permissionContext, warnings } = buildCustomParam(context.runtime, context.frame, workflowId);
142
+ const value = await host.contractRequest({
143
+ method: 'POST',
144
+ path: BROWSER_COMPLETE_PATH,
145
+ body: {
146
+ browserMultiple: true,
147
+ newly: 0,
148
+ searchValue,
149
+ formParam: JSON.stringify({
150
+ formId: context.frame.form_id,
151
+ layoutId,
152
+ fieldId: field.id,
153
+ filterItems: [],
154
+ module: 'workflow',
155
+ dataDetails: [],
156
+ }),
157
+ openScroll: true,
158
+ controlId: field.id,
159
+ businessId: workflowId,
160
+ variableMap: {},
161
+ variableDataKeyMap: {},
162
+ customParam,
163
+ },
164
+ });
165
+ const rows = extractRows(value);
166
+ const customers = rows.slice(0, pageSize).map(projectCustomer);
167
+ return {
168
+ status: 'COMPLETE',
169
+ data: {
170
+ path: BROWSER_COMPLETE_PATH,
171
+ workflowId,
172
+ searchValue,
173
+ field,
174
+ customers,
175
+ total: rows.length,
176
+ truncated: rows.length > pageSize,
177
+ // 多命中不自动取第一条:品牌名常命中母/子公司多条,认错主体就等于认错新老客户
178
+ needsChoice: rows.length > 1,
179
+ permissionContext,
180
+ warnings,
181
+ },
182
+ };
183
+ }
184
+ export const contractCustomerBrowserOperation = {
185
+ name: 'contract.customer.browser',
186
+ async execute(input, context) {
187
+ return queryCustomers(context.host, input);
188
+ },
189
+ };
190
+ export const contractCustomerOperations = [
191
+ contractCustomerBrowserOperation,
192
+ ];
@@ -0,0 +1,75 @@
1
+ import { contractValidationError } from '../errors.js';
2
+ import { requireNonEmptyString } from './shared.js';
3
+ /** 与采知连附件下载保持一致的模块取值;合同模板走 ebContract。 */
4
+ const SUPPORTED_MODULES = ['ebContract', 'workflow', 'docCompared', 'ebuilderform'];
5
+ const DEFAULT_MODULE = 'ebContract';
6
+ const FILE_ID_PATTERN = /^[1-9]\d*$/u;
7
+ /**
8
+ * 构造 E10 文件下载路径。
9
+ *
10
+ * 沿用平台既有格式 `/api/file/remotedownload/{fileId}/auth/true?...`,
11
+ * 路径里出现两次 fileId(路径段 + 查询参数)是平台要求,不能只留一个。
12
+ */
13
+ function downloadPath(fileId, module) {
14
+ return {
15
+ path: `/api/file/remotedownload/${fileId}/auth/true`,
16
+ query: {
17
+ id: fileId,
18
+ autoSave: 'true',
19
+ create: 'false',
20
+ module,
21
+ enterprisePan: 'false',
22
+ publicFileHost: '',
23
+ tempFileType: '1',
24
+ batchCollaboration: 'false',
25
+ fileId,
26
+ notLoggedIn: 'false',
27
+ autoSelect: 'false',
28
+ coordinateFlag: 'false',
29
+ deepClean: 'false',
30
+ imgType: 'imgPlug',
31
+ mobile: 'false',
32
+ },
33
+ };
34
+ }
35
+ export const contractFileDownloadOperations = [
36
+ {
37
+ name: 'contract.file.download',
38
+ async execute(input, { host }) {
39
+ const fileId = requireNonEmptyString(input.fileId, 'fileId', 64).trim();
40
+ if (!FILE_ID_PATTERN.test(fileId)) {
41
+ throw contractValidationError('file_id_invalid', 'fileId 必须是正整数(E10 文件 ID)');
42
+ }
43
+ const rawModule = input.module === undefined || input.module === null || input.module === ''
44
+ ? DEFAULT_MODULE
45
+ : requireNonEmptyString(input.module, 'module', 32).trim();
46
+ if (!SUPPORTED_MODULES.includes(rawModule)) {
47
+ throw contractValidationError('module_unsupported', `module 只支持 ${SUPPORTED_MODULES.join(' / ')},收到:${rawModule}`);
48
+ }
49
+ const module = rawModule;
50
+ const savePath = requireNonEmptyString(input.savePath, 'savePath', 4096).trim();
51
+ if (typeof host.contractDownloadToFile !== 'function') {
52
+ throw contractValidationError('download_unsupported', '当前 CLI host 未实现二进制下载通道,无法下载文件');
53
+ }
54
+ const { path, query } = downloadPath(fileId, module);
55
+ const result = await host.contractDownloadToFile({
56
+ path,
57
+ query,
58
+ savePath,
59
+ ...(input.maxBytes === undefined ? {} : { maxBytes: Number(input.maxBytes) }),
60
+ });
61
+ return {
62
+ status: 'COMPLETE',
63
+ data: {
64
+ fileId,
65
+ module,
66
+ filePath: result.filePath,
67
+ fileName: result.filePath.split(/[\\/]/u).pop() ?? '',
68
+ fileSize: result.fileSize,
69
+ contentType: result.contentType,
70
+ note: '文件已下载到本地;二进制内容不进入大模型上下文,只回传路径与元数据',
71
+ },
72
+ };
73
+ },
74
+ },
75
+ ];
@@ -1,10 +1,17 @@
1
1
  import { contractValidationError } from '../errors.js';
2
2
  import { flowPageUrl } from './page.js';
3
+ import { loadFormContext, inspectUploadField, resolveUploadFieldId } from './form-info.js';
3
4
  import { requireNonEmptyString } from './shared.js';
4
5
  import { assertContractDocument, uploadFile } from './upload.js';
5
6
  /**
6
7
  * 四个合同流程的固定 workflowId / fieldId。
7
8
  * 这些是业务常量(不是环境 ID),但流程页面里的其他 ID 仍需运行时解析。
9
+ *
10
+ * 🔴 `fieldId` 只是**预设**,不是权威值(2026-11-03 O-3c 修正):
11
+ * 表单改版后字段 id 会漂移,而"挂错字段"不会报错、只会静默丢附件。
12
+ * 因此发起前一律由 `resolveUploadFieldId` 用实时布局校验:
13
+ * 预设命中 → 用预设;预设失效但布局里只有一个主表附件字段 → 用布局那个并回报来源;
14
+ * 多个 / 一个都没有 → 阻断(不替用户猜)。
8
15
  */
9
16
  export const FLOW_PRESETS = [
10
17
  { key: '契约锁', label: '契约锁合同审批流程', workflowId: '100003460000002066', fieldId: '100003720000025579' },
@@ -51,12 +58,45 @@ export const contractFlowOperations = [
51
58
  };
52
59
  },
53
60
  },
61
+ {
62
+ name: 'contract.flow.upload-field',
63
+ async execute(input, { host }) {
64
+ const flow = resolveFlow(input.flow);
65
+ const context = await loadFormContext(host, flow.workflowId);
66
+ const inspection = inspectUploadField(context.layout, flow.fieldId);
67
+ const advice = {
68
+ preset: '预设 fieldId 与实时布局一致,可直接发起',
69
+ layout: '预设 fieldId 在实时布局里不存在,已改用布局里唯一的附件字段;建议回写 FLOW_PRESETS',
70
+ ambiguous: '布局里有多个主表附件字段,真实发起会被阻断;需人工确认该用哪一个',
71
+ missing: '布局里没有主表附件字段(FileComponent),真实发起会被阻断',
72
+ };
73
+ return {
74
+ status: 'COMPLETE',
75
+ data: {
76
+ flow: flow.key,
77
+ flowLabel: flow.label,
78
+ workflowId: flow.workflowId,
79
+ formId: context.frame.form_id,
80
+ layoutId: String((context.layout.formLayout ?? {}).id ?? ''),
81
+ presetFieldId: flow.fieldId,
82
+ resolvedFieldId: inspection.fieldId,
83
+ state: inspection.state,
84
+ ready: inspection.fieldId !== null,
85
+ candidates: inspection.candidates,
86
+ advice: advice[inspection.state],
87
+ },
88
+ };
89
+ },
90
+ },
54
91
  {
55
92
  name: 'contract.flow.launch',
56
93
  async execute(input, { host }) {
57
94
  const flow = resolveFlow(input.flow);
58
95
  const path = requireNonEmptyString(input.path, 'path', 1000);
59
96
  assertContractDocument(path);
97
+ // 先解析上传字段(O-3c):宁可多三次只读请求,也不把合同挂到一个可能失效的 fieldId 上。
98
+ const formContext = await loadFormContext(host, flow.workflowId);
99
+ const uploadField = resolveUploadFieldId(formContext.layout, flow.fieldId, flow.label);
60
100
  const baseParam = await host.contractRequest({
61
101
  method: 'POST',
62
102
  path: '/api/workflow/core/flowPage/loadBaseParam',
@@ -73,7 +113,7 @@ export const contractFlowOperations = [
73
113
  extraFields: {
74
114
  authModule: 'workflow',
75
115
  source: 'form',
76
- fieldId: flow.fieldId,
116
+ fieldId: uploadField.fieldId,
77
117
  sourceRefId: requestId,
78
118
  refId: requestId,
79
119
  folderId: '300',
@@ -86,7 +126,9 @@ export const contractFlowOperations = [
86
126
  flow: flow.key,
87
127
  flowLabel: flow.label,
88
128
  workflowId: flow.workflowId,
89
- fieldId: flow.fieldId,
129
+ fieldId: uploadField.fieldId,
130
+ fieldIdPreset: flow.fieldId,
131
+ fieldIdSource: uploadField.state,
90
132
  requestId,
91
133
  file: uploaded,
92
134
  url: flowPageUrl(session.baseUrl, flow.workflowId, uploaded.fileId),