11import { createAppError } from "@ctxport/core-schema" ;
22import type { GeminiRuntimeParams } from "./types" ;
33
4- const BATCH_EXECUTE_ENDPOINT =
5- "https://gemini.google.com/_/BardChatUi/data/batchexecute" ;
4+ const BATCH_EXECUTE_BASE = "https://gemini.google.com" ;
65
76const GEMINI_IMAGE_URL_PATTERN =
87 / ^ h t t p s : \/ \/ l h 3 \. g o o g l e u s e r c o n t e n t \. c o m \/ g g (?: - d l ) ? \/ / ;
@@ -12,12 +11,13 @@ const GEMINI_IMAGE_URL_PATTERN =
1211export async function fetchConversationPayload (
1312 conversationId : string ,
1413 runtimeParams : GeminiRuntimeParams ,
14+ pathPrefix = "" ,
1515) : Promise < unknown > {
1616 const rpcId = "hNvQHb" ;
1717
1818 const query = new URLSearchParams ( {
1919 rpcids : rpcId ,
20- "source-path" : `/app/${ conversationId } ` ,
20+ "source-path" : `${ pathPrefix } /app/${ conversationId } ` ,
2121 bl : runtimeParams . bl ,
2222 "f.sid" : runtimeParams . fSid ,
2323 hl : runtimeParams . hl ,
@@ -29,16 +29,7 @@ export async function fetchConversationPayload(
2929 [
3030 [
3131 rpcId ,
32- JSON . stringify ( [
33- `c_${ conversationId } ` ,
34- 100 ,
35- null ,
36- 1 ,
37- [ 0 ] ,
38- [ 4 ] ,
39- null ,
40- 1 ,
41- ] ) ,
32+ JSON . stringify ( [ `c_${ conversationId } ` , 10 , null , 1 , [ 0 ] , [ 4 ] , null , 1 ] ) ,
4233 null ,
4334 "generic" ,
4435 ] ,
@@ -49,24 +40,22 @@ export async function fetchConversationPayload(
4940 body . set ( "at" , runtimeParams . at ) ;
5041 }
5142
52- const response = await fetch (
53- `${ BATCH_EXECUTE_ENDPOINT } ?${ query . toString ( ) } ` ,
54- {
55- method : "POST" ,
56- mode : "cors" ,
57- credentials : "include" ,
58- cache : "no-store" ,
59- referrer : `https://gemini.google.com/app/${ conversationId } ` ,
60- referrerPolicy : "strict-origin-when-cross-origin" ,
61- headers : {
62- Accept : "*/*" ,
63- "Content-Type" : "application/x-www-form-urlencoded;charset=utf-8" ,
64- Origin : "https://gemini.google.com" ,
65- "X-Same-Domain" : "1" ,
66- } ,
67- body : body . toString ( ) ,
43+ const endpoint = `${ BATCH_EXECUTE_BASE } ${ pathPrefix } /_/BardChatUi/data/batchexecute` ;
44+ const response = await fetch ( `${ endpoint } ?${ query . toString ( ) } ` , {
45+ method : "POST" ,
46+ mode : "cors" ,
47+ credentials : "include" ,
48+ cache : "no-store" ,
49+ referrer : `https://gemini.google.com${ pathPrefix } /app/${ conversationId } ` ,
50+ referrerPolicy : "strict-origin-when-cross-origin" ,
51+ headers : {
52+ Accept : "*/*" ,
53+ "Content-Type" : "application/x-www-form-urlencoded;charset=utf-8" ,
54+ Origin : "https://gemini.google.com" ,
55+ "X-Same-Domain" : "1" ,
6856 } ,
69- ) ;
57+ body : body . toString ( ) ,
58+ } ) ;
7059
7160 if ( ! response . ok ) {
7261 throw createAppError (
0 commit comments