| 67 | } |
| 68 | } |
| 69 | |
| 70 | async #createConversation(options) { |
| 71 | const response = await fetch(bingChatURL, { |
| 72 | signal: options.signal, |
| 73 | headers: { |
| 74 | ...edgeBrowserHeaders, |
| 75 | cookie: this.credential.cookie, |
| 76 | }, |
| 77 | }); |
| 78 | const body = await response.json(); |
| 79 | if (!body.result) |
| 80 | throw new APIError(`Invalid response when creating conversation: ${body}`); |
| 81 | if (body.result.value != 'Success') { |
| 82 | if (body.result.value == 'UnauthorizedRequest') |
| 83 | throw new APIError(body.result.message, 'refresh'); |
| 84 | throw new APIError(`Unable to create conversation: ${body.result.value} - ${body.result.message}`); |
| 85 | } |
| 86 | this.session = body as SessionData; |
| 87 | this.session.invocationId = 0; |
| 88 | } |
| 89 | |
| 90 | #createWebSocketConnection(ws: WebSocket, options): Promise<void> { |