agents-library 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of agents-library might be problematic. Click here for more details.
- package/dist/base-agent.d.ts +172 -0
- package/dist/base-agent.d.ts.map +1 -0
- package/dist/base-agent.js +255 -0
- package/dist/base-agent.js.map +1 -0
- package/dist/base-bot.d.ts +282 -0
- package/dist/base-bot.d.ts.map +1 -0
- package/dist/base-bot.js +375 -0
- package/dist/base-bot.js.map +1 -0
- package/dist/common/result.d.ts +51 -0
- package/dist/common/result.d.ts.map +1 -0
- package/dist/common/result.js +45 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/types.d.ts +57 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/types.js +42 -0
- package/dist/common/types.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/kadi-event-publisher.d.ts +163 -0
- package/dist/kadi-event-publisher.d.ts.map +1 -0
- package/dist/kadi-event-publisher.js +286 -0
- package/dist/kadi-event-publisher.js.map +1 -0
- package/dist/memory/arcadedb-adapter.d.ts +159 -0
- package/dist/memory/arcadedb-adapter.d.ts.map +1 -0
- package/dist/memory/arcadedb-adapter.js +314 -0
- package/dist/memory/arcadedb-adapter.js.map +1 -0
- package/dist/memory/file-storage-adapter.d.ts +122 -0
- package/dist/memory/file-storage-adapter.d.ts.map +1 -0
- package/dist/memory/file-storage-adapter.js +352 -0
- package/dist/memory/file-storage-adapter.js.map +1 -0
- package/dist/memory/memory-service.d.ts +208 -0
- package/dist/memory/memory-service.d.ts.map +1 -0
- package/dist/memory/memory-service.js +410 -0
- package/dist/memory/memory-service.js.map +1 -0
- package/dist/memory/types.d.ts +126 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +41 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/producer-tool-utils.d.ts +474 -0
- package/dist/producer-tool-utils.d.ts.map +1 -0
- package/dist/producer-tool-utils.js +664 -0
- package/dist/producer-tool-utils.js.map +1 -0
- package/dist/providers/anthropic-provider.d.ts +160 -0
- package/dist/providers/anthropic-provider.d.ts.map +1 -0
- package/dist/providers/anthropic-provider.js +527 -0
- package/dist/providers/anthropic-provider.js.map +1 -0
- package/dist/providers/model-manager-provider.d.ts +91 -0
- package/dist/providers/model-manager-provider.d.ts.map +1 -0
- package/dist/providers/model-manager-provider.js +355 -0
- package/dist/providers/model-manager-provider.js.map +1 -0
- package/dist/providers/provider-manager.d.ts +111 -0
- package/dist/providers/provider-manager.d.ts.map +1 -0
- package/dist/providers/provider-manager.js +337 -0
- package/dist/providers/provider-manager.js.map +1 -0
- package/dist/providers/types.d.ts +145 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +23 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/shadow-agent-factory.d.ts +623 -0
- package/dist/shadow-agent-factory.d.ts.map +1 -0
- package/dist/shadow-agent-factory.js +1117 -0
- package/dist/shadow-agent-factory.js.map +1 -0
- package/dist/types/agent-config.d.ts +307 -0
- package/dist/types/agent-config.d.ts.map +1 -0
- package/dist/types/agent-config.js +15 -0
- package/dist/types/agent-config.js.map +1 -0
- package/dist/types/event-schemas.d.ts +358 -0
- package/dist/types/event-schemas.d.ts.map +1 -0
- package/dist/types/event-schemas.js +188 -0
- package/dist/types/event-schemas.js.map +1 -0
- package/dist/types/tool-schemas.d.ts +498 -0
- package/dist/types/tool-schemas.d.ts.map +1 -0
- package/dist/types/tool-schemas.js +457 -0
- package/dist/types/tool-schemas.js.map +1 -0
- package/dist/utils/logger.d.ts +135 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +205 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/timer.d.ts +186 -0
- package/dist/utils/timer.d.ts.map +1 -0
- package/dist/utils/timer.js +211 -0
- package/dist/utils/timer.js.map +1 -0
- package/dist/worker-agent-factory.d.ts +688 -0
- package/dist/worker-agent-factory.d.ts.map +1 -0
- package/dist/worker-agent-factory.js +1517 -0
- package/dist/worker-agent-factory.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Type Pattern for Predictable Error Handling
|
|
3
|
+
*
|
|
4
|
+
* Provides a type-safe way to handle success and error cases without throwing exceptions.
|
|
5
|
+
* Inspired by Rust's Result<T, E> type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const result = await someOperation();
|
|
10
|
+
* if (result.success) {
|
|
11
|
+
* console.log(result.data);
|
|
12
|
+
* } else {
|
|
13
|
+
* console.error(result.error);
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Result type representing either success with data or failure with error
|
|
19
|
+
*/
|
|
20
|
+
export type Result<T, E> = {
|
|
21
|
+
success: true;
|
|
22
|
+
data: T;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
error: E;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to create a successful Result
|
|
29
|
+
*
|
|
30
|
+
* @param data - The success data
|
|
31
|
+
* @returns Success Result
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* return ok({ message: 'Success!' });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function ok<T, E = never>(data: T): Result<T, E>;
|
|
39
|
+
/**
|
|
40
|
+
* Helper function to create a failed Result
|
|
41
|
+
*
|
|
42
|
+
* @param error - The error data
|
|
43
|
+
* @returns Error Result
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* return err(new Error('Something went wrong'));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function err<T = never, E = unknown>(error: E): Result<T, E>;
|
|
51
|
+
//# sourceMappingURL=result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/common/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC1B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAEtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAElE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Type Pattern for Predictable Error Handling
|
|
3
|
+
*
|
|
4
|
+
* Provides a type-safe way to handle success and error cases without throwing exceptions.
|
|
5
|
+
* Inspired by Rust's Result<T, E> type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const result = await someOperation();
|
|
10
|
+
* if (result.success) {
|
|
11
|
+
* console.log(result.data);
|
|
12
|
+
* } else {
|
|
13
|
+
* console.error(result.error);
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Helper function to create a successful Result
|
|
19
|
+
*
|
|
20
|
+
* @param data - The success data
|
|
21
|
+
* @returns Success Result
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* return ok({ message: 'Success!' });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function ok(data) {
|
|
29
|
+
return { success: true, data };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Helper function to create a failed Result
|
|
33
|
+
*
|
|
34
|
+
* @param error - The error data
|
|
35
|
+
* @returns Error Result
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* return err(new Error('Something went wrong'));
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function err(error) {
|
|
43
|
+
return { success: false, error };
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/common/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,EAAE,CAAe,IAAO;IACtC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,GAAG,CAAyB,KAAQ;IAClD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions used across the application
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* File error types
|
|
8
|
+
*/
|
|
9
|
+
export declare enum FileErrorType {
|
|
10
|
+
READ_ERROR = "READ_ERROR",
|
|
11
|
+
WRITE_ERROR = "WRITE_ERROR",
|
|
12
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
13
|
+
NOT_FOUND = "NOT_FOUND",
|
|
14
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
15
|
+
UNKNOWN = "UNKNOWN",
|
|
16
|
+
START_SERVER_FAILED = "START_SERVER_FAILED",
|
|
17
|
+
STOP_SERVER_FAILED = "STOP_SERVER_FAILED",
|
|
18
|
+
UPLOAD_FAILED = "UPLOAD_FAILED",
|
|
19
|
+
DOWNLOAD_FAILED = "DOWNLOAD_FAILED",
|
|
20
|
+
LIST_FILES_FAILED = "LIST_FILES_FAILED",
|
|
21
|
+
SHARE_CONTAINER_FAILED = "SHARE_CONTAINER_FAILED",
|
|
22
|
+
STOP_REGISTRY_FAILED = "STOP_REGISTRY_FAILED",
|
|
23
|
+
SSH_UPLOAD_FAILED = "SSH_UPLOAD_FAILED",
|
|
24
|
+
SSH_DOWNLOAD_FAILED = "SSH_DOWNLOAD_FAILED",
|
|
25
|
+
SSH_COMMAND_FAILED = "SSH_COMMAND_FAILED",
|
|
26
|
+
KADI_PROTOCOL_ERROR = "KADI_PROTOCOL_ERROR"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* File operation error
|
|
30
|
+
*/
|
|
31
|
+
export interface FileError {
|
|
32
|
+
type: FileErrorType;
|
|
33
|
+
message: string;
|
|
34
|
+
filePath: string;
|
|
35
|
+
originalError?: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Database error types
|
|
39
|
+
*/
|
|
40
|
+
export declare enum DatabaseErrorType {
|
|
41
|
+
CONNECTION_ERROR = "CONNECTION_ERROR",
|
|
42
|
+
QUERY_ERROR = "QUERY_ERROR",
|
|
43
|
+
AUTH_ERROR = "AUTH_ERROR",
|
|
44
|
+
NOT_CONNECTED = "NOT_CONNECTED",
|
|
45
|
+
TIMEOUT = "TIMEOUT",
|
|
46
|
+
UNKNOWN = "UNKNOWN"
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Database operation error
|
|
50
|
+
*/
|
|
51
|
+
export interface DatabaseError {
|
|
52
|
+
type: DatabaseErrorType;
|
|
53
|
+
message: string;
|
|
54
|
+
query?: string;
|
|
55
|
+
originalError?: unknown;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,oBAAY,aAAa;IACvB,UAAU,eAAe;IACzB,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,iBAAiB,sBAAsB;IACvC,OAAO,YAAY;IAEnB,mBAAmB,wBAAwB;IAC3C,kBAAkB,uBAAuB;IACzC,aAAa,kBAAkB;IAC/B,eAAe,oBAAoB;IACnC,iBAAiB,sBAAsB;IACvC,sBAAsB,2BAA2B;IACjD,oBAAoB,yBAAyB;IAC7C,iBAAiB,sBAAsB;IACvC,mBAAmB,wBAAwB;IAC3C,kBAAkB,uBAAuB;IACzC,mBAAmB,wBAAwB;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,gBAAgB,qBAAqB;IACrC,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common Types
|
|
3
|
+
*
|
|
4
|
+
* Shared type definitions used across the application
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* File error types
|
|
8
|
+
*/
|
|
9
|
+
export var FileErrorType;
|
|
10
|
+
(function (FileErrorType) {
|
|
11
|
+
FileErrorType["READ_ERROR"] = "READ_ERROR";
|
|
12
|
+
FileErrorType["WRITE_ERROR"] = "WRITE_ERROR";
|
|
13
|
+
FileErrorType["PARSE_ERROR"] = "PARSE_ERROR";
|
|
14
|
+
FileErrorType["NOT_FOUND"] = "NOT_FOUND";
|
|
15
|
+
FileErrorType["PERMISSION_DENIED"] = "PERMISSION_DENIED";
|
|
16
|
+
FileErrorType["UNKNOWN"] = "UNKNOWN";
|
|
17
|
+
// File management errors
|
|
18
|
+
FileErrorType["START_SERVER_FAILED"] = "START_SERVER_FAILED";
|
|
19
|
+
FileErrorType["STOP_SERVER_FAILED"] = "STOP_SERVER_FAILED";
|
|
20
|
+
FileErrorType["UPLOAD_FAILED"] = "UPLOAD_FAILED";
|
|
21
|
+
FileErrorType["DOWNLOAD_FAILED"] = "DOWNLOAD_FAILED";
|
|
22
|
+
FileErrorType["LIST_FILES_FAILED"] = "LIST_FILES_FAILED";
|
|
23
|
+
FileErrorType["SHARE_CONTAINER_FAILED"] = "SHARE_CONTAINER_FAILED";
|
|
24
|
+
FileErrorType["STOP_REGISTRY_FAILED"] = "STOP_REGISTRY_FAILED";
|
|
25
|
+
FileErrorType["SSH_UPLOAD_FAILED"] = "SSH_UPLOAD_FAILED";
|
|
26
|
+
FileErrorType["SSH_DOWNLOAD_FAILED"] = "SSH_DOWNLOAD_FAILED";
|
|
27
|
+
FileErrorType["SSH_COMMAND_FAILED"] = "SSH_COMMAND_FAILED";
|
|
28
|
+
FileErrorType["KADI_PROTOCOL_ERROR"] = "KADI_PROTOCOL_ERROR";
|
|
29
|
+
})(FileErrorType || (FileErrorType = {}));
|
|
30
|
+
/**
|
|
31
|
+
* Database error types
|
|
32
|
+
*/
|
|
33
|
+
export var DatabaseErrorType;
|
|
34
|
+
(function (DatabaseErrorType) {
|
|
35
|
+
DatabaseErrorType["CONNECTION_ERROR"] = "CONNECTION_ERROR";
|
|
36
|
+
DatabaseErrorType["QUERY_ERROR"] = "QUERY_ERROR";
|
|
37
|
+
DatabaseErrorType["AUTH_ERROR"] = "AUTH_ERROR";
|
|
38
|
+
DatabaseErrorType["NOT_CONNECTED"] = "NOT_CONNECTED";
|
|
39
|
+
DatabaseErrorType["TIMEOUT"] = "TIMEOUT";
|
|
40
|
+
DatabaseErrorType["UNKNOWN"] = "UNKNOWN";
|
|
41
|
+
})(DatabaseErrorType || (DatabaseErrorType = {}));
|
|
42
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,aAmBX;AAnBD,WAAY,aAAa;IACvB,0CAAyB,CAAA;IACzB,4CAA2B,CAAA;IAC3B,4CAA2B,CAAA;IAC3B,wCAAuB,CAAA;IACvB,wDAAuC,CAAA;IACvC,oCAAmB,CAAA;IACnB,yBAAyB;IACzB,4DAA2C,CAAA;IAC3C,0DAAyC,CAAA;IACzC,gDAA+B,CAAA;IAC/B,oDAAmC,CAAA;IACnC,wDAAuC,CAAA;IACvC,kEAAiD,CAAA;IACjD,8DAA6C,CAAA;IAC7C,wDAAuC,CAAA;IACvC,4DAA2C,CAAA;IAC3C,0DAAyC,CAAA;IACzC,4DAA2C,CAAA;AAC7C,CAAC,EAnBW,aAAa,KAAb,aAAa,QAmBxB;AAYD;;GAEG;AACH,MAAM,CAAN,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,0DAAqC,CAAA;IACrC,gDAA2B,CAAA;IAC3B,8CAAyB,CAAA;IACzB,oDAA+B,CAAA;IAC/B,wCAAmB,CAAA;IACnB,wCAAmB,CAAA;AACrB,CAAC,EAPW,iBAAiB,KAAjB,iBAAiB,QAO5B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agents-library
|
|
3
|
+
* ==============
|
|
4
|
+
*
|
|
5
|
+
* Shared utilities and factories for KĀDI multi-agent orchestration system.
|
|
6
|
+
*
|
|
7
|
+
* This package eliminates code duplication across worker agents, shadow agents,
|
|
8
|
+
* and agent-producer by providing reusable factories, utilities, and type definitions.
|
|
9
|
+
*
|
|
10
|
+
* ## Exports
|
|
11
|
+
*
|
|
12
|
+
* ### Utilities
|
|
13
|
+
* - **BaseBot** - Abstract base class with circuit breaker pattern and retry logic
|
|
14
|
+
* - **KadiEventPublisher** - Event publishing utility for KĀDI broker with connection retry
|
|
15
|
+
* - **validateTopicPattern** - Topic pattern validation for KĀDI broker
|
|
16
|
+
*
|
|
17
|
+
* ### Factories
|
|
18
|
+
* - **WorkerAgentFactory** - Factory for creating worker agents (artist, designer, programmer)
|
|
19
|
+
* - **BaseWorkerAgent** - Base class for worker agents with lifecycle management
|
|
20
|
+
* - **createWorkerAgent** - Convenience function for worker agent creation
|
|
21
|
+
* - **ShadowAgentFactory** - Factory for creating shadow backup agents
|
|
22
|
+
* - **BaseShadowAgent** - Base class for shadow agents with filesystem and git monitoring
|
|
23
|
+
* - **createShadowAgent** - Convenience function for shadow agent creation
|
|
24
|
+
* - **ShadowAgentConfigSchema** - Zod schema for shadow agent configuration validation
|
|
25
|
+
*
|
|
26
|
+
* ### Producer Utilities
|
|
27
|
+
* - **invokeShrimTool** - Invoke shrimp-task-manager tools via KĀDI protocol with retry logic
|
|
28
|
+
* - **orchestrateWithClaude** - Claude API orchestration with tool invocation (Option C pattern)
|
|
29
|
+
* - **publishToolEvent** - Standardized tool event publishing to KĀDI broker
|
|
30
|
+
* - **classifyToolError** - Enhanced error classification for intelligent retry logic
|
|
31
|
+
* - **isToolSuccess** - Type guard for successful tool invocations
|
|
32
|
+
* - **isToolFailure** - Type guard for failed tool invocations
|
|
33
|
+
*
|
|
34
|
+
* ### Types
|
|
35
|
+
*
|
|
36
|
+
* #### Agent Configuration Types
|
|
37
|
+
* - **AgentRole** - Union type for agent roles (artist, designer, programmer)
|
|
38
|
+
* - **WorkerAgentConfig** - Configuration interface for worker agents
|
|
39
|
+
* - **ShadowAgentConfig** - Configuration interface for shadow agents
|
|
40
|
+
* - **WorkerBehaviors** - Custom behavior overrides for worker agents
|
|
41
|
+
* - **PathConfig** - Path configuration for agent worktrees
|
|
42
|
+
* - **NetworkConfig** - Network configuration for KĀDI broker
|
|
43
|
+
*
|
|
44
|
+
* #### Event Schema Types
|
|
45
|
+
* - **TaskAssignedEvent** - Event schema for task assignments
|
|
46
|
+
* - **TaskCompletedEvent** - Event schema for task completions
|
|
47
|
+
* - **TaskFailedEvent** - Event schema for task failures
|
|
48
|
+
* - **TaskRejectedEvent** - Event schema for task rejections (capability mismatch)
|
|
49
|
+
* - **BackupEvent** - Event schema for shadow agent backups
|
|
50
|
+
* - Event validation schemas and type guards
|
|
51
|
+
*
|
|
52
|
+
* #### Tool Schema Types
|
|
53
|
+
* - **ErrorType** - Enum for error classification (transient, permanent)
|
|
54
|
+
* - **ErrorClassification** - Detailed error classification with category and retry info
|
|
55
|
+
* - **ToolSchema** - Tool definition interface for KĀDI tool registration
|
|
56
|
+
* - **ToolInvocationSuccess** - Success result from tool invocation
|
|
57
|
+
* - **ToolInvocationFailure** - Failure result from tool invocation
|
|
58
|
+
* - **ToolInvocationResult** - Discriminated union for tool results
|
|
59
|
+
* - **ToolInvocationParams** - Parameters for tool invocation via KĀDI protocol
|
|
60
|
+
* - Tool validation schemas and type guards
|
|
61
|
+
*
|
|
62
|
+
* #### Producer Utility Types
|
|
63
|
+
* - **InvokeOptions** - Options for invokeShrimTool
|
|
64
|
+
* - **ShrimpToolResult** - Result structure for shrimp tool invocations
|
|
65
|
+
* - **ToolDefinition** - Claude API tool definition
|
|
66
|
+
* - **ToolInvocation** - Record of a tool invocation during orchestration
|
|
67
|
+
* - **OrchestrationOptions** - Options for orchestrateWithClaude
|
|
68
|
+
* - **OrchestrationResult** - Result from orchestrateWithClaude
|
|
69
|
+
* - **EventMetadata** - Metadata for tool event publication
|
|
70
|
+
*
|
|
71
|
+
* @module agents-library
|
|
72
|
+
*/
|
|
73
|
+
export { BaseBot, BaseBotConfig } from './base-bot.js';
|
|
74
|
+
export { BaseAgent, type BaseAgentConfig, type BaseAgentProviderConfig, type BaseAgentMemoryConfig } from './base-agent.js';
|
|
75
|
+
export { KadiEventPublisher, PublisherConfig, validateTopicPattern } from './kadi-event-publisher.js';
|
|
76
|
+
export { logger, MODULE_AGENT, MODULE_SLACK_BOT, MODULE_DISCORD_BOT, MODULE_TASK_HANDLER, MODULE_TOOLS } from './utils/logger.js';
|
|
77
|
+
export { timer, type Timer } from './utils/timer.js';
|
|
78
|
+
export { invokeShrimTool, isToolSuccess, isToolFailure, orchestrateWithClaude, publishToolEvent, type InvokeOptions, type ShrimpToolResult, type ToolDefinition, type ToolInvocation, type OrchestrationOptions, type OrchestrationResult, type EventMetadata } from './producer-tool-utils.js';
|
|
79
|
+
export { BaseWorkerAgent, WorkerAgentFactory, createWorkerAgent } from './worker-agent-factory.js';
|
|
80
|
+
export { BaseShadowAgent, ShadowAgentFactory, ShadowAgentConfigSchema, createShadowAgent } from './shadow-agent-factory.js';
|
|
81
|
+
export { type AgentRole, type WorkerAgentConfig, type ShadowAgentConfig, type WorkerBehaviors, type PathConfig, type NetworkConfig } from './types/agent-config.js';
|
|
82
|
+
export { type TaskAssignedEvent, type TaskCompletedEvent, type TaskFailedEvent, type TaskRejectedEvent, type BackupEvent, TaskAssignedEventSchema, TaskCompletedEventSchema, TaskFailedEventSchema, TaskRejectedEventSchema, BackupEventSchema, isTaskAssignedEvent, isTaskCompletedEvent, isTaskFailedEvent, isTaskRejectedEvent, isBackupEvent, parseTaskAssignedEvent, parseTaskCompletedEvent, parseTaskFailedEvent, parseTaskRejectedEvent, parseBackupEvent } from './types/event-schemas.js';
|
|
83
|
+
export { ErrorType, type ToolSchema, type ToolInvocationSuccess, type ToolInvocationFailure, type ToolInvocationResult, type ToolInvocationParams, type ErrorClassification, ToolInvocationSuccessSchema, ToolInvocationFailureSchema, ToolInvocationResultSchema, ToolInvocationParamsSchema, isToolInvocationSuccess, isToolInvocationFailure, classifyToolError } from './types/tool-schemas.js';
|
|
84
|
+
export { ProviderManager } from './providers/provider-manager.js';
|
|
85
|
+
export { AnthropicProvider } from './providers/anthropic-provider.js';
|
|
86
|
+
export { ModelManagerProvider } from './providers/model-manager-provider.js';
|
|
87
|
+
export * from './providers/types.js';
|
|
88
|
+
export { MemoryService } from './memory/memory-service.js';
|
|
89
|
+
export { FileStorageAdapter } from './memory/file-storage-adapter.js';
|
|
90
|
+
export { ArcadeDBAdapter, ArcadeDBClient } from './memory/arcadedb-adapter.js';
|
|
91
|
+
export { type MemoryType, type MemoryEntry, type ConversationMessage, type ConversationSummary, type UserPreference, type PublicKnowledge, MemoryErrorType, type MemoryError } from './memory/types.js';
|
|
92
|
+
export { type Result, ok, err } from './common/result.js';
|
|
93
|
+
export * from './common/types.js';
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agents-library
|
|
3
|
+
* ==============
|
|
4
|
+
*
|
|
5
|
+
* Shared utilities and factories for KĀDI multi-agent orchestration system.
|
|
6
|
+
*
|
|
7
|
+
* This package eliminates code duplication across worker agents, shadow agents,
|
|
8
|
+
* and agent-producer by providing reusable factories, utilities, and type definitions.
|
|
9
|
+
*
|
|
10
|
+
* ## Exports
|
|
11
|
+
*
|
|
12
|
+
* ### Utilities
|
|
13
|
+
* - **BaseBot** - Abstract base class with circuit breaker pattern and retry logic
|
|
14
|
+
* - **KadiEventPublisher** - Event publishing utility for KĀDI broker with connection retry
|
|
15
|
+
* - **validateTopicPattern** - Topic pattern validation for KĀDI broker
|
|
16
|
+
*
|
|
17
|
+
* ### Factories
|
|
18
|
+
* - **WorkerAgentFactory** - Factory for creating worker agents (artist, designer, programmer)
|
|
19
|
+
* - **BaseWorkerAgent** - Base class for worker agents with lifecycle management
|
|
20
|
+
* - **createWorkerAgent** - Convenience function for worker agent creation
|
|
21
|
+
* - **ShadowAgentFactory** - Factory for creating shadow backup agents
|
|
22
|
+
* - **BaseShadowAgent** - Base class for shadow agents with filesystem and git monitoring
|
|
23
|
+
* - **createShadowAgent** - Convenience function for shadow agent creation
|
|
24
|
+
* - **ShadowAgentConfigSchema** - Zod schema for shadow agent configuration validation
|
|
25
|
+
*
|
|
26
|
+
* ### Producer Utilities
|
|
27
|
+
* - **invokeShrimTool** - Invoke shrimp-task-manager tools via KĀDI protocol with retry logic
|
|
28
|
+
* - **orchestrateWithClaude** - Claude API orchestration with tool invocation (Option C pattern)
|
|
29
|
+
* - **publishToolEvent** - Standardized tool event publishing to KĀDI broker
|
|
30
|
+
* - **classifyToolError** - Enhanced error classification for intelligent retry logic
|
|
31
|
+
* - **isToolSuccess** - Type guard for successful tool invocations
|
|
32
|
+
* - **isToolFailure** - Type guard for failed tool invocations
|
|
33
|
+
*
|
|
34
|
+
* ### Types
|
|
35
|
+
*
|
|
36
|
+
* #### Agent Configuration Types
|
|
37
|
+
* - **AgentRole** - Union type for agent roles (artist, designer, programmer)
|
|
38
|
+
* - **WorkerAgentConfig** - Configuration interface for worker agents
|
|
39
|
+
* - **ShadowAgentConfig** - Configuration interface for shadow agents
|
|
40
|
+
* - **WorkerBehaviors** - Custom behavior overrides for worker agents
|
|
41
|
+
* - **PathConfig** - Path configuration for agent worktrees
|
|
42
|
+
* - **NetworkConfig** - Network configuration for KĀDI broker
|
|
43
|
+
*
|
|
44
|
+
* #### Event Schema Types
|
|
45
|
+
* - **TaskAssignedEvent** - Event schema for task assignments
|
|
46
|
+
* - **TaskCompletedEvent** - Event schema for task completions
|
|
47
|
+
* - **TaskFailedEvent** - Event schema for task failures
|
|
48
|
+
* - **TaskRejectedEvent** - Event schema for task rejections (capability mismatch)
|
|
49
|
+
* - **BackupEvent** - Event schema for shadow agent backups
|
|
50
|
+
* - Event validation schemas and type guards
|
|
51
|
+
*
|
|
52
|
+
* #### Tool Schema Types
|
|
53
|
+
* - **ErrorType** - Enum for error classification (transient, permanent)
|
|
54
|
+
* - **ErrorClassification** - Detailed error classification with category and retry info
|
|
55
|
+
* - **ToolSchema** - Tool definition interface for KĀDI tool registration
|
|
56
|
+
* - **ToolInvocationSuccess** - Success result from tool invocation
|
|
57
|
+
* - **ToolInvocationFailure** - Failure result from tool invocation
|
|
58
|
+
* - **ToolInvocationResult** - Discriminated union for tool results
|
|
59
|
+
* - **ToolInvocationParams** - Parameters for tool invocation via KĀDI protocol
|
|
60
|
+
* - Tool validation schemas and type guards
|
|
61
|
+
*
|
|
62
|
+
* #### Producer Utility Types
|
|
63
|
+
* - **InvokeOptions** - Options for invokeShrimTool
|
|
64
|
+
* - **ShrimpToolResult** - Result structure for shrimp tool invocations
|
|
65
|
+
* - **ToolDefinition** - Claude API tool definition
|
|
66
|
+
* - **ToolInvocation** - Record of a tool invocation during orchestration
|
|
67
|
+
* - **OrchestrationOptions** - Options for orchestrateWithClaude
|
|
68
|
+
* - **OrchestrationResult** - Result from orchestrateWithClaude
|
|
69
|
+
* - **EventMetadata** - Metadata for tool event publication
|
|
70
|
+
*
|
|
71
|
+
* @module agents-library
|
|
72
|
+
*/
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// Utilities
|
|
75
|
+
// ============================================================================
|
|
76
|
+
export { BaseBot } from './base-bot.js';
|
|
77
|
+
export { BaseAgent } from './base-agent.js';
|
|
78
|
+
export { KadiEventPublisher, validateTopicPattern } from './kadi-event-publisher.js';
|
|
79
|
+
export { logger, MODULE_AGENT, MODULE_SLACK_BOT, MODULE_DISCORD_BOT, MODULE_TASK_HANDLER, MODULE_TOOLS } from './utils/logger.js';
|
|
80
|
+
export { timer } from './utils/timer.js';
|
|
81
|
+
export { invokeShrimTool, isToolSuccess, isToolFailure, orchestrateWithClaude, publishToolEvent } from './producer-tool-utils.js';
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Factories
|
|
84
|
+
// ============================================================================
|
|
85
|
+
export { BaseWorkerAgent, WorkerAgentFactory, createWorkerAgent } from './worker-agent-factory.js';
|
|
86
|
+
export { BaseShadowAgent, ShadowAgentFactory, ShadowAgentConfigSchema, createShadowAgent } from './shadow-agent-factory.js';
|
|
87
|
+
export { TaskAssignedEventSchema, TaskCompletedEventSchema, TaskFailedEventSchema, TaskRejectedEventSchema, BackupEventSchema, isTaskAssignedEvent, isTaskCompletedEvent, isTaskFailedEvent, isTaskRejectedEvent, isBackupEvent, parseTaskAssignedEvent, parseTaskCompletedEvent, parseTaskFailedEvent, parseTaskRejectedEvent, parseBackupEvent } from './types/event-schemas.js';
|
|
88
|
+
export { ErrorType, ToolInvocationSuccessSchema, ToolInvocationFailureSchema, ToolInvocationResultSchema, ToolInvocationParamsSchema, isToolInvocationSuccess, isToolInvocationFailure, classifyToolError } from './types/tool-schemas.js';
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Providers
|
|
91
|
+
// ============================================================================
|
|
92
|
+
export { ProviderManager } from './providers/provider-manager.js';
|
|
93
|
+
export { AnthropicProvider } from './providers/anthropic-provider.js';
|
|
94
|
+
export { ModelManagerProvider } from './providers/model-manager-provider.js';
|
|
95
|
+
export * from './providers/types.js';
|
|
96
|
+
// ============================================================================
|
|
97
|
+
// Memory Services
|
|
98
|
+
// ============================================================================
|
|
99
|
+
export { MemoryService } from './memory/memory-service.js';
|
|
100
|
+
export { FileStorageAdapter } from './memory/file-storage-adapter.js';
|
|
101
|
+
export { ArcadeDBAdapter, ArcadeDBClient } from './memory/arcadedb-adapter.js';
|
|
102
|
+
export { MemoryErrorType } from './memory/types.js';
|
|
103
|
+
// ============================================================================
|
|
104
|
+
// Common Utilities
|
|
105
|
+
// ============================================================================
|
|
106
|
+
export { ok, err } from './common/result.js';
|
|
107
|
+
export * from './common/types.js';
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AAEH,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,OAAO,EAAE,OAAO,EAAiB,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAmB,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtG,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClI,OAAO,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;AACrD,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAQjB,MAAM,0BAA0B,CAAC;AAElC,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAenC,OAAO,EAML,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,SAAS,EAOT,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,yBAAyB,CAAC;AAEjC,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,cAAc,sBAAsB,CAAC;AAErC,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAOL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAE3B,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,OAAO,EAAe,EAAE,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC1D,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared KĀDI Event Publisher Utility
|
|
3
|
+
* ====================================
|
|
4
|
+
*
|
|
5
|
+
* Common publisher logic extracted from mcp-client-slack and mcp-client-discord
|
|
6
|
+
* to eliminate code duplication (DRY principle).
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* - Generic event publishing to KĀDI broker
|
|
10
|
+
* - Platform-agnostic connection management
|
|
11
|
+
* - Graceful degradation pattern (stub mode if broker unavailable)
|
|
12
|
+
* - Retry logic with exponential backoff
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const publisher = new KadiEventPublisher({
|
|
17
|
+
* brokerUrl: 'ws://localhost:8080/kadi',
|
|
18
|
+
* clientName: 'mcp-client-slack',
|
|
19
|
+
* networks: ['slack']
|
|
20
|
+
* });
|
|
21
|
+
* await publisher.connect();
|
|
22
|
+
* await publisher.publishEvent('slack.app_mention.U12345', event);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Validates topic pattern against standard format: {platform}.{event_type}.{bot_id}
|
|
27
|
+
*
|
|
28
|
+
* @param topic - Topic string to validate
|
|
29
|
+
* @returns True if topic matches pattern, false otherwise
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* validateTopicPattern('slack.app_mention.U12345') // true
|
|
34
|
+
* validateTopicPattern('discord.mention.67890') // true
|
|
35
|
+
* validateTopicPattern('invalid-topic') // false
|
|
36
|
+
* validateTopicPattern('slack.app_mention') // false (missing bot_id)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateTopicPattern(topic: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration interface for KĀDI Event Publisher
|
|
42
|
+
*/
|
|
43
|
+
export interface PublisherConfig {
|
|
44
|
+
/** KĀDI broker WebSocket URL (e.g., 'ws://localhost:8080/kadi') */
|
|
45
|
+
brokerUrl: string;
|
|
46
|
+
/** Client name for identification in broker logs */
|
|
47
|
+
clientName: string;
|
|
48
|
+
/** Network(s) this publisher belongs to (e.g., ['slack'], ['discord']) */
|
|
49
|
+
networks: string[];
|
|
50
|
+
/** Client version (default: '1.0.0') */
|
|
51
|
+
version?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Shared KĀDI Event Publisher
|
|
55
|
+
*
|
|
56
|
+
* Provides common event publishing functionality for all MCP clients.
|
|
57
|
+
* Handles connection management, retry logic, graceful degradation,
|
|
58
|
+
* and error handling.
|
|
59
|
+
*/
|
|
60
|
+
export declare class KadiEventPublisher {
|
|
61
|
+
private client;
|
|
62
|
+
private enabled;
|
|
63
|
+
private config;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new KĀDI Event Publisher
|
|
66
|
+
*
|
|
67
|
+
* @param config - Publisher configuration with broker URL, client name, and networks
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const publisher = new KadiEventPublisher({
|
|
72
|
+
* brokerUrl: 'ws://localhost:8080/kadi',
|
|
73
|
+
* clientName: 'mcp-client-slack',
|
|
74
|
+
* networks: ['slack']
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
constructor(config: PublisherConfig);
|
|
79
|
+
/**
|
|
80
|
+
* Create a new KadiClient instance
|
|
81
|
+
* Must be called before each connection attempt to avoid handshake state issues
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
private createClient;
|
|
86
|
+
/**
|
|
87
|
+
* Connect to KĀDI broker with retry logic
|
|
88
|
+
*
|
|
89
|
+
* Establishes WebSocket connection and performs authentication handshake.
|
|
90
|
+
* Retries with exponential backoff when broker is not ready (e.g., during startup).
|
|
91
|
+
* Logs connection status for debugging.
|
|
92
|
+
*
|
|
93
|
+
* Retry schedule: 5 attempts with exponential backoff (1s, 2s, 4s, 8s, 16s)
|
|
94
|
+
*
|
|
95
|
+
* @throws {Error} If connection fails after all retries
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* await publisher.connect();
|
|
100
|
+
* console.log('Connected to KĀDI broker');
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
connect(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Publish an event to a specific KĀDI broker topic
|
|
106
|
+
*
|
|
107
|
+
* Generic event publishing method. Accepts any event data and publishes
|
|
108
|
+
* it to the specified topic. Validation should be done by the caller.
|
|
109
|
+
*
|
|
110
|
+
* @param topic - Topic pattern (e.g., 'slack.app_mention.U12345', 'discord.mention.67890')
|
|
111
|
+
* @param event - Event data to publish (must be JSON-serializable)
|
|
112
|
+
* @param metadata - Optional metadata for logging (e.g., { eventId, user, textPreview })
|
|
113
|
+
*
|
|
114
|
+
* @throws {Error} If publish fails (fail-fast, no retry)
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* await publisher.publishEvent(
|
|
119
|
+
* 'slack.app_mention.U12345',
|
|
120
|
+
* {
|
|
121
|
+
* id: '1234567890.123456',
|
|
122
|
+
* user: 'U12345678',
|
|
123
|
+
* text: 'Hello bot!',
|
|
124
|
+
* channel: 'C12345678',
|
|
125
|
+
* bot_id: 'U87654321',
|
|
126
|
+
* timestamp: '2025-11-29T12:00:00Z'
|
|
127
|
+
* },
|
|
128
|
+
* { eventId: '1234567890.123456', user: 'U12345678', textPreview: 'Hello bot!' }
|
|
129
|
+
* );
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
publishEvent(topic: string, event: Record<string, any>, metadata?: {
|
|
133
|
+
eventId?: string;
|
|
134
|
+
user?: string;
|
|
135
|
+
textPreview?: string;
|
|
136
|
+
}): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Disconnect from KĀDI broker
|
|
139
|
+
*
|
|
140
|
+
* Performs cleanup and gracefully closes WebSocket connection.
|
|
141
|
+
* Safe to call multiple times (idempotent).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* await publisher.disconnect();
|
|
146
|
+
* console.log('Disconnected from KĀDI broker');
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
disconnect(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Check if publisher is connected and enabled
|
|
152
|
+
*
|
|
153
|
+
* @returns True if connected to broker and publishing is enabled
|
|
154
|
+
*/
|
|
155
|
+
isConnected(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Get current publisher configuration
|
|
158
|
+
*
|
|
159
|
+
* @returns Current publisher configuration
|
|
160
|
+
*/
|
|
161
|
+
getConfig(): Readonly<Required<PublisherConfig>>;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=kadi-event-publisher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kadi-event-publisher.d.ts","sourceRoot":"","sources":["../src/kadi-event-publisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,SAAS,EAAE,MAAM,CAAC;IAElB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IAEnB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,EAAE,CAAC;IAEnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,MAAM,CAA4B;IAE1C;;;;;;;;;;;;;OAaG;gBACS,MAAM,EAAE,eAAe;IAuBnC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAkCpB;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2C9B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,QAAQ,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACnE,OAAO,CAAC,IAAI,CAAC;IAqChB;;;;;;;;;;;OAWG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBjC;;;;OAIG;IACI,WAAW,IAAI,OAAO;IAI7B;;;;OAIG;IACI,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;CAGxD"}
|