weaver-work-cli 0.1.48 → 0.1.50

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 (167) hide show
  1. package/dist/chunks/{archive-oa-EDJDU3V4.js → archive-oa-57R2FYHV.js} +111 -12
  2. package/dist/chunks/{attachment-content-4KSNBPRO.js → attachment-content-EJYIOJPH.js} +3 -3
  3. package/dist/chunks/{chunk-FEP6ELMR.js → chunk-3NCFFHB2.js} +1 -1
  4. package/dist/chunks/chunk-5QYE52LG.js +223 -0
  5. package/dist/chunks/{chunk-3YV7PKRL.js → chunk-6QYNE6HE.js} +12 -212
  6. package/dist/chunks/{chunk-NBEWUR7L.js → chunk-6T53BSWZ.js} +158 -44
  7. package/dist/chunks/{chunk-OCYRVZGN.js → chunk-7AYQJSFY.js} +2 -2
  8. package/dist/chunks/{chunk-5B5JXTY2.js → chunk-7ECB22G3.js} +221 -30
  9. package/dist/chunks/{chunk-72MI3MBX.js → chunk-ATEXBEPD.js} +55 -15
  10. package/dist/chunks/{chunk-WMSAWAWZ.js → chunk-BFKLQLBK.js} +8 -8
  11. package/dist/chunks/{chunk-EFOUMXIX.js → chunk-HARQF5IP.js} +28 -28
  12. package/dist/chunks/{chunk-O6CMPO65.js → chunk-IW7A2IQY.js} +16 -146
  13. package/dist/chunks/chunk-JEQHNNSS.js +158 -0
  14. package/dist/chunks/{chunk-NK74RE5F.js → chunk-K67FODVC.js} +3 -3
  15. package/dist/chunks/{chunk-YLCYX7LE.js → chunk-KMRT7NAT.js} +18 -5
  16. package/dist/chunks/{chunk-BCACE6VV.js → chunk-MCZG6HPM.js} +3 -3
  17. package/dist/chunks/{chunk-SVFG6EMV.js → chunk-RYFRGTUV.js} +5 -5
  18. package/dist/chunks/{chunk-PSPOFLSU.js → chunk-WNJUGI2F.js} +1 -1
  19. package/dist/chunks/{chunk-R2HHLJNN.js → chunk-YB3AJYPY.js} +4 -4
  20. package/dist/chunks/{conflict-APGSD5E7.js → conflict-C4UDHCWV.js} +2 -2
  21. package/dist/chunks/{contract-N6P2HIIE.js → contract-VUC6JOPG.js} +464 -9
  22. package/dist/chunks/{create-flow-5TXFOC7X.js → create-flow-6OG2LYBD.js} +6 -6
  23. package/dist/chunks/data-QO7QWOIV.js +2525 -0
  24. package/dist/chunks/{employee-NOHNXC46.js → employee-DR5Y64TI.js} +2 -1
  25. package/dist/chunks/{env-B6GKA2J3.js → env-WP57TF2S.js} +2 -2
  26. package/dist/chunks/{factory-MFCKLUT6.js → factory-VUXI7N5C.js} +1 -1
  27. package/dist/chunks/{fna-ZVB2IILI.js → fna-ECOYBQYL.js} +328 -5
  28. package/dist/chunks/{group-chat-YE7WIBFO.js → group-chat-UQRGXILK.js} +3 -3
  29. package/dist/chunks/{hrm-UNKCCCGP.js → hrm-YGIR3HGF.js} +4 -2
  30. package/dist/chunks/{im-3RCNL5GT.js → im-TN2JYVGJ.js} +2 -2
  31. package/dist/chunks/{invoice-FXWH5GPO.js → invoice-E7GOITEU.js} +1 -1
  32. package/dist/chunks/{meeting-RYZV2JTQ.js → meeting-4BBLVAWM.js} +10 -10
  33. package/dist/chunks/{msg-parse-4GSQ2WTO.js → msg-parse-FPFVPMYI.js} +5 -1
  34. package/dist/chunks/org-NFE7X7FK.js +12 -0
  35. package/dist/chunks/{reception-VL6TKVAW.js → reception-QGPNTGHG.js} +526 -175
  36. package/dist/chunks/{recruit-stage-ERZD3ZNB.js → recruit-stage-FKWS5UQF.js} +66 -13
  37. package/dist/chunks/{registry-VWXWPVAG.js → registry-3UGIWH53.js} +4 -2
  38. package/dist/chunks/{registry-22O6UG4I.js → registry-5CRCN2TV.js} +10 -10
  39. package/dist/chunks/{registry-BUTEDK3C.js → registry-E5RQJVWN.js} +2 -2
  40. package/dist/chunks/{registry-7VZ6YJUF.js → registry-V4CHRQDI.js} +1 -1
  41. package/dist/chunks/{room-recommend-IMZPJMYB.js → room-recommend-AYR3UG7R.js} +4 -4
  42. package/dist/chunks/{schedule-SPPAHER2.js → schedule-JZEFIXUS.js} +4 -4
  43. package/dist/chunks/{workflow-WVEFJ6KC.js → workflow-3ZAF2J5E.js} +4 -4
  44. package/dist/index.js +16 -11
  45. package/dist/shortcuts/archive-oa/operations/contract-modules.js +57 -0
  46. package/dist/shortcuts/archive-oa/operations/contract.js +23 -8
  47. package/dist/shortcuts/archive-oa/operations/registry.js +4 -1
  48. package/dist/shortcuts/archive-oa/operations/shared.js +41 -5
  49. package/dist/shortcuts/contract/host.js +11 -0
  50. package/dist/shortcuts/contract/index.js +13 -0
  51. package/dist/shortcuts/contract/manifest.js +53 -0
  52. package/dist/shortcuts/contract/operations/performance.js +58 -7
  53. package/dist/shortcuts/contract/operations/quote.js +283 -1
  54. package/dist/shortcuts/contract/operations/registry.js +2 -0
  55. package/dist/shortcuts/contract/operations/save-recognize.js +151 -0
  56. package/dist/shortcuts/data/errors.js +64 -0
  57. package/dist/shortcuts/data/host.js +140 -0
  58. package/dist/shortcuts/data/index.js +429 -0
  59. package/dist/shortcuts/data/manifest.js +133 -0
  60. package/dist/shortcuts/data/operations/attend.js +62 -0
  61. package/dist/shortcuts/data/operations/conf.js +384 -0
  62. package/dist/shortcuts/data/operations/ds.js +686 -0
  63. package/dist/shortcuts/data/operations/field.js +68 -0
  64. package/dist/shortcuts/data/operations/index.js +65 -0
  65. package/dist/shortcuts/data/operations/module.js +383 -0
  66. package/dist/shortcuts/data/operations/noun.js +102 -0
  67. package/dist/shortcuts/data/operations/query.js +85 -0
  68. package/dist/shortcuts/data/operations/scene.js +235 -0
  69. package/dist/shortcuts/data/operations/shared.js +279 -0
  70. package/dist/shortcuts/ehr/recruit-stage/operations/interview-arrange.js +12 -5
  71. package/dist/shortcuts/ehr/recruit-stage/operations/resume-import.js +21 -13
  72. package/dist/shortcuts/ehr/recruit-stage/shared.js +57 -0
  73. package/dist/shortcuts/fna/host.js +4 -2
  74. package/dist/shortcuts/fna/manifest.js +14 -5
  75. package/dist/shortcuts/fna/operations/audit.js +334 -0
  76. package/dist/shortcuts/fna/operations/registry.js +2 -0
  77. package/dist/shortcuts/im/operations/at-mention.js +6 -3
  78. package/dist/shortcuts/im/operations/msg-parse.js +35 -5
  79. package/dist/shortcuts/im/operations/msg-sync.js +3 -1
  80. package/dist/shortcuts/im/operations/msg-write.js +57 -9
  81. package/dist/shortcuts/index.js +5 -0
  82. package/dist/shortcuts/invoice/manifest.js +1 -1
  83. package/dist/shortcuts/meeting/operations/eb/member-expand.js +200 -0
  84. package/dist/shortcuts/meeting/operations/from-group-chat.js +16 -2
  85. package/dist/shortcuts/meeting/operations/registry.js +2 -0
  86. package/dist/shortcuts/reception/constants.js +13 -6
  87. package/dist/shortcuts/reception/index.js +3 -1
  88. package/dist/shortcuts/reception/manifest.js +3 -2
  89. package/dist/shortcuts/reception/operations/ask.js +20 -2
  90. package/dist/shortcuts/reception/operations/compose.js +11 -0
  91. package/dist/shortcuts/reception/operations/doc.js +59 -0
  92. package/dist/shortcuts/reception/operations/docrender.js +25 -1
  93. package/dist/shortcuts/reception/operations/leads.js +31 -7
  94. package/dist/shortcuts/reception/operations/panels.js +86 -22
  95. package/dist/shortcuts/reception/operations/render.js +40 -0
  96. package/dist/shortcuts/reception/operations/restaurant.js +17 -4
  97. package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +12 -5
  98. package/dist/shortcuts/recruit-stage/operations/resume-import.js +21 -13
  99. package/dist/shortcuts/recruit-stage/shared.js +57 -0
  100. package/dist/shortcuts/workflow/operations/read.js +58 -14
  101. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +140 -24
  102. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +42 -14
  103. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +4 -6
  104. package/docs/SKILL.md +2 -1
  105. package/docs/_catalog.md +4 -1
  106. package/docs/data.md +149 -0
  107. package/docs/fna.md +11 -4
  108. package/docs/reception.md +59 -5
  109. package/package.json +1 -1
  110. package/scripts/check-skill-sync.mjs +188 -0
  111. package/scripts/package-skill.mjs +17 -3
  112. package/skill-template/business-info.json +29 -1
  113. package/skill-template/domains/data.md +15 -0
  114. package/skill-template/domains/qiyecheng.md +4 -2
  115. package/skills/weaver-e10-archive-oa/SKILL.md +7 -6
  116. package/skills/weaver-e10-archive-oa/references/contract-search.md +83 -14
  117. package/skills/weaver-e10-archive-oa/references/disabled-capabilities.md +1 -1
  118. package/skills/weaver-e10-archive-oa/references/qys-contract-search.md +35 -11
  119. package/skills/weaver-e10-data/SKILL.md +118 -0
  120. package/skills/weaver-e10-data/references/config-center.md +90 -0
  121. package/skills/weaver-e10-data/references/datasource.md +136 -0
  122. package/skills/weaver-e10-data/references/scene-and-misc.md +82 -0
  123. package/skills/weaver-e10-jinchengda/SKILL.md +1 -1
  124. package/skills/weaver-e10-jinchengda/references/contract-action-card.md +5 -5
  125. package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +1 -1
  126. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +44 -2
  127. package/skills/weaver-e10-jinchengda/references/contract-command-index.md +2 -2
  128. package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +219 -0
  129. package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +50 -30
  130. package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +24 -15
  131. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +1 -1
  132. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +96 -2
  133. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +43 -0
  134. package/skills/weaver-e10-jinchengda/scripts/fill_plan.py +997 -0
  135. package/skills/weaver-e10-jinchengda/scripts/render_ebdf_list_card.py +265 -0
  136. package/skills/weaver-e10-jinchengda/scripts/validate_action_card.py +83 -0
  137. package/skills/weaver-e10-jinchengda/scripts/verify_docx_placeholders.py +118 -0
  138. package/skills/weaver-e10-meeting/SKILL.md +39 -7
  139. package/skills/weaver-e10-qiyecheng/SKILL.md +21 -7
  140. package/skills/weaver-e10-qiyecheng/references/ai-check-audit.md +104 -0
  141. package/skills/weaver-e10-qiyecheng/references/catalog.md +17 -3
  142. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +136 -30
  143. package/skills/weaver-e10-reception-flow/SKILL.md +70 -19
  144. package/skills/weaver-e10-reception-flow/references/guide.md +5 -4
  145. package/skills/weaver-e10-reception-flow/scripts/render.py +5 -3
  146. package/skills/weaver-e10-recruit-stage/SKILL.md +1 -1
  147. package/skills/weaver-e10-recruit-stage/agents/openai.yaml +26 -6
  148. package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +3 -3
  149. package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +6 -4
  150. package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +3 -3
  151. package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +53 -11
  152. package/skills/weaver-e10-workflow/SKILL.md +2 -1
  153. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +29 -6
  154. package/skills/weaver-e10-workflow/tools/todo-summary.cjs +162 -10
  155. package/skills/weaver-e10-yepiaotong/SKILL.md +10 -5
  156. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +19 -32
  157. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +6 -45
  158. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +5 -5
  159. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +4 -37
  160. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +2 -2
  161. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +4 -4
  162. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +22 -35
  163. package/skills/weaver-e10-yimiaoban/SKILL.md +8 -6
  164. package/skills/weaver-e10-yimiaoban/references/msg-read.md +20 -0
  165. package/skills/weaver-e10-yimiaoban/references/msg-write.md +7 -0
  166. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +18 -15
  167. package/dist/chunks/{ebuilder-form-I5ZIX4WO.js → ebuilder-form-CBYI6CQ6.js} +4 -4
@@ -0,0 +1,64 @@
1
+ import { CliError, ExitCode } from '../../core/errors.js';
2
+ /**
3
+ * data 模块的错误类型。
4
+ *
5
+ * 退出码沿用 e10-data 的既有语义(技能侧按退出码分流,不能改):
6
+ * 0 正常(**空结果也算正常**)|2 未登录·凭据失效|3 非 JSON·confAttrs 异常
7
+ * 4 权限受限(hasSearchRight=false,终端态)|6 命中 HRM 路径黑名单|7 请求失败|8 用法错误
8
+ * 映射到框架的 ExitCode:2→UsageError、3→AuthError、4→PolicyError、6→PolicyError、
9
+ * 7→NetworkError、8→UsageError。**退出码数值本身必须与旧版一致**,因此这里直接使用数值。
10
+ */
11
+ export const DataExit = {
12
+ OK: 0,
13
+ AUTH: 2,
14
+ JSON: 3,
15
+ PERM: 4,
16
+ HRM: 6,
17
+ HTTP: 7,
18
+ USAGE: 8,
19
+ };
20
+ export class DataCliError extends CliError {
21
+ type;
22
+ subtype;
23
+ code;
24
+ retryable;
25
+ stage;
26
+ details;
27
+ constructor(type, subtype, message, options = {}) {
28
+ super(message, options.exitCode ?? ExitCode.GeneralError);
29
+ this.name = 'DataCliError';
30
+ this.type = type;
31
+ this.subtype = subtype;
32
+ this.code = options.code;
33
+ this.retryable = options.retryable ?? false;
34
+ this.stage = options.stage;
35
+ this.details = options.details;
36
+ }
37
+ }
38
+ export function dataValidationError(subtype, message, exitCode = DataExit.USAGE) {
39
+ return new DataCliError('validation', subtype, message, { exitCode });
40
+ }
41
+ export function dataAuthError(subtype, message, details) {
42
+ return new DataCliError('authentication', subtype, message, { exitCode: DataExit.AUTH, details });
43
+ }
44
+ export function dataNetworkError(subtype, message, details) {
45
+ return new DataCliError('network', subtype, message, { exitCode: DataExit.HTTP, retryable: true, details });
46
+ }
47
+ export function dataApiError(subtype, message, options = {}) {
48
+ return new DataCliError('api', subtype, message, {
49
+ code: options.code,
50
+ details: options.details,
51
+ exitCode: options.exitCode ?? DataExit.JSON,
52
+ });
53
+ }
54
+ export function dataPolicyError(subtype, message, details) {
55
+ return new DataCliError('policy', subtype, message, { exitCode: DataExit.PERM, details });
56
+ }
57
+ /** 权限受限是「终端态」:结果照常给,但退出码必须非 0(对齐 call_module.py)。 */
58
+ export function dataPermissionBlocked(message) {
59
+ return new DataCliError('policy', 'permission_restricted', message, { exitCode: DataExit.PERM });
60
+ }
61
+ /** HRM 路径黑名单:人员/部门/岗位一律走 `weaver-work-cli hrm`,禁止在 data 通道直调。 */
62
+ export function dataHrmBlocked(apiPath) {
63
+ return new DataCliError('policy', 'hrm_path_blocked', `该接口命中 HRM 路径黑名单(${apiPath})→ 人员/部门/岗位一律走 weaver-work-cli 的 hrm 子命令,禁止直调`, { exitCode: DataExit.HRM, details: { apiPath } });
64
+ }
@@ -0,0 +1,140 @@
1
+ import { E10_SESSION_EXPIRED_MESSAGE } from '../../internal/e10/auth/messages.js';
2
+ import { requireE10Session } from '../../internal/e10/context.js';
3
+ import { E10ApiError, createE10RequestRuntime } from '../../internal/e10/request-runtime.js';
4
+ import { isE10SessionExpiredResponse } from '../../internal/e10/auth-recovery.js';
5
+ import { dataApiError, dataAuthError, dataNetworkError, dataValidationError, } from './errors.js';
6
+ /** 业务请求默认超时(与 e10-data 的 module call 默认一致:60s)。 */
7
+ export const DATA_TIMEOUT_MS = 60_000;
8
+ /** EB 业务 ID。e10-data 对 conf / module 通道恒定下发该头,运行时不会自动注入。 */
9
+ export const DATA_EB_BUSINESS_ID = '10000000000000000';
10
+ function queryStringOf(query) {
11
+ if (!query)
12
+ return undefined;
13
+ const out = {};
14
+ for (const [key, value] of Object.entries(query)) {
15
+ if (value === undefined || value === null)
16
+ continue;
17
+ out[key] = value;
18
+ }
19
+ return out;
20
+ }
21
+ function formStringOf(form) {
22
+ if (typeof form === 'string')
23
+ return form;
24
+ const params = new URLSearchParams();
25
+ for (const [key, value] of Object.entries(form)) {
26
+ if (value === undefined || value === null)
27
+ continue;
28
+ // 数组按多值展开、对象 JSON 化 —— 与 e10-data 的 moduleQueryString 口径一致
29
+ if (Array.isArray(value)) {
30
+ for (const item of value) {
31
+ params.append(key, item !== null && typeof item === 'object' ? JSON.stringify(item) : String(item));
32
+ }
33
+ }
34
+ else {
35
+ params.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
36
+ }
37
+ }
38
+ return params.toString();
39
+ }
40
+ function multipartOf(fields) {
41
+ const form = new FormData();
42
+ for (const [key, value] of Object.entries(fields)) {
43
+ if (value === undefined || value === null)
44
+ continue;
45
+ form.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
46
+ }
47
+ return form;
48
+ }
49
+ export function createDataHost(ctx, dependencies = {}) {
50
+ let authSession = null;
51
+ let snapshot = null;
52
+ const requireSession = dependencies.requireSession ?? requireE10Session;
53
+ async function ensureSession() {
54
+ if (!authSession) {
55
+ authSession = await requireSession(ctx);
56
+ snapshot = {
57
+ baseUrl: authSession.getBaseUrl(),
58
+ userId: authSession.userId,
59
+ tenantKey: authSession.tenantKey,
60
+ eteamsId: authSession.eteamsId,
61
+ userAgent: authSession.uaHeader(),
62
+ };
63
+ }
64
+ return authSession;
65
+ }
66
+ async function requestText(request) {
67
+ const session = await ensureSession();
68
+ const runtime = createE10RequestRuntime(ctx, session);
69
+ const method = request.method ?? (request.body === undefined && request.form === undefined && request.multipart === undefined
70
+ ? 'GET'
71
+ : 'POST');
72
+ let response;
73
+ try {
74
+ response = await runtime.requestJson({
75
+ module: 'data',
76
+ operation: request.operation ?? request.path,
77
+ method,
78
+ path: request.path,
79
+ query: queryStringOf(request.query),
80
+ // multipart 与 body/form 互斥:FormData 自带 boundary,不能与 Content-Type 混用
81
+ body: request.multipart === undefined ? request.body : undefined,
82
+ form: request.multipart === undefined && request.form !== undefined ? formStringOf(request.form) : undefined,
83
+ formData: request.multipart === undefined ? undefined : multipartOf(request.multipart),
84
+ headers: {
85
+ // e10-data 对 conf / module 通道恒定下发 ebbusinessid,运行时不会自动注入
86
+ ebbusinessid: DATA_EB_BUSINESS_ID,
87
+ ...(request.headers ?? {}),
88
+ },
89
+ trustedHeaders: request.trustedHeaders,
90
+ timeoutMs: request.timeoutMs ?? DATA_TIMEOUT_MS,
91
+ });
92
+ }
93
+ catch (error) {
94
+ if (error instanceof E10ApiError) {
95
+ if (error.type === 'authentication')
96
+ throw dataAuthError('session_expired', error.message);
97
+ if (error.type === 'network')
98
+ throw dataNetworkError(error.subtype, error.message, error.details);
99
+ }
100
+ throw error;
101
+ }
102
+ if (isE10SessionExpiredResponse(response)) {
103
+ throw dataAuthError('session_expired', E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
104
+ }
105
+ if (response.parseError) {
106
+ if (response.status >= 200 && response.status < 300) {
107
+ // 2xx 但非 JSON:把原文交回调用方(module call 需要原样输出前 2000 字符)
108
+ return { status: response.status, text: response.text, value: null };
109
+ }
110
+ throw dataNetworkError('non_json', `HTTP ${response.status} 非 JSON 响应: ${response.text.slice(0, 300)}`, {
111
+ status: response.status,
112
+ });
113
+ }
114
+ return { status: response.status, text: response.text, value: response.value };
115
+ }
116
+ async function request(request) {
117
+ const { status, value, text } = await requestText(request);
118
+ if (status < 200 || status >= 300) {
119
+ throw dataApiError('http_error', `接口 HTTP ${status}`, {
120
+ code: status,
121
+ details: { status, body: String(text ?? '').slice(0, 500) },
122
+ exitCode: 7,
123
+ });
124
+ }
125
+ return value;
126
+ }
127
+ async function session() {
128
+ await ensureSession();
129
+ return snapshot;
130
+ }
131
+ return { session, request, requestText };
132
+ }
133
+ /** 参数校验小工具:必填项缺失统一走用法错误(退出码 8)。 */
134
+ export function needArg(input, key, flag) {
135
+ const raw = input[key];
136
+ if (raw === undefined || raw === null || raw === '' || raw === true) {
137
+ throw dataValidationError('missing_argument', `缺少必填参数 --${flag ?? key.replace(/_/g, '-')}`);
138
+ }
139
+ return String(raw);
140
+ }
@@ -0,0 +1,429 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { createDataHost } from './host.js';
3
+ import { dataManifest } from './manifest.js';
4
+ import { dataValidationError } from './errors.js';
5
+ import { executeDataOperation, operationNames } from './operations/index.js';
6
+ /** commander 的 camelCase 选项 → operation 的 snake_case 输入。 */
7
+ export function toInput(options) {
8
+ const input = {};
9
+ for (const [key, value] of Object.entries(options)) {
10
+ if (value === undefined)
11
+ continue;
12
+ input[key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)] = value;
13
+ }
14
+ // `--no-escalate` 在 commander 里表现为 escalate=false
15
+ if (input.escalate === false) {
16
+ input.no_escalate = true;
17
+ delete input.escalate;
18
+ }
19
+ return input;
20
+ }
21
+ async function readStdin() {
22
+ const chunks = [];
23
+ for await (const chunk of process.stdin)
24
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
25
+ return Buffer.concat(chunks).toString('utf8');
26
+ }
27
+ async function inputFrom(options) {
28
+ let input = {};
29
+ if (options.input && options.inputJson) {
30
+ throw dataValidationError('input_conflict', '不能同时传 --input 和 --input-json');
31
+ }
32
+ if (options.inputJson)
33
+ input = parseInput(String(options.inputJson), '--input-json');
34
+ if (options.input) {
35
+ let raw;
36
+ try {
37
+ raw = options.input === '-' ? await readStdin() : await readFile(String(options.input), 'utf8');
38
+ }
39
+ catch {
40
+ throw dataValidationError('input_unreadable', `无法读取 --input:${String(options.input)}`);
41
+ }
42
+ input = parseInput(raw, '--input');
43
+ }
44
+ return input;
45
+ }
46
+ function parseInput(raw, label) {
47
+ try {
48
+ const parsed = JSON.parse(raw.replace(/^\uFEFF+/g, ''));
49
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
50
+ throw new Error('not an object');
51
+ return parsed;
52
+ }
53
+ catch {
54
+ throw dataValidationError('input_invalid', `${label} 不是合法 JSON 对象`);
55
+ }
56
+ }
57
+ /**
58
+ * 便捷命令的输出口径:**与旧 CLI 逐字一致**。
59
+ *
60
+ * 技能里有 453 处 `e10-data … --json` 调用,jq 路径直指响应体(如 `.data.records`)。
61
+ * 因此便捷命令一律输出**原始响应体**(不再套一层信封),且关闭「超预算落盘」,
62
+ * 避免大结果被替换成 `{refId, preview…}` 而打断下游解析。
63
+ * 需要统一信封(`{schemaVersion, ok, operation, data, warnings}`)时走 `data run`。
64
+ */
65
+ function emit(ctx, result) {
66
+ ctx.output.write(result.data, { text: result.text, persist: false });
67
+ }
68
+ function emitEnvelope(ctx, operation, result) {
69
+ ctx.output.write({
70
+ schemaVersion: 1,
71
+ ok: true,
72
+ operation,
73
+ data: result.data === undefined ? null : result.data,
74
+ warnings: [],
75
+ }, { text: result.text, persist: false });
76
+ }
77
+ async function run(ctx, operation, input, envelope) {
78
+ const host = createDataHost(ctx);
79
+ const result = await executeDataOperation(operation, input, host);
80
+ if (envelope)
81
+ emitEnvelope(ctx, operation, result);
82
+ else
83
+ emit(ctx, result);
84
+ }
85
+ export const dataShortcut = {
86
+ name: 'data',
87
+ description: '泛微E10数据助手 CLI(数据源查询 / 配置中心 / 场景定位)',
88
+ category: 'shortcut',
89
+ register({ program, action }) {
90
+ const data = program.command('data').description('泛微E10数据助手(DSL 查询 / 数据源发现 / 配置中心 / 场景定位)');
91
+ data.command('schema')
92
+ .description('Print data operation manifest for agents')
93
+ .action(action((ctx) => {
94
+ ctx.output.write(dataManifest, { json: true, persist: false });
95
+ }));
96
+ data.command('run')
97
+ .description('Run a data operation with JSON input')
98
+ .argument('<operation>', `operation name, e.g. data.ds.count(共 ${operationNames().length} 个)`)
99
+ .option('--input <path>', 'JSON input file, or - for stdin')
100
+ .option('--input-json <json>', 'inline JSON input object')
101
+ .action(action(async (ctx, operation, options) => {
102
+ await run(ctx, String(operation), await inputFrom(options), true);
103
+ }));
104
+ // ---------------------------------------------------------------- query
105
+ data.command('query')
106
+ .description('直接执行 DSL 查询(executeQueryDsl)')
107
+ .option('--conn <connId>', '数据连接 ID(CONN_*)')
108
+ .option('--model <model>', '模型标识,如 dw / ebuilder / flow')
109
+ .option('--schema <schema>', '库名')
110
+ .option('--table-id <id>', '数据集 / 流程 ID')
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>', '问句日期起始年月(无则传空)')
118
+ .action(action(async (ctx, options) => {
119
+ await run(ctx, 'data.dsl.query', toInput(options), false);
120
+ }));
121
+ // ---------------------------------------------------------------- ds
122
+ const ds = data.command('ds').description('数据源:分组 / 找表 / 元数据 / 取数');
123
+ ds.command('groups')
124
+ .description('内置分组清单(仅用于 ds find 的默认扫描候选集)')
125
+ .option('--pattern <sub>', '按 groupId / 中文名过滤')
126
+ .action(action(async (ctx, options) => {
127
+ await run(ctx, 'data.ds.groups', toInput(options), false);
128
+ }));
129
+ ds.command('find')
130
+ .description('按关键词跨分组找表(并发扇出 + 本地过滤 + 路由建议)')
131
+ .option('--name <keyword>', '表名关键词')
132
+ .option('--keyword <keyword>', '同 --name')
133
+ .option('--source-type <type>', 'LOGIC / ETEAMS,默认 LOGIC')
134
+ .option('--size <n>', '每页条数(≤2000),默认 100')
135
+ .option('--pages <n>', '抓取页数(≤50),默认 1')
136
+ .option('--concurrency <n>', '进程内并发数,默认 10')
137
+ .option('--groups <a,b>', '显式指定扫描分组')
138
+ .option('--all-groups', '扫描全部 58 个分组')
139
+ .option('--max-groups <n>', '默认扫描集上限,默认 6')
140
+ .option('--app-id <id>', 'EB 分组按应用分域时显式传入')
141
+ .option('--limit <n>', '候选上限')
142
+ .option('--loose', '关闭本地关键词过滤')
143
+ .option('--no-escalate', '未命中时不升级全扫')
144
+ .action(action(async (ctx, options) => {
145
+ await run(ctx, 'data.ds.find', toInput(options), false);
146
+ }));
147
+ ds.command('describe')
148
+ .description('并发取字段元数据 + 词库,并给出关联字段/通道提示')
149
+ .option('--group <groupId>', '分组 ID')
150
+ .option('--table <tableId>', '数据集 ID')
151
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
152
+ .option('--app-id <id>', 'EB 分组应用 ID')
153
+ .option('--skill <skillKey>', '词库 skillKey,默认 data-source-query')
154
+ .option('--require', '存在失败分支时直接失败')
155
+ .action(action(async (ctx, options) => {
156
+ await run(ctx, 'data.ds.describe', toInput(options), false);
157
+ }));
158
+ ds.command('tables')
159
+ .description('列分组下的数据集(表)清单')
160
+ .option('--group <groupId>', '分组 ID')
161
+ .option('--name <keyword>', '表名关键词')
162
+ .option('--page <n>', '页码,默认 1')
163
+ .option('--size <n>', '每页条数,默认 100')
164
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
165
+ .option('--app-id <id>', 'EB 分组应用 ID')
166
+ .action(action(async (ctx, options) => {
167
+ await run(ctx, 'data.ds.tables', toInput(options), false);
168
+ }));
169
+ ds.command('fields')
170
+ .description('取数据集字段元数据(/api/ebuilder/common/ds/fields)')
171
+ .option('--group <groupId>', '分组 ID')
172
+ .option('--table <tableId>', '数据集 ID')
173
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
174
+ .option('--app-id <id>', 'EB 分组应用 ID')
175
+ .action(action(async (ctx, options) => {
176
+ await run(ctx, 'data.ds.fields', toInput(options), false);
177
+ }));
178
+ ds.command('fields-dsl')
179
+ .description('取 DSL 口径字段元数据(含 dataKey / formTableId)')
180
+ .option('--group <groupId>', '分组 ID')
181
+ .option('--table <tableId>', '数据集 ID')
182
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
183
+ .option('--app-id <id>', 'EB 分组应用 ID')
184
+ .action(action(async (ctx, options) => {
185
+ await run(ctx, 'data.ds.fields-dsl', toInput(options), false);
186
+ }));
187
+ ds.command('list')
188
+ .description('明细列表取数(getListDatas)')
189
+ .option('--group <groupId>', '分组 ID')
190
+ .option('--table <tableId>', '数据集 ID')
191
+ .option('--fields <a,b|@f>', '返回字段(逗号分隔)')
192
+ .option('--where <json|@file>', '条件树 / 条件数组')
193
+ .option('--order <expr>', '排序,如 "create_time desc"')
194
+ .option('--page <n>', '页码,默认 1')
195
+ .option('--size <n>', '每页条数,默认 20')
196
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
197
+ .option('--app-id <id>', 'EB 分组应用 ID')
198
+ .action(action(async (ctx, options) => {
199
+ await run(ctx, 'data.ds.list', toInput(options), false);
200
+ }));
201
+ ds.command('chart')
202
+ .description('分组聚合取数(getChartDatas)')
203
+ .option('--group <groupId>', '分组 ID')
204
+ .option('--table <tableId>', '数据集 ID')
205
+ .option('--group-by <a,b>', '分组字段')
206
+ .option('--stat <json|@file>', '统计字段(fieldId + aggregator)')
207
+ .option('--where <json|@file>', '条件树 / 条件数组')
208
+ .option('--page <n>', '页码')
209
+ .option('--size <n>', '每页条数,默认 100')
210
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
211
+ .option('--app-id <id>', 'EB 分组应用 ID')
212
+ .action(action(async (ctx, options) => {
213
+ await run(ctx, 'data.ds.chart', toInput(options), false);
214
+ }));
215
+ ds.command('stat')
216
+ .description('统计字段取数(getStatDatas)')
217
+ .option('--group <groupId>', '分组 ID')
218
+ .option('--table <tableId>', '数据集 ID')
219
+ .option('--stat <json|@file>', '统计字段(fieldId + aggregator)')
220
+ .option('--where <json|@file>', '条件树 / 条件数组')
221
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
222
+ .option('--app-id <id>', 'EB 分组应用 ID')
223
+ .action(action(async (ctx, options) => {
224
+ await run(ctx, 'data.ds.stat', toInput(options), false);
225
+ }));
226
+ ds.command('count')
227
+ .description('计数(getCountData)')
228
+ .option('--group <groupId>', '分组 ID')
229
+ .option('--table <tableId>', '数据集 ID')
230
+ .option('--where <json|@file>', '条件树 / 条件数组')
231
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
232
+ .option('--app-id <id>', 'EB 分组应用 ID')
233
+ .action(action(async (ctx, options) => {
234
+ await run(ctx, 'data.ds.count', toInput(options), false);
235
+ }));
236
+ // ---------------------------------------------------------------- noun
237
+ const noun = data.command('noun').description('词库(ChatBI 名词解释)');
238
+ noun.command('list')
239
+ .description('按 skill 取词库')
240
+ .option('--skill <skillKey>', 'skill 标识')
241
+ .option('--source-type <type>', '数据源类型')
242
+ .option('--source-group <groupId>', '数据源分组')
243
+ .option('--source-table <tableId>', '数据集 ID')
244
+ .action(action(async (ctx, options) => {
245
+ await run(ctx, 'data.noun.list', toInput(options), false);
246
+ }));
247
+ noun.command('scope')
248
+ .description('按数据集生效范围批量取词库')
249
+ .option('--ids <a,b|@f>', '数据集 id 列表(取自 scene items)')
250
+ .action(action(async (ctx, options) => {
251
+ await run(ctx, 'data.noun.scope', toInput(options), false);
252
+ }));
253
+ // ---------------------------------------------------------------- field
254
+ const field = data.command('field').description('字段值翻译 / 选项字典');
255
+ field.command('name2id')
256
+ .description('名称 → 字段值 id 候选(浏览按钮类字段)')
257
+ .option('--module <module>', '模块标识,如 hrm / workflow')
258
+ .option('--type <browserType>', '浏览按钮类型')
259
+ .option('--name <text>', '要翻译的名称')
260
+ .option('--form-param <json>', '表单参数')
261
+ .option('--eb-browser-param <json|@file>', 'EB 浏览参数')
262
+ .option('--property-type <type>', '属性类型')
263
+ .action(action(async (ctx, options) => {
264
+ await run(ctx, 'data.field.name2id', toInput(options), false);
265
+ }));
266
+ field.command('options')
267
+ .description('Select/Radio/Checkbox 选项值字典(id↔name)')
268
+ .option('--field-name <name>', '字段名(ds fields 返回的 name)')
269
+ .option('--obj-id <id>', '数据集 / 表 ID')
270
+ .option('--group <groupId>', '分组 ID')
271
+ .option('--source-type <type>', 'LOGIC / ETEAMS')
272
+ .action(action(async (ctx, options) => {
273
+ await run(ctx, 'data.field.options', toInput(options), false);
274
+ }));
275
+ // ---------------------------------------------------------------- conf
276
+ const conf = data.command('conf').description('环境参数配置中心(chatBi config map)');
277
+ conf.command('get')
278
+ .description('按 confKey 取单条配置')
279
+ .argument('<key>', 'confKey(CONN_/DS_/WF_/API_ 前缀可推导 confType)')
280
+ .option('--type <confType>', 'confType(默认由前缀推导)')
281
+ .option('--group <confGroup>', 'confGroup(confType=api 时建议显式指定)')
282
+ .action(action(async (ctx, key, options) => {
283
+ await run(ctx, 'data.conf.get', { ...toInput(options), keys: [key] }, false);
284
+ }));
285
+ conf.command('batch')
286
+ .description('批量取配置')
287
+ .argument('<keys...>', 'confKey 列表')
288
+ .option('--type <confType>', 'confType')
289
+ .option('--group <confGroup>', 'confGroup')
290
+ .action(action(async (ctx, keys, options) => {
291
+ await run(ctx, 'data.conf.batch', { ...toInput(options), keys }, false);
292
+ }));
293
+ conf.command('batch-file')
294
+ .description('按文件批量取配置(逐条单查)')
295
+ .argument('<file>', 'JSON 文件,或 @items.json')
296
+ .action(action(async (ctx, file, options) => {
297
+ await run(ctx, 'data.conf.batch-file', { ...toInput(options), batch_file: file }, false);
298
+ }));
299
+ conf.command('group')
300
+ .description('按 confType + confGroup 批量取回整组配置')
301
+ .argument('<confType>', 'confType,如 api')
302
+ .argument('<confGroup>', 'confGroup,如 workflow')
303
+ .option('--key <confKey>', '只取该组下的一条')
304
+ .action(action(async (ctx, confType, confGroup, options) => {
305
+ await run(ctx, 'data.conf.group', { ...toInput(options), keys: [confType, confGroup] }, false);
306
+ }));
307
+ conf.command('group-file')
308
+ .description('按文件批量取多个分组的配置')
309
+ .argument('<file>', 'JSON 文件,形如 [{confType, confGroup}]')
310
+ .action(action(async (ctx, file, options) => {
311
+ await run(ctx, 'data.conf.group-file', { ...toInput(options), group_file: file }, false);
312
+ }));
313
+ conf.command('resolve')
314
+ .description('把文本里的 #{KEY} 占位符替换为配置值')
315
+ .argument('<text>', "含 #{KEY} 的文本,或 @file.txt")
316
+ .option('--group <confGroup>', 'confGroup')
317
+ .action(action(async (ctx, text, options) => {
318
+ await run(ctx, 'data.conf.resolve', { ...toInput(options), text }, false);
319
+ }));
320
+ conf.command('resolve-file')
321
+ .description('按文件替换 #{KEY} 占位符')
322
+ .argument('<path>', '文本文件路径')
323
+ .option('--group <confGroup>', 'confGroup')
324
+ .action(action(async (ctx, path, options) => {
325
+ await run(ctx, 'data.conf.resolve-file', { ...toInput(options), path }, false);
326
+ }));
327
+ conf.command('add')
328
+ .description('新增配置(已存在默认跳过)')
329
+ .argument('<key>', 'confKey')
330
+ .option('--value <v>', '配置值')
331
+ .option('--name <n>', '配置名称')
332
+ .option('--attrs <json>', 'confAttrs')
333
+ .option('--type <confType>', 'confType')
334
+ .option('--group <confGroup>', 'confGroup')
335
+ .option('--force', '已存在时也重建')
336
+ .action(action(async (ctx, key, options) => {
337
+ await run(ctx, 'data.conf.add', { ...toInput(options), keys: [key] }, false);
338
+ }));
339
+ conf.command('add-file')
340
+ .description('按文件批量新增配置')
341
+ .argument('<file>', 'JSON 文件')
342
+ .option('--type <confType>', 'confType')
343
+ .option('--group <confGroup>', 'confGroup')
344
+ .action(action(async (ctx, file, options) => {
345
+ await run(ctx, 'data.conf.add-file', { ...toInput(options), add_file: file }, false);
346
+ }));
347
+ conf.command('update')
348
+ .description('更新配置的 value / name / attrs')
349
+ .argument('<key>', 'confKey')
350
+ .option('--value <v>', '配置值')
351
+ .option('--name <n>', '配置名称')
352
+ .option('--attrs <json>', 'confAttrs')
353
+ .option('--type <confType>', 'confType')
354
+ .option('--group <confGroup>', 'confGroup')
355
+ .action(action(async (ctx, key, options) => {
356
+ await run(ctx, 'data.conf.update', { ...toInput(options), keys: [key] }, false);
357
+ }));
358
+ conf.command('delete')
359
+ .description('删除配置')
360
+ .argument('<key>', 'confKey')
361
+ .option('--type <confType>', 'confType')
362
+ .option('--group <confGroup>', 'confGroup')
363
+ .action(action(async (ctx, key, options) => {
364
+ await run(ctx, 'data.conf.delete', { ...toInput(options), keys: [key] }, false);
365
+ }));
366
+ // ---------------------------------------------------------------- scene
367
+ const scene = data.command('scene').description('场景定位元数据(getSceneGroups)');
368
+ scene.command('groups')
369
+ .description('场景分组骨架')
370
+ .option('--client <client>', 'agent / all / connector,默认 agent')
371
+ .action(action(async (ctx, options) => {
372
+ await run(ctx, 'data.scene.groups', toInput(options), false);
373
+ }));
374
+ scene.command('items')
375
+ .description('组内条目(接口 / 数据源)')
376
+ .option('--group <groupId>', '分组 ID(19 位雪花号按字符串传)')
377
+ .option('--client <client>', 'agent / all / connector')
378
+ .action(action(async (ctx, options) => {
379
+ await run(ctx, 'data.scene.items', toInput(options), false);
380
+ }));
381
+ scene.command('search')
382
+ .description('关键词候选召回(后端 keyword 优先,本地打分兜底)')
383
+ .option('--keywords <a,b>', '关键词(也支持空格 / 、 分隔)')
384
+ .option('--keyword <a,b>', '同 --keywords')
385
+ .option('--client <client>', 'agent / all / connector')
386
+ .option('--max-groups <n>', '候选分组上限,默认 3')
387
+ .option('--max-items <n>', '每组条目上限,默认 12')
388
+ .option('--scope-group-id <id>', '限定单个分组')
389
+ .option('--server-filter <mode>', 'auto / on / off,默认 auto')
390
+ .action(action(async (ctx, options) => {
391
+ await run(ctx, 'data.scene.search', toInput(options), false);
392
+ }));
393
+ // ---------------------------------------------------------------- module
394
+ const moduleCommand = data.command('module').description('模块配置接口调用(配置中心驱动)');
395
+ moduleCommand.command('call')
396
+ .description('按 confAttrs 组参并调用接口(已确定模块 + 接口之后用)')
397
+ .option('--conf-key <key>', 'confKey')
398
+ .option('--group <module>', '模块唯一标识,如 WORKFLOW / EHR / DOCUMENT')
399
+ .option('--type <confType>', 'confType,默认 api')
400
+ .option('--conf-file <path>', '本地 confAttrs 文件(跳过配置读取)')
401
+ .option('--args <json|@file>', '业务参数(JSON 对象)')
402
+ .option('--query <k=v&k2=v2>', '业务参数(query 串,与 --args 合并)')
403
+ .option('--header <k: v>', '额外请求头(单个)')
404
+ .option('--headers <json|@file>', '额外请求头(JSON 对象)')
405
+ .option('--method <GET|POST|FORM>', '提交方式,默认取 confAttrs.http_method')
406
+ .option('--limit <n>', '行数上限,默认 50;0 = 不截断')
407
+ .option('--fields <a,b|@f>', '只保留这些行字段')
408
+ .option('--raw', '原样输出响应体')
409
+ .option('--show-params', '只打印入/出参说明,不调接口')
410
+ .option('--full', '--show-params 时回显完整 request_example')
411
+ .option('--with-example', '同 --full')
412
+ .option('--no-example', '--show-params 时强制省略 request_example')
413
+ .option('--dry-run', '只组装请求不发送(凭据脱敏)')
414
+ .option('--timeout <sec>', '超时秒数,默认 60')
415
+ .action(action(async (ctx, options) => {
416
+ await run(ctx, 'data.module.call', toInput(options), false);
417
+ }));
418
+ // ---------------------------------------------------------------- attend
419
+ const attend = data.command('attend').description('考勤 REST 接口');
420
+ attend.command('statis')
421
+ .description('考勤假期余额(年假 / 带薪病假 / 带薪事假)')
422
+ .option('--user <人员ID>', '查本人可不传,默认当前登录用户')
423
+ .option('--begin <yyyy-MM-dd>', '起始日期,默认当月 1 号')
424
+ .option('--end <yyyy-MM-dd>', '结束日期,默认当月最后一天')
425
+ .action(action(async (ctx, options) => {
426
+ await run(ctx, 'data.attend.statis', toInput(options), false);
427
+ }));
428
+ },
429
+ };