Fix : Antigravity MITM
This commit is contained in:
1 parent
512e3de371
commit
34da52f144
12 files changed
+313
-128
No files matched your search
@@ -1,19 +1,31 @@
|
||||
const { err } = require("../logger");
|
||||
const { err, createResponseDumper } = require("../logger");
|
||||
const { fetchRouter, pipeSSE } = require("./base");
|
||||
|
||||
/**
|
||||
* Intercept Antigravity (Gemini) request — replace model and forward to router
|
||||
* Intercept Antigravity request — forward Gemini body as-is to /v1/chat/completions.
|
||||
* Router auto-detects format via body.userAgent==="antigravity" + body.request.contents,
|
||||
* runs antigravity→openai→provider→openai→antigravity translators internally.
|
||||
*/
|
||||
async function intercept(req, res, bodyBuffer, mappedModel) {
|
||||
const dumper = createResponseDumper(req, "intercept-antigravity");
|
||||
const isStream = req.url.includes(":streamGenerateContent");
|
||||
try {
|
||||
const body = JSON.parse(bodyBuffer.toString());
|
||||
body.model = mappedModel;
|
||||
if (body.model) body.model = mappedModel;
|
||||
|
||||
const routerRes = await fetchRouter(body, "/v1/chat/completions", req.headers);
|
||||
await pipeSSE(routerRes, res);
|
||||
await pipeSSE(routerRes, res, dumper);
|
||||
} catch (error) {
|
||||
err(`[antigravity] ${error.message}`);
|
||||
if (!res.headersSent) res.writeHead(500, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ error: { message: error.message, type: "mitm_error" } }));
|
||||
if (dumper) { dumper.writeChunk(`\n[ERROR] ${error.message}\n`); dumper.end(); }
|
||||
// For stream endpoint, send SSE error chunk so SDK doesn't hang waiting
|
||||
if (isStream) {
|
||||
if (!res.headersSent) res.writeHead(200, { "Content-Type": "text/event-stream" });
|
||||
res.end(`data: ${JSON.stringify({ error: { message: error.message } })}\r\n\r\n`);
|
||||
} else {
|
||||
if (!res.headersSent) res.writeHead(500, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ error: { message: error.message, type: "mitm_error" } }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user