Enhance provider models and chat handling with new thinking configurations

This commit is contained in:
decolua
2026-04-13 12:04:57 +07:00
parent ee1271b6fd
commit 4c28a1671d
15 changed files with 142 additions and 421 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ async function intercept(req, res, bodyBuffer, mappedModel) {
try {
const body = JSON.parse(bodyBuffer.toString());
body.model = mappedModel;
const routerRes = await fetchRouter(body);
const routerRes = await fetchRouter(body, "/v1/chat/completions", req.headers);
await pipeSSE(routerRes, res);
} catch (error) {
err(`[antigravity] ${error.message}`);
+15 -2
View File
@@ -6,13 +6,26 @@ const ROUTER_BASE = String(process.env.MITM_ROUTER_BASE || DEFAULT_LOCAL_ROUTER)
.replace(/\/+$/, "") || DEFAULT_LOCAL_ROUTER;
const API_KEY = process.env.ROUTER_API_KEY;
// Headers that must not be forwarded to 9Router
const STRIP_HEADERS = new Set([
"host", "content-length", "connection", "transfer-encoding",
"content-type", "authorization"
]);
/**
* Send body to 9Router at the given path and return the fetch Response object
* Send body to 9Router at the given path and return the fetch Response object.
* Optionally forwards client headers (stripped of hop-by-hop / overridden keys).
*/
async function fetchRouter(openaiBody, path = "/v1/chat/completions") {
async function fetchRouter(openaiBody, path = "/v1/chat/completions", clientHeaders = {}) {
const forwarded = {};
for (const [k, v] of Object.entries(clientHeaders)) {
if (!STRIP_HEADERS.has(k.toLowerCase())) forwarded[k] = v;
}
const response = await fetch(`${ROUTER_BASE}${path}`, {
method: "POST",
headers: {
...forwarded,
"Content-Type": "application/json",
...(API_KEY && { "Authorization": `Bearer ${API_KEY}` })
},
+1 -1
View File
@@ -23,7 +23,7 @@ async function intercept(req, res, bodyBuffer, mappedModel) {
const body = JSON.parse(bodyBuffer.toString());
body.model = mappedModel;
const routerPath = resolveRouterPath(req.url);
const routerRes = await fetchRouter(body, routerPath);
const routerRes = await fetchRouter(body, routerPath, req.headers);
await pipeSSE(routerRes, res);
} catch (error) {
err(`[copilot] ${error.message}`);
+1 -1
View File
@@ -8,7 +8,7 @@ async function intercept(req, res, bodyBuffer, mappedModel) {
try {
const body = JSON.parse(bodyBuffer.toString());
body.model = mappedModel;
const routerRes = await fetchRouter(body);
const routerRes = await fetchRouter(body, "/v1/chat/completions", req.headers);
await pipeSSE(routerRes, res);
} catch (error) {
err(`[Kiro] ${error.message}`);