weaver-work-cli 0.1.6 → 0.1.7

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 (225) hide show
  1. package/README.md +14 -9
  2. package/dist/cmd/skills/index.js +60 -0
  3. package/dist/internal/e10/auth/commands.js +44 -31
  4. package/dist/internal/e10/auth/session.js +44 -3
  5. package/dist/internal/e10/auth/xiaoe.js +363 -11
  6. package/dist/internal/e10/context.js +4 -2
  7. package/dist/internal/skills/detector.js +42 -0
  8. package/dist/internal/skills/install.js +50 -3
  9. package/dist/shortcuts/archive/render/search-format.js +12 -3
  10. package/dist/shortcuts/ebuilder-form/continuation.js +70 -0
  11. package/dist/shortcuts/ebuilder-form/errors.js +54 -0
  12. package/dist/shortcuts/ebuilder-form/host.js +1238 -0
  13. package/dist/shortcuts/ebuilder-form/index.js +108 -0
  14. package/dist/shortcuts/ebuilder-form/manifest.js +347 -0
  15. package/dist/shortcuts/ebuilder-form/operations/read.js +157 -0
  16. package/dist/shortcuts/ebuilder-form/operations/registry.js +56 -0
  17. package/dist/shortcuts/ebuilder-form/operations/shared.js +132 -0
  18. package/dist/shortcuts/ebuilder-form/operations/types.js +19 -0
  19. package/dist/shortcuts/ebuilder-form/operations/write.js +277 -0
  20. package/dist/shortcuts/ebuilder-form/operations.js +8 -0
  21. package/dist/shortcuts/ehr/operations/salary.js +2 -140
  22. package/dist/shortcuts/im/continuation.js +70 -0
  23. package/dist/shortcuts/{yimiaoban → im}/errors.js +14 -14
  24. package/dist/shortcuts/{yimiaoban → im}/host.js +26 -26
  25. package/dist/shortcuts/{yimiaoban → im}/index.js +42 -42
  26. package/dist/shortcuts/{yimiaoban → im}/manifest.js +7 -6
  27. package/dist/shortcuts/{yimiaoban → im}/operations/file-user.js +54 -41
  28. package/dist/shortcuts/{yimiaoban → im}/operations/group-read.js +46 -44
  29. package/dist/shortcuts/{yimiaoban → im}/operations/group-write.js +113 -66
  30. package/dist/shortcuts/{yimiaoban → im}/operations/msg-sync.js +164 -141
  31. package/dist/shortcuts/{yimiaoban → im}/operations/msg-write.js +47 -47
  32. package/dist/shortcuts/{yimiaoban → im}/operations/person.js +10 -10
  33. package/dist/shortcuts/{yimiaoban → im}/operations/registry.js +10 -8
  34. package/dist/shortcuts/{yimiaoban → im}/operations/session.js +82 -83
  35. package/dist/shortcuts/im/operations/shared.js +442 -0
  36. package/dist/shortcuts/{yimiaoban → im}/operations/types.js +1 -1
  37. package/dist/shortcuts/im/operations/user-remind.js +201 -0
  38. package/dist/shortcuts/{yimiaoban → im}/operations/write-util.js +7 -7
  39. package/dist/shortcuts/{yimiaoban → im}/operations.js +3 -3
  40. package/dist/shortcuts/index.js +10 -2
  41. package/dist/shortcuts/invoice/manifest.js +113 -10
  42. package/dist/shortcuts/invoice/operations/import.js +39 -14
  43. package/dist/shortcuts/invoice/operations/reim.js +38 -18
  44. package/dist/shortcuts/invoice/operations/shared.js +35 -6
  45. package/dist/shortcuts/jiuchuanhui/manifest.js +3 -3
  46. package/dist/shortcuts/jiuchuanhui/operations/registry.js +2 -2
  47. package/dist/shortcuts/{yimiaoban → okr}/continuation.js +10 -10
  48. package/dist/shortcuts/okr/errors.js +70 -0
  49. package/dist/shortcuts/okr/host.js +169 -0
  50. package/dist/shortcuts/okr/index.js +155 -0
  51. package/dist/shortcuts/okr/manifest.js +70 -0
  52. package/dist/shortcuts/okr/operations/link.js +305 -0
  53. package/dist/shortcuts/okr/operations/read.js +481 -0
  54. package/dist/shortcuts/okr/operations/registry.js +31 -0
  55. package/dist/shortcuts/okr/operations/shared.js +381 -0
  56. package/dist/shortcuts/okr/operations/types.js +88 -0
  57. package/dist/shortcuts/okr/operations/write.js +838 -0
  58. package/dist/shortcuts/okr/operations.js +8 -0
  59. package/dist/shortcuts/project/continuation.js +70 -0
  60. package/dist/shortcuts/project/errors.js +53 -0
  61. package/dist/shortcuts/project/host.js +160 -0
  62. package/dist/shortcuts/project/index.js +106 -0
  63. package/dist/shortcuts/project/manifest.js +36 -0
  64. package/dist/shortcuts/project/operations/read.js +551 -0
  65. package/dist/shortcuts/project/operations/registry.js +31 -0
  66. package/dist/shortcuts/project/operations/shared.js +68 -0
  67. package/dist/shortcuts/project/operations/types.js +39 -0
  68. package/dist/shortcuts/project/operations/write.js +266 -0
  69. package/dist/shortcuts/project/operations.js +8 -0
  70. package/dist/shortcuts/workflow/continuation.js +508 -0
  71. package/dist/shortcuts/workflow/endpoints.js +149 -0
  72. package/dist/shortcuts/workflow/errors.js +112 -0
  73. package/dist/shortcuts/workflow/host.js +224 -0
  74. package/dist/shortcuts/workflow/index.js +116 -0
  75. package/dist/shortcuts/workflow/manifest.js +30 -0
  76. package/dist/shortcuts/workflow/operations/form.js +4159 -0
  77. package/dist/shortcuts/workflow/operations/read.js +3778 -0
  78. package/dist/shortcuts/workflow/operations/registry.js +33 -0
  79. package/dist/shortcuts/workflow/operations/shared.js +167 -0
  80. package/dist/shortcuts/workflow/operations/types.js +44 -0
  81. package/dist/shortcuts/workflow/operations/write.js +1991 -0
  82. package/dist/shortcuts/workflow/operations.js +119 -0
  83. package/dist/shortcuts/workflow/state.js +182 -0
  84. package/docs/SKILL.md +5 -3
  85. package/docs/_catalog.md +10 -1
  86. package/docs/agent-invoice.md +2 -2
  87. package/docs/agent-skill-install.md +2 -2
  88. package/docs/e10-auth.md +3 -1
  89. package/docs/ebuilder-form.md +38 -0
  90. package/docs/im.md +104 -0
  91. package/docs/invoice.md +5 -5
  92. package/docs/okr.md +122 -0
  93. package/docs/operation-manual.md +10 -7
  94. package/docs/project.md +69 -0
  95. package/docs/skill-review-2026-09-19.md +68 -0
  96. package/package.json +3 -2
  97. package/scripts/package-skill.mjs +38 -11
  98. package/scripts/sync-connector-skills.mjs +172 -0
  99. package/skill-template/business-info.json +357 -16
  100. package/skill-template/domains/ebuilder-form.md +5 -0
  101. package/skill-template/domains/okr.md +18 -0
  102. package/skill-template/domains/shijingran.md +3 -0
  103. package/skill-template/domains/skill-maker.md +4 -4
  104. package/skill-template/domains/workflow.md +22 -0
  105. package/skill-template/domains/yepiaotong.md +4 -2
  106. package/skill-template/domains/yimiaoban.md +13 -10
  107. package/skill-template/product.json +5 -0
  108. package/skill-template/skill-template.md +1 -0
  109. package/skills/weaver-e10-calendar/SKILL.md +5 -1
  110. package/skills/weaver-e10-calendar/references/calendar-query.md +7 -0
  111. package/skills/weaver-e10-calendar/references/source-manifest.json +314 -32
  112. package/skills/weaver-e10-ebuilder-form/SKILL.md +123 -0
  113. package/skills/weaver-e10-ebuilder-form/references/context-routing.md +90 -0
  114. package/skills/weaver-e10-ebuilder-form/references/custom-api.md +86 -0
  115. package/skills/weaver-e10-ebuilder-form/references/disabled-capabilities.md +50 -0
  116. package/skills/weaver-e10-ebuilder-form/references/fields-browser.md +100 -0
  117. package/skills/weaver-e10-ebuilder-form/references/list-nlist.md +91 -0
  118. package/skills/weaver-e10-ebuilder-form/references/openapi-read.md +74 -0
  119. package/skills/weaver-e10-ebuilder-form/references/openapi-write.md +86 -0
  120. package/skills/weaver-e10-ebuilder-form/references/source-manifest.json +107 -0
  121. package/skills/weaver-e10-esb/SKILL.md +1 -1
  122. package/skills/weaver-e10-esb/references/source-manifest.json +15 -14
  123. package/skills/weaver-e10-hrm/SKILL.md +1 -1
  124. package/skills/weaver-e10-hrm/references/source-manifest.json +357 -38
  125. package/skills/weaver-e10-jiuchuanhui/SKILL.md +22 -4
  126. package/skills/weaver-e10-jiuchuanhui/references/clue.md +4 -2
  127. package/skills/weaver-e10-jiuchuanhui/references/contact.md +1 -1
  128. package/skills/weaver-e10-jiuchuanhui/references/customer.md +3 -3
  129. package/skills/weaver-e10-jiuchuanhui/references/disabled-capabilities.md +1 -1
  130. package/skills/weaver-e10-jiuchuanhui/references/discovery-config.md +10 -10
  131. package/skills/weaver-e10-jiuchuanhui/references/general-helpers.md +3 -3
  132. package/skills/weaver-e10-jiuchuanhui/references/sale.md +7 -7
  133. package/skills/weaver-e10-jiuchuanhui/references/source-manifest.json +3 -3
  134. package/skills/weaver-e10-jucailin/SKILL.md +2 -2
  135. package/skills/weaver-e10-mail/SKILL.md +22 -6
  136. package/skills/weaver-e10-meeting/SKILL.md +22 -1
  137. package/skills/weaver-e10-okr/SKILL.md +139 -0
  138. package/skills/weaver-e10-okr/references/okr-align.md +59 -0
  139. package/skills/weaver-e10-okr/references/okr-keyresult.md +68 -0
  140. package/skills/weaver-e10-okr/references/okr-link-routing.md +67 -0
  141. package/skills/weaver-e10-okr/references/okr-query.md +105 -0
  142. package/skills/weaver-e10-okr/references/okr-write.md +94 -0
  143. package/skills/weaver-e10-okr/references/source-manifest.json +672 -0
  144. package/skills/weaver-e10-plan/SKILL.md +3 -3
  145. package/skills/weaver-e10-plan/references/plan-report-write.md +1 -1
  146. package/skills/weaver-e10-plan/references/source-manifest.json +20 -20
  147. package/skills/weaver-e10-qiyecheng/SKILL.md +21 -1
  148. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +17 -17
  149. package/skills/weaver-e10-shared/SKILL.md +79 -11
  150. package/skills/weaver-e10-shared/references/e10-auth-and-session.md +41 -8
  151. package/skills/weaver-e10-shared/references/non-interactive-environment.md +78 -0
  152. package/skills/weaver-e10-shared/references/weaver-e10-installation.md +39 -0
  153. package/skills/weaver-e10-shijingran/SKILL.md +83 -0
  154. package/skills/weaver-e10-shijingran/references/field-resolution.md +105 -0
  155. package/skills/weaver-e10-shijingran/references/operations.md +154 -0
  156. package/skills/weaver-e10-shijingran/references/source-manifest.json +1380 -0
  157. package/skills/weaver-e10-shijingran/references/write-operations.md +90 -0
  158. package/skills/weaver-e10-skill-maker/SKILL.md +26 -9
  159. package/skills/weaver-e10-skill-maker/references/business-skill-generation.md +39 -8
  160. package/skills/weaver-e10-skill-maker/references/detector-validation.md +25 -8
  161. package/skills/weaver-e10-skill-maker/references/module-cli-generation.md +66 -5
  162. package/skills/weaver-e10-skill-maker/references/module-gap-audit-and-repair.md +86 -0
  163. package/skills/weaver-e10-skill-maker/references/source-update-detection.md +59 -5
  164. package/skills/weaver-e10-skill-maker/references/weaver-skill-style.md +16 -8
  165. package/skills/weaver-e10-wenshuding/SKILL.md +28 -4
  166. package/skills/weaver-e10-wenshuding/references/archive-search.md +14 -0
  167. package/skills/weaver-e10-wenshuding/references/source-manifest.json +27 -26
  168. package/skills/weaver-e10-workflow/SKILL.md +250 -0
  169. package/skills/weaver-e10-workflow/references/source-manifest.json +1062 -0
  170. package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +96 -0
  171. package/skills/weaver-e10-workflow/references/workflow-batch.md +275 -0
  172. package/skills/weaver-e10-workflow/references/workflow-create.md +182 -0
  173. package/skills/weaver-e10-workflow/references/workflow-edit.md +106 -0
  174. package/skills/weaver-e10-workflow/references/workflow-memory.md +165 -0
  175. package/skills/weaver-e10-workflow/references/workflow-operate.md +153 -0
  176. package/skills/weaver-e10-workflow/references/workflow-query.md +821 -0
  177. package/skills/weaver-e10-workflow/references/workflow-share.md +117 -0
  178. package/skills/weaver-e10-workflow/references/workflow-view.md +189 -0
  179. package/skills/weaver-e10-yepiaotong/SKILL.md +28 -28
  180. package/skills/weaver-e10-yepiaotong/references/invoice-disabled-capabilities.md +11 -5
  181. package/skills/weaver-e10-yepiaotong/references/invoice-import.md +14 -8
  182. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-examples.md +9 -43
  183. package/skills/weaver-e10-yepiaotong/references/invoice-issuing.md +8 -0
  184. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +13 -17
  185. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +6 -7
  186. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +2 -2
  187. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +1155 -553
  188. package/skills/weaver-e10-yimiaoban/SKILL.md +56 -38
  189. package/skills/weaver-e10-yimiaoban/references/ding-write.md +8 -8
  190. package/skills/weaver-e10-yimiaoban/references/error-codes.md +16 -0
  191. package/skills/weaver-e10-yimiaoban/references/field-resolution.md +10 -10
  192. package/skills/weaver-e10-yimiaoban/references/file-user-i18n.md +12 -12
  193. package/skills/weaver-e10-yimiaoban/references/group-read.md +16 -16
  194. package/skills/weaver-e10-yimiaoban/references/group-write.md +17 -15
  195. package/skills/weaver-e10-yimiaoban/references/msg-read.md +21 -17
  196. package/skills/weaver-e10-yimiaoban/references/msg-write.md +10 -10
  197. package/skills/weaver-e10-yimiaoban/references/person.md +6 -6
  198. package/skills/weaver-e10-yimiaoban/references/safety-boundaries.md +15 -11
  199. package/skills/weaver-e10-yimiaoban/references/session-sysmsg.md +11 -10
  200. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +2164 -154
  201. package/skills/weaver-e10-yimiaoban/references/user-remind.md +75 -0
  202. package/skills/weaver-e10-ziguanjia/SKILL.md +4 -2
  203. package/skills/weaver-e10-ziguanjia/references/source-manifest.json +99 -29
  204. package/tools/weaver-skill-detector-1.0.13/SKILL.md +253 -0
  205. package/tools/weaver-skill-detector-1.0.13/_meta.json +6 -0
  206. package/tools/weaver-skill-detector-1.0.13/references/checklist.md +298 -0
  207. package/tools/weaver-skill-detector-1.0.13/scripts/validate_skill.py +4190 -0
  208. package/dist/shortcuts/yimiaoban/operations/shared.js +0 -236
  209. package/docs/yimiaoban.md +0 -86
  210. package/skills/weaver-e10-calendar/product.json +0 -8
  211. package/skills/weaver-e10-esb/product.json +0 -8
  212. package/skills/weaver-e10-hrm/product.json +0 -8
  213. package/skills/weaver-e10-jiuchuanhui/product.json +0 -8
  214. package/skills/weaver-e10-jucailin/product.json +0 -8
  215. package/skills/weaver-e10-mail/product.json +0 -8
  216. package/skills/weaver-e10-meeting/product.json +0 -8
  217. package/skills/weaver-e10-plan/product.json +0 -8
  218. package/skills/weaver-e10-qiyecheng/product.json +0 -8
  219. package/skills/weaver-e10-skill-maker/product.json +0 -8
  220. package/skills/weaver-e10-wenshuding/product.json +0 -8
  221. package/skills/weaver-e10-yepiaotong/product.json +0 -8
  222. package/skills/weaver-e10-yepiaotong/references/invoice-red.md +0 -261
  223. package/skills/weaver-e10-yimiaoban/product.json +0 -8
  224. package/skills/weaver-e10-ziguanjia/product.json +0 -8
  225. /package/dist/shortcuts/{yimiaoban → im}/operations/msg-parse.js +0 -0
@@ -0,0 +1,112 @@
1
+ import { CliError, ExitCode } from '../../core/errors.js';
2
+ export class WorkflowCliError extends CliError {
3
+ type;
4
+ subtype;
5
+ code;
6
+ retryable;
7
+ stage;
8
+ details;
9
+ partialData;
10
+ constructor(type, subtype, message, options = {}) {
11
+ super(message, options.exitCode ?? ExitCode.InternalError);
12
+ this.name = 'WorkflowCliError';
13
+ this.type = type;
14
+ this.subtype = subtype;
15
+ this.code = options.code;
16
+ this.retryable = options.retryable ?? false;
17
+ this.stage = options.stage;
18
+ this.details = options.details;
19
+ this.partialData = options.partialData;
20
+ }
21
+ }
22
+ export function workflowValidationError(subtype, message, details) {
23
+ return new WorkflowCliError('validation', subtype, message, {
24
+ details,
25
+ exitCode: ExitCode.UsageError,
26
+ });
27
+ }
28
+ export function workflowAuthError(subtype, message, details) {
29
+ return new WorkflowCliError('authentication', subtype, message, {
30
+ details,
31
+ exitCode: ExitCode.AuthError,
32
+ });
33
+ }
34
+ export function workflowApiError(subtype, message, options = {}) {
35
+ return new WorkflowCliError('api', subtype, message, {
36
+ ...options,
37
+ exitCode: ExitCode.GeneralError,
38
+ });
39
+ }
40
+ export function workflowNetworkError(subtype, message, options = {}) {
41
+ return new WorkflowCliError('network', subtype, message, {
42
+ ...options,
43
+ retryable: options.retryable ?? true,
44
+ exitCode: ExitCode.NetworkError,
45
+ });
46
+ }
47
+ export function workflowConfirmationError(action, details) {
48
+ return new WorkflowCliError('confirmation', 'required', '该操作需要明确确认', {
49
+ details: { action, ...details },
50
+ exitCode: ExitCode.ConfirmationRequired,
51
+ });
52
+ }
53
+ /**
54
+ * 写操作结果不确定:请求可能已经送达服务端并生效,但本地无法确认。
55
+ * 一律返回该错误,禁止自动重试,必须先做只读回查确认流程状态。
56
+ */
57
+ export function workflowPartialError(message, partialData, details) {
58
+ return new WorkflowCliError('partial', 'write_uncertain', message, {
59
+ details,
60
+ partialData,
61
+ exitCode: ExitCode.Partial,
62
+ });
63
+ }
64
+ /**
65
+ * 一次性 continuation 的**幂等重放**:上一次同句柄的 Apply 已经执行并且**成功**。
66
+ *
67
+ * 这不是失败——调度层(operations.ts)会把它转换成成功信封(`status: ALREADY_APPLIED`)。
68
+ * 之所以仍以错误形式在底层传递:`verify()/consume()` 只能返回「已占用」,无法直接产出信封。
69
+ *
70
+ * 来源:2026-09-16 线上——命令被执行两次(沙箱内首跑成功写入并消费句柄,宿主逃逸重跑),
71
+ * 重跑只能报 `continuation_consumed`,把**已经生效的写入报成失败**,模型被迫连查三次才确认真相。
72
+ */
73
+ export function workflowAlreadyAppliedError(operation, details) {
74
+ return new WorkflowCliError('validation', 'continuation_already_applied', `该 continuation 已经执行过且已成功(${operation}),本次未重复写入。`
75
+ + '请不要重跑 Prepare,也不要再次提交——如需确认结果,直接看本次返回的上一次执行结果。', { details, exitCode: ExitCode.UsageError });
76
+ }
77
+ export function workflowPolicyError(subtype, message, details) {
78
+ return new WorkflowCliError('policy', subtype, message, {
79
+ details,
80
+ exitCode: ExitCode.PolicyError,
81
+ });
82
+ }
83
+ /** 澄清错误的 subtype 标记(调度层据此转成功信封,见 operations.ts 的 clarificationEnvelope)。 */
84
+ export const CLARIFICATION_SUBTYPE = 'needs_clarification';
85
+ /**
86
+ * 名称→ID 解析需要用户澄清 —— **这不是失败**。
87
+ *
88
+ * 底层解析函数(`read.ts` 的 `resolveTerm` / `resolveRequestLevel` / `resolveFilterFieldItem` /
89
+ * `resolveFieldValues`)无法直接产出信封,故仍以错误形式向上抛;**调度层(`operations.ts`)会把它
90
+ * 转成成功信封**:`ok:true` + `data.type=workflowClarification` + `data.status=NEEDS_CLARIFICATION`。
91
+ * 这与 `workflow.createList` 已有的 `ok:true` + `status:SELECTED/NEEDS_SELECTION` 是同一套约定。
92
+ *
93
+ * 形态来源(对齐 V11.3):`e10_workflow.py:10356-10400`(工作流名 0 命中 / 多命中分支)与
94
+ * `resolve_system_name_condition`(L8262)都返回 `success:true` + `needClarification:true`
95
+ * (多命中时另带 `candidates` + `clarificationType` + `clarificationKeyword`),
96
+ * 文档见 `references/workflow-search.md`「异常返回处理 · 澄清后回传」。
97
+ *
98
+ * 覆盖的两种情形(与 V11.3 一致):
99
+ * 1. **0 命中** —— 名称在当前环境没有对应对象(`candidates` 为空);
100
+ * 2. **多命中且没有唯一全名精确匹配** —— 列出候选让用户挑;有唯一全名精确匹配时**不澄清**,直接用。
101
+ */
102
+ export function workflowClarificationError(clarificationType, keyword, question, candidates = []) {
103
+ return new WorkflowCliError('validation', CLARIFICATION_SUBTYPE, question, {
104
+ details: {
105
+ clarificationType,
106
+ clarificationKeyword: keyword,
107
+ clarificationQuestion: question,
108
+ candidates,
109
+ },
110
+ exitCode: ExitCode.UsageError,
111
+ });
112
+ }
@@ -0,0 +1,224 @@
1
+ import { requireE10Session } from '../../internal/e10/context.js';
2
+ import { getActiveProfile } from '../../internal/e10/auth/session.js';
3
+ import { createE10RequestRuntime } from '../../internal/e10/request-runtime.js';
4
+ import { workflowApiError, workflowAuthError, workflowNetworkError } from './errors.js';
5
+ const DEFAULT_TIMEOUT_MS = 30_000;
6
+ /**
7
+ * 登录失效关键词(与登录页/网关返回文本做大小写无关匹配)。
8
+ * 来源:原 Python skill `e10_workflow.py` 的 `LOGIN_EXPIRED_WORDS`,逐条对齐。
9
+ */
10
+ const LOGIN_EXPIRED_WORDS = [
11
+ '未登录',
12
+ '请登录',
13
+ '登录失效',
14
+ '登录超时',
15
+ '会话过期',
16
+ '认证失败',
17
+ '身份认证失败',
18
+ 'token失效',
19
+ 'token超时',
20
+ 'token过期',
21
+ 'token expired',
22
+ 'token timeout',
23
+ 'token invalid',
24
+ 'session expired',
25
+ 'login required',
26
+ 'not login',
27
+ 'not logged',
28
+ ];
29
+ /** 响应原文(用于 aTrust 重定向识别),等价原 Python `response_raw_text`。 */
30
+ function responseRawText(value) {
31
+ if (typeof value === 'string')
32
+ return value;
33
+ if (value === undefined || value === null)
34
+ return '';
35
+ try {
36
+ return JSON.stringify(value);
37
+ }
38
+ catch {
39
+ return String(value);
40
+ }
41
+ }
42
+ function payloadTexts(value) {
43
+ const texts = [];
44
+ if (typeof value === 'string') {
45
+ texts.push(value);
46
+ return texts;
47
+ }
48
+ if (!value || typeof value !== 'object')
49
+ return texts;
50
+ const record = value;
51
+ for (const key of ['code', 'status', 'message', 'msg', 'error', 'errorMsg', 'rawText']) {
52
+ const item = record[key];
53
+ if (item !== undefined && item !== null)
54
+ texts.push(String(item));
55
+ }
56
+ const data = record.data;
57
+ if (data && typeof data === 'object') {
58
+ const nested = data;
59
+ for (const key of ['code', 'status', 'message', 'msg', 'error', 'errorMsg']) {
60
+ const item = nested[key];
61
+ if (item !== undefined && item !== null)
62
+ texts.push(String(item));
63
+ }
64
+ }
65
+ return texts;
66
+ }
67
+ /**
68
+ * aTrust 网关重定向识别:3xx 且响应文本含 atrust。
69
+ * 来源:原 Python `is_atrust_redirect_response`。
70
+ */
71
+ export function isAtustRedirect(status, value) {
72
+ if (status === undefined || !(status >= 300 && status < 400))
73
+ return false;
74
+ return responseRawText(value).toLowerCase().includes('atrust');
75
+ }
76
+ /**
77
+ * 登录失效判定:401/403、aTrust 重定向、或响应文本命中登录失效特征。
78
+ * 来源:原 Python `is_login_expired_payload`。
79
+ */
80
+ export function isLoginExpired(value, httpStatus) {
81
+ if (httpStatus === 401 || httpStatus === 403)
82
+ return true;
83
+ if (isAtustRedirect(httpStatus, value))
84
+ return true;
85
+ const joined = payloadTexts(value).join('\n').toLowerCase();
86
+ if (joined.includes('login.jsp'))
87
+ return true;
88
+ if (joined.includes('<input') && joined.includes('password'))
89
+ return true;
90
+ return LOGIN_EXPIRED_WORDS.some((word) => joined.includes(word.toLowerCase()));
91
+ }
92
+ /**
93
+ * 业务错误提取。来源:原 Python `extract_api_business_error`,语义逐条对齐。
94
+ * 返回空串表示无业务错误。
95
+ */
96
+ export function extractApiBusinessError(payload) {
97
+ if (!payload || typeof payload !== 'object')
98
+ return '';
99
+ const record = payload;
100
+ const message = record.message;
101
+ if (message && typeof message === 'object') {
102
+ const info = message;
103
+ const errcode = String(info.errcode ?? '').trim();
104
+ const errmsg = String(info.errmsg ?? '').trim();
105
+ if (errcode && !['0', '200'].includes(errcode)) {
106
+ return errmsg || `接口错误码 ${errcode}`;
107
+ }
108
+ }
109
+ if (record.fail === true || record.status === false) {
110
+ for (const key of ['msg', 'message', 'error', 'errorMsg']) {
111
+ const value = record[key];
112
+ if (typeof value === 'string' && value.trim())
113
+ return value.trim();
114
+ }
115
+ if (record.code !== undefined && record.code !== null) {
116
+ return `接口返回状态异常,code=${String(record.code)}`;
117
+ }
118
+ }
119
+ return '';
120
+ }
121
+ function loginExpiredMessage() {
122
+ return 'OA 登录状态或系统认证信息无效,本次任务已停止。请先向用户确认 E10 登录域名,再运行 weaver-work-cli auth login --base-url <域名> --agent_type <当前智能体名称> 完成登录,随后重放原请求。';
123
+ }
124
+ export function createWorkflowHost(ctx, dependencies = {}) {
125
+ let session = null;
126
+ let sessionContext = null;
127
+ const requireSession = dependencies.requireSession || requireE10Session;
128
+ async function ensureSession() {
129
+ if (!session) {
130
+ session = await requireSession(ctx);
131
+ const options = ctx.getGlobalOptions();
132
+ sessionContext = {
133
+ baseUrl: session.getBaseUrl(),
134
+ profile: options.profile || getActiveProfile(),
135
+ userId: session.userId,
136
+ agentType: session.agentType,
137
+ ...(session.version ? { version: session.version } : {}),
138
+ ...(session.tenantKey ? { tenantKey: session.tenantKey } : {}),
139
+ ...(session.tenantName ? { tenantName: session.tenantName } : {}),
140
+ ...(session.department ? { department: session.department } : {}),
141
+ ...(session.subcompany ? { subcompany: session.subcompany } : {}),
142
+ ...(session.position ? { position: session.position } : {}),
143
+ };
144
+ }
145
+ return session;
146
+ }
147
+ async function getSession() {
148
+ await ensureSession();
149
+ return sessionContext;
150
+ }
151
+ async function run(request, responseType) {
152
+ const { method = 'POST', path, query, body, form, formData, operation, timeoutMs = DEFAULT_TIMEOUT_MS, } = request;
153
+ const runtime = createE10RequestRuntime(ctx, await ensureSession(), {
154
+ interceptors: dependencies.interceptors,
155
+ fetch: dependencies.fetch,
156
+ });
157
+ let response;
158
+ try {
159
+ const base = { method, path, query, body, form, formData, operation, timeoutMs, module: 'workflow' };
160
+ response = responseType === 'binary'
161
+ ? await runtime.requestBinary(base)
162
+ : await runtime.requestJson(base);
163
+ }
164
+ catch (error) {
165
+ const structured = error;
166
+ if (structured?.type === 'network') {
167
+ throw workflowNetworkError(structured.subtype || 'transport', structured.message || '网络请求失败', { retryable: false, details: structured.details });
168
+ }
169
+ throw error;
170
+ }
171
+ if ('content' in response) {
172
+ if (isLoginExpired({}, response.status)) {
173
+ throw workflowAuthError('session_expired', loginExpiredMessage(), { httpStatus: response.status });
174
+ }
175
+ return {
176
+ status: response.status,
177
+ value: {},
178
+ content: response.content,
179
+ contentType: response.contentType,
180
+ };
181
+ }
182
+ if (isLoginExpired(response.value, response.status)) {
183
+ throw workflowAuthError('session_expired', loginExpiredMessage(), {
184
+ httpStatus: response.status,
185
+ details: { endpointKey: operation, response: response.value },
186
+ });
187
+ }
188
+ if (response.parseError) {
189
+ if (response.status < 200 || response.status >= 300) {
190
+ throw workflowApiError('http_error', `OA 接口 HTTP ${response.status}`, {
191
+ code: response.status,
192
+ details: { status: response.status },
193
+ });
194
+ }
195
+ throw workflowNetworkError('protocol', `接口返回不是合法 JSON(HTTP ${response.status})`, { retryable: false });
196
+ }
197
+ if (response.status < 200 || response.status >= 300) {
198
+ throw workflowApiError('http_error', `OA 接口 HTTP ${response.status}`, {
199
+ code: response.status,
200
+ details: { status: response.status },
201
+ });
202
+ }
203
+ const businessError = extractApiBusinessError(response.value);
204
+ if (businessError) {
205
+ throw workflowApiError('business_error', `OA 接口返回错误,本次操作已停止。接口提示:${businessError}。如果您无法处理,请联系系统管理员。`, { details: { endpointKey: operation, businessError } });
206
+ }
207
+ return { status: response.status, value: response.value };
208
+ }
209
+ return {
210
+ async workflowRequest(request) {
211
+ const result = await run(request, 'json');
212
+ return result.value;
213
+ },
214
+ async workflowBinaryRequest(request) {
215
+ const result = await run(request, 'binary');
216
+ return {
217
+ content: result.content,
218
+ contentType: result.contentType || 'application/octet-stream',
219
+ status: result.status,
220
+ };
221
+ },
222
+ getSession,
223
+ };
224
+ }
@@ -0,0 +1,116 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { ExitCode, isCliError, toErrorEnvelope } from '../../core/errors.js';
3
+ import { createWorkflowContinuationSigner } from './continuation.js';
4
+ import { createWorkflowHost } from './host.js';
5
+ import { workflowManifest } from './manifest.js';
6
+ import { executeWorkflowOperation } from './operations.js';
7
+ import { workflowValidationError } from './errors.js';
8
+ function asOptions(value) {
9
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
10
+ }
11
+ async function readStdin() {
12
+ const chunks = [];
13
+ for await (const chunk of process.stdin) {
14
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
15
+ }
16
+ return Buffer.concat(chunks).toString('utf8');
17
+ }
18
+ function stripBom(value) {
19
+ return value.replace(/^\uFEFF+/u, '');
20
+ }
21
+ export async function inputFrom(options, extra = {}) {
22
+ const opts = asOptions(options);
23
+ if (opts.input && opts.inputJson) {
24
+ throw workflowValidationError('input_conflict', '不能同时传 --input 和 --input-json');
25
+ }
26
+ let input = {};
27
+ if (opts.inputJson) {
28
+ input = parseJsonInput(String(opts.inputJson), '--input-json');
29
+ }
30
+ if (opts.input) {
31
+ let raw;
32
+ try {
33
+ raw = stripBom(opts.input === '-' ? await readStdin() : await readFile(String(opts.input), 'utf8'));
34
+ }
35
+ catch {
36
+ throw workflowValidationError('input_unreadable', `无法读取 --input:${String(opts.input)}`);
37
+ }
38
+ input = parseJsonInput(raw, '--input');
39
+ }
40
+ return {
41
+ ...input,
42
+ ...Object.fromEntries(Object.entries(extra).filter(([, value]) => value !== undefined && value !== '')),
43
+ };
44
+ }
45
+ function parseJsonInput(raw, label) {
46
+ try {
47
+ const parsed = JSON.parse(stripBom(raw));
48
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
49
+ throw new Error('input must be an object');
50
+ }
51
+ return parsed;
52
+ }
53
+ catch {
54
+ throw workflowValidationError('input_invalid', `${label} 不是合法 JSON 对象`);
55
+ }
56
+ }
57
+ export function successEnvelope(operation, result) {
58
+ return {
59
+ schemaVersion: 1,
60
+ ok: true,
61
+ operation,
62
+ data: result.data === undefined ? null : result.data,
63
+ ...(result.meta ? { meta: result.meta } : {}),
64
+ warnings: [],
65
+ };
66
+ }
67
+ function failureEnvelope(error) {
68
+ const structured = error;
69
+ return {
70
+ schemaVersion: 1,
71
+ ok: false,
72
+ ...(structured?.partialData === undefined ? {} : { data: structured.partialData }),
73
+ error: toErrorEnvelope(error),
74
+ };
75
+ }
76
+ async function executeAndPrint(ctx, operation, input) {
77
+ try {
78
+ const result = await executeWorkflowOperation(operation, input, {
79
+ ctx,
80
+ host: createWorkflowHost(ctx),
81
+ continuation: createWorkflowContinuationSigner(ctx),
82
+ });
83
+ ctx.output.write(successEnvelope(operation, result), { json: true });
84
+ }
85
+ catch (error) {
86
+ console.error(JSON.stringify(failureEnvelope(error), null, 2));
87
+ process.exitCode = isCliError(error) ? error.exitCode : ExitCode.GeneralError;
88
+ }
89
+ }
90
+ function withJsonInputOptions(command) {
91
+ command
92
+ .option('--input <path>', 'JSON input file, or - for stdin')
93
+ .option('--input-json <json>', 'inline JSON input object');
94
+ return command;
95
+ }
96
+ export const workflowShortcut = {
97
+ name: 'workflow',
98
+ description: '泛微E10流程智能助手 CLI(查询/查看/操作/批量/发起/修改)',
99
+ category: 'shortcut',
100
+ register({ program, action }) {
101
+ const workflow = program
102
+ .command('workflow')
103
+ .description('泛微E10流程智能助手(待办/已办/我发起/全部、详情、操作、批量、发起、修改)');
104
+ workflow.command('schema')
105
+ .description('Print workflow operation manifest for agents')
106
+ .action(action((ctx) => {
107
+ ctx.output.write(workflowManifest, { json: true });
108
+ }));
109
+ withJsonInputOptions(workflow.command('run')
110
+ .description('Run a workflow operation with JSON input')
111
+ .argument('<operation>', 'operation name, e.g. workflow.search'))
112
+ .action(action(async (ctx, operation, options) => {
113
+ await executeAndPrint(ctx, String(operation), await inputFrom(options));
114
+ }));
115
+ },
116
+ };
@@ -0,0 +1,30 @@
1
+ import { workflowOperationDefinitions } from './operations/registry.js';
2
+ /**
3
+ * 禁用边界:本模块保留原 skill 的全部可自动化能力,暂无可声明为"暂缓"的 operation。
4
+ * 明确不在本模块范围的能力(例如"姓名 → 人员 ID"解析)由 weaver-e10-hrm 提供,
5
+ * 不属于流程模块的 operation。
6
+ */
7
+ const WITHHELD = [];
8
+ function buildOperations() {
9
+ return workflowOperationDefinitions().map((definition) => ({
10
+ name: definition.name,
11
+ resource: definition.resource,
12
+ summary: definition.summary,
13
+ ...(definition.capability ? { capability: definition.capability } : {}),
14
+ risk: definition.risk,
15
+ ...(definition.requiresConfirmation ? { requiresConfirmation: true } : {}),
16
+ inputSchema: definition.inputSchema,
17
+ }));
18
+ }
19
+ export const workflowManifest = {
20
+ schemaVersion: 1,
21
+ name: 'workflow',
22
+ title: '泛微E10流程智能助手(查询/查看/操作/批量/发起/修改)',
23
+ version: '0.1.0',
24
+ host: 'e10-workflow',
25
+ status: 'builtin',
26
+ sourceSkill: 'weaver-e10-workflow',
27
+ capabilities: ['workflow'],
28
+ operations: buildOperations(),
29
+ withheldOperations: WITHHELD,
30
+ };