weaver-work-cli 0.1.32 → 0.1.36

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 (211) hide show
  1. package/README.md +2 -2
  2. package/dist/chunks/{archive-UMGX72K6.js → archive-XBVH7JU7.js} +2 -2
  3. package/dist/chunks/{archive-oa-N2IYBLF3.js → archive-oa-MZM3EKFQ.js} +2 -2
  4. package/dist/chunks/{asset-GLEGKFG5.js → asset-4XO7UOUW.js} +2 -2
  5. package/dist/chunks/{attachment-content-AQNX5N3S.js → attachment-content-VXSWANAC.js} +3 -2
  6. package/dist/chunks/{blog-E44OTVDA.js → blog-PGZKOPSC.js} +2 -2
  7. package/dist/chunks/{caizhilian-DQUFZXZL.js → caizhilian-BH4ZVGUN.js} +2 -2
  8. package/dist/chunks/{calendar-JKPIRKFD.js → calendar-MXEMTIO4.js} +2 -2
  9. package/dist/chunks/{chunk-QWY6PGL6.js → chunk-2LV74IWP.js} +361 -56
  10. package/dist/chunks/chunk-3SO6QL6U.js +73 -0
  11. package/dist/chunks/chunk-5DQEEGCC.js +229 -0
  12. package/dist/chunks/{chunk-G3QJULO2.js → chunk-6LLJFKJE.js} +1 -1
  13. package/dist/chunks/{chunk-C6R3B2ML.js → chunk-BPE37FPB.js} +35 -7
  14. package/dist/chunks/chunk-BYATLLEF.js +68 -0
  15. package/dist/chunks/chunk-BYBSCN4X.js +932 -0
  16. package/dist/chunks/{chunk-CVZ2JOSW.js → chunk-F746NKNF.js} +1 -1
  17. package/dist/chunks/{chunk-GCG2NMWR.js → chunk-HXJQI5NM.js} +4 -2
  18. package/dist/chunks/{chunk-YRVDW4WN.js → chunk-I6QGIBDM.js} +2 -2
  19. package/dist/chunks/{chunk-H7J4DC5R.js → chunk-JCSN3JGM.js} +2 -2
  20. package/dist/chunks/{chunk-2GA5ZIQL.js → chunk-JNG42JKG.js} +30 -1
  21. package/dist/chunks/{chunk-DW6AUUKS.js → chunk-JUXVYKII.js} +9 -4
  22. package/dist/chunks/{chunk-6RKD4DRZ.js → chunk-JYKABYCV.js} +2 -2
  23. package/dist/chunks/{chunk-6EFWDL7Y.js → chunk-NCOVUAZK.js} +2 -2
  24. package/dist/chunks/{chunk-E4Z23GHM.js → chunk-QHFANTX7.js} +1114 -904
  25. package/dist/chunks/{ebuilder-form-V5FG2EHC.js → chunk-QYGO5EE2.js} +22 -1148
  26. package/dist/chunks/{chunk-IURUFGZK.js → chunk-T72N74ZT.js} +50 -33
  27. package/dist/chunks/{chunk-H6XSTSLM.js → chunk-TC6MZAO3.js} +137 -204
  28. package/dist/chunks/{chunk-WKI2FBIQ.js → chunk-VPUTVEMC.js} +737 -341
  29. package/dist/chunks/{chunk-WSKBSQ2U.js → chunk-VPXOPQJI.js} +2 -2
  30. package/dist/chunks/chunk-WXFPWCXG.js +774 -0
  31. package/dist/chunks/{chunk-4YC43QQ4.js → chunk-XMGSYD6S.js} +4 -4
  32. package/dist/chunks/conflict-JAB2LJEZ.js +21 -0
  33. package/dist/chunks/continuation-RN6PZN2M.js +11 -0
  34. package/dist/chunks/contract-XI2EEIZU.js +9110 -0
  35. package/dist/chunks/cowork-SCPGLBA4.js +2527 -0
  36. package/dist/chunks/ebuilder-form-EYLHNOTA.js +121 -0
  37. package/dist/chunks/{ehr-HMFY6VIL.js → ehr-EAP77IMT.js} +1344 -27
  38. package/dist/chunks/{esb-ZYSVB7SG.js → esb-2TGGXEE7.js} +4 -4
  39. package/dist/chunks/{fna-B7RKPAZD.js → fna-2X7ZE7BU.js} +13 -8
  40. package/dist/chunks/{host-OCH2BCCV.js → host-C6EL2RKL.js} +3 -3
  41. package/dist/chunks/{host-45WED2KK.js → host-I4NRK4MX.js} +3 -3
  42. package/dist/chunks/{host-I4Z6BFYX.js → host-Q4LZGCRU.js} +3 -3
  43. package/dist/chunks/host-UEI5FGDM.js +23 -0
  44. package/dist/chunks/{host-KNZ52LJZ.js → host-XCLDDXKQ.js} +3 -3
  45. package/dist/chunks/{hrm-2KAZGUHI.js → hrm-YXERJM76.js} +3 -3
  46. package/dist/chunks/{im-ACJJWH4U.js → im-A4VZN2TQ.js} +88 -12
  47. package/dist/chunks/{invoice-ZK3WCX2U.js → invoice-2Z6YPMIS.js} +3 -3
  48. package/dist/chunks/{jiuchuanhui-5PQD3IL2.js → jiuchuanhui-AR5GMKZB.js} +2 -2
  49. package/dist/chunks/{lazy-dispatch-JQXBW3GM.js → lazy-dispatch-QXW7P4X3.js} +4 -4
  50. package/dist/chunks/{mail-S2HDDXO2.js → mail-7GZ6CPBJ.js} +45 -24
  51. package/dist/chunks/{meeting-QVN3I37L.js → meeting-3NMGA3MB.js} +278 -43
  52. package/dist/chunks/{okr-QNG4VC2Q.js → okr-BZ6XUOAG.js} +2 -2
  53. package/dist/chunks/operations-5QL3AECO.js +11 -0
  54. package/dist/chunks/{plan-A25EMW6U.js → plan-DR5CMUYP.js} +2 -2
  55. package/dist/chunks/{project-G6XV66DZ.js → project-6J63MK33.js} +2 -2
  56. package/dist/chunks/{registry-DC6KR3NH.js → registry-KDD7DHNK.js} +4 -4
  57. package/dist/chunks/{registry-2VLUAESA.js → registry-OZSMDVPP.js} +2 -2
  58. package/dist/chunks/{registry-7C5UMIPL.js → registry-TKX2E7C7.js} +2 -2
  59. package/dist/chunks/{registry-TI3CIUXF.js → registry-VRTNC6UR.js} +8 -6
  60. package/dist/chunks/{room-recommend-WRTHO6Y2.js → room-recommend-XCWRMB5P.js} +4 -3
  61. package/dist/chunks/{schedule-KFIITGSK.js → schedule-IVBICP32.js} +4 -3
  62. package/dist/chunks/{workflow-DJ7SYWAF.js → workflow-D74NFK3C.js} +179 -6
  63. package/dist/index.js +35 -25
  64. package/dist/internal/e10/auth-recovery.js +14 -4
  65. package/dist/internal/e10/fetch-timing.js +31 -0
  66. package/dist/internal/e10/request-runtime.js +5 -0
  67. package/dist/shortcuts/contract/host.js +34 -59
  68. package/dist/shortcuts/cowork/continuation.js +70 -0
  69. package/dist/shortcuts/cowork/errors.js +59 -0
  70. package/dist/shortcuts/cowork/host.js +180 -0
  71. package/dist/shortcuts/cowork/index.js +166 -0
  72. package/dist/shortcuts/cowork/manifest.js +65 -0
  73. package/dist/shortcuts/cowork/operations/discuss-write.js +277 -0
  74. package/dist/shortcuts/cowork/operations/item-write.js +380 -0
  75. package/dist/shortcuts/cowork/operations/member-write.js +283 -0
  76. package/dist/shortcuts/cowork/operations/permission-write.js +286 -0
  77. package/dist/shortcuts/cowork/operations/read.js +423 -0
  78. package/dist/shortcuts/cowork/operations/registry.js +39 -0
  79. package/dist/shortcuts/cowork/operations/review-write.js +157 -0
  80. package/dist/shortcuts/cowork/operations/shared.js +215 -0
  81. package/dist/shortcuts/cowork/operations/types.js +39 -0
  82. package/dist/shortcuts/cowork/operations.js +19 -0
  83. package/dist/shortcuts/ehr/host.js +4 -1
  84. package/dist/shortcuts/ehr/operations/recruit-candidate-import.js +757 -0
  85. package/dist/shortcuts/ehr/operations/recruit-position.js +367 -0
  86. package/dist/shortcuts/ehr/operations/recruit-stats.js +133 -0
  87. package/dist/shortcuts/ehr/operations/recruit-write.js +43 -16
  88. package/dist/shortcuts/ehr/operations/recruit.js +182 -10
  89. package/dist/shortcuts/ehr/operations/registry.js +6 -0
  90. package/dist/shortcuts/fna/operations/expense-chart.js +19 -7
  91. package/dist/shortcuts/im/diagnostics.js +97 -0
  92. package/dist/shortcuts/im/host.js +58 -31
  93. package/dist/shortcuts/im/index.js +7 -2
  94. package/dist/shortcuts/im/operations/at-mention.js +127 -0
  95. package/dist/shortcuts/im/operations/file-user.js +10 -2
  96. package/dist/shortcuts/im/operations/group-read.js +26 -5
  97. package/dist/shortcuts/im/operations/group-write.js +35 -28
  98. package/dist/shortcuts/im/operations/msg-sync.js +7 -2
  99. package/dist/shortcuts/im/operations/msg-write.js +76 -10
  100. package/dist/shortcuts/im/operations/quote-mention.js +119 -0
  101. package/dist/shortcuts/im/operations/session.js +1 -1
  102. package/dist/shortcuts/im/operations/shared.js +10 -0
  103. package/dist/shortcuts/im/operations/types.js +13 -0
  104. package/dist/shortcuts/index.js +10 -0
  105. package/dist/shortcuts/mail/host.js +12 -1
  106. package/dist/shortcuts/mail/operations/types.js +17 -2
  107. package/dist/shortcuts/meeting/host.js +27 -34
  108. package/dist/shortcuts/meeting/index.js +79 -1
  109. package/dist/shortcuts/meeting/manifest.js +10 -0
  110. package/dist/shortcuts/meeting/operations/create.js +4 -1
  111. package/dist/shortcuts/meeting/operations/eb/catalog.js +10 -0
  112. package/dist/shortcuts/meeting/operations/eb/conflict.js +84 -8
  113. package/dist/shortcuts/meeting/operations/eb/create-flow.js +1195 -140
  114. package/dist/shortcuts/meeting/operations/eb/factory.js +170 -8
  115. package/dist/shortcuts/meeting/operations/eb/index.js +16 -3
  116. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +50 -5
  117. package/dist/shortcuts/meeting/operations/eb-fallback.js +163 -0
  118. package/dist/shortcuts/meeting/operations/env.js +99 -46
  119. package/dist/shortcuts/meeting/operations/form-fields.js +110 -0
  120. package/dist/shortcuts/meeting/operations/invitation.js +79 -20
  121. package/dist/shortcuts/meeting/operations/registry.js +2 -0
  122. package/dist/shortcuts/meeting/operations/standard-guard.js +71 -0
  123. package/dist/shortcuts/meeting/operations.js +16 -0
  124. package/dist/shortcuts/workflow/endpoints.js +8 -3
  125. package/dist/shortcuts/workflow/index.js +110 -1
  126. package/dist/shortcuts/workflow/operations/form.js +204 -36
  127. package/dist/shortcuts/workflow/operations/read.js +104 -23
  128. package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupRules.js +448 -0
  129. package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupStore.js +106 -0
  130. package/dist/shortcuts/workflow/operations/todoSmartConvert/businessRules.js +47 -0
  131. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +30 -23
  132. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +1 -0
  133. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +1 -0
  134. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.groupSummary.js +2 -1
  135. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +2 -4
  136. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +138 -181
  137. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.summary.js +12 -7
  138. package/dist/shortcuts/workflow/operations.js +23 -1
  139. package/docs/e10-auth.md +1 -1
  140. package/docs/ehr.md +1 -1
  141. package/docs/fna.md +2 -1
  142. package/docs/im.md +8 -1
  143. package/docs/todo-smart-convert/README.md +1 -1
  144. package/docs/todo-smart-convert/data-contract.md +2 -2
  145. package/docs/todo-smart-convert/subgroup-rules.md +6 -0
  146. package/package.json +1 -1
  147. package/skill-template/business-info.json +18 -0
  148. package/skill-template/domains/cowork.md +14 -0
  149. package/skill-template/domains/yimiaoban.md +3 -3
  150. package/skill-template/skill-template.md +1 -1
  151. package/skills/weaver-e10-blog/SKILL.md +5 -5
  152. package/skills/weaver-e10-caizhilian/SKILL.md +5 -5
  153. package/skills/weaver-e10-calendar/SKILL.md +5 -5
  154. package/skills/weaver-e10-cowork/SKILL.md +101 -0
  155. package/skills/weaver-e10-cowork/references/cowork-read.md +90 -0
  156. package/skills/weaver-e10-cowork/references/cowork-write.md +131 -0
  157. package/skills/weaver-e10-cowork/references/safety-boundaries.md +45 -0
  158. package/skills/weaver-e10-esb/SKILL.md +5 -5
  159. package/skills/weaver-e10-hrm/SKILL.md +5 -5
  160. package/skills/weaver-e10-jinchengda/SKILL.md +2 -2
  161. package/skills/weaver-e10-jiuchuanhui/SKILL.md +5 -5
  162. package/skills/weaver-e10-jucailin/SKILL.md +38 -14
  163. package/skills/weaver-e10-jucailin/references/recruit-create.md +104 -0
  164. package/skills/weaver-e10-jucailin/references/recruit-read.md +25 -0
  165. package/skills/weaver-e10-jucailin/references/recruit-write.md +13 -0
  166. package/skills/weaver-e10-jucailin/references/salary.md +15 -11
  167. package/skills/weaver-e10-mail/SKILL.md +17 -14
  168. package/skills/weaver-e10-meeting/SKILL.md +442 -46
  169. package/skills/weaver-e10-meeting/references/meeting-eb.md +135 -3
  170. package/skills/weaver-e10-meeting/references/meeting-invitation.md +28 -2
  171. package/skills/weaver-e10-meeting/references/meeting-queries.md +9 -6
  172. package/skills/weaver-e10-meeting/references/meeting-verification.md +8 -6
  173. package/skills/weaver-e10-meeting.zip +0 -0
  174. package/skills/weaver-e10-okr/SKILL.md +5 -5
  175. package/skills/weaver-e10-okr/references/source-manifest.json +3 -3
  176. package/skills/weaver-e10-plan/SKILL.md +5 -5
  177. package/skills/weaver-e10-qiyecheng/SKILL.md +5 -2
  178. package/skills/weaver-e10-qiyecheng/references/catalog.md +2 -2
  179. package/skills/weaver-e10-qiyecheng/references/expense-chart.md +15 -1
  180. package/skills/weaver-e10-qiyecheng/references/source-manifest.json +22 -21
  181. package/skills/weaver-e10-shared/SKILL.md +12 -12
  182. package/skills/weaver-e10-shared/references/e10-auth-and-session.md +4 -4
  183. package/skills/weaver-e10-wenshuding/SKILL.md +5 -5
  184. package/skills/weaver-e10-workflow/SKILL.md +29 -5
  185. package/skills/weaver-e10-workflow/aigroup/default.json +88 -0
  186. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +66 -14
  187. package/skills/weaver-e10-workflow/references/workflow-agent-entry.md +1 -1
  188. package/skills/weaver-e10-workflow/references/workflow-memory.md +1 -1
  189. package/skills/weaver-e10-workflow/references/workflow-query.md +12 -10
  190. package/skills/weaver-e10-workflow/references/workflow-view.md +2 -2
  191. package/skills/weaver-e10-workflow/tools/todo-serve.cjs +239 -0
  192. package/skills/weaver-e10-workflow/{scripts → tools}/todo-summary.cjs +218 -28
  193. package/skills/weaver-e10-yepiaotong/SKILL.md +10 -8
  194. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +7 -7
  195. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +10 -10
  196. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +40 -37
  197. package/skills/weaver-e10-yepiaotong/references/reim-expense-subject-rules.md +4 -4
  198. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +27 -38
  199. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +4 -4
  200. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +37 -29
  201. package/skills/weaver-e10-yimiaoban/SKILL.md +156 -33
  202. package/skills/weaver-e10-yimiaoban/references/ding-write.md +1 -1
  203. package/skills/weaver-e10-yimiaoban/references/error-codes.md +5 -1
  204. package/skills/weaver-e10-yimiaoban/references/group-read.md +5 -1
  205. package/skills/weaver-e10-yimiaoban/references/group-write.md +6 -4
  206. package/skills/weaver-e10-yimiaoban/references/msg-read.md +1 -0
  207. package/skills/weaver-e10-yimiaoban/references/msg-write.md +34 -2
  208. package/skills/weaver-e10-yimiaoban/references/safety-boundaries.md +5 -2
  209. package/skills/weaver-e10-yimiaoban/references/source-manifest.json +79 -58
  210. package/skills/weaver-e10-yimiaoban/references/user-remind.md +2 -2
  211. package/skills/weaver-e10-ziguanjia/SKILL.md +5 -5
@@ -0,0 +1,2527 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ E10ApiError,
5
+ createE10RequestRuntime,
6
+ requireE10Session
7
+ } from "./chunk-JUXVYKII.js";
8
+ import {
9
+ E10_SESSION_EXPIRED_MESSAGE,
10
+ getActiveProfile
11
+ } from "./chunk-JNG42JKG.js";
12
+ import {
13
+ CliError,
14
+ isCliError,
15
+ toErrorEnvelope
16
+ } from "./chunk-LUSPKZKY.js";
17
+ import "./chunk-BUSC6UAE.js";
18
+
19
+ // src/shortcuts/cowork/index.ts
20
+ import { readFile as readFile2 } from "node:fs/promises";
21
+
22
+ // src/shortcuts/cowork/continuation.ts
23
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
24
+ import { existsSync } from "node:fs";
25
+ import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
26
+ import { homedir } from "node:os";
27
+ import { resolve } from "node:path";
28
+
29
+ // src/shortcuts/cowork/errors.ts
30
+ var CoworkCliError = class extends CliError {
31
+ type;
32
+ subtype;
33
+ code;
34
+ retryable;
35
+ stage;
36
+ details;
37
+ partialData;
38
+ constructor(type, subtype, message, options = {}) {
39
+ super(message, options.exitCode ?? 5 /* InternalError */);
40
+ this.name = "CoworkCliError";
41
+ this.type = type;
42
+ this.subtype = subtype;
43
+ this.code = options.code;
44
+ this.retryable = options.retryable ?? false;
45
+ this.stage = options.stage;
46
+ this.details = options.details;
47
+ this.partialData = options.partialData;
48
+ }
49
+ };
50
+ function coworkValidationError(subtype, message, details) {
51
+ return new CoworkCliError("validation", subtype, message, {
52
+ details,
53
+ exitCode: 2 /* UsageError */
54
+ });
55
+ }
56
+ function coworkAuthError(subtype, message, details) {
57
+ return new CoworkCliError("authentication", subtype, message, {
58
+ details,
59
+ exitCode: 3 /* AuthError */
60
+ });
61
+ }
62
+ function coworkNetworkError(subtype, message, options = {}) {
63
+ return new CoworkCliError("network", subtype, message, {
64
+ ...options,
65
+ retryable: options.retryable ?? true,
66
+ exitCode: 4 /* NetworkError */
67
+ });
68
+ }
69
+ function coworkConfirmationError(action, details) {
70
+ return new CoworkCliError("confirmation", "required", "\u8BE5\u64CD\u4F5C\u9700\u8981\u660E\u786E\u786E\u8BA4", {
71
+ details: { action, ...details },
72
+ exitCode: 10 /* ConfirmationRequired */
73
+ });
74
+ }
75
+ function coworkPartialError(message, partialData, details) {
76
+ return new CoworkCliError("partial", "write_uncertain", message, {
77
+ details,
78
+ partialData,
79
+ exitCode: 11 /* Partial */
80
+ });
81
+ }
82
+ function coworkNotFoundError(subtype, message, details) {
83
+ return new CoworkCliError("not_found", subtype, message, {
84
+ details,
85
+ exitCode: 2 /* UsageError */
86
+ });
87
+ }
88
+
89
+ // src/shortcuts/cowork/continuation.ts
90
+ function stateRoot(ctx) {
91
+ const configured = ctx?.config?.path();
92
+ if (configured) return resolve(configured, "..");
93
+ return process.env.WEAVER_WORK_CLI_HOME || process.env.WORK_CLI_HOME || resolve(homedir(), ".weaver-work-cli");
94
+ }
95
+ async function loadKey(ctx) {
96
+ const keysDir = resolve(stateRoot(ctx), "keys");
97
+ const filename = resolve(keysDir, "cowork-continuation.key");
98
+ await mkdir(keysDir, { recursive: true, mode: 448 });
99
+ if (existsSync(filename)) return readFile(filename);
100
+ const key = randomBytes(32);
101
+ try {
102
+ await writeFile(filename, key, { flag: "wx", mode: 384 });
103
+ if (process.platform !== "win32") await chmod(filename, 384).catch(() => void 0);
104
+ return key;
105
+ } catch {
106
+ return readFile(filename);
107
+ }
108
+ }
109
+ function encode(value) {
110
+ return Buffer.from(JSON.stringify(value)).toString("base64url");
111
+ }
112
+ function signature(payload, key) {
113
+ return createHmac("sha256", key).update(payload).digest("base64url");
114
+ }
115
+ function createCoworkContinuationSigner(ctx) {
116
+ return {
117
+ async issue(payload, ttlMs = 10 * 6e4) {
118
+ const issuedAt = Date.now();
119
+ const body = encode({ ...payload, issuedAt, expiresAt: issuedAt + ttlMs });
120
+ const sig = signature(body, await loadKey(ctx));
121
+ return `${body}.${sig}`;
122
+ },
123
+ async verify(token, expectedOperation) {
124
+ if (typeof token !== "string" || !token.includes(".")) {
125
+ throw coworkValidationError("continuation_invalid", "continuation \u65E0\u6548");
126
+ }
127
+ const [body, provided] = token.split(".");
128
+ const expected = signature(body, await loadKey(ctx));
129
+ const valid = provided.length === expected.length && timingSafeEqual(Buffer.from(provided), Buffer.from(expected));
130
+ if (!valid) throw coworkValidationError("continuation_invalid", "continuation \u7B7E\u540D\u6821\u9A8C\u5931\u8D25");
131
+ let value;
132
+ try {
133
+ value = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
134
+ } catch {
135
+ throw coworkValidationError("continuation_invalid", "continuation \u5185\u5BB9\u65E0\u6CD5\u89E3\u6790");
136
+ }
137
+ if (value.operation !== expectedOperation) {
138
+ throw coworkValidationError("continuation_mismatch", "continuation \u4E0D\u5C5E\u4E8E\u5F53\u524D\u64CD\u4F5C");
139
+ }
140
+ if (!Number.isSafeInteger(value.expiresAt) || value.expiresAt < Date.now()) {
141
+ throw coworkValidationError("continuation_expired", "continuation \u5DF2\u8FC7\u671F");
142
+ }
143
+ return value;
144
+ }
145
+ };
146
+ }
147
+
148
+ // src/shortcuts/cowork/operations/types.ts
149
+ var READ = "read";
150
+ var READ_BEFORE_WRITE = "read-before-write";
151
+ var WRITE = "write";
152
+ var coworkPerf = {
153
+ t0: Date.now(),
154
+ sessionMs: 0,
155
+ requestCount: 0,
156
+ requestMs: 0
157
+ };
158
+ function coworkSuccess(action, data, meta) {
159
+ const payload = { ok: true, action, data };
160
+ const perf = {
161
+ elapsed_ms: Date.now() - coworkPerf.t0,
162
+ session_ms: coworkPerf.sessionMs || void 0,
163
+ requests: coworkPerf.requestCount || void 0,
164
+ network_ms: coworkPerf.requestMs || void 0
165
+ };
166
+ for (const k of Object.keys(perf)) if (perf[k] === void 0) delete perf[k];
167
+ payload.meta = { ...meta || {}, ...perf };
168
+ return payload;
169
+ }
170
+ function schemaOf(properties, options = {}) {
171
+ return {
172
+ type: "object",
173
+ additionalProperties: false,
174
+ properties,
175
+ ...options.required?.length ? { required: options.required } : {},
176
+ ...options.description ? { description: options.description } : {}
177
+ };
178
+ }
179
+ var SCHEMA_ID = { oneOf: [{ type: "integer" }, { type: "string", pattern: "^\\d+$" }] };
180
+ var SCHEMA_PAGE_CURRENT = { type: "integer", minimum: 1 };
181
+ var SCHEMA_PAGE_SIZE = { type: "integer", minimum: 1, maximum: 200 };
182
+ var SCHEMA_DATETIME = { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$" };
183
+
184
+ // src/shortcuts/cowork/host.ts
185
+ function inferProfile(ctx) {
186
+ const options = ctx.getGlobalOptions();
187
+ return options.profile || getActiveProfile();
188
+ }
189
+ function isCoworkSuccess(value) {
190
+ if (value === "SUCCESS" || value === 1 || value === true) return true;
191
+ if (!value || typeof value !== "object") return false;
192
+ if (value.fail === true) return false;
193
+ if (value.status === true) return true;
194
+ if (value.code !== void 0 && value.code !== null && Number(value.code) === 200) return true;
195
+ const data = value.data;
196
+ if (data === "SUCCESS" || data === 1 || data === true) return true;
197
+ if (data && typeof data === "object" && data.status === true) return true;
198
+ return false;
199
+ }
200
+ function coworkBusinessMessage(value) {
201
+ if (!value || typeof value !== "object") return "\u534F\u4F5C\u63A5\u53E3\u8FD4\u56DE\u4E1A\u52A1\u5931\u8D25";
202
+ const candidates = [value.msg, value.message, value.data?.msg, value.data?.message, value.error];
203
+ for (const item of candidates) {
204
+ if (typeof item === "string" && item.trim()) return item;
205
+ }
206
+ return "\u534F\u4F5C\u63A5\u53E3\u8FD4\u56DE\u4E1A\u52A1\u5931\u8D25";
207
+ }
208
+ function coworkBusinessCode(value) {
209
+ if (!value || typeof value !== "object") return void 0;
210
+ const code = value.code ?? value.status;
211
+ if (typeof code === "string" || typeof code === "number") return code;
212
+ return void 0;
213
+ }
214
+ function assertPath(requestPath) {
215
+ if (typeof requestPath !== "string" || !requestPath.startsWith("/") || requestPath.startsWith("//")) {
216
+ throw coworkValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u5FC5\u987B\u662F\u76F8\u5BF9\u7EDD\u5BF9\u8DEF\u5F84");
217
+ }
218
+ if (/^https?:/i.test(requestPath) || /[\r\n]/.test(requestPath) || requestPath.includes("/../")) {
219
+ throw coworkValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u4E0D\u5141\u8BB8\u8DE8\u57DF\u6216\u8DEF\u5F84\u9003\u9038");
220
+ }
221
+ if (!requestPath.startsWith("/api/cowork/")) {
222
+ throw coworkValidationError("path_not_allowed", "\u534F\u4F5C\u6A21\u5757\u53EA\u80FD\u8C03\u7528 /api/cowork/ \u8DEF\u5F84");
223
+ }
224
+ }
225
+ function formBody(form) {
226
+ if (!form) return void 0;
227
+ const params = new URLSearchParams();
228
+ for (const [key, value] of Object.entries(form)) {
229
+ if (value === void 0 || value === null) continue;
230
+ params.set(key, typeof value === "string" ? value : String(value));
231
+ }
232
+ return params;
233
+ }
234
+ function omitEmptyQueryValues(query) {
235
+ if (!query) return void 0;
236
+ return Object.fromEntries(Object.entries(query).filter(([, value]) => value !== ""));
237
+ }
238
+ function mapRuntimeNetworkError(error) {
239
+ if (error instanceof E10ApiError && error.type === "network") {
240
+ throw coworkNetworkError(error.subtype, error.message, {
241
+ retryable: error.retryable,
242
+ details: error.details
243
+ });
244
+ }
245
+ throw error;
246
+ }
247
+ function createCoworkHost(ctx, dependencies = {}) {
248
+ let e10Session = null;
249
+ let sessionContext = null;
250
+ const requireSession = dependencies.requireSession || ((innerCtx) => requireE10Session(innerCtx, { skipProfileEnrichment: true }));
251
+ async function ensureSession() {
252
+ if (!e10Session) {
253
+ const sessionStart = Date.now();
254
+ e10Session = await requireSession(ctx);
255
+ coworkPerf.sessionMs = Date.now() - sessionStart;
256
+ sessionContext = {
257
+ baseUrl: e10Session.getBaseUrl(),
258
+ profile: inferProfile(ctx),
259
+ userId: e10Session.userId,
260
+ tenantKey: e10Session.tenantKey,
261
+ eteamsId: e10Session.eteamsId
262
+ };
263
+ }
264
+ return e10Session;
265
+ }
266
+ async function getSession() {
267
+ await ensureSession();
268
+ return sessionContext;
269
+ }
270
+ async function runtime() {
271
+ return createE10RequestRuntime(ctx, await ensureSession(), {
272
+ interceptors: dependencies.interceptors,
273
+ fetch: dependencies.fetch
274
+ });
275
+ }
276
+ async function request(request2) {
277
+ const {
278
+ method,
279
+ path,
280
+ query,
281
+ body,
282
+ form,
283
+ operation,
284
+ headers: extraHeaders = {},
285
+ timeoutMs = 3e4
286
+ } = request2;
287
+ assertPath(path);
288
+ const resolvedMethod = method || (body === void 0 && form === void 0 ? "GET" : "POST");
289
+ let response;
290
+ const reqStart = Date.now();
291
+ try {
292
+ response = await (await runtime()).requestJson({
293
+ module: "cowork",
294
+ operation,
295
+ method: resolvedMethod,
296
+ path,
297
+ query: omitEmptyQueryValues(query),
298
+ body: form === void 0 ? body : void 0,
299
+ form: form === void 0 ? void 0 : formBody(form),
300
+ headers: { "X-Requested-With": "XMLHttpRequest", ...extraHeaders },
301
+ timeoutMs
302
+ });
303
+ } catch (error) {
304
+ mapRuntimeNetworkError(error);
305
+ } finally {
306
+ coworkPerf.requestCount += 1;
307
+ coworkPerf.requestMs += Date.now() - reqStart;
308
+ }
309
+ if (response.status === 401 || response.status === 302) {
310
+ throw coworkAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
311
+ }
312
+ if (response.parseError) {
313
+ if (response.status < 200 || response.status >= 300) {
314
+ throw new CoworkCliError("api", "http_error", `\u534F\u4F5C\u63A5\u53E3 HTTP ${response.status}`, {
315
+ code: response.status,
316
+ details: { status: response.status },
317
+ exitCode: 1
318
+ });
319
+ }
320
+ throw coworkNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
321
+ }
322
+ if (response.status < 200 || response.status >= 300) {
323
+ throw new CoworkCliError("api", "http_error", `\u534F\u4F5C\u63A5\u53E3 HTTP ${response.status}`, {
324
+ code: response.status,
325
+ details: { status: response.status, message: coworkBusinessMessage(response.value) },
326
+ exitCode: 1
327
+ });
328
+ }
329
+ if (!isCoworkSuccess(response.value)) {
330
+ throw new CoworkCliError("api", "business_error", coworkBusinessMessage(response.value), {
331
+ code: coworkBusinessCode(response.value),
332
+ details: { code: coworkBusinessCode(response.value), message: coworkBusinessMessage(response.value) },
333
+ exitCode: 1
334
+ });
335
+ }
336
+ return response.value;
337
+ }
338
+ return { request, getSession };
339
+ }
340
+
341
+ // src/shortcuts/cowork/operations/shared.ts
342
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
343
+ function asObject(value) {
344
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
345
+ throw coworkValidationError("input_not_object", "\u8F93\u5165\u5FC5\u987B\u662F JSON \u5BF9\u8C61");
346
+ }
347
+ return value;
348
+ }
349
+ function assertNoForbiddenKeys(input) {
350
+ for (const key of Object.keys(input)) {
351
+ if (FORBIDDEN_KEYS.has(key)) {
352
+ throw coworkValidationError("forbidden_key", `\u8F93\u5165\u5305\u542B\u975E\u6CD5\u5B57\u6BB5\uFF1A${key}`);
353
+ }
354
+ }
355
+ }
356
+ function toId(value, field) {
357
+ if (value === void 0 || value === null || value === "") return void 0;
358
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
359
+ throw coworkValidationError("id_precision", `${field} \u8D85\u51FA\u5B89\u5168\u6574\u6570\u8303\u56F4\uFF0C\u8BF7\u4EE5\u5B57\u7B26\u4E32\u4F20\u5165`);
360
+ }
361
+ const text = String(value).trim();
362
+ if (!/^\d+$/.test(text)) {
363
+ throw coworkValidationError("id_invalid", `${field} \u5FC5\u987B\u662F\u6570\u5B57 ID\uFF1A${text}`);
364
+ }
365
+ return text;
366
+ }
367
+ function toIdList(value, field) {
368
+ if (value === void 0 || value === null) return void 0;
369
+ if (!Array.isArray(value)) throw coworkValidationError("id_list_invalid", `${field} \u5FC5\u987B\u662F ID \u6570\u7EC4`);
370
+ return value.map((item, index) => {
371
+ const id = toId(item, `${field}[${index}]`);
372
+ if (!id) throw coworkValidationError("id_list_invalid", `${field}[${index}] \u4E0D\u80FD\u4E3A\u7A7A`);
373
+ return id;
374
+ });
375
+ }
376
+ function toPositiveInt(value, field) {
377
+ if (value === void 0 || value === null || value === "") return void 0;
378
+ const numeric = Number(value);
379
+ if (!Number.isFinite(numeric)) {
380
+ throw coworkValidationError("number_invalid", `${field} \u5FC5\u987B\u662F\u6570\u5B57`);
381
+ }
382
+ const truncated = Math.trunc(numeric);
383
+ if (truncated !== numeric || truncated <= 0) {
384
+ throw coworkValidationError("number_invalid", `${field} \u5FC5\u987B\u662F\u6B63\u6574\u6570`);
385
+ }
386
+ return truncated;
387
+ }
388
+ function compact(body) {
389
+ for (const key of Object.keys(body)) {
390
+ if (body[key] === void 0) delete body[key];
391
+ }
392
+ return body;
393
+ }
394
+ function assertEnum(value, allowed, field) {
395
+ const text = typeof value === "string" ? value : String(value);
396
+ if (!allowed.includes(text)) {
397
+ throw coworkValidationError("enum_invalid", `${field} \u53D6\u503C\u5FC5\u987B\u662F ${allowed.join(" / ")} \u4E4B\u4E00`);
398
+ }
399
+ return text;
400
+ }
401
+ function assertString(value, field, maxLength = 500) {
402
+ if (typeof value !== "string" || !value.trim()) {
403
+ throw coworkValidationError("string_invalid", `${field} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32`);
404
+ }
405
+ const text = value.trim();
406
+ if (text.length > maxLength) {
407
+ throw coworkValidationError("string_too_long", `${field} \u8D85\u8FC7 ${maxLength} \u5B57\u7B26\u4E0A\u9650`);
408
+ }
409
+ return text;
410
+ }
411
+ function unwrapData(response) {
412
+ if (!response || typeof response !== "object") return response;
413
+ return response.data;
414
+ }
415
+ function normalizePaged(response) {
416
+ const data = unwrapData(response);
417
+ const page = {};
418
+ const candidates = [data, response];
419
+ for (const source of candidates) {
420
+ if (!source || typeof source !== "object") continue;
421
+ for (const key of ["current", "pageSize", "total", "pageUid", "tableType"]) {
422
+ if (source[key] !== void 0 && page[key] === void 0) page[key] = source[key];
423
+ }
424
+ }
425
+ return { data, page };
426
+ }
427
+ function normalizeList(response) {
428
+ const { data, page } = normalizePaged(response);
429
+ const payload = data;
430
+ const items = Array.isArray(payload?.data) ? payload.data : Array.isArray(payload?.records) ? payload.records : Array.isArray(payload?.list) ? payload.list : Array.isArray(payload) ? payload : [];
431
+ return { data: items, page };
432
+ }
433
+ function toBase64Html(text) {
434
+ return Buffer.from(String(text), "utf8").toString("base64");
435
+ }
436
+ function requireConfirm(args, action) {
437
+ if (args.confirm !== true) {
438
+ throw coworkConfirmationError(action, { hint: "\u91CD\u65B0\u8C03\u7528\u65F6\u4F20\u5165 confirm=true \u4E0E prepare \u8FD4\u56DE\u7684 continuation" });
439
+ }
440
+ }
441
+ async function verifyLease(args, action, env) {
442
+ const lease = await env.continuation.verify(args.continuation, action);
443
+ const session = await env.host.getSession();
444
+ if (lease.baseUrl !== session.baseUrl || lease.profile !== session.profile || lease.userId !== session.userId) {
445
+ throw coworkValidationError("context_mismatch", "\u786E\u8BA4\u4E0A\u4E0B\u6587\u5DF2\u53D8\u5316\uFF08\u79DF\u6237\u6216\u767B\u5F55\u8D26\u53F7\u4E0D\u540C\uFF09\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
446
+ }
447
+ return lease;
448
+ }
449
+ function buildListBody(args, scope) {
450
+ if (scope === "discussApprove") {
451
+ return compact({
452
+ current: toPositiveInt(args.current, "current") ?? 1,
453
+ type: typeof args.type === "string" && args.type ? args.type : "and",
454
+ dateType: typeof args.dateType === "string" ? args.dateType : "",
455
+ ...toPositiveInt(args.pageSize, "pageSize") !== void 0 ? { pageSize: toPositiveInt(args.pageSize, "pageSize") } : {}
456
+ });
457
+ }
458
+ const body = {
459
+ current: toPositiveInt(args.current, "current") ?? 1,
460
+ type: typeof args.type === "string" && args.type ? args.type : "and"
461
+ };
462
+ const paging = toPositiveInt(args.pageSize, "pageSize");
463
+ if (paging !== void 0) body.pageSize = paging;
464
+ const conditions = [
465
+ ["itemName", "itemNameCondition"],
466
+ ["sectionId", "sectionCondition"],
467
+ ["principal", "principalCondition"],
468
+ ["creator", "creatorCondition"],
469
+ ["tagId", "tagCondition"],
470
+ ["tagCommonId", "tagCommonCondition"],
471
+ ["applyer", "applyerCondition"],
472
+ ["applyerDept", "applyerDeptCondition"],
473
+ ["approver", "approverCondition"],
474
+ ["applyStatus", "applyStatusCondition"]
475
+ ];
476
+ for (const [valueField, conditionField2] of conditions) {
477
+ if (args[valueField] === void 0) continue;
478
+ const condition = typeof args[conditionField2] === "string" && args[conditionField2] ? String(args[conditionField2]) : "in";
479
+ body[conditionField2] = condition;
480
+ body[valueField] = String(args[valueField]);
481
+ }
482
+ if (scope === "main" || scope === "attention" || scope === "mineItem" || scope === "apply" || scope === "itemApprove") {
483
+ body.itemStatus = args.itemStatus === void 0 ? "1" : String(args.itemStatus);
484
+ body.hidden = args.hidden === void 0 ? "0" : String(args.hidden);
485
+ }
486
+ if (scope === "itemApprove") {
487
+ body.itemNameCondition = body.itemNameCondition ?? "in";
488
+ body.sectionCondition = body.sectionCondition ?? "bl";
489
+ body.principalCondition = body.principalCondition ?? "bl";
490
+ body.creatorCondition = body.creatorCondition ?? "bl";
491
+ }
492
+ if (scope === "main" && typeof args.creatorSearch === "string" && args.creatorSearch) {
493
+ body.creatorSearch = args.creatorSearch;
494
+ }
495
+ if (scope === "collect") {
496
+ body.orderBy = typeof args.orderBy === "string" && args.orderBy ? args.orderBy : "collectTime";
497
+ body.sortOrder = typeof args.sortOrder === "string" && args.sortOrder ? args.sortOrder : "desc";
498
+ if (args.quickSearchDatas && typeof args.quickSearchDatas === "object") {
499
+ body.quickSearchDatas = args.quickSearchDatas;
500
+ }
501
+ }
502
+ if (scope === "mineDiscuss" || scope === "mineComment") {
503
+ if (typeof args.tabKey === "string" && args.tabKey) body.tabKey = args.tabKey;
504
+ }
505
+ if (scope === "mineItem") {
506
+ body.tabKey = typeof args.tabKey === "string" && args.tabKey ? args.tabKey : "mineItemCreate";
507
+ }
508
+ if (scope === "related") {
509
+ body.discussFrom = typeof args.discussFrom === "string" && args.discussFrom ? args.discussFrom : "relatedMenu";
510
+ }
511
+ return compact(body);
512
+ }
513
+
514
+ // src/shortcuts/cowork/operations/read.ts
515
+ var LIST_PATHS = {
516
+ main: "/api/cowork/main/getCoworkMainItemList",
517
+ attention: "/api/cowork/attention/getCoworkAttentionItemList",
518
+ collect: "/api/cowork/collect/getCoworkCollectList",
519
+ mineDiscuss: "/api/cowork/mine/getCoworkMineDiscussList",
520
+ mineComment: "/api/cowork/mine/getCoworkMineCommentList",
521
+ mineItem: "/api/cowork/mineItem/getCoworkMineItemList",
522
+ related: "/api/cowork/related/relatedRecord",
523
+ apply: "/api/cowork/apply/getCoworkApplyList",
524
+ approve: "/api/cowork/apply/getCoworkApplyApproveList",
525
+ log: "/api/cowork/apply/getCoworkApplyLogList",
526
+ quit: "/api/cowork/apply/getCoworkQuitList",
527
+ // 审批台列表(脚本实测;接口文档未收录,但真机验证可用)
528
+ itemApprove: "/api/cowork/itemApprove/getCoworkItemApproveList",
529
+ discussApprove: "/api/cowork/discussApprove/getCoworkDiscussApproveList"
530
+ };
531
+ var CONDITION_PATHS = {
532
+ main: "/api/cowork/main/getCoworkMainItemSearchCondition",
533
+ attention: "/api/cowork/attention/getCoworkAttentionItemSearchCondition",
534
+ collect: "/api/cowork/collect/getCoworkDiscussCollectSearchCondition",
535
+ mine: "/api/cowork/mine/getCoworkMineSearchCondition",
536
+ mineItem: "/api/cowork/mineItem/getCoworkMineItemSearchCondition",
537
+ related: "/api/cowork/related/getCoworkRelatedSearchCondition",
538
+ apply: "/api/cowork/apply/getCoworkItemApplySearchCondition",
539
+ approve: "/api/cowork/apply/getCoworkApplyApproveSearchCondition",
540
+ log: "/api/cowork/apply/getCoworkApplyLogSearchCondition",
541
+ quit: "/api/cowork/apply/getCoworkQuitSearchCondition",
542
+ discuss: "/api/cowork/view/getCoworkDiscussSearchCondition"
543
+ };
544
+ var LIST_SCOPES = Object.keys(LIST_PATHS);
545
+ var CONDITION_SCOPES = Object.keys(CONDITION_PATHS);
546
+ var conditionField = (description) => ({
547
+ type: "string",
548
+ enum: ["in", "bl"],
549
+ description: `${description}\u5339\u914D\u6A21\u5F0F\uFF1Ain \u7CBE\u786E / bl \u6A21\u7CCA`
550
+ });
551
+ var listSchema = schemaOf(
552
+ {
553
+ scope: {
554
+ type: "string",
555
+ enum: LIST_SCOPES,
556
+ description: [
557
+ "main=\u534F\u4F5C\u5217\u8868",
558
+ "attention=\u6211\u5173\u6CE8\u7684",
559
+ "collect=\u6211\u6536\u85CF\u7684",
560
+ "mineDiscuss=\u6211\u7684\u8BA8\u8BBA",
561
+ "mineComment=\u6211\u7684\u8BC4\u8BBA",
562
+ "mineItem=\u6211\u7684\u4E8B\u9879\uFF08tabKey \u533A\u5206\u6211\u521B\u5EFA\u7684/\u6211\u8D1F\u8D23\u7684\uFF09",
563
+ "related=\u76F8\u5173\u6211",
564
+ "apply=\u7533\u8BF7\u52A0\u5165\u5217\u8868",
565
+ "approve=\u5F85\u5BA1\u6279\u5217\u8868\uFF08\u52A0\u5165\u7533\u8BF7\uFF09",
566
+ "log=\u5BA1\u6279\u65E5\u5FD7",
567
+ "quit=\u9000\u51FA\u5217\u8868",
568
+ "itemApprove=\u4E8B\u9879\u5BA1\u6279\u53F0\u5217\u8868",
569
+ "discussApprove=\u4EA4\u6D41\u5BA1\u6279\u53F0\u5217\u8868"
570
+ ].join("\uFF1B")
571
+ },
572
+ current: SCHEMA_PAGE_CURRENT,
573
+ pageSize: SCHEMA_PAGE_SIZE,
574
+ type: { type: "string", enum: ["and", "or"], description: "\u6761\u4EF6\u7EC4\u5408\u65B9\u5F0F\uFF0C\u9ED8\u8BA4 and" },
575
+ itemName: { type: "string", description: "\u534F\u4F5C\u4E3B\u9898" },
576
+ itemNameCondition: conditionField("\u534F\u4F5C\u4E3B\u9898"),
577
+ sectionId: SCHEMA_ID,
578
+ sectionCondition: conditionField("\u7248\u5757"),
579
+ principal: SCHEMA_ID,
580
+ principalCondition: conditionField("\u8D1F\u8D23\u4EBA"),
581
+ creator: SCHEMA_ID,
582
+ creatorCondition: conditionField("\u521B\u5EFA\u4EBA"),
583
+ creatorSearch: { type: "string", description: "\u521B\u5EFA\u4EBA\u5173\u952E\u5B57\uFF08\u4EC5 scope=main\uFF09" },
584
+ tagId: SCHEMA_ID,
585
+ tagCondition: conditionField("\u6807\u7B7E"),
586
+ tagCommonId: SCHEMA_ID,
587
+ tagCommonCondition: conditionField("\u516C\u5171\u6807\u7B7E"),
588
+ itemStatus: { type: "string", description: "\u534F\u4F5C\u72B6\u6001\uFF1A1 \u8FDB\u884C\u4E2D\uFF08\u9ED8\u8BA4 1\uFF09" },
589
+ hidden: { type: "string", description: "\u662F\u5426\u542B\u9690\u85CF\uFF1A0 \u5426\uFF08\u9ED8\u8BA4 0\uFF09/ 1 \u662F" },
590
+ tabKey: { type: "string", description: "mineItem \u9ED8\u8BA4 mineItemCreate\uFF1BmineDiscuss/mineComment \u53EF\u7701\u7565" },
591
+ orderBy: { type: "string", enum: ["collectTime"], description: "\u6392\u5E8F\u5B57\u6BB5\uFF08\u4EC5 scope=collect\uFF09" },
592
+ sortOrder: { type: "string", enum: ["asc", "desc"], description: "\u6392\u5E8F\u65B9\u5411\uFF08\u4EC5 scope=collect\uFF09" },
593
+ quickSearchDatas: { type: "object", description: "\u5FEB\u901F\u641C\u7D22\u6761\u4EF6\uFF08\u4EC5 scope=collect\uFF09" },
594
+ discussFrom: { type: "string", description: "\u6765\u6E90\u6807\u8BC6\uFF0Cscope=related \u9ED8\u8BA4 relatedMenu" },
595
+ applyer: SCHEMA_ID,
596
+ applyerCondition: conditionField("\u7533\u8BF7\u4EBA\uFF08scope=approve\uFF09"),
597
+ applyerDept: SCHEMA_ID,
598
+ applyerDeptCondition: conditionField("\u7533\u8BF7\u4EBA\u90E8\u95E8\uFF08scope=approve\uFF09"),
599
+ approver: SCHEMA_ID,
600
+ approverCondition: conditionField("\u5BA1\u6279\u4EBA\uFF08scope=log\uFF09"),
601
+ applyStatus: { type: "string", description: "\u7533\u8BF7\u72B6\u6001\uFF08scope=log\uFF09" },
602
+ applyStatusCondition: conditionField("\u7533\u8BF7\u72B6\u6001\uFF08scope=log\uFF09"),
603
+ dateType: { type: "string", description: "\u65E5\u671F\u7C7B\u578B\uFF08scope=discussApprove\uFF0C\u9ED8\u8BA4\u7A7A\uFF09" }
604
+ },
605
+ { required: ["scope"] }
606
+ );
607
+ var coworkList = {
608
+ name: "cowork.list",
609
+ resource: "cowork",
610
+ method: "list",
611
+ action: "cowork.list",
612
+ summary: "\u6309 scope \u67E5\u8BE2\u534F\u4F5C/\u5173\u6CE8/\u6536\u85CF/\u6211\u7684\u4E8B\u9879/\u7533\u8BF7/\u5F85\u5BA1\u6279/\u5BA1\u6279\u65E5\u5FD7/\u9000\u51FA\u7B49\u5217\u8868\uFF08\u5206\u9875\uFF1B\u7B5B\u9009\u5B57\u6BB5\u4EE5 cowork.conditions \u8FD4\u56DE\u4E3A\u51C6\uFF09",
613
+ risk: READ,
614
+ inputSchema: listSchema,
615
+ handler: async (args, { host }) => {
616
+ const scope = assertEnum(args.scope, LIST_SCOPES, "scope");
617
+ const body = buildListBody(args, scope);
618
+ const response = await host.request({
619
+ method: "POST",
620
+ path: LIST_PATHS[scope],
621
+ body,
622
+ operation: "cowork.list"
623
+ });
624
+ const { data, page } = normalizeList(response);
625
+ return coworkSuccess("cowork.list", data, { scope, ...page });
626
+ }
627
+ };
628
+ var coworkConditions = {
629
+ name: "cowork.conditions",
630
+ resource: "cowork",
631
+ method: "conditions",
632
+ action: "cowork.conditions",
633
+ summary: "\u53D6\u5BF9\u5E94\u5217\u8868\u7684\u9AD8\u7EA7\u641C\u7D22\u6761\u4EF6\u5143\u6570\u636E\uFF08groups/layout\uFF09\uFF0C\u662F\u6784\u9020 cowork.list \u7B5B\u9009\u53C2\u6570\u7684\u552F\u4E00\u4F9D\u636E",
634
+ risk: READ,
635
+ inputSchema: schemaOf(
636
+ { scope: { type: "string", enum: CONDITION_SCOPES, description: "\u4E0E cowork.list \u7684 scope \u5BF9\u5E94\uFF1Bdiscuss \u7528\u4E8E\u8BA8\u8BBA\u5217\u8868" } },
637
+ { required: ["scope"] }
638
+ ),
639
+ handler: async (args, { host }) => {
640
+ const scope = assertEnum(args.scope, CONDITION_SCOPES, "scope");
641
+ const response = await host.request({
642
+ method: "POST",
643
+ path: CONDITION_PATHS[scope],
644
+ body: {},
645
+ operation: "cowork.conditions"
646
+ });
647
+ return coworkSuccess("cowork.conditions", unwrapData(response) ?? null, { scope });
648
+ }
649
+ };
650
+ var coworkCount = {
651
+ name: "cowork.count",
652
+ resource: "cowork",
653
+ method: "count",
654
+ action: "cowork.count",
655
+ summary: "\u7EDF\u8BA1\u8FDB\u884C\u4E2D\u534F\u4F5C\u603B\u6570\uFF08\u4E0E scope=main \u5217\u8868\u53E3\u5F84\u4E00\u81F4\uFF09",
656
+ risk: READ,
657
+ inputSchema: schemaOf({
658
+ hidden: { type: "string", description: "\u662F\u5426\u542B\u9690\u85CF\uFF1A0 \u5426\uFF08\u9ED8\u8BA4\uFF09/ 1 \u662F" },
659
+ itemStatus: { type: "string", description: "\u534F\u4F5C\u72B6\u6001\uFF0C\u9ED8\u8BA4 1 \u8FDB\u884C\u4E2D" }
660
+ }),
661
+ handler: async (args, { host }) => {
662
+ const body = compact({
663
+ hidden: args.hidden === void 0 ? "0" : String(args.hidden),
664
+ itemStatus: args.itemStatus === void 0 ? "1" : String(args.itemStatus)
665
+ });
666
+ const response = await host.request({
667
+ method: "POST",
668
+ path: "/api/cowork/main/countCoworkMainItem",
669
+ body,
670
+ operation: "cowork.count"
671
+ });
672
+ return coworkSuccess("cowork.count", unwrapData(response) ?? null);
673
+ }
674
+ };
675
+ var coworkView = {
676
+ name: "cowork.view",
677
+ resource: "cowork",
678
+ method: "view",
679
+ action: "cowork.view",
680
+ summary: "\u67E5\u534F\u4F5C\u8BE6\u60C5\uFF08\u72B6\u6001/\u7248\u5757/\u6743\u9650\u6807\u8BB0 canEdit\u3001canEnd\u3001canReply \u7B49\uFF09",
681
+ risk: READ,
682
+ inputSchema: schemaOf(
683
+ { id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" } },
684
+ { required: ["id"] }
685
+ ),
686
+ handler: async (args, { host }) => {
687
+ const id = toId(args.id, "id");
688
+ const response = await host.request({
689
+ method: "POST",
690
+ path: "/api/cowork/view/viewCowork",
691
+ form: { id },
692
+ operation: "cowork.view"
693
+ });
694
+ return coworkSuccess("cowork.view", unwrapData(response) ?? null);
695
+ }
696
+ };
697
+ var coworkDiscussList = {
698
+ name: "cowork.discuss.list",
699
+ resource: "cowork",
700
+ method: "discuss.list",
701
+ action: "cowork.discuss.list",
702
+ summary: "\u67E5\u67D0\u534F\u4F5C\u4E0B\u7684\u8BA8\u8BBA/\u56DE\u590D\u8BB0\u5F55\uFF08\u9ED8\u8BA4\u6309\u6700\u540E\u56DE\u590D\u5012\u5E8F\uFF09",
703
+ risk: READ,
704
+ inputSchema: schemaOf({
705
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
706
+ current: SCHEMA_PAGE_CURRENT,
707
+ pageSize: SCHEMA_PAGE_SIZE,
708
+ orderColumn: { type: "string", description: "\u6392\u5E8F\u5B57\u6BB5\uFF0C\u9ED8\u8BA4 lastReply" },
709
+ orderAsc: { type: "boolean", description: "\u662F\u5426\u5347\u5E8F\uFF0C\u9ED8\u8BA4 false\uFF08\u5012\u5E8F\uFF09" }
710
+ }, { required: ["coworkId"] }),
711
+ handler: async (args, { host }) => {
712
+ const coworkId = toId(args.coworkId, "coworkId");
713
+ const body = compact({
714
+ coworkId,
715
+ current: toPositiveInt(args.current, "current") ?? 1,
716
+ pageSize: toPositiveInt(args.pageSize, "pageSize"),
717
+ orders: [{
718
+ column: typeof args.orderColumn === "string" && args.orderColumn ? args.orderColumn : "lastReply",
719
+ asc: args.orderAsc === true
720
+ }]
721
+ });
722
+ const response = await host.request({
723
+ method: "POST",
724
+ path: "/api/cowork/view/discussRecord",
725
+ body,
726
+ operation: "cowork.discuss.list"
727
+ });
728
+ const { data, page } = normalizeList(response);
729
+ return coworkSuccess("cowork.discuss.list", data, page);
730
+ }
731
+ };
732
+ var PARTICIPANT_SCOPES = ["all", "share", "quit"];
733
+ var coworkParticipantList = {
734
+ name: "cowork.participant.list",
735
+ resource: "cowork",
736
+ method: "participant.list",
737
+ action: "cowork.participant.list",
738
+ summary: "\u67E5\u534F\u4F5C\u53C2\u4E0E\u4EBA\uFF1Aall=\u5168\u90E8\u53C2\u4E0E\u4EBA / share=\u5171\u4EAB\u53C2\u4E0E\u4EBA\uFF08\u542B\u90AE\u7BB1\u624B\u673A\uFF09 / quit=\u9000\u51FA\u8BB0\u5F55",
739
+ risk: READ,
740
+ inputSchema: schemaOf({
741
+ scope: { type: "string", enum: [...PARTICIPANT_SCOPES], description: "all / share / quit" },
742
+ id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
743
+ participationFrom: { type: "string", description: "scope=all \u65F6\u7684\u6765\u6E90\u6807\u8BC6\uFF0C\u9ED8\u8BA4 participant" },
744
+ current: SCHEMA_PAGE_CURRENT,
745
+ pageSize: SCHEMA_PAGE_SIZE
746
+ }, { required: ["scope", "id"] }),
747
+ handler: async (args, { host }) => {
748
+ const scope = assertEnum(args.scope, PARTICIPANT_SCOPES, "scope");
749
+ const id = toId(args.id, "id");
750
+ if (scope === "share") {
751
+ const response2 = await host.request({
752
+ method: "POST",
753
+ path: "/api/cowork/view/shareParticipation",
754
+ form: { id },
755
+ operation: "cowork.participant.list"
756
+ });
757
+ return coworkSuccess("cowork.participant.list", unwrapData(response2) ?? null, { scope });
758
+ }
759
+ if (scope === "quit") {
760
+ const body2 = compact({
761
+ coworkId: id,
762
+ current: toPositiveInt(args.current, "current") ?? 1,
763
+ pageSize: toPositiveInt(args.pageSize, "pageSize") ?? 10
764
+ });
765
+ const response2 = await host.request({
766
+ method: "POST",
767
+ path: "/api/cowork/main/getCoworkQuitList",
768
+ body: body2,
769
+ operation: "cowork.participant.list"
770
+ });
771
+ const { data: data2, page: page2 } = normalizeList(response2);
772
+ return coworkSuccess("cowork.participant.list", data2, { scope, ...page2 });
773
+ }
774
+ const body = compact({
775
+ id,
776
+ participationFrom: typeof args.participationFrom === "string" && args.participationFrom ? args.participationFrom : "participant",
777
+ current: toPositiveInt(args.current, "current") ?? 1,
778
+ pageSize: toPositiveInt(args.pageSize, "pageSize") ?? 10
779
+ });
780
+ const response = await host.request({
781
+ method: "POST",
782
+ path: "/api/cowork/view/participationAllList",
783
+ body,
784
+ operation: "cowork.participant.list"
785
+ });
786
+ const { data, page } = normalizeList(response);
787
+ return coworkSuccess("cowork.participant.list", data, { scope, ...page });
788
+ }
789
+ };
790
+ var coworkResource = {
791
+ name: "cowork.resource",
792
+ resource: "cowork",
793
+ method: "resource",
794
+ action: "cowork.resource",
795
+ summary: "\u67E5\u534F\u4F5C\u5173\u8054\u8D44\u6E90\u6570\u636E\uFF08\u4E3A\u7A7A\u65F6\u8FD4\u56DE {}\uFF09",
796
+ risk: READ,
797
+ inputSchema: schemaOf({ id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" } }, { required: ["id"] }),
798
+ handler: async (args, { host }) => {
799
+ const id = toId(args.id, "id");
800
+ const response = await host.request({
801
+ method: "POST",
802
+ path: "/api/cowork/view/resourceData",
803
+ form: { id },
804
+ operation: "cowork.resource"
805
+ });
806
+ return coworkSuccess("cowork.resource", unwrapData(response) ?? null);
807
+ }
808
+ };
809
+ var coworkVoteLog = {
810
+ name: "cowork.vote.log",
811
+ resource: "cowork",
812
+ method: "vote.log",
813
+ action: "cowork.vote.log",
814
+ summary: "\u67E5\u534F\u4F5C\u6295\u7968\u65E5\u5FD7\uFF08\u65E0\u6295\u7968\u65F6 total \u4E3A 0\uFF09",
815
+ risk: READ,
816
+ inputSchema: schemaOf({
817
+ id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
818
+ current: SCHEMA_PAGE_CURRENT,
819
+ pageSize: SCHEMA_PAGE_SIZE
820
+ }, { required: ["id"] }),
821
+ handler: async (args, { host }) => {
822
+ const id = toId(args.id, "id");
823
+ const body = compact({
824
+ id,
825
+ current: toPositiveInt(args.current, "current") ?? 1,
826
+ pageSize: toPositiveInt(args.pageSize, "pageSize") ?? 10
827
+ });
828
+ const response = await host.request({
829
+ method: "POST",
830
+ path: "/api/cowork/view/voteLog",
831
+ body,
832
+ operation: "cowork.vote.log"
833
+ });
834
+ const { data, page } = normalizeList(response);
835
+ return coworkSuccess("cowork.vote.log", data, page);
836
+ }
837
+ };
838
+ var coworkForm = {
839
+ name: "cowork.form",
840
+ resource: "cowork",
841
+ method: "form",
842
+ action: "cowork.form",
843
+ summary: "\u53D6\u65B0\u5EFA\u534F\u4F5C\u7684\u8868\u5355\u5143\u6570\u636E\uFF08groups/layout\uFF09\uFF0C\u7528\u4E8E\u786E\u5B9A\u7248\u5757 sectionId \u4E0E\u53EF\u9009\u5F00\u5173\u5B57\u6BB5\uFF1B\u5EFA\u534F\u4F5C\u524D\u5FC5\u987B\u5148\u8C03\u7528",
844
+ risk: READ,
845
+ inputSchema: schemaOf({ id: { ...SCHEMA_ID, description: "\u7F16\u8F91\u5DF2\u6709\u534F\u4F5C\u6587\u65F6\u4F20\u5176 id\uFF1B\u65B0\u5EFA\u7559\u7A7A" } }),
846
+ handler: async (args, { host }) => {
847
+ const id = toId(args.id, "id");
848
+ const response = await host.request({
849
+ method: "POST",
850
+ path: "/api/cowork/main/getCoworkAddItemForm",
851
+ form: { id: id ?? "", type: "new" },
852
+ operation: "cowork.form"
853
+ });
854
+ return coworkSuccess("cowork.form", unwrapData(response) ?? null);
855
+ }
856
+ };
857
+ var META_SCOPES = ["operateAuth", "layout"];
858
+ var coworkMeta = {
859
+ name: "cowork.meta",
860
+ resource: "cowork",
861
+ method: "meta",
862
+ action: "cowork.meta",
863
+ summary: "\u53D6\u534F\u4F5C\u6A21\u5757\u7684\u754C\u9762\u5143\u6570\u636E\uFF1AoperateAuth=\u5F53\u524D\u7528\u6237\u5728\u5217\u8868\u53EF\u6267\u884C\u7684\u64CD\u4F5C\uFF08\u5982\u6279\u91CF\u5220\u9664\uFF09/ layout=\u884C\u4E3A\u5E03\u5C40\u6807\u8BC6",
864
+ risk: READ,
865
+ inputSchema: schemaOf(
866
+ { scope: { type: "string", enum: [...META_SCOPES], description: "operateAuth \u6216 layout" } },
867
+ { required: ["scope"] }
868
+ ),
869
+ handler: async (args, { host }) => {
870
+ const scope = assertEnum(args.scope, META_SCOPES, "scope");
871
+ if (scope === "layout") {
872
+ const response2 = await host.request({
873
+ method: "GET",
874
+ path: "/api/cowork/behavior/getLayout",
875
+ operation: "cowork.meta"
876
+ });
877
+ return coworkSuccess("cowork.meta", unwrapData(response2) ?? null, { scope });
878
+ }
879
+ const response = await host.request({
880
+ method: "POST",
881
+ path: "/api/cowork/main/getListOperateAuth",
882
+ body: {},
883
+ operation: "cowork.meta"
884
+ });
885
+ return coworkSuccess("cowork.meta", unwrapData(response) ?? null, { scope });
886
+ }
887
+ };
888
+ var coworkPermissionList = {
889
+ name: "cowork.permission.list",
890
+ resource: "cowork",
891
+ method: "permission.list",
892
+ action: "cowork.permission.list",
893
+ summary: "\u67E5\u534F\u4F5C\u7684\u5171\u4EAB\u6743\u9650\u5BF9\u8C61\u5217\u8868\uFF08\u5220\u9664\u5171\u4EAB\u5BF9\u8C61\u524D\u7528\u5B83\u53D6\u5F97\u771F\u5B9E\u8BB0\u5F55 id\uFF09",
894
+ risk: READ,
895
+ inputSchema: schemaOf({
896
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
897
+ permissionId: { ...SCHEMA_ID, description: "\u6743\u9650\u7C7B\u578B id\uFF0C\u9ED8\u8BA4 5\uFF08\u534F\u4F5C\u9ED8\u8BA4\u53C2\u4E0E\u6743\u9650\uFF09" },
898
+ current: SCHEMA_PAGE_CURRENT,
899
+ pageSize: SCHEMA_PAGE_SIZE
900
+ }, { required: ["coworkId"] }),
901
+ handler: async (args, { host }) => {
902
+ const coworkId = toId(args.coworkId, "coworkId");
903
+ const permissionId = toId(args.permissionId, "permissionId") ?? "5";
904
+ const body = {
905
+ sourceId: coworkId,
906
+ permissionId,
907
+ sourceType: 1,
908
+ current: toPositiveInt(args.current, "current") ?? 1,
909
+ pageSize: toPositiveInt(args.pageSize, "pageSize") ?? 50,
910
+ id: coworkId,
911
+ permissionFrom: permissionId
912
+ };
913
+ const response = await host.request({
914
+ method: "POST",
915
+ path: "/api/cowork/permission/getCoworkSharePermissionList",
916
+ body,
917
+ operation: "cowork.permission.list"
918
+ });
919
+ const { data, page } = normalizeList(response);
920
+ return coworkSuccess("cowork.permission.list", data, { coworkId, permissionId, ...page });
921
+ }
922
+ };
923
+ var coworkReadOperations = [
924
+ coworkList,
925
+ coworkConditions,
926
+ coworkCount,
927
+ coworkView,
928
+ coworkDiscussList,
929
+ coworkParticipantList,
930
+ coworkResource,
931
+ coworkVoteLog,
932
+ coworkForm,
933
+ coworkMeta,
934
+ coworkPermissionList
935
+ ];
936
+
937
+ // src/shortcuts/cowork/operations/item-write.ts
938
+ function isNetworkError(error) {
939
+ return error instanceof CoworkCliError && error.type === "network";
940
+ }
941
+ async function resolveSectionOptions(host) {
942
+ const response = await host.request({
943
+ method: "POST",
944
+ path: "/api/cowork/main/getCoworkAddItemForm",
945
+ form: { id: "", type: "new" },
946
+ operation: "cowork.item.create.prepare"
947
+ });
948
+ const data = unwrapData(response);
949
+ const options = data?.items?.sectionId?.options;
950
+ if (!Array.isArray(options)) return [];
951
+ return options.map((o) => ({ id: String(o.id), name: String(o.content ?? o.name ?? "") }));
952
+ }
953
+ var SWITCH_FIELDS = [
954
+ "enableDiscussElog",
955
+ "enableViewLog",
956
+ "expandDetail",
957
+ "allowInvite",
958
+ "allowQuit",
959
+ "allowApply",
960
+ "allowHideDelelted"
961
+ ];
962
+ function buildSwitches(args) {
963
+ const switches = {};
964
+ for (const field of SWITCH_FIELDS) {
965
+ const value = args[field];
966
+ switches[field] = value === void 0 ? 1 : value === true || value === 1 || value === "1" ? 1 : 0;
967
+ }
968
+ return switches;
969
+ }
970
+ var itemCreatePrepare = {
971
+ name: "cowork.item.create.prepare",
972
+ resource: "cowork",
973
+ method: "item.create.prepare",
974
+ action: "cowork.item.create.prepare",
975
+ summary: "\u65B0\u5EFA\u534F\u4F5C\u7684\u786E\u8BA4\u6458\u8981\uFF1A\u6821\u9A8C\u7248\u5757 id \u662F\u5426\u5728\u672C\u73AF\u5883\u771F\u5B9E\u5B58\u5728\u3001\u8D1F\u8D23\u4EBA\u9ED8\u8BA4\u4E3A\u5F53\u524D\u7528\u6237\u3001\u5F00\u5173\u9ED8\u8BA4\u5168\u5F00\uFF1B\u4E0D\u5199\u5165",
976
+ risk: READ_BEFORE_WRITE,
977
+ inputSchema: schemaOf({
978
+ itemName: { type: "string", maxLength: 200, description: "\u534F\u4F5C\u4E3B\u9898" },
979
+ itemContent: { type: "string", maxLength: 2e4, description: "\u8BE6\u7EC6\u8BF4\u660E\uFF08\u7EAF\u6587\u672C\u6216 HTML\uFF0CCLI \u5185\u90E8\u6309\u63A5\u53E3\u8981\u6C42\u505A Base64 \u7F16\u7801\uFF09" },
980
+ sectionId: { ...SCHEMA_ID, description: "\u6240\u5C5E\u7248\u5757 id\uFF08\u7528 cowork.form \u7684 sectionId \u9009\u9879\u786E\u5B9A\uFF09" },
981
+ principal: { ...SCHEMA_ID, description: "\u8D1F\u8D23\u4EBA\u4EBA\u5458 id\uFF0C\u9ED8\u8BA4\u5F53\u524D\u767B\u5F55\u7528\u6237" },
982
+ endTime: { ...SCHEMA_DATETIME, description: "\u622A\u6B62\u65F6\u95F4 YYYY-MM-DD HH:mm\uFF0C\u9ED8\u8BA4 7 \u5929\u540E" },
983
+ enableDiscussElog: { type: "boolean", description: "\u542F\u7528\u8BA8\u8BBA\u65E5\u5FD7\uFF0C\u9ED8\u8BA4 true" },
984
+ enableViewLog: { type: "boolean", description: "\u542F\u7528\u67E5\u770B\u65E5\u5FD7\uFF0C\u9ED8\u8BA4 true" },
985
+ expandDetail: { type: "boolean", description: "\u5C55\u5F00\u8BE6\u60C5\uFF0C\u9ED8\u8BA4 true" },
986
+ allowInvite: { type: "boolean", description: "\u5141\u8BB8\u9080\u8BF7\uFF0C\u9ED8\u8BA4 true" },
987
+ allowQuit: { type: "boolean", description: "\u5141\u8BB8\u9000\u51FA\uFF0C\u9ED8\u8BA4 true" },
988
+ allowApply: { type: "boolean", description: "\u5141\u8BB8\u7533\u8BF7\uFF0C\u9ED8\u8BA4 true" },
989
+ allowHideDelelted: { type: "boolean", description: "\u5141\u8BB8\u9690\u85CF\u5220\u9664\uFF0C\u9ED8\u8BA4 true" }
990
+ }, { required: ["itemName", "sectionId"] }),
991
+ handler: async (args, env) => {
992
+ const itemName = assertString(args.itemName, "itemName", 200);
993
+ const sectionId = toId(args.sectionId, "sectionId");
994
+ const options = await resolveSectionOptions(env.host);
995
+ let sectionName;
996
+ if (options.length > 0) {
997
+ const hit = options.find((o) => o.id === sectionId);
998
+ if (!hit) {
999
+ throw coworkNotFoundError(
1000
+ "section_not_found",
1001
+ `\u7248\u5757 id ${sectionId} \u4E0D\u5728\u672C\u73AF\u5883\u7684\u53EF\u9009\u7248\u5757\u4E2D\uFF0C\u8BF7\u7528 cowork.form \u91CD\u65B0\u83B7\u53D6`,
1002
+ { availableSections: options }
1003
+ );
1004
+ }
1005
+ sectionName = hit.name;
1006
+ }
1007
+ const session = await env.host.getSession();
1008
+ const principal = toId(args.principal, "principal") || session.userId;
1009
+ if (!principal) {
1010
+ throw coworkValidationError("principal_required", "\u65E0\u6CD5\u786E\u5B9A\u8D1F\u8D23\u4EBA\uFF1A\u8BF7\u663E\u5F0F\u4F20 principal\uFF08\u4EBA\u5458 id\uFF09");
1011
+ }
1012
+ const endTime = args.endTime ? assertString(args.endTime, "endTime", 32) : defaultEndTime();
1013
+ const switches = buildSwitches(args);
1014
+ const itemContent = typeof args.itemContent === "string" ? args.itemContent : "";
1015
+ const summary = {
1016
+ itemName,
1017
+ sectionId,
1018
+ sectionName: sectionName ?? "(\u672A\u53D6\u5230\u7248\u5757\u540D\uFF0C\u4EC5\u6821\u9A8C\u4E86\u8868\u5355\u7ED3\u6784)",
1019
+ principal,
1020
+ principalIsCurrentUser: principal === session.userId,
1021
+ endTime,
1022
+ switches,
1023
+ contentLength: itemContent.length
1024
+ };
1025
+ const continuation = await env.continuation.issue({
1026
+ operation: "cowork.item.create.apply",
1027
+ baseUrl: session.baseUrl,
1028
+ profile: session.profile,
1029
+ userId: session.userId,
1030
+ itemName,
1031
+ sectionId,
1032
+ principal,
1033
+ endTime,
1034
+ switches,
1035
+ contentHash: hashCode(itemContent)
1036
+ });
1037
+ return coworkSuccess("cowork.item.create.prepare", {
1038
+ summary,
1039
+ onApply: "\u5C06\u8C03\u7528 saveItemsInfo \u65B0\u5EFA\u534F\u4F5C\uFF08\u4E3B\u8868 + \u5F00\u5173\u53C2\u6570\uFF09\uFF0C\u6210\u529F\u540E\u8FD4\u56DE\u65B0\u534F\u4F5C id",
1040
+ continuation
1041
+ });
1042
+ }
1043
+ };
1044
+ function hashCode(text) {
1045
+ let hash = 0;
1046
+ for (let i = 0; i < text.length; i++) {
1047
+ hash = hash * 31 + text.charCodeAt(i) | 0;
1048
+ }
1049
+ return String(hash >>> 0);
1050
+ }
1051
+ function defaultEndTime() {
1052
+ const target = new Date(Date.now() + 7 * 24 * 3600 * 1e3);
1053
+ const pad = (n) => String(n).padStart(2, "0");
1054
+ return `${target.getFullYear()}-${pad(target.getMonth() + 1)}-${pad(target.getDate())} ${pad(target.getHours())}:${pad(target.getMinutes())}`;
1055
+ }
1056
+ var itemCreateApply = {
1057
+ name: "cowork.item.create.apply",
1058
+ resource: "cowork",
1059
+ method: "item.create.apply",
1060
+ action: "cowork.item.create.apply",
1061
+ summary: "\u6267\u884C\u65B0\u5EFA\u534F\u4F5C\uFF08\u9700 confirm=true \u4E0E prepare \u7684 continuation\uFF09",
1062
+ risk: WRITE,
1063
+ requiresConfirmation: true,
1064
+ inputSchema: schemaOf({
1065
+ itemName: { type: "string", maxLength: 200, description: "\u534F\u4F5C\u4E3B\u9898\uFF08\u987B\u4E0E prepare \u4E00\u81F4\uFF09" },
1066
+ itemContent: { type: "string", maxLength: 2e4, description: "\u8BE6\u7EC6\u8BF4\u660E\uFF08\u987B\u4E0E prepare \u4E00\u81F4\uFF09" },
1067
+ sectionId: { ...SCHEMA_ID, description: "\u6240\u5C5E\u7248\u5757 id" },
1068
+ principal: { ...SCHEMA_ID, description: "\u8D1F\u8D23\u4EBA\u4EBA\u5458 id" },
1069
+ endTime: { ...SCHEMA_DATETIME, description: "\u622A\u6B62\u65F6\u95F4" },
1070
+ enableDiscussElog: { type: "boolean" },
1071
+ enableViewLog: { type: "boolean" },
1072
+ expandDetail: { type: "boolean" },
1073
+ allowInvite: { type: "boolean" },
1074
+ allowQuit: { type: "boolean" },
1075
+ allowApply: { type: "boolean" },
1076
+ allowHideDelelted: { type: "boolean" },
1077
+ confirm: { type: "boolean", description: "\u7528\u6237\u660E\u786E\u786E\u8BA4\u540E\u4F20 true" },
1078
+ continuation: { type: "string", description: "prepare \u8FD4\u56DE\u7684 continuation" }
1079
+ }, { required: ["itemName", "sectionId", "confirm", "continuation"] }),
1080
+ handler: async (args, env) => {
1081
+ requireConfirm(args, "cowork.item.create.apply");
1082
+ const lease = await verifyLease(args, "cowork.item.create.apply", env);
1083
+ const itemName = assertString(args.itemName, "itemName", 200);
1084
+ const sectionId = toId(args.sectionId, "sectionId");
1085
+ const principal = args.principal !== void 0 ? toId(args.principal, "principal") : String(lease.principal || "");
1086
+ const endTime = assertString(args.endTime || lease.endTime, "endTime", 32);
1087
+ const itemContent = typeof args.itemContent === "string" ? args.itemContent : "";
1088
+ const switches = buildSwitches(args);
1089
+ if (lease.itemName !== itemName || lease.sectionId !== sectionId || lease.principal !== principal) {
1090
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF08\u4E3B\u9898/\u7248\u5757/\u8D1F\u8D23\u4EBA\u5DF2\u53D8\u5316\uFF09\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1091
+ }
1092
+ if (lease.contentHash !== hashCode(itemContent)) {
1093
+ throw coworkValidationError("content_changed", "\u8BF4\u660E\u5185\u5BB9\u4E0E prepare \u65F6\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1094
+ }
1095
+ const body = {
1096
+ itemName,
1097
+ itemContent: toBase64Html(itemContent),
1098
+ sectionId,
1099
+ principal,
1100
+ endTime,
1101
+ ...switches,
1102
+ relatedFile: "",
1103
+ params: {
1104
+ ...switches,
1105
+ itemName,
1106
+ relatedFile: [],
1107
+ principal: principal ? [{ id: principal, name: "" }] : []
1108
+ }
1109
+ };
1110
+ let response;
1111
+ try {
1112
+ response = await env.host.request({
1113
+ method: "POST",
1114
+ path: "/api/cowork/main/saveItemsInfo",
1115
+ body,
1116
+ operation: "cowork.item.create.apply"
1117
+ });
1118
+ } catch (error) {
1119
+ if (isNetworkError(error)) {
1120
+ throw coworkPartialError("\u65B0\u5EFA\u534F\u4F5C\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u5148\u7528 cowork.list \u6838\u5BF9\u662F\u5426\u5DF2\u521B\u5EFA", { itemName, sectionId });
1121
+ }
1122
+ throw error;
1123
+ }
1124
+ const data = unwrapData(response) ?? {};
1125
+ const root = response;
1126
+ const ok = !!(data.status ?? root?.status);
1127
+ if (!ok) {
1128
+ throw coworkPartialError("\u65B0\u5EFA\u534F\u4F5C\u8FD4\u56DE\u672A\u786E\u8BA4\u6210\u529F\uFF0C\u8BF7\u7528 cowork.list \u6838\u5BF9\u540E\u518D\u51B3\u5B9A\u662F\u5426\u91CD\u8BD5", { itemName, raw: data });
1129
+ }
1130
+ return coworkSuccess("cowork.item.create.apply", {
1131
+ id: data.id ? String(data.id) : null,
1132
+ itemName,
1133
+ sectionId,
1134
+ principal,
1135
+ endTime
1136
+ });
1137
+ }
1138
+ };
1139
+ var ITEM_ACTIONS = ["end"];
1140
+ var itemActionPrepare = {
1141
+ name: "cowork.item.action.prepare",
1142
+ resource: "cowork",
1143
+ method: "item.action.prepare",
1144
+ action: "cowork.item.action.prepare",
1145
+ summary: "\u534F\u4F5C\u7EA7\u52A8\u4F5C\u7684\u786E\u8BA4\u6458\u8981\uFF08\u5F53\u524D\u652F\u6301 end \u7ED3\u675F\u534F\u4F5C\uFF09\uFF1A\u5148\u8BFB\u8BE6\u60C5\u6821\u9A8C\u5B58\u5728\u4E0E canEnd\uFF0C\u4E0D\u5199\u5165",
1146
+ risk: READ_BEFORE_WRITE,
1147
+ inputSchema: schemaOf({
1148
+ action: { type: "string", enum: [...ITEM_ACTIONS], description: "end=\u7ED3\u675F\u534F\u4F5C\uFF08\u4E0D\u53EF\u9006\uFF09" },
1149
+ id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" }
1150
+ }, { required: ["action", "id"] }),
1151
+ handler: async (args, env) => {
1152
+ const action = assertEnum(args.action, ITEM_ACTIONS, "action");
1153
+ const id = toId(args.id, "id");
1154
+ const detailResponse = await env.host.request({
1155
+ method: "POST",
1156
+ path: "/api/cowork/view/viewCowork",
1157
+ form: { id },
1158
+ operation: "cowork.item.action.prepare"
1159
+ });
1160
+ const detail = unwrapData(detailResponse) ?? {};
1161
+ if (!detail || Object.keys(detail).length === 0) {
1162
+ throw coworkNotFoundError("item_not_found", `\u534F\u4F5C ${id} \u4E0D\u5B58\u5728\u6216\u65E0\u6743\u67E5\u770B`);
1163
+ }
1164
+ const canEnd = String(detail.canEnd) === "1";
1165
+ if (!canEnd) {
1166
+ throw coworkValidationError("not_permitted", `\u5F53\u524D\u7528\u6237\u4E0D\u53EF\u7ED3\u675F\u8BE5\u534F\u4F5C\uFF08canEnd=${String(detail.canEnd)}\uFF09`);
1167
+ }
1168
+ const session = await env.host.getSession();
1169
+ const continuation = await env.continuation.issue({
1170
+ operation: "cowork.item.action.apply",
1171
+ baseUrl: session.baseUrl,
1172
+ profile: session.profile,
1173
+ userId: session.userId,
1174
+ action,
1175
+ id,
1176
+ itemName: detail.itemName ?? ""
1177
+ });
1178
+ return coworkSuccess("cowork.item.action.prepare", {
1179
+ summary: {
1180
+ action,
1181
+ id,
1182
+ itemName: detail.itemName ?? "",
1183
+ status: detail.itemStatus,
1184
+ canEnd,
1185
+ warning: action === "end" ? "\u7ED3\u675F\u534F\u4F5C\u540E\u53C2\u4E0E\u8005\u4E0D\u53EF\u518D\u56DE\u590D\uFF0C\u4E14\u9875\u9762\u4E0D\u63D0\u4F9B\u64A4\u9500" : void 0
1186
+ },
1187
+ continuation
1188
+ });
1189
+ }
1190
+ };
1191
+ var itemActionApply = {
1192
+ name: "cowork.item.action.apply",
1193
+ resource: "cowork",
1194
+ method: "item.action.apply",
1195
+ action: "cowork.item.action.apply",
1196
+ summary: "\u6267\u884C\u534F\u4F5C\u7EA7\u52A8\u4F5C\uFF08end \u7ED3\u675F\u534F\u4F5C\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation",
1197
+ risk: WRITE,
1198
+ requiresConfirmation: true,
1199
+ inputSchema: schemaOf({
1200
+ action: { type: "string", enum: [...ITEM_ACTIONS] },
1201
+ id: { ...SCHEMA_ID },
1202
+ confirm: { type: "boolean" },
1203
+ continuation: { type: "string" }
1204
+ }, { required: ["action", "id", "confirm", "continuation"] }),
1205
+ handler: async (args, env) => {
1206
+ requireConfirm(args, "cowork.item.action.apply");
1207
+ const lease = await verifyLease(args, "cowork.item.action.apply", env);
1208
+ const action = assertEnum(args.action, ITEM_ACTIONS, "action");
1209
+ const id = toId(args.id, "id");
1210
+ if (lease.action !== action || lease.id !== id) {
1211
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1212
+ }
1213
+ let response;
1214
+ try {
1215
+ response = await env.host.request({
1216
+ method: "POST",
1217
+ path: "/api/cowork/view/endCoworkItem",
1218
+ form: { id },
1219
+ operation: "cowork.item.action.apply"
1220
+ });
1221
+ } catch (error) {
1222
+ if (isNetworkError(error)) {
1223
+ throw coworkPartialError("\u7ED3\u675F\u534F\u4F5C\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u5148\u7528 cowork.view \u6838\u5BF9\u72B6\u6001", { id });
1224
+ }
1225
+ throw error;
1226
+ }
1227
+ return coworkSuccess("cowork.item.action.apply", { action, id, result: unwrapData(response) ?? null });
1228
+ }
1229
+ };
1230
+ var ITEM_FLAGS = ["hide", "vote"];
1231
+ var itemFlagPrepare = {
1232
+ name: "cowork.item.flag.prepare",
1233
+ resource: "cowork",
1234
+ method: "item.flag.prepare",
1235
+ action: "cowork.item.flag.prepare",
1236
+ summary: "\u534F\u4F5C\u6807\u8BB0\u52A8\u4F5C\u6458\u8981\uFF1Ahide=\u4ECE\u6211\u7684\u5217\u8868\u9690\u85CF / vote=\u6807\u8BB0\u6295\u7968\uFF1B\u5148\u8BFB\u8BE6\u60C5\u786E\u8BA4\u534F\u4F5C\u5B58\u5728\uFF0C\u4E0D\u5199\u5165",
1237
+ risk: READ_BEFORE_WRITE,
1238
+ inputSchema: schemaOf({
1239
+ action: { type: "string", enum: [...ITEM_FLAGS], description: "hide \u9690\u85CF / vote \u6807\u8BB0\u6295\u7968" },
1240
+ id: { ...SCHEMA_ID, description: "\u534F\u4F5C id" }
1241
+ }, { required: ["action", "id"] }),
1242
+ handler: async (args, env) => {
1243
+ const action = assertEnum(args.action, ITEM_FLAGS, "action");
1244
+ const id = toId(args.id, "id");
1245
+ const detailResponse = await env.host.request({
1246
+ method: "POST",
1247
+ path: "/api/cowork/view/viewCowork",
1248
+ form: { id },
1249
+ operation: "cowork.item.flag.prepare"
1250
+ });
1251
+ const detail = unwrapData(detailResponse) ?? {};
1252
+ if (!detail || Object.keys(detail).length === 0) {
1253
+ throw coworkNotFoundError("item_not_found", `\u534F\u4F5C ${id} \u4E0D\u5B58\u5728\u6216\u65E0\u6743\u67E5\u770B`);
1254
+ }
1255
+ const session = await env.host.getSession();
1256
+ const continuation = await env.continuation.issue({
1257
+ operation: "cowork.item.flag.apply",
1258
+ baseUrl: session.baseUrl,
1259
+ profile: session.profile,
1260
+ userId: session.userId,
1261
+ action,
1262
+ id
1263
+ });
1264
+ return coworkSuccess("cowork.item.flag.prepare", {
1265
+ summary: { action, id, itemName: detail.itemName ?? "" },
1266
+ continuation
1267
+ });
1268
+ }
1269
+ };
1270
+ var itemFlagApply = {
1271
+ name: "cowork.item.flag.apply",
1272
+ resource: "cowork",
1273
+ method: "item.flag.apply",
1274
+ action: "cowork.item.flag.apply",
1275
+ summary: "\u6267\u884C\u534F\u4F5C\u6807\u8BB0\u52A8\u4F5C\uFF08hide / vote\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation",
1276
+ risk: WRITE,
1277
+ requiresConfirmation: true,
1278
+ inputSchema: schemaOf({
1279
+ action: { type: "string", enum: [...ITEM_FLAGS] },
1280
+ id: { ...SCHEMA_ID },
1281
+ confirm: { type: "boolean" },
1282
+ continuation: { type: "string" }
1283
+ }, { required: ["action", "id", "confirm", "continuation"] }),
1284
+ handler: async (args, env) => {
1285
+ requireConfirm(args, "cowork.item.flag.apply");
1286
+ const lease = await verifyLease(args, "cowork.item.flag.apply", env);
1287
+ const action = assertEnum(args.action, ITEM_FLAGS, "action");
1288
+ const id = toId(args.id, "id");
1289
+ if (lease.action !== action || lease.id !== id) {
1290
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1291
+ }
1292
+ const form = action === "hide" ? { hidden: 1, ids: id } : { vote: 1, ids: id };
1293
+ const response = await env.host.request({
1294
+ method: "POST",
1295
+ path: action === "hide" ? "/api/cowork/behavior/markAsHidden" : "/api/cowork/behavior/markAsVote",
1296
+ form,
1297
+ operation: "cowork.item.flag.apply"
1298
+ });
1299
+ return coworkSuccess("cowork.item.flag.apply", { action, id, result: unwrapData(response) ?? null });
1300
+ }
1301
+ };
1302
+ var coworkItemWriteOperations = [
1303
+ itemCreatePrepare,
1304
+ itemCreateApply,
1305
+ itemActionPrepare,
1306
+ itemActionApply,
1307
+ itemFlagPrepare,
1308
+ itemFlagApply
1309
+ ];
1310
+
1311
+ // src/shortcuts/cowork/operations/discuss-write.ts
1312
+ function isNetworkError2(error) {
1313
+ return error instanceof CoworkCliError && error.type === "network";
1314
+ }
1315
+ async function resolveSectionId(host, coworkId) {
1316
+ const response = await host.request({
1317
+ method: "POST",
1318
+ path: "/api/cowork/view/viewCowork",
1319
+ form: { id: coworkId },
1320
+ operation: "cowork.discuss.publish.prepare"
1321
+ });
1322
+ const detail = unwrapData(response) ?? {};
1323
+ if (!detail || Object.keys(detail).length === 0) {
1324
+ throw coworkNotFoundError("item_not_found", `\u534F\u4F5C ${coworkId} \u4E0D\u5B58\u5728\u6216\u65E0\u6743\u67E5\u770B`);
1325
+ }
1326
+ const sectionId = detail.sectionId ? String(detail.sectionId) : "";
1327
+ if (!sectionId) {
1328
+ throw coworkValidationError("section_unresolved", "\u65E0\u6CD5\u4ECE\u534F\u4F5C\u8BE6\u60C5\u89E3\u6790\u7248\u5757 id\uFF0C\u8BF7\u663E\u5F0F\u4F20 sectionId");
1329
+ }
1330
+ return sectionId;
1331
+ }
1332
+ var discussPublishPrepare = {
1333
+ name: "cowork.discuss.publish.prepare",
1334
+ resource: "cowork",
1335
+ method: "discuss.publish.prepare",
1336
+ action: "cowork.discuss.publish.prepare",
1337
+ summary: "\u53D1\u5E03/\u56DE\u590D\u8BA8\u8BBA\u7684\u786E\u8BA4\u6458\u8981\uFF1A\u5148\u8BFB\u534F\u4F5C\u8BE6\u60C5\u786E\u8BA4\u5B58\u5728\u5E76\u89E3\u6790\u7248\u5757 id\uFF0C\u4E0D\u5199\u5165",
1338
+ risk: READ_BEFORE_WRITE,
1339
+ inputSchema: schemaOf({
1340
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
1341
+ content: { type: "string", maxLength: 2e4, description: "\u8BA8\u8BBA\u5185\u5BB9\uFF08\u7EAF\u6587\u672C\uFF09" },
1342
+ sectionId: { ...SCHEMA_ID, description: "\u7248\u5757 id\uFF1B\u4E0D\u4F20\u5219\u4ECE\u534F\u4F5C\u8BE6\u60C5\u81EA\u52A8\u89E3\u6790" }
1343
+ }, { required: ["coworkId", "content"] }),
1344
+ handler: async (args, env) => {
1345
+ const coworkId = toId(args.coworkId, "coworkId");
1346
+ const content = assertString(args.content, "content", 2e4);
1347
+ const sectionId = args.sectionId !== void 0 ? toId(args.sectionId, "sectionId") : await resolveSectionId(env.host, coworkId);
1348
+ const session = await env.host.getSession();
1349
+ const continuation = await env.continuation.issue({
1350
+ operation: "cowork.discuss.publish.apply",
1351
+ baseUrl: session.baseUrl,
1352
+ profile: session.profile,
1353
+ userId: session.userId,
1354
+ coworkId,
1355
+ sectionId,
1356
+ contentLength: content.length,
1357
+ contentHash: hashText(content)
1358
+ });
1359
+ return coworkSuccess("cowork.discuss.publish.prepare", {
1360
+ summary: {
1361
+ coworkId,
1362
+ sectionId,
1363
+ sectionIdSource: args.sectionId !== void 0 ? "explicit" : "resolved-from-view",
1364
+ contentPreview: content.length > 120 ? `${content.slice(0, 120)}\u2026` : content,
1365
+ contentLength: content.length
1366
+ },
1367
+ onApply: "\u5C06\u8C03\u7528 publishCoworkDiscuss \u53D1\u5E03\u4E00\u6761\u8BA8\u8BBA\uFF08replyType=discuss\uFF0Cclient=pc\uFF09",
1368
+ continuation
1369
+ });
1370
+ }
1371
+ };
1372
+ function hashText(text) {
1373
+ let hash = 0;
1374
+ for (let i = 0; i < text.length; i++) hash = hash * 31 + text.charCodeAt(i) | 0;
1375
+ return String(hash >>> 0);
1376
+ }
1377
+ var discussPublishApply = {
1378
+ name: "cowork.discuss.publish.apply",
1379
+ resource: "cowork",
1380
+ method: "discuss.publish.apply",
1381
+ action: "cowork.discuss.publish.apply",
1382
+ summary: "\u6267\u884C\u53D1\u5E03/\u56DE\u590D\u8BA8\u8BBA\uFF08\u9700 confirm=true \u4E0E continuation\uFF09",
1383
+ risk: WRITE,
1384
+ requiresConfirmation: true,
1385
+ inputSchema: schemaOf({
1386
+ coworkId: { ...SCHEMA_ID },
1387
+ content: { type: "string", maxLength: 2e4 },
1388
+ sectionId: { ...SCHEMA_ID },
1389
+ confirm: { type: "boolean" },
1390
+ continuation: { type: "string" }
1391
+ }, { required: ["coworkId", "content", "confirm", "continuation"] }),
1392
+ handler: async (args, env) => {
1393
+ requireConfirm(args, "cowork.discuss.publish.apply");
1394
+ const lease = await verifyLease(args, "cowork.discuss.publish.apply", env);
1395
+ const coworkId = toId(args.coworkId, "coworkId");
1396
+ const content = assertString(args.content, "content", 2e4);
1397
+ if (lease.coworkId !== coworkId || lease.contentHash !== hashText(content)) {
1398
+ throw coworkValidationError("target_changed", "\u534F\u4F5C id \u6216\u8BA8\u8BBA\u5185\u5BB9\u4E0E prepare \u65F6\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1399
+ }
1400
+ const sectionId = args.sectionId !== void 0 ? toId(args.sectionId, "sectionId") : String(lease.sectionId);
1401
+ const body = {
1402
+ attachments: "",
1403
+ relevanceList: [],
1404
+ atLinkList: [],
1405
+ desensitization: 0,
1406
+ secondAuth: 0,
1407
+ clobContent: toBase64Html(content),
1408
+ client: "pc",
1409
+ relatedFile: "",
1410
+ replyType: "discuss",
1411
+ cwItemsId: coworkId,
1412
+ sectionId,
1413
+ anonymous: 0,
1414
+ approvalStatus: 1
1415
+ };
1416
+ let response;
1417
+ try {
1418
+ response = await env.host.request({
1419
+ method: "POST",
1420
+ path: "/api/cowork/main/publishCoworkDiscuss",
1421
+ body,
1422
+ operation: "cowork.discuss.publish.apply"
1423
+ });
1424
+ } catch (error) {
1425
+ if (isNetworkError2(error)) {
1426
+ throw coworkPartialError("\u8BA8\u8BBA\u53D1\u5E03\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u7528 cowork.discuss.list \u6838\u5BF9\u8BE5\u534F\u4F5C\u6700\u65B0\u8BA8\u8BBA", { coworkId });
1427
+ }
1428
+ throw error;
1429
+ }
1430
+ const data = unwrapData(response) ?? {};
1431
+ const root = response;
1432
+ return coworkSuccess("cowork.discuss.publish.apply", {
1433
+ coworkId,
1434
+ sectionId,
1435
+ status: data.status ?? root?.status ?? null
1436
+ });
1437
+ }
1438
+ };
1439
+ var DISCUSS_ACTIONS = ["top", "untop", "delete", "approve"];
1440
+ var DISCUSS_ACTION_PATHS = {
1441
+ top: { path: "/api/cowork/view/topCoworkDiscuss", form: (id) => ({ id }) },
1442
+ untop: { path: "/api/cowork/view/cancelTopCoworkDiscuss", form: (id) => ({ id }) },
1443
+ delete: { path: "/api/cowork/view/deleteCoworkDiscuss", form: (id, all) => ({ id, isDeleteAll: all ? 1 : 0 }) },
1444
+ approve: { path: "/api/cowork/view/approveCoworkDiscuss", form: (id) => ({ id }) }
1445
+ };
1446
+ async function locateDiscuss(env, coworkId, discussId, maxPages = 5, pageSize = 50) {
1447
+ for (let page = 1; page <= maxPages; page++) {
1448
+ const response = await env.host.request({
1449
+ method: "POST",
1450
+ path: "/api/cowork/view/discussRecord",
1451
+ body: { coworkId, current: page, pageSize, orders: [{ column: "lastReply", asc: false }] },
1452
+ operation: "cowork.discuss.action.prepare"
1453
+ });
1454
+ const { data } = normalizeList(response);
1455
+ const rows = data;
1456
+ if (!Array.isArray(rows) || rows.length === 0) return null;
1457
+ const hit = rows.find((row) => String(row.id ?? row.discussId ?? "") === discussId);
1458
+ if (hit) return hit;
1459
+ if (rows.length < pageSize) return null;
1460
+ }
1461
+ return null;
1462
+ }
1463
+ var discussActionPrepare = {
1464
+ name: "cowork.discuss.action.prepare",
1465
+ resource: "cowork",
1466
+ method: "discuss.action.prepare",
1467
+ action: "cowork.discuss.action.prepare",
1468
+ summary: "\u8BA8\u8BBA\u52A8\u4F5C\u6458\u8981\uFF08top \u7F6E\u9876 / untop \u53D6\u6D88\u7F6E\u9876 / delete \u5220\u9664 / approve \u5BA1\u6279\u901A\u8FC7\uFF09\uFF1A\u5728\u534F\u4F5C\u8BA8\u8BBA\u4E2D\u5B9A\u4F4D\u8BE5\u8BA8\u8BBA\u5E76\u56DE\u663E\u5185\u5BB9\uFF0C\u4E0D\u5199\u5165",
1469
+ risk: READ_BEFORE_WRITE,
1470
+ inputSchema: schemaOf({
1471
+ action: { type: "string", enum: [...DISCUSS_ACTIONS], description: "top / untop / delete / approve" },
1472
+ coworkId: { ...SCHEMA_ID, description: "\u6240\u5C5E\u534F\u4F5C id\uFF08\u7528\u4E8E\u5B9A\u4F4D\u8BA8\u8BBA\uFF09" },
1473
+ discussId: { ...SCHEMA_ID, description: "\u8BA8\u8BBA id" },
1474
+ isDeleteAll: { type: "boolean", description: "action=delete \u65F6\u662F\u5426\u5220\u9664\u5168\u90E8\u56DE\u590D\uFF0C\u9ED8\u8BA4 true\uFF08\u4E0E\u9875\u9762\u4E00\u81F4\uFF09" },
1475
+ maxPages: { type: "integer", minimum: 1, maximum: 20, description: "\u5B9A\u4F4D\u8BA8\u8BBA\u7684\u7FFB\u9875\u4E0A\u9650\uFF0C\u9ED8\u8BA4 5" },
1476
+ pageSize: { type: "integer", minimum: 1, maximum: 100, description: "\u6BCF\u9875\u6761\u6570\uFF0C\u9ED8\u8BA4 50" }
1477
+ }, { required: ["action", "coworkId", "discussId"] }),
1478
+ handler: async (args, env) => {
1479
+ const action = assertEnum(args.action, DISCUSS_ACTIONS, "action");
1480
+ const coworkId = toId(args.coworkId, "coworkId");
1481
+ const discussId = toId(args.discussId, "discussId");
1482
+ const hit = await locateDiscuss(
1483
+ env,
1484
+ coworkId,
1485
+ discussId,
1486
+ toPositiveInt(args.maxPages, "maxPages") ?? 5,
1487
+ toPositiveInt(args.pageSize, "pageSize") ?? 50
1488
+ );
1489
+ if (!hit) {
1490
+ throw coworkNotFoundError(
1491
+ "discuss_not_found",
1492
+ `\u5728\u524D ${toPositiveInt(args.maxPages, "maxPages") ?? 5} \u9875\u8BA8\u8BBA\u4E2D\u672A\u627E\u5230\u8BA8\u8BBA ${discussId}\uFF1A\u8BF7\u786E\u8BA4 coworkId \u4E0E\u8BA8\u8BBA id \u662F\u5426\u5339\u914D\uFF08\u7981\u6B62\u5BF9\u672A\u786E\u8BA4\u7684\u8BA8\u8BBA\u6267\u884C\u52A8\u4F5C\uFF09`
1493
+ );
1494
+ }
1495
+ const session = await env.host.getSession();
1496
+ const continuation = await env.continuation.issue({
1497
+ operation: "cowork.discuss.action.apply",
1498
+ baseUrl: session.baseUrl,
1499
+ profile: session.profile,
1500
+ userId: session.userId,
1501
+ action,
1502
+ coworkId,
1503
+ discussId,
1504
+ isDeleteAll: args.isDeleteAll === false ? false : true
1505
+ });
1506
+ return coworkSuccess("cowork.discuss.action.prepare", {
1507
+ summary: {
1508
+ action,
1509
+ coworkId,
1510
+ discussId,
1511
+ contentPreview: previewOf(hit),
1512
+ author: hit.creatorName ?? hit.username ?? hit.creator ?? null,
1513
+ createdTime: hit.createTime ?? hit.createShowTime ?? null,
1514
+ isDeleteAll: action === "delete" ? args.isDeleteAll === false ? false : true : void 0
1515
+ },
1516
+ continuation
1517
+ });
1518
+ }
1519
+ };
1520
+ function previewOf(row) {
1521
+ const raw = row.clobContent ?? row.content ?? row.summary ?? "";
1522
+ const text = String(raw).replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
1523
+ return text.length > 120 ? `${text.slice(0, 120)}\u2026` : text;
1524
+ }
1525
+ var discussActionApply = {
1526
+ name: "cowork.discuss.action.apply",
1527
+ resource: "cowork",
1528
+ method: "discuss.action.apply",
1529
+ action: "cowork.discuss.action.apply",
1530
+ summary: "\u6267\u884C\u8BA8\u8BBA\u52A8\u4F5C\uFF08top / untop / delete / approve\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation",
1531
+ risk: WRITE,
1532
+ requiresConfirmation: true,
1533
+ inputSchema: schemaOf({
1534
+ action: { type: "string", enum: [...DISCUSS_ACTIONS] },
1535
+ coworkId: { ...SCHEMA_ID },
1536
+ discussId: { ...SCHEMA_ID },
1537
+ isDeleteAll: { type: "boolean" },
1538
+ confirm: { type: "boolean" },
1539
+ continuation: { type: "string" }
1540
+ }, { required: ["action", "coworkId", "discussId", "confirm", "continuation"] }),
1541
+ handler: async (args, env) => {
1542
+ requireConfirm(args, "cowork.discuss.action.apply");
1543
+ const lease = await verifyLease(args, "cowork.discuss.action.apply", env);
1544
+ const action = assertEnum(args.action, DISCUSS_ACTIONS, "action");
1545
+ const coworkId = toId(args.coworkId, "coworkId");
1546
+ const discussId = toId(args.discussId, "discussId");
1547
+ if (lease.action !== action || lease.discussId !== discussId) {
1548
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1549
+ }
1550
+ const isDeleteAll = lease.isDeleteAll !== false;
1551
+ const spec = DISCUSS_ACTION_PATHS[action];
1552
+ let response;
1553
+ try {
1554
+ response = await env.host.request({
1555
+ method: "POST",
1556
+ path: spec.path,
1557
+ form: compact(spec.form(discussId, isDeleteAll)),
1558
+ operation: "cowork.discuss.action.apply"
1559
+ });
1560
+ } catch (error) {
1561
+ if (isNetworkError2(error)) {
1562
+ throw coworkPartialError("\u8BA8\u8BBA\u52A8\u4F5C\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u91CD\u65B0\u62C9\u53D6\u8BA8\u8BBA\u5217\u8868\u6838\u5BF9", { action, discussId });
1563
+ }
1564
+ throw error;
1565
+ }
1566
+ return coworkSuccess("cowork.discuss.action.apply", {
1567
+ action,
1568
+ coworkId,
1569
+ discussId,
1570
+ result: unwrapData(response) ?? null
1571
+ });
1572
+ }
1573
+ };
1574
+ var coworkDiscussWriteOperations = [
1575
+ discussPublishPrepare,
1576
+ discussPublishApply,
1577
+ discussActionPrepare,
1578
+ discussActionApply
1579
+ ];
1580
+
1581
+ // src/shortcuts/cowork/operations/member-write.ts
1582
+ function isNetworkError3(error) {
1583
+ return error instanceof CoworkCliError && error.type === "network";
1584
+ }
1585
+ var MEMBER_ACTIONS = ["invite", "rejoin", "join"];
1586
+ var MEMBER_SPECS = {
1587
+ invite: { path: "/api/cowork/behavior/inviteJoin" },
1588
+ rejoin: { path: "/api/cowork/behavior/reJoin" },
1589
+ join: { path: "/api/cowork/apply/applyCwItem" }
1590
+ };
1591
+ async function currentParticipantIds(env, coworkId) {
1592
+ try {
1593
+ const response = await env.host.request({
1594
+ method: "POST",
1595
+ path: "/api/cowork/view/participationAllList",
1596
+ body: { id: coworkId, participationFrom: "participant", current: 1, pageSize: 100 },
1597
+ operation: "cowork.member.action.prepare"
1598
+ });
1599
+ const { data } = normalizeList(response);
1600
+ const rows = Array.isArray(data) ? data : [];
1601
+ return new Set(rows.map((row) => String(row.id ?? row.userId ?? "")).filter(Boolean));
1602
+ } catch {
1603
+ return /* @__PURE__ */ new Set();
1604
+ }
1605
+ }
1606
+ var memberActionPrepare = {
1607
+ name: "cowork.member.action.prepare",
1608
+ resource: "cowork",
1609
+ method: "member.action.prepare",
1610
+ action: "cowork.member.action.prepare",
1611
+ summary: "\u6210\u5458\u52A8\u4F5C\u6458\u8981\uFF1Ainvite \u9080\u8BF7 / rejoin \u91CD\u65B0\u52A0\u5165 / join \u7533\u8BF7\u52A0\u5165\uFF1B\u5148\u8BFB\u534F\u4F5C\u8BE6\u60C5\u786E\u8BA4\u5B58\u5728\uFF0C\u5E76\u63D0\u793A\u5DF2\u5728\u534F\u4F5C\u5185\u7684\u4EBA\u5458\uFF0C\u4E0D\u5199\u5165",
1612
+ risk: READ_BEFORE_WRITE,
1613
+ inputSchema: schemaOf({
1614
+ action: { type: "string", enum: [...MEMBER_ACTIONS], description: "invite \u9080\u8BF7\u4ED6\u4EBA / rejoin \u91CD\u65B0\u52A0\u5165 / join \u7533\u8BF7\u52A0\u5165\uFF08\u6211\uFF09" },
1615
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
1616
+ userIds: {
1617
+ type: "array",
1618
+ items: SCHEMA_ID,
1619
+ maxItems: 50,
1620
+ description: "invite / rejoin \u5FC5\u586B\uFF1A\u4EBA\u5458 id \u6570\u7EC4\uFF08join \u4E0D\u9700\u8981\uFF09"
1621
+ }
1622
+ }, { required: ["action", "coworkId"] }),
1623
+ handler: async (args, env) => {
1624
+ const action = assertEnum(args.action, MEMBER_ACTIONS, "action");
1625
+ const coworkId = toId(args.coworkId, "coworkId");
1626
+ const detailResponse = await env.host.request({
1627
+ method: "POST",
1628
+ path: "/api/cowork/view/viewCowork",
1629
+ form: { id: coworkId },
1630
+ operation: "cowork.member.action.prepare"
1631
+ });
1632
+ const detail = unwrapData(detailResponse) ?? {};
1633
+ if (!detail || Object.keys(detail).length === 0) {
1634
+ throw coworkNotFoundError("item_not_found", `\u534F\u4F5C ${coworkId} \u4E0D\u5B58\u5728\u6216\u65E0\u6743\u67E5\u770B`);
1635
+ }
1636
+ let userIds;
1637
+ let alreadyIn = [];
1638
+ if (action !== "join") {
1639
+ userIds = toIdList(args.userIds, "userIds");
1640
+ if (!userIds || userIds.length === 0) {
1641
+ throw coworkValidationError("user_ids_required", `${action} \u5FC5\u987B\u63D0\u4F9B userIds\uFF08\u4EBA\u5458 id \u6570\u7EC4\uFF09`);
1642
+ }
1643
+ const current = await currentParticipantIds(env, coworkId);
1644
+ alreadyIn = userIds.filter((id) => current.has(id));
1645
+ }
1646
+ const session = await env.host.getSession();
1647
+ const continuation = await env.continuation.issue({
1648
+ operation: "cowork.member.action.apply",
1649
+ baseUrl: session.baseUrl,
1650
+ profile: session.profile,
1651
+ userId: session.userId,
1652
+ action,
1653
+ coworkId,
1654
+ userIds: userIds ?? []
1655
+ });
1656
+ return coworkSuccess("cowork.member.action.prepare", {
1657
+ summary: {
1658
+ action,
1659
+ coworkId,
1660
+ itemName: detail.itemName ?? "",
1661
+ userIds: userIds ?? void 0,
1662
+ userCount: userIds?.length,
1663
+ alreadyParticipant: alreadyIn.length > 0 ? alreadyIn : void 0,
1664
+ note: alreadyIn.length > 0 ? "\u4E0A\u8FF0\u4EBA\u5458\u5DF2\u5728\u534F\u4F5C\u53C2\u4E0E\u4EBA\u5217\u8868\u4E2D\uFF0C\u91CD\u590D\u9080\u8BF7\u53EF\u80FD\u88AB\u670D\u52A1\u7AEF\u5224\u4E3A\u65E0\u53D8\u5316\uFF1B\u8BF7\u4E0E\u7528\u6237\u786E\u8BA4\u540E\u51B3\u5B9A" : void 0
1665
+ },
1666
+ continuation
1667
+ });
1668
+ }
1669
+ };
1670
+ var memberActionApply = {
1671
+ name: "cowork.member.action.apply",
1672
+ resource: "cowork",
1673
+ method: "member.action.apply",
1674
+ action: "cowork.member.action.apply",
1675
+ summary: "\u6267\u884C\u6210\u5458\u52A8\u4F5C\uFF08invite / rejoin / join\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation",
1676
+ risk: WRITE,
1677
+ requiresConfirmation: true,
1678
+ inputSchema: schemaOf({
1679
+ action: { type: "string", enum: [...MEMBER_ACTIONS] },
1680
+ coworkId: { ...SCHEMA_ID },
1681
+ userIds: { type: "array", items: SCHEMA_ID, maxItems: 50 },
1682
+ confirm: { type: "boolean" },
1683
+ continuation: { type: "string" }
1684
+ }, { required: ["action", "coworkId", "confirm", "continuation"] }),
1685
+ handler: async (args, env) => {
1686
+ requireConfirm(args, "cowork.member.action.apply");
1687
+ const lease = await verifyLease(args, "cowork.member.action.apply", env);
1688
+ const action = assertEnum(args.action, MEMBER_ACTIONS, "action");
1689
+ const coworkId = toId(args.coworkId, "coworkId");
1690
+ if (lease.action !== action || lease.coworkId !== coworkId) {
1691
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1692
+ }
1693
+ let form;
1694
+ if (action === "join") {
1695
+ form = { ids: coworkId };
1696
+ } else {
1697
+ const userIds = toIdList(args.userIds, "userIds") ?? lease.userIds ?? [];
1698
+ const leaseIds = lease.userIds ?? [];
1699
+ if (userIds.join(",") !== leaseIds.join(",")) {
1700
+ throw coworkValidationError("target_changed", "\u4EBA\u5458\u540D\u5355\u4E0E prepare \u65F6\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1701
+ }
1702
+ if (userIds.length === 0) {
1703
+ throw coworkValidationError("user_ids_required", `${action} \u5FC5\u987B\u63D0\u4F9B userIds`);
1704
+ }
1705
+ form = { ids: userIds.join(","), coworkId };
1706
+ }
1707
+ let response;
1708
+ try {
1709
+ response = await env.host.request({
1710
+ method: "POST",
1711
+ path: MEMBER_SPECS[action].path,
1712
+ form,
1713
+ operation: "cowork.member.action.apply"
1714
+ });
1715
+ } catch (error) {
1716
+ if (isNetworkError3(error)) {
1717
+ throw coworkPartialError("\u6210\u5458\u52A8\u4F5C\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u7528 cowork.participant.list \u6838\u5BF9\u53C2\u4E0E\u4EBA", { action, coworkId });
1718
+ }
1719
+ throw error;
1720
+ }
1721
+ return coworkSuccess("cowork.member.action.apply", {
1722
+ action,
1723
+ coworkId,
1724
+ userIds: action === "join" ? void 0 : String(form.ids).split(","),
1725
+ result: unwrapData(response) ?? null
1726
+ });
1727
+ }
1728
+ };
1729
+ var DECISIONS = ["approve", "refuse"];
1730
+ var DECISION_PATHS = {
1731
+ approve: "/api/cowork/apply/approveCwItem",
1732
+ refuse: "/api/cowork/apply/refuseCwItem"
1733
+ };
1734
+ async function locateApplyRecord(env, applyId, maxPages = 5, pageSize = 50) {
1735
+ for (let page = 1; page <= maxPages; page++) {
1736
+ const response = await env.host.request({
1737
+ method: "POST",
1738
+ path: "/api/cowork/apply/getCoworkApplyApproveList",
1739
+ body: {
1740
+ current: page,
1741
+ applyerCondition: "bl",
1742
+ applyer: "",
1743
+ applyerDeptCondition: "bl",
1744
+ applyerDept: "",
1745
+ itemNameCondition: "in",
1746
+ type: "and"
1747
+ },
1748
+ operation: "cowork.apply.decide.prepare"
1749
+ });
1750
+ const { data } = normalizeList(response);
1751
+ const rows = Array.isArray(data) ? data : [];
1752
+ if (rows.length === 0) return null;
1753
+ const hit = rows.find((row) => String(row.id ?? "") === applyId);
1754
+ if (hit) return hit;
1755
+ if (rows.length < pageSize) return null;
1756
+ }
1757
+ return null;
1758
+ }
1759
+ var applyDecidePrepare = {
1760
+ name: "cowork.apply.decide.prepare",
1761
+ resource: "cowork",
1762
+ method: "apply.decide.prepare",
1763
+ action: "cowork.apply.decide.prepare",
1764
+ summary: "\u52A0\u5165\u7533\u8BF7\u5BA1\u6279\u6458\u8981\uFF08approve \u901A\u8FC7 / refuse \u62D2\u7EDD\uFF09\uFF1A\u5728\u5F85\u5BA1\u6279\u5217\u8868\u4E2D\u5B9A\u4F4D\u7533\u8BF7\u8BB0\u5F55\u5E76\u56DE\u663E\u7533\u8BF7\u4EBA\u4E0E\u534F\u4F5C\u4E3B\u9898\uFF0C\u4E0D\u5199\u5165",
1765
+ risk: READ_BEFORE_WRITE,
1766
+ inputSchema: schemaOf({
1767
+ decision: { type: "string", enum: [...DECISIONS], description: "approve \u901A\u8FC7 / refuse \u62D2\u7EDD" },
1768
+ applyId: { ...SCHEMA_ID, description: "\u7533\u8BF7\u8BB0\u5F55 id\uFF08\u6765\u81EA cowork.list scope=approve\uFF09" },
1769
+ maxPages: { type: "integer", minimum: 1, maximum: 20, description: "\u5B9A\u4F4D\u8BB0\u5F55\u7684\u7FFB\u9875\u4E0A\u9650\uFF0C\u9ED8\u8BA4 5" }
1770
+ }, { required: ["decision", "applyId"] }),
1771
+ handler: async (args, env) => {
1772
+ const decision = assertEnum(args.decision, DECISIONS, "decision");
1773
+ const applyId = toId(args.applyId, "applyId");
1774
+ const maxPages = toPositiveInt(args.maxPages, "maxPages") ?? 5;
1775
+ const hit = await locateApplyRecord(env, applyId, maxPages);
1776
+ if (!hit) {
1777
+ throw coworkNotFoundError(
1778
+ "apply_not_found",
1779
+ `\u5728\u524D ${maxPages} \u9875\u5F85\u5BA1\u6279\u5217\u8868\u4E2D\u672A\u627E\u5230\u7533\u8BF7\u8BB0\u5F55 ${applyId}\uFF1A\u8BF7\u5148\u7528 cowork.list\uFF08scope=approve\uFF09\u786E\u8BA4\uFF0C\u7981\u6B62\u5BF9\u672A\u786E\u8BA4\u7684\u8BB0\u5F55\u5BA1\u6279`
1780
+ );
1781
+ }
1782
+ const session = await env.host.getSession();
1783
+ const continuation = await env.continuation.issue({
1784
+ operation: "cowork.apply.decide.apply",
1785
+ baseUrl: session.baseUrl,
1786
+ profile: session.profile,
1787
+ userId: session.userId,
1788
+ decision,
1789
+ applyId
1790
+ });
1791
+ return coworkSuccess("cowork.apply.decide.prepare", {
1792
+ summary: {
1793
+ decision,
1794
+ applyId,
1795
+ itemName: hit.itemName ?? null,
1796
+ applyer: hit.applyerName ?? hit.applyer ?? null,
1797
+ applyTime: hit.applyTime ?? hit.createTime ?? null
1798
+ },
1799
+ continuation
1800
+ });
1801
+ }
1802
+ };
1803
+ var applyDecideApply = {
1804
+ name: "cowork.apply.decide.apply",
1805
+ resource: "cowork",
1806
+ method: "apply.decide.apply",
1807
+ action: "cowork.apply.decide.apply",
1808
+ summary: "\u6267\u884C\u52A0\u5165\u7533\u8BF7\u5BA1\u6279\uFF08approve / refuse\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation",
1809
+ risk: WRITE,
1810
+ requiresConfirmation: true,
1811
+ inputSchema: schemaOf({
1812
+ decision: { type: "string", enum: [...DECISIONS] },
1813
+ applyId: { ...SCHEMA_ID },
1814
+ confirm: { type: "boolean" },
1815
+ continuation: { type: "string" }
1816
+ }, { required: ["decision", "applyId", "confirm", "continuation"] }),
1817
+ handler: async (args, env) => {
1818
+ requireConfirm(args, "cowork.apply.decide.apply");
1819
+ const lease = await verifyLease(args, "cowork.apply.decide.apply", env);
1820
+ const decision = assertEnum(args.decision, DECISIONS, "decision");
1821
+ const applyId = toId(args.applyId, "applyId");
1822
+ if (lease.decision !== decision || lease.applyId !== applyId) {
1823
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1824
+ }
1825
+ let response;
1826
+ try {
1827
+ response = await env.host.request({
1828
+ method: "POST",
1829
+ path: DECISION_PATHS[decision],
1830
+ form: compact({ ids: applyId }),
1831
+ operation: "cowork.apply.decide.apply"
1832
+ });
1833
+ } catch (error) {
1834
+ if (isNetworkError3(error)) {
1835
+ throw coworkPartialError("\u5BA1\u6279\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u7528 cowork.list\uFF08scope=approve\uFF09\u6838\u5BF9\u662F\u5426\u5DF2\u6D88\u5931", { decision, applyId });
1836
+ }
1837
+ throw error;
1838
+ }
1839
+ return coworkSuccess("cowork.apply.decide.apply", {
1840
+ decision,
1841
+ applyId,
1842
+ result: unwrapData(response) ?? null
1843
+ });
1844
+ }
1845
+ };
1846
+ var coworkMemberWriteOperations = [
1847
+ memberActionPrepare,
1848
+ memberActionApply,
1849
+ applyDecidePrepare,
1850
+ applyDecideApply
1851
+ ];
1852
+
1853
+ // src/shortcuts/cowork/operations/review-write.ts
1854
+ function isNetworkError4(error) {
1855
+ return error instanceof CoworkCliError && error.type === "network";
1856
+ }
1857
+ var REVIEW_ACTIONS = ["approve", "delete"];
1858
+ var REVIEW_SPECS = {
1859
+ item: {
1860
+ label: "\u4E8B\u9879\u5BA1\u6279",
1861
+ listPath: "/api/cowork/itemApprove/getCoworkItemApproveList",
1862
+ listBody: (page) => ({
1863
+ current: page,
1864
+ itemNameCondition: "in",
1865
+ sectionCondition: "bl",
1866
+ itemStatus: "1",
1867
+ principalCondition: "bl",
1868
+ principal: "",
1869
+ creatorCondition: "bl",
1870
+ creator: "",
1871
+ type: "and"
1872
+ }),
1873
+ actionPath: {
1874
+ approve: "/api/cowork/itemApprove/approveCoworkItem",
1875
+ delete: "/api/cowork/itemApprove/deleteCoworkItem"
1876
+ },
1877
+ actionForm: (_action, id) => ({ ids: id })
1878
+ },
1879
+ discuss: {
1880
+ label: "\u4EA4\u6D41\u5BA1\u6279",
1881
+ listPath: "/api/cowork/discussApprove/getCoworkDiscussApproveList",
1882
+ listBody: (page) => ({ current: page, type: "and", dateType: "" }),
1883
+ actionPath: {
1884
+ approve: "/api/cowork/discussApprove/approveCoworkDiscuss",
1885
+ delete: "/api/cowork/discussApprove/deleteCoworkDiscuss"
1886
+ },
1887
+ actionForm: (action, id) => action === "delete" ? { id, isDeleteAll: 1 } : { id }
1888
+ }
1889
+ };
1890
+ async function locateReviewRecord(env, domain, recordId, maxPages, pageSize) {
1891
+ const spec = REVIEW_SPECS[domain];
1892
+ for (let page = 1; page <= maxPages; page++) {
1893
+ const response = await env.host.request({
1894
+ method: "POST",
1895
+ path: spec.listPath,
1896
+ body: spec.listBody(page),
1897
+ operation: `cowork.review.${domain}.prepare`
1898
+ });
1899
+ const { data } = normalizeList(response);
1900
+ const rows = Array.isArray(data) ? data : [];
1901
+ if (rows.length === 0) return null;
1902
+ const hit = rows.find((row) => String(row.id ?? "") === recordId);
1903
+ if (hit) return hit;
1904
+ if (rows.length < pageSize) return null;
1905
+ }
1906
+ return null;
1907
+ }
1908
+ function buildReviewOperations(domain) {
1909
+ const spec = REVIEW_SPECS[domain];
1910
+ const prepareName = `cowork.review.${domain}.prepare`;
1911
+ const applyName = `cowork.review.${domain}.apply`;
1912
+ const prepare = {
1913
+ name: prepareName,
1914
+ resource: "cowork",
1915
+ method: `review.${domain}.prepare`,
1916
+ action: prepareName,
1917
+ summary: `${spec.label}\u53F0\u7684\u52A8\u4F5C\u6458\u8981\uFF08approve \u901A\u8FC7 / delete \u5220\u9664\uFF09\uFF1A\u5148\u5728\u5F85\u5BA1\u5217\u8868\u4E2D\u5B9A\u4F4D\u8BB0\u5F55\u5E76\u56DE\u663E\u4E3B\u9898\uFF0C\u4E0D\u5199\u5165`,
1918
+ risk: READ_BEFORE_WRITE,
1919
+ inputSchema: schemaOf({
1920
+ action: { type: "string", enum: [...REVIEW_ACTIONS], description: "approve \u901A\u8FC7 / delete \u5220\u9664" },
1921
+ id: { ...SCHEMA_ID, description: `\u8BB0\u5F55 id\uFF08\u6765\u81EA cowork.list \u7684 ${domain === "item" ? "itemApprove" : "discussApprove"} \u5217\u8868\uFF09` },
1922
+ maxPages: { type: "integer", minimum: 1, maximum: 20, description: "\u5B9A\u4F4D\u8BB0\u5F55\u7684\u7FFB\u9875\u4E0A\u9650\uFF0C\u9ED8\u8BA4 5" }
1923
+ }, { required: ["action", "id"] }),
1924
+ handler: async (args, env) => {
1925
+ const action = assertEnum(args.action, REVIEW_ACTIONS, "action");
1926
+ const id = toId(args.id, "id");
1927
+ const maxPages = toPositiveInt(args.maxPages, "maxPages") ?? 5;
1928
+ const hit = await locateReviewRecord(env, domain, id, maxPages, 50);
1929
+ if (!hit) {
1930
+ throw coworkNotFoundError(
1931
+ "record_not_found",
1932
+ `\u5728\u524D ${maxPages} \u9875${spec.label}\u5217\u8868\u4E2D\u672A\u627E\u5230\u8BB0\u5F55 ${id}\uFF1A\u8BF7\u5148\u7528 cowork.list \u62C9\u53D6\u5BF9\u5E94\u5F85\u5BA1\u5217\u8868\u786E\u8BA4\uFF0C\u7981\u6B62\u5BF9\u672A\u786E\u8BA4\u7684\u8BB0\u5F55\u6267\u884C\u52A8\u4F5C`
1933
+ );
1934
+ }
1935
+ const session = await env.host.getSession();
1936
+ const continuation = await env.continuation.issue({
1937
+ operation: applyName,
1938
+ baseUrl: session.baseUrl,
1939
+ profile: session.profile,
1940
+ userId: session.userId,
1941
+ action,
1942
+ id
1943
+ });
1944
+ return coworkSuccess(prepareName, {
1945
+ summary: {
1946
+ domain,
1947
+ action,
1948
+ id,
1949
+ itemName: hit.itemName ?? null,
1950
+ applyer: hit.applyerName ?? hit.creatorName ?? hit.username ?? null,
1951
+ status: hit.applyStatus ?? hit.approvalStatus ?? null
1952
+ },
1953
+ continuation
1954
+ });
1955
+ }
1956
+ };
1957
+ const apply = {
1958
+ name: applyName,
1959
+ resource: "cowork",
1960
+ method: `review.${domain}.apply`,
1961
+ action: applyName,
1962
+ summary: `\u6267\u884C${spec.label}\u52A8\u4F5C\uFF08approve / delete\uFF09\uFF0C\u9700 confirm=true \u4E0E continuation`,
1963
+ risk: WRITE,
1964
+ requiresConfirmation: true,
1965
+ inputSchema: schemaOf({
1966
+ action: { type: "string", enum: [...REVIEW_ACTIONS] },
1967
+ id: { ...SCHEMA_ID },
1968
+ confirm: { type: "boolean" },
1969
+ continuation: { type: "string" }
1970
+ }, { required: ["action", "id", "confirm", "continuation"] }),
1971
+ handler: async (args, env) => {
1972
+ requireConfirm(args, applyName);
1973
+ const lease = await verifyLease(args, applyName, env);
1974
+ const action = assertEnum(args.action, REVIEW_ACTIONS, "action");
1975
+ const id = toId(args.id, "id");
1976
+ if (lease.action !== action || lease.id !== id) {
1977
+ throw coworkValidationError("target_changed", "\u4E0E prepare \u65F6\u7684\u76EE\u6807\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
1978
+ }
1979
+ let response;
1980
+ try {
1981
+ response = await env.host.request({
1982
+ method: "POST",
1983
+ path: spec.actionPath[action],
1984
+ form: compact(spec.actionForm(action, id)),
1985
+ operation: applyName
1986
+ });
1987
+ } catch (error) {
1988
+ if (isNetworkError4(error)) {
1989
+ throw coworkPartialError(`${spec.label}\u52A8\u4F5C\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u91CD\u65B0\u62C9\u53D6\u5F85\u5BA1\u5217\u8868\u6838\u5BF9`, { domain, action, id });
1990
+ }
1991
+ throw error;
1992
+ }
1993
+ return coworkSuccess(applyName, {
1994
+ domain,
1995
+ action,
1996
+ id,
1997
+ result: unwrapData(response) ?? null
1998
+ });
1999
+ }
2000
+ };
2001
+ return [prepare, apply];
2002
+ }
2003
+ var coworkReviewOperations = [
2004
+ ...buildReviewOperations("item"),
2005
+ ...buildReviewOperations("discuss")
2006
+ ];
2007
+
2008
+ // src/shortcuts/cowork/operations/permission-write.ts
2009
+ function isNetworkError5(error) {
2010
+ return error instanceof CoworkCliError && error.type === "network";
2011
+ }
2012
+ var DEFAULT_PERMISSION_ID = "5";
2013
+ async function listSharePermissions(env, coworkId, permissionId, pageSize = 50) {
2014
+ const response = await env.host.request({
2015
+ method: "POST",
2016
+ path: "/api/cowork/permission/getCoworkSharePermissionList",
2017
+ body: {
2018
+ sourceId: coworkId,
2019
+ permissionId,
2020
+ sourceType: 1,
2021
+ current: 1,
2022
+ pageSize,
2023
+ id: coworkId,
2024
+ permissionFrom: permissionId
2025
+ },
2026
+ operation: "cowork.permission.list"
2027
+ });
2028
+ const { data } = normalizeList(response);
2029
+ return Array.isArray(data) ? data : [];
2030
+ }
2031
+ var permAddPrepare = {
2032
+ name: "cowork.permission.add.prepare",
2033
+ resource: "cowork",
2034
+ method: "permission.add.prepare",
2035
+ action: "cowork.permission.add.prepare",
2036
+ summary: "\u65B0\u589E\u5171\u4EAB\u5BF9\u8C61\u7684\u6458\u8981\uFF1A\u5148\u8BFB\u534F\u4F5C\u8BE6\u60C5\u4E0E\u73B0\u6709\u5171\u4EAB\u6743\u9650\u5217\u8868\uFF0C\u63D0\u793A\u8BE5\u4EBA\u5458\u662F\u5426\u5DF2\u5728\uFF0C\u4E0D\u5199\u5165",
2037
+ risk: READ_BEFORE_WRITE,
2038
+ inputSchema: schemaOf({
2039
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
2040
+ userId: { ...SCHEMA_ID, description: "\u88AB\u6388\u6743\u4EBA\u5458 id" },
2041
+ userName: { type: "string", maxLength: 100, description: "\u4EBA\u5458\u59D3\u540D\uFF08\u63A5\u53E3\u5FC5\u586B\uFF0C\u7528\u4E8E\u5C55\u793A\uFF09" },
2042
+ userDept: { type: "string", maxLength: 200, description: "\u90E8\u95E8\u540D\uFF08\u53EF\u9009\uFF0C\u7F3A\u5931\u53EF\u80FD\u5BFC\u81F4\u670D\u52A1\u7AEF\u62D2\u7EDD\uFF09" },
2043
+ userTitle: { type: "string", maxLength: 200, description: "\u5C97\u4F4D\u540D\uFF08\u53EF\u9009\uFF09" },
2044
+ userCid: { type: "string", maxLength: 100, description: "\u4EBA\u5458 cid\uFF08\u90E8\u5206\u73AF\u5883\u5FC5\u586B\uFF0C\u7F3A\u5931\u4F1A\u88AB\u62D2\uFF09" },
2045
+ permissionId: { ...SCHEMA_ID, description: `\u6743\u9650\u7C7B\u578B id\uFF0C\u9ED8\u8BA4 ${DEFAULT_PERMISSION_ID}` }
2046
+ }, { required: ["coworkId", "userId", "userName"] }),
2047
+ handler: async (args, env) => {
2048
+ const coworkId = toId(args.coworkId, "coworkId");
2049
+ const userId = toId(args.userId, "userId");
2050
+ const userName = String(args.userName ?? "").trim();
2051
+ if (!userName) throw coworkValidationError("user_name_required", "userName \u5FC5\u586B\uFF08\u63A5\u53E3\u8981\u6C42\u5C55\u793A\u540D\uFF09");
2052
+ const permissionId = toId(args.permissionId, "permissionId") ?? DEFAULT_PERMISSION_ID;
2053
+ const detailResponse = await env.host.request({
2054
+ method: "POST",
2055
+ path: "/api/cowork/view/viewCowork",
2056
+ form: { id: coworkId },
2057
+ operation: "cowork.permission.add.prepare"
2058
+ });
2059
+ const detail = unwrapData(detailResponse) ?? {};
2060
+ if (!detail || Object.keys(detail).length === 0) {
2061
+ throw coworkNotFoundError("item_not_found", `\u534F\u4F5C ${coworkId} \u4E0D\u5B58\u5728\u6216\u65E0\u6743\u67E5\u770B`);
2062
+ }
2063
+ const existing = await listSharePermissions(env, coworkId, permissionId);
2064
+ const already = existing.some((row) => {
2065
+ const rowUserId = String(row.userid ?? row.userId ?? row.id ?? "");
2066
+ return rowUserId === userId;
2067
+ });
2068
+ const session = await env.host.getSession();
2069
+ const continuation = await env.continuation.issue({
2070
+ operation: "cowork.permission.add.apply",
2071
+ baseUrl: session.baseUrl,
2072
+ profile: session.profile,
2073
+ userId: session.userId,
2074
+ coworkId,
2075
+ targetUserId: userId,
2076
+ userName,
2077
+ permissionId
2078
+ });
2079
+ return coworkSuccess("cowork.permission.add.prepare", {
2080
+ summary: {
2081
+ coworkId,
2082
+ itemName: detail.itemName ?? "",
2083
+ permissionId,
2084
+ targetUser: { id: userId, name: userName, dept: args.userDept ?? null, title: args.userTitle ?? null },
2085
+ alreadyShared: already,
2086
+ note: already ? "\u8BE5\u4EBA\u5458\u5DF2\u5728\u5171\u4EAB\u6743\u9650\u5217\u8868\u4E2D\uFF0C\u91CD\u590D\u65B0\u589E\u53EF\u80FD\u88AB\u670D\u52A1\u7AEF\u5224\u4E3A\u65E0\u53D8\u5316" : args.userCid ? void 0 : "\u672A\u63D0\u4F9B userCid\uFF1A\u90E8\u5206\u73AF\u5883\u8981\u6C42 cid/\u90E8\u95E8/\u5C97\u4F4D\u9F50\u5168\u624D\u63A5\u53D7\u65B0\u589E\uFF0C\u5931\u8D25\u65F6\u53EF\u8865\u9F50\u540E\u91CD\u8BD5"
2087
+ },
2088
+ continuation
2089
+ });
2090
+ }
2091
+ };
2092
+ var permAddApply = {
2093
+ name: "cowork.permission.add.apply",
2094
+ resource: "cowork",
2095
+ method: "permission.add.apply",
2096
+ action: "cowork.permission.add.apply",
2097
+ summary: "\u65B0\u589E\u5171\u4EAB\u5BF9\u8C61\uFF08\u9700 confirm=true \u4E0E continuation\uFF09",
2098
+ risk: WRITE,
2099
+ requiresConfirmation: true,
2100
+ inputSchema: schemaOf({
2101
+ coworkId: { ...SCHEMA_ID },
2102
+ userId: { ...SCHEMA_ID },
2103
+ userName: { type: "string", maxLength: 100 },
2104
+ userDept: { type: "string", maxLength: 200 },
2105
+ userTitle: { type: "string", maxLength: 200 },
2106
+ userCid: { type: "string", maxLength: 100 },
2107
+ permissionId: { ...SCHEMA_ID },
2108
+ confirm: { type: "boolean" },
2109
+ continuation: { type: "string" }
2110
+ }, { required: ["coworkId", "userId", "userName", "confirm", "continuation"] }),
2111
+ handler: async (args, env) => {
2112
+ requireConfirm(args, "cowork.permission.add.apply");
2113
+ const lease = await verifyLease(args, "cowork.permission.add.apply", env);
2114
+ const coworkId = toId(args.coworkId, "coworkId");
2115
+ const userId = toId(args.userId, "userId");
2116
+ if (lease.coworkId !== coworkId || lease.targetUserId !== userId) {
2117
+ throw coworkValidationError("target_changed", "\u534F\u4F5C\u6216\u4EBA\u5458\u4E0E prepare \u65F6\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
2118
+ }
2119
+ const userName = String(args.userName ?? "").trim();
2120
+ if (!userName) throw coworkValidationError("user_name_required", "userName \u5FC5\u586B");
2121
+ const permissionId = toId(args.permissionId, "permissionId") ?? String(lease.permissionId ?? DEFAULT_PERMISSION_ID);
2122
+ const dept = typeof args.userDept === "string" ? args.userDept : "";
2123
+ const position = typeof args.userTitle === "string" ? args.userTitle : "";
2124
+ const obj = {
2125
+ id: userId,
2126
+ userid: userId,
2127
+ name: userName,
2128
+ content: userName,
2129
+ title: [userName, dept, position].filter(Boolean).join("|"),
2130
+ contentDesc: [userName, dept].filter(Boolean).join("|"),
2131
+ statusCode: "normal",
2132
+ department: dept,
2133
+ position,
2134
+ cid: typeof args.userCid === "string" ? args.userCid : ""
2135
+ };
2136
+ const body = {
2137
+ sourceId: coworkId,
2138
+ permissionId,
2139
+ sourceType: 1,
2140
+ refId: coworkId,
2141
+ permissionFrom: permissionId,
2142
+ objType: "resource",
2143
+ obj_id: [obj]
2144
+ };
2145
+ let response;
2146
+ try {
2147
+ response = await env.host.request({
2148
+ method: "POST",
2149
+ path: "/api/cowork/permission/addSharePermission",
2150
+ body,
2151
+ operation: "cowork.permission.add.apply"
2152
+ });
2153
+ } catch (error) {
2154
+ if (isNetworkError5(error)) {
2155
+ throw coworkPartialError("\u65B0\u589E\u5171\u4EAB\u5BF9\u8C61\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u7528 cowork.permission.list \u6838\u5BF9", { coworkId, userId });
2156
+ }
2157
+ throw error;
2158
+ }
2159
+ return coworkSuccess("cowork.permission.add.apply", {
2160
+ coworkId,
2161
+ permissionId,
2162
+ userId,
2163
+ userName,
2164
+ result: unwrapData(response) ?? null
2165
+ });
2166
+ }
2167
+ };
2168
+ var permRemovePrepare = {
2169
+ name: "cowork.permission.remove.prepare",
2170
+ resource: "cowork",
2171
+ method: "permission.remove.prepare",
2172
+ action: "cowork.permission.remove.prepare",
2173
+ summary: "\u5220\u9664\u5171\u4EAB\u5BF9\u8C61\u7684\u6458\u8981\uFF1A\u5148\u6309 pkId \u5728\u5171\u4EAB\u6743\u9650\u5217\u8868\u4E2D\u5B9A\u4F4D\u771F\u5B9E\u8BB0\u5F55\u5E76\u56DE\u663E\uFF0C\u4E0D\u5199\u5165",
2174
+ risk: READ_BEFORE_WRITE,
2175
+ inputSchema: schemaOf({
2176
+ coworkId: { ...SCHEMA_ID, description: "\u534F\u4F5C id" },
2177
+ pkId: { ...SCHEMA_ID, description: "\u5171\u4EAB\u8BB0\u5F55 id\uFF08\u6765\u81EA cowork.permission.list \u7684\u884C id\uFF09" },
2178
+ permissionId: { ...SCHEMA_ID, description: `\u6743\u9650\u7C7B\u578B id\uFF0C\u9ED8\u8BA4 ${DEFAULT_PERMISSION_ID}` }
2179
+ }, { required: ["coworkId", "pkId"] }),
2180
+ handler: async (args, env) => {
2181
+ const coworkId = toId(args.coworkId, "coworkId");
2182
+ const pkId = toId(args.pkId, "pkId");
2183
+ const permissionId = toId(args.permissionId, "permissionId") ?? DEFAULT_PERMISSION_ID;
2184
+ const rows = await listSharePermissions(env, coworkId, permissionId);
2185
+ const hit = rows.find((row) => String(row.id ?? "") === pkId);
2186
+ if (!hit) {
2187
+ throw coworkNotFoundError(
2188
+ "permission_record_not_found",
2189
+ `\u5171\u4EAB\u6743\u9650\u5217\u8868\u4E2D\u672A\u627E\u5230 id=${pkId} \u7684\u8BB0\u5F55\uFF0C\u65E0\u6CD5\u5220\u9664\uFF08\u7981\u6B62\u51ED\u7A7A\u6784\u9020 datas \u63D0\u4EA4\uFF09`
2190
+ );
2191
+ }
2192
+ const session = await env.host.getSession();
2193
+ const continuation = await env.continuation.issue({
2194
+ operation: "cowork.permission.remove.apply",
2195
+ baseUrl: session.baseUrl,
2196
+ profile: session.profile,
2197
+ userId: session.userId,
2198
+ coworkId,
2199
+ pkId,
2200
+ permissionId
2201
+ });
2202
+ return coworkSuccess("cowork.permission.remove.prepare", {
2203
+ summary: {
2204
+ coworkId,
2205
+ pkId,
2206
+ permissionId,
2207
+ targetUser: {
2208
+ id: hit.userid ?? hit.userId ?? hit.id ?? null,
2209
+ name: hit.username ?? hit.name ?? hit.content ?? null
2210
+ },
2211
+ warning: "\u5220\u9664\u5171\u4EAB\u5BF9\u8C61\u540E\u8BE5\u4EBA\u5458\u5C06\u5931\u53BB\u5BF9\u5E94\u6743\u9650\uFF0C\u9875\u9762\u65E0\u64A4\u9500\u5165\u53E3"
2212
+ },
2213
+ continuation
2214
+ });
2215
+ }
2216
+ };
2217
+ var permRemoveApply = {
2218
+ name: "cowork.permission.remove.apply",
2219
+ resource: "cowork",
2220
+ method: "permission.remove.apply",
2221
+ action: "cowork.permission.remove.apply",
2222
+ summary: "\u5220\u9664\u5171\u4EAB\u5BF9\u8C61\uFF08\u9700 confirm=true \u4E0E continuation\uFF09\uFF1Aapply \u9636\u6BB5\u91CD\u65B0\u53D6\u771F\u5B9E\u8BB0\u5F55\u540E\u5168\u91CF\u56DE\u4F20",
2223
+ risk: WRITE,
2224
+ requiresConfirmation: true,
2225
+ inputSchema: schemaOf({
2226
+ coworkId: { ...SCHEMA_ID },
2227
+ pkId: { ...SCHEMA_ID },
2228
+ permissionId: { ...SCHEMA_ID },
2229
+ confirm: { type: "boolean" },
2230
+ continuation: { type: "string" }
2231
+ }, { required: ["coworkId", "pkId", "confirm", "continuation"] }),
2232
+ handler: async (args, env) => {
2233
+ requireConfirm(args, "cowork.permission.remove.apply");
2234
+ const lease = await verifyLease(args, "cowork.permission.remove.apply", env);
2235
+ const coworkId = toId(args.coworkId, "coworkId");
2236
+ const pkId = toId(args.pkId, "pkId");
2237
+ if (lease.coworkId !== coworkId || lease.pkId !== pkId) {
2238
+ throw coworkValidationError("target_changed", "\u534F\u4F5C\u6216\u8BB0\u5F55\u4E0E prepare \u65F6\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C prepare");
2239
+ }
2240
+ const permissionId = toId(args.permissionId, "permissionId") ?? String(lease.permissionId ?? DEFAULT_PERMISSION_ID);
2241
+ const rows = await listSharePermissions(env, coworkId, permissionId);
2242
+ const record = rows.find((row) => String(row.id ?? "") === pkId);
2243
+ if (!record) {
2244
+ throw coworkNotFoundError(
2245
+ "permission_record_gone",
2246
+ `\u5171\u4EAB\u8BB0\u5F55 ${pkId} \u5DF2\u4E0D\u5B58\u5728\uFF08\u53EF\u80FD\u5DF2\u88AB\u4ED6\u4EBA\u79FB\u9664\uFF09\uFF0C\u65E0\u9700\u91CD\u590D\u5220\u9664`
2247
+ );
2248
+ }
2249
+ const body = {
2250
+ sourceId: coworkId,
2251
+ permissionId,
2252
+ sourceType: 1,
2253
+ id: coworkId,
2254
+ permissionFrom: permissionId,
2255
+ ids: pkId,
2256
+ datas: [record]
2257
+ };
2258
+ let response;
2259
+ try {
2260
+ response = await env.host.request({
2261
+ method: "POST",
2262
+ path: "/api/cowork/permission/deleteSharePermissionByPKIds",
2263
+ body,
2264
+ operation: "cowork.permission.remove.apply"
2265
+ });
2266
+ } catch (error) {
2267
+ if (isNetworkError5(error)) {
2268
+ throw coworkPartialError("\u5220\u9664\u5171\u4EAB\u5BF9\u8C61\u8BF7\u6C42\u5DF2\u53D1\u51FA\u4F46\u672A\u6536\u5230\u786E\u5B9A\u7ED3\u679C\uFF0C\u7981\u6B62\u81EA\u52A8\u91CD\u8BD5\uFF1A\u8BF7\u7528 cowork.permission.list \u6838\u5BF9", { coworkId, pkId });
2269
+ }
2270
+ throw error;
2271
+ }
2272
+ const after = await listSharePermissions(env, coworkId, permissionId).catch(() => null);
2273
+ const stillThere = after ? after.some((row) => String(row.id ?? "") === pkId) : null;
2274
+ return coworkSuccess("cowork.permission.remove.apply", {
2275
+ coworkId,
2276
+ pkId,
2277
+ removed: stillThere === false ? true : void 0,
2278
+ verified: stillThere !== null,
2279
+ result: unwrapData(response) ?? null
2280
+ });
2281
+ }
2282
+ };
2283
+ var coworkPermissionWriteOperations = [
2284
+ permAddPrepare,
2285
+ permAddApply,
2286
+ permRemovePrepare,
2287
+ permRemoveApply
2288
+ ];
2289
+
2290
+ // src/shortcuts/cowork/operations/registry.ts
2291
+ function buildRegistry() {
2292
+ const registry = /* @__PURE__ */ new Map();
2293
+ const definitions = [
2294
+ ...coworkReadOperations,
2295
+ ...coworkItemWriteOperations,
2296
+ ...coworkDiscussWriteOperations,
2297
+ ...coworkMemberWriteOperations,
2298
+ ...coworkReviewOperations,
2299
+ ...coworkPermissionWriteOperations
2300
+ ];
2301
+ for (const definition of definitions) {
2302
+ if (registry.has(definition.name)) {
2303
+ throw new Error(`duplicate cowork operation: ${definition.name}`);
2304
+ }
2305
+ registry.set(definition.name, definition);
2306
+ }
2307
+ return registry;
2308
+ }
2309
+ var coworkOperationRegistry = buildRegistry();
2310
+ function coworkOperationDefinitions() {
2311
+ return [...coworkOperationRegistry.values()];
2312
+ }
2313
+ function getCoworkOperation(operation) {
2314
+ const definition = coworkOperationRegistry.get(operation);
2315
+ if (!definition) {
2316
+ throw coworkValidationError("operation_unknown", `\u534F\u4F5C\u533A\u4E0D\u652F\u6301\u64CD\u4F5C\uFF1A${operation}`);
2317
+ }
2318
+ return definition;
2319
+ }
2320
+
2321
+ // src/shortcuts/cowork/manifest.ts
2322
+ var BROWSER_WITHHELD = [
2323
+ "cowork.browser.associate",
2324
+ "cowork.browser.complete",
2325
+ "cowork.browser.condition",
2326
+ "cowork.browser.data",
2327
+ "cowork.browser.destData",
2328
+ "cowork.browser.history",
2329
+ "cowork.browser.leftData",
2330
+ "cowork.browser.prop",
2331
+ "cowork.upvote.vote",
2332
+ "cowork.upvote.cancel",
2333
+ "cowork.upvote.voters"
2334
+ ];
2335
+ var PERMISSION_TABLE_WITHHELD = [
2336
+ "cowork.permission.table.info",
2337
+ "cowork.permission.table.update"
2338
+ ];
2339
+ var SEARCH_WITHHELD = [
2340
+ "cowork.search.meta",
2341
+ "cowork.search.history"
2342
+ ];
2343
+ function buildOperations() {
2344
+ return coworkOperationDefinitions().map((definition) => ({
2345
+ name: definition.name,
2346
+ resource: definition.resource,
2347
+ summary: definition.summary,
2348
+ risk: definition.risk,
2349
+ ...definition.requiresConfirmation ? { requiresConfirmation: true } : {},
2350
+ inputSchema: definition.inputSchema
2351
+ }));
2352
+ }
2353
+ var coworkManifest = {
2354
+ schemaVersion: 1,
2355
+ name: "cowork",
2356
+ title: "\u6CDB\u5FAEE10\u534F\u4F5C\u533A\uFF08\u534F\u4F5C\u4E8B\u9879/\u8BA8\u8BBA/\u5BA1\u6279/\u5171\u4EAB\u6743\u9650\uFF09",
2357
+ version: "0.1.0",
2358
+ host: "e10-cowork",
2359
+ status: "builtin",
2360
+ sourceSkill: "weaver-e10-cowork",
2361
+ capabilities: ["cowork"],
2362
+ operations: buildOperations(),
2363
+ withheldOperations: [
2364
+ ...BROWSER_WITHHELD.map((name) => ({
2365
+ name,
2366
+ reason: "\u6D4F\u89C8\u9009\u62E9/\u70B9\u8D5E\u7EC4\u4EF6\u63A5\u53E3\uFF1A\u6E90\u8D44\u6599\u53EA\u63D0\u4F9B path \u6E05\u5355\uFF0C\u672A\u7ED9\u51FA\u8BF7\u6C42\u4F53\u5B57\u6BB5\u8868\uFF0C\u65E0\u6CD5\u9010\u5B57\u6BB5\u5EFA\u6A21\u3002\u9009\u4EBA/\u9009\u90E8\u95E8\u8BF7\u6539\u7528 ehr \u6A21\u5757\u7684\u4EBA\u5458\u4E0E\u7EC4\u7EC7\u67E5\u8BE2\u80FD\u529B\u53D6 id\uFF1B\u8865\u9F50\u65B9\u5F0F\uFF1A\u6293\u4E00\u6B21\u9875\u9762\u8BF7\u6C42\u4F53\u540E\u518D\u5B9E\u73B0\u3002\u4E0D\u5F97\u51ED\u731C\u6D4B\u6784\u9020\u8BF7\u6C42\u4F53\u3002"
2367
+ })),
2368
+ ...PERMISSION_TABLE_WITHHELD.map((name) => ({
2369
+ name,
2370
+ reason: "\u5171\u4EAB\u6743\u9650\u5355\u5143\u7684\u9AD8\u7EA7\u914D\u7F6E\uFF08\u5BF9\u8C61\u7C7B\u578B/\u5B89\u5168\u7EA7\u522B/\u7EA7\u8054\u89C4\u5219\uFF09\u662F\u524D\u7AEF\u8868\u5355\u5185\u90E8\u7ED3\u6784\uFF0C\u65E0\u7A33\u5B9A\u5165\u53C2\u5951\u7EA6\uFF1B\u5E38\u89C4\u6388\u6743/\u53D6\u6D88\u6388\u6743\u8BF7\u7528 cowork.permission.add / cowork.permission.remove\u3002"
2371
+ })),
2372
+ ...SEARCH_WITHHELD.map((name) => ({
2373
+ name,
2374
+ reason: "\u641C\u7D22\u7EC4\u4EF6\u7684 UI \u5143\u6570\u636E\u4E0E\u641C\u7D22\u5386\u53F2\u8BB0\u5F55\uFF0C\u5C5E\u524D\u7AEF\u4EA4\u4E92\u884C\u4E3A\uFF0C\u5BF9 Agent \u65E0\u4E1A\u52A1\u8BED\u4E49\uFF1B\u5217\u8868\u7B5B\u9009\u8BF7\u76F4\u63A5\u7528 cowork.list \u7684\u6761\u4EF6\u5B57\u6BB5\uFF08\u5B57\u6BB5\u96C6\u5408\u4EE5 cowork.conditions \u8FD4\u56DE\u4E3A\u51C6\uFF09\u3002"
2375
+ }))
2376
+ ]
2377
+ };
2378
+
2379
+ // src/shortcuts/cowork/operations.ts
2380
+ async function executeCoworkOperation(operation, rawInput, context) {
2381
+ const definition = getCoworkOperation(operation);
2382
+ const input = asObject(rawInput);
2383
+ assertNoForbiddenKeys(input);
2384
+ const host = {
2385
+ request(request) {
2386
+ return context.host.request({
2387
+ ...request,
2388
+ operation: request.operation || operation
2389
+ });
2390
+ },
2391
+ getSession() {
2392
+ return context.host.getSession();
2393
+ }
2394
+ };
2395
+ return definition.handler(input, { ...context, host });
2396
+ }
2397
+
2398
+ // src/shortcuts/cowork/index.ts
2399
+ function asOptions(value) {
2400
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
2401
+ }
2402
+ async function readStdin() {
2403
+ const chunks = [];
2404
+ for await (const chunk of process.stdin) {
2405
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
2406
+ }
2407
+ return Buffer.concat(chunks).toString("utf8");
2408
+ }
2409
+ function stripBom(value) {
2410
+ return value.replace(/^\uFEFF+/, "");
2411
+ }
2412
+ function parseJsonInput(raw, label) {
2413
+ try {
2414
+ const parsed = JSON.parse(stripBom(raw));
2415
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
2416
+ throw new Error("input must be an object");
2417
+ }
2418
+ return parsed;
2419
+ } catch {
2420
+ throw coworkValidationError("input_invalid", `${label} \u4E0D\u662F\u5408\u6CD5 JSON \u5BF9\u8C61`);
2421
+ }
2422
+ }
2423
+ async function inputFrom(options, extra = {}) {
2424
+ const opts = asOptions(options);
2425
+ let input = {};
2426
+ if (opts.input && opts.inputJson) {
2427
+ throw coworkValidationError("input_conflict", "\u4E0D\u80FD\u540C\u65F6\u4F20 --input \u548C --input-json");
2428
+ }
2429
+ if (opts.inputJson) {
2430
+ input = parseJsonInput(String(opts.inputJson), "--input-json");
2431
+ }
2432
+ if (opts.input) {
2433
+ let raw;
2434
+ try {
2435
+ raw = stripBom(opts.input === "-" ? await readStdin() : await readFile2(String(opts.input), "utf8"));
2436
+ } catch {
2437
+ throw coworkValidationError("input_unreadable", `\u65E0\u6CD5\u8BFB\u53D6 --input\uFF1A${String(opts.input)}`);
2438
+ }
2439
+ input = parseJsonInput(raw, "--input");
2440
+ }
2441
+ return {
2442
+ ...input,
2443
+ ...Object.fromEntries(Object.entries(extra).filter(([, value]) => value !== void 0 && value !== ""))
2444
+ };
2445
+ }
2446
+ function successEnvelope(operation, result) {
2447
+ return {
2448
+ schemaVersion: 1,
2449
+ ok: true,
2450
+ operation,
2451
+ data: result.data === void 0 ? null : result.data,
2452
+ ...result.meta ? { meta: result.meta } : {},
2453
+ warnings: []
2454
+ };
2455
+ }
2456
+ function failureEnvelope(error) {
2457
+ const structured = error;
2458
+ return {
2459
+ schemaVersion: 1,
2460
+ ok: false,
2461
+ ...structured?.partialData === void 0 ? {} : { data: structured.partialData },
2462
+ error: toErrorEnvelope(error)
2463
+ };
2464
+ }
2465
+ async function executeAndPrint(ctx, operation, input) {
2466
+ try {
2467
+ const result = await executeCoworkOperation(operation, input, {
2468
+ ctx,
2469
+ host: createCoworkHost(ctx),
2470
+ continuation: createCoworkContinuationSigner(ctx)
2471
+ });
2472
+ ctx.output.write(successEnvelope(operation, result), { json: true });
2473
+ } catch (error) {
2474
+ console.error(JSON.stringify(failureEnvelope(error), null, 2));
2475
+ process.exitCode = isCliError(error) ? error.exitCode : 1 /* GeneralError */;
2476
+ }
2477
+ }
2478
+ var coworkShortcut = {
2479
+ name: "cowork",
2480
+ description: "\u6CDB\u5FAEE10\u534F\u4F5C\u533A\uFF08\u534F\u4F5C\u4E8B\u9879/\u8BA8\u8BBA/\u5BA1\u6279/\u5171\u4EAB\u6743\u9650\uFF09CLI",
2481
+ category: "shortcut",
2482
+ register({ program, action }) {
2483
+ const cowork = program.command("cowork").description("\u6CDB\u5FAEE10\u534F\u4F5C\u533A\uFF08\u534F\u4F5C\u4E8B\u9879/\u8BA8\u8BBA/\u5BA1\u6279/\u5171\u4EAB\u6743\u9650\uFF09");
2484
+ cowork.command("schema").description("Print cowork operation manifest for agents").action(action((ctx) => {
2485
+ ctx.output.write(coworkManifest, { json: true });
2486
+ }));
2487
+ cowork.command("run").description("Run a cowork operation with JSON input").argument("<operation>", "operation name, e.g. cowork.list").option("--input <path>", "JSON input file, or - for stdin").option("--input-json <json>", "inline JSON input object").action(action(async (ctx, operation, options) => {
2488
+ await executeAndPrint(ctx, String(operation), await inputFrom(options));
2489
+ }));
2490
+ cowork.command("list").description("\u534F\u4F5C\u5217\u8868\uFF08\u9ED8\u8BA4\u8FDB\u884C\u4E2D\uFF09").option("--input <path>", "JSON input file, or - for stdin").option("--scope <scope>", "main/attention/collect/mineDiscuss/mineItem/related/apply/approve/log/quit/itemApprove/discussApprove").option("--keyword <text>", "\u534F\u4F5C\u4E3B\u9898\u5173\u952E\u5B57").option("--page <n>", "page number").option("--size <n>", "page size").action(action(async (ctx, options) => {
2491
+ const opts = asOptions(options);
2492
+ await executeAndPrint(ctx, "cowork.list", await inputFrom(options, {
2493
+ scope: opts.scope || "main",
2494
+ itemName: opts.keyword,
2495
+ itemNameCondition: opts.keyword ? "bl" : void 0,
2496
+ current: opts.page ? Number(opts.page) : void 0,
2497
+ pageSize: opts.size ? Number(opts.size) : void 0
2498
+ }));
2499
+ }));
2500
+ cowork.command("view").description("\u534F\u4F5C\u8BE6\u60C5").option("--input <path>", "JSON input file, or - for stdin").option("--id <id>", "cowork id").action(action(async (ctx, options) => {
2501
+ const opts = asOptions(options);
2502
+ await executeAndPrint(ctx, "cowork.view", await inputFrom(options, { id: opts.id }));
2503
+ }));
2504
+ cowork.command("discussions").description("\u534F\u4F5C\u8BA8\u8BBA\u8BB0\u5F55").option("--input <path>", "JSON input file, or - for stdin").option("--id <id>", "cowork id").option("--page <n>", "page number").action(action(async (ctx, options) => {
2505
+ const opts = asOptions(options);
2506
+ await executeAndPrint(ctx, "cowork.discuss.list", await inputFrom(options, {
2507
+ coworkId: opts.id,
2508
+ current: opts.page ? Number(opts.page) : void 0
2509
+ }));
2510
+ }));
2511
+ cowork.command("sections").description("\u65B0\u5EFA\u534F\u4F5C\u53EF\u9009\u7248\u5757\uFF08\u4ECE\u65B0\u5EFA\u8868\u5355\u89E3\u6790\uFF09").action(action(async (ctx) => {
2512
+ await executeAndPrint(ctx, "cowork.form", await inputFrom({}));
2513
+ }));
2514
+ cowork.command("reply").description("\u53D1\u5E03/\u56DE\u590D\u8BA8\u8BBA\uFF08prepare\uFF0C\u786E\u8BA4\u540E apply\uFF09").option("--input <path>", "JSON input file, or - for stdin").option("--id <id>", "cowork id").option("--content <text>", "discussion content").action(action(async (ctx, options) => {
2515
+ const opts = asOptions(options);
2516
+ await executeAndPrint(ctx, "cowork.discuss.publish.prepare", await inputFrom(options, {
2517
+ coworkId: opts.id,
2518
+ content: opts.content
2519
+ }));
2520
+ }));
2521
+ }
2522
+ };
2523
+ export {
2524
+ coworkShortcut,
2525
+ inputFrom,
2526
+ successEnvelope
2527
+ };