@a3s-lab/code 0.5.0 → 0.7.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 (52) hide show
  1. package/index.d.ts +87 -0
  2. package/index.darwin-arm64.node +0 -0
  3. package/index.darwin-x64.node +0 -0
  4. package/index.js +128 -0
  5. package/index.linux-arm64-gnu.node +0 -0
  6. package/index.linux-arm64-musl.node +0 -0
  7. package/index.linux-x64-gnu.node +0 -0
  8. package/index.linux-x64-musl.node +0 -0
  9. package/package.json +27 -34
  10. package/LICENSE +0 -21
  11. package/README.md +0 -764
  12. package/dist/chat.d.ts +0 -97
  13. package/dist/chat.d.ts.map +0 -1
  14. package/dist/chat.js +0 -179
  15. package/dist/chat.js.map +0 -1
  16. package/dist/client.d.ts +0 -1356
  17. package/dist/client.d.ts.map +0 -1
  18. package/dist/client.js +0 -1014
  19. package/dist/client.js.map +0 -1
  20. package/dist/config.d.ts +0 -106
  21. package/dist/config.d.ts.map +0 -1
  22. package/dist/config.js +0 -142
  23. package/dist/config.js.map +0 -1
  24. package/dist/generate.d.ts +0 -130
  25. package/dist/generate.d.ts.map +0 -1
  26. package/dist/generate.js +0 -283
  27. package/dist/generate.js.map +0 -1
  28. package/dist/index.d.ts +0 -54
  29. package/dist/index.d.ts.map +0 -1
  30. package/dist/index.js +0 -60
  31. package/dist/index.js.map +0 -1
  32. package/dist/message.d.ts +0 -157
  33. package/dist/message.d.ts.map +0 -1
  34. package/dist/message.js +0 -279
  35. package/dist/message.js.map +0 -1
  36. package/dist/openai-compat.d.ts +0 -186
  37. package/dist/openai-compat.d.ts.map +0 -1
  38. package/dist/openai-compat.js +0 -263
  39. package/dist/openai-compat.js.map +0 -1
  40. package/dist/provider.d.ts +0 -64
  41. package/dist/provider.d.ts.map +0 -1
  42. package/dist/provider.js +0 -60
  43. package/dist/provider.js.map +0 -1
  44. package/dist/session.d.ts +0 -573
  45. package/dist/session.d.ts.map +0 -1
  46. package/dist/session.js +0 -1153
  47. package/dist/session.js.map +0 -1
  48. package/dist/tool.d.ts +0 -106
  49. package/dist/tool.d.ts.map +0 -1
  50. package/dist/tool.js +0 -71
  51. package/dist/tool.js.map +0 -1
  52. package/proto/code_agent.proto +0 -1754
package/dist/client.js DELETED
@@ -1,1014 +0,0 @@
1
- /**
2
- * A3S Code Agent gRPC Client
3
- *
4
- * Full implementation of the CodeAgentService interface.
5
- */
6
- import * as grpc from '@grpc/grpc-js';
7
- import * as protoLoader from '@grpc/proto-loader';
8
- import { fileURLToPath } from 'url';
9
- import { dirname, join } from 'path';
10
- import { loadConfigFromFile, loadConfigFromDir } from './config.js';
11
- import { normalizeMessages, a3sResponseToOpenAI, a3sChunkToOpenAI, } from './openai-compat.js';
12
- import { modelRefToLLMConfig } from './provider.js';
13
- import { Session as CodeSession } from './session.js';
14
- // Get the directory of this module
15
- const __filename = fileURLToPath(import.meta.url);
16
- const __dirname = dirname(__filename);
17
- // Proto file path
18
- const PROTO_PATH = join(__dirname, '..', 'proto', 'code_agent.proto');
19
- // Numeric enum values
20
- export const StorageType = {
21
- STORAGE_TYPE_UNSPECIFIED: 0,
22
- STORAGE_TYPE_MEMORY: 1,
23
- STORAGE_TYPE_FILE: 2,
24
- };
25
- export const SessionLane = {
26
- SESSION_LANE_UNKNOWN: 0,
27
- SESSION_LANE_CONTROL: 1,
28
- SESSION_LANE_QUERY: 2,
29
- SESSION_LANE_EXECUTE: 3,
30
- SESSION_LANE_GENERATE: 4,
31
- };
32
- export const TimeoutAction = {
33
- TIMEOUT_ACTION_UNKNOWN: 0,
34
- TIMEOUT_ACTION_REJECT: 1,
35
- TIMEOUT_ACTION_AUTO_APPROVE: 2,
36
- };
37
- export const TaskHandlerMode = {
38
- TASK_HANDLER_MODE_UNKNOWN: 0,
39
- TASK_HANDLER_MODE_INTERNAL: 1,
40
- TASK_HANDLER_MODE_EXTERNAL: 2,
41
- TASK_HANDLER_MODE_HYBRID: 3,
42
- };
43
- export const CronJobStatusEnum = {
44
- UNKNOWN: 0,
45
- ACTIVE: 1,
46
- PAUSED: 2,
47
- RUNNING: 3,
48
- };
49
- export const CronExecutionStatusEnum = {
50
- UNKNOWN: 0,
51
- SUCCESS: 1,
52
- FAILED: 2,
53
- TIMEOUT: 3,
54
- CANCELLED: 4,
55
- };
56
- // ============================================================================
57
- // A3sClient Class
58
- // ============================================================================
59
- /**
60
- * A3S Code Agent gRPC Client
61
- *
62
- * Provides a TypeScript interface to all CodeAgentService RPCs.
63
- *
64
- * @example
65
- * ```typescript
66
- * // Create client with config directory
67
- * const client = new A3sClient({ configDir: '/path/to/a3s' });
68
- *
69
- * // Create client with config file
70
- * const client = new A3sClient({ configPath: '/path/to/config.json' });
71
- *
72
- * // Create client with explicit address
73
- * const client = new A3sClient({ address: 'localhost:4088' });
74
- * ```
75
- */
76
- export class A3sClient {
77
- client;
78
- address;
79
- configDir;
80
- constructor(options = {}) {
81
- this.configDir = options.configDir;
82
- // Load config from file if specified
83
- let fileConfig;
84
- if (options.configPath) {
85
- fileConfig = loadConfigFromFile(options.configPath);
86
- }
87
- else if (options.configDir) {
88
- fileConfig = loadConfigFromDir(options.configDir);
89
- }
90
- // Determine address: explicit > config file > default
91
- this.address = options.address || fileConfig?.address || 'localhost:4088';
92
- // Load proto definition
93
- const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
94
- keepCase: false,
95
- longs: String,
96
- enums: String,
97
- defaults: true,
98
- oneofs: true,
99
- });
100
- const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
101
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
- const a3s = protoDescriptor.a3s;
103
- const CodeAgentService = a3s.code.agent.v1.CodeAgentService;
104
- // Create credentials
105
- const credentials = options.useTls
106
- ? grpc.credentials.createSsl()
107
- : grpc.credentials.createInsecure();
108
- // Create client
109
- this.client = new CodeAgentService(this.address, credentials);
110
- }
111
- /**
112
- * Get the config directory path
113
- */
114
- getConfigDir() {
115
- return this.configDir;
116
- }
117
- /**
118
- * Get the server address
119
- */
120
- getAddress() {
121
- return this.address;
122
- }
123
- /**
124
- * Close the client connection
125
- */
126
- close() {
127
- this.client.close();
128
- }
129
- // ==========================================================================
130
- // Helper method for promisifying unary calls
131
- // ==========================================================================
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
- promisify(method, request) {
134
- return new Promise((resolve, reject) => {
135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
- this.client[method](request, (error, response) => {
137
- if (error) {
138
- reject(error);
139
- }
140
- else {
141
- resolve(response);
142
- }
143
- });
144
- });
145
- }
146
- // ==========================================================================
147
- // Lifecycle Management
148
- // ==========================================================================
149
- /**
150
- * Check the health status of the agent
151
- */
152
- async healthCheck() {
153
- return this.promisify('healthCheck', {});
154
- }
155
- /**
156
- * Get agent capabilities
157
- */
158
- async getCapabilities() {
159
- return this.promisify('getCapabilities', {});
160
- }
161
- /**
162
- * Initialize the agent with workspace and environment
163
- */
164
- async initialize(workspace, env) {
165
- return this.promisify('initialize', { workspace, env: env || {} });
166
- }
167
- /**
168
- * Shutdown the agent
169
- */
170
- async shutdown() {
171
- return this.promisify('shutdown', {});
172
- }
173
- async createSession(configOrOptions, sessionId, initialContext) {
174
- // High-level path: options has `model` (ModelRef)
175
- if (configOrOptions && 'model' in configOrOptions) {
176
- const opts = configOrOptions;
177
- const llm = modelRefToLLMConfig(opts.model);
178
- const resp = await this.promisify('createSession', {
179
- sessionId: opts.sessionId,
180
- config: {
181
- name: `session-${Date.now()}`,
182
- workspace: opts.workspace || '',
183
- llm,
184
- systemPrompt: opts.system,
185
- autoCompact: opts.autoCompact,
186
- },
187
- initialContext: opts.initialContext || [],
188
- });
189
- const session = new CodeSession(this, resp.sessionId);
190
- // Apply optional configurations after session creation
191
- if (opts.confirmation) {
192
- await session.setConfirmation(opts.confirmation);
193
- }
194
- if (opts.permissions) {
195
- await session.setPermissions(opts.permissions);
196
- }
197
- if (opts.lanes) {
198
- for (const [lane, config] of Object.entries(opts.lanes)) {
199
- if (config) {
200
- await session.setLaneHandler(lane, config);
201
- }
202
- }
203
- }
204
- if (opts.skills) {
205
- for (const skill of opts.skills) {
206
- if (typeof skill === 'string') {
207
- await session.loadSkill(skill);
208
- }
209
- else {
210
- await session.addSkill(skill);
211
- }
212
- }
213
- }
214
- return session;
215
- }
216
- // Low-level path: raw SessionConfig
217
- return this.promisify('createSession', {
218
- sessionId,
219
- config: configOrOptions,
220
- initialContext: initialContext || [],
221
- });
222
- }
223
- /**
224
- * Destroy a session
225
- */
226
- async destroySession(sessionId) {
227
- return this.promisify('destroySession', { sessionId });
228
- }
229
- /**
230
- * Restore a persisted session from store by ID
231
- */
232
- async restoreSession(sessionId) {
233
- return this.promisify('restoreSession', { sessionId });
234
- }
235
- /**
236
- * List all sessions
237
- */
238
- async listSessions() {
239
- return this.promisify('listSessions', {});
240
- }
241
- /**
242
- * Get a specific session
243
- */
244
- async getSession(sessionId) {
245
- return this.promisify('getSession', { sessionId });
246
- }
247
- /**
248
- * Configure a session
249
- */
250
- async configureSession(sessionId, config) {
251
- return this.promisify('configureSession', { sessionId, config });
252
- }
253
- /**
254
- * Get messages from a session
255
- */
256
- async getMessages(sessionId, limit, offset) {
257
- return this.promisify('getMessages', { sessionId, limit, offset });
258
- }
259
- // ==========================================================================
260
- // Code Generation
261
- // ==========================================================================
262
- /**
263
- * Generate a response (unary)
264
- *
265
- * Supports both A3S and OpenAI message formats:
266
- * - A3S: { role: 'ROLE_USER', content: '...' }
267
- * - OpenAI: { role: 'user', content: '...' }
268
- */
269
- async generate(sessionId, messages) {
270
- const normalizedMessages = normalizeMessages(messages);
271
- return this.promisify('generate', { sessionId, messages: normalizedMessages });
272
- }
273
- /**
274
- * Generate a response (streaming)
275
- *
276
- * Supports both A3S and OpenAI message formats.
277
- */
278
- streamGenerate(sessionId, messages) {
279
- const normalizedMessages = normalizeMessages(messages);
280
- const call = this.client.streamGenerate({ sessionId, messages: normalizedMessages });
281
- return this.streamToAsyncIterable(call);
282
- }
283
- /**
284
- * Generate structured output (unary)
285
- *
286
- * Supports both A3S and OpenAI message formats.
287
- */
288
- async generateStructured(sessionId, messages, schema) {
289
- const normalizedMessages = normalizeMessages(messages);
290
- return this.promisify('generateStructured', { sessionId, messages: normalizedMessages, schema });
291
- }
292
- /**
293
- * Generate structured output (streaming)
294
- *
295
- * Supports both A3S and OpenAI message formats.
296
- */
297
- streamGenerateStructured(sessionId, messages, schema) {
298
- const normalizedMessages = normalizeMessages(messages);
299
- const call = this.client.streamGenerateStructured({
300
- sessionId,
301
- messages: normalizedMessages,
302
- schema,
303
- });
304
- return this.streamToAsyncIterable(call);
305
- }
306
- // ==========================================================================
307
- // OpenAI-Compatible Methods
308
- // ==========================================================================
309
- /**
310
- * Generate a response in OpenAI ChatCompletion format
311
- *
312
- * This method provides full OpenAI API compatibility.
313
- *
314
- * @example
315
- * ```typescript
316
- * const completion = await client.chatCompletion(sessionId, [
317
- * { role: 'user', content: 'Hello!' }
318
- * ]);
319
- * console.log(completion.choices[0].message.content);
320
- * ```
321
- */
322
- async chatCompletion(sessionId, messages, options) {
323
- const response = await this.generate(sessionId, messages);
324
- return a3sResponseToOpenAI(response, options?.model);
325
- }
326
- /**
327
- * Stream a response in OpenAI ChatCompletionChunk format
328
- *
329
- * This method provides full OpenAI API compatibility for streaming.
330
- *
331
- * @example
332
- * ```typescript
333
- * for await (const chunk of client.streamChatCompletion(sessionId, [
334
- * { role: 'user', content: 'Hello!' }
335
- * ])) {
336
- * const content = chunk.choices[0].delta.content;
337
- * if (content) process.stdout.write(content);
338
- * }
339
- * ```
340
- */
341
- async *streamChatCompletion(sessionId, messages, options) {
342
- for await (const chunk of this.streamGenerate(sessionId, messages)) {
343
- yield a3sChunkToOpenAI(chunk, options?.model);
344
- }
345
- }
346
- // ==========================================================================
347
- // Skill Management
348
- // ==========================================================================
349
- /**
350
- * Load a skill into a session
351
- */
352
- async loadSkill(sessionId, skillName, skillContent) {
353
- return this.promisify('loadSkill', { sessionId, skillName, skillContent });
354
- }
355
- /**
356
- * Unload a skill from a session
357
- */
358
- async unloadSkill(sessionId, skillName) {
359
- return this.promisify('unloadSkill', { sessionId, skillName });
360
- }
361
- /**
362
- * List available skills
363
- */
364
- async listSkills(sessionId) {
365
- return this.promisify('listSkills', { sessionId });
366
- }
367
- /**
368
- * Get skills by name or all skills
369
- */
370
- async getSkill(name) {
371
- return this.promisify('getSkill', { name });
372
- }
373
- /**
374
- * Search for skills in the open skills ecosystem
375
- *
376
- * @param query - Search query (e.g., "react performance", "testing")
377
- * @param limit - Maximum number of results (default 10)
378
- */
379
- async searchSkills(query, limit) {
380
- return this.promisify('searchSkills', { query, limit: limit || 10 });
381
- }
382
- /**
383
- * Install a skill from the skills ecosystem
384
- *
385
- * @param source - Skill source (e.g., "owner/repo" or "owner/repo@skill-name")
386
- * @param global - Install globally (user-level) vs project-level
387
- * @param sessionId - Optional session to load the skill into after install
388
- */
389
- async installSkill(source, global, sessionId) {
390
- return this.promisify('installSkill', {
391
- source,
392
- global: global || false,
393
- sessionId,
394
- });
395
- }
396
- // ==========================================================================
397
- // Context Management
398
- // ==========================================================================
399
- /**
400
- * Get context usage for a session
401
- */
402
- async getContextUsage(sessionId) {
403
- return this.promisify('getContextUsage', { sessionId });
404
- }
405
- /**
406
- * Compact context for a session
407
- */
408
- async compactContext(sessionId) {
409
- return this.promisify('compactContext', { sessionId });
410
- }
411
- /**
412
- * Clear context for a session
413
- */
414
- async clearContext(sessionId) {
415
- return this.promisify('clearContext', { sessionId });
416
- }
417
- // ==========================================================================
418
- // Event Streaming
419
- // ==========================================================================
420
- /**
421
- * Subscribe to agent events
422
- */
423
- subscribeEvents(sessionId, eventTypes) {
424
- const call = this.client.subscribeEvents({
425
- sessionId,
426
- eventTypes: eventTypes || [],
427
- });
428
- return this.streamToAsyncIterable(call);
429
- }
430
- // ==========================================================================
431
- // Control Operations
432
- // ==========================================================================
433
- /**
434
- * Cancel an operation
435
- */
436
- async cancel(sessionId, operationId) {
437
- return this.promisify('cancel', { sessionId, operationId });
438
- }
439
- /**
440
- * Pause a session
441
- */
442
- async pause(sessionId) {
443
- return this.promisify('pause', { sessionId });
444
- }
445
- /**
446
- * Resume a session
447
- */
448
- async resume(sessionId) {
449
- return this.promisify('resume', { sessionId });
450
- }
451
- // ==========================================================================
452
- // Human-in-the-Loop (HITL)
453
- // ==========================================================================
454
- /**
455
- * Confirm or reject tool execution
456
- */
457
- async confirmToolExecution(sessionId, toolId, approved, reason) {
458
- return this.promisify('confirmToolExecution', {
459
- sessionId,
460
- toolId,
461
- approved,
462
- reason,
463
- });
464
- }
465
- /**
466
- * Set confirmation policy for a session
467
- */
468
- async setConfirmationPolicy(sessionId, policy) {
469
- return this.promisify('setConfirmationPolicy', { sessionId, policy });
470
- }
471
- /**
472
- * Get confirmation policy for a session
473
- */
474
- async getConfirmationPolicy(sessionId) {
475
- return this.promisify('getConfirmationPolicy', { sessionId });
476
- }
477
- // ==========================================================================
478
- // External Task Handling
479
- // ==========================================================================
480
- /**
481
- * Set lane handler configuration
482
- */
483
- async setLaneHandler(sessionId, lane, config) {
484
- return this.promisify('setLaneHandler', { sessionId, lane, config });
485
- }
486
- /**
487
- * Get lane handler configuration
488
- */
489
- async getLaneHandler(sessionId, lane) {
490
- return this.promisify('getLaneHandler', { sessionId, lane });
491
- }
492
- /**
493
- * Complete an external task
494
- */
495
- async completeExternalTask(sessionId, taskId, success, result, error) {
496
- return this.promisify('completeExternalTask', {
497
- sessionId,
498
- taskId,
499
- success,
500
- result: result || '',
501
- error: error || '',
502
- });
503
- }
504
- /**
505
- * List pending external tasks
506
- */
507
- async listPendingExternalTasks(sessionId) {
508
- return this.promisify('listPendingExternalTasks', { sessionId });
509
- }
510
- // ==========================================================================
511
- // Permission System
512
- // ==========================================================================
513
- /**
514
- * Set permission policy for a session
515
- */
516
- async setPermissionPolicy(sessionId, policy) {
517
- return this.promisify('setPermissionPolicy', { sessionId, policy });
518
- }
519
- /**
520
- * Get permission policy for a session
521
- */
522
- async getPermissionPolicy(sessionId) {
523
- return this.promisify('getPermissionPolicy', { sessionId });
524
- }
525
- /**
526
- * Check permission for a tool call
527
- */
528
- async checkPermission(sessionId, toolName, args) {
529
- return this.promisify('checkPermission', {
530
- sessionId,
531
- toolName,
532
- arguments: args,
533
- });
534
- }
535
- /**
536
- * Add a permission rule
537
- */
538
- async addPermissionRule(sessionId, ruleType, rule) {
539
- return this.promisify('addPermissionRule', { sessionId, ruleType, rule });
540
- }
541
- // ==========================================================================
542
- // Todo/Task Tracking
543
- // ==========================================================================
544
- /**
545
- * Get todos for a session
546
- */
547
- async getTodos(sessionId) {
548
- return this.promisify('getTodos', { sessionId });
549
- }
550
- /**
551
- * Set todos for a session
552
- */
553
- async setTodos(sessionId, todos) {
554
- return this.promisify('setTodos', { sessionId, todos });
555
- }
556
- // ==========================================================================
557
- // Provider Configuration
558
- // ==========================================================================
559
- /**
560
- * List all providers
561
- */
562
- async listProviders() {
563
- return this.promisify('listProviders', {});
564
- }
565
- /**
566
- * Get a specific provider
567
- */
568
- async getProvider(name) {
569
- return this.promisify('getProvider', { name });
570
- }
571
- /**
572
- * Add a new provider
573
- */
574
- async addProvider(provider) {
575
- return this.promisify('addProvider', { provider });
576
- }
577
- /**
578
- * Update an existing provider
579
- */
580
- async updateProvider(provider) {
581
- return this.promisify('updateProvider', { provider });
582
- }
583
- /**
584
- * Remove a provider
585
- */
586
- async removeProvider(name) {
587
- return this.promisify('removeProvider', { name });
588
- }
589
- /**
590
- * Set the default model
591
- */
592
- async setDefaultModel(provider, model) {
593
- return this.promisify('setDefaultModel', { provider, model });
594
- }
595
- /**
596
- * Get the default model
597
- */
598
- async getDefaultModel() {
599
- return this.promisify('getDefaultModel', {});
600
- }
601
- // ==========================================================================
602
- // Planning & Goal Tracking
603
- // ==========================================================================
604
- /**
605
- * Create an execution plan
606
- */
607
- async createPlan(sessionId, prompt, context) {
608
- return this.promisify('createPlan', { sessionId, prompt, context });
609
- }
610
- /**
611
- * Get an existing plan
612
- */
613
- async getPlan(sessionId, planId) {
614
- return this.promisify('getPlan', { sessionId, planId });
615
- }
616
- /**
617
- * Extract goal from prompt
618
- */
619
- async extractGoal(sessionId, prompt) {
620
- return this.promisify('extractGoal', { sessionId, prompt });
621
- }
622
- /**
623
- * Check if goal is achieved
624
- */
625
- async checkGoalAchievement(sessionId, goal, currentState) {
626
- return this.promisify('checkGoalAchievement', {
627
- sessionId,
628
- goal,
629
- currentState,
630
- });
631
- }
632
- // ==========================================================================
633
- // Memory System
634
- // ==========================================================================
635
- /**
636
- * Store a memory item
637
- */
638
- async storeMemory(sessionId, memory) {
639
- return this.promisify('storeMemory', { sessionId, memory });
640
- }
641
- /**
642
- * Retrieve a memory by ID
643
- */
644
- async retrieveMemory(sessionId, memoryId) {
645
- return this.promisify('retrieveMemory', { sessionId, memoryId });
646
- }
647
- /**
648
- * Search memories
649
- */
650
- async searchMemories(sessionId, query, tags, limit, recentOnly, minImportance) {
651
- return this.promisify('searchMemories', {
652
- sessionId,
653
- query,
654
- tags: tags || [],
655
- limit: limit || 10,
656
- recentOnly: recentOnly || false,
657
- minImportance,
658
- });
659
- }
660
- /**
661
- * Get memory statistics
662
- */
663
- async getMemoryStats(sessionId) {
664
- return this.promisify('getMemoryStats', { sessionId });
665
- }
666
- /**
667
- * Clear memories
668
- */
669
- async clearMemories(sessionId, clearLongTerm, clearShortTerm, clearWorking) {
670
- return this.promisify('clearMemories', {
671
- sessionId,
672
- clearLongTerm: clearLongTerm || false,
673
- clearShortTerm: clearShortTerm || false,
674
- clearWorking: clearWorking || false,
675
- });
676
- }
677
- /**
678
- * Delete a specific memory by ID
679
- */
680
- async deleteMemory(sessionId, memoryId) {
681
- return this.promisify('deleteMemory', { sessionId, memoryId });
682
- }
683
- /**
684
- * Summarize memories using LLM
685
- */
686
- async summarizeMemories(sessionId, tags, limit, recentHours) {
687
- return this.promisify('summarizeMemories', {
688
- sessionId,
689
- tags: tags || [],
690
- limit: limit || 50,
691
- recentHours,
692
- });
693
- }
694
- // ==========================================================================
695
- // MCP (Model Context Protocol) Methods
696
- // ==========================================================================
697
- /**
698
- * Register an MCP server
699
- */
700
- async registerMcpServer(config) {
701
- return this.promisify('registerMcpServer', { config });
702
- }
703
- /**
704
- * Connect to an MCP server
705
- */
706
- async connectMcpServer(name) {
707
- return this.promisify('connectMcpServer', { name });
708
- }
709
- /**
710
- * Disconnect from an MCP server
711
- */
712
- async disconnectMcpServer(name) {
713
- return this.promisify('disconnectMcpServer', { name });
714
- }
715
- /**
716
- * List all MCP servers
717
- */
718
- async listMcpServers() {
719
- return this.promisify('listMcpServers', {});
720
- }
721
- /**
722
- * Get MCP tools
723
- */
724
- async getMcpTools(serverName) {
725
- return this.promisify('getMcpTools', { serverName });
726
- }
727
- // ==========================================================================
728
- // LSP (Language Server Protocol) Methods
729
- // ==========================================================================
730
- /**
731
- * Start a language server for a specific language
732
- */
733
- async startLspServer(language, rootUri) {
734
- return this.promisify('startLspServer', {
735
- language,
736
- rootUri: rootUri || '',
737
- });
738
- }
739
- /**
740
- * Stop a running language server
741
- */
742
- async stopLspServer(language) {
743
- return this.promisify('stopLspServer', { language });
744
- }
745
- /**
746
- * List all running language servers
747
- */
748
- async listLspServers() {
749
- return this.promisify('listLspServers', {});
750
- }
751
- /**
752
- * Get hover information at a specific position
753
- */
754
- async lspHover(filePath, line, column) {
755
- return this.promisify('lspHover', {
756
- filePath,
757
- line,
758
- column,
759
- });
760
- }
761
- /**
762
- * Go to definition at a specific position
763
- */
764
- async lspDefinition(filePath, line, column) {
765
- return this.promisify('lspDefinition', {
766
- filePath,
767
- line,
768
- column,
769
- });
770
- }
771
- /**
772
- * Find all references at a specific position
773
- */
774
- async lspReferences(filePath, line, column, includeDeclaration) {
775
- return this.promisify('lspReferences', {
776
- filePath,
777
- line,
778
- column,
779
- includeDeclaration: includeDeclaration || false,
780
- });
781
- }
782
- /**
783
- * Search for symbols in the workspace
784
- */
785
- async lspSymbols(query, limit) {
786
- return this.promisify('lspSymbols', {
787
- query,
788
- limit: limit || 20,
789
- });
790
- }
791
- /**
792
- * Get diagnostics for a file
793
- */
794
- async lspDiagnostics(filePath) {
795
- return this.promisify('lspDiagnostics', {
796
- filePath: filePath || '',
797
- });
798
- }
799
- // ==========================================================================
800
- // Cron (Scheduled Tasks)
801
- // ==========================================================================
802
- /**
803
- * List all cron jobs
804
- */
805
- async listCronJobs() {
806
- return this.promisify('listCronJobs', {});
807
- }
808
- /**
809
- * Create a new cron job
810
- * @param name Job name
811
- * @param schedule Schedule expression (cron syntax or natural language)
812
- * @param command Command to execute
813
- * @param timeoutMs Execution timeout in milliseconds (default: 60000)
814
- */
815
- async createCronJob(name, schedule, command, timeoutMs) {
816
- return this.promisify('createCronJob', {
817
- name,
818
- schedule,
819
- command,
820
- timeoutMs,
821
- });
822
- }
823
- /**
824
- * Get a cron job by ID or name
825
- * @param id Job ID
826
- * @param name Job name (alternative to ID)
827
- */
828
- async getCronJob(id, name) {
829
- return this.promisify('getCronJob', { id, name });
830
- }
831
- /**
832
- * Update a cron job
833
- * @param id Job ID
834
- * @param schedule New schedule expression
835
- * @param command New command
836
- * @param timeoutMs New timeout
837
- */
838
- async updateCronJob(id, schedule, command, timeoutMs) {
839
- return this.promisify('updateCronJob', {
840
- id,
841
- schedule,
842
- command,
843
- timeoutMs,
844
- });
845
- }
846
- /**
847
- * Pause a cron job
848
- * @param id Job ID
849
- */
850
- async pauseCronJob(id) {
851
- return this.promisify('pauseCronJob', { id });
852
- }
853
- /**
854
- * Resume a paused cron job
855
- * @param id Job ID
856
- */
857
- async resumeCronJob(id) {
858
- return this.promisify('resumeCronJob', { id });
859
- }
860
- /**
861
- * Delete a cron job
862
- * @param id Job ID
863
- */
864
- async deleteCronJob(id) {
865
- return this.promisify('deleteCronJob', { id });
866
- }
867
- /**
868
- * Get execution history for a cron job
869
- * @param id Job ID
870
- * @param limit Max records to return (default: 10)
871
- */
872
- async getCronHistory(id, limit) {
873
- return this.promisify('getCronHistory', { id, limit });
874
- }
875
- /**
876
- * Manually run a cron job
877
- * @param id Job ID
878
- */
879
- async runCronJob(id) {
880
- return this.promisify('runCronJob', { id });
881
- }
882
- /**
883
- * Parse natural language schedule to cron expression
884
- * @param input Natural language or cron expression
885
- */
886
- async parseCronSchedule(input) {
887
- return this.promisify('parseCronSchedule', { input });
888
- }
889
- // ==========================================================================
890
- // Observability
891
- // ==========================================================================
892
- async getToolMetrics(sessionId, toolName) {
893
- return this.promisify('getToolMetrics', {
894
- session_id: sessionId || '',
895
- tool_name: toolName || '',
896
- });
897
- }
898
- async getCostSummary(options) {
899
- return this.promisify('getCostSummary', {
900
- session_id: options?.sessionId || '',
901
- model: options?.model || '',
902
- start_date: options?.startDate || '',
903
- end_date: options?.endDate || '',
904
- });
905
- }
906
- // ==========================================================================
907
- // Server-Side AgenticLoop
908
- // ==========================================================================
909
- /**
910
- * Run the server-side AgenticLoop (non-streaming).
911
- * The server executes the full loop: generate → tool call → execute → reflect → repeat.
912
- */
913
- async agenticGenerate(sessionId, prompt, options) {
914
- return this.promisify('agenticGenerate', {
915
- sessionId,
916
- prompt,
917
- strategy: options?.strategy || 'AGENTIC_STRATEGY_AUTO',
918
- maxSteps: options?.maxSteps || 50,
919
- reflection: options?.reflection ?? true,
920
- planning: options?.planning ?? true,
921
- });
922
- }
923
- /**
924
- * Stream the server-side AgenticLoop.
925
- * Returns a stream of AgenticGenerateEvent for real-time UI updates.
926
- */
927
- streamAgenticGenerate(sessionId, prompt, options) {
928
- const call = this.client.streamAgenticGenerate({
929
- sessionId,
930
- prompt,
931
- strategy: options?.strategy || 'AGENTIC_STRATEGY_AUTO',
932
- maxSteps: options?.maxSteps || 50,
933
- reflection: options?.reflection ?? true,
934
- planning: options?.planning ?? true,
935
- });
936
- return this.streamToAsyncIterable(call);
937
- }
938
- // ==========================================================================
939
- // Server-Side Delegation (Subagents)
940
- // ==========================================================================
941
- /**
942
- * Delegate a task to a built-in or custom subagent (non-streaming).
943
- */
944
- async delegate(sessionId, agentName, task, options) {
945
- return this.promisify('delegate', {
946
- sessionId,
947
- agentName,
948
- task,
949
- maxSteps: options?.maxSteps || 50,
950
- allowedTools: options?.allowedTools || [],
951
- });
952
- }
953
- /**
954
- * Delegate a task to a subagent with streaming events.
955
- */
956
- streamDelegate(sessionId, agentName, task, options) {
957
- const call = this.client.streamDelegate({
958
- sessionId,
959
- agentName,
960
- task,
961
- maxSteps: options?.maxSteps || 50,
962
- allowedTools: options?.allowedTools || [],
963
- });
964
- return this.streamToAsyncIterable(call);
965
- }
966
- // ==========================================================================
967
- // Queue Statistics
968
- // ==========================================================================
969
- /**
970
- * Get per-lane queue statistics for a session.
971
- */
972
- async getQueueStats(sessionId) {
973
- return this.promisify('getQueueStats', { sessionId });
974
- }
975
- // ==========================================================================
976
- // Batch Skill Loading
977
- // ==========================================================================
978
- /**
979
- * Load all skills from a directory.
980
- */
981
- async loadSkillsFromDir(sessionId, directory, recursive) {
982
- return this.promisify('loadSkillsFromDir', {
983
- sessionId,
984
- directory,
985
- recursive: recursive ?? true,
986
- });
987
- }
988
- // ==========================================================================
989
- // Helper: Convert gRPC stream to AsyncIterable
990
- // ==========================================================================
991
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
992
- streamToAsyncIterable(call) {
993
- return {
994
- [Symbol.asyncIterator]() {
995
- return {
996
- next() {
997
- return new Promise((resolve, reject) => {
998
- call.once('data', (data) => {
999
- resolve({ value: data, done: false });
1000
- });
1001
- call.once('end', () => {
1002
- resolve({ value: undefined, done: true });
1003
- });
1004
- call.once('error', (error) => {
1005
- reject(error);
1006
- });
1007
- });
1008
- },
1009
- };
1010
- },
1011
- };
1012
- }
1013
- }
1014
- //# sourceMappingURL=client.js.map