mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-18 14:27:20 +00:00
- Create FLOWS.md with complete inventory of all 16 flows in codebase - Mark 5 complete, 7 partial, and 4 not started flows - Add [UNFINISHED FLOW] TODO markers to affected files: - wine-launcher.sh: VM launcher not implemented - execute.ts: Non-JS/TS language support missing - app-registry.ts: Stub implementation only - OAUTH_IMPLEMENTATION.md: Unlink endpoint needed - DEPLOYMENT_STATUS.md: Railway deployment pending - Add FLOWS.md reference to PROJECT_RUNDOWN.md
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import type { VercelRequest, VercelResponse } from '@vercel/node';
|
|
|
|
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|
if (req.method !== 'POST') {
|
|
res.status(405).json({ error: 'Method not allowed' });
|
|
return;
|
|
}
|
|
|
|
const { code, language } = req.body;
|
|
|
|
if (!code) {
|
|
res.status(400).json({ error: 'Code is required' });
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Simple JavaScript execution (TypeScript gets transpiled to JS)
|
|
if (language === 'typescript' || language === 'javascript') {
|
|
// Create a safe execution context
|
|
const result = await executeJavaScript(code);
|
|
res.status(200).json({ output: result, status: 'success' });
|
|
return;
|
|
}
|
|
|
|
// TODO: [UNFINISHED FLOW] Add support for additional languages
|
|
// Priority languages to implement:
|
|
// - Python (via pyodide or server-side execution)
|
|
// - Go (via server-side compilation)
|
|
// - Rust (via server-side compilation)
|
|
// See: FLOWS.md section "Code Execution API"
|
|
res.status(200).json({
|
|
output: `// Language: ${language}\n// Execution not yet supported in cloud environment\n// Run locally for full support`,
|
|
status: 'info'
|
|
});
|
|
} catch (error: any) {
|
|
res.status(200).json({
|
|
output: error.message || 'Execution error',
|
|
status: 'error'
|
|
});
|
|
}
|
|
}
|
|
|
|
async function executeJavaScript(code: string): Promise<string> {
|
|
const output: string[] = [];
|
|
const originalLog = console.log;
|
|
|
|
try {
|
|
// Capture console output
|
|
console.log = (...args: any[]) => {
|
|
output.push(args.map(arg => String(arg)).join(' '));
|
|
originalLog(...args);
|
|
};
|
|
|
|
// Execute the code in an isolated scope
|
|
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
|
const fn = new AsyncFunction(code);
|
|
const result = await fn();
|
|
|
|
if (result !== undefined) {
|
|
output.push(String(result));
|
|
}
|
|
|
|
return output.length > 0 ? output.join('\n') : '(no output)';
|
|
} catch (error: any) {
|
|
throw new Error(`${error.name}: ${error.message}`);
|
|
} finally {
|
|
console.log = originalLog;
|
|
}
|
|
}
|