agentuity-vscode 0.0.86

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,149 @@
1
+ import * as vscode from 'vscode';
2
+ import * as path from 'path';
3
+ import { getCliClient, type Agent } from '../../core/cliClient';
4
+ import { getCurrentProject } from '../../core/project';
5
+ import { BaseTreeDataProvider } from '../../core/baseTreeDataProvider';
6
+
7
+ export class AgentTreeItem extends vscode.TreeItem {
8
+ constructor(
9
+ public readonly label: string,
10
+ public readonly collapsibleState: vscode.TreeItemCollapsibleState,
11
+ public readonly itemType: 'agent' | 'route' | 'message',
12
+ public readonly agentData?: Agent
13
+ ) {
14
+ super(label, collapsibleState);
15
+
16
+ if (itemType === 'agent') {
17
+ this.iconPath = new vscode.ThemeIcon('robot');
18
+ this.contextValue = 'agent';
19
+ this.tooltip = this.buildAgentTooltip(agentData);
20
+ if (agentData?.metadata?.filename) {
21
+ const project = getCurrentProject();
22
+ if (project) {
23
+ const filePath = path.join(project.rootPath, agentData.metadata.filename);
24
+ this.command = {
25
+ command: 'vscode.open',
26
+ title: 'Open Agent',
27
+ arguments: [vscode.Uri.file(filePath)],
28
+ };
29
+ }
30
+ }
31
+ } else if (itemType === 'route') {
32
+ this.iconPath = new vscode.ThemeIcon('symbol-method');
33
+ this.contextValue = 'route';
34
+ } else if (itemType === 'message') {
35
+ this.iconPath = new vscode.ThemeIcon('info');
36
+ this.contextValue = 'message';
37
+ }
38
+ }
39
+
40
+ private buildAgentTooltip(agent?: Agent): string {
41
+ const lines: string[] = [];
42
+ if (agent?.name) {
43
+ lines.push(`Name: ${agent.name}`);
44
+ }
45
+ if (agent?.description) {
46
+ lines.push(`Description: ${agent.description}`);
47
+ }
48
+ if (agent?.identifier) {
49
+ lines.push(`Identifier: ${agent.identifier}`);
50
+ }
51
+ if (agent?.metadata?.filename) {
52
+ lines.push(`File: ${agent.metadata.filename}`);
53
+ }
54
+ lines.push('');
55
+ lines.push('Right-click for more actions');
56
+ return lines.join('\n');
57
+ }
58
+ }
59
+
60
+ export class AgentTreeDataProvider extends BaseTreeDataProvider<AgentTreeItem> {
61
+ private agents: Agent[] = [];
62
+
63
+ protected createMessageItem(message: string): AgentTreeItem {
64
+ return new AgentTreeItem(message, vscode.TreeItemCollapsibleState.None, 'message');
65
+ }
66
+
67
+ async getChildren(element?: AgentTreeItem): Promise<AgentTreeItem[]> {
68
+ if (element) {
69
+ return [];
70
+ }
71
+
72
+ const authProjectCheck = this.checkAuthAndProject();
73
+ if (authProjectCheck) {
74
+ return authProjectCheck;
75
+ }
76
+
77
+ if (this.loading) {
78
+ return this.getLoadingItems();
79
+ }
80
+
81
+ if (this.error) {
82
+ return this.getErrorItems();
83
+ }
84
+
85
+ if (this.agents.length === 0) {
86
+ await this.loadData();
87
+ }
88
+
89
+ if (this.agents.length === 0) {
90
+ return this.getEmptyItems('No agents found');
91
+ }
92
+
93
+ return this.agents.map(
94
+ (agent) =>
95
+ new AgentTreeItem(agent.name, vscode.TreeItemCollapsibleState.None, 'agent', agent)
96
+ );
97
+ }
98
+
99
+ protected async loadData(): Promise<void> {
100
+ this.loading = true;
101
+ this.error = undefined;
102
+
103
+ try {
104
+ const cli = getCliClient();
105
+ const result = await cli.listAgents();
106
+
107
+ if (result.success && result.data) {
108
+ this.agents = Array.isArray(result.data) ? result.data : [];
109
+ } else {
110
+ // Check for deployment-related errors
111
+ const errorLower = (result.error || '').toLowerCase();
112
+ if (
113
+ errorLower.includes('no deployment') ||
114
+ errorLower.includes('not deployed') ||
115
+ errorLower.includes('deployment not found') ||
116
+ errorLower.includes('no agents')
117
+ ) {
118
+ this.error = 'Deploy first to see agents';
119
+ } else {
120
+ this.error = result.error || 'Failed to load agents';
121
+ }
122
+ this.agents = [];
123
+ }
124
+ } catch (err) {
125
+ this.error = err instanceof Error ? err.message : 'Unknown error';
126
+ this.agents = [];
127
+ } finally {
128
+ this.loading = false;
129
+ }
130
+ }
131
+
132
+ async forceRefresh(): Promise<void> {
133
+ this.agents = [];
134
+ await super.forceRefresh();
135
+ }
136
+
137
+ getAgents(): Agent[] {
138
+ return this.agents;
139
+ }
140
+
141
+ findAgentByIdentifier(identifier: string): Agent | undefined {
142
+ return this.agents.find(
143
+ (a) =>
144
+ a.metadata?.identifier === identifier ||
145
+ a.identifier === identifier ||
146
+ a.name === identifier
147
+ );
148
+ }
149
+ }
@@ -0,0 +1,105 @@
1
+ import * as vscode from 'vscode';
2
+ import * as path from 'path';
3
+ import { AgentTreeDataProvider, AgentTreeItem } from './agentTreeData';
4
+ import { onAuthStatusChanged } from '../../core/auth';
5
+ import { onProjectChanged, getCurrentProject } from '../../core/project';
6
+
7
+ const SESSIONS_BASE_URL = 'https://app-v1.agentuity.com';
8
+
9
+ let agentProvider: AgentTreeDataProvider | undefined;
10
+
11
+ export function getAgentProvider(): AgentTreeDataProvider | undefined {
12
+ return agentProvider;
13
+ }
14
+
15
+ export function registerAgentExplorer(context: vscode.ExtensionContext): AgentTreeDataProvider {
16
+ const provider = new AgentTreeDataProvider();
17
+ agentProvider = provider;
18
+
19
+ const treeView = vscode.window.createTreeView('agentuity.agents', {
20
+ treeDataProvider: provider,
21
+ showCollapseAll: true,
22
+ });
23
+
24
+ const authSub = onAuthStatusChanged(() => {
25
+ provider.refresh();
26
+ });
27
+
28
+ const projectSub = onProjectChanged(() => {
29
+ void provider.forceRefresh();
30
+ });
31
+
32
+ context.subscriptions.push(
33
+ vscode.commands.registerCommand('agentuity.agent.goToFile', async (item: AgentTreeItem) => {
34
+ if (!item?.agentData?.metadata?.filename) {
35
+ vscode.window.showWarningMessage('No source file associated with this agent');
36
+ return;
37
+ }
38
+
39
+ const project = getCurrentProject();
40
+ if (!project) {
41
+ vscode.window.showWarningMessage('No project detected');
42
+ return;
43
+ }
44
+
45
+ const filePath = path.join(project.rootPath, item.agentData.metadata.filename);
46
+ const uri = vscode.Uri.file(filePath);
47
+
48
+ try {
49
+ await vscode.window.showTextDocument(uri);
50
+ } catch {
51
+ vscode.window.showErrorMessage(`Could not open file: ${filePath}`);
52
+ }
53
+ })
54
+ );
55
+
56
+ context.subscriptions.push(
57
+ vscode.commands.registerCommand(
58
+ 'agentuity.agent.viewSessions',
59
+ async (item: AgentTreeItem) => {
60
+ const project = getCurrentProject();
61
+ if (!project) {
62
+ vscode.window.showErrorMessage('No Agentuity project found');
63
+ return;
64
+ }
65
+
66
+ const agent = item?.agentData;
67
+ if (!agent) {
68
+ vscode.window.showWarningMessage('No agent selected');
69
+ return;
70
+ }
71
+
72
+ const url = `${SESSIONS_BASE_URL}/projects/${project.projectId}/sessions?agent=${agent.id}`;
73
+ await vscode.env.openExternal(vscode.Uri.parse(url));
74
+ }
75
+ )
76
+ );
77
+
78
+ context.subscriptions.push(
79
+ vscode.commands.registerCommand(
80
+ 'agentuity.agent.viewSessionLogs',
81
+ async (item: AgentTreeItem) => {
82
+ const project = getCurrentProject();
83
+ if (!project) {
84
+ vscode.window.showErrorMessage('No Agentuity project found');
85
+ return;
86
+ }
87
+
88
+ const agent = item?.agentData;
89
+ if (!agent) {
90
+ vscode.window.showWarningMessage('No agent selected');
91
+ return;
92
+ }
93
+
94
+ const url = `${SESSIONS_BASE_URL}/projects/${project.projectId}/sessions?agent=${agent.id}`;
95
+ await vscode.env.openExternal(vscode.Uri.parse(url));
96
+ }
97
+ )
98
+ );
99
+
100
+ context.subscriptions.push(treeView, authSub, projectSub, { dispose: () => provider.dispose() });
101
+
102
+ return provider;
103
+ }
104
+
105
+ export { AgentTreeDataProvider };