feat: add support for Grok Web and Perplexity Web providers
This commit is contained in:
1 parent
eeb2dc9e30
commit
abb04c5366
17 files changed
+1583
-13
No files matched your search
@@ -516,6 +516,39 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
|
||||
const res = await fetchWithConnectionProxy("https://llm.chutes.ai/v1/models", { headers: { Authorization: `Bearer ${connection.apiKey}` } }, effectiveProxy);
|
||||
return { valid: res.ok, error: res.ok ? null : "Invalid API key" };
|
||||
}
|
||||
case "grok-web": {
|
||||
const token = connection.apiKey.startsWith("sso=") ? connection.apiKey.slice(4) : connection.apiKey;
|
||||
const randomHex = (n) => Array.from(crypto.getRandomValues(new Uint8Array(n)), (b) => b.toString(16).padStart(2, "0")).join("");
|
||||
const statsigId = Buffer.from("e:TypeError: Cannot read properties of null (reading 'children')").toString("base64");
|
||||
const res = await fetchWithConnectionProxy("https://grok.com/rest/app-chat/conversations/new", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "*/*", "Content-Type": "application/json",
|
||||
Cookie: `sso=${token}`, Origin: "https://grok.com", Referer: "https://grok.com/",
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
||||
"x-statsig-id": statsigId, "x-xai-request-id": crypto.randomUUID(),
|
||||
traceparent: `00-${randomHex(16)}-${randomHex(8)}-00`,
|
||||
},
|
||||
body: JSON.stringify({ temporary: true, modelName: "grok-4", message: "ping", fileAttachments: [], imageAttachments: [], disableSearch: false, enableImageGeneration: false, sendFinalMetadata: true }),
|
||||
}, effectiveProxy);
|
||||
const valid = res.status !== 401 && res.status !== 403;
|
||||
return { valid, error: valid ? null : "Invalid SSO cookie" };
|
||||
}
|
||||
case "perplexity-web": {
|
||||
let sessionToken = connection.apiKey;
|
||||
if (sessionToken.startsWith("__Secure-next-auth.session-token=")) sessionToken = sessionToken.slice("__Secure-next-auth.session-token=".length);
|
||||
const res = await fetchWithConnectionProxy("https://www.perplexity.ai/api/auth/session", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
||||
Cookie: `__Secure-next-auth.session-token=${sessionToken}`,
|
||||
},
|
||||
}, effectiveProxy);
|
||||
if (!res.ok) return { valid: false, error: "Invalid session cookie" };
|
||||
const data = await res.json().catch(() => null);
|
||||
const valid = !!(data && data.user);
|
||||
return { valid, error: valid ? null : "Session expired — re-paste cookie" };
|
||||
}
|
||||
default:
|
||||
return { valid: false, error: "Provider test not supported" };
|
||||
}
|
||||
@@ -549,7 +582,7 @@ export async function testSingleConnection(id) {
|
||||
const start = Date.now();
|
||||
let result;
|
||||
|
||||
if (connection.authType === "apikey") {
|
||||
if (connection.authType === "apikey" || connection.authType === "cookie") {
|
||||
result = await testApiKeyConnection(connection, effectiveProxy);
|
||||
} else {
|
||||
result = await testOAuthConnection(connection, effectiveProxy);
|
||||
|
||||
Reference in new issue
Block a user