fix(providers): update Gemini Web cookies and models (#6095)

Refresh Gemini Web cookie handling + model catalog. Regression guard: gemini-web.test.ts.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
This commit is contained in:
backryun
2026-07-04 04:55:12 +09:00
committed by GitHub
parent caeee8970d
commit 91cda11c83
4 changed files with 203 additions and 23 deletions

View File

@@ -22,6 +22,8 @@
### 🔧 Bug Fixes
- **providers (Gemini Web):** refresh the Gemini Web cookie handling and model catalog so live Gemini Web sessions keep authenticating and routing to current models. Regression guard: `tests/unit/gemini-web.test.ts`. ([#6095](https://github.com/diegosouzapw/OmniRoute/pull/6095) — thanks @backryun)
- **providers (Perplexity Web):** refresh the Perplexity Web model catalog to the current set (GPT-5.4/5.5, Claude Sonnet 5.0 / Opus 4.8, GLM-5.2, Kimi K2.6, Nemotron 3 Ultra) and update the internal mode / `model_preference` mappings and thinking variants so requests resolve to live upstream models. Regression guard: `tests/unit/perplexity-web.test.ts`. ([#6106](https://github.com/diegosouzapw/OmniRoute/pull/6106) — thanks @backryun)
- **dashboard ("Update now" → Internal Server Error):** clicking **Update now** on the dashboard home could crash the page with a blank "Internal Server Error" screen (`Minified React error #31`). The handler POSTs the loopback-only `/api/system/version` auto-update endpoint and, on a non-OK JSON response (e.g. a `403` when the dashboard is reached through a reverse proxy / non-loopback origin), passed the raw error envelope object `{ error: { code, message, correlation_id } }` straight to `notify.error()`, which rendered the object as a React child and threw #31. The update-error path now funnels the body through `extractApiErrorMessage()` (the same safe extractor added in #5340), so a readable string always reaches the toast. Regression guard: `tests/unit/ui/home-update-error-render-5991.test.ts`. ([#5991](https://github.com/diegosouzapw/OmniRoute/issues/5991))

View File

@@ -9,9 +9,8 @@ export const gemini_webProvider: RegistryEntry = {
authType: "apikey",
authHeader: "cookie",
models: [
{ id: "gemini-2.5-pro", name: "Gemini 2.5 Pro" },
{ id: "gemini-2.5-flash", name: "Gemini 2.5 Flash" },
{ id: "gemini-2.0-pro", name: "Gemini 2.0 Pro" },
{ id: "gemini-2.0-flash", name: "Gemini 2.0 Flash" },
{ id: "gemini-3.1-pro", name: "Gemini 3.1 Pro" },
{ id: "gemini-3.5-flash", name: "Gemini 3.5 Flash" },
{ id: "gemini-3.1-flash-lite", name: "Gemini 3.1 Flash-Lite" },
],
};

View File

@@ -111,16 +111,21 @@ function parseCookies(raw: string): Array<{ name: string; value: string }> {
* <length>
* [["wrb.fr", null, "<JSON string>"]]
*
* The JSON string contains nested array: inner[4][0][1] = ["text chunks"]
* We return text from the first wrb.fr line that contains content.
* The JSON string contains nested array: inner[4][0][1] = ["text chunks"].
* We concatenate text from every wrb.fr line because Gemini can split one
* assistant answer across multiple StreamGenerate chunks.
*/
function parseStreamResponse(raw: string): string {
export function parseStreamResponse(raw: string): string {
const lines = raw.split("\n");
for (const line of lines) {
if (!line.trim() || line.trim() === ")]}'" || /^\d+$/.test(line.trim())) continue;
const textChunks: string[] = [];
for (const rawLine of lines) {
const line = rawLine.trim();
if (!line || line === ")]}'" || /^\d+$/.test(line)) continue;
if (!line.includes("wrb.fr")) continue;
try {
const arr = JSON.parse(line);
if (!Array.isArray(arr) || !arr[0] || arr[0][0] !== "wrb.fr") continue;
if (!Array.isArray(arr) || !Array.isArray(arr[0]) || arr[0][0] !== "wrb.fr") continue;
const payload = arr[0]?.[2];
if (typeof payload !== "string") continue;
const inner = JSON.parse(payload);
@@ -128,14 +133,65 @@ function parseStreamResponse(raw: string): string {
const responseArray = inner?.[4]?.[0]?.[1];
if (!Array.isArray(responseArray)) continue;
const text = responseArray.filter((c: unknown) => typeof c === "string").join("");
if (text) return text;
if (text) textChunks.push(text);
} catch {
// Skip unparseable lines
}
}
return textChunks.join("");
}
function readCredentialString(value: unknown): string {
if (typeof value !== "string") return "";
const trimmed = value.trim();
return trimmed.length > 0 ? trimmed : "";
}
function readProviderSpecificString(
providerSpecificData: unknown,
keys: readonly string[]
): string {
if (
!providerSpecificData ||
typeof providerSpecificData !== "object" ||
Array.isArray(providerSpecificData)
) {
return "";
}
const data = providerSpecificData as Record<string, unknown>;
for (const key of keys) {
const value = readCredentialString(data[key]);
if (value) return value;
}
return "";
}
function normalizeGeminiCookieInput(raw: string, cookieName = "__Secure-1PSID"): string {
const trimmed = raw.trim();
if (!trimmed) return "";
return trimmed.includes("=") ? trimmed : `${cookieName}=${trimmed}`;
}
function resolveGeminiWebCookie(credentials: ExecuteInput["credentials"]): string {
const directCookie =
readCredentialString(credentials?.apiKey) ||
readCredentialString((credentials as Record<string, unknown> | undefined)?.cookie);
if (directCookie) return normalizeGeminiCookieInput(directCookie);
const providerSpecificData = credentials?.providerSpecificData;
const cookie = readProviderSpecificString(providerSpecificData, ["cookie"]);
if (cookie) return normalizeGeminiCookieInput(cookie);
const psid = readProviderSpecificString(providerSpecificData, ["__Secure-1PSID"]);
const psidts = readProviderSpecificString(providerSpecificData, ["__Secure-1PSIDTS"]);
return [
psid ? normalizeGeminiCookieInput(psid, "__Secure-1PSID") : "",
psidts ? normalizeGeminiCookieInput(psidts, "__Secure-1PSIDTS") : "",
]
.filter(Boolean)
.join("; ");
}
// ─── Executor ───────────────────────────────────────────────────────────────
export class GeminiWebExecutor extends BaseExecutor {
@@ -147,7 +203,7 @@ export class GeminiWebExecutor extends BaseExecutor {
const { model, body, stream, credentials, signal } = input;
const requestBody = body as GeminiRequestBody;
const cookie = credentials.apiKey || "";
const cookie = resolveGeminiWebCookie(credentials);
if (!cookie) {
return {
response: new Response(JSON.stringify({ error: "Missing Gemini cookies" }), {

View File

@@ -1,7 +1,8 @@
import test from "node:test";
import assert from "node:assert/strict";
const { GeminiWebExecutor } = await import("../../open-sse/executors/gemini-web.ts");
const { GeminiWebExecutor, parseStreamResponse } =
await import("../../open-sse/executors/gemini-web.ts");
const { getExecutor, hasSpecializedExecutor } = await import("../../open-sse/executors/index.ts");
// ─── Registration ───────────────────────────────────────────────────────────
@@ -22,7 +23,7 @@ test("GeminiWebExecutor sets correct provider name", () => {
test("Returns 401 when no cookies provided", async () => {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-2.5-pro",
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hi" }], stream: false },
stream: false,
credentials: {},
@@ -37,7 +38,7 @@ test("Returns 401 when no cookies provided", async () => {
test("Returns 400 when no user message", async () => {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-2.5-pro",
model: "gemini-3.1-pro",
body: { messages: [{ role: "system", content: "You are helpful" }], stream: false },
stream: false,
credentials: { apiKey: "test-cookie" },
@@ -49,6 +50,104 @@ test("Returns 400 when no user message", async () => {
assert.ok(json.error.includes("No user message"));
});
test("Reads bulk-imported cookie credentials from providerSpecificData.cookie", async () => {
const playwrightError = new Error(
"browserType.launch: Executable doesn't exist at /home/node/.cache/ms-playwright/chromium_headless_shell-1161/chrome-linux/headless_shell"
);
const playwright = await import("playwright");
const originalLaunch = playwright.chromium.launch;
playwright.chromium.launch = async () => {
throw playwrightError;
};
try {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hello" }], stream: false },
stream: false,
credentials: {
providerSpecificData: { cookie: "__Secure-1PSID=from-bulk-import" },
} as any,
signal: AbortSignal.timeout(5000),
log: null,
});
assert.equal(
result.response.status,
503,
"providerSpecificData.cookie should be accepted and reach Playwright launch"
);
} finally {
playwright.chromium.launch = originalLaunch;
}
});
test("Ignores array-valued providerSpecificData when resolving cookies", async () => {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hello" }], stream: false },
stream: false,
credentials: {
providerSpecificData: ["__Secure-1PSID=not-a-record"],
} as any,
signal: AbortSignal.timeout(5000),
log: null,
});
assert.equal(result.response.status, 401);
});
test("Normalizes a bare __Secure-1PSID value before adding browser cookies", async () => {
const playwright = await import("playwright");
const originalLaunch = playwright.chromium.launch;
let addedCookies: Array<{ name: string; value: string }> = [];
playwright.chromium.launch = async () =>
({
newContext: async () => ({
addCookies: async (cookies: Array<{ name: string; value: string }>) => {
addedCookies = cookies;
},
newPage: async () => ({
on: () => {},
goto: async () => {},
waitForTimeout: async () => {},
waitForSelector: async () => ({
click: async () => {},
}),
keyboard: {
type: async () => {},
press: async () => {},
},
}),
}),
close: async () => {},
}) as any;
try {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hello" }], stream: false },
stream: false,
credentials: { apiKey: "raw-psid-value" },
signal: AbortSignal.timeout(5000),
log: null,
});
assert.equal(result.response.status, 502, "fake page intentionally returns no Gemini response");
assert.equal(addedCookies.length, 1);
assert.equal(addedCookies[0].name, "__Secure-1PSID");
assert.equal(addedCookies[0].value, "raw-psid-value");
} finally {
playwright.chromium.launch = originalLaunch;
}
});
// ─── Provider registration ──────────────────────────────────────────────────
test("Provider: gemini-web in WEB_COOKIE_PROVIDERS", async () => {
@@ -68,11 +167,14 @@ test("Provider: gemini-web in providerRegistry", async () => {
test("Provider: gemini-web has correct models", async () => {
const { REGISTRY } = await import("../../open-sse/config/providerRegistry.ts");
const models = REGISTRY["gemini-web"].models;
const modelIds = models.map((m: any) => m.id);
assert.ok(modelIds.includes("gemini-2.5-pro"));
assert.ok(modelIds.includes("gemini-2.5-flash"));
assert.ok(modelIds.includes("gemini-2.0-pro"));
assert.ok(modelIds.includes("gemini-2.0-flash"));
assert.deepEqual(
models.map((m: any) => [m.id, m.name]),
[
["gemini-3.1-pro", "Gemini 3.1 Pro"],
["gemini-3.5-flash", "Gemini 3.5 Flash"],
["gemini-3.1-flash-lite", "Gemini 3.1 Flash-Lite"],
]
);
});
// ─── Regression: #2832 / #3516 — Playwright missing in Docker (runner-base) ──
@@ -106,7 +208,7 @@ test("#2832/#3516: missing Playwright browser returns an actionable 503 with coo
try {
const executor = new GeminiWebExecutor();
const result = await executor.execute({
model: "gemini-2.5-pro",
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hello" }], stream: false },
stream: false,
credentials: { apiKey: "fake-cookie=abc" },
@@ -126,7 +228,10 @@ test("#2832/#3516: missing Playwright browser returns an actionable 503 with coo
assert.match(json.error, /playwright install|not installed/i, "message must be actionable");
// No raw stack trace / source path leaks into the body.
assert.ok(!json.error.includes("\n at "), "must not contain multi-line stack trace");
assert.ok(!json.error.includes("node_modules/playwright-core"), "must not contain node_modules source path");
assert.ok(
!json.error.includes("node_modules/playwright-core"),
"must not contain node_modules source path"
);
} finally {
playwright.chromium.launch = originalLaunch;
}
@@ -143,7 +248,7 @@ test("#2832: GeminiWebExecutor catch block sanitizes Playwright launch errors (i
controller.abort(new Error("Request aborted"));
const result = await executor.execute({
model: "gemini-2.5-pro",
model: "gemini-3.1-pro",
body: { messages: [{ role: "user", content: "hello" }], stream: false },
stream: false,
credentials: { apiKey: "fake-cookie=abc" },
@@ -158,3 +263,21 @@ test("#2832: GeminiWebExecutor catch block sanitizes Playwright launch errors (i
assert.ok(typeof json.error === "string", "error must be a string");
assert.ok(!json.error.includes("at /"), "no stack trace path in error response");
});
// ─── StreamGenerate parsing ─────────────────────────────────────────────────
test("parseStreamResponse concatenates Gemini Web text from multiple wrb.fr chunks", () => {
const makeChunk = (text: string) => {
const inner = new Array(80).fill(null);
inner[4] = [[null, [text]]];
return `[["wrb.fr", null, ${JSON.stringify(JSON.stringify(inner))}]]`;
};
const raw = `)]}'\n10\n${makeChunk("First ")}\n5\n${makeChunk("chunk")}`;
assert.equal(parseStreamResponse(raw), "First chunk");
});
test("parseStreamResponse ignores wrb.fr lines whose first entry is not an array", () => {
const raw = `)]}'\n10\n${JSON.stringify(["wrb.fr", null, "[]"])}`;
assert.equal(parseStreamResponse(raw), "");
});