From 8f96b10b40ac92ef0c167096b44ae4533bb53a47 Mon Sep 17 00:00:00 2001 From: oyi77 Date: Sun, 2 Aug 2026 00:37:04 -0300 Subject: [PATCH] fix(sse): resolve type errors in browserBackedChat stub Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --- open-sse/services/browserBackedChat.ts | 50 ++++++++++++++++++++------ open-sse/utils/tlsClient.ts | 1 + 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/open-sse/services/browserBackedChat.ts b/open-sse/services/browserBackedChat.ts index 52e4497851..3578035788 100644 --- a/open-sse/services/browserBackedChat.ts +++ b/open-sse/services/browserBackedChat.ts @@ -38,14 +38,25 @@ export interface BrowserBackedChatResult { } // ===================== MODULE PROXY ===================== export interface BrowserPoolModule { - tryBackedChat(req: TryBackedChatRequest, signal?: AbortSignal): Promise; - browserBackedChat(req: BrowserBackedChatRequest): Promise; - getFreshCookiesWithWarmup(req: CookieRefreshRequest): Promise; - getCachedCookies(domain: string): Promise; - setCachedCookies(domain: string, cookies: CookieStore): Promise; - clearCookieCache(domain?: string): Promise; + browserBackedChat(req: BrowserBackedChatRequest): Promise; + startBrowserWarmup( + poolKey: string, + chatPageUrl: string, + cookieDomain: string, + signal: AbortSignal | null + ): Promise; + getFreshCookiesWithWarmup( + chatUrl: string, + chatPageUrl: string, + cookieDomain: string, + poolKey: string, + signal: AbortSignal | null + ): Promise; + getCachedCookies(domain: string): string | null; + setCachedCookies(domain: string, cookieString: string, ttlMs?: number): void; + clearCookieCache(): void; shouldUseGrokBrowserBacked(): boolean; - setProxyResolver(fn: ProxyResolver): void; + setProxyResolver(fn: (providerKey: string) => Promise): void; } let modPromise: Promise | null = null; function getMod(): Promise { @@ -66,13 +77,13 @@ const COOKIE_POLL_TIMEOUT_MS = 5 * 1000; async function getCachedCookies(domain: string | undefined): Promise { const mod = await getMod(); if (!mod) return undefined; - return mod.getCachedCookies(domain); + return mod.getCachedCookies(domain ?? "") ?? undefined; } async function setCachedCookies(domain: string | undefined, cookies: string): Promise { if (!domain) return; const mod = await getMod(); - if (mod) await mod.setCachedCookies(domain, cookies); + if (mod) mod.setCachedCookies(domain, cookies); } export async function clearCookieCache(): Promise { @@ -254,7 +265,18 @@ export async function tryBackedChat( const mod = getMod(); // Start browser warmup in parallel - mod.then((m) => m?.startBrowserWarmup?.().catch(() => {})).catch(() => {}); + mod + .then((m) => + m + ?.startBrowserWarmup?.( + req.poolKey, + req.chatPageUrl ?? req.chatUrl, + req.cookieDomain ?? "", + req.signal ?? null + ) + .catch(() => {}) + ) + .catch(() => {}); // Try HTTP path first try { @@ -279,7 +301,13 @@ export async function tryBackedChat( // Get fresh cookies via browser (delegated — null check is safe) if (loaded) { try { - const fresh = await loaded.getFreshCookiesWithWarmup(req); + const fresh = await loaded.getFreshCookiesWithWarmup( + req.chatUrl, + req.chatPageUrl ?? req.chatUrl, + req.cookieDomain ?? "", + req.poolKey, + req.signal ?? null + ); if (fresh) { if (req.cookieDomain) await setCachedCookies(req.cookieDomain, fresh); const retry = await httpBackedChat({ ...req, cookieString: fresh }); diff --git a/open-sse/utils/tlsClient.ts b/open-sse/utils/tlsClient.ts index c2b41521d0..73ba3216e9 100644 --- a/open-sse/utils/tlsClient.ts +++ b/open-sse/utils/tlsClient.ts @@ -40,6 +40,7 @@ interface FetchOptions { body?: unknown; redirect?: string; signal?: AbortSignal; + fingerprint?: { userAgent: string; secChUa: string; secChUaPlatform: string }; } function normalizeHeaders(headers: HeadersInit | undefined): Record | undefined {