@openclaw/twitch 2026.10.10 → 2026.11.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,125 +1,12 @@
1
- import { n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-CnPNkPhc.mjs";
2
- import { l as normalizeTwitchChannel } from "./setup-surface-8f7RsuJw.mjs";
3
- import { t as getTwitchRuntime } from "./runtime-DrwVh6hF.mjs";
4
- import { createChannelIngressError, createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
5
- import { createChannelInboundEnvelopeBuilderAsync } from "openclaw/plugin-sdk/channel-inbound";
1
+ import { l as normalizeTwitchChannel } from "./setup-surface-mdCyd7g7.mjs";
2
+ import { i as getTwitchRuntime, n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-B2l8TCND.mjs";
3
+ import { bindIngressLifecycleToReplyOptions, createChannelIngressError, createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
6
4
  import { collectErrorGraphCandidates, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
5
+ import { createChannelInboundEnvelopeBuilderAsync } from "openclaw/plugin-sdk/channel-inbound";
7
6
  import { normalizeLowercaseStringOrEmpty, normalizeNullableString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
7
  import { HttpStatusCodeError } from "@twurple/api-call";
9
- import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
10
8
  import { defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
11
- // extensions/twitch/src/access-control.ts
12
- const twitchUserIdentity = defineStableChannelIngressIdentity({
13
- key: "sender-id",
14
- entryIdPrefix: "twitch-user-entry"
15
- });
16
- const twitchRoleIdentity = defineStableChannelIngressIdentity({
17
- key: "sender-id",
18
- normalizeEntry: () => null,
19
- aliases: [
20
- "moderator",
21
- "owner",
22
- "vip",
23
- "subscriber"
24
- ].map((role) => ({
25
- key: `role-${role}`,
26
- kind: "role",
27
- normalizeEntry: (entry) => normalizeTwitchRole(entry) === role ? role : null,
28
- normalizeSubject: normalizeTwitchRole
29
- })),
30
- resolveEntryId: ({ entryIndex }) => `twitch-role-entry-${entryIndex + 1}`
31
- });
32
- async function checkTwitchAccessControl(params) {
33
- const { message, account, botUsername } = params;
34
- const policyKind = resolveTwitchPolicyKind(account);
35
- const resolved = await getTwitchRuntime().channel.inbound.ingress.createResolver({
36
- channelId: "twitch",
37
- accountId: params.accountId,
38
- identity: policyKind === "role" ? twitchRoleIdentity : twitchUserIdentity
39
- }).message({
40
- subject: twitchSubject(message),
41
- conversation: {
42
- kind: "group",
43
- id: message.channel
44
- },
45
- contextBinding: params.contextBinding,
46
- event: { mayPair: false },
47
- mentionFacts: {
48
- canDetectMention: true,
49
- wasMentioned: mentionsBot(message.message, botUsername)
50
- },
51
- dmPolicy: "open",
52
- groupPolicy: policyKind === "open" ? "open" : "allowlist",
53
- policy: { activation: {
54
- requireMention: account.requireMention ?? true,
55
- allowTextCommands: false,
56
- order: "before-sender"
57
- } },
58
- groupAllowFrom: policyKind === "allowFrom" ? account.allowFrom : policyKind === "role" ? account.allowedRoles?.map((role) => role === "all" ? "*" : role) : void 0
59
- });
60
- const decision = resolved.ingress;
61
- if (decision.decisiveGateId === "activation" && decision.admission !== "dispatch") return {
62
- allowed: false,
63
- reason: "message does not mention the bot (requireMention is enabled)"
64
- };
65
- if (decision.admission === "dispatch") return {
66
- allowed: true,
67
- channelIngress: resolved
68
- };
69
- if (policyKind === "allowFrom") {
70
- if (!params.message.userId) return {
71
- allowed: false,
72
- reason: "sender user ID not available for allowlist check"
73
- };
74
- return {
75
- allowed: false,
76
- reason: "sender is not in allowFrom allowlist"
77
- };
78
- }
79
- if (policyKind === "role") return {
80
- allowed: false,
81
- reason: `sender does not have any of the required roles: ${params.account.allowedRoles?.join(", ") ?? ""}`
82
- };
83
- return {
84
- allowed: false,
85
- reason: reasonForTwitchIngressDecision(decision)
86
- };
87
- }
88
- function resolveTwitchPolicyKind(account) {
89
- if (account.allowFrom !== void 0) return "allowFrom";
90
- if (account.allowedRoles && account.allowedRoles.length > 0) return "role";
91
- return "open";
92
- }
93
- function twitchSubject(message) {
94
- return {
95
- stableId: message.userId,
96
- aliases: {
97
- "role-moderator": message.isMod ? "moderator" : void 0,
98
- "role-owner": message.isOwner ? "owner" : void 0,
99
- "role-vip": message.isVip ? "vip" : void 0,
100
- "role-subscriber": message.isSub ? "subscriber" : void 0
101
- }
102
- };
103
- }
104
- function normalizeTwitchRole(value) {
105
- const role = normalizeLowercaseStringOrEmpty(value);
106
- return role === "moderator" || role === "owner" || role === "vip" || role === "subscriber" ? role : null;
107
- }
108
- function reasonForTwitchIngressDecision(decision) {
109
- switch (decision.reasonCode) {
110
- case "activation_skipped": return "message does not mention the bot (requireMention is enabled)";
111
- case "group_policy_empty_allowlist":
112
- case "group_policy_not_allowlisted": return "sender is not in allowFrom allowlist";
113
- default: return decision.reasonCode;
114
- }
115
- }
116
- function mentionsBot(message, botUsername) {
117
- const expected = normalizeLowercaseStringOrEmpty(botUsername);
118
- const mentionRegex = /@(\w+)/g;
119
- let match;
120
- while ((match = mentionRegex.exec(message)) !== null) if ((match[1] ? normalizeLowercaseStringOrEmpty(match[1]) : "") === expected) return true;
121
- return false;
122
- }
9
+ import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
123
10
  // extensions/twitch/src/twitch-ingress.ts
124
11
  const TWITCH_INGRESS_PAYLOAD_VERSION = 1;
125
12
  const TWITCH_INGRESS_DRAIN_INTERVAL_MS = 1e3;
@@ -178,43 +65,9 @@ function createTwitchIngress(options) {
178
65
  deserialize: (rawEvent) => deserializeTwitchIngressEvent(rawEvent),
179
66
  createClaimError: (kind) => new TwitchIngressPermanentError(kind === "invalid-version" ? "Twitch ingress payload is invalid." : "Twitch ingress event identity changed after durable admission.")
180
67
  },
181
- deliver: async (rawEvent, lifecycle, claim) => {
182
- const message = normalizeClaimedTwitchMessage(rawEvent, claim.id);
183
- let handedOff = false;
184
- const deliveryAbortSignal = AbortSignal.any([lifecycle.abortSignal, shutdown.signal]);
185
- try {
186
- await options.deliver(message, {
187
- admission: lifecycle.admission,
188
- abortSignal: deliveryAbortSignal,
189
- onAdopted: async () => {
190
- handedOff = true;
191
- await lifecycle.onAdopted();
192
- },
193
- onDeferred: () => {
194
- handedOff = true;
195
- lifecycle.onDeferred();
196
- },
197
- onDeferredHeartbeat: () => lifecycle.onDeferredHeartbeat?.(),
198
- deferredHeartbeatIntervalMs: lifecycle.deferredHeartbeatIntervalMs,
199
- onAbandoned: async () => {
200
- handedOff = true;
201
- await lifecycle.onAbandoned();
202
- }
203
- });
204
- } catch (error) {
205
- if (stopped || deliveryAbortSignal.aborted) return {
206
- kind: "failed-retryable",
207
- error
208
- };
209
- throw error;
210
- }
211
- if (!handedOff && (stopped || deliveryAbortSignal.aborted)) return {
212
- kind: "failed-retryable",
213
- error: stoppedError()
214
- };
215
- },
68
+ deliver: (rawEvent, lifecycle, claim) => options.deliver(normalizeClaimedTwitchMessage(rawEvent, claim.id), bindIngressLifecycleToReplyOptions(lifecycle).turnAdoptionLifecycle),
216
69
  deferredClaims: "manual",
217
- pollIntervalMs: options.pollIntervalMs ?? TWITCH_INGRESS_DRAIN_INTERVAL_MS,
70
+ pollIntervalMs: TWITCH_INGRESS_DRAIN_INTERVAL_MS,
218
71
  retention: {
219
72
  completedMaxEntries: 1e3,
220
73
  failedMaxEntries: 1e3
@@ -260,6 +113,53 @@ function createTwitchIngress(options) {
260
113
  };
261
114
  }
262
115
  // extensions/twitch/src/monitor.ts
116
+ const twitchUserIdentity = defineStableChannelIngressIdentity({
117
+ key: "sender-id",
118
+ entryIdPrefix: "twitch-user-entry"
119
+ });
120
+ const twitchRoleIdentity = defineStableChannelIngressIdentity({
121
+ key: "sender-id",
122
+ normalizeEntry: () => null,
123
+ aliases: [
124
+ "moderator",
125
+ "owner",
126
+ "vip",
127
+ "subscriber"
128
+ ].map((role) => ({
129
+ key: `role-${role}`,
130
+ kind: "role",
131
+ normalizeEntry: (entry) => normalizeTwitchRole(entry) === role ? role : null,
132
+ normalizeSubject: normalizeTwitchRole
133
+ })),
134
+ resolveEntryId: ({ entryIndex }) => `twitch-role-entry-${entryIndex + 1}`
135
+ });
136
+ function resolveTwitchPolicyKind(account) {
137
+ if (account.allowFrom !== void 0) return "allowFrom";
138
+ if (account.allowedRoles && account.allowedRoles.length > 0) return "role";
139
+ return "open";
140
+ }
141
+ function twitchSubject(message) {
142
+ return {
143
+ stableId: message.userId,
144
+ aliases: {
145
+ "role-moderator": message.isMod ? "moderator" : void 0,
146
+ "role-owner": message.isOwner ? "owner" : void 0,
147
+ "role-vip": message.isVip ? "vip" : void 0,
148
+ "role-subscriber": message.isSub ? "subscriber" : void 0
149
+ }
150
+ };
151
+ }
152
+ function normalizeTwitchRole(value) {
153
+ const role = normalizeLowercaseStringOrEmpty(value);
154
+ return role === "moderator" || role === "owner" || role === "vip" || role === "subscriber" ? role : null;
155
+ }
156
+ function mentionsBot(message, botUsername) {
157
+ const expected = normalizeLowercaseStringOrEmpty(botUsername);
158
+ const mentionRegex = /@(\w+)/g;
159
+ let match;
160
+ while ((match = mentionRegex.exec(message)) !== null) if ((match[1] ? normalizeLowercaseStringOrEmpty(match[1]) : "") === expected) return true;
161
+ return false;
162
+ }
263
163
  async function monitorTwitchProvider(options) {
264
164
  const { account, accountId, channelRuntime, config, runtime, abortSignal, statusSink } = options;
265
165
  const core = getTwitchRuntime();
@@ -276,25 +176,42 @@ async function monitorTwitchProvider(options) {
276
176
  error: (msg) => coreLogger.error(msg),
277
177
  debug: logVerboseMessage
278
178
  }, statusSink);
279
- try {
280
- await clientManager.getClient(account, config, accountId);
281
- } catch (error) {
282
- const errorMsg = formatErrorMessage(error);
283
- runtime.error?.(`Failed to connect: ${errorMsg}`);
284
- throw error;
285
- }
179
+ await clientManager.getClient(account, config, accountId);
286
180
  const ingress = createTwitchIngress({
287
181
  accountId,
288
182
  runtime,
289
183
  deliver: async (message, turnAdoptionLifecycle) => {
290
184
  const botUsername = normalizeLowercaseStringOrEmpty(account.username);
291
185
  if (normalizeLowercaseStringOrEmpty(message.username) === botUsername) return;
292
- if (!(await checkTwitchAccessControl({
293
- message,
294
- account,
295
- accountId,
296
- botUsername
297
- })).allowed) return;
186
+ const checkAccess = (contextBinding) => {
187
+ const policyKind = resolveTwitchPolicyKind(account);
188
+ return core.channel.inbound.ingress.createResolver({
189
+ channelId: "twitch",
190
+ accountId,
191
+ identity: policyKind === "role" ? twitchRoleIdentity : twitchUserIdentity
192
+ }).message({
193
+ subject: twitchSubject(message),
194
+ conversation: {
195
+ kind: "group",
196
+ id: message.channel
197
+ },
198
+ contextBinding,
199
+ event: { mayPair: false },
200
+ mentionFacts: {
201
+ canDetectMention: true,
202
+ wasMentioned: mentionsBot(message.message, account.username)
203
+ },
204
+ dmPolicy: "open",
205
+ groupPolicy: policyKind === "open" ? "open" : "allowlist",
206
+ policy: { activation: {
207
+ requireMention: account.requireMention ?? true,
208
+ allowTextCommands: false,
209
+ order: "before-sender"
210
+ } },
211
+ groupAllowFrom: policyKind === "allowFrom" ? account.allowFrom : policyKind === "role" ? account.allowedRoles?.map((role) => role === "all" ? "*" : role) : void 0
212
+ });
213
+ };
214
+ if ((await checkAccess()).ingress.admission !== "dispatch") return;
298
215
  statusSink?.({ lastInboundAt: Date.now() });
299
216
  const cfg = config;
300
217
  const route = channelRuntime.routing.resolveAgentRoute({
@@ -306,19 +223,13 @@ async function monitorTwitchProvider(options) {
306
223
  id: message.channel
307
224
  }
308
225
  });
309
- const exactAccess = await checkTwitchAccessControl({
310
- message,
311
- account,
312
- accountId,
313
- botUsername: normalizeLowercaseStringOrEmpty(account.username),
314
- contextBinding: {
315
- agentId: route.agentId,
316
- sessionKey: route.sessionKey,
317
- messageId: message.id,
318
- inboundEventKind: "user_request"
319
- }
226
+ const exactAccess = await checkAccess({
227
+ agentId: route.agentId,
228
+ sessionKey: route.sessionKey,
229
+ messageId: message.id,
230
+ inboundEventKind: "user_request"
320
231
  });
321
- if (!exactAccess.allowed) return;
232
+ if (exactAccess.ingress.admission !== "dispatch") return;
322
233
  await channelRuntime.inbound.run({
323
234
  channel: "twitch",
324
235
  accountId,
@@ -346,7 +257,7 @@ async function monitorTwitchProvider(options) {
346
257
  body: input.rawText
347
258
  });
348
259
  const ctxPayload = channelRuntime.inbound.buildContext({
349
- channelIngress: exactAccess.channelIngress,
260
+ channelIngress: exactAccess,
350
261
  channel: "twitch",
351
262
  accountId,
352
263
  messageId: input.id,
@@ -431,7 +342,7 @@ async function monitorTwitchProvider(options) {
431
342
  }
432
343
  });
433
344
  ingress.start();
434
- const unregisterHandler = clientManager.onMessage(account, (message) => {
345
+ const unregisterHandler = clientManager.onMessage((message) => {
435
346
  if (stopped) return;
436
347
  ingress.accept(message).catch((err) => {
437
348
  runtime.error?.(`Message durable admission failed: ${String(err)}`);