mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 20:32:25 +03:00
Rebased onto the current release/v3.8.51 tip as part of a combined provider-retirement/provenance merge batch (Designer Web, Felo Web, Runtime, GPL-derived removal, Qwen Web already landed). Large conflict set (this is the biggest PR in the batch — the common ChatGPT Web provider touches chat, images, count-tokens, session leases, and combos). Conflicts resolved: - `open-sse/config/providers/registry/chatgpt-web/*`, `open-sse/executors/chatgpt-web*`, `open-sse/handlers/imageGeneration/providers/chatgptWeb.ts`, and their tests: kept deleted, matching the PR's stated scope. - `open-sse/config/providers/registry/minimax/web/index.ts`, `open-sse/handlers/imageGeneration/providers/geminiWeb.ts`, `open-sse/executors/gemini-web.ts`'s stale image-mode branch: base-drift collisions against already-merged sibling retirements (#11691, #11708) — kept deleted / dropped the dead code, since this PR's own branch forked before those merged. - `src/shared/constants/reservedProviderPrefixes.ts`, `open-sse/executors/index.ts`, `executorProxy.ts`, `virtualFactory.ts`, `autoStrategy.ts`, `src/lib/db/providers.ts`, `src/sse/handlers/chat.ts`: combined the Designer + Runtime (Felo/Qwen) + common-ChatGPT-Web retirement guard calls at each shared chokepoint — compute-once-then-OR pattern, consistent with prior combinations in this batch. - `src/sse/services/model.ts` / `src/sse/handlers/chatHelpers.ts`: adopted this PR's new `getModelInfoOrRetirementResponse()` central wrapper (a real improvement over ad-hoc try/catch), and extended it to also catch the Designer + Runtime retirement errors it didn't originally cover, so the consolidation doesn't regress the other two mechanisms. - `src/app/api/v1/images/edits/route.ts`: this PR moved the retirement check earlier (before `enforceApiKeyPolicy`) but left the old later call+catch block in place from base drift — removed the now-redundant duplicate `resolveImageRouteModel()` call and merged the Designer catch into the earlier one. - `open-sse/config/imageRegistry.ts`, `tests/snapshots/executors/executor-map.json` (`keyCount` recomputed to 133), `tests/snapshots/provider/translate-path.json`: same "both sides inserted a different retired provider at the same slot" pattern — resolved by dropping both. - `tests/unit/chatcore-executor-proxy.test.ts`, `provider-node-reserved-prefix.test.ts`, `combo-auto-candidate-expansion.test.ts`, `messages-count-tokens-route.test.ts`, `virtual-auto-combo.test.ts`: split into independent per-mechanism test blocks (established pattern); `virtual-auto-combo.test.ts`'s old "includes cookie web-session providers" positive-inclusion test (which used chatgpt-web as its example) was retired along with the provider and replaced by this PR's negative-exclusion test for the same slot. - `docs/architecture/ARCHITECTURE.md`, `CODEBASE_DOCUMENTATION.md` (+ 4 i18n mirrors), `README.md`, `FREE-TIERS-GUIDE.md`, `docs/diagrams/free-tier-budget.svg`, `docs/screenshots/free-tier-budget-card.svg`, `docs/reference/PROVIDER_REFERENCE.md`: recomputed every stale count from the real merged state — 104 executors (`countFiles` gate logic), 351 providers (regenerated via `gen:provider-reference`), 152/351 `hasFree` entries, 445/438/7 free-tier catalog rows, 13 ToS-avoid providers, budget-card regenerated via its real generator script. One doc conflict (`oauth/` module list) needed picking HEAD's side specifically — theirs still listed the already-removed `raycast` module instead of the real `openference`. - `config/quality/test-masking-allowlist.json`: additive merge of the PR's 17 `_deletedWithReplacement` entries alongside the batch's existing ones (one real duplicate-key mistake in my first pass, caught and fixed via a `object_pairs_hook` duplicate-key check before finalizing). Also fixed two real, unrelated-to-my-merge issues surfaced by the focused suite: - `tests/unit/resolve-web-provider-host.test.ts`: the PR's own test had a typo — it asserted `perplexity-web`'s resolved host as `"perplexity.ai"`, but the provider's registered `website` is `"https://www.perplexity.ai"` and the resolver returns the URL's `host` verbatim (no www-stripping), so the correct value is `"www.perplexity.ai"` (consistent with the same test's own `url` assertion). - `tests/unit/hard-session-lease-bypass-inventory.test.ts`: this golden call-site inventory was already stale on the pristine post-#11713 tip (confirmed via a throwaway probe worktree) — `src/lib/db/providers.ts`'s 3 connection-fallback sites and a third `src/app/api/providers/route.ts` site were never added to the golden list by the earlier-merged #11698/#11720 PRs. Updated it to the real current inventory (dated inline comments explain each delta and which PR introduced it), plus this PR's own legitimate deltas (image-edits duplicate-call removal, `ChatGptWebExecutor.execute()` site removed). Focused suite green (433/433 across executor-proxy, reserved-prefix, hard-session-lease-bypass-inventory, resolve-web-provider-host, retirement/runtime-block/source-retirement/management-retirement/image-handler-retirement, migration-168, combo-auto-candidate-expansion, virtual-auto-combo, executor-map-golden and siblings), plus `typecheck:core`, `check-file-size`, and `check-changelog-integrity` clean. Thanks for the thorough provenance-hold retirement work — appreciated.
399 lines
16 KiB
TypeScript
399 lines
16 KiB
TypeScript
/**
|
|
* TokenExtractionConfig — Login & cookie extraction configs for web-cookie providers
|
|
*
|
|
* Each config describes how to:
|
|
* 1. Open a browser window/navigate to the provider's login page
|
|
* 2. Detect successful login (URL change + token presence)
|
|
* 3. Extract session cookies / tokens from the browser context
|
|
*
|
|
* Used by InAppLoginService (Electron BrowserWindow path) and
|
|
* the Playwright-based login flow (dashboard API).
|
|
*/
|
|
|
|
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
|
|
/** Describes where to extract credential data from after login */
|
|
export type TokenSource =
|
|
| { type: "cookie"; name: string; domain?: string }
|
|
| { type: "localStorage"; key: string }
|
|
| { type: "sessionStorage"; key: string }
|
|
| { type: "header"; name: string };
|
|
|
|
export interface PollingConfig {
|
|
/** Milliseconds between extraction polls (default 1000) */
|
|
pollInterval: number;
|
|
/** Total timeout in ms (default 300000 = 5 min) */
|
|
timeout: number;
|
|
/** Minimum time in ms before first extraction attempt (default 5000) */
|
|
minLoginTime: number;
|
|
}
|
|
|
|
export interface TokenExtractionConfig {
|
|
/** Matches the executor's provider ID (e.g. "claude-web", "gemini-web") */
|
|
providerId: string;
|
|
/** Human-readable name shown in dashboard UI */
|
|
displayName: string;
|
|
/** The URL to navigate to for login */
|
|
loginUrl: string;
|
|
/** The provider's home page URL (for cookie domain binding) */
|
|
homeUrl: string;
|
|
/** Optional regex. If current URL matches → login is likely complete */
|
|
successUrlPattern?: RegExp;
|
|
/** Sources to extract credentials from after login */
|
|
tokenSources: TokenSource[];
|
|
/** Polling behaviour */
|
|
pollingConfig: PollingConfig;
|
|
/** Short instructions shown to the user in the login modal */
|
|
instructions: string;
|
|
/** Optional: cookie domain override for cookie injection */
|
|
cookieDomain?: string;
|
|
}
|
|
|
|
// ─── Defaults ───────────────────────────────────────────────────────────────
|
|
|
|
const DEFAULT_POLLING: PollingConfig = {
|
|
pollInterval: 1000,
|
|
timeout: 300_000,
|
|
minLoginTime: 5000,
|
|
};
|
|
|
|
const QUICK_POLLING: PollingConfig = {
|
|
pollInterval: 800,
|
|
timeout: 120_000,
|
|
minLoginTime: 3000,
|
|
};
|
|
|
|
// ─── Helper ──────────────────────────────────────────────────────────────────
|
|
|
|
function config(
|
|
providerId: string,
|
|
displayName: string,
|
|
loginUrl: string,
|
|
homeUrl: string,
|
|
tokenSources: TokenSource[],
|
|
instructions: string,
|
|
opts?: {
|
|
successUrlPattern?: RegExp;
|
|
pollingConfig?: Partial<PollingConfig>;
|
|
cookieDomain?: string;
|
|
}
|
|
): TokenExtractionConfig {
|
|
return {
|
|
providerId,
|
|
displayName,
|
|
loginUrl,
|
|
homeUrl,
|
|
tokenSources,
|
|
instructions,
|
|
pollingConfig: { ...DEFAULT_POLLING, ...opts?.pollingConfig },
|
|
successUrlPattern: opts?.successUrlPattern,
|
|
cookieDomain: opts?.cookieDomain,
|
|
};
|
|
}
|
|
|
|
// ─── Configuration Map ──────────────────────────────────────────────────────
|
|
|
|
const RAW_CONFIGS: TokenExtractionConfig[] = [
|
|
// ── Claude Web ────────────────────────────────────────────
|
|
config(
|
|
"claude-web",
|
|
"Claude Web",
|
|
"https://claude.ai/login",
|
|
"https://claude.ai",
|
|
[{ type: "cookie", name: "sessionKey", domain: ".claude.ai" }],
|
|
"Log in to your Claude account at claude.ai. After login, the session cookie will be extracted automatically."
|
|
),
|
|
|
|
// ── Gemini Web ────────────────────────────────────────────
|
|
config(
|
|
"gemini-web",
|
|
"Gemini Web",
|
|
"https://gemini.google.com/app",
|
|
"https://gemini.google.com",
|
|
[
|
|
{ type: "cookie", name: "__Secure-1PSID", domain: ".google.com" },
|
|
{ type: "cookie", name: "__Secure-1PSIDTS", domain: ".google.com" },
|
|
],
|
|
"Log in to your Google account at gemini.google.com. Both __Secure-1PSID and __Secure-1PSIDTS cookies will be extracted.",
|
|
{ cookieDomain: ".google.com" }
|
|
),
|
|
|
|
// ── Grok Web ──────────────────────────────────────────────
|
|
config(
|
|
"grok-web",
|
|
"Grok Web",
|
|
"https://grok.com/login",
|
|
"https://grok.com",
|
|
[{ type: "cookie", name: "sso", domain: ".grok.com" }],
|
|
"Log in to your xAI account at grok.com. The sso session cookie will be extracted."
|
|
),
|
|
|
|
// ── Perplexity Web ────────────────────────────────────────
|
|
config(
|
|
"perplexity-web",
|
|
"Perplexity Web",
|
|
"https://www.perplexity.ai/login",
|
|
"https://www.perplexity.ai",
|
|
[{ type: "cookie", name: "__Secure-next-auth.session-token", domain: ".perplexity.ai" }],
|
|
"Log in to Perplexity. The __Secure-next-auth.session-token cookie will be extracted.",
|
|
{ cookieDomain: ".perplexity.ai" }
|
|
),
|
|
|
|
// ── DeepSeek Web ──────────────────────────────────────────
|
|
config(
|
|
"deepseek-web",
|
|
"DeepSeek Web",
|
|
"https://chat.deepseek.com/sign_in",
|
|
"https://chat.deepseek.com",
|
|
[
|
|
{ type: "cookie", name: "user-token", domain: ".deepseek.com" },
|
|
{ type: "localStorage", key: "userToken" },
|
|
],
|
|
"Log in to DeepSeek at chat.deepseek.com. The user-token cookie will be extracted.",
|
|
{ cookieDomain: ".deepseek.com" }
|
|
),
|
|
|
|
// ── Volcano Engine Ark Console ───────────────────────────
|
|
config(
|
|
"volcengine-console",
|
|
"Volcano Engine Ark Console",
|
|
"https://console.volcengine.com/ark/region:cn-beijing/subscription/coding-plan",
|
|
"https://console.volcengine.com",
|
|
[
|
|
{ type: "cookie", name: "digest", domain: ".volcengine.com" },
|
|
{ type: "cookie", name: "AccountID", domain: ".volcengine.com" },
|
|
{ type: "cookie", name: "csrfToken", domain: ".volcengine.com" },
|
|
{ type: "cookie", name: "userInfo", domain: ".volcengine.com" },
|
|
],
|
|
"Log in to the Volcano Engine Ark console. The console session is used to discover Agent/Coding Plan API keys and live quota usage.",
|
|
{
|
|
cookieDomain: ".volcengine.com",
|
|
successUrlPattern: /console\.volcengine\.com\/ark/i,
|
|
pollingConfig: { timeout: 300_000, minLoginTime: 3000 },
|
|
}
|
|
),
|
|
|
|
// ── Kimi Web ──────────────────────────────────────────────
|
|
config(
|
|
"kimi-web",
|
|
"Kimi (Moonshot)",
|
|
"https://www.kimi.com/",
|
|
"https://www.kimi.com",
|
|
[
|
|
{ type: "localStorage", key: "access_token" },
|
|
{ type: "cookie", name: "kimi-auth", domain: ".kimi.com" },
|
|
],
|
|
"Log in to Kimi at www.kimi.com. The current access_token will be extracted from localStorage; kimi-auth remains a legacy fallback.",
|
|
{ cookieDomain: ".kimi.com" }
|
|
),
|
|
|
|
// ── Blackbox Web ──────────────────────────────────────────
|
|
config(
|
|
"blackbox-web",
|
|
"Blackbox AI",
|
|
"https://app.blackbox.ai/login",
|
|
"https://app.blackbox.ai",
|
|
[
|
|
{ type: "cookie", name: "connect.sid", domain: ".blackbox.ai" },
|
|
{ type: "localStorage", key: "token" },
|
|
],
|
|
"Log in to Blackbox AI at app.blackbox.ai using Google/GitHub. The session cookie will be extracted.",
|
|
{ cookieDomain: ".blackbox.ai" }
|
|
),
|
|
|
|
// ── Poe Web ───────────────────────────────────────────────
|
|
config(
|
|
"poe-web",
|
|
"Poe (Quora)",
|
|
"https://poe.com/login",
|
|
"https://poe.com",
|
|
[{ type: "cookie", name: "p-b", domain: ".poe.com" }],
|
|
"Log in to Poe at poe.com. The session cookie will be extracted.",
|
|
{ cookieDomain: ".poe.com" }
|
|
),
|
|
|
|
// ── Copilot Web ───────────────────────────────────────────
|
|
config(
|
|
"copilot-web",
|
|
"Microsoft Copilot",
|
|
"https://copilot.microsoft.com/",
|
|
"https://copilot.microsoft.com",
|
|
[{ type: "header", name: "Authorization" }],
|
|
"Log in with your Microsoft account at copilot.microsoft.com. The bearer access token will be extracted from an authenticated request."
|
|
),
|
|
|
|
// ── DuckDuckGo Web ────────────────────────────────────────
|
|
config(
|
|
"duckduckgo-web",
|
|
"DuckDuckGo AI Chat",
|
|
"https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=1",
|
|
"https://duckduckgo.com",
|
|
[{ type: "cookie", name: "duckai", domain: ".duckduckgo.com" }],
|
|
"Open DuckDuckGo AI Chat. Some models may require a free account. The duckai cookie will be extracted.",
|
|
{
|
|
cookieDomain: ".duckduckgo.com",
|
|
pollingConfig: QUICK_POLLING,
|
|
}
|
|
),
|
|
|
|
// ── Dola Web ──────────────────────────────────────────────
|
|
config(
|
|
"doubao-web",
|
|
"Dola (ByteDance)",
|
|
"https://www.dola.com/",
|
|
"https://www.dola.com",
|
|
[
|
|
{ type: "cookie", name: "sessionid", domain: ".dola.com" },
|
|
{ type: "cookie", name: "ttwid", domain: ".dola.com" },
|
|
{ type: "cookie", name: "s_v_web_id", domain: ".dola.com" },
|
|
],
|
|
"Log in to Dola at www.dola.com with your ByteDance account. sessionid, ttwid, and s_v_web_id will be extracted.",
|
|
{ cookieDomain: ".dola.com" }
|
|
),
|
|
|
|
// ── T3 Chat Web ───────────────────────────────────────────
|
|
config(
|
|
"t3-chat-web",
|
|
"T3 Chat",
|
|
"https://t3.chat/login",
|
|
"https://t3.chat",
|
|
[{ type: "localStorage", key: "token" }],
|
|
"Log in to T3 Chat at t3.chat using Google/GitHub. The token from localStorage will be extracted.",
|
|
{ pollingConfig: QUICK_POLLING }
|
|
),
|
|
|
|
// ── Venice Web ────────────────────────────────────────────
|
|
config(
|
|
"venice-web",
|
|
"Venice AI",
|
|
"https://venice.ai/login",
|
|
"https://venice.ai",
|
|
[
|
|
{ type: "cookie", name: "venice_session", domain: ".venice.ai" },
|
|
{ type: "localStorage", key: "token" },
|
|
],
|
|
"Log in to Venice AI at venice.ai. The session cookie will be extracted.",
|
|
{ cookieDomain: ".venice.ai" }
|
|
),
|
|
|
|
// ── v0 Dev Web ────────────────────────────────────────────
|
|
config(
|
|
"v0-vercel-web",
|
|
"v0 by Vercel",
|
|
"https://v0.dev/login",
|
|
"https://v0.dev",
|
|
[{ type: "cookie", name: "__Secure-next-auth.session-token", domain: ".v0.dev" }],
|
|
"Log in to v0.dev with your Vercel/Google/GitHub account. The session cookie will be extracted.",
|
|
{ cookieDomain: ".v0.dev" }
|
|
),
|
|
|
|
// ── Muse / Spark Web ──────────────────────────────────────
|
|
config(
|
|
"muse-spark-web",
|
|
"Meta AI (Muse)",
|
|
"https://www.meta.ai/",
|
|
"https://www.meta.ai",
|
|
[{ type: "cookie", name: "session", domain: ".meta.ai" }],
|
|
"Log in to Meta AI at meta.ai with your Facebook/Instagram account. The session cookie will be extracted.",
|
|
{ cookieDomain: ".meta.ai" }
|
|
),
|
|
|
|
// ── Adapta Web ────────────────────────────────────────────
|
|
config(
|
|
"adapta-web",
|
|
"Adapta AI",
|
|
"https://agent.adapta.one/login",
|
|
"https://agent.adapta.one",
|
|
[{ type: "cookie", name: "__session", domain: ".adapta.one" }],
|
|
"Log in to Adapta at agent.adapta.one. The session token will be extracted.",
|
|
{ cookieDomain: ".adapta.one" }
|
|
),
|
|
|
|
// ── VeoAI Free Web ────────────────────────────────────────
|
|
config(
|
|
"veoaifree-web",
|
|
"VeoAI Free",
|
|
"https://veoaifree.com/",
|
|
"https://veoaifree.com",
|
|
[{ type: "cookie", name: "wordpress_logged_in", domain: ".veoaifree.com" }],
|
|
"Log in to VeoAI Free at veoaifree.com. The WordPress session cookie will be extracted.",
|
|
{
|
|
cookieDomain: ".veoaifree.com",
|
|
pollingConfig: QUICK_POLLING,
|
|
}
|
|
),
|
|
|
|
// ── Missing Provider: ChatGLM (Zhipu) ──────────────────────
|
|
config(
|
|
"chatglm-web",
|
|
"ChatGLM (Zhipu AI)",
|
|
"https://chatglm.cn/",
|
|
"https://chatglm.cn",
|
|
[
|
|
{ type: "cookie", name: "chatglm_session", domain: ".chatglm.cn" },
|
|
{ type: "localStorage", key: "token" },
|
|
],
|
|
"Log in to ChatGLM at chatglm.cn with your phone number. The session token will be extracted.",
|
|
{ cookieDomain: ".chatglm.cn" }
|
|
),
|
|
|
|
// ── Missing Provider: Xiaomi MiMo ──────────────────────────
|
|
config(
|
|
"xiaomimimo-web",
|
|
"Xiaomi MiMo AI Studio",
|
|
"https://aistudio.xiaomimimo.com/login",
|
|
"https://aistudio.xiaomimimo.com",
|
|
[
|
|
{ type: "cookie", name: "session", domain: ".xiaomimimo.com" },
|
|
{ type: "localStorage", key: "access_token" },
|
|
],
|
|
"Log in to Xiaomi MiMo AI Studio at aistudio.xiaomimimo.com. The session token will be extracted.",
|
|
{ cookieDomain: ".xiaomimimo.com" }
|
|
),
|
|
|
|
// ── Missing Provider: Manus ────────────────────────────────
|
|
config(
|
|
"manus-web",
|
|
"Manus AI",
|
|
"https://manus.im/login",
|
|
"https://manus.im",
|
|
[
|
|
{ type: "cookie", name: "manus_session", domain: ".manus.im" },
|
|
{ type: "localStorage", key: "auth_token" },
|
|
],
|
|
"Log in to Manus at manus.im. The session cookie will be extracted.",
|
|
{ cookieDomain: ".manus.im" }
|
|
),
|
|
|
|
// ── Z.ai Web (#4056) ────────────────────────────────────────
|
|
config(
|
|
"zai-web",
|
|
"Z.ai Web",
|
|
"https://chat.z.ai/",
|
|
"https://chat.z.ai",
|
|
[{ type: "localStorage", key: "token" }],
|
|
'Log in to Z.ai at chat.z.ai. OmniRoute extracts the Local Storage value named "token"; chat CAPTCHA is handled by the browser transport.'
|
|
),
|
|
];
|
|
|
|
// ─── Registry ───────────────────────────────────────────────────────────────
|
|
|
|
const CONFIG_MAP = new Map<string, TokenExtractionConfig>();
|
|
|
|
for (const cfg of RAW_CONFIGS) {
|
|
CONFIG_MAP.set(cfg.providerId, cfg);
|
|
}
|
|
|
|
/** Get extraction config for a specific provider */
|
|
export function getExtractionConfig(providerId: string): TokenExtractionConfig | undefined {
|
|
return CONFIG_MAP.get(providerId);
|
|
}
|
|
|
|
/** List all registered extraction configs */
|
|
export function listExtractionConfigs(): TokenExtractionConfig[] {
|
|
return [...RAW_CONFIGS];
|
|
}
|
|
|
|
/** The shared config map — used by LoginManager and InAppLoginService */
|
|
export const TOKEN_EXTRACTION_CONFIGS = CONFIG_MAP;
|