@openclaw/twitch 2026.9.5 → 2026.9.7
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/assets/icon.png +0 -0
- package/dist/.setup/{monitor-Dd6CJA6V.mjs → monitor-CnvhK43s.mjs} +4 -15
- package/dist/.setup/{plugin-BJMHt2z3.mjs → plugin-BbtWQOSW.mjs} +47 -369
- package/dist/.setup/{setup-plugin-api-CWMOjn6G.mjs → setup-plugin-api-B1c86Vpi.mjs} +1 -1
- package/dist/.setup/{setup-surface-D_5uHrDU.mjs → setup-surface-KNOOeRU6.mjs} +58 -118
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/package.json +8 -8
package/assets/icon.png
CHANGED
|
Binary file
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-
|
|
2
|
-
import {
|
|
1
|
+
import { n as sendMessageTwitchInternal, r as getOrCreateClientManager } from "./plugin-BbtWQOSW.mjs";
|
|
2
|
+
import { l as normalizeTwitchChannel } from "./setup-surface-KNOOeRU6.mjs";
|
|
3
3
|
import { t as getTwitchRuntime } from "./runtime-B5If4b0g.mjs";
|
|
4
4
|
import { createChannelIngressError, createChannelIngressMonitor } from "openclaw/plugin-sdk/channel-outbound";
|
|
5
5
|
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
@@ -7,7 +7,7 @@ import { normalizeLowercaseStringOrEmpty, normalizeNullableString } from "opencl
|
|
|
7
7
|
import { HttpStatusCodeError } from "@twurple/api-call";
|
|
8
8
|
import { createChannelInboundEnvelopeBuilder } from "openclaw/plugin-sdk/channel-inbound";
|
|
9
9
|
import { resolveOutboundMediaUrls } from "openclaw/plugin-sdk/reply-payload";
|
|
10
|
-
import {
|
|
10
|
+
import { defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
|
|
11
11
|
//#region extensions/twitch/src/access-control.ts
|
|
12
12
|
const twitchUserIdentity = defineStableChannelIngressIdentity({
|
|
13
13
|
key: "sender-id",
|
|
@@ -32,7 +32,7 @@ const twitchRoleIdentity = defineStableChannelIngressIdentity({
|
|
|
32
32
|
async function checkTwitchAccessControl(params) {
|
|
33
33
|
const { message, account, botUsername } = params;
|
|
34
34
|
const policyKind = resolveTwitchPolicyKind(account);
|
|
35
|
-
const resolved = await
|
|
35
|
+
const resolved = await getTwitchRuntime().channel.inbound.ingress.createResolver({
|
|
36
36
|
channelId: "twitch",
|
|
37
37
|
accountId: params.accountId,
|
|
38
38
|
identity: policyKind === "role" ? twitchRoleIdentity : twitchUserIdentity
|
|
@@ -282,9 +282,6 @@ function createTwitchIngress(options) {
|
|
|
282
282
|
}
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region extensions/twitch/src/monitor.ts
|
|
285
|
-
/**
|
|
286
|
-
* Process an incoming Twitch message and dispatch to agent.
|
|
287
|
-
*/
|
|
288
285
|
async function processTwitchMessage(params) {
|
|
289
286
|
const { message, account, accountId, config, runtime, channelRuntime, turnAdoptionLifecycle, statusSink } = params;
|
|
290
287
|
const cfg = config;
|
|
@@ -405,9 +402,6 @@ async function processTwitchMessage(params) {
|
|
|
405
402
|
}
|
|
406
403
|
});
|
|
407
404
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Deliver a reply to Twitch chat.
|
|
410
|
-
*/
|
|
411
405
|
async function deliverTwitchReply(params) {
|
|
412
406
|
const { payload, channel, account, accountId, config, runtime } = params;
|
|
413
407
|
try {
|
|
@@ -434,11 +428,6 @@ async function deliverTwitchReply(params) {
|
|
|
434
428
|
return { visibleReplySent: false };
|
|
435
429
|
}
|
|
436
430
|
}
|
|
437
|
-
/**
|
|
438
|
-
* Main monitor provider for Twitch.
|
|
439
|
-
*
|
|
440
|
-
* Sets up message handlers and processes incoming messages.
|
|
441
|
-
*/
|
|
442
431
|
async function monitorTwitchProvider(options) {
|
|
443
432
|
const { account, accountId, channelRuntime, config, runtime, abortSignal, statusSink } = options;
|
|
444
433
|
const core = getTwitchRuntime();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as resolveTwitchAccountContext, c as
|
|
1
|
+
import { a as resolveTwitchAccountContext, c as normalizeToken, i as resolveDefaultTwitchAccountId, l as normalizeTwitchChannel, n as DEFAULT_ACCOUNT_ID$1, o as twitchConfigAdapter, r as getAccountConfig, s as isAccountConfigured, t as twitchSetupPlugin, u as resolveTwitchToken } from "./setup-surface-KNOOeRU6.mjs";
|
|
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";
|
|
@@ -17,64 +17,20 @@ import { normalizeLowercaseStringOrEmpty, normalizeStringEntries } from "opencla
|
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { HttpStatusCodeError, callTwitchApi } from "@twurple/api-call";
|
|
19
19
|
//#region extensions/twitch/src/actions.ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @param args - Action arguments
|
|
24
|
-
* @param key - Parameter key
|
|
25
|
-
* @param options - Options for reading the parameter
|
|
26
|
-
* @returns The parameter value or undefined if not found
|
|
27
|
-
*/
|
|
28
|
-
function readStringParam(args, key, options = {}) {
|
|
29
|
-
const value = args[key];
|
|
30
|
-
if (value === void 0 || value === null) {
|
|
31
|
-
if (options.required) throw new Error(`Missing required parameter: ${key}`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (typeof value === "string") return options.trim !== false ? value.trim() : value;
|
|
35
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
36
|
-
const str = String(value);
|
|
37
|
-
return options.trim !== false ? str.trim() : str;
|
|
38
|
-
}
|
|
39
|
-
throw new Error(`Parameter ${key} must be a string, number, or boolean`);
|
|
20
|
+
function readSendValue(value) {
|
|
21
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : void 0;
|
|
40
22
|
}
|
|
41
|
-
/** Supported Twitch actions */
|
|
42
|
-
const TWITCH_ACTIONS = /* @__PURE__ */ new Set(["send"]);
|
|
43
|
-
/**
|
|
44
|
-
* Twitch message actions adapter.
|
|
45
|
-
*/
|
|
46
23
|
const twitchMessageActions = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*/
|
|
50
|
-
describeMessageTool: () => ({ actions: [...TWITCH_ACTIONS] }),
|
|
51
|
-
/**
|
|
52
|
-
* Check if an action is supported.
|
|
53
|
-
*/
|
|
54
|
-
supportsAction: ({ action }) => TWITCH_ACTIONS.has(action),
|
|
55
|
-
/**
|
|
56
|
-
* Extract tool send parameters from action arguments.
|
|
57
|
-
*
|
|
58
|
-
* Parses and validates the "to" and "message" parameters for sending.
|
|
59
|
-
*
|
|
60
|
-
* @param params - Arguments from the tool call
|
|
61
|
-
* @returns Parsed send parameters or null if invalid
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* const result = twitchMessageActions.extractToolSend!({
|
|
65
|
-
* args: { to: "#mychannel", message: "Hello!" }
|
|
66
|
-
* });
|
|
67
|
-
* // Returns: { to: "#mychannel", message: "Hello!" }
|
|
68
|
-
*/
|
|
24
|
+
describeMessageTool: () => ({ actions: ["send"] }),
|
|
25
|
+
supportsAction: ({ action }) => action === "send",
|
|
69
26
|
extractToolSend: ({ args }) => {
|
|
70
27
|
try {
|
|
71
|
-
const to =
|
|
72
|
-
const message =
|
|
73
|
-
|
|
74
|
-
return {
|
|
28
|
+
const to = readSendValue(args.to);
|
|
29
|
+
const message = readSendValue(args.message);
|
|
30
|
+
return to && message ? {
|
|
75
31
|
to,
|
|
76
32
|
message
|
|
77
|
-
};
|
|
33
|
+
} : null;
|
|
78
34
|
} catch {
|
|
79
35
|
return null;
|
|
80
36
|
}
|
|
@@ -83,9 +39,6 @@ const twitchMessageActions = {
|
|
|
83
39
|
//#endregion
|
|
84
40
|
//#region extensions/twitch/src/twitch-client.ts
|
|
85
41
|
const TWITCH_CHAT_AUTH_INTENTS = ["chat"];
|
|
86
|
-
/**
|
|
87
|
-
* Manages Twitch chat client connections
|
|
88
|
-
*/
|
|
89
42
|
var TwitchClientManager = class {
|
|
90
43
|
constructor(logger, statusSink) {
|
|
91
44
|
this.logger = logger;
|
|
@@ -94,7 +47,6 @@ var TwitchClientManager = class {
|
|
|
94
47
|
this.pendingClients = /* @__PURE__ */ new Map();
|
|
95
48
|
this.connectionPromises = /* @__PURE__ */ new Map();
|
|
96
49
|
this.messageHandlers = /* @__PURE__ */ new Map();
|
|
97
|
-
this.messageHandlerTokens = /* @__PURE__ */ new Map();
|
|
98
50
|
}
|
|
99
51
|
setStatusSink(statusSink) {
|
|
100
52
|
if (statusSink) this.statusSink = statusSink;
|
|
@@ -109,9 +61,6 @@ var TwitchClientManager = class {
|
|
|
109
61
|
lastError
|
|
110
62
|
});
|
|
111
63
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Create an auth provider for the account.
|
|
114
|
-
*/
|
|
115
64
|
async createAuthProvider(account, normalizedToken) {
|
|
116
65
|
if (!account.clientId) throw new Error("Missing Twitch client ID");
|
|
117
66
|
if (account.clientSecret) {
|
|
@@ -143,9 +92,6 @@ var TwitchClientManager = class {
|
|
|
143
92
|
this.logger.info(`Using StaticAuthProvider for ${account.username} (no clientSecret provided)`);
|
|
144
93
|
return new StaticAuthProvider(account.clientId, normalizedToken);
|
|
145
94
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Get or create a chat client for an account
|
|
148
|
-
*/
|
|
149
95
|
async getClient(account, cfg, accountId) {
|
|
150
96
|
const key = this.getAccountKey(account);
|
|
151
97
|
const existing = this.clients.get(key);
|
|
@@ -185,8 +131,6 @@ var TwitchClientManager = class {
|
|
|
185
131
|
custom: { log: (level, message) => {
|
|
186
132
|
switch (level) {
|
|
187
133
|
case LogLevel.CRITICAL:
|
|
188
|
-
this.logger.error(message);
|
|
189
|
-
break;
|
|
190
134
|
case LogLevel.ERROR:
|
|
191
135
|
this.logger.error(message);
|
|
192
136
|
break;
|
|
@@ -197,8 +141,6 @@ var TwitchClientManager = class {
|
|
|
197
141
|
this.logger.info(message);
|
|
198
142
|
break;
|
|
199
143
|
case LogLevel.DEBUG:
|
|
200
|
-
this.logger.debug?.(message);
|
|
201
|
-
break;
|
|
202
144
|
case LogLevel.TRACE: this.logger.debug?.(message);
|
|
203
145
|
}
|
|
204
146
|
} }
|
|
@@ -211,10 +153,8 @@ var TwitchClientManager = class {
|
|
|
211
153
|
client.quit();
|
|
212
154
|
throw new Error(`Twitch connection cancelled for ${account.username}`);
|
|
213
155
|
}
|
|
214
|
-
|
|
215
|
-
} catch (error) {
|
|
156
|
+
} finally {
|
|
216
157
|
if (this.pendingClients.get(key) === client) this.pendingClients.delete(key);
|
|
217
|
-
throw error;
|
|
218
158
|
}
|
|
219
159
|
this.setupClientHandlers(client, account);
|
|
220
160
|
this.clients.set(key, client);
|
|
@@ -265,13 +205,10 @@ var TwitchClientManager = class {
|
|
|
265
205
|
}
|
|
266
206
|
});
|
|
267
207
|
}
|
|
268
|
-
/**
|
|
269
|
-
* Set up message and event handlers for a client
|
|
270
|
-
*/
|
|
271
208
|
setupClientHandlers(client, account) {
|
|
272
209
|
const key = this.getAccountKey(account);
|
|
273
210
|
client.onMessage((channelName, _user, messageText, msg) => {
|
|
274
|
-
const handler = this.messageHandlers.get(key);
|
|
211
|
+
const handler = this.messageHandlers.get(key)?.handler;
|
|
275
212
|
if (handler) {
|
|
276
213
|
const from = `twitch:${msg.userInfo.userName}`;
|
|
277
214
|
const preview = sliceUtf16Safe(messageText, 0, 100).replace(/\n/g, "\\n");
|
|
@@ -301,29 +238,14 @@ var TwitchClientManager = class {
|
|
|
301
238
|
});
|
|
302
239
|
this.logger.info(`Set up handlers for ${key}`);
|
|
303
240
|
}
|
|
304
|
-
/**
|
|
305
|
-
* Set a message handler for an account
|
|
306
|
-
* @returns A function that removes the handler when called
|
|
307
|
-
*/
|
|
308
241
|
onMessage(account, handler) {
|
|
309
242
|
const key = this.getAccountKey(account);
|
|
310
|
-
const
|
|
311
|
-
this.messageHandlers.set(key,
|
|
312
|
-
this.messageHandlerTokens.set(key, token);
|
|
243
|
+
const registration = { handler };
|
|
244
|
+
this.messageHandlers.set(key, registration);
|
|
313
245
|
return () => {
|
|
314
|
-
if (this.
|
|
315
|
-
this.messageHandlers.delete(key);
|
|
316
|
-
this.messageHandlerTokens.delete(key);
|
|
317
|
-
}
|
|
246
|
+
if (this.messageHandlers.get(key) === registration) this.messageHandlers.delete(key);
|
|
318
247
|
};
|
|
319
248
|
}
|
|
320
|
-
clearMessageHandler(key) {
|
|
321
|
-
this.messageHandlers.delete(key);
|
|
322
|
-
this.messageHandlerTokens.delete(key);
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Disconnect a client
|
|
326
|
-
*/
|
|
327
249
|
async disconnect(account) {
|
|
328
250
|
const key = this.getAccountKey(account);
|
|
329
251
|
const client = this.clients.get(key);
|
|
@@ -338,11 +260,8 @@ var TwitchClientManager = class {
|
|
|
338
260
|
this.clients.delete(key);
|
|
339
261
|
this.logger.info(`Disconnected ${key}`);
|
|
340
262
|
}
|
|
341
|
-
if (pendingConnection || pendingClient || client) this.
|
|
263
|
+
if (pendingConnection || pendingClient || client) this.messageHandlers.delete(key);
|
|
342
264
|
}
|
|
343
|
-
/**
|
|
344
|
-
* Disconnect all clients
|
|
345
|
-
*/
|
|
346
265
|
async disconnectAll() {
|
|
347
266
|
this.pendingClients.forEach((client) => client.quit());
|
|
348
267
|
this.clients.forEach((client) => client.quit());
|
|
@@ -350,12 +269,8 @@ var TwitchClientManager = class {
|
|
|
350
269
|
this.connectionPromises.clear();
|
|
351
270
|
this.clients.clear();
|
|
352
271
|
this.messageHandlers.clear();
|
|
353
|
-
this.messageHandlerTokens.clear();
|
|
354
272
|
this.logger.info(" Disconnected all clients");
|
|
355
273
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Send a message to a channel
|
|
358
|
-
*/
|
|
359
274
|
async sendMessage(account, channel, message, cfg, accountId) {
|
|
360
275
|
try {
|
|
361
276
|
const client = await this.getClient(account, cfg, accountId);
|
|
@@ -374,33 +289,13 @@ var TwitchClientManager = class {
|
|
|
374
289
|
};
|
|
375
290
|
}
|
|
376
291
|
}
|
|
377
|
-
/**
|
|
378
|
-
* Generate a unique key for an account
|
|
379
|
-
*/
|
|
380
292
|
getAccountKey(account) {
|
|
381
293
|
return `${account.username}:${account.channel}`;
|
|
382
294
|
}
|
|
383
295
|
};
|
|
384
296
|
//#endregion
|
|
385
297
|
//#region extensions/twitch/src/client-manager-registry.ts
|
|
386
|
-
/**
|
|
387
|
-
* Client manager registry for Twitch plugin.
|
|
388
|
-
*
|
|
389
|
-
* Manages the lifecycle of TwitchClientManager instances across the plugin,
|
|
390
|
-
* ensuring proper cleanup when accounts are stopped or reconfigured.
|
|
391
|
-
*/
|
|
392
|
-
/**
|
|
393
|
-
* Global registry of client managers.
|
|
394
|
-
* Keyed by account ID.
|
|
395
|
-
*/
|
|
396
298
|
const registry = /* @__PURE__ */ new Map();
|
|
397
|
-
/**
|
|
398
|
-
* Get or create a client manager for an account.
|
|
399
|
-
*
|
|
400
|
-
* @param accountId - The account ID
|
|
401
|
-
* @param logger - Logger instance
|
|
402
|
-
* @returns The client manager
|
|
403
|
-
*/
|
|
404
299
|
function getOrCreateClientManager(accountId, logger, statusSink) {
|
|
405
300
|
const existing = registry.get(accountId);
|
|
406
301
|
if (existing) {
|
|
@@ -410,28 +305,14 @@ function getOrCreateClientManager(accountId, logger, statusSink) {
|
|
|
410
305
|
const manager = new TwitchClientManager(logger, statusSink);
|
|
411
306
|
registry.set(accountId, {
|
|
412
307
|
manager,
|
|
413
|
-
|
|
414
|
-
logger,
|
|
415
|
-
createdAt: Date.now()
|
|
308
|
+
logger
|
|
416
309
|
});
|
|
417
310
|
logger.info(`Registered client manager for account: ${accountId}`);
|
|
418
311
|
return manager;
|
|
419
312
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Get an existing client manager for an account.
|
|
422
|
-
*
|
|
423
|
-
* @param accountId - The account ID
|
|
424
|
-
* @returns The client manager, or undefined if not registered
|
|
425
|
-
*/
|
|
426
313
|
function getClientManager(accountId) {
|
|
427
314
|
return registry.get(accountId)?.manager;
|
|
428
315
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Disconnect and remove a client manager from the registry.
|
|
431
|
-
*
|
|
432
|
-
* @param accountId - The account ID
|
|
433
|
-
* @returns Promise that resolves when cleanup is complete
|
|
434
|
-
*/
|
|
435
316
|
async function removeClientManager(accountId) {
|
|
436
317
|
const entry = registry.get(accountId);
|
|
437
318
|
if (!entry) return;
|
|
@@ -444,9 +325,6 @@ async function removeClientManager(accountId) {
|
|
|
444
325
|
}
|
|
445
326
|
//#endregion
|
|
446
327
|
//#region extensions/twitch/src/config-schema.ts
|
|
447
|
-
/**
|
|
448
|
-
* Twitch user roles that can be allowed to interact with the bot
|
|
449
|
-
*/
|
|
450
328
|
const TwitchRoleSchema = z.enum([
|
|
451
329
|
"moderator",
|
|
452
330
|
"owner",
|
|
@@ -455,25 +333,20 @@ const TwitchRoleSchema = z.enum([
|
|
|
455
333
|
"all"
|
|
456
334
|
]);
|
|
457
335
|
const TwitchAccountShape = {
|
|
458
|
-
/** Twitch username */
|
|
459
336
|
username: z.string(),
|
|
460
337
|
/** Twitch OAuth access token (requires chat:read and chat:write scopes) */
|
|
461
338
|
accessToken: z.string(),
|
|
462
339
|
/** Twitch client ID (from Twitch Developer Portal or twitchtokengenerator.com) */
|
|
463
340
|
clientId: z.string().optional(),
|
|
464
|
-
/** Channel name to join */
|
|
465
341
|
channel: z.string().min(1),
|
|
466
|
-
/** Enable this account */
|
|
467
342
|
enabled: z.boolean().optional(),
|
|
468
343
|
/** Allow channel-initiated configuration writes */
|
|
469
344
|
configWrites: z.boolean().optional(),
|
|
470
345
|
/** Allowlist of Twitch user IDs who can interact with the bot (use IDs for safety, not usernames) */
|
|
471
346
|
allowFrom: z.array(z.string()).optional(),
|
|
472
|
-
/** Roles allowed to interact with the bot (e.g., ["moderator", "vip", "subscriber"]) */
|
|
473
347
|
allowedRoles: z.array(TwitchRoleSchema).optional(),
|
|
474
348
|
/** Require @mention to trigger bot responses */
|
|
475
349
|
requireMention: z.boolean().optional(),
|
|
476
|
-
/** Outbound response prefix override for this channel/account. */
|
|
477
350
|
responsePrefix: z.string().optional(),
|
|
478
351
|
/** Twitch client secret (required for token refresh via RefreshingAuthProvider) */
|
|
479
352
|
clientSecret: z.string().optional(),
|
|
@@ -484,13 +357,7 @@ const TwitchAccountShape = {
|
|
|
484
357
|
/** Timestamp when token was obtained (optional, for token refresh tracking) */
|
|
485
358
|
obtainmentTimestamp: z.number().optional()
|
|
486
359
|
};
|
|
487
|
-
/**
|
|
488
|
-
* Twitch account configuration schema
|
|
489
|
-
*/
|
|
490
360
|
const TwitchAccountSchema = z.object(TwitchAccountShape);
|
|
491
|
-
/**
|
|
492
|
-
* Base configuration properties shared by both single and multi-account modes
|
|
493
|
-
*/
|
|
494
361
|
const TwitchConfigBaseShape = {
|
|
495
362
|
name: z.string().optional(),
|
|
496
363
|
enabled: z.boolean().optional(),
|
|
@@ -500,35 +367,14 @@ const TwitchConfigBaseShape = {
|
|
|
500
367
|
historyLimit: z.number().int().min(0).optional(),
|
|
501
368
|
responsePrefix: z.string().optional()
|
|
502
369
|
};
|
|
503
|
-
/**
|
|
504
|
-
* Simplified single-account configuration schema
|
|
505
|
-
*
|
|
506
|
-
* Use this for single-account setups. Properties are at the top level,
|
|
507
|
-
* creating an implicit "default" account.
|
|
508
|
-
*/
|
|
509
370
|
const SimplifiedSchema = z.object({
|
|
510
371
|
...TwitchConfigBaseShape,
|
|
511
372
|
...TwitchAccountShape
|
|
512
373
|
});
|
|
513
|
-
/**
|
|
514
|
-
* Multi-account configuration schema
|
|
515
|
-
*
|
|
516
|
-
* Use this for multi-account setups. Each key is an account ID (e.g., "default", "secondary").
|
|
517
|
-
*/
|
|
518
374
|
const MultiAccountSchema = z.object({
|
|
519
375
|
...TwitchConfigBaseShape,
|
|
520
|
-
/** Per-account configuration (for multi-account setups) */
|
|
521
376
|
accounts: z.record(z.string(), TwitchAccountSchema)
|
|
522
|
-
}).refine((val) => Object.keys(val.accounts
|
|
523
|
-
/**
|
|
524
|
-
* Twitch plugin configuration schema
|
|
525
|
-
*
|
|
526
|
-
* Supports two mutually exclusive patterns:
|
|
527
|
-
* 1. Simplified single-account: username, accessToken, clientId, channel at top level
|
|
528
|
-
* 2. Multi-account: accounts object with named account configs
|
|
529
|
-
*
|
|
530
|
-
* The union ensures clear discrimination between the two modes.
|
|
531
|
-
*/
|
|
377
|
+
}).refine((val) => Object.keys(val.accounts).length > 0, { message: "accounts must contain at least one entry" });
|
|
532
378
|
const TwitchConfigSchema = z.union([SimplifiedSchema, MultiAccountSchema]);
|
|
533
379
|
//#endregion
|
|
534
380
|
//#region extensions/twitch/src/utils/markdown.ts
|
|
@@ -571,20 +417,7 @@ async function sendMessageTwitchInternal(params) {
|
|
|
571
417
|
}
|
|
572
418
|
//#endregion
|
|
573
419
|
//#region extensions/twitch/src/outbound.ts
|
|
574
|
-
/**
|
|
575
|
-
* Twitch outbound adapter for sending messages.
|
|
576
|
-
*
|
|
577
|
-
* Implements the ChannelOutboundAdapter interface for Twitch chat.
|
|
578
|
-
* Supports text and media (URL) sending with markdown stripping and chunking.
|
|
579
|
-
*/
|
|
580
|
-
/**
|
|
581
|
-
* Twitch outbound adapter.
|
|
582
|
-
*
|
|
583
|
-
* Handles sending text and media to Twitch channels with automatic
|
|
584
|
-
* markdown stripping and message chunking.
|
|
585
|
-
*/
|
|
586
420
|
const twitchOutbound = {
|
|
587
|
-
/** Direct delivery mode - messages are sent immediately */
|
|
588
421
|
deliveryMode: "direct",
|
|
589
422
|
deliveryCapabilities: { durableFinal: {
|
|
590
423
|
text: true,
|
|
@@ -592,75 +425,27 @@ const twitchOutbound = {
|
|
|
592
425
|
messageSendingHooks: true
|
|
593
426
|
} },
|
|
594
427
|
textChunkLimit: 500,
|
|
595
|
-
/** Strip internal assistant tool-trace scaffolding before delivery */
|
|
596
428
|
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
|
|
597
|
-
/**
|
|
598
|
-
* Resolve target from context.
|
|
599
|
-
*
|
|
600
|
-
* Handles target resolution with allowlist support for implicit/heartbeat modes.
|
|
601
|
-
* For explicit mode, accepts any valid channel name.
|
|
602
|
-
*
|
|
603
|
-
* @param params - Resolution parameters
|
|
604
|
-
* @returns Resolved target or error
|
|
605
|
-
*/
|
|
606
429
|
resolveTarget: ({ to, allowFrom, mode }) => {
|
|
607
430
|
const trimmed = to?.trim() ?? "";
|
|
608
431
|
const allowListRaw = normalizeStringEntries(allowFrom ?? []);
|
|
609
432
|
const hasWildcard = allowListRaw.includes("*");
|
|
610
433
|
const allowList = allowListRaw.filter((entry) => entry !== "*").map((entry) => normalizeTwitchChannel(entry)).filter((entry) => entry.length > 0);
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
};
|
|
617
|
-
if (mode === "implicit" || mode === "heartbeat") {
|
|
618
|
-
if (hasWildcard || allowList.length === 0) return {
|
|
619
|
-
ok: true,
|
|
620
|
-
to: normalizedTo
|
|
621
|
-
};
|
|
622
|
-
if (allowList.includes(normalizedTo)) return {
|
|
623
|
-
ok: true,
|
|
624
|
-
to: normalizedTo
|
|
625
|
-
};
|
|
626
|
-
return {
|
|
627
|
-
ok: false,
|
|
628
|
-
error: missingTargetError("Twitch", "<channel-name>")
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
return {
|
|
632
|
-
ok: true,
|
|
633
|
-
to: normalizedTo
|
|
634
|
-
};
|
|
635
|
-
}
|
|
434
|
+
const normalizedTo = normalizeTwitchChannel(trimmed);
|
|
435
|
+
if (normalizedTo && (!(mode === "implicit" || mode === "heartbeat") || hasWildcard || allowList.length === 0 || allowList.includes(normalizedTo))) return {
|
|
436
|
+
ok: true,
|
|
437
|
+
to: normalizedTo
|
|
438
|
+
};
|
|
636
439
|
return {
|
|
637
440
|
ok: false,
|
|
638
|
-
error:
|
|
441
|
+
error: /* @__PURE__ */ new Error("Delivering to Twitch requires target <channel-name>")
|
|
639
442
|
};
|
|
640
443
|
},
|
|
641
|
-
/**
|
|
642
|
-
* Send a text message to a Twitch channel.
|
|
643
|
-
*
|
|
644
|
-
* Strips Markdown, validates account configuration,
|
|
645
|
-
* and sends the message via the Twitch client.
|
|
646
|
-
*
|
|
647
|
-
* @param params - Send parameters including target, text, and config
|
|
648
|
-
* @returns Delivery result with message ID and status
|
|
649
|
-
*
|
|
650
|
-
* @example
|
|
651
|
-
* const result = await twitchOutbound.sendText({
|
|
652
|
-
* cfg: openclawConfig,
|
|
653
|
-
* to: "#mychannel",
|
|
654
|
-
* text: "Hello Twitch!",
|
|
655
|
-
* accountId: "default",
|
|
656
|
-
* });
|
|
657
|
-
*/
|
|
658
444
|
sendText: async (params) => {
|
|
659
445
|
const { cfg, to, text, accountId } = params;
|
|
660
446
|
if (params.signal?.aborted) throw new Error("Outbound delivery aborted");
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
if (!account) throw new Error(`Twitch account not found: ${resolvedAccountId}. Available accounts: ${availableAccountIds.join(", ") || "none"}`);
|
|
447
|
+
const { account, accountId: normalizedAccountId, availableAccountIds, configured } = resolveTwitchAccountContext(cfg, accountId);
|
|
448
|
+
if (!account) throw new Error(`Twitch account not found: ${accountId ?? normalizedAccountId}. Available accounts: ${availableAccountIds.join(", ") || "none"}`);
|
|
664
449
|
const channel = to || account.channel;
|
|
665
450
|
if (!channel) throw new Error("No channel specified and no default channel in account config");
|
|
666
451
|
if (!configured) throw new Error(`Account ${normalizedAccountId} is not properly configured. Required: username, clientId, and accessToken (config or env for default account).`);
|
|
@@ -682,29 +467,10 @@ const twitchOutbound = {
|
|
|
682
467
|
timestamp: Date.now()
|
|
683
468
|
};
|
|
684
469
|
},
|
|
685
|
-
/**
|
|
686
|
-
* Send media to a Twitch channel.
|
|
687
|
-
*
|
|
688
|
-
* Note: Twitch chat doesn't support direct media uploads.
|
|
689
|
-
* This sends the media URL as text instead.
|
|
690
|
-
*
|
|
691
|
-
* @param params - Send parameters including media URL
|
|
692
|
-
* @returns Delivery result with message ID and status
|
|
693
|
-
*
|
|
694
|
-
* @example
|
|
695
|
-
* const result = await twitchOutbound.sendMedia({
|
|
696
|
-
* cfg: openclawConfig,
|
|
697
|
-
* to: "#mychannel",
|
|
698
|
-
* text: "Check this out!",
|
|
699
|
-
* mediaUrl: "https://example.com/image.png",
|
|
700
|
-
* accountId: "default",
|
|
701
|
-
* });
|
|
702
|
-
*/
|
|
703
470
|
sendMedia: async (params) => {
|
|
704
471
|
const { text, mediaUrl } = params;
|
|
705
472
|
if (params.signal?.aborted) throw new Error("Outbound delivery aborted");
|
|
706
473
|
const message = mediaUrl ? `${text || ""} ${mediaUrl}`.trim() : text;
|
|
707
|
-
if (!twitchOutbound.sendText) throw new Error("sendText not implemented");
|
|
708
474
|
return twitchOutbound.sendText({
|
|
709
475
|
...params,
|
|
710
476
|
text: message
|
|
@@ -789,32 +555,12 @@ async function probeTwitch(account, timeoutMs) {
|
|
|
789
555
|
}
|
|
790
556
|
//#endregion
|
|
791
557
|
//#region extensions/twitch/src/resolver.ts
|
|
792
|
-
/**
|
|
793
|
-
* Twitch resolver adapter for channel/user name resolution.
|
|
794
|
-
*
|
|
795
|
-
* This module implements the ChannelResolverAdapter interface to resolve
|
|
796
|
-
* Twitch usernames to user IDs via the Twitch Helix API.
|
|
797
|
-
*/
|
|
798
558
|
const TWITCH_HELIX_USER_LOOKUP_TIMEOUT_MS = 1e4;
|
|
799
|
-
/**
|
|
800
|
-
* Normalize a Twitch username - strip @ prefix and convert to lowercase
|
|
801
|
-
*/
|
|
802
559
|
function normalizeUsername(input) {
|
|
803
560
|
const trimmed = input.trim();
|
|
804
561
|
if (trimmed.startsWith("@")) return normalizeLowercaseStringOrEmpty(trimmed.slice(1));
|
|
805
562
|
return normalizeLowercaseStringOrEmpty(trimmed);
|
|
806
563
|
}
|
|
807
|
-
/**
|
|
808
|
-
* Create a logger that includes the Twitch prefix
|
|
809
|
-
*/
|
|
810
|
-
function createLogger(logger) {
|
|
811
|
-
return {
|
|
812
|
-
info: (msg) => logger?.info(msg),
|
|
813
|
-
warn: (msg) => logger?.warn(msg),
|
|
814
|
-
error: (msg) => logger?.error(msg),
|
|
815
|
-
debug: (msg) => logger?.debug?.(msg) ?? (() => {})
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
564
|
function createHelixUserResolver(clientId, accessToken) {
|
|
819
565
|
let tokenValidated = false;
|
|
820
566
|
return async (query) => {
|
|
@@ -848,19 +594,9 @@ function createHelixUserResolver(clientId, accessToken) {
|
|
|
848
594
|
}
|
|
849
595
|
};
|
|
850
596
|
}
|
|
851
|
-
|
|
852
|
-
* Resolve Twitch usernames to user IDs via the Helix API
|
|
853
|
-
*
|
|
854
|
-
* @param inputs - Array of usernames or user IDs to resolve
|
|
855
|
-
* @param account - Twitch account configuration with auth credentials
|
|
856
|
-
* @param kind - Type of target to resolve ("user" or "group")
|
|
857
|
-
* @param logger - Optional logger
|
|
858
|
-
* @returns Promise resolving to array of ChannelResolveResult
|
|
859
|
-
*/
|
|
860
|
-
async function resolveTwitchTargets(inputs, account, _kind, logger) {
|
|
861
|
-
const log = createLogger(logger);
|
|
597
|
+
async function resolveTwitchTargets(inputs, account, _kind, log) {
|
|
862
598
|
if (!account.clientId || !account.accessToken) {
|
|
863
|
-
log
|
|
599
|
+
log?.error("Missing Twitch client ID or accessToken");
|
|
864
600
|
return inputs.map((input) => ({
|
|
865
601
|
input,
|
|
866
602
|
resolved: false,
|
|
@@ -882,43 +618,23 @@ async function resolveTwitchTargets(inputs, account, _kind, logger) {
|
|
|
882
618
|
}
|
|
883
619
|
const looksLikeUserId = /^\d+$/.test(normalized);
|
|
884
620
|
try {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
} else {
|
|
896
|
-
results.push({
|
|
897
|
-
input,
|
|
898
|
-
resolved: false,
|
|
899
|
-
note: "user ID not found"
|
|
900
|
-
});
|
|
901
|
-
log.warn(`User ID ${normalized} not found`);
|
|
902
|
-
}
|
|
621
|
+
const user = await resolveHelixUser(looksLikeUserId ? { id: normalized } : { login: normalized });
|
|
622
|
+
if (user) {
|
|
623
|
+
results.push({
|
|
624
|
+
input,
|
|
625
|
+
resolved: true,
|
|
626
|
+
id: user.id,
|
|
627
|
+
name: user.login,
|
|
628
|
+
...!looksLikeUserId ? { note: user.display_name !== user.login ? `display: ${user.display_name}` : void 0 } : {}
|
|
629
|
+
});
|
|
630
|
+
log?.debug?.(looksLikeUserId ? `Resolved user ID ${normalized} -> ${user.login}` : `Resolved username ${normalized} -> ${user.id} (${user.login})`);
|
|
903
631
|
} else {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
name: user.login,
|
|
911
|
-
note: user.display_name !== user.login ? `display: ${user.display_name}` : void 0
|
|
912
|
-
});
|
|
913
|
-
log.debug?.(`Resolved username ${normalized} -> ${user.id} (${user.login})`);
|
|
914
|
-
} else {
|
|
915
|
-
results.push({
|
|
916
|
-
input,
|
|
917
|
-
resolved: false,
|
|
918
|
-
note: "username not found"
|
|
919
|
-
});
|
|
920
|
-
log.warn(`Username ${normalized} not found`);
|
|
921
|
-
}
|
|
632
|
+
results.push({
|
|
633
|
+
input,
|
|
634
|
+
resolved: false,
|
|
635
|
+
note: looksLikeUserId ? "user ID not found" : "username not found"
|
|
636
|
+
});
|
|
637
|
+
log?.warn(`${looksLikeUserId ? "User ID" : "Username"} ${normalized} not found`);
|
|
922
638
|
}
|
|
923
639
|
} catch (error) {
|
|
924
640
|
const errorMessage = formatErrorMessage(error);
|
|
@@ -927,30 +643,13 @@ async function resolveTwitchTargets(inputs, account, _kind, logger) {
|
|
|
927
643
|
resolved: false,
|
|
928
644
|
note: `API error: ${errorMessage}`
|
|
929
645
|
});
|
|
930
|
-
log
|
|
646
|
+
log?.error(`Failed to resolve ${input}: ${errorMessage}`);
|
|
931
647
|
}
|
|
932
648
|
}
|
|
933
649
|
return results;
|
|
934
650
|
}
|
|
935
651
|
//#endregion
|
|
936
652
|
//#region extensions/twitch/src/status.ts
|
|
937
|
-
/**
|
|
938
|
-
* Collect status issues for Twitch accounts.
|
|
939
|
-
*
|
|
940
|
-
* Analyzes account snapshots and detects configuration problems,
|
|
941
|
-
* authentication issues, and other potential problems.
|
|
942
|
-
*
|
|
943
|
-
* @param accounts - Array of account snapshots to analyze
|
|
944
|
-
* @param getCfg - Optional function to get full config for additional checks
|
|
945
|
-
* @returns Array of detected status issues
|
|
946
|
-
*
|
|
947
|
-
* @example
|
|
948
|
-
* const issues = collectTwitchStatusIssues(accountSnapshots);
|
|
949
|
-
* if (issues.length > 0) {
|
|
950
|
-
* console.warn("Twitch configuration issues detected:");
|
|
951
|
-
* issues.forEach(issue => console.warn(`- ${issue.message}`));
|
|
952
|
-
* }
|
|
953
|
-
*/
|
|
954
653
|
function collectTwitchStatusIssues(accounts, getCfg) {
|
|
955
654
|
const issues = [];
|
|
956
655
|
for (const entry of accounts) {
|
|
@@ -1008,13 +707,6 @@ function collectTwitchStatusIssues(accounts, getCfg) {
|
|
|
1008
707
|
message: "clientSecret provided without refreshToken",
|
|
1009
708
|
fix: "For automatic token refresh, provide both clientSecret and refreshToken. Otherwise, clientSecret is not needed."
|
|
1010
709
|
});
|
|
1011
|
-
if (account.allowFrom && account.allowFrom.length === 0) issues.push({
|
|
1012
|
-
channel: "twitch",
|
|
1013
|
-
accountId,
|
|
1014
|
-
kind: "config",
|
|
1015
|
-
message: "allowFrom is configured but empty",
|
|
1016
|
-
fix: "Either add user IDs to allowFrom, remove the allowFrom field, or use allowedRoles instead."
|
|
1017
|
-
});
|
|
1018
710
|
if (account.allowedRoles?.includes("all") && account.allowFrom && account.allowFrom.length > 0) issues.push({
|
|
1019
711
|
channel: "twitch",
|
|
1020
712
|
accountId,
|
|
@@ -1052,12 +744,6 @@ function collectTwitchStatusIssues(accounts, getCfg) {
|
|
|
1052
744
|
}
|
|
1053
745
|
//#endregion
|
|
1054
746
|
//#region extensions/twitch/src/plugin.ts
|
|
1055
|
-
/**
|
|
1056
|
-
* Twitch channel plugin for OpenClaw.
|
|
1057
|
-
*
|
|
1058
|
-
* Main plugin export combining all adapters (outbound, actions, status, gateway).
|
|
1059
|
-
* This is the primary entry point for the Twitch channel integration.
|
|
1060
|
-
*/
|
|
1061
747
|
function normalizeTwitchMessagingTarget(target) {
|
|
1062
748
|
const providerTarget = stripChannelTargetPrefix(target, "twitch", "twitch-chat");
|
|
1063
749
|
const kindMatch = /^(user|dm|channel|group|conversation|room):/i.exec(providerTarget);
|
|
@@ -1066,13 +752,6 @@ function normalizeTwitchMessagingTarget(target) {
|
|
|
1066
752
|
const channelTarget = kindMatch ? providerTarget.slice(kindMatch[0].length) : providerTarget;
|
|
1067
753
|
return normalizeTwitchChannel(channelTarget);
|
|
1068
754
|
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Twitch channel plugin.
|
|
1071
|
-
*
|
|
1072
|
-
* Implements the ChannelPlugin interface to provide Twitch chat integration
|
|
1073
|
-
* for OpenClaw. Supports message sending, receiving, access control, and
|
|
1074
|
-
* status monitoring.
|
|
1075
|
-
*/
|
|
1076
755
|
const twitchPlugin = createChatChannelPlugin({
|
|
1077
756
|
pairing: {
|
|
1078
757
|
idLabel: "twitchUserId",
|
|
@@ -1158,10 +837,9 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1158
837
|
probeAccount: async ({ account, timeoutMs }) => await probeTwitch(account, timeoutMs),
|
|
1159
838
|
collectStatusIssues: collectTwitchStatusIssues,
|
|
1160
839
|
resolveAccountSnapshot: ({ account, cfg }) => {
|
|
1161
|
-
const
|
|
1162
|
-
const { configured } = resolveTwitchAccountContext(cfg, resolvedAccountId);
|
|
840
|
+
const { configured } = resolveTwitchAccountContext(cfg, account.accountId);
|
|
1163
841
|
return {
|
|
1164
|
-
accountId:
|
|
842
|
+
accountId: account.accountId,
|
|
1165
843
|
enabled: account.enabled !== false,
|
|
1166
844
|
configured
|
|
1167
845
|
};
|
|
@@ -1188,7 +866,7 @@ const twitchPlugin = createChatChannelPlugin({
|
|
|
1188
866
|
await runPassiveAccountLifecycle({
|
|
1189
867
|
abortSignal: ctx.abortSignal,
|
|
1190
868
|
start: async () => {
|
|
1191
|
-
const { monitorTwitchProvider } = await import("./monitor-
|
|
869
|
+
const { monitorTwitchProvider } = await import("./monitor-CnvhK43s.mjs");
|
|
1192
870
|
return monitorTwitchProvider({
|
|
1193
871
|
account,
|
|
1194
872
|
accountId,
|
|
@@ -7,39 +7,12 @@ import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
|
|
|
7
7
|
import { getChatChannelMeta } from "openclaw/plugin-sdk/core";
|
|
8
8
|
import { createSetupTranslator, formatDocsLink, normalizeAccountId as normalizeAccountId$1, patchTopLevelChannelConfigSection, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
|
|
9
9
|
//#region extensions/twitch/src/token.ts
|
|
10
|
-
/**
|
|
11
|
-
* Twitch access token resolution with environment variable support.
|
|
12
|
-
*
|
|
13
|
-
* Supports reading Twitch OAuth access tokens from config or environment variable.
|
|
14
|
-
* The OPENCLAW_TWITCH_ACCESS_TOKEN env var is only used for the default account.
|
|
15
|
-
*
|
|
16
|
-
* Token resolution priority:
|
|
17
|
-
* 1. Account access token from merged config (accounts.{id} or base-level for default)
|
|
18
|
-
* 2. Environment variable: OPENCLAW_TWITCH_ACCESS_TOKEN (default account only)
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Normalize a Twitch OAuth token - ensure it has the oauth: prefix
|
|
22
|
-
*/
|
|
23
10
|
function normalizeTwitchToken(raw) {
|
|
24
11
|
if (!raw) return;
|
|
25
12
|
const trimmed = raw.trim();
|
|
26
13
|
if (!trimmed) return;
|
|
27
14
|
return trimmed.startsWith("oauth:") ? trimmed : `oauth:${trimmed}`;
|
|
28
15
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Resolve Twitch access token from config or environment variable.
|
|
31
|
-
*
|
|
32
|
-
* Priority:
|
|
33
|
-
* 1. Account access token (from merged config - base-level for default, or accounts.{accountId})
|
|
34
|
-
* 2. Environment variable: OPENCLAW_TWITCH_ACCESS_TOKEN (default account only)
|
|
35
|
-
*
|
|
36
|
-
* The getAccountConfig function handles merging base-level config with accounts.default,
|
|
37
|
-
* so this logic works for both simplified and multi-account patterns.
|
|
38
|
-
*
|
|
39
|
-
* @param cfg - OpenClaw config
|
|
40
|
-
* @param opts - Options including accountId and optional envToken override
|
|
41
|
-
* @returns Token resolution with source
|
|
42
|
-
*/
|
|
43
16
|
function resolveTwitchToken(cfg, opts = {}) {
|
|
44
17
|
const accountId = normalizeAccountId(opts.accountId);
|
|
45
18
|
const twitchCfg = cfg?.channels?.twitch;
|
|
@@ -64,60 +37,16 @@ function resolveTwitchToken(cfg, opts = {}) {
|
|
|
64
37
|
}
|
|
65
38
|
//#endregion
|
|
66
39
|
//#region extensions/twitch/src/utils/twitch.ts
|
|
67
|
-
/**
|
|
68
|
-
* Twitch-specific utility functions
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Normalize Twitch channel names.
|
|
72
|
-
*
|
|
73
|
-
* Removes the '#' prefix if present, converts to lowercase, and trims whitespace.
|
|
74
|
-
* Twitch channel names are case-insensitive and don't use the '#' prefix in the API.
|
|
75
|
-
*
|
|
76
|
-
* @param channel - The channel name to normalize
|
|
77
|
-
* @returns Normalized channel name
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* normalizeTwitchChannel("#TwitchChannel") // "twitchchannel"
|
|
81
|
-
* normalizeTwitchChannel("MyChannel") // "mychannel"
|
|
82
|
-
*/
|
|
83
40
|
function normalizeTwitchChannel(channel) {
|
|
84
41
|
const trimmed = normalizeLowercaseStringOrEmpty(channel);
|
|
85
42
|
return trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
|
|
86
43
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Create a standardized error message for missing target.
|
|
89
|
-
*
|
|
90
|
-
* @param provider - The provider name (e.g., "Twitch")
|
|
91
|
-
* @param hint - Optional hint for how to fix the issue
|
|
92
|
-
* @returns Error object with descriptive message
|
|
93
|
-
*/
|
|
94
|
-
function missingTargetError(provider, hint) {
|
|
95
|
-
return /* @__PURE__ */ new Error(`Delivering to ${provider} requires target${hint ? ` ${hint}` : ""}`);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Normalize OAuth token by removing the "oauth:" prefix if present.
|
|
99
|
-
*
|
|
100
|
-
* Twurple doesn't require the "oauth:" prefix, so we strip it for consistency.
|
|
101
|
-
*
|
|
102
|
-
* @param token - The OAuth token to normalize
|
|
103
|
-
* @returns Normalized token without "oauth:" prefix
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* normalizeToken("oauth:abc123") // "abc123"
|
|
107
|
-
* normalizeToken("abc123") // "abc123"
|
|
108
|
-
*/
|
|
109
44
|
function normalizeToken(token) {
|
|
110
45
|
return token.startsWith("oauth:") ? token.slice(6) : token;
|
|
111
46
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Check if an account is properly configured with required credentials.
|
|
114
|
-
*
|
|
115
|
-
* @param account - The Twitch account config to check
|
|
116
|
-
* @returns true if the account has required credentials
|
|
117
|
-
*/
|
|
118
47
|
function isAccountConfigured(account, resolvedToken) {
|
|
119
|
-
const token = resolvedToken ?? account
|
|
120
|
-
return Boolean(account
|
|
48
|
+
const token = resolvedToken ?? account.accessToken;
|
|
49
|
+
return Boolean(account.username && token && account.clientId);
|
|
121
50
|
}
|
|
122
51
|
//#endregion
|
|
123
52
|
//#region extensions/twitch/src/config.ts
|
|
@@ -130,14 +59,8 @@ const { listAccountIds, resolveDefaultAccountId: resolveDefaultTwitchAccountId }
|
|
|
130
59
|
}
|
|
131
60
|
});
|
|
132
61
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* Handles two patterns:
|
|
136
|
-
* 1. Simplified single-account: base-level properties create implicit "default" account
|
|
137
|
-
* 2. Multi-account: explicit accounts object
|
|
138
|
-
*
|
|
139
|
-
* For "default" account, base-level properties take precedence over accounts.default
|
|
140
|
-
* For other accounts, only the accounts object is checked
|
|
62
|
+
* Root credentials take precedence for the implicit default account; named
|
|
63
|
+
* accounts only read their own account entry.
|
|
141
64
|
*/
|
|
142
65
|
function getAccountConfig(coreConfig, accountId) {
|
|
143
66
|
if (!coreConfig || typeof coreConfig !== "object") return null;
|
|
@@ -166,12 +89,9 @@ function getAccountConfig(coreConfig, accountId) {
|
|
|
166
89
|
...baseLevel
|
|
167
90
|
};
|
|
168
91
|
if (merged.username) return merged;
|
|
169
|
-
|
|
170
|
-
return null;
|
|
92
|
+
return accountFromAccounts || null;
|
|
171
93
|
}
|
|
172
|
-
|
|
173
|
-
if (!account) return null;
|
|
174
|
-
return account;
|
|
94
|
+
return resolveNormalizedAccountEntry(accounts, normalizedAccountId, normalizeAccountId) || null;
|
|
175
95
|
}
|
|
176
96
|
function resolveTwitchAccountContext(cfg, accountId) {
|
|
177
97
|
const resolvedAccountId = accountId?.trim() ? normalizeAccountId(accountId) : resolveDefaultTwitchAccountId(cfg);
|
|
@@ -210,18 +130,16 @@ const twitchConfigAdapter = {
|
|
|
210
130
|
isConfigured: (account, cfg) => resolveTwitchAccountContext(cfg, account.accountId).configured,
|
|
211
131
|
isEnabled: (account) => account?.enabled !== false
|
|
212
132
|
};
|
|
213
|
-
function resolveTwitchSnapshotAccountId(cfg, account) {
|
|
214
|
-
const accountMap = (cfg.channels?.twitch)?.accounts ?? {};
|
|
215
|
-
return Object.entries(accountMap).find(([, value]) => value === account)?.[0] ?? DEFAULT_ACCOUNT_ID$1;
|
|
216
|
-
}
|
|
217
133
|
//#endregion
|
|
218
134
|
//#region extensions/twitch/src/setup-surface.ts
|
|
219
|
-
/**
|
|
220
|
-
* Twitch setup wizard surface for CLI setup.
|
|
221
|
-
*/
|
|
222
135
|
const channel = "twitch";
|
|
223
136
|
const t = createSetupTranslator();
|
|
224
137
|
const INVALID_ACCOUNT_ID_MESSAGE = "Invalid Twitch account id";
|
|
138
|
+
const requiredAccountPrompts = {
|
|
139
|
+
username: "wizard.twitch.botUsernamePrompt",
|
|
140
|
+
clientId: "wizard.twitch.clientIdPrompt",
|
|
141
|
+
channel: "wizard.twitch.channelJoinPrompt"
|
|
142
|
+
};
|
|
225
143
|
function normalizeRequestedSetupAccountId(accountId) {
|
|
226
144
|
const normalized = normalizeOptionalAccountId(accountId);
|
|
227
145
|
if (!normalized) throw new Error(INVALID_ACCOUNT_ID_MESSAGE);
|
|
@@ -234,7 +152,7 @@ function resolveSetupAccountId(cfg, requestedAccountId) {
|
|
|
234
152
|
return preferred ? normalizeAccountId$1(preferred) : resolveDefaultTwitchAccountId(cfg);
|
|
235
153
|
}
|
|
236
154
|
function setTwitchAccount(cfg, account, accountId = resolveSetupAccountId(cfg)) {
|
|
237
|
-
const resolvedAccountId = accountId.trim()
|
|
155
|
+
const resolvedAccountId = resolveSetupAccountId(cfg, accountId.trim());
|
|
238
156
|
const existing = getAccountConfig(cfg, resolvedAccountId);
|
|
239
157
|
const merged = {
|
|
240
158
|
username: account.username ?? existing?.username ?? "",
|
|
@@ -289,22 +207,13 @@ async function promptToken(prompter, account) {
|
|
|
289
207
|
}
|
|
290
208
|
})).trim();
|
|
291
209
|
}
|
|
292
|
-
async function promptRequiredTwitchAccountValue(prompter,
|
|
210
|
+
async function promptRequiredTwitchAccountValue(prompter, account, key) {
|
|
293
211
|
return (await prompter.text({
|
|
294
|
-
message,
|
|
295
|
-
initialValue:
|
|
212
|
+
message: t(requiredAccountPrompts[key]),
|
|
213
|
+
initialValue: account?.[key] ?? "",
|
|
296
214
|
validate: (value) => value?.trim() ? void 0 : "Required"
|
|
297
215
|
})).trim();
|
|
298
216
|
}
|
|
299
|
-
async function promptUsername(prompter, account) {
|
|
300
|
-
return await promptRequiredTwitchAccountValue(prompter, t("wizard.twitch.botUsernamePrompt"), account?.username);
|
|
301
|
-
}
|
|
302
|
-
async function promptClientId(prompter, account) {
|
|
303
|
-
return await promptRequiredTwitchAccountValue(prompter, t("wizard.twitch.clientIdPrompt"), account?.clientId);
|
|
304
|
-
}
|
|
305
|
-
async function promptChannelName(prompter, account) {
|
|
306
|
-
return await promptRequiredTwitchAccountValue(prompter, t("wizard.twitch.channelJoinPrompt"), account?.channel);
|
|
307
|
-
}
|
|
308
217
|
async function promptRefreshCredential(params) {
|
|
309
218
|
const existingValue = params.existingValue?.trim();
|
|
310
219
|
if (existingValue) {
|
|
@@ -340,15 +249,15 @@ async function promptRefreshTokenSetup(prompter, account) {
|
|
|
340
249
|
};
|
|
341
250
|
}
|
|
342
251
|
async function configureWithEnvToken(cfg, prompter, account, envToken, forceAllowFrom, dmPolicy, accountId = resolveSetupAccountId(cfg)) {
|
|
343
|
-
const resolvedAccountId = accountId.trim()
|
|
252
|
+
const resolvedAccountId = resolveSetupAccountId(cfg, accountId.trim());
|
|
344
253
|
if (resolvedAccountId !== DEFAULT_ACCOUNT_ID$1) return null;
|
|
345
254
|
if (!await prompter.confirm({
|
|
346
255
|
message: t("wizard.twitch.envPrompt"),
|
|
347
256
|
initialValue: true
|
|
348
257
|
})) return null;
|
|
349
258
|
const cfgWithAccount = setTwitchAccount(cfg, {
|
|
350
|
-
username: await
|
|
351
|
-
clientId: await
|
|
259
|
+
username: await promptRequiredTwitchAccountValue(prompter, account, "username"),
|
|
260
|
+
clientId: await promptRequiredTwitchAccountValue(prompter, account, "clientId"),
|
|
352
261
|
accessToken: envToken,
|
|
353
262
|
enabled: true
|
|
354
263
|
}, resolvedAccountId);
|
|
@@ -371,12 +280,43 @@ function setTwitchAccessControl(cfg, allowedRoles, requireMention, accountId) {
|
|
|
371
280
|
}
|
|
372
281
|
function resolveTwitchGroupPolicy(cfg, accountId) {
|
|
373
282
|
const account = getAccountConfig(cfg, resolveSetupAccountId(cfg, accountId));
|
|
374
|
-
if (account
|
|
375
|
-
if (account
|
|
376
|
-
return "
|
|
283
|
+
if (!account) return "disabled";
|
|
284
|
+
if (account.allowFrom !== void 0) return account.allowFrom.length > 0 ? "allowlist" : "disabled";
|
|
285
|
+
if (account.allowedRoles?.length) return account.allowedRoles.includes("all") ? "open" : "allowlist";
|
|
286
|
+
return "open";
|
|
377
287
|
}
|
|
378
288
|
function setTwitchGroupPolicy(cfg, policy, accountId) {
|
|
379
|
-
|
|
289
|
+
const resolvedAccountId = resolveSetupAccountId(cfg, accountId);
|
|
290
|
+
const account = getAccountConfig(cfg, resolvedAccountId);
|
|
291
|
+
if (!account) return cfg;
|
|
292
|
+
const patch = {
|
|
293
|
+
allowedRoles: policy === "open" ? ["all"] : policy === "allowlist" ? ["moderator", "vip"] : [],
|
|
294
|
+
requireMention: true
|
|
295
|
+
};
|
|
296
|
+
if (policy === "disabled") patch.allowFrom = [];
|
|
297
|
+
else if (policy === "allowlist" && account.allowFrom?.length) patch.allowFrom = account.allowFrom;
|
|
298
|
+
const twitch = cfg.channels?.twitch;
|
|
299
|
+
if (resolvedAccountId === DEFAULT_ACCOUNT_ID$1 && typeof twitch?.username === "string" && twitch.username) return patchTopLevelChannelConfigSection({
|
|
300
|
+
cfg,
|
|
301
|
+
channel,
|
|
302
|
+
enabled: true,
|
|
303
|
+
clearFields: patch.allowFrom === void 0 ? ["allowFrom"] : void 0,
|
|
304
|
+
patch
|
|
305
|
+
});
|
|
306
|
+
const nextAccount = {
|
|
307
|
+
...account,
|
|
308
|
+
...patch
|
|
309
|
+
};
|
|
310
|
+
if (patch.allowFrom === void 0) delete nextAccount.allowFrom;
|
|
311
|
+
return patchTopLevelChannelConfigSection({
|
|
312
|
+
cfg,
|
|
313
|
+
channel,
|
|
314
|
+
enabled: true,
|
|
315
|
+
patch: { accounts: {
|
|
316
|
+
...twitch?.accounts,
|
|
317
|
+
[resolvedAccountId]: nextAccount
|
|
318
|
+
} }
|
|
319
|
+
});
|
|
380
320
|
}
|
|
381
321
|
const twitchDmPolicy = createChannelDmPolicy({
|
|
382
322
|
label: "Twitch",
|
|
@@ -430,7 +370,7 @@ const twitchGroupAccess = {
|
|
|
430
370
|
},
|
|
431
371
|
updatePrompt: ({ cfg, accountId }) => {
|
|
432
372
|
const account = getAccountConfig(cfg, resolveSetupAccountId(cfg, accountId));
|
|
433
|
-
return Boolean(account?.allowedRoles?.length || account?.allowFrom
|
|
373
|
+
return Boolean(account?.allowedRoles?.length || account?.allowFrom !== void 0);
|
|
434
374
|
},
|
|
435
375
|
setPolicy: ({ cfg, accountId, policy }) => setTwitchGroupPolicy(cfg, policy, accountId),
|
|
436
376
|
resolveAllowlist: async () => [],
|
|
@@ -472,10 +412,10 @@ const twitchSetupWizard = {
|
|
|
472
412
|
const envResult = await configureWithEnvToken(cfg, prompter, account, envToken, forceAllowFrom, twitchDmPolicy, accountId);
|
|
473
413
|
if (envResult) return envResult;
|
|
474
414
|
}
|
|
475
|
-
const username = await
|
|
415
|
+
const username = await promptRequiredTwitchAccountValue(prompter, account, "username");
|
|
476
416
|
const token = await promptToken(prompter, account);
|
|
477
|
-
const clientId = await
|
|
478
|
-
const channelName = await
|
|
417
|
+
const clientId = await promptRequiredTwitchAccountValue(prompter, account, "clientId");
|
|
418
|
+
const channelName = await promptRequiredTwitchAccountValue(prompter, account, "channel");
|
|
479
419
|
const { clientSecret, refreshToken } = await promptRefreshTokenSetup(prompter, account);
|
|
480
420
|
const cfgWithAccount = setTwitchAccount(cfg, {
|
|
481
421
|
username,
|
|
@@ -506,4 +446,4 @@ const twitchSetupPlugin = {
|
|
|
506
446
|
setupWizard: twitchSetupWizard
|
|
507
447
|
};
|
|
508
448
|
//#endregion
|
|
509
|
-
export { resolveTwitchAccountContext as a,
|
|
449
|
+
export { resolveTwitchAccountContext as a, normalizeToken as c, resolveDefaultTwitchAccountId as i, normalizeTwitchChannel as l, DEFAULT_ACCOUNT_ID$1 as n, twitchConfigAdapter as o, getAccountConfig as r, isAccountConfigured as s, twitchSetupPlugin as t, resolveTwitchToken as u };
|
package/dist/api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as twitchPlugin } from "./.setup/plugin-
|
|
1
|
+
import { t as twitchPlugin } from "./.setup/plugin-BbtWQOSW.mjs";
|
|
2
2
|
export { twitchPlugin };
|
package/dist/setup-entry.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
var setup_entry_default = defineBundledChannelSetupEntry({
|
|
5
5
|
importMetaUrl: import.meta.url,
|
|
6
6
|
plugin: {
|
|
7
|
-
specifier: fileURLToPath(new URL(".setup/setup-plugin-api-
|
|
7
|
+
specifier: fileURLToPath(new URL(".setup/setup-plugin-api-B1c86Vpi.mjs", import.meta.url).href),
|
|
8
8
|
exportName: "twitchSetupPlugin"
|
|
9
9
|
}
|
|
10
10
|
});
|
package/dist/setup-plugin-api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as twitchSetupPlugin } from "./.setup/setup-surface-
|
|
1
|
+
import { t as twitchSetupPlugin } from "./.setup/setup-surface-KNOOeRU6.mjs";
|
|
2
2
|
export { twitchSetupPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/twitch",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.7",
|
|
4
4
|
"description": "OpenClaw Twitch channel plugin for chat and moderation workflows.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@twurple/api-call": "8.
|
|
12
|
-
"@twurple/auth": "8.
|
|
13
|
-
"@twurple/chat": "8.
|
|
14
|
-
"zod": "4.5
|
|
11
|
+
"@twurple/api-call": "8.2.0",
|
|
12
|
+
"@twurple/auth": "8.2.0",
|
|
13
|
+
"@twurple/chat": "8.2.0",
|
|
14
|
+
"zod": "4.6.5"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@openclaw/plugin-sdk": "workspace:*"
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"minHostVersion": ">=2026.4.10"
|
|
32
32
|
},
|
|
33
33
|
"compat": {
|
|
34
|
-
"pluginApi": ">=2026.9.
|
|
34
|
+
"pluginApi": ">=2026.9.7"
|
|
35
35
|
},
|
|
36
36
|
"build": {
|
|
37
|
-
"openclawVersion": "2026.9.
|
|
37
|
+
"openclawVersion": "2026.9.7"
|
|
38
38
|
},
|
|
39
39
|
"channel": {
|
|
40
40
|
"id": "twitch",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"assets/activity.svg"
|
|
75
75
|
],
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"openclaw": ">=2026.9.
|
|
77
|
+
"openclaw": ">=2026.9.7"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"openclaw": {
|