@openclaw/whatsapp 2026.5.2 → 2026.5.3-beta.2
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.
- package/dist/access-control-BQ3tCkH8.js +288 -0
- package/dist/account-config-CNQ33oav.js +47 -0
- package/dist/account-ids-DG18xddX.js +5 -0
- package/dist/accounts-BDqgpFEB.js +116 -0
- package/dist/action-runtime-DTGNgG-i.js +74 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/action-runtime.runtime.js +2 -0
- package/dist/active-listener-N7GFKsuN.js +11 -0
- package/dist/agent-tools-login-DpRxLNRB.js +89 -0
- package/dist/api.js +148 -0
- package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
- package/dist/auth-presence.js +32 -0
- package/dist/auth-store-BjCb50Ry.js +381 -0
- package/dist/channel-DQ-5Xoj9.js +542 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel-react-action-Df20qAy9.js +42 -0
- package/dist/channel.runtime-DKXRnA8x.js +55 -0
- package/dist/channel.setup-DOHR2BGp.js +20 -0
- package/dist/command-policy-O8sRnqUV.js +8 -0
- package/dist/config-schema-Dmo66Ubb.js +27 -0
- package/dist/connection-controller-BiHAsTM8.js +596 -0
- package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
- package/dist/constants-DLGCIbfl.js +4 -0
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +19 -0
- package/dist/creds-files-_2V8jzQa.js +19 -0
- package/dist/directory-config-DVs4ffXu.js +37 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/doctor-A9tXm9Om.js +48 -0
- package/dist/doctor-contract-api.js +10 -0
- package/dist/group-session-contract-B8QBn0I2.js +15 -0
- package/dist/identity-QHAlV7Fu.js +75 -0
- package/dist/index.js +18 -0
- package/dist/legacy-session-surface-api.js +8 -0
- package/dist/legacy-state-migrations-api.js +2 -0
- package/dist/light-runtime-api.js +5 -0
- package/dist/login-DymdrKca.js +52 -0
- package/dist/login-qr-DIS0Iv-7.js +378 -0
- package/dist/login-qr-api.js +2 -0
- package/dist/login-qr-runtime.js +16 -0
- package/dist/monitor-C4Fhg_lD.js +3349 -0
- package/dist/normalize-CWYiGkXw.js +2 -0
- package/dist/normalize-target-BPVHNsM5.js +74 -0
- package/dist/outbound-adapter-BssVnZdz.js +29 -0
- package/dist/outbound-base-Bq1UYEK5.js +119 -0
- package/dist/outbound-media-contract-CGss_QHy.js +163 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/quoted-message-TENQzyxV.js +108 -0
- package/dist/reaction-level-CRVEVAfi.js +16 -0
- package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
- package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
- package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
- package/dist/runtime-6fZ67abR.js +8 -0
- package/dist/runtime-api.js +15 -0
- package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-contract-DqH8JDX6.js +26 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-CIyLFxdZ.js +234 -0
- package/dist/session-contract-B0efQf9P.js +27 -0
- package/dist/session-errors-CSuKZPub.js +63 -0
- package/dist/session.runtime-C1eSE_KK.js +13 -0
- package/dist/setup-core-DZKvpzbH.js +46 -0
- package/dist/setup-entry.js +23 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-ieFnIW4g.js +344 -0
- package/dist/shared-D_wzSVar.js +307 -0
- package/dist/state-migrations-DnCdvoYD.js +39 -0
- package/dist/targets.js +2 -0
- package/dist/test-api.js +3 -0
- package/dist/text-runtime-C1zNiZeO.js +116 -0
- package/package.json +14 -6
- package/action-runtime-api.ts +0 -1
- package/action-runtime.runtime.ts +0 -1
- package/api.ts +0 -213
- package/auth-presence.ts +0 -80
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/constants.ts +0 -1
- package/contract-api.ts +0 -29
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -8
- package/index.test.ts +0 -13
- package/index.ts +0 -16
- package/legacy-session-surface-api.ts +0 -6
- package/legacy-state-migrations-api.ts +0 -1
- package/light-runtime-api.ts +0 -12
- package/login-qr-api.ts +0 -1
- package/login-qr-runtime.ts +0 -23
- package/outbound-payload-test-api.ts +0 -1
- package/runtime-api.ts +0 -84
- package/secret-contract-api.ts +0 -4
- package/security-contract-api.ts +0 -4
- package/setup-entry.test.ts +0 -21
- package/setup-entry.ts +0 -21
- package/setup-plugin-api.ts +0 -3
- package/src/account-config.ts +0 -77
- package/src/account-ids.ts +0 -13
- package/src/account-types.ts +0 -5
- package/src/accounts.test.ts +0 -182
- package/src/accounts.ts +0 -176
- package/src/accounts.whatsapp-auth.test.ts +0 -59
- package/src/action-runtime-target-auth.ts +0 -27
- package/src/action-runtime.test.ts +0 -330
- package/src/action-runtime.ts +0 -76
- package/src/active-listener.test.ts +0 -65
- package/src/active-listener.ts +0 -17
- package/src/agent-tools-login.test.ts +0 -81
- package/src/agent-tools-login.ts +0 -113
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -27
- package/src/auth-store.runtime.ts +0 -1
- package/src/auth-store.test.ts +0 -311
- package/src/auth-store.ts +0 -502
- package/src/auto-reply/config.runtime.ts +0 -16
- package/src/auto-reply/constants.ts +0 -1
- package/src/auto-reply/deliver-reply.test.ts +0 -843
- package/src/auto-reply/deliver-reply.ts +0 -279
- package/src/auto-reply/loggers.ts +0 -6
- package/src/auto-reply/mentions.ts +0 -131
- package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
- package/src/auto-reply/monitor/ack-reaction.ts +0 -99
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
- package/src/auto-reply/monitor/broadcast.ts +0 -153
- package/src/auto-reply/monitor/commands.ts +0 -19
- package/src/auto-reply/monitor/echo.ts +0 -64
- package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
- package/src/auto-reply/monitor/group-activation.test.ts +0 -189
- package/src/auto-reply/monitor/group-activation.ts +0 -73
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
- package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
- package/src/auto-reply/monitor/group-gating.ts +0 -217
- package/src/auto-reply/monitor/group-members.test.ts +0 -56
- package/src/auto-reply/monitor/group-members.ts +0 -65
- package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
- package/src/auto-reply/monitor/inbound-context.ts +0 -92
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
- package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
- package/src/auto-reply/monitor/last-route.test.ts +0 -37
- package/src/auto-reply/monitor/last-route.ts +0 -61
- package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
- package/src/auto-reply/monitor/message-line.ts +0 -54
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
- package/src/auto-reply/monitor/on-message.ts +0 -291
- package/src/auto-reply/monitor/peer.ts +0 -17
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
- package/src/auto-reply/monitor/process-message.test.ts +0 -355
- package/src/auto-reply/monitor/process-message.ts +0 -531
- package/src/auto-reply/monitor/runtime-api.ts +0 -30
- package/src/auto-reply/monitor-state.test.ts +0 -64
- package/src/auto-reply/monitor-state.ts +0 -106
- package/src/auto-reply/monitor.ts +0 -600
- package/src/auto-reply/reply-resolver.runtime.ts +0 -1
- package/src/auto-reply/types.ts +0 -48
- package/src/auto-reply/util.ts +0 -63
- package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
- package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
- package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
- package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
- package/src/auto-reply.impl.ts +0 -6
- package/src/auto-reply.test-harness.ts +0 -421
- package/src/auto-reply.ts +0 -1
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
- package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
- package/src/channel-actions.runtime.ts +0 -7
- package/src/channel-actions.test.ts +0 -216
- package/src/channel-actions.ts +0 -84
- package/src/channel-outbound.test.ts +0 -131
- package/src/channel-outbound.ts +0 -36
- package/src/channel-react-action.runtime.ts +0 -7
- package/src/channel-react-action.test.ts +0 -294
- package/src/channel-react-action.ts +0 -84
- package/src/channel.runtime.ts +0 -117
- package/src/channel.setup.test.ts +0 -461
- package/src/channel.setup.ts +0 -28
- package/src/channel.ts +0 -339
- package/src/command-policy.ts +0 -7
- package/src/config-accessors.test.ts +0 -34
- package/src/config-accessors.ts +0 -22
- package/src/config-schema.test.ts +0 -121
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -24
- package/src/connection-controller-registry.test.ts +0 -27
- package/src/connection-controller-registry.ts +0 -49
- package/src/connection-controller.test.ts +0 -282
- package/src/connection-controller.ts +0 -679
- package/src/creds-files.ts +0 -19
- package/src/creds-persistence.ts +0 -102
- package/src/directory-config.test.ts +0 -60
- package/src/directory-config.ts +0 -40
- package/src/directory-contract.test.ts +0 -56
- package/src/doctor-contract.ts +0 -11
- package/src/doctor.test.ts +0 -74
- package/src/doctor.ts +0 -56
- package/src/group-intro.ts +0 -15
- package/src/group-policy.test.ts +0 -36
- package/src/group-policy.ts +0 -40
- package/src/group-session-contract.ts +0 -20
- package/src/group-session-key.test.ts +0 -53
- package/src/group-session-key.ts +0 -41
- package/src/heartbeat.ts +0 -34
- package/src/identity.ts +0 -164
- package/src/inbound/access-control.test-harness.ts +0 -37
- package/src/inbound/access-control.test.ts +0 -375
- package/src/inbound/access-control.ts +0 -237
- package/src/inbound/dedupe.ts +0 -132
- package/src/inbound/extract.test.ts +0 -282
- package/src/inbound/extract.ts +0 -488
- package/src/inbound/lifecycle.ts +0 -39
- package/src/inbound/media.node.test.ts +0 -83
- package/src/inbound/media.ts +0 -102
- package/src/inbound/monitor.ts +0 -890
- package/src/inbound/runtime-api.ts +0 -7
- package/src/inbound/save-media.runtime.ts +0 -1
- package/src/inbound/send-api.test.ts +0 -319
- package/src/inbound/send-api.ts +0 -145
- package/src/inbound/send-result.ts +0 -61
- package/src/inbound/types.ts +0 -106
- package/src/inbound-context.contract.test.ts +0 -32
- package/src/inbound-policy.ts +0 -231
- package/src/inbound.media.test.ts +0 -320
- package/src/inbound.test.ts +0 -290
- package/src/inbound.ts +0 -9
- package/src/login-qr.test.ts +0 -483
- package/src/login-qr.ts +0 -542
- package/src/login.coverage.test.ts +0 -133
- package/src/login.test.ts +0 -89
- package/src/login.ts +0 -70
- package/src/logout.test.ts +0 -162
- package/src/media.test.ts +0 -480
- package/src/media.ts +0 -10
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
- package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
- package/src/monitor-inbox.behavior.test.ts +0 -5
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
- package/src/monitor-inbox.test-harness.ts +0 -304
- package/src/normalize-target.ts +0 -123
- package/src/normalize.ts +0 -7
- package/src/outbound-adapter.poll.test.ts +0 -62
- package/src/outbound-adapter.sendpayload.test.ts +0 -195
- package/src/outbound-adapter.ts +0 -36
- package/src/outbound-base.test.ts +0 -560
- package/src/outbound-base.ts +0 -244
- package/src/outbound-media-contract.ts +0 -278
- package/src/outbound-media.runtime.ts +0 -36
- package/src/outbound-payload.contract.test.ts +0 -61
- package/src/outbound-send-deps.ts +0 -1
- package/src/outbound-test-support.ts +0 -16
- package/src/pairing-security.test-harness.ts +0 -59
- package/src/qr-image.ts +0 -1
- package/src/qr-terminal.ts +0 -1
- package/src/quoted-message.test.ts +0 -83
- package/src/quoted-message.ts +0 -184
- package/src/reaction-level.test.ts +0 -94
- package/src/reaction-level.ts +0 -21
- package/src/reconnect.test.ts +0 -51
- package/src/reconnect.ts +0 -55
- package/src/resolve-outbound-target.test.ts +0 -288
- package/src/resolve-outbound-target.ts +0 -58
- package/src/resolve-target.test.ts +0 -120
- package/src/runtime-api.ts +0 -59
- package/src/runtime-group-policy.ts +0 -16
- package/src/runtime.ts +0 -9
- package/src/security-contract.ts +0 -47
- package/src/security-fix.ts +0 -71
- package/src/send.test.ts +0 -534
- package/src/send.ts +0 -292
- package/src/session-contract.test.ts +0 -31
- package/src/session-contract.ts +0 -43
- package/src/session-errors.ts +0 -125
- package/src/session-route.test.ts +0 -41
- package/src/session-route.ts +0 -32
- package/src/session.runtime.ts +0 -8
- package/src/session.test.ts +0 -559
- package/src/session.ts +0 -330
- package/src/setup-core.ts +0 -52
- package/src/setup-finalize.ts +0 -446
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -69
- package/src/setup-test-helpers.ts +0 -216
- package/src/shared.ts +0 -291
- package/src/socket-timing.test.ts +0 -49
- package/src/socket-timing.ts +0 -38
- package/src/state-migrations.ts +0 -54
- package/src/status-issues.test.ts +0 -137
- package/src/status-issues.ts +0 -185
- package/src/system-prompt.test.ts +0 -199
- package/src/system-prompt.ts +0 -31
- package/src/targets-runtime.ts +0 -180
- package/src/test-helpers.ts +0 -690
- package/src/text-runtime.test.ts +0 -162
- package/src/text-runtime.ts +0 -11
- package/src/vcard.ts +0 -84
- package/targets.ts +0 -5
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
package/dist/api.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { r as resolveDefaultWhatsAppAccountId, t as listAccountIds } from "./account-ids-DG18xddX.js";
|
|
2
|
+
import { a as resolveWhatsAppAccount, i as listWhatsAppAuthDirs, n as hasAnyWhatsAppAuth, o as resolveWhatsAppAuthDir, r as listEnabledWhatsAppAccounts, s as resolveWhatsAppMediaMaxBytes, t as DEFAULT_WHATSAPP_MEDIA_MAX_MB } from "./accounts-BDqgpFEB.js";
|
|
3
|
+
import { a as normalizeWhatsAppAllowFromEntries, i as looksLikeWhatsAppTargetId, o as normalizeWhatsAppMessagingTarget, r as isWhatsAppUserTarget, s as normalizeWhatsAppTarget, t as isWhatsAppGroupJid } from "./normalize-target-BPVHNsM5.js";
|
|
4
|
+
import { t as resolveWhatsAppOutboundTarget } from "./resolve-outbound-target-CN-Wo6IY.js";
|
|
5
|
+
import "./reaction-level-CRVEVAfi.js";
|
|
6
|
+
import { a as markdownToWhatsApp, i as jidToE164, n as assertWebChannel, o as resolveJidToE164, r as isSelfChatMode, s as toWhatsappJid, t as text_runtime_exports } from "./text-runtime-C1zNiZeO.js";
|
|
7
|
+
import "./send-CIyLFxdZ.js";
|
|
8
|
+
import { t as whatsappPlugin } from "./channel-DQ-5Xoj9.js";
|
|
9
|
+
import { n as WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS } from "./outbound-base-Bq1UYEK5.js";
|
|
10
|
+
import { t as whatsappCommandPolicy } from "./command-policy-O8sRnqUV.js";
|
|
11
|
+
import { a as resolveWhatsAppGroupToolPolicy, i as resolveWhatsAppGroupRequireMention, o as resolveWhatsAppGroupIntroHint } from "./shared-D_wzSVar.js";
|
|
12
|
+
import "./config-schema-Dmo66Ubb.js";
|
|
13
|
+
import { t as whatsappSetupPlugin } from "./channel.setup-DOHR2BGp.js";
|
|
14
|
+
import { t as DEFAULT_WEB_MEDIA_BYTES } from "./constants-DLGCIbfl.js";
|
|
15
|
+
import { n as listWhatsAppDirectoryGroupsFromConfig, r as listWhatsAppDirectoryPeersFromConfig } from "./directory-config-DVs4ffXu.js";
|
|
16
|
+
import { t as __testing } from "./access-control-BQ3tCkH8.js";
|
|
17
|
+
import "openclaw/plugin-sdk/channel-actions";
|
|
18
|
+
import "openclaw/plugin-sdk/account-resolution";
|
|
19
|
+
import "openclaw/plugin-sdk/core";
|
|
20
|
+
import "openclaw/plugin-sdk/account-id";
|
|
21
|
+
var CONFIG_DIR = text_runtime_exports.CONFIG_DIR;
|
|
22
|
+
var DEFAULT_LOG_DIR = text_runtime_exports.DEFAULT_LOG_DIR;
|
|
23
|
+
var DEFAULT_LOG_FILE = text_runtime_exports.DEFAULT_LOG_FILE;
|
|
24
|
+
var FILE_REF_EXTENSIONS_WITH_TLD = text_runtime_exports.FILE_REF_EXTENSIONS_WITH_TLD;
|
|
25
|
+
var SYSTEM_MARK = text_runtime_exports.SYSTEM_MARK;
|
|
26
|
+
var __test__ = text_runtime_exports.__test__;
|
|
27
|
+
var asNullableObjectRecord = text_runtime_exports.asNullableObjectRecord;
|
|
28
|
+
var asNullableRecord = text_runtime_exports.asNullableRecord;
|
|
29
|
+
var asOptionalObjectRecord = text_runtime_exports.asOptionalObjectRecord;
|
|
30
|
+
var asOptionalRecord = text_runtime_exports.asOptionalRecord;
|
|
31
|
+
var asRecord = text_runtime_exports.asRecord;
|
|
32
|
+
var bindAbortRelay = text_runtime_exports.bindAbortRelay;
|
|
33
|
+
var buildTimeoutAbortSignal = text_runtime_exports.buildTimeoutAbortSignal;
|
|
34
|
+
var chunkItems = text_runtime_exports.chunkItems;
|
|
35
|
+
var chunkMarkdownIR = text_runtime_exports.chunkMarkdownIR;
|
|
36
|
+
var clamp = text_runtime_exports.clamp;
|
|
37
|
+
var clampInt = text_runtime_exports.clampInt;
|
|
38
|
+
var clampNumber = text_runtime_exports.clampNumber;
|
|
39
|
+
var convertMarkdownTables = text_runtime_exports.convertMarkdownTables;
|
|
40
|
+
var createScopedExpiringIdCache = text_runtime_exports.createScopedExpiringIdCache;
|
|
41
|
+
var diagnosticLogger = text_runtime_exports.diagnosticLogger;
|
|
42
|
+
var displayPath = text_runtime_exports.displayPath;
|
|
43
|
+
var displayString = text_runtime_exports.displayString;
|
|
44
|
+
var ensureDir = text_runtime_exports.ensureDir;
|
|
45
|
+
var escapeRegExp = text_runtime_exports.escapeRegExp;
|
|
46
|
+
var fetchWithTimeout = text_runtime_exports.fetchWithTimeout;
|
|
47
|
+
var findCodeRegions = text_runtime_exports.findCodeRegions;
|
|
48
|
+
var getChildLogger = text_runtime_exports.getChildLogger;
|
|
49
|
+
var getDefaultRedactPatterns = text_runtime_exports.getDefaultRedactPatterns;
|
|
50
|
+
var getDiagnosticSessionStateCountForTest = text_runtime_exports.getDiagnosticSessionStateCountForTest;
|
|
51
|
+
var getLogger = text_runtime_exports.getLogger;
|
|
52
|
+
var getResolvedLoggerSettings = text_runtime_exports.getResolvedLoggerSettings;
|
|
53
|
+
var hasNonEmptyString = text_runtime_exports.hasNonEmptyString;
|
|
54
|
+
var hasOrphanReasoningCloseBoundary = text_runtime_exports.hasOrphanReasoningCloseBoundary;
|
|
55
|
+
var hasSystemMark = text_runtime_exports.hasSystemMark;
|
|
56
|
+
var isAutoLinkedFileRef = text_runtime_exports.isAutoLinkedFileRef;
|
|
57
|
+
var isFileLogLevelEnabled = text_runtime_exports.isFileLogLevelEnabled;
|
|
58
|
+
var isInsideCode = text_runtime_exports.isInsideCode;
|
|
59
|
+
var isRecord = text_runtime_exports.isRecord;
|
|
60
|
+
var localeLowercasePreservingWhitespace = text_runtime_exports.localeLowercasePreservingWhitespace;
|
|
61
|
+
var logActiveRuns = text_runtime_exports.logActiveRuns;
|
|
62
|
+
var logDebug = text_runtime_exports.logDebug;
|
|
63
|
+
var logError = text_runtime_exports.logError;
|
|
64
|
+
var logInfo = text_runtime_exports.logInfo;
|
|
65
|
+
var logLaneDequeue = text_runtime_exports.logLaneDequeue;
|
|
66
|
+
var logLaneEnqueue = text_runtime_exports.logLaneEnqueue;
|
|
67
|
+
var logMessageProcessed = text_runtime_exports.logMessageProcessed;
|
|
68
|
+
var logMessageQueued = text_runtime_exports.logMessageQueued;
|
|
69
|
+
var logRunAttempt = text_runtime_exports.logRunAttempt;
|
|
70
|
+
var logSessionStateChange = text_runtime_exports.logSessionStateChange;
|
|
71
|
+
var logSuccess = text_runtime_exports.logSuccess;
|
|
72
|
+
var logToolLoopAction = text_runtime_exports.logToolLoopAction;
|
|
73
|
+
var logWarn = text_runtime_exports.logWarn;
|
|
74
|
+
var logWebhookError = text_runtime_exports.logWebhookError;
|
|
75
|
+
var logWebhookProcessed = text_runtime_exports.logWebhookProcessed;
|
|
76
|
+
var logWebhookReceived = text_runtime_exports.logWebhookReceived;
|
|
77
|
+
var lowercasePreservingWhitespace = text_runtime_exports.lowercasePreservingWhitespace;
|
|
78
|
+
var markdownToIR = text_runtime_exports.markdownToIR;
|
|
79
|
+
var markdownToIRWithMeta = text_runtime_exports.markdownToIRWithMeta;
|
|
80
|
+
var normalizeArrayBackedTrimmedStringList = text_runtime_exports.normalizeArrayBackedTrimmedStringList;
|
|
81
|
+
var normalizeAtHashSlug = text_runtime_exports.normalizeAtHashSlug;
|
|
82
|
+
var normalizeCsvOrLooseStringList = text_runtime_exports.normalizeCsvOrLooseStringList;
|
|
83
|
+
var normalizeE164 = text_runtime_exports.normalizeE164;
|
|
84
|
+
var normalizeFastMode = text_runtime_exports.normalizeFastMode;
|
|
85
|
+
var normalizeHyphenSlug = text_runtime_exports.normalizeHyphenSlug;
|
|
86
|
+
var normalizeLowercaseStringOrEmpty = text_runtime_exports.normalizeLowercaseStringOrEmpty;
|
|
87
|
+
var normalizeNullableString = text_runtime_exports.normalizeNullableString;
|
|
88
|
+
var normalizeOptionalLowercaseString = text_runtime_exports.normalizeOptionalLowercaseString;
|
|
89
|
+
var normalizeOptionalString = text_runtime_exports.normalizeOptionalString;
|
|
90
|
+
var normalizeOptionalStringifiedId = text_runtime_exports.normalizeOptionalStringifiedId;
|
|
91
|
+
var normalizeOptionalThreadValue = text_runtime_exports.normalizeOptionalThreadValue;
|
|
92
|
+
var normalizeOptionalTrimmedStringList = text_runtime_exports.normalizeOptionalTrimmedStringList;
|
|
93
|
+
var normalizeSingleOrTrimmedStringList = text_runtime_exports.normalizeSingleOrTrimmedStringList;
|
|
94
|
+
var normalizeStringEntries = text_runtime_exports.normalizeStringEntries;
|
|
95
|
+
var normalizeStringEntriesLower = text_runtime_exports.normalizeStringEntriesLower;
|
|
96
|
+
var normalizeStringifiedOptionalString = text_runtime_exports.normalizeStringifiedOptionalString;
|
|
97
|
+
var normalizeTrimmedStringList = text_runtime_exports.normalizeTrimmedStringList;
|
|
98
|
+
var parseInlineDirectives = text_runtime_exports.parseInlineDirectives;
|
|
99
|
+
var pathExists = text_runtime_exports.pathExists;
|
|
100
|
+
var prefixSystemMessage = text_runtime_exports.prefixSystemMessage;
|
|
101
|
+
var readStringField = text_runtime_exports.readStringField;
|
|
102
|
+
var readStringValue = text_runtime_exports.readStringValue;
|
|
103
|
+
var redactIdentifier = text_runtime_exports.redactIdentifier;
|
|
104
|
+
var redactSensitiveLines = text_runtime_exports.redactSensitiveLines;
|
|
105
|
+
var redactSensitiveText = text_runtime_exports.redactSensitiveText;
|
|
106
|
+
var redactToolDetail = text_runtime_exports.redactToolDetail;
|
|
107
|
+
var renderMarkdownIRChunksWithinLimit = text_runtime_exports.renderMarkdownIRChunksWithinLimit;
|
|
108
|
+
var renderMarkdownWithMarkers = text_runtime_exports.renderMarkdownWithMarkers;
|
|
109
|
+
var resetDiagnosticStateForTest = text_runtime_exports.resetDiagnosticStateForTest;
|
|
110
|
+
var resetLogger = text_runtime_exports.resetLogger;
|
|
111
|
+
var resolveConfigDir = text_runtime_exports.resolveConfigDir;
|
|
112
|
+
var resolveGlobalMap = text_runtime_exports.resolveGlobalMap;
|
|
113
|
+
var resolveGlobalSingleton = text_runtime_exports.resolveGlobalSingleton;
|
|
114
|
+
var resolveHomeDir = text_runtime_exports.resolveHomeDir;
|
|
115
|
+
var resolvePrimaryStringValue = text_runtime_exports.resolvePrimaryStringValue;
|
|
116
|
+
var resolveReactionLevel = text_runtime_exports.resolveReactionLevel;
|
|
117
|
+
var resolveRedactOptions = text_runtime_exports.resolveRedactOptions;
|
|
118
|
+
var resolveStuckSessionWarnMs = text_runtime_exports.resolveStuckSessionWarnMs;
|
|
119
|
+
var resolveUserPath = text_runtime_exports.resolveUserPath;
|
|
120
|
+
var safeParseJson = text_runtime_exports.safeParseJson;
|
|
121
|
+
var sanitizeAssistantVisibleText = text_runtime_exports.sanitizeAssistantVisibleText;
|
|
122
|
+
var sanitizeAssistantVisibleTextWithOptions = text_runtime_exports.sanitizeAssistantVisibleTextWithOptions;
|
|
123
|
+
var sanitizeAssistantVisibleTextWithProfile = text_runtime_exports.sanitizeAssistantVisibleTextWithProfile;
|
|
124
|
+
var sanitizeReplyDirectiveId = text_runtime_exports.sanitizeReplyDirectiveId;
|
|
125
|
+
var sanitizeTerminalText = text_runtime_exports.sanitizeTerminalText;
|
|
126
|
+
var setLoggerOverride = text_runtime_exports.setLoggerOverride;
|
|
127
|
+
var sha256HexPrefix = text_runtime_exports.sha256HexPrefix;
|
|
128
|
+
var shortenHomeInString = text_runtime_exports.shortenHomeInString;
|
|
129
|
+
var shortenHomePath = text_runtime_exports.shortenHomePath;
|
|
130
|
+
var sleep = text_runtime_exports.sleep;
|
|
131
|
+
var sliceMarkdownIR = text_runtime_exports.sliceMarkdownIR;
|
|
132
|
+
var sliceUtf16Safe = text_runtime_exports.sliceUtf16Safe;
|
|
133
|
+
var startDiagnosticHeartbeat = text_runtime_exports.startDiagnosticHeartbeat;
|
|
134
|
+
var stopDiagnosticHeartbeat = text_runtime_exports.stopDiagnosticHeartbeat;
|
|
135
|
+
var stripAssistantInternalScaffolding = text_runtime_exports.stripAssistantInternalScaffolding;
|
|
136
|
+
var stripDowngradedToolCallText = text_runtime_exports.stripDowngradedToolCallText;
|
|
137
|
+
var stripInlineDirectiveTagsForDelivery = text_runtime_exports.stripInlineDirectiveTagsForDelivery;
|
|
138
|
+
var stripInlineDirectiveTagsForDisplay = text_runtime_exports.stripInlineDirectiveTagsForDisplay;
|
|
139
|
+
var stripInlineDirectiveTagsFromMessageForDisplay = text_runtime_exports.stripInlineDirectiveTagsFromMessageForDisplay;
|
|
140
|
+
var stripMarkdown = text_runtime_exports.stripMarkdown;
|
|
141
|
+
var stripMinimaxToolCallXml = text_runtime_exports.stripMinimaxToolCallXml;
|
|
142
|
+
var stripReasoningTagsFromText = text_runtime_exports.stripReasoningTagsFromText;
|
|
143
|
+
var stripToolCallXmlTags = text_runtime_exports.stripToolCallXmlTags;
|
|
144
|
+
var summarizeStringEntries = text_runtime_exports.summarizeStringEntries;
|
|
145
|
+
var toPinoLikeLogger = text_runtime_exports.toPinoLikeLogger;
|
|
146
|
+
var truncateUtf16Safe = text_runtime_exports.truncateUtf16Safe;
|
|
147
|
+
var withTimeout = text_runtime_exports.withTimeout;
|
|
148
|
+
export { CONFIG_DIR, DEFAULT_LOG_DIR, DEFAULT_LOG_FILE, DEFAULT_WEB_MEDIA_BYTES, DEFAULT_WHATSAPP_MEDIA_MAX_MB, FILE_REF_EXTENSIONS_WITH_TLD, SYSTEM_MARK, WHATSAPP_LEGACY_OUTBOUND_SEND_DEP_KEYS, __test__, asNullableObjectRecord, asNullableRecord, asOptionalObjectRecord, asOptionalRecord, asRecord, assertWebChannel, bindAbortRelay, buildTimeoutAbortSignal, chunkItems, chunkMarkdownIR, clamp, clampInt, clampNumber, convertMarkdownTables, createScopedExpiringIdCache, diagnosticLogger, displayPath, displayString, ensureDir, escapeRegExp, fetchWithTimeout, findCodeRegions, getChildLogger, getDefaultRedactPatterns, getDiagnosticSessionStateCountForTest, getLogger, getResolvedLoggerSettings, hasAnyWhatsAppAuth, hasNonEmptyString, hasOrphanReasoningCloseBoundary, hasSystemMark, isAutoLinkedFileRef, isFileLogLevelEnabled, isInsideCode, isRecord, isSelfChatMode, isWhatsAppGroupJid, isWhatsAppUserTarget, jidToE164, listEnabledWhatsAppAccounts, listAccountIds as listWhatsAppAccountIds, listWhatsAppAuthDirs, listWhatsAppDirectoryGroupsFromConfig, listWhatsAppDirectoryPeersFromConfig, localeLowercasePreservingWhitespace, logActiveRuns, logDebug, logError, logInfo, logLaneDequeue, logLaneEnqueue, logMessageProcessed, logMessageQueued, logRunAttempt, logSessionStateChange, logSuccess, logToolLoopAction, logWarn, logWebhookError, logWebhookProcessed, logWebhookReceived, looksLikeWhatsAppTargetId, lowercasePreservingWhitespace, markdownToIR, markdownToIRWithMeta, markdownToWhatsApp, normalizeArrayBackedTrimmedStringList, normalizeAtHashSlug, normalizeCsvOrLooseStringList, normalizeE164, normalizeFastMode, normalizeHyphenSlug, normalizeLowercaseStringOrEmpty, normalizeNullableString, normalizeOptionalLowercaseString, normalizeOptionalString, normalizeOptionalStringifiedId, normalizeOptionalThreadValue, normalizeOptionalTrimmedStringList, normalizeSingleOrTrimmedStringList, normalizeStringEntries, normalizeStringEntriesLower, normalizeStringifiedOptionalString, normalizeTrimmedStringList, normalizeWhatsAppAllowFromEntries, normalizeWhatsAppMessagingTarget, normalizeWhatsAppTarget, parseInlineDirectives, pathExists, prefixSystemMessage, readStringField, readStringValue, redactIdentifier, redactSensitiveLines, redactSensitiveText, redactToolDetail, renderMarkdownIRChunksWithinLimit, renderMarkdownWithMarkers, resetDiagnosticStateForTest, resetLogger, resolveConfigDir, resolveDefaultWhatsAppAccountId, resolveGlobalMap, resolveGlobalSingleton, resolveHomeDir, resolveJidToE164, resolvePrimaryStringValue, resolveReactionLevel, resolveRedactOptions, resolveStuckSessionWarnMs, resolveUserPath, resolveWhatsAppAccount, resolveWhatsAppAuthDir, resolveWhatsAppGroupIntroHint, resolveWhatsAppGroupRequireMention, resolveWhatsAppGroupToolPolicy, resolveWhatsAppMediaMaxBytes, resolveWhatsAppOutboundTarget, safeParseJson, sanitizeAssistantVisibleText, sanitizeAssistantVisibleTextWithOptions, sanitizeAssistantVisibleTextWithProfile, sanitizeReplyDirectiveId, sanitizeTerminalText, setLoggerOverride, sha256HexPrefix, shortenHomeInString, shortenHomePath, sleep, sliceMarkdownIR, sliceUtf16Safe, startDiagnosticHeartbeat, stopDiagnosticHeartbeat, stripAssistantInternalScaffolding, stripDowngradedToolCallText, stripInlineDirectiveTagsForDelivery, stripInlineDirectiveTagsForDisplay, stripInlineDirectiveTagsFromMessageForDisplay, stripMarkdown, stripMinimaxToolCallXml, stripReasoningTagsFromText, stripToolCallXmlTags, summarizeStringEntries, toPinoLikeLogger, toWhatsappJid, truncateUtf16Safe, __testing as whatsappAccessControlTesting, whatsappCommandPolicy, whatsappPlugin, whatsappSetupPlugin, withTimeout };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { transcribeFirstAudio as transcribeFirstAudio$1 } from "openclaw/plugin-sdk/media-runtime";
|
|
2
|
+
//#region extensions/whatsapp/src/auto-reply/monitor/audio-preflight.runtime.ts
|
|
3
|
+
async function transcribeFirstAudio(...args) {
|
|
4
|
+
return await transcribeFirstAudio$1(...args);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { transcribeFirstAudio };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { t as hasWebCredsSync } from "./creds-files-_2V8jzQa.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { resolveOAuthDir } from "openclaw/plugin-sdk/state-paths";
|
|
5
|
+
import { resolveUserPath } from "openclaw/plugin-sdk/account-resolution";
|
|
6
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
7
|
+
//#region extensions/whatsapp/auth-presence.ts
|
|
8
|
+
function addAccountAuthDirs(authDirs, accountId, authDir, accountsRoot, env) {
|
|
9
|
+
authDirs.add(path.join(accountsRoot, normalizeAccountId(accountId)));
|
|
10
|
+
const configuredAuthDir = authDir?.trim();
|
|
11
|
+
if (configuredAuthDir) authDirs.add(resolveUserPath(configuredAuthDir, env));
|
|
12
|
+
}
|
|
13
|
+
function listWhatsAppAuthDirs(cfg, env = process.env) {
|
|
14
|
+
const oauthDir = resolveOAuthDir(env);
|
|
15
|
+
const accountsRoot = path.join(oauthDir, "whatsapp");
|
|
16
|
+
const channel = cfg.channels?.whatsapp;
|
|
17
|
+
const authDirs = new Set([oauthDir, path.join(accountsRoot, DEFAULT_ACCOUNT_ID)]);
|
|
18
|
+
addAccountAuthDirs(authDirs, DEFAULT_ACCOUNT_ID, void 0, accountsRoot, env);
|
|
19
|
+
if (channel?.defaultAccount?.trim()) addAccountAuthDirs(authDirs, channel.defaultAccount, channel.accounts?.[channel.defaultAccount]?.authDir, accountsRoot, env);
|
|
20
|
+
const accounts = channel?.accounts;
|
|
21
|
+
if (accounts) for (const [accountId, account] of Object.entries(accounts)) addAccountAuthDirs(authDirs, accountId, account?.authDir, accountsRoot, env);
|
|
22
|
+
try {
|
|
23
|
+
const entries = fs.readdirSync(accountsRoot, { withFileTypes: true });
|
|
24
|
+
for (const entry of entries) if (entry.isDirectory()) authDirs.add(path.join(accountsRoot, entry.name));
|
|
25
|
+
} catch {}
|
|
26
|
+
return [...authDirs];
|
|
27
|
+
}
|
|
28
|
+
function hasAnyWhatsAppAuth(params, env = process.env) {
|
|
29
|
+
return listWhatsAppAuthDirs(params && typeof params === "object" && "cfg" in params ? params.cfg : params, params && typeof params === "object" && "cfg" in params ? params.env ?? env : env).some((authDir) => hasWebCredsSync(authDir));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { hasAnyWhatsAppAuth };
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { n as resolveWebCredsBackupPath, r as resolveWebCredsPath } from "./creds-files-_2V8jzQa.js";
|
|
2
|
+
import { t as text_runtime_exports } from "./text-runtime-C1zNiZeO.js";
|
|
3
|
+
import { c as resolveComparableIdentity } from "./identity-QHAlV7Fu.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { resolveOAuthDir as resolveOAuthDir$1 } from "openclaw/plugin-sdk/state-paths";
|
|
7
|
+
import { formatCliCommand } from "openclaw/plugin-sdk/cli-runtime";
|
|
8
|
+
import { defaultRuntime, getChildLogger, info, success } from "openclaw/plugin-sdk/runtime-env";
|
|
9
|
+
import fs$1 from "node:fs/promises";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/routing";
|
|
12
|
+
//#region extensions/whatsapp/src/creds-persistence.ts
|
|
13
|
+
const CREDS_FILE_MODE = 384;
|
|
14
|
+
const CREDS_SAVE_FLUSH_TIMEOUT_MS = 15e3;
|
|
15
|
+
const credsSaveQueues = /* @__PURE__ */ new Map();
|
|
16
|
+
async function stringifyCreds(creds) {
|
|
17
|
+
const { BufferJSON } = await import("./session.runtime-C1eSE_KK.js").then((n) => n.a);
|
|
18
|
+
return JSON.stringify(creds, BufferJSON.replacer);
|
|
19
|
+
}
|
|
20
|
+
async function syncDirectory(dirPath) {
|
|
21
|
+
let handle;
|
|
22
|
+
try {
|
|
23
|
+
handle = await fs$1.open(dirPath, "r");
|
|
24
|
+
await handle.sync();
|
|
25
|
+
} catch {} finally {
|
|
26
|
+
await handle?.close().catch(() => {});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function writeCredsJsonAtomically(authDir, creds) {
|
|
30
|
+
const credsPath = resolveWebCredsPath(authDir);
|
|
31
|
+
const tempPath = path.join(authDir, `.creds.${process.pid}.${randomUUID()}.tmp`);
|
|
32
|
+
const json = await stringifyCreds(creds);
|
|
33
|
+
let handle;
|
|
34
|
+
try {
|
|
35
|
+
handle = await fs$1.open(tempPath, "w", CREDS_FILE_MODE);
|
|
36
|
+
await handle.writeFile(json, { encoding: "utf-8" });
|
|
37
|
+
await handle.sync();
|
|
38
|
+
await handle.close();
|
|
39
|
+
handle = void 0;
|
|
40
|
+
await fs$1.rename(tempPath, credsPath);
|
|
41
|
+
await fs$1.chmod(credsPath, CREDS_FILE_MODE).catch(() => {});
|
|
42
|
+
await syncDirectory(path.dirname(credsPath));
|
|
43
|
+
} catch (error) {
|
|
44
|
+
await handle?.close().catch(() => {});
|
|
45
|
+
await fs$1.rm(tempPath, { force: true }).catch(() => {});
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function enqueueCredsSave(authDir, saveCreds, onError) {
|
|
50
|
+
const next = (credsSaveQueues.get(authDir) ?? Promise.resolve()).then(() => saveCreds()).catch((error) => {
|
|
51
|
+
onError(error);
|
|
52
|
+
}).finally(() => {
|
|
53
|
+
if (credsSaveQueues.get(authDir) === next) credsSaveQueues.delete(authDir);
|
|
54
|
+
});
|
|
55
|
+
credsSaveQueues.set(authDir, next);
|
|
56
|
+
}
|
|
57
|
+
function waitForCredsSaveQueue(authDir) {
|
|
58
|
+
if (authDir) return credsSaveQueues.get(authDir) ?? Promise.resolve();
|
|
59
|
+
return Promise.all(credsSaveQueues.values()).then(() => {});
|
|
60
|
+
}
|
|
61
|
+
async function waitForCredsSaveQueueWithTimeout(authDir, timeoutMs = CREDS_SAVE_FLUSH_TIMEOUT_MS) {
|
|
62
|
+
let flushTimeout;
|
|
63
|
+
return await Promise.race([waitForCredsSaveQueue(authDir).then(() => "drained"), new Promise((resolve) => {
|
|
64
|
+
flushTimeout = setTimeout(() => resolve("timed_out"), timeoutMs);
|
|
65
|
+
})]).finally(() => {
|
|
66
|
+
if (flushTimeout) clearTimeout(flushTimeout);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region extensions/whatsapp/src/auth-store.ts
|
|
71
|
+
const WHATSAPP_AUTH_UNSTABLE_CODE = "whatsapp-auth-unstable";
|
|
72
|
+
const authStoreLogger = getChildLogger({ module: "web-auth-store" });
|
|
73
|
+
const emptyWebSelfId = () => ({
|
|
74
|
+
e164: null,
|
|
75
|
+
jid: null,
|
|
76
|
+
lid: null
|
|
77
|
+
});
|
|
78
|
+
var WhatsAppAuthUnstableError = class extends Error {
|
|
79
|
+
constructor(message = "WhatsApp auth state is still stabilizing; retry shortly.") {
|
|
80
|
+
super(message);
|
|
81
|
+
this.code = WHATSAPP_AUTH_UNSTABLE_CODE;
|
|
82
|
+
this.name = "WhatsAppAuthUnstableError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function resolveDefaultWebAuthDir() {
|
|
86
|
+
return path.join(resolveOAuthDir$1(), "whatsapp", DEFAULT_ACCOUNT_ID);
|
|
87
|
+
}
|
|
88
|
+
const WA_WEB_AUTH_DIR = resolveDefaultWebAuthDir();
|
|
89
|
+
function readCredsJsonRaw(filePath) {
|
|
90
|
+
try {
|
|
91
|
+
if (!fs.existsSync(filePath)) return null;
|
|
92
|
+
const stats = fs.statSync(filePath);
|
|
93
|
+
if (!stats.isFile() || stats.size <= 1) return null;
|
|
94
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function waitForWebAuthBarrier(authDir, context) {
|
|
100
|
+
const result = await waitForCredsSaveQueueWithTimeout(authDir);
|
|
101
|
+
if (result === "timed_out") authStoreLogger.warn({
|
|
102
|
+
authDir,
|
|
103
|
+
context
|
|
104
|
+
}, "timed out waiting for queued WhatsApp creds save before auth read");
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
async function restoreCredsFromBackupIfNeeded(authDir) {
|
|
108
|
+
const logger = getChildLogger({ module: "web-session" });
|
|
109
|
+
let tempRestorePath = null;
|
|
110
|
+
try {
|
|
111
|
+
const credsPath = resolveWebCredsPath(authDir);
|
|
112
|
+
const backupPath = resolveWebCredsBackupPath(authDir);
|
|
113
|
+
const raw = readCredsJsonRaw(credsPath);
|
|
114
|
+
if (raw) {
|
|
115
|
+
JSON.parse(raw);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const backupRaw = readCredsJsonRaw(backupPath);
|
|
119
|
+
if (!backupRaw) return false;
|
|
120
|
+
if (!(await fs$1.lstat(backupPath).catch(() => null))?.isFile()) return false;
|
|
121
|
+
JSON.parse(backupRaw);
|
|
122
|
+
tempRestorePath = path.join(authDir, `.creds.restore-${randomUUID()}.tmp`);
|
|
123
|
+
await fs$1.writeFile(tempRestorePath, backupRaw, {
|
|
124
|
+
encoding: "utf-8",
|
|
125
|
+
mode: 384,
|
|
126
|
+
flag: "wx"
|
|
127
|
+
});
|
|
128
|
+
await fs$1.rename(tempRestorePath, credsPath);
|
|
129
|
+
tempRestorePath = null;
|
|
130
|
+
logger.warn({ credsPath }, "restored corrupted WhatsApp creds.json from backup");
|
|
131
|
+
return true;
|
|
132
|
+
} catch {} finally {
|
|
133
|
+
if (tempRestorePath) await fs$1.rm(tempRestorePath, { force: true }).catch(() => {});
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
async function webAuthExists(authDir = resolveDefaultWebAuthDir()) {
|
|
138
|
+
const resolvedAuthDir = (0, text_runtime_exports.resolveUserPath)(authDir);
|
|
139
|
+
const credsPath = resolveWebCredsPath(resolvedAuthDir);
|
|
140
|
+
try {
|
|
141
|
+
await fs$1.access(resolvedAuthDir);
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const stats = await fs$1.stat(credsPath);
|
|
147
|
+
if (!stats.isFile() || stats.size <= 1) return false;
|
|
148
|
+
const raw = await fs$1.readFile(credsPath, "utf-8");
|
|
149
|
+
JSON.parse(raw);
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function resolveWebAuthState(params) {
|
|
156
|
+
if (params.barrierResult === "timed_out") return "unstable";
|
|
157
|
+
return params.linked ? "linked" : "not-linked";
|
|
158
|
+
}
|
|
159
|
+
async function readWebAuthStateCore(authDir, context) {
|
|
160
|
+
const resolvedAuthDir = (0, text_runtime_exports.resolveUserPath)(authDir);
|
|
161
|
+
const barrierResult = await waitForWebAuthBarrier(resolvedAuthDir, context);
|
|
162
|
+
const linked = await webAuthExists(resolvedAuthDir);
|
|
163
|
+
return {
|
|
164
|
+
authDir: resolvedAuthDir,
|
|
165
|
+
linked,
|
|
166
|
+
state: resolveWebAuthState({
|
|
167
|
+
linked,
|
|
168
|
+
barrierResult
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function formatWhatsAppWebAuthStatusState(state) {
|
|
173
|
+
switch (state) {
|
|
174
|
+
case "linked": return "linked";
|
|
175
|
+
case "not-linked": return "not linked";
|
|
176
|
+
case "unstable": return "auth stabilizing";
|
|
177
|
+
}
|
|
178
|
+
return state;
|
|
179
|
+
}
|
|
180
|
+
async function readWebAuthState(authDir = resolveDefaultWebAuthDir()) {
|
|
181
|
+
return (await readWebAuthStateCore(authDir, "readWebAuthState")).state;
|
|
182
|
+
}
|
|
183
|
+
async function readWebAuthSnapshot(authDir = resolveDefaultWebAuthDir()) {
|
|
184
|
+
const auth = await readWebAuthStateCore(authDir, "readWebAuthSnapshot");
|
|
185
|
+
return {
|
|
186
|
+
state: auth.state,
|
|
187
|
+
authAgeMs: auth.state === "linked" ? getWebAuthAgeMs(auth.authDir) : null,
|
|
188
|
+
selfId: auth.state === "linked" ? readWebSelfId(auth.authDir) : emptyWebSelfId()
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async function readWebAuthExistsBestEffort(authDir = resolveDefaultWebAuthDir()) {
|
|
192
|
+
const state = await readWebAuthState(authDir);
|
|
193
|
+
return {
|
|
194
|
+
exists: state === "linked",
|
|
195
|
+
timedOut: state === "unstable"
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
async function readWebAuthExistsForDecision(authDir = resolveDefaultWebAuthDir()) {
|
|
199
|
+
const state = await readWebAuthState(authDir);
|
|
200
|
+
if (state === "unstable") return { outcome: "unstable" };
|
|
201
|
+
return {
|
|
202
|
+
outcome: "stable",
|
|
203
|
+
exists: state === "linked"
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
async function readWebAuthSnapshotBestEffort(authDir = resolveDefaultWebAuthDir()) {
|
|
207
|
+
const snapshot = await readWebAuthSnapshot(authDir);
|
|
208
|
+
return {
|
|
209
|
+
linked: snapshot.state === "linked",
|
|
210
|
+
timedOut: snapshot.state === "unstable",
|
|
211
|
+
authAgeMs: snapshot.authAgeMs,
|
|
212
|
+
selfId: snapshot.selfId
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function isBaileysAuthFileName(name) {
|
|
216
|
+
if (name === "oauth.json") return false;
|
|
217
|
+
if (name === "creds.json" || name === "creds.json.bak") return true;
|
|
218
|
+
if (!name.endsWith(".json")) return false;
|
|
219
|
+
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
|
|
220
|
+
}
|
|
221
|
+
async function clearBaileysAuthFiles(authDir) {
|
|
222
|
+
const rootStats = await fs$1.lstat(authDir).catch(() => null);
|
|
223
|
+
if (!rootStats?.isDirectory() || rootStats.isSymbolicLink()) return;
|
|
224
|
+
const entries = await fs$1.readdir(authDir, { withFileTypes: true });
|
|
225
|
+
await Promise.all(entries.map(async (entry) => {
|
|
226
|
+
if (!entry.isFile()) return;
|
|
227
|
+
if (!isBaileysAuthFileName(entry.name)) return;
|
|
228
|
+
await fs$1.rm(path.join(authDir, entry.name), { force: true });
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
async function shouldClearOnLogout(authDir, isLegacyAuthDir) {
|
|
232
|
+
try {
|
|
233
|
+
const stats = await fs$1.lstat(authDir);
|
|
234
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) return false;
|
|
235
|
+
if (isLegacyAuthDir) return (await fs$1.readdir(authDir, { withFileTypes: true })).some((entry) => {
|
|
236
|
+
if (!entry.isFile()) return false;
|
|
237
|
+
return isBaileysAuthFileName(entry.name);
|
|
238
|
+
});
|
|
239
|
+
if ((await fs$1.lstat(resolveWebCredsPath(authDir)).catch(() => null))?.isFile()) return true;
|
|
240
|
+
return (await fs$1.lstat(resolveWebCredsBackupPath(authDir)).catch(() => null))?.isFile() === true;
|
|
241
|
+
} catch (error) {
|
|
242
|
+
const codeValue = error && typeof error === "object" && "code" in error ? error.code : void 0;
|
|
243
|
+
return (typeof codeValue === "string" ? codeValue : "") !== "ENOENT";
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function isPathInsideDirectory(baseDir, targetPath) {
|
|
247
|
+
const relativePath = path.relative(baseDir, targetPath);
|
|
248
|
+
return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
249
|
+
}
|
|
250
|
+
async function pathHasSymlinkComponent(baseDir, targetPath) {
|
|
251
|
+
const relativePath = path.relative(baseDir, targetPath);
|
|
252
|
+
let currentPath = baseDir;
|
|
253
|
+
for (const segment of relativePath.split(path.sep)) {
|
|
254
|
+
currentPath = path.join(currentPath, segment);
|
|
255
|
+
const stats = await fs$1.lstat(currentPath).catch(() => null);
|
|
256
|
+
if (!stats || stats.isSymbolicLink()) return true;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
async function isLegacyWebAuthDir(authDir) {
|
|
261
|
+
const legacyAuthDir = path.resolve(resolveOAuthDir$1());
|
|
262
|
+
const resolvedAuthDir = path.resolve(authDir);
|
|
263
|
+
if (resolvedAuthDir !== legacyAuthDir) return false;
|
|
264
|
+
const stats = await fs$1.lstat(resolvedAuthDir).catch(() => null);
|
|
265
|
+
return stats?.isDirectory() === true && !stats.isSymbolicLink();
|
|
266
|
+
}
|
|
267
|
+
async function classifyWebAuthDirOwnership(authDir) {
|
|
268
|
+
const whatsappAuthBase = path.resolve(resolveOAuthDir$1(), "whatsapp");
|
|
269
|
+
const resolvedAuthDir = path.resolve(authDir);
|
|
270
|
+
if (!isPathInsideDirectory(whatsappAuthBase, resolvedAuthDir)) return { kind: "external" };
|
|
271
|
+
const [baseRealPath, authDirRealPath] = await Promise.all([fs$1.realpath(whatsappAuthBase).catch(() => null), fs$1.realpath(resolvedAuthDir).catch(() => null)]);
|
|
272
|
+
if (!baseRealPath || !authDirRealPath) return { kind: "unsafe-owned" };
|
|
273
|
+
if (!isPathInsideDirectory(baseRealPath, authDirRealPath)) return { kind: "unsafe-owned" };
|
|
274
|
+
if (await pathHasSymlinkComponent(whatsappAuthBase, resolvedAuthDir)) return { kind: "unsafe-owned" };
|
|
275
|
+
return {
|
|
276
|
+
kind: "owned",
|
|
277
|
+
authDir: resolvedAuthDir
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async function logoutWeb(params) {
|
|
281
|
+
const runtime = params.runtime ?? defaultRuntime;
|
|
282
|
+
const resolvedAuthDir = (0, text_runtime_exports.resolveUserPath)(params.authDir ?? resolveDefaultWebAuthDir());
|
|
283
|
+
if (await waitForWebAuthBarrier(resolvedAuthDir, "logoutWeb") === "timed_out") runtime.log(info("WhatsApp auth state is still stabilizing; clearing cached credentials anyway."));
|
|
284
|
+
if (!await shouldClearOnLogout(resolvedAuthDir, Boolean(params.isLegacyAuthDir))) {
|
|
285
|
+
runtime.log(info("No WhatsApp Web session found; nothing to delete."));
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
if (params.isLegacyAuthDir) {
|
|
289
|
+
if (!await isLegacyWebAuthDir(resolvedAuthDir)) {
|
|
290
|
+
runtime.log(info("Skipped WhatsApp Web credential cleanup outside the managed legacy auth directory."));
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
await clearBaileysAuthFiles(resolvedAuthDir);
|
|
294
|
+
} else {
|
|
295
|
+
const ownership = await classifyWebAuthDirOwnership(resolvedAuthDir);
|
|
296
|
+
if (ownership.kind === "owned") await fs$1.rm(ownership.authDir, {
|
|
297
|
+
recursive: true,
|
|
298
|
+
force: true
|
|
299
|
+
});
|
|
300
|
+
else if (ownership.kind === "unsafe-owned") {
|
|
301
|
+
runtime.log(info("Skipped WhatsApp Web credential cleanup because the auth directory crosses a symlink boundary."));
|
|
302
|
+
return false;
|
|
303
|
+
} else {
|
|
304
|
+
runtime.log(info("Skipped WhatsApp Web credential cleanup outside the managed auth directory."));
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
runtime.log(success("Cleared WhatsApp Web credentials."));
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
function readWebSelfId(authDir = resolveDefaultWebAuthDir()) {
|
|
312
|
+
try {
|
|
313
|
+
const credsPath = resolveWebCredsPath((0, text_runtime_exports.resolveUserPath)(authDir));
|
|
314
|
+
if (!fs.existsSync(credsPath)) return emptyWebSelfId();
|
|
315
|
+
const raw = fs.readFileSync(credsPath, "utf-8");
|
|
316
|
+
const parsed = JSON.parse(raw);
|
|
317
|
+
const identity = resolveComparableIdentity({
|
|
318
|
+
jid: parsed?.me?.id ?? null,
|
|
319
|
+
lid: parsed?.me?.lid ?? null
|
|
320
|
+
}, authDir);
|
|
321
|
+
return {
|
|
322
|
+
e164: identity.e164 ?? null,
|
|
323
|
+
jid: identity.jid ?? null,
|
|
324
|
+
lid: identity.lid ?? null
|
|
325
|
+
};
|
|
326
|
+
} catch {
|
|
327
|
+
return emptyWebSelfId();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function readWebSelfIdentity(authDir = resolveDefaultWebAuthDir(), fallback) {
|
|
331
|
+
const resolvedAuthDir = (0, text_runtime_exports.resolveUserPath)(authDir);
|
|
332
|
+
try {
|
|
333
|
+
const raw = await fs$1.readFile(resolveWebCredsPath(resolvedAuthDir), "utf-8");
|
|
334
|
+
const parsed = JSON.parse(raw);
|
|
335
|
+
return resolveComparableIdentity({
|
|
336
|
+
jid: parsed?.me?.id ?? null,
|
|
337
|
+
lid: parsed?.me?.lid ?? null
|
|
338
|
+
}, resolvedAuthDir);
|
|
339
|
+
} catch {
|
|
340
|
+
return resolveComparableIdentity({
|
|
341
|
+
jid: fallback?.id ?? null,
|
|
342
|
+
lid: fallback?.lid ?? null
|
|
343
|
+
}, resolvedAuthDir);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async function readWebSelfIdentityForDecision(authDir = resolveDefaultWebAuthDir(), fallback) {
|
|
347
|
+
const resolvedAuthDir = (0, text_runtime_exports.resolveUserPath)(authDir);
|
|
348
|
+
if (await waitForWebAuthBarrier(resolvedAuthDir, "readWebSelfIdentityForDecision") === "timed_out") return { outcome: "unstable" };
|
|
349
|
+
return {
|
|
350
|
+
outcome: "stable",
|
|
351
|
+
identity: await readWebSelfIdentity(resolvedAuthDir, fallback)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Return the age (in milliseconds) of the cached WhatsApp web auth state, or null when missing.
|
|
356
|
+
* Helpful for heartbeats/observability to spot stale credentials.
|
|
357
|
+
*/
|
|
358
|
+
function getWebAuthAgeMs(authDir = resolveDefaultWebAuthDir()) {
|
|
359
|
+
try {
|
|
360
|
+
const stats = fs.statSync(resolveWebCredsPath((0, text_runtime_exports.resolveUserPath)(authDir)));
|
|
361
|
+
return Date.now() - stats.mtimeMs;
|
|
362
|
+
} catch {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function logWebSelfId(authDir = resolveDefaultWebAuthDir(), runtime = defaultRuntime, includeChannelPrefix = false) {
|
|
367
|
+
const { e164, jid, lid } = readWebSelfId(authDir);
|
|
368
|
+
const parts = [jid ? `jid ${jid}` : null, lid ? `lid ${lid}` : null].filter((value) => Boolean(value));
|
|
369
|
+
const details = e164 || parts.length > 0 ? `${e164 ?? "unknown"}${parts.length > 0 ? ` (${parts.join(", ")})` : ""}` : "unknown";
|
|
370
|
+
const prefix = includeChannelPrefix ? "Web Channel: " : "";
|
|
371
|
+
runtime.log(info(`${prefix}${details}`));
|
|
372
|
+
}
|
|
373
|
+
async function pickWebChannel(pref, authDir = resolveDefaultWebAuthDir()) {
|
|
374
|
+
const choice = pref === "auto" ? "web" : pref;
|
|
375
|
+
const auth = await readWebAuthExistsForDecision(authDir);
|
|
376
|
+
if (auth.outcome === "unstable") throw new WhatsAppAuthUnstableError();
|
|
377
|
+
if (!auth.exists) throw new Error(`No WhatsApp Web session found. Run \`${formatCliCommand("openclaw channels login --channel whatsapp --verbose")}\` to link.`);
|
|
378
|
+
return choice;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
export { waitForCredsSaveQueueWithTimeout as C, waitForCredsSaveQueue as S, readWebSelfIdentityForDecision as _, getWebAuthAgeMs as a, webAuthExists as b, pickWebChannel as c, readWebAuthExistsForDecision as d, readWebAuthSnapshot as f, readWebSelfIdentity as g, readWebSelfId as h, formatWhatsAppWebAuthStatusState as i, readCredsJsonRaw as l, readWebAuthState as m, WHATSAPP_AUTH_UNSTABLE_CODE as n, logWebSelfId as o, readWebAuthSnapshotBestEffort as p, WhatsAppAuthUnstableError as r, logoutWeb as s, WA_WEB_AUTH_DIR as t, readWebAuthExistsBestEffort as u, resolveDefaultWebAuthDir as v, writeCredsJsonAtomically as w, enqueueCredsSave as x, restoreCredsFromBackupIfNeeded as y };
|