weaver-work-cli 0.1.31 → 0.1.33

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 (186) hide show
  1. package/README.md +2 -2
  2. package/dist/chunks/{archive-U766FTFH.js → archive-FVFY6GZN.js} +2 -2
  3. package/dist/chunks/{archive-oa-DMWEKX3L.js → archive-oa-NW3OD4UV.js} +2 -2
  4. package/dist/chunks/{asset-TCR7VDEV.js → asset-7QJKMIDV.js} +2 -2
  5. package/dist/chunks/{attachment-content-AQNX5N3S.js → attachment-content-OSAVA6K3.js} +3 -2
  6. package/dist/chunks/{blog-EVZWGDVM.js → blog-I7SDPNW4.js} +2 -2
  7. package/dist/chunks/{caizhilian-JOWS6SL5.js → caizhilian-O37ZIQNY.js} +2 -2
  8. package/dist/chunks/{calendar-5WNCV66Q.js → calendar-7KXE4ED3.js} +2 -2
  9. package/dist/chunks/{chunk-VZTXRG6X.js → chunk-2FLWXFVS.js} +4 -4
  10. package/dist/chunks/{chunk-QWY6PGL6.js → chunk-2LV74IWP.js} +361 -56
  11. package/dist/chunks/chunk-3SO6QL6U.js +73 -0
  12. package/dist/chunks/{chunk-H3WDBYJW.js → chunk-6ATGWRZM.js} +6 -4
  13. package/dist/chunks/chunk-BYATLLEF.js +68 -0
  14. package/dist/chunks/chunk-BYBSCN4X.js +932 -0
  15. package/dist/chunks/{chunk-324YPTC2.js → chunk-D223PTXU.js} +11 -2
  16. package/dist/chunks/{chunk-R2IJAK7T.js → chunk-EEWPQE3O.js} +2 -2
  17. package/dist/chunks/{chunk-J7RJTZSV.js → chunk-GFPXQIY2.js} +2 -2
  18. package/dist/chunks/{chunk-AC7KJWC5.js → chunk-HEL5XTYI.js} +12 -6
  19. package/dist/chunks/{chunk-CVZ2JOSW.js → chunk-IHUYP6LO.js} +1 -1
  20. package/dist/chunks/{chunk-R7O5PUWO.js → chunk-ILMBNVSG.js} +2 -2
  21. package/dist/chunks/{chunk-6V7ZLF34.js → chunk-KAS45KNR.js} +1 -1
  22. package/dist/chunks/{chunk-H6XSTSLM.js → chunk-MEEFGWTM.js} +54 -196
  23. package/dist/chunks/{chunk-GCG2NMWR.js → chunk-MQ2I5AA3.js} +4 -2
  24. package/dist/chunks/chunk-NHA62QD7.js +774 -0
  25. package/dist/chunks/{chunk-2DUV44UX.js → chunk-OCU4RLHC.js} +641 -309
  26. package/dist/chunks/{chunk-65QMVWHS.js → chunk-PRHJGPMA.js} +2 -2
  27. package/dist/chunks/{chunk-WHD4XMRP.js → chunk-Q6LWB5HX.js} +2 -2
  28. package/dist/chunks/{chunk-D4LTJSJD.js → chunk-RBGOMK4Y.js} +50 -33
  29. package/dist/chunks/chunk-VBCFFFGT.js +226 -0
  30. package/dist/chunks/{ebuilder-form-NJ4YK6CC.js → chunk-WRRJ4GG2.js} +22 -1148
  31. package/dist/chunks/{chunk-RCGYCOMG.js → chunk-WY74UBJ6.js} +264 -750
  32. package/dist/chunks/conflict-SFNEVJY5.js +21 -0
  33. package/dist/chunks/continuation-RN6PZN2M.js +11 -0
  34. package/dist/chunks/cowork-CKWYHXYB.js +2508 -0
  35. package/dist/chunks/ebuilder-form-KOLJRVZD.js +121 -0
  36. package/dist/chunks/{ehr-MMYN36VA.js → ehr-WFOC3B4D.js} +1174 -20
  37. package/dist/chunks/{esb-HIWHOU7Q.js → esb-LJZTN663.js} +4 -4
  38. package/dist/chunks/{fna-KBACQTA5.js → fna-F7QRIIZC.js} +2 -2
  39. package/dist/chunks/{host-3OHS5QUX.js → host-BCGUVEWX.js} +3 -3
  40. package/dist/chunks/host-BQBRHVR3.js +23 -0
  41. package/dist/chunks/{host-KQL5N4HO.js → host-DGE2TZD4.js} +3 -3
  42. package/dist/chunks/{host-LLSZQCWR.js → host-KXPTEWFS.js} +3 -3
  43. package/dist/chunks/{host-IG6KEH5Q.js → host-VQ6JJXGQ.js} +3 -3
  44. package/dist/chunks/{hrm-LYEC67ZQ.js → hrm-NI6XAKW5.js} +3 -3
  45. package/dist/chunks/{im-RN2UKAEU.js → im-7TRTF3KT.js} +88 -12
  46. package/dist/chunks/{invoice-EEPHLAF6.js → invoice-AOXWJKYT.js} +3 -3
  47. package/dist/chunks/{jiuchuanhui-WVVZYSJE.js → jiuchuanhui-7NQWEZAW.js} +2 -2
  48. package/dist/chunks/{lazy-dispatch-MDOFFL2S.js → lazy-dispatch-RNS4EE4S.js} +4 -4
  49. package/dist/chunks/{mail-LNQLTF6L.js → mail-VDHJAB4O.js} +3 -3
  50. package/dist/chunks/{meeting-XSD3BDVQ.js → meeting-GA7XCNNP.js} +214 -43
  51. package/dist/chunks/{okr-TMWTIU2K.js → okr-TQIRERPQ.js} +2 -2
  52. package/dist/chunks/operations-5QL3AECO.js +11 -0
  53. package/dist/chunks/{plan-A2FSFA7T.js → plan-4RY4LN2P.js} +2 -2
  54. package/dist/chunks/{project-T26QLBQF.js → project-D6XT2OC5.js} +2 -2
  55. package/dist/chunks/{registry-JCFEYXOE.js → registry-JHRIDQ3A.js} +4 -4
  56. package/dist/chunks/{registry-2VLUAESA.js → registry-OZSMDVPP.js} +2 -2
  57. package/dist/chunks/{registry-ZJMJVWFA.js → registry-QKMI43Q6.js} +8 -6
  58. package/dist/chunks/{registry-Q7OQJ3SU.js → registry-VOGKFFTR.js} +2 -2
  59. package/dist/chunks/{room-recommend-UR4ZDZS6.js → room-recommend-D4EUOOWY.js} +4 -3
  60. package/dist/chunks/{schedule-5L2PM4M6.js → schedule-XPFBHPCV.js} +4 -3
  61. package/dist/chunks/{workflow-TR6PG2SL.js → workflow-HLBZRWIY.js} +172 -6
  62. package/dist/core/package-paths.js +16 -2
  63. package/dist/index.js +30 -25
  64. package/dist/internal/e10/auth-recovery.js +14 -4
  65. package/dist/shortcuts/contract/host.js +34 -59
  66. package/dist/shortcuts/cowork/continuation.js +70 -0
  67. package/dist/shortcuts/cowork/errors.js +59 -0
  68. package/dist/shortcuts/cowork/host.js +172 -0
  69. package/dist/shortcuts/cowork/index.js +166 -0
  70. package/dist/shortcuts/cowork/manifest.js +65 -0
  71. package/dist/shortcuts/cowork/operations/discuss-write.js +277 -0
  72. package/dist/shortcuts/cowork/operations/item-write.js +380 -0
  73. package/dist/shortcuts/cowork/operations/member-write.js +283 -0
  74. package/dist/shortcuts/cowork/operations/permission-write.js +286 -0
  75. package/dist/shortcuts/cowork/operations/read.js +423 -0
  76. package/dist/shortcuts/cowork/operations/registry.js +39 -0
  77. package/dist/shortcuts/cowork/operations/review-write.js +157 -0
  78. package/dist/shortcuts/cowork/operations/shared.js +215 -0
  79. package/dist/shortcuts/cowork/operations/types.js +24 -0
  80. package/dist/shortcuts/cowork/operations.js +19 -0
  81. package/dist/shortcuts/ehr/host.js +4 -1
  82. package/dist/shortcuts/ehr/operations/recruit-candidate-import.js +757 -0
  83. package/dist/shortcuts/ehr/operations/recruit-position.js +367 -0
  84. package/dist/shortcuts/ehr/operations/recruit-stats.js +133 -0
  85. package/dist/shortcuts/ehr/operations/recruit-write.js +8 -16
  86. package/dist/shortcuts/ehr/operations/recruit.js +35 -10
  87. package/dist/shortcuts/ehr/operations/registry.js +6 -0
  88. package/dist/shortcuts/im/diagnostics.js +97 -0
  89. package/dist/shortcuts/im/host.js +58 -31
  90. package/dist/shortcuts/im/index.js +7 -2
  91. package/dist/shortcuts/im/operations/at-mention.js +127 -0
  92. package/dist/shortcuts/im/operations/file-user.js +10 -2
  93. package/dist/shortcuts/im/operations/group-read.js +26 -5
  94. package/dist/shortcuts/im/operations/group-write.js +35 -28
  95. package/dist/shortcuts/im/operations/msg-sync.js +7 -2
  96. package/dist/shortcuts/im/operations/msg-write.js +76 -10
  97. package/dist/shortcuts/im/operations/quote-mention.js +119 -0
  98. package/dist/shortcuts/im/operations/session.js +1 -1
  99. package/dist/shortcuts/im/operations/shared.js +10 -0
  100. package/dist/shortcuts/im/operations/types.js +13 -0
  101. package/dist/shortcuts/index.js +5 -0
  102. package/dist/shortcuts/mail/host.js +4 -1
  103. package/dist/shortcuts/meeting/host.js +27 -34
  104. package/dist/shortcuts/meeting/operations/create.js +4 -1
  105. package/dist/shortcuts/meeting/operations/eb/catalog.js +5 -0
  106. package/dist/shortcuts/meeting/operations/eb/conflict.js +78 -7
  107. package/dist/shortcuts/meeting/operations/eb/create-flow.js +168 -26
  108. package/dist/shortcuts/meeting/operations/eb/factory.js +69 -1
  109. package/dist/shortcuts/meeting/operations/eb/index.js +16 -3
  110. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +14 -3
  111. package/dist/shortcuts/meeting/operations/eb-fallback.js +159 -0
  112. package/dist/shortcuts/meeting/operations/env.js +93 -46
  113. package/dist/shortcuts/meeting/operations/form-fields.js +110 -0
  114. package/dist/shortcuts/meeting/operations/registry.js +2 -0
  115. package/dist/shortcuts/meeting/operations/standard-guard.js +71 -0
  116. package/dist/shortcuts/meeting/operations.js +16 -0
  117. package/dist/shortcuts/workflow/index.js +110 -1
  118. package/dist/shortcuts/workflow/operations/form.js +24 -3
  119. package/dist/shortcuts/workflow/operations/read.js +104 -23
  120. package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupRules.js +448 -0
  121. package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupStore.js +106 -0
  122. package/dist/shortcuts/workflow/operations/todoSmartConvert/businessRules.js +47 -0
  123. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +30 -23
  124. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +1 -0
  125. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +1 -0
  126. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.groupSummary.js +2 -1
  127. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +2 -4
  128. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +138 -181
  129. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.summary.js +12 -7
  130. package/docs/e10-auth.md +1 -1
  131. package/docs/im.md +8 -1
  132. package/docs/todo-smart-convert/README.md +1 -1
  133. package/docs/todo-smart-convert/data-contract.md +2 -2
  134. package/docs/todo-smart-convert/subgroup-rules.md +6 -0
  135. package/package.json +1 -1
  136. package/skill-template/domains/yimiaoban.md +3 -3
  137. package/skill-template/skill-template.md +1 -1
  138. package/skills/weaver-e10-blog/SKILL.md +5 -5
  139. package/skills/weaver-e10-caizhilian/SKILL.md +5 -5
  140. package/skills/weaver-e10-calendar/SKILL.md +5 -5
  141. package/skills/weaver-e10-esb/SKILL.md +5 -5
  142. package/skills/weaver-e10-hrm/SKILL.md +5 -5
  143. package/skills/weaver-e10-jinchengda/SKILL.md +2 -2
  144. package/skills/weaver-e10-jiuchuanhui/SKILL.md +5 -5
  145. package/skills/weaver-e10-jucailin/SKILL.md +18 -12
  146. package/skills/weaver-e10-jucailin/references/recruit-create.md +104 -0
  147. package/skills/weaver-e10-mail/SKILL.md +5 -5
  148. package/skills/weaver-e10-meeting/SKILL.md +171 -25
  149. package/skills/weaver-e10-meeting/references/meeting-eb.md +4 -3
  150. package/skills/weaver-e10-meeting/references/meeting-queries.md +9 -6
  151. package/skills/weaver-e10-meeting/references/meeting-verification.md +8 -6
  152. package/skills/weaver-e10-meeting.zip +0 -0
  153. package/skills/weaver-e10-okr/SKILL.md +5 -5
  154. package/skills/weaver-e10-okr/references/source-manifest.json +3 -3
  155. package/skills/weaver-e10-plan/SKILL.md +5 -5
  156. package/skills/weaver-e10-shared/SKILL.md +12 -12
  157. package/skills/weaver-e10-shared/references/e10-auth-and-session.md +4 -4
  158. package/skills/weaver-e10-wenshuding/SKILL.md +5 -5
  159. package/skills/weaver-e10-workflow/SKILL.md +29 -5
  160. package/skills/weaver-e10-workflow/aigroup/default.json +88 -0
  161. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +66 -14
  162. package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +1 -1
  163. package/skills/weaver-e10-workflow/references/workflow-memory.md +1 -1
  164. package/skills/weaver-e10-workflow/references/workflow-query.md +12 -10
  165. package/skills/weaver-e10-workflow/references/workflow-view.md +2 -2
  166. package/skills/weaver-e10-workflow/tools/todo-serve.cjs +239 -0
  167. package/skills/weaver-e10-workflow/{scripts → tools}/todo-summary.cjs +218 -28
  168. package/skills/weaver-e10-yepiaotong/SKILL.md +10 -8
  169. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +7 -7
  170. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +10 -10
  171. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +40 -37
  172. package/skills/weaver-e10-yepiaotong/references/reim-expense-subject-rules.md +4 -4
  173. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +27 -38
  174. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +4 -4
  175. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +37 -29
  176. package/skills/weaver-e10-yimiaoban/SKILL.md +156 -33
  177. package/skills/weaver-e10-yimiaoban/references/ding-write.md +1 -1
  178. package/skills/weaver-e10-yimiaoban/references/error-codes.md +5 -1
  179. package/skills/weaver-e10-yimiaoban/references/group-read.md +5 -1
  180. package/skills/weaver-e10-yimiaoban/references/group-write.md +6 -4
  181. package/skills/weaver-e10-yimiaoban/references/msg-read.md +1 -0
  182. package/skills/weaver-e10-yimiaoban/references/msg-write.md +34 -2
  183. package/skills/weaver-e10-yimiaoban/references/safety-boundaries.md +5 -2
  184. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +79 -58
  185. package/skills/weaver-e10-yimiaoban/references/user-remind.md +2 -2
  186. package/skills/weaver-e10-ziguanjia/SKILL.md +5 -5
@@ -0,0 +1,59 @@
1
+ import { CliError, ExitCode } from '../../core/errors.js';
2
+ export class CoworkCliError 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 = 'CoworkCliError';
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 coworkValidationError(subtype, message, details) {
23
+ return new CoworkCliError('validation', subtype, message, {
24
+ details,
25
+ exitCode: ExitCode.UsageError,
26
+ });
27
+ }
28
+ export function coworkAuthError(subtype, message, details) {
29
+ return new CoworkCliError('authentication', subtype, message, {
30
+ details,
31
+ exitCode: ExitCode.AuthError,
32
+ });
33
+ }
34
+ export function coworkNetworkError(subtype, message, options = {}) {
35
+ return new CoworkCliError('network', subtype, message, {
36
+ ...options,
37
+ retryable: options.retryable ?? true,
38
+ exitCode: ExitCode.NetworkError,
39
+ });
40
+ }
41
+ export function coworkConfirmationError(action, details) {
42
+ return new CoworkCliError('confirmation', 'required', '该操作需要明确确认', {
43
+ details: { action, ...details },
44
+ exitCode: ExitCode.ConfirmationRequired,
45
+ });
46
+ }
47
+ export function coworkPartialError(message, partialData, details) {
48
+ return new CoworkCliError('partial', 'write_uncertain', message, {
49
+ details,
50
+ partialData,
51
+ exitCode: ExitCode.Partial,
52
+ });
53
+ }
54
+ export function coworkNotFoundError(subtype, message, details) {
55
+ return new CoworkCliError('not_found', subtype, message, {
56
+ details,
57
+ exitCode: ExitCode.UsageError,
58
+ });
59
+ }
@@ -0,0 +1,172 @@
1
+ import { E10_SESSION_EXPIRED_MESSAGE } from '../../internal/e10/auth/messages.js';
2
+ import { requireE10Session } from '../../internal/e10/context.js';
3
+ import { getActiveProfile } from '../../internal/e10/auth/session.js';
4
+ import { E10ApiError, createE10RequestRuntime } from '../../internal/e10/request-runtime.js';
5
+ import { CoworkCliError, coworkAuthError, coworkNetworkError, coworkValidationError } from './errors.js';
6
+ function inferProfile(ctx) {
7
+ const options = ctx.getGlobalOptions();
8
+ return options.profile || getActiveProfile();
9
+ }
10
+ /**
11
+ * 协作接口成功判定(口径取自技能侧 cowork-write.mjs 的 `opOk`,真机实测)。
12
+ *
13
+ * 协作各子系统的响应形状不统一:
14
+ * - 主流程写操作:`{ status: true, id }` / `data: "SUCCESS"` / `data: 1`
15
+ * - 查询/列表:`{ code: 200, status: true, msg, data: {...} }`
16
+ * - 行为/审批:`data: "SUCCESS"`,data 也可能直接是 `true`
17
+ * 因此按「根 status / code 200 / data 的 SUCCESS|1|true / data.status」四路判定。
18
+ */
19
+ export function isCoworkSuccess(value) {
20
+ if (value === 'SUCCESS' || value === 1 || value === true)
21
+ return true;
22
+ if (!value || typeof value !== 'object')
23
+ return false;
24
+ if (value.fail === true)
25
+ return false;
26
+ if (value.status === true)
27
+ return true;
28
+ if (value.code !== undefined && value.code !== null && Number(value.code) === 200)
29
+ return true;
30
+ const data = value.data;
31
+ if (data === 'SUCCESS' || data === 1 || data === true)
32
+ return true;
33
+ if (data && typeof data === 'object' && data.status === true)
34
+ return true;
35
+ return false;
36
+ }
37
+ export function coworkBusinessMessage(value) {
38
+ if (!value || typeof value !== 'object')
39
+ return '协作接口返回业务失败';
40
+ const candidates = [value.msg, value.message, value.data?.msg, value.data?.message, value.error];
41
+ for (const item of candidates) {
42
+ if (typeof item === 'string' && item.trim())
43
+ return item;
44
+ }
45
+ return '协作接口返回业务失败';
46
+ }
47
+ function coworkBusinessCode(value) {
48
+ if (!value || typeof value !== 'object')
49
+ return undefined;
50
+ const code = value.code ?? value.status;
51
+ if (typeof code === 'string' || typeof code === 'number')
52
+ return code;
53
+ return undefined;
54
+ }
55
+ export function assertPath(requestPath) {
56
+ if (typeof requestPath !== 'string' || !requestPath.startsWith('/') || requestPath.startsWith('//')) {
57
+ throw coworkValidationError('path_invalid', '请求路径必须是相对绝对路径');
58
+ }
59
+ if (/^https?:/i.test(requestPath) || /[\r\n]/.test(requestPath) || requestPath.includes('/../')) {
60
+ throw coworkValidationError('path_invalid', '请求路径不允许跨域或路径逃逸');
61
+ }
62
+ if (!requestPath.startsWith('/api/cowork/')) {
63
+ throw coworkValidationError('path_not_allowed', '协作模块只能调用 /api/cowork/ 路径');
64
+ }
65
+ }
66
+ function formBody(form) {
67
+ if (!form)
68
+ return undefined;
69
+ const params = new URLSearchParams();
70
+ for (const [key, value] of Object.entries(form)) {
71
+ if (value === undefined || value === null)
72
+ continue;
73
+ params.set(key, typeof value === 'string' ? value : String(value));
74
+ }
75
+ return params;
76
+ }
77
+ function omitEmptyQueryValues(query) {
78
+ if (!query)
79
+ return undefined;
80
+ return Object.fromEntries(Object.entries(query).filter(([, value]) => value !== ''));
81
+ }
82
+ function mapRuntimeNetworkError(error) {
83
+ if (error instanceof E10ApiError && error.type === 'network') {
84
+ throw coworkNetworkError(error.subtype, error.message, {
85
+ retryable: error.retryable,
86
+ details: error.details,
87
+ });
88
+ }
89
+ throw error;
90
+ }
91
+ export function createCoworkHost(ctx, dependencies = {}) {
92
+ let e10Session = null;
93
+ let sessionContext = null;
94
+ // 与 workflow 模块同口径(2026-10-29 实测):auth 文件里已有登录时落盘的 userId,
95
+ // 业务命令不需要 teamsCheck 的登录人信息富化 ⇒ 跳过它,省掉每次调用一次串行 HTTPS 往返(实测约 150~250ms)。
96
+ const requireSession = dependencies.requireSession
97
+ || ((innerCtx) => requireE10Session(innerCtx, { skipProfileEnrichment: true }));
98
+ async function ensureSession() {
99
+ if (!e10Session) {
100
+ e10Session = await requireSession(ctx);
101
+ sessionContext = {
102
+ baseUrl: e10Session.getBaseUrl(),
103
+ profile: inferProfile(ctx),
104
+ userId: e10Session.userId,
105
+ tenantKey: e10Session.tenantKey,
106
+ eteamsId: e10Session.eteamsId,
107
+ };
108
+ }
109
+ return e10Session;
110
+ }
111
+ async function getSession() {
112
+ await ensureSession();
113
+ return sessionContext;
114
+ }
115
+ async function runtime() {
116
+ return createE10RequestRuntime(ctx, await ensureSession(), {
117
+ interceptors: dependencies.interceptors,
118
+ fetch: dependencies.fetch,
119
+ });
120
+ }
121
+ async function request(request) {
122
+ const { method, path, query, body, form, operation, headers: extraHeaders = {}, timeoutMs = 30_000, } = request;
123
+ assertPath(path);
124
+ const resolvedMethod = method || (body === undefined && form === undefined ? 'GET' : 'POST');
125
+ let response;
126
+ try {
127
+ response = await (await runtime()).requestJson({
128
+ module: 'cowork',
129
+ operation,
130
+ method: resolvedMethod,
131
+ path,
132
+ query: omitEmptyQueryValues(query),
133
+ body: form === undefined ? body : undefined,
134
+ form: form === undefined ? undefined : formBody(form),
135
+ headers: { 'X-Requested-With': 'XMLHttpRequest', ...extraHeaders },
136
+ timeoutMs,
137
+ });
138
+ }
139
+ catch (error) {
140
+ mapRuntimeNetworkError(error);
141
+ }
142
+ if (response.status === 401 || response.status === 302) {
143
+ throw coworkAuthError('session_expired', E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
144
+ }
145
+ if (response.parseError) {
146
+ if (response.status < 200 || response.status >= 300) {
147
+ throw new CoworkCliError('api', 'http_error', `协作接口 HTTP ${response.status}`, {
148
+ code: response.status,
149
+ details: { status: response.status },
150
+ exitCode: 1,
151
+ });
152
+ }
153
+ throw coworkNetworkError('protocol', `接口返回不是合法 JSON(HTTP ${response.status})`, { retryable: false });
154
+ }
155
+ if (response.status < 200 || response.status >= 300) {
156
+ throw new CoworkCliError('api', 'http_error', `协作接口 HTTP ${response.status}`, {
157
+ code: response.status,
158
+ details: { status: response.status, message: coworkBusinessMessage(response.value) },
159
+ exitCode: 1,
160
+ });
161
+ }
162
+ if (!isCoworkSuccess(response.value)) {
163
+ throw new CoworkCliError('api', 'business_error', coworkBusinessMessage(response.value), {
164
+ code: coworkBusinessCode(response.value),
165
+ details: { code: coworkBusinessCode(response.value), message: coworkBusinessMessage(response.value) },
166
+ exitCode: 1,
167
+ });
168
+ }
169
+ return response.value;
170
+ }
171
+ return { request, getSession };
172
+ }
@@ -0,0 +1,166 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { ExitCode, isCliError, toErrorEnvelope } from '../../core/errors.js';
3
+ import { createCoworkContinuationSigner } from './continuation.js';
4
+ import { createCoworkHost } from './host.js';
5
+ import { coworkManifest } from './manifest.js';
6
+ import { executeCoworkOperation } from './operations.js';
7
+ import { coworkValidationError } 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
+ /** Windows PowerShell 的管道与 Set-Content -Encoding utf8 会写入 UTF-8 BOM,JSON.parse 不接受前导 BOM。 */
19
+ function stripBom(value) {
20
+ return value.replace(/^\uFEFF+/, '');
21
+ }
22
+ function parseJsonInput(raw, label) {
23
+ try {
24
+ const parsed = JSON.parse(stripBom(raw));
25
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
26
+ throw new Error('input must be an object');
27
+ }
28
+ return parsed;
29
+ }
30
+ catch {
31
+ throw coworkValidationError('input_invalid', `${label} 不是合法 JSON 对象`);
32
+ }
33
+ }
34
+ export async function inputFrom(options, extra = {}) {
35
+ const opts = asOptions(options);
36
+ let input = {};
37
+ if (opts.input && opts.inputJson) {
38
+ throw coworkValidationError('input_conflict', '不能同时传 --input 和 --input-json');
39
+ }
40
+ if (opts.inputJson) {
41
+ input = parseJsonInput(String(opts.inputJson), '--input-json');
42
+ }
43
+ if (opts.input) {
44
+ let raw;
45
+ try {
46
+ raw = stripBom(opts.input === '-' ? await readStdin() : await readFile(String(opts.input), 'utf8'));
47
+ }
48
+ catch {
49
+ throw coworkValidationError('input_unreadable', `无法读取 --input:${String(opts.input)}`);
50
+ }
51
+ input = parseJsonInput(raw, '--input');
52
+ }
53
+ return {
54
+ ...input,
55
+ ...Object.fromEntries(Object.entries(extra).filter(([, value]) => value !== undefined && value !== '')),
56
+ };
57
+ }
58
+ export function successEnvelope(operation, result) {
59
+ return {
60
+ schemaVersion: 1,
61
+ ok: true,
62
+ operation,
63
+ data: result.data === undefined ? null : result.data,
64
+ ...(result.meta ? { meta: result.meta } : {}),
65
+ warnings: [],
66
+ };
67
+ }
68
+ function failureEnvelope(error) {
69
+ const structured = error;
70
+ return {
71
+ schemaVersion: 1,
72
+ ok: false,
73
+ ...(structured?.partialData === undefined ? {} : { data: structured.partialData }),
74
+ error: toErrorEnvelope(error),
75
+ };
76
+ }
77
+ async function executeAndPrint(ctx, operation, input) {
78
+ try {
79
+ const result = await executeCoworkOperation(operation, input, {
80
+ ctx,
81
+ host: createCoworkHost(ctx),
82
+ continuation: createCoworkContinuationSigner(ctx),
83
+ });
84
+ ctx.output.write(successEnvelope(operation, result), { json: true });
85
+ }
86
+ catch (error) {
87
+ console.error(JSON.stringify(failureEnvelope(error), null, 2));
88
+ process.exitCode = isCliError(error) ? error.exitCode : ExitCode.GeneralError;
89
+ }
90
+ }
91
+ export const coworkShortcut = {
92
+ name: 'cowork',
93
+ description: '泛微E10协作区(协作事项/讨论/审批/共享权限)CLI',
94
+ category: 'shortcut',
95
+ register({ program, action }) {
96
+ const cowork = program.command('cowork').description('泛微E10协作区(协作事项/讨论/审批/共享权限)');
97
+ cowork.command('schema')
98
+ .description('Print cowork operation manifest for agents')
99
+ .action(action((ctx) => {
100
+ ctx.output.write(coworkManifest, { json: true });
101
+ }));
102
+ cowork.command('run')
103
+ .description('Run a cowork operation with JSON input')
104
+ .argument('<operation>', 'operation name, e.g. cowork.list')
105
+ .option('--input <path>', 'JSON input file, or - for stdin')
106
+ .option('--input-json <json>', 'inline JSON input object')
107
+ .action(action(async (ctx, operation, options) => {
108
+ await executeAndPrint(ctx, String(operation), await inputFrom(options));
109
+ }));
110
+ // ---- 高频便捷命令 ----
111
+ cowork.command('list')
112
+ .description('协作列表(默认进行中)')
113
+ .option('--input <path>', 'JSON input file, or - for stdin')
114
+ .option('--scope <scope>', 'main/attention/collect/mineDiscuss/mineItem/related/apply/approve/log/quit/itemApprove/discussApprove')
115
+ .option('--keyword <text>', '协作主题关键字')
116
+ .option('--page <n>', 'page number')
117
+ .option('--size <n>', 'page size')
118
+ .action(action(async (ctx, options) => {
119
+ const opts = asOptions(options);
120
+ await executeAndPrint(ctx, 'cowork.list', await inputFrom(options, {
121
+ scope: opts.scope || 'main',
122
+ itemName: opts.keyword,
123
+ itemNameCondition: opts.keyword ? 'bl' : undefined,
124
+ current: opts.page ? Number(opts.page) : undefined,
125
+ pageSize: opts.size ? Number(opts.size) : undefined,
126
+ }));
127
+ }));
128
+ cowork.command('view')
129
+ .description('协作详情')
130
+ .option('--input <path>', 'JSON input file, or - for stdin')
131
+ .option('--id <id>', 'cowork id')
132
+ .action(action(async (ctx, options) => {
133
+ const opts = asOptions(options);
134
+ await executeAndPrint(ctx, 'cowork.view', await inputFrom(options, { id: opts.id }));
135
+ }));
136
+ cowork.command('discussions')
137
+ .description('协作讨论记录')
138
+ .option('--input <path>', 'JSON input file, or - for stdin')
139
+ .option('--id <id>', 'cowork id')
140
+ .option('--page <n>', 'page number')
141
+ .action(action(async (ctx, options) => {
142
+ const opts = asOptions(options);
143
+ await executeAndPrint(ctx, 'cowork.discuss.list', await inputFrom(options, {
144
+ coworkId: opts.id,
145
+ current: opts.page ? Number(opts.page) : undefined,
146
+ }));
147
+ }));
148
+ cowork.command('sections')
149
+ .description('新建协作可选版块(从新建表单解析)')
150
+ .action(action(async (ctx) => {
151
+ await executeAndPrint(ctx, 'cowork.form', await inputFrom({}));
152
+ }));
153
+ cowork.command('reply')
154
+ .description('发布/回复讨论(prepare,确认后 apply)')
155
+ .option('--input <path>', 'JSON input file, or - for stdin')
156
+ .option('--id <id>', 'cowork id')
157
+ .option('--content <text>', 'discussion content')
158
+ .action(action(async (ctx, options) => {
159
+ const opts = asOptions(options);
160
+ await executeAndPrint(ctx, 'cowork.discuss.publish.prepare', await inputFrom(options, {
161
+ coworkId: opts.id,
162
+ content: opts.content,
163
+ }));
164
+ }));
165
+ },
166
+ };
@@ -0,0 +1,65 @@
1
+ import { coworkOperationDefinitions } from './operations/registry.js';
2
+ /**
3
+ * 浏览选择类(common/browser)32 个接口 + 点赞组件(upvoteComponent)3 个接口:
4
+ * 源资料只给出 `POST /api/cowork/common/browser/<action>/<object>` 的 path 清单,
5
+ * 明确声明「不展开请求/响应结构」。缺少请求体字段表就无法给出逐字段 inputSchema,
6
+ * 按「不补推测能力」原则不实现;需要时先补抓一次页面请求体再落地。
7
+ */
8
+ const BROWSER_WITHHELD = [
9
+ 'cowork.browser.associate',
10
+ 'cowork.browser.complete',
11
+ 'cowork.browser.condition',
12
+ 'cowork.browser.data',
13
+ 'cowork.browser.destData',
14
+ 'cowork.browser.history',
15
+ 'cowork.browser.leftData',
16
+ 'cowork.browser.prop',
17
+ 'cowork.upvote.vote',
18
+ 'cowork.upvote.cancel',
19
+ 'cowork.upvote.voters',
20
+ ];
21
+ /** 权限单元高级配置:`table/info`、`table/update` 是前端表单联动的内部结构(级联规则、多维数组),无稳定契约。 */
22
+ const PERMISSION_TABLE_WITHHELD = [
23
+ 'cowork.permission.table.info',
24
+ 'cowork.permission.table.update',
25
+ ];
26
+ /** 搜索组件的 UI 元数据与行为记录(公共条件/默认快照/历史/个人匹配词/快照名/加历史),无业务语义。 */
27
+ const SEARCH_WITHHELD = [
28
+ 'cowork.search.meta',
29
+ 'cowork.search.history',
30
+ ];
31
+ function buildOperations() {
32
+ return coworkOperationDefinitions().map((definition) => ({
33
+ name: definition.name,
34
+ resource: definition.resource,
35
+ summary: definition.summary,
36
+ risk: definition.risk,
37
+ ...(definition.requiresConfirmation ? { requiresConfirmation: true } : {}),
38
+ inputSchema: definition.inputSchema,
39
+ }));
40
+ }
41
+ export const coworkManifest = {
42
+ schemaVersion: 1,
43
+ name: 'cowork',
44
+ title: '泛微E10协作区(协作事项/讨论/审批/共享权限)',
45
+ version: '0.1.0',
46
+ host: 'e10-cowork',
47
+ status: 'builtin',
48
+ sourceSkill: 'weaver-e10-cowork',
49
+ capabilities: ['cowork'],
50
+ operations: buildOperations(),
51
+ withheldOperations: [
52
+ ...BROWSER_WITHHELD.map((name) => ({
53
+ name,
54
+ reason: '浏览选择/点赞组件接口:源资料只提供 path 清单,未给出请求体字段表,无法逐字段建模。选人/选部门请改用 ehr 模块的人员与组织查询能力取 id;补齐方式:抓一次页面请求体后再实现。不得凭猜测构造请求体。',
55
+ })),
56
+ ...PERMISSION_TABLE_WITHHELD.map((name) => ({
57
+ name,
58
+ reason: '共享权限单元的高级配置(对象类型/安全级别/级联规则)是前端表单内部结构,无稳定入参契约;常规授权/取消授权请用 cowork.permission.add / cowork.permission.remove。',
59
+ })),
60
+ ...SEARCH_WITHHELD.map((name) => ({
61
+ name,
62
+ reason: '搜索组件的 UI 元数据与搜索历史记录,属前端交互行为,对 Agent 无业务语义;列表筛选请直接用 cowork.list 的条件字段(字段集合以 cowork.conditions 返回为准)。',
63
+ })),
64
+ ],
65
+ };