@herdctl/core 0.2.0 → 0.3.0

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.
@@ -0,0 +1,569 @@
1
+ /**
2
+ * Discord Manager Module
3
+ *
4
+ * Manages Discord connectors for agents that have `chat.discord` configured.
5
+ * This module is responsible for:
6
+ * - Creating one DiscordConnector instance per Discord-enabled agent
7
+ * - Managing connector lifecycle (start/stop)
8
+ * - Providing access to connectors for status queries
9
+ *
10
+ * Note: This module dynamically imports @herdctl/discord at runtime to avoid
11
+ * a hard dependency. The @herdctl/core package can be used without Discord support.
12
+ *
13
+ * @module discord-manager
14
+ */
15
+ /**
16
+ * Lazy import the Discord package to avoid hard dependency
17
+ * This allows @herdctl/core to be used without @herdctl/discord installed
18
+ */
19
+ async function importDiscordPackage() {
20
+ try {
21
+ // Dynamic import - will be resolved at runtime
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ const pkg = (await import("@herdctl/discord"));
24
+ return pkg;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /**
31
+ * DiscordManager handles Discord connections for agents
32
+ *
33
+ * This class encapsulates the creation and lifecycle management of
34
+ * DiscordConnector instances for agents that have Discord chat configured.
35
+ */
36
+ export class DiscordManager {
37
+ ctx;
38
+ connectors = new Map();
39
+ initialized = false;
40
+ constructor(ctx) {
41
+ this.ctx = ctx;
42
+ }
43
+ /**
44
+ * Initialize Discord connectors for all configured agents
45
+ *
46
+ * This method:
47
+ * 1. Checks if @herdctl/discord package is available
48
+ * 2. Iterates through agents to find those with Discord configured
49
+ * 3. Creates a DiscordConnector for each Discord-enabled agent
50
+ *
51
+ * Should be called during FleetManager initialization.
52
+ */
53
+ async initialize() {
54
+ if (this.initialized) {
55
+ return;
56
+ }
57
+ const logger = this.ctx.getLogger();
58
+ const config = this.ctx.getConfig();
59
+ if (!config) {
60
+ logger.debug("No config available, skipping Discord initialization");
61
+ return;
62
+ }
63
+ // Try to import the discord package
64
+ const discordPkg = await importDiscordPackage();
65
+ if (!discordPkg) {
66
+ logger.debug("@herdctl/discord not installed, skipping Discord connectors");
67
+ return;
68
+ }
69
+ const { DiscordConnector, SessionManager } = discordPkg;
70
+ const stateDir = this.ctx.getStateDir();
71
+ // Find agents with Discord configured
72
+ const discordAgents = config.agents.filter((agent) => agent.chat?.discord !== undefined);
73
+ if (discordAgents.length === 0) {
74
+ logger.debug("No agents with Discord configured");
75
+ this.initialized = true;
76
+ return;
77
+ }
78
+ logger.info(`Initializing Discord connectors for ${discordAgents.length} agent(s)`);
79
+ for (const agent of discordAgents) {
80
+ try {
81
+ const discordConfig = agent.chat.discord;
82
+ if (!discordConfig)
83
+ continue;
84
+ // Get bot token from environment variable
85
+ const botToken = process.env[discordConfig.bot_token_env];
86
+ if (!botToken) {
87
+ logger.warn(`Discord bot token not found in environment variable '${discordConfig.bot_token_env}' for agent '${agent.name}'`);
88
+ continue;
89
+ }
90
+ // Create logger adapter for this agent
91
+ const createAgentLogger = (prefix) => ({
92
+ debug: (msg, data) => logger.debug(`${prefix} ${msg}${data ? ` ${JSON.stringify(data)}` : ""}`),
93
+ info: (msg, data) => logger.info(`${prefix} ${msg}${data ? ` ${JSON.stringify(data)}` : ""}`),
94
+ warn: (msg, data) => logger.warn(`${prefix} ${msg}${data ? ` ${JSON.stringify(data)}` : ""}`),
95
+ error: (msg, data) => logger.error(`${prefix} ${msg}${data ? ` ${JSON.stringify(data)}` : ""}`),
96
+ });
97
+ // Create session manager for this agent
98
+ const sessionManager = new SessionManager({
99
+ agentName: agent.name,
100
+ stateDir,
101
+ sessionExpiryHours: discordConfig.session_expiry_hours,
102
+ logger: createAgentLogger(`[discord:${agent.name}:session]`),
103
+ });
104
+ // Create the connector
105
+ // Note: FleetManager is passed via ctx.getEmitter() which returns the FleetManager instance
106
+ const connector = new DiscordConnector({
107
+ agentConfig: agent,
108
+ discordConfig,
109
+ botToken,
110
+ // The context's getEmitter() returns the FleetManager instance (which extends EventEmitter)
111
+ fleetManager: this.ctx.getEmitter(),
112
+ sessionManager,
113
+ stateDir,
114
+ logger: createAgentLogger(`[discord:${agent.name}]`),
115
+ });
116
+ this.connectors.set(agent.name, connector);
117
+ logger.debug(`Created Discord connector for agent '${agent.name}'`);
118
+ }
119
+ catch (error) {
120
+ const errorMessage = error instanceof Error ? error.message : String(error);
121
+ logger.error(`Failed to create Discord connector for agent '${agent.name}': ${errorMessage}`);
122
+ // Continue with other agents - don't fail the whole initialization
123
+ }
124
+ }
125
+ this.initialized = true;
126
+ logger.info(`Discord manager initialized with ${this.connectors.size} connector(s)`);
127
+ }
128
+ /**
129
+ * Connect all Discord connectors
130
+ *
131
+ * Connects each connector to the Discord gateway and subscribes to events.
132
+ * Errors are logged but don't stop other connectors from connecting.
133
+ */
134
+ async start() {
135
+ const logger = this.ctx.getLogger();
136
+ if (this.connectors.size === 0) {
137
+ logger.debug("No Discord connectors to start");
138
+ return;
139
+ }
140
+ logger.info(`Starting ${this.connectors.size} Discord connector(s)...`);
141
+ const connectPromises = [];
142
+ for (const [agentName, connector] of this.connectors) {
143
+ // Subscribe to connector events before connecting
144
+ connector.on("message", (event) => {
145
+ this.handleMessage(agentName, event).catch((error) => {
146
+ this.handleError(agentName, error);
147
+ });
148
+ });
149
+ connector.on("error", (event) => {
150
+ this.handleError(agentName, event.error);
151
+ });
152
+ connectPromises.push(connector.connect().catch((error) => {
153
+ const errorMessage = error instanceof Error ? error.message : String(error);
154
+ logger.error(`Failed to connect Discord for agent '${agentName}': ${errorMessage}`);
155
+ // Don't re-throw - we want to continue connecting other agents
156
+ }));
157
+ }
158
+ await Promise.all(connectPromises);
159
+ const connectedCount = Array.from(this.connectors.values()).filter((c) => c.isConnected()).length;
160
+ logger.info(`Discord connectors started: ${connectedCount}/${this.connectors.size} connected`);
161
+ }
162
+ /**
163
+ * Disconnect all Discord connectors gracefully
164
+ *
165
+ * Sessions are automatically persisted to disk on every update,
166
+ * so they survive bot restarts. This method logs session state
167
+ * before disconnecting for monitoring purposes.
168
+ *
169
+ * Errors are logged but don't prevent other connectors from disconnecting.
170
+ */
171
+ async stop() {
172
+ const logger = this.ctx.getLogger();
173
+ if (this.connectors.size === 0) {
174
+ logger.debug("No Discord connectors to stop");
175
+ return;
176
+ }
177
+ logger.info(`Stopping ${this.connectors.size} Discord connector(s)...`);
178
+ // Log session state before shutdown (sessions are already persisted to disk)
179
+ for (const [agentName, connector] of this.connectors) {
180
+ try {
181
+ const activeSessionCount = await connector.sessionManager.getActiveSessionCount();
182
+ if (activeSessionCount > 0) {
183
+ logger.info(`Preserving ${activeSessionCount} active session(s) for agent '${agentName}'`);
184
+ }
185
+ }
186
+ catch (error) {
187
+ const errorMessage = error instanceof Error ? error.message : String(error);
188
+ logger.warn(`Failed to get session count for agent '${agentName}': ${errorMessage}`);
189
+ // Continue with shutdown - this is just informational logging
190
+ }
191
+ }
192
+ const disconnectPromises = [];
193
+ for (const [agentName, connector] of this.connectors) {
194
+ disconnectPromises.push(connector.disconnect().catch((error) => {
195
+ const errorMessage = error instanceof Error ? error.message : String(error);
196
+ logger.error(`Error disconnecting Discord for agent '${agentName}': ${errorMessage}`);
197
+ // Don't re-throw - graceful shutdown should continue
198
+ }));
199
+ }
200
+ await Promise.all(disconnectPromises);
201
+ logger.info("All Discord connectors stopped");
202
+ }
203
+ /**
204
+ * Get a connector for a specific agent
205
+ *
206
+ * @param agentName - Name of the agent
207
+ * @returns The DiscordConnector instance, or undefined if not found
208
+ */
209
+ getConnector(agentName) {
210
+ return this.connectors.get(agentName);
211
+ }
212
+ /**
213
+ * Get all connector names
214
+ *
215
+ * @returns Array of agent names that have Discord connectors
216
+ */
217
+ getConnectorNames() {
218
+ return Array.from(this.connectors.keys());
219
+ }
220
+ /**
221
+ * Get the number of active connectors
222
+ *
223
+ * @returns Number of connectors that are currently connected
224
+ */
225
+ getConnectedCount() {
226
+ return Array.from(this.connectors.values()).filter((c) => c.isConnected()).length;
227
+ }
228
+ /**
229
+ * Check if a specific agent has a Discord connector
230
+ *
231
+ * @param agentName - Name of the agent
232
+ * @returns true if the agent has a Discord connector
233
+ */
234
+ hasConnector(agentName) {
235
+ return this.connectors.has(agentName);
236
+ }
237
+ // ===========================================================================
238
+ // Message Handling Pipeline
239
+ // ===========================================================================
240
+ /**
241
+ * Handle an incoming Discord message
242
+ *
243
+ * This method:
244
+ * 1. Gets or creates a session for the channel
245
+ * 2. Builds job context from the message
246
+ * 3. Executes the job via trigger
247
+ * 4. Sends the response back to Discord
248
+ *
249
+ * @param agentName - Name of the agent handling the message
250
+ * @param event - The Discord message event
251
+ */
252
+ async handleMessage(agentName, event) {
253
+ const logger = this.ctx.getLogger();
254
+ const emitter = this.ctx.getEmitter();
255
+ logger.info(`Discord message for agent '${agentName}': ${event.prompt.substring(0, 50)}...`);
256
+ // Get the agent configuration
257
+ const config = this.ctx.getConfig();
258
+ const agent = config?.agents.find((a) => a.name === agentName);
259
+ if (!agent) {
260
+ logger.error(`Agent '${agentName}' not found in configuration`);
261
+ try {
262
+ await event.reply("Sorry, I'm not properly configured. Please contact an administrator.");
263
+ }
264
+ catch (replyError) {
265
+ logger.error(`Failed to send error reply: ${replyError.message}`);
266
+ }
267
+ return;
268
+ }
269
+ // Get or create session for this channel (persists to disk automatically)
270
+ const connector = this.connectors.get(agentName);
271
+ if (connector) {
272
+ try {
273
+ const sessionResult = await connector.sessionManager.getOrCreateSession(event.metadata.channelId);
274
+ logger.debug(`Session for channel ${event.metadata.channelId}: ${sessionResult.sessionId} (${sessionResult.isNew ? "new" : "existing"})`);
275
+ }
276
+ catch (error) {
277
+ const errorMessage = error instanceof Error ? error.message : String(error);
278
+ logger.warn(`Failed to get/create session: ${errorMessage}`);
279
+ // Continue processing - session failure shouldn't block message handling
280
+ }
281
+ }
282
+ // Collect all response chunks as the job executes
283
+ const responseChunks = [];
284
+ // Start typing indicator while processing
285
+ const stopTyping = event.startTyping();
286
+ try {
287
+ // Import FleetManager dynamically to avoid circular dependency
288
+ // The context's getEmitter() returns the FleetManager instance
289
+ const fleetManager = emitter;
290
+ // Execute job via FleetManager.trigger()
291
+ // The onMessage callback collects streaming output
292
+ const result = await fleetManager.trigger(agentName, undefined, {
293
+ prompt: event.prompt,
294
+ onMessage: (message) => {
295
+ // Extract text content from assistant messages
296
+ if (message.type === "assistant") {
297
+ const content = this.extractMessageContent(message);
298
+ if (content) {
299
+ responseChunks.push(content);
300
+ }
301
+ }
302
+ },
303
+ });
304
+ logger.info(`Discord job completed: ${result.jobId} for agent '${agentName}'`);
305
+ // Combine all response chunks
306
+ const fullResponse = responseChunks.join("");
307
+ // Send response to Discord channel (handles splitting if needed)
308
+ if (fullResponse) {
309
+ await this.sendResponse(event.reply, fullResponse);
310
+ }
311
+ else {
312
+ await event.reply("I've completed the task, but I don't have a specific response to share.");
313
+ }
314
+ // Update session timestamp after successful response
315
+ if (connector) {
316
+ try {
317
+ await connector.sessionManager.touchSession(event.metadata.channelId);
318
+ }
319
+ catch (touchError) {
320
+ const errorMessage = touchError instanceof Error ? touchError.message : String(touchError);
321
+ logger.warn(`Failed to touch session: ${errorMessage}`);
322
+ // Don't fail the message handling for session touch failure
323
+ }
324
+ }
325
+ // Emit event for tracking
326
+ emitter.emit("discord:message:handled", {
327
+ agentName,
328
+ channelId: event.metadata.channelId,
329
+ messageId: event.metadata.messageId,
330
+ jobId: result.jobId,
331
+ timestamp: new Date().toISOString(),
332
+ });
333
+ }
334
+ catch (error) {
335
+ const err = error instanceof Error ? error : new Error(String(error));
336
+ logger.error(`Discord message handling failed for agent '${agentName}': ${err.message}`);
337
+ // Send user-friendly error message using the formatted error method
338
+ try {
339
+ await event.reply(this.formatErrorMessage(err));
340
+ }
341
+ catch (replyError) {
342
+ logger.error(`Failed to send error reply: ${replyError.message}`);
343
+ }
344
+ // Emit error event for tracking
345
+ emitter.emit("discord:message:error", {
346
+ agentName,
347
+ channelId: event.metadata.channelId,
348
+ messageId: event.metadata.messageId,
349
+ error: err.message,
350
+ timestamp: new Date().toISOString(),
351
+ });
352
+ }
353
+ finally {
354
+ // Always stop typing indicator when done
355
+ stopTyping();
356
+ }
357
+ }
358
+ /**
359
+ * Extract text content from an SDK message
360
+ *
361
+ * Handles various message formats from the Claude Agent SDK
362
+ */
363
+ extractMessageContent(message) {
364
+ // Check for direct content
365
+ if (typeof message.content === "string" && message.content) {
366
+ return message.content;
367
+ }
368
+ // Check for nested message content (SDK structure)
369
+ const apiMessage = message.message;
370
+ const content = apiMessage?.content;
371
+ if (!content)
372
+ return undefined;
373
+ // If it's a string, return directly
374
+ if (typeof content === "string") {
375
+ return content;
376
+ }
377
+ // If it's an array of content blocks, extract text
378
+ if (Array.isArray(content)) {
379
+ const textParts = [];
380
+ for (const block of content) {
381
+ if (block && typeof block === "object" && "type" in block) {
382
+ if (block.type === "text" && "text" in block && typeof block.text === "string") {
383
+ textParts.push(block.text);
384
+ }
385
+ }
386
+ }
387
+ return textParts.length > 0 ? textParts.join("") : undefined;
388
+ }
389
+ return undefined;
390
+ }
391
+ /**
392
+ * Handle errors from Discord connectors
393
+ *
394
+ * Logs errors without crashing the connector
395
+ *
396
+ * @param agentName - Name of the agent that encountered the error
397
+ * @param error - The error that occurred
398
+ */
399
+ handleError(agentName, error) {
400
+ const logger = this.ctx.getLogger();
401
+ const emitter = this.ctx.getEmitter();
402
+ const errorMessage = error instanceof Error ? error.message : String(error);
403
+ logger.error(`Discord connector error for agent '${agentName}': ${errorMessage}`);
404
+ // Emit error event for monitoring
405
+ emitter.emit("discord:error", {
406
+ agentName,
407
+ error: errorMessage,
408
+ timestamp: new Date().toISOString(),
409
+ });
410
+ }
411
+ // ===========================================================================
412
+ // Response Formatting and Splitting
413
+ // ===========================================================================
414
+ /** Discord's maximum message length */
415
+ static MAX_MESSAGE_LENGTH = 2000;
416
+ /**
417
+ * Format an error message for Discord display
418
+ *
419
+ * Creates a user-friendly error message with guidance on how to proceed.
420
+ *
421
+ * @param error - The error that occurred
422
+ * @returns Formatted error message string
423
+ */
424
+ formatErrorMessage(error) {
425
+ return `❌ **Error**: ${error.message}\n\nPlease try again or use \`/reset\` to start a new session.`;
426
+ }
427
+ /**
428
+ * Split a response into chunks that fit Discord's 2000 character limit
429
+ *
430
+ * This method intelligently splits text:
431
+ * - Preserves code blocks when possible (closing and reopening across chunks)
432
+ * - Splits at natural boundaries (newlines, then spaces)
433
+ * - Never splits mid-word
434
+ *
435
+ * @param text - The text to split
436
+ * @returns Array of text chunks, each under 2000 characters
437
+ */
438
+ splitResponse(text) {
439
+ const MAX_LENGTH = DiscordManager.MAX_MESSAGE_LENGTH;
440
+ // If text fits in one message, return as-is
441
+ if (text.length <= MAX_LENGTH) {
442
+ return [text];
443
+ }
444
+ const chunks = [];
445
+ let remaining = text;
446
+ while (remaining.length > 0) {
447
+ if (remaining.length <= MAX_LENGTH) {
448
+ chunks.push(remaining);
449
+ break;
450
+ }
451
+ // Find the best split point
452
+ const { chunk, rest } = this.findSplitPoint(remaining, MAX_LENGTH);
453
+ chunks.push(chunk);
454
+ remaining = rest;
455
+ }
456
+ return chunks;
457
+ }
458
+ /**
459
+ * Find the best point to split text, preserving code blocks
460
+ *
461
+ * @param text - Text to split
462
+ * @param maxLength - Maximum chunk length
463
+ * @returns Object with the chunk and remaining text
464
+ */
465
+ findSplitPoint(text, maxLength) {
466
+ // Check if we're inside a code block at the split point
467
+ const codeBlockState = this.analyzeCodeBlocks(text.substring(0, maxLength));
468
+ // If inside a code block, we need to close it and reopen in the next chunk
469
+ if (codeBlockState.insideBlock) {
470
+ // Find a good split point before maxLength
471
+ const splitIndex = this.findNaturalBreak(text, maxLength);
472
+ const chunkText = text.substring(0, splitIndex);
473
+ // Re-analyze the actual chunk
474
+ const actualState = this.analyzeCodeBlocks(chunkText);
475
+ if (actualState.insideBlock) {
476
+ // Close the code block in this chunk
477
+ const closedChunk = chunkText + "\n```";
478
+ // Reopen with the same language in the next chunk
479
+ const continuation = "```" + (actualState.language || "") + "\n" + text.substring(splitIndex);
480
+ return { chunk: closedChunk, rest: continuation };
481
+ }
482
+ return {
483
+ chunk: chunkText,
484
+ rest: text.substring(splitIndex),
485
+ };
486
+ }
487
+ // Not inside a code block - find natural break point
488
+ const splitIndex = this.findNaturalBreak(text, maxLength);
489
+ return {
490
+ chunk: text.substring(0, splitIndex),
491
+ rest: text.substring(splitIndex),
492
+ };
493
+ }
494
+ /**
495
+ * Analyze text to determine if it ends inside a code block
496
+ *
497
+ * @param text - Text to analyze
498
+ * @returns Object indicating if inside a block and the language if so
499
+ */
500
+ analyzeCodeBlocks(text) {
501
+ // Find all code block markers (```)
502
+ const codeBlockRegex = /```(\w*)?/g;
503
+ let match;
504
+ let insideBlock = false;
505
+ let language = null;
506
+ while ((match = codeBlockRegex.exec(text)) !== null) {
507
+ if (insideBlock) {
508
+ // This closes a block
509
+ insideBlock = false;
510
+ language = null;
511
+ }
512
+ else {
513
+ // This opens a block
514
+ insideBlock = true;
515
+ language = match[1] || null;
516
+ }
517
+ }
518
+ return { insideBlock, language };
519
+ }
520
+ /**
521
+ * Find a natural break point in text (newline or space)
522
+ *
523
+ * Prefers breaking at:
524
+ * 1. Double newlines (paragraph breaks)
525
+ * 2. Single newlines
526
+ * 3. Spaces
527
+ *
528
+ * @param text - Text to search
529
+ * @param maxLength - Maximum position to search
530
+ * @returns Index of the best split point
531
+ */
532
+ findNaturalBreak(text, maxLength) {
533
+ // Don't search beyond the text length
534
+ const searchEnd = Math.min(maxLength, text.length);
535
+ // First, try to find a double newline (paragraph break)
536
+ const doubleNewline = text.lastIndexOf("\n\n", searchEnd);
537
+ if (doubleNewline > 0 && doubleNewline > searchEnd - 500) {
538
+ // Found a paragraph break within the last 500 chars
539
+ return doubleNewline + 2; // Include the newlines
540
+ }
541
+ // Try to find a single newline
542
+ const singleNewline = text.lastIndexOf("\n", searchEnd);
543
+ if (singleNewline > 0 && singleNewline > searchEnd - 200) {
544
+ // Found a newline within the last 200 chars
545
+ return singleNewline + 1; // Include the newline
546
+ }
547
+ // Try to find a space (avoid splitting mid-word)
548
+ const space = text.lastIndexOf(" ", searchEnd);
549
+ if (space > 0 && space > searchEnd - 100) {
550
+ // Found a space within the last 100 chars
551
+ return space + 1; // Include the space
552
+ }
553
+ // Last resort: hard cut at maxLength
554
+ return searchEnd;
555
+ }
556
+ /**
557
+ * Send a response to Discord, splitting if necessary
558
+ *
559
+ * @param reply - The reply function from the message event
560
+ * @param content - The content to send
561
+ */
562
+ async sendResponse(reply, content) {
563
+ const chunks = this.splitResponse(content);
564
+ for (const chunk of chunks) {
565
+ await reply(chunk);
566
+ }
567
+ }
568
+ }
569
+ //# sourceMappingURL=discord-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discord-manager.js","sourceRoot":"","sources":["../../src/fleet-manager/discord-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA4JH;;;GAGG;AACH,KAAK,UAAU,oBAAoB;IACjC,IAAI,CAAC;QACH,+CAA+C;QAC/C,8DAA8D;QAC9D,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,kBAA4B,CAAC,CAA6B,CAAC;QACrF,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAIL;IAHZ,UAAU,GAAmC,IAAI,GAAG,EAAE,CAAC;IACvD,WAAW,GAAY,KAAK,CAAC;IAErC,YAAoB,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;IAAG,CAAC;IAEhD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QAEpC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,CAAC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AAa,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC1D,IAAI,aAAa,GAAG,CAAC,IAAI,aAAa,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YACzD,oDAAoD;YACpD,OAAO,aAAa,GAAG,CAAC,CAAC,CAAC,uBAAuB;QACnD,CAAC;QAED,+BAA+B;QAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxD,IAAI,aAAa,GAAG,CAAC,IAAI,aAAa,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YACzD,4CAA4C;YAC5C,OAAO,aAAa,GAAG,CAAC,CAAC,CAAC,sBAAsB;QAClD,CAAC;QAED,iDAAiD;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,SAAS,GAAG,GAAG,EAAE,CAAC;YACzC,0CAA0C;YAC1C,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,oBAAoB;QACxC,CAAC;QAED,qCAAqC;QACrC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAChB,KAAyC,EACzC,OAAe;QAEf,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC"}
@@ -172,6 +172,39 @@ export interface JobForkedPayload {
172
172
  /** ISO timestamp when the job was forked */
173
173
  timestamp: string;
174
174
  }
175
+ /**
176
+ * Payload for discord:connector:connected event
177
+ */
178
+ export interface DiscordConnectorConnectedPayload {
179
+ /** Name of the agent whose Discord connector connected */
180
+ agentName: string;
181
+ /** Bot username */
182
+ botUsername: string;
183
+ /** ISO timestamp when the connector connected */
184
+ timestamp: string;
185
+ }
186
+ /**
187
+ * Payload for discord:connector:disconnected event
188
+ */
189
+ export interface DiscordConnectorDisconnectedPayload {
190
+ /** Name of the agent whose Discord connector disconnected */
191
+ agentName: string;
192
+ /** Reason for disconnection (if available) */
193
+ reason?: string;
194
+ /** ISO timestamp when the connector disconnected */
195
+ timestamp: string;
196
+ }
197
+ /**
198
+ * Payload for discord:connector:error event
199
+ */
200
+ export interface DiscordConnectorErrorPayload {
201
+ /** Name of the agent whose Discord connector had an error */
202
+ agentName: string;
203
+ /** Error message */
204
+ error: string;
205
+ /** ISO timestamp when the error occurred */
206
+ timestamp: string;
207
+ }
175
208
  /**
176
209
  * Strongly-typed event map for FleetManager
177
210
  *
@@ -266,6 +299,18 @@ export interface FleetManagerEventMap {
266
299
  * A new job is created based on an existing job's configuration.
267
300
  */
268
301
  "job:forked": [payload: JobForkedPayload];
302
+ /**
303
+ * Emitted when a Discord connector successfully connects.
304
+ */
305
+ "discord:connector:connected": [payload: DiscordConnectorConnectedPayload];
306
+ /**
307
+ * Emitted when a Discord connector disconnects.
308
+ */
309
+ "discord:connector:disconnected": [payload: DiscordConnectorDisconnectedPayload];
310
+ /**
311
+ * Emitted when a Discord connector encounters an error.
312
+ */
313
+ "discord:connector:error": [payload: DiscordConnectorErrorPayload];
269
314
  /**
270
315
  * Emitted when an error occurs in the FleetManager.
271
316
  * This is a catch-all for errors that aren't tied to a specific job.