@qvac/harness 1.0.0-rc.2 → 1.0.0-rc.4
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/.nvmrc +1 -0
- package/CHANGELOG.md +2280 -1485
- package/README.md +56 -43
- package/dist-lib/index.d.ts +50 -6
- package/dist-lib/index.js +130 -28
- package/dist-lib/lib/agent/delegate.d.ts +3 -2
- package/dist-lib/lib/agent/delegate.js +6 -4
- package/dist-lib/lib/agent/follow.d.ts +5 -0
- package/dist-lib/lib/agent/follow.js +2 -0
- package/dist-lib/lib/agent/resolve.js +22 -17
- package/dist-lib/lib/agent/tool-selection.d.ts +4 -2
- package/dist-lib/lib/agent/tool-selection.js +5 -6
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +2 -1
- package/dist-lib/lib/capabilities/agent-ports.js +3 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +60 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +4 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +35 -6
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +67 -27
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +6 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +61 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +23 -13
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +8 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +5 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +47 -21
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +30 -5
- package/dist-lib/lib/capabilities/completion-engine/driver.js +27 -11
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.js +5 -1
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/index.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +15 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -0
- package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +9 -2
- package/dist-lib/lib/capabilities/completion-engine/metrics.js +28 -7
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +46 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +45 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -7
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +23 -3
- package/dist-lib/lib/capabilities/completion-engine/round.js +323 -97
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +10 -3
- package/dist-lib/lib/capabilities/completion-engine/session.js +30 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +4 -3
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -10
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +11 -4
- package/dist-lib/lib/capabilities/completion-engine/turns.js +48 -65
- package/dist-lib/lib/capabilities/download.d.ts +9 -7
- package/dist-lib/lib/capabilities/download.js +1 -1
- package/dist-lib/lib/capabilities/enhance.d.ts +1 -1
- package/dist-lib/lib/capabilities/enhance.js +20 -8
- package/dist-lib/lib/capabilities/preview-model-source.d.ts +7 -0
- package/dist-lib/lib/capabilities/preview-model-source.js +83 -23
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -0
- package/dist-lib/lib/capabilities/sdk-tool.js +18 -1
- package/dist-lib/lib/capabilities/tool-plan.d.ts +1 -1
- package/dist-lib/lib/capabilities/tool-plan.js +5 -5
- package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
- package/dist-lib/lib/capabilities/tool-turns.d.ts +7 -9
- package/dist-lib/lib/capabilities/tool-turns.js +25 -20
- package/dist-lib/lib/client/index.d.ts +19 -0
- package/dist-lib/lib/client/index.js +262 -0
- package/dist-lib/lib/connect.d.ts +13 -10
- package/dist-lib/lib/connect.js +62 -24
- package/dist-lib/lib/context-window.d.ts +1 -0
- package/dist-lib/lib/context-window.js +3 -3
- package/dist-lib/lib/contract/agent.d.ts +7 -3
- package/dist-lib/lib/contract/completion.d.ts +44 -29
- package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
- package/dist-lib/lib/contract/egress-proxy.js +1 -0
- package/dist-lib/lib/contract/exec.d.ts +3 -3
- package/dist-lib/lib/contract/hooks.d.ts +4 -1
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/models.d.ts +6 -4
- package/dist-lib/lib/contract/policy.d.ts +75 -0
- package/dist-lib/lib/contract/policy.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +9 -3
- package/dist-lib/lib/contract/sandbox.d.ts +3 -1
- package/dist-lib/lib/contract/translation.d.ts +20 -0
- package/dist-lib/lib/contract/translation.js +1 -0
- package/dist-lib/lib/contract-types.d.ts +32 -14
- package/dist-lib/lib/embeddings/index.d.ts +7 -1
- package/dist-lib/lib/embeddings/index.js +26 -5
- package/dist-lib/lib/errors.d.ts +266 -0
- package/dist-lib/lib/errors.js +198 -0
- package/dist-lib/lib/fold/index.d.ts +25 -1
- package/dist-lib/lib/fold/index.js +75 -9
- package/dist-lib/lib/guarded-fetch.js +11 -7
- package/dist-lib/lib/hardware/gpu-probe.js +10 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +6 -2
- package/dist-lib/lib/helpers/completion-params.js +10 -1
- package/dist-lib/lib/helpers/engine-error.d.ts +2 -1
- package/dist-lib/lib/helpers/engine-error.js +12 -12
- package/dist-lib/lib/helpers/goal-check.d.ts +4 -0
- package/dist-lib/lib/helpers/goal-check.js +81 -0
- package/dist-lib/lib/helpers/head-tail.js +1 -1
- package/dist-lib/lib/helpers/load-stall.d.ts +1 -1
- package/dist-lib/lib/helpers/load-stall.js +2 -2
- package/dist-lib/lib/helpers/markup-stream-filter.d.ts +4 -1
- package/dist-lib/lib/helpers/markup-stream-filter.js +20 -6
- package/dist-lib/lib/helpers/repeated-reply.js +24 -16
- package/dist-lib/lib/helpers/thinking.d.ts +3 -2
- package/dist-lib/lib/helpers/thinking.js +19 -0
- package/dist-lib/lib/hooks/built-in/arg-repair.js +6 -2
- package/dist-lib/lib/hooks/built-in/policy-rules.d.ts +8 -0
- package/dist-lib/lib/hooks/built-in/policy-rules.js +192 -0
- package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
- package/dist-lib/lib/hooks/index.d.ts +4 -1
- package/dist-lib/lib/hooks/index.js +9 -4
- package/dist-lib/lib/hooks/run.js +3 -3
- package/dist-lib/lib/lifecycle/index.js +15 -14
- package/dist-lib/lib/lifecycle/machine.js +2 -2
- package/dist-lib/lib/log.d.ts +26 -5
- package/dist-lib/lib/log.js +86 -23
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +4 -2
- package/dist-lib/lib/machine/completion/actions/completion.js +75 -10
- package/dist-lib/lib/machine/completion/actions/prepare.js +1 -1
- package/dist-lib/lib/machine/completion/actions/tools.js +48 -5
- package/dist-lib/lib/machine/completion/context.js +4 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +1 -0
- package/dist-lib/lib/machine/completion/guards/retry.js +8 -2
- package/dist-lib/lib/machine/completion/implementations.d.ts +10 -4
- package/dist-lib/lib/machine/completion/implementations.js +27 -6
- package/dist-lib/lib/machine/completion/machine.d.ts +21 -3
- package/dist-lib/lib/machine/completion/machine.js +33 -4
- package/dist-lib/lib/machine/completion/rules.d.ts +17 -2
- package/dist-lib/lib/machine/completion/rules.js +49 -3
- package/dist-lib/lib/machine/completion/types.d.ts +36 -0
- package/dist-lib/lib/machine/index.d.ts +27 -4
- package/dist-lib/lib/machine/index.js +6 -1
- package/dist-lib/lib/models/context-choice.d.ts +15 -0
- package/dist-lib/lib/models/context-choice.js +55 -0
- package/dist-lib/lib/models/download-gate.d.ts +20 -0
- package/dist-lib/lib/models/download-gate.js +73 -0
- package/dist-lib/lib/models/gguf-header.d.ts +5 -0
- package/dist-lib/lib/models/gguf-header.js +165 -14
- package/dist-lib/lib/models/llm-presets.d.ts +5 -1
- package/dist-lib/lib/models/llm-presets.js +6 -5
- package/dist-lib/lib/models/memory-cap.d.ts +13 -0
- package/dist-lib/lib/models/memory-cap.js +21 -0
- package/dist-lib/lib/models/model-catalog.d.ts +2 -0
- package/dist-lib/lib/models/model-catalog.js +15 -0
- package/dist-lib/lib/models/model-fit.d.ts +1 -1
- package/dist-lib/lib/models/model-fit.js +5 -6
- package/dist-lib/lib/models/model-handle.d.ts +8 -2
- package/dist-lib/lib/models/model-handle.js +14 -3
- package/dist-lib/lib/models/model-list.d.ts +8 -1
- package/dist-lib/lib/models/model-list.js +23 -0
- package/dist-lib/lib/models/model-pool.d.ts +35 -5
- package/dist-lib/lib/models/model-pool.js +121 -43
- package/dist-lib/lib/models/model-source.d.ts +1 -0
- package/dist-lib/lib/models/model-source.js +23 -5
- package/dist-lib/lib/models/sdk-faults.d.ts +1 -0
- package/dist-lib/lib/models/sdk-faults.js +9 -0
- package/dist-lib/lib/no-redirect-fetch-bare.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +2 -1
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +23 -0
- package/dist-lib/lib/office/engine/pptx/picture-area.js +84 -0
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +2 -0
- package/dist-lib/lib/office/engine/pptx/presentation.js +55 -17
- package/dist-lib/lib/office/engine/pptx/types.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +1 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.js +34 -3
- package/dist-lib/lib/office/extract.js +4 -3
- package/dist-lib/lib/office/index.js +2 -1
- package/dist-lib/lib/plugins/registry.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.js +16 -7
- package/dist-lib/lib/policy/index.d.ts +10 -0
- package/dist-lib/lib/policy/index.js +229 -0
- package/dist-lib/lib/prompt.d.ts +1 -0
- package/dist-lib/lib/prompt.js +7 -1
- package/dist-lib/lib/residency/completion-runtime.d.ts +1 -0
- package/dist-lib/lib/residency/completion-runtime.js +11 -4
- package/dist-lib/lib/residency/index.d.ts +44 -4
- package/dist-lib/lib/residency/index.js +399 -35
- package/dist-lib/lib/resolution-detector.js +3 -3
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/sdk-loader.js +17 -11
- package/dist-lib/lib/serve.js +76 -36
- package/dist-lib/lib/sidecar/index.d.ts +29 -0
- package/dist-lib/lib/sidecar/index.js +174 -0
- package/dist-lib/lib/sidecar/user-plugins.d.ts +8 -0
- package/dist-lib/lib/sidecar/user-plugins.js +117 -0
- package/dist-lib/lib/skills-host/index.d.ts +1 -0
- package/dist-lib/lib/skills-host/index.js +8 -4
- package/dist-lib/lib/spawn.d.ts +3 -4
- package/dist-lib/lib/spawn.js +17 -17
- package/dist-lib/lib/spill.d.ts +1 -0
- package/dist-lib/lib/spill.js +12 -8
- package/dist-lib/lib/tools/attachments/staging.js +8 -8
- package/dist-lib/lib/tools/exec/runner.js +2 -1
- package/dist-lib/lib/tools/exec/scope.d.ts +0 -1
- package/dist-lib/lib/tools/exec/scope.js +23 -114
- package/dist-lib/lib/tools/exec/shell-guidance.js +4 -4
- package/dist-lib/lib/tools/exec/shell-line.d.ts +26 -0
- package/dist-lib/lib/tools/exec/shell-line.js +334 -0
- package/dist-lib/lib/tools/exec.d.ts +4 -1
- package/dist-lib/lib/tools/exec.js +87 -26
- package/dist-lib/lib/tools/files/edit-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/edit-file.js +74 -0
- package/dist-lib/lib/tools/files/glob.d.ts +3 -0
- package/dist-lib/lib/tools/files/glob.js +65 -0
- package/dist-lib/lib/tools/files/grep.d.ts +6 -0
- package/dist-lib/lib/tools/files/grep.js +114 -0
- package/dist-lib/lib/tools/files/index.d.ts +3 -0
- package/dist-lib/lib/tools/files/index.js +23 -0
- package/dist-lib/lib/tools/files/list-dir.d.ts +6 -0
- package/dist-lib/lib/tools/files/list-dir.js +136 -0
- package/dist-lib/lib/tools/files/make-dir.d.ts +3 -0
- package/dist-lib/lib/tools/files/make-dir.js +48 -0
- package/dist-lib/lib/tools/files/read-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/read-file.js +105 -0
- package/dist-lib/lib/tools/files/transfer.d.ts +4 -0
- package/dist-lib/lib/tools/files/transfer.js +83 -0
- package/dist-lib/lib/tools/files/trash-file.d.ts +4 -0
- package/dist-lib/lib/tools/files/trash-file.js +62 -0
- package/dist-lib/lib/tools/files/write-file.d.ts +3 -0
- package/dist-lib/lib/tools/files/write-file.js +56 -0
- package/dist-lib/lib/tools/fs/document-text.d.ts +2 -0
- package/dist-lib/lib/tools/fs/document-text.js +38 -0
- package/dist-lib/lib/tools/fs/drive.d.ts +14 -3
- package/dist-lib/lib/tools/fs/drive.js +9 -1
- package/dist-lib/lib/tools/fs/edit-match.d.ts +11 -0
- package/dist-lib/lib/tools/fs/edit-match.js +85 -0
- package/dist-lib/lib/tools/fs/ignore.d.ts +13 -0
- package/dist-lib/lib/tools/fs/ignore.js +104 -0
- package/dist-lib/lib/tools/fs/local.js +28 -5
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +23 -3
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -4
- package/dist-lib/lib/tools/fs/remote.js +23 -13
- package/dist-lib/lib/tools/fs/scope.d.ts +5 -1
- package/dist-lib/lib/tools/fs/scope.js +5 -2
- package/dist-lib/lib/tools/fs/search.d.ts +41 -0
- package/dist-lib/lib/tools/fs/search.js +382 -0
- package/dist-lib/lib/tools/{file-glob.d.ts → fs/targets.d.ts} +1 -5
- package/dist-lib/lib/tools/fs/targets.js +32 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +27 -0
- package/dist-lib/lib/tools/fs/tool-path.js +70 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +15 -3
- package/dist-lib/lib/tools/fs/walk.js +118 -24
- package/dist-lib/lib/tools/http-request.js +12 -2
- package/dist-lib/lib/tools/index.js +2 -10
- package/dist-lib/lib/tools/office/ops.js +1 -1
- package/dist-lib/lib/tools/office.js +77 -21
- package/dist-lib/lib/tools/pdf/build.d.ts +5 -1
- package/dist-lib/lib/tools/pdf/build.js +31 -6
- package/dist-lib/lib/tools/pdf.js +17 -2
- package/dist-lib/lib/tools/skill.js +10 -7
- package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
- package/dist-lib/lib/tools/skills/catalog.d.ts +2 -0
- package/dist-lib/lib/tools/skills/catalog.js +6 -2
- package/dist-lib/lib/tools/skills/cli-argv.js +25 -5
- package/dist-lib/lib/tools/skills/cli-schema-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/cli-schema-check.js +3 -0
- package/dist-lib/lib/tools/skills/cli-schema-load.js +10 -0
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +2 -0
- package/dist-lib/lib/tools/skills/cli-schema.js +6 -3
- package/dist-lib/lib/tools/skills/credential-health.js +3 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +2 -0
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +4 -0
- package/dist-lib/lib/tools/skills/manifest-parse.d.ts +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +12 -0
- package/dist-lib/lib/tools/skills/mention-name.d.ts +6 -0
- package/dist-lib/lib/tools/skills/mention-name.js +6 -0
- package/dist-lib/lib/tools/skills/mention.d.ts +2 -2
- package/dist-lib/lib/tools/skills/mention.js +11 -4
- package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
- package/dist-lib/lib/tools/url-guard.d.ts +6 -1
- package/dist-lib/lib/tools/url-guard.js +8 -2
- package/dist-lib/lib/tools/web-fetch.js +10 -4
- package/dist-lib/lib/wire.js +3 -5
- package/dist-lib/plugins/coding/index.d.ts +1 -1
- package/dist-lib/plugins/coding/index.js +2 -4
- package/dist-lib/plugins/coding/session.d.ts +3 -3
- package/dist-lib/plugins/coding/session.js +26 -14
- package/dist-lib/plugins/command-hooks/index.js +5 -3
- package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
- package/dist-lib/plugins/egress-proxy/index.js +182 -0
- package/dist-lib/plugins/image/edit-image.js +4 -3
- package/dist-lib/plugins/image/generate-image.d.ts +4 -3
- package/dist-lib/plugins/image/generate-image.js +10 -9
- package/dist-lib/plugins/image/index.d.ts +1 -1
- package/dist-lib/plugins/image/index.js +13 -10
- package/dist-lib/plugins/language-hint/index.d.ts +15 -0
- package/dist-lib/plugins/language-hint/index.js +51 -0
- package/dist-lib/plugins/lsp/tool.js +2 -2
- package/dist-lib/plugins/mcp/index.js +6 -3
- package/dist-lib/plugins/music/generate-music.d.ts +4 -2
- package/dist-lib/plugins/music/generate-music.js +7 -4
- package/dist-lib/plugins/music/index.js +12 -9
- package/dist-lib/plugins/obsidian/command.js +2 -2
- package/dist-lib/plugins/obsidian/note-name.js +2 -1
- package/dist-lib/plugins/obsidian/safe-path.js +5 -4
- package/dist-lib/plugins/obsidian/vault-create.js +3 -2
- package/dist-lib/plugins/obsidian/vault-fs.js +2 -2
- package/dist-lib/plugins/obsidian/vault-paths.js +3 -2
- package/dist-lib/plugins/obsidian/vault-read.js +6 -5
- package/dist-lib/plugins/obsidian/vault-write.js +13 -12
- package/dist-lib/plugins/python/guarded-fetch.d.ts +2 -1
- package/dist-lib/plugins/python/guarded-fetch.js +5 -1
- package/dist-lib/plugins/python/interrupt-timer.js +2 -2
- package/dist-lib/plugins/python/loader.js +68 -3
- package/dist-lib/plugins/python/memfs.js +2 -2
- package/dist-lib/plugins/python/pyodide.d.ts +1 -0
- package/dist-lib/plugins/python/pyodide.js +9 -8
- package/dist-lib/plugins/python/python-adapter.js +3 -1
- package/dist-lib/plugins/python/run-session.d.ts +1 -0
- package/dist-lib/plugins/python/run-session.js +19 -8
- package/dist-lib/plugins/python/wheels.js +8 -6
- package/dist-lib/plugins/python/worker/active.js +2 -2
- package/dist-lib/plugins/python/worker/client.js +9 -8
- package/dist-lib/plugins/python/worker/protocol.d.ts +2 -0
- package/dist-lib/plugins/python/worker/serve.js +23 -4
- package/dist-lib/plugins/python/worker/spawn.d.ts +2 -1
- package/dist-lib/plugins/python/worker/spawn.js +2 -1
- package/dist-lib/plugins/run-report/chain.d.ts +2 -0
- package/dist-lib/plugins/run-report/chain.js +73 -0
- package/dist-lib/plugins/run-report/flow-view.js +2 -1
- package/dist-lib/plugins/run-report/flow.d.ts +1 -1
- package/dist-lib/plugins/run-report/flow.js +66 -14
- package/dist-lib/plugins/run-report/index.d.ts +23 -2
- package/dist-lib/plugins/run-report/index.js +27 -12
- package/dist-lib/plugins/run-report/model.d.ts +10 -1
- package/dist-lib/plugins/run-report/model.js +12 -6
- package/dist-lib/plugins/run-report/page.d.ts +9 -0
- package/dist-lib/plugins/run-report/page.js +55 -15
- package/dist-lib/plugins/run-report/script.js +317 -43
- package/dist-lib/plugins/run-report/story.d.ts +2 -1
- package/dist-lib/plugins/run-report/story.js +3 -3
- package/dist-lib/plugins/run-report/style.d.ts +1 -1
- package/dist-lib/plugins/run-report/style.js +126 -0
- package/dist-lib/plugins/run-report/why.js +1 -1
- package/dist-lib/plugins/sandbox-linux/index.d.ts +60 -0
- package/dist-lib/plugins/sandbox-linux/index.js +347 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.d.ts +2 -0
- package/dist-lib/plugins/sandbox-linux/seccomp.js +74 -0
- package/dist-lib/plugins/sandbox-macos/index.d.ts +23 -11
- package/dist-lib/plugins/sandbox-macos/index.js +239 -49
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +4 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +9 -4
- package/dist-lib/plugins/sandbox-windows/helper/qvac-sandbox.c +554 -0
- package/dist-lib/plugins/sandbox-windows/index.d.ts +53 -0
- package/dist-lib/plugins/sandbox-windows/index.js +205 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/audio-resample.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-resample.js +7 -8
- package/dist-lib/plugins/speech/audio-transcode-bare.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-bare.js +23 -26
- package/dist-lib/plugins/speech/audio-transcode-node.d.ts +1 -1
- package/dist-lib/plugins/speech/audio-transcode-node.js +1 -3
- package/dist-lib/plugins/speech/speech-runtime.js +37 -37
- package/dist-lib/plugins/speech/voice.d.ts +5 -1
- package/dist-lib/plugins/speech/voice.js +100 -31
- package/dist-lib/plugins/translation/index.d.ts +1 -0
- package/dist-lib/plugins/translation/index.js +16 -9
- package/dist-lib/plugins/translation/translate.d.ts +7 -3
- package/dist-lib/plugins/translation/translate.js +64 -58
- package/dist-lib/plugins/weather/geocode.js +2 -1
- package/dist-lib/plugins/weather/lookup.js +5 -4
- package/dist-lib/plugins/web-search/engines/bing.js +2 -1
- package/dist-lib/plugins/web-search/engines/google.js +2 -1
- package/dist-lib/plugins/web-search/fetch-html.d.ts +5 -5
- package/dist-lib/plugins/web-search/fetch-html.js +12 -15
- package/dist-lib/plugins/web-search/tool.js +1 -0
- package/dist-lib/schema/harness.js +48 -7
- package/dist-lib/spec/bind.js +9 -0
- package/dist-lib/spec/calls.js +3 -0
- package/dist-lib/spec/hrpc/hrpc.json +42 -3
- package/dist-lib/spec/hrpc/index.js +44 -8
- package/dist-lib/spec/hrpc/messages.js +297 -202
- package/dist-lib/spec/hyperschema/index.js +297 -202
- package/dist-lib/spec/hyperschema/schema.json +155 -84
- package/dist-lib/spec/hyperschema/types.d.ts +23 -3
- package/package.json +101 -38
- package/patches/@qvac%2Finference@0.22.0.patch +59 -0
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +10 -5
- package/worker/harness-sidecar.mjs +18 -154
- package/dist-lib/lib/tools/create-documents.d.ts +0 -3
- package/dist-lib/lib/tools/create-documents.js +0 -95
- package/dist-lib/lib/tools/edit-documents.d.ts +0 -3
- package/dist-lib/lib/tools/edit-documents.js +0 -132
- package/dist-lib/lib/tools/exec/shell-argv.d.ts +0 -2
- package/dist-lib/lib/tools/exec/shell-argv.js +0 -61
- package/dist-lib/lib/tools/file-glob.js +0 -118
- package/dist-lib/lib/tools/grep.d.ts +0 -5
- package/dist-lib/lib/tools/grep.js +0 -184
- package/dist-lib/lib/tools/read-files.d.ts +0 -5
- package/dist-lib/lib/tools/read-files.js +0 -160
- package/dist-lib/plugins/coding/write-file.d.ts +0 -3
- package/dist-lib/plugins/coding/write-file.js +0 -52
- package/patches/@qvac%2Finference@0.21.0.patch +0 -67
- package/patches/bare-stow@0.1.5.patch +0 -68
- package/patches/hypercore-blob-server@1.15.0.patch +0 -15
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { errorMessage } from '../../lib/guards.js';
|
|
3
3
|
import { AbortedError } from '../../lib/helpers/race-abort.js';
|
|
4
|
-
import {
|
|
4
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
5
|
+
import { HarnessLog } from '../../lib/log.js';
|
|
5
6
|
import { normalizeForMoss, normalizeForSpeech } from './speech-text.js';
|
|
7
|
+
import { buildWavBuffer } from './wav-encode.js';
|
|
6
8
|
const NATIVE_SAMPLE_RATE = { supertonic: 44100, moss: 24000 };
|
|
7
9
|
const NORMALIZE = {
|
|
8
10
|
supertonic: normalizeForSpeech,
|
|
@@ -10,31 +12,19 @@ const NORMALIZE = {
|
|
|
10
12
|
};
|
|
11
13
|
const TRANSCRIBE_SAMPLE_RATE = 16000;
|
|
12
14
|
const TRANSCRIBE_CHUNK_BYTES = TRANSCRIBE_SAMPLE_RATE * 2;
|
|
15
|
+
const TRANSCRIBE_STREAM_MIN_BYTES = TRANSCRIBE_CHUNK_BYTES * 60;
|
|
16
|
+
const TRANSCRIBE_SEGMENT_SECONDS = 300;
|
|
13
17
|
const PARAKEET_STREAMING = { emitPartials: false, chunkMs: 5000 };
|
|
14
18
|
const TRANSCRIBE_WITH_METADATA = false;
|
|
15
19
|
const TRANSCRIBE_PACE_MS = 40;
|
|
16
20
|
function pace(ms) {
|
|
17
21
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
async function writePaced(session, data, signal) {
|
|
22
|
-
for (let offset = 0; offset < data.length; offset += TRANSCRIBE_CHUNK_BYTES) {
|
|
23
|
+
async function writePaced(session, pcm, signal) {
|
|
24
|
+
for await (const second of pcm) {
|
|
23
25
|
if (signal?.aborted)
|
|
24
26
|
return;
|
|
25
|
-
session.write(
|
|
26
|
-
await pace(TRANSCRIBE_PACE_MS);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
async function drainUntilIdle(lastPieceAt, streamClosed, signal) {
|
|
30
|
-
const deadline = Date.now() + TRANSCRIBE_DRAIN_MAX_MS;
|
|
31
|
-
for (;;) {
|
|
32
|
-
if (signal?.aborted || streamClosed() || Date.now() >= deadline)
|
|
33
|
-
return;
|
|
34
|
-
const last = lastPieceAt();
|
|
35
|
-
if (last > 0 && Date.now() - last >= TRANSCRIBE_DRAIN_IDLE_MS) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
27
|
+
session.write(second);
|
|
38
28
|
await pace(TRANSCRIBE_PACE_MS);
|
|
39
29
|
}
|
|
40
30
|
}
|
|
@@ -55,7 +45,93 @@ function transcribePiece(piece) {
|
|
|
55
45
|
}
|
|
56
46
|
return null;
|
|
57
47
|
}
|
|
58
|
-
|
|
48
|
+
async function* inSeconds(pcm) {
|
|
49
|
+
let pending = [];
|
|
50
|
+
let size = 0;
|
|
51
|
+
for await (const chunk of pcm) {
|
|
52
|
+
pending.push(chunk);
|
|
53
|
+
size += chunk.length;
|
|
54
|
+
if (size < TRANSCRIBE_CHUNK_BYTES) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const joined = pending.length === 1 ? chunk : b4a.concat(pending);
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (; joined.length - offset >= TRANSCRIBE_CHUNK_BYTES; offset += TRANSCRIBE_CHUNK_BYTES) {
|
|
60
|
+
yield joined.subarray(offset, offset + TRANSCRIBE_CHUNK_BYTES);
|
|
61
|
+
}
|
|
62
|
+
size = joined.length - offset;
|
|
63
|
+
pending = size > 0 ? [joined.subarray(offset)] : [];
|
|
64
|
+
}
|
|
65
|
+
if (size > 0) {
|
|
66
|
+
yield b4a.concat(pending);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function readHead(seconds, signal) {
|
|
70
|
+
const head = { seconds: [], bytes: 0 };
|
|
71
|
+
try {
|
|
72
|
+
while (head.bytes < TRANSCRIBE_STREAM_MIN_BYTES && !signal?.aborted) {
|
|
73
|
+
const next = await seconds.next();
|
|
74
|
+
if (next.done) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
head.seconds.push(next.value);
|
|
78
|
+
head.bytes += next.value.length;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
HarnessLog.warn('audio decode/resample failed', { error: errorMessage(err) });
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return head;
|
|
86
|
+
}
|
|
87
|
+
async function* resume(head, rest) {
|
|
88
|
+
yield* head.seconds;
|
|
89
|
+
yield* { [Symbol.asyncIterator]: () => rest };
|
|
90
|
+
}
|
|
91
|
+
export async function transcribeAudio(sdk, pcm, { modelId, signal, audio }) {
|
|
92
|
+
const seconds = inSeconds(pcm);
|
|
93
|
+
const head = await readHead(seconds, signal);
|
|
94
|
+
if (signal?.aborted) {
|
|
95
|
+
await seconds.return(undefined);
|
|
96
|
+
throw new AbortedError();
|
|
97
|
+
}
|
|
98
|
+
if (!head || head.bytes === 0) {
|
|
99
|
+
return transcribeOnce(sdk, modelId, audio);
|
|
100
|
+
}
|
|
101
|
+
if (head.bytes < TRANSCRIBE_STREAM_MIN_BYTES) {
|
|
102
|
+
return transcribeOnce(sdk, modelId, buildWavBuffer(b4a.concat(head.seconds)));
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
return await transcribeStreaming(sdk, resume(head, seconds), { modelId, signal });
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await seconds.return(undefined);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function* segment(first, rest) {
|
|
112
|
+
yield first;
|
|
113
|
+
for (let n = 1; n < TRANSCRIBE_SEGMENT_SECONDS; n++) {
|
|
114
|
+
const next = await rest.next();
|
|
115
|
+
if (next.done) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
yield next.value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export async function transcribeStreaming(sdk, pcm, opts) {
|
|
122
|
+
const seconds = pcm[Symbol.asyncIterator]();
|
|
123
|
+
const parts = [];
|
|
124
|
+
try {
|
|
125
|
+
for (let first = await seconds.next(); !first.done; first = await seconds.next()) {
|
|
126
|
+
parts.push(await transcribeSession(sdk, segment(first.value, seconds), opts));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
await seconds.return?.();
|
|
131
|
+
}
|
|
132
|
+
return parts.filter(Boolean).join(' ');
|
|
133
|
+
}
|
|
134
|
+
async function transcribeSession(sdk, pcm, { modelId, signal }) {
|
|
59
135
|
const session = await sdk.transcribeStream({
|
|
60
136
|
modelId,
|
|
61
137
|
metadata: TRANSCRIBE_WITH_METADATA,
|
|
@@ -63,27 +139,20 @@ export async function transcribeStreaming(sdk, pcm, { modelId, signal }) {
|
|
|
63
139
|
});
|
|
64
140
|
const onAbort = () => session.destroy();
|
|
65
141
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
66
|
-
let lastPieceAt = 0;
|
|
67
|
-
let streamClosed = false;
|
|
68
142
|
const collect = (async () => {
|
|
69
143
|
let out = '';
|
|
70
144
|
for await (const piece of session) {
|
|
71
|
-
lastPieceAt = Date.now();
|
|
72
145
|
const seg = transcribePiece(piece);
|
|
73
146
|
if (!seg) {
|
|
74
147
|
continue;
|
|
75
148
|
}
|
|
76
149
|
out += !out || seg.append ? seg.text : ` ${seg.text}`;
|
|
77
150
|
}
|
|
78
|
-
streamClosed = true;
|
|
79
151
|
return out.replace(/\s+/g, ' ').trim();
|
|
80
152
|
})();
|
|
81
|
-
collect.catch(
|
|
82
|
-
streamClosed = true;
|
|
83
|
-
});
|
|
153
|
+
collect.catch(noop);
|
|
84
154
|
try {
|
|
85
155
|
await writePaced(session, pcm, signal);
|
|
86
|
-
await drainUntilIdle(() => lastPieceAt, () => streamClosed, signal);
|
|
87
156
|
if (!signal?.aborted) {
|
|
88
157
|
session.end();
|
|
89
158
|
}
|
|
@@ -118,7 +187,7 @@ export async function* speakStreamOnce(sdk, text, { modelId, engine = 'supertoni
|
|
|
118
187
|
session.end();
|
|
119
188
|
}
|
|
120
189
|
catch (err) {
|
|
121
|
-
|
|
190
|
+
HarnessLog.warn('tts stream input failed', { err: errorMessage(err) });
|
|
122
191
|
inputError = err;
|
|
123
192
|
destroyQuietly(session);
|
|
124
193
|
}
|
|
@@ -139,7 +208,7 @@ export async function* speakStreamOnce(sdk, text, { modelId, engine = 'supertoni
|
|
|
139
208
|
throw inputError;
|
|
140
209
|
}
|
|
141
210
|
if (wrotePronounceable && !yieldedAudio) {
|
|
142
|
-
throw new
|
|
211
|
+
throw new HarnessError('TTS_NO_AUDIO');
|
|
143
212
|
}
|
|
144
213
|
}
|
|
145
214
|
catch (err) {
|
|
@@ -167,7 +236,7 @@ function writeSpeakable(session, fragment, engine) {
|
|
|
167
236
|
export function speakable(text, engine = 'supertonic') {
|
|
168
237
|
const { text: spoken, dropped } = NORMALIZE[engine](text);
|
|
169
238
|
if (dropped.length) {
|
|
170
|
-
|
|
239
|
+
HarnessLog.info('tts dropped unspeakable characters', { chars: [...new Set(dropped)].join('') });
|
|
171
240
|
}
|
|
172
241
|
return spoken;
|
|
173
242
|
}
|
|
@@ -182,7 +251,7 @@ export async function speakOnce(sdk, text, { modelId, engine = 'supertonic' }) {
|
|
|
182
251
|
samples.push(sample);
|
|
183
252
|
}
|
|
184
253
|
if (!(await result.done)) {
|
|
185
|
-
throw new
|
|
254
|
+
throw new HarnessError('TTS_INCOMPLETE');
|
|
186
255
|
}
|
|
187
256
|
return {
|
|
188
257
|
audio: packSamples(samples),
|
|
@@ -13,6 +13,7 @@ export declare class TranslationPlugin implements HarnessPlugin {
|
|
|
13
13
|
static planFor(from: string, to: string): TranslationPlan | TranslationRefusal;
|
|
14
14
|
readonly name = "translation";
|
|
15
15
|
readonly api = 1;
|
|
16
|
+
readonly provides: string[];
|
|
16
17
|
readonly needs: string[];
|
|
17
18
|
readonly addons: {
|
|
18
19
|
translation: () => Promise<typeof import("@qvac/sdk/nmtcpp-translation/plugin")>;
|
|
@@ -3,18 +3,20 @@ import { raceAbort } from '../../lib/helpers/race-abort.js';
|
|
|
3
3
|
import { retryMemo } from '../../lib/helpers/retry-memo.js';
|
|
4
4
|
import { PluginRegistry } from '../../lib/plugins/index.js';
|
|
5
5
|
import { EURONANO_LANGUAGES, NMT_FROM_ENGLISH, NMT_TO_ENGLISH, SLM_LANGUAGE_CODES, SLM_LANGUAGE_NAMES, translationPlanFor } from './nmt-catalog.js';
|
|
6
|
-
import { createTranslateTool, createTranslationRuntime } from './translate.js';
|
|
6
|
+
import { createTranslate, createTranslateTool, createTranslationRuntime } from './translate.js';
|
|
7
7
|
function nmtSdk(models) {
|
|
8
8
|
return retryMemo(async () => {
|
|
9
9
|
const sdk = await models.sdk();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (typeof globalThis.Bare !== 'undefined') {
|
|
11
|
+
const [{ nmtPlugin }, { registerPlugin }] = await Promise.all([
|
|
12
|
+
import('@qvac/sdk/nmtcpp-translation/plugin'),
|
|
13
|
+
import('@qvac/sdk/plugins')
|
|
14
|
+
]);
|
|
15
|
+
try {
|
|
16
|
+
registerPlugin(nmtPlugin);
|
|
17
|
+
}
|
|
18
|
+
catch { }
|
|
16
19
|
}
|
|
17
|
-
catch { }
|
|
18
20
|
return sdk;
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -42,6 +44,7 @@ export class TranslationPlugin {
|
|
|
42
44
|
}
|
|
43
45
|
name = 'translation';
|
|
44
46
|
api = PluginRegistry.API_VERSION;
|
|
47
|
+
provides = ['translation'];
|
|
45
48
|
needs = ['models'];
|
|
46
49
|
addons = {
|
|
47
50
|
translation: () => import('@qvac/sdk/nmtcpp-translation/plugin'),
|
|
@@ -51,11 +54,15 @@ export class TranslationPlugin {
|
|
|
51
54
|
const models = ctx.service('models');
|
|
52
55
|
const runtime = createTranslationRuntime({
|
|
53
56
|
loads: models,
|
|
57
|
+
hold: models.hold,
|
|
54
58
|
loadSdk: nmtSdk(models),
|
|
55
59
|
onProgress: (model, progress) => models.emit(models.progressState(model, progress))
|
|
56
60
|
});
|
|
61
|
+
const options = { slm: slmTranslate(models) };
|
|
62
|
+
const translation = { translate: createTranslate(runtime, options) };
|
|
57
63
|
return {
|
|
58
|
-
capabilities: [createTranslateTool(runtime,
|
|
64
|
+
capabilities: [createTranslateTool(runtime, options)],
|
|
65
|
+
services: { translation },
|
|
59
66
|
unload: () => runtime.unload(),
|
|
60
67
|
unloadIdle: () => runtime.unloadIdle()
|
|
61
68
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
import type { ToolDefinition } from '../../lib/contract/index.ts';
|
|
3
3
|
import type { ModelHost, TrackedLoad } from '../../lib/contract/models.ts';
|
|
4
|
+
import type { TranslationService } from '../../lib/contract/translation.ts';
|
|
4
5
|
import type { ModelSrc } from '../../lib/models/context.ts';
|
|
6
|
+
import type { HoldFn } from '../../lib/contract/models.ts';
|
|
5
7
|
import { type ModelRegistrySdk } from '../../lib/models/model-source.ts';
|
|
6
8
|
import { type NmtPlan } from './nmt-catalog.ts';
|
|
7
9
|
interface BergamotConfig {
|
|
@@ -44,11 +46,11 @@ export type TranslationSdk = ModelRegistrySdk & {
|
|
|
44
46
|
};
|
|
45
47
|
};
|
|
46
48
|
export declare const TRANSLATION_LOAD_STALL_MS: number;
|
|
47
|
-
export declare const TRANSLATION_LOAD_STALL_ERROR = "translation model download stalled";
|
|
48
49
|
export interface TranslationRuntimeOptions {
|
|
49
50
|
loadSdk: () => Promise<TranslationSdk>;
|
|
50
51
|
loads?: Pick<ModelHost, 'track'>;
|
|
51
52
|
onProgress?: (model: string, progress: Record<string, unknown>) => void;
|
|
53
|
+
hold?: HoldFn;
|
|
52
54
|
stallMs?: number;
|
|
53
55
|
}
|
|
54
56
|
export interface TranslationRuntime {
|
|
@@ -61,7 +63,7 @@ export interface TranslationRuntime {
|
|
|
61
63
|
enter: (signal?: BareAbortSignal) => Promise<void>;
|
|
62
64
|
exit: () => void;
|
|
63
65
|
}
|
|
64
|
-
export declare function createTranslationRuntime({ loadSdk, loads, onProgress, stallMs }: TranslationRuntimeOptions): TranslationRuntime;
|
|
66
|
+
export declare function createTranslationRuntime({ loadSdk, loads, onProgress, hold, stallMs }: TranslationRuntimeOptions): TranslationRuntime;
|
|
65
67
|
export type SlmTranslateFn = (model: string, params: {
|
|
66
68
|
text: string;
|
|
67
69
|
from: string;
|
|
@@ -81,5 +83,7 @@ export declare function sourceLanguage(text: string, from?: string): string | Tr
|
|
|
81
83
|
export interface TranslateToolOptions {
|
|
82
84
|
slm?: SlmTranslateFn;
|
|
83
85
|
}
|
|
84
|
-
export
|
|
86
|
+
export type TranslateFn = TranslationService['translate'];
|
|
87
|
+
export declare function createTranslate(runtime: TranslationRuntime, { slm }?: TranslateToolOptions): TranslateFn;
|
|
88
|
+
export declare function createTranslateTool(runtime: TranslationRuntime, options?: TranslateToolOptions): ToolDefinition;
|
|
85
89
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import ScopeLock from 'scope-lock';
|
|
2
2
|
import { getLangName } from '@qvac/langdetect-text';
|
|
3
3
|
import { detectLanguage, UNDETERMINED } from '../../lib/capabilities/detect-language.js';
|
|
4
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
4
5
|
import { createLoadStall } from '../../lib/helpers/load-stall.js';
|
|
5
6
|
import { AbortedError, raceAbort } from '../../lib/helpers/race-abort.js';
|
|
6
7
|
import { resolveModelSrc } from '../../lib/models/model-source.js';
|
|
7
8
|
import { ENGLISH, NMT_FROM_ENGLISH, NMT_TO_ENGLISH, languageLabel, SLM_LANGUAGE_CODES, sameLanguage, translationPlanFor } from './nmt-catalog.js';
|
|
8
9
|
export const TRANSLATION_LOAD_STALL_MS = 15 * 60_000;
|
|
9
|
-
export const TRANSLATION_LOAD_STALL_ERROR = 'translation model download stalled';
|
|
10
10
|
function packName(plan) {
|
|
11
11
|
const pair = plan.model.match(/model\.([a-z]+)\.intgemm/)?.[1];
|
|
12
12
|
if (pair) {
|
|
@@ -25,7 +25,7 @@ function bergamotConfig(plan) {
|
|
|
25
25
|
}
|
|
26
26
|
return config;
|
|
27
27
|
}
|
|
28
|
-
export function createTranslationRuntime({ loadSdk, loads = { track: (pending) => pending }, onProgress, stallMs = TRANSLATION_LOAD_STALL_MS }) {
|
|
28
|
+
export function createTranslationRuntime({ loadSdk, loads = { track: (pending) => pending }, onProgress, hold, stallMs = TRANSLATION_LOAD_STALL_MS }) {
|
|
29
29
|
let loading = null;
|
|
30
30
|
let residentFingerprint = null;
|
|
31
31
|
let inFlight = 0;
|
|
@@ -38,7 +38,7 @@ export function createTranslationRuntime({ loadSdk, loads = { track: (pending) =
|
|
|
38
38
|
modelConfig.pivotModel = { modelSrc: await resolveModelSrc(sdk, plan.pivot, 'nmt') };
|
|
39
39
|
}
|
|
40
40
|
const name = packName(plan);
|
|
41
|
-
const stall = createLoadStall(stallMs,
|
|
41
|
+
const stall = createLoadStall(stallMs, () => new HarnessError('TRANSLATION_LOAD_STALLED'));
|
|
42
42
|
onProgress?.(name, {});
|
|
43
43
|
const pending = sdk.loadModel({
|
|
44
44
|
modelSrc,
|
|
@@ -54,9 +54,7 @@ export function createTranslationRuntime({ loadSdk, loads = { track: (pending) =
|
|
|
54
54
|
return { modelId };
|
|
55
55
|
}
|
|
56
56
|
catch (err) {
|
|
57
|
-
if (err
|
|
58
|
-
err.message === TRANSLATION_LOAD_STALL_ERROR &&
|
|
59
|
-
pending.requestId) {
|
|
57
|
+
if (HarnessError.is(err, 'TRANSLATION_LOAD_STALLED') && pending.requestId) {
|
|
60
58
|
void sdk.cancel?.({ requestId: pending.requestId }).catch(noop);
|
|
61
59
|
}
|
|
62
60
|
throw err;
|
|
@@ -95,6 +93,11 @@ export function createTranslationRuntime({ loadSdk, loads = { track: (pending) =
|
|
|
95
93
|
loadSdk,
|
|
96
94
|
ensureLoaded: async (sdk, plan, signal) => {
|
|
97
95
|
const fingerprint = fingerprintOf(plan);
|
|
96
|
+
if (hold && !(loading && residentFingerprint === fingerprint)) {
|
|
97
|
+
for (const model of plan.pivot ? [plan.model, plan.pivot] : [plan.model]) {
|
|
98
|
+
await hold(model, 'nmt', signal);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
98
101
|
await lock.lock();
|
|
99
102
|
try {
|
|
100
103
|
if (loading && residentFingerprint !== fingerprint) {
|
|
@@ -163,7 +166,60 @@ export function sourceLanguage(text, from) {
|
|
|
163
166
|
return code;
|
|
164
167
|
}
|
|
165
168
|
const NEEDS_SOURCE = 'could not detect the source language; pass `from` explicitly';
|
|
166
|
-
export function
|
|
169
|
+
export function createTranslate(runtime, { slm } = {}) {
|
|
170
|
+
return async (request, signal) => {
|
|
171
|
+
const from = sourceLanguage(request.text, request.from);
|
|
172
|
+
if (typeof from === 'object') {
|
|
173
|
+
return from;
|
|
174
|
+
}
|
|
175
|
+
if (sameLanguage(from, request.to)) {
|
|
176
|
+
return { text: request.text, from, to: request.to, engine: 'none' };
|
|
177
|
+
}
|
|
178
|
+
const plan = translationPlanFor(from, request.to);
|
|
179
|
+
if ('error' in plan) {
|
|
180
|
+
return plan;
|
|
181
|
+
}
|
|
182
|
+
if (plan.route === 'slm' && !slm) {
|
|
183
|
+
return { error: `this device cannot translate ${from} to ${request.to}` };
|
|
184
|
+
}
|
|
185
|
+
let entered = false;
|
|
186
|
+
try {
|
|
187
|
+
await runtime.enter(signal);
|
|
188
|
+
entered = true;
|
|
189
|
+
if (plan.route === 'slm') {
|
|
190
|
+
if (!slm) {
|
|
191
|
+
throw new HarnessError('SLM_TRANSLATION_UNAVAILABLE');
|
|
192
|
+
}
|
|
193
|
+
const text = await slm(plan.model, { text: request.text, from: plan.from, to: plan.to }, signal);
|
|
194
|
+
return {
|
|
195
|
+
text: stripLanguageLabel(text, plan.from, plan.to),
|
|
196
|
+
from,
|
|
197
|
+
to: request.to,
|
|
198
|
+
engine: 'slm',
|
|
199
|
+
model: plan.model
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const sdk = await runtime.loadSdk();
|
|
203
|
+
const { modelId } = await runtime.ensureLoaded(sdk, plan, signal);
|
|
204
|
+
const source = plan.tag ? `${plan.tag} ${request.text}` : request.text;
|
|
205
|
+
const text = await raceAbort(sdk.translate({ modelId, text: source, stream: false, modelType: 'nmt' }).text, signal);
|
|
206
|
+
return { text, from, to: request.to, engine: 'nmt', pivoted: Boolean(plan.pivot) };
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (err instanceof AbortedError) {
|
|
210
|
+
return { error: 'translation canceled' };
|
|
211
|
+
}
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
if (entered) {
|
|
216
|
+
runtime.exit();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
export function createTranslateTool(runtime, options = {}) {
|
|
222
|
+
const translate = createTranslate(runtime, options);
|
|
167
223
|
return {
|
|
168
224
|
name: 'translate',
|
|
169
225
|
toolset: null,
|
|
@@ -194,57 +250,7 @@ export function createTranslateTool(runtime, { slm } = {}) {
|
|
|
194
250
|
resource: (args) => ({ kind: 'translation', label: String(args.to ?? '') }),
|
|
195
251
|
execute: async (args, ctx) => {
|
|
196
252
|
const parsed = parseTranslateArgs(args);
|
|
197
|
-
|
|
198
|
-
return parsed;
|
|
199
|
-
}
|
|
200
|
-
const from = sourceLanguage(parsed.text, parsed.from);
|
|
201
|
-
if (typeof from === 'object') {
|
|
202
|
-
return from;
|
|
203
|
-
}
|
|
204
|
-
if (sameLanguage(from, parsed.to)) {
|
|
205
|
-
return { text: parsed.text, from, to: parsed.to, engine: 'none' };
|
|
206
|
-
}
|
|
207
|
-
const plan = translationPlanFor(from, parsed.to);
|
|
208
|
-
if ('error' in plan) {
|
|
209
|
-
return plan;
|
|
210
|
-
}
|
|
211
|
-
if (plan.route === 'slm' && !slm) {
|
|
212
|
-
return { error: `this device cannot translate ${from} to ${parsed.to}` };
|
|
213
|
-
}
|
|
214
|
-
let entered = false;
|
|
215
|
-
try {
|
|
216
|
-
await runtime.enter(ctx?.signal);
|
|
217
|
-
entered = true;
|
|
218
|
-
if (plan.route === 'slm') {
|
|
219
|
-
if (!slm) {
|
|
220
|
-
throw new Error('slm translation is unavailable');
|
|
221
|
-
}
|
|
222
|
-
const text = await slm(plan.model, { text: parsed.text, from: plan.from, to: plan.to }, ctx?.signal);
|
|
223
|
-
return {
|
|
224
|
-
text: stripLanguageLabel(text, plan.from, plan.to),
|
|
225
|
-
from,
|
|
226
|
-
to: parsed.to,
|
|
227
|
-
engine: 'slm',
|
|
228
|
-
model: plan.model
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
const sdk = await runtime.loadSdk();
|
|
232
|
-
const { modelId } = await runtime.ensureLoaded(sdk, plan, ctx?.signal);
|
|
233
|
-
const source = plan.tag ? `${plan.tag} ${parsed.text}` : parsed.text;
|
|
234
|
-
const text = await raceAbort(sdk.translate({ modelId, text: source, stream: false, modelType: 'nmt' }).text, ctx?.signal);
|
|
235
|
-
return { text, from, to: parsed.to, engine: 'nmt', pivoted: Boolean(plan.pivot) };
|
|
236
|
-
}
|
|
237
|
-
catch (err) {
|
|
238
|
-
if (err instanceof AbortedError) {
|
|
239
|
-
return { error: 'translation canceled' };
|
|
240
|
-
}
|
|
241
|
-
throw err;
|
|
242
|
-
}
|
|
243
|
-
finally {
|
|
244
|
-
if (entered) {
|
|
245
|
-
runtime.exit();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
253
|
+
return 'error' in parsed ? parsed : translate(parsed, ctx?.signal);
|
|
248
254
|
}
|
|
249
255
|
};
|
|
250
256
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
3
4
|
import { checkQualifier, describePlace, fold } from './place.js';
|
|
4
5
|
export const GEOCODER_HOST = 'geocoding-api.open-meteo.com';
|
|
5
6
|
export const GEOCODE_TIMEOUT_MS = 5_000;
|
|
@@ -48,7 +49,7 @@ async function search(city, { fetch }, signal) {
|
|
|
48
49
|
redirect: 'manual'
|
|
49
50
|
});
|
|
50
51
|
if (response.status !== 200) {
|
|
51
|
-
throw new
|
|
52
|
+
throw new HarnessError('GEOCODER_HTTP_STATUS', [response.status]);
|
|
52
53
|
}
|
|
53
54
|
const { results = [] } = GeocodeSchema.parse(JSON.parse(await response.text()));
|
|
54
55
|
return results.map((result) => ({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
2
3
|
import { errorMessage } from '../../lib/guards.js';
|
|
3
4
|
import { choose, geocode, GEOCODE_TIMEOUT_MS, GEOCODER_HOST, geocoderUrl } from './geocode.js';
|
|
4
5
|
import { checkQualifier, cityMatches, describePlace, qualifierOf } from './place.js';
|
|
@@ -42,6 +43,7 @@ export function createWeatherLookupTool({ geocodeTimeoutMs = GEOCODE_TIMEOUT_MS
|
|
|
42
43
|
required: ['location']
|
|
43
44
|
},
|
|
44
45
|
effect: () => 'read',
|
|
46
|
+
stableRead: true,
|
|
45
47
|
resource: () => ({ kind: 'host', label: `${GEOCODER_HOST}, ${WEATHER_HOST}` }),
|
|
46
48
|
egress,
|
|
47
49
|
execute: (args, ctx) => execute(args.location, {
|
|
@@ -149,11 +151,10 @@ function failure(err, signal, callerSignal) {
|
|
|
149
151
|
if (signal.aborted) {
|
|
150
152
|
return { error: `weather_lookup timed out after ${LOOKUP_TIMEOUT_MS} ms`, code: 'timeout' };
|
|
151
153
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return { error: message };
|
|
154
|
+
if (HarnessError.is(err, 'FETCH_REFUSED')) {
|
|
155
|
+
return { error: errorMessage(err) };
|
|
155
156
|
}
|
|
156
|
-
return { error: unavailable(
|
|
157
|
+
return { error: unavailable(errorMessage(err)), code: 'transport' };
|
|
157
158
|
}
|
|
158
159
|
function unavailable(reason) {
|
|
159
160
|
return `The weather service could not be reached: ${reason}.`;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HarnessError } from '../../../lib/errors.js';
|
|
1
2
|
import { fetchHtml } from '../fetch-html.js';
|
|
2
3
|
import { clean } from '../../../lib/helpers/html-helpers.js';
|
|
3
4
|
import { urlMatchesHost } from '../url-helpers.js';
|
|
@@ -106,7 +107,7 @@ export async function searchBing(query, fetcher, signal) {
|
|
|
106
107
|
signal
|
|
107
108
|
});
|
|
108
109
|
if (html.includes('captcha') || html.includes('challenge/verify') || html.includes('Turnstile')) {
|
|
109
|
-
throw new
|
|
110
|
+
throw new HarnessError('SEARCH_CAPTCHA', ['Bing']);
|
|
110
111
|
}
|
|
111
112
|
const primary = parseBAlgoBlocks(html);
|
|
112
113
|
if (primary.length > 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HarnessError } from '../../../lib/errors.js';
|
|
1
2
|
import { fetchHtml } from '../fetch-html.js';
|
|
2
3
|
import { clean } from '../../../lib/helpers/html-helpers.js';
|
|
3
4
|
import { urlMatchesHost } from '../url-helpers.js';
|
|
@@ -88,7 +89,7 @@ export async function searchGoogle(query, fetcher, signal) {
|
|
|
88
89
|
signal
|
|
89
90
|
});
|
|
90
91
|
if (html.includes('detected unusual traffic') || html.includes('g-recaptcha')) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new HarnessError('SEARCH_CAPTCHA', ['Google']);
|
|
92
93
|
}
|
|
93
94
|
const primary = parseDataVedAnchors(html);
|
|
94
95
|
if (primary.length > 0) {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
|
+
import { HarnessError } from '../../lib/errors.ts';
|
|
2
3
|
import type { Fetcher } from './types.ts';
|
|
3
4
|
export declare const ENGINE_TIMEOUT_MS = 8000;
|
|
4
5
|
export declare const MAX_HTML_CHARS = 2000000;
|
|
5
|
-
export declare class TimeoutError extends
|
|
6
|
+
export declare class TimeoutError extends HarnessError<'FETCH_TIMED_OUT'> {
|
|
6
7
|
constructor(ms: number);
|
|
7
8
|
}
|
|
8
|
-
export declare class AbortError extends
|
|
9
|
+
export declare class AbortError extends HarnessError<'FETCH_CANCELLED'> {
|
|
9
10
|
constructor();
|
|
10
11
|
}
|
|
11
12
|
interface FetchOptions {
|
|
@@ -18,9 +19,8 @@ interface FetchOptions {
|
|
|
18
19
|
readonly signal?: BareAbortSignal;
|
|
19
20
|
}
|
|
20
21
|
export declare function fetchHtml(fetcher: Fetcher, url: string, options?: FetchOptions): Promise<string>;
|
|
21
|
-
export declare class JsonParseError extends
|
|
22
|
-
|
|
23
|
-
constructor(message: string, cause?: unknown);
|
|
22
|
+
export declare class JsonParseError extends HarnessError<'RESPONSE_NOT_JSON'> {
|
|
23
|
+
constructor(chars: number, cause: unknown);
|
|
24
24
|
}
|
|
25
25
|
export declare function fetchJson(fetcher: Fetcher, url: string, options?: FetchOptions): Promise<unknown>;
|
|
26
26
|
export {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
|
+
import { errorMessage } from '../../lib/guards.js';
|
|
3
|
+
import { HarnessError } from '../../lib/errors.js';
|
|
2
4
|
import { BROWSER_UA } from '../../lib/helpers/user-agents.js';
|
|
3
5
|
export const ENGINE_TIMEOUT_MS = 8000;
|
|
4
6
|
export const MAX_HTML_CHARS = 2_000_000;
|
|
5
|
-
export class TimeoutError extends
|
|
7
|
+
export class TimeoutError extends HarnessError {
|
|
6
8
|
constructor(ms) {
|
|
7
|
-
super(
|
|
8
|
-
this.name = 'TimeoutError';
|
|
9
|
+
super('FETCH_TIMED_OUT', [ms]);
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
export class AbortError extends
|
|
12
|
+
export class AbortError extends HarnessError {
|
|
12
13
|
constructor() {
|
|
13
|
-
super('
|
|
14
|
-
this.name = 'AbortError';
|
|
14
|
+
super('FETCH_CANCELLED');
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function buildInit(options, signal) {
|
|
@@ -74,16 +74,13 @@ async function fetchWithTimeout(fetcher, url, options) {
|
|
|
74
74
|
export async function fetchHtml(fetcher, url, options) {
|
|
75
75
|
const { ok, status, text } = await fetchWithTimeout(fetcher, url, options);
|
|
76
76
|
if (!ok) {
|
|
77
|
-
throw new
|
|
77
|
+
throw new HarnessError('HTTP_STATUS', [status]);
|
|
78
78
|
}
|
|
79
79
|
return text;
|
|
80
80
|
}
|
|
81
|
-
export class JsonParseError extends
|
|
82
|
-
cause
|
|
83
|
-
|
|
84
|
-
super(message);
|
|
85
|
-
this.cause = cause;
|
|
86
|
-
this.name = 'JsonParseError';
|
|
81
|
+
export class JsonParseError extends HarnessError {
|
|
82
|
+
constructor(chars, cause) {
|
|
83
|
+
super('RESPONSE_NOT_JSON', [chars, errorMessage(cause)], { cause });
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
86
|
export async function fetchJson(fetcher, url, options) {
|
|
@@ -92,12 +89,12 @@ export async function fetchJson(fetcher, url, options) {
|
|
|
92
89
|
accept: options?.accept ?? 'application/json'
|
|
93
90
|
});
|
|
94
91
|
if (!ok) {
|
|
95
|
-
throw new
|
|
92
|
+
throw new HarnessError('HTTP_STATUS', [status]);
|
|
96
93
|
}
|
|
97
94
|
try {
|
|
98
95
|
return JSON.parse(text);
|
|
99
96
|
}
|
|
100
97
|
catch (err) {
|
|
101
|
-
throw new JsonParseError(
|
|
98
|
+
throw new JsonParseError(text.length, err);
|
|
102
99
|
}
|
|
103
100
|
}
|
|
@@ -30,6 +30,7 @@ export function createWebSearchTool(engines, maxResults) {
|
|
|
30
30
|
? engines.map((engine) => engine.url(query))
|
|
31
31
|
: null;
|
|
32
32
|
},
|
|
33
|
+
stableRead: true,
|
|
33
34
|
async execute(args, ctx) {
|
|
34
35
|
const query = args.query;
|
|
35
36
|
if (typeof query !== 'string' || query.trim().length === 0) {
|