weaver-work-cli 0.1.28 → 0.1.31

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 (219) hide show
  1. package/dist/chunks/archive-U766FTFH.js +2537 -0
  2. package/dist/chunks/archive-oa-DMWEKX3L.js +1317 -0
  3. package/dist/chunks/asset-TCR7VDEV.js +2109 -0
  4. package/dist/chunks/attachment-content-AQNX5N3S.js +23 -0
  5. package/dist/chunks/blog-EVZWGDVM.js +2157 -0
  6. package/dist/chunks/caizhilian-JOWS6SL5.js +10087 -0
  7. package/dist/chunks/calendar-5WNCV66Q.js +1195 -0
  8. package/dist/chunks/chunk-2DUV44UX.js +15606 -0
  9. package/dist/chunks/chunk-324YPTC2.js +1607 -0
  10. package/dist/chunks/chunk-65QMVWHS.js +231 -0
  11. package/dist/chunks/chunk-6V7ZLF34.js +387 -0
  12. package/dist/chunks/chunk-AC7KJWC5.js +358 -0
  13. package/dist/chunks/chunk-AJ62BGAW.js +29 -0
  14. package/dist/chunks/chunk-BUSC6UAE.js +43 -0
  15. package/dist/chunks/chunk-CVZ2JOSW.js +62 -0
  16. package/dist/chunks/chunk-D4LTJSJD.js +477 -0
  17. package/dist/chunks/chunk-EG6ZU444.js +654 -0
  18. package/dist/chunks/chunk-EZALDOQH.js +383 -0
  19. package/dist/chunks/chunk-FMPJJYYI.js +106 -0
  20. package/dist/chunks/chunk-G2JSIUWF.js +769 -0
  21. package/dist/chunks/chunk-GCG2NMWR.js +703 -0
  22. package/dist/chunks/chunk-GPMFD4RD.js +75 -0
  23. package/dist/chunks/chunk-H3WDBYJW.js +508 -0
  24. package/dist/chunks/chunk-H6XSTSLM.js +2357 -0
  25. package/dist/chunks/chunk-J7RJTZSV.js +5556 -0
  26. package/dist/chunks/chunk-LUSPKZKY.js +53 -0
  27. package/dist/chunks/chunk-NIAJ5ZCG.js +73 -0
  28. package/dist/chunks/chunk-NOODWMCL.js +584 -0
  29. package/dist/chunks/chunk-OOUTBLZ4.js +51 -0
  30. package/dist/chunks/chunk-P26ZWSKU.js +73 -0
  31. package/dist/chunks/chunk-QWY6PGL6.js +3472 -0
  32. package/dist/chunks/chunk-R2IJAK7T.js +464 -0
  33. package/dist/chunks/chunk-R7O5PUWO.js +205 -0
  34. package/dist/chunks/chunk-RCGYCOMG.js +6962 -0
  35. package/dist/chunks/chunk-VZTXRG6X.js +403 -0
  36. package/dist/chunks/chunk-WHD4XMRP.js +161 -0
  37. package/dist/chunks/chunk-YLCYX7LE.js +371 -0
  38. package/dist/chunks/chunk-ZEDWSH32.js +68 -0
  39. package/dist/chunks/continuation-2CKSBLA6.js +11 -0
  40. package/dist/chunks/continuation-HZIZRZBX.js +13 -0
  41. package/dist/chunks/continuation-NLECEJPX.js +11 -0
  42. package/dist/chunks/ebuilder-form-NJ4YK6CC.js +2276 -0
  43. package/dist/chunks/ehr-MMYN36VA.js +5241 -0
  44. package/dist/chunks/employee-SAK2QYXX.js +11 -0
  45. package/dist/chunks/esb-HIWHOU7Q.js +141 -0
  46. package/dist/chunks/fna-KBACQTA5.js +1444 -0
  47. package/dist/chunks/host-3OHS5QUX.js +21 -0
  48. package/dist/chunks/host-IG6KEH5Q.js +19 -0
  49. package/dist/chunks/host-KQL5N4HO.js +23 -0
  50. package/dist/chunks/host-LLSZQCWR.js +17 -0
  51. package/dist/chunks/hrm-LYEC67ZQ.js +244 -0
  52. package/dist/chunks/im-RN2UKAEU.js +252 -0
  53. package/dist/chunks/invoice-EEPHLAF6.js +5179 -0
  54. package/dist/chunks/jiuchuanhui-WVVZYSJE.js +1940 -0
  55. package/dist/chunks/lazy-dispatch-MDOFFL2S.js +28 -0
  56. package/dist/chunks/mail-LNQLTF6L.js +2695 -0
  57. package/dist/chunks/meeting-XSD3BDVQ.js +504 -0
  58. package/dist/chunks/msg-parse-4GSQ2WTO.js +41 -0
  59. package/dist/chunks/okr-TMWTIU2K.js +2482 -0
  60. package/dist/chunks/plan-A2FSFA7T.js +2025 -0
  61. package/dist/chunks/project-T26QLBQF.js +1361 -0
  62. package/dist/chunks/registry-2VLUAESA.js +14 -0
  63. package/dist/chunks/registry-JCFEYXOE.js +18 -0
  64. package/dist/chunks/registry-NYPYMZXG.js +16 -0
  65. package/dist/chunks/registry-Q7OQJ3SU.js +19 -0
  66. package/dist/chunks/registry-ZJMJVWFA.js +19 -0
  67. package/dist/chunks/room-recommend-UR4ZDZS6.js +20 -0
  68. package/dist/chunks/schedule-5L2PM4M6.js +24 -0
  69. package/dist/chunks/state-Y2XBP6YE.js +15 -0
  70. package/dist/chunks/workflow-TR6PG2SL.js +245 -0
  71. package/dist/cmd/argv.js +45 -0
  72. package/dist/cmd/docs/index.js +3 -3
  73. package/dist/cmd/lazy-dispatch.js +20 -0
  74. package/dist/cmd/root.js +2 -4
  75. package/dist/cmd/setup/index.js +2 -2
  76. package/dist/cmd/skills/index.js +2 -2
  77. package/dist/core/package-paths.js +47 -0
  78. package/dist/index.js +163 -7
  79. package/dist/internal/e10/auth/xiaoe.js +3 -3
  80. package/dist/internal/e10/request-runtime.js +18 -62
  81. package/dist/internal/skills/detector.js +2 -2
  82. package/dist/shortcuts/contract/data/performance-catalog.js +1306 -0
  83. package/dist/shortcuts/contract/host.js +91 -35
  84. package/dist/shortcuts/contract/index.js +213 -0
  85. package/dist/shortcuts/contract/manifest.js +928 -0
  86. package/dist/shortcuts/contract/ooxml/docx.js +295 -0
  87. package/dist/shortcuts/contract/ooxml/xlsx.js +221 -0
  88. package/dist/shortcuts/contract/ooxml/zip.js +158 -0
  89. package/dist/shortcuts/contract/operations/assistant.js +1156 -0
  90. package/dist/shortcuts/contract/operations/clause-library.js +522 -0
  91. package/dist/shortcuts/contract/operations/compare.js +193 -0
  92. package/dist/shortcuts/contract/operations/credit-page.js +34 -0
  93. package/dist/shortcuts/contract/operations/flow.js +98 -0
  94. package/dist/shortcuts/contract/operations/page.js +66 -0
  95. package/dist/shortcuts/contract/operations/performance.js +733 -0
  96. package/dist/shortcuts/contract/operations/quote.js +557 -0
  97. package/dist/shortcuts/contract/operations/recommend.js +78 -0
  98. package/dist/shortcuts/contract/operations/registry.js +18 -0
  99. package/dist/shortcuts/contract/operations/review.js +83 -0
  100. package/dist/shortcuts/contract/operations/shared.js +37 -0
  101. package/dist/shortcuts/contract/operations/upload.js +108 -0
  102. package/dist/shortcuts/contract/operations/write.js +3 -2
  103. package/dist/shortcuts/index.js +140 -40
  104. package/dist/shortcuts/invoice/host.js +2 -1
  105. package/dist/shortcuts/invoice/manifest.js +36 -12
  106. package/dist/shortcuts/invoice/operations/issuing-qys.js +132 -36
  107. package/dist/shortcuts/invoice/operations/reim-auto.js +9 -0
  108. package/dist/shortcuts/invoice/operations/reim.js +81 -5
  109. package/dist/shortcuts/invoice/operations/shared.js +12 -5
  110. package/dist/shortcuts/meeting/host.js +45 -3
  111. package/dist/shortcuts/meeting/invitation/docx.js +442 -0
  112. package/dist/shortcuts/meeting/operations/attachment-content.js +418 -0
  113. package/dist/shortcuts/meeting/operations/attachment.js +442 -0
  114. package/dist/shortcuts/meeting/operations/eb/cache.js +57 -0
  115. package/dist/shortcuts/meeting/operations/eb/catalog.js +343 -28
  116. package/dist/shortcuts/meeting/operations/eb/conflict.js +372 -11
  117. package/dist/shortcuts/meeting/operations/eb/create-flow.js +710 -0
  118. package/dist/shortcuts/meeting/operations/eb/decision.js +47 -1
  119. package/dist/shortcuts/meeting/operations/eb/factory.js +129 -11
  120. package/dist/shortcuts/meeting/operations/eb/index.js +122 -2
  121. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +378 -0
  122. package/dist/shortcuts/meeting/operations/eb/room-summary.js +84 -0
  123. package/dist/shortcuts/meeting/operations/eb/schedule.js +450 -0
  124. package/dist/shortcuts/meeting/operations/from-group-chat.js +576 -0
  125. package/dist/shortcuts/meeting/operations/invitation.js +458 -0
  126. package/dist/shortcuts/meeting/operations/minute-content.js +266 -0
  127. package/dist/shortcuts/meeting/operations/pipeline.js +489 -0
  128. package/dist/shortcuts/meeting/operations/qrcode.js +131 -0
  129. package/dist/shortcuts/meeting/operations/receipts.js +1 -1
  130. package/dist/shortcuts/meeting/operations/registry.js +18 -0
  131. package/dist/shortcuts/meeting/operations/summary.js +276 -0
  132. package/dist/shortcuts/meeting/operations/task-notify.js +325 -0
  133. package/dist/shortcuts/meeting/operations.js +42 -1
  134. package/dist/shortcuts/meeting/qr/encoder.js +427 -0
  135. package/dist/shortcuts/meeting/qr/render.js +103 -0
  136. package/dist/shortcuts/workflow/index.js +3 -0
  137. package/dist/shortcuts/workflow/operations/form.js +17 -5
  138. package/dist/shortcuts/workflow/operations/read.js +13 -6
  139. package/dist/shortcuts/workflow/operations/registry.js +2 -0
  140. package/dist/shortcuts/workflow/operations/todoSmartConvert/businessRules.js +331 -0
  141. package/dist/shortcuts/workflow/operations/todoSmartConvert/detailFieldRules.js +133 -0
  142. package/dist/shortcuts/workflow/operations/todoSmartConvert/summaryCache.js +326 -0
  143. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoDetailCache.js +113 -0
  144. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoDetailFetcher.js +259 -0
  145. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoListRows.js +64 -0
  146. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoOutputPlanner.js +28 -0
  147. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.aggregate.js +70 -0
  148. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +267 -0
  149. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +392 -0
  150. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.detail.js +165 -0
  151. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +448 -0
  152. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.groupSummary.js +348 -0
  153. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +222 -0
  154. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.pipeline.js +66 -0
  155. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +502 -0
  156. package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.summary.js +540 -0
  157. package/docs/_catalog.md +1 -0
  158. package/docs/contract.md +39 -4
  159. package/docs/invoice.md +7 -7
  160. package/docs/todo-smart-convert/README.md +171 -0
  161. package/docs/todo-smart-convert/data-contract.md +236 -0
  162. package/docs/todo-smart-convert/mock/ai-todo-query-target.json +209 -0
  163. package/docs/todo-smart-convert/subgroup-rules.md +245 -0
  164. package/package.json +3 -2
  165. package/scripts/bundle.mjs +63 -0
  166. package/scripts/package-skill.mjs +1 -1
  167. package/skill-template/business-info.json +25 -4
  168. package/skill-template/domains/jinchengda.md +16 -3
  169. package/skill-template/domains/yepiaotong.md +3 -3
  170. package/skills/weaver-e10-jinchengda/SKILL.md +111 -31
  171. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +7 -13
  172. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +150 -0
  173. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +87 -0
  174. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +111 -0
  175. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +0 -15
  176. package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +0 -13
  177. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +50 -0
  178. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +4 -2
  179. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +74 -0
  180. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +84 -0
  181. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +29 -0
  182. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +28 -0
  183. package/skills/weaver-e10-jinchengda/references/contract-request-status.md +2 -21
  184. package/skills/weaver-e10-jinchengda/references/contract-request-write.md +0 -24
  185. package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +0 -15
  186. package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +0 -17
  187. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +70 -0
  188. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +0 -15
  189. package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +0 -15
  190. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1168 -152
  191. package/skills/weaver-e10-meeting/SKILL.md +493 -17
  192. package/skills/weaver-e10-meeting/references/meeting-change.md +4 -4
  193. package/skills/weaver-e10-meeting/references/meeting-create.md +6 -6
  194. package/skills/weaver-e10-meeting/references/meeting-eb.md +503 -27
  195. package/skills/weaver-e10-meeting/references/meeting-invitation.md +113 -0
  196. package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +6 -6
  197. package/skills/weaver-e10-meeting/references/meeting-minute-file.md +425 -0
  198. package/skills/weaver-e10-meeting/references/meeting-queries.md +4 -4
  199. package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +15 -15
  200. package/skills/weaver-e10-meeting/references/meeting-verification.md +19 -11
  201. package/skills/weaver-e10-meeting.zip +0 -0
  202. package/skills/weaver-e10-workflow/SKILL.md +23 -1
  203. package/skills/weaver-e10-workflow/references/todo-smart-convert.md +282 -0
  204. package/skills/weaver-e10-workflow/scripts/todo-summary.cjs +695 -0
  205. package/skills/weaver-e10-yepiaotong/SKILL.md +15 -11
  206. package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +1 -1
  207. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-examples.md +10 -7
  208. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-form-fill-rules.md +41 -14
  209. package/skills/weaver-e10-yepiaotong/references/invoice-issuing-workflow.md +54 -26
  210. package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +6 -5
  211. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +14 -11
  212. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +97 -56
  213. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +84 -60
  214. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +142 -105
  215. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +53 -194
  216. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +7 -7
  217. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +164 -72
  218. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +8 -2
  219. package/templates/meeting/invitation.docx +0 -0
@@ -0,0 +1,477 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ ImCliError,
5
+ imAuthError,
6
+ imNetworkError,
7
+ imValidationError
8
+ } from "./chunk-ZEDWSH32.js";
9
+ import {
10
+ E10ApiError,
11
+ createE10RequestRuntime,
12
+ requireE10Session
13
+ } from "./chunk-H3WDBYJW.js";
14
+ import {
15
+ E10_SESSION_EXPIRED_MESSAGE,
16
+ getActiveProfile
17
+ } from "./chunk-324YPTC2.js";
18
+
19
+ // src/shortcuts/im/host.ts
20
+ import { createHash } from "node:crypto";
21
+ import { existsSync } from "node:fs";
22
+ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
23
+ import { dirname, extname, resolve } from "node:path";
24
+ var IM_PREFIX = "/api/em/msg/executeIm";
25
+ function inferProfile(ctx) {
26
+ const options = ctx.getGlobalOptions();
27
+ return options.profile || getActiveProfile();
28
+ }
29
+ function assertPath(requestPath) {
30
+ if (typeof requestPath !== "string" || !requestPath.startsWith("/") || requestPath.startsWith("//")) {
31
+ throw imValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u5FC5\u987B\u662F\u76F8\u5BF9\u7EDD\u5BF9\u8DEF\u5F84");
32
+ }
33
+ if (/^https?:/i.test(requestPath) || /[\r\n]/.test(requestPath) || requestPath.includes("/../")) {
34
+ throw imValidationError("path_invalid", "\u8BF7\u6C42\u8DEF\u5F84\u4E0D\u5141\u8BB8\u8DE8\u57DF\u6216\u8DEF\u5F84\u9003\u9038");
35
+ }
36
+ }
37
+ function formBody(form) {
38
+ if (!form) return void 0;
39
+ const params = new URLSearchParams();
40
+ for (const [key, value] of Object.entries(form)) {
41
+ if (value === void 0 || value === null) continue;
42
+ params.set(key, typeof value === "string" ? value : JSON.stringify(value));
43
+ }
44
+ return params;
45
+ }
46
+ function mapRuntimeNetworkError(error) {
47
+ if (error instanceof E10ApiError && error.type === "network") {
48
+ throw imNetworkError(error.subtype, error.message, {
49
+ retryable: error.retryable,
50
+ details: error.details
51
+ });
52
+ }
53
+ throw error;
54
+ }
55
+ function guessMime(name) {
56
+ const ext = extname(String(name || "")).toLowerCase();
57
+ const map = {
58
+ ".jpg": "image/jpeg",
59
+ ".jpeg": "image/jpeg",
60
+ ".png": "image/png",
61
+ ".gif": "image/gif",
62
+ ".webp": "image/webp",
63
+ ".bmp": "image/bmp",
64
+ ".svg": "image/svg+xml",
65
+ ".pdf": "application/pdf",
66
+ ".txt": "text/plain",
67
+ ".md": "text/markdown",
68
+ ".doc": "application/msword",
69
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
70
+ ".xls": "application/vnd.ms-excel",
71
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
72
+ ".ppt": "application/vnd.ms-powerpoint",
73
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
74
+ ".zip": "application/zip",
75
+ ".rar": "application/x-rar-compressed",
76
+ ".mp4": "video/mp4",
77
+ ".mp3": "audio/mpeg"
78
+ };
79
+ return map[ext] || "application/octet-stream";
80
+ }
81
+ async function md5File(filePath) {
82
+ const hash = createHash("md5");
83
+ const { createReadStream } = await import("node:fs");
84
+ const stream = createReadStream(filePath);
85
+ for await (const chunk of stream) hash.update(chunk);
86
+ return hash.digest("hex");
87
+ }
88
+ function createImHost(ctx, dependencies = {}) {
89
+ let e10Session = null;
90
+ let sessionContext = null;
91
+ let selfIdentity = null;
92
+ const personCache = /* @__PURE__ */ new Map();
93
+ const i18nCache = /* @__PURE__ */ new Map();
94
+ const requireSession = dependencies.requireSession || requireE10Session;
95
+ async function ensureSession() {
96
+ if (!e10Session) {
97
+ e10Session = await requireSession(ctx);
98
+ sessionContext = {
99
+ baseUrl: e10Session.getBaseUrl(),
100
+ profile: inferProfile(ctx),
101
+ userId: e10Session.userId,
102
+ tenantKey: e10Session.tenantKey,
103
+ eteamsId: e10Session.eteamsId,
104
+ agentType: e10Session.agentType
105
+ };
106
+ }
107
+ return e10Session;
108
+ }
109
+ async function getSession() {
110
+ await ensureSession();
111
+ return sessionContext;
112
+ }
113
+ async function runtime() {
114
+ return createE10RequestRuntime(ctx, await ensureSession(), {
115
+ interceptors: dependencies.interceptors,
116
+ fetch: dependencies.fetch
117
+ });
118
+ }
119
+ async function request(request2) {
120
+ const {
121
+ method,
122
+ path,
123
+ query,
124
+ body,
125
+ operation,
126
+ form,
127
+ multipart,
128
+ headers: extraHeaders = {},
129
+ // 与源 skill 一致:普通 JSON 请求 15 秒超时即视为失败(超时不做重试)
130
+ timeoutMs = 15e3
131
+ } = request2;
132
+ assertPath(path);
133
+ const resolvedMethod = method || (body === void 0 && form === void 0 && multipart === void 0 ? "GET" : "POST");
134
+ let response;
135
+ try {
136
+ response = await (await runtime()).requestJson({
137
+ module: "im",
138
+ operation,
139
+ method: resolvedMethod,
140
+ path,
141
+ query,
142
+ body: multipart === void 0 ? body : void 0,
143
+ form: multipart === void 0 && form === void 0 ? void 0 : formBody(form ?? {}),
144
+ formData: multipart,
145
+ headers: { "X-Requested-With": "XMLHttpRequest", ...extraHeaders },
146
+ timeoutMs
147
+ });
148
+ } catch (error) {
149
+ mapRuntimeNetworkError(error);
150
+ }
151
+ if (response.status === 401 || response.status === 302) {
152
+ throw imAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
153
+ }
154
+ if (response.parseError) {
155
+ if (response.status < 200 || response.status >= 300) {
156
+ throw new ImCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
157
+ code: response.status,
158
+ details: { status: response.status },
159
+ exitCode: 1
160
+ });
161
+ }
162
+ throw imNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
163
+ }
164
+ if (response.status < 200 || response.status >= 300) {
165
+ throw new ImCliError("api", "http_error", `\u6CDB\u5FAE\u63A5\u53E3 HTTP ${response.status}`, {
166
+ code: response.status,
167
+ details: { status: response.status },
168
+ exitCode: 1
169
+ });
170
+ }
171
+ return response.value;
172
+ }
173
+ async function requestBinary(url, headers = {}) {
174
+ const session = await ensureSession();
175
+ const controller = new AbortController();
176
+ const timer = setTimeout(() => controller.abort(), 6e4);
177
+ try {
178
+ const resp = await (dependencies.fetch || globalThis.fetch)(url, {
179
+ headers: {
180
+ accept: "application/json, text/plain, */*",
181
+ cookie: session.cookieHeader(),
182
+ eteamsid: session.eteamsId,
183
+ "user-agent": session.uaHeader(),
184
+ origin: session.getBaseUrl(),
185
+ ...headers
186
+ },
187
+ redirect: "manual",
188
+ signal: controller.signal
189
+ });
190
+ if (resp.status === 401 || resp.status === 302) {
191
+ throw imAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE);
192
+ }
193
+ if (resp.status !== 200) {
194
+ throw new ImCliError("api", "download_failed", `\u4E0B\u8F7D\u5931\u8D25 HTTP ${resp.status}`, {
195
+ code: resp.status,
196
+ exitCode: 1
197
+ });
198
+ }
199
+ return Buffer.from(await resp.arrayBuffer());
200
+ } catch (error) {
201
+ if (error instanceof ImCliError) throw error;
202
+ const message = error instanceof Error ? error.message : String(error);
203
+ throw imNetworkError("transport", `\u4E0B\u8F7D\u5931\u8D25\uFF1A${message}`, { retryable: true });
204
+ } finally {
205
+ clearTimeout(timer);
206
+ }
207
+ }
208
+ async function getSelfIdentity() {
209
+ if (selfIdentity) return selfIdentity;
210
+ await ensureSession();
211
+ const base = sessionContext?.baseUrl || "";
212
+ if (!base) throw imAuthError("self_identity_unavailable", "\u7F3A\u5C11 baseUrl\uFF0C\u8BF7\u5148\u767B\u5F55");
213
+ const res = await request({
214
+ method: "POST",
215
+ path: `/api/baseserver/layout/teamsCheck?clientType=not_xinchuang&client=WEB&domainName=${encodeURIComponent(base)}`,
216
+ body: {},
217
+ operation: "im.self.identity"
218
+ });
219
+ const cur = res?.currentUser || res?.data?.currentUser || {};
220
+ const uid = String(cur.imUid || sessionContext?.userId || "");
221
+ const cid = String(cur.imCid || "");
222
+ const name = cur.name || cur.realName || cur.userName || "";
223
+ if (!uid || !cid) {
224
+ throw imAuthError("self_identity_incomplete", `teamsCheck \u672A\u8FD4\u56DE\u5B8C\u6574 IM \u8EAB\u4EFD\uFF08imUid=${uid || "-"}, imCid=${cid || "-"}\uFF09\uFF0C\u8BF7\u786E\u8BA4\u767B\u5F55\u6001\u540E\u91CD\u8BD5`);
225
+ }
226
+ selfIdentity = { uid, cid, name };
227
+ return selfIdentity;
228
+ }
229
+ async function uploadFile(filePath, options = {}) {
230
+ const abs = resolve(filePath);
231
+ if (!existsSync(abs)) throw imValidationError("file_not_found", `\u6587\u4EF6\u4E0D\u5B58\u5728: ${abs}`);
232
+ const st = await stat(abs);
233
+ if (!st.isFile()) throw imValidationError("file_invalid", `\u4E0D\u662F\u6587\u4EF6: ${abs}`);
234
+ const name = options.name || filePath.split(/[\\/]/).pop() || "file";
235
+ const size = st.size;
236
+ const md5 = await md5File(abs);
237
+ const data = await readFile(abs);
238
+ const mime = guessMime(name);
239
+ const permission = options.permission !== void 0 ? String(options.permission) : "3";
240
+ const shareUsers = options.shareUsers !== void 0 ? String(options.shareUsers) : "";
241
+ const shareGroups = options.shareGroups !== void 0 ? String(options.shareGroups) : "";
242
+ const lastModified = Math.round(st.mtimeMs);
243
+ const base = sessionContext?.baseUrl || (await getSession()).baseUrl;
244
+ const uploadHeaders = { devtype: "5", langtype: "zh_CN", timezoneoffset: String((/* @__PURE__ */ new Date()).getTimezoneOffset()) };
245
+ const preForm = new FormData();
246
+ const preFields = {
247
+ module: "im",
248
+ size: String(size),
249
+ name,
250
+ lastModified: String(lastModified),
251
+ lastModifiedDate: String(lastModified),
252
+ MD5: md5,
253
+ permission,
254
+ shareUsers,
255
+ shareGroups,
256
+ shareExternals: ""
257
+ };
258
+ for (const [k, v] of Object.entries(preFields)) preForm.append(k, v);
259
+ const preRes = await request({
260
+ method: "POST",
261
+ path: "/api/file/preUploadCheck",
262
+ multipart: preForm,
263
+ headers: uploadHeaders,
264
+ operation: "im.file.upload.check",
265
+ timeoutMs: 15e3
266
+ });
267
+ const preData = preRes?.data || {};
268
+ if (!preData.preUploadId) {
269
+ throw new ImCliError("api", "upload_check_failed", `preUploadCheck \u5931\u8D25`, { details: preRes, exitCode: 1 });
270
+ }
271
+ const preUploadId = String(preData.preUploadId);
272
+ const uploadType = preData.uploadType || "common";
273
+ const upForm = new FormData();
274
+ upForm.append("data", new Blob([data], { type: mime }), name);
275
+ for (const [k, v] of Object.entries({ module: "im", permission, shareUsers, shareGroups, shareExternals: "", uploadType, preUploadId, MD5: md5 })) {
276
+ upForm.append(k, v);
277
+ }
278
+ const upRes = await request({
279
+ method: "POST",
280
+ path: "/api/file/valid/upload",
281
+ multipart: upForm,
282
+ headers: uploadHeaders,
283
+ operation: "im.file.upload.do",
284
+ timeoutMs: 6e4
285
+ });
286
+ const upData = upRes?.data || {};
287
+ if (!upData.fileObj || !upData.fileObj.id && !upData.fileObj.fileid) {
288
+ throw new ImCliError("api", "upload_failed", `valid/upload \u5931\u8D25`, { details: upRes, exitCode: 1 });
289
+ }
290
+ return upData.fileObj;
291
+ }
292
+ async function resolveUsersByIds(ids) {
293
+ const unique = [...new Set(ids.map((x) => String(x)).filter(Boolean))];
294
+ const miss = unique.filter((id) => !personCache.has(id));
295
+ const result = {};
296
+ for (const id of unique) {
297
+ const hit = personCache.get(id);
298
+ if (hit) result[id] = hit;
299
+ }
300
+ for (let i = 0; i < miss.length; i += 100) {
301
+ const batch = miss.slice(i, i + 100);
302
+ const res = await request({
303
+ method: "POST",
304
+ path: "/api/hrm/common/getEmployeeByIds",
305
+ body: { userIdList: batch, externalIdList: [] },
306
+ headers: { devtype: "5" },
307
+ operation: "im.person.resolveByIds",
308
+ timeoutMs: 15e3
309
+ });
310
+ const list = res?.data?.userList;
311
+ if (Array.isArray(list)) {
312
+ for (const u of list) {
313
+ const brief = {
314
+ uid: String(u.id ?? ""),
315
+ name: String(u.name ?? ""),
316
+ cid: String(u.imCid ?? u.cid ?? ""),
317
+ jobNum: String(u.jobNum ?? u.job_num ?? ""),
318
+ department: String(u.department ?? ""),
319
+ departmentId: String(u.departmentId ?? u.department_id ?? ""),
320
+ subCompany: String(u.subCompany ?? u.subcompany ?? ""),
321
+ position: String(u.position ?? ""),
322
+ mobile: String(u.mobile ?? "")
323
+ };
324
+ if (brief.uid) {
325
+ personCache.set(brief.uid, brief);
326
+ result[brief.uid] = brief;
327
+ }
328
+ }
329
+ }
330
+ }
331
+ return result;
332
+ }
333
+ async function searchEmployeeByName(name) {
334
+ const baseForm = {
335
+ browserMultiple: true,
336
+ authWecahtBook: false,
337
+ wxDepNeedConvertCount: 0,
338
+ wxEmpNeedConvertCount: 0,
339
+ wxTotalNeedConvertCount: 0
340
+ };
341
+ const formDatas = {
342
+ status: [{ statusSelect: ["normal"] }],
343
+ subcompany: [{ subcompanyOpt: "in" }],
344
+ department: [{ departmentOpt: "in" }],
345
+ role: [{ roleOpt: "in" }],
346
+ position: [{ positionOpt: "in" }],
347
+ superior: [{ superiorOpt: "in" }]
348
+ };
349
+ if (/@/.test(name)) formDatas.email = [{ emailOpt: "in", emailInput: name }];
350
+ else if (/^\d{11}$/.test(name)) formDatas.mobile = [{ mobileOpt: "in", mobileInput: name }];
351
+ else if (/^\d+$/.test(name) || /^[A-Za-z][A-Za-z0-9]*\d[A-Za-z0-9]*$/.test(name)) formDatas.job_num = [{ job_numOpt: "in", job_numInput: name }];
352
+ else formDatas.username = [{ usernameOpt: "in", usernameInput: name }];
353
+ const out = [];
354
+ let current = 1;
355
+ const pageSize = 200;
356
+ for (; ; ) {
357
+ const res = await request({
358
+ method: "POST",
359
+ path: "/api/hrm/common/browser/data/resource",
360
+ body: { ...baseForm, cmd: "all", formDatas, quickSearchDatas: {}, type: "and", current, pageSize, containsNoneAccount: false, containsPartTimeEmployee: false, containsDls: false },
361
+ operation: "im.person.search",
362
+ timeoutMs: 15e3
363
+ });
364
+ const rows = res?.data?.data;
365
+ if (!Array.isArray(rows)) break;
366
+ for (const r of rows) {
367
+ if (!r?.name) continue;
368
+ const brief = {
369
+ uid: String(r.id ?? ""),
370
+ name: String(r.name),
371
+ cid: String(r.imCid ?? r.cid ?? ""),
372
+ jobNum: String(r.jobNum ?? r.job_num ?? ""),
373
+ department: String(r.department ?? ""),
374
+ departmentId: String(r.departmentId ?? r.department_id ?? ""),
375
+ subCompany: String(r.subCompany ?? r.subcompany ?? ""),
376
+ position: String(r.position ?? ""),
377
+ mobile: String(r.mobile ?? "")
378
+ };
379
+ if (brief.uid) personCache.set(brief.uid, brief);
380
+ out.push(brief);
381
+ }
382
+ if (rows.length < pageSize) break;
383
+ current++;
384
+ if (current > 5) break;
385
+ }
386
+ return out;
387
+ }
388
+ async function fetchI18nLabels(ids) {
389
+ const result = {};
390
+ const unique = [...new Set(ids.map((x) => String(x)).filter((x) => /^\d+$/.test(x)))];
391
+ const miss = unique.filter((id) => !i18nCache.has(id));
392
+ for (const id of unique) {
393
+ const hit = i18nCache.get(id);
394
+ if (hit !== void 0) result[id] = hit;
395
+ }
396
+ if (miss.length === 0) return result;
397
+ try {
398
+ const res = await request({
399
+ method: "POST",
400
+ path: "/api/bs/i18n/labelmanage/getHtmlLabelNames",
401
+ body: miss,
402
+ operation: "im.i18n.labels",
403
+ timeoutMs: 15e3
404
+ });
405
+ const data = res?.data || {};
406
+ for (const id of miss) {
407
+ if (data[id] !== void 0 && data[id] !== null) {
408
+ const text = String(data[id]);
409
+ i18nCache.set(id, text);
410
+ result[id] = text;
411
+ }
412
+ }
413
+ } catch {
414
+ }
415
+ return result;
416
+ }
417
+ async function buildPreviewUrl(options) {
418
+ await ensureSession();
419
+ const kind = options.kind === "video" ? "video" : "img";
420
+ const payload = { tag: kind === "video" ? "1" : "0", msgid: String(options.msgid) };
421
+ if (options.groupId !== void 0 && options.groupId !== null && String(options.groupId) !== "") {
422
+ payload.flag = 1;
423
+ payload.group_id = String(options.groupId);
424
+ } else {
425
+ payload.flag = 0;
426
+ payload.user = { cid: String(options.user?.cid ?? ""), uid: String(options.user?.uid ?? "") };
427
+ }
428
+ const weappAuthStr = Buffer.from(JSON.stringify(payload), "utf-8").toString("base64");
429
+ const params = new URLSearchParams();
430
+ params.set("fileId", String(options.fileId));
431
+ params.set("type", kind === "video" ? "video" : "imgs");
432
+ if (kind !== "video") params.set("imgFormat", options.imgFormat || "small");
433
+ params.set("authModule", "im");
434
+ params.set("weappAuthStr", weappAuthStr);
435
+ return `${(sessionContext?.baseUrl || "").replace(/\/+$/, "")}/api/file/preview?${params.toString()}`;
436
+ }
437
+ async function buildDownloadUrl(options) {
438
+ await ensureSession();
439
+ const kind = options.kind === "video" ? "video" : "img";
440
+ const payload = { tag: kind === "video" ? "1" : "0", msgid: String(options.msgid) };
441
+ if (options.groupId !== void 0 && options.groupId !== null && String(options.groupId) !== "") {
442
+ payload.flag = 1;
443
+ payload.group_id = String(options.groupId);
444
+ } else {
445
+ payload.flag = 0;
446
+ payload.user = { cid: String(options.user?.cid ?? ""), uid: String(options.user?.uid ?? "") };
447
+ }
448
+ const weappAuthStr = Buffer.from(JSON.stringify(payload), "utf-8").toString("base64");
449
+ const params = new URLSearchParams();
450
+ params.set("type", kind === "video" ? "video" : "imgs");
451
+ if (kind !== "video") params.set("imgFormat", options.imgFormat || "small");
452
+ params.set("authModule", "im");
453
+ params.set("weappAuthStr", weappAuthStr);
454
+ return `${(sessionContext?.baseUrl || "").replace(/\/+$/, "")}/api/file/remotedownload/${String(options.fileId)}/im/true?${params.toString()}`;
455
+ }
456
+ return {
457
+ request,
458
+ requestBinary,
459
+ getSession,
460
+ getSelfIdentity,
461
+ uploadFile,
462
+ resolveUsersByIds,
463
+ searchEmployeeByName,
464
+ fetchI18nLabels,
465
+ buildPreviewUrl,
466
+ buildDownloadUrl
467
+ };
468
+ }
469
+
470
+ export {
471
+ mkdir,
472
+ writeFile,
473
+ dirname,
474
+ IM_PREFIX,
475
+ assertPath,
476
+ createImHost
477
+ };