weaver-work-cli 0.1.54 → 0.1.57

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 (189) hide show
  1. package/dist/chunks/{archive-ZQ4A4TV6.js → archive-4SQAVTIB.js} +3 -2
  2. package/dist/chunks/{archive-oa-57R2FYHV.js → archive-oa-W2UEJ67L.js} +137 -8
  3. package/dist/chunks/{asset-ZOJVBWZH.js → asset-EGZEABBI.js} +3 -2
  4. package/dist/chunks/{asset-idle-XGB5IPGT.js → asset-idle-EBUZBB6M.js} +3 -2
  5. package/dist/chunks/{attachment-content-2EPEI4HV.js → attachment-content-QGM5MLQE.js} +4 -3
  6. package/dist/chunks/{blog-QSHLZSFW.js → blog-2YKMWOWI.js} +3 -2
  7. package/dist/chunks/{caizhilian-KCQYFH72.js → caizhilian-QJ4FLSQJ.js} +5 -4
  8. package/dist/chunks/{calendar-DLGMRJQA.js → calendar-H4QTJCUY.js} +3 -2
  9. package/dist/chunks/{chunk-XPQN4E5O.js → chunk-44KJ7WFA.js} +300 -55
  10. package/dist/chunks/{chunk-CZNZKOHR.js → chunk-4GG72JAT.js} +2 -2
  11. package/dist/chunks/{chunk-YIKSL36S.js → chunk-5N222HK6.js} +2 -2
  12. package/dist/chunks/{chunk-XHMJBRLZ.js → chunk-6DVL5IN5.js} +4 -1
  13. package/dist/chunks/{chunk-JJRIT2ZN.js → chunk-6MS3RLPO.js} +5 -334
  14. package/dist/chunks/{chunk-QUDHSMG3.js → chunk-7EBV7Q3R.js} +112 -27
  15. package/dist/chunks/{chunk-CNVZETM5.js → chunk-AHJZIMCX.js} +1 -1
  16. package/dist/chunks/{chunk-TGAGQV4I.js → chunk-CQ4OVCKG.js} +2 -2
  17. package/dist/chunks/{chunk-2BQESR2U.js → chunk-DVR2EDUU.js} +99 -34
  18. package/dist/chunks/{chunk-7KKI5KDY.js → chunk-FDAJC7R4.js} +4 -4
  19. package/dist/chunks/{chunk-GR76ZDDX.js → chunk-FMNCSYIG.js} +2 -2
  20. package/dist/chunks/{chunk-6LGLI46Q.js → chunk-L2LMBFG5.js} +1 -1
  21. package/dist/chunks/{chunk-DLY5GUXX.js → chunk-PH7N4UFT.js} +1 -1
  22. package/dist/chunks/{chunk-U6R6FZHD.js → chunk-SFM3M2L3.js} +286 -93
  23. package/dist/chunks/chunk-SHYQUBY3.js +48 -0
  24. package/dist/chunks/{chunk-HFXK54M4.js → chunk-TGM7BWEH.js} +2 -2
  25. package/dist/chunks/{chunk-Z7B7QSR2.js → chunk-TJUAGZU7.js} +11 -11
  26. package/dist/chunks/{chunk-LYOFRYC4.js → chunk-UI66EMOR.js} +4 -4
  27. package/dist/chunks/{chunk-762M5XJS.js → chunk-VMCCRWFO.js} +2 -2
  28. package/dist/chunks/{chunk-FE3CQAAM.js → chunk-WHJIUKJW.js} +681 -48
  29. package/dist/chunks/{chunk-PGO4ILMQ.js → chunk-WMB3SMXI.js} +1 -1
  30. package/dist/chunks/chunk-WMRNO6IU.js +337 -0
  31. package/dist/chunks/{chunk-6NXT4ICB.js → chunk-WVH5ESDA.js} +1 -1
  32. package/dist/chunks/{chunk-O6RIBG5E.js → chunk-XU3FL3AW.js} +4 -4
  33. package/dist/chunks/{chunk-Z6UUBY37.js → chunk-Z4IPY5GV.js} +2 -2
  34. package/dist/chunks/{conflict-K2IAKKFR.js → conflict-VAFFPUY3.js} +2 -2
  35. package/dist/chunks/{contract-LJRAXVZU.js → contract-LLRKMLQQ.js} +2655 -1319
  36. package/dist/chunks/{cowork-3ACICHDQ.js → cowork-2RDFBZWB.js} +3 -2
  37. package/dist/chunks/{create-flow-UL37MZGP.js → create-flow-TVYE3IOH.js} +6 -6
  38. package/dist/chunks/{data-WK5CQXNF.js → data-WVICO3DT.js} +57 -11
  39. package/dist/chunks/{ebuilder-form-CBYI6CQ6.js → ebuilder-form-TWSXS5NA.js} +7 -6
  40. package/dist/chunks/{ehr-XI4BIVR2.js → ehr-52GBKNJR.js} +3 -2
  41. package/dist/chunks/{env-BZDB5OVZ.js → env-BVVFIN4P.js} +2 -2
  42. package/dist/chunks/{esb-4BQHNP5C.js → esb-HJSXCEOM.js} +5 -4
  43. package/dist/chunks/{factory-VD3YI6N7.js → factory-RCQ36LLE.js} +1 -1
  44. package/dist/chunks/{fna-ECOYBQYL.js → fna-OBACRT3J.js} +72 -3
  45. package/dist/chunks/{group-chat-DHNVO76L.js → group-chat-YFZDUUY3.js} +3 -3
  46. package/dist/chunks/{host-TUOIOEMC.js → host-2BKMPWDH.js} +4 -3
  47. package/dist/chunks/{host-3TNBMDTR.js → host-KJT3G5D2.js} +4 -3
  48. package/dist/chunks/{host-7OWWPLM4.js → host-KOWUMNAY.js} +4 -3
  49. package/dist/chunks/{host-M4XP5URR.js → host-MFXRA2MY.js} +4 -3
  50. package/dist/chunks/{host-7NTIBSPK.js → host-TTSGY5NZ.js} +4 -3
  51. package/dist/chunks/{host-G3VU7SDW.js → host-W4JCNRFS.js} +4 -3
  52. package/dist/chunks/{hrm-YGIR3HGF.js → hrm-AK3WGBMN.js} +4 -3
  53. package/dist/chunks/{im-TN2JYVGJ.js → im-JZSBPO4Z.js} +4 -3
  54. package/dist/chunks/{invoice-V7ZTITUO.js → invoice-7JGSEWT5.js} +22 -9
  55. package/dist/chunks/{jiuchuanhui-ASFZBMPU.js → jiuchuanhui-K4EQU6GK.js} +3 -2
  56. package/dist/chunks/{lazy-dispatch-XSAHDK6Z.js → lazy-dispatch-JHGFCKJN.js} +5 -4
  57. package/dist/chunks/{mail-M3HJF5ER.js → mail-IKVCQCVZ.js} +3 -2
  58. package/dist/chunks/{meeting-OWG4O2XH.js → meeting-JOHV4RH3.js} +14 -12
  59. package/dist/chunks/minute-doc-JLS4KMFZ.js +156 -0
  60. package/dist/chunks/{okr-EVX7FB5G.js → okr-KV43FPPX.js} +3 -2
  61. package/dist/chunks/{operations-J7PUIVWZ.js → operations-ZPWBMYKE.js} +5 -4
  62. package/dist/chunks/{plan-2QJQEPBO.js → plan-WOYR4WEG.js} +3 -2
  63. package/dist/chunks/{project-XELELW2T.js → project-CQJKBUIL.js} +3 -2
  64. package/dist/chunks/{reception-QGPNTGHG.js → reception-MPBU3JXC.js} +3 -2
  65. package/dist/chunks/{recruit-stage-XCMVEQA2.js → recruit-stage-USTTRHOX.js} +3 -2
  66. package/dist/chunks/{registry-CJOVECZD.js → registry-GURQG4ZV.js} +3 -2
  67. package/dist/chunks/{registry-ASYCWF2U.js → registry-LITYOH2W.js} +12 -10
  68. package/dist/chunks/{registry-QJCZ2GVG.js → registry-SS5J2FZQ.js} +5 -4
  69. package/dist/chunks/{room-recommend-LSVAMGKV.js → room-recommend-62MECG4J.js} +4 -4
  70. package/dist/chunks/{schedule-7QOPRUU4.js → schedule-6QRXIBGU.js} +4 -4
  71. package/dist/chunks/{smart-extract-FOUYNIG3.js → smart-extract-APX2PNIN.js} +3 -2
  72. package/dist/chunks/{workflow-YHXFIU63.js → workflow-WMPW3WSB.js} +5 -4
  73. package/dist/index.js +33 -32
  74. package/dist/internal/e10/auth/agent-host-key.js +68 -0
  75. package/dist/internal/e10/auth/agent-hosts.js +250 -0
  76. package/dist/internal/e10/auth/commands.js +99 -30
  77. package/dist/internal/e10/auth/paths.js +9 -0
  78. package/dist/internal/e10/auth/session.js +17 -0
  79. package/dist/internal/e10/auth/xiaoe.js +37 -3
  80. package/dist/shortcuts/archive-oa/operations/contract-modules.js +106 -0
  81. package/dist/shortcuts/archive-oa/operations/contract.js +38 -4
  82. package/dist/shortcuts/archive-oa/operations/registry.js +2 -1
  83. package/dist/shortcuts/contract/index.js +6 -7
  84. package/dist/shortcuts/contract/manifest.js +101 -24
  85. package/dist/shortcuts/contract/ooxml/docx-table.js +75 -3
  86. package/dist/shortcuts/contract/ooxml/xlsx.js +49 -13
  87. package/dist/shortcuts/contract/operations/card-action.js +113 -12
  88. package/dist/shortcuts/contract/operations/card-ebdf-list.js +29 -7
  89. package/dist/shortcuts/contract/operations/card-plan.js +75 -9
  90. package/dist/shortcuts/contract/operations/card-risk-report.js +2 -2
  91. package/dist/shortcuts/contract/operations/card.js +1 -1
  92. package/dist/shortcuts/contract/operations/clause-library.js +88 -16
  93. package/dist/shortcuts/contract/operations/compare-screen.js +378 -0
  94. package/dist/shortcuts/contract/operations/compare.js +1 -1
  95. package/dist/shortcuts/contract/operations/credit-page.js +1 -1
  96. package/dist/shortcuts/contract/operations/docx-slots.js +1000 -0
  97. package/dist/shortcuts/contract/operations/flow.js +2 -2
  98. package/dist/shortcuts/contract/operations/quote-to-contract.js +495 -0
  99. package/dist/shortcuts/contract/operations/quote.js +2 -229
  100. package/dist/shortcuts/contract/operations/recommend.js +1 -1
  101. package/dist/shortcuts/contract/operations/registry.js +6 -2
  102. package/dist/shortcuts/contract/operations/review.js +230 -4
  103. package/dist/shortcuts/contract/operations/save-recognize.js +122 -3
  104. package/dist/shortcuts/contract/operations/template.js +11 -10
  105. package/dist/shortcuts/data/operations/ds.js +5 -5
  106. package/dist/shortcuts/data/operations/shared.js +76 -4
  107. package/dist/shortcuts/fna/manifest.js +7 -2
  108. package/dist/shortcuts/fna/operations/budget.js +68 -0
  109. package/dist/shortcuts/invoice/manifest.js +8 -3
  110. package/dist/shortcuts/invoice/operations/reim.js +10 -3
  111. package/dist/shortcuts/meeting/minute-doc.js +153 -0
  112. package/dist/shortcuts/meeting/operations/compose-outcome.js +176 -0
  113. package/dist/shortcuts/meeting/operations/eb/catalog.js +1 -1
  114. package/dist/shortcuts/meeting/operations/eb/create-flow.js +26 -0
  115. package/dist/shortcuts/meeting/operations/eb/decision-task-batch.js +144 -0
  116. package/dist/shortcuts/meeting/operations/eb/decision.js +92 -4
  117. package/dist/shortcuts/meeting/operations/eb/index.js +133 -4
  118. package/dist/shortcuts/meeting/operations/eb/meeting-link.js +90 -0
  119. package/dist/shortcuts/meeting/operations/from-group-chat.js +46 -0
  120. package/dist/shortcuts/meeting/operations/minute-content.js +61 -0
  121. package/dist/shortcuts/meeting/operations/registry.js +14 -1
  122. package/dist/shortcuts/meeting/operations/self-check.js +49 -0
  123. package/dist/shortcuts/workflow/endpoints.js +2 -0
  124. package/dist/shortcuts/workflow/operations/read.js +114 -8
  125. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +72 -46
  126. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +41 -0
  127. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +46 -11
  128. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +18 -1
  129. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroupAdd.js +51 -0
  130. package/docs/e10-auth.md +78 -0
  131. package/docs/fna.md +8 -3
  132. package/docs/invoice.md +1 -1
  133. package/package.json +4 -2
  134. package/scripts/pack-offline.mjs +228 -0
  135. package/scripts/package-skill.mjs +14 -5
  136. package/skill-template/business-info.json +3 -0
  137. package/skill-template/domains/qiyecheng.md +4 -3
  138. package/skills/weaver-e10-archive-oa/SKILL.md +6 -1
  139. package/skills/weaver-e10-archive-oa/references/contract-search.md +91 -4
  140. package/skills/weaver-e10-jinchengda/SKILL.md +100 -81
  141. package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +11 -6
  142. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -4
  143. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +38 -12
  144. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +1 -1
  145. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  146. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +20 -6
  147. package/skills/weaver-e10-jinchengda/references/contract-card-render-internals.md +8 -3
  148. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +56 -13
  149. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +7 -0
  150. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +4 -4
  151. package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +11 -5
  152. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
  153. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
  154. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +38 -7
  155. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +13 -25
  156. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +9 -8
  157. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +8 -6
  158. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +10 -7
  159. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +2 -2
  160. package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +3 -1
  161. package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +26 -18
  162. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +4 -4
  163. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +18 -13
  164. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +5 -3
  165. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +105 -49
  166. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
  167. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +3 -6
  168. package/skills/weaver-e10-meeting/SKILL.md +47 -9
  169. package/skills/weaver-e10-qiyecheng/SKILL.md +16 -7
  170. package/skills/weaver-e10-qiyecheng/references/budget.md +77 -3
  171. package/skills/weaver-e10-qiyecheng/references/catalog.md +6 -4
  172. package/skills/weaver-e10-qiyecheng/references/getEnabledTemplate-api.md +255 -0
  173. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +70 -25
  174. package/skills/weaver-e10-workflow/SKILL.md +54 -40
  175. package/skills/weaver-e10-workflow/references/todo-dialogue.md +134 -0
  176. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +102 -80
  177. package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +23 -13
  178. package/skills/weaver-e10-workflow/references/workflow-query.md +68 -46
  179. package/skills/weaver-e10-workflow/references/workflow-view.md +21 -13
  180. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +317 -332
  181. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +1 -0
  182. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +23 -13
  183. package/skills/weaver-e10-yepiaotong.zip +0 -0
  184. package/dist/shortcuts/contract/ooxml/docx.js +0 -295
  185. package/dist/shortcuts/contract/operations/docx-fillfromquote.js +0 -532
  186. package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +0 -178
  187. package/skills/weaver-e10-jinchengda/references/source-manifest.json +0 -1270
  188. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +0 -998
  189. package/skills/weaver-e10-workflow/tools/todo-serve.cjs +0 -327
@@ -6,6 +6,7 @@ import { isConnectorMode } from '../../../core/connector.js';
6
6
  import { writeWithRetry } from '../../../core/write-with-retry.js';
7
7
  import { createTimeoutSignal } from '../network-error.js';
8
8
  import { encryptAuthData, parseAuthFile } from './crypto.js';
9
+ import { lookupAgentHost } from './agent-hosts.js';
9
10
  import { getE10ActiveProfilePath, getE10ProfilesRoot } from './paths.js';
10
11
  /**
11
12
  * teamsCheck 与会话探测都是「发业务请求之前的必经往返」,没有上限时一个半开
@@ -169,6 +170,17 @@ export function clearProfileAuthFile(profile = getActiveProfile()) {
169
170
  unlinkSync(authFile);
170
171
  return { profile, authFile, cleared: true };
171
172
  }
173
+ /**
174
+ * 当前宿主应使用的 profile 名。
175
+ *
176
+ * 有宿主记录且记录可用时优先用它;记录缺失(旧数据 / 无宿主标识)时才回到全局
177
+ * `profile` 指针。记录存在但不可用(profile 被删、凭据被清、域名对不上)时
178
+ * **仍然返回该 profile**,让上层按「未登录」处理,而不是静默借用别人的凭据。
179
+ */
180
+ export function resolveActiveProfileForHost(env = process.env) {
181
+ const host = lookupAgentHost(env);
182
+ return host ? host.profile : getActiveProfile();
183
+ }
172
184
  export function findAuthFile(startDir = process.cwd(), options = {}) {
173
185
  if (options.auth)
174
186
  return options.auth;
@@ -180,6 +192,11 @@ export function findAuthFile(startDir = process.cwd(), options = {}) {
180
192
  const envAuth = process.env.E10_AUTH_PATH;
181
193
  if (envAuth && existsSync(envAuth))
182
194
  return envAuth;
195
+ // 宿主记录优先于全局指针:WorkBuddy 与智能小 E 各自认自己的那次登录。
196
+ // 记录存在但不可用时返回 null(视为未登录),不回落——回落等于跨宿主串用凭据。
197
+ const host = lookupAgentHost();
198
+ if (host)
199
+ return host.status === 'ok' ? host.authFile : null;
183
200
  const activeProfileAuth = getProfileAuthPath(getActiveProfile());
184
201
  if (existsSync(activeProfileAuth))
185
202
  return activeProfileAuth;
@@ -7,6 +7,17 @@ import { packagePath } from '../../../core/package-paths.js';
7
7
  import { isXiaoERuntime, isXiaoERuntimeAgent } from '../../../core/runtime-agent.js';
8
8
  import { createTimeoutSignal, isAbortError, isNetworkErrorCode, looksLikeTransportMessage, readErrorCauseCode, } from '../network-error.js';
9
9
  import { buildE10CookieHeader, E10_TEAMS_CHECK_TIMEOUT_MS, E10AuthSession, extractRawSetCookie, extractSessionTicket, profileNameFromUrl, readTeamsCheckUserInfo, saveAuthFile, saveProfileConfig, setActiveProfile, } from './session.js';
10
+ import { resolveLoginProfileName, upsertAgentHost } from './agent-hosts.js';
11
+ /**
12
+ * 通用登录(非 XiaoE 宿主)默认使用的 E10 域名。
13
+ * 登录、ETEAMSID 落盘与会话恢复在调用方没有显式指定域名时都走这里。
14
+ */
15
+ export const DEFAULT_E10_LOGIN_BASE_URL = 'https://weapp.eteams.cn';
16
+ /**
17
+ * XiaoE 宿主(网页端 `cloud` / 桌面客户端 `client`)在环境上下文里拿不到
18
+ * E10 目标域时的最终回退。这两类环境的默认域一直由宿主注入的
19
+ * `XIAOE_*` / `WEAVER_XIAOE_*` 变量决定,回退值保持既有行为不变。
20
+ */
10
21
  export const DEFAULT_E10_BASE_URL = 'https://www.e-cology.com.cn';
11
22
  export const XIAOE_AGENT_TYPE = 'XiaoE';
12
23
  // `XIAOE_` 是宿主/平台保留前缀(XIAOE_DOMAIN、XIAOE_USER_TOKEN、XIAOE_SKILL_* 等)。
@@ -483,11 +494,27 @@ function resolveXiaoEConfiguredBaseUrl(env) {
483
494
  return normalizeUrl(firstCredential.baseUrl);
484
495
  return '';
485
496
  }
497
+ /**
498
+ * 是否处于 XiaoE 宿主环境。网页端(`XIAOE_CLIENT_TYPE=cloud`)与桌面客户端
499
+ * (`client`)的默认域名一直取自环境上下文,因此不能用通用登录默认域名顶掉。
500
+ */
501
+ export function isXiaoEHostedEnvironment(env = process.env) {
502
+ return resolveXiaoEClientType(env) !== undefined
503
+ || hasXiaoEPlatformCredential(env)
504
+ || hasXiaoEEnv(env);
505
+ }
506
+ /**
507
+ * 没有显式域名、profile 配置或宿主注入时使用的默认 E10 域名:
508
+ * XiaoE 宿主保持既有回退,其他环境使用 `DEFAULT_E10_LOGIN_BASE_URL`。
509
+ */
510
+ export function resolveDefaultE10BaseUrl(env = process.env) {
511
+ return isXiaoEHostedEnvironment(env) ? DEFAULT_E10_BASE_URL : DEFAULT_E10_LOGIN_BASE_URL;
512
+ }
486
513
  export function resolveXiaoEDefaultBaseUrl(env = process.env) {
487
514
  const configured = resolveXiaoEConfiguredBaseUrl(env);
488
515
  if (configured)
489
516
  return configured;
490
- return DEFAULT_E10_BASE_URL;
517
+ return resolveDefaultE10BaseUrl(env);
491
518
  }
492
519
  function uniqueStrings(values) {
493
520
  const seen = new Set();
@@ -1132,7 +1159,7 @@ export function resolveXiaoEPreferredBaseUrl(options) {
1132
1159
  const profileBaseUrl = normalizeUrl(options.profileBaseUrl || '');
1133
1160
  if (profileBaseUrl)
1134
1161
  return profileBaseUrl;
1135
- return DEFAULT_E10_BASE_URL;
1162
+ return resolveDefaultE10BaseUrl(env);
1136
1163
  }
1137
1164
  export function createXiaoEUnifiedLoginUnavailableError(baseUrl = '') {
1138
1165
  const target = normalizeUrl(baseUrl);
@@ -1208,7 +1235,12 @@ async function saveXiaoEUnifiedLogin(input) {
1208
1235
  });
1209
1236
  }
1210
1237
  const tenantKey = userInfo.tenantKey || input.tenantKeyFallback || '';
1211
- const profile = input.profileHint || profileNameFromUrl(baseUrl);
1238
+ const profile = resolveLoginProfileName({
1239
+ derivedName: profileNameFromUrl(baseUrl),
1240
+ baseUrl,
1241
+ hostKey: input.hostKey,
1242
+ profileHint: input.profileHint,
1243
+ });
1212
1244
  setActiveProfile(profile);
1213
1245
  const cookies = { ETEAMSID: input.eteamsId };
1214
1246
  if (input.rawCookie)
@@ -1236,6 +1268,7 @@ async function saveXiaoEUnifiedLogin(input) {
1236
1268
  };
1237
1269
  const authFile = saveAuthFile(authData, profile);
1238
1270
  saveProfileConfig(baseUrl, baseUrl, profile, tenantKey);
1271
+ upsertAgentHost({ profile, baseUrl, tenantKey, agentType: XIAOE_AGENT_TYPE, hostKey: input.hostKey });
1239
1272
  const session = new E10AuthSession(authData, authFile);
1240
1273
  return {
1241
1274
  session,
@@ -1397,6 +1430,7 @@ export async function tryXiaoEUnifiedLogin(options = {}) {
1397
1430
  tenantKeyFallback: options.tenantKeyFallback,
1398
1431
  profileHint: options.profileHint,
1399
1432
  credentialSource: describeXiaoECredentialSource(credential.source),
1433
+ hostKey: options.hostKey,
1400
1434
  });
1401
1435
  noteXiaoEStep(diagnostics, 'e10_session:ok');
1402
1436
  if (diagnostics) {
@@ -55,3 +55,109 @@ export const contractModuleOptionsOperation = {
55
55
  });
56
56
  },
57
57
  };
58
+ /** 所属行业(`ssxynew`)浏览按钮:国民经济行业分类树。 */
59
+ const INDUSTRY_BROWSER_PATH = '/api/bcw/common/browser/complete/customBrowser_industrybrowser';
60
+ /** 合同表单里所属行业控件的 controlId(浏览按钮搜索时必带)。 */
61
+ const INDUSTRY_CONTROL_ID = '-1904370529';
62
+ /** 浏览按钮返回的是树,展平成「节点 + 完整路径」列表,便于直接取 dataId 组条件。 */
63
+ function flattenIndustryTree(nodes, parentPath = '', depth = 0) {
64
+ if (!Array.isArray(nodes))
65
+ return [];
66
+ const out = [];
67
+ for (const raw of nodes) {
68
+ if (!raw || typeof raw !== 'object')
69
+ continue;
70
+ const node = raw;
71
+ const name = String(node.content ?? '');
72
+ const id = String(node.dataId ?? node.id ?? '');
73
+ if (id.length === 0)
74
+ continue;
75
+ const path = parentPath ? `${parentPath}/${name}` : name;
76
+ out.push({
77
+ id,
78
+ name,
79
+ path,
80
+ level: Number(node.level ?? depth + 1),
81
+ leaf: node.isLeaf === true || !Array.isArray(node.children) || node.children.length === 0,
82
+ });
83
+ if (Array.isArray(node.children) && node.children.length > 0) {
84
+ out.push(...flattenIndustryTree(node.children, path, depth + 1));
85
+ }
86
+ }
87
+ return out;
88
+ }
89
+ /**
90
+ * 带关键字搜索时,接口把结果按**森林**返回:命中的门类/大类是一棵树,
91
+ * 命中的子节点又会各自再作为一个根返回一遍,于是同一个 `dataId` 会出现多条(路径长短不同)。
92
+ * 这里按 `dataId` 去重,保留路径最长的那份(即从最顶层命中根算下来的完整路径),
93
+ * 保证候选列表里一个行业只出现一次、路径可直接用于 `wholePathName`。
94
+ */
95
+ function dedupeIndustryNodes(list) {
96
+ const byId = new Map();
97
+ for (const item of list) {
98
+ const prev = byId.get(item.id);
99
+ if (!prev || item.path.length > prev.path.length)
100
+ byId.set(item.id, item);
101
+ }
102
+ return [...byId.values()];
103
+ }
104
+ export const contractIndustryOptionsOperation = {
105
+ name: 'archive-oa.contract.industry-options',
106
+ resource: 'contract',
107
+ method: 'industry-options',
108
+ action: 'archive-oa.contract.industry-options',
109
+ summary: '查询所属行业(ssxynew):默认拉全量行业树,按关键字本地过滤后返回命中节点及其全部下级节点,可直接用于 in 条件',
110
+ capability: 'contract',
111
+ risk: READ,
112
+ inputSchema: schemaOf({
113
+ keyword: { type: 'string', description: '关键字,如「采矿」「金融」;缺省返回整棵树(不分页展示时慎用)' },
114
+ pageSize: { type: 'integer', minimum: 1, maximum: 200, description: 'options 返回条数,缺省 50' },
115
+ }, { description: '查询所属行业树节点(含全部下级行业)' }),
116
+ handler: async (args, env) => {
117
+ const keyword = typeof args.keyword === 'string' ? args.keyword.trim() : '';
118
+ const pageSize = positiveInt(args.pageSize, 'pageSize', 50);
119
+ if (pageSize > 200) {
120
+ throw archiveOaValidationError('number_invalid', 'pageSize 最多 200');
121
+ }
122
+ const response = await env.host.request({
123
+ method: 'POST',
124
+ path: INDUSTRY_BROWSER_PATH,
125
+ operation: 'archive-oa.contract.industry-options',
126
+ body: {
127
+ browserMultiple: true,
128
+ fromSearch: '1',
129
+ controlId: INDUSTRY_CONTROL_ID,
130
+ formParam: JSON.stringify({ filterItems: [], module: 'ebuilderform', dataDetails: [] }),
131
+ notFromLayout: true,
132
+ /**
133
+ * 固定按「首次加载」形态拉**全量**行业树(`newly:1` + 空 `searchValue`),
134
+ * 关键字在本地过滤:服务端按 searchValue 过滤时会按命中节点返回森林,
135
+ * 同一行业出现多条、且子节点缺上级路径前缀,不如全量树干净。
136
+ */
137
+ newly: 1,
138
+ searchValue: '',
139
+ },
140
+ });
141
+ const data = unwrapData(response);
142
+ const tree = data?.data;
143
+ const all = dedupeIndustryNodes(flattenIndustryTree(tree));
144
+ const matched = keyword
145
+ ? all.filter((item) => item.name.includes(keyword) || item.path.includes(keyword))
146
+ : all;
147
+ /** 子树规模:选中非末级节点时,调用方需要连子孙一起传给 `ssxynew`,这里先给出规模提示。 */
148
+ const options = matched.slice(0, pageSize).map((item) => ({
149
+ ...item,
150
+ subtreeCount: all.filter((other) => other.id === item.id || other.path.startsWith(`${item.path}/`)).length,
151
+ }));
152
+ /** `nodes` = 命中节点 + 它们的全部下级节点,调用方可原样映射成 `ssxynew` 的节点对象数组。 */
153
+ const nodes = all.filter((item) => matched.some((hit) => item.id === hit.id || item.path.startsWith(`${hit.path}/`)));
154
+ return archiveOaSuccess('archive-oa.contract.industry-options', {
155
+ keyword,
156
+ treeTotal: all.length,
157
+ total: matched.length,
158
+ descendantTotal: nodes.length,
159
+ options,
160
+ nodes,
161
+ });
162
+ },
163
+ };
@@ -1,6 +1,7 @@
1
1
  import { QYS_CONTRACT, QYS_DEFAULT_ARCHIVED_FIELD, QYS_DEFAULT_ARCHIVED_VALUE, WEAVER_CONTRACT, } from '../constants.js';
2
2
  import { READ, archiveOaSuccess, schemaOf, SCHEMA_PAGE_NO, SCHEMA_SEARCH_FIELDS, } from './types.js';
3
3
  import { assertEnum, buildCommonSearchFields, normalizeListResult, positiveInt, unwrapData } from './shared.js';
4
+ import { archiveOaValidationError } from '../errors.js';
4
5
  const CONTRACT_LIST_PATH = '/api/ebuilder/form/list/getListDatas';
5
6
  function filterPath(profile) {
6
7
  return `/api/ebuilder/form/listFilter/showFilters/${profile.listId}`;
@@ -44,11 +45,16 @@ function makeFieldsOperation(profile) {
44
45
  resource: 'contract',
45
46
  method: 'fields',
46
47
  action: name,
47
- summary: `查询${profile.source === 'qys' ? '契约锁' : '泛微'}商务合同可搜索字段配置(构造 commonSearchFields 用)`,
48
+ summary: `查询${profile.source === 'qys' ? '契约锁' : '泛微'}商务合同可搜索字段配置(含下拉字段的可选值,构造 commonSearchFields 用)`,
48
49
  capability: 'contract-search',
49
50
  risk: READ,
50
- inputSchema: schemaOf({}, { description: '查询合同搜索字段配置,无需入参' }),
51
- handler: async (_args, env) => {
51
+ inputSchema: schemaOf({
52
+ field: {
53
+ type: 'string',
54
+ description: '只看某个字段(如 khxznew),用于取该下拉字段的可选值;缺省返回全部字段',
55
+ },
56
+ }, { description: '查询合同搜索字段配置,无需必填入参' }),
57
+ handler: async (args, env) => {
52
58
  const response = await env.host.request({
53
59
  method: 'GET',
54
60
  path: searchFieldsPath(profile),
@@ -59,19 +65,47 @@ function makeFieldsOperation(profile) {
59
65
  /** getListSearch 把字段放在 `layout`(二维:分组 → 字段项),每项含 id / label / groupId。 */
60
66
  const layout = Array.isArray(data.layout) ? data.layout : [];
61
67
  const groups = Array.isArray(data.groups) ? data.groups : [];
68
+ /** 字段的控件形态与下拉候选值放在 `items[<字段>]`,`layout` 里只有展示信息。 */
69
+ const items = (data.items ?? {});
62
70
  const groupTitle = new Map(groups.map((group) => [String(group.id), String(group.title ?? '')]));
63
71
  const fields = layout.flat().map((item) => {
64
72
  const id = String(item?.id ?? '');
65
73
  const groupId = String(item?.groupId ?? '');
74
+ const config = (items[id] ?? {});
75
+ const itemType = typeof config.itemType === 'string' ? config.itemType : '';
76
+ /** SELECT 字段的 options 就是搜索面板里能勾的值(id 用于 commonSearchFields,content 是显示名)。 */
77
+ const options = Array.isArray(config.options)
78
+ ? config.options
79
+ .map((option) => ({
80
+ id: String(option?.id ?? ''),
81
+ name: String(option?.content ?? ''),
82
+ }))
83
+ .filter((option) => option.id.length > 0 && option.name.length > 0)
84
+ : [];
66
85
  return {
67
86
  fieldName: id,
68
87
  showName: String(item?.label ?? ''),
69
88
  groupId,
70
89
  groupName: groupTitle.get(groupId) ?? '',
71
90
  hidden: item?.hide === true,
91
+ ...(itemType ? { itemType } : {}),
92
+ ...(config.multiple === true ? { multiple: true } : {}),
93
+ ...(options.length > 0 ? { options } : {}),
72
94
  };
73
95
  }).filter((item) => item.fieldName.length > 0);
74
- return archiveOaSuccess(name, { fields }, { source: profile.source, listId: profile.listId, count: fields.length });
96
+ const wanted = typeof args.field === 'string' ? args.field.trim() : '';
97
+ const picked = wanted
98
+ ? fields.filter((item) => item.fieldName === wanted)
99
+ : fields;
100
+ if (wanted && picked.length === 0) {
101
+ throw archiveOaValidationError('field_unknown', `字段 ${wanted} 不在${profile.source === 'qys' ? '契约锁' : '泛微'}商务合同的搜索字段中`);
102
+ }
103
+ return archiveOaSuccess(name, { fields: picked }, {
104
+ source: profile.source,
105
+ listId: profile.listId,
106
+ count: picked.length,
107
+ ...(wanted ? { field: wanted } : {}),
108
+ });
75
109
  },
76
110
  };
77
111
  }
@@ -4,7 +4,7 @@ import { createBorrowCarOperations } from './borrow-car.js';
4
4
  import { createBorrowStartUrlOperation } from './borrow-url.js';
5
5
  import { qysContractFieldsOperation, qysContractListOperation, weaverContractFieldsOperation, weaverContractListOperation, } from './contract.js';
6
6
  import { archiveLocateOperation } from './locate.js';
7
- import { contractModuleOptionsOperation } from './contract-modules.js';
7
+ import { contractIndustryOptionsOperation, contractModuleOptionsOperation } from './contract-modules.js';
8
8
  import { myBorrowListOperation } from './my-borrow-contract.js';
9
9
  function buildRegistry() {
10
10
  const registry = new Map();
@@ -12,6 +12,7 @@ function buildRegistry() {
12
12
  archiveLocateOperation,
13
13
  myBorrowListOperation,
14
14
  contractModuleOptionsOperation,
15
+ contractIndustryOptionsOperation,
15
16
  weaverContractFieldsOperation,
16
17
  qysContractFieldsOperation,
17
18
  weaverContractListOperation,
@@ -362,6 +362,12 @@ export const contractShortcut = {
362
362
  { flag: '--file-id <id>', description: 'contract file id', key: 'fileId' },
363
363
  { flag: '--sclx <types>', description: '8 risk review (contract pre-review); 1/2/3 disabled', key: 'sclx' },
364
364
  ]);
365
+ // 一条命令出审查摘要:省掉「导出 → 解析 scnr → 手工压缩」的多轮往返(2026-11-16 新增)。
366
+ registerCommand(review, 'digest', 'Export AI review records and return a compact digest in one shot', 'contract.review.digest', [
367
+ { flag: '--file-id <id>', description: 'contract file id', key: 'fileId' },
368
+ { flag: '--ref <path>', description: 'digest from a persisted export result json instead of calling the api', key: 'ref' },
369
+ { flag: '--out <path>', description: 'optional: write digest json to this path', key: 'out' },
370
+ ]);
365
371
  const flow = contract.command('flow').description('Contract flow entry commands');
366
372
  registerCommand(flow, 'save-recognize-record', 'Save extracted form elements as a recognize record and return aiExtraId', 'contract.flow.save-recognize-record', [
367
373
  { flag: '--flow <name>', description: 'optional flow preset: 契约锁 / 新客户 / 老客户增值 / 常规二次销售' },
@@ -495,13 +501,6 @@ export const contractShortcut = {
495
501
  registerCommand(quote, 'normalize', 'Validate and normalize model-produced quote JSON', 'contract.quote.normalize', [
496
502
  { flag: '--data <file>', description: 'model JSON path', key: 'data' },
497
503
  ]);
498
- registerCommand(quote, 'fill', 'Fill a real .docx contract template with data JSON', 'contract.quote.fill', [
499
- { flag: '--template <file>', description: 'real contract template docx', key: 'template' },
500
- { flag: '--data <file>', description: 'data JSON path', key: 'data' },
501
- { flag: '--out <file>', description: 'output docx path', key: 'out' },
502
- { flag: '--detail <mode>', description: 'append|none', key: 'detail' },
503
- { flag: '--map-out <file>', description: 'mapping log path', key: 'mapOut' },
504
- ]);
505
504
  const assistant = contract.command('assistant').description('Contract AI assistant commands');
506
505
  registerCommand(assistant, 'init', 'Initialize or refresh assistant configuration', 'contract.assistant.init');
507
506
  registerCommand(assistant, 'meta', 'Read assistant list field metadata (ai_background_config)', 'contract.assistant.meta');
@@ -435,22 +435,28 @@ const quoteContracts = [
435
435
  inputSchema: readSchema({ num: { type: 'string', minLength: 1 } }, ['num']),
436
436
  },
437
437
  {
438
- name: 'contract.docx.fillfromquote',
438
+ name: 'contract.docx.slots.scan',
439
+ risk: 'read',
440
+ fixed: { local: true, kind: 'docx-slots-scan' },
441
+ inputSchema: readSchema({
442
+ template: { type: 'string', minLength: 1, maxLength: 4096, description: '模板 docx 绝对路径' },
443
+ out: { type: 'string', maxLength: 4096, description: '可选:位点清单 JSON 输出路径' },
444
+ }, ['template']),
445
+ },
446
+ {
447
+ name: 'contract.docx.slots.fill',
439
448
  risk: 'local-file-write',
440
- fixed: { local: true, kind: 'docx-fill-from-quote' },
449
+ fixed: { local: true, kind: 'docx-slots-fill' },
441
450
  inputSchema: readSchema({
442
451
  template: { type: 'string', minLength: 1, maxLength: 4096, description: '模板 docx 绝对路径' },
443
- data: {
452
+ out: { type: 'string', minLength: 1, maxLength: 4096, description: '输出 docx 绝对路径' },
453
+ plan: {
444
454
  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)',
455
+ description: '填充方案:{ slots:[{slotId,value}], details:[{slotId,items,subtotal}], unsupported:[], totals:{grandTotal,installments} };也可传 JSON 文件路径',
446
456
  },
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']),
457
+ strict: { type: 'boolean', description: '默认 true:必填位点未覆盖即判不通过' },
458
+ allowRowInsert: { type: 'boolean', description: '默认 true:明细行不足时克隆已有行补足(不改网格)' },
459
+ }, ['template', 'out', 'plan']),
454
460
  },
455
461
  {
456
462
  name: 'contract.docx.verify',
@@ -481,6 +487,35 @@ const quoteContracts = [
481
487
  head: { type: 'integer', minimum: 1, maximum: 200, description: '网格预览头部行数,默认 12' },
482
488
  }, ['file', 'outDir']),
483
489
  },
490
+ {
491
+ name: 'contract.quotescreen.tocontract',
492
+ risk: 'local-file-write',
493
+ fixed: { local: true, kind: 'quote-to-contract' },
494
+ inputSchema: readSchema({
495
+ quoteFile: { type: 'string', minLength: 1, maxLength: 4096, description: '报价单 .xlsx 绝对路径' },
496
+ outDir: { type: 'string', minLength: 1, maxLength: 4096, description: '中间产物与合同输出目录' },
497
+ out: { type: 'string', maxLength: 4096, description: '可选:合同 docx 输出路径;缺省 outDir/{合同名称}.docx' },
498
+ sheet: { type: 'string', description: '指定工作表名;不传取第一个' },
499
+ customerName: { type: 'string', description: '客户全称;缺省从报价单「客户名称:」自动识别' },
500
+ contractTitle: { type: 'string', description: '合同名称;缺省按「客户全称 + 标的 + 软件产品及实施服务购买合同」生成' },
501
+ subjectTitle: { type: 'string', description: '标的表述,默认「协同办公系统(e-cology)」' },
502
+ ourCompany: { type: 'string', description: '我方签约主体,默认「泛微网络科技股份有限公司」' },
503
+ signDate: { type: 'string', description: '签订/生效日期文本;缺省取当天' },
504
+ signPlace: { type: 'string', description: '签订地点,默认「上海市」' },
505
+ payments: {
506
+ type: 'array',
507
+ items: { type: 'number' },
508
+ description: '付款分期:传比例(如 0.3/0.3/0.3/0.1)或绝对金额数组;缺省 30/30/30/10',
509
+ },
510
+ templateFileId: { type: 'string', description: '指定范文 fileId;不传则走智能推荐取 rank1 且 matchScore ≥ 阈值' },
511
+ templatePath: { type: 'string', maxLength: 4096, description: '已下载的本地模板 docx 路径;传了即跳过推荐与下载' },
512
+ templateModule: { type: 'string', description: '模板下载 module,默认 ebuilderform' },
513
+ recommendContent: { type: 'string', maxLength: 4000, description: '自定义范文推荐需求描述;缺省按报价单自动拼装' },
514
+ minMatchScore: { type: 'number', description: '范文最低匹配分,默认 85;低于即中止并提示指定模板' },
515
+ card: { type: 'boolean', description: '默认 true:合同校验通过后一并渲染动作卡片' },
516
+ strict: { type: 'boolean', description: '透传 slots.fill:必填位点未覆盖即判不通过,默认 true' },
517
+ }, ['quoteFile', 'outDir']),
518
+ },
484
519
  {
485
520
  name: 'contract.triage.extract',
486
521
  risk: 'local-file-write',
@@ -732,18 +767,6 @@ const quoteContracts = [
732
767
  data: { type: 'string', minLength: 1 },
733
768
  }, ['data']),
734
769
  },
735
- {
736
- name: 'contract.quote.fill',
737
- risk: 'read-with-upload',
738
- fixed: { local: true, kind: 'docx-fill' },
739
- inputSchema: readSchema({
740
- template: { type: 'string', minLength: 1 },
741
- data: { type: 'string', minLength: 1 },
742
- out: { type: 'string', minLength: 1 },
743
- detail: { type: 'string', enum: ['append', 'none'] },
744
- mapOut: { type: 'string' },
745
- }, ['template', 'data', 'out']),
746
- },
747
770
  ];
748
771
  // ---------------------------------------------------------------- 客户主数据查询(按全称)
749
772
  //
@@ -1410,6 +1433,28 @@ export const contractOperations = [
1410
1433
  sclx: { type: 'string', pattern: '^8$' },
1411
1434
  }, ['fileId']),
1412
1435
  },
1436
+ {
1437
+ // 2026-11-16 新增:一条命令完成「取审查记录 → 解析 scnr → 压成约 8KB 摘要」。
1438
+ // 直接调 getAiReviewRecord,所以保留 fixed.method/path 便于审计;解析在本进程内完成。
1439
+ name: 'contract.review.digest',
1440
+ risk: 'read',
1441
+ auth: AUTH,
1442
+ fixed: {
1443
+ method: 'POST',
1444
+ path: '/api/ebd/contract/ai/getAiReviewRecord',
1445
+ aiId: '1326842382967570463',
1446
+ defaults: { sclx: '8' },
1447
+ postProcess: 'review-digest',
1448
+ },
1449
+ inputSchema: readSchema({
1450
+ fileId: { type: 'string', minLength: 1, maxLength: 64, description: '审查文件 id;给了 ref 时可省略' },
1451
+ ref: { type: 'string', maxLength: 4096, description: '可选:直接解析已落盘的导出结果 json,不再请求接口' },
1452
+ sclx: { type: 'string', pattern: '^8$', description: '固定 8(风险审查)' },
1453
+ includePass: { type: 'boolean', description: '默认 true:附判定无风险的规则名清单' },
1454
+ includeOriginal: { type: 'boolean', description: '默认 true:风险条目附合同原文片段' },
1455
+ out: { type: 'string', maxLength: 4096, description: '可选:摘要 JSON 落盘路径' },
1456
+ }, []),
1457
+ },
1413
1458
  {
1414
1459
  name: 'contract.flow.page',
1415
1460
  risk: 'read',
@@ -1562,11 +1607,43 @@ export const contractOperations = [
1562
1607
  compareFileId: { type: 'string', minLength: 1, maxLength: 64 },
1563
1608
  }, ['baseFileId', 'compareFileId']),
1564
1609
  },
1610
+ {
1611
+ name: 'contract.comparescreen.run',
1612
+ risk: 'read-with-upload',
1613
+ auth: AUTH,
1614
+ fixed: { local: true, kind: 'compare-screen-orchestration' },
1615
+ inputSchema: readSchema({
1616
+ files: {
1617
+ type: 'array',
1618
+ minItems: 2,
1619
+ maxItems: 2,
1620
+ items: { type: 'string', minLength: 1, maxLength: 1000 },
1621
+ description: '两个本地文件绝对路径:基准文件在前,比对文件在后(与 baseFileId 二选一)',
1622
+ },
1623
+ baseFileId: {
1624
+ type: 'string',
1625
+ minLength: 1,
1626
+ maxLength: 64,
1627
+ description: '已上传的基准文件 fileId(module=docCompared)',
1628
+ },
1629
+ compareFileId: {
1630
+ type: 'string',
1631
+ minLength: 1,
1632
+ maxLength: 64,
1633
+ description: '已上传的比对文件 fileId(module=docCompared)',
1634
+ },
1635
+ baseFileName: { type: 'string', maxLength: 300, description: '基准文件名;缺省取接口或上传返回值' },
1636
+ compareFileName: { type: 'string', maxLength: 300, description: '比对文件名;缺省取接口或上传返回值' },
1637
+ title: { type: 'string', maxLength: 200, description: '卡片标题,缺省为「可做的 N 件事」' },
1638
+ baseUrl: { type: 'string', maxLength: 2048, description: 'E10 地址,默认 https://www.e-cology.com.cn' },
1639
+ aiid: { type: 'string', maxLength: 64, description: '比对助手 id(透传给卡片)' },
1640
+ }, []),
1641
+ },
1565
1642
  {
1566
1643
  name: 'contract.credit.page',
1567
1644
  risk: 'read',
1568
1645
  auth: AUTH,
1569
- fixed: { pagePath: '/sp/contract/business/credit', pageTitle: '资信查询', activate: true, width: 1000 },
1646
+ fixed: { pagePath: '/sp/contract/business/credit', pageTitle: '资信查询', activate: true, width: 1300 },
1570
1647
  inputSchema: readSchema({
1571
1648
  names: {
1572
1649
  type: 'array',
@@ -38,7 +38,12 @@ export function encodeXml(text) {
38
38
  /** 收集指定标签的**成对**区间(含嵌套,按 start 升序)。 */
39
39
  export function collectRanges(xml, tag) {
40
40
  const ranges = [];
41
- const open = new RegExp(`<${tag}(?:\\s[^>]*)?>`, 'gu');
41
+ // 必须排除自闭合标签(如 `<w:p w14:paraId="X"/>`):它没有结束标签,
42
+ // 若当作开始标签压栈,会与后续真实的 `</w:p>` 错配,使区间整体跨段。
43
+ // 2026-11-16 实测:模板含 13 个自闭合空段落,开始标签 381 / 结束标签 368,
44
+ // 错配后段落区间把多个段落并成一段(P11 变成 6050 字符),
45
+ // 据此做「整段替换」会产出标签破碎的 docx(Word 打不开)。
46
+ const open = new RegExp(`<${tag}(?:\\s[^>]*?)?(?<!/)>`, 'gu');
42
47
  const close = new RegExp(`</${tag}>`, 'gu');
43
48
  const events = [];
44
49
  for (const m of xml.matchAll(open))
@@ -61,8 +66,18 @@ export function collectRanges(xml, tag) {
61
66
  ranges.push({ start, end });
62
67
  }
63
68
  }
64
- ranges.sort((a, b) => a.start - b.start);
65
- return ranges;
69
+ // 统一再做一次「只保留最外层」过滤。
70
+ //
71
+ // 上面的即时判断有盲区:嵌套标签是**内层先闭合、外层后闭合**,
72
+ // 内层先入 ranges,外层形成时并不"被内层覆盖",于是内外层都被保留,区间重叠。
73
+ // 2026-11-16 实测:模板封面标题段(含文本框)区间把内层两个标题段整段包住,
74
+ // 多个段落同时替换时按原偏移切片错位,产出标签破碎的 docx(Word 打不开)。
75
+ const outermost = ranges.filter((range) => !ranges.some((other) => other !== range &&
76
+ other.start <= range.start &&
77
+ other.end >= range.end &&
78
+ other.end - other.start > range.end - range.start));
79
+ outermost.sort((a, b) => a.start - b.start);
80
+ return outermost;
66
81
  }
67
82
  /** 解析**顶层**表格(`depth=1`),行与单元格都不含嵌套表格内部结构。 */
68
83
  export function parseTables(xml) {
@@ -231,3 +246,60 @@ export function deleteTableRows(xml, tableIndex, startRow, keep, count) {
231
246
  }
232
247
  return { xml: out, removed, ok: true };
233
248
  }
249
+ /** 去掉 w14:paraId / w14:textId,避免克隆行产生重复的段落标识。 */
250
+ function stripRowIds(rowXml) {
251
+ return rowXml
252
+ .replace(/\s+w14:paraId="[^"]*"/gu, '')
253
+ .replace(/\s+w14:textId="[^"]*"/gu, '');
254
+ }
255
+ /**
256
+ * 在 `atRow` 之前插入 `count` 行,行结构克隆自 `templateRow`。
257
+ *
258
+ * 只克隆**已有行**并把 `<w:tr>` 整段复制,不新建 `<w:tc>`、不改 `w:tblGrid`,
259
+ * 因此网格列宽、合并单元格语义都不会漂移。克隆行的文本沿用模板行,
260
+ * 由调用方随后用 `setCellText` 覆盖。
261
+ */
262
+ export function insertTableRows(xml, tableIndex, atRow, templateRow, count) {
263
+ if (count <= 0)
264
+ return { xml, inserted: 0, ok: true, insertedRange: { startRow: atRow, endRow: atRow - 1 } };
265
+ const table = parseTables(xml)[tableIndex];
266
+ if (!table)
267
+ return { xml, inserted: 0, ok: false, reason: 'table_not_found' };
268
+ const anchor = table.rows[atRow];
269
+ if (!anchor)
270
+ return { xml, inserted: 0, ok: false, reason: 'anchor_row_not_found' };
271
+ const template = table.rows[templateRow];
272
+ if (!template)
273
+ return { xml, inserted: 0, ok: false, reason: 'template_row_not_found' };
274
+ const rowXml = stripRowIds(template.xml);
275
+ const insertion = rowXml.repeat(count);
276
+ const absAt = table.start + anchor.start;
277
+ const out = xml.slice(0, absAt) + insertion + xml.slice(absAt);
278
+ return {
279
+ xml: out,
280
+ inserted: count,
281
+ ok: true,
282
+ insertedRange: { startRow: atRow, endRow: atRow + count - 1 },
283
+ };
284
+ }
285
+ /** 表网格列宽序列(对应 `<w:tblGrid>` 的 gridCol),用于「结构未变」比对。 */
286
+ export function tableGridWidths(xml, tableIndex) {
287
+ const tables = parseTables(xml);
288
+ const table = tables[tableIndex];
289
+ if (!table)
290
+ return [];
291
+ const tableXml = xml.slice(table.start, table.end);
292
+ const gridMatch = /<w:tblGrid(?:\s[^>]*)?>([\s\S]*?)<\/w:tblGrid>/u.exec(tableXml);
293
+ if (!gridMatch)
294
+ return [];
295
+ const widths = [];
296
+ for (const match of (gridMatch[1] ?? '').matchAll(/<w:gridCol[^>]*w:w="(\d+)"/gu)) {
297
+ widths.push(match[1] ?? '');
298
+ }
299
+ return widths;
300
+ }
301
+ /** 全部顶层表格的网格列宽,供填充前后比对。 */
302
+ export function allTableGrids(xml) {
303
+ const tables = parseTables(xml);
304
+ return tables.map((table) => tableGridWidths(xml, table.index));
305
+ }