@qvac/sdk 0.22.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 +194 -97
- package/README.md +29 -470
- package/dist/examples/asr/parakeet-sortformer.js +24 -14
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.d.ts +2 -0
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +105 -0
- 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-img2vid-ltx.js +7 -14
- 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.d.ts +2 -0
- package/dist/examples/diffusion-qwen-image-21.js +115 -0
- package/dist/examples/diffusion-txt2vid-ltx.js +7 -14
- 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/finetune/llamacpp-finetune.js +9 -4
- package/dist/examples/image/megaloc.d.ts +2 -0
- package/dist/examples/image/megaloc.js +37 -0
- package/dist/examples/llamacpp-multimodal.js +21 -1
- package/dist/examples/mcp-websearch.js +1 -1
- package/dist/examples/plugins.js +1 -1
- package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
- package/dist/examples/rag/rag-turbovec.js +2 -2
- package/dist/examples/rerank.d.ts +2 -0
- package/dist/examples/rerank.js +33 -0
- package/dist/examples/sessions.d.ts +17 -0
- package/dist/examples/sessions.js +63 -0
- package/dist/examples/tools/llamacpp-deferred-tools.js +12 -8
- package/dist/examples/tools/llamacpp-tools-auto-dialect.js +4 -3
- package/dist/examples/tools/llamacpp-tools-gemma4.js +3 -3
- package/dist/examples/tools/llamacpp-tools-qwen35.js +4 -3
- 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 +19 -0
- package/dist/scripts/contract/constants-registry.js +9 -2
- package/dist/scripts/contract/method-shapes.d.ts +5 -0
- package/dist/scripts/contract/method-shapes.js +5 -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 +19 -32
- package/dist/src/client/api/audio-edit.d.ts +5 -3
- package/dist/src/client/api/audio-edit.js +7 -5
- package/dist/src/client/api/audio-gen-result.js +136 -47
- package/dist/src/client/api/audio-gen.d.ts +40 -3
- package/dist/src/client/api/audio-gen.js +42 -5
- package/dist/src/client/api/audio-understand.d.ts +2 -2
- package/dist/src/client/api/audio-understand.js +4 -4
- package/dist/src/client/api/batch-completion.js +4 -3
- package/dist/src/client/api/bci-transcribe.js +3 -3
- 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 +3 -3
- package/dist/src/client/api/classify.d.ts +12 -5
- package/dist/src/client/api/classify.js +18 -6
- 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 +9 -1
- package/dist/src/client/api/completion-stream.js +14 -3
- package/dist/src/client/api/decide.d.ts +1 -1
- package/dist/src/client/api/decide.js +3 -3
- package/dist/src/client/api/delete-cache.d.ts +9 -2
- package/dist/src/client/api/delete-cache.js +14 -4
- package/dist/src/client/api/diffusion.d.ts +38 -5
- package/dist/src/client/api/diffusion.js +42 -7
- package/dist/src/client/api/download-asset.js +3 -3
- package/dist/src/client/api/embed.d.ts +82 -29
- package/dist/src/client/api/embed.js +66 -21
- package/dist/src/client/api/finetune.js +3 -3
- package/dist/src/client/api/get-loaded-model-info.js +1 -1
- package/dist/src/client/api/get-model-info.d.ts +2 -2
- package/dist/src/client/api/get-model-info.js +3 -3
- package/dist/src/client/api/get-system-resources.d.ts +2 -2
- package/dist/src/client/api/get-system-resources.js +3 -3
- package/dist/src/client/api/heartbeat.d.ts +3 -2
- package/dist/src/client/api/heartbeat.js +4 -3
- package/dist/src/client/api/index.d.ts +8 -6
- package/dist/src/client/api/index.js +6 -4
- package/dist/src/client/api/invoke-plugin.d.ts +8 -2
- package/dist/src/client/api/invoke-plugin.js +18 -3
- package/dist/src/client/api/load-model.js +9 -6
- package/dist/src/client/api/logging-stream.d.ts +11 -2
- package/dist/src/client/api/logging-stream.js +12 -3
- package/dist/src/client/api/ocr.d.ts +5 -3
- package/dist/src/client/api/ocr.js +45 -22
- package/dist/src/client/api/rag.d.ts +1 -1
- package/dist/src/client/api/rag.js +3 -3
- package/dist/src/client/api/registry.d.ts +19 -8
- package/dist/src/client/api/registry.js +43 -17
- package/dist/src/client/api/rerank.d.ts +22 -0
- package/dist/src/client/api/rerank.js +39 -0
- package/dist/src/client/api/resume.d.ts +2 -1
- package/dist/src/client/api/resume.js +3 -3
- package/dist/src/client/api/rpc-server.d.ts +4 -4
- package/dist/src/client/api/rpc-server.js +12 -12
- package/dist/src/client/api/state.d.ts +2 -2
- package/dist/src/client/api/state.js +3 -3
- package/dist/src/client/api/subscribe-logs.d.ts +2 -2
- package/dist/src/client/api/subscribe-logs.js +4 -3
- package/dist/src/client/api/suspend.d.ts +4 -2
- package/dist/src/client/api/suspend.js +5 -4
- package/dist/src/client/api/text-to-speech.d.ts +14 -5
- package/dist/src/client/api/text-to-speech.js +86 -32
- package/dist/src/client/api/transcribe.d.ts +7 -3
- package/dist/src/client/api/transcribe.js +9 -3
- package/dist/src/client/api/translate.js +2 -2
- package/dist/src/client/api/unload-model.d.ts +19 -7
- package/dist/src/client/api/unload-model.js +31 -13
- package/dist/src/client/api/upscale.d.ts +6 -3
- package/dist/src/client/api/upscale.js +10 -5
- package/dist/src/client/api/vector-index.d.ts +51 -17
- package/dist/src/client/api/vector-index.js +101 -49
- 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 +6 -5
- 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-result.js +2 -2
- package/dist/src/client/api/world.d.ts +6 -6
- package/dist/src/client/api/world.js +6 -6
- 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 +36 -14
- package/dist/src/client/plugins-factory.d.ts +1 -1
- package/dist/src/client/plugins-factory.js +1 -1
- 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 +192 -138
- package/dist/src/client/rpc/node-rpc-client.js +324 -426
- 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 +6 -4
- package/dist/src/client/rpc/rpc-client.js +168 -31
- package/dist/src/client/rpc/rpc-error.js +24 -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 +2 -0
- package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
- package/dist/src/commands/bundle/entry-gen.js +18 -51
- package/dist/src/commands/bundle/index.d.ts +60 -14
- package/dist/src/commands/bundle/index.js +350 -126
- 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/plugins.js +1 -1
- 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 +8 -7
- package/dist/src/commands/host-prebuilds/index.js +13 -11
- package/dist/src/commands/index.d.ts +13 -12
- package/dist/src/commands/index.js +7 -7
- package/dist/src/commands/verify/abi.d.ts +21 -15
- package/dist/src/commands/verify/abi.js +12 -80
- 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.d.ts +1 -1
- package/dist/src/commands/verify/bundle-source.js +27 -23
- package/dist/src/commands/verify/engines-advice.d.ts +6 -12
- package/dist/src/commands/verify/engines-advice.js +9 -56
- package/dist/src/commands/verify/index.d.ts +34 -33
- package/dist/src/commands/verify/index.js +96 -204
- package/dist/src/commands/verify/node-modules-source.d.ts +1 -1
- package/dist/src/commands/verify/node-modules-source.js +1 -1
- package/dist/src/commands/verify/prebuilds.d.ts +4 -6
- package/dist/src/commands/verify/prebuilds.js +3 -4
- package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
- package/dist/src/commands/verify/resource-collectors.js +3 -52
- 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/get-project-root.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidArchitecture.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidNdkVersion.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidNdkVersion.js +16 -10
- package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
- package/dist/src/expo/plugins/withBareKit.js +204 -0
- package/dist/src/expo/plugins/withDeviceInfo.d.ts +1 -1
- package/dist/src/expo/plugins/withDeviceInfo.js +19 -5
- package/dist/src/expo/plugins/withMobileBundle.d.ts +5 -12
- package/dist/src/expo/plugins/withMobileBundle.js +38 -59
- package/dist/src/expo/plugins/withOpenCL.d.ts +1 -1
- package/dist/src/expo/plugins/withQvacSDK.d.ts +2 -1
- 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/addon.d.ts +1 -1
- package/dist/src/logging/base-logger.js +1 -1
- package/dist/src/logging/utils.js +11 -3
- package/dist/src/plugin-ids.d.ts +3 -1
- package/dist/src/plugin-ids.js +4 -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 +12 -1
- package/dist/src/schemas/sdk-errors-server.js +65 -2
- package/dist/src/server/rpc/rpc-utils.d.ts +26 -0
- package/dist/src/server/rpc/rpc-utils.js +41 -0
- package/dist/src/utils/aggregate-events.d.ts +1 -1
- package/dist/src/utils/aggregate-events.js +2 -2
- 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 +65 -1
- package/dist/src/utils/errors-server.js +122 -1
- package/dist/src/utils/mcp-adapter.d.ts +1 -1
- package/dist/src/utils/mcp-adapter.js +1 -1
- package/dist/src/utils/tool-helpers.js +1 -1
- package/dist/src/utils/withTimeout.js +34 -17
- package/dist/src/worker/handle-request.js +26 -21
- 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 +24 -34
- 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/plugins/llamacpp-rerank.d.ts +2 -0
- package/dist/src/worker/plugins/llamacpp-rerank.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 +91 -74
- 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/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 -448
- 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
|
@@ -2,31 +2,40 @@ import { promises as fsp } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import semver from 'semver';
|
|
5
|
-
import {
|
|
6
|
-
import { BARE_KIT_BARE_VERSIONS,
|
|
5
|
+
import { fetchBareVersionFromGitHub, fetchBindingBareKitFromGitHub, fetchText, NETWORK_TIMEOUT_MS } from '../src/commands/verify/bare-kit-runtime.js';
|
|
6
|
+
import { BARE_KIT_BARE_VERSIONS, BARE_KIT_KOTLIN_BARE_KITS, BARE_KIT_KOTLIN_WITHOUT_BARE_KIT, BARE_KIT_SWIFT_BARE_KITS, BARE_KIT_SWIFT_WITHOUT_BARE_KIT, BARE_KIT_WITHOUT_BARE } from '../src/commands/verify/bare-kit-runtimes.js';
|
|
7
7
|
const CONCURRENCY = 8;
|
|
8
|
+
const TAGS_PER_PAGE = 100;
|
|
9
|
+
/** prettier-config-holepunch's printWidth, which decides when a list fits on one line. */
|
|
10
|
+
const PRINT_WIDTH = 100;
|
|
8
11
|
const OUTPUT_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'src', 'commands', 'verify', 'bare-kit-runtimes.ts');
|
|
9
|
-
async function
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function latest(versions) {
|
|
18
|
-
const valid = versions.filter((version) => semver.valid(version) !== null);
|
|
19
|
-
return valid.length === 0 ? null : valid.sort(semver.rcompare)[0];
|
|
12
|
+
async function listTags(repo) {
|
|
13
|
+
const names = [];
|
|
14
|
+
for (let page = 1;; page++) {
|
|
15
|
+
const tags = JSON.parse(await fetchText(`https://api.github.com/repos/holepunchto/${repo}/tags?per_page=${TAGS_PER_PAGE}&page=${page}`));
|
|
16
|
+
names.push(...tags.map((tag) => tag.name.replace(/^v/, '')));
|
|
17
|
+
if (tags.length < TAGS_PER_PAGE)
|
|
18
|
+
return names;
|
|
19
|
+
}
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* A release without the file reads as empty, so it parses as naming no
|
|
23
|
+
* version. Any other failure throws, so it is never recorded as a release
|
|
24
|
+
* without a version.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
26
|
+
async function fetchReleaseFile(url) {
|
|
27
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(NETWORK_TIMEOUT_MS) });
|
|
28
|
+
if (response.status === 404)
|
|
29
|
+
return '';
|
|
30
|
+
if (!response.ok)
|
|
31
|
+
throw new Error(`GET ${url} returned HTTP ${response.status}`);
|
|
32
|
+
return response.text();
|
|
33
|
+
}
|
|
34
|
+
/** Releases not yet in the table or the list of releases without a version, oldest first. */
|
|
35
|
+
function unchecked(versions, table, without) {
|
|
27
36
|
return versions
|
|
28
37
|
.filter((version) => semver.valid(version) !== null)
|
|
29
|
-
.filter((version) =>
|
|
38
|
+
.filter((version) => table[version] === undefined && !without.has(version))
|
|
30
39
|
.sort(semver.compare);
|
|
31
40
|
}
|
|
32
41
|
async function mapConcurrent(items, fn) {
|
|
@@ -41,66 +50,89 @@ async function mapConcurrent(items, fn) {
|
|
|
41
50
|
await Promise.all(Array.from({ length: CONCURRENCY }, worker));
|
|
42
51
|
return results;
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
53
|
+
/**
|
|
54
|
+
* Adds each release of `repo` not checked before to `table` with the version
|
|
55
|
+
* `lookUp` finds, or to `without` when its CMakeLists.txt names none.
|
|
56
|
+
*/
|
|
57
|
+
async function extend(table, without, repo, lookUp) {
|
|
58
|
+
const versions = unchecked(await listTags(repo), table, without);
|
|
59
|
+
console.log(`Resolving ${versions.length} new ${repo} releases...`);
|
|
60
|
+
const found = await mapConcurrent(versions, lookUp);
|
|
61
|
+
versions.forEach((version, index) => {
|
|
62
|
+
const value = found[index];
|
|
63
|
+
if (value)
|
|
64
|
+
table[version] = value;
|
|
65
|
+
else
|
|
66
|
+
without.add(version);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function bindingLookUp(binding) {
|
|
70
|
+
return (version) => fetchBindingBareKitFromGitHub(binding, version, fetchReleaseFile);
|
|
51
71
|
}
|
|
52
72
|
function sortedEntries(record) {
|
|
53
73
|
return Object.entries(record).sort(([a], [b]) => semver.compare(a, b));
|
|
54
74
|
}
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
/** Object entries in the repo's Prettier style: no trailing comma. */
|
|
76
|
+
function entryLines(record) {
|
|
77
|
+
const entries = sortedEntries(record).map(([key, value]) => `'${key}': '${value}'`);
|
|
78
|
+
return entries.map((entry, index) => ` ${entry}${index === entries.length - 1 ? '' : ','}`);
|
|
79
|
+
}
|
|
80
|
+
function table(doc, name, record) {
|
|
81
|
+
return [
|
|
82
|
+
`/** ${doc} */`,
|
|
83
|
+
`export const ${name}: Record<string, string> = {`,
|
|
84
|
+
...entryLines(record),
|
|
85
|
+
'}'
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/** A string array in the repo's Prettier style: on one line when it fits. */
|
|
89
|
+
function list(doc, name, versions) {
|
|
90
|
+
const items = [...versions].sort(semver.compare).map((version) => `'${version}'`);
|
|
91
|
+
const head = `export const ${name}: string[] = [`;
|
|
92
|
+
const oneLine = `${head}${items.join(', ')}]`;
|
|
93
|
+
if (oneLine.length <= PRINT_WIDTH)
|
|
94
|
+
return [`/** ${doc} */`, oneLine];
|
|
95
|
+
return [
|
|
96
|
+
`/** ${doc} */`,
|
|
97
|
+
head,
|
|
98
|
+
...items.map((item, index) => ` ${item}${index === items.length - 1 ? '' : ','}`),
|
|
99
|
+
']'
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
function render(tables) {
|
|
103
|
+
return [
|
|
57
104
|
'// Generated by scripts/generate-bare-kit-runtimes.ts. Do not edit by hand.',
|
|
58
105
|
'',
|
|
59
|
-
'
|
|
60
|
-
' bareKit: string',
|
|
61
|
-
' bare: string',
|
|
62
|
-
'}',
|
|
106
|
+
...table('bare-kit release each bare-kit-kotlin release is built from.', 'BARE_KIT_KOTLIN_BARE_KITS', tables.kotlin),
|
|
63
107
|
'',
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return lines.join('\n');
|
|
76
|
-
}
|
|
77
|
-
/** Object entries in the repo's Prettier style: no trailing comma. */
|
|
78
|
-
function entryLines(entries) {
|
|
79
|
-
return entries.map((entry, index) => ` ${entry}${index === entries.length - 1 ? '' : ','}`);
|
|
108
|
+
...list('bare-kit-kotlin releases whose CMakeLists.txt names no bare-kit version.', 'BARE_KIT_KOTLIN_WITHOUT_BARE_KIT', tables.kotlinWithout),
|
|
109
|
+
'',
|
|
110
|
+
...table('bare-kit release each bare-kit-swift release is built from.', 'BARE_KIT_SWIFT_BARE_KITS', tables.swift),
|
|
111
|
+
'',
|
|
112
|
+
...list('bare-kit-swift releases whose CMakeLists.txt names no bare-kit version.', 'BARE_KIT_SWIFT_WITHOUT_BARE_KIT', tables.swiftWithout),
|
|
113
|
+
'',
|
|
114
|
+
...table('Bare version each bare-kit release is built against.', 'BARE_KIT_BARE_VERSIONS', tables.bare),
|
|
115
|
+
'',
|
|
116
|
+
...list('bare-kit releases whose CMakeLists.txt names no Bare version.', 'BARE_KIT_WITHOUT_BARE', tables.bareWithout),
|
|
117
|
+
''
|
|
118
|
+
].join('\n');
|
|
80
119
|
}
|
|
81
120
|
async function main() {
|
|
82
121
|
const full = process.argv.includes('--full');
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const bare = bareKit ? bareByBareKit[bareKit] : undefined;
|
|
99
|
-
if (bareKit && bare)
|
|
100
|
-
runtimes[version] = { bareKit, bare };
|
|
101
|
-
});
|
|
102
|
-
await fsp.writeFile(OUTPUT_PATH, render(runtimes, bareByBareKit));
|
|
103
|
-
console.log(`Wrote ${Object.keys(runtimes).length} ${REACT_NATIVE_BARE_KIT} and ` +
|
|
104
|
-
`${Object.keys(bareByBareKit).length} bare-kit entries to ${OUTPUT_PATH}`);
|
|
122
|
+
const tables = {
|
|
123
|
+
kotlin: full ? {} : { ...BARE_KIT_KOTLIN_BARE_KITS },
|
|
124
|
+
kotlinWithout: new Set(full ? [] : BARE_KIT_KOTLIN_WITHOUT_BARE_KIT),
|
|
125
|
+
swift: full ? {} : { ...BARE_KIT_SWIFT_BARE_KITS },
|
|
126
|
+
swiftWithout: new Set(full ? [] : BARE_KIT_SWIFT_WITHOUT_BARE_KIT),
|
|
127
|
+
bare: full ? {} : { ...BARE_KIT_BARE_VERSIONS },
|
|
128
|
+
bareWithout: new Set(full ? [] : BARE_KIT_WITHOUT_BARE)
|
|
129
|
+
};
|
|
130
|
+
await extend(tables.bare, tables.bareWithout, 'bare-kit', (version) => fetchBareVersionFromGitHub(version, fetchReleaseFile));
|
|
131
|
+
await extend(tables.kotlin, tables.kotlinWithout, 'bare-kit-kotlin', bindingLookUp('bare-kit-kotlin'));
|
|
132
|
+
await extend(tables.swift, tables.swiftWithout, 'bare-kit-swift', bindingLookUp('bare-kit-swift'));
|
|
133
|
+
await fsp.writeFile(OUTPUT_PATH, render(tables));
|
|
134
|
+
console.log(`Wrote ${Object.keys(tables.kotlin).length} bare-kit-kotlin, ` +
|
|
135
|
+
`${Object.keys(tables.swift).length} bare-kit-swift and ` +
|
|
136
|
+
`${Object.keys(tables.bare).length} bare-kit entries to ${OUTPUT_PATH}`);
|
|
105
137
|
}
|
|
106
138
|
await main();
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { type AssessModelFitInput, type AssessModelFitResult } from '@qvac/inference/surface';
|
|
1
|
+
import { type AssessModelFitInput, type AssessModelFitResult, type RPCOptions } from '@qvac/inference/surface';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Whether a set of models fits in this device's memory when loaded together,
|
|
4
|
+
* without downloading them.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* should treat it as "cannot say", not "no".
|
|
6
|
+
* Each model's engine fitter runs against the registry's weightless description
|
|
7
|
+
* of the model, or the model itself when it is on disk. The memory each load
|
|
8
|
+
* takes is summed per device and compared against what is free.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* never confirm one.
|
|
10
|
+
* `unknown` is the answer for a load that would start but cannot be sized: an
|
|
11
|
+
* engine with no fitter, a load the fitter cannot project, a model with no
|
|
12
|
+
* registry description that is not on disk, or a device that reported no free
|
|
13
|
+
* memory.
|
|
16
14
|
*
|
|
17
|
-
* @param input -
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* @param input - The models, each as `loadModel` takes it.
|
|
16
|
+
* @returns The verdict for the set, the memory pools it was judged on, and
|
|
17
|
+
* each model's addon result: its status, device rows and stats.
|
|
18
|
+
* @throws The error `loadModel` would throw for a load it refuses: no plugin
|
|
19
|
+
* for the model type, a config the plugin refuses, or a model the fitter
|
|
20
|
+
* cannot read.
|
|
21
21
|
*/
|
|
22
|
-
export declare function assessModelFit(input: AssessModelFitInput): Promise<AssessModelFitResult>;
|
|
22
|
+
export declare function assessModelFit(input: AssessModelFitInput, options?: RPCOptions): Promise<AssessModelFitResult>;
|
|
23
23
|
//# sourceMappingURL=assess-model-fit.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assessModelFitInputSchema, inferModelTypeFromModelSrc } from '@qvac/inference/surface';
|
|
2
|
-
import { send } from '
|
|
2
|
+
import { send } from '../../client/rpc/rpc-client.js';
|
|
3
3
|
import { InvalidResponseError, ModelTypeRequiredError } from '../../utils/errors-client.js';
|
|
4
4
|
/**
|
|
5
5
|
* Names the engine a candidate omitted, from the source it carries.
|
|
@@ -15,47 +15,34 @@ function withModelType(candidate) {
|
|
|
15
15
|
return { ...candidate, modelType: inferred };
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* Whether a set of models fits in this device's memory when loaded together,
|
|
19
|
+
* without downloading them.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* should treat it as "cannot say", not "no".
|
|
21
|
+
* Each model's engine fitter runs against the registry's weightless description
|
|
22
|
+
* of the model, or the model itself when it is on disk. The memory each load
|
|
23
|
+
* takes is summed per device and compared against what is free.
|
|
25
24
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* never confirm one.
|
|
25
|
+
* `unknown` is the answer for a load that would start but cannot be sized: an
|
|
26
|
+
* engine with no fitter, a load the fitter cannot project, a model with no
|
|
27
|
+
* registry description that is not on disk, or a device that reported no free
|
|
28
|
+
* memory.
|
|
31
29
|
*
|
|
32
|
-
* @param input -
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
30
|
+
* @param input - The models, each as `loadModel` takes it.
|
|
31
|
+
* @returns The verdict for the set, the memory pools it was judged on, and
|
|
32
|
+
* each model's addon result: its status, device rows and stats.
|
|
33
|
+
* @throws The error `loadModel` would throw for a load it refuses: no plugin
|
|
34
|
+
* for the model type, a config the plugin refuses, or a model the fitter
|
|
35
|
+
* cannot read.
|
|
36
36
|
*/
|
|
37
|
-
export async function assessModelFit(input) {
|
|
37
|
+
export async function assessModelFit(input, options) {
|
|
38
38
|
const parsed = assessModelFitInputSchema.parse({
|
|
39
39
|
...input,
|
|
40
40
|
models: input.models.map(withModelType)
|
|
41
41
|
});
|
|
42
42
|
const request = { type: 'assessModelFit', ...parsed };
|
|
43
|
-
const response = await send(request);
|
|
43
|
+
const response = await send(request, options);
|
|
44
44
|
if (response.type !== 'assessModelFit') {
|
|
45
45
|
throw new InvalidResponseError('assessModelFit');
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
// matching the other client wrappers and keeping optionals absent rather than
|
|
49
|
-
// explicitly undefined.
|
|
50
|
-
return {
|
|
51
|
-
verdict: response.verdict,
|
|
52
|
-
basis: response.basis,
|
|
53
|
-
execution: response.execution,
|
|
54
|
-
...(response.evidence && { evidence: response.evidence }),
|
|
55
|
-
...(response.budget && { budget: response.budget }),
|
|
56
|
-
...(response.floorBytes !== undefined && { floorBytes: response.floorBytes }),
|
|
57
|
-
models: response.models,
|
|
58
|
-
reasons: response.reasons,
|
|
59
|
-
assumptions: response.assumptions
|
|
60
|
-
};
|
|
47
|
+
return { verdict: response.verdict, pools: response.pools, models: response.models };
|
|
61
48
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AudioEditClientParams, AudioGenResult } from '@qvac/inference/surface';
|
|
1
|
+
import type { AudioEditClientParams, AudioGenResult, RPCOptions } from '@qvac/inference/surface';
|
|
2
2
|
/**
|
|
3
3
|
* Edits a source recording with a loaded ACE-Step AudioGen model: an ordered
|
|
4
4
|
* pipeline of `flow-edit` and `repaint` operations, executed in array order.
|
|
@@ -20,7 +20,9 @@ import type { AudioEditClientParams, AudioGenResult } from '@qvac/inference/surf
|
|
|
20
20
|
* `repaint` regenerates the `start`..`end` range (seconds) against a new `caption`, keeping the
|
|
21
21
|
* rest of the clip. Operations may repeat or mix.
|
|
22
22
|
* @param params.seed - Seeds the first operation; each following operation uses `seed + index`.
|
|
23
|
-
* @
|
|
23
|
+
* @param params.outputFormat - Also deliver the edited audio as a file in this container, through
|
|
24
|
+
* `run.encoded`, as on a generation.
|
|
25
|
+
* @returns The same run shape as `audioGen()`: a synchronous request ID, generation progress stream, PCM audio promise, `chunkStream`, `encoded`, stats promise, and diagnostics promise. `stats.metadata.seed` reports the base seed the edit used.
|
|
24
26
|
*
|
|
25
27
|
* @example
|
|
26
28
|
* ```typescript
|
|
@@ -44,5 +46,5 @@ import type { AudioEditClientParams, AudioGenResult } from '@qvac/inference/surf
|
|
|
44
46
|
* const { pcm, sampleRate, channels, bitsPerSample } = await run.audio;
|
|
45
47
|
* ```
|
|
46
48
|
*/
|
|
47
|
-
export declare function audioEdit(params: AudioEditClientParams): AudioGenResult;
|
|
49
|
+
export declare function audioEdit(params: AudioEditClientParams, options?: RPCOptions): AudioGenResult;
|
|
48
50
|
//# sourceMappingURL=audio-edit.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { stream as streamRpc } from '
|
|
2
|
-
import { createAudioEditResult } from '
|
|
1
|
+
import { stream as streamRpc } from '../../client/rpc/rpc-client.js';
|
|
2
|
+
import { createAudioEditResult } from '../../client/api/audio-gen-result.js';
|
|
3
3
|
/**
|
|
4
4
|
* Edits a source recording with a loaded ACE-Step AudioGen model: an ordered
|
|
5
5
|
* pipeline of `flow-edit` and `repaint` operations, executed in array order.
|
|
@@ -21,7 +21,9 @@ import { createAudioEditResult } from './audio-gen-result.js';
|
|
|
21
21
|
* `repaint` regenerates the `start`..`end` range (seconds) against a new `caption`, keeping the
|
|
22
22
|
* rest of the clip. Operations may repeat or mix.
|
|
23
23
|
* @param params.seed - Seeds the first operation; each following operation uses `seed + index`.
|
|
24
|
-
* @
|
|
24
|
+
* @param params.outputFormat - Also deliver the edited audio as a file in this container, through
|
|
25
|
+
* `run.encoded`, as on a generation.
|
|
26
|
+
* @returns The same run shape as `audioGen()`: a synchronous request ID, generation progress stream, PCM audio promise, `chunkStream`, `encoded`, stats promise, and diagnostics promise. `stats.metadata.seed` reports the base seed the edit used.
|
|
25
27
|
*
|
|
26
28
|
* @example
|
|
27
29
|
* ```typescript
|
|
@@ -45,6 +47,6 @@ import { createAudioEditResult } from './audio-gen-result.js';
|
|
|
45
47
|
* const { pcm, sampleRate, channels, bitsPerSample } = await run.audio;
|
|
46
48
|
* ```
|
|
47
49
|
*/
|
|
48
|
-
export function audioEdit(params) {
|
|
49
|
-
return createAudioEditResult(params, streamRpc);
|
|
50
|
+
export function audioEdit(params, options) {
|
|
51
|
+
return createAudioEditResult(params, (request) => streamRpc(request, options));
|
|
50
52
|
}
|
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
import { audioEditClientParamsSchema, audioEditStreamResponseSchema, audioGenClientParamsSchema, audioGenStreamResponseSchema, audioUnderstandClientParamsSchema, audioUnderstandResponseSchema } from '@qvac/inference/surface';
|
|
2
|
-
import { parseClientInput } from '
|
|
3
|
-
import { generateClientRequestId } from '
|
|
2
|
+
import { parseClientInput } from '../../client/parse-input.js';
|
|
3
|
+
import { generateClientRequestId } from '../../client/api/client-request-id.js';
|
|
4
4
|
import { decodeBase64 } from '../../utils/encoding.js';
|
|
5
5
|
import { InvalidResponseError } from '../../utils/errors-client.js';
|
|
6
|
-
import { InferenceCancelledError } from '../../utils/errors-server.js';
|
|
6
|
+
import { AudioEncodeFailedError, InferenceCancelledError } from '../../utils/errors-server.js';
|
|
7
|
+
/**
|
|
8
|
+
* A queue one consumer drains as an async generator. It ends when the run
|
|
9
|
+
* does, and throws the run's error once the queued items are delivered.
|
|
10
|
+
*/
|
|
11
|
+
function createFeed() {
|
|
12
|
+
const queue = [];
|
|
13
|
+
let closed = false;
|
|
14
|
+
let failure;
|
|
15
|
+
let wake;
|
|
16
|
+
function notify() {
|
|
17
|
+
wake?.();
|
|
18
|
+
wake = undefined;
|
|
19
|
+
}
|
|
20
|
+
async function* drain() {
|
|
21
|
+
while (true) {
|
|
22
|
+
if (queue.length > 0) {
|
|
23
|
+
yield queue.shift();
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (closed) {
|
|
27
|
+
if (failure !== undefined)
|
|
28
|
+
throw failure;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
await new Promise((resolve) => {
|
|
32
|
+
wake = resolve;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
push(item) {
|
|
38
|
+
queue.push(item);
|
|
39
|
+
notify();
|
|
40
|
+
},
|
|
41
|
+
close(error) {
|
|
42
|
+
closed = true;
|
|
43
|
+
failure = error;
|
|
44
|
+
notify();
|
|
45
|
+
},
|
|
46
|
+
stream: drain()
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Copies one PCM frame into its own `Int16Array`. The copy keeps a caller
|
|
51
|
+
* that edits a chunk in place from changing `audio`, and gives the samples
|
|
52
|
+
* the alignment a view over the decoded bytes might lack.
|
|
53
|
+
*/
|
|
54
|
+
function toInt16Chunk(bytes, wireType) {
|
|
55
|
+
if (bytes.byteLength % Int16Array.BYTES_PER_ELEMENT !== 0) {
|
|
56
|
+
throw new InvalidResponseError(`${wireType} audio chunk`);
|
|
57
|
+
}
|
|
58
|
+
const samples = new Int16Array(bytes.byteLength / Int16Array.BYTES_PER_ELEMENT);
|
|
59
|
+
new Uint8Array(samples.buffer).set(bytes);
|
|
60
|
+
return samples;
|
|
61
|
+
}
|
|
62
|
+
async function* int16Chunks(indexes, read, wireType) {
|
|
63
|
+
for await (const index of indexes)
|
|
64
|
+
yield toInt16Chunk(read(index), wireType);
|
|
65
|
+
}
|
|
7
66
|
function concatenateChunks(chunks) {
|
|
8
67
|
const totalLength = chunks.reduce((total, chunk) => total + chunk.length, 0);
|
|
9
68
|
const pcm = new Uint8Array(totalLength);
|
|
@@ -22,7 +81,7 @@ export function createAudioGenResult(params, streamFactory) {
|
|
|
22
81
|
type: 'audioGenStream',
|
|
23
82
|
requestId
|
|
24
83
|
};
|
|
25
|
-
return collectAudioRun(requestId, 'audioGenStream', audioGenStreamResponseSchema, () => streamFactory(request));
|
|
84
|
+
return collectAudioRun(requestId, 'audioGenStream', audioGenStreamResponseSchema, () => streamFactory(request), request.outputFormat !== undefined);
|
|
26
85
|
}
|
|
27
86
|
export function createAudioEditResult(params, streamFactory) {
|
|
28
87
|
const parsed = parseClientInput(audioEditClientParamsSchema, params);
|
|
@@ -32,7 +91,7 @@ export function createAudioEditResult(params, streamFactory) {
|
|
|
32
91
|
type: 'audioEditStream',
|
|
33
92
|
requestId
|
|
34
93
|
};
|
|
35
|
-
return collectAudioRun(requestId, 'audioEditStream', audioEditStreamResponseSchema, () => streamFactory(request));
|
|
94
|
+
return collectAudioRun(requestId, 'audioEditStream', audioEditStreamResponseSchema, () => streamFactory(request), request.outputFormat !== undefined);
|
|
36
95
|
}
|
|
37
96
|
export function createAudioUnderstandResult(params, streamFactory) {
|
|
38
97
|
const parsed = parseClientInput(audioUnderstandClientParamsSchema, params);
|
|
@@ -45,10 +104,7 @@ export function createAudioUnderstandResult(params, streamFactory) {
|
|
|
45
104
|
return collectUnderstandRun(requestId, () => streamFactory(request));
|
|
46
105
|
}
|
|
47
106
|
function collectRun(requestId, wireType, responseSchema, open, sink) {
|
|
48
|
-
const
|
|
49
|
-
let progressDone = false;
|
|
50
|
-
let progressError;
|
|
51
|
-
let progressResolve;
|
|
107
|
+
const progress = createFeed();
|
|
52
108
|
let resolvePayload = () => { };
|
|
53
109
|
let rejectPayload = () => { };
|
|
54
110
|
const payload = new Promise((resolve, reject) => {
|
|
@@ -70,10 +126,6 @@ function collectRun(requestId, wireType, responseSchema, open, sink) {
|
|
|
70
126
|
rejectDiagnostics = reject;
|
|
71
127
|
});
|
|
72
128
|
diagnostics.catch(() => { });
|
|
73
|
-
function notifyProgress() {
|
|
74
|
-
progressResolve?.();
|
|
75
|
-
progressResolve = undefined;
|
|
76
|
-
}
|
|
77
129
|
function rejectAll(error) {
|
|
78
130
|
rejectPayload(error);
|
|
79
131
|
rejectStats(error);
|
|
@@ -81,6 +133,7 @@ function collectRun(requestId, wireType, responseSchema, open, sink) {
|
|
|
81
133
|
}
|
|
82
134
|
async function processResponses() {
|
|
83
135
|
let receivedDone = false;
|
|
136
|
+
let failure;
|
|
84
137
|
try {
|
|
85
138
|
for await (const response of open()) {
|
|
86
139
|
if (!response ||
|
|
@@ -90,10 +143,8 @@ function collectRun(requestId, wireType, responseSchema, open, sink) {
|
|
|
90
143
|
continue;
|
|
91
144
|
}
|
|
92
145
|
const frame = responseSchema.parse(response);
|
|
93
|
-
if (frame.progress)
|
|
94
|
-
|
|
95
|
-
notifyProgress();
|
|
96
|
-
}
|
|
146
|
+
if (frame.progress)
|
|
147
|
+
progress.push(frame.progress);
|
|
97
148
|
sink.absorb(frame);
|
|
98
149
|
if (frame.done) {
|
|
99
150
|
receivedDone = true;
|
|
@@ -113,33 +164,16 @@ function collectRun(requestId, wireType, responseSchema, open, sink) {
|
|
|
113
164
|
}
|
|
114
165
|
}
|
|
115
166
|
catch (error) {
|
|
116
|
-
|
|
117
|
-
rejectAll(
|
|
167
|
+
failure = error instanceof Error ? error : new InvalidResponseError(wireType, error);
|
|
168
|
+
rejectAll(failure);
|
|
118
169
|
}
|
|
119
170
|
finally {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function* progressStream() {
|
|
125
|
-
while (true) {
|
|
126
|
-
const tick = progressQueue.shift();
|
|
127
|
-
if (tick) {
|
|
128
|
-
yield tick;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (progressDone) {
|
|
132
|
-
if (progressError !== undefined)
|
|
133
|
-
throw progressError;
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
await new Promise((resolve) => {
|
|
137
|
-
progressResolve = resolve;
|
|
138
|
-
});
|
|
171
|
+
progress.close(failure);
|
|
172
|
+
sink.close?.(failure);
|
|
139
173
|
}
|
|
140
174
|
}
|
|
141
175
|
void processResponses();
|
|
142
|
-
return { requestId, progressStream:
|
|
176
|
+
return { requestId, progressStream: progress.stream, payload, stats, diagnostics };
|
|
143
177
|
}
|
|
144
178
|
/**
|
|
145
179
|
* Consumes an `audioUnderstand()` stream: the engine streams the description
|
|
@@ -164,18 +198,44 @@ function collectUnderstandRun(requestId, openStream) {
|
|
|
164
198
|
}
|
|
165
199
|
/**
|
|
166
200
|
* Consumes one generation or editing stream: PCM chunks accumulate into
|
|
167
|
-
* `audio`, carrying the format reported alongside them
|
|
201
|
+
* `audio`, carrying the format reported alongside them, and are offered one
|
|
202
|
+
* by one on `chunkStream`. The encoded file, when the request asked for one,
|
|
203
|
+
* settles `encoded`; a failed encode rejects `encoded` and nothing else.
|
|
168
204
|
*/
|
|
169
|
-
function collectAudioRun(requestId, wireType, responseSchema, open) {
|
|
205
|
+
function collectAudioRun(requestId, wireType, responseSchema, open, expectsEncoded) {
|
|
170
206
|
const pcmChunks = [];
|
|
171
207
|
let sampleRate;
|
|
172
208
|
let channels;
|
|
173
209
|
let bitsPerSample;
|
|
210
|
+
let encoded;
|
|
211
|
+
let encodeFailure;
|
|
212
|
+
// The PCM is held once. Until the run settles it is the received chunks;
|
|
213
|
+
// from then on it is `audio.pcm` alone, and the chunks are views into it.
|
|
214
|
+
// `chunkStream` queues chunk indexes rather than bytes, so an unread
|
|
215
|
+
// stream keeps no second copy of the audio alive.
|
|
216
|
+
let settledPcm;
|
|
217
|
+
const chunkEnds = [];
|
|
218
|
+
const chunks = createFeed();
|
|
219
|
+
function chunkBytes(index) {
|
|
220
|
+
if (settledPcm === undefined)
|
|
221
|
+
return pcmChunks[index] ?? new Uint8Array(0);
|
|
222
|
+
const start = index > 0 ? (chunkEnds[index - 1] ?? 0) : 0;
|
|
223
|
+
return settledPcm.subarray(start, chunkEnds[index] ?? start);
|
|
224
|
+
}
|
|
174
225
|
const { progressStream, payload, stats, diagnostics } = collectRun(requestId, wireType, responseSchema, open, {
|
|
175
226
|
absorb(frame) {
|
|
227
|
+
if (frame.encoded !== undefined) {
|
|
228
|
+
encoded = { ...frame.encoded, data: decodeBase64(frame.encoded.data) };
|
|
229
|
+
}
|
|
230
|
+
if (frame.encodeError !== undefined) {
|
|
231
|
+
encodeFailure = new AudioEncodeFailedError(frame.encodeError.format, frame.encodeError.details);
|
|
232
|
+
}
|
|
176
233
|
if (frame.data === undefined)
|
|
177
234
|
return;
|
|
178
|
-
|
|
235
|
+
const bytes = decodeBase64(frame.data);
|
|
236
|
+
chunks.push(pcmChunks.length);
|
|
237
|
+
pcmChunks.push(bytes);
|
|
238
|
+
chunkEnds.push((chunkEnds.at(-1) ?? 0) + bytes.byteLength);
|
|
179
239
|
sampleRate = frame.sampleRate;
|
|
180
240
|
channels = frame.channels;
|
|
181
241
|
bitsPerSample = frame.bitsPerSample;
|
|
@@ -184,13 +244,42 @@ function collectAudioRun(requestId, wireType, responseSchema, open) {
|
|
|
184
244
|
if (sampleRate === undefined || channels === undefined || bitsPerSample === undefined) {
|
|
185
245
|
throw new InvalidResponseError(`${wireType} audio chunk`);
|
|
186
246
|
}
|
|
247
|
+
if (expectsEncoded && encoded === undefined && encodeFailure === undefined) {
|
|
248
|
+
throw new InvalidResponseError(`${wireType} encoded audio`);
|
|
249
|
+
}
|
|
250
|
+
settledPcm = concatenateChunks(pcmChunks);
|
|
251
|
+
pcmChunks.length = 0;
|
|
187
252
|
return {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
253
|
+
audio: {
|
|
254
|
+
pcm: settledPcm,
|
|
255
|
+
sampleRate,
|
|
256
|
+
channels,
|
|
257
|
+
bitsPerSample
|
|
258
|
+
},
|
|
259
|
+
encoded,
|
|
260
|
+
encodeFailure
|
|
192
261
|
};
|
|
262
|
+
},
|
|
263
|
+
close(error) {
|
|
264
|
+
chunks.close(error);
|
|
193
265
|
}
|
|
194
266
|
});
|
|
195
|
-
|
|
267
|
+
const audio = payload.then((settled) => settled.audio);
|
|
268
|
+
// A failed encode rejects the file alone; the run itself completed.
|
|
269
|
+
const encodedAudio = payload.then((settled) => {
|
|
270
|
+
if (settled.encodeFailure !== undefined)
|
|
271
|
+
throw settled.encodeFailure;
|
|
272
|
+
return settled.encoded;
|
|
273
|
+
});
|
|
274
|
+
audio.catch(() => { });
|
|
275
|
+
encodedAudio.catch(() => { });
|
|
276
|
+
return {
|
|
277
|
+
requestId,
|
|
278
|
+
progressStream,
|
|
279
|
+
chunkStream: int16Chunks(chunks.stream, chunkBytes, wireType),
|
|
280
|
+
audio,
|
|
281
|
+
encoded: encodedAudio,
|
|
282
|
+
stats,
|
|
283
|
+
diagnostics
|
|
284
|
+
};
|
|
196
285
|
}
|