@qvac/sdk 0.10.2 → 0.12.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 +1455 -29
- package/README.md +2 -0
- package/dist/client/api/cancel.d.ts +24 -32
- package/dist/client/api/cancel.js +58 -31
- package/dist/client/api/classify.d.ts +23 -0
- package/dist/client/api/classify.js +43 -0
- package/dist/client/api/client-request-id.d.ts +17 -0
- package/dist/client/api/client-request-id.js +27 -0
- package/dist/client/api/completion-stream.d.ts +1 -1
- package/dist/client/api/completion-stream.js +34 -3
- package/dist/client/api/diffusion.d.ts +46 -0
- package/dist/client/api/diffusion.js +50 -1
- package/dist/client/api/download-asset.d.ts +12 -2
- package/dist/client/api/download-asset.js +21 -3
- package/dist/client/api/embed.d.ts +8 -4
- package/dist/client/api/embed.js +14 -1
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/index.d.ts +5 -0
- package/dist/client/api/index.js +5 -0
- package/dist/client/api/load-model.d.ts +12 -4
- package/dist/client/api/load-model.js +49 -2
- package/dist/client/api/rag.d.ts +9 -3
- package/dist/client/api/rag.js +23 -3
- package/dist/client/api/transcribe.d.ts +23 -8
- package/dist/client/api/transcribe.js +69 -4
- package/dist/client/api/unload-model.d.ts +5 -2
- package/dist/client/api/unload-model.js +9 -4
- package/dist/client/api/upscale.d.ts +45 -0
- package/dist/client/api/upscale.js +99 -0
- package/dist/client/api/video.d.ts +64 -0
- package/dist/client/api/video.js +147 -0
- package/dist/client/api/vla-helpers.d.ts +45 -0
- package/dist/client/api/vla-helpers.js +130 -0
- package/dist/client/api/vla.d.ts +65 -0
- package/dist/client/api/vla.js +109 -0
- package/dist/client/config-loader/resolve-config.node.d.ts +16 -0
- package/dist/client/config-loader/resolve-config.node.js +77 -23
- package/dist/client/plugins-factory.d.ts +8 -0
- package/dist/client/plugins-factory.js +10 -0
- package/dist/client/rpc/bare-client.js +62 -66
- package/dist/client/rpc/ensure-worker-ready.d.ts +9 -0
- package/dist/client/rpc/ensure-worker-ready.js +17 -0
- package/dist/client/rpc/expo-rpc-client.js +2 -1
- package/dist/client/rpc/node-rpc-client.js +22 -8
- package/dist/client/rpc/rpc-client.d.ts +2 -2
- package/dist/client/rpc/rpc-client.js +10 -4
- package/dist/client/rpc/rpc-error.d.ts +9 -0
- package/dist/client/rpc/rpc-error.js +105 -0
- package/dist/commands/bundle/bare-pack.d.ts +13 -0
- package/dist/commands/bundle/bare-pack.js +54 -0
- package/dist/commands/bundle/constants.d.ts +7 -0
- package/dist/commands/bundle/constants.js +23 -0
- package/dist/commands/bundle/entry-gen.d.ts +2 -0
- package/dist/commands/bundle/entry-gen.js +48 -0
- package/dist/commands/bundle/index.d.ts +20 -0
- package/dist/commands/bundle/index.js +141 -0
- package/dist/commands/bundle/manifest.d.ts +21 -0
- package/dist/commands/bundle/manifest.js +193 -0
- package/dist/commands/bundle/plugins.d.ts +9 -0
- package/dist/commands/bundle/plugins.js +51 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/verify/abi.d.ts +52 -0
- package/dist/commands/verify/abi.js +125 -0
- package/dist/commands/verify/addon-source.d.ts +43 -0
- package/dist/commands/verify/addon-source.js +75 -0
- package/dist/commands/verify/bundle-source.d.ts +12 -0
- package/dist/commands/verify/bundle-source.js +53 -0
- package/dist/commands/verify/index.d.ts +59 -0
- package/dist/commands/verify/index.js +371 -0
- package/dist/commands/verify/node-modules-source.d.ts +11 -0
- package/dist/commands/verify/node-modules-source.js +76 -0
- package/dist/commands/verify/prebuilds.d.ts +15 -0
- package/dist/commands/verify/prebuilds.js +39 -0
- package/dist/examples/cancel-by-request-id.d.ts +38 -0
- package/dist/examples/cancel-by-request-id.js +103 -0
- package/dist/examples/classification/classify-image.d.ts +2 -0
- package/dist/examples/classification/classify-image.js +23 -0
- package/dist/examples/diffusion-esrgan-upscale.d.ts +2 -0
- package/dist/examples/diffusion-esrgan-upscale.js +78 -0
- package/dist/examples/diffusion-txt2vid.d.ts +2 -0
- package/dist/examples/diffusion-txt2vid.js +81 -0
- package/dist/examples/download-with-cancel.js +10 -10
- package/dist/examples/embed-multi-gpu.d.ts +2 -0
- package/dist/examples/embed-multi-gpu.js +46 -0
- package/dist/examples/llamacpp-multi-gpu.d.ts +2 -0
- package/dist/examples/llamacpp-multi-gpu.js +57 -0
- package/dist/examples/plugins.js +3 -7
- package/dist/examples/rag/rag-hyperdb/cancellation.js +20 -17
- package/dist/examples/tools/llamacpp-tools-gemma4.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-gemma4.js +73 -0
- package/dist/examples/tools/llamacpp-tools-qwen35.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-qwen35.js +69 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +18 -12
- package/dist/examples/transcription/parakeet-microphone-record.js +7 -12
- package/dist/examples/transcription/parakeet-microphone-stream.d.ts +2 -0
- package/dist/examples/transcription/parakeet-microphone-stream.js +79 -0
- package/dist/examples/transcription/parakeet-sortformer-streaming.d.ts +2 -0
- package/dist/examples/transcription/parakeet-sortformer-streaming.js +121 -0
- package/dist/examples/transcription/parakeet-sortformer.js +58 -55
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +18 -15
- package/dist/examples/transcription/whispercpp-microphone-conversation.d.ts +2 -0
- package/dist/examples/transcription/whispercpp-microphone-conversation.js +107 -0
- package/dist/examples/tts/chatterbox.js +7 -16
- package/dist/examples/tts/llm-to-tts-streaming.js +3 -10
- package/dist/examples/tts/supertonic-multilingual.js +4 -12
- package/dist/examples/tts/supertonic.js +5 -12
- package/dist/examples/vla-smolvla.d.ts +2 -0
- package/dist/examples/vla-smolvla.js +75 -0
- package/dist/examples/voice-assistant/voice-assistant.js +3 -10
- package/dist/expo/plugins/find-in-ancestor-node-modules.d.ts +14 -0
- package/dist/expo/plugins/find-in-ancestor-node-modules.js +24 -0
- package/dist/expo/plugins/get-project-root.d.ts +22 -0
- package/dist/expo/plugins/get-project-root.js +23 -0
- package/dist/expo/plugins/index.d.ts +4 -0
- package/dist/expo/plugins/index.js +4 -0
- package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +9 -2
- package/dist/expo/plugins/resolve-sdk-package-dir.js +38 -11
- package/dist/expo/plugins/withDeviceInfo.js +2 -1
- package/dist/expo/plugins/withMobileBundle.d.ts +5 -4
- package/dist/expo/plugins/withMobileBundle.js +42 -58
- package/dist/index.d.ts +6 -2
- package/dist/index.js +23 -2
- package/dist/models/registry/models.d.ts +3725 -514
- package/dist/models/registry/models.js +7269 -3910
- package/dist/models/update-models/naming.js +22 -8
- package/dist/pear/pre.d.ts +3 -0
- package/dist/pear/pre.js +9 -2
- package/dist/schemas/cancel.d.ts +172 -28
- package/dist/schemas/cancel.js +120 -19
- package/dist/schemas/classification.d.ts +53 -0
- package/dist/schemas/classification.js +33 -0
- package/dist/schemas/common.d.ts +860 -1379
- package/dist/schemas/common.js +8 -1
- package/dist/schemas/completion-event.d.ts +17 -0
- package/dist/schemas/completion-event.js +12 -1
- package/dist/schemas/completion-stream.d.ts +16 -1
- package/dist/schemas/completion-stream.js +25 -7
- package/dist/schemas/download-asset.d.ts +25 -9
- package/dist/schemas/download-asset.js +17 -6
- package/dist/schemas/embed.d.ts +1 -0
- package/dist/schemas/embed.js +5 -0
- package/dist/schemas/engine-addon-map.d.ts +3 -0
- package/dist/schemas/engine-addon-map.js +18 -5
- package/dist/schemas/error.d.ts +31 -0
- package/dist/schemas/error.js +29 -1
- package/dist/schemas/finetune.d.ts +2 -0
- package/dist/schemas/finetune.js +5 -0
- package/dist/schemas/get-model-info.d.ts +10 -6
- package/dist/schemas/get-model-info.js +2 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/llamacpp-config.d.ts +64 -8
- package/dist/schemas/llamacpp-config.js +12 -0
- package/dist/schemas/load-model.d.ts +4644 -8605
- package/dist/schemas/load-model.js +90 -7
- package/dist/schemas/model-src-utils.d.ts +34 -14
- package/dist/schemas/model-types.d.ts +54 -14
- package/dist/schemas/model-types.js +28 -5
- package/dist/schemas/ocr.d.ts +8 -3
- package/dist/schemas/plugin.d.ts +60 -6
- package/dist/schemas/plugin.js +31 -5
- package/dist/schemas/rag.d.ts +9 -0
- package/dist/schemas/rag.js +17 -9
- package/dist/schemas/registry.d.ts +74 -30
- package/dist/schemas/registry.js +5 -0
- package/dist/schemas/reload-config.d.ts +34 -14
- package/dist/schemas/sdcpp-config.d.ts +445 -16
- package/dist/schemas/sdcpp-config.js +387 -26
- package/dist/schemas/sdk-config.d.ts +2431 -2723
- package/dist/schemas/sdk-config.js +16 -1
- package/dist/schemas/sdk-errors-client.d.ts +6 -0
- package/dist/schemas/sdk-errors-client.js +31 -1
- package/dist/schemas/sdk-errors-server.d.ts +8 -1
- package/dist/schemas/sdk-errors-server.js +45 -5
- package/dist/schemas/text-to-speech.d.ts +81 -698
- package/dist/schemas/text-to-speech.js +46 -19
- package/dist/schemas/transcription-config.d.ts +40 -229
- package/dist/schemas/transcription-config.js +76 -15
- package/dist/schemas/transcription.d.ts +108 -2
- package/dist/schemas/transcription.js +81 -0
- package/dist/schemas/translate.d.ts +2 -0
- package/dist/schemas/translate.js +13 -2
- package/dist/schemas/translation-config.d.ts +90 -40
- package/dist/schemas/unload-model.d.ts +2 -1
- package/dist/schemas/unload-model.js +4 -1
- package/dist/schemas/vla.d.ts +87 -0
- package/dist/schemas/vla.js +108 -0
- package/dist/scripts/run-unit-tests.js +22 -3
- package/dist/server/bare/ops/cancel.d.ts +27 -1
- package/dist/server/bare/ops/cancel.js +36 -10
- package/dist/server/bare/ops/embed.d.ts +3 -3
- package/dist/server/bare/ops/embed.js +144 -28
- package/dist/server/bare/ops/kv-cache-utils.d.ts +0 -7
- package/dist/server/bare/ops/kv-cache-utils.js +8 -47
- package/dist/server/bare/ops/transcribe.d.ts +11 -5
- package/dist/server/bare/ops/transcribe.js +230 -50
- package/dist/server/bare/ops/translate.d.ts +1 -1
- package/dist/server/bare/ops/translate.js +197 -88
- package/dist/server/bare/plugins/ggml-classification/ops/classify.d.ts +6 -0
- package/dist/server/bare/plugins/ggml-classification/ops/classify.js +30 -0
- package/dist/server/bare/plugins/ggml-classification/plugin.d.ts +32 -0
- package/dist/server/bare/plugins/ggml-classification/plugin.js +55 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.d.ts +3 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.js +12 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.d.ts +3 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.js +75 -0
- package/dist/server/bare/plugins/ggml-vla/plugin.d.ts +54 -0
- package/dist/server/bare/plugins/ggml-vla/plugin.js +57 -0
- package/dist/server/bare/plugins/index.d.ts +3 -1
- package/dist/server/bare/plugins/index.js +3 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +12 -3
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +173 -172
- package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.d.ts +29 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.js +65 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +125 -21
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.d.ts +154 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js +448 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +21 -73
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +18 -101
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +36 -3
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +183 -85
- package/dist/server/bare/plugins/llamacpp-completion/transform.d.ts +10 -0
- package/dist/server/bare/plugins/llamacpp-completion/transform.js +34 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +7 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -1
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +42 -15
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +5 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +8 -3
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +3 -0
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +73 -244
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +68 -96
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +8 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.js +40 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.js +199 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +288 -15
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +150 -7
- package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.js +2 -15
- package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.js +2 -1
- package/dist/server/bare/plugins/tts-ggml/plugin.d.ts +75 -0
- package/dist/server/bare/plugins/tts-ggml/plugin.js +189 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +47 -3
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +61 -14
- package/dist/server/bare/rag-hyperdb/index.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/index.js +1 -1
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +26 -4
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +65 -28
- package/dist/server/bare/registry/model-config-utils.js +7 -0
- package/dist/server/bare/runtime/disposable-scope.d.ts +36 -0
- package/dist/server/bare/runtime/disposable-scope.js +69 -0
- package/dist/server/bare/runtime/index.d.ts +8 -0
- package/dist/server/bare/runtime/index.js +3 -0
- package/dist/server/bare/runtime/request-context.d.ts +49 -0
- package/dist/server/bare/runtime/request-context.js +1 -0
- package/dist/server/bare/runtime/request-id.d.ts +12 -0
- package/dist/server/bare/runtime/request-id.js +14 -0
- package/dist/server/bare/runtime/request-registry-singleton.d.ts +4 -0
- package/dist/server/bare/runtime/request-registry-singleton.js +27 -0
- package/dist/server/bare/runtime/request-registry.d.ts +136 -0
- package/dist/server/bare/runtime/request-registry.js +297 -0
- package/dist/server/bare/runtime/with-request-context.d.ts +22 -0
- package/dist/server/bare/runtime/with-request-context.js +53 -0
- package/dist/server/bare/runtime-lifecycle.js +9 -9
- package/dist/server/bare/types/addon-responses.d.ts +12 -1
- package/dist/server/env.js +4 -1
- package/dist/server/plugins/index.d.ts +1 -1
- package/dist/server/plugins/index.js +1 -1
- package/dist/server/plugins/registry.d.ts +1 -0
- package/dist/server/plugins/registry.js +5 -0
- package/dist/server/rpc/handler-registry.js +30 -7
- package/dist/server/rpc/handler-selection.d.ts +9 -0
- package/dist/server/rpc/handler-selection.js +14 -0
- package/dist/server/rpc/handler-utils.js +5 -13
- package/dist/server/rpc/handlers/cancel-delegated.js +28 -31
- package/dist/server/rpc/handlers/cancelHandler.d.ts +30 -1
- package/dist/server/rpc/handlers/cancelHandler.js +54 -22
- package/dist/server/rpc/handlers/classify.d.ts +3 -0
- package/dist/server/rpc/handlers/classify.js +4 -0
- package/dist/server/rpc/handlers/delete-cache.d.ts +9 -0
- package/dist/server/rpc/handlers/delete-cache.js +13 -15
- package/dist/server/rpc/handlers/download-asset.js +133 -40
- package/dist/server/rpc/handlers/index.d.ts +4 -0
- package/dist/server/rpc/handlers/index.js +4 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +60 -2
- package/dist/server/rpc/handlers/load-model/download-manager.js +141 -8
- package/dist/server/rpc/handlers/load-model/handler.js +216 -98
- package/dist/server/rpc/handlers/load-model/http.js +3 -3
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +1 -1
- package/dist/server/rpc/handlers/load-model/registry.js +1 -1
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +20 -1
- package/dist/server/rpc/handlers/load-model/resolve-session.js +6 -5
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -2
- package/dist/server/rpc/handlers/load-model/resolve.js +18 -6
- package/dist/server/rpc/handlers/load-model/types.d.ts +24 -0
- package/dist/server/rpc/handlers/rag.js +133 -15
- package/dist/server/rpc/handlers/upscale-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/upscale-stream.js +4 -0
- package/dist/server/rpc/handlers/video-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/video-stream.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.js +23 -0
- package/dist/server/utils/completion-normalizer.js +8 -0
- package/dist/server/utils/config-transform.js +1 -1
- package/dist/server/utils/tools/dialect.js +4 -0
- package/dist/server/utils/tools/parser.js +16 -1
- package/dist/server/utils/tools/parsers/gemma4native.d.ts +4 -0
- package/dist/server/utils/tools/parsers/gemma4native.js +60 -0
- package/dist/server/utils/tools/parsers/qwen35.d.ts +4 -0
- package/dist/server/utils/tools/parsers/qwen35.js +120 -0
- package/dist/server/worker.js +14 -11
- package/dist/utils/aggregate-events.d.ts +9 -0
- package/dist/utils/aggregate-events.js +18 -3
- package/dist/utils/decorate-promise.d.ts +34 -0
- package/dist/utils/decorate-promise.js +35 -0
- package/dist/utils/errors-client.d.ts +18 -0
- package/dist/utils/errors-client.js +31 -0
- package/dist/utils/errors-server.d.ts +115 -2
- package/dist/utils/errors-server.js +148 -3
- package/package.json +68 -77
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +0 -490
- package/dist/server/bare/plugins/onnx-tts/plugin.js +0 -266
- package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +0 -14
- package/dist/server/bare/plugins/onnx-tts/wav-helper.js +0 -107
- /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.d.ts +0 -0
- /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.d.ts +0 -0
|
@@ -6,9 +6,16 @@ import { promises as fs } from "fs";
|
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { pathToFileURL } from "url";
|
|
8
8
|
import { validateConfig, parseJsonConfig, } from "./config-utils.js";
|
|
9
|
-
import { ConfigFileParseFailedError } from "../../utils/errors-client.js";
|
|
9
|
+
import { ConfigFileInvalidError, ConfigFileParseFailedError, } from "../../utils/errors-client.js";
|
|
10
10
|
import { getClientLogger } from "../../logging/index.js";
|
|
11
11
|
const logger = getClientLogger();
|
|
12
|
+
/** Config filenames searched under a project root (bundle/verify/commands). */
|
|
13
|
+
export const CONFIG_CANDIDATES = [
|
|
14
|
+
"qvac.config.ts",
|
|
15
|
+
"qvac.config.mjs",
|
|
16
|
+
"qvac.config.js",
|
|
17
|
+
"qvac.config.json",
|
|
18
|
+
];
|
|
12
19
|
async function findProjectRoot() {
|
|
13
20
|
try {
|
|
14
21
|
let currentDir = path.resolve(process.cwd());
|
|
@@ -65,20 +72,76 @@ async function loadJsConfig(filePath) {
|
|
|
65
72
|
throw new ConfigFileParseFailedError(filePath, error instanceof Error ? error.message : String(error), error);
|
|
66
73
|
}
|
|
67
74
|
}
|
|
68
|
-
async function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
async function loadTsConfig(filePath) {
|
|
76
|
+
let tsxApiPath;
|
|
77
|
+
try {
|
|
78
|
+
const { createRequire } = await import("node:module");
|
|
79
|
+
const require = createRequire(import.meta.url);
|
|
80
|
+
tsxApiPath = require.resolve("tsx/esm/api");
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new ConfigFileInvalidError(filePath, "Loading a TypeScript qvac.config.ts requires the optional peer dependency `tsx`. Install it as a devDependency, or use qvac.config.mjs / qvac.config.js / qvac.config.json instead.", error);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const tsxModule = (await import(tsxApiPath));
|
|
87
|
+
const mod = await tsxModule.tsImport(filePath, import.meta.url);
|
|
88
|
+
return validateConfig(mod.default ?? mod);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw new ConfigFileParseFailedError(filePath, error instanceof Error ? error.message : String(error), error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Load and validate a config file at an explicit path (used by RPC init and commands). */
|
|
95
|
+
export async function loadConfigFromPath(configPath) {
|
|
96
|
+
const ext = path.extname(configPath).toLowerCase();
|
|
97
|
+
if (ext === ".json") {
|
|
98
|
+
return loadJsonConfig(configPath);
|
|
99
|
+
}
|
|
100
|
+
if (ext === ".js" || ext === ".mjs") {
|
|
101
|
+
return loadJsConfig(configPath);
|
|
102
|
+
}
|
|
103
|
+
if (ext === ".ts") {
|
|
104
|
+
return loadTsConfig(configPath);
|
|
105
|
+
}
|
|
106
|
+
throw new ConfigFileInvalidError(configPath, `Unsupported config format: ${ext}. Use .json, .js, .mjs, or .ts`);
|
|
107
|
+
}
|
|
108
|
+
async function findConfigFileInDir(searchDir) {
|
|
109
|
+
for (const name of CONFIG_CANDIDATES) {
|
|
75
110
|
const filePath = path.resolve(searchDir, name);
|
|
76
111
|
if (await fileExists(filePath)) {
|
|
77
|
-
return
|
|
112
|
+
return filePath;
|
|
78
113
|
}
|
|
79
114
|
}
|
|
80
115
|
return undefined;
|
|
81
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Resolve a config file path under `projectRoot` (or an explicit relative/absolute path).
|
|
119
|
+
* Used by `bundleSdk` / `verifyBundle` when the caller supplies `projectRoot`.
|
|
120
|
+
*/
|
|
121
|
+
export async function resolveConfigFileInProject(projectRoot, explicitPath) {
|
|
122
|
+
if (explicitPath) {
|
|
123
|
+
const absPath = path.isAbsolute(explicitPath)
|
|
124
|
+
? explicitPath
|
|
125
|
+
: path.join(projectRoot, explicitPath);
|
|
126
|
+
if (await fileExists(absPath)) {
|
|
127
|
+
return absPath;
|
|
128
|
+
}
|
|
129
|
+
throw new ConfigFileInvalidError(absPath, "Config file not found at explicit path");
|
|
130
|
+
}
|
|
131
|
+
const found = await findConfigFileInDir(projectRoot);
|
|
132
|
+
return found ?? null;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Load `qvac.config.*` for a known project directory (commands tooling API).
|
|
136
|
+
*/
|
|
137
|
+
export async function resolveConfigForProject(projectRoot, explicitPath) {
|
|
138
|
+
const configPath = await resolveConfigFileInProject(projectRoot, explicitPath);
|
|
139
|
+
if (!configPath) {
|
|
140
|
+
return { configPath: null, config: {} };
|
|
141
|
+
}
|
|
142
|
+
const config = await loadConfigFromPath(configPath);
|
|
143
|
+
return { configPath, config };
|
|
144
|
+
}
|
|
82
145
|
function getResourcesPath() {
|
|
83
146
|
const { resourcesPath } = process;
|
|
84
147
|
return typeof resourcesPath === "string" ? resourcesPath : undefined;
|
|
@@ -111,14 +174,7 @@ export async function resolveConfig() {
|
|
|
111
174
|
if (configPath) {
|
|
112
175
|
const normalizedPath = path.resolve(configPath);
|
|
113
176
|
if (await fileExists(normalizedPath)) {
|
|
114
|
-
const
|
|
115
|
-
? "json"
|
|
116
|
-
: normalizedPath.endsWith(".ts")
|
|
117
|
-
? "ts"
|
|
118
|
-
: "js";
|
|
119
|
-
const config = ext === "json"
|
|
120
|
-
? await loadJsonConfig(normalizedPath)
|
|
121
|
-
: await loadJsConfig(normalizedPath);
|
|
177
|
+
const config = await loadConfigFromPath(normalizedPath);
|
|
122
178
|
logger.info(`✅ Loaded config from: ${normalizedPath}`);
|
|
123
179
|
return config;
|
|
124
180
|
}
|
|
@@ -131,12 +187,10 @@ export async function resolveConfig() {
|
|
|
131
187
|
}
|
|
132
188
|
const projectRoot = await findProjectRoot();
|
|
133
189
|
if (projectRoot) {
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
const config =
|
|
137
|
-
|
|
138
|
-
: await loadJsConfig(configFile.path);
|
|
139
|
-
logger.info(`✅ Loaded config from: ${configFile.path}`);
|
|
190
|
+
const configFilePath = await findConfigFileInDir(projectRoot);
|
|
191
|
+
if (configFilePath) {
|
|
192
|
+
const config = await loadConfigFromPath(configFilePath);
|
|
193
|
+
logger.info(`✅ Loaded config from: ${configFilePath}`);
|
|
140
194
|
return config;
|
|
141
195
|
}
|
|
142
196
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as hostApi from "./api/index";
|
|
2
|
+
import type { QvacPlugin } from "../schemas/plugin";
|
|
3
|
+
/**
|
|
4
|
+
* Register plugins and return the client host API. Designed for
|
|
5
|
+
* @qvac/bare-sdk consumers assembling explicit plugin subsets.
|
|
6
|
+
*/
|
|
7
|
+
export declare function plugins(pluginList: readonly QvacPlugin[]): typeof hostApi;
|
|
8
|
+
//# sourceMappingURL=plugins-factory.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { registerPlugins } from "../server/plugins/index.js";
|
|
2
|
+
import * as hostApi from "./api/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Register plugins and return the client host API. Designed for
|
|
5
|
+
* @qvac/bare-sdk consumers assembling explicit plugin subsets.
|
|
6
|
+
*/
|
|
7
|
+
export function plugins(pluginList) {
|
|
8
|
+
registerPlugins(pluginList);
|
|
9
|
+
return hostApi;
|
|
10
|
+
}
|
|
@@ -1,59 +1,27 @@
|
|
|
1
|
-
import { normalizeModelType } from "../../schemas/index.js";
|
|
1
|
+
import { normalizeModelType, PROFILING_KEY } from "../../schemas/index.js";
|
|
2
2
|
import os from "bare-os";
|
|
3
|
-
import { handlers } from "../../server/rpc/handlers/index.js";
|
|
4
3
|
import { registry } from "../../server/rpc/handler-registry.js";
|
|
4
|
+
import { handlerSupportsProgress, selectHandler, } from "../../server/rpc/handler-selection.js";
|
|
5
5
|
import { createErrorResponse } from "../../schemas/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { RPCNoHandlerError, RPCRequestNotSentError, } from "../../utils/errors-client.js";
|
|
7
7
|
import { initializeConfig } from "../init-hooks.js";
|
|
8
8
|
import { setSDKConfig } from "../../server/bare/registry/config-registry.js";
|
|
9
9
|
import { setRuntimeContext } from "../../server/bare/registry/runtime-context-registry.js";
|
|
10
10
|
import { resolveModelConfig } from "../../server/bare/registry/model-config-registry.js";
|
|
11
11
|
import { resolveConfig } from "../config-loader/resolve-config.bare.js";
|
|
12
|
-
import { getClientLogger } from "../../logging/index.js";
|
|
13
|
-
import { getAllPlugins } from "../../server/plugins/index.js";
|
|
14
12
|
import { initializeWorkerCore, shutdownBareDirectWorker, cleanupForTerminate, } from "../../server/worker-core.js";
|
|
15
13
|
import { assertLifecycleAllowed } from "../../server/bare/runtime-lifecycle.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Load worker entry to register plugins before any SDK calls.
|
|
19
|
-
*
|
|
20
|
-
* If plugins are already registered (e.g., by a Pear worker bootstrap),
|
|
21
|
-
* skip loading the default worker but still initialize worker core.
|
|
22
|
-
*
|
|
23
|
-
* NOTE: For Pear apps, the fallback (loading default worker) cannot work.
|
|
24
|
-
*
|
|
25
|
-
* The default worker is intentionally excluded from `pear stage --compact`
|
|
26
|
-
* to enable tree-shaking of unused built-in plugins. When a Pear app tries
|
|
27
|
-
* to dynamically import it at runtime, the path resolves to a pear:// URL.
|
|
28
|
-
* The default worker imports built-in plugins, which load native addons
|
|
29
|
-
* (.bare files). Native addons cannot be loaded from pear:// URLs, causing
|
|
30
|
-
* UNSUPPORTED_PROTOCOL errors.
|
|
31
|
-
*
|
|
32
|
-
* Instead, we detect Pear runtime and throw a clear error directing users
|
|
33
|
-
* to use the generated worker entry (qvac/worker.pear.entry.mjs).
|
|
34
|
-
*
|
|
35
|
-
* The fallback only works in non-Pear environments.
|
|
36
|
-
*/
|
|
37
|
-
async function loadWorkerEntry() {
|
|
14
|
+
import { ensurePluginsRegistered } from "./ensure-worker-ready.js";
|
|
15
|
+
async function ensureWorkerReady() {
|
|
38
16
|
initializeWorkerCore();
|
|
39
|
-
|
|
40
|
-
logger.info("📦 Plugins already registered, worker core initialized");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const { isPear } = await import("which-runtime");
|
|
44
|
-
if (isPear) {
|
|
45
|
-
throw new PearWorkerEntryRequiredError("qvac/worker.pear.entry.mjs");
|
|
46
|
-
}
|
|
47
|
-
// Fallback: load default worker (all built-in plugins)
|
|
48
|
-
logger.info("📦 Loading default worker (all built-in plugins)");
|
|
49
|
-
const workerPath = "../../server/" + "worker.js";
|
|
50
|
-
await import(workerPath);
|
|
17
|
+
await ensurePluginsRegistered();
|
|
51
18
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
19
|
+
function getHandlerEntry(type) {
|
|
20
|
+
const entry = registry[type];
|
|
21
|
+
if (!entry) {
|
|
22
|
+
throw new RPCNoHandlerError(type);
|
|
23
|
+
}
|
|
24
|
+
return entry;
|
|
57
25
|
}
|
|
58
26
|
function applyDeviceDefaultsToLoadModel(request) {
|
|
59
27
|
if (request.type !== "loadModel" || !("modelSrc" in request)) {
|
|
@@ -70,16 +38,49 @@ function applyDeviceDefaultsToLoadModel(request) {
|
|
|
70
38
|
const configWithDefaults = resolveModelConfig(canonicalType, rawConfig);
|
|
71
39
|
return { ...request, modelConfig: configWithDefaults };
|
|
72
40
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
request
|
|
76
|
-
|
|
41
|
+
function getProfilingMetaFromRequest(request) {
|
|
42
|
+
if (PROFILING_KEY in request) {
|
|
43
|
+
return request[PROFILING_KEY];
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function createDelegatedOptions(request, progressCallback) {
|
|
48
|
+
const profilingMeta = getProfilingMetaFromRequest(request);
|
|
49
|
+
if (!profilingMeta && !progressCallback) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const options = {};
|
|
53
|
+
if (progressCallback) {
|
|
54
|
+
options.progressCallback = progressCallback;
|
|
55
|
+
}
|
|
56
|
+
if (profilingMeta) {
|
|
57
|
+
options.profilingMeta = profilingMeta;
|
|
58
|
+
}
|
|
59
|
+
return options;
|
|
60
|
+
}
|
|
61
|
+
function executeDirectHandler(request, handler, isDelegated) {
|
|
62
|
+
const directHandler = handler;
|
|
63
|
+
if (isDelegated) {
|
|
64
|
+
return directHandler(request, createDelegatedOptions(request));
|
|
65
|
+
}
|
|
66
|
+
return directHandler(request);
|
|
67
|
+
}
|
|
68
|
+
function isAsyncGenerator(result) {
|
|
69
|
+
return (typeof result === "object" &&
|
|
70
|
+
result !== null &&
|
|
71
|
+
Symbol.asyncIterator in result);
|
|
77
72
|
}
|
|
78
|
-
async function* streamWithProgress(request, handler) {
|
|
73
|
+
async function* streamWithProgress(request, handler, isDelegated) {
|
|
79
74
|
const queue = [];
|
|
80
75
|
const errors = [];
|
|
81
76
|
let done = false;
|
|
82
|
-
|
|
77
|
+
function progressCallback(update) {
|
|
78
|
+
queue.push(update);
|
|
79
|
+
}
|
|
80
|
+
const directHandler = handler;
|
|
81
|
+
Promise.resolve(directHandler(request, isDelegated
|
|
82
|
+
? createDelegatedOptions(request, progressCallback)
|
|
83
|
+
: progressCallback))
|
|
83
84
|
.then((final) => {
|
|
84
85
|
queue.push(final);
|
|
85
86
|
done = true;
|
|
@@ -103,25 +104,23 @@ async function* streamWithProgress(request, handler) {
|
|
|
103
104
|
}
|
|
104
105
|
export async function send(request) {
|
|
105
106
|
assertLifecycleAllowed(request);
|
|
106
|
-
const handler = getHandler(request.type);
|
|
107
|
-
if (!handler)
|
|
108
|
-
throw new RPCNoHandlerError(request.type);
|
|
109
107
|
const processedRequest = applyDeviceDefaultsToLoadModel(request);
|
|
110
|
-
|
|
108
|
+
const entry = getHandlerEntry(processedRequest.type);
|
|
109
|
+
const { handler, isDelegated } = selectHandler(entry, processedRequest);
|
|
110
|
+
return (await executeDirectHandler(processedRequest, handler, isDelegated));
|
|
111
111
|
}
|
|
112
112
|
async function* stream(request) {
|
|
113
113
|
assertLifecycleAllowed(request);
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
yield* streamWithProgress(processedRequest, handler);
|
|
114
|
+
const processedRequest = applyDeviceDefaultsToLoadModel(request);
|
|
115
|
+
const entry = getHandlerEntry(processedRequest.type);
|
|
116
|
+
const { handler, isDelegated } = selectHandler(entry, processedRequest);
|
|
117
|
+
if (handlerSupportsProgress(entry, processedRequest)) {
|
|
118
|
+
yield* streamWithProgress(processedRequest, handler, isDelegated);
|
|
120
119
|
}
|
|
121
120
|
else {
|
|
122
|
-
const result = handler
|
|
121
|
+
const result = executeDirectHandler(processedRequest, handler, isDelegated);
|
|
123
122
|
// Check if the handler returns a Promise or AsyncGenerator
|
|
124
|
-
if (
|
|
123
|
+
if (isAsyncGenerator(result)) {
|
|
125
124
|
// It's an AsyncGenerator
|
|
126
125
|
yield* result;
|
|
127
126
|
}
|
|
@@ -195,10 +194,7 @@ function createMockRPCRequest() {
|
|
|
195
194
|
}
|
|
196
195
|
let configInitialized = false;
|
|
197
196
|
export async function getRPC() {
|
|
198
|
-
|
|
199
|
-
await loadWorkerEntry();
|
|
200
|
-
workerEntryLoaded = true;
|
|
201
|
-
}
|
|
197
|
+
await ensureWorkerReady();
|
|
202
198
|
const mockRPC = {
|
|
203
199
|
request() {
|
|
204
200
|
return createMockRPCRequest();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw if no plugins are registered before an SDK call. On Pear,
|
|
3
|
+
* point at the generated worker entry; otherwise raise a generic
|
|
4
|
+
* registration error. `isPear` is overridable for tests.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ensurePluginsRegistered(opts?: {
|
|
7
|
+
isPear?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=ensure-worker-ready.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getAllPlugins } from "../../server/plugins/index.js";
|
|
2
|
+
import { PearWorkerEntryRequiredError, WorkerPluginsNotRegisteredError, } from "../../utils/errors-client.js";
|
|
3
|
+
const PEAR_WORKER_ENTRY_PATH = "qvac/worker.pear.entry.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Throw if no plugins are registered before an SDK call. On Pear,
|
|
6
|
+
* point at the generated worker entry; otherwise raise a generic
|
|
7
|
+
* registration error. `isPear` is overridable for tests.
|
|
8
|
+
*/
|
|
9
|
+
export async function ensurePluginsRegistered(opts) {
|
|
10
|
+
if (getAllPlugins().length > 0)
|
|
11
|
+
return;
|
|
12
|
+
const isPear = opts?.isPear ?? (await import("which-runtime")).isPear;
|
|
13
|
+
if (isPear) {
|
|
14
|
+
throw new PearWorkerEntryRequiredError(PEAR_WORKER_ENTRY_PATH);
|
|
15
|
+
}
|
|
16
|
+
throw new WorkerPluginsNotRegisteredError();
|
|
17
|
+
}
|
|
@@ -195,6 +195,7 @@ export async function createDuplexSession(payload, commandId) {
|
|
|
195
195
|
const req = rpc.request(commandId);
|
|
196
196
|
const requestStream = req.createRequestStream();
|
|
197
197
|
const responseStream = req.createResponseStream({ encoding: "utf-8" });
|
|
198
|
-
|
|
198
|
+
// Pre-encode payload — RN/Hermes lacks a global `Buffer`, so `write(string, "utf-8")` would throw.
|
|
199
|
+
requestStream.write(new TextEncoder().encode(payload));
|
|
199
200
|
return { requestStream, responseStream };
|
|
200
201
|
}
|
|
@@ -13,8 +13,6 @@ import { getClientLogger } from "../../logging/index.js";
|
|
|
13
13
|
import { RPCInitTimeoutError } from "../../utils/errors-client.js";
|
|
14
14
|
const RPC_INIT_TIMEOUT_MS = 30_000;
|
|
15
15
|
const logger = getClientLogger();
|
|
16
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
17
|
-
const __dirname = path.dirname(__filename);
|
|
18
16
|
let rpcInstance = null;
|
|
19
17
|
let rpcPromise = null;
|
|
20
18
|
let bareWorkerProc = null;
|
|
@@ -56,14 +54,27 @@ function resolvePackagedWorkerPath() {
|
|
|
56
54
|
return undefined;
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
|
-
*
|
|
57
|
+
* Resolve the SDK's default worker entry via bundler-visible asset references.
|
|
58
|
+
*
|
|
59
|
+
* `path.resolve(__dirname, ...)` is invisible to static analysis, so packaged
|
|
60
|
+
* consumers ship without worker.js. We use `import.meta.asset(<literal>)` on
|
|
61
|
+
* Bare (detected by bare-module-lexer) and fall back to
|
|
62
|
+
* `new URL(<literal>, import.meta.url)` elsewhere. Specs must be string
|
|
63
|
+
* literals at the call site.
|
|
60
64
|
*/
|
|
61
65
|
function getDefaultWorkerPath() {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
const hasAsset = typeof import.meta.asset === "function";
|
|
67
|
+
const packagedUrl = hasAsset
|
|
68
|
+
? new URL(import.meta.asset("../../server/worker.js"))
|
|
69
|
+
: new URL("../../server/worker.js", import.meta.url);
|
|
70
|
+
const packaged = fileURLToPath(packagedUrl);
|
|
71
|
+
if (fs.existsSync(packaged))
|
|
72
|
+
return packaged;
|
|
65
73
|
// Dev/source layout fallback
|
|
66
|
-
|
|
74
|
+
const devUrl = hasAsset
|
|
75
|
+
? new URL(import.meta.asset("../../dist/server/worker.js"))
|
|
76
|
+
: new URL("../../dist/server/worker.js", import.meta.url);
|
|
77
|
+
return fileURLToPath(devUrl);
|
|
67
78
|
}
|
|
68
79
|
/**
|
|
69
80
|
* Resolve worker path with priority:
|
|
@@ -208,7 +219,10 @@ async function ensureRPC() {
|
|
|
208
219
|
WORKER_PATH,
|
|
209
220
|
JSON.stringify({
|
|
210
221
|
QVAC_IPC_SOCKET_PATH: socketPath,
|
|
211
|
-
|
|
222
|
+
// Snap's HOME can be revision-scoped; SNAP_USER_COMMON is stable.
|
|
223
|
+
HOME_DIR: process.env["SNAP_USER_COMMON"]
|
|
224
|
+
? String(process.env["SNAP_USER_COMMON"])
|
|
225
|
+
: os.homedir(),
|
|
212
226
|
}),
|
|
213
227
|
],
|
|
214
228
|
stdio: ["inherit", "inherit", "inherit"],
|
|
@@ -3,11 +3,11 @@ import { type Request, type Response, type RPCOptions } from "../../schemas/inde
|
|
|
3
3
|
export declare function send<T extends Request>(request: T, options?: RPCOptions, rpc?: RPC): Promise<Response>;
|
|
4
4
|
export declare function stream<T extends Request>(request: T, options?: RPCOptions, rpc?: RPC): AsyncGenerator<Response>;
|
|
5
5
|
export interface DuplexWritable {
|
|
6
|
-
write(chunk:
|
|
6
|
+
write(chunk: Uint8Array): void;
|
|
7
7
|
end(): void;
|
|
8
8
|
destroy(): void;
|
|
9
9
|
}
|
|
10
|
-
export interface DuplexReadable extends AsyncIterable<Buffer> {
|
|
10
|
+
export interface DuplexReadable extends AsyncIterable<Buffer | string> {
|
|
11
11
|
destroy(): void;
|
|
12
12
|
}
|
|
13
13
|
export interface DuplexSession {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { requestSchema, responseSchema, PROFILING_TRAILER_KEY, } from "../../schemas/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { reconstructError } from "./rpc-error.js";
|
|
3
3
|
import { withTimeout, withTimeoutStream } from "../../utils/withTimeout.js";
|
|
4
4
|
import { getClientLogger, summarizeRequest } from "../../logging/index.js";
|
|
5
5
|
import { getRPC, close as closeRPC, createDuplexSession } from "#rpc";
|
|
@@ -15,7 +15,12 @@ function getNextCommandId() {
|
|
|
15
15
|
}
|
|
16
16
|
function checkAndThrowError(response) {
|
|
17
17
|
if (response.type === "error") {
|
|
18
|
-
|
|
18
|
+
// Use the typed-error reconstructor map in `rpc-error.ts` so the
|
|
19
|
+
// original class (e.g. `RequestRejectedByPolicyError`) survives
|
|
20
|
+
// the RPC boundary intact and `err instanceof <Class>` works in
|
|
21
|
+
// consumer `catch` blocks. Unknown error names fall back to a
|
|
22
|
+
// plain `RPCError` wrapper inside `reconstructError`.
|
|
23
|
+
throw reconstructError(response);
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
async function getRPCInstance() {
|
|
@@ -311,12 +316,13 @@ async function duplexProfiled(request, options = {}) {
|
|
|
311
316
|
}
|
|
312
317
|
if (outputParts.length > 0) {
|
|
313
318
|
timings.chunkCount += outputParts.length;
|
|
314
|
-
|
|
319
|
+
// Yield strings (not Buffer) — RN/Hermes has no global `Buffer`; consumers call `.toString()` either way.
|
|
320
|
+
yield outputParts.join("\n") + "\n";
|
|
315
321
|
}
|
|
316
322
|
}
|
|
317
323
|
if (lineBuffer.trim()) {
|
|
318
324
|
timings.chunkCount++;
|
|
319
|
-
yield
|
|
325
|
+
yield lineBuffer + "\n";
|
|
320
326
|
}
|
|
321
327
|
}
|
|
322
328
|
catch (error) {
|
|
@@ -16,4 +16,13 @@ export declare class RPCError extends Error {
|
|
|
16
16
|
isQvacError: boolean;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Rebuild the original server-thrown typed error from its serialised
|
|
21
|
+
* envelope so consumer code can do
|
|
22
|
+
* `if (err instanceof RequestRejectedByPolicyError) { ... }` across
|
|
23
|
+
* the RPC boundary. Unknown error names fall through to the legacy
|
|
24
|
+
* `RPCError` wrapper, which preserves `name`/`code`/`message` for
|
|
25
|
+
* code-based predicates.
|
|
26
|
+
*/
|
|
27
|
+
export declare function reconstructError(response: ErrorResponse): Error;
|
|
19
28
|
//# sourceMappingURL=rpc-error.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ContextOverflowError, RequestIdConflictError, RequestNotFoundError, RequestRejectedByPolicyError, } from "../../utils/errors-server.js";
|
|
1
2
|
export class RPCError extends Error {
|
|
2
3
|
timestamp;
|
|
3
4
|
remoteStack;
|
|
@@ -37,3 +38,107 @@ export class RPCError extends Error {
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Attach the remote stack onto a reconstructed typed error so the
|
|
43
|
+
* client-side trace points at the consumer call site and the worker-
|
|
44
|
+
* side trace is preserved for debugging. Mirrors the behaviour
|
|
45
|
+
* `RPCError`'s constructor applies in the fall-through path.
|
|
46
|
+
*/
|
|
47
|
+
function attachRemoteContext(err, response) {
|
|
48
|
+
if (response.stack) {
|
|
49
|
+
err.remoteStack = response.stack;
|
|
50
|
+
err.stack = `${err.stack}\n--- Worker Stack ---\n${response.stack}`;
|
|
51
|
+
}
|
|
52
|
+
if (response.timestamp) {
|
|
53
|
+
err.timestamp = response.timestamp;
|
|
54
|
+
}
|
|
55
|
+
return err;
|
|
56
|
+
}
|
|
57
|
+
/** Read a string field from the `typedFields` envelope, defaulting to `fallback` if missing or non-string. */
|
|
58
|
+
function readStringField(fields, key, fallback) {
|
|
59
|
+
const value = fields?.[key];
|
|
60
|
+
return typeof value === "string" ? value : fallback;
|
|
61
|
+
}
|
|
62
|
+
/** Read a number field from the `typedFields` envelope, returning `undefined` if missing or non-number. */
|
|
63
|
+
function readOptionalNumberField(fields, key) {
|
|
64
|
+
const value = fields?.[key];
|
|
65
|
+
return typeof value === "number" ? value : undefined;
|
|
66
|
+
}
|
|
67
|
+
/** Read a string field, returning `undefined` (not a fallback string) if missing. */
|
|
68
|
+
function readOptionalStringField(fields, key) {
|
|
69
|
+
const value = fields?.[key];
|
|
70
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Map of server-thrown `QvacErrorBase` subclasses that need to survive
|
|
74
|
+
* the RPC boundary as their original class — `err instanceof
|
|
75
|
+
* RequestRejectedByPolicyError` on the consumer side must match the
|
|
76
|
+
* class re-exported from `@qvac/sdk`.
|
|
77
|
+
*
|
|
78
|
+
* **Key shape.** The key is the `name` value `QvacErrorBase` sets at
|
|
79
|
+
* construction time, which `createErrorResponse` forwards onto
|
|
80
|
+
* `response.name`. That value is the SCREAMING_SNAKE_CASE error-code
|
|
81
|
+
* name from `sdk-errors-server.ts` (`"REQUEST_REJECTED_BY_POLICY"`),
|
|
82
|
+
* **not** the JS class name (`"RequestRejectedByPolicyError"`). The
|
|
83
|
+
* mismatch was a 0.11.0 bring-up bug fixed alongside the reconstructor
|
|
84
|
+
* unit tests in `rpc-error-reconstruct.test.ts`.
|
|
85
|
+
*
|
|
86
|
+
* **Maintenance contract.** Every new cross-RPC server-thrown typed
|
|
87
|
+
* error class added in `errors-server.ts` adds a row here in the same
|
|
88
|
+
* PR, keyed by its `SDK_SERVER_ERROR_CODES.<NAME>` constant. The
|
|
89
|
+
* class must (a) implement `toErrorResponseFields(): Record<…>` so
|
|
90
|
+
* the wire envelope carries its named constructor arguments and (b)
|
|
91
|
+
* be re-exported from `@qvac/sdk` so consumers can `import` it.
|
|
92
|
+
* Forgetting either side means `instanceof` regresses for that class.
|
|
93
|
+
*
|
|
94
|
+
* Client-constructed typed errors (e.g. `InferenceCancelledError`
|
|
95
|
+
* built in `client/api/completion-stream.ts` from the aggregated
|
|
96
|
+
* partial state) are NOT registered here — they never round-trip the
|
|
97
|
+
* envelope, and adding a reconstructor for one would create a
|
|
98
|
+
* parallel construction path that fires whenever the server happens
|
|
99
|
+
* to throw the same class name.
|
|
100
|
+
*/
|
|
101
|
+
const RECONSTRUCTORS = {
|
|
102
|
+
REQUEST_ID_CONFLICT: (response) => {
|
|
103
|
+
return new RequestIdConflictError(readStringField(response.typedFields, "requestId", ""), response.cause);
|
|
104
|
+
},
|
|
105
|
+
REQUEST_NOT_FOUND: (response) => {
|
|
106
|
+
return new RequestNotFoundError(readStringField(response.typedFields, "requestId", ""), response.cause);
|
|
107
|
+
},
|
|
108
|
+
REQUEST_REJECTED_BY_POLICY: (response) => {
|
|
109
|
+
return new RequestRejectedByPolicyError(readStringField(response.typedFields, "requestId", ""), readStringField(response.typedFields, "kind", ""), readStringField(response.typedFields, "modelId", ""), readStringField(response.typedFields, "reason", response.message), response.cause);
|
|
110
|
+
},
|
|
111
|
+
CONTEXT_OVERFLOW: (response) => {
|
|
112
|
+
return new ContextOverflowError(readOptionalNumberField(response.typedFields, "promptTokens"), readOptionalNumberField(response.typedFields, "ctxSize"), readOptionalStringField(response.typedFields, "modelId"), response.cause);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Rebuild the original server-thrown typed error from its serialised
|
|
117
|
+
* envelope so consumer code can do
|
|
118
|
+
* `if (err instanceof RequestRejectedByPolicyError) { ... }` across
|
|
119
|
+
* the RPC boundary. Unknown error names fall through to the legacy
|
|
120
|
+
* `RPCError` wrapper, which preserves `name`/`code`/`message` for
|
|
121
|
+
* code-based predicates.
|
|
122
|
+
*/
|
|
123
|
+
export function reconstructError(response) {
|
|
124
|
+
const reconstructor = response.name
|
|
125
|
+
? RECONSTRUCTORS[response.name]
|
|
126
|
+
: undefined;
|
|
127
|
+
if (!reconstructor) {
|
|
128
|
+
return new RPCError(response);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return attachRemoteContext(reconstructor(response), response);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Defensive fall-through: if a reconstructor throws (e.g. a
|
|
135
|
+
// future class adds a required constructor field and an older
|
|
136
|
+
// server doesn't ship `typedFields`), surface the original error
|
|
137
|
+
// via `RPCError` so consumers never see "couldn't reconstruct
|
|
138
|
+
// error" obscuring the real one. The reconstructors here are
|
|
139
|
+
// intentionally written to coerce missing fields to defensible
|
|
140
|
+
// defaults (`String(x ?? "")`), so reaching this branch is the
|
|
141
|
+
// edge case, not the norm.
|
|
142
|
+
return new RPCError(response);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Logger } from "../../logging/types";
|
|
2
|
+
interface RunBarePackOptions {
|
|
3
|
+
entryPath: string;
|
|
4
|
+
outputPath: string;
|
|
5
|
+
hosts: string[];
|
|
6
|
+
importsMapPath: string;
|
|
7
|
+
deferModules: string[];
|
|
8
|
+
quiet: boolean;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}
|
|
11
|
+
export declare function runBarePack(options: RunBarePackOptions): Promise<void>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=bare-pack.d.ts.map
|