@openclaw/twitch 2026.11.3 → 2026.11.5-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.
@@ -1,126 +1,12 @@
1
- import { n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-CkRhClVg.mjs";
2
- import { l as normalizeTwitchChannel } from "./setup-surface-BHuTmMZL.mjs";
3
- import { t as getTwitchRuntime } from "./runtime-B5If4b0g.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-DuCk_ZHo.mjs";
2
+ import { i as getTwitchRuntime, n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-D_NszQlS.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
- //#region 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
- }
123
- //#endregion
9
+ import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
124
10
  //#region extensions/twitch/src/twitch-ingress.ts
125
11
  const TWITCH_INGRESS_PAYLOAD_VERSION = 1;
126
12
  const TWITCH_INGRESS_DRAIN_INTERVAL_MS = 1e3;
@@ -179,43 +65,9 @@ function createTwitchIngress(options) {
179
65
  deserialize: (rawEvent) => deserializeTwitchIngressEvent(rawEvent),
180
66
  createClaimError: (kind) => new TwitchIngressPermanentError(kind === "invalid-version" ? "Twitch ingress payload is invalid." : "Twitch ingress event identity changed after durable admission.")
181
67
  },
182
- deliver: async (rawEvent, lifecycle, claim) => {
183
- const message = normalizeClaimedTwitchMessage(rawEvent, claim.id);
184
- let handedOff = false;
185
- const deliveryAbortSignal = AbortSignal.any([lifecycle.abortSignal, shutdown.signal]);
186
- try {
187
- await options.deliver(message, {
188
- admission: lifecycle.admission,
189
- abortSignal: deliveryAbortSignal,
190
- onAdopted: async () => {
191
- handedOff = true;
192
- await lifecycle.onAdopted();
193
- },
194
- onDeferred: () => {
195
- handedOff = true;
196
- lifecycle.onDeferred();
197
- },
198
- onDeferredHeartbeat: () => lifecycle.onDeferredHeartbeat?.(),
199
- deferredHeartbeatIntervalMs: lifecycle.deferredHeartbeatIntervalMs,
200
- onAbandoned: async () => {
201
- handedOff = true;
202
- await lifecycle.onAbandoned();
203
- }
204
- });
205
- } catch (error) {
206
- if (stopped || deliveryAbortSignal.aborted) return {
207
- kind: "failed-retryable",
208
- error
209
- };
210
- throw error;
211
- }
212
- if (!handedOff && (stopped || deliveryAbortSignal.aborted)) return {
213
- kind: "failed-retryable",
214
- error: stoppedError()
215
- };
216
- },
68
+ deliver: (rawEvent, lifecycle, claim) => options.deliver(normalizeClaimedTwitchMessage(rawEvent, claim.id), bindIngressLifecycleToReplyOptions(lifecycle).turnAdoptionLifecycle),
217
69
  deferredClaims: "manual",
218
- pollIntervalMs: options.pollIntervalMs ?? TWITCH_INGRESS_DRAIN_INTERVAL_MS,
70
+ pollIntervalMs: TWITCH_INGRESS_DRAIN_INTERVAL_MS,
219
71
  retention: {
220
72
  completedMaxEntries: 1e3,
221
73
  failedMaxEntries: 1e3
@@ -262,6 +114,53 @@ function createTwitchIngress(options) {
262
114
  }
263
115
  //#endregion
264
116
  //#region extensions/twitch/src/monitor.ts
117
+ const twitchUserIdentity = defineStableChannelIngressIdentity({
118
+ key: "sender-id",
119
+ entryIdPrefix: "twitch-user-entry"
120
+ });
121
+ const twitchRoleIdentity = defineStableChannelIngressIdentity({
122
+ key: "sender-id",
123
+ normalizeEntry: () => null,
124
+ aliases: [
125
+ "moderator",
126
+ "owner",
127
+ "vip",
128
+ "subscriber"
129
+ ].map((role) => ({
130
+ key: `role-${role}`,
131
+ kind: "role",
132
+ normalizeEntry: (entry) => normalizeTwitchRole(entry) === role ? role : null,
133
+ normalizeSubject: normalizeTwitchRole
134
+ })),
135
+ resolveEntryId: ({ entryIndex }) => `twitch-role-entry-${entryIndex + 1}`
136
+ });
137
+ function resolveTwitchPolicyKind(account) {
138
+ if (account.allowFrom !== void 0) return "allowFrom";
139
+ if (account.allowedRoles && account.allowedRoles.length > 0) return "role";
140
+ return "open";
141
+ }
142
+ function twitchSubject(message) {
143
+ return {
144
+ stableId: message.userId,
145
+ aliases: {
146
+ "role-moderator": message.isMod ? "moderator" : void 0,
147
+ "role-owner": message.isOwner ? "owner" : void 0,
148
+ "role-vip": message.isVip ? "vip" : void 0,
149
+ "role-subscriber": message.isSub ? "subscriber" : void 0
150
+ }
151
+ };
152
+ }
153
+ function normalizeTwitchRole(value) {
154
+ const role = normalizeLowercaseStringOrEmpty(value);
155
+ return role === "moderator" || role === "owner" || role === "vip" || role === "subscriber" ? role : null;
156
+ }
157
+ function mentionsBot(message, botUsername) {
158
+ const expected = normalizeLowercaseStringOrEmpty(botUsername);
159
+ const mentionRegex = /@(\w+)/g;
160
+ let match;
161
+ while ((match = mentionRegex.exec(message)) !== null) if ((match[1] ? normalizeLowercaseStringOrEmpty(match[1]) : "") === expected) return true;
162
+ return false;
163
+ }
265
164
  async function monitorTwitchProvider(options) {
266
165
  const { account, accountId, channelRuntime, config, runtime, abortSignal, statusSink } = options;
267
166
  const core = getTwitchRuntime();
@@ -278,25 +177,42 @@ async function monitorTwitchProvider(options) {
278
177
  error: (msg) => coreLogger.error(msg),
279
178
  debug: logVerboseMessage
280
179
  }, statusSink);
281
- try {
282
- await clientManager.getClient(account, config, accountId);
283
- } catch (error) {
284
- const errorMsg = formatErrorMessage(error);
285
- runtime.error?.(`Failed to connect: ${errorMsg}`);
286
- throw error;
287
- }
180
+ await clientManager.getClient(account, config, accountId);
288
181
  const ingress = createTwitchIngress({
289
182
  accountId,
290
183
  runtime,
291
184
  deliver: async (message, turnAdoptionLifecycle) => {
292
185
  const botUsername = normalizeLowercaseStringOrEmpty(account.username);
293
186
  if (normalizeLowercaseStringOrEmpty(message.username) === botUsername) return;
294
- if (!(await checkTwitchAccessControl({
295
- message,
296
- account,
297
- accountId,
298
- botUsername
299
- })).allowed) return;
187
+ const checkAccess = (contextBinding) => {
188
+ const policyKind = resolveTwitchPolicyKind(account);
189
+ return core.channel.inbound.ingress.createResolver({
190
+ channelId: "twitch",
191
+ accountId,
192
+ identity: policyKind === "role" ? twitchRoleIdentity : twitchUserIdentity
193
+ }).message({
194
+ subject: twitchSubject(message),
195
+ conversation: {
196
+ kind: "group",
197
+ id: message.channel
198
+ },
199
+ contextBinding,
200
+ event: { mayPair: false },
201
+ mentionFacts: {
202
+ canDetectMention: true,
203
+ wasMentioned: mentionsBot(message.message, account.username)
204
+ },
205
+ dmPolicy: "open",
206
+ groupPolicy: policyKind === "open" ? "open" : "allowlist",
207
+ policy: { activation: {
208
+ requireMention: account.requireMention ?? true,
209
+ allowTextCommands: false,
210
+ order: "before-sender"
211
+ } },
212
+ groupAllowFrom: policyKind === "allowFrom" ? account.allowFrom : policyKind === "role" ? account.allowedRoles?.map((role) => role === "all" ? "*" : role) : void 0
213
+ });
214
+ };
215
+ if ((await checkAccess()).ingress.admission !== "dispatch") return;
300
216
  statusSink?.({ lastInboundAt: Date.now() });
301
217
  const cfg = config;
302
218
  const route = channelRuntime.routing.resolveAgentRoute({
@@ -308,19 +224,13 @@ async function monitorTwitchProvider(options) {
308
224
  id: message.channel
309
225
  }
310
226
  });
311
- const exactAccess = await checkTwitchAccessControl({
312
- message,
313
- account,
314
- accountId,
315
- botUsername: normalizeLowercaseStringOrEmpty(account.username),
316
- contextBinding: {
317
- agentId: route.agentId,
318
- sessionKey: route.sessionKey,
319
- messageId: message.id,
320
- inboundEventKind: "user_request"
321
- }
227
+ const exactAccess = await checkAccess({
228
+ agentId: route.agentId,
229
+ sessionKey: route.sessionKey,
230
+ messageId: message.id,
231
+ inboundEventKind: "user_request"
322
232
  });
323
- if (!exactAccess.allowed) return;
233
+ if (exactAccess.ingress.admission !== "dispatch") return;
324
234
  await channelRuntime.inbound.run({
325
235
  channel: "twitch",
326
236
  accountId,
@@ -348,7 +258,7 @@ async function monitorTwitchProvider(options) {
348
258
  body: input.rawText
349
259
  });
350
260
  const ctxPayload = channelRuntime.inbound.buildContext({
351
- channelIngress: exactAccess.channelIngress,
261
+ channelIngress: exactAccess,
352
262
  channel: "twitch",
353
263
  accountId,
354
264
  messageId: input.id,
@@ -433,7 +343,7 @@ async function monitorTwitchProvider(options) {
433
343
  }
434
344
  });
435
345
  ingress.start();
436
- const unregisterHandler = clientManager.onMessage(account, (message) => {
346
+ const unregisterHandler = clientManager.onMessage((message) => {
437
347
  if (stopped) return;
438
348
  ingress.accept(message).catch((err) => {
439
349
  runtime.error?.(`Message durable admission failed: ${String(err)}`);