@openclaw/twitch 2026.8.1-beta.3 → 2026.8.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.
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{monitor-D03bj88f.js → monitor-DwOuh3Ah.js} +26 -25
- package/dist/{plugin-BbgNQfFL.js → plugin--Ji1Tvw0.js} +205 -353
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-1wrrTKpx.js → setup-surface-CPpsDfR8.js} +4 -2
- package/openclaw.plugin.json +16 -3
- package/package.json +4 -4
package/dist/api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as twitchPlugin } from "./plugin
|
|
1
|
+
import { t as twitchPlugin } from "./plugin--Ji1Tvw0.js";
|
|
2
2
|
export { twitchPlugin };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as stripMarkdownForTwitch, r as getOrCreateClientManager } from "./plugin--Ji1Tvw0.js";
|
|
2
|
+
import { m as normalizeTwitchChannel } from "./setup-surface-CPpsDfR8.js";
|
|
3
3
|
import { t as getTwitchRuntime } from "./runtime-B5If4b0g.js";
|
|
4
4
|
import { createChannelIngressError, createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
|
|
5
5
|
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
6
6
|
import { normalizeLowercaseStringOrEmpty, normalizeNullableString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
7
|
import { HttpStatusCodeError } from "@twurple/api-call";
|
|
8
8
|
import { createChannelInboundEnvelopeBuilder } from "openclaw/plugin-sdk/channel-inbound";
|
|
9
|
+
import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
|
|
9
10
|
import { createChannelIngressResolver, defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
|
|
10
11
|
//#region extensions/twitch/src/access-control.ts
|
|
11
12
|
const twitchUserIdentity = defineStableChannelIngressIdentity({
|
|
@@ -13,21 +14,19 @@ const twitchUserIdentity = defineStableChannelIngressIdentity({
|
|
|
13
14
|
entryIdPrefix: "twitch-user-entry"
|
|
14
15
|
});
|
|
15
16
|
const twitchRoleIdentity = defineStableChannelIngressIdentity({
|
|
16
|
-
key: "
|
|
17
|
-
|
|
18
|
-
normalizeEntry: normalizeTwitchRole,
|
|
19
|
-
normalizeSubject: normalizeTwitchRole,
|
|
17
|
+
key: "sender-id",
|
|
18
|
+
normalizeEntry: () => null,
|
|
20
19
|
aliases: [
|
|
20
|
+
"moderator",
|
|
21
21
|
"owner",
|
|
22
22
|
"vip",
|
|
23
23
|
"subscriber"
|
|
24
24
|
].map((role) => ({
|
|
25
25
|
key: `role-${role}`,
|
|
26
26
|
kind: "role",
|
|
27
|
-
normalizeEntry: () => null,
|
|
27
|
+
normalizeEntry: (entry) => normalizeTwitchRole(entry) === role ? role : null,
|
|
28
28
|
normalizeSubject: normalizeTwitchRole
|
|
29
29
|
})),
|
|
30
|
-
isWildcardEntry: (entry) => normalizeTwitchRole(entry) === "all",
|
|
31
30
|
resolveEntryId: ({ entryIndex }) => `twitch-role-entry-${entryIndex + 1}`
|
|
32
31
|
});
|
|
33
32
|
async function checkTwitchAccessControl(params) {
|
|
@@ -35,10 +34,10 @@ async function checkTwitchAccessControl(params) {
|
|
|
35
34
|
const policyKind = resolveTwitchPolicyKind(account);
|
|
36
35
|
const resolved = await createChannelIngressResolver({
|
|
37
36
|
channelId: "twitch",
|
|
38
|
-
accountId:
|
|
37
|
+
accountId: params.accountId,
|
|
39
38
|
identity: policyKind === "role" ? twitchRoleIdentity : twitchUserIdentity
|
|
40
39
|
}).message({
|
|
41
|
-
subject:
|
|
40
|
+
subject: twitchSubject(message),
|
|
42
41
|
conversation: {
|
|
43
42
|
kind: "group",
|
|
44
43
|
id: message.channel
|
|
@@ -56,7 +55,7 @@ async function checkTwitchAccessControl(params) {
|
|
|
56
55
|
allowTextCommands: false,
|
|
57
56
|
order: "before-sender"
|
|
58
57
|
} },
|
|
59
|
-
groupAllowFrom: policyKind === "allowFrom" ? account.allowFrom : policyKind === "role" ? account.allowedRoles : void 0
|
|
58
|
+
groupAllowFrom: policyKind === "allowFrom" ? account.allowFrom : policyKind === "role" ? account.allowedRoles?.map((role) => role === "all" ? "*" : role) : void 0
|
|
60
59
|
});
|
|
61
60
|
const decision = resolved.ingress;
|
|
62
61
|
if (decision.decisiveGateId === "activation" && decision.admission !== "dispatch") return {
|
|
@@ -105,10 +104,11 @@ function resolveTwitchPolicyKind(account) {
|
|
|
105
104
|
if (account.allowedRoles && account.allowedRoles.length > 0) return "role";
|
|
106
105
|
return "open";
|
|
107
106
|
}
|
|
108
|
-
function
|
|
107
|
+
function twitchSubject(message) {
|
|
109
108
|
return {
|
|
110
|
-
stableId: message.
|
|
109
|
+
stableId: message.userId,
|
|
111
110
|
aliases: {
|
|
111
|
+
"role-moderator": message.isMod ? "moderator" : void 0,
|
|
112
112
|
"role-owner": message.isOwner ? "owner" : void 0,
|
|
113
113
|
"role-vip": message.isVip ? "vip" : void 0,
|
|
114
114
|
"role-subscriber": message.isSub ? "subscriber" : void 0
|
|
@@ -117,8 +117,7 @@ function twitchRoleSubject(message) {
|
|
|
117
117
|
}
|
|
118
118
|
function normalizeTwitchRole(value) {
|
|
119
119
|
const role = normalizeLowercaseStringOrEmpty(value);
|
|
120
|
-
|
|
121
|
-
return role === "moderator" || role === "owner" || role === "vip" || role === "subscriber" || role === "all" ? role : null;
|
|
120
|
+
return role === "moderator" || role === "owner" || role === "vip" || role === "subscriber" ? role : null;
|
|
122
121
|
}
|
|
123
122
|
function reasonForTwitchIngressDecision(decision) {
|
|
124
123
|
switch (decision.reasonCode) {
|
|
@@ -216,6 +215,7 @@ function createTwitchIngress(options) {
|
|
|
216
215
|
handedOff = true;
|
|
217
216
|
lifecycle.onDeferred();
|
|
218
217
|
},
|
|
218
|
+
onDeferredHeartbeat: () => lifecycle.onDeferredHeartbeat?.(),
|
|
219
219
|
onAbandoned: async () => {
|
|
220
220
|
handedOff = true;
|
|
221
221
|
await lifecycle.onAbandoned();
|
|
@@ -285,9 +285,9 @@ function createTwitchIngress(options) {
|
|
|
285
285
|
* Process an incoming Twitch message and dispatch to agent.
|
|
286
286
|
*/
|
|
287
287
|
async function processTwitchMessage(params) {
|
|
288
|
-
const { message, account, accountId, config, runtime,
|
|
288
|
+
const { message, account, accountId, config, runtime, channelRuntime, turnAdoptionLifecycle, statusSink } = params;
|
|
289
289
|
const cfg = config;
|
|
290
|
-
const route =
|
|
290
|
+
const route = channelRuntime.routing.resolveAgentRoute({
|
|
291
291
|
cfg,
|
|
292
292
|
channel: "twitch",
|
|
293
293
|
accountId,
|
|
@@ -299,6 +299,7 @@ async function processTwitchMessage(params) {
|
|
|
299
299
|
const exactAccess = await checkTwitchAccessControl({
|
|
300
300
|
message,
|
|
301
301
|
account,
|
|
302
|
+
accountId,
|
|
302
303
|
botUsername: normalizeLowercaseStringOrEmpty(account.username),
|
|
303
304
|
contextBinding: {
|
|
304
305
|
agentId: route.agentId,
|
|
@@ -308,7 +309,7 @@ async function processTwitchMessage(params) {
|
|
|
308
309
|
}
|
|
309
310
|
});
|
|
310
311
|
if (!exactAccess.allowed) return;
|
|
311
|
-
await
|
|
312
|
+
await channelRuntime.inbound.run({
|
|
312
313
|
channel: "twitch",
|
|
313
314
|
accountId,
|
|
314
315
|
raw: message,
|
|
@@ -334,7 +335,7 @@ async function processTwitchMessage(params) {
|
|
|
334
335
|
timestamp: input.timestamp,
|
|
335
336
|
body: input.rawText
|
|
336
337
|
});
|
|
337
|
-
const ctxPayload =
|
|
338
|
+
const ctxPayload = channelRuntime.inbound.buildContext({
|
|
338
339
|
channelIngress: exactAccess.channelIngress,
|
|
339
340
|
channel: "twitch",
|
|
340
341
|
accountId,
|
|
@@ -365,7 +366,7 @@ async function processTwitchMessage(params) {
|
|
|
365
366
|
commandBody: input.textForCommands
|
|
366
367
|
}
|
|
367
368
|
});
|
|
368
|
-
const tableMode =
|
|
369
|
+
const tableMode = channelRuntime.text.resolveMarkdownTableMode({
|
|
369
370
|
cfg,
|
|
370
371
|
channel: "twitch",
|
|
371
372
|
accountId
|
|
@@ -421,12 +422,11 @@ async function deliverTwitchReply(params) {
|
|
|
421
422
|
error: (msg) => runtime.error?.(msg),
|
|
422
423
|
debug: (msg) => runtime.log?.(msg)
|
|
423
424
|
});
|
|
424
|
-
|
|
425
|
+
const textToSend = stripMarkdownForTwitch([payload.text, ...resolveOutboundMediaUrls(payload)].filter(Boolean).join(" "));
|
|
426
|
+
if (!textToSend) {
|
|
425
427
|
runtime.error?.(`No text to send in reply payload`);
|
|
426
428
|
return { visibleReplySent: false };
|
|
427
429
|
}
|
|
428
|
-
const textToSend = stripMarkdownForTwitch(payload.text);
|
|
429
|
-
if (!textToSend) return { visibleReplySent: false };
|
|
430
430
|
const result = await clientManager.sendMessage(account, channel, textToSend, config, accountId);
|
|
431
431
|
if (!result.ok) throw new Error(result.error ?? "Send failed");
|
|
432
432
|
return { visibleReplySent: true };
|
|
@@ -441,7 +441,7 @@ async function deliverTwitchReply(params) {
|
|
|
441
441
|
* Sets up message handlers and processes incoming messages.
|
|
442
442
|
*/
|
|
443
443
|
async function monitorTwitchProvider(options) {
|
|
444
|
-
const { account, accountId, config, runtime, abortSignal, statusSink } = options;
|
|
444
|
+
const { account, accountId, channelRuntime, config, runtime, abortSignal, statusSink } = options;
|
|
445
445
|
const core = getTwitchRuntime();
|
|
446
446
|
let stopped = false;
|
|
447
447
|
let stopTask;
|
|
@@ -472,6 +472,7 @@ async function monitorTwitchProvider(options) {
|
|
|
472
472
|
if (!(await checkTwitchAccessControl({
|
|
473
473
|
message,
|
|
474
474
|
account,
|
|
475
|
+
accountId,
|
|
475
476
|
botUsername
|
|
476
477
|
})).allowed) return;
|
|
477
478
|
statusSink?.({ lastInboundAt: Date.now() });
|
|
@@ -481,7 +482,7 @@ async function monitorTwitchProvider(options) {
|
|
|
481
482
|
accountId,
|
|
482
483
|
config,
|
|
483
484
|
runtime,
|
|
484
|
-
|
|
485
|
+
channelRuntime,
|
|
485
486
|
turnAdoptionLifecycle,
|
|
486
487
|
statusSink
|
|
487
488
|
});
|
|
@@ -1,20 +1,85 @@
|
|
|
1
|
-
import { a as getAccountConfig, c as resolveTwitchSnapshotAccountId, d as isAccountConfigured, f as missingTargetError, h as resolveTwitchToken, i as DEFAULT_ACCOUNT_ID, l as twitchConfigAdapter, m as normalizeTwitchChannel, o as resolveDefaultTwitchAccountId, p as normalizeToken, r as twitchSetupWizard, s as resolveTwitchAccountContext, t as twitchSetupContract, u as generateMessageId } from "./setup-surface-
|
|
1
|
+
import { a as getAccountConfig, c as resolveTwitchSnapshotAccountId, d as isAccountConfigured, f as missingTargetError, h as resolveTwitchToken, i as DEFAULT_ACCOUNT_ID, l as twitchConfigAdapter, m as normalizeTwitchChannel, o as resolveDefaultTwitchAccountId, p as normalizeToken, r as twitchSetupWizard, s as resolveTwitchAccountContext, t as twitchSetupContract, u as generateMessageId } from "./setup-surface-CPpsDfR8.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 { createAccountStatusSink,
|
|
5
|
+
import { createAccountStatusSink, createChannelMessageAdapterFromOutbound, createMessageReceiptFromOutboundResults, runPassiveAccountLifecycle } from "openclaw/plugin-sdk/channel-outbound";
|
|
6
6
|
import { createLoggedPairingApprovalNotifier, createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";
|
|
7
7
|
import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared";
|
|
8
8
|
import { createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
|
|
9
|
-
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
10
|
-
import { normalizeLowercaseStringOrEmpty, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
11
|
-
import { chunkTextForOutbound, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
|
|
12
9
|
import { RefreshingAuthProvider, StaticAuthProvider } from "@twurple/auth";
|
|
13
10
|
import { ChatClient, LogLevel } from "@twurple/chat";
|
|
11
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
14
12
|
import { channelReadyPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
|
13
|
+
import { chunkTextForOutbound, sanitizeAssistantVisibleText, stripMarkdown } from "openclaw/plugin-sdk/text-chunking";
|
|
15
14
|
import { runChannelProbe, sliceUtf16Safe, withTimeout } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
15
|
+
import { normalizeLowercaseStringOrEmpty, normalizeStringEntries } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
16
16
|
import { z } from "zod";
|
|
17
17
|
import { HttpStatusCodeError, callTwitchApi } from "@twurple/api-call";
|
|
18
|
+
//#region extensions/twitch/src/actions.ts
|
|
19
|
+
/**
|
|
20
|
+
* Read a string parameter from action arguments.
|
|
21
|
+
*
|
|
22
|
+
* @param args - Action arguments
|
|
23
|
+
* @param key - Parameter key
|
|
24
|
+
* @param options - Options for reading the parameter
|
|
25
|
+
* @returns The parameter value or undefined if not found
|
|
26
|
+
*/
|
|
27
|
+
function readStringParam(args, key, options = {}) {
|
|
28
|
+
const value = args[key];
|
|
29
|
+
if (value === void 0 || value === null) {
|
|
30
|
+
if (options.required) throw new Error(`Missing required parameter: ${key}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === "string") return options.trim !== false ? value.trim() : value;
|
|
34
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
35
|
+
const str = String(value);
|
|
36
|
+
return options.trim !== false ? str.trim() : str;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Parameter ${key} must be a string, number, or boolean`);
|
|
39
|
+
}
|
|
40
|
+
/** Supported Twitch actions */
|
|
41
|
+
const TWITCH_ACTIONS = /* @__PURE__ */ new Set(["send"]);
|
|
42
|
+
/**
|
|
43
|
+
* Twitch message actions adapter.
|
|
44
|
+
*/
|
|
45
|
+
const twitchMessageActions = {
|
|
46
|
+
/**
|
|
47
|
+
* List available actions for this channel.
|
|
48
|
+
*/
|
|
49
|
+
describeMessageTool: () => ({ actions: [...TWITCH_ACTIONS] }),
|
|
50
|
+
/**
|
|
51
|
+
* Check if an action is supported.
|
|
52
|
+
*/
|
|
53
|
+
supportsAction: ({ action }) => TWITCH_ACTIONS.has(action),
|
|
54
|
+
/**
|
|
55
|
+
* Extract tool send parameters from action arguments.
|
|
56
|
+
*
|
|
57
|
+
* Parses and validates the "to" and "message" parameters for sending.
|
|
58
|
+
*
|
|
59
|
+
* @param params - Arguments from the tool call
|
|
60
|
+
* @returns Parsed send parameters or null if invalid
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* const result = twitchMessageActions.extractToolSend!({
|
|
64
|
+
* args: { to: "#mychannel", message: "Hello!" }
|
|
65
|
+
* });
|
|
66
|
+
* // Returns: { to: "#mychannel", message: "Hello!" }
|
|
67
|
+
*/
|
|
68
|
+
extractToolSend: ({ args }) => {
|
|
69
|
+
try {
|
|
70
|
+
const to = readStringParam(args, "to", { required: true });
|
|
71
|
+
const message = readStringParam(args, "message", { required: true });
|
|
72
|
+
if (!to || !message) return null;
|
|
73
|
+
return {
|
|
74
|
+
to,
|
|
75
|
+
message
|
|
76
|
+
};
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
18
83
|
//#region extensions/twitch/src/twitch-client.ts
|
|
19
84
|
const TWITCH_CHAT_AUTH_INTENTS = ["chat"];
|
|
20
85
|
/**
|
|
@@ -86,7 +151,7 @@ var TwitchClientManager = class {
|
|
|
86
151
|
if (existing) return existing;
|
|
87
152
|
const pending = this.connectionPromises.get(key);
|
|
88
153
|
if (pending) return pending;
|
|
89
|
-
const connection = this.createConnectedClient(key, account, cfg, accountId);
|
|
154
|
+
const connection = this.createConnectedClient(key, account, () => this.connectionPromises.get(key) === connection, cfg, accountId);
|
|
90
155
|
this.connectionPromises.set(key, connection);
|
|
91
156
|
try {
|
|
92
157
|
return await connection;
|
|
@@ -94,7 +159,7 @@ var TwitchClientManager = class {
|
|
|
94
159
|
if (this.connectionPromises.get(key) === connection) this.connectionPromises.delete(key);
|
|
95
160
|
}
|
|
96
161
|
}
|
|
97
|
-
async createConnectedClient(key, account, cfg, accountId) {
|
|
162
|
+
async createConnectedClient(key, account, ownsConnection, cfg, accountId) {
|
|
98
163
|
const tokenResolution = resolveTwitchToken(cfg, { accountId });
|
|
99
164
|
if (!tokenResolution.token) {
|
|
100
165
|
this.logger.error(`Missing Twitch token for account ${account.username} (set channels.twitch.accounts.${account.username}.token or OPENCLAW_TWITCH_ACCESS_TOKEN for default)`);
|
|
@@ -106,8 +171,10 @@ var TwitchClientManager = class {
|
|
|
106
171
|
throw new Error("Missing Twitch client ID");
|
|
107
172
|
}
|
|
108
173
|
const normalizedToken = normalizeToken(tokenResolution.token);
|
|
174
|
+
const authProvider = await this.createAuthProvider(account, normalizedToken);
|
|
175
|
+
if (!ownsConnection()) throw new Error(`Twitch connection cancelled for ${account.username}`);
|
|
109
176
|
const client = new ChatClient({
|
|
110
|
-
authProvider
|
|
177
|
+
authProvider,
|
|
111
178
|
channels: [account.channel],
|
|
112
179
|
rejoinChannelsOnReconnect: true,
|
|
113
180
|
requestMembershipEvents: true,
|
|
@@ -130,9 +197,7 @@ var TwitchClientManager = class {
|
|
|
130
197
|
case LogLevel.DEBUG:
|
|
131
198
|
this.logger.debug?.(message);
|
|
132
199
|
break;
|
|
133
|
-
case LogLevel.TRACE:
|
|
134
|
-
this.logger.debug?.(message);
|
|
135
|
-
break;
|
|
200
|
+
case LogLevel.TRACE: this.logger.debug?.(message);
|
|
136
201
|
}
|
|
137
202
|
} }
|
|
138
203
|
}
|
|
@@ -261,18 +326,17 @@ var TwitchClientManager = class {
|
|
|
261
326
|
const key = this.getAccountKey(account);
|
|
262
327
|
const client = this.clients.get(key);
|
|
263
328
|
const pendingClient = this.pendingClients.get(key);
|
|
329
|
+
const pendingConnection = this.connectionPromises.delete(key);
|
|
264
330
|
if (pendingClient) {
|
|
265
331
|
pendingClient.quit();
|
|
266
332
|
this.pendingClients.delete(key);
|
|
267
|
-
this.connectionPromises.delete(key);
|
|
268
|
-
this.clearMessageHandler(key);
|
|
269
333
|
}
|
|
270
334
|
if (client) {
|
|
271
335
|
client.quit();
|
|
272
336
|
this.clients.delete(key);
|
|
273
|
-
this.clearMessageHandler(key);
|
|
274
337
|
this.logger.info(`Disconnected ${key}`);
|
|
275
338
|
}
|
|
339
|
+
if (pendingConnection || pendingClient || client) this.clearMessageHandler(key);
|
|
276
340
|
}
|
|
277
341
|
/**
|
|
278
342
|
* Disconnect all clients
|
|
@@ -385,6 +449,94 @@ async function removeClientManager(accountId) {
|
|
|
385
449
|
}
|
|
386
450
|
}
|
|
387
451
|
//#endregion
|
|
452
|
+
//#region extensions/twitch/src/config-schema.ts
|
|
453
|
+
/**
|
|
454
|
+
* Twitch user roles that can be allowed to interact with the bot
|
|
455
|
+
*/
|
|
456
|
+
const TwitchRoleSchema = z.enum([
|
|
457
|
+
"moderator",
|
|
458
|
+
"owner",
|
|
459
|
+
"vip",
|
|
460
|
+
"subscriber",
|
|
461
|
+
"all"
|
|
462
|
+
]);
|
|
463
|
+
const TwitchAccountShape = {
|
|
464
|
+
/** Twitch username */
|
|
465
|
+
username: z.string(),
|
|
466
|
+
/** Twitch OAuth access token (requires chat:read and chat:write scopes) */
|
|
467
|
+
accessToken: z.string(),
|
|
468
|
+
/** Twitch client ID (from Twitch Developer Portal or twitchtokengenerator.com) */
|
|
469
|
+
clientId: z.string().optional(),
|
|
470
|
+
/** Channel name to join */
|
|
471
|
+
channel: z.string().min(1),
|
|
472
|
+
/** Enable this account */
|
|
473
|
+
enabled: z.boolean().optional(),
|
|
474
|
+
/** Allow channel-initiated configuration writes */
|
|
475
|
+
configWrites: z.boolean().optional(),
|
|
476
|
+
/** Allowlist of Twitch user IDs who can interact with the bot (use IDs for safety, not usernames) */
|
|
477
|
+
allowFrom: z.array(z.string()).optional(),
|
|
478
|
+
/** Roles allowed to interact with the bot (e.g., ["moderator", "vip", "subscriber"]) */
|
|
479
|
+
allowedRoles: z.array(TwitchRoleSchema).optional(),
|
|
480
|
+
/** Require @mention to trigger bot responses */
|
|
481
|
+
requireMention: z.boolean().optional(),
|
|
482
|
+
/** Outbound response prefix override for this channel/account. */
|
|
483
|
+
responsePrefix: z.string().optional(),
|
|
484
|
+
/** Twitch client secret (required for token refresh via RefreshingAuthProvider) */
|
|
485
|
+
clientSecret: z.string().optional(),
|
|
486
|
+
/** Refresh token (required for automatic token refresh) */
|
|
487
|
+
refreshToken: z.string().optional(),
|
|
488
|
+
/** Token expiry time in seconds (optional, for token refresh tracking) */
|
|
489
|
+
expiresIn: z.number().nullable().optional(),
|
|
490
|
+
/** Timestamp when token was obtained (optional, for token refresh tracking) */
|
|
491
|
+
obtainmentTimestamp: z.number().optional()
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Twitch account configuration schema
|
|
495
|
+
*/
|
|
496
|
+
const TwitchAccountSchema = z.object(TwitchAccountShape);
|
|
497
|
+
/**
|
|
498
|
+
* Base configuration properties shared by both single and multi-account modes
|
|
499
|
+
*/
|
|
500
|
+
const TwitchConfigBaseShape = {
|
|
501
|
+
name: z.string().optional(),
|
|
502
|
+
enabled: z.boolean().optional(),
|
|
503
|
+
configWrites: z.boolean().optional(),
|
|
504
|
+
markdown: MarkdownConfigSchema.optional(),
|
|
505
|
+
defaultAccount: z.string().optional(),
|
|
506
|
+
historyLimit: z.number().int().min(0).optional(),
|
|
507
|
+
responsePrefix: z.string().optional()
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* Simplified single-account configuration schema
|
|
511
|
+
*
|
|
512
|
+
* Use this for single-account setups. Properties are at the top level,
|
|
513
|
+
* creating an implicit "default" account.
|
|
514
|
+
*/
|
|
515
|
+
const SimplifiedSchema = z.object({
|
|
516
|
+
...TwitchConfigBaseShape,
|
|
517
|
+
...TwitchAccountShape
|
|
518
|
+
});
|
|
519
|
+
/**
|
|
520
|
+
* Multi-account configuration schema
|
|
521
|
+
*
|
|
522
|
+
* Use this for multi-account setups. Each key is an account ID (e.g., "default", "secondary").
|
|
523
|
+
*/
|
|
524
|
+
const MultiAccountSchema = z.object({
|
|
525
|
+
...TwitchConfigBaseShape,
|
|
526
|
+
/** Per-account configuration (for multi-account setups) */
|
|
527
|
+
accounts: z.record(z.string(), TwitchAccountSchema)
|
|
528
|
+
}).refine((val) => Object.keys(val.accounts || {}).length > 0, { message: "accounts must contain at least one entry" });
|
|
529
|
+
/**
|
|
530
|
+
* Twitch plugin configuration schema
|
|
531
|
+
*
|
|
532
|
+
* Supports two mutually exclusive patterns:
|
|
533
|
+
* 1. Simplified single-account: username, accessToken, clientId, channel at top level
|
|
534
|
+
* 2. Multi-account: accounts object with named account configs
|
|
535
|
+
*
|
|
536
|
+
* The union ensures clear discrimination between the two modes.
|
|
537
|
+
*/
|
|
538
|
+
const TwitchConfigSchema = z.union([SimplifiedSchema, MultiAccountSchema]);
|
|
539
|
+
//#endregion
|
|
388
540
|
//#region extensions/twitch/src/utils/markdown.ts
|
|
389
541
|
/**
|
|
390
542
|
* Markdown utilities for Twitch chat
|
|
@@ -395,19 +547,6 @@ async function removeClientManager(accountId) {
|
|
|
395
547
|
function stripMarkdownForTwitch(markdown) {
|
|
396
548
|
return stripMarkdown(markdown, { linkStyle: "label-and-url" }).replace(/\r/g, "").replace(/[ \t]+\n/g, "\n").replace(/\n/g, " ").replace(/[ \t]{2,}/g, " ").trim();
|
|
397
549
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Simple word-boundary chunker for Twitch (500 char limit).
|
|
400
|
-
* Strips markdown before chunking to avoid breaking markdown patterns.
|
|
401
|
-
*
|
|
402
|
-
* @param text - The text to chunk
|
|
403
|
-
* @param limit - Maximum characters per chunk (Twitch limit is 500)
|
|
404
|
-
* @returns Array of text chunks
|
|
405
|
-
*/
|
|
406
|
-
function chunkTextForTwitch(text, limit) {
|
|
407
|
-
const cleaned = stripMarkdownForTwitch(text);
|
|
408
|
-
if (!cleaned) return [];
|
|
409
|
-
return chunkTextForOutbound(cleaned, limit);
|
|
410
|
-
}
|
|
411
550
|
//#endregion
|
|
412
551
|
//#region extensions/twitch/src/send.ts
|
|
413
552
|
/**
|
|
@@ -416,14 +555,12 @@ function chunkTextForTwitch(text, limit) {
|
|
|
416
555
|
* These functions are the primary interface for sending messages to Twitch.
|
|
417
556
|
* They support dependency injection via the `deps` parameter for testability.
|
|
418
557
|
*/
|
|
419
|
-
function createTwitchSendReceipt(
|
|
420
|
-
const messageId = params.messageId.trim();
|
|
421
|
-
const conversationId = params.channel?.trim();
|
|
558
|
+
function createTwitchSendReceipt(messageId, channel) {
|
|
422
559
|
return createMessageReceiptFromOutboundResults({
|
|
423
|
-
results:
|
|
560
|
+
results: messageId ? [{
|
|
424
561
|
channel: "twitch",
|
|
425
562
|
messageId,
|
|
426
|
-
|
|
563
|
+
conversationId: channel
|
|
427
564
|
}] : [],
|
|
428
565
|
kind: "text"
|
|
429
566
|
});
|
|
@@ -457,80 +594,50 @@ async function sendMessageTwitchInternal(channel, text, cfg, accountId, stripMar
|
|
|
457
594
|
if (!account) return {
|
|
458
595
|
ok: false,
|
|
459
596
|
messageId: generateMessageId(),
|
|
460
|
-
receipt: createTwitchSendReceipt(
|
|
461
|
-
messageId: "",
|
|
462
|
-
channel,
|
|
463
|
-
visible: false
|
|
464
|
-
}),
|
|
597
|
+
receipt: createTwitchSendReceipt(),
|
|
465
598
|
error: `Account not found: ${accountId ?? "(default)"}. Available accounts: ${availableAccountIds.join(", ") || "none"}`
|
|
466
599
|
};
|
|
467
600
|
if (!configured) return {
|
|
468
601
|
ok: false,
|
|
469
602
|
messageId: generateMessageId(),
|
|
470
|
-
receipt: createTwitchSendReceipt(
|
|
471
|
-
messageId: "",
|
|
472
|
-
channel,
|
|
473
|
-
visible: false
|
|
474
|
-
}),
|
|
603
|
+
receipt: createTwitchSendReceipt(),
|
|
475
604
|
error: `Account ${resolvedAccountId} is not properly configured. Required: username, clientId, and token (config or env for default account).`
|
|
476
605
|
};
|
|
477
606
|
const normalizedChannel = channel || account.channel;
|
|
478
607
|
if (!normalizedChannel) return {
|
|
479
608
|
ok: false,
|
|
480
609
|
messageId: generateMessageId(),
|
|
481
|
-
receipt: createTwitchSendReceipt(
|
|
482
|
-
messageId: "",
|
|
483
|
-
channel: normalizedChannel,
|
|
484
|
-
visible: false
|
|
485
|
-
}),
|
|
610
|
+
receipt: createTwitchSendReceipt(),
|
|
486
611
|
error: "No channel specified and no default channel in account config"
|
|
487
612
|
};
|
|
488
613
|
const deliveryChannel = normalizeTwitchChannel(normalizedChannel);
|
|
489
614
|
const cleanedText = stripMarkdown ? stripMarkdownForTwitch(text) : text;
|
|
490
615
|
if (!cleanedText) return {
|
|
491
616
|
ok: true,
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
channel: deliveryChannel,
|
|
496
|
-
visible: false
|
|
497
|
-
})
|
|
617
|
+
outcome: "not_sent",
|
|
618
|
+
messageId: "",
|
|
619
|
+
receipt: createTwitchSendReceipt()
|
|
498
620
|
};
|
|
499
621
|
const clientManager = getClientManager(resolvedAccountId);
|
|
500
622
|
if (!clientManager) return {
|
|
501
623
|
ok: false,
|
|
502
624
|
messageId: generateMessageId(),
|
|
503
|
-
receipt: createTwitchSendReceipt(
|
|
504
|
-
messageId: "",
|
|
505
|
-
channel: deliveryChannel,
|
|
506
|
-
visible: false
|
|
507
|
-
}),
|
|
625
|
+
receipt: createTwitchSendReceipt(),
|
|
508
626
|
error: `Client manager not found for account: ${resolvedAccountId}. Please start the Twitch gateway first.`
|
|
509
627
|
};
|
|
510
628
|
try {
|
|
511
629
|
const result = await clientManager.sendMessage(account, deliveryChannel, cleanedText, cfg, resolvedAccountId);
|
|
512
|
-
if (!result.ok) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
messageId,
|
|
519
|
-
channel: deliveryChannel,
|
|
520
|
-
visible: false
|
|
521
|
-
}),
|
|
522
|
-
error: result.error ?? "Send failed"
|
|
523
|
-
};
|
|
524
|
-
}
|
|
630
|
+
if (!result.ok) return {
|
|
631
|
+
ok: false,
|
|
632
|
+
messageId: result.messageId ?? generateMessageId(),
|
|
633
|
+
receipt: createTwitchSendReceipt(),
|
|
634
|
+
error: result.error ?? "Send failed"
|
|
635
|
+
};
|
|
525
636
|
const messageId = result.messageId ?? generateMessageId();
|
|
526
637
|
return {
|
|
527
638
|
ok: true,
|
|
528
639
|
messageId,
|
|
529
|
-
receipt: createTwitchSendReceipt(
|
|
530
|
-
messageId,
|
|
531
|
-
channel: deliveryChannel,
|
|
532
|
-
visible: true
|
|
533
|
-
})
|
|
640
|
+
receipt: createTwitchSendReceipt(messageId, deliveryChannel)
|
|
534
641
|
};
|
|
535
642
|
} catch (error) {
|
|
536
643
|
const errorMsg = formatErrorMessage(error);
|
|
@@ -539,11 +646,7 @@ async function sendMessageTwitchInternal(channel, text, cfg, accountId, stripMar
|
|
|
539
646
|
return {
|
|
540
647
|
ok: false,
|
|
541
648
|
messageId,
|
|
542
|
-
receipt: createTwitchSendReceipt(
|
|
543
|
-
messageId,
|
|
544
|
-
channel: deliveryChannel,
|
|
545
|
-
visible: false
|
|
546
|
-
}),
|
|
649
|
+
receipt: createTwitchSendReceipt(),
|
|
547
650
|
error: errorMsg
|
|
548
651
|
};
|
|
549
652
|
}
|
|
@@ -570,12 +673,9 @@ const twitchOutbound = {
|
|
|
570
673
|
media: true,
|
|
571
674
|
messageSendingHooks: true
|
|
572
675
|
} },
|
|
573
|
-
/** Twitch chat message limit is 500 characters */
|
|
574
676
|
textChunkLimit: 500,
|
|
575
677
|
/** Strip internal assistant tool-trace scaffolding before delivery */
|
|
576
678
|
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
|
|
577
|
-
/** Word-boundary chunker with markdown stripping */
|
|
578
|
-
chunker: chunkTextForTwitch,
|
|
579
679
|
/**
|
|
580
680
|
* Resolve target from context.
|
|
581
681
|
*
|
|
@@ -649,6 +749,7 @@ const twitchOutbound = {
|
|
|
649
749
|
if (!result.ok) throw new Error(result.error ?? "Send failed");
|
|
650
750
|
return {
|
|
651
751
|
channel: "twitch",
|
|
752
|
+
...result.outcome ? { outcome: result.outcome } : {},
|
|
652
753
|
messageId: result.messageId,
|
|
653
754
|
receipt: result.receipt,
|
|
654
755
|
timestamp: Date.now()
|
|
@@ -683,274 +784,11 @@ const twitchOutbound = {
|
|
|
683
784
|
});
|
|
684
785
|
}
|
|
685
786
|
};
|
|
686
|
-
|
|
687
|
-
const receipt = result.receipt ?? createMessageReceiptFromOutboundResults({
|
|
688
|
-
results: result.messageId ? [{
|
|
689
|
-
channel: "twitch",
|
|
690
|
-
messageId: result.messageId
|
|
691
|
-
}] : [],
|
|
692
|
-
kind
|
|
693
|
-
});
|
|
694
|
-
return {
|
|
695
|
-
messageId: result.messageId || receipt.primaryPlatformMessageId,
|
|
696
|
-
receipt
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
const twitchMessageAdapter = defineChannelMessageAdapter({
|
|
787
|
+
const twitchMessageAdapter = createChannelMessageAdapterFromOutbound({
|
|
700
788
|
id: "twitch",
|
|
701
|
-
|
|
702
|
-
text: true,
|
|
703
|
-
media: true,
|
|
704
|
-
messageSendingHooks: true
|
|
705
|
-
} },
|
|
706
|
-
send: {
|
|
707
|
-
text: async (ctx) => {
|
|
708
|
-
if (!twitchOutbound.sendText) throw new Error("Twitch text sending is not available.");
|
|
709
|
-
const { onDeliveryResult, ...outboundCtx } = ctx;
|
|
710
|
-
return toTwitchMessageSendResult(await twitchOutbound.sendText({
|
|
711
|
-
...outboundCtx,
|
|
712
|
-
...onDeliveryResult ? { onDeliveryResult: async (progress) => {
|
|
713
|
-
await onDeliveryResult(toTwitchMessageSendResult(progress, "text"));
|
|
714
|
-
} } : {}
|
|
715
|
-
}), "text");
|
|
716
|
-
},
|
|
717
|
-
media: async (ctx) => {
|
|
718
|
-
if (!twitchOutbound.sendMedia) throw new Error("Twitch media sending is not available.");
|
|
719
|
-
const { onDeliveryResult, ...outboundCtx } = ctx;
|
|
720
|
-
return toTwitchMessageSendResult(await twitchOutbound.sendMedia({
|
|
721
|
-
...outboundCtx,
|
|
722
|
-
...onDeliveryResult ? { onDeliveryResult: async (progress) => {
|
|
723
|
-
await onDeliveryResult(toTwitchMessageSendResult(progress, "media"));
|
|
724
|
-
} } : {}
|
|
725
|
-
}), "media");
|
|
726
|
-
}
|
|
727
|
-
}
|
|
789
|
+
outbound: twitchOutbound
|
|
728
790
|
});
|
|
729
791
|
//#endregion
|
|
730
|
-
//#region extensions/twitch/src/actions.ts
|
|
731
|
-
/**
|
|
732
|
-
* Twitch message actions adapter.
|
|
733
|
-
*
|
|
734
|
-
* Handles tool-based actions for Twitch, such as sending messages.
|
|
735
|
-
*/
|
|
736
|
-
/**
|
|
737
|
-
* Create a tool result with error content.
|
|
738
|
-
*/
|
|
739
|
-
function errorResponse(error) {
|
|
740
|
-
return {
|
|
741
|
-
content: [{
|
|
742
|
-
type: "text",
|
|
743
|
-
text: JSON.stringify({
|
|
744
|
-
ok: false,
|
|
745
|
-
error
|
|
746
|
-
})
|
|
747
|
-
}],
|
|
748
|
-
details: { ok: false }
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Read a string parameter from action arguments.
|
|
753
|
-
*
|
|
754
|
-
* @param args - Action arguments
|
|
755
|
-
* @param key - Parameter key
|
|
756
|
-
* @param options - Options for reading the parameter
|
|
757
|
-
* @returns The parameter value or undefined if not found
|
|
758
|
-
*/
|
|
759
|
-
function readStringParam(args, key, options = {}) {
|
|
760
|
-
const value = args[key];
|
|
761
|
-
if (value === void 0 || value === null) {
|
|
762
|
-
if (options.required) throw new Error(`Missing required parameter: ${key}`);
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
if (typeof value === "string") return options.trim !== false ? value.trim() : value;
|
|
766
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
767
|
-
const str = String(value);
|
|
768
|
-
return options.trim !== false ? str.trim() : str;
|
|
769
|
-
}
|
|
770
|
-
throw new Error(`Parameter ${key} must be a string, number, or boolean`);
|
|
771
|
-
}
|
|
772
|
-
/** Supported Twitch actions */
|
|
773
|
-
const TWITCH_ACTIONS = /* @__PURE__ */ new Set(["send"]);
|
|
774
|
-
/**
|
|
775
|
-
* Twitch message actions adapter.
|
|
776
|
-
*/
|
|
777
|
-
const twitchMessageActions = {
|
|
778
|
-
/**
|
|
779
|
-
* List available actions for this channel.
|
|
780
|
-
*/
|
|
781
|
-
describeMessageTool: () => ({ actions: [...TWITCH_ACTIONS] }),
|
|
782
|
-
/**
|
|
783
|
-
* Check if an action is supported.
|
|
784
|
-
*/
|
|
785
|
-
supportsAction: ({ action }) => TWITCH_ACTIONS.has(action),
|
|
786
|
-
/**
|
|
787
|
-
* Extract tool send parameters from action arguments.
|
|
788
|
-
*
|
|
789
|
-
* Parses and validates the "to" and "message" parameters for sending.
|
|
790
|
-
*
|
|
791
|
-
* @param params - Arguments from the tool call
|
|
792
|
-
* @returns Parsed send parameters or null if invalid
|
|
793
|
-
*
|
|
794
|
-
* @example
|
|
795
|
-
* const result = twitchMessageActions.extractToolSend!({
|
|
796
|
-
* args: { to: "#mychannel", message: "Hello!" }
|
|
797
|
-
* });
|
|
798
|
-
* // Returns: { to: "#mychannel", message: "Hello!" }
|
|
799
|
-
*/
|
|
800
|
-
extractToolSend: ({ args }) => {
|
|
801
|
-
try {
|
|
802
|
-
const to = readStringParam(args, "to", { required: true });
|
|
803
|
-
const message = readStringParam(args, "message", { required: true });
|
|
804
|
-
if (!to || !message) return null;
|
|
805
|
-
return {
|
|
806
|
-
to,
|
|
807
|
-
message
|
|
808
|
-
};
|
|
809
|
-
} catch {
|
|
810
|
-
return null;
|
|
811
|
-
}
|
|
812
|
-
},
|
|
813
|
-
/**
|
|
814
|
-
* Handle an action execution.
|
|
815
|
-
*
|
|
816
|
-
* Processes the "send" action to send messages to Twitch.
|
|
817
|
-
*
|
|
818
|
-
* @param ctx - Action context including action type, parameters, and config
|
|
819
|
-
* @returns Tool result with content or null if action not supported
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* const result = await twitchMessageActions.handleAction!({
|
|
823
|
-
* action: "send",
|
|
824
|
-
* params: { message: "Hello Twitch!", to: "#mychannel" },
|
|
825
|
-
* cfg: openclawConfig,
|
|
826
|
-
* accountId: "default",
|
|
827
|
-
* });
|
|
828
|
-
*/
|
|
829
|
-
handleAction: async (ctx) => {
|
|
830
|
-
if (ctx.action !== "send") return {
|
|
831
|
-
content: [{
|
|
832
|
-
type: "text",
|
|
833
|
-
text: "Unsupported action"
|
|
834
|
-
}],
|
|
835
|
-
details: {
|
|
836
|
-
ok: false,
|
|
837
|
-
error: "Unsupported action"
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
const message = readStringParam(ctx.params, "message", { required: true });
|
|
841
|
-
const to = readStringParam(ctx.params, "to", { required: false });
|
|
842
|
-
const accountId = ctx.accountId ?? resolveTwitchAccountContext(ctx.cfg).accountId;
|
|
843
|
-
const { account, availableAccountIds } = resolveTwitchAccountContext(ctx.cfg, accountId);
|
|
844
|
-
if (!account) return errorResponse(`Account not found: ${accountId}. Available accounts: ${availableAccountIds.join(", ") || "none"}`);
|
|
845
|
-
const targetChannel = to || account.channel;
|
|
846
|
-
if (!targetChannel) return errorResponse("No channel specified and no default channel in account config");
|
|
847
|
-
if (!twitchOutbound.sendText) return errorResponse("sendText not implemented");
|
|
848
|
-
try {
|
|
849
|
-
const result = await twitchOutbound.sendText({
|
|
850
|
-
cfg: ctx.cfg,
|
|
851
|
-
to: targetChannel,
|
|
852
|
-
text: message ?? "",
|
|
853
|
-
accountId
|
|
854
|
-
});
|
|
855
|
-
return {
|
|
856
|
-
content: [{
|
|
857
|
-
type: "text",
|
|
858
|
-
text: JSON.stringify(result)
|
|
859
|
-
}],
|
|
860
|
-
details: { ok: true }
|
|
861
|
-
};
|
|
862
|
-
} catch (error) {
|
|
863
|
-
return errorResponse(formatErrorMessage(error));
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
//#endregion
|
|
868
|
-
//#region extensions/twitch/src/config-schema.ts
|
|
869
|
-
/**
|
|
870
|
-
* Twitch user roles that can be allowed to interact with the bot
|
|
871
|
-
*/
|
|
872
|
-
const TwitchRoleSchema = z.enum([
|
|
873
|
-
"moderator",
|
|
874
|
-
"owner",
|
|
875
|
-
"vip",
|
|
876
|
-
"subscriber",
|
|
877
|
-
"all"
|
|
878
|
-
]);
|
|
879
|
-
const TwitchAccountShape = {
|
|
880
|
-
/** Twitch username */
|
|
881
|
-
username: z.string(),
|
|
882
|
-
/** Twitch OAuth access token (requires chat:read and chat:write scopes) */
|
|
883
|
-
accessToken: z.string(),
|
|
884
|
-
/** Twitch client ID (from Twitch Developer Portal or twitchtokengenerator.com) */
|
|
885
|
-
clientId: z.string().optional(),
|
|
886
|
-
/** Channel name to join */
|
|
887
|
-
channel: z.string().min(1),
|
|
888
|
-
/** Enable this account */
|
|
889
|
-
enabled: z.boolean().optional(),
|
|
890
|
-
/** Allow channel-initiated configuration writes */
|
|
891
|
-
configWrites: z.boolean().optional(),
|
|
892
|
-
/** Allowlist of Twitch user IDs who can interact with the bot (use IDs for safety, not usernames) */
|
|
893
|
-
allowFrom: z.array(z.string()).optional(),
|
|
894
|
-
/** Roles allowed to interact with the bot (e.g., ["moderator", "vip", "subscriber"]) */
|
|
895
|
-
allowedRoles: z.array(TwitchRoleSchema).optional(),
|
|
896
|
-
/** Require @mention to trigger bot responses */
|
|
897
|
-
requireMention: z.boolean().optional(),
|
|
898
|
-
/** Outbound response prefix override for this channel/account. */
|
|
899
|
-
responsePrefix: z.string().optional(),
|
|
900
|
-
/** Twitch client secret (required for token refresh via RefreshingAuthProvider) */
|
|
901
|
-
clientSecret: z.string().optional(),
|
|
902
|
-
/** Refresh token (required for automatic token refresh) */
|
|
903
|
-
refreshToken: z.string().optional(),
|
|
904
|
-
/** Token expiry time in seconds (optional, for token refresh tracking) */
|
|
905
|
-
expiresIn: z.number().nullable().optional(),
|
|
906
|
-
/** Timestamp when token was obtained (optional, for token refresh tracking) */
|
|
907
|
-
obtainmentTimestamp: z.number().optional()
|
|
908
|
-
};
|
|
909
|
-
/**
|
|
910
|
-
* Twitch account configuration schema
|
|
911
|
-
*/
|
|
912
|
-
const TwitchAccountSchema = z.object(TwitchAccountShape);
|
|
913
|
-
/**
|
|
914
|
-
* Base configuration properties shared by both single and multi-account modes
|
|
915
|
-
*/
|
|
916
|
-
const TwitchConfigBaseShape = {
|
|
917
|
-
name: z.string().optional(),
|
|
918
|
-
enabled: z.boolean().optional(),
|
|
919
|
-
configWrites: z.boolean().optional(),
|
|
920
|
-
markdown: MarkdownConfigSchema.optional(),
|
|
921
|
-
defaultAccount: z.string().optional()
|
|
922
|
-
};
|
|
923
|
-
/**
|
|
924
|
-
* Simplified single-account configuration schema
|
|
925
|
-
*
|
|
926
|
-
* Use this for single-account setups. Properties are at the top level,
|
|
927
|
-
* creating an implicit "default" account.
|
|
928
|
-
*/
|
|
929
|
-
const SimplifiedSchema = z.object({
|
|
930
|
-
...TwitchConfigBaseShape,
|
|
931
|
-
...TwitchAccountShape
|
|
932
|
-
});
|
|
933
|
-
/**
|
|
934
|
-
* Multi-account configuration schema
|
|
935
|
-
*
|
|
936
|
-
* Use this for multi-account setups. Each key is an account ID (e.g., "default", "secondary").
|
|
937
|
-
*/
|
|
938
|
-
const MultiAccountSchema = z.object({
|
|
939
|
-
...TwitchConfigBaseShape,
|
|
940
|
-
/** Per-account configuration (for multi-account setups) */
|
|
941
|
-
accounts: z.record(z.string(), TwitchAccountSchema)
|
|
942
|
-
}).refine((val) => Object.keys(val.accounts || {}).length > 0, { message: "accounts must contain at least one entry" });
|
|
943
|
-
/**
|
|
944
|
-
* Twitch plugin configuration schema
|
|
945
|
-
*
|
|
946
|
-
* Supports two mutually exclusive patterns:
|
|
947
|
-
* 1. Simplified single-account: username, accessToken, clientId, channel at top level
|
|
948
|
-
* 2. Multi-account: accounts object with named account configs
|
|
949
|
-
*
|
|
950
|
-
* The union ensures clear discrimination between the two modes.
|
|
951
|
-
*/
|
|
952
|
-
const TwitchConfigSchema = z.union([SimplifiedSchema, MultiAccountSchema]);
|
|
953
|
-
//#endregion
|
|
954
792
|
//#region extensions/twitch/src/probe.ts
|
|
955
793
|
/**
|
|
956
794
|
* Probe a Twitch account to verify the connection is working
|
|
@@ -968,7 +806,8 @@ async function probeTwitch(account, timeoutMs) {
|
|
|
968
806
|
username: account.username
|
|
969
807
|
};
|
|
970
808
|
const rawToken = normalizeToken(account.accessToken.trim());
|
|
971
|
-
|
|
809
|
+
const authProvider = new StaticAuthProvider(account.clientId ?? "", rawToken);
|
|
810
|
+
client = new ChatClient({ authProvider });
|
|
972
811
|
const connectionPromise = new Promise((resolve, reject) => {
|
|
973
812
|
let settled = false;
|
|
974
813
|
const cleanup = () => {
|
|
@@ -1272,7 +1111,7 @@ function collectTwitchStatusIssues(accounts, getCfg) {
|
|
|
1272
1111
|
fix: "Start the Twitch gateway to begin receiving messages. Check logs for connection errors."
|
|
1273
1112
|
});
|
|
1274
1113
|
if (entry.running && entry.lastStartAt) {
|
|
1275
|
-
const daysSinceStart = (Date.now() - entry.lastStartAt) /
|
|
1114
|
+
const daysSinceStart = (Date.now() - entry.lastStartAt) / 864e5;
|
|
1276
1115
|
if (daysSinceStart > 7) issues.push({
|
|
1277
1116
|
channel: "twitch",
|
|
1278
1117
|
accountId,
|
|
@@ -1297,7 +1136,8 @@ function normalizeTwitchMessagingTarget(target) {
|
|
|
1297
1136
|
const kindMatch = /^(user|dm|channel|group|conversation|room):/i.exec(providerTarget);
|
|
1298
1137
|
const kind = kindMatch?.[1]?.toLowerCase();
|
|
1299
1138
|
if (kind === "user" || kind === "dm") return "";
|
|
1300
|
-
|
|
1139
|
+
const channelTarget = kindMatch ? providerTarget.slice(kindMatch[0].length) : providerTarget;
|
|
1140
|
+
return normalizeTwitchChannel(channelTarget);
|
|
1301
1141
|
}
|
|
1302
1142
|
/**
|
|
1303
1143
|
* Twitch channel plugin.
|
|
@@ -1312,6 +1152,10 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1312
1152
|
normalizeAllowEntry: createPairingPrefixStripper(/^(twitch:)?user:?/i),
|
|
1313
1153
|
notifyApproval: createLoggedPairingApprovalNotifier(({ id }) => `Pairing approved for user ${id} (notification sent via chat if possible)`, console.warn)
|
|
1314
1154
|
},
|
|
1155
|
+
threading: { matchesToolContextTarget: ({ target, toolContext }) => {
|
|
1156
|
+
const channel = normalizeTwitchMessagingTarget(target);
|
|
1157
|
+
return Boolean(channel) && [toolContext.currentChannelId, toolContext.currentMessagingTarget].some((current) => current != null && normalizeTwitchMessagingTarget(current) === channel);
|
|
1158
|
+
} },
|
|
1315
1159
|
outbound: twitchOutbound,
|
|
1316
1160
|
base: {
|
|
1317
1161
|
id: "twitch",
|
|
@@ -1327,6 +1171,11 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1327
1171
|
setupWizard: twitchSetupWizard,
|
|
1328
1172
|
capabilities: { chatTypes: ["group"] },
|
|
1329
1173
|
messaging: {
|
|
1174
|
+
normalizeTarget: normalizeTwitchMessagingTarget,
|
|
1175
|
+
targetResolver: {
|
|
1176
|
+
looksLikeId: (input) => Boolean(normalizeTwitchMessagingTarget(input)),
|
|
1177
|
+
hint: "<channel-name>"
|
|
1178
|
+
},
|
|
1330
1179
|
inferTargetChatType: ({ to }) => normalizeTwitchMessagingTarget(to) ? "group" : void 0,
|
|
1331
1180
|
resolveOutboundSessionRoute: ({ cfg, agentId, accountId, target }) => {
|
|
1332
1181
|
const channel = normalizeTwitchMessagingTarget(target);
|
|
@@ -1394,6 +1243,8 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1394
1243
|
startAccount: async (ctx) => {
|
|
1395
1244
|
const account = ctx.account;
|
|
1396
1245
|
const accountId = ctx.accountId;
|
|
1246
|
+
const channelRuntime = ctx.channelRuntime;
|
|
1247
|
+
if (!channelRuntime?.inbound?.buildContext) throw new Error("Twitch requires its registered channel runtime context builder");
|
|
1397
1248
|
const statusSink = createAccountStatusSink({
|
|
1398
1249
|
accountId,
|
|
1399
1250
|
setStatus: ctx.setStatus
|
|
@@ -1409,10 +1260,11 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1409
1260
|
await runPassiveAccountLifecycle({
|
|
1410
1261
|
abortSignal: ctx.abortSignal,
|
|
1411
1262
|
start: async () => {
|
|
1412
|
-
const { monitorTwitchProvider } = await import("./monitor-
|
|
1263
|
+
const { monitorTwitchProvider } = await import("./monitor-DwOuh3Ah.js");
|
|
1413
1264
|
return monitorTwitchProvider({
|
|
1414
1265
|
account,
|
|
1415
1266
|
accountId,
|
|
1267
|
+
channelRuntime,
|
|
1416
1268
|
config: ctx.cfg,
|
|
1417
1269
|
runtime: ctx.runtime,
|
|
1418
1270
|
abortSignal: ctx.abortSignal,
|
package/dist/setup-plugin-api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as twitchSetupPlugin } from "./setup-surface-
|
|
1
|
+
import { n as twitchSetupPlugin } from "./setup-surface-CPpsDfR8.js";
|
|
2
2
|
export { twitchSetupPlugin };
|
|
@@ -218,6 +218,7 @@ const twitchConfigAdapter = {
|
|
|
218
218
|
listAccountIds,
|
|
219
219
|
resolveAccount: resolveTwitchAccount,
|
|
220
220
|
defaultAccountId: resolveDefaultTwitchAccountId,
|
|
221
|
+
resolveDefaultTo: ({ cfg, accountId }) => resolveTwitchAccountContext(cfg, accountId).account?.channel,
|
|
221
222
|
isConfigured: (account, cfg) => resolveTwitchAccountContext(cfg, account.accountId).configured,
|
|
222
223
|
isEnabled: (account) => account?.enabled !== false
|
|
223
224
|
};
|
|
@@ -424,11 +425,12 @@ const twitchDmPolicy = createChannelDmPolicy({
|
|
|
424
425
|
const resolvedAccountId = resolveSetupAccountId(cfg, accountId);
|
|
425
426
|
const account = getAccountConfig(cfg, resolvedAccountId);
|
|
426
427
|
const existingAllowFrom = account?.allowFrom ?? [];
|
|
427
|
-
const
|
|
428
|
+
const entry = await prompter.text({
|
|
428
429
|
message: t("wizard.twitch.allowFromPrompt"),
|
|
429
430
|
placeholder: "123456789",
|
|
430
431
|
initialValue: existingAllowFrom[0] || void 0
|
|
431
|
-
})
|
|
432
|
+
});
|
|
433
|
+
const allowFrom = normalizeStringEntries((entry ?? "").split(/[\n,;]+/g));
|
|
432
434
|
return setTwitchAccount(cfg, {
|
|
433
435
|
...account ?? void 0,
|
|
434
436
|
allowFrom
|
package/openclaw.plugin.json
CHANGED
|
@@ -49,6 +49,14 @@
|
|
|
49
49
|
"defaultAccount": {
|
|
50
50
|
"type": "string"
|
|
51
51
|
},
|
|
52
|
+
"historyLimit": {
|
|
53
|
+
"type": "integer",
|
|
54
|
+
"minimum": 0,
|
|
55
|
+
"maximum": 9007199254740991
|
|
56
|
+
},
|
|
57
|
+
"responsePrefix": {
|
|
58
|
+
"type": "string"
|
|
59
|
+
},
|
|
52
60
|
"username": {
|
|
53
61
|
"type": "string"
|
|
54
62
|
},
|
|
@@ -84,9 +92,6 @@
|
|
|
84
92
|
"requireMention": {
|
|
85
93
|
"type": "boolean"
|
|
86
94
|
},
|
|
87
|
-
"responsePrefix": {
|
|
88
|
-
"type": "string"
|
|
89
|
-
},
|
|
90
95
|
"clientSecret": {
|
|
91
96
|
"type": "string"
|
|
92
97
|
},
|
|
@@ -144,6 +149,14 @@
|
|
|
144
149
|
"defaultAccount": {
|
|
145
150
|
"type": "string"
|
|
146
151
|
},
|
|
152
|
+
"historyLimit": {
|
|
153
|
+
"type": "integer",
|
|
154
|
+
"minimum": 0,
|
|
155
|
+
"maximum": 9007199254740991
|
|
156
|
+
},
|
|
157
|
+
"responsePrefix": {
|
|
158
|
+
"type": "string"
|
|
159
|
+
},
|
|
147
160
|
"accounts": {
|
|
148
161
|
"type": "object",
|
|
149
162
|
"propertyNames": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/twitch",
|
|
3
|
-
"version": "2026.8.
|
|
3
|
+
"version": "2026.8.2",
|
|
4
4
|
"description": "OpenClaw Twitch channel plugin for chat and moderation workflows.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"minHostVersion": ">=2026.4.10"
|
|
31
31
|
},
|
|
32
32
|
"compat": {
|
|
33
|
-
"pluginApi": ">=2026.8.
|
|
33
|
+
"pluginApi": ">=2026.8.2"
|
|
34
34
|
},
|
|
35
35
|
"build": {
|
|
36
|
-
"openclawVersion": "2026.8.
|
|
36
|
+
"openclawVersion": "2026.8.2"
|
|
37
37
|
},
|
|
38
38
|
"channel": {
|
|
39
39
|
"id": "twitch",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"README.md"
|
|
72
72
|
],
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"openclaw": ">=2026.8.
|
|
74
|
+
"openclaw": ">=2026.8.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependenciesMeta": {
|
|
77
77
|
"openclaw": {
|