openclaw-multi-auto 1.5.2 → 1.5.4

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/{audio-preflight-5FEeDooz.js → audio-preflight-DDBLZBdb.js} +4 -4
  2. package/dist/{audio-transcription-runner-B-UvoDjZ.js → audio-transcription-runner-DZbSWT9E.js} +1 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  5. package/dist/{chrome-D45SyhQL.js → chrome-CMU2WVFh.js} +8 -8
  6. package/dist/{deliver-B9cys0EZ.js → deliver-BXVcFIHL.js} +1 -1
  7. package/dist/{deliver-runtime-DhaQJ0pI.js → deliver-runtime-DTaIS-1i.js} +3 -3
  8. package/dist/{deps-send-whatsapp.runtime-DvTL2tzN.js → deps-send-whatsapp.runtime-CIZqFAqb.js} +7 -7
  9. package/dist/extensionAPI.js +6 -6
  10. package/dist/{image-DAOPwVXi.js → image-BCVLo0qw.js} +1 -1
  11. package/dist/{image-runtime-wlCLVvVv.js → image-runtime-DtCKpMPZ.js} +3 -3
  12. package/dist/{pi-embedded-DYU79yGe.js → pi-embedded-CgQ_W6Xs.js} +24 -24
  13. package/dist/{pi-embedded-helpers-uTRAmQ4n.js → pi-embedded-helpers-CwuBTKza.js} +3 -3
  14. package/dist/plugin-sdk/accounts-CJWOBzwB.js +35 -0
  15. package/dist/plugin-sdk/accounts-DP1-L-QS.js +288 -0
  16. package/dist/plugin-sdk/accounts-DZhWlEg3.js +46 -0
  17. package/dist/plugin-sdk/active-listener-B_sLJTXM.js +50 -0
  18. package/dist/plugin-sdk/api-key-rotation-BRE4X2tf.js +181 -0
  19. package/dist/plugin-sdk/audio-preflight-DGEUDxxR.js +69 -0
  20. package/dist/plugin-sdk/audio-transcription-runner-DkoPNPYt.js +2176 -0
  21. package/dist/plugin-sdk/audit-membership-runtime-DSBHHw7o.js +58 -0
  22. package/dist/plugin-sdk/bluebubbles.js +2 -2
  23. package/dist/plugin-sdk/channel-activity-F3d0yUwy.js +94 -0
  24. package/dist/plugin-sdk/channel-web-QF7EpjeP.js +2256 -0
  25. package/dist/plugin-sdk/chrome-BXoCyCkY.js +2415 -0
  26. package/dist/plugin-sdk/commands-registry-t7cXBTfN.js +1125 -0
  27. package/dist/plugin-sdk/config-BkEnz2Po.js +17913 -0
  28. package/dist/plugin-sdk/deliver-B6AG_l67.js +1694 -0
  29. package/dist/plugin-sdk/deliver-runtime-D585kJZc.js +32 -0
  30. package/dist/plugin-sdk/deps-send-discord.runtime-a_OKY2js.js +23 -0
  31. package/dist/plugin-sdk/deps-send-imessage.runtime-Baxy9TD4.js +22 -0
  32. package/dist/plugin-sdk/deps-send-signal.runtime-BwXoCrFl.js +21 -0
  33. package/dist/plugin-sdk/deps-send-slack.runtime-CLmKjgso.js +19 -0
  34. package/dist/plugin-sdk/deps-send-telegram.runtime-BKfdBKnZ.js +24 -0
  35. package/dist/plugin-sdk/deps-send-whatsapp.runtime-BOTwkbx_.js +57 -0
  36. package/dist/plugin-sdk/diagnostic-CsP-lEkI.js +319 -0
  37. package/dist/plugin-sdk/errors-DaiAM-yU.js +54 -0
  38. package/dist/plugin-sdk/fetch-guard-DETCcJzQ.js +156 -0
  39. package/dist/plugin-sdk/fs-safe-B8y811FR.js +352 -0
  40. package/dist/plugin-sdk/image-DjTEkYZE.js +2310 -0
  41. package/dist/plugin-sdk/image-ops-BSiMpAw4.js +584 -0
  42. package/dist/plugin-sdk/image-runtime-6xPp8m5a.js +25 -0
  43. package/dist/plugin-sdk/index.js +50 -50
  44. package/dist/plugin-sdk/ir-DQ7_HbvK.js +1296 -0
  45. package/dist/plugin-sdk/irc.js +2 -2
  46. package/dist/plugin-sdk/local-roots-BUP4YBmR.js +186 -0
  47. package/dist/plugin-sdk/logger-CZY9KIoY.js +1163 -0
  48. package/dist/plugin-sdk/login-BxEKLlCo.js +57 -0
  49. package/dist/plugin-sdk/login-qr-BQIpMPr9.js +320 -0
  50. package/dist/plugin-sdk/manager-I6KbPihW.js +3917 -0
  51. package/dist/plugin-sdk/manager-runtime-CFfYYWIQ.js +15 -0
  52. package/dist/plugin-sdk/outbound-NS6UHnB6.js +212 -0
  53. package/dist/plugin-sdk/outbound-attachment-Dy6fyf6H.js +19 -0
  54. package/dist/plugin-sdk/path-alias-guards-DBjLbIX_.js +43 -0
  55. package/dist/plugin-sdk/paths-vTM3Lh3X.js +166 -0
  56. package/dist/plugin-sdk/pi-embedded-helpers-1R1gu7eX.js +9627 -0
  57. package/dist/plugin-sdk/pi-model-discovery-runtime-Do9o-dUd.js +8 -0
  58. package/dist/plugin-sdk/pi-model-discovery-v-XPUOOf.js +134 -0
  59. package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-D4sFsIks.js +354 -0
  60. package/dist/plugin-sdk/plugins-DeBZB9l_.js +864 -0
  61. package/dist/plugin-sdk/proxy-fetch-ChxOhWF4.js +38 -0
  62. package/dist/plugin-sdk/pw-ai-DEOmCSSC.js +1938 -0
  63. package/dist/plugin-sdk/qmd-manager-HyYKoEch.js +1448 -0
  64. package/dist/plugin-sdk/query-expansion-CeyKUeDW.js +1011 -0
  65. package/dist/plugin-sdk/redact-DjVX-1N3.js +319 -0
  66. package/dist/plugin-sdk/reply-DAo_Jt8K.js +97916 -0
  67. package/dist/plugin-sdk/resolve-outbound-target-B42qgQS9.js +40 -0
  68. package/dist/plugin-sdk/run-with-concurrency-Bt_ks0Qa.js +1994 -0
  69. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-B6W989eF.js +10 -0
  70. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-c_GDFy37.js +19 -0
  71. package/dist/plugin-sdk/send-CQpMudwO.js +2587 -0
  72. package/dist/plugin-sdk/send-DQHLzVyO.js +414 -0
  73. package/dist/plugin-sdk/send-DTB24bEF.js +3135 -0
  74. package/dist/plugin-sdk/send-DfHadjZ_.js +503 -0
  75. package/dist/plugin-sdk/send-XXlW2iny.js +540 -0
  76. package/dist/plugin-sdk/session-6TF6MyaC.js +169 -0
  77. package/dist/plugin-sdk/skill-commands-CkGeFUMl.js +342 -0
  78. package/dist/plugin-sdk/skills-CBkHBYPq.js +1428 -0
  79. package/dist/plugin-sdk/slash-commands.runtime-CxliuGaP.js +13 -0
  80. package/dist/plugin-sdk/slash-dispatch.runtime-DFaeYlJQ.js +52 -0
  81. package/dist/plugin-sdk/slash-skill-commands.runtime-0M0OLCxq.js +16 -0
  82. package/dist/plugin-sdk/ssrf-cFtplYtS.js +202 -0
  83. package/dist/plugin-sdk/store-5nyxY3WU.js +81 -0
  84. package/dist/plugin-sdk/subagent-registry-runtime-DCtmDwna.js +52 -0
  85. package/dist/plugin-sdk/tables-C47P4GTN.js +55 -0
  86. package/dist/plugin-sdk/target-errors-Blia4S69.js +195 -0
  87. package/dist/plugin-sdk/thinking-Bo2eosVa.js +1206 -0
  88. package/dist/plugin-sdk/tokens-DgNRBwIg.js +52 -0
  89. package/dist/plugin-sdk/tool-images-Gk_-0y2N.js +274 -0
  90. package/dist/plugin-sdk/web-CVxZbXyH.js +56 -0
  91. package/dist/plugin-sdk/whatsapp-actions-Bw0H9g-n.js +80 -0
  92. package/dist/{pw-ai-GcYO6HPE.js → pw-ai-CmphSzHx.js} +1 -1
  93. package/dist/{slash-dispatch.runtime-Dh053pQK.js → slash-dispatch.runtime-131yup2e.js} +6 -6
  94. package/dist/{subagent-registry-runtime-DSi5mnCQ.js → subagent-registry-runtime-DbSf_Je6.js} +6 -6
  95. package/dist/{web-1hWJDzNA.js → web-MR9d7KyB.js} +6 -6
  96. package/package.json +1 -1
  97. package/scripts/create-instance.sh +1 -37
  98. package/scripts/npm_publish.sh +0 -65
  99. package/scripts/npm_publish_backup.sh +185 -0
  100. package/extensions/page-action-cache/dist/actions-executor.d.ts +0 -62
  101. package/extensions/page-action-cache/dist/actions-executor.d.ts.map +0 -1
  102. package/extensions/page-action-cache/dist/actions-executor.js +0 -339
  103. package/extensions/page-action-cache/dist/actions-executor.js.map +0 -1
  104. package/extensions/page-action-cache/dist/cache-invalidator.d.ts +0 -70
  105. package/extensions/page-action-cache/dist/cache-invalidator.d.ts.map +0 -1
  106. package/extensions/page-action-cache/dist/cache-invalidator.js +0 -212
  107. package/extensions/page-action-cache/dist/cache-invalidator.js.map +0 -1
  108. package/extensions/page-action-cache/dist/cache-store.d.ts +0 -80
  109. package/extensions/page-action-cache/dist/cache-store.d.ts.map +0 -1
  110. package/extensions/page-action-cache/dist/cache-store.js +0 -361
  111. package/extensions/page-action-cache/dist/cache-store.js.map +0 -1
  112. package/extensions/page-action-cache/dist/cache-strategy.d.ts +0 -65
  113. package/extensions/page-action-cache/dist/cache-strategy.d.ts.map +0 -1
  114. package/extensions/page-action-cache/dist/cache-strategy.js +0 -237
  115. package/extensions/page-action-cache/dist/cache-strategy.js.map +0 -1
  116. package/extensions/page-action-cache/dist/hooks-entry.d.ts +0 -29
  117. package/extensions/page-action-cache/dist/hooks-entry.d.ts.map +0 -1
  118. package/extensions/page-action-cache/dist/hooks-entry.js +0 -83
  119. package/extensions/page-action-cache/dist/hooks-entry.js.map +0 -1
  120. package/extensions/page-action-cache/dist/hooks.d.ts +0 -10
  121. package/extensions/page-action-cache/dist/hooks.d.ts.map +0 -1
  122. package/extensions/page-action-cache/dist/hooks.js +0 -277
  123. package/extensions/page-action-cache/dist/hooks.js.map +0 -1
  124. package/extensions/page-action-cache/dist/index.d.ts +0 -24
  125. package/extensions/page-action-cache/dist/index.d.ts.map +0 -1
  126. package/extensions/page-action-cache/dist/index.js +0 -34
  127. package/extensions/page-action-cache/dist/index.js.map +0 -1
  128. package/extensions/page-action-cache/dist/scenario-recognizer.d.ts +0 -45
  129. package/extensions/page-action-cache/dist/scenario-recognizer.d.ts.map +0 -1
  130. package/extensions/page-action-cache/dist/scenario-recognizer.js +0 -213
  131. package/extensions/page-action-cache/dist/scenario-recognizer.js.map +0 -1
  132. package/extensions/page-action-cache/dist/security-policy.d.ts +0 -62
  133. package/extensions/page-action-cache/dist/security-policy.d.ts.map +0 -1
  134. package/extensions/page-action-cache/dist/security-policy.js +0 -219
  135. package/extensions/page-action-cache/dist/security-policy.js.map +0 -1
  136. package/extensions/page-action-cache/dist/tools.d.ts +0 -209
  137. package/extensions/page-action-cache/dist/tools.d.ts.map +0 -1
  138. package/extensions/page-action-cache/dist/tools.js +0 -383
  139. package/extensions/page-action-cache/dist/tools.js.map +0 -1
  140. package/extensions/page-action-cache/dist/types.d.ts +0 -336
  141. package/extensions/page-action-cache/dist/types.d.ts.map +0 -1
  142. package/extensions/page-action-cache/dist/types.js +0 -8
  143. package/extensions/page-action-cache/dist/types.js.map +0 -1
  144. package/extensions/page-action-cache/dist/ux-enhancer.d.ts +0 -60
  145. package/extensions/page-action-cache/dist/ux-enhancer.d.ts.map +0 -1
  146. package/extensions/page-action-cache/dist/ux-enhancer.js +0 -218
  147. package/extensions/page-action-cache/dist/ux-enhancer.js.map +0 -1
  148. package/extensions/page-action-cache/dist/variable-resolver.d.ts +0 -28
  149. package/extensions/page-action-cache/dist/variable-resolver.d.ts.map +0 -1
  150. package/extensions/page-action-cache/dist/variable-resolver.js +0 -201
  151. package/extensions/page-action-cache/dist/variable-resolver.js.map +0 -1
  152. package/extensions/page-action-cache/docs/API.md +0 -555
  153. package/extensions/page-action-cache/docs/IMPLEMENTATION.md +0 -1792
  154. package/extensions/page-action-cache/docs/INTEGRATION.md +0 -387
  155. package/extensions/page-action-cache/docs/README.md +0 -183
  156. package/extensions/page-action-cache/index.ts +0 -118
  157. package/extensions/page-action-cache/node_modules/.bin/nlc +0 -21
  158. package/extensions/page-action-cache/node_modules/.bin/node-llama-cpp +0 -21
  159. package/extensions/page-action-cache/node_modules/.bin/openclaw +0 -21
  160. package/extensions/page-action-cache/node_modules/.bin/tsc +0 -21
  161. package/extensions/page-action-cache/node_modules/.bin/tsserver +0 -21
  162. package/extensions/page-action-cache/node_modules/.bin/vitest +0 -21
  163. package/extensions/page-action-cache/openclaw.plugin.json +0 -208
  164. package/extensions/page-action-cache/package.json +0 -74
  165. package/extensions/page-action-cache/scripts/npm_publish.sh +0 -80
  166. package/extensions/page-action-cache/skills/page-action-cache/SKILL.md +0 -216
  167. package/extensions/page-action-cache/src/actions-executor.ts +0 -441
  168. package/extensions/page-action-cache/src/cache-invalidator.ts +0 -271
  169. package/extensions/page-action-cache/src/cache-store.ts +0 -457
  170. package/extensions/page-action-cache/src/cache-strategy.ts +0 -327
  171. package/extensions/page-action-cache/src/hooks-entry.ts +0 -114
  172. package/extensions/page-action-cache/src/hooks.ts +0 -332
  173. package/extensions/page-action-cache/src/index.ts +0 -89
  174. package/extensions/page-action-cache/src/scenario-recognizer.ts +0 -259
  175. package/extensions/page-action-cache/src/security-policy.ts +0 -268
  176. package/extensions/page-action-cache/src/tools.ts +0 -437
  177. package/extensions/page-action-cache/src/types.ts +0 -482
  178. package/extensions/page-action-cache/src/ux-enhancer.ts +0 -266
  179. package/extensions/page-action-cache/src/variable-resolver.ts +0 -258
  180. package/extensions/page-action-cache/tests/actions-executor.test.ts +0 -424
  181. package/extensions/page-action-cache/tests/cache-store.test.ts +0 -267
  182. package/extensions/page-action-cache/tests/integration-test.ts +0 -62
  183. package/extensions/page-action-cache/tests/scenario-recognizer.test.ts +0 -140
  184. package/extensions/page-action-cache/tests/variable-resolver.test.ts +0 -187
  185. package/extensions/page-action-cache/tsconfig.json +0 -39
@@ -0,0 +1,584 @@
1
+ import { O as runExec } from "./run-with-concurrency-Bt_ks0Qa.js";
2
+ import { Ct as normalizeChatChannelId, _t as CHANNEL_IDS, wt as getActivePluginRegistry } from "./config-BkEnz2Po.js";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import fs from "node:fs/promises";
6
+ import { fileTypeFromBuffer } from "file-type";
7
+
8
+ //#region src/gateway/protocol/client-info.ts
9
+ const GATEWAY_CLIENT_IDS = {
10
+ WEBCHAT_UI: "webchat-ui",
11
+ CONTROL_UI: "openclaw-control-ui",
12
+ WEBCHAT: "webchat",
13
+ CLI: "cli",
14
+ GATEWAY_CLIENT: "gateway-client",
15
+ MACOS_APP: "openclaw-macos",
16
+ IOS_APP: "openclaw-ios",
17
+ ANDROID_APP: "openclaw-android",
18
+ NODE_HOST: "node-host",
19
+ TEST: "test",
20
+ FINGERPRINT: "fingerprint",
21
+ PROBE: "openclaw-probe"
22
+ };
23
+ const GATEWAY_CLIENT_NAMES = GATEWAY_CLIENT_IDS;
24
+ const GATEWAY_CLIENT_MODES = {
25
+ WEBCHAT: "webchat",
26
+ CLI: "cli",
27
+ UI: "ui",
28
+ BACKEND: "backend",
29
+ NODE: "node",
30
+ PROBE: "probe",
31
+ TEST: "test"
32
+ };
33
+ const GATEWAY_CLIENT_ID_SET = new Set(Object.values(GATEWAY_CLIENT_IDS));
34
+ const GATEWAY_CLIENT_MODE_SET = new Set(Object.values(GATEWAY_CLIENT_MODES));
35
+
36
+ //#endregion
37
+ //#region src/utils/message-channel.ts
38
+ const INTERNAL_MESSAGE_CHANNEL = "webchat";
39
+ const MARKDOWN_CAPABLE_CHANNELS = new Set([
40
+ "slack",
41
+ "telegram",
42
+ "signal",
43
+ "discord",
44
+ "googlechat",
45
+ "tui",
46
+ INTERNAL_MESSAGE_CHANNEL
47
+ ]);
48
+ function isInternalMessageChannel(raw) {
49
+ return normalizeMessageChannel(raw) === INTERNAL_MESSAGE_CHANNEL;
50
+ }
51
+ function normalizeMessageChannel(raw) {
52
+ const normalized = raw?.trim().toLowerCase();
53
+ if (!normalized) return;
54
+ if (normalized === INTERNAL_MESSAGE_CHANNEL) return INTERNAL_MESSAGE_CHANNEL;
55
+ const builtIn = normalizeChatChannelId(normalized);
56
+ if (builtIn) return builtIn;
57
+ return (getActivePluginRegistry()?.channels.find((entry) => {
58
+ if (entry.plugin.id.toLowerCase() === normalized) return true;
59
+ return (entry.plugin.meta.aliases ?? []).some((alias) => alias.trim().toLowerCase() === normalized);
60
+ }))?.plugin.id ?? normalized;
61
+ }
62
+ const listPluginChannelIds = () => {
63
+ const registry = getActivePluginRegistry();
64
+ if (!registry) return [];
65
+ return registry.channels.map((entry) => entry.plugin.id);
66
+ };
67
+ const listDeliverableMessageChannels = () => Array.from(new Set([...CHANNEL_IDS, ...listPluginChannelIds()]));
68
+ const listGatewayMessageChannels = () => [...listDeliverableMessageChannels(), INTERNAL_MESSAGE_CHANNEL];
69
+ function isGatewayMessageChannel(value) {
70
+ return listGatewayMessageChannels().includes(value);
71
+ }
72
+ function isDeliverableMessageChannel(value) {
73
+ return listDeliverableMessageChannels().includes(value);
74
+ }
75
+ function resolveGatewayMessageChannel(raw) {
76
+ const normalized = normalizeMessageChannel(raw);
77
+ if (!normalized) return;
78
+ return isGatewayMessageChannel(normalized) ? normalized : void 0;
79
+ }
80
+ function resolveMessageChannel(primary, fallback) {
81
+ return normalizeMessageChannel(primary) ?? normalizeMessageChannel(fallback);
82
+ }
83
+ function isMarkdownCapableMessageChannel(raw) {
84
+ const channel = normalizeMessageChannel(raw);
85
+ if (!channel) return false;
86
+ return MARKDOWN_CAPABLE_CHANNELS.has(channel);
87
+ }
88
+
89
+ //#endregion
90
+ //#region src/media/constants.ts
91
+ const MAX_IMAGE_BYTES = 6 * 1024 * 1024;
92
+ const MAX_AUDIO_BYTES = 16 * 1024 * 1024;
93
+ const MAX_VIDEO_BYTES = 16 * 1024 * 1024;
94
+ const MAX_DOCUMENT_BYTES = 100 * 1024 * 1024;
95
+ function mediaKindFromMime(mime) {
96
+ if (!mime) return "unknown";
97
+ if (mime.startsWith("image/")) return "image";
98
+ if (mime.startsWith("audio/")) return "audio";
99
+ if (mime.startsWith("video/")) return "video";
100
+ if (mime === "application/pdf") return "document";
101
+ if (mime.startsWith("text/")) return "document";
102
+ if (mime.startsWith("application/")) return "document";
103
+ return "unknown";
104
+ }
105
+ function maxBytesForKind(kind) {
106
+ switch (kind) {
107
+ case "image": return MAX_IMAGE_BYTES;
108
+ case "audio": return MAX_AUDIO_BYTES;
109
+ case "video": return MAX_VIDEO_BYTES;
110
+ case "document": return MAX_DOCUMENT_BYTES;
111
+ default: return MAX_DOCUMENT_BYTES;
112
+ }
113
+ }
114
+
115
+ //#endregion
116
+ //#region src/media/mime.ts
117
+ const EXT_BY_MIME = {
118
+ "image/heic": ".heic",
119
+ "image/heif": ".heif",
120
+ "image/jpeg": ".jpg",
121
+ "image/png": ".png",
122
+ "image/webp": ".webp",
123
+ "image/gif": ".gif",
124
+ "audio/ogg": ".ogg",
125
+ "audio/mpeg": ".mp3",
126
+ "audio/x-m4a": ".m4a",
127
+ "audio/mp4": ".m4a",
128
+ "video/mp4": ".mp4",
129
+ "video/quicktime": ".mov",
130
+ "application/pdf": ".pdf",
131
+ "application/json": ".json",
132
+ "application/zip": ".zip",
133
+ "application/gzip": ".gz",
134
+ "application/x-tar": ".tar",
135
+ "application/x-7z-compressed": ".7z",
136
+ "application/vnd.rar": ".rar",
137
+ "application/msword": ".doc",
138
+ "application/vnd.ms-excel": ".xls",
139
+ "application/vnd.ms-powerpoint": ".ppt",
140
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
141
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
142
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",
143
+ "text/csv": ".csv",
144
+ "text/plain": ".txt",
145
+ "text/markdown": ".md"
146
+ };
147
+ const MIME_BY_EXT = {
148
+ ...Object.fromEntries(Object.entries(EXT_BY_MIME).map(([mime, ext]) => [ext, mime])),
149
+ ".jpeg": "image/jpeg",
150
+ ".js": "text/javascript"
151
+ };
152
+ const AUDIO_FILE_EXTENSIONS = new Set([
153
+ ".aac",
154
+ ".caf",
155
+ ".flac",
156
+ ".m4a",
157
+ ".mp3",
158
+ ".oga",
159
+ ".ogg",
160
+ ".opus",
161
+ ".wav"
162
+ ]);
163
+ function normalizeMimeType(mime) {
164
+ if (!mime) return;
165
+ return mime.split(";")[0]?.trim().toLowerCase() || void 0;
166
+ }
167
+ async function sniffMime(buffer) {
168
+ if (!buffer) return;
169
+ try {
170
+ return (await fileTypeFromBuffer(buffer))?.mime ?? void 0;
171
+ } catch {
172
+ return;
173
+ }
174
+ }
175
+ function getFileExtension(filePath) {
176
+ if (!filePath) return;
177
+ try {
178
+ if (/^https?:\/\//i.test(filePath)) {
179
+ const url = new URL(filePath);
180
+ return path.extname(url.pathname).toLowerCase() || void 0;
181
+ }
182
+ } catch {}
183
+ return path.extname(filePath).toLowerCase() || void 0;
184
+ }
185
+ function isAudioFileName(fileName) {
186
+ const ext = getFileExtension(fileName);
187
+ if (!ext) return false;
188
+ return AUDIO_FILE_EXTENSIONS.has(ext);
189
+ }
190
+ function detectMime(opts) {
191
+ return detectMimeImpl(opts);
192
+ }
193
+ function isGenericMime(mime) {
194
+ if (!mime) return true;
195
+ const m = mime.toLowerCase();
196
+ return m === "application/octet-stream" || m === "application/zip";
197
+ }
198
+ async function detectMimeImpl(opts) {
199
+ const ext = getFileExtension(opts.filePath);
200
+ const extMime = ext ? MIME_BY_EXT[ext] : void 0;
201
+ const headerMime = normalizeMimeType(opts.headerMime);
202
+ const sniffed = await sniffMime(opts.buffer);
203
+ if (sniffed && (!isGenericMime(sniffed) || !extMime)) return sniffed;
204
+ if (extMime) return extMime;
205
+ if (headerMime && !isGenericMime(headerMime)) return headerMime;
206
+ if (sniffed) return sniffed;
207
+ if (headerMime) return headerMime;
208
+ }
209
+ function extensionForMime(mime) {
210
+ const normalized = normalizeMimeType(mime);
211
+ if (!normalized) return;
212
+ return EXT_BY_MIME[normalized];
213
+ }
214
+ function isGifMedia(opts) {
215
+ if (opts.contentType?.toLowerCase() === "image/gif") return true;
216
+ return getFileExtension(opts.fileName) === ".gif";
217
+ }
218
+ function imageMimeFromFormat(format) {
219
+ if (!format) return;
220
+ switch (format.toLowerCase()) {
221
+ case "jpg":
222
+ case "jpeg": return "image/jpeg";
223
+ case "heic": return "image/heic";
224
+ case "heif": return "image/heif";
225
+ case "png": return "image/png";
226
+ case "webp": return "image/webp";
227
+ case "gif": return "image/gif";
228
+ default: return;
229
+ }
230
+ }
231
+ function kindFromMime(mime) {
232
+ return mediaKindFromMime(normalizeMimeType(mime));
233
+ }
234
+
235
+ //#endregion
236
+ //#region src/media/image-ops.ts
237
+ const IMAGE_REDUCE_QUALITY_STEPS = [
238
+ 85,
239
+ 75,
240
+ 65,
241
+ 55,
242
+ 45,
243
+ 35
244
+ ];
245
+ function buildImageResizeSideGrid(maxSide, sideStart) {
246
+ return [
247
+ sideStart,
248
+ 1800,
249
+ 1600,
250
+ 1400,
251
+ 1200,
252
+ 1e3,
253
+ 800
254
+ ].map((value) => Math.min(maxSide, value)).filter((value, idx, arr) => value > 0 && arr.indexOf(value) === idx).toSorted((a, b) => b - a);
255
+ }
256
+ function isBun() {
257
+ return typeof process.versions.bun === "string";
258
+ }
259
+ function prefersSips() {
260
+ return process.env.OPENCLAW_IMAGE_BACKEND === "sips" || process.env.OPENCLAW_IMAGE_BACKEND !== "sharp" && isBun() && process.platform === "darwin";
261
+ }
262
+ async function loadSharp() {
263
+ const mod = await import("sharp");
264
+ const sharp = mod.default ?? mod;
265
+ return (buffer) => sharp(buffer, { failOnError: false });
266
+ }
267
+ /**
268
+ * Reads EXIF orientation from JPEG buffer.
269
+ * Returns orientation value 1-8, or null if not found/not JPEG.
270
+ *
271
+ * EXIF orientation values:
272
+ * 1 = Normal, 2 = Flip H, 3 = Rotate 180, 4 = Flip V,
273
+ * 5 = Rotate 270 CW + Flip H, 6 = Rotate 90 CW, 7 = Rotate 90 CW + Flip H, 8 = Rotate 270 CW
274
+ */
275
+ function readJpegExifOrientation(buffer) {
276
+ if (buffer.length < 2 || buffer[0] !== 255 || buffer[1] !== 216) return null;
277
+ let offset = 2;
278
+ while (offset < buffer.length - 4) {
279
+ if (buffer[offset] !== 255) {
280
+ offset++;
281
+ continue;
282
+ }
283
+ const marker = buffer[offset + 1];
284
+ if (marker === 255) {
285
+ offset++;
286
+ continue;
287
+ }
288
+ if (marker === 225) {
289
+ const exifStart = offset + 4;
290
+ if (buffer.length > exifStart + 6 && buffer.toString("ascii", exifStart, exifStart + 4) === "Exif" && buffer[exifStart + 4] === 0 && buffer[exifStart + 5] === 0) {
291
+ const tiffStart = exifStart + 6;
292
+ if (buffer.length < tiffStart + 8) return null;
293
+ const isLittleEndian = buffer.toString("ascii", tiffStart, tiffStart + 2) === "II";
294
+ const readU16 = (pos) => isLittleEndian ? buffer.readUInt16LE(pos) : buffer.readUInt16BE(pos);
295
+ const readU32 = (pos) => isLittleEndian ? buffer.readUInt32LE(pos) : buffer.readUInt32BE(pos);
296
+ const ifd0Start = tiffStart + readU32(tiffStart + 4);
297
+ if (buffer.length < ifd0Start + 2) return null;
298
+ const numEntries = readU16(ifd0Start);
299
+ for (let i = 0; i < numEntries; i++) {
300
+ const entryOffset = ifd0Start + 2 + i * 12;
301
+ if (buffer.length < entryOffset + 12) break;
302
+ if (readU16(entryOffset) === 274) {
303
+ const value = readU16(entryOffset + 8);
304
+ return value >= 1 && value <= 8 ? value : null;
305
+ }
306
+ }
307
+ }
308
+ return null;
309
+ }
310
+ if (marker >= 224 && marker <= 239) {
311
+ const segmentLength = buffer.readUInt16BE(offset + 2);
312
+ offset += 2 + segmentLength;
313
+ continue;
314
+ }
315
+ if (marker === 192 || marker === 218) break;
316
+ offset++;
317
+ }
318
+ return null;
319
+ }
320
+ async function withTempDir(fn) {
321
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-img-"));
322
+ try {
323
+ return await fn(dir);
324
+ } finally {
325
+ await fs.rm(dir, {
326
+ recursive: true,
327
+ force: true
328
+ }).catch(() => {});
329
+ }
330
+ }
331
+ async function sipsMetadataFromBuffer(buffer) {
332
+ return await withTempDir(async (dir) => {
333
+ const input = path.join(dir, "in.img");
334
+ await fs.writeFile(input, buffer);
335
+ const { stdout } = await runExec("/usr/bin/sips", [
336
+ "-g",
337
+ "pixelWidth",
338
+ "-g",
339
+ "pixelHeight",
340
+ input
341
+ ], {
342
+ timeoutMs: 1e4,
343
+ maxBuffer: 512 * 1024
344
+ });
345
+ const w = stdout.match(/pixelWidth:\s*([0-9]+)/);
346
+ const h = stdout.match(/pixelHeight:\s*([0-9]+)/);
347
+ if (!w?.[1] || !h?.[1]) return null;
348
+ const width = Number.parseInt(w[1], 10);
349
+ const height = Number.parseInt(h[1], 10);
350
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
351
+ if (width <= 0 || height <= 0) return null;
352
+ return {
353
+ width,
354
+ height
355
+ };
356
+ });
357
+ }
358
+ async function sipsResizeToJpeg(params) {
359
+ return await withTempDir(async (dir) => {
360
+ const input = path.join(dir, "in.img");
361
+ const output = path.join(dir, "out.jpg");
362
+ await fs.writeFile(input, params.buffer);
363
+ await runExec("/usr/bin/sips", [
364
+ "-Z",
365
+ String(Math.max(1, Math.round(params.maxSide))),
366
+ "-s",
367
+ "format",
368
+ "jpeg",
369
+ "-s",
370
+ "formatOptions",
371
+ String(Math.max(1, Math.min(100, Math.round(params.quality)))),
372
+ input,
373
+ "--out",
374
+ output
375
+ ], {
376
+ timeoutMs: 2e4,
377
+ maxBuffer: 1024 * 1024
378
+ });
379
+ return await fs.readFile(output);
380
+ });
381
+ }
382
+ async function sipsConvertToJpeg(buffer) {
383
+ return await withTempDir(async (dir) => {
384
+ const input = path.join(dir, "in.heic");
385
+ const output = path.join(dir, "out.jpg");
386
+ await fs.writeFile(input, buffer);
387
+ await runExec("/usr/bin/sips", [
388
+ "-s",
389
+ "format",
390
+ "jpeg",
391
+ input,
392
+ "--out",
393
+ output
394
+ ], {
395
+ timeoutMs: 2e4,
396
+ maxBuffer: 1024 * 1024
397
+ });
398
+ return await fs.readFile(output);
399
+ });
400
+ }
401
+ async function getImageMetadata(buffer) {
402
+ if (prefersSips()) return await sipsMetadataFromBuffer(buffer).catch(() => null);
403
+ try {
404
+ const meta = await (await loadSharp())(buffer).metadata();
405
+ const width = Number(meta.width ?? 0);
406
+ const height = Number(meta.height ?? 0);
407
+ if (!Number.isFinite(width) || !Number.isFinite(height)) return null;
408
+ if (width <= 0 || height <= 0) return null;
409
+ return {
410
+ width,
411
+ height
412
+ };
413
+ } catch {
414
+ return null;
415
+ }
416
+ }
417
+ /**
418
+ * Applies rotation/flip to image buffer using sips based on EXIF orientation.
419
+ */
420
+ async function sipsApplyOrientation(buffer, orientation) {
421
+ const ops = [];
422
+ switch (orientation) {
423
+ case 2:
424
+ ops.push("-f", "horizontal");
425
+ break;
426
+ case 3:
427
+ ops.push("-r", "180");
428
+ break;
429
+ case 4:
430
+ ops.push("-f", "vertical");
431
+ break;
432
+ case 5:
433
+ ops.push("-r", "270", "-f", "horizontal");
434
+ break;
435
+ case 6:
436
+ ops.push("-r", "90");
437
+ break;
438
+ case 7:
439
+ ops.push("-r", "90", "-f", "horizontal");
440
+ break;
441
+ case 8:
442
+ ops.push("-r", "270");
443
+ break;
444
+ default: return buffer;
445
+ }
446
+ return await withTempDir(async (dir) => {
447
+ const input = path.join(dir, "in.jpg");
448
+ const output = path.join(dir, "out.jpg");
449
+ await fs.writeFile(input, buffer);
450
+ await runExec("/usr/bin/sips", [
451
+ ...ops,
452
+ input,
453
+ "--out",
454
+ output
455
+ ], {
456
+ timeoutMs: 2e4,
457
+ maxBuffer: 1024 * 1024
458
+ });
459
+ return await fs.readFile(output);
460
+ });
461
+ }
462
+ async function resizeToJpeg(params) {
463
+ if (prefersSips()) {
464
+ const normalized = await normalizeExifOrientationSips(params.buffer);
465
+ if (params.withoutEnlargement !== false) {
466
+ const meta = await getImageMetadata(normalized);
467
+ if (meta) {
468
+ const maxDim = Math.max(meta.width, meta.height);
469
+ if (maxDim > 0 && maxDim <= params.maxSide) return await sipsResizeToJpeg({
470
+ buffer: normalized,
471
+ maxSide: maxDim,
472
+ quality: params.quality
473
+ });
474
+ }
475
+ }
476
+ return await sipsResizeToJpeg({
477
+ buffer: normalized,
478
+ maxSide: params.maxSide,
479
+ quality: params.quality
480
+ });
481
+ }
482
+ return await (await loadSharp())(params.buffer).rotate().resize({
483
+ width: params.maxSide,
484
+ height: params.maxSide,
485
+ fit: "inside",
486
+ withoutEnlargement: params.withoutEnlargement !== false
487
+ }).jpeg({
488
+ quality: params.quality,
489
+ mozjpeg: true
490
+ }).toBuffer();
491
+ }
492
+ async function convertHeicToJpeg(buffer) {
493
+ if (prefersSips()) return await sipsConvertToJpeg(buffer);
494
+ return await (await loadSharp())(buffer).jpeg({
495
+ quality: 90,
496
+ mozjpeg: true
497
+ }).toBuffer();
498
+ }
499
+ /**
500
+ * Checks if an image has an alpha channel (transparency).
501
+ * Returns true if the image has alpha, false otherwise.
502
+ */
503
+ async function hasAlphaChannel(buffer) {
504
+ try {
505
+ const meta = await (await loadSharp())(buffer).metadata();
506
+ return meta.hasAlpha || meta.channels === 4;
507
+ } catch {
508
+ return false;
509
+ }
510
+ }
511
+ /**
512
+ * Resizes an image to PNG format, preserving alpha channel (transparency).
513
+ * Falls back to sharp only (no sips fallback for PNG with alpha).
514
+ */
515
+ async function resizeToPng(params) {
516
+ const sharp = await loadSharp();
517
+ const compressionLevel = params.compressionLevel ?? 6;
518
+ return await sharp(params.buffer).rotate().resize({
519
+ width: params.maxSide,
520
+ height: params.maxSide,
521
+ fit: "inside",
522
+ withoutEnlargement: params.withoutEnlargement !== false
523
+ }).png({ compressionLevel }).toBuffer();
524
+ }
525
+ async function optimizeImageToPng(buffer, maxBytes) {
526
+ const sides = [
527
+ 2048,
528
+ 1536,
529
+ 1280,
530
+ 1024,
531
+ 800
532
+ ];
533
+ const compressionLevels = [
534
+ 6,
535
+ 7,
536
+ 8,
537
+ 9
538
+ ];
539
+ let smallest = null;
540
+ for (const side of sides) for (const compressionLevel of compressionLevels) try {
541
+ const out = await resizeToPng({
542
+ buffer,
543
+ maxSide: side,
544
+ compressionLevel,
545
+ withoutEnlargement: true
546
+ });
547
+ const size = out.length;
548
+ if (!smallest || size < smallest.size) smallest = {
549
+ buffer: out,
550
+ size,
551
+ resizeSide: side,
552
+ compressionLevel
553
+ };
554
+ if (size <= maxBytes) return {
555
+ buffer: out,
556
+ optimizedSize: size,
557
+ resizeSide: side,
558
+ compressionLevel
559
+ };
560
+ } catch {}
561
+ if (smallest) return {
562
+ buffer: smallest.buffer,
563
+ optimizedSize: smallest.size,
564
+ resizeSide: smallest.resizeSide,
565
+ compressionLevel: smallest.compressionLevel
566
+ };
567
+ throw new Error("Failed to optimize PNG image");
568
+ }
569
+ /**
570
+ * Internal sips-only EXIF normalization (no sharp fallback).
571
+ * Used by resizeToJpeg to normalize before sips resize.
572
+ */
573
+ async function normalizeExifOrientationSips(buffer) {
574
+ try {
575
+ const orientation = readJpegExifOrientation(buffer);
576
+ if (!orientation || orientation === 1) return buffer;
577
+ return await sipsApplyOrientation(buffer, orientation);
578
+ } catch {
579
+ return buffer;
580
+ }
581
+ }
582
+
583
+ //#endregion
584
+ export { GATEWAY_CLIENT_NAMES as A, isMarkdownCapableMessageChannel as C, resolveMessageChannel as D, resolveGatewayMessageChannel as E, GATEWAY_CLIENT_IDS as O, isInternalMessageChannel as S, normalizeMessageChannel as T, maxBytesForKind as _, hasAlphaChannel as a, isDeliverableMessageChannel as b, detectMime as c, imageMimeFromFormat as d, isAudioFileName as f, MAX_IMAGE_BYTES as g, normalizeMimeType as h, getImageMetadata as i, GATEWAY_CLIENT_MODES as k, extensionForMime as l, kindFromMime as m, buildImageResizeSideGrid as n, optimizeImageToPng as o, isGifMedia as p, convertHeicToJpeg as r, resizeToJpeg as s, IMAGE_REDUCE_QUALITY_STEPS as t, getFileExtension as u, mediaKindFromMime as v, listDeliverableMessageChannels as w, isGatewayMessageChannel as x, INTERNAL_MESSAGE_CHANNEL as y };
@@ -0,0 +1,25 @@
1
+ import "./run-with-concurrency-Bt_ks0Qa.js";
2
+ import "./accounts-DP1-L-QS.js";
3
+ import "./paths-MKyEVmEb.js";
4
+ import "./github-copilot-token-D5fdS6xD.js";
5
+ import "./config-BkEnz2Po.js";
6
+ import "./logger-CZY9KIoY.js";
7
+ import "./thinking-Bo2eosVa.js";
8
+ import "./image-ops-BSiMpAw4.js";
9
+ import "./pi-embedded-helpers-1R1gu7eX.js";
10
+ import "./plugins-DeBZB9l_.js";
11
+ import "./accounts-CJWOBzwB.js";
12
+ import "./accounts-DZhWlEg3.js";
13
+ import "./paths-vTM3Lh3X.js";
14
+ import "./redact-DjVX-1N3.js";
15
+ import "./errors-DaiAM-yU.js";
16
+ import "./path-alias-guards-DBjLbIX_.js";
17
+ import "./fs-safe-B8y811FR.js";
18
+ import "./ssrf-cFtplYtS.js";
19
+ import "./tool-images-Gk_-0y2N.js";
20
+ import "./skills-CBkHBYPq.js";
21
+ import "./chrome-BXoCyCkY.js";
22
+ import "./store-5nyxY3WU.js";
23
+ import { t as describeImageWithModel } from "./image-DjTEkYZE.js";
24
+
25
+ export { describeImageWithModel };