@livekit/agents-plugin-openai 1.7.1 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/realtime/gpt_live_model.cjs +883 -0
- package/dist/realtime/gpt_live_model.cjs.map +1 -0
- package/dist/realtime/gpt_live_model.d.cts +183 -0
- package/dist/realtime/gpt_live_model.d.ts +183 -0
- package/dist/realtime/gpt_live_model.d.ts.map +1 -0
- package/dist/realtime/gpt_live_model.js +859 -0
- package/dist/realtime/gpt_live_model.js.map +1 -0
- package/dist/realtime/gpt_live_model.test.cjs +1397 -0
- package/dist/realtime/gpt_live_model.test.cjs.map +1 -0
- package/dist/realtime/gpt_live_model.test.d.cts +2 -0
- package/dist/realtime/gpt_live_model.test.d.ts +2 -0
- package/dist/realtime/gpt_live_model.test.d.ts.map +1 -0
- package/dist/realtime/gpt_live_model.test.js +1398 -0
- package/dist/realtime/gpt_live_model.test.js.map +1 -0
- package/dist/realtime/gpt_live_types.cjs +17 -0
- package/dist/realtime/gpt_live_types.cjs.map +1 -0
- package/dist/realtime/gpt_live_types.d.cts +170 -0
- package/dist/realtime/gpt_live_types.d.ts +170 -0
- package/dist/realtime/gpt_live_types.d.ts.map +1 -0
- package/dist/realtime/gpt_live_types.js +1 -0
- package/dist/realtime/gpt_live_types.js.map +1 -0
- package/dist/realtime/index.cjs +22 -1
- package/dist/realtime/index.cjs.map +1 -1
- package/dist/realtime/index.d.cts +2 -0
- package/dist/realtime/index.d.ts +2 -0
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +5 -0
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/realtime_model.cjs +4 -1
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +4 -1
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/realtime/realtime_model.test.cjs +29 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -1
- package/dist/realtime/realtime_model.test.js +29 -0
- package/dist/realtime/realtime_model.test.js.map +1 -1
- package/dist/responses/llm.cjs +10 -0
- package/dist/responses/llm.cjs.map +1 -1
- package/dist/responses/llm.d.ts.map +1 -1
- package/dist/responses/llm.js +10 -0
- package/dist/responses/llm.js.map +1 -1
- package/dist/responses/llm.test.cjs +51 -0
- package/dist/responses/llm.test.cjs.map +1 -1
- package/dist/responses/llm.test.js +52 -1
- package/dist/responses/llm.test.js.map +1 -1
- package/dist/tool_utils.cjs +12 -8
- package/dist/tool_utils.cjs.map +1 -1
- package/dist/tool_utils.d.cts +1 -0
- package/dist/tool_utils.d.ts +1 -0
- package/dist/tool_utils.d.ts.map +1 -1
- package/dist/tool_utils.js +11 -8
- package/dist/tool_utils.js.map +1 -1
- package/dist/tool_utils.test.cjs +27 -0
- package/dist/tool_utils.test.cjs.map +1 -1
- package/dist/tool_utils.test.js +27 -0
- package/dist/tool_utils.test.js.map +1 -1
- package/dist/ws/llm.cjs +25 -7
- package/dist/ws/llm.cjs.map +1 -1
- package/dist/ws/llm.d.cts +2 -2
- package/dist/ws/llm.d.ts +2 -2
- package/dist/ws/llm.d.ts.map +1 -1
- package/dist/ws/llm.js +25 -7
- package/dist/ws/llm.js.map +1 -1
- package/dist/ws/llm.test.cjs +117 -0
- package/dist/ws/llm.test.cjs.map +1 -1
- package/dist/ws/llm.test.js +126 -3
- package/dist/ws/llm.test.js.map +1 -1
- package/dist/ws/types.cjs +12 -0
- package/dist/ws/types.cjs.map +1 -1
- package/dist/ws/types.d.cts +18 -0
- package/dist/ws/types.d.ts +18 -0
- package/dist/ws/types.d.ts.map +1 -1
- package/dist/ws/types.js +11 -0
- package/dist/ws/types.js.map +1 -1
- package/package.json +5 -5
- package/src/realtime/gpt_live_model.test.ts +1458 -0
- package/src/realtime/gpt_live_model.ts +1032 -0
- package/src/realtime/gpt_live_types.ts +140 -0
- package/src/realtime/index.ts +2 -0
- package/src/realtime/realtime_model.test.ts +32 -0
- package/src/realtime/realtime_model.ts +4 -1
- package/src/responses/llm.test.ts +55 -1
- package/src/responses/llm.ts +10 -0
- package/src/tool_utils.test.ts +30 -0
- package/src/tool_utils.ts +21 -18
- package/src/ws/llm.test.ts +141 -5
- package/src/ws/llm.ts +29 -8
- package/src/ws/types.ts +17 -0
package/dist/ws/llm.test.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ChatContext, ConnectionPool, initializeLogger, stream } from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { describe, expect, it } from 'vitest';\nimport { LLM } from '../responses/llm.js';\nimport type { ResponsesWebSocket } from './llm.js';\nimport { WSLLM, WSLLMStream, buildResponsesWsUrl } from './llm.js';\nimport type { WsServerEvent } from './types.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\nconst hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);\n\ndescribe('buildResponsesWsUrl', () => {\n it('points at the OpenAI Responses WS endpoint without model when no baseURL is set', () => {\n const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('rewrites https baseURL to wss and appends /responses with the model', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('rewrites full https Responses endpoint to wss without duplicating /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('uses full wss Responses endpoint with the model', () => {\n const url = new URL(buildResponsesWsUrl('wss://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('omits the model when an explicit baseURL still points at api.openai.com', () => {\n const url = new URL(buildResponsesWsUrl('https://api.openai.com/v1', 'gpt-4.1'));\n\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('strips a trailing slash on baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('rewrites http baseURL to ws (not wss)', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('strips a trailing slash on an http baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n});\n\n// opens every stream, on every provider\nconst RESPONSE_CREATED: WsServerEvent = {\n type: 'response.created',\n response: { id: 'resp_1' },\n};\n\n// a reasoning phase marker: a message item with no text of its own\nconst PHASE_METADATA: WsServerEvent = {\n type: 'response.output_item.done',\n item: { type: 'message', phase: 'thinking' },\n};\n\nconst TEXT_DELTA: WsServerEvent = {\n type: 'response.output_text.delta',\n delta: 'hello',\n};\n\n/** Replays the given frames, then dies the way a socket going quiet does. */\nclass StallingConnection {\n attempts = 0;\n\n constructor(private readonly frames: WsServerEvent[]) {}\n\n sendRequest(): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n const channel = stream.createStreamChannel<WsServerEvent>();\n\n void (async () => {\n for (const frame of this.frames) {\n await channel.write(frame);\n }\n await channel.abort(new Error('stalled mid-stream'));\n })();\n\n return channel;\n }\n\n close(): void {}\n}\n\n/** Returns how many times the response was requested before the stream gave up. */\nasync function attemptsUntilStall(frames: WsServerEvent[], maxRetry: number): Promise<number> {\n const wsLLM = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n // the stream emits 'error' on every failed attempt; without a listener the\n // EventEmitter turns it into an unhandled error and fails the run\n wsLLM.on('error', () => {});\n\n const conn = new StallingConnection(frames);\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => conn as unknown as ResponsesWebSocket,\n });\n\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n\n const llmStream = new WSLLMStream(wsLLM, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n try {\n for await (const _chunk of llmStream) {\n void _chunk;\n }\n } catch {\n // the stall surfaces through the 'error' event; the iterator just ends\n }\n\n return conn.attempts;\n}\n\ndescribe('OpenAI Responses WS retry eligibility', () => {\n it('retries a stall that follows the stream-opening frame alone', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED], 2)).toBe(3);\n });\n\n it('retries a stall that follows a phase marker', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, PHASE_METADATA], 2)).toBe(3);\n });\n\n it('does not retry once generated text has reached the caller', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, TEXT_DELTA], 2)).toBe(1);\n });\n});\n\nif (hasOpenAIApiKey) {\n describe('OpenAI Responses WS wrapper', async () => {\n await llm(\n new LLM({\n temperature: 0,\n strictToolSchema: false,\n useWebSocket: true,\n }),\n true,\n );\n });\n\n describe('OpenAI Responses WS wrapper strict tool schema', async () => {\n await llmStrict(\n new LLM({\n temperature: 0,\n strictToolSchema: true,\n useWebSocket: true,\n }),\n );\n });\n} else {\n describe('OpenAI Responses WS wrapper', () => {\n it.skip('requires OPENAI_API_KEY', () => {});\n });\n}\n"],"mappings":";AAGA,oBAAsE;AACtE,iCAA+B;AAC/B,oBAAqC;AACrC,iBAAoB;AAEpB,IAAAA,cAAwD;AAAA,IAGxD,gCAAiB,EAAE,OAAO,UAAU,QAAQ,MAAM,CAAC;AAEnD,MAAM,kBAAkB,QAAQ,QAAQ,IAAI,cAAc;AAAA,IAE1D,wBAAS,uBAAuB,MAAM;AACpC,wBAAG,mFAAmF,MAAM;AAC1F,UAAM,MAAM,IAAI,QAAI,iCAAoB,QAAW,SAAS,CAAC;AAE7D,8BAAO,IAAI,QAAQ,EAAE,KAAK,MAAM;AAChC,8BAAO,IAAI,IAAI,EAAE,KAAK,gBAAgB;AACtC,8BAAO,IAAI,QAAQ,EAAE,KAAK,eAAe;AACzC,8BAAO,IAAI,aAAa,IAAI,OAAO,CAAC,EAAE,KAAK,IAAI;AAAA,EACjD,CAAC;AAED,wBAAG,uEAAuE,MAAM;AAC9E,UAAM,MAAM,IAAI,QAAI,iCAAoB,kCAAkC,QAAQ,CAAC;AAEnF,8BAAO,IAAI,QAAQ,EAAE,KAAK,MAAM;AAChC,8BAAO,IAAI,IAAI,EAAE,KAAK,qBAAqB;AAC3C,8BAAO,IAAI,QAAQ,EAAE,KAAK,eAAe;AACzC,8BAAO,IAAI,aAAa,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ;AAAA,EACrD,CAAC;AAED,wBAAG,gFAAgF,MAAM;AACvF,UAAM,MAAM,IAAI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S,+BAA+B,MAAM;AAC5C,qBAAG,KAAK,2BAA2B,MAAM;AAAA,IAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":["import_llm"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {\n APIStatusError,\n ChatContext,\n ConnectionPool,\n initializeLogger,\n stream,\n} from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { EventEmitter } from 'node:events';\nimport { describe, expect, it, vi } from 'vitest';\nimport { LLM } from '../responses/llm.js';\nimport { ResponsesWebSocket, WSLLM, WSLLMStream, buildResponsesWsUrl } from './llm.js';\nimport type { WsResponseCreateEvent, WsServerEvent } from './types.js';\nimport { wsServerEventSchema } from './types.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\nconst hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);\n\ndescribe('buildResponsesWsUrl', () => {\n it('points at the OpenAI Responses WS endpoint without model when no baseURL is set', () => {\n const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('rewrites https baseURL to wss and appends /responses with the model', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('rewrites full https Responses endpoint to wss without duplicating /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('uses full wss Responses endpoint with the model', () => {\n const url = new URL(buildResponsesWsUrl('wss://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('omits the model when an explicit baseURL still points at api.openai.com', () => {\n const url = new URL(buildResponsesWsUrl('https://api.openai.com/v1', 'gpt-4.1'));\n\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('strips a trailing slash on baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('rewrites http baseURL to ws (not wss)', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('strips a trailing slash on an http baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n});\n\n// opens every stream, on every provider\nconst RESPONSE_CREATED: WsServerEvent = {\n type: 'response.created',\n response: { id: 'resp_1' },\n};\n\n// a reasoning phase marker: a message item with no text of its own\nconst PHASE_METADATA: WsServerEvent = {\n type: 'response.output_item.done',\n item: { type: 'message', phase: 'thinking' },\n};\n\nconst TEXT_DELTA: WsServerEvent = {\n type: 'response.output_text.delta',\n delta: 'hello',\n};\n\nfunction responseIncomplete(reason?: string): WsServerEvent {\n return {\n type: 'response.incomplete',\n response: {\n id: 'resp_1',\n incomplete_details: reason === undefined ? {} : { reason },\n },\n };\n}\n\ndescribe('OpenAI Responses WS incomplete events', () => {\n it.each(['max_output_tokens', 'content_filter'])('parses the provider reason %s', (reason) => {\n const parsed = wsServerEventSchema.parse(responseIncomplete(reason));\n\n expect(parsed.type).toBe('response.incomplete');\n if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');\n expect(parsed.response.incomplete_details?.reason).toBe(reason);\n });\n\n it('accepts incomplete details without a reason', () => {\n const parsed = wsServerEventSchema.parse({\n type: 'response.incomplete',\n response: { id: 'resp_1', incomplete_details: {} },\n });\n\n expect(parsed.type).toBe('response.incomplete');\n if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');\n expect(parsed.response.incomplete_details?.reason).toBeUndefined();\n });\n\n it('closes the request channel after the terminal frame', async () => {\n class RecordingSocket extends EventEmitter {\n readyState = 1;\n sent: string[] = [];\n\n send(data: string): void {\n this.sent.push(data);\n }\n\n close(): void {}\n }\n\n const socket = new RecordingSocket();\n const transport = new ResponsesWebSocket(socket as never);\n const channel = transport.sendRequest({\n type: 'response.create',\n model: 'gpt-4.1',\n input: [],\n });\n\n socket.emit('message', Buffer.from(JSON.stringify(responseIncomplete())));\n const events = [];\n for await (const event of channel.stream()) events.push(event);\n\n expect(events).toEqual([responseIncomplete()]);\n expect(socket.sent).toHaveLength(1);\n });\n});\n\n/** Replays the given frames, then dies the way a socket going quiet does. */\nclass StallingConnection {\n attempts = 0;\n\n constructor(private readonly frames: WsServerEvent[]) {}\n\n sendRequest(): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n const channel = stream.createStreamChannel<WsServerEvent>();\n\n void (async () => {\n for (const frame of this.frames) {\n await channel.write(frame);\n }\n await channel.abort(new Error('stalled mid-stream'));\n })();\n\n return channel;\n }\n\n close(): void {}\n}\n\n/** Returns how many times the response was requested before the stream gave up. */\nasync function attemptsUntilStall(frames: WsServerEvent[], maxRetry: number): Promise<number> {\n const wsLLM = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n // the stream emits 'error' on every failed attempt; without a listener the\n // EventEmitter turns it into an unhandled error and fails the run\n wsLLM.on('error', () => {});\n\n const conn = new StallingConnection(frames);\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => conn as unknown as ResponsesWebSocket,\n });\n\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n\n const llmStream = new WSLLMStream(wsLLM, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n try {\n for await (const _chunk of llmStream) {\n void _chunk;\n }\n } catch {\n // the stall surfaces through the 'error' event; the iterator just ends\n }\n\n return conn.attempts;\n}\n\ndescribe('OpenAI Responses WS retry eligibility', () => {\n it('retries a stall that follows the stream-opening frame alone', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED], 2)).toBe(3);\n });\n\n it('retries a stall that follows a phase marker', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, PHASE_METADATA], 2)).toBe(3);\n });\n\n it('does not retry once generated text has reached the caller', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, TEXT_DELTA], 2)).toBe(1);\n });\n});\n\ndescribe('OpenAI Responses WS incomplete handling', () => {\n it.each([\n ['max_output_tokens', 'max_output_tokens'],\n [undefined, 'reason unavailable'],\n ] as const)(\n 'surfaces %s as non-retryable without updating context',\n async (reason, expectedMessage) => {\n class ReplayConnection {\n attempts = 0;\n payloads: WsResponseCreateEvent[] = [];\n\n sendRequest(payload: WsResponseCreateEvent): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n this.payloads.push(payload);\n const channel = stream.createStreamChannel<WsServerEvent>();\n void (async () => {\n await channel.write(RESPONSE_CREATED);\n await channel.write(responseIncomplete(reason));\n await channel.close();\n })();\n return channel;\n }\n\n close(): void {}\n }\n\n const model = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n const onCompleted = vi.spyOn(model, '_onResponseCompleted');\n const errorEvent = new Promise<Error>((resolve) => {\n model.once('error', (event) => resolve(event.error));\n });\n const conn = new ReplayConnection();\n let connectCalls = 0;\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => {\n connectCalls++;\n return conn as unknown as ResponsesWebSocket;\n },\n });\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n const llmStream = new WSLLMStream(model, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry: 2, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n for await (const _chunk of llmStream) void _chunk;\n const error = await errorEvent;\n\n expect(error).toBeInstanceOf(APIStatusError);\n expect(error.message).toContain(expectedMessage);\n expect((error as APIStatusError).statusCode).toBe(-1);\n expect((error as APIStatusError).retryable).toBe(false);\n expect(conn.attempts).toBe(1);\n expect(onCompleted).not.toHaveBeenCalled();\n\n await pool.withConnection(async (pooled) => expect(pooled).toBe(conn));\n expect(connectCalls).toBe(1);\n expect(conn.payloads[0]).not.toHaveProperty('previous_response_id');\n await pool.close();\n await model.aclose();\n },\n );\n});\n\nif (hasOpenAIApiKey) {\n describe('OpenAI Responses WS wrapper', async () => {\n await llm(\n new LLM({\n temperature: 0,\n strictToolSchema: false,\n useWebSocket: true,\n }),\n true,\n );\n });\n\n describe('OpenAI Responses WS wrapper strict tool schema', async () => {\n await llmStrict(\n new LLM({\n temperature: 0,\n strictToolSchema: true,\n useWebSocket: true,\n }),\n );\n });\n} else {\n describe('OpenAI Responses WS wrapper', () => {\n it.skip('requires OPENAI_API_KEY', () => {});\n });\n}\n"],"mappings":";AAGA,oBAMO;AACP,iCAA+B;AAC/B,yBAA6B;AAC7B,oBAAyC;AACzC,iBAAoB;AACpB,IAAA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3B,gCAAO,KAAK,SAAS,CAAC,CAAC,EAAE,IAAI,eAAe,sBAAsB;AAClE,YAAM,KAAK,MAAM;AACjB,YAAM,MAAM,OAAO;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAED,IAAI,iBAAiB;AACnB,8BAAS,+BAA+B,YAAY;AAClD,cAAM;AAAA,MACJ,IAAI,eAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF,CAAC;AAED,8BAAS,kDAAkD,YAAY;AACrE,cAAM;AAAA,MACJ,IAAI,eAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH,OAAO;AACL,8BAAS,+BAA+B,MAAM;AAC5C,qBAAG,KAAK,2BAA2B,MAAM;AAAA,IAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":["import_llm"]}
|
package/dist/ws/llm.test.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
APIStatusError,
|
|
3
|
+
ChatContext,
|
|
4
|
+
ConnectionPool,
|
|
5
|
+
initializeLogger,
|
|
6
|
+
stream
|
|
7
|
+
} from "@livekit/agents";
|
|
2
8
|
import { llm, llmStrict } from "@livekit/agents-plugins-test";
|
|
3
|
-
import {
|
|
9
|
+
import { EventEmitter } from "node:events";
|
|
10
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
11
|
import { LLM } from "../responses/llm.js";
|
|
5
|
-
import { WSLLM, WSLLMStream, buildResponsesWsUrl } from "./llm.js";
|
|
12
|
+
import { ResponsesWebSocket, WSLLM, WSLLMStream, buildResponsesWsUrl } from "./llm.js";
|
|
13
|
+
import { wsServerEventSchema } from "./types.js";
|
|
6
14
|
initializeLogger({ level: "silent", pretty: false });
|
|
7
15
|
const hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);
|
|
8
16
|
describe("buildResponsesWsUrl", () => {
|
|
@@ -71,6 +79,57 @@ const TEXT_DELTA = {
|
|
|
71
79
|
type: "response.output_text.delta",
|
|
72
80
|
delta: "hello"
|
|
73
81
|
};
|
|
82
|
+
function responseIncomplete(reason) {
|
|
83
|
+
return {
|
|
84
|
+
type: "response.incomplete",
|
|
85
|
+
response: {
|
|
86
|
+
id: "resp_1",
|
|
87
|
+
incomplete_details: reason === void 0 ? {} : { reason }
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
describe("OpenAI Responses WS incomplete events", () => {
|
|
92
|
+
it.each(["max_output_tokens", "content_filter"])("parses the provider reason %s", (reason) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const parsed = wsServerEventSchema.parse(responseIncomplete(reason));
|
|
95
|
+
expect(parsed.type).toBe("response.incomplete");
|
|
96
|
+
if (parsed.type !== "response.incomplete") throw new Error("expected incomplete event");
|
|
97
|
+
expect((_a = parsed.response.incomplete_details) == null ? void 0 : _a.reason).toBe(reason);
|
|
98
|
+
});
|
|
99
|
+
it("accepts incomplete details without a reason", () => {
|
|
100
|
+
var _a;
|
|
101
|
+
const parsed = wsServerEventSchema.parse({
|
|
102
|
+
type: "response.incomplete",
|
|
103
|
+
response: { id: "resp_1", incomplete_details: {} }
|
|
104
|
+
});
|
|
105
|
+
expect(parsed.type).toBe("response.incomplete");
|
|
106
|
+
if (parsed.type !== "response.incomplete") throw new Error("expected incomplete event");
|
|
107
|
+
expect((_a = parsed.response.incomplete_details) == null ? void 0 : _a.reason).toBeUndefined();
|
|
108
|
+
});
|
|
109
|
+
it("closes the request channel after the terminal frame", async () => {
|
|
110
|
+
class RecordingSocket extends EventEmitter {
|
|
111
|
+
readyState = 1;
|
|
112
|
+
sent = [];
|
|
113
|
+
send(data) {
|
|
114
|
+
this.sent.push(data);
|
|
115
|
+
}
|
|
116
|
+
close() {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const socket = new RecordingSocket();
|
|
120
|
+
const transport = new ResponsesWebSocket(socket);
|
|
121
|
+
const channel = transport.sendRequest({
|
|
122
|
+
type: "response.create",
|
|
123
|
+
model: "gpt-4.1",
|
|
124
|
+
input: []
|
|
125
|
+
});
|
|
126
|
+
socket.emit("message", Buffer.from(JSON.stringify(responseIncomplete())));
|
|
127
|
+
const events = [];
|
|
128
|
+
for await (const event of channel.stream()) events.push(event);
|
|
129
|
+
expect(events).toEqual([responseIncomplete()]);
|
|
130
|
+
expect(socket.sent).toHaveLength(1);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
74
133
|
class StallingConnection {
|
|
75
134
|
constructor(frames) {
|
|
76
135
|
this.frames = frames;
|
|
@@ -128,6 +187,70 @@ describe("OpenAI Responses WS retry eligibility", () => {
|
|
|
128
187
|
expect(await attemptsUntilStall([RESPONSE_CREATED, TEXT_DELTA], 2)).toBe(1);
|
|
129
188
|
});
|
|
130
189
|
});
|
|
190
|
+
describe("OpenAI Responses WS incomplete handling", () => {
|
|
191
|
+
it.each([
|
|
192
|
+
["max_output_tokens", "max_output_tokens"],
|
|
193
|
+
[void 0, "reason unavailable"]
|
|
194
|
+
])(
|
|
195
|
+
"surfaces %s as non-retryable without updating context",
|
|
196
|
+
async (reason, expectedMessage) => {
|
|
197
|
+
class ReplayConnection {
|
|
198
|
+
attempts = 0;
|
|
199
|
+
payloads = [];
|
|
200
|
+
sendRequest(payload) {
|
|
201
|
+
this.attempts++;
|
|
202
|
+
this.payloads.push(payload);
|
|
203
|
+
const channel = stream.createStreamChannel();
|
|
204
|
+
void (async () => {
|
|
205
|
+
await channel.write(RESPONSE_CREATED);
|
|
206
|
+
await channel.write(responseIncomplete(reason));
|
|
207
|
+
await channel.close();
|
|
208
|
+
})();
|
|
209
|
+
return channel;
|
|
210
|
+
}
|
|
211
|
+
close() {
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const model = new WSLLM({ model: "gpt-4.1", apiKey: "test-key" });
|
|
215
|
+
const onCompleted = vi.spyOn(model, "_onResponseCompleted");
|
|
216
|
+
const errorEvent = new Promise((resolve) => {
|
|
217
|
+
model.once("error", (event) => resolve(event.error));
|
|
218
|
+
});
|
|
219
|
+
const conn = new ReplayConnection();
|
|
220
|
+
let connectCalls = 0;
|
|
221
|
+
const pool = new ConnectionPool({
|
|
222
|
+
connectCb: async () => {
|
|
223
|
+
connectCalls++;
|
|
224
|
+
return conn;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
const chatCtx = ChatContext.empty();
|
|
228
|
+
chatCtx.addMessage({ role: "user", content: "hi" });
|
|
229
|
+
const llmStream = new WSLLMStream(model, {
|
|
230
|
+
pool,
|
|
231
|
+
model: "gpt-4.1",
|
|
232
|
+
chatCtx,
|
|
233
|
+
fullChatCtx: chatCtx,
|
|
234
|
+
connOptions: { maxRetry: 2, retryIntervalMs: 0, timeoutMs: 5e3 },
|
|
235
|
+
modelOptions: {},
|
|
236
|
+
strictToolSchema: true
|
|
237
|
+
});
|
|
238
|
+
for await (const _chunk of llmStream) void _chunk;
|
|
239
|
+
const error = await errorEvent;
|
|
240
|
+
expect(error).toBeInstanceOf(APIStatusError);
|
|
241
|
+
expect(error.message).toContain(expectedMessage);
|
|
242
|
+
expect(error.statusCode).toBe(-1);
|
|
243
|
+
expect(error.retryable).toBe(false);
|
|
244
|
+
expect(conn.attempts).toBe(1);
|
|
245
|
+
expect(onCompleted).not.toHaveBeenCalled();
|
|
246
|
+
await pool.withConnection(async (pooled) => expect(pooled).toBe(conn));
|
|
247
|
+
expect(connectCalls).toBe(1);
|
|
248
|
+
expect(conn.payloads[0]).not.toHaveProperty("previous_response_id");
|
|
249
|
+
await pool.close();
|
|
250
|
+
await model.aclose();
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
});
|
|
131
254
|
if (hasOpenAIApiKey) {
|
|
132
255
|
describe("OpenAI Responses WS wrapper", async () => {
|
|
133
256
|
await llm(
|
package/dist/ws/llm.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { ChatContext, ConnectionPool, initializeLogger, stream } from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { describe, expect, it } from 'vitest';\nimport { LLM } from '../responses/llm.js';\nimport type { ResponsesWebSocket } from './llm.js';\nimport { WSLLM, WSLLMStream, buildResponsesWsUrl } from './llm.js';\nimport type { WsServerEvent } from './types.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\nconst hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);\n\ndescribe('buildResponsesWsUrl', () => {\n it('points at the OpenAI Responses WS endpoint without model when no baseURL is set', () => {\n const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('rewrites https baseURL to wss and appends /responses with the model', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('rewrites full https Responses endpoint to wss without duplicating /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('uses full wss Responses endpoint with the model', () => {\n const url = new URL(buildResponsesWsUrl('wss://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('omits the model when an explicit baseURL still points at api.openai.com', () => {\n const url = new URL(buildResponsesWsUrl('https://api.openai.com/v1', 'gpt-4.1'));\n\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('strips a trailing slash on baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('rewrites http baseURL to ws (not wss)', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('strips a trailing slash on an http baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n});\n\n// opens every stream, on every provider\nconst RESPONSE_CREATED: WsServerEvent = {\n type: 'response.created',\n response: { id: 'resp_1' },\n};\n\n// a reasoning phase marker: a message item with no text of its own\nconst PHASE_METADATA: WsServerEvent = {\n type: 'response.output_item.done',\n item: { type: 'message', phase: 'thinking' },\n};\n\nconst TEXT_DELTA: WsServerEvent = {\n type: 'response.output_text.delta',\n delta: 'hello',\n};\n\n/** Replays the given frames, then dies the way a socket going quiet does. */\nclass StallingConnection {\n attempts = 0;\n\n constructor(private readonly frames: WsServerEvent[]) {}\n\n sendRequest(): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n const channel = stream.createStreamChannel<WsServerEvent>();\n\n void (async () => {\n for (const frame of this.frames) {\n await channel.write(frame);\n }\n await channel.abort(new Error('stalled mid-stream'));\n })();\n\n return channel;\n }\n\n close(): void {}\n}\n\n/** Returns how many times the response was requested before the stream gave up. */\nasync function attemptsUntilStall(frames: WsServerEvent[], maxRetry: number): Promise<number> {\n const wsLLM = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n // the stream emits 'error' on every failed attempt; without a listener the\n // EventEmitter turns it into an unhandled error and fails the run\n wsLLM.on('error', () => {});\n\n const conn = new StallingConnection(frames);\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => conn as unknown as ResponsesWebSocket,\n });\n\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n\n const llmStream = new WSLLMStream(wsLLM, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n try {\n for await (const _chunk of llmStream) {\n void _chunk;\n }\n } catch {\n // the stall surfaces through the 'error' event; the iterator just ends\n }\n\n return conn.attempts;\n}\n\ndescribe('OpenAI Responses WS retry eligibility', () => {\n it('retries a stall that follows the stream-opening frame alone', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED], 2)).toBe(3);\n });\n\n it('retries a stall that follows a phase marker', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, PHASE_METADATA], 2)).toBe(3);\n });\n\n it('does not retry once generated text has reached the caller', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, TEXT_DELTA], 2)).toBe(1);\n });\n});\n\nif (hasOpenAIApiKey) {\n describe('OpenAI Responses WS wrapper', async () => {\n await llm(\n new LLM({\n temperature: 0,\n strictToolSchema: false,\n useWebSocket: true,\n }),\n true,\n );\n });\n\n describe('OpenAI Responses WS wrapper strict tool schema', async () => {\n await llmStrict(\n new LLM({\n temperature: 0,\n strictToolSchema: true,\n useWeb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W,IAAK;AAAA,IAC7D,cAAc,CAAC;AAAA,IACf,kBAAkB;AAAA,EACpB,CAAC;AAED,MAAI;AACF,qBAAiB,UAAU,WAAW;AACpC,WAAK;AAAA,IACP;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,SAAO,KAAK;AACd;AAEA,SAAS,yCAAyC,MAAM;AACtD,KAAG,+DAA+D,YAAY;AAC5E,WAAO,MAAM,mBAAmB,CAAC,gBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;AAAA,EAChE,CAAC;AAED,KAAG,+CAA+C,YAAY;AAC5D,WAAO,MAAM,mBAAmB,CAAC,kBAAkB,cAAc,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;AAAA,EAChF,CAAC;AAED,KAAG,6DAA6D,YAAY;AAC1E,WAAO,MAAM,mBAAmB,CAAC,kBAAkB,UAAU,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC;AAAA,EAC5E,CAAC;AACH,CAAC;AAED,IAAI,iBAAiB;AACnB,WAAS,+BAA+B,YAAY;AAClD,UAAM;AAAA,MACJ,IAAI,IAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF,CAAC;AAED,WAAS,kDAAkD,YAAY;AACrE,UAAM;AAAA,MACJ,IAAI,IAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH,OAAO;AACL,WAAS,+BAA+B,MAAM;AAC5C,OAAG,KAAK,2BAA2B,MAAM;AAAA,IAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/ws/llm.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {\n APIStatusError,\n ChatContext,\n ConnectionPool,\n initializeLogger,\n stream,\n} from '@livekit/agents';\nimport { llm, llmStrict } from '@livekit/agents-plugins-test';\nimport { EventEmitter } from 'node:events';\nimport { describe, expect, it, vi } from 'vitest';\nimport { LLM } from '../responses/llm.js';\nimport { ResponsesWebSocket, WSLLM, WSLLMStream, buildResponsesWsUrl } from './llm.js';\nimport type { WsResponseCreateEvent, WsServerEvent } from './types.js';\nimport { wsServerEventSchema } from './types.js';\n\ninitializeLogger({ level: 'silent', pretty: false });\n\nconst hasOpenAIApiKey = Boolean(process.env.OPENAI_API_KEY);\n\ndescribe('buildResponsesWsUrl', () => {\n it('points at the OpenAI Responses WS endpoint without model when no baseURL is set', () => {\n const url = new URL(buildResponsesWsUrl(undefined, 'gpt-4.1'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('rewrites https baseURL to wss and appends /responses with the model', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('rewrites full https Responses endpoint to wss without duplicating /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('uses full wss Responses endpoint with the model', () => {\n const url = new URL(buildResponsesWsUrl('wss://gateway.example.com/v1/responses', 'gpt-4o'));\n\n expect(url.protocol).toBe('wss:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o');\n });\n\n it('omits the model when an explicit baseURL still points at api.openai.com', () => {\n const url = new URL(buildResponsesWsUrl('https://api.openai.com/v1', 'gpt-4.1'));\n\n expect(url.host).toBe('api.openai.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe(null);\n });\n\n it('strips a trailing slash on baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('https://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('rewrites http baseURL to ws (not wss)', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.host).toBe('gateway.example.com');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n\n it('strips a trailing slash on an http baseURL before appending /responses', () => {\n const url = new URL(buildResponsesWsUrl('http://gateway.example.com/v1/', 'gpt-4o-mini'));\n\n expect(url.protocol).toBe('ws:');\n expect(url.pathname).toBe('/v1/responses');\n expect(url.searchParams.get('model')).toBe('gpt-4o-mini');\n });\n});\n\n// opens every stream, on every provider\nconst RESPONSE_CREATED: WsServerEvent = {\n type: 'response.created',\n response: { id: 'resp_1' },\n};\n\n// a reasoning phase marker: a message item with no text of its own\nconst PHASE_METADATA: WsServerEvent = {\n type: 'response.output_item.done',\n item: { type: 'message', phase: 'thinking' },\n};\n\nconst TEXT_DELTA: WsServerEvent = {\n type: 'response.output_text.delta',\n delta: 'hello',\n};\n\nfunction responseIncomplete(reason?: string): WsServerEvent {\n return {\n type: 'response.incomplete',\n response: {\n id: 'resp_1',\n incomplete_details: reason === undefined ? {} : { reason },\n },\n };\n}\n\ndescribe('OpenAI Responses WS incomplete events', () => {\n it.each(['max_output_tokens', 'content_filter'])('parses the provider reason %s', (reason) => {\n const parsed = wsServerEventSchema.parse(responseIncomplete(reason));\n\n expect(parsed.type).toBe('response.incomplete');\n if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');\n expect(parsed.response.incomplete_details?.reason).toBe(reason);\n });\n\n it('accepts incomplete details without a reason', () => {\n const parsed = wsServerEventSchema.parse({\n type: 'response.incomplete',\n response: { id: 'resp_1', incomplete_details: {} },\n });\n\n expect(parsed.type).toBe('response.incomplete');\n if (parsed.type !== 'response.incomplete') throw new Error('expected incomplete event');\n expect(parsed.response.incomplete_details?.reason).toBeUndefined();\n });\n\n it('closes the request channel after the terminal frame', async () => {\n class RecordingSocket extends EventEmitter {\n readyState = 1;\n sent: string[] = [];\n\n send(data: string): void {\n this.sent.push(data);\n }\n\n close(): void {}\n }\n\n const socket = new RecordingSocket();\n const transport = new ResponsesWebSocket(socket as never);\n const channel = transport.sendRequest({\n type: 'response.create',\n model: 'gpt-4.1',\n input: [],\n });\n\n socket.emit('message', Buffer.from(JSON.stringify(responseIncomplete())));\n const events = [];\n for await (const event of channel.stream()) events.push(event);\n\n expect(events).toEqual([responseIncomplete()]);\n expect(socket.sent).toHaveLength(1);\n });\n});\n\n/** Replays the given frames, then dies the way a socket going quiet does. */\nclass StallingConnection {\n attempts = 0;\n\n constructor(private readonly frames: WsServerEvent[]) {}\n\n sendRequest(): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n const channel = stream.createStreamChannel<WsServerEvent>();\n\n void (async () => {\n for (const frame of this.frames) {\n await channel.write(frame);\n }\n await channel.abort(new Error('stalled mid-stream'));\n })();\n\n return channel;\n }\n\n close(): void {}\n}\n\n/** Returns how many times the response was requested before the stream gave up. */\nasync function attemptsUntilStall(frames: WsServerEvent[], maxRetry: number): Promise<number> {\n const wsLLM = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n // the stream emits 'error' on every failed attempt; without a listener the\n // EventEmitter turns it into an unhandled error and fails the run\n wsLLM.on('error', () => {});\n\n const conn = new StallingConnection(frames);\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => conn as unknown as ResponsesWebSocket,\n });\n\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n\n const llmStream = new WSLLMStream(wsLLM, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n try {\n for await (const _chunk of llmStream) {\n void _chunk;\n }\n } catch {\n // the stall surfaces through the 'error' event; the iterator just ends\n }\n\n return conn.attempts;\n}\n\ndescribe('OpenAI Responses WS retry eligibility', () => {\n it('retries a stall that follows the stream-opening frame alone', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED], 2)).toBe(3);\n });\n\n it('retries a stall that follows a phase marker', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, PHASE_METADATA], 2)).toBe(3);\n });\n\n it('does not retry once generated text has reached the caller', async () => {\n expect(await attemptsUntilStall([RESPONSE_CREATED, TEXT_DELTA], 2)).toBe(1);\n });\n});\n\ndescribe('OpenAI Responses WS incomplete handling', () => {\n it.each([\n ['max_output_tokens', 'max_output_tokens'],\n [undefined, 'reason unavailable'],\n ] as const)(\n 'surfaces %s as non-retryable without updating context',\n async (reason, expectedMessage) => {\n class ReplayConnection {\n attempts = 0;\n payloads: WsResponseCreateEvent[] = [];\n\n sendRequest(payload: WsResponseCreateEvent): stream.StreamChannel<WsServerEvent> {\n this.attempts++;\n this.payloads.push(payload);\n const channel = stream.createStreamChannel<WsServerEvent>();\n void (async () => {\n await channel.write(RESPONSE_CREATED);\n await channel.write(responseIncomplete(reason));\n await channel.close();\n })();\n return channel;\n }\n\n close(): void {}\n }\n\n const model = new WSLLM({ model: 'gpt-4.1', apiKey: 'test-key' });\n const onCompleted = vi.spyOn(model, '_onResponseCompleted');\n const errorEvent = new Promise<Error>((resolve) => {\n model.once('error', (event) => resolve(event.error));\n });\n const conn = new ReplayConnection();\n let connectCalls = 0;\n const pool = new ConnectionPool<ResponsesWebSocket>({\n connectCb: async () => {\n connectCalls++;\n return conn as unknown as ResponsesWebSocket;\n },\n });\n const chatCtx = ChatContext.empty();\n chatCtx.addMessage({ role: 'user', content: 'hi' });\n const llmStream = new WSLLMStream(model, {\n pool,\n model: 'gpt-4.1',\n chatCtx,\n fullChatCtx: chatCtx,\n connOptions: { maxRetry: 2, retryIntervalMs: 0, timeoutMs: 5000 },\n modelOptions: {},\n strictToolSchema: true,\n });\n\n for await (const _chunk of llmStream) void _chunk;\n const error = await errorEvent;\n\n expect(error).toBeInstanceOf(APIStatusError);\n expect(error.message).toContain(expectedMessage);\n expect((error as APIStatusError).statusCode).toBe(-1);\n expect((error as APIStatusError).retryable).toBe(false);\n expect(conn.attempts).toBe(1);\n expect(onCompleted).not.toHaveBeenCalled();\n\n await pool.withConnection(async (pooled) => expect(pooled).toBe(conn));\n expect(connectCalls).toBe(1);\n expect(conn.payloads[0]).not.toHaveProperty('previous_response_id');\n await pool.close();\n await model.aclose();\n },\n );\n});\n\nif (hasOpenAIApiKey) {\n describe('OpenAI Responses WS wrapper', async () => {\n await llm(\n new LLM({\n temperature: 0,\n strictToolSchema: false,\n useWebSocket: true,\n }),\n true,\n );\n });\n\n describe('OpenAI Responses WS wrapper strict tool schema', async () => {\n await llmStrict(\n new LLM({\n temperature: 0,\n strictToolSchema: true,\n useWebSocket: true,\n }),\n );\n });\n} else {\n describe('OpenAI Responses WS wrapper', () => {\n it.skip('requires OPENAI_API_KEY', () => {});\n });\n}\n"],"mappings":"AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAK,iBAAiB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,UAAU,QAAQ,IAAI,UAAU;AACzC,SAAS,WAAW;AACpB,SAAS,oBAAoB,OAAO,aAAa,2BAA2B;AAE5E,SAAS,2BAA2B;AAEpC,iBAAiB,EAAE,OAAO,UAAU,QAAQ,MAAM,CAAC;AAEnD,MAAM,kBAAkB,QAAQ,QAAQ,IAAI,cAAc;AAE1D,SAAS,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AA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,MACD;AAAA,IACF;AAAA,EACF,CAAC;AAED,WAAS,kDAAkD,YAAY;AACrE,UAAM;AAAA,MACJ,IAAI,IAAI;AAAA,QACN,aAAa;AAAA,QACb,kBAAkB;AAAA,QAClB,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH,OAAO;AACL,WAAS,+BAA+B,MAAM;AAC5C,OAAG,KAAK,2BAA2B,MAAM;AAAA,IAAC,CAAC;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
package/dist/ws/types.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(types_exports, {
|
|
|
27
27
|
wsResponseCreateEventSchema: () => wsResponseCreateEventSchema,
|
|
28
28
|
wsResponseCreatedEventSchema: () => wsResponseCreatedEventSchema,
|
|
29
29
|
wsResponseFailedEventSchema: () => wsResponseFailedEventSchema,
|
|
30
|
+
wsResponseIncompleteEventSchema: () => wsResponseIncompleteEventSchema,
|
|
30
31
|
wsServerEventSchema: () => wsServerEventSchema
|
|
31
32
|
});
|
|
32
33
|
module.exports = __toCommonJS(types_exports);
|
|
@@ -94,6 +95,15 @@ const wsResponseFailedEventSchema = import_zod.z.object({
|
|
|
94
95
|
}).optional()
|
|
95
96
|
}).passthrough()
|
|
96
97
|
});
|
|
98
|
+
const wsResponseIncompleteEventSchema = import_zod.z.object({
|
|
99
|
+
type: import_zod.z.literal("response.incomplete"),
|
|
100
|
+
response: import_zod.z.object({
|
|
101
|
+
id: import_zod.z.string(),
|
|
102
|
+
incomplete_details: import_zod.z.object({
|
|
103
|
+
reason: import_zod.z.string().optional()
|
|
104
|
+
}).nullable().optional()
|
|
105
|
+
}).passthrough()
|
|
106
|
+
});
|
|
97
107
|
const wsErrorEventSchema = import_zod.z.object({
|
|
98
108
|
type: import_zod.z.literal("error"),
|
|
99
109
|
status: import_zod.z.number().optional(),
|
|
@@ -113,6 +123,7 @@ const wsServerEventSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
113
123
|
wsOutputTextDeltaEventSchema,
|
|
114
124
|
wsResponseCompletedEventSchema,
|
|
115
125
|
wsResponseFailedEventSchema,
|
|
126
|
+
wsResponseIncompleteEventSchema,
|
|
116
127
|
wsErrorEventSchema
|
|
117
128
|
]);
|
|
118
129
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -126,6 +137,7 @@ const wsServerEventSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
126
137
|
wsResponseCreateEventSchema,
|
|
127
138
|
wsResponseCreatedEventSchema,
|
|
128
139
|
wsResponseFailedEventSchema,
|
|
140
|
+
wsResponseIncompleteEventSchema,
|
|
129
141
|
wsServerEventSchema
|
|
130
142
|
});
|
|
131
143
|
//# sourceMappingURL=types.cjs.map
|
package/dist/ws/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAkB;AAMX,MAAM,8BAA8B,aACxC,OAAO;AAAA,EACN,MAAM,aAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,aAAE,OAAO;AAAA,EAChB,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACrD,OAAO,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,aAAa,aAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,OAAO,CAAC,EAAE,SAAS;AACtD,CAAC,EACA,YAAY;AAQR,MAAM,+BAA+B,aAAE,OAAO;AAAA,EACnD,MAAM,aAAE,QAAQ,kBAAkB;AAAA,EAClC,UAAU,aACP,OAAO;AAAA,IACN,IAAI,aAAE,OAAO;AAAA,EACf,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,2BAA2B,aAAE,OAAO;AAAA,EAC/C,MAAM,aAAE,QAAQ,eAAe;AAAA,EAC/B,SAAS,aAAE,OAAO;AAAA,EAClB,MAAM,aAAE,OAAO;AAAA,EACf,WAAW,aAAE,OAAO;AACtB,CAAC;AAEM,MAAM,qBAAqB,aAAE,mBAAmB,QAAQ;AAAA,EAC7D;AAAA,EACA,aA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I,aAAE,OAAO,EAAE,SAAS;AAAA,IACxB,OAAO,aACJ,OAAO;AAAA,MACN,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,MAC1B,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,CAAC,EACA,SAAS;AAAA,EACd,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,qBAAqB,aAAE,OAAO;AAAA,EACzC,MAAM,aAAE,QAAQ,OAAO;AAAA,EACvB,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,aACJ,OAAO;AAAA,IACN,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,aAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,aAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseIncompleteEventSchema = z.object({\n type: z.literal('response.incomplete'),\n response: z\n .object({\n id: z.string(),\n incomplete_details: z\n .object({\n reason: z.string().optional(),\n })\n .nullable()\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsResponseIncompleteEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAkB;AAMX,MAAM,8BAA8B,aACxC,OAAO;AAAA,EACN,MAAM,aAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,aAAE,OAAO;AAAA,EAChB,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,aAAE,MAAM,aAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,aAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACrD,OAAO,aAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,aAAa,aAAE,OAAO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,OAAO,aACJ,OAAO;AAAA,IACN,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,aAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,aAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,aAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
package/dist/ws/types.d.cts
CHANGED
|
@@ -88,6 +88,15 @@ export declare const wsResponseFailedEventSchema: z.ZodObject<{
|
|
|
88
88
|
}, z.core.$strip>>;
|
|
89
89
|
}, z.core.$loose>;
|
|
90
90
|
}, z.core.$strip>;
|
|
91
|
+
export declare const wsResponseIncompleteEventSchema: z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
93
|
+
response: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
96
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
}, z.core.$strip>;
|
|
91
100
|
export declare const wsErrorEventSchema: z.ZodObject<{
|
|
92
101
|
type: z.ZodLiteral<"error">;
|
|
93
102
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -151,6 +160,14 @@ export declare const wsServerEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
151
160
|
message: z.ZodOptional<z.ZodString>;
|
|
152
161
|
}, z.core.$strip>>;
|
|
153
162
|
}, z.core.$loose>;
|
|
163
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
165
|
+
response: z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
168
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$strip>>>;
|
|
170
|
+
}, z.core.$loose>;
|
|
154
171
|
}, z.core.$strip>, z.ZodObject<{
|
|
155
172
|
type: z.ZodLiteral<"error">;
|
|
156
173
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -171,6 +188,7 @@ export type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;
|
|
|
171
188
|
export type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;
|
|
172
189
|
export type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;
|
|
173
190
|
export type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;
|
|
191
|
+
export type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;
|
|
174
192
|
export type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;
|
|
175
193
|
export type WsServerEvent = z.infer<typeof wsServerEventSchema>;
|
|
176
194
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/ws/types.d.ts
CHANGED
|
@@ -88,6 +88,15 @@ export declare const wsResponseFailedEventSchema: z.ZodObject<{
|
|
|
88
88
|
}, z.core.$strip>>;
|
|
89
89
|
}, z.core.$loose>;
|
|
90
90
|
}, z.core.$strip>;
|
|
91
|
+
export declare const wsResponseIncompleteEventSchema: z.ZodObject<{
|
|
92
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
93
|
+
response: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
96
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>>>;
|
|
98
|
+
}, z.core.$loose>;
|
|
99
|
+
}, z.core.$strip>;
|
|
91
100
|
export declare const wsErrorEventSchema: z.ZodObject<{
|
|
92
101
|
type: z.ZodLiteral<"error">;
|
|
93
102
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -151,6 +160,14 @@ export declare const wsServerEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
151
160
|
message: z.ZodOptional<z.ZodString>;
|
|
152
161
|
}, z.core.$strip>>;
|
|
153
162
|
}, z.core.$loose>;
|
|
163
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"response.incomplete">;
|
|
165
|
+
response: z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
incomplete_details: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
168
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$strip>>>;
|
|
170
|
+
}, z.core.$loose>;
|
|
154
171
|
}, z.core.$strip>, z.ZodObject<{
|
|
155
172
|
type: z.ZodLiteral<"error">;
|
|
156
173
|
status: z.ZodOptional<z.ZodNumber>;
|
|
@@ -171,6 +188,7 @@ export type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;
|
|
|
171
188
|
export type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;
|
|
172
189
|
export type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;
|
|
173
190
|
export type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;
|
|
191
|
+
export type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;
|
|
174
192
|
export type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;
|
|
175
193
|
export type WsServerEvent = z.infer<typeof wsServerEventSchema>;
|
|
176
194
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/ws/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","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64
64
|
});
|
|
65
|
+
const wsResponseIncompleteEventSchema = z.object({
|
|
66
|
+
type: z.literal("response.incomplete"),
|
|
67
|
+
response: z.object({
|
|
68
|
+
id: z.string(),
|
|
69
|
+
incomplete_details: z.object({
|
|
70
|
+
reason: z.string().optional()
|
|
71
|
+
}).nullable().optional()
|
|
72
|
+
}).passthrough()
|
|
73
|
+
});
|
|
65
74
|
const wsErrorEventSchema = z.object({
|
|
66
75
|
type: z.literal("error"),
|
|
67
76
|
status: z.number().optional(),
|
|
@@ -81,6 +90,7 @@ const wsServerEventSchema = z.discriminatedUnion("type", [
|
|
|
81
90
|
wsOutputTextDeltaEventSchema,
|
|
82
91
|
wsResponseCompletedEventSchema,
|
|
83
92
|
wsResponseFailedEventSchema,
|
|
93
|
+
wsResponseIncompleteEventSchema,
|
|
84
94
|
wsErrorEventSchema
|
|
85
95
|
]);
|
|
86
96
|
export {
|
|
@@ -93,6 +103,7 @@ export {
|
|
|
93
103
|
wsResponseCreateEventSchema,
|
|
94
104
|
wsResponseCreatedEventSchema,
|
|
95
105
|
wsResponseFailedEventSchema,
|
|
106
|
+
wsResponseIncompleteEventSchema,
|
|
96
107
|
wsServerEventSchema
|
|
97
108
|
};
|
|
98
109
|
//# sourceMappingURL=types.js.map
|
package/dist/ws/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAMX,MAAM,8BAA8B,EACxC,OAAO;AAAA,EACN,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACrD,OAAO,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5B,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS;AACtD,CAAC,EACA,YAAY;AAQR,MAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,MAAM,EAAE,QAAQ,kBAAkB;AAAA,EAClC,UAAU,EACP,OAAO;AAAA,IACN,IAAI,EAAE,OAAO;AAAA,EACf,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/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AC,EACA,YAAY;AAAA,IACjB,CAAC,EACA,SAAS;AAAA,EACd,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,UAAU,EACP,OAAO;AAAA,IACN,IAAI,EAAE,OAAO,EAAE,SAAS;AAAA,IACxB,OAAO,EACJ,OAAO;AAAA,MACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,MAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC/B,CAAC,EACA,SAAS;AAAA,EACd,CAAC,EACA,YAAY;AACjB,CAAC;AAEM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,MAAM,EAAE,QAAQ,OAAO;AAAA,EACvB,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EACJ,OAAO;AAAA,IACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,EAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/ws/types.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\n// ============================================================================\n// Client → Server events\n// ============================================================================\n\nexport const wsResponseCreateEventSchema = z\n .object({\n type: z.literal('response.create'),\n model: z.string(),\n input: z.array(z.unknown()),\n tools: z.array(z.unknown()).optional(),\n previous_response_id: z.string().nullable().optional(),\n store: z.boolean().optional(),\n temperature: z.number().optional(),\n metadata: z.record(z.string(), z.string()).optional(),\n })\n .passthrough();\n\nexport type WsResponseCreateEvent = z.infer<typeof wsResponseCreateEventSchema>;\n\n// ============================================================================\n// Server → Client events\n// ============================================================================\n\nexport const wsResponseCreatedEventSchema = z.object({\n type: z.literal('response.created'),\n response: z\n .object({\n id: z.string(),\n })\n .passthrough(),\n});\n\nexport const wsFunctionCallItemSchema = z.object({\n type: z.literal('function_call'),\n call_id: z.string(),\n name: z.string(),\n arguments: z.string(),\n});\n\nexport const wsOutputItemSchema = z.discriminatedUnion('type', [\n wsFunctionCallItemSchema,\n z.object({ type: z.literal('message'), phase: z.string().optional() }).passthrough(),\n z.object({ type: z.literal('reasoning') }).passthrough(),\n z.object({ type: z.literal('file') }).passthrough(),\n z.object({ type: z.literal('computer_call') }).passthrough(),\n z.object({ type: z.literal('web_search_call') }).passthrough(),\n]);\n\nexport const wsOutputItemDoneEventSchema = z.object({\n type: z.literal('response.output_item.done'),\n item: wsOutputItemSchema,\n});\n\nexport const wsOutputTextDeltaEventSchema = z.object({\n type: z.literal('response.output_text.delta'),\n delta: z.string(),\n});\n\nexport const wsResponseCompletedEventSchema = z.object({\n type: z.literal('response.completed'),\n response: z\n .object({\n id: z.string(),\n service_tier: z.string().nullable().optional(),\n usage: z\n .object({\n output_tokens: z.number(),\n input_tokens: z.number(),\n total_tokens: z.number(),\n input_tokens_details: z\n .object({\n cached_tokens: z.number(),\n })\n .passthrough(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseFailedEventSchema = z.object({\n type: z.literal('response.failed'),\n response: z\n .object({\n id: z.string().optional(),\n error: z\n .object({\n code: z.string().optional(),\n message: z.string().optional(),\n })\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsResponseIncompleteEventSchema = z.object({\n type: z.literal('response.incomplete'),\n response: z\n .object({\n id: z.string(),\n incomplete_details: z\n .object({\n reason: z.string().optional(),\n })\n .nullable()\n .optional(),\n })\n .passthrough(),\n});\n\nexport const wsErrorEventSchema = z.object({\n type: z.literal('error'),\n status: z.number().optional(),\n code: z.string().optional(),\n param: z.string().optional(),\n error: z\n .object({\n type: z.string().optional(),\n code: z.string().optional(),\n message: z.string().optional(),\n param: z.string().optional(),\n })\n .optional(),\n message: z.string().optional(),\n});\n\nexport const wsServerEventSchema = z.discriminatedUnion('type', [\n wsResponseCreatedEventSchema,\n wsOutputItemDoneEventSchema,\n wsOutputTextDeltaEventSchema,\n wsResponseCompletedEventSchema,\n wsResponseFailedEventSchema,\n wsResponseIncompleteEventSchema,\n wsErrorEventSchema,\n]);\n\nexport type WsResponseCreatedEvent = z.infer<typeof wsResponseCreatedEventSchema>;\nexport type WsFunctionCallItem = z.infer<typeof wsFunctionCallItemSchema>;\nexport type WsOutputItem = z.infer<typeof wsOutputItemSchema>;\nexport type WsOutputItemDoneEvent = z.infer<typeof wsOutputItemDoneEventSchema>;\nexport type WsOutputTextDeltaEvent = z.infer<typeof wsOutputTextDeltaEventSchema>;\nexport type WsResponseCompletedEvent = z.infer<typeof wsResponseCompletedEventSchema>;\nexport type WsResponseFailedEvent = z.infer<typeof wsResponseFailedEventSchema>;\nexport type WsResponseIncompleteEvent = z.infer<typeof wsResponseIncompleteEventSchema>;\nexport type WsErrorEvent = z.infer<typeof wsErrorEventSchema>;\nexport type WsServerEvent = z.infer<typeof wsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAMX,MAAM,8BAA8B,EACxC,OAAO;AAAA,EACN,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;AAAA,EAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACrC,sBAAsB,EAAE,OAAO,EAAE,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AC5B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EACJ,OAAO;AAAA,IACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,CAAC,EACA,SAAS;AAAA,EACZ,SAAS,EAAE,OAAO,EAAE,SAAS;AAC/B,CAAC;AAEM,MAAM,sBAAsB,EAAE,mBAAmB,QAAQ;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/agents-plugin-openai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "OpenAI plugin for LiveKit Node Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@types/ws": "^8.5.10",
|
|
34
34
|
"tsup": "^8.3.5",
|
|
35
35
|
"typescript": "^5.0.0",
|
|
36
|
-
"@livekit/agents": "1.
|
|
37
|
-
"@livekit/agents-plugin-silero": "1.
|
|
38
|
-
"@livekit/agents-plugins-test": "1.
|
|
36
|
+
"@livekit/agents": "1.8.1",
|
|
37
|
+
"@livekit/agents-plugin-silero": "1.8.1",
|
|
38
|
+
"@livekit/agents-plugins-test": "1.8.1"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@livekit/mutex": "^1.1.1",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@livekit/rtc-node": "^0.13.34",
|
|
47
47
|
"zod": "^3.25.76 || ^4.1.8",
|
|
48
|
-
"@livekit/agents": "1.
|
|
48
|
+
"@livekit/agents": "1.8.1"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|