@qvac/inference 0.20.1 → 0.21.1
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 +102 -40
- package/README.md +8 -5
- package/dist/api/bci-transcribe.d.ts +4 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/rpc-server.d.ts +19 -0
- package/dist/api/rpc-server.js +44 -0
- package/dist/api/text-to-speech.d.ts +9 -0
- package/dist/api/text-to-speech.js +9 -0
- package/dist/api/transcribe.d.ts +11 -7
- package/dist/api/transcribe.js +47 -15
- package/dist/api/video-request.d.ts +5 -5
- package/dist/dispatch.js +39 -7
- package/dist/errors/index.d.ts +7 -0
- package/dist/errors/index.js +15 -0
- package/dist/handlers/assess-model-fit.d.ts +8 -20
- package/dist/handlers/assess-model-fit.js +195 -77
- package/dist/handlers/completion-orchestrate.js +17 -0
- package/dist/handlers/get-loaded-model-info.js +4 -1
- package/dist/handlers/get-model-info.js +29 -1
- package/dist/handlers/load-model/coreml-sidecars.d.ts +25 -0
- package/dist/handlers/load-model/coreml-sidecars.js +274 -0
- package/dist/handlers/load-model/hyperdrive.js +2 -2
- package/dist/handlers/load-model/registry.js +59 -0
- package/dist/handlers/rpc-server.d.ts +23 -0
- package/dist/handlers/rpc-server.js +141 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/models/registry/models.d.ts +7731 -5672
- package/dist/models/registry/models.js +4652 -2526
- package/dist/models/registry/resource-profiles.js +481 -94
- package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +8 -6
- package/dist/plugins/builtin/audiogen-ggml/plugin.js +2 -1
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +73 -1
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +37 -19
- package/dist/plugins/builtin/ggml-vla/plugin.d.ts +1 -1
- package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +9 -5
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.d.ts +1 -1
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +16 -7
- package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +22 -11
- package/dist/plugins/builtin/llamacpp-completion/plugin.js +9 -3
- package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +5 -3
- package/dist/plugins/builtin/llamacpp-embedding/plugin.js +2 -1
- package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +121 -0
- package/dist/plugins/builtin/parakeet-transcription/plugin.js +56 -27
- package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +8 -2
- package/dist/plugins/builtin/sdcpp-generation/plugin.js +7 -2
- package/dist/plugins/builtin/tts-ggml/ops/parler-options.d.ts +2 -0
- package/dist/plugins/builtin/tts-ggml/ops/parler-options.js +5 -1
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +27 -10
- package/dist/plugins/builtin/tts-ggml/plugin.d.ts +181 -0
- package/dist/plugins/builtin/tts-ggml/plugin.js +84 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +136 -0
- package/dist/plugins/builtin/whispercpp-transcription/plugin.js +18 -7
- package/dist/plugins/ops/bci-transcribe.d.ts +6 -2
- package/dist/plugins/ops/bci-transcribe.js +18 -13
- package/dist/plugins/ops/load-model.js +2 -2
- package/dist/plugins/ops/transcribe.d.ts +4 -2
- package/dist/plugins/ops/transcribe.js +39 -2
- package/dist/plugins/ops/translate-stats.d.ts +2 -1
- package/dist/plugins/ops/translate-stats.js +64 -7
- package/dist/plugins/ops/translate.js +20 -4
- package/dist/profiling/operation-metrics.js +56 -0
- package/dist/registry.js +4 -0
- package/dist/resources/model-fit/assess.d.ts +37 -2
- package/dist/resources/model-fit/assess.js +24 -3
- package/dist/resources/model-fit/estimators/llm.js +2 -2
- package/dist/resources/model-fit/estimators/whisper.js +3 -4
- package/dist/resources/model-fit/fit-stub/fetch-fit-stub.d.ts +20 -1
- package/dist/resources/model-fit/fit-stub/fetch-fit-stub.js +126 -47
- package/dist/resources/model-fit/fit-stub/project-fit-from-load.d.ts +27 -0
- package/dist/resources/model-fit/fit-stub/project-fit-from-load.js +31 -0
- package/dist/resources/model-fit/fit-stub/resolve-load-from-stubs.d.ts +38 -0
- package/dist/resources/model-fit/fit-stub/resolve-load-from-stubs.js +138 -0
- package/dist/resources/model-fit/floor.js +2 -2
- package/dist/resources/model-fit/native-probe/advisory-fit.d.ts +9 -6
- package/dist/resources/model-fit/native-probe/advisory-fit.js +129 -80
- package/dist/resources/model-fit/native-probe/child-engine-fit.d.ts +2 -0
- package/dist/resources/model-fit/native-probe/child-engine-fit.js +41 -0
- package/dist/resources/model-fit/native-probe/classify-fit.d.ts +6 -0
- package/dist/resources/model-fit/native-probe/classify-fit.js +135 -0
- package/dist/resources/model-fit/native-probe/create-fit-request.d.ts +28 -0
- package/dist/resources/model-fit/native-probe/create-fit-request.js +51 -0
- package/dist/resources/model-fit/native-probe/engine-fit.d.ts +59 -0
- package/dist/resources/model-fit/native-probe/engine-fit.js +13 -0
- package/dist/resources/model-fit/native-probe/engines/asr.d.ts +10 -0
- package/dist/resources/model-fit/native-probe/engines/asr.js +103 -0
- package/dist/resources/model-fit/native-probe/engines/audiogen.d.ts +8 -0
- package/dist/resources/model-fit/native-probe/engines/audiogen.js +35 -0
- package/dist/resources/model-fit/native-probe/engines/diffusion.d.ts +7 -0
- package/dist/resources/model-fit/native-probe/engines/diffusion.js +55 -0
- package/dist/resources/model-fit/native-probe/engines/gpu.d.ts +10 -0
- package/dist/resources/model-fit/native-probe/engines/gpu.js +21 -0
- package/dist/resources/model-fit/native-probe/engines/llama.d.ts +13 -0
- package/dist/resources/model-fit/native-probe/engines/llama.js +145 -0
- package/dist/resources/model-fit/native-probe/engines/tts.d.ts +8 -0
- package/dist/resources/model-fit/native-probe/engines/tts.js +106 -0
- package/dist/resources/model-fit/native-probe/fit-outcome.d.ts +16 -0
- package/dist/resources/model-fit/native-probe/fit-outcome.js +1 -0
- package/dist/resources/model-fit/native-probe/fit-process.d.ts +27 -0
- package/dist/resources/model-fit/native-probe/fit-process.js +55 -0
- package/dist/resources/model-fit/native-probe/fit-runner.d.ts +1 -0
- package/dist/resources/model-fit/native-probe/fit-runner.js +58 -0
- package/dist/resources/model-fit/native-probe/run-fit.d.ts +24 -0
- package/dist/resources/model-fit/native-probe/run-fit.js +20 -0
- package/dist/resources/model-fit/native-probe/run-in-process-fit.d.ts +14 -34
- package/dist/resources/model-fit/native-probe/run-in-process-fit.js +55 -139
- package/dist/resources/model-fit/native-probe/run-isolated-fit.d.ts +5 -12
- package/dist/resources/model-fit/native-probe/run-isolated-fit.js +13 -8
- package/dist/resources/model-fit/platform.d.ts +9 -0
- package/dist/resources/model-fit/platform.js +28 -0
- package/dist/rpc/device-map.d.ts +13 -0
- package/dist/rpc/device-map.js +22 -0
- package/dist/rpc/discovery.d.ts +12 -0
- package/dist/rpc/discovery.js +225 -0
- package/dist/rpc/ggml-provider.d.ts +4 -0
- package/dist/rpc/ggml-provider.js +25 -0
- package/dist/rpc/index.d.ts +2 -0
- package/dist/rpc/index.js +1 -0
- package/dist/rpc/instance.d.ts +6 -0
- package/dist/rpc/instance.js +21 -0
- package/dist/rpc/inventory.d.ts +5 -0
- package/dist/rpc/inventory.js +144 -0
- package/dist/rpc/manager.d.ts +14 -0
- package/dist/rpc/manager.js +174 -0
- package/dist/rpc/network.d.ts +11 -0
- package/dist/rpc/network.js +85 -0
- package/dist/rpc/provider.d.ts +6 -0
- package/dist/rpc/provider.js +24 -0
- package/dist/runtime/lifecycle.js +31 -13
- package/dist/runtime/request-context.d.ts +1 -1
- package/dist/runtime/state.js +5 -0
- package/dist/schemas/assess-model-fit.d.ts +269 -85
- package/dist/schemas/assess-model-fit.js +78 -54
- package/dist/schemas/audio-gen.d.ts +6 -6
- package/dist/schemas/audio-gen.js +2 -2
- package/dist/schemas/batch-completion-stream.d.ts +13 -5
- package/dist/schemas/batch-completion-stream.js +5 -3
- package/dist/schemas/bci-config.js +1 -1
- package/dist/schemas/bci.d.ts +86 -1
- package/dist/schemas/bci.js +21 -2
- package/dist/schemas/cancel.d.ts +10 -0
- package/dist/schemas/cancel.js +2 -0
- package/dist/schemas/common.d.ts +708 -66
- package/dist/schemas/common.js +7 -0
- package/dist/schemas/completion-event.d.ts +6 -6
- package/dist/schemas/completion-stream.d.ts +27 -8
- package/dist/schemas/completion-stream.js +41 -4
- package/dist/schemas/config.d.ts +104 -36
- package/dist/schemas/config.js +10 -0
- package/dist/schemas/embed.d.ts +2 -2
- package/dist/schemas/error.js +13 -0
- package/dist/schemas/errors.d.ts +1 -0
- package/dist/schemas/errors.js +5 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/llamacpp-config.d.ts +25 -18
- package/dist/schemas/llamacpp-config.js +26 -16
- package/dist/schemas/load-model.d.ts +2608 -469
- package/dist/schemas/load-model.js +2 -2
- package/dist/schemas/mcp-adapter.d.ts +4 -0
- package/dist/schemas/model-config-schemas.d.ts +183 -6
- package/dist/schemas/model-info.d.ts +56 -0
- package/dist/schemas/model-info.js +5 -1
- package/dist/schemas/plugin.d.ts +8 -2
- package/dist/schemas/profiling.d.ts +4 -4
- package/dist/schemas/reload-config.d.ts +30 -0
- package/dist/schemas/rpc-server.d.ts +101 -0
- package/dist/schemas/rpc-server.js +87 -0
- package/dist/schemas/sdcpp-config.d.ts +7 -3
- package/dist/schemas/sdcpp-config.js +37 -2
- package/dist/schemas/system-resources.d.ts +4 -4
- package/dist/schemas/text-to-speech.d.ts +529 -1
- package/dist/schemas/text-to-speech.js +122 -12
- package/dist/schemas/tools.d.ts +2 -0
- package/dist/schemas/tools.js +8 -0
- package/dist/schemas/transcription-config.d.ts +5 -0
- package/dist/schemas/transcription-config.js +20 -2
- package/dist/schemas/transcription.d.ts +164 -0
- package/dist/schemas/transcription.js +71 -4
- package/dist/schemas/vla.d.ts +1 -1
- package/dist/surface.d.ts +4 -1
- package/dist/surface.js +3 -1
- package/dist/utils/addon-responses.d.ts +5 -1
- package/dist/utils/archive.js +5 -1
- package/dist/utils/asr-diagnostics.d.ts +12 -0
- package/dist/utils/asr-diagnostics.js +42 -0
- package/dist/utils/asr-events.d.ts +1 -0
- package/dist/utils/asr-events.js +3 -2
- package/dist/utils/cache/paths.js +3 -2
- package/dist/utils/mcp-adapter.js +7 -1
- package/dist/utils/multi-gpu-mobile.d.ts +1 -1
- package/dist/utils/multi-gpu-mobile.js +8 -6
- package/dist/utils/path-security.d.ts +5 -0
- package/dist/utils/path-security.js +14 -0
- package/dist/utils/tool-helpers.d.ts +4 -0
- package/dist/utils/tool-helpers.js +2 -0
- package/dist/utils/tools/defer.d.ts +93 -0
- package/dist/utils/tools/defer.js +290 -0
- package/dist/utils/tools/index.d.ts +1 -0
- package/dist/utils/tools/index.js +1 -0
- package/dist/utils/transcribe-metadata.d.ts +21 -7
- package/dist/utils/transcribe-metadata.js +24 -8
- package/dist/utils/tts-stats.d.ts +6 -0
- package/dist/utils/tts-stats.js +14 -1
- package/package.json +43 -29
- package/dist/resources/model-fit/fit-stub/index.d.ts +0 -2
- package/dist/resources/model-fit/fit-stub/index.js +0 -2
- package/dist/resources/model-fit/fit-stub/project-fit-from-stub.d.ts +0 -31
- package/dist/resources/model-fit/fit-stub/project-fit-from-stub.js +0 -36
- package/dist/resources/model-fit/native-probe/create-llama-fit-request.d.ts +0 -26
- package/dist/resources/model-fit/native-probe/create-llama-fit-request.js +0 -191
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { gpuLayersFromGate } from './gpu.js';
|
|
2
|
+
/**
|
|
3
|
+
* The longest single transcribe the projection has to cover. Whisper's KV cache
|
|
4
|
+
* and decode graph are sized from it; unset leaves the engine's own default,
|
|
5
|
+
* which is the worst case it supports.
|
|
6
|
+
*/
|
|
7
|
+
function audioSeconds(durationMs) {
|
|
8
|
+
if (durationMs === undefined || durationMs <= 0)
|
|
9
|
+
return undefined;
|
|
10
|
+
return durationMs / 1000;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Worst-case resident decoders. Each strategy carries its own count and `-1` is
|
|
14
|
+
* the engine's "use the default" sentinel rather than a number of decoders.
|
|
15
|
+
*/
|
|
16
|
+
function decoderCount(candidates) {
|
|
17
|
+
for (const candidate of candidates) {
|
|
18
|
+
if (candidate !== undefined && candidate > 0)
|
|
19
|
+
return candidate;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function createWhisperFitRequest(params) {
|
|
24
|
+
const config = (params.modelConfig ?? {});
|
|
25
|
+
const vadModelPath = params.artifacts?.['vadModelPath'];
|
|
26
|
+
const decoders = decoderCount([
|
|
27
|
+
config.strategy === 'beam_search' ? config.beam_search_beam_size : config.greedy_best_of
|
|
28
|
+
]);
|
|
29
|
+
const seconds = audioSeconds(config.duration_ms);
|
|
30
|
+
const request = {
|
|
31
|
+
engine: 'whisper',
|
|
32
|
+
modelPath: params.modelPath,
|
|
33
|
+
gpuLayers: gpuLayersFromGate(config.contextParams?.use_gpu),
|
|
34
|
+
...(vadModelPath !== undefined && { vadModelPath }),
|
|
35
|
+
...(config.contextParams?.flash_attn !== undefined && {
|
|
36
|
+
flashAttn: config.contextParams.flash_attn
|
|
37
|
+
}),
|
|
38
|
+
...(config.contextParams?.gpu_device !== undefined && {
|
|
39
|
+
gpuDevice: config.contextParams.gpu_device
|
|
40
|
+
}),
|
|
41
|
+
...(decoders !== undefined && { decoders }),
|
|
42
|
+
...(seconds !== undefined && { audioSeconds: seconds }),
|
|
43
|
+
...(params.marginBytes !== undefined && { marginBytes: params.marginBytes })
|
|
44
|
+
};
|
|
45
|
+
return { supported: true, probe: { engine: 'asr-ggml', request } };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The encoder's left context and Sortformer's rolling history size its live
|
|
49
|
+
* state, and the fit request measures that state in frames while the load sets
|
|
50
|
+
* it in milliseconds. Converting needs the model's frame rate, which is a
|
|
51
|
+
* property of the checkpoint, so a load that pins either is refused rather than
|
|
52
|
+
* projected against the engine's default window.
|
|
53
|
+
*/
|
|
54
|
+
const UNREPRESENTABLE_STREAMING = [
|
|
55
|
+
'streamingLeftContextMs',
|
|
56
|
+
'streamingHistoryMs'
|
|
57
|
+
];
|
|
58
|
+
export function createParakeetFitRequest(params) {
|
|
59
|
+
const config = (params.modelConfig ?? {});
|
|
60
|
+
if (config.streaming === true) {
|
|
61
|
+
for (const key of UNREPRESENTABLE_STREAMING) {
|
|
62
|
+
if (config[key] !== undefined) {
|
|
63
|
+
return { supported: false, detail: `load setting the projection cannot represent: ${key}` };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const request = {
|
|
68
|
+
engine: 'parakeet',
|
|
69
|
+
modelPath: params.modelPath,
|
|
70
|
+
gpuLayers: gpuLayersFromGate(config.useGPU),
|
|
71
|
+
...(config.maxThreads !== undefined && { threads: config.maxThreads }),
|
|
72
|
+
// Only a streaming load holds a live session, so outside one the chunk
|
|
73
|
+
// cadence describes no allocation the projection should cover.
|
|
74
|
+
...(config.streaming === true &&
|
|
75
|
+
config.streamingChunkMs !== undefined && { nemotronChunkMs: config.streamingChunkMs }),
|
|
76
|
+
...(params.marginBytes !== undefined && { marginBytes: params.marginBytes })
|
|
77
|
+
};
|
|
78
|
+
return { supported: true, probe: { engine: 'asr-ggml', request } };
|
|
79
|
+
}
|
|
80
|
+
export function createBciFitRequest(params) {
|
|
81
|
+
const config = (params.modelConfig ?? {});
|
|
82
|
+
const embedderPath = params.artifacts?.['embedderPath'];
|
|
83
|
+
const whisper = config.whisperConfig;
|
|
84
|
+
const decoders = decoderCount([whisper?.beam_search_beam_size, whisper?.greedy_best_of]);
|
|
85
|
+
const seconds = audioSeconds(whisper?.duration_ms);
|
|
86
|
+
return {
|
|
87
|
+
supported: true,
|
|
88
|
+
probe: {
|
|
89
|
+
engine: 'bci-whispercpp',
|
|
90
|
+
request: {
|
|
91
|
+
modelPath: params.modelPath,
|
|
92
|
+
...(embedderPath !== undefined && { embedderPath }),
|
|
93
|
+
gpuLayers: gpuLayersFromGate(config.contextParams?.use_gpu ?? true),
|
|
94
|
+
...(config.contextParams?.gpu_device !== undefined && {
|
|
95
|
+
gpuDevice: config.contextParams.gpu_device
|
|
96
|
+
}),
|
|
97
|
+
...(decoders !== undefined && { decoders }),
|
|
98
|
+
...(seconds !== undefined && { audioSeconds: seconds }),
|
|
99
|
+
...(params.marginBytes !== undefined && { marginBytes: params.marginBytes })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FitRequestPlan } from '../create-fit-request.js';
|
|
2
|
+
export interface AudiogenFitRequestParams {
|
|
3
|
+
modelPath: string;
|
|
4
|
+
modelConfig: unknown;
|
|
5
|
+
artifacts?: Record<string, string> | undefined;
|
|
6
|
+
marginBytes?: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function createAudiogenFitRequest(params: AudiogenFitRequestParams): FitRequestPlan;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { gpuLayersFromGate } from './gpu.js';
|
|
2
|
+
/**
|
|
3
|
+
* `@qvac/audiogen-ggml` is an optional peer dependency, so its value exports
|
|
4
|
+
* are unavailable to a host that ships without it. The engine discriminator is
|
|
5
|
+
* matched by its literal rather than imported.
|
|
6
|
+
*/
|
|
7
|
+
const MINIMAX = 'minimax';
|
|
8
|
+
export function createAudiogenFitRequest(params) {
|
|
9
|
+
const config = (params.modelConfig ?? {});
|
|
10
|
+
const artifacts = params.artifacts ?? {};
|
|
11
|
+
if (config.engine === MINIMAX) {
|
|
12
|
+
return { supported: false, detail: 'the minimax pipeline has no fitter' };
|
|
13
|
+
}
|
|
14
|
+
const textEncoderPath = artifacts['textEncModelPath'];
|
|
15
|
+
const lmPath = artifacts['lmModelPath'];
|
|
16
|
+
const ditPath = artifacts['ditModelPath'];
|
|
17
|
+
const vaePath = artifacts['vaeModelPath'];
|
|
18
|
+
if (textEncoderPath === undefined ||
|
|
19
|
+
lmPath === undefined ||
|
|
20
|
+
ditPath === undefined ||
|
|
21
|
+
vaePath === undefined) {
|
|
22
|
+
return { supported: false, detail: 'the ace-step stage checkpoints are not all resolved' };
|
|
23
|
+
}
|
|
24
|
+
const layers = 'nGpuLayers' in config ? config.nGpuLayers : undefined;
|
|
25
|
+
const request = {
|
|
26
|
+
textEncoderPath,
|
|
27
|
+
lmPath,
|
|
28
|
+
ditPath,
|
|
29
|
+
vaePath,
|
|
30
|
+
gpuLayers: gpuLayersFromGate(config.useGPU, layers),
|
|
31
|
+
...(config.threads !== undefined && { threads: config.threads }),
|
|
32
|
+
...(params.marginBytes !== undefined && { marginBytes: params.marginBytes })
|
|
33
|
+
};
|
|
34
|
+
return { supported: true, probe: { engine: 'audiogen-ggml', request } };
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FitRequestPlan } from '../create-fit-request.js';
|
|
2
|
+
export interface DiffusionFitRequestParams {
|
|
3
|
+
modelPath: string;
|
|
4
|
+
modelConfig: unknown;
|
|
5
|
+
artifacts?: Record<string, string> | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function createDiffusionFitRequest(params: DiffusionFitRequestParams): FitRequestPlan;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modes whose load the projection would not describe.
|
|
3
|
+
*
|
|
4
|
+
* `upscale` is an ESRGAN checkpoint, which has no fitter. `video` and `world`
|
|
5
|
+
* assemble file sets — the audio VAE, the embeddings connectors, the TAEHV
|
|
6
|
+
* preview decoder, a seed scene — that the fit request has no place for, and
|
|
7
|
+
* their peak is driven by a frame count the load config does not carry.
|
|
8
|
+
*/
|
|
9
|
+
const UNFITTABLE_MODES = {
|
|
10
|
+
upscale: 'a standalone upscaler load has no fitter',
|
|
11
|
+
video: 'video loads are not representable',
|
|
12
|
+
world: 'world loads are not representable'
|
|
13
|
+
};
|
|
14
|
+
export function createDiffusionFitRequest(params) {
|
|
15
|
+
const config = (params.modelConfig ?? {});
|
|
16
|
+
const artifacts = params.artifacts ?? {};
|
|
17
|
+
const unfittable = config.mode === undefined ? undefined : UNFITTABLE_MODES[config.mode];
|
|
18
|
+
if (unfittable !== undefined)
|
|
19
|
+
return { supported: false, detail: unfittable };
|
|
20
|
+
// A configured upscaler adds a second resident model the projection does not
|
|
21
|
+
// account for.
|
|
22
|
+
if (config.upscaler !== undefined) {
|
|
23
|
+
return { supported: false, detail: 'a configured upscaler is not part of the projection' };
|
|
24
|
+
}
|
|
25
|
+
const files = {
|
|
26
|
+
model: params.modelPath,
|
|
27
|
+
...(artifacts['clipLModelPath'] !== undefined && { clipL: artifacts['clipLModelPath'] }),
|
|
28
|
+
...(artifacts['clipGModelPath'] !== undefined && { clipG: artifacts['clipGModelPath'] }),
|
|
29
|
+
...(artifacts['t5XxlModelPath'] !== undefined && { t5Xxl: artifacts['t5XxlModelPath'] }),
|
|
30
|
+
...(artifacts['llmModelPath'] !== undefined && { llm: artifacts['llmModelPath'] }),
|
|
31
|
+
...(artifacts['vaeModelPath'] !== undefined && { vae: artifacts['vaeModelPath'] }),
|
|
32
|
+
...(artifacts['uncondModelPath'] !== undefined && {
|
|
33
|
+
uncondModel: artifacts['uncondModelPath']
|
|
34
|
+
}),
|
|
35
|
+
...(artifacts['clipVisionModelPath'] !== undefined && {
|
|
36
|
+
clipVision: artifacts['clipVisionModelPath']
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
// `mode` and `upscaler` are this SDK's own keys; the engine config has no
|
|
40
|
+
// field for either.
|
|
41
|
+
const { mode: _mode, upscaler: _upscaler, ...engineConfig } = config;
|
|
42
|
+
return {
|
|
43
|
+
supported: true,
|
|
44
|
+
probe: {
|
|
45
|
+
engine: 'diffusion-cpp',
|
|
46
|
+
request: {
|
|
47
|
+
files,
|
|
48
|
+
config: engineConfig,
|
|
49
|
+
workload: {
|
|
50
|
+
...(config.vae_tiling !== undefined && { vaeTiling: config.vae_tiling })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For loads where a layer count only applies once the GPU is switched on, and
|
|
3
|
+
* for those that offer no layer count at all.
|
|
4
|
+
*/
|
|
5
|
+
export declare function gpuLayersFromGate(useGpu: boolean | undefined, layers?: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* For loads where an explicit layer count takes effect on its own and wins over
|
|
8
|
+
* the boolean, which the schema requires to agree with it when both are set.
|
|
9
|
+
*/
|
|
10
|
+
export declare function gpuLayersFromCount(useGpu: boolean | undefined, layers?: number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The speech and music fitters take a layer count alone and read any positive
|
|
2
|
+
// value as "the GPU stack, with the fallbacks a real load applies". Their
|
|
3
|
+
// loaders express that intent two different ways.
|
|
4
|
+
/**
|
|
5
|
+
* For loads where a layer count only applies once the GPU is switched on, and
|
|
6
|
+
* for those that offer no layer count at all.
|
|
7
|
+
*/
|
|
8
|
+
export function gpuLayersFromGate(useGpu, layers) {
|
|
9
|
+
if (useGpu !== true)
|
|
10
|
+
return 0;
|
|
11
|
+
return layers === undefined || layers <= 0 ? 1 : layers;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* For loads where an explicit layer count takes effect on its own and wins over
|
|
15
|
+
* the boolean, which the schema requires to agree with it when both are set.
|
|
16
|
+
*/
|
|
17
|
+
export function gpuLayersFromCount(useGpu, layers) {
|
|
18
|
+
if (layers !== undefined)
|
|
19
|
+
return layers;
|
|
20
|
+
return useGpu === true ? 1 : 0;
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CanonicalModelType } from '../../../../schemas/index.js';
|
|
2
|
+
import type { FitRequestPlan } from '../create-fit-request.js';
|
|
3
|
+
export type LlamaLoadKind = 'completion' | 'embedding';
|
|
4
|
+
export declare function llamaLoadKindFor(modelType: CanonicalModelType): LlamaLoadKind | undefined;
|
|
5
|
+
export interface LlamaFitRequestParams {
|
|
6
|
+
loadKind: LlamaLoadKind;
|
|
7
|
+
modelPath: string;
|
|
8
|
+
modelConfig: unknown;
|
|
9
|
+
artifacts?: Record<string, string> | undefined;
|
|
10
|
+
isShardedModel: boolean;
|
|
11
|
+
marginBytes?: number | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function createLlamaFitRequest(params: LlamaFitRequestParams): FitRequestPlan;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ModelType } from '../../../../schemas/index.js';
|
|
2
|
+
import { transformLlmConfig } from '../../../../plugins/builtin/llamacpp-completion/transform.js';
|
|
3
|
+
import { transformEmbedConfig } from '../../../../plugins/builtin/llamacpp-embedding/transform.js';
|
|
4
|
+
const BYTES_PER_MIB = 1024 * 1024;
|
|
5
|
+
/**
|
|
6
|
+
* The transforms emit some settings with underscores where llama's own
|
|
7
|
+
* argument table spells them with hyphens.
|
|
8
|
+
*/
|
|
9
|
+
const CANONICAL_KEY = {
|
|
10
|
+
ctx_size: 'ctx-size',
|
|
11
|
+
gpu_layers: 'gpu-layers',
|
|
12
|
+
batch_size: 'batch-size',
|
|
13
|
+
ubatch_size: 'ubatch-size',
|
|
14
|
+
flash_attn: 'flash-attn',
|
|
15
|
+
split_mode: 'split-mode',
|
|
16
|
+
main_gpu: 'main-gpu',
|
|
17
|
+
load_mode: 'load-mode'
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Settings that decide how much device memory the load needs, in the spelling
|
|
21
|
+
* each transform emits. `device` and `fit-target` are absent because they are
|
|
22
|
+
* read before this point.
|
|
23
|
+
*/
|
|
24
|
+
const MEMORY_KEYS = {
|
|
25
|
+
completion: [
|
|
26
|
+
'ctx_size',
|
|
27
|
+
'gpu_layers',
|
|
28
|
+
'load_mode',
|
|
29
|
+
'parallel',
|
|
30
|
+
'cache-type-k',
|
|
31
|
+
'cache-type-v',
|
|
32
|
+
'main-gpu',
|
|
33
|
+
'split-mode',
|
|
34
|
+
'flash-attn',
|
|
35
|
+
'tensor-split',
|
|
36
|
+
'batch-size',
|
|
37
|
+
'ubatch-size',
|
|
38
|
+
'cpu-moe',
|
|
39
|
+
'n-cpu-moe',
|
|
40
|
+
'kv-offload',
|
|
41
|
+
'no-kv-offload',
|
|
42
|
+
'override-tensor',
|
|
43
|
+
'n-cpu-ffn',
|
|
44
|
+
'moe-cache-mib',
|
|
45
|
+
'prefetch-weights',
|
|
46
|
+
'tensor-read-lazy',
|
|
47
|
+
'fit',
|
|
48
|
+
'fit-ctx'
|
|
49
|
+
],
|
|
50
|
+
embedding: ['gpu_layers', 'batch_size', 'flash_attn', 'main-gpu', 'split-mode', 'tensor-split']
|
|
51
|
+
};
|
|
52
|
+
/** Shapes the SDK resolves elsewhere; reaching here means they were not. */
|
|
53
|
+
const UNSUPPORTED_KEYS = ['lora', 'projection_model_src'];
|
|
54
|
+
export function llamaLoadKindFor(modelType) {
|
|
55
|
+
if (modelType === ModelType.llamacppCompletion)
|
|
56
|
+
return 'completion';
|
|
57
|
+
if (modelType === ModelType.llamacppEmbedding)
|
|
58
|
+
return 'embedding';
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A CPU load's weights stay file-backed and evictable, so the fitter projects
|
|
63
|
+
* `fits` for nearly any model the OS could page through. Measured on a 24 GiB
|
|
64
|
+
* M4 Pro: an 18.3 GiB model at 32k context still reports `fits` on
|
|
65
|
+
* `device: 'cpu'`, and it does decode — at 0.1 tok/s. That answer carries no
|
|
66
|
+
* admission information.
|
|
67
|
+
*/
|
|
68
|
+
function isCpuLoad(transformed) {
|
|
69
|
+
return transformed['device']?.toLowerCase() === 'cpu';
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `fit-target` is the free margin the real load asks the engine to leave, in
|
|
73
|
+
* MiB, and a comma-separated list sets it per device. The fit request carries
|
|
74
|
+
* one value for every device, so a list resolves to its largest entry, which is
|
|
75
|
+
* the only reading that cannot project a device as roomier than the load will
|
|
76
|
+
* leave it.
|
|
77
|
+
*/
|
|
78
|
+
function fitTargetBytes(transformed) {
|
|
79
|
+
const value = transformed['fit-target'];
|
|
80
|
+
if (value === undefined)
|
|
81
|
+
return undefined;
|
|
82
|
+
const targets = value
|
|
83
|
+
.split(',')
|
|
84
|
+
.map((entry) => Number(entry.trim()))
|
|
85
|
+
.filter((entry) => Number.isFinite(entry) && entry >= 0);
|
|
86
|
+
return targets.length === 0 ? undefined : Math.max(...targets) * BYTES_PER_MIB;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Selects the settings that describe the load and spells them the way llama's
|
|
90
|
+
* argument table does. Everything forwarded is parsed by llama itself, so this
|
|
91
|
+
* layer classifies rather than interprets.
|
|
92
|
+
*/
|
|
93
|
+
function loadParams(loadKind, transformed) {
|
|
94
|
+
const carried = new Set(MEMORY_KEYS[loadKind]);
|
|
95
|
+
const params = {};
|
|
96
|
+
for (const [key, value] of Object.entries(transformed)) {
|
|
97
|
+
if (UNSUPPORTED_KEYS.includes(key)) {
|
|
98
|
+
return { detail: `unsupported load setting: ${key}` };
|
|
99
|
+
}
|
|
100
|
+
if (!carried.has(key))
|
|
101
|
+
continue;
|
|
102
|
+
params[CANONICAL_KEY[key] ?? key] = value;
|
|
103
|
+
}
|
|
104
|
+
return { params };
|
|
105
|
+
}
|
|
106
|
+
export function createLlamaFitRequest(params) {
|
|
107
|
+
const { loadKind } = params;
|
|
108
|
+
if (params.isShardedModel) {
|
|
109
|
+
return { supported: false, detail: 'sharded models are not representable' };
|
|
110
|
+
}
|
|
111
|
+
if (loadKind === 'completion' && params.artifacts?.['projectionModelPath'] !== undefined) {
|
|
112
|
+
return { supported: false, detail: 'multimodal projection loads are not representable' };
|
|
113
|
+
}
|
|
114
|
+
const modelConfig = (params.modelConfig ?? {});
|
|
115
|
+
const transformed = loadKind === 'completion'
|
|
116
|
+
? transformLlmConfig(modelConfig)
|
|
117
|
+
: transformEmbedConfig(modelConfig);
|
|
118
|
+
if (isCpuLoad(transformed)) {
|
|
119
|
+
return { supported: false, detail: 'cpu loads carry no device-memory evidence' };
|
|
120
|
+
}
|
|
121
|
+
const selected = loadParams(loadKind, transformed);
|
|
122
|
+
if ('detail' in selected)
|
|
123
|
+
return { supported: false, detail: selected.detail };
|
|
124
|
+
const request = {
|
|
125
|
+
modelPath: params.modelPath,
|
|
126
|
+
params: selected.params
|
|
127
|
+
};
|
|
128
|
+
// A pinned context is also the floor, so the fitter reports on the load the
|
|
129
|
+
// caller asked for rather than one it reduced.
|
|
130
|
+
const ctxSize = Number(selected.params['ctx-size']);
|
|
131
|
+
if (Number.isSafeInteger(ctxSize) && ctxSize > 0)
|
|
132
|
+
request.minCtxSize = ctxSize;
|
|
133
|
+
// The caller's own target and the advisory margin answer different questions
|
|
134
|
+
// — what this load leaves free, and what the models already resident need —
|
|
135
|
+
// so the projection holds to whichever is stricter.
|
|
136
|
+
const margins = [params.marginBytes, fitTargetBytes(transformed)].filter((value) => value !== undefined);
|
|
137
|
+
if (margins.length > 0)
|
|
138
|
+
request.marginBytes = Math.max(...margins);
|
|
139
|
+
return {
|
|
140
|
+
supported: true,
|
|
141
|
+
probe: loadKind === 'completion'
|
|
142
|
+
? { engine: 'llm-llamacpp', request }
|
|
143
|
+
: { engine: 'embed-llamacpp', request }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FitRequestPlan } from '../create-fit-request.js';
|
|
2
|
+
export interface TtsFitRequestParams {
|
|
3
|
+
modelPath: string;
|
|
4
|
+
modelConfig: unknown;
|
|
5
|
+
artifacts?: Record<string, string> | undefined;
|
|
6
|
+
marginBytes?: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function createTtsFitRequest(params: TtsFitRequestParams): FitRequestPlan;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from 'bare-fs';
|
|
2
|
+
import path from 'bare-path';
|
|
3
|
+
import { gpuLayersFromCount } from './gpu.js';
|
|
4
|
+
function unsupported(detail) {
|
|
5
|
+
return { supported: false, detail };
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* CosyVoice's companion set co-locates the flow, HiFT and voice GGUFs beside
|
|
9
|
+
* the LLM checkpoint, and the loader finds them by name in that directory. The
|
|
10
|
+
* fitter takes explicit paths, so the same directory is read here.
|
|
11
|
+
*/
|
|
12
|
+
function cosyvoiceCompanion(entries, dir, matches) {
|
|
13
|
+
const found = entries.find(matches);
|
|
14
|
+
return found === undefined ? undefined : path.join(dir, found);
|
|
15
|
+
}
|
|
16
|
+
function cosyvoiceRequest(modelPath, common) {
|
|
17
|
+
const dir = path.dirname(modelPath);
|
|
18
|
+
let entries;
|
|
19
|
+
try {
|
|
20
|
+
entries = fs.readdirSync(dir);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return unsupported('the cosyvoice companion set is not laid out beside the checkpoint');
|
|
24
|
+
}
|
|
25
|
+
const flowPath = cosyvoiceCompanion(entries, dir, (name) => name.includes('-flow-'));
|
|
26
|
+
const hiftPath = cosyvoiceCompanion(entries, dir, (name) => name.includes('-hift-'));
|
|
27
|
+
const voicePath = cosyvoiceCompanion(entries, dir, (name) => name === 'voice.gguf');
|
|
28
|
+
if (flowPath === undefined || hiftPath === undefined || voicePath === undefined) {
|
|
29
|
+
return unsupported('the cosyvoice companion set is not laid out beside the checkpoint');
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
supported: true,
|
|
33
|
+
probe: {
|
|
34
|
+
engine: 'tts-ggml',
|
|
35
|
+
request: {
|
|
36
|
+
engineType: 'cosyvoice3',
|
|
37
|
+
cosyvoiceLlmModelPath: modelPath,
|
|
38
|
+
cosyvoiceFlowModelPath: flowPath,
|
|
39
|
+
cosyvoiceHiftModelPath: hiftPath,
|
|
40
|
+
cosyvoiceVoiceModelPath: voicePath,
|
|
41
|
+
...common
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createTtsFitRequest(params) {
|
|
47
|
+
const config = (params.modelConfig ?? {});
|
|
48
|
+
const artifacts = params.artifacts ?? {};
|
|
49
|
+
const common = {
|
|
50
|
+
nGpuLayers: gpuLayersFromCount(config.useGPU, config.nGpuLayers),
|
|
51
|
+
...(params.marginBytes !== undefined && { marginBytes: params.marginBytes })
|
|
52
|
+
};
|
|
53
|
+
const supported = (request) => ({
|
|
54
|
+
supported: true,
|
|
55
|
+
probe: { engine: 'tts-ggml', request }
|
|
56
|
+
});
|
|
57
|
+
switch (config.ttsEngine) {
|
|
58
|
+
case 'supertonic':
|
|
59
|
+
return supported({
|
|
60
|
+
engineType: 'supertonic',
|
|
61
|
+
supertonicModelPath: params.modelPath,
|
|
62
|
+
...common,
|
|
63
|
+
...(config.ttsNumInferenceSteps !== undefined && { steps: config.ttsNumInferenceSteps })
|
|
64
|
+
});
|
|
65
|
+
case 'parler':
|
|
66
|
+
return supported({
|
|
67
|
+
engineType: 'parler',
|
|
68
|
+
parlerModelPath: params.modelPath,
|
|
69
|
+
...common,
|
|
70
|
+
...(config.maxFrames !== undefined && { maxFrames: config.maxFrames })
|
|
71
|
+
});
|
|
72
|
+
case 'audio8': {
|
|
73
|
+
const codecDecoderPath = artifacts['audio8CodecDecoderPath'];
|
|
74
|
+
if (codecDecoderPath === undefined) {
|
|
75
|
+
return unsupported('the audio8 codec decoder is not resolved');
|
|
76
|
+
}
|
|
77
|
+
const codecEncoderPath = artifacts['audio8CodecEncoderPath'];
|
|
78
|
+
return supported({
|
|
79
|
+
engineType: 'audio8',
|
|
80
|
+
audio8LmPath: params.modelPath,
|
|
81
|
+
audio8CodecDecoderPath: codecDecoderPath,
|
|
82
|
+
...(codecEncoderPath !== undefined && { audio8CodecEncoderPath: codecEncoderPath }),
|
|
83
|
+
...common,
|
|
84
|
+
...(config.maxFrames !== undefined && { maxFrames: config.maxFrames })
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
case 'cosyvoice3':
|
|
88
|
+
return cosyvoiceRequest(params.modelPath, common);
|
|
89
|
+
case 'moss':
|
|
90
|
+
return unsupported('the moss engine takes no fit request');
|
|
91
|
+
default: {
|
|
92
|
+
const s3genPath = artifacts['s3genPath'];
|
|
93
|
+
if (s3genPath === undefined) {
|
|
94
|
+
return unsupported('the chatterbox s3gen checkpoint is not resolved');
|
|
95
|
+
}
|
|
96
|
+
return supported({
|
|
97
|
+
engineType: 'chatterbox',
|
|
98
|
+
t3ModelPath: params.modelPath,
|
|
99
|
+
s3genModelPath: s3genPath,
|
|
100
|
+
...common,
|
|
101
|
+
...(config.nCtx !== undefined && config.nCtx > 0 && { nCtx: config.nCtx }),
|
|
102
|
+
...(config.kvCacheType !== undefined && { kvCacheType: config.kvCacheType })
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FitProbeResult } from './engine-fit.js';
|
|
2
|
+
/**
|
|
3
|
+
* Why a run produced no projection. Every one of these is absence of evidence,
|
|
4
|
+
* so the caller proceeds with the load it was going to run anyway.
|
|
5
|
+
*/
|
|
6
|
+
export type FitRunUnknownReason = 'unsupported-platform' | 'spawn-failed' | 'timeout' | 'cancelled' | 'crashed' | 'invalid-response' | 'invocation-error';
|
|
7
|
+
/** The contract both isolation strategies answer with. */
|
|
8
|
+
export type FitRunResult = {
|
|
9
|
+
status: 'completed';
|
|
10
|
+
probe: FitProbeResult;
|
|
11
|
+
} | {
|
|
12
|
+
status: 'unknown';
|
|
13
|
+
reason: FitRunUnknownReason;
|
|
14
|
+
message: string;
|
|
15
|
+
stderrTail?: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FitProbeRequest, FitProbeResult } from './engine-fit.js';
|
|
2
|
+
/**
|
|
3
|
+
* One JSON line in, one JSON line out. The child holds a native addon for the
|
|
4
|
+
* duration of the call, so the boundary stays deliberately narrow: nothing
|
|
5
|
+
* streams, nothing is stateful, and a child that dies mid-call costs only the
|
|
6
|
+
* projection.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FIT_PROCESS_PROTOCOL_VERSION = 1;
|
|
9
|
+
export declare const FIT_PROCESS_MAX_REQUEST_BYTES: number;
|
|
10
|
+
export declare const FIT_PROCESS_MAX_RESPONSE_BYTES: number;
|
|
11
|
+
export interface FitProcessRequest {
|
|
12
|
+
version: number;
|
|
13
|
+
probe: FitProbeRequest;
|
|
14
|
+
}
|
|
15
|
+
export type FitProcessResponse = {
|
|
16
|
+
status: 'completed';
|
|
17
|
+
probe: FitProbeResult;
|
|
18
|
+
} | {
|
|
19
|
+
status: 'invocation-error';
|
|
20
|
+
error: {
|
|
21
|
+
name: string;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function encodeFitProcessRequest(probe: FitProbeRequest): string;
|
|
26
|
+
export declare function parseFitProcessRequest(value: unknown): FitProcessRequest;
|
|
27
|
+
export declare function parseFitProcessResponse(value: unknown): FitProcessResponse;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One JSON line in, one JSON line out. The child holds a native addon for the
|
|
3
|
+
* duration of the call, so the boundary stays deliberately narrow: nothing
|
|
4
|
+
* streams, nothing is stateful, and a child that dies mid-call costs only the
|
|
5
|
+
* projection.
|
|
6
|
+
*/
|
|
7
|
+
export const FIT_PROCESS_PROTOCOL_VERSION = 1;
|
|
8
|
+
export const FIT_PROCESS_MAX_REQUEST_BYTES = 256 * 1024;
|
|
9
|
+
export const FIT_PROCESS_MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
10
|
+
export function encodeFitProcessRequest(probe) {
|
|
11
|
+
const line = `${JSON.stringify({ version: FIT_PROCESS_PROTOCOL_VERSION, probe })}\n`;
|
|
12
|
+
if (Buffer.byteLength(line) > FIT_PROCESS_MAX_REQUEST_BYTES) {
|
|
13
|
+
throw new RangeError(`Fit request exceeds ${FIT_PROCESS_MAX_REQUEST_BYTES} bytes`);
|
|
14
|
+
}
|
|
15
|
+
return line;
|
|
16
|
+
}
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
export function parseFitProcessRequest(value) {
|
|
21
|
+
if (!isRecord(value))
|
|
22
|
+
throw new TypeError('Fit request must be an object');
|
|
23
|
+
if (value['version'] !== FIT_PROCESS_PROTOCOL_VERSION) {
|
|
24
|
+
throw new TypeError(`Unsupported fit protocol version: ${String(value['version'])}`);
|
|
25
|
+
}
|
|
26
|
+
const probe = value['probe'];
|
|
27
|
+
if (!isRecord(probe) || typeof probe['engine'] !== 'string' || !isRecord(probe['request'])) {
|
|
28
|
+
throw new TypeError('Fit request must carry an engine and a request');
|
|
29
|
+
}
|
|
30
|
+
return { version: FIT_PROCESS_PROTOCOL_VERSION, probe: probe };
|
|
31
|
+
}
|
|
32
|
+
export function parseFitProcessResponse(value) {
|
|
33
|
+
if (!isRecord(value))
|
|
34
|
+
throw new TypeError('Fit response must be an object');
|
|
35
|
+
if (value['status'] === 'invocation-error') {
|
|
36
|
+
const error = value['error'];
|
|
37
|
+
if (!isRecord(error) ||
|
|
38
|
+
typeof error['name'] !== 'string' ||
|
|
39
|
+
typeof error['message'] !== 'string') {
|
|
40
|
+
throw new TypeError('Fit invocation error must carry a name and a message');
|
|
41
|
+
}
|
|
42
|
+
return { status: 'invocation-error', error: { name: error['name'], message: error['message'] } };
|
|
43
|
+
}
|
|
44
|
+
if (value['status'] !== 'completed') {
|
|
45
|
+
throw new TypeError(`Unknown fit response status: ${String(value['status'])}`);
|
|
46
|
+
}
|
|
47
|
+
const probe = value['probe'];
|
|
48
|
+
if (!isRecord(probe) || typeof probe['engine'] !== 'string' || !isRecord(probe['result'])) {
|
|
49
|
+
throw new TypeError('Fit response must carry an engine and a result');
|
|
50
|
+
}
|
|
51
|
+
if (typeof probe['result']['status'] !== 'string') {
|
|
52
|
+
throw new TypeError('Fit result must carry a status');
|
|
53
|
+
}
|
|
54
|
+
return { status: 'completed', probe: probe };
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|