@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,291 @@
|
|
|
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/processors/aggregators/async_tool_messages.py
|
|
6
|
+
// --- Payload shape (private; canonical source of truth) ---------------------
|
|
7
|
+
// The `type` field that identifies an async-tool message payload. Both the
|
|
8
|
+
// builders and the parser use this constant; do not duplicate the literal.
|
|
9
|
+
const _PAYLOAD_TYPE = "async_tool";
|
|
10
|
+
// Status value for started / intermediate messages (task still running).
|
|
11
|
+
const _STATUS_RUNNING = "running";
|
|
12
|
+
// Status value for the final message (task complete).
|
|
13
|
+
const _STATUS_FINISHED = "finished";
|
|
14
|
+
// Description shipped on the started message. It says only what the model has
|
|
15
|
+
// to act on (wait, and don't answer from nothing) and deliberately does not
|
|
16
|
+
// describe the message the result will arrive in. A model told the shape of a
|
|
17
|
+
// message it should expect will try to produce one, and a function call is the
|
|
18
|
+
// only structured channel it has, so it calls the tool again with the protocol
|
|
19
|
+
// payload as the arguments. The payload's own fields are read by parseMessage,
|
|
20
|
+
// never by the model, so describing them buys nothing either.
|
|
21
|
+
const _STARTED_DESCRIPTION = "This tool is still running. You will be given its result later. Do not call it " +
|
|
22
|
+
"again and do not invent a result in the meantime.";
|
|
23
|
+
// Description shipped on each intermediate-result message. Names no message
|
|
24
|
+
// shape either, for the same reason as the started message above.
|
|
25
|
+
const _INTERMEDIATE_DESCRIPTION = "This is a partial result and the task is still running. More may follow. Do not " +
|
|
26
|
+
"call this tool again and do not treat this as the final answer.";
|
|
27
|
+
// Result shipped on the message that settles a cancelled task. It names the
|
|
28
|
+
// tool call as the thing that was cancelled: a bare "CANCELLED" reads as a
|
|
29
|
+
// statement about whatever the tool looks up, and a model relaying it will
|
|
30
|
+
// tell the user their flight, order, or booking was cancelled.
|
|
31
|
+
const _CANCELLED_RESULT = "CANCELLED: this tool call was cancelled before it returned a result";
|
|
32
|
+
// Description shipped on the message that settles a cancelled task.
|
|
33
|
+
const _CANCELLED_DESCRIPTION = "The asynchronous task associated with this tool_call_id was cancelled " +
|
|
34
|
+
"before it produced a result, either because it ran past its deadline or " +
|
|
35
|
+
"because cancellation was requested. No further results will arrive for " +
|
|
36
|
+
"this tool_call_id. If the user is still waiting on it, tell them it did " +
|
|
37
|
+
"not complete rather than leaving it unanswered.";
|
|
38
|
+
/**
|
|
39
|
+
* Standing guidance composed into the system instruction whenever an async
|
|
40
|
+
* tool is registered. The per-result message says the same thing, but it
|
|
41
|
+
* arrives buried in a context whose most recent turn may be the user asking
|
|
42
|
+
* for something else; a model weighing the two follows the nearer, louder
|
|
43
|
+
* request. This states the policy before any result exists, so it is in force
|
|
44
|
+
* when one arrives.
|
|
45
|
+
*/
|
|
46
|
+
export const ASYNC_TOOL_INSTRUCTIONS = "ASYNC TOOLS:\n" +
|
|
47
|
+
"Some of your tools keep running after you have replied. Their results arrive later as " +
|
|
48
|
+
"messages in the conversation, on whatever turn happens to be in progress by then.\n" +
|
|
49
|
+
"\n" +
|
|
50
|
+
"A result that has arrived is owed to the user, whatever the conversation has moved on to. " +
|
|
51
|
+
"If the user has said something you have not answered yet, answer that first, then add the " +
|
|
52
|
+
"result at the end of that same reply — never before your answer. If you have already " +
|
|
53
|
+
"answered everything the user said, deliver just the result — do not repeat or rephrase " +
|
|
54
|
+
"your earlier reply. State a short result outright; for a long one, say what came back and " +
|
|
55
|
+
"offer the details. Say it once, and do not repeat it in later replies.";
|
|
56
|
+
// Description shipped on the final-result message.
|
|
57
|
+
const _FINAL_DESCRIPTION = "This is the final result for the asynchronous task associated with this " +
|
|
58
|
+
"tool_call_id. The task has completed. No further results will arrive for " +
|
|
59
|
+
"this tool_call_id. You must convey this result to the user, even if the " +
|
|
60
|
+
"conversation has moved on. Never leave it unsaid. If the user has said " +
|
|
61
|
+
"something you have not answered yet, first finish responding to that, " +
|
|
62
|
+
"then deliver the result at the end of your response; if you have already " +
|
|
63
|
+
"answered, deliver just the result and do not repeat your earlier reply. " +
|
|
64
|
+
"How you deliver it depends on its size: if the result is short, simply " +
|
|
65
|
+
"state it; if it is long or complex, name what has come back and offer " +
|
|
66
|
+
"the details. Convey it once; do not repeat it in later responses.";
|
|
67
|
+
/**
|
|
68
|
+
* The structured contents of an async-tool message in an LLM context.
|
|
69
|
+
*
|
|
70
|
+
* - `kind`: which of the three async-tool message stages this is.
|
|
71
|
+
* - `toolCallId`: the id of the tool invocation this payload relates to.
|
|
72
|
+
* - `status`: `"running"` for started/intermediate, `"finished"` for the
|
|
73
|
+
* final message.
|
|
74
|
+
* - `description`: human-readable description from the payload. May be empty.
|
|
75
|
+
* - `result`: for `intermediate` and `final` messages, the JSON-encoded result
|
|
76
|
+
* string (or the literal `"COMPLETED"` if the function returned no value).
|
|
77
|
+
* `null` for `started` messages.
|
|
78
|
+
*/
|
|
79
|
+
export class AsyncToolMessagePayload {
|
|
80
|
+
kind;
|
|
81
|
+
toolCallId;
|
|
82
|
+
status;
|
|
83
|
+
description;
|
|
84
|
+
result;
|
|
85
|
+
constructor(options) {
|
|
86
|
+
this.kind = options.kind;
|
|
87
|
+
this.toolCallId = options.toolCallId;
|
|
88
|
+
this.status = options.status;
|
|
89
|
+
this.description = options.description;
|
|
90
|
+
this.result = options.result;
|
|
91
|
+
Object.freeze(this);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// --- Internal: payload <-> on-the-wire forms ---------------------------------
|
|
95
|
+
/**
|
|
96
|
+
* Serialize a payload to its on-the-wire JSON string form.
|
|
97
|
+
*
|
|
98
|
+
* Fields that don't apply to the payload's kind are omitted (notably `result`
|
|
99
|
+
* is left out of `started` payloads, since the task hasn't produced a result
|
|
100
|
+
* yet).
|
|
101
|
+
*
|
|
102
|
+
* The string matches Python's `json.dumps(obj, ensure_ascii=False)` byte for
|
|
103
|
+
* byte (`", "` and `": "` separators), so contexts are identical across ports.
|
|
104
|
+
*/
|
|
105
|
+
function _payloadToJson(payload) {
|
|
106
|
+
const obj = {
|
|
107
|
+
type: _PAYLOAD_TYPE,
|
|
108
|
+
status: payload.status,
|
|
109
|
+
tool_call_id: payload.toolCallId,
|
|
110
|
+
description: payload.description,
|
|
111
|
+
};
|
|
112
|
+
if (payload.result !== null) {
|
|
113
|
+
obj.result = payload.result;
|
|
114
|
+
}
|
|
115
|
+
const entries = Object.entries(obj).map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`);
|
|
116
|
+
return `{${entries.join(", ")}}`;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Wrap a payload in the LLM context message shape that matches its kind.
|
|
120
|
+
*
|
|
121
|
+
* - `started`: `role="tool"` plus `tool_call_id` at the top level (so the
|
|
122
|
+
* message can sit alongside other regular tool-result messages).
|
|
123
|
+
* - `intermediate` / `final`: `role="developer"`; `tool_call_id` lives only
|
|
124
|
+
* inside the JSON payload.
|
|
125
|
+
*/
|
|
126
|
+
function _payloadToMessage(payload) {
|
|
127
|
+
const content = _payloadToJson(payload);
|
|
128
|
+
if (payload.kind === "started") {
|
|
129
|
+
return {
|
|
130
|
+
role: "tool",
|
|
131
|
+
content,
|
|
132
|
+
tool_call_id: payload.toolCallId,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
role: "developer",
|
|
137
|
+
content,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// --- Builders ----------------------------------------------------------------
|
|
141
|
+
/**
|
|
142
|
+
* Build a `started` async-tool message for an LLM context.
|
|
143
|
+
*
|
|
144
|
+
* Append the returned message to the LLM context immediately when an async
|
|
145
|
+
* function call (registered with `cancelOnInterruption: false`) starts
|
|
146
|
+
* running. The message lets the model know a task is in flight and that its
|
|
147
|
+
* results will arrive later in subsequent `developer`-role messages.
|
|
148
|
+
*
|
|
149
|
+
* @param toolCallId The id of the tool invocation this message is for.
|
|
150
|
+
* @returns A message ready to pass to `LLMContext.addMessage`.
|
|
151
|
+
*/
|
|
152
|
+
export function buildStartedMessage(toolCallId) {
|
|
153
|
+
return _payloadToMessage(new AsyncToolMessagePayload({
|
|
154
|
+
kind: "started",
|
|
155
|
+
toolCallId,
|
|
156
|
+
status: _STATUS_RUNNING,
|
|
157
|
+
description: _STARTED_DESCRIPTION,
|
|
158
|
+
result: null,
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Build an intermediate-result async-tool message for an LLM context.
|
|
163
|
+
*
|
|
164
|
+
* Append the returned message to the LLM context each time the running async
|
|
165
|
+
* function reports a non-final result via
|
|
166
|
+
* `resultCallback(..., new FunctionCallResultProperties({ isFinal: false }))`.
|
|
167
|
+
*
|
|
168
|
+
* @param toolCallId The id of the tool invocation the result is for.
|
|
169
|
+
* @param result The JSON-encoded result string (caller is responsible for
|
|
170
|
+
* encoding the function's actual return value, typically via
|
|
171
|
+
* `JSON.stringify`).
|
|
172
|
+
* @returns A message ready to pass to `LLMContext.addMessage`.
|
|
173
|
+
*/
|
|
174
|
+
export function buildIntermediateResultMessage(toolCallId, result) {
|
|
175
|
+
return _payloadToMessage(new AsyncToolMessagePayload({
|
|
176
|
+
kind: "intermediate",
|
|
177
|
+
toolCallId,
|
|
178
|
+
status: _STATUS_RUNNING,
|
|
179
|
+
description: _INTERMEDIATE_DESCRIPTION,
|
|
180
|
+
result,
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build a final-result async-tool message for an LLM context.
|
|
185
|
+
*
|
|
186
|
+
* Append the returned message to the LLM context when the async function
|
|
187
|
+
* finishes. After this message no further async-tool messages will arrive for
|
|
188
|
+
* this `tool_call_id`.
|
|
189
|
+
*
|
|
190
|
+
* @param toolCallId The id of the tool invocation the result is for.
|
|
191
|
+
* @param result The JSON-encoded result string, or the literal `"COMPLETED"`
|
|
192
|
+
* sentinel when the function returned nothing (matching the same convention
|
|
193
|
+
* used for synchronous tool calls).
|
|
194
|
+
* @returns A message ready to pass to `LLMContext.addMessage`.
|
|
195
|
+
*/
|
|
196
|
+
export function buildFinalResultMessage(toolCallId, result) {
|
|
197
|
+
return _payloadToMessage(new AsyncToolMessagePayload({
|
|
198
|
+
kind: "final",
|
|
199
|
+
toolCallId,
|
|
200
|
+
status: _STATUS_FINISHED,
|
|
201
|
+
description: _FINAL_DESCRIPTION,
|
|
202
|
+
result,
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Build a message settling a cancelled async-tool call in an LLM context.
|
|
207
|
+
*
|
|
208
|
+
* Append the returned message to the LLM context when an async function call
|
|
209
|
+
* is cancelled (by a timeout or at the model's request) instead of running to
|
|
210
|
+
* completion. It settles the `tool_call_id` the same way a final result does,
|
|
211
|
+
* carrying a cancellation notice in place of a result.
|
|
212
|
+
*
|
|
213
|
+
* @param toolCallId The id of the tool invocation that was cancelled.
|
|
214
|
+
* @returns A message ready to pass to `LLMContext.addMessage`.
|
|
215
|
+
*/
|
|
216
|
+
export function buildCancelledMessage(toolCallId) {
|
|
217
|
+
return _payloadToMessage(new AsyncToolMessagePayload({
|
|
218
|
+
kind: "final",
|
|
219
|
+
toolCallId,
|
|
220
|
+
status: _STATUS_FINISHED,
|
|
221
|
+
description: _CANCELLED_DESCRIPTION,
|
|
222
|
+
result: _CANCELLED_RESULT,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
// --- Parsing -----------------------------------------------------------------
|
|
226
|
+
/**
|
|
227
|
+
* Decode an async-tool message payload, or return null if not async-tool.
|
|
228
|
+
*
|
|
229
|
+
* @param message A standard message from the LLM context. Callers iterating
|
|
230
|
+
* over `LLMContext.getMessages()` should filter out `LLMSpecificMessage`
|
|
231
|
+
* entries first; only `LLMStandardMessage` values can carry async-tool
|
|
232
|
+
* payloads.
|
|
233
|
+
* @returns An `AsyncToolMessagePayload` if the message is a recognized
|
|
234
|
+
* async-tool payload, otherwise `null`.
|
|
235
|
+
*/
|
|
236
|
+
export function parseMessage(message) {
|
|
237
|
+
const role = message.role;
|
|
238
|
+
if (role !== "tool" && role !== "developer") {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
const content = message.content;
|
|
242
|
+
if (typeof content !== "string") {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
let payload;
|
|
246
|
+
try {
|
|
247
|
+
payload = JSON.parse(content);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (typeof payload !== "object" ||
|
|
253
|
+
payload === null ||
|
|
254
|
+
Array.isArray(payload) ||
|
|
255
|
+
payload.type !== _PAYLOAD_TYPE) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const obj = payload;
|
|
259
|
+
const toolCallId = obj.tool_call_id;
|
|
260
|
+
const status = obj.status;
|
|
261
|
+
if (typeof toolCallId !== "string" ||
|
|
262
|
+
(status !== _STATUS_RUNNING && status !== _STATUS_FINISHED)) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
let description = "description" in obj ? obj.description : "";
|
|
266
|
+
if (typeof description !== "string") {
|
|
267
|
+
description = "";
|
|
268
|
+
}
|
|
269
|
+
let result = obj.result ?? null;
|
|
270
|
+
if (result !== null && typeof result !== "string") {
|
|
271
|
+
result = null;
|
|
272
|
+
}
|
|
273
|
+
let kind;
|
|
274
|
+
if (result === null) {
|
|
275
|
+
kind = "started";
|
|
276
|
+
}
|
|
277
|
+
else if (status === _STATUS_FINISHED) {
|
|
278
|
+
kind = "final";
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
kind = "intermediate";
|
|
282
|
+
}
|
|
283
|
+
return new AsyncToolMessagePayload({
|
|
284
|
+
kind,
|
|
285
|
+
toolCallId,
|
|
286
|
+
status,
|
|
287
|
+
description: description,
|
|
288
|
+
result: result,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=async_tool_messages.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DTMF aggregation processor for converting keypad input to transcription.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a frame processor that aggregates DTMF (Dual-Tone
|
|
5
|
+
* Multi-Frequency) keypad inputs into meaningful sequences and converts them to
|
|
6
|
+
* transcription frames for downstream processing by LLM context aggregators.
|
|
7
|
+
*/
|
|
8
|
+
import { Event, type Task } from "@pipedog/asyncio";
|
|
9
|
+
import { KeypadEntry } from "../../audio/dtmf/types.ts";
|
|
10
|
+
import { type Frame, InputDTMFFrame } from "../../frames/frames.ts";
|
|
11
|
+
import { type FrameDirection, FrameProcessor, type FrameProcessorOptions } from "../frame_processor.ts";
|
|
12
|
+
export interface DTMFAggregatorOptions extends FrameProcessorOptions {
|
|
13
|
+
/** Idle timeout in seconds before flushing. Defaults to 2.0. */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Digit that triggers immediate flush. Defaults to `KeypadEntry.POUND`. */
|
|
16
|
+
terminationDigit?: KeypadEntry;
|
|
17
|
+
/** Prefix added to DTMF sequence in transcription. Defaults to "DTMF: ". */
|
|
18
|
+
prefix?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Aggregates DTMF frames into meaningful sequences for LLM processing.
|
|
22
|
+
*
|
|
23
|
+
* The aggregator accumulates digits from InputDTMFFrame instances and flushes
|
|
24
|
+
* when:
|
|
25
|
+
*
|
|
26
|
+
* - Timeout occurs (configurable idle period)
|
|
27
|
+
* - Termination digit is received (default: '#')
|
|
28
|
+
* - EndFrame or CancelFrame is received
|
|
29
|
+
*
|
|
30
|
+
* Emits TranscriptionFrame for compatibility with existing LLM context aggregators.
|
|
31
|
+
*/
|
|
32
|
+
export declare class DTMFAggregator extends FrameProcessor {
|
|
33
|
+
protected _aggregation: string;
|
|
34
|
+
protected _idleTimeout: number;
|
|
35
|
+
protected _terminationDigit: KeypadEntry;
|
|
36
|
+
protected _prefix: string;
|
|
37
|
+
protected _digitEvent: Event;
|
|
38
|
+
protected _aggregationTask: Task<unknown> | null;
|
|
39
|
+
/** Initialize the DTMF aggregator. */
|
|
40
|
+
constructor(options?: DTMFAggregatorOptions);
|
|
41
|
+
/** Clean up resources. */
|
|
42
|
+
cleanup(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Process incoming frames and handle DTMF aggregation.
|
|
45
|
+
*
|
|
46
|
+
* @param frame The frame to process.
|
|
47
|
+
* @param direction The direction of frame flow in the pipeline.
|
|
48
|
+
*/
|
|
49
|
+
processFrame(frame: Frame, direction: FrameDirection): Promise<void>;
|
|
50
|
+
/** Handle DTMF input frame. */
|
|
51
|
+
protected _handleDtmfFrame(frame: InputDTMFFrame): Promise<void>;
|
|
52
|
+
/** Creates the aggregation task if it hasn't been created yet. */
|
|
53
|
+
protected _createAggregationTask(): void;
|
|
54
|
+
/** Stops the aggregation task. */
|
|
55
|
+
protected _stopAggregationTask(): Promise<void>;
|
|
56
|
+
/** Background task that handles timeout-based flushing. */
|
|
57
|
+
protected _aggregationTaskHandler(): Promise<void>;
|
|
58
|
+
/** Flush the current aggregation as a TranscriptionFrame. */
|
|
59
|
+
protected _flushAggregation(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=dtmf_aggregator.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
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/processors/aggregators/dtmf_aggregator.py
|
|
6
|
+
/**
|
|
7
|
+
* DTMF aggregation processor for converting keypad input to transcription.
|
|
8
|
+
*
|
|
9
|
+
* This module provides a frame processor that aggregates DTMF (Dual-Tone
|
|
10
|
+
* Multi-Frequency) keypad inputs into meaningful sequences and converts them to
|
|
11
|
+
* transcription frames for downstream processing by LLM context aggregators.
|
|
12
|
+
*/
|
|
13
|
+
import { Event, TimeoutError, waitFor } from "@pipedog/asyncio";
|
|
14
|
+
import { KeypadEntry } from "../../audio/dtmf/types.js";
|
|
15
|
+
import { CancelFrame, EndFrame, InputDTMFFrame, StartFrame, TranscriptionFrame, } from "../../frames/frames.js";
|
|
16
|
+
import { timeNowIso8601 } from "../../utils/time.js";
|
|
17
|
+
import { FrameProcessor, } from "../frame_processor.js";
|
|
18
|
+
/**
|
|
19
|
+
* Aggregates DTMF frames into meaningful sequences for LLM processing.
|
|
20
|
+
*
|
|
21
|
+
* The aggregator accumulates digits from InputDTMFFrame instances and flushes
|
|
22
|
+
* when:
|
|
23
|
+
*
|
|
24
|
+
* - Timeout occurs (configurable idle period)
|
|
25
|
+
* - Termination digit is received (default: '#')
|
|
26
|
+
* - EndFrame or CancelFrame is received
|
|
27
|
+
*
|
|
28
|
+
* Emits TranscriptionFrame for compatibility with existing LLM context aggregators.
|
|
29
|
+
*/
|
|
30
|
+
export class DTMFAggregator extends FrameProcessor {
|
|
31
|
+
_aggregation = "";
|
|
32
|
+
_idleTimeout;
|
|
33
|
+
_terminationDigit;
|
|
34
|
+
_prefix;
|
|
35
|
+
_digitEvent = new Event();
|
|
36
|
+
_aggregationTask = null;
|
|
37
|
+
/** Initialize the DTMF aggregator. */
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
super(options);
|
|
40
|
+
this._idleTimeout = options.timeout ?? 2.0;
|
|
41
|
+
this._terminationDigit = options.terminationDigit ?? KeypadEntry.POUND;
|
|
42
|
+
this._prefix = options.prefix ?? "DTMF: ";
|
|
43
|
+
}
|
|
44
|
+
/** Clean up resources. */
|
|
45
|
+
async cleanup() {
|
|
46
|
+
await super.cleanup();
|
|
47
|
+
await this._stopAggregationTask();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Process incoming frames and handle DTMF aggregation.
|
|
51
|
+
*
|
|
52
|
+
* @param frame The frame to process.
|
|
53
|
+
* @param direction The direction of frame flow in the pipeline.
|
|
54
|
+
*/
|
|
55
|
+
async processFrame(frame, direction) {
|
|
56
|
+
await super.processFrame(frame, direction);
|
|
57
|
+
if (frame instanceof StartFrame) {
|
|
58
|
+
await this.pushFrame(frame, direction);
|
|
59
|
+
this._createAggregationTask();
|
|
60
|
+
}
|
|
61
|
+
else if (frame instanceof EndFrame || frame instanceof CancelFrame) {
|
|
62
|
+
if (this._aggregation) {
|
|
63
|
+
await this._flushAggregation();
|
|
64
|
+
}
|
|
65
|
+
await this._stopAggregationTask();
|
|
66
|
+
await this.pushFrame(frame, direction);
|
|
67
|
+
}
|
|
68
|
+
else if (frame instanceof InputDTMFFrame) {
|
|
69
|
+
// Push the DTMF frame downstream first
|
|
70
|
+
await this.pushFrame(frame, direction);
|
|
71
|
+
// Then handle it in order for the TranscriptionFrame to be emitted
|
|
72
|
+
// after the InputDTMFFrame
|
|
73
|
+
await this._handleDtmfFrame(frame);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
await this.pushFrame(frame, direction);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Handle DTMF input frame. */
|
|
80
|
+
async _handleDtmfFrame(frame) {
|
|
81
|
+
const isFirstDigit = !this._aggregation;
|
|
82
|
+
const digitValue = frame.button;
|
|
83
|
+
this._aggregation += digitValue;
|
|
84
|
+
// For first digit, schedule interruption.
|
|
85
|
+
if (isFirstDigit) {
|
|
86
|
+
await this.broadcastInterruption();
|
|
87
|
+
}
|
|
88
|
+
// Check for immediate flush conditions
|
|
89
|
+
if (frame.button === this._terminationDigit) {
|
|
90
|
+
await this._flushAggregation();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Signal digit received for timeout handling
|
|
94
|
+
this._digitEvent.set();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Creates the aggregation task if it hasn't been created yet. */
|
|
98
|
+
_createAggregationTask() {
|
|
99
|
+
if (!this._aggregationTask) {
|
|
100
|
+
this._aggregationTask = this.createTask(() => this._aggregationTaskHandler());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Stops the aggregation task. */
|
|
104
|
+
async _stopAggregationTask() {
|
|
105
|
+
if (this._aggregationTask) {
|
|
106
|
+
await this.cancelTask(this._aggregationTask);
|
|
107
|
+
this._aggregationTask = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Background task that handles timeout-based flushing. */
|
|
111
|
+
async _aggregationTaskHandler() {
|
|
112
|
+
for (;;) {
|
|
113
|
+
try {
|
|
114
|
+
await waitFor(() => this._digitEvent.wait(), this._idleTimeout);
|
|
115
|
+
this._digitEvent.clear();
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
if (!(e instanceof TimeoutError))
|
|
119
|
+
throw e;
|
|
120
|
+
if (this._aggregation) {
|
|
121
|
+
await this._flushAggregation();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Flush the current aggregation as a TranscriptionFrame. */
|
|
127
|
+
async _flushAggregation() {
|
|
128
|
+
if (!this._aggregation) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const sequence = this._aggregation;
|
|
132
|
+
const transcriptionText = `${this._prefix}${sequence}`;
|
|
133
|
+
// A DTMF flush is always a complete entry, so mark it finalized.
|
|
134
|
+
const transcriptionFrame = new TranscriptionFrame({
|
|
135
|
+
text: transcriptionText,
|
|
136
|
+
userId: "",
|
|
137
|
+
timestamp: timeNowIso8601(),
|
|
138
|
+
finalized: true,
|
|
139
|
+
});
|
|
140
|
+
await this.pushFrame(transcriptionFrame);
|
|
141
|
+
this._aggregation = "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=dtmf_aggregator.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gated frame aggregator for conditional frame accumulation.
|
|
3
|
+
*
|
|
4
|
+
* This module provides a gated aggregator that accumulates frames based on
|
|
5
|
+
* custom gate open/close functions, allowing for conditional frame buffering
|
|
6
|
+
* and release in frame processing pipelines.
|
|
7
|
+
*/
|
|
8
|
+
import { type Frame } from "../../frames/frames.ts";
|
|
9
|
+
import { FrameDirection, FrameProcessor } from "../frame_processor.ts";
|
|
10
|
+
/** Predicate deciding whether a frame opens or closes the gate. */
|
|
11
|
+
export type GateFn = (frame: Frame) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Accumulate frames, with custom functions to start and stop accumulation.
|
|
14
|
+
*
|
|
15
|
+
* Yields gate-opening frame before any accumulated frames, then ensuing frames
|
|
16
|
+
* until and not including the gate-closed frame. The aggregator maintains an
|
|
17
|
+
* internal gate state that controls whether frames are passed through
|
|
18
|
+
* immediately or accumulated for later release.
|
|
19
|
+
*/
|
|
20
|
+
export declare class GatedAggregator extends FrameProcessor {
|
|
21
|
+
protected _gateOpenFn: GateFn;
|
|
22
|
+
protected _gateCloseFn: GateFn;
|
|
23
|
+
protected _gateOpen: boolean;
|
|
24
|
+
protected _direction: FrameDirection;
|
|
25
|
+
protected _accumulator: [Frame, FrameDirection][];
|
|
26
|
+
/**
|
|
27
|
+
* Initialize the gated aggregator.
|
|
28
|
+
*
|
|
29
|
+
* @param gateOpenFn Function that returns true when a frame should open the gate.
|
|
30
|
+
* @param gateCloseFn Function that returns true when a frame should close the gate.
|
|
31
|
+
* @param startOpen Whether the gate should start in the open state.
|
|
32
|
+
* @param direction The frame direction this aggregator operates on.
|
|
33
|
+
*/
|
|
34
|
+
constructor(gateOpenFn: GateFn, gateCloseFn: GateFn, startOpen: boolean, direction?: FrameDirection);
|
|
35
|
+
/**
|
|
36
|
+
* Process incoming frames with gated accumulation logic.
|
|
37
|
+
*
|
|
38
|
+
* @param frame The frame to process.
|
|
39
|
+
* @param direction The direction of the frame flow.
|
|
40
|
+
*/
|
|
41
|
+
processFrame(frame: Frame, direction: FrameDirection): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=gated.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
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/processors/aggregators/gated.py
|
|
6
|
+
/**
|
|
7
|
+
* Gated frame aggregator for conditional frame accumulation.
|
|
8
|
+
*
|
|
9
|
+
* This module provides a gated aggregator that accumulates frames based on
|
|
10
|
+
* custom gate open/close functions, allowing for conditional frame buffering
|
|
11
|
+
* and release in frame processing pipelines.
|
|
12
|
+
*/
|
|
13
|
+
import { SystemFrame } from "../../frames/frames.js";
|
|
14
|
+
import { logger } from "../../utils/logger.js";
|
|
15
|
+
import { FrameDirection, FrameProcessor } from "../frame_processor.js";
|
|
16
|
+
/**
|
|
17
|
+
* Accumulate frames, with custom functions to start and stop accumulation.
|
|
18
|
+
*
|
|
19
|
+
* Yields gate-opening frame before any accumulated frames, then ensuing frames
|
|
20
|
+
* until and not including the gate-closed frame. The aggregator maintains an
|
|
21
|
+
* internal gate state that controls whether frames are passed through
|
|
22
|
+
* immediately or accumulated for later release.
|
|
23
|
+
*/
|
|
24
|
+
export class GatedAggregator extends FrameProcessor {
|
|
25
|
+
_gateOpenFn;
|
|
26
|
+
_gateCloseFn;
|
|
27
|
+
_gateOpen;
|
|
28
|
+
_direction;
|
|
29
|
+
_accumulator = [];
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the gated aggregator.
|
|
32
|
+
*
|
|
33
|
+
* @param gateOpenFn Function that returns true when a frame should open the gate.
|
|
34
|
+
* @param gateCloseFn Function that returns true when a frame should close the gate.
|
|
35
|
+
* @param startOpen Whether the gate should start in the open state.
|
|
36
|
+
* @param direction The frame direction this aggregator operates on.
|
|
37
|
+
*/
|
|
38
|
+
constructor(gateOpenFn, gateCloseFn, startOpen, direction = FrameDirection.DOWNSTREAM) {
|
|
39
|
+
super();
|
|
40
|
+
this._gateOpenFn = gateOpenFn;
|
|
41
|
+
this._gateCloseFn = gateCloseFn;
|
|
42
|
+
this._gateOpen = startOpen;
|
|
43
|
+
this._direction = direction;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Process incoming frames with gated accumulation logic.
|
|
47
|
+
*
|
|
48
|
+
* @param frame The frame to process.
|
|
49
|
+
* @param direction The direction of the frame flow.
|
|
50
|
+
*/
|
|
51
|
+
async processFrame(frame, direction) {
|
|
52
|
+
await super.processFrame(frame, direction);
|
|
53
|
+
// We must not block system frames.
|
|
54
|
+
if (frame instanceof SystemFrame) {
|
|
55
|
+
await this.pushFrame(frame, direction);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// Ignore frames that are not following the direction of this gate.
|
|
59
|
+
if (direction !== this._direction) {
|
|
60
|
+
await this.pushFrame(frame, direction);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const oldState = this._gateOpen;
|
|
64
|
+
if (this._gateOpen) {
|
|
65
|
+
this._gateOpen = !this._gateCloseFn(frame);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this._gateOpen = this._gateOpenFn(frame);
|
|
69
|
+
}
|
|
70
|
+
if (oldState !== this._gateOpen) {
|
|
71
|
+
const state = this._gateOpen ? "open" : "closed";
|
|
72
|
+
logger.debug(`Gate is now ${state} because of ${frame}`);
|
|
73
|
+
}
|
|
74
|
+
if (this._gateOpen) {
|
|
75
|
+
await this.pushFrame(frame, direction);
|
|
76
|
+
for (const [f, d] of this._accumulator) {
|
|
77
|
+
await this.pushFrame(f, d);
|
|
78
|
+
}
|
|
79
|
+
this._accumulator = [];
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this._accumulator.push([frame, direction]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=gated.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Gated LLM context aggregator for controlled message flow. */
|
|
2
|
+
import type { Task } from "@pipedog/asyncio";
|
|
3
|
+
import { type Frame, LLMContextFrame } from "../../frames/frames.ts";
|
|
4
|
+
import type { BaseNotifier } from "../../utils/sync/base_notifier.ts";
|
|
5
|
+
import { type FrameDirection, FrameProcessor, type FrameProcessorOptions } from "../frame_processor.ts";
|
|
6
|
+
export interface GatedLLMContextAggregatorOptions extends FrameProcessorOptions {
|
|
7
|
+
/** The notifier that controls when frames are released. */
|
|
8
|
+
notifier: BaseNotifier;
|
|
9
|
+
/** If true, the first context frame passes through immediately. */
|
|
10
|
+
startOpen?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Aggregator that gates LLM context frames until notified.
|
|
14
|
+
*
|
|
15
|
+
* This aggregator captures LLM context frames and holds them until a notifier
|
|
16
|
+
* signals that they can be released. This is useful for controlling the flow
|
|
17
|
+
* of context frames based on external conditions or timing.
|
|
18
|
+
*/
|
|
19
|
+
export declare class GatedLLMContextAggregator extends FrameProcessor {
|
|
20
|
+
protected _notifier: BaseNotifier;
|
|
21
|
+
protected _startOpen: boolean;
|
|
22
|
+
protected _lastContextFrame: LLMContextFrame | null;
|
|
23
|
+
protected _gateTask: Task<unknown> | null;
|
|
24
|
+
/** Initialize the gated context aggregator. */
|
|
25
|
+
constructor(options: GatedLLMContextAggregatorOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Process incoming frames, gating LLM context frames.
|
|
28
|
+
*
|
|
29
|
+
* @param frame The frame to process.
|
|
30
|
+
* @param direction The direction of frame flow in the pipeline.
|
|
31
|
+
*/
|
|
32
|
+
processFrame(frame: Frame, direction: FrameDirection): Promise<void>;
|
|
33
|
+
/** Release resources held by the aggregator. */
|
|
34
|
+
cleanup(): Promise<void>;
|
|
35
|
+
/** Start the gate task handler. */
|
|
36
|
+
protected _start(): Promise<void>;
|
|
37
|
+
/** Stop the gate task handler. */
|
|
38
|
+
protected _stop(): Promise<void>;
|
|
39
|
+
/** Handle the gating logic by waiting for notifications and releasing frames. */
|
|
40
|
+
protected _gateTaskHandler(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=gated_llm_context.d.ts.map
|