@herdctl/discord 0.2.2 → 1.0.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.
- package/dist/__tests__/auto-mode-handler.test.js +1 -28
- package/dist/__tests__/auto-mode-handler.test.js.map +1 -1
- package/dist/__tests__/discord-connector.test.js +1 -0
- package/dist/__tests__/discord-connector.test.js.map +1 -1
- package/dist/__tests__/error-handler.test.js +1 -1
- package/dist/__tests__/error-handler.test.js.map +1 -1
- package/dist/__tests__/manager.test.d.ts +8 -0
- package/dist/__tests__/manager.test.d.ts.map +1 -0
- package/dist/__tests__/manager.test.js +3541 -0
- package/dist/__tests__/manager.test.js.map +1 -0
- package/dist/auto-mode-handler.d.ts +8 -39
- package/dist/auto-mode-handler.d.ts.map +1 -1
- package/dist/auto-mode-handler.js +12 -78
- package/dist/auto-mode-handler.js.map +1 -1
- package/dist/commands/__tests__/command-manager.test.js +1 -0
- package/dist/commands/__tests__/command-manager.test.js.map +1 -1
- package/dist/commands/__tests__/help.test.js +1 -0
- package/dist/commands/__tests__/help.test.js.map +1 -1
- package/dist/commands/__tests__/reset.test.js +1 -0
- package/dist/commands/__tests__/reset.test.js.map +1 -1
- package/dist/commands/__tests__/status.test.js +1 -0
- package/dist/commands/__tests__/status.test.js.map +1 -1
- package/dist/commands/command-manager.d.ts.map +1 -1
- package/dist/commands/command-manager.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +1 -54
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts +3 -3
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/discord-connector.d.ts +2 -2
- package/dist/discord-connector.d.ts.map +1 -1
- package/dist/discord-connector.js.map +1 -1
- package/dist/error-handler.js +1 -1
- package/dist/error-handler.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +195 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +851 -0
- package/dist/manager.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/__tests__/formatting.test.js +1 -247
- package/dist/utils/__tests__/formatting.test.js.map +1 -1
- package/dist/utils/formatting.d.ts +11 -99
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +15 -163
- package/dist/utils/formatting.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -4
- package/dist/session-manager/__tests__/errors.test.d.ts +0 -2
- package/dist/session-manager/__tests__/errors.test.d.ts.map +0 -1
- package/dist/session-manager/__tests__/errors.test.js +0 -124
- package/dist/session-manager/__tests__/errors.test.js.map +0 -1
- package/dist/session-manager/__tests__/session-manager.test.d.ts +0 -2
- package/dist/session-manager/__tests__/session-manager.test.d.ts.map +0 -1
- package/dist/session-manager/__tests__/session-manager.test.js +0 -573
- package/dist/session-manager/__tests__/session-manager.test.js.map +0 -1
- package/dist/session-manager/__tests__/types.test.d.ts +0 -2
- package/dist/session-manager/__tests__/types.test.d.ts.map +0 -1
- package/dist/session-manager/__tests__/types.test.js +0 -169
- package/dist/session-manager/__tests__/types.test.js.map +0 -1
- package/dist/session-manager/errors.d.ts +0 -58
- package/dist/session-manager/errors.d.ts.map +0 -1
- package/dist/session-manager/errors.js +0 -70
- package/dist/session-manager/errors.js.map +0 -1
- package/dist/session-manager/index.d.ts +0 -11
- package/dist/session-manager/index.d.ts.map +0 -1
- package/dist/session-manager/index.js +0 -12
- package/dist/session-manager/index.js.map +0 -1
- package/dist/session-manager/session-manager.d.ts +0 -119
- package/dist/session-manager/session-manager.d.ts.map +0 -1
- package/dist/session-manager/session-manager.js +0 -383
- package/dist/session-manager/session-manager.js.map +0 -1
- package/dist/session-manager/types.d.ts +0 -186
- package/dist/session-manager/types.d.ts.map +0 -1
- package/dist/session-manager/types.js +0 -57
- package/dist/session-manager/types.js.map +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
* @module manager
|
|
11
|
+
*/
|
|
12
|
+
import type { FleetManagerContext, IChatManager, ChatManagerConnectorState } from "@herdctl/core";
|
|
13
|
+
import { DiscordConnector } from "./discord-connector.js";
|
|
14
|
+
/**
|
|
15
|
+
* DiscordManager handles Discord connections for agents
|
|
16
|
+
*
|
|
17
|
+
* This class encapsulates the creation and lifecycle management of
|
|
18
|
+
* DiscordConnector instances for agents that have Discord chat configured.
|
|
19
|
+
*
|
|
20
|
+
* Implements IChatManager so FleetManager can interact with it through
|
|
21
|
+
* the generic chat manager interface.
|
|
22
|
+
*/
|
|
23
|
+
export declare class DiscordManager implements IChatManager {
|
|
24
|
+
private ctx;
|
|
25
|
+
private connectors;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(ctx: FleetManagerContext);
|
|
28
|
+
/**
|
|
29
|
+
* Initialize Discord connectors for all configured agents
|
|
30
|
+
*
|
|
31
|
+
* This method:
|
|
32
|
+
* 1. Iterates through agents to find those with Discord configured
|
|
33
|
+
* 2. Creates a DiscordConnector for each Discord-enabled agent
|
|
34
|
+
*
|
|
35
|
+
* Should be called during FleetManager initialization.
|
|
36
|
+
*/
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Connect all Discord connectors
|
|
40
|
+
*
|
|
41
|
+
* Connects each connector to the Discord gateway and subscribes to events.
|
|
42
|
+
* Errors are logged but don't stop other connectors from connecting.
|
|
43
|
+
*/
|
|
44
|
+
start(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Disconnect all Discord connectors gracefully
|
|
47
|
+
*
|
|
48
|
+
* Sessions are automatically persisted to disk on every update,
|
|
49
|
+
* so they survive bot restarts. This method logs session state
|
|
50
|
+
* before disconnecting for monitoring purposes.
|
|
51
|
+
*
|
|
52
|
+
* Errors are logged but don't prevent other connectors from disconnecting.
|
|
53
|
+
*/
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get a connector for a specific agent
|
|
57
|
+
*
|
|
58
|
+
* @param agentName - Name of the agent
|
|
59
|
+
* @returns The DiscordConnector instance, or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
getConnector(agentName: string): DiscordConnector | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get all connector names
|
|
64
|
+
*
|
|
65
|
+
* @returns Array of agent names that have Discord connectors
|
|
66
|
+
*/
|
|
67
|
+
getConnectorNames(): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Get the number of active connectors
|
|
70
|
+
*
|
|
71
|
+
* @returns Number of connectors that are currently connected
|
|
72
|
+
*/
|
|
73
|
+
getConnectedCount(): number;
|
|
74
|
+
/**
|
|
75
|
+
* Check if the manager has been initialized
|
|
76
|
+
*/
|
|
77
|
+
isInitialized(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Check if a specific agent has a Discord connector
|
|
80
|
+
*
|
|
81
|
+
* @param agentName - Name of the agent
|
|
82
|
+
* @returns true if the agent has a Discord connector
|
|
83
|
+
*/
|
|
84
|
+
hasConnector(agentName: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a specific agent has a connector (alias for hasConnector)
|
|
87
|
+
*
|
|
88
|
+
* @param agentName - Name of the agent
|
|
89
|
+
* @returns true if the agent has a connector
|
|
90
|
+
*/
|
|
91
|
+
hasAgent(agentName: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Get the state of a connector for a specific agent
|
|
94
|
+
*
|
|
95
|
+
* @param agentName - Name of the agent
|
|
96
|
+
* @returns The connector state, or undefined if not found
|
|
97
|
+
*/
|
|
98
|
+
getState(agentName: string): ChatManagerConnectorState | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Handle an incoming Discord message
|
|
101
|
+
*
|
|
102
|
+
* This method:
|
|
103
|
+
* 1. Gets or creates a session for the channel
|
|
104
|
+
* 2. Builds job context from the message
|
|
105
|
+
* 3. Executes the job via trigger
|
|
106
|
+
* 4. Sends the response back to Discord
|
|
107
|
+
*
|
|
108
|
+
* @param agentName - Name of the agent handling the message
|
|
109
|
+
* @param event - The Discord message event
|
|
110
|
+
*/
|
|
111
|
+
private handleMessage;
|
|
112
|
+
/** Maximum characters for tool output in Discord embed fields */
|
|
113
|
+
private static readonly TOOL_OUTPUT_MAX_CHARS;
|
|
114
|
+
/** Embed colors */
|
|
115
|
+
private static readonly EMBED_COLOR_DEFAULT;
|
|
116
|
+
private static readonly EMBED_COLOR_ERROR;
|
|
117
|
+
private static readonly EMBED_COLOR_SYSTEM;
|
|
118
|
+
private static readonly EMBED_COLOR_SUCCESS;
|
|
119
|
+
/** Tool title emojis */
|
|
120
|
+
private static readonly TOOL_EMOJIS;
|
|
121
|
+
/**
|
|
122
|
+
* Extract tool_use blocks from an assistant message's content blocks
|
|
123
|
+
*
|
|
124
|
+
* Returns id, name, and input for each tool_use block so we can
|
|
125
|
+
* track pending calls and pair them with results.
|
|
126
|
+
*/
|
|
127
|
+
private extractToolUseBlocks;
|
|
128
|
+
/**
|
|
129
|
+
* Get a human-readable summary of tool input
|
|
130
|
+
*/
|
|
131
|
+
private getToolInputSummary;
|
|
132
|
+
/**
|
|
133
|
+
* Extract tool results from a user message
|
|
134
|
+
*
|
|
135
|
+
* Returns output, error status, and the tool_use_id for matching
|
|
136
|
+
* to the pending tool_use that produced this result.
|
|
137
|
+
*/
|
|
138
|
+
private extractToolResults;
|
|
139
|
+
/**
|
|
140
|
+
* Extract content from a top-level tool_use_result value
|
|
141
|
+
*/
|
|
142
|
+
private extractToolResultContent;
|
|
143
|
+
/**
|
|
144
|
+
* Format duration in milliseconds to a human-readable string
|
|
145
|
+
*/
|
|
146
|
+
private static formatDuration;
|
|
147
|
+
/**
|
|
148
|
+
* Build a Discord embed for a tool call result
|
|
149
|
+
*
|
|
150
|
+
* Combines the tool_use info (name, input) with the tool_result
|
|
151
|
+
* (output, error status) into a compact Discord embed.
|
|
152
|
+
*
|
|
153
|
+
* @param toolUse - The tool_use block info (name, input, startTime)
|
|
154
|
+
* @param toolResult - The tool result (output, isError)
|
|
155
|
+
* @param maxOutputChars - Maximum characters for output (defaults to TOOL_OUTPUT_MAX_CHARS)
|
|
156
|
+
*/
|
|
157
|
+
private buildToolEmbed;
|
|
158
|
+
/**
|
|
159
|
+
* Handle errors from Discord connectors
|
|
160
|
+
*
|
|
161
|
+
* Logs errors without crashing the connector
|
|
162
|
+
*
|
|
163
|
+
* @param agentName - Name of the agent that encountered the error
|
|
164
|
+
* @param error - The error that occurred
|
|
165
|
+
*/
|
|
166
|
+
private handleError;
|
|
167
|
+
/** Discord's maximum message length */
|
|
168
|
+
private static readonly MAX_MESSAGE_LENGTH;
|
|
169
|
+
/**
|
|
170
|
+
* Format an error message for Discord display
|
|
171
|
+
*
|
|
172
|
+
* Creates a user-friendly error message with guidance on how to proceed.
|
|
173
|
+
*
|
|
174
|
+
* @param error - The error that occurred
|
|
175
|
+
* @returns Formatted error message string
|
|
176
|
+
*/
|
|
177
|
+
formatErrorMessage(error: Error): string;
|
|
178
|
+
/**
|
|
179
|
+
* Split a response into chunks that fit Discord's 2000 character limit
|
|
180
|
+
*
|
|
181
|
+
* Uses the shared splitMessage utility from @herdctl/chat.
|
|
182
|
+
*
|
|
183
|
+
* @param text - The text to split
|
|
184
|
+
* @returns Array of text chunks, each under 2000 characters
|
|
185
|
+
*/
|
|
186
|
+
splitResponse(text: string): string[];
|
|
187
|
+
/**
|
|
188
|
+
* Send a response to Discord, splitting if necessary
|
|
189
|
+
*
|
|
190
|
+
* @param reply - The reply function from the message event
|
|
191
|
+
* @param content - The content to send
|
|
192
|
+
*/
|
|
193
|
+
sendResponse(reply: (content: string) => Promise<void>, content: string): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EAI1B,MAAM,eAAe,CAAC;AASvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAuB1D;;;;;;;;GAQG;AACH,qBAAa,cAAe,YAAW,YAAY;IAIrC,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,UAAU,CAA4C;IAC9D,OAAO,CAAC,WAAW,CAAkB;gBAEjB,GAAG,EAAE,mBAAmB;IAE5C;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA0FjC;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyC5B;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAwC3B;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI7D;;;;OAIG;IACH,iBAAiB,IAAI,MAAM,EAAE;IAI7B;;;;OAIG;IACH,iBAAiB,IAAI,MAAM;IAM3B;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIxC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIpC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,GAAG,SAAS;IAoBlE;;;;;;;;;;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