openclaw-multi-auto 1.6.2 → 1.6.5

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 (192) hide show
  1. package/dist/{audio-preflight-DoPfNXDz.js → audio-preflight-DpxQCpsA.js} +4 -4
  2. package/dist/{audio-transcription-runner-CzjuH3uL.js → audio-transcription-runner-28fcRNNi.js} +1 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/bundled/boot-md/handler.js +6 -6
  5. package/dist/bundled/session-memory/handler.js +6 -6
  6. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  7. package/dist/{chrome-DlhJHqj8.js → chrome-DwizpzOC.js} +8 -8
  8. package/dist/{deliver-CApVJA_l.js → deliver-D4o6VIur.js} +1 -1
  9. package/dist/{deliver-runtime-D1z-h5eg.js → deliver-runtime-P-G3bPjW.js} +3 -3
  10. package/dist/{deps-send-whatsapp.runtime-Dz_4fi2D.js → deps-send-whatsapp.runtime-CJkTHkah.js} +7 -7
  11. package/dist/{image-B3Mz7N5I.js → image-Bbn53mzj.js} +1 -1
  12. package/dist/{image-runtime-DWjhow2W.js → image-runtime-CVv2ra9J.js} +3 -3
  13. package/dist/llm-slug-generator.js +6 -6
  14. package/dist/{pi-embedded-bcjMe3wj.js → pi-embedded-BaGj07T0.js} +24 -24
  15. package/dist/{pi-embedded-helpers-D5yyGEvA.js → pi-embedded-helpers-wy0DZvx1.js} +3 -3
  16. package/dist/plugin-sdk/{accounts-DyFCXtHv.js → accounts-BslAlVYS.js} +2 -2
  17. package/dist/plugin-sdk/{accounts-BJAXxY46.js → accounts-C3m65--E.js} +2 -2
  18. package/dist/plugin-sdk/{accounts-C1j7HSL0.js → accounts-CNCCkdEF.js} +3 -3
  19. package/dist/plugin-sdk/{active-listener-B_sLJTXM.js → active-listener-CkPnMUkB.js} +2 -2
  20. package/dist/plugin-sdk/{api-key-rotation-8nyyt1kx.js → api-key-rotation-BXnNsojA.js} +2 -2
  21. package/dist/plugin-sdk/{audio-preflight-C_aSAPR1.js → audio-preflight-CtO4fFvp.js} +26 -26
  22. package/dist/plugin-sdk/{audio-transcription-runner-CB53F7_7.js → audio-transcription-runner-DnxvOS1-.js} +11 -11
  23. package/dist/plugin-sdk/{audit-membership-runtime-BXndI4LG.js → audit-membership-runtime-BpfoSk8M.js} +2 -2
  24. package/dist/plugin-sdk/{channel-activity-C5y8AgAV.js → channel-activity-WJYxcJ3S.js} +3 -3
  25. package/dist/plugin-sdk/{channel-web-DBTRO03V.js → channel-web-dO5k3ubM.js} +18 -18
  26. package/dist/plugin-sdk/{chrome-f00sZkDX.js → chrome-CjNTuJML.js} +6 -6
  27. package/dist/plugin-sdk/{commands-registry-BJ_NxG2F.js → commands-registry-CdYjoI0i.js} +4 -4
  28. package/dist/plugin-sdk/{common-Cf27Jwxu.js → common-oYc5vPFl.js} +2 -2
  29. package/dist/plugin-sdk/compat.js +50 -50
  30. package/dist/plugin-sdk/{config-CHQrpx-Q.js → config-B1z-UxQ3.js} +7 -7
  31. package/dist/plugin-sdk/{deliver-DNEuetST.js → deliver-D5_6T567.js} +10 -10
  32. package/dist/plugin-sdk/deliver-runtime-C5dgvvga.js +32 -0
  33. package/dist/plugin-sdk/deps-send-discord.runtime-Dg4N7PHJ.js +23 -0
  34. package/dist/plugin-sdk/deps-send-imessage.runtime-0OEwzMQm.js +22 -0
  35. package/dist/plugin-sdk/deps-send-signal.runtime-BM1jRt3G.js +21 -0
  36. package/dist/plugin-sdk/deps-send-slack.runtime-1E3BYRdF.js +19 -0
  37. package/dist/plugin-sdk/deps-send-telegram.runtime-DNCxIflA.js +24 -0
  38. package/dist/plugin-sdk/deps-send-whatsapp.runtime-OLwr-9c8.js +57 -0
  39. package/dist/plugin-sdk/{diagnostic-LYUUmjJ5.js → diagnostic-Bxxu0ig-.js} +2 -2
  40. package/dist/plugin-sdk/discord.js +6 -6
  41. package/dist/plugin-sdk/{errors-CtMWwS2Z.js → errors-B3cHyZZA.js} +1 -1
  42. package/dist/plugin-sdk/{fetch-guard-CxYB5Kg6.js → fetch-guard-Dcgod0tg.js} +2 -2
  43. package/dist/plugin-sdk/{fs-safe-DtfhxbrI.js → fs-safe-BaKqI3G4.js} +3 -3
  44. package/dist/plugin-sdk/{image-BwjYjRHx.js → image-B2mQW9Rb.js} +6 -6
  45. package/dist/plugin-sdk/{image-ops-BnZKcbd6.js → image-ops-Cbzr4U9l.js} +2 -2
  46. package/dist/plugin-sdk/image-runtime-BFm45j49.js +25 -0
  47. package/dist/plugin-sdk/{ir-Z4hX67TJ.js → ir-ZEmrTr4J.js} +7 -7
  48. package/dist/plugin-sdk/{local-roots-KhjQw04O.js → local-roots-CIPRxA-4.js} +4 -4
  49. package/dist/plugin-sdk/{logger-DHIIvMxj.js → logger-CvPFVOgT.js} +2 -2
  50. package/dist/plugin-sdk/{login-C31642Ld.js → login-CCTew9bt.js} +4 -4
  51. package/dist/plugin-sdk/{login-qr--y2SG_Ue.js → login-qr-BI3Vi_wJ.js} +5 -5
  52. package/dist/plugin-sdk/{manager-2UZBMCc7.js → manager-BEoYPn7R.js} +8 -8
  53. package/dist/plugin-sdk/manager-runtime-DxclHQ4U.js +15 -0
  54. package/dist/plugin-sdk/{outbound-Ba0QUI5h.js → outbound-ByOw1K6W.js} +5 -5
  55. package/dist/plugin-sdk/{outbound-attachment-B1Laso-8.js → outbound-attachment-BzVhxRRw.js} +2 -2
  56. package/dist/plugin-sdk/{path-alias-guards-C7Vm5DZ1.js → path-alias-guards-sWayacde.js} +1 -1
  57. package/dist/plugin-sdk/{paths-DopV9PQG.js → paths-Dpg3qxcl.js} +1 -1
  58. package/dist/plugin-sdk/{pi-embedded-helpers-DnA_OCzP.js → pi-embedded-helpers-DIxXkGJf.js} +16 -16
  59. package/dist/plugin-sdk/{pi-model-discovery-DdPqXk8f.js → pi-model-discovery-DM_2uFtj.js} +1 -1
  60. package/dist/plugin-sdk/pi-model-discovery-runtime-BuzvkvNR.js +8 -0
  61. package/dist/plugin-sdk/{pi-tools.before-tool-call.runtime-DxFHiLUE.js → pi-tools.before-tool-call.runtime-w1dqL_ty.js} +4 -4
  62. package/dist/plugin-sdk/{plugins-CbCt4osF.js → plugins-C4USiH29.js} +4 -4
  63. package/dist/plugin-sdk/{proxy-env-C63mMdas.js → proxy-env-ET-rp8eg.js} +1 -1
  64. package/dist/plugin-sdk/{proxy-fetch-Ch95c_Y2.js → proxy-fetch-uDXGKG3Z.js} +1 -1
  65. package/dist/plugin-sdk/{pw-ai-DpJk62D4.js → pw-ai-CyOt3RDA.js} +9 -9
  66. package/dist/plugin-sdk/{qmd-manager-Ca-iSfEE.js → qmd-manager-BySdoVR7.js} +7 -7
  67. package/dist/plugin-sdk/{query-expansion-B_Xe41Ab.js → query-expansion-C6uS-7lj.js} +4 -4
  68. package/dist/plugin-sdk/{redact-hp9TOulW.js → redact-Bvxt1T_Q.js} +1 -1
  69. package/dist/plugin-sdk/{reply-CovBlFea.js → reply-CTCSeQqW.js} +73 -73
  70. package/dist/plugin-sdk/{resolve-outbound-target-BbrHgyUk.js → resolve-outbound-target-Bw8YNANu.js} +2 -2
  71. package/dist/plugin-sdk/{run-with-concurrency-BR1DXa8T.js → run-with-concurrency-C_KCHwvf.js} +1 -1
  72. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-BxgRDkhc.js +10 -0
  73. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-elOqrkfg.js +19 -0
  74. package/dist/plugin-sdk/{send-BvAtLLPl.js → send-BZ6nYFZr.js} +5 -5
  75. package/dist/plugin-sdk/{send-BTztm3D2.js → send-C0w6xP2x.js} +6 -6
  76. package/dist/plugin-sdk/{send-CWJUuG0i.js → send-CFf-1V89.js} +8 -8
  77. package/dist/plugin-sdk/{send-EcglC4cG.js → send-CY-Qfwia.js} +7 -7
  78. package/dist/plugin-sdk/{send-BXpXBwM_.js → send-qPyNGSe4.js} +13 -13
  79. package/dist/plugin-sdk/{session-k256LJZT.js → session-COrvpvUQ.js} +3 -3
  80. package/dist/plugin-sdk/{skill-commands-DoRqLzxm.js → skill-commands-DZqhtmiv.js} +4 -4
  81. package/dist/plugin-sdk/{skills-QudILG6e.js → skills-Cw_vXEJb.js} +6 -6
  82. package/dist/plugin-sdk/slack.js +2 -2
  83. package/dist/plugin-sdk/slash-commands.runtime-D67JLweo.js +13 -0
  84. package/dist/plugin-sdk/slash-dispatch.runtime-DvcpvCJ0.js +52 -0
  85. package/dist/plugin-sdk/slash-skill-commands.runtime-BM1x3azR.js +16 -0
  86. package/dist/plugin-sdk/{store-BbDQw3g6.js → store-CMHj6IIw.js} +2 -2
  87. package/dist/plugin-sdk/subagent-registry-runtime-1lbDyRzz.js +52 -0
  88. package/dist/plugin-sdk/{tables-BhvloMKN.js → tables-CSqrHsKL.js} +1 -1
  89. package/dist/plugin-sdk/{thinking-URzkT-3p.js → thinking-DOnsR_A8.js} +7 -7
  90. package/dist/plugin-sdk/{tokens-DgNRBwIg.js → tokens-BDr0Z9o3.js} +1 -1
  91. package/dist/plugin-sdk/{tool-images-Gk_-0y2N.js → tool-images-eEfOVkzf.js} +2 -2
  92. package/dist/plugin-sdk/web-BLyT64pW.js +56 -0
  93. package/dist/plugin-sdk/{whatsapp-actions-RcZ6vp61.js → whatsapp-actions-xcleMoMv.js} +17 -17
  94. package/dist/plugin-sdk/whatsapp.js +50 -50
  95. package/dist/{pw-ai-CDQDCfUa.js → pw-ai-Cl1Lc7RC.js} +1 -1
  96. package/dist/{slash-dispatch.runtime-CWbpp23S.js → slash-dispatch.runtime-DoBAQBU5.js} +6 -6
  97. package/dist/{subagent-registry-runtime-DEVpAaAP.js → subagent-registry-runtime-ppWS3tVu.js} +6 -6
  98. package/dist/{web-NWKn8ABz.js → web-CzWRVmFt.js} +6 -6
  99. package/package.json +1 -1
  100. package/scripts/create-instance.sh +11 -13
  101. package/dist/plugin-sdk/accounts-CJWOBzwB.js +0 -35
  102. package/dist/plugin-sdk/accounts-DP1-L-QS.js +0 -288
  103. package/dist/plugin-sdk/accounts-DZhWlEg3.js +0 -46
  104. package/dist/plugin-sdk/active-listener-CftX5jLD.js +0 -50
  105. package/dist/plugin-sdk/api-key-rotation-BRE4X2tf.js +0 -181
  106. package/dist/plugin-sdk/audio-preflight-DGEUDxxR.js +0 -69
  107. package/dist/plugin-sdk/audio-transcription-runner-DkoPNPYt.js +0 -2176
  108. package/dist/plugin-sdk/audit-membership-runtime-DSBHHw7o.js +0 -58
  109. package/dist/plugin-sdk/channel-activity-F3d0yUwy.js +0 -94
  110. package/dist/plugin-sdk/channel-web-QF7EpjeP.js +0 -2256
  111. package/dist/plugin-sdk/chrome-BXoCyCkY.js +0 -2415
  112. package/dist/plugin-sdk/commands-registry-t7cXBTfN.js +0 -1125
  113. package/dist/plugin-sdk/config-BkEnz2Po.js +0 -17913
  114. package/dist/plugin-sdk/deliver-B6AG_l67.js +0 -1694
  115. package/dist/plugin-sdk/deliver-runtime-BFdqklJM.js +0 -32
  116. package/dist/plugin-sdk/deliver-runtime-D585kJZc.js +0 -32
  117. package/dist/plugin-sdk/deps-send-discord.runtime-DuqpYwU0.js +0 -23
  118. package/dist/plugin-sdk/deps-send-discord.runtime-a_OKY2js.js +0 -23
  119. package/dist/plugin-sdk/deps-send-imessage.runtime-Baxy9TD4.js +0 -22
  120. package/dist/plugin-sdk/deps-send-imessage.runtime-CZ2rS8Lb.js +0 -22
  121. package/dist/plugin-sdk/deps-send-signal.runtime-BdqiWhIh.js +0 -21
  122. package/dist/plugin-sdk/deps-send-signal.runtime-BwXoCrFl.js +0 -21
  123. package/dist/plugin-sdk/deps-send-slack.runtime-04s36qiC.js +0 -19
  124. package/dist/plugin-sdk/deps-send-slack.runtime-CLmKjgso.js +0 -19
  125. package/dist/plugin-sdk/deps-send-telegram.runtime-BKfdBKnZ.js +0 -24
  126. package/dist/plugin-sdk/deps-send-telegram.runtime-LE5tkPvr.js +0 -24
  127. package/dist/plugin-sdk/deps-send-whatsapp.runtime-BOTwkbx_.js +0 -57
  128. package/dist/plugin-sdk/deps-send-whatsapp.runtime-Bz57lobC.js +0 -57
  129. package/dist/plugin-sdk/diagnostic-CsP-lEkI.js +0 -319
  130. package/dist/plugin-sdk/errors-DaiAM-yU.js +0 -54
  131. package/dist/plugin-sdk/fetch-guard-DETCcJzQ.js +0 -156
  132. package/dist/plugin-sdk/fs-safe-B8y811FR.js +0 -352
  133. package/dist/plugin-sdk/image-DjTEkYZE.js +0 -2310
  134. package/dist/plugin-sdk/image-ops-BSiMpAw4.js +0 -584
  135. package/dist/plugin-sdk/image-runtime-6xPp8m5a.js +0 -25
  136. package/dist/plugin-sdk/image-runtime-B8twoubs.js +0 -25
  137. package/dist/plugin-sdk/ir-DQ7_HbvK.js +0 -1296
  138. package/dist/plugin-sdk/local-roots-BUP4YBmR.js +0 -186
  139. package/dist/plugin-sdk/logger-CZY9KIoY.js +0 -1163
  140. package/dist/plugin-sdk/login-BxEKLlCo.js +0 -57
  141. package/dist/plugin-sdk/login-qr-BQIpMPr9.js +0 -320
  142. package/dist/plugin-sdk/manager-I6KbPihW.js +0 -3917
  143. package/dist/plugin-sdk/manager-runtime-CFfYYWIQ.js +0 -15
  144. package/dist/plugin-sdk/manager-runtime-CMeLwose.js +0 -15
  145. package/dist/plugin-sdk/outbound-NS6UHnB6.js +0 -212
  146. package/dist/plugin-sdk/outbound-attachment-Dy6fyf6H.js +0 -19
  147. package/dist/plugin-sdk/path-alias-guards-DBjLbIX_.js +0 -43
  148. package/dist/plugin-sdk/paths-vTM3Lh3X.js +0 -166
  149. package/dist/plugin-sdk/pi-embedded-helpers-1R1gu7eX.js +0 -9627
  150. package/dist/plugin-sdk/pi-model-discovery-runtime-D8CJhtJY.js +0 -8
  151. package/dist/plugin-sdk/pi-model-discovery-runtime-Do9o-dUd.js +0 -8
  152. package/dist/plugin-sdk/pi-model-discovery-v-XPUOOf.js +0 -134
  153. package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-D4sFsIks.js +0 -354
  154. package/dist/plugin-sdk/plugins-DeBZB9l_.js +0 -864
  155. package/dist/plugin-sdk/proxy-fetch-ChxOhWF4.js +0 -38
  156. package/dist/plugin-sdk/pw-ai-DEOmCSSC.js +0 -1938
  157. package/dist/plugin-sdk/qmd-manager-HyYKoEch.js +0 -1448
  158. package/dist/plugin-sdk/query-expansion-CeyKUeDW.js +0 -1011
  159. package/dist/plugin-sdk/redact-DjVX-1N3.js +0 -319
  160. package/dist/plugin-sdk/reply-DAo_Jt8K.js +0 -97916
  161. package/dist/plugin-sdk/resolve-outbound-target-B42qgQS9.js +0 -40
  162. package/dist/plugin-sdk/run-with-concurrency-Bt_ks0Qa.js +0 -1994
  163. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-B6W989eF.js +0 -10
  164. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-SkO91TZH.js +0 -10
  165. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-B0VWK5hm.js +0 -19
  166. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-c_GDFy37.js +0 -19
  167. package/dist/plugin-sdk/send-CQpMudwO.js +0 -2587
  168. package/dist/plugin-sdk/send-DQHLzVyO.js +0 -414
  169. package/dist/plugin-sdk/send-DTB24bEF.js +0 -3135
  170. package/dist/plugin-sdk/send-DfHadjZ_.js +0 -503
  171. package/dist/plugin-sdk/send-XXlW2iny.js +0 -540
  172. package/dist/plugin-sdk/session-6TF6MyaC.js +0 -169
  173. package/dist/plugin-sdk/skill-commands-CkGeFUMl.js +0 -342
  174. package/dist/plugin-sdk/skills-CBkHBYPq.js +0 -1428
  175. package/dist/plugin-sdk/slash-commands.runtime-CxliuGaP.js +0 -13
  176. package/dist/plugin-sdk/slash-commands.runtime-DS6vCNSL.js +0 -13
  177. package/dist/plugin-sdk/slash-dispatch.runtime-BXrxb2wd.js +0 -52
  178. package/dist/plugin-sdk/slash-dispatch.runtime-DFaeYlJQ.js +0 -52
  179. package/dist/plugin-sdk/slash-skill-commands.runtime-0M0OLCxq.js +0 -16
  180. package/dist/plugin-sdk/slash-skill-commands.runtime-Bd6qQ2oT.js +0 -16
  181. package/dist/plugin-sdk/ssrf-cFtplYtS.js +0 -202
  182. package/dist/plugin-sdk/store-5nyxY3WU.js +0 -81
  183. package/dist/plugin-sdk/subagent-registry-runtime-1uwQbuXj.js +0 -52
  184. package/dist/plugin-sdk/subagent-registry-runtime-DCtmDwna.js +0 -52
  185. package/dist/plugin-sdk/tables-C47P4GTN.js +0 -55
  186. package/dist/plugin-sdk/target-errors-Blia4S69.js +0 -195
  187. package/dist/plugin-sdk/thinking-Bo2eosVa.js +0 -1206
  188. package/dist/plugin-sdk/tokens-B1PW5Ayy.js +0 -52
  189. package/dist/plugin-sdk/tool-images-xpqbP6RR.js +0 -274
  190. package/dist/plugin-sdk/web-B74yhL2N.js +0 -56
  191. package/dist/plugin-sdk/web-CVxZbXyH.js +0 -56
  192. package/dist/plugin-sdk/whatsapp-actions-Bw0H9g-n.js +0 -80
@@ -1,57 +0,0 @@
1
- import { i as resolveWhatsAppAccount, l as logoutWeb } from "./accounts-DP1-L-QS.js";
2
- import { Pr as formatCliCommand, n as loadConfig } from "./config-BkEnz2Po.js";
3
- import { B as success, F as danger, I as info, c as defaultRuntime, r as logInfo } from "./logger-CZY9KIoY.js";
4
- import { i as waitForWaConnection, n as formatError, t as createWaSocket } from "./session-6TF6MyaC.js";
5
- import { DisconnectReason } from "@whiskeysockets/baileys";
6
-
7
- //#region src/web/login.ts
8
- async function loginWeb(verbose, waitForConnection, runtime = defaultRuntime, accountId) {
9
- const wait = waitForConnection ?? waitForWaConnection;
10
- const account = resolveWhatsAppAccount({
11
- cfg: loadConfig(),
12
- accountId
13
- });
14
- const sock = await createWaSocket(true, verbose, { authDir: account.authDir });
15
- logInfo("Waiting for WhatsApp connection...", runtime);
16
- try {
17
- await wait(sock);
18
- console.log(success("✅ Linked! Credentials saved for future sends."));
19
- } catch (err) {
20
- const code = err?.error?.output?.statusCode ?? err?.output?.statusCode;
21
- if (code === 515) {
22
- console.log(info("WhatsApp asked for a restart after pairing (code 515); creds are saved. Restarting connection once…"));
23
- try {
24
- sock.ws?.close();
25
- } catch {}
26
- const retry = await createWaSocket(false, verbose, { authDir: account.authDir });
27
- try {
28
- await wait(retry);
29
- console.log(success("✅ Linked after restart; web session ready."));
30
- return;
31
- } finally {
32
- setTimeout(() => retry.ws?.close(), 500);
33
- }
34
- }
35
- if (code === DisconnectReason.loggedOut) {
36
- await logoutWeb({
37
- authDir: account.authDir,
38
- isLegacyAuthDir: account.isLegacyAuthDir,
39
- runtime
40
- });
41
- console.error(danger(`WhatsApp reported the session is logged out. Cleared cached web session; please rerun ${formatCliCommand("openclaw channels login")} and scan the QR again.`));
42
- throw new Error("Session logged out; cache cleared. Re-run login.", { cause: err });
43
- }
44
- const formatted = formatError(err);
45
- console.error(danger(`WhatsApp Web connection ended before fully opening. ${formatted}`));
46
- throw new Error(formatted, { cause: err });
47
- } finally {
48
- setTimeout(() => {
49
- try {
50
- sock.ws?.close();
51
- } catch {}
52
- }, 500);
53
- }
54
- }
55
-
56
- //#endregion
57
- export { loginWeb as t };
@@ -1,320 +0,0 @@
1
- import "./run-with-concurrency-Bt_ks0Qa.js";
2
- import { _ as webAuthExists, i as resolveWhatsAppAccount, l as logoutWeb, p as readWebSelfId } from "./accounts-DP1-L-QS.js";
3
- import "./paths-MKyEVmEb.js";
4
- import "./github-copilot-token-D5fdS6xD.js";
5
- import { n as loadConfig } from "./config-BkEnz2Po.js";
6
- import { B as success, F as danger, I as info, c as defaultRuntime, r as logInfo } from "./logger-CZY9KIoY.js";
7
- import { i as waitForWaConnection, n as formatError, r as getStatusCode, t as createWaSocket } from "./session-6TF6MyaC.js";
8
- import { randomUUID } from "node:crypto";
9
- import { DisconnectReason } from "@whiskeysockets/baileys";
10
- import QRCodeModule from "qrcode-terminal/vendor/QRCode/index.js";
11
- import QRErrorCorrectLevelModule from "qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js";
12
- import { deflateSync } from "node:zlib";
13
-
14
- //#region src/media/png-encode.ts
15
- /**
16
- * Minimal PNG encoder for generating simple RGBA images without native dependencies.
17
- * Used for QR codes, live probes, and other programmatic image generation.
18
- */
19
- const CRC_TABLE = (() => {
20
- const table = new Uint32Array(256);
21
- for (let i = 0; i < 256; i += 1) {
22
- let c = i;
23
- for (let k = 0; k < 8; k += 1) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
24
- table[i] = c >>> 0;
25
- }
26
- return table;
27
- })();
28
- /** Compute CRC32 checksum for a buffer (used in PNG chunk encoding). */
29
- function crc32(buf) {
30
- let crc = 4294967295;
31
- for (let i = 0; i < buf.length; i += 1) crc = CRC_TABLE[(crc ^ buf[i]) & 255] ^ crc >>> 8;
32
- return (crc ^ 4294967295) >>> 0;
33
- }
34
- /** Create a PNG chunk with type, data, and CRC. */
35
- function pngChunk(type, data) {
36
- const typeBuf = Buffer.from(type, "ascii");
37
- const len = Buffer.alloc(4);
38
- len.writeUInt32BE(data.length, 0);
39
- const crc = crc32(Buffer.concat([typeBuf, data]));
40
- const crcBuf = Buffer.alloc(4);
41
- crcBuf.writeUInt32BE(crc, 0);
42
- return Buffer.concat([
43
- len,
44
- typeBuf,
45
- data,
46
- crcBuf
47
- ]);
48
- }
49
- /** Write a pixel to an RGBA buffer. Ignores out-of-bounds writes. */
50
- function fillPixel(buf, x, y, width, r, g, b, a = 255) {
51
- if (x < 0 || y < 0 || x >= width) return;
52
- const idx = (y * width + x) * 4;
53
- if (idx < 0 || idx + 3 >= buf.length) return;
54
- buf[idx] = r;
55
- buf[idx + 1] = g;
56
- buf[idx + 2] = b;
57
- buf[idx + 3] = a;
58
- }
59
- /** Encode an RGBA buffer as a PNG image. */
60
- function encodePngRgba(buffer, width, height) {
61
- const stride = width * 4;
62
- const raw = Buffer.alloc((stride + 1) * height);
63
- for (let row = 0; row < height; row += 1) {
64
- const rawOffset = row * (stride + 1);
65
- raw[rawOffset] = 0;
66
- buffer.copy(raw, rawOffset + 1, row * stride, row * stride + stride);
67
- }
68
- const compressed = deflateSync(raw);
69
- const signature = Buffer.from([
70
- 137,
71
- 80,
72
- 78,
73
- 71,
74
- 13,
75
- 10,
76
- 26,
77
- 10
78
- ]);
79
- const ihdr = Buffer.alloc(13);
80
- ihdr.writeUInt32BE(width, 0);
81
- ihdr.writeUInt32BE(height, 4);
82
- ihdr[8] = 8;
83
- ihdr[9] = 6;
84
- ihdr[10] = 0;
85
- ihdr[11] = 0;
86
- ihdr[12] = 0;
87
- return Buffer.concat([
88
- signature,
89
- pngChunk("IHDR", ihdr),
90
- pngChunk("IDAT", compressed),
91
- pngChunk("IEND", Buffer.alloc(0))
92
- ]);
93
- }
94
-
95
- //#endregion
96
- //#region src/web/qr-image.ts
97
- const QRCode = QRCodeModule;
98
- const QRErrorCorrectLevel = QRErrorCorrectLevelModule;
99
- function createQrMatrix(input) {
100
- const qr = new QRCode(-1, QRErrorCorrectLevel.L);
101
- qr.addData(input);
102
- qr.make();
103
- return qr;
104
- }
105
- async function renderQrPngBase64(input, opts = {}) {
106
- const { scale = 6, marginModules = 4 } = opts;
107
- const qr = createQrMatrix(input);
108
- const modules = qr.getModuleCount();
109
- const size = (modules + marginModules * 2) * scale;
110
- const buf = Buffer.alloc(size * size * 4, 255);
111
- for (let row = 0; row < modules; row += 1) for (let col = 0; col < modules; col += 1) {
112
- if (!qr.isDark(row, col)) continue;
113
- const startX = (col + marginModules) * scale;
114
- const startY = (row + marginModules) * scale;
115
- for (let y = 0; y < scale; y += 1) {
116
- const pixelY = startY + y;
117
- for (let x = 0; x < scale; x += 1) fillPixel(buf, startX + x, pixelY, size, 0, 0, 0, 255);
118
- }
119
- }
120
- return encodePngRgba(buf, size, size).toString("base64");
121
- }
122
-
123
- //#endregion
124
- //#region src/web/login-qr.ts
125
- const ACTIVE_LOGIN_TTL_MS = 3 * 6e4;
126
- const activeLogins = /* @__PURE__ */ new Map();
127
- function closeSocket(sock) {
128
- try {
129
- sock.ws?.close();
130
- } catch {}
131
- }
132
- async function resetActiveLogin(accountId, reason) {
133
- const login = activeLogins.get(accountId);
134
- if (login) {
135
- closeSocket(login.sock);
136
- activeLogins.delete(accountId);
137
- }
138
- if (reason) logInfo(reason);
139
- }
140
- function isLoginFresh(login) {
141
- return Date.now() - login.startedAt < ACTIVE_LOGIN_TTL_MS;
142
- }
143
- function attachLoginWaiter(accountId, login) {
144
- login.waitPromise = waitForWaConnection(login.sock).then(() => {
145
- const current = activeLogins.get(accountId);
146
- if (current?.id === login.id) current.connected = true;
147
- }).catch((err) => {
148
- const current = activeLogins.get(accountId);
149
- if (current?.id !== login.id) return;
150
- current.error = formatError(err);
151
- current.errorStatus = getStatusCode(err);
152
- });
153
- }
154
- async function restartLoginSocket(login, runtime) {
155
- if (login.restartAttempted) return false;
156
- login.restartAttempted = true;
157
- runtime.log(info("WhatsApp asked for a restart after pairing (code 515); retrying connection once…"));
158
- closeSocket(login.sock);
159
- try {
160
- login.sock = await createWaSocket(false, login.verbose, { authDir: login.authDir });
161
- login.connected = false;
162
- login.error = void 0;
163
- login.errorStatus = void 0;
164
- attachLoginWaiter(login.accountId, login);
165
- return true;
166
- } catch (err) {
167
- login.error = formatError(err);
168
- login.errorStatus = getStatusCode(err);
169
- return false;
170
- }
171
- }
172
- async function startWebLoginWithQr(opts = {}) {
173
- const runtime = opts.runtime ?? defaultRuntime;
174
- const account = resolveWhatsAppAccount({
175
- cfg: loadConfig(),
176
- accountId: opts.accountId
177
- });
178
- const hasWeb = await webAuthExists(account.authDir);
179
- const selfId = readWebSelfId(account.authDir);
180
- if (hasWeb && !opts.force) return { message: `WhatsApp is already linked (${selfId.e164 ?? selfId.jid ?? "unknown"}). Say “relink” if you want a fresh QR.` };
181
- const existing = activeLogins.get(account.accountId);
182
- if (existing && isLoginFresh(existing) && existing.qrDataUrl) return {
183
- qrDataUrl: existing.qrDataUrl,
184
- message: "QR already active. Scan it in WhatsApp → Linked Devices."
185
- };
186
- await resetActiveLogin(account.accountId);
187
- let resolveQr = null;
188
- let rejectQr = null;
189
- const qrPromise = new Promise((resolve, reject) => {
190
- resolveQr = resolve;
191
- rejectQr = reject;
192
- });
193
- const qrTimer = setTimeout(() => {
194
- rejectQr?.(/* @__PURE__ */ new Error("Timed out waiting for WhatsApp QR"));
195
- }, Math.max(opts.timeoutMs ?? 3e4, 5e3));
196
- let sock;
197
- let pendingQr = null;
198
- try {
199
- sock = await createWaSocket(false, Boolean(opts.verbose), {
200
- authDir: account.authDir,
201
- onQr: (qr) => {
202
- if (pendingQr) return;
203
- pendingQr = qr;
204
- const current = activeLogins.get(account.accountId);
205
- if (current && !current.qr) current.qr = qr;
206
- clearTimeout(qrTimer);
207
- runtime.log(info("WhatsApp QR received."));
208
- resolveQr?.(qr);
209
- }
210
- });
211
- } catch (err) {
212
- clearTimeout(qrTimer);
213
- await resetActiveLogin(account.accountId);
214
- return { message: `Failed to start WhatsApp login: ${String(err)}` };
215
- }
216
- const login = {
217
- accountId: account.accountId,
218
- authDir: account.authDir,
219
- isLegacyAuthDir: account.isLegacyAuthDir,
220
- id: randomUUID(),
221
- sock,
222
- startedAt: Date.now(),
223
- connected: false,
224
- waitPromise: Promise.resolve(),
225
- restartAttempted: false,
226
- verbose: Boolean(opts.verbose)
227
- };
228
- activeLogins.set(account.accountId, login);
229
- if (pendingQr && !login.qr) login.qr = pendingQr;
230
- attachLoginWaiter(account.accountId, login);
231
- let qr;
232
- try {
233
- qr = await qrPromise;
234
- } catch (err) {
235
- clearTimeout(qrTimer);
236
- await resetActiveLogin(account.accountId);
237
- return { message: `Failed to get QR: ${String(err)}` };
238
- }
239
- login.qrDataUrl = `data:image/png;base64,${await renderQrPngBase64(qr)}`;
240
- return {
241
- qrDataUrl: login.qrDataUrl,
242
- message: "Scan this QR in WhatsApp → Linked Devices."
243
- };
244
- }
245
- async function waitForWebLogin(opts = {}) {
246
- const runtime = opts.runtime ?? defaultRuntime;
247
- const account = resolveWhatsAppAccount({
248
- cfg: loadConfig(),
249
- accountId: opts.accountId
250
- });
251
- const activeLogin = activeLogins.get(account.accountId);
252
- if (!activeLogin) return {
253
- connected: false,
254
- message: "No active WhatsApp login in progress."
255
- };
256
- const login = activeLogin;
257
- if (!isLoginFresh(login)) {
258
- await resetActiveLogin(account.accountId);
259
- return {
260
- connected: false,
261
- message: "The login QR expired. Ask me to generate a new one."
262
- };
263
- }
264
- const timeoutMs = Math.max(opts.timeoutMs ?? 12e4, 1e3);
265
- const deadline = Date.now() + timeoutMs;
266
- while (true) {
267
- const remaining = deadline - Date.now();
268
- if (remaining <= 0) return {
269
- connected: false,
270
- message: "Still waiting for the QR scan. Let me know when you’ve scanned it."
271
- };
272
- const timeout = new Promise((resolve) => setTimeout(() => resolve("timeout"), remaining));
273
- if (await Promise.race([login.waitPromise.then(() => "done"), timeout]) === "timeout") return {
274
- connected: false,
275
- message: "Still waiting for the QR scan. Let me know when you’ve scanned it."
276
- };
277
- if (login.error) {
278
- if (login.errorStatus === DisconnectReason.loggedOut) {
279
- await logoutWeb({
280
- authDir: login.authDir,
281
- isLegacyAuthDir: login.isLegacyAuthDir,
282
- runtime
283
- });
284
- const message = "WhatsApp reported the session is logged out. Cleared cached web session; please scan a new QR.";
285
- await resetActiveLogin(account.accountId, message);
286
- runtime.log(danger(message));
287
- return {
288
- connected: false,
289
- message
290
- };
291
- }
292
- if (login.errorStatus === 515) {
293
- if (await restartLoginSocket(login, runtime) && isLoginFresh(login)) continue;
294
- }
295
- const message = `WhatsApp login failed: ${login.error}`;
296
- await resetActiveLogin(account.accountId, message);
297
- runtime.log(danger(message));
298
- return {
299
- connected: false,
300
- message
301
- };
302
- }
303
- if (login.connected) {
304
- const message = "✅ Linked! WhatsApp is ready.";
305
- runtime.log(success(message));
306
- await resetActiveLogin(account.accountId);
307
- return {
308
- connected: true,
309
- message
310
- };
311
- }
312
- return {
313
- connected: false,
314
- message: "Login ended without a connection."
315
- };
316
- }
317
- }
318
-
319
- //#endregion
320
- export { startWebLoginWithQr, waitForWebLogin };