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,5 @@
1
+ export * from './cliClient';
2
+ export * from './auth';
3
+ export * from './project';
4
+ export * from './service';
5
+ export * from './baseTreeDataProvider';
@@ -0,0 +1,98 @@
1
+ import * as vscode from 'vscode';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import * as jsonc from 'jsonc-parser';
5
+
6
+ export interface AgentuityProject {
7
+ projectId: string;
8
+ orgId: string;
9
+ region?: string;
10
+ rootPath: string;
11
+ }
12
+
13
+ let _currentProject: AgentuityProject | undefined;
14
+ const _onProjectChanged = new vscode.EventEmitter<AgentuityProject | undefined>();
15
+ export const onProjectChanged = _onProjectChanged.event;
16
+
17
+ export function getCurrentProject(): AgentuityProject | undefined {
18
+ return _currentProject;
19
+ }
20
+
21
+ export function hasProject(): boolean {
22
+ return _currentProject !== undefined;
23
+ }
24
+
25
+ function setProject(project: AgentuityProject | undefined): void {
26
+ _currentProject = project;
27
+ _onProjectChanged.fire(project);
28
+ void vscode.commands.executeCommand('setContext', 'agentuity.hasProject', project !== undefined);
29
+ }
30
+
31
+ export async function detectProject(): Promise<AgentuityProject | undefined> {
32
+ const workspaceFolders = vscode.workspace.workspaceFolders;
33
+
34
+ if (!workspaceFolders || workspaceFolders.length === 0) {
35
+ setProject(undefined);
36
+ return undefined;
37
+ }
38
+
39
+ for (const folder of workspaceFolders) {
40
+ const configPath = path.join(folder.uri.fsPath, 'agentuity.json');
41
+
42
+ if (fs.existsSync(configPath)) {
43
+ try {
44
+ const content = fs.readFileSync(configPath, 'utf-8');
45
+ const config = jsonc.parse(content) as Record<string, unknown>;
46
+
47
+ const project: AgentuityProject = {
48
+ projectId: config.projectId as string,
49
+ orgId: config.orgId as string,
50
+ region: config.region as string | undefined,
51
+ rootPath: folder.uri.fsPath,
52
+ };
53
+
54
+ setProject(project);
55
+ return project;
56
+ } catch {
57
+ // Invalid JSON, continue to next folder
58
+ }
59
+ }
60
+ }
61
+
62
+ setProject(undefined);
63
+ return undefined;
64
+ }
65
+
66
+ export function requireProject(): boolean {
67
+ if (!hasProject()) {
68
+ vscode.window
69
+ .showWarningMessage(
70
+ 'No Agentuity project found. Open a folder containing agentuity.json.',
71
+ 'Learn More'
72
+ )
73
+ .then((action) => {
74
+ if (action === 'Learn More') {
75
+ void vscode.env.openExternal(
76
+ vscode.Uri.parse('https://agentuity.com/docs/getting-started')
77
+ );
78
+ }
79
+ });
80
+ return false;
81
+ }
82
+ return true;
83
+ }
84
+
85
+ export function watchProjectConfig(context: vscode.ExtensionContext): void {
86
+ const watcher = vscode.workspace.createFileSystemWatcher('**/agentuity.json');
87
+
88
+ watcher.onDidCreate(() => void detectProject());
89
+ watcher.onDidDelete(() => void detectProject());
90
+ watcher.onDidChange(() => void detectProject());
91
+
92
+ context.subscriptions.push(watcher);
93
+ }
94
+
95
+ export function disposeProject(): void {
96
+ _currentProject = undefined;
97
+ _onProjectChanged.dispose();
98
+ }
@@ -0,0 +1,57 @@
1
+ import * as vscode from 'vscode';
2
+
3
+ const SCHEME = 'agentuity-readonly';
4
+
5
+ const contentMap = new Map<string, { content: string; language: string }>();
6
+ let counter = 0;
7
+
8
+ class ReadonlyDocumentProvider implements vscode.TextDocumentContentProvider {
9
+ provideTextDocumentContent(uri: vscode.Uri): string {
10
+ const data = contentMap.get(uri.path);
11
+ return data?.content ?? '';
12
+ }
13
+ }
14
+
15
+ let registered = false;
16
+
17
+ export function registerReadonlyDocumentProvider(context: vscode.ExtensionContext): void {
18
+ if (registered) return;
19
+ registered = true;
20
+
21
+ context.subscriptions.push(
22
+ vscode.workspace.registerTextDocumentContentProvider(SCHEME, new ReadonlyDocumentProvider())
23
+ );
24
+ }
25
+
26
+ export async function openReadonlyDocument(
27
+ content: string,
28
+ language: string,
29
+ title?: string
30
+ ): Promise<vscode.TextEditor> {
31
+ const id = `${++counter}`;
32
+ const name = title || `Agentuity-${id}`;
33
+ const path = `/${name}.${getExtension(language)}`;
34
+
35
+ contentMap.set(path, { content, language });
36
+
37
+ const uri = vscode.Uri.parse(`${SCHEME}:${path}`);
38
+ const doc = await vscode.workspace.openTextDocument(uri);
39
+
40
+ return vscode.window.showTextDocument(doc, { preview: false });
41
+ }
42
+
43
+ function getExtension(language: string): string {
44
+ const extensions: Record<string, string> = {
45
+ json: 'json',
46
+ javascript: 'js',
47
+ typescript: 'ts',
48
+ html: 'html',
49
+ css: 'css',
50
+ xml: 'xml',
51
+ yaml: 'yaml',
52
+ markdown: 'md',
53
+ log: 'log',
54
+ plaintext: 'txt',
55
+ };
56
+ return extensions[language] || 'txt';
57
+ }
@@ -0,0 +1,208 @@
1
+
2
+ import {
3
+ getCliClient,
4
+ type CliClient,
5
+ type Agent,
6
+ type Session,
7
+ type Deployment,
8
+ type DbInfo,
9
+ type VectorSearchResult,
10
+ } from './cliClient';
11
+ import { getAuthStatus, checkAuth, type AuthStatus } from './auth';
12
+ import { getCurrentProject, hasProject, type AgentuityProject } from './project';
13
+ import { getDevServerManager, type DevServerState } from '../features/devServer';
14
+
15
+ export interface AgentuityStatus {
16
+ auth: AuthStatus;
17
+ project: AgentuityProject | undefined;
18
+ devServer: DevServerState;
19
+ isReady: boolean;
20
+ }
21
+
22
+ export interface ListAgentsResult {
23
+ success: boolean;
24
+ agents: Agent[];
25
+ error?: string;
26
+ }
27
+
28
+ export interface ListSessionsResult {
29
+ success: boolean;
30
+ sessions: Session[];
31
+ error?: string;
32
+ }
33
+
34
+ export interface ListDeploymentsResult {
35
+ success: boolean;
36
+ deployments: Deployment[];
37
+ error?: string;
38
+ }
39
+
40
+ export interface ListDatabasesResult {
41
+ success: boolean;
42
+ databases: DbInfo[];
43
+ error?: string;
44
+ }
45
+
46
+ export interface VectorSearchResultData {
47
+ success: boolean;
48
+ results: VectorSearchResult[];
49
+ error?: string;
50
+ }
51
+
52
+ export class AgentuityService {
53
+ private cli: CliClient;
54
+
55
+ constructor() {
56
+ this.cli = getCliClient();
57
+ }
58
+
59
+ getStatus(): AgentuityStatus {
60
+ const auth = getAuthStatus();
61
+ const project = getCurrentProject();
62
+ const devServer = getDevServerManager().getState();
63
+
64
+ return {
65
+ auth,
66
+ project,
67
+ devServer,
68
+ isReady: auth.state === 'authenticated' && project !== undefined,
69
+ };
70
+ }
71
+
72
+ async refreshAuth(): Promise<AuthStatus> {
73
+ return checkAuth();
74
+ }
75
+
76
+ hasProject(): boolean {
77
+ return hasProject();
78
+ }
79
+
80
+ getProject(): AgentuityProject | undefined {
81
+ return getCurrentProject();
82
+ }
83
+
84
+ isDevServerRunning(): boolean {
85
+ return getDevServerManager().getState() === 'running';
86
+ }
87
+
88
+ async ensureDevServerRunning(): Promise<boolean> {
89
+ const devServer = getDevServerManager();
90
+ if (devServer.getState() === 'running') {
91
+ return true;
92
+ }
93
+
94
+ await devServer.start();
95
+
96
+ return new Promise((resolve) => {
97
+ const timeout = setTimeout(() => {
98
+ resolve(devServer.getState() === 'running');
99
+ }, 5000);
100
+
101
+ const disposable = devServer.onStateChanged((state) => {
102
+ if (state === 'running') {
103
+ clearTimeout(timeout);
104
+ disposable.dispose();
105
+ resolve(true);
106
+ } else if (state === 'error' || state === 'stopped') {
107
+ clearTimeout(timeout);
108
+ disposable.dispose();
109
+ resolve(false);
110
+ }
111
+ });
112
+ });
113
+ }
114
+
115
+ async listAgents(): Promise<ListAgentsResult> {
116
+ const result = await this.cli.listAgents();
117
+ return {
118
+ success: result.success,
119
+ agents: result.data || [],
120
+ error: result.error,
121
+ };
122
+ }
123
+
124
+ async listSessions(count = 10): Promise<ListSessionsResult> {
125
+ const result = await this.cli.listSessions({ count });
126
+ return {
127
+ success: result.success,
128
+ sessions: result.data || [],
129
+ error: result.error,
130
+ };
131
+ }
132
+
133
+ async listDeployments(): Promise<ListDeploymentsResult> {
134
+ const result = await this.cli.listDeployments();
135
+ return {
136
+ success: result.success,
137
+ deployments: result.data || [],
138
+ error: result.error,
139
+ };
140
+ }
141
+
142
+ async listDatabases(): Promise<ListDatabasesResult> {
143
+ const result = await this.cli.listDatabases();
144
+ return {
145
+ success: result.success,
146
+ databases: result.data?.databases || [],
147
+ error: result.error,
148
+ };
149
+ }
150
+
151
+ async listKvNamespaces(): Promise<{ success: boolean; namespaces: string[]; error?: string }> {
152
+ const result = await this.cli.listKvNamespaces();
153
+ return {
154
+ success: result.success,
155
+ namespaces: result.data || [],
156
+ error: result.error,
157
+ };
158
+ }
159
+
160
+ async listKvKeys(
161
+ namespace: string
162
+ ): Promise<{ success: boolean; keys: string[]; error?: string }> {
163
+ const result = await this.cli.listKvKeys(namespace);
164
+ return {
165
+ success: result.success,
166
+ keys: result.data?.keys || [],
167
+ error: result.error,
168
+ };
169
+ }
170
+
171
+ async vectorSearch(namespace: string, query: string): Promise<VectorSearchResultData> {
172
+ const result = await this.cli.vectorSearch(namespace, query);
173
+ return {
174
+ success: result.success,
175
+ results: result.data?.results || [],
176
+ error: result.error,
177
+ };
178
+ }
179
+
180
+ async getSessionLogs(
181
+ sessionId: string
182
+ ): Promise<{ success: boolean; logs: Array<{ body: string; severity: string; timestamp: string }>; error?: string }> {
183
+ const result = await this.cli.getSessionLogs(sessionId);
184
+ return {
185
+ success: result.success,
186
+ logs: result.data || [],
187
+ error: result.error,
188
+ };
189
+ }
190
+
191
+ async getCliHelp(): Promise<string> {
192
+ const result = await this.cli.getAiPrompt();
193
+ return result.success && result.data ? result.data : '';
194
+ }
195
+ }
196
+
197
+ let _service: AgentuityService | undefined;
198
+
199
+ export function getAgentuityService(): AgentuityService {
200
+ if (!_service) {
201
+ _service = new AgentuityService();
202
+ }
203
+ return _service;
204
+ }
205
+
206
+ export function disposeAgentuityService(): void {
207
+ _service = undefined;
208
+ }
@@ -0,0 +1,260 @@
1
+ import * as vscode from 'vscode';
2
+ import {
3
+ getCliClient,
4
+ disposeCliClient,
5
+ checkAuth,
6
+ promptLogin,
7
+ disposeAuth,
8
+ detectProject,
9
+ watchProjectConfig,
10
+ disposeProject,
11
+ requireAuth,
12
+ } from './core';
13
+ import { registerReadonlyDocumentProvider } from './core/readonlyDocument';
14
+ import { registerAgentExplorer } from './features/agentExplorer';
15
+ import { registerDataExplorer } from './features/dataExplorer';
16
+ import { registerDeploymentExplorer } from './features/deploymentExplorer';
17
+ import { registerDevServerCommands } from './features/devServer';
18
+ import { registerWorkbenchCommands } from './features/workbench';
19
+ import { registerChatParticipant, registerCliTool } from './features/chat';
20
+ import { registerCodeLens } from './features/codeLens';
21
+
22
+ const outputChannel = vscode.window.createOutputChannel('Agentuity');
23
+
24
+ function log(message: string): void {
25
+ outputChannel.appendLine(`[${new Date().toISOString()}] ${message}`);
26
+ }
27
+
28
+ export async function activate(context: vscode.ExtensionContext): Promise<void> {
29
+ log('Extension activating...');
30
+
31
+ watchProjectConfig(context);
32
+ registerReadonlyDocumentProvider(context);
33
+
34
+ const project = await detectProject();
35
+ log(`Project: ${project ? project.projectId : 'none'}`);
36
+
37
+ const authStatus = await checkAuth();
38
+ log(`Auth: ${authStatus.state}${authStatus.user ? ` (${authStatus.user.email})` : ''}`);
39
+
40
+ if (authStatus.state === 'cli-missing' || authStatus.state === 'unauthenticated') {
41
+ void promptLogin();
42
+ }
43
+
44
+ registerAuthCommands(context);
45
+ registerAiCommands(context);
46
+ registerSetupCommands(context);
47
+ registerDeployCommand(context);
48
+
49
+ const walkthroughShown = context.globalState.get('agentuity.walkthroughShown', false);
50
+ if (!walkthroughShown) {
51
+ await context.globalState.update('agentuity.walkthroughShown', true);
52
+ void vscode.commands.executeCommand(
53
+ 'workbench.action.openWalkthrough',
54
+ 'agentuity.agentuity#gettingStarted',
55
+ false
56
+ );
57
+ }
58
+
59
+ const agentProvider = registerAgentExplorer(context);
60
+ const dataProvider = registerDataExplorer(context);
61
+ const deploymentProvider = registerDeploymentExplorer(context);
62
+
63
+ registerRefreshCommands(context, {
64
+ agents: agentProvider,
65
+ data: dataProvider,
66
+ deployments: deploymentProvider,
67
+ });
68
+
69
+ context.subscriptions.push({
70
+ dispose: () => {
71
+ agentProvider.dispose();
72
+ dataProvider.dispose();
73
+ deploymentProvider.dispose();
74
+ },
75
+ });
76
+
77
+ registerDevServerCommands(context);
78
+ registerWorkbenchCommands(context);
79
+ registerChatParticipant(context);
80
+ registerCliTool(context);
81
+ registerCodeLens(context);
82
+
83
+ log('Extension activated');
84
+ }
85
+
86
+ function registerAuthCommands(context: vscode.ExtensionContext): void {
87
+ context.subscriptions.push(
88
+ vscode.commands.registerCommand('agentuity.login', () => {
89
+ const terminal = vscode.window.createTerminal('Agentuity Login');
90
+ terminal.sendText('agentuity auth login');
91
+ terminal.show();
92
+
93
+ vscode.window
94
+ .showInformationMessage(
95
+ 'Complete login in the terminal, then refresh the extension.',
96
+ 'Refresh'
97
+ )
98
+ .then((action) => {
99
+ if (action === 'Refresh') {
100
+ void checkAuth();
101
+ }
102
+ });
103
+ })
104
+ );
105
+
106
+ context.subscriptions.push(
107
+ vscode.commands.registerCommand('agentuity.logout', async () => {
108
+ const cli = getCliClient();
109
+ const result = await cli.exec(['auth', 'logout']);
110
+
111
+ if (result.success) {
112
+ vscode.window.showInformationMessage('Logged out of Agentuity');
113
+ await checkAuth();
114
+ } else {
115
+ vscode.window.showErrorMessage(`Logout failed: ${result.error}`);
116
+ }
117
+ })
118
+ );
119
+
120
+ context.subscriptions.push(
121
+ vscode.commands.registerCommand('agentuity.whoami', async () => {
122
+ const cli = getCliClient();
123
+ const result = await cli.whoami();
124
+
125
+ if (result.success && result.data) {
126
+ const user = result.data;
127
+ vscode.window.showInformationMessage(
128
+ `Logged in as: ${user.name || user.email} (${user.email})`
129
+ );
130
+ } else {
131
+ vscode.window.showWarningMessage('Not logged in to Agentuity');
132
+ }
133
+ })
134
+ );
135
+ }
136
+
137
+ function registerAiCommands(context: vscode.ExtensionContext): void {
138
+ context.subscriptions.push(
139
+ vscode.commands.registerCommand('agentuity.getAiCapabilities', async () => {
140
+ if (!(await requireAuth())) {
141
+ return undefined;
142
+ }
143
+
144
+ const cli = getCliClient();
145
+ const result = await cli.getAiCapabilities();
146
+
147
+ if (result.success) {
148
+ return result.data;
149
+ } else {
150
+ vscode.window.showErrorMessage(`Failed to get capabilities: ${result.error}`);
151
+ return undefined;
152
+ }
153
+ })
154
+ );
155
+
156
+ context.subscriptions.push(
157
+ vscode.commands.registerCommand('agentuity.getAiSchema', async () => {
158
+ if (!(await requireAuth())) {
159
+ return undefined;
160
+ }
161
+
162
+ const cli = getCliClient();
163
+ const result = await cli.getAiSchema();
164
+
165
+ if (result.success) {
166
+ return result.data;
167
+ } else {
168
+ vscode.window.showErrorMessage(`Failed to get schema: ${result.error}`);
169
+ return undefined;
170
+ }
171
+ })
172
+ );
173
+ }
174
+
175
+ function registerSetupCommands(context: vscode.ExtensionContext): void {
176
+ context.subscriptions.push(
177
+ vscode.commands.registerCommand('agentuity.installCli', () => {
178
+ void vscode.env.openExternal(
179
+ vscode.Uri.parse('https://agentuity.dev/Introduction/getting-started')
180
+ );
181
+ })
182
+ );
183
+
184
+ context.subscriptions.push(
185
+ vscode.commands.registerCommand('agentuity.createProject', () => {
186
+ const terminal = vscode.window.createTerminal('Agentuity');
187
+ terminal.sendText('agentuity project new');
188
+ terminal.show();
189
+ })
190
+ );
191
+ }
192
+
193
+ function registerDeployCommand(context: vscode.ExtensionContext): void {
194
+ context.subscriptions.push(
195
+ vscode.commands.registerCommand('agentuity.deploy', async () => {
196
+ if (!(await requireAuth())) {
197
+ return;
198
+ }
199
+
200
+ const answer = await vscode.window.showWarningMessage(
201
+ 'Deploy to Agentuity Cloud?',
202
+ { modal: true },
203
+ 'Deploy'
204
+ );
205
+
206
+ if (answer !== 'Deploy') {
207
+ return;
208
+ }
209
+
210
+ const terminal = vscode.window.createTerminal('Agentuity Deploy');
211
+ terminal.sendText('agentuity cloud deploy');
212
+ terminal.show();
213
+ })
214
+ );
215
+ }
216
+
217
+ function registerRefreshCommands(
218
+ context: vscode.ExtensionContext,
219
+ providers: {
220
+ agents: ReturnType<typeof registerAgentExplorer>;
221
+ data: ReturnType<typeof registerDataExplorer>;
222
+ deployments: ReturnType<typeof registerDeploymentExplorer>;
223
+ }
224
+ ): void {
225
+ context.subscriptions.push(
226
+ vscode.commands.registerCommand('agentuity.refresh', async () => {
227
+ await checkAuth();
228
+ await detectProject();
229
+ providers.agents.forceRefresh();
230
+ providers.data.refresh();
231
+ providers.deployments.forceRefresh();
232
+ vscode.window.showInformationMessage('Agentuity refreshed');
233
+ })
234
+ );
235
+
236
+ context.subscriptions.push(
237
+ vscode.commands.registerCommand('agentuity.agents.refresh', () => {
238
+ void providers.agents.forceRefresh();
239
+ })
240
+ );
241
+
242
+ context.subscriptions.push(
243
+ vscode.commands.registerCommand('agentuity.deployments.refresh', () => {
244
+ void providers.deployments.forceRefresh();
245
+ })
246
+ );
247
+
248
+ context.subscriptions.push(
249
+ vscode.commands.registerCommand('agentuity.data.refresh', () => {
250
+ providers.data.refresh();
251
+ })
252
+ );
253
+ }
254
+
255
+ export function deactivate(): void {
256
+ disposeCliClient();
257
+ disposeAuth();
258
+ disposeProject();
259
+ outputChannel.dispose();
260
+ }