@openclaw/twitch 2026.7.2-beta.2 → 2026.7.2-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as twitchPlugin } from "./plugin-DKq9eX97.js";
1
+ import { t as twitchPlugin } from "./plugin-B31l1oaD.js";
2
2
  import { n as setTwitchRuntime } from "./runtime-B5If4b0g.js";
3
3
  export { setTwitchRuntime, twitchPlugin };
@@ -1,2 +1,2 @@
1
- import { t as twitchPlugin } from "./plugin-DKq9eX97.js";
1
+ import { t as twitchPlugin } from "./plugin-B31l1oaD.js";
2
2
  export { twitchPlugin };
@@ -1,7 +1,11 @@
1
- import { n as stripMarkdownForTwitch, r as getOrCreateClientManager } from "./plugin-DKq9eX97.js";
1
+ import { h as normalizeTwitchChannel } from "./setup-surface-CVAaMigx.js";
2
+ import { n as stripMarkdownForTwitch, r as getOrCreateClientManager } from "./plugin-B31l1oaD.js";
2
3
  import { t as getTwitchRuntime } from "./runtime-B5If4b0g.js";
4
+ import { createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
3
5
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4
6
  import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
7
+ import { HttpStatusCodeError } from "@twurple/api-call";
8
+ import { createChannelInboundEnvelopeBuilder } from "openclaw/plugin-sdk/channel-inbound";
5
9
  import { createChannelIngressResolver, defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
6
10
  //#region extensions/twitch/src/access-control.ts
7
11
  const twitchUserIdentity = defineStableChannelIngressIdentity({
@@ -125,21 +129,208 @@ function mentionsBot(message, botUsername) {
125
129
  return false;
126
130
  }
127
131
  //#endregion
132
+ //#region extensions/twitch/src/twitch-ingress.ts
133
+ const TWITCH_INGRESS_PAYLOAD_VERSION = 1;
134
+ const TWITCH_INGRESS_DRAIN_INTERVAL_MS = 1e3;
135
+ const TWITCH_INGRESS_PRUNE_INTERVAL_MS = 3600 * 1e3;
136
+ const TWITCH_INGRESS_COMPLETED_TTL_MS = 720 * 60 * 60 * 1e3;
137
+ const TWITCH_INGRESS_COMPLETED_MAX_ENTRIES = 1e3;
138
+ const TWITCH_INGRESS_FAILED_TTL_MS = 720 * 60 * 60 * 1e3;
139
+ const TWITCH_INGRESS_FAILED_MAX_ENTRIES = 1e3;
140
+ var TwitchIngressPermanentError = class extends Error {
141
+ constructor(message, options) {
142
+ super(message, options);
143
+ this.name = "TwitchIngressPermanentError";
144
+ }
145
+ };
146
+ function nonEmptyString(value) {
147
+ return typeof value === "string" && value.trim() ? value.trim() : null;
148
+ }
149
+ function inspectTwitchIngressEvent(event) {
150
+ if (!event || typeof event !== "object" || Array.isArray(event)) throw new TwitchIngressPermanentError("Twitch ingress event must be an object.");
151
+ const candidate = event;
152
+ const eventId = nonEmptyString(candidate.id);
153
+ if (!eventId) throw new TwitchIngressPermanentError("Twitch ingress event is missing its message id.");
154
+ const rawChannel = nonEmptyString(candidate.channel);
155
+ const channel = rawChannel ? normalizeTwitchChannel(rawChannel) : "";
156
+ if (!channel) throw new TwitchIngressPermanentError("Twitch ingress event is missing its channel.");
157
+ return {
158
+ eventId,
159
+ laneKey: `channel:${channel}`
160
+ };
161
+ }
162
+ function deserializeTwitchIngressEvent(rawEvent) {
163
+ let parsed;
164
+ try {
165
+ parsed = JSON.parse(rawEvent);
166
+ } catch (error) {
167
+ throw new TwitchIngressPermanentError("Twitch ingress event JSON is invalid.", { cause: error });
168
+ }
169
+ return parsed;
170
+ }
171
+ function normalizeClaimedTwitchMessage(event, claimedId) {
172
+ const candidate = event;
173
+ const username = nonEmptyString(candidate.username);
174
+ const rawChannel = nonEmptyString(candidate.channel);
175
+ if (!username || typeof candidate.message !== "string" || !rawChannel) throw new TwitchIngressPermanentError("Twitch ingress event shape is invalid.");
176
+ return {
177
+ ...candidate,
178
+ id: claimedId,
179
+ username,
180
+ message: candidate.message,
181
+ channel: normalizeTwitchChannel(rawChannel)
182
+ };
183
+ }
184
+ function isTwitchAuthenticationFailure(error) {
185
+ let current = error;
186
+ for (let depth = 0; depth < 8 && current && typeof current === "object"; depth += 1) {
187
+ if (current instanceof HttpStatusCodeError && (current.statusCode === 401 || current.statusCode === 403)) return true;
188
+ current = current.cause;
189
+ }
190
+ return false;
191
+ }
192
+ function stoppedError() {
193
+ return /* @__PURE__ */ new Error("Twitch ingress stopped before dispatch.");
194
+ }
195
+ function createTwitchIngress(options) {
196
+ const queue = options.queue ?? getTwitchRuntime().state.openChannelIngressQueue({ accountId: options.accountId });
197
+ const shutdown = new AbortController();
198
+ let stopped = false;
199
+ const deferredClaims = /* @__PURE__ */ new Map();
200
+ const monitor = createChannelIngressMonitor({
201
+ queue,
202
+ inspect: (message) => inspectTwitchIngressEvent(message),
203
+ payload: {
204
+ storage: "raw-event",
205
+ version: TWITCH_INGRESS_PAYLOAD_VERSION,
206
+ serialize: (message) => JSON.stringify(message),
207
+ deserialize: (rawEvent) => deserializeTwitchIngressEvent(rawEvent),
208
+ createClaimError: (kind) => new TwitchIngressPermanentError(kind === "invalid-version" ? "Twitch ingress payload is invalid." : "Twitch ingress event identity changed after durable admission.")
209
+ },
210
+ deliver: async (rawEvent, lifecycle, claim) => {
211
+ const message = normalizeClaimedTwitchMessage(rawEvent, claim.id);
212
+ let handedOff = false;
213
+ let resolveDeferredClaim;
214
+ const deferredClaim = new Promise((resolve) => {
215
+ resolveDeferredClaim = resolve;
216
+ });
217
+ let deferredClaimSettled = false;
218
+ const settleDeferredClaim = () => {
219
+ if (deferredClaimSettled) return;
220
+ deferredClaimSettled = true;
221
+ if (deferredClaims.get(claim.id) === deferredClaim) deferredClaims.delete(claim.id);
222
+ resolveDeferredClaim();
223
+ };
224
+ const deliveryAbortSignal = AbortSignal.any([lifecycle.abortSignal, shutdown.signal]);
225
+ try {
226
+ await options.deliver(message, {
227
+ admission: lifecycle.admission,
228
+ abortSignal: deliveryAbortSignal,
229
+ onAdopted: async () => {
230
+ handedOff = true;
231
+ try {
232
+ await lifecycle.onAdopted();
233
+ } finally {
234
+ settleDeferredClaim();
235
+ }
236
+ },
237
+ onDeferred: () => {
238
+ handedOff = true;
239
+ if (!deferredClaimSettled) deferredClaims.set(claim.id, deferredClaim);
240
+ lifecycle.onDeferred();
241
+ },
242
+ onAbandoned: async () => {
243
+ handedOff = true;
244
+ try {
245
+ await lifecycle.onAbandoned();
246
+ } finally {
247
+ settleDeferredClaim();
248
+ }
249
+ }
250
+ });
251
+ } catch (error) {
252
+ if (stopped || deliveryAbortSignal.aborted) return {
253
+ kind: "failed-retryable",
254
+ error
255
+ };
256
+ throw error;
257
+ }
258
+ if (!handedOff && (stopped || deliveryAbortSignal.aborted)) return {
259
+ kind: "failed-retryable",
260
+ error: stoppedError()
261
+ };
262
+ },
263
+ pollIntervalMs: options.pollIntervalMs ?? TWITCH_INGRESS_DRAIN_INTERVAL_MS,
264
+ retention: {
265
+ pruneIntervalMs: TWITCH_INGRESS_PRUNE_INTERVAL_MS,
266
+ completedTtlMs: TWITCH_INGRESS_COMPLETED_TTL_MS,
267
+ completedMaxEntries: TWITCH_INGRESS_COMPLETED_MAX_ENTRIES,
268
+ failedTtlMs: TWITCH_INGRESS_FAILED_TTL_MS,
269
+ failedMaxEntries: TWITCH_INGRESS_FAILED_MAX_ENTRIES
270
+ },
271
+ drain: {
272
+ resolveNonRetryableFailure: (error) => {
273
+ if (error instanceof TwitchIngressPermanentError) return {
274
+ reason: "invalid-event",
275
+ message: error.message
276
+ };
277
+ if (isTwitchAuthenticationFailure(error)) return {
278
+ reason: "authentication-failed",
279
+ message: formatErrorMessage(error)
280
+ };
281
+ return null;
282
+ },
283
+ onLog: (message) => options.runtime.error?.(`twitch ingress: ${message}`)
284
+ },
285
+ abortSignal: shutdown.signal,
286
+ createStoppedError: stoppedError,
287
+ onError: (error) => options.runtime.error?.(`Twitch ingress drain failed: ${formatErrorMessage(error)}`)
288
+ });
289
+ let stopTask;
290
+ return {
291
+ accept: (message) => {
292
+ if (stopped) return Promise.reject(stoppedError());
293
+ return monitor.admit(message).then(() => void 0);
294
+ },
295
+ start: () => {
296
+ if (!stopped) monitor.start();
297
+ },
298
+ stop: () => {
299
+ stopTask ??= (async () => {
300
+ stopped = true;
301
+ shutdown.abort(stoppedError());
302
+ await monitor.pause();
303
+ await monitor.waitForIdle();
304
+ await Promise.allSettled(deferredClaims.values());
305
+ await monitor.stop();
306
+ })();
307
+ return stopTask;
308
+ }
309
+ };
310
+ }
311
+ //#endregion
128
312
  //#region extensions/twitch/src/monitor.ts
129
313
  /**
314
+ * Twitch message monitor - processes incoming messages and routes to agents.
315
+ *
316
+ * This monitor connects to the Twitch client manager, processes incoming messages,
317
+ * resolves agent routes, and handles replies.
318
+ */
319
+ /**
130
320
  * Process an incoming Twitch message and dispatch to agent.
131
321
  */
132
322
  async function processTwitchMessage(params) {
133
- const { message, account, accountId, config, runtime, core, statusSink } = params;
323
+ const { message, account, accountId, config, runtime, core, turnAdoptionLifecycle, statusSink } = params;
134
324
  const cfg = config;
135
325
  await core.channel.inbound.run({
136
326
  channel: "twitch",
137
327
  accountId,
138
328
  raw: message,
329
+ turnAdoptionLifecycle,
139
330
  adapter: {
140
331
  ingest: (incoming) => ({
141
- id: incoming.id ?? `${incoming.channel}:${incoming.timestamp?.getTime() ?? Date.now()}`,
142
- timestamp: incoming.timestamp?.getTime(),
332
+ id: incoming.id,
333
+ timestamp: incoming.timestamp,
143
334
  rawText: incoming.message,
144
335
  textForAgent: incoming.message,
145
336
  textForCommands: incoming.message,
@@ -157,11 +348,13 @@ async function processTwitchMessage(params) {
157
348
  });
158
349
  const senderId = message.userId ?? message.username;
159
350
  const fromLabel = message.displayName ?? message.username;
160
- const body = core.channel.reply.formatAgentEnvelope({
351
+ const body = createChannelInboundEnvelopeBuilder({
352
+ cfg,
353
+ route
354
+ })({
161
355
  channel: "Twitch",
162
356
  from: fromLabel,
163
357
  timestamp: input.timestamp,
164
- envelope: core.channel.reply.resolveEnvelopeFormatOptions(cfg),
165
358
  body: input.rawText
166
359
  });
167
360
  const ctxPayload = core.channel.inbound.buildContext({
@@ -182,6 +375,7 @@ async function processTwitchMessage(params) {
182
375
  },
183
376
  route: {
184
377
  agentId: route.agentId,
378
+ dmScope: route.dmScope,
185
379
  accountId: route.accountId,
186
380
  routeSessionKey: route.sessionKey
187
381
  },
@@ -193,7 +387,6 @@ async function processTwitchMessage(params) {
193
387
  commandBody: input.textForCommands
194
388
  }
195
389
  });
196
- const storePath = core.channel.session.resolveStorePath(cfg.session?.store, { agentId: route.agentId });
197
390
  const tableMode = core.channel.text.resolveMarkdownTableMode({
198
391
  cfg,
199
392
  channel: "twitch",
@@ -203,12 +396,12 @@ async function processTwitchMessage(params) {
203
396
  cfg,
204
397
  channel: "twitch",
205
398
  accountId,
206
- agentId: route.agentId,
207
- routeSessionKey: route.sessionKey,
208
- storePath,
399
+ route: {
400
+ agentId: route.agentId,
401
+ dmScope: route.dmScope,
402
+ sessionKey: route.sessionKey
403
+ },
209
404
  ctxPayload,
210
- recordInboundSession: core.channel.session.recordInboundSession,
211
- dispatchReplyWithBufferedBlockDispatcher: core.channel.reply.dispatchReplyWithBufferedBlockDispatcher,
212
405
  delivery: {
213
406
  durable: () => ({ to: `twitch:channel:${message.channel}` }),
214
407
  deliver: async (payload) => {
@@ -273,6 +466,7 @@ async function monitorTwitchProvider(options) {
273
466
  const { account, accountId, config, runtime, abortSignal, statusSink } = options;
274
467
  const core = getTwitchRuntime();
275
468
  let stopped = false;
469
+ let stopTask;
276
470
  const coreLogger = core.logging.getChildLogger({ module: "twitch" });
277
471
  const logVerboseMessage = (message) => {
278
472
  if (!core.logging.shouldLogVerbose()) return;
@@ -291,17 +485,17 @@ async function monitorTwitchProvider(options) {
291
485
  runtime.error?.(`Failed to connect: ${errorMsg}`);
292
486
  throw error;
293
487
  }
294
- const unregisterHandler = clientManager.onMessage(account, (message) => {
295
- if (stopped) return;
296
- (async () => {
488
+ const ingress = createTwitchIngress({
489
+ accountId,
490
+ runtime,
491
+ deliver: async (message, turnAdoptionLifecycle) => {
297
492
  const botUsername = normalizeLowercaseStringOrEmpty(account.username);
298
493
  if (normalizeLowercaseStringOrEmpty(message.username) === botUsername) return;
299
- const access = await checkTwitchAccessControl({
494
+ if (!(await checkTwitchAccessControl({
300
495
  message,
301
496
  account,
302
497
  botUsername
303
- });
304
- if (stopped || !access.allowed) return;
498
+ })).allowed) return;
305
499
  statusSink?.({ lastInboundAt: Date.now() });
306
500
  await processTwitchMessage({
307
501
  message,
@@ -310,17 +504,31 @@ async function monitorTwitchProvider(options) {
310
504
  config,
311
505
  runtime,
312
506
  core,
507
+ turnAdoptionLifecycle,
313
508
  statusSink
314
509
  });
315
- })().catch((err) => {
316
- runtime.error?.(`Message processing failed: ${String(err)}`);
510
+ }
511
+ });
512
+ ingress.start();
513
+ const unregisterHandler = clientManager.onMessage(account, (message) => {
514
+ if (stopped) return;
515
+ ingress.accept(message).catch((err) => {
516
+ runtime.error?.(`Message durable admission failed: ${String(err)}`);
317
517
  });
318
518
  });
319
519
  const stop = () => {
320
- stopped = true;
321
- unregisterHandler();
520
+ stopTask ??= (async () => {
521
+ stopped = true;
522
+ unregisterHandler();
523
+ await ingress.stop();
524
+ })();
525
+ return stopTask;
322
526
  };
323
- abortSignal.addEventListener("abort", stop, { once: true });
527
+ abortSignal.addEventListener("abort", () => {
528
+ stop().catch((error) => {
529
+ runtime.error?.(`Twitch ingress stop failed: ${String(error)}`);
530
+ });
531
+ }, { once: true });
324
532
  return { stop };
325
533
  }
326
534
  //#endregion
@@ -1,14 +1,14 @@
1
- import { a as getAccountConfig, c as resolveTwitchAccountContext, d as isAccountConfigured, f as missingTargetError, h as resolveTwitchToken, i as DEFAULT_ACCOUNT_ID, l as resolveTwitchSnapshotAccountId, m as normalizeTwitchChannel, o as listAccountIds, p as normalizeToken, r as twitchSetupWizard, s as resolveDefaultTwitchAccountId, t as twitchSetupAdapter, u as generateMessageId } from "./setup-surface-CxAa0pLj.js";
1
+ import { a as DEFAULT_ACCOUNT_ID, c as resolveDefaultTwitchAccountId, d as generateMessageId, f as isAccountConfigured, g as resolveTwitchToken, h as normalizeTwitchChannel, i as twitchSetupWizard, l as resolveTwitchAccountContext, m as normalizeToken, n as twitchSetupContract, o as getAccountConfig, p as missingTargetError, s as listAccountIds, t as twitchSetupAdapter, u as resolveTwitchSnapshotAccountId } from "./setup-surface-CVAaMigx.js";
2
2
  import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
3
3
  import { MarkdownConfigSchema, buildChannelConfigSchema } from "openclaw/plugin-sdk/channel-config-schema";
4
4
  import { buildChannelOutboundSessionRoute, createChatChannelPlugin, stripChannelTargetPrefix } from "openclaw/plugin-sdk/channel-core";
5
+ import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter, runPassiveAccountLifecycle } from "openclaw/plugin-sdk/channel-outbound";
5
6
  import { createLoggedPairingApprovalNotifier, createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";
6
- import { buildPassiveProbedChannelStatusSummary, runStoppablePassiveMonitor } from "openclaw/plugin-sdk/extension-shared";
7
+ import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared";
7
8
  import { createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
8
9
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
9
10
  import { normalizeLowercaseStringOrEmpty, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
10
- import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter } from "openclaw/plugin-sdk/channel-outbound";
11
- import { chunkTextForOutbound, sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
11
+ import { chunkTextForOutbound, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
12
12
  import { RefreshingAuthProvider, StaticAuthProvider } from "@twurple/auth";
13
13
  import { ChatClient, LogLevel } from "@twurple/chat";
14
14
  import { sliceUtf16Safe, withTimeout } from "openclaw/plugin-sdk/text-utility-runtime";
@@ -186,18 +186,17 @@ var TwitchClientManager = class {
186
186
  client.onMessage((channelName, _user, messageText, msg) => {
187
187
  const handler = this.messageHandlers.get(key);
188
188
  if (handler) {
189
- const normalizedChannel = channelName.startsWith("#") ? channelName.slice(1) : channelName;
190
189
  const from = `twitch:${msg.userInfo.userName}`;
191
190
  const preview = sliceUtf16Safe(messageText, 0, 100).replace(/\n/g, "\\n");
192
- this.logger.debug?.(`twitch inbound: channel=${normalizedChannel} from=${from} len=${messageText.length} preview="${preview}"`);
191
+ this.logger.debug?.(`twitch inbound: channel=${channelName} from=${from} len=${messageText.length} preview="${preview}"`);
193
192
  handler({
194
193
  username: msg.userInfo.userName,
195
194
  displayName: msg.userInfo.displayName,
196
195
  userId: msg.userInfo.userId,
197
196
  message: messageText,
198
- channel: normalizedChannel,
197
+ channel: channelName,
199
198
  id: msg.id,
200
- timestamp: /* @__PURE__ */ new Date(),
199
+ timestamp: Date.now(),
201
200
  isMod: msg.userInfo.isMod,
202
201
  isOwner: msg.userInfo.isBroadcaster,
203
202
  isVip: msg.userInfo.isVip,
@@ -361,20 +360,10 @@ async function removeClientManager(accountId) {
361
360
  * Markdown utilities for Twitch chat
362
361
  *
363
362
  * Twitch chat doesn't support markdown formatting, so we strip it before sending.
364
- * Based on OpenClaw's markdownToText in src/agents/tools/web-fetch-utils.ts.
365
- */
366
- /**
367
- * Strip markdown formatting from text for Twitch compatibility.
368
- *
369
- * Removes images, links, bold, italic, strikethrough, code blocks, inline code,
370
- * headers, and list formatting. Replaces newlines with spaces since Twitch
371
- * is a single-line chat medium.
372
- *
373
- * @param markdown - The markdown text to strip
374
- * @returns Plain text with markdown removed
375
363
  */
364
+ /** Strip markdown, then flatten newlines for Twitch's single-line chat. */
376
365
  function stripMarkdownForTwitch(markdown) {
377
- return markdown.replace(/!\[[^\]]*]\([^)]+\)/g, "").replace(/\[([^\]]+)]\([^)]+\)/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/__([^_]+)__/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/(?<![\p{L}\p{N}\p{M}])_(?!_)([^_]+)_(?![\p{L}\p{N}\p{M}])/gu, "$1").replace(/~~([^~]+)~~/g, "$1").replace(/```[\s\S]*?```/g, (block) => block.replace(/```[^\n]*\n?/g, "").replace(/```/g, "")).replace(/`([^`]+)`/g, "$1").replace(/^#{1,6}\s+/gm, "").replace(/^\s*[-*+]\s+/gm, "").replace(/^\s*\d+\.\s+/gm, "").replace(/\r/g, "").replace(/[ \t]+\n/g, "\n").replace(/\n/g, " ").replace(/[ \t]{2,}/g, " ").trim();
366
+ return stripMarkdown(markdown, { linkStyle: "label-and-url" }).replace(/\r/g, "").replace(/[ \t]+\n/g, "\n").replace(/\n/g, " ").replace(/[ \t]{2,}/g, " ").trim();
378
367
  }
379
368
  /**
380
369
  * Simple word-boundary chunker for Twitch (500 char limit).
@@ -1306,6 +1295,7 @@ const twitchPlugin = createChatChannelPlugin({
1306
1295
  aliases: ["twitch-chat"]
1307
1296
  },
1308
1297
  setup: twitchSetupAdapter,
1298
+ setupContract: twitchSetupContract,
1309
1299
  setupWizard: twitchSetupWizard,
1310
1300
  capabilities: { chatTypes: ["group"] },
1311
1301
  messaging: { resolveOutboundSessionRoute: ({ cfg, agentId, accountId, target }) => {
@@ -1400,10 +1390,10 @@ const twitchPlugin = createChatChannelPlugin({
1400
1390
  });
1401
1391
  ctx.log?.info(`Starting Twitch connection for ${account.username}`);
1402
1392
  try {
1403
- await runStoppablePassiveMonitor({
1393
+ await runPassiveAccountLifecycle({
1404
1394
  abortSignal: ctx.abortSignal,
1405
1395
  start: async () => {
1406
- const { monitorTwitchProvider } = await import("./monitor-MwCp9bY0.js");
1396
+ const { monitorTwitchProvider } = await import("./monitor-CQidEQhp.js");
1407
1397
  return monitorTwitchProvider({
1408
1398
  account,
1409
1399
  accountId,
@@ -1411,6 +1401,9 @@ const twitchPlugin = createChatChannelPlugin({
1411
1401
  runtime: ctx.runtime,
1412
1402
  abortSignal: ctx.abortSignal
1413
1403
  });
1404
+ },
1405
+ stop: async (monitor) => {
1406
+ await monitor.stop();
1414
1407
  }
1415
1408
  });
1416
1409
  } catch (error) {
@@ -1,2 +1,2 @@
1
- import { n as twitchSetupPlugin } from "./setup-surface-CxAa0pLj.js";
1
+ import { r as twitchSetupPlugin } from "./setup-surface-CVAaMigx.js";
2
2
  export { twitchSetupPlugin };
@@ -2,6 +2,7 @@ import { DEFAULT_ACCOUNT_ID, listCombinedAccountIds, normalizeAccountId, resolve
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { normalizeLowercaseStringOrEmpty, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
5
+ import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
5
6
  import { getChatChannelMeta } from "openclaw/plugin-sdk/core";
6
7
  import { createSetupTranslator, formatDocsLink, normalizeAccountId as normalizeAccountId$1, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
7
8
  //#region extensions/twitch/src/token.ts
@@ -427,9 +428,14 @@ const twitchGroupAccess = {
427
428
  applyAllowlist: ({ cfg }) => cfg
428
429
  };
429
430
  const twitchSetupAdapter = {
431
+ singleAccountKeysToMove: ["accessToken"],
430
432
  resolveAccountId: ({ cfg }) => resolveSetupAccountId(cfg),
431
433
  applyAccountConfig: ({ cfg, accountId }) => setTwitchAccount(cfg, { enabled: true }, accountId)
432
434
  };
435
+ const twitchSetupContract = defineChannelSetupContract({
436
+ fields: {},
437
+ legacyAdapter: twitchSetupAdapter
438
+ });
433
439
  const twitchSetupWizard = {
434
440
  channel,
435
441
  resolveAccountIdForConfigure: ({ cfg, accountOverride }) => resolveSetupAccountId(cfg, accountOverride),
@@ -509,7 +515,8 @@ const twitchSetupPlugin = {
509
515
  isEnabled: (account) => account.enabled !== false
510
516
  },
511
517
  setup: twitchSetupAdapter,
518
+ setupContract: twitchSetupContract,
512
519
  setupWizard: twitchSetupWizard
513
520
  };
514
521
  //#endregion
515
- export { getAccountConfig as a, resolveTwitchAccountContext as c, isAccountConfigured as d, missingTargetError as f, resolveTwitchToken as h, DEFAULT_ACCOUNT_ID$1 as i, resolveTwitchSnapshotAccountId as l, normalizeTwitchChannel as m, twitchSetupPlugin as n, listAccountIds as o, normalizeToken as p, twitchSetupWizard as r, resolveDefaultTwitchAccountId as s, twitchSetupAdapter as t, generateMessageId as u };
522
+ export { DEFAULT_ACCOUNT_ID$1 as a, resolveDefaultTwitchAccountId as c, generateMessageId as d, isAccountConfigured as f, resolveTwitchToken as g, normalizeTwitchChannel as h, twitchSetupWizard as i, resolveTwitchAccountContext as l, normalizeToken as m, twitchSetupContract as n, getAccountConfig as o, missingTargetError as p, twitchSetupPlugin as r, listAccountIds as s, twitchSetupAdapter as t, resolveTwitchSnapshotAccountId as u };
@@ -8,7 +8,7 @@ This package contains type definitions for node (https://nodejs.org/).
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Wed, 01 Jul 2026 11:03:38 GMT
11
+ * Last updated: Wed, 08 Jul 2026 06:47:45 GMT
12
12
  * Dependencies: [undici-types](https://npmjs.com/package/undici-types)
13
13
 
14
14
  # Credits
@@ -153,7 +153,11 @@ declare module "node:fs/promises" {
153
153
  * @return Fulfills with `undefined` upon success.
154
154
  */
155
155
  appendFile(
156
- data: string | Uint8Array,
156
+ data:
157
+ | string
158
+ | NodeJS.ArrayBufferView
159
+ | Iterable<string | NodeJS.ArrayBufferView>
160
+ | AsyncIterable<string | NodeJS.ArrayBufferView>,
157
161
  options?:
158
162
  | (ObjectEncodingOptions & Abortable)
159
163
  | BufferEncoding
@@ -470,7 +474,11 @@ declare module "node:fs/promises" {
470
474
  * @since v10.0.0
471
475
  */
472
476
  writeFile(
473
- data: string | Uint8Array,
477
+ data:
478
+ | string
479
+ | NodeJS.ArrayBufferView
480
+ | Iterable<string | NodeJS.ArrayBufferView>
481
+ | AsyncIterable<string | NodeJS.ArrayBufferView>,
474
482
  options?:
475
483
  | (ObjectEncodingOptions & Abortable)
476
484
  | BufferEncoding
@@ -1208,8 +1216,7 @@ declare module "node:fs/promises" {
1208
1216
  | string
1209
1217
  | NodeJS.ArrayBufferView
1210
1218
  | Iterable<string | NodeJS.ArrayBufferView>
1211
- | AsyncIterable<string | NodeJS.ArrayBufferView>
1212
- | Stream,
1219
+ | AsyncIterable<string | NodeJS.ArrayBufferView>,
1213
1220
  options?:
1214
1221
  | (ObjectEncodingOptions & {
1215
1222
  mode?: Mode | undefined;
@@ -1240,7 +1247,11 @@ declare module "node:fs/promises" {
1240
1247
  */
1241
1248
  function appendFile(
1242
1249
  path: PathLike | FileHandle,
1243
- data: string | Uint8Array,
1250
+ data:
1251
+ | string
1252
+ | NodeJS.ArrayBufferView
1253
+ | Iterable<string | NodeJS.ArrayBufferView>
1254
+ | AsyncIterable<string | NodeJS.ArrayBufferView>,
1244
1255
  options?: (ObjectEncodingOptions & FlagAndOpenMode & { flush?: boolean | undefined }) | BufferEncoding | null,
1245
1256
  ): Promise<void>;
1246
1257
  /**
@@ -1432,7 +1443,6 @@ declare module "node:fs/promises" {
1432
1443
  * When copying a directory to another directory, globs are not supported and
1433
1444
  * behavior is similar to `cp dir1/ dir2/`.
1434
1445
  * @since v16.7.0
1435
- * @experimental
1436
1446
  * @param src source path to copy.
1437
1447
  * @param dest destination path to copy to.
1438
1448
  * @return Fulfills with `undefined` upon success.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/node",
3
- "version": "26.1.0",
3
+ "version": "26.1.1",
4
4
  "description": "TypeScript definitions for node",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
6
6
  "license": "MIT",
@@ -150,6 +150,6 @@
150
150
  "undici-types": "~8.3.0"
151
151
  },
152
152
  "peerDependencies": {},
153
- "typesPublisherContentHash": "bac6fe2369bbd2e0f2cf6643373e8c398ed66b886a72749c8d1fb0b9b60031ab",
153
+ "typesPublisherContentHash": "a59119b073061829bc67a5bf6bc2b8ecb0a5a6196058e3c73172a00440f4e16d",
154
154
  "typeScriptVersion": "5.6"
155
155
  }
@@ -77,6 +77,7 @@ class Receiver extends Writable {
77
77
 
78
78
  this._totalPayloadLength = 0;
79
79
  this._messageLength = 0;
80
+ this._numFragments = 0;
80
81
  this._fragments = [];
81
82
 
82
83
  this._errored = false;
@@ -500,6 +501,19 @@ class Receiver extends Writable {
500
501
  return;
501
502
  }
502
503
 
504
+ if (this._maxFragments > 0 && ++this._numFragments > this._maxFragments) {
505
+ const error = this.createError(
506
+ RangeError,
507
+ 'Too many message fragments',
508
+ false,
509
+ 1008,
510
+ 'WS_ERR_TOO_MANY_BUFFERED_PARTS'
511
+ );
512
+
513
+ cb(error);
514
+ return;
515
+ }
516
+
503
517
  if (this._compressed) {
504
518
  this._state = INFLATING;
505
519
  this.decompress(data, cb);
@@ -507,22 +521,6 @@ class Receiver extends Writable {
507
521
  }
508
522
 
509
523
  if (data.length) {
510
- if (
511
- this._maxFragments > 0 &&
512
- this._fragments.length >= this._maxFragments
513
- ) {
514
- const error = this.createError(
515
- RangeError,
516
- 'Too many message fragments',
517
- false,
518
- 1008,
519
- 'WS_ERR_TOO_MANY_BUFFERED_PARTS'
520
- );
521
-
522
- cb(error);
523
- return;
524
- }
525
-
526
524
  //
527
525
  // This message is not compressed so its length is the sum of the payload
528
526
  // length of all fragments.
@@ -562,22 +560,6 @@ class Receiver extends Writable {
562
560
  return;
563
561
  }
564
562
 
565
- if (
566
- this._maxFragments > 0 &&
567
- this._fragments.length >= this._maxFragments
568
- ) {
569
- const error = this.createError(
570
- RangeError,
571
- 'Too many message fragments',
572
- false,
573
- 1008,
574
- 'WS_ERR_TOO_MANY_BUFFERED_PARTS'
575
- );
576
-
577
- cb(error);
578
- return;
579
- }
580
-
581
563
  this._fragments.push(buf);
582
564
  }
583
565
 
@@ -604,6 +586,7 @@ class Receiver extends Writable {
604
586
  this._totalPayloadLength = 0;
605
587
  this._messageLength = 0;
606
588
  this._fragmented = 0;
589
+ this._numFragments = 0;
607
590
  this._fragments = [];
608
591
 
609
592
  if (this._opcode === 2) {
@@ -43,9 +43,9 @@ class WebSocketServer extends EventEmitter {
43
43
  * called
44
44
  * @param {Function} [options.handleProtocols] A hook to handle protocols
45
45
  * @param {String} [options.host] The hostname where to bind the server
46
- * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
46
+ * @param {Number} [options.maxBufferedChunks=262144] The maximum number of
47
47
  * buffered data chunks
48
- * @param {Number} [options.maxFragments=131072] The maximum number of message
48
+ * @param {Number} [options.maxFragments=16384] The maximum number of message
49
49
  * fragments
50
50
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
51
51
  * size
@@ -69,8 +69,8 @@ class WebSocketServer extends EventEmitter {
69
69
  options = {
70
70
  allowSynchronousEvents: true,
71
71
  autoPong: true,
72
- maxBufferedChunks: 1024 * 1024,
73
- maxFragments: 128 * 1024,
72
+ maxBufferedChunks: 256 * 1024,
73
+ maxFragments: 16 * 1024,
74
74
  maxPayload: 100 * 1024 * 1024,
75
75
  skipUTF8Validation: false,
76
76
  perMessageDeflate: false,
@@ -646,9 +646,9 @@ module.exports = WebSocket;
646
646
  * masking key
647
647
  * @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
648
648
  * handshake request
649
- * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
649
+ * @param {Number} [options.maxBufferedChunks=262144] The maximum number of
650
650
  * buffered data chunks
651
- * @param {Number} [options.maxFragments=131072] The maximum number of message
651
+ * @param {Number} [options.maxFragments=16384] The maximum number of message
652
652
  * fragments
653
653
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
654
654
  * size
@@ -670,8 +670,8 @@ function initAsClient(websocket, address, protocols, options) {
670
670
  autoPong: true,
671
671
  closeTimeout: CLOSE_TIMEOUT,
672
672
  protocolVersion: protocolVersions[1],
673
- maxBufferedChunks: 1024 * 1024,
674
- maxFragments: 128 * 1024,
673
+ maxBufferedChunks: 256 * 1024,
674
+ maxFragments: 16 * 1024,
675
675
  maxPayload: 100 * 1024 * 1024,
676
676
  skipUTF8Validation: false,
677
677
  perMessageDeflate: true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ws",
3
- "version": "8.21.0",
3
+ "version": "8.21.1",
4
4
  "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
5
5
  "keywords": [
6
6
  "HyBi",
@@ -66,5 +66,9 @@
66
66
  "nyc": "^15.0.0",
67
67
  "prettier": "^3.0.0",
68
68
  "utf-8-validate": "^6.0.0"
69
+ },
70
+ "allowScripts": {
71
+ "bufferutil": true,
72
+ "utf-8-validate": true
69
73
  }
70
74
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@openclaw/twitch",
3
- "version": "2026.7.2-beta.2",
3
+ "version": "2026.7.2-beta.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@openclaw/twitch",
9
- "version": "2026.7.2-beta.2",
9
+ "version": "2026.7.2-beta.4",
10
10
  "dependencies": {
11
11
  "@twurple/api-call": "8.1.4",
12
12
  "@twurple/auth": "8.1.4",
@@ -212,9 +212,9 @@
212
212
  }
213
213
  },
214
214
  "node_modules/@types/ws/node_modules/@types/node": {
215
- "version": "26.1.0",
216
- "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.0.tgz",
217
- "integrity": "sha512-O0A1G3xPGy4w7AgQdAQYUlQ+BKk2Oovw8eRpofyp5KdBZULnbe+WqaOVNrm705SHphCiG4XHsACrSmPu1f+Kgw==",
215
+ "version": "26.1.1",
216
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-26.1.1.tgz",
217
+ "integrity": "sha512-nxAkRSVkN1Y0JC1W8ky/fTfkGsMmcrRsbx+3XoZE+rMOX71kLYTV7fLXpqud1GpbpP5TuffXFqfX7fH2GgZREw==",
218
218
  "license": "MIT",
219
219
  "dependencies": {
220
220
  "undici-types": "~8.3.0"
@@ -266,9 +266,9 @@
266
266
  "license": "MIT"
267
267
  },
268
268
  "node_modules/ws": {
269
- "version": "8.21.0",
270
- "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
271
- "integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
269
+ "version": "8.21.1",
270
+ "resolved": "https://registry.npmjs.org/ws/-/ws-8.21.1.tgz",
271
+ "integrity": "sha512-+0NTnW77fFN/DjQi6k/Sq/Yvk4Sgajw7urW8V+asjXnRgDs9gyGkdb7EzgfhA4goXsRIZKE28fzIXBHEzhuiWw==",
272
272
  "license": "MIT",
273
273
  "engines": {
274
274
  "node": ">=10.0.0"
@@ -9,11 +9,6 @@
9
9
  "channels": [
10
10
  "twitch"
11
11
  ],
12
- "channelEnvVars": {
13
- "twitch": [
14
- "OPENCLAW_TWITCH_ACCESS_TOKEN"
15
- ]
16
- },
17
12
  "configSchema": {
18
13
  "type": "object",
19
14
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/twitch",
3
- "version": "2026.7.2-beta.2",
3
+ "version": "2026.7.2-beta.4",
4
4
  "description": "OpenClaw Twitch channel plugin for chat and moderation workflows.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,26 +18,39 @@
18
18
  "./index.ts"
19
19
  ],
20
20
  "setupEntry": "./dist/setup-entry.js",
21
+ "setupFeatures": {
22
+ "configPromotion": true
23
+ },
21
24
  "install": {
22
25
  "npmSpec": "@openclaw/twitch",
23
26
  "defaultChoice": "npm",
24
27
  "minHostVersion": ">=2026.4.10"
25
28
  },
26
29
  "compat": {
27
- "pluginApi": ">=2026.7.2-beta.2"
30
+ "pluginApi": ">=2026.7.2-beta.4"
28
31
  },
29
32
  "build": {
30
- "openclawVersion": "2026.7.2-beta.2"
33
+ "openclawVersion": "2026.7.2-beta.4"
31
34
  },
32
35
  "channel": {
33
36
  "id": "twitch",
37
+ "configuredState": {
38
+ "env": {
39
+ "anyOf": [
40
+ "OPENCLAW_TWITCH_ACCESS_TOKEN"
41
+ ]
42
+ }
43
+ },
34
44
  "label": "Twitch",
35
45
  "selectionLabel": "Twitch (Chat)",
36
46
  "docsPath": "/channels/twitch",
37
47
  "blurb": "Twitch chat integration",
38
48
  "aliases": [
39
49
  "twitch-chat"
40
- ]
50
+ ],
51
+ "setup": {
52
+ "fields": []
53
+ }
41
54
  },
42
55
  "release": {
43
56
  "publishToClawHub": true,
@@ -55,7 +68,7 @@
55
68
  "README.md"
56
69
  ],
57
70
  "peerDependencies": {
58
- "openclaw": ">=2026.7.2-beta.2"
71
+ "openclaw": ">=2026.7.2-beta.4"
59
72
  },
60
73
  "peerDependenciesMeta": {
61
74
  "openclaw": {