@qvac/inference 0.18.2 → 0.19.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/NOTICE +11 -2
- package/README.md +1 -5
- package/dist/api/assess-model-fit.d.ts +16 -0
- package/dist/api/assess-model-fit.js +27 -0
- package/dist/api/audio-gen.d.ts +4 -4
- package/dist/api/audio-gen.js +17 -6
- package/dist/api/completion-stream.d.ts +1 -1
- package/dist/api/completion-stream.js +1 -1
- package/dist/api/download-asset.d.ts +1 -1
- package/dist/api/download-asset.js +2 -2
- package/dist/api/finetune.js +1 -1
- package/dist/api/get-loaded-model-info.d.ts +6 -10
- package/dist/api/get-loaded-model-info.js +6 -10
- package/dist/api/heartbeat.d.ts +5 -22
- package/dist/api/heartbeat.js +6 -23
- package/dist/api/index.d.ts +36 -35
- package/dist/api/index.js +35 -35
- package/dist/api/load-model.d.ts +5 -1
- package/dist/api/load-model.js +3 -5
- package/dist/api/logging-stream-registry.js +1 -1
- package/dist/api/resume.d.ts +0 -3
- package/dist/api/resume.js +0 -3
- package/dist/api/subscribe-logs.js +1 -1
- package/dist/api/suspend.d.ts +0 -4
- package/dist/api/suspend.js +0 -4
- package/dist/api/translate.d.ts +3 -1
- package/dist/api/translate.js +16 -8
- package/dist/api/unload-model.js +3 -5
- package/dist/api/video-request.d.ts +207 -0
- package/dist/api/video-request.js +18 -0
- package/dist/api/video.d.ts +22 -2
- package/dist/api/video.js +25 -15
- package/dist/api/vla-helpers.d.ts +1 -2
- package/dist/api/vla-helpers.js +1 -2
- package/dist/api/vla.js +1 -1
- package/dist/api/world-result.d.ts +71 -0
- package/dist/api/world-result.js +293 -0
- package/dist/api/world.d.ts +143 -0
- package/dist/api/world.js +71 -0
- package/dist/config/resolve-config.d.ts +1 -1
- package/dist/config/resolve-config.js +1 -1
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +2 -2
- package/dist/dispatch.js +15 -28
- package/dist/errors/index.d.ts +35 -31
- package/dist/errors/index.js +66 -56
- package/dist/handlers/assess-model-fit.d.ts +10 -0
- package/dist/handlers/assess-model-fit.js +75 -0
- package/dist/handlers/cancelHandler.js +1 -1
- package/dist/handlers/completion-orchestrate.js +1 -1
- package/dist/handlers/download-asset.js +6 -5
- package/dist/handlers/finetune.js +1 -1
- package/dist/handlers/get-loaded-model-info.js +0 -12
- package/dist/handlers/get-model-info.js +1 -1
- package/dist/handlers/get-system-resources.js +8 -0
- package/dist/handlers/load-model/download-manager.d.ts +1 -1
- package/dist/handlers/load-model/download-stats.d.ts +3 -3
- package/dist/handlers/load-model/download-stats.js +5 -5
- package/dist/handlers/load-model/handler.js +6 -8
- package/dist/handlers/load-model/http-verify.d.ts +20 -0
- package/dist/handlers/load-model/http-verify.js +54 -0
- package/dist/handlers/load-model/http.d.ts +12 -2
- package/dist/handlers/load-model/http.js +119 -230
- package/dist/handlers/load-model/hyperdrive.d.ts +1 -1
- package/dist/handlers/load-model/hyperdrive.js +1 -1
- package/dist/handlers/load-model/index.d.ts +2 -2
- package/dist/handlers/load-model/index.js +2 -2
- package/dist/handlers/load-model/registry-companion-set.d.ts +1 -1
- package/dist/handlers/load-model/registry-companion-set.js +1 -1
- package/dist/handlers/load-model/registry-download-utils.d.ts +3 -3
- package/dist/handlers/load-model/registry-download-utils.js +2 -2
- package/dist/handlers/load-model/registry.d.ts +2 -2
- package/dist/handlers/load-model/registry.js +4 -4
- package/dist/handlers/load-model/resolve-session.d.ts +8 -1
- package/dist/handlers/load-model/resolve-session.js +12 -9
- package/dist/handlers/load-model/resolve.d.ts +4 -4
- package/dist/handlers/load-model/resolve.js +18 -16
- package/dist/handlers/load-model/safe-fetch.d.ts +44 -0
- package/dist/handlers/load-model/safe-fetch.js +143 -0
- package/dist/handlers/load-model/types.d.ts +9 -0
- package/dist/handlers/plugin-dispatch.js +1 -4
- package/dist/handlers/plugin-invoke.js +1 -4
- package/dist/handlers/types.d.ts +0 -2
- package/dist/handlers/unload-model.js +1 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/logging/addon.d.ts +1 -1
- package/dist/logging/addon.js +1 -1
- package/dist/logging/index.d.ts +5 -5
- package/dist/logging/index.js +4 -4
- package/dist/logging/logger.d.ts +1 -1
- package/dist/logging/logger.js +2 -2
- package/dist/models/registry/index.d.ts +1 -1
- package/dist/models/registry/index.js +2 -2
- package/dist/models/registry/models.d.ts +250 -0
- package/dist/models/registry/models.js +2071 -1806
- package/dist/models/registry/resource-profiles.d.ts +18 -0
- package/dist/models/registry/resource-profiles.js +4934 -0
- package/dist/plugins/builtin/audiogen-ggml/config.d.ts +14 -0
- package/dist/plugins/builtin/audiogen-ggml/config.js +23 -0
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +47 -5
- package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +134 -4
- package/dist/plugins/builtin/audiogen-ggml/plugin.js +47 -28
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +1 -1
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +3 -3
- package/dist/plugins/builtin/ggml-classification/plugin.js +1 -1
- package/dist/plugins/builtin/ggml-ocr/plugin.js +2 -2
- package/dist/plugins/builtin/ggml-vla/plugin.d.ts +1 -1
- package/dist/plugins/builtin/ggml-vla/plugin.js +3 -3
- package/dist/plugins/builtin/index.d.ts +12 -12
- package/dist/plugins/builtin/index.js +12 -12
- package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +2 -2
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +37 -26
- package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.d.ts +12 -11
- package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.js +133 -41
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +7 -1
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +26 -4
- package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +19 -8
- package/dist/plugins/builtin/llamacpp-completion/plugin.js +10 -13
- package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +4 -0
- package/dist/plugins/builtin/llamacpp-embedding/plugin.js +13 -2
- package/dist/plugins/builtin/nmtcpp-translation/plugin.js +2 -2
- package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +2 -2
- package/dist/plugins/builtin/parakeet-transcription/plugin.js +3 -3
- package/dist/plugins/builtin/sdcpp-generation/ops/upscale.js +1 -1
- package/dist/plugins/builtin/sdcpp-generation/ops/video.js +32 -2
- package/dist/plugins/builtin/sdcpp-generation/ops/world.d.ts +126 -0
- package/dist/plugins/builtin/sdcpp-generation/ops/world.js +820 -0
- package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +153 -4
- package/dist/plugins/builtin/sdcpp-generation/plugin.js +134 -13
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +1 -1
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +1 -1
- package/dist/plugins/builtin/tts-ggml/plugin.js +2 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +2 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.js +3 -3
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/ops/kv-cache-utils.js +1 -1
- package/dist/plugins/ops/load-model.js +1 -1
- package/dist/plugins/ops/transcribe.js +2 -2
- package/dist/plugins/ops/translate.js +4 -12
- package/dist/plugins/ops/unload-model.js +19 -21
- package/dist/plugins/registry.d.ts +1 -0
- package/dist/plugins/registry.js +12 -0
- package/dist/profiling/aggregator.d.ts +1 -1
- package/dist/profiling/aggregator.js +1 -1
- package/dist/profiling/controller.d.ts +1 -1
- package/dist/profiling/controller.js +2 -2
- package/dist/profiling/envelope.d.ts +0 -1
- package/dist/profiling/envelope.js +0 -10
- package/dist/profiling/events.d.ts +2 -3
- package/dist/profiling/events.js +2 -9
- package/dist/profiling/exporters.d.ts +1 -1
- package/dist/profiling/exporters.js +3 -3
- package/dist/profiling/index.d.ts +13 -14
- package/dist/profiling/index.js +12 -13
- package/dist/profiling/operation-metrics.d.ts +1 -1
- package/dist/profiling/operation-metrics.js +35 -2
- package/dist/profiling/operation-wrappers.js +12 -15
- package/dist/profiling/profiler.d.ts +1 -2
- package/dist/profiling/profiler.js +7 -26
- package/dist/profiling/types.d.ts +1 -1
- package/dist/rag/handler.js +1 -1
- package/dist/rag/handlers/close-workspace.js +1 -1
- package/dist/rag/handlers/delete-embeddings.js +1 -1
- package/dist/rag/handlers/delete-workspace.js +2 -6
- package/dist/rag/handlers/ingest.js +1 -1
- package/dist/rag/handlers/list-workspaces.d.ts +1 -1
- package/dist/rag/handlers/list-workspaces.js +1 -1
- package/dist/rag/handlers/reindex.js +1 -1
- package/dist/rag/handlers/save-embeddings.js +1 -1
- package/dist/rag/handlers/search.js +1 -1
- package/dist/rag/index.d.ts +11 -11
- package/dist/rag/index.js +11 -11
- package/dist/rag/rag-workspace-manager.d.ts +4 -2
- package/dist/rag/rag-workspace-manager.js +268 -15
- package/dist/registry.js +8 -58
- package/dist/resources/collector.d.ts +3 -1
- package/dist/resources/collector.js +91 -9
- package/dist/resources/instance.d.ts +1 -1
- package/dist/resources/instance.js +1 -1
- package/dist/resources/model-fit/assess.d.ts +36 -0
- package/dist/resources/model-fit/assess.js +578 -0
- package/dist/resources/model-fit/calibration/darwin-arm64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/darwin-arm64.js +36 -0
- package/dist/resources/model-fit/calibration/darwin-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/darwin-x64.js +38 -0
- package/dist/resources/model-fit/calibration/fit.d.ts +73 -0
- package/dist/resources/model-fit/calibration/fit.js +152 -0
- package/dist/resources/model-fit/calibration/index.d.ts +37 -0
- package/dist/resources/model-fit/calibration/index.js +75 -0
- package/dist/resources/model-fit/calibration/linux-arm64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-arm64.js +38 -0
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.js +39 -0
- package/dist/resources/model-fit/calibration/linux-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-x64.js +38 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.js +39 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.js +36 -0
- package/dist/resources/model-fit/calibration/win32-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64.js +38 -0
- package/dist/resources/model-fit/estimators/llm.d.ts +45 -0
- package/dist/resources/model-fit/estimators/llm.js +220 -0
- package/dist/resources/model-fit/estimators/whisper.d.ts +10 -0
- package/dist/resources/model-fit/estimators/whisper.js +77 -0
- package/dist/resources/model-fit/types.d.ts +120 -0
- package/dist/resources/model-fit/types.js +1 -0
- package/dist/resources/native.d.ts +1 -1
- package/dist/resources/native.js +14 -0
- package/dist/resources/normalize.d.ts +1 -1
- package/dist/resources/types.d.ts +16 -0
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/lifecycle.js +5 -7
- package/dist/runtime/model-registry.d.ts +0 -14
- package/dist/runtime/model-registry.js +17 -40
- package/dist/runtime/registry-client.js +1 -1
- package/dist/runtime/request-context.d.ts +3 -3
- package/dist/runtime/request-context.js +13 -1
- package/dist/runtime/request-registry.d.ts +1 -1
- package/dist/runtime/request-registry.js +4 -5
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +18 -3
- package/dist/schemas/assess-model-fit.d.ts +271 -0
- package/dist/schemas/assess-model-fit.js +153 -0
- package/dist/schemas/audio-gen.d.ts +434 -4
- package/dist/schemas/audio-gen.js +131 -19
- package/dist/schemas/batch-completion-stream.d.ts +2 -2
- package/dist/schemas/batch-completion-stream.js +3 -3
- package/dist/schemas/bci-config.js +73 -27
- package/dist/schemas/bci.d.ts +2 -2
- package/dist/schemas/bci.js +5 -5
- package/dist/schemas/cancel.d.ts +5 -0
- package/dist/schemas/cancel.js +1 -0
- package/dist/schemas/classification.js +13 -6
- package/dist/schemas/common.d.ts +662 -331
- package/dist/schemas/common.js +33 -31
- package/dist/schemas/completion-event.d.ts +2 -2
- package/dist/schemas/completion-event.js +1 -1
- package/dist/schemas/completion-stream.d.ts +1 -5
- package/dist/schemas/completion-stream.js +4 -8
- package/dist/schemas/config.d.ts +640 -18
- package/dist/schemas/config.js +50 -8
- package/dist/schemas/download-asset.d.ts +19 -1
- package/dist/schemas/download-asset.js +20 -4
- package/dist/schemas/engine-addon-map.d.ts +1 -1
- package/dist/schemas/engine-addon-map.js +3 -3
- package/dist/schemas/error.d.ts +2 -2
- package/dist/schemas/error.js +2 -2
- package/dist/schemas/errors.d.ts +2 -6
- package/dist/schemas/errors.js +30 -40
- package/dist/schemas/heartbeat.d.ts +10 -0
- package/dist/schemas/heartbeat.js +8 -0
- package/dist/schemas/index.d.ts +46 -44
- package/dist/schemas/index.js +45 -43
- package/dist/schemas/llamacpp-config.d.ts +32 -10
- package/dist/schemas/llamacpp-config.js +11 -8
- package/dist/schemas/load-model.d.ts +2933 -1948
- package/dist/schemas/load-model.js +52 -52
- package/dist/schemas/mcp-adapter.d.ts +1 -1
- package/dist/schemas/model-config-schemas.d.ts +2354 -0
- package/dist/schemas/model-config-schemas.js +46 -0
- package/dist/schemas/model-info.d.ts +10 -20
- package/dist/schemas/model-info.js +4 -25
- package/dist/schemas/model-ops.d.ts +0 -1
- package/dist/schemas/model-ops.js +1 -2
- package/dist/schemas/model-resource-profile.d.ts +109 -0
- package/dist/schemas/model-resource-profile.js +83 -0
- package/dist/schemas/model-src-utils.d.ts +1 -0
- package/dist/schemas/model-src-utils.js +33 -13
- package/dist/schemas/ocr.js +48 -13
- package/dist/schemas/path-validation.js +8 -2
- package/dist/schemas/plugin.d.ts +14 -1
- package/dist/schemas/plugin.js +11 -0
- package/dist/schemas/profiling.d.ts +138 -43
- package/dist/schemas/profiling.js +1 -22
- package/dist/schemas/rag.js +1 -1
- package/dist/schemas/registry.js +1 -1
- package/dist/schemas/reload-config.d.ts +0 -2
- package/dist/schemas/reload-config.js +2 -3
- package/dist/schemas/sdcpp-config.d.ts +344 -4
- package/dist/schemas/sdcpp-config.js +504 -17
- package/dist/schemas/system-resources.d.ts +138 -0
- package/dist/schemas/system-resources.js +3 -1
- package/dist/schemas/text-to-speech.js +183 -76
- package/dist/schemas/transcription-config.js +253 -85
- package/dist/schemas/transcription.d.ts +3 -3
- package/dist/schemas/translate.d.ts +2 -2
- package/dist/schemas/translate.js +1 -1
- package/dist/schemas/translation-config.js +53 -25
- package/dist/schemas/vla.d.ts +1 -1
- package/dist/selection.d.ts +1 -5
- package/dist/selection.js +2 -6
- package/dist/surface.d.ts +1 -1
- package/dist/utils/aggregate-events.d.ts +1 -1
- package/dist/utils/aggregate-events.js +2 -2
- package/dist/utils/archive.js +2 -2
- package/dist/utils/audio-input.js +1 -1
- package/dist/utils/cache/auto-history.d.ts +1 -1
- package/dist/utils/cache/auto-history.js +1 -1
- package/dist/utils/cache/paths.js +5 -5
- package/dist/utils/completion-normalizer.js +1 -1
- package/dist/utils/gguf-tensor-extractor.js +1 -1
- package/dist/utils/image-dimensions.d.ts +26 -0
- package/dist/utils/image-dimensions.js +46 -0
- package/dist/utils/index.d.ts +13 -10
- package/dist/utils/index.js +13 -10
- package/dist/utils/mcp-adapter.d.ts +1 -1
- package/dist/utils/mcp-adapter.js +1 -1
- package/dist/utils/path-sanitize.d.ts +7 -0
- package/dist/utils/path-sanitize.js +36 -0
- package/dist/utils/path-security.d.ts +0 -7
- package/dist/utils/path-security.js +1 -36
- package/dist/utils/shard-utils.js +3 -3
- package/dist/utils/tool-integration.js +1 -1
- package/dist/utils/tools/dialect.js +1 -1
- package/dist/utils/tools/index.d.ts +2 -2
- package/dist/utils/tools/index.js +2 -2
- package/dist/utils/tools/parser.js +8 -8
- package/dist/utils/tools/parsers/dsml.d.ts +1 -1
- package/dist/utils/tools/parsers/dsml.js +1 -1
- package/dist/utils/tools/parsers/gemma4native.d.ts +1 -1
- package/dist/utils/tools/parsers/gemma4native.js +1 -1
- package/dist/utils/tools/parsers/harmony.d.ts +1 -1
- package/dist/utils/tools/parsers/harmony.js +1 -1
- package/dist/utils/tools/parsers/hermes.d.ts +1 -1
- package/dist/utils/tools/parsers/hermes.js +1 -1
- package/dist/utils/tools/parsers/json.d.ts +1 -1
- package/dist/utils/tools/parsers/json.js +1 -1
- package/dist/utils/tools/parsers/pythonic.d.ts +1 -1
- package/dist/utils/tools/parsers/pythonic.js +1 -1
- package/dist/utils/tools/parsers/qwen35.d.ts +1 -1
- package/dist/utils/tools/parsers/qwen35.js +3 -3
- package/dist/utils/url-security.d.ts +17 -0
- package/dist/utils/url-security.js +75 -0
- package/package.json +31 -26
- package/dist/api/provide.d.ts +0 -23
- package/dist/api/provide.js +0 -32
- package/dist/api/stop-provider.d.ts +0 -20
- package/dist/api/stop-provider.js +0 -30
- package/dist/p2p/cancel-delegated.d.ts +0 -3
- package/dist/p2p/cancel-delegated.js +0 -64
- package/dist/p2p/completion-stream-delegated.d.ts +0 -4
- package/dist/p2p/completion-stream-delegated.js +0 -51
- package/dist/p2p/delegate-client.d.ts +0 -9
- package/dist/p2p/delegate-client.js +0 -219
- package/dist/p2p/delegate-connect-diagnostics.d.ts +0 -8
- package/dist/p2p/delegate-connect-diagnostics.js +0 -38
- package/dist/p2p/delegate-transport.d.ts +0 -18
- package/dist/p2p/delegate-transport.js +0 -237
- package/dist/p2p/error-handlers.d.ts +0 -4
- package/dist/p2p/error-handlers.js +0 -31
- package/dist/p2p/handle-request.d.ts +0 -2
- package/dist/p2p/handle-request.js +0 -171
- package/dist/p2p/handler-utils.d.ts +0 -19
- package/dist/p2p/handler-utils.js +0 -180
- package/dist/p2p/heartbeat-delegated.d.ts +0 -3
- package/dist/p2p/heartbeat-delegated.js +0 -32
- package/dist/p2p/load-model-delegated.d.ts +0 -6
- package/dist/p2p/load-model-delegated.js +0 -132
- package/dist/p2p/progress-throttle.d.ts +0 -7
- package/dist/p2p/progress-throttle.js +0 -47
- package/dist/p2p/provideHandler/connection.d.ts +0 -2
- package/dist/p2p/provideHandler/connection.js +0 -38
- package/dist/p2p/provideHandler/handler.d.ts +0 -2
- package/dist/p2p/provideHandler/handler.js +0 -66
- package/dist/p2p/provideHandler/proxy.d.ts +0 -2
- package/dist/p2p/provideHandler/proxy.js +0 -24
- package/dist/p2p/provideHandler.d.ts +0 -1
- package/dist/p2p/provideHandler.js +0 -2
- package/dist/p2p/rpc-utils.d.ts +0 -4
- package/dist/p2p/rpc-utils.js +0 -8
- package/dist/p2p/stopProvideHandler.d.ts +0 -2
- package/dist/p2p/stopProvideHandler.js +0 -29
- package/dist/p2p/swarm.d.ts +0 -9
- package/dist/p2p/swarm.js +0 -103
- package/dist/p2p/transport-selector.d.ts +0 -2
- package/dist/p2p/transport-selector.js +0 -18
- package/dist/p2p/unload-model-delegated.d.ts +0 -2
- package/dist/p2p/unload-model-delegated.js +0 -31
- package/dist/profiling/delegation-profiler.d.ts +0 -31
- package/dist/profiling/delegation-profiler.js +0 -155
- package/dist/schemas/delegate.d.ts +0 -29
- package/dist/schemas/delegate.js +0 -40
- package/dist/schemas/provide.d.ts +0 -50
- package/dist/schemas/provide.js +0 -32
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side RPC transport for delegated requests.
|
|
3
|
-
*
|
|
4
|
-
* This module provides `send` and `stream` functions for server-side
|
|
5
|
-
* delegation to remote peers (via HyperSwarm RPC).
|
|
6
|
-
*/
|
|
7
|
-
import { requestSchema, responseSchema, PROFILING_KEY, PROFILING_TRAILER_KEY, DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY } from '../schemas/index.js';
|
|
8
|
-
import { nowMs, extractProfilingMeta, stripProfilingMeta, recordFailure, generateId, createDelegatedProfilingMeta } from '../profiling/index.js';
|
|
9
|
-
import { withTimeout, withTimeoutStream } from '../utils/withTimeout.js';
|
|
10
|
-
import { getEngineLogger } from '../logging/index.js';
|
|
11
|
-
import { DelegateProviderError } from '../errors/index.js';
|
|
12
|
-
import { cleanupStaleConnection } from '../p2p/delegate-client.js';
|
|
13
|
-
import { shouldProfileDelegation, createDelegationTimings, createDelegationStreamTimings, recordDelegationEvents, recordDelegationStreamEvents, buildDelegationStreamBreakdown, flushServerConnectionEvent, consumeBreakdownConnectionTime } from '../profiling/delegation-profiler.js';
|
|
14
|
-
const logger = getEngineLogger();
|
|
15
|
-
import { getNextCommandId } from '../p2p/rpc-utils.js';
|
|
16
|
-
function checkAndThrowError(response) {
|
|
17
|
-
if (response.type === 'error') {
|
|
18
|
-
throw new DelegateProviderError(response.message || 'Unknown provider error', response.code);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function isConnectionError(error) {
|
|
22
|
-
return !(error instanceof DelegateProviderError);
|
|
23
|
-
}
|
|
24
|
-
function cleanupDelegationPeer(options, error) {
|
|
25
|
-
if (!options?.peerKey)
|
|
26
|
-
return;
|
|
27
|
-
if (error !== undefined && !isConnectionError(error))
|
|
28
|
-
return;
|
|
29
|
-
cleanupStaleConnection(options.peerKey);
|
|
30
|
-
}
|
|
31
|
-
export async function send(request, rpc, options) {
|
|
32
|
-
const { profilingMeta } = options ?? {};
|
|
33
|
-
const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
|
|
34
|
-
if (!shouldProfile) {
|
|
35
|
-
return sendBase(request, rpc, options, profilingMeta);
|
|
36
|
-
}
|
|
37
|
-
return sendProfiled(request, rpc, options, profilingMeta);
|
|
38
|
-
}
|
|
39
|
-
async function sendBase(request, rpc, options, profilingMeta) {
|
|
40
|
-
try {
|
|
41
|
-
const parsedRequest = requestSchema.parse(request);
|
|
42
|
-
const req = rpc.request(getNextCommandId());
|
|
43
|
-
logger.debug('[delegate-transport] Sending:', { type: request.type });
|
|
44
|
-
// Propagate per-call disable signal to delegated provider
|
|
45
|
-
const finalRequest = profilingMeta?.enabled === false
|
|
46
|
-
? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
|
|
47
|
-
: parsedRequest;
|
|
48
|
-
const payload = JSON.stringify(finalRequest);
|
|
49
|
-
req.send(payload, 'utf-8');
|
|
50
|
-
const response = await withTimeout(req.reply('utf-8'), options?.timeout);
|
|
51
|
-
const rawPayload = JSON.parse(response?.toString() || '{}');
|
|
52
|
-
const resPayload = responseSchema.parse(stripProfilingMeta(rawPayload));
|
|
53
|
-
logger.debug('[delegate-transport] Response:', { type: resPayload.type });
|
|
54
|
-
checkAndThrowError(resPayload);
|
|
55
|
-
return resPayload;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
cleanupDelegationPeer(options, error);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async function sendProfiled(request, rpc, options, profilingMeta) {
|
|
63
|
-
const profileId = profilingMeta?.id ?? generateId();
|
|
64
|
-
const timings = createDelegationTimings(profileId, request.type);
|
|
65
|
-
try {
|
|
66
|
-
if (options?.peerKey) {
|
|
67
|
-
flushServerConnectionEvent(options.peerKey);
|
|
68
|
-
}
|
|
69
|
-
const connectionMs = options?.peerKey
|
|
70
|
-
? consumeBreakdownConnectionTime(options.peerKey)
|
|
71
|
-
: undefined;
|
|
72
|
-
const parsedRequest = requestSchema.parse(request);
|
|
73
|
-
const req = rpc.request(getNextCommandId());
|
|
74
|
-
logger.debug('[delegate-transport] Sending (profiled):', {
|
|
75
|
-
type: request.type
|
|
76
|
-
});
|
|
77
|
-
const stringifyStart = nowMs();
|
|
78
|
-
const requestWithProfiling = {
|
|
79
|
-
...parsedRequest,
|
|
80
|
-
[PROFILING_KEY]: createDelegatedProfilingMeta(profileId, profilingMeta)
|
|
81
|
-
};
|
|
82
|
-
const payload = JSON.stringify(requestWithProfiling);
|
|
83
|
-
timings.requestStringifyMs = nowMs() - stringifyStart;
|
|
84
|
-
timings.sendStart = nowMs();
|
|
85
|
-
req.send(payload, 'utf-8');
|
|
86
|
-
const response = await withTimeout(req.reply('utf-8'), options?.timeout);
|
|
87
|
-
timings.firstResponseAt = nowMs();
|
|
88
|
-
const parseStart = nowMs();
|
|
89
|
-
const rawPayload = JSON.parse(response?.toString() || '{}');
|
|
90
|
-
timings.responseJsonParseMs = nowMs() - parseStart;
|
|
91
|
-
const serverMeta = extractProfilingMeta(rawPayload);
|
|
92
|
-
const cleanPayload = stripProfilingMeta(rawPayload);
|
|
93
|
-
const resPayload = responseSchema.parse(cleanPayload);
|
|
94
|
-
logger.debug('[delegate-transport] Response (profiled):', {
|
|
95
|
-
type: resPayload.type
|
|
96
|
-
});
|
|
97
|
-
checkAndThrowError(resPayload);
|
|
98
|
-
const delegationBreakdown = recordDelegationEvents(timings, serverMeta, connectionMs);
|
|
99
|
-
resPayload[DELEGATION_BREAKDOWN_KEY] = delegationBreakdown;
|
|
100
|
-
if (serverMeta?.operation) {
|
|
101
|
-
resPayload[OPERATION_EVENT_KEY] = serverMeta.operation;
|
|
102
|
-
}
|
|
103
|
-
return resPayload;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
cleanupDelegationPeer(options, error);
|
|
107
|
-
const base = {
|
|
108
|
-
ts: nowMs(),
|
|
109
|
-
op: timings.requestType,
|
|
110
|
-
kind: 'delegation',
|
|
111
|
-
profileId: timings.profileId
|
|
112
|
-
};
|
|
113
|
-
recordFailure(base, timings.requestStart, error);
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
export async function* stream(request, rpc, options = {}) {
|
|
118
|
-
const { profilingMeta } = options;
|
|
119
|
-
const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
|
|
120
|
-
if (!shouldProfile) {
|
|
121
|
-
yield* streamBase(request, rpc, options, profilingMeta);
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
yield* streamProfiled(request, rpc, options, profilingMeta);
|
|
125
|
-
}
|
|
126
|
-
async function* streamBase(request, rpc, options = {}, profilingMeta) {
|
|
127
|
-
try {
|
|
128
|
-
const parsedRequest = requestSchema.parse(request);
|
|
129
|
-
const req = rpc.request(getNextCommandId());
|
|
130
|
-
logger.debug('[delegate-transport] Streaming:', { type: request.type });
|
|
131
|
-
// Propagate per-call disable signal to delegated provider
|
|
132
|
-
const finalRequest = profilingMeta?.enabled === false
|
|
133
|
-
? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
|
|
134
|
-
: parsedRequest;
|
|
135
|
-
req.send(JSON.stringify(finalRequest), 'utf-8');
|
|
136
|
-
const responseStream = req.createResponseStream({ encoding: 'utf-8' });
|
|
137
|
-
let buffer = '';
|
|
138
|
-
async function* processStream() {
|
|
139
|
-
for await (const chunk of responseStream) {
|
|
140
|
-
yield chunk;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const streamWithTimeout = withTimeoutStream(processStream(), options?.timeout);
|
|
144
|
-
for await (const chunk of streamWithTimeout) {
|
|
145
|
-
buffer += chunk.toString();
|
|
146
|
-
// Process complete lines (newline-delimited JSON)
|
|
147
|
-
const lines = buffer.split('\n');
|
|
148
|
-
buffer = lines.pop() || ''; // Keep incomplete line in buffer
|
|
149
|
-
for (const line of lines) {
|
|
150
|
-
if (!line.trim())
|
|
151
|
-
continue;
|
|
152
|
-
const rawPayload = JSON.parse(line);
|
|
153
|
-
if (rawPayload[PROFILING_TRAILER_KEY] === true)
|
|
154
|
-
continue;
|
|
155
|
-
const response = responseSchema.parse(stripProfilingMeta(rawPayload));
|
|
156
|
-
checkAndThrowError(response);
|
|
157
|
-
yield response;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
cleanupDelegationPeer(options, error);
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async function* streamProfiled(request, rpc, options = {}, profilingMeta) {
|
|
167
|
-
const profileId = profilingMeta?.id ?? generateId();
|
|
168
|
-
const timings = createDelegationStreamTimings(profileId, request.type);
|
|
169
|
-
try {
|
|
170
|
-
if (options.peerKey) {
|
|
171
|
-
flushServerConnectionEvent(options.peerKey);
|
|
172
|
-
}
|
|
173
|
-
const parsedRequest = requestSchema.parse(request);
|
|
174
|
-
const req = rpc.request(getNextCommandId());
|
|
175
|
-
logger.debug('[delegate-transport] Streaming (profiled):', {
|
|
176
|
-
type: request.type
|
|
177
|
-
});
|
|
178
|
-
const stringifyStart = nowMs();
|
|
179
|
-
const requestWithProfiling = {
|
|
180
|
-
...parsedRequest,
|
|
181
|
-
[PROFILING_KEY]: createDelegatedProfilingMeta(profileId, profilingMeta)
|
|
182
|
-
};
|
|
183
|
-
const payload = JSON.stringify(requestWithProfiling);
|
|
184
|
-
timings.requestStringifyMs = nowMs() - stringifyStart;
|
|
185
|
-
timings.sendStart = nowMs();
|
|
186
|
-
req.send(payload, 'utf-8');
|
|
187
|
-
const responseStream = req.createResponseStream({ encoding: 'utf-8' });
|
|
188
|
-
let buffer = '';
|
|
189
|
-
async function* processStream() {
|
|
190
|
-
for await (const chunk of responseStream) {
|
|
191
|
-
yield chunk;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const streamWithTimeout = withTimeoutStream(processStream(), options?.timeout);
|
|
195
|
-
let lastServerMeta;
|
|
196
|
-
for await (const chunk of streamWithTimeout) {
|
|
197
|
-
buffer += chunk.toString();
|
|
198
|
-
const lines = buffer.split('\n');
|
|
199
|
-
buffer = lines.pop() || '';
|
|
200
|
-
for (const line of lines) {
|
|
201
|
-
if (!line.trim())
|
|
202
|
-
continue;
|
|
203
|
-
const rawPayload = JSON.parse(line);
|
|
204
|
-
const serverMeta = extractProfilingMeta(rawPayload);
|
|
205
|
-
if (serverMeta) {
|
|
206
|
-
lastServerMeta = serverMeta;
|
|
207
|
-
}
|
|
208
|
-
if (rawPayload[PROFILING_TRAILER_KEY] === true)
|
|
209
|
-
continue;
|
|
210
|
-
const response = responseSchema.parse(stripProfilingMeta(rawPayload));
|
|
211
|
-
checkAndThrowError(response);
|
|
212
|
-
timings.chunkCount++;
|
|
213
|
-
if (timings.firstChunkAt === undefined) {
|
|
214
|
-
timings.firstChunkAt = nowMs();
|
|
215
|
-
}
|
|
216
|
-
timings.lastChunkAt = nowMs();
|
|
217
|
-
if (serverMeta?.operation) {
|
|
218
|
-
response[OPERATION_EVENT_KEY] = serverMeta.operation;
|
|
219
|
-
}
|
|
220
|
-
response[DELEGATION_BREAKDOWN_KEY] = buildDelegationStreamBreakdown(timings);
|
|
221
|
-
yield response;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
recordDelegationStreamEvents(timings, lastServerMeta);
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
cleanupDelegationPeer(options, error);
|
|
228
|
-
const base = {
|
|
229
|
-
ts: nowMs(),
|
|
230
|
-
op: timings.requestType,
|
|
231
|
-
kind: 'delegation',
|
|
232
|
-
profileId: timings.profileId
|
|
233
|
-
};
|
|
234
|
-
recordFailure(base, timings.requestStart, error);
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type RPC from 'bare-rpc';
|
|
2
|
-
import { type ServerProfiler } from '../profiling/index.js';
|
|
3
|
-
export declare function sendErrorResponse(req: RPC.IncomingRequest, error: unknown, profiler?: ServerProfiler): void;
|
|
4
|
-
export declare function sendStreamErrorResponse(stream: ReturnType<RPC.IncomingRequest['createResponseStream']>, error: unknown, profiler?: ServerProfiler): void;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createErrorResponse, responseSchema } from '../schemas/index.js';
|
|
2
|
-
import { getEngineLogger } from '../logging/index.js';
|
|
3
|
-
const logger = getEngineLogger();
|
|
4
|
-
function buildErrorResponseData(error, profiler) {
|
|
5
|
-
const errorResponse = createErrorResponse(error);
|
|
6
|
-
const validated = responseSchema.parse(errorResponse);
|
|
7
|
-
const json = JSON.stringify(validated);
|
|
8
|
-
return profiler ? profiler.serializeError(json) : json;
|
|
9
|
-
}
|
|
10
|
-
export function sendErrorResponse(req, error, profiler) {
|
|
11
|
-
try {
|
|
12
|
-
req.reply(buildErrorResponseData(error, profiler), 'utf-8');
|
|
13
|
-
}
|
|
14
|
-
catch (responseError) {
|
|
15
|
-
logger.error('Failed to create error response:', responseError);
|
|
16
|
-
const fallbackError = createErrorResponse(new Error('Internal server error'));
|
|
17
|
-
req.reply(JSON.stringify(fallbackError), 'utf-8');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function sendStreamErrorResponse(stream, error, profiler) {
|
|
21
|
-
try {
|
|
22
|
-
stream.write(buildErrorResponseData(error, profiler) + '\n', 'utf-8');
|
|
23
|
-
stream.end();
|
|
24
|
-
}
|
|
25
|
-
catch (responseError) {
|
|
26
|
-
logger.error('Failed to create stream error response:', responseError);
|
|
27
|
-
const fallbackError = createErrorResponse(new Error('Internal server error'));
|
|
28
|
-
stream.write(JSON.stringify(fallbackError) + '\n', 'utf-8');
|
|
29
|
-
stream.end();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { requestSchema, normalizeModelType, PROFILING_KEY } from '../schemas/index.js';
|
|
2
|
-
import { nowMs, createServerProfiler } from '../profiling/index.js';
|
|
3
|
-
import { resolveModelConfig } from '../runtime/state.js';
|
|
4
|
-
import { sendErrorResponse, sendStreamErrorResponse } from '../p2p/error-handlers.js';
|
|
5
|
-
import { RPCUnknownRequestTypeError, PluginHandlerTypeMismatchError } from '../errors/index.js';
|
|
6
|
-
import { registry } from '../registry.js';
|
|
7
|
-
import { executeHandler, executeDuplexHandler, handleInitConfig, isInitConfigMessage, handleShutdown, isShutdownMessage } from '../p2p/handler-utils.js';
|
|
8
|
-
import { assertLifecycleAllowed } from '../runtime/runtime-lifecycle.js';
|
|
9
|
-
import { shouldUseStreamErrorTransport } from '../p2p/transport-selector.js';
|
|
10
|
-
export async function handleRequest(req) {
|
|
11
|
-
let profiler;
|
|
12
|
-
let validationStart = 0;
|
|
13
|
-
let rawRequest;
|
|
14
|
-
let entry;
|
|
15
|
-
try {
|
|
16
|
-
const rawData = req.data?.toString();
|
|
17
|
-
// Duplex stream request: metadata arrives as the first chunk on the
|
|
18
|
-
// request stream (client used createRequestStream instead of send).
|
|
19
|
-
if (!rawData) {
|
|
20
|
-
await handleDuplexRequest(req);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
// Timing runs unconditionally since we can't know if client
|
|
24
|
-
// requested profiling until after parsing.
|
|
25
|
-
const parseStart = nowMs();
|
|
26
|
-
const jsonData = JSON.parse(rawData);
|
|
27
|
-
const jsonParseMs = nowMs() - parseStart;
|
|
28
|
-
// Handle internal config initialization (bypasses schema)
|
|
29
|
-
if (isInitConfigMessage(jsonData)) {
|
|
30
|
-
handleInitConfig(req, jsonData);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// Handle internal pre-terminate cleanup signal (bypasses schema). Lets
|
|
34
|
-
// the host tear addons down while the JS env is still alive so static
|
|
35
|
-
// js_ref_t state doesn't survive into the next isolate.
|
|
36
|
-
if (isShutdownMessage(jsonData)) {
|
|
37
|
-
await handleShutdown(req);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const { data: cleanData, profilingMeta } = extractProfilingMeta(jsonData);
|
|
41
|
-
if (cleanData && typeof cleanData === 'object') {
|
|
42
|
-
rawRequest = cleanData;
|
|
43
|
-
const rawType = rawRequest['type'];
|
|
44
|
-
if (typeof rawType === 'string') {
|
|
45
|
-
entry = registry[rawType];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
profiler = createServerProfiler(profilingMeta);
|
|
49
|
-
profiler.markRequestParsed(jsonParseMs);
|
|
50
|
-
validationStart = nowMs();
|
|
51
|
-
const processedData = applyDeviceDefaultsToRequest(cleanData);
|
|
52
|
-
const request = requestSchema.parse(processedData);
|
|
53
|
-
attachProfilingMetaToRequest(request, profilingMeta);
|
|
54
|
-
profiler.markRequestValidated(nowMs() - validationStart);
|
|
55
|
-
validationStart = 0;
|
|
56
|
-
assertLifecycleAllowed(request);
|
|
57
|
-
entry = registry[request.type];
|
|
58
|
-
if (!entry) {
|
|
59
|
-
throw new RPCUnknownRequestTypeError(request.type);
|
|
60
|
-
}
|
|
61
|
-
await executeHandler(req, request, entry, profiler);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
if (profiler && validationStart > 0) {
|
|
65
|
-
profiler.markRequestValidated(nowMs() - validationStart);
|
|
66
|
-
}
|
|
67
|
-
if (shouldUseStreamErrorTransport(entry, rawRequest)) {
|
|
68
|
-
sendStreamErrorResponse(req.createResponseStream(), error, profiler);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
sendErrorResponse(req, error, profiler);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function attachProfilingMetaToRequest(request, profilingMeta) {
|
|
76
|
-
if (!profilingMeta)
|
|
77
|
-
return;
|
|
78
|
-
Object.defineProperty(request, PROFILING_KEY, {
|
|
79
|
-
value: profilingMeta,
|
|
80
|
-
enumerable: false,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: false
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function extractProfilingMeta(data) {
|
|
86
|
-
if (!data || typeof data !== 'object' || !(PROFILING_KEY in data)) {
|
|
87
|
-
return { data, profilingMeta: undefined };
|
|
88
|
-
}
|
|
89
|
-
const obj = data;
|
|
90
|
-
const { [PROFILING_KEY]: meta, ...rest } = obj;
|
|
91
|
-
return {
|
|
92
|
-
data: rest,
|
|
93
|
-
profilingMeta: meta
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async function handleDuplexRequest(req) {
|
|
97
|
-
const inputStream = req.createRequestStream();
|
|
98
|
-
const outputStream = req.createResponseStream();
|
|
99
|
-
let profiler;
|
|
100
|
-
try {
|
|
101
|
-
const firstChunk = await new Promise((resolve, reject) => {
|
|
102
|
-
const onData = (data) => {
|
|
103
|
-
inputStream.off('error', onError);
|
|
104
|
-
inputStream.pause();
|
|
105
|
-
resolve(data);
|
|
106
|
-
};
|
|
107
|
-
const onError = (err) => {
|
|
108
|
-
inputStream.off('data', onData);
|
|
109
|
-
reject(err instanceof Error ? err : new Error(String(err)));
|
|
110
|
-
};
|
|
111
|
-
inputStream.once('data', onData);
|
|
112
|
-
inputStream.once('error', onError);
|
|
113
|
-
});
|
|
114
|
-
const parseStart = nowMs();
|
|
115
|
-
const jsonData = JSON.parse(firstChunk.toString());
|
|
116
|
-
const jsonParseMs = nowMs() - parseStart;
|
|
117
|
-
const { data: cleanData, profilingMeta } = extractProfilingMeta(jsonData);
|
|
118
|
-
profiler = createServerProfiler(profilingMeta);
|
|
119
|
-
profiler.markRequestParsed(jsonParseMs);
|
|
120
|
-
const validationStart = nowMs();
|
|
121
|
-
const processedData = applyDeviceDefaultsToRequest(cleanData);
|
|
122
|
-
const request = requestSchema.parse(processedData);
|
|
123
|
-
attachProfilingMetaToRequest(request, profilingMeta);
|
|
124
|
-
profiler.markRequestValidated(nowMs() - validationStart);
|
|
125
|
-
assertLifecycleAllowed(request);
|
|
126
|
-
const entry = registry[request.type];
|
|
127
|
-
if (!entry) {
|
|
128
|
-
throw new RPCUnknownRequestTypeError(request.type);
|
|
129
|
-
}
|
|
130
|
-
if (entry.type !== 'duplex') {
|
|
131
|
-
throw new PluginHandlerTypeMismatchError(request.type, 'duplex', entry.type);
|
|
132
|
-
}
|
|
133
|
-
await executeDuplexHandler(req, request, entry, inputStream, outputStream, profiler);
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
inputStream.destroy();
|
|
137
|
-
sendStreamErrorResponse(outputStream, error, profiler);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Apply device-specific config defaults to loadModel requests before schema parsing.
|
|
142
|
-
* This ensures device defaults are applied before schema defaults.
|
|
143
|
-
*
|
|
144
|
-
* Priority: User config > Device defaults > Schema defaults
|
|
145
|
-
*/
|
|
146
|
-
function applyDeviceDefaultsToRequest(data) {
|
|
147
|
-
if (!data || typeof data !== 'object')
|
|
148
|
-
return data;
|
|
149
|
-
const obj = data;
|
|
150
|
-
const requestType = obj['type'];
|
|
151
|
-
// Only process loadModel requests (not reload config which uses modelId)
|
|
152
|
-
if (requestType !== 'loadModel' || !obj['modelType'] || !('modelSrc' in obj)) {
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
155
|
-
// Normalize model type to canonical form
|
|
156
|
-
let canonicalType;
|
|
157
|
-
try {
|
|
158
|
-
canonicalType = normalizeModelType(obj['modelType']);
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
// Invalid model type, let schema validation handle it
|
|
162
|
-
return data;
|
|
163
|
-
}
|
|
164
|
-
// Apply device defaults and full schema defaults to modelConfig
|
|
165
|
-
const rawConfig = obj['modelConfig'] ?? {};
|
|
166
|
-
const configWithDefaults = resolveModelConfig(canonicalType, rawConfig);
|
|
167
|
-
return {
|
|
168
|
-
...obj,
|
|
169
|
-
modelConfig: configWithDefaults
|
|
170
|
-
};
|
|
171
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type QvacConfig, type Request, type RuntimeContext } from '../schemas/index.js';
|
|
2
|
-
import type RPC from 'bare-rpc';
|
|
3
|
-
import { type ServerProfiler } from '../profiling/index.js';
|
|
4
|
-
import type { HandlerEntry } from '../handlers/types.js';
|
|
5
|
-
export declare function executeDuplexHandler(_req: RPC.IncomingRequest, request: Request, entry: HandlerEntry, inputStream: ReturnType<RPC.IncomingRequest['createRequestStream']>, outputStream: ReturnType<RPC.IncomingRequest['createResponseStream']>, profiler: ServerProfiler): Promise<void>;
|
|
6
|
-
export declare function executeHandler(req: RPC.IncomingRequest, request: Request, entry: HandlerEntry, profiler: ServerProfiler): Promise<void>;
|
|
7
|
-
type InitConfigMessage = {
|
|
8
|
-
type: '__init_config';
|
|
9
|
-
config: QvacConfig;
|
|
10
|
-
runtimeContext?: RuntimeContext;
|
|
11
|
-
};
|
|
12
|
-
export declare function isInitConfigMessage(data: unknown): data is InitConfigMessage;
|
|
13
|
-
export declare function handleInitConfig(req: RPC.IncomingRequest, data: InitConfigMessage): void;
|
|
14
|
-
type ShutdownMessage = {
|
|
15
|
-
type: '__shutdown__';
|
|
16
|
-
};
|
|
17
|
-
export declare function isShutdownMessage(data: unknown): data is ShutdownMessage;
|
|
18
|
-
export declare function handleShutdown(req: RPC.IncomingRequest): Promise<void>;
|
|
19
|
-
export {};
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { PROFILING_KEY } from '../schemas/index.js';
|
|
2
|
-
import { sendErrorResponse, sendStreamErrorResponse } from '../p2p/error-handlers.js';
|
|
3
|
-
import { PluginHandlerTypeMismatchError } from '../errors/index.js';
|
|
4
|
-
import { setConfig, setRuntimeContext } from '../runtime/state.js';
|
|
5
|
-
import { isTerminalChunk } from '../p2p/rpc-utils.js';
|
|
6
|
-
import { createProgressThrottle } from '../p2p/progress-throttle.js';
|
|
7
|
-
import { handlerSupportsProgress, selectHandler } from '../selection.js';
|
|
8
|
-
function getProfilingMetaFromRequest(request) {
|
|
9
|
-
if (PROFILING_KEY in request) {
|
|
10
|
-
return request[PROFILING_KEY];
|
|
11
|
-
}
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
async function executeReplyHandler(req, request, handler, profiler, isDelegated) {
|
|
15
|
-
profiler.startHandler();
|
|
16
|
-
try {
|
|
17
|
-
let response;
|
|
18
|
-
if (isDelegated) {
|
|
19
|
-
const profilingMeta = getProfilingMetaFromRequest(request);
|
|
20
|
-
response = await handler(request, profilingMeta ? { profilingMeta } : undefined);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
response = await handler(request);
|
|
24
|
-
}
|
|
25
|
-
profiler.endHandler();
|
|
26
|
-
req.reply(profiler.serialize(response, true), 'utf-8');
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
profiler.endHandler();
|
|
30
|
-
sendErrorResponse(req, error, profiler);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function executeStreamHandler(req, request, handler, profiler, isDelegated) {
|
|
34
|
-
const stream = req.createResponseStream();
|
|
35
|
-
profiler.startHandler();
|
|
36
|
-
let sentFinalChunk = false;
|
|
37
|
-
try {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
let generator;
|
|
40
|
-
if (isDelegated) {
|
|
41
|
-
const profilingMeta = getProfilingMetaFromRequest(request);
|
|
42
|
-
generator = handler(request, profilingMeta ? { profilingMeta } : undefined);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
generator = handler(request);
|
|
46
|
-
}
|
|
47
|
-
for await (const response of generator) {
|
|
48
|
-
if (isTerminalChunk(response)) {
|
|
49
|
-
profiler.endHandler();
|
|
50
|
-
stream.write(profiler.serialize(response, true) + '\n', 'utf-8');
|
|
51
|
-
sentFinalChunk = true;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
stream.write(profiler.serialize(response, false) + '\n', 'utf-8');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Fallback
|
|
58
|
-
if (!sentFinalChunk) {
|
|
59
|
-
profiler.endHandler();
|
|
60
|
-
const trailer = profiler.serialize();
|
|
61
|
-
if (trailer) {
|
|
62
|
-
stream.write(trailer + '\n', 'utf-8');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
stream.end();
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
profiler.endHandler();
|
|
69
|
-
sendStreamErrorResponse(stream, error, profiler);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async function executeProgressHandler(req, request, handler, profiler, isDelegated) {
|
|
73
|
-
const stream = req.createResponseStream();
|
|
74
|
-
profiler.startHandler();
|
|
75
|
-
const writeBatch = (updates) => {
|
|
76
|
-
const payload = updates.map((u) => profiler.serialize(u, false)).join('\n');
|
|
77
|
-
stream.write(payload + '\n', 'utf-8');
|
|
78
|
-
};
|
|
79
|
-
const throttle = createProgressThrottle(writeBatch);
|
|
80
|
-
try {
|
|
81
|
-
let response;
|
|
82
|
-
if (isDelegated) {
|
|
83
|
-
const profilingMeta = getProfilingMetaFromRequest(request);
|
|
84
|
-
const options = { progressCallback: throttle.push };
|
|
85
|
-
if (profilingMeta) {
|
|
86
|
-
options.profilingMeta = profilingMeta;
|
|
87
|
-
}
|
|
88
|
-
response = await handler(request, options);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
response = await handler(request, throttle.push);
|
|
92
|
-
}
|
|
93
|
-
throttle.flush();
|
|
94
|
-
profiler.endHandler();
|
|
95
|
-
stream.write(profiler.serialize(response, true) + '\n', 'utf-8');
|
|
96
|
-
stream.end();
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
throttle.flush();
|
|
100
|
-
profiler.endHandler();
|
|
101
|
-
sendStreamErrorResponse(stream, error, profiler);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export async function executeDuplexHandler(_req, request, entry, inputStream, outputStream, profiler) {
|
|
105
|
-
const { handler } = selectHandler(entry, request);
|
|
106
|
-
profiler.startHandler();
|
|
107
|
-
try {
|
|
108
|
-
for await (const response of handler(request, inputStream)) {
|
|
109
|
-
outputStream.write(profiler.serialize(response, false) + '\n', 'utf-8');
|
|
110
|
-
}
|
|
111
|
-
profiler.endHandler();
|
|
112
|
-
const trailer = profiler.serialize();
|
|
113
|
-
if (trailer) {
|
|
114
|
-
outputStream.write(trailer + '\n', 'utf-8');
|
|
115
|
-
}
|
|
116
|
-
outputStream.end();
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
profiler.endHandler();
|
|
120
|
-
sendStreamErrorResponse(outputStream, error, profiler);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// Unified handler executor with delegation and progress support
|
|
124
|
-
export async function executeHandler(req, request, entry, profiler) {
|
|
125
|
-
const { handler, isDelegated } = selectHandler(entry, request);
|
|
126
|
-
const wantsProgress = handlerSupportsProgress(entry, request);
|
|
127
|
-
if (entry.type === 'duplex') {
|
|
128
|
-
throw new PluginHandlerTypeMismatchError(request.type, 'reply or stream', 'duplex');
|
|
129
|
-
}
|
|
130
|
-
if (entry.type === 'stream') {
|
|
131
|
-
await executeStreamHandler(req, request, handler, profiler, isDelegated);
|
|
132
|
-
}
|
|
133
|
-
else if (wantsProgress) {
|
|
134
|
-
await executeProgressHandler(req, request, handler, profiler, isDelegated);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
await executeReplyHandler(req, request, handler, profiler, isDelegated);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
export function isInitConfigMessage(data) {
|
|
141
|
-
return (typeof data === 'object' && data !== null && 'type' in data && data.type === '__init_config');
|
|
142
|
-
}
|
|
143
|
-
export function handleInitConfig(req, data) {
|
|
144
|
-
try {
|
|
145
|
-
if (data.config) {
|
|
146
|
-
setConfig(data.config);
|
|
147
|
-
}
|
|
148
|
-
if (data.runtimeContext) {
|
|
149
|
-
setRuntimeContext(data.runtimeContext);
|
|
150
|
-
}
|
|
151
|
-
req.reply(JSON.stringify({ success: true }), 'utf-8');
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
req.reply(JSON.stringify({
|
|
155
|
-
success: false,
|
|
156
|
-
error: error instanceof Error ? error.message : String(error)
|
|
157
|
-
}), 'utf-8');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
export function isShutdownMessage(data) {
|
|
161
|
-
return (typeof data === 'object' &&
|
|
162
|
-
data !== null &&
|
|
163
|
-
'type' in data &&
|
|
164
|
-
data.type === '__shutdown__');
|
|
165
|
-
}
|
|
166
|
-
export async function handleShutdown(req) {
|
|
167
|
-
try {
|
|
168
|
-
// Lazy import to avoid an import cycle with `./lifecycle`. By the time
|
|
169
|
-
// this runs, all modules are loaded.
|
|
170
|
-
const { cleanupForTerminate } = await import('../runtime/lifecycle.js');
|
|
171
|
-
await cleanupForTerminate();
|
|
172
|
-
req.reply(JSON.stringify({ success: true }), 'utf-8');
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
req.reply(JSON.stringify({
|
|
176
|
-
success: false,
|
|
177
|
-
error: error instanceof Error ? error.message : String(error)
|
|
178
|
-
}), 'utf-8');
|
|
179
|
-
}
|
|
180
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { HeartbeatRequest, HeartbeatResponse } from '../schemas/index.js';
|
|
2
|
-
import type { DelegatedHandlerOptions } from '../profiling/index.js';
|
|
3
|
-
export declare function handleHeartbeatDelegated(request: HeartbeatRequest, options?: DelegatedHandlerOptions): Promise<HeartbeatResponse>;
|