@qvac/sdk 0.7.1 → 0.8.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 +57 -331
- package/README.md +2 -2
- package/bare-imports.json +9 -0
- package/dist/client/api/completion-stream.d.ts +2 -1
- package/dist/client/api/completion-stream.js +2 -1
- package/dist/client/api/download-asset.d.ts +3 -2
- package/dist/client/api/download-asset.js +4 -3
- package/dist/client/api/embed.d.ts +5 -2
- package/dist/client/api/embed.js +2 -2
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/invoke-plugin.d.ts +3 -2
- package/dist/client/api/invoke-plugin.js +4 -4
- package/dist/client/api/load-model.d.ts +12 -10
- package/dist/client/api/load-model.js +3 -3
- package/dist/client/api/rag.d.ts +10 -10
- package/dist/client/api/rag.js +21 -21
- package/dist/client/api/text-to-speech.d.ts +2 -2
- package/dist/client/api/text-to-speech.js +3 -3
- package/dist/client/api/transcribe.d.ts +5 -3
- package/dist/client/api/transcribe.js +6 -4
- package/dist/client/api/translate.d.ts +2 -2
- package/dist/client/api/translate.js +3 -3
- package/dist/client/rpc/node-rpc-client.d.ts +2 -7
- package/dist/client/rpc/node-rpc-client.js +2 -39
- package/dist/client/rpc/profiling/index.d.ts +2 -0
- package/dist/client/rpc/profiling/index.js +1 -0
- package/dist/client/rpc/profiling/profiler.d.ts +27 -0
- package/dist/client/rpc/profiling/profiler.js +139 -0
- package/dist/client/rpc/rpc-client.d.ts +2 -2
- package/dist/client/rpc/rpc-client.js +174 -12
- package/dist/examples/delegated-inference/consumer-profiled.d.ts +2 -0
- package/dist/examples/delegated-inference/consumer-profiled.js +67 -0
- package/dist/examples/llamacpp-multimodal.js +1 -1
- package/dist/examples/parallel-download.js +45 -13
- package/dist/examples/profiling/basic.d.ts +2 -0
- package/dist/examples/profiling/basic.js +71 -0
- package/dist/examples/profiling/per-call.d.ts +2 -0
- package/dist/examples/profiling/per-call.js +30 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.d.ts +2 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +40 -0
- package/dist/examples/transcription/parakeet-microphone-record.d.ts +2 -0
- package/dist/examples/transcription/parakeet-microphone-record.js +95 -0
- package/dist/examples/transcription/parakeet-sortformer.d.ts +2 -0
- package/dist/examples/transcription/parakeet-sortformer.js +115 -0
- package/dist/examples/transcription/parakeet-tdt-filesystem.d.ts +2 -0
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +44 -0
- package/dist/examples/translation/translation-bergamot-pivot.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot-pivot.js +73 -0
- package/dist/examples/translation/translation-llm-afriquegemma.d.ts +2 -0
- package/dist/examples/translation/translation-llm-afriquegemma.js +39 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.js +1 -1
- package/dist/logging/namespaces.d.ts +3 -9
- package/dist/logging/namespaces.js +2 -8
- package/dist/logging/registry.js +15 -1
- package/dist/models/registry/models.d.ts +1606 -245
- package/dist/models/registry/models.js +2127 -721
- package/dist/models/update-models/codegen.js +2 -2
- package/dist/models/update-models/history.d.ts +11 -0
- package/dist/models/update-models/history.js +24 -5
- package/dist/models/update-models/index.js +17 -16
- package/dist/models/update-models/naming.js +56 -0
- package/dist/profiling/aggregator.d.ts +15 -0
- package/dist/profiling/aggregator.js +100 -0
- package/dist/profiling/clock.d.ts +12 -0
- package/dist/profiling/clock.js +51 -0
- package/dist/profiling/controller.d.ts +33 -0
- package/dist/profiling/controller.js +123 -0
- package/dist/profiling/envelope.d.ts +10 -0
- package/dist/profiling/envelope.js +36 -0
- package/dist/profiling/events.d.ts +20 -0
- package/dist/profiling/events.js +37 -0
- package/dist/profiling/exporters.d.ts +10 -0
- package/dist/profiling/exporters.js +236 -0
- package/dist/profiling/index.d.ts +36 -0
- package/dist/profiling/index.js +31 -0
- package/dist/profiling/ring-buffer.d.ts +19 -0
- package/dist/profiling/ring-buffer.js +83 -0
- package/dist/profiling/types.d.ts +47 -0
- package/dist/profiling/types.js +1 -0
- package/dist/schemas/common.d.ts +1888 -133
- package/dist/schemas/common.js +2 -0
- package/dist/schemas/completion-stream.d.ts +31 -0
- package/dist/schemas/completion-stream.js +13 -0
- package/dist/schemas/download-asset.d.ts +14 -3
- package/dist/schemas/download-asset.js +3 -1
- package/dist/schemas/engine-addon-map.js +9 -6
- package/dist/schemas/get-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.js +1 -0
- package/dist/schemas/index.d.ts +2 -1
- package/dist/schemas/index.js +2 -1
- package/dist/schemas/llamacpp-config.d.ts +140 -14
- package/dist/schemas/llamacpp-config.js +11 -7
- package/dist/schemas/load-model.d.ts +9649 -2515
- package/dist/schemas/load-model.js +142 -182
- package/dist/schemas/model-src-utils.d.ts +10 -2
- package/dist/schemas/model-types.d.ts +19 -1
- package/dist/schemas/model-types.js +11 -0
- package/dist/schemas/ocr.d.ts +37 -0
- package/dist/schemas/ocr.js +5 -0
- package/dist/schemas/plugin.d.ts +51 -5
- package/dist/schemas/plugin.js +26 -0
- package/dist/schemas/profiling.d.ts +105 -0
- package/dist/schemas/profiling.js +66 -0
- package/dist/schemas/registry.d.ts +18 -0
- package/dist/schemas/registry.js +2 -0
- package/dist/schemas/reload-config.d.ts +126 -6
- package/dist/schemas/reload-config.js +1 -1
- package/dist/schemas/sdk-config.d.ts +2280 -24
- package/dist/schemas/sdk-config.js +6 -1
- package/dist/schemas/sdk-errors-client.d.ts +1 -0
- package/dist/schemas/sdk-errors-client.js +7 -0
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +15 -0
- package/dist/schemas/text-to-speech.d.ts +90 -68
- package/dist/schemas/text-to-speech.js +16 -33
- package/dist/schemas/transcription-config.d.ts +383 -0
- package/dist/schemas/{whispercpp-config.js → transcription-config.js} +29 -1
- package/dist/schemas/translation-config.d.ts +463 -8
- package/dist/schemas/translation-config.js +35 -2
- package/dist/server/bare/delegate-rpc-client.js +11 -1
- package/dist/server/bare/ops/load-model.d.ts +7 -1
- package/dist/server/bare/ops/load-model.js +41 -42
- package/dist/server/bare/ops/transcribe.d.ts +3 -0
- package/dist/server/bare/ops/transcribe.js +75 -0
- package/dist/server/bare/ops/translate.d.ts +2 -0
- package/dist/server/bare/ops/translate.js +12 -4
- package/dist/server/bare/plugins/index.d.ts +1 -0
- package/dist/server/bare/plugins/index.js +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +2 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +8 -6
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +108 -3
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +19 -6
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +32 -2
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +31 -17
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +325 -3
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +117 -10
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +50 -2
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +46 -5
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +351 -4
- package/dist/server/bare/plugins/onnx-tts/plugin.js +81 -61
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +317 -0
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +154 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +209 -3
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +21 -9
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +2 -2
- package/dist/server/bare/registry/model-config-utils.js +3 -1
- package/dist/server/bare/utils/audio-input.d.ts +10 -0
- package/dist/server/bare/utils/audio-input.js +33 -0
- package/dist/server/error-handlers.d.ts +3 -2
- package/dist/server/error-handlers.js +11 -8
- package/dist/server/plugins/registry.js +5 -1
- package/dist/server/rpc/delegate-transport.d.ts +11 -3
- package/dist/server/rpc/delegate-transport.js +158 -3
- package/dist/server/rpc/handle-request.js +43 -4
- package/dist/server/rpc/handler-registry.js +7 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -4
- package/dist/server/rpc/handler-utils.js +72 -31
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -1
- package/dist/server/rpc/handlers/completion-stream-delegated.js +11 -2
- package/dist/server/rpc/handlers/download-asset.js +55 -3
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +6 -0
- package/dist/server/rpc/handlers/load-model/download-stats.js +87 -0
- package/dist/server/rpc/handlers/load-model/handler.js +108 -123
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/http.js +21 -5
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +19 -14
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -1
- package/dist/server/rpc/handlers/load-model/registry.js +123 -130
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +2 -0
- package/dist/server/rpc/handlers/load-model/resolve.js +55 -22
- package/dist/server/rpc/handlers/load-model/types.d.ts +29 -0
- package/dist/server/rpc/handlers/load-model/types.js +1 -0
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +5 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +35 -7
- package/dist/server/rpc/handlers/plugin-dispatch.js +15 -10
- package/dist/server/rpc/handlers/plugin-invoke.js +56 -51
- package/dist/server/rpc/handlers/rag.js +24 -0
- package/dist/server/rpc/handlers/unload-model-delegated.d.ts +3 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +32 -0
- package/dist/server/rpc/profiling/context.d.ts +18 -0
- package/dist/server/rpc/profiling/context.js +38 -0
- package/dist/server/rpc/profiling/delegation-profiler.d.ts +32 -0
- package/dist/server/rpc/profiling/delegation-profiler.js +154 -0
- package/dist/server/rpc/profiling/index.d.ts +5 -0
- package/dist/server/rpc/profiling/index.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.d.ts +25 -0
- package/dist/server/rpc/profiling/operation-metrics.js +199 -0
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +18 -0
- package/dist/server/rpc/profiling/operation-wrappers.js +124 -0
- package/dist/server/rpc/profiling/profiler.d.ts +13 -0
- package/dist/server/rpc/profiling/profiler.js +97 -0
- package/dist/server/utils/cache.d.ts +2 -1
- package/dist/server/utils/cache.js +5 -1
- package/dist/server/utils/checksum.d.ts +2 -0
- package/dist/server/utils/checksum.js +7 -0
- package/dist/server/utils/formatting.d.ts +6 -0
- package/dist/server/utils/formatting.js +35 -0
- package/dist/server/worker.js +2 -1
- package/dist/utils/errors-client.d.ts +3 -0
- package/dist/utils/errors-client.js +6 -0
- package/dist/utils/errors-server.d.ts +9 -0
- package/dist/utils/errors-server.js +15 -0
- package/dist/utils/global-singleton.d.ts +2 -0
- package/dist/utils/global-singleton.js +10 -0
- package/package.json +13 -16
- package/dist/schemas/whispercpp-config.d.ts +0 -70
- package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.d.ts +0 -3
- package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.js +0 -81
- /package/dist/examples/{whispercpp-filesystem.d.ts → transcription/whispercpp-filesystem.d.ts} +0 -0
- /package/dist/examples/{whispercpp-filesystem.js → transcription/whispercpp-filesystem.js} +0 -0
- /package/dist/examples/{whispercpp-microphone-record.d.ts → transcription/whispercpp-microphone-record.d.ts} +0 -0
- /package/dist/examples/{whispercpp-microphone-record.js → transcription/whispercpp-microphone-record.js} +0 -0
- /package/dist/examples/{whispercpp-prompt.d.ts → transcription/whispercpp-prompt.d.ts} +0 -0
- /package/dist/examples/{whispercpp-prompt.js → transcription/whispercpp-prompt.js} +0 -0
|
@@ -1,8 +1,214 @@
|
|
|
1
|
-
import { type CreateModelParams, type PluginModelResult } from "../../../../schemas/index";
|
|
1
|
+
import { type CreateModelParams, type PluginModelResult, type ResolveContext, type WhisperConfig } from "../../../../schemas/index";
|
|
2
2
|
export declare const whisperPlugin: {
|
|
3
3
|
modelType: "whispercpp-transcription";
|
|
4
4
|
displayName: string;
|
|
5
|
-
addonPackage:
|
|
5
|
+
addonPackage: "@qvac/transcription-whispercpp";
|
|
6
|
+
loadConfigSchema: import("zod").ZodObject<{
|
|
7
|
+
strategy: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
8
|
+
greedy: "greedy";
|
|
9
|
+
beam_search: "beam_search";
|
|
10
|
+
}>>;
|
|
11
|
+
n_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
12
|
+
n_max_text_ctx: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
13
|
+
offset_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
14
|
+
duration_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
15
|
+
audio_ctx: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
16
|
+
translate: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
17
|
+
no_context: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
18
|
+
no_timestamps: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
19
|
+
single_segment: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
20
|
+
print_special: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
21
|
+
print_progress: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
22
|
+
print_realtime: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
23
|
+
print_timestamps: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
24
|
+
token_timestamps: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
25
|
+
thold_pt: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
26
|
+
thold_ptsum: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
27
|
+
max_len: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
28
|
+
split_on_word: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
29
|
+
max_tokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
30
|
+
debug_mode: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
31
|
+
tdrz_enable: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
32
|
+
suppress_regex: import("zod").ZodOptional<import("zod").ZodString>;
|
|
33
|
+
initial_prompt: import("zod").ZodOptional<import("zod").ZodString>;
|
|
34
|
+
language: import("zod").ZodOptional<import("zod").ZodString>;
|
|
35
|
+
detect_language: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
36
|
+
suppress_blank: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
37
|
+
suppress_nst: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
38
|
+
temperature: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
39
|
+
length_penalty: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
40
|
+
temperature_inc: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
41
|
+
entropy_thold: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
42
|
+
logprob_thold: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
43
|
+
greedy_best_of: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
44
|
+
beam_search_beam_size: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
45
|
+
vad_params: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
46
|
+
threshold: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
47
|
+
min_speech_duration_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
48
|
+
min_silence_duration_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
49
|
+
max_speech_duration_s: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
50
|
+
speech_pad_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
51
|
+
samples_overlap: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
52
|
+
}, import("zod/v4/core").$strip>>;
|
|
53
|
+
audio_format: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
54
|
+
f32le: "f32le";
|
|
55
|
+
s16le: "s16le";
|
|
56
|
+
}>>;
|
|
57
|
+
contextParams: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
58
|
+
model: import("zod").ZodOptional<import("zod").ZodString>;
|
|
59
|
+
use_gpu: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
60
|
+
flash_attn: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
61
|
+
gpu_device: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
62
|
+
}, import("zod/v4/core").$strip>>;
|
|
63
|
+
miscConfig: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
64
|
+
caption_enabled: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
65
|
+
}, import("zod/v4/core").$strip>>;
|
|
66
|
+
vadModelSrc: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodObject<{
|
|
67
|
+
src: import("zod").ZodString;
|
|
68
|
+
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
69
|
+
modelId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
70
|
+
registryPath: import("zod").ZodOptional<import("zod").ZodString>;
|
|
71
|
+
registrySource: import("zod").ZodOptional<import("zod").ZodString>;
|
|
72
|
+
blobCoreKey: import("zod").ZodOptional<import("zod").ZodString>;
|
|
73
|
+
blobIndex: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
74
|
+
engine: import("zod").ZodOptional<import("zod").ZodString>;
|
|
75
|
+
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
76
|
+
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
77
|
+
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
78
|
+
"llamacpp-completion": "llamacpp-completion";
|
|
79
|
+
"whispercpp-transcription": "whispercpp-transcription";
|
|
80
|
+
"llamacpp-embedding": "llamacpp-embedding";
|
|
81
|
+
"nmtcpp-translation": "nmtcpp-translation";
|
|
82
|
+
"onnx-tts": "onnx-tts";
|
|
83
|
+
"parakeet-transcription": "parakeet-transcription";
|
|
84
|
+
"onnx-ocr": "onnx-ocr";
|
|
85
|
+
llm: "llm";
|
|
86
|
+
whisper: "whisper";
|
|
87
|
+
embeddings: "embeddings";
|
|
88
|
+
nmt: "nmt";
|
|
89
|
+
parakeet: "parakeet";
|
|
90
|
+
tts: "tts";
|
|
91
|
+
ocr: "ocr";
|
|
92
|
+
}>, import("zod").ZodLiteral<"vad">]>>;
|
|
93
|
+
}, import("zod/v4/core").$strip>]>>;
|
|
94
|
+
}, import("zod/v4/core").$strip>;
|
|
95
|
+
resolveConfig(cfg: WhisperConfig, ctx: ResolveContext): Promise<{
|
|
96
|
+
config: {
|
|
97
|
+
strategy?: "greedy" | "beam_search" | undefined;
|
|
98
|
+
n_threads?: number | undefined;
|
|
99
|
+
n_max_text_ctx?: number | undefined;
|
|
100
|
+
offset_ms?: number | undefined;
|
|
101
|
+
duration_ms?: number | undefined;
|
|
102
|
+
audio_ctx?: number | undefined;
|
|
103
|
+
translate?: boolean | undefined;
|
|
104
|
+
no_context?: boolean | undefined;
|
|
105
|
+
no_timestamps?: boolean | undefined;
|
|
106
|
+
single_segment?: boolean | undefined;
|
|
107
|
+
print_special?: boolean | undefined;
|
|
108
|
+
print_progress?: boolean | undefined;
|
|
109
|
+
print_realtime?: boolean | undefined;
|
|
110
|
+
print_timestamps?: boolean | undefined;
|
|
111
|
+
token_timestamps?: boolean | undefined;
|
|
112
|
+
thold_pt?: number | undefined;
|
|
113
|
+
thold_ptsum?: number | undefined;
|
|
114
|
+
max_len?: number | undefined;
|
|
115
|
+
split_on_word?: boolean | undefined;
|
|
116
|
+
max_tokens?: number | undefined;
|
|
117
|
+
debug_mode?: boolean | undefined;
|
|
118
|
+
tdrz_enable?: boolean | undefined;
|
|
119
|
+
suppress_regex?: string | undefined;
|
|
120
|
+
initial_prompt?: string | undefined;
|
|
121
|
+
language?: string | undefined;
|
|
122
|
+
detect_language?: boolean | undefined;
|
|
123
|
+
suppress_blank?: boolean | undefined;
|
|
124
|
+
suppress_nst?: boolean | undefined;
|
|
125
|
+
temperature?: number | undefined;
|
|
126
|
+
length_penalty?: number | undefined;
|
|
127
|
+
temperature_inc?: number | undefined;
|
|
128
|
+
entropy_thold?: number | undefined;
|
|
129
|
+
logprob_thold?: number | undefined;
|
|
130
|
+
greedy_best_of?: number | undefined;
|
|
131
|
+
beam_search_beam_size?: number | undefined;
|
|
132
|
+
vad_params?: {
|
|
133
|
+
threshold?: number | undefined;
|
|
134
|
+
min_speech_duration_ms?: number | undefined;
|
|
135
|
+
min_silence_duration_ms?: number | undefined;
|
|
136
|
+
max_speech_duration_s?: number | undefined;
|
|
137
|
+
speech_pad_ms?: number | undefined;
|
|
138
|
+
samples_overlap?: number | undefined;
|
|
139
|
+
} | undefined;
|
|
140
|
+
audio_format?: "f32le" | "s16le" | undefined;
|
|
141
|
+
contextParams?: {
|
|
142
|
+
model?: string | undefined;
|
|
143
|
+
use_gpu?: boolean | undefined;
|
|
144
|
+
flash_attn?: boolean | undefined;
|
|
145
|
+
gpu_device?: number | undefined;
|
|
146
|
+
} | undefined;
|
|
147
|
+
miscConfig?: {
|
|
148
|
+
caption_enabled?: boolean | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
};
|
|
151
|
+
artifacts?: never;
|
|
152
|
+
} | {
|
|
153
|
+
config: {
|
|
154
|
+
strategy?: "greedy" | "beam_search" | undefined;
|
|
155
|
+
n_threads?: number | undefined;
|
|
156
|
+
n_max_text_ctx?: number | undefined;
|
|
157
|
+
offset_ms?: number | undefined;
|
|
158
|
+
duration_ms?: number | undefined;
|
|
159
|
+
audio_ctx?: number | undefined;
|
|
160
|
+
translate?: boolean | undefined;
|
|
161
|
+
no_context?: boolean | undefined;
|
|
162
|
+
no_timestamps?: boolean | undefined;
|
|
163
|
+
single_segment?: boolean | undefined;
|
|
164
|
+
print_special?: boolean | undefined;
|
|
165
|
+
print_progress?: boolean | undefined;
|
|
166
|
+
print_realtime?: boolean | undefined;
|
|
167
|
+
print_timestamps?: boolean | undefined;
|
|
168
|
+
token_timestamps?: boolean | undefined;
|
|
169
|
+
thold_pt?: number | undefined;
|
|
170
|
+
thold_ptsum?: number | undefined;
|
|
171
|
+
max_len?: number | undefined;
|
|
172
|
+
split_on_word?: boolean | undefined;
|
|
173
|
+
max_tokens?: number | undefined;
|
|
174
|
+
debug_mode?: boolean | undefined;
|
|
175
|
+
tdrz_enable?: boolean | undefined;
|
|
176
|
+
suppress_regex?: string | undefined;
|
|
177
|
+
initial_prompt?: string | undefined;
|
|
178
|
+
language?: string | undefined;
|
|
179
|
+
detect_language?: boolean | undefined;
|
|
180
|
+
suppress_blank?: boolean | undefined;
|
|
181
|
+
suppress_nst?: boolean | undefined;
|
|
182
|
+
temperature?: number | undefined;
|
|
183
|
+
length_penalty?: number | undefined;
|
|
184
|
+
temperature_inc?: number | undefined;
|
|
185
|
+
entropy_thold?: number | undefined;
|
|
186
|
+
logprob_thold?: number | undefined;
|
|
187
|
+
greedy_best_of?: number | undefined;
|
|
188
|
+
beam_search_beam_size?: number | undefined;
|
|
189
|
+
vad_params?: {
|
|
190
|
+
threshold?: number | undefined;
|
|
191
|
+
min_speech_duration_ms?: number | undefined;
|
|
192
|
+
min_silence_duration_ms?: number | undefined;
|
|
193
|
+
max_speech_duration_s?: number | undefined;
|
|
194
|
+
speech_pad_ms?: number | undefined;
|
|
195
|
+
samples_overlap?: number | undefined;
|
|
196
|
+
} | undefined;
|
|
197
|
+
audio_format?: "f32le" | "s16le" | undefined;
|
|
198
|
+
contextParams?: {
|
|
199
|
+
model?: string | undefined;
|
|
200
|
+
use_gpu?: boolean | undefined;
|
|
201
|
+
flash_attn?: boolean | undefined;
|
|
202
|
+
gpu_device?: number | undefined;
|
|
203
|
+
} | undefined;
|
|
204
|
+
miscConfig?: {
|
|
205
|
+
caption_enabled?: boolean | undefined;
|
|
206
|
+
} | undefined;
|
|
207
|
+
};
|
|
208
|
+
artifacts: {
|
|
209
|
+
vadModelPath: string;
|
|
210
|
+
};
|
|
211
|
+
}>;
|
|
6
212
|
createModel(params: CreateModelParams): PluginModelResult;
|
|
7
213
|
handlers: {
|
|
8
214
|
transcribeStream: import("../../../../schemas/index").PluginHandlerDefinition<import("zod").ZodObject<{
|
|
@@ -25,7 +231,7 @@ export declare const whisperPlugin: {
|
|
|
25
231
|
};
|
|
26
232
|
logging: {
|
|
27
233
|
module: import("@qvac/transcription-whispercpp/addonLogging").AddonLogging;
|
|
28
|
-
namespace: "whispercpp";
|
|
234
|
+
namespace: "whispercpp-transcription";
|
|
29
235
|
};
|
|
30
236
|
};
|
|
31
237
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import whisperAddonLogging from "@qvac/transcription-whispercpp/addonLogging.js";
|
|
2
2
|
import TranscriptionWhispercpp, {} from "@qvac/transcription-whispercpp";
|
|
3
|
-
import { definePlugin, defineHandler, transcribeStreamRequestSchema, transcribeStreamResponseSchema, ModelType, } from "../../../../schemas/index.js";
|
|
4
|
-
import {
|
|
3
|
+
import { definePlugin, defineHandler, transcribeStreamRequestSchema, transcribeStreamResponseSchema, ModelType, whisperConfigSchema, ADDON_WHISPER, } from "../../../../schemas/index.js";
|
|
4
|
+
import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
|
|
5
5
|
import { parseModelPath } from "../../../utils/index.js";
|
|
6
6
|
import FilesystemDL from "@qvac/dl-filesystem";
|
|
7
|
-
import { transcribe } from "
|
|
7
|
+
import { transcribe } from "../../ops/transcribe.js";
|
|
8
8
|
function createWhisperModel(modelId, modelPath, whisperConfig, vadModelPath) {
|
|
9
9
|
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
10
10
|
let vadModelName = "";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const vadParsed = parseModelPath(effectiveVadPath);
|
|
11
|
+
if (vadModelPath) {
|
|
12
|
+
const vadParsed = parseModelPath(vadModelPath);
|
|
14
13
|
vadModelName = vadParsed.basePath;
|
|
15
14
|
}
|
|
16
15
|
const loader = new FilesystemDL({ dirPath });
|
|
17
|
-
const logger = createStreamLogger(modelId,
|
|
16
|
+
const logger = createStreamLogger(modelId, ModelType.whispercppTranscription);
|
|
17
|
+
registerAddonLogger(modelId, ModelType.whispercppTranscription, logger);
|
|
18
18
|
const args = {
|
|
19
19
|
loader,
|
|
20
20
|
logger,
|
|
@@ -37,7 +37,19 @@ function createWhisperModel(modelId, modelPath, whisperConfig, vadModelPath) {
|
|
|
37
37
|
export const whisperPlugin = definePlugin({
|
|
38
38
|
modelType: ModelType.whispercppTranscription,
|
|
39
39
|
displayName: "Whisper (whisper.cpp)",
|
|
40
|
-
addonPackage:
|
|
40
|
+
addonPackage: ADDON_WHISPER,
|
|
41
|
+
loadConfigSchema: whisperConfigSchema,
|
|
42
|
+
async resolveConfig(cfg, ctx) {
|
|
43
|
+
const { vadModelSrc, ...whisperConfig } = cfg;
|
|
44
|
+
if (!vadModelSrc) {
|
|
45
|
+
return { config: whisperConfig };
|
|
46
|
+
}
|
|
47
|
+
const vadModelPath = await ctx.resolveModelPath(vadModelSrc);
|
|
48
|
+
return {
|
|
49
|
+
config: whisperConfig,
|
|
50
|
+
artifacts: { vadModelPath },
|
|
51
|
+
};
|
|
52
|
+
},
|
|
41
53
|
createModel(params) {
|
|
42
54
|
const whisperConfig = (params.modelConfig ?? {});
|
|
43
55
|
const { model, loader } = createWhisperModel(params.modelId, params.modelPath, whisperConfig, params.artifacts?.["vadModelPath"]);
|
|
@@ -69,6 +81,6 @@ export const whisperPlugin = definePlugin({
|
|
|
69
81
|
},
|
|
70
82
|
logging: {
|
|
71
83
|
module: whisperAddonLogging,
|
|
72
|
-
namespace:
|
|
84
|
+
namespace: ModelType.whispercppTranscription,
|
|
73
85
|
},
|
|
74
86
|
});
|
|
@@ -5,7 +5,7 @@ import path from "bare-path";
|
|
|
5
5
|
import { getConfiguredCacheDir } from "../registry/config-registry.js";
|
|
6
6
|
import { RAGWorkspaceModelMismatchError, RAGWorkspaceNotOpenError, } from "../../../utils/errors-server.js";
|
|
7
7
|
import { validateAndJoinPath } from "../../utils/path-security.js";
|
|
8
|
-
import { createStreamLogger, getServerLogger,
|
|
8
|
+
import { createStreamLogger, getServerLogger, RAG_NAMESPACE, } from "../../../logging/index.js";
|
|
9
9
|
import { cancelAllRagOperations } from "./rag-operation-manager.js";
|
|
10
10
|
const logger = getServerLogger();
|
|
11
11
|
const ragWorkspaces = new Map();
|
|
@@ -59,7 +59,7 @@ export async function getRagInstance(modelId, embeddingFunction, workspace) {
|
|
|
59
59
|
}
|
|
60
60
|
return entry.rag;
|
|
61
61
|
}
|
|
62
|
-
const workspaceLogger = createStreamLogger(key,
|
|
62
|
+
const workspaceLogger = createStreamLogger(key, RAG_NAMESPACE);
|
|
63
63
|
const rag = new RAG({
|
|
64
64
|
dbAdapter: entry.dbAdapter,
|
|
65
65
|
embeddingFunction,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ModelType, } from "../../../schemas/index.js";
|
|
2
2
|
import { llmConfigSchema, embedConfigSchema } from "../../../schemas/llamacpp-config.js";
|
|
3
|
-
import { whisperConfigSchema } from "../../../schemas/
|
|
3
|
+
import { whisperConfigSchema, parakeetRuntimeConfigSchema, } from "../../../schemas/transcription-config.js";
|
|
4
4
|
import { ocrConfigSchema } from "../../../schemas/ocr.js";
|
|
5
5
|
export const CANONICAL_TO_ALIAS = {
|
|
6
6
|
[ModelType.llamacppCompletion]: "llm",
|
|
7
7
|
[ModelType.llamacppEmbedding]: "embeddings",
|
|
8
8
|
[ModelType.whispercppTranscription]: "whisper",
|
|
9
|
+
[ModelType.parakeetTranscription]: "parakeet",
|
|
9
10
|
[ModelType.nmtcppTranslation]: "nmt",
|
|
10
11
|
[ModelType.onnxTts]: "tts",
|
|
11
12
|
[ModelType.onnxOcr]: "ocr",
|
|
@@ -14,6 +15,7 @@ export const MODEL_CONFIG_SCHEMAS = {
|
|
|
14
15
|
[ModelType.llamacppCompletion]: llmConfigSchema,
|
|
15
16
|
[ModelType.llamacppEmbedding]: embedConfigSchema,
|
|
16
17
|
[ModelType.whispercppTranscription]: whisperConfigSchema,
|
|
18
|
+
[ModelType.parakeetTranscription]: parakeetRuntimeConfigSchema.passthrough(),
|
|
17
19
|
[ModelType.onnxOcr]: ocrConfigSchema,
|
|
18
20
|
};
|
|
19
21
|
// Ordered general → specific (later patterns override earlier)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Readable } from "bare-stream";
|
|
2
|
+
import type { AudioInput, AudioFormat } from "../../../schemas/index";
|
|
3
|
+
/**
|
|
4
|
+
* Converts an AudioInput (base64 or filePath) into a Readable stream,
|
|
5
|
+
* decoding the audio when necessary.
|
|
6
|
+
*
|
|
7
|
+
* Shared by all transcription plugins (Whisper, Parakeet, etc.).
|
|
8
|
+
*/
|
|
9
|
+
export declare function createAudioStream(audioChunk: AudioInput, audioFormat: AudioFormat): Promise<Readable>;
|
|
10
|
+
//# sourceMappingURL=audio-input.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Readable } from "bare-stream";
|
|
2
|
+
import fs from "bare-fs";
|
|
3
|
+
import { needsDecoding, decodeAudioToStream, } from "../../utils/audio/decoder.js";
|
|
4
|
+
import { AudioFileNotFoundError, InvalidAudioChunkError, } from "../../../utils/errors-server.js";
|
|
5
|
+
/**
|
|
6
|
+
* Converts an AudioInput (base64 or filePath) into a Readable stream,
|
|
7
|
+
* decoding the audio when necessary.
|
|
8
|
+
*
|
|
9
|
+
* Shared by all transcription plugins (Whisper, Parakeet, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export async function createAudioStream(audioChunk, audioFormat) {
|
|
12
|
+
switch (audioChunk.type) {
|
|
13
|
+
case "base64": {
|
|
14
|
+
const audioBuffer = Buffer.from(audioChunk.value, "base64");
|
|
15
|
+
return Readable.from([audioBuffer]);
|
|
16
|
+
}
|
|
17
|
+
case "filePath": {
|
|
18
|
+
const filePath = audioChunk.value;
|
|
19
|
+
try {
|
|
20
|
+
fs.accessSync(filePath);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw new AudioFileNotFoundError(filePath, error);
|
|
24
|
+
}
|
|
25
|
+
if (needsDecoding(filePath)) {
|
|
26
|
+
return decodeAudioToStream(filePath, audioFormat);
|
|
27
|
+
}
|
|
28
|
+
return fs.createReadStream(filePath);
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
throw new InvalidAudioChunkError();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type RPC from "bare-rpc";
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
import { type ServerProfiler } from "./rpc/profiling/index";
|
|
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;
|
|
4
5
|
//# sourceMappingURL=error-handlers.d.ts.map
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { createErrorResponse, responseSchema } from "../schemas/index.js";
|
|
2
2
|
import { getServerLogger } from "../logging/index.js";
|
|
3
|
+
import {} from "./rpc/profiling/index.js";
|
|
3
4
|
const logger = getServerLogger();
|
|
4
|
-
|
|
5
|
+
function buildErrorResponseData(error, profiler) {
|
|
6
|
+
const errorResponse = createErrorResponse(error);
|
|
7
|
+
const validated = responseSchema.parse(errorResponse);
|
|
8
|
+
const json = JSON.stringify(validated);
|
|
9
|
+
return profiler ? profiler.serializeError(json) : json;
|
|
10
|
+
}
|
|
11
|
+
export function sendErrorResponse(req, error, profiler) {
|
|
5
12
|
try {
|
|
6
|
-
|
|
7
|
-
const responseData = JSON.stringify(responseSchema.parse(errorResponse));
|
|
8
|
-
req.reply(responseData, "utf-8");
|
|
13
|
+
req.reply(buildErrorResponseData(error, profiler), "utf-8");
|
|
9
14
|
}
|
|
10
15
|
catch (responseError) {
|
|
11
16
|
logger.error("Failed to create error response:", responseError);
|
|
@@ -13,11 +18,9 @@ export function sendErrorResponse(req, error) {
|
|
|
13
18
|
req.reply(JSON.stringify(fallbackError), "utf-8");
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
|
-
export function sendStreamErrorResponse(stream, error) {
|
|
21
|
+
export function sendStreamErrorResponse(stream, error, profiler) {
|
|
17
22
|
try {
|
|
18
|
-
|
|
19
|
-
const responseData = JSON.stringify(responseSchema.parse(errorResponse));
|
|
20
|
-
stream.write(responseData + "\n", "utf-8");
|
|
23
|
+
stream.write(buildErrorResponseData(error, profiler) + "\n", "utf-8");
|
|
21
24
|
stream.end();
|
|
22
25
|
}
|
|
23
26
|
catch (responseError) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pluginDefinitionRuntimeSchema, } from "../../schemas/plugin.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isModelTypeAlias } from "../../schemas/index.js";
|
|
3
|
+
import { PluginAlreadyRegisteredError, PluginDefinitionInvalidError, PluginLoggingInvalidError, PluginModelTypeReservedError, } from "../../utils/errors-server.js";
|
|
3
4
|
import { createAddonLoggerCallback } from "../../logging/addon.js";
|
|
4
5
|
const plugins = new Map();
|
|
5
6
|
function getModelTypeForError(plugin) {
|
|
@@ -23,6 +24,9 @@ function validatePluginDefinition(plugin) {
|
|
|
23
24
|
}
|
|
24
25
|
export function registerPlugin(plugin) {
|
|
25
26
|
validatePluginDefinition(plugin);
|
|
27
|
+
if (isModelTypeAlias(plugin.modelType)) {
|
|
28
|
+
throw new PluginModelTypeReservedError(plugin.modelType);
|
|
29
|
+
}
|
|
26
30
|
if (plugins.has(plugin.modelType)) {
|
|
27
31
|
throw new PluginAlreadyRegisteredError(plugin.modelType);
|
|
28
32
|
}
|
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
* delegation to remote peers (via HyperSwarm RPC).
|
|
6
6
|
*/
|
|
7
7
|
import type RPC from "bare-rpc";
|
|
8
|
-
import { type Request, type Response, type RPCOptions } from "../../schemas/index";
|
|
9
|
-
|
|
10
|
-
export
|
|
8
|
+
import { DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY, type Request, type Response, type RPCOptions, type DelegationBreakdown, type OperationEvent } from "../../schemas/index";
|
|
9
|
+
import type { DelegatedHandlerOptions } from "./profiling/index";
|
|
10
|
+
export interface DelegateOptions extends RPCOptions, DelegatedHandlerOptions {
|
|
11
|
+
peerKey?: string;
|
|
12
|
+
}
|
|
13
|
+
export type ResponseWithDelegation = Response & {
|
|
14
|
+
[DELEGATION_BREAKDOWN_KEY]?: DelegationBreakdown;
|
|
15
|
+
[OPERATION_EVENT_KEY]?: OperationEvent;
|
|
16
|
+
};
|
|
17
|
+
export declare function send<T extends Request>(request: T, rpc: RPC, options?: DelegateOptions): Promise<Response>;
|
|
18
|
+
export declare function stream<T extends Request>(request: T, rpc: RPC, options?: DelegateOptions): AsyncGenerator<Response>;
|
|
11
19
|
//# sourceMappingURL=delegate-transport.d.ts.map
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
* This module provides `send` and `stream` functions for server-side
|
|
5
5
|
* delegation to remote peers (via HyperSwarm RPC).
|
|
6
6
|
*/
|
|
7
|
-
import { requestSchema, responseSchema, } from "../../schemas/index.js";
|
|
7
|
+
import { requestSchema, responseSchema, PROFILING_KEY, DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY, } from "../../schemas/index.js";
|
|
8
|
+
import { nowMs, extractProfilingMeta, recordFailure, generateId, } from "../../profiling/index.js";
|
|
8
9
|
import { withTimeout, withTimeoutStream } from "../../utils/withTimeout.js";
|
|
9
10
|
import { getServerLogger } from "../../logging/index.js";
|
|
10
11
|
import { DelegateProviderError } from "../../utils/errors-server.js";
|
|
12
|
+
import { shouldProfileDelegation, createDelegationTimings, createDelegationStreamTimings, recordDelegationEvents, recordDelegationStreamEvents, buildDelegationStreamBreakdown, flushServerConnectionEvent, consumeBreakdownConnectionTime, } from "./profiling/delegation-profiler.js";
|
|
11
13
|
const logger = getServerLogger();
|
|
12
14
|
let commandCounter = 0;
|
|
13
15
|
function getNextCommandId() {
|
|
@@ -20,10 +22,22 @@ function checkAndThrowError(response) {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
export async function send(request, rpc, options) {
|
|
25
|
+
const { profilingMeta } = options ?? {};
|
|
26
|
+
const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
|
|
27
|
+
if (!shouldProfile) {
|
|
28
|
+
return sendBase(request, rpc, options, profilingMeta);
|
|
29
|
+
}
|
|
30
|
+
return sendProfiled(request, rpc, options, profilingMeta);
|
|
31
|
+
}
|
|
32
|
+
async function sendBase(request, rpc, options, profilingMeta) {
|
|
23
33
|
const parsedRequest = requestSchema.parse(request);
|
|
24
34
|
const req = rpc.request(getNextCommandId());
|
|
25
35
|
logger.debug("[delegate-transport] Sending:", { type: request.type });
|
|
26
|
-
|
|
36
|
+
// Propagate per-call disable signal to delegated provider
|
|
37
|
+
const finalRequest = profilingMeta?.enabled === false
|
|
38
|
+
? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
|
|
39
|
+
: parsedRequest;
|
|
40
|
+
const payload = JSON.stringify(finalRequest);
|
|
27
41
|
req.send(payload, "utf-8");
|
|
28
42
|
const response = await withTimeout(req.reply("utf-8"), options?.timeout);
|
|
29
43
|
const resPayload = responseSchema.parse(JSON.parse(response?.toString() || "{}"));
|
|
@@ -31,11 +45,82 @@ export async function send(request, rpc, options) {
|
|
|
31
45
|
checkAndThrowError(resPayload);
|
|
32
46
|
return resPayload;
|
|
33
47
|
}
|
|
48
|
+
async function sendProfiled(request, rpc, options, profilingMeta) {
|
|
49
|
+
const profileId = profilingMeta?.id ?? generateId();
|
|
50
|
+
const includeServerBreakdown = profilingMeta?.includeServer ?? false;
|
|
51
|
+
const timings = createDelegationTimings(profileId, request.type);
|
|
52
|
+
try {
|
|
53
|
+
if (options?.peerKey) {
|
|
54
|
+
flushServerConnectionEvent(options.peerKey);
|
|
55
|
+
}
|
|
56
|
+
const connectionMs = options?.peerKey
|
|
57
|
+
? consumeBreakdownConnectionTime(options.peerKey)
|
|
58
|
+
: undefined;
|
|
59
|
+
const parsedRequest = requestSchema.parse(request);
|
|
60
|
+
const req = rpc.request(getNextCommandId());
|
|
61
|
+
logger.debug("[delegate-transport] Sending (profiled):", {
|
|
62
|
+
type: request.type,
|
|
63
|
+
});
|
|
64
|
+
const stringifyStart = nowMs();
|
|
65
|
+
const profilingEnvelope = { id: profileId };
|
|
66
|
+
if (includeServerBreakdown) {
|
|
67
|
+
profilingEnvelope["includeServer"] = true;
|
|
68
|
+
}
|
|
69
|
+
const requestWithProfiling = {
|
|
70
|
+
...parsedRequest,
|
|
71
|
+
[PROFILING_KEY]: profilingEnvelope,
|
|
72
|
+
};
|
|
73
|
+
const payload = JSON.stringify(requestWithProfiling);
|
|
74
|
+
timings.requestStringifyMs = nowMs() - stringifyStart;
|
|
75
|
+
timings.sendStart = nowMs();
|
|
76
|
+
req.send(payload, "utf-8");
|
|
77
|
+
const response = await withTimeout(req.reply("utf-8"), options?.timeout);
|
|
78
|
+
timings.firstResponseAt = nowMs();
|
|
79
|
+
const parseStart = nowMs();
|
|
80
|
+
const rawPayload = JSON.parse(response?.toString() || "{}");
|
|
81
|
+
timings.responseJsonParseMs = nowMs() - parseStart;
|
|
82
|
+
const resPayload = responseSchema.parse(rawPayload);
|
|
83
|
+
logger.debug("[delegate-transport] Response (profiled):", {
|
|
84
|
+
type: resPayload.type,
|
|
85
|
+
});
|
|
86
|
+
checkAndThrowError(resPayload);
|
|
87
|
+
const serverMeta = extractProfilingMeta(rawPayload);
|
|
88
|
+
const delegationBreakdown = recordDelegationEvents(timings, serverMeta, connectionMs);
|
|
89
|
+
resPayload[DELEGATION_BREAKDOWN_KEY] = delegationBreakdown;
|
|
90
|
+
if (serverMeta?.operation) {
|
|
91
|
+
resPayload[OPERATION_EVENT_KEY] = serverMeta.operation;
|
|
92
|
+
}
|
|
93
|
+
return resPayload;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const base = {
|
|
97
|
+
ts: nowMs(),
|
|
98
|
+
op: timings.requestType,
|
|
99
|
+
kind: "delegation",
|
|
100
|
+
profileId: timings.profileId,
|
|
101
|
+
};
|
|
102
|
+
recordFailure(base, timings.requestStart, error);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
34
106
|
export async function* stream(request, rpc, options = {}) {
|
|
107
|
+
const { profilingMeta } = options;
|
|
108
|
+
const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
|
|
109
|
+
if (!shouldProfile) {
|
|
110
|
+
yield* streamBase(request, rpc, options, profilingMeta);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
yield* streamProfiled(request, rpc, options, profilingMeta);
|
|
114
|
+
}
|
|
115
|
+
async function* streamBase(request, rpc, options = {}, profilingMeta) {
|
|
35
116
|
const parsedRequest = requestSchema.parse(request);
|
|
36
117
|
const req = rpc.request(getNextCommandId());
|
|
37
118
|
logger.debug("[delegate-transport] Streaming:", { type: request.type });
|
|
38
|
-
|
|
119
|
+
// Propagate per-call disable signal to delegated provider
|
|
120
|
+
const finalRequest = profilingMeta?.enabled === false
|
|
121
|
+
? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
|
|
122
|
+
: parsedRequest;
|
|
123
|
+
req.send(JSON.stringify(finalRequest), "utf-8");
|
|
39
124
|
const responseStream = req.createResponseStream({ encoding: "utf-8" });
|
|
40
125
|
let buffer = "";
|
|
41
126
|
async function* processStream() {
|
|
@@ -58,3 +143,73 @@ export async function* stream(request, rpc, options = {}) {
|
|
|
58
143
|
}
|
|
59
144
|
}
|
|
60
145
|
}
|
|
146
|
+
async function* streamProfiled(request, rpc, options = {}, profilingMeta) {
|
|
147
|
+
const profileId = profilingMeta?.id ?? generateId();
|
|
148
|
+
const timings = createDelegationStreamTimings(profileId, request.type);
|
|
149
|
+
try {
|
|
150
|
+
if (options.peerKey) {
|
|
151
|
+
flushServerConnectionEvent(options.peerKey);
|
|
152
|
+
}
|
|
153
|
+
const parsedRequest = requestSchema.parse(request);
|
|
154
|
+
const req = rpc.request(getNextCommandId());
|
|
155
|
+
logger.debug("[delegate-transport] Streaming (profiled):", {
|
|
156
|
+
type: request.type,
|
|
157
|
+
});
|
|
158
|
+
const stringifyStart = nowMs();
|
|
159
|
+
const requestWithProfiling = {
|
|
160
|
+
...parsedRequest,
|
|
161
|
+
[PROFILING_KEY]: { id: profileId },
|
|
162
|
+
};
|
|
163
|
+
const payload = JSON.stringify(requestWithProfiling);
|
|
164
|
+
timings.requestStringifyMs = nowMs() - stringifyStart;
|
|
165
|
+
timings.sendStart = nowMs();
|
|
166
|
+
req.send(payload, "utf-8");
|
|
167
|
+
const responseStream = req.createResponseStream({ encoding: "utf-8" });
|
|
168
|
+
let buffer = "";
|
|
169
|
+
async function* processStream() {
|
|
170
|
+
for await (const chunk of responseStream) {
|
|
171
|
+
yield chunk;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const streamWithTimeout = withTimeoutStream(processStream(), options?.timeout);
|
|
175
|
+
let lastServerMeta;
|
|
176
|
+
for await (const chunk of streamWithTimeout) {
|
|
177
|
+
buffer += chunk.toString();
|
|
178
|
+
const lines = buffer.split("\n");
|
|
179
|
+
buffer = lines.pop() || "";
|
|
180
|
+
for (const line of lines) {
|
|
181
|
+
if (line.trim()) {
|
|
182
|
+
const rawPayload = JSON.parse(line);
|
|
183
|
+
const response = responseSchema.parse(rawPayload);
|
|
184
|
+
checkAndThrowError(response);
|
|
185
|
+
timings.chunkCount++;
|
|
186
|
+
if (timings.firstChunkAt === undefined) {
|
|
187
|
+
timings.firstChunkAt = nowMs();
|
|
188
|
+
}
|
|
189
|
+
timings.lastChunkAt = nowMs();
|
|
190
|
+
const serverMeta = extractProfilingMeta(rawPayload);
|
|
191
|
+
if (serverMeta?.operation) {
|
|
192
|
+
response[OPERATION_EVENT_KEY] = serverMeta.operation;
|
|
193
|
+
}
|
|
194
|
+
if (serverMeta) {
|
|
195
|
+
lastServerMeta = serverMeta;
|
|
196
|
+
}
|
|
197
|
+
response[DELEGATION_BREAKDOWN_KEY] =
|
|
198
|
+
buildDelegationStreamBreakdown(timings);
|
|
199
|
+
yield response;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
recordDelegationStreamEvents(timings, lastServerMeta);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
const base = {
|
|
207
|
+
ts: nowMs(),
|
|
208
|
+
op: timings.requestType,
|
|
209
|
+
kind: "delegation",
|
|
210
|
+
profileId: timings.profileId,
|
|
211
|
+
};
|
|
212
|
+
recordFailure(base, timings.requestStart, error);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
}
|