@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
package/dist/utils/formatting.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* Message formatting utilities for Discord
|
|
3
3
|
*
|
|
4
4
|
* Provides utilities for:
|
|
5
|
-
* - Splitting long messages to fit Discord's 2000 character limit
|
|
6
|
-
* - Maintaining message coherence when splitting (avoiding mid-sentence breaks)
|
|
7
5
|
* - Managing typing indicators during message processing
|
|
6
|
+
* - Sending messages with automatic splitting
|
|
7
|
+
* - Discord-specific markdown escaping
|
|
8
|
+
*
|
|
9
|
+
* Message splitting utilities are provided by @herdctl/chat.
|
|
8
10
|
*/
|
|
11
|
+
import { splitMessage, DEFAULT_MESSAGE_DELAY_MS, } from "@herdctl/chat";
|
|
9
12
|
// =============================================================================
|
|
10
13
|
// Constants
|
|
11
14
|
// =============================================================================
|
|
@@ -13,124 +16,6 @@
|
|
|
13
16
|
* Discord's maximum message length
|
|
14
17
|
*/
|
|
15
18
|
export const DISCORD_MAX_MESSAGE_LENGTH = 2000;
|
|
16
|
-
/**
|
|
17
|
-
* Default delay between sending split messages (in milliseconds)
|
|
18
|
-
*/
|
|
19
|
-
export const DEFAULT_MESSAGE_DELAY_MS = 500;
|
|
20
|
-
/**
|
|
21
|
-
* Minimum chunk size when splitting messages
|
|
22
|
-
* Prevents creating very small message fragments
|
|
23
|
-
*/
|
|
24
|
-
export const MIN_CHUNK_SIZE = 100;
|
|
25
|
-
// =============================================================================
|
|
26
|
-
// Message Splitting
|
|
27
|
-
// =============================================================================
|
|
28
|
-
/**
|
|
29
|
-
* Default split points in order of preference
|
|
30
|
-
*
|
|
31
|
-
* We prefer to split at paragraph breaks, then sentences, then clauses, then words
|
|
32
|
-
*/
|
|
33
|
-
const DEFAULT_SPLIT_POINTS = ["\n\n", "\n", ". ", "! ", "? ", ", ", " "];
|
|
34
|
-
/**
|
|
35
|
-
* Find the best split point within a text chunk
|
|
36
|
-
*
|
|
37
|
-
* @param text - Text to find split point in
|
|
38
|
-
* @param maxLength - Maximum length for the chunk
|
|
39
|
-
* @param splitPoints - Split points to search for, in order of preference
|
|
40
|
-
* @returns Index to split at, or maxLength if no good split point found
|
|
41
|
-
*/
|
|
42
|
-
export function findSplitPoint(text, maxLength, splitPoints = DEFAULT_SPLIT_POINTS) {
|
|
43
|
-
// If text fits, no split needed
|
|
44
|
-
if (text.length <= maxLength) {
|
|
45
|
-
return text.length;
|
|
46
|
-
}
|
|
47
|
-
// Try each split point in order of preference
|
|
48
|
-
for (const splitPoint of splitPoints) {
|
|
49
|
-
// Search backwards from maxLength to find the last occurrence of this split point
|
|
50
|
-
const searchText = text.slice(0, maxLength);
|
|
51
|
-
const lastIndex = searchText.lastIndexOf(splitPoint);
|
|
52
|
-
// If found and results in a reasonable chunk size
|
|
53
|
-
if (lastIndex > MIN_CHUNK_SIZE) {
|
|
54
|
-
// Include the split point in the first chunk (e.g., keep the period with the sentence)
|
|
55
|
-
return lastIndex + splitPoint.length;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// No good split point found - fall back to hard split at maxLength
|
|
59
|
-
// But try to avoid splitting in the middle of a word
|
|
60
|
-
const hardSplitIndex = text.lastIndexOf(" ", maxLength);
|
|
61
|
-
if (hardSplitIndex > MIN_CHUNK_SIZE) {
|
|
62
|
-
return hardSplitIndex + 1; // Include the space in the first chunk
|
|
63
|
-
}
|
|
64
|
-
// Last resort: hard split at maxLength
|
|
65
|
-
return maxLength;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Split a message into chunks that fit Discord's message length limit
|
|
69
|
-
*
|
|
70
|
-
* @param content - Message content to split
|
|
71
|
-
* @param options - Split options
|
|
72
|
-
* @returns Split result with chunks array
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* const result = splitMessage(longText);
|
|
77
|
-
* for (const chunk of result.chunks) {
|
|
78
|
-
* await channel.send(chunk);
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export function splitMessage(content, options = {}) {
|
|
83
|
-
const { maxLength = DISCORD_MAX_MESSAGE_LENGTH, preserveBoundaries = true, splitPoints = DEFAULT_SPLIT_POINTS, } = options;
|
|
84
|
-
const originalLength = content.length;
|
|
85
|
-
// If content fits in one message, return as-is
|
|
86
|
-
if (content.length <= maxLength) {
|
|
87
|
-
return {
|
|
88
|
-
chunks: [content],
|
|
89
|
-
wasSplit: false,
|
|
90
|
-
originalLength,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const chunks = [];
|
|
94
|
-
let remaining = content;
|
|
95
|
-
while (remaining.length > 0) {
|
|
96
|
-
if (remaining.length <= maxLength) {
|
|
97
|
-
// Remaining text fits in one message
|
|
98
|
-
chunks.push(remaining.trim());
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
// Find the best split point
|
|
102
|
-
let splitIndex;
|
|
103
|
-
if (preserveBoundaries) {
|
|
104
|
-
splitIndex = findSplitPoint(remaining, maxLength, splitPoints);
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
// Simple split at maxLength
|
|
108
|
-
splitIndex = maxLength;
|
|
109
|
-
}
|
|
110
|
-
// Extract the chunk and trim
|
|
111
|
-
const chunk = remaining.slice(0, splitIndex).trim();
|
|
112
|
-
if (chunk.length > 0) {
|
|
113
|
-
chunks.push(chunk);
|
|
114
|
-
}
|
|
115
|
-
// Update remaining text
|
|
116
|
-
remaining = remaining.slice(splitIndex).trim();
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
chunks,
|
|
120
|
-
wasSplit: chunks.length > 1,
|
|
121
|
-
originalLength,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Check if a message needs to be split
|
|
126
|
-
*
|
|
127
|
-
* @param content - Message content to check
|
|
128
|
-
* @param maxLength - Maximum message length (default: 2000)
|
|
129
|
-
* @returns true if the message exceeds the max length
|
|
130
|
-
*/
|
|
131
|
-
export function needsSplit(content, maxLength = DISCORD_MAX_MESSAGE_LENGTH) {
|
|
132
|
-
return content.length > maxLength;
|
|
133
|
-
}
|
|
134
19
|
/**
|
|
135
20
|
* Start a typing indicator that refreshes automatically
|
|
136
21
|
*
|
|
@@ -201,16 +86,21 @@ export function startTypingIndicator(channel, refreshInterval = 5000) {
|
|
|
201
86
|
* ```
|
|
202
87
|
*/
|
|
203
88
|
export async function sendSplitMessage(channel, content, options = {}) {
|
|
204
|
-
const { delayMs = DEFAULT_MESSAGE_DELAY_MS,
|
|
205
|
-
|
|
89
|
+
const { delayMs = DEFAULT_MESSAGE_DELAY_MS, maxLength = DISCORD_MAX_MESSAGE_LENGTH, preserveBoundaries, splitPoints, } = options;
|
|
90
|
+
// Use Discord's max length as default
|
|
91
|
+
const splitResult = splitMessage(content, {
|
|
92
|
+
maxLength,
|
|
93
|
+
preserveBoundaries,
|
|
94
|
+
splitPoints,
|
|
95
|
+
});
|
|
206
96
|
const messageIds = [];
|
|
207
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
208
|
-
const chunk = chunks[i];
|
|
97
|
+
for (let i = 0; i < splitResult.chunks.length; i++) {
|
|
98
|
+
const chunk = splitResult.chunks[i];
|
|
209
99
|
// Send the message
|
|
210
100
|
const message = await channel.send(chunk);
|
|
211
101
|
messageIds.push(message.id);
|
|
212
102
|
// Add delay between messages (except after the last one)
|
|
213
|
-
if (i < chunks.length - 1 && delayMs > 0) {
|
|
103
|
+
if (i < splitResult.chunks.length - 1 && delayMs > 0) {
|
|
214
104
|
await sleep(delayMs);
|
|
215
105
|
}
|
|
216
106
|
}
|
|
@@ -255,44 +145,6 @@ export async function sendWithTyping(channel, contentProvider, options = {}) {
|
|
|
255
145
|
function sleep(ms) {
|
|
256
146
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
257
147
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Truncate a message to fit within the max length, adding an ellipsis
|
|
260
|
-
*
|
|
261
|
-
* @param content - Message content to truncate
|
|
262
|
-
* @param maxLength - Maximum length (default: 2000)
|
|
263
|
-
* @param ellipsis - Ellipsis to append (default: '...')
|
|
264
|
-
* @returns Truncated message
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```typescript
|
|
268
|
-
* const short = truncateMessage(longText, 100);
|
|
269
|
-
* // Returns: "This is a very long text that has been trun..."
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
export function truncateMessage(content, maxLength = DISCORD_MAX_MESSAGE_LENGTH, ellipsis = "...") {
|
|
273
|
-
if (content.length <= maxLength) {
|
|
274
|
-
return content;
|
|
275
|
-
}
|
|
276
|
-
const truncatedLength = maxLength - ellipsis.length;
|
|
277
|
-
return content.slice(0, truncatedLength) + ellipsis;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Format code as a Discord code block
|
|
281
|
-
*
|
|
282
|
-
* @param code - Code to format
|
|
283
|
-
* @param language - Optional language for syntax highlighting
|
|
284
|
-
* @returns Formatted code block
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* ```typescript
|
|
288
|
-
* const formatted = formatCodeBlock('const x = 1;', 'typescript');
|
|
289
|
-
* // Returns: "```typescript\nconst x = 1;\n```"
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
export function formatCodeBlock(code, language) {
|
|
293
|
-
const langTag = language ?? "";
|
|
294
|
-
return `\`\`\`${langTag}\n${code}\n\`\`\``;
|
|
295
|
-
}
|
|
296
148
|
/**
|
|
297
149
|
* Escape Discord markdown characters in text
|
|
298
150
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,EACL,YAA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C,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utility modules for the Discord connector
|
|
3
3
|
*/
|
|
4
|
-
export { DISCORD_MAX_MESSAGE_LENGTH,
|
|
4
|
+
export { DISCORD_MAX_MESSAGE_LENGTH, startTypingIndicator, sendSplitMessage, sendWithTyping, escapeMarkdown, type SendableChannel, type SendSplitOptions, type TypingController, } from "./formatting.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,0BAA0B,EAE1B,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,cAAc,EAEd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export {
|
|
5
5
|
// Constants
|
|
6
|
-
DISCORD_MAX_MESSAGE_LENGTH,
|
|
6
|
+
DISCORD_MAX_MESSAGE_LENGTH,
|
|
7
7
|
// Functions
|
|
8
|
-
|
|
8
|
+
startTypingIndicator, sendSplitMessage, sendWithTyping, escapeMarkdown, } from "./formatting.js";
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO;AACL,YAAY;AACZ,0BAA0B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO;AACL,YAAY;AACZ,0BAA0B;AAC1B,YAAY;AACZ,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,cAAc,GAKf,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herdctl/discord",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Discord connector for herdctl fleet management",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@discordjs/rest": "^2.6.0",
|
|
14
14
|
"discord.js": "^14.16.0",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"@herdctl/core": "4.1.1"
|
|
15
|
+
"@herdctl/chat": "0.2.0",
|
|
16
|
+
"@herdctl/core": "5.0.0"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
19
|
"@vitest/coverage-v8": "^4.0.17",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../../src/session-manager/__tests__/errors.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "../errors.js";
|
|
3
|
-
// =============================================================================
|
|
4
|
-
// SessionManagerError Tests
|
|
5
|
-
// =============================================================================
|
|
6
|
-
describe("SessionManagerError", () => {
|
|
7
|
-
it("creates error with correct properties", () => {
|
|
8
|
-
const error = new SessionManagerError("Test error message", SessionErrorCode.STATE_READ_FAILED, "test-agent");
|
|
9
|
-
expect(error.message).toBe("Test error message");
|
|
10
|
-
expect(error.code).toBe(SessionErrorCode.STATE_READ_FAILED);
|
|
11
|
-
expect(error.agentName).toBe("test-agent");
|
|
12
|
-
expect(error.name).toBe("SessionManagerError");
|
|
13
|
-
});
|
|
14
|
-
it("accepts cause option", () => {
|
|
15
|
-
const cause = new Error("Original error");
|
|
16
|
-
const error = new SessionManagerError("Wrapper error", SessionErrorCode.STATE_WRITE_FAILED, "test-agent", { cause });
|
|
17
|
-
expect(error.cause).toBe(cause);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
// =============================================================================
|
|
21
|
-
// SessionStateReadError Tests
|
|
22
|
-
// =============================================================================
|
|
23
|
-
describe("SessionStateReadError", () => {
|
|
24
|
-
it("creates error with correct message and properties", () => {
|
|
25
|
-
const error = new SessionStateReadError("my-agent", "/path/to/state.yaml");
|
|
26
|
-
expect(error.message).toBe("Failed to read session state for agent 'my-agent' from '/path/to/state.yaml'");
|
|
27
|
-
expect(error.code).toBe(SessionErrorCode.STATE_READ_FAILED);
|
|
28
|
-
expect(error.agentName).toBe("my-agent");
|
|
29
|
-
expect(error.path).toBe("/path/to/state.yaml");
|
|
30
|
-
expect(error.name).toBe("SessionStateReadError");
|
|
31
|
-
});
|
|
32
|
-
it("accepts cause option", () => {
|
|
33
|
-
const cause = new Error("ENOENT");
|
|
34
|
-
const error = new SessionStateReadError("my-agent", "/path/to/state.yaml", { cause });
|
|
35
|
-
expect(error.cause).toBe(cause);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
// =============================================================================
|
|
39
|
-
// SessionStateWriteError Tests
|
|
40
|
-
// =============================================================================
|
|
41
|
-
describe("SessionStateWriteError", () => {
|
|
42
|
-
it("creates error with correct message and properties", () => {
|
|
43
|
-
const error = new SessionStateWriteError("my-agent", "/path/to/state.yaml");
|
|
44
|
-
expect(error.message).toBe("Failed to write session state for agent 'my-agent' to '/path/to/state.yaml'");
|
|
45
|
-
expect(error.code).toBe(SessionErrorCode.STATE_WRITE_FAILED);
|
|
46
|
-
expect(error.agentName).toBe("my-agent");
|
|
47
|
-
expect(error.path).toBe("/path/to/state.yaml");
|
|
48
|
-
expect(error.name).toBe("SessionStateWriteError");
|
|
49
|
-
});
|
|
50
|
-
it("accepts cause option", () => {
|
|
51
|
-
const cause = new Error("EACCES");
|
|
52
|
-
const error = new SessionStateWriteError("my-agent", "/path/to/state.yaml", { cause });
|
|
53
|
-
expect(error.cause).toBe(cause);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
// =============================================================================
|
|
57
|
-
// SessionDirectoryCreateError Tests
|
|
58
|
-
// =============================================================================
|
|
59
|
-
describe("SessionDirectoryCreateError", () => {
|
|
60
|
-
it("creates error with correct message and properties", () => {
|
|
61
|
-
const error = new SessionDirectoryCreateError("my-agent", "/path/to/sessions");
|
|
62
|
-
expect(error.message).toBe("Failed to create session directory for agent 'my-agent' at '/path/to/sessions'");
|
|
63
|
-
expect(error.code).toBe(SessionErrorCode.DIRECTORY_CREATE_FAILED);
|
|
64
|
-
expect(error.agentName).toBe("my-agent");
|
|
65
|
-
expect(error.path).toBe("/path/to/sessions");
|
|
66
|
-
expect(error.name).toBe("SessionDirectoryCreateError");
|
|
67
|
-
});
|
|
68
|
-
it("accepts cause option", () => {
|
|
69
|
-
const cause = new Error("EPERM");
|
|
70
|
-
const error = new SessionDirectoryCreateError("my-agent", "/path/to/sessions", { cause });
|
|
71
|
-
expect(error.cause).toBe(cause);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
// =============================================================================
|
|
75
|
-
// isSessionManagerError Tests
|
|
76
|
-
// =============================================================================
|
|
77
|
-
describe("isSessionManagerError", () => {
|
|
78
|
-
it("returns true for SessionManagerError", () => {
|
|
79
|
-
const error = new SessionManagerError("Test", SessionErrorCode.STATE_READ_FAILED, "agent");
|
|
80
|
-
expect(isSessionManagerError(error)).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
it("returns true for SessionStateReadError", () => {
|
|
83
|
-
const error = new SessionStateReadError("agent", "/path");
|
|
84
|
-
expect(isSessionManagerError(error)).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
it("returns true for SessionStateWriteError", () => {
|
|
87
|
-
const error = new SessionStateWriteError("agent", "/path");
|
|
88
|
-
expect(isSessionManagerError(error)).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
it("returns true for SessionDirectoryCreateError", () => {
|
|
91
|
-
const error = new SessionDirectoryCreateError("agent", "/path");
|
|
92
|
-
expect(isSessionManagerError(error)).toBe(true);
|
|
93
|
-
});
|
|
94
|
-
it("returns false for regular Error", () => {
|
|
95
|
-
const error = new Error("Not a session error");
|
|
96
|
-
expect(isSessionManagerError(error)).toBe(false);
|
|
97
|
-
});
|
|
98
|
-
it("returns false for null", () => {
|
|
99
|
-
expect(isSessionManagerError(null)).toBe(false);
|
|
100
|
-
});
|
|
101
|
-
it("returns false for undefined", () => {
|
|
102
|
-
expect(isSessionManagerError(undefined)).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
it("returns false for string", () => {
|
|
105
|
-
expect(isSessionManagerError("error")).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
it("returns false for object", () => {
|
|
108
|
-
expect(isSessionManagerError({ message: "error" })).toBe(false);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
// =============================================================================
|
|
112
|
-
// Error Code Tests
|
|
113
|
-
// =============================================================================
|
|
114
|
-
describe("SessionErrorCode", () => {
|
|
115
|
-
it("has all expected error codes", () => {
|
|
116
|
-
expect(SessionErrorCode.STATE_READ_FAILED).toBe("SESSION_STATE_READ_FAILED");
|
|
117
|
-
expect(SessionErrorCode.STATE_WRITE_FAILED).toBe("SESSION_STATE_WRITE_FAILED");
|
|
118
|
-
expect(SessionErrorCode.DIRECTORY_CREATE_FAILED).toBe("SESSION_DIRECTORY_CREATE_FAILED");
|
|
119
|
-
expect(SessionErrorCode.SESSION_NOT_FOUND).toBe("SESSION_NOT_FOUND");
|
|
120
|
-
expect(SessionErrorCode.SESSION_EXPIRED).toBe("SESSION_EXPIRED");
|
|
121
|
-
expect(SessionErrorCode.INVALID_STATE).toBe("SESSION_INVALID_STATE");
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
//# sourceMappingURL=errors.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.test.js","sourceRoot":"","sources":["../../../src/session-manager/__tests__/errors.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAEtB,gFAAgF;AAChF,4BAA4B;AAC5B,gFAAgF;AAEhF,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,KAAK,GAAG,IAAI,mBAAmB,CACnC,oBAAoB,EACpB,gBAAgB,CAAC,iBAAiB,EAClC,YAAY,CACb,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;QAC5D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,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C,MAAM,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,qBAAqB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC7E,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QAC/E,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,CAAC,IAAI,CACnD,iCAAiC,CAClC,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrE,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjE,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-manager.test.d.ts","sourceRoot":"","sources":["../../../src/session-manager/__tests__/session-manager.test.ts"],"names":[],"mappings":""}
|