@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,151 @@
1
+ /**
2
+ * Broker Transport
3
+ *
4
+ * Accesses abilities on remote agents via broker communication.
5
+ * Enables distributed system architecture with service discovery.
6
+ *
7
+ * @module transports/BrokerTransport
8
+ */
9
+ import { EventEmitter } from 'events';
10
+ import type { AbilityTransport, BrokerTransportOptions, MethodSchema } from '../types/index.js';
11
+ import type { BrokerConnectionManager } from '../broker/BrokerConnectionManager.js';
12
+ import type { BrokerProtocol } from '../broker/BrokerProtocol.js';
13
+ /**
14
+ * Broker Client Interface
15
+ *
16
+ * Defines the minimal interface BrokerTransport needs from the client.
17
+ * This breaks the circular dependency between transport and client.
18
+ */
19
+ export interface IBrokerClient {
20
+ /**
21
+ * Get the broker connection manager
22
+ */
23
+ getBrokerManager(): BrokerConnectionManager;
24
+ /**
25
+ * Get broker protocol instance for a specific broker
26
+ */
27
+ getBrokerProtocol(brokerName?: string): BrokerProtocol;
28
+ /**
29
+ * Networks this client is part of
30
+ */
31
+ networks: string[];
32
+ }
33
+ /**
34
+ * Broker Transport
35
+ *
36
+ * Communicates with remote abilities via broker infrastructure.
37
+ * Provides service discovery and load balancing across multiple brokers.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const transport = new BrokerTransport({
42
+ * abilityName: 'calculator',
43
+ * brokerUrl: 'ws://localhost:8080',
44
+ * networks: ['global']
45
+ * }, client);
46
+ *
47
+ * await transport.connect();
48
+ * const result = await transport.invoke('add', { a: 5, b: 3 });
49
+ * ```
50
+ */
51
+ export declare class BrokerTransport extends EventEmitter implements AbilityTransport {
52
+ /**
53
+ * Transport configuration
54
+ */
55
+ private readonly options;
56
+ /**
57
+ * Broker client interface
58
+ */
59
+ private readonly client;
60
+ /**
61
+ * Discovered methods
62
+ */
63
+ private methods;
64
+ /**
65
+ * Method schemas
66
+ */
67
+ private schemas;
68
+ /**
69
+ * Whether transport is connected
70
+ */
71
+ private connected;
72
+ /**
73
+ * Target agent name (resolved during discovery)
74
+ */
75
+ private targetAgent;
76
+ /**
77
+ * Create a new BrokerTransport
78
+ *
79
+ * @param options - Broker transport options
80
+ * @param client - Broker client interface
81
+ */
82
+ constructor(options: BrokerTransportOptions, client: IBrokerClient);
83
+ /**
84
+ * Connect to the ability
85
+ *
86
+ * Discovers the ability on the broker network and queries its capabilities.
87
+ *
88
+ * @throws {KadiError} If ability cannot be found or discovery fails
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * await transport.connect();
93
+ * console.log('Connected to remote ability');
94
+ * ```
95
+ */
96
+ connect(): Promise<void>;
97
+ /**
98
+ * Invoke a method on the remote ability
99
+ *
100
+ * @template TInput - Input parameter type
101
+ * @template TOutput - Return type
102
+ *
103
+ * @param method - Method name
104
+ * @param params - Method parameters
105
+ * @returns Promise resolving to method result
106
+ *
107
+ * @throws {KadiError} If method doesn't exist or invocation fails
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
112
+ * 'add',
113
+ * { a: 5, b: 3 }
114
+ * );
115
+ * ```
116
+ */
117
+ invoke<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
118
+ /**
119
+ * Get list of available methods
120
+ *
121
+ * @returns Array of method names
122
+ */
123
+ getMethods(): string[];
124
+ /**
125
+ * Get schema for a specific method
126
+ *
127
+ * @param method - Method name
128
+ * @returns Method schema or undefined
129
+ */
130
+ getMethodSchema(method: string): MethodSchema | undefined;
131
+ /**
132
+ * Disconnect from the ability
133
+ *
134
+ * Note: Does not disconnect the underlying broker connection,
135
+ * as it may be shared with other transports.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * await transport.disconnect();
140
+ * ```
141
+ */
142
+ disconnect(): Promise<void>;
143
+ /**
144
+ * Publish an event from the ability
145
+ *
146
+ * @param eventName - Event name
147
+ * @param data - Event data
148
+ */
149
+ publishEvent(eventName: string, data: unknown): void;
150
+ }
151
+ //# sourceMappingURL=BrokerTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrokerTransport.d.ts","sourceRoot":"","sources":["../../src/transports/BrokerTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,gBAAgB,IAAI,uBAAuB,CAAC;IAE5C;;OAEG;IACH,iBAAiB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC;IAEvD;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,gBAAgB;IAC3E;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAE3D;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAgB;IAE/B;;OAEG;IACH,OAAO,CAAC,OAAO,CAAmC;IAElD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;OAEG;IACH,OAAO,CAAC,WAAW,CAAuB;IAE1C;;;;;OAKG;gBACS,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,aAAa;IAgBlE;;;;;;;;;;;;OAYG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA0E9B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;IAgEnB;;;;OAIG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;;;;OAKG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIzD;;;;;;;;;;OAUG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAejC;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;CA8BrD"}
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Broker Transport
3
+ *
4
+ * Accesses abilities on remote agents via broker communication.
5
+ * Enables distributed system architecture with service discovery.
6
+ *
7
+ * @module transports/BrokerTransport
8
+ */
9
+ import { EventEmitter } from 'events';
10
+ import { KadiError, ErrorCode } from '../types/index.js';
11
+ /**
12
+ * Broker Transport
13
+ *
14
+ * Communicates with remote abilities via broker infrastructure.
15
+ * Provides service discovery and load balancing across multiple brokers.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const transport = new BrokerTransport({
20
+ * abilityName: 'calculator',
21
+ * brokerUrl: 'ws://localhost:8080',
22
+ * networks: ['global']
23
+ * }, client);
24
+ *
25
+ * await transport.connect();
26
+ * const result = await transport.invoke('add', { a: 5, b: 3 });
27
+ * ```
28
+ */
29
+ export class BrokerTransport extends EventEmitter {
30
+ /**
31
+ * Transport configuration
32
+ */
33
+ options;
34
+ /**
35
+ * Broker client interface
36
+ */
37
+ client;
38
+ /**
39
+ * Discovered methods
40
+ */
41
+ methods = [];
42
+ /**
43
+ * Method schemas
44
+ */
45
+ schemas = new Map();
46
+ /**
47
+ * Whether transport is connected
48
+ */
49
+ connected = false;
50
+ /**
51
+ * Target agent name (resolved during discovery)
52
+ */
53
+ targetAgent = null;
54
+ /**
55
+ * Create a new BrokerTransport
56
+ *
57
+ * @param options - Broker transport options
58
+ * @param client - Broker client interface
59
+ */
60
+ constructor(options, client) {
61
+ super();
62
+ this.options = {
63
+ timeout: options.timeout ?? 30000,
64
+ networks: options.networks ?? client.networks,
65
+ brokerUrl: options.brokerUrl,
66
+ brokerName: options.brokerName ?? 'default',
67
+ authToken: options.authToken ?? '',
68
+ abilityName: options.abilityName,
69
+ abilityVersion: options.abilityVersion ?? '0.0.1'
70
+ };
71
+ this.client = client;
72
+ }
73
+ /**
74
+ * Connect to the ability
75
+ *
76
+ * Discovers the ability on the broker network and queries its capabilities.
77
+ *
78
+ * @throws {KadiError} If ability cannot be found or discovery fails
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * await transport.connect();
83
+ * console.log('Connected to remote ability');
84
+ * ```
85
+ */
86
+ async connect() {
87
+ if (this.connected) {
88
+ return;
89
+ }
90
+ try {
91
+ // Get broker protocol
92
+ const protocol = this.client.getBrokerProtocol(this.options.brokerName);
93
+ // Discover agents on the network
94
+ const agents = await protocol.discoverAgents(this.options.networks);
95
+ // Find the target ability
96
+ const targetAgent = agents.find(agent => agent.name === this.options.abilityName ||
97
+ agent.capabilities.includes(this.options.abilityName));
98
+ if (!targetAgent) {
99
+ throw new KadiError(`Ability '${this.options.abilityName}' not found on networks: ${this.options.networks.join(', ')}`, ErrorCode.ABILITY_NOT_FOUND, 404, {
100
+ abilityName: this.options.abilityName,
101
+ networks: this.options.networks,
102
+ availableAgents: agents.map(a => a.name)
103
+ });
104
+ }
105
+ this.targetAgent = targetAgent.name;
106
+ // Query capabilities
107
+ const capabilities = await protocol.queryCapabilities(this.targetAgent, this.options.networks);
108
+ // Extract methods and schemas
109
+ this.methods = capabilities.map(cap => cap.name);
110
+ for (const cap of capabilities) {
111
+ if (cap.inputSchema || cap.outputSchema) {
112
+ this.schemas.set(cap.name, {
113
+ description: cap.description,
114
+ inputSchema: cap.inputSchema,
115
+ outputSchema: cap.outputSchema
116
+ });
117
+ }
118
+ }
119
+ this.connected = true;
120
+ this.emit('connected');
121
+ }
122
+ catch (error) {
123
+ const kadiError = error instanceof KadiError
124
+ ? error
125
+ : new KadiError(`Failed to connect to ability: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.ABILITY_LOAD_FAILED, 500, {
126
+ abilityName: this.options.abilityName,
127
+ networks: this.options.networks,
128
+ originalError: error instanceof Error ? error.message : String(error)
129
+ });
130
+ this.emit('error', kadiError);
131
+ throw kadiError;
132
+ }
133
+ }
134
+ /**
135
+ * Invoke a method on the remote ability
136
+ *
137
+ * @template TInput - Input parameter type
138
+ * @template TOutput - Return type
139
+ *
140
+ * @param method - Method name
141
+ * @param params - Method parameters
142
+ * @returns Promise resolving to method result
143
+ *
144
+ * @throws {KadiError} If method doesn't exist or invocation fails
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
149
+ * 'add',
150
+ * { a: 5, b: 3 }
151
+ * );
152
+ * ```
153
+ */
154
+ async invoke(method, params) {
155
+ if (!this.connected || !this.targetAgent) {
156
+ throw new KadiError('Transport not connected', ErrorCode.TRANSPORT_NOT_CONNECTED, 503, { abilityName: this.options.abilityName });
157
+ }
158
+ // Check if method exists
159
+ if (!this.methods.includes(method)) {
160
+ throw new KadiError(`Method '${method}' not found on ability '${this.options.abilityName}'`, ErrorCode.ABILITY_METHOD_NOT_FOUND, 404, {
161
+ abilityName: this.options.abilityName,
162
+ method,
163
+ availableMethods: this.methods
164
+ });
165
+ }
166
+ try {
167
+ // Get broker protocol
168
+ const protocol = this.client.getBrokerProtocol(this.options.brokerName);
169
+ // Invoke tool via broker
170
+ const result = await protocol.invokeTool({
171
+ targetAgent: this.targetAgent,
172
+ toolName: method,
173
+ toolInput: params,
174
+ timeout: this.options.timeout
175
+ });
176
+ return result;
177
+ }
178
+ catch (error) {
179
+ // Don't wrap KadiError
180
+ if (error instanceof KadiError) {
181
+ throw error;
182
+ }
183
+ // Enhance the original error
184
+ if (error instanceof Error) {
185
+ const enhancedError = error;
186
+ enhancedError.message = `${error.message} (in remote ${this.options.abilityName}.${method})`;
187
+ throw enhancedError;
188
+ }
189
+ throw new KadiError(`Remote method invocation failed: ${String(error)}`, ErrorCode.TOOL_INVOCATION_FAILED, 500, {
190
+ abilityName: this.options.abilityName,
191
+ targetAgent: this.targetAgent,
192
+ method
193
+ });
194
+ }
195
+ }
196
+ /**
197
+ * Get list of available methods
198
+ *
199
+ * @returns Array of method names
200
+ */
201
+ getMethods() {
202
+ return [...this.methods];
203
+ }
204
+ /**
205
+ * Get schema for a specific method
206
+ *
207
+ * @param method - Method name
208
+ * @returns Method schema or undefined
209
+ */
210
+ getMethodSchema(method) {
211
+ return this.schemas.get(method);
212
+ }
213
+ /**
214
+ * Disconnect from the ability
215
+ *
216
+ * Note: Does not disconnect the underlying broker connection,
217
+ * as it may be shared with other transports.
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * await transport.disconnect();
222
+ * ```
223
+ */
224
+ async disconnect() {
225
+ if (!this.connected) {
226
+ return;
227
+ }
228
+ // Just mark as disconnected - don't close broker connection
229
+ // The broker connection is managed by BrokerConnectionManager
230
+ this.connected = false;
231
+ this.targetAgent = null;
232
+ this.methods = [];
233
+ this.schemas.clear();
234
+ this.emit('disconnected');
235
+ }
236
+ /**
237
+ * Publish an event from the ability
238
+ *
239
+ * @param eventName - Event name
240
+ * @param data - Event data
241
+ */
242
+ publishEvent(eventName, data) {
243
+ if (!this.connected) {
244
+ return;
245
+ }
246
+ try {
247
+ const protocol = this.client.getBrokerProtocol(this.options.brokerName);
248
+ protocol.publishEvent({
249
+ channel: eventName,
250
+ data,
251
+ networkId: this.options.networks[0] // Use first network
252
+ }).catch(error => {
253
+ this.emit('error', new KadiError(`Failed to publish event: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.EVENT_PUBLISH_FAILED, 500, { abilityName: this.options.abilityName, eventName }));
254
+ });
255
+ }
256
+ catch (error) {
257
+ this.emit('error', new KadiError(`Failed to publish event: ${error instanceof Error ? error.message : String(error)}`, ErrorCode.EVENT_PUBLISH_FAILED, 500, { abilityName: this.options.abilityName, eventName }));
258
+ }
259
+ }
260
+ }
261
+ //# sourceMappingURL=BrokerTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BrokerTransport.js","sourceRoot":"","sources":["../../src/transports/BrokerTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AA2BzD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAC/C;;OAEG;IACc,OAAO,CAAmC;IAE3D;;OAEG;IACc,MAAM,CAAgB;IAEvC;;OAEG;IACK,OAAO,GAAa,EAAE,CAAC;IAE/B;;OAEG;IACK,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAElD;;OAEG;IACK,SAAS,GAAG,KAAK,CAAC;IAE1B;;OAEG;IACK,WAAW,GAAkB,IAAI,CAAC;IAE1C;;;;;OAKG;IACH,YAAY,OAA+B,EAAE,MAAqB;QAChE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,GAAG;YACb,OAAO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AC,OAAO,CAAC,WAAW,EAAE,SAAS,EAAE,CACrD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Native Transport
3
+ *
4
+ * Loads abilities in-process for zero-overhead communication.
5
+ * Best for abilities written in JavaScript/TypeScript that can run in the same process.
6
+ *
7
+ * @module transports/NativeTransport
8
+ */
9
+ import { EventEmitter } from 'events';
10
+ import type { AbilityTransport, NativeTransportOptions, MethodSchema } from '../types/index.js';
11
+ /**
12
+ * Native Transport
13
+ *
14
+ * Loads Node.js modules directly into the current process.
15
+ * Provides zero-overhead method invocation since everything runs in-process.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const transport = new NativeTransport({
20
+ * abilityName: 'calculator',
21
+ * abilityPath: '/path/to/calculator',
22
+ * entryPoint: 'index.js'
23
+ * });
24
+ *
25
+ * await transport.connect();
26
+ * const result = await transport.invoke('add', { a: 5, b: 3 });
27
+ * console.log(result); // { result: 8 }
28
+ * ```
29
+ */
30
+ export declare class NativeTransport extends EventEmitter implements AbilityTransport {
31
+ /**
32
+ * Transport configuration
33
+ */
34
+ private readonly options;
35
+ /**
36
+ * Loaded ability module
37
+ */
38
+ private ability;
39
+ /**
40
+ * Discovered methods
41
+ */
42
+ private methods;
43
+ /**
44
+ * Method schemas
45
+ */
46
+ private schemas;
47
+ /**
48
+ * Whether transport is connected
49
+ */
50
+ private connected;
51
+ /**
52
+ * Create a new NativeTransport
53
+ *
54
+ * @param options - Native transport options
55
+ */
56
+ constructor(options: NativeTransportOptions);
57
+ /**
58
+ * Connect to the ability
59
+ *
60
+ * Loads the module from disk and performs discovery.
61
+ *
62
+ * @throws {KadiError} If module cannot be loaded
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * await transport.connect();
67
+ * ```
68
+ */
69
+ connect(): Promise<void>;
70
+ /**
71
+ * Invoke a method on the ability
72
+ *
73
+ * @template TInput - Input parameter type
74
+ * @template TOutput - Return type
75
+ *
76
+ * @param method - Method name
77
+ * @param params - Method parameters
78
+ * @returns Promise resolving to method result
79
+ *
80
+ * @throws {KadiError} If method doesn't exist or invocation fails
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const result = await transport.invoke<{ a: number; b: number }, { result: number }>(
85
+ * 'add',
86
+ * { a: 5, b: 3 }
87
+ * );
88
+ * ```
89
+ */
90
+ invoke<TInput = unknown, TOutput = unknown>(method: string, params: TInput): Promise<TOutput>;
91
+ /**
92
+ * Get list of available methods
93
+ *
94
+ * @returns Array of method names
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const methods = transport.getMethods();
99
+ * console.log('Available methods:', methods);
100
+ * ```
101
+ */
102
+ getMethods(): string[];
103
+ /**
104
+ * Get schema for a specific method
105
+ *
106
+ * @param method - Method name
107
+ * @returns Method schema or undefined
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const schema = transport.getMethodSchema('add');
112
+ * if (schema) {
113
+ * console.log('Input schema:', schema.inputSchema);
114
+ * }
115
+ * ```
116
+ */
117
+ getMethodSchema(method: string): MethodSchema | undefined;
118
+ /**
119
+ * Disconnect from the ability
120
+ *
121
+ * Cleans up resources and removes references.
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * await transport.disconnect();
126
+ * ```
127
+ */
128
+ disconnect(): Promise<void>;
129
+ /**
130
+ * Publish an event from the ability
131
+ *
132
+ * @param eventName - Event name
133
+ * @param data - Event data
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * transport.publishEvent('calculation.completed', { result: 42 });
138
+ * ```
139
+ */
140
+ publishEvent(eventName: string, data: unknown): void;
141
+ /**
142
+ * Discover methods on the loaded ability
143
+ *
144
+ * Introspects the ability object to find callable methods.
145
+ * Excludes internal methods (starting with _) and special methods.
146
+ */
147
+ private discoverMethods;
148
+ }
149
+ //# sourceMappingURL=NativeTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeTransport.d.ts","sourceRoot":"","sources":["../../src/transports/NativeTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAG3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,gBAAgB;IAC3E;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAE3D;;OAEG;IACH,OAAO,CAAC,OAAO,CAAiB;IAEhC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAgB;IAE/B;;OAEG;IACH,OAAO,CAAC,OAAO,CAAmC;IAElD;;OAEG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;OAIG;gBACS,OAAO,EAAE,sBAAsB;IAW3C;;;;;;;;;;;OAWG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiD9B;;;;;;;;;;;;;;;;;;;OAmBG;IACG,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,EAC9C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC;IA0EnB;;;;;;;;;;OAUG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIzD;;;;;;;;;OASG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAcjC;;;;;;;;;;OAUG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IASpD;;;;;OAKG;YACW,eAAe;CA6D9B"}