@kadi.build/core 0.0.1-alpha.8 → 0.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.
Files changed (126) hide show
  1. package/README.md +362 -1305
  2. package/dist/client.d.ts +573 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +1673 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/errors.d.ts +107 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +147 -0
  9. package/dist/errors.js.map +1 -0
  10. package/dist/index.d.ts +37 -14
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +40 -23
  13. package/dist/index.js.map +1 -1
  14. package/dist/lockfile.d.ts +190 -0
  15. package/dist/lockfile.d.ts.map +1 -0
  16. package/dist/lockfile.js +373 -0
  17. package/dist/lockfile.js.map +1 -0
  18. package/dist/transports/broker.d.ts +75 -0
  19. package/dist/transports/broker.d.ts.map +1 -0
  20. package/dist/transports/broker.js +383 -0
  21. package/dist/transports/broker.js.map +1 -0
  22. package/dist/transports/native.d.ts +39 -0
  23. package/dist/transports/native.d.ts.map +1 -0
  24. package/dist/transports/native.js +189 -0
  25. package/dist/transports/native.js.map +1 -0
  26. package/dist/transports/stdio.d.ts +46 -0
  27. package/dist/transports/stdio.d.ts.map +1 -0
  28. package/dist/transports/stdio.js +460 -0
  29. package/dist/transports/stdio.js.map +1 -0
  30. package/dist/types.d.ts +664 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +16 -0
  33. package/dist/types.js.map +1 -0
  34. package/dist/zod.d.ts +34 -0
  35. package/dist/zod.d.ts.map +1 -0
  36. package/dist/zod.js +60 -0
  37. package/dist/zod.js.map +1 -0
  38. package/package.json +13 -28
  39. package/dist/KadiClient.d.ts +0 -432
  40. package/dist/KadiClient.d.ts.map +0 -1
  41. package/dist/KadiClient.js +0 -1506
  42. package/dist/KadiClient.js.map +0 -1
  43. package/dist/errors/error-codes.d.ts +0 -985
  44. package/dist/errors/error-codes.d.ts.map +0 -1
  45. package/dist/errors/error-codes.js +0 -638
  46. package/dist/errors/error-codes.js.map +0 -1
  47. package/dist/loadAbility.d.ts +0 -105
  48. package/dist/loadAbility.d.ts.map +0 -1
  49. package/dist/loadAbility.js +0 -370
  50. package/dist/loadAbility.js.map +0 -1
  51. package/dist/messages/BrokerMessages.d.ts +0 -84
  52. package/dist/messages/BrokerMessages.d.ts.map +0 -1
  53. package/dist/messages/BrokerMessages.js +0 -125
  54. package/dist/messages/BrokerMessages.js.map +0 -1
  55. package/dist/messages/MessageBuilder.d.ts +0 -83
  56. package/dist/messages/MessageBuilder.d.ts.map +0 -1
  57. package/dist/messages/MessageBuilder.js +0 -144
  58. package/dist/messages/MessageBuilder.js.map +0 -1
  59. package/dist/schemas/events.schemas.d.ts +0 -177
  60. package/dist/schemas/events.schemas.d.ts.map +0 -1
  61. package/dist/schemas/events.schemas.js +0 -265
  62. package/dist/schemas/events.schemas.js.map +0 -1
  63. package/dist/schemas/index.d.ts +0 -3
  64. package/dist/schemas/index.d.ts.map +0 -1
  65. package/dist/schemas/index.js +0 -4
  66. package/dist/schemas/index.js.map +0 -1
  67. package/dist/schemas/kadi.schemas.d.ts +0 -70
  68. package/dist/schemas/kadi.schemas.d.ts.map +0 -1
  69. package/dist/schemas/kadi.schemas.js +0 -120
  70. package/dist/schemas/kadi.schemas.js.map +0 -1
  71. package/dist/transports/BrokerTransport.d.ts +0 -102
  72. package/dist/transports/BrokerTransport.d.ts.map +0 -1
  73. package/dist/transports/BrokerTransport.js +0 -177
  74. package/dist/transports/BrokerTransport.js.map +0 -1
  75. package/dist/transports/NativeTransport.d.ts +0 -82
  76. package/dist/transports/NativeTransport.d.ts.map +0 -1
  77. package/dist/transports/NativeTransport.js +0 -263
  78. package/dist/transports/NativeTransport.js.map +0 -1
  79. package/dist/transports/StdioTransport.d.ts +0 -112
  80. package/dist/transports/StdioTransport.d.ts.map +0 -1
  81. package/dist/transports/StdioTransport.js +0 -450
  82. package/dist/transports/StdioTransport.js.map +0 -1
  83. package/dist/transports/Transport.d.ts +0 -93
  84. package/dist/transports/Transport.d.ts.map +0 -1
  85. package/dist/transports/Transport.js +0 -13
  86. package/dist/transports/Transport.js.map +0 -1
  87. package/dist/types/broker.d.ts +0 -31
  88. package/dist/types/broker.d.ts.map +0 -1
  89. package/dist/types/broker.js +0 -6
  90. package/dist/types/broker.js.map +0 -1
  91. package/dist/types/core.d.ts +0 -139
  92. package/dist/types/core.d.ts.map +0 -1
  93. package/dist/types/core.js +0 -26
  94. package/dist/types/core.js.map +0 -1
  95. package/dist/types/events.d.ts +0 -186
  96. package/dist/types/events.d.ts.map +0 -1
  97. package/dist/types/events.js +0 -16
  98. package/dist/types/events.js.map +0 -1
  99. package/dist/types/index.d.ts +0 -9
  100. package/dist/types/index.d.ts.map +0 -1
  101. package/dist/types/index.js +0 -13
  102. package/dist/types/index.js.map +0 -1
  103. package/dist/types/protocol.d.ts +0 -160
  104. package/dist/types/protocol.d.ts.map +0 -1
  105. package/dist/types/protocol.js +0 -5
  106. package/dist/types/protocol.js.map +0 -1
  107. package/dist/utils/agentUtils.d.ts +0 -187
  108. package/dist/utils/agentUtils.d.ts.map +0 -1
  109. package/dist/utils/agentUtils.js +0 -185
  110. package/dist/utils/agentUtils.js.map +0 -1
  111. package/dist/utils/commandUtils.d.ts +0 -45
  112. package/dist/utils/commandUtils.d.ts.map +0 -1
  113. package/dist/utils/commandUtils.js +0 -145
  114. package/dist/utils/commandUtils.js.map +0 -1
  115. package/dist/utils/configUtils.d.ts +0 -55
  116. package/dist/utils/configUtils.d.ts.map +0 -1
  117. package/dist/utils/configUtils.js +0 -100
  118. package/dist/utils/configUtils.js.map +0 -1
  119. package/dist/utils/logger.d.ts +0 -59
  120. package/dist/utils/logger.d.ts.map +0 -1
  121. package/dist/utils/logger.js +0 -122
  122. package/dist/utils/logger.js.map +0 -1
  123. package/dist/utils/pathUtils.d.ts +0 -48
  124. package/dist/utils/pathUtils.d.ts.map +0 -1
  125. package/dist/utils/pathUtils.js +0 -128
  126. package/dist/utils/pathUtils.js.map +0 -1
@@ -1,177 +0,0 @@
1
- /**
2
- * BrokerTransport - Handles communication with remote abilities via broker
3
- *
4
- * This transport connects to a broker (WebSocket server) to invoke methods
5
- * on remote agents/abilities. Unlike Native and Stdio transports which load
6
- * local code, BrokerTransport is purely a client that calls remote services.
7
- *
8
- * The broker acts as a message router, allowing agents to discover and
9
- * invoke each other's methods across network boundaries.
10
- *
11
- * Communication Flow:
12
- * 1. Connect to broker via WebSocket
13
- * 2. Authenticate and join networks
14
- * 3. Discover available methods from target agent
15
- * 4. Send method invocations through broker
16
- * 5. Receive results back through broker
17
- */
18
- import { EventEmitter } from 'events';
19
- import { createComponentLogger } from '../utils/logger.js';
20
- /**
21
- * BrokerTransport - Client for invoking methods on remote agents
22
- *
23
- * This transport is a thin wrapper around KadiClient's broker functionality.
24
- * It creates an ephemeral KadiClient instance that connects to the broker
25
- * solely for the purpose of calling methods on a remote agent.
26
- *
27
- * Unlike serving mode (where an agent registers its own methods),
28
- * this transport is purely a consumer of remote methods.
29
- */
30
- export class BrokerTransport extends EventEmitter {
31
- options;
32
- logger;
33
- client;
34
- targetAgent;
35
- connected = false;
36
- constructor(options) {
37
- super();
38
- this.options = options;
39
- this.targetAgent = options.targetAgent || options.abilityName;
40
- this.logger = createComponentLogger('BrokerTransport');
41
- if (!options.existingClient) {
42
- throw new Error('BrokerTransport requires an existing KadiClient');
43
- }
44
- this.client = options.existingClient;
45
- this.logger.lifecycle('constructor', `Creating broker transport for target: ${this.targetAgent} using existing client`);
46
- }
47
- /**
48
- * Connect to the broker and discover target agent's methods
49
- *
50
- * This creates an ephemeral KadiClient that connects to the broker
51
- * as a client (not serving any methods of its own).
52
- */
53
- async connect() {
54
- this.logger.lifecycle('connect', `Connecting to broker for target agent: ${this.targetAgent}`);
55
- try {
56
- // Connect to specific broker if not already connected
57
- const brokerUrl = this.options.brokerUrl;
58
- if (!brokerUrl) {
59
- throw new Error('Broker URL is required for BrokerTransport');
60
- }
61
- // Check if we're already connected to this specific broker
62
- const isConnectedToRightBroker = this.client.isConnectedToBroker(brokerUrl);
63
- if (!isConnectedToRightBroker) {
64
- // Need to connect to the specific broker
65
- this.logger.info('connect', `Connecting to specific broker: ${brokerUrl}`);
66
- // Connect only to the specific broker requested
67
- await this.client.connectToBroker(brokerUrl, this.options.brokerName);
68
- }
69
- else {
70
- this.logger.info('connect', `Already connected to broker: ${brokerUrl}`);
71
- }
72
- // OLD CODE - Connect to all brokers
73
- // await this.client.connectToBrokers();
74
- this.logger.info('connect', `Connected to broker at ${this.options.brokerUrl}`);
75
- // Discover available tools in the network to verify target exists
76
- this.logger.debug('connect', `Discovering tools in network to verify ${this.targetAgent} exists`);
77
- const toolsResponse = await this.client.sendBrokerRequest('kadi.ability.list', {
78
- networks: this.client.networks || ['global'],
79
- includeProviders: true
80
- });
81
- // Check if any tools are provided by an agent matching our target name
82
- const tools = toolsResponse.tools || [];
83
- const targetProviders = new Set();
84
- const availableAgents = new Set();
85
- for (const tool of tools) {
86
- if (tool.providers) {
87
- for (const provider of tool.providers) {
88
- // Track all available agents for error message (prefer displayName)
89
- const agentName = provider.displayName || provider.agentId;
90
- availableAgents.add(agentName);
91
- // Check if this provider matches our target
92
- // Match by displayName or if the targetAgent appears to be an agentId
93
- if (provider.displayName === this.targetAgent ||
94
- provider.agentId === this.targetAgent) {
95
- targetProviders.add(provider.agentId);
96
- }
97
- }
98
- }
99
- }
100
- if (targetProviders.size === 0) {
101
- const networks = this.client.networks || ['global'];
102
- const availableList = Array.from(availableAgents).sort();
103
- throw new Error(`Ability '${this.targetAgent}' not found in networks [${networks.join(', ')}].\n` +
104
- `Available abilities in these networks:\n${availableList.map((a) => ` - ${a}`).join('\n')}\n\n` +
105
- `Make sure the ability is running and connected to the broker.`);
106
- }
107
- this.logger.info('connect', `Found ${this.targetAgent} in network with ${targetProviders.size} provider(s)`);
108
- this.connected = true;
109
- this.logger.lifecycle('connect', `Broker transport connected to ${this.targetAgent}`);
110
- this.emit('connected');
111
- }
112
- catch (error) {
113
- this.logger.error('connect', `Failed to connect to broker: ${error}`);
114
- throw error;
115
- }
116
- }
117
- /**
118
- * Invoke a method on the remote agent
119
- *
120
- * Sends the method invocation through the broker to the target agent.
121
- */
122
- async invoke(method, params) {
123
- if (!this.connected || !this.client) {
124
- throw new Error('Not connected to broker');
125
- }
126
- this.logger.trace('invoke', `Invoking ${this.targetAgent}.${method}`);
127
- try {
128
- // Use KadiClient's remote tool invocation
129
- const result = await this.client.callTool(this.targetAgent, method, params);
130
- this.logger.trace('invoke', `Method ${method} completed successfully`);
131
- return result;
132
- }
133
- catch (error) {
134
- this.logger.error('invoke', `Failed to invoke ${this.targetAgent}.${method}: ${error}`);
135
- throw error;
136
- }
137
- }
138
- /**
139
- * Get list of discovered methods
140
- *
141
- * Returns empty array as broker transport doesn't do method discovery.
142
- */
143
- getMethods() {
144
- return [];
145
- }
146
- /**
147
- * Disconnect from the broker
148
- *
149
- * Since we're reusing an existing client, we don't actually disconnect it
150
- * (other parts of the app might still be using it)
151
- */
152
- async disconnect() {
153
- this.logger.lifecycle('disconnect', 'Disconnecting broker transport');
154
- // Don't disconnect the shared client - just mark ourselves as disconnected
155
- // The client is managed by the main application
156
- this.connected = false;
157
- if (this.client) {
158
- await this.client.disconnect();
159
- }
160
- this.emit('disconnected');
161
- }
162
- /**
163
- * Check if transport is connected
164
- */
165
- isConnected() {
166
- return this.connected;
167
- }
168
- /**
169
- * Get the target agent name
170
- *
171
- * Useful for debugging and logging
172
- */
173
- getTargetAgent() {
174
- return this.targetAgent;
175
- }
176
- }
177
- //# sourceMappingURL=BrokerTransport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BrokerTransport.js","sourceRoot":"","sources":["../../src/transports/BrokerTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;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AC,SAAS,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
@@ -1,82 +0,0 @@
1
- /**
2
- * NativeTransport - Handles direct in-process ability loading
3
- *
4
- * This transport loads abilities directly into the same process,
5
- * allowing for zero-overhead method invocation. It's used when
6
- * you want to load local JavaScript/TypeScript modules as abilities.
7
- *
8
- * The native protocol is the fastest but requires the ability code
9
- * to be trusted since it runs in the same process.
10
- */
11
- import { EventEmitter } from 'events';
12
- import { Transport, TransportOptions } from './Transport.js';
13
- /**
14
- * Options specific to NativeTransport
15
- */
16
- interface NativeTransportOptions extends TransportOptions {
17
- /**
18
- * Directory where the ability code is located
19
- */
20
- abilityDir: string;
21
- }
22
- /**
23
- * NativeTransport - Loads and executes abilities in the same process
24
- *
25
- * This transport provides the fastest execution since there's no
26
- * serialization or IPC overhead. The ability code runs directly
27
- * in the Node.js process.
28
- */
29
- export declare class NativeTransport extends EventEmitter implements Transport {
30
- private options;
31
- private logger;
32
- private ability;
33
- private methodHandlers;
34
- private connected;
35
- constructor(options: NativeTransportOptions);
36
- /**
37
- * Connect by loading the ability module into memory
38
- *
39
- * This method uses JavaScript's native import to load the ability,
40
- * delegating all module resolution complexity to Node.js itself.
41
- */
42
- connect(): Promise<void>;
43
- /**
44
- * Extract methods from the loaded module
45
- *
46
- * Handles different export formats:
47
- * - KadiClient/KadiAbility instances
48
- * - Plain objects with function properties
49
- * - Class constructors
50
- */
51
- private extractMethods;
52
- /**
53
- * Invoke a method on the loaded ability
54
- *
55
- * Since this is native, we just call the function directly
56
- * with no serialization overhead.
57
- */
58
- invoke(method: string, params: unknown): Promise<unknown>;
59
- /**
60
- * Get list of available methods
61
- */
62
- getMethods(): string[];
63
- /**
64
- * Get schema for a specific method (if available)
65
- */
66
- getMethodSchema(method: string): {
67
- inputSchema?: unknown;
68
- outputSchema?: unknown;
69
- } | undefined;
70
- /**
71
- * Disconnect and cleanup
72
- *
73
- * Releases references to the loaded module to allow garbage collection
74
- */
75
- disconnect(): Promise<void>;
76
- /**
77
- * Check if transport is connected
78
- */
79
- isConnected(): boolean;
80
- }
81
- export {};
82
- //# sourceMappingURL=NativeTransport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativeTransport.d.ts","sourceRoot":"","sources":["../../src/transports/NativeTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG7D;;GAEG;AACH,UAAU,sBAAuB,SAAQ,gBAAgB;IACvD;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAOD;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,SAAS;IAMxD,OAAO,CAAC,OAAO;IAL3B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,cAAc,CAAoC;IAC1D,OAAO,CAAC,SAAS,CAAS;gBAEN,OAAO,EAAE,sBAAsB;IAUnD;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+F9B;;;;;;;OAOG;YACW,cAAc;IAoG5B;;;;;OAKG;IACG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAuB/D;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;OAEG;IACH,eAAe,CACb,MAAM,EAAE,MAAM,GACb;QAAE,WAAW,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS;IAQhE;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC;;OAEG;IACH,WAAW,IAAI,OAAO;CAGvB"}
@@ -1,263 +0,0 @@
1
- /**
2
- * NativeTransport - Handles direct in-process ability loading
3
- *
4
- * This transport loads abilities directly into the same process,
5
- * allowing for zero-overhead method invocation. It's used when
6
- * you want to load local JavaScript/TypeScript modules as abilities.
7
- *
8
- * The native protocol is the fastest but requires the ability code
9
- * to be trusted since it runs in the same process.
10
- */
11
- import path from 'node:path';
12
- import { EventEmitter } from 'events';
13
- import { createComponentLogger } from '../utils/logger.js';
14
- /**
15
- * NativeTransport - Loads and executes abilities in the same process
16
- *
17
- * This transport provides the fastest execution since there's no
18
- * serialization or IPC overhead. The ability code runs directly
19
- * in the Node.js process.
20
- */
21
- export class NativeTransport extends EventEmitter {
22
- options;
23
- logger;
24
- ability;
25
- methodHandlers = new Map();
26
- connected = false;
27
- constructor(options) {
28
- super();
29
- this.options = options;
30
- this.logger = createComponentLogger('NativeTransport');
31
- this.logger.lifecycle('constructor', `Creating native transport for ${options.abilityName}`);
32
- }
33
- /**
34
- * Connect by loading the ability module into memory
35
- *
36
- * This method uses JavaScript's native import to load the ability,
37
- * delegating all module resolution complexity to Node.js itself.
38
- */
39
- async connect() {
40
- const { abilityName, abilityDir } = this.options;
41
- this.logger.lifecycle('connect', `Loading ${abilityName} as native module`);
42
- this.logger.debug('connect', `abilityDir received: ${abilityDir}`);
43
- this.logger.debug('connect', `process.cwd(): ${process.cwd()}`);
44
- // Set environment variable so the module knows it's being loaded via native protocol
45
- const originalProtocol = process.env.KADI_PROTOCOL;
46
- process.env.KADI_PROTOCOL = 'native';
47
- let rawModule;
48
- try {
49
- // Convert to absolute path if needed
50
- const baseDir = path.isAbsolute(abilityDir)
51
- ? abilityDir
52
- : path.resolve(process.cwd(), abilityDir);
53
- // Resolve the actual entry file
54
- // ES modules require importing a file, not a directory
55
- let entryFile;
56
- // Check for package.json main field
57
- const packageJsonPath = path.join(baseDir, 'package.json');
58
- try {
59
- const fs = await import('node:fs');
60
- const packageJson = JSON.parse(fs.default.readFileSync(packageJsonPath, 'utf-8'));
61
- if (packageJson.main) {
62
- entryFile = path.join(baseDir, packageJson.main);
63
- this.logger.debug('connect', `Using package.json main: ${packageJson.main}`);
64
- }
65
- else {
66
- throw new Error('No main field in package.json');
67
- }
68
- }
69
- catch (error) {
70
- // Fallback to common entry points
71
- const fs = await import('node:fs');
72
- const commonEntries = ['service.js', 'index.js', 'index.mjs'];
73
- entryFile = '';
74
- for (const entry of commonEntries) {
75
- const testPath = path.join(baseDir, entry);
76
- if (fs.default.existsSync(testPath)) {
77
- entryFile = testPath;
78
- this.logger.debug('connect', `Using fallback entry: ${entry}`);
79
- break;
80
- }
81
- }
82
- if (!entryFile) {
83
- throw new Error(`No entry point found in ${baseDir}`);
84
- }
85
- }
86
- this.logger.debug('connect', `Importing from: ${entryFile}`);
87
- // Import the actual file
88
- const mod = await import(entryFile);
89
- rawModule = mod.default || mod;
90
- this.logger.debug('connect', `Successfully imported module`);
91
- }
92
- catch (error) {
93
- const errorMessage = error instanceof Error ? error.message : String(error);
94
- this.logger.error('connect', `Failed to import ability: ${errorMessage}`);
95
- // Provide helpful error message
96
- throw new Error(`Cannot load ability '${abilityName}' from ${abilityDir}. ` +
97
- `Make sure the ability has either:\n` +
98
- ` 1. A package.json with a "main" field pointing to the entry file\n` +
99
- ` 2. An index.js file in the root directory\n` +
100
- `Original error: ${errorMessage}`);
101
- }
102
- finally {
103
- // Restore original environment
104
- if (originalProtocol !== undefined) {
105
- process.env.KADI_PROTOCOL = originalProtocol;
106
- }
107
- else {
108
- delete process.env.KADI_PROTOCOL;
109
- }
110
- }
111
- // Extract methods from the imported module
112
- await this.extractMethods(rawModule, abilityName);
113
- this.connected = true;
114
- this.logger.lifecycle('connect', 'Native ability loaded successfully');
115
- this.emit('connected');
116
- }
117
- /**
118
- * Extract methods from the loaded module
119
- *
120
- * Handles different export formats:
121
- * - KadiClient/KadiAbility instances
122
- * - Plain objects with function properties
123
- * - Class constructors
124
- */
125
- async extractMethods(rawModule, abilityName) {
126
- if (typeof rawModule === 'object' && rawModule !== null) {
127
- // Check if this is a KadiClient or KadiAbility instance
128
- if (rawModule.constructor?.name === 'KadiClient' ||
129
- rawModule.constructor?.name === 'KadiAbility' ||
130
- typeof rawModule.getToolNames === 'function') {
131
- this.logger.debug('extractMethods', 'Detected KadiClient/KadiAbility instance');
132
- // Extract methods from KadiClient/KadiAbility
133
- const methodNames = rawModule.getToolNames();
134
- for (const methodName of methodNames) {
135
- const handler = rawModule.getToolHandler(methodName);
136
- if (handler) {
137
- this.methodHandlers.set(methodName, handler);
138
- }
139
- }
140
- this.ability = rawModule;
141
- // Forward events if the ability supports them
142
- if (typeof rawModule.on === 'function') {
143
- /**
144
- * Listen for the internal transport event from the loaded ability.
145
- * KadiClient instances emit __KADI_INTERNAL_ABILITY_EVENT_TRANSPORT__ when
146
- * they publish events in native mode. We catch these and forward them
147
- * to the AbilityProxy as regular 'event' emissions.
148
- */
149
- const ABILITY_EVENT_TRANSPORT = '__KADI_INTERNAL_ABILITY_EVENT_TRANSPORT__';
150
- this.logger.trace('extractMethods', `Setting up ${ABILITY_EVENT_TRANSPORT} listener on rawModule`);
151
- rawModule.on(ABILITY_EVENT_TRANSPORT, (eventData) => {
152
- this.logger.trace('extractMethods', `Received ${ABILITY_EVENT_TRANSPORT} from rawModule: ${JSON.stringify(eventData)}`);
153
- this.logger.debug('extractMethods', 'Emitting event on transport');
154
- this.emit('event', eventData);
155
- });
156
- }
157
- else {
158
- this.logger.debug('extractMethods', 'rawModule does not support .on() method');
159
- }
160
- }
161
- else {
162
- // Plain object with methods as properties
163
- this.logger.debug('extractMethods', 'Processing plain object with methods');
164
- for (const [key, value] of Object.entries(rawModule)) {
165
- if (typeof value === 'function' && !key.startsWith('_')) {
166
- this.methodHandlers.set(key, value);
167
- }
168
- }
169
- this.ability = rawModule;
170
- }
171
- }
172
- else if (typeof rawModule === 'function') {
173
- // Class constructor - instantiate and extract methods
174
- this.logger.debug('extractMethods', 'Processing class constructor');
175
- const instance = new rawModule();
176
- const prototype = Object.getPrototypeOf(instance);
177
- const methodNames = Object.getOwnPropertyNames(prototype).filter((name) => name !== 'constructor' &&
178
- !name.startsWith('_') &&
179
- typeof prototype[name] === 'function');
180
- for (const name of methodNames) {
181
- const method = instance[name];
182
- if (typeof method === 'function') {
183
- this.methodHandlers.set(name, method.bind(instance));
184
- }
185
- }
186
- this.ability = instance;
187
- }
188
- else {
189
- throw new Error(`Unsupported module export type for ability '${abilityName}'`);
190
- }
191
- this.logger.info('extractMethods', `Extracted ${this.methodHandlers.size} methods from ${abilityName}`);
192
- }
193
- /**
194
- * Invoke a method on the loaded ability
195
- *
196
- * Since this is native, we just call the function directly
197
- * with no serialization overhead.
198
- */
199
- async invoke(method, params) {
200
- if (!this.connected) {
201
- throw new Error('Native ability not loaded');
202
- }
203
- this.logger.trace('invoke', `Invoking method: ${method}`);
204
- const handler = this.methodHandlers.get(method);
205
- if (!handler) {
206
- throw new Error(`Method '${method}' not found in native ability`);
207
- }
208
- try {
209
- // Direct function call - no serialization needed
210
- const result = await handler(params);
211
- this.logger.trace('invoke', `Method ${method} completed successfully`);
212
- return result;
213
- }
214
- catch (error) {
215
- this.logger.error('invoke', `Method ${method} failed: ${error}`);
216
- throw error;
217
- }
218
- }
219
- /**
220
- * Get list of available methods
221
- */
222
- getMethods() {
223
- return Array.from(this.methodHandlers.keys());
224
- }
225
- /**
226
- * Get schema for a specific method (if available)
227
- */
228
- getMethodSchema(method) {
229
- // If the ability is a KadiClient/KadiAbility, it might have schema info
230
- if (this.ability && typeof this.ability.getMethodSchema === 'function') {
231
- return this.ability.getMethodSchema(method);
232
- }
233
- return undefined;
234
- }
235
- /**
236
- * Disconnect and cleanup
237
- *
238
- * Releases references to the loaded module to allow garbage collection
239
- */
240
- async disconnect() {
241
- this.logger.lifecycle('disconnect', 'Disconnecting native transport');
242
- // Call the ability's disconnect method if it exists
243
- // This is crucial for native abilities to clean up properly.
244
- // When an ability is loaded natively, it may have called serve()
245
- // which creates a promise keeping the process alive. Calling
246
- // disconnect() on the ability resolves that promise.
247
- if (this.ability && typeof this.ability.disconnect === 'function') {
248
- this.logger.debug('disconnect', 'Calling ability disconnect method');
249
- await this.ability.disconnect();
250
- }
251
- this.ability = undefined;
252
- this.methodHandlers.clear();
253
- this.connected = false;
254
- this.emit('disconnected');
255
- }
256
- /**
257
- * Check if transport is connected
258
- */
259
- isConnected() {
260
- return this.connected;
261
- }
262
- }
263
- //# sourceMappingURL=NativeTransport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativeTransport.js","sourceRoot":"","sources":["../../src/transports/NativeTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAmB,MAAM,oBAAoB,CAAC;AAiB5E;;;;;;GAMG;AACH,MAAM,OAAO,eAAgB,SAAQ,YAAY;IAM3B;IALZ,MAAM,CAAa;IACnB,OAAO,CAAM;IACb,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAC;IAClD,SAAS,GAAG,KAAK,CAAC;IAE1B,YAAoB,OAA+B;QACjD,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAAwB;QAEjD,IAAI,CAAC,MAAM,GAAG,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAEvD,IAAI,CAAC,MAAM,CAAC,SAAS,CACnB,aAAa,EACb,iCAAiC,OAAO,CAAC,WAAW,EAAE,CACvD,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEjD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,WAAW,WAAW,mBAAmB,CAAC,CAAC;QAC5E,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,wBAAwB,UAAU,EAAE,CAAC,CAAC;QACnE,I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tE,oDAAoD;QACpD,6DAA6D;QAC7D,iEAAiE;QACjE,6DAA6D;QAC7D,qDAAqD;QACrD,IAAI,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,mCAAmC,CAAC,CAAC;YACrE,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QAEvB,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF"}
@@ -1,112 +0,0 @@
1
- /**
2
- * StdioTransport - Handles stdio communication for abilities
3
- *
4
- * This transport operates in two modes:
5
- *
6
- * CLIENT MODE: Spawns an ability as a child process and calls its methods
7
- * - Parent process sends JSON-RPC requests to child's stdin
8
- * - Child process sends JSON-RPC responses back via stdout
9
- *
10
- * SERVER MODE: Serves an ability's methods via stdio (when running as a child)
11
- * - Reads JSON-RPC requests from stdin
12
- * - Writes JSON-RPC responses to stdout
13
- *
14
- * Both modes use LSP-style message framing for reliable communication.
15
- * The transport handles all the complexity of:
16
- * - Process spawning and lifecycle management (client mode)
17
- * - Message framing and buffering
18
- * - Request/response correlation
19
- * - Timeout handling
20
- */
21
- import { EventEmitter } from 'events';
22
- import { Transport, TransportOptions } from './Transport.js';
23
- /**
24
- * Options specific to StdioTransport
25
- */
26
- interface StdioTransportOptions extends TransportOptions {
27
- /**
28
- * Directory where the ability code is located
29
- */
30
- abilityDir: string;
31
- /**
32
- * Command to start the ability process
33
- */
34
- startCmd: string;
35
- /**
36
- * Optional timeout override (milliseconds)
37
- */
38
- timeoutMs?: number;
39
- }
40
- /**
41
- * StdioTransport - Manages child process abilities via stdio
42
- *
43
- * This transport provides process isolation and language independence.
44
- * The ability runs in a separate process and can be written in any
45
- * language that supports JSON-RPC over stdio.
46
- */
47
- export declare class StdioTransport extends EventEmitter implements Transport {
48
- private options;
49
- private logger;
50
- private process?;
51
- private reader?;
52
- private writer?;
53
- private connected;
54
- private pending;
55
- private nextId;
56
- constructor(options: StdioTransportOptions);
57
- /**
58
- * Connect by spawning the child process
59
- *
60
- * This method spawns the ability as a child process and sets up
61
- * the stdio communication channels.
62
- */
63
- connect(): Promise<void>;
64
- /**
65
- * Handle incoming message from child process
66
- */
67
- private handleMessage;
68
- /**
69
- * Invoke a method on the child process ability
70
- *
71
- * Sends a JSON-RPC request to the child and waits for the response.
72
- */
73
- invoke(method: string, params: unknown): Promise<unknown>;
74
- /**
75
- * Get list of available methods
76
- */
77
- getMethods(): string[];
78
- /**
79
- * Disconnect and cleanup
80
- *
81
- * Terminates the child process and cleans up resources.
82
- */
83
- disconnect(): Promise<void>;
84
- /**
85
- * Cleanup resources
86
- */
87
- private cleanup;
88
- /**
89
- * Check if transport is connected
90
- */
91
- isConnected(): boolean;
92
- /**
93
- * Publish an event to the parent process (when serving as child)
94
- */
95
- publishEvent(eventName: string, data: unknown): void;
96
- /**
97
- * Serve an ability via stdio (server mode)
98
- *
99
- * This method is used when the transport needs to serve an ability's methods
100
- * via stdio (when running as a child process). It reads JSON-RPC requests
101
- * from stdin and writes responses to stdout.
102
- *
103
- * @param ability - The ability (KadiClient) to serve
104
- */
105
- serve(ability: {
106
- name: string;
107
- getToolNames: () => string[];
108
- getToolHandler: (method: string) => ((p: unknown) => Promise<unknown>) | undefined;
109
- }): Promise<void>;
110
- }
111
- export {};
112
- //# sourceMappingURL=StdioTransport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StdioTransport.d.ts","sourceRoot":"","sources":["../../src/transports/StdioTransport.ts"],"names":[],"mappings":"AAA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