Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/realtime-url-configurable.md

This file was deleted.

14 changes: 4 additions & 10 deletions packages/agents-realtime/src/openaiRealtimeWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export type OpenAIRealtimeWebSocketOptions = {
* @see https://platform.openai.com/docs/guides/realtime#creating-an-ephemeral-token
*/
useInsecureApiKey?: boolean;
/**
* The URL to use for the WebSocket connection.
*/
url?: string;
} & OpenAIRealtimeBaseOptions;

/**
Expand All @@ -63,7 +59,7 @@ export class OpenAIRealtimeWebSocket
implements RealtimeTransportLayer
{
#apiKey: string | undefined;
#url: string | undefined;
#url: string;
#state: WebSocketState = {
status: 'disconnected',
websocket: undefined,
Expand All @@ -84,7 +80,7 @@ export class OpenAIRealtimeWebSocket

constructor(options: OpenAIRealtimeWebSocketOptions = {}) {
super(options);
this.#url = options.url;
this.#url = `wss://api.openai.com/v1/realtime?model=${this.currentModel}`;
this.#useInsecureApiKey = options.useInsecureApiKey ?? false;
}

Expand Down Expand Up @@ -173,7 +169,7 @@ export class OpenAIRealtimeWebSocket
},
};

const ws = new WebSocket(this.#url!, websocketArguments as any);
const ws = new WebSocket(this.#url, websocketArguments as any);
this.#state = {
status: 'connecting',
websocket: ws,
Expand Down Expand Up @@ -264,11 +260,9 @@ export class OpenAIRealtimeWebSocket
const model = options.model ?? this.currentModel;
this.currentModel = model;
this.#apiKey = await this._getApiKey(options);
const url =
this.#url =
options.url ??
this.#url ??
`wss://api.openai.com/v1/realtime?model=${this.currentModel}`;
this.#url = url;

const sessionConfig: Partial<RealtimeSessionConfig> = {
...(options.initialSessionConfig || {}),
Expand Down
1 change: 0 additions & 1 deletion packages/agents-realtime/src/realtimeSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ export class RealtimeSession<
await this.#transport.connect({
apiKey: options.apiKey ?? this.options.apiKey,
model: this.options.model,
url: options.url,
initialSessionConfig: await this.#getSessionConfig(this.options.config),
});

Expand Down
8 changes: 0 additions & 8 deletions packages/agents-realtime/test/openaiRealtimeWebsocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ describe('OpenAIRealtimeWebSocket', () => {
expect(statuses).toEqual(['connecting', 'connected']);
});

it('uses custom url from constructor', async () => {
const ws = new OpenAIRealtimeWebSocket({ url: 'ws://test' });
const p = ws.connect({ apiKey: 'ek_test', model: 'm' });
await vi.runAllTimersAsync();
await p;
expect(lastFakeSocket!.url).toBe('ws://test');
});

it('handles audio delta, speech started and created/done events', async () => {
const ws = new OpenAIRealtimeWebSocket();
const audioSpy = vi.fn();
Expand Down
8 changes: 0 additions & 8 deletions packages/agents-realtime/test/realtimeSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,6 @@ describe('RealtimeSession', () => {
expect(transport.closeCalls).toBe(1);
});

it('forwards url in connect options to transport', async () => {
const t = new FakeTransport();
const agent = new RealtimeAgent({ name: 'A', handoffs: [] });
const s = new RealtimeSession(agent, { transport: t });
await s.connect({ apiKey: 'test', url: 'ws://example' });
expect(t.connectCalls[0]?.url).toBe('ws://example');
});

it('updateHistory accepts callback', () => {
const item = createMessage('1', 'hi');
session.updateHistory([item]);
Expand Down