@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
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConnectionState,
|
|
3
|
+
DisconnectReason,
|
|
4
|
+
ParticipantKind,
|
|
5
|
+
RoomEvent,
|
|
6
|
+
TrackPublishOptions,
|
|
7
|
+
TrackSource
|
|
8
|
+
} from "@livekit/rtc-node";
|
|
9
|
+
import { ATTRIBUTE_PUBLISH_ON_BEHALF, TOPIC_CHAT } from "../../constants.js";
|
|
10
|
+
import { log } from "../../log.js";
|
|
11
|
+
import { IdentityTransform } from "../../stream/identity_transform.js";
|
|
12
|
+
import { Future, Task } from "../../utils.js";
|
|
13
|
+
import {} from "../agent_session.js";
|
|
14
|
+
import {
|
|
15
|
+
AgentSessionEventTypes,
|
|
16
|
+
CloseReason
|
|
17
|
+
} from "../events.js";
|
|
18
|
+
import { TranscriptionSynchronizer } from "../transcription/synchronizer.js";
|
|
19
|
+
import { ParticipantAudioInputStream } from "./_input.js";
|
|
20
|
+
import {
|
|
21
|
+
ParalellTextOutput,
|
|
22
|
+
ParticipantAudioOutput,
|
|
23
|
+
ParticipantLegacyTranscriptionOutput,
|
|
24
|
+
ParticipantTranscriptionOutput
|
|
25
|
+
} from "./_output.js";
|
|
26
|
+
const DEFAULT_TEXT_INPUT_CALLBACK = (sess, ev) => {
|
|
27
|
+
sess.interrupt();
|
|
28
|
+
sess.generateReply({ userInput: ev.text });
|
|
29
|
+
};
|
|
30
|
+
const DEFAULT_PARTICIPANT_KINDS = [
|
|
31
|
+
ParticipantKind.SIP,
|
|
32
|
+
ParticipantKind.STANDARD
|
|
33
|
+
];
|
|
34
|
+
const CLOSE_ON_DISCONNECT_REASONS = [
|
|
35
|
+
DisconnectReason.CLIENT_INITIATED,
|
|
36
|
+
DisconnectReason.ROOM_DELETED,
|
|
37
|
+
DisconnectReason.USER_REJECTED
|
|
38
|
+
];
|
|
39
|
+
const DEFAULT_ROOM_INPUT_OPTIONS = {
|
|
40
|
+
audioSampleRate: 24e3,
|
|
41
|
+
audioNumChannels: 1,
|
|
42
|
+
textEnabled: true,
|
|
43
|
+
audioEnabled: true,
|
|
44
|
+
videoEnabled: false,
|
|
45
|
+
textInputCallback: DEFAULT_TEXT_INPUT_CALLBACK,
|
|
46
|
+
closeOnDisconnect: true
|
|
47
|
+
};
|
|
48
|
+
const DEFAULT_ROOM_OUTPUT_OPTIONS = {
|
|
49
|
+
audioSampleRate: 24e3,
|
|
50
|
+
audioNumChannels: 1,
|
|
51
|
+
transcriptionEnabled: true,
|
|
52
|
+
audioEnabled: true,
|
|
53
|
+
syncTranscription: true,
|
|
54
|
+
audioPublishOptions: new TrackPublishOptions({ source: TrackSource.SOURCE_MICROPHONE })
|
|
55
|
+
};
|
|
56
|
+
class RoomIO {
|
|
57
|
+
agentSession;
|
|
58
|
+
room;
|
|
59
|
+
inputOptions;
|
|
60
|
+
outputOptions;
|
|
61
|
+
audioInput;
|
|
62
|
+
participantAudioOutput;
|
|
63
|
+
userTranscriptOutput;
|
|
64
|
+
agentTranscriptOutput;
|
|
65
|
+
transcriptionSynchronizer;
|
|
66
|
+
participantIdentity = null;
|
|
67
|
+
participantAvailableFuture = new Future();
|
|
68
|
+
roomConnectedFuture = new Future();
|
|
69
|
+
// Use stream API for transcript queue
|
|
70
|
+
userTranscriptStream = new IdentityTransform();
|
|
71
|
+
userTranscriptWriter;
|
|
72
|
+
forwardUserTranscriptTask;
|
|
73
|
+
initTask;
|
|
74
|
+
textStreamHandlerRegistered = false;
|
|
75
|
+
logger = log();
|
|
76
|
+
constructor({
|
|
77
|
+
agentSession,
|
|
78
|
+
room,
|
|
79
|
+
participant = null,
|
|
80
|
+
inputOptions,
|
|
81
|
+
outputOptions
|
|
82
|
+
}) {
|
|
83
|
+
this.agentSession = agentSession;
|
|
84
|
+
this.room = room;
|
|
85
|
+
this.inputOptions = { ...DEFAULT_ROOM_INPUT_OPTIONS, ...inputOptions };
|
|
86
|
+
this.outputOptions = { ...DEFAULT_ROOM_OUTPUT_OPTIONS, ...outputOptions };
|
|
87
|
+
this.userTranscriptWriter = this.userTranscriptStream.writable.getWriter();
|
|
88
|
+
this.participantIdentity = participant ? typeof participant === "string" ? participant : participant.identity : this.inputOptions.participantIdentity ?? null;
|
|
89
|
+
}
|
|
90
|
+
async init(signal) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
await this.roomConnectedFuture.await;
|
|
93
|
+
for (const participant2 of this.room.remoteParticipants.values()) {
|
|
94
|
+
this.onParticipantConnected(participant2);
|
|
95
|
+
}
|
|
96
|
+
if (signal.aborted) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const participant = await this.participantAvailableFuture.await;
|
|
100
|
+
this.setParticipant(participant.identity);
|
|
101
|
+
this.updateTranscriptionOutput({
|
|
102
|
+
output: this.agentTranscriptOutput,
|
|
103
|
+
participant: ((_a = this.room.localParticipant) == null ? void 0 : _a.identity) ?? null
|
|
104
|
+
});
|
|
105
|
+
await ((_b = this.participantAudioOutput) == null ? void 0 : _b.start(signal));
|
|
106
|
+
}
|
|
107
|
+
onConnectionStateChanged = (state) => {
|
|
108
|
+
this.logger.debug({ state }, "connection state changed");
|
|
109
|
+
if (state === ConnectionState.CONN_CONNECTED && this.room.isConnected && !this.roomConnectedFuture.done) {
|
|
110
|
+
this.roomConnectedFuture.resolve();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
onParticipantConnected = (participant) => {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
if (this.participantAvailableFuture.done) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (this.participantIdentity) {
|
|
119
|
+
if (participant.identity !== this.participantIdentity) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
} else if (
|
|
123
|
+
// otherwise, skip participants that are marked as publishing for this agent
|
|
124
|
+
((_a = participant.attributes) == null ? void 0 : _a[ATTRIBUTE_PUBLISH_ON_BEHALF]) === ((_b = this.room.localParticipant) == null ? void 0 : _b.identity)
|
|
125
|
+
) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const acceptedKinds = this.inputOptions.participantKinds ?? DEFAULT_PARTICIPANT_KINDS;
|
|
129
|
+
if (participant.info.kind !== void 0 && !acceptedKinds.includes(participant.info.kind)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.participantAvailableFuture.resolve(participant);
|
|
133
|
+
};
|
|
134
|
+
onParticipantDisconnected = (participant) => {
|
|
135
|
+
if (participant.identity !== this.participantIdentity) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.participantAvailableFuture = new Future();
|
|
139
|
+
if (this.inputOptions.closeOnDisconnect && participant.disconnectReason && CLOSE_ON_DISCONNECT_REASONS.includes(participant.disconnectReason)) {
|
|
140
|
+
this.logger.info(
|
|
141
|
+
{
|
|
142
|
+
participant: participant.identity,
|
|
143
|
+
reason: DisconnectReason[participant.disconnectReason]
|
|
144
|
+
},
|
|
145
|
+
"closing agent session due to participant disconnect (disable via `RoomInputOptions.closeOnDisconnect=False`)"
|
|
146
|
+
);
|
|
147
|
+
this.agentSession._closeSoon({
|
|
148
|
+
reason: CloseReason.PARTICIPANT_DISCONNECTED
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
onUserInputTranscribed = (ev) => {
|
|
153
|
+
this.userTranscriptWriter.write(ev).catch((error) => {
|
|
154
|
+
this.logger.error({ error }, "Failed to write transcript event to stream");
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
onAgentStateChanged = async (ev) => {
|
|
158
|
+
if (this.room.isConnected && this.room.localParticipant) {
|
|
159
|
+
await this.room.localParticipant.setAttributes({
|
|
160
|
+
[`lk.agent.state`]: ev.newState
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
onUserTextInput = (reader, participantInfo) => {
|
|
165
|
+
if (participantInfo.identity !== this.participantIdentity) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const participant = this.room.remoteParticipants.get(participantInfo.identity);
|
|
169
|
+
if (!participant) {
|
|
170
|
+
this.logger.warn("participant not found, ignoring text input");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const readText = async () => {
|
|
174
|
+
const text = await reader.readAll();
|
|
175
|
+
const textInputResult = this.inputOptions.textInputCallback(this.agentSession, {
|
|
176
|
+
text,
|
|
177
|
+
info: reader.info,
|
|
178
|
+
participant
|
|
179
|
+
});
|
|
180
|
+
if (textInputResult instanceof Promise) {
|
|
181
|
+
await textInputResult;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
readText().catch((error) => {
|
|
185
|
+
this.logger.error({ error }, "Error reading text input");
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
async forwardUserTranscript(signal) {
|
|
189
|
+
var _a, _b;
|
|
190
|
+
const reader = this.userTranscriptStream.readable.getReader();
|
|
191
|
+
try {
|
|
192
|
+
while (!signal.aborted) {
|
|
193
|
+
const { done, value } = await reader.read();
|
|
194
|
+
if (done) break;
|
|
195
|
+
const event = value;
|
|
196
|
+
await ((_a = this.userTranscriptOutput) == null ? void 0 : _a.captureText(event.transcript));
|
|
197
|
+
if (event.isFinal) {
|
|
198
|
+
(_b = this.userTranscriptOutput) == null ? void 0 : _b.flush();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} catch (error) {
|
|
202
|
+
this.logger.error({ error }, "Error processing transcript stream");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
createTranscriptionOutput(options) {
|
|
206
|
+
return new ParalellTextOutput([
|
|
207
|
+
new ParticipantLegacyTranscriptionOutput(
|
|
208
|
+
this.room,
|
|
209
|
+
options.isDeltaStream,
|
|
210
|
+
options.participant
|
|
211
|
+
),
|
|
212
|
+
new ParticipantTranscriptionOutput(this.room, options.isDeltaStream, options.participant)
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
updateTranscriptionOutput({
|
|
216
|
+
output,
|
|
217
|
+
participant
|
|
218
|
+
}) {
|
|
219
|
+
if (!output) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
for (const sink of output._sinks) {
|
|
223
|
+
if (sink instanceof ParticipantLegacyTranscriptionOutput || sink instanceof ParticipantTranscriptionOutput) {
|
|
224
|
+
sink.setParticipant(participant);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
get audioOutput() {
|
|
229
|
+
if (!this.transcriptionSynchronizer) {
|
|
230
|
+
return this.participantAudioOutput;
|
|
231
|
+
}
|
|
232
|
+
return this.transcriptionSynchronizer.audioOutput;
|
|
233
|
+
}
|
|
234
|
+
get transcriptionOutput() {
|
|
235
|
+
if (!this.transcriptionSynchronizer) {
|
|
236
|
+
return this.agentTranscriptOutput;
|
|
237
|
+
}
|
|
238
|
+
return this.transcriptionSynchronizer.textOutput;
|
|
239
|
+
}
|
|
240
|
+
/* Switch to a different participant */
|
|
241
|
+
setParticipant(participantIdentity) {
|
|
242
|
+
var _a;
|
|
243
|
+
this.logger.debug({ participantIdentity }, "setting participant");
|
|
244
|
+
if (participantIdentity === null) {
|
|
245
|
+
this.unsetParticipant();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (this.participantIdentity !== participantIdentity) {
|
|
249
|
+
this.participantAvailableFuture = new Future();
|
|
250
|
+
for (const participant of this.room.remoteParticipants.values()) {
|
|
251
|
+
if (participant.identity === participantIdentity) {
|
|
252
|
+
this.participantAvailableFuture.resolve(participant);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
this.participantIdentity = participantIdentity;
|
|
258
|
+
(_a = this.audioInput) == null ? void 0 : _a.setParticipant(participantIdentity);
|
|
259
|
+
this.updateTranscriptionOutput({
|
|
260
|
+
output: this.userTranscriptOutput,
|
|
261
|
+
participant: participantIdentity
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
unsetParticipant() {
|
|
265
|
+
var _a;
|
|
266
|
+
this.participantIdentity = null;
|
|
267
|
+
this.participantAvailableFuture = new Future();
|
|
268
|
+
(_a = this.audioInput) == null ? void 0 : _a.setParticipant(null);
|
|
269
|
+
this.updateTranscriptionOutput({
|
|
270
|
+
output: this.userTranscriptOutput,
|
|
271
|
+
participant: null
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
start() {
|
|
275
|
+
if (this.inputOptions.textEnabled) {
|
|
276
|
+
try {
|
|
277
|
+
this.room.registerTextStreamHandler(TOPIC_CHAT, this.onUserTextInput);
|
|
278
|
+
this.textStreamHandlerRegistered = true;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
if (this.inputOptions.textEnabled) {
|
|
281
|
+
this.logger.warn(`text stream handler for topic "${TOPIC_CHAT}" already set, ignoring`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (this.inputOptions.audioEnabled) {
|
|
286
|
+
this.audioInput = new ParticipantAudioInputStream({
|
|
287
|
+
room: this.room,
|
|
288
|
+
sampleRate: this.inputOptions.audioSampleRate,
|
|
289
|
+
numChannels: this.inputOptions.audioNumChannels,
|
|
290
|
+
noiseCancellation: this.inputOptions.noiseCancellation
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (this.outputOptions.audioEnabled) {
|
|
294
|
+
this.participantAudioOutput = new ParticipantAudioOutput(this.room, {
|
|
295
|
+
sampleRate: this.outputOptions.audioSampleRate,
|
|
296
|
+
numChannels: this.outputOptions.audioNumChannels,
|
|
297
|
+
trackPublishOptions: this.outputOptions.audioPublishOptions
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (this.outputOptions.transcriptionEnabled) {
|
|
301
|
+
this.userTranscriptOutput = this.createTranscriptionOutput({
|
|
302
|
+
isDeltaStream: false,
|
|
303
|
+
participant: this.participantIdentity
|
|
304
|
+
});
|
|
305
|
+
this.forwardUserTranscriptTask = Task.from(
|
|
306
|
+
(controller) => this.forwardUserTranscript(controller.signal)
|
|
307
|
+
);
|
|
308
|
+
this.agentTranscriptOutput = this.createTranscriptionOutput({
|
|
309
|
+
isDeltaStream: true,
|
|
310
|
+
participant: null
|
|
311
|
+
});
|
|
312
|
+
const audioOutput = this.participantAudioOutput;
|
|
313
|
+
if (this.outputOptions.syncTranscription && audioOutput) {
|
|
314
|
+
this.transcriptionSynchronizer = new TranscriptionSynchronizer(
|
|
315
|
+
audioOutput,
|
|
316
|
+
this.agentTranscriptOutput
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
this.room.on(RoomEvent.ParticipantConnected, this.onParticipantConnected);
|
|
321
|
+
this.room.on(RoomEvent.ConnectionStateChanged, this.onConnectionStateChanged);
|
|
322
|
+
this.room.on(RoomEvent.ParticipantDisconnected, this.onParticipantDisconnected);
|
|
323
|
+
if (this.room.isConnected) {
|
|
324
|
+
this.onConnectionStateChanged(ConnectionState.CONN_CONNECTED);
|
|
325
|
+
}
|
|
326
|
+
this.initTask = Task.from((controller) => this.init(controller.signal));
|
|
327
|
+
if (this.audioInput) {
|
|
328
|
+
this.agentSession.input.audio = this.audioInput;
|
|
329
|
+
}
|
|
330
|
+
if (this.audioOutput) {
|
|
331
|
+
this.agentSession.output.audio = this.audioOutput;
|
|
332
|
+
}
|
|
333
|
+
if (this.transcriptionOutput) {
|
|
334
|
+
this.agentSession.output.transcription = this.transcriptionOutput;
|
|
335
|
+
}
|
|
336
|
+
this.agentSession.on(AgentSessionEventTypes.AgentStateChanged, this.onAgentStateChanged);
|
|
337
|
+
this.agentSession.on(AgentSessionEventTypes.UserInputTranscribed, this.onUserInputTranscribed);
|
|
338
|
+
}
|
|
339
|
+
async close() {
|
|
340
|
+
var _a, _b, _c, _d, _e;
|
|
341
|
+
this.room.off(RoomEvent.ParticipantConnected, this.onParticipantConnected);
|
|
342
|
+
this.room.off(RoomEvent.ConnectionStateChanged, this.onConnectionStateChanged);
|
|
343
|
+
this.room.off(RoomEvent.ParticipantDisconnected, this.onParticipantDisconnected);
|
|
344
|
+
this.agentSession.off(AgentSessionEventTypes.UserInputTranscribed, this.onUserInputTranscribed);
|
|
345
|
+
this.agentSession.off(AgentSessionEventTypes.AgentStateChanged, this.onAgentStateChanged);
|
|
346
|
+
if (this.textStreamHandlerRegistered) {
|
|
347
|
+
this.room.unregisterTextStreamHandler(TOPIC_CHAT);
|
|
348
|
+
this.textStreamHandlerRegistered = false;
|
|
349
|
+
}
|
|
350
|
+
await ((_a = this.initTask) == null ? void 0 : _a.cancelAndWait());
|
|
351
|
+
this.userTranscriptWriter.close();
|
|
352
|
+
await ((_b = this.forwardUserTranscriptTask) == null ? void 0 : _b.cancelAndWait());
|
|
353
|
+
await ((_c = this.audioInput) == null ? void 0 : _c.close());
|
|
354
|
+
await ((_d = this.participantAudioOutput) == null ? void 0 : _d.close());
|
|
355
|
+
await ((_e = this.transcriptionSynchronizer) == null ? void 0 : _e.close());
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
export {
|
|
359
|
+
RoomIO
|
|
360
|
+
};
|
|
361
|
+
//# sourceMappingURL=room_io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/room_io/room_io.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {\n ConnectionState,\n DisconnectReason,\n type NoiseCancellationOptions,\n type Participant,\n ParticipantKind,\n type RemoteParticipant,\n type Room,\n RoomEvent,\n type TextStreamInfo,\n type TextStreamReader,\n TrackPublishOptions,\n TrackSource,\n} from '@livekit/rtc-node';\nimport type { WritableStreamDefaultWriter } from 'node:stream/web';\nimport { ATTRIBUTE_PUBLISH_ON_BEHALF, TOPIC_CHAT } from '../../constants.js';\nimport { log } from '../../log.js';\nimport { IdentityTransform } from '../../stream/identity_transform.js';\nimport { Future, Task } from '../../utils.js';\nimport { type AgentSession } from '../agent_session.js';\nimport {\n AgentSessionEventTypes,\n type AgentStateChangedEvent,\n CloseReason,\n type UserInputTranscribedEvent,\n} from '../events.js';\nimport type { AudioOutput, TextOutput } from '../io.js';\nimport { TranscriptionSynchronizer } from '../transcription/synchronizer.js';\nimport { ParticipantAudioInputStream } from './_input.js';\nimport {\n ParalellTextOutput,\n ParticipantAudioOutput,\n ParticipantLegacyTranscriptionOutput,\n ParticipantTranscriptionOutput,\n} from './_output.js';\n\nexport interface TextInputEvent {\n text: string;\n info: TextStreamInfo;\n participant: RemoteParticipant;\n}\n\nexport type TextInputCallback = (sess: AgentSession, ev: TextInputEvent) => void | Promise<void>;\n\nconst DEFAULT_TEXT_INPUT_CALLBACK: TextInputCallback = (sess: AgentSession, ev: TextInputEvent) => {\n sess.interrupt();\n sess.generateReply({ userInput: ev.text });\n};\n\nconst DEFAULT_PARTICIPANT_KINDS: ParticipantKind[] = [\n ParticipantKind.SIP,\n ParticipantKind.STANDARD,\n];\n\nconst CLOSE_ON_DISCONNECT_REASONS: DisconnectReason[] = [\n DisconnectReason.CLIENT_INITIATED,\n DisconnectReason.ROOM_DELETED,\n DisconnectReason.USER_REJECTED,\n];\n\nexport interface RoomInputOptions {\n audioSampleRate: number;\n audioNumChannels: number;\n textEnabled: boolean;\n audioEnabled: boolean;\n videoEnabled: boolean;\n participantIdentity?: string;\n noiseCancellation?: NoiseCancellationOptions;\n textInputCallback?: TextInputCallback;\n participantKinds?: ParticipantKind[];\n closeOnDisconnect: boolean;\n}\n\nexport interface RoomOutputOptions {\n transcriptionEnabled: boolean;\n audioEnabled: boolean;\n audioSampleRate: number;\n audioNumChannels: number;\n syncTranscription: boolean;\n audioPublishOptions: TrackPublishOptions;\n}\n\nconst DEFAULT_ROOM_INPUT_OPTIONS: RoomInputOptions = {\n audioSampleRate: 24000,\n audioNumChannels: 1,\n textEnabled: true,\n audioEnabled: true,\n videoEnabled: false,\n textInputCallback: DEFAULT_TEXT_INPUT_CALLBACK,\n closeOnDisconnect: true,\n};\n\nconst DEFAULT_ROOM_OUTPUT_OPTIONS: RoomOutputOptions = {\n audioSampleRate: 24000,\n audioNumChannels: 1,\n transcriptionEnabled: true,\n audioEnabled: true,\n syncTranscription: true,\n audioPublishOptions: new TrackPublishOptions({ source: TrackSource.SOURCE_MICROPHONE }),\n};\n\nexport class RoomIO {\n private agentSession: AgentSession;\n private room: Room;\n private inputOptions: RoomInputOptions;\n private outputOptions: RoomOutputOptions;\n\n private audioInput?: ParticipantAudioInputStream;\n private participantAudioOutput?: ParticipantAudioOutput;\n private userTranscriptOutput?: ParalellTextOutput;\n private agentTranscriptOutput?: ParalellTextOutput;\n private transcriptionSynchronizer?: TranscriptionSynchronizer;\n private participantIdentity: string | null = null;\n\n private participantAvailableFuture: Future<RemoteParticipant> = new Future();\n private roomConnectedFuture: Future<void> = new Future();\n\n // Use stream API for transcript queue\n private userTranscriptStream = new IdentityTransform<UserInputTranscribedEvent>();\n private userTranscriptWriter: WritableStreamDefaultWriter<UserInputTranscribedEvent>;\n private forwardUserTranscriptTask?: Task<void>;\n private initTask?: Task<void>;\n\n private textStreamHandlerRegistered = false;\n\n private logger = log();\n\n constructor({\n agentSession,\n room,\n participant = null,\n inputOptions,\n outputOptions,\n }: {\n agentSession: AgentSession;\n room: Room;\n participant?: RemoteParticipant | string | null;\n inputOptions?: Partial<RoomInputOptions>;\n outputOptions?: Partial<RoomOutputOptions>;\n }) {\n this.agentSession = agentSession;\n this.room = room;\n this.inputOptions = { ...DEFAULT_ROOM_INPUT_OPTIONS, ...inputOptions };\n this.outputOptions = { ...DEFAULT_ROOM_OUTPUT_OPTIONS, ...outputOptions };\n\n this.userTranscriptWriter = this.userTranscriptStream.writable.getWriter();\n\n this.participantIdentity = participant\n ? typeof participant === 'string'\n ? participant\n : participant.identity\n : this.inputOptions.participantIdentity ?? null;\n }\n private async init(signal: AbortSignal): Promise<void> {\n await this.roomConnectedFuture.await;\n\n for (const participant of this.room.remoteParticipants.values()) {\n this.onParticipantConnected(participant);\n }\n if (signal.aborted) {\n return;\n }\n\n const participant = await this.participantAvailableFuture.await;\n this.setParticipant(participant.identity);\n\n // init agent outputs\n this.updateTranscriptionOutput({\n output: this.agentTranscriptOutput,\n participant: this.room.localParticipant?.identity ?? null,\n });\n\n await this.participantAudioOutput?.start(signal);\n }\n\n private onConnectionStateChanged = (state: ConnectionState) => {\n this.logger.debug({ state }, 'connection state changed');\n if (\n state === ConnectionState.CONN_CONNECTED &&\n this.room.isConnected &&\n !this.roomConnectedFuture.done\n ) {\n this.roomConnectedFuture.resolve();\n }\n };\n\n private onParticipantConnected = (participant: RemoteParticipant) => {\n if (this.participantAvailableFuture.done) {\n return;\n }\n\n if (this.participantIdentity) {\n if (participant.identity !== this.participantIdentity) {\n return;\n }\n } else if (\n // otherwise, skip participants that are marked as publishing for this agent\n participant.attributes?.[ATTRIBUTE_PUBLISH_ON_BEHALF] === this.room.localParticipant?.identity\n ) {\n return;\n }\n\n const acceptedKinds = this.inputOptions.participantKinds ?? DEFAULT_PARTICIPANT_KINDS;\n if (participant.info.kind !== undefined && !acceptedKinds.includes(participant.info.kind)) {\n return;\n }\n\n this.participantAvailableFuture.resolve(participant);\n };\n\n private onParticipantDisconnected = (participant: RemoteParticipant) => {\n if (participant.identity !== this.participantIdentity) {\n return;\n }\n this.participantAvailableFuture = new Future<RemoteParticipant>();\n if (\n this.inputOptions.closeOnDisconnect &&\n participant.disconnectReason &&\n CLOSE_ON_DISCONNECT_REASONS.includes(participant.disconnectReason)\n ) {\n this.logger.info(\n {\n participant: participant.identity,\n reason: DisconnectReason[participant.disconnectReason],\n },\n 'closing agent session due to participant disconnect ' +\n '(disable via `RoomInputOptions.closeOnDisconnect=False`)',\n );\n this.agentSession._closeSoon({\n reason: CloseReason.PARTICIPANT_DISCONNECTED,\n });\n }\n };\n\n private onUserInputTranscribed = (ev: UserInputTranscribedEvent) => {\n this.userTranscriptWriter.write(ev).catch((error) => {\n this.logger.error({ error }, 'Failed to write transcript event to stream');\n });\n };\n\n private onAgentStateChanged = async (ev: AgentStateChangedEvent) => {\n if (this.room.isConnected && this.room.localParticipant) {\n await this.room.localParticipant.setAttributes({\n [`lk.agent.state`]: ev.newState,\n });\n }\n };\n\n private onUserTextInput = (reader: TextStreamReader, participantInfo: { identity: string }) => {\n if (participantInfo.identity !== this.participantIdentity) {\n return;\n }\n\n const participant = this.room.remoteParticipants.get(participantInfo.identity);\n if (!participant) {\n this.logger.warn('participant not found, ignoring text input');\n return;\n }\n\n const readText = async () => {\n const text = await reader.readAll();\n\n const textInputResult = this.inputOptions.textInputCallback!(this.agentSession, {\n text,\n info: reader.info,\n participant,\n });\n\n // check if callback is a Promise\n if (textInputResult instanceof Promise) {\n await textInputResult;\n }\n };\n\n readText().catch((error) => {\n this.logger.error({ error }, 'Error reading text input');\n });\n };\n\n private async forwardUserTranscript(signal: AbortSignal): Promise<void> {\n const reader = this.userTranscriptStream.readable.getReader();\n try {\n while (!signal.aborted) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const event = value;\n // IMPORTANT: need to await here to avoid race condition\n await this.userTranscriptOutput?.captureText(event.transcript);\n if (event.isFinal) {\n this.userTranscriptOutput?.flush();\n }\n }\n } catch (error) {\n this.logger.error({ error }, 'Error processing transcript stream');\n }\n }\n\n private createTranscriptionOutput(options: {\n isDeltaStream: boolean;\n participant: Participant | string | null;\n }) {\n return new ParalellTextOutput([\n new ParticipantLegacyTranscriptionOutput(\n this.room,\n options.isDeltaStream,\n options.participant,\n ),\n new ParticipantTranscriptionOutput(this.room, options.isDeltaStream, options.participant),\n ]);\n }\n\n private updateTranscriptionOutput({\n output,\n participant,\n }: {\n output?: ParalellTextOutput;\n participant: string | null;\n }) {\n if (!output) {\n return;\n }\n\n for (const sink of output._sinks) {\n if (\n sink instanceof ParticipantLegacyTranscriptionOutput ||\n sink instanceof ParticipantTranscriptionOutput\n ) {\n sink.setParticipant(participant);\n }\n }\n }\n\n get audioOutput(): AudioOutput | undefined {\n if (!this.transcriptionSynchronizer) {\n return this.participantAudioOutput;\n }\n\n return this.transcriptionSynchronizer.audioOutput;\n }\n\n get transcriptionOutput(): TextOutput | undefined {\n if (!this.transcriptionSynchronizer) {\n return this.agentTranscriptOutput;\n }\n\n return this.transcriptionSynchronizer.textOutput;\n }\n\n /* Switch to a different participant */\n setParticipant(participantIdentity: string | null) {\n this.logger.debug({ participantIdentity }, 'setting participant');\n if (participantIdentity === null) {\n this.unsetParticipant();\n return;\n }\n\n if (this.participantIdentity !== participantIdentity) {\n this.participantAvailableFuture = new Future<RemoteParticipant>();\n\n // check if new participant is already connected\n for (const participant of this.room.remoteParticipants.values()) {\n if (participant.identity === participantIdentity) {\n this.participantAvailableFuture.resolve(participant);\n break;\n }\n }\n }\n\n // update participant identity and handlers\n this.participantIdentity = participantIdentity;\n this.audioInput?.setParticipant(participantIdentity);\n this.updateTranscriptionOutput({\n output: this.userTranscriptOutput,\n participant: participantIdentity,\n });\n }\n\n unsetParticipant() {\n this.participantIdentity = null;\n this.participantAvailableFuture = new Future<RemoteParticipant>();\n this.audioInput?.setParticipant(null);\n this.updateTranscriptionOutput({\n output: this.userTranscriptOutput,\n participant: null,\n });\n }\n\n start() {\n if (this.inputOptions.textEnabled) {\n try {\n this.room.registerTextStreamHandler(TOPIC_CHAT, this.onUserTextInput);\n this.textStreamHandlerRegistered = true;\n } catch (error) {\n if (this.inputOptions.textEnabled) {\n this.logger.warn(`text stream handler for topic \"${TOPIC_CHAT}\" already set, ignoring`);\n }\n }\n }\n\n // -- create inputs --\n if (this.inputOptions.audioEnabled) {\n this.audioInput = new ParticipantAudioInputStream({\n room: this.room,\n sampleRate: this.inputOptions.audioSampleRate,\n numChannels: this.inputOptions.audioNumChannels,\n noiseCancellation: this.inputOptions.noiseCancellation,\n });\n }\n\n // -- create outputs --\n if (this.outputOptions.audioEnabled) {\n this.participantAudioOutput = new ParticipantAudioOutput(this.room, {\n sampleRate: this.outputOptions.audioSampleRate,\n numChannels: this.outputOptions.audioNumChannels,\n trackPublishOptions: this.outputOptions.audioPublishOptions,\n });\n }\n if (this.outputOptions.transcriptionEnabled) {\n this.userTranscriptOutput = this.createTranscriptionOutput({\n isDeltaStream: false,\n participant: this.participantIdentity,\n });\n // Start the transcript forwarding\n this.forwardUserTranscriptTask = Task.from((controller) =>\n this.forwardUserTranscript(controller.signal),\n );\n this.agentTranscriptOutput = this.createTranscriptionOutput({\n isDeltaStream: true,\n participant: null,\n });\n\n // use the RoomIO's audio output if available, otherwise use the agent's audio output\n // TODO(AJS-176): check for agent output\n const audioOutput = this.participantAudioOutput;\n if (this.outputOptions.syncTranscription && audioOutput) {\n this.transcriptionSynchronizer = new TranscriptionSynchronizer(\n audioOutput,\n this.agentTranscriptOutput,\n );\n }\n }\n\n // -- set the room event handlers --\n this.room.on(RoomEvent.ParticipantConnected, this.onParticipantConnected);\n this.room.on(RoomEvent.ConnectionStateChanged, this.onConnectionStateChanged);\n this.room.on(RoomEvent.ParticipantDisconnected, this.onParticipantDisconnected);\n if (this.room.isConnected) {\n this.onConnectionStateChanged(ConnectionState.CONN_CONNECTED);\n }\n\n this.initTask = Task.from((controller) => this.init(controller.signal));\n\n // -- attatch the agent to the session --\n if (this.audioInput) {\n this.agentSession.input.audio = this.audioInput;\n }\n if (this.audioOutput) {\n this.agentSession.output.audio = this.audioOutput;\n }\n if (this.transcriptionOutput) {\n this.agentSession.output.transcription = this.transcriptionOutput;\n }\n\n this.agentSession.on(AgentSessionEventTypes.AgentStateChanged, this.onAgentStateChanged);\n this.agentSession.on(AgentSessionEventTypes.UserInputTranscribed, this.onUserInputTranscribed);\n }\n\n async close() {\n this.room.off(RoomEvent.ParticipantConnected, this.onParticipantConnected);\n this.room.off(RoomEvent.ConnectionStateChanged, this.onConnectionStateChanged);\n this.room.off(RoomEvent.ParticipantDisconnected, this.onParticipantDisconnected);\n this.agentSession.off(AgentSessionEventTypes.UserInputTranscribed, this.onUserInputTranscribed);\n this.agentSession.off(AgentSessionEventTypes.AgentStateChanged, this.onAgentStateChanged);\n\n if (this.textStreamHandlerRegistered) {\n this.room.unregisterTextStreamHandler(TOPIC_CHAT);\n this.textStreamHandlerRegistered = false;\n }\n\n await this.initTask?.cancelAndWait();\n\n // Close stream FIRST so reader.read() in forwardUserTranscript can exit.\n // This is a workaround for a race condition in the stream API.\n this.userTranscriptWriter.close();\n await this.forwardUserTranscriptTask?.cancelAndWait();\n\n await this.audioInput?.close();\n await this.participantAudioOutput?.close();\n await this.transcriptionSynchronizer?.close();\n }\n}\n"],"mappings":"AAGA;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EAGA;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,6BAA6B,kBAAkB;AACxD,SAAS,WAAW;AACpB,SAAS,yBAAyB;AAClC,SAAS,QAAQ,YAAY;AAC7B,eAAkC;AAClC;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AAEP,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUP,MAAM,8BAAiD,CAAC,MAAoB,OAAuB;AACjG,OAAK,UAAU;AACf,OAAK,cAAc,EAAE,WAAW,GAAG,KAAK,CAAC;AAC3C;AAEA,MAAM,4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AAAA,EAEA,MAAM,QAAQ;AAvdhB;AAwdI,SAAK,KAAK,IAAI,UAAU,sBAAsB,KAAK,sBAAsB;AACzE,SAAK,KAAK,IAAI,UAAU,wBAAwB,KAAK,wBAAwB;AAC7E,SAAK,KAAK,IAAI,UAAU,yBAAyB,KAAK,yBAAyB;AAC/E,SAAK,aAAa,IAAI,uBAAuB,sBAAsB,KAAK,sBAAsB;AAC9F,SAAK,aAAa,IAAI,uBAAuB,mBAAmB,KAAK,mBAAmB;AAExF,QAAI,KAAK,6BAA6B;AACpC,WAAK,KAAK,4BAA4B,UAAU;AAChD,WAAK,8BAA8B;AAAA,IACrC;AAEA,YAAM,UAAK,aAAL,mBAAe;AAIrB,SAAK,qBAAqB,MAAM;AAChC,YAAM,UAAK,8BAAL,mBAAgC;AAEtC,YAAM,UAAK,eAAL,mBAAiB;AACvB,YAAM,UAAK,2BAAL,mBAA6B;AACnC,YAAM,UAAK,8BAAL,mBAAgC;AAAA,EACxC;AACF;","names":["participant"]}
|
|
@@ -16,18 +16,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
22
|
-
VPAEvent: () => import_pipeline_agent.VPAEvent,
|
|
23
|
-
VoicePipelineAgent: () => import_pipeline_agent.VoicePipelineAgent
|
|
19
|
+
var run_context_exports = {};
|
|
20
|
+
__export(run_context_exports, {
|
|
21
|
+
RunContext: () => RunContext
|
|
24
22
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
|
|
23
|
+
module.exports = __toCommonJS(run_context_exports);
|
|
24
|
+
class RunContext {
|
|
25
|
+
constructor(session, speechHandle, functionCall) {
|
|
26
|
+
this.session = session;
|
|
27
|
+
this.speechHandle = speechHandle;
|
|
28
|
+
this.functionCall = functionCall;
|
|
29
|
+
}
|
|
30
|
+
get userData() {
|
|
31
|
+
return this.session.userData;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
35
|
0 && (module.exports = {
|
|
29
|
-
|
|
30
|
-
VPAEvent,
|
|
31
|
-
VoicePipelineAgent
|
|
36
|
+
RunContext
|
|
32
37
|
});
|
|
33
|
-
//# sourceMappingURL=
|
|
38
|
+
//# sourceMappingURL=run_context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/voice/run_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { FunctionCall } from '../llm/chat_context.js';\nimport type { AgentSession } from './agent_session.js';\nimport type { SpeechHandle } from './speech_handle.js';\n\nexport type UnknownUserData = unknown;\n\nexport class RunContext<UserData = UnknownUserData> {\n constructor(\n public readonly session: AgentSession<UserData>,\n public readonly speechHandle: SpeechHandle,\n public readonly functionCall: FunctionCall,\n ) {}\n\n get userData(): UserData {\n return this.session.userData;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,MAAM,WAAuC;AAAA,EAClD,YACkB,SACA,cACA,cAChB;AAHgB;AACA;AACA;AAAA,EACf;AAAA,EAEH,IAAI,WAAqB;AACvB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FunctionCall } from '../llm/chat_context.js';
|
|
2
|
+
import type { AgentSession } from './agent_session.js';
|
|
3
|
+
import type { SpeechHandle } from './speech_handle.js';
|
|
4
|
+
export type UnknownUserData = unknown;
|
|
5
|
+
export declare class RunContext<UserData = UnknownUserData> {
|
|
6
|
+
readonly session: AgentSession<UserData>;
|
|
7
|
+
readonly speechHandle: SpeechHandle;
|
|
8
|
+
readonly functionCall: FunctionCall;
|
|
9
|
+
constructor(session: AgentSession<UserData>, speechHandle: SpeechHandle, functionCall: FunctionCall);
|
|
10
|
+
get userData(): UserData;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=run_context.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FunctionCall } from '../llm/chat_context.js';
|
|
2
|
+
import type { AgentSession } from './agent_session.js';
|
|
3
|
+
import type { SpeechHandle } from './speech_handle.js';
|
|
4
|
+
export type UnknownUserData = unknown;
|
|
5
|
+
export declare class RunContext<UserData = UnknownUserData> {
|
|
6
|
+
readonly session: AgentSession<UserData>;
|
|
7
|
+
readonly speechHandle: SpeechHandle;
|
|
8
|
+
readonly functionCall: FunctionCall;
|
|
9
|
+
constructor(session: AgentSession<UserData>, speechHandle: SpeechHandle, functionCall: FunctionCall);
|
|
10
|
+
get userData(): UserData;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=run_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run_context.d.ts","sourceRoot":"","sources":["../../src/voice/run_context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC;AAEtC,qBAAa,UAAU,CAAC,QAAQ,GAAG,eAAe;aAE9B,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC;aAC/B,YAAY,EAAE,YAAY;aAC1B,YAAY,EAAE,YAAY;gBAF1B,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,EAC/B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY;IAG5C,IAAI,QAAQ,IAAI,QAAQ,CAEvB;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class RunContext {
|
|
2
|
+
constructor(session, speechHandle, functionCall) {
|
|
3
|
+
this.session = session;
|
|
4
|
+
this.speechHandle = speechHandle;
|
|
5
|
+
this.functionCall = functionCall;
|
|
6
|
+
}
|
|
7
|
+
get userData() {
|
|
8
|
+
return this.session.userData;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
RunContext
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=run_context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/voice/run_context.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { FunctionCall } from '../llm/chat_context.js';\nimport type { AgentSession } from './agent_session.js';\nimport type { SpeechHandle } from './speech_handle.js';\n\nexport type UnknownUserData = unknown;\n\nexport class RunContext<UserData = UnknownUserData> {\n constructor(\n public readonly session: AgentSession<UserData>,\n public readonly speechHandle: SpeechHandle,\n public readonly functionCall: FunctionCall,\n ) {}\n\n get userData(): UserData {\n return this.session.userData;\n }\n}\n"],"mappings":"AASO,MAAM,WAAuC;AAAA,EAClD,YACkB,SACA,cACA,cAChB;AAHgB;AACA;AACA;AAAA,EACf;AAAA,EAEH,IAAI,WAAqB;AACvB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;","names":[]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var speech_handle_exports = {};
|
|
20
|
+
__export(speech_handle_exports, {
|
|
21
|
+
SpeechHandle: () => SpeechHandle
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(speech_handle_exports);
|
|
24
|
+
var import_utils = require("../utils.cjs");
|
|
25
|
+
class SpeechHandle {
|
|
26
|
+
constructor(id, allowInterruptions, stepIndex, parent) {
|
|
27
|
+
this.id = id;
|
|
28
|
+
this.allowInterruptions = allowInterruptions;
|
|
29
|
+
this.stepIndex = stepIndex;
|
|
30
|
+
this.parent = parent;
|
|
31
|
+
}
|
|
32
|
+
/** Priority for messages that should be played after all other messages in the queue */
|
|
33
|
+
static SPEECH_PRIORITY_LOW = 0;
|
|
34
|
+
/** Every speech generates by the VoiceAgent defaults to this priority. */
|
|
35
|
+
static SPEECH_PRIORITY_NORMAL = 5;
|
|
36
|
+
/** Priority for important messages that should be played before others. */
|
|
37
|
+
static SPEECH_PRIORITY_HIGH = 10;
|
|
38
|
+
interruptFut = new import_utils.Future();
|
|
39
|
+
authorizeFut = new import_utils.Future();
|
|
40
|
+
playoutDoneFut = new import_utils.Future();
|
|
41
|
+
_chatMessage;
|
|
42
|
+
static create(options) {
|
|
43
|
+
const { allowInterruptions = false, stepIndex = 0, parent } = options ?? {};
|
|
44
|
+
return new SpeechHandle((0, import_utils.shortuuid)("speech_"), allowInterruptions, stepIndex, parent);
|
|
45
|
+
}
|
|
46
|
+
get interrupted() {
|
|
47
|
+
return this.interruptFut.done;
|
|
48
|
+
}
|
|
49
|
+
get done() {
|
|
50
|
+
return this.playoutDoneFut.done;
|
|
51
|
+
}
|
|
52
|
+
get chatMessage() {
|
|
53
|
+
return this._chatMessage;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Interrupt the current speech generation.
|
|
57
|
+
*
|
|
58
|
+
* @throws Error If this speech handle does not allow interruptions.
|
|
59
|
+
*
|
|
60
|
+
* @returns The same speech handle that was interrupted.
|
|
61
|
+
*/
|
|
62
|
+
interrupt() {
|
|
63
|
+
if (!this.allowInterruptions) {
|
|
64
|
+
throw new Error("interruptions are not allowed");
|
|
65
|
+
}
|
|
66
|
+
if (this.done) return this;
|
|
67
|
+
this.interruptFut.resolve();
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
then(callback) {
|
|
71
|
+
return this.playoutDoneFut.await.finally(() => callback(this));
|
|
72
|
+
}
|
|
73
|
+
async waitForPlayout() {
|
|
74
|
+
return this.playoutDoneFut.await;
|
|
75
|
+
}
|
|
76
|
+
async waitIfNotInterrupted(aw) {
|
|
77
|
+
const allTasksPromise = Promise.all(aw);
|
|
78
|
+
const fs = [allTasksPromise, this.interruptFut.await];
|
|
79
|
+
await Promise.race(fs);
|
|
80
|
+
}
|
|
81
|
+
/** @internal */
|
|
82
|
+
_setChatMessage(chatMessage) {
|
|
83
|
+
if (this.done) {
|
|
84
|
+
throw new Error("cannot set chat message after speech has been played");
|
|
85
|
+
}
|
|
86
|
+
this._chatMessage = chatMessage;
|
|
87
|
+
}
|
|
88
|
+
/** @internal */
|
|
89
|
+
_authorizePlayout() {
|
|
90
|
+
this.authorizeFut.resolve();
|
|
91
|
+
}
|
|
92
|
+
/** @internal */
|
|
93
|
+
async _waitForAuthorization() {
|
|
94
|
+
return this.authorizeFut.await;
|
|
95
|
+
}
|
|
96
|
+
/** @internal */
|
|
97
|
+
_markPlayoutDone() {
|
|
98
|
+
this.playoutDoneFut.resolve();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
SpeechHandle
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=speech_handle.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/voice/speech_handle.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChatMessage } from '../llm/index.js';\nimport { Future, shortuuid } from '../utils.js';\n\nexport class SpeechHandle {\n /** Priority for messages that should be played after all other messages in the queue */\n static SPEECH_PRIORITY_LOW = 0;\n /** Every speech generates by the VoiceAgent defaults to this priority. */\n static SPEECH_PRIORITY_NORMAL = 5;\n /** Priority for important messages that should be played before others. */\n static SPEECH_PRIORITY_HIGH = 10;\n\n private interruptFut = new Future();\n private authorizeFut = new Future();\n private playoutDoneFut = new Future();\n\n private _chatMessage?: ChatMessage;\n\n constructor(\n readonly id: string,\n readonly allowInterruptions: boolean,\n readonly stepIndex: number,\n readonly parent?: SpeechHandle,\n ) {}\n\n static create(options: {\n allowInterruptions?: boolean;\n stepIndex?: number;\n parent?: SpeechHandle;\n }) {\n const { allowInterruptions = false, stepIndex = 0, parent } = options ?? {};\n\n return new SpeechHandle(shortuuid('speech_'), allowInterruptions, stepIndex, parent);\n }\n\n get interrupted(): boolean {\n return this.interruptFut.done;\n }\n\n get done(): boolean {\n return this.playoutDoneFut.done;\n }\n\n get chatMessage(): ChatMessage | undefined {\n return this._chatMessage;\n }\n\n /**\n * Interrupt the current speech generation.\n *\n * @throws Error If this speech handle does not allow interruptions.\n *\n * @returns The same speech handle that was interrupted.\n */\n interrupt(): SpeechHandle {\n if (!this.allowInterruptions) {\n throw new Error('interruptions are not allowed');\n }\n\n if (this.done) return this;\n\n this.interruptFut.resolve();\n return this;\n }\n\n then(callback: (sh: SpeechHandle) => void) {\n return this.playoutDoneFut.await.finally(() => callback(this));\n }\n\n async waitForPlayout() {\n return this.playoutDoneFut.await;\n }\n\n async waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void> {\n const allTasksPromise = Promise.all(aw);\n const fs: Promise<unknown>[] = [allTasksPromise, this.interruptFut.await];\n await Promise.race(fs);\n }\n\n /** @internal */\n _setChatMessage(chatMessage: ChatMessage) {\n if (this.done) {\n throw new Error('cannot set chat message after speech has been played');\n }\n this._chatMessage = chatMessage;\n }\n\n /** @internal */\n _authorizePlayout() {\n this.authorizeFut.resolve();\n }\n\n /** @internal */\n async _waitForAuthorization() {\n return this.authorizeFut.await;\n }\n\n /** @internal */\n _markPlayoutDone() {\n this.playoutDoneFut.resolve();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAkC;AAE3B,MAAM,aAAa;AAAA,EAcxB,YACW,IACA,oBACA,WACA,QACT;AAJS;AACA;AACA;AACA;AAAA,EACR;AAAA;AAAA,EAjBH,OAAO,sBAAsB;AAAA;AAAA,EAE7B,OAAO,yBAAyB;AAAA;AAAA,EAEhC,OAAO,uBAAuB;AAAA,EAEtB,eAAe,IAAI,oBAAO;AAAA,EAC1B,eAAe,IAAI,oBAAO;AAAA,EAC1B,iBAAiB,IAAI,oBAAO;AAAA,EAE5B;AAAA,EASR,OAAO,OAAO,SAIX;AACD,UAAM,EAAE,qBAAqB,OAAO,YAAY,GAAG,OAAO,IAAI,WAAW,CAAC;AAE1E,WAAO,IAAI,iBAAa,wBAAU,SAAS,GAAG,oBAAoB,WAAW,MAAM;AAAA,EACrF;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,aAAa;AAAA,EAC3B;AAAA,EAEA,IAAI,OAAgB;AAClB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAuC;AACzC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAA0B;AACxB,QAAI,CAAC,KAAK,oBAAoB;AAC5B,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,QAAI,KAAK,KAAM,QAAO;AAEtB,SAAK,aAAa,QAAQ;AAC1B,WAAO;AAAA,EACT;AAAA,EAEA,KAAK,UAAsC;AACzC,WAAO,KAAK,eAAe,MAAM,QAAQ,MAAM,SAAS,IAAI,CAAC;AAAA,EAC/D;AAAA,EAEA,MAAM,iBAAiB;AACrB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,MAAM,qBAAqB,IAAuC;AAChE,UAAM,kBAAkB,QAAQ,IAAI,EAAE;AACtC,UAAM,KAAyB,CAAC,iBAAiB,KAAK,aAAa,KAAK;AACxE,UAAM,QAAQ,KAAK,EAAE;AAAA,EACvB;AAAA;AAAA,EAGA,gBAAgB,aAA0B;AACxC,QAAI,KAAK,MAAM;AACb,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AACA,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA,EAGA,oBAAoB;AAClB,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA;AAAA,EAGA,MAAM,wBAAwB;AAC5B,WAAO,KAAK,aAAa;AAAA,EAC3B;AAAA;AAAA,EAGA,mBAAmB;AACjB,SAAK,eAAe,QAAQ;AAAA,EAC9B;AACF;","names":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ChatMessage } from '../llm/index.js';
|
|
2
|
+
export declare class SpeechHandle {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly allowInterruptions: boolean;
|
|
5
|
+
readonly stepIndex: number;
|
|
6
|
+
readonly parent?: SpeechHandle | undefined;
|
|
7
|
+
/** Priority for messages that should be played after all other messages in the queue */
|
|
8
|
+
static SPEECH_PRIORITY_LOW: number;
|
|
9
|
+
/** Every speech generates by the VoiceAgent defaults to this priority. */
|
|
10
|
+
static SPEECH_PRIORITY_NORMAL: number;
|
|
11
|
+
/** Priority for important messages that should be played before others. */
|
|
12
|
+
static SPEECH_PRIORITY_HIGH: number;
|
|
13
|
+
private interruptFut;
|
|
14
|
+
private authorizeFut;
|
|
15
|
+
private playoutDoneFut;
|
|
16
|
+
private _chatMessage?;
|
|
17
|
+
constructor(id: string, allowInterruptions: boolean, stepIndex: number, parent?: SpeechHandle | undefined);
|
|
18
|
+
static create(options: {
|
|
19
|
+
allowInterruptions?: boolean;
|
|
20
|
+
stepIndex?: number;
|
|
21
|
+
parent?: SpeechHandle;
|
|
22
|
+
}): SpeechHandle;
|
|
23
|
+
get interrupted(): boolean;
|
|
24
|
+
get done(): boolean;
|
|
25
|
+
get chatMessage(): ChatMessage | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Interrupt the current speech generation.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error If this speech handle does not allow interruptions.
|
|
30
|
+
*
|
|
31
|
+
* @returns The same speech handle that was interrupted.
|
|
32
|
+
*/
|
|
33
|
+
interrupt(): SpeechHandle;
|
|
34
|
+
then(callback: (sh: SpeechHandle) => void): Promise<void>;
|
|
35
|
+
waitForPlayout(): Promise<void>;
|
|
36
|
+
waitIfNotInterrupted(aw: Promise<unknown>[]): Promise<void>;
|
|
37
|
+
/** @internal */
|
|
38
|
+
_setChatMessage(chatMessage: ChatMessage): void;
|
|
39
|
+
/** @internal */
|
|
40
|
+
_authorizePlayout(): void;
|
|
41
|
+
/** @internal */
|
|
42
|
+
_waitForAuthorization(): Promise<void>;
|
|
43
|
+
/** @internal */
|
|
44
|
+
_markPlayoutDone(): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=speech_handle.d.ts.map
|