@herdctl/chat 0.0.1 → 0.2.1

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 (90) hide show
  1. package/LICENSE +21 -0
  2. package/dist/__tests__/dm-filter.test.d.ts +5 -0
  3. package/dist/__tests__/dm-filter.test.d.ts.map +1 -0
  4. package/dist/__tests__/dm-filter.test.js +136 -0
  5. package/dist/__tests__/dm-filter.test.js.map +1 -0
  6. package/dist/__tests__/error-handler.test.d.ts +5 -0
  7. package/dist/__tests__/error-handler.test.d.ts.map +1 -0
  8. package/dist/__tests__/error-handler.test.js +235 -0
  9. package/dist/__tests__/error-handler.test.js.map +1 -0
  10. package/dist/__tests__/errors.test.d.ts +5 -0
  11. package/dist/__tests__/errors.test.d.ts.map +1 -0
  12. package/dist/__tests__/errors.test.js +140 -0
  13. package/dist/__tests__/errors.test.js.map +1 -0
  14. package/dist/__tests__/index.test.d.ts +2 -0
  15. package/dist/__tests__/index.test.d.ts.map +1 -0
  16. package/dist/__tests__/index.test.js +25 -0
  17. package/dist/__tests__/index.test.js.map +1 -0
  18. package/dist/__tests__/message-extraction.test.d.ts +5 -0
  19. package/dist/__tests__/message-extraction.test.d.ts.map +1 -0
  20. package/dist/__tests__/message-extraction.test.js +157 -0
  21. package/dist/__tests__/message-extraction.test.js.map +1 -0
  22. package/dist/__tests__/message-splitting.test.d.ts +5 -0
  23. package/dist/__tests__/message-splitting.test.d.ts.map +1 -0
  24. package/dist/__tests__/message-splitting.test.js +153 -0
  25. package/dist/__tests__/message-splitting.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 +779 -0
  29. package/dist/__tests__/session-manager.test.js.map +1 -0
  30. package/dist/__tests__/status-formatting.test.d.ts +5 -0
  31. package/dist/__tests__/status-formatting.test.d.ts.map +1 -0
  32. package/dist/__tests__/status-formatting.test.js +160 -0
  33. package/dist/__tests__/status-formatting.test.js.map +1 -0
  34. package/dist/__tests__/streaming-responder.test.d.ts +5 -0
  35. package/dist/__tests__/streaming-responder.test.d.ts.map +1 -0
  36. package/dist/__tests__/streaming-responder.test.js +154 -0
  37. package/dist/__tests__/streaming-responder.test.js.map +1 -0
  38. package/dist/dm-filter.d.ts +121 -0
  39. package/dist/dm-filter.d.ts.map +1 -0
  40. package/dist/dm-filter.js +162 -0
  41. package/dist/dm-filter.js.map +1 -0
  42. package/dist/error-handler.d.ts +217 -0
  43. package/dist/error-handler.d.ts.map +1 -0
  44. package/dist/error-handler.js +313 -0
  45. package/dist/error-handler.js.map +1 -0
  46. package/dist/errors.d.ts +118 -0
  47. package/dist/errors.d.ts.map +1 -0
  48. package/dist/errors.js +157 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/index.d.ts +22 -0
  51. package/dist/index.d.ts.map +1 -0
  52. package/dist/index.js +69 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/message-extraction.d.ts +81 -0
  55. package/dist/message-extraction.d.ts.map +1 -0
  56. package/dist/message-extraction.js +90 -0
  57. package/dist/message-extraction.js.map +1 -0
  58. package/dist/message-splitting.d.ts +133 -0
  59. package/dist/message-splitting.d.ts.map +1 -0
  60. package/dist/message-splitting.js +188 -0
  61. package/dist/message-splitting.js.map +1 -0
  62. package/dist/session-manager/errors.d.ts +59 -0
  63. package/dist/session-manager/errors.d.ts.map +1 -0
  64. package/dist/session-manager/errors.js +71 -0
  65. package/dist/session-manager/errors.js.map +1 -0
  66. package/dist/session-manager/index.d.ts +10 -0
  67. package/dist/session-manager/index.d.ts.map +1 -0
  68. package/dist/session-manager/index.js +14 -0
  69. package/dist/session-manager/index.js.map +1 -0
  70. package/dist/session-manager/session-manager.d.ts +123 -0
  71. package/dist/session-manager/session-manager.d.ts.map +1 -0
  72. package/dist/session-manager/session-manager.js +394 -0
  73. package/dist/session-manager/session-manager.js.map +1 -0
  74. package/dist/session-manager/types.d.ts +205 -0
  75. package/dist/session-manager/types.d.ts.map +1 -0
  76. package/dist/session-manager/types.js +67 -0
  77. package/dist/session-manager/types.js.map +1 -0
  78. package/dist/status-formatting.d.ts +147 -0
  79. package/dist/status-formatting.d.ts.map +1 -0
  80. package/dist/status-formatting.js +234 -0
  81. package/dist/status-formatting.js.map +1 -0
  82. package/dist/streaming-responder.d.ts +130 -0
  83. package/dist/streaming-responder.d.ts.map +1 -0
  84. package/dist/streaming-responder.js +178 -0
  85. package/dist/streaming-responder.js.map +1 -0
  86. package/dist/types.d.ts +184 -0
  87. package/dist/types.d.ts.map +1 -0
  88. package/dist/types.js +8 -0
  89. package/dist/types.js.map +1 -0
  90. package/package.json +39 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/session-manager/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,mDAAmD;IACnD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,4BAA4B,CAAC;IAE1D,wDAAwD;IACxD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC;QACjC,OAAO,EAAE,mDAAmD;KAC7D,CAAC;CACH,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C;;;;;OAKG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5D,+CAA+C;IAC/C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,4BAA4B,CAAC;IAE1D,wCAAwC;IACxC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC;CACrD,CAAC,CAAC;AA8JH,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,SAAiB;IAEjB,OAAO;QACL,OAAO,EAAE,CAAC;QACV,SAAS;QACT,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,OAAO;QACL,SAAS;QACT,aAAa,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACxC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Status formatting utilities for chat commands
3
+ *
4
+ * Provides common formatting functions used by status commands
5
+ * across all chat platforms. These are identical between Discord
6
+ * and Slack status commands.
7
+ */
8
+ /**
9
+ * Format an ISO timestamp for display
10
+ *
11
+ * Converts an ISO 8601 timestamp to a locale-appropriate string.
12
+ * Returns "N/A" if the timestamp is null or undefined.
13
+ *
14
+ * @param isoString - ISO 8601 timestamp string
15
+ * @returns Formatted date/time string
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * formatTimestamp('2024-01-15T10:30:00Z');
20
+ * // Returns: "1/15/2024, 10:30:00 AM" (locale-dependent)
21
+ *
22
+ * formatTimestamp(null);
23
+ * // Returns: "N/A"
24
+ * ```
25
+ */
26
+ export declare function formatTimestamp(isoString: string | null): string;
27
+ /**
28
+ * Format the duration since a timestamp
29
+ *
30
+ * Calculates and formats the time elapsed since the given timestamp.
31
+ * Returns a human-readable string like "2h 30m" or "5d 12h".
32
+ *
33
+ * @param isoString - ISO 8601 timestamp string (start time)
34
+ * @returns Formatted duration string
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // If current time is 2 hours after the timestamp:
39
+ * formatDuration('2024-01-15T10:30:00Z');
40
+ * // Returns: "2h 0m"
41
+ *
42
+ * formatDuration(null);
43
+ * // Returns: "N/A"
44
+ * ```
45
+ */
46
+ export declare function formatDuration(isoString: string | null): string;
47
+ /**
48
+ * Format a duration in milliseconds to a human-readable string
49
+ *
50
+ * @param ms - Duration in milliseconds
51
+ * @returns Formatted duration string
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * formatDurationMs(500);
56
+ * // Returns: "500ms"
57
+ *
58
+ * formatDurationMs(65000);
59
+ * // Returns: "1m 5s"
60
+ * ```
61
+ */
62
+ export declare function formatDurationMs(ms: number): string;
63
+ /**
64
+ * Get the appropriate emoji for a connection status
65
+ *
66
+ * Returns a circle emoji colored based on the connection state:
67
+ * - Green: connected
68
+ * - Yellow: connecting/reconnecting
69
+ * - White: disconnected/disconnecting
70
+ * - Red: error
71
+ * - Question mark: unknown status
72
+ *
73
+ * @param status - Connection status string
74
+ * @returns Appropriate emoji for the status
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * getStatusEmoji('connected');
79
+ * // Returns: green circle emoji
80
+ *
81
+ * getStatusEmoji('error');
82
+ * // Returns: red circle emoji
83
+ * ```
84
+ */
85
+ export declare function getStatusEmoji(status: string): string;
86
+ /**
87
+ * Format a number with thousand separators
88
+ *
89
+ * @param num - Number to format
90
+ * @returns Formatted string with locale-appropriate separators
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * formatNumber(1234567);
95
+ * // Returns: "1,234,567" (US locale)
96
+ * ```
97
+ */
98
+ export declare function formatNumber(num: number): string;
99
+ /**
100
+ * Format a large number in abbreviated form
101
+ *
102
+ * @param num - Number to format
103
+ * @returns Abbreviated string (e.g., "1.2k", "3.5M")
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * formatCompactNumber(1500);
108
+ * // Returns: "1.5k"
109
+ *
110
+ * formatCompactNumber(2500000);
111
+ * // Returns: "2.5M"
112
+ * ```
113
+ */
114
+ export declare function formatCompactNumber(num: number): string;
115
+ /**
116
+ * Format a character count for display
117
+ *
118
+ * Shows "X chars" for small counts, "X.Xk chars" for larger counts.
119
+ *
120
+ * @param count - Number of characters
121
+ * @returns Formatted character count string
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * formatCharCount(500);
126
+ * // Returns: "500 chars"
127
+ *
128
+ * formatCharCount(15000);
129
+ * // Returns: "15.0k chars"
130
+ * ```
131
+ */
132
+ export declare function formatCharCount(count: number): string;
133
+ /**
134
+ * Format a USD cost amount
135
+ *
136
+ * @param usd - Cost in USD
137
+ * @param precision - Decimal precision (default: 4)
138
+ * @returns Formatted cost string with $ prefix
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * formatCost(0.0123);
143
+ * // Returns: "$0.0123"
144
+ * ```
145
+ */
146
+ export declare function formatCost(usd: number, precision?: number): string;
147
+ //# sourceMappingURL=status-formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-formatting.d.ts","sourceRoot":"","sources":["../src/status-formatting.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAMhE;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAuB/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAWnD;AAuBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAErD;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrD;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,MAAU,GAAG,MAAM,CAErE"}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Status formatting utilities for chat commands
3
+ *
4
+ * Provides common formatting functions used by status commands
5
+ * across all chat platforms. These are identical between Discord
6
+ * and Slack status commands.
7
+ */
8
+ // =============================================================================
9
+ // Timestamp Formatting
10
+ // =============================================================================
11
+ /**
12
+ * Format an ISO timestamp for display
13
+ *
14
+ * Converts an ISO 8601 timestamp to a locale-appropriate string.
15
+ * Returns "N/A" if the timestamp is null or undefined.
16
+ *
17
+ * @param isoString - ISO 8601 timestamp string
18
+ * @returns Formatted date/time string
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * formatTimestamp('2024-01-15T10:30:00Z');
23
+ * // Returns: "1/15/2024, 10:30:00 AM" (locale-dependent)
24
+ *
25
+ * formatTimestamp(null);
26
+ * // Returns: "N/A"
27
+ * ```
28
+ */
29
+ export function formatTimestamp(isoString) {
30
+ if (!isoString) {
31
+ return "N/A";
32
+ }
33
+ const date = new Date(isoString);
34
+ return date.toLocaleString();
35
+ }
36
+ // =============================================================================
37
+ // Duration Formatting
38
+ // =============================================================================
39
+ /**
40
+ * Format the duration since a timestamp
41
+ *
42
+ * Calculates and formats the time elapsed since the given timestamp.
43
+ * Returns a human-readable string like "2h 30m" or "5d 12h".
44
+ *
45
+ * @param isoString - ISO 8601 timestamp string (start time)
46
+ * @returns Formatted duration string
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // If current time is 2 hours after the timestamp:
51
+ * formatDuration('2024-01-15T10:30:00Z');
52
+ * // Returns: "2h 0m"
53
+ *
54
+ * formatDuration(null);
55
+ * // Returns: "N/A"
56
+ * ```
57
+ */
58
+ export function formatDuration(isoString) {
59
+ if (!isoString) {
60
+ return "N/A";
61
+ }
62
+ const startTime = new Date(isoString).getTime();
63
+ const now = Date.now();
64
+ const durationMs = now - startTime;
65
+ const seconds = Math.floor(durationMs / 1000);
66
+ const minutes = Math.floor(seconds / 60);
67
+ const hours = Math.floor(minutes / 60);
68
+ const days = Math.floor(hours / 24);
69
+ if (days > 0) {
70
+ return `${days}d ${hours % 24}h`;
71
+ }
72
+ if (hours > 0) {
73
+ return `${hours}h ${minutes % 60}m`;
74
+ }
75
+ if (minutes > 0) {
76
+ return `${minutes}m ${seconds % 60}s`;
77
+ }
78
+ return `${seconds}s`;
79
+ }
80
+ /**
81
+ * Format a duration in milliseconds to a human-readable string
82
+ *
83
+ * @param ms - Duration in milliseconds
84
+ * @returns Formatted duration string
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * formatDurationMs(500);
89
+ * // Returns: "500ms"
90
+ *
91
+ * formatDurationMs(65000);
92
+ * // Returns: "1m 5s"
93
+ * ```
94
+ */
95
+ export function formatDurationMs(ms) {
96
+ if (ms < 1000) {
97
+ return `${ms}ms`;
98
+ }
99
+ const seconds = Math.floor(ms / 1000);
100
+ if (seconds < 60) {
101
+ return `${seconds}s`;
102
+ }
103
+ const minutes = Math.floor(seconds / 60);
104
+ const remainingSeconds = seconds % 60;
105
+ return remainingSeconds > 0 ? `${minutes}m ${remainingSeconds}s` : `${minutes}m`;
106
+ }
107
+ // =============================================================================
108
+ // Status Emoji
109
+ // =============================================================================
110
+ /**
111
+ * Status emoji mapping
112
+ *
113
+ * Maps connection status to appropriate emoji for display.
114
+ * Uses Unicode code points to avoid rendering issues.
115
+ */
116
+ const STATUS_EMOJIS = {
117
+ connected: "\u{1F7E2}", // Green circle
118
+ connecting: "\u{1F7E1}", // Yellow circle
119
+ reconnecting: "\u{1F7E1}", // Yellow circle
120
+ disconnected: "\u26AA", // White circle
121
+ disconnecting: "\u26AA", // White circle
122
+ error: "\u{1F534}", // Red circle
123
+ };
124
+ const DEFAULT_STATUS_EMOJI = "\u2753"; // Question mark
125
+ /**
126
+ * Get the appropriate emoji for a connection status
127
+ *
128
+ * Returns a circle emoji colored based on the connection state:
129
+ * - Green: connected
130
+ * - Yellow: connecting/reconnecting
131
+ * - White: disconnected/disconnecting
132
+ * - Red: error
133
+ * - Question mark: unknown status
134
+ *
135
+ * @param status - Connection status string
136
+ * @returns Appropriate emoji for the status
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * getStatusEmoji('connected');
141
+ * // Returns: green circle emoji
142
+ *
143
+ * getStatusEmoji('error');
144
+ * // Returns: red circle emoji
145
+ * ```
146
+ */
147
+ export function getStatusEmoji(status) {
148
+ return STATUS_EMOJIS[status] ?? DEFAULT_STATUS_EMOJI;
149
+ }
150
+ // =============================================================================
151
+ // Number Formatting
152
+ // =============================================================================
153
+ /**
154
+ * Format a number with thousand separators
155
+ *
156
+ * @param num - Number to format
157
+ * @returns Formatted string with locale-appropriate separators
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * formatNumber(1234567);
162
+ * // Returns: "1,234,567" (US locale)
163
+ * ```
164
+ */
165
+ export function formatNumber(num) {
166
+ return num.toLocaleString();
167
+ }
168
+ /**
169
+ * Format a large number in abbreviated form
170
+ *
171
+ * @param num - Number to format
172
+ * @returns Abbreviated string (e.g., "1.2k", "3.5M")
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * formatCompactNumber(1500);
177
+ * // Returns: "1.5k"
178
+ *
179
+ * formatCompactNumber(2500000);
180
+ * // Returns: "2.5M"
181
+ * ```
182
+ */
183
+ export function formatCompactNumber(num) {
184
+ if (num >= 1000000) {
185
+ return `${(num / 1000000).toFixed(1)}M`;
186
+ }
187
+ if (num >= 1000) {
188
+ return `${(num / 1000).toFixed(1)}k`;
189
+ }
190
+ return String(num);
191
+ }
192
+ /**
193
+ * Format a character count for display
194
+ *
195
+ * Shows "X chars" for small counts, "X.Xk chars" for larger counts.
196
+ *
197
+ * @param count - Number of characters
198
+ * @returns Formatted character count string
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * formatCharCount(500);
203
+ * // Returns: "500 chars"
204
+ *
205
+ * formatCharCount(15000);
206
+ * // Returns: "15.0k chars"
207
+ * ```
208
+ */
209
+ export function formatCharCount(count) {
210
+ if (count >= 1000) {
211
+ return `${(count / 1000).toFixed(1)}k chars`;
212
+ }
213
+ return `${count} chars`;
214
+ }
215
+ // =============================================================================
216
+ // Cost Formatting
217
+ // =============================================================================
218
+ /**
219
+ * Format a USD cost amount
220
+ *
221
+ * @param usd - Cost in USD
222
+ * @param precision - Decimal precision (default: 4)
223
+ * @returns Formatted cost string with $ prefix
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * formatCost(0.0123);
228
+ * // Returns: "$0.0123"
229
+ * ```
230
+ */
231
+ export function formatCost(usd, precision = 4) {
232
+ return `$${usd.toFixed(precision)}`;
233
+ }
234
+ //# sourceMappingURL=status-formatting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-formatting.js","sourceRoot":"","sources":["../src/status-formatting.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACtD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC;AAC/B,CAAC;AAED,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,SAAwB;IACrD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,IA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AC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IACD,OAAO,GAAG,KAAK,QAAQ,CAAC;AAC1B,CAAC;AAED,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,YAAoB,CAAC;IAC3D,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Streaming Responder for chat platforms
3
+ *
4
+ * Handles incremental message delivery to chat platforms with:
5
+ * - Message buffering
6
+ * - Rate limiting between sends
7
+ * - Automatic message splitting for platform limits
8
+ */
9
+ import type { ChatConnectorLogger } from "./types.js";
10
+ /**
11
+ * Options for StreamingResponder
12
+ */
13
+ export interface StreamingResponderOptions {
14
+ /** Function to send a reply to the chat platform */
15
+ reply: (content: string) => Promise<void>;
16
+ /** Logger for debug output */
17
+ logger: ChatConnectorLogger;
18
+ /** Agent name for logging context */
19
+ agentName: string;
20
+ /**
21
+ * Maximum message length for the platform
22
+ * Discord: 2000, Slack: 4000
23
+ */
24
+ maxMessageLength: number;
25
+ /**
26
+ * Minimum time between messages in ms (default: 1000)
27
+ * Helps avoid rate limiting
28
+ */
29
+ minMessageInterval?: number;
30
+ /**
31
+ * Maximum buffer size before forcing a send (default: platform max - 500)
32
+ * Discord: 1500, Slack: 3500
33
+ */
34
+ maxBufferSize?: number;
35
+ /**
36
+ * Platform name for logging (default: "chat")
37
+ */
38
+ platformName?: string;
39
+ }
40
+ /**
41
+ * StreamingResponder handles incremental message delivery to chat platforms
42
+ *
43
+ * Instead of collecting all output and sending at the end, this class:
44
+ * - Buffers incoming content
45
+ * - Sends messages as complete chunks arrive
46
+ * - Respects rate limits by enforcing minimum intervals between sends
47
+ * - Handles message splitting for content exceeding platform limits
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const streamer = new StreamingResponder({
52
+ * reply: (content) => channel.send(content),
53
+ * logger: myLogger,
54
+ * agentName: 'my-agent',
55
+ * maxMessageLength: 2000, // Discord
56
+ * maxBufferSize: 1500,
57
+ * });
58
+ *
59
+ * // Add content as it arrives
60
+ * await streamer.addContent("Hello ");
61
+ * await streamer.addContent("world!");
62
+ *
63
+ * // Flush any remaining content when done
64
+ * await streamer.flush();
65
+ * ```
66
+ */
67
+ export declare class StreamingResponder {
68
+ private buffer;
69
+ private lastSendTime;
70
+ private messagesSent;
71
+ private readonly reply;
72
+ private readonly logger;
73
+ private readonly agentName;
74
+ private readonly maxMessageLength;
75
+ private readonly minMessageInterval;
76
+ private readonly maxBufferSize;
77
+ private readonly platformName;
78
+ constructor(options: StreamingResponderOptions);
79
+ /**
80
+ * Add content to the buffer
81
+ *
82
+ * Content is accumulated until flush() is called or buffer exceeds maxBufferSize.
83
+ *
84
+ * @param content - Text content to add
85
+ */
86
+ addContent(content: string): void;
87
+ /**
88
+ * Add a complete message and send it immediately (with rate limiting)
89
+ *
90
+ * Use this for complete assistant message turns from the SDK.
91
+ * Each assistant message is a complete response that should be sent.
92
+ *
93
+ * @param content - Complete message content to send
94
+ */
95
+ addMessageAndSend(content: string): Promise<void>;
96
+ /**
97
+ * Flush any remaining content in the buffer
98
+ *
99
+ * Should be called when message processing is complete to ensure
100
+ * all content is sent.
101
+ */
102
+ flush(): Promise<void>;
103
+ /**
104
+ * Check if any messages have been sent
105
+ *
106
+ * @returns true if at least one message has been sent
107
+ */
108
+ hasSentAnything(): boolean;
109
+ /**
110
+ * Alias for hasSentAnything() for backward compatibility
111
+ */
112
+ hasSentMessages(): boolean;
113
+ /**
114
+ * Get the number of messages sent
115
+ */
116
+ getMessagesSent(): number;
117
+ /**
118
+ * Get the current buffer content (for debugging)
119
+ */
120
+ getBufferContent(): string;
121
+ /**
122
+ * Send all buffered content immediately (with rate limiting)
123
+ */
124
+ private sendAll;
125
+ /**
126
+ * Sleep for a given number of milliseconds
127
+ */
128
+ private sleep;
129
+ }
130
+ //# sourceMappingURL=streaming-responder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming-responder.d.ts","sourceRoot":"","sources":["../src/streaming-responder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOtD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,oDAAoD;IACpD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C,8BAA8B;IAC9B,MAAM,EAAE,mBAAmB,CAAC;IAE5B,qCAAqC;IACrC,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,YAAY,CAAa;IAEjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,kB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