@kadi.build/core 0.0.1-alpha.1 → 0.0.1-alpha.10

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 (179) hide show
  1. package/README.md +1387 -214
  2. package/dist/abilities/AbilityCache.d.ts +242 -0
  3. package/dist/abilities/AbilityCache.d.ts.map +1 -0
  4. package/dist/abilities/AbilityCache.js +285 -0
  5. package/dist/abilities/AbilityCache.js.map +1 -0
  6. package/dist/abilities/AbilityContext.d.ts +215 -0
  7. package/dist/abilities/AbilityContext.d.ts.map +1 -0
  8. package/dist/abilities/AbilityContext.js +36 -0
  9. package/dist/abilities/AbilityContext.js.map +1 -0
  10. package/dist/abilities/AbilityLoader.d.ts +177 -0
  11. package/dist/abilities/AbilityLoader.d.ts.map +1 -0
  12. package/dist/abilities/AbilityLoader.js +277 -0
  13. package/dist/abilities/AbilityLoader.js.map +1 -0
  14. package/dist/abilities/AbilityProxy.d.ts +463 -0
  15. package/dist/abilities/AbilityProxy.d.ts.map +1 -0
  16. package/dist/abilities/AbilityProxy.js +511 -0
  17. package/dist/abilities/AbilityProxy.js.map +1 -0
  18. package/dist/abilities/AbilityValidator.d.ts +172 -0
  19. package/dist/abilities/AbilityValidator.d.ts.map +1 -0
  20. package/dist/abilities/AbilityValidator.js +253 -0
  21. package/dist/abilities/AbilityValidator.js.map +1 -0
  22. package/dist/abilities/index.d.ts +26 -0
  23. package/dist/abilities/index.d.ts.map +1 -0
  24. package/dist/abilities/index.js +23 -0
  25. package/dist/abilities/index.js.map +1 -0
  26. package/dist/abilities/types.d.ts +156 -0
  27. package/dist/abilities/types.d.ts.map +1 -0
  28. package/dist/abilities/types.js +10 -0
  29. package/dist/abilities/types.js.map +1 -0
  30. package/dist/api/index.d.ts +92 -0
  31. package/dist/api/index.d.ts.map +1 -0
  32. package/dist/api/index.js +124 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/broker/BrokerConnection.d.ts +253 -0
  35. package/dist/broker/BrokerConnection.d.ts.map +1 -0
  36. package/dist/broker/BrokerConnection.js +434 -0
  37. package/dist/broker/BrokerConnection.js.map +1 -0
  38. package/dist/broker/BrokerConnectionManager.d.ts +216 -0
  39. package/dist/broker/BrokerConnectionManager.d.ts.map +1 -0
  40. package/dist/broker/BrokerConnectionManager.js +305 -0
  41. package/dist/broker/BrokerConnectionManager.js.map +1 -0
  42. package/dist/broker/BrokerProtocol.d.ts +280 -0
  43. package/dist/broker/BrokerProtocol.d.ts.map +1 -0
  44. package/dist/broker/BrokerProtocol.js +466 -0
  45. package/dist/broker/BrokerProtocol.js.map +1 -0
  46. package/dist/broker/index.d.ts +9 -0
  47. package/dist/broker/index.d.ts.map +1 -0
  48. package/dist/broker/index.js +9 -0
  49. package/dist/broker/index.js.map +1 -0
  50. package/dist/client/KadiClient.d.ts +270 -0
  51. package/dist/client/KadiClient.d.ts.map +1 -0
  52. package/dist/client/KadiClient.js +492 -0
  53. package/dist/client/KadiClient.js.map +1 -0
  54. package/dist/client/index.d.ts +7 -0
  55. package/dist/client/index.d.ts.map +1 -0
  56. package/dist/client/index.js +7 -0
  57. package/dist/client/index.js.map +1 -0
  58. package/dist/config/ConfigLoader.d.ts +138 -0
  59. package/dist/config/ConfigLoader.d.ts.map +1 -0
  60. package/dist/config/ConfigLoader.js +226 -0
  61. package/dist/config/ConfigLoader.js.map +1 -0
  62. package/dist/config/ConfigResolver.d.ts +135 -0
  63. package/dist/config/ConfigResolver.d.ts.map +1 -0
  64. package/dist/config/ConfigResolver.js +282 -0
  65. package/dist/config/ConfigResolver.js.map +1 -0
  66. package/dist/config/index.d.ts +8 -0
  67. package/dist/config/index.d.ts.map +1 -0
  68. package/dist/config/index.js +8 -0
  69. package/dist/config/index.js.map +1 -0
  70. package/dist/errors/index.d.ts +9 -0
  71. package/dist/errors/index.d.ts.map +1 -0
  72. package/dist/errors/index.js +8 -0
  73. package/dist/errors/index.js.map +1 -0
  74. package/dist/events/EventHub.d.ts +172 -0
  75. package/dist/events/EventHub.d.ts.map +1 -0
  76. package/dist/events/EventHub.js +333 -0
  77. package/dist/events/EventHub.js.map +1 -0
  78. package/dist/events/index.d.ts +7 -0
  79. package/dist/events/index.d.ts.map +1 -0
  80. package/dist/events/index.js +7 -0
  81. package/dist/events/index.js.map +1 -0
  82. package/dist/index.d.ts +49 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +63 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/messages/index.d.ts +33 -0
  87. package/dist/messages/index.d.ts.map +1 -0
  88. package/dist/messages/index.js +33 -0
  89. package/dist/messages/index.js.map +1 -0
  90. package/dist/schemas/index.d.ts +19 -0
  91. package/dist/schemas/index.d.ts.map +1 -0
  92. package/dist/schemas/index.js +25 -0
  93. package/dist/schemas/index.js.map +1 -0
  94. package/dist/schemas/kadi-extensions.d.ts +231 -0
  95. package/dist/schemas/kadi-extensions.d.ts.map +1 -0
  96. package/dist/schemas/kadi-extensions.js +14 -0
  97. package/dist/schemas/kadi-extensions.js.map +1 -0
  98. package/dist/schemas/mcp/schema.d.ts +1399 -0
  99. package/dist/schemas/mcp/schema.d.ts.map +1 -0
  100. package/dist/schemas/mcp/schema.js +53 -0
  101. package/dist/schemas/mcp/schema.js.map +1 -0
  102. package/dist/schemas/mcp/version.d.ts +37 -0
  103. package/dist/schemas/mcp/version.d.ts.map +1 -0
  104. package/dist/schemas/mcp/version.js +39 -0
  105. package/dist/schemas/mcp/version.js.map +1 -0
  106. package/dist/schemas/schema-builders.d.ts +178 -0
  107. package/dist/schemas/schema-builders.d.ts.map +1 -0
  108. package/dist/schemas/schema-builders.js +258 -0
  109. package/dist/schemas/schema-builders.js.map +1 -0
  110. package/dist/tools/ToolRegistry.d.ts +256 -0
  111. package/dist/tools/ToolRegistry.d.ts.map +1 -0
  112. package/dist/tools/ToolRegistry.js +340 -0
  113. package/dist/tools/ToolRegistry.js.map +1 -0
  114. package/dist/tools/index.d.ts +7 -0
  115. package/dist/tools/index.d.ts.map +1 -0
  116. package/dist/tools/index.js +7 -0
  117. package/dist/tools/index.js.map +1 -0
  118. package/dist/transports/BrokerTransport.d.ts +151 -0
  119. package/dist/transports/BrokerTransport.d.ts.map +1 -0
  120. package/dist/transports/BrokerTransport.js +261 -0
  121. package/dist/transports/BrokerTransport.js.map +1 -0
  122. package/dist/transports/NativeTransport.d.ts +149 -0
  123. package/dist/transports/NativeTransport.d.ts.map +1 -0
  124. package/dist/transports/NativeTransport.js +302 -0
  125. package/dist/transports/NativeTransport.js.map +1 -0
  126. package/dist/transports/StdioTransport.d.ts +172 -0
  127. package/dist/transports/StdioTransport.d.ts.map +1 -0
  128. package/dist/transports/StdioTransport.js +410 -0
  129. package/dist/transports/StdioTransport.js.map +1 -0
  130. package/dist/transports/index.d.ts +10 -0
  131. package/dist/transports/index.d.ts.map +1 -0
  132. package/dist/transports/index.js +9 -0
  133. package/dist/transports/index.js.map +1 -0
  134. package/dist/types/broker.d.ts +301 -0
  135. package/dist/types/broker.d.ts.map +1 -0
  136. package/dist/types/broker.js +46 -0
  137. package/dist/types/broker.js.map +1 -0
  138. package/dist/types/config.d.ts +325 -0
  139. package/dist/types/config.d.ts.map +1 -0
  140. package/dist/types/config.js +17 -0
  141. package/dist/types/config.js.map +1 -0
  142. package/dist/types/errors.d.ts +178 -0
  143. package/dist/types/errors.d.ts.map +1 -0
  144. package/dist/types/errors.js +165 -0
  145. package/dist/types/errors.js.map +1 -0
  146. package/dist/types/events.d.ts +210 -0
  147. package/dist/types/events.d.ts.map +1 -0
  148. package/dist/types/events.js +8 -0
  149. package/dist/types/events.js.map +1 -0
  150. package/dist/types/index.d.ts +32 -0
  151. package/dist/types/index.d.ts.map +1 -0
  152. package/dist/types/index.js +21 -0
  153. package/dist/types/index.js.map +1 -0
  154. package/dist/types/protocol.d.ts +48 -0
  155. package/dist/types/protocol.d.ts.map +1 -0
  156. package/dist/types/protocol.js +11 -0
  157. package/dist/types/protocol.js.map +1 -0
  158. package/dist/types/tools.d.ts +67 -0
  159. package/dist/types/tools.d.ts.map +1 -0
  160. package/dist/types/tools.js +16 -0
  161. package/dist/types/tools.js.map +1 -0
  162. package/dist/types/transport.d.ts +250 -0
  163. package/dist/types/transport.d.ts.map +1 -0
  164. package/dist/types/transport.js +18 -0
  165. package/dist/types/transport.js.map +1 -0
  166. package/dist/validation/SchemaValidator.d.ts +208 -0
  167. package/dist/validation/SchemaValidator.d.ts.map +1 -0
  168. package/dist/validation/SchemaValidator.js +411 -0
  169. package/dist/validation/SchemaValidator.js.map +1 -0
  170. package/dist/validation/index.d.ts +11 -0
  171. package/dist/validation/index.d.ts.map +1 -0
  172. package/dist/validation/index.js +10 -0
  173. package/dist/validation/index.js.map +1 -0
  174. package/package.json +69 -5
  175. package/agent.json +0 -18
  176. package/broker.js +0 -214
  177. package/index.js +0 -370
  178. package/ipc.js +0 -220
  179. package/ipcInterfaces/pythonAbilityIPC.py +0 -177
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Simplified KADI API
3
+ *
4
+ * User-friendly API wrapper that makes KADI incredibly simple to use.
5
+ * This is what developers actually interact with.
6
+ *
7
+ * @module api
8
+ */
9
+ import { KadiClient } from '../client/KadiClient.js';
10
+ import type { KadiConfig, ServiceConfig } from '../types/index.js';
11
+ /**
12
+ * Connect to a KADI broker and create a client
13
+ *
14
+ * Simplified connection API that handles common cases beautifully.
15
+ *
16
+ * @param config - Broker URL string or full configuration object
17
+ * @returns Connected KADI client
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Simple broker URL
22
+ * const client = await Kadi.connect('ws://localhost:8080');
23
+ *
24
+ * // Full configuration
25
+ * const client = await Kadi.connect({
26
+ * name: 'my-app',
27
+ * brokers: { local: 'ws://localhost:8080' },
28
+ * networks: ['global']
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function connect(config: string | KadiConfig): Promise<KadiClient>;
33
+ /**
34
+ * Create a service that provides tools
35
+ *
36
+ * Simplified service creation for agents that expose capabilities.
37
+ *
38
+ * @param config - Service configuration
39
+ * @returns Service client ready for tool registration
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const service = await Kadi.service({
44
+ * name: 'calculator',
45
+ * broker: 'ws://localhost:8080'
46
+ * });
47
+ *
48
+ * // Register tools using MCP schema format
49
+ * service.registerTool({
50
+ * name: 'add',
51
+ * description: 'Add two numbers',
52
+ * inputSchema: {
53
+ * type: 'object',
54
+ * properties: {
55
+ * a: { type: 'number' },
56
+ * b: { type: 'number' }
57
+ * },
58
+ * required: ['a', 'b']
59
+ * },
60
+ * outputSchema: {
61
+ * type: 'object',
62
+ * properties: {
63
+ * result: { type: 'number' }
64
+ * }
65
+ * }
66
+ * }, async ({ a, b }) => {
67
+ * return { result: a + b };
68
+ * });
69
+ * ```
70
+ */
71
+ export declare function service(config: ServiceConfig): Promise<KadiClient>;
72
+ /**
73
+ * Create a client without connecting to brokers
74
+ *
75
+ * Useful for local-only operations (native/stdio transports).
76
+ *
77
+ * @param name - Client name
78
+ * @returns Local client (not connected to brokers)
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const client = Kadi.local('my-app');
83
+ *
84
+ * // Load abilities locally
85
+ * const calc = await client.loadAbility('calculator', {
86
+ * transport: 'native',
87
+ * path: './calculator'
88
+ * });
89
+ * ```
90
+ */
91
+ export declare function local(name: string): KadiClient;
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAoB,MAAM,mBAAmB,CAAC;AAErF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAa9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBxE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAK9C"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Simplified KADI API
3
+ *
4
+ * User-friendly API wrapper that makes KADI incredibly simple to use.
5
+ * This is what developers actually interact with.
6
+ *
7
+ * @module api
8
+ */
9
+ import { KadiClient } from '../client/KadiClient.js';
10
+ /**
11
+ * Connect to a KADI broker and create a client
12
+ *
13
+ * Simplified connection API that handles common cases beautifully.
14
+ *
15
+ * @param config - Broker URL string or full configuration object
16
+ * @returns Connected KADI client
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Simple broker URL
21
+ * const client = await Kadi.connect('ws://localhost:8080');
22
+ *
23
+ * // Full configuration
24
+ * const client = await Kadi.connect({
25
+ * name: 'my-app',
26
+ * brokers: { local: 'ws://localhost:8080' },
27
+ * networks: ['global']
28
+ * });
29
+ * ```
30
+ */
31
+ export async function connect(config) {
32
+ // Normalize config
33
+ const normalizedConfig = typeof config === 'string'
34
+ ? { name: 'kadi-client', brokers: { default: config } }
35
+ : config;
36
+ // Create client
37
+ const client = new KadiClient(normalizedConfig);
38
+ // Auto-connect
39
+ await client.connect();
40
+ return client;
41
+ }
42
+ /**
43
+ * Create a service that provides tools
44
+ *
45
+ * Simplified service creation for agents that expose capabilities.
46
+ *
47
+ * @param config - Service configuration
48
+ * @returns Service client ready for tool registration
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const service = await Kadi.service({
53
+ * name: 'calculator',
54
+ * broker: 'ws://localhost:8080'
55
+ * });
56
+ *
57
+ * // Register tools using MCP schema format
58
+ * service.registerTool({
59
+ * name: 'add',
60
+ * description: 'Add two numbers',
61
+ * inputSchema: {
62
+ * type: 'object',
63
+ * properties: {
64
+ * a: { type: 'number' },
65
+ * b: { type: 'number' }
66
+ * },
67
+ * required: ['a', 'b']
68
+ * },
69
+ * outputSchema: {
70
+ * type: 'object',
71
+ * properties: {
72
+ * result: { type: 'number' }
73
+ * }
74
+ * }
75
+ * }, async ({ a, b }) => {
76
+ * return { result: a + b };
77
+ * });
78
+ * ```
79
+ */
80
+ export async function service(config) {
81
+ // Convert ServiceConfig to KadiConfig
82
+ const clientConfig = {
83
+ name: config.name,
84
+ version: config.version,
85
+ description: config.description,
86
+ role: 'ability',
87
+ networks: config.networks ?? ['global']
88
+ };
89
+ // Add broker configuration
90
+ if (config.broker) {
91
+ clientConfig.brokers = { default: config.broker };
92
+ clientConfig.defaultBroker = 'default';
93
+ }
94
+ // Create and return client
95
+ const client = new KadiClient(clientConfig);
96
+ await client.connect();
97
+ return client;
98
+ }
99
+ /**
100
+ * Create a client without connecting to brokers
101
+ *
102
+ * Useful for local-only operations (native/stdio transports).
103
+ *
104
+ * @param name - Client name
105
+ * @returns Local client (not connected to brokers)
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const client = Kadi.local('my-app');
110
+ *
111
+ * // Load abilities locally
112
+ * const calc = await client.loadAbility('calculator', {
113
+ * transport: 'native',
114
+ * path: './calculator'
115
+ * });
116
+ * ```
117
+ */
118
+ export function local(name) {
119
+ return new KadiClient({
120
+ name,
121
+ networks: ['local']
122
+ });
123
+ }
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAA2B;IACvD,mBAAmB;IACnB,MAAM,gBAAgB,GAAe,OAAO,MAAM,KAAK,QAAQ;QAC7D,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;QACvD,CAAC,CAAC,MAAM,CAAC;IAEX,gBAAgB;IAChB,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAEhD,eAAe;IACf,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,MAAqB;IACjD,sCAAsC;IACtC,MAAM,YAAY,GAAqB;QACrC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC;KACxC,CAAC;IAEF,2BAA2B;IAC3B,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,YAAY,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QAClD,YAAY,CAAC,aAAa,GAAG,SAAS,CAAC;IACzC,CAAC;IAED,2BAA2B;IAC3B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC;IAC5C,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IAEvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,IAAI,UAAU,CAAC;QACpB,IAAI;QACJ,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Broker Connection
3
+ *
4
+ * Wraps a single WebSocket connection to a KADI broker.
5
+ * Handles connection lifecycle, message sending/receiving, and state management.
6
+ *
7
+ * @module broker/BrokerConnection
8
+ */
9
+ import { EventEmitter } from 'events';
10
+ import type { BrokerConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcNotification } from '../types/index.js';
11
+ import { ConnectionState } from '../types/index.js';
12
+ /**
13
+ * Broker Connection Events
14
+ */
15
+ export interface BrokerConnectionEvents {
16
+ /**
17
+ * Emitted when connection is established
18
+ */
19
+ connected: () => void;
20
+ /**
21
+ * Emitted when connection is closed
22
+ */
23
+ disconnected: (code: number, reason: string) => void;
24
+ /**
25
+ * Emitted when an error occurs
26
+ */
27
+ error: (error: Error) => void;
28
+ /**
29
+ * Emitted when a message is received
30
+ */
31
+ message: (message: JsonRpcResponse | JsonRpcNotification) => void;
32
+ /**
33
+ * Emitted when connection state changes
34
+ */
35
+ stateChange: (oldState: ConnectionState, newState: ConnectionState) => void;
36
+ }
37
+ /**
38
+ * Broker Connection
39
+ *
40
+ * Manages a single WebSocket connection to a broker.
41
+ * Handles low-level connection lifecycle and message framing.
42
+ *
43
+ * Does NOT handle:
44
+ * - Protocol logic (handshake, auth) - that's BrokerProtocol's job
45
+ * - Multiple connections - that's BrokerConnectionManager's job
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const connection = new BrokerConnection({
50
+ * url: 'ws://localhost:8080',
51
+ * name: 'local',
52
+ * connectionTimeout: 10000
53
+ * });
54
+ *
55
+ * connection.on('connected', () => {
56
+ * console.log('Connected to broker');
57
+ * });
58
+ *
59
+ * connection.on('message', (message) => {
60
+ * console.log('Received:', message);
61
+ * });
62
+ *
63
+ * await connection.connect();
64
+ * ```
65
+ */
66
+ export declare class BrokerConnection extends EventEmitter {
67
+ /**
68
+ * Broker configuration
69
+ */
70
+ private readonly config;
71
+ /**
72
+ * WebSocket instance
73
+ */
74
+ private ws;
75
+ /**
76
+ * Current connection state
77
+ */
78
+ private _state;
79
+ /**
80
+ * Assigned agent ID (set after handshake)
81
+ */
82
+ private _agentId;
83
+ /**
84
+ * Heartbeat timer
85
+ */
86
+ private heartbeatTimer;
87
+ /**
88
+ * Connection timestamp
89
+ */
90
+ private _connectedAt;
91
+ /**
92
+ * Last heartbeat timestamp
93
+ */
94
+ private _lastHeartbeat;
95
+ /**
96
+ * Pending requests (for matching responses)
97
+ */
98
+ private pendingRequests;
99
+ /**
100
+ * Request ID counter
101
+ */
102
+ private requestIdCounter;
103
+ /**
104
+ * Create a new BrokerConnection
105
+ *
106
+ * @param config - Broker configuration
107
+ */
108
+ constructor(config: BrokerConfig);
109
+ /**
110
+ * Connect to the broker
111
+ *
112
+ * @throws {KadiError} If connection fails
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * await connection.connect();
117
+ * console.log('Connected!');
118
+ * ```
119
+ */
120
+ connect(): Promise<void>;
121
+ /**
122
+ * Disconnect from the broker
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * await connection.disconnect();
127
+ * ```
128
+ */
129
+ disconnect(): Promise<void>;
130
+ /**
131
+ * Send a JSON-RPC request and wait for response
132
+ *
133
+ * @template T - Response result type
134
+ * @param request - JSON-RPC request
135
+ * @returns Promise resolving to the response result
136
+ *
137
+ * @throws {KadiError} If request fails or times out
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const result = await connection.sendRequest({
142
+ * jsonrpc: '2.0',
143
+ * method: 'kadi.handshake',
144
+ * params: { name: 'my-agent' },
145
+ * id: 1
146
+ * });
147
+ * ```
148
+ */
149
+ sendRequest<T = unknown>(request: JsonRpcRequest): Promise<T>;
150
+ /**
151
+ * Send a JSON-RPC notification (no response expected)
152
+ *
153
+ * @param notification - JSON-RPC notification
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * connection.sendNotification({
158
+ * jsonrpc: '2.0',
159
+ * method: 'kadi.heartbeat',
160
+ * params: { timestamp: Date.now() }
161
+ * });
162
+ * ```
163
+ */
164
+ sendNotification(notification: JsonRpcNotification): void;
165
+ /**
166
+ * Send a tool result back to broker as JSON-RPC response
167
+ *
168
+ * Used when this client acts as a tool provider and needs to respond to invocations.
169
+ * The requestId must match the incoming request's id field for proper routing.
170
+ *
171
+ * @param requestId - Request ID to respond to (CRITICAL: must match incoming request id)
172
+ * @param result - Result data to send back
173
+ */
174
+ sendResponse(requestId: string | number | undefined, result: unknown): void;
175
+ /**
176
+ * Send a tool error back to broker as JSON-RPC error response
177
+ *
178
+ * Used when tool execution fails and we need to report the error back.
179
+ * The requestId must match the incoming request's id field for proper routing.
180
+ *
181
+ * @param requestId - Request ID to respond to (CRITICAL: must match incoming request id)
182
+ * @param code - Error code (e.g., ErrorCode.TOOL_NOT_FOUND)
183
+ * @param message - Human-readable error message
184
+ * @param data - Optional additional error context
185
+ */
186
+ sendError(requestId: string | number | undefined, code: string, message: string, data?: Record<string, unknown>): void;
187
+ /**
188
+ * Send raw data to broker
189
+ *
190
+ * @param data - Data to send (request, response, or notification)
191
+ */
192
+ private send;
193
+ /**
194
+ * Handle incoming WebSocket message
195
+ *
196
+ * @param data - Raw message data
197
+ */
198
+ private handleMessage;
199
+ /**
200
+ * Handle WebSocket close event
201
+ *
202
+ * @param code - Close code
203
+ * @param reason - Close reason
204
+ */
205
+ private handleClose;
206
+ /**
207
+ * Setup heartbeat timer
208
+ */
209
+ private setupHeartbeat;
210
+ /**
211
+ * Cleanup connection resources
212
+ */
213
+ private cleanup;
214
+ /**
215
+ * Set connection state and emit event
216
+ *
217
+ * @param newState - New state
218
+ */
219
+ private setState;
220
+ /**
221
+ * Get broker name
222
+ */
223
+ get name(): string;
224
+ /**
225
+ * Get broker URL
226
+ */
227
+ get url(): string;
228
+ /**
229
+ * Get current connection state
230
+ */
231
+ get state(): ConnectionState;
232
+ /**
233
+ * Check if connected
234
+ */
235
+ get isConnected(): boolean;
236
+ /**
237
+ * Get assigned agent ID
238
+ */
239
+ get agentId(): string | null;
240
+ /**
241
+ * Set agent ID (called after handshake)
242
+ */
243
+ set agentId(id: string | null);
244
+ /**
245
+ * Get connection timestamp
246
+ */
247
+ get connectedAt(): number | null;
248
+ /**
249
+ * Get last heartbeat timestamp
250
+ */
251
+ get lastHeartbeat(): number | null;
252
+ }
253
+ //# sourceMappingURL=BrokerConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrokerConnection.d.ts","sourceRoot":"","sources":["../../src/broker/BrokerConnection.ts"],"names":[],"mappings":"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"}