@braingrid/cli 0.0.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/CHANGELOG.md +17 -0
- package/README.md +7 -3
- package/dist/build-config.d.ts +4 -8
- package/dist/build-config.d.ts.map +1 -1
- package/dist/build-config.js +21 -8
- package/dist/build-config.js.map +1 -1
- package/dist/cli.js +297 -276
- package/dist/cli.js.map +1 -1
- package/dist/handlers/auth.handlers.d.ts +7 -1
- package/dist/handlers/auth.handlers.d.ts.map +1 -1
- package/dist/handlers/auth.handlers.js +80 -21
- package/dist/handlers/auth.handlers.js.map +1 -1
- package/dist/handlers/project.handlers.d.ts.map +1 -1
- package/dist/handlers/project.handlers.js +1 -0
- package/dist/handlers/project.handlers.js.map +1 -1
- package/dist/rpc/registry.d.ts +97 -0
- package/dist/rpc/registry.d.ts.map +1 -0
- package/dist/rpc/registry.js +119 -0
- package/dist/rpc/registry.js.map +1 -0
- package/dist/rpc/server.d.ts +76 -0
- package/dist/rpc/server.d.ts.map +1 -0
- package/dist/rpc/server.js +420 -0
- package/dist/rpc/server.js.map +1 -0
- package/dist/rpc/transport.d.ts +84 -0
- package/dist/rpc/transport.d.ts.map +1 -0
- package/dist/rpc/transport.js +296 -0
- package/dist/rpc/transport.js.map +1 -0
- package/dist/services/__mocks__/utils.d.ts +16 -0
- package/dist/services/__mocks__/utils.d.ts.map +1 -0
- package/dist/services/__mocks__/utils.js +21 -0
- package/dist/services/__mocks__/utils.js.map +1 -0
- package/dist/services/auth.d.ts +18 -0
- package/dist/services/auth.d.ts.map +1 -1
- package/dist/services/auth.js +92 -42
- package/dist/services/auth.js.map +1 -1
- package/dist/services/oauth2-auth.d.ts +16 -0
- package/dist/services/oauth2-auth.d.ts.map +1 -1
- package/dist/services/oauth2-auth.js +74 -0
- package/dist/services/oauth2-auth.js.map +1 -1
- package/package.json +11 -29
- package/dist/.build-info.json +0 -9
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/test/setup.js +0 -40
- package/dist/test/setup.js.map +0 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC Server implementation
|
|
3
|
+
* Coordinates transport, registry, and provides dual-mode operation
|
|
4
|
+
*/
|
|
5
|
+
import { StdioTransport } from './transport.js';
|
|
6
|
+
import { MethodRegistry } from './registry.js';
|
|
7
|
+
import { methodSchemas, isJsonRpcRequest, isJsonRpcNotification, isJsonRpcResponse, } from '@braingrid/protocol';
|
|
8
|
+
import * as handlers from '../handlers/index.js';
|
|
9
|
+
import { BraingridAuth } from '../services/auth.js';
|
|
10
|
+
import { getConfig } from '../utils/config.js';
|
|
11
|
+
/**
|
|
12
|
+
* JSON-RPC Server
|
|
13
|
+
*/
|
|
14
|
+
export class JsonRpcServer {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.isRunning = false;
|
|
17
|
+
this.transport = new StdioTransport(options.input, options.output, {
|
|
18
|
+
useContentLength: options.useContentLength || false,
|
|
19
|
+
});
|
|
20
|
+
this.registry = new MethodRegistry();
|
|
21
|
+
this.context = options.context || {};
|
|
22
|
+
// Initialize auth service
|
|
23
|
+
const config = getConfig();
|
|
24
|
+
this.auth = new BraingridAuth(config.apiUrl);
|
|
25
|
+
// Register all methods
|
|
26
|
+
this.registerMethods();
|
|
27
|
+
// Set up message handling
|
|
28
|
+
this.transport.onMessage(this.handleMessage.bind(this));
|
|
29
|
+
this.transport.onBatch(this.handleBatch.bind(this));
|
|
30
|
+
this.transport.onError(this.handleTransportError.bind(this));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get current authentication context
|
|
34
|
+
*/
|
|
35
|
+
async getAuthContext() {
|
|
36
|
+
try {
|
|
37
|
+
const isAuthenticated = await this.auth.isAuthenticated();
|
|
38
|
+
const session = await this.auth.getStoredSession();
|
|
39
|
+
return {
|
|
40
|
+
...this.context,
|
|
41
|
+
isAuthenticated,
|
|
42
|
+
session,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// If auth check fails, return unauthenticated context
|
|
47
|
+
return {
|
|
48
|
+
...this.context,
|
|
49
|
+
isAuthenticated: false,
|
|
50
|
+
session: undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Helper to register a method with braingrid. prefix
|
|
56
|
+
*/
|
|
57
|
+
registerMethod(name, config) {
|
|
58
|
+
// Register with braingrid. prefix as per REQ-899
|
|
59
|
+
this.registry.register(`braingrid.${name}`, config);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Register all RPC methods
|
|
63
|
+
*/
|
|
64
|
+
registerMethods() {
|
|
65
|
+
// ============================================
|
|
66
|
+
// AUTH METHODS
|
|
67
|
+
// ============================================
|
|
68
|
+
this.registerMethod('auth.login', {
|
|
69
|
+
schema: methodSchemas['auth.login'],
|
|
70
|
+
handler: async (_params, context) => {
|
|
71
|
+
const result = await handlers.handleLogin(context);
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
metadata: { description: 'Authenticate with BrainGrid (returns auth URL in RPC mode)' },
|
|
75
|
+
});
|
|
76
|
+
this.registerMethod('auth.complete', {
|
|
77
|
+
schema: methodSchemas['auth.logout'], // Same schema as logout (no params)
|
|
78
|
+
handler: async (_params, context) => {
|
|
79
|
+
const result = await handlers.handleCompleteLogin(context);
|
|
80
|
+
return result;
|
|
81
|
+
},
|
|
82
|
+
metadata: { description: 'Complete authentication after opening browser (RPC mode only)' },
|
|
83
|
+
});
|
|
84
|
+
this.registerMethod('auth.logout', {
|
|
85
|
+
schema: methodSchemas['auth.logout'],
|
|
86
|
+
handler: async () => {
|
|
87
|
+
const result = await handlers.handleLogout();
|
|
88
|
+
return result;
|
|
89
|
+
},
|
|
90
|
+
metadata: { description: 'Sign out from BrainGrid' },
|
|
91
|
+
});
|
|
92
|
+
this.registerMethod('auth.whoami', {
|
|
93
|
+
schema: methodSchemas['auth.whoami'],
|
|
94
|
+
handler: async () => {
|
|
95
|
+
const result = await handlers.handleWhoami();
|
|
96
|
+
return result;
|
|
97
|
+
},
|
|
98
|
+
metadata: { description: 'Show current user information', requiresAuth: true },
|
|
99
|
+
});
|
|
100
|
+
// ============================================
|
|
101
|
+
// INIT & UPDATE METHODS
|
|
102
|
+
// ============================================
|
|
103
|
+
this.registerMethod('init', {
|
|
104
|
+
schema: methodSchemas['braingrid.init'],
|
|
105
|
+
handler: async (params) => {
|
|
106
|
+
const typedParams = params;
|
|
107
|
+
const result = await handlers.handleInit(typedParams || {});
|
|
108
|
+
return result;
|
|
109
|
+
},
|
|
110
|
+
metadata: {
|
|
111
|
+
description: 'Initialize BrainGrid project in current repository',
|
|
112
|
+
requiresAuth: true,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
this.registerMethod('update', {
|
|
116
|
+
schema: methodSchemas['braingrid.update'],
|
|
117
|
+
handler: async (params) => {
|
|
118
|
+
const typedParams = params;
|
|
119
|
+
const result = await handlers.handleUpdate(typedParams || {});
|
|
120
|
+
return result;
|
|
121
|
+
},
|
|
122
|
+
metadata: {
|
|
123
|
+
description: 'Update BrainGrid CLI to the latest version (use --check in RPC mode)',
|
|
124
|
+
requiresAuth: false,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
// ============================================
|
|
128
|
+
// PROJECT METHODS
|
|
129
|
+
// ============================================
|
|
130
|
+
this.registerMethod('project.list', {
|
|
131
|
+
schema: methodSchemas['project.list'],
|
|
132
|
+
handler: async (params) => {
|
|
133
|
+
const typedParams = params;
|
|
134
|
+
const result = await handlers.handleProjectList(typedParams || {});
|
|
135
|
+
return result;
|
|
136
|
+
},
|
|
137
|
+
metadata: { description: 'List all projects', requiresAuth: true },
|
|
138
|
+
});
|
|
139
|
+
this.registerMethod('project.create', {
|
|
140
|
+
schema: methodSchemas['project.create'],
|
|
141
|
+
handler: async (params) => {
|
|
142
|
+
const typedParams = params;
|
|
143
|
+
const result = await handlers.handleProjectCreate(typedParams);
|
|
144
|
+
return result;
|
|
145
|
+
},
|
|
146
|
+
metadata: {
|
|
147
|
+
description: 'Create a new project',
|
|
148
|
+
requiresAuth: true,
|
|
149
|
+
positionalParams: ['name', 'description'], // Support ["my-project", "description"] format
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
this.registerMethod('project.get', {
|
|
153
|
+
schema: methodSchemas['project.get'],
|
|
154
|
+
handler: async (params) => {
|
|
155
|
+
const typedParams = params;
|
|
156
|
+
const result = await handlers.handleProjectGet(typedParams.project);
|
|
157
|
+
return result;
|
|
158
|
+
},
|
|
159
|
+
metadata: {
|
|
160
|
+
description: 'Get a specific project by ID',
|
|
161
|
+
requiresAuth: true,
|
|
162
|
+
positionalParams: ['project'], // Support ["project-id"] format
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
this.registerMethod('project.show', {
|
|
166
|
+
schema: methodSchemas['project.show'],
|
|
167
|
+
handler: async (params) => {
|
|
168
|
+
const typedParams = params;
|
|
169
|
+
const result = await handlers.handleProjectShow({
|
|
170
|
+
repo: typedParams.project, // project parameter contains the repository
|
|
171
|
+
format: typedParams.format,
|
|
172
|
+
});
|
|
173
|
+
return result;
|
|
174
|
+
},
|
|
175
|
+
metadata: { description: 'Show projects for a repository', requiresAuth: true },
|
|
176
|
+
});
|
|
177
|
+
this.registerMethod('project.update', {
|
|
178
|
+
schema: methodSchemas['project.update'],
|
|
179
|
+
handler: async (params) => {
|
|
180
|
+
const typedParams = params;
|
|
181
|
+
const result = await handlers.handleProjectUpdate(typedParams.project, {
|
|
182
|
+
name: typedParams.name,
|
|
183
|
+
description: typedParams.description,
|
|
184
|
+
});
|
|
185
|
+
return result;
|
|
186
|
+
},
|
|
187
|
+
metadata: { description: 'Update a project', requiresAuth: true },
|
|
188
|
+
});
|
|
189
|
+
this.registerMethod('project.delete', {
|
|
190
|
+
schema: methodSchemas['project.delete'],
|
|
191
|
+
handler: async (params) => {
|
|
192
|
+
const typedParams = params;
|
|
193
|
+
const result = await handlers.handleProjectDelete(typedParams.project, { force: typedParams.confirm } // Map confirm to force parameter
|
|
194
|
+
);
|
|
195
|
+
return result;
|
|
196
|
+
},
|
|
197
|
+
metadata: { description: 'Delete a project', requiresAuth: true },
|
|
198
|
+
});
|
|
199
|
+
// ============================================
|
|
200
|
+
// REQUIREMENT METHODS
|
|
201
|
+
// ============================================
|
|
202
|
+
this.registerMethod('requirement.list', {
|
|
203
|
+
schema: methodSchemas['requirement.list'],
|
|
204
|
+
handler: async (params) => {
|
|
205
|
+
const typedParams = params;
|
|
206
|
+
const result = await handlers.handleRequirementList(typedParams);
|
|
207
|
+
return result;
|
|
208
|
+
},
|
|
209
|
+
metadata: { description: 'List requirements for a project', requiresAuth: true },
|
|
210
|
+
});
|
|
211
|
+
this.registerMethod('requirement.show', {
|
|
212
|
+
schema: methodSchemas['requirement.show'],
|
|
213
|
+
handler: async (params) => {
|
|
214
|
+
const typedParams = params;
|
|
215
|
+
const result = await handlers.handleRequirementShow(typedParams.requirement);
|
|
216
|
+
return result;
|
|
217
|
+
},
|
|
218
|
+
metadata: { description: 'Show requirement details', requiresAuth: true },
|
|
219
|
+
});
|
|
220
|
+
this.registerMethod('requirement.create', {
|
|
221
|
+
schema: methodSchemas['requirement.create'],
|
|
222
|
+
handler: async (params) => {
|
|
223
|
+
const typedParams = params;
|
|
224
|
+
const result = await handlers.handleRequirementCreate(typedParams);
|
|
225
|
+
return result;
|
|
226
|
+
},
|
|
227
|
+
metadata: {
|
|
228
|
+
description: 'Create a new requirement',
|
|
229
|
+
requiresAuth: true,
|
|
230
|
+
supportsStreaming: true, // Requirement creation supports streaming
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
this.registerMethod('requirement.update', {
|
|
234
|
+
schema: methodSchemas['requirement.update'],
|
|
235
|
+
handler: async (params) => {
|
|
236
|
+
const typedParams = params;
|
|
237
|
+
const result = await handlers.handleRequirementUpdate(typedParams.requirement, {
|
|
238
|
+
status: typedParams.status,
|
|
239
|
+
name: typedParams.name,
|
|
240
|
+
});
|
|
241
|
+
return result;
|
|
242
|
+
},
|
|
243
|
+
metadata: { description: 'Update a requirement', requiresAuth: true },
|
|
244
|
+
});
|
|
245
|
+
this.registerMethod('requirement.delete', {
|
|
246
|
+
schema: methodSchemas['requirement.delete'],
|
|
247
|
+
handler: async (params) => {
|
|
248
|
+
const typedParams = params;
|
|
249
|
+
const result = await handlers.handleRequirementDelete(typedParams.requirement, { force: typedParams.confirm } // Map confirm to force parameter
|
|
250
|
+
);
|
|
251
|
+
return result;
|
|
252
|
+
},
|
|
253
|
+
metadata: { description: 'Delete a requirement', requiresAuth: true },
|
|
254
|
+
});
|
|
255
|
+
// ============================================
|
|
256
|
+
// TASK METHODS
|
|
257
|
+
// ============================================
|
|
258
|
+
this.registerMethod('task.list', {
|
|
259
|
+
schema: methodSchemas['task.list'],
|
|
260
|
+
handler: async (params) => {
|
|
261
|
+
const typedParams = params;
|
|
262
|
+
const result = await handlers.handleTaskList(typedParams);
|
|
263
|
+
return result;
|
|
264
|
+
},
|
|
265
|
+
metadata: { description: 'List tasks for a requirement', requiresAuth: true },
|
|
266
|
+
});
|
|
267
|
+
this.registerMethod('task.show', {
|
|
268
|
+
schema: methodSchemas['task.show'],
|
|
269
|
+
handler: async (params) => {
|
|
270
|
+
const typedParams = params;
|
|
271
|
+
const result = await handlers.handleTaskShow(typedParams.task);
|
|
272
|
+
return result;
|
|
273
|
+
},
|
|
274
|
+
metadata: { description: 'Show task details', requiresAuth: true },
|
|
275
|
+
});
|
|
276
|
+
this.registerMethod('task.create', {
|
|
277
|
+
schema: methodSchemas['task.create'],
|
|
278
|
+
handler: async (params) => {
|
|
279
|
+
const typedParams = params;
|
|
280
|
+
const result = await handlers.handleTaskCreate(typedParams);
|
|
281
|
+
return result;
|
|
282
|
+
},
|
|
283
|
+
metadata: { description: 'Create a new task', requiresAuth: true },
|
|
284
|
+
});
|
|
285
|
+
this.registerMethod('task.update', {
|
|
286
|
+
schema: methodSchemas['task.update'],
|
|
287
|
+
handler: async (params) => {
|
|
288
|
+
const typedParams = params;
|
|
289
|
+
const result = await handlers.handleTaskUpdate(typedParams.task, {
|
|
290
|
+
status: typedParams.status,
|
|
291
|
+
title: typedParams.title,
|
|
292
|
+
});
|
|
293
|
+
return result;
|
|
294
|
+
},
|
|
295
|
+
metadata: { description: 'Update a task', requiresAuth: true },
|
|
296
|
+
});
|
|
297
|
+
this.registerMethod('task.delete', {
|
|
298
|
+
schema: methodSchemas['task.delete'],
|
|
299
|
+
handler: async (params) => {
|
|
300
|
+
const typedParams = params;
|
|
301
|
+
const result = await handlers.handleTaskDelete(typedParams.task, { force: typedParams.confirm } // Map confirm to force parameter
|
|
302
|
+
);
|
|
303
|
+
return result;
|
|
304
|
+
},
|
|
305
|
+
metadata: { description: 'Delete a task', requiresAuth: true },
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Handle incoming JSON-RPC message
|
|
310
|
+
*/
|
|
311
|
+
async handleMessage(message) {
|
|
312
|
+
try {
|
|
313
|
+
if (isJsonRpcRequest(message)) {
|
|
314
|
+
await this.handleRequest(message);
|
|
315
|
+
}
|
|
316
|
+
else if (isJsonRpcNotification(message)) {
|
|
317
|
+
await this.handleNotification(message);
|
|
318
|
+
}
|
|
319
|
+
else if (isJsonRpcResponse(message)) {
|
|
320
|
+
// Server doesn't handle responses
|
|
321
|
+
console.error('Unexpected response message received');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
console.error('Error handling message:', error);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Handle JSON-RPC request
|
|
330
|
+
*/
|
|
331
|
+
async handleRequest(request) {
|
|
332
|
+
// Get fresh auth context for this request
|
|
333
|
+
const authContext = await this.getAuthContext();
|
|
334
|
+
const response = await this.registry.execute(request.id, request.method, request.params, authContext);
|
|
335
|
+
await this.transport.send(response);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Handle JSON-RPC notification
|
|
339
|
+
*/
|
|
340
|
+
async handleNotification(notification) {
|
|
341
|
+
// Get fresh auth context for this notification
|
|
342
|
+
const authContext = await this.getAuthContext();
|
|
343
|
+
// Notifications don't expect responses
|
|
344
|
+
// Execute the method but don't send response
|
|
345
|
+
await this.registry.execute('', // Notifications don't have IDs
|
|
346
|
+
notification.method, notification.params, authContext);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Send a progress notification for long-running operations
|
|
350
|
+
*/
|
|
351
|
+
async sendProgress(id, message, progress) {
|
|
352
|
+
const notification = {
|
|
353
|
+
jsonrpc: '2.0',
|
|
354
|
+
method: 'braingrid.progress',
|
|
355
|
+
params: {
|
|
356
|
+
id,
|
|
357
|
+
message,
|
|
358
|
+
progress,
|
|
359
|
+
timestamp: new Date().toISOString(),
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
await this.transport.send(notification);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Handle batch request
|
|
366
|
+
*/
|
|
367
|
+
async handleBatch(batch) {
|
|
368
|
+
const responses = [];
|
|
369
|
+
// Get fresh auth context for this batch
|
|
370
|
+
const authContext = await this.getAuthContext();
|
|
371
|
+
// Process each message in the batch
|
|
372
|
+
for (const message of batch) {
|
|
373
|
+
if (isJsonRpcRequest(message)) {
|
|
374
|
+
// Requests expect responses
|
|
375
|
+
const response = await this.registry.execute(message.id, message.method, message.params, authContext);
|
|
376
|
+
responses.push(response);
|
|
377
|
+
}
|
|
378
|
+
else if (isJsonRpcNotification(message)) {
|
|
379
|
+
// Notifications don't expect responses
|
|
380
|
+
await this.registry.execute('', // Notifications don't have IDs
|
|
381
|
+
message.method, message.params, authContext);
|
|
382
|
+
// Don't add to responses array
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
// Send batch response if there are any responses
|
|
386
|
+
if (responses.length > 0) {
|
|
387
|
+
await this.transport.send(responses);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Handle transport errors
|
|
392
|
+
*/
|
|
393
|
+
handleTransportError(error) {
|
|
394
|
+
console.error('Transport error:', error);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Start the server
|
|
398
|
+
*/
|
|
399
|
+
start() {
|
|
400
|
+
if (this.isRunning)
|
|
401
|
+
return;
|
|
402
|
+
this.isRunning = true;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Stop the server
|
|
406
|
+
*/
|
|
407
|
+
async stop() {
|
|
408
|
+
if (!this.isRunning)
|
|
409
|
+
return;
|
|
410
|
+
this.isRunning = false;
|
|
411
|
+
await this.transport.close();
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Get registered methods for discovery
|
|
415
|
+
*/
|
|
416
|
+
getMethods() {
|
|
417
|
+
return this.registry.getMethods().map(m => m.name);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rpc/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AACnE,OAAO,EACN,aAAa,EAQb,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAY/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAOzB,YAAY,UAAgC,EAAE;QAHtC,cAAS,GAAY,KAAK,CAAC;QAIlC,IA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C9B,CAAC;IAED;;OAEG;IACH,UAAU;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACD"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* STDIO Transport Layer for JSON-RPC 2.0
|
|
3
|
+
* Handles newline-delimited JSON message parsing and sending over stdin/stdout
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import type { Readable, Writable } from 'stream';
|
|
7
|
+
import type { JsonRpcMessage, JsonRpcBatchRequest, JsonRpcBatchResponse, Transport } from '@braingrid/protocol';
|
|
8
|
+
/**
|
|
9
|
+
* STDIO Transport implementation for JSON-RPC communication
|
|
10
|
+
*/
|
|
11
|
+
export declare class StdioTransport extends EventEmitter implements Transport {
|
|
12
|
+
private readonly input;
|
|
13
|
+
private readonly output;
|
|
14
|
+
private buffer;
|
|
15
|
+
private isClosed;
|
|
16
|
+
private readonly useContentLength;
|
|
17
|
+
private contentBuffer;
|
|
18
|
+
private expectedContentLength;
|
|
19
|
+
private headers;
|
|
20
|
+
constructor(input?: Readable, output?: Writable, options?: {
|
|
21
|
+
useContentLength?: boolean;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Handle incoming data chunks from stdin
|
|
25
|
+
*/
|
|
26
|
+
private handleData;
|
|
27
|
+
/**
|
|
28
|
+
* Handle data in newline-delimited mode
|
|
29
|
+
*/
|
|
30
|
+
private handleNewlineDelimitedData;
|
|
31
|
+
/**
|
|
32
|
+
* Handle data in content-length mode (LSP-style)
|
|
33
|
+
*/
|
|
34
|
+
private handleContentLengthData;
|
|
35
|
+
/**
|
|
36
|
+
* Parse LSP-style headers
|
|
37
|
+
*/
|
|
38
|
+
private parseHeaders;
|
|
39
|
+
/**
|
|
40
|
+
* Process a complete JSON message string
|
|
41
|
+
*/
|
|
42
|
+
private processMessage;
|
|
43
|
+
/**
|
|
44
|
+
* Process a single JSON-RPC message
|
|
45
|
+
*/
|
|
46
|
+
private processSingleMessage;
|
|
47
|
+
/**
|
|
48
|
+
* Process a batch request (array of messages)
|
|
49
|
+
*/
|
|
50
|
+
private processBatchRequest;
|
|
51
|
+
/**
|
|
52
|
+
* Send a JSON-RPC message or batch response
|
|
53
|
+
*/
|
|
54
|
+
send(message: JsonRpcMessage | JsonRpcBatchResponse): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Set up a handler for incoming messages
|
|
57
|
+
*/
|
|
58
|
+
onMessage(handler: (message: JsonRpcMessage) => void): void;
|
|
59
|
+
/**
|
|
60
|
+
* Set up a handler for batch requests
|
|
61
|
+
*/
|
|
62
|
+
onBatch(handler: (batch: JsonRpcBatchRequest) => void): void;
|
|
63
|
+
/**
|
|
64
|
+
* Set up a handler for transport errors
|
|
65
|
+
*/
|
|
66
|
+
onError(handler: (error: Error) => void): void;
|
|
67
|
+
/**
|
|
68
|
+
* Handle transport errors
|
|
69
|
+
*/
|
|
70
|
+
private handleError;
|
|
71
|
+
/**
|
|
72
|
+
* Handle transport close
|
|
73
|
+
*/
|
|
74
|
+
private handleClose;
|
|
75
|
+
/**
|
|
76
|
+
* Close the transport
|
|
77
|
+
*/
|
|
78
|
+
close(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Check if transport is closed
|
|
81
|
+
*/
|
|
82
|
+
get closed(): boolean;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/rpc/transport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EACX,cAAc,E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