@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":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAN,IAAY,aAmBX;AAnBD,WAAY,aAAa;IACvB,4EAA4E;IAC5E,wCAAuB,CAAA;IACvB,oEAAoE;IACpE,wCAAuB,CAAA;IACvB,uDAAuD;IACvD,0CAAyB,CAAA;IACzB,oCAAoC;IACpC,gDAA+B,CAAA;IAC/B,6CAA6C;IAC7C,8BAAa,CAAA;IACb,kCAAkC;IAClC,oCAAmB,CAAA;IACnB,0BAA0B;IAC1B,4BAAW,CAAA;IACX,iCAAiC;IACjC,sCAAqB,CAAA;IACrB,gCAAgC;IAChC,oCAAmB,CAAA;AACrB,CAAC,EAnBW,aAAa,KAAb,aAAa,QAmBxB;AAsBD,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,+BAA+B;IAC/B,gBAAgB,EACd,0EAA0E;IAC5E,+BAA+B;IAC/B,gBAAgB,EACd,wEAAwE;IAC1E,uBAAuB;IACvB,YAAY,EACV,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G,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtE,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,WAAW,IAAI,mBAAmB,CAAC,gBAAgB,CAAC;YACpE,MAAM,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CACV,+BAAgC,UAAoB,CAAC,OAAO,EAAE,CAC/D,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Shared error classes for chat connectors
3
+ *
4
+ * Provides typed errors for chat connection and operation failures.
5
+ * Platform-specific connectors extend these with their own error codes.
6
+ */
7
+ /**
8
+ * Common error codes for chat connector operations
9
+ *
10
+ * These are shared across all platforms. Platform-specific connectors
11
+ * may have additional error codes.
12
+ */
13
+ export declare enum ChatErrorCode {
14
+ /** Connection to the chat platform failed */
15
+ CONNECTION_FAILED = "CHAT_CONNECTION_FAILED",
16
+ /** Attempting to connect while already connected */
17
+ ALREADY_CONNECTED = "CHAT_ALREADY_CONNECTED",
18
+ /** Bot token is invalid or rejected by the platform */
19
+ INVALID_TOKEN = "CHAT_INVALID_TOKEN",
20
+ /** Required bot token is not provided */
21
+ MISSING_TOKEN = "CHAT_MISSING_TOKEN"
22
+ }
23
+ /**
24
+ * Base error class for chat connector operations
25
+ *
26
+ * All chat-related errors extend this class. It includes:
27
+ * - An error code for programmatic handling
28
+ * - An optional agent name for context
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * try {
33
+ * await connector.connect();
34
+ * } catch (error) {
35
+ * if (isChatConnectorError(error)) {
36
+ * console.log(`Error code: ${error.code}`);
37
+ * console.log(`Agent: ${error.agentName}`);
38
+ * }
39
+ * }
40
+ * ```
41
+ */
42
+ export declare class ChatConnectorError extends Error {
43
+ readonly code: string;
44
+ readonly agentName: string;
45
+ constructor(message: string, code: string, agentName: string, options?: {
46
+ cause?: Error;
47
+ });
48
+ }
49
+ /**
50
+ * Error thrown when connection to the chat platform fails
51
+ */
52
+ export declare class ChatConnectionError extends ChatConnectorError {
53
+ constructor(agentName: string, message: string, options?: {
54
+ cause?: Error;
55
+ });
56
+ }
57
+ /**
58
+ * Error thrown when attempting to connect while already connected
59
+ */
60
+ export declare class AlreadyConnectedError extends ChatConnectorError {
61
+ constructor(agentName: string);
62
+ }
63
+ /**
64
+ * Error thrown when bot token is invalid or rejected
65
+ */
66
+ export declare class InvalidTokenError extends ChatConnectorError {
67
+ constructor(agentName: string, reason: string);
68
+ }
69
+ /**
70
+ * Error thrown when required bot token is not provided
71
+ */
72
+ export declare class MissingTokenError extends ChatConnectorError {
73
+ readonly envVar: string;
74
+ readonly tokenType?: string;
75
+ constructor(agentName: string, envVar: string, tokenType?: string);
76
+ }
77
+ /**
78
+ * Type guard to check if an error is a ChatConnectorError
79
+ *
80
+ * @param error - Error to check
81
+ * @returns true if the error is a ChatConnectorError
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * try {
86
+ * await connector.connect();
87
+ * } catch (error) {
88
+ * if (isChatConnectorError(error)) {
89
+ * switch (error.code) {
90
+ * case ChatErrorCode.ALREADY_CONNECTED:
91
+ * // Already connected, ignore
92
+ * break;
93
+ * case ChatErrorCode.INVALID_TOKEN:
94
+ * // Handle invalid token
95
+ * break;
96
+ * }
97
+ * }
98
+ * }
99
+ * ```
100
+ */
101
+ export declare function isChatConnectorError(error: unknown): error is ChatConnectorError;
102
+ /**
103
+ * Type guard to check if an error is a ChatConnectionError
104
+ */
105
+ export declare function isChatConnectionError(error: unknown): error is ChatConnectionError;
106
+ /**
107
+ * Type guard to check if an error is an AlreadyConnectedError
108
+ */
109
+ export declare function isAlreadyConnectedError(error: unknown): error is AlreadyConnectedError;
110
+ /**
111
+ * Type guard to check if an error is an InvalidTokenError
112
+ */
113
+ export declare function isInvalidTokenError(error: unknown): error is InvalidTokenError;
114
+ /**
115
+ * Type guard to check if an error is a MissingTokenError
116
+ */
117
+ export declare function isMissingTokenError(error: unknown): error is MissingTokenError;
118
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;GAKG;AACH,oBAAY,aAAa;IACvB,6CAA6C;IAC7C,iBAAiB,2BAA2B;IAC5C,oDAAoD;IACpD,iBAAiB,2BAA2B;IAC5C,uDAAuD;IACvD,aAAa,uBAAuB;IACpC,yCAAyC;IACzC,aAAa,uBAAuB;CACrC;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,SAAS,EAAE,MAAM,CAAC;gBAGhC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAO9B;AAMD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,kBAAkB;gBAC7C,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAS5E;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,kBAAkB;gBAC/C,SAAS,EAAE,MAAM;CAQ9B;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,kBAAkB;gBAC3C,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ9C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,kBAAkB;IACvD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEvB,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAWlE;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAE7B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,mBAAmB,CAE9B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,qBAAqB,CAEhC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAE5B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAE5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Shared error classes for chat connectors
3
+ *
4
+ * Provides typed errors for chat connection and operation failures.
5
+ * Platform-specific connectors extend these with their own error codes.
6
+ */
7
+ // =============================================================================
8
+ // Error Codes
9
+ // =============================================================================
10
+ /**
11
+ * Common error codes for chat connector operations
12
+ *
13
+ * These are shared across all platforms. Platform-specific connectors
14
+ * may have additional error codes.
15
+ */
16
+ export var ChatErrorCode;
17
+ (function (ChatErrorCode) {
18
+ /** Connection to the chat platform failed */
19
+ ChatErrorCode["CONNECTION_FAILED"] = "CHAT_CONNECTION_FAILED";
20
+ /** Attempting to connect while already connected */
21
+ ChatErrorCode["ALREADY_CONNECTED"] = "CHAT_ALREADY_CONNECTED";
22
+ /** Bot token is invalid or rejected by the platform */
23
+ ChatErrorCode["INVALID_TOKEN"] = "CHAT_INVALID_TOKEN";
24
+ /** Required bot token is not provided */
25
+ ChatErrorCode["MISSING_TOKEN"] = "CHAT_MISSING_TOKEN";
26
+ })(ChatErrorCode || (ChatErrorCode = {}));
27
+ // =============================================================================
28
+ // Base Error Class
29
+ // =============================================================================
30
+ /**
31
+ * Base error class for chat connector operations
32
+ *
33
+ * All chat-related errors extend this class. It includes:
34
+ * - An error code for programmatic handling
35
+ * - An optional agent name for context
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * try {
40
+ * await connector.connect();
41
+ * } catch (error) {
42
+ * if (isChatConnectorError(error)) {
43
+ * console.log(`Error code: ${error.code}`);
44
+ * console.log(`Agent: ${error.agentName}`);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export class ChatConnectorError extends Error {
50
+ code;
51
+ agentName;
52
+ constructor(message, code, agentName, options) {
53
+ super(message, options);
54
+ this.name = "ChatConnectorError";
55
+ this.code = code;
56
+ this.agentName = agentName;
57
+ }
58
+ }
59
+ // =============================================================================
60
+ // Specific Error Classes
61
+ // =============================================================================
62
+ /**
63
+ * Error thrown when connection to the chat platform fails
64
+ */
65
+ export class ChatConnectionError extends ChatConnectorError {
66
+ constructor(agentName, message, options) {
67
+ super(`Chat connection failed for agent '${agentName}': ${message}`, ChatErrorCode.CONNECTION_FAILED, agentName, options);
68
+ this.name = "ChatConnectionError";
69
+ }
70
+ }
71
+ /**
72
+ * Error thrown when attempting to connect while already connected
73
+ */
74
+ export class AlreadyConnectedError extends ChatConnectorError {
75
+ constructor(agentName) {
76
+ super(`Chat connector for agent '${agentName}' is already connected`, ChatErrorCode.ALREADY_CONNECTED, agentName);
77
+ this.name = "AlreadyConnectedError";
78
+ }
79
+ }
80
+ /**
81
+ * Error thrown when bot token is invalid or rejected
82
+ */
83
+ export class InvalidTokenError extends ChatConnectorError {
84
+ constructor(agentName, reason) {
85
+ super(`Invalid chat token for agent '${agentName}': ${reason}`, ChatErrorCode.INVALID_TOKEN, agentName);
86
+ this.name = "InvalidTokenError";
87
+ }
88
+ }
89
+ /**
90
+ * Error thrown when required bot token is not provided
91
+ */
92
+ export class MissingTokenError extends ChatConnectorError {
93
+ envVar;
94
+ tokenType;
95
+ constructor(agentName, envVar, tokenType) {
96
+ const tokenDesc = tokenType ? `${tokenType} token` : "token";
97
+ super(`Missing chat ${tokenDesc} for agent '${agentName}': environment variable '${envVar}' is not set`, ChatErrorCode.MISSING_TOKEN, agentName);
98
+ this.name = "MissingTokenError";
99
+ this.envVar = envVar;
100
+ this.tokenType = tokenType;
101
+ }
102
+ }
103
+ // =============================================================================
104
+ // Type Guards
105
+ // =============================================================================
106
+ /**
107
+ * Type guard to check if an error is a ChatConnectorError
108
+ *
109
+ * @param error - Error to check
110
+ * @returns true if the error is a ChatConnectorError
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * try {
115
+ * await connector.connect();
116
+ * } catch (error) {
117
+ * if (isChatConnectorError(error)) {
118
+ * switch (error.code) {
119
+ * case ChatErrorCode.ALREADY_CONNECTED:
120
+ * // Already connected, ignore
121
+ * break;
122
+ * case ChatErrorCode.INVALID_TOKEN:
123
+ * // Handle invalid token
124
+ * break;
125
+ * }
126
+ * }
127
+ * }
128
+ * ```
129
+ */
130
+ export function isChatConnectorError(error) {
131
+ return error instanceof ChatConnectorError;
132
+ }
133
+ /**
134
+ * Type guard to check if an error is a ChatConnectionError
135
+ */
136
+ export function isChatConnectionError(error) {
137
+ return error instanceof ChatConnectionError;
138
+ }
139
+ /**
140
+ * Type guard to check if an error is an AlreadyConnectedError
141
+ */
142
+ export function isAlreadyConnectedError(error) {
143
+ return error instanceof AlreadyConnectedError;
144
+ }
145
+ /**
146
+ * Type guard to check if an error is an InvalidTokenError
147
+ */
148
+ export function isInvalidTokenError(error) {
149
+ return error instanceof InvalidTokenError;
150
+ }
151
+ /**
152
+ * Type guard to check if an error is a MissingTokenError
153
+ */
154
+ export function isMissingTokenError(error) {
155
+ return error instanceof MissingTokenError;
156
+ }
157
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,6CAA6C;IAC7C,6DAA4C,CAAA;IAC5C,oDAAoD;IACpD,6DAA4C,CAAA;IAC5C,uDAAuD;IACvD,qDAAoC,CAAA;IACpC,yCAAyC;IACzC,qDAAoC,CAAA;AACtC,CAAC,EATW,aAAa,KAAb,aAAa,QASxB;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3B,IAAI,CAAS;IACb,SAAS,CAAS;IAElC,YACE,OAAe,EACf,IAAY,EACZ,SAAiB,EACjB,OAA2B;QAE3B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,gFAAgF;AAChF,yBAAyB;AACzB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,YAAY,SAAiB,EAAE,OAAe,EAAE,OAA2B;QACzE,KAAK,CACH,qCAAqC,SAAS,MAAM,OAAO,EAAE,EAC7D,aAAa,CAAC,iBAAiB,EAC/B,SAAS,EACT,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC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C;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,KAAc;IAEd,OAAO,KAAK,YAAY,qBAAqB,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,OAAO,KAAK,YAAY,iBAAiB,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAc;IAEd,OAAO,KAAK,YAAY,iBAAiB,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @herdctl/chat - Shared chat infrastructure for herdctl connectors
3
+ *
4
+ * This package provides shared components for chat platform integrations:
5
+ * - Session manager for conversation context preservation
6
+ * - Message splitting utilities
7
+ * - Streaming responder
8
+ * - Message content extraction
9
+ * - DM filtering
10
+ * - Error handling utilities
11
+ * - Status formatting
12
+ */
13
+ export { ChatSessionManager, ChannelSessionSchema, ChatSessionStateSchema, type ChannelSession, type ChatSessionState, type SessionManagerLogger, type ChatSessionManagerOptions, type SessionResult, type IChatSessionManager, createInitialSessionState, createChannelSession, SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
14
+ export { type ChatConnectionStatus, type ChatConnectorState, type IChatConnector, type IChatSessionManager as IChatConnectorSessionManager, type ChatConnectorLogger, type ChatMessageMetadata, type ChatMessageEvent, type SessionLifecycleEvent, type ChatConnectorEventMap, type ChatConnectorEventName, type ChatConnectorEventPayload, } from "./types.js";
15
+ export { findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock, type MessageSplitOptions, type SplitResult, DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, DEFAULT_SPLIT_POINTS, } from "./message-splitting.js";
16
+ export { StreamingResponder, type StreamingResponderOptions, } from "./streaming-responder.js";
17
+ export { extractMessageContent, isTextContentBlock, hasTextContent, type TextContentBlock, type ContentBlock, type SDKMessage, } from "./message-extraction.js";
18
+ export { isDMEnabled, getDMMode, checkDMUserFilter, shouldProcessInMode, type DMFilterResult, type DMConfig, } from "./dm-filter.js";
19
+ export { ChatErrorCode, ChatConnectorError, ChatConnectionError, AlreadyConnectedError, InvalidTokenError, MissingTokenError, isChatConnectorError, isChatConnectionError, isAlreadyConnectedError, isInvalidTokenError, isMissingTokenError, } from "./errors.js";
20
+ export { ErrorCategory, type ClassifiedError, type RetryOptions, type RetryResult, type UserErrorMessageKey, USER_ERROR_MESSAGES, withRetry, isTransientError, isRateLimitError, isAuthError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
21
+ export { formatTimestamp, formatDuration, formatDurationMs, getStatusEmoji, formatNumber, formatCompactNumber, formatCharCount, formatCost, } from "./status-formatting.js";
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EAEL,kBAAkB,EAElB,oBAAoB,EACpB,sBAAsB,EAEtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAExB,yBAAyB,EACzB,oBAAoB,EAEpB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,kBAAkB,EAEvB,KAAK,cAAc,EACnB,KAAK,mBAAmB,IAAI,4BAA4B,EACxD,KAAK,mBAAmB,EAExB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAErB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,GAC/B,MAAM,YAAY,CAAC;AAMpB,OAAO,EAEL,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe,EAEf,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAEhB,wBAAwB,EACxB,cAAc,EACd,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EACL,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,cAAc,EACnB,KAAK,QAAQ,GACd,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAEL,aAAa,EAEb,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAEjB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAEL,aAAa,EAEb,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAExB,mBAAmB,EAEnB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,UAAU,GACX,MAAM,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @herdctl/chat - Shared chat infrastructure for herdctl connectors
3
+ *
4
+ * This package provides shared components for chat platform integrations:
5
+ * - Session manager for conversation context preservation
6
+ * - Message splitting utilities
7
+ * - Streaming responder
8
+ * - Message content extraction
9
+ * - DM filtering
10
+ * - Error handling utilities
11
+ * - Status formatting
12
+ */
13
+ // =============================================================================
14
+ // Session Manager
15
+ // =============================================================================
16
+ export {
17
+ // Class
18
+ ChatSessionManager,
19
+ // Schemas
20
+ ChannelSessionSchema, ChatSessionStateSchema,
21
+ // Factory functions
22
+ createInitialSessionState, createChannelSession,
23
+ // Errors
24
+ SessionErrorCode, SessionManagerError, SessionStateReadError, SessionStateWriteError, SessionDirectoryCreateError, isSessionManagerError, } from "./session-manager/index.js";
25
+ // =============================================================================
26
+ // Message Splitting
27
+ // =============================================================================
28
+ export {
29
+ // Functions
30
+ findSplitPoint, splitMessage, needsSplit, truncateMessage, formatCodeBlock,
31
+ // Constants
32
+ DEFAULT_MESSAGE_DELAY_MS, MIN_CHUNK_SIZE, DEFAULT_SPLIT_POINTS, } from "./message-splitting.js";
33
+ // =============================================================================
34
+ // Streaming Responder
35
+ // =============================================================================
36
+ export { StreamingResponder, } from "./streaming-responder.js";
37
+ // =============================================================================
38
+ // Message Extraction
39
+ // =============================================================================
40
+ export { extractMessageContent, isTextContentBlock, hasTextContent, } from "./message-extraction.js";
41
+ // =============================================================================
42
+ // DM Filtering
43
+ // =============================================================================
44
+ export { isDMEnabled, getDMMode, checkDMUserFilter, shouldProcessInMode, } from "./dm-filter.js";
45
+ // =============================================================================
46
+ // Errors
47
+ // =============================================================================
48
+ export {
49
+ // Error codes
50
+ ChatErrorCode,
51
+ // Error classes
52
+ ChatConnectorError, ChatConnectionError, AlreadyConnectedError, InvalidTokenError, MissingTokenError,
53
+ // Type guards
54
+ isChatConnectorError, isChatConnectionError, isAlreadyConnectedError, isInvalidTokenError, isMissingTokenError, } from "./errors.js";
55
+ // =============================================================================
56
+ // Error Handler
57
+ // =============================================================================
58
+ export {
59
+ // Categories
60
+ ErrorCategory,
61
+ // Constants
62
+ USER_ERROR_MESSAGES,
63
+ // Functions
64
+ withRetry, isTransientError, isRateLimitError, isAuthError, safeExecute, safeExecuteWithReply, } from "./error-handler.js";
65
+ // =============================================================================
66
+ // Status Formatting
67
+ // =============================================================================
68
+ export { formatTimestamp, formatDuration, formatDurationMs, getStatusEmoji, formatNumber, formatCompactNumber, formatCharCount, formatCost, } from "./status-formatting.js";
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF,OAAO;AACL,QAAQ;AACR,kBAAkB;AAClB,UAAU;AACV,oBAAoB,EACpB,sBAAsB;AAQtB,oBAAoB;AACpB,yBAAyB,EACzB,oBAAoB;AACpB,SAAS;AACT,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAyBpC,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,OAAO;AACL,YAAY;AACZ,cAAc,EACd,YAAY,EACZ,UAAU,EACV,eAAe,EACf,eAAe;AAIf,YAAY;AACZ,wBAAwB,EACxB,cAAc,EACd,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,OAAO,EACL,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC;AAElC,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,GAIf,MAAM,yBAAyB,CAAC;AAEjC,gFAAgF;AAChF,eAAe;AACf,gFAAgF;AAEhF,OAAO,EACL,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,mBAAmB,GAGpB,MAAM,gBAAgB,CAAC;AAExB,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,OAAO;AACL,cAAc;AACd,aAAa;AACb,gBAAgB;AAChB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB;AACjB,cAAc;AACd,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,OAAO;AACL,aAAa;AACb,aAAa;AAMb,YAAY;AACZ,mBAAmB;AACnB,YAAY;AACZ,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAE5B,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,UAAU,GACX,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Message content extraction utilities
3
+ *
4
+ * Extracts text content from Claude SDK assistant messages.
5
+ * This is 100% identical between Discord and Slack managers.
6
+ */
7
+ /**
8
+ * Content block with type and text
9
+ *
10
+ * Represents a text content block from the Claude SDK.
11
+ * We define a minimal type here to avoid depending on the full Anthropic SDK.
12
+ */
13
+ export interface TextContentBlock {
14
+ type: "text";
15
+ text: string;
16
+ }
17
+ /**
18
+ * Any content block from the SDK
19
+ */
20
+ export interface ContentBlock {
21
+ type: string;
22
+ [key: string]: unknown;
23
+ }
24
+ /**
25
+ * SDK message structure
26
+ *
27
+ * Represents the structure of messages from the Claude Agent SDK.
28
+ */
29
+ export interface SDKMessage {
30
+ type: string;
31
+ content?: string;
32
+ message?: {
33
+ content?: string | ContentBlock[];
34
+ };
35
+ }
36
+ /**
37
+ * Extract text content from an SDK assistant message
38
+ *
39
+ * Handles various message formats from the Claude Agent SDK:
40
+ * - Direct string content in message.content
41
+ * - Nested string content in message.message.content
42
+ * - Array of content blocks with text type
43
+ *
44
+ * @param message - SDK message object
45
+ * @returns Extracted text content, or undefined if no text found
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Direct content
50
+ * extractMessageContent({ type: 'assistant', content: 'Hello!' });
51
+ * // Returns: 'Hello!'
52
+ *
53
+ * // Array of content blocks
54
+ * extractMessageContent({
55
+ * type: 'assistant',
56
+ * message: {
57
+ * content: [
58
+ * { type: 'text', text: 'Hello ' },
59
+ * { type: 'text', text: 'world!' }
60
+ * ]
61
+ * }
62
+ * });
63
+ * // Returns: 'Hello world!'
64
+ * ```
65
+ */
66
+ export declare function extractMessageContent(message: SDKMessage): string | undefined;
67
+ /**
68
+ * Type guard for text content blocks
69
+ *
70
+ * @param block - Content block to check
71
+ * @returns true if the block is a text content block
72
+ */
73
+ export declare function isTextContentBlock(block: unknown): block is TextContentBlock;
74
+ /**
75
+ * Check if a message has extractable text content
76
+ *
77
+ * @param message - SDK message object
78
+ * @returns true if the message contains text content
79
+ */
80
+ export declare function hasTextContent(message: SDKMessage): boolean;
81
+ //# sourceMappingURL=message-extraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-extraction.d.ts","sourceRoot":"","sources":["../src/message-extraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;KACnC,CAAC;CACH;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CA+B7E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAS5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Message content extraction utilities
3
+ *
4
+ * Extracts text content from Claude SDK assistant messages.
5
+ * This is 100% identical between Discord and Slack managers.
6
+ */
7
+ // =============================================================================
8
+ // Extraction Functions
9
+ // =============================================================================
10
+ /**
11
+ * Extract text content from an SDK assistant message
12
+ *
13
+ * Handles various message formats from the Claude Agent SDK:
14
+ * - Direct string content in message.content
15
+ * - Nested string content in message.message.content
16
+ * - Array of content blocks with text type
17
+ *
18
+ * @param message - SDK message object
19
+ * @returns Extracted text content, or undefined if no text found
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Direct content
24
+ * extractMessageContent({ type: 'assistant', content: 'Hello!' });
25
+ * // Returns: 'Hello!'
26
+ *
27
+ * // Array of content blocks
28
+ * extractMessageContent({
29
+ * type: 'assistant',
30
+ * message: {
31
+ * content: [
32
+ * { type: 'text', text: 'Hello ' },
33
+ * { type: 'text', text: 'world!' }
34
+ * ]
35
+ * }
36
+ * });
37
+ * // Returns: 'Hello world!'
38
+ * ```
39
+ */
40
+ export function extractMessageContent(message) {
41
+ // Check for direct content
42
+ if (typeof message.content === "string" && message.content) {
43
+ return message.content;
44
+ }
45
+ // Check for nested message content (SDK structure)
46
+ const apiMessage = message.message;
47
+ const content = apiMessage?.content;
48
+ if (!content) {
49
+ return undefined;
50
+ }
51
+ // If it's a string, return directly
52
+ if (typeof content === "string") {
53
+ return content;
54
+ }
55
+ // If it's an array of content blocks, extract text
56
+ if (Array.isArray(content)) {
57
+ const textParts = [];
58
+ for (const block of content) {
59
+ if (isTextContentBlock(block)) {
60
+ textParts.push(block.text);
61
+ }
62
+ }
63
+ return textParts.length > 0 ? textParts.join("") : undefined;
64
+ }
65
+ return undefined;
66
+ }
67
+ /**
68
+ * Type guard for text content blocks
69
+ *
70
+ * @param block - Content block to check
71
+ * @returns true if the block is a text content block
72
+ */
73
+ export function isTextContentBlock(block) {
74
+ return (block !== null &&
75
+ typeof block === "object" &&
76
+ "type" in block &&
77
+ block.type === "text" &&
78
+ "text" in block &&
79
+ typeof block.text === "string");
80
+ }
81
+ /**
82
+ * Check if a message has extractable text content
83
+ *
84
+ * @param message - SDK message object
85
+ * @returns true if the message contains text content
86
+ */
87
+ export function hasTextContent(message) {
88
+ return extractMessageContent(message) !== undefined;
89
+ }
90
+ //# sourceMappingURL=message-extraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-extraction.js","sourceRoot":"","sources":["../src/message-extraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsCH,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAmB;IACvD,2BAA2B;IAC3B,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3D,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IAED,mDAAmD;IACnD,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IACnC,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,CAAC;IAEpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oCAAoC;IACpC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,mDAAmD;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B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