Files
OmniRoute/src/shared/providers/webSessionCredentials.ts
backryun c92bdd13c6 fix(lmarena): modernize Arena web provider + static Direct-chat catalog (#6280)
* fix(lmarena): modernize Arena web provider + static Direct-chat catalog

Update the lmarena provider for arena.ai (product rebranded from LMArena):

- Route chat via arena.ai create-evaluation with Chrome TLS impersonation
  (tls-client-node) and optional browser-minted recaptchaV3Token.
- Seed Text+Search (48) into the chat registry; seed Image (27) only into
  IMAGE_PROVIDERS. Disable live HTML model discovery; resolve public names to
  Arena UUIDs from the static TypeScript allowlist (no scrape JSON in-repo).
- Soft-exclude 404/502 model ids; slow/stop bulk test-all probes for this provider.
- Do not fold IMAGE_PROVIDERS/video specialty into the chat provider catalog when
  a chat registry already exists (lmarena/openai/xai).
- Display name Arena (Free); keep wire id `lmarena` / alias `lma` for back-compat.
- Theme-aware provider icons: arena-light.svg / arena-dark.svg.
- Preserve split Supabase SSR cookie reconstruction for arena-auth-prod-v1.*.

* fix(providers): align provider-models-route test fixture + regen provider reference

Fold the topaz image-only catalog entry's apiFormat/supportedEndpoints
into the local-catalog test fixture (route now tags media-only
providers per the lmarena PR's staticModels.ts change), regenerate
PROVIDER_REFERENCE.md against the merged release providers.ts, and add
the changelog fragment for #6280.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* test: align web-cookie fallback suite — lmarena now has a registry entry (probe path)

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-11 01:33:24 -03:00

313 lines
12 KiB
TypeScript

import { WEB_COOKIE_PROVIDERS } from "@/shared/constants/providers";
export type WebSessionCredentialRequirement =
| {
kind: "cookie" | "token";
credentialName: string;
placeholder: string;
acceptsFullCookieHeader: boolean;
storageKeys: readonly string[];
/**
* #5465 — Optional i18n key for a provider-specific credential hint that
* REPLACES the generic "Required cookie: {credential}…" copy. Use when the
* generic template is confusing (e.g. t3.chat needs a localStorage value
* AND the Cookie header, so the one-line cookie hint reads circular).
*/
hintKey?: string;
hintFallback?: string;
}
| {
kind: "none";
credentialName: "";
placeholder: "";
acceptsFullCookieHeader: false;
storageKeys: readonly [];
};
export const WEB_SESSION_CREDENTIAL_REQUIREMENTS = {
"zenmux-free": {
kind: "cookie",
credentialName: "Cookie header (full)",
placeholder: "paste the full Cookie header from zenmux.ai",
acceptsFullCookieHeader: true,
storageKeys: ["cookie"],
},
"chatgpt-web": {
kind: "cookie",
credentialName: "__Secure-next-auth.session-token",
placeholder: "__Secure-next-auth.session-token=...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sessionToken", "session-token", "__Secure-next-auth.session-token"],
},
"grok-web": {
kind: "cookie",
credentialName: "sso + sso-rw",
placeholder: "sso=...; sso-rw=...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sso", "sso-rw"],
},
"gemini-web": {
kind: "cookie",
credentialName: "__Secure-1PSID (optional: __Secure-1PSIDTS)",
placeholder: "__Secure-1PSID=...; __Secure-1PSIDTS=...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "__Secure-1PSID", "__Secure-1PSIDTS"],
},
"gemini-business": {
kind: "cookie",
credentialName: "__Secure-1PSID (optional: __Secure-1PSIDTS)",
placeholder: "__Secure-1PSID=...; __Secure-1PSIDTS=... (from business.gemini.google)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "__Secure-1PSID", "__Secure-1PSIDTS"],
},
"perplexity-web": {
kind: "cookie",
credentialName: "__Secure-next-auth.session-token",
placeholder: "__Secure-next-auth.session-token=...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sessionToken", "session-token", "__Secure-next-auth.session-token"],
},
"blackbox-web": {
kind: "cookie",
credentialName: "__Secure-authjs.session-token",
placeholder: "__Secure-authjs.session-token=...; other=value",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sessionToken", "__Secure-authjs.session-token"],
},
"muse-spark-web": {
kind: "cookie",
credentialName: "abra_sess",
placeholder: "abra_sess=...; other=value",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "abra_sess"],
},
"claude-web": {
kind: "cookie",
credentialName: "sessionKey",
placeholder: "sessionKey=... or full Cookie header from claude.ai",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sessionKey"],
},
"deepseek-web": {
kind: "token",
credentialName: "userToken",
placeholder: "userToken=... or paste raw userToken",
acceptsFullCookieHeader: false,
storageKeys: ["token", "userToken"],
},
"copilot-web": {
kind: "token",
credentialName: "access_token",
placeholder: "access_token=... or a DevTools HAR export",
acceptsFullCookieHeader: false,
storageKeys: ["token", "access_token", "accessToken"],
},
"copilot-m365-web": {
kind: "token",
credentialName: "access_token + chathubPath",
placeholder: "access_token=...; chathubPath=redacted",
acceptsFullCookieHeader: false,
storageKeys: ["token", "access_token", "accessToken", "chathubPath", "userTenant"],
},
"t3-web": {
kind: "cookie",
credentialName: "convex-session-id + Cookie header",
placeholder: "convex-session-id=abc123...; Cookie: ...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "convex-session-id", "convexSessionId"],
// #5465 — the generic cookie hint reads circular for t3.chat (needs a
// localStorage value AND the Cookie header); use the step-by-step DevTools
// copy that already ships translated in every locale.
hintKey: "t3ChatWebCookieHint",
},
"adapta-web": {
kind: "cookie",
credentialName: "__client",
placeholder: "__client=... or full Cookie header from agent.adapta.one",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "__client"],
},
"inner-ai": {
kind: "cookie",
credentialName: "token + email",
placeholder: "token_value user@example.com",
acceptsFullCookieHeader: false,
storageKeys: ["token", "cookie", "email"],
},
huggingchat: {
kind: "cookie",
credentialName: "full Cookie header (hf-chat + token)",
placeholder:
"hf-chat=...; token=...; aws-waf-token=... (full Cookie header from huggingface.co)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "hf-chat"],
},
"yuanbao-web": {
kind: "cookie",
credentialName: "full Cookie header (hy_user + hy_token)",
placeholder: "hy_user=...; hy_token=... (full Cookie header from yuanbao.tencent.com)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "hy_user", "hy_token"],
},
"poe-web": {
kind: "cookie",
credentialName: "p-b",
placeholder: "p-b=... or full Cookie header from poe.com",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "p-b"],
},
"venice-web": {
kind: "cookie",
credentialName: "session",
placeholder: "session=... or full Cookie header from venice.ai",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "session"],
},
"v0-vercel-web": {
kind: "cookie",
credentialName: "__vercel_session",
placeholder: "__vercel_session=... or full Cookie header from v0.dev",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "__vercel_session"],
},
"kimi-web": {
kind: "cookie",
credentialName: "kimi-auth",
placeholder: "kimi-auth=eyJ... (full Cookie header from www.kimi.com)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "kimi-auth", "session"],
},
"doubao-web": {
kind: "cookie",
credentialName: "full Cookie header (sessionid + ttwid + s_v_web_id)",
placeholder:
"sessionid=...; ttwid=...; s_v_web_id=... (or fp=verify_... fallback from www.dola.com)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "sessionid", "ttwid", "s_v_web_id", "fp"],
},
"qwen-web": {
kind: "cookie",
credentialName: "full Cookie header (must include cna, ssxmod_itna, token)",
placeholder:
"cna=...; token=...; ssxmod_itna=...; ssxmod_itna2=... (full Cookie header from chat.qwen.ai)",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "token", "ssxmod_itna", "ssxmod_itna2", "cna", "tongyi_sso_ticket"],
},
"duckduckgo-web": {
kind: "cookie",
credentialName: "duckai",
placeholder: "duckai=... or full Cookie header from duckduckgo.com",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "duckai"],
},
"t3-chat-web": {
kind: "token",
credentialName: "token",
placeholder: "Paste your T3 Chat token from t3.chat (Local Storage → token)",
acceptsFullCookieHeader: false,
storageKeys: ["token"],
},
"chatglm-web": {
kind: "cookie",
credentialName: "chatglm_session",
placeholder: "chatglm_session=... or full Cookie header from chatglm.cn",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "chatglm_session"],
},
"xiaomimimo-web": {
kind: "cookie",
credentialName: "session",
placeholder: "session=... or full Cookie header from aistudio.xiaomimimo.com",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "session"],
},
"manus-web": {
kind: "cookie",
credentialName: "manus_session",
placeholder: "manus_session=... or full Cookie header from manus.im",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "manus_session"],
},
lmarena: {
kind: "cookie",
// arena.ai's auth cookie is `arena-auth-prod-v1` (the legacy hint said `session`,
// which never matched the real cookie name and confused users). #3810
//
// #4271: LMArena migrated to Supabase SSR chunked cookies — the single
// `arena-auth-prod-v1` cookie is now empty and the session is split across
// `arena-auth-prod-v1.0`, `arena-auth-prod-v1.1`, … Users must paste the FULL
// Cookie header so the executor can reconstruct the single cookie from chunks.
credentialName: "full Cookie header (arena-auth-prod-v1.0 + arena-auth-prod-v1.1)",
placeholder:
"arena-auth-prod-v1.0=...; arena-auth-prod-v1.1=...; other=value (full Cookie header from arena.ai)",
acceptsFullCookieHeader: true,
storageKeys: [
"cookie",
"arena-auth-prod-v1",
"arena-auth-prod-v1.0",
"arena-auth-prod-v1.1",
"session",
],
hintKey: "lmarenaWebCookieHint",
hintFallback:
"Open arena.ai, sign in, then copy the full Cookie header from a Network request. Include arena-auth-prod-v1.0 and arena-auth-prod-v1.1 (and further chunks if present), preferably with cf_clearance. Do not paste only the empty arena-auth-prod-v1 cookie. Optional: providerSpecificData.recaptchaV3Token if create-evaluation still returns 403.",
},
} satisfies Record<keyof typeof WEB_COOKIE_PROVIDERS, WebSessionCredentialRequirement>;
export function getWebSessionCredentialRequirement(
providerId: unknown
): WebSessionCredentialRequirement | null {
if (typeof providerId !== "string") return null;
return (
WEB_SESSION_CREDENTIAL_REQUIREMENTS[
providerId as keyof typeof WEB_SESSION_CREDENTIAL_REQUIREMENTS
] ?? null
);
}
export function requiresWebSessionCredential(providerId: unknown): boolean {
const requirement = getWebSessionCredentialRequirement(providerId);
return !!requirement && requirement.kind !== "none";
}
function hasNonEmptyString(value: unknown): value is string {
return typeof value === "string" && value.trim().length > 0;
}
export function hasUsableWebSessionCredential(
providerId: unknown,
providerSpecificData: unknown
): boolean {
const requirement = getWebSessionCredentialRequirement(providerId);
if (!requirement || requirement.kind === "none") return false;
if (!providerSpecificData || typeof providerSpecificData !== "object") return false;
const data = providerSpecificData as Record<string, unknown>;
return requirement.storageKeys.some((key) => hasNonEmptyString(data[key]));
}
/**
* Resolve the value that a web-session import must store in the connection's
* `apiKey` column.
*
* `token`-kind providers (deepseek-web, copilot-web, copilot-m365-web,
* t3-chat-web, …) are authenticated from `apiKey`: both the connection
* validator (`validateDeepSeekWebProvider({ apiKey })`) and the executor
* (`extractUserToken` → `credentials.apiKey`) read the token there — never from
* `providerSpecificData`. The bulk web-session import used to leave `apiKey`
* null and stash the token only in `providerSpecificData`, so imported token-kind
* connections were never recognized. Return the credential for token-kind so the
* import stores it where those readers look.
*
* `cookie`-kind providers keep `apiKey` null — their executors read the full
* cookie from `providerSpecificData.cookie`.
*/
export function resolveWebSessionImportApiKey(
requirement: WebSessionCredentialRequirement | null,
credential: string
): string | null {
if (!requirement || requirement.kind !== "token") return null;
const trimmed = typeof credential === "string" ? credential.trim() : "";
return trimmed.length > 0 ? trimmed : null;
}