weaver-work-cli 0.1.47 → 0.1.49

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 (229) hide show
  1. package/dist/chunks/{archive-oa-BBDP7AKJ.js → archive-oa-57R2FYHV.js} +565 -17
  2. package/dist/chunks/{attachment-content-MCXQBD6N.js → attachment-content-MU2LPI5P.js} +3 -3
  3. package/dist/chunks/{chunk-J2VEB5K3.js → chunk-2BQESR2U.js} +2 -2
  4. package/dist/chunks/{chunk-727FH2NI.js → chunk-2IGZUMNG.js} +15 -2
  5. package/dist/chunks/{chunk-IP4CWQCF.js → chunk-3NV2ETZR.js} +8 -8
  6. package/dist/chunks/{chunk-OXHHJWNC.js → chunk-3X7VOSBA.js} +1 -1
  7. package/dist/chunks/chunk-5QYE52LG.js +223 -0
  8. package/dist/chunks/{chunk-IRMIEDXN.js → chunk-6GWU63YF.js} +1 -1
  9. package/dist/chunks/{chunk-3YV7PKRL.js → chunk-6QYNE6HE.js} +12 -212
  10. package/dist/chunks/{chunk-Q4OYAQYH.js → chunk-72MI3MBX.js} +4 -0
  11. package/dist/chunks/{chunk-AD46OMQK.js → chunk-BRRW7CWA.js} +121 -46
  12. package/dist/chunks/{chunk-76H3IKH6.js → chunk-D2QRZUW4.js} +221 -37
  13. package/dist/chunks/{chunk-GSZTA43P.js → chunk-EJVA5ZVB.js} +2 -2
  14. package/dist/chunks/{chunk-4RWS2YYL.js → chunk-GEOMANP7.js} +3 -3
  15. package/dist/chunks/{chunk-LIEQJIGM.js → chunk-GR76ZDDX.js} +0 -3
  16. package/dist/chunks/{chunk-O6CMPO65.js → chunk-IW7A2IQY.js} +16 -146
  17. package/dist/chunks/chunk-JEQHNNSS.js +158 -0
  18. package/dist/chunks/{chunk-6V5ZPKHV.js → chunk-K3BT54CU.js} +4 -4
  19. package/dist/chunks/{chunk-6AXKWFKG.js → chunk-KV5SOWMS.js} +4 -4
  20. package/dist/chunks/{chunk-JB34OE7R.js → chunk-NBEWUR7L.js} +1 -1
  21. package/dist/chunks/{chunk-PSOMGA3U.js → chunk-ZKEUGS2U.js} +36 -7
  22. package/dist/chunks/{conflict-H7EHQXYY.js → conflict-6347A7YK.js} +2 -2
  23. package/dist/chunks/{contract-3QLAGYQL.js → contract-N6P2HIIE.js} +425 -187
  24. package/dist/chunks/{create-flow-VRVJEOBX.js → create-flow-7WG7LVX5.js} +6 -6
  25. package/dist/chunks/data-QO7QWOIV.js +2525 -0
  26. package/dist/chunks/{ehr-SH2LM3NK.js → ehr-XI4BIVR2.js} +16 -5
  27. package/dist/chunks/{employee-NOHNXC46.js → employee-DR5Y64TI.js} +2 -1
  28. package/dist/chunks/{env-66FPSJDV.js → env-LHRKSLG6.js} +2 -2
  29. package/dist/chunks/{factory-UH2TZBVA.js → factory-2H7Z4RWJ.js} +1 -1
  30. package/dist/chunks/{group-chat-CAKMMV7K.js → group-chat-EW6PNDDT.js} +3 -3
  31. package/dist/chunks/{hrm-UNKCCCGP.js → hrm-YGIR3HGF.js} +4 -2
  32. package/dist/chunks/{im-NJB7ZYMH.js → im-3RCNL5GT.js} +107 -1
  33. package/dist/chunks/{invoice-UEAHSYAE.js → invoice-FXWH5GPO.js} +2 -71
  34. package/dist/chunks/{lazy-dispatch-25XGTXLM.js → lazy-dispatch-XSAHDK6Z.js} +3 -3
  35. package/dist/chunks/{meeting-VTBFW4HI.js → meeting-N2FQBHXI.js} +10 -10
  36. package/dist/chunks/org-NFE7X7FK.js +12 -0
  37. package/dist/chunks/{reception-5WITA44R.js → reception-MYOKJULO.js} +905 -116
  38. package/dist/chunks/{recruit-stage-CAKZTUA7.js → recruit-stage-FKWS5UQF.js} +118 -29
  39. package/dist/chunks/{registry-VWXWPVAG.js → registry-3UGIWH53.js} +4 -2
  40. package/dist/chunks/{registry-AQVGHUM6.js → registry-7VZ6YJUF.js} +2 -2
  41. package/dist/chunks/{registry-PVUZQDDQ.js → registry-BUTEDK3C.js} +1 -1
  42. package/dist/chunks/{registry-JVQBLFQ5.js → registry-CKUVBS53.js} +10 -10
  43. package/dist/chunks/{room-recommend-5U55FMXZ.js → room-recommend-MBCYENQ2.js} +4 -4
  44. package/dist/chunks/{schedule-IDETODCA.js → schedule-5IFMCXME.js} +4 -4
  45. package/dist/chunks/{workflow-BSYT5TGL.js → workflow-2TRU2ZSP.js} +5 -5
  46. package/dist/core/refs.js +19 -2
  47. package/dist/index.js +20 -15
  48. package/dist/shortcuts/archive-oa/constants.js +42 -0
  49. package/dist/shortcuts/archive-oa/host.js +2 -2
  50. package/dist/shortcuts/archive-oa/index.js +38 -0
  51. package/dist/shortcuts/archive-oa/operations/borrow-car.js +117 -3
  52. package/dist/shortcuts/archive-oa/operations/contract-modules.js +57 -0
  53. package/dist/shortcuts/archive-oa/operations/contract.js +23 -8
  54. package/dist/shortcuts/archive-oa/operations/my-borrow-contract.js +271 -0
  55. package/dist/shortcuts/archive-oa/operations/registry.js +9 -4
  56. package/dist/shortcuts/archive-oa/operations/shared.js +41 -5
  57. package/dist/shortcuts/contract/index.js +9 -1
  58. package/dist/shortcuts/contract/manifest.js +14 -2
  59. package/dist/shortcuts/contract/operations/card.js +231 -0
  60. package/dist/shortcuts/contract/operations/registry.js +2 -0
  61. package/dist/shortcuts/contract/operations/review.js +16 -5
  62. package/dist/shortcuts/contract/operations/summary.js +25 -17
  63. package/dist/shortcuts/data/errors.js +64 -0
  64. package/dist/shortcuts/data/host.js +140 -0
  65. package/dist/shortcuts/data/index.js +429 -0
  66. package/dist/shortcuts/data/manifest.js +133 -0
  67. package/dist/shortcuts/data/operations/attend.js +62 -0
  68. package/dist/shortcuts/data/operations/conf.js +384 -0
  69. package/dist/shortcuts/data/operations/ds.js +686 -0
  70. package/dist/shortcuts/data/operations/field.js +68 -0
  71. package/dist/shortcuts/data/operations/index.js +65 -0
  72. package/dist/shortcuts/data/operations/module.js +383 -0
  73. package/dist/shortcuts/data/operations/noun.js +102 -0
  74. package/dist/shortcuts/data/operations/query.js +85 -0
  75. package/dist/shortcuts/data/operations/scene.js +235 -0
  76. package/dist/shortcuts/data/operations/shared.js +279 -0
  77. package/dist/shortcuts/ehr/operations/recruit-write.js +22 -5
  78. package/dist/shortcuts/ehr/recruit-stage/operations/interview-arrange.js +28 -12
  79. package/dist/shortcuts/ehr/recruit-stage/operations/resume-import.js +21 -13
  80. package/dist/shortcuts/ehr/recruit-stage/shared.js +90 -8
  81. package/dist/shortcuts/im/index.js +128 -0
  82. package/dist/shortcuts/im/operations/session.js +6 -0
  83. package/dist/shortcuts/index.js +5 -0
  84. package/dist/shortcuts/invoice/host.js +0 -3
  85. package/dist/shortcuts/invoice/manifest.js +0 -1
  86. package/dist/shortcuts/invoice/operations/reim-subsidy.js +1 -71
  87. package/dist/shortcuts/meeting/operations/eb/conflict.js +26 -3
  88. package/dist/shortcuts/meeting/operations/eb/continuation-alias.js +63 -0
  89. package/dist/shortcuts/meeting/operations/eb/create-flow.js +71 -12
  90. package/dist/shortcuts/meeting/operations/eb/factory.js +5 -3
  91. package/dist/shortcuts/meeting/operations/eb/member-expand.js +200 -0
  92. package/dist/shortcuts/meeting/operations/registry.js +2 -0
  93. package/dist/shortcuts/reception/constants.js +11 -0
  94. package/dist/shortcuts/reception/host.js +33 -1
  95. package/dist/shortcuts/reception/index.js +22 -1
  96. package/dist/shortcuts/reception/manifest.js +55 -2
  97. package/dist/shortcuts/reception/operations/ask.js +37 -1
  98. package/dist/shortcuts/reception/operations/compose.js +124 -3
  99. package/dist/shortcuts/reception/operations/doc.js +59 -0
  100. package/dist/shortcuts/reception/operations/docrender.js +25 -1
  101. package/dist/shortcuts/reception/operations/leads.js +245 -0
  102. package/dist/shortcuts/reception/operations/markdown.js +22 -0
  103. package/dist/shortcuts/reception/operations/panels.js +84 -21
  104. package/dist/shortcuts/reception/operations/registry.js +2 -0
  105. package/dist/shortcuts/reception/operations/render.js +76 -3
  106. package/dist/shortcuts/reception/operations/restaurant-rooms.js +118 -0
  107. package/dist/shortcuts/reception/operations/restaurant.js +264 -0
  108. package/dist/shortcuts/reception/operations/restaurantrooms.js +42 -0
  109. package/dist/shortcuts/reception/operations/schedule.js +7 -1
  110. package/dist/shortcuts/reception/upload.js +22 -6
  111. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +28 -12
  112. package/dist/shortcuts/recruit-stage/operations/resume-import.js +21 -13
  113. package/dist/shortcuts/recruit-stage/shared.js +99 -14
  114. package/docs/SKILL.md +1 -0
  115. package/docs/_catalog.md +3 -0
  116. package/docs/archive-oa.md +4 -2
  117. package/docs/data.md +149 -0
  118. package/docs/reception.md +59 -5
  119. package/package.json +1 -1
  120. package/scripts/check-skill-sync.mjs +188 -0
  121. package/scripts/package-skill.mjs +17 -3
  122. package/skill-template/business-info.json +23 -0
  123. package/skill-template/domains/archive-oa.md +2 -1
  124. package/skill-template/domains/data.md +15 -0
  125. package/skill-template/master-skill-template.md +1 -0
  126. package/skill-template/skill-template.md +1 -0
  127. package/skills/weaver-e10-archive-oa/SKILL.md +35 -7
  128. package/skills/weaver-e10-archive-oa/references/borrow-car.md +32 -7
  129. package/skills/weaver-e10-archive-oa/references/contract-search.md +105 -4
  130. package/skills/weaver-e10-archive-oa/references/disabled-capabilities.md +2 -2
  131. package/skills/weaver-e10-archive-oa/references/my-borrow-contract.md +97 -0
  132. package/skills/weaver-e10-archive-oa/references/my-borrow.md +6 -1
  133. package/skills/weaver-e10-archive-oa/references/qys-contract-search.md +48 -2
  134. package/skills/weaver-e10-calendar/SKILL.md +1 -1
  135. package/skills/weaver-e10-calendar/references/calendar-query.md +1 -1
  136. package/skills/weaver-e10-calendar/references/calendar-write.md +9 -9
  137. package/skills/weaver-e10-cowork/SKILL.md +9 -6
  138. package/skills/weaver-e10-data/SKILL.md +118 -0
  139. package/skills/weaver-e10-data/references/config-center.md +90 -0
  140. package/skills/weaver-e10-data/references/datasource.md +136 -0
  141. package/skills/weaver-e10-data/references/scene-and-misc.md +82 -0
  142. package/skills/weaver-e10-jinchengda/SKILL.md +10 -7
  143. package/skills/weaver-e10-jinchengda/references/contract-action-card-template.html +17 -0
  144. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +263 -35
  145. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +8 -5
  146. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +1 -1
  147. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +175 -22
  148. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  149. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +1 -1
  150. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +1 -1
  151. package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +124 -19
  152. package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +2 -2
  153. package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +4 -4
  154. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +6 -0
  155. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  156. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +1 -1
  157. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +1 -1
  158. package/skills/weaver-e10-jinchengda/references/contract-risk-report-template.html +178 -0
  159. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
  160. package/skills/weaver-e10-jinchengda/references/orchestration.md +7 -7
  161. package/skills/weaver-e10-jinchengda/scripts/plan_actions.py +279 -0
  162. package/skills/weaver-e10-jinchengda/scripts/render_action_card.py +450 -0
  163. package/skills/weaver-e10-jinchengda/scripts/render_risk_report.py +358 -0
  164. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +505 -0
  165. package/skills/weaver-e10-jucailin/SKILL.md +7 -4
  166. package/skills/weaver-e10-jucailin/references/recruit-create.md +3 -2
  167. package/skills/weaver-e10-jucailin/references/recruit-read.md +2 -1
  168. package/skills/weaver-e10-jucailin/references/recruit-stage-ops.md +3 -3
  169. package/skills/weaver-e10-jucailin/references/safety-boundaries.md +30 -2
  170. package/skills/weaver-e10-mail/SKILL.md +17 -4
  171. package/skills/weaver-e10-meeting/SKILL.md +129 -412
  172. package/skills/weaver-e10-meeting/references/create-flow.md +188 -0
  173. package/skills/weaver-e10-meeting/references/create-guardrails.md +234 -0
  174. package/skills/weaver-e10-meeting/references/pitfalls.md +40 -0
  175. package/skills/weaver-e10-reception-flow/SKILL.md +77 -19
  176. package/skills/weaver-e10-reception-flow/data/fields-snapshot.json +628 -26
  177. package/skills/weaver-e10-reception-flow/references/fields-snapshot.md +96 -26
  178. package/skills/weaver-e10-reception-flow/references/guide.md +4 -3
  179. package/skills/weaver-e10-reception-flow/scripts/render.py +84 -3
  180. package/skills/weaver-e10-recruit-stage/SKILL.md +45 -12
  181. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +78 -8
  182. package/skills/weaver-e10-recruit-stage/references/position-templates.md +5 -0
  183. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +1 -1
  184. package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +1 -1
  185. package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +40 -11
  186. package/skills/weaver-e10-recruit-stage/references/recruit-list-candidate.md +1 -1
  187. package/skills/weaver-e10-recruit-stage/references/recruit-list-interview.md +1 -1
  188. package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +1 -1
  189. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +16 -0
  190. package/skills/weaver-e10-recruit-stage/references/recruit-resume-parse.md +1 -1
  191. package/skills/weaver-e10-recruit-stage/references/recruit-search-candidate.md +1 -1
  192. package/skills/weaver-e10-recruit-stage/references/recruit-urge-feedback.md +1 -1
  193. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +169 -0
  194. package/skills/weaver-e10-shijingran/SKILL.md +6 -2
  195. package/skills/weaver-e10-shijingran/references/source-manifest.json +5 -4
  196. package/skills/weaver-e10-workflow/SKILL.md +1 -1
  197. package/skills/weaver-e10-yepiaotong/SKILL.md +8 -4
  198. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +1 -1
  199. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +1 -1
  200. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +2 -2
  201. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +1 -1
  202. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +1 -1
  203. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +1 -0
  204. package/skills/weaver-e10-yimiaoban/SKILL.md +2 -1
  205. package/skills/weaver-e10-yimiaoban/references/msg-write.md +32 -0
  206. package/skills/weaver-e10-yimiaoban/references/session-sysmsg.md +3 -0
  207. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +11 -11
  208. package/dist/chunks/{ebuilder-form-GWDTKEI2.js → ebuilder-form-CBYI6CQ6.js} +3 -3
  209. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-README.md +0 -0
  210. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-SKILL.md +0 -0
  211. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-openai.yaml +0 -0
  212. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-position-templates.md +0 -0
  213. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-arrange-interview.md +0 -0
  214. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-capability-check.md +0 -0
  215. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-check-install.md +0 -0
  216. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-detail-process.md +0 -0
  217. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-edit-interview-feedback.md +0 -0
  218. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-jd-create.md +0 -0
  219. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-jd-template.md +0 -0
  220. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-list-candidate.md +0 -0
  221. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-list-interview.md +0 -0
  222. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-match-candidates.md +0 -0
  223. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-output-links.md +0 -0
  224. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-creator.md +0 -0
  225. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resolve-metadata.md +0 -0
  226. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resume-import.md +0 -0
  227. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-resume-parse.md +0 -0
  228. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-search-candidate.md +0 -0
  229. /package/{skills → docs/legacy}/weaver-e10-jucailin/archive/LEGACY-recruit-urge-feedback.md +0 -0
@@ -0,0 +1,68 @@
1
+ import { needArg } from '../host.js';
2
+ import { readJsonArg, renderTable } from './shared.js';
3
+ /**
4
+ * 关联字段翻译(`name2id`)与下拉选项字典(`options`)。
5
+ *
6
+ * ⚠️ 与 `ds fields` 的区别(Agent 最容易选错的一对):
7
+ * - `data field name2id` —— 把**名称**翻译成**字段值 id**(浏览按钮类字段);
8
+ * - `data ds fields` —— 取一张表的**字段元数据**(字段名/类型/是否主键)。
9
+ *
10
+ * `id2name` 已在本迁移中删除:技能里 19 处提及全是禁令(打的是 `/api/bcw/test/testRemoteBrowser`
11
+ * 探针接口,已停用),且字段值显示映射改走 `field options` + `ds fields`。
12
+ */
13
+ function customParamOf(input) {
14
+ if (input.form_param)
15
+ return { formParam: input.form_param };
16
+ if (input.eb_browser_param)
17
+ return { ebBrowserForEditParam: readJsonArg(input.eb_browser_param, '--eb-browser-param') };
18
+ if (input.property_type)
19
+ return { propertyType: input.property_type };
20
+ return {};
21
+ }
22
+ /** 名称 → id 候选(浏览按钮的自动补全接口)。 */
23
+ export async function fieldName2id(input, host) {
24
+ const module = needArg(input, 'module');
25
+ const type = needArg(input, 'type');
26
+ const name = needArg(input, 'name');
27
+ const body = { newly: 1, searchValue: name, ...customParamOf(input) };
28
+ const response = await host.request({
29
+ method: 'POST',
30
+ path: `/api/${module}/common/browser/complete/${type}`,
31
+ body,
32
+ operation: 'field.name2id',
33
+ });
34
+ const rows = response?.data?.data || [];
35
+ if (!rows.length)
36
+ return { data: response, text: '(未匹配到名称对应 ID)' };
37
+ const rendered = rows.map((row) => ({ id: row.id, name: row.name ?? row.title ?? '' }));
38
+ return {
39
+ data: response,
40
+ text: renderTable(`name→id 候选 ${rows.length} 条`, rendered, ['id', 'name']),
41
+ };
42
+ }
43
+ /**
44
+ * Select / Radio / Checkbox 字段的选项值字典:`GET /api/ebuilder/common/ds/options`。
45
+ *
46
+ * 用途:字段列存 `value_key` 时,用本命令取 `{id,name,archive}` 完成显示映射
47
+ * (替代已停用的 id2name / 选项字典物理表直查)。RULES.md §4.5 规定选项类字段一律走这里。
48
+ */
49
+ export async function fieldOptions(input, host) {
50
+ const fieldName = needArg(input, 'field_name', 'field-name');
51
+ const objId = needArg(input, 'obj_id', 'obj-id');
52
+ const groupId = needArg(input, 'group');
53
+ const sourceType = String(input.source_type || 'LOGIC');
54
+ const response = await host.request({
55
+ method: 'GET',
56
+ path: '/api/ebuilder/common/ds/options',
57
+ query: { fieldName, objId, sourceType, groupId },
58
+ operation: 'field.options',
59
+ });
60
+ const rows = Array.isArray(response?.data) ? response.data : [];
61
+ if (!rows.length) {
62
+ return {
63
+ data: response,
64
+ text: `(空:该字段无选项或参数不匹配) code=${response?.code ?? ''} msg=${response?.msg || ''}`,
65
+ };
66
+ }
67
+ return { data: response, text: renderTable(`选项清单 ${rows.length} 项`, rows, ['id', 'name', 'archive']) };
68
+ }
@@ -0,0 +1,65 @@
1
+ import { dataValidationError } from '../errors.js';
2
+ import { executeQuery } from './query.js';
3
+ import { dsChart, dsCount, dsDescribe, dsFields, dsFieldsDsl, dsFind, dsGroups, dsList, dsStat, dsTables, } from './ds.js';
4
+ import { attendStatis } from './attend.js';
5
+ import { fieldName2id, fieldOptions } from './field.js';
6
+ import { nounList, nounScope } from './noun.js';
7
+ import { confAdd, confAddFile, confBatch, confBatchFile, confDelete, confGet, confGroup, confGroupFile, confResolve, confResolveFile, confUpdate, } from './conf.js';
8
+ import { moduleCall } from './module.js';
9
+ import { sceneGroups, sceneItems, sceneSearch } from './scene.js';
10
+ const DEFINITIONS = [
11
+ { name: 'data.dsl.query', summary: '直接执行 DSL 查询(executeQueryDsl),ds list/chart/stat/count 的底层入口', capability: 'dsl', handler: executeQuery, command: 'query' },
12
+ { name: 'data.ds.groups', summary: '内置数据源分组清单(仅用于 ds find 的默认扫描候选集)', capability: 'discovery', handler: dsGroups, command: 'ds groups' },
13
+ { name: 'data.ds.find', summary: '按关键词跨分组找表(进程内并发扇出 + 本地过滤 + 路由建议)', capability: 'discovery', handler: dsFind, command: 'ds find' },
14
+ { name: 'data.ds.describe', summary: '一次并发取回字段元数据 + 词库,并给出关联字段/通道提示', capability: 'discovery', handler: dsDescribe, command: 'ds describe' },
15
+ { name: 'data.ds.tables', summary: '列某个分组下的数据集(表)清单', capability: 'metadata', handler: dsTables, command: 'ds tables' },
16
+ { name: 'data.ds.fields', summary: '取数据集字段元数据(/api/ebuilder/common/ds/fields)', capability: 'metadata', handler: dsFields, command: 'ds fields' },
17
+ { name: 'data.ds.fields-dsl', summary: '取 DSL 口径字段元数据(/ds/fieldsForDSL,含 dataKey / formTableId)', capability: 'metadata', handler: dsFieldsDsl, command: 'ds fields-dsl' },
18
+ { name: 'data.ds.list', summary: '明细列表取数(getListDatas)', capability: 'fetch', handler: dsList, command: 'ds list' },
19
+ { name: 'data.ds.chart', summary: '分组聚合取数(getChartDatas)', capability: 'fetch', handler: dsChart, command: 'ds chart' },
20
+ { name: 'data.ds.stat', summary: '统计字段取数(getStatDatas)', capability: 'fetch', handler: dsStat, command: 'ds stat' },
21
+ { name: 'data.ds.count', summary: '计数(getCountData)', capability: 'fetch', handler: dsCount, command: 'ds count' },
22
+ { name: 'data.noun.list', summary: '按 skill 取词库(ChatBI 名词解释)', capability: 'lexicon', handler: nounList, command: 'noun list' },
23
+ { name: 'data.noun.scope', summary: '按数据集生效范围批量取词库(getChatBiDocByScopeId)', capability: 'lexicon', handler: nounScope, command: 'noun scope' },
24
+ { name: 'data.field.name2id', summary: '名称 → 字段值 id 候选(浏览按钮类字段)', capability: 'field', handler: fieldName2id, command: 'field name2id' },
25
+ { name: 'data.field.options', summary: 'Select/Radio/Checkbox 选项值字典(id↔name)', capability: 'field', handler: fieldOptions, command: 'field options' },
26
+ { name: 'data.conf.get', summary: '按 confKey 取单条配置(confType 由前缀推导或 --type 指定)', capability: 'config', handler: confGet, command: 'conf get' },
27
+ { name: 'data.conf.batch', summary: '批量取配置(批量接口不可用时自动降级逐条单查)', capability: 'config', handler: confBatch, command: 'conf batch' },
28
+ { name: 'data.conf.batch-file', summary: '按文件批量取配置(逐条单查,跳过批量接口)', capability: 'config', handler: confBatchFile, command: 'conf batch-file' },
29
+ { name: 'data.conf.group', summary: '按 confType + confGroup 批量取回整组配置', capability: 'config', handler: confGroup, command: 'conf group' },
30
+ { name: 'data.conf.group-file', summary: '按文件批量取多个分组的配置', capability: 'config', handler: confGroupFile, command: 'conf group-file' },
31
+ { name: 'data.conf.resolve', summary: '把文本里的 #{KEY} 占位符替换为配置值', capability: 'config', handler: confResolve, command: 'conf resolve' },
32
+ { name: 'data.conf.resolve-file', summary: '按文件替换 #{KEY} 占位符', capability: 'config', handler: confResolveFile, command: 'conf resolve-file' },
33
+ { name: 'data.conf.add', summary: '新增配置(已存在默认跳过,--force 重建)', capability: 'config', handler: confAdd, command: 'conf add' },
34
+ { name: 'data.conf.add-file', summary: '按文件批量新增配置(已存在的跳过)', capability: 'config', handler: confAddFile, command: 'conf add-file' },
35
+ { name: 'data.conf.update', summary: '更新配置的 value / name / attrs', capability: 'config', handler: confUpdate, command: 'conf update' },
36
+ { name: 'data.conf.delete', summary: '删除配置', capability: 'config', handler: confDelete, command: 'conf delete' },
37
+ { name: 'data.scene.groups', summary: '场景分组骨架(getSceneGroups)', capability: 'scene', handler: sceneGroups, command: 'scene groups' },
38
+ { name: 'data.scene.items', summary: '组内条目(接口 / 数据源,含取数通道参数)', capability: 'scene', handler: sceneItems, command: 'scene items' },
39
+ { name: 'data.scene.search', summary: '关键词候选召回(后端 keyword 优先,本地打分兜底)', capability: 'scene', handler: sceneSearch, command: 'scene search' },
40
+ { name: 'data.module.call', summary: '按配置中心的接口定义组参并调用(confAttrs 驱动)', capability: 'module', handler: moduleCall, command: 'module call' },
41
+ { name: 'data.attend.statis', summary: '考勤假期余额(getAttendInfoStatis;年假/带薪病假/带薪事假)', capability: 'attend', handler: attendStatis, command: 'attend statis' },
42
+ ];
43
+ const REGISTRY = new Map(DEFINITIONS.map((definition) => [definition.name, definition]));
44
+ export function operationNames() {
45
+ return DEFINITIONS.map((definition) => definition.name);
46
+ }
47
+ export function operationDefinitions() {
48
+ return DEFINITIONS;
49
+ }
50
+ export function findOperation(name) {
51
+ return REGISTRY.get(name);
52
+ }
53
+ /**
54
+ * 执行一个 operation。
55
+ *
56
+ * 便捷命令(`data ds count`)与统一入口(`data run data.ds.count`)**共用这一份实现**,
57
+ * 区别只在参数怎么来:前者由 commander 的 flags 翻译成对象,后者直接反序列化 `--input-json`。
58
+ */
59
+ export async function executeDataOperation(name, input, host) {
60
+ const definition = REGISTRY.get(name);
61
+ if (!definition) {
62
+ throw dataValidationError('unknown_operation', `未知 operation:${name}。可用值见 \`weaver-work-cli data schema\`(共 ${DEFINITIONS.length} 个)`);
63
+ }
64
+ return definition.handler(input, host);
65
+ }
@@ -0,0 +1,383 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dataApiError, dataHrmBlocked, dataPermissionBlocked, dataValidationError } from '../errors.js';
3
+ import { attributesOf, confGetData } from './conf.js';
4
+ import { parseJsonSafe, readJsonArg, readListArg, renderTable, scanTips, tipFields, tipsLines } from './shared.js';
5
+ /**
6
+ * 模块配置接口调用(配置中心驱动)。
7
+ *
8
+ * 定位:**已确定「哪个模块的哪条具体接口」之后**,一条命令完成取数:
9
+ * 精取该条 confAttrs → 按 http_method / input_params 组参 → 发请求 → 按外层结构提取精简结果。
10
+ *
11
+ * 与技能自带 Python 调用器 `call_module.py` 等价(参数名、退出码、提取口径全对齐),
12
+ * 区别是本命令复用 CLI 的登录态与 conf 通道、全程零临时文件。
13
+ */
14
+ const HRM_PATTERNS = ['/api/hrm/', '/api/bs/hrm/', '/api/app/hrm/'];
15
+ const PERM_WORDS = ['没有权限', '无权限', '权限不足', '未授权', '无权访问', '无查询权限'];
16
+ const INVOICE_TOKEN_PATH = '/api/inc/proxy/getToken?appType=1';
17
+ /** 业务参数 → query 串(数组按多值展开、对象 JSON 化,对齐 `urlencode(..., doseq=True)`)。 */
18
+ function queryStringOf(obj) {
19
+ const params = new URLSearchParams();
20
+ for (const [key, value] of Object.entries(obj || {})) {
21
+ if (value === undefined || value === null)
22
+ continue;
23
+ if (Array.isArray(value)) {
24
+ for (const item of value) {
25
+ params.append(key, item !== null && typeof item === 'object' ? JSON.stringify(item) : String(item));
26
+ }
27
+ }
28
+ else {
29
+ params.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
30
+ }
31
+ }
32
+ return params.toString();
33
+ }
34
+ /** 按已知外层形态找列表:datajson.data / datajson.datas / data.data / data.records / data / datas / list。 */
35
+ function rowsOf(obj) {
36
+ const numish = (value) => (typeof value === 'number' || typeof value === 'string' ? value : null);
37
+ if (Array.isArray(obj))
38
+ return { rows: obj, total: null };
39
+ if (!obj || typeof obj !== 'object')
40
+ return { rows: null, total: null };
41
+ for (const key of ['datajson', 'data', 'result']) {
42
+ const value = obj[key];
43
+ if (Array.isArray(value))
44
+ return { rows: value, total: null };
45
+ if (value && typeof value === 'object') {
46
+ for (const inner of ['data', 'datas', 'records', 'list', 'items', 'rows']) {
47
+ if (Array.isArray(value[inner]))
48
+ return { rows: value[inner], total: numish(value.total) };
49
+ }
50
+ return { rows: null, total: null };
51
+ }
52
+ }
53
+ for (const inner of ['datas', 'list', 'records', 'items', 'rows']) {
54
+ if (Array.isArray(obj[inner]))
55
+ return { rows: obj[inner], total: numish(obj.total) };
56
+ }
57
+ return { rows: null, total: null };
58
+ }
59
+ function payloadOf(obj) {
60
+ if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
61
+ for (const key of ['datajson', 'data']) {
62
+ if (obj[key] !== undefined && obj[key] !== null)
63
+ return { value: obj[key], via: key };
64
+ }
65
+ }
66
+ return { value: obj, via: '(root)' };
67
+ }
68
+ /** 权限/二次验证标志位:权限受限 ≠ 无数据,二次验证 ≠ 无数据。 */
69
+ function flagsOf(obj, payload) {
70
+ const flags = [];
71
+ if (payload && typeof payload === 'object' && !Array.isArray(payload) && payload.hasSearchRight === false) {
72
+ flags.push('hasSearchRight=false(权限受限,其余字段必为空 → 立即终止,不得交付为「无数据」)');
73
+ }
74
+ if (payload && typeof payload === 'object' && !Array.isArray(payload) && payload.pageUid === 'checkSecondFail') {
75
+ flags.push('pageUid=checkSecondFail(二次身份验证:total 可信、明细恒 0 行 → 如实说明,不得当无数据)');
76
+ }
77
+ let text = '';
78
+ try {
79
+ text = JSON.stringify(obj).slice(0, 4000);
80
+ }
81
+ catch {
82
+ text = '';
83
+ }
84
+ if (PERM_WORDS.some((word) => text.includes(word)))
85
+ flags.push('响应含权限关键词 → 按「无权限即终止」处理');
86
+ return flags;
87
+ }
88
+ function loadConfFile(path) {
89
+ let raw;
90
+ try {
91
+ raw = readFileSync(path, 'utf-8');
92
+ }
93
+ catch (error) {
94
+ throw dataApiError('conf_file_unreadable', `读 --conf-file 失败:${error.message}(${path})`);
95
+ }
96
+ let parsed;
97
+ try {
98
+ parsed = JSON.parse(raw.replace(/^\uFEFF/, '').trim());
99
+ }
100
+ catch {
101
+ throw dataApiError('conf_file_invalid', `--conf-file 不是合法 JSON:${path}`);
102
+ }
103
+ if (Array.isArray(parsed))
104
+ parsed = parsed[0] || {};
105
+ if (!parsed || typeof parsed !== 'object') {
106
+ throw dataApiError('conf_file_invalid', `--conf-file 形态异常(期望对象):${path}`);
107
+ }
108
+ // 形态②:`conf get --json` 原样输出(有 confAttrs);形态①:模板缓存(本身就是 attrs 视图)
109
+ if (parsed.confAttrs !== undefined || (parsed.confValue !== undefined && parsed.api_path === undefined)) {
110
+ const attrs = attributesOf(parsed);
111
+ return {
112
+ record: parsed,
113
+ attrs,
114
+ confKey: String(parsed.confKey || attrs.confKey || ''),
115
+ group: String(attrs.module || parsed.module || ''),
116
+ };
117
+ }
118
+ return {
119
+ record: parsed,
120
+ attrs: parsed,
121
+ confKey: String(parsed.confKey || ''),
122
+ group: String(parsed.module || ''),
123
+ };
124
+ }
125
+ export async function moduleCall(input, host) {
126
+ const confFile = typeof input.conf_file === 'string' && input.conf_file
127
+ ? String(input.conf_file).replace(/^@/, '')
128
+ : (typeof input.attrs === 'string' && input.attrs ? String(input.attrs).replace(/^@/, '') : '');
129
+ if (!input.conf_key && !confFile) {
130
+ throw dataValidationError('missing_argument', '缺必填参数 --conf-key(用法: module call --conf-key <confKey> --group <模块> [--type <confType>] [--conf-file <本地confAttrs>])');
131
+ }
132
+ if (!input.group && !confFile) {
133
+ throw dataValidationError('missing_argument', '缺必填参数 --group(模块唯一标识,如 WORKFLOW / EHR / DOCUMENT;带 --conf-file 时可省)');
134
+ }
135
+ let confKey = typeof input.conf_key === 'string' ? input.conf_key : '';
136
+ let group = typeof input.group === 'string' ? input.group : '';
137
+ const confType = typeof input.type === 'string' && input.type ? input.type : 'api';
138
+ const timeoutMs = Math.max(1, Number(input.timeout || '60') || 60) * 1000;
139
+ const limit = input.limit === undefined || input.limit === true ? 50 : (Number(input.limit) || 0);
140
+ const fields = typeof input.fields === 'string' && input.fields
141
+ ? readListArg(input.fields).split(',').map((item) => item.trim()).filter(Boolean)
142
+ : null;
143
+ // ---- ① 取该条接口配置 ----
144
+ let record;
145
+ let attrs;
146
+ if (confFile) {
147
+ const loaded = loadConfFile(confFile);
148
+ record = loaded.record;
149
+ attrs = loaded.attrs;
150
+ confKey = confKey || loaded.confKey;
151
+ group = group || loaded.group;
152
+ process.stderr.write(`# confAttrs 来自本地缓存(${confFile})|未请求配置中心\n`);
153
+ }
154
+ else {
155
+ try {
156
+ record = await confGetData(host, confType, confKey, false, group);
157
+ }
158
+ catch (error) {
159
+ const message = String(error?.message || error);
160
+ throw dataApiError('conf_get_failed', `conf get 失败:${message}(先核对 confType / confGroup / confKey;自定义 confType 须显式 --type;登录态问题请重新登录)`, { code: /登录态失效/.test(message) ? 2 : 3 });
161
+ }
162
+ attrs = attributesOf(record);
163
+ }
164
+ if (!attrs || typeof attrs !== 'object' || Array.isArray(attrs)) {
165
+ throw dataApiError('conf_attrs_invalid', `confAttrs 缺失或形态异常: ${confKey}(--group ${group})`);
166
+ }
167
+ const apiPath = String(attrs.api_path || record?.confValue || '');
168
+ if (!apiPath)
169
+ throw dataApiError('conf_attrs_invalid', `confAttrs 未提供 api_path / confValue: ${confKey}`);
170
+ // ---- ② HRM 路径黑名单 ----
171
+ if (HRM_PATTERNS.some((pattern) => apiPath.includes(pattern)))
172
+ throw dataHrmBlocked(apiPath);
173
+ const apiName = attrs.api_name || record?.confName || confKey;
174
+ // ---- ③ --show-params:只给入/出参说明与请求示例,不调接口 ----
175
+ if (input.show_params) {
176
+ const fullExample = (input.full === true || input.with_example === true) && input.no_example !== true;
177
+ const out = {
178
+ confKey,
179
+ conf_type: confType,
180
+ module: group,
181
+ api_name: apiName,
182
+ http_method: attrs.http_method ?? null,
183
+ api_path: apiPath,
184
+ business_desc: attrs.business_desc ?? null,
185
+ api_params: attrs.api_params ?? null,
186
+ input_params: attrs.input_params ?? null,
187
+ output_params: attrs.output_params ?? null,
188
+ };
189
+ if (fullExample)
190
+ out.request_example = attrs.request_example ?? null;
191
+ else {
192
+ out.request_example_omitted = true;
193
+ out.request_example_hint = '已省略 request_example(需完整模板加 --full);组参建议用 build_query.py --set/--set-file 生成';
194
+ }
195
+ return { data: out, text: JSON.stringify(out, null, 1) };
196
+ }
197
+ // ---- ④ 组参 ----
198
+ let businessArgs = {};
199
+ if (input.args !== undefined && input.args !== true) {
200
+ try {
201
+ businessArgs = readJsonArg(String(input.args), '--args') || {};
202
+ }
203
+ catch (error) {
204
+ throw dataValidationError('args_invalid', `--args 读取/解析失败:${error.message}`);
205
+ }
206
+ }
207
+ if (!businessArgs || typeof businessArgs !== 'object' || Array.isArray(businessArgs)) {
208
+ throw dataValidationError('args_invalid', '--args 必须是 JSON 对象');
209
+ }
210
+ if (typeof input.query === 'string' && input.query) {
211
+ for (const pair of input.query.split('&')) {
212
+ if (!pair)
213
+ continue;
214
+ const index = pair.indexOf('=');
215
+ if (index > 0)
216
+ businessArgs[pair.slice(0, index)] = pair.slice(index + 1);
217
+ }
218
+ }
219
+ const extraHeaders = {};
220
+ if (input.headers !== undefined && input.headers !== true) {
221
+ let parsed;
222
+ try {
223
+ parsed = readJsonArg(String(input.headers), '--headers');
224
+ }
225
+ catch (error) {
226
+ throw dataValidationError('headers_invalid', `--headers 读取/解析失败:${error.message}`);
227
+ }
228
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
229
+ Object.assign(extraHeaders, parsed);
230
+ }
231
+ if (typeof input.header === 'string' && input.header.includes(':')) {
232
+ const index = input.header.indexOf(':');
233
+ extraHeaders[input.header.slice(0, index).trim()] = input.header.slice(index + 1).trim();
234
+ }
235
+ const declared = String(input.method || attrs.http_method || 'POST').toUpperCase();
236
+ if (declared !== 'GET' && declared !== 'POST' && declared !== 'FORM') {
237
+ throw dataValidationError('method_invalid', `--method 只支持 GET / POST / FORM(当前: ${input.method})`);
238
+ }
239
+ const effMethod = declared === 'FORM' ? 'POST' : declared;
240
+ const isForm = declared === 'FORM' || /x-www-form-urlencoded/i.test(String(attrs.api_definition || ''));
241
+ let queryString = '';
242
+ // ⚠️ 运行时会对 `body` 再做一次 JSON.stringify ⇒ 这里必须传**对象**,不能传已序列化的字符串,
243
+ // 否则发出去的是「被转义的 JSON 字符串字面量」,后端一律 400/500(实测 DOCUMENT/EHR 都中招)。
244
+ // form-urlencoded 走 `form` 字段(运行时置 Content-Type 并 String() 处理)。
245
+ let jsonBody;
246
+ let formBody;
247
+ if (effMethod === 'GET') {
248
+ const serialized = queryStringOf(businessArgs);
249
+ queryString = serialized ? `?${serialized}` : '';
250
+ }
251
+ else if (isForm) {
252
+ formBody = queryStringOf(businessArgs);
253
+ }
254
+ else {
255
+ jsonBody = businessArgs;
256
+ }
257
+ // ---- ⑤ --dry-run:只组装不发送(凭据一律脱敏)----
258
+ if (input.dry_run) {
259
+ const masked = {};
260
+ for (const [key, value] of Object.entries(extraHeaders))
261
+ masked[key] = /^token$/i.test(key) ? '<脱敏>' : value;
262
+ const out = {
263
+ ok: true,
264
+ confKey,
265
+ api_name: apiName,
266
+ method: effMethod,
267
+ url: `<baseUrl>${apiPath}${queryString}`,
268
+ body: businessArgs,
269
+ headers: {
270
+ Cookie: '<脱敏>',
271
+ eteamsid: '<脱敏>',
272
+ 'User-Agent': '<AgentType=…,IsAgent=true>',
273
+ 'Content-Type': effMethod === 'POST' ? (isForm ? 'application/x-www-form-urlencoded' : 'application/json;charset=UTF-8') : null,
274
+ ...masked,
275
+ },
276
+ note: '--dry-run:未发送请求',
277
+ };
278
+ return { data: out, text: JSON.stringify(out, null, 1) };
279
+ }
280
+ // ---- ⑥ 发请求 ----
281
+ const headers = { ...extraHeaders };
282
+ const trustedHeaders = {};
283
+ if (effMethod === 'POST')
284
+ headers['Content-Type'] = isForm ? 'application/x-www-form-urlencoded;charset=UTF-8' : 'application/json;charset=UTF-8';
285
+ // INVOICE:业务接口除通用三件套外必须带发票云 token。
286
+ // ⚠️ `token` 在运行时的保留头清单里,走 headers 会被剥掉 ⇒ 只能走 trustedHeaders。
287
+ if (group.toUpperCase() === 'INVOICE' || String(attrs.module_key || '').toUpperCase() === 'INVOICE') {
288
+ const tokenResponse = await host.requestText({ method: 'GET', path: INVOICE_TOKEN_PATH, operation: 'module.invoiceToken' });
289
+ let token = null;
290
+ try {
291
+ token = parseJsonSafe(tokenResponse.text)?.data?.token ?? null;
292
+ }
293
+ catch {
294
+ token = null;
295
+ }
296
+ if (!token) {
297
+ throw dataApiError('invoice_token_missing', `未取到发票云 Token(INVOICE 业务接口必需;HTTP ${tokenResponse.status})`, { code: 7 });
298
+ }
299
+ trustedHeaders.token = token;
300
+ }
301
+ for (const [key, value] of Object.entries(extraHeaders)) {
302
+ if (/^token$/i.test(key) || ['cookie', 'eteamsid', 'user-agent'].includes(key.toLowerCase()))
303
+ trustedHeaders[key] = value;
304
+ }
305
+ const { status, text } = await host.requestText({
306
+ method: effMethod,
307
+ path: apiPath + queryString,
308
+ body: effMethod === 'POST' ? jsonBody : undefined,
309
+ form: effMethod === 'POST' ? formBody : undefined,
310
+ headers,
311
+ trustedHeaders,
312
+ timeoutMs,
313
+ operation: `module.call:${confKey}`,
314
+ });
315
+ if (status === 401) {
316
+ throw dataApiError('login_required', '登录态失效(HTTP 401):请执行 `weaver-work-cli auth login --base-url <域名>` 重新登录', { code: 2 });
317
+ }
318
+ let obj = null;
319
+ try {
320
+ obj = parseJsonSafe(text);
321
+ }
322
+ catch {
323
+ obj = null;
324
+ }
325
+ if (obj === null) {
326
+ // 非 JSON:原样输出前 2000 字符(2xx 视为正常,其余按请求失败)
327
+ const out = { ok: status >= 200 && status < 300, api_name: apiName, http: status, nonJson: text.slice(0, 2000) };
328
+ if (status < 200 || status >= 300) {
329
+ throw dataApiError('non_json', `HTTP ${status} 且响应非 JSON(已原样输出前 2000 字符)`, { code: 7, details: out });
330
+ }
331
+ return { data: out, text: text.slice(0, 2000) };
332
+ }
333
+ // ---- ⑦ --raw:原样输出响应体 ----
334
+ if (input.raw)
335
+ return { data: obj, text: JSON.stringify(obj, null, 1) };
336
+ // ---- ⑧ 提取精简结果 ----
337
+ const payload = payloadOf(obj);
338
+ const flags = flagsOf(obj, payload.value);
339
+ const tips = scanTips(obj);
340
+ const { rows, total } = rowsOf(obj);
341
+ const out = { ok: true, api_name: apiName, http: status, via: payload.via, ...tipFields(tips) };
342
+ let projected = null;
343
+ if (rows !== null) {
344
+ const shown = limit > 0 ? rows.slice(0, limit) : rows;
345
+ projected = fields
346
+ ? shown.map((row) => {
347
+ const picked = {};
348
+ if (row && typeof row === 'object')
349
+ for (const key of fields)
350
+ if (key in row)
351
+ picked[key] = row[key];
352
+ return picked;
353
+ })
354
+ : shown;
355
+ out.total = total;
356
+ out.rows = rows.length;
357
+ out.shown = projected.length;
358
+ out.data = projected;
359
+ }
360
+ else {
361
+ out.data = payload.value;
362
+ }
363
+ if (flags.length)
364
+ out.flags = flags;
365
+ const lines = [`== ${apiName} ==`, `${effMethod} ${apiPath} → HTTP ${status}(via=${payload.via})`];
366
+ if (rows !== null) {
367
+ lines.push(`rows=${rows.length}${total !== null && total !== undefined ? ` / total=${total}` : ''}${limit > 0 && rows.length > limit ? `(已截断到 ${limit} 行)` : ''}`);
368
+ lines.push(renderTable('', projected));
369
+ }
370
+ else {
371
+ lines.push(JSON.stringify(payload.value, null, 1));
372
+ }
373
+ for (const flag of flags)
374
+ lines.push(`[!] ${flag}`);
375
+ lines.push(...tipsLines(tips));
376
+ // 权限受限是终端态:结果照常给出(供调用方留证),但退出码必须非 0
377
+ if (flags.some((flag) => flag.startsWith('hasSearchRight=false'))) {
378
+ const error = dataPermissionBlocked('权限受限:hasSearchRight=false(立即终止,不重试、不换参、不交付为「无数据」)');
379
+ error.details = { result: out };
380
+ throw error;
381
+ }
382
+ return { data: out, text: lines.join('\n') };
383
+ }
@@ -0,0 +1,102 @@
1
+ import { needArg } from '../host.js';
2
+ import { dataApiError, dataValidationError } from '../errors.js';
3
+ import { readListArg } from './shared.js';
4
+ /**
5
+ * 词库(ChatBI 名词解释)。
6
+ *
7
+ * - `noun list --skill <skillKey>`:按 skill 取词库(`getChatDocsBySkillKey`)。
8
+ * - `noun scope --ids <数据集id...>`:按生效范围批量检索(`getChatBiDocByScopeId`),
9
+ * 入参是场景定位(`scene items --group`)里每个条目的 id。
10
+ *
11
+ * ⚠️ id 一律按**字符串**下发:19 位雪花号超出 JS 安全整数(2^53),`Number()` 会丢精度
12
+ * (实测 `Number("1060565684758507544")` 末位归零)→ 下发即检不到,且不报错。
13
+ */
14
+ const DOC_SCOPE_PATH = '/api/dw/newetl/chatBi/doc/getChatBiDocByScopeId';
15
+ function normalizeDoc(doc) {
16
+ return {
17
+ keyword: doc.keyword ?? null,
18
+ synonyms: doc.synonyms ?? null,
19
+ wordExplain: doc.wordExplain ?? null,
20
+ allScope: doc.allScope ?? null,
21
+ scopeEffectId: doc.scopeEffectId ?? null,
22
+ docType: doc.docType ?? null,
23
+ };
24
+ }
25
+ /** `--ids`:逗号/空白分隔的 id 串,或 `@文件`(JSON 数组或逗号串)→ 字符串 id 数组(去重保序)。 */
26
+ function parseScopeIds(value) {
27
+ const raw = String(readListArg(value) ?? '').trim();
28
+ const ids = raw.split(/[,\s]+/).map((item) => item.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
29
+ if (!ids.length) {
30
+ throw dataValidationError('missing_argument', '--ids 为空:请传数据集 id 列表(如 --ids 1060565684758507544,1060565684758507545 或 --ids @ids.json)');
31
+ }
32
+ for (const id of ids) {
33
+ if (!/^\d+$/.test(id)) {
34
+ throw dataValidationError('ids_invalid', `--ids 含非法项「${id}」(须为数字型数据集 id,取自 scene items 的条目 id)`);
35
+ }
36
+ if (BigInt(id) > 9223372036854775807n)
37
+ throw dataValidationError('ids_invalid', `--ids 含超出 Long 上限的 id:${id}`);
38
+ }
39
+ return [...new Set(ids)];
40
+ }
41
+ export async function nounList(input, host) {
42
+ const skill = needArg(input, 'skill');
43
+ const query = { skillKey: skill };
44
+ if (input.source_type)
45
+ query.sourceType = String(input.source_type);
46
+ if (input.source_group)
47
+ query.sourceGroupId = String(input.source_group);
48
+ if (input.source_table)
49
+ query.sourceTableId = String(input.source_table);
50
+ const response = await host.request({
51
+ method: 'GET',
52
+ path: '/api/dw/newetl/chatBi/skill/getChatDocsBySkillKey',
53
+ query,
54
+ operation: 'noun.list',
55
+ });
56
+ const data = response?.data;
57
+ if (!data || !data.nouns) {
58
+ return { data: response, text: `(该 skill 词库不存在或为空) msg=${response?.msg || ''}` };
59
+ }
60
+ const lines = [`== 名词解释 ${data.nouns.length} 条 (skill=${skill}) ==`];
61
+ for (const noun of data.nouns) {
62
+ lines.push(`【${noun.keyword || ''}】${noun.synonyms ? ` 同义:${noun.synonyms}` : ''}`);
63
+ if (noun.wordExplain)
64
+ lines.push(` ${String(noun.wordExplain).replace(/\n/g, ' ')}`);
65
+ }
66
+ return { data: response, text: lines.join('\n') };
67
+ }
68
+ export async function nounScope(input, host) {
69
+ const ids = parseScopeIds(needArg(input, 'ids'));
70
+ const response = await host.request({
71
+ method: 'POST',
72
+ path: DOC_SCOPE_PATH,
73
+ body: ids.map(String),
74
+ operation: 'noun.scope',
75
+ });
76
+ const bad = response && typeof response === 'object' && !Array.isArray(response)
77
+ && ((response.code !== undefined && Number(response.code) !== 0) || response.fail === true);
78
+ if (bad) {
79
+ throw dataApiError('noun_scope_failed', `getChatBiDocByScopeId 业务失败:code=${response.code} msg=${response.msg || '(无 msg)'}`, {
80
+ code: response.code,
81
+ });
82
+ }
83
+ const docs = ((response && response.data) || []).map(normalizeDoc);
84
+ const globalCount = docs.filter((doc) => doc.allScope === 1).length;
85
+ const scopedCount = docs.filter((doc) => doc.allScope !== 1).length;
86
+ const lines = [`== 词库 ${docs.length} 条(生效范围 id ${ids.length} 个;全局 ${globalCount} + 数据集级 ${scopedCount})==`];
87
+ if (!docs.length) {
88
+ lines.push('(空词库:该环境未返回任何词库条目)');
89
+ }
90
+ else {
91
+ for (const doc of docs) {
92
+ const tag = doc.allScope === 1 ? '全局' : (doc.allScope === 2 ? 'Skill' : '数据集');
93
+ const scope = doc.allScope === 1 ? '全部数据' : (doc.scopeEffectId || '');
94
+ lines.push(`【${doc.keyword || ''}】${doc.synonyms ? ` 同义:${doc.synonyms}` : ''} [${tag} ${scope}]`);
95
+ if (doc.wordExplain)
96
+ lines.push(` ${String(doc.wordExplain).replace(/\n/g, ' ')}`);
97
+ }
98
+ if (!scopedCount)
99
+ lines.push('(提示:本次只命中全局词库,所选数据集均无专属词库 —— 为确定结论)');
100
+ }
101
+ return { data: { scopeIds: ids, count: docs.length, globalCount, scopedCount, docs }, text: lines.join('\n') };
102
+ }