@qvac/harness 1.0.0-rc.0 → 1.0.0-rc.10
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 +2638 -397
- package/NOTICE.md +16 -0
- package/README.md +303 -471
- package/dist-lib/index.d.ts +151 -172
- package/dist-lib/index.js +573 -1513
- package/dist-lib/lib/addon-seal.bare.d.ts +1 -0
- package/dist-lib/lib/addon-seal.bare.js +3 -0
- package/dist-lib/lib/addon-seal.node.d.ts +1 -0
- package/dist-lib/lib/addon-seal.node.js +1 -0
- package/dist-lib/lib/agent/delegate.d.ts +84 -0
- package/dist-lib/lib/agent/delegate.js +263 -0
- package/dist-lib/lib/agent/follow.d.ts +37 -0
- package/dist-lib/lib/agent/follow.js +164 -0
- package/dist-lib/lib/agent/index.d.ts +37 -0
- package/dist-lib/lib/agent/index.js +42 -0
- package/dist-lib/lib/agent/plan.d.ts +6 -0
- package/dist-lib/lib/agent/plan.js +74 -0
- package/dist-lib/lib/agent/resolve.d.ts +3 -0
- package/dist-lib/lib/agent/resolve.js +83 -0
- package/dist-lib/lib/{capabilities → agent}/tool-names.d.ts +0 -1
- package/dist-lib/lib/{capabilities → agent}/tool-names.js +0 -1
- package/dist-lib/lib/{capabilities → agent}/tool-selection.d.ts +7 -8
- package/dist-lib/lib/{capabilities → agent}/tool-selection.js +14 -7
- package/dist-lib/lib/agent/tools.d.ts +15 -0
- package/dist-lib/lib/agent/tools.js +17 -0
- package/dist-lib/lib/agent/transfer.d.ts +7 -0
- package/dist-lib/lib/agent/transfer.js +26 -0
- package/dist-lib/lib/capabilities/agent-ports.d.ts +3 -0
- package/dist-lib/lib/capabilities/agent-ports.js +9 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +25 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/batching.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/batching.js +91 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +16 -5
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.js +8 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +29 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +160 -40
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.d.ts +11 -10
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +29 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/finishing.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +68 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +10 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +59 -17
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +7 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +40 -32
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.d.ts +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +170 -120
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +30 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.d.ts +4 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.js +8 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +129 -19
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +10 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +65 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +74 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +95 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +9 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +55 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +6 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +138 -35
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +52 -17
- package/dist-lib/lib/capabilities/completion-engine/actors.d.ts +11 -0
- package/dist-lib/lib/capabilities/completion-engine/actors.js +216 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +12 -5
- package/dist-lib/lib/capabilities/completion-engine/driver.js +141 -37
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +11 -5
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +68 -0
- package/dist-lib/lib/{machine → capabilities/completion-engine}/engine.js +80 -130
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +34 -0
- package/dist-lib/lib/capabilities/completion-engine/index.js +47 -0
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +73 -0
- package/dist-lib/lib/capabilities/completion-engine/loop.js +69 -0
- package/dist-lib/lib/capabilities/completion-engine/metrics.d.ts +11 -0
- package/dist-lib/lib/capabilities/completion-engine/metrics.js +67 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +60 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +97 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.d.ts +5 -2
- package/dist-lib/lib/capabilities/completion-engine/operations.js +84 -15
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +25 -2
- package/dist-lib/lib/capabilities/completion-engine/ports.js +26 -21
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +26 -0
- package/dist-lib/lib/{machine → capabilities/completion-engine}/replay-output.d.ts +1 -1
- package/dist-lib/lib/{machine → capabilities/completion-engine}/replay-output.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +73 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +813 -0
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +28 -14
- package/dist-lib/lib/capabilities/completion-engine/session.js +40 -6
- package/dist-lib/lib/capabilities/completion-engine/splice.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/splice.js +7 -0
- package/dist-lib/lib/capabilities/completion-engine/stages.d.ts +23 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.d.ts +10 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +152 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +78 -0
- package/dist-lib/lib/capabilities/{completion-loop → completion-engine}/tool-execution.js +88 -34
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.d.ts +24 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-sets.js +15 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +32 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +212 -0
- package/dist-lib/lib/capabilities/detect-language.d.ts +2 -1
- package/dist-lib/lib/capabilities/detect-language.js +14 -2
- package/dist-lib/lib/capabilities/download.d.ts +10 -8
- package/dist-lib/lib/capabilities/download.js +1 -1
- package/dist-lib/lib/capabilities/enhance.d.ts +2 -2
- package/dist-lib/lib/capabilities/enhance.js +23 -10
- package/dist-lib/lib/capabilities/invoke.d.ts +1 -1
- package/dist-lib/lib/capabilities/kv-cache.d.ts +1 -1
- package/dist-lib/lib/capabilities/preview-model-source.d.ts +8 -10
- package/dist-lib/lib/capabilities/preview-model-source.js +83 -21
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +1 -1
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +19 -0
- package/dist-lib/lib/capabilities/sdk-tool.js +166 -0
- package/dist-lib/lib/capabilities/skill-entry.d.ts +8 -0
- package/dist-lib/lib/capabilities/skill-entry.js +14 -0
- package/dist-lib/lib/capabilities/tool-plan.d.ts +11 -6
- package/dist-lib/lib/capabilities/tool-plan.js +36 -15
- package/dist-lib/lib/capabilities/tool-prompt-log.d.ts +1 -1
- package/dist-lib/lib/capabilities/tool-prompt-log.js +3 -3
- package/dist-lib/lib/capabilities/tool-turns.d.ts +30 -5
- package/dist-lib/lib/capabilities/tool-turns.js +137 -18
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -1
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- 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 +21 -10
- package/dist-lib/lib/connect.js +290 -84
- package/dist-lib/lib/context-window.d.ts +5 -2
- package/dist-lib/lib/context-window.js +27 -16
- package/dist-lib/lib/contract/agent.d.ts +69 -0
- package/dist-lib/lib/{capabilities/types.d.ts → contract/completion.d.ts} +181 -46
- package/dist-lib/lib/contract/drive.d.ts +4 -0
- package/dist-lib/lib/contract/egress-proxy.d.ts +13 -0
- package/dist-lib/lib/contract/exec.d.ts +134 -0
- package/dist-lib/lib/contract/hooks.d.ts +124 -0
- package/dist-lib/lib/contract/hooks.js +1 -0
- package/dist-lib/lib/contract/index.d.ts +8 -0
- package/dist-lib/lib/contract/index.js +1 -0
- package/dist-lib/lib/contract/knowledge.d.ts +60 -0
- package/dist-lib/lib/contract/knowledge.js +1 -0
- package/dist-lib/lib/contract/managed-skills.d.ts +1 -0
- package/dist-lib/lib/contract/managed-skills.js +1 -0
- package/dist-lib/lib/contract/models.d.ts +58 -0
- package/dist-lib/lib/contract/models.js +1 -0
- 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 +156 -0
- package/dist-lib/lib/contract/run.js +1 -0
- package/dist-lib/lib/contract/sandbox.d.ts +31 -0
- package/dist-lib/lib/contract/sandbox.js +1 -0
- package/dist-lib/lib/contract/skill-readiness.d.ts +14 -0
- package/dist-lib/lib/contract/skill-readiness.js +1 -0
- package/dist-lib/lib/{capabilities/voice.d.ts → contract/speech.d.ts} +12 -17
- package/dist-lib/lib/contract/speech.js +1 -0
- 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 +82 -30
- package/dist-lib/lib/docx/index.d.ts +0 -1
- package/dist-lib/lib/docx/index.js +15 -24
- package/dist-lib/lib/embeddings/index.d.ts +69 -0
- package/dist-lib/lib/embeddings/index.js +288 -0
- package/dist-lib/lib/errors.d.ts +270 -0
- package/dist-lib/lib/errors.js +204 -0
- package/dist-lib/lib/fold/index.d.ts +74 -0
- package/dist-lib/lib/fold/index.js +189 -0
- package/dist-lib/lib/{tools/exec/adapters/python/guarded-fetch.d.ts → guarded-fetch.d.ts} +5 -12
- package/dist-lib/lib/{tools/exec/adapters/python/guarded-fetch.js → guarded-fetch.js} +23 -41
- package/dist-lib/lib/hardware/cpu-placement.d.ts +8 -0
- package/dist-lib/lib/hardware/cpu-placement.js +48 -0
- package/dist-lib/lib/hardware/gpu-probe.js +10 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +7 -0
- package/dist-lib/lib/helpers/completion-params.js +21 -0
- package/dist-lib/lib/helpers/copy.d.ts +1 -0
- package/dist-lib/lib/helpers/copy.js +5 -0
- package/dist-lib/lib/helpers/drain.d.ts +5 -0
- package/dist-lib/lib/helpers/drain.js +19 -0
- package/dist-lib/lib/{machine/errors.d.ts → helpers/engine-error.d.ts} +8 -10
- package/dist-lib/lib/{machine/errors.js → helpers/engine-error.js} +20 -36
- package/dist-lib/lib/helpers/failure-result.d.ts +21 -0
- package/dist-lib/lib/helpers/failure-result.js +39 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +6 -0
- package/dist-lib/lib/helpers/goal-check.js +99 -0
- package/dist-lib/lib/helpers/head-tail.d.ts +7 -0
- package/dist-lib/lib/helpers/head-tail.js +19 -0
- package/dist-lib/lib/helpers/image-settings.d.ts +2 -0
- package/dist-lib/lib/helpers/image-settings.js +19 -0
- 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/mcp-methods.d.ts +2 -0
- package/dist-lib/lib/helpers/mcp-methods.js +14 -0
- package/dist-lib/lib/helpers/race-abort.d.ts +1 -1
- package/dist-lib/lib/helpers/race-abort.js +1 -1
- package/dist-lib/lib/helpers/repeated-reply.d.ts +2 -0
- package/dist-lib/lib/helpers/repeated-reply.js +71 -0
- package/dist-lib/lib/helpers/require-peers.d.ts +3 -0
- package/dist-lib/lib/helpers/require-peers.js +23 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +5 -4
- package/dist-lib/lib/helpers/run-outcome.js +11 -9
- package/dist-lib/lib/{machine → helpers}/stable-stringify.js +1 -1
- package/dist-lib/lib/helpers/thinking.d.ts +3 -2
- package/dist-lib/lib/helpers/thinking.js +19 -0
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +1 -0
- package/dist-lib/lib/helpers/tool-call-markup.js +9 -5
- package/dist-lib/lib/helpers/tool-label.d.ts +2 -2
- package/dist-lib/lib/helpers/tool-label.js +3 -3
- package/dist-lib/lib/hooks/built-in/arg-repair.d.ts +1 -1
- package/dist-lib/lib/hooks/built-in/arg-repair.js +114 -20
- package/dist-lib/lib/hooks/built-in/egress.d.ts +1 -1
- package/dist-lib/lib/hooks/built-in/egress.js +13 -21
- 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.d.ts +1 -1
- package/dist-lib/lib/hooks/built-in/sandbox.js +23 -5
- package/dist-lib/lib/hooks/built-in/skill-catalog.d.ts +1 -1
- package/dist-lib/lib/hooks/index.d.ts +51 -0
- package/dist-lib/lib/hooks/index.js +135 -0
- package/dist-lib/lib/hooks/run.d.ts +9 -6
- package/dist-lib/lib/hooks/run.js +115 -50
- package/dist-lib/lib/{completion-lifecycle.d.ts → lifecycle/completion-run.d.ts} +1 -1
- package/dist-lib/lib/{completion-lifecycle.js → lifecycle/completion-run.js} +1 -1
- package/dist-lib/lib/lifecycle/index.d.ts +83 -0
- package/dist-lib/lib/lifecycle/index.js +336 -0
- package/dist-lib/lib/{harness-lifecycle.js → lifecycle/machine.js} +3 -3
- 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 +15 -4
- package/dist-lib/lib/machine/completion/actions/completion.js +189 -20
- package/dist-lib/lib/machine/completion/actions/prepare.d.ts +9 -0
- package/dist-lib/lib/machine/completion/actions/prepare.js +30 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +10 -1
- package/dist-lib/lib/machine/completion/actions/tools.js +137 -10
- package/dist-lib/lib/machine/completion/context.d.ts +7 -2
- package/dist-lib/lib/machine/completion/context.js +34 -5
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -0
- package/dist-lib/lib/machine/completion/guards/retry.js +13 -4
- package/dist-lib/lib/machine/completion/implementations.d.ts +46 -14
- package/dist-lib/lib/machine/completion/implementations.js +115 -32
- package/dist-lib/lib/machine/completion/machine.d.ts +162 -65
- package/dist-lib/lib/machine/completion/machine.js +225 -60
- package/dist-lib/lib/machine/completion/ports.d.ts +7 -55
- package/dist-lib/lib/machine/completion/ports.js +1 -224
- package/dist-lib/lib/machine/completion/rules.d.ts +35 -19
- package/dist-lib/lib/machine/completion/rules.js +115 -49
- package/dist-lib/lib/machine/completion/types.d.ts +155 -187
- package/dist-lib/lib/machine/completion/version.d.ts +1 -0
- package/dist-lib/lib/machine/completion/version.js +1 -0
- package/dist-lib/lib/machine/definition.d.ts +23 -0
- package/dist-lib/lib/machine/definition.js +76 -0
- package/dist-lib/lib/machine/index.d.ts +488 -20
- package/dist-lib/lib/machine/index.js +20 -11
- 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/context.d.ts +1 -1
- 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 +7 -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-constants.d.ts +3 -1
- package/dist-lib/lib/models/model-catalog-constants.js +9 -1
- package/dist-lib/lib/models/model-catalog.d.ts +34 -5
- package/dist-lib/lib/models/model-catalog.js +104 -8
- package/dist-lib/lib/models/model-delete.d.ts +1 -1
- package/dist-lib/lib/models/model-fit.d.ts +55 -0
- package/dist-lib/lib/models/model-fit.js +101 -0
- package/dist-lib/lib/models/model-handle.d.ts +11 -1
- package/dist-lib/lib/models/model-handle.js +20 -2
- package/dist-lib/lib/models/model-list.d.ts +13 -2
- package/dist-lib/lib/models/model-list.js +23 -0
- package/dist-lib/lib/models/model-pool.d.ts +74 -15
- package/dist-lib/lib/models/model-pool.js +180 -50
- package/dist-lib/lib/models/model-source.d.ts +3 -2
- package/dist-lib/lib/models/model-source.js +23 -5
- package/dist-lib/lib/models/music-catalog.d.ts +1 -1
- package/dist-lib/lib/models/music-catalog.js +8 -1
- package/dist-lib/lib/models/opencl-cache.js +2 -2
- package/dist-lib/lib/models/sdk-faults.d.ts +3 -0
- package/dist-lib/lib/models/sdk-faults.js +27 -0
- package/dist-lib/lib/models/tool-dialect.d.ts +1 -1
- package/dist-lib/lib/models/tts-model-default.js +3 -3
- 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/codes.d.ts +62 -0
- package/dist-lib/lib/office/engine/codes.js +61 -0
- package/dist-lib/lib/office/engine/docx/document.d.ts +216 -0
- package/dist-lib/lib/office/engine/docx/document.js +1152 -0
- package/dist-lib/lib/office/engine/docx/index.d.ts +7 -0
- package/dist-lib/lib/office/engine/docx/index.js +8 -0
- package/dist-lib/lib/office/engine/docx/styles.d.ts +31 -0
- package/dist-lib/lib/office/engine/docx/styles.js +173 -0
- package/dist-lib/lib/office/engine/docx/template.d.ts +18 -0
- package/dist-lib/lib/office/engine/docx/template.js +133 -0
- package/dist-lib/lib/office/engine/docx/text.d.ts +55 -0
- package/dist-lib/lib/office/engine/docx/text.js +538 -0
- package/dist-lib/lib/office/engine/drawingml/chart.d.ts +63 -0
- package/dist-lib/lib/office/engine/drawingml/chart.js +539 -0
- package/dist-lib/lib/office/engine/drawingml/text.d.ts +35 -0
- package/dist-lib/lib/office/engine/drawingml/text.js +352 -0
- package/dist-lib/lib/office/engine/errors.d.ts +6 -0
- package/dist-lib/lib/office/engine/errors.js +12 -0
- package/dist-lib/lib/office/engine/image.d.ts +8 -0
- package/dist-lib/lib/office/engine/image.js +48 -0
- package/dist-lib/lib/office/engine/index.d.ts +12 -0
- package/dist-lib/lib/office/engine/index.js +7 -0
- package/dist-lib/lib/office/engine/opc/content-types.d.ts +17 -0
- package/dist-lib/lib/office/engine/opc/content-types.js +74 -0
- package/dist-lib/lib/office/engine/opc/media.d.ts +13 -0
- package/dist-lib/lib/office/engine/opc/media.js +11 -0
- package/dist-lib/lib/office/engine/opc/package.d.ts +51 -0
- package/dist-lib/lib/office/engine/opc/package.js +324 -0
- package/dist-lib/lib/office/engine/opc/paths.d.ts +7 -0
- package/dist-lib/lib/office/engine/opc/paths.js +46 -0
- package/dist-lib/lib/office/engine/opc/properties.d.ts +7 -0
- package/dist-lib/lib/office/engine/opc/properties.js +75 -0
- package/dist-lib/lib/office/engine/opc/relationships.d.ts +23 -0
- package/dist-lib/lib/office/engine/opc/relationships.js +65 -0
- package/dist-lib/lib/office/engine/opc/zip.d.ts +15 -0
- package/dist-lib/lib/office/engine/opc/zip.js +264 -0
- package/dist-lib/lib/office/engine/pptx/fit.d.ts +12 -0
- package/dist-lib/lib/office/engine/pptx/fit.js +37 -0
- package/dist-lib/lib/office/engine/pptx/index.d.ts +8 -0
- package/dist-lib/lib/office/engine/pptx/index.js +8 -0
- package/dist-lib/lib/office/engine/pptx/inherit.d.ts +29 -0
- package/dist-lib/lib/office/engine/pptx/inherit.js +155 -0
- package/dist-lib/lib/office/engine/pptx/notes.d.ts +5 -0
- package/dist-lib/lib/office/engine/pptx/notes.js +85 -0
- 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 +56 -0
- package/dist-lib/lib/office/engine/pptx/presentation.js +787 -0
- package/dist-lib/lib/office/engine/pptx/read.d.ts +9 -0
- package/dist-lib/lib/office/engine/pptx/read.js +66 -0
- package/dist-lib/lib/office/engine/pptx/shapes.d.ts +52 -0
- package/dist-lib/lib/office/engine/pptx/shapes.js +276 -0
- package/dist-lib/lib/office/engine/pptx/slides.d.ts +27 -0
- package/dist-lib/lib/office/engine/pptx/slides.js +123 -0
- package/dist-lib/lib/office/engine/pptx/template.d.ts +20 -0
- package/dist-lib/lib/office/engine/pptx/template.js +391 -0
- package/dist-lib/lib/office/engine/pptx/types.d.ts +121 -0
- package/dist-lib/lib/office/engine/pptx/types.js +1 -0
- package/dist-lib/lib/office/engine/units.d.ts +3 -0
- package/dist-lib/lib/office/engine/units.js +12 -0
- package/dist-lib/lib/office/engine/utf8.d.ts +2 -0
- package/dist-lib/lib/office/engine/utf8.js +103 -0
- package/dist-lib/lib/office/engine/xlsx/formula.d.ts +49 -0
- package/dist-lib/lib/office/engine/xlsx/formula.js +381 -0
- package/dist-lib/lib/office/engine/xlsx/index.d.ts +8 -0
- package/dist-lib/lib/office/engine/xlsx/index.js +8 -0
- package/dist-lib/lib/office/engine/xlsx/refs.d.ts +22 -0
- package/dist-lib/lib/office/engine/xlsx/refs.js +82 -0
- package/dist-lib/lib/office/engine/xlsx/reshape.d.ts +21 -0
- package/dist-lib/lib/office/engine/xlsx/reshape.js +424 -0
- package/dist-lib/lib/office/engine/xlsx/sheet.d.ts +108 -0
- package/dist-lib/lib/office/engine/xlsx/sheet.js +662 -0
- package/dist-lib/lib/office/engine/xlsx/strings.d.ts +15 -0
- package/dist-lib/lib/office/engine/xlsx/strings.js +93 -0
- package/dist-lib/lib/office/engine/xlsx/styles.d.ts +38 -0
- package/dist-lib/lib/office/engine/xlsx/styles.js +369 -0
- package/dist-lib/lib/office/engine/xlsx/template.d.ts +7 -0
- package/dist-lib/lib/office/engine/xlsx/template.js +54 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +162 -0
- package/dist-lib/lib/office/engine/xlsx/workbook.js +881 -0
- package/dist-lib/lib/office/engine/xlsx/write.d.ts +2 -0
- package/dist-lib/lib/office/engine/xlsx/write.js +42 -0
- package/dist-lib/lib/office/engine/xml.d.ts +45 -0
- package/dist-lib/lib/office/engine/xml.js +258 -0
- package/dist-lib/lib/office/extract.d.ts +9 -0
- package/dist-lib/lib/office/extract.js +20 -0
- package/dist-lib/lib/office/index.d.ts +1 -1
- package/dist-lib/lib/office/index.js +77 -21
- package/dist-lib/lib/plugins/addons.d.ts +2 -0
- package/dist-lib/lib/plugins/addons.js +12 -0
- package/dist-lib/lib/plugins/context.d.ts +16 -0
- package/dist-lib/lib/plugins/context.js +48 -0
- package/dist-lib/lib/plugins/index.d.ts +3 -0
- package/dist-lib/lib/plugins/index.js +1 -0
- package/dist-lib/lib/plugins/registry.d.ts +121 -0
- package/dist-lib/lib/plugins/registry.js +518 -0
- package/dist-lib/lib/plugins/runtime.d.ts +27 -0
- package/dist-lib/lib/plugins/runtime.js +143 -0
- package/dist-lib/lib/plugins/scope.d.ts +17 -0
- package/dist-lib/lib/plugins/scope.js +55 -0
- package/dist-lib/lib/policy/index.d.ts +11 -0
- package/dist-lib/lib/policy/index.js +235 -0
- package/dist-lib/lib/prompt.d.ts +5 -6
- package/dist-lib/lib/prompt.js +26 -11
- package/dist-lib/lib/residency/completion-runtime.d.ts +61 -0
- package/dist-lib/lib/{capabilities → residency}/completion-runtime.js +55 -38
- package/dist-lib/lib/residency/index.d.ts +192 -0
- package/dist-lib/lib/residency/index.js +908 -0
- package/dist-lib/lib/resolution-detector.js +3 -3
- package/dist-lib/lib/round-host.d.ts +12 -0
- package/dist-lib/lib/round-host.js +57 -0
- package/dist-lib/lib/round-port.d.ts +24 -0
- package/dist-lib/lib/round-port.js +81 -0
- package/dist-lib/lib/rpc-session.js +2 -1
- package/dist-lib/lib/run-log/boundary.d.ts +17 -0
- package/dist-lib/lib/run-log/boundary.js +58 -0
- package/dist-lib/lib/run-log/history-codec.d.ts +7 -6
- package/dist-lib/lib/run-log/history-codec.js +175 -46
- package/dist-lib/lib/run-log/index.d.ts +46 -0
- package/dist-lib/lib/run-log/index.js +40 -0
- package/dist-lib/lib/run-log/inspect.d.ts +53 -0
- package/dist-lib/lib/{run-log-inspect.js → run-log/inspect.js} +196 -139
- package/dist-lib/lib/run-log/live.d.ts +37 -0
- package/dist-lib/lib/run-log/live.js +195 -0
- package/dist-lib/lib/run-log/persisted-actor.d.ts +1 -6
- package/dist-lib/lib/run-log/persisted-actor.js +4 -3
- package/dist-lib/lib/run-log/protocol-types.d.ts +37 -14
- package/dist-lib/lib/run-log/protocol.d.ts +1 -2
- package/dist-lib/lib/run-log/protocol.js +45 -40
- package/dist-lib/lib/{run-log-redact.d.ts → run-log/redact.d.ts} +3 -2
- package/dist-lib/lib/{run-log-redact.js → run-log/redact.js} +101 -16
- package/dist-lib/lib/run-log/replay.d.ts +3 -2
- package/dist-lib/lib/run-log/replay.js +7 -6
- package/dist-lib/lib/run-log/request-codec.d.ts +17 -0
- package/dist-lib/lib/run-log/request-codec.js +87 -0
- package/dist-lib/lib/run-log/run-journal.d.ts +14 -8
- package/dist-lib/lib/run-log/run-journal.js +100 -75
- package/dist-lib/lib/sdk-loader.d.ts +3 -8
- package/dist-lib/lib/sdk-loader.js +51 -28
- package/dist-lib/lib/sdk-storage.d.ts +1 -0
- package/dist-lib/lib/sdk-storage.js +20 -2
- package/dist-lib/lib/serve.js +277 -69
- package/dist-lib/lib/sidecar/index.d.ts +39 -0
- package/dist-lib/lib/sidecar/index.js +206 -0
- package/dist-lib/lib/sidecar/user-plugins.d.ts +9 -0
- package/dist-lib/lib/sidecar/user-plugins.js +119 -0
- package/dist-lib/lib/skills-host/index.d.ts +60 -0
- package/dist-lib/lib/skills-host/index.js +272 -0
- package/dist-lib/lib/spawn.d.ts +40 -7
- package/dist-lib/lib/spawn.js +24 -20
- package/dist-lib/lib/spill.d.ts +12 -0
- package/dist-lib/lib/spill.js +86 -0
- package/dist-lib/lib/tools/{exec/adapters/python → attachments}/output-policy.d.ts +2 -3
- package/dist-lib/lib/tools/{exec/adapters/python/attachments.d.ts → attachments/staging.d.ts} +2 -2
- package/dist-lib/lib/tools/{exec/adapters/python/attachments.js → attachments/staging.js} +9 -9
- package/dist-lib/lib/tools/catalog.d.ts +1 -1
- package/dist-lib/lib/tools/catalog.js +1 -1
- package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.d.ts +5 -7
- package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.js +3 -2
- package/dist-lib/lib/tools/exec/bare-runtime.js +2 -4
- package/dist-lib/lib/tools/exec/python-source.d.ts +6 -0
- package/dist-lib/lib/tools/exec/python-source.js +243 -0
- package/dist-lib/lib/tools/exec/runner.d.ts +24 -45
- package/dist-lib/lib/tools/exec/runner.js +70 -35
- package/dist-lib/lib/tools/exec/scope.d.ts +2 -1
- package/dist-lib/lib/tools/exec/scope.js +45 -105
- package/dist-lib/lib/tools/exec/shell-guidance.d.ts +11 -9
- package/dist-lib/lib/tools/exec/shell-guidance.js +30 -59
- 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/video-tools.d.ts +0 -1
- package/dist-lib/lib/tools/exec/video-tools.js +0 -5
- package/dist-lib/lib/tools/exec.d.ts +10 -14
- package/dist-lib/lib/tools/exec.js +253 -468
- 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 +212 -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 +10 -14
- 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 +153 -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 +45 -3
- package/dist-lib/lib/tools/fs/remote-protocol.js +1 -1
- package/dist-lib/lib/tools/fs/remote.d.ts +3 -11
- package/dist-lib/lib/tools/fs/remote.js +24 -14
- package/dist-lib/lib/tools/fs/scope.d.ts +6 -1
- package/dist-lib/lib/tools/fs/scope.js +13 -5
- package/dist-lib/lib/tools/fs/search.d.ts +41 -0
- package/dist-lib/lib/tools/fs/search.js +383 -0
- package/dist-lib/lib/tools/fs/targets.d.ts +10 -0
- 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.d.ts +1 -1
- package/dist-lib/lib/tools/http-request.js +14 -2
- package/dist-lib/lib/tools/index.d.ts +22 -0
- package/dist-lib/lib/tools/index.js +38 -0
- package/dist-lib/lib/tools/office/ops.d.ts +13 -0
- package/dist-lib/lib/tools/office/ops.js +100 -0
- package/dist-lib/lib/tools/office.d.ts +12 -0
- package/dist-lib/lib/tools/office.js +542 -0
- package/dist-lib/lib/tools/operations/compile.d.ts +3 -3
- package/dist-lib/lib/tools/operations/compile.js +2 -1
- package/dist-lib/lib/tools/operations/decoders.js +1 -1
- package/dist-lib/lib/tools/operations/manifest.d.ts +1 -1
- package/dist-lib/lib/tools/outbound-guard.d.ts +3 -1
- package/dist-lib/lib/tools/outbound-guard.js +4 -0
- package/dist-lib/lib/tools/pdf/build.d.ts +47 -0
- package/dist-lib/lib/tools/pdf/build.js +175 -0
- package/dist-lib/lib/tools/pdf/images.d.ts +7 -0
- package/dist-lib/lib/tools/pdf/images.js +82 -0
- package/dist-lib/lib/tools/pdf/request.d.ts +63 -0
- package/dist-lib/lib/tools/pdf/request.js +335 -0
- package/dist-lib/lib/tools/pdf.d.ts +6 -0
- package/dist-lib/lib/tools/pdf.js +318 -0
- package/dist-lib/lib/tools/skill.d.ts +2 -4
- package/dist-lib/lib/tools/skill.js +29 -28
- package/dist-lib/lib/tools/skills/auth-resolver.d.ts +1 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +4 -4
- package/dist-lib/lib/tools/skills/catalog.d.ts +11 -2
- package/dist-lib/lib/tools/skills/catalog.js +13 -9
- 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 +7 -4
- package/dist-lib/lib/tools/skills/credential-health.js +3 -3
- package/dist-lib/lib/tools/skills/frontmatter-parser.d.ts +4 -0
- package/dist-lib/lib/tools/skills/frontmatter-parser.js +6 -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 +3 -4
- package/dist-lib/lib/tools/skills/mention.js +11 -7
- package/dist-lib/lib/tools/skills/overlay-crud.js +3 -2
- package/dist-lib/lib/tools/skills/scope-key.d.ts +2 -1
- package/dist-lib/lib/tools/skills/scope-key.js +2 -3
- package/dist-lib/lib/tools/skills/skill-state-constants.d.ts +1 -0
- package/dist-lib/lib/tools/skills/skill-state-constants.js +4 -0
- package/dist-lib/lib/tools/skills/skill-state.d.ts +2 -2
- package/dist-lib/lib/tools/skills/skill-state.js +11 -28
- package/dist-lib/lib/tools/toolsets.d.ts +3 -7
- package/dist-lib/lib/tools/toolsets.js +5 -9
- 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.d.ts +1 -1
- package/dist-lib/lib/tools/web-fetch.js +52 -10
- package/dist-lib/lib/web-fetch/embedded-state.js +1 -1
- package/dist-lib/lib/web-fetch/extract.js +1 -1
- package/dist-lib/lib/web-fetch/images.js +1 -1
- package/dist-lib/lib/web-fetch/video.js +1 -1
- package/dist-lib/lib/wire.d.ts +21 -0
- package/dist-lib/lib/wire.js +161 -5
- package/dist-lib/plugins/code-mode/index.d.ts +16 -0
- package/dist-lib/plugins/code-mode/index.js +43 -0
- package/dist-lib/plugins/coding/index.d.ts +15 -0
- package/dist-lib/plugins/coding/index.js +40 -0
- package/dist-lib/plugins/coding/jobs.d.ts +24 -0
- package/dist-lib/plugins/coding/jobs.js +144 -0
- package/dist-lib/plugins/coding/read-only.d.ts +1 -0
- package/dist-lib/plugins/coding/read-only.js +264 -0
- package/dist-lib/plugins/coding/session.d.ts +53 -0
- package/dist-lib/plugins/coding/session.js +292 -0
- package/dist-lib/plugins/command-hooks/index.d.ts +88 -0
- package/dist-lib/plugins/command-hooks/index.js +340 -0
- package/dist-lib/plugins/egress-proxy/index.d.ts +53 -0
- package/dist-lib/plugins/egress-proxy/index.js +184 -0
- package/dist-lib/plugins/external-agents/acp.d.ts +27 -0
- package/dist-lib/plugins/external-agents/acp.js +264 -0
- package/dist-lib/plugins/external-agents/cli.d.ts +3 -0
- package/dist-lib/plugins/external-agents/cli.js +199 -0
- package/dist-lib/plugins/external-agents/index.d.ts +25 -0
- package/dist-lib/plugins/external-agents/index.js +54 -0
- package/dist-lib/plugins/external-agents/process.d.ts +19 -0
- package/dist-lib/plugins/external-agents/process.js +92 -0
- package/dist-lib/plugins/external-agents/targets.d.ts +32 -0
- package/dist-lib/plugins/external-agents/targets.js +66 -0
- package/dist-lib/{lib/tools → plugins/image}/edit-image.d.ts +3 -2
- package/dist-lib/{lib/tools → plugins/image}/edit-image.js +11 -5
- package/dist-lib/{lib/tools → plugins/image}/generate-image.d.ts +10 -15
- package/dist-lib/{lib/tools → plugins/image}/generate-image.js +15 -15
- package/dist-lib/plugins/image/index.d.ts +25 -0
- package/dist-lib/plugins/image/index.js +84 -0
- package/dist-lib/plugins/knowledge/index.d.ts +21 -0
- package/dist-lib/plugins/knowledge/index.js +47 -0
- package/dist-lib/plugins/knowledge/search-tool.d.ts +4 -0
- package/dist-lib/plugins/knowledge/search-tool.js +38 -0
- package/dist-lib/plugins/knowledge/store.d.ts +42 -0
- package/dist-lib/plugins/knowledge/store.js +332 -0
- package/dist-lib/plugins/language-hint/index.d.ts +15 -0
- package/dist-lib/plugins/language-hint/index.js +54 -0
- package/dist-lib/plugins/lsp/index.d.ts +32 -0
- package/dist-lib/plugins/lsp/index.js +77 -0
- package/dist-lib/plugins/lsp/pool.d.ts +24 -0
- package/dist-lib/plugins/lsp/pool.js +73 -0
- package/dist-lib/plugins/lsp/rpc.d.ts +37 -0
- package/dist-lib/plugins/lsp/rpc.js +145 -0
- package/dist-lib/plugins/lsp/server.d.ts +55 -0
- package/dist-lib/plugins/lsp/server.js +192 -0
- package/dist-lib/plugins/lsp/tool.d.ts +12 -0
- package/dist-lib/plugins/lsp/tool.js +366 -0
- package/dist-lib/plugins/mcp/call.d.ts +17 -0
- package/dist-lib/{lib/tools/mcp-call.js → plugins/mcp/call.js} +92 -84
- package/dist-lib/plugins/mcp/index.d.ts +21 -0
- package/dist-lib/plugins/mcp/index.js +88 -0
- package/dist-lib/{lib/tools → plugins}/mcp/protocol.d.ts +9 -16
- package/dist-lib/{lib/tools → plugins}/mcp/protocol.js +3 -16
- package/dist-lib/plugins/mcp/server.d.ts +23 -0
- package/dist-lib/plugins/mcp/server.js +108 -0
- package/dist-lib/{lib/tools → plugins/music}/generate-music.d.ts +10 -17
- package/dist-lib/{lib/tools → plugins/music}/generate-music.js +12 -10
- package/dist-lib/plugins/music/index.d.ts +24 -0
- package/dist-lib/plugins/music/index.js +55 -0
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/cli-process.d.ts +2 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/cli-process.js +2 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/cli.d.ts +1 -1
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/cli.js +7 -7
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/command.js +2 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/guidance.d.ts +0 -1
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/guidance.js +0 -7
- package/dist-lib/plugins/obsidian/index.d.ts +26 -0
- package/dist-lib/plugins/obsidian/index.js +138 -0
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/note-name.js +2 -1
- package/dist-lib/{lib/tools/skills/obsidian-readiness.d.ts → plugins/obsidian/readiness.d.ts} +1 -0
- package/dist-lib/{lib/tools/skills/obsidian-readiness.js → plugins/obsidian/readiness.js} +7 -0
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/safe-path.js +5 -4
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-create.js +3 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-fs.js +2 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-paths.js +3 -2
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-read.js +20 -18
- package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-write.js +13 -12
- package/dist-lib/plugins/python/guarded-fetch.d.ts +14 -0
- package/dist-lib/plugins/python/guarded-fetch.js +36 -0
- package/dist-lib/plugins/python/index.d.ts +18 -0
- package/dist-lib/plugins/python/index.js +20 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/interrupt-timer.js +3 -3
- package/dist-lib/plugins/python/language.d.ts +8 -0
- package/dist-lib/plugins/python/language.js +377 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/loader.d.ts +2 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/loader.js +84 -4
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/memfs.js +4 -4
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/module-distributions.js +0 -3
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/pyodide.d.ts +1 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/pyodide.js +12 -11
- package/dist-lib/plugins/python/python-adapter.d.ts +41 -0
- package/dist-lib/plugins/python/python-adapter.js +517 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/run-session.d.ts +2 -2
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/run-session.js +28 -106
- package/dist-lib/plugins/python/shell-redirect.d.ts +8 -0
- package/dist-lib/plugins/python/shell-redirect.js +25 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/wheels.js +11 -7
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/active.js +2 -2
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/client.d.ts +1 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/client.js +14 -10
- package/dist-lib/plugins/python/worker/entry.d.ts +1 -0
- package/dist-lib/plugins/python/worker/entry.js +9 -0
- package/dist-lib/plugins/python/worker/interrupt-deadline.d.ts +1 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/interrupt-deadline.js +1 -1
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/protocol.d.ts +2 -0
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/serve.js +24 -5
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/spawn.d.ts +3 -1
- package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/spawn.js +9 -1
- package/dist-lib/plugins/quickjs/index.d.ts +20 -0
- package/dist-lib/plugins/quickjs/index.js +29 -0
- package/dist-lib/plugins/quickjs/language.d.ts +3 -0
- package/dist-lib/plugins/quickjs/language.js +59 -0
- package/dist-lib/plugins/quickjs/runtime.d.ts +38 -0
- package/dist-lib/plugins/quickjs/runtime.js +426 -0
- package/dist-lib/plugins/quickjs/text-decoder.d.ts +1 -0
- package/dist-lib/plugins/quickjs/text-decoder.js +15 -0
- package/dist-lib/plugins/run-report/brand.d.ts +1 -0
- package/dist-lib/plugins/run-report/brand.js +1 -0
- 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.d.ts +6 -0
- package/dist-lib/plugins/run-report/flow-view.js +54 -0
- package/dist-lib/plugins/run-report/flow.d.ts +33 -0
- package/dist-lib/plugins/run-report/flow.js +253 -0
- package/dist-lib/plugins/run-report/index.d.ts +38 -0
- package/dist-lib/plugins/run-report/index.js +46 -0
- package/dist-lib/plugins/run-report/layout.d.ts +39 -0
- package/dist-lib/plugins/run-report/layout.js +175 -0
- package/dist-lib/plugins/run-report/meaning.d.ts +6 -0
- package/dist-lib/plugins/run-report/meaning.js +43 -0
- package/dist-lib/plugins/run-report/model.d.ts +95 -0
- package/dist-lib/plugins/run-report/model.js +393 -0
- package/dist-lib/plugins/run-report/page.d.ts +22 -0
- package/dist-lib/plugins/run-report/page.js +274 -0
- package/dist-lib/plugins/run-report/script.d.ts +1 -0
- package/dist-lib/plugins/run-report/script.js +935 -0
- package/dist-lib/plugins/run-report/story.d.ts +49 -0
- package/dist-lib/plugins/run-report/story.js +188 -0
- package/dist-lib/plugins/run-report/style.d.ts +1 -0
- package/dist-lib/plugins/run-report/style.js +536 -0
- package/dist-lib/plugins/run-report/why.d.ts +28 -0
- package/dist-lib/plugins/run-report/why.js +170 -0
- package/dist-lib/plugins/sandbox-linux/index.d.ts +62 -0
- package/dist-lib/plugins/sandbox-linux/index.js +354 -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 +62 -0
- package/dist-lib/plugins/sandbox-macos/index.js +370 -0
- package/dist-lib/plugins/sandbox-vm/index.d.ts +24 -0
- package/dist-lib/plugins/sandbox-vm/index.js +30 -0
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +48 -0
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +111 -0
- 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/{lib/capabilities → plugins/speech}/audio-resample.d.ts +1 -1
- package/dist-lib/{lib/capabilities → plugins/speech}/audio-resample.js +8 -8
- package/dist-lib/{lib → plugins/speech}/audio-transcode-bare.d.ts +1 -1
- package/dist-lib/{lib → plugins/speech}/audio-transcode-bare.js +24 -27
- package/dist-lib/{lib → plugins/speech}/audio-transcode-node.d.ts +1 -1
- package/dist-lib/{lib → plugins/speech}/audio-transcode-node.js +1 -3
- package/dist-lib/plugins/speech/index.d.ts +18 -0
- package/dist-lib/plugins/speech/index.js +31 -0
- package/dist-lib/plugins/speech/speech-engine.d.ts +23 -0
- package/dist-lib/plugins/speech/speech-engine.js +55 -0
- package/dist-lib/plugins/speech/speech-runtime.d.ts +22 -0
- package/dist-lib/plugins/speech/speech-runtime.js +212 -0
- package/dist-lib/{lib/capabilities → plugins/speech}/speech-text.d.ts +1 -0
- package/dist-lib/{lib/capabilities → plugins/speech}/speech-text.js +10 -3
- package/dist-lib/plugins/speech/voice-lane.d.ts +2 -0
- package/dist-lib/plugins/speech/voice-lane.js +9 -0
- package/dist-lib/plugins/speech/voice.d.ts +21 -0
- package/dist-lib/plugins/speech/voice.js +270 -0
- package/dist-lib/plugins/translation/index.d.ts +23 -0
- package/dist-lib/plugins/translation/index.js +74 -0
- package/dist-lib/{lib/models → plugins/translation}/nmt-catalog.d.ts +0 -1
- package/dist-lib/{lib/models → plugins/translation}/nmt-catalog.js +0 -3
- package/dist-lib/{lib/tools → plugins/translation}/translate.d.ts +23 -11
- package/dist-lib/{lib/tools → plugins/translation}/translate.js +81 -70
- package/dist-lib/plugins/walkie-talkie/crew.d.ts +27 -0
- package/dist-lib/plugins/walkie-talkie/crew.js +103 -0
- package/dist-lib/plugins/walkie-talkie/index.d.ts +127 -0
- package/dist-lib/plugins/walkie-talkie/index.js +348 -0
- package/dist-lib/plugins/walkie-talkie/wire.d.ts +72 -0
- package/dist-lib/plugins/walkie-talkie/wire.js +137 -0
- package/dist-lib/plugins/weather/geocode.d.ts +25 -0
- package/dist-lib/plugins/weather/geocode.js +102 -0
- package/dist-lib/plugins/weather/index.d.ts +15 -0
- package/dist-lib/plugins/weather/index.js +17 -0
- package/dist-lib/plugins/weather/lookup.d.ts +6 -0
- package/dist-lib/plugins/weather/lookup.js +170 -0
- package/dist-lib/{lib/tools/weather-lookup → plugins/weather}/place.js +5 -1
- package/dist-lib/plugins/web-search/engine-registry.d.ts +44 -0
- package/dist-lib/plugins/web-search/engine-registry.js +17 -0
- package/dist-lib/{lib → plugins}/web-search/engines/aol.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/aol.js +5 -3
- package/dist-lib/{lib → plugins}/web-search/engines/bing.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/bing.js +11 -5
- package/dist-lib/{lib → plugins}/web-search/engines/brave.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/brave.js +5 -3
- package/dist-lib/{lib → plugins}/web-search/engines/duckduckgo.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/duckduckgo.js +5 -2
- package/dist-lib/{lib → plugins}/web-search/engines/google.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/google.js +8 -5
- package/dist-lib/{lib → plugins}/web-search/engines/wikipedia.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/wikipedia.js +5 -3
- package/dist-lib/{lib → plugins}/web-search/engines/yahoo.d.ts +1 -0
- package/dist-lib/{lib → plugins}/web-search/engines/yahoo.js +5 -3
- package/dist-lib/{lib → plugins}/web-search/fetch-html.d.ts +5 -5
- package/dist-lib/{lib → plugins}/web-search/fetch-html.js +13 -16
- package/dist-lib/plugins/web-search/index.d.ts +18 -0
- package/dist-lib/plugins/web-search/index.js +33 -0
- package/dist-lib/{lib → plugins}/web-search/orchestrator.d.ts +3 -1
- package/dist-lib/{lib → plugins}/web-search/orchestrator.js +5 -5
- package/dist-lib/plugins/web-search/tool.d.ts +3 -0
- package/dist-lib/{lib/tools/web-search.js → plugins/web-search/tool.js} +19 -14
- package/dist-lib/plugins/web-search/types.js +1 -0
- package/dist-lib/schema/generate.js +5 -2
- package/dist-lib/schema/harness.js +214 -10
- package/dist-lib/spec/bind.js +29 -4
- package/dist-lib/spec/calls.js +7 -0
- package/dist-lib/spec/hrpc/hrpc.json +91 -0
- package/dist-lib/spec/hrpc/index.js +87 -3
- package/dist-lib/spec/hrpc/messages.js +796 -55
- package/dist-lib/spec/hyperschema/index.js +796 -55
- package/dist-lib/spec/hyperschema/schema.json +601 -17
- package/dist-lib/spec/hyperschema/types.d.ts +137 -4
- package/package.json +442 -499
- package/patches/pyodide@314.0.2.patch +37 -8
- package/scripts/addon-externals.cjs +391 -0
- package/scripts/addon-externals.d.ts +30 -0
- package/wheels/manifest.json +1 -160
- package/worker/harness-sidecar.mjs +51 -166
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.d.ts +0 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.js +0 -75
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.d.ts +0 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.js +0 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.d.ts +0 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.js +0 -114
- package/dist-lib/lib/capabilities/completion-loop/index.d.ts +0 -80
- package/dist-lib/lib/capabilities/completion-loop/index.js +0 -158
- package/dist-lib/lib/capabilities/completion-loop/metrics.d.ts +0 -5
- package/dist-lib/lib/capabilities/completion-loop/metrics.js +0 -29
- package/dist-lib/lib/capabilities/completion-loop/round.d.ts +0 -33
- package/dist-lib/lib/capabilities/completion-loop/round.js +0 -353
- package/dist-lib/lib/capabilities/completion-loop/tool-execution.d.ts +0 -60
- package/dist-lib/lib/capabilities/completion-loop/turns.d.ts +0 -23
- package/dist-lib/lib/capabilities/completion-loop/turns.js +0 -112
- package/dist-lib/lib/capabilities/completion-runtime.d.ts +0 -46
- package/dist-lib/lib/capabilities/completion.d.ts +0 -18
- package/dist-lib/lib/capabilities/completion.js +0 -22
- package/dist-lib/lib/capabilities/voice.js +0 -199
- package/dist-lib/lib/helpers/recovery-required.d.ts +0 -1
- package/dist-lib/lib/helpers/recovery-required.js +0 -1
- package/dist-lib/lib/hooks/built-in/index.d.ts +0 -4
- package/dist-lib/lib/hooks/built-in/index.js +0 -4
- package/dist-lib/lib/hooks/pipeline.d.ts +0 -24
- package/dist-lib/lib/hooks/pipeline.js +0 -74
- package/dist-lib/lib/hooks/registry.d.ts +0 -2
- package/dist-lib/lib/hooks/registry.js +0 -7
- package/dist-lib/lib/hooks/types.d.ts +0 -69
- package/dist-lib/lib/machine/completion/actions/skills.d.ts +0 -9
- package/dist-lib/lib/machine/completion/actions/skills.js +0 -83
- package/dist-lib/lib/machine/engine.d.ts +0 -93
- package/dist-lib/lib/machine/guards.d.ts +0 -2
- package/dist-lib/lib/machine/guards.js +0 -6
- package/dist-lib/lib/office/pptx.d.ts +0 -1
- package/dist-lib/lib/office/pptx.js +0 -26
- package/dist-lib/lib/office/python.d.ts +0 -8
- package/dist-lib/lib/office/python.js +0 -32
- package/dist-lib/lib/office/xlsx.d.ts +0 -1
- package/dist-lib/lib/office/xlsx.js +0 -26
- package/dist-lib/lib/run-log-inspect.d.ts +0 -25
- package/dist-lib/lib/run-log-protocol.d.ts +0 -2
- package/dist-lib/lib/run-log-protocol.js +0 -1
- package/dist-lib/lib/tool-call-display.d.ts +0 -1
- 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/adapters/adapter.d.ts +0 -31
- package/dist-lib/lib/tools/exec/adapters/python/create-effect.d.ts +0 -7
- package/dist-lib/lib/tools/exec/adapters/python/create-effect.js +0 -318
- package/dist-lib/lib/tools/exec/adapters/python/python-adapter.d.ts +0 -89
- package/dist-lib/lib/tools/exec/adapters/python/python-adapter.js +0 -1371
- package/dist-lib/lib/tools/exec/adapters/python/worker/entry.js +0 -3
- package/dist-lib/lib/tools/exec/obsidian/route.d.ts +0 -17
- package/dist-lib/lib/tools/exec/obsidian/route.js +0 -91
- 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.d.ts +0 -14
- package/dist-lib/lib/tools/file-glob.js +0 -117
- package/dist-lib/lib/tools/grep.d.ts +0 -5
- package/dist-lib/lib/tools/grep.js +0 -183
- package/dist-lib/lib/tools/mcp-call.d.ts +0 -14
- package/dist-lib/lib/tools/rag-search.d.ts +0 -2
- package/dist-lib/lib/tools/rag-search.js +0 -105
- package/dist-lib/lib/tools/read-files.d.ts +0 -5
- package/dist-lib/lib/tools/read-files.js +0 -156
- package/dist-lib/lib/tools/weather-lookup.d.ts +0 -8
- package/dist-lib/lib/tools/weather-lookup.js +0 -122
- package/dist-lib/lib/tools/web-search.d.ts +0 -6
- package/dist-lib/lib/web-search/engine-registry.d.ts +0 -7
- package/dist-lib/lib/web-search/engine-registry.js +0 -17
- package/patches/@qvac%2Finference@0.20.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
- package/wheels/cffi-2.0.0-cp314-cp314-pyemscripten_2026_0_wasm32.whl +0 -0
- package/wheels/cryptography-47.0.0-cp314-abi3-pyemscripten_2026_0_wasm32.whl +0 -0
- package/wheels/defusedxml-0.7.1-py2.py3-none-any.whl +0 -0
- package/wheels/et_xmlfile-2.0.0-py3-none-any.whl +0 -0
- package/wheels/fonttools-4.62.1-py3-none-any.whl +0 -0
- package/wheels/fpdf2-2.8.8-py3-none-any.whl +0 -0
- package/wheels/lxml-6.0.2-cp314-cp314-pyemscripten_2026_0_wasm32.whl +0 -0
- package/wheels/openpyxl-3.1.5-py2.py3-none-any.whl +0 -0
- package/wheels/pillow-12.2.0-cp314-cp314-pyemscripten_2026_0_wasm32.whl +0 -0
- package/wheels/pycparser-3.0-py3-none-any.whl +0 -0
- package/wheels/pypdf-6.15.0-py3-none-any.whl +0 -0
- package/wheels/python_docx-1.2.0-py3-none-any.whl +0 -0
- package/wheels/python_pptx-1.0.2-py3-none-any.whl +0 -0
- package/wheels/six-1.17.0-py2.py3-none-any.whl +0 -0
- package/wheels/typing_extensions-4.15.0-py3-none-any.whl +0 -0
- package/wheels/xlsxwriter-3.2.9-py3-none-any.whl +0 -0
- /package/dist-lib/lib/{tools/skills → agent}/tool-grants.d.ts +0 -0
- /package/dist-lib/lib/{tools/skills → agent}/tool-grants.js +0 -0
- /package/dist-lib/lib/capabilities/{types.js → completion-engine/prepare-step.js} +0 -0
- /package/dist-lib/lib/{hooks/types.js → capabilities/completion-engine/stages.js} +0 -0
- /package/dist-lib/lib/{tool-call-display.js → contract/agent.js} +0 -0
- /package/dist-lib/lib/{tools/exec/adapters/adapter.js → contract/completion.js} +0 -0
- /package/dist-lib/lib/{tools/exec/adapters/python/worker/entry.d.ts → contract/drive.js} +0 -0
- /package/dist-lib/lib/{tools/exec/adapters/python/worker/interrupt-deadline.d.ts → contract/egress-proxy.js} +0 -0
- /package/dist-lib/lib/{web-search/types.js → contract/exec.js} +0 -0
- /package/dist-lib/lib/{capabilities/completion-engine → helpers}/abort-polyfill.d.ts +0 -0
- /package/dist-lib/lib/{capabilities/completion-engine → helpers}/abort-polyfill.js +0 -0
- /package/dist-lib/lib/{web-search → helpers}/html-helpers.d.ts +0 -0
- /package/dist-lib/lib/{web-search → helpers}/html-helpers.js +0 -0
- /package/dist-lib/lib/{tools → helpers}/model-args.d.ts +0 -0
- /package/dist-lib/lib/{tools → helpers}/model-args.js +0 -0
- /package/dist-lib/lib/{machine → helpers}/stable-stringify.d.ts +0 -0
- /package/dist-lib/lib/{web-search → helpers}/user-agents.d.ts +0 -0
- /package/dist-lib/lib/{web-search → helpers}/user-agents.js +0 -0
- /package/dist-lib/lib/{harness-lifecycle.d.ts → lifecycle/machine.d.ts} +0 -0
- /package/dist-lib/lib/tools/{exec/adapters/python → attachments}/output-policy.js +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/command.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/note-name.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/output.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/output.js +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/safe-path.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-create.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-fs.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-paths.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-read.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec → plugins}/obsidian/vault-write.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/deadline-state.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/deadline-state.js +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/distributions.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/distributions.js +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/interrupt-timer.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/memfs.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/module-distributions.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/named-hosts.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/named-hosts.js +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/net-shim.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/net-shim.js +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/wheels.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/active.d.ts +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/protocol.js +0 -0
- /package/dist-lib/{lib/tools/exec/adapters → plugins}/python/worker/serve.d.ts +0 -0
- /package/dist-lib/{lib/capabilities → plugins/speech}/speech-lexicon.d.ts +0 -0
- /package/dist-lib/{lib/capabilities → plugins/speech}/speech-lexicon.js +0 -0
- /package/dist-lib/{lib → plugins/speech}/wav-encode.d.ts +0 -0
- /package/dist-lib/{lib → plugins/speech}/wav-encode.js +0 -0
- /package/dist-lib/{lib/tools/weather-lookup → plugins/weather}/place.d.ts +0 -0
- /package/dist-lib/{lib/tools/weather-lookup → plugins/weather}/report.d.ts +0 -0
- /package/dist-lib/{lib/tools/weather-lookup → plugins/weather}/report.js +0 -0
- /package/dist-lib/{lib → plugins}/web-search/format-results.d.ts +0 -0
- /package/dist-lib/{lib → plugins}/web-search/format-results.js +0 -0
- /package/dist-lib/{lib → plugins}/web-search/merge-results.d.ts +0 -0
- /package/dist-lib/{lib → plugins}/web-search/merge-results.js +0 -0
- /package/dist-lib/{lib → plugins}/web-search/types.d.ts +0 -0
- /package/dist-lib/{lib → plugins}/web-search/url-helpers.d.ts +0 -0
- /package/dist-lib/{lib → plugins}/web-search/url-helpers.js +0 -0
- /package/dist-lib/{lib → plugins}/web-search/url-normalize.d.ts +0 -0
- /package/dist-lib/{lib → plugins}/web-search/url-normalize.js +0 -0
package/dist-lib/index.js
CHANGED
|
@@ -2,71 +2,55 @@ import fs from 'fs';
|
|
|
2
2
|
import { platform, totalmem } from 'os';
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import ReadyResource from 'ready-resource';
|
|
5
|
+
import { HarnessError } from './lib/errors.js';
|
|
6
|
+
import { androidCpuPlacement } from './lib/hardware/cpu-placement.js';
|
|
5
7
|
import { probeGpuStats } from './lib/hardware/gpu-probe.js';
|
|
6
8
|
import { probeCapabilityProfile } from './lib/hardware/capability-probe.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { Lifecycle } from './lib/lifecycle/index.js';
|
|
10
|
+
import { Policy } from './lib/policy/index.js';
|
|
11
|
+
import { didDrainTimeOut, raceDrain } from './lib/helpers/drain.js';
|
|
12
|
+
import { CompletionEngine } from './lib/capabilities/completion-engine/index.js';
|
|
13
|
+
import { imageSettingsFrom } from './lib/helpers/image-settings.js';
|
|
12
14
|
import { detectLanguage } from './lib/capabilities/detect-language.js';
|
|
13
15
|
import { invoke } from './lib/capabilities/invoke.js';
|
|
14
16
|
import { previewModelSource } from './lib/capabilities/preview-model-source.js';
|
|
15
17
|
import { expandImagePrompt } from './lib/capabilities/enhance.js';
|
|
16
|
-
import { cleanAnswer } from './lib/helpers/clean-answer.js';
|
|
17
|
-
import { isTranslationModel } from './lib/models/nmt-catalog.js';
|
|
18
|
-
import { createTranslateTool, createTranslationRuntime } from './lib/tools/translate.js';
|
|
19
18
|
import { download } from './lib/capabilities/download.js';
|
|
20
|
-
import {
|
|
19
|
+
import { Embeddings } from './lib/embeddings/index.js';
|
|
21
20
|
import { deleteAllKvCaches, deleteKvCacheKey } from './lib/capabilities/kv-cache.js';
|
|
22
|
-
import { pcmForTranscription } from './lib/capabilities/audio-resample.js';
|
|
23
|
-
import { buildWavBuffer } from './lib/wav-encode.js';
|
|
24
|
-
import { createVoiceLane, packSamples, speakOnce, speakStreamOnce, transcribeOnce, transcribeStreaming, SUPERTONIC_SAMPLE_RATE } from './lib/capabilities/voice.js';
|
|
25
21
|
import { pushQueue } from './lib/queue.js';
|
|
26
|
-
import { AbortedError
|
|
27
|
-
import { audioGenDownloadMetadata, customProjectionMap, defaultProjectionMap,
|
|
28
|
-
import {
|
|
22
|
+
import { AbortedError } from './lib/helpers/race-abort.js';
|
|
23
|
+
import { audioGenDownloadMetadata, categoryDownloadMetadata, customProjectionMap, defaultProjectionMap, catalogModelName, defaultVoiceModel, diffusionDownloadMetadata, infraModelsFor, modelNameToCapabilityProfile, residentSrc, setCustomModels } from './lib/models/model-catalog.js';
|
|
24
|
+
import { customModelRows, isModelSourceCached, mergeCustomRows, listModels } from './lib/models/model-list.js';
|
|
25
|
+
import { createDownloadGate } from './lib/models/download-gate.js';
|
|
29
26
|
import { deleteModelFiles, summarizeDelete } from './lib/models/model-delete.js';
|
|
30
|
-
import {
|
|
31
|
-
import { defaultContextSize } from './lib/models/context.js';
|
|
32
|
-
import { resolveMainGpu } from './lib/models/gpu-selection.js';
|
|
33
|
-
import { createIdleReaper } from './lib/models/idle-unload.js';
|
|
27
|
+
import { createLoadTracker, createVoicePool, evictIdle, evictIdleWhere, isResident, leaseResidentModel, loadedModels, releaseModel, progressState } from './lib/models/model-pool.js';
|
|
34
28
|
import { openclCacheDir } from './lib/models/opencl-cache.js';
|
|
35
|
-
import {
|
|
36
|
-
import { createGpuFaultState, isSdkGpuDeviceLostError, isSdkModelWedgedError } from './lib/models/sdk-faults.js';
|
|
29
|
+
import { isSdkModelWedgedError } from './lib/models/sdk-faults.js';
|
|
37
30
|
import { createSdkLoader } from './lib/sdk-loader.js';
|
|
38
|
-
import { installAbortControllerPolyfill } from './lib/
|
|
39
|
-
import {
|
|
40
|
-
import { createEditImageTool } from './lib/tools/edit-image.js';
|
|
31
|
+
import { installAbortControllerPolyfill } from './lib/helpers/abort-polyfill.js';
|
|
32
|
+
import { Residency } from './lib/residency/index.js';
|
|
41
33
|
import { toolCatalog } from './lib/tools/catalog.js';
|
|
42
|
-
import {
|
|
43
|
-
import { createGenerateMusicTool, createMusicRuntime } from './lib/tools/generate-music.js';
|
|
44
|
-
import { availableSkills, detectPlatform, loadSkillCatalog, resolveSkillStatuses, skillSupportsPlatform, versionProbeSkills } from './lib/tools/skills/catalog.js';
|
|
45
|
-
import { ensureBundledSkillsDir } from './lib/tools/skills/bundled-dir.js';
|
|
46
|
-
import { ensureSkillsOverlayDir } from './lib/tools/skills/overlay-dir.js';
|
|
47
|
-
import { copyBaseForEdit, deleteOverlaySkill, listManagedSkills, readSkillFile, writeSkillFile } from './lib/tools/skills/overlay-crud.js';
|
|
48
|
-
import { watchSkillsOverlay } from './lib/tools/skills/overlay-watch.js';
|
|
34
|
+
import { SkillsHost } from './lib/skills-host/index.js';
|
|
49
35
|
import { errorMessage, isRecord } from './lib/guards.js';
|
|
50
36
|
import { redactedRecoveryFields } from './lib/wire.js';
|
|
51
|
-
import {
|
|
37
|
+
import { HarnessLog } from './lib/log.js';
|
|
52
38
|
import { installResolutionDetector, resolutionDetail } from './lib/resolution-detector.js';
|
|
53
|
-
import { probeBinVersions } from './lib/tools/skills/bin-check.js';
|
|
54
39
|
import { bareRuntime } from './lib/tools/exec/bare-runtime.js';
|
|
55
40
|
import { runCommand } from './lib/tools/exec/runner.js';
|
|
56
41
|
import { createLocalRoots } from './lib/tools/fs/local.js';
|
|
57
42
|
import { createRemoteRoots } from './lib/tools/fs/remote.js';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export
|
|
43
|
+
export { CompletionEngine, ToolSets } from './lib/capabilities/completion-engine/index.js';
|
|
44
|
+
export const CONTEXT_OVERFLOW_MESSAGE = HarnessError.CONTEXT_OVERFLOW_MESSAGE;
|
|
45
|
+
export { imageSettingsFrom } from './lib/helpers/image-settings.js';
|
|
46
|
+
export { skillInContext, unreadySkillState } from './lib/capabilities/skill-entry.js';
|
|
47
|
+
export { toSdkTool } from './lib/capabilities/sdk-tool.js';
|
|
62
48
|
export { attachmentTurn, loadedSkillsFrom, skillLoadedTurn } from './lib/capabilities/tool-turns.js';
|
|
63
49
|
export { CAPABILITIES, isCapability } from './lib/capabilities/invoke.js';
|
|
64
|
-
export { EURONANO_LANGUAGES, NMT_FROM_ENGLISH, NMT_TO_ENGLISH, SLM_LANGUAGE_CODES, SLM_LANGUAGE_NAMES, translationPlanFor } from './lib/models/nmt-catalog.js';
|
|
65
50
|
export * from './lib/capabilities/download.js';
|
|
66
51
|
export * from './lib/models/model-catalog.js';
|
|
67
52
|
export * from './lib/models/model-list.js';
|
|
68
53
|
export { harnessChild, spawnHarness } from './lib/spawn.js';
|
|
69
|
-
export { settingsDimension, settingsSteps } from './lib/tools/generate-image.js';
|
|
70
54
|
export * from './lib/tools/skills/catalog.js';
|
|
71
55
|
export { requiredSettings, settingEnvName } from './lib/tools/skills/skill-settings.js';
|
|
72
56
|
export { TOOLSETS, toolsetEnabled } from './lib/tools/toolsets.js';
|
|
@@ -75,456 +59,370 @@ export { readSetup as normalizeSkillSetup } from './lib/tools/skills/manifest-pa
|
|
|
75
59
|
export { isAvailableState, SKILL_STATE } from './lib/tools/skills/skill-state.js';
|
|
76
60
|
export { connectHarness, HARNESS_DIED, RemoteHarness } from './lib/connect.js';
|
|
77
61
|
export { serveHarness } from './lib/serve.js';
|
|
78
|
-
export {
|
|
79
|
-
export
|
|
80
|
-
export
|
|
81
|
-
const
|
|
62
|
+
export { HarnessLog };
|
|
63
|
+
export const harnessLog = HarnessLog;
|
|
64
|
+
export const hlog = HarnessLog.info;
|
|
65
|
+
export const setHarnessLog = HarnessLog.enable;
|
|
66
|
+
export const setHarnessLogLevel = HarnessLog.setLevel;
|
|
67
|
+
export const setHarnessLogSink = HarnessLog.setSink;
|
|
68
|
+
import { HookPipeline } from './lib/hooks/index.js';
|
|
69
|
+
import { Agent } from './lib/agent/index.js';
|
|
70
|
+
export { HookPipeline };
|
|
71
|
+
export { Policy };
|
|
72
|
+
import { createGuardedFetch } from './lib/guarded-fetch.js';
|
|
73
|
+
import { PluginRegistry } from './lib/plugins/index.js';
|
|
74
|
+
import { createExecTool } from './lib/tools/exec.js';
|
|
75
|
+
import { canonicalDenyRoots, defaultRealpath, deniedRootsFor } from './lib/tools/fs/scope.js';
|
|
76
|
+
export const PLUGIN_API_VERSION = PluginRegistry.API_VERSION;
|
|
82
77
|
const SUSPEND_SETTLE_MS = 500;
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const WEDGED_EVICT_LEASED_MS = 120_000;
|
|
93
|
-
const TTS_MODEL_CONFIG = {
|
|
94
|
-
ttsEngine: 'supertonic',
|
|
95
|
-
language: 'en',
|
|
96
|
-
ttsSpeed: 1.175,
|
|
97
|
-
ttsNumInferenceSteps: 5
|
|
98
|
-
};
|
|
78
|
+
const SPEECH_PLUGIN_MISSING = 'speech needs the speech plugin';
|
|
79
|
+
const KNOWLEDGE_PLUGIN_MISSING = 'knowledge needs the knowledge plugin';
|
|
80
|
+
const UNLOAD_FAILED = 'Runtime unload failed; close the harness before loading models again';
|
|
81
|
+
const HOST_SHELL = { name: 'host' };
|
|
82
|
+
function execOptions(exec) {
|
|
83
|
+
if (!exec)
|
|
84
|
+
return null;
|
|
85
|
+
return exec === true ? {} : exec;
|
|
86
|
+
}
|
|
99
87
|
export class Harness extends ReadyResource {
|
|
88
|
+
_hostTools;
|
|
100
89
|
_tools;
|
|
90
|
+
_capabilities = [];
|
|
101
91
|
_sdk;
|
|
102
92
|
_loads = createLoadTracker();
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_embedLane = createEmbedLane();
|
|
111
|
-
_embedFaults;
|
|
112
|
-
_embedGpuLayers;
|
|
113
|
-
_embedBatchSize;
|
|
114
|
-
_embedControl;
|
|
115
|
-
_ttsModels;
|
|
116
|
-
_transcriptionModels;
|
|
117
|
-
_voiceLane = createVoiceLane();
|
|
118
|
-
_lifecycle = createHarnessLifecycle({
|
|
119
|
-
suspend: () => this._suspendRuntimes(),
|
|
120
|
-
resume: () => this._resumeRuntimes()
|
|
121
|
-
});
|
|
122
|
-
_detachedRuns = new Set();
|
|
123
|
-
_effectDrainWaiters = new Set();
|
|
124
|
-
_activeWork = 0;
|
|
125
|
-
_workDrainWaiters = new Set();
|
|
126
|
-
_runtimeDraining = false;
|
|
127
|
-
_runtimeUnloadFailed = false;
|
|
128
|
-
_poolUnloadFailed = false;
|
|
129
|
-
_poolCleanupFailed = false;
|
|
130
|
-
_failedModelUnloads = new Set();
|
|
131
|
-
_sdkClosed = false;
|
|
132
|
-
_runtimesReleased = false;
|
|
93
|
+
_downloads;
|
|
94
|
+
_hold;
|
|
95
|
+
_residency;
|
|
96
|
+
_embeddings;
|
|
97
|
+
_voicePools = new Map();
|
|
98
|
+
_skills;
|
|
99
|
+
_lifecycle;
|
|
133
100
|
_closeRetryNeeded = false;
|
|
134
|
-
_closeRequested = false;
|
|
135
|
-
_skillsDir;
|
|
136
101
|
_modelsDir;
|
|
137
|
-
|
|
138
|
-
|
|
102
|
+
_skillsDir;
|
|
103
|
+
_exec;
|
|
104
|
+
_deniedRoots;
|
|
105
|
+
_policy;
|
|
106
|
+
_shell;
|
|
139
107
|
_projectionModel;
|
|
140
108
|
_customProjection = {};
|
|
141
|
-
_llmDevice;
|
|
142
|
-
_llmGpuLayers;
|
|
143
109
|
_contextSize;
|
|
144
|
-
|
|
145
|
-
_kvCacheV;
|
|
146
|
-
_transcriptionDevice;
|
|
110
|
+
_recentFits = new Map();
|
|
147
111
|
_gpuStats;
|
|
148
|
-
_completionModelCap;
|
|
149
|
-
_allSkills;
|
|
150
|
-
_credentialStore;
|
|
151
|
-
_credentials = new Map();
|
|
152
|
-
_settings = new Map();
|
|
153
|
-
_platform;
|
|
154
|
-
_diffusionSdk;
|
|
155
|
-
_imageRuntime;
|
|
156
|
-
_musicSdk;
|
|
157
|
-
_translationSdk;
|
|
158
|
-
_musicRuntime;
|
|
159
|
-
_completionRuns;
|
|
160
|
-
_translationRuntime;
|
|
161
|
-
_capabilityTools;
|
|
162
112
|
_capability = null;
|
|
163
113
|
_capabilityInflight = null;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
114
|
+
_hostHooks;
|
|
115
|
+
_hooks;
|
|
116
|
+
_plugins;
|
|
117
|
+
_pluginMode;
|
|
118
|
+
_pluginsStarted = null;
|
|
119
|
+
constructor({ tools = [], sdkLoader, skillsDir, modelsDir, sdkHome, exec, projectionModel, llmDevice, llmGpuLayers, contextSize, kvCacheK, kvCacheV, llmLoad, slots, embedDevice, embedGpuLayers, embedBatchSize, transcriptionDevice, completionModelCap, credentialStore, platform, gpuStats, hooks, plugins = [], pluginMode = 'frozen', policy } = {}) {
|
|
167
120
|
super();
|
|
121
|
+
this._exec = execOptions(exec);
|
|
122
|
+
if (this._exec && tools.some((tool) => tool.name === PluginRegistry.EXEC_TOOL)) {
|
|
123
|
+
throw new Error(`tools has '${PluginRegistry.EXEC_TOOL}', which the harness builds when exec is set`);
|
|
124
|
+
}
|
|
125
|
+
this._deniedRoots = sdkHome === undefined ? undefined : deniedRootsFor(sdkHome);
|
|
126
|
+
this._policy = policy;
|
|
127
|
+
this._plugins = new PluginRegistry(plugins, {
|
|
128
|
+
services: { models: this._modelHost(transcriptionDevice), embed: this._embedHost() },
|
|
129
|
+
exec: this._exec !== null,
|
|
130
|
+
deniedRoots: this._deniedRoots ?? []
|
|
131
|
+
});
|
|
132
|
+
this._pluginMode = pluginMode;
|
|
168
133
|
installAbortControllerPolyfill();
|
|
134
|
+
this._hostHooks = Object.freeze([...(hooks ?? HookPipeline.defaults())]);
|
|
135
|
+
this._hooks = this._hostHooks;
|
|
169
136
|
this._sdk = sdkLoader ?? createSdkLoader();
|
|
170
|
-
this.
|
|
137
|
+
this._lifecycle = new Lifecycle({
|
|
138
|
+
resource: this,
|
|
139
|
+
sdk: { peek: () => this._sdk.peek() },
|
|
140
|
+
loads: this._loads,
|
|
141
|
+
releases: {
|
|
142
|
+
pools: () => [
|
|
143
|
+
this._residency.destroy(),
|
|
144
|
+
this._embeddings.destroy(),
|
|
145
|
+
...[...this._voicePools.values()].map((entry) => entry.pool.destroy())
|
|
146
|
+
],
|
|
147
|
+
runtimes: () => [],
|
|
148
|
+
plugins: () => this._plugins.unload()
|
|
149
|
+
},
|
|
150
|
+
models: () => loadedModels(this._residency.pool).map((entry) => entry.model),
|
|
151
|
+
recreate: () => {
|
|
152
|
+
this._residency.recreate();
|
|
153
|
+
this._embeddings.recreate();
|
|
154
|
+
for (const entry of this._voicePools.values()) {
|
|
155
|
+
entry.pool = this._createVoicePool(entry.spec);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
statusChanged: () => this._residency.invalidateStatus(),
|
|
159
|
+
teardown: async () => {
|
|
160
|
+
this._skills.close();
|
|
161
|
+
await this._teardownPlugins();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
171
164
|
this._gpuStats = gpuStats;
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
174
|
-
this.
|
|
175
|
-
this.
|
|
176
|
-
this.
|
|
177
|
-
this.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
165
|
+
this._hostTools = tools;
|
|
166
|
+
this._tools = tools;
|
|
167
|
+
this._projectionModel = projectionModel ?? defaultProjectionMap();
|
|
168
|
+
this._modelsDir = modelsDir;
|
|
169
|
+
this._skillsDir = skillsDir;
|
|
170
|
+
this._skills = new SkillsHost({
|
|
171
|
+
skillsDir,
|
|
172
|
+
platform,
|
|
173
|
+
credentialStore,
|
|
174
|
+
tools: () => this._tools,
|
|
175
|
+
startPlugins: () => this._startPlugins()
|
|
182
176
|
});
|
|
183
|
-
this.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this._embedFaults = createGpuFaultState({
|
|
188
|
-
device: embedConfig.device,
|
|
189
|
-
gpuLayers: embedConfig.gpuLayers
|
|
177
|
+
this._downloads = createDownloadGate({
|
|
178
|
+
isCached: (model, addon) => this._isModelCached(model, addon),
|
|
179
|
+
onHeld: ({ model, addon }) => this._residency.notify({ status: 'held', model, addon }),
|
|
180
|
+
onDropped: ({ model, addon }) => this._residency.notify({ status: 'error', model, addon, message: 'aborted' })
|
|
190
181
|
});
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.emit('model', { ...transfer, status: 'downloaded' });
|
|
217
|
-
},
|
|
218
|
-
onBeforeLoad: async (signal) => {
|
|
219
|
-
if (this._models.destroyed)
|
|
220
|
-
return;
|
|
221
|
-
const evicted = await awaitModelCapacity(this._models, {
|
|
222
|
-
cap: 1,
|
|
223
|
-
deadlineMs: DIFFUSION_EVICT_WAIT_MS,
|
|
224
|
-
signal
|
|
225
|
-
});
|
|
226
|
-
if (signal?.aborted) {
|
|
227
|
-
throw new AbortedError();
|
|
228
|
-
}
|
|
229
|
-
if (!evicted) {
|
|
230
|
-
throw new Error('the chat model is busy; try the image again once the current reply finishes');
|
|
231
|
-
}
|
|
182
|
+
this._hold = (model, addon, signal) => this._downloads.hold(catalogModelName(model, addon), addon, signal);
|
|
183
|
+
this._contextSize = contextSize;
|
|
184
|
+
this._residency = new Residency({
|
|
185
|
+
llmDevice,
|
|
186
|
+
llmGpuLayers,
|
|
187
|
+
contextSize,
|
|
188
|
+
kvCacheK,
|
|
189
|
+
kvCacheV,
|
|
190
|
+
llmLoad,
|
|
191
|
+
slots,
|
|
192
|
+
completionModelCap,
|
|
193
|
+
sdk: { load: () => this._sdk.load() },
|
|
194
|
+
loads: this._loads,
|
|
195
|
+
gate: this._lifecycle,
|
|
196
|
+
hold: this._hold,
|
|
197
|
+
capability: () => this.capability(),
|
|
198
|
+
emit: (state) => this.emit('model', state),
|
|
199
|
+
projectionFor: (model) => this._projectionFor(model),
|
|
200
|
+
pools: () => [
|
|
201
|
+
...this._embeddings.pools(),
|
|
202
|
+
...[...this._voicePools.values()].map((entry) => entry.pool)
|
|
203
|
+
],
|
|
204
|
+
poolFor: (addon, model) => {
|
|
205
|
+
if (addon === 'embeddings') {
|
|
206
|
+
return this._embeddings.target(model);
|
|
232
207
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
this._musicRuntime = music
|
|
237
|
-
? createMusicRuntime({
|
|
238
|
-
...music,
|
|
239
|
-
loads: this._loads,
|
|
240
|
-
loadSdk: () => this._loadMusicSdk(),
|
|
241
|
-
onProgress: (model, progress) => {
|
|
242
|
-
const state = progressState(model, progress);
|
|
243
|
-
this.emit('model', state);
|
|
244
|
-
},
|
|
245
|
-
onBeforeLoad: async (signal) => {
|
|
246
|
-
if (this._models.destroyed)
|
|
247
|
-
return;
|
|
248
|
-
const evicted = await awaitModelCapacity(this._models, {
|
|
249
|
-
cap: 1,
|
|
250
|
-
deadlineMs: MUSIC_EVICT_WAIT_MS,
|
|
251
|
-
signal
|
|
252
|
-
});
|
|
253
|
-
if (signal?.aborted) {
|
|
254
|
-
throw new AbortedError();
|
|
255
|
-
}
|
|
256
|
-
if (!evicted) {
|
|
257
|
-
throw new Error('the chat model is busy; try the music again once the current reply finishes');
|
|
258
|
-
}
|
|
208
|
+
const entry = this._voicePools.get(addon);
|
|
209
|
+
if (!entry) {
|
|
210
|
+
throw new Error(SPEECH_PLUGIN_MISSING);
|
|
259
211
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
212
|
+
const key = residentSrc(model, addon);
|
|
213
|
+
return {
|
|
214
|
+
pool: entry.pool,
|
|
215
|
+
key,
|
|
216
|
+
modelType: entry.spec.modelType,
|
|
217
|
+
needsRoom: entry.spec.needsRoom?.(key) ?? false,
|
|
218
|
+
open: () => entry.pool.open(key, key)
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
embedRoom: (model, target) => this._embeddings.makeRoom(model, target),
|
|
222
|
+
evictIdle: () => [
|
|
223
|
+
...this._embeddings.evictIdle(),
|
|
224
|
+
...[...this._voicePools.values()].map((entry) => evictIdle(entry.pool))
|
|
225
|
+
],
|
|
226
|
+
unloadIdlePlugins: () => this._plugins.unloadIdle(),
|
|
227
|
+
tools: () => this._tools,
|
|
228
|
+
skills: (agentId, model) => this._skills.completionSkills(agentId, model)
|
|
266
229
|
});
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
: []),
|
|
280
|
-
...(this._musicRuntime ? [createGenerateMusicTool(this._musicRuntime, musicClamps)] : [])
|
|
281
|
-
];
|
|
282
|
-
this._projectionModel = projectionModel ?? defaultProjectionMap();
|
|
283
|
-
this._skillsDir = skillsDir;
|
|
284
|
-
this._modelsDir = modelsDir;
|
|
285
|
-
this._supportedSkills = [];
|
|
286
|
-
this._allSkills = [];
|
|
287
|
-
this._credentialStore = credentialStore;
|
|
288
|
-
this._platform = platform;
|
|
289
|
-
this._diffusionSdk = null;
|
|
290
|
-
this._musicSdk = null;
|
|
291
|
-
this._completionRuns = new Set();
|
|
292
|
-
this._translationSdk = null;
|
|
293
|
-
this._models = this._createPool();
|
|
294
|
-
this._embedModels = this._createEmbedPool();
|
|
295
|
-
this._ttsModels = this._createTtsPool();
|
|
296
|
-
this._transcriptionModels = this._createTranscriptionPool();
|
|
297
|
-
this._idle = createIdleReaper({
|
|
298
|
-
sweep: () => this._unloadIdleModels(),
|
|
299
|
-
waitMs: WEDGED_EVICT_WAIT_MS,
|
|
300
|
-
onError: (err) => hlog('idle unload failed', { err: errorMessage(err) })
|
|
230
|
+
this._embeddings = new Embeddings({
|
|
231
|
+
device: embedDevice,
|
|
232
|
+
gpuLayers: embedGpuLayers,
|
|
233
|
+
batchSize: embedBatchSize,
|
|
234
|
+
sdk: { loadEmbed: () => this._sdk.loadEmbed() },
|
|
235
|
+
loads: this._loads,
|
|
236
|
+
gate: this._lifecycle,
|
|
237
|
+
notify: (state) => this._residency.notify(state),
|
|
238
|
+
settleFit: (query) => this._residency.fit.settle(query),
|
|
239
|
+
evictIdleChat: () => this._residency.evictIdleChat(),
|
|
240
|
+
beforeLoad: (load) => this._residency.beforeLoad(load),
|
|
241
|
+
hold: this._hold
|
|
301
242
|
});
|
|
302
243
|
}
|
|
303
244
|
async _open() {
|
|
304
245
|
try {
|
|
305
246
|
installResolutionDetector(import.meta);
|
|
306
|
-
await this.
|
|
307
|
-
await this.
|
|
308
|
-
|
|
247
|
+
await this._startPlugins();
|
|
248
|
+
await this._loadAddons();
|
|
249
|
+
await this._skills.open();
|
|
250
|
+
HarnessLog.info('open', { skills: this._skills.names.length, tools: this._tools.length });
|
|
309
251
|
}
|
|
310
252
|
catch (error) {
|
|
253
|
+
await this._teardownPlugins();
|
|
311
254
|
throw error;
|
|
312
255
|
}
|
|
313
256
|
}
|
|
257
|
+
_startPlugins() {
|
|
258
|
+
this._pluginsStarted ??= this._runPluginStart();
|
|
259
|
+
return this._pluginsStarted;
|
|
260
|
+
}
|
|
261
|
+
async _runPluginStart() {
|
|
262
|
+
const reserved = this._hostTools.map((tool) => tool.name);
|
|
263
|
+
if (this._exec) {
|
|
264
|
+
reserved.push(PluginRegistry.EXEC_TOOL);
|
|
265
|
+
}
|
|
266
|
+
const started = await this._plugins.start([...reserved, Agent.TRANSFER_TOOL_NAME, Agent.DELEGATE_TOOL_NAME], {
|
|
267
|
+
fetch: (signal, mayConnect) => createGuardedFetch({ signal, mayConnect }),
|
|
268
|
+
publish: (swapped) => this._publishPlugins(swapped)
|
|
269
|
+
});
|
|
270
|
+
this._publishPlugins(started);
|
|
271
|
+
}
|
|
272
|
+
_publishPlugins({ tools, capabilities, hooks, skills, exec }) {
|
|
273
|
+
const pre = hooks.filter((hook) => hook.phase === 'preToolCall');
|
|
274
|
+
const rest = hooks.filter((hook) => hook.phase !== 'preToolCall');
|
|
275
|
+
this._tools = Object.freeze([...this._hostTools, ...this._execTools(exec), ...tools]);
|
|
276
|
+
this._shell = exec.shell;
|
|
277
|
+
this._capabilities = Object.freeze(capabilities);
|
|
278
|
+
this._hooks = Object.freeze([...pre, ...this._hostHooks, ...rest]);
|
|
279
|
+
this._skills.publish(skills);
|
|
280
|
+
}
|
|
281
|
+
_execTools(exec) {
|
|
282
|
+
if (!this._exec) {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
return [
|
|
286
|
+
createExecTool({
|
|
287
|
+
...this._exec,
|
|
288
|
+
...exec,
|
|
289
|
+
deniedRoots: this._deniedRoots,
|
|
290
|
+
skillsDir: this._skillsDir,
|
|
291
|
+
skillSettings: (skill, agentId) => this._skills.skillSettings(skill, agentId),
|
|
292
|
+
skillEnv: (skill) => this._skills.skillEnv(skill)
|
|
293
|
+
})
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
async addPlugin(plugin) {
|
|
297
|
+
await this._dynamicPlugins();
|
|
298
|
+
await this._plugins.add(plugin);
|
|
299
|
+
}
|
|
300
|
+
async removePlugin(name) {
|
|
301
|
+
await this._dynamicPlugins();
|
|
302
|
+
await this._plugins.remove(name);
|
|
303
|
+
}
|
|
304
|
+
async reloadPlugin(name, plugin) {
|
|
305
|
+
await this._dynamicPlugins();
|
|
306
|
+
await this._plugins.reload(name, plugin);
|
|
307
|
+
}
|
|
308
|
+
async _dynamicPlugins() {
|
|
309
|
+
if (this._pluginMode !== 'dynamic') {
|
|
310
|
+
throw new Error("plugins are frozen: construct the harness with pluginMode 'dynamic'");
|
|
311
|
+
}
|
|
312
|
+
if (!this.opened)
|
|
313
|
+
await this.ready();
|
|
314
|
+
this._lifecycle.assertNotClosing();
|
|
315
|
+
}
|
|
316
|
+
_modelHost(transcriptionDevice) {
|
|
317
|
+
return {
|
|
318
|
+
transcriptionDevice,
|
|
319
|
+
sdk: () => this._sdk.load(),
|
|
320
|
+
track: (load, sdk) => this._loads.track(load, sdk),
|
|
321
|
+
makeRoom: (signal, busy, srcs) => this._residency.makeRoomForPlugin(signal, busy, srcs),
|
|
322
|
+
hold: this._hold,
|
|
323
|
+
completionModel: (model, signal) => this._residency.borrow(model, signal),
|
|
324
|
+
emit: (state) => this.emit('model', state),
|
|
325
|
+
progressState,
|
|
326
|
+
statusChanged: () => this._residency.statusChanged(),
|
|
327
|
+
registerPool: (spec) => this._registerPool(spec),
|
|
328
|
+
enterWork: () => {
|
|
329
|
+
if (this._lifecycle.suspended) {
|
|
330
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
331
|
+
}
|
|
332
|
+
return this._lifecycle.enterWork();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
_registerPool(spec) {
|
|
337
|
+
const entry = { spec, pool: this._createVoicePool(spec) };
|
|
338
|
+
this._voicePools.set(spec.addon, entry);
|
|
339
|
+
return {
|
|
340
|
+
open: (model) => {
|
|
341
|
+
const pool = entry.pool;
|
|
342
|
+
const handle = pool.open(model, model);
|
|
343
|
+
return {
|
|
344
|
+
load: async () => {
|
|
345
|
+
const { modelId } = await handle.load();
|
|
346
|
+
this._lifecycle.assertNotClosing();
|
|
347
|
+
return { modelId };
|
|
348
|
+
},
|
|
349
|
+
peek: () => handle.peek(),
|
|
350
|
+
release: () => releaseModel(pool, model)
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
resident: (model) => isResident(entry.pool, model),
|
|
354
|
+
evictIdle: (wanted) => evictIdleWhere(entry.pool, wanted)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
_createVoicePool({ sdk, label, openclCache, ...spec }) {
|
|
358
|
+
return createVoicePool(() => sdk(), (state) => this._residency.notify(label ? { ...state, model: label } : state), {
|
|
359
|
+
...spec,
|
|
360
|
+
openclCacheDir: openclCache ? openclCacheDir : undefined,
|
|
361
|
+
loads: this._loads,
|
|
362
|
+
onUnloadFailure: (modelId, error) => this._lifecycle.recordModelUnloadFailure(modelId, error),
|
|
363
|
+
beforeLoad: (load) => this._residency.beforeLoad(load),
|
|
364
|
+
hold: this._hold
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
_embedHost() {
|
|
368
|
+
return {
|
|
369
|
+
embed: (request) => this.embed(request),
|
|
370
|
+
sdk: () => this._sdk.loadEmbed()
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
async _loadAddons() {
|
|
374
|
+
await Promise.all([
|
|
375
|
+
PluginRegistry.loadAddons('the harness', this._sdk.addons),
|
|
376
|
+
...this._tools.map((tool) => PluginRegistry.loadAddons(`tool '${tool.name}'`, tool.addons))
|
|
377
|
+
]);
|
|
378
|
+
}
|
|
379
|
+
_teardownPlugins() {
|
|
380
|
+
return this._plugins.teardown((plugin, error) => HarnessLog.info('plugin teardown failed', { plugin, err: errorMessage(error) }));
|
|
381
|
+
}
|
|
314
382
|
get suspended() {
|
|
315
383
|
return this._lifecycle.suspended;
|
|
316
384
|
}
|
|
317
385
|
get skillNames() {
|
|
318
|
-
return this.
|
|
386
|
+
return this._skills.names;
|
|
319
387
|
}
|
|
320
388
|
setCredentials(entries) {
|
|
321
|
-
|
|
322
|
-
const next = new Map();
|
|
323
|
-
for (const { key, token, expiresAt, agentId, skill } of entries) {
|
|
324
|
-
if (!token)
|
|
325
|
-
continue;
|
|
326
|
-
const storeKey = scopeKey({ agentId, skill, key });
|
|
327
|
-
const record = typeof expiresAt === 'number' && expiresAt > 0 ? { token, expiresAt } : { token };
|
|
328
|
-
const current = previous.get(storeKey);
|
|
329
|
-
if (!current || current.token !== record.token || current.expiresAt !== record.expiresAt) {
|
|
330
|
-
resetCredentialHealthAfterSnapshot(key, agentId, skill);
|
|
331
|
-
}
|
|
332
|
-
next.set(storeKey, record);
|
|
333
|
-
}
|
|
334
|
-
this._credentials = next;
|
|
389
|
+
this._skills.setCredentials(entries);
|
|
335
390
|
}
|
|
336
391
|
setSkillSettings(entries) {
|
|
337
|
-
|
|
338
|
-
for (const { skill, key, value, agentId } of entries) {
|
|
339
|
-
if (!skill || !key || typeof value !== 'string')
|
|
340
|
-
continue;
|
|
341
|
-
const scope = settingsScopeKey(skill, agentId);
|
|
342
|
-
const bucket = next.get(scope) ?? {};
|
|
343
|
-
bucket[key] = value;
|
|
344
|
-
next.set(scope, bucket);
|
|
345
|
-
}
|
|
346
|
-
this._settings = next;
|
|
392
|
+
this._skills.setSkillSettings(entries);
|
|
347
393
|
}
|
|
348
394
|
skillSettings(skill, agentId) {
|
|
349
|
-
return
|
|
350
|
-
...this._settings.get(settingsScopeKey(skill, null)),
|
|
351
|
-
...(agentId ? this._settings.get(settingsScopeKey(skill, agentId)) : undefined)
|
|
352
|
-
};
|
|
395
|
+
return this._skills.skillSettings(skill, agentId);
|
|
353
396
|
}
|
|
354
|
-
|
|
355
|
-
return this.
|
|
397
|
+
listManagedSkills() {
|
|
398
|
+
return this._skills.listManagedSkills();
|
|
356
399
|
}
|
|
357
|
-
|
|
358
|
-
return
|
|
400
|
+
readSkillFile(name) {
|
|
401
|
+
return this._skills.readSkillFile(name);
|
|
359
402
|
}
|
|
360
|
-
|
|
361
|
-
return
|
|
403
|
+
writeSkillFile(name, content) {
|
|
404
|
+
return this._skills.writeSkillFile(name, content);
|
|
362
405
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (!overlay) {
|
|
366
|
-
throw new Error('no writable skills overlay is configured');
|
|
367
|
-
}
|
|
368
|
-
await writeSkillFile(overlay, name, content);
|
|
369
|
-
await this._reloadSkills();
|
|
370
|
-
return { ok: true };
|
|
371
|
-
}
|
|
372
|
-
async copyBaseForEdit(name) {
|
|
373
|
-
const overlay = await ensureSkillsOverlayDir();
|
|
374
|
-
if (!overlay) {
|
|
375
|
-
throw new Error('no writable skills overlay is configured');
|
|
376
|
-
}
|
|
377
|
-
const result = await copyBaseForEdit(await this._baseSkillsDir(), overlay, name);
|
|
378
|
-
if (result.copied) {
|
|
379
|
-
await this._reloadSkills();
|
|
380
|
-
}
|
|
381
|
-
return result;
|
|
406
|
+
copyBaseForEdit(name) {
|
|
407
|
+
return this._skills.copyBaseForEdit(name);
|
|
382
408
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (!overlay) {
|
|
386
|
-
throw new Error('no writable skills overlay is configured');
|
|
387
|
-
}
|
|
388
|
-
const result = await deleteOverlaySkill(overlay, name);
|
|
389
|
-
if (result.removed) {
|
|
390
|
-
await this._reloadSkills();
|
|
391
|
-
}
|
|
392
|
-
return result;
|
|
409
|
+
deleteOverlaySkill(name) {
|
|
410
|
+
return this._skills.deleteOverlaySkill(name);
|
|
393
411
|
}
|
|
394
412
|
resolveCredential(key, ctx) {
|
|
395
|
-
|
|
396
|
-
return this._credentialStore(key, ctx);
|
|
397
|
-
}
|
|
398
|
-
const agentId = ctx?.agentId ?? null;
|
|
399
|
-
const deviceShared = isDeviceSharedCredentialKey(key);
|
|
400
|
-
for (const skill of ctx?.skills ?? []) {
|
|
401
|
-
const owned = this._credentials.get(scopeKey({ agentId, skill, key })) ??
|
|
402
|
-
(agentId && deviceShared ? this._credentials.get(scopeKey({ skill, key })) : undefined);
|
|
403
|
-
if (owned) {
|
|
404
|
-
return owned;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
if (agentId) {
|
|
408
|
-
const scoped = this._credentials.get(scopeKey({ agentId, key }));
|
|
409
|
-
if (scoped) {
|
|
410
|
-
return scoped;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (!agentId || deviceShared) {
|
|
414
|
-
return this._credentials.get(scopeKey({ key })) ?? null;
|
|
415
|
-
}
|
|
416
|
-
return null;
|
|
417
|
-
}
|
|
418
|
-
async _completionSkills(agentId, model) {
|
|
419
|
-
const statuses = new Map((await this.skills(agentId, model, { skipCredentialProbe: true, skipBinProbe: true })).map((entry) => [entry.name, entry.status]));
|
|
420
|
-
return availableSkills(this._supportedSkills, new Set(this._tools.map((tool) => tool.name)), modelNameToCapabilityProfile(model)).map((entry) => ({
|
|
421
|
-
...entry,
|
|
422
|
-
status: statuses.get(entry.name)
|
|
423
|
-
}));
|
|
413
|
+
return this._skills.resolveCredential(key, ctx);
|
|
424
414
|
}
|
|
425
415
|
async skills(agentId, modelName, options) {
|
|
426
416
|
if (!this.opened)
|
|
427
417
|
await this.ready();
|
|
428
|
-
this.
|
|
429
|
-
|
|
430
|
-
const refresh = options?.refresh === true;
|
|
431
|
-
return resolveSkillStatuses(this._allSkills, {
|
|
432
|
-
installedTools: new Set(this._tools.map((tool) => tool.name)),
|
|
433
|
-
credentialStore: (key, ctx) => this.resolveCredential(key, ctx),
|
|
434
|
-
settingsStore: (skill, agentId) => this.skillSettings(skill, agentId),
|
|
435
|
-
platform,
|
|
436
|
-
agentId,
|
|
437
|
-
binVersions: options?.skipBinProbe === true
|
|
438
|
-
? (this._binVersionCache?.bySkill ?? new Map())
|
|
439
|
-
: await this._probeBinVersions(platform, refresh),
|
|
440
|
-
refresh,
|
|
441
|
-
skipCredentialProbe: options?.skipCredentialProbe === true,
|
|
442
|
-
activeProfile: modelName ? modelNameToCapabilityProfile(modelName) : undefined
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
async _reloadSkills() {
|
|
446
|
-
const skillsDir = this._skillsDir ?? (await ensureBundledSkillsDir());
|
|
447
|
-
this._allSkills = await loadSkillCatalog(skillsDir, { platform: null });
|
|
448
|
-
const platform = this._platform ?? detectPlatform();
|
|
449
|
-
const supported = this._allSkills.filter((skill) => skillSupportsPlatform(skill, platform));
|
|
450
|
-
this._supportedSkills = availableSkills(supported, new Set(this._tools.map((t) => t.name)));
|
|
451
|
-
}
|
|
452
|
-
async _startOverlayWatch() {
|
|
453
|
-
if (this._overlayWatcher)
|
|
454
|
-
return;
|
|
455
|
-
try {
|
|
456
|
-
const overlay = await ensureSkillsOverlayDir();
|
|
457
|
-
if (!overlay) {
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
this._overlayWatcher = watchSkillsOverlay(overlay, () => {
|
|
461
|
-
this._reloadSkills().catch((err) => hlog('overlay reload failed', { err: errorMessage(err) }));
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
catch (err) {
|
|
465
|
-
hlog('overlay watch unavailable', { err: errorMessage(err) });
|
|
466
|
-
}
|
|
418
|
+
this._lifecycle.assertNotClosing();
|
|
419
|
+
return this._skills.statuses(agentId, modelName, options);
|
|
467
420
|
}
|
|
468
421
|
async tools() {
|
|
422
|
+
if (!this.opened)
|
|
423
|
+
await this.ready();
|
|
469
424
|
return toolCatalog(this._tools);
|
|
470
425
|
}
|
|
471
|
-
_binVersionCache = null;
|
|
472
|
-
_binVersionInflight = null;
|
|
473
|
-
async _probeBinVersions(platform, refresh = false) {
|
|
474
|
-
const now = Date.now();
|
|
475
|
-
if (!refresh && this._binVersionCache && this._binVersionCache.expiresAt > now) {
|
|
476
|
-
return this._binVersionCache.bySkill;
|
|
477
|
-
}
|
|
478
|
-
if (this._binVersionInflight) {
|
|
479
|
-
return this._binVersionInflight;
|
|
480
|
-
}
|
|
481
|
-
this._binVersionInflight = this._runBinVersionProbes(platform)
|
|
482
|
-
.then((bySkill) => {
|
|
483
|
-
this._binVersionCache = {
|
|
484
|
-
expiresAt: Date.now() + BIN_VERSION_PROBE_TTL_MS,
|
|
485
|
-
bySkill
|
|
486
|
-
};
|
|
487
|
-
return bySkill;
|
|
488
|
-
})
|
|
489
|
-
.finally(() => {
|
|
490
|
-
this._binVersionInflight = null;
|
|
491
|
-
});
|
|
492
|
-
return this._binVersionInflight;
|
|
493
|
-
}
|
|
494
|
-
async _runBinVersionProbes(platform) {
|
|
495
|
-
if (process.env.QVAC_NO_SKILL_BIN_PROBE) {
|
|
496
|
-
return new Map();
|
|
497
|
-
}
|
|
498
|
-
const installed = new Set(this._tools.map((tool) => tool.name));
|
|
499
|
-
const candidates = versionProbeSkills(this._allSkills, installed, platform);
|
|
500
|
-
if (candidates.length === 0) {
|
|
501
|
-
return new Map();
|
|
502
|
-
}
|
|
503
|
-
let runtime;
|
|
504
|
-
try {
|
|
505
|
-
runtime = await bareRuntime();
|
|
506
|
-
}
|
|
507
|
-
catch {
|
|
508
|
-
return new Map();
|
|
509
|
-
}
|
|
510
|
-
const run = async (command) => {
|
|
511
|
-
try {
|
|
512
|
-
const result = await runCommand(command, { ...runtime, timeoutMs: 5_000 });
|
|
513
|
-
return result.exitCode === 0 ? result.stdout : null;
|
|
514
|
-
}
|
|
515
|
-
catch {
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
const bySkill = new Map();
|
|
520
|
-
for (const skill of candidates) {
|
|
521
|
-
const states = await probeBinVersions(skill.requires, { platform, run });
|
|
522
|
-
if (states.size > 0) {
|
|
523
|
-
bySkill.set(skill.name, states);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return bySkill;
|
|
527
|
-
}
|
|
528
426
|
get toolNames() {
|
|
529
427
|
return this._tools.map((tool) => tool.name);
|
|
530
428
|
}
|
|
@@ -554,550 +452,88 @@ export class Harness extends ReadyResource {
|
|
|
554
452
|
this._customProjection = customProjectionMap();
|
|
555
453
|
}
|
|
556
454
|
setModelIdleTimeout(ms) {
|
|
557
|
-
this.
|
|
455
|
+
this._residency.setIdleTimeout(ms);
|
|
558
456
|
}
|
|
559
|
-
|
|
560
|
-
|
|
457
|
+
async setModelMemoryCap(percent) {
|
|
458
|
+
await this._residency.setMemoryCap(percent);
|
|
561
459
|
}
|
|
562
|
-
async
|
|
460
|
+
async memoryUsage() {
|
|
461
|
+
return { usedBytes: this._residency.settledBytes() };
|
|
462
|
+
}
|
|
463
|
+
setDownloadsAllowed({ allowed }) {
|
|
464
|
+
this._downloads.setAllowed(allowed);
|
|
465
|
+
}
|
|
466
|
+
async _isModelCached(model, addon) {
|
|
467
|
+
const row = (await this.list({ type: addon })).find((entry) => entry.name === model);
|
|
468
|
+
if (row) {
|
|
469
|
+
return row.isCached;
|
|
470
|
+
}
|
|
563
471
|
const sdk = await this._sdk.load();
|
|
564
|
-
|
|
565
|
-
|
|
472
|
+
return isModelSourceCached(sdk, { model, addon, modelsDir: this._modelsDir });
|
|
473
|
+
}
|
|
474
|
+
previewModelSource(context) {
|
|
475
|
+
return previewModelSource(context, {
|
|
476
|
+
assessFit: (query) => this._residency.fit.assess(query),
|
|
477
|
+
contextSize: this._contextSize,
|
|
478
|
+
recentFits: this._recentFits
|
|
566
479
|
});
|
|
567
|
-
const model = result.models[0];
|
|
568
|
-
return {
|
|
569
|
-
fit: model?.verdict ?? result.verdict,
|
|
570
|
-
fitReasons: [...(model?.reasons ?? result.reasons)]
|
|
571
|
-
};
|
|
572
480
|
}
|
|
573
481
|
async describe() {
|
|
574
482
|
if (!this.opened)
|
|
575
483
|
await this.ready();
|
|
576
484
|
return {
|
|
577
485
|
toolNames: this.toolNames,
|
|
578
|
-
skills: this.
|
|
486
|
+
skills: this._skills.names,
|
|
579
487
|
supportsImages: this.supportsImages,
|
|
580
488
|
supportsKvCacheDeletion: true
|
|
581
489
|
};
|
|
582
490
|
}
|
|
583
491
|
diagnostics() {
|
|
584
492
|
return {
|
|
585
|
-
models: this.opened ? this.
|
|
493
|
+
models: this.opened ? this._residency.loaded() : [],
|
|
586
494
|
suspended: this.suspended,
|
|
587
495
|
sdkLoaded: this._sdk.peek() !== null,
|
|
588
496
|
toolNames: this.toolNames,
|
|
589
|
-
skills: this.
|
|
590
|
-
device: this.
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
_loadedModels() {
|
|
594
|
-
return this._pools().flatMap((pool) => loadedModels(pool));
|
|
595
|
-
}
|
|
596
|
-
_loadingModels() {
|
|
597
|
-
return new Set(this._pools().flatMap((pool) => loadingModels(pool)));
|
|
598
|
-
}
|
|
599
|
-
_settledModels() {
|
|
600
|
-
return new Set(this._pools().flatMap((pool) => settledModels(pool)));
|
|
601
|
-
}
|
|
602
|
-
_pools() {
|
|
603
|
-
return [
|
|
604
|
-
this._models,
|
|
605
|
-
this._embedModels,
|
|
606
|
-
...this._retiredEmbedModels,
|
|
607
|
-
this._ttsModels,
|
|
608
|
-
this._transcriptionModels
|
|
609
|
-
];
|
|
610
|
-
}
|
|
611
|
-
_loadPluginSdk(current, store, importPlugin) {
|
|
612
|
-
let pending = current();
|
|
613
|
-
if (!pending) {
|
|
614
|
-
pending = (async () => {
|
|
615
|
-
const sdk = await this._sdk.load();
|
|
616
|
-
const [plugin, { registerPlugin }] = await Promise.all([
|
|
617
|
-
importPlugin(),
|
|
618
|
-
import('@qvac/sdk/plugins')
|
|
619
|
-
]);
|
|
620
|
-
try {
|
|
621
|
-
registerPlugin(plugin);
|
|
622
|
-
}
|
|
623
|
-
catch { }
|
|
624
|
-
return sdk;
|
|
625
|
-
})().catch((err) => {
|
|
626
|
-
store(null);
|
|
627
|
-
throw err;
|
|
628
|
-
});
|
|
629
|
-
store(pending);
|
|
630
|
-
}
|
|
631
|
-
return pending;
|
|
632
|
-
}
|
|
633
|
-
_loadDiffusionSdk() {
|
|
634
|
-
return this._loadPluginSdk(() => this._diffusionSdk, (sdk) => {
|
|
635
|
-
this._diffusionSdk = sdk;
|
|
636
|
-
}, () => import('@qvac/sdk/sdcpp-generation/plugin').then((m) => m.diffusionPlugin));
|
|
637
|
-
}
|
|
638
|
-
async _slmTranslate(model, { text, from, to }, signal) {
|
|
639
|
-
const loadOpts = resolveLoadOptions({}, this._deviceConfig());
|
|
640
|
-
const key = modelKey(model, loadOpts);
|
|
641
|
-
const pool = this._models;
|
|
642
|
-
if (!isResident(pool, key)) {
|
|
643
|
-
await this._makeRoomForCompletion(model, { ctxSize: loadOpts.ctxSize, signal });
|
|
644
|
-
}
|
|
645
|
-
try {
|
|
646
|
-
const { modelId } = await raceAbort(pool.open(key, model, loadOpts).load(), signal);
|
|
647
|
-
const sdk = await this._sdk.load();
|
|
648
|
-
const answer = await raceAbort(sdk.translate({ modelId, text, from, to, stream: false, modelType: 'llm' }).text, signal);
|
|
649
|
-
return cleanAnswer(answer, text);
|
|
650
|
-
}
|
|
651
|
-
finally {
|
|
652
|
-
releaseModel(pool, key);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
_loadTranslationSdk() {
|
|
656
|
-
return this._loadPluginSdk(() => this._translationSdk, (sdk) => {
|
|
657
|
-
this._translationSdk = sdk;
|
|
658
|
-
}, () => import('@qvac/sdk/nmtcpp-translation/plugin').then((m) => m.nmtPlugin));
|
|
659
|
-
}
|
|
660
|
-
_loadMusicSdk() {
|
|
661
|
-
return this._loadPluginSdk(() => this._musicSdk, (sdk) => {
|
|
662
|
-
this._musicSdk = sdk;
|
|
663
|
-
}, () => import('@qvac/sdk/audiogen-ggml/plugin').then((m) => m.audioGenPlugin));
|
|
664
|
-
}
|
|
665
|
-
_deviceConfig() {
|
|
666
|
-
return {
|
|
667
|
-
device: this._llmDevice,
|
|
668
|
-
gpuLayers: this._llmGpuLayers,
|
|
669
|
-
contextSize: this._contextSize,
|
|
670
|
-
kvCacheK: this._kvCacheK,
|
|
671
|
-
kvCacheV: this._kvCacheV,
|
|
672
|
-
mainGpu: resolveMainGpu,
|
|
673
|
-
openclCacheDir
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
_createPool() {
|
|
677
|
-
const loadSdk = () => this._loadModelLifecycleSdk();
|
|
678
|
-
return createModelPool(loadSdk, (state) => this._notifyModel(state), {
|
|
679
|
-
deviceConfig: this._deviceConfig(),
|
|
680
|
-
loads: this._loads,
|
|
681
|
-
onUnloadFailure: (modelId, error) => this._recordModelUnloadFailure(modelId, error)
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
_loadModelLifecycleSdk() {
|
|
685
|
-
return this._sdk.load();
|
|
686
|
-
}
|
|
687
|
-
_createEmbedPool() {
|
|
688
|
-
const loadSdk = () => this._sdk.loadEmbed();
|
|
689
|
-
return createEmbedPool(loadSdk, (state) => this._notifyModel(state), {
|
|
690
|
-
faults: this._embedFaults,
|
|
691
|
-
batchSize: this._embedBatchSize,
|
|
692
|
-
openclCacheDir,
|
|
693
|
-
loads: this._loads,
|
|
694
|
-
onUnloadFailure: (modelId, error) => this._recordModelUnloadFailure(modelId, error)
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
_createTtsPool() {
|
|
698
|
-
const loadSdk = () => this._sdk.loadVoice();
|
|
699
|
-
return createVoicePool(loadSdk, (state) => this._notifyModel(state), {
|
|
700
|
-
modelType: 'tts-ggml',
|
|
701
|
-
addon: 'tts',
|
|
702
|
-
modelConfig: TTS_MODEL_CONFIG,
|
|
703
|
-
loads: this._loads,
|
|
704
|
-
onUnloadFailure: (modelId, error) => this._recordModelUnloadFailure(modelId, error)
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
_createTranscriptionPool() {
|
|
708
|
-
const loadSdk = () => this._sdk.loadVoice();
|
|
709
|
-
return createVoicePool(loadSdk, (state) => this._notifyModel({ ...state, model: TRANSCRIPTION_MODEL_LABEL }), {
|
|
710
|
-
modelType: 'parakeet-transcription',
|
|
711
|
-
addon: 'parakeet',
|
|
712
|
-
modelConfig: { useGPU: this._transcriptionDevice !== 'cpu' },
|
|
713
|
-
openclCacheDir,
|
|
714
|
-
loads: this._loads,
|
|
715
|
-
onUnloadFailure: (modelId, error) => this._recordModelUnloadFailure(modelId, error)
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
_recordModelUnloadFailure(modelId, error) {
|
|
719
|
-
this._failedModelUnloads.add(modelId);
|
|
720
|
-
this._poolUnloadFailed = true;
|
|
721
|
-
this._runtimeUnloadFailed = true;
|
|
722
|
-
hlog('model unload failed', { modelId, err: errorMessage(error) });
|
|
723
|
-
}
|
|
724
|
-
_notifyModel(state) {
|
|
725
|
-
if (state.status === 'ready' || state.status === 'unloaded' || state.status === 'error') {
|
|
726
|
-
invalidateModelStatusCache(this._modelStatus);
|
|
727
|
-
}
|
|
728
|
-
if (state.status === 'unloaded') {
|
|
729
|
-
for (const key of this._pinned) {
|
|
730
|
-
if (!isResident(this._models, key)) {
|
|
731
|
-
this._pinned.delete(key);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
this.emit('model', {
|
|
736
|
-
...state,
|
|
737
|
-
catalogChanged: state.catalogChanged === true,
|
|
738
|
-
loaded: this._loadedModels()
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
async _collectRetiredEmbedPool(pool) {
|
|
742
|
-
if (!this._retiredEmbedModels.has(pool) || pool.idle !== pool.size)
|
|
743
|
-
return;
|
|
744
|
-
try {
|
|
745
|
-
await pool.destroy();
|
|
746
|
-
}
|
|
747
|
-
catch (error) {
|
|
748
|
-
if (!(error instanceof ModelUnloadError)) {
|
|
749
|
-
this._poolCleanupFailed = true;
|
|
750
|
-
this._poolUnloadFailed = true;
|
|
751
|
-
this._runtimeUnloadFailed = true;
|
|
752
|
-
}
|
|
753
|
-
throw error;
|
|
754
|
-
}
|
|
755
|
-
this._retiredEmbedModels.delete(pool);
|
|
756
|
-
}
|
|
757
|
-
async _releaseEmbedResource(pool, key) {
|
|
758
|
-
releaseModel(pool, key);
|
|
759
|
-
const faulted = this._faultedEmbedKeys.get(pool);
|
|
760
|
-
if (faulted?.has(key)) {
|
|
761
|
-
await evictIdle(pool);
|
|
762
|
-
if (!isResident(pool, key)) {
|
|
763
|
-
faulted.delete(key);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
await this._collectRetiredEmbedPool(pool);
|
|
767
|
-
}
|
|
768
|
-
async _releaseEmbedResourceBeforeWork(releasing, releaseWork) {
|
|
769
|
-
try {
|
|
770
|
-
await releasing;
|
|
771
|
-
}
|
|
772
|
-
finally {
|
|
773
|
-
releaseWork();
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
_markEmbedFault({ pool, key, faults, generation }) {
|
|
777
|
-
faults.recordFault(generation);
|
|
778
|
-
let faulted = this._faultedEmbedKeys.get(pool);
|
|
779
|
-
if (!faulted) {
|
|
780
|
-
faulted = new Set();
|
|
781
|
-
this._faultedEmbedKeys.set(pool, faulted);
|
|
782
|
-
}
|
|
783
|
-
faulted.add(key);
|
|
784
|
-
}
|
|
785
|
-
_releaseEmbedResourceAfter(settled, fault) {
|
|
786
|
-
return settled
|
|
787
|
-
.then(() => this._releaseEmbedResource(fault.pool, fault.key), (error) => {
|
|
788
|
-
if (isSdkGpuDeviceLostError(error)) {
|
|
789
|
-
this._markEmbedFault(fault);
|
|
790
|
-
}
|
|
791
|
-
return this._releaseEmbedResource(fault.pool, fault.key);
|
|
792
|
-
})
|
|
793
|
-
.catch(noop);
|
|
794
|
-
}
|
|
795
|
-
async _destroyEmbedPools() {
|
|
796
|
-
const pools = [this._embedModels, ...this._retiredEmbedModels].filter((pool) => Boolean(pool));
|
|
797
|
-
const outcomes = await Promise.allSettled(pools.map(async (pool) => {
|
|
798
|
-
await pool.destroy();
|
|
799
|
-
this._retiredEmbedModels.delete(pool);
|
|
800
|
-
}));
|
|
801
|
-
const generic = outcomes.find((outcome) => outcome.status === 'rejected' && !(outcome.reason instanceof ModelUnloadError));
|
|
802
|
-
if (generic?.status === 'rejected') {
|
|
803
|
-
throw generic.reason;
|
|
804
|
-
}
|
|
805
|
-
const failed = outcomes.find((outcome) => outcome.status === 'rejected');
|
|
806
|
-
if (failed?.status === 'rejected') {
|
|
807
|
-
throw failed.reason;
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
_enqueueEmbedControl(run) {
|
|
811
|
-
const next = this._embedControl.then(run, run);
|
|
812
|
-
this._embedControl = next.catch(noop);
|
|
813
|
-
return next;
|
|
814
|
-
}
|
|
815
|
-
async _runLifecycle(type, { open = true } = {}) {
|
|
816
|
-
if (!this.opened) {
|
|
817
|
-
if (open) {
|
|
818
|
-
await this.ready();
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
if (this._closeRequested || this.closing) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
await this._lifecycle.send(type);
|
|
825
|
-
}
|
|
826
|
-
_abortCompletions() {
|
|
827
|
-
for (const run of this._completionRuns) {
|
|
828
|
-
run.abort();
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
_assertNotClosing() {
|
|
832
|
-
if (this._closeRequested || this.closing || this.closed) {
|
|
833
|
-
throw new Error('harness is closing');
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
_enterWork() {
|
|
837
|
-
this._assertNotClosing();
|
|
838
|
-
if (this._runtimeDraining) {
|
|
839
|
-
throw new Error('harness is suspended');
|
|
840
|
-
}
|
|
841
|
-
if (this._runtimeUnloadFailed) {
|
|
842
|
-
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
843
|
-
}
|
|
844
|
-
this._activeWork++;
|
|
845
|
-
let released = false;
|
|
846
|
-
return () => {
|
|
847
|
-
if (released)
|
|
848
|
-
return;
|
|
849
|
-
released = true;
|
|
850
|
-
if (--this._activeWork !== 0) {
|
|
851
|
-
return;
|
|
852
|
-
}
|
|
853
|
-
for (const resolve of this._workDrainWaiters) {
|
|
854
|
-
resolve();
|
|
855
|
-
}
|
|
856
|
-
this._workDrainWaiters.clear();
|
|
497
|
+
skills: this._skills.names,
|
|
498
|
+
device: this._residency.deviceConfig().device
|
|
857
499
|
};
|
|
858
500
|
}
|
|
859
|
-
_waitForWorkDrain() {
|
|
860
|
-
if (!this._activeWork) {
|
|
861
|
-
return Promise.resolve();
|
|
862
|
-
}
|
|
863
|
-
return new Promise((resolve) => this._workDrainWaiters.add(resolve));
|
|
864
|
-
}
|
|
865
|
-
_effectsSettled() {
|
|
866
|
-
return !this._detachedRuns.size && ![...this._completionRuns].some((run) => run.started);
|
|
867
|
-
}
|
|
868
|
-
_notifyEffectDrain() {
|
|
869
|
-
if (!this._effectsSettled())
|
|
870
|
-
return;
|
|
871
|
-
for (const resolve of this._effectDrainWaiters) {
|
|
872
|
-
resolve();
|
|
873
|
-
}
|
|
874
|
-
this._effectDrainWaiters.clear();
|
|
875
|
-
}
|
|
876
|
-
_waitForEffectDrain() {
|
|
877
|
-
if (this._effectsSettled()) {
|
|
878
|
-
return Promise.resolve();
|
|
879
|
-
}
|
|
880
|
-
return new Promise((resolve) => this._effectDrainWaiters.add(resolve));
|
|
881
|
-
}
|
|
882
|
-
_trackDetachedRun(pending, runId) {
|
|
883
|
-
const tracked = pending.catch((error) => {
|
|
884
|
-
hlog('detached completion effect failed', { runId, err: errorMessage(error) });
|
|
885
|
-
});
|
|
886
|
-
this._detachedRuns.add(tracked);
|
|
887
|
-
void tracked
|
|
888
|
-
.finally(() => {
|
|
889
|
-
this._detachedRuns.delete(tracked);
|
|
890
|
-
this._notifyEffectDrain();
|
|
891
|
-
})
|
|
892
|
-
.catch(noop);
|
|
893
|
-
}
|
|
894
|
-
async _closeCompletions(runs = this._completionRuns) {
|
|
895
|
-
const closed = await Promise.allSettled([...runs].map((run) => run.close()));
|
|
896
|
-
for (const outcome of closed) {
|
|
897
|
-
if (outcome.status === 'rejected') {
|
|
898
|
-
hlog('completion close failed', {
|
|
899
|
-
err: errorMessage(outcome.reason)
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
501
|
getEmbeddingDevice() {
|
|
905
|
-
return this.
|
|
502
|
+
return this._embeddings.device;
|
|
906
503
|
}
|
|
907
504
|
setEmbeddingDevice(device) {
|
|
908
|
-
|
|
909
|
-
return this._enqueueEmbedControl(() => this._setEmbeddingDevice(device));
|
|
910
|
-
}
|
|
911
|
-
async _setEmbeddingDevice(device) {
|
|
912
|
-
if (!this.opened)
|
|
913
|
-
await this.ready();
|
|
914
|
-
if (this.suspended) {
|
|
915
|
-
this._assertNotClosing();
|
|
916
|
-
if (this._embedFaults.device === device) {
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
this._embedFaults = createGpuFaultState({ device, gpuLayers: this._embedGpuLayers });
|
|
920
|
-
return;
|
|
921
|
-
}
|
|
922
|
-
const releaseWork = this._enterWork();
|
|
923
|
-
try {
|
|
924
|
-
if (this._embedFaults.device === device) {
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
this._embedFaults = createGpuFaultState({ device, gpuLayers: this._embedGpuLayers });
|
|
928
|
-
if (this.suspended) {
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
const retired = this._embedModels;
|
|
932
|
-
this._retiredEmbedModels.add(retired);
|
|
933
|
-
this._embedModels = this._createEmbedPool();
|
|
934
|
-
await this._collectRetiredEmbedPool(retired);
|
|
935
|
-
}
|
|
936
|
-
finally {
|
|
937
|
-
releaseWork();
|
|
938
|
-
}
|
|
505
|
+
return this._embeddings.setDevice(device);
|
|
939
506
|
}
|
|
940
507
|
async presuspend() {
|
|
941
|
-
await this.
|
|
508
|
+
await this._lifecycle.send('PRESUSPEND', { open: false });
|
|
942
509
|
}
|
|
943
510
|
async suspend() {
|
|
944
|
-
|
|
511
|
+
this._downloads.abandon();
|
|
512
|
+
const result = await raceDrain(this._lifecycle.send('SUSPEND'), SUSPEND_SETTLE_MS);
|
|
945
513
|
if (didDrainTimeOut(result)) {
|
|
946
514
|
throw new Error('Harness suspend is still waiting for active work to settle');
|
|
947
515
|
}
|
|
948
516
|
}
|
|
949
|
-
async _suspendRuntimes() {
|
|
950
|
-
this._runtimeDraining = true;
|
|
951
|
-
hlog('suspending', { models: loadedModels(this._models).map((entry) => entry.model) });
|
|
952
|
-
this._abortCompletions();
|
|
953
|
-
this._loads.drain();
|
|
954
|
-
await this._closeCompletions([...this._completionRuns].filter((run) => run.started));
|
|
955
|
-
await this._waitForEffectDrain();
|
|
956
|
-
const pending = this._sdk.peek();
|
|
957
|
-
if (pending) {
|
|
958
|
-
const sdk = await pending.catch(noop);
|
|
959
|
-
if (sdk) {
|
|
960
|
-
this._loads.drain(sdk);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
await this._waitForWorkDrain();
|
|
964
|
-
if (!(await this._releaseRuntimes())) {
|
|
965
|
-
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
966
|
-
}
|
|
967
|
-
invalidateModelStatusCache(this._modelStatus);
|
|
968
|
-
await this._sdkLifecycle('suspend');
|
|
969
|
-
hlog('suspended');
|
|
970
|
-
}
|
|
971
|
-
async _sdkLifecycle(op) {
|
|
972
|
-
const sdk = await this._sdk.peek()?.catch(noop);
|
|
973
|
-
if (!sdk) {
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
try {
|
|
977
|
-
await sdk[op]();
|
|
978
|
-
}
|
|
979
|
-
catch (err) {
|
|
980
|
-
hlog(`sdk ${op} failed`, { err: errorMessage(err) });
|
|
981
|
-
if (op === 'suspend') {
|
|
982
|
-
throw err;
|
|
983
|
-
}
|
|
984
|
-
await sdk.resume().catch((retryErr) => {
|
|
985
|
-
hlog('sdk resume retry failed', {
|
|
986
|
-
err: errorMessage(retryErr)
|
|
987
|
-
});
|
|
988
|
-
throw retryErr;
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
async _releaseRuntimes() {
|
|
993
|
-
const released = await Promise.allSettled([
|
|
994
|
-
this._models?.destroy(),
|
|
995
|
-
this._destroyEmbedPools(),
|
|
996
|
-
this._ttsModels?.destroy(),
|
|
997
|
-
this._transcriptionModels?.destroy(),
|
|
998
|
-
this._imageRuntime?.unload(),
|
|
999
|
-
this._musicRuntime?.unload(),
|
|
1000
|
-
this._translationRuntime.unload()
|
|
1001
|
-
]);
|
|
1002
|
-
for (const [index, outcome] of released.entries()) {
|
|
1003
|
-
if (outcome.status !== 'rejected')
|
|
1004
|
-
continue;
|
|
1005
|
-
if (index < 4 && !(outcome.reason instanceof ModelUnloadError)) {
|
|
1006
|
-
this._poolCleanupFailed = true;
|
|
1007
|
-
}
|
|
1008
|
-
const err = outcome.reason;
|
|
1009
|
-
hlog('unload failed', { err: errorMessage(err) });
|
|
1010
|
-
}
|
|
1011
|
-
const sdk = await this._sdk.peek()?.catch(noop);
|
|
1012
|
-
if (sdk) {
|
|
1013
|
-
for (const modelId of this._failedModelUnloads) {
|
|
1014
|
-
try {
|
|
1015
|
-
await sdk.unloadModel({ modelId });
|
|
1016
|
-
this._failedModelUnloads.delete(modelId);
|
|
1017
|
-
invalidateModelStatusCache(this._modelStatus);
|
|
1018
|
-
}
|
|
1019
|
-
catch (error) {
|
|
1020
|
-
hlog('model unload retry failed', {
|
|
1021
|
-
modelId,
|
|
1022
|
-
err: errorMessage(error)
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
this._poolUnloadFailed = this._poolCleanupFailed || this._failedModelUnloads.size > 0;
|
|
1028
|
-
this._runtimeUnloadFailed =
|
|
1029
|
-
this._poolUnloadFailed || released.slice(4).some((outcome) => outcome.status === 'rejected');
|
|
1030
|
-
return !this._runtimeUnloadFailed;
|
|
1031
|
-
}
|
|
1032
|
-
async _unloadIdleModels() {
|
|
1033
|
-
if (!this.opened || this.closing || this.suspended || this._runtimeDraining) {
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
hlog('idle unload', { models: this._loadedModels().map((entry) => entry.model) });
|
|
1037
|
-
const released = await Promise.allSettled([
|
|
1038
|
-
evictIdle(this._models),
|
|
1039
|
-
evictIdle(this._embedModels),
|
|
1040
|
-
...[...this._retiredEmbedModels].map((pool) => this._collectRetiredEmbedPool(pool)),
|
|
1041
|
-
evictIdle(this._ttsModels),
|
|
1042
|
-
evictIdle(this._transcriptionModels),
|
|
1043
|
-
this._imageRuntime?.unloadIdle(),
|
|
1044
|
-
this._musicRuntime?.unloadIdle(),
|
|
1045
|
-
this._translationRuntime.unload()
|
|
1046
|
-
]);
|
|
1047
|
-
for (const outcome of released) {
|
|
1048
|
-
if (outcome.status !== 'rejected')
|
|
1049
|
-
continue;
|
|
1050
|
-
hlog('idle unload failed', { err: errorMessage(outcome.reason) });
|
|
1051
|
-
}
|
|
1052
|
-
invalidateModelStatusCache(this._modelStatus);
|
|
1053
|
-
}
|
|
1054
517
|
async resume() {
|
|
1055
|
-
await this.
|
|
1056
|
-
}
|
|
1057
|
-
async _resumeRuntimes() {
|
|
1058
|
-
this._assertNotClosing();
|
|
1059
|
-
if (this._runtimeUnloadFailed) {
|
|
1060
|
-
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
1061
|
-
}
|
|
1062
|
-
hlog('resuming', { pools: 'recreated' });
|
|
1063
|
-
this._loads.undrain();
|
|
1064
|
-
this._models = this._createPool();
|
|
1065
|
-
this._embedModels = this._createEmbedPool();
|
|
1066
|
-
this._ttsModels = this._createTtsPool();
|
|
1067
|
-
this._transcriptionModels = this._createTranscriptionPool();
|
|
1068
|
-
try {
|
|
1069
|
-
await this._sdkLifecycle('resume');
|
|
1070
|
-
this._runtimeDraining = false;
|
|
1071
|
-
}
|
|
1072
|
-
catch (error) {
|
|
1073
|
-
const sdk = await this._sdk.peek()?.catch(noop);
|
|
1074
|
-
if (sdk) {
|
|
1075
|
-
this._loads.drain(sdk);
|
|
1076
|
-
}
|
|
1077
|
-
await this._releaseRuntimes();
|
|
1078
|
-
throw error;
|
|
1079
|
-
}
|
|
518
|
+
await this._lifecycle.send('RESUME');
|
|
1080
519
|
}
|
|
1081
520
|
async wakeup() {
|
|
1082
|
-
await this.
|
|
521
|
+
await this._lifecycle.send('WAKEUP');
|
|
1083
522
|
}
|
|
1084
523
|
ready() {
|
|
1085
|
-
if (this.
|
|
1086
|
-
return Promise.reject(new
|
|
524
|
+
if (this._lifecycle.closeRequested || this.closing || this.closed) {
|
|
525
|
+
return Promise.reject(new HarnessError('HARNESS_CLOSING'));
|
|
1087
526
|
}
|
|
1088
527
|
return super.ready();
|
|
1089
528
|
}
|
|
1090
529
|
async _close() {
|
|
1091
|
-
|
|
1092
|
-
this.
|
|
1093
|
-
this.
|
|
1094
|
-
this.
|
|
1095
|
-
this._loads.drain();
|
|
1096
|
-
await this._lifecycle.settled();
|
|
1097
|
-
await this._finishClose();
|
|
530
|
+
HarnessLog.info('closing');
|
|
531
|
+
this._residency.closeIdle();
|
|
532
|
+
this._downloads.abandon();
|
|
533
|
+
await this._lifecycle.close();
|
|
1098
534
|
}
|
|
1099
535
|
close() {
|
|
1100
|
-
this.
|
|
536
|
+
this._lifecycle.requestClose();
|
|
1101
537
|
if (this._closeRetryNeeded) {
|
|
1102
538
|
this.closing = null;
|
|
1103
539
|
this._closeRetryNeeded = false;
|
|
@@ -1120,80 +556,33 @@ export class Harness extends ReadyResource {
|
|
|
1120
556
|
if (this.closing)
|
|
1121
557
|
return this.closing;
|
|
1122
558
|
const opening = this.opening;
|
|
559
|
+
const pluginsClosing = this._teardownPlugins();
|
|
1123
560
|
const pending = (async () => {
|
|
1124
561
|
await opening?.catch(noop);
|
|
1125
|
-
|
|
562
|
+
await pluginsClosing;
|
|
563
|
+
this._lifecycle.abortCompletions();
|
|
1126
564
|
this._loads.drain();
|
|
1127
|
-
await this.
|
|
565
|
+
await this._lifecycle.finishClose();
|
|
1128
566
|
this.closed = true;
|
|
1129
567
|
this.emit('close');
|
|
1130
568
|
})();
|
|
1131
569
|
this.closing = pending;
|
|
1132
570
|
return pending;
|
|
1133
571
|
}
|
|
1134
|
-
async _finishClose() {
|
|
1135
|
-
let completed = false;
|
|
1136
|
-
try {
|
|
1137
|
-
const pending = this._sdk.peek();
|
|
1138
|
-
if (pending) {
|
|
1139
|
-
const sdk = await pending.catch(noop);
|
|
1140
|
-
if (sdk) {
|
|
1141
|
-
this._loads.drain(sdk);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
await this._closeCompletions();
|
|
1145
|
-
await this._waitForEffectDrain();
|
|
1146
|
-
await this._waitForWorkDrain();
|
|
1147
|
-
this._overlayWatcher?.stop();
|
|
1148
|
-
this._overlayWatcher = null;
|
|
1149
|
-
if (!this._runtimesReleased) {
|
|
1150
|
-
let [released] = await Promise.all([this._releaseRuntimes(), closePythonWorker()]);
|
|
1151
|
-
if (!released && !this._poolUnloadFailed) {
|
|
1152
|
-
released = await this._releaseRuntimes();
|
|
1153
|
-
}
|
|
1154
|
-
this._runtimesReleased = released;
|
|
1155
|
-
}
|
|
1156
|
-
let sdkCloseFailed = false;
|
|
1157
|
-
let sdkCloseError;
|
|
1158
|
-
const sdk = !this._sdkClosed && !this._runtimeUnloadFailed ? await this._sdk.peek()?.catch(noop) : null;
|
|
1159
|
-
if (sdk) {
|
|
1160
|
-
try {
|
|
1161
|
-
await sdk.close();
|
|
1162
|
-
this._sdkClosed = true;
|
|
1163
|
-
}
|
|
1164
|
-
catch (error) {
|
|
1165
|
-
sdkCloseFailed = true;
|
|
1166
|
-
sdkCloseError = error;
|
|
1167
|
-
hlog('sdk close failed', { err: errorMessage(error) });
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
if (sdkCloseFailed) {
|
|
1171
|
-
throw sdkCloseError;
|
|
1172
|
-
}
|
|
1173
|
-
if (this._runtimeUnloadFailed) {
|
|
1174
|
-
throw new Error('Runtime unload failed; model cleanup could not be confirmed');
|
|
1175
|
-
}
|
|
1176
|
-
completed = true;
|
|
1177
|
-
}
|
|
1178
|
-
finally {
|
|
1179
|
-
if (completed) {
|
|
1180
|
-
this._lifecycle.stop();
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
572
|
download(args) {
|
|
1185
|
-
this.
|
|
573
|
+
this._lifecycle.assertNotClosing();
|
|
1186
574
|
let releaseWork = null;
|
|
1187
575
|
const projection = (args.addon ?? 'llm') === 'llm' ? this._projectionFor(args.model) : undefined;
|
|
1188
576
|
const multiFile = diffusionDownloadMetadata(args.model, args.addon) ??
|
|
1189
|
-
audioGenDownloadMetadata(args.model, args.addon)
|
|
577
|
+
audioGenDownloadMetadata(args.model, args.addon) ??
|
|
578
|
+
categoryDownloadMetadata(args.model, args.addon);
|
|
1190
579
|
return download(async () => {
|
|
1191
580
|
if (!this.opened)
|
|
1192
581
|
await this.ready();
|
|
1193
|
-
releaseWork = this.
|
|
582
|
+
releaseWork = this._lifecycle.enterWork();
|
|
1194
583
|
try {
|
|
1195
584
|
const sdk = await this._sdk.load();
|
|
1196
|
-
this.
|
|
585
|
+
this._lifecycle.assertNotClosing();
|
|
1197
586
|
return sdk;
|
|
1198
587
|
}
|
|
1199
588
|
catch (error) {
|
|
@@ -1206,264 +595,107 @@ export class Harness extends ReadyResource {
|
|
|
1206
595
|
projection,
|
|
1207
596
|
companions: multiFile?.companions,
|
|
1208
597
|
assetSizes: multiFile?.assetSizes
|
|
1209
|
-
}, () =>
|
|
598
|
+
}, (event) => {
|
|
599
|
+
this._residency.invalidateStatus();
|
|
600
|
+
if (event.type === 'complete') {
|
|
601
|
+
this._downloads.downloaded();
|
|
602
|
+
}
|
|
603
|
+
}, () => {
|
|
1210
604
|
releaseWork?.();
|
|
1211
605
|
releaseWork = null;
|
|
1212
606
|
});
|
|
1213
607
|
}
|
|
1214
608
|
embed(context) {
|
|
1215
|
-
return this.
|
|
609
|
+
return this._residency.busy(() => this._embeddings.embed(context));
|
|
1216
610
|
}
|
|
1217
|
-
async
|
|
611
|
+
async _speechService() {
|
|
1218
612
|
if (!this.opened)
|
|
1219
613
|
await this.ready();
|
|
1220
|
-
this.
|
|
1221
|
-
|
|
1222
|
-
throw new Error('harness is suspended');
|
|
1223
|
-
}
|
|
1224
|
-
if (texts.length === 0) {
|
|
1225
|
-
return [];
|
|
1226
|
-
}
|
|
1227
|
-
const pool = this._embedModels;
|
|
1228
|
-
const faults = this._embedFaults;
|
|
1229
|
-
const generation = faults.generation;
|
|
1230
|
-
const key = faults.key(residentSrc(model, 'embeddings'));
|
|
1231
|
-
const releaseWork = this._enterWork();
|
|
1232
|
-
let handle;
|
|
1233
|
-
try {
|
|
1234
|
-
handle = pool.open(key, model);
|
|
1235
|
-
}
|
|
1236
|
-
catch (error) {
|
|
1237
|
-
releaseWork();
|
|
1238
|
-
throw error;
|
|
1239
|
-
}
|
|
1240
|
-
let loaded = null;
|
|
1241
|
-
let job = null;
|
|
1242
|
-
let releaseAfter = null;
|
|
1243
|
-
let drainWorkAfter = null;
|
|
1244
|
-
try {
|
|
1245
|
-
loaded = await raceAbort(handle.load(), signal);
|
|
1246
|
-
const sdk = await this._sdk.loadEmbed();
|
|
1247
|
-
this._assertNotClosing();
|
|
1248
|
-
job = this._embedLane(sdk, { modelId: loaded.modelId, texts });
|
|
1249
|
-
const vectors = await raceAbort(job, signal);
|
|
1250
|
-
faults.reset();
|
|
1251
|
-
return vectors;
|
|
1252
|
-
}
|
|
1253
|
-
catch (err) {
|
|
1254
|
-
if (err instanceof AbortedError) {
|
|
1255
|
-
if (job || this._retiredEmbedModels.has(pool)) {
|
|
1256
|
-
releaseAfter = job ?? handle.peek();
|
|
1257
|
-
}
|
|
1258
|
-
else {
|
|
1259
|
-
drainWorkAfter = handle.peek();
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
if (isSdkGpuDeviceLostError(err)) {
|
|
1263
|
-
this._markEmbedFault({ pool, key, faults, generation });
|
|
1264
|
-
}
|
|
1265
|
-
throw err;
|
|
1266
|
-
}
|
|
1267
|
-
finally {
|
|
1268
|
-
if (releaseAfter) {
|
|
1269
|
-
void this._releaseEmbedResourceAfter(releaseAfter, {
|
|
1270
|
-
pool,
|
|
1271
|
-
key,
|
|
1272
|
-
faults,
|
|
1273
|
-
generation
|
|
1274
|
-
}).finally(releaseWork);
|
|
1275
|
-
}
|
|
1276
|
-
else {
|
|
1277
|
-
const releasing = this._releaseEmbedResource(pool, key);
|
|
1278
|
-
if (drainWorkAfter) {
|
|
1279
|
-
void Promise.allSettled([releasing, drainWorkAfter]).then(releaseWork);
|
|
1280
|
-
}
|
|
1281
|
-
else {
|
|
1282
|
-
await this._releaseEmbedResourceBeforeWork(releasing, releaseWork);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
614
|
+
if (!this._plugins.ctx.speech) {
|
|
615
|
+
throw new Error(SPEECH_PLUGIN_MISSING);
|
|
1285
616
|
}
|
|
617
|
+
return this._plugins.ctx.speech;
|
|
1286
618
|
}
|
|
1287
|
-
async
|
|
1288
|
-
if (category !== 'tts') {
|
|
1289
|
-
return defaultVoiceModel(category);
|
|
1290
|
-
}
|
|
1291
|
-
try {
|
|
1292
|
-
const { capabilityProfile } = await this.capability();
|
|
1293
|
-
return defaultTtsFor(capabilityProfile).asset.src;
|
|
1294
|
-
}
|
|
1295
|
-
catch {
|
|
1296
|
-
return defaultVoiceModel('tts');
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
async _voiceJob(pool, { category, model, signal }, run) {
|
|
619
|
+
async _knowledgeService() {
|
|
1300
620
|
if (!this.opened)
|
|
1301
621
|
await this.ready();
|
|
1302
|
-
if (this.
|
|
1303
|
-
throw new Error(
|
|
1304
|
-
const addon = category === 'tts' ? 'tts' : 'parakeet';
|
|
1305
|
-
const name = residentSrc(model || (await this._defaultVoiceSrc(category)), addon);
|
|
1306
|
-
this._assertNotClosing();
|
|
1307
|
-
const releaseWork = this._enterWork();
|
|
1308
|
-
let handle;
|
|
1309
|
-
try {
|
|
1310
|
-
handle = pool.open(name, name);
|
|
1311
|
-
}
|
|
1312
|
-
catch (error) {
|
|
1313
|
-
releaseWork();
|
|
1314
|
-
throw error;
|
|
1315
|
-
}
|
|
1316
|
-
let job = null;
|
|
1317
|
-
let releaseAfter = null;
|
|
1318
|
-
let sdk = null;
|
|
1319
|
-
let modelId = null;
|
|
1320
|
-
try {
|
|
1321
|
-
modelId = (await raceAbort(handle.load(), signal)).modelId;
|
|
1322
|
-
sdk = (await this._sdk.loadVoice());
|
|
1323
|
-
this._assertNotClosing();
|
|
1324
|
-
const boundSdk = sdk;
|
|
1325
|
-
const boundId = modelId;
|
|
1326
|
-
job = this._voiceLane(() => run(boundSdk, boundId));
|
|
1327
|
-
return await raceAbort(job, signal);
|
|
1328
|
-
}
|
|
1329
|
-
catch (err) {
|
|
1330
|
-
if (err instanceof AbortedError) {
|
|
1331
|
-
if (sdk && modelId) {
|
|
1332
|
-
void sdk.cancel({ modelId, operation: 'inference' }).catch(noop);
|
|
1333
|
-
}
|
|
1334
|
-
releaseAfter = job ?? handle.peek();
|
|
1335
|
-
}
|
|
1336
|
-
throw err;
|
|
1337
|
-
}
|
|
1338
|
-
finally {
|
|
1339
|
-
const release = () => {
|
|
1340
|
-
releaseModel(pool, name);
|
|
1341
|
-
};
|
|
1342
|
-
if (releaseAfter) {
|
|
1343
|
-
void releaseAfter.then(release, release).finally(releaseWork).catch(noop);
|
|
1344
|
-
}
|
|
1345
|
-
else {
|
|
1346
|
-
try {
|
|
1347
|
-
release();
|
|
1348
|
-
}
|
|
1349
|
-
finally {
|
|
1350
|
-
releaseWork();
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
622
|
+
if (!this._plugins.ctx.knowledge) {
|
|
623
|
+
throw new Error(KNOWLEDGE_PLUGIN_MISSING);
|
|
1353
624
|
}
|
|
625
|
+
return this._plugins.ctx.knowledge;
|
|
626
|
+
}
|
|
627
|
+
async knowledgeUpsert(artifact) {
|
|
628
|
+
return (await this._knowledgeService()).upsert(artifact);
|
|
629
|
+
}
|
|
630
|
+
async knowledgeRemove(artifactId) {
|
|
631
|
+
return (await this._knowledgeService()).remove(artifactId);
|
|
632
|
+
}
|
|
633
|
+
async knowledgeSearch(query) {
|
|
634
|
+
return (await this._knowledgeService()).search(query);
|
|
635
|
+
}
|
|
636
|
+
async knowledgeStatus() {
|
|
637
|
+
return (await this._knowledgeService()).status();
|
|
1354
638
|
}
|
|
1355
639
|
transcribe(context) {
|
|
1356
|
-
return this.
|
|
640
|
+
return this._residency.busy(() => this._transcribe(context));
|
|
1357
641
|
}
|
|
1358
642
|
async _transcribe({ model, audio, signal }) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
if (pcm && pcm.length >= TRANSCRIBE_STREAM_MIN_BYTES) {
|
|
1365
|
-
return transcribeStreaming(sdk, pcm, { modelId: id, signal });
|
|
1366
|
-
}
|
|
1367
|
-
return transcribeOnce(sdk, id, pcm ? buildWavBuffer(pcm) : audio);
|
|
643
|
+
const speech = await this._speechService();
|
|
644
|
+
return speech.transcribe({
|
|
645
|
+
model: model || defaultVoiceModel('transcription'),
|
|
646
|
+
audio,
|
|
647
|
+
signal
|
|
1368
648
|
});
|
|
1369
649
|
}
|
|
1370
650
|
detectLanguage(context) {
|
|
1371
651
|
return detectLanguage(context);
|
|
1372
652
|
}
|
|
1373
653
|
speak(context) {
|
|
1374
|
-
return this.
|
|
654
|
+
return this._residency.busy(() => this._speak(context));
|
|
1375
655
|
}
|
|
1376
656
|
async _speak({ model, text, signal }) {
|
|
1377
|
-
const
|
|
1378
|
-
return {
|
|
657
|
+
const speech = await this._speechService();
|
|
658
|
+
return speech.speak({ model: model || (await this._defaultTts(speech)), text, signal });
|
|
1379
659
|
}
|
|
1380
660
|
speakStream(context) {
|
|
1381
|
-
return this.
|
|
661
|
+
return this._residency.busyStream(() => this._speakStream(context));
|
|
1382
662
|
}
|
|
1383
663
|
async *_speakStream({ model, text, signal }) {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
const
|
|
1389
|
-
|
|
1390
|
-
const pool = this._ttsModels;
|
|
1391
|
-
const chunks = pushQueue();
|
|
1392
|
-
const releaseWork = this._enterWork();
|
|
1393
|
-
let handle;
|
|
1394
|
-
try {
|
|
1395
|
-
handle = pool.open(name, name);
|
|
1396
|
-
}
|
|
1397
|
-
catch (error) {
|
|
1398
|
-
releaseWork();
|
|
1399
|
-
throw error;
|
|
1400
|
-
}
|
|
1401
|
-
let sdk = null;
|
|
1402
|
-
let modelId = null;
|
|
1403
|
-
const cancel = () => {
|
|
1404
|
-
if (sdk && modelId) {
|
|
1405
|
-
void sdk.cancel({ modelId, operation: 'inference' }).catch(noop);
|
|
1406
|
-
}
|
|
1407
|
-
};
|
|
1408
|
-
signal?.addEventListener('abort', cancel, { once: true });
|
|
1409
|
-
const job = this._voiceLane(async () => {
|
|
1410
|
-
try {
|
|
1411
|
-
modelId = (await handle.load()).modelId;
|
|
1412
|
-
sdk = (await this._sdk.loadVoice());
|
|
1413
|
-
this._assertNotClosing();
|
|
1414
|
-
if (signal?.aborted) {
|
|
1415
|
-
return;
|
|
1416
|
-
}
|
|
1417
|
-
for await (const chunk of speakStreamOnce(sdk, modelId, text)) {
|
|
1418
|
-
chunks.push(chunk);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
finally {
|
|
1422
|
-
chunks.end();
|
|
1423
|
-
}
|
|
1424
|
-
});
|
|
1425
|
-
let settled = false;
|
|
1426
|
-
try {
|
|
1427
|
-
yield* chunks;
|
|
1428
|
-
await job;
|
|
1429
|
-
settled = true;
|
|
1430
|
-
}
|
|
1431
|
-
finally {
|
|
1432
|
-
signal?.removeEventListener('abort', cancel);
|
|
1433
|
-
if (!settled) {
|
|
1434
|
-
cancel();
|
|
1435
|
-
}
|
|
1436
|
-
void job
|
|
1437
|
-
.catch(noop)
|
|
1438
|
-
.finally(() => {
|
|
1439
|
-
try {
|
|
1440
|
-
releaseModel(pool, name);
|
|
1441
|
-
}
|
|
1442
|
-
finally {
|
|
1443
|
-
releaseWork();
|
|
1444
|
-
}
|
|
1445
|
-
})
|
|
1446
|
-
.catch(noop);
|
|
1447
|
-
}
|
|
664
|
+
const speech = await this._speechService();
|
|
665
|
+
yield* speech.speakStream({ model: model || (await this._defaultTts(speech)), text, signal });
|
|
666
|
+
}
|
|
667
|
+
async _defaultTts(speech) {
|
|
668
|
+
const profile = await this.capability().then((capability) => capability.capabilityProfile, () => null);
|
|
669
|
+
return speech.defaultModel(profile);
|
|
1448
670
|
}
|
|
1449
671
|
async list(options = {}) {
|
|
1450
672
|
if (!this.opened)
|
|
1451
673
|
await this.ready();
|
|
1452
|
-
const releaseWork = this.
|
|
674
|
+
const releaseWork = this._lifecycle.enterWork();
|
|
1453
675
|
try {
|
|
1454
676
|
const sdk = await this._sdk.load();
|
|
1455
|
-
this.
|
|
677
|
+
this._lifecycle.assertNotClosing();
|
|
1456
678
|
const rows = await listModels(sdk, options, {
|
|
1457
|
-
cache: this.
|
|
679
|
+
cache: this._residency.status,
|
|
1458
680
|
projectionFor: (name) => this._projectionFor(name)
|
|
1459
681
|
});
|
|
1460
|
-
const loaded = this.
|
|
1461
|
-
const loading = this.
|
|
682
|
+
const loaded = this._residency.settled();
|
|
683
|
+
const loading = this._residency.loading();
|
|
1462
684
|
const custom = await customModelRows(options, { modelsDir: this._modelsDir, loaded });
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
685
|
+
const merged = mergeCustomRows(rows, custom);
|
|
686
|
+
const fits = await this._residency.rowFits(merged);
|
|
687
|
+
const memory = this._residency.memoryByModel();
|
|
688
|
+
return merged.map((row) => {
|
|
689
|
+
const fit = row.isLoaded || loaded.has(row.name) ? undefined : fits.get(row.registryPath);
|
|
690
|
+
return {
|
|
691
|
+
...row,
|
|
692
|
+
isLoading: loading.has(row.name),
|
|
693
|
+
memoryBytes: memory.get(row.name) ?? memory.get(residentSrc(row.name, row.type)),
|
|
694
|
+
fit: fit?.verdict,
|
|
695
|
+
fitBasis: fit?.basis,
|
|
696
|
+
fitEvidence: fit?.evidence
|
|
697
|
+
};
|
|
698
|
+
});
|
|
1467
699
|
}
|
|
1468
700
|
finally {
|
|
1469
701
|
releaseWork();
|
|
@@ -1472,12 +704,12 @@ export class Harness extends ReadyResource {
|
|
|
1472
704
|
async deleteModel(name) {
|
|
1473
705
|
if (!this.opened)
|
|
1474
706
|
await this.ready();
|
|
1475
|
-
const releaseWork = this.
|
|
707
|
+
const releaseWork = this._lifecycle.enterWork();
|
|
1476
708
|
try {
|
|
1477
709
|
const sdk = await this._sdk.load();
|
|
1478
|
-
this.
|
|
710
|
+
this._lifecycle.assertNotClosing();
|
|
1479
711
|
const result = await deleteModelFiles(sdk, name, { modelsDir: this._modelsDir });
|
|
1480
|
-
|
|
712
|
+
this._residency.invalidateStatus();
|
|
1481
713
|
return summarizeDelete(result);
|
|
1482
714
|
}
|
|
1483
715
|
finally {
|
|
@@ -1487,10 +719,10 @@ export class Harness extends ReadyResource {
|
|
|
1487
719
|
async clearKvCache() {
|
|
1488
720
|
if (!this.opened)
|
|
1489
721
|
await this.ready();
|
|
1490
|
-
const releaseWork = this.
|
|
722
|
+
const releaseWork = this._lifecycle.enterWork();
|
|
1491
723
|
try {
|
|
1492
724
|
return await deleteAllKvCaches(() => {
|
|
1493
|
-
this.
|
|
725
|
+
this._lifecycle.assertNotClosing();
|
|
1494
726
|
return this._sdk.load();
|
|
1495
727
|
});
|
|
1496
728
|
}
|
|
@@ -1501,10 +733,10 @@ export class Harness extends ReadyResource {
|
|
|
1501
733
|
async deleteKvCache(kvCacheKey) {
|
|
1502
734
|
if (!this.opened)
|
|
1503
735
|
await this.ready();
|
|
1504
|
-
const releaseWork = this.
|
|
736
|
+
const releaseWork = this._lifecycle.enterWork();
|
|
1505
737
|
try {
|
|
1506
738
|
return await deleteKvCacheKey(() => {
|
|
1507
|
-
this.
|
|
739
|
+
this._lifecycle.assertNotClosing();
|
|
1508
740
|
return this._sdk.load();
|
|
1509
741
|
}, kvCacheKey);
|
|
1510
742
|
}
|
|
@@ -1518,7 +750,7 @@ export class Harness extends ReadyResource {
|
|
|
1518
750
|
async capability() {
|
|
1519
751
|
if (!this.opened)
|
|
1520
752
|
await this.ready();
|
|
1521
|
-
this.
|
|
753
|
+
this._lifecycle.assertNotClosing();
|
|
1522
754
|
if (this._capability) {
|
|
1523
755
|
return this._capability;
|
|
1524
756
|
}
|
|
@@ -1560,219 +792,33 @@ export class Harness extends ReadyResource {
|
|
|
1560
792
|
return this._capabilityInflight;
|
|
1561
793
|
}
|
|
1562
794
|
warmModel(context) {
|
|
1563
|
-
return this.
|
|
1564
|
-
}
|
|
1565
|
-
async _warmModel({ model, agent, signal }) {
|
|
1566
|
-
if (!this.opened)
|
|
1567
|
-
await this.ready();
|
|
1568
|
-
this._assertNotClosing();
|
|
1569
|
-
if (this.suspended) {
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
const target = this._residency(model, agent);
|
|
1573
|
-
hlog('warm model', { model, resident: isResident(target.pool, target.key) });
|
|
1574
|
-
await this._loadAndRelease(target, signal, async () => {
|
|
1575
|
-
if (target.pool !== this._models || isResident(target.pool, target.key)) {
|
|
1576
|
-
return true;
|
|
1577
|
-
}
|
|
1578
|
-
const roomed = await this._makeRoomForCompletion(model, {
|
|
1579
|
-
ctxSize: target.ctxSize,
|
|
1580
|
-
signal,
|
|
1581
|
-
deadlineMs: WARM_ROOM_WAIT_MS
|
|
1582
|
-
});
|
|
1583
|
-
if (roomed) {
|
|
1584
|
-
await this._unloadIdleGenerators();
|
|
1585
|
-
}
|
|
1586
|
-
return roomed;
|
|
1587
|
-
});
|
|
795
|
+
return this._residency.busy(() => this._residency.warm(context));
|
|
1588
796
|
}
|
|
1589
797
|
loadModel(context) {
|
|
1590
|
-
return this.
|
|
1591
|
-
}
|
|
1592
|
-
async _loadModel({ model, agent, signal }) {
|
|
1593
|
-
if (!this.opened)
|
|
1594
|
-
await this.ready();
|
|
1595
|
-
if (this.suspended) {
|
|
1596
|
-
throw new Error('harness is suspended');
|
|
1597
|
-
}
|
|
1598
|
-
const target = this._residency(model, agent);
|
|
1599
|
-
const resident = isResident(target.pool, target.key);
|
|
1600
|
-
hlog('load model', { model, resident });
|
|
1601
|
-
if (target.pool !== this._models) {
|
|
1602
|
-
await this._loadAndRelease(target, signal);
|
|
1603
|
-
return { loaded: true };
|
|
1604
|
-
}
|
|
1605
|
-
if (!resident) {
|
|
1606
|
-
if (!(await this._fits(model, target.ctxSize))) {
|
|
1607
|
-
return { loaded: false, reason: 'memory' };
|
|
1608
|
-
}
|
|
1609
|
-
await evictIdleWhere(this._models, (key) => modelOf(key) === model && !this._replying.includes(key));
|
|
1610
|
-
await this._unloadIdleGenerators();
|
|
1611
|
-
}
|
|
1612
|
-
this._pinned.add(target.key);
|
|
1613
|
-
try {
|
|
1614
|
-
await this._loadAndRelease(target, signal);
|
|
1615
|
-
}
|
|
1616
|
-
catch (err) {
|
|
1617
|
-
this._pinned.delete(target.key);
|
|
1618
|
-
throw err;
|
|
1619
|
-
}
|
|
1620
|
-
return { loaded: true };
|
|
798
|
+
return this._residency.busy(() => this._residency.load(context));
|
|
1621
799
|
}
|
|
1622
800
|
unloadModel(context) {
|
|
1623
|
-
return this.
|
|
1624
|
-
}
|
|
1625
|
-
async _unloadModel({ model }) {
|
|
1626
|
-
if (!this.opened)
|
|
1627
|
-
await this.ready();
|
|
1628
|
-
const target = this._residency(model);
|
|
1629
|
-
const name = modelOf(target.key);
|
|
1630
|
-
const unloaded = await evictModel(target.pool, name, { deadlineMs: UNLOAD_LEASE_WAIT_MS });
|
|
1631
|
-
hlog('unload model', { model, unloaded });
|
|
1632
|
-
if (unloaded) {
|
|
1633
|
-
for (const key of this._pinned) {
|
|
1634
|
-
if (modelOf(key) === name) {
|
|
1635
|
-
this._pinned.delete(key);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
return { unloaded };
|
|
1640
|
-
}
|
|
1641
|
-
async _loadAndRelease({ pool, key, open }, signal, prepare = async () => true) {
|
|
1642
|
-
const lease = await this._acquireModelLease({ pool, key, open, signal, prepare });
|
|
1643
|
-
lease?.release();
|
|
1644
|
-
}
|
|
1645
|
-
async _unloadIdleGenerators() {
|
|
1646
|
-
await this._imageRuntime?.unloadIdle().catch(noop);
|
|
1647
|
-
await this._musicRuntime?.unloadIdle().catch(noop);
|
|
1648
|
-
}
|
|
1649
|
-
async _fits(model, ctxSize) {
|
|
1650
|
-
const asset = curatedModelAsset(model, 'llm');
|
|
1651
|
-
if (!asset) {
|
|
1652
|
-
return true;
|
|
1653
|
-
}
|
|
1654
|
-
const assessed = await this._assessFit({
|
|
1655
|
-
sha256Checksum: asset.sha256Checksum,
|
|
1656
|
-
name: asset.name,
|
|
1657
|
-
contextTokens: ctxSize || defaultContextSize(asset)
|
|
1658
|
-
}).catch((err) => {
|
|
1659
|
-
hlog('fit estimate failed', { model, err: errorMessage(err) });
|
|
1660
|
-
return null;
|
|
1661
|
-
});
|
|
1662
|
-
return assessed?.fit !== 'likely-too-large';
|
|
1663
|
-
}
|
|
1664
|
-
async _yieldPins(model, ctxSize) {
|
|
1665
|
-
for (const key of this._pinned) {
|
|
1666
|
-
if (leaseCount(this._models, key) > 0 || this._replying.includes(key)) {
|
|
1667
|
-
continue;
|
|
1668
|
-
}
|
|
1669
|
-
if (await this._fits(model, ctxSize))
|
|
1670
|
-
return;
|
|
1671
|
-
this._pinned.delete(key);
|
|
1672
|
-
await evictModelWithin(this._models, key, { deadlineMs: WEDGED_EVICT_WAIT_MS });
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
_residency(model, agent) {
|
|
1676
|
-
const addon = modelAddonOf(model);
|
|
1677
|
-
if (addon === 'llm') {
|
|
1678
|
-
const loadOpts = this._completionLoadOptions(model, agent);
|
|
1679
|
-
const key = modelKey(model, loadOpts);
|
|
1680
|
-
return {
|
|
1681
|
-
pool: this._models,
|
|
1682
|
-
key,
|
|
1683
|
-
ctxSize: loadOpts.ctxSize,
|
|
1684
|
-
open: () => this._models.open(key, model, loadOpts)
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
if (addon === 'embeddings') {
|
|
1688
|
-
const key = this._embedFaults.key(residentSrc(model, addon));
|
|
1689
|
-
return { pool: this._embedModels, key, open: () => this._embedModels.open(key, model) };
|
|
1690
|
-
}
|
|
1691
|
-
if (addon === 'tts' || addon === 'parakeet') {
|
|
1692
|
-
const pool = addon === 'tts' ? this._ttsModels : this._transcriptionModels;
|
|
1693
|
-
const key = residentSrc(model, addon);
|
|
1694
|
-
return { pool, key, open: () => pool.open(key, key) };
|
|
1695
|
-
}
|
|
1696
|
-
throw new Error(`${model} loads for each generation and is not kept in memory`);
|
|
1697
|
-
}
|
|
1698
|
-
_completionLoadOptions(model, agent) {
|
|
1699
|
-
return resolveLoadOptions({
|
|
1700
|
-
ctxSize: agent?.ctxSize ?? undefined,
|
|
1701
|
-
kvCacheK: agent?.kvCacheK ?? undefined,
|
|
1702
|
-
kvCacheV: agent?.kvCacheV ?? undefined,
|
|
1703
|
-
projectionModel: this._projectionFor(model)
|
|
1704
|
-
}, this._deviceConfig());
|
|
1705
|
-
}
|
|
1706
|
-
async _acquireModelLease({ pool, key, open, signal, prepare }) {
|
|
1707
|
-
const releaseWork = this._enterWork();
|
|
1708
|
-
let pendingLoad = null;
|
|
1709
|
-
let opened = false;
|
|
1710
|
-
let released = false;
|
|
1711
|
-
const release = () => {
|
|
1712
|
-
if (released) {
|
|
1713
|
-
return;
|
|
1714
|
-
}
|
|
1715
|
-
released = true;
|
|
1716
|
-
try {
|
|
1717
|
-
if (opened) {
|
|
1718
|
-
releaseModel(pool, key);
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
finally {
|
|
1722
|
-
releaseWork();
|
|
1723
|
-
}
|
|
1724
|
-
};
|
|
1725
|
-
try {
|
|
1726
|
-
if (!(await prepare())) {
|
|
1727
|
-
release();
|
|
1728
|
-
return null;
|
|
1729
|
-
}
|
|
1730
|
-
if (signal?.aborted) {
|
|
1731
|
-
throw new AbortedError();
|
|
1732
|
-
}
|
|
1733
|
-
if (this.suspended || this._runtimeDraining) {
|
|
1734
|
-
throw new Error('harness is suspended');
|
|
1735
|
-
}
|
|
1736
|
-
this._assertNotClosing();
|
|
1737
|
-
if (this._runtimeUnloadFailed) {
|
|
1738
|
-
throw new Error('Runtime unload failed; close the harness before loading models again');
|
|
1739
|
-
}
|
|
1740
|
-
const handle = open();
|
|
1741
|
-
opened = true;
|
|
1742
|
-
const loading = handle.load();
|
|
1743
|
-
pendingLoad = loading;
|
|
1744
|
-
const loaded = await raceAbort(loading, signal);
|
|
1745
|
-
return { modelId: loaded.modelId, release };
|
|
1746
|
-
}
|
|
1747
|
-
catch (error) {
|
|
1748
|
-
if (pendingLoad) {
|
|
1749
|
-
void pendingLoad.then(release, release).catch(noop);
|
|
1750
|
-
}
|
|
1751
|
-
else {
|
|
1752
|
-
release();
|
|
1753
|
-
}
|
|
1754
|
-
throw error;
|
|
1755
|
-
}
|
|
801
|
+
return this._residency.busy(() => this._residency.unload(context));
|
|
1756
802
|
}
|
|
1757
803
|
invoke(context) {
|
|
1758
|
-
return this.
|
|
804
|
+
return this._residency.busyStream(() => this._invoke(context));
|
|
1759
805
|
}
|
|
1760
806
|
async *_invoke({ capability, args, enhance, agent, attach, fetchAttachment, progress, signal }) {
|
|
1761
807
|
if (!this.opened)
|
|
1762
808
|
await this.ready();
|
|
1763
809
|
if (this.suspended) {
|
|
1764
|
-
this.
|
|
810
|
+
this._lifecycle.assertNotClosing();
|
|
1765
811
|
return yield { type: 'aborted' };
|
|
1766
812
|
}
|
|
1767
|
-
const releaseWork = this.
|
|
1768
|
-
|
|
813
|
+
const releaseWork = this._lifecycle.enterWork();
|
|
814
|
+
HarnessLog.info('invoke start', { capability, enhance });
|
|
1769
815
|
try {
|
|
1770
816
|
yield* invoke({
|
|
1771
817
|
capability,
|
|
1772
818
|
args,
|
|
1773
819
|
enhance,
|
|
1774
820
|
enhancer: this._residentEnhancer(),
|
|
1775
|
-
tools: [...this._tools, ...this.
|
|
821
|
+
tools: [...this._tools, ...this._capabilities],
|
|
1776
822
|
ctx: {
|
|
1777
823
|
image: imageSettingsFrom(agent),
|
|
1778
824
|
attach,
|
|
@@ -1783,61 +829,111 @@ export class Harness extends ReadyResource {
|
|
|
1783
829
|
});
|
|
1784
830
|
}
|
|
1785
831
|
finally {
|
|
1786
|
-
|
|
832
|
+
HarnessLog.info('invoke end', { capability });
|
|
1787
833
|
releaseWork();
|
|
1788
834
|
}
|
|
1789
835
|
}
|
|
1790
836
|
completion(context) {
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
837
|
+
if (!context.agents) {
|
|
838
|
+
const { hopLog, ...run } = context;
|
|
839
|
+
return this._completion({ ...run, ...hopLog?.({ index: 0, agent: run.agent?.id ?? '' }) });
|
|
1794
840
|
}
|
|
1795
|
-
if (
|
|
1796
|
-
throw new
|
|
841
|
+
if (context.boot || context.onStep) {
|
|
842
|
+
throw new TypeError('A run that follows handoffs cannot take boot or onStep; give it a hopLog, or run it over the wire with a HostRunLog');
|
|
1797
843
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
this.
|
|
1804
|
-
|
|
844
|
+
return Agent.follow({ completion: (hop) => this._completion(hop) }, { ...context, goal: undefined });
|
|
845
|
+
}
|
|
846
|
+
async serveModelRound(request, io) {
|
|
847
|
+
if (!this.opened)
|
|
848
|
+
await this.ready();
|
|
849
|
+
this._lifecycle.assertNotClosing();
|
|
850
|
+
if (this.suspended || this._lifecycle.draining) {
|
|
851
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
852
|
+
}
|
|
853
|
+
if (this._lifecycle.unloadFailed) {
|
|
854
|
+
throw new Error(UNLOAD_FAILED);
|
|
855
|
+
}
|
|
856
|
+
const { modelId } = request;
|
|
857
|
+
const { key, acquireRound } = this._residency.servedRound(modelId);
|
|
858
|
+
let served;
|
|
859
|
+
const round = this._lifecycle.trackCompletion((signal) => this._residency.busyStream(async function* () {
|
|
860
|
+
served = await CompletionEngine.serveModelRound(request, { signal, emit: (event) => io.emit(event), retake: () => io.retake() }, { acquireRound });
|
|
861
|
+
}), io.signal);
|
|
862
|
+
try {
|
|
863
|
+
await round.next();
|
|
864
|
+
}
|
|
865
|
+
catch (err) {
|
|
866
|
+
throw await this._servedRoundFailed(err, modelId, key);
|
|
867
|
+
}
|
|
868
|
+
if (!served) {
|
|
869
|
+
throw new Error('A served round ended without its result');
|
|
870
|
+
}
|
|
871
|
+
this._residency.clearFaults(modelId);
|
|
872
|
+
return served;
|
|
873
|
+
}
|
|
874
|
+
async _servedRoundFailed(err, model, key) {
|
|
875
|
+
const aborted = err instanceof AbortedError || this.suspended || this._lifecycle.draining;
|
|
876
|
+
if (aborted || !isSdkModelWedgedError(err)) {
|
|
877
|
+
return err;
|
|
878
|
+
}
|
|
879
|
+
const wedged = await this._residency.evictWedged(model, key);
|
|
880
|
+
if (wedged.fatal) {
|
|
881
|
+
setTimeout(() => process.exit(1), 0);
|
|
882
|
+
}
|
|
883
|
+
return new Error(wedged.message, { cause: err });
|
|
884
|
+
}
|
|
885
|
+
_completion(context) {
|
|
886
|
+
this._lifecycle.assertNotClosing();
|
|
887
|
+
if (this._lifecycle.draining) {
|
|
888
|
+
throw new HarnessError('HARNESS_SUSPENDED');
|
|
889
|
+
}
|
|
890
|
+
if (this._lifecycle.unloadFailed) {
|
|
891
|
+
throw new Error(UNLOAD_FAILED);
|
|
892
|
+
}
|
|
893
|
+
return this._lifecycle.trackCompletion((signal) => this._residency.busyStream(() => this._runCompletion({ ...context, signal })), context.signal);
|
|
1805
894
|
}
|
|
1806
895
|
async *_runCompletion(request) {
|
|
1807
896
|
if (!this.opened)
|
|
1808
897
|
await this.ready();
|
|
1809
|
-
this.
|
|
1810
|
-
if (this.suspended || this.
|
|
898
|
+
this._lifecycle.assertNotClosing();
|
|
899
|
+
if (this.suspended || this._lifecycle.draining) {
|
|
1811
900
|
yield { type: 'aborted' };
|
|
1812
901
|
return;
|
|
1813
902
|
}
|
|
1814
903
|
const { boot, onStep, hostAppendTimeoutMs, requestDigestKey, ...provided } = request;
|
|
1815
904
|
let modelId = request.model ?? '';
|
|
1816
905
|
let key = null;
|
|
906
|
+
const releasePlugins = await this._plugins.hold(request.parentRunId !== undefined);
|
|
907
|
+
const detached = [];
|
|
1817
908
|
try {
|
|
1818
909
|
const runtime = async (run) => {
|
|
1819
910
|
modelId = run.model ?? run.modelId;
|
|
1820
911
|
const runContext = { ...run, model: run.model ?? run.modelId };
|
|
1821
|
-
const lease = await this.
|
|
912
|
+
const lease = await this._residency.completionRuntime(runContext);
|
|
913
|
+
const access = await this._access(run, lease.args);
|
|
1822
914
|
if (!key) {
|
|
1823
|
-
this.
|
|
915
|
+
this._residency.reply(lease.key);
|
|
1824
916
|
}
|
|
1825
917
|
key = lease.key;
|
|
1826
|
-
return lease;
|
|
918
|
+
return { ...lease, args: { ...lease.args, access }, services: this._plugins.ctx };
|
|
1827
919
|
};
|
|
1828
920
|
const args = { ...provided, lockOwner: this };
|
|
1829
|
-
for await (const event of
|
|
921
|
+
for await (const event of CompletionEngine.run(runtime, args, {
|
|
922
|
+
hooks: this._hooks,
|
|
1830
923
|
boot,
|
|
1831
924
|
onStep,
|
|
1832
925
|
hostAppendTimeoutMs,
|
|
1833
926
|
requestDigestKey,
|
|
1834
927
|
resumeRequest: provided,
|
|
1835
|
-
onDetached: (pending, runId) =>
|
|
928
|
+
onDetached: (pending, runId) => {
|
|
929
|
+
detached.push(pending);
|
|
930
|
+
this._lifecycle.trackDetachedRun(pending, runId);
|
|
931
|
+
}
|
|
1836
932
|
})) {
|
|
1837
933
|
yield event;
|
|
1838
934
|
}
|
|
1839
935
|
if (key) {
|
|
1840
|
-
this.
|
|
936
|
+
this._residency.clearFaults(modelId);
|
|
1841
937
|
}
|
|
1842
938
|
}
|
|
1843
939
|
catch (error) {
|
|
@@ -1845,24 +941,42 @@ export class Harness extends ReadyResource {
|
|
|
1845
941
|
}
|
|
1846
942
|
finally {
|
|
1847
943
|
if (key) {
|
|
1848
|
-
|
|
1849
|
-
this.
|
|
1850
|
-
void this.
|
|
1851
|
-
void this._musicRuntime?.unloadIdle().catch(noop);
|
|
944
|
+
HarnessLog.info('completion end', { model: modelId });
|
|
945
|
+
this._residency.replied(key);
|
|
946
|
+
void this._plugins.unloadIdle();
|
|
1852
947
|
}
|
|
948
|
+
void Promise.allSettled(detached).then(releasePlugins);
|
|
1853
949
|
}
|
|
1854
950
|
}
|
|
951
|
+
async _access(run, roots) {
|
|
952
|
+
const layers = [this._policy, run.agent?.policy, run.policy];
|
|
953
|
+
return Policy.forRun(await Promise.all(layers.map(canonicalPolicy)), { ...roots, deny: await canonicalDenyRoots(this._deniedRoots, defaultRealpath) }, this._providers());
|
|
954
|
+
}
|
|
955
|
+
_providers() {
|
|
956
|
+
const providers = [];
|
|
957
|
+
if (this._exec) {
|
|
958
|
+
providers.push(this._shell ?? HOST_SHELL);
|
|
959
|
+
}
|
|
960
|
+
const ctx = this._plugins.ctx;
|
|
961
|
+
if ('sandbox' in ctx) {
|
|
962
|
+
providers.push(ctx.sandbox);
|
|
963
|
+
}
|
|
964
|
+
return providers;
|
|
965
|
+
}
|
|
1855
966
|
async *_completionFailed(err, model, key) {
|
|
1856
|
-
if (err instanceof AbortedError || this.suspended || this.
|
|
1857
|
-
|
|
967
|
+
if (err instanceof AbortedError || this.suspended || this._lifecycle.draining) {
|
|
968
|
+
HarnessLog.info('completion aborted', {
|
|
969
|
+
model,
|
|
970
|
+
suspended: this.suspended || this._lifecycle.draining
|
|
971
|
+
});
|
|
1858
972
|
yield { type: 'aborted' };
|
|
1859
973
|
return;
|
|
1860
974
|
}
|
|
1861
975
|
const message = errorMessage(err);
|
|
1862
976
|
const name = err instanceof Error ? err.name : undefined;
|
|
1863
|
-
|
|
977
|
+
HarnessLog.error('completion failed', { model, ...resolutionDetail(err), err: message });
|
|
1864
978
|
if (key && isSdkModelWedgedError(err)) {
|
|
1865
|
-
const wedged = await this.
|
|
979
|
+
const wedged = await this._residency.evictWedged(model, key);
|
|
1866
980
|
yield completionErrorEvent(wedged.message, name, err);
|
|
1867
981
|
if (wedged.fatal) {
|
|
1868
982
|
process.exit(1);
|
|
@@ -1872,18 +986,9 @@ export class Harness extends ReadyResource {
|
|
|
1872
986
|
yield completionErrorEvent(message, name, err);
|
|
1873
987
|
}
|
|
1874
988
|
}
|
|
1875
|
-
async _completionRuntime(request) {
|
|
1876
|
-
const releaseWork = this._enterWork();
|
|
1877
|
-
try {
|
|
1878
|
-
return await prepareCompletionRuntime(this, request);
|
|
1879
|
-
}
|
|
1880
|
-
finally {
|
|
1881
|
-
releaseWork();
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
989
|
_residentEnhancer() {
|
|
1885
990
|
return async (prompt, signal) => {
|
|
1886
|
-
const lease = await leaseResidentModel(this.
|
|
991
|
+
const lease = await leaseResidentModel(this._residency.pool, (model) => !this._residency.borrowed(model));
|
|
1887
992
|
if (!lease) {
|
|
1888
993
|
return null;
|
|
1889
994
|
}
|
|
@@ -1896,7 +1001,7 @@ export class Harness extends ReadyResource {
|
|
|
1896
1001
|
});
|
|
1897
1002
|
}
|
|
1898
1003
|
catch (err) {
|
|
1899
|
-
|
|
1004
|
+
HarnessLog.warn('enhance failed', { err: errorMessage(err) });
|
|
1900
1005
|
return null;
|
|
1901
1006
|
}
|
|
1902
1007
|
finally {
|
|
@@ -1904,69 +1009,6 @@ export class Harness extends ReadyResource {
|
|
|
1904
1009
|
}
|
|
1905
1010
|
};
|
|
1906
1011
|
}
|
|
1907
|
-
async _makeRoomForCompletion(model, { ctxSize, signal, deadlineMs = MODEL_ROOM_WAIT_MS } = {}) {
|
|
1908
|
-
const roomed = await awaitModelCapacity(this._models, {
|
|
1909
|
-
cap: this._completionModelCap,
|
|
1910
|
-
deadlineMs,
|
|
1911
|
-
signal,
|
|
1912
|
-
evictable: (key) => !this._pinned.has(key) || modelOf(key) === model
|
|
1913
|
-
});
|
|
1914
|
-
if (!roomed) {
|
|
1915
|
-
hlog('model room wait gave up', {
|
|
1916
|
-
cap: this._completionModelCap,
|
|
1917
|
-
loaded: loadedModels(this._models).length
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
await this._yieldPins(model, ctxSize);
|
|
1921
|
-
return roomed;
|
|
1922
|
-
}
|
|
1923
|
-
async _evictWedgedModel(model, key) {
|
|
1924
|
-
const faults = (this._modelFaults.get(model) ?? 0) + 1;
|
|
1925
|
-
this._modelFaults.set(model, faults);
|
|
1926
|
-
const leased = leaseCount(this._models, key) > 0;
|
|
1927
|
-
const evicted = leased
|
|
1928
|
-
? false
|
|
1929
|
-
: await evictModelWithin(this._models, key, { deadlineMs: WEDGED_EVICT_WAIT_MS });
|
|
1930
|
-
hlog('wedged model evicted', { model, faults, evicted, leased });
|
|
1931
|
-
if (leased) {
|
|
1932
|
-
this._evictAfterLeases(model, key);
|
|
1933
|
-
}
|
|
1934
|
-
if (!evicted && !leased) {
|
|
1935
|
-
return {
|
|
1936
|
-
message: `${model} is stuck in device memory — restarting the model runtime`,
|
|
1937
|
-
fatal: true
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
|
-
return {
|
|
1941
|
-
message: faults > 1
|
|
1942
|
-
? `${model} keeps failing during inference on this device — it may need more memory than is available`
|
|
1943
|
-
: `${model} failed during inference and was unloaded — try again`,
|
|
1944
|
-
fatal: false
|
|
1945
|
-
};
|
|
1946
|
-
}
|
|
1947
|
-
_evictAfterLeases(model, key) {
|
|
1948
|
-
void evictModelWithin(this._models, key, { deadlineMs: WEDGED_EVICT_LEASED_MS })
|
|
1949
|
-
.then((evicted) => hlog('wedged model evicted after leases', { model, evicted }))
|
|
1950
|
-
.catch(noop);
|
|
1951
|
-
}
|
|
1952
|
-
async _busy(run) {
|
|
1953
|
-
await this._idle.enter();
|
|
1954
|
-
try {
|
|
1955
|
-
return await run();
|
|
1956
|
-
}
|
|
1957
|
-
finally {
|
|
1958
|
-
this._idle.exit();
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
async *_busyStream(run) {
|
|
1962
|
-
await this._idle.enter();
|
|
1963
|
-
try {
|
|
1964
|
-
yield* run();
|
|
1965
|
-
}
|
|
1966
|
-
finally {
|
|
1967
|
-
this._idle.exit();
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
1012
|
}
|
|
1971
1013
|
function completionErrorEvent(message, name, error) {
|
|
1972
1014
|
const event = { type: 'error', message, ...completionErrorDetails(error) };
|
|
@@ -1997,3 +1039,21 @@ function completionErrorDetails(error) {
|
|
|
1997
1039
|
return { kind, found, expected };
|
|
1998
1040
|
}
|
|
1999
1041
|
function noop() { }
|
|
1042
|
+
async function canonicalPolicy(policy) {
|
|
1043
|
+
if (!policy) {
|
|
1044
|
+
return undefined;
|
|
1045
|
+
}
|
|
1046
|
+
const { files = {}, sockets } = policy;
|
|
1047
|
+
return {
|
|
1048
|
+
...policy,
|
|
1049
|
+
files: {
|
|
1050
|
+
read: files.read === 'all' ? 'all' : await canonicalRoots(files.read),
|
|
1051
|
+
write: await canonicalRoots(files.write),
|
|
1052
|
+
deny: await canonicalRoots(files.deny)
|
|
1053
|
+
},
|
|
1054
|
+
sockets: await canonicalRoots(sockets)
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
async function canonicalRoots(roots) {
|
|
1058
|
+
return roots && canonicalDenyRoots(roots, defaultRealpath);
|
|
1059
|
+
}
|