@openclaw/twitch 2026.10.10-beta.5 → 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.
- package/dist/.setup/{monitor-DH2GTYQv.mjs → monitor-DfA87gBg.mjs} +94 -186
- package/dist/.setup/plugin-B2l8TCND.mjs +1023 -0
- package/dist/.setup/setup-plugin-api-EN3PbyIC.mjs +2 -0
- package/dist/.setup/{setup-surface-BHuTmMZL.mjs → setup-surface-mdCyd7g7.mjs} +82 -99
- package/dist/.source-module-urls/e92ae748f4a308f6cf1a5ef62518f7ba0627945de435d928747fa07ea1b4421f.json +1 -1
- package/dist/api.js +1 -3
- package/dist/channel-plugin-api.js +1 -1
- package/dist/index.js +1 -2
- package/dist/setup-entry.js +2 -3
- package/dist/setup-plugin-api.js +1 -1
- package/package.json +5 -5
- package/dist/.setup/plugin-Ds8927WG.mjs +0 -861
- package/dist/.setup/runtime-B5If4b0g.mjs +0 -8
- package/dist/.setup/setup-plugin-api-VbVHO_SG.mjs +0 -2
|
@@ -1,127 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
12
|
-
|
|
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
|
|
124
|
-
//#region extensions/twitch/src/twitch-ingress.ts
|
|
9
|
+
import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
|
|
10
|
+
// extensions/twitch/src/twitch-ingress.ts
|
|
125
11
|
const TWITCH_INGRESS_PAYLOAD_VERSION = 1;
|
|
126
12
|
const TWITCH_INGRESS_DRAIN_INTERVAL_MS = 1e3;
|
|
127
13
|
const TwitchIngressPermanentError = createChannelIngressError("TwitchIngressPermanentError");
|
|
@@ -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:
|
|
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:
|
|
70
|
+
pollIntervalMs: TWITCH_INGRESS_DRAIN_INTERVAL_MS,
|
|
219
71
|
retention: {
|
|
220
72
|
completedMaxEntries: 1e3,
|
|
221
73
|
failedMaxEntries: 1e3
|
|
@@ -260,8 +112,54 @@ function createTwitchIngress(options) {
|
|
|
260
112
|
}
|
|
261
113
|
};
|
|
262
114
|
}
|
|
263
|
-
|
|
264
|
-
|
|
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
|
+
}
|
|
265
163
|
async function monitorTwitchProvider(options) {
|
|
266
164
|
const { account, accountId, channelRuntime, config, runtime, abortSignal, statusSink } = options;
|
|
267
165
|
const core = getTwitchRuntime();
|
|
@@ -278,25 +176,42 @@ async function monitorTwitchProvider(options) {
|
|
|
278
176
|
error: (msg) => coreLogger.error(msg),
|
|
279
177
|
debug: logVerboseMessage
|
|
280
178
|
}, statusSink);
|
|
281
|
-
|
|
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
|
-
}
|
|
179
|
+
await clientManager.getClient(account, config, accountId);
|
|
288
180
|
const ingress = createTwitchIngress({
|
|
289
181
|
accountId,
|
|
290
182
|
runtime,
|
|
291
183
|
deliver: async (message, turnAdoptionLifecycle) => {
|
|
292
184
|
const botUsername = normalizeLowercaseStringOrEmpty(account.username);
|
|
293
185
|
if (normalizeLowercaseStringOrEmpty(message.username) === botUsername) return;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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;
|
|
300
215
|
statusSink?.({ lastInboundAt: Date.now() });
|
|
301
216
|
const cfg = config;
|
|
302
217
|
const route = channelRuntime.routing.resolveAgentRoute({
|
|
@@ -308,19 +223,13 @@ async function monitorTwitchProvider(options) {
|
|
|
308
223
|
id: message.channel
|
|
309
224
|
}
|
|
310
225
|
});
|
|
311
|
-
const exactAccess = await
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
contextBinding: {
|
|
317
|
-
agentId: route.agentId,
|
|
318
|
-
sessionKey: route.sessionKey,
|
|
319
|
-
messageId: message.id,
|
|
320
|
-
inboundEventKind: "user_request"
|
|
321
|
-
}
|
|
226
|
+
const exactAccess = await checkAccess({
|
|
227
|
+
agentId: route.agentId,
|
|
228
|
+
sessionKey: route.sessionKey,
|
|
229
|
+
messageId: message.id,
|
|
230
|
+
inboundEventKind: "user_request"
|
|
322
231
|
});
|
|
323
|
-
if (
|
|
232
|
+
if (exactAccess.ingress.admission !== "dispatch") return;
|
|
324
233
|
await channelRuntime.inbound.run({
|
|
325
234
|
channel: "twitch",
|
|
326
235
|
accountId,
|
|
@@ -348,7 +257,7 @@ async function monitorTwitchProvider(options) {
|
|
|
348
257
|
body: input.rawText
|
|
349
258
|
});
|
|
350
259
|
const ctxPayload = channelRuntime.inbound.buildContext({
|
|
351
|
-
channelIngress: exactAccess
|
|
260
|
+
channelIngress: exactAccess,
|
|
352
261
|
channel: "twitch",
|
|
353
262
|
accountId,
|
|
354
263
|
messageId: input.id,
|
|
@@ -433,7 +342,7 @@ async function monitorTwitchProvider(options) {
|
|
|
433
342
|
}
|
|
434
343
|
});
|
|
435
344
|
ingress.start();
|
|
436
|
-
const unregisterHandler = clientManager.onMessage(
|
|
345
|
+
const unregisterHandler = clientManager.onMessage((message) => {
|
|
437
346
|
if (stopped) return;
|
|
438
347
|
ingress.accept(message).catch((err) => {
|
|
439
348
|
runtime.error?.(`Message durable admission failed: ${String(err)}`);
|
|
@@ -454,5 +363,4 @@ async function monitorTwitchProvider(options) {
|
|
|
454
363
|
}, { once: true });
|
|
455
364
|
return { stop };
|
|
456
365
|
}
|
|
457
|
-
//#endregion
|
|
458
366
|
export { monitorTwitchProvider };
|