@qvac/harness 0.3.3 → 0.5.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/CHANGELOG.md +700 -126
- package/README.md +156 -0
- package/dist/harness.bundle +71 -103
- package/dist/prebuilds-manifest.json +0 -8
- package/dist-lib/index.d.ts +42 -40
- package/dist-lib/index.js +307 -117
- package/dist-lib/lib/audio-transcode-bare.d.ts +2 -2
- package/dist-lib/lib/audio-transcode-bare.js +28 -18
- package/dist-lib/lib/audio-transcode-node.d.ts +2 -2
- package/dist-lib/lib/capabilities/audio-resample.d.ts +7 -6
- package/dist-lib/lib/capabilities/audio-resample.js +30 -18
- package/dist-lib/lib/capabilities/completion.d.ts +20 -19
- package/dist-lib/lib/capabilities/completion.js +194 -135
- package/dist-lib/lib/capabilities/download.d.ts +6 -6
- package/dist-lib/lib/capabilities/download.js +15 -8
- package/dist-lib/lib/capabilities/embed.js +2 -1
- package/dist-lib/lib/capabilities/enhance.d.ts +6 -1
- package/dist-lib/lib/capabilities/enhance.js +7 -4
- package/dist-lib/lib/capabilities/invoke.js +7 -4
- package/dist-lib/lib/capabilities/kv-cache.js +2 -1
- package/dist-lib/lib/capabilities/preview-model-source.d.ts +69 -0
- package/dist-lib/lib/capabilities/preview-model-source.js +439 -0
- package/dist-lib/lib/capabilities/speech-text.js +5 -4
- package/dist-lib/lib/capabilities/tool-selection.js +10 -9
- package/dist-lib/lib/capabilities/tool-turns.js +30 -16
- package/dist-lib/lib/capabilities/usage-breakdown.js +2 -1
- package/dist-lib/lib/capabilities/voice.d.ts +5 -1
- package/dist-lib/lib/capabilities/voice.js +22 -12
- package/dist-lib/lib/connect.d.ts +15 -37
- package/dist-lib/lib/connect.js +161 -112
- package/dist-lib/lib/context-window.js +25 -21
- package/dist-lib/lib/contract-types.d.ts +26 -20
- package/dist-lib/lib/diagram-repair.d.ts +4 -4
- package/dist-lib/lib/diagram-repair.js +6 -3
- package/dist-lib/lib/docx/index.d.ts +3 -2
- package/dist-lib/lib/{error-fields.d.ts → guards.d.ts} +1 -0
- package/dist-lib/lib/{error-fields.js → guards.js} +3 -0
- package/dist-lib/lib/hardware/capability-probe.js +20 -10
- package/dist-lib/lib/hardware/gpu-classify.js +6 -3
- package/dist-lib/lib/hardware/gpu-probe-addon.js +8 -4
- package/dist-lib/lib/hardware/gpu-probe.js +4 -2
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +8 -9
- package/dist-lib/lib/hardware/parsers.js +8 -4
- package/dist-lib/lib/helpers/buffer-burst.js +4 -2
- package/dist-lib/lib/helpers/control-tokens.js +4 -2
- package/dist-lib/lib/helpers/join-guard.d.ts +2 -2
- package/dist-lib/lib/helpers/join-guard.js +4 -2
- package/dist-lib/lib/helpers/load-stall.js +4 -2
- package/dist-lib/lib/helpers/markup-stream-filter.d.ts +2 -2
- package/dist-lib/lib/helpers/markup-stream-filter.js +6 -3
- package/dist-lib/lib/helpers/race-abort.js +2 -1
- package/dist-lib/lib/helpers/race-timeout.d.ts +5 -0
- package/dist-lib/lib/helpers/race-timeout.js +14 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +6 -8
- package/dist-lib/lib/helpers/run-outcome.js +36 -20
- package/dist-lib/lib/helpers/spawn-path.js +6 -3
- package/dist-lib/lib/helpers/text-coalescer.js +6 -3
- package/dist-lib/lib/helpers/thinking.js +38 -45
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +9 -7
- package/dist-lib/lib/helpers/tool-call-markup.js +36 -20
- package/dist-lib/lib/helpers/tool-intent.d.ts +3 -2
- package/dist-lib/lib/helpers/tool-intent.js +4 -2
- package/dist-lib/lib/helpers/tool-label.js +18 -9
- package/dist-lib/lib/hooks/built-in/arg-repair.js +23 -13
- package/dist-lib/lib/hooks/built-in/egress.js +2 -1
- package/dist-lib/lib/hooks/built-in/skill-catalog.js +2 -1
- package/dist-lib/lib/hooks/pipeline.d.ts +5 -4
- package/dist-lib/lib/hooks/pipeline.js +6 -3
- package/dist-lib/lib/hooks/run.js +12 -8
- package/dist-lib/lib/model-download-progress.js +10 -8
- package/dist-lib/lib/models/context.d.ts +1 -1
- package/dist-lib/lib/models/context.js +5 -1
- package/dist-lib/lib/models/custom-model-cache.d.ts +13 -0
- package/dist-lib/lib/models/custom-model-cache.js +70 -0
- package/dist-lib/lib/models/gguf-header.d.ts +31 -0
- package/dist-lib/lib/models/gguf-header.js +230 -0
- package/dist-lib/lib/models/idle-unload.d.ts +14 -0
- package/dist-lib/lib/models/idle-unload.js +51 -0
- package/dist-lib/lib/models/kv-cache.d.ts +3 -2
- package/dist-lib/lib/models/kv-cache.js +4 -3
- package/dist-lib/lib/models/llm-presets.d.ts +2 -2
- package/dist-lib/lib/models/llm-presets.js +4 -2
- package/dist-lib/lib/models/model-catalog-constants.js +3 -2
- package/dist-lib/lib/models/model-catalog.d.ts +19 -21
- package/dist-lib/lib/models/model-catalog.js +66 -33
- package/dist-lib/lib/models/model-delete.d.ts +4 -1
- package/dist-lib/lib/models/model-delete.js +30 -15
- package/dist-lib/lib/models/model-handle.js +2 -1
- package/dist-lib/lib/models/model-list.d.ts +14 -3
- package/dist-lib/lib/models/model-list.js +33 -6
- package/dist-lib/lib/models/model-pool.d.ts +44 -10
- package/dist-lib/lib/models/model-pool.js +47 -42
- package/dist-lib/lib/models/model-source.js +11 -6
- package/dist-lib/lib/models/music-catalog.d.ts +2 -2
- package/dist-lib/lib/models/nmt-catalog.d.ts +4 -3
- package/dist-lib/lib/models/nmt-catalog.js +10 -5
- package/dist-lib/lib/models/opencl-cache.d.ts +6 -1
- package/dist-lib/lib/models/opencl-cache.js +5 -3
- package/dist-lib/lib/models/sdk-faults.d.ts +11 -8
- package/dist-lib/lib/models/sdk-faults.js +9 -6
- package/dist-lib/lib/models/shards.d.ts +11 -0
- package/dist-lib/lib/models/shards.js +15 -0
- package/dist-lib/lib/models/tool-dialect.js +10 -5
- package/dist-lib/lib/no-redirect-fetch-bare.d.ts +3 -3
- package/dist-lib/lib/no-redirect-fetch-bare.js +1 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +6 -3
- package/dist-lib/lib/no-redirect-fetch-node.d.ts +1 -1
- package/dist-lib/lib/no-redirect-fetch-node.js +9 -9
- package/dist-lib/lib/office/index.d.ts +3 -2
- package/dist-lib/lib/office/python.d.ts +3 -2
- package/dist-lib/lib/office/python.js +2 -1
- package/dist-lib/lib/prompt.d.ts +5 -4
- package/dist-lib/lib/prompt.js +8 -4
- package/dist-lib/lib/queue.js +10 -5
- package/dist-lib/lib/resolution-detector.js +21 -11
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/sdk-loader.js +2 -1
- package/dist-lib/lib/sdk-storage.js +4 -2
- package/dist-lib/lib/serve.js +128 -68
- package/dist-lib/lib/spawn.js +7 -4
- package/dist-lib/lib/tmp-path.d.ts +7 -6
- package/dist-lib/lib/tool-call-display.d.ts +2 -2
- package/dist-lib/lib/tools/create-documents.js +18 -10
- package/dist-lib/lib/tools/edit-documents.js +23 -13
- package/dist-lib/lib/tools/edit-image.d.ts +2 -2
- package/dist-lib/lib/tools/edit-image.js +60 -36
- package/dist-lib/lib/tools/exec/adapters/adapter.d.ts +10 -10
- package/dist-lib/lib/tools/exec/adapters/python/attachments.d.ts +17 -11
- package/dist-lib/lib/tools/exec/adapters/python/attachments.js +53 -40
- package/dist-lib/lib/tools/exec/adapters/python/create-effect.d.ts +2 -2
- package/dist-lib/lib/tools/exec/adapters/python/create-effect.js +60 -32
- package/dist-lib/lib/tools/exec/adapters/python/guarded-fetch.d.ts +33 -22
- package/dist-lib/lib/tools/exec/adapters/python/guarded-fetch.js +58 -29
- package/dist-lib/lib/tools/exec/adapters/python/interrupt-timer.d.ts +2 -2
- package/dist-lib/lib/tools/exec/adapters/python/loader.js +23 -12
- package/dist-lib/lib/tools/exec/adapters/python/memfs.d.ts +13 -11
- package/dist-lib/lib/tools/exec/adapters/python/memfs.js +10 -5
- package/dist-lib/lib/tools/exec/adapters/python/net-shim.js +3 -1
- package/dist-lib/lib/tools/exec/adapters/python/output-policy.d.ts +6 -4
- package/dist-lib/lib/tools/exec/adapters/python/output-policy.js +20 -10
- package/dist-lib/lib/tools/exec/adapters/python/pyodide.d.ts +2 -2
- package/dist-lib/lib/tools/exec/adapters/python/pyodide.js +14 -7
- package/dist-lib/lib/tools/exec/adapters/python/python-adapter.d.ts +41 -34
- package/dist-lib/lib/tools/exec/adapters/python/python-adapter.js +316 -166
- package/dist-lib/lib/tools/exec/adapters/python/run-session.d.ts +9 -8
- package/dist-lib/lib/tools/exec/adapters/python/run-session.js +56 -28
- package/dist-lib/lib/tools/exec/adapters/python/wheels.d.ts +8 -10
- package/dist-lib/lib/tools/exec/adapters/python/wheels.js +22 -11
- package/dist-lib/lib/tools/exec/adapters/python/worker/client.d.ts +3 -2
- package/dist-lib/lib/tools/exec/adapters/python/worker/client.js +41 -26
- package/dist-lib/lib/tools/exec/adapters/python/worker/entry.js +27 -18
- package/dist-lib/lib/tools/exec/adapters/python/worker/protocol.d.ts +2 -2
- package/dist-lib/lib/tools/exec/adapters/python/worker/protocol.js +14 -13
- package/dist-lib/lib/tools/exec/adapters/python/worker/spawn-node.d.ts +4 -4
- package/dist-lib/lib/tools/exec/adapters/python/worker/spawn-node.js +10 -5
- package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.d.ts +4 -4
- package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.js +2 -1
- package/dist-lib/lib/tools/exec/obsidian/cli-process.d.ts +6 -1
- package/dist-lib/lib/tools/exec/obsidian/cli-process.js +8 -5
- package/dist-lib/lib/tools/exec/obsidian/cli.d.ts +6 -6
- package/dist-lib/lib/tools/exec/obsidian/cli.js +4 -4
- package/dist-lib/lib/tools/exec/obsidian/command.d.ts +3 -2
- package/dist-lib/lib/tools/exec/obsidian/command.js +6 -3
- package/dist-lib/lib/tools/exec/obsidian/output.js +2 -1
- package/dist-lib/lib/tools/exec/obsidian/route.d.ts +4 -6
- package/dist-lib/lib/tools/exec/obsidian/route.js +17 -11
- package/dist-lib/lib/tools/exec/obsidian/safe-path.js +2 -1
- package/dist-lib/lib/tools/exec/obsidian/vault-create.js +15 -7
- package/dist-lib/lib/tools/exec/obsidian/vault-paths.d.ts +2 -2
- package/dist-lib/lib/tools/exec/obsidian/vault-paths.js +20 -10
- package/dist-lib/lib/tools/exec/obsidian/vault-read.js +20 -13
- package/dist-lib/lib/tools/exec/obsidian/vault-write.js +24 -12
- package/dist-lib/lib/tools/exec/runner.d.ts +14 -14
- package/dist-lib/lib/tools/exec/runner.js +5 -3
- package/dist-lib/lib/tools/exec/scope.js +52 -28
- package/dist-lib/lib/tools/exec/shell-argv.js +31 -18
- package/dist-lib/lib/tools/exec/shell-guidance.d.ts +6 -1
- package/dist-lib/lib/tools/exec/shell-guidance.js +35 -20
- package/dist-lib/lib/tools/exec/video-tools.js +2 -2
- package/dist-lib/lib/tools/exec.d.ts +6 -8
- package/dist-lib/lib/tools/exec.js +113 -54
- package/dist-lib/lib/tools/file-glob.d.ts +4 -5
- package/dist-lib/lib/tools/file-glob.js +16 -11
- package/dist-lib/lib/tools/fs/glob.js +13 -18
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +10 -10
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -2
- package/dist-lib/lib/tools/fs/remote.js +13 -7
- package/dist-lib/lib/tools/fs/scope.d.ts +8 -3
- package/dist-lib/lib/tools/fs/scope.js +20 -12
- package/dist-lib/lib/tools/fs/walk.js +6 -3
- package/dist-lib/lib/tools/fs/write.d.ts +3 -2
- package/dist-lib/lib/tools/generate-image.d.ts +11 -9
- package/dist-lib/lib/tools/generate-image.js +73 -37
- package/dist-lib/lib/tools/generate-music.d.ts +22 -11
- package/dist-lib/lib/tools/generate-music.js +79 -48
- package/dist-lib/lib/tools/grep.js +66 -41
- package/dist-lib/lib/tools/http-request/encode-fields.js +18 -9
- package/dist-lib/lib/tools/http-request/{utils.js → request.js} +20 -11
- package/dist-lib/lib/tools/http-request/truncate-response.js +57 -46
- package/dist-lib/lib/tools/http-request.d.ts +1 -1
- package/dist-lib/lib/tools/http-request.js +33 -18
- package/dist-lib/lib/tools/mcp/protocol.d.ts +53 -0
- package/dist-lib/lib/tools/mcp/{utils.js → protocol.js} +45 -23
- package/dist-lib/lib/tools/mcp-call.d.ts +1 -1
- package/dist-lib/lib/tools/mcp-call.js +37 -16
- package/dist-lib/lib/tools/operations/builders.js +10 -6
- package/dist-lib/lib/tools/operations/compile.js +20 -10
- package/dist-lib/lib/tools/operations/decoders.js +12 -6
- package/dist-lib/lib/tools/operations/gmail-message.js +3 -2
- package/dist-lib/lib/tools/outbound-guard.d.ts +4 -3
- package/dist-lib/lib/tools/outbound-guard.js +14 -8
- package/dist-lib/lib/tools/private-ip.js +8 -7
- package/dist-lib/lib/tools/rag-search.js +14 -7
- package/dist-lib/lib/tools/read-files.js +23 -20
- package/dist-lib/lib/tools/skill.js +19 -10
- package/dist-lib/lib/tools/skills/auth-resolver.d.ts +11 -18
- package/dist-lib/lib/tools/skills/auth-resolver.js +30 -18
- package/dist-lib/lib/tools/skills/bin-check.d.ts +3 -2
- package/dist-lib/lib/tools/skills/bin-check.js +10 -3
- package/dist-lib/lib/tools/skills/bundled-dir.js +20 -10
- package/dist-lib/lib/tools/skills/bundled-hash.d.ts +3 -2
- package/dist-lib/lib/tools/skills/bundled-hash.js +6 -1
- package/dist-lib/lib/tools/skills/catalog.d.ts +3 -2
- package/dist-lib/lib/tools/skills/catalog.js +33 -28
- package/dist-lib/lib/tools/skills/cli-argv.d.ts +3 -2
- package/dist-lib/lib/tools/skills/cli-argv.js +55 -52
- package/dist-lib/lib/tools/skills/cli-schema-check.js +21 -10
- package/dist-lib/lib/tools/skills/cli-schema-load.js +28 -20
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +6 -6
- package/dist-lib/lib/tools/skills/cli-schema.js +2 -1
- package/dist-lib/lib/tools/skills/credential-check.d.ts +6 -3
- package/dist-lib/lib/tools/skills/credential-check.js +24 -12
- package/dist-lib/lib/tools/skills/credential-grants.js +1 -6
- package/dist-lib/lib/tools/skills/credential-health.d.ts +5 -1
- package/dist-lib/lib/tools/skills/credential-health.js +5 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +10 -5
- package/dist-lib/lib/tools/skills/manifest-parse.js +84 -64
- package/dist-lib/lib/tools/skills/mention.js +7 -6
- package/dist-lib/lib/tools/skills/obsidian-readiness.d.ts +2 -2
- package/dist-lib/lib/tools/skills/obsidian-readiness.js +11 -3
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +6 -4
- package/dist-lib/lib/tools/skills/overlay-crud.js +12 -6
- package/dist-lib/lib/tools/skills/overlay-dir.js +4 -2
- package/dist-lib/lib/tools/skills/overlay-watch.d.ts +3 -2
- package/dist-lib/lib/tools/skills/overlay-watch.js +8 -4
- package/dist-lib/lib/tools/skills/setup-routes.js +1 -3
- package/dist-lib/lib/tools/skills/skill-settings.js +4 -1
- package/dist-lib/lib/tools/skills/skill-state.d.ts +6 -11
- package/dist-lib/lib/tools/skills/skill-state.js +48 -29
- package/dist-lib/lib/tools/skills/tool-grants.js +6 -3
- package/dist-lib/lib/tools/toolsets.js +2 -1
- package/dist-lib/lib/tools/translate.d.ts +4 -5
- package/dist-lib/lib/tools/translate.js +31 -14
- package/dist-lib/lib/tools/url-guard.js +2 -1
- package/dist-lib/lib/tools/weather-lookup/place.js +8 -4
- package/dist-lib/lib/tools/weather-lookup/report.d.ts +7 -1
- package/dist-lib/lib/tools/weather-lookup/report.js +46 -9
- package/dist-lib/lib/tools/weather-lookup.js +18 -12
- package/dist-lib/lib/tools/web-fetch.js +47 -24
- package/dist-lib/lib/tools/web-search.js +8 -3
- package/dist-lib/lib/validating-lookup.d.ts +4 -4
- package/dist-lib/lib/wav-encode.d.ts +1 -1
- package/dist-lib/lib/wav-encode.js +11 -10
- package/dist-lib/lib/web-fetch/embedded-state.js +24 -12
- package/dist-lib/lib/web-fetch/extract.js +4 -2
- package/dist-lib/lib/web-fetch/images.js +8 -4
- package/dist-lib/lib/web-fetch/video.d.ts +2 -2
- package/dist-lib/lib/web-fetch/video.js +8 -4
- package/dist-lib/lib/web-search/engine-registry.d.ts +2 -2
- package/dist-lib/lib/web-search/engines/aol.js +1 -1
- package/dist-lib/lib/web-search/engines/bing.js +1 -1
- package/dist-lib/lib/web-search/engines/brave.js +4 -1
- package/dist-lib/lib/web-search/engines/duckduckgo.js +3 -2
- package/dist-lib/lib/web-search/engines/google.js +7 -3
- package/dist-lib/lib/web-search/engines/wikipedia.js +5 -4
- package/dist-lib/lib/web-search/engines/yahoo.js +1 -1
- package/dist-lib/lib/web-search/fetch-html.d.ts +5 -4
- package/dist-lib/lib/web-search/fetch-html.js +13 -7
- package/dist-lib/lib/web-search/orchestrator.d.ts +9 -5
- package/dist-lib/lib/web-search/orchestrator.js +3 -3
- package/dist-lib/lib/wire.d.ts +3 -2
- package/dist-lib/lib/wire.js +23 -15
- package/dist-lib/schema/baseline.js +10 -5
- package/dist-lib/schema/build.js +2 -1
- package/dist-lib/schema/harness.d.ts +15 -2
- package/dist-lib/schema/harness.js +55 -2
- package/dist-lib/schema/release-tags.d.ts +3 -2
- package/dist-lib/schema/release-tags.js +6 -3
- package/dist-lib/spec/bind.js +6 -0
- package/dist-lib/spec/calls.js +2 -0
- package/dist-lib/spec/hrpc/hrpc.json +26 -0
- package/dist-lib/spec/hrpc/index.js +27 -3
- package/dist-lib/spec/hrpc/messages.js +207 -8
- package/dist-lib/spec/hyperschema/index.js +207 -8
- package/dist-lib/spec/hyperschema/schema.json +165 -1
- package/dist-lib/spec/hyperschema/types.d.ts +42 -1
- package/package.json +13 -14
- package/worker/harness-sidecar.mjs +16 -22
- package/worker/stow-entry.mjs +7 -4
- package/dist-lib/lib/tools/mcp/utils.d.ts +0 -47
- /package/dist-lib/lib/tools/http-request/{utils.d.ts → request.d.ts} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function transcodeToWav16kMono(input:
|
|
2
|
-
export declare function transcodeToPcm16kMono(input:
|
|
1
|
+
export declare function transcodeToWav16kMono(input: Uint8Array): Promise<Uint8Array | null>;
|
|
2
|
+
export declare function transcodeToPcm16kMono(input: Uint8Array): Promise<Uint8Array | null>;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import ffmpeg from 'bare-ffmpeg';
|
|
2
|
+
import b4a from 'b4a';
|
|
3
|
+
import { errorMessage } from './guards.js';
|
|
2
4
|
import { hlog } from './log.js';
|
|
3
5
|
import { buildWavBuffer, TARGET_SAMPLE_RATE } from './wav-encode.js';
|
|
4
6
|
function bufferReadIO(input) {
|
|
5
7
|
let offset = 0;
|
|
6
|
-
return new ffmpeg.IOContext(
|
|
8
|
+
return new ffmpeg.IOContext(b4a.alloc(4096), {
|
|
7
9
|
onread: (buffer, requested) => {
|
|
8
10
|
const remaining = input.length - offset;
|
|
9
|
-
if (remaining <= 0)
|
|
11
|
+
if (remaining <= 0) {
|
|
10
12
|
return 0;
|
|
13
|
+
}
|
|
11
14
|
const n = Math.min(requested, remaining);
|
|
12
15
|
buffer.set(input.subarray(offset, offset + n));
|
|
13
16
|
offset += n;
|
|
@@ -45,12 +48,12 @@ function readChunk(samples, outFrame, produced) {
|
|
|
45
48
|
if (produced <= 0)
|
|
46
49
|
return null;
|
|
47
50
|
samples.read(outFrame);
|
|
48
|
-
return
|
|
51
|
+
return b4a.from(samples.data.subarray(0, produced * 2));
|
|
49
52
|
}
|
|
50
53
|
function createResampler(frame, rate) {
|
|
51
54
|
return new ffmpeg.Resampler(frame.sampleRate, frame.channelLayout, frame.format, rate, ffmpeg.constants.channelLayouts.MONO, ffmpeg.constants.sampleFormats.S16);
|
|
52
55
|
}
|
|
53
|
-
function convertFrame(resampler, frame, samples, rate) {
|
|
56
|
+
function convertFrame(resampler, { frame, samples, rate }) {
|
|
54
57
|
const capacity = Math.ceil((frame.nbSamples * rate) / frame.sampleRate) + 1024;
|
|
55
58
|
const outFrame = makeOutFrame(capacity, rate);
|
|
56
59
|
const chunk = readChunk(samples, outFrame, resampler.convert(frame, outFrame));
|
|
@@ -66,19 +69,22 @@ function flushResampler(resampler, samples, rate) {
|
|
|
66
69
|
const outFrame = makeOutFrame(rate, rate);
|
|
67
70
|
flushed = resampler.flush(outFrame);
|
|
68
71
|
const chunk = readChunk(samples, outFrame, flushed);
|
|
69
|
-
if (chunk)
|
|
72
|
+
if (chunk) {
|
|
70
73
|
chunks.push(chunk);
|
|
74
|
+
}
|
|
71
75
|
outFrame.destroy();
|
|
72
76
|
} while (flushed > 0);
|
|
73
77
|
return chunks;
|
|
74
78
|
}
|
|
75
|
-
function drainDecodedFrames(decoder,
|
|
79
|
+
function drainDecodedFrames(decoder, resampler, target) {
|
|
80
|
+
const { frame, chunks, rate } = target;
|
|
76
81
|
let current = resampler;
|
|
77
82
|
while (decoder.receiveFrame(frame)) {
|
|
78
83
|
current ??= createResampler(frame, rate);
|
|
79
|
-
const chunk = convertFrame(current,
|
|
80
|
-
if (chunk)
|
|
84
|
+
const chunk = convertFrame(current, target);
|
|
85
|
+
if (chunk) {
|
|
81
86
|
chunks.push(chunk);
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
return current;
|
|
84
90
|
}
|
|
@@ -86,25 +92,27 @@ const YIELD_EVERY_PACKETS = 32;
|
|
|
86
92
|
function yieldToLoop() {
|
|
87
93
|
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
88
94
|
}
|
|
89
|
-
async function decodeToPcmChunks(inputFormat, stream, decoder, rate) {
|
|
95
|
+
async function decodeToPcmChunks(inputFormat, { stream, decoder, rate }) {
|
|
90
96
|
const chunks = [];
|
|
91
97
|
const packet = new ffmpeg.Packet();
|
|
92
98
|
const flush = new ffmpeg.Packet();
|
|
93
99
|
const frame = new ffmpeg.Frame();
|
|
94
100
|
const samples = new ffmpeg.Samples();
|
|
101
|
+
const target = { frame, samples, chunks, rate };
|
|
95
102
|
let resampler = null;
|
|
96
103
|
let packets = 0;
|
|
97
104
|
try {
|
|
98
105
|
while (inputFormat.readFrame(packet)) {
|
|
99
106
|
if (packet.streamIndex === stream.index && decoder.sendPacket(packet)) {
|
|
100
|
-
resampler = drainDecodedFrames(decoder,
|
|
107
|
+
resampler = drainDecodedFrames(decoder, resampler, target);
|
|
101
108
|
}
|
|
102
109
|
packet.unref();
|
|
103
|
-
if (++packets % YIELD_EVERY_PACKETS === 0)
|
|
110
|
+
if (++packets % YIELD_EVERY_PACKETS === 0) {
|
|
104
111
|
await yieldToLoop();
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
114
|
decoder.sendPacket(flush);
|
|
107
|
-
resampler = drainDecodedFrames(decoder,
|
|
115
|
+
resampler = drainDecodedFrames(decoder, resampler, target);
|
|
108
116
|
chunks.push(...flushResampler(resampler, samples, rate));
|
|
109
117
|
}
|
|
110
118
|
finally {
|
|
@@ -119,20 +127,22 @@ async function decodeInputToPcm(input, rate) {
|
|
|
119
127
|
let inputFormat = null;
|
|
120
128
|
let decoder = null;
|
|
121
129
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
const format = new ffmpeg.InputFormatContext(bufferReadIO(input));
|
|
131
|
+
inputFormat = format;
|
|
132
|
+
const stream = format.getBestStream(ffmpeg.constants.mediaTypes.AUDIO);
|
|
124
133
|
decoder = stream.decoder();
|
|
125
134
|
decoder.open();
|
|
126
|
-
const chunks = await decodeToPcmChunks(
|
|
127
|
-
return chunks.length === 0 ? null :
|
|
135
|
+
const chunks = await decodeToPcmChunks(format, { stream, decoder, rate });
|
|
136
|
+
return chunks.length === 0 ? null : b4a.concat(chunks);
|
|
128
137
|
}
|
|
129
138
|
catch (e) {
|
|
130
|
-
hlog('audio decode/resample failed', { error:
|
|
139
|
+
hlog('audio decode/resample failed', { error: errorMessage(e) });
|
|
131
140
|
return null;
|
|
132
141
|
}
|
|
133
142
|
finally {
|
|
134
|
-
if (decoder)
|
|
143
|
+
if (decoder) {
|
|
135
144
|
decoder.destroy();
|
|
145
|
+
}
|
|
136
146
|
inputFormat?.destroy();
|
|
137
147
|
}
|
|
138
148
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function transcodeToWav16kMono(_input:
|
|
2
|
-
export declare function transcodeToPcm16kMono(_input:
|
|
1
|
+
export declare function transcodeToWav16kMono(_input: Uint8Array): Promise<Uint8Array | null>;
|
|
2
|
+
export declare function transcodeToPcm16kMono(_input: Uint8Array): Promise<Uint8Array | null>;
|
|
@@ -4,11 +4,12 @@ interface WavFormat {
|
|
|
4
4
|
readonly sampleRate: number;
|
|
5
5
|
readonly bitsPerSample: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function wavFormat(bytes:
|
|
8
|
-
export declare function needsResample(bytes:
|
|
9
|
-
export
|
|
10
|
-
readonly bytes:
|
|
7
|
+
export declare function wavFormat(bytes: Uint8Array): WavFormat | null;
|
|
8
|
+
export declare function needsResample(bytes: Uint8Array): boolean;
|
|
9
|
+
export interface ResampledAudio {
|
|
10
|
+
readonly bytes: Uint8Array;
|
|
11
11
|
readonly transcoded: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare function
|
|
12
|
+
}
|
|
13
|
+
export declare function resampleForTranscription(bytes: Uint8Array): Promise<ResampledAudio>;
|
|
14
|
+
export declare function pcmForTranscription(bytes: Uint8Array): Promise<Uint8Array | null>;
|
|
14
15
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
1
2
|
import { transcodeToPcm16kMono, transcodeToWav16kMono } from '#audio-transcode';
|
|
2
3
|
const TARGET_SAMPLE_RATE = 16000;
|
|
3
4
|
const TARGET_CHANNELS = 1;
|
|
@@ -6,21 +7,24 @@ const WAV_PCM_FORMAT = 1;
|
|
|
6
7
|
export function wavFormat(bytes) {
|
|
7
8
|
if (bytes.length < 44)
|
|
8
9
|
return null;
|
|
9
|
-
if (
|
|
10
|
+
if (b4a.toString(bytes, 'ascii', 0, 4) !== 'RIFF')
|
|
10
11
|
return null;
|
|
11
|
-
if (
|
|
12
|
+
if (b4a.toString(bytes, 'ascii', 8, 12) !== 'WAVE') {
|
|
12
13
|
return null;
|
|
14
|
+
}
|
|
15
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
13
16
|
return {
|
|
14
|
-
formatCode:
|
|
15
|
-
channels:
|
|
16
|
-
sampleRate:
|
|
17
|
-
bitsPerSample:
|
|
17
|
+
formatCode: view.getUint16(20, true),
|
|
18
|
+
channels: view.getUint16(22, true),
|
|
19
|
+
sampleRate: b4a.readUInt32LE(bytes, 24),
|
|
20
|
+
bitsPerSample: view.getUint16(34, true)
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
function wavNeedsResample(bytes) {
|
|
21
24
|
const fmt = wavFormat(bytes);
|
|
22
|
-
if (!fmt)
|
|
25
|
+
if (!fmt) {
|
|
23
26
|
return true;
|
|
27
|
+
}
|
|
24
28
|
return (fmt.formatCode !== WAV_PCM_FORMAT ||
|
|
25
29
|
fmt.channels !== TARGET_CHANNELS ||
|
|
26
30
|
fmt.sampleRate !== TARGET_SAMPLE_RATE ||
|
|
@@ -29,35 +33,42 @@ function wavNeedsResample(bytes) {
|
|
|
29
33
|
export function needsResample(bytes) {
|
|
30
34
|
if (bytes.length < 12)
|
|
31
35
|
return false;
|
|
32
|
-
if (
|
|
36
|
+
if (b4a.toString(bytes, 'ascii', 0, 4) === 'RIFF' &&
|
|
37
|
+
b4a.toString(bytes, 'ascii', 8, 12) === 'WAVE') {
|
|
33
38
|
return wavNeedsResample(bytes);
|
|
34
39
|
}
|
|
35
|
-
if (
|
|
40
|
+
if (b4a.toString(bytes, 'ascii', 4, 8) === 'ftyp')
|
|
36
41
|
return true;
|
|
37
|
-
if (
|
|
42
|
+
if (b4a.toString(bytes, 'ascii', 0, 3) === 'ID3') {
|
|
38
43
|
return true;
|
|
39
|
-
|
|
44
|
+
}
|
|
45
|
+
if (bytes[0] === 0xff && ((bytes[1] ?? 0) & 0xe0) === 0xe0) {
|
|
40
46
|
return true;
|
|
41
|
-
|
|
47
|
+
}
|
|
48
|
+
if (b4a.toString(bytes, 'ascii', 0, 4) === 'OggS') {
|
|
42
49
|
return true;
|
|
43
|
-
|
|
50
|
+
}
|
|
51
|
+
if (b4a.toString(bytes, 'ascii', 0, 4) === 'fLaC') {
|
|
44
52
|
return true;
|
|
53
|
+
}
|
|
45
54
|
return false;
|
|
46
55
|
}
|
|
47
56
|
export async function resampleForTranscription(bytes) {
|
|
48
|
-
if (!needsResample(bytes))
|
|
57
|
+
if (!needsResample(bytes)) {
|
|
49
58
|
return { bytes, transcoded: false };
|
|
59
|
+
}
|
|
50
60
|
const wav = await transcodeToWav16kMono(bytes);
|
|
51
61
|
return wav ? { bytes: wav, transcoded: true } : { bytes, transcoded: false };
|
|
52
62
|
}
|
|
53
63
|
function wavPcmData(bytes) {
|
|
54
64
|
let offset = 12;
|
|
55
65
|
while (offset + 8 <= bytes.length) {
|
|
56
|
-
const id =
|
|
57
|
-
const size =
|
|
66
|
+
const id = b4a.toString(bytes, 'ascii', offset, offset + 4);
|
|
67
|
+
const size = b4a.readUInt32LE(bytes, offset + 4);
|
|
58
68
|
const start = offset + 8;
|
|
59
|
-
if (id === 'data')
|
|
69
|
+
if (id === 'data') {
|
|
60
70
|
return bytes.subarray(start, Math.min(start + size, bytes.length));
|
|
71
|
+
}
|
|
61
72
|
offset = start + size + (size & 1);
|
|
62
73
|
}
|
|
63
74
|
return null;
|
|
@@ -65,8 +76,9 @@ function wavPcmData(bytes) {
|
|
|
65
76
|
export async function pcmForTranscription(bytes) {
|
|
66
77
|
if (wavFormat(bytes) && !needsResample(bytes)) {
|
|
67
78
|
const pcm = wavPcmData(bytes);
|
|
68
|
-
if (pcm)
|
|
79
|
+
if (pcm) {
|
|
69
80
|
return pcm;
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
return transcodeToPcm16kMono(bytes);
|
|
72
84
|
}
|
|
@@ -10,12 +10,13 @@ import type { SkillCatalogEntry } from '../tools/skills/catalog.ts';
|
|
|
10
10
|
import { type SkillState } from '../tools/skills/skill-state-constants.ts';
|
|
11
11
|
import type { CliValidator } from '../tools/skills/cli-schema.ts';
|
|
12
12
|
import { type Toolset } from '../tools/toolsets.ts';
|
|
13
|
+
export interface MessageAttachment {
|
|
14
|
+
path: string;
|
|
15
|
+
}
|
|
13
16
|
export interface Message {
|
|
14
17
|
role: string;
|
|
15
18
|
content: string;
|
|
16
|
-
attachments?:
|
|
17
|
-
path: string;
|
|
18
|
-
}[];
|
|
19
|
+
attachments?: MessageAttachment[];
|
|
19
20
|
[key: string]: unknown;
|
|
20
21
|
}
|
|
21
22
|
export interface Agent {
|
|
@@ -186,35 +187,35 @@ export interface ToolDefinition {
|
|
|
186
187
|
compiled?: true;
|
|
187
188
|
execute: (args: Record<string, unknown>, ctx?: ToolExecuteContext) => Promise<unknown>;
|
|
188
189
|
}
|
|
189
|
-
export
|
|
190
|
+
export interface ToolCallEvent {
|
|
190
191
|
type: 'tool-call';
|
|
191
192
|
name: string;
|
|
192
193
|
args: Record<string, unknown>;
|
|
193
194
|
rawCall?: string | undefined;
|
|
194
195
|
effect?: ToolEffect | undefined;
|
|
195
196
|
display?: ToolCallDisplay | undefined;
|
|
196
|
-
}
|
|
197
|
-
export
|
|
197
|
+
}
|
|
198
|
+
export interface ToolResultEvent {
|
|
198
199
|
type: 'tool-result';
|
|
199
200
|
name: string;
|
|
200
201
|
result: unknown;
|
|
201
|
-
}
|
|
202
|
-
export
|
|
202
|
+
}
|
|
203
|
+
export interface ToolActivityEvent {
|
|
203
204
|
type: 'tool-activity';
|
|
204
205
|
name: string;
|
|
205
206
|
args: Record<string, unknown>;
|
|
206
207
|
resource: ResourceDescriptor | null;
|
|
207
208
|
effect: ToolEffect;
|
|
208
209
|
decision: ToolDecision;
|
|
209
|
-
}
|
|
210
|
-
export
|
|
210
|
+
}
|
|
211
|
+
export interface ErrorEvent {
|
|
211
212
|
type: 'error';
|
|
212
213
|
message: string;
|
|
213
|
-
}
|
|
214
|
-
export
|
|
214
|
+
}
|
|
215
|
+
export interface AbortedEvent {
|
|
215
216
|
type: 'aborted';
|
|
216
|
-
}
|
|
217
|
-
export
|
|
217
|
+
}
|
|
218
|
+
export interface MetricsEvent {
|
|
218
219
|
type: 'metrics';
|
|
219
220
|
totalTokens: number;
|
|
220
221
|
durationMs: number;
|
|
@@ -229,7 +230,7 @@ export type MetricsEvent = {
|
|
|
229
230
|
route?: 'direct' | 'enhanced' | undefined;
|
|
230
231
|
routeModel?: string | undefined;
|
|
231
232
|
stopReason?: string | undefined;
|
|
232
|
-
}
|
|
233
|
+
}
|
|
233
234
|
export interface InferenceCall {
|
|
234
235
|
round: number;
|
|
235
236
|
droppedTurns: number;
|
|
@@ -242,11 +243,11 @@ export interface InferenceCall {
|
|
|
242
243
|
cacheKey: string | undefined;
|
|
243
244
|
promptPrefix: string;
|
|
244
245
|
}
|
|
245
|
-
export
|
|
246
|
+
export interface InferenceCallEvent {
|
|
246
247
|
type: 'inference-call';
|
|
247
248
|
call: InferenceCall;
|
|
248
|
-
}
|
|
249
|
-
export
|
|
249
|
+
}
|
|
250
|
+
export interface InferenceSentEvent {
|
|
250
251
|
type: 'inference-sent';
|
|
251
252
|
round: number;
|
|
252
253
|
droppedTurns: number;
|
|
@@ -254,7 +255,7 @@ export type InferenceSentEvent = {
|
|
|
254
255
|
tokens: InferenceTokens | undefined;
|
|
255
256
|
outcome: 'completed' | 'overflowed' | 'failed';
|
|
256
257
|
reason: string | undefined;
|
|
257
|
-
}
|
|
258
|
+
}
|
|
258
259
|
export interface InferenceTokens {
|
|
259
260
|
prompt?: number | undefined;
|
|
260
261
|
generated?: number | undefined;
|