diff --git a/.changeset/olive-yaks-battle.md b/.changeset/olive-yaks-battle.md new file mode 100644 index 00000000..5a3937ce --- /dev/null +++ b/.changeset/olive-yaks-battle.md @@ -0,0 +1,6 @@ +--- +"@livekit/agents": patch +"@livekit/agents-plugin-openai": patch +--- + +make sure rejects return errors, not string diff --git a/agents/src/multimodal/multimodal_agent.ts b/agents/src/multimodal/multimodal_agent.ts index 3bdf2d31..0e12d93d 100644 --- a/agents/src/multimodal/multimodal_agent.ts +++ b/agents/src/multimodal/multimodal_agent.ts @@ -129,7 +129,7 @@ export class MultimodalAgent { ): Promise { return new Promise(async (resolve, reject) => { if (this.#started) { - reject('MultimodalAgent already started'); + reject(new Error('MultimodalAgent already started')); } this.#updateState(); diff --git a/agents/src/worker.ts b/agents/src/worker.ts index f020fda2..95e47ad7 100644 --- a/agents/src/worker.ts +++ b/agents/src/worker.ts @@ -323,7 +323,7 @@ export class Worker { await new Promise((resolve, reject) => { this.#session!.on('open', resolve); this.#session!.on('error', (error) => reject(error)); - this.#session!.on('close', (code) => reject(`WebSocket returned ${code}`)); + this.#session!.on('close', (code) => reject(new Error(`WebSocket returned ${code}`))); }); retries = 0; diff --git a/plugins/openai/src/realtime/realtime_model.ts b/plugins/openai/src/realtime/realtime_model.ts index cd13e5db..b0c8039e 100644 --- a/plugins/openai/src/realtime/realtime_model.ts +++ b/plugins/openai/src/realtime/realtime_model.ts @@ -458,7 +458,7 @@ export class RealtimeSession extends multimodal.RealtimeSession { }); this.#ws.onerror = (error) => { - reject(error.message); + reject(error); }; await once(this.#ws, 'open'); @@ -576,7 +576,7 @@ export class RealtimeSession extends multimodal.RealtimeSession { this.#closing = true; } if (!this.#closing) { - reject('OpenAI Realtime connection closed unexpectedly'); + reject(new Error('OpenAI Realtime connection closed unexpectedly')); } this.#ws = null; resolve();