feat(coding): add core host api composition

This commit is contained in:
2026-08-23 20:00:35 +08:00
parent 98bac20639
commit 22b4a9f9c4
23 changed files with 2258 additions and 59 deletions

View File

@@ -0,0 +1,42 @@
import type { ServerResponse } from 'node:http';
import { CodingProjectServiceError } from '../../coding-projects/project-service';
import { CodingConversationServiceError } from '../../coding-runtime/conversation-service';
import { sendJson } from '../route-utils';
export function sendCodingRouteError(res: ServerResponse, error: unknown): void {
if (error instanceof CodingProjectServiceError || error instanceof CodingConversationServiceError) {
sendJson(res, error.status, {
success: false,
code: error.code,
error: error.message,
});
return;
}
if (error instanceof SyntaxError) {
sendJson(res, 400, {
success: false,
code: 'CODING_REQUEST_INVALID',
error: 'Request JSON is invalid',
});
return;
}
sendJson(res, 500, {
success: false,
code: 'CODING_REQUEST_FAILED',
error: 'Coding request failed',
});
}
export function decodeRouteId(value: string): string {
try {
const decoded = decodeURIComponent(value).trim();
if (!decoded || decoded.length > 128 || decoded.includes('/')) throw new Error();
return decoded;
} catch {
throw new CodingConversationServiceError(
400,
'CODING_CONVERSATION_REQUEST_INVALID',
'Route identifier is invalid',
);
}
}