agentuity-vscode 0.0.95 → 0.0.97

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.
@@ -0,0 +1,529 @@
1
+ import * as vscode from 'vscode';
2
+ import { getCliClient } from '../../core/cliClient';
3
+ import { getAuthStatus } from '../../core/auth';
4
+ import { hasProject, getCurrentProject } from '../../core/project';
5
+ import { getDevServerManager } from '../devServer';
6
+
7
+ export interface GetAgentsInput {
8
+ includeDetails?: boolean;
9
+ }
10
+
11
+ export class GetAgentsTool implements vscode.LanguageModelTool<GetAgentsInput> {
12
+ async invoke(
13
+ _options: vscode.LanguageModelToolInvocationOptions<GetAgentsInput>,
14
+ _token: vscode.CancellationToken
15
+ ): Promise<vscode.LanguageModelToolResult> {
16
+ if (!hasProject()) {
17
+ throw new Error('No Agentuity project found in the current workspace.');
18
+ }
19
+
20
+ const cli = getCliClient();
21
+ const result = await cli.listAgents();
22
+
23
+ if (!result.success || !result.data) {
24
+ throw new Error(`Failed to list agents: ${result.error || 'Unknown error'}`);
25
+ }
26
+
27
+ const agents = result.data;
28
+ if (agents.length === 0) {
29
+ return new vscode.LanguageModelToolResult([
30
+ new vscode.LanguageModelTextPart('No agents found in this project.'),
31
+ ]);
32
+ }
33
+
34
+ const output = agents.map((agent) => ({
35
+ name: agent.name,
36
+ id: agent.id,
37
+ identifier: agent.identifier,
38
+ description: agent.description,
39
+ sourceFile: agent.metadata?.filename,
40
+ }));
41
+
42
+ return new vscode.LanguageModelToolResult([
43
+ new vscode.LanguageModelTextPart(JSON.stringify(output, null, 2)),
44
+ ]);
45
+ }
46
+
47
+ async prepareInvocation(
48
+ _options: vscode.LanguageModelToolInvocationPrepareOptions<GetAgentsInput>,
49
+ _token: vscode.CancellationToken
50
+ ): Promise<vscode.PreparedToolInvocation> {
51
+ return {
52
+ invocationMessage: 'Fetching Agentuity agents...',
53
+ };
54
+ }
55
+ }
56
+
57
+ export type GetProjectStatusInput = Record<string, never>;
58
+
59
+ export class GetProjectStatusTool implements vscode.LanguageModelTool<GetProjectStatusInput> {
60
+ async invoke(
61
+ _options: vscode.LanguageModelToolInvocationOptions<GetProjectStatusInput>,
62
+ _token: vscode.CancellationToken
63
+ ): Promise<vscode.LanguageModelToolResult> {
64
+ const status: Record<string, unknown> = {};
65
+
66
+ const authStatus = getAuthStatus();
67
+ status.authentication = {
68
+ state: authStatus.state,
69
+ user: authStatus.user
70
+ ? { name: `${authStatus.user.firstName} ${authStatus.user.lastName}` }
71
+ : null,
72
+ };
73
+
74
+ const project = getCurrentProject();
75
+ status.project = project
76
+ ? {
77
+ projectId: project.projectId,
78
+ orgId: project.orgId,
79
+ region: project.region,
80
+ rootPath: project.rootPath,
81
+ }
82
+ : null;
83
+
84
+ const devServer = getDevServerManager();
85
+ status.devServer = {
86
+ state: devServer.getState(),
87
+ };
88
+
89
+ if (hasProject()) {
90
+ const cli = getCliClient();
91
+
92
+ const agentsResult = await cli.listAgents();
93
+ status.agentCount = agentsResult.success ? agentsResult.data?.length || 0 : 0;
94
+
95
+ const deploymentsResult = await cli.listDeployments();
96
+ if (deploymentsResult.success && deploymentsResult.data) {
97
+ const active = deploymentsResult.data.find((d) => d.active);
98
+ status.activeDeployment = active
99
+ ? {
100
+ id: active.id,
101
+ createdAt: active.createdAt,
102
+ tags: active.tags,
103
+ }
104
+ : null;
105
+ status.totalDeployments = deploymentsResult.data.length;
106
+ }
107
+ }
108
+
109
+ return new vscode.LanguageModelToolResult([
110
+ new vscode.LanguageModelTextPart(JSON.stringify(status, null, 2)),
111
+ ]);
112
+ }
113
+
114
+ async prepareInvocation(
115
+ _options: vscode.LanguageModelToolInvocationPrepareOptions<GetProjectStatusInput>,
116
+ _token: vscode.CancellationToken
117
+ ): Promise<vscode.PreparedToolInvocation> {
118
+ return {
119
+ invocationMessage: 'Getting Agentuity project status...',
120
+ };
121
+ }
122
+ }
123
+
124
+ export interface GetSessionsInput {
125
+ count?: number;
126
+ agentName?: string;
127
+ }
128
+
129
+ export class GetSessionsTool implements vscode.LanguageModelTool<GetSessionsInput> {
130
+ async invoke(
131
+ options: vscode.LanguageModelToolInvocationOptions<GetSessionsInput>,
132
+ _token: vscode.CancellationToken
133
+ ): Promise<vscode.LanguageModelToolResult> {
134
+ if (!hasProject()) {
135
+ throw new Error('No Agentuity project found in the current workspace.');
136
+ }
137
+
138
+ const cli = getCliClient();
139
+ const count = options.input.count || 10;
140
+ const result = await cli.listSessions({ count });
141
+
142
+ if (!result.success || !result.data) {
143
+ throw new Error(`Failed to list sessions: ${result.error || 'Unknown error'}`);
144
+ }
145
+
146
+ const sessions = result.data.map((session) => ({
147
+ id: session.id,
148
+ createdAt: session.created_at,
149
+ success: session.success,
150
+ duration: session.duration,
151
+ trigger: session.trigger,
152
+ env: session.env,
153
+ }));
154
+
155
+ return new vscode.LanguageModelToolResult([
156
+ new vscode.LanguageModelTextPart(JSON.stringify(sessions, null, 2)),
157
+ ]);
158
+ }
159
+
160
+ async prepareInvocation(
161
+ options: vscode.LanguageModelToolInvocationPrepareOptions<GetSessionsInput>,
162
+ _token: vscode.CancellationToken
163
+ ): Promise<vscode.PreparedToolInvocation> {
164
+ const count = options.input.count || 10;
165
+ return {
166
+ invocationMessage: `Fetching last ${count} sessions...`,
167
+ };
168
+ }
169
+ }
170
+
171
+ export interface GetSessionLogsInput {
172
+ sessionId: string;
173
+ }
174
+
175
+ export class GetSessionLogsTool implements vscode.LanguageModelTool<GetSessionLogsInput> {
176
+ async invoke(
177
+ options: vscode.LanguageModelToolInvocationOptions<GetSessionLogsInput>,
178
+ _token: vscode.CancellationToken
179
+ ): Promise<vscode.LanguageModelToolResult> {
180
+ if (!hasProject()) {
181
+ throw new Error('No Agentuity project found in the current workspace.');
182
+ }
183
+
184
+ const { sessionId } = options.input;
185
+ if (!sessionId) {
186
+ throw new Error('Session ID is required.');
187
+ }
188
+
189
+ const cli = getCliClient();
190
+ const result = await cli.getSessionLogs(sessionId);
191
+
192
+ if (!result.success || !result.data) {
193
+ throw new Error(`Failed to get session logs: ${result.error || 'Unknown error'}`);
194
+ }
195
+
196
+ const logs = result.data.map((log) => ({
197
+ timestamp: log.timestamp,
198
+ severity: log.severity,
199
+ message: log.body,
200
+ }));
201
+
202
+ return new vscode.LanguageModelToolResult([
203
+ new vscode.LanguageModelTextPart(JSON.stringify(logs, null, 2)),
204
+ ]);
205
+ }
206
+
207
+ async prepareInvocation(
208
+ options: vscode.LanguageModelToolInvocationPrepareOptions<GetSessionLogsInput>,
209
+ _token: vscode.CancellationToken
210
+ ): Promise<vscode.PreparedToolInvocation> {
211
+ return {
212
+ invocationMessage: `Fetching logs for session ${options.input.sessionId?.substring(0, 8)}...`,
213
+ };
214
+ }
215
+ }
216
+
217
+ export interface ControlDevServerInput {
218
+ action: 'start' | 'stop' | 'restart' | 'status';
219
+ }
220
+
221
+ export class ControlDevServerTool implements vscode.LanguageModelTool<ControlDevServerInput> {
222
+ async invoke(
223
+ options: vscode.LanguageModelToolInvocationOptions<ControlDevServerInput>,
224
+ _token: vscode.CancellationToken
225
+ ): Promise<vscode.LanguageModelToolResult> {
226
+ if (!hasProject()) {
227
+ throw new Error('No Agentuity project found in the current workspace.');
228
+ }
229
+
230
+ const devServer = getDevServerManager();
231
+ const { action } = options.input;
232
+
233
+ switch (action) {
234
+ case 'start':
235
+ if (devServer.getState() === 'running') {
236
+ return new vscode.LanguageModelToolResult([
237
+ new vscode.LanguageModelTextPart('Dev server is already running.'),
238
+ ]);
239
+ }
240
+ await devServer.start();
241
+ return new vscode.LanguageModelToolResult([
242
+ new vscode.LanguageModelTextPart('Dev server started successfully.'),
243
+ ]);
244
+
245
+ case 'stop':
246
+ if (devServer.getState() === 'stopped') {
247
+ return new vscode.LanguageModelToolResult([
248
+ new vscode.LanguageModelTextPart('Dev server is not running.'),
249
+ ]);
250
+ }
251
+ await devServer.stop();
252
+ return new vscode.LanguageModelToolResult([
253
+ new vscode.LanguageModelTextPart('Dev server stopped.'),
254
+ ]);
255
+
256
+ case 'restart':
257
+ await devServer.restart();
258
+ return new vscode.LanguageModelToolResult([
259
+ new vscode.LanguageModelTextPart('Dev server restarted.'),
260
+ ]);
261
+
262
+ case 'status':
263
+ return new vscode.LanguageModelToolResult([
264
+ new vscode.LanguageModelTextPart(
265
+ JSON.stringify({ state: devServer.getState() }, null, 2)
266
+ ),
267
+ ]);
268
+
269
+ default:
270
+ throw new Error(
271
+ `Unknown action: ${action}. Valid actions: start, stop, restart, status`
272
+ );
273
+ }
274
+ }
275
+
276
+ async prepareInvocation(
277
+ options: vscode.LanguageModelToolInvocationPrepareOptions<ControlDevServerInput>,
278
+ _token: vscode.CancellationToken
279
+ ): Promise<vscode.PreparedToolInvocation> {
280
+ const { action } = options.input;
281
+
282
+ if (action === 'start' || action === 'restart') {
283
+ return {
284
+ invocationMessage: `${action === 'start' ? 'Starting' : 'Restarting'} dev server...`,
285
+ confirmationMessages: {
286
+ title: `${action === 'start' ? 'Start' : 'Restart'} Dev Server`,
287
+ message: new vscode.MarkdownString(
288
+ `This will ${action} the Agentuity dev server for local testing.\n\nDo you want to continue?`
289
+ ),
290
+ },
291
+ };
292
+ }
293
+
294
+ return {
295
+ invocationMessage:
296
+ action === 'stop' ? 'Stopping dev server...' : 'Getting dev server status...',
297
+ };
298
+ }
299
+ }
300
+
301
+ export interface GetDeploymentsInput {
302
+ limit?: number;
303
+ }
304
+
305
+ export class GetDeploymentsTool implements vscode.LanguageModelTool<GetDeploymentsInput> {
306
+ async invoke(
307
+ options: vscode.LanguageModelToolInvocationOptions<GetDeploymentsInput>,
308
+ _token: vscode.CancellationToken
309
+ ): Promise<vscode.LanguageModelToolResult> {
310
+ if (!hasProject()) {
311
+ throw new Error('No Agentuity project found in the current workspace.');
312
+ }
313
+
314
+ const cli = getCliClient();
315
+ const result = await cli.listDeployments();
316
+
317
+ if (!result.success || !result.data) {
318
+ throw new Error(`Failed to list deployments: ${result.error || 'Unknown error'}`);
319
+ }
320
+
321
+ const limit = options.input.limit || 10;
322
+ const deployments = result.data.slice(0, limit).map((dep) => ({
323
+ id: dep.id,
324
+ active: dep.active,
325
+ state: dep.state,
326
+ createdAt: dep.createdAt,
327
+ tags: dep.tags,
328
+ }));
329
+
330
+ return new vscode.LanguageModelToolResult([
331
+ new vscode.LanguageModelTextPart(JSON.stringify(deployments, null, 2)),
332
+ ]);
333
+ }
334
+
335
+ async prepareInvocation(
336
+ _options: vscode.LanguageModelToolInvocationPrepareOptions<GetDeploymentsInput>,
337
+ _token: vscode.CancellationToken
338
+ ): Promise<vscode.PreparedToolInvocation> {
339
+ return {
340
+ invocationMessage: 'Fetching deployments...',
341
+ };
342
+ }
343
+ }
344
+
345
+ export interface DeployProjectInput {
346
+ message?: string;
347
+ }
348
+
349
+ export class DeployProjectTool implements vscode.LanguageModelTool<DeployProjectInput> {
350
+ async invoke(
351
+ _options: vscode.LanguageModelToolInvocationOptions<DeployProjectInput>,
352
+ _token: vscode.CancellationToken
353
+ ): Promise<vscode.LanguageModelToolResult> {
354
+ if (!hasProject()) {
355
+ throw new Error('No Agentuity project found in the current workspace.');
356
+ }
357
+
358
+ const authStatus = getAuthStatus();
359
+ if (authStatus.state !== 'authenticated') {
360
+ throw new Error('You must be logged in to deploy. Run "agentuity auth login" first.');
361
+ }
362
+
363
+ const terminal = vscode.window.createTerminal('Agentuity Deploy');
364
+ terminal.sendText('agentuity cloud deploy');
365
+ terminal.show();
366
+
367
+ return new vscode.LanguageModelToolResult([
368
+ new vscode.LanguageModelTextPart(
369
+ 'Deployment started in terminal. Check the terminal output for progress.'
370
+ ),
371
+ ]);
372
+ }
373
+
374
+ async prepareInvocation(
375
+ _options: vscode.LanguageModelToolInvocationPrepareOptions<DeployProjectInput>,
376
+ _token: vscode.CancellationToken
377
+ ): Promise<vscode.PreparedToolInvocation> {
378
+ return {
379
+ invocationMessage: 'Preparing deployment...',
380
+ confirmationMessages: {
381
+ title: 'Deploy to Agentuity Cloud',
382
+ message: new vscode.MarkdownString(
383
+ 'This will deploy your Agentuity project to the cloud.\n\n**Warning**: This will make your agents publicly accessible.\n\nDo you want to continue?'
384
+ ),
385
+ },
386
+ };
387
+ }
388
+ }
389
+
390
+ export interface GetHealthSummaryInput {
391
+ sessionCount?: number;
392
+ }
393
+
394
+ export class GetHealthSummaryTool implements vscode.LanguageModelTool<GetHealthSummaryInput> {
395
+ async invoke(
396
+ options: vscode.LanguageModelToolInvocationOptions<GetHealthSummaryInput>,
397
+ _token: vscode.CancellationToken
398
+ ): Promise<vscode.LanguageModelToolResult> {
399
+ if (!hasProject()) {
400
+ throw new Error('No Agentuity project found in the current workspace.');
401
+ }
402
+
403
+ const cli = getCliClient();
404
+ const sessionCount = options.input.sessionCount || 20;
405
+
406
+ const health: Record<string, unknown> = {
407
+ timestamp: new Date().toISOString(),
408
+ };
409
+
410
+ const sessionsResult = await cli.listSessions({ count: sessionCount });
411
+ if (sessionsResult.success && sessionsResult.data) {
412
+ const sessions = sessionsResult.data;
413
+ const successful = sessions.filter((s) => s.success).length;
414
+ const failed = sessions.filter((s) => !s.success).length;
415
+
416
+ health.sessions = {
417
+ total: sessions.length,
418
+ successful,
419
+ failed,
420
+ successRate:
421
+ sessions.length > 0
422
+ ? ((successful / sessions.length) * 100).toFixed(1) + '%'
423
+ : 'N/A',
424
+ recentFailures: sessions
425
+ .filter((s) => !s.success)
426
+ .slice(0, 5)
427
+ .map((s) => ({
428
+ id: s.id,
429
+ createdAt: s.created_at,
430
+ trigger: s.trigger,
431
+ })),
432
+ };
433
+
434
+ const durations = sessions.filter((s) => s.duration).map((s) => s.duration!);
435
+ if (durations.length > 0) {
436
+ const avgDuration = durations.reduce((a, b) => a + b, 0) / durations.length;
437
+ health.performance = {
438
+ avgDurationMs: (avgDuration / 1_000_000).toFixed(0),
439
+ minDurationMs: (Math.min(...durations) / 1_000_000).toFixed(0),
440
+ maxDurationMs: (Math.max(...durations) / 1_000_000).toFixed(0),
441
+ };
442
+ }
443
+ }
444
+
445
+ const deploymentsResult = await cli.listDeployments();
446
+ if (deploymentsResult.success && deploymentsResult.data) {
447
+ const deployments = deploymentsResult.data;
448
+ const active = deployments.find((d) => d.active);
449
+
450
+ health.deployment = {
451
+ totalDeployments: deployments.length,
452
+ activeDeployment: active
453
+ ? {
454
+ id: active.id,
455
+ createdAt: active.createdAt,
456
+ tags: active.tags,
457
+ }
458
+ : null,
459
+ lastDeployment: deployments[0]
460
+ ? {
461
+ id: deployments[0].id,
462
+ createdAt: deployments[0].createdAt,
463
+ state: deployments[0].state,
464
+ }
465
+ : null,
466
+ };
467
+ }
468
+
469
+ const devServer = getDevServerManager();
470
+ health.devServer = {
471
+ state: devServer.getState(),
472
+ };
473
+
474
+ return new vscode.LanguageModelToolResult([
475
+ new vscode.LanguageModelTextPart(JSON.stringify(health, null, 2)),
476
+ ]);
477
+ }
478
+
479
+ async prepareInvocation(
480
+ _options: vscode.LanguageModelToolInvocationPrepareOptions<GetHealthSummaryInput>,
481
+ _token: vscode.CancellationToken
482
+ ): Promise<vscode.PreparedToolInvocation> {
483
+ return {
484
+ invocationMessage: 'Analyzing project health...',
485
+ };
486
+ }
487
+ }
488
+
489
+ export function registerAgentTools(context: vscode.ExtensionContext): void {
490
+ if (!vscode.lm?.registerTool) {
491
+ return;
492
+ }
493
+
494
+ try {
495
+ context.subscriptions.push(
496
+ vscode.lm.registerTool('agentuity_get_agents', new GetAgentsTool())
497
+ );
498
+
499
+ context.subscriptions.push(
500
+ vscode.lm.registerTool('agentuity_get_project_status', new GetProjectStatusTool())
501
+ );
502
+
503
+ context.subscriptions.push(
504
+ vscode.lm.registerTool('agentuity_get_sessions', new GetSessionsTool())
505
+ );
506
+
507
+ context.subscriptions.push(
508
+ vscode.lm.registerTool('agentuity_get_session_logs', new GetSessionLogsTool())
509
+ );
510
+
511
+ context.subscriptions.push(
512
+ vscode.lm.registerTool('agentuity_control_dev_server', new ControlDevServerTool())
513
+ );
514
+
515
+ context.subscriptions.push(
516
+ vscode.lm.registerTool('agentuity_get_deployments', new GetDeploymentsTool())
517
+ );
518
+
519
+ context.subscriptions.push(
520
+ vscode.lm.registerTool('agentuity_deploy_project', new DeployProjectTool())
521
+ );
522
+
523
+ context.subscriptions.push(
524
+ vscode.lm.registerTool('agentuity_get_health_summary', new GetHealthSummaryTool())
525
+ );
526
+ } catch {
527
+ // LM API not available
528
+ }
529
+ }
@@ -301,7 +301,7 @@ async function gatherProjectContext(token?: vscode.CancellationToken): Promise<s
301
301
  const authStatus = getAuthStatus();
302
302
  lines.push(`- Authenticated: ${authStatus.state === 'authenticated' ? 'Yes' : 'No'}`);
303
303
  if (authStatus.user) {
304
- lines.push(`- User: ${authStatus.user.email}`);
304
+ lines.push(`- User: ${authStatus.user.firstName} ${authStatus.user.lastName}`);
305
305
  }
306
306
 
307
307
  if (token?.isCancellationRequested) {
@@ -522,7 +522,9 @@ async function handleStatus(stream: vscode.ChatResponseStream): Promise<vscode.C
522
522
 
523
523
  stream.markdown('### Authentication\n');
524
524
  if (authStatus.state === 'authenticated' && authStatus.user) {
525
- stream.markdown(`✓ Logged in as **${authStatus.user.email}**\n\n`);
525
+ stream.markdown(
526
+ `✓ Logged in as **${authStatus.user.firstName} ${authStatus.user.lastName}**\n\n`
527
+ );
526
528
  } else {
527
529
  stream.markdown(`✗ Not logged in\n\n`);
528
530
  stream.button({ title: 'Login', command: 'agentuity.login' });