(text: string, options: ChatAPIOptions)
| 41 | super(credential); |
| 42 | } |
| 43 | |
| 44 | async sendMessage(text: string, options: ChatAPIOptions) { |
| 45 | if (!this.session) |
| 46 | await this.#createConversation(options); |
| 47 | this.#lastContentLength = 0; |
| 48 | this.#lastLinks = null; |
| 49 | |
| 50 | const ws = new WebSocket(sydneyWebSocketURL); |
| 51 | |
| 52 | // Handle abort signals. |
| 53 | const handler = ws.terminate.bind(ws); |
| 54 | if (options.signal) |
| 55 | options.signal.addEventListener('abort', handler); |
| 56 | |
| 57 | try { |
| 58 | await this.#createWebSocketConnection(ws, options); |
| 59 | await this.#sendMessageToWebSocket(ws, text, options); |
| 60 | ws.close(); |
| 61 | } catch (error) { |
| 62 | ws.terminate(); |
| 63 | throw error; |
| 64 | } finally { |
| 65 | if (options.signal) |
| 66 | options.signal.removeEventListener('abort', handler); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | async #createConversation(options) { |
no test coverage detected