@livekit/agents-plugin-openai 1.3.0 → 1.3.2
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/llm.cjs +1 -1
- package/dist/llm.cjs.map +1 -1
- package/dist/llm.js +1 -1
- package/dist/llm.js.map +1 -1
- package/dist/models.cjs.map +1 -1
- package/dist/models.d.cts +2 -2
- package/dist/models.d.ts +2 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/realtime/realtime_model.cjs +36 -31
- package/dist/realtime/realtime_model.cjs.map +1 -1
- package/dist/realtime/realtime_model.d.cts +1 -0
- package/dist/realtime/realtime_model.d.ts +1 -0
- package/dist/realtime/realtime_model.d.ts.map +1 -1
- package/dist/realtime/realtime_model.js +36 -31
- package/dist/realtime/realtime_model.js.map +1 -1
- package/dist/realtime/realtime_model.test.cjs +58 -0
- package/dist/realtime/realtime_model.test.cjs.map +1 -1
- package/dist/realtime/realtime_model.test.js +60 -2
- package/dist/realtime/realtime_model.test.js.map +1 -1
- package/package.json +7 -7
- package/src/llm.ts +1 -1
- package/src/models.ts +4 -14
- package/src/realtime/realtime_model.test.ts +91 -2
- package/src/realtime/realtime_model.ts +41 -34
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime/realtime_model.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport { describe, expect, it } from 'vitest';\nimport type * as api_proto from './api_proto.js';\nimport { livekitItemToOpenAIItem } from './realtime_model.js';\n\ndescribe('livekitItemToOpenAIItem', () => {\n describe('message items', () => {\n it('should use output_text type for assistant messages', async () => {\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: 'Hello, how can I help you?',\n id: 'test-assistant-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('output_text');\n expect((content as api_proto.OutputTextContent).text).toBe('Hello, how can I help you?');\n });\n\n it('should use input_text type for user messages', async () => {\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: 'What is the weather like?',\n id: 'test-user-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n expect((content as api_proto.InputTextContent).text).toBe('What is the weather like?');\n });\n\n it('should use input_text type for system messages', async () => {\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: 'You are a helpful assistant.',\n id: 'test-system-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should convert developer role to system role', async () => {\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: 'System instructions.',\n id: 'test-developer-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should handle multiple content items for assistant', async () => {\n const multiContentMessage = new llm.ChatMessage({\n role: 'assistant',\n content: ['First part.', 'Second part.'],\n id: 'test-multi-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(\n multiContentMessage,\n )) as api_proto.AssistantItem;\n\n expect(result.content).toHaveLength(2);\n const content0 = result.content[0]!;\n const content1 = result.content[1]!;\n expect(content0.type).toBe('output_text');\n expect(content1.type).toBe('output_text');\n });\n\n it('should convert image content to input_image for user messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: [imageContent],\n id: 'test-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_image');\n expect((content as api_proto.InputImageContent).image_url).toBe(\n `data:image/png;base64,${base64Data}`,\n );\n });\n\n it('should ignore image content for assistant messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: [imageContent],\n id: 'test-assistant-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for system messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: [imageContent],\n id: 'test-system-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for developer messages mapped to system', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: [imageContent],\n id: 'test-developer-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should handle mixed text and image content', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: ['Describe this image:', imageContent],\n id: 'test-mixed-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.content).toHaveLength(2);\n expect(result.content[0]!.type).toBe('input_text');\n expect(result.content[1]!.type).toBe('input_image');\n });\n });\n\n describe('function_call items', () => {\n it('should convert function call items correctly', async () => {\n const functionCall = new llm.FunctionCall({\n callId: 'call-123',\n name: 'get_weather',\n args: '{\"location\": \"San Francisco\"}',\n id: 'test-func-call',\n });\n\n const result = (await livekitItemToOpenAIItem(functionCall)) as api_proto.FunctionCallItem;\n\n expect(result.type).toBe('function_call');\n expect(result.id).toBe('test-func-call');\n expect(result.call_id).toBe('call-123');\n expect(result.name).toBe('get_weather');\n expect(result.arguments).toBe('{\"location\": \"San Francisco\"}');\n });\n });\n\n describe('function_call_output items', () => {\n it('should convert function call output items correctly', async () => {\n const functionOutput = new llm.FunctionCallOutput({\n callId: 'call-123',\n output: 'The weather in San Francisco is sunny.',\n isError: false,\n id: 'test-func-output',\n });\n\n const result = (await livekitItemToOpenAIItem(\n functionOutput,\n )) as api_proto.FunctionCallOutputItem;\n\n expect(result.type).toBe('function_call_output');\n expect(result.id).toBe('test-func-output');\n expect(result.call_id).toBe('call-123');\n expect(result.output).toBe('The weather in San Francisco is sunny.');\n });\n });\n});\n"],"mappings":";AAGA,oBAAoB;AACpB,oBAAqC;AAErC,4BAAwC;AAAA,IAExC,wBAAS,2BAA2B,MAAM;AACxC,8BAAS,iBAAiB,MAAM;AAC9B,0BAAG,sDAAsD,YAAY;AACnE,YAAM,mBAAmB,IAAI,kBAAI,YAAY;AAAA,QAC3C,MAAM;AAAA,QACN,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,UAAM,+CAAwB,gBAAgB;AAE9D,gCAAO,OAAO,IAAI,EAAE,KAAK,SAAS;AAClC,gCAAO,OAAO,IAAI,EAAE,KAAK,WAAW;AACpC,gCAAO,OAAO,OAAO,EAAE,aAAa,CAAC;AACrC,YAAM,UAAU,OAAO,QAAQ,CAAC;AAChC,gCAAO,QAAQ,IAAI,EAAE,KAAK,aAAa;AACvC,gCAAQ,QAAwC,IAAI,EAAE,KAAK,4BAA4B;AAAA,IACzF,CAAC;AAED,0BAAG,gDAAgD,YAAY;AAC7D,YAAM,cAAc,IAAI,kBAAI,YAAY;AAAA,QACtC,MAAM;AAAA,QACN,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,UAAM,+CAAwB,WAAW;AAEzD,gCAAO,OAAO,IAAI,EAAE,KAAK,SAAS;AAClC,gCAAO,OAAO,IAAI,EAAE,KAAK,MAAM;AAC/B,gCAAO,OAAO,OAAO,EAAE,aAAa,CAAC;AACrC,YAAM,UAAU,OAAO,QAAQ,CAAC;AAChC,gCAAO,QAAQ,IAAI,EAAE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,IAAI,EAAE,KAAK,YAAY;AACjD,gCAAO,OAAO,QAAQ,CAAC,EAAG,IAAI,EAAE,KAAK,aAAa;AAAA,IACpD,CAAC;AAAA,EACH,CAAC;AAED,8BAAS,uBAAuB,MAAM;AACpC,0BAAG,gDAAgD,YAAY;AAC7D,YAAM,eAAe,IAAI,kBAAI,aAAa;AAAA,QACxC,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,MAAM;AAAA,QACN,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,UAAM,+CAAwB,YAAY;AAE1D,gCAAO,OAAO,IAAI,EAAE,KAAK,eAAe;AACxC,gCAAO,OAAO,EAAE,EAAE,KAAK,gBAAgB;AACvC,gCAAO,OAAO,OAAO,EAAE,KAAK,UAAU;AACtC,gCAAO,OAAO,IAAI,EAAE,KAAK,aAAa;AACtC,gCAAO,OAAO,SAAS,EAAE,KAAK,+BAA+B;AAAA,IAC/D,CAAC;AAAA,EACH,CAAC;AAED,8BAAS,8BAA8B,MAAM;AAC3C,0BAAG,uDAAuD,YAAY;AACpE,YAAM,iBAAiB,IAAI,kBAAI,mBAAmB;AAAA,QAChD,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,UAAM;AAAA,QACpB;AAAA,MACF;AAEA,gCAAO,OAAO,IAAI,EAAE,KAAK,sBAAsB;AAC/C,gCAAO,OAAO,EAAE,EAAE,KAAK,kBAAkB;AACzC,gCAAO,OAAO,OAAO,EAAE,KAAK,UAAU;AACtC,gCAAO,OAAO,MAAM,EAAE,KAAK,wCAAwC;AAAA,IACrE,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/realtime/realtime_model.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport { afterEach, describe, expect, it, vi } from 'vitest';\nimport type * as api_proto from './api_proto.js';\nimport { RealtimeModel, livekitItemToOpenAIItem } from './realtime_model.js';\n\ndescribe('livekitItemToOpenAIItem', () => {\n describe('message items', () => {\n it('should use output_text type for assistant messages', async () => {\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: 'Hello, how can I help you?',\n id: 'test-assistant-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('output_text');\n expect((content as api_proto.OutputTextContent).text).toBe('Hello, how can I help you?');\n });\n\n it('should use input_text type for user messages', async () => {\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: 'What is the weather like?',\n id: 'test-user-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n expect((content as api_proto.InputTextContent).text).toBe('What is the weather like?');\n });\n\n it('should use input_text type for system messages', async () => {\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: 'You are a helpful assistant.',\n id: 'test-system-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should convert developer role to system role', async () => {\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: 'System instructions.',\n id: 'test-developer-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should handle multiple content items for assistant', async () => {\n const multiContentMessage = new llm.ChatMessage({\n role: 'assistant',\n content: ['First part.', 'Second part.'],\n id: 'test-multi-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(\n multiContentMessage,\n )) as api_proto.AssistantItem;\n\n expect(result.content).toHaveLength(2);\n const content0 = result.content[0]!;\n const content1 = result.content[1]!;\n expect(content0.type).toBe('output_text');\n expect(content1.type).toBe('output_text');\n });\n\n it('should convert image content to input_image for user messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: [imageContent],\n id: 'test-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_image');\n expect((content as api_proto.InputImageContent).image_url).toBe(\n `data:image/png;base64,${base64Data}`,\n );\n });\n\n it('should ignore image content for assistant messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: [imageContent],\n id: 'test-assistant-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for system messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: [imageContent],\n id: 'test-system-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for developer messages mapped to system', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: [imageContent],\n id: 'test-developer-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should handle mixed text and image content', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: ['Describe this image:', imageContent],\n id: 'test-mixed-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.content).toHaveLength(2);\n expect(result.content[0]!.type).toBe('input_text');\n expect(result.content[1]!.type).toBe('input_image');\n });\n });\n\n describe('function_call items', () => {\n it('should convert function call items correctly', async () => {\n const functionCall = new llm.FunctionCall({\n callId: 'call-123',\n name: 'get_weather',\n args: '{\"location\": \"San Francisco\"}',\n id: 'test-func-call',\n });\n\n const result = (await livekitItemToOpenAIItem(functionCall)) as api_proto.FunctionCallItem;\n\n expect(result.type).toBe('function_call');\n expect(result.id).toBe('test-func-call');\n expect(result.call_id).toBe('call-123');\n expect(result.name).toBe('get_weather');\n expect(result.arguments).toBe('{\"location\": \"San Francisco\"}');\n });\n });\n\n describe('function_call_output items', () => {\n it('should convert function call output items correctly', async () => {\n const functionOutput = new llm.FunctionCallOutput({\n callId: 'call-123',\n output: 'The weather in San Francisco is sunny.',\n isError: false,\n id: 'test-func-output',\n });\n\n const result = (await livekitItemToOpenAIItem(\n functionOutput,\n )) as api_proto.FunctionCallOutputItem;\n\n expect(result.type).toBe('function_call_output');\n expect(result.id).toBe('test-func-output');\n expect(result.call_id).toBe('call-123');\n expect(result.output).toBe('The weather in San Francisco is sunny.');\n });\n });\n});\n\ndescribe('RealtimeSession.updateOptions', () => {\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n const stubTaskRuntime = () => {\n // Prevent background realtime tasks from opening network connections in unit tests.\n vi.spyOn(llm, 'RealtimeSession', 'get');\n const agentsModule = require('@livekit/agents') as typeof import('@livekit/agents'); // eslint-disable-line @typescript-eslint/no-var-requires\n vi.spyOn(agentsModule.Task, 'from').mockReturnValue({\n cancel: vi.fn(),\n done: true,\n result: Promise.resolve(undefined),\n } as unknown as import('@livekit/agents').Task<void>);\n };\n\n it('emits session.update when toolChoice changes', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const session = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n };\n const sendEventSpy = vi.spyOn(session, 'sendEvent');\n sendEventSpy.mockClear();\n\n session.updateOptions({ toolChoice: 'required' });\n\n expect(sendEventSpy).toHaveBeenCalledTimes(1);\n expect(sendEventSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n type: 'session.update',\n session: expect.objectContaining({\n type: 'realtime',\n tool_choice: 'required',\n }),\n }),\n );\n });\n\n it('does not emit session.update when toolChoice is unchanged', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const session = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n };\n const sendEventSpy = vi.spyOn(session, 'sendEvent');\n sendEventSpy.mockClear();\n\n session.updateOptions({ toolChoice: 'auto' });\n\n expect(sendEventSpy).not.toHaveBeenCalled();\n });\n\n it('keeps toolChoice state isolated across sessions from same model', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const sessionA = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n _options: { toolChoice?: llm.ToolChoice };\n };\n const sessionB = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n _options: { toolChoice?: llm.ToolChoice };\n };\n\n const sendEventSpyA = vi.spyOn(sessionA, 'sendEvent');\n const sendEventSpyB = vi.spyOn(sessionB, 'sendEvent');\n sendEventSpyA.mockClear();\n sendEventSpyB.mockClear();\n\n sessionA.updateOptions({ toolChoice: 'required' });\n\n expect(sessionA._options.toolChoice).toBe('required');\n expect(sessionB._options.toolChoice).toBe('auto');\n expect(sendEventSpyA).toHaveBeenCalledTimes(1);\n expect(sendEventSpyB).toHaveBeenCalledTimes(0);\n\n sessionB.updateOptions({ toolChoice: 'required' });\n expect(sendEventSpyB).toHaveBeenCalledTimes(1);\n });\n});\n"],"mappings":";AAGA,oBAAoB;AACpB,oBAAoD;AAEpD,4BAAuD;AAAA,IAEvD,wBAAS,2BAA2B,MAAM;AACxC,8BAAS,iBAAiB,MAAM;AAC9B,0BAAG,sDAAsD,YAAY;AACnE,YAAM,mBAAmB,IAAI,kBAAI,YAAY;AAAA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
|
-
import { livekitItemToOpenAIItem } from "./realtime_model.js";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { RealtimeModel, livekitItemToOpenAIItem } from "./realtime_model.js";
|
|
4
4
|
describe("livekitItemToOpenAIItem", () => {
|
|
5
5
|
describe("message items", () => {
|
|
6
6
|
it("should use output_text type for assistant messages", async () => {
|
|
@@ -192,4 +192,62 @@ describe("livekitItemToOpenAIItem", () => {
|
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
});
|
|
195
|
+
describe("RealtimeSession.updateOptions", () => {
|
|
196
|
+
afterEach(() => {
|
|
197
|
+
vi.restoreAllMocks();
|
|
198
|
+
});
|
|
199
|
+
const stubTaskRuntime = () => {
|
|
200
|
+
vi.spyOn(llm, "RealtimeSession", "get");
|
|
201
|
+
const agentsModule = require("@livekit/agents");
|
|
202
|
+
vi.spyOn(agentsModule.Task, "from").mockReturnValue({
|
|
203
|
+
cancel: vi.fn(),
|
|
204
|
+
done: true,
|
|
205
|
+
result: Promise.resolve(void 0)
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
it("emits session.update when toolChoice changes", () => {
|
|
209
|
+
stubTaskRuntime();
|
|
210
|
+
const model = new RealtimeModel({ apiKey: "test-key" });
|
|
211
|
+
const session = model.session();
|
|
212
|
+
const sendEventSpy = vi.spyOn(session, "sendEvent");
|
|
213
|
+
sendEventSpy.mockClear();
|
|
214
|
+
session.updateOptions({ toolChoice: "required" });
|
|
215
|
+
expect(sendEventSpy).toHaveBeenCalledTimes(1);
|
|
216
|
+
expect(sendEventSpy).toHaveBeenCalledWith(
|
|
217
|
+
expect.objectContaining({
|
|
218
|
+
type: "session.update",
|
|
219
|
+
session: expect.objectContaining({
|
|
220
|
+
type: "realtime",
|
|
221
|
+
tool_choice: "required"
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
it("does not emit session.update when toolChoice is unchanged", () => {
|
|
227
|
+
stubTaskRuntime();
|
|
228
|
+
const model = new RealtimeModel({ apiKey: "test-key" });
|
|
229
|
+
const session = model.session();
|
|
230
|
+
const sendEventSpy = vi.spyOn(session, "sendEvent");
|
|
231
|
+
sendEventSpy.mockClear();
|
|
232
|
+
session.updateOptions({ toolChoice: "auto" });
|
|
233
|
+
expect(sendEventSpy).not.toHaveBeenCalled();
|
|
234
|
+
});
|
|
235
|
+
it("keeps toolChoice state isolated across sessions from same model", () => {
|
|
236
|
+
stubTaskRuntime();
|
|
237
|
+
const model = new RealtimeModel({ apiKey: "test-key" });
|
|
238
|
+
const sessionA = model.session();
|
|
239
|
+
const sessionB = model.session();
|
|
240
|
+
const sendEventSpyA = vi.spyOn(sessionA, "sendEvent");
|
|
241
|
+
const sendEventSpyB = vi.spyOn(sessionB, "sendEvent");
|
|
242
|
+
sendEventSpyA.mockClear();
|
|
243
|
+
sendEventSpyB.mockClear();
|
|
244
|
+
sessionA.updateOptions({ toolChoice: "required" });
|
|
245
|
+
expect(sessionA._options.toolChoice).toBe("required");
|
|
246
|
+
expect(sessionB._options.toolChoice).toBe("auto");
|
|
247
|
+
expect(sendEventSpyA).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(sendEventSpyB).toHaveBeenCalledTimes(0);
|
|
249
|
+
sessionB.updateOptions({ toolChoice: "required" });
|
|
250
|
+
expect(sendEventSpyB).toHaveBeenCalledTimes(1);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
195
253
|
//# sourceMappingURL=realtime_model.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime/realtime_model.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport { describe, expect, it } from 'vitest';\nimport type * as api_proto from './api_proto.js';\nimport { livekitItemToOpenAIItem } from './realtime_model.js';\n\ndescribe('livekitItemToOpenAIItem', () => {\n describe('message items', () => {\n it('should use output_text type for assistant messages', async () => {\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: 'Hello, how can I help you?',\n id: 'test-assistant-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('output_text');\n expect((content as api_proto.OutputTextContent).text).toBe('Hello, how can I help you?');\n });\n\n it('should use input_text type for user messages', async () => {\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: 'What is the weather like?',\n id: 'test-user-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n expect((content as api_proto.InputTextContent).text).toBe('What is the weather like?');\n });\n\n it('should use input_text type for system messages', async () => {\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: 'You are a helpful assistant.',\n id: 'test-system-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should convert developer role to system role', async () => {\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: 'System instructions.',\n id: 'test-developer-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should handle multiple content items for assistant', async () => {\n const multiContentMessage = new llm.ChatMessage({\n role: 'assistant',\n content: ['First part.', 'Second part.'],\n id: 'test-multi-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(\n multiContentMessage,\n )) as api_proto.AssistantItem;\n\n expect(result.content).toHaveLength(2);\n const content0 = result.content[0]!;\n const content1 = result.content[1]!;\n expect(content0.type).toBe('output_text');\n expect(content1.type).toBe('output_text');\n });\n\n it('should convert image content to input_image for user messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: [imageContent],\n id: 'test-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_image');\n expect((content as api_proto.InputImageContent).image_url).toBe(\n `data:image/png;base64,${base64Data}`,\n );\n });\n\n it('should ignore image content for assistant messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: [imageContent],\n id: 'test-assistant-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for system messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: [imageContent],\n id: 'test-system-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for developer messages mapped to system', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: [imageContent],\n id: 'test-developer-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should handle mixed text and image content', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: ['Describe this image:', imageContent],\n id: 'test-mixed-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.content).toHaveLength(2);\n expect(result.content[0]!.type).toBe('input_text');\n expect(result.content[1]!.type).toBe('input_image');\n });\n });\n\n describe('function_call items', () => {\n it('should convert function call items correctly', async () => {\n const functionCall = new llm.FunctionCall({\n callId: 'call-123',\n name: 'get_weather',\n args: '{\"location\": \"San Francisco\"}',\n id: 'test-func-call',\n });\n\n const result = (await livekitItemToOpenAIItem(functionCall)) as api_proto.FunctionCallItem;\n\n expect(result.type).toBe('function_call');\n expect(result.id).toBe('test-func-call');\n expect(result.call_id).toBe('call-123');\n expect(result.name).toBe('get_weather');\n expect(result.arguments).toBe('{\"location\": \"San Francisco\"}');\n });\n });\n\n describe('function_call_output items', () => {\n it('should convert function call output items correctly', async () => {\n const functionOutput = new llm.FunctionCallOutput({\n callId: 'call-123',\n output: 'The weather in San Francisco is sunny.',\n isError: false,\n id: 'test-func-output',\n });\n\n const result = (await livekitItemToOpenAIItem(\n functionOutput,\n )) as api_proto.FunctionCallOutputItem;\n\n expect(result.type).toBe('function_call_output');\n expect(result.id).toBe('test-func-output');\n expect(result.call_id).toBe('call-123');\n expect(result.output).toBe('The weather in San Francisco is sunny.');\n });\n });\n});\n"],"mappings":"AAGA,SAAS,WAAW;AACpB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,+BAA+B;AAExC,SAAS,2BAA2B,MAAM;AACxC,WAAS,iBAAiB,MAAM;AAC9B,OAAG,sDAAsD,YAAY;AACnE,YAAM,mBAAmB,IAAI,IAAI,YAAY;AAAA,QAC3C,MAAM;AAAA,QACN,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,MAAM,wBAAwB,gBAAgB;AAE9D,aAAO,OAAO,IAAI,EAAE,KAAK,SAAS;AAClC,aAAO,OAAO,IAAI,EAAE,KAAK,WAAW;AACpC,aAAO,OAAO,OAAO,EAAE,aAAa,CAAC;AACrC,YAAM,UAAU,OAAO,QAAQ,CAAC;AAChC,aAAO,QAAQ,IAAI,EAAE,KAAK,aAAa;AACvC,aAAQ,QAAwC,IAAI,EAAE,KAAK,4BAA4B;AAAA,IACzF,CAAC;AAED,OAAG,gDAAgD,YAAY;AAC7D,YAAM,cAAc,IAAI,IAAI,YAAY;AAAA,QACtC,MAAM;AAAA,QACN,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,MAAM,wBAAwB,WAAW;AAEzD,aAAO,OAAO,IAAI,EAAE,KAAK,SAAS;AAClC,aAAO,OAAO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AClC,aAAO,OAAO,OAAO,EAAE,aAAa,CAAC;AACrC,aAAO,OAAO,QAAQ,CAAC,EAAG,IAAI,EAAE,KAAK,YAAY;AACjD,aAAO,OAAO,QAAQ,CAAC,EAAG,IAAI,EAAE,KAAK,aAAa;AAAA,IACpD,CAAC;AAAA,EACH,CAAC;AAED,WAAS,uBAAuB,MAAM;AACpC,OAAG,gDAAgD,YAAY;AAC7D,YAAM,eAAe,IAAI,IAAI,aAAa;AAAA,QACxC,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,MAAM;AAAA,QACN,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,MAAM,wBAAwB,YAAY;AAE1D,aAAO,OAAO,IAAI,EAAE,KAAK,eAAe;AACxC,aAAO,OAAO,EAAE,EAAE,KAAK,gBAAgB;AACvC,aAAO,OAAO,OAAO,EAAE,KAAK,UAAU;AACtC,aAAO,OAAO,IAAI,EAAE,KAAK,aAAa;AACtC,aAAO,OAAO,SAAS,EAAE,KAAK,+BAA+B;AAAA,IAC/D,CAAC;AAAA,EACH,CAAC;AAED,WAAS,8BAA8B,MAAM;AAC3C,OAAG,uDAAuD,YAAY;AACpE,YAAM,iBAAiB,IAAI,IAAI,mBAAmB;AAAA,QAChD,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,IAAI;AAAA,MACN,CAAC;AAED,YAAM,SAAU,MAAM;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,OAAO,IAAI,EAAE,KAAK,sBAAsB;AAC/C,aAAO,OAAO,EAAE,EAAE,KAAK,kBAAkB;AACzC,aAAO,OAAO,OAAO,EAAE,KAAK,UAAU;AACtC,aAAO,OAAO,MAAM,EAAE,KAAK,wCAAwC;AAAA,IACrE,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/realtime/realtime_model.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { llm } from '@livekit/agents';\nimport { afterEach, describe, expect, it, vi } from 'vitest';\nimport type * as api_proto from './api_proto.js';\nimport { RealtimeModel, livekitItemToOpenAIItem } from './realtime_model.js';\n\ndescribe('livekitItemToOpenAIItem', () => {\n describe('message items', () => {\n it('should use output_text type for assistant messages', async () => {\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: 'Hello, how can I help you?',\n id: 'test-assistant-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('output_text');\n expect((content as api_proto.OutputTextContent).text).toBe('Hello, how can I help you?');\n });\n\n it('should use input_text type for user messages', async () => {\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: 'What is the weather like?',\n id: 'test-user-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n expect((content as api_proto.InputTextContent).text).toBe('What is the weather like?');\n });\n\n it('should use input_text type for system messages', async () => {\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: 'You are a helpful assistant.',\n id: 'test-system-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should convert developer role to system role', async () => {\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: 'System instructions.',\n id: 'test-developer-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n const content = result.content[0]!;\n expect(content.type).toBe('input_text');\n });\n\n it('should handle multiple content items for assistant', async () => {\n const multiContentMessage = new llm.ChatMessage({\n role: 'assistant',\n content: ['First part.', 'Second part.'],\n id: 'test-multi-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(\n multiContentMessage,\n )) as api_proto.AssistantItem;\n\n expect(result.content).toHaveLength(2);\n const content0 = result.content[0]!;\n const content1 = result.content[1]!;\n expect(content0.type).toBe('output_text');\n expect(content1.type).toBe('output_text');\n });\n\n it('should convert image content to input_image for user messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: [imageContent],\n id: 'test-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('user');\n expect(result.content).toHaveLength(1);\n const content = result.content[0]!;\n expect(content.type).toBe('input_image');\n expect((content as api_proto.InputImageContent).image_url).toBe(\n `data:image/png;base64,${base64Data}`,\n );\n });\n\n it('should ignore image content for assistant messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const assistantMessage = new llm.ChatMessage({\n role: 'assistant',\n content: [imageContent],\n id: 'test-assistant-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(assistantMessage)) as api_proto.AssistantItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('assistant');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for system messages', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const systemMessage = new llm.ChatMessage({\n role: 'system',\n content: [imageContent],\n id: 'test-system-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(systemMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should ignore image content for developer messages mapped to system', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const developerMessage = new llm.ChatMessage({\n role: 'developer',\n content: [imageContent],\n id: 'test-developer-image-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(developerMessage)) as api_proto.SystemItem;\n\n expect(result.type).toBe('message');\n expect(result.role).toBe('system');\n expect(result.content).toHaveLength(0);\n });\n\n it('should handle mixed text and image content', async () => {\n const base64Data =\n 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';\n const imageContent = llm.createImageContent({\n image: `data:image/png;base64,${base64Data}`,\n mimeType: 'image/png',\n });\n\n const userMessage = new llm.ChatMessage({\n role: 'user',\n content: ['Describe this image:', imageContent],\n id: 'test-mixed-msg',\n });\n\n const result = (await livekitItemToOpenAIItem(userMessage)) as api_proto.UserItem;\n\n expect(result.type).toBe('message');\n expect(result.content).toHaveLength(2);\n expect(result.content[0]!.type).toBe('input_text');\n expect(result.content[1]!.type).toBe('input_image');\n });\n });\n\n describe('function_call items', () => {\n it('should convert function call items correctly', async () => {\n const functionCall = new llm.FunctionCall({\n callId: 'call-123',\n name: 'get_weather',\n args: '{\"location\": \"San Francisco\"}',\n id: 'test-func-call',\n });\n\n const result = (await livekitItemToOpenAIItem(functionCall)) as api_proto.FunctionCallItem;\n\n expect(result.type).toBe('function_call');\n expect(result.id).toBe('test-func-call');\n expect(result.call_id).toBe('call-123');\n expect(result.name).toBe('get_weather');\n expect(result.arguments).toBe('{\"location\": \"San Francisco\"}');\n });\n });\n\n describe('function_call_output items', () => {\n it('should convert function call output items correctly', async () => {\n const functionOutput = new llm.FunctionCallOutput({\n callId: 'call-123',\n output: 'The weather in San Francisco is sunny.',\n isError: false,\n id: 'test-func-output',\n });\n\n const result = (await livekitItemToOpenAIItem(\n functionOutput,\n )) as api_proto.FunctionCallOutputItem;\n\n expect(result.type).toBe('function_call_output');\n expect(result.id).toBe('test-func-output');\n expect(result.call_id).toBe('call-123');\n expect(result.output).toBe('The weather in San Francisco is sunny.');\n });\n });\n});\n\ndescribe('RealtimeSession.updateOptions', () => {\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n const stubTaskRuntime = () => {\n // Prevent background realtime tasks from opening network connections in unit tests.\n vi.spyOn(llm, 'RealtimeSession', 'get');\n const agentsModule = require('@livekit/agents') as typeof import('@livekit/agents'); // eslint-disable-line @typescript-eslint/no-var-requires\n vi.spyOn(agentsModule.Task, 'from').mockReturnValue({\n cancel: vi.fn(),\n done: true,\n result: Promise.resolve(undefined),\n } as unknown as import('@livekit/agents').Task<void>);\n };\n\n it('emits session.update when toolChoice changes', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const session = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n };\n const sendEventSpy = vi.spyOn(session, 'sendEvent');\n sendEventSpy.mockClear();\n\n session.updateOptions({ toolChoice: 'required' });\n\n expect(sendEventSpy).toHaveBeenCalledTimes(1);\n expect(sendEventSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n type: 'session.update',\n session: expect.objectContaining({\n type: 'realtime',\n tool_choice: 'required',\n }),\n }),\n );\n });\n\n it('does not emit session.update when toolChoice is unchanged', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const session = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n };\n const sendEventSpy = vi.spyOn(session, 'sendEvent');\n sendEventSpy.mockClear();\n\n session.updateOptions({ toolChoice: 'auto' });\n\n expect(sendEventSpy).not.toHaveBeenCalled();\n });\n\n it('keeps toolChoice state isolated across sessions from same model', () => {\n stubTaskRuntime();\n\n const model = new RealtimeModel({ apiKey: 'test-key' });\n const sessionA = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n _options: { toolChoice?: llm.ToolChoice };\n };\n const sessionB = model.session() as unknown as {\n updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;\n sendEvent: (event: api_proto.ClientEvent) => void;\n _options: { toolChoice?: llm.ToolChoice };\n };\n\n const sendEventSpyA = vi.spyOn(sessionA, 'sendEvent');\n const sendEventSpyB = vi.spyOn(sessionB, 'sendEvent');\n sendEventSpyA.mockClear();\n sendEventSpyB.mockClear();\n\n sessionA.updateOptions({ toolChoice: 'required' });\n\n expect(sessionA._options.toolChoice).toBe('required');\n expect(sessionB._options.toolChoice).toBe('auto');\n expect(sendEventSpyA).toHaveBeenCalledTimes(1);\n expect(sendEventSpyB).toHaveBeenCalledTimes(0);\n\n sessionB.updateOptions({ toolChoice: 'required' });\n expect(sendEventSpyB).toHaveBeenCalledTimes(1);\n });\n});\n"],"mappings":"AAGA,SAAS,WAAW;AACpB,SAAS,WAAW,UAAU,QAAQ,IAAI,UAAU;AAEpD,SAAS,eAAe,+BAA+B;AAEvD,SAAS,2BAA2B,MAAM;AACxC,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.2",
|
|
4
4
|
"description": "OpenAI plugin for LiveKit Node Agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@livekit/rtc-node": "^0.13.
|
|
28
|
+
"@livekit/rtc-node": "^0.13.27",
|
|
29
29
|
"@microsoft/api-extractor": "^7.35.0",
|
|
30
30
|
"@types/ws": "^8.5.10",
|
|
31
31
|
"tsup": "^8.3.5",
|
|
32
32
|
"typescript": "^5.0.0",
|
|
33
|
-
"@livekit/agents": "1.3.
|
|
34
|
-
"@livekit/agents-plugin-silero": "1.3.
|
|
35
|
-
"@livekit/agents-plugins-test": "1.3.
|
|
33
|
+
"@livekit/agents": "1.3.2",
|
|
34
|
+
"@livekit/agents-plugin-silero": "1.3.2",
|
|
35
|
+
"@livekit/agents-plugins-test": "1.3.2"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@livekit/mutex": "^1.1.1",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"ws": "^8.18.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@livekit/rtc-node": "^0.13.
|
|
43
|
+
"@livekit/rtc-node": "^0.13.27",
|
|
44
44
|
"zod": "^3.25.76 || ^4.1.8",
|
|
45
|
-
"@livekit/agents": "1.3.
|
|
45
|
+
"@livekit/agents": "1.3.2"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup --onSuccess \"pnpm build:types\"",
|
package/src/llm.ts
CHANGED
package/src/models.ts
CHANGED
|
@@ -100,22 +100,12 @@ export type PerplexityChatModels =
|
|
|
100
100
|
| 'llama-3.1-70b-instruct';
|
|
101
101
|
|
|
102
102
|
export type GroqChatModels =
|
|
103
|
-
| 'llama-3.1-405b-reasoning'
|
|
104
103
|
| 'llama-3.1-8b-instant'
|
|
105
104
|
| 'llama-3.3-70b-versatile'
|
|
106
|
-
| '
|
|
107
|
-
| '
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| 'llama3-8b-8192'
|
|
111
|
-
| 'mixtral-8x7b-32768'
|
|
112
|
-
| 'gemma-7b-it'
|
|
113
|
-
| 'gemma2-9b-it';
|
|
114
|
-
|
|
115
|
-
export type GroqAudioModels =
|
|
116
|
-
| 'whisper-large-v3'
|
|
117
|
-
| 'distil-whisper-large-v3-en'
|
|
118
|
-
| 'whisper-large-v3-turbo';
|
|
105
|
+
| 'openai/gpt-oss-120b'
|
|
106
|
+
| 'openai/gpt-oss-20b';
|
|
107
|
+
|
|
108
|
+
export type GroqAudioModels = 'whisper-large-v3' | 'whisper-large-v3-turbo';
|
|
119
109
|
|
|
120
110
|
export type DeepSeekChatModels = 'deepseek-coder' | 'deepseek-chat';
|
|
121
111
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { llm } from '@livekit/agents';
|
|
5
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
import type * as api_proto from './api_proto.js';
|
|
7
|
-
import { livekitItemToOpenAIItem } from './realtime_model.js';
|
|
7
|
+
import { RealtimeModel, livekitItemToOpenAIItem } from './realtime_model.js';
|
|
8
8
|
|
|
9
9
|
describe('livekitItemToOpenAIItem', () => {
|
|
10
10
|
describe('message items', () => {
|
|
@@ -242,3 +242,92 @@ describe('livekitItemToOpenAIItem', () => {
|
|
|
242
242
|
});
|
|
243
243
|
});
|
|
244
244
|
});
|
|
245
|
+
|
|
246
|
+
describe('RealtimeSession.updateOptions', () => {
|
|
247
|
+
afterEach(() => {
|
|
248
|
+
vi.restoreAllMocks();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const stubTaskRuntime = () => {
|
|
252
|
+
// Prevent background realtime tasks from opening network connections in unit tests.
|
|
253
|
+
vi.spyOn(llm, 'RealtimeSession', 'get');
|
|
254
|
+
const agentsModule = require('@livekit/agents') as typeof import('@livekit/agents'); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
255
|
+
vi.spyOn(agentsModule.Task, 'from').mockReturnValue({
|
|
256
|
+
cancel: vi.fn(),
|
|
257
|
+
done: true,
|
|
258
|
+
result: Promise.resolve(undefined),
|
|
259
|
+
} as unknown as import('@livekit/agents').Task<void>);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
it('emits session.update when toolChoice changes', () => {
|
|
263
|
+
stubTaskRuntime();
|
|
264
|
+
|
|
265
|
+
const model = new RealtimeModel({ apiKey: 'test-key' });
|
|
266
|
+
const session = model.session() as unknown as {
|
|
267
|
+
updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;
|
|
268
|
+
sendEvent: (event: api_proto.ClientEvent) => void;
|
|
269
|
+
};
|
|
270
|
+
const sendEventSpy = vi.spyOn(session, 'sendEvent');
|
|
271
|
+
sendEventSpy.mockClear();
|
|
272
|
+
|
|
273
|
+
session.updateOptions({ toolChoice: 'required' });
|
|
274
|
+
|
|
275
|
+
expect(sendEventSpy).toHaveBeenCalledTimes(1);
|
|
276
|
+
expect(sendEventSpy).toHaveBeenCalledWith(
|
|
277
|
+
expect.objectContaining({
|
|
278
|
+
type: 'session.update',
|
|
279
|
+
session: expect.objectContaining({
|
|
280
|
+
type: 'realtime',
|
|
281
|
+
tool_choice: 'required',
|
|
282
|
+
}),
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('does not emit session.update when toolChoice is unchanged', () => {
|
|
288
|
+
stubTaskRuntime();
|
|
289
|
+
|
|
290
|
+
const model = new RealtimeModel({ apiKey: 'test-key' });
|
|
291
|
+
const session = model.session() as unknown as {
|
|
292
|
+
updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;
|
|
293
|
+
sendEvent: (event: api_proto.ClientEvent) => void;
|
|
294
|
+
};
|
|
295
|
+
const sendEventSpy = vi.spyOn(session, 'sendEvent');
|
|
296
|
+
sendEventSpy.mockClear();
|
|
297
|
+
|
|
298
|
+
session.updateOptions({ toolChoice: 'auto' });
|
|
299
|
+
|
|
300
|
+
expect(sendEventSpy).not.toHaveBeenCalled();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('keeps toolChoice state isolated across sessions from same model', () => {
|
|
304
|
+
stubTaskRuntime();
|
|
305
|
+
|
|
306
|
+
const model = new RealtimeModel({ apiKey: 'test-key' });
|
|
307
|
+
const sessionA = model.session() as unknown as {
|
|
308
|
+
updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;
|
|
309
|
+
sendEvent: (event: api_proto.ClientEvent) => void;
|
|
310
|
+
_options: { toolChoice?: llm.ToolChoice };
|
|
311
|
+
};
|
|
312
|
+
const sessionB = model.session() as unknown as {
|
|
313
|
+
updateOptions: (opts: { toolChoice?: llm.ToolChoice }) => void;
|
|
314
|
+
sendEvent: (event: api_proto.ClientEvent) => void;
|
|
315
|
+
_options: { toolChoice?: llm.ToolChoice };
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const sendEventSpyA = vi.spyOn(sessionA, 'sendEvent');
|
|
319
|
+
const sendEventSpyB = vi.spyOn(sessionB, 'sendEvent');
|
|
320
|
+
sendEventSpyA.mockClear();
|
|
321
|
+
sendEventSpyB.mockClear();
|
|
322
|
+
|
|
323
|
+
sessionA.updateOptions({ toolChoice: 'required' });
|
|
324
|
+
|
|
325
|
+
expect(sessionA._options.toolChoice).toBe('required');
|
|
326
|
+
expect(sessionB._options.toolChoice).toBe('auto');
|
|
327
|
+
expect(sendEventSpyA).toHaveBeenCalledTimes(1);
|
|
328
|
+
expect(sendEventSpyB).toHaveBeenCalledTimes(0);
|
|
329
|
+
|
|
330
|
+
sessionB.updateOptions({ toolChoice: 'required' });
|
|
331
|
+
expect(sendEventSpyB).toHaveBeenCalledTimes(1);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
@@ -415,6 +415,10 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
415
415
|
private inputResampler?: AudioResampler;
|
|
416
416
|
private instructions?: string;
|
|
417
417
|
private oaiRealtimeModel: RealtimeModel;
|
|
418
|
+
// Ref: python livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py - 795-797 lines
|
|
419
|
+
// per-session copy of options so updateOptions can diff against the session's
|
|
420
|
+
// own state instead of the shared model-level state.
|
|
421
|
+
private _options: RealtimeOptions;
|
|
418
422
|
private currentGeneration?: ResponseGeneration;
|
|
419
423
|
private responseCreatedFutures: { [id: string]: CreateResponseHandle } = {};
|
|
420
424
|
|
|
@@ -443,6 +447,12 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
443
447
|
super(realtimeModel);
|
|
444
448
|
|
|
445
449
|
this.oaiRealtimeModel = realtimeModel;
|
|
450
|
+
// Ref: python livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py - 796-797 lines
|
|
451
|
+
// Shallow copy (equivalent to Python's `dataclasses.replace`) so each
|
|
452
|
+
// session has independent option state. Without this, updateOptions would
|
|
453
|
+
// mutate the shared model._options before computing its diff, causing the
|
|
454
|
+
// diff to always see "no change" and never send session.update.
|
|
455
|
+
this._options = { ...realtimeModel._options };
|
|
446
456
|
|
|
447
457
|
this.#task = Task.from(({ signal }) => this.#mainTask(signal));
|
|
448
458
|
|
|
@@ -460,7 +470,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
460
470
|
}
|
|
461
471
|
|
|
462
472
|
private createSessionUpdateEvent(): api_proto.SessionUpdateEvent {
|
|
463
|
-
const opts = this.
|
|
473
|
+
const opts = this._options;
|
|
464
474
|
const maxOutputTokens =
|
|
465
475
|
opts.maxResponseOutputTokens === Infinity ? 'inf' : opts.maxResponseOutputTokens;
|
|
466
476
|
|
|
@@ -722,13 +732,12 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
722
732
|
}
|
|
723
733
|
}
|
|
724
734
|
|
|
725
|
-
const isLegacyAzure =
|
|
726
|
-
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
735
|
+
const isLegacyAzure = this._options.isAzure && !!this._options.apiVersion;
|
|
727
736
|
return {
|
|
728
737
|
type: 'session.update',
|
|
729
738
|
session: {
|
|
730
739
|
...(!isLegacyAzure && { type: 'realtime' }),
|
|
731
|
-
model: this.
|
|
740
|
+
model: this._options.model,
|
|
732
741
|
tools: oaiTools,
|
|
733
742
|
},
|
|
734
743
|
event_id: shortuuid('tools_update_'),
|
|
@@ -736,8 +745,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
736
745
|
}
|
|
737
746
|
|
|
738
747
|
async updateInstructions(_instructions: string): Promise<void> {
|
|
739
|
-
const isLegacyAzure =
|
|
740
|
-
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
748
|
+
const isLegacyAzure = this._options.isAzure && !!this._options.apiVersion;
|
|
741
749
|
const eventId = shortuuid('instructions_update_');
|
|
742
750
|
this.sendEvent({
|
|
743
751
|
type: 'session.update',
|
|
@@ -751,20 +759,19 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
751
759
|
}
|
|
752
760
|
|
|
753
761
|
updateOptions({ toolChoice }: { toolChoice?: llm.ToolChoice }): void {
|
|
754
|
-
const currentToolChoice = toOaiToolChoice(this.
|
|
762
|
+
const currentToolChoice = toOaiToolChoice(this._options.toolChoice);
|
|
755
763
|
const nextToolChoice = toOaiToolChoice(toolChoice);
|
|
756
764
|
if (currentToolChoice === nextToolChoice) {
|
|
757
|
-
this.
|
|
765
|
+
this._options.toolChoice = toolChoice;
|
|
758
766
|
return;
|
|
759
767
|
}
|
|
760
768
|
|
|
761
|
-
const isLegacyAzure =
|
|
762
|
-
this.oaiRealtimeModel._options.isAzure && !!this.oaiRealtimeModel._options.apiVersion;
|
|
769
|
+
const isLegacyAzure = this._options.isAzure && !!this._options.apiVersion;
|
|
763
770
|
const options: api_proto.SessionUpdateEvent['session'] = {
|
|
764
771
|
...(!isLegacyAzure && { type: 'realtime' }),
|
|
765
772
|
};
|
|
766
773
|
|
|
767
|
-
this.
|
|
774
|
+
this._options.toolChoice = toolChoice;
|
|
768
775
|
options.tool_choice = toOaiToolChoice(toolChoice);
|
|
769
776
|
|
|
770
777
|
// TODO(brian): add other options here
|
|
@@ -889,32 +896,32 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
889
896
|
'User-Agent': 'LiveKit-Agents-JS',
|
|
890
897
|
};
|
|
891
898
|
|
|
892
|
-
if (this.
|
|
899
|
+
if (this._options.isAzure) {
|
|
893
900
|
// Microsoft API has two ways of authentication
|
|
894
901
|
// 1. Entra token set as `Bearer` token
|
|
895
902
|
// 2. API key set as `api_key` header (also accepts query string)
|
|
896
|
-
if (this.
|
|
897
|
-
headers.Authorization = `Bearer ${this.
|
|
898
|
-
} else if (this.
|
|
899
|
-
headers['api-key'] = this.
|
|
903
|
+
if (this._options.entraToken) {
|
|
904
|
+
headers.Authorization = `Bearer ${this._options.entraToken}`;
|
|
905
|
+
} else if (this._options.apiKey) {
|
|
906
|
+
headers['api-key'] = this._options.apiKey;
|
|
900
907
|
} else {
|
|
901
908
|
throw new Error('Microsoft API key or entraToken is required');
|
|
902
909
|
}
|
|
903
910
|
} else {
|
|
904
|
-
if (!this.
|
|
911
|
+
if (!this._options.apiKey) {
|
|
905
912
|
throw new Error(
|
|
906
913
|
'OpenAI API key is required but not set. Check OPENAI_API_KEY environment variable.',
|
|
907
914
|
);
|
|
908
915
|
}
|
|
909
|
-
headers.Authorization = `Bearer ${this.
|
|
916
|
+
headers.Authorization = `Bearer ${this._options.apiKey}`;
|
|
910
917
|
}
|
|
911
918
|
|
|
912
919
|
const url = processBaseURL({
|
|
913
|
-
baseURL: this.
|
|
914
|
-
model: this.
|
|
915
|
-
isAzure: this.
|
|
916
|
-
apiVersion: this.
|
|
917
|
-
azureDeployment: this.
|
|
920
|
+
baseURL: this._options.baseURL,
|
|
921
|
+
model: this._options.model,
|
|
922
|
+
isAzure: this._options.isAzure,
|
|
923
|
+
apiVersion: this._options.apiVersion,
|
|
924
|
+
azureDeployment: this._options.azureDeployment,
|
|
918
925
|
});
|
|
919
926
|
|
|
920
927
|
if (lkOaiDebug) {
|
|
@@ -928,7 +935,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
928
935
|
const timeout = setTimeout(() => {
|
|
929
936
|
ws.close();
|
|
930
937
|
reject(new Error('WebSocket connection timeout'));
|
|
931
|
-
}, this.
|
|
938
|
+
}, this._options.connOptions.timeoutMs);
|
|
932
939
|
|
|
933
940
|
ws.once('open', () => {
|
|
934
941
|
if (!waiting) return;
|
|
@@ -950,12 +957,12 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
950
957
|
let reconnecting = false;
|
|
951
958
|
let numRetries = 0;
|
|
952
959
|
let wsConn: WebSocket | null = null;
|
|
953
|
-
const maxRetries = this.
|
|
960
|
+
const maxRetries = this._options.connOptions.maxRetry;
|
|
954
961
|
|
|
955
962
|
const reconnect = async () => {
|
|
956
963
|
this.#logger.debug(
|
|
957
964
|
{
|
|
958
|
-
maxSessionDuration: this.
|
|
965
|
+
maxSessionDuration: this._options.maxSessionDuration,
|
|
959
966
|
},
|
|
960
967
|
'Reconnecting to OpenAI Realtime API',
|
|
961
968
|
);
|
|
@@ -1005,7 +1012,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1005
1012
|
try {
|
|
1006
1013
|
for (const ev of events) {
|
|
1007
1014
|
this.emit('openai_client_event_queued', ev);
|
|
1008
|
-
if (this.
|
|
1015
|
+
if (this._options.isAzure && this._options.apiVersion) {
|
|
1009
1016
|
normalizeAzureClientEvent(ev as unknown as Record<string, unknown>);
|
|
1010
1017
|
}
|
|
1011
1018
|
wsConn!.send(JSON.stringify(ev));
|
|
@@ -1063,7 +1070,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1063
1070
|
const retryInterval =
|
|
1064
1071
|
numRetries === 0
|
|
1065
1072
|
? DEFAULT_FIRST_RETRY_INTERVAL_MS
|
|
1066
|
-
: this.
|
|
1073
|
+
: this._options.connOptions.retryIntervalMs;
|
|
1067
1074
|
this.#logger.warn(
|
|
1068
1075
|
{
|
|
1069
1076
|
attempt: numRetries,
|
|
@@ -1098,7 +1105,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1098
1105
|
}
|
|
1099
1106
|
|
|
1100
1107
|
this.emit('openai_client_event_queued', event);
|
|
1101
|
-
if (this.
|
|
1108
|
+
if (this._options.isAzure && this._options.apiVersion) {
|
|
1102
1109
|
normalizeAzureClientEvent(event as unknown as Record<string, unknown>);
|
|
1103
1110
|
}
|
|
1104
1111
|
wsConn.send(JSON.stringify(event));
|
|
@@ -1214,7 +1221,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1214
1221
|
});
|
|
1215
1222
|
|
|
1216
1223
|
const waitReconnectTask = Task.from(async ({ signal }) => {
|
|
1217
|
-
await delay(this.
|
|
1224
|
+
await delay(this._options.maxSessionDuration, { signal });
|
|
1218
1225
|
return new APIConnectionError({
|
|
1219
1226
|
message: 'OpenAI Realtime API connection timeout',
|
|
1220
1227
|
});
|
|
@@ -1269,7 +1276,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1269
1276
|
gen.textChannel.close();
|
|
1270
1277
|
gen.audioChannel.close();
|
|
1271
1278
|
if (!gen.modalities.done) {
|
|
1272
|
-
gen.modalities.resolve(this.
|
|
1279
|
+
gen.modalities.resolve(this._options.modalities);
|
|
1273
1280
|
}
|
|
1274
1281
|
}
|
|
1275
1282
|
this.currentGeneration.messages.clear();
|
|
@@ -1295,7 +1302,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1295
1302
|
_event: api_proto.InputAudioBufferSpeechStoppedEvent,
|
|
1296
1303
|
): void {
|
|
1297
1304
|
this.emit('input_speech_stopped', {
|
|
1298
|
-
userTranscriptionEnabled: this.
|
|
1305
|
+
userTranscriptionEnabled: this._options.inputAudioTranscription !== null,
|
|
1299
1306
|
} as llm.InputSpeechStoppedEvent);
|
|
1300
1307
|
}
|
|
1301
1308
|
|
|
@@ -1644,7 +1651,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1644
1651
|
itemGeneration.audioChannel.close();
|
|
1645
1652
|
if (!itemGeneration.modalities.done) {
|
|
1646
1653
|
// In case message modalities is not set, this shouldn't happen
|
|
1647
|
-
itemGeneration.modalities.resolve(this.
|
|
1654
|
+
itemGeneration.modalities.resolve(this._options.modalities);
|
|
1648
1655
|
}
|
|
1649
1656
|
}
|
|
1650
1657
|
}
|
|
@@ -1670,7 +1677,7 @@ export class RealtimeSession extends llm.RealtimeSession {
|
|
|
1670
1677
|
generation.textChannel.close();
|
|
1671
1678
|
generation.audioChannel.close();
|
|
1672
1679
|
if (!generation.modalities.done) {
|
|
1673
|
-
generation.modalities.resolve(this.
|
|
1680
|
+
generation.modalities.resolve(this._options.modalities);
|
|
1674
1681
|
}
|
|
1675
1682
|
}
|
|
1676
1683
|
|