weaver-work-cli 0.1.49 → 0.1.52

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 (207) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{attachment-content-MU2LPI5P.js → attachment-content-MBYYSQIX.js} +3 -3
  3. package/dist/chunks/{chunk-ZKEUGS2U.js → chunk-7UOXOGFL.js} +4 -4
  4. package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
  5. package/dist/chunks/{chunk-3NV2ETZR.js → chunk-D3TDNRFE.js} +8 -8
  6. package/dist/chunks/{chunk-6GWU63YF.js → chunk-DZOC77ZD.js} +1 -1
  7. package/dist/chunks/{chunk-K3BT54CU.js → chunk-IRMA3GVP.js} +1 -1
  8. package/dist/chunks/{chunk-3X7VOSBA.js → chunk-KLZ3ULQQ.js} +1 -1
  9. package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
  10. package/dist/chunks/{chunk-NBEWUR7L.js → chunk-LALWNK6M.js} +167 -44
  11. package/dist/chunks/{chunk-BRRW7CWA.js → chunk-LM2H7SZI.js} +26 -26
  12. package/dist/chunks/{chunk-KV5SOWMS.js → chunk-LTRLF6MM.js} +4 -4
  13. package/dist/chunks/{chunk-D2QRZUW4.js → chunk-RPRFIG6I.js} +35 -28
  14. package/dist/chunks/{chunk-GEOMANP7.js → chunk-RWFRZSIP.js} +2 -2
  15. package/dist/chunks/{chunk-EJVA5ZVB.js → chunk-ZRHKGQRQ.js} +2 -2
  16. package/dist/chunks/{conflict-6347A7YK.js → conflict-D2HYKBMH.js} +2 -2
  17. package/dist/chunks/{contract-N6P2HIIE.js → contract-MFOFMM2J.js} +4284 -254
  18. package/dist/chunks/{create-flow-7WG7LVX5.js → create-flow-7ZATJVTM.js} +6 -6
  19. package/dist/chunks/{data-QO7QWOIV.js → data-WK5CQXNF.js} +17 -32
  20. package/dist/chunks/{env-LHRKSLG6.js → env-5DO4YENS.js} +2 -2
  21. package/dist/chunks/{factory-2H7Z4RWJ.js → factory-3M7D7WJC.js} +1 -1
  22. package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
  23. package/dist/chunks/{group-chat-EW6PNDDT.js → group-chat-B2HT5NEO.js} +3 -3
  24. package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
  25. package/dist/chunks/{invoice-FXWH5GPO.js → invoice-V7ZTITUO.js} +726 -206
  26. package/dist/chunks/{meeting-N2FQBHXI.js → meeting-HZOX3CBB.js} +10 -10
  27. package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
  28. package/dist/chunks/{reception-MYOKJULO.js → reception-QGPNTGHG.js} +98 -82
  29. package/dist/chunks/{recruit-stage-FKWS5UQF.js → recruit-stage-XCMVEQA2.js} +718 -131
  30. package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
  31. package/dist/chunks/{registry-7VZ6YJUF.js → registry-KYPFFQIH.js} +1 -1
  32. package/dist/chunks/{registry-CKUVBS53.js → registry-SJHSBO5G.js} +10 -10
  33. package/dist/chunks/{room-recommend-MBCYENQ2.js → room-recommend-5AHR4YQV.js} +4 -4
  34. package/dist/chunks/{schedule-5IFMCXME.js → schedule-KZPJUPC2.js} +4 -4
  35. package/dist/chunks/smart-extract-IXHCZE4R.js +2846 -0
  36. package/dist/chunks/{workflow-2TRU2ZSP.js → workflow-UHKCZJMY.js} +1 -1
  37. package/dist/index.js +14 -9
  38. package/dist/shortcuts/contract/host.js +11 -0
  39. package/dist/shortcuts/contract/index.js +13 -0
  40. package/dist/shortcuts/contract/manifest.js +204 -0
  41. package/dist/shortcuts/contract/operations/card-action.js +585 -0
  42. package/dist/shortcuts/contract/operations/card-ebdf-list.js +315 -0
  43. package/dist/shortcuts/contract/operations/card-plan.js +327 -0
  44. package/dist/shortcuts/contract/operations/card-risk-report.js +565 -0
  45. package/dist/shortcuts/contract/operations/elements-build.js +714 -0
  46. package/dist/shortcuts/contract/operations/elements-spec.js +216 -0
  47. package/dist/shortcuts/contract/operations/first-screen.js +563 -0
  48. package/dist/shortcuts/contract/operations/flow.js +81 -25
  49. package/dist/shortcuts/contract/operations/modeltext.js +132 -0
  50. package/dist/shortcuts/contract/operations/op-resolver.js +22 -0
  51. package/dist/shortcuts/contract/operations/performance.js +58 -7
  52. package/dist/shortcuts/contract/operations/quote.js +410 -22
  53. package/dist/shortcuts/contract/operations/registry.js +22 -0
  54. package/dist/shortcuts/contract/operations/review.js +73 -58
  55. package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
  56. package/dist/shortcuts/contract/operations/summary-validate.js +293 -0
  57. package/dist/shortcuts/contract/operations/summary.js +4 -2
  58. package/dist/shortcuts/contract/operations/upload.js +48 -7
  59. package/dist/shortcuts/contract/prewarm-cache.js +90 -0
  60. package/dist/shortcuts/contract/prewarm.js +88 -0
  61. package/dist/shortcuts/contract/upload-cache.js +49 -4
  62. package/dist/shortcuts/data/index.js +1 -6
  63. package/dist/shortcuts/data/manifest.js +2 -2
  64. package/dist/shortcuts/data/operations/index.js +1 -1
  65. package/dist/shortcuts/data/operations/query.js +23 -46
  66. package/dist/shortcuts/fna/host.js +4 -2
  67. package/dist/shortcuts/fna/manifest.js +14 -5
  68. package/dist/shortcuts/fna/operations/audit.js +334 -0
  69. package/dist/shortcuts/fna/operations/registry.js +2 -0
  70. package/dist/shortcuts/im/operations/at-mention.js +6 -3
  71. package/dist/shortcuts/im/operations/msg-parse.js +35 -5
  72. package/dist/shortcuts/im/operations/msg-sync.js +3 -1
  73. package/dist/shortcuts/im/operations/msg-write.js +57 -9
  74. package/dist/shortcuts/index.js +5 -0
  75. package/dist/shortcuts/invoice/index.js +0 -12
  76. package/dist/shortcuts/invoice/manifest.js +201 -50
  77. package/dist/shortcuts/invoice/operations/registry.js +4 -2
  78. package/dist/shortcuts/invoice/operations/reim-relation.js +438 -0
  79. package/dist/shortcuts/invoice/operations/shared.js +3 -19
  80. package/dist/shortcuts/invoice/operations/upload-and-validate.js +109 -73
  81. package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
  82. package/dist/shortcuts/reception/constants.js +3 -7
  83. package/dist/shortcuts/reception/operations/leads.js +30 -6
  84. package/dist/shortcuts/reception/operations/panels.js +3 -2
  85. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +4 -2
  86. package/dist/shortcuts/recruit-stage/operations/jd-create.js +6 -2
  87. package/dist/shortcuts/recruit-stage/operations/list.js +217 -1
  88. package/dist/shortcuts/recruit-stage/operations/resume-import.js +144 -158
  89. package/dist/shortcuts/recruit-stage/operations/search.js +348 -0
  90. package/dist/shortcuts/recruit-stage/shared.js +5 -0
  91. package/dist/shortcuts/recruit-stage/tag-lookup.js +136 -0
  92. package/dist/shortcuts/smart-extract/constants.js +79 -0
  93. package/dist/shortcuts/smart-extract/continuation.js +71 -0
  94. package/dist/shortcuts/smart-extract/errors.js +68 -0
  95. package/dist/shortcuts/smart-extract/host.js +191 -0
  96. package/dist/shortcuts/smart-extract/index.js +105 -0
  97. package/dist/shortcuts/smart-extract/ledger.js +70 -0
  98. package/dist/shortcuts/smart-extract/manifest.js +35 -0
  99. package/dist/shortcuts/smart-extract/operations/attachment.js +212 -0
  100. package/dist/shortcuts/smart-extract/operations/batch.js +67 -0
  101. package/dist/shortcuts/smart-extract/operations/config.js +118 -0
  102. package/dist/shortcuts/smart-extract/operations/fill.js +489 -0
  103. package/dist/shortcuts/smart-extract/operations/preview.js +174 -0
  104. package/dist/shortcuts/smart-extract/operations/registry.js +34 -0
  105. package/dist/shortcuts/smart-extract/operations/save.js +355 -0
  106. package/dist/shortcuts/smart-extract/operations/shared.js +191 -0
  107. package/dist/shortcuts/smart-extract/operations/structure.js +401 -0
  108. package/dist/shortcuts/smart-extract/operations/target.js +167 -0
  109. package/dist/shortcuts/smart-extract/operations/types.js +22 -0
  110. package/dist/shortcuts/smart-extract/operations/validate.js +408 -0
  111. package/dist/shortcuts/workflow/operations/read.js +77 -15
  112. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
  113. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
  114. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
  115. package/docs/SKILL.md +1 -1
  116. package/docs/_catalog.md +4 -1
  117. package/docs/agent-invoice.md +5 -7
  118. package/docs/data.md +5 -1
  119. package/docs/fna.md +24 -4
  120. package/docs/invoice.md +7 -5
  121. package/docs/smart-extract.md +156 -0
  122. package/package.json +1 -1
  123. package/skill-template/business-info.json +21 -1
  124. package/skill-template/domains/qiyecheng.md +6 -2
  125. package/skill-template/domains/smart-extract.md +16 -0
  126. package/skill-template/domains/yepiaotong.md +2 -2
  127. package/skills/weaver-e10-data/references/scene-and-misc.md +4 -3
  128. package/skills/weaver-e10-jinchengda/SKILL.md +159 -11
  129. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +13 -8
  130. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +5 -4
  131. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
  132. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  133. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +220 -0
  134. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +68 -33
  135. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +26 -15
  136. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  137. package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +128 -0
  138. package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +90 -0
  139. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
  140. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +167 -5
  141. package/skills/weaver-e10-jinchengda/scripts/contract_first_screen.py +200 -0
  142. package/skills/weaver-e10-jinchengda/scripts/fill_contract_from_quote.py +572 -0
  143. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
  144. package/skills/weaver-e10-jinchengda/scripts/quote_screen.py +560 -0
  145. package/skills/weaver-e10-jinchengda/scripts/triage_contract.py +894 -0
  146. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +93 -0
  147. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
  148. package/skills/weaver-e10-qiyecheng/SKILL.md +58 -7
  149. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +118 -0
  150. package/skills/weaver-e10-qiyecheng/references/budget.md +14 -0
  151. package/skills/weaver-e10-qiyecheng/references/catalog.md +42 -3
  152. package/skills/weaver-e10-qiyecheng/references/expense-center.md +8 -0
  153. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +9 -0
  154. package/skills/weaver-e10-qiyecheng/references/invoice-writeoff.md +13 -0
  155. package/skills/weaver-e10-qiyecheng/references/loan-management.md +14 -0
  156. package/skills/weaver-e10-qiyecheng/references/self-hosted-mode.md +239 -0
  157. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +153 -40
  158. package/skills/weaver-e10-reception-flow/SKILL.md +43 -6
  159. package/skills/weaver-e10-reception-flow/references/guide.md +1 -1
  160. package/skills/weaver-e10-recruit-stage/SKILL.md +62 -4
  161. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +42 -8
  162. package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +79 -0
  163. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +11 -3
  164. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +3 -2
  165. package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +153 -0
  166. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +7 -4
  167. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  168. package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +66 -0
  169. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +156 -40
  170. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +122 -0
  171. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +36 -8
  172. package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +157 -0
  173. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +35 -0
  174. package/skills/weaver-e10-smart-extract/SKILL.md +169 -0
  175. package/skills/weaver-e10-smart-extract/references/api-contract.md +71 -0
  176. package/skills/weaver-e10-smart-extract/references/result-format.md +102 -0
  177. package/skills/weaver-e10-smart-extract/references/troubleshooting.md +105 -0
  178. package/skills/weaver-e10-workflow/SKILL.md +2 -1
  179. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
  180. package/skills/weaver-e10-workflow/references/workflow-query.md +1 -1
  181. package/skills/weaver-e10-workflow/references/workflow-view.md +1 -1
  182. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
  183. package/skills/weaver-e10-yepiaotong/SKILL.md +53 -35
  184. package/skills/weaver-e10-yepiaotong/references/invoice-add.md +2 -0
  185. package/skills/weaver-e10-yepiaotong/references/invoice-file-upload.md +1 -1
  186. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +19 -2
  187. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
  188. package/skills/weaver-e10-yepiaotong/references/invoice-ocr-preview.md +8 -2
  189. package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +407 -0
  190. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +18 -53
  191. package/skills/weaver-e10-yepiaotong/references/invoice-upload-and-validate.md +97 -39
  192. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +96 -7
  193. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +5 -38
  194. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +14 -14
  195. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +8 -4
  196. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +139 -94
  197. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +131 -58
  198. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +110 -43
  199. package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
  200. package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
  201. package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
  202. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
  203. package/dist/shortcuts/invoice/operations/validate-preview.js +0 -40
  204. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +0 -279
  205. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +0 -450
  206. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +0 -358
  207. package/skills/weaver-e10-yepiaotong/references/invoice-validation-preview.md +0 -40
@@ -2,7 +2,8 @@ import { createHash } from 'node:crypto';
2
2
  import { readFile, stat } from 'node:fs/promises';
3
3
  import { basename, resolve } from 'node:path';
4
4
  import { contractPolicyError, contractValidationError } from '../errors.js';
5
- import { fingerprintKey, isCacheEnabled, lookupUpload, rememberUpload, sha256Of, } from '../upload-cache.js';
5
+ import { fingerprintKey, isCacheEnabled, lookupUpload, rememberFileModule, rememberUpload, sha256Of, } from '../upload-cache.js';
6
+ import { ensurePrewarmed } from '../prewarm.js';
6
7
  const MAX_FILE_BYTES = 200 * 1024 * 1024;
7
8
  const DEFAULT_UPLOAD_TIMEOUT_MS = 120_000;
8
9
  const DOC_EXTENSIONS = new Set(['.doc', '.docx']);
@@ -22,6 +23,9 @@ function pickFileId(payload) {
22
23
  /**
23
24
  * 两段式文件上传:preUploadCheck 预检(命中秒传直接返回 fileId)→ module/upload 实传。
24
25
  * 成功判据是拿到非空 fileId,HTTP 200 不算成功。
26
+ *
27
+ * 上传成功后**立即触发预审预热**(与 module 无关),由 `ensurePrewarmed` 做整轮去重:
28
+ * 后续预审复用同一个 fileId 时不会再重复调用预热接口。
25
29
  */
26
30
  export async function uploadFile(host, options) {
27
31
  const absolutePath = resolve(options.path);
@@ -55,7 +59,7 @@ export async function uploadFile(host, options) {
55
59
  });
56
60
  const hit = await lookupUpload(reuseKey);
57
61
  if (hit) {
58
- return {
62
+ return await finish({
59
63
  fileId: hit.fileId,
60
64
  docId: hit.docId,
61
65
  name: hit.name || name,
@@ -63,7 +67,7 @@ export async function uploadFile(host, options) {
63
67
  md5: hit.md5,
64
68
  sha256,
65
69
  reused: true,
66
- };
70
+ });
67
71
  }
68
72
  }
69
73
  catch {
@@ -105,7 +109,7 @@ export async function uploadFile(host, options) {
105
109
  sha256,
106
110
  });
107
111
  }
108
- return {
112
+ return await finish({
109
113
  fileId: secondUploadId,
110
114
  docId: reusedDocId,
111
115
  name: reusedName,
@@ -113,7 +117,7 @@ export async function uploadFile(host, options) {
113
117
  md5,
114
118
  sha256,
115
119
  reused: false,
116
- };
120
+ });
117
121
  }
118
122
  const preUploadId = text(precheckData.preUploadId);
119
123
  const uploadType = text(precheckData.uploadType) ?? 'common';
@@ -148,7 +152,7 @@ export async function uploadFile(host, options) {
148
152
  sha256,
149
153
  });
150
154
  }
151
- return {
155
+ return await finish({
152
156
  fileId,
153
157
  docId: finalDocId,
154
158
  name: finalName,
@@ -156,7 +160,44 @@ export async function uploadFile(host, options) {
156
160
  md5,
157
161
  sha256,
158
162
  reused: false,
159
- };
163
+ });
164
+ /**
165
+ * 上传收口:三条返回路径共用。
166
+ * 1. 补记 fileId → module,供流程侧判断附件能否直接复用;
167
+ * 2. 触发预审预热(与 module 无关,默认开;同一 fileId 只触发一次)。
168
+ */
169
+ async function finish(file) {
170
+ file.module = options.module;
171
+ const prewarmEnabled = options.prewarm !== false;
172
+ if (!prewarmEnabled)
173
+ return file;
174
+ try {
175
+ const session = await host.getSession();
176
+ await rememberFileModule({
177
+ fileId: file.fileId,
178
+ module: options.module,
179
+ baseUrl: session.baseUrl,
180
+ userId: session.userId ?? '',
181
+ });
182
+ }
183
+ catch {
184
+ // 记录失败只影响"能否复用",不影响上传结果。
185
+ }
186
+ try {
187
+ const summary = await ensurePrewarmed(host, [file.fileId]);
188
+ const result = summary.results[0];
189
+ const ok = result?.ok === true;
190
+ file.prewarmed = ok;
191
+ file.prewarmSkipped = result?.skipped === true;
192
+ if (!ok)
193
+ file.prewarmError = result?.error ?? '未知原因';
194
+ }
195
+ catch (error) {
196
+ file.prewarmed = false;
197
+ file.prewarmError = error instanceof Error ? error.message : String(error);
198
+ }
199
+ return file;
200
+ }
160
201
  }
161
202
  export function assertContractDocument(path) {
162
203
  const lower = path.toLowerCase();
@@ -0,0 +1,90 @@
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, resolve } from 'node:path';
4
+ const CACHE_VERSION = 1;
5
+ const MAX_ENTRIES = 500;
6
+ /** 预审记录本身有时效,预热标记 2 小时后失效,避免误跳过真正需要的重跑。 */
7
+ const DEFAULT_TTL_MS = 2 * 60 * 60 * 1000;
8
+ function cacheRoot() {
9
+ const home = process.env.WEAVER_WORK_CLI_HOME
10
+ || process.env.WORK_CLI_HOME
11
+ || resolve(homedir(), '.weaver-work-cli');
12
+ return resolve(home, 'contract');
13
+ }
14
+ export function prewarmCacheFilePath() {
15
+ return resolve(cacheRoot(), 'prewarm-cache.json');
16
+ }
17
+ function ttlMs() {
18
+ const raw = process.env.WEAVER_CONTRACT_PREWARM_CACHE_TTL_MS;
19
+ if (raw === undefined)
20
+ return DEFAULT_TTL_MS;
21
+ const parsed = Number(raw);
22
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : DEFAULT_TTL_MS;
23
+ }
24
+ export function isPrewarmCacheEnabled() {
25
+ return ttlMs() > 0;
26
+ }
27
+ /** 预热去重键:fileId + 环境 + 用户,任一不同都视为不同文件。 */
28
+ export function prewarmKey(input) {
29
+ return `${input.baseUrl}|${input.userId}|${input.fileId}`;
30
+ }
31
+ async function readCache() {
32
+ try {
33
+ const raw = (await readFile(prewarmCacheFilePath(), 'utf8')).replace(/^\uFEFF/u, '');
34
+ const parsed = JSON.parse(raw);
35
+ if (!parsed || parsed.version !== CACHE_VERSION || typeof parsed.entries !== 'object') {
36
+ return { version: CACHE_VERSION, entries: {} };
37
+ }
38
+ return parsed;
39
+ }
40
+ catch {
41
+ return { version: CACHE_VERSION, entries: {} };
42
+ }
43
+ }
44
+ async function writeCache(cache) {
45
+ try {
46
+ const path = prewarmCacheFilePath();
47
+ await mkdir(dirname(path), { recursive: true });
48
+ await writeFile(path, JSON.stringify(cache), 'utf8');
49
+ }
50
+ catch {
51
+ // 缓存写不进去不影响业务:最坏情况就是多预热一次。
52
+ }
53
+ }
54
+ /** 该 fileId 是否已经预热过(未过期)。 */
55
+ export async function wasPrewarmed(key) {
56
+ if (!isPrewarmCacheEnabled())
57
+ return false;
58
+ const cache = await readCache();
59
+ const at = cache.entries[key];
60
+ if (at === undefined)
61
+ return false;
62
+ if (Date.now() - at > ttlMs()) {
63
+ delete cache.entries[key];
64
+ await writeCache(cache);
65
+ return false;
66
+ }
67
+ return true;
68
+ }
69
+ /** 预热成功后登记,供同一轮后续步骤跳过重复调用。 */
70
+ export async function markPrewarmed(key) {
71
+ if (!isPrewarmCacheEnabled())
72
+ return;
73
+ const cache = await readCache();
74
+ cache.entries[key] = Date.now();
75
+ const keys = Object.keys(cache.entries);
76
+ if (keys.length > MAX_ENTRIES) {
77
+ keys
78
+ .sort((a, b) => cache.entries[a] - cache.entries[b])
79
+ .slice(0, keys.length - MAX_ENTRIES)
80
+ .forEach((stale) => delete cache.entries[stale]);
81
+ }
82
+ await writeCache(cache);
83
+ }
84
+ /** 清空预热标记,供排查或强制重跑使用。 */
85
+ export async function clearPrewarmCache() {
86
+ const cache = await readCache();
87
+ const count = Object.keys(cache.entries).length;
88
+ await writeCache({ version: CACHE_VERSION, entries: {} });
89
+ return count;
90
+ }
@@ -0,0 +1,88 @@
1
+ import { isPrewarmCacheEnabled, markPrewarmed, prewarmKey, wasPrewarmed } from './prewarm-cache.js';
2
+ /**
3
+ * 合同预审预热(`saveInternalRecord`)。
4
+ *
5
+ * 业务口径(2026-11-12 用户定稿):
6
+ * 1. **文件上传后就触发预热**,与上传时用的 module 无关(workflow / ebContract / docCompared 都一样);
7
+ * 2. 一整轮处理**只需要预热一次**,因此这里用 `ensurePrewarmed` 做本地去重;
8
+ * 3. 预审与 module 无关,审查页直接用会话里已有的 fileId 即可。
9
+ *
10
+ * 预热只是加速手段:失败不抛异常,收敛成 `{ ok: false, error }` 交给调用方汇总成 warnings。
11
+ */
12
+ /** 预审预热流程 ID(固定业务常量,禁止替换)。 */
13
+ export const AI_REVIEW_PREWARM_FLOW_ID = '1269716062340284522';
14
+ const PREWARM_PATH = '/api/ebd/contract/ai/saveInternalRecord';
15
+ const PREWARM_TIMEOUT_MS = 30_000;
16
+ async function prewarmOne(host, fileId) {
17
+ try {
18
+ await host.contractRequest({
19
+ method: 'POST',
20
+ path: PREWARM_PATH,
21
+ body: { flowId: AI_REVIEW_PREWARM_FLOW_ID, fileId },
22
+ timeoutMs: PREWARM_TIMEOUT_MS,
23
+ // 触发型接口:成功时响应体为空,代表"预审已在执行"。
24
+ // 不能走业务码判定,否则空体会被判成业务失败。
25
+ okOnHttpSuccess: true,
26
+ });
27
+ return { fileId, ok: true };
28
+ }
29
+ catch (error) {
30
+ const message = error instanceof Error ? error.message : String(error);
31
+ const structured = error;
32
+ const code = structured?.code === undefined ? '' : ` code=${String(structured.code)}`;
33
+ const raw = typeof structured?.details?.raw === 'string'
34
+ ? ` raw=${String(structured.details.raw).slice(0, 300)}`
35
+ : '';
36
+ return { fileId, ok: false, error: `${message}${code}${raw}` };
37
+ }
38
+ }
39
+ /**
40
+ * 按需预热:已预热过的 fileId 直接跳过,未预热的并行触发。
41
+ *
42
+ * `force: true` 时会忽略去重标记强制重跑(仅用于显式补触发命令)。
43
+ * 本函数**不抛异常**,调用方据 `failCount` 汇总 warning 即可。
44
+ */
45
+ export async function ensurePrewarmed(host, fileIds, options = {}) {
46
+ const unique = Array.from(new Set(fileIds.map((item) => String(item).trim()).filter(Boolean)));
47
+ const force = options.force === true;
48
+ let baseUrl = '';
49
+ let userId = '';
50
+ try {
51
+ const session = await host.getSession();
52
+ baseUrl = session.baseUrl ?? '';
53
+ userId = session.userId ?? '';
54
+ }
55
+ catch {
56
+ // 拿不到会话时退化为"不去重",宁可多预热一次也不阻断主流程。
57
+ }
58
+ const results = await Promise.all(unique.map(async (fileId) => {
59
+ if (!force && isPrewarmCacheEnabled() && baseUrl) {
60
+ const key = prewarmKey({ fileId, baseUrl, userId });
61
+ if (await wasPrewarmed(key)) {
62
+ return { fileId, ok: true, skipped: true };
63
+ }
64
+ }
65
+ const result = await prewarmOne(host, fileId);
66
+ if (result.ok && isPrewarmCacheEnabled() && baseUrl) {
67
+ await markPrewarmed(prewarmKey({ fileId, baseUrl, userId }));
68
+ }
69
+ return result;
70
+ }));
71
+ return {
72
+ flowId: AI_REVIEW_PREWARM_FLOW_ID,
73
+ enabled: true,
74
+ okCount: results.filter((item) => item.ok).length,
75
+ failCount: results.filter((item) => !item.ok).length,
76
+ skippedCount: results.filter((item) => item.skipped === true).length,
77
+ results,
78
+ };
79
+ }
80
+ /** 无条件预热(显式补触发用),不去重。 */
81
+ export async function prewarmAll(host, fileIds) {
82
+ const unique = Array.from(new Set(fileIds.map((item) => String(item).trim()).filter(Boolean)));
83
+ return Promise.all(unique.map((fileId) => prewarmOne(host, fileId)));
84
+ }
85
+ /** 单文件无条件预热。 */
86
+ export async function prewarmOneFile(host, fileId) {
87
+ return prewarmOne(host, fileId);
88
+ }
@@ -4,6 +4,7 @@ import { homedir } from 'node:os';
4
4
  import { dirname, resolve } from 'node:path';
5
5
  const CACHE_VERSION = 1;
6
6
  const MAX_ENTRIES = 200;
7
+ const MAX_FILE_MODULES = 500;
7
8
  const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
8
9
  function cacheRoot() {
9
10
  const home = process.env.WEAVER_WORK_CLI_HOME
@@ -39,12 +40,19 @@ async function readCache() {
39
40
  const raw = (await readFile(cacheFilePath(), 'utf8')).replace(/^\uFEFF/u, '');
40
41
  const parsed = JSON.parse(raw);
41
42
  if (!parsed || parsed.version !== CACHE_VERSION || typeof parsed.entries !== 'object') {
42
- return { version: CACHE_VERSION, entries: {} };
43
+ return { version: CACHE_VERSION, entries: {}, fileModules: {} };
43
44
  }
44
- return parsed;
45
+ return {
46
+ version: CACHE_VERSION,
47
+ entries: parsed.entries ?? {},
48
+ // 旧版本缓存文件没有这个字段,读出来时补空对象即可。
49
+ fileModules: (parsed.fileModules && typeof parsed.fileModules === 'object')
50
+ ? parsed.fileModules
51
+ : {},
52
+ };
45
53
  }
46
54
  catch {
47
- return { version: CACHE_VERSION, entries: {} };
55
+ return { version: CACHE_VERSION, entries: {}, fileModules: {} };
48
56
  }
49
57
  }
50
58
  async function writeCache(cache) {
@@ -95,10 +103,47 @@ export async function rememberUpload(key, entry) {
95
103
  }
96
104
  await writeCache(cache);
97
105
  }
106
+ /** 登记 fileId → module,供流程侧判断能否直接复用附件文件。 */
107
+ export async function rememberFileModule(input) {
108
+ if (!isCacheEnabled() || !input.fileId)
109
+ return;
110
+ const cache = await readCache();
111
+ cache.fileModules[`${input.baseUrl}|${input.userId}|${input.fileId}`] = {
112
+ module: input.module,
113
+ updatedAt: Date.now(),
114
+ };
115
+ const keys = Object.keys(cache.fileModules);
116
+ if (keys.length > MAX_FILE_MODULES) {
117
+ keys
118
+ .sort((a, b) => cache.fileModules[a].updatedAt - cache.fileModules[b].updatedAt)
119
+ .slice(0, keys.length - MAX_FILE_MODULES)
120
+ .forEach((stale) => delete cache.fileModules[stale]);
121
+ }
122
+ await writeCache(cache);
123
+ }
124
+ /**
125
+ * 反查某个 fileId 当初是用哪个 module 上传的。
126
+ * 返回 null 表示未知(缓存过期、从未在本机上传、或换了环境/账号)。
127
+ * 调用方对 null 要按"不是 workflow"处理,即重新上传。
128
+ */
129
+ export async function lookupFileModule(input) {
130
+ if (!isCacheEnabled() || !input.fileId)
131
+ return null;
132
+ const cache = await readCache();
133
+ const entry = cache.fileModules[`${input.baseUrl}|${input.userId}|${input.fileId}`];
134
+ if (!entry)
135
+ return null;
136
+ if (Date.now() - entry.updatedAt > ttlMs()) {
137
+ delete cache.fileModules[`${input.baseUrl}|${input.userId}|${input.fileId}`];
138
+ await writeCache(cache);
139
+ return null;
140
+ }
141
+ return entry.module;
142
+ }
98
143
  /** 清空缓存,供显式刷新或多份副本排查时使用。 */
99
144
  export async function clearUploadCache() {
100
145
  const cache = await readCache();
101
146
  const count = Object.keys(cache.entries).length;
102
- await writeCache({ version: CACHE_VERSION, entries: {} });
147
+ await writeCache({ version: CACHE_VERSION, entries: {}, fileModules: {} });
103
148
  return count;
104
149
  }
@@ -109,12 +109,7 @@ export const dataShortcut = {
109
109
  .option('--schema <schema>', '库名')
110
110
  .option('--table-id <id>', '数据集 / 流程 ID')
111
111
  .option('--dsl <json|@file>', 'DSL 查询体')
112
- .option('--debug [bool]', '回显 SQL(true/false)')
113
- .option('--dimension <key>', '后端 confKey(URL query,恒定发送)')
114
- .option('--conf-group <group>', 'confGroup(URL query,恒定发送)')
115
- .option('--confGroup <group>', '同 --conf-group')
116
- .option('--username <name>', '问句中出现的人名(无则传空)')
117
- .option('--start-date <ym>', '问句日期起始年月(无则传空)')
112
+ .requiredOption('--question-context <json|@file>', '问句上下文,含 dimensions / timeRanges')
118
113
  .action(action(async (ctx, options) => {
119
114
  await run(ctx, 'data.dsl.query', toInput(options), false);
120
115
  }));
@@ -7,8 +7,8 @@ import { operationDefinitions } from './operations/index.js';
7
7
  */
8
8
  const INPUT_SCHEMAS = {
9
9
  'data.dsl.query': {
10
- required: ['conn', 'model', 'schema', 'dsl'],
11
- optional: ['table_id', 'debug', 'dimension', 'conf_group', 'username', 'start_date'],
10
+ required: ['conn', 'model', 'schema', 'dsl', 'question_context'],
11
+ optional: ['table_id'],
12
12
  },
13
13
  'data.ds.groups': { required: [], optional: ['pattern'] },
14
14
  'data.ds.find': {
@@ -8,7 +8,7 @@ import { confAdd, confAddFile, confBatch, confBatchFile, confDelete, confGet, co
8
8
  import { moduleCall } from './module.js';
9
9
  import { sceneGroups, sceneItems, sceneSearch } from './scene.js';
10
10
  const DEFINITIONS = [
11
- { name: 'data.dsl.query', summary: '直接执行 DSL 查询(executeQueryDsl),ds list/chart/stat/count 的底层入口', capability: 'dsl', handler: executeQuery, command: 'query' },
11
+ { name: 'data.dsl.query', summary: '直接执行 DSL 查询(executeQueryDsl;与 ds list/chart/stat/count 为独立通道)', capability: 'dsl', handler: executeQuery, command: 'query' },
12
12
  { name: 'data.ds.groups', summary: '内置数据源分组清单(仅用于 ds find 的默认扫描候选集)', capability: 'discovery', handler: dsGroups, command: 'ds groups' },
13
13
  { name: 'data.ds.find', summary: '按关键词跨分组找表(进程内并发扇出 + 本地过滤 + 路由建议)', capability: 'discovery', handler: dsFind, command: 'ds find' },
14
14
  { name: 'data.ds.describe', summary: '一次并发取回字段元数据 + 词库,并给出关联字段/通道提示', capability: 'discovery', handler: dsDescribe, command: 'ds describe' },
@@ -1,68 +1,30 @@
1
1
  import { needArg } from '../host.js';
2
2
  import { dataValidationError } from '../errors.js';
3
- import { readJsonArg, renderTable } from './shared.js';
4
- /** `executeQueryDsl` 的 4 个 URL query 参数——**恒定发送**,值允许为空。 */
5
- const QUERY_PARAM_ALIASES = [
6
- ['dimension', 'dimension'],
7
- ['confGroup', 'conf-group'],
8
- ['username', 'username'],
9
- ['startDate', 'start-date'],
10
- ];
11
- function argStr(input, key) {
12
- const value = input[key];
13
- // 裸开关(只写 --username 不给值)与未传都归一为空值
14
- if (value === undefined || value === null || value === true)
15
- return '';
16
- return String(value).trim();
17
- }
18
- /**
19
- * 拼 4 个恒定 query。
20
- *
21
- * 后端签名为 `executeQueryDsl(@RequestBody DslQueryVo, @RequestParam confKey,
22
- * @RequestParam confGroup, @RequestParam username, @RequestParam startDate, Employee)`,
23
- * `@RequestParam` 的 required 校验看「键是否存在」而非「值是否非空」——缺键即失败、空值合法。
24
- * 早前「空串就不带」会把最常见的情况(问句里没有人名/日期)直接打成 400/500。
25
- */
26
- function buildQueryString(input) {
27
- return '?' + QUERY_PARAM_ALIASES
28
- .map(([name, flag]) => {
29
- const snake = flag.replace(/-/g, '_');
30
- const raw = argStr(input, name) || argStr(input, snake) || argStr(input, flag);
31
- return `${encodeURIComponent(name)}=${encodeURIComponent(raw)}`;
32
- })
33
- .join('&');
34
- }
3
+ import { readJsonArg, renderTable, scanTips, tipsLines } from './shared.js';
35
4
  /**
36
5
  * DSL 直查:`POST /api/dw/dsl/executeQueryDsl`。
37
6
  *
38
- * 这是整条问数链路的底层入口,`ds list/chart/stat/count` 都是它的封装。技能里有 9 条现成调用,
39
- * 参数形式(`--conn/--model/--schema/--dsl`)必须逐字保留。
7
+ * 与 `ds list/chart/stat/count` 是独立通道:本命令发送 DslQuery,后者分别请求数据源的 get*Datas 接口。
40
8
  */
41
9
  export async function executeQuery(input, host) {
42
10
  const conn = needArg(input, 'conn');
43
11
  const model = needArg(input, 'model');
44
12
  const schema = needArg(input, 'schema');
45
13
  const dslRaw = needArg(input, 'dsl');
14
+ const questionContextRaw = needArg(input, 'question_context', 'question-context');
46
15
  const dslQuery = readJsonArg(dslRaw, '--dsl');
16
+ const questionContext = readJsonArg(questionContextRaw, '--question-context');
47
17
  const body = {
48
18
  connId: conn,
49
19
  model,
50
20
  schema,
51
21
  tableId: input.table_id || input.tableId || '',
52
22
  dslQuery,
23
+ questionContext,
53
24
  };
54
- if (input.debug !== undefined && input.debug !== null && input.debug !== '') {
55
- const flag = String(input.debug).toLowerCase();
56
- if (flag === 'true' || flag === '1')
57
- body.debug = true;
58
- else if (flag === 'false' || flag === '0')
59
- body.debug = false;
60
- else
61
- throw dataValidationError('debug_invalid', `--debug 值必须为 true 或 false(当前: ${input.debug})`);
62
- }
63
25
  const response = await host.request({
64
26
  method: 'POST',
65
- path: `/api/dw/dsl/executeQueryDsl${buildQueryString(input)}`,
27
+ path: '/api/dw/dsl/executeQueryDsl',
66
28
  body,
67
29
  headers: { 'Content-Type': 'application/json;charset=utf-8' },
68
30
  });
@@ -74,12 +36,27 @@ export async function executeQuery(input, host) {
74
36
  }
75
37
  }
76
38
  const payload = response?.data;
77
- const rows = Array.isArray(payload) ? payload : (payload && Array.isArray(payload.records) ? payload.records : []);
39
+ const rows = Array.isArray(payload)
40
+ ? payload
41
+ : Array.isArray(payload?.dataList)
42
+ ? payload.dataList
43
+ : Array.isArray(payload?.records)
44
+ ? payload.records
45
+ : [];
46
+ const tips = scanTips(response);
78
47
  const lines = [];
79
48
  if (payload && !Array.isArray(payload) && payload.sql)
80
49
  lines.push(`SQL: ${payload.sql}`);
81
50
  if (String(code) !== '200' && code !== undefined)
82
51
  lines.push(`code=${code} msg=${response?.msg || ''}`);
83
- lines.push(rows.length ? renderTable(`结果 ${rows.length} 行`, rows) : '(空:0 行)');
52
+ // 后端正常保证两类提示互斥;异常响应同时出现时,人读输出以 tipTimeout 为最高优先级。
53
+ lines.push(...tipsLines(tips.tipTimeout ? {
54
+ tipTimeout: true,
55
+ tipTimeoutMsg: tips.tipTimeoutMsg,
56
+ } : tips));
57
+ if (tips.tipTimeout)
58
+ lines.push('(平台未执行数据返回:请按上述提示收窄时间范围)');
59
+ else
60
+ lines.push(rows.length ? renderTable(`结果 ${rows.length} 行`, rows) : '(空:0 行)');
84
61
  return { data: response, text: lines.join('\n') };
85
62
  }
@@ -52,8 +52,10 @@ export function assertPath(requestPath) {
52
52
  }
53
53
  if (!requestPath.startsWith('/api/fna/')
54
54
  && !requestPath.startsWith('/api/app/fna/')
55
- && !requestPath.startsWith('/api/secondev/fna/')) {
56
- throw fnaValidationError('path_not_allowed', 'FNA 费控中心只能调用 /api/fna/、/api/app/fna/ 或 /api/secondev/fna/ 路径');
55
+ && !requestPath.startsWith('/api/secondev/fna/')
56
+ // AI 规则预审挂在 ai/application 下(非 fna 命名空间),只放行该 Controller 的 rule/check 路径
57
+ && !requestPath.startsWith('/api/ai/application/rule/check/')) {
58
+ throw fnaValidationError('path_not_allowed', 'FNA 费控中心只能调用 /api/fna/、/api/app/fna/、/api/secondev/fna/ 或 /api/ai/application/rule/check/ 路径');
57
59
  }
58
60
  }
59
61
  function omitEmptyQueryValues(query) {
@@ -1,11 +1,12 @@
1
1
  import { fnaOperationDefinitions } from './operations/registry.js';
2
2
  /**
3
3
  * FNA 费控中心(齐业成)模块禁用/暂缓边界。
4
- * 12 个源接口全部落地;以下几类能力不在本 CLI,写入 manifest 供 Agent 判断,
4
+ * 13 个源接口全部落地;以下几类能力不在本 CLI,写入 manifest 供 Agent 判断,
5
5
  * 不得编造 operation 或绕过 CLI 直连接口:
6
6
  * - 姓名/流程名 → employeeId/workflowId 的人员与流程解析不在本模块;
7
7
  * - 借款「确认已还 confirmRepay」、核销明细等页面按钮能力未随源资料提供接口,未实现;
8
- * - 报销报表 AI 问答只暴露自然语言问题,不接受也不回传 AI 生成的 SQL。
8
+ * - 报销报表 AI 问答只暴露自然语言问题,不接受也不回传 AI 生成的 SQL;
9
+ * - AI 规则预审只执行流程配置的规则,不支持增删改规则配置,也不回传 formDataList 明细。
9
10
  */
10
11
  const FNA_WITHHELD = [
11
12
  {
@@ -20,6 +21,14 @@ const FNA_WITHHELD = [
20
21
  name: 'fna.expense.chart.raw.sql',
21
22
  reason: '报销报表 AI 问答由服务端生成 SQL 并做租户隔离改写与安全校验;CLI 只接受 userInput,不暴露、不回传 SQL,也不允许调用方绕过安全校验自写 SQL。',
22
23
  },
24
+ {
25
+ name: 'fna.audit.rule.configure',
26
+ reason: 'AI 规则预审只按流程已配置的规则执行(可传 ruleList/settingId 指定),不支持新增、编辑、删除规则配置或规则设置;源资料未提供规则维护接口。',
27
+ },
28
+ {
29
+ name: 'fna.audit.formdata.raw',
30
+ reason: 'aiCheckAudit 返回的 data.formDataList 含完整主表/明细/发票数据,体积大且含业务敏感字段;CLI 只回传 id/refId/title 摘要,不把整段表单数据暴露给 Agent。',
31
+ },
23
32
  ];
24
33
  function buildOperations() {
25
34
  return fnaOperationDefinitions().map((definition) => ({
@@ -35,12 +44,12 @@ function buildOperations() {
35
44
  export const fnaManifest = {
36
45
  schemaVersion: 1,
37
46
  name: 'fna',
38
- title: '泛微E10齐业成费控中心(预算查询/费用中心/报销报表/借款管理/发票核销)',
39
- version: '0.1.1',
47
+ title: '泛微E10齐业成费控中心(预算查询/费用中心/报销报表/AI规则预审/借款管理/发票核销)',
48
+ version: '0.1.2',
40
49
  host: 'e10-fna',
41
50
  status: 'builtin',
42
51
  sourceSkill: 'weaver-e10-qiyecheng',
43
- capabilities: ['budget', 'expense', 'expense-chart', 'loan', 'invoice-writeoff'],
52
+ capabilities: ['budget', 'expense', 'expense-chart', 'audit', 'loan', 'invoice-writeoff'],
44
53
  operations: buildOperations(),
45
54
  withheldOperations: FNA_WITHHELD,
46
55
  };