@pipedog/core 0.0.0 → 0.1.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/LICENSE +25 -0
- package/NOTICE +9 -0
- package/dist/adapters/base_llm_adapter.d.ts +266 -0
- package/dist/adapters/base_llm_adapter.js +489 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.js +8 -0
- package/dist/adapters/schemas/direct_function.d.ts +202 -0
- package/dist/adapters/schemas/direct_function.js +302 -0
- package/dist/adapters/schemas/function_schema.d.ts +67 -0
- package/dist/adapters/schemas/function_schema.js +72 -0
- package/dist/adapters/schemas/index.d.ts +2 -0
- package/dist/adapters/schemas/index.js +8 -0
- package/dist/adapters/schemas/tools_schema.d.ts +57 -0
- package/dist/adapters/schemas/tools_schema.js +79 -0
- package/dist/adapters/services/index.d.ts +2 -0
- package/dist/adapters/services/index.js +8 -0
- package/dist/adapters/services/open_ai_adapter.d.ts +147 -0
- package/dist/adapters/services/open_ai_adapter.js +250 -0
- package/dist/audio/dtmf/dtmf_data.d.ts +3 -0
- package/dist/audio/dtmf/dtmf_data.js +22 -0
- package/dist/audio/dtmf/index.d.ts +2 -0
- package/dist/audio/dtmf/index.js +8 -0
- package/dist/audio/dtmf/types.d.ts +31 -0
- package/dist/audio/dtmf/types.js +35 -0
- package/dist/audio/dtmf/utils.d.ts +13 -0
- package/dist/audio/dtmf/utils.js +62 -0
- package/dist/audio/filters/base_audio_filter.d.ts +51 -0
- package/dist/audio/filters/base_audio_filter.js +17 -0
- package/dist/audio/filters/index.d.ts +2 -0
- package/dist/audio/filters/index.js +8 -0
- package/dist/audio/index.d.ts +2 -0
- package/dist/audio/index.js +8 -0
- package/dist/audio/krisp_instance.d.ts +95 -0
- package/dist/audio/krisp_instance.js +229 -0
- package/dist/audio/mixers/base_audio_mixer.d.ts +56 -0
- package/dist/audio/mixers/base_audio_mixer.js +16 -0
- package/dist/audio/mixers/index.d.ts +2 -0
- package/dist/audio/mixers/index.js +8 -0
- package/dist/audio/resamplers/base_audio_resampler.d.ts +46 -0
- package/dist/audio/resamplers/base_audio_resampler.js +35 -0
- package/dist/audio/resamplers/index.d.ts +2 -0
- package/dist/audio/resamplers/index.js +8 -0
- package/dist/audio/resamplers/resampy_resampler.d.ts +10 -0
- package/dist/audio/resamplers/resampy_resampler.js +15 -0
- package/dist/audio/resamplers/soxr_resampler.d.ts +54 -0
- package/dist/audio/resamplers/soxr_resampler.js +69 -0
- package/dist/audio/resamplers/soxr_stream_resampler.d.ts +75 -0
- package/dist/audio/resamplers/soxr_stream_resampler.js +146 -0
- package/dist/audio/turn/base_turn_analyzer.d.ts +84 -0
- package/dist/audio/turn/base_turn_analyzer.js +61 -0
- package/dist/audio/turn/index.d.ts +2 -0
- package/dist/audio/turn/index.js +8 -0
- package/dist/audio/turn/smart_turn/_whisper_features.d.ts +30 -0
- package/dist/audio/turn/smart_turn/_whisper_features.js +225 -0
- package/dist/audio/turn/smart_turn/base_smart_turn.d.ts +94 -0
- package/dist/audio/turn/smart_turn/base_smart_turn.js +239 -0
- package/dist/audio/turn/smart_turn/local_smart_turn_v3.d.ts +76 -0
- package/dist/audio/turn/smart_turn/local_smart_turn_v3.js +143 -0
- package/dist/audio/utils.d.ts +224 -0
- package/dist/audio/utils.js +634 -0
- package/dist/audio/vad/data/index.d.ts +2 -0
- package/dist/audio/vad/data/index.js +8 -0
- package/dist/audio/vad/index.d.ts +2 -0
- package/dist/audio/vad/index.js +8 -0
- package/dist/audio/vad/vad_analyzer.d.ts +126 -0
- package/dist/audio/vad/vad_analyzer.js +211 -0
- package/dist/audio/vad/vad_controller.d.ts +143 -0
- package/dist/audio/vad/vad_controller.js +228 -0
- package/dist/audio/volume.d.ts +38 -0
- package/dist/audio/volume.js +75 -0
- package/dist/bus/adapters/base.d.ts +35 -0
- package/dist/bus/adapters/base.js +19 -0
- package/dist/bus/adapters/index.d.ts +10 -0
- package/dist/bus/adapters/index.js +15 -0
- package/dist/bus/adapters/llm_context_adapter.d.ts +36 -0
- package/dist/bus/adapters/llm_context_adapter.js +82 -0
- package/dist/bus/adapters/tools_schema_adapter.d.ts +25 -0
- package/dist/bus/adapters/tools_schema_adapter.js +70 -0
- package/dist/bus/bridge_processor.d.ts +111 -0
- package/dist/bus/bridge_processor.js +166 -0
- package/dist/bus/bus.d.ts +110 -0
- package/dist/bus/bus.js +200 -0
- package/dist/bus/index.d.ts +22 -0
- package/dist/bus/index.js +27 -0
- package/dist/bus/local/async_queue.d.ts +12 -0
- package/dist/bus/local/async_queue.js +21 -0
- package/dist/bus/local/index.d.ts +3 -0
- package/dist/bus/local/index.js +8 -0
- package/dist/bus/messages.d.ts +378 -0
- package/dist/bus/messages.js +357 -0
- package/dist/bus/network/index.d.ts +16 -0
- package/dist/bus/network/index.js +21 -0
- package/dist/bus/queue.d.ts +27 -0
- package/dist/bus/queue.js +51 -0
- package/dist/bus/serializers/base.d.ts +25 -0
- package/dist/bus/serializers/base.js +14 -0
- package/dist/bus/serializers/index.d.ts +9 -0
- package/dist/bus/serializers/index.js +14 -0
- package/dist/bus/serializers/json.d.ts +77 -0
- package/dist/bus/serializers/json.js +367 -0
- package/dist/bus/subscriber.d.ts +46 -0
- package/dist/bus/subscriber.js +27 -0
- package/dist/bus/ui/index.d.ts +3 -0
- package/dist/bus/ui/index.js +8 -0
- package/dist/bus/ui/messages.d.ts +186 -0
- package/dist/bus/ui/messages.js +171 -0
- package/dist/classifiers/base_classifier.d.ts +263 -0
- package/dist/classifiers/base_classifier.js +346 -0
- package/dist/classifiers/cloudflare/clef/classifier.d.ts +70 -0
- package/dist/classifiers/cloudflare/clef/classifier.js +204 -0
- package/dist/classifiers/cloudflare/clef/client.d.ts +104 -0
- package/dist/classifiers/cloudflare/clef/client.js +234 -0
- package/dist/classifiers/cloudflare/clef/index.d.ts +2 -0
- package/dist/classifiers/cloudflare/clef/index.js +8 -0
- package/dist/classifiers/cloudflare/index.d.ts +2 -0
- package/dist/classifiers/cloudflare/index.js +8 -0
- package/dist/classifiers/http_client.d.ts +70 -0
- package/dist/classifiers/http_client.js +161 -0
- package/dist/classifiers/index.d.ts +2 -0
- package/dist/classifiers/index.js +8 -0
- package/dist/classifiers/jev/classifier.d.ts +8 -0
- package/dist/classifiers/jev/classifier.js +13 -0
- package/dist/classifiers/jev/client.d.ts +8 -0
- package/dist/classifiers/jev/client.js +13 -0
- package/dist/classifiers/jev/index.d.ts +2 -0
- package/dist/classifiers/jev/index.js +8 -0
- package/dist/classifiers/llm/classifier.d.ts +72 -0
- package/dist/classifiers/llm/classifier.js +304 -0
- package/dist/classifiers/llm/index.d.ts +2 -0
- package/dist/classifiers/llm/index.js +8 -0
- package/dist/classifiers/openai/decisions/classifier.d.ts +77 -0
- package/dist/classifiers/openai/decisions/classifier.js +241 -0
- package/dist/classifiers/openai/decisions/client.d.ts +108 -0
- package/dist/classifiers/openai/decisions/client.js +234 -0
- package/dist/classifiers/openai/decisions/index.d.ts +2 -0
- package/dist/classifiers/openai/decisions/index.js +8 -0
- package/dist/classifiers/openai/index.d.ts +2 -0
- package/dist/classifiers/openai/index.js +8 -0
- package/dist/classifiers/typesafe/index.d.ts +2 -0
- package/dist/classifiers/typesafe/index.js +8 -0
- package/dist/classifiers/typesafe/jev/classifier.d.ts +70 -0
- package/dist/classifiers/typesafe/jev/classifier.js +220 -0
- package/dist/classifiers/typesafe/jev/client.d.ts +105 -0
- package/dist/classifiers/typesafe/jev/client.js +233 -0
- package/dist/classifiers/typesafe/jev/index.d.ts +2 -0
- package/dist/classifiers/typesafe/jev/index.js +8 -0
- package/dist/clocks/base_clock.d.ts +13 -0
- package/dist/clocks/base_clock.js +14 -0
- package/dist/clocks/index.d.ts +2 -0
- package/dist/clocks/index.js +8 -0
- package/dist/clocks/system_clock.d.ts +15 -0
- package/dist/clocks/system_clock.js +25 -0
- package/dist/frames/frames.d.ts +2533 -0
- package/dist/frames/frames.js +2485 -0
- package/dist/frames/index.d.ts +2 -0
- package/dist/frames/index.js +8 -0
- package/dist/frames/protobufs/frames_pb2.d.ts +229 -0
- package/dist/frames/protobufs/frames_pb2.js +466 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +56 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.js +8 -0
- package/dist/metrics/metrics.d.ts +276 -0
- package/dist/metrics/metrics.js +254 -0
- package/dist/observers/base_observer.d.ts +173 -0
- package/dist/observers/base_observer.js +151 -0
- package/dist/observers/error_observer.d.ts +75 -0
- package/dist/observers/error_observer.js +87 -0
- package/dist/observers/function_call_observer.d.ts +157 -0
- package/dist/observers/function_call_observer.js +222 -0
- package/dist/observers/index.d.ts +2 -0
- package/dist/observers/index.js +8 -0
- package/dist/observers/loggers/debug_log_observer.d.ts +91 -0
- package/dist/observers/loggers/debug_log_observer.js +228 -0
- package/dist/observers/loggers/index.d.ts +2 -0
- package/dist/observers/loggers/index.js +8 -0
- package/dist/observers/loggers/llm_log_observer.d.ts +24 -0
- package/dist/observers/loggers/llm_log_observer.js +110 -0
- package/dist/observers/loggers/metrics_log_observer.d.ts +85 -0
- package/dist/observers/loggers/metrics_log_observer.js +186 -0
- package/dist/observers/loggers/transcription_log_observer.d.ts +23 -0
- package/dist/observers/loggers/transcription_log_observer.js +74 -0
- package/dist/observers/service_metrics_observer.d.ts +168 -0
- package/dist/observers/service_metrics_observer.js +236 -0
- package/dist/observers/speaking_observer.d.ts +104 -0
- package/dist/observers/speaking_observer.js +150 -0
- package/dist/observers/startup_timing_observer.d.ts +221 -0
- package/dist/observers/startup_timing_observer.js +365 -0
- package/dist/observers/turn_tracking_observer.d.ts +78 -0
- package/dist/observers/turn_tracking_observer.js +189 -0
- package/dist/observers/user_bot_latency_observer.d.ts +411 -0
- package/dist/observers/user_bot_latency_observer.js +974 -0
- package/dist/pipeline/base_pipeline.d.ts +49 -0
- package/dist/pipeline/base_pipeline.js +101 -0
- package/dist/pipeline/capabilities.d.ts +76 -0
- package/dist/pipeline/capabilities.js +97 -0
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +8 -0
- package/dist/pipeline/job_context.d.ts +317 -0
- package/dist/pipeline/job_context.js +450 -0
- package/dist/pipeline/job_decorator.d.ts +54 -0
- package/dist/pipeline/job_decorator.js +92 -0
- package/dist/pipeline/llm_switcher.d.ts +84 -0
- package/dist/pipeline/llm_switcher.js +107 -0
- package/dist/pipeline/llm_with_backend.d.ts +435 -0
- package/dist/pipeline/llm_with_backend.js +806 -0
- package/dist/pipeline/parallel_pipeline.d.ts +83 -0
- package/dist/pipeline/parallel_pipeline.js +200 -0
- package/dist/pipeline/pipeline.d.ts +126 -0
- package/dist/pipeline/pipeline.js +196 -0
- package/dist/pipeline/service_switcher.d.ts +287 -0
- package/dist/pipeline/service_switcher.js +509 -0
- package/dist/pipeline/sync_parallel_pipeline.d.ts +192 -0
- package/dist/pipeline/sync_parallel_pipeline.js +387 -0
- package/dist/pipeline/worker.d.ts +814 -0
- package/dist/pipeline/worker.js +1639 -0
- package/dist/pipeline/worker_observer.d.ts +131 -0
- package/dist/pipeline/worker_observer.js +274 -0
- package/dist/pipeline/worker_ready_decorator.d.ts +45 -0
- package/dist/pipeline/worker_ready_decorator.js +76 -0
- package/dist/processors/aggregators/async_tool_messages.d.ts +146 -0
- package/dist/processors/aggregators/async_tool_messages.js +291 -0
- package/dist/processors/aggregators/dtmf_aggregator.d.ts +61 -0
- package/dist/processors/aggregators/dtmf_aggregator.js +144 -0
- package/dist/processors/aggregators/gated.d.ts +43 -0
- package/dist/processors/aggregators/gated.js +86 -0
- package/dist/processors/aggregators/gated_llm_context.d.ts +42 -0
- package/dist/processors/aggregators/gated_llm_context.js +86 -0
- package/dist/processors/aggregators/index.d.ts +2 -0
- package/dist/processors/aggregators/index.js +8 -0
- package/dist/processors/aggregators/llm_context.d.ts +370 -0
- package/dist/processors/aggregators/llm_context.js +580 -0
- package/dist/processors/aggregators/llm_context_summarizer.d.ts +219 -0
- package/dist/processors/aggregators/llm_context_summarizer.js +447 -0
- package/dist/processors/aggregators/llm_response.d.ts +37 -0
- package/dist/processors/aggregators/llm_response.js +71 -0
- package/dist/processors/aggregators/llm_response_universal.d.ts +966 -0
- package/dist/processors/aggregators/llm_response_universal.js +2394 -0
- package/dist/processors/aggregators/llm_text_processor.d.ts +53 -0
- package/dist/processors/aggregators/llm_text_processor.js +102 -0
- package/dist/processors/aggregators/sentence.d.ts +39 -0
- package/dist/processors/aggregators/sentence.js +69 -0
- package/dist/processors/async_generator.d.ts +42 -0
- package/dist/processors/async_generator.js +76 -0
- package/dist/processors/audio/audio_buffer_processor.d.ts +241 -0
- package/dist/processors/audio/audio_buffer_processor.js +565 -0
- package/dist/processors/audio/index.d.ts +2 -0
- package/dist/processors/audio/index.js +8 -0
- package/dist/processors/audio/vad_processor.d.ts +67 -0
- package/dist/processors/audio/vad_processor.js +103 -0
- package/dist/processors/consumer_processor.d.ts +49 -0
- package/dist/processors/consumer_processor.js +85 -0
- package/dist/processors/filters/frame_filter.d.ts +39 -0
- package/dist/processors/filters/frame_filter.js +52 -0
- package/dist/processors/filters/function_filter.d.ts +59 -0
- package/dist/processors/filters/function_filter.js +78 -0
- package/dist/processors/filters/identity_filter.d.ts +33 -0
- package/dist/processors/filters/identity_filter.js +37 -0
- package/dist/processors/filters/index.d.ts +2 -0
- package/dist/processors/filters/index.js +8 -0
- package/dist/processors/filters/null_filter.d.ts +34 -0
- package/dist/processors/filters/null_filter.js +47 -0
- package/dist/processors/filters/wake_notifier_filter.d.ts +48 -0
- package/dist/processors/filters/wake_notifier_filter.js +49 -0
- package/dist/processors/frame_processor.d.ts +360 -0
- package/dist/processors/frame_processor.js +932 -0
- package/dist/processors/frameworks/index.d.ts +2 -0
- package/dist/processors/frameworks/index.js +8 -0
- package/dist/processors/frameworks/rtvi/frames.d.ts +241 -0
- package/dist/processors/frameworks/rtvi/frames.js +259 -0
- package/dist/processors/frameworks/rtvi/index.d.ts +6 -0
- package/dist/processors/frameworks/rtvi/index.js +11 -0
- package/dist/processors/frameworks/rtvi/models.d.ts +1741 -0
- package/dist/processors/frameworks/rtvi/models.js +1807 -0
- package/dist/processors/frameworks/rtvi/observer.d.ts +340 -0
- package/dist/processors/frameworks/rtvi/observer.js +1113 -0
- package/dist/processors/frameworks/rtvi/processor.d.ts +182 -0
- package/dist/processors/frameworks/rtvi/processor.js +676 -0
- package/dist/processors/idle_frame_processor.d.ts +44 -0
- package/dist/processors/idle_frame_processor.js +86 -0
- package/dist/processors/index.d.ts +2 -0
- package/dist/processors/index.js +8 -0
- package/dist/processors/logger.d.ts +42 -0
- package/dist/processors/logger.js +87 -0
- package/dist/processors/metrics/frame_processor_metrics.d.ts +172 -0
- package/dist/processors/metrics/frame_processor_metrics.js +372 -0
- package/dist/processors/metrics/index.d.ts +2 -0
- package/dist/processors/metrics/index.js +8 -0
- package/dist/processors/producer_processor.d.ts +68 -0
- package/dist/processors/producer_processor.js +78 -0
- package/dist/processors/text_transformer.d.ts +30 -0
- package/dist/processors/text_transformer.js +48 -0
- package/dist/registry/index.d.ts +3 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/registry.d.ts +69 -0
- package/dist/registry/registry.js +149 -0
- package/dist/registry/types.d.ts +47 -0
- package/dist/registry/types.js +39 -0
- package/dist/serializers/base_serializer.d.ts +94 -0
- package/dist/serializers/base_serializer.js +82 -0
- package/dist/serializers/index.d.ts +2 -0
- package/dist/serializers/index.js +8 -0
- package/dist/services/ai_service.d.ts +145 -0
- package/dist/services/ai_service.js +262 -0
- package/dist/services/anthropic/index.d.ts +2 -0
- package/dist/services/anthropic/index.js +7 -0
- package/dist/services/assemblyai/index.d.ts +2 -0
- package/dist/services/assemblyai/index.js +7 -0
- package/dist/services/asyncai/index.d.ts +2 -0
- package/dist/services/asyncai/index.js +7 -0
- package/dist/services/aws/index.d.ts +2 -0
- package/dist/services/aws/index.js +7 -0
- package/dist/services/azure/index.d.ts +2 -0
- package/dist/services/azure/index.js +7 -0
- package/dist/services/baseten/index.d.ts +2 -0
- package/dist/services/baseten/index.js +7 -0
- package/dist/services/bland/index.d.ts +2 -0
- package/dist/services/bland/index.js +7 -0
- package/dist/services/camb/index.d.ts +2 -0
- package/dist/services/camb/index.js +7 -0
- package/dist/services/cartesia/index.d.ts +2 -0
- package/dist/services/cartesia/index.js +7 -0
- package/dist/services/cerebras/index.d.ts +2 -0
- package/dist/services/cerebras/index.js +7 -0
- package/dist/services/crusoe/index.d.ts +2 -0
- package/dist/services/crusoe/index.js +7 -0
- package/dist/services/deepgram/index.d.ts +2 -0
- package/dist/services/deepgram/index.js +7 -0
- package/dist/services/deepseek/index.d.ts +2 -0
- package/dist/services/deepseek/index.js +7 -0
- package/dist/services/elevenlabs/index.d.ts +2 -0
- package/dist/services/elevenlabs/index.js +7 -0
- package/dist/services/fal/index.d.ts +2 -0
- package/dist/services/fal/index.js +7 -0
- package/dist/services/fireworks/index.d.ts +2 -0
- package/dist/services/fireworks/index.js +7 -0
- package/dist/services/fish/index.d.ts +2 -0
- package/dist/services/fish/index.js +7 -0
- package/dist/services/funasr/index.d.ts +3 -0
- package/dist/services/funasr/index.js +8 -0
- package/dist/services/gladia/index.d.ts +2 -0
- package/dist/services/gladia/index.js +7 -0
- package/dist/services/google/index.d.ts +2 -0
- package/dist/services/google/index.js +7 -0
- package/dist/services/gradium/index.d.ts +2 -0
- package/dist/services/gradium/index.js +7 -0
- package/dist/services/grok/index.d.ts +2 -0
- package/dist/services/grok/index.js +7 -0
- package/dist/services/groq/index.d.ts +2 -0
- package/dist/services/groq/index.js +7 -0
- package/dist/services/heygen/index.d.ts +2 -0
- package/dist/services/heygen/index.js +7 -0
- package/dist/services/hume/index.d.ts +2 -0
- package/dist/services/hume/index.js +7 -0
- package/dist/services/image_service.d.ts +52 -0
- package/dist/services/image_service.js +60 -0
- package/dist/services/inception/index.d.ts +2 -0
- package/dist/services/inception/index.js +7 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +8 -0
- package/dist/services/inworld/index.d.ts +2 -0
- package/dist/services/inworld/index.js +7 -0
- package/dist/services/keenable/index.d.ts +2 -0
- package/dist/services/keenable/index.js +7 -0
- package/dist/services/kokoro/index.d.ts +2 -0
- package/dist/services/kokoro/index.js +7 -0
- package/dist/services/llm_service.d.ts +1106 -0
- package/dist/services/llm_service.js +2231 -0
- package/dist/services/mem0/index.d.ts +2 -0
- package/dist/services/mem0/index.js +7 -0
- package/dist/services/meta/index.d.ts +2 -0
- package/dist/services/meta/index.js +7 -0
- package/dist/services/minimax/index.d.ts +2 -0
- package/dist/services/minimax/index.js +7 -0
- package/dist/services/mistral/index.d.ts +2 -0
- package/dist/services/mistral/index.js +7 -0
- package/dist/services/moondream/index.d.ts +2 -0
- package/dist/services/moondream/index.js +7 -0
- package/dist/services/moonshine/index.d.ts +2 -0
- package/dist/services/moonshine/index.js +7 -0
- package/dist/services/nebius/index.d.ts +2 -0
- package/dist/services/nebius/index.js +7 -0
- package/dist/services/neuphonic/index.d.ts +2 -0
- package/dist/services/neuphonic/index.js +7 -0
- package/dist/services/novita/index.d.ts +2 -0
- package/dist/services/novita/index.js +7 -0
- package/dist/services/nvidia/index.d.ts +2 -0
- package/dist/services/nvidia/index.js +11 -0
- package/dist/services/ollama/index.d.ts +2 -0
- package/dist/services/ollama/index.js +7 -0
- package/dist/services/openai/index.d.ts +2 -0
- package/dist/services/openai/index.js +7 -0
- package/dist/services/openclaw/index.d.ts +14 -0
- package/dist/services/openclaw/index.js +19 -0
- package/dist/services/openrouter/index.d.ts +2 -0
- package/dist/services/openrouter/index.js +7 -0
- package/dist/services/perplexity/index.d.ts +2 -0
- package/dist/services/perplexity/index.js +7 -0
- package/dist/services/piper/index.d.ts +2 -0
- package/dist/services/piper/index.js +7 -0
- package/dist/services/pocket_tts/index.d.ts +2 -0
- package/dist/services/pocket_tts/index.js +7 -0
- package/dist/services/qwen/index.d.ts +2 -0
- package/dist/services/qwen/index.js +7 -0
- package/dist/services/resembleai/index.d.ts +2 -0
- package/dist/services/resembleai/index.js +7 -0
- package/dist/services/rime/index.d.ts +2 -0
- package/dist/services/rime/index.js +7 -0
- package/dist/services/sambanova/index.d.ts +2 -0
- package/dist/services/sambanova/index.js +7 -0
- package/dist/services/sarvam/index.d.ts +2 -0
- package/dist/services/sarvam/index.js +7 -0
- package/dist/services/settings.d.ts +356 -0
- package/dist/services/settings.js +437 -0
- package/dist/services/simli/index.d.ts +2 -0
- package/dist/services/simli/index.js +7 -0
- package/dist/services/smallest/index.d.ts +2 -0
- package/dist/services/smallest/index.js +7 -0
- package/dist/services/soniox/index.d.ts +2 -0
- package/dist/services/soniox/index.js +7 -0
- package/dist/services/speechify/index.d.ts +2 -0
- package/dist/services/speechify/index.js +7 -0
- package/dist/services/speechmatics/index.d.ts +2 -0
- package/dist/services/speechmatics/index.js +7 -0
- package/dist/services/stt_latency.d.ts +62 -0
- package/dist/services/stt_latency.js +71 -0
- package/dist/services/stt_service.d.ts +601 -0
- package/dist/services/stt_service.js +1044 -0
- package/dist/services/tavus/index.d.ts +2 -0
- package/dist/services/tavus/index.js +7 -0
- package/dist/services/together/index.d.ts +2 -0
- package/dist/services/together/index.js +7 -0
- package/dist/services/tts_service.d.ts +909 -0
- package/dist/services/tts_service.js +2018 -0
- package/dist/services/ultravox/index.d.ts +2 -0
- package/dist/services/ultravox/index.js +9 -0
- package/dist/services/vision_service.d.ts +56 -0
- package/dist/services/vision_service.js +62 -0
- package/dist/services/websocket_service.d.ts +213 -0
- package/dist/services/websocket_service.js +654 -0
- package/dist/services/whisper/index.d.ts +2 -0
- package/dist/services/whisper/index.js +9 -0
- package/dist/services/xai/index.d.ts +2 -0
- package/dist/services/xai/index.js +9 -0
- package/dist/services/xtts/index.d.ts +2 -0
- package/dist/services/xtts/index.js +9 -0
- package/dist/tests/index.d.ts +2 -0
- package/dist/tests/index.js +8 -0
- package/dist/tests/utils.d.ts +123 -0
- package/dist/tests/utils.js +212 -0
- package/dist/transcriptions/index.d.ts +2 -0
- package/dist/transcriptions/index.js +8 -0
- package/dist/transcriptions/language.d.ts +376 -0
- package/dist/transcriptions/language.js +543 -0
- package/dist/transports/base_input.d.ts +149 -0
- package/dist/transports/base_input.js +338 -0
- package/dist/transports/base_output.d.ts +432 -0
- package/dist/transports/base_output.js +1231 -0
- package/dist/transports/base_transport.d.ts +223 -0
- package/dist/transports/base_transport.js +167 -0
- package/dist/transports/daily/index.d.ts +2 -0
- package/dist/transports/daily/index.js +9 -0
- package/dist/transports/heygen/index.d.ts +2 -0
- package/dist/transports/heygen/index.js +9 -0
- package/dist/transports/index.d.ts +2 -0
- package/dist/transports/index.js +8 -0
- package/dist/transports/lemonslice/index.d.ts +2 -0
- package/dist/transports/lemonslice/index.js +9 -0
- package/dist/transports/livekit/index.d.ts +2 -0
- package/dist/transports/livekit/index.js +9 -0
- package/dist/transports/local/index.d.ts +2 -0
- package/dist/transports/local/index.js +9 -0
- package/dist/transports/moq/index.d.ts +2 -0
- package/dist/transports/moq/index.js +9 -0
- package/dist/transports/smallwebrtc/index.d.ts +2 -0
- package/dist/transports/smallwebrtc/index.js +9 -0
- package/dist/transports/tavus/index.d.ts +2 -0
- package/dist/transports/tavus/index.js +9 -0
- package/dist/transports/video_in_sampler.d.ts +157 -0
- package/dist/transports/video_in_sampler.js +258 -0
- package/dist/transports/vonage/index.d.ts +2 -0
- package/dist/transports/vonage/index.js +9 -0
- package/dist/transports/websocket/index.d.ts +2 -0
- package/dist/transports/websocket/index.js +9 -0
- package/dist/transports/whatsapp/index.d.ts +2 -0
- package/dist/transports/whatsapp/index.js +9 -0
- package/dist/turns/eager_end_of_turn_mixin.d.ts +70 -0
- package/dist/turns/eager_end_of_turn_mixin.js +122 -0
- package/dist/turns/empty_user_turn.d.ts +55 -0
- package/dist/turns/empty_user_turn.js +53 -0
- package/dist/turns/index.d.ts +2 -0
- package/dist/turns/index.js +8 -0
- package/dist/turns/speculation_gate.d.ts +169 -0
- package/dist/turns/speculation_gate.js +294 -0
- package/dist/turns/types.d.ts +33 -0
- package/dist/turns/types.js +35 -0
- package/dist/turns/user_idle_controller.d.ts +94 -0
- package/dist/turns/user_idle_controller.js +187 -0
- package/dist/turns/user_mute/always_user_mute_strategy.d.ts +15 -0
- package/dist/turns/user_mute/always_user_mute_strategy.js +29 -0
- package/dist/turns/user_mute/base_user_mute_strategy.d.ts +39 -0
- package/dist/turns/user_mute/base_user_mute_strategy.js +45 -0
- package/dist/turns/user_mute/first_speech_user_mute_strategy.d.ts +28 -0
- package/dist/turns/user_mute/first_speech_user_mute_strategy.js +52 -0
- package/dist/turns/user_mute/function_call_user_mute_strategy.d.ts +25 -0
- package/dist/turns/user_mute/function_call_user_mute_strategy.js +50 -0
- package/dist/turns/user_mute/index.d.ts +6 -0
- package/dist/turns/user_mute/index.js +11 -0
- package/dist/turns/user_mute/mute_until_first_bot_complete_user_mute_strategy.d.ts +43 -0
- package/dist/turns/user_mute/mute_until_first_bot_complete_user_mute_strategy.js +76 -0
- package/dist/turns/user_start/base_user_turn_start_strategy.d.ts +135 -0
- package/dist/turns/user_start/base_user_turn_start_strategy.js +134 -0
- package/dist/turns/user_start/external_user_turn_start_strategy.d.ts +45 -0
- package/dist/turns/user_start/external_user_turn_start_strategy.js +64 -0
- package/dist/turns/user_start/index.d.ts +8 -0
- package/dist/turns/user_start/index.js +16 -0
- package/dist/turns/user_start/krisp_viva_ip_user_turn_start_strategy.d.ts +133 -0
- package/dist/turns/user_start/krisp_viva_ip_user_turn_start_strategy.js +243 -0
- package/dist/turns/user_start/min_words_user_turn_start_strategy.d.ts +60 -0
- package/dist/turns/user_start/min_words_user_turn_start_strategy.js +102 -0
- package/dist/turns/user_start/transcription_user_turn_start_strategy.d.ts +29 -0
- package/dist/turns/user_start/transcription_user_turn_start_strategy.js +43 -0
- package/dist/turns/user_start/vad_user_turn_start_strategy.d.ts +20 -0
- package/dist/turns/user_start/vad_user_turn_start_strategy.js +31 -0
- package/dist/turns/user_start/wake_phrase_user_turn_start_strategy.d.ts +141 -0
- package/dist/turns/user_start/wake_phrase_user_turn_start_strategy.js +238 -0
- package/dist/turns/user_stop/base_user_turn_stop_strategy.d.ts +174 -0
- package/dist/turns/user_stop/base_user_turn_stop_strategy.js +170 -0
- package/dist/turns/user_stop/deferred_user_turn_stop_strategy.d.ts +81 -0
- package/dist/turns/user_stop/deferred_user_turn_stop_strategy.js +107 -0
- package/dist/turns/user_stop/eager_match_policy.d.ts +36 -0
- package/dist/turns/user_stop/eager_match_policy.js +50 -0
- package/dist/turns/user_stop/eager_user_turn_stop_strategy.d.ts +84 -0
- package/dist/turns/user_stop/eager_user_turn_stop_strategy.js +154 -0
- package/dist/turns/user_stop/external_user_turn_completion_stop_strategy.d.ts +45 -0
- package/dist/turns/user_stop/external_user_turn_completion_stop_strategy.js +55 -0
- package/dist/turns/user_stop/external_user_turn_stop_strategy.d.ts +115 -0
- package/dist/turns/user_stop/external_user_turn_stop_strategy.js +205 -0
- package/dist/turns/user_stop/index.d.ts +10 -0
- package/dist/turns/user_stop/index.js +15 -0
- package/dist/turns/user_stop/llm_turn_completion_user_turn_stop_strategy.d.ts +44 -0
- package/dist/turns/user_stop/llm_turn_completion_user_turn_stop_strategy.js +59 -0
- package/dist/turns/user_stop/speech_timeout_user_turn_stop_strategy.d.ts +140 -0
- package/dist/turns/user_stop/speech_timeout_user_turn_stop_strategy.js +303 -0
- package/dist/turns/user_stop/turn_analyzer_user_turn_stop_strategy.d.ts +135 -0
- package/dist/turns/user_stop/turn_analyzer_user_turn_stop_strategy.js +332 -0
- package/dist/turns/user_turn_completion_mixin.d.ts +147 -0
- package/dist/turns/user_turn_completion_mixin.js +591 -0
- package/dist/turns/user_turn_controller.d.ts +134 -0
- package/dist/turns/user_turn_controller.js +335 -0
- package/dist/turns/user_turn_processor.d.ts +87 -0
- package/dist/turns/user_turn_processor.js +180 -0
- package/dist/turns/user_turn_strategies.d.ts +187 -0
- package/dist/turns/user_turn_strategies.js +222 -0
- package/dist/utils/async_tool_cancellation.d.ts +35 -0
- package/dist/utils/async_tool_cancellation.js +78 -0
- package/dist/utils/asyncio/index.d.ts +2 -0
- package/dist/utils/asyncio/index.js +7 -0
- package/dist/utils/asyncio/task_manager.d.ts +49 -0
- package/dist/utils/asyncio/task_manager.js +105 -0
- package/dist/utils/base_object.d.ts +76 -0
- package/dist/utils/base_object.js +154 -0
- package/dist/utils/context/aggregated_frame_sequencer.d.ts +491 -0
- package/dist/utils/context/aggregated_frame_sequencer.js +803 -0
- package/dist/utils/context/audio_context_manager.d.ts +131 -0
- package/dist/utils/context/audio_context_manager.js +233 -0
- package/dist/utils/context/index.d.ts +2 -0
- package/dist/utils/context/index.js +7 -0
- package/dist/utils/context/llm_context_summarization.d.ts +258 -0
- package/dist/utils/context/llm_context_summarization.js +511 -0
- package/dist/utils/context/text_segment_map.d.ts +611 -0
- package/dist/utils/context/text_segment_map.js +1132 -0
- package/dist/utils/context/word_completion_tracker.d.ts +273 -0
- package/dist/utils/context/word_completion_tracker.js +441 -0
- package/dist/utils/context/word_timestamp_tracker.d.ts +72 -0
- package/dist/utils/context/word_timestamp_tracker.js +98 -0
- package/dist/utils/deprecation.d.ts +28 -0
- package/dist/utils/deprecation.js +75 -0
- package/dist/utils/env.d.ts +38 -0
- package/dist/utils/env.js +62 -0
- package/dist/utils/errors.d.ts +75 -0
- package/dist/utils/errors.js +202 -0
- package/dist/utils/file_resolver.d.ts +126 -0
- package/dist/utils/file_resolver.js +314 -0
- package/dist/utils/file_storage.d.ts +99 -0
- package/dist/utils/file_storage.js +100 -0
- package/dist/utils/frame_queue.d.ts +36 -0
- package/dist/utils/frame_queue.js +66 -0
- package/dist/utils/http.d.ts +39 -0
- package/dist/utils/http.js +53 -0
- package/dist/utils/image.d.ts +15 -0
- package/dist/utils/image.js +30 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/log_config.d.ts +34 -0
- package/dist/utils/log_config.js +76 -0
- package/dist/utils/logger.d.ts +40 -0
- package/dist/utils/logger.js +91 -0
- package/dist/utils/mixin.d.ts +14 -0
- package/dist/utils/mixin.js +63 -0
- package/dist/utils/network.d.ts +73 -0
- package/dist/utils/network.js +90 -0
- package/dist/utils/security/allowed_origins.d.ts +16 -0
- package/dist/utils/security/allowed_origins.js +34 -0
- package/dist/utils/security/index.d.ts +2 -0
- package/dist/utils/security/index.js +7 -0
- package/dist/utils/security/redaction.d.ts +27 -0
- package/dist/utils/security/redaction.js +123 -0
- package/dist/utils/security/ssrf.d.ts +79 -0
- package/dist/utils/security/ssrf.js +327 -0
- package/dist/utils/shared.d.ts +35 -0
- package/dist/utils/shared.js +136 -0
- package/dist/utils/startup.d.ts +17 -0
- package/dist/utils/startup.js +130 -0
- package/dist/utils/string.d.ts +116 -0
- package/dist/utils/string.js +460 -0
- package/dist/utils/sync/base_notifier.d.ts +25 -0
- package/dist/utils/sync/base_notifier.js +16 -0
- package/dist/utils/sync/event_notifier.d.ts +38 -0
- package/dist/utils/sync/event_notifier.js +51 -0
- package/dist/utils/sync/index.d.ts +2 -0
- package/dist/utils/sync/index.js +7 -0
- package/dist/utils/text/alnum_utils.d.ts +109 -0
- package/dist/utils/text/alnum_utils.js +262 -0
- package/dist/utils/text/base_text_aggregator.d.ts +146 -0
- package/dist/utils/text/base_text_aggregator.js +102 -0
- package/dist/utils/text/base_text_filter.d.ts +54 -0
- package/dist/utils/text/base_text_filter.js +50 -0
- package/dist/utils/text/index.d.ts +2 -0
- package/dist/utils/text/index.js +7 -0
- package/dist/utils/text/markdown_text_filter.d.ts +147 -0
- package/dist/utils/text/markdown_text_filter.js +522 -0
- package/dist/utils/text/markup_utils.d.ts +54 -0
- package/dist/utils/text/markup_utils.js +156 -0
- package/dist/utils/text/pattern_pair_aggregator.d.ts +251 -0
- package/dist/utils/text/pattern_pair_aggregator.js +478 -0
- package/dist/utils/text/phonemes.d.ts +60 -0
- package/dist/utils/text/phonemes.js +172 -0
- package/dist/utils/text/simple_text_aggregator.d.ts +135 -0
- package/dist/utils/text/simple_text_aggregator.js +254 -0
- package/dist/utils/text/skip_tags_aggregator.d.ts +85 -0
- package/dist/utils/text/skip_tags_aggregator.js +147 -0
- package/dist/utils/text/transforms/pronunciations.d.ts +65 -0
- package/dist/utils/text/transforms/pronunciations.js +111 -0
- package/dist/utils/text/word_timestamp_utils.d.ts +26 -0
- package/dist/utils/text/word_timestamp_utils.js +52 -0
- package/dist/utils/time.d.ts +13 -0
- package/dist/utils/time.js +31 -0
- package/dist/utils/tracing/index.d.ts +3 -0
- package/dist/utils/tracing/index.js +8 -0
- package/dist/utils/tracing/service_attributes.d.ts +198 -0
- package/dist/utils/tracing/service_attributes.js +434 -0
- package/dist/utils/tracing/service_decorators.d.ts +214 -0
- package/dist/utils/tracing/service_decorators.js +1662 -0
- package/dist/utils/tracing/setup.d.ts +95 -0
- package/dist/utils/tracing/setup.js +110 -0
- package/dist/utils/tracing/tracing_context.d.ts +55 -0
- package/dist/utils/tracing/tracing_context.js +97 -0
- package/dist/utils/tracing/turn_trace_observer.d.ts +90 -0
- package/dist/utils/tracing/turn_trace_observer.js +219 -0
- package/dist/utils/types.d.ts +80 -0
- package/dist/utils/types.js +108 -0
- package/dist/utils/utils.d.ts +5 -0
- package/dist/utils/utils.js +22 -0
- package/dist/utils/yaml.d.ts +64 -0
- package/dist/utils/yaml.js +41 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.js +7 -0
- package/dist/workers/base_worker.d.ts +772 -0
- package/dist/workers/base_worker.js +1298 -0
- package/dist/workers/index.d.ts +2 -0
- package/dist/workers/index.js +8 -0
- package/dist/workers/llm/backend_llm_worker.d.ts +552 -0
- package/dist/workers/llm/backend_llm_worker.js +1055 -0
- package/dist/workers/llm/index.d.ts +6 -0
- package/dist/workers/llm/index.js +11 -0
- package/dist/workers/llm/llm_context_worker.d.ts +66 -0
- package/dist/workers/llm/llm_context_worker.js +72 -0
- package/dist/workers/llm/llm_worker.d.ts +180 -0
- package/dist/workers/llm/llm_worker.js +323 -0
- package/dist/workers/llm/tool_decorator.d.ts +68 -0
- package/dist/workers/llm/tool_decorator.js +60 -0
- package/dist/workers/runner.d.ts +268 -0
- package/dist/workers/runner.js +489 -0
- package/dist/workers/ui/index.d.ts +22 -0
- package/dist/workers/ui/index.js +27 -0
- package/dist/workers/ui/ui_event_decorator.d.ts +43 -0
- package/dist/workers/ui/ui_event_decorator.js +75 -0
- package/dist/workers/ui/ui_job_context.d.ts +12 -0
- package/dist/workers/ui/ui_job_context.js +17 -0
- package/dist/workers/ui/ui_prompts.d.ts +21 -0
- package/dist/workers/ui/ui_prompts.js +41 -0
- package/dist/workers/ui/ui_tools.d.ts +32 -0
- package/dist/workers/ui/ui_tools.js +112 -0
- package/dist/workers/ui/ui_worker.d.ts +571 -0
- package/dist/workers/ui/ui_worker.js +1156 -0
- package/package.json +46 -3
- package/README.md +0 -5
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026, Daily
|
|
2
|
+
// Copyright (c) 2026, pipedog contributors
|
|
3
|
+
// SPDX-License-Identifier: BSD-2-Clause
|
|
4
|
+
//
|
|
5
|
+
// Ported from pipecat: src/pipecat/turns/user_turn_processor.py
|
|
6
|
+
/** Frame processor for managing the user turn lifecycle. */
|
|
7
|
+
import { CancelFrame, EagerEndOfTurnCancelFrame, EndFrame, ProposedUserStartedSpeakingFrame, ProposedUserStoppedSpeakingFrame, StartFrame, UserStartedSpeakingFrame, UserStoppedSpeakingFrame, } from "../frames/frames.js";
|
|
8
|
+
import { FrameDirection, FrameProcessor, } from "../processors/frame_processor.js";
|
|
9
|
+
import { logger } from "../utils/logger.js";
|
|
10
|
+
import { UserIdleController } from "./user_idle_controller.js";
|
|
11
|
+
import { UserTurnController } from "./user_turn_controller.js";
|
|
12
|
+
import { UserTurnStrategies } from "./user_turn_strategies.js";
|
|
13
|
+
/**
|
|
14
|
+
* Frame processor for managing the user turn lifecycle.
|
|
15
|
+
*
|
|
16
|
+
* This processor uses a turn controller to determine when a user turn starts
|
|
17
|
+
* or stops. The actual frames emitted (e.g., UserStartedSpeakingFrame,
|
|
18
|
+
* UserStoppedSpeakingFrame) or interruptions depend on the configured
|
|
19
|
+
* strategies.
|
|
20
|
+
*
|
|
21
|
+
* Event handlers available:
|
|
22
|
+
*
|
|
23
|
+
* - on_user_turn_started: Emitted when a user turn starts.
|
|
24
|
+
* - on_user_turn_inference_triggered: Emitted when enough signal exists to
|
|
25
|
+
* start LLM inference. Fires together with `on_user_turn_stopped` for most
|
|
26
|
+
* strategies; fires alone when a downstream strategy gates finalization on
|
|
27
|
+
* the LLM's verdict.
|
|
28
|
+
* - on_user_turn_stopped: Emitted when a user turn is semantically final.
|
|
29
|
+
* - on_user_turn_stop_timeout: Emitted if no stop strategy triggers before timeout.
|
|
30
|
+
* - on_user_turn_idle: Emitted when the user has been idle for the configured timeout.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* processor.eventHandler("on_user_turn_started", async (processor, strategy) => { ... });
|
|
34
|
+
* processor.eventHandler("on_user_turn_inference_triggered", async (processor, strategy) => { ... });
|
|
35
|
+
* processor.eventHandler("on_user_turn_stopped", async (processor, strategy) => { ... });
|
|
36
|
+
* processor.eventHandler("on_user_turn_stop_timeout", async (processor) => { ... });
|
|
37
|
+
* processor.eventHandler("on_user_turn_idle", async (processor) => { ... });
|
|
38
|
+
*/
|
|
39
|
+
export class UserTurnProcessor extends FrameProcessor {
|
|
40
|
+
_userTurnController;
|
|
41
|
+
_userIdleController;
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
super(options);
|
|
44
|
+
this._registerEventHandler("on_user_turn_started");
|
|
45
|
+
this._registerEventHandler("on_user_turn_stopped");
|
|
46
|
+
this._registerEventHandler("on_user_turn_stop_timeout");
|
|
47
|
+
this._registerEventHandler("on_user_turn_idle");
|
|
48
|
+
this._registerEventHandler("on_user_turn_inference_triggered");
|
|
49
|
+
this._userTurnController = new UserTurnController({
|
|
50
|
+
userTurnStrategies: options.userTurnStrategies ?? new UserTurnStrategies(),
|
|
51
|
+
userTurnStopTimeout: options.userTurnStopTimeout ?? 5.0,
|
|
52
|
+
});
|
|
53
|
+
this._userTurnController.addEventHandler("on_push_frame", (_c, frame, direction) => this._onPushFrame(frame, direction));
|
|
54
|
+
this._userTurnController.addEventHandler("on_broadcast_frame", (_c, frameCls, frameOptions) => this._onBroadcastFrame(frameCls, frameOptions));
|
|
55
|
+
this._userTurnController.addEventHandler("on_user_turn_speculation_cancelled", (c) => this._onUserTurnSpeculationCancelled(c));
|
|
56
|
+
this._userTurnController.addEventHandler("on_user_turn_started", (c, strategy, params) => this._onUserTurnStarted(c, strategy, params));
|
|
57
|
+
this._userTurnController.addEventHandler("on_user_turn_stopped", (c, strategy, params) => this._onUserTurnStopped(c, strategy, params));
|
|
58
|
+
this._userTurnController.addEventHandler("on_user_turn_stop_timeout", (c) => this._onUserTurnStopTimeout(c));
|
|
59
|
+
this._userTurnController.addEventHandler("on_user_turn_inference_triggered", (c, strategy, speculation) => this._onUserTurnInferenceTriggered(c, strategy, speculation));
|
|
60
|
+
this._userIdleController = new UserIdleController({
|
|
61
|
+
userIdleTimeout: options.userIdleTimeout ?? 0,
|
|
62
|
+
});
|
|
63
|
+
this._userIdleController.addEventHandler("on_user_turn_idle", (c) => this._onUserTurnIdle(c));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Set up the processor.
|
|
67
|
+
*
|
|
68
|
+
* @param setup Configuration object containing setup parameters.
|
|
69
|
+
*/
|
|
70
|
+
async setup(setup) {
|
|
71
|
+
await super.setup(setup);
|
|
72
|
+
await this._userTurnController.setup(setup);
|
|
73
|
+
await this._userIdleController.setup(setup);
|
|
74
|
+
}
|
|
75
|
+
/** Clean up processor resources. */
|
|
76
|
+
async cleanup() {
|
|
77
|
+
await super.cleanup();
|
|
78
|
+
await this._cleanup();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Process an incoming frame to detect user turn start or stop.
|
|
82
|
+
*
|
|
83
|
+
* The frame is passed to the user turn controller which is responsible for
|
|
84
|
+
* deciding when a user turn starts or stops and emitting the corresponding
|
|
85
|
+
* events.
|
|
86
|
+
*
|
|
87
|
+
* @param frame The frame to be processed.
|
|
88
|
+
* @param direction The direction of the incoming frame.
|
|
89
|
+
*/
|
|
90
|
+
async processFrame(frame, direction) {
|
|
91
|
+
await super.processFrame(frame, direction);
|
|
92
|
+
if (frame instanceof StartFrame) {
|
|
93
|
+
await this.pushFrame(frame, direction);
|
|
94
|
+
await this._userTurnController.start();
|
|
95
|
+
}
|
|
96
|
+
else if (frame instanceof EndFrame) {
|
|
97
|
+
// Push EndFrame before stop(), because stop() waits on the task to
|
|
98
|
+
// finish and the task finishes when EndFrame is processed.
|
|
99
|
+
await this.pushFrame(frame, direction);
|
|
100
|
+
await this._stop(frame);
|
|
101
|
+
}
|
|
102
|
+
else if (frame instanceof CancelFrame) {
|
|
103
|
+
await this._cancel(frame);
|
|
104
|
+
await this.pushFrame(frame, direction);
|
|
105
|
+
}
|
|
106
|
+
else if (frame instanceof ProposedUserStartedSpeakingFrame) {
|
|
107
|
+
// A proposal is resolved once. Forwarding one our own strategies
|
|
108
|
+
// resolve would let a resolver further down the pipeline decide the
|
|
109
|
+
// same turn a second time.
|
|
110
|
+
if (!this._userTurnController.resolvesProposedTurnStartFrames) {
|
|
111
|
+
await this.pushFrame(frame, direction);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (frame instanceof ProposedUserStoppedSpeakingFrame) {
|
|
115
|
+
if (!this._userTurnController.resolvesProposedTurnStopFrames) {
|
|
116
|
+
await this.pushFrame(frame, direction);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
await this.pushFrame(frame, direction);
|
|
121
|
+
}
|
|
122
|
+
await this._userTurnController.processFrame(frame);
|
|
123
|
+
await this._userIdleController.processFrame(frame);
|
|
124
|
+
}
|
|
125
|
+
async _stop(_frame) {
|
|
126
|
+
await this._stopControllers();
|
|
127
|
+
}
|
|
128
|
+
async _cancel(_frame) {
|
|
129
|
+
await this._stopControllers();
|
|
130
|
+
}
|
|
131
|
+
async _stopControllers() {
|
|
132
|
+
// Session end stops the controllers' timers; what they hold may be
|
|
133
|
+
// shared, so releasing it waits for cleanup().
|
|
134
|
+
await this._userTurnController.stop();
|
|
135
|
+
await this._userIdleController.stop();
|
|
136
|
+
}
|
|
137
|
+
async _cleanup() {
|
|
138
|
+
await this._userTurnController.cleanup();
|
|
139
|
+
await this._userIdleController.cleanup();
|
|
140
|
+
}
|
|
141
|
+
async _onPushFrame(frame, direction = FrameDirection.DOWNSTREAM) {
|
|
142
|
+
await this.pushFrame(frame, direction);
|
|
143
|
+
}
|
|
144
|
+
async _onBroadcastFrame(frameCls, options) {
|
|
145
|
+
await this.broadcastFrame(frameCls, options);
|
|
146
|
+
}
|
|
147
|
+
async _onUserTurnSpeculationCancelled(_controller) {
|
|
148
|
+
await this.broadcastFrame(EagerEndOfTurnCancelFrame);
|
|
149
|
+
}
|
|
150
|
+
async _onUserTurnStarted(_controller, strategy, params) {
|
|
151
|
+
logger.debug(`${this}: User started speaking (strategy: ${strategy})`);
|
|
152
|
+
if (params.enableUserSpeakingFrames) {
|
|
153
|
+
await this.broadcastFrame(UserStartedSpeakingFrame);
|
|
154
|
+
}
|
|
155
|
+
await this._userIdleController.processFrame(new UserStartedSpeakingFrame());
|
|
156
|
+
if (params.enableInterruptions) {
|
|
157
|
+
await this.broadcastInterruption();
|
|
158
|
+
}
|
|
159
|
+
await this._callEventHandler("on_user_turn_started", strategy);
|
|
160
|
+
}
|
|
161
|
+
async _onUserTurnStopped(_controller, strategy, params) {
|
|
162
|
+
logger.debug(`${this}: User stopped speaking (strategy: ${strategy})`);
|
|
163
|
+
if (params.enableUserSpeakingFrames) {
|
|
164
|
+
await this.broadcastFrame(UserStoppedSpeakingFrame);
|
|
165
|
+
}
|
|
166
|
+
await this._userIdleController.processFrame(new UserStoppedSpeakingFrame());
|
|
167
|
+
await this._callEventHandler("on_user_turn_stopped", strategy);
|
|
168
|
+
}
|
|
169
|
+
async _onUserTurnStopTimeout(_controller) {
|
|
170
|
+
await this._callEventHandler("on_user_turn_stop_timeout");
|
|
171
|
+
}
|
|
172
|
+
async _onUserTurnIdle(_controller) {
|
|
173
|
+
await this._callEventHandler("on_user_turn_idle");
|
|
174
|
+
}
|
|
175
|
+
async _onUserTurnInferenceTriggered(_controller, strategy, _speculation) {
|
|
176
|
+
logger.debug(`${this}: User turn inference triggered (strategy: ${strategy})`);
|
|
177
|
+
await this._callEventHandler("on_user_turn_inference_triggered", strategy);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=user_turn_processor.js.map
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { type BaseUserTurnStartStrategy } from "./user_start/index.ts";
|
|
2
|
+
import { type BaseUserTurnStopStrategy, type EagerMatchPolicy } from "./user_stop/index.ts";
|
|
3
|
+
import type { UserTurnCompletionConfig } from "./user_turn_completion_mixin.ts";
|
|
4
|
+
/**
|
|
5
|
+
* Return the default user turn start strategies.
|
|
6
|
+
*
|
|
7
|
+
* Returns `[VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]`.
|
|
8
|
+
* Useful when building a custom strategy list that extends the defaults.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const startStrategies = [
|
|
12
|
+
* new WakePhraseUserTurnStartStrategy({ phrases: ["hey pipecat"] }),
|
|
13
|
+
* ...defaultUserTurnStartStrategies(),
|
|
14
|
+
* ];
|
|
15
|
+
*/
|
|
16
|
+
export declare function defaultUserTurnStartStrategies(): BaseUserTurnStartStrategy[];
|
|
17
|
+
/**
|
|
18
|
+
* Return the default user turn stop strategies.
|
|
19
|
+
*
|
|
20
|
+
* Returns `[TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]`.
|
|
21
|
+
* Useful when building a custom strategy list that extends the defaults.
|
|
22
|
+
*/
|
|
23
|
+
export declare function defaultUserTurnStopStrategies(): BaseUserTurnStopStrategy[];
|
|
24
|
+
export interface UserTurnStrategiesOptions {
|
|
25
|
+
/**
|
|
26
|
+
* A list of user turn start strategies used to detect when the user starts
|
|
27
|
+
* speaking.
|
|
28
|
+
*/
|
|
29
|
+
start?: BaseUserTurnStartStrategy[] | null;
|
|
30
|
+
/**
|
|
31
|
+
* A list of user turn stop strategies used to decide when the user stops
|
|
32
|
+
* speaking.
|
|
33
|
+
*/
|
|
34
|
+
stop?: BaseUserTurnStopStrategy[] | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Container for user turn start and stop strategies.
|
|
38
|
+
*
|
|
39
|
+
* If no strategies are specified, the following defaults are used:
|
|
40
|
+
*
|
|
41
|
+
* start: [VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]
|
|
42
|
+
* stop: [TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]
|
|
43
|
+
*
|
|
44
|
+
* - `start`: A list of user turn start strategies used to detect when the
|
|
45
|
+
* user starts speaking.
|
|
46
|
+
* - `stop`: A list of user turn stop strategies used to decide when the user
|
|
47
|
+
* stops speaking.
|
|
48
|
+
*/
|
|
49
|
+
export declare class UserTurnStrategies {
|
|
50
|
+
start: BaseUserTurnStartStrategy[];
|
|
51
|
+
stop: BaseUserTurnStopStrategy[];
|
|
52
|
+
constructor(options?: UserTurnStrategiesOptions);
|
|
53
|
+
protected _postInit(): void;
|
|
54
|
+
}
|
|
55
|
+
export interface ExternalUserTurnStrategiesOptions extends UserTurnStrategiesOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Whether to broadcast an interruption when a proposal starts a turn.
|
|
58
|
+
* Services route their `should_interrupt` setting here.
|
|
59
|
+
*/
|
|
60
|
+
enableInterruptions?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Container for turn strategies driven by another component in the pipeline.
|
|
64
|
+
*
|
|
65
|
+
* Preconfigures UserTurnStrategies with ExternalUserTurnStartStrategy and
|
|
66
|
+
* ExternalUserTurnStopStrategy, so a service with its own turn detection — or
|
|
67
|
+
* a shared UserTurnProcessor — controls when user turns start and stop.
|
|
68
|
+
*
|
|
69
|
+
* What the aggregator emits depends on which signal drives the turn.
|
|
70
|
+
* `ProposedUserStarted/StoppedSpeakingFrame` leaves the decision here, so the
|
|
71
|
+
* aggregator pushes the turn frames and broadcasts interruptions.
|
|
72
|
+
* `UserStarted/StoppedSpeakingFrame` means the emitter already announced the
|
|
73
|
+
* turn, so the aggregator emits nothing and the parameter below doesn't apply.
|
|
74
|
+
*
|
|
75
|
+
* - `enableInterruptions`: Whether to broadcast an interruption when a
|
|
76
|
+
* proposal starts a turn. Services route their `should_interrupt` setting
|
|
77
|
+
* here.
|
|
78
|
+
*/
|
|
79
|
+
export declare class ExternalUserTurnStrategies extends UserTurnStrategies {
|
|
80
|
+
enableInterruptions: boolean;
|
|
81
|
+
constructor(options?: ExternalUserTurnStrategiesOptions);
|
|
82
|
+
protected _postInit(): void;
|
|
83
|
+
}
|
|
84
|
+
export interface FilterIncompleteUserTurnStrategiesOptions extends UserTurnStrategiesOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Optional configuration applied to the LLM via the
|
|
87
|
+
* `filter_incomplete_user_turns` setting. Customizes the turn-completion
|
|
88
|
+
* instructions, incomplete-turn timeouts, and re-prompts. If null, defaults
|
|
89
|
+
* from UserTurnCompletionConfig are used.
|
|
90
|
+
*/
|
|
91
|
+
config?: UserTurnCompletionConfig | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Stop strategies gated on the LLM's turn-completion verdict.
|
|
95
|
+
*
|
|
96
|
+
* The LLM is asked to begin every response with one of three markers: ●
|
|
97
|
+
* (complete), ◐ (incomplete short), or ○ (incomplete long). Only ● finalizes
|
|
98
|
+
* the user turn; ◐ / ○ keep the turn open so the user can continue speaking
|
|
99
|
+
* and the LLM can re-evaluate later.
|
|
100
|
+
*
|
|
101
|
+
* Configuring strategies this way preserves the existing detector chain
|
|
102
|
+
* (defaults or user-supplied) for inference triggering and appends
|
|
103
|
+
* LLMTurnCompletionUserTurnStopStrategy as the finalizer. The detector
|
|
104
|
+
* strategies are wrapped with `deferred()` automatically so they fire only
|
|
105
|
+
* `on_user_turn_inference_triggered` and leave finalization to the LLM gate.
|
|
106
|
+
*
|
|
107
|
+
* - `config`: Optional configuration applied to the LLM via the
|
|
108
|
+
* `filter_incomplete_user_turns` setting. Customizes the turn-completion
|
|
109
|
+
* instructions, incomplete-turn timeouts, and re-prompts. If null, defaults
|
|
110
|
+
* from UserTurnCompletionConfig are used.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies()
|
|
114
|
+
*
|
|
115
|
+
* // Custom detector chain:
|
|
116
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies({
|
|
117
|
+
* stop: [new SpeechTimeoutUserTurnStopStrategy({ ... })],
|
|
118
|
+
* })
|
|
119
|
+
*
|
|
120
|
+
* // Custom completion config:
|
|
121
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies({
|
|
122
|
+
* config: new UserTurnCompletionConfig({
|
|
123
|
+
* incompleteShortTimeout: 5.0,
|
|
124
|
+
* incompleteLongTimeout: 10.0,
|
|
125
|
+
* }),
|
|
126
|
+
* })
|
|
127
|
+
*/
|
|
128
|
+
export declare class FilterIncompleteUserTurnStrategies extends UserTurnStrategies {
|
|
129
|
+
config: UserTurnCompletionConfig | null;
|
|
130
|
+
constructor(options?: FilterIncompleteUserTurnStrategiesOptions);
|
|
131
|
+
protected _postInit(): void;
|
|
132
|
+
}
|
|
133
|
+
export interface EagerUserTurnStrategiesOptions extends ExternalUserTurnStrategiesOptions {
|
|
134
|
+
/**
|
|
135
|
+
* Decides whether the committed transcript is close enough to the eager one
|
|
136
|
+
* to keep the speculative response. Defaults to NormalizedMatch.
|
|
137
|
+
*/
|
|
138
|
+
matchPolicy?: EagerMatchPolicy | null;
|
|
139
|
+
/**
|
|
140
|
+
* Seconds a prediction may go unresolved before it is withdrawn and the
|
|
141
|
+
* turn falls back to answering the committed transcript.
|
|
142
|
+
*/
|
|
143
|
+
speculationTimeout?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Strategies for a service that predicts the end of a turn before committing.
|
|
147
|
+
*
|
|
148
|
+
* Answers the prediction while the turn is still open, so the gap before the
|
|
149
|
+
* committed end of turn is spent generating a response instead of waiting for
|
|
150
|
+
* one. The response is discarded if the user resumes speaking or the
|
|
151
|
+
* committed transcript differs from the eager one. See
|
|
152
|
+
* EagerUserTurnStopStrategy.
|
|
153
|
+
*
|
|
154
|
+
* The response is held by the LLM service until the turn is confirmed, so no
|
|
155
|
+
* extra processor is needed in the pipeline.
|
|
156
|
+
*
|
|
157
|
+
* The service owns turn detection here, so this replaces the detector chain
|
|
158
|
+
* rather than extending it: a local detector running alongside would trigger
|
|
159
|
+
* a second inference for the same turn.
|
|
160
|
+
*
|
|
161
|
+
* - `matchPolicy`: Decides whether the committed transcript is close enough to
|
|
162
|
+
* the eager one to keep the speculative response. Defaults to
|
|
163
|
+
* NormalizedMatch, since services commonly format the transcript they
|
|
164
|
+
* commit (capitalization, punctuation) while leaving the eager one raw. Pass
|
|
165
|
+
* ExactMatch to require the two to be identical.
|
|
166
|
+
* - `speculationTimeout`: Seconds a prediction may go unresolved before it is
|
|
167
|
+
* withdrawn and the turn falls back to answering the committed transcript.
|
|
168
|
+
* Guards against a service that stops sending turn signals
|
|
169
|
+
* mid-speculation, which would otherwise leave the response held and the
|
|
170
|
+
* bot silent.
|
|
171
|
+
* - `enableInterruptions`: Whether to broadcast an interruption when a
|
|
172
|
+
* proposal starts a turn. Services route their `should_interrupt` setting
|
|
173
|
+
* here.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* userTurnStrategies: new EagerUserTurnStrategies()
|
|
177
|
+
*
|
|
178
|
+
* // Require the committed transcript to match the eager one exactly:
|
|
179
|
+
* userTurnStrategies: new EagerUserTurnStrategies({ matchPolicy: new ExactMatch() })
|
|
180
|
+
*/
|
|
181
|
+
export declare class EagerUserTurnStrategies extends ExternalUserTurnStrategies {
|
|
182
|
+
matchPolicy: EagerMatchPolicy | null;
|
|
183
|
+
speculationTimeout: number;
|
|
184
|
+
constructor(options?: EagerUserTurnStrategiesOptions);
|
|
185
|
+
protected _postInit(): void;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=user_turn_strategies.d.ts.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Copyright (c) 2024-2026, Daily
|
|
2
|
+
// Copyright (c) 2026, pipedog contributors
|
|
3
|
+
// SPDX-License-Identifier: BSD-2-Clause
|
|
4
|
+
//
|
|
5
|
+
// Ported from pipecat: src/pipecat/turns/user_turn_strategies.py
|
|
6
|
+
/** Turn start strategy configuration. */
|
|
7
|
+
import { LocalSmartTurnAnalyzerV3 } from "../audio/turn/smart_turn/local_smart_turn_v3.js";
|
|
8
|
+
import { ExternalUserTurnStartStrategy, TranscriptionUserTurnStartStrategy, VADUserTurnStartStrategy, } from "./user_start/index.js";
|
|
9
|
+
import { deferred, EagerUserTurnStopStrategy, ExternalUserTurnStopStrategy, LLMTurnCompletionUserTurnStopStrategy, TurnAnalyzerUserTurnStopStrategy, } from "./user_stop/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Return the default user turn start strategies.
|
|
12
|
+
*
|
|
13
|
+
* Returns `[VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]`.
|
|
14
|
+
* Useful when building a custom strategy list that extends the defaults.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const startStrategies = [
|
|
18
|
+
* new WakePhraseUserTurnStartStrategy({ phrases: ["hey pipecat"] }),
|
|
19
|
+
* ...defaultUserTurnStartStrategies(),
|
|
20
|
+
* ];
|
|
21
|
+
*/
|
|
22
|
+
export function defaultUserTurnStartStrategies() {
|
|
23
|
+
return [new VADUserTurnStartStrategy(), new TranscriptionUserTurnStartStrategy()];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return the default user turn stop strategies.
|
|
27
|
+
*
|
|
28
|
+
* Returns `[TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]`.
|
|
29
|
+
* Useful when building a custom strategy list that extends the defaults.
|
|
30
|
+
*/
|
|
31
|
+
export function defaultUserTurnStopStrategies() {
|
|
32
|
+
return [new TurnAnalyzerUserTurnStopStrategy({ turnAnalyzer: new LocalSmartTurnAnalyzerV3() })];
|
|
33
|
+
}
|
|
34
|
+
// Python dataclasses run `__post_init__` once, after every field of the most
|
|
35
|
+
// derived class is set. Each constructor below assigns its own fields and then
|
|
36
|
+
// runs `_postInit()` only when it is the most derived of these dataclasses in
|
|
37
|
+
// `new.target`'s chain, so the override chain behaves like upstream's (a user
|
|
38
|
+
// subclass that adds no dataclass fields gets it from its nearest parent).
|
|
39
|
+
const postInitClasses = new Set();
|
|
40
|
+
function runsPostInit(target, cls) {
|
|
41
|
+
let proto = target;
|
|
42
|
+
while (proto && !postInitClasses.has(proto)) {
|
|
43
|
+
proto = Object.getPrototypeOf(proto);
|
|
44
|
+
}
|
|
45
|
+
return proto === cls;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Container for user turn start and stop strategies.
|
|
49
|
+
*
|
|
50
|
+
* If no strategies are specified, the following defaults are used:
|
|
51
|
+
*
|
|
52
|
+
* start: [VADUserTurnStartStrategy, TranscriptionUserTurnStartStrategy]
|
|
53
|
+
* stop: [TurnAnalyzerUserTurnStopStrategy(LocalSmartTurnAnalyzerV3)]
|
|
54
|
+
*
|
|
55
|
+
* - `start`: A list of user turn start strategies used to detect when the
|
|
56
|
+
* user starts speaking.
|
|
57
|
+
* - `stop`: A list of user turn stop strategies used to decide when the user
|
|
58
|
+
* stops speaking.
|
|
59
|
+
*/
|
|
60
|
+
export class UserTurnStrategies {
|
|
61
|
+
start;
|
|
62
|
+
stop;
|
|
63
|
+
constructor(options = {}) {
|
|
64
|
+
this.start = options.start ?? [];
|
|
65
|
+
this.stop = options.stop ?? [];
|
|
66
|
+
if (runsPostInit(new.target, UserTurnStrategies))
|
|
67
|
+
this._postInit();
|
|
68
|
+
}
|
|
69
|
+
_postInit() {
|
|
70
|
+
if (!this.start || this.start.length === 0) {
|
|
71
|
+
this.start = defaultUserTurnStartStrategies();
|
|
72
|
+
}
|
|
73
|
+
if (!this.stop || this.stop.length === 0) {
|
|
74
|
+
this.stop = defaultUserTurnStopStrategies();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Container for turn strategies driven by another component in the pipeline.
|
|
80
|
+
*
|
|
81
|
+
* Preconfigures UserTurnStrategies with ExternalUserTurnStartStrategy and
|
|
82
|
+
* ExternalUserTurnStopStrategy, so a service with its own turn detection — or
|
|
83
|
+
* a shared UserTurnProcessor — controls when user turns start and stop.
|
|
84
|
+
*
|
|
85
|
+
* What the aggregator emits depends on which signal drives the turn.
|
|
86
|
+
* `ProposedUserStarted/StoppedSpeakingFrame` leaves the decision here, so the
|
|
87
|
+
* aggregator pushes the turn frames and broadcasts interruptions.
|
|
88
|
+
* `UserStarted/StoppedSpeakingFrame` means the emitter already announced the
|
|
89
|
+
* turn, so the aggregator emits nothing and the parameter below doesn't apply.
|
|
90
|
+
*
|
|
91
|
+
* - `enableInterruptions`: Whether to broadcast an interruption when a
|
|
92
|
+
* proposal starts a turn. Services route their `should_interrupt` setting
|
|
93
|
+
* here.
|
|
94
|
+
*/
|
|
95
|
+
export class ExternalUserTurnStrategies extends UserTurnStrategies {
|
|
96
|
+
enableInterruptions;
|
|
97
|
+
constructor(options = {}) {
|
|
98
|
+
super(options);
|
|
99
|
+
this.enableInterruptions = options.enableInterruptions ?? true;
|
|
100
|
+
if (runsPostInit(new.target, ExternalUserTurnStrategies))
|
|
101
|
+
this._postInit();
|
|
102
|
+
}
|
|
103
|
+
_postInit() {
|
|
104
|
+
this.start = [
|
|
105
|
+
new ExternalUserTurnStartStrategy({ enableInterruptions: this.enableInterruptions }),
|
|
106
|
+
];
|
|
107
|
+
this.stop = [new ExternalUserTurnStopStrategy()];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Stop strategies gated on the LLM's turn-completion verdict.
|
|
112
|
+
*
|
|
113
|
+
* The LLM is asked to begin every response with one of three markers: ●
|
|
114
|
+
* (complete), ◐ (incomplete short), or ○ (incomplete long). Only ● finalizes
|
|
115
|
+
* the user turn; ◐ / ○ keep the turn open so the user can continue speaking
|
|
116
|
+
* and the LLM can re-evaluate later.
|
|
117
|
+
*
|
|
118
|
+
* Configuring strategies this way preserves the existing detector chain
|
|
119
|
+
* (defaults or user-supplied) for inference triggering and appends
|
|
120
|
+
* LLMTurnCompletionUserTurnStopStrategy as the finalizer. The detector
|
|
121
|
+
* strategies are wrapped with `deferred()` automatically so they fire only
|
|
122
|
+
* `on_user_turn_inference_triggered` and leave finalization to the LLM gate.
|
|
123
|
+
*
|
|
124
|
+
* - `config`: Optional configuration applied to the LLM via the
|
|
125
|
+
* `filter_incomplete_user_turns` setting. Customizes the turn-completion
|
|
126
|
+
* instructions, incomplete-turn timeouts, and re-prompts. If null, defaults
|
|
127
|
+
* from UserTurnCompletionConfig are used.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies()
|
|
131
|
+
*
|
|
132
|
+
* // Custom detector chain:
|
|
133
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies({
|
|
134
|
+
* stop: [new SpeechTimeoutUserTurnStopStrategy({ ... })],
|
|
135
|
+
* })
|
|
136
|
+
*
|
|
137
|
+
* // Custom completion config:
|
|
138
|
+
* userTurnStrategies: new FilterIncompleteUserTurnStrategies({
|
|
139
|
+
* config: new UserTurnCompletionConfig({
|
|
140
|
+
* incompleteShortTimeout: 5.0,
|
|
141
|
+
* incompleteLongTimeout: 10.0,
|
|
142
|
+
* }),
|
|
143
|
+
* })
|
|
144
|
+
*/
|
|
145
|
+
export class FilterIncompleteUserTurnStrategies extends UserTurnStrategies {
|
|
146
|
+
config;
|
|
147
|
+
constructor(options = {}) {
|
|
148
|
+
super(options);
|
|
149
|
+
this.config = options.config ?? null;
|
|
150
|
+
if (runsPostInit(new.target, FilterIncompleteUserTurnStrategies))
|
|
151
|
+
this._postInit();
|
|
152
|
+
}
|
|
153
|
+
_postInit() {
|
|
154
|
+
super._postInit();
|
|
155
|
+
// Defer the detector chain so it only fires inference-triggered, then
|
|
156
|
+
// append the LLM gate as the sole finalizer.
|
|
157
|
+
const gated = (this.stop ?? []).map((s) => deferred(s));
|
|
158
|
+
gated.push(new LLMTurnCompletionUserTurnStopStrategy({ config: this.config }));
|
|
159
|
+
this.stop = gated;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Strategies for a service that predicts the end of a turn before committing.
|
|
164
|
+
*
|
|
165
|
+
* Answers the prediction while the turn is still open, so the gap before the
|
|
166
|
+
* committed end of turn is spent generating a response instead of waiting for
|
|
167
|
+
* one. The response is discarded if the user resumes speaking or the
|
|
168
|
+
* committed transcript differs from the eager one. See
|
|
169
|
+
* EagerUserTurnStopStrategy.
|
|
170
|
+
*
|
|
171
|
+
* The response is held by the LLM service until the turn is confirmed, so no
|
|
172
|
+
* extra processor is needed in the pipeline.
|
|
173
|
+
*
|
|
174
|
+
* The service owns turn detection here, so this replaces the detector chain
|
|
175
|
+
* rather than extending it: a local detector running alongside would trigger
|
|
176
|
+
* a second inference for the same turn.
|
|
177
|
+
*
|
|
178
|
+
* - `matchPolicy`: Decides whether the committed transcript is close enough to
|
|
179
|
+
* the eager one to keep the speculative response. Defaults to
|
|
180
|
+
* NormalizedMatch, since services commonly format the transcript they
|
|
181
|
+
* commit (capitalization, punctuation) while leaving the eager one raw. Pass
|
|
182
|
+
* ExactMatch to require the two to be identical.
|
|
183
|
+
* - `speculationTimeout`: Seconds a prediction may go unresolved before it is
|
|
184
|
+
* withdrawn and the turn falls back to answering the committed transcript.
|
|
185
|
+
* Guards against a service that stops sending turn signals
|
|
186
|
+
* mid-speculation, which would otherwise leave the response held and the
|
|
187
|
+
* bot silent.
|
|
188
|
+
* - `enableInterruptions`: Whether to broadcast an interruption when a
|
|
189
|
+
* proposal starts a turn. Services route their `should_interrupt` setting
|
|
190
|
+
* here.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* userTurnStrategies: new EagerUserTurnStrategies()
|
|
194
|
+
*
|
|
195
|
+
* // Require the committed transcript to match the eager one exactly:
|
|
196
|
+
* userTurnStrategies: new EagerUserTurnStrategies({ matchPolicy: new ExactMatch() })
|
|
197
|
+
*/
|
|
198
|
+
export class EagerUserTurnStrategies extends ExternalUserTurnStrategies {
|
|
199
|
+
matchPolicy;
|
|
200
|
+
speculationTimeout;
|
|
201
|
+
constructor(options = {}) {
|
|
202
|
+
super(options);
|
|
203
|
+
this.matchPolicy = options.matchPolicy ?? null;
|
|
204
|
+
this.speculationTimeout = options.speculationTimeout ?? 5.0;
|
|
205
|
+
if (runsPostInit(new.target, EagerUserTurnStrategies))
|
|
206
|
+
this._postInit();
|
|
207
|
+
}
|
|
208
|
+
_postInit() {
|
|
209
|
+
super._postInit();
|
|
210
|
+
this.stop = [
|
|
211
|
+
new EagerUserTurnStopStrategy({
|
|
212
|
+
matchPolicy: this.matchPolicy,
|
|
213
|
+
speculationTimeout: this.speculationTimeout,
|
|
214
|
+
}),
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
postInitClasses.add(UserTurnStrategies);
|
|
219
|
+
postInitClasses.add(ExternalUserTurnStrategies);
|
|
220
|
+
postInitClasses.add(FilterIncompleteUserTurnStrategies);
|
|
221
|
+
postInitClasses.add(EagerUserTurnStrategies);
|
|
222
|
+
//# sourceMappingURL=user_turn_strategies.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for the built-in async tool cancellation feature.
|
|
3
|
+
*
|
|
4
|
+
* A function registered with `cancellableByLlm: true` is advertised alongside
|
|
5
|
+
* a cancel tool named for it, built here, and the instructions below are
|
|
6
|
+
* composed into the system instruction — so the LLM can drop work whose result
|
|
7
|
+
* is no longer wanted. A tool that doesn't opt in has no cancel tool at all.
|
|
8
|
+
*
|
|
9
|
+
* A single running call is stopped without arguments. Telling several calls of
|
|
10
|
+
* one tool apart takes the `tool_call_id` the conversation already carries, on
|
|
11
|
+
* the message that reported each call running.
|
|
12
|
+
*/
|
|
13
|
+
import { FunctionSchema } from "../adapters/schemas/function_schema.ts";
|
|
14
|
+
export declare const ASYNC_TOOL_CANCELLATION_INSTRUCTIONS = "ASYNC TOOL CANCELLATION:\nSome of your tools keep running in the background after you have replied, and some of those can be stopped early.\n\nWork that can be stopped early has its own cancel tool, named for it: a running write_report call is stopped by cancel_write_report. Work with no such tool cannot be stopped and will finish on its own.\n\nWhen the user no longer wants a result you are still waiting on, call the corresponding cancel tool. Only the call stops the work: saying you cancelled it, or that you'll skip it, leaves it running and its result will still arrive and contradict you. So when the same turn also asks for something else, make the call and answer \u2014 don't just answer.\n\nCall the cancel tool with no arguments and it stops the one call that is running. If several calls of that same tool are running, it needs a tool_call_id to say which. Each call's id is already in the conversation: find the tool message that reported it running, which carries \"status\": \"running\", its \"tool_call_id\", and the arguments that call was given. Copy that id exactly as written; never invent or guess one.";
|
|
15
|
+
export declare const CANCEL_TOOL_PREFIX = "cancel_";
|
|
16
|
+
/**
|
|
17
|
+
* Name of the tool that cancels calls of `functionName`.
|
|
18
|
+
*
|
|
19
|
+
* @param functionName The cancellable tool.
|
|
20
|
+
* @returns The built-in cancel tool's name, e.g. `cancel_write_report`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cancelToolName(functionName: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Build the cancel tool for one cancellable tool.
|
|
25
|
+
*
|
|
26
|
+
* Which work to stop is carried by the tool the model picks, so a single
|
|
27
|
+
* running call is stopped without arguments. `tool_call_id` only has to be
|
|
28
|
+
* given to choose between several calls of the same tool, and the handler
|
|
29
|
+
* refuses with the ids when it is needed and missing.
|
|
30
|
+
*
|
|
31
|
+
* @param functionName The tool whose calls this one cancels.
|
|
32
|
+
* @returns The schema to advertise alongside `functionName`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildCancelToolSchema(functionName: string): FunctionSchema;
|
|
35
|
+
//# sourceMappingURL=async_tool_cancellation.d.ts.map
|