@kadi.build/core 0.0.1-alpha.9 → 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.
- package/README.md +362 -1305
- package/dist/client.d.ts +573 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1673 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +107 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +147 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +37 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -23
- package/dist/index.js.map +1 -1
- package/dist/lockfile.d.ts +190 -0
- package/dist/lockfile.d.ts.map +1 -0
- package/dist/lockfile.js +373 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/transports/broker.d.ts +75 -0
- package/dist/transports/broker.d.ts.map +1 -0
- package/dist/transports/broker.js +383 -0
- package/dist/transports/broker.js.map +1 -0
- package/dist/transports/native.d.ts +39 -0
- package/dist/transports/native.d.ts.map +1 -0
- package/dist/transports/native.js +189 -0
- package/dist/transports/native.js.map +1 -0
- package/dist/transports/stdio.d.ts +46 -0
- package/dist/transports/stdio.d.ts.map +1 -0
- package/dist/transports/stdio.js +460 -0
- package/dist/transports/stdio.js.map +1 -0
- package/dist/types.d.ts +664 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/dist/zod.d.ts +34 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +60 -0
- package/dist/zod.js.map +1 -0
- package/package.json +13 -28
- package/dist/KadiClient.d.ts +0 -470
- package/dist/KadiClient.d.ts.map +0 -1
- package/dist/KadiClient.js +0 -1572
- package/dist/KadiClient.js.map +0 -1
- package/dist/errors/error-codes.d.ts +0 -985
- package/dist/errors/error-codes.d.ts.map +0 -1
- package/dist/errors/error-codes.js +0 -638
- package/dist/errors/error-codes.js.map +0 -1
- package/dist/loadAbility.d.ts +0 -105
- package/dist/loadAbility.d.ts.map +0 -1
- package/dist/loadAbility.js +0 -370
- package/dist/loadAbility.js.map +0 -1
- package/dist/messages/BrokerMessages.d.ts +0 -84
- package/dist/messages/BrokerMessages.d.ts.map +0 -1
- package/dist/messages/BrokerMessages.js +0 -125
- package/dist/messages/BrokerMessages.js.map +0 -1
- package/dist/messages/MessageBuilder.d.ts +0 -83
- package/dist/messages/MessageBuilder.d.ts.map +0 -1
- package/dist/messages/MessageBuilder.js +0 -144
- package/dist/messages/MessageBuilder.js.map +0 -1
- package/dist/schemas/events.schemas.d.ts +0 -177
- package/dist/schemas/events.schemas.d.ts.map +0 -1
- package/dist/schemas/events.schemas.js +0 -265
- package/dist/schemas/events.schemas.js.map +0 -1
- package/dist/schemas/index.d.ts +0 -3
- package/dist/schemas/index.d.ts.map +0 -1
- package/dist/schemas/index.js +0 -4
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/kadi.schemas.d.ts +0 -70
- package/dist/schemas/kadi.schemas.d.ts.map +0 -1
- package/dist/schemas/kadi.schemas.js +0 -120
- package/dist/schemas/kadi.schemas.js.map +0 -1
- package/dist/transports/BrokerTransport.d.ts +0 -102
- package/dist/transports/BrokerTransport.d.ts.map +0 -1
- package/dist/transports/BrokerTransport.js +0 -177
- package/dist/transports/BrokerTransport.js.map +0 -1
- package/dist/transports/NativeTransport.d.ts +0 -82
- package/dist/transports/NativeTransport.d.ts.map +0 -1
- package/dist/transports/NativeTransport.js +0 -263
- package/dist/transports/NativeTransport.js.map +0 -1
- package/dist/transports/StdioTransport.d.ts +0 -112
- package/dist/transports/StdioTransport.d.ts.map +0 -1
- package/dist/transports/StdioTransport.js +0 -450
- package/dist/transports/StdioTransport.js.map +0 -1
- package/dist/transports/Transport.d.ts +0 -93
- package/dist/transports/Transport.d.ts.map +0 -1
- package/dist/transports/Transport.js +0 -13
- package/dist/transports/Transport.js.map +0 -1
- package/dist/types/broker.d.ts +0 -31
- package/dist/types/broker.d.ts.map +0 -1
- package/dist/types/broker.js +0 -6
- package/dist/types/broker.js.map +0 -1
- package/dist/types/core.d.ts +0 -139
- package/dist/types/core.d.ts.map +0 -1
- package/dist/types/core.js +0 -26
- package/dist/types/core.js.map +0 -1
- package/dist/types/events.d.ts +0 -186
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js +0 -16
- package/dist/types/events.js.map +0 -1
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -13
- package/dist/types/index.js.map +0 -1
- package/dist/types/protocol.d.ts +0 -160
- package/dist/types/protocol.d.ts.map +0 -1
- package/dist/types/protocol.js +0 -5
- package/dist/types/protocol.js.map +0 -1
- package/dist/utils/agentUtils.d.ts +0 -187
- package/dist/utils/agentUtils.d.ts.map +0 -1
- package/dist/utils/agentUtils.js +0 -185
- package/dist/utils/agentUtils.js.map +0 -1
- package/dist/utils/commandUtils.d.ts +0 -45
- package/dist/utils/commandUtils.d.ts.map +0 -1
- package/dist/utils/commandUtils.js +0 -145
- package/dist/utils/commandUtils.js.map +0 -1
- package/dist/utils/configUtils.d.ts +0 -55
- package/dist/utils/configUtils.d.ts.map +0 -1
- package/dist/utils/configUtils.js +0 -100
- package/dist/utils/configUtils.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -59
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -122
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/pathUtils.d.ts +0 -48
- package/dist/utils/pathUtils.d.ts.map +0 -1
- package/dist/utils/pathUtils.js +0 -128
- package/dist/utils/pathUtils.js.map +0 -1
|
@@ -1,450 +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 { spawn } from 'node:child_process';
|
|
22
|
-
import path from 'node:path';
|
|
23
|
-
import fs from 'node:fs';
|
|
24
|
-
import { EventEmitter } from 'events';
|
|
25
|
-
import { createComponentLogger } from '../utils/logger.js';
|
|
26
|
-
// Constants for frame handling and timeouts
|
|
27
|
-
const DEFAULT_BUFFER_SIZE = 8 * 1024 * 1024; // 8MB max buffer size
|
|
28
|
-
const HEADER_SEARCH_WINDOW = 100; // bytes to keep when seeking headers
|
|
29
|
-
const PROCESS_START_DELAY_MS = 500; // delay after spawning process
|
|
30
|
-
/**
|
|
31
|
-
* FrameReader - Reads LSP-style framed JSON messages from a stream
|
|
32
|
-
*
|
|
33
|
-
* This class solves the "message boundary" problem when reading from streams.
|
|
34
|
-
* When you read from stdin/stdout, data arrives in chunks that don't align
|
|
35
|
-
* with message boundaries. FrameReader ensures we extract complete messages.
|
|
36
|
-
*
|
|
37
|
-
* THE FRAMING PROTOCOL (LSP-style with KADI header):
|
|
38
|
-
* Each message has this structure:
|
|
39
|
-
* Kadi-Content-Length: 123\r\n\r\n{"jsonrpc":"2.0",...}
|
|
40
|
-
*/
|
|
41
|
-
class FrameReader {
|
|
42
|
-
input;
|
|
43
|
-
onMessage;
|
|
44
|
-
buffer = Buffer.alloc(0); // Accumulates data chunks as they arrive
|
|
45
|
-
maxBufferSize;
|
|
46
|
-
logger;
|
|
47
|
-
constructor(input, // The stream to read from (like process.stdout)
|
|
48
|
-
onMessage, // Callback when complete message is parsed
|
|
49
|
-
maxBufferSize = DEFAULT_BUFFER_SIZE, // 8MB limit to prevent memory exhaustion
|
|
50
|
-
logger // Logger for reporting skipped bytes
|
|
51
|
-
) {
|
|
52
|
-
this.input = input;
|
|
53
|
-
this.onMessage = onMessage;
|
|
54
|
-
this.maxBufferSize = maxBufferSize;
|
|
55
|
-
this.logger = logger || createComponentLogger('FrameReader');
|
|
56
|
-
// Listen for data chunks and process them as they arrive
|
|
57
|
-
this.input.on('data', (chunk) => this.handleData(chunk));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Process incoming data chunks and extract complete messages
|
|
61
|
-
*/
|
|
62
|
-
handleData(chunk) {
|
|
63
|
-
// Add new chunk to our accumulation buffer
|
|
64
|
-
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
65
|
-
// Safety check: prevent memory exhaustion from malformed streams
|
|
66
|
-
if (this.buffer.length > this.maxBufferSize) {
|
|
67
|
-
this.logger.error('handleData', `Buffer overflow: ${this.buffer.length} bytes`);
|
|
68
|
-
this.buffer = Buffer.alloc(0);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// Process all complete messages in the buffer
|
|
72
|
-
let processed = true;
|
|
73
|
-
while (processed && this.buffer.length > 0) {
|
|
74
|
-
processed = this.processFrame();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Process a single frame from the buffer
|
|
79
|
-
*/
|
|
80
|
-
processFrame() {
|
|
81
|
-
// Look for frame header
|
|
82
|
-
const headerEnd = this.buffer.indexOf('\r\n\r\n');
|
|
83
|
-
if (headerEnd === -1) {
|
|
84
|
-
// No complete header yet, check if buffer is getting too large
|
|
85
|
-
if (this.buffer.length > HEADER_SEARCH_WINDOW) {
|
|
86
|
-
// Skip garbage bytes
|
|
87
|
-
const skipped = this.buffer.length - HEADER_SEARCH_WINDOW;
|
|
88
|
-
this.logger.debug('processFrame', `Skipping ${skipped} garbage bytes`);
|
|
89
|
-
this.buffer = this.buffer.slice(skipped);
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
// Parse header
|
|
94
|
-
const headerBytes = this.buffer.slice(0, headerEnd);
|
|
95
|
-
const headerText = headerBytes.toString('utf8');
|
|
96
|
-
// Extract content length
|
|
97
|
-
const match = headerText.match(/Kadi-Content-Length:\s*(\d+)/i);
|
|
98
|
-
if (!match) {
|
|
99
|
-
// Invalid header, skip it
|
|
100
|
-
this.buffer = this.buffer.slice(headerEnd + 4);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
const contentLength = parseInt(match[1], 10);
|
|
104
|
-
const totalLength = headerEnd + 4 + contentLength;
|
|
105
|
-
// Check if we have the complete message
|
|
106
|
-
if (this.buffer.length < totalLength) {
|
|
107
|
-
return false; // Wait for more data
|
|
108
|
-
}
|
|
109
|
-
// Extract message content
|
|
110
|
-
const messageBytes = this.buffer.slice(headerEnd + 4, totalLength);
|
|
111
|
-
const messageText = messageBytes.toString('utf8');
|
|
112
|
-
// Parse JSON and emit
|
|
113
|
-
try {
|
|
114
|
-
const message = JSON.parse(messageText);
|
|
115
|
-
this.onMessage(message);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
this.logger.error('processFrame', `Failed to parse JSON: ${e}`);
|
|
119
|
-
}
|
|
120
|
-
// Remove processed message from buffer
|
|
121
|
-
this.buffer = this.buffer.slice(totalLength);
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* FrameWriter - Writes LSP-style framed JSON messages to a stream
|
|
127
|
-
*/
|
|
128
|
-
class FrameWriter {
|
|
129
|
-
output;
|
|
130
|
-
constructor(output) {
|
|
131
|
-
this.output = output;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Write a JSON message using LSP-style framing
|
|
135
|
-
*
|
|
136
|
-
* IMPORTANT: Content-Length is calculated in bytes, not characters.
|
|
137
|
-
* This matters for UTF-8 strings where some characters use multiple bytes.
|
|
138
|
-
*/
|
|
139
|
-
write(message) {
|
|
140
|
-
// Convert message to JSON string
|
|
141
|
-
const json = JSON.stringify(message);
|
|
142
|
-
// Convert to UTF-8 bytes and measure actual byte length
|
|
143
|
-
const jsonBuffer = Buffer.from(json, 'utf8');
|
|
144
|
-
const contentLength = jsonBuffer.length;
|
|
145
|
-
// Create the LSP-style header
|
|
146
|
-
const header = `Kadi-Content-Length: ${contentLength}\r\n\r\n`;
|
|
147
|
-
const headerBuffer = Buffer.from(header, 'utf8');
|
|
148
|
-
// Write header + content as single atomic operation
|
|
149
|
-
this.output.write(Buffer.concat([headerBuffer, jsonBuffer]));
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* StdioTransport - Manages child process abilities via stdio
|
|
154
|
-
*
|
|
155
|
-
* This transport provides process isolation and language independence.
|
|
156
|
-
* The ability runs in a separate process and can be written in any
|
|
157
|
-
* language that supports JSON-RPC over stdio.
|
|
158
|
-
*/
|
|
159
|
-
export class StdioTransport extends EventEmitter {
|
|
160
|
-
options;
|
|
161
|
-
logger;
|
|
162
|
-
process;
|
|
163
|
-
reader;
|
|
164
|
-
writer;
|
|
165
|
-
connected = false;
|
|
166
|
-
pending = new Map();
|
|
167
|
-
nextId = 1;
|
|
168
|
-
constructor(options) {
|
|
169
|
-
super();
|
|
170
|
-
this.options = options;
|
|
171
|
-
this.logger = createComponentLogger('StdioTransport');
|
|
172
|
-
this.logger.lifecycle('constructor', `Creating stdio transport for ${options.abilityName}`);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Connect by spawning the child process
|
|
176
|
-
*
|
|
177
|
-
* This method spawns the ability as a child process and sets up
|
|
178
|
-
* the stdio communication channels.
|
|
179
|
-
*/
|
|
180
|
-
async connect() {
|
|
181
|
-
const { abilityName, abilityDir, startCmd } = this.options;
|
|
182
|
-
this.logger.lifecycle('connect', `Loading ${abilityName} with stdio transport`);
|
|
183
|
-
// Set KADI_PROTOCOL environment variable so the child knows how it's being run
|
|
184
|
-
const env = { ...process.env, KADI_PROTOCOL: 'stdio' };
|
|
185
|
-
const logFile = path.join(abilityDir, `${abilityName}.log`);
|
|
186
|
-
this.logger.debug('connect', 'Spawning child process', {
|
|
187
|
-
KADI_PROTOCOL: env.KADI_PROTOCOL,
|
|
188
|
-
startCmd,
|
|
189
|
-
cwd: abilityDir
|
|
190
|
-
});
|
|
191
|
-
// Spawn the child process that will run the ability
|
|
192
|
-
// stdio: ['pipe', 'pipe', 'pipe'] creates pipes for stdin, stdout, stderr
|
|
193
|
-
this.process = spawn(startCmd, {
|
|
194
|
-
cwd: abilityDir,
|
|
195
|
-
env,
|
|
196
|
-
shell: true,
|
|
197
|
-
stdio: ['pipe', 'pipe', 'pipe']
|
|
198
|
-
});
|
|
199
|
-
this.logger.info('connect', `Child process spawned with PID: ${this.process.pid}`);
|
|
200
|
-
// Setup optional logging for stderr
|
|
201
|
-
if (logFile) {
|
|
202
|
-
try {
|
|
203
|
-
fs.mkdirSync(path.dirname(logFile), { recursive: true });
|
|
204
|
-
const logStream = fs.createWriteStream(logFile, { flags: 'a' });
|
|
205
|
-
this.process.stderr?.pipe(logStream);
|
|
206
|
-
}
|
|
207
|
-
catch (e) {
|
|
208
|
-
this.logger.warn('connect', `Unable to open log file: ${logFile}`, e);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// Setup frame-based communication with the child process
|
|
212
|
-
this.reader = new FrameReader(this.process.stdout, (msg) => this.handleMessage(msg), DEFAULT_BUFFER_SIZE, this.logger);
|
|
213
|
-
this.writer = new FrameWriter(this.process.stdin);
|
|
214
|
-
// Handle process events
|
|
215
|
-
this.process.on('error', (error) => {
|
|
216
|
-
this.logger.error('connect', 'Process error', error);
|
|
217
|
-
this.cleanup();
|
|
218
|
-
this.emit('error', error);
|
|
219
|
-
});
|
|
220
|
-
this.process.on('exit', (code, signal) => {
|
|
221
|
-
this.logger.lifecycle('connect', `Process exited with code ${code}, signal ${signal}`);
|
|
222
|
-
// Only cleanup if we haven't already
|
|
223
|
-
if (this.connected) {
|
|
224
|
-
this.cleanup();
|
|
225
|
-
this.emit('disconnected');
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
// Wait a moment for the process to start
|
|
229
|
-
await new Promise((resolve) => setTimeout(resolve, PROCESS_START_DELAY_MS));
|
|
230
|
-
this.connected = true;
|
|
231
|
-
this.logger.lifecycle('connect', 'Stdio connection established');
|
|
232
|
-
this.emit('connected');
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Handle incoming message from child process
|
|
236
|
-
*/
|
|
237
|
-
handleMessage(msg) {
|
|
238
|
-
const message = msg;
|
|
239
|
-
// Check if it's a response to one of our requests
|
|
240
|
-
if ('id' in message && message.id !== null && message.id !== undefined) {
|
|
241
|
-
// Type guard to ensure we have a response with valid id
|
|
242
|
-
const messageId = message.id;
|
|
243
|
-
if (this.pending.has(messageId)) {
|
|
244
|
-
const pending = this.pending.get(messageId);
|
|
245
|
-
if (!pending)
|
|
246
|
-
return;
|
|
247
|
-
if (pending.timer)
|
|
248
|
-
clearTimeout(pending.timer);
|
|
249
|
-
this.pending.delete(messageId);
|
|
250
|
-
// Type guard for response
|
|
251
|
-
const response = message;
|
|
252
|
-
if ('error' in response && response.error) {
|
|
253
|
-
pending.reject(new Error(response.error.message));
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
pending.resolve(response.result);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// Handle notifications or events from the child
|
|
261
|
-
if ('method' in message && !('id' in message)) {
|
|
262
|
-
this.emit('notification', message);
|
|
263
|
-
// Check for specific event types
|
|
264
|
-
if (message.method === '__kadi_event') {
|
|
265
|
-
const params = message.params;
|
|
266
|
-
if (params && params.eventName) {
|
|
267
|
-
this.emit('event', { name: params.eventName, data: params.data });
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Invoke a method on the child process ability
|
|
274
|
-
*
|
|
275
|
-
* Sends a JSON-RPC request to the child and waits for the response.
|
|
276
|
-
*/
|
|
277
|
-
async invoke(method, params) {
|
|
278
|
-
if (!this.connected || !this.writer) {
|
|
279
|
-
throw new Error('Not connected to stdio process');
|
|
280
|
-
}
|
|
281
|
-
const id = this.nextId++;
|
|
282
|
-
const request = {
|
|
283
|
-
jsonrpc: '2.0',
|
|
284
|
-
method,
|
|
285
|
-
params,
|
|
286
|
-
id
|
|
287
|
-
};
|
|
288
|
-
return new Promise((resolve, reject) => {
|
|
289
|
-
// Store pending request (no default timeout)
|
|
290
|
-
this.pending.set(id, { resolve, reject });
|
|
291
|
-
// Send request to child
|
|
292
|
-
try {
|
|
293
|
-
this.writer.write(request);
|
|
294
|
-
this.logger.trace('invoke', `Sent request ${id}: ${method}`);
|
|
295
|
-
}
|
|
296
|
-
catch (error) {
|
|
297
|
-
this.pending.delete(id);
|
|
298
|
-
reject(error);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Get list of available methods
|
|
304
|
-
*/
|
|
305
|
-
getMethods() {
|
|
306
|
-
return [];
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Disconnect and cleanup
|
|
310
|
-
*
|
|
311
|
-
* Terminates the child process and cleans up resources.
|
|
312
|
-
*/
|
|
313
|
-
async disconnect() {
|
|
314
|
-
this.logger.lifecycle('disconnect', 'Disconnecting stdio transport');
|
|
315
|
-
if (this.process && !this.process.killed) {
|
|
316
|
-
// Try graceful shutdown first
|
|
317
|
-
this.process.kill('SIGTERM');
|
|
318
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
319
|
-
// Force kill if still running
|
|
320
|
-
// Check this.process again as it might be cleared by exit handler
|
|
321
|
-
if (this.process && !this.process.killed) {
|
|
322
|
-
this.process.kill('SIGKILL');
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
this.cleanup();
|
|
326
|
-
this.emit('disconnected');
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Cleanup resources
|
|
330
|
-
*/
|
|
331
|
-
cleanup() {
|
|
332
|
-
// Clear pending requests
|
|
333
|
-
for (const [, pending] of this.pending) {
|
|
334
|
-
if (pending.timer)
|
|
335
|
-
clearTimeout(pending.timer);
|
|
336
|
-
pending.reject(new Error('Connection closed'));
|
|
337
|
-
}
|
|
338
|
-
this.pending.clear();
|
|
339
|
-
this.process = undefined;
|
|
340
|
-
this.reader = undefined;
|
|
341
|
-
this.writer = undefined;
|
|
342
|
-
this.connected = false;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Check if transport is connected
|
|
346
|
-
*/
|
|
347
|
-
isConnected() {
|
|
348
|
-
return this.connected;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Publish an event to the parent process (when serving as child)
|
|
352
|
-
*/
|
|
353
|
-
publishEvent(eventName, data) {
|
|
354
|
-
this.logger.debug('publishEvent', `Publishing event via stdio: ${eventName}`);
|
|
355
|
-
if (!this.writer) {
|
|
356
|
-
this.logger.warn('publishEvent', 'No writer available for event publishing');
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
const notification = {
|
|
360
|
-
jsonrpc: '2.0',
|
|
361
|
-
method: '__kadi_event',
|
|
362
|
-
params: {
|
|
363
|
-
eventName,
|
|
364
|
-
data,
|
|
365
|
-
timestamp: Date.now()
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
this.logger.trace('publishEvent', `Writing stdio event notification: ${JSON.stringify(notification)}`);
|
|
369
|
-
this.writer.write(notification);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Serve an ability via stdio (server mode)
|
|
373
|
-
*
|
|
374
|
-
* This method is used when the transport needs to serve an ability's methods
|
|
375
|
-
* via stdio (when running as a child process). It reads JSON-RPC requests
|
|
376
|
-
* from stdin and writes responses to stdout.
|
|
377
|
-
*
|
|
378
|
-
* @param ability - The ability (KadiClient) to serve
|
|
379
|
-
*/
|
|
380
|
-
async serve(ability) {
|
|
381
|
-
this.logger.lifecycle('serve', `Serving ${ability.name} via stdio`);
|
|
382
|
-
// In server mode, we read from stdin and write to stdout
|
|
383
|
-
// Keep both a local 'writer' and 'this.writer': local avoids non-null
|
|
384
|
-
// assertions inside closures; instance lets publishEvent() use it elsewhere.
|
|
385
|
-
const writer = new FrameWriter(process.stdout);
|
|
386
|
-
this.writer = writer;
|
|
387
|
-
const reader = new FrameReader(process.stdin, (msg) => {
|
|
388
|
-
const request = msg;
|
|
389
|
-
const { id, method, params } = request;
|
|
390
|
-
void (async () => {
|
|
391
|
-
try {
|
|
392
|
-
// Handle discovery request (use __kadi_list to match old handler)
|
|
393
|
-
if (method === '__kadi_list') {
|
|
394
|
-
const response = {
|
|
395
|
-
jsonrpc: '2.0',
|
|
396
|
-
result: {
|
|
397
|
-
methods: ability.getToolNames()
|
|
398
|
-
},
|
|
399
|
-
id
|
|
400
|
-
};
|
|
401
|
-
writer.write(response);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
// Handle method invocation
|
|
405
|
-
const handler = ability.getToolHandler(method);
|
|
406
|
-
if (!handler) {
|
|
407
|
-
const response = {
|
|
408
|
-
jsonrpc: '2.0',
|
|
409
|
-
error: {
|
|
410
|
-
code: -32601,
|
|
411
|
-
message: `Method '${method}' not found`
|
|
412
|
-
},
|
|
413
|
-
id
|
|
414
|
-
};
|
|
415
|
-
writer.write(response);
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
// Execute the method
|
|
419
|
-
const result = await handler(params);
|
|
420
|
-
const response = {
|
|
421
|
-
jsonrpc: '2.0',
|
|
422
|
-
result,
|
|
423
|
-
id
|
|
424
|
-
};
|
|
425
|
-
writer.write(response);
|
|
426
|
-
}
|
|
427
|
-
catch (error) {
|
|
428
|
-
const response = {
|
|
429
|
-
jsonrpc: '2.0',
|
|
430
|
-
error: {
|
|
431
|
-
code: -32603,
|
|
432
|
-
message: error instanceof Error ? error.message : 'Internal error',
|
|
433
|
-
data: error instanceof Error ? error.stack : undefined
|
|
434
|
-
},
|
|
435
|
-
id
|
|
436
|
-
};
|
|
437
|
-
writer.write(response);
|
|
438
|
-
}
|
|
439
|
-
})();
|
|
440
|
-
}, DEFAULT_BUFFER_SIZE, this.logger);
|
|
441
|
-
this.reader = reader;
|
|
442
|
-
// Emit that we're ready to serve
|
|
443
|
-
this.emit('serving');
|
|
444
|
-
// Keep the process alive
|
|
445
|
-
return new Promise(() => {
|
|
446
|
-
// This promise never resolves, keeping the server running
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
//# sourceMappingURL=StdioTransport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StdioTransport.js","sourceRoot":"","sources":["../../src/transports/StdioTransport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,KAAK,EAAgB,MAAM,oBAAoB,CAAC;AACzD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,qBAAqB,EAAmB,MAAM,oBAAoB,CAAC;AAE5E,4CAA4C;AAC5C,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,sBAAsB;AACnE,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,qCAAqC;AACvE,MAAM,sBAAsB,GAAG,GAAG,CAAC,CAAC,+BAA+B;AAmDnE;;;;;;;;;;GAUG;AACH,MAAM,WAAW;IAML;IACA;IANF,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,yCAAyC;IAC1D,aAAa,CA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C;wBACF,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;wBACvB,OAAO;oBACT,CAAC;oBAED,qBAAqB;oBACrB,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;oBACrC,MAAM,QAAQ,GAAG;wBACf,OAAO,EAAE,KAAK;wBACd,MAAM;wBACN,EAAE;qBACH,CAAC;oBACF,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACzB,CAAC;gBAAC,OAAO,KAAc,EAAE,CAAC;oBACxB,MAAM,QAAQ,GAAG;wBACf,OAAO,EAAE,KAAK;wBACd,KAAK,EAAE;4BACL,IAAI,EAAE,CAAC,KAAK;4BACZ,OAAO,EACL,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB;4BAC3D,IAAI,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;yBACvD;wBACD,EAAE;qBACH,CAAC;oBACF,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,EACD,mBAAmB,EACnB,IAAI,CAAC,MAAM,CACZ,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,iCAAiC;QACjC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAErB,yBAAyB;QACzB,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;YACtB,0DAA0D;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transport Interface
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract that all protocol transports must implement.
|
|
5
|
-
* A transport is responsible for establishing connections and invoking
|
|
6
|
-
* methods across different communication protocols (native, stdio, broker, etc.)
|
|
7
|
-
*
|
|
8
|
-
* The Transport abstraction allows loadAbility() to work uniformly across
|
|
9
|
-
* all protocols, providing a consistent interface regardless of whether
|
|
10
|
-
* the ability is loaded locally, from a child process, or from a remote broker.
|
|
11
|
-
*/
|
|
12
|
-
import { EventEmitter } from 'events';
|
|
13
|
-
/**
|
|
14
|
-
* Transport interface that all protocol implementations must follow
|
|
15
|
-
*/
|
|
16
|
-
export interface Transport extends EventEmitter {
|
|
17
|
-
/**
|
|
18
|
-
* Establish connection to the ability/service
|
|
19
|
-
*
|
|
20
|
-
* For native: loads the module from disk
|
|
21
|
-
* For stdio: spawns the child process
|
|
22
|
-
* For broker: connects to WebSocket and authenticates
|
|
23
|
-
*/
|
|
24
|
-
connect(): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Invoke a method on the connected ability
|
|
27
|
-
*
|
|
28
|
-
* @param method - The method name to invoke
|
|
29
|
-
* @param params - The parameters to pass to the method
|
|
30
|
-
* @returns The result from the method invocation
|
|
31
|
-
* @throws Error if not connected or method fails
|
|
32
|
-
*/
|
|
33
|
-
invoke(method: string, params: unknown): Promise<unknown>;
|
|
34
|
-
/**
|
|
35
|
-
* Get the list of available methods
|
|
36
|
-
*
|
|
37
|
-
* For native: methods discovered from the loaded module
|
|
38
|
-
* For stdio: methods discovered via __kadi_discover
|
|
39
|
-
* For broker: methods discovered from the remote agent
|
|
40
|
-
*
|
|
41
|
-
* @returns Array of method names
|
|
42
|
-
*/
|
|
43
|
-
getMethods(): string[];
|
|
44
|
-
/**
|
|
45
|
-
* Disconnect and cleanup resources
|
|
46
|
-
*
|
|
47
|
-
* For native: cleanup module references
|
|
48
|
-
* For stdio: terminate child process
|
|
49
|
-
* For broker: close WebSocket connection
|
|
50
|
-
*/
|
|
51
|
-
disconnect(): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Optional: Get schema for a specific method
|
|
54
|
-
* Not all transports may support this
|
|
55
|
-
*
|
|
56
|
-
* @param method - The method name
|
|
57
|
-
* @returns The method schema if available
|
|
58
|
-
*/
|
|
59
|
-
getMethodSchema?(method: string): {
|
|
60
|
-
inputSchema?: unknown;
|
|
61
|
-
outputSchema?: unknown;
|
|
62
|
-
} | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* Optional: Publish an event from the ability
|
|
65
|
-
* Used when an ability needs to emit events to its parent/caller
|
|
66
|
-
*
|
|
67
|
-
* @param eventName - Name of the event
|
|
68
|
-
* @param data - Event data payload
|
|
69
|
-
*/
|
|
70
|
-
publishEvent?(eventName: string, data: unknown): void;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Base options for transport configuration
|
|
74
|
-
*/
|
|
75
|
-
export interface TransportOptions {
|
|
76
|
-
/**
|
|
77
|
-
* Name of the ability/agent being connected to
|
|
78
|
-
*/
|
|
79
|
-
abilityName: string;
|
|
80
|
-
/**
|
|
81
|
-
* Version of the ability (optional)
|
|
82
|
-
*/
|
|
83
|
-
abilityVersion?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Timeout for method invocations in milliseconds
|
|
86
|
-
*/
|
|
87
|
-
timeoutMs?: number;
|
|
88
|
-
/**
|
|
89
|
-
* Additional protocol-specific options
|
|
90
|
-
*/
|
|
91
|
-
[key: string]: unknown;
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=Transport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../../src/transports/Transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC7C;;;;;;OAMG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;;;;;;;OAQG;IACH,UAAU,IAAI,MAAM,EAAE,CAAC;IAEvB;;;;;;OAMG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B;;;;;;OAMG;IACH,eAAe,CAAC,CAAC,MAAM,EAAE,MAAM,GAC3B;QACE,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,GACD,SAAS,CAAC;IAEd;;;;;;OAMG;IACH,YAAY,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transport Interface
|
|
3
|
-
*
|
|
4
|
-
* Defines the contract that all protocol transports must implement.
|
|
5
|
-
* A transport is responsible for establishing connections and invoking
|
|
6
|
-
* methods across different communication protocols (native, stdio, broker, etc.)
|
|
7
|
-
*
|
|
8
|
-
* The Transport abstraction allows loadAbility() to work uniformly across
|
|
9
|
-
* all protocols, providing a consistent interface regardless of whether
|
|
10
|
-
* the ability is loaded locally, from a child process, or from a remote broker.
|
|
11
|
-
*/
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=Transport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../../src/transports/Transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
package/dist/types/broker.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Re-export protocol types for backward compatibility
|
|
3
|
-
* @deprecated Import directly from './protocol' instead
|
|
4
|
-
*/
|
|
5
|
-
export * from './protocol.js';
|
|
6
|
-
import { KadiProtocol, JsonRpcRequest } from './protocol.js';
|
|
7
|
-
export type KadiHelloParams = KadiProtocol.HelloParams;
|
|
8
|
-
export type KadiHelloResult = KadiProtocol.HelloResult;
|
|
9
|
-
export type KadiAuthenticateParams = KadiProtocol.AuthenticateParams;
|
|
10
|
-
export type KadiAuthenticateResult = KadiProtocol.AuthenticateResult;
|
|
11
|
-
export type KadiTool = KadiProtocol.Tool;
|
|
12
|
-
export type KadiRegisterCapabilitiesParams = KadiProtocol.RegisterCapabilitiesParams;
|
|
13
|
-
export type KadiRegisterCapabilitiesResult = KadiProtocol.RegisterCapabilitiesResult;
|
|
14
|
-
export type KadiCallAbilityParams = KadiProtocol.CallAbilityParams;
|
|
15
|
-
export type KadiAbilityResultParams = KadiProtocol.AbilityResultParams;
|
|
16
|
-
export interface BrokerMessageBuilder {
|
|
17
|
-
registerCapabilities(params: KadiRegisterCapabilitiesParams): MessageBuilder;
|
|
18
|
-
hello(params: KadiHelloParams): MessageBuilder;
|
|
19
|
-
authenticate(params: KadiAuthenticateParams): MessageBuilder;
|
|
20
|
-
callAbility(params: KadiCallAbilityParams): MessageBuilder;
|
|
21
|
-
abilityResult(params: KadiAbilityResultParams): MessageBuilder;
|
|
22
|
-
ping(): MessageBuilder;
|
|
23
|
-
listTools(): MessageBuilder;
|
|
24
|
-
}
|
|
25
|
-
export interface MessageBuilder {
|
|
26
|
-
params(obj: unknown): MessageBuilder;
|
|
27
|
-
id(id: string | number): MessageBuilder;
|
|
28
|
-
build(): JsonRpcRequest;
|
|
29
|
-
toString(): string;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/types/broker.ts"],"names":[],"mappings":"AAAA;;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ED
package/dist/types/broker.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/types/broker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,eAAe,CAAC"}
|