feat(server): маршрут POST /<stand>/_api/assist + оркестратор пайплайна
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user