feat(server): маршрут POST /<stand>/_api/assist + оркестратор пайплайна

This commit is contained in:
Repinoid
2026-10-07 13:50:56 +03:00
parent c2e2f9cc7c
commit e8b6d9b7a2
2 changed files with 351 additions and 0 deletions
+31
View File
@@ -71,7 +71,38 @@ function proxyRequest(req, res, targetPath) {
upstreamReq.end();
}
// AI-ассистент: лениво грузим, не роняем процесс при ошибках загрузки.
let assistShared = null;
let assistHandler = null;
try {
const orchestrator = require('./orchestrator.js');
assistHandler = orchestrator.handleAssist;
assistShared = orchestrator.createSharedState();
} catch (_) {
assistHandler = null;
assistShared = null;
}
const server = http.createServer((req, res) => {
// POST /<stand>/_api/assist — ветка AI-ассистента (до проверки 405).
if (req.method === 'POST') {
const path = (req.url || '/').split('?')[0];
const match = path.match(/^\/([A-Za-z0-9._-]+)\/_api\/assist$/);
if (match && assistHandler && assistShared) {
const stand = match[1];
assistHandler(req, res, { stand, vmDocsBaseUrl: VM_DOCS_BASE_URL, shared: assistShared })
.catch(() => {
try {
if (!res.headersSent) {
res.writeHead(500, { 'Content-Type': 'application/json; charset=utf-8' });
res.end(JSON.stringify({ error: 'internal_error', message: 'assist failed' }));
}
} catch (_) {}
});
return;
}
}
if (req.method !== 'GET' && req.method !== 'HEAD') {
respond(res, 405, 'Method Not Allowed');
return;