@@ -118,23 +118,33 @@ export default class BingAIClient {
118118 // } else {
119119 // fetchOptions.dispatcher = new Agent({ connect: { timeout: 20_000 } })
120120 // }
121- const response = await fetchBg ( `${ this . options . host } /turing/conversation/create` , fetchOptions )
121+ const response = await fetchBg (
122+ `${ this . options . host } /turing/conversation/create?bundleVersion=1.864.15` ,
123+ fetchOptions ,
124+ )
122125 const body = await response . text ( )
123126 try {
124- return JSON . parse ( body )
127+ const res = JSON . parse ( body )
128+ res . encryptedConversationSignature =
129+ response . headers . get ( 'x-sydney-encryptedconversationsignature' ) ?? null
130+ return res
125131 } catch ( err ) {
126132 throw new Error ( `/turing/conversation/create: failed to parse response body.\n${ body } ` )
127133 }
128134 }
129135
130- async createWebSocketConnection ( ) {
136+ async createWebSocketConnection ( encryptedConversationSignature ) {
131137 return new Promise ( ( resolve , reject ) => {
132138 // let agent
133139 // if (this.options.proxy) {
134140 // agent = new HttpsProxyAgent(this.options.proxy)
135141 // }
136142
137- const ws = new WebSocket ( 'wss://sydney.bing.com/sydney/ChatHub' )
143+ const ws = new WebSocket (
144+ `wss://sydney.bing.com/sydney/ChatHub?sec_access_token=${ encodeURIComponent (
145+ encryptedConversationSignature ,
146+ ) } `,
147+ )
138148
139149 ws . onerror = ( err ) => {
140150 reject ( err )
@@ -201,7 +211,7 @@ export default class BingAIClient {
201211 let {
202212 jailbreakConversationId = false , // set to `true` for the first message to enable jailbreak mode
203213 conversationId,
204- conversationSignature ,
214+ encryptedConversationSignature ,
205215 clientId,
206216 onProgress,
207217 } = opts
@@ -219,13 +229,18 @@ export default class BingAIClient {
219229 onProgress = ( ) => { }
220230 }
221231
222- if ( jailbreakConversationId || ! conversationSignature || ! conversationId || ! clientId ) {
232+ if (
233+ jailbreakConversationId ||
234+ ! encryptedConversationSignature ||
235+ ! conversationId ||
236+ ! clientId
237+ ) {
223238 const createNewConversationResponse = await this . createNewConversation ( )
224239 if ( this . debug ) {
225240 console . debug ( createNewConversationResponse )
226241 }
227242 if (
228- ! createNewConversationResponse . conversationSignature ||
243+ ! createNewConversationResponse . encryptedConversationSignature ||
229244 ! createNewConversationResponse . conversationId ||
230245 ! createNewConversationResponse . clientId
231246 ) {
@@ -240,7 +255,8 @@ export default class BingAIClient {
240255 )
241256 }
242257 // eslint-disable-next-line
243- ; ( { conversationSignature, conversationId, clientId } = createNewConversationResponse )
258+ ; ( { encryptedConversationSignature, conversationId, clientId } =
259+ createNewConversationResponse )
244260 }
245261
246262 // Due to this jailbreak, the AI will occasionally start responding as the user. It only happens rarely (and happens with the non-jailbroken Bing too), but since we are handling conversations ourselves now, we can use this system to ignore the part of the generated message that is replying as the user.
@@ -319,7 +335,7 @@ export default class BingAIClient {
319335 conversation . messages . push ( userMessage )
320336 }
321337
322- const ws = await this . createWebSocketConnection ( )
338+ const ws = await this . createWebSocketConnection ( encryptedConversationSignature )
323339
324340 ws . onerror = ( error ) => {
325341 console . error ( error )
@@ -367,7 +383,7 @@ export default class BingAIClient {
367383 : message ,
368384 messageType : jailbreakConversationId ? 'SearchQuery' : 'Chat' ,
369385 } ,
370- conversationSignature ,
386+ encryptedConversationSignature ,
371387 participant : {
372388 id : clientId ,
373389 } ,
@@ -604,7 +620,7 @@ export default class BingAIClient {
604620
605621 const returnData = {
606622 conversationId,
607- conversationSignature ,
623+ encryptedConversationSignature ,
608624 clientId,
609625 invocationId : invocationId + 1 ,
610626 conversationExpiryTime,
0 commit comments