@livekit/agents 0.7.9 → 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_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 -3
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -2
- 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 +97 -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 +98 -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 +100 -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 +101 -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 +156 -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 +156 -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 +298 -27
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +145 -9
- package/dist/utils.d.ts +145 -9
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +281 -26
- package/dist/utils.js.map +1 -1
- package/dist/utils.test.cjs +491 -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 +374 -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 +350 -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 +379 -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 +354 -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 +8 -2
- package/src/_exceptions.ts +137 -0
- package/src/audio.ts +12 -1
- package/src/cli.ts +37 -0
- package/src/constants.ts +2 -1
- 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 +148 -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 +134 -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 +202 -21
- package/src/types.ts +42 -0
- package/src/utils.test.ts +658 -0
- package/src/utils.ts +402 -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 +473 -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 +477 -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 -486
- 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 -461
- 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 -859
- 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 -837
- 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 -592
- 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 -1197
- package/src/pipeline/speech_handle.ts +0 -201
|
@@ -1,859 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var pipeline_agent_exports = {};
|
|
30
|
-
__export(pipeline_agent_exports, {
|
|
31
|
-
AGENT_STATE_ATTRIBUTE: () => AGENT_STATE_ATTRIBUTE,
|
|
32
|
-
AgentCallContext: () => AgentCallContext,
|
|
33
|
-
VPAEvent: () => VPAEvent,
|
|
34
|
-
VoicePipelineAgent: () => VoicePipelineAgent
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(pipeline_agent_exports);
|
|
37
|
-
var import_rtc_node = require("@livekit/rtc-node");
|
|
38
|
-
var import_node_crypto = require("node:crypto");
|
|
39
|
-
var import_node_events = __toESM(require("node:events"), 1);
|
|
40
|
-
var import_constants = require("../constants.cjs");
|
|
41
|
-
var import_llm = require("../llm/index.cjs");
|
|
42
|
-
var import_log = require("../log.cjs");
|
|
43
|
-
var import_stt = require("../stt/index.cjs");
|
|
44
|
-
var import_basic = require("../tokenize/basic/index.cjs");
|
|
45
|
-
var import_transcription = require("../transcription.cjs");
|
|
46
|
-
var import_tts = require("../tts/index.cjs");
|
|
47
|
-
var import_utils = require("../utils.cjs");
|
|
48
|
-
var import_vad = require("../vad.cjs");
|
|
49
|
-
var import_agent_output = require("./agent_output.cjs");
|
|
50
|
-
var import_agent_playout = require("./agent_playout.cjs");
|
|
51
|
-
var import_human_input = require("./human_input.cjs");
|
|
52
|
-
var import_speech_handle = require("./speech_handle.cjs");
|
|
53
|
-
const AGENT_STATE_ATTRIBUTE = "lk.agent.state";
|
|
54
|
-
let lastSpeechData;
|
|
55
|
-
let speechData;
|
|
56
|
-
var VPAEvent = /* @__PURE__ */ ((VPAEvent2) => {
|
|
57
|
-
VPAEvent2[VPAEvent2["USER_STARTED_SPEAKING"] = 0] = "USER_STARTED_SPEAKING";
|
|
58
|
-
VPAEvent2[VPAEvent2["USER_STOPPED_SPEAKING"] = 1] = "USER_STOPPED_SPEAKING";
|
|
59
|
-
VPAEvent2[VPAEvent2["AGENT_STARTED_SPEAKING"] = 2] = "AGENT_STARTED_SPEAKING";
|
|
60
|
-
VPAEvent2[VPAEvent2["AGENT_STOPPED_SPEAKING"] = 3] = "AGENT_STOPPED_SPEAKING";
|
|
61
|
-
VPAEvent2[VPAEvent2["USER_SPEECH_COMMITTED"] = 4] = "USER_SPEECH_COMMITTED";
|
|
62
|
-
VPAEvent2[VPAEvent2["AGENT_SPEECH_COMMITTED"] = 5] = "AGENT_SPEECH_COMMITTED";
|
|
63
|
-
VPAEvent2[VPAEvent2["AGENT_SPEECH_INTERRUPTED"] = 6] = "AGENT_SPEECH_INTERRUPTED";
|
|
64
|
-
VPAEvent2[VPAEvent2["FUNCTION_CALLS_COLLECTED"] = 7] = "FUNCTION_CALLS_COLLECTED";
|
|
65
|
-
VPAEvent2[VPAEvent2["FUNCTION_CALLS_FINISHED"] = 8] = "FUNCTION_CALLS_FINISHED";
|
|
66
|
-
VPAEvent2[VPAEvent2["METRICS_COLLECTED"] = 9] = "METRICS_COLLECTED";
|
|
67
|
-
return VPAEvent2;
|
|
68
|
-
})(VPAEvent || {});
|
|
69
|
-
class AgentCallContext {
|
|
70
|
-
#agent;
|
|
71
|
-
#llmStream;
|
|
72
|
-
#metadata = /* @__PURE__ */ new Map();
|
|
73
|
-
#extraChatMessages = [];
|
|
74
|
-
static #current;
|
|
75
|
-
constructor(agent, llmStream) {
|
|
76
|
-
this.#agent = agent;
|
|
77
|
-
this.#llmStream = llmStream;
|
|
78
|
-
AgentCallContext.#current = this;
|
|
79
|
-
}
|
|
80
|
-
static getCurrent() {
|
|
81
|
-
return AgentCallContext.#current;
|
|
82
|
-
}
|
|
83
|
-
get agent() {
|
|
84
|
-
return this.#agent;
|
|
85
|
-
}
|
|
86
|
-
storeMetadata(key, value) {
|
|
87
|
-
this.#metadata.set(key, value);
|
|
88
|
-
}
|
|
89
|
-
getMetadata(key, orDefault = void 0) {
|
|
90
|
-
return this.#metadata.get(key) || orDefault;
|
|
91
|
-
}
|
|
92
|
-
get llmStream() {
|
|
93
|
-
return this.#llmStream;
|
|
94
|
-
}
|
|
95
|
-
get extraChatMessages() {
|
|
96
|
-
return this.#extraChatMessages;
|
|
97
|
-
}
|
|
98
|
-
addExtraChatMessage(message) {
|
|
99
|
-
this.#extraChatMessages.push(message);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const defaultBeforeLLMCallback = (agent, chatCtx) => {
|
|
103
|
-
return agent.llm.chat({ chatCtx, fncCtx: agent.fncCtx });
|
|
104
|
-
};
|
|
105
|
-
const defaultBeforeTTSCallback = (_, text) => {
|
|
106
|
-
return text;
|
|
107
|
-
};
|
|
108
|
-
const defaultAgentTranscriptionOptions = {
|
|
109
|
-
userTranscription: true,
|
|
110
|
-
agentTranscription: true,
|
|
111
|
-
agentTranscriptionSpeech: 1,
|
|
112
|
-
sentenceTokenizer: new import_basic.SentenceTokenizer(),
|
|
113
|
-
wordTokenizer: new import_basic.WordTokenizer(false),
|
|
114
|
-
hyphenateWord: import_basic.hyphenateWord
|
|
115
|
-
};
|
|
116
|
-
const defaultVPAOptions = {
|
|
117
|
-
chatCtx: new import_llm.ChatContext(),
|
|
118
|
-
allowInterruptions: true,
|
|
119
|
-
interruptSpeechDuration: 50,
|
|
120
|
-
interruptMinWords: 0,
|
|
121
|
-
minEndpointingDelay: 500,
|
|
122
|
-
maxNestedFncCalls: 1,
|
|
123
|
-
preemptiveSynthesis: false,
|
|
124
|
-
beforeLLMCallback: defaultBeforeLLMCallback,
|
|
125
|
-
beforeTTSCallback: defaultBeforeTTSCallback,
|
|
126
|
-
transcription: defaultAgentTranscriptionOptions
|
|
127
|
-
};
|
|
128
|
-
class VoicePipelineAgent extends import_node_events.default {
|
|
129
|
-
/** Minimum time played for the user speech to be committed to the chat context. */
|
|
130
|
-
MIN_TIME_PLAYED_FOR_COMMIT = 1.5;
|
|
131
|
-
static FLUSH_SENTINEL = Symbol("FLUSH_SENTINEL");
|
|
132
|
-
#vad;
|
|
133
|
-
#stt;
|
|
134
|
-
#llm;
|
|
135
|
-
#tts;
|
|
136
|
-
#opts;
|
|
137
|
-
#humanInput;
|
|
138
|
-
#agentOutput;
|
|
139
|
-
#trackPublishedFut = new import_utils.Future();
|
|
140
|
-
#pendingAgentReply;
|
|
141
|
-
#agentReplyTask;
|
|
142
|
-
#playingSpeech;
|
|
143
|
-
transcribedText = "";
|
|
144
|
-
#transcribedInterimText = "";
|
|
145
|
-
#speechQueueOpen = new import_utils.Future();
|
|
146
|
-
#speechQueue = new import_utils.AsyncIterableQueue();
|
|
147
|
-
#updateStateTask;
|
|
148
|
-
#started = false;
|
|
149
|
-
#room;
|
|
150
|
-
#participant = null;
|
|
151
|
-
#deferredValidation;
|
|
152
|
-
#logger = (0, import_log.log)();
|
|
153
|
-
#agentPublication;
|
|
154
|
-
#lastFinalTranscriptTime;
|
|
155
|
-
#lastSpeechTime;
|
|
156
|
-
#transcriptionId;
|
|
157
|
-
#agentTranscribedText = "";
|
|
158
|
-
constructor(vad, stt, llm, tts, opts = defaultVPAOptions) {
|
|
159
|
-
super();
|
|
160
|
-
this.#opts = { ...defaultVPAOptions, ...opts };
|
|
161
|
-
if (!stt.capabilities.streaming) {
|
|
162
|
-
stt = new import_stt.StreamAdapter(stt, vad);
|
|
163
|
-
}
|
|
164
|
-
if (!tts.capabilities.streaming) {
|
|
165
|
-
tts = new import_tts.StreamAdapter(tts, new import_basic.SentenceTokenizer());
|
|
166
|
-
}
|
|
167
|
-
this.#vad = vad;
|
|
168
|
-
this.#stt = stt;
|
|
169
|
-
this.#llm = llm;
|
|
170
|
-
this.#tts = tts;
|
|
171
|
-
this.#deferredValidation = new DeferredReplyValidation(
|
|
172
|
-
this.#validateReplyIfPossible.bind(this),
|
|
173
|
-
this.#opts.minEndpointingDelay,
|
|
174
|
-
this,
|
|
175
|
-
this.#opts.turnDetector
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
get fncCtx() {
|
|
179
|
-
return this.#opts.fncCtx;
|
|
180
|
-
}
|
|
181
|
-
set fncCtx(ctx) {
|
|
182
|
-
this.#opts.fncCtx = ctx;
|
|
183
|
-
}
|
|
184
|
-
get chatCtx() {
|
|
185
|
-
return this.#opts.chatCtx;
|
|
186
|
-
}
|
|
187
|
-
get llm() {
|
|
188
|
-
return this.#llm;
|
|
189
|
-
}
|
|
190
|
-
get tts() {
|
|
191
|
-
return this.#tts;
|
|
192
|
-
}
|
|
193
|
-
get stt() {
|
|
194
|
-
return this.#stt;
|
|
195
|
-
}
|
|
196
|
-
get vad() {
|
|
197
|
-
return this.#vad;
|
|
198
|
-
}
|
|
199
|
-
/** Start the voice assistant. */
|
|
200
|
-
start(room, participant = null) {
|
|
201
|
-
if (this.#started) {
|
|
202
|
-
throw new Error("voice assistant already started");
|
|
203
|
-
}
|
|
204
|
-
this.#stt.on(import_stt.SpeechEventType.METRICS_COLLECTED, (metrics) => {
|
|
205
|
-
this.emit(9 /* METRICS_COLLECTED */, metrics);
|
|
206
|
-
});
|
|
207
|
-
this.#tts.on(import_tts.TTSEvent.METRICS_COLLECTED, (metrics) => {
|
|
208
|
-
if (!speechData) return;
|
|
209
|
-
this.emit(9 /* METRICS_COLLECTED */, { ...metrics, sequenceId: speechData.sequenceId });
|
|
210
|
-
});
|
|
211
|
-
this.#llm.on(import_llm.LLMEvent.METRICS_COLLECTED, (metrics) => {
|
|
212
|
-
const sequenceId = speechData ? speechData.sequenceId : lastSpeechData == null ? void 0 : lastSpeechData.sequenceId;
|
|
213
|
-
if (!sequenceId) return;
|
|
214
|
-
this.emit(9 /* METRICS_COLLECTED */, { ...metrics, sequenceId });
|
|
215
|
-
});
|
|
216
|
-
this.#vad.on(import_vad.VADEventType.METRICS_COLLECTED, (metrics) => {
|
|
217
|
-
this.emit(9 /* METRICS_COLLECTED */, metrics);
|
|
218
|
-
});
|
|
219
|
-
room.on(import_rtc_node.RoomEvent.ParticipantConnected, (participant2) => {
|
|
220
|
-
if (this.#participant) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
this.#linkParticipant.call(this, participant2.identity);
|
|
224
|
-
});
|
|
225
|
-
this.#room = room;
|
|
226
|
-
this.#participant = participant;
|
|
227
|
-
if (participant) {
|
|
228
|
-
if (typeof participant === "string") {
|
|
229
|
-
this.#linkParticipant(participant);
|
|
230
|
-
} else {
|
|
231
|
-
this.#linkParticipant(participant.identity);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
this.#run();
|
|
235
|
-
}
|
|
236
|
-
/** Play a speech source through the voice assistant. */
|
|
237
|
-
async say(source, allowInterruptions = true, addToChatCtx = true) {
|
|
238
|
-
await this.#trackPublishedFut.await;
|
|
239
|
-
let callContext;
|
|
240
|
-
let fncSource;
|
|
241
|
-
if (addToChatCtx) {
|
|
242
|
-
callContext = AgentCallContext.getCurrent();
|
|
243
|
-
if (source instanceof import_llm.LLMStream) {
|
|
244
|
-
this.#logger.warn("LLMStream will be ignored for function call chat context");
|
|
245
|
-
} else if (typeof source === "string") {
|
|
246
|
-
fncSource = source;
|
|
247
|
-
} else {
|
|
248
|
-
fncSource = source;
|
|
249
|
-
source = new import_utils.AsyncIterableQueue();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
const newHandle = import_speech_handle.SpeechHandle.createAssistantSpeech(allowInterruptions, addToChatCtx);
|
|
253
|
-
const synthesisHandle = this.#synthesizeAgentSpeech(newHandle.id, source);
|
|
254
|
-
newHandle.initialize(source, synthesisHandle);
|
|
255
|
-
if (this.#playingSpeech && !this.#playingSpeech.nestedSpeechFinished) {
|
|
256
|
-
this.#playingSpeech.addNestedSpeech(newHandle);
|
|
257
|
-
} else {
|
|
258
|
-
this.#addSpeechForPlayout(newHandle);
|
|
259
|
-
}
|
|
260
|
-
if (callContext && fncSource) {
|
|
261
|
-
let text;
|
|
262
|
-
if (typeof source === "string") {
|
|
263
|
-
text = fncSource;
|
|
264
|
-
} else {
|
|
265
|
-
text = "";
|
|
266
|
-
for await (const chunk of fncSource) {
|
|
267
|
-
source.put(chunk);
|
|
268
|
-
text += chunk;
|
|
269
|
-
}
|
|
270
|
-
source.close();
|
|
271
|
-
}
|
|
272
|
-
callContext.addExtraChatMessage(import_llm.ChatMessage.create({ text, role: import_llm.ChatRole.ASSISTANT }));
|
|
273
|
-
this.#logger.child({ text }).debug("added speech to function call chat context");
|
|
274
|
-
}
|
|
275
|
-
return newHandle;
|
|
276
|
-
}
|
|
277
|
-
#updateState(state, delay = 0) {
|
|
278
|
-
const runTask = (delay2) => {
|
|
279
|
-
return new import_utils.CancellablePromise(async (resolve, _, onCancel) => {
|
|
280
|
-
var _a, _b;
|
|
281
|
-
let cancelled = false;
|
|
282
|
-
onCancel(() => {
|
|
283
|
-
cancelled = true;
|
|
284
|
-
});
|
|
285
|
-
await new Promise((resolve2) => setTimeout(resolve2, delay2));
|
|
286
|
-
if ((_a = this.#room) == null ? void 0 : _a.isConnected) {
|
|
287
|
-
if (!cancelled) {
|
|
288
|
-
await ((_b = this.#room.localParticipant) == null ? void 0 : _b.setAttributes({ [AGENT_STATE_ATTRIBUTE]: state }));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
resolve();
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
if (this.#updateStateTask) {
|
|
295
|
-
this.#updateStateTask.cancel();
|
|
296
|
-
}
|
|
297
|
-
this.#updateStateTask = runTask(delay);
|
|
298
|
-
}
|
|
299
|
-
#linkParticipant(participantIdentity) {
|
|
300
|
-
if (!this.#room) {
|
|
301
|
-
this.#logger.error("Room is not set");
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
this.#participant = this.#room.remoteParticipants.get(participantIdentity) || null;
|
|
305
|
-
if (!this.#participant) {
|
|
306
|
-
this.#logger.error(`Participant with identity ${participantIdentity} not found`);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
this.#humanInput = new import_human_input.HumanInput(
|
|
310
|
-
this.#room,
|
|
311
|
-
this.#vad,
|
|
312
|
-
this.#stt,
|
|
313
|
-
this.#participant,
|
|
314
|
-
this.#opts.noiseCancellation
|
|
315
|
-
);
|
|
316
|
-
this.#humanInput.on(import_human_input.HumanInputEvent.START_OF_SPEECH, (event) => {
|
|
317
|
-
this.emit(0 /* USER_STARTED_SPEAKING */);
|
|
318
|
-
this.#deferredValidation.onHumanStartOfSpeech(event);
|
|
319
|
-
});
|
|
320
|
-
this.#humanInput.on(import_human_input.HumanInputEvent.VAD_INFERENCE_DONE, (event) => {
|
|
321
|
-
if (!this.#trackPublishedFut.done) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
if (!this.#agentOutput) {
|
|
325
|
-
throw new Error("agent output is undefined");
|
|
326
|
-
}
|
|
327
|
-
let tv = 1;
|
|
328
|
-
if (this.#opts.allowInterruptions) {
|
|
329
|
-
tv = Math.max(0, 1 - event.probability);
|
|
330
|
-
this.#agentOutput.playout.targetVolume = tv;
|
|
331
|
-
}
|
|
332
|
-
if (event.speechDuration >= this.#opts.interruptSpeechDuration) {
|
|
333
|
-
this.#interruptIfPossible();
|
|
334
|
-
}
|
|
335
|
-
if (event.rawAccumulatedSpeech > 0) {
|
|
336
|
-
this.#lastSpeechTime = Date.now() - event.rawAccumulatedSilence;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
this.#humanInput.on(import_human_input.HumanInputEvent.END_OF_SPEECH, (event) => {
|
|
340
|
-
this.emit(1 /* USER_STOPPED_SPEAKING */);
|
|
341
|
-
this.#deferredValidation.onHumanEndOfSpeech(event);
|
|
342
|
-
});
|
|
343
|
-
this.#humanInput.on(import_human_input.HumanInputEvent.INTERIM_TRANSCRIPT, async (event) => {
|
|
344
|
-
if (!this.#transcriptionId) {
|
|
345
|
-
this.#transcriptionId = (0, import_node_crypto.randomUUID)();
|
|
346
|
-
}
|
|
347
|
-
this.#transcribedInterimText = event.alternatives[0].text;
|
|
348
|
-
await this.#publishTranscription(
|
|
349
|
-
this.#humanInput.participant.identity,
|
|
350
|
-
this.#humanInput.subscribedTrack.sid,
|
|
351
|
-
this.#transcribedInterimText,
|
|
352
|
-
false,
|
|
353
|
-
this.#transcriptionId,
|
|
354
|
-
this.#transcriptionId
|
|
355
|
-
);
|
|
356
|
-
});
|
|
357
|
-
this.#humanInput.on(import_human_input.HumanInputEvent.FINAL_TRANSCRIPT, async (event) => {
|
|
358
|
-
const newTranscript = event.alternatives[0].text;
|
|
359
|
-
if (!newTranscript) return;
|
|
360
|
-
if (!this.#transcriptionId) {
|
|
361
|
-
this.#transcriptionId = (0, import_node_crypto.randomUUID)();
|
|
362
|
-
}
|
|
363
|
-
this.#lastFinalTranscriptTime = Date.now();
|
|
364
|
-
this.transcribedText += (this.transcribedText ? " " : "") + newTranscript;
|
|
365
|
-
await this.#publishTranscription(
|
|
366
|
-
this.#humanInput.participant.identity,
|
|
367
|
-
this.#humanInput.subscribedTrack.sid,
|
|
368
|
-
this.transcribedText,
|
|
369
|
-
true,
|
|
370
|
-
this.#transcriptionId,
|
|
371
|
-
this.#transcriptionId
|
|
372
|
-
);
|
|
373
|
-
this.#transcriptionId = void 0;
|
|
374
|
-
if (this.#opts.preemptiveSynthesis && (!this.#playingSpeech || this.#playingSpeech.allowInterruptions)) {
|
|
375
|
-
this.#synthesizeAgentReply();
|
|
376
|
-
}
|
|
377
|
-
this.#deferredValidation.onHumanFinalTranscript(newTranscript);
|
|
378
|
-
const words = this.#opts.transcription.wordTokenizer.tokenize(newTranscript);
|
|
379
|
-
if (words.length >= 3) {
|
|
380
|
-
this.#interruptIfPossible();
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
async #run() {
|
|
385
|
-
var _a, _b;
|
|
386
|
-
this.#updateState("initializing");
|
|
387
|
-
const audioSource = new import_rtc_node.AudioSource(this.#tts.sampleRate, this.#tts.numChannels);
|
|
388
|
-
const track = import_rtc_node.LocalAudioTrack.createAudioTrack("assistant_voice", audioSource);
|
|
389
|
-
this.#agentPublication = await ((_b = (_a = this.#room) == null ? void 0 : _a.localParticipant) == null ? void 0 : _b.publishTrack(
|
|
390
|
-
track,
|
|
391
|
-
new import_rtc_node.TrackPublishOptions({ source: import_rtc_node.TrackSource.SOURCE_MICROPHONE })
|
|
392
|
-
));
|
|
393
|
-
const agentPlayout = new import_agent_playout.AgentPlayout(audioSource);
|
|
394
|
-
this.#agentOutput = new import_agent_output.AgentOutput(agentPlayout, this.#tts);
|
|
395
|
-
agentPlayout.on(import_agent_playout.AgentPlayoutEvent.PLAYOUT_STARTED, () => {
|
|
396
|
-
this.emit(2 /* AGENT_STARTED_SPEAKING */);
|
|
397
|
-
this.#updateState("speaking");
|
|
398
|
-
});
|
|
399
|
-
agentPlayout.on(import_agent_playout.AgentPlayoutEvent.PLAYOUT_STOPPED, (_) => {
|
|
400
|
-
this.emit(3 /* AGENT_STOPPED_SPEAKING */);
|
|
401
|
-
this.#updateState("listening");
|
|
402
|
-
});
|
|
403
|
-
this.#trackPublishedFut.resolve();
|
|
404
|
-
while (true) {
|
|
405
|
-
await this.#speechQueueOpen.await;
|
|
406
|
-
for await (const speech of this.#speechQueue) {
|
|
407
|
-
if (speech === VoicePipelineAgent.FLUSH_SENTINEL) break;
|
|
408
|
-
this.#playingSpeech = speech;
|
|
409
|
-
await this.#playSpeech(speech);
|
|
410
|
-
this.#playingSpeech = void 0;
|
|
411
|
-
}
|
|
412
|
-
this.#speechQueueOpen = new import_utils.Future();
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
#synthesizeAgentReply() {
|
|
416
|
-
var _a;
|
|
417
|
-
(_a = this.#pendingAgentReply) == null ? void 0 : _a.cancel();
|
|
418
|
-
if (this.#humanInput && this.#humanInput.speaking) {
|
|
419
|
-
this.#updateState("thinking", 200);
|
|
420
|
-
}
|
|
421
|
-
this.#pendingAgentReply = import_speech_handle.SpeechHandle.createAssistantReply(
|
|
422
|
-
this.#opts.allowInterruptions,
|
|
423
|
-
true,
|
|
424
|
-
this.transcribedText
|
|
425
|
-
);
|
|
426
|
-
const newHandle = this.#pendingAgentReply;
|
|
427
|
-
this.#agentReplyTask = this.#synthesizeAnswerTask(this.#agentReplyTask, newHandle);
|
|
428
|
-
}
|
|
429
|
-
#synthesizeAnswerTask(oldTask, handle) {
|
|
430
|
-
return new import_utils.CancellablePromise(async (resolve, _, onCancel) => {
|
|
431
|
-
let cancelled = false;
|
|
432
|
-
onCancel(() => {
|
|
433
|
-
cancelled = true;
|
|
434
|
-
});
|
|
435
|
-
if (oldTask) {
|
|
436
|
-
await (0, import_utils.gracefullyCancel)(oldTask);
|
|
437
|
-
}
|
|
438
|
-
const copiedCtx = this.chatCtx.copy();
|
|
439
|
-
const playingSpeech = this.#playingSpeech;
|
|
440
|
-
if (playingSpeech && playingSpeech.initialized) {
|
|
441
|
-
if ((!playingSpeech.userQuestion || playingSpeech.userCommitted) && !playingSpeech.speechCommitted) {
|
|
442
|
-
copiedCtx.messages.push(
|
|
443
|
-
import_llm.ChatMessage.create({
|
|
444
|
-
text: playingSpeech.synthesisHandle.text,
|
|
445
|
-
role: import_llm.ChatRole.ASSISTANT
|
|
446
|
-
})
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
copiedCtx.messages.push(
|
|
451
|
-
import_llm.ChatMessage.create({
|
|
452
|
-
text: handle == null ? void 0 : handle.userQuestion,
|
|
453
|
-
role: import_llm.ChatRole.USER
|
|
454
|
-
})
|
|
455
|
-
);
|
|
456
|
-
speechData = { sequenceId: handle.id };
|
|
457
|
-
try {
|
|
458
|
-
if (cancelled) resolve();
|
|
459
|
-
let llmStream = await this.#opts.beforeLLMCallback(this, copiedCtx);
|
|
460
|
-
if (llmStream === false) {
|
|
461
|
-
handle == null ? void 0 : handle.cancel();
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
if (cancelled) resolve();
|
|
465
|
-
if (!(llmStream instanceof import_llm.LLMStream)) {
|
|
466
|
-
llmStream = await defaultBeforeLLMCallback(this, copiedCtx);
|
|
467
|
-
}
|
|
468
|
-
if (handle.interrupted) {
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
const synthesisHandle = this.#synthesizeAgentSpeech(handle.id, llmStream);
|
|
472
|
-
handle.initialize(llmStream, synthesisHandle);
|
|
473
|
-
} finally {
|
|
474
|
-
lastSpeechData = speechData;
|
|
475
|
-
speechData = void 0;
|
|
476
|
-
}
|
|
477
|
-
resolve();
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
async #playSpeech(handle) {
|
|
481
|
-
try {
|
|
482
|
-
await handle.waitForInitialization();
|
|
483
|
-
} catch {
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
await this.#agentPublication.waitForSubscription();
|
|
487
|
-
const synthesisHandle = handle.synthesisHandle;
|
|
488
|
-
if (synthesisHandle.interrupted) return;
|
|
489
|
-
const userQuestion = handle.userQuestion;
|
|
490
|
-
const playHandle = synthesisHandle.play();
|
|
491
|
-
const joinFut = playHandle.join();
|
|
492
|
-
const commitUserQuestionIfNeeded = () => {
|
|
493
|
-
if (!userQuestion || synthesisHandle.interrupted || handle.userCommitted) return;
|
|
494
|
-
const isUsingTools2 = handle.source instanceof import_llm.LLMStream && !!handle.source.functionCalls.length;
|
|
495
|
-
if (handle.allowInterruptions && !isUsingTools2 && playHandle.timePlayed < this.MIN_TIME_PLAYED_FOR_COMMIT && !joinFut.done) {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
this.#logger.child({ userTranscript: userQuestion }).debug("committed user transcript");
|
|
499
|
-
const userMsg = import_llm.ChatMessage.create({ text: userQuestion, role: import_llm.ChatRole.USER });
|
|
500
|
-
this.chatCtx.messages.push(userMsg);
|
|
501
|
-
this.emit(4 /* USER_SPEECH_COMMITTED */, userMsg);
|
|
502
|
-
this.transcribedText = this.transcribedText.slice(userQuestion.length);
|
|
503
|
-
handle.markUserCommitted();
|
|
504
|
-
};
|
|
505
|
-
commitUserQuestionIfNeeded();
|
|
506
|
-
while (!joinFut.done) {
|
|
507
|
-
await new Promise(async (resolve) => {
|
|
508
|
-
setTimeout(resolve, 500);
|
|
509
|
-
await joinFut.await;
|
|
510
|
-
resolve();
|
|
511
|
-
});
|
|
512
|
-
commitUserQuestionIfNeeded();
|
|
513
|
-
if (handle.interrupted) break;
|
|
514
|
-
}
|
|
515
|
-
commitUserQuestionIfNeeded();
|
|
516
|
-
let collectedText = this.#agentTranscribedText;
|
|
517
|
-
const isUsingTools = handle.source instanceof import_llm.LLMStream && !!handle.source.functionCalls.length;
|
|
518
|
-
const interrupted = handle.interrupted;
|
|
519
|
-
if (handle.addToChatCtx && (!userQuestion || handle.userCommitted)) {
|
|
520
|
-
if (handle.extraToolsMessages) {
|
|
521
|
-
this.chatCtx.messages.push(...handle.extraToolsMessages);
|
|
522
|
-
}
|
|
523
|
-
if (interrupted) {
|
|
524
|
-
collectedText += "\u2026";
|
|
525
|
-
}
|
|
526
|
-
const msg = import_llm.ChatMessage.create({ text: collectedText, role: import_llm.ChatRole.ASSISTANT });
|
|
527
|
-
this.chatCtx.messages.push(msg);
|
|
528
|
-
handle.markSpeechCommitted();
|
|
529
|
-
if (interrupted) {
|
|
530
|
-
this.emit(6 /* AGENT_SPEECH_INTERRUPTED */, msg);
|
|
531
|
-
} else {
|
|
532
|
-
this.emit(5 /* AGENT_SPEECH_COMMITTED */, msg);
|
|
533
|
-
}
|
|
534
|
-
this.#logger.child({
|
|
535
|
-
agentTranscript: collectedText,
|
|
536
|
-
interrupted,
|
|
537
|
-
speechId: handle.id
|
|
538
|
-
}).debug("committed agent speech");
|
|
539
|
-
handle.setDone();
|
|
540
|
-
}
|
|
541
|
-
const executeFunctionCalls = async () => {
|
|
542
|
-
if (!isUsingTools || interrupted) return;
|
|
543
|
-
if (handle.fncNestedDepth >= this.#opts.maxNestedFncCalls) {
|
|
544
|
-
this.#logger.child({ speechId: handle.id, fncNestedDepth: handle.fncNestedDepth }).warn("max function calls nested depth reached");
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
if (userQuestion && !handle.userCommitted) {
|
|
548
|
-
throw new Error("user speech should have been committed before using tools");
|
|
549
|
-
}
|
|
550
|
-
const llmStream = handle.source;
|
|
551
|
-
const newFunctionCalls = llmStream.functionCalls;
|
|
552
|
-
new AgentCallContext(this, llmStream);
|
|
553
|
-
this.emit(7 /* FUNCTION_CALLS_COLLECTED */, newFunctionCalls);
|
|
554
|
-
const calledFuncs = [];
|
|
555
|
-
for (const func of newFunctionCalls) {
|
|
556
|
-
const task2 = func.func.execute(func.params).then(
|
|
557
|
-
(result) => ({ name: func.name, toolCallId: func.toolCallId, result }),
|
|
558
|
-
(error) => ({ name: func.name, toolCallId: func.toolCallId, error })
|
|
559
|
-
);
|
|
560
|
-
calledFuncs.push({ ...func, task: task2 });
|
|
561
|
-
this.#logger.child({ function: func.name, speechId: handle.id }).debug("executing AI function");
|
|
562
|
-
try {
|
|
563
|
-
await task2;
|
|
564
|
-
} catch {
|
|
565
|
-
this.#logger.child({ function: func.name, speechId: handle.id }).error("error executing AI function");
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
const toolCallsInfo = [];
|
|
569
|
-
const toolCallsResults = [];
|
|
570
|
-
for (const fnc of calledFuncs) {
|
|
571
|
-
const task2 = await fnc.task;
|
|
572
|
-
if (!task2 || task2.result === void 0) continue;
|
|
573
|
-
toolCallsInfo.push(fnc);
|
|
574
|
-
toolCallsResults.push(import_llm.ChatMessage.createToolFromFunctionResult(task2));
|
|
575
|
-
}
|
|
576
|
-
if (!toolCallsInfo.length) return;
|
|
577
|
-
const extraToolsMessages = [import_llm.ChatMessage.createToolCalls(toolCallsInfo, collectedText)];
|
|
578
|
-
extraToolsMessages.push(...toolCallsResults);
|
|
579
|
-
const newSpeechHandle = import_speech_handle.SpeechHandle.createToolSpeech(
|
|
580
|
-
handle.allowInterruptions,
|
|
581
|
-
handle.addToChatCtx,
|
|
582
|
-
handle.fncNestedDepth + 1,
|
|
583
|
-
extraToolsMessages
|
|
584
|
-
);
|
|
585
|
-
const chatCtx = handle.source.chatCtx.copy();
|
|
586
|
-
chatCtx.messages.push(...extraToolsMessages);
|
|
587
|
-
chatCtx.messages.push(...AgentCallContext.getCurrent().extraChatMessages);
|
|
588
|
-
const answerLLMStream = this.llm.chat({
|
|
589
|
-
chatCtx,
|
|
590
|
-
fncCtx: this.fncCtx
|
|
591
|
-
});
|
|
592
|
-
const answerSynthesis = this.#synthesizeAgentSpeech(newSpeechHandle.id, answerLLMStream);
|
|
593
|
-
newSpeechHandle.initialize(answerLLMStream, answerSynthesis);
|
|
594
|
-
handle.addNestedSpeech(newSpeechHandle);
|
|
595
|
-
this.emit(8 /* FUNCTION_CALLS_FINISHED */, calledFuncs);
|
|
596
|
-
};
|
|
597
|
-
let finished = false;
|
|
598
|
-
const task = executeFunctionCalls().then(() => {
|
|
599
|
-
finished = true;
|
|
600
|
-
});
|
|
601
|
-
while (!handle.nestedSpeechFinished) {
|
|
602
|
-
const changed = handle.nestedSpeechChanged();
|
|
603
|
-
await Promise.race([changed, task]);
|
|
604
|
-
while (handle.nestedSpeechHandles.length) {
|
|
605
|
-
const speech = handle.nestedSpeechHandles[0];
|
|
606
|
-
this.#playingSpeech = speech;
|
|
607
|
-
await this.#playSpeech(speech);
|
|
608
|
-
handle.nestedSpeechHandles.shift();
|
|
609
|
-
this.#playingSpeech = handle;
|
|
610
|
-
}
|
|
611
|
-
handle.nestedSpeechHandles.forEach(() => handle.nestedSpeechHandles.pop());
|
|
612
|
-
if (finished) {
|
|
613
|
-
handle.markNestedSpeechFinished();
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
handle.setDone();
|
|
617
|
-
}
|
|
618
|
-
async #publishTranscription(participantIdentity, trackSid, text, isFinal, id, segmentId) {
|
|
619
|
-
this.#room.localParticipant.publishTranscription({
|
|
620
|
-
participantIdentity,
|
|
621
|
-
trackSid,
|
|
622
|
-
segments: [
|
|
623
|
-
{
|
|
624
|
-
text,
|
|
625
|
-
final: isFinal,
|
|
626
|
-
id,
|
|
627
|
-
startTime: BigInt(0),
|
|
628
|
-
endTime: BigInt(0),
|
|
629
|
-
language: ""
|
|
630
|
-
}
|
|
631
|
-
]
|
|
632
|
-
});
|
|
633
|
-
const stream = await this.#room.localParticipant.streamText({
|
|
634
|
-
senderIdentity: participantIdentity,
|
|
635
|
-
topic: import_constants.TOPIC_TRANSCRIPTION,
|
|
636
|
-
attributes: {
|
|
637
|
-
[import_constants.ATTRIBUTE_TRANSCRIPTION_TRACK_ID]: trackSid,
|
|
638
|
-
[import_constants.ATTRIBUTE_TRANSCRIPTION_FINAL]: isFinal.toString(),
|
|
639
|
-
[import_constants.ATTRIBUTE_SEGMENT_ID]: segmentId
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
await stream.write(text);
|
|
643
|
-
await stream.close();
|
|
644
|
-
}
|
|
645
|
-
#synthesizeAgentSpeech(speechId, source) {
|
|
646
|
-
const synchronizer = new import_transcription.TextAudioSynchronizer(import_transcription.defaultTextSyncOptions);
|
|
647
|
-
synchronizer.on("textUpdated", async (text) => {
|
|
648
|
-
var _a;
|
|
649
|
-
this.#agentTranscribedText = text.text;
|
|
650
|
-
if (!this.#transcriptionId) {
|
|
651
|
-
this.#transcriptionId = (0, import_node_crypto.randomUUID)();
|
|
652
|
-
}
|
|
653
|
-
await this.#publishTranscription(
|
|
654
|
-
this.#room.localParticipant.identity,
|
|
655
|
-
((_a = this.#agentPublication) == null ? void 0 : _a.sid) ?? "",
|
|
656
|
-
text.text,
|
|
657
|
-
text.final,
|
|
658
|
-
text.id,
|
|
659
|
-
this.#transcriptionId
|
|
660
|
-
);
|
|
661
|
-
if (text.final) {
|
|
662
|
-
this.#transcriptionId = void 0;
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
if (!this.#agentOutput) {
|
|
666
|
-
throw new Error("agent output should be initialized when ready");
|
|
667
|
-
}
|
|
668
|
-
if (source instanceof import_llm.LLMStream) {
|
|
669
|
-
source = llmStreamToStringIterable(speechId, source);
|
|
670
|
-
}
|
|
671
|
-
const ogSource = source;
|
|
672
|
-
if (!(typeof source === "string")) {
|
|
673
|
-
}
|
|
674
|
-
const ttsSource = this.#opts.beforeTTSCallback(this, ogSource);
|
|
675
|
-
if (!ttsSource) {
|
|
676
|
-
throw new Error("beforeTTSCallback must return string or AsyncIterable<string>");
|
|
677
|
-
}
|
|
678
|
-
return this.#agentOutput.synthesize(speechId, ttsSource, synchronizer);
|
|
679
|
-
}
|
|
680
|
-
async #validateReplyIfPossible() {
|
|
681
|
-
if (this.#playingSpeech && !this.#playingSpeech.allowInterruptions) {
|
|
682
|
-
this.#logger.child({ speechId: this.#playingSpeech.id }).debug("skipping validation, agent is speaking and does not allow interruptions");
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
if (!this.#pendingAgentReply) {
|
|
686
|
-
if (this.#opts.preemptiveSynthesis || !this.transcribedText) {
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
this.#synthesizeAgentReply();
|
|
690
|
-
}
|
|
691
|
-
if (!this.#pendingAgentReply) {
|
|
692
|
-
throw new Error("pending agent reply is undefined");
|
|
693
|
-
}
|
|
694
|
-
if (this.#speechQueueOpen.done) {
|
|
695
|
-
for await (const speech of this.#speechQueue) {
|
|
696
|
-
if (speech === VoicePipelineAgent.FLUSH_SENTINEL) break;
|
|
697
|
-
if (!speech.isReply) continue;
|
|
698
|
-
if (speech.allowInterruptions) speech.interrupt();
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
this.#logger.child({ speechId: this.#pendingAgentReply.id }).debug("validated agent reply");
|
|
702
|
-
if (this.#lastSpeechTime) {
|
|
703
|
-
const timeSinceLastSpeech = Date.now() - this.#lastSpeechTime;
|
|
704
|
-
const transcriptionDelay = Math.max(
|
|
705
|
-
(this.#lastFinalTranscriptTime || 0) - this.#lastSpeechTime,
|
|
706
|
-
0
|
|
707
|
-
);
|
|
708
|
-
const metrics = {
|
|
709
|
-
timestamp: Date.now(),
|
|
710
|
-
sequenceId: this.#pendingAgentReply.id,
|
|
711
|
-
endOfUtteranceDelay: timeSinceLastSpeech,
|
|
712
|
-
transcriptionDelay
|
|
713
|
-
};
|
|
714
|
-
this.emit(9 /* METRICS_COLLECTED */, metrics);
|
|
715
|
-
}
|
|
716
|
-
this.#addSpeechForPlayout(this.#pendingAgentReply);
|
|
717
|
-
this.#pendingAgentReply = void 0;
|
|
718
|
-
this.#transcribedInterimText = "";
|
|
719
|
-
}
|
|
720
|
-
#interruptIfPossible() {
|
|
721
|
-
if (!this.#playingSpeech || !this.#playingSpeech.allowInterruptions || this.#playingSpeech.interrupted) {
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
if (this.#opts.interruptMinWords !== 0) {
|
|
725
|
-
const interimWords = this.#opts.transcription.wordTokenizer.tokenize(
|
|
726
|
-
this.#transcribedInterimText
|
|
727
|
-
);
|
|
728
|
-
if (interimWords.length < this.#opts.interruptMinWords) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
this.#playingSpeech.interrupt();
|
|
733
|
-
}
|
|
734
|
-
#addSpeechForPlayout(handle) {
|
|
735
|
-
this.#speechQueue.put(handle);
|
|
736
|
-
this.#speechQueue.put(VoicePipelineAgent.FLUSH_SENTINEL);
|
|
737
|
-
this.#speechQueueOpen.resolve();
|
|
738
|
-
}
|
|
739
|
-
/** Close the voice assistant. */
|
|
740
|
-
async close() {
|
|
741
|
-
var _a;
|
|
742
|
-
if (!this.#started) {
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
(_a = this.#room) == null ? void 0 : _a.removeAllListeners(import_rtc_node.RoomEvent.ParticipantConnected);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
async function* llmStreamToStringIterable(speechId, stream) {
|
|
749
|
-
var _a;
|
|
750
|
-
const startTime = Date.now();
|
|
751
|
-
let firstFrame = true;
|
|
752
|
-
for await (const chunk of stream) {
|
|
753
|
-
const content = (_a = chunk.choices[0]) == null ? void 0 : _a.delta.content;
|
|
754
|
-
if (!content) continue;
|
|
755
|
-
if (firstFrame) {
|
|
756
|
-
firstFrame = false;
|
|
757
|
-
(0, import_log.log)().child({ speechId, elapsed: Math.round(Date.now() - startTime) }).debug("received first LLM token");
|
|
758
|
-
}
|
|
759
|
-
yield content;
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
class DeferredReplyValidation {
|
|
763
|
-
// if the STT gives us punctuation, we can try to validate the reply faster.
|
|
764
|
-
PUNCTUATION = ".!?";
|
|
765
|
-
PUNCTUATION_REDUCE_FACTOR = 0.75;
|
|
766
|
-
LATE_TRANSCRIPT_TOLERANCE = 1.5;
|
|
767
|
-
// late compared to end of speech
|
|
768
|
-
UNLIKELY_ENDPOINT_DELAY = 6e3;
|
|
769
|
-
#validateFunc;
|
|
770
|
-
#validatingPromise;
|
|
771
|
-
#validatingFuture = new import_utils.Future();
|
|
772
|
-
#lastFinalTranscript = "";
|
|
773
|
-
#lastRecvEndOfSpeechTime = 0;
|
|
774
|
-
#speaking = false;
|
|
775
|
-
#endOfSpeechDelay;
|
|
776
|
-
#finalTranscriptDelay;
|
|
777
|
-
#turnDetector;
|
|
778
|
-
#agent;
|
|
779
|
-
#abort;
|
|
780
|
-
constructor(validateFunc, minEndpointingDelay, agent, turnDetector) {
|
|
781
|
-
this.#validateFunc = validateFunc;
|
|
782
|
-
this.#endOfSpeechDelay = minEndpointingDelay;
|
|
783
|
-
this.#finalTranscriptDelay = minEndpointingDelay;
|
|
784
|
-
this.#agent = agent;
|
|
785
|
-
this.#turnDetector = turnDetector;
|
|
786
|
-
}
|
|
787
|
-
get validating() {
|
|
788
|
-
return !this.#validatingFuture.done;
|
|
789
|
-
}
|
|
790
|
-
onHumanFinalTranscript(transcript) {
|
|
791
|
-
this.#lastFinalTranscript = transcript.trim();
|
|
792
|
-
if (this.#speaking) return;
|
|
793
|
-
const hasRecentEndOfSpeech = Date.now() - this.#lastRecvEndOfSpeechTime < this.LATE_TRANSCRIPT_TOLERANCE;
|
|
794
|
-
let delay = hasRecentEndOfSpeech ? this.#endOfSpeechDelay : this.#finalTranscriptDelay;
|
|
795
|
-
delay = this.#endWithPunctuation() ? delay * this.PUNCTUATION_REDUCE_FACTOR : 1;
|
|
796
|
-
this.#run(delay);
|
|
797
|
-
}
|
|
798
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
799
|
-
onHumanStartOfSpeech(_) {
|
|
800
|
-
var _a;
|
|
801
|
-
this.#speaking = true;
|
|
802
|
-
if (this.validating) {
|
|
803
|
-
(_a = this.#abort) == null ? void 0 : _a.abort();
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
807
|
-
onHumanEndOfSpeech(_) {
|
|
808
|
-
this.#speaking = false;
|
|
809
|
-
this.#lastRecvEndOfSpeechTime = Date.now();
|
|
810
|
-
if (this.#lastFinalTranscript) {
|
|
811
|
-
const delay = this.#endWithPunctuation() ? this.#endOfSpeechDelay * this.PUNCTUATION_REDUCE_FACTOR : 1e3;
|
|
812
|
-
this.#run(delay);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
// TODO(nbsp): aclose
|
|
816
|
-
#endWithPunctuation() {
|
|
817
|
-
return this.#lastFinalTranscript.length > 0 && this.PUNCTUATION.includes(this.#lastFinalTranscript[this.#lastFinalTranscript.length - 1]);
|
|
818
|
-
}
|
|
819
|
-
#resetStates() {
|
|
820
|
-
this.#lastFinalTranscript = "";
|
|
821
|
-
this.#lastRecvEndOfSpeechTime = 0;
|
|
822
|
-
}
|
|
823
|
-
#run(delay) {
|
|
824
|
-
var _a;
|
|
825
|
-
const runTask = async (delay2, chatCtx, signal) => {
|
|
826
|
-
if (this.#lastFinalTranscript && !this.#speaking && this.#turnDetector) {
|
|
827
|
-
const startTime = Date.now();
|
|
828
|
-
const eotProb = await this.#turnDetector.predictEndOfTurn(chatCtx);
|
|
829
|
-
const unlikelyThreshold = this.#turnDetector.unlikelyThreshold;
|
|
830
|
-
const elapsed = Date.now() - startTime;
|
|
831
|
-
if (eotProb < unlikelyThreshold) {
|
|
832
|
-
delay2 = this.UNLIKELY_ENDPOINT_DELAY;
|
|
833
|
-
}
|
|
834
|
-
delay2 = Math.max(0, delay2 - elapsed);
|
|
835
|
-
}
|
|
836
|
-
const timeout = setTimeout(() => {
|
|
837
|
-
this.#resetStates();
|
|
838
|
-
this.#validateFunc();
|
|
839
|
-
}, delay2);
|
|
840
|
-
signal.addEventListener("abort", () => {
|
|
841
|
-
clearTimeout(timeout);
|
|
842
|
-
});
|
|
843
|
-
};
|
|
844
|
-
(_a = this.#abort) == null ? void 0 : _a.abort();
|
|
845
|
-
this.#abort = new AbortController();
|
|
846
|
-
this.#validatingFuture = new import_utils.Future();
|
|
847
|
-
const detectCtx = this.#agent.chatCtx.copy();
|
|
848
|
-
detectCtx.append({ text: this.#agent.transcribedText, role: import_llm.ChatRole.USER });
|
|
849
|
-
this.#validatingPromise = runTask(delay, detectCtx, this.#abort.signal);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
853
|
-
0 && (module.exports = {
|
|
854
|
-
AGENT_STATE_ATTRIBUTE,
|
|
855
|
-
AgentCallContext,
|
|
856
|
-
VPAEvent,
|
|
857
|
-
VoicePipelineAgent
|
|
858
|
-
});
|
|
859
|
-
//# sourceMappingURL=pipeline_agent.cjs.map
|