@openclaw/sms 2026.8.1 → 2026.8.33

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.
@@ -1,9 +1,9 @@
1
- import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
2
- import { n as TWILIO_MMS_MAX_BYTES } from "./twilio-BkGAecwf.js";
1
+ import { t as getSmsRuntime } from "./runtime-BBlPgBIF.mjs";
2
+ import { m as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-BpcGZSHK.mjs";
3
+ import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
3
4
  import { resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
4
5
  import { createHash } from "node:crypto";
5
6
  import { formatInboundMediaUnavailableText, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
6
- import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
7
7
  import { SsrFBlockedError, safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
8
  import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
9
9
  import { MediaFetchError, unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
@@ -15,7 +15,7 @@ const TWILIO_MEDIA_PATH_RE = /^\/2010-04-01\/Accounts\/([^/]+)\/Messages\/([^/]+
15
15
  const TWILIO_MEDIA_TOTAL_TIMEOUT_MS = 6e4;
16
16
  const TWILIO_MEDIA_RESPONSE_HEADER_TIMEOUT_MS = 3e4;
17
17
  const TWILIO_MEDIA_READ_IDLE_TIMEOUT_MS = 3e4;
18
- const TWILIO_MEDIA_BATCH_TIMEOUT_MS = 4 * 6e4;
18
+ const TWILIO_MEDIA_BATCH_TIMEOUT_MS = 24e4;
19
19
  const TWILIO_MEDIA_RETRY = {
20
20
  attempts: 2,
21
21
  minDelayMs: 500,
@@ -78,13 +78,13 @@ const TWILIO_MMS_EXTENSION_BY_TYPE = {
78
78
  "video/quicktime": ".mov",
79
79
  "video/webm": ".webm"
80
80
  };
81
- const SMS_OUTBOUND_MEDIA_TTL_MS = 10 * 6e4;
81
+ const SMS_OUTBOUND_MEDIA_TTL_MS = 6e5;
82
82
  const SMS_OUTBOUND_MEDIA_ID_RE = /^[a-f0-9]{24}$/;
83
83
  const SMS_OUTBOUND_MEDIA_TOKEN_PARAM_PREFIX = "__openclaw_mms_token";
84
84
  const SMS_OUTBOUND_MEDIA_NAMESPACE = "hosted-outbound-media";
85
85
  const SMS_OUTBOUND_MEDIA_CHUNKS_NAMESPACE = "hosted-outbound-media-chunks";
86
86
  const SMS_OUTBOUND_MEDIA_MAX_ENTRIES = 64;
87
- const SMS_OUTBOUND_MEDIA_MAX_CHUNK_ROWS = SMS_OUTBOUND_MEDIA_MAX_ENTRIES * 160;
87
+ const SMS_OUTBOUND_MEDIA_MAX_CHUNK_ROWS = 10240;
88
88
  const hostedSmsMediaStores = /* @__PURE__ */ new Map();
89
89
  let hostedSmsMediaRuntime;
90
90
  function normalizeBasePath(path) {
@@ -276,7 +276,12 @@ async function materializeSmsInboundMedia(params) {
276
276
  let remainingBytes = TWILIO_MMS_MAX_BYTES;
277
277
  let unavailableCount = declaredUnavailableCount;
278
278
  const batchTimeoutSignal = AbortSignal.timeout(TWILIO_MEDIA_BATCH_TIMEOUT_MS);
279
- const abortSignal = params.abortSignal ? AbortSignal.any([params.abortSignal, batchTimeoutSignal]) : batchTimeoutSignal;
279
+ const credentialAbortController = new AbortController();
280
+ const abortSignal = AbortSignal.any([
281
+ credentialAbortController.signal,
282
+ batchTimeoutSignal,
283
+ ...params.abortSignal ? [params.abortSignal] : []
284
+ ]);
280
285
  const savedMedia = [];
281
286
  try {
282
287
  for (const [index, media] of params.msg.media.entries()) {
@@ -291,6 +296,14 @@ async function materializeSmsInboundMedia(params) {
291
296
  accountSid: callbackAccountSid,
292
297
  messageSid: params.msg.messageSid
293
298
  }),
299
+ beforeRequest: () => {
300
+ try {
301
+ assertSmsCredentialOwnerAvailable(params.account);
302
+ } catch (error) {
303
+ credentialAbortController.abort(error);
304
+ throw error;
305
+ }
306
+ },
294
307
  requestInit: {
295
308
  headers: { authorization: `Basic ${Buffer.from(`${params.account.accountSid}:${params.account.authToken}`).toString("base64")}` },
296
309
  signal: abortSignal
@@ -1,7 +1,16 @@
1
+ import { normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
2
+ import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
3
+ import { normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ import { createAccountListHelpers, resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
5
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, hasConfiguredAccountValue, resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
6
+ import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
7
+ import { hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
1
8
  import { isIP } from "node:net";
2
9
  import { fetchWithSsrFGuard, isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
3
10
  import { createHmac } from "node:crypto";
4
11
  import { readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
12
+ import { assertSecretOwnerAvailable } from "openclaw/plugin-sdk/channel-secret-owner-runtime";
13
+ import { getRuntimeConfigSnapshot } from "openclaw/plugin-sdk/runtime-config-snapshot";
5
14
  import * as querystring from "node:querystring";
6
15
  import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
7
16
  import { readResponseTextPrefix, readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
@@ -93,20 +102,131 @@ function resolveTwilioStatusCallbackUrl(publicWebhookUrl) {
93
102
  return callbackUrl;
94
103
  }
95
104
  //#endregion
105
+ //#region extensions/sms/src/accounts.ts
106
+ const CHANNEL_ID = "sms";
107
+ const DEFAULT_WEBHOOK_PATH = "/webhooks/sms";
108
+ const DEFAULT_TEXT_CHUNK_LIMIT = 1500;
109
+ function getChannelConfig(cfg) {
110
+ return cfg?.channels?.[CHANNEL_ID];
111
+ }
112
+ function parseList(raw) {
113
+ if (!raw) return [];
114
+ return (Array.isArray(raw) ? raw : typeof raw === "string" ? normalizeStringEntries(raw.split(",")) : [raw]).map((entry) => normalizeSmsAllowFrom(String(entry))).filter(Boolean);
115
+ }
116
+ function parseTextChunkLimit(raw) {
117
+ if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) return raw;
118
+ if (typeof raw === "string" && /^\d+$/.test(raw.trim())) return parseStrictPositiveInteger(raw.trim()) ?? DEFAULT_TEXT_CHUNK_LIMIT;
119
+ return DEFAULT_TEXT_CHUNK_LIMIT;
120
+ }
121
+ function firstNonBlankEnv(...values) {
122
+ return values.find((value) => value?.trim());
123
+ }
124
+ function hasBaseAccount(channelCfg) {
125
+ return [
126
+ channelCfg?.accountSid,
127
+ channelCfg?.fromNumber,
128
+ channelCfg?.messagingServiceSid,
129
+ process.env.TWILIO_ACCOUNT_SID,
130
+ process.env.TWILIO_AUTH_TOKEN,
131
+ process.env.TWILIO_PHONE_NUMBER,
132
+ process.env.TWILIO_SMS_FROM,
133
+ process.env.TWILIO_MESSAGING_SERVICE_SID
134
+ ].some((value) => hasConfiguredAccountValue(value)) || hasConfiguredSecretInput(channelCfg?.authToken);
135
+ }
136
+ const { listAccountIds: listSmsAccountIds, resolveDefaultAccountId: resolveDefaultSmsAccountId, resolveAccountConfig: resolveMergedSmsAccountConfig } = createAccountListHelpers(CHANNEL_ID, {
137
+ fallbackAccountIdWhenEmpty: false,
138
+ hasImplicitDefaultAccount: (cfg) => hasBaseAccount(getChannelConfig(cfg)),
139
+ omitKeys: ["defaultAccount"]
140
+ });
141
+ function resolveSmsAccount(cfg, accountId) {
142
+ return readSmsAccount(cfg, accountId, "strict").account;
143
+ }
144
+ function readSmsAccount(cfg, accountId, mode) {
145
+ const channelCfg = getChannelConfig(cfg) ?? {};
146
+ const id = normalizeOptionalAccountId(accountId) ?? resolveDefaultSmsAccountId(cfg);
147
+ const accountConfig = resolveAccountEntry(channelCfg.accounts, id);
148
+ const merged = resolveMergedSmsAccountConfig(cfg, id);
149
+ const useEnvFallbacks = id === DEFAULT_ACCOUNT_ID$1;
150
+ const envAccountSid = useEnvFallbacks ? process.env.TWILIO_ACCOUNT_SID : void 0;
151
+ const envAuthToken = useEnvFallbacks ? process.env.TWILIO_AUTH_TOKEN : void 0;
152
+ const envFromNumber = useEnvFallbacks ? firstNonBlankEnv(process.env.TWILIO_PHONE_NUMBER, process.env.TWILIO_SMS_FROM) : void 0;
153
+ const envMessagingServiceSid = useEnvFallbacks ? process.env.TWILIO_MESSAGING_SERVICE_SID : void 0;
154
+ const envWebhookPath = useEnvFallbacks ? process.env.SMS_WEBHOOK_PATH : void 0;
155
+ const envPublicWebhookUrl = useEnvFallbacks ? process.env.SMS_PUBLIC_WEBHOOK_URL : void 0;
156
+ const envAllowFrom = useEnvFallbacks ? process.env.SMS_ALLOWED_USERS : void 0;
157
+ const envTextChunkLimit = useEnvFallbacks ? process.env.SMS_TEXT_CHUNK_LIMIT : void 0;
158
+ const envDisableSignatureValidation = useEnvFallbacks ? process.env.SMS_DANGEROUSLY_DISABLE_SIGNATURE_VALIDATION : void 0;
159
+ const webhookPath = (merged.webhookPath ?? envWebhookPath ?? DEFAULT_WEBHOOK_PATH).trim();
160
+ const publicWebhookUrl = (merged.publicWebhookUrl ?? envPublicWebhookUrl ?? "").trim();
161
+ const authToken = resolveSecretInputString({
162
+ value: merged.authToken ?? envAuthToken,
163
+ path: id === DEFAULT_ACCOUNT_ID$1 ? "channels.sms.authToken" : `channels.sms.accounts.${id}.authToken`,
164
+ mode
165
+ });
166
+ return {
167
+ account: {
168
+ accountId: id,
169
+ enabled: channelCfg.enabled !== false && accountConfig?.enabled !== false,
170
+ accountSid: (merged.accountSid ?? envAccountSid ?? "").trim(),
171
+ authToken: authToken.value ?? "",
172
+ fromNumber: normalizeSmsPhoneNumber(merged.fromNumber ?? envFromNumber ?? ""),
173
+ messagingServiceSid: (merged.messagingServiceSid ?? envMessagingServiceSid ?? "").trim(),
174
+ defaultTo: normalizeSmsPhoneNumber(merged.defaultTo ?? ""),
175
+ webhookPath: webhookPath || DEFAULT_WEBHOOK_PATH,
176
+ publicWebhookUrl,
177
+ dangerouslyDisableSignatureValidation: merged.dangerouslyDisableSignatureValidation === true || envDisableSignatureValidation === "true",
178
+ dmPolicy: merged.dmPolicy ?? "pairing",
179
+ allowFrom: parseList(merged.allowFrom ?? envAllowFrom),
180
+ textChunkLimit: parseTextChunkLimit(merged.textChunkLimit ?? envTextChunkLimit),
181
+ mediaMaxBytes: resolveChannelMediaMaxBytes({
182
+ cfg,
183
+ accountId: id,
184
+ resolveChannelLimitMb: () => merged.mediaMaxMb
185
+ })
186
+ },
187
+ tokenStatus: authToken.status
188
+ };
189
+ }
190
+ function inspectSmsAccount(cfg, accountId) {
191
+ const { account, tokenStatus } = readSmsAccount(cfg, accountId, "inspect");
192
+ const configured = Boolean(account.accountSid && tokenStatus !== "missing" && (account.fromNumber || account.messagingServiceSid));
193
+ return {
194
+ accountId: account.accountId,
195
+ name: account.fromNumber || account.messagingServiceSid || "SMS",
196
+ enabled: account.enabled,
197
+ configured,
198
+ tokenStatus,
199
+ webhookPath: account.webhookPath,
200
+ signatureValidation: account.dangerouslyDisableSignatureValidation ? "configured" : !account.publicWebhookUrl ? "missing-public-url" : parseSmsPublicWebhookUrl(account.publicWebhookUrl) ? "configured" : "invalid-public-url"
201
+ };
202
+ }
203
+ function isSmsAccountConfigured(account) {
204
+ return Boolean(account.accountSid && account.authToken && (account.fromNumber || account.messagingServiceSid));
205
+ }
206
+ //#endregion
207
+ //#region extensions/sms/src/credential-availability.ts
208
+ function assertSmsCredentialOwnerAvailable(account) {
209
+ assertSecretOwnerAvailable("account", `sms:${account.accountId}`);
210
+ const runtimeConfig = getRuntimeConfigSnapshot();
211
+ if (!runtimeConfig) return;
212
+ const current = resolveSmsAccount(runtimeConfig, account.accountId);
213
+ if (current.accountSid !== account.accountSid || current.authToken !== account.authToken) throw new Error(`SMS credentials changed for ${account.accountId}; retry the operation.`);
214
+ }
215
+ //#endregion
96
216
  //#region extensions/sms/src/twilio.ts
97
217
  const TWILIO_ACCOUNTS_URL = "https://api.twilio.com/2010-04-01/Accounts";
98
218
  const TWILIO_MESSAGING_URL = "https://messaging.twilio.com/v1";
99
219
  const TWILIO_API_HOSTNAME = "api.twilio.com";
100
220
  const TWILIO_MESSAGING_HOSTNAME = "messaging.twilio.com";
101
221
  const TWILIO_API_TIMEOUT_MS = 3e4;
102
- const TWILIO_API_SUCCESS_BODY_LIMIT_BYTES = 1 * 1024 * 1024;
103
- const TWILIO_API_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
222
+ const TWILIO_API_SUCCESS_BODY_LIMIT_BYTES = 1048576;
223
+ const TWILIO_API_ERROR_BODY_LIMIT_BYTES = 8192;
104
224
  const TRUNCATED_RESPONSE_SUFFIX = "... [truncated]";
105
- const WEBHOOK_BODY_LIMIT_BYTES = 32 * 1024;
225
+ const WEBHOOK_BODY_LIMIT_BYTES = 32768;
106
226
  const WEBHOOK_BODY_TIMEOUT_MS = 5e3;
107
227
  const TWILIO_MESSAGE_BODY_MAX_LENGTH = 1600;
108
228
  const TWILIO_MMS_MAX_OUTBOUND_MEDIA_COUNT = 10;
109
- const TWILIO_MMS_MAX_BYTES = 5 * 1024 * 1024;
229
+ const TWILIO_MMS_MAX_BYTES = 5242880;
110
230
  const SMS_MAX_INBOUND_MEDIA_DOWNLOADS = 10;
111
231
  const TWILIO_CHANNEL_ADDRESS_RE = /^([a-z][a-z0-9-]*):(.*)$/i;
112
232
  function firstString(value) {
@@ -294,6 +414,13 @@ function normalizeRequestHeaders(headers) {
294
414
  if (Array.isArray(headers)) return Object.fromEntries(headers.map(([key, value]) => [key, value]));
295
415
  return Object.fromEntries(Object.entries(headers));
296
416
  }
417
+ function assertTwilioRequestCredentialsAvailable(account) {
418
+ try {
419
+ assertSmsCredentialOwnerAvailable(account);
420
+ } catch (error) {
421
+ throw new PlatformMessageNotDispatchedError(`SMS request stopped before Twilio dispatch: ${formatErrorMessage(error)}`, { cause: error });
422
+ }
423
+ }
297
424
  async function requestTwilioApi(params) {
298
425
  const init = {
299
426
  ...params.init,
@@ -303,6 +430,7 @@ async function requestTwilioApi(params) {
303
430
  }
304
431
  };
305
432
  if (params.fetchImpl) {
433
+ assertTwilioRequestCredentialsAvailable(params.account);
306
434
  const response = await params.fetchImpl(params.url, init);
307
435
  return {
308
436
  ok: response.ok,
@@ -310,9 +438,18 @@ async function requestTwilioApi(params) {
310
438
  text: await readTwilioApiResponseText(response)
311
439
  };
312
440
  }
441
+ let requestDispatched = false;
313
442
  const guarded = await fetchWithSsrFGuard({
314
443
  url: params.url,
315
444
  init,
445
+ beforeRequest: () => {
446
+ if (requestDispatched) {
447
+ assertSmsCredentialOwnerAvailable(params.account);
448
+ return;
449
+ }
450
+ assertTwilioRequestCredentialsAvailable(params.account);
451
+ requestDispatched = true;
452
+ },
316
453
  auditContext: "sms-twilio-api",
317
454
  policy: { allowedHostnames: [params.allowedHostname] },
318
455
  requireHttps: true,
@@ -418,6 +555,7 @@ async function listTwilioMessages(params) {
418
555
  return parseTwilioListPayload(response.text, "messages", parseTwilioMessageLogEntry);
419
556
  }
420
557
  async function sendSmsViaTwilio(params) {
558
+ assertSmsCredentialOwnerAvailable(params.account);
421
559
  if (!params.account.fromNumber && !params.account.messagingServiceSid) throw new Error("Twilio SMS send requires fromNumber or messagingServiceSid.");
422
560
  if (params.text && params.text.length > 1600) throw new Error(`Twilio SMS/MMS Body supports at most ${TWILIO_MESSAGE_BODY_MAX_LENGTH} characters.`);
423
561
  const mediaUrls = (params.mediaUrls ?? []).map((url) => url.trim()).filter(Boolean);
@@ -455,4 +593,4 @@ async function sendSmsViaTwilio(params) {
455
593
  };
456
594
  }
457
595
  //#endregion
458
- export { normalizeSmsAllowFrom as _, listTwilioMessages as a, resolveTwilioMessageSid as c, retrieveTwilioMessagingService as d, sendSmsViaTwilio as f, looksLikeSmsPhoneNumber as g, resolveTwilioStatusCallbackUrl as h, listTwilioIncomingPhoneNumbers as i, resolveTwilioWebhookSignatureUrl as l, parseSmsPublicWebhookUrl as m, TWILIO_MMS_MAX_BYTES as n, readTwilioWebhookForm as o, verifyTwilioSignature as p, buildTwilioInboundMessage as r, resolveTwilioInboundSender as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, respondTwiml as u, normalizeSmsPhoneNumber as v };
596
+ export { normalizeSmsPhoneNumber as C, normalizeSmsAllowFrom as S, listSmsAccountIds as _, listTwilioMessages as a, resolveTwilioStatusCallbackUrl as b, resolveTwilioMessageSid as c, retrieveTwilioMessagingService as d, sendSmsViaTwilio as f, isSmsAccountConfigured as g, inspectSmsAccount as h, listTwilioIncomingPhoneNumbers as i, resolveTwilioWebhookSignatureUrl as l, assertSmsCredentialOwnerAvailable as m, TWILIO_MMS_MAX_BYTES as n, readTwilioWebhookForm as o, verifyTwilioSignature as p, buildTwilioInboundMessage as r, resolveTwilioInboundSender as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, respondTwiml as u, resolveDefaultSmsAccountId as v, looksLikeSmsPhoneNumber as x, resolveSmsAccount as y };
package/dist/api.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as setSmsRuntime, t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
1
+ import { n as setSmsRuntime, t as getSmsRuntime } from "./.setup/runtime-BBlPgBIF.mjs";
2
2
  export { getSmsRuntime, setSmsRuntime };
@@ -1,20 +1,18 @@
1
- import { t as getSmsRuntime } from "./runtime-BBlPgBIF.js";
2
- import { _ as normalizeSmsAllowFrom, a as listTwilioMessages, c as resolveTwilioMessageSid, d as retrieveTwilioMessagingService, f as sendSmsViaTwilio, g as looksLikeSmsPhoneNumber, h as resolveTwilioStatusCallbackUrl, i as listTwilioIncomingPhoneNumbers, l as resolveTwilioWebhookSignatureUrl, m as parseSmsPublicWebhookUrl, o as readTwilioWebhookForm, p as verifyTwilioSignature, r as buildTwilioInboundMessage, s as resolveTwilioInboundSender, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as respondTwiml, v as normalizeSmsPhoneNumber } from "./twilio-BkGAecwf.js";
3
- import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Cp0f-YPc.js";
4
- import { DEFAULT_ACCOUNT_ID, normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
1
+ import { t as getSmsRuntime } from "./.setup/runtime-BBlPgBIF.mjs";
2
+ import { C as normalizeSmsPhoneNumber, S as normalizeSmsAllowFrom, _ as listSmsAccountIds, a as listTwilioMessages, b as resolveTwilioStatusCallbackUrl, c as resolveTwilioMessageSid, d as retrieveTwilioMessagingService, f as sendSmsViaTwilio, g as isSmsAccountConfigured, h as inspectSmsAccount, i as listTwilioIncomingPhoneNumbers, l as resolveTwilioWebhookSignatureUrl, m as assertSmsCredentialOwnerAvailable, o as readTwilioWebhookForm, p as verifyTwilioSignature, r as buildTwilioInboundMessage, s as resolveTwilioInboundSender, t as TWILIO_MESSAGE_BODY_MAX_LENGTH, u as respondTwiml, v as resolveDefaultSmsAccountId, x as looksLikeSmsPhoneNumber, y as resolveSmsAccount } from "./.setup/twilio-BpcGZSHK.mjs";
3
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./.setup/secret-contract-Cp0f-YPc.mjs";
4
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
5
5
  import { createHybridChannelConfigAdapter, createScopedDmSecurityResolver } from "openclaw/plugin-sdk/channel-config-helpers";
6
6
  import { buildChannelOutboundSessionRoute, createChatChannelPlugin } from "openclaw/plugin-sdk/channel-core";
7
7
  import { bindIngressLifecycleToReplyOptions, createAccountStatusSink, createChannelIngressMonitor, createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, waitUntilAbort } from "openclaw/plugin-sdk/channel-outbound";
8
8
  import { createConditionalWarningCollector } from "openclaw/plugin-sdk/channel-policy";
9
9
  import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
10
10
  import { createEmptyChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
11
+ import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
11
12
  import { createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
12
13
  import { isRecord, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
13
14
  import { chunkTextForOutbound, renderMarkdownIRChunksWithinLimit, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
14
- import { createAccountListHelpers, resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
15
- import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, hasConfiguredAccountValue, resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
16
- import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
17
- import { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
15
+ import { buildSecretInputSchema } from "openclaw/plugin-sdk/secret-input";
18
16
  import { AllowFromListSchema, DmPolicySchema, buildChannelConfigSchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
19
17
  import { requireChannelOpenAllowFrom } from "openclaw/plugin-sdk/extension-shared";
20
18
  import { z } from "zod";
@@ -25,104 +23,10 @@ import { runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guar
25
23
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
26
24
  import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
27
25
  import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
28
- import { PlatformMessageNotDispatchedError, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
29
26
  import { withTimeout } from "openclaw/plugin-sdk/text-utility-runtime";
30
- //#region extensions/sms/src/accounts.ts
31
- const CHANNEL_ID$3 = "sms";
32
- const DEFAULT_WEBHOOK_PATH = "/webhooks/sms";
33
- const DEFAULT_TEXT_CHUNK_LIMIT = 1500;
34
- function getChannelConfig(cfg) {
35
- return cfg?.channels?.[CHANNEL_ID$3];
36
- }
37
- function parseList(raw) {
38
- if (!raw) return [];
39
- return (Array.isArray(raw) ? raw : typeof raw === "string" ? normalizeStringEntries(raw.split(",")) : [raw]).map((entry) => normalizeSmsAllowFrom(String(entry))).filter(Boolean);
40
- }
41
- function parseTextChunkLimit(raw) {
42
- if (typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0) return raw;
43
- if (typeof raw === "string" && /^\d+$/.test(raw.trim())) return parseStrictPositiveInteger(raw.trim()) ?? DEFAULT_TEXT_CHUNK_LIMIT;
44
- return DEFAULT_TEXT_CHUNK_LIMIT;
45
- }
46
- function firstNonBlankEnv(...values) {
47
- return values.find((value) => value?.trim());
48
- }
49
- function hasBaseAccount(channelCfg) {
50
- return [
51
- channelCfg?.accountSid,
52
- channelCfg?.fromNumber,
53
- channelCfg?.messagingServiceSid,
54
- process.env.TWILIO_ACCOUNT_SID,
55
- process.env.TWILIO_AUTH_TOKEN,
56
- process.env.TWILIO_PHONE_NUMBER,
57
- process.env.TWILIO_SMS_FROM,
58
- process.env.TWILIO_MESSAGING_SERVICE_SID
59
- ].some((value) => hasConfiguredAccountValue(value)) || hasConfiguredSecretInput(channelCfg?.authToken);
60
- }
61
- const { listAccountIds: listSmsAccountIds, resolveDefaultAccountId: resolveDefaultSmsAccountId, resolveAccountConfig: resolveMergedSmsAccountConfig } = createAccountListHelpers(CHANNEL_ID$3, {
62
- fallbackAccountIdWhenEmpty: false,
63
- hasImplicitDefaultAccount: (cfg) => hasBaseAccount(getChannelConfig(cfg)),
64
- omitKeys: ["defaultAccount"]
65
- });
66
- function resolveSmsAccount(cfg, accountId) {
67
- const channelCfg = getChannelConfig(cfg) ?? {};
68
- const id = normalizeOptionalAccountId(accountId) ?? resolveDefaultSmsAccountId(cfg);
69
- const accountConfig = resolveAccountEntry(channelCfg.accounts, id);
70
- const merged = resolveMergedSmsAccountConfig(cfg, id);
71
- const useEnvFallbacks = id === DEFAULT_ACCOUNT_ID$1;
72
- const envAccountSid = useEnvFallbacks ? process.env.TWILIO_ACCOUNT_SID : void 0;
73
- const envAuthToken = useEnvFallbacks ? process.env.TWILIO_AUTH_TOKEN : void 0;
74
- const envFromNumber = useEnvFallbacks ? firstNonBlankEnv(process.env.TWILIO_PHONE_NUMBER, process.env.TWILIO_SMS_FROM) : void 0;
75
- const envMessagingServiceSid = useEnvFallbacks ? process.env.TWILIO_MESSAGING_SERVICE_SID : void 0;
76
- const envWebhookPath = useEnvFallbacks ? process.env.SMS_WEBHOOK_PATH : void 0;
77
- const envPublicWebhookUrl = useEnvFallbacks ? process.env.SMS_PUBLIC_WEBHOOK_URL : void 0;
78
- const envAllowFrom = useEnvFallbacks ? process.env.SMS_ALLOWED_USERS : void 0;
79
- const envTextChunkLimit = useEnvFallbacks ? process.env.SMS_TEXT_CHUNK_LIMIT : void 0;
80
- const envDisableSignatureValidation = useEnvFallbacks ? process.env.SMS_DANGEROUSLY_DISABLE_SIGNATURE_VALIDATION : void 0;
81
- const webhookPath = (merged.webhookPath ?? envWebhookPath ?? DEFAULT_WEBHOOK_PATH).trim();
82
- const publicWebhookUrl = (merged.publicWebhookUrl ?? envPublicWebhookUrl ?? "").trim();
83
- const authToken = normalizeResolvedSecretInputString({
84
- value: merged.authToken ?? envAuthToken,
85
- path: id === DEFAULT_ACCOUNT_ID$1 ? "channels.sms.authToken" : `channels.sms.accounts.${id}.authToken`
86
- }) ?? "";
87
- return {
88
- accountId: id,
89
- enabled: channelCfg.enabled !== false && accountConfig?.enabled !== false,
90
- accountSid: (merged.accountSid ?? envAccountSid ?? "").trim(),
91
- authToken,
92
- fromNumber: normalizeSmsPhoneNumber(merged.fromNumber ?? envFromNumber ?? ""),
93
- messagingServiceSid: (merged.messagingServiceSid ?? envMessagingServiceSid ?? "").trim(),
94
- defaultTo: normalizeSmsPhoneNumber(merged.defaultTo ?? ""),
95
- webhookPath: webhookPath || DEFAULT_WEBHOOK_PATH,
96
- publicWebhookUrl,
97
- dangerouslyDisableSignatureValidation: merged.dangerouslyDisableSignatureValidation === true || envDisableSignatureValidation === "true",
98
- dmPolicy: merged.dmPolicy ?? "pairing",
99
- allowFrom: parseList(merged.allowFrom ?? envAllowFrom),
100
- textChunkLimit: parseTextChunkLimit(merged.textChunkLimit ?? envTextChunkLimit),
101
- mediaMaxBytes: resolveChannelMediaMaxBytes({
102
- cfg,
103
- accountId: id,
104
- resolveChannelLimitMb: () => merged.mediaMaxMb
105
- })
106
- };
107
- }
108
- function inspectSmsAccount(cfg, accountId) {
109
- const account = resolveSmsAccount(cfg, accountId);
110
- const configured = isSmsAccountConfigured(account);
111
- return {
112
- enabled: account.enabled,
113
- configured,
114
- tokenStatus: account.authToken ? "available" : "missing",
115
- webhookPath: account.webhookPath,
116
- signatureValidation: account.dangerouslyDisableSignatureValidation ? "configured" : !account.publicWebhookUrl ? "missing-public-url" : parseSmsPublicWebhookUrl(account.publicWebhookUrl) ? "configured" : "invalid-public-url"
117
- };
118
- }
119
- function isSmsAccountConfigured(account) {
120
- return Boolean(account.accountSid && account.authToken && (account.fromNumber || account.messagingServiceSid));
121
- }
122
- //#endregion
123
27
  //#region extensions/sms/src/config-schema.ts
124
28
  const SecretInputSchema = buildSecretInputSchema();
125
- const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannelSchema(z.object({
29
+ const SmsAccountConfigSchema = z.object({
126
30
  name: z.string().optional(),
127
31
  enabled: z.boolean().optional(),
128
32
  configWrites: z.boolean().optional(),
@@ -138,7 +42,8 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
138
42
  dmPolicy: DmPolicySchema.optional().default("pairing"),
139
43
  allowFrom: AllowFromListSchema,
140
44
  textChunkLimit: z.number().int().positive().optional()
141
- }).strict(), {
45
+ }).strict();
46
+ const SmsConfigSchema = buildMultiAccountChannelSchema(SmsAccountConfigSchema, {
142
47
  optionalAccount: true,
143
48
  refine: (value, ctx) => {
144
49
  requireChannelOpenAllowFrom({
@@ -149,7 +54,8 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
149
54
  requireOpenAllowFrom
150
55
  });
151
56
  }
152
- }), { uiHints: {
57
+ });
58
+ const SmsChannelConfigSchema = buildChannelConfigSchema(SmsConfigSchema, { uiHints: {
153
59
  "": {
154
60
  label: "SMS",
155
61
  help: "Twilio SMS/MMS channel configuration for inbound webhooks and outbound replies."
@@ -204,7 +110,7 @@ const SmsChannelConfigSchema = buildChannelConfigSchema(buildMultiAccountChannel
204
110
  //#endregion
205
111
  //#region extensions/sms/src/delivery-observations.ts
206
112
  const DELIVERY_NAMESPACE = "twilio-delivery-observations-v1";
207
- const DELIVERY_RETENTION_MS = 720 * 60 * 60 * 1e3;
113
+ const DELIVERY_RETENTION_MS = 2592e6;
208
114
  const DELIVERY_MAX_MESSAGES = 5e3;
209
115
  const DELIVERY_STATUS_RANK = {
210
116
  accepted: 10,
@@ -470,7 +376,8 @@ function throwSmsPartialDeliveryError(error, results, kind) {
470
376
  });
471
377
  }
472
378
  function toSmsPlainText(text) {
473
- return stripMarkdown(sanitizeAssistantVisibleText(text), {
379
+ const visibleText = sanitizeAssistantVisibleText(text);
380
+ return stripMarkdown(visibleText, {
474
381
  assistantTranscriptRoleHeaders: true,
475
382
  assistantTranscriptRolePrefix: SMS_ASSISTANT_TRANSCRIPT_ROLE_PREFIX,
476
383
  linkStyle: "label-and-url"
@@ -567,7 +474,8 @@ async function prepareSmsMediaAttempt(params) {
567
474
  });
568
475
  let hostedMedia;
569
476
  try {
570
- const { prepareHostedSmsMedia } = await import("./media-CakyGP6W.js");
477
+ const { prepareHostedSmsMedia } = await import("./.setup/media-CWVWiPWe.mjs");
478
+ assertSmsCredentialOwnerAvailable(params.account);
571
479
  const prepared = await prepareHostedSmsMedia({
572
480
  account: params.account,
573
481
  mediaUrl: params.mediaUrl,
@@ -698,7 +606,7 @@ async function dispatchSmsInboundEvent(params) {
698
606
  params.log?.warn?.(`SMS sender ${from} is not authorized`);
699
607
  return;
700
608
  }
701
- const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./media-CakyGP6W.js")).materializeSmsInboundMedia({
609
+ const materialized = params.msg.media.length > 0 || (params.msg.unavailableMediaCount ?? 0) > 0 ? await (await import("./.setup/media-CWVWiPWe.mjs")).materializeSmsInboundMedia({
702
610
  account: params.account,
703
611
  msg: params.msg,
704
612
  mediaRuntime: params.channelRuntime,
@@ -924,7 +832,7 @@ function createSmsIngressSpool(params) {
924
832
  pollIntervalMs: SMS_INGRESS_DRAIN_INTERVAL_MS,
925
833
  retention: {
926
834
  pruneIntervalMs: 0,
927
- completedTtlMs: 1440 * 60 * 1e3,
835
+ completedTtlMs: 864e5,
928
836
  failedMaxEntries: 1e3
929
837
  },
930
838
  appendRetryDelaysMs: [0],
@@ -1031,6 +939,7 @@ function createSmsWebhookHandler(params) {
1031
939
  }
1032
940
  throw error;
1033
941
  }
942
+ assertSmsCredentialOwnerAvailable(params.account);
1034
943
  if (!params.account.dangerouslyDisableSignatureValidation) {
1035
944
  if (!verifyTwilioSignature({
1036
945
  signature: headerValue(req.headers["x-twilio-signature"]),
@@ -1182,7 +1091,7 @@ async function registerSmsWebhookRoute(params) {
1182
1091
  throwOnFailure: true,
1183
1092
  log: (msg) => params.log?.info?.(msg),
1184
1093
  handler: async (req, res) => {
1185
- const { tryHandleHostedSmsMediaRequest } = await import("./media-CakyGP6W.js");
1094
+ const { tryHandleHostedSmsMediaRequest } = await import("./.setup/media-CWVWiPWe.mjs");
1186
1095
  if (await tryHandleHostedSmsMediaRequest(req, res, params.account.accountId)) return true;
1187
1096
  return await webhookHandler(req, res);
1188
1097
  }
@@ -1752,7 +1661,7 @@ const smsMessageAdapter = defineChannelMessageAdapter({
1752
1661
  afterSendFailure: async (ctx) => {
1753
1662
  if (ctx.kind !== "media") return;
1754
1663
  const attemptToken = resolveSmsAttachmentAttemptToken(ctx.attemptToken);
1755
- if (!attemptToken || attemptToken.platformDispatchStarted) return;
1664
+ if (!attemptToken || attemptToken.platformDispatchStarted && !(ctx.error instanceof PlatformMessageNotDispatchedError)) return;
1756
1665
  await attemptToken.attempt.cleanupHostedMedia();
1757
1666
  }
1758
1667
  },
@@ -1,2 +1,2 @@
1
- import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./secret-contract-Cp0f-YPc.js";
1
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./.setup/secret-contract-Cp0f-YPc.mjs";
2
2
  export { channelSecrets, collectRuntimeConfigAssignments, secretTargetRegistryEntries };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/sms",
3
- "version": "2026.8.1",
3
+ "version": "2026.8.33",
4
4
  "description": "OpenClaw SMS/MMS channel plugin for Twilio messages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -123,10 +123,10 @@
123
123
  }
124
124
  },
125
125
  "compat": {
126
- "pluginApi": ">=2026.8.1"
126
+ "pluginApi": ">=2026.8.33"
127
127
  },
128
128
  "build": {
129
- "openclawVersion": "2026.8.1",
129
+ "openclawVersion": "2026.8.33",
130
130
  "bundledDist": false
131
131
  },
132
132
  "install": {
@@ -150,7 +150,7 @@
150
150
  "README.md"
151
151
  ],
152
152
  "peerDependencies": {
153
- "openclaw": ">=2026.8.1"
153
+ "openclaw": ">=2026.8.33"
154
154
  },
155
155
  "peerDependenciesMeta": {
156
156
  "openclaw": {