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.
- package/.env +15 -0
- package/README.md +85 -0
- package/dist/bin/agentstudio.d.ts +3 -0
- package/dist/bin/agentstudio.d.ts.map +1 -0
- package/dist/bin/agentstudio.js +141 -0
- package/dist/bin/agentstudio.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/auth.d.ts +7 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +21 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/routes/agents.d.ts +4 -0
- package/dist/routes/agents.d.ts.map +1 -0
- package/dist/routes/agents.js +804 -0
- package/dist/routes/agents.js.map +1 -0
- package/dist/routes/auth.d.ts +4 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +60 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/files.d.ts +4 -0
- package/dist/routes/files.d.ts.map +1 -0
- package/dist/routes/files.js +301 -0
- package/dist/routes/files.js.map +1 -0
- package/dist/routes/mcp.d.ts +4 -0
- package/dist/routes/mcp.d.ts.map +1 -0
- package/dist/routes/mcp.js +652 -0
- package/dist/routes/mcp.js.map +1 -0
- package/dist/routes/media.d.ts +5 -0
- package/dist/routes/media.d.ts.map +1 -0
- package/dist/routes/media.js +117 -0
- package/dist/routes/media.js.map +1 -0
- package/dist/routes/slides.d.ts +4 -0
- package/dist/routes/slides.d.ts.map +1 -0
- package/dist/routes/slides.js +146 -0
- package/dist/routes/slides.js.map +1 -0
- package/dist/services/claudeSession.d.ts +83 -0
- package/dist/services/claudeSession.d.ts.map +1 -0
- package/dist/services/claudeSession.js +255 -0
- package/dist/services/claudeSession.js.map +1 -0
- package/dist/services/messageQueue.d.ts +31 -0
- package/dist/services/messageQueue.d.ts.map +1 -0
- package/dist/services/messageQueue.js +67 -0
- package/dist/services/messageQueue.js.map +1 -0
- package/dist/services/sessionManager.d.ts +132 -0
- package/dist/services/sessionManager.d.ts.map +1 -0
- package/dist/services/sessionManager.js +439 -0
- package/dist/services/sessionManager.js.map +1 -0
- package/dist/types/claude-history.d.ts +48 -0
- package/dist/types/claude-history.d.ts.map +1 -0
- package/dist/types/claude-history.js +2 -0
- package/dist/types/claude-history.js.map +1 -0
- package/dist/types/claude-versions.d.ts +31 -0
- package/dist/types/claude-versions.d.ts.map +1 -0
- package/dist/types/claude-versions.js +2 -0
- package/dist/types/claude-versions.js.map +1 -0
- package/dist/types/commands.d.ts +32 -0
- package/dist/types/commands.d.ts.map +1 -0
- package/dist/types/commands.js +2 -0
- package/dist/types/commands.js.map +1 -0
- package/dist/types/index.d.ts +81 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +150 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/subagents.d.ts +88 -0
- package/dist/types/subagents.d.ts.map +1 -0
- package/dist/types/subagents.js +2 -0
- package/dist/types/subagents.js.map +1 -0
- package/dist/utils/agentStorage.d.ts +19 -0
- package/dist/utils/agentStorage.d.ts.map +1 -0
- package/dist/utils/agentStorage.js +110 -0
- package/dist/utils/agentStorage.js.map +1 -0
- package/dist/utils/claudeVersionStorage.d.ts +33 -0
- package/dist/utils/claudeVersionStorage.d.ts.map +1 -0
- package/dist/utils/claudeVersionStorage.js +168 -0
- package/dist/utils/claudeVersionStorage.js.map +1 -0
- package/dist/utils/jwt.d.ts +15 -0
- package/dist/utils/jwt.d.ts.map +1 -0
- package/dist/utils/jwt.js +28 -0
- package/dist/utils/jwt.js.map +1 -0
- package/dist/utils/projectMetadataStorage.d.ts +21 -0
- package/dist/utils/projectMetadataStorage.d.ts.map +1 -0
- package/dist/utils/projectMetadataStorage.js +68 -0
- package/dist/utils/projectMetadataStorage.js.map +1 -0
- package/frontend/dist/index.html +86 -0
- package/package.json +66 -0
- package/src/bin/agentstudio.ts +161 -0
- package/src/index.ts +100 -0
- package/src/middleware/auth.ts +26 -0
- package/src/routes/agents.ts +885 -0
- package/src/routes/auth.ts +73 -0
- package/src/routes/commands.ts.bak +441 -0
- package/src/routes/files.ts +352 -0
- package/src/routes/mcp.ts +751 -0
- package/src/routes/media.ts +140 -0
- package/src/routes/projects.ts.bak +601 -0
- package/src/routes/sessions.ts.bak +809 -0
- package/src/routes/settings.ts.bak +718 -0
- package/src/routes/slides.ts +170 -0
- package/src/routes/subagents.ts.bak +364 -0
- package/src/services/claudeSession.ts +293 -0
- package/src/services/messageQueue.ts +71 -0
- package/src/services/sessionManager.ts +532 -0
- package/src/types/claude-history.ts +50 -0
- package/src/types/claude-versions.ts +33 -0
- package/src/types/commands.ts +35 -0
- package/src/types/index.ts +248 -0
- package/src/types/subagents.ts +106 -0
- package/src/utils/agentStorage.ts +126 -0
- package/src/utils/claudeVersionStorage.ts +199 -0
- package/src/utils/jwt.ts +36 -0
- package/src/utils/projectMetadataStorage.ts +86 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import express, { Router } from 'express';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { join, resolve, relative, extname, dirname } from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import crypto from 'crypto';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
const router: Router = express.Router();
|
|
12
|
+
|
|
13
|
+
// Project ID to path mapping (in production, this should be stored in a database)
|
|
14
|
+
const projectMappings = new Map<string, string>();
|
|
15
|
+
|
|
16
|
+
// Helper function to generate project ID from path
|
|
17
|
+
const generateProjectId = (projectPath: string): string => {
|
|
18
|
+
return crypto.createHash('md5').update(projectPath).digest('hex').substring(0, 16);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Helper function to get or create project ID
|
|
22
|
+
export const getProjectId = (projectPath: string): string => {
|
|
23
|
+
const normalizedPath = resolve(projectPath);
|
|
24
|
+
|
|
25
|
+
// Check if we already have an ID for this path
|
|
26
|
+
for (const [id, path] of projectMappings.entries()) {
|
|
27
|
+
if (path === normalizedPath) {
|
|
28
|
+
return id;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Generate new ID and store mapping
|
|
33
|
+
const projectId = generateProjectId(normalizedPath);
|
|
34
|
+
projectMappings.set(projectId, normalizedPath);
|
|
35
|
+
return projectId;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Helper function to get project path from ID
|
|
39
|
+
const getProjectPath = (projectId: string): string | null => {
|
|
40
|
+
return projectMappings.get(projectId) || null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Helper function to resolve and validate file path within project
|
|
44
|
+
const resolveSafeMediaPath = (projectPath: string, relativePath: string): string => {
|
|
45
|
+
const resolvedProjectPath = resolve(projectPath);
|
|
46
|
+
const resolvedFilePath = resolve(resolvedProjectPath, relativePath);
|
|
47
|
+
|
|
48
|
+
// Ensure the path is within the project directory for security
|
|
49
|
+
const relativeToProject = relative(resolvedProjectPath, resolvedFilePath);
|
|
50
|
+
if (relativeToProject.startsWith('..') || resolve(resolvedProjectPath, relativeToProject) !== resolvedFilePath) {
|
|
51
|
+
throw new Error('Path is outside project directory');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return resolvedFilePath;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Helper function to get MIME type from file extension
|
|
58
|
+
const getMimeType = (filePath: string): string => {
|
|
59
|
+
const ext = extname(filePath).toLowerCase();
|
|
60
|
+
const mimeTypes: Record<string, string> = {
|
|
61
|
+
'.html': 'text/html',
|
|
62
|
+
'.htm': 'text/html',
|
|
63
|
+
'.css': 'text/css',
|
|
64
|
+
'.js': 'text/javascript',
|
|
65
|
+
'.json': 'application/json',
|
|
66
|
+
'.png': 'image/png',
|
|
67
|
+
'.jpg': 'image/jpeg',
|
|
68
|
+
'.jpeg': 'image/jpeg',
|
|
69
|
+
'.gif': 'image/gif',
|
|
70
|
+
'.svg': 'image/svg+xml',
|
|
71
|
+
'.webp': 'image/webp',
|
|
72
|
+
'.ico': 'image/x-icon',
|
|
73
|
+
'.pdf': 'application/pdf',
|
|
74
|
+
'.txt': 'text/plain',
|
|
75
|
+
'.md': 'text/markdown',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return mimeTypes[ext] || 'application/octet-stream';
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// GET /media/{project-id}/{relative-path} - Serve static files from project directory
|
|
82
|
+
router.get('/:projectId/*', async (req, res) => {
|
|
83
|
+
try {
|
|
84
|
+
const { projectId } = req.params;
|
|
85
|
+
const relativePath = (req.params as any)[0]; // Everything after projectId
|
|
86
|
+
|
|
87
|
+
if (!relativePath) {
|
|
88
|
+
return res.status(400).json({ error: 'File path is required' });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Get project path from ID
|
|
92
|
+
const projectPath = getProjectPath(projectId);
|
|
93
|
+
if (!projectPath) {
|
|
94
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Resolve safe file path
|
|
98
|
+
const filePath = resolveSafeMediaPath(projectPath, relativePath);
|
|
99
|
+
|
|
100
|
+
// Check if file exists
|
|
101
|
+
if (!existsSync(filePath)) {
|
|
102
|
+
return res.status(404).json({ error: 'File not found' });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Check if it's a file (not directory)
|
|
106
|
+
const stats = await fs.stat(filePath);
|
|
107
|
+
if (!stats.isFile()) {
|
|
108
|
+
return res.status(400).json({ error: 'Path is not a file' });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Set appropriate Content-Type
|
|
112
|
+
const mimeType = getMimeType(filePath);
|
|
113
|
+
res.setHeader('Content-Type', mimeType);
|
|
114
|
+
|
|
115
|
+
// Set cache headers for static assets
|
|
116
|
+
if (mimeType.startsWith('image/') || mimeType === 'text/css' || mimeType === 'text/javascript') {
|
|
117
|
+
res.setHeader('Cache-Control', 'public, max-age=3600'); // 1 hour cache
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Stream the file
|
|
121
|
+
const fileStream = fs.createReadStream(filePath);
|
|
122
|
+
fileStream.pipe(res);
|
|
123
|
+
|
|
124
|
+
fileStream.on('error', (error) => {
|
|
125
|
+
console.error('Error streaming file:', error);
|
|
126
|
+
if (!res.headersSent) {
|
|
127
|
+
res.status(500).json({ error: 'Failed to read file' });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Error serving media file:', error);
|
|
133
|
+
if (error instanceof Error && error.message === 'Path is outside project directory') {
|
|
134
|
+
return res.status(403).json({ error: 'Access denied' });
|
|
135
|
+
}
|
|
136
|
+
res.status(500).json({ error: 'Failed to serve file' });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export default router;
|