@qvac/sdk 0.23.0 → 0.24.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 +115 -58
- package/README.md +10 -13
- package/dist/examples/asr/parakeet-sortformer.js +24 -14
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +40 -11
- package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
- package/dist/examples/asr/whispercpp-prompt.js +9 -5
- package/dist/examples/assess-model-fit.d.ts +7 -9
- package/dist/examples/assess-model-fit.js +22 -43
- package/dist/examples/calc-tokens.d.ts +2 -0
- package/dist/examples/calc-tokens.js +21 -0
- package/dist/examples/classification/classify-image.js +11 -5
- package/dist/examples/completion-stop-reason.d.ts +3 -3
- package/dist/examples/completion-stop-reason.js +4 -4
- package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
- package/dist/examples/diffusion-flux3-klein.js +102 -0
- package/dist/examples/diffusion-moss-image.d.ts +2 -0
- package/dist/examples/diffusion-moss-image.js +126 -0
- package/dist/examples/diffusion-qwen-image-21.js +15 -4
- package/dist/examples/embed-multimodal.d.ts +2 -0
- package/dist/examples/embed-multimodal.js +80 -0
- package/dist/examples/embed-p2p.js +2 -2
- package/dist/examples/image/megaloc.d.ts +2 -0
- package/dist/examples/image/megaloc.js +37 -0
- package/dist/examples/llamacpp-multimodal.js +18 -0
- package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
- package/dist/examples/rag/rag-turbovec.js +2 -2
- package/dist/examples/sessions.d.ts +17 -0
- package/dist/examples/sessions.js +63 -0
- package/dist/examples/tools/llamacpp-deferred-tools.js +8 -4
- package/dist/scripts/check-resource-collectors-packaging.js +7 -6
- package/dist/scripts/contract/build-contract.d.ts +2 -1
- package/dist/scripts/contract/build-contract.js +13 -1
- package/dist/scripts/contract/constants-registry.d.ts +17 -0
- package/dist/scripts/contract/constants-registry.js +8 -2
- package/dist/scripts/contract/method-shapes.d.ts +4 -0
- package/dist/scripts/contract/method-shapes.js +4 -0
- package/dist/scripts/enforce-inference-versions.d.ts +1 -1
- package/dist/scripts/enforce-inference-versions.js +28 -18
- package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
- package/dist/src/client/api/assess-model-fit.d.ts +17 -17
- package/dist/src/client/api/assess-model-fit.js +18 -31
- package/dist/src/client/api/audio-edit.d.ts +5 -3
- package/dist/src/client/api/audio-edit.js +5 -3
- package/dist/src/client/api/audio-gen-result.js +134 -45
- package/dist/src/client/api/audio-gen.d.ts +40 -3
- package/dist/src/client/api/audio-gen.js +40 -3
- package/dist/src/client/api/audio-understand.d.ts +2 -2
- package/dist/src/client/api/audio-understand.js +2 -2
- package/dist/src/client/api/batch-completion.js +2 -1
- package/dist/src/client/api/calc-tokens.d.ts +33 -0
- package/dist/src/client/api/calc-tokens.js +44 -0
- package/dist/src/client/api/cancel.d.ts +2 -2
- package/dist/src/client/api/cancel.js +2 -2
- package/dist/src/client/api/classify.d.ts +12 -5
- package/dist/src/client/api/classify.js +17 -5
- package/dist/src/client/api/client-request-id.d.ts +0 -15
- package/dist/src/client/api/client-request-id.js +15 -12
- package/dist/src/client/api/completion-stream.d.ts +8 -1
- package/dist/src/client/api/completion-stream.js +10 -1
- package/dist/src/client/api/delete-cache.d.ts +9 -2
- package/dist/src/client/api/delete-cache.js +13 -3
- package/dist/src/client/api/diffusion.d.ts +20 -4
- package/dist/src/client/api/diffusion.js +23 -5
- package/dist/src/client/api/embed.d.ts +82 -29
- package/dist/src/client/api/embed.js +64 -19
- package/dist/src/client/api/get-model-info.d.ts +2 -2
- package/dist/src/client/api/get-model-info.js +2 -2
- package/dist/src/client/api/get-system-resources.d.ts +2 -2
- package/dist/src/client/api/get-system-resources.js +2 -2
- package/dist/src/client/api/heartbeat.d.ts +3 -2
- package/dist/src/client/api/heartbeat.js +3 -2
- package/dist/src/client/api/index.d.ts +4 -3
- package/dist/src/client/api/index.js +2 -1
- package/dist/src/client/api/invoke-plugin.d.ts +8 -2
- package/dist/src/client/api/invoke-plugin.js +17 -2
- package/dist/src/client/api/load-model.js +5 -2
- package/dist/src/client/api/ocr.d.ts +5 -3
- package/dist/src/client/api/ocr.js +44 -21
- package/dist/src/client/api/rag.d.ts +1 -1
- package/dist/src/client/api/rag.js +1 -1
- package/dist/src/client/api/registry.d.ts +17 -7
- package/dist/src/client/api/registry.js +37 -12
- package/dist/src/client/api/resume.d.ts +2 -1
- package/dist/src/client/api/resume.js +2 -2
- package/dist/src/client/api/rpc-server.d.ts +4 -4
- package/dist/src/client/api/rpc-server.js +10 -10
- package/dist/src/client/api/state.d.ts +2 -2
- package/dist/src/client/api/state.js +2 -2
- package/dist/src/client/api/subscribe-logs.d.ts +2 -2
- package/dist/src/client/api/subscribe-logs.js +2 -2
- package/dist/src/client/api/suspend.d.ts +4 -2
- package/dist/src/client/api/suspend.js +4 -3
- package/dist/src/client/api/text-to-speech.d.ts +14 -5
- package/dist/src/client/api/text-to-speech.js +83 -29
- package/dist/src/client/api/transcribe.d.ts +6 -2
- package/dist/src/client/api/transcribe.js +7 -1
- package/dist/src/client/api/unload-model.d.ts +19 -7
- package/dist/src/client/api/unload-model.js +29 -11
- package/dist/src/client/api/upscale.d.ts +6 -3
- package/dist/src/client/api/upscale.js +9 -4
- package/dist/src/client/api/vector-index.d.ts +50 -16
- package/dist/src/client/api/vector-index.js +100 -48
- package/dist/src/client/api/video-request.d.ts +5 -5
- package/dist/src/client/api/video.d.ts +3 -2
- package/dist/src/client/api/video.js +3 -2
- package/dist/src/client/api/vla.d.ts +9 -5
- package/dist/src/client/api/vla.js +17 -8
- package/dist/src/client/api/world.d.ts +5 -5
- package/dist/src/client/api/world.js +4 -4
- package/dist/src/client/init-hooks.d.ts +6 -4
- package/dist/src/client/init-hooks.js +12 -15
- package/dist/src/client/logging-stream-registry.d.ts +6 -3
- package/dist/src/client/logging-stream-registry.js +31 -12
- package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
- package/dist/src/client/rpc/bundle-stamp.js +75 -0
- package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
- package/dist/src/client/rpc/expo-home-dir.js +4 -0
- package/dist/src/client/rpc/expo-rpc-client.js +189 -135
- package/dist/src/client/rpc/node-rpc-client.js +322 -413
- package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
- package/dist/src/client/rpc/pear-runtime.js +12 -0
- package/dist/src/client/rpc/rpc-client.d.ts +5 -4
- package/dist/src/client/rpc/rpc-client.js +126 -23
- package/dist/src/client/rpc/rpc-error.js +21 -2
- package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
- package/dist/src/client/rpc/unbundled-harness.js +27 -0
- package/dist/src/client/rpc/worker-failure.d.ts +27 -0
- package/dist/src/client/rpc/worker-failure.js +61 -0
- package/dist/src/client/session-registry.d.ts +75 -0
- package/dist/src/client/session-registry.js +149 -0
- package/dist/src/client/session.d.ts +125 -0
- package/dist/src/client/session.js +148 -0
- package/dist/src/commands/bundle/addons.d.ts +14 -0
- package/dist/src/commands/bundle/addons.js +65 -0
- package/dist/src/commands/bundle/constants.js +1 -0
- package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
- package/dist/src/commands/bundle/entry-gen.js +17 -50
- package/dist/src/commands/bundle/index.d.ts +59 -13
- package/dist/src/commands/bundle/index.js +345 -121
- package/dist/src/commands/bundle/link.d.ts +58 -0
- package/dist/src/commands/bundle/link.js +135 -0
- package/dist/src/commands/bundle/node-support.d.ts +13 -0
- package/dist/src/commands/bundle/node-support.js +23 -0
- package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
- package/dist/src/commands/bundle/read-bundle.js +27 -0
- package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
- package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
- package/dist/src/commands/bundle/scratch.d.ts +35 -0
- package/dist/src/commands/bundle/scratch.js +178 -0
- package/dist/src/commands/bundle/targets.d.ts +14 -0
- package/dist/src/commands/bundle/targets.js +37 -0
- package/dist/src/commands/host-prebuilds/index.d.ts +5 -4
- package/dist/src/commands/host-prebuilds/index.js +9 -7
- package/dist/src/commands/index.d.ts +4 -3
- package/dist/src/commands/verify/abi.d.ts +20 -14
- package/dist/src/commands/verify/abi.js +11 -79
- package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
- package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
- package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
- package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
- package/dist/src/commands/verify/bundle-source.js +25 -21
- package/dist/src/commands/verify/engines-advice.d.ts +2 -8
- package/dist/src/commands/verify/engines-advice.js +7 -54
- package/dist/src/commands/verify/index.d.ts +30 -29
- package/dist/src/commands/verify/index.js +92 -200
- package/dist/src/commands/verify/prebuilds.d.ts +3 -5
- package/dist/src/commands/verify/prebuilds.js +1 -2
- package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
- package/dist/src/commands/verify/resource-collectors.js +1 -50
- package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
- package/dist/src/commands/verify/sidecar-runtime.js +51 -0
- package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
- package/dist/src/expo/plugins/withBareKit.js +204 -0
- package/dist/src/expo/plugins/withMobileBundle.d.ts +4 -11
- package/dist/src/expo/plugins/withMobileBundle.js +36 -57
- package/dist/src/expo/plugins/withQvacSDK.d.ts +1 -0
- package/dist/src/expo/plugins/withQvacSDK.js +3 -0
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.js +10 -14
- package/dist/src/logging/utils.js +10 -2
- package/dist/src/plugin-ids.d.ts +2 -1
- package/dist/src/plugin-ids.js +2 -0
- package/dist/src/schemas/public.d.ts +1 -1
- package/dist/src/schemas/public.js +1 -1
- package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
- package/dist/src/schemas/sdk-errors-client.js +30 -36
- package/dist/src/schemas/sdk-errors-server.d.ts +11 -1
- package/dist/src/schemas/sdk-errors-server.js +60 -2
- package/dist/src/server/rpc/rpc-utils.d.ts +25 -4
- package/dist/src/server/rpc/rpc-utils.js +39 -5
- package/dist/src/utils/errors-client.d.ts +37 -29
- package/dist/src/utils/errors-client.js +50 -41
- package/dist/src/utils/errors-server.d.ts +59 -1
- package/dist/src/utils/errors-server.js +110 -1
- package/dist/src/utils/withTimeout.js +34 -17
- package/dist/src/worker/handle-request.js +25 -22
- package/dist/src/worker/handler-utils.d.ts +2 -6
- package/dist/src/worker/handler-utils.js +2 -20
- package/dist/src/worker/index.d.ts +2 -4
- package/dist/src/worker/index.js +23 -35
- package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
- package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
- package/dist/src/worker/shim.d.ts +4 -0
- package/dist/src/worker/shim.js +7 -0
- package/dist/src/worker/start.d.ts +9 -0
- package/dist/src/worker/start.js +16 -0
- package/dist/src/worker/unbundled-shim.d.ts +2 -0
- package/dist/src/worker/unbundled-shim.js +4 -0
- package/docs/system-resources-support-matrix.md +27 -19
- package/package.json +62 -51
- package/src/electron-forge/index.cjs +65 -91
- package/dist/examples/model-fit-ui/server.d.ts +0 -24
- package/dist/examples/model-fit-ui/server.js +0 -221
- package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
- package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
- package/dist/src/client/rpc/init-timeout.d.ts +0 -26
- package/dist/src/client/rpc/init-timeout.js +0 -25
- package/dist/src/client/rpc/ipc-socket-path.d.ts +0 -11
- package/dist/src/client/rpc/ipc-socket-path.js +0 -30
- package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
- package/dist/src/client/rpc/worker-startup-error.js +0 -13
- package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
- package/dist/src/commands/bundle/bare-pack.js +0 -77
- package/dist/src/commands/bundle/manifest.d.ts +0 -25
- package/dist/src/commands/bundle/manifest.js +0 -192
- package/dist/src/expo/plugins/link-addons.d.ts +0 -18
- package/dist/src/expo/plugins/link-addons.js +0 -65
- package/dist/src/pear/pre.d.ts +0 -21
- package/dist/src/pear/pre.js +0 -450
- package/dist/src/server/env.d.ts +0 -22
- package/dist/src/server/env.js +0 -59
- package/dist/src/server/utils/qvac-paths.d.ts +0 -2
- package/dist/src/server/utils/qvac-paths.js +0 -5
- package/dist/src/server/utils/worker-lock.d.ts +0 -3
- package/dist/src/server/utils/worker-lock.js +0 -67
- package/dist/src/worker/create-server.d.ts +0 -8
- package/dist/src/worker/create-server.js +0 -51
- package/dist/src/worker/lifecycle.d.ts +0 -23
- package/dist/src/worker/lifecycle.js +0 -149
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { textToSpeechStreamResponseSchema, textToSpeechStreamRequestSchema, ttsClientParamsSchema } from '@qvac/inference/surface';
|
|
1
|
+
import { textToSpeechStreamResponseSchema, textToSpeechStreamRequestSchema, ttsClientParamsSchema, withDecodedTtsPcm, decodeTtsPcm } from '@qvac/inference/surface';
|
|
2
2
|
import { stream as streamRpc, duplex } from '../../client/rpc/rpc-client.js';
|
|
3
3
|
import { getClientLogger } from '../../logging/index.js';
|
|
4
4
|
import { TextToSpeechStreamFailedError } from '../../utils/errors-client.js';
|
|
@@ -164,7 +164,13 @@ function buildTextToSpeechStreamRequest(params, requestId) {
|
|
|
164
164
|
...(params.expressivity !== undefined && { expressivity: params.expressivity }),
|
|
165
165
|
...(params.noise !== undefined && { noise: params.noise }),
|
|
166
166
|
...(params.reverb !== undefined && { reverb: params.reverb }),
|
|
167
|
-
...(params.quality !== undefined && { quality: params.quality })
|
|
167
|
+
...(params.quality !== undefined && { quality: params.quality }),
|
|
168
|
+
// Per-request voice controls: CosyVoice3's instruct, Audio8's reference pair.
|
|
169
|
+
...(params.instruct !== undefined && { instruct: params.instruct }),
|
|
170
|
+
...(params.referenceAudioSrc !== undefined && {
|
|
171
|
+
referenceAudioSrc: params.referenceAudioSrc
|
|
172
|
+
}),
|
|
173
|
+
...(params.referenceText !== undefined && { referenceText: params.referenceText })
|
|
168
174
|
};
|
|
169
175
|
}
|
|
170
176
|
/**
|
|
@@ -174,9 +180,10 @@ function buildTextToSpeechStreamRequest(params, requestId) {
|
|
|
174
180
|
*
|
|
175
181
|
* - `stream: false` — collect all PCM samples and resolve once via
|
|
176
182
|
* `result.buffer` (`Promise<number[]>`). `bufferStream` is empty.
|
|
177
|
-
* - `stream: true` (default) — yield PCM
|
|
178
|
-
* (`AsyncGenerator<
|
|
179
|
-
*
|
|
183
|
+
* - `stream: true` (default) — yield PCM through `result.chunkStream`
|
|
184
|
+
* (`AsyncGenerator<Int16Array>`, one chunk per frame) or
|
|
185
|
+
* `result.bufferStream` (`AsyncGenerator<number>`, one sample at a time).
|
|
186
|
+
* `buffer` resolves to an empty array.
|
|
180
187
|
* - `stream: true, sentenceStream: true` — also exposes `result.chunkUpdates`
|
|
181
188
|
* (`AsyncGenerator<TtsSentenceChunkUpdate>`) so callers can mux per-sentence
|
|
182
189
|
* metadata with the audio. Multiple consumers can iterate the response
|
|
@@ -199,7 +206,8 @@ function buildTextToSpeechStreamRequest(params, requestId) {
|
|
|
199
206
|
* before draining the audio); `result.stats` and `result.stopReason` resolve
|
|
200
207
|
* from the terminal frame. All three resolve — with `undefined` when the run
|
|
201
208
|
* produced none — rather than reject. In `stream: true` mode (the default) the
|
|
202
|
-
* run starts lazily: nothing is sent until `bufferStream` is
|
|
209
|
+
* run starts lazily: nothing is sent until `chunkStream` or `bufferStream` is
|
|
210
|
+
* first iterated, so
|
|
203
211
|
* `done`, `sampleRate`, `stats` and `stopReason` stay pending until then. In
|
|
204
212
|
* `stream: false` and `sentenceStream: true` modes the run starts immediately.
|
|
205
213
|
* Read `sampleRate` rather than assuming the engine default: `outputSampleRate`
|
|
@@ -207,7 +215,7 @@ function buildTextToSpeechStreamRequest(params, requestId) {
|
|
|
207
215
|
*
|
|
208
216
|
* @param params - TTS request parameters (see `TtsClientParamsInput`).
|
|
209
217
|
* @param options - Optional RPC options (timeout, profiling, force new connection).
|
|
210
|
-
* @returns A `TextToSpeechStreamResult` with `bufferStream`, `buffer`, `done`,
|
|
218
|
+
* @returns A `TextToSpeechStreamResult` with `chunkStream`, `bufferStream`, `buffer`, `done`,
|
|
211
219
|
* `sampleRate`, `stats`, and (when `sentenceStream: true`)
|
|
212
220
|
* `chunkUpdates`.
|
|
213
221
|
* @throws {TextToSpeechStreamFailedError} When `sentenceStream: true` is paired
|
|
@@ -236,9 +244,10 @@ export function textToSpeech(params, options) {
|
|
|
236
244
|
// constructed in tests with a hand-rolled source instead.
|
|
237
245
|
async function* ttsResponseSource(request, options, side) {
|
|
238
246
|
try {
|
|
239
|
-
for await (const
|
|
240
|
-
if (
|
|
247
|
+
for await (const raw of streamRpc(request, options)) {
|
|
248
|
+
if (raw.type !== 'textToSpeech')
|
|
241
249
|
continue;
|
|
250
|
+
const response = withDecodedTtsPcm(raw);
|
|
242
251
|
side.observe(response);
|
|
243
252
|
yield response;
|
|
244
253
|
}
|
|
@@ -259,6 +268,7 @@ export function createTtsSideChannel() {
|
|
|
259
268
|
let resolveSampleRate;
|
|
260
269
|
let resolveStats;
|
|
261
270
|
let resolveStopReason;
|
|
271
|
+
let resolveSpeechTokenIds;
|
|
262
272
|
const sampleRate = new Promise((resolve) => {
|
|
263
273
|
resolveSampleRate = resolve;
|
|
264
274
|
});
|
|
@@ -268,15 +278,22 @@ export function createTtsSideChannel() {
|
|
|
268
278
|
const stopReason = new Promise((resolve) => {
|
|
269
279
|
resolveStopReason = resolve;
|
|
270
280
|
});
|
|
281
|
+
const speechTokenIds = new Promise((resolve) => {
|
|
282
|
+
resolveSpeechTokenIds = resolve;
|
|
283
|
+
});
|
|
271
284
|
let seenSampleRate;
|
|
272
285
|
let latestStats;
|
|
273
286
|
let seenStopReason;
|
|
287
|
+
// CosyVoice3 hands back one array per native synthesis; the chunked paths
|
|
288
|
+
// run one per sentence, so the run's trajectory is their concatenation.
|
|
289
|
+
let seenSpeechTokenIds;
|
|
274
290
|
let settled = false;
|
|
275
291
|
return {
|
|
276
292
|
text,
|
|
277
293
|
sampleRate,
|
|
278
294
|
stats,
|
|
279
295
|
stopReason,
|
|
296
|
+
speechTokenIds,
|
|
280
297
|
observe(response) {
|
|
281
298
|
if (response.text !== undefined)
|
|
282
299
|
seenText = response.text;
|
|
@@ -292,6 +309,13 @@ export function createTtsSideChannel() {
|
|
|
292
309
|
latestStats = response.stats;
|
|
293
310
|
if (response.stopReason !== undefined)
|
|
294
311
|
seenStopReason = response.stopReason;
|
|
312
|
+
if (response.speechTokenIds !== undefined) {
|
|
313
|
+
// Append into one owned array: a spread per frame would copy every
|
|
314
|
+
// token collected so far on each sentence of a long stream.
|
|
315
|
+
seenSpeechTokenIds ??= [];
|
|
316
|
+
for (const id of response.speechTokenIds)
|
|
317
|
+
seenSpeechTokenIds.push(id);
|
|
318
|
+
}
|
|
295
319
|
},
|
|
296
320
|
settle() {
|
|
297
321
|
if (settled)
|
|
@@ -301,6 +325,7 @@ export function createTtsSideChannel() {
|
|
|
301
325
|
resolveSampleRate(seenSampleRate);
|
|
302
326
|
resolveStats(latestStats);
|
|
303
327
|
resolveStopReason(seenStopReason);
|
|
328
|
+
resolveSpeechTokenIds(seenSpeechTokenIds);
|
|
304
329
|
}
|
|
305
330
|
};
|
|
306
331
|
}
|
|
@@ -312,10 +337,11 @@ function sentenceStreamTts(request, options) {
|
|
|
312
337
|
// deferred subscribing until the generators were iterated, the first
|
|
313
338
|
// consumer could trim the queue before the second ever registered,
|
|
314
339
|
// silently dropping earlier frames.
|
|
315
|
-
const
|
|
340
|
+
const audio = sentenceAudioViews(multicast.subscribe());
|
|
316
341
|
const chunkSubscription = multicast.subscribe();
|
|
317
342
|
return {
|
|
318
|
-
bufferStream:
|
|
343
|
+
bufferStream: audio.bufferStream,
|
|
344
|
+
chunkStream: audio.chunkStream,
|
|
319
345
|
chunkUpdates: sentenceChunkUpdates(chunkSubscription),
|
|
320
346
|
buffer: Promise.resolve([]),
|
|
321
347
|
done: multicast.done,
|
|
@@ -323,23 +349,38 @@ function sentenceStreamTts(request, options) {
|
|
|
323
349
|
text: side.text,
|
|
324
350
|
sampleRate: side.sampleRate,
|
|
325
351
|
stats: side.stats,
|
|
326
|
-
stopReason: side.stopReason
|
|
352
|
+
stopReason: side.stopReason,
|
|
353
|
+
speechTokenIds: side.speechTokenIds
|
|
327
354
|
};
|
|
328
355
|
}
|
|
329
|
-
|
|
356
|
+
// Both audio views share ONE multicast subscription, so an un-iterated
|
|
357
|
+
// `chunkStream` cannot pin the queue for a caller that drains `bufferStream`
|
|
358
|
+
// and `chunkUpdates` only. Exported for test use; not part of the public
|
|
359
|
+
// surface.
|
|
360
|
+
export function sentenceAudioViews(subscription) {
|
|
361
|
+
const chunkStream = pcmChunksOf(subscription);
|
|
362
|
+
return { bufferStream: samplesOf(chunkStream), chunkStream };
|
|
363
|
+
}
|
|
364
|
+
export async function* pcmChunksOf(source) {
|
|
330
365
|
for await (const m of source) {
|
|
331
366
|
if (m.buffer.length > 0) {
|
|
332
|
-
yield
|
|
367
|
+
yield Int16Array.from(m.buffer);
|
|
333
368
|
}
|
|
334
369
|
if (m.done)
|
|
335
370
|
break;
|
|
336
371
|
}
|
|
337
372
|
}
|
|
373
|
+
export async function* samplesOf(chunks) {
|
|
374
|
+
for await (const chunk of chunks) {
|
|
375
|
+
yield* chunk;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
338
378
|
async function* sentenceChunkUpdates(source) {
|
|
339
379
|
for await (const m of source) {
|
|
340
380
|
const hasAudio = m.buffer.length > 0;
|
|
341
381
|
const hasMeta = m.chunkIndex !== undefined ||
|
|
342
|
-
(typeof m.sentenceChunk === 'string' && m.sentenceChunk.length > 0)
|
|
382
|
+
(typeof m.sentenceChunk === 'string' && m.sentenceChunk.length > 0) ||
|
|
383
|
+
m.speechTokenIds !== undefined;
|
|
343
384
|
if (hasAudio || hasMeta) {
|
|
344
385
|
yield {
|
|
345
386
|
buffer: hasAudio ? [...m.buffer] : [],
|
|
@@ -348,7 +389,8 @@ async function* sentenceChunkUpdates(source) {
|
|
|
348
389
|
...(typeof m.sentenceChunk === 'string' && m.sentenceChunk.length > 0
|
|
349
390
|
? { sentenceChunk: m.sentenceChunk }
|
|
350
391
|
: {}),
|
|
351
|
-
...(m.isLast !== undefined ? { isLast: m.isLast } : {})
|
|
392
|
+
...(m.isLast !== undefined ? { isLast: m.isLast } : {}),
|
|
393
|
+
...(m.speechTokenIds !== undefined ? { speechTokenIds: m.speechTokenIds } : {})
|
|
352
394
|
};
|
|
353
395
|
}
|
|
354
396
|
if (m.done)
|
|
@@ -364,30 +406,38 @@ function plainStreamTts(request, options) {
|
|
|
364
406
|
});
|
|
365
407
|
done.catch(() => { });
|
|
366
408
|
const side = createTtsSideChannel();
|
|
409
|
+
// Both views share one lazy run; iterating either starts it.
|
|
410
|
+
const chunkStream = plainTtsChunkStream(request, options, resolveDone, rejectDone, side);
|
|
367
411
|
return {
|
|
368
|
-
bufferStream:
|
|
412
|
+
bufferStream: samplesOf(chunkStream),
|
|
413
|
+
chunkStream,
|
|
369
414
|
buffer: Promise.resolve([]),
|
|
370
415
|
done,
|
|
371
416
|
requestId: request.requestId,
|
|
372
417
|
text: side.text,
|
|
373
418
|
sampleRate: side.sampleRate,
|
|
374
419
|
stats: side.stats,
|
|
375
|
-
stopReason: side.stopReason
|
|
420
|
+
stopReason: side.stopReason,
|
|
421
|
+
speechTokenIds: side.speechTokenIds
|
|
376
422
|
};
|
|
377
423
|
}
|
|
378
|
-
async function*
|
|
424
|
+
async function* plainTtsChunkStream(request, options, resolveDone, rejectDone, side) {
|
|
379
425
|
let settled = false;
|
|
380
426
|
try {
|
|
381
|
-
for await (const
|
|
382
|
-
if (
|
|
427
|
+
for await (const raw of streamRpc(request, options)) {
|
|
428
|
+
if (raw.type !== 'textToSpeech')
|
|
383
429
|
continue;
|
|
384
430
|
// See TtsMulticast.pump — skip per-frame Zod validation; the server is
|
|
385
431
|
// the source of truth for this wire shape.
|
|
386
|
-
side
|
|
387
|
-
|
|
388
|
-
|
|
432
|
+
// The side channel reads text, rate, stats and stopReason, never the
|
|
433
|
+
// audio, so a `pcm` frame is decoded straight to the typed array callers
|
|
434
|
+
// get instead of through an intermediate `number[]`.
|
|
435
|
+
side.observe(raw);
|
|
436
|
+
const chunk = raw.pcm !== undefined ? decodeTtsPcm(raw.pcm) : Int16Array.from(raw.buffer);
|
|
437
|
+
if (chunk.length > 0) {
|
|
438
|
+
yield chunk;
|
|
389
439
|
}
|
|
390
|
-
if (
|
|
440
|
+
if (raw.done) {
|
|
391
441
|
settled = true;
|
|
392
442
|
resolveDone(true);
|
|
393
443
|
}
|
|
@@ -419,24 +469,28 @@ function collectTts(request, options) {
|
|
|
419
469
|
const side = createTtsSideChannel();
|
|
420
470
|
return {
|
|
421
471
|
bufferStream: emptyBufferStream(),
|
|
472
|
+
chunkStream: emptyChunkStream(),
|
|
422
473
|
buffer: collectTtsBuffer(request, options, resolveDone, rejectDone, side),
|
|
423
474
|
done,
|
|
424
475
|
requestId: request.requestId,
|
|
425
476
|
text: side.text,
|
|
426
477
|
sampleRate: side.sampleRate,
|
|
427
478
|
stats: side.stats,
|
|
428
|
-
stopReason: side.stopReason
|
|
479
|
+
stopReason: side.stopReason,
|
|
480
|
+
speechTokenIds: side.speechTokenIds
|
|
429
481
|
};
|
|
430
482
|
}
|
|
431
483
|
async function* emptyBufferStream() {
|
|
432
484
|
// Non-streaming mode exposes no incremental buffer stream.
|
|
433
485
|
}
|
|
486
|
+
async function* emptyChunkStream() { }
|
|
434
487
|
async function collectTtsBuffer(request, options, resolveDone, rejectDone, side) {
|
|
435
488
|
let buffer = [];
|
|
436
489
|
try {
|
|
437
|
-
for await (const
|
|
438
|
-
if (
|
|
490
|
+
for await (const raw of streamRpc(request, options)) {
|
|
491
|
+
if (raw.type !== 'textToSpeech')
|
|
439
492
|
continue;
|
|
493
|
+
const response = withDecodedTtsPcm(raw);
|
|
440
494
|
side.observe(response);
|
|
441
495
|
buffer = buffer.concat(response.buffer);
|
|
442
496
|
if (response.done) {
|
|
@@ -558,5 +612,5 @@ function processTextToSpeechStreamLine(line) {
|
|
|
558
612
|
if (obj['type'] === 'error') {
|
|
559
613
|
throw new TextToSpeechStreamFailedError(obj['message'] ?? 'Unknown server error');
|
|
560
614
|
}
|
|
561
|
-
return textToSpeechStreamResponseSchema.parse(parsed);
|
|
615
|
+
return withDecodedTtsPcm(textToSpeechStreamResponseSchema.parse(parsed));
|
|
562
616
|
}
|
|
@@ -11,7 +11,9 @@ type TranscribeDuplexFactory = (request: TranscribeStreamRequest, options?: RPCO
|
|
|
11
11
|
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
12
12
|
* @param params.metadata - When true, resolves to an array of transcript
|
|
13
13
|
* segments (`{ text, startMs, endMs, append, id }`,
|
|
14
|
-
* plus `isEndOfTurn` and `startsWord` on parakeet
|
|
14
|
+
* plus `isEndOfTurn` and `startsWord` on parakeet, and
|
|
15
|
+
* `language`, `noSpeechProb`, `speakerTurnNext` and
|
|
16
|
+
* `tokens` on whisper when the engine reports them)
|
|
15
17
|
* instead of joined text.
|
|
16
18
|
* @param options - Optional RPC options including per-call profiling
|
|
17
19
|
* @returns A promise (decorated with `requestId`) resolving to the
|
|
@@ -61,7 +63,9 @@ export declare function transcribeStream(params: TranscribeClientParams, options
|
|
|
61
63
|
* @param params.prompt - Optional initial prompt to guide transcription
|
|
62
64
|
* @param params.metadata - When true, the session yields transcript segment
|
|
63
65
|
* objects (`{ text, startMs, endMs, append, id }`,
|
|
64
|
-
* plus `isEndOfTurn` and `startsWord` on parakeet
|
|
66
|
+
* plus `isEndOfTurn` and `startsWord` on parakeet, and
|
|
67
|
+
* `language`, `noSpeechProb`, `speakerTurnNext` and
|
|
68
|
+
* `tokens` on whisper when the engine reports them)
|
|
65
69
|
* instead of plain text.
|
|
66
70
|
* @param options - Optional RPC options including per-call profiling.
|
|
67
71
|
* @returns A session object: call `write(audioChunk)` with a `Uint8Array`
|
|
@@ -313,6 +313,8 @@ export function processLineConversation(line, wantsMetadata, onTerminal) {
|
|
|
313
313
|
speaking: response.vad.speaking,
|
|
314
314
|
probability: response.vad.probability,
|
|
315
315
|
...(response.vad.source && { source: response.vad.source }),
|
|
316
|
+
...(response.vad.timestamp !== undefined && { timestamp: response.vad.timestamp }),
|
|
317
|
+
...(response.vad.chunkIndex !== undefined && { chunkIndex: response.vad.chunkIndex }),
|
|
316
318
|
...(response.vad.speakerId !== undefined && { speakerId: response.vad.speakerId })
|
|
317
319
|
};
|
|
318
320
|
}
|
|
@@ -324,9 +326,13 @@ export function processLineConversation(line, wantsMetadata, onTerminal) {
|
|
|
324
326
|
silenceDurationMs: response.endOfTurn.silenceDurationMs
|
|
325
327
|
};
|
|
326
328
|
}
|
|
329
|
+
const { timestamp, chunkIndex, confidence } = response.endOfTurn;
|
|
327
330
|
return {
|
|
328
331
|
type: 'endOfTurn',
|
|
329
|
-
source: 'parakeet'
|
|
332
|
+
source: 'parakeet',
|
|
333
|
+
...(timestamp !== undefined && { timestamp }),
|
|
334
|
+
...(chunkIndex !== undefined && { chunkIndex }),
|
|
335
|
+
...(confidence !== undefined && { confidence })
|
|
330
336
|
};
|
|
331
337
|
}
|
|
332
338
|
if (wantsMetadata) {
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import { type UnloadModelParams } from '@qvac/inference/surface';
|
|
1
|
+
import { type UnloadModelParams, type RPCOptions } from '@qvac/inference/surface';
|
|
2
|
+
import { send, close } from '../../client/rpc/rpc-client.js';
|
|
3
|
+
export interface UnloadModelResult {
|
|
4
|
+
/** The caller's lease on the model was released. */
|
|
5
|
+
released: boolean;
|
|
6
|
+
/** The model left memory. False while another session still holds it. */
|
|
7
|
+
unloaded: boolean;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
|
-
*
|
|
10
|
+
* Releases the caller's hold on a loaded model. The model leaves memory once
|
|
11
|
+
* no caller session holds it; a session that shares the model with another
|
|
12
|
+
* only drops its own lease.
|
|
4
13
|
*
|
|
5
|
-
* When the last model
|
|
6
|
-
* automatically closes the RPC connection on Node/Electron, allowing
|
|
7
|
-
* process to exit naturally without requiring manual cleanup. On Bare the
|
|
14
|
+
* When the owner unloads the last model and no caller session is open, this
|
|
15
|
+
* function automatically closes the RPC connection on Node/Electron, allowing
|
|
16
|
+
* the process to exit naturally without requiring manual cleanup. On Bare the
|
|
8
17
|
* connection is left open by default so long-lived workers survive a routine
|
|
9
|
-
* unload; pass `autoClose: true` to opt in to closing.
|
|
18
|
+
* unload; pass `autoClose: true` to opt in to closing. A session never closes
|
|
19
|
+
* the runtime.
|
|
10
20
|
*
|
|
11
21
|
* @param params - The parameters for unloading the model
|
|
12
22
|
* @param params.modelId - The unique identifier of the model to unload
|
|
13
23
|
* @param params.clearStorage - Whether to clear the storage for the model
|
|
14
24
|
* @param params.autoClose - Override the runtime-default auto-close behavior
|
|
25
|
+
* @param options - Optional RPC options (timeout, profiling, force new connection).
|
|
15
26
|
* @throws {QvacErrorBase} When the response type is invalid or when the unload operation fails
|
|
16
27
|
*/
|
|
17
|
-
export declare function unloadModel(params: UnloadModelParams): Promise<
|
|
28
|
+
export declare function unloadModel(params: UnloadModelParams, options?: RPCOptions): Promise<UnloadModelResult>;
|
|
29
|
+
export declare function createUnloadModelCall(params: UnloadModelParams, options?: RPCOptions, sendRequest?: typeof send, closeRuntime?: typeof close): Promise<UnloadModelResult>;
|
|
18
30
|
//# sourceMappingURL=unload-model.d.ts.map
|
|
@@ -2,41 +2,59 @@ import { isBare } from 'which-runtime';
|
|
|
2
2
|
import {} from '@qvac/inference/surface';
|
|
3
3
|
import { send, close } from '../../client/rpc/rpc-client.js';
|
|
4
4
|
import { stopLoggingStreamForModel } from '../../client/logging-stream-registry.js';
|
|
5
|
+
import { hasClientSessions, releaseHeldModel } from '../../client/session-registry.js';
|
|
5
6
|
import { InvalidResponseError, ModelUnloadFailedError } from '../../utils/errors-client.js';
|
|
6
7
|
import { getClientLogger } from '../../logging/index.js';
|
|
7
8
|
const logger = getClientLogger();
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Releases the caller's hold on a loaded model. The model leaves memory once
|
|
11
|
+
* no caller session holds it; a session that shares the model with another
|
|
12
|
+
* only drops its own lease.
|
|
10
13
|
*
|
|
11
|
-
* When the last model
|
|
12
|
-
* automatically closes the RPC connection on Node/Electron, allowing
|
|
13
|
-
* process to exit naturally without requiring manual cleanup. On Bare the
|
|
14
|
+
* When the owner unloads the last model and no caller session is open, this
|
|
15
|
+
* function automatically closes the RPC connection on Node/Electron, allowing
|
|
16
|
+
* the process to exit naturally without requiring manual cleanup. On Bare the
|
|
14
17
|
* connection is left open by default so long-lived workers survive a routine
|
|
15
|
-
* unload; pass `autoClose: true` to opt in to closing.
|
|
18
|
+
* unload; pass `autoClose: true` to opt in to closing. A session never closes
|
|
19
|
+
* the runtime.
|
|
16
20
|
*
|
|
17
21
|
* @param params - The parameters for unloading the model
|
|
18
22
|
* @param params.modelId - The unique identifier of the model to unload
|
|
19
23
|
* @param params.clearStorage - Whether to clear the storage for the model
|
|
20
24
|
* @param params.autoClose - Override the runtime-default auto-close behavior
|
|
25
|
+
* @param options - Optional RPC options (timeout, profiling, force new connection).
|
|
21
26
|
* @throws {QvacErrorBase} When the response type is invalid or when the unload operation fails
|
|
22
27
|
*/
|
|
23
|
-
export async function unloadModel(params) {
|
|
28
|
+
export async function unloadModel(params, options) {
|
|
29
|
+
return createUnloadModelCall(params, options);
|
|
30
|
+
}
|
|
31
|
+
export async function createUnloadModelCall(params, options, sendRequest = send, closeRuntime = close) {
|
|
24
32
|
const request = {
|
|
25
33
|
type: 'unloadModel',
|
|
26
34
|
modelId: params.modelId,
|
|
27
35
|
clearStorage: params.clearStorage ?? false
|
|
28
36
|
};
|
|
29
|
-
const response = await
|
|
37
|
+
const response = await sendRequest(request, options);
|
|
30
38
|
if (response.type !== 'unloadModel') {
|
|
31
39
|
throw new InvalidResponseError('unloadModel');
|
|
32
40
|
}
|
|
33
41
|
if (!response.success) {
|
|
34
42
|
throw new ModelUnloadFailedError(params.modelId);
|
|
35
43
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if (response.released !== false) {
|
|
45
|
+
stopLoggingStreamForModel(params.modelId, options);
|
|
46
|
+
releaseHeldModel(options, params.modelId);
|
|
47
|
+
}
|
|
48
|
+
const isOwnerCall = options?.sessionId === undefined;
|
|
49
|
+
const shouldAutoClose = isOwnerCall && (params.autoClose ?? !isBare);
|
|
50
|
+
// The worker's count misses a session this client began opening while the
|
|
51
|
+
// unload was in flight; the client registry records it at `openSession()`.
|
|
52
|
+
if (shouldAutoClose &&
|
|
53
|
+
response.hasActiveModels === false &&
|
|
54
|
+
response.hasOpenSessions !== true &&
|
|
55
|
+
!hasClientSessions()) {
|
|
39
56
|
logger.info('🧹 No models active, automatically closing RPC connection...');
|
|
40
|
-
await
|
|
57
|
+
await closeRuntime();
|
|
41
58
|
}
|
|
59
|
+
return { released: response.released ?? true, unloaded: response.unloaded ?? true };
|
|
42
60
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { type UpscaleClientParams, type UpscaleStats } from '@qvac/inference/surface';
|
|
1
|
+
import { type UpscaleClientParams, type UpscaleStats, type RPCOptions } from '@qvac/inference/surface';
|
|
2
2
|
interface UpscaleResult {
|
|
3
|
+
/** Stable id of this run; pass to `cancel({ requestId })` to stop delivery. */
|
|
4
|
+
requestId: string;
|
|
3
5
|
outputs: Promise<Uint8Array[]>;
|
|
4
6
|
stats: Promise<UpscaleStats | undefined>;
|
|
5
7
|
}
|
|
@@ -18,7 +20,8 @@ interface UpscaleResult {
|
|
|
18
20
|
*
|
|
19
21
|
* @param params - `{ modelId, image, repeats? }`. `image` is raw PNG/JPEG
|
|
20
22
|
* bytes; the client base64-encodes them on the wire.
|
|
21
|
-
* @
|
|
23
|
+
* @param options - Optional RPC options (timeout, profiling, force new connection).
|
|
24
|
+
* @returns `{ requestId, outputs, stats }` — `outputs` resolves to a single-element
|
|
22
25
|
* array containing the final upscaled PNG; `stats` resolves to
|
|
23
26
|
* addon-side stats (load/upscale ms, final width/height, repeats
|
|
24
27
|
* actually executed, etc.).
|
|
@@ -40,6 +43,6 @@ interface UpscaleResult {
|
|
|
40
43
|
* console.log(await stats);
|
|
41
44
|
* ```
|
|
42
45
|
*/
|
|
43
|
-
export declare function upscale(params: UpscaleClientParams): UpscaleResult;
|
|
46
|
+
export declare function upscale(params: UpscaleClientParams, options?: RPCOptions): UpscaleResult;
|
|
44
47
|
export {};
|
|
45
48
|
//# sourceMappingURL=upscale.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { upscaleStreamResponseSchema } from '@qvac/inference/surface';
|
|
2
2
|
import { stream as streamRpc } from '../../client/rpc/rpc-client.js';
|
|
3
|
+
import { generateClientRequestId } from '../../client/api/client-request-id.js';
|
|
3
4
|
import { decodeBase64, encodeBase64 } from '../../utils/encoding.js';
|
|
4
5
|
import { StreamEndedError } from '../../utils/errors-client.js';
|
|
5
6
|
/**
|
|
@@ -17,7 +18,8 @@ import { StreamEndedError } from '../../utils/errors-client.js';
|
|
|
17
18
|
*
|
|
18
19
|
* @param params - `{ modelId, image, repeats? }`. `image` is raw PNG/JPEG
|
|
19
20
|
* bytes; the client base64-encodes them on the wire.
|
|
20
|
-
* @
|
|
21
|
+
* @param options - Optional RPC options (timeout, profiling, force new connection).
|
|
22
|
+
* @returns `{ requestId, outputs, stats }` — `outputs` resolves to a single-element
|
|
21
23
|
* array containing the final upscaled PNG; `stats` resolves to
|
|
22
24
|
* addon-side stats (load/upscale ms, final width/height, repeats
|
|
23
25
|
* actually executed, etc.).
|
|
@@ -39,12 +41,14 @@ import { StreamEndedError } from '../../utils/errors-client.js';
|
|
|
39
41
|
* console.log(await stats);
|
|
40
42
|
* ```
|
|
41
43
|
*/
|
|
42
|
-
export function upscale(params) {
|
|
44
|
+
export function upscale(params, options) {
|
|
45
|
+
const requestId = generateClientRequestId();
|
|
43
46
|
const request = {
|
|
44
47
|
modelId: params.modelId,
|
|
45
48
|
image: encodeBase64(params.image),
|
|
46
49
|
...(params.repeats !== undefined && { repeats: params.repeats }),
|
|
47
|
-
type: 'upscaleStream'
|
|
50
|
+
type: 'upscaleStream',
|
|
51
|
+
requestId
|
|
48
52
|
};
|
|
49
53
|
let statsResolver = () => { };
|
|
50
54
|
let statsRejecter = () => { };
|
|
@@ -64,7 +68,7 @@ export function upscale(params) {
|
|
|
64
68
|
async function processResponses() {
|
|
65
69
|
let sawDone = false;
|
|
66
70
|
try {
|
|
67
|
-
for await (const response of streamRpc(request)) {
|
|
71
|
+
for await (const response of streamRpc(request, options)) {
|
|
68
72
|
if (response &&
|
|
69
73
|
typeof response === 'object' &&
|
|
70
74
|
'type' in response &&
|
|
@@ -93,6 +97,7 @@ export function upscale(params) {
|
|
|
93
97
|
}
|
|
94
98
|
void processResponses();
|
|
95
99
|
return {
|
|
100
|
+
requestId,
|
|
96
101
|
outputs: outputsPromise,
|
|
97
102
|
stats: statsPromise
|
|
98
103
|
};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { send } from '../../client/rpc/rpc-client.js';
|
|
2
|
-
import { type CreateVectorIndexParams, type LoadVectorIndexParams, type RPCOptions, type VectorIndexAddParams, type VectorIndexHit, type VectorIndexIdsParams, type VectorIndexStorage, type VectorIndexWriteParams } from '@qvac/inference/surface';
|
|
2
|
+
import { type CreateVectorIndexParams, type LoadVectorIndexParams, type RPCOptions, type VectorIndexAddParams, type VectorIndexHit, type VectorIndexIdsParams, type VectorIndexSetStagedSearchParams, type VectorIndexStorage, type VectorIndexWriteParams } from '@qvac/inference/surface';
|
|
3
|
+
/**
|
|
4
|
+
* A pending index operation. `requestId` is readable before the promise
|
|
5
|
+
* settles, so the operation can be targeted with `cancel({ requestId })`.
|
|
6
|
+
*/
|
|
7
|
+
export type VectorIndexOperation<T> = Promise<T> & {
|
|
8
|
+
requestId: string;
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
11
|
* A handle to a vector index that lives in worker memory.
|
|
5
12
|
*
|
|
@@ -13,6 +20,10 @@ import { type CreateVectorIndexParams, type LoadVectorIndexParams, type RPCOptio
|
|
|
13
20
|
* shutdown. After a worker crash or restart every method rejects with
|
|
14
21
|
* `VECTOR_INDEX_NOT_FOUND`; recover by creating a new index or loading a
|
|
15
22
|
* snapshot written earlier with `write()`.
|
|
23
|
+
*
|
|
24
|
+
* A handle opened through a session keeps that session: every call it makes
|
|
25
|
+
* runs as the session, is swept by the session's close, and is refused once
|
|
26
|
+
* the session ended.
|
|
16
27
|
*/
|
|
17
28
|
export interface VectorIndex {
|
|
18
29
|
/** Opaque id of the worker-side index; useful in logs, not needed for any call. */
|
|
@@ -27,12 +38,34 @@ export interface VectorIndex {
|
|
|
27
38
|
readonly storage: VectorIndexStorage | undefined;
|
|
28
39
|
/** Number of live entries as of the last call that changed or reported it. */
|
|
29
40
|
readonly length: number;
|
|
41
|
+
/**
|
|
42
|
+
* TQ+ calibration state as of create, load, or the last successful add.
|
|
43
|
+
* Undefined when an external provider does not report calibration.
|
|
44
|
+
*/
|
|
45
|
+
readonly calibrated: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Staged search setting as of the last successful call that reported it.
|
|
48
|
+
* Undefined when an external provider does not report the setting.
|
|
49
|
+
*/
|
|
50
|
+
readonly stagedSearch: boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Turns TurboVec staged search on or off. Off on every new or loaded index.
|
|
53
|
+
* On supported hosts, dimensions divisible by 32 and at least 32,768 entries
|
|
54
|
+
* use a shortlist for faster searches with lower recall. Other dimensions
|
|
55
|
+
* and v3 snapshots retain the setting but scan in full. The setting is not
|
|
56
|
+
* saved in snapshots. Rejects non-TurboVec storage or unsupported providers.
|
|
57
|
+
*/
|
|
58
|
+
setStagedSearch(params: VectorIndexSetStagedSearchParams, options?: RPCOptions): VectorIndexOperation<{
|
|
59
|
+
stagedSearch: boolean;
|
|
60
|
+
}>;
|
|
30
61
|
/**
|
|
31
62
|
* Adds vectors under the given ids in one atomic batch. Rejects duplicate
|
|
32
63
|
* ids, ids equal to 2^64 - 1, and rows whose length differs from `dim`.
|
|
64
|
+
* A fresh TurboVec index attempts calibration from a first batch of at
|
|
65
|
+
* least 1,000 vectors. A smaller first batch leaves it uncalibrated.
|
|
33
66
|
* @returns The number of live entries after the add.
|
|
34
67
|
*/
|
|
35
|
-
add(params: VectorIndexAddParams, options?: RPCOptions):
|
|
68
|
+
add(params: VectorIndexAddParams, options?: RPCOptions): VectorIndexOperation<{
|
|
36
69
|
length: number;
|
|
37
70
|
}>;
|
|
38
71
|
/**
|
|
@@ -44,7 +77,7 @@ export interface VectorIndex {
|
|
|
44
77
|
search(params: {
|
|
45
78
|
query: number[];
|
|
46
79
|
k: number;
|
|
47
|
-
}, options?: RPCOptions):
|
|
80
|
+
}, options?: RPCOptions): VectorIndexOperation<VectorIndexHit[]>;
|
|
48
81
|
/**
|
|
49
82
|
* Finds the `k` nearest entries to each query row; one hit list per row.
|
|
50
83
|
* @overloadLabel "Multiple queries"
|
|
@@ -52,35 +85,36 @@ export interface VectorIndex {
|
|
|
52
85
|
search(params: {
|
|
53
86
|
queries: number[][];
|
|
54
87
|
k: number;
|
|
55
|
-
}, options?: RPCOptions):
|
|
88
|
+
}, options?: RPCOptions): VectorIndexOperation<VectorIndexHit[][]>;
|
|
56
89
|
/**
|
|
57
90
|
* Removes ids; each boolean tells whether that id was present. Ids are
|
|
58
91
|
* applied in order, so a rejection leaves the ids before the failure
|
|
59
92
|
* removed and `length` reporting the last successful call.
|
|
60
93
|
*/
|
|
61
|
-
remove(params: VectorIndexIdsParams, options?: RPCOptions):
|
|
94
|
+
remove(params: VectorIndexIdsParams, options?: RPCOptions): VectorIndexOperation<boolean[]>;
|
|
62
95
|
/** Reports, per id, whether the index holds it. */
|
|
63
|
-
contains(params: VectorIndexIdsParams, options?: RPCOptions):
|
|
96
|
+
contains(params: VectorIndexIdsParams, options?: RPCOptions): VectorIndexOperation<boolean[]>;
|
|
64
97
|
/**
|
|
65
98
|
* Writes a checksummed snapshot to `path`, replacing any existing file.
|
|
66
99
|
* An absolute path is used as given; a relative path resolves under the
|
|
67
100
|
* QVAC data directory. Load it later with `loadVectorIndex`.
|
|
68
101
|
* @returns The resolved absolute path.
|
|
69
102
|
*/
|
|
70
|
-
write(params: VectorIndexWriteParams, options?: RPCOptions):
|
|
103
|
+
write(params: VectorIndexWriteParams, options?: RPCOptions): VectorIndexOperation<{
|
|
71
104
|
path: string;
|
|
72
105
|
}>;
|
|
73
106
|
/** Releases worker memory. Safe to call more than once. */
|
|
74
|
-
dispose(options?: RPCOptions):
|
|
107
|
+
dispose(options?: RPCOptions): VectorIndexOperation<void>;
|
|
75
108
|
[Symbol.asyncDispose](): Promise<void>;
|
|
76
109
|
}
|
|
77
110
|
/**
|
|
78
111
|
* Builds the two public functions over a transport. The default export pair
|
|
79
|
-
* below binds them to the RPC client;
|
|
112
|
+
* below binds them to the RPC client; a session binds them to its own
|
|
113
|
+
* stamped transport, and tests bind a fake.
|
|
80
114
|
*/
|
|
81
115
|
export declare function createVectorIndexClient(transport: typeof send): {
|
|
82
|
-
createVectorIndex(params: CreateVectorIndexParams, options?: RPCOptions):
|
|
83
|
-
loadVectorIndex(params: LoadVectorIndexParams, options?: RPCOptions):
|
|
116
|
+
createVectorIndex(params: CreateVectorIndexParams, options?: RPCOptions): VectorIndexOperation<VectorIndex>;
|
|
117
|
+
loadVectorIndex(params: LoadVectorIndexParams, options?: RPCOptions): VectorIndexOperation<VectorIndex>;
|
|
84
118
|
};
|
|
85
119
|
/**
|
|
86
120
|
* Creates an empty vector index in worker memory and returns a handle to it.
|
|
@@ -93,10 +127,10 @@ export declare function createVectorIndexClient(transport: typeof send): {
|
|
|
93
127
|
* documents.
|
|
94
128
|
*
|
|
95
129
|
* @param params - Index parameters
|
|
96
|
-
* @param params.dim - Vector dimensionality, for example 1024 for GTE Large. TurboVec storage needs a multiple of 8 no greater than
|
|
130
|
+
* @param params.dim - Vector dimensionality, for example 1024 for GTE Large. TurboVec storage needs a multiple of 8 no greater than 16384.
|
|
97
131
|
* @param params.storage - Storage mode from `VectorIndexStorage`; defaults to `TURBOVEC_Q4`. `TURBOVEC_Q2` halves memory again at lower recall; `F32`, `Q8`, and `Q4` are exact or generically quantised stores for dimensions TurboVec cannot hold.
|
|
98
132
|
* @param options - Optional RPC options (timeout, profiling, force new connection, etc.).
|
|
99
|
-
* @returns A handle whose methods add, search, remove, snapshot, and dispose the index.
|
|
133
|
+
* @returns A handle whose methods add, search, remove, snapshot, and dispose the index. The pending promise carries `requestId` for `cancel({ requestId })`.
|
|
100
134
|
* @throws {VectorIndexProviderUnavailableError} When no registered plugin exposes a vector index provider
|
|
101
135
|
* @throws {VectorIndexFailedError} When the native index rejects the dimension or storage mode
|
|
102
136
|
*
|
|
@@ -106,7 +140,7 @@ export declare function createVectorIndexClient(transport: typeof send): {
|
|
|
106
140
|
* ['1', 'Saturn moon Titan has lakes of liquid methane.'],
|
|
107
141
|
* ['2', 'Solar panels turn sunlight into electricity.']
|
|
108
142
|
* ])
|
|
109
|
-
* const { embedding } = await
|
|
143
|
+
* const { embedding } = await embedBatch({ modelId, inputs: [...documents.values()] })
|
|
110
144
|
*
|
|
111
145
|
* await using index = await createVectorIndex({ dim: embedding[0].length })
|
|
112
146
|
* await index.add({ ids: [...documents.keys()], vectors: embedding })
|
|
@@ -116,7 +150,7 @@ export declare function createVectorIndexClient(transport: typeof send): {
|
|
|
116
150
|
* console.log(documents.get(hits[0].id))
|
|
117
151
|
* ```
|
|
118
152
|
*/
|
|
119
|
-
export declare function createVectorIndex(params: CreateVectorIndexParams, options?: RPCOptions):
|
|
153
|
+
export declare function createVectorIndex(params: CreateVectorIndexParams, options?: RPCOptions): VectorIndexOperation<VectorIndex>;
|
|
120
154
|
/**
|
|
121
155
|
* Loads a vector index snapshot written by `VectorIndex.write()` into worker
|
|
122
156
|
* memory and returns a handle to it.
|
|
@@ -139,5 +173,5 @@ export declare function createVectorIndex(params: CreateVectorIndexParams, optio
|
|
|
139
173
|
* await index.dispose()
|
|
140
174
|
* ```
|
|
141
175
|
*/
|
|
142
|
-
export declare function loadVectorIndex(params: LoadVectorIndexParams, options?: RPCOptions):
|
|
176
|
+
export declare function loadVectorIndex(params: LoadVectorIndexParams, options?: RPCOptions): VectorIndexOperation<VectorIndex>;
|
|
143
177
|
//# sourceMappingURL=vector-index.d.ts.map
|