@openclaw/whatsapp 2026.5.2-beta.2 → 2026.5.3-beta.1

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 (301) hide show
  1. package/dist/access-control-BQ3tCkH8.js +288 -0
  2. package/dist/account-config-CNQ33oav.js +47 -0
  3. package/dist/account-ids-DG18xddX.js +5 -0
  4. package/dist/accounts-BDqgpFEB.js +116 -0
  5. package/dist/action-runtime-DTGNgG-i.js +74 -0
  6. package/dist/action-runtime-api.js +2 -0
  7. package/dist/action-runtime.runtime.js +2 -0
  8. package/dist/active-listener-N7GFKsuN.js +11 -0
  9. package/dist/agent-tools-login-DpRxLNRB.js +89 -0
  10. package/dist/api.js +148 -0
  11. package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
  12. package/dist/auth-presence.js +32 -0
  13. package/dist/auth-store-BjCb50Ry.js +381 -0
  14. package/dist/channel-DQ-5Xoj9.js +542 -0
  15. package/dist/channel-config-api.js +2 -0
  16. package/dist/channel-plugin-api.js +2 -0
  17. package/dist/channel-react-action-Df20qAy9.js +42 -0
  18. package/dist/channel.runtime-DKXRnA8x.js +55 -0
  19. package/dist/channel.setup-DOHR2BGp.js +20 -0
  20. package/dist/command-policy-O8sRnqUV.js +8 -0
  21. package/dist/config-schema-Dmo66Ubb.js +27 -0
  22. package/dist/connection-controller-BiHAsTM8.js +596 -0
  23. package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
  24. package/dist/constants-DLGCIbfl.js +4 -0
  25. package/dist/constants.js +2 -0
  26. package/dist/contract-api.js +19 -0
  27. package/dist/creds-files-_2V8jzQa.js +19 -0
  28. package/dist/directory-config-DVs4ffXu.js +37 -0
  29. package/dist/directory-contract-api.js +2 -0
  30. package/dist/doctor-A9tXm9Om.js +48 -0
  31. package/dist/doctor-contract-api.js +10 -0
  32. package/dist/group-session-contract-B8QBn0I2.js +15 -0
  33. package/dist/identity-QHAlV7Fu.js +75 -0
  34. package/dist/index.js +18 -0
  35. package/dist/legacy-session-surface-api.js +8 -0
  36. package/dist/legacy-state-migrations-api.js +2 -0
  37. package/dist/light-runtime-api.js +5 -0
  38. package/dist/login-DymdrKca.js +52 -0
  39. package/dist/login-qr-DIS0Iv-7.js +378 -0
  40. package/dist/login-qr-api.js +2 -0
  41. package/dist/login-qr-runtime.js +16 -0
  42. package/dist/monitor-C4Fhg_lD.js +3349 -0
  43. package/dist/normalize-CWYiGkXw.js +2 -0
  44. package/dist/normalize-target-BPVHNsM5.js +74 -0
  45. package/dist/outbound-adapter-BssVnZdz.js +29 -0
  46. package/dist/outbound-base-Bq1UYEK5.js +119 -0
  47. package/dist/outbound-media-contract-CGss_QHy.js +163 -0
  48. package/dist/outbound-payload-test-api.js +2 -0
  49. package/dist/quoted-message-TENQzyxV.js +108 -0
  50. package/dist/reaction-level-CRVEVAfi.js +16 -0
  51. package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
  52. package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
  53. package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
  54. package/dist/runtime-6fZ67abR.js +8 -0
  55. package/dist/runtime-api.js +15 -0
  56. package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
  57. package/dist/secret-contract-api.js +5 -0
  58. package/dist/security-contract-DqH8JDX6.js +26 -0
  59. package/dist/security-contract-api.js +2 -0
  60. package/dist/send-CIyLFxdZ.js +234 -0
  61. package/dist/session-contract-B0efQf9P.js +27 -0
  62. package/dist/session-errors-CSuKZPub.js +63 -0
  63. package/dist/session.runtime-C1eSE_KK.js +13 -0
  64. package/dist/setup-core-DZKvpzbH.js +46 -0
  65. package/dist/setup-entry.js +23 -0
  66. package/dist/setup-plugin-api.js +2 -0
  67. package/dist/setup-surface-ieFnIW4g.js +344 -0
  68. package/dist/shared-D_wzSVar.js +307 -0
  69. package/dist/state-migrations-DnCdvoYD.js +39 -0
  70. package/dist/targets.js +2 -0
  71. package/dist/test-api.js +3 -0
  72. package/dist/text-runtime-C1zNiZeO.js +116 -0
  73. package/package.json +14 -6
  74. package/action-runtime-api.ts +0 -1
  75. package/action-runtime.runtime.ts +0 -1
  76. package/api.ts +0 -213
  77. package/auth-presence.ts +0 -80
  78. package/channel-config-api.ts +0 -1
  79. package/channel-plugin-api.ts +0 -3
  80. package/config-api.ts +0 -4
  81. package/constants.ts +0 -1
  82. package/contract-api.ts +0 -29
  83. package/directory-contract-api.ts +0 -4
  84. package/doctor-contract-api.ts +0 -8
  85. package/index.test.ts +0 -13
  86. package/index.ts +0 -16
  87. package/legacy-session-surface-api.ts +0 -6
  88. package/legacy-state-migrations-api.ts +0 -1
  89. package/light-runtime-api.ts +0 -12
  90. package/login-qr-api.ts +0 -1
  91. package/login-qr-runtime.ts +0 -23
  92. package/outbound-payload-test-api.ts +0 -1
  93. package/runtime-api.ts +0 -84
  94. package/secret-contract-api.ts +0 -4
  95. package/security-contract-api.ts +0 -4
  96. package/setup-entry.test.ts +0 -21
  97. package/setup-entry.ts +0 -21
  98. package/setup-plugin-api.ts +0 -3
  99. package/src/account-config.ts +0 -77
  100. package/src/account-ids.ts +0 -13
  101. package/src/account-types.ts +0 -5
  102. package/src/accounts.test.ts +0 -182
  103. package/src/accounts.ts +0 -176
  104. package/src/accounts.whatsapp-auth.test.ts +0 -59
  105. package/src/action-runtime-target-auth.ts +0 -27
  106. package/src/action-runtime.test.ts +0 -330
  107. package/src/action-runtime.ts +0 -76
  108. package/src/active-listener.test.ts +0 -65
  109. package/src/active-listener.ts +0 -17
  110. package/src/agent-tools-login.test.ts +0 -81
  111. package/src/agent-tools-login.ts +0 -113
  112. package/src/approval-auth.test.ts +0 -24
  113. package/src/approval-auth.ts +0 -27
  114. package/src/auth-store.runtime.ts +0 -1
  115. package/src/auth-store.test.ts +0 -311
  116. package/src/auth-store.ts +0 -502
  117. package/src/auto-reply/config.runtime.ts +0 -16
  118. package/src/auto-reply/constants.ts +0 -1
  119. package/src/auto-reply/deliver-reply.test.ts +0 -843
  120. package/src/auto-reply/deliver-reply.ts +0 -279
  121. package/src/auto-reply/loggers.ts +0 -6
  122. package/src/auto-reply/mentions.ts +0 -131
  123. package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
  124. package/src/auto-reply/monitor/ack-reaction.ts +0 -99
  125. package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
  126. package/src/auto-reply/monitor/broadcast.ts +0 -153
  127. package/src/auto-reply/monitor/commands.ts +0 -19
  128. package/src/auto-reply/monitor/echo.ts +0 -64
  129. package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
  130. package/src/auto-reply/monitor/group-activation.test.ts +0 -189
  131. package/src/auto-reply/monitor/group-activation.ts +0 -73
  132. package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
  133. package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
  134. package/src/auto-reply/monitor/group-gating.ts +0 -217
  135. package/src/auto-reply/monitor/group-members.test.ts +0 -56
  136. package/src/auto-reply/monitor/group-members.ts +0 -65
  137. package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
  138. package/src/auto-reply/monitor/inbound-context.ts +0 -92
  139. package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
  140. package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
  141. package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
  142. package/src/auto-reply/monitor/last-route.test.ts +0 -37
  143. package/src/auto-reply/monitor/last-route.ts +0 -61
  144. package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
  145. package/src/auto-reply/monitor/message-line.ts +0 -54
  146. package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
  147. package/src/auto-reply/monitor/on-message.ts +0 -291
  148. package/src/auto-reply/monitor/peer.ts +0 -17
  149. package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
  150. package/src/auto-reply/monitor/process-message.test.ts +0 -355
  151. package/src/auto-reply/monitor/process-message.ts +0 -531
  152. package/src/auto-reply/monitor/runtime-api.ts +0 -30
  153. package/src/auto-reply/monitor-state.test.ts +0 -64
  154. package/src/auto-reply/monitor-state.ts +0 -106
  155. package/src/auto-reply/monitor.ts +0 -600
  156. package/src/auto-reply/reply-resolver.runtime.ts +0 -1
  157. package/src/auto-reply/types.ts +0 -48
  158. package/src/auto-reply/util.ts +0 -63
  159. package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
  160. package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
  161. package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
  162. package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
  163. package/src/auto-reply.impl.ts +0 -6
  164. package/src/auto-reply.test-harness.ts +0 -421
  165. package/src/auto-reply.ts +0 -1
  166. package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
  167. package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
  168. package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
  169. package/src/channel-actions.runtime.ts +0 -7
  170. package/src/channel-actions.test.ts +0 -216
  171. package/src/channel-actions.ts +0 -84
  172. package/src/channel-outbound.test.ts +0 -131
  173. package/src/channel-outbound.ts +0 -36
  174. package/src/channel-react-action.runtime.ts +0 -7
  175. package/src/channel-react-action.test.ts +0 -294
  176. package/src/channel-react-action.ts +0 -84
  177. package/src/channel.runtime.ts +0 -117
  178. package/src/channel.setup.test.ts +0 -461
  179. package/src/channel.setup.ts +0 -28
  180. package/src/channel.ts +0 -334
  181. package/src/command-policy.ts +0 -7
  182. package/src/config-accessors.test.ts +0 -34
  183. package/src/config-accessors.ts +0 -22
  184. package/src/config-schema.test.ts +0 -121
  185. package/src/config-schema.ts +0 -6
  186. package/src/config-ui-hints.ts +0 -24
  187. package/src/connection-controller-registry.test.ts +0 -27
  188. package/src/connection-controller-registry.ts +0 -49
  189. package/src/connection-controller.test.ts +0 -282
  190. package/src/connection-controller.ts +0 -679
  191. package/src/creds-files.ts +0 -19
  192. package/src/creds-persistence.ts +0 -102
  193. package/src/directory-config.test.ts +0 -60
  194. package/src/directory-config.ts +0 -40
  195. package/src/directory-contract.test.ts +0 -56
  196. package/src/doctor-contract.ts +0 -11
  197. package/src/doctor.test.ts +0 -74
  198. package/src/doctor.ts +0 -56
  199. package/src/group-intro.ts +0 -15
  200. package/src/group-policy.test.ts +0 -36
  201. package/src/group-policy.ts +0 -40
  202. package/src/group-session-contract.ts +0 -20
  203. package/src/group-session-key.test.ts +0 -53
  204. package/src/group-session-key.ts +0 -41
  205. package/src/heartbeat.ts +0 -34
  206. package/src/identity.ts +0 -164
  207. package/src/inbound/access-control.test-harness.ts +0 -37
  208. package/src/inbound/access-control.test.ts +0 -375
  209. package/src/inbound/access-control.ts +0 -237
  210. package/src/inbound/dedupe.ts +0 -132
  211. package/src/inbound/extract.test.ts +0 -282
  212. package/src/inbound/extract.ts +0 -488
  213. package/src/inbound/lifecycle.ts +0 -39
  214. package/src/inbound/media.node.test.ts +0 -83
  215. package/src/inbound/media.ts +0 -102
  216. package/src/inbound/monitor.ts +0 -890
  217. package/src/inbound/runtime-api.ts +0 -7
  218. package/src/inbound/save-media.runtime.ts +0 -1
  219. package/src/inbound/send-api.test.ts +0 -307
  220. package/src/inbound/send-api.ts +0 -141
  221. package/src/inbound/send-result.ts +0 -61
  222. package/src/inbound/types.ts +0 -106
  223. package/src/inbound-context.contract.test.ts +0 -32
  224. package/src/inbound-policy.ts +0 -231
  225. package/src/inbound.media.test.ts +0 -320
  226. package/src/inbound.test.ts +0 -290
  227. package/src/inbound.ts +0 -9
  228. package/src/login-qr.test.ts +0 -483
  229. package/src/login-qr.ts +0 -542
  230. package/src/login.coverage.test.ts +0 -133
  231. package/src/login.test.ts +0 -89
  232. package/src/login.ts +0 -70
  233. package/src/logout.test.ts +0 -162
  234. package/src/media.test.ts +0 -480
  235. package/src/media.ts +0 -10
  236. package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
  237. package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
  238. package/src/monitor-inbox.behavior.test.ts +0 -5
  239. package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
  240. package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
  241. package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
  242. package/src/monitor-inbox.test-harness.ts +0 -304
  243. package/src/normalize-target.ts +0 -112
  244. package/src/normalize.ts +0 -6
  245. package/src/outbound-adapter.poll.test.ts +0 -62
  246. package/src/outbound-adapter.sendpayload.test.ts +0 -195
  247. package/src/outbound-adapter.ts +0 -36
  248. package/src/outbound-base.test.ts +0 -560
  249. package/src/outbound-base.ts +0 -244
  250. package/src/outbound-media-contract.ts +0 -278
  251. package/src/outbound-media.runtime.ts +0 -36
  252. package/src/outbound-payload.contract.test.ts +0 -61
  253. package/src/outbound-send-deps.ts +0 -1
  254. package/src/outbound-test-support.ts +0 -16
  255. package/src/pairing-security.test-harness.ts +0 -59
  256. package/src/qr-image.ts +0 -1
  257. package/src/qr-terminal.ts +0 -1
  258. package/src/quoted-message.test.ts +0 -83
  259. package/src/quoted-message.ts +0 -184
  260. package/src/reaction-level.test.ts +0 -94
  261. package/src/reaction-level.ts +0 -21
  262. package/src/reconnect.test.ts +0 -51
  263. package/src/reconnect.ts +0 -55
  264. package/src/resolve-outbound-target.test.ts +0 -265
  265. package/src/resolve-outbound-target.ts +0 -54
  266. package/src/resolve-target.test.ts +0 -97
  267. package/src/runtime-api.ts +0 -59
  268. package/src/runtime-group-policy.ts +0 -16
  269. package/src/runtime.ts +0 -9
  270. package/src/security-contract.ts +0 -47
  271. package/src/security-fix.ts +0 -71
  272. package/src/send.test.ts +0 -515
  273. package/src/send.ts +0 -287
  274. package/src/session-contract.test.ts +0 -31
  275. package/src/session-contract.ts +0 -43
  276. package/src/session-errors.ts +0 -125
  277. package/src/session-route.ts +0 -26
  278. package/src/session.runtime.ts +0 -8
  279. package/src/session.test.ts +0 -559
  280. package/src/session.ts +0 -330
  281. package/src/setup-core.ts +0 -52
  282. package/src/setup-finalize.ts +0 -446
  283. package/src/setup-surface.test.ts +0 -367
  284. package/src/setup-surface.ts +0 -69
  285. package/src/setup-test-helpers.ts +0 -216
  286. package/src/shared.ts +0 -291
  287. package/src/socket-timing.test.ts +0 -49
  288. package/src/socket-timing.ts +0 -38
  289. package/src/state-migrations.ts +0 -54
  290. package/src/status-issues.test.ts +0 -137
  291. package/src/status-issues.ts +0 -185
  292. package/src/system-prompt.test.ts +0 -199
  293. package/src/system-prompt.ts +0 -31
  294. package/src/targets-runtime.ts +0 -180
  295. package/src/test-helpers.ts +0 -690
  296. package/src/text-runtime.test.ts +0 -162
  297. package/src/text-runtime.ts +0 -11
  298. package/src/vcard.ts +0 -84
  299. package/targets.ts +0 -5
  300. package/test-api.ts +0 -2
  301. package/tsconfig.json +0 -16
@@ -1,83 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- cacheInboundMessageMeta,
4
- lookupInboundMessageMeta,
5
- lookupInboundMessageMetaForTarget,
6
- } from "./quoted-message.js";
7
-
8
- describe("quoted message metadata cache", () => {
9
- it("scopes cached metadata by account id", () => {
10
- cacheInboundMessageMeta("account-a", "1555@s.whatsapp.net", "msg-1", {
11
- participant: "111@s.whatsapp.net",
12
- body: "hello from a",
13
- fromMe: true,
14
- });
15
- cacheInboundMessageMeta("account-b", "1555@s.whatsapp.net", "msg-1", {
16
- participant: "222@s.whatsapp.net",
17
- body: "hello from b",
18
- fromMe: false,
19
- });
20
-
21
- expect(lookupInboundMessageMeta("account-a", "1555@s.whatsapp.net", "msg-1")).toEqual({
22
- participant: "111@s.whatsapp.net",
23
- body: "hello from a",
24
- fromMe: true,
25
- });
26
- expect(lookupInboundMessageMeta("account-b", "1555@s.whatsapp.net", "msg-1")).toEqual({
27
- participant: "222@s.whatsapp.net",
28
- body: "hello from b",
29
- fromMe: false,
30
- });
31
- });
32
-
33
- it("can recover the original remoteJid for a matching direct-chat target", () => {
34
- cacheInboundMessageMeta("account-c", "277038292303944@lid", "msg-2", {
35
- participant: "5511976136970@s.whatsapp.net",
36
- body: "hello from lid chat",
37
- fromMe: true,
38
- });
39
-
40
- expect(
41
- lookupInboundMessageMetaForTarget("account-c", "5511976136970@s.whatsapp.net", "msg-2"),
42
- ).toEqual({
43
- remoteJid: "277038292303944@lid",
44
- participant: "5511976136970@s.whatsapp.net",
45
- body: "hello from lid chat",
46
- fromMe: true,
47
- });
48
- expect(
49
- lookupInboundMessageMetaForTarget("account-c", "99999999999@s.whatsapp.net", "msg-2"),
50
- ).toBeUndefined();
51
- expect(
52
- lookupInboundMessageMetaForTarget("missing", "5511976136970@s.whatsapp.net", "msg-2"),
53
- ).toBeUndefined();
54
- });
55
-
56
- it("can recover a direct-chat remoteJid when only sender E164 was cached", () => {
57
- cacheInboundMessageMeta("account-e", "277038292303944@lid", "msg-4", {
58
- participantE164: "+5511976136970",
59
- body: "hello from e164 participant",
60
- });
61
-
62
- expect(
63
- lookupInboundMessageMetaForTarget("account-e", "5511976136970@s.whatsapp.net", "msg-4"),
64
- ).toEqual({
65
- remoteJid: "277038292303944@lid",
66
- participant: undefined,
67
- participantE164: "+5511976136970",
68
- body: "hello from e164 participant",
69
- fromMe: undefined,
70
- });
71
- });
72
-
73
- it("does not recover metadata from another chat when the target conversation differs", () => {
74
- cacheInboundMessageMeta("account-d", "120363400000000000@g.us", "msg-3", {
75
- participant: "111@s.whatsapp.net",
76
- body: "group secret",
77
- });
78
-
79
- expect(
80
- lookupInboundMessageMetaForTarget("account-d", "222@s.whatsapp.net", "msg-3"),
81
- ).toBeUndefined();
82
- });
83
- });
@@ -1,184 +0,0 @@
1
- import type { MiscMessageGenerationOptions } from "@whiskeysockets/baileys";
2
- import { jidToE164 } from "./text-runtime.js";
3
-
4
- // ── Inbound message metadata cache ──────────────────────────────────────
5
- // Maps messageId → { participant, participantE164, body, fromMe } so the
6
- // outbound adapter can
7
- // populate the quote key with the sender JID and preview text even though
8
- // the outbound path only receives a bare messageId string.
9
-
10
- type QuotedMeta = {
11
- participant?: string;
12
- participantE164?: string;
13
- body?: string;
14
- fromMe?: boolean;
15
- };
16
- type CacheEntry = QuotedMeta & { ts: number };
17
- type QuotedMetaLookup = QuotedMeta & { remoteJid: string };
18
-
19
- const CACHE_TTL_MS = 10 * 60 * 1000;
20
- const MAX_ENTRIES = 500;
21
- const cache = new Map<string, CacheEntry>();
22
-
23
- function makeCacheKey(accountId: string, remoteJid: string, messageId: string): string {
24
- return `${accountId}:${remoteJid}:${messageId}`;
25
- }
26
-
27
- export function cacheInboundMessageMeta(
28
- accountId: string,
29
- remoteJid: string,
30
- messageId: string,
31
- meta: QuotedMeta,
32
- ): void {
33
- if (!accountId || !messageId || !remoteJid) {
34
- return;
35
- }
36
- if (cache.size >= MAX_ENTRIES) {
37
- const oldest = cache.keys().next().value;
38
- if (oldest) {
39
- cache.delete(oldest);
40
- }
41
- }
42
- cache.set(makeCacheKey(accountId, remoteJid, messageId), { ...meta, ts: Date.now() });
43
- }
44
-
45
- export function lookupInboundMessageMeta(
46
- accountId: string,
47
- remoteJid: string,
48
- messageId: string,
49
- ): QuotedMeta | undefined {
50
- const cacheKey = makeCacheKey(accountId, remoteJid, messageId);
51
- const entry = cache.get(cacheKey);
52
- if (!entry) {
53
- return undefined;
54
- }
55
- if (Date.now() - entry.ts > CACHE_TTL_MS) {
56
- cache.delete(cacheKey);
57
- return undefined;
58
- }
59
- return {
60
- participant: entry.participant,
61
- participantE164: entry.participantE164,
62
- body: entry.body,
63
- fromMe: entry.fromMe,
64
- };
65
- }
66
-
67
- function normalizeComparableJid(jid: string | undefined): string | undefined {
68
- const normalized = jid?.trim().replace(/:\d+/, "").toLowerCase();
69
- return normalized || undefined;
70
- }
71
-
72
- function isGroupJid(jid: string | undefined): boolean {
73
- return Boolean(jid && jid.endsWith("@g.us"));
74
- }
75
-
76
- function areComparableE164sEqual(left: string | undefined, right: string | undefined): boolean {
77
- const normalizedLeft = left?.trim();
78
- const normalizedRight = right?.trim();
79
- if (!normalizedLeft || !normalizedRight) {
80
- return false;
81
- }
82
- return normalizedLeft === normalizedRight;
83
- }
84
-
85
- function areComparableJidsEqual(left: string | undefined, right: string | undefined): boolean {
86
- const normalizedLeft = normalizeComparableJid(left);
87
- const normalizedRight = normalizeComparableJid(right);
88
- if (!normalizedLeft || !normalizedRight) {
89
- return false;
90
- }
91
- if (normalizedLeft === normalizedRight) {
92
- return true;
93
- }
94
- const leftE164 = jidToE164(normalizedLeft);
95
- const rightE164 = jidToE164(normalizedRight);
96
- return Boolean(leftE164 && rightE164 && leftE164 === rightE164);
97
- }
98
-
99
- function matchesQuotedConversationTarget(targetJid: string, candidate: QuotedMetaLookup): boolean {
100
- if (areComparableJidsEqual(targetJid, candidate.remoteJid)) {
101
- return true;
102
- }
103
- if (isGroupJid(targetJid) || isGroupJid(candidate.remoteJid)) {
104
- return false;
105
- }
106
- return (
107
- areComparableJidsEqual(targetJid, candidate.participant) ||
108
- areComparableE164sEqual(jidToE164(targetJid) ?? undefined, candidate.participantE164)
109
- );
110
- }
111
-
112
- export function lookupInboundMessageMetaForTarget(
113
- accountId: string,
114
- targetJid: string,
115
- messageId: string,
116
- ): QuotedMetaLookup | undefined {
117
- if (!accountId || !messageId || !targetJid) {
118
- return undefined;
119
- }
120
- const exact = lookupInboundMessageMeta(accountId, targetJid, messageId);
121
- if (exact) {
122
- return {
123
- remoteJid: targetJid,
124
- participant: exact.participant,
125
- participantE164: exact.participantE164,
126
- body: exact.body,
127
- fromMe: exact.fromMe,
128
- };
129
- }
130
- const prefix = `${accountId}:`;
131
- const suffix = `:${messageId}`;
132
- let matched: QuotedMetaLookup | undefined;
133
- for (const [cacheKey, entry] of cache.entries()) {
134
- if (!cacheKey.startsWith(prefix) || !cacheKey.endsWith(suffix)) {
135
- continue;
136
- }
137
- if (Date.now() - entry.ts > CACHE_TTL_MS) {
138
- cache.delete(cacheKey);
139
- continue;
140
- }
141
- const remoteJid = cacheKey.slice(prefix.length, cacheKey.length - suffix.length);
142
- const candidate = {
143
- remoteJid,
144
- participant: entry.participant,
145
- participantE164: entry.participantE164,
146
- body: entry.body,
147
- fromMe: entry.fromMe,
148
- };
149
- if (!matchesQuotedConversationTarget(targetJid, candidate)) {
150
- continue;
151
- }
152
- if (matched) {
153
- return undefined;
154
- }
155
- matched = candidate;
156
- }
157
- return matched;
158
- }
159
-
160
- export function buildQuotedMessageOptions(params: {
161
- messageId?: string | null;
162
- remoteJid?: string | null;
163
- fromMe?: boolean;
164
- participant?: string;
165
- /** Original message text — shown in the quote preview bubble. */
166
- messageText?: string;
167
- }): MiscMessageGenerationOptions | undefined {
168
- const id = params.messageId?.trim();
169
- const remoteJid = params.remoteJid?.trim();
170
- if (!id || !remoteJid) {
171
- return undefined;
172
- }
173
- return {
174
- quoted: {
175
- key: {
176
- remoteJid,
177
- id,
178
- fromMe: params.fromMe ?? false,
179
- participant: params.participant,
180
- },
181
- message: { conversation: params.messageText ?? "" },
182
- },
183
- } as MiscMessageGenerationOptions;
184
- }
@@ -1,94 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
- import { describe, expect, it } from "vitest";
3
- import { resolveWhatsAppReactionLevel } from "./reaction-level.js";
4
-
5
- describe("resolveWhatsAppReactionLevel", () => {
6
- it("defaults to minimal level when reactionLevel is not set", () => {
7
- const cfg: OpenClawConfig = {
8
- channels: { whatsapp: {} },
9
- };
10
-
11
- const result = resolveWhatsAppReactionLevel({ cfg });
12
- expect(result).toEqual({
13
- level: "minimal",
14
- ackEnabled: false,
15
- agentReactionsEnabled: true,
16
- agentReactionGuidance: "minimal",
17
- });
18
- });
19
-
20
- it("returns off level with no reactions enabled", () => {
21
- const cfg: OpenClawConfig = {
22
- channels: { whatsapp: { reactionLevel: "off" } },
23
- };
24
-
25
- const result = resolveWhatsAppReactionLevel({ cfg });
26
- expect(result).toEqual({
27
- level: "off",
28
- ackEnabled: false,
29
- agentReactionsEnabled: false,
30
- });
31
- });
32
-
33
- it("returns ack level with only ackEnabled", () => {
34
- const cfg: OpenClawConfig = {
35
- channels: { whatsapp: { reactionLevel: "ack" } },
36
- };
37
-
38
- const result = resolveWhatsAppReactionLevel({ cfg });
39
- expect(result).toEqual({
40
- level: "ack",
41
- ackEnabled: true,
42
- agentReactionsEnabled: false,
43
- });
44
- });
45
-
46
- it("returns minimal level with agent reactions enabled and minimal guidance", () => {
47
- const cfg: OpenClawConfig = {
48
- channels: { whatsapp: { reactionLevel: "minimal" } },
49
- };
50
-
51
- const result = resolveWhatsAppReactionLevel({ cfg });
52
- expect(result).toEqual({
53
- level: "minimal",
54
- ackEnabled: false,
55
- agentReactionsEnabled: true,
56
- agentReactionGuidance: "minimal",
57
- });
58
- });
59
-
60
- it("returns extensive level with agent reactions enabled and extensive guidance", () => {
61
- const cfg: OpenClawConfig = {
62
- channels: { whatsapp: { reactionLevel: "extensive" } },
63
- };
64
-
65
- const result = resolveWhatsAppReactionLevel({ cfg });
66
- expect(result).toEqual({
67
- level: "extensive",
68
- ackEnabled: false,
69
- agentReactionsEnabled: true,
70
- agentReactionGuidance: "extensive",
71
- });
72
- });
73
-
74
- it("resolves reaction level from a specific account", () => {
75
- const cfg: OpenClawConfig = {
76
- channels: {
77
- whatsapp: {
78
- reactionLevel: "minimal",
79
- accounts: {
80
- work: { reactionLevel: "extensive" },
81
- },
82
- },
83
- },
84
- };
85
-
86
- const result = resolveWhatsAppReactionLevel({ cfg, accountId: "work" });
87
- expect(result).toEqual({
88
- level: "extensive",
89
- ackEnabled: false,
90
- agentReactionsEnabled: true,
91
- agentReactionGuidance: "extensive",
92
- });
93
- });
94
- });
@@ -1,21 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
- import { resolveReactionLevel, type ResolvedReactionLevel } from "openclaw/plugin-sdk/text-runtime";
3
- import { resolveMergedWhatsAppAccountConfig } from "./account-config.js";
4
-
5
- type ResolvedWhatsAppReactionLevel = ResolvedReactionLevel;
6
-
7
- /** Resolve the effective reaction level and its implications for WhatsApp. */
8
- export function resolveWhatsAppReactionLevel(params: {
9
- cfg: OpenClawConfig;
10
- accountId?: string;
11
- }): ResolvedWhatsAppReactionLevel {
12
- const account = resolveMergedWhatsAppAccountConfig({
13
- cfg: params.cfg,
14
- accountId: params.accountId,
15
- });
16
- return resolveReactionLevel({
17
- value: account.reactionLevel,
18
- defaultLevel: "minimal",
19
- invalidFallback: "minimal",
20
- });
21
- }
@@ -1,51 +0,0 @@
1
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2
- import { describe, expect, it } from "vitest";
3
- import {
4
- computeBackoff,
5
- DEFAULT_HEARTBEAT_SECONDS,
6
- DEFAULT_RECONNECT_POLICY,
7
- resolveHeartbeatSeconds,
8
- resolveReconnectPolicy,
9
- sleepWithAbort,
10
- } from "./reconnect.js";
11
-
12
- describe("web reconnect helpers", () => {
13
- const cfg: OpenClawConfig = {};
14
-
15
- it("resolves sane reconnect defaults with clamps", () => {
16
- const policy = resolveReconnectPolicy(cfg, {
17
- initialMs: 100,
18
- maxMs: 5,
19
- factor: 20,
20
- jitter: 2,
21
- maxAttempts: -1,
22
- });
23
-
24
- expect(policy.initialMs).toBe(250); // clamped to minimum
25
- expect(policy.maxMs).toBeGreaterThanOrEqual(policy.initialMs);
26
- expect(policy.factor).toBeLessThanOrEqual(10);
27
- expect(policy.jitter).toBeLessThanOrEqual(1);
28
- expect(policy.maxAttempts).toBeGreaterThanOrEqual(0);
29
- });
30
-
31
- it("computes increasing backoff with jitter", () => {
32
- const policy = { ...DEFAULT_RECONNECT_POLICY, jitter: 0 };
33
- const first = computeBackoff(policy, 1);
34
- const second = computeBackoff(policy, 2);
35
- expect(first).toBe(policy.initialMs);
36
- expect(second).toBeGreaterThan(first);
37
- expect(second).toBeLessThanOrEqual(policy.maxMs);
38
- });
39
-
40
- it("returns heartbeat default when unset", () => {
41
- expect(resolveHeartbeatSeconds(cfg)).toBe(DEFAULT_HEARTBEAT_SECONDS);
42
- expect(resolveHeartbeatSeconds(cfg, 5)).toBe(5);
43
- });
44
-
45
- it("sleepWithAbort rejects on abort", async () => {
46
- const controller = new AbortController();
47
- const promise = sleepWithAbort(50, controller.signal);
48
- controller.abort();
49
- await expect(promise).rejects.toThrow("aborted");
50
- });
51
- });
package/src/reconnect.ts DELETED
@@ -1,55 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
3
- import {
4
- computeBackoff,
5
- sleepWithAbort,
6
- type BackoffPolicy,
7
- } from "openclaw/plugin-sdk/runtime-env";
8
- import { clamp } from "openclaw/plugin-sdk/text-runtime";
9
-
10
- export type ReconnectPolicy = BackoffPolicy & {
11
- maxAttempts: number;
12
- };
13
-
14
- export const DEFAULT_HEARTBEAT_SECONDS = 60;
15
- export const DEFAULT_RECONNECT_POLICY: ReconnectPolicy = {
16
- initialMs: 2_000,
17
- maxMs: 30_000,
18
- factor: 1.8,
19
- jitter: 0.25,
20
- maxAttempts: 12,
21
- };
22
-
23
- export function resolveHeartbeatSeconds(cfg: OpenClawConfig, overrideSeconds?: number): number {
24
- const candidate = overrideSeconds ?? cfg.web?.heartbeatSeconds;
25
- if (typeof candidate === "number" && candidate > 0) {
26
- return candidate;
27
- }
28
- return DEFAULT_HEARTBEAT_SECONDS;
29
- }
30
-
31
- export function resolveReconnectPolicy(
32
- cfg: OpenClawConfig,
33
- overrides?: Partial<ReconnectPolicy>,
34
- ): ReconnectPolicy {
35
- const reconnectOverrides = cfg.web?.reconnect ?? {};
36
- const overrideConfig = overrides ?? {};
37
- const merged = {
38
- ...DEFAULT_RECONNECT_POLICY,
39
- ...reconnectOverrides,
40
- ...overrideConfig,
41
- } as ReconnectPolicy;
42
-
43
- merged.initialMs = Math.max(250, merged.initialMs);
44
- merged.maxMs = Math.max(merged.initialMs, merged.maxMs);
45
- merged.factor = clamp(merged.factor, 1.1, 10);
46
- merged.jitter = clamp(merged.jitter, 0, 1);
47
- merged.maxAttempts = Math.max(0, Math.floor(merged.maxAttempts));
48
- return merged;
49
- }
50
-
51
- export { computeBackoff, sleepWithAbort };
52
-
53
- export function newConnectionId() {
54
- return randomUUID();
55
- }