-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.ts
More file actions
123 lines (104 loc) · 4.59 KB
/
extension.ts
File metadata and controls
123 lines (104 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as vscode from 'vscode';
import { AgentRunsProvider } from './providers/AgentRunsProvider';
import { HomeViewProvider } from './providers/HomeViewProvider';
import { AuthManager } from './auth/AuthManager';
import { ApiClient } from './api/ApiClient';
export function activate(context: vscode.ExtensionContext) {
console.log('Codegen IDE extension is now active!');
// Initialize auth manager
const authManager = new AuthManager(context);
// Initialize API client
const apiClient = new ApiClient(authManager);
// Initialize providers
const agentRunsProvider = new AgentRunsProvider(apiClient, authManager);
const homeViewProvider = new HomeViewProvider(context.extensionUri, apiClient, authManager);
// Register tree data provider
vscode.window.createTreeView('codegenAgentRuns', {
treeDataProvider: agentRunsProvider,
showCollapseAll: true
});
// Register webview provider
context.subscriptions.push(
vscode.window.registerWebviewViewProvider('codegenHome', homeViewProvider)
);
// Set authentication context
vscode.commands.executeCommand('setContext', 'codegen.authenticated', authManager.isAuthenticated());
// Register commands
const commands = [
vscode.commands.registerCommand('codegen.login', async () => {
await authManager.login();
vscode.commands.executeCommand('setContext', 'codegen.authenticated', authManager.isAuthenticated());
agentRunsProvider.refresh();
homeViewProvider.refresh();
}),
vscode.commands.registerCommand('codegen.logout', async () => {
await authManager.logout();
vscode.commands.executeCommand('setContext', 'codegen.authenticated', authManager.isAuthenticated());
agentRunsProvider.refresh();
homeViewProvider.refresh();
}),
vscode.commands.registerCommand('codegen.showAgentRuns', () => {
vscode.commands.executeCommand('workbench.view.extension.codegen');
}),
vscode.commands.registerCommand('codegen.createAgent', async () => {
if (!authManager.isAuthenticated()) {
const result = await vscode.window.showInformationMessage(
'You need to login to create agents',
'Login'
);
if (result === 'Login') {
await vscode.commands.executeCommand('codegen.login');
}
return;
}
const prompt = await vscode.window.showInputBox({
prompt: 'Enter your agent prompt',
placeHolder: 'e.g., Fix the bug in the login component',
ignoreFocusOut: true
});
if (prompt) {
try {
const agentRun = await apiClient.createAgentRun(prompt);
vscode.window.showInformationMessage(
`Agent run created successfully! ID: ${agentRun.id}`,
'View in Browser'
).then(selection => {
if (selection === 'View in Browser' && agentRun.web_url) {
vscode.env.openExternal(vscode.Uri.parse(agentRun.web_url));
}
});
agentRunsProvider.refresh();
homeViewProvider.refresh();
} catch (error) {
vscode.window.showErrorMessage(`Failed to create agent: ${error}`);
}
}
}),
vscode.commands.registerCommand('codegen.refreshAgentRuns', () => {
agentRunsProvider.refresh();
}),
vscode.commands.registerCommand('codegen.openAgentRun', (agentRun) => {
if (agentRun.web_url) {
vscode.env.openExternal(vscode.Uri.parse(agentRun.web_url));
}
})
];
// Add all commands to subscriptions
commands.forEach(command => context.subscriptions.push(command));
// Auto-refresh setup
const config = vscode.workspace.getConfiguration('codegen');
if (config.get('autoRefresh', true)) {
const interval = config.get('refreshInterval', 30) * 1000;
const refreshTimer = setInterval(() => {
if (authManager.isAuthenticated()) {
agentRunsProvider.refresh();
}
}, interval);
context.subscriptions.push({
dispose: () => clearInterval(refreshTimer)
});
}
}
export function deactivate() {
console.log('Codegen IDE extension is now deactivated');
}