File size: 948 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import { handleChat } from "@/sse/handlers/chat.js";
import { initTranslators } from "open-sse/translator/index.js";
let initialized = false;
async function ensureInitialized() {
if (!initialized) {
await initTranslators();
initialized = true;
}
}
export async function OPTIONS() {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "*"
}
});
}
/**
* POST /v1/responses/compact - Compact conversation context
* Reuses the same handleChat pipeline, signals compact via body._compact
*/
export async function POST(request) {
await ensureInitialized();
const body = await request.json();
body._compact = true;
const newRequest = new Request(request.url, {
method: "POST",
headers: request.headers,
body: JSON.stringify(body)
});
return await handleChat(newRequest);
}
|