@herdctl/slack 0.3.0 → 1.1.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__/command-handler.test.js +1 -0
- package/dist/__tests__/command-handler.test.js.map +1 -1
- package/dist/__tests__/error-handler.test.js +25 -25
- package/dist/__tests__/error-handler.test.js.map +1 -1
- package/dist/__tests__/formatting.test.js +9 -9
- package/dist/__tests__/formatting.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 +278 -0
- package/dist/__tests__/manager.test.js.map +1 -0
- package/dist/__tests__/slack-connector.test.js +200 -0
- package/dist/__tests__/slack-connector.test.js.map +1 -1
- package/dist/commands/command-handler.d.ts +3 -3
- package/dist/commands/command-handler.d.ts.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/error-handler.d.ts +12 -33
- package/dist/error-handler.d.ts.map +1 -1
- package/dist/error-handler.js +32 -57
- package/dist/error-handler.js.map +1 -1
- package/dist/formatting.d.ts +4 -45
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +10 -96
- package/dist/formatting.js.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/manager.d.ts +156 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +532 -0
- package/dist/manager.js.map +1 -0
- package/dist/slack-connector.d.ts +10 -2
- package/dist/slack-connector.d.ts.map +1 -1
- package/dist/slack-connector.js +112 -32
- package/dist/slack-connector.js.map +1 -1
- package/dist/types.d.ts +8 -24
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/__tests__/session-manager.test.d.ts +0 -2
- package/dist/__tests__/session-manager.test.d.ts.map +0 -1
- package/dist/__tests__/session-manager.test.js +0 -214
- package/dist/__tests__/session-manager.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 -9
- package/dist/session-manager/index.d.ts.map +0 -1
- package/dist/session-manager/index.js +0 -13
- package/dist/session-manager/index.js.map +0 -1
- package/dist/session-manager/session-manager.d.ts +0 -62
- package/dist/session-manager/session-manager.d.ts.map +0 -1
- package/dist/session-manager/session-manager.js +0 -320
- package/dist/session-manager/session-manager.js.map +0 -1
- package/dist/session-manager/types.d.ts +0 -154
- 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/formatting.d.ts
CHANGED
|
@@ -3,39 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides utilities for:
|
|
5
5
|
* - Converting standard markdown to Slack's mrkdwn format
|
|
6
|
-
* - Splitting long messages to fit Slack's practical limit
|
|
7
6
|
* - Creating context attachments with color coding
|
|
7
|
+
*
|
|
8
|
+
* Note: Message splitting utilities (findSplitPoint, splitMessage, needsSplit,
|
|
9
|
+
* truncateMessage, formatCodeBlock) are provided by @herdctl/chat.
|
|
8
10
|
*/
|
|
11
|
+
export { findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, type MessageSplitOptions, type SplitResult, } from "@herdctl/chat";
|
|
9
12
|
/**
|
|
10
13
|
* Slack's practical maximum message length
|
|
11
14
|
*
|
|
12
15
|
* Hard limit is ~40K, but messages above ~4K become unwieldy in threads.
|
|
13
16
|
*/
|
|
14
17
|
export declare const SLACK_MAX_MESSAGE_LENGTH = 4000;
|
|
15
|
-
/**
|
|
16
|
-
* Minimum chunk size when splitting messages
|
|
17
|
-
*/
|
|
18
|
-
export declare const MIN_CHUNK_SIZE = 100;
|
|
19
|
-
/**
|
|
20
|
-
* Default delay between sending split messages (in milliseconds)
|
|
21
|
-
*/
|
|
22
|
-
export declare const DEFAULT_MESSAGE_DELAY_MS = 500;
|
|
23
|
-
/**
|
|
24
|
-
* Options for splitting messages
|
|
25
|
-
*/
|
|
26
|
-
export interface MessageSplitOptions {
|
|
27
|
-
maxLength?: number;
|
|
28
|
-
preserveBoundaries?: boolean;
|
|
29
|
-
splitPoints?: string[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Result from splitting a message
|
|
33
|
-
*/
|
|
34
|
-
export interface SplitResult {
|
|
35
|
-
chunks: string[];
|
|
36
|
-
wasSplit: boolean;
|
|
37
|
-
originalLength: number;
|
|
38
|
-
}
|
|
39
18
|
/**
|
|
40
19
|
* Context attachment for Slack messages
|
|
41
20
|
*/
|
|
@@ -50,32 +29,12 @@ export interface ContextAttachment {
|
|
|
50
29
|
* conversion that handles edge cases regex approaches miss.
|
|
51
30
|
*/
|
|
52
31
|
export declare function markdownToMrkdwn(text: string): string;
|
|
53
|
-
/**
|
|
54
|
-
* Find the best split point within a text chunk
|
|
55
|
-
*/
|
|
56
|
-
export declare function findSplitPoint(text: string, maxLength: number, splitPoints?: string[]): number;
|
|
57
|
-
/**
|
|
58
|
-
* Split a message into chunks that fit Slack's message length limit
|
|
59
|
-
*/
|
|
60
|
-
export declare function splitMessage(content: string, options?: MessageSplitOptions): SplitResult;
|
|
61
|
-
/**
|
|
62
|
-
* Check if a message needs to be split
|
|
63
|
-
*/
|
|
64
|
-
export declare function needsSplit(content: string, maxLength?: number): boolean;
|
|
65
32
|
/**
|
|
66
33
|
* Create a context attachment for Slack messages
|
|
67
34
|
*
|
|
68
35
|
* Used to display context usage information in a color-coded footer.
|
|
69
36
|
*/
|
|
70
37
|
export declare function createContextAttachment(contextPercent: number): ContextAttachment;
|
|
71
|
-
/**
|
|
72
|
-
* Truncate a message to fit within the max length, adding an ellipsis
|
|
73
|
-
*/
|
|
74
|
-
export declare function truncateMessage(content: string, maxLength?: number, ellipsis?: string): string;
|
|
75
|
-
/**
|
|
76
|
-
* Format code as a Slack code block
|
|
77
|
-
*/
|
|
78
|
-
export declare function formatCodeBlock(code: string, language?: string): string;
|
|
79
38
|
/**
|
|
80
39
|
* Escape Slack mrkdwn characters in text
|
|
81
40
|
*/
|
package/dist/formatting.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,EACL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,cAAc,EACd,KAAK,mBAAmB,EACxB,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AAMvB;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAM7C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUrD;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,GACrB,iBAAiB,CAKnB;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
package/dist/formatting.js
CHANGED
|
@@ -3,9 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides utilities for:
|
|
5
5
|
* - Converting standard markdown to Slack's mrkdwn format
|
|
6
|
-
* - Splitting long messages to fit Slack's practical limit
|
|
7
6
|
* - Creating context attachments with color coding
|
|
7
|
+
*
|
|
8
|
+
* Note: Message splitting utilities (findSplitPoint, splitMessage, needsSplit,
|
|
9
|
+
* truncateMessage, formatCodeBlock) are provided by @herdctl/chat.
|
|
8
10
|
*/
|
|
11
|
+
import { slackifyMarkdown } from "slackify-markdown";
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Re-exports from @herdctl/chat
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Re-export message splitting utilities from @herdctl/chat
|
|
16
|
+
// These are identical between Discord and Slack, just with different max lengths
|
|
17
|
+
export { findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, } from "@herdctl/chat";
|
|
9
18
|
// =============================================================================
|
|
10
19
|
// Constants
|
|
11
20
|
// =============================================================================
|
|
@@ -15,18 +24,9 @@
|
|
|
15
24
|
* Hard limit is ~40K, but messages above ~4K become unwieldy in threads.
|
|
16
25
|
*/
|
|
17
26
|
export const SLACK_MAX_MESSAGE_LENGTH = 4000;
|
|
18
|
-
/**
|
|
19
|
-
* Minimum chunk size when splitting messages
|
|
20
|
-
*/
|
|
21
|
-
export const MIN_CHUNK_SIZE = 100;
|
|
22
|
-
/**
|
|
23
|
-
* Default delay between sending split messages (in milliseconds)
|
|
24
|
-
*/
|
|
25
|
-
export const DEFAULT_MESSAGE_DELAY_MS = 500;
|
|
26
27
|
// =============================================================================
|
|
27
28
|
// Markdown to mrkdwn Conversion
|
|
28
29
|
// =============================================================================
|
|
29
|
-
import { slackifyMarkdown } from "slackify-markdown";
|
|
30
30
|
/**
|
|
31
31
|
* Convert standard markdown to Slack's mrkdwn format
|
|
32
32
|
*
|
|
@@ -44,75 +44,6 @@ export function markdownToMrkdwn(text) {
|
|
|
44
44
|
.trimEnd());
|
|
45
45
|
}
|
|
46
46
|
// =============================================================================
|
|
47
|
-
// Message Splitting
|
|
48
|
-
// =============================================================================
|
|
49
|
-
const DEFAULT_SPLIT_POINTS = ["\n\n", "\n", ". ", "! ", "? ", ", ", " "];
|
|
50
|
-
/**
|
|
51
|
-
* Find the best split point within a text chunk
|
|
52
|
-
*/
|
|
53
|
-
export function findSplitPoint(text, maxLength, splitPoints = DEFAULT_SPLIT_POINTS) {
|
|
54
|
-
if (text.length <= maxLength) {
|
|
55
|
-
return text.length;
|
|
56
|
-
}
|
|
57
|
-
for (const splitPoint of splitPoints) {
|
|
58
|
-
const searchText = text.slice(0, maxLength);
|
|
59
|
-
const lastIndex = searchText.lastIndexOf(splitPoint);
|
|
60
|
-
if (lastIndex > MIN_CHUNK_SIZE) {
|
|
61
|
-
return lastIndex + splitPoint.length;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const hardSplitIndex = text.lastIndexOf(" ", maxLength);
|
|
65
|
-
if (hardSplitIndex > MIN_CHUNK_SIZE) {
|
|
66
|
-
return hardSplitIndex + 1;
|
|
67
|
-
}
|
|
68
|
-
return maxLength;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Split a message into chunks that fit Slack's message length limit
|
|
72
|
-
*/
|
|
73
|
-
export function splitMessage(content, options = {}) {
|
|
74
|
-
const { maxLength = SLACK_MAX_MESSAGE_LENGTH, preserveBoundaries = true, splitPoints = DEFAULT_SPLIT_POINTS, } = options;
|
|
75
|
-
const originalLength = content.length;
|
|
76
|
-
if (content.length <= maxLength) {
|
|
77
|
-
return {
|
|
78
|
-
chunks: [content],
|
|
79
|
-
wasSplit: false,
|
|
80
|
-
originalLength,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const chunks = [];
|
|
84
|
-
let remaining = content;
|
|
85
|
-
while (remaining.length > 0) {
|
|
86
|
-
if (remaining.length <= maxLength) {
|
|
87
|
-
chunks.push(remaining.trim());
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
let splitIndex;
|
|
91
|
-
if (preserveBoundaries) {
|
|
92
|
-
splitIndex = findSplitPoint(remaining, maxLength, splitPoints);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
splitIndex = maxLength;
|
|
96
|
-
}
|
|
97
|
-
const chunk = remaining.slice(0, splitIndex).trim();
|
|
98
|
-
if (chunk.length > 0) {
|
|
99
|
-
chunks.push(chunk);
|
|
100
|
-
}
|
|
101
|
-
remaining = remaining.slice(splitIndex).trim();
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
chunks,
|
|
105
|
-
wasSplit: chunks.length > 1,
|
|
106
|
-
originalLength,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Check if a message needs to be split
|
|
111
|
-
*/
|
|
112
|
-
export function needsSplit(content, maxLength = SLACK_MAX_MESSAGE_LENGTH) {
|
|
113
|
-
return content.length > maxLength;
|
|
114
|
-
}
|
|
115
|
-
// =============================================================================
|
|
116
47
|
// Context Attachments
|
|
117
48
|
// =============================================================================
|
|
118
49
|
/**
|
|
@@ -129,23 +60,6 @@ export function createContextAttachment(contextPercent) {
|
|
|
129
60
|
// =============================================================================
|
|
130
61
|
// Utility Functions
|
|
131
62
|
// =============================================================================
|
|
132
|
-
/**
|
|
133
|
-
* Truncate a message to fit within the max length, adding an ellipsis
|
|
134
|
-
*/
|
|
135
|
-
export function truncateMessage(content, maxLength = SLACK_MAX_MESSAGE_LENGTH, ellipsis = "...") {
|
|
136
|
-
if (content.length <= maxLength) {
|
|
137
|
-
return content;
|
|
138
|
-
}
|
|
139
|
-
const truncatedLength = maxLength - ellipsis.length;
|
|
140
|
-
return content.slice(0, truncatedLength) + ellipsis;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Format code as a Slack code block
|
|
144
|
-
*/
|
|
145
|
-
export function formatCodeBlock(code, language) {
|
|
146
|
-
const langTag = language ?? "";
|
|
147
|
-
return `\`\`\`${langTag}\n${code}\n\`\`\``;
|
|
148
|
-
}
|
|
149
63
|
/**
|
|
150
64
|
* Escape Slack mrkdwn characters in text
|
|
151
65
|
*/
|
package/dist/formatting.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF,2DAA2D;AAC3D,iFAAiF;AACjF,OAAO,EACL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,cAAc,GAGf,MAAM,eAAe,CAAC;AAEvB,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAc7C,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,CACL,gBAAgB,CAAC,IAAI,CAAC;QACpB,sEAAsE;SACrE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;QACvB,uEAAuE;SACtE,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC;SAC1B,OAAO,EAAE,CACb,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,cAAsB;IAEtB,OAAO;QACL,MAAM,EAAE,YAAY,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,aAAa;QAC3D,KAAK,EAAE,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KACnD,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,24 +8,23 @@
|
|
|
8
8
|
* - Single Bolt App shared across all agents (one bot token per workspace)
|
|
9
9
|
* - Channel->agent routing for multi-agent support
|
|
10
10
|
* - Channel-based conversation management
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Session management, message splitting, and other shared utilities
|
|
13
|
+
* are provided by @herdctl/chat - import them from there directly.
|
|
12
14
|
*/
|
|
13
15
|
export declare const VERSION = "0.1.0";
|
|
14
16
|
export { SlackConnector } from "./slack-connector.js";
|
|
17
|
+
export { SlackManager } from "./manager.js";
|
|
15
18
|
export { createSlackLogger, createDefaultSlackLogger, } from "./logger.js";
|
|
16
19
|
export type { SlackLogLevel, SlackLoggerOptions, } from "./logger.js";
|
|
17
|
-
export {
|
|
18
|
-
export type { SlackConnectorOptions, SlackConnectorState, SlackConnectionStatus, SlackConnectorLogger, SlackMessageEvent, SlackErrorEvent, SlackChannelConfig, ISlackConnector, ISlackSessionManager, SlackConnectorEventMap, SlackConnectorEventName, SlackConnectorEventPayload, } from "./types.js";
|
|
19
|
-
export type { SessionManagerOptions, SessionManagerLogger, ISessionManager, SessionResult, ChannelSession, SlackSessionState, } from "./session-manager/index.js";
|
|
20
|
-
export { SlackSessionStateSchema, ChannelSessionSchema, createInitialSessionState, createChannelSession, } from "./session-manager/index.js";
|
|
20
|
+
export type { SlackConnectorOptions, SlackConnectorState, SlackConnectionStatus, SlackConnectorLogger, SlackMessageEvent, SlackErrorEvent, SlackChannelConfig, SlackFileUploadParams, ISlackConnector, SlackConnectorEventMap, SlackConnectorEventName, SlackConnectorEventPayload, } from "./types.js";
|
|
21
21
|
export { SlackErrorCode, SlackConnectorError, SlackConnectionError, AlreadyConnectedError, MissingTokenError, InvalidTokenError, isSlackConnectorError, } from "./errors.js";
|
|
22
|
-
export {
|
|
22
|
+
export { ErrorCategory, classifyError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
|
|
23
23
|
export type { ClassifiedError } from "./error-handler.js";
|
|
24
|
-
export { SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
|
|
25
24
|
export { CommandHandler } from "./commands/index.js";
|
|
26
25
|
export { helpCommand, resetCommand, statusCommand } from "./commands/index.js";
|
|
27
26
|
export type { CommandContext, PrefixCommand, CommandHandlerOptions, } from "./commands/index.js";
|
|
28
27
|
export { isBotMentioned, stripBotMention, stripMentions, shouldProcessMessage, processMessage, } from "./message-handler.js";
|
|
29
|
-
export { SLACK_MAX_MESSAGE_LENGTH,
|
|
28
|
+
export { SLACK_MAX_MESSAGE_LENGTH, markdownToMrkdwn, escapeMrkdwn, createContextAttachment, findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, } from "./formatting.js";
|
|
30
29
|
export type { MessageSplitOptions, SplitResult, ContextAttachment, } from "./formatting.js";
|
|
31
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE/E,YAAY,EACV,cAAc,EACd,aAAa,EACb,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAEL,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EAEvB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,mBAAmB,EACnB,WAAW,EACX,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,27 +8,31 @@
|
|
|
8
8
|
* - Single Bolt App shared across all agents (one bot token per workspace)
|
|
9
9
|
* - Channel->agent routing for multi-agent support
|
|
10
10
|
* - Channel-based conversation management
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Session management, message splitting, and other shared utilities
|
|
13
|
+
* are provided by @herdctl/chat - import them from there directly.
|
|
12
14
|
*/
|
|
13
15
|
export const VERSION = "0.1.0";
|
|
14
16
|
// Main connector class
|
|
15
17
|
export { SlackConnector } from "./slack-connector.js";
|
|
18
|
+
// Manager class (used by FleetManager)
|
|
19
|
+
export { SlackManager } from "./manager.js";
|
|
16
20
|
// Logger
|
|
17
21
|
export { createSlackLogger, createDefaultSlackLogger, } from "./logger.js";
|
|
18
|
-
//
|
|
19
|
-
export { SessionManager } from "./session-manager/index.js";
|
|
20
|
-
export { SlackSessionStateSchema, ChannelSessionSchema, createInitialSessionState, createChannelSession, } from "./session-manager/index.js";
|
|
21
|
-
// Errors
|
|
22
|
+
// Slack-specific errors
|
|
22
23
|
export { SlackErrorCode, SlackConnectorError, SlackConnectionError, AlreadyConnectedError, MissingTokenError, InvalidTokenError, isSlackConnectorError, } from "./errors.js";
|
|
23
|
-
//
|
|
24
|
-
export {
|
|
25
|
-
// Session manager errors
|
|
26
|
-
export { SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
|
|
24
|
+
// Slack-specific error handling (re-exports shared types + Slack classifier)
|
|
25
|
+
export { ErrorCategory, classifyError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
|
|
27
26
|
// Commands
|
|
28
27
|
export { CommandHandler } from "./commands/index.js";
|
|
29
28
|
export { helpCommand, resetCommand, statusCommand } from "./commands/index.js";
|
|
30
29
|
// Message handling
|
|
31
30
|
export { isBotMentioned, stripBotMention, stripMentions, shouldProcessMessage, processMessage, } from "./message-handler.js";
|
|
32
|
-
//
|
|
33
|
-
|
|
31
|
+
// Slack-specific formatting utilities
|
|
32
|
+
// Note: Message splitting functions are re-exported from @herdctl/chat
|
|
33
|
+
export {
|
|
34
|
+
// Slack-specific
|
|
35
|
+
SLACK_MAX_MESSAGE_LENGTH, markdownToMrkdwn, escapeMrkdwn, createContextAttachment,
|
|
36
|
+
// Re-exported from @herdctl/chat
|
|
37
|
+
findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, } from "./formatting.js";
|
|
34
38
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,uBAAuB;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,SAAS;AACT,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAuBrB,wBAAwB;AACxB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,6EAA6E;AAC7E,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAI5B,WAAW;AACX,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQ/E,mBAAmB;AACnB,OAAO,EACL,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,sCAAsC;AACtC,uEAAuE;AACvE,OAAO;AACL,iBAAiB;AACjB,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,uBAAuB;AACvB,iCAAiC;AACjC,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,cAAc,GACf,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack Manager Module
|
|
3
|
+
*
|
|
4
|
+
* Manages Slack connectors for agents that have `chat.slack` configured.
|
|
5
|
+
* This module is responsible for:
|
|
6
|
+
* - Creating one SlackConnector instance per Slack-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 { SlackConnector } from "./slack-connector.js";
|
|
14
|
+
/**
|
|
15
|
+
* SlackManager handles Slack connections for agents
|
|
16
|
+
*
|
|
17
|
+
* This class encapsulates the creation and lifecycle management of
|
|
18
|
+
* SlackConnector instances for agents that have Slack chat configured.
|
|
19
|
+
*
|
|
20
|
+
* Implements IChatManager so FleetManager can interact with it through
|
|
21
|
+
* the generic chat manager interface.
|
|
22
|
+
*/
|
|
23
|
+
export declare class SlackManager implements IChatManager {
|
|
24
|
+
private ctx;
|
|
25
|
+
private connectors;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(ctx: FleetManagerContext);
|
|
28
|
+
/**
|
|
29
|
+
* Initialize Slack connectors for all configured agents
|
|
30
|
+
*
|
|
31
|
+
* This method:
|
|
32
|
+
* 1. Iterates through agents to find those with Slack configured
|
|
33
|
+
* 2. Creates a SlackConnector for each Slack-enabled agent
|
|
34
|
+
*
|
|
35
|
+
* Should be called during FleetManager initialization.
|
|
36
|
+
*/
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Connect all Slack connectors
|
|
40
|
+
*
|
|
41
|
+
* Connects each connector to Slack via Socket Mode 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 Slack 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 SlackConnector instance, or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
getConnector(agentName: string): SlackConnector | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get all connector names
|
|
64
|
+
*
|
|
65
|
+
* @returns Array of agent names that have Slack 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 Slack connector
|
|
80
|
+
*
|
|
81
|
+
* @param agentName - Name of the agent
|
|
82
|
+
* @returns true if the agent has a Slack 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 Slack 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 Slack
|
|
107
|
+
*
|
|
108
|
+
* @param agentName - Name of the agent handling the message
|
|
109
|
+
* @param event - The Slack message event
|
|
110
|
+
*/
|
|
111
|
+
private handleMessage;
|
|
112
|
+
/**
|
|
113
|
+
* Handle errors from Slack connectors
|
|
114
|
+
*
|
|
115
|
+
* Logs errors without crashing the connector
|
|
116
|
+
*
|
|
117
|
+
* @param agentName - Name of the agent that encountered the error
|
|
118
|
+
* @param error - The error that occurred
|
|
119
|
+
*/
|
|
120
|
+
private handleError;
|
|
121
|
+
/** Slack's maximum message length */
|
|
122
|
+
private static readonly MAX_MESSAGE_LENGTH;
|
|
123
|
+
/**
|
|
124
|
+
* Format an error message for Slack display
|
|
125
|
+
*
|
|
126
|
+
* Creates a user-friendly error message with guidance on how to proceed.
|
|
127
|
+
*
|
|
128
|
+
* @param error - The error that occurred
|
|
129
|
+
* @returns Formatted error message string
|
|
130
|
+
*/
|
|
131
|
+
formatErrorMessage(error: Error): string;
|
|
132
|
+
/**
|
|
133
|
+
* Split a response into chunks that fit Slack's 4000 character limit
|
|
134
|
+
*
|
|
135
|
+
* Uses the shared splitMessage utility from @herdctl/chat.
|
|
136
|
+
*
|
|
137
|
+
* @param text - The text to split
|
|
138
|
+
* @returns Array of text chunks, each under 4000 characters
|
|
139
|
+
*/
|
|
140
|
+
splitResponse(text: string): string[];
|
|
141
|
+
/**
|
|
142
|
+
* Send a response to Slack, splitting if necessary
|
|
143
|
+
*
|
|
144
|
+
* @param reply - The reply function from the message event
|
|
145
|
+
* @param content - The content to send
|
|
146
|
+
*/
|
|
147
|
+
sendResponse(reply: (content: string) => Promise<void>, content: string): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Resolve the agent's working directory to an absolute path string
|
|
150
|
+
*
|
|
151
|
+
* @param agent - The resolved agent configuration
|
|
152
|
+
* @returns Absolute path to working directory, or undefined if not configured
|
|
153
|
+
*/
|
|
154
|
+
private resolveWorkingDirectory;
|
|
155
|
+
}
|
|
156
|
+
//# 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,EAK1B,MAAM,eAAe,CAAC;AAavB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAsBtD;;;;;;;;GAQG;AACH,qBAAa,YAAa,YAAW,YAAY;IAInC,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,UAAU,CAA0C;IAC5D,OAAO,CAAC,WAAW,CAAkB;gBAEjB,GAAG,EAAE,mBAAmB;IAE5C;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiGjC;;;;;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,cAAc,GAAG,SAAS;IAI3D;;;;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;;;;;;;;;;;OAWG;YACW,aAAa;IAgM3B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW;IAmBnB,qCAAqC;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAElD;;;;;;;OAOG;IACH,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAIxC;;;;;;;OAOG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAKrC;;;;;OAKG;IACG,YAAY,CAChB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACzC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;CAWhC"}
|