@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,772 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base worker for the multi-worker framework.
|
|
3
|
+
*
|
|
4
|
+
* Provides the `BaseWorker` class that all workers inherit from, handling
|
|
5
|
+
* worker lifecycle, parent-child relationships, and long-running job
|
|
6
|
+
* coordination on the bus.
|
|
7
|
+
*
|
|
8
|
+
* Porting notes:
|
|
9
|
+
* - The deprecated per-argument job spelling (`name=`, `payload=`,
|
|
10
|
+
* `timeout=`, `cancel_on_error=` on `request_job`, `job`,
|
|
11
|
+
* `request_job_group`, `job_group` and `create_job_group_and_request_job`)
|
|
12
|
+
* and `resolve_job_params` are not ported; pass `params` instead.
|
|
13
|
+
* - Methods that take `*names` plus keyword arguments take the names as rest
|
|
14
|
+
* arguments and an optional trailing options object:
|
|
15
|
+
* `this.jobGroup("w1", "w2", { params })`, `this.addWorkers(a, b, { watch: false })`.
|
|
16
|
+
*/
|
|
17
|
+
import { Event, Lock, type Task, type TaskFn } from "@pipedog/asyncio";
|
|
18
|
+
import type { WorkerBus } from "../bus/bus.ts";
|
|
19
|
+
import { BusActivateWorkerMessage, BusCancelWorkerMessage, BusDeactivateWorkerMessage, BusEndWorkerMessage, BusJobCancelMessage, BusJobRequestMessage, BusJobResponseMessage, BusJobResponseUrgentMessage, BusJobStreamDataMessage, BusJobStreamEndMessage, BusJobStreamStartMessage, BusJobUpdateMessage, BusJobUpdateRequestMessage, BusJobUpdateUrgentMessage, type BusMessage, BusWorkerErrorMessage, BusWorkerLocalErrorMessage } from "../bus/messages.ts";
|
|
20
|
+
import { JobContext, JobGroup, JobGroupContext, JobGroupEvent, JobGroupParams, JobGroupResponse, JobParams, JobStatus } from "../pipeline/job_context.ts";
|
|
21
|
+
import type { WorkerRegistry } from "../registry/registry.ts";
|
|
22
|
+
import { WorkerErrorData, WorkerReadyData } from "../registry/types.ts";
|
|
23
|
+
import type { BaseTaskManager } from "../utils/asyncio/task_manager.ts";
|
|
24
|
+
import { BaseObject, type BaseObjectOptions } from "../utils/base_object.ts";
|
|
25
|
+
import type { WorkerRunner } from "./runner.ts";
|
|
26
|
+
type Dict = Record<string, unknown>;
|
|
27
|
+
type JobHandlerFn = (message: BusJobRequestMessage) => Promise<unknown> | unknown;
|
|
28
|
+
export interface WorkerParamsOptions {
|
|
29
|
+
/** Task manager for handling asyncio tasks. */
|
|
30
|
+
taskManager: BaseTaskManager;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration parameters for worker execution.
|
|
34
|
+
*
|
|
35
|
+
* - `taskManager`: Task manager for handling asyncio tasks.
|
|
36
|
+
*/
|
|
37
|
+
export declare class WorkerParams {
|
|
38
|
+
taskManager: BaseTaskManager;
|
|
39
|
+
constructor(options: WorkerParamsOptions);
|
|
40
|
+
}
|
|
41
|
+
export interface WorkerActivationArgsOptions {
|
|
42
|
+
/** Optional structured data passed during activation. */
|
|
43
|
+
metadata?: Dict | null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Base activation arguments for any worker.
|
|
47
|
+
*
|
|
48
|
+
* - `metadata`: Optional structured data passed during activation.
|
|
49
|
+
*
|
|
50
|
+
* Subclasses add fields (with defaults) and accept them in their options
|
|
51
|
+
* object; `fromDict` and `toDict` work off the instance's own fields.
|
|
52
|
+
*/
|
|
53
|
+
export declare class WorkerActivationArgs {
|
|
54
|
+
metadata: Dict | null;
|
|
55
|
+
constructor(options?: WorkerActivationArgsOptions);
|
|
56
|
+
/** Create from a dict, ignoring unknown keys. */
|
|
57
|
+
static fromDict<T extends WorkerActivationArgs>(this: new (options?: Dict) => T, data: Dict): T;
|
|
58
|
+
/** Convert to a dict, excluding null values. */
|
|
59
|
+
toDict(): Dict;
|
|
60
|
+
}
|
|
61
|
+
export interface BaseWorkerOptions extends BaseObjectOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Unique name for this worker. If null, an auto-generated name is used
|
|
64
|
+
* (useful for instances that don't participate in inter-worker
|
|
65
|
+
* communication).
|
|
66
|
+
*/
|
|
67
|
+
name?: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the worker starts out accepting bus messages (see `active`).
|
|
70
|
+
* Starting one inactive is for multi-worker setups where workers take
|
|
71
|
+
* turns: it stays out of the way, doing nothing, until another worker or
|
|
72
|
+
* the application activates it. Defaults to true.
|
|
73
|
+
*/
|
|
74
|
+
active?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to warn about tasks left running when the worker finishes. Only
|
|
77
|
+
* applies when the worker owns its task manager; a worker sharing the
|
|
78
|
+
* runner's task manager leaves the report to the runner. Defaults to true.
|
|
79
|
+
*/
|
|
80
|
+
checkDanglingTasks?: boolean;
|
|
81
|
+
/** Optional task manager for handling asyncio tasks. */
|
|
82
|
+
taskManager?: BaseTaskManager | null;
|
|
83
|
+
}
|
|
84
|
+
export interface AttachOptions {
|
|
85
|
+
/** The shared worker registry. */
|
|
86
|
+
registry: WorkerRegistry;
|
|
87
|
+
/** The shared worker bus. */
|
|
88
|
+
bus: WorkerBus;
|
|
89
|
+
/** The runner hosting the worker, reachable afterwards as `workerRunner`. */
|
|
90
|
+
workerRunner: WorkerRunner;
|
|
91
|
+
}
|
|
92
|
+
export interface AddWorkersOptions {
|
|
93
|
+
/**
|
|
94
|
+
* When true (the default), watch each newly added child so
|
|
95
|
+
* `onWorkerReady` fires once it registers. Workers that were skipped
|
|
96
|
+
* (already parented elsewhere) are not watched.
|
|
97
|
+
*/
|
|
98
|
+
watch?: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface ActivateWorkerOptions {
|
|
101
|
+
/** Optional `WorkerActivationArgs` forwarded to the target worker's `onActivated`. */
|
|
102
|
+
args?: WorkerActivationArgs | null;
|
|
103
|
+
/** Whether to deactivate this worker before activating the target. */
|
|
104
|
+
deactivateSelf?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface JobOptions {
|
|
107
|
+
/** How to run the job. See `JobParams`. */
|
|
108
|
+
params?: JobParams | null;
|
|
109
|
+
}
|
|
110
|
+
export interface JobGroupOptions {
|
|
111
|
+
/** How to run the group. See `JobGroupParams`. */
|
|
112
|
+
params?: JobGroupParams | null;
|
|
113
|
+
}
|
|
114
|
+
export interface SendJobResponseOptions {
|
|
115
|
+
/** Completion status. Defaults to `JobStatus.COMPLETED`. */
|
|
116
|
+
status?: JobStatus;
|
|
117
|
+
/** When true, the response is delivered with system priority, preempting queued data messages. */
|
|
118
|
+
urgent?: boolean;
|
|
119
|
+
}
|
|
120
|
+
export interface SendJobUpdateOptions {
|
|
121
|
+
/** When true, the update is delivered with system priority, preempting queued data messages. */
|
|
122
|
+
urgent?: boolean;
|
|
123
|
+
}
|
|
124
|
+
declare const BaseWorker_base: typeof BaseObject & import("../utils/mixin.ts").Ctor<import("../bus/subscriber.ts").BusSubscriberMethods>;
|
|
125
|
+
/**
|
|
126
|
+
* Abstract base for workers in framework.
|
|
127
|
+
*
|
|
128
|
+
* A worker connects to a `WorkerBus`, registers itself in the shared
|
|
129
|
+
* registry, accepts activation/deactivation, and exchanges job
|
|
130
|
+
* requests/responses with other workers. Concrete subclasses
|
|
131
|
+
* (e.g. `PipelineWorker`) provide the runtime that actually drives
|
|
132
|
+
* the worker's work.
|
|
133
|
+
*
|
|
134
|
+
* Overridable lifecycle methods (always call `super`):
|
|
135
|
+
*
|
|
136
|
+
* - `onActivated(args)`: Called when this worker is activated.
|
|
137
|
+
* - `onDeactivated()`: Called when this worker is deactivated.
|
|
138
|
+
* - `onWorkerReady(data)`: Called when another worker is ready to receive
|
|
139
|
+
* messages. For local root workers, fires automatically. For children,
|
|
140
|
+
* fires only on the parent. For remote workers, fires only for workers
|
|
141
|
+
* watched via `watchWorkers()`.
|
|
142
|
+
* - `onJobRequest(message)`: Called when a job request is received.
|
|
143
|
+
* - `onJobResponse(message)`: Called when a worker sends a response.
|
|
144
|
+
* - `onJobUpdate(message)`: Called when a worker sends a progress update.
|
|
145
|
+
* - `onJobUpdateRequested(message)`: Called when the requester asks for a
|
|
146
|
+
* progress update.
|
|
147
|
+
* - `onJobCompleted(result)`: Called when all workers in a job group have
|
|
148
|
+
* responded.
|
|
149
|
+
* - `onJobError(message)`: Called when a worker errors and the group is
|
|
150
|
+
* cancelled (`cancelOnError`).
|
|
151
|
+
* - `onJobStreamStart(message)`: Called when a worker begins streaming.
|
|
152
|
+
* - `onJobStreamData(message)`: Called for each streaming chunk from a worker.
|
|
153
|
+
* - `onJobStreamEnd(message)`: Called when a worker finishes streaming.
|
|
154
|
+
* - `onJobCancelled(message)`: Called when this worker's job is cancelled by
|
|
155
|
+
* the requester.
|
|
156
|
+
* - `onBusMessage(message)`: Called for bus messages after default lifecycle
|
|
157
|
+
* handling.
|
|
158
|
+
*
|
|
159
|
+
* Event handlers available:
|
|
160
|
+
*
|
|
161
|
+
* - on_activated: Worker was activated.
|
|
162
|
+
* - on_deactivated: Worker was deactivated.
|
|
163
|
+
* - on_worker_ready: Another worker is ready.
|
|
164
|
+
* - on_worker_failed: A child worker reported an error.
|
|
165
|
+
* - on_job_request: Received a job request.
|
|
166
|
+
* - on_job_response: A worker sent a response.
|
|
167
|
+
* - on_job_update: A worker sent a progress update.
|
|
168
|
+
* - on_job_update_requested: Requester asked for a progress update.
|
|
169
|
+
* - on_job_completed: All workers in a job group responded.
|
|
170
|
+
* - on_job_error: A worker errored and the group was cancelled.
|
|
171
|
+
* - on_job_stream_start: A worker started streaming.
|
|
172
|
+
* - on_job_stream_data: A worker sent a streaming chunk.
|
|
173
|
+
* - on_job_stream_end: A worker finished streaming.
|
|
174
|
+
* - on_job_cancelled: This worker's job was cancelled.
|
|
175
|
+
* - on_bus_message: A bus message was received.
|
|
176
|
+
*/
|
|
177
|
+
export declare class BaseWorker extends BaseWorker_base {
|
|
178
|
+
protected _checkDanglingTasks: boolean;
|
|
179
|
+
protected _ownsTaskManager: boolean;
|
|
180
|
+
protected _bus: WorkerBus | null;
|
|
181
|
+
protected _registry: WorkerRegistry | null;
|
|
182
|
+
protected _workerRunner: WorkerRunner | null;
|
|
183
|
+
protected _active: boolean;
|
|
184
|
+
protected _pendingActivation: boolean;
|
|
185
|
+
protected _activationArgs: Dict | null;
|
|
186
|
+
protected _parent: string | null;
|
|
187
|
+
protected _children: BaseWorker[];
|
|
188
|
+
protected _startedAt: number | null;
|
|
189
|
+
protected _finishedEvent: Event;
|
|
190
|
+
protected _activeJobs: Map<string, BusJobRequestMessage>;
|
|
191
|
+
protected _jobHandlerTasks: Map<string, Task<unknown>>;
|
|
192
|
+
protected _jobGroups: Map<string, JobGroup>;
|
|
193
|
+
protected _jobHandlers: Map<string, JobHandlerFn>;
|
|
194
|
+
protected _jobLocks: Map<string, Lock>;
|
|
195
|
+
protected _workerReadyHandlers: Map<string, (data: WorkerReadyData) => unknown>;
|
|
196
|
+
protected readonly _onWatchedWorkerReadyHandler: (data: WorkerReadyData) => Promise<void>;
|
|
197
|
+
/** Initialize the BaseWorker. */
|
|
198
|
+
constructor(options?: BaseWorkerOptions);
|
|
199
|
+
/**
|
|
200
|
+
* The bus this worker is attached to.
|
|
201
|
+
*
|
|
202
|
+
* @throws Error If accessed before `attach()` has been called.
|
|
203
|
+
*/
|
|
204
|
+
get bus(): WorkerBus;
|
|
205
|
+
/**
|
|
206
|
+
* Whether this worker is accepting bus messages.
|
|
207
|
+
*
|
|
208
|
+
* An active worker takes everything addressed to it. An inactive one takes
|
|
209
|
+
* only activation, deactivation, end or cancel messages, so no job request,
|
|
210
|
+
* frame or UI event reaches it and none of its `onBusMessage` handling runs.
|
|
211
|
+
*
|
|
212
|
+
* It matters mainly in multi-worker setups, where a worker is put out of
|
|
213
|
+
* the way while the others carry on.
|
|
214
|
+
*
|
|
215
|
+
* Registry watches sit outside this: `workerReady` handlers fire from
|
|
216
|
+
* `WorkerRegistry` whatever this returns, because they never travel over
|
|
217
|
+
* the bus.
|
|
218
|
+
*/
|
|
219
|
+
get active(): boolean;
|
|
220
|
+
/** The arguments from the most recent activation, or null if inactive. */
|
|
221
|
+
get activationArgs(): Dict | null;
|
|
222
|
+
/** The name of the parent worker, or null if this is a root worker. */
|
|
223
|
+
get parent(): string | null;
|
|
224
|
+
/**
|
|
225
|
+
* The shared worker registry this worker is attached to.
|
|
226
|
+
*
|
|
227
|
+
* @throws Error If accessed before `attach()` has been called.
|
|
228
|
+
*/
|
|
229
|
+
get registry(): WorkerRegistry;
|
|
230
|
+
/**
|
|
231
|
+
* The runner this worker is attached to.
|
|
232
|
+
*
|
|
233
|
+
* Use it to reach another worker on the same runner by name, e.g.
|
|
234
|
+
* `this.workerRunner.getWorker("ui-jobs")`.
|
|
235
|
+
*
|
|
236
|
+
* @throws Error If accessed before `attach()` has been called.
|
|
237
|
+
*/
|
|
238
|
+
get workerRunner(): WorkerRunner;
|
|
239
|
+
/** Unix timestamp (seconds) when this worker became ready, or null if not yet started. */
|
|
240
|
+
get startedAt(): number | null;
|
|
241
|
+
/**
|
|
242
|
+
* Whether this worker is bridged onto the bus.
|
|
243
|
+
*
|
|
244
|
+
* Subclasses (e.g. `PipelineWorker`) override when they auto-wrap their
|
|
245
|
+
* pipeline with bus edge processors.
|
|
246
|
+
*/
|
|
247
|
+
get bridged(): boolean;
|
|
248
|
+
/** The list of child workers added via `addWorkers()`. */
|
|
249
|
+
get children(): BaseWorker[];
|
|
250
|
+
/** Active job requests this worker is currently working on, keyed by jobId. */
|
|
251
|
+
get activeJobs(): Map<string, BusJobRequestMessage>;
|
|
252
|
+
/** Active job groups launched by this worker, keyed by jobId. */
|
|
253
|
+
get jobGroups(): Map<string, JobGroup>;
|
|
254
|
+
/**
|
|
255
|
+
* Attach the worker to a runner-provided registry and bus.
|
|
256
|
+
*
|
|
257
|
+
* Called by the runner (typically from `addWorkers()`) before the worker
|
|
258
|
+
* is run. After this call, `registry` and `bus` return the provided
|
|
259
|
+
* instances, and the worker is subscribed to the bus — so workers added
|
|
260
|
+
* later are listening before any worker emits its first message.
|
|
261
|
+
*/
|
|
262
|
+
attach(options: AttachOptions): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Clean up the worker and release resources.
|
|
265
|
+
*
|
|
266
|
+
* Cancels running jobs, unsubscribes from the bus, and signals that the
|
|
267
|
+
* worker has stopped.
|
|
268
|
+
*/
|
|
269
|
+
cleanup(): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Run this worker until it finishes.
|
|
272
|
+
*
|
|
273
|
+
* The default implementation is for bus-only workers: it subscribes to the
|
|
274
|
+
* bus, marks the worker as started, then waits until `stop()` (or
|
|
275
|
+
* `_finishedEvent`) is signalled. Subclasses with their own runtime (e.g.
|
|
276
|
+
* `PipelineWorker`) override this method.
|
|
277
|
+
*
|
|
278
|
+
* @param params Configuration parameters for worker execution.
|
|
279
|
+
*/
|
|
280
|
+
run(params: WorkerParams): Promise<void>;
|
|
281
|
+
/** Mark the worker as started, register, and activate if requested. */
|
|
282
|
+
start(): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Clean up and signal that this worker has stopped.
|
|
285
|
+
*
|
|
286
|
+
* Cancels all running job groups and reports any still-active job
|
|
287
|
+
* requests back to their requesters as `CANCELLED`, so parents aren't left
|
|
288
|
+
* waiting, and cancels the handlers still running for them, such as one
|
|
289
|
+
* holding a long-lived job open.
|
|
290
|
+
*/
|
|
291
|
+
stop(): Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Request a graceful end of the session.
|
|
294
|
+
*
|
|
295
|
+
* @param options.reason Optional human-readable reason for ending.
|
|
296
|
+
*/
|
|
297
|
+
end(options?: {
|
|
298
|
+
reason?: string | null;
|
|
299
|
+
}): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Request an immediate cancellation of all workers.
|
|
302
|
+
*
|
|
303
|
+
* @param options.reason Optional human-readable reason. Propagated through
|
|
304
|
+
* the runner to every root worker's `BusCancelWorkerMessage`.
|
|
305
|
+
*/
|
|
306
|
+
cancel(options?: {
|
|
307
|
+
reason?: string | null;
|
|
308
|
+
}): Promise<void>;
|
|
309
|
+
/** Wait for this worker to finish. */
|
|
310
|
+
wait(): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Called when this worker is activated.
|
|
313
|
+
*
|
|
314
|
+
* Override in subclasses to react to activation. Always call
|
|
315
|
+
* `super.onActivated(args)`.
|
|
316
|
+
*
|
|
317
|
+
* @param args Optional arguments from the caller.
|
|
318
|
+
*/
|
|
319
|
+
onActivated(_args: Dict | null): Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Called when this worker is deactivated.
|
|
322
|
+
*
|
|
323
|
+
* Override in subclasses to react to deactivation. Always call
|
|
324
|
+
* `super.onDeactivated()`.
|
|
325
|
+
*/
|
|
326
|
+
onDeactivated(): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Called when another worker is ready to receive messages.
|
|
329
|
+
*
|
|
330
|
+
* For local root workers this fires automatically. For remote workers it
|
|
331
|
+
* fires only for workers watched via `watchWorkers()`. For child workers
|
|
332
|
+
* it fires only on the parent that created them.
|
|
333
|
+
*
|
|
334
|
+
* @param data Information about the ready worker.
|
|
335
|
+
*/
|
|
336
|
+
onWorkerReady(_data: WorkerReadyData): Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Called when a child worker reports an error.
|
|
339
|
+
*
|
|
340
|
+
* @param data Information about the error.
|
|
341
|
+
*/
|
|
342
|
+
onWorkerFailed(_data: WorkerErrorData): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* Take bus messages only while active.
|
|
345
|
+
*
|
|
346
|
+
* An inactive worker is handed only activation, deactivation, end or
|
|
347
|
+
* cancel messages. Work addressed to it, and everything it would merely
|
|
348
|
+
* observe, is dropped by the bus rather than reaching `onBusMessage`.
|
|
349
|
+
*
|
|
350
|
+
* Registry notifications are unaffected, since `workerReady` watches fire
|
|
351
|
+
* from `WorkerRegistry` rather than travelling over the bus.
|
|
352
|
+
*
|
|
353
|
+
* @param message The bus message about to be delivered.
|
|
354
|
+
* @returns Whether to deliver the message.
|
|
355
|
+
*/
|
|
356
|
+
acceptsBusMessage(message: BusMessage): boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Called for every bus message after built-in lifecycle handling.
|
|
359
|
+
*
|
|
360
|
+
* Override to handle custom message types. Built-in message types
|
|
361
|
+
* (activation, end, cancel, job) are already dispatched to their
|
|
362
|
+
* respective hooks before this method is called.
|
|
363
|
+
*
|
|
364
|
+
* @param message The `BusMessage` to process.
|
|
365
|
+
*/
|
|
366
|
+
onBusMessage(message: BusMessage): Promise<void>;
|
|
367
|
+
/**
|
|
368
|
+
* Called when this worker receives a job request.
|
|
369
|
+
*
|
|
370
|
+
* Override to perform work. Use `sendJobUpdate()` to report progress and
|
|
371
|
+
* `sendJobResponse()` to return results.
|
|
372
|
+
*/
|
|
373
|
+
onJobRequest(_message: BusJobRequestMessage): Promise<void>;
|
|
374
|
+
/**
|
|
375
|
+
* Called when a worker sends a response.
|
|
376
|
+
*
|
|
377
|
+
* Override to process individual results as they arrive.
|
|
378
|
+
*/
|
|
379
|
+
onJobResponse(_message: BusJobResponseMessage | BusJobResponseUrgentMessage): Promise<void>;
|
|
380
|
+
/** Called when a worker sends a progress update. */
|
|
381
|
+
onJobUpdate(_message: BusJobUpdateMessage | BusJobUpdateUrgentMessage): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Called when the requester asks for a progress update.
|
|
384
|
+
*
|
|
385
|
+
* Override to send back a progress update via `sendJobUpdate()`.
|
|
386
|
+
*/
|
|
387
|
+
onJobUpdateRequested(_message: BusJobUpdateRequestMessage): Promise<void>;
|
|
388
|
+
/** Called when all workers in a job group have responded. */
|
|
389
|
+
onJobCompleted(_result: JobGroupResponse): Promise<void>;
|
|
390
|
+
/**
|
|
391
|
+
* Called when a job group is cancelled due to a worker error.
|
|
392
|
+
*
|
|
393
|
+
* Fires when a worker responds with `ERROR` or `FAILED` status and
|
|
394
|
+
* `cancelOnError` is set. The group is cancelled and `onJobCompleted`
|
|
395
|
+
* will not fire. Partial responses from workers that completed before the
|
|
396
|
+
* error are available in the job group's `responses`.
|
|
397
|
+
*/
|
|
398
|
+
onJobError(_message: BusJobResponseMessage | BusJobResponseUrgentMessage): Promise<void>;
|
|
399
|
+
/** Called when a worker begins streaming. */
|
|
400
|
+
onJobStreamStart(_message: BusJobStreamStartMessage): Promise<void>;
|
|
401
|
+
/** Called for each streaming chunk from a worker. */
|
|
402
|
+
onJobStreamData(_message: BusJobStreamDataMessage): Promise<void>;
|
|
403
|
+
/** Called when a worker finishes streaming. */
|
|
404
|
+
onJobStreamEnd(_message: BusJobStreamEndMessage): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Called when this worker's job is cancelled by the requester.
|
|
407
|
+
*
|
|
408
|
+
* Override to clean up resources or stop in-progress work.
|
|
409
|
+
*/
|
|
410
|
+
onJobCancelled(_message: BusJobCancelMessage): Promise<void>;
|
|
411
|
+
/**
|
|
412
|
+
* Send a message on the bus.
|
|
413
|
+
*
|
|
414
|
+
* @param message The `BusMessage` to send.
|
|
415
|
+
*/
|
|
416
|
+
sendBusMessage(message: BusMessage): Promise<void>;
|
|
417
|
+
/**
|
|
418
|
+
* Report an error on the bus.
|
|
419
|
+
*
|
|
420
|
+
* Child workers send a local-only message to the parent. Root workers
|
|
421
|
+
* broadcast over the network.
|
|
422
|
+
*
|
|
423
|
+
* @param error Description of the error.
|
|
424
|
+
*/
|
|
425
|
+
sendBusErrorMessage(error: string): Promise<void>;
|
|
426
|
+
/**
|
|
427
|
+
* Register one or more child workers under this parent.
|
|
428
|
+
*
|
|
429
|
+
* Each child's lifecycle (end, cancel) is automatically managed by this
|
|
430
|
+
* parent worker. By default, the children are also watched so the parent
|
|
431
|
+
* receives `onWorkerReady` when each one starts; pass `{ watch: false }`
|
|
432
|
+
* as the last argument to opt out (you can still call `watchWorkers()`
|
|
433
|
+
* later).
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* await this.addWorkers(researcher, writer);
|
|
437
|
+
* await this.addWorkers(researcher, writer, { watch: false });
|
|
438
|
+
*/
|
|
439
|
+
addWorkers(...args: [...workers: BaseWorker[], options: AddWorkersOptions]): Promise<void>;
|
|
440
|
+
addWorkers(...workers: BaseWorker[]): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Activate a worker by name.
|
|
443
|
+
*
|
|
444
|
+
* The target worker's `onActivated` hook will be called with the provided
|
|
445
|
+
* arguments. The target need not be active already: an activation reaches
|
|
446
|
+
* an inactive worker, which is what lets it become active.
|
|
447
|
+
*
|
|
448
|
+
* @param workerName The name of the worker to activate.
|
|
449
|
+
* @param options.args Optional `WorkerActivationArgs` forwarded to the
|
|
450
|
+
* target worker's `onActivated`.
|
|
451
|
+
* @param options.deactivateSelf Whether to deactivate this worker before
|
|
452
|
+
* activating the target.
|
|
453
|
+
*/
|
|
454
|
+
activateWorker(workerName: string, options?: ActivateWorkerOptions): Promise<void>;
|
|
455
|
+
/**
|
|
456
|
+
* Deactivate a worker by name.
|
|
457
|
+
*
|
|
458
|
+
* The target worker's `onDeactivated` hook will be called.
|
|
459
|
+
*
|
|
460
|
+
* @param workerName The name of the worker to deactivate.
|
|
461
|
+
*/
|
|
462
|
+
deactivateWorker(workerName: string): Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Request notification when one or more workers register.
|
|
465
|
+
*
|
|
466
|
+
* For each name: if the worker is already registered, `onWorkerReady`
|
|
467
|
+
* fires immediately. Otherwise `onWorkerReady` fires when the worker
|
|
468
|
+
* eventually registers.
|
|
469
|
+
*
|
|
470
|
+
* @param workerNames Names of workers to watch for.
|
|
471
|
+
*/
|
|
472
|
+
watchWorkers(...workerNames: string[]): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* Send a job request to a single worker (fire-and-forget).
|
|
475
|
+
*
|
|
476
|
+
* Waits for the worker to be ready before sending the request. Does not
|
|
477
|
+
* wait for the job to complete; use callbacks (`onJobResponse`,
|
|
478
|
+
* `onJobCompleted`) or `job()` for that.
|
|
479
|
+
*
|
|
480
|
+
* @param workerName Name of the worker to send the job to.
|
|
481
|
+
* @param options.params How to run the job. See `JobParams`.
|
|
482
|
+
* @returns The generated jobId.
|
|
483
|
+
*/
|
|
484
|
+
requestJob(workerName: string, options?: JobOptions): Promise<string>;
|
|
485
|
+
/**
|
|
486
|
+
* Create a single-worker job context.
|
|
487
|
+
*
|
|
488
|
+
* Waits for the worker to be ready, sends a job request, and waits for the
|
|
489
|
+
* response on exit. Supports `for await` inside the block to receive
|
|
490
|
+
* intermediate events (updates and streaming data) from the worker while
|
|
491
|
+
* waiting.
|
|
492
|
+
*
|
|
493
|
+
* On normal completion, the result is available via `response`. On worker
|
|
494
|
+
* error or timeout, throws `JobError`.
|
|
495
|
+
*
|
|
496
|
+
* @param workerName Name of the worker to send the job to.
|
|
497
|
+
* @param options.params How to run the job. See `JobParams`.
|
|
498
|
+
* @returns A `JobContext` (Python's `async with` → `await ctx.run(...)`).
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* const t = this.job("worker", { params: new JobParams({ payload: data }) });
|
|
502
|
+
* await t.run(async (t) => {
|
|
503
|
+
* for await (const event of t) {
|
|
504
|
+
* if (event.type === JobEvent.UPDATE) console.log(event.data);
|
|
505
|
+
* }
|
|
506
|
+
* });
|
|
507
|
+
* console.log(t.response);
|
|
508
|
+
*/
|
|
509
|
+
job(workerName: string, options?: JobOptions): JobContext;
|
|
510
|
+
/**
|
|
511
|
+
* Send a job request to multiple workers (fire-and-forget).
|
|
512
|
+
*
|
|
513
|
+
* Waits for all workers to be ready before sending requests. Does not
|
|
514
|
+
* wait for the job group to complete; use callbacks (`onJobResponse`,
|
|
515
|
+
* `onJobCompleted`) or `jobGroup()` for that.
|
|
516
|
+
*
|
|
517
|
+
* @param args Names of the workers to send the job to, optionally followed
|
|
518
|
+
* by `{ params }` (see `JobGroupParams`).
|
|
519
|
+
* @returns The generated jobId shared by all workers in the group.
|
|
520
|
+
* @throws TypeError If a worker name is not a string.
|
|
521
|
+
*/
|
|
522
|
+
requestJobGroup(...args: [...workerNames: string[], options: JobGroupOptions]): Promise<string>;
|
|
523
|
+
requestJobGroup(...workerNames: string[]): Promise<string>;
|
|
524
|
+
/**
|
|
525
|
+
* Create a job group context.
|
|
526
|
+
*
|
|
527
|
+
* Waits for workers to be ready, sends job requests, and waits for all
|
|
528
|
+
* responses on exit. Supports `for await` inside the block to receive
|
|
529
|
+
* intermediate events (updates and streaming data) from workers while
|
|
530
|
+
* waiting.
|
|
531
|
+
*
|
|
532
|
+
* On normal completion, results are available via `responses`. On worker
|
|
533
|
+
* error (with `cancelOnError: true`) or timeout, throws `JobGroupError`.
|
|
534
|
+
*
|
|
535
|
+
* @param args Names of the workers to send the job to, optionally followed
|
|
536
|
+
* by `{ params }` (see `JobGroupParams`).
|
|
537
|
+
* @returns A `JobGroupContext` (Python's `async with` → `await ctx.run(...)`).
|
|
538
|
+
* @throws TypeError If a worker name is not a string.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* const tg = this.jobGroup("w1", "w2", { params: new JobGroupParams({ payload: data }) });
|
|
542
|
+
* await tg.run(async (tg) => {
|
|
543
|
+
* for await (const event of tg) {
|
|
544
|
+
* if (event.type === JobGroupEvent.UPDATE) console.log(`${event.workerName}: ${event.data}`);
|
|
545
|
+
* }
|
|
546
|
+
* });
|
|
547
|
+
* for (const [name, result] of Object.entries(tg.responses)) console.log(name, result);
|
|
548
|
+
*/
|
|
549
|
+
jobGroup(...args: [...workerNames: string[], options: JobGroupOptions]): JobGroupContext;
|
|
550
|
+
jobGroup(...workerNames: string[]): JobGroupContext;
|
|
551
|
+
/**
|
|
552
|
+
* Cancel a running job group.
|
|
553
|
+
*
|
|
554
|
+
* @param jobId The job identifier to cancel.
|
|
555
|
+
* @param options.reason Optional human-readable reason for cancellation.
|
|
556
|
+
*/
|
|
557
|
+
cancelJobGroup(jobId: string, options?: {
|
|
558
|
+
reason?: string | null;
|
|
559
|
+
}): Promise<void>;
|
|
560
|
+
/**
|
|
561
|
+
* Honor an externally requested cancellation, if the group allows it.
|
|
562
|
+
*
|
|
563
|
+
* The door for cancellation asked for from outside the worker, by a client
|
|
564
|
+
* UI or an operator endpoint, which `JobGroupParams.cancellable` governs.
|
|
565
|
+
* Cancellation the worker decides on itself (shutdown, a timeout,
|
|
566
|
+
* `cancelOnError`) goes straight to `cancelJobGroup()` and is never
|
|
567
|
+
* refused.
|
|
568
|
+
*
|
|
569
|
+
* @param jobId The job identifier to cancel.
|
|
570
|
+
* @param options.reason Optional human-readable reason for cancellation.
|
|
571
|
+
* @returns Whether the group was cancelled. False means it is unknown or
|
|
572
|
+
* was dispatched as non-cancellable.
|
|
573
|
+
*/
|
|
574
|
+
requestCancelJobGroup(jobId: string, options?: {
|
|
575
|
+
reason?: string | null;
|
|
576
|
+
}): Promise<boolean>;
|
|
577
|
+
/**
|
|
578
|
+
* Request a progress update from a worker.
|
|
579
|
+
*
|
|
580
|
+
* @param jobId The job identifier.
|
|
581
|
+
* @param workerName The name of the worker to request an update from.
|
|
582
|
+
*/
|
|
583
|
+
requestJobUpdate(jobId: string, workerName: string): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* Wait for workers to be ready, create a job group, and send requests.
|
|
586
|
+
*
|
|
587
|
+
* Waits for all workers to be registered as ready, then creates the group
|
|
588
|
+
* and sends a job request to each worker. Does not wait for the group to
|
|
589
|
+
* complete; call `group.wait()` or use `jobGroup()` for that.
|
|
590
|
+
*
|
|
591
|
+
* @param workerNames Names of the workers to send the job to.
|
|
592
|
+
* @param options.params How to run the group. See `JobGroupParams`.
|
|
593
|
+
* @returns The created `JobGroup`.
|
|
594
|
+
* @throws JobGroupError If workers are not ready within the timeout.
|
|
595
|
+
*/
|
|
596
|
+
createJobGroupAndRequestJob(workerNames: string[], options?: JobGroupOptions): Promise<JobGroup>;
|
|
597
|
+
/**
|
|
598
|
+
* Send a job response back to the requester.
|
|
599
|
+
*
|
|
600
|
+
* After sending, the job is removed from the set of active jobs.
|
|
601
|
+
*
|
|
602
|
+
* @param jobId The identifier of the job being responded to.
|
|
603
|
+
* @param response Optional result data.
|
|
604
|
+
* @param options.status Completion status. Defaults to `JobStatus.COMPLETED`.
|
|
605
|
+
* @param options.urgent When true, the response is delivered with system
|
|
606
|
+
* priority, preempting queued data messages.
|
|
607
|
+
* @throws Error If there is no active job with this `jobId`.
|
|
608
|
+
*/
|
|
609
|
+
sendJobResponse(jobId: string, response?: Dict | null, options?: SendJobResponseOptions): Promise<void>;
|
|
610
|
+
/**
|
|
611
|
+
* Send a progress update to the requester.
|
|
612
|
+
*
|
|
613
|
+
* @param jobId The identifier of the job being updated.
|
|
614
|
+
* @param update Optional progress data.
|
|
615
|
+
* @param options.urgent When true, the update is delivered with system
|
|
616
|
+
* priority, preempting queued data messages.
|
|
617
|
+
* @throws Error If there is no active job with this `jobId`.
|
|
618
|
+
*/
|
|
619
|
+
sendJobUpdate(jobId: string, update?: Dict | null, options?: SendJobUpdateOptions): Promise<void>;
|
|
620
|
+
/**
|
|
621
|
+
* Begin streaming job results back to the requester.
|
|
622
|
+
*
|
|
623
|
+
* @param jobId The identifier of the job being streamed.
|
|
624
|
+
* @param data Optional metadata about the stream.
|
|
625
|
+
* @throws Error If there is no active job with this `jobId`.
|
|
626
|
+
*/
|
|
627
|
+
sendJobStreamStart(jobId: string, data?: Dict | null): Promise<void>;
|
|
628
|
+
/**
|
|
629
|
+
* Send a streaming chunk to the requester.
|
|
630
|
+
*
|
|
631
|
+
* @param jobId The identifier of the job being streamed.
|
|
632
|
+
* @param data The chunk payload.
|
|
633
|
+
* @throws Error If there is no active job with this `jobId`.
|
|
634
|
+
*/
|
|
635
|
+
sendJobStreamData(jobId: string, data?: Dict | null): Promise<void>;
|
|
636
|
+
/**
|
|
637
|
+
* End the current stream and mark this worker's job as complete.
|
|
638
|
+
*
|
|
639
|
+
* After sending, the job is removed from the set of active jobs.
|
|
640
|
+
*
|
|
641
|
+
* @param jobId The identifier of the job being streamed.
|
|
642
|
+
* @param data Optional final metadata.
|
|
643
|
+
* @throws Error If there is no active job with this `jobId`.
|
|
644
|
+
*/
|
|
645
|
+
sendJobStreamEnd(jobId: string, data?: Dict | null): Promise<void>;
|
|
646
|
+
/**
|
|
647
|
+
* Register this worker as ready in the shared registry.
|
|
648
|
+
*
|
|
649
|
+
* The registry notifies watchers (parent for children, runner for root
|
|
650
|
+
* workers).
|
|
651
|
+
*/
|
|
652
|
+
protected _registerReady(): Promise<void>;
|
|
653
|
+
/** Activate the worker, call onActivated, and fire event handlers. */
|
|
654
|
+
protected _maybeActivate(): Promise<void>;
|
|
655
|
+
/** Register watches for all `workerReady` decorated handlers. */
|
|
656
|
+
protected _watchDecoratedWorkers(): Promise<void>;
|
|
657
|
+
/**
|
|
658
|
+
* Called when a watched worker is ready.
|
|
659
|
+
*
|
|
660
|
+
* Dispatches to the `workerReady` handler if one exists for this worker,
|
|
661
|
+
* otherwise proxies to `onWorkerReady`.
|
|
662
|
+
*/
|
|
663
|
+
protected _onWatchedWorkerReady(data: WorkerReadyData): Promise<void>;
|
|
664
|
+
/** Handle an error reported by a child or remote worker. */
|
|
665
|
+
protected _handleWorkerError(message: BusWorkerErrorMessage | BusWorkerLocalErrorMessage): Promise<void>;
|
|
666
|
+
/**
|
|
667
|
+
* Handle an activation message.
|
|
668
|
+
*
|
|
669
|
+
* Stores the activation arguments and marks the worker as pending
|
|
670
|
+
* activation, then delegates to `_maybeActivate()`.
|
|
671
|
+
*
|
|
672
|
+
* @param message The `BusActivateWorkerMessage` requesting activation.
|
|
673
|
+
*/
|
|
674
|
+
protected _handleWorkerActivate(message: BusActivateWorkerMessage): Promise<void>;
|
|
675
|
+
/**
|
|
676
|
+
* Deactivate this worker.
|
|
677
|
+
*
|
|
678
|
+
* @param message The `BusDeactivateWorkerMessage` requesting deactivation.
|
|
679
|
+
*/
|
|
680
|
+
protected _handleWorkerDeactivate(_message: BusDeactivateWorkerMessage): Promise<void>;
|
|
681
|
+
/**
|
|
682
|
+
* Propagate end to children, wait for them, then stop this worker.
|
|
683
|
+
*
|
|
684
|
+
* Subclasses with their own runtime (e.g. `PipelineWorker`) call
|
|
685
|
+
* `_propagateEndToChildren()` directly and drive their own shutdown so
|
|
686
|
+
* `_finishedEvent` fires at the right moment.
|
|
687
|
+
*
|
|
688
|
+
* @param message The `BusEndWorkerMessage` requesting a graceful end.
|
|
689
|
+
*/
|
|
690
|
+
protected _handleWorkerEnd(message: BusEndWorkerMessage): Promise<void>;
|
|
691
|
+
/**
|
|
692
|
+
* Propagate cancel to children, then stop this worker.
|
|
693
|
+
*
|
|
694
|
+
* Subclasses with their own runtime (e.g. `PipelineWorker`) call
|
|
695
|
+
* `_propagateCancelToChildren()` directly and drive their own shutdown so
|
|
696
|
+
* `_finishedEvent` fires at the right moment.
|
|
697
|
+
*
|
|
698
|
+
* @param message The `BusCancelWorkerMessage` requesting cancellation.
|
|
699
|
+
*/
|
|
700
|
+
protected _handleWorkerCancel(message: BusCancelWorkerMessage): Promise<void>;
|
|
701
|
+
/** Forward a `BusEndWorkerMessage` to each child and wait for them. */
|
|
702
|
+
protected _propagateEndToChildren(message: BusEndWorkerMessage): Promise<void>;
|
|
703
|
+
/** Forward a `BusCancelWorkerMessage` to each child. */
|
|
704
|
+
protected _propagateCancelToChildren(message: BusCancelWorkerMessage): Promise<void>;
|
|
705
|
+
/**
|
|
706
|
+
* Handle an incoming job request.
|
|
707
|
+
*
|
|
708
|
+
* Dispatches to `job()` handlers if any match, otherwise falls back to
|
|
709
|
+
* onJobRequest. The handler always runs in its own task so the bus message
|
|
710
|
+
* loop is never blocked. When the matched handler is marked
|
|
711
|
+
* `sequential: true`, requests with the same job name are queued and run
|
|
712
|
+
* one at a time in FIFO order.
|
|
713
|
+
*/
|
|
714
|
+
protected _handleJobRequest(message: BusJobRequestMessage): Promise<void>;
|
|
715
|
+
protected _runJobHandler(jobId: string, handler: JobHandlerFn, message: BusJobRequestMessage, lock?: Lock | null): Promise<void>;
|
|
716
|
+
/** Handle a job response and track group completion. */
|
|
717
|
+
protected _handleJobResponse(message: BusJobResponseMessage | BusJobResponseUrgentMessage): Promise<void>;
|
|
718
|
+
/**
|
|
719
|
+
* Record that a worker of a group has reached a terminal state.
|
|
720
|
+
*
|
|
721
|
+
* A worker terminates either by responding or by ending its stream.
|
|
722
|
+
* `cancelJobGroup` reads this to tell apart the workers a cancellation
|
|
723
|
+
* actually cut short from those that had already finished on their own.
|
|
724
|
+
*/
|
|
725
|
+
protected _markWorkerTerminated(jobId: string, workerName: string): void;
|
|
726
|
+
/** Handle a job progress update. */
|
|
727
|
+
protected _handleJobUpdate(message: BusJobUpdateMessage | BusJobUpdateUrgentMessage): Promise<void>;
|
|
728
|
+
/** Handle a job update request from the requester. */
|
|
729
|
+
protected _handleJobUpdateRequest(message: BusJobUpdateRequestMessage): Promise<void>;
|
|
730
|
+
/**
|
|
731
|
+
* Handle a job cancellation.
|
|
732
|
+
*
|
|
733
|
+
* Cancels the running handler task (if any), calls the `onJobCancelled`
|
|
734
|
+
* hook for cleanup, then automatically sends a cancelled response back to
|
|
735
|
+
* the requester. The requester receives `onJobResponse` with
|
|
736
|
+
* `status: "cancelled"`, same path as completed or failed jobs.
|
|
737
|
+
*/
|
|
738
|
+
protected _handleJobCancel(message: BusJobCancelMessage): Promise<void>;
|
|
739
|
+
/** Handle the start of a streaming job response. */
|
|
740
|
+
protected _handleJobStreamStart(message: BusJobStreamStartMessage): Promise<void>;
|
|
741
|
+
/** Handle a streaming job data chunk. */
|
|
742
|
+
protected _handleJobStreamData(message: BusJobStreamDataMessage): Promise<void>;
|
|
743
|
+
/** Handle the end of a streaming job response. */
|
|
744
|
+
protected _handleJobStreamEnd(message: BusJobStreamEndMessage): Promise<void>;
|
|
745
|
+
protected _createJobGroup(workerNames: string[], options: {
|
|
746
|
+
params: JobGroupParams;
|
|
747
|
+
}): JobGroup;
|
|
748
|
+
/**
|
|
749
|
+
* Return a coroutine function that resolves when all named workers are ready.
|
|
750
|
+
*
|
|
751
|
+
* The watches are registered before this returns; callers race the
|
|
752
|
+
* returned function against a timeout (`waitFor(allReady, timeout)`) or a
|
|
753
|
+
* group done signal. Upstream returns an `asyncio.Future`; a function is
|
|
754
|
+
* returned here because awaiting an async function that returns a Task
|
|
755
|
+
* would adopt (wait for) it.
|
|
756
|
+
*
|
|
757
|
+
* @throws Error If the registry is not available.
|
|
758
|
+
*/
|
|
759
|
+
protected _waitWorkersReady(workerNames: string[]): Promise<TaskFn<void>>;
|
|
760
|
+
protected _sendJobRequest(workerName: string, jobId: string, options?: {
|
|
761
|
+
jobName?: string | null;
|
|
762
|
+
payload?: Dict | null;
|
|
763
|
+
}): Promise<void>;
|
|
764
|
+
protected _taskTimeout(jobId: string, timeout: number): Promise<void>;
|
|
765
|
+
protected _pushJobGroupEvent(jobId: string, event: JobGroupEvent): void;
|
|
766
|
+
/** Record a worker's response and fire completion when all have responded. */
|
|
767
|
+
protected _trackJobGroupResponse(jobId: string, source: string, response: Dict | null): Promise<void>;
|
|
768
|
+
/** Warn about tasks left running on the task manager this worker owns. */
|
|
769
|
+
protected _printDanglingTasks(): void;
|
|
770
|
+
}
|
|
771
|
+
export {};
|
|
772
|
+
//# sourceMappingURL=base_worker.d.ts.map
|