File size: 8,103 Bytes
923b5bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | import { WEB_COOKIE_PROVIDERS } from "@/shared/constants/providers";
export type WebSessionCredentialRequirement =
| {
kind: "cookie" | "token";
credentialName: string;
placeholder: string;
acceptsFullCookieHeader: boolean;
storageKeys: readonly string[];
}
| {
kind: "none";
credentialName: "";
placeholder: "";
acceptsFullCookieHeader: false;
storageKeys: readonly [];
};
export const WEB_SESSION_CREDENTIAL_REQUIREMENTS = {
"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"],
},
"t3-web": {
kind: "cookie",
credentialName: "convex-session-id + Cookie header",
placeholder: "convex-session-id=abc123...; Cookie: ...",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "convex-session-id", "convexSessionId"],
},
"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: "hf-chat",
placeholder: "hf-chat=... or full Cookie header from huggingface.co",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "hf-chat"],
},
phind: {
kind: "cookie",
credentialName: "phind_session",
placeholder: "phind_session=... or full Cookie header from phind.com",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "phind_session"],
},
"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: "session",
placeholder: "session=... or full Cookie header from kimi.moonshot.cn",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "session"],
},
"doubao-web": {
kind: "cookie",
credentialName: "session",
placeholder: "session=... or full Cookie header from doubao.com",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "session"],
},
"qwen-web": {
kind: "token",
credentialName: "token",
placeholder: "Paste your Qwen token from chat.qwen.ai (Local Storage → token)",
acceptsFullCookieHeader: false,
storageKeys: ["token", "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",
credentialName: "session",
placeholder: "session=... or full Cookie header from lmarena.ai",
acceptsFullCookieHeader: true,
storageKeys: ["cookie", "session"],
},
} 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]));
}
|