agentstudio 0.1.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 (115) hide show
  1. package/.env +15 -0
  2. package/README.md +85 -0
  3. package/dist/bin/agentstudio.d.ts +3 -0
  4. package/dist/bin/agentstudio.d.ts.map +1 -0
  5. package/dist/bin/agentstudio.js +141 -0
  6. package/dist/bin/agentstudio.js.map +1 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +87 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/middleware/auth.d.ts +7 -0
  12. package/dist/middleware/auth.d.ts.map +1 -0
  13. package/dist/middleware/auth.js +21 -0
  14. package/dist/middleware/auth.js.map +1 -0
  15. package/dist/routes/agents.d.ts +4 -0
  16. package/dist/routes/agents.d.ts.map +1 -0
  17. package/dist/routes/agents.js +804 -0
  18. package/dist/routes/agents.js.map +1 -0
  19. package/dist/routes/auth.d.ts +4 -0
  20. package/dist/routes/auth.d.ts.map +1 -0
  21. package/dist/routes/auth.js +60 -0
  22. package/dist/routes/auth.js.map +1 -0
  23. package/dist/routes/files.d.ts +4 -0
  24. package/dist/routes/files.d.ts.map +1 -0
  25. package/dist/routes/files.js +301 -0
  26. package/dist/routes/files.js.map +1 -0
  27. package/dist/routes/mcp.d.ts +4 -0
  28. package/dist/routes/mcp.d.ts.map +1 -0
  29. package/dist/routes/mcp.js +652 -0
  30. package/dist/routes/mcp.js.map +1 -0
  31. package/dist/routes/media.d.ts +5 -0
  32. package/dist/routes/media.d.ts.map +1 -0
  33. package/dist/routes/media.js +117 -0
  34. package/dist/routes/media.js.map +1 -0
  35. package/dist/routes/slides.d.ts +4 -0
  36. package/dist/routes/slides.d.ts.map +1 -0
  37. package/dist/routes/slides.js +146 -0
  38. package/dist/routes/slides.js.map +1 -0
  39. package/dist/services/claudeSession.d.ts +83 -0
  40. package/dist/services/claudeSession.d.ts.map +1 -0
  41. package/dist/services/claudeSession.js +255 -0
  42. package/dist/services/claudeSession.js.map +1 -0
  43. package/dist/services/messageQueue.d.ts +31 -0
  44. package/dist/services/messageQueue.d.ts.map +1 -0
  45. package/dist/services/messageQueue.js +67 -0
  46. package/dist/services/messageQueue.js.map +1 -0
  47. package/dist/services/sessionManager.d.ts +132 -0
  48. package/dist/services/sessionManager.d.ts.map +1 -0
  49. package/dist/services/sessionManager.js +439 -0
  50. package/dist/services/sessionManager.js.map +1 -0
  51. package/dist/types/claude-history.d.ts +48 -0
  52. package/dist/types/claude-history.d.ts.map +1 -0
  53. package/dist/types/claude-history.js +2 -0
  54. package/dist/types/claude-history.js.map +1 -0
  55. package/dist/types/claude-versions.d.ts +31 -0
  56. package/dist/types/claude-versions.d.ts.map +1 -0
  57. package/dist/types/claude-versions.js +2 -0
  58. package/dist/types/claude-versions.js.map +1 -0
  59. package/dist/types/commands.d.ts +32 -0
  60. package/dist/types/commands.d.ts.map +1 -0
  61. package/dist/types/commands.js +2 -0
  62. package/dist/types/commands.js.map +1 -0
  63. package/dist/types/index.d.ts +81 -0
  64. package/dist/types/index.d.ts.map +1 -0
  65. package/dist/types/index.js +150 -0
  66. package/dist/types/index.js.map +1 -0
  67. package/dist/types/subagents.d.ts +88 -0
  68. package/dist/types/subagents.d.ts.map +1 -0
  69. package/dist/types/subagents.js +2 -0
  70. package/dist/types/subagents.js.map +1 -0
  71. package/dist/utils/agentStorage.d.ts +19 -0
  72. package/dist/utils/agentStorage.d.ts.map +1 -0
  73. package/dist/utils/agentStorage.js +110 -0
  74. package/dist/utils/agentStorage.js.map +1 -0
  75. package/dist/utils/claudeVersionStorage.d.ts +33 -0
  76. package/dist/utils/claudeVersionStorage.d.ts.map +1 -0
  77. package/dist/utils/claudeVersionStorage.js +168 -0
  78. package/dist/utils/claudeVersionStorage.js.map +1 -0
  79. package/dist/utils/jwt.d.ts +15 -0
  80. package/dist/utils/jwt.d.ts.map +1 -0
  81. package/dist/utils/jwt.js +28 -0
  82. package/dist/utils/jwt.js.map +1 -0
  83. package/dist/utils/projectMetadataStorage.d.ts +21 -0
  84. package/dist/utils/projectMetadataStorage.d.ts.map +1 -0
  85. package/dist/utils/projectMetadataStorage.js +68 -0
  86. package/dist/utils/projectMetadataStorage.js.map +1 -0
  87. package/frontend/dist/index.html +86 -0
  88. package/package.json +66 -0
  89. package/src/bin/agentstudio.ts +161 -0
  90. package/src/index.ts +100 -0
  91. package/src/middleware/auth.ts +26 -0
  92. package/src/routes/agents.ts +885 -0
  93. package/src/routes/auth.ts +73 -0
  94. package/src/routes/commands.ts.bak +441 -0
  95. package/src/routes/files.ts +352 -0
  96. package/src/routes/mcp.ts +751 -0
  97. package/src/routes/media.ts +140 -0
  98. package/src/routes/projects.ts.bak +601 -0
  99. package/src/routes/sessions.ts.bak +809 -0
  100. package/src/routes/settings.ts.bak +718 -0
  101. package/src/routes/slides.ts +170 -0
  102. package/src/routes/subagents.ts.bak +364 -0
  103. package/src/services/claudeSession.ts +293 -0
  104. package/src/services/messageQueue.ts +71 -0
  105. package/src/services/sessionManager.ts +532 -0
  106. package/src/types/claude-history.ts +50 -0
  107. package/src/types/claude-versions.ts +33 -0
  108. package/src/types/commands.ts +35 -0
  109. package/src/types/index.ts +248 -0
  110. package/src/types/subagents.ts +106 -0
  111. package/src/utils/agentStorage.ts +126 -0
  112. package/src/utils/claudeVersionStorage.ts +199 -0
  113. package/src/utils/jwt.ts +36 -0
  114. package/src/utils/projectMetadataStorage.ts +86 -0
  115. package/tsconfig.json +26 -0
@@ -0,0 +1,248 @@
1
+ // Agent configuration types
2
+ export interface AgentTool {
3
+ name: string;
4
+ enabled: boolean;
5
+ permissions?: {
6
+ requireConfirmation?: boolean;
7
+ allowedPaths?: string[];
8
+ blockedPaths?: string[];
9
+ };
10
+ }
11
+
12
+ export interface AgentConfig {
13
+ id: string;
14
+ name: string;
15
+ description: string;
16
+ version: string;
17
+
18
+ // AI configuration
19
+ systemPrompt: string;
20
+ maxTurns: number;
21
+ permissionMode: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
22
+ model: string;
23
+
24
+ // Available tools
25
+ allowedTools: AgentTool[];
26
+
27
+ // UI configuration
28
+ ui: {
29
+ icon: string;
30
+ primaryColor: string;
31
+ headerTitle: string;
32
+ headerDescription: string;
33
+ welcomeMessage?: string; // Custom welcome message instead of title + description
34
+ componentType: 'slides' | 'chat' | 'documents' | 'code' | 'custom';
35
+ customComponent?: string; // Path to custom component
36
+ };
37
+
38
+ // File system integration
39
+ workingDirectory?: string;
40
+ dataDirectory?: string;
41
+ fileTypes?: string[]; // Supported file extensions
42
+
43
+ // Metadata
44
+ author: string;
45
+ homepage?: string;
46
+ tags: string[];
47
+ createdAt: string;
48
+ updatedAt: string;
49
+
50
+ // Enable/disable state
51
+ enabled: boolean;
52
+
53
+ // Project associations
54
+ projects?: string[]; // Array of project paths associated with this agent
55
+ }
56
+
57
+ export interface AgentSession {
58
+ id: string;
59
+ agentId: string;
60
+ title: string;
61
+ createdAt: number;
62
+ lastUpdated: number;
63
+ messages: AgentMessage[];
64
+ claudeVersionId?: string; // Claude version ID used for this session
65
+ customData?: Record<string, unknown>;
66
+ }
67
+
68
+ export interface AgentMessage {
69
+ id: string;
70
+ role: 'user' | 'assistant';
71
+ content: string;
72
+ timestamp: number;
73
+ messageParts?: MessagePart[];
74
+ agentId: string;
75
+ }
76
+
77
+ export interface MessagePart {
78
+ id: string;
79
+ type: 'text' | 'tool' | 'command' | 'compactSummary' | 'image';
80
+ content?: string;
81
+ toolData?: {
82
+ id: string;
83
+ toolName: string;
84
+ toolInput: Record<string, unknown>;
85
+ toolResult?: string;
86
+ isExecuting: boolean;
87
+ isError?: boolean;
88
+ claudeId?: string; // Claude's tool use ID for matching with results
89
+ };
90
+ imageData?: {
91
+ id: string;
92
+ data: string;
93
+ mediaType: string;
94
+ filename?: string;
95
+ };
96
+ order: number;
97
+ originalContent?: string; // For commands that need to preserve original content
98
+ }
99
+
100
+ // Built-in agent templates
101
+ export const BUILTIN_AGENTS: Partial<AgentConfig>[] = [
102
+ {
103
+ id: 'ppt-editor',
104
+ name: 'PPT编辑助手',
105
+ description: '专门用于创建和编辑HTML演示文稿的AI助手',
106
+ systemPrompt: `You are an AI assistant specialized in helping users create and edit HTML presentations.
107
+ You can help with:
108
+ - Content creation and editing
109
+ - Design suggestions
110
+ - Structure improvements
111
+ - HTML/CSS modifications
112
+ - Presentation flow optimization
113
+ - File operations for slide management
114
+
115
+ The presentation uses HTML slides with embedded CSS styling. Each slide should be self-contained with a 1280x720 viewport.
116
+ Slides are stored in the ../slides/ directory relative to the backend.
117
+
118
+ Always provide helpful, specific suggestions and when possible, include code examples.
119
+ Please respond in Chinese.`,
120
+ allowedTools: [
121
+ { name: 'Write', enabled: true },
122
+ { name: 'Read', enabled: true },
123
+ { name: 'Edit', enabled: true },
124
+ { name: 'Glob', enabled: true },
125
+ { name: 'MultiEdit', enabled: true },
126
+ { name: 'Bash', enabled: true }
127
+ ],
128
+ ui: {
129
+ icon: '🎯',
130
+ primaryColor: '#3B82F6',
131
+ headerTitle: 'AI PPT助手',
132
+ headerDescription: '与AI聊天来编辑你的演示文稿',
133
+ welcomeMessage: '你好!我是你的AI PPT助手,可以帮你创建、编辑和优化HTML演示文稿。有什么需要帮助的吗?',
134
+ componentType: 'slides'
135
+ },
136
+ workingDirectory: '../slides',
137
+ dataDirectory: '.ai-sessions',
138
+ fileTypes: ['.html', '.css', '.js'],
139
+ tags: ['presentation', 'html', 'css', 'slides'],
140
+ enabled: true
141
+ },
142
+ {
143
+ id: 'code-assistant',
144
+ name: '代码助手',
145
+ description: '通用代码开发和审查助手',
146
+ systemPrompt: `You are a professional software development assistant. You can help with:
147
+ - Code review and optimization
148
+ - Bug fixing and debugging
149
+ - Architecture design
150
+ - Best practices implementation
151
+ - Documentation writing
152
+ - Testing strategies
153
+
154
+ You have access to file system operations and can directly modify code files.
155
+ Always follow coding best practices and maintain clean, readable code.
156
+ Please respond in Chinese.`,
157
+ allowedTools: [
158
+ { name: 'Write', enabled: true },
159
+ { name: 'Read', enabled: true },
160
+ { name: 'Edit', enabled: true },
161
+ { name: 'Glob', enabled: true },
162
+ { name: 'MultiEdit', enabled: true },
163
+ { name: 'Bash', enabled: true },
164
+ { name: 'Task', enabled: true }
165
+ ],
166
+ ui: {
167
+ icon: '💻',
168
+ primaryColor: '#10B981',
169
+ headerTitle: '代码助手',
170
+ headerDescription: '专业的软件开发和代码审查助手',
171
+ welcomeMessage: '你好!我是专业的代码助手,可以帮你进行代码开发、审查、调试和优化。请告诉我你想要解决的编程问题!',
172
+ componentType: 'code'
173
+ },
174
+ tags: ['coding', 'development', 'review', 'debugging'],
175
+ enabled: false
176
+ },
177
+ {
178
+ id: 'document-writer',
179
+ name: '文档助手',
180
+ description: '专注于文档创建和编辑的助手',
181
+ systemPrompt: `You are a professional document writing assistant. You can help with:
182
+ - Creating and editing documentation
183
+ - Technical writing
184
+ - Content structuring
185
+ - Markdown formatting
186
+ - Research and information gathering
187
+ - Proofreading and editing
188
+
189
+ You work primarily with text files and markdown documents.
190
+ Focus on clarity, accuracy, and professional presentation.
191
+ Please respond in Chinese.`,
192
+ allowedTools: [
193
+ { name: 'Write', enabled: true },
194
+ { name: 'Read', enabled: true },
195
+ { name: 'Edit', enabled: true },
196
+ { name: 'Glob', enabled: true },
197
+ { name: 'WebFetch', enabled: true },
198
+ { name: 'WebSearch', enabled: true }
199
+ ],
200
+ ui: {
201
+ icon: '📝',
202
+ primaryColor: '#8B5CF6',
203
+ headerTitle: '文档助手',
204
+ headerDescription: '专业的文档创建和编辑助手',
205
+ welcomeMessage: '你好!我是文档助手,专门帮助你创建、编辑和优化各种文档。无论是技术文档还是普通文档,我都能为你提供专业建议!',
206
+ componentType: 'documents'
207
+ },
208
+ fileTypes: ['.md', '.txt', '.rst', '.adoc'],
209
+ tags: ['documentation', 'writing', 'markdown', 'content'],
210
+ enabled: true
211
+ },
212
+ {
213
+ id: 'general-chat',
214
+ name: '通用聊天助手',
215
+ description: '通用的AI聊天助手,适用于各种对话和咨询',
216
+ systemPrompt: `You are a general-purpose AI assistant. You can help with:
217
+ - General questions and conversations
218
+ - Problem-solving and brainstorming
219
+ - Information and explanations
220
+ - Creative tasks and writing
221
+ - Analysis and research
222
+ - File operations when needed
223
+
224
+ You are helpful, harmless, and honest. Always strive to provide accurate and useful information.
225
+ Please respond in Chinese unless the user specifically requests another language.`,
226
+ allowedTools: [
227
+ { name: 'Write', enabled: true },
228
+ { name: 'Read', enabled: true },
229
+ { name: 'Edit', enabled: true },
230
+ { name: 'Glob', enabled: true },
231
+ { name: 'MultiEdit', enabled: true },
232
+ { name: 'Bash', enabled: true },
233
+ { name: 'Task', enabled: true },
234
+ { name: 'WebFetch', enabled: true },
235
+ { name: 'WebSearch', enabled: true }
236
+ ],
237
+ ui: {
238
+ icon: '💬',
239
+ primaryColor: '#6366F1',
240
+ headerTitle: '通用聊天',
241
+ headerDescription: '与AI进行自由对话和咨询',
242
+ welcomeMessage: '你好!我是通用AI助手,可以帮你解答问题、进行对话、处理各种任务。有什么我可以帮助你的吗?',
243
+ componentType: 'chat'
244
+ },
245
+ tags: ['general', 'chat', 'conversation', 'assistant'],
246
+ enabled: true
247
+ }
248
+ ];
@@ -0,0 +1,106 @@
1
+ // Subagent configuration types
2
+ export interface SubagentTool {
3
+ name: string;
4
+ enabled: boolean;
5
+ permissions?: {
6
+ requireConfirmation?: boolean;
7
+ allowedPaths?: string[];
8
+ blockedPaths?: string[];
9
+ };
10
+ }
11
+
12
+ export interface Subagent {
13
+ id: string;
14
+ name: string;
15
+ description: string;
16
+ version: string;
17
+
18
+ // AI configuration
19
+ systemPrompt: string;
20
+ maxTurns: number;
21
+ permissionMode: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
22
+ model: string;
23
+
24
+ // Available tools
25
+ allowedTools: SubagentTool[];
26
+
27
+ // UI configuration
28
+ ui: {
29
+ icon: string;
30
+ primaryColor: string;
31
+ headerTitle: string;
32
+ headerDescription: string;
33
+ welcomeMessage?: string;
34
+ componentType: 'slides' | 'chat' | 'documents' | 'code' | 'custom';
35
+ customComponent?: string;
36
+ };
37
+
38
+ // File system integration
39
+ workingDirectory?: string;
40
+ dataDirectory?: string;
41
+ fileTypes?: string[];
42
+
43
+ // Metadata
44
+ author: string;
45
+ homepage?: string;
46
+ tags: string[];
47
+ createdAt: string;
48
+ updatedAt: string;
49
+
50
+ // Enable/disable state
51
+ enabled: boolean;
52
+
53
+ // Project associations
54
+ projects?: string[];
55
+ }
56
+
57
+ export interface SubagentCreate {
58
+ name: string;
59
+ description: string;
60
+ systemPrompt: string;
61
+ model: string;
62
+ allowedTools: SubagentTool[];
63
+ ui: {
64
+ icon: string;
65
+ primaryColor: string;
66
+ headerTitle: string;
67
+ headerDescription: string;
68
+ welcomeMessage?: string;
69
+ componentType: 'slides' | 'chat' | 'documents' | 'code' | 'custom';
70
+ customComponent?: string;
71
+ };
72
+ workingDirectory?: string;
73
+ dataDirectory?: string;
74
+ fileTypes?: string[];
75
+ author: string;
76
+ tags: string[];
77
+ }
78
+
79
+ export interface SubagentUpdate {
80
+ name?: string;
81
+ description?: string;
82
+ systemPrompt?: string;
83
+ model?: string;
84
+ allowedTools?: SubagentTool[];
85
+ ui?: {
86
+ icon?: string;
87
+ primaryColor?: string;
88
+ headerTitle?: string;
89
+ headerDescription?: string;
90
+ welcomeMessage?: string;
91
+ componentType?: 'slides' | 'chat' | 'documents' | 'code' | 'custom';
92
+ customComponent?: string;
93
+ };
94
+ workingDirectory?: string;
95
+ dataDirectory?: string;
96
+ fileTypes?: string[];
97
+ author?: string;
98
+ tags?: string[];
99
+ enabled?: boolean;
100
+ }
101
+
102
+ export interface SubagentFilter {
103
+ search?: string;
104
+ tags?: string[];
105
+ enabled?: boolean;
106
+ }
@@ -0,0 +1,126 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { AgentConfig } from '../types/index.js';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ export class AgentStorage {
10
+ private dataDir: string;
11
+
12
+ constructor(dataDir?: string) {
13
+ this.dataDir = dataDir || path.join(__dirname, '../../data/agents');
14
+ }
15
+
16
+ private getAgentPath(agentId: string): string {
17
+ return path.join(this.dataDir, `${agentId}.json`);
18
+ }
19
+
20
+ async saveAgent(agent: AgentConfig): Promise<void> {
21
+ await fs.ensureDir(this.dataDir);
22
+ const agentPath = this.getAgentPath(agent.id);
23
+ await fs.writeJson(agentPath, agent, { spaces: 2 });
24
+ }
25
+
26
+ async loadAgent(agentId: string): Promise<AgentConfig | null> {
27
+ const agentPath = this.getAgentPath(agentId);
28
+ try {
29
+ if (await fs.pathExists(agentPath)) {
30
+ return await fs.readJson(agentPath);
31
+ }
32
+ } catch (error) {
33
+ console.error(`Error loading agent ${agentId}:`, error);
34
+ }
35
+ return null;
36
+ }
37
+
38
+ async deleteAgent(agentId: string): Promise<void> {
39
+ const agentPath = this.getAgentPath(agentId);
40
+ try {
41
+ if (await fs.pathExists(agentPath)) {
42
+ await fs.remove(agentPath);
43
+ }
44
+ } catch (error) {
45
+ console.error(`Error deleting agent ${agentId}:`, error);
46
+ throw error;
47
+ }
48
+ }
49
+
50
+ async listAgents(): Promise<AgentConfig[]> {
51
+ await fs.ensureDir(this.dataDir);
52
+ const files = await fs.readdir(this.dataDir);
53
+ const agents: AgentConfig[] = [];
54
+
55
+ for (const file of files) {
56
+ if (file.endsWith('.json')) {
57
+ const agentId = path.basename(file, '.json');
58
+ try {
59
+ const agent = await this.loadAgent(agentId);
60
+ if (agent) {
61
+ agents.push(agent);
62
+ }
63
+ } catch (error) {
64
+ console.error(`Error loading agent from file ${file}:`, error);
65
+ }
66
+ }
67
+ }
68
+
69
+ return agents;
70
+ }
71
+
72
+ async agentExists(agentId: string): Promise<boolean> {
73
+ const agentPath = this.getAgentPath(agentId);
74
+ return await fs.pathExists(agentPath);
75
+ }
76
+
77
+ // Alias for listAgents to match route usage
78
+ getAllAgents(): Promise<AgentConfig[]> {
79
+ return this.listAgents();
80
+ }
81
+
82
+ // Alias for loadAgent to match route usage
83
+ getAgent(agentId: string): Promise<AgentConfig | null> {
84
+ return this.loadAgent(agentId);
85
+ }
86
+
87
+ // Create agent method
88
+ async createAgent(agentData: Omit<AgentConfig, 'createdAt' | 'updatedAt'>): Promise<AgentConfig> {
89
+ const now = new Date().toISOString();
90
+ const agent: AgentConfig = {
91
+ ...agentData,
92
+ createdAt: now,
93
+ updatedAt: now
94
+ };
95
+
96
+ await this.saveAgent(agent);
97
+ return agent;
98
+ }
99
+
100
+ // Session-related methods (stubs for now)
101
+ getAgentSessions(agentId: string, search?: string): Promise<any[]> {
102
+ // This would need session storage implementation
103
+ return Promise.resolve([]);
104
+ }
105
+
106
+ getSession(agentId: string, sessionId: string): Promise<any | null> {
107
+ // This would need session storage implementation
108
+ return Promise.resolve(null);
109
+ }
110
+
111
+ createSession(agentId: string, title: string): Promise<any> {
112
+ // This would need session storage implementation
113
+ const session = {
114
+ id: `session-${Date.now()}`,
115
+ title,
116
+ createdAt: new Date().toISOString(),
117
+ updatedAt: new Date().toISOString()
118
+ };
119
+ return Promise.resolve(session);
120
+ }
121
+
122
+ deleteSession(agentId: string, sessionId: string): Promise<boolean> {
123
+ // This would need session storage implementation
124
+ return Promise.resolve(true);
125
+ }
126
+ }
@@ -0,0 +1,199 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ export interface ClaudeVersion {
9
+ id: string;
10
+ name: string;
11
+ model: string;
12
+ description: string;
13
+ isDefault: boolean;
14
+ executablePath: string;
15
+ environmentVariables: Record<string, string>;
16
+ alias?: string;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ }
20
+
21
+ export class ClaudeVersionStorage {
22
+ private dataDir: string;
23
+
24
+ constructor(dataDir?: string) {
25
+ this.dataDir = dataDir || path.join(__dirname, '../../data/claude-versions');
26
+ }
27
+
28
+ private getVersionsPath(): string {
29
+ return path.join(this.dataDir, 'versions.json');
30
+ }
31
+
32
+ async saveVersions(versions: ClaudeVersion[]): Promise<void> {
33
+ await fs.ensureDir(this.dataDir);
34
+ const versionsPath = this.getVersionsPath();
35
+ await fs.writeJson(versionsPath, versions, { spaces: 2 });
36
+ }
37
+
38
+ async loadVersions(): Promise<ClaudeVersion[]> {
39
+ const versionsPath = this.getVersionsPath();
40
+ try {
41
+ if (await fs.pathExists(versionsPath)) {
42
+ return await fs.readJson(versionsPath);
43
+ }
44
+ } catch (error) {
45
+ console.error('Error loading Claude versions:', error);
46
+ }
47
+
48
+ // Return default versions if file doesn't exist
49
+ const now = new Date().toISOString();
50
+ return [
51
+ {
52
+ id: 'claude-3-5-sonnet-20241022',
53
+ name: 'Claude 3.5 Sonnet',
54
+ model: 'claude-3-5-sonnet-20241022',
55
+ description: 'Latest Claude 3.5 Sonnet model',
56
+ isDefault: true,
57
+ executablePath: '',
58
+ environmentVariables: {},
59
+ alias: 'claude-3-5-sonnet',
60
+ createdAt: now,
61
+ updatedAt: now
62
+ },
63
+ {
64
+ id: 'claude-3-opus-20240229',
65
+ name: 'Claude 3 Opus',
66
+ model: 'claude-3-opus-20240229',
67
+ description: 'Claude 3 Opus model',
68
+ isDefault: false,
69
+ executablePath: '',
70
+ environmentVariables: {},
71
+ alias: 'claude-3-opus',
72
+ createdAt: now,
73
+ updatedAt: now
74
+ },
75
+ {
76
+ id: 'claude-3-sonnet-20240229',
77
+ name: 'Claude 3 Sonnet',
78
+ model: 'claude-3-sonnet-20240229',
79
+ description: 'Claude 3 Sonnet model',
80
+ isDefault: false,
81
+ executablePath: '',
82
+ environmentVariables: {},
83
+ alias: 'claude-3-sonnet',
84
+ createdAt: now,
85
+ updatedAt: now
86
+ }
87
+ ];
88
+ }
89
+
90
+ async getDefaultVersionId(): Promise<string> {
91
+ const versions = await this.loadVersions();
92
+ const defaultVersion = versions.find(v => v.isDefault);
93
+ return defaultVersion?.id || versions[0]?.id || 'claude-3-5-sonnet-20241022';
94
+ }
95
+
96
+ async setDefaultVersion(versionId: string): Promise<void> {
97
+ const versions = await this.loadVersions();
98
+ const updatedVersions = versions.map(v => ({
99
+ ...v,
100
+ isDefault: v.id === versionId
101
+ }));
102
+ await this.saveVersions(updatedVersions);
103
+ }
104
+
105
+ async createVersion(version: Omit<ClaudeVersion, 'id' | 'createdAt' | 'updatedAt'>): Promise<ClaudeVersion> {
106
+ const versions = await this.loadVersions();
107
+ const now = new Date().toISOString();
108
+ const newVersion: ClaudeVersion = {
109
+ ...version,
110
+ id: `custom-${Date.now()}`,
111
+ createdAt: now,
112
+ updatedAt: now
113
+ };
114
+ versions.push(newVersion);
115
+ await this.saveVersions(versions);
116
+ return newVersion;
117
+ }
118
+
119
+ async updateVersion(versionId: string, updates: Partial<ClaudeVersion>): Promise<ClaudeVersion | null> {
120
+ const versions = await this.loadVersions();
121
+ const versionIndex = versions.findIndex(v => v.id === versionId);
122
+ if (versionIndex === -1) return null;
123
+
124
+ versions[versionIndex] = {
125
+ ...versions[versionIndex],
126
+ ...updates,
127
+ updatedAt: new Date().toISOString()
128
+ };
129
+ await this.saveVersions(versions);
130
+ return versions[versionIndex];
131
+ }
132
+
133
+ async deleteVersion(versionId: string): Promise<boolean> {
134
+ const versions = await this.loadVersions();
135
+ const filteredVersions = versions.filter(v => v.id !== versionId);
136
+ if (filteredVersions.length === versions.length) return false;
137
+
138
+ await this.saveVersions(filteredVersions);
139
+ return true;
140
+ }
141
+
142
+ async initializeSystemVersion(): Promise<void> {
143
+ const versions = await this.loadVersions();
144
+ // Ensure at least one version exists
145
+ if (versions.length === 0) {
146
+ const now = new Date().toISOString();
147
+ await this.saveVersions([
148
+ {
149
+ id: 'claude-3-5-sonnet-20241022',
150
+ name: 'Claude 3.5 Sonnet',
151
+ model: 'claude-3-5-sonnet-20241022',
152
+ description: 'Latest Claude 3.5 Sonnet model',
153
+ isDefault: true,
154
+ executablePath: '',
155
+ environmentVariables: {},
156
+ alias: 'claude-3-5-sonnet',
157
+ createdAt: now,
158
+ updatedAt: now
159
+ }
160
+ ]);
161
+ }
162
+ }
163
+ }
164
+
165
+ // Export singleton functions for backward compatibility
166
+ export const getAllVersions = async (): Promise<ClaudeVersion[]> => {
167
+ const storage = new ClaudeVersionStorage();
168
+ return storage.loadVersions();
169
+ };
170
+
171
+ export const getDefaultVersionId = async (): Promise<string> => {
172
+ const storage = new ClaudeVersionStorage();
173
+ return storage.getDefaultVersionId();
174
+ };
175
+
176
+ export const setDefaultVersion = async (versionId: string): Promise<void> => {
177
+ const storage = new ClaudeVersionStorage();
178
+ return storage.setDefaultVersion(versionId);
179
+ };
180
+
181
+ export const createVersion = async (version: Omit<ClaudeVersion, 'id' | 'createdAt' | 'updatedAt'>): Promise<ClaudeVersion> => {
182
+ const storage = new ClaudeVersionStorage();
183
+ return storage.createVersion(version);
184
+ };
185
+
186
+ export const updateVersion = async (versionId: string, updates: Partial<ClaudeVersion>): Promise<ClaudeVersion | null> => {
187
+ const storage = new ClaudeVersionStorage();
188
+ return storage.updateVersion(versionId, updates);
189
+ };
190
+
191
+ export const deleteVersion = async (versionId: string): Promise<boolean> => {
192
+ const storage = new ClaudeVersionStorage();
193
+ return storage.deleteVersion(versionId);
194
+ };
195
+
196
+ export const initializeSystemVersion = async (): Promise<void> => {
197
+ const storage = new ClaudeVersionStorage();
198
+ return storage.initializeSystemVersion();
199
+ };