weaver-work-cli 0.1.29 → 0.1.32

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 (185) hide show
  1. package/dist/chunks/archive-UMGX72K6.js +2537 -0
  2. package/dist/chunks/archive-oa-N2IYBLF3.js +1317 -0
  3. package/dist/chunks/asset-GLEGKFG5.js +2109 -0
  4. package/dist/chunks/attachment-content-AQNX5N3S.js +23 -0
  5. package/dist/chunks/blog-E44OTVDA.js +2157 -0
  6. package/dist/chunks/caizhilian-DQUFZXZL.js +10087 -0
  7. package/dist/chunks/calendar-JKPIRKFD.js +1195 -0
  8. package/dist/chunks/chunk-2GA5ZIQL.js +1615 -0
  9. package/dist/chunks/chunk-4YC43QQ4.js +403 -0
  10. package/dist/chunks/chunk-6EFWDL7Y.js +161 -0
  11. package/dist/chunks/chunk-6RKD4DRZ.js +5556 -0
  12. package/dist/chunks/chunk-AJ62BGAW.js +29 -0
  13. package/dist/chunks/chunk-BUSC6UAE.js +43 -0
  14. package/dist/chunks/chunk-C6R3B2ML.js +358 -0
  15. package/dist/chunks/chunk-CVZ2JOSW.js +62 -0
  16. package/dist/chunks/chunk-DW6AUUKS.js +508 -0
  17. package/dist/chunks/chunk-E4Z23GHM.js +6962 -0
  18. package/dist/chunks/chunk-EG6ZU444.js +654 -0
  19. package/dist/chunks/chunk-EZALDOQH.js +383 -0
  20. package/dist/chunks/chunk-FMPJJYYI.js +106 -0
  21. package/dist/chunks/chunk-G2JSIUWF.js +769 -0
  22. package/dist/chunks/chunk-G3QJULO2.js +387 -0
  23. package/dist/chunks/chunk-GCG2NMWR.js +703 -0
  24. package/dist/chunks/chunk-GPMFD4RD.js +75 -0
  25. package/dist/chunks/chunk-H6XSTSLM.js +2357 -0
  26. package/dist/chunks/chunk-H7J4DC5R.js +464 -0
  27. package/dist/chunks/chunk-IURUFGZK.js +477 -0
  28. package/dist/chunks/chunk-LUSPKZKY.js +53 -0
  29. package/dist/chunks/chunk-NIAJ5ZCG.js +73 -0
  30. package/dist/chunks/chunk-NOODWMCL.js +584 -0
  31. package/dist/chunks/chunk-OOUTBLZ4.js +51 -0
  32. package/dist/chunks/chunk-P26ZWSKU.js +73 -0
  33. package/dist/chunks/chunk-QWY6PGL6.js +3472 -0
  34. package/dist/chunks/chunk-WKI2FBIQ.js +15606 -0
  35. package/dist/chunks/chunk-WSKBSQ2U.js +231 -0
  36. package/dist/chunks/chunk-YLCYX7LE.js +371 -0
  37. package/dist/chunks/chunk-YRVDW4WN.js +205 -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-V5FG2EHC.js +2276 -0
  43. package/dist/chunks/ehr-HMFY6VIL.js +5241 -0
  44. package/dist/chunks/employee-SAK2QYXX.js +11 -0
  45. package/dist/chunks/esb-ZYSVB7SG.js +141 -0
  46. package/dist/chunks/fna-B7RKPAZD.js +1444 -0
  47. package/dist/chunks/host-45WED2KK.js +21 -0
  48. package/dist/chunks/host-I4Z6BFYX.js +23 -0
  49. package/dist/chunks/host-KNZ52LJZ.js +17 -0
  50. package/dist/chunks/host-OCH2BCCV.js +19 -0
  51. package/dist/chunks/hrm-2KAZGUHI.js +244 -0
  52. package/dist/chunks/im-ACJJWH4U.js +252 -0
  53. package/dist/chunks/invoice-ZK3WCX2U.js +5179 -0
  54. package/dist/chunks/jiuchuanhui-5PQD3IL2.js +1940 -0
  55. package/dist/chunks/lazy-dispatch-JQXBW3GM.js +28 -0
  56. package/dist/chunks/mail-S2HDDXO2.js +2695 -0
  57. package/dist/chunks/meeting-QVN3I37L.js +504 -0
  58. package/dist/chunks/msg-parse-4GSQ2WTO.js +41 -0
  59. package/dist/chunks/okr-QNG4VC2Q.js +2482 -0
  60. package/dist/chunks/plan-A25EMW6U.js +2025 -0
  61. package/dist/chunks/project-G6XV66DZ.js +1361 -0
  62. package/dist/chunks/registry-2VLUAESA.js +14 -0
  63. package/dist/chunks/registry-7C5UMIPL.js +19 -0
  64. package/dist/chunks/registry-DC6KR3NH.js +18 -0
  65. package/dist/chunks/registry-NYPYMZXG.js +16 -0
  66. package/dist/chunks/registry-TI3CIUXF.js +19 -0
  67. package/dist/chunks/room-recommend-WRTHO6Y2.js +20 -0
  68. package/dist/chunks/schedule-KFIITGSK.js +24 -0
  69. package/dist/chunks/state-Y2XBP6YE.js +15 -0
  70. package/dist/chunks/workflow-DJ7SYWAF.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 +61 -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/manifest.js +34 -11
  105. package/dist/shortcuts/invoice/operations/reim-auto.js +9 -0
  106. package/dist/shortcuts/invoice/operations/reim.js +81 -5
  107. package/dist/shortcuts/invoice/operations/shared.js +12 -5
  108. package/dist/shortcuts/meeting/host.js +45 -3
  109. package/dist/shortcuts/meeting/invitation/docx.js +442 -0
  110. package/dist/shortcuts/meeting/operations/attachment-content.js +418 -0
  111. package/dist/shortcuts/meeting/operations/attachment.js +442 -0
  112. package/dist/shortcuts/meeting/operations/eb/cache.js +57 -0
  113. package/dist/shortcuts/meeting/operations/eb/catalog.js +343 -28
  114. package/dist/shortcuts/meeting/operations/eb/conflict.js +372 -11
  115. package/dist/shortcuts/meeting/operations/eb/create-flow.js +710 -0
  116. package/dist/shortcuts/meeting/operations/eb/decision.js +47 -1
  117. package/dist/shortcuts/meeting/operations/eb/factory.js +129 -11
  118. package/dist/shortcuts/meeting/operations/eb/index.js +122 -2
  119. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +378 -0
  120. package/dist/shortcuts/meeting/operations/eb/room-summary.js +84 -0
  121. package/dist/shortcuts/meeting/operations/eb/schedule.js +450 -0
  122. package/dist/shortcuts/meeting/operations/from-group-chat.js +576 -0
  123. package/dist/shortcuts/meeting/operations/invitation.js +458 -0
  124. package/dist/shortcuts/meeting/operations/minute-content.js +266 -0
  125. package/dist/shortcuts/meeting/operations/pipeline.js +489 -0
  126. package/dist/shortcuts/meeting/operations/qrcode.js +131 -0
  127. package/dist/shortcuts/meeting/operations/receipts.js +1 -1
  128. package/dist/shortcuts/meeting/operations/registry.js +18 -0
  129. package/dist/shortcuts/meeting/operations/summary.js +276 -0
  130. package/dist/shortcuts/meeting/operations/task-notify.js +325 -0
  131. package/dist/shortcuts/meeting/operations.js +42 -1
  132. package/dist/shortcuts/meeting/qr/encoder.js +427 -0
  133. package/dist/shortcuts/meeting/qr/render.js +103 -0
  134. package/dist/shortcuts/workflow/operations/form.js +17 -5
  135. package/docs/contract.md +39 -4
  136. package/docs/invoice.md +5 -5
  137. package/package.json +3 -2
  138. package/scripts/bundle.mjs +63 -0
  139. package/skill-template/business-info.json +25 -4
  140. package/skill-template/domains/jinchengda.md +16 -3
  141. package/skill-template/domains/yepiaotong.md +1 -1
  142. package/skills/weaver-e10-jinchengda/SKILL.md +111 -31
  143. package/skills/weaver-e10-jinchengda/references/contract-agent-entry.md +7 -13
  144. package/skills/weaver-e10-jinchengda/references/contract-ai-assistant.md +150 -0
  145. package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +87 -0
  146. package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +111 -0
  147. package/skills/weaver-e10-jinchengda/references/contract-clause-recommender.md +0 -15
  148. package/skills/weaver-e10-jinchengda/references/contract-clause-reference-save.md +0 -13
  149. package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +50 -0
  150. package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +4 -2
  151. package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +74 -0
  152. package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +84 -0
  153. package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +29 -0
  154. package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +28 -0
  155. package/skills/weaver-e10-jinchengda/references/contract-request-status.md +2 -21
  156. package/skills/weaver-e10-jinchengda/references/contract-request-write.md +0 -24
  157. package/skills/weaver-e10-jinchengda/references/contract-signing-subjects.md +0 -15
  158. package/skills/weaver-e10-jinchengda/references/contract-subject-create.md +0 -17
  159. package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +70 -0
  160. package/skills/weaver-e10-jinchengda/references/contract-template-selector.md +0 -15
  161. package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +0 -15
  162. package/skills/weaver-e10-jinchengda/references/source-manifest.json +1168 -152
  163. package/skills/weaver-e10-meeting/SKILL.md +493 -17
  164. package/skills/weaver-e10-meeting/references/meeting-change.md +4 -4
  165. package/skills/weaver-e10-meeting/references/meeting-create.md +6 -6
  166. package/skills/weaver-e10-meeting/references/meeting-eb.md +503 -27
  167. package/skills/weaver-e10-meeting/references/meeting-invitation.md +113 -0
  168. package/skills/weaver-e10-meeting/references/meeting-lifecycle.md +6 -6
  169. package/skills/weaver-e10-meeting/references/meeting-minute-file.md +425 -0
  170. package/skills/weaver-e10-meeting/references/meeting-queries.md +4 -4
  171. package/skills/weaver-e10-meeting/references/meeting-receipts-signs.md +15 -15
  172. package/skills/weaver-e10-meeting/references/meeting-verification.md +19 -11
  173. package/skills/weaver-e10-meeting.zip +0 -0
  174. package/skills/weaver-e10-yepiaotong/SKILL.md +9 -5
  175. package/skills/weaver-e10-yepiaotong/references/invoice-enterprise-list.md +1 -1
  176. package/skills/weaver-e10-yepiaotong/references/invoice-personal-list.md +6 -5
  177. package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +14 -11
  178. package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +97 -56
  179. package/skills/weaver-e10-yepiaotong/references/reim-examples.md +84 -60
  180. package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +142 -105
  181. package/skills/weaver-e10-yepiaotong/references/reim-matching-rules.md +53 -194
  182. package/skills/weaver-e10-yepiaotong/references/reim-phone-subsidy-rules.md +7 -7
  183. package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +164 -72
  184. package/skills/weaver-e10-yepiaotong/references/source-manifest.json +6 -0
  185. package/templates/meeting/invitation.docx +0 -0
@@ -0,0 +1,231 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+ import {
4
+ workflowApiError,
5
+ workflowAuthError,
6
+ workflowNetworkError
7
+ } from "./chunk-FMPJJYYI.js";
8
+ import {
9
+ createE10RequestRuntime,
10
+ requireE10Session
11
+ } from "./chunk-DW6AUUKS.js";
12
+ import {
13
+ E10_SESSION_EXPIRED_MESSAGE,
14
+ getActiveProfile
15
+ } from "./chunk-2GA5ZIQL.js";
16
+
17
+ // src/shortcuts/workflow/host.ts
18
+ var DEFAULT_TIMEOUT_MS = 3e4;
19
+ var LOGIN_EXPIRED_WORDS = [
20
+ "\u672A\u767B\u5F55",
21
+ "\u8BF7\u767B\u5F55",
22
+ "\u767B\u5F55\u5931\u6548",
23
+ "\u767B\u5F55\u8D85\u65F6",
24
+ "\u4F1A\u8BDD\u8FC7\u671F",
25
+ "\u8BA4\u8BC1\u5931\u8D25",
26
+ "\u8EAB\u4EFD\u8BA4\u8BC1\u5931\u8D25",
27
+ "token\u5931\u6548",
28
+ "token\u8D85\u65F6",
29
+ "token\u8FC7\u671F",
30
+ "token expired",
31
+ "token timeout",
32
+ "token invalid",
33
+ "session expired",
34
+ "login required",
35
+ "not login",
36
+ "not logged"
37
+ ];
38
+ function responseRawText(value) {
39
+ if (typeof value === "string") return value;
40
+ if (value === void 0 || value === null) return "";
41
+ try {
42
+ return JSON.stringify(value);
43
+ } catch {
44
+ return String(value);
45
+ }
46
+ }
47
+ function payloadTexts(value) {
48
+ const texts = [];
49
+ if (typeof value === "string") {
50
+ texts.push(value);
51
+ return texts;
52
+ }
53
+ if (!value || typeof value !== "object") return texts;
54
+ const record = value;
55
+ for (const key of ["code", "status", "message", "msg", "error", "errorMsg", "rawText"]) {
56
+ const item = record[key];
57
+ if (item !== void 0 && item !== null) texts.push(String(item));
58
+ }
59
+ const data = record.data;
60
+ if (data && typeof data === "object") {
61
+ const nested = data;
62
+ for (const key of ["code", "status", "message", "msg", "error", "errorMsg"]) {
63
+ const item = nested[key];
64
+ if (item !== void 0 && item !== null) texts.push(String(item));
65
+ }
66
+ }
67
+ return texts;
68
+ }
69
+ function isAtustRedirect(status, value) {
70
+ if (status === void 0 || !(status >= 300 && status < 400)) return false;
71
+ return responseRawText(value).toLowerCase().includes("atrust");
72
+ }
73
+ function isLoginExpired(value, httpStatus) {
74
+ if (httpStatus === 401 || httpStatus === 403) return true;
75
+ if (isAtustRedirect(httpStatus, value)) return true;
76
+ const joined = payloadTexts(value).join("\n").toLowerCase();
77
+ if (joined.includes("login.jsp")) return true;
78
+ if (joined.includes("<input") && joined.includes("password")) return true;
79
+ return LOGIN_EXPIRED_WORDS.some((word) => joined.includes(word.toLowerCase()));
80
+ }
81
+ function extractApiBusinessError(payload) {
82
+ if (!payload || typeof payload !== "object") return "";
83
+ const record = payload;
84
+ const message = record.message;
85
+ if (message && typeof message === "object") {
86
+ const info = message;
87
+ const errcode = String(info.errcode ?? "").trim();
88
+ const errmsg = String(info.errmsg ?? "").trim();
89
+ if (errcode && !["0", "200"].includes(errcode)) {
90
+ return errmsg || `\u63A5\u53E3\u9519\u8BEF\u7801 ${errcode}`;
91
+ }
92
+ }
93
+ if (record.fail === true || record.status === false) {
94
+ for (const key of ["msg", "message", "error", "errorMsg"]) {
95
+ const value = record[key];
96
+ if (typeof value === "string" && value.trim()) return value.trim();
97
+ }
98
+ if (record.code !== void 0 && record.code !== null) {
99
+ return `\u63A5\u53E3\u8FD4\u56DE\u72B6\u6001\u5F02\u5E38\uFF0Ccode=${String(record.code)}`;
100
+ }
101
+ }
102
+ return "";
103
+ }
104
+ function createWorkflowHost(ctx, dependencies = {}) {
105
+ let session = null;
106
+ let sessionContext = null;
107
+ const requireSession = dependencies.requireSession || ((innerCtx) => requireE10Session(innerCtx, { skipProfileEnrichment: true }));
108
+ async function ensureSession() {
109
+ if (!session) {
110
+ session = await requireSession(ctx);
111
+ const options = ctx.getGlobalOptions();
112
+ sessionContext = {
113
+ baseUrl: session.getBaseUrl(),
114
+ profile: options.profile || getActiveProfile(),
115
+ userId: session.userId,
116
+ agentType: session.agentType,
117
+ ...session.version ? { version: session.version } : {},
118
+ ...session.tenantKey ? { tenantKey: session.tenantKey } : {},
119
+ ...session.tenantName ? { tenantName: session.tenantName } : {},
120
+ ...session.department ? { department: session.department } : {},
121
+ ...session.subcompany ? { subcompany: session.subcompany } : {},
122
+ ...session.position ? { position: session.position } : {}
123
+ };
124
+ }
125
+ return session;
126
+ }
127
+ async function getSession() {
128
+ await ensureSession();
129
+ return sessionContext;
130
+ }
131
+ async function run(request, responseType) {
132
+ const {
133
+ method = "POST",
134
+ path,
135
+ query,
136
+ headers,
137
+ body,
138
+ form,
139
+ formData,
140
+ operation,
141
+ timeoutMs = DEFAULT_TIMEOUT_MS
142
+ } = request;
143
+ const runtime = createE10RequestRuntime(ctx, await ensureSession(), {
144
+ interceptors: dependencies.interceptors,
145
+ fetch: dependencies.fetch,
146
+ // 流程侧是唯一开启"请求带上网关会话票据(ZT_SESSION)"的调用方:登录时已把票存进 auth
147
+ // (`ztSession`),带上可让网关不再为每个请求重发票。没有票或票已过期时不附加,请求头与从前一致。
148
+ attachSessionTicket: true
149
+ });
150
+ let response;
151
+ try {
152
+ const base = { method, path, query, headers, body, form, formData, operation, timeoutMs, module: "workflow" };
153
+ response = responseType === "binary" ? await runtime.requestBinary(base) : await runtime.requestJson(base);
154
+ } catch (error) {
155
+ const structured = error;
156
+ if (structured?.type === "network") {
157
+ throw workflowNetworkError(
158
+ structured.subtype || "transport",
159
+ structured.message || "\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25",
160
+ { retryable: false, details: structured.details }
161
+ );
162
+ }
163
+ throw error;
164
+ }
165
+ if ("content" in response) {
166
+ if (isLoginExpired({}, response.status)) {
167
+ throw workflowAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, { httpStatus: response.status });
168
+ }
169
+ return {
170
+ status: response.status,
171
+ value: {},
172
+ content: response.content,
173
+ contentType: response.contentType
174
+ };
175
+ }
176
+ if (isLoginExpired(response.value, response.status)) {
177
+ throw workflowAuthError("session_expired", E10_SESSION_EXPIRED_MESSAGE, {
178
+ httpStatus: response.status,
179
+ details: { endpointKey: operation, response: response.value }
180
+ });
181
+ }
182
+ if (response.parseError) {
183
+ if (response.status < 200 || response.status >= 300) {
184
+ throw workflowApiError("http_error", `OA \u63A5\u53E3 HTTP ${response.status}`, {
185
+ code: response.status,
186
+ details: { status: response.status }
187
+ });
188
+ }
189
+ throw workflowNetworkError("protocol", `\u63A5\u53E3\u8FD4\u56DE\u4E0D\u662F\u5408\u6CD5 JSON\uFF08HTTP ${response.status}\uFF09`, { retryable: false });
190
+ }
191
+ if (response.status < 200 || response.status >= 300) {
192
+ throw workflowApiError("http_error", `OA \u63A5\u53E3 HTTP ${response.status}`, {
193
+ code: response.status,
194
+ details: { status: response.status }
195
+ });
196
+ }
197
+ if (request.tolerateBusinessError !== true) {
198
+ const businessError = extractApiBusinessError(response.value);
199
+ if (businessError) {
200
+ throw workflowApiError(
201
+ "business_error",
202
+ `OA \u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\uFF0C\u672C\u6B21\u64CD\u4F5C\u5DF2\u505C\u6B62\u3002\u63A5\u53E3\u63D0\u793A\uFF1A${businessError}\u3002\u5982\u679C\u60A8\u65E0\u6CD5\u5904\u7406\uFF0C\u8BF7\u8054\u7CFB\u7CFB\u7EDF\u7BA1\u7406\u5458\u3002`,
203
+ { details: { endpointKey: operation, businessError } }
204
+ );
205
+ }
206
+ }
207
+ return { status: response.status, value: response.value };
208
+ }
209
+ return {
210
+ async workflowRequest(request) {
211
+ const result = await run(request, "json");
212
+ return result.value;
213
+ },
214
+ async workflowBinaryRequest(request) {
215
+ const result = await run(request, "binary");
216
+ return {
217
+ content: result.content,
218
+ contentType: result.contentType || "application/octet-stream",
219
+ status: result.status
220
+ };
221
+ },
222
+ getSession
223
+ };
224
+ }
225
+
226
+ export {
227
+ isAtustRedirect,
228
+ isLoginExpired,
229
+ extractApiBusinessError,
230
+ createWorkflowHost
231
+ };
@@ -0,0 +1,371 @@
1
+ import { createRequire as __esbuildCreateRequire } from 'node:module';
2
+ const require = __esbuildCreateRequire(import.meta.url);
3
+
4
+ // src/shortcuts/im/operations/msg-parse.ts
5
+ var MSG_TYPES = {
6
+ 1: "\u6587\u672C",
7
+ 2: "\u56FE\u7247",
8
+ 3: "\u8BED\u97F3",
9
+ 4: "\u6587\u4EF6",
10
+ 5: "\u4F4D\u7F6E",
11
+ 6: "\u56FE\u6587",
12
+ 7: "\u89C6\u9891",
13
+ 8: "\u4E8B\u9879",
14
+ 9: "\u7CFB\u7EDF\u6D88\u606F",
15
+ 10: "\u64A4\u56DE",
16
+ 11: "\u6296\u4E00\u6296",
17
+ 12: "\u5C4F\u853D",
18
+ 14: "\u901A\u77E5",
19
+ 15: "\u81EA\u5B9A\u4E49",
20
+ 16: "\u8BED\u97F3\u901A\u8BDD",
21
+ 17: "\u804A\u5929\u8BB0\u5F55",
22
+ 18: "\u89C6\u9891\u901A\u8BDD",
23
+ 19: "\u7FA4\u516C\u544A",
24
+ 20: "\u5206\u4EAB\u5730\u5740",
25
+ 21: "\u8868\u60C5",
26
+ 22: "\u5F3A\u63D0\u9192",
27
+ 23: "\u94FE\u63A5",
28
+ 24: "\u7FA4\u63A5\u9F99",
29
+ 25: "+1\u56DE\u590D",
30
+ 26: "\u5BCC\u6587\u672C"
31
+ };
32
+ function getTypeName(type) {
33
+ const t = Number(type);
34
+ return MSG_TYPES[t] || "\u672A\u77E5";
35
+ }
36
+ function parseMsg(value) {
37
+ if (!value) return null;
38
+ if (typeof value === "string") {
39
+ try {
40
+ return JSON.parse(value);
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+ if (typeof value === "object") return value;
46
+ return null;
47
+ }
48
+ function normalizeKey(key) {
49
+ if (key.startsWith("%") && key.endsWith("%")) return key;
50
+ return `%${key}%`;
51
+ }
52
+ function formatPersonToken(value, nameMap) {
53
+ const uidRaw = value?.u !== void 0 && value.u !== null ? String(value.u) : value?.uid !== void 0 && value.uid !== null ? String(value.uid) : "";
54
+ const cRaw = value?.c !== void 0 && value.c !== null ? String(value.c) : "";
55
+ if (uidRaw && nameMap?.[uidRaw]) return nameMap[uidRaw];
56
+ if (uidRaw) return uidRaw;
57
+ return cRaw;
58
+ }
59
+ function formatI18nVal(value, nameMap) {
60
+ if (Array.isArray(value)) {
61
+ return value.map((item) => formatI18nVal(item, nameMap)).filter(Boolean).join("\u3001");
62
+ }
63
+ if (value && typeof value === "object") {
64
+ if (value.u !== void 0 || value.uid !== void 0) return formatPersonToken(value, nameMap);
65
+ return "";
66
+ }
67
+ if (value === void 0 || value === null) return "";
68
+ return String(value);
69
+ }
70
+ function substituteTemplate(template, kvs, jvs, nameMap) {
71
+ const merged = { ...kvs || {}, ...jvs || {} };
72
+ let text = String(template || "");
73
+ for (const [rawKey, value] of Object.entries(merged)) {
74
+ const key = normalizeKey(rawKey);
75
+ const replacement = formatI18nVal(value, nameMap);
76
+ text = text.split(key).join(replacement);
77
+ }
78
+ return text;
79
+ }
80
+ function collectMentionMap(msg) {
81
+ const map = /* @__PURE__ */ new Map();
82
+ const walk = (value) => {
83
+ if (!value || typeof value !== "object") return;
84
+ if (Array.isArray(value)) {
85
+ for (const item of value) walk(item);
86
+ return;
87
+ }
88
+ if (Array.isArray(value.aus)) {
89
+ for (const item of value.aus) {
90
+ if (item && item.id !== void 0 && item.id !== null && item.nm) map.set(String(item.id), String(item.nm));
91
+ }
92
+ }
93
+ for (const key of Object.keys(value)) {
94
+ if (key === "aus") continue;
95
+ walk(value[key]);
96
+ }
97
+ };
98
+ walk(msg);
99
+ return map;
100
+ }
101
+ function replaceMentions(text, mentionMap, nameMap) {
102
+ let output = String(text || "");
103
+ if (!output.includes(":@")) return output;
104
+ output = output.replace(/:@(\d{1,30});/g, (_, uidRaw) => {
105
+ const uid = uidRaw;
106
+ const name = mentionMap?.get(uid) || nameMap?.[uid] || uid;
107
+ return `@${name}`;
108
+ });
109
+ return output;
110
+ }
111
+ function extractTxt(seg, opts = {}) {
112
+ const txt = seg?.txt;
113
+ if (!txt) return "";
114
+ const mentionMap = opts.mentionMap ?? collectMentionMap(seg);
115
+ if (typeof txt === "string") return replaceMentions(txt, mentionMap, opts.nameMap);
116
+ if (typeof txt !== "object") return "";
117
+ if (txt.v !== void 0 && txt.v !== null && String(txt.v) !== "") {
118
+ return replaceMentions(String(txt.v), mentionMap, opts.nameMap);
119
+ }
120
+ const kvs = txt.kvs || {};
121
+ const jvs = txt.jvs || {};
122
+ if (txt.i18n && typeof txt.i18n === "string" && txt.i18n.includes("%")) {
123
+ return replaceMentions(substituteTemplate(txt.i18n, kvs, jvs, opts.nameMap), mentionMap, opts.nameMap);
124
+ }
125
+ if (txt.id18n !== void 0 && txt.id18n !== null) {
126
+ const translated = opts.i18nMap?.[String(txt.id18n)];
127
+ if (translated) {
128
+ return replaceMentions(substituteTemplate(translated, kvs, jvs, opts.nameMap), mentionMap, opts.nameMap);
129
+ }
130
+ }
131
+ if (txt.i18n && typeof txt.i18n === "string") {
132
+ return replaceMentions(substituteTemplate(txt.i18n, kvs, jvs, opts.nameMap), mentionMap, opts.nameMap);
133
+ }
134
+ return "";
135
+ }
136
+ function parseSysMsg(msg) {
137
+ const sys = msg?.dt?.[0]?.sys;
138
+ if (!sys) return {};
139
+ return {
140
+ group: sys.group !== void 0 ? String(sys.group) : void 0,
141
+ type: sys.type !== void 0 ? String(sys.type) : void 0,
142
+ tpl: sys.tpl !== void 0 ? String(sys.tpl) : void 0,
143
+ etName: sys.et?.nm !== void 0 && sys.et.nm !== null ? String(sys.et.nm) : void 0,
144
+ id18n: sys.id18n !== void 0 ? String(sys.id18n) : void 0
145
+ };
146
+ }
147
+ function parseContent(value, opts = {}) {
148
+ const msg = parseMsg(value) || {};
149
+ const type = Number(msg.type || 0);
150
+ const typeName = getTypeName(type);
151
+ const dt = Array.isArray(msg.dt) ? msg.dt : [];
152
+ const data = dt[0] || {};
153
+ const sys = parseSysMsg(msg);
154
+ const tf = Number(msg.tf || 0);
155
+ const must = (tf & 1) !== 0;
156
+ const localOpts = { ...opts, mentionMap: opts.mentionMap ?? collectMentionMap(msg) };
157
+ let content = "";
158
+ let fileName = "";
159
+ switch (type) {
160
+ case 1:
161
+ content = extractTxt(data, localOpts);
162
+ break;
163
+ case 2: {
164
+ content = parseSegment(data, localOpts) || "[\u56FE\u7247]";
165
+ fileName = data?.img?.nm ? String(data.img.nm) : "";
166
+ break;
167
+ }
168
+ case 4:
169
+ fileName = data?.file?.nm ? String(data.file.nm) : "";
170
+ content = fileName ? `[\u6587\u4EF6]${fileName}` : "[\u6587\u4EF6]";
171
+ break;
172
+ case 7: {
173
+ content = parseSegment(data, localOpts) || "[\u89C6\u9891]";
174
+ fileName = data?.media?.nm ? String(data.media.nm) : data?.video?.nm ? String(data.video.nm) : "";
175
+ break;
176
+ }
177
+ case 5:
178
+ content = data?.location?.name ? String(data.location.name) : "";
179
+ break;
180
+ case 8:
181
+ content = data?.entity?.entityName ? String(data.entity.entityName) : "";
182
+ break;
183
+ case 20:
184
+ content = data?.shareaddr?.name ? String(data.shareaddr.name) : extractTxt(data, localOpts);
185
+ break;
186
+ case 26:
187
+ content = msg.vv ? String(msg.vv) : dt.map((d) => parseSegment(d, localOpts)).join("");
188
+ break;
189
+ default:
190
+ content = extractTxt(data, localOpts);
191
+ }
192
+ if (sys.tpl === "1" && sys.etName) content = sys.etName;
193
+ if (content && String(content).includes(":@")) {
194
+ content = replaceMentions(content, localOpts.mentionMap, localOpts.nameMap);
195
+ }
196
+ if (must) content = `[\u5FC5\u8FBE]${content}`;
197
+ let title = "";
198
+ if (sys.etName) title = sys.etName;
199
+ else if (sys.id18n && opts.i18nMap?.[sys.id18n]) title = opts.i18nMap[sys.id18n];
200
+ return { type, typeName, content, title, must, fileName, sys };
201
+ }
202
+ function parseSegment(seg, opts = {}) {
203
+ if (!seg) return "";
204
+ const name = (value) => value?.nm !== void 0 && value.nm !== null ? String(value.nm) : "";
205
+ const hasFileId = (value) => Boolean(value) && (value.src !== void 0 || value.id !== void 0 || value.nm !== void 0);
206
+ if (hasFileId(seg.img)) return `[\u56FE\u7247]${name(seg.img)}`;
207
+ if (hasFileId(seg.file)) return `[\u6587\u4EF6]${name(seg.file)}`;
208
+ if (hasFileId(seg.video)) return `[\u89C6\u9891]${name(seg.video)}`;
209
+ if (hasFileId(seg.media)) return `[\u89C6\u9891]${name(seg.media)}`;
210
+ if (hasFileId(seg.voice)) return `[\u8BED\u97F3]${name(seg.voice)}`;
211
+ if (seg.location?.name) return String(seg.location.name);
212
+ if (seg.txt) return extractTxt(seg, opts);
213
+ return "";
214
+ }
215
+ function senderName(msg, fromUid, authUid, nameMap = {}) {
216
+ const uid = String(fromUid ?? "");
217
+ if (authUid && uid === authUid) return "\u6211";
218
+ const sname = msg?.sname ? String(msg.sname) : "";
219
+ if (sname) return sname;
220
+ if (uid && nameMap[uid]) return nameMap[uid];
221
+ if (uid) return uid;
222
+ return "";
223
+ }
224
+ function extractImgs(msg) {
225
+ const dt = Array.isArray(msg?.dt) ? msg.dt : [];
226
+ const items = [];
227
+ for (const seg of dt) {
228
+ const img = seg?.img;
229
+ if (!img) continue;
230
+ const fileId = img.src !== void 0 && img.src !== null ? String(img.src) : img.id !== void 0 ? String(img.id) : "";
231
+ if (!fileId) continue;
232
+ items.push({
233
+ fileId,
234
+ name: img.nm !== void 0 ? String(img.nm) : "",
235
+ w: img.w !== void 0 ? String(img.w) : void 0,
236
+ h: img.h !== void 0 ? String(img.h) : void 0,
237
+ size: img.s !== void 0 ? String(img.s) : void 0,
238
+ mime: img.t !== void 0 ? String(img.t) : void 0
239
+ });
240
+ }
241
+ return items;
242
+ }
243
+ function extractVideos(msg) {
244
+ const dt = Array.isArray(msg?.dt) ? msg.dt : [];
245
+ const items = [];
246
+ for (const seg of dt) {
247
+ const media = seg?.media || seg?.video;
248
+ if (!media) continue;
249
+ const fileId = media.src !== void 0 && media.src !== null ? String(media.src) : media.id !== void 0 ? String(media.id) : "";
250
+ if (!fileId) continue;
251
+ items.push({
252
+ fileId,
253
+ name: media.nm !== void 0 ? String(media.nm) : "",
254
+ ext: media.ext !== void 0 ? String(media.ext) : void 0,
255
+ w: media.w !== void 0 ? String(media.w) : void 0,
256
+ h: media.h !== void 0 ? String(media.h) : void 0,
257
+ size: media.s !== void 0 ? String(media.s) : void 0,
258
+ mime: media.t !== void 0 ? String(media.t) : void 0
259
+ });
260
+ }
261
+ return items;
262
+ }
263
+ function extractFiles(msg) {
264
+ const dt = Array.isArray(msg?.dt) ? msg.dt : [];
265
+ const items = [];
266
+ for (const seg of dt) {
267
+ const file = seg?.file;
268
+ if (!file) continue;
269
+ const fileId = file.id !== void 0 && file.id !== null ? String(file.id) : file.src !== void 0 ? String(file.src) : "";
270
+ if (!fileId) continue;
271
+ items.push({
272
+ fileId,
273
+ name: file.nm !== void 0 ? String(file.nm) : "",
274
+ ext: file.ext !== void 0 ? String(file.ext) : void 0,
275
+ size: file.s !== void 0 ? String(file.s) : void 0,
276
+ mime: file.t !== void 0 ? String(file.t) : void 0
277
+ });
278
+ }
279
+ return items;
280
+ }
281
+ function walkCollect(value, kind, out) {
282
+ if (value === void 0 || value === null) return;
283
+ if (Array.isArray(value)) {
284
+ for (const item of value) walkCollect(item, kind, out);
285
+ return;
286
+ }
287
+ if (typeof value === "object") {
288
+ for (const key of Object.keys(value)) {
289
+ const child = value[key];
290
+ if (kind === "id18n" && key === "id18n" && child !== void 0 && child !== null && /^\d+$/.test(String(child))) {
291
+ out.add(String(child));
292
+ continue;
293
+ }
294
+ if (kind === "person") {
295
+ if ((key === "u" || key === "uid") && child !== void 0 && child !== null) {
296
+ const uid = String(child);
297
+ if (/^\d+$/.test(uid)) out.add(uid);
298
+ continue;
299
+ }
300
+ if (key === "fd" && child === "@") {
301
+ const id = value.id;
302
+ if (id !== void 0 && id !== null) out.add(String(id));
303
+ continue;
304
+ }
305
+ if (key === "txt" && typeof child === "string") {
306
+ const matches = child.match(/:@(\d+);/g);
307
+ if (matches) {
308
+ for (const m of matches) {
309
+ const uid = m.slice(2, -1);
310
+ if (/^\d+$/.test(uid)) out.add(uid);
311
+ }
312
+ }
313
+ continue;
314
+ }
315
+ }
316
+ walkCollect(child, kind, out);
317
+ }
318
+ return;
319
+ }
320
+ if (kind === "person" && typeof value === "string") {
321
+ const matches = value.match(/:@(\d+);/g);
322
+ if (matches) {
323
+ for (const m of matches) {
324
+ const uid = m.slice(2, -1);
325
+ if (/^\d+$/.test(uid)) out.add(uid);
326
+ }
327
+ }
328
+ }
329
+ }
330
+ function collectI18nIds(msgs) {
331
+ const out = /* @__PURE__ */ new Set();
332
+ for (const item of msgs) {
333
+ const msg = parseMsg(item?.msg);
334
+ if (msg) walkCollect(msg, "id18n", out);
335
+ }
336
+ return [...out];
337
+ }
338
+ function collectPersonIds(msgs) {
339
+ const out = /* @__PURE__ */ new Set();
340
+ for (const item of msgs) {
341
+ const msg = parseMsg(item?.msg);
342
+ if (msg) walkCollect(msg, "person", out);
343
+ }
344
+ return [...out];
345
+ }
346
+ function collapseNewlines(text) {
347
+ return String(text || "").replace(/\r\n+/g, "\n").replace(/\n+/g, "\u23CE");
348
+ }
349
+ function escapePipe(text) {
350
+ return String(text || "").replace(/\|/g, "\\|");
351
+ }
352
+
353
+ export {
354
+ MSG_TYPES,
355
+ getTypeName,
356
+ parseMsg,
357
+ substituteTemplate,
358
+ collectMentionMap,
359
+ replaceMentions,
360
+ extractTxt,
361
+ parseSysMsg,
362
+ parseContent,
363
+ senderName,
364
+ extractImgs,
365
+ extractVideos,
366
+ extractFiles,
367
+ collectI18nIds,
368
+ collectPersonIds,
369
+ collapseNewlines,
370
+ escapePipe
371
+ };