@livekit/agents 0.7.8 → 1.0.0-next.0
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/_exceptions.cjs +109 -0
- package/dist/_exceptions.cjs.map +1 -0
- package/dist/_exceptions.d.cts +64 -0
- package/dist/_exceptions.d.ts +64 -0
- package/dist/_exceptions.d.ts.map +1 -0
- package/dist/_exceptions.js +80 -0
- package/dist/_exceptions.js.map +1 -0
- package/dist/audio.cjs +10 -3
- package/dist/audio.cjs.map +1 -1
- package/dist/audio.d.cts +2 -0
- package/dist/audio.d.ts +2 -0
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +8 -2
- package/dist/audio.js.map +1 -1
- package/dist/cli.cjs +25 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -1
- package/dist/constants.cjs +6 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/http_server.cjs.map +1 -1
- package/dist/http_server.d.cts +1 -0
- package/dist/http_server.d.ts +1 -0
- package/dist/http_server.d.ts.map +1 -1
- package/dist/http_server.js.map +1 -1
- package/dist/index.cjs +27 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/inference_runner.cjs +0 -1
- package/dist/inference_runner.cjs.map +1 -1
- package/dist/inference_runner.d.cts +2 -3
- package/dist/inference_runner.d.ts +2 -3
- package/dist/inference_runner.d.ts.map +1 -1
- package/dist/inference_runner.js +0 -1
- package/dist/inference_runner.js.map +1 -1
- package/dist/ipc/inference_proc_executor.cjs +2 -2
- package/dist/ipc/inference_proc_executor.cjs.map +1 -1
- package/dist/ipc/inference_proc_executor.js +2 -2
- package/dist/ipc/inference_proc_executor.js.map +1 -1
- package/dist/ipc/job_executor.cjs.map +1 -1
- package/dist/ipc/job_executor.js.map +1 -1
- package/dist/ipc/job_proc_executor.cjs +1 -0
- package/dist/ipc/job_proc_executor.cjs.map +1 -1
- package/dist/ipc/job_proc_executor.js +1 -0
- package/dist/ipc/job_proc_executor.js.map +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
- package/dist/ipc/job_proc_lazy_main.js +1 -1
- package/dist/ipc/job_proc_lazy_main.js.map +1 -1
- package/dist/ipc/supervised_proc.d.cts +1 -1
- package/dist/ipc/supervised_proc.d.ts +1 -1
- package/dist/ipc/supervised_proc.d.ts.map +1 -1
- package/dist/job.cjs +14 -2
- package/dist/job.cjs.map +1 -1
- package/dist/job.d.cts +8 -0
- package/dist/job.d.ts +8 -0
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +12 -1
- package/dist/job.js.map +1 -1
- package/dist/llm/chat_context.cjs +332 -82
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +152 -48
- package/dist/llm/chat_context.d.ts +152 -48
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +327 -81
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/chat_context.test.cjs +380 -0
- package/dist/llm/chat_context.test.cjs.map +1 -0
- package/dist/llm/chat_context.test.js +385 -0
- package/dist/llm/chat_context.test.js.map +1 -0
- package/dist/llm/index.cjs +37 -8
- package/dist/llm/index.cjs.map +1 -1
- package/dist/llm/index.d.cts +7 -3
- package/dist/llm/index.d.ts +7 -3
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +39 -9
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/llm.cjs +98 -33
- package/dist/llm/llm.cjs.map +1 -1
- package/dist/llm/llm.d.cts +50 -24
- package/dist/llm/llm.d.ts +50 -24
- package/dist/llm/llm.d.ts.map +1 -1
- package/dist/llm/llm.js +99 -33
- package/dist/llm/llm.js.map +1 -1
- package/dist/llm/provider_format/google.cjs +128 -0
- package/dist/llm/provider_format/google.cjs.map +1 -0
- package/dist/llm/provider_format/google.d.cts +6 -0
- package/dist/llm/provider_format/google.d.ts +6 -0
- package/dist/llm/provider_format/google.d.ts.map +1 -0
- package/dist/llm/provider_format/google.js +104 -0
- package/dist/llm/provider_format/google.js.map +1 -0
- package/dist/llm/provider_format/google.test.cjs +676 -0
- package/dist/llm/provider_format/google.test.cjs.map +1 -0
- package/dist/llm/provider_format/google.test.js +675 -0
- package/dist/llm/provider_format/google.test.js.map +1 -0
- package/dist/llm/provider_format/index.cjs +40 -0
- package/dist/llm/provider_format/index.cjs.map +1 -0
- package/dist/llm/provider_format/index.d.cts +4 -0
- package/dist/llm/provider_format/index.d.ts +4 -0
- package/dist/llm/provider_format/index.d.ts.map +1 -0
- package/dist/llm/provider_format/index.js +16 -0
- package/dist/llm/provider_format/index.js.map +1 -0
- package/dist/llm/provider_format/openai.cjs +116 -0
- package/dist/llm/provider_format/openai.cjs.map +1 -0
- package/dist/llm/provider_format/openai.d.cts +3 -0
- package/dist/llm/provider_format/openai.d.ts +3 -0
- package/dist/llm/provider_format/openai.d.ts.map +1 -0
- package/dist/llm/provider_format/openai.js +92 -0
- package/dist/llm/provider_format/openai.js.map +1 -0
- package/dist/llm/provider_format/openai.test.cjs +490 -0
- package/dist/llm/provider_format/openai.test.cjs.map +1 -0
- package/dist/llm/provider_format/openai.test.js +489 -0
- package/dist/llm/provider_format/openai.test.js.map +1 -0
- package/dist/llm/provider_format/utils.cjs +146 -0
- package/dist/llm/provider_format/utils.cjs.map +1 -0
- package/dist/llm/provider_format/utils.d.cts +38 -0
- package/dist/llm/provider_format/utils.d.ts +38 -0
- package/dist/llm/provider_format/utils.d.ts.map +1 -0
- package/dist/llm/provider_format/utils.js +122 -0
- package/dist/llm/provider_format/utils.js.map +1 -0
- package/dist/llm/realtime.cjs +77 -0
- package/dist/llm/realtime.cjs.map +1 -0
- package/dist/llm/realtime.d.cts +98 -0
- package/dist/llm/realtime.d.ts +98 -0
- package/dist/llm/realtime.d.ts.map +1 -0
- package/dist/llm/realtime.js +52 -0
- package/dist/llm/realtime.js.map +1 -0
- package/dist/llm/remote_chat_context.cjs +112 -0
- package/dist/llm/remote_chat_context.cjs.map +1 -0
- package/dist/llm/remote_chat_context.d.cts +23 -0
- package/dist/llm/remote_chat_context.d.ts +23 -0
- package/dist/llm/remote_chat_context.d.ts.map +1 -0
- package/dist/llm/remote_chat_context.js +88 -0
- package/dist/llm/remote_chat_context.js.map +1 -0
- package/dist/llm/remote_chat_context.test.cjs +225 -0
- package/dist/llm/remote_chat_context.test.cjs.map +1 -0
- package/dist/llm/remote_chat_context.test.js +224 -0
- package/dist/llm/remote_chat_context.test.js.map +1 -0
- package/dist/llm/tool_context.cjs +111 -0
- package/dist/llm/tool_context.cjs.map +1 -0
- package/dist/llm/tool_context.d.cts +125 -0
- package/dist/llm/tool_context.d.ts +125 -0
- package/dist/llm/tool_context.d.ts.map +1 -0
- package/dist/llm/tool_context.js +80 -0
- package/dist/llm/tool_context.js.map +1 -0
- package/dist/llm/tool_context.test.cjs +162 -0
- package/dist/llm/tool_context.test.cjs.map +1 -0
- package/dist/llm/tool_context.test.js +161 -0
- package/dist/llm/tool_context.test.js.map +1 -0
- package/dist/llm/tool_context.type.test.cjs +92 -0
- package/dist/llm/tool_context.type.test.cjs.map +1 -0
- package/dist/llm/tool_context.type.test.js +91 -0
- package/dist/llm/tool_context.type.test.js.map +1 -0
- package/dist/llm/utils.cjs +260 -0
- package/dist/llm/utils.cjs.map +1 -0
- package/dist/llm/utils.d.cts +42 -0
- package/dist/llm/utils.d.ts +42 -0
- package/dist/llm/utils.d.ts.map +1 -0
- package/dist/llm/utils.js +223 -0
- package/dist/llm/utils.js.map +1 -0
- package/dist/llm/utils.test.cjs +513 -0
- package/dist/llm/utils.test.cjs.map +1 -0
- package/dist/llm/utils.test.js +490 -0
- package/dist/llm/utils.test.js.map +1 -0
- package/dist/metrics/base.cjs +0 -27
- package/dist/metrics/base.cjs.map +1 -1
- package/dist/metrics/base.d.cts +105 -63
- package/dist/metrics/base.d.ts +105 -63
- package/dist/metrics/base.d.ts.map +1 -1
- package/dist/metrics/base.js +0 -19
- package/dist/metrics/base.js.map +1 -1
- package/dist/metrics/index.cjs +0 -3
- package/dist/metrics/index.cjs.map +1 -1
- package/dist/metrics/index.d.cts +2 -3
- package/dist/metrics/index.d.ts +2 -3
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +0 -2
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/usage_collector.cjs +17 -12
- package/dist/metrics/usage_collector.cjs.map +1 -1
- package/dist/metrics/usage_collector.d.cts +3 -2
- package/dist/metrics/usage_collector.d.ts +3 -2
- package/dist/metrics/usage_collector.d.ts.map +1 -1
- package/dist/metrics/usage_collector.js +17 -12
- package/dist/metrics/usage_collector.js.map +1 -1
- package/dist/metrics/utils.cjs +22 -59
- package/dist/metrics/utils.cjs.map +1 -1
- package/dist/metrics/utils.d.cts +1 -8
- package/dist/metrics/utils.d.ts +1 -8
- package/dist/metrics/utils.d.ts.map +1 -1
- package/dist/metrics/utils.js +22 -52
- package/dist/metrics/utils.js.map +1 -1
- package/dist/multimodal/index.cjs +0 -2
- package/dist/multimodal/index.cjs.map +1 -1
- package/dist/multimodal/index.d.cts +0 -1
- package/dist/multimodal/index.d.ts +0 -1
- package/dist/multimodal/index.d.ts.map +1 -1
- package/dist/multimodal/index.js +0 -1
- package/dist/multimodal/index.js.map +1 -1
- package/dist/plugin.cjs +24 -8
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +18 -4
- package/dist/plugin.d.ts +18 -4
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +22 -7
- package/dist/plugin.js.map +1 -1
- package/dist/stream/deferred_stream.cjs +98 -0
- package/dist/stream/deferred_stream.cjs.map +1 -0
- package/dist/stream/deferred_stream.d.cts +27 -0
- package/dist/stream/deferred_stream.d.ts +27 -0
- package/dist/stream/deferred_stream.d.ts.map +1 -0
- package/dist/stream/deferred_stream.js +73 -0
- package/dist/stream/deferred_stream.js.map +1 -0
- package/dist/stream/deferred_stream.test.cjs +527 -0
- package/dist/stream/deferred_stream.test.cjs.map +1 -0
- package/dist/stream/deferred_stream.test.js +526 -0
- package/dist/stream/deferred_stream.test.js.map +1 -0
- package/dist/stream/identity_transform.cjs +42 -0
- package/dist/stream/identity_transform.cjs.map +1 -0
- package/dist/stream/identity_transform.d.cts +6 -0
- package/dist/stream/identity_transform.d.ts +6 -0
- package/dist/stream/identity_transform.d.ts.map +1 -0
- package/dist/stream/identity_transform.js +18 -0
- package/dist/stream/identity_transform.js.map +1 -0
- package/dist/stream/identity_transform.test.cjs +125 -0
- package/dist/stream/identity_transform.test.cjs.map +1 -0
- package/dist/stream/identity_transform.test.js +124 -0
- package/dist/stream/identity_transform.test.js.map +1 -0
- package/dist/stream/index.cjs +38 -0
- package/dist/stream/index.cjs.map +1 -0
- package/dist/stream/index.d.cts +5 -0
- package/dist/stream/index.d.ts +5 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/index.js +11 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/merge_readable_streams.cjs +59 -0
- package/dist/stream/merge_readable_streams.cjs.map +1 -0
- package/dist/stream/merge_readable_streams.d.cts +4 -0
- package/dist/stream/merge_readable_streams.d.ts +4 -0
- package/dist/stream/merge_readable_streams.d.ts.map +1 -0
- package/dist/stream/merge_readable_streams.js +35 -0
- package/dist/stream/merge_readable_streams.js.map +1 -0
- package/dist/stream/stream_channel.cjs +47 -0
- package/dist/stream/stream_channel.cjs.map +1 -0
- package/dist/stream/stream_channel.d.cts +9 -0
- package/dist/stream/stream_channel.d.ts +9 -0
- package/dist/stream/stream_channel.d.ts.map +1 -0
- package/dist/stream/stream_channel.js +23 -0
- package/dist/stream/stream_channel.js.map +1 -0
- package/dist/stream/stream_channel.test.cjs +97 -0
- package/dist/stream/stream_channel.test.cjs.map +1 -0
- package/dist/stream/stream_channel.test.js +96 -0
- package/dist/stream/stream_channel.test.js.map +1 -0
- package/dist/stt/stream_adapter.cjs +3 -4
- package/dist/stt/stream_adapter.cjs.map +1 -1
- package/dist/stt/stream_adapter.d.cts +1 -0
- package/dist/stt/stream_adapter.d.ts +1 -0
- package/dist/stt/stream_adapter.d.ts.map +1 -1
- package/dist/stt/stream_adapter.js +3 -4
- package/dist/stt/stream_adapter.js.map +1 -1
- package/dist/stt/stt.cjs +101 -10
- package/dist/stt/stt.cjs.map +1 -1
- package/dist/stt/stt.d.cts +26 -5
- package/dist/stt/stt.d.ts +26 -5
- package/dist/stt/stt.d.ts.map +1 -1
- package/dist/stt/stt.js +102 -11
- package/dist/stt/stt.js.map +1 -1
- package/dist/tokenize/basic/basic.cjs +10 -5
- package/dist/tokenize/basic/basic.cjs.map +1 -1
- package/dist/tokenize/basic/basic.d.cts +7 -1
- package/dist/tokenize/basic/basic.d.ts +7 -1
- package/dist/tokenize/basic/basic.d.ts.map +1 -1
- package/dist/tokenize/basic/basic.js +10 -5
- package/dist/tokenize/basic/basic.js.map +1 -1
- package/dist/tokenize/basic/sentence.cjs +14 -6
- package/dist/tokenize/basic/sentence.cjs.map +1 -1
- package/dist/tokenize/basic/sentence.d.cts +1 -1
- package/dist/tokenize/basic/sentence.d.ts +1 -1
- package/dist/tokenize/basic/sentence.d.ts.map +1 -1
- package/dist/tokenize/basic/sentence.js +14 -6
- package/dist/tokenize/basic/sentence.js.map +1 -1
- package/dist/tokenize/token_stream.cjs +5 -3
- package/dist/tokenize/token_stream.cjs.map +1 -1
- package/dist/tokenize/token_stream.d.cts +1 -0
- package/dist/tokenize/token_stream.d.ts +1 -0
- package/dist/tokenize/token_stream.d.ts.map +1 -1
- package/dist/tokenize/token_stream.js +6 -4
- package/dist/tokenize/token_stream.js.map +1 -1
- package/dist/transcription.cjs +1 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +2 -3
- package/dist/transcription.js.map +1 -1
- package/dist/tts/index.cjs +2 -4
- package/dist/tts/index.cjs.map +1 -1
- package/dist/tts/index.d.cts +1 -1
- package/dist/tts/index.d.ts +1 -1
- package/dist/tts/index.d.ts.map +1 -1
- package/dist/tts/index.js +1 -3
- package/dist/tts/index.js.map +1 -1
- package/dist/tts/stream_adapter.cjs +26 -13
- package/dist/tts/stream_adapter.cjs.map +1 -1
- package/dist/tts/stream_adapter.d.cts +1 -1
- package/dist/tts/stream_adapter.d.ts +1 -1
- package/dist/tts/stream_adapter.d.ts.map +1 -1
- package/dist/tts/stream_adapter.js +27 -14
- package/dist/tts/stream_adapter.js.map +1 -1
- package/dist/tts/tts.cjs +157 -25
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.d.cts +29 -5
- package/dist/tts/tts.d.ts +29 -5
- package/dist/tts/tts.d.ts.map +1 -1
- package/dist/tts/tts.js +157 -24
- package/dist/tts/tts.js.map +1 -1
- package/dist/types.cjs +60 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +281 -27
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +134 -9
- package/dist/utils.d.ts +134 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +265 -26
- package/dist/utils.js.map +1 -1
- package/dist/utils.test.cjs +492 -0
- package/dist/utils.test.cjs.map +1 -0
- package/dist/utils.test.js +498 -0
- package/dist/utils.test.js.map +1 -0
- package/dist/vad.cjs +76 -20
- package/dist/vad.cjs.map +1 -1
- package/dist/vad.d.cts +25 -5
- package/dist/vad.d.ts +25 -5
- package/dist/vad.d.ts.map +1 -1
- package/dist/vad.js +76 -20
- package/dist/vad.js.map +1 -1
- package/dist/voice/agent.cjs +245 -0
- package/dist/voice/agent.cjs.map +1 -0
- package/dist/voice/agent.d.cts +78 -0
- package/dist/voice/agent.d.ts +78 -0
- package/dist/voice/agent.d.ts.map +1 -0
- package/dist/voice/agent.js +220 -0
- package/dist/voice/agent.js.map +1 -0
- package/dist/voice/agent.test.cjs +61 -0
- package/dist/voice/agent.test.cjs.map +1 -0
- package/dist/voice/agent.test.js +60 -0
- package/dist/voice/agent.test.js.map +1 -0
- package/dist/voice/agent_activity.cjs +1453 -0
- package/dist/voice/agent_activity.cjs.map +1 -0
- package/dist/voice/agent_activity.d.cts +94 -0
- package/dist/voice/agent_activity.d.ts +94 -0
- package/dist/voice/agent_activity.d.ts.map +1 -0
- package/dist/voice/agent_activity.js +1449 -0
- package/dist/voice/agent_activity.js.map +1 -0
- package/dist/voice/agent_session.cjs +312 -0
- package/dist/voice/agent_session.cjs.map +1 -0
- package/dist/voice/agent_session.d.cts +121 -0
- package/dist/voice/agent_session.d.ts +121 -0
- package/dist/voice/agent_session.d.ts.map +1 -0
- package/dist/voice/agent_session.js +295 -0
- package/dist/voice/agent_session.js.map +1 -0
- package/dist/voice/audio_recognition.cjs +375 -0
- package/dist/voice/audio_recognition.cjs.map +1 -0
- package/dist/voice/audio_recognition.d.cts +80 -0
- package/dist/voice/audio_recognition.d.ts +80 -0
- package/dist/voice/audio_recognition.d.ts.map +1 -0
- package/dist/voice/audio_recognition.js +351 -0
- package/dist/voice/audio_recognition.js.map +1 -0
- package/dist/voice/events.cjs +145 -0
- package/dist/voice/events.cjs.map +1 -0
- package/dist/voice/events.d.cts +124 -0
- package/dist/voice/events.d.ts +124 -0
- package/dist/voice/events.d.ts.map +1 -0
- package/dist/voice/events.js +110 -0
- package/dist/voice/events.js.map +1 -0
- package/dist/voice/generation.cjs +700 -0
- package/dist/voice/generation.cjs.map +1 -0
- package/dist/voice/generation.d.cts +115 -0
- package/dist/voice/generation.d.ts +115 -0
- package/dist/voice/generation.d.ts.map +1 -0
- package/dist/voice/generation.js +672 -0
- package/dist/voice/generation.js.map +1 -0
- package/dist/voice/index.cjs +40 -0
- package/dist/voice/index.cjs.map +1 -0
- package/dist/voice/index.d.cts +5 -0
- package/dist/voice/index.d.ts +5 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +11 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/io.cjs +245 -0
- package/dist/voice/io.cjs.map +1 -0
- package/dist/voice/io.d.cts +101 -0
- package/dist/voice/io.d.ts +101 -0
- package/dist/voice/io.d.ts.map +1 -0
- package/dist/voice/io.js +217 -0
- package/dist/voice/io.js.map +1 -0
- package/dist/voice/room_io/_input.cjs +121 -0
- package/dist/voice/room_io/_input.cjs.map +1 -0
- package/dist/voice/room_io/_input.d.cts +24 -0
- package/dist/voice/room_io/_input.d.ts +24 -0
- package/dist/voice/room_io/_input.d.ts.map +1 -0
- package/dist/voice/room_io/_input.js +102 -0
- package/dist/voice/room_io/_input.js.map +1 -0
- package/dist/voice/room_io/_output.cjs +358 -0
- package/dist/voice/room_io/_output.cjs.map +1 -0
- package/dist/voice/room_io/_output.d.cts +75 -0
- package/dist/voice/room_io/_output.d.ts +75 -0
- package/dist/voice/room_io/_output.d.ts.map +1 -0
- package/dist/voice/room_io/_output.js +342 -0
- package/dist/voice/room_io/_output.js.map +1 -0
- package/dist/voice/room_io/index.cjs +25 -0
- package/dist/voice/room_io/index.cjs.map +1 -0
- package/dist/voice/room_io/index.d.cts +3 -0
- package/dist/voice/room_io/index.d.ts +3 -0
- package/dist/voice/room_io/index.d.ts.map +1 -0
- package/dist/voice/room_io/index.js +3 -0
- package/dist/voice/room_io/index.js.map +1 -0
- package/dist/voice/room_io/room_io.cjs +370 -0
- package/dist/voice/room_io/room_io.cjs.map +1 -0
- package/dist/voice/room_io/room_io.d.cts +73 -0
- package/dist/voice/room_io/room_io.d.ts +73 -0
- package/dist/voice/room_io/room_io.d.ts.map +1 -0
- package/dist/voice/room_io/room_io.js +361 -0
- package/dist/voice/room_io/room_io.js.map +1 -0
- package/dist/{pipeline/index.cjs → voice/run_context.cjs} +16 -11
- package/dist/voice/run_context.cjs.map +1 -0
- package/dist/voice/run_context.d.cts +12 -0
- package/dist/voice/run_context.d.ts +12 -0
- package/dist/voice/run_context.d.ts.map +1 -0
- package/dist/voice/run_context.js +14 -0
- package/dist/voice/run_context.js.map +1 -0
- package/dist/voice/speech_handle.cjs +105 -0
- package/dist/voice/speech_handle.cjs.map +1 -0
- package/dist/voice/speech_handle.d.cts +46 -0
- package/dist/voice/speech_handle.d.ts +46 -0
- package/dist/voice/speech_handle.d.ts.map +1 -0
- package/dist/voice/speech_handle.js +81 -0
- package/dist/voice/speech_handle.js.map +1 -0
- package/dist/voice/transcription/_utils.cjs +45 -0
- package/dist/voice/transcription/_utils.cjs.map +1 -0
- package/dist/voice/transcription/_utils.d.cts +3 -0
- package/dist/voice/transcription/_utils.d.ts +3 -0
- package/dist/voice/transcription/_utils.d.ts.map +1 -0
- package/dist/voice/transcription/_utils.js +21 -0
- package/dist/voice/transcription/_utils.js.map +1 -0
- package/dist/voice/transcription/index.cjs +23 -0
- package/dist/voice/transcription/index.cjs.map +1 -0
- package/dist/voice/transcription/index.d.cts +2 -0
- package/dist/voice/transcription/index.d.ts +2 -0
- package/dist/voice/transcription/index.d.ts.map +1 -0
- package/dist/voice/transcription/index.js +2 -0
- package/dist/voice/transcription/index.js.map +1 -0
- package/dist/voice/transcription/synchronizer.cjs +380 -0
- package/dist/voice/transcription/synchronizer.cjs.map +1 -0
- package/dist/voice/transcription/synchronizer.d.cts +86 -0
- package/dist/voice/transcription/synchronizer.d.ts +86 -0
- package/dist/voice/transcription/synchronizer.d.ts.map +1 -0
- package/dist/voice/transcription/synchronizer.js +355 -0
- package/dist/voice/transcription/synchronizer.js.map +1 -0
- package/dist/worker.cjs +22 -4
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +22 -4
- package/dist/worker.js.map +1 -1
- package/package.json +9 -2
- package/src/_exceptions.ts +137 -0
- package/src/audio.ts +12 -1
- package/src/cli.ts +37 -0
- package/src/constants.ts +2 -0
- package/src/http_server.ts +1 -0
- package/src/index.ts +13 -10
- package/src/inference_runner.ts +2 -3
- package/src/ipc/inference_proc_executor.ts +2 -2
- package/src/ipc/job_executor.ts +1 -1
- package/src/ipc/job_proc_executor.ts +1 -1
- package/src/ipc/job_proc_lazy_main.ts +1 -1
- package/src/job.ts +18 -0
- package/src/llm/__snapshots__/chat_context.test.ts.snap +527 -0
- package/src/llm/__snapshots__/tool_context.test.ts.snap +177 -0
- package/src/llm/__snapshots__/utils.test.ts.snap +65 -0
- package/src/llm/chat_context.test.ts +450 -0
- package/src/llm/chat_context.ts +501 -103
- package/src/llm/index.ts +53 -18
- package/src/llm/llm.ts +149 -50
- package/src/llm/provider_format/google.test.ts +772 -0
- package/src/llm/provider_format/google.ts +130 -0
- package/src/llm/provider_format/index.ts +23 -0
- package/src/llm/provider_format/openai.test.ts +581 -0
- package/src/llm/provider_format/openai.ts +118 -0
- package/src/llm/provider_format/utils.ts +183 -0
- package/src/llm/realtime.ts +151 -0
- package/src/llm/remote_chat_context.test.ts +290 -0
- package/src/llm/remote_chat_context.ts +114 -0
- package/src/llm/tool_context.test.ts +198 -0
- package/src/llm/tool_context.ts +259 -0
- package/src/llm/tool_context.type.test.ts +115 -0
- package/src/llm/utils.test.ts +670 -0
- package/src/llm/utils.ts +324 -0
- package/src/metrics/base.ts +110 -78
- package/src/metrics/index.ts +3 -9
- package/src/metrics/usage_collector.ts +19 -13
- package/src/metrics/utils.ts +24 -69
- package/src/multimodal/index.ts +0 -1
- package/src/plugin.ts +26 -8
- package/src/stream/deferred_stream.test.ts +755 -0
- package/src/stream/deferred_stream.ts +110 -0
- package/src/stream/identity_transform.test.ts +179 -0
- package/src/stream/identity_transform.ts +18 -0
- package/src/stream/index.ts +7 -0
- package/src/stream/merge_readable_streams.ts +40 -0
- package/src/stream/stream_channel.test.ts +129 -0
- package/src/stream/stream_channel.ts +32 -0
- package/src/stt/stream_adapter.ts +3 -5
- package/src/stt/stt.ts +135 -17
- package/src/tokenize/basic/basic.ts +13 -5
- package/src/tokenize/basic/sentence.ts +20 -6
- package/src/tokenize/token_stream.ts +7 -4
- package/src/transcription.ts +2 -3
- package/src/tts/index.ts +0 -1
- package/src/tts/stream_adapter.ts +42 -16
- package/src/tts/tts.ts +203 -21
- package/src/types.ts +42 -0
- package/src/utils.test.ts +658 -0
- package/src/utils.ts +375 -44
- package/src/vad.ts +90 -22
- package/src/voice/agent.test.ts +80 -0
- package/src/voice/agent.ts +332 -0
- package/src/voice/agent_activity.ts +1913 -0
- package/src/voice/agent_session.ts +460 -0
- package/src/voice/audio_recognition.ts +474 -0
- package/src/voice/events.ts +252 -0
- package/src/voice/generation.ts +881 -0
- package/src/voice/index.ts +7 -0
- package/src/voice/io.ts +304 -0
- package/src/voice/room_io/_input.ts +144 -0
- package/src/voice/room_io/_output.ts +436 -0
- package/src/voice/room_io/index.ts +5 -0
- package/src/voice/room_io/room_io.ts +495 -0
- package/src/voice/run_context.ts +20 -0
- package/src/voice/speech_handle.ts +104 -0
- package/src/voice/transcription/_utils.ts +25 -0
- package/src/voice/transcription/index.ts +4 -0
- package/src/voice/transcription/synchronizer.ts +478 -0
- package/src/worker.ts +22 -2
- package/dist/llm/function_context.cjs +0 -103
- package/dist/llm/function_context.cjs.map +0 -1
- package/dist/llm/function_context.d.cts +0 -47
- package/dist/llm/function_context.d.ts +0 -47
- package/dist/llm/function_context.d.ts.map +0 -1
- package/dist/llm/function_context.js +0 -78
- package/dist/llm/function_context.js.map +0 -1
- package/dist/llm/function_context.test.cjs +0 -218
- package/dist/llm/function_context.test.cjs.map +0 -1
- package/dist/llm/function_context.test.js +0 -217
- package/dist/llm/function_context.test.js.map +0 -1
- package/dist/multimodal/multimodal_agent.cjs +0 -451
- package/dist/multimodal/multimodal_agent.cjs.map +0 -1
- package/dist/multimodal/multimodal_agent.d.cts +0 -48
- package/dist/multimodal/multimodal_agent.d.ts +0 -48
- package/dist/multimodal/multimodal_agent.d.ts.map +0 -1
- package/dist/multimodal/multimodal_agent.js +0 -425
- package/dist/multimodal/multimodal_agent.js.map +0 -1
- package/dist/pipeline/agent_output.cjs +0 -197
- package/dist/pipeline/agent_output.cjs.map +0 -1
- package/dist/pipeline/agent_output.d.cts +0 -33
- package/dist/pipeline/agent_output.d.ts +0 -33
- package/dist/pipeline/agent_output.d.ts.map +0 -1
- package/dist/pipeline/agent_output.js +0 -172
- package/dist/pipeline/agent_output.js.map +0 -1
- package/dist/pipeline/agent_playout.cjs +0 -175
- package/dist/pipeline/agent_playout.cjs.map +0 -1
- package/dist/pipeline/agent_playout.d.cts +0 -40
- package/dist/pipeline/agent_playout.d.ts +0 -40
- package/dist/pipeline/agent_playout.d.ts.map +0 -1
- package/dist/pipeline/agent_playout.js +0 -139
- package/dist/pipeline/agent_playout.js.map +0 -1
- package/dist/pipeline/human_input.cjs +0 -171
- package/dist/pipeline/human_input.cjs.map +0 -1
- package/dist/pipeline/human_input.d.cts +0 -30
- package/dist/pipeline/human_input.d.ts +0 -30
- package/dist/pipeline/human_input.d.ts.map +0 -1
- package/dist/pipeline/human_input.js +0 -146
- package/dist/pipeline/human_input.js.map +0 -1
- package/dist/pipeline/index.cjs.map +0 -1
- package/dist/pipeline/index.d.cts +0 -2
- package/dist/pipeline/index.d.ts +0 -2
- package/dist/pipeline/index.d.ts.map +0 -1
- package/dist/pipeline/index.js +0 -11
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/pipeline_agent.cjs +0 -849
- package/dist/pipeline/pipeline_agent.cjs.map +0 -1
- package/dist/pipeline/pipeline_agent.d.cts +0 -150
- package/dist/pipeline/pipeline_agent.d.ts +0 -150
- package/dist/pipeline/pipeline_agent.d.ts.map +0 -1
- package/dist/pipeline/pipeline_agent.js +0 -826
- package/dist/pipeline/pipeline_agent.js.map +0 -1
- package/dist/pipeline/speech_handle.cjs +0 -176
- package/dist/pipeline/speech_handle.cjs.map +0 -1
- package/dist/pipeline/speech_handle.d.cts +0 -37
- package/dist/pipeline/speech_handle.d.ts +0 -37
- package/dist/pipeline/speech_handle.d.ts.map +0 -1
- package/dist/pipeline/speech_handle.js +0 -152
- package/dist/pipeline/speech_handle.js.map +0 -1
- package/src/llm/function_context.test.ts +0 -248
- package/src/llm/function_context.ts +0 -142
- package/src/multimodal/multimodal_agent.ts +0 -555
- package/src/pipeline/agent_output.ts +0 -219
- package/src/pipeline/agent_playout.ts +0 -192
- package/src/pipeline/human_input.ts +0 -188
- package/src/pipeline/index.ts +0 -15
- package/src/pipeline/pipeline_agent.ts +0 -1185
- package/src/pipeline/speech_handle.ts +0 -201
|
@@ -1,555 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
|
-
//
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import type {
|
|
5
|
-
LocalTrackPublication,
|
|
6
|
-
NoiseCancellationOptions,
|
|
7
|
-
RemoteAudioTrack,
|
|
8
|
-
RemoteParticipant,
|
|
9
|
-
RemoteTrack,
|
|
10
|
-
RemoteTrackPublication,
|
|
11
|
-
Room,
|
|
12
|
-
} from '@livekit/rtc-node';
|
|
13
|
-
import {
|
|
14
|
-
AudioSource,
|
|
15
|
-
AudioStream,
|
|
16
|
-
LocalAudioTrack,
|
|
17
|
-
RoomEvent,
|
|
18
|
-
TrackPublishOptions,
|
|
19
|
-
TrackSource,
|
|
20
|
-
} from '@livekit/rtc-node';
|
|
21
|
-
import { EventEmitter } from 'node:events';
|
|
22
|
-
import { AudioByteStream } from '../audio.js';
|
|
23
|
-
import {
|
|
24
|
-
ATTRIBUTE_TRANSCRIPTION_FINAL,
|
|
25
|
-
ATTRIBUTE_TRANSCRIPTION_TRACK_ID,
|
|
26
|
-
TOPIC_TRANSCRIPTION,
|
|
27
|
-
} from '../constants.js';
|
|
28
|
-
import * as llm from '../llm/index.js';
|
|
29
|
-
import { log } from '../log.js';
|
|
30
|
-
import type { MultimodalLLMMetrics } from '../metrics/base.js';
|
|
31
|
-
import { TextAudioSynchronizer, defaultTextSyncOptions } from '../transcription.js';
|
|
32
|
-
import { findMicroTrackId } from '../utils.js';
|
|
33
|
-
import { AgentPlayout, type PlayoutHandle } from './agent_playout.js';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @internal
|
|
37
|
-
* @beta
|
|
38
|
-
*/
|
|
39
|
-
export abstract class RealtimeSession extends EventEmitter {
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
abstract conversation: any; // openai.realtime.Conversation
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
abstract inputAudioBuffer: any; // openai.realtime.InputAudioBuffer
|
|
44
|
-
abstract fncCtx: llm.FunctionContext | undefined;
|
|
45
|
-
abstract recoverFromTextResponse(itemId: string): void;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @internal
|
|
50
|
-
* @beta
|
|
51
|
-
*/
|
|
52
|
-
export abstract class RealtimeModel {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
abstract session(options: any): RealtimeSession; // openai.realtime.ModelOptions
|
|
55
|
-
abstract close(): Promise<void>;
|
|
56
|
-
abstract sampleRate: number;
|
|
57
|
-
abstract numChannels: number;
|
|
58
|
-
abstract inFrameSize: number;
|
|
59
|
-
abstract outFrameSize: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type AgentState = 'initializing' | 'thinking' | 'listening' | 'speaking';
|
|
63
|
-
export const AGENT_STATE_ATTRIBUTE = 'lk.agent.state';
|
|
64
|
-
|
|
65
|
-
/** @beta */
|
|
66
|
-
export class MultimodalAgent extends EventEmitter {
|
|
67
|
-
model: RealtimeModel;
|
|
68
|
-
room: Room | null = null;
|
|
69
|
-
linkedParticipant: RemoteParticipant | null = null;
|
|
70
|
-
subscribedTrack: RemoteAudioTrack | null = null;
|
|
71
|
-
readMicroTask: Promise<void> | null = null;
|
|
72
|
-
|
|
73
|
-
#textResponseRetries = 0;
|
|
74
|
-
#maxTextResponseRetries: number;
|
|
75
|
-
|
|
76
|
-
constructor({
|
|
77
|
-
model,
|
|
78
|
-
chatCtx,
|
|
79
|
-
fncCtx,
|
|
80
|
-
maxTextResponseRetries = 5,
|
|
81
|
-
noiseCancellation,
|
|
82
|
-
}: {
|
|
83
|
-
model: RealtimeModel;
|
|
84
|
-
chatCtx?: llm.ChatContext;
|
|
85
|
-
fncCtx?: llm.FunctionContext;
|
|
86
|
-
maxTextResponseRetries?: number;
|
|
87
|
-
noiseCancellation?: NoiseCancellationOptions;
|
|
88
|
-
}) {
|
|
89
|
-
super();
|
|
90
|
-
this.model = model;
|
|
91
|
-
this.#chatCtx = chatCtx;
|
|
92
|
-
this.#fncCtx = fncCtx;
|
|
93
|
-
this.#maxTextResponseRetries = maxTextResponseRetries;
|
|
94
|
-
this.#noiseCancellation = noiseCancellation;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
#participant: RemoteParticipant | string | null = null;
|
|
98
|
-
#agentPublication: LocalTrackPublication | null = null;
|
|
99
|
-
#localTrackSid: string | null = null;
|
|
100
|
-
#localSource: AudioSource | null = null;
|
|
101
|
-
#agentPlayout: AgentPlayout | null = null;
|
|
102
|
-
#playingHandle: PlayoutHandle | undefined = undefined;
|
|
103
|
-
#logger = log();
|
|
104
|
-
#session: RealtimeSession | null = null;
|
|
105
|
-
#fncCtx: llm.FunctionContext | undefined = undefined;
|
|
106
|
-
#chatCtx: llm.ChatContext | undefined = undefined;
|
|
107
|
-
#noiseCancellation: NoiseCancellationOptions | undefined = undefined;
|
|
108
|
-
|
|
109
|
-
#_started: boolean = false;
|
|
110
|
-
#_pendingFunctionCalls: Set<string> = new Set();
|
|
111
|
-
#_speaking: boolean = false;
|
|
112
|
-
|
|
113
|
-
get fncCtx(): llm.FunctionContext | undefined {
|
|
114
|
-
return this.#fncCtx;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
set fncCtx(ctx: llm.FunctionContext | undefined) {
|
|
118
|
-
this.#fncCtx = ctx;
|
|
119
|
-
if (this.#session) {
|
|
120
|
-
this.#session.fncCtx = ctx;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
get #pendingFunctionCalls(): Set<string> {
|
|
125
|
-
return this.#_pendingFunctionCalls;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
set #pendingFunctionCalls(calls: Set<string>) {
|
|
129
|
-
this.#_pendingFunctionCalls = calls;
|
|
130
|
-
this.#updateState();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
get #speaking(): boolean {
|
|
134
|
-
return this.#_speaking;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
set #speaking(isSpeaking: boolean) {
|
|
138
|
-
this.#_speaking = isSpeaking;
|
|
139
|
-
this.#updateState();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
get #started(): boolean {
|
|
143
|
-
return this.#_started;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
set #started(started: boolean) {
|
|
147
|
-
this.#_started = started;
|
|
148
|
-
this.#updateState();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
start(
|
|
152
|
-
room: Room,
|
|
153
|
-
participant: RemoteParticipant | string | null = null,
|
|
154
|
-
): Promise<RealtimeSession> {
|
|
155
|
-
return new Promise(async (resolve, reject) => {
|
|
156
|
-
if (this.#started) {
|
|
157
|
-
reject(new Error('MultimodalAgent already started'));
|
|
158
|
-
}
|
|
159
|
-
this.#updateState();
|
|
160
|
-
|
|
161
|
-
room.on(RoomEvent.ParticipantConnected, (participant: RemoteParticipant) => {
|
|
162
|
-
// automatically link to the first participant that connects, if not already linked
|
|
163
|
-
if (this.linkedParticipant) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this.#linkParticipant(participant.identity!);
|
|
167
|
-
});
|
|
168
|
-
room.on(
|
|
169
|
-
RoomEvent.TrackPublished,
|
|
170
|
-
(trackPublication: RemoteTrackPublication, participant: RemoteParticipant) => {
|
|
171
|
-
if (
|
|
172
|
-
this.linkedParticipant &&
|
|
173
|
-
participant.identity === this.linkedParticipant.identity &&
|
|
174
|
-
trackPublication.source === TrackSource.SOURCE_MICROPHONE &&
|
|
175
|
-
!trackPublication.subscribed
|
|
176
|
-
) {
|
|
177
|
-
trackPublication.setSubscribed(true);
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
);
|
|
181
|
-
room.on(RoomEvent.TrackSubscribed, this.#handleTrackSubscription.bind(this));
|
|
182
|
-
|
|
183
|
-
this.room = room;
|
|
184
|
-
this.#participant = participant;
|
|
185
|
-
|
|
186
|
-
this.#localSource = new AudioSource(this.model.sampleRate, this.model.numChannels);
|
|
187
|
-
this.#agentPlayout = new AgentPlayout(
|
|
188
|
-
this.#localSource,
|
|
189
|
-
this.model.sampleRate,
|
|
190
|
-
this.model.numChannels,
|
|
191
|
-
this.model.inFrameSize,
|
|
192
|
-
this.model.outFrameSize,
|
|
193
|
-
);
|
|
194
|
-
const onPlayoutStarted = () => {
|
|
195
|
-
this.emit('agent_started_speaking');
|
|
196
|
-
this.#speaking = true;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const onPlayoutStopped = (interrupted: boolean) => {
|
|
200
|
-
this.emit('agent_stopped_speaking');
|
|
201
|
-
this.#speaking = false;
|
|
202
|
-
if (this.#playingHandle) {
|
|
203
|
-
let text = this.#playingHandle.synchronizer.playedText;
|
|
204
|
-
if (interrupted) {
|
|
205
|
-
text += '…';
|
|
206
|
-
}
|
|
207
|
-
const msg = llm.ChatMessage.create({
|
|
208
|
-
role: llm.ChatRole.ASSISTANT,
|
|
209
|
-
text,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
if (interrupted) {
|
|
213
|
-
this.emit('agent_speech_interrupted', msg);
|
|
214
|
-
} else {
|
|
215
|
-
this.emit('agent_speech_committed', msg);
|
|
216
|
-
}
|
|
217
|
-
this.#logger.child({ transcription: text, interrupted }).debug('committed agent speech');
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
this.#agentPlayout.on('playout_started', onPlayoutStarted);
|
|
222
|
-
this.#agentPlayout.on('playout_stopped', onPlayoutStopped);
|
|
223
|
-
|
|
224
|
-
const track = LocalAudioTrack.createAudioTrack('assistant_voice', this.#localSource);
|
|
225
|
-
const options = new TrackPublishOptions();
|
|
226
|
-
options.source = TrackSource.SOURCE_MICROPHONE;
|
|
227
|
-
this.#agentPublication = (await room.localParticipant?.publishTrack(track, options)) || null;
|
|
228
|
-
if (!this.#agentPublication) {
|
|
229
|
-
this.#logger.error('Failed to publish track');
|
|
230
|
-
reject(new Error('Failed to publish track'));
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
await this.#agentPublication.waitForSubscription();
|
|
235
|
-
|
|
236
|
-
if (participant) {
|
|
237
|
-
if (typeof participant === 'string') {
|
|
238
|
-
this.#linkParticipant(participant);
|
|
239
|
-
} else {
|
|
240
|
-
this.#linkParticipant(participant.identity!);
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
// No participant specified, try to find the first participant in the room
|
|
244
|
-
for (const participant of room.remoteParticipants.values()) {
|
|
245
|
-
this.#linkParticipant(participant.identity!);
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this.#session = this.model.session({ fncCtx: this.#fncCtx, chatCtx: this.#chatCtx });
|
|
251
|
-
this.#started = true;
|
|
252
|
-
|
|
253
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
254
|
-
this.#session.on('response_content_added', (message: any) => {
|
|
255
|
-
// openai.realtime.RealtimeContent
|
|
256
|
-
if (message.contentType === 'text') return;
|
|
257
|
-
|
|
258
|
-
const synchronizer = new TextAudioSynchronizer(defaultTextSyncOptions);
|
|
259
|
-
synchronizer.on('textUpdated', async (text) => {
|
|
260
|
-
await this.#publishTranscription(
|
|
261
|
-
this.room!.localParticipant!.identity!,
|
|
262
|
-
this.#getLocalTrackSid()!,
|
|
263
|
-
text.text,
|
|
264
|
-
text.final,
|
|
265
|
-
text.id,
|
|
266
|
-
);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
const handle = this.#agentPlayout?.play(
|
|
270
|
-
message.itemId,
|
|
271
|
-
message.contentIndex,
|
|
272
|
-
synchronizer,
|
|
273
|
-
message.textStream,
|
|
274
|
-
message.audioStream,
|
|
275
|
-
);
|
|
276
|
-
this.#playingHandle = handle;
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
280
|
-
this.#session.on('response_content_done', (message: any) => {
|
|
281
|
-
// openai.realtime.RealtimeContent
|
|
282
|
-
if (message.contentType === 'text') {
|
|
283
|
-
if (this.#textResponseRetries >= this.#maxTextResponseRetries) {
|
|
284
|
-
throw new Error(
|
|
285
|
-
'The OpenAI Realtime API returned a text response ' +
|
|
286
|
-
`after ${this.#maxTextResponseRetries} retries. ` +
|
|
287
|
-
'Please try to reduce the number of text system or ' +
|
|
288
|
-
'assistant messages in the chat context.',
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
this.#textResponseRetries++;
|
|
293
|
-
this.#logger
|
|
294
|
-
.child({
|
|
295
|
-
itemId: message.itemId,
|
|
296
|
-
text: message.text,
|
|
297
|
-
retries: this.#textResponseRetries,
|
|
298
|
-
})
|
|
299
|
-
.warn(
|
|
300
|
-
'The OpenAI Realtime API returned a text response instead of audio. ' +
|
|
301
|
-
'Attempting to recover to audio mode...',
|
|
302
|
-
);
|
|
303
|
-
this.#session!.recoverFromTextResponse(message.itemId);
|
|
304
|
-
} else {
|
|
305
|
-
this.#textResponseRetries = 0;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
310
|
-
this.#session.on('input_speech_committed', async (ev: any) => {
|
|
311
|
-
// openai.realtime.InputSpeechCommittedEvent
|
|
312
|
-
const participantIdentity = this.linkedParticipant?.identity;
|
|
313
|
-
const trackSid = this.subscribedTrack?.sid;
|
|
314
|
-
if (participantIdentity && trackSid) {
|
|
315
|
-
await this.#publishTranscription(participantIdentity, trackSid, '…', false, ev.itemId);
|
|
316
|
-
} else {
|
|
317
|
-
this.#logger.error('Participant or track not set');
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
322
|
-
this.#session.on('input_speech_transcription_completed', async (ev: any) => {
|
|
323
|
-
// openai.realtime.InputSpeechTranscriptionCompletedEvent
|
|
324
|
-
const transcription = ev.transcript;
|
|
325
|
-
const participantIdentity = this.linkedParticipant?.identity;
|
|
326
|
-
const trackSid = this.subscribedTrack?.sid;
|
|
327
|
-
if (participantIdentity && trackSid) {
|
|
328
|
-
await this.#publishTranscription(
|
|
329
|
-
participantIdentity,
|
|
330
|
-
trackSid,
|
|
331
|
-
transcription,
|
|
332
|
-
true,
|
|
333
|
-
ev.itemId,
|
|
334
|
-
);
|
|
335
|
-
} else {
|
|
336
|
-
this.#logger.error('Participant or track not set');
|
|
337
|
-
}
|
|
338
|
-
const userMsg = llm.ChatMessage.create({
|
|
339
|
-
role: llm.ChatRole.USER,
|
|
340
|
-
text: transcription,
|
|
341
|
-
});
|
|
342
|
-
this.emit('user_speech_committed', userMsg);
|
|
343
|
-
this.#logger.child({ transcription }).debug('committed user speech');
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
this.#session.on('input_speech_started', async (ev: any) => {
|
|
347
|
-
this.emit('user_started_speaking');
|
|
348
|
-
if (this.#playingHandle && !this.#playingHandle.done) {
|
|
349
|
-
this.#playingHandle.interrupt();
|
|
350
|
-
|
|
351
|
-
this.#session!.conversation.item.truncate(
|
|
352
|
-
this.#playingHandle.itemId,
|
|
353
|
-
this.#playingHandle.contentIndex,
|
|
354
|
-
Math.floor((this.#playingHandle.audioSamples / 24000) * 1000),
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
this.#playingHandle = undefined;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const participantIdentity = this.linkedParticipant?.identity;
|
|
361
|
-
const trackSid = this.subscribedTrack?.sid;
|
|
362
|
-
if (participantIdentity && trackSid) {
|
|
363
|
-
await this.#publishTranscription(participantIdentity, trackSid, '…', false, ev.itemId);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
368
|
-
this.#session.on('input_speech_stopped', (ev: any) => {
|
|
369
|
-
this.emit('user_stopped_speaking');
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
|
-
this.#session.on('function_call_started', (ev: any) => {
|
|
374
|
-
this.#pendingFunctionCalls.add(ev.callId);
|
|
375
|
-
this.#updateState();
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
379
|
-
this.#session.on('function_call_completed', (ev: any) => {
|
|
380
|
-
this.#pendingFunctionCalls.delete(ev.callId);
|
|
381
|
-
this.#updateState();
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
385
|
-
this.#session.on('function_call_failed', (ev: any) => {
|
|
386
|
-
this.#pendingFunctionCalls.delete(ev.callId);
|
|
387
|
-
this.#updateState();
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
this.#session.on('metrics_collected', (metrics: MultimodalLLMMetrics) => {
|
|
391
|
-
this.emit('metrics_collected', metrics);
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
resolve(this.#session);
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
#linkParticipant(participantIdentity: string): void {
|
|
399
|
-
if (!this.room) {
|
|
400
|
-
this.#logger.error('Room is not set');
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
this.linkedParticipant = this.room.remoteParticipants.get(participantIdentity) || null;
|
|
405
|
-
if (!this.linkedParticipant) {
|
|
406
|
-
this.#logger.error(`Participant with identity ${participantIdentity} not found`);
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (this.linkedParticipant.trackPublications.size > 0) {
|
|
411
|
-
this.#subscribeToMicrophone();
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// also check if already subscribed
|
|
415
|
-
for (const publication of this.linkedParticipant.trackPublications.values()) {
|
|
416
|
-
if (publication.source === TrackSource.SOURCE_MICROPHONE && publication.track) {
|
|
417
|
-
this.#handleTrackSubscription(publication.track, publication, this.linkedParticipant);
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
#subscribeToMicrophone(): void {
|
|
424
|
-
if (!this.linkedParticipant) {
|
|
425
|
-
this.#logger.error('Participant is not set');
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
let microphonePublication: RemoteTrackPublication | undefined = undefined;
|
|
430
|
-
for (const publication of this.linkedParticipant.trackPublications.values()) {
|
|
431
|
-
if (publication.source === TrackSource.SOURCE_MICROPHONE) {
|
|
432
|
-
microphonePublication = publication;
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
if (!microphonePublication) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if (!microphonePublication.subscribed) {
|
|
441
|
-
microphonePublication.setSubscribed(true);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
#handleTrackSubscription(
|
|
446
|
-
track: RemoteTrack,
|
|
447
|
-
publication: RemoteTrackPublication,
|
|
448
|
-
participant: RemoteParticipant,
|
|
449
|
-
) {
|
|
450
|
-
if (
|
|
451
|
-
publication.source !== TrackSource.SOURCE_MICROPHONE ||
|
|
452
|
-
participant.identity !== this.linkedParticipant?.identity
|
|
453
|
-
) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
const readAudioStreamTask = async (audioStream: AudioStream) => {
|
|
457
|
-
const bstream = new AudioByteStream(
|
|
458
|
-
this.model.sampleRate,
|
|
459
|
-
this.model.numChannels,
|
|
460
|
-
this.model.inFrameSize,
|
|
461
|
-
);
|
|
462
|
-
|
|
463
|
-
for await (const frame of audioStream) {
|
|
464
|
-
const audioData = frame.data;
|
|
465
|
-
for (const frame of bstream.write(audioData.buffer)) {
|
|
466
|
-
this.#session!.inputAudioBuffer.append(frame);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
this.subscribedTrack = track;
|
|
471
|
-
|
|
472
|
-
this.readMicroTask = new Promise<void>((resolve, reject) => {
|
|
473
|
-
const audioStreamOptions = {
|
|
474
|
-
sampleRate: this.model.sampleRate,
|
|
475
|
-
numChannels: this.model.numChannels,
|
|
476
|
-
...(this.#noiseCancellation ? { noiseCancellation: this.#noiseCancellation } : {}),
|
|
477
|
-
};
|
|
478
|
-
readAudioStreamTask(new AudioStream(track, audioStreamOptions)).then(resolve).catch(reject);
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
#getLocalTrackSid(): string | null {
|
|
483
|
-
if (!this.#localTrackSid && this.room && this.room.localParticipant) {
|
|
484
|
-
this.#localTrackSid = findMicroTrackId(this.room, this.room.localParticipant!.identity!);
|
|
485
|
-
}
|
|
486
|
-
return this.#localTrackSid;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
async #publishTranscription(
|
|
490
|
-
participantIdentity: string,
|
|
491
|
-
trackSid: string,
|
|
492
|
-
text: string,
|
|
493
|
-
isFinal: boolean,
|
|
494
|
-
id: string,
|
|
495
|
-
): Promise<void> {
|
|
496
|
-
this.#logger.debug(
|
|
497
|
-
`Publishing transcription ${participantIdentity} ${trackSid} ${text} ${isFinal} ${id}`,
|
|
498
|
-
);
|
|
499
|
-
if (!this.room?.localParticipant) {
|
|
500
|
-
this.#logger.error('Room or local participant not set');
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
this.room.localParticipant.publishTranscription({
|
|
505
|
-
participantIdentity,
|
|
506
|
-
trackSid,
|
|
507
|
-
segments: [
|
|
508
|
-
{
|
|
509
|
-
text,
|
|
510
|
-
final: isFinal,
|
|
511
|
-
id,
|
|
512
|
-
startTime: BigInt(0),
|
|
513
|
-
endTime: BigInt(0),
|
|
514
|
-
language: '',
|
|
515
|
-
},
|
|
516
|
-
],
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
const stream = await this.room.localParticipant.streamText({
|
|
520
|
-
topic: TOPIC_TRANSCRIPTION,
|
|
521
|
-
senderIdentity: participantIdentity,
|
|
522
|
-
attributes: {
|
|
523
|
-
[ATTRIBUTE_TRANSCRIPTION_TRACK_ID]: trackSid,
|
|
524
|
-
[ATTRIBUTE_TRANSCRIPTION_FINAL]: isFinal.toString(),
|
|
525
|
-
},
|
|
526
|
-
});
|
|
527
|
-
await stream.write(text);
|
|
528
|
-
await stream.close();
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
#updateState() {
|
|
532
|
-
let newState: AgentState = 'initializing';
|
|
533
|
-
if (this.#pendingFunctionCalls.size > 0) {
|
|
534
|
-
newState = 'thinking';
|
|
535
|
-
} else if (this.#speaking) {
|
|
536
|
-
newState = 'speaking';
|
|
537
|
-
} else if (this.#started) {
|
|
538
|
-
newState = 'listening';
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
this.#setState(newState);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
#setState(state: AgentState) {
|
|
545
|
-
if (this.room?.isConnected && this.room.localParticipant) {
|
|
546
|
-
const currentState = this.room.localParticipant.attributes![AGENT_STATE_ATTRIBUTE];
|
|
547
|
-
if (currentState !== state) {
|
|
548
|
-
this.room.localParticipant.setAttributes({
|
|
549
|
-
[AGENT_STATE_ATTRIBUTE]: state,
|
|
550
|
-
});
|
|
551
|
-
this.#logger.debug(`${AGENT_STATE_ATTRIBUTE}: ${currentState} ->${state}`);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|