@@ -118,23 +118,33 @@ export default class BingAIClient {
118
118
// } else {
119
119
// fetchOptions.dispatcher = new Agent({ connect: { timeout: 20_000 } })
120
120
// }
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
+ )
122
125
const body = await response . text ( )
123
126
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
125
131
} catch ( err ) {
126
132
throw new Error ( `/turing/conversation/create: failed to parse response body.\n${ body } ` )
127
133
}
128
134
}
129
135
130
- async createWebSocketConnection ( ) {
136
+ async createWebSocketConnection ( encryptedConversationSignature ) {
131
137
return new Promise ( ( resolve , reject ) => {
132
138
// let agent
133
139
// if (this.options.proxy) {
134
140
// agent = new HttpsProxyAgent(this.options.proxy)
135
141
// }
136
142
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
+ )
138
148
139
149
ws . onerror = ( err ) => {
140
150
reject ( err )
@@ -201,7 +211,7 @@ export default class BingAIClient {
201
211
let {
202
212
jailbreakConversationId = false , // set to `true` for the first message to enable jailbreak mode
203
213
conversationId,
204
- conversationSignature ,
214
+ encryptedConversationSignature ,
205
215
clientId,
206
216
onProgress,
207
217
} = opts
@@ -219,13 +229,18 @@ export default class BingAIClient {
219
229
onProgress = ( ) => { }
220
230
}
221
231
222
- if ( jailbreakConversationId || ! conversationSignature || ! conversationId || ! clientId ) {
232
+ if (
233
+ jailbreakConversationId ||
234
+ ! encryptedConversationSignature ||
235
+ ! conversationId ||
236
+ ! clientId
237
+ ) {
223
238
const createNewConversationResponse = await this . createNewConversation ( )
224
239
if ( this . debug ) {
225
240
console . debug ( createNewConversationResponse )
226
241
}
227
242
if (
228
- ! createNewConversationResponse . conversationSignature ||
243
+ ! createNewConversationResponse . encryptedConversationSignature ||
229
244
! createNewConversationResponse . conversationId ||
230
245
! createNewConversationResponse . clientId
231
246
) {
@@ -240,7 +255,8 @@ export default class BingAIClient {
240
255
)
241
256
}
242
257
// eslint-disable-next-line
243
- ; ( { conversationSignature, conversationId, clientId } = createNewConversationResponse )
258
+ ; ( { encryptedConversationSignature, conversationId, clientId } =
259
+ createNewConversationResponse )
244
260
}
245
261
246
262
// 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 {
319
335
conversation . messages . push ( userMessage )
320
336
}
321
337
322
- const ws = await this . createWebSocketConnection ( )
338
+ const ws = await this . createWebSocketConnection ( encryptedConversationSignature )
323
339
324
340
ws . onerror = ( error ) => {
325
341
console . error ( error )
@@ -367,7 +383,7 @@ export default class BingAIClient {
367
383
: message ,
368
384
messageType : jailbreakConversationId ? 'SearchQuery' : 'Chat' ,
369
385
} ,
370
- conversationSignature ,
386
+ encryptedConversationSignature ,
371
387
participant : {
372
388
id : clientId ,
373
389
} ,
@@ -604,7 +620,7 @@ export default class BingAIClient {
604
620
605
621
const returnData = {
606
622
conversationId,
607
- conversationSignature ,
623
+ encryptedConversationSignature ,
608
624
clientId,
609
625
invocationId : invocationId + 1 ,
610
626
conversationExpiryTime,
0 commit comments