@herdctl/slack 0.0.1 → 0.2.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.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/dist/__tests__/command-handler.test.d.ts +2 -0
  3. package/dist/__tests__/command-handler.test.d.ts.map +1 -0
  4. package/dist/__tests__/command-handler.test.js +141 -0
  5. package/dist/__tests__/command-handler.test.js.map +1 -0
  6. package/dist/__tests__/error-handler.test.d.ts +2 -0
  7. package/dist/__tests__/error-handler.test.d.ts.map +1 -0
  8. package/dist/__tests__/error-handler.test.js +168 -0
  9. package/dist/__tests__/error-handler.test.js.map +1 -0
  10. package/dist/__tests__/errors.test.d.ts +2 -0
  11. package/dist/__tests__/errors.test.d.ts.map +1 -0
  12. package/dist/__tests__/errors.test.js +133 -0
  13. package/dist/__tests__/errors.test.js.map +1 -0
  14. package/dist/__tests__/formatting.test.d.ts +2 -0
  15. package/dist/__tests__/formatting.test.d.ts.map +1 -0
  16. package/dist/__tests__/formatting.test.js +216 -0
  17. package/dist/__tests__/formatting.test.js.map +1 -0
  18. package/dist/__tests__/logger.test.d.ts +2 -0
  19. package/dist/__tests__/logger.test.d.ts.map +1 -0
  20. package/dist/__tests__/logger.test.js +97 -0
  21. package/dist/__tests__/logger.test.js.map +1 -0
  22. package/dist/__tests__/message-handler.test.d.ts +2 -0
  23. package/dist/__tests__/message-handler.test.d.ts.map +1 -0
  24. package/dist/__tests__/message-handler.test.js +78 -0
  25. package/dist/__tests__/message-handler.test.js.map +1 -0
  26. package/dist/__tests__/session-manager.test.d.ts +2 -0
  27. package/dist/__tests__/session-manager.test.d.ts.map +1 -0
  28. package/dist/__tests__/session-manager.test.js +214 -0
  29. package/dist/__tests__/session-manager.test.js.map +1 -0
  30. package/dist/__tests__/slack-connector.test.d.ts +2 -0
  31. package/dist/__tests__/slack-connector.test.d.ts.map +1 -0
  32. package/dist/__tests__/slack-connector.test.js +376 -0
  33. package/dist/__tests__/slack-connector.test.js.map +1 -0
  34. package/dist/commands/command-handler.d.ts +72 -0
  35. package/dist/commands/command-handler.d.ts.map +1 -0
  36. package/dist/commands/command-handler.js +85 -0
  37. package/dist/commands/command-handler.js.map +1 -0
  38. package/dist/commands/help.d.ts +6 -0
  39. package/dist/commands/help.d.ts.map +1 -0
  40. package/dist/commands/help.js +22 -0
  41. package/dist/commands/help.js.map +1 -0
  42. package/dist/commands/index.d.ts +11 -0
  43. package/dist/commands/index.d.ts.map +1 -0
  44. package/dist/commands/index.js +10 -0
  45. package/dist/commands/index.js.map +1 -0
  46. package/dist/commands/reset.d.ts +6 -0
  47. package/dist/commands/reset.d.ts.map +1 -0
  48. package/dist/commands/reset.js +18 -0
  49. package/dist/commands/reset.js.map +1 -0
  50. package/dist/commands/status.d.ts +6 -0
  51. package/dist/commands/status.d.ts.map +1 -0
  52. package/dist/commands/status.js +94 -0
  53. package/dist/commands/status.js.map +1 -0
  54. package/dist/error-handler.d.ts +50 -0
  55. package/dist/error-handler.d.ts.map +1 -0
  56. package/dist/error-handler.js +123 -0
  57. package/dist/error-handler.js.map +1 -0
  58. package/dist/errors.d.ts +59 -0
  59. package/dist/errors.d.ts.map +1 -0
  60. package/dist/errors.js +73 -0
  61. package/dist/errors.js.map +1 -0
  62. package/dist/formatting.d.ts +83 -0
  63. package/dist/formatting.d.ts.map +1 -0
  64. package/dist/formatting.js +155 -0
  65. package/dist/formatting.js.map +1 -0
  66. package/dist/index.d.ts +31 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +34 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/logger.d.ts +28 -0
  71. package/dist/logger.d.ts.map +1 -0
  72. package/dist/logger.js +40 -0
  73. package/dist/logger.js.map +1 -0
  74. package/dist/message-handler.d.ts +62 -0
  75. package/dist/message-handler.d.ts.map +1 -0
  76. package/dist/message-handler.js +85 -0
  77. package/dist/message-handler.js.map +1 -0
  78. package/dist/session-manager/errors.d.ts +58 -0
  79. package/dist/session-manager/errors.d.ts.map +1 -0
  80. package/dist/session-manager/errors.js +70 -0
  81. package/dist/session-manager/errors.js.map +1 -0
  82. package/dist/session-manager/index.d.ts +9 -0
  83. package/dist/session-manager/index.d.ts.map +1 -0
  84. package/dist/session-manager/index.js +13 -0
  85. package/dist/session-manager/index.js.map +1 -0
  86. package/dist/session-manager/session-manager.d.ts +62 -0
  87. package/dist/session-manager/session-manager.d.ts.map +1 -0
  88. package/dist/session-manager/session-manager.js +325 -0
  89. package/dist/session-manager/session-manager.js.map +1 -0
  90. package/dist/session-manager/types.d.ts +154 -0
  91. package/dist/session-manager/types.d.ts.map +1 -0
  92. package/dist/session-manager/types.js +57 -0
  93. package/dist/session-manager/types.js.map +1 -0
  94. package/dist/slack-connector.d.ts +53 -0
  95. package/dist/slack-connector.d.ts.map +1 -0
  96. package/dist/slack-connector.js +447 -0
  97. package/dist/slack-connector.js.map +1 -0
  98. package/dist/types.d.ts +211 -0
  99. package/dist/types.d.ts.map +1 -0
  100. package/dist/types.js +8 -0
  101. package/dist/types.js.map +1 -0
  102. package/package.json +42 -4
package/dist/errors.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Error classes for the Slack connector
3
+ *
4
+ * Provides typed errors for Slack connection and message handling failures.
5
+ */
6
+ /**
7
+ * Error codes for Slack connector operations
8
+ */
9
+ export var SlackErrorCode;
10
+ (function (SlackErrorCode) {
11
+ SlackErrorCode["CONNECTION_FAILED"] = "SLACK_CONNECTION_FAILED";
12
+ SlackErrorCode["ALREADY_CONNECTED"] = "SLACK_ALREADY_CONNECTED";
13
+ SlackErrorCode["MISSING_TOKEN"] = "SLACK_MISSING_TOKEN";
14
+ SlackErrorCode["INVALID_TOKEN"] = "SLACK_INVALID_TOKEN";
15
+ SlackErrorCode["MESSAGE_SEND_FAILED"] = "SLACK_MESSAGE_SEND_FAILED";
16
+ SlackErrorCode["SOCKET_MODE_ERROR"] = "SLACK_SOCKET_MODE_ERROR";
17
+ })(SlackErrorCode || (SlackErrorCode = {}));
18
+ /**
19
+ * Base error class for Slack connector operations
20
+ */
21
+ export class SlackConnectorError extends Error {
22
+ code;
23
+ constructor(message, code, options) {
24
+ super(message, options);
25
+ this.name = "SlackConnectorError";
26
+ this.code = code;
27
+ }
28
+ }
29
+ /**
30
+ * Error thrown when connection to Slack fails
31
+ */
32
+ export class SlackConnectionError extends SlackConnectorError {
33
+ constructor(message, options) {
34
+ super(message, SlackErrorCode.CONNECTION_FAILED, options);
35
+ this.name = "SlackConnectionError";
36
+ }
37
+ }
38
+ /**
39
+ * Error thrown when attempting to connect while already connected
40
+ */
41
+ export class AlreadyConnectedError extends SlackConnectorError {
42
+ constructor() {
43
+ super("Slack connector is already connected", SlackErrorCode.ALREADY_CONNECTED);
44
+ this.name = "AlreadyConnectedError";
45
+ }
46
+ }
47
+ /**
48
+ * Error thrown when bot or app token is missing
49
+ */
50
+ export class MissingTokenError extends SlackConnectorError {
51
+ tokenType;
52
+ constructor(tokenType, envVar) {
53
+ super(`Slack ${tokenType} token not found in environment variable '${envVar}'`, SlackErrorCode.MISSING_TOKEN);
54
+ this.name = "MissingTokenError";
55
+ this.tokenType = tokenType;
56
+ }
57
+ }
58
+ /**
59
+ * Error thrown when a token is invalid
60
+ */
61
+ export class InvalidTokenError extends SlackConnectorError {
62
+ constructor(message, options) {
63
+ super(message, SlackErrorCode.INVALID_TOKEN, options);
64
+ this.name = "InvalidTokenError";
65
+ }
66
+ }
67
+ /**
68
+ * Type guard to check if an error is a SlackConnectorError
69
+ */
70
+ export function isSlackConnectorError(error) {
71
+ return error instanceof SlackConnectorError;
72
+ }
73
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACxB,+DAA6C,CAAA;IAC7C,+DAA6C,CAAA;IAC7C,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AAC,CAAC;QACtD,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAc;IAEd,OAAO,KAAK,YAAY,mBAAmB,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Message formatting utilities for Slack
3
+ *
4
+ * Provides utilities for:
5
+ * - Converting standard markdown to Slack's mrkdwn format
6
+ * - Splitting long messages to fit Slack's practical limit
7
+ * - Creating context attachments with color coding
8
+ */
9
+ /**
10
+ * Slack's practical maximum message length
11
+ *
12
+ * Hard limit is ~40K, but messages above ~4K become unwieldy in threads.
13
+ */
14
+ 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
+ /**
40
+ * Context attachment for Slack messages
41
+ */
42
+ export interface ContextAttachment {
43
+ footer: string;
44
+ color: string;
45
+ }
46
+ /**
47
+ * Convert standard markdown to Slack's mrkdwn format
48
+ *
49
+ * Uses slackify-markdown (Unified/Remark-based AST parser) for robust
50
+ * conversion that handles edge cases regex approaches miss.
51
+ */
52
+ 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
+ /**
66
+ * Create a context attachment for Slack messages
67
+ *
68
+ * Used to display context usage information in a color-coded footer.
69
+ */
70
+ 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
+ /**
80
+ * Escape Slack mrkdwn characters in text
81
+ */
82
+ export declare function escapeMrkdwn(text: string): string;
83
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC;;GAEG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAM5C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAQD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUrD;AAQD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,WAAW,GAAE,MAAM,EAAyB,GAC3C,MAAM,CAoBR;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,mBAAwB,GAChC,WAAW,CA8Cb;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAiC,GAC3C,OAAO,CAET;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,MAAM,GACrB,iBAAiB,CAKnB;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAiC,EAC5C,QAAQ,GAAE,MAAc,GACvB,MAAM,CAOR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Message formatting utilities for Slack
3
+ *
4
+ * Provides utilities for:
5
+ * - Converting standard markdown to Slack's mrkdwn format
6
+ * - Splitting long messages to fit Slack's practical limit
7
+ * - Creating context attachments with color coding
8
+ */
9
+ // =============================================================================
10
+ // Constants
11
+ // =============================================================================
12
+ /**
13
+ * Slack's practical maximum message length
14
+ *
15
+ * Hard limit is ~40K, but messages above ~4K become unwieldy in threads.
16
+ */
17
+ 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
+ // Markdown to mrkdwn Conversion
28
+ // =============================================================================
29
+ import { slackifyMarkdown } from "slackify-markdown";
30
+ /**
31
+ * Convert standard markdown to Slack's mrkdwn format
32
+ *
33
+ * Uses slackify-markdown (Unified/Remark-based AST parser) for robust
34
+ * conversion that handles edge cases regex approaches miss.
35
+ */
36
+ export function markdownToMrkdwn(text) {
37
+ if (!text)
38
+ return text;
39
+ return (slackifyMarkdown(text)
40
+ // Strip zero-width spaces — Slack's mrkdwn parser doesn't handle them
41
+ .replace(/\u200B/g, "")
42
+ // Replace *** horizontal rules (Slack shows them as literal asterisks)
43
+ .replace(/^\*\*\*$/gm, "⸻")
44
+ .trimEnd());
45
+ }
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
+ // Context Attachments
117
+ // =============================================================================
118
+ /**
119
+ * Create a context attachment for Slack messages
120
+ *
121
+ * Used to display context usage information in a color-coded footer.
122
+ */
123
+ export function createContextAttachment(contextPercent) {
124
+ return {
125
+ footer: `Context: ${Math.round(contextPercent)}% remaining`,
126
+ color: contextPercent < 20 ? "#ff0000" : "#36a64f",
127
+ };
128
+ }
129
+ // =============================================================================
130
+ // Utility Functions
131
+ // =============================================================================
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
+ /**
150
+ * Escape Slack mrkdwn characters in text
151
+ */
152
+ export function escapeMrkdwn(text) {
153
+ return text.replace(/([*_~`|\\<>])/g, "\\$1");
154
+ }
155
+ //# sourceMappingURL=formatting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.js","sourceRoot":"","sources":["../src/formatting.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAgC5C,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;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,oBAAoB;AACpB,gFAAgF;AAEhF,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,SAAiB,EACjB,cAAwB,oBAAoB;IAE5C,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CA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,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,QAAiB;IAC7D,MAAM,OAAO,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC/B,OAAO,SAAS,OAAO,KAAK,IAAI,UAAU,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @herdctl/slack
3
+ *
4
+ * Slack connector for herdctl — Autonomous Agent Fleet Management for Claude Code
5
+ *
6
+ * This package provides:
7
+ * - SlackConnector class for connecting agents to Slack via Socket Mode
8
+ * - Single Bolt App shared across all agents (one bot token per workspace)
9
+ * - Channel->agent routing for multi-agent support
10
+ * - Channel-based conversation management
11
+ * - SessionManager for per-channel conversation context
12
+ */
13
+ export declare const VERSION = "0.1.0";
14
+ export { SlackConnector } from "./slack-connector.js";
15
+ export { createSlackLogger, createDefaultSlackLogger, } from "./logger.js";
16
+ export type { SlackLogLevel, SlackLoggerOptions, } from "./logger.js";
17
+ export { SessionManager } from "./session-manager/index.js";
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";
21
+ export { SlackErrorCode, SlackConnectorError, SlackConnectionError, AlreadyConnectedError, MissingTokenError, InvalidTokenError, isSlackConnectorError, } from "./errors.js";
22
+ export { USER_ERROR_MESSAGES, ErrorCategory, classifyError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
23
+ export type { ClassifiedError } from "./error-handler.js";
24
+ export { SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
25
+ export { CommandHandler } from "./commands/index.js";
26
+ export { helpCommand, resetCommand, statusCommand } from "./commands/index.js";
27
+ export type { CommandContext, PrefixCommand, CommandHandlerOptions, } from "./commands/index.js";
28
+ export { isBotMentioned, stripBotMention, stripMentions, shouldProcessMessage, processMessage, } from "./message-handler.js";
29
+ export { SLACK_MAX_MESSAGE_LENGTH, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, escapeMrkdwn, markdownToMrkdwn, createContextAttachment, } from "./formatting.js";
30
+ export type { MessageSplitOptions, SplitResult, ContextAttachment, } from "./formatting.js";
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,aAAa,EACb,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,cAAc,EACd,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAGpC,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;AAG9B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,mBAAmB,EACnB,WAAW,EACX,iBAAiB,GAClB,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @herdctl/slack
3
+ *
4
+ * Slack connector for herdctl — Autonomous Agent Fleet Management for Claude Code
5
+ *
6
+ * This package provides:
7
+ * - SlackConnector class for connecting agents to Slack via Socket Mode
8
+ * - Single Bolt App shared across all agents (one bot token per workspace)
9
+ * - Channel->agent routing for multi-agent support
10
+ * - Channel-based conversation management
11
+ * - SessionManager for per-channel conversation context
12
+ */
13
+ export const VERSION = "0.1.0";
14
+ // Main connector class
15
+ export { SlackConnector } from "./slack-connector.js";
16
+ // Logger
17
+ export { createSlackLogger, createDefaultSlackLogger, } from "./logger.js";
18
+ // Session manager
19
+ export { SessionManager } from "./session-manager/index.js";
20
+ export { SlackSessionStateSchema, ChannelSessionSchema, createInitialSessionState, createChannelSession, } from "./session-manager/index.js";
21
+ // Errors
22
+ export { SlackErrorCode, SlackConnectorError, SlackConnectionError, AlreadyConnectedError, MissingTokenError, InvalidTokenError, isSlackConnectorError, } from "./errors.js";
23
+ // Error handling utilities
24
+ export { USER_ERROR_MESSAGES, ErrorCategory, classifyError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
25
+ // Session manager errors
26
+ export { SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
27
+ // Commands
28
+ export { CommandHandler } from "./commands/index.js";
29
+ export { helpCommand, resetCommand, statusCommand } from "./commands/index.js";
30
+ // Message handling
31
+ export { isBotMentioned, stripBotMention, stripMentions, shouldProcessMessage, processMessage, } from "./message-handler.js";
32
+ // Formatting utilities
33
+ export { SLACK_MAX_MESSAGE_LENGTH, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, escapeMrkdwn, markdownToMrkdwn, createContextAttachment, } from "./formatting.js";
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,uBAAuB;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,SAAS;AACT,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAOrB,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AA4B5D,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAEpC,SAAS;AACT,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,2BAA2B;AAC3B,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAI5B,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,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,uBAAuB;AACvB,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Logger utilities for the Slack connector
3
+ *
4
+ * Provides configurable logging with level-based filtering.
5
+ */
6
+ import type { SlackConnectorLogger } from "./types.js";
7
+ /**
8
+ * Log level for Slack connector operations
9
+ */
10
+ export type SlackLogLevel = "minimal" | "standard" | "verbose";
11
+ /**
12
+ * Options for creating a Slack logger
13
+ */
14
+ export interface SlackLoggerOptions {
15
+ /** Prefix for log messages */
16
+ prefix: string;
17
+ /** Log level */
18
+ logLevel?: SlackLogLevel;
19
+ }
20
+ /**
21
+ * Create a logger with the specified configuration
22
+ */
23
+ export declare function createSlackLogger(options: SlackLoggerOptions): SlackConnectorLogger;
24
+ /**
25
+ * Create a default logger for Slack operations
26
+ */
27
+ export declare function createDefaultSlackLogger(agentName?: string): SlackConnectorLogger;
28
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMvD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IAEf,gBAAgB;IAChB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,oBAAoB,CAqBtB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,CAAC,EAAE,MAAM,GACjB,oBAAoB,CAGtB"}
package/dist/logger.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Logger utilities for the Slack connector
3
+ *
4
+ * Provides configurable logging with level-based filtering.
5
+ */
6
+ // =============================================================================
7
+ // Logger Factory
8
+ // =============================================================================
9
+ /**
10
+ * Create a logger with the specified configuration
11
+ */
12
+ export function createSlackLogger(options) {
13
+ const { prefix, logLevel = "standard" } = options;
14
+ return {
15
+ debug: (msg, data) => {
16
+ if (logLevel === "verbose") {
17
+ console.debug(`${prefix} ${msg}`, data ? JSON.stringify(data) : "");
18
+ }
19
+ },
20
+ info: (msg, data) => {
21
+ if (logLevel !== "minimal") {
22
+ console.info(`${prefix} ${msg}`, data ? JSON.stringify(data) : "");
23
+ }
24
+ },
25
+ warn: (msg, data) => {
26
+ console.warn(`${prefix} ${msg}`, data ? JSON.stringify(data) : "");
27
+ },
28
+ error: (msg, data) => {
29
+ console.error(`${prefix} ${msg}`, data ? JSON.stringify(data) : "");
30
+ },
31
+ };
32
+ }
33
+ /**
34
+ * Create a default logger for Slack operations
35
+ */
36
+ export function createDefaultSlackLogger(agentName) {
37
+ const prefix = agentName ? `[slack:${agentName}]` : "[slack]";
38
+ return createSlackLogger({ prefix });
39
+ }
40
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAA2B;IAE3B,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAElD,OAAO;QACL,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE;YACrD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE;YACpD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE;YACpD,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE;YACrD,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAkB;IAElB,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9D,OAAO,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Message handling utilities for Slack
3
+ *
4
+ * Provides utilities for:
5
+ * - Detecting bot mentions in messages
6
+ * - Stripping bot mention from message text
7
+ * - Determining if a message should be processed
8
+ */
9
+ /**
10
+ * Check if the bot was mentioned in a message
11
+ *
12
+ * Slack format for mentions: <@U1234567890>
13
+ *
14
+ * @param text - Message text
15
+ * @param botUserId - Bot's user ID
16
+ * @returns true if the bot was mentioned
17
+ */
18
+ export declare function isBotMentioned(text: string, botUserId: string): boolean;
19
+ /**
20
+ * Strip the bot mention from message text
21
+ *
22
+ * Removes <@BOTID> and trims whitespace.
23
+ *
24
+ * @param text - Message text
25
+ * @param botUserId - Bot's user ID
26
+ * @returns Cleaned message text
27
+ */
28
+ export declare function stripBotMention(text: string, botUserId: string): string;
29
+ /**
30
+ * Strip all user mentions from message text
31
+ *
32
+ * @param text - Message text
33
+ * @returns Text with all mentions removed
34
+ */
35
+ export declare function stripMentions(text: string): string;
36
+ /**
37
+ * Determine if a message should be processed
38
+ *
39
+ * Rules:
40
+ * - Ignore messages from bots
41
+ * - Process app_mention events (always a mention)
42
+ * - Process thread replies in active conversation threads
43
+ *
44
+ * @param event - Slack event data
45
+ * @param botUserId - Bot's user ID
46
+ * @returns true if the message should be processed
47
+ */
48
+ export declare function shouldProcessMessage(event: {
49
+ bot_id?: string;
50
+ subtype?: string;
51
+ user?: string;
52
+ thread_ts?: string;
53
+ }, botUserId: string): boolean;
54
+ /**
55
+ * Process a message event and extract the prompt
56
+ *
57
+ * @param text - Raw message text
58
+ * @param botUserId - Bot's user ID
59
+ * @returns Processed prompt text
60
+ */
61
+ export declare function processMessage(text: string, botUserId: string): string;
62
+ //# sourceMappingURL=message-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-handler.d.ts","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,EACD,SAAS,EAAE,MAAM,GAChB,OAAO,CAYT;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAQtE"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Message handling utilities for Slack
3
+ *
4
+ * Provides utilities for:
5
+ * - Detecting bot mentions in messages
6
+ * - Stripping bot mention from message text
7
+ * - Determining if a message should be processed
8
+ */
9
+ // =============================================================================
10
+ // Mention Detection
11
+ // =============================================================================
12
+ /**
13
+ * Check if the bot was mentioned in a message
14
+ *
15
+ * Slack format for mentions: <@U1234567890>
16
+ *
17
+ * @param text - Message text
18
+ * @param botUserId - Bot's user ID
19
+ * @returns true if the bot was mentioned
20
+ */
21
+ export function isBotMentioned(text, botUserId) {
22
+ return text.includes(`<@${botUserId}>`);
23
+ }
24
+ /**
25
+ * Strip the bot mention from message text
26
+ *
27
+ * Removes <@BOTID> and trims whitespace.
28
+ *
29
+ * @param text - Message text
30
+ * @param botUserId - Bot's user ID
31
+ * @returns Cleaned message text
32
+ */
33
+ export function stripBotMention(text, botUserId) {
34
+ return text.replace(new RegExp(`<@${botUserId}>`, "g"), "").trim();
35
+ }
36
+ /**
37
+ * Strip all user mentions from message text
38
+ *
39
+ * @param text - Message text
40
+ * @returns Text with all mentions removed
41
+ */
42
+ export function stripMentions(text) {
43
+ return text.replace(/<@[A-Z0-9]+>/g, "").trim();
44
+ }
45
+ // =============================================================================
46
+ // Message Processing
47
+ // =============================================================================
48
+ /**
49
+ * Determine if a message should be processed
50
+ *
51
+ * Rules:
52
+ * - Ignore messages from bots
53
+ * - Process app_mention events (always a mention)
54
+ * - Process thread replies in active conversation threads
55
+ *
56
+ * @param event - Slack event data
57
+ * @param botUserId - Bot's user ID
58
+ * @returns true if the message should be processed
59
+ */
60
+ export function shouldProcessMessage(event, botUserId) {
61
+ // Ignore bot messages
62
+ if (event.bot_id || event.subtype === "bot_message") {
63
+ return false;
64
+ }
65
+ // Ignore messages from the bot itself
66
+ if (event.user === botUserId) {
67
+ return false;
68
+ }
69
+ return true;
70
+ }
71
+ /**
72
+ * Process a message event and extract the prompt
73
+ *
74
+ * @param text - Raw message text
75
+ * @param botUserId - Bot's user ID
76
+ * @returns Processed prompt text
77
+ */
78
+ export function processMessage(text, botUserId) {
79
+ // Strip the bot mention if present
80
+ let prompt = stripBotMention(text, botUserId);
81
+ // Trim whitespace
82
+ prompt = prompt.trim();
83
+ return prompt;
84
+ }
85
+ //# sourceMappingURL=message-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-handler.js","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,SAAiB;IAC5D,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,SAAiB;IAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,KAAK,SAAS,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAClD,CAAC;AAED,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAKC,EACD,SAAiB;IAEjB,sBAAsB;IACtB,IAAI,KAAK,CAAC,MAAM,IAAI,K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