@openclaw/twitch 2026.8.1-beta.2 → 2026.8.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/api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{monitor-D6ovNCYU.js → monitor-CgM3FcBi.js} +26 -25
- package/dist/{plugin-pRKPTroN.js → plugin-DitCSgI5.js} +200 -348
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-1wrrTKpx.js → setup-surface-BkbaBYll.js} +1 -0
- 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-DitCSgI5.js";
|
|
2
2
|
export { twitchPlugin };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as stripMarkdownForTwitch, r as getOrCreateClientManager } from "./plugin-DitCSgI5.js";
|
|
2
|
+
import { m as normalizeTwitchChannel } from "./setup-surface-BkbaBYll.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-BkbaBYll.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,
|
|
@@ -261,18 +328,17 @@ var TwitchClientManager = class {
|
|
|
261
328
|
const key = this.getAccountKey(account);
|
|
262
329
|
const client = this.clients.get(key);
|
|
263
330
|
const pendingClient = this.pendingClients.get(key);
|
|
331
|
+
const pendingConnection = this.connectionPromises.delete(key);
|
|
264
332
|
if (pendingClient) {
|
|
265
333
|
pendingClient.quit();
|
|
266
334
|
this.pendingClients.delete(key);
|
|
267
|
-
this.connectionPromises.delete(key);
|
|
268
|
-
this.clearMessageHandler(key);
|
|
269
335
|
}
|
|
270
336
|
if (client) {
|
|
271
337
|
client.quit();
|
|
272
338
|
this.clients.delete(key);
|
|
273
|
-
this.clearMessageHandler(key);
|
|
274
339
|
this.logger.info(`Disconnected ${key}`);
|
|
275
340
|
}
|
|
341
|
+
if (pendingConnection || pendingClient || client) this.clearMessageHandler(key);
|
|
276
342
|
}
|
|
277
343
|
/**
|
|
278
344
|
* Disconnect all clients
|
|
@@ -377,14 +443,102 @@ function getClientManager(accountId) {
|
|
|
377
443
|
async function removeClientManager(accountId) {
|
|
378
444
|
const entry = registry.get(accountId);
|
|
379
445
|
if (!entry) return;
|
|
446
|
+
registry.delete(accountId);
|
|
380
447
|
try {
|
|
381
448
|
await entry.manager.disconnectAll();
|
|
382
449
|
} finally {
|
|
383
|
-
registry.delete(accountId);
|
|
384
450
|
entry.logger.info(`Unregistered client manager for account: ${accountId}`);
|
|
385
451
|
}
|
|
386
452
|
}
|
|
387
453
|
//#endregion
|
|
454
|
+
//#region extensions/twitch/src/config-schema.ts
|
|
455
|
+
/**
|
|
456
|
+
* Twitch user roles that can be allowed to interact with the bot
|
|
457
|
+
*/
|
|
458
|
+
const TwitchRoleSchema = z.enum([
|
|
459
|
+
"moderator",
|
|
460
|
+
"owner",
|
|
461
|
+
"vip",
|
|
462
|
+
"subscriber",
|
|
463
|
+
"all"
|
|
464
|
+
]);
|
|
465
|
+
const TwitchAccountShape = {
|
|
466
|
+
/** Twitch username */
|
|
467
|
+
username: z.string(),
|
|
468
|
+
/** Twitch OAuth access token (requires chat:read and chat:write scopes) */
|
|
469
|
+
accessToken: z.string(),
|
|
470
|
+
/** Twitch client ID (from Twitch Developer Portal or twitchtokengenerator.com) */
|
|
471
|
+
clientId: z.string().optional(),
|
|
472
|
+
/** Channel name to join */
|
|
473
|
+
channel: z.string().min(1),
|
|
474
|
+
/** Enable this account */
|
|
475
|
+
enabled: z.boolean().optional(),
|
|
476
|
+
/** Allow channel-initiated configuration writes */
|
|
477
|
+
configWrites: z.boolean().optional(),
|
|
478
|
+
/** Allowlist of Twitch user IDs who can interact with the bot (use IDs for safety, not usernames) */
|
|
479
|
+
allowFrom: z.array(z.string()).optional(),
|
|
480
|
+
/** Roles allowed to interact with the bot (e.g., ["moderator", "vip", "subscriber"]) */
|
|
481
|
+
allowedRoles: z.array(TwitchRoleSchema).optional(),
|
|
482
|
+
/** Require @mention to trigger bot responses */
|
|
483
|
+
requireMention: z.boolean().optional(),
|
|
484
|
+
/** Outbound response prefix override for this channel/account. */
|
|
485
|
+
responsePrefix: z.string().optional(),
|
|
486
|
+
/** Twitch client secret (required for token refresh via RefreshingAuthProvider) */
|
|
487
|
+
clientSecret: z.string().optional(),
|
|
488
|
+
/** Refresh token (required for automatic token refresh) */
|
|
489
|
+
refreshToken: z.string().optional(),
|
|
490
|
+
/** Token expiry time in seconds (optional, for token refresh tracking) */
|
|
491
|
+
expiresIn: z.number().nullable().optional(),
|
|
492
|
+
/** Timestamp when token was obtained (optional, for token refresh tracking) */
|
|
493
|
+
obtainmentTimestamp: z.number().optional()
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* Twitch account configuration schema
|
|
497
|
+
*/
|
|
498
|
+
const TwitchAccountSchema = z.object(TwitchAccountShape);
|
|
499
|
+
/**
|
|
500
|
+
* Base configuration properties shared by both single and multi-account modes
|
|
501
|
+
*/
|
|
502
|
+
const TwitchConfigBaseShape = {
|
|
503
|
+
name: z.string().optional(),
|
|
504
|
+
enabled: z.boolean().optional(),
|
|
505
|
+
configWrites: z.boolean().optional(),
|
|
506
|
+
markdown: MarkdownConfigSchema.optional(),
|
|
507
|
+
defaultAccount: z.string().optional(),
|
|
508
|
+
historyLimit: z.number().int().min(0).optional(),
|
|
509
|
+
responsePrefix: z.string().optional()
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Simplified single-account configuration schema
|
|
513
|
+
*
|
|
514
|
+
* Use this for single-account setups. Properties are at the top level,
|
|
515
|
+
* creating an implicit "default" account.
|
|
516
|
+
*/
|
|
517
|
+
const SimplifiedSchema = z.object({
|
|
518
|
+
...TwitchConfigBaseShape,
|
|
519
|
+
...TwitchAccountShape
|
|
520
|
+
});
|
|
521
|
+
/**
|
|
522
|
+
* Multi-account configuration schema
|
|
523
|
+
*
|
|
524
|
+
* Use this for multi-account setups. Each key is an account ID (e.g., "default", "secondary").
|
|
525
|
+
*/
|
|
526
|
+
const MultiAccountSchema = z.object({
|
|
527
|
+
...TwitchConfigBaseShape,
|
|
528
|
+
/** Per-account configuration (for multi-account setups) */
|
|
529
|
+
accounts: z.record(z.string(), TwitchAccountSchema)
|
|
530
|
+
}).refine((val) => Object.keys(val.accounts || {}).length > 0, { message: "accounts must contain at least one entry" });
|
|
531
|
+
/**
|
|
532
|
+
* Twitch plugin configuration schema
|
|
533
|
+
*
|
|
534
|
+
* Supports two mutually exclusive patterns:
|
|
535
|
+
* 1. Simplified single-account: username, accessToken, clientId, channel at top level
|
|
536
|
+
* 2. Multi-account: accounts object with named account configs
|
|
537
|
+
*
|
|
538
|
+
* The union ensures clear discrimination between the two modes.
|
|
539
|
+
*/
|
|
540
|
+
const TwitchConfigSchema = z.union([SimplifiedSchema, MultiAccountSchema]);
|
|
541
|
+
//#endregion
|
|
388
542
|
//#region extensions/twitch/src/utils/markdown.ts
|
|
389
543
|
/**
|
|
390
544
|
* Markdown utilities for Twitch chat
|
|
@@ -395,19 +549,6 @@ async function removeClientManager(accountId) {
|
|
|
395
549
|
function stripMarkdownForTwitch(markdown) {
|
|
396
550
|
return stripMarkdown(markdown, { linkStyle: "label-and-url" }).replace(/\r/g, "").replace(/[ \t]+\n/g, "\n").replace(/\n/g, " ").replace(/[ \t]{2,}/g, " ").trim();
|
|
397
551
|
}
|
|
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
552
|
//#endregion
|
|
412
553
|
//#region extensions/twitch/src/send.ts
|
|
413
554
|
/**
|
|
@@ -416,14 +557,12 @@ function chunkTextForTwitch(text, limit) {
|
|
|
416
557
|
* These functions are the primary interface for sending messages to Twitch.
|
|
417
558
|
* They support dependency injection via the `deps` parameter for testability.
|
|
418
559
|
*/
|
|
419
|
-
function createTwitchSendReceipt(
|
|
420
|
-
const messageId = params.messageId.trim();
|
|
421
|
-
const conversationId = params.channel?.trim();
|
|
560
|
+
function createTwitchSendReceipt(messageId, channel) {
|
|
422
561
|
return createMessageReceiptFromOutboundResults({
|
|
423
|
-
results:
|
|
562
|
+
results: messageId ? [{
|
|
424
563
|
channel: "twitch",
|
|
425
564
|
messageId,
|
|
426
|
-
|
|
565
|
+
conversationId: channel
|
|
427
566
|
}] : [],
|
|
428
567
|
kind: "text"
|
|
429
568
|
});
|
|
@@ -457,80 +596,50 @@ async function sendMessageTwitchInternal(channel, text, cfg, accountId, stripMar
|
|
|
457
596
|
if (!account) return {
|
|
458
597
|
ok: false,
|
|
459
598
|
messageId: generateMessageId(),
|
|
460
|
-
receipt: createTwitchSendReceipt(
|
|
461
|
-
messageId: "",
|
|
462
|
-
channel,
|
|
463
|
-
visible: false
|
|
464
|
-
}),
|
|
599
|
+
receipt: createTwitchSendReceipt(),
|
|
465
600
|
error: `Account not found: ${accountId ?? "(default)"}. Available accounts: ${availableAccountIds.join(", ") || "none"}`
|
|
466
601
|
};
|
|
467
602
|
if (!configured) return {
|
|
468
603
|
ok: false,
|
|
469
604
|
messageId: generateMessageId(),
|
|
470
|
-
receipt: createTwitchSendReceipt(
|
|
471
|
-
messageId: "",
|
|
472
|
-
channel,
|
|
473
|
-
visible: false
|
|
474
|
-
}),
|
|
605
|
+
receipt: createTwitchSendReceipt(),
|
|
475
606
|
error: `Account ${resolvedAccountId} is not properly configured. Required: username, clientId, and token (config or env for default account).`
|
|
476
607
|
};
|
|
477
608
|
const normalizedChannel = channel || account.channel;
|
|
478
609
|
if (!normalizedChannel) return {
|
|
479
610
|
ok: false,
|
|
480
611
|
messageId: generateMessageId(),
|
|
481
|
-
receipt: createTwitchSendReceipt(
|
|
482
|
-
messageId: "",
|
|
483
|
-
channel: normalizedChannel,
|
|
484
|
-
visible: false
|
|
485
|
-
}),
|
|
612
|
+
receipt: createTwitchSendReceipt(),
|
|
486
613
|
error: "No channel specified and no default channel in account config"
|
|
487
614
|
};
|
|
488
615
|
const deliveryChannel = normalizeTwitchChannel(normalizedChannel);
|
|
489
616
|
const cleanedText = stripMarkdown ? stripMarkdownForTwitch(text) : text;
|
|
490
617
|
if (!cleanedText) return {
|
|
491
618
|
ok: true,
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
channel: deliveryChannel,
|
|
496
|
-
visible: false
|
|
497
|
-
})
|
|
619
|
+
outcome: "not_sent",
|
|
620
|
+
messageId: "",
|
|
621
|
+
receipt: createTwitchSendReceipt()
|
|
498
622
|
};
|
|
499
623
|
const clientManager = getClientManager(resolvedAccountId);
|
|
500
624
|
if (!clientManager) return {
|
|
501
625
|
ok: false,
|
|
502
626
|
messageId: generateMessageId(),
|
|
503
|
-
receipt: createTwitchSendReceipt(
|
|
504
|
-
messageId: "",
|
|
505
|
-
channel: deliveryChannel,
|
|
506
|
-
visible: false
|
|
507
|
-
}),
|
|
627
|
+
receipt: createTwitchSendReceipt(),
|
|
508
628
|
error: `Client manager not found for account: ${resolvedAccountId}. Please start the Twitch gateway first.`
|
|
509
629
|
};
|
|
510
630
|
try {
|
|
511
631
|
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
|
-
}
|
|
632
|
+
if (!result.ok) return {
|
|
633
|
+
ok: false,
|
|
634
|
+
messageId: result.messageId ?? generateMessageId(),
|
|
635
|
+
receipt: createTwitchSendReceipt(),
|
|
636
|
+
error: result.error ?? "Send failed"
|
|
637
|
+
};
|
|
525
638
|
const messageId = result.messageId ?? generateMessageId();
|
|
526
639
|
return {
|
|
527
640
|
ok: true,
|
|
528
641
|
messageId,
|
|
529
|
-
receipt: createTwitchSendReceipt(
|
|
530
|
-
messageId,
|
|
531
|
-
channel: deliveryChannel,
|
|
532
|
-
visible: true
|
|
533
|
-
})
|
|
642
|
+
receipt: createTwitchSendReceipt(messageId, deliveryChannel)
|
|
534
643
|
};
|
|
535
644
|
} catch (error) {
|
|
536
645
|
const errorMsg = formatErrorMessage(error);
|
|
@@ -539,11 +648,7 @@ async function sendMessageTwitchInternal(channel, text, cfg, accountId, stripMar
|
|
|
539
648
|
return {
|
|
540
649
|
ok: false,
|
|
541
650
|
messageId,
|
|
542
|
-
receipt: createTwitchSendReceipt(
|
|
543
|
-
messageId,
|
|
544
|
-
channel: deliveryChannel,
|
|
545
|
-
visible: false
|
|
546
|
-
}),
|
|
651
|
+
receipt: createTwitchSendReceipt(),
|
|
547
652
|
error: errorMsg
|
|
548
653
|
};
|
|
549
654
|
}
|
|
@@ -570,12 +675,9 @@ const twitchOutbound = {
|
|
|
570
675
|
media: true,
|
|
571
676
|
messageSendingHooks: true
|
|
572
677
|
} },
|
|
573
|
-
/** Twitch chat message limit is 500 characters */
|
|
574
678
|
textChunkLimit: 500,
|
|
575
679
|
/** Strip internal assistant tool-trace scaffolding before delivery */
|
|
576
680
|
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
|
|
577
|
-
/** Word-boundary chunker with markdown stripping */
|
|
578
|
-
chunker: chunkTextForTwitch,
|
|
579
681
|
/**
|
|
580
682
|
* Resolve target from context.
|
|
581
683
|
*
|
|
@@ -649,6 +751,7 @@ const twitchOutbound = {
|
|
|
649
751
|
if (!result.ok) throw new Error(result.error ?? "Send failed");
|
|
650
752
|
return {
|
|
651
753
|
channel: "twitch",
|
|
754
|
+
...result.outcome ? { outcome: result.outcome } : {},
|
|
652
755
|
messageId: result.messageId,
|
|
653
756
|
receipt: result.receipt,
|
|
654
757
|
timestamp: Date.now()
|
|
@@ -683,273 +786,10 @@ const twitchOutbound = {
|
|
|
683
786
|
});
|
|
684
787
|
}
|
|
685
788
|
};
|
|
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({
|
|
789
|
+
const twitchMessageAdapter = createChannelMessageAdapterFromOutbound({
|
|
700
790
|
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
|
-
}
|
|
728
|
-
});
|
|
729
|
-
//#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
|
|
791
|
+
outbound: twitchOutbound
|
|
932
792
|
});
|
|
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
793
|
//#endregion
|
|
954
794
|
//#region extensions/twitch/src/probe.ts
|
|
955
795
|
/**
|
|
@@ -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-CgM3FcBi.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-BkbaBYll.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
|
};
|
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.1
|
|
3
|
+
"version": "2026.8.1",
|
|
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.1
|
|
33
|
+
"pluginApi": ">=2026.8.1"
|
|
34
34
|
},
|
|
35
35
|
"build": {
|
|
36
|
-
"openclawVersion": "2026.8.1
|
|
36
|
+
"openclawVersion": "2026.8.1"
|
|
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.1
|
|
74
|
+
"openclaw": ">=2026.8.1"
|
|
75
75
|
},
|
|
76
76
|
"peerDependenciesMeta": {
|
|
77
77
|
"openclaw": {
|