@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,700 @@
|
|
|
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 generation_exports = {};
|
|
20
|
+
__export(generation_exports, {
|
|
21
|
+
ToolExecutionOutput: () => ToolExecutionOutput,
|
|
22
|
+
_JsOutput: () => _JsOutput,
|
|
23
|
+
_LLMGenerationData: () => _LLMGenerationData,
|
|
24
|
+
_SanitizedOutput: () => _SanitizedOutput,
|
|
25
|
+
_ToolOutput: () => _ToolOutput,
|
|
26
|
+
createToolOutput: () => createToolOutput,
|
|
27
|
+
performAudioForwarding: () => performAudioForwarding,
|
|
28
|
+
performLLMInference: () => performLLMInference,
|
|
29
|
+
performTTSInference: () => performTTSInference,
|
|
30
|
+
performTextForwarding: () => performTextForwarding,
|
|
31
|
+
performToolExecutions: () => performToolExecutions,
|
|
32
|
+
removeInstructions: () => removeInstructions,
|
|
33
|
+
updateInstructions: () => updateInstructions
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(generation_exports);
|
|
36
|
+
var import_rtc_node = require("@livekit/rtc-node");
|
|
37
|
+
var import_zod = require("zod");
|
|
38
|
+
var import_chat_context = require("../llm/chat_context.cjs");
|
|
39
|
+
var import_tool_context = require("../llm/tool_context.cjs");
|
|
40
|
+
var import_log = require("../log.cjs");
|
|
41
|
+
var import_identity_transform = require("../stream/identity_transform.cjs");
|
|
42
|
+
var import_utils = require("../utils.cjs");
|
|
43
|
+
var import_agent = require("./agent.cjs");
|
|
44
|
+
var import_run_context = require("./run_context.cjs");
|
|
45
|
+
class _LLMGenerationData {
|
|
46
|
+
constructor(textStream, toolCallStream) {
|
|
47
|
+
this.textStream = textStream;
|
|
48
|
+
this.toolCallStream = toolCallStream;
|
|
49
|
+
this.id = (0, import_utils.shortuuid)("item_");
|
|
50
|
+
this.generatedToolCalls = [];
|
|
51
|
+
}
|
|
52
|
+
generatedText = "";
|
|
53
|
+
generatedToolCalls;
|
|
54
|
+
id;
|
|
55
|
+
}
|
|
56
|
+
class _ToolOutput {
|
|
57
|
+
output;
|
|
58
|
+
firstToolFut;
|
|
59
|
+
constructor() {
|
|
60
|
+
this.output = [];
|
|
61
|
+
this.firstToolFut = new import_utils.Future();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class _SanitizedOutput {
|
|
65
|
+
toolCall;
|
|
66
|
+
toolCallOutput;
|
|
67
|
+
replyRequired;
|
|
68
|
+
agentTask;
|
|
69
|
+
constructor(toolCall, toolCallOutput, replyRequired, agentTask) {
|
|
70
|
+
this.toolCall = toolCall;
|
|
71
|
+
this.toolCallOutput = toolCallOutput;
|
|
72
|
+
this.replyRequired = replyRequired;
|
|
73
|
+
this.agentTask = agentTask;
|
|
74
|
+
}
|
|
75
|
+
static create(params) {
|
|
76
|
+
const { toolCall, toolCallOutput, replyRequired = true, agentTask } = params;
|
|
77
|
+
return new _SanitizedOutput(toolCall, toolCallOutput, replyRequired, agentTask);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function isValidToolOutput(toolOutput) {
|
|
81
|
+
const validTypes = ["string", "number", "boolean"];
|
|
82
|
+
if (validTypes.includes(typeof toolOutput)) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (toolOutput === void 0 || toolOutput === null) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(toolOutput)) {
|
|
89
|
+
return toolOutput.every(isValidToolOutput);
|
|
90
|
+
}
|
|
91
|
+
if (toolOutput instanceof Set) {
|
|
92
|
+
return Array.from(toolOutput).every(isValidToolOutput);
|
|
93
|
+
}
|
|
94
|
+
if (toolOutput instanceof Map) {
|
|
95
|
+
return Array.from(toolOutput.values()).every(isValidToolOutput);
|
|
96
|
+
}
|
|
97
|
+
if (toolOutput instanceof Object) {
|
|
98
|
+
return Object.entries(toolOutput).every(
|
|
99
|
+
([key, value]) => validTypes.includes(typeof key) && isValidToolOutput(value)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
class ToolExecutionOutput {
|
|
105
|
+
constructor(toolCall, toolCallOutput, agentTask, rawOutput, rawException, replyRequired) {
|
|
106
|
+
this.toolCall = toolCall;
|
|
107
|
+
this.toolCallOutput = toolCallOutput;
|
|
108
|
+
this.agentTask = agentTask;
|
|
109
|
+
this.rawOutput = rawOutput;
|
|
110
|
+
this.rawException = rawException;
|
|
111
|
+
this.replyRequired = replyRequired;
|
|
112
|
+
}
|
|
113
|
+
static create(params) {
|
|
114
|
+
const {
|
|
115
|
+
toolCall,
|
|
116
|
+
toolCallOutput,
|
|
117
|
+
agentTask,
|
|
118
|
+
rawOutput,
|
|
119
|
+
rawException,
|
|
120
|
+
replyRequired = true
|
|
121
|
+
} = params;
|
|
122
|
+
return new ToolExecutionOutput(
|
|
123
|
+
toolCall,
|
|
124
|
+
toolCallOutput,
|
|
125
|
+
agentTask,
|
|
126
|
+
rawOutput,
|
|
127
|
+
rawException,
|
|
128
|
+
replyRequired
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
class _JsOutput {
|
|
133
|
+
toolCall;
|
|
134
|
+
output;
|
|
135
|
+
exception;
|
|
136
|
+
#logger = (0, import_log.log)();
|
|
137
|
+
constructor(toolCall, output, exception) {
|
|
138
|
+
this.toolCall = toolCall;
|
|
139
|
+
this.output = output;
|
|
140
|
+
this.exception = exception;
|
|
141
|
+
}
|
|
142
|
+
static create(params) {
|
|
143
|
+
const { toolCall, output = void 0, exception = void 0 } = params;
|
|
144
|
+
return new _JsOutput(toolCall, output, exception);
|
|
145
|
+
}
|
|
146
|
+
sanitize() {
|
|
147
|
+
if ((0, import_tool_context.isToolError)(this.exception)) {
|
|
148
|
+
return _SanitizedOutput.create({
|
|
149
|
+
toolCall: import_chat_context.FunctionCall.create({ ...this.toolCall }),
|
|
150
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
151
|
+
name: this.toolCall.name,
|
|
152
|
+
callId: this.toolCall.callId,
|
|
153
|
+
output: this.exception.message,
|
|
154
|
+
isError: true
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if ((0, import_agent.isStopResponse)(this.exception)) {
|
|
159
|
+
return _SanitizedOutput.create({
|
|
160
|
+
toolCall: import_chat_context.FunctionCall.create({ ...this.toolCall })
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (this.exception !== void 0) {
|
|
164
|
+
return _SanitizedOutput.create({
|
|
165
|
+
toolCall: import_chat_context.FunctionCall.create({ ...this.toolCall }),
|
|
166
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
167
|
+
name: this.toolCall.name,
|
|
168
|
+
callId: this.toolCall.callId,
|
|
169
|
+
output: "An internal error occurred while executing the tool.",
|
|
170
|
+
// Don't send the actual error message, as it may contain sensitive information
|
|
171
|
+
isError: true
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
let agentTask = void 0;
|
|
176
|
+
let toolOutput = this.output;
|
|
177
|
+
if ((0, import_tool_context.isAgentHandoff)(this.output)) {
|
|
178
|
+
agentTask = this.output.agent;
|
|
179
|
+
toolOutput = this.output.returns;
|
|
180
|
+
}
|
|
181
|
+
if (!isValidToolOutput(toolOutput)) {
|
|
182
|
+
this.#logger.error(
|
|
183
|
+
{
|
|
184
|
+
callId: this.toolCall.callId,
|
|
185
|
+
function: this.toolCall.name
|
|
186
|
+
},
|
|
187
|
+
`AI function ${this.toolCall.name} returned an invalid output`
|
|
188
|
+
);
|
|
189
|
+
return _SanitizedOutput.create({
|
|
190
|
+
toolCall: import_chat_context.FunctionCall.create({ ...this.toolCall }),
|
|
191
|
+
toolCallOutput: void 0
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return _SanitizedOutput.create({
|
|
195
|
+
toolCall: import_chat_context.FunctionCall.create({ ...this.toolCall }),
|
|
196
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
197
|
+
name: this.toolCall.name,
|
|
198
|
+
callId: this.toolCall.callId,
|
|
199
|
+
output: toolOutput !== void 0 ? JSON.stringify(toolOutput) : "",
|
|
200
|
+
// take the string representation of the output
|
|
201
|
+
isError: false
|
|
202
|
+
}),
|
|
203
|
+
replyRequired: toolOutput !== void 0,
|
|
204
|
+
// require a reply if the tool returned an output
|
|
205
|
+
agentTask
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function createToolOutput(params) {
|
|
210
|
+
const { toolCall, output, exception } = params;
|
|
211
|
+
const logger = (0, import_log.log)();
|
|
212
|
+
let finalOutput = output;
|
|
213
|
+
let finalException = exception;
|
|
214
|
+
if (output instanceof Error) {
|
|
215
|
+
finalException = output;
|
|
216
|
+
finalOutput = void 0;
|
|
217
|
+
}
|
|
218
|
+
if ((0, import_tool_context.isToolError)(finalException)) {
|
|
219
|
+
return ToolExecutionOutput.create({
|
|
220
|
+
toolCall: import_chat_context.FunctionCall.create({ ...toolCall }),
|
|
221
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
222
|
+
name: toolCall.name,
|
|
223
|
+
callId: toolCall.callId,
|
|
224
|
+
output: finalException.message,
|
|
225
|
+
isError: true
|
|
226
|
+
}),
|
|
227
|
+
rawOutput: finalOutput,
|
|
228
|
+
rawException: finalException
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if ((0, import_agent.isStopResponse)(finalException)) {
|
|
232
|
+
return ToolExecutionOutput.create({
|
|
233
|
+
toolCall: import_chat_context.FunctionCall.create({ ...toolCall }),
|
|
234
|
+
rawOutput: finalOutput,
|
|
235
|
+
rawException: finalException
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (finalException !== void 0) {
|
|
239
|
+
return ToolExecutionOutput.create({
|
|
240
|
+
toolCall: import_chat_context.FunctionCall.create({ ...toolCall }),
|
|
241
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
242
|
+
name: toolCall.name,
|
|
243
|
+
callId: toolCall.callId,
|
|
244
|
+
output: "An internal error occurred",
|
|
245
|
+
// Don't send the actual error message, as it may contain sensitive information
|
|
246
|
+
isError: true
|
|
247
|
+
}),
|
|
248
|
+
rawOutput: finalOutput,
|
|
249
|
+
rawException: finalException
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
let agentTask = void 0;
|
|
253
|
+
let toolOutput = finalOutput;
|
|
254
|
+
if ((0, import_tool_context.isAgentHandoff)(finalOutput)) {
|
|
255
|
+
agentTask = finalOutput.agent;
|
|
256
|
+
toolOutput = finalOutput.returns;
|
|
257
|
+
}
|
|
258
|
+
if (!isValidToolOutput(toolOutput)) {
|
|
259
|
+
logger.error(
|
|
260
|
+
{
|
|
261
|
+
callId: toolCall.callId,
|
|
262
|
+
output: finalOutput
|
|
263
|
+
},
|
|
264
|
+
`AI function ${toolCall.name} returned an invalid output`
|
|
265
|
+
);
|
|
266
|
+
return ToolExecutionOutput.create({
|
|
267
|
+
toolCall: import_chat_context.FunctionCall.create({ ...toolCall }),
|
|
268
|
+
rawOutput: finalOutput,
|
|
269
|
+
rawException: finalException
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return ToolExecutionOutput.create({
|
|
273
|
+
toolCall: import_chat_context.FunctionCall.create({ ...toolCall }),
|
|
274
|
+
toolCallOutput: import_chat_context.FunctionCallOutput.create({
|
|
275
|
+
name: toolCall.name,
|
|
276
|
+
callId: toolCall.callId,
|
|
277
|
+
output: toolOutput !== void 0 ? JSON.stringify(toolOutput) : "",
|
|
278
|
+
// take the string representation of the output
|
|
279
|
+
isError: false
|
|
280
|
+
}),
|
|
281
|
+
replyRequired: toolOutput !== void 0,
|
|
282
|
+
// require a reply if the tool returned an output
|
|
283
|
+
agentTask,
|
|
284
|
+
rawOutput: finalOutput,
|
|
285
|
+
rawException: finalException
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const INSTRUCTIONS_MESSAGE_ID = "lk.agent_task.instructions";
|
|
289
|
+
function updateInstructions(options) {
|
|
290
|
+
const { chatCtx, instructions, addIfMissing } = options;
|
|
291
|
+
const idx = chatCtx.indexById(INSTRUCTIONS_MESSAGE_ID);
|
|
292
|
+
if (idx !== void 0) {
|
|
293
|
+
if (chatCtx.items[idx].type === "message") {
|
|
294
|
+
chatCtx.items[idx] = import_chat_context.ChatMessage.create({
|
|
295
|
+
id: INSTRUCTIONS_MESSAGE_ID,
|
|
296
|
+
role: "system",
|
|
297
|
+
content: [instructions],
|
|
298
|
+
createdAt: chatCtx.items[idx].createdAt
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
throw new Error('expected the instructions inside the chatCtx to be of type "message"');
|
|
302
|
+
}
|
|
303
|
+
} else if (addIfMissing) {
|
|
304
|
+
chatCtx.items.unshift(
|
|
305
|
+
import_chat_context.ChatMessage.create({
|
|
306
|
+
id: INSTRUCTIONS_MESSAGE_ID,
|
|
307
|
+
role: "system",
|
|
308
|
+
content: [instructions]
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function performLLMInference(node, chatCtx, toolCtx, modelSettings, controller) {
|
|
314
|
+
const textStream = new import_identity_transform.IdentityTransform();
|
|
315
|
+
const toolCallStream = new import_identity_transform.IdentityTransform();
|
|
316
|
+
const textWriter = textStream.writable.getWriter();
|
|
317
|
+
const toolCallWriter = toolCallStream.writable.getWriter();
|
|
318
|
+
const data = new _LLMGenerationData(textStream.readable, toolCallStream.readable);
|
|
319
|
+
const inferenceTask = async (signal) => {
|
|
320
|
+
let llmStreamReader = null;
|
|
321
|
+
let llmStream = null;
|
|
322
|
+
try {
|
|
323
|
+
llmStream = await node(chatCtx, toolCtx, modelSettings);
|
|
324
|
+
if (llmStream === null) {
|
|
325
|
+
await textWriter.close();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
llmStreamReader = llmStream.getReader();
|
|
329
|
+
while (true) {
|
|
330
|
+
if (signal.aborted) {
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
const { done, value: chunk } = await llmStreamReader.read();
|
|
334
|
+
if (done) {
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
if (typeof chunk === "string") {
|
|
338
|
+
data.generatedText += chunk;
|
|
339
|
+
await textWriter.write(chunk);
|
|
340
|
+
} else {
|
|
341
|
+
if (chunk.delta === void 0) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
if (chunk.delta.toolCalls) {
|
|
345
|
+
for (const tool of chunk.delta.toolCalls) {
|
|
346
|
+
if (tool.type !== "function_call") continue;
|
|
347
|
+
const toolCall = import_chat_context.FunctionCall.create({
|
|
348
|
+
callId: `${data.id}/fnc_${data.generatedToolCalls.length}`,
|
|
349
|
+
name: tool.name,
|
|
350
|
+
args: tool.args
|
|
351
|
+
});
|
|
352
|
+
data.generatedToolCalls.push(toolCall);
|
|
353
|
+
await toolCallWriter.write(toolCall);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (chunk.delta.content) {
|
|
357
|
+
data.generatedText += chunk.delta.content;
|
|
358
|
+
await textWriter.write(chunk.delta.content);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
throw error;
|
|
367
|
+
} finally {
|
|
368
|
+
llmStreamReader == null ? void 0 : llmStreamReader.releaseLock();
|
|
369
|
+
await (llmStream == null ? void 0 : llmStream.cancel());
|
|
370
|
+
await textWriter.close();
|
|
371
|
+
await toolCallWriter.close();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
return [
|
|
375
|
+
import_utils.Task.from((controller2) => inferenceTask(controller2.signal), controller, "performLLMInference"),
|
|
376
|
+
data
|
|
377
|
+
];
|
|
378
|
+
}
|
|
379
|
+
function performTTSInference(node, text, modelSettings, controller) {
|
|
380
|
+
const audioStream = new import_identity_transform.IdentityTransform();
|
|
381
|
+
const outputWriter = audioStream.writable.getWriter();
|
|
382
|
+
const audioOutputStream = audioStream.readable;
|
|
383
|
+
const inferenceTask = async (signal) => {
|
|
384
|
+
let ttsStreamReader = null;
|
|
385
|
+
let ttsStream = null;
|
|
386
|
+
try {
|
|
387
|
+
ttsStream = await node(text, modelSettings);
|
|
388
|
+
if (ttsStream === null) {
|
|
389
|
+
await outputWriter.close();
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
ttsStreamReader = ttsStream.getReader();
|
|
393
|
+
while (true) {
|
|
394
|
+
if (signal.aborted) {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
const { done, value: chunk } = await ttsStreamReader.read();
|
|
398
|
+
if (done) {
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
await outputWriter.write(chunk);
|
|
402
|
+
}
|
|
403
|
+
} catch (error) {
|
|
404
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
throw error;
|
|
408
|
+
} finally {
|
|
409
|
+
ttsStreamReader == null ? void 0 : ttsStreamReader.releaseLock();
|
|
410
|
+
await (ttsStream == null ? void 0 : ttsStream.cancel());
|
|
411
|
+
await outputWriter.close();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
return [
|
|
415
|
+
import_utils.Task.from((controller2) => inferenceTask(controller2.signal), controller, "performTTSInference"),
|
|
416
|
+
audioOutputStream
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
async function forwardText(source, out, signal, textOutput) {
|
|
420
|
+
const reader = source.getReader();
|
|
421
|
+
try {
|
|
422
|
+
while (true) {
|
|
423
|
+
if (signal.aborted) {
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
const { done, value: delta } = await reader.read();
|
|
427
|
+
if (done) break;
|
|
428
|
+
out.text += delta;
|
|
429
|
+
if (textOutput !== null) {
|
|
430
|
+
await textOutput.captureText(delta);
|
|
431
|
+
}
|
|
432
|
+
if (!out.firstTextFut.done) {
|
|
433
|
+
out.firstTextFut.resolve();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
} finally {
|
|
437
|
+
if (textOutput !== null) {
|
|
438
|
+
textOutput.flush();
|
|
439
|
+
}
|
|
440
|
+
reader == null ? void 0 : reader.releaseLock();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function performTextForwarding(source, controller, textOutput) {
|
|
444
|
+
const out = {
|
|
445
|
+
text: "",
|
|
446
|
+
firstTextFut: new import_utils.Future()
|
|
447
|
+
};
|
|
448
|
+
return [
|
|
449
|
+
import_utils.Task.from(
|
|
450
|
+
(controller2) => forwardText(source, out, controller2.signal, textOutput),
|
|
451
|
+
controller,
|
|
452
|
+
"performTextForwarding"
|
|
453
|
+
),
|
|
454
|
+
out
|
|
455
|
+
];
|
|
456
|
+
}
|
|
457
|
+
async function forwardAudio(ttsStream, audioOuput, out, signal) {
|
|
458
|
+
const reader = ttsStream.getReader();
|
|
459
|
+
let resampler = null;
|
|
460
|
+
try {
|
|
461
|
+
while (true) {
|
|
462
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
const { done, value: frame } = await reader.read();
|
|
466
|
+
if (done) break;
|
|
467
|
+
out.audio.push(frame);
|
|
468
|
+
if (!out.firstFrameFut.done && audioOuput.sampleRate && audioOuput.sampleRate !== frame.sampleRate && !resampler) {
|
|
469
|
+
resampler = new import_rtc_node.AudioResampler(frame.sampleRate, audioOuput.sampleRate, 1);
|
|
470
|
+
}
|
|
471
|
+
if (resampler) {
|
|
472
|
+
for (const f of resampler.push(frame)) {
|
|
473
|
+
await audioOuput.captureFrame(f);
|
|
474
|
+
}
|
|
475
|
+
} else {
|
|
476
|
+
await audioOuput.captureFrame(frame);
|
|
477
|
+
}
|
|
478
|
+
if (!out.firstFrameFut.done) {
|
|
479
|
+
out.firstFrameFut.resolve();
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
} finally {
|
|
483
|
+
reader == null ? void 0 : reader.releaseLock();
|
|
484
|
+
if (resampler) {
|
|
485
|
+
for (const f of resampler.flush()) {
|
|
486
|
+
await audioOuput.captureFrame(f);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
audioOuput.flush();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function performAudioForwarding(ttsStream, audioOutput, controller) {
|
|
493
|
+
const out = {
|
|
494
|
+
audio: [],
|
|
495
|
+
firstFrameFut: new import_utils.Future()
|
|
496
|
+
};
|
|
497
|
+
return [
|
|
498
|
+
import_utils.Task.from(
|
|
499
|
+
(controller2) => forwardAudio(ttsStream, audioOutput, out, controller2.signal),
|
|
500
|
+
controller,
|
|
501
|
+
"performAudioForwarding"
|
|
502
|
+
),
|
|
503
|
+
out
|
|
504
|
+
];
|
|
505
|
+
}
|
|
506
|
+
function performToolExecutions({
|
|
507
|
+
session,
|
|
508
|
+
speechHandle,
|
|
509
|
+
toolCtx,
|
|
510
|
+
toolChoice,
|
|
511
|
+
toolCallStream,
|
|
512
|
+
onToolExecutionStarted = () => {
|
|
513
|
+
},
|
|
514
|
+
onToolExecutionCompleted = () => {
|
|
515
|
+
},
|
|
516
|
+
controller
|
|
517
|
+
}) {
|
|
518
|
+
const logger = (0, import_log.log)();
|
|
519
|
+
const toolOutput = {
|
|
520
|
+
output: [],
|
|
521
|
+
firstToolStartedFuture: new import_utils.Future()
|
|
522
|
+
};
|
|
523
|
+
const toolCompleted = (out) => {
|
|
524
|
+
onToolExecutionCompleted(out);
|
|
525
|
+
toolOutput.output.push(out);
|
|
526
|
+
};
|
|
527
|
+
const executeToolsTask = async (controller2) => {
|
|
528
|
+
const signal = controller2.signal;
|
|
529
|
+
const reader = toolCallStream.getReader();
|
|
530
|
+
const tasks = [];
|
|
531
|
+
while (!signal.aborted) {
|
|
532
|
+
const { done, value: toolCall } = await reader.read();
|
|
533
|
+
if (signal.aborted) break;
|
|
534
|
+
if (done) break;
|
|
535
|
+
if (toolChoice === "none") {
|
|
536
|
+
logger.error(
|
|
537
|
+
{
|
|
538
|
+
function: toolCall.name,
|
|
539
|
+
speech_id: speechHandle.id
|
|
540
|
+
},
|
|
541
|
+
"received a tool call with toolChoice set to 'none', ignoring"
|
|
542
|
+
);
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
const tool = toolCtx[toolCall.name];
|
|
546
|
+
if (!tool) {
|
|
547
|
+
logger.warn(
|
|
548
|
+
{
|
|
549
|
+
function: toolCall.name,
|
|
550
|
+
speech_id: speechHandle.id
|
|
551
|
+
},
|
|
552
|
+
`unknown AI function ${toolCall.name}`
|
|
553
|
+
);
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (!(0, import_tool_context.isFunctionTool)(tool)) {
|
|
557
|
+
logger.error(
|
|
558
|
+
{
|
|
559
|
+
function: toolCall.name,
|
|
560
|
+
speech_id: speechHandle.id
|
|
561
|
+
},
|
|
562
|
+
`unknown tool type: ${typeof tool}`
|
|
563
|
+
);
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
let parsedArgs;
|
|
567
|
+
try {
|
|
568
|
+
const jsonArgs = JSON.parse(toolCall.args);
|
|
569
|
+
if (tool.parameters instanceof import_zod.ZodObject) {
|
|
570
|
+
parsedArgs = tool.parameters.parse(jsonArgs);
|
|
571
|
+
} else {
|
|
572
|
+
parsedArgs = jsonArgs;
|
|
573
|
+
}
|
|
574
|
+
} catch (rawError) {
|
|
575
|
+
const error = (0, import_utils.toError)(rawError);
|
|
576
|
+
logger.error(
|
|
577
|
+
{
|
|
578
|
+
function: toolCall.name,
|
|
579
|
+
arguments: toolCall.args,
|
|
580
|
+
speech_id: speechHandle.id,
|
|
581
|
+
error: error.message
|
|
582
|
+
},
|
|
583
|
+
`tried to call AI function ${toolCall.name} with invalid arguments`
|
|
584
|
+
);
|
|
585
|
+
toolCompleted(
|
|
586
|
+
createToolOutput({
|
|
587
|
+
toolCall,
|
|
588
|
+
exception: error
|
|
589
|
+
})
|
|
590
|
+
);
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
if (!toolOutput.firstToolStartedFuture.done) {
|
|
594
|
+
toolOutput.firstToolStartedFuture.resolve();
|
|
595
|
+
}
|
|
596
|
+
onToolExecutionStarted(toolCall);
|
|
597
|
+
logger.info(
|
|
598
|
+
{
|
|
599
|
+
function: toolCall.name,
|
|
600
|
+
arguments: parsedArgs,
|
|
601
|
+
speech_id: speechHandle.id
|
|
602
|
+
},
|
|
603
|
+
"Executing LLM tool call"
|
|
604
|
+
);
|
|
605
|
+
const toolExecution = import_agent.asyncLocalStorage.run({ functionCall: toolCall }, async () => {
|
|
606
|
+
return await tool.execute(parsedArgs, {
|
|
607
|
+
ctx: new import_run_context.RunContext(session, speechHandle, toolCall),
|
|
608
|
+
toolCallId: toolCall.callId,
|
|
609
|
+
abortSignal: signal
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
const tracableToolExecution = async (toolExecTask) => {
|
|
613
|
+
let toolOutput2;
|
|
614
|
+
try {
|
|
615
|
+
const { result, isAborted } = await waitUntilAborted(toolExecTask, signal);
|
|
616
|
+
toolOutput2 = createToolOutput({
|
|
617
|
+
toolCall,
|
|
618
|
+
exception: isAborted ? new Error("tool call was aborted") : void 0,
|
|
619
|
+
output: isAborted ? void 0 : result
|
|
620
|
+
});
|
|
621
|
+
} catch (rawError) {
|
|
622
|
+
logger.error(
|
|
623
|
+
{
|
|
624
|
+
function: toolCall.name,
|
|
625
|
+
speech_id: speechHandle.id,
|
|
626
|
+
error: (0, import_utils.toError)(rawError).message
|
|
627
|
+
},
|
|
628
|
+
"exception occurred while executing tool"
|
|
629
|
+
);
|
|
630
|
+
toolOutput2 = createToolOutput({
|
|
631
|
+
toolCall,
|
|
632
|
+
exception: (0, import_utils.toError)(rawError)
|
|
633
|
+
});
|
|
634
|
+
} finally {
|
|
635
|
+
if (!toolOutput2) throw new Error("toolOutput is undefined");
|
|
636
|
+
toolCompleted(toolOutput2);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
tasks.push(tracableToolExecution(toolExecution));
|
|
640
|
+
}
|
|
641
|
+
await Promise.allSettled(tasks);
|
|
642
|
+
if (toolOutput.output.length > 0) {
|
|
643
|
+
logger.debug(
|
|
644
|
+
{
|
|
645
|
+
speech_id: speechHandle.id
|
|
646
|
+
},
|
|
647
|
+
"tools execution completed"
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
return [import_utils.Task.from(executeToolsTask, controller, "performToolExecutions"), toolOutput];
|
|
652
|
+
}
|
|
653
|
+
async function waitUntilAborted(promise, signal) {
|
|
654
|
+
const abortFut = new import_utils.Future();
|
|
655
|
+
const resolveAbort = () => {
|
|
656
|
+
if (!abortFut.done) {
|
|
657
|
+
abortFut.resolve({ result: void 0, isAborted: true });
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
signal.addEventListener("abort", resolveAbort);
|
|
661
|
+
promise.then((r) => {
|
|
662
|
+
if (!abortFut.done) {
|
|
663
|
+
abortFut.resolve({ result: r, isAborted: false });
|
|
664
|
+
}
|
|
665
|
+
}).catch((e) => {
|
|
666
|
+
if (!abortFut.done) {
|
|
667
|
+
abortFut.reject(e);
|
|
668
|
+
}
|
|
669
|
+
}).finally(() => {
|
|
670
|
+
signal.removeEventListener("abort", resolveAbort);
|
|
671
|
+
});
|
|
672
|
+
return await abortFut.await;
|
|
673
|
+
}
|
|
674
|
+
function removeInstructions(chatCtx) {
|
|
675
|
+
while (true) {
|
|
676
|
+
const idx = chatCtx.indexById(INSTRUCTIONS_MESSAGE_ID);
|
|
677
|
+
if (idx !== void 0) {
|
|
678
|
+
chatCtx.items.splice(idx, 1);
|
|
679
|
+
} else {
|
|
680
|
+
break;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
685
|
+
0 && (module.exports = {
|
|
686
|
+
ToolExecutionOutput,
|
|
687
|
+
_JsOutput,
|
|
688
|
+
_LLMGenerationData,
|
|
689
|
+
_SanitizedOutput,
|
|
690
|
+
_ToolOutput,
|
|
691
|
+
createToolOutput,
|
|
692
|
+
performAudioForwarding,
|
|
693
|
+
performLLMInference,
|
|
694
|
+
performTTSInference,
|
|
695
|
+
performTextForwarding,
|
|
696
|
+
performToolExecutions,
|
|
697
|
+
removeInstructions,
|
|
698
|
+
updateInstructions
|
|
699
|
+
});
|
|
700
|
+
//# sourceMappingURL=generation.cjs.map
|