@qvac/harness 1.0.0-rc.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +696 -7
- package/NOTICE.md +0 -16
- package/README.md +46 -5
- package/dist-lib/index.d.ts +23 -16
- package/dist-lib/index.js +127 -23
- package/dist-lib/lib/agent/delegate.d.ts +1 -0
- package/dist-lib/lib/agent/delegate.js +10 -9
- package/dist-lib/lib/agent/follow.d.ts +1 -0
- package/dist-lib/lib/agent/follow.js +12 -2
- package/dist-lib/lib/agent/resolve.js +11 -3
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +1 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +8 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +79 -9
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +12 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +47 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +5 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +10 -4
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/retrieving.js +19 -11
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +38 -23
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +31 -10
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +61 -7
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +41 -16
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +26 -10
- package/dist-lib/lib/capabilities/completion-engine/actors.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors.js +8 -8
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/driver.js +30 -6
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/engine.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/engine.js +35 -15
- package/dist-lib/lib/capabilities/completion-engine/index.d.ts +0 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +13 -3
- package/dist-lib/lib/capabilities/completion-engine/loop.js +7 -2
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/model-round.js +2 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +29 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +6 -4
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +4 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +102 -47
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +5 -3
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-caller.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.d.ts +5 -41
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +21 -135
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-outcome.js +40 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.d.ts +43 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-preflight.js +91 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.d.ts +14 -0
- package/dist-lib/lib/capabilities/completion-engine/transition-log.js +44 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/turns.js +36 -8
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/kv-cache.js +11 -3
- package/dist-lib/lib/capabilities/prefix-template.d.ts +34 -0
- package/dist-lib/lib/capabilities/prefix-template.js +175 -0
- package/dist-lib/lib/capabilities/prompt-prefix.d.ts +2 -0
- package/dist-lib/lib/capabilities/prompt-prefix.js +8 -0
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +4 -4
- package/dist-lib/lib/capabilities/sdk-tool.js +22 -6
- package/dist-lib/lib/capabilities/skill-entry.d.ts +13 -1
- package/dist-lib/lib/capabilities/skill-entry.js +33 -2
- package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
- package/dist-lib/lib/capabilities/tool-turns/answered.d.ts +15 -0
- package/dist-lib/lib/capabilities/tool-turns/answered.js +16 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.d.ts +7 -0
- package/dist-lib/lib/capabilities/tool-turns/attachments.js +39 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.d.ts +13 -0
- package/dist-lib/lib/capabilities/tool-turns/copy.js +29 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.d.ts +22 -0
- package/dist-lib/lib/capabilities/tool-turns/result-turn.js +120 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.d.ts +6 -0
- package/dist-lib/lib/capabilities/tool-turns/run-limits.js +32 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.d.ts +9 -0
- package/dist-lib/lib/capabilities/tool-turns/skill-loads.js +71 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +10 -43
- package/dist-lib/lib/capabilities/tool-turns.js +7 -262
- package/dist-lib/lib/capabilities/usage-breakdown.d.ts +1 -0
- package/dist-lib/lib/capabilities/usage-breakdown.js +4 -1
- package/dist-lib/lib/client/index.js +6 -5
- package/dist-lib/lib/connect/abort.d.ts +6 -0
- package/dist-lib/lib/connect/abort.js +52 -0
- package/dist-lib/lib/connect/bridges.d.ts +21 -0
- package/dist-lib/lib/connect/bridges.js +185 -0
- package/dist-lib/lib/connect/decode.d.ts +31 -0
- package/dist-lib/lib/connect/decode.js +114 -0
- package/dist-lib/lib/connect/host-run-log.d.ts +20 -0
- package/dist-lib/lib/connect/host-run-log.js +89 -0
- package/dist-lib/lib/connect/round-log.d.ts +8 -0
- package/dist-lib/lib/connect/round-log.js +33 -0
- package/dist-lib/lib/connect/served.d.ts +7 -0
- package/dist-lib/lib/connect/served.js +45 -0
- package/dist-lib/lib/connect.d.ts +5 -1
- package/dist-lib/lib/connect.js +102 -444
- package/dist-lib/lib/context-window.d.ts +13 -6
- package/dist-lib/lib/context-window.js +18 -5
- package/dist-lib/lib/contract/agent.d.ts +18 -1
- package/dist-lib/lib/contract/completion.d.ts +35 -3
- package/dist-lib/lib/contract/drive.d.ts +154 -4
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/index.d.ts +1 -0
- package/dist-lib/lib/contract/knowledge.d.ts +10 -0
- package/dist-lib/lib/contract/media.d.ts +58 -0
- package/dist-lib/lib/contract/models.d.ts +6 -2
- package/dist-lib/lib/contract/ocr.d.ts +17 -0
- package/dist-lib/lib/contract/ocr.js +1 -0
- package/dist-lib/lib/contract/root-search.d.ts +34 -0
- package/dist-lib/lib/contract/root-search.js +1 -0
- package/dist-lib/lib/contract/run.d.ts +13 -0
- package/dist-lib/lib/contract-types.d.ts +10 -2
- package/dist-lib/lib/docx/index.js +1 -1
- package/dist-lib/lib/errors.d.ts +8 -4
- package/dist-lib/lib/errors.js +12 -8
- package/dist-lib/lib/fold/index.d.ts +4 -2
- package/dist-lib/lib/fold/index.js +15 -7
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +18 -2
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/helpers/drain.d.ts +1 -1
- package/dist-lib/lib/helpers/drain.js +1 -1
- package/dist-lib/lib/helpers/goal-check/asks.d.ts +25 -0
- package/dist-lib/lib/helpers/goal-check/asks.js +52 -0
- package/dist-lib/lib/helpers/goal-check/checks.d.ts +8 -0
- package/dist-lib/lib/helpers/goal-check/checks.js +92 -0
- package/dist-lib/lib/helpers/goal-check/commands.d.ts +7 -0
- package/dist-lib/lib/helpers/goal-check/commands.js +130 -0
- package/dist-lib/lib/helpers/goal-check/paths.d.ts +5 -0
- package/dist-lib/lib/helpers/goal-check/paths.js +44 -0
- package/dist-lib/lib/helpers/goal-check/shell.d.ts +9 -0
- package/dist-lib/lib/helpers/goal-check/shell.js +96 -0
- package/dist-lib/lib/helpers/goal-check.d.ts +36 -6
- package/dist-lib/lib/helpers/goal-check.js +34 -98
- package/dist-lib/lib/helpers/html-helpers.js +9 -6
- package/dist-lib/lib/helpers/recent-map.d.ts +7 -0
- package/dist-lib/lib/helpers/recent-map.js +23 -0
- package/dist-lib/lib/helpers/repeated-reply.js +9 -2
- package/dist-lib/lib/helpers/root-search.d.ts +3 -0
- package/dist-lib/lib/helpers/root-search.js +74 -0
- package/dist-lib/lib/helpers/run-latency.d.ts +14 -0
- package/dist-lib/lib/helpers/run-latency.js +63 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +2 -0
- package/dist-lib/lib/helpers/run-outcome.js +6 -2
- package/dist-lib/lib/helpers/spawn-path.d.ts +1 -0
- package/dist-lib/lib/helpers/spawn-path.js +2 -1
- package/dist-lib/lib/helpers/stable-stringify.js +10 -2
- package/dist-lib/lib/helpers/text-coalescer.d.ts +6 -0
- package/dist-lib/lib/helpers/text-coalescer.js +44 -4
- package/dist-lib/lib/helpers/tool-call-markup/emit.d.ts +6 -0
- package/dist-lib/lib/helpers/tool-call-markup/emit.js +15 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.d.ts +22 -0
- package/dist-lib/lib/helpers/tool-call-markup/recover.js +130 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.d.ts +3 -0
- package/dist-lib/lib/helpers/tool-call-markup/skill-recovery.js +56 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.d.ts +4 -0
- package/dist-lib/lib/helpers/tool-call-markup/strip.js +157 -0
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +19 -24
- package/dist-lib/lib/helpers/tool-call-markup.js +17 -343
- package/dist-lib/lib/lifecycle/completion-run.js +2 -2
- package/dist-lib/lib/log.d.ts +3 -0
- package/dist-lib/lib/log.js +17 -1
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +13 -16
- package/dist-lib/lib/machine/completion/actions/completion.js +110 -138
- package/dist-lib/lib/machine/completion/actions/goal.d.ts +10 -0
- package/dist-lib/lib/machine/completion/actions/goal.js +93 -0
- package/dist-lib/lib/machine/completion/actions/prepare.js +2 -1
- package/dist-lib/lib/machine/completion/actions/reject-tool.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/reject-tool.js +147 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.d.ts +6 -0
- package/dist-lib/lib/machine/completion/actions/retry-round.js +50 -0
- package/dist-lib/lib/machine/completion/actions/rounds.d.ts +5 -0
- package/dist-lib/lib/machine/completion/actions/rounds.js +31 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +1 -16
- package/dist-lib/lib/machine/completion/actions/tools.js +73 -151
- package/dist-lib/lib/machine/completion/context.js +6 -1
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +4 -3
- package/dist-lib/lib/machine/completion/implementations.d.ts +8 -5
- package/dist-lib/lib/machine/completion/implementations.js +22 -7
- package/dist-lib/lib/machine/completion/machine.d.ts +15 -6
- package/dist-lib/lib/machine/completion/machine.js +25 -5
- package/dist-lib/lib/machine/completion/metrics.d.ts +25 -0
- package/dist-lib/lib/machine/completion/metrics.js +70 -0
- package/dist-lib/lib/machine/completion/nudges.d.ts +5 -0
- package/dist-lib/lib/machine/completion/nudges.js +33 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +10 -33
- package/dist-lib/lib/machine/completion/rules.js +27 -103
- package/dist-lib/lib/machine/completion/splice.d.ts +9 -0
- package/dist-lib/lib/machine/completion/splice.js +19 -0
- package/dist-lib/lib/machine/completion/types.d.ts +37 -13
- package/dist-lib/lib/machine/index.d.ts +21 -7
- package/dist-lib/lib/machine/index.js +7 -2
- package/dist-lib/lib/media-host.d.ts +12 -0
- package/dist-lib/lib/media-host.js +52 -0
- package/dist-lib/lib/media-port.d.ts +20 -0
- package/dist-lib/lib/media-port.js +77 -0
- package/dist-lib/lib/media-wire.d.ts +8 -0
- package/dist-lib/lib/media-wire.js +111 -0
- package/dist-lib/lib/models/context-choice.js +8 -1
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -0
- package/dist-lib/lib/models/gguf-header.d.ts +6 -0
- package/dist-lib/lib/models/gguf-header.js +38 -1
- package/dist-lib/lib/models/gpu-selection.d.ts +6 -1
- package/dist-lib/lib/models/gpu-selection.js +29 -5
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/llm-presets.js +27 -1
- package/dist-lib/lib/models/load-requests.d.ts +9 -0
- package/dist-lib/lib/models/load-requests.js +42 -0
- package/dist-lib/lib/models/model-catalog-constants.d.ts +3 -2
- package/dist-lib/lib/models/model-catalog-constants.js +8 -5
- package/dist-lib/lib/models/model-catalog.d.ts +12 -3
- package/dist-lib/lib/models/model-catalog.js +40 -16
- package/dist-lib/lib/models/model-delete.js +3 -0
- package/dist-lib/lib/models/model-handle.d.ts +1 -0
- package/dist-lib/lib/models/model-list.d.ts +2 -1
- package/dist-lib/lib/models/model-list.js +5 -1
- package/dist-lib/lib/models/model-pool.d.ts +7 -1
- package/dist-lib/lib/models/model-pool.js +34 -13
- package/dist-lib/lib/models/tts-model-default.d.ts +2 -1
- package/dist-lib/lib/models/tts-model-default.js +8 -6
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +45 -8
- package/dist-lib/lib/office/index.js +1 -1
- package/dist-lib/lib/plugins/registry.d.ts +12 -0
- package/dist-lib/lib/plugins/registry.js +71 -15
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/prompt.d.ts +7 -4
- package/dist-lib/lib/prompt.js +81 -24
- package/dist-lib/lib/residency/completion-runtime.d.ts +8 -6
- package/dist-lib/lib/residency/completion-runtime.js +53 -9
- package/dist-lib/lib/residency/index.d.ts +12 -3
- package/dist-lib/lib/residency/index.js +52 -16
- package/dist-lib/lib/round-host.js +3 -3
- package/dist-lib/lib/round-port.js +3 -3
- package/dist-lib/lib/run-log/boundary.d.ts +1 -4
- package/dist-lib/lib/run-log/boundary.js +4 -21
- package/dist-lib/lib/run-log/history-codec.d.ts +1 -1
- package/dist-lib/lib/run-log/history-codec.js +3 -3
- package/dist-lib/lib/run-log/protocol.js +17 -16
- package/dist-lib/lib/run-log/redact.d.ts +10 -1
- package/dist-lib/lib/run-log/redact.js +99 -9
- package/dist-lib/lib/run-log/request-codec.d.ts +3 -0
- package/dist-lib/lib/run-log/request-codec.js +19 -4
- package/dist-lib/lib/run-log/run-journal.js +1 -1
- package/dist-lib/lib/sdk-loader.d.ts +1 -0
- package/dist-lib/lib/sdk-loader.js +14 -0
- package/dist-lib/lib/serve/completion.d.ts +7 -0
- package/dist-lib/lib/serve/completion.js +571 -0
- package/dist-lib/lib/serve/downloads.d.ts +4 -0
- package/dist-lib/lib/serve/downloads.js +79 -0
- package/dist-lib/lib/serve/models.d.ts +5 -0
- package/dist-lib/lib/serve/models.js +120 -0
- package/dist-lib/lib/serve/noop.d.ts +1 -0
- package/dist-lib/lib/serve/noop.js +1 -0
- package/dist-lib/lib/serve/requests.d.ts +148 -0
- package/dist-lib/lib/serve/requests.js +1 -0
- package/dist-lib/lib/serve/rounds.d.ts +11 -0
- package/dist-lib/lib/serve/rounds.js +67 -0
- package/dist-lib/lib/serve/run-log-start.d.ts +37 -0
- package/dist-lib/lib/serve/run-log-start.js +253 -0
- package/dist-lib/lib/serve/skills.d.ts +32 -0
- package/dist-lib/lib/serve/skills.js +46 -0
- package/dist-lib/lib/serve.d.ts +5 -1
- package/dist-lib/lib/serve.js +23 -995
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +11 -19
- package/dist-lib/lib/sidecar/user-plugins.js +6 -4
- package/dist-lib/lib/skills-host/index.d.ts +6 -3
- package/dist-lib/lib/skills-host/index.js +39 -18
- package/dist-lib/lib/spawn.d.ts +14 -0
- package/dist-lib/lib/spawn.js +9 -5
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
- package/dist-lib/lib/tools/attachments/staging.js +18 -22
- package/dist-lib/lib/tools/exec/runner.d.ts +4 -0
- package/dist-lib/lib/tools/exec/runner.js +20 -3
- package/dist-lib/lib/tools/exec.js +2 -1
- package/dist-lib/lib/tools/files/edit-file.d.ts +4 -1
- package/dist-lib/lib/tools/files/edit-file.js +220 -28
- package/dist-lib/lib/tools/files/glob.js +72 -11
- package/dist-lib/lib/tools/files/grep.js +65 -22
- package/dist-lib/lib/tools/files/index.js +3 -1
- package/dist-lib/lib/tools/files/read-file.js +199 -36
- package/dist-lib/lib/tools/fs/document-text.d.ts +7 -1
- package/dist-lib/lib/tools/fs/document-text.js +5 -21
- package/dist-lib/lib/tools/fs/drive.d.ts +1 -17
- package/dist-lib/lib/tools/fs/edit-match.d.ts +22 -0
- package/dist-lib/lib/tools/fs/edit-match.js +337 -45
- package/dist-lib/lib/tools/fs/engine.d.ts +9 -0
- package/dist-lib/lib/tools/fs/engine.js +28 -0
- package/dist-lib/lib/tools/fs/remote-protocol.d.ts +1 -81
- package/dist-lib/lib/tools/fs/scope.d.ts +2 -17
- package/dist-lib/lib/tools/fs/search.d.ts +2 -18
- package/dist-lib/lib/tools/fs/suggest.d.ts +8 -0
- package/dist-lib/lib/tools/fs/suggest.js +110 -0
- package/dist-lib/lib/tools/fs/tool-path.d.ts +3 -0
- package/dist-lib/lib/tools/fs/tool-path.js +13 -0
- package/dist-lib/lib/tools/fs/walk.d.ts +5 -5
- package/dist-lib/lib/tools/fs/walk.js +22 -21
- package/dist-lib/lib/tools/http-request/request.d.ts +4 -2
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +56 -11
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +88 -14
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +3 -2
- package/dist-lib/lib/tools/office.js +200 -39
- package/dist-lib/lib/tools/operations/builders.d.ts +4 -3
- package/dist-lib/lib/tools/operations/builders.js +41 -3
- package/dist-lib/lib/tools/operations/calendar-range.d.ts +16 -0
- package/dist-lib/lib/tools/operations/calendar-range.js +40 -0
- package/dist-lib/lib/tools/operations/compile.js +8 -6
- package/dist-lib/lib/tools/operations/manifest.d.ts +4 -0
- package/dist-lib/lib/tools/pdf/build.d.ts +13 -3
- package/dist-lib/lib/tools/pdf/build.js +52 -16
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +31 -0
- package/dist-lib/lib/tools/pdf/recognize.d.ts +13 -0
- package/dist-lib/lib/tools/pdf/recognize.js +55 -0
- package/dist-lib/lib/tools/pdf/request.d.ts +3 -8
- package/dist-lib/lib/tools/pdf/request.js +4 -4
- package/dist-lib/lib/tools/pdf.d.ts +0 -1
- package/dist-lib/lib/tools/pdf.js +42 -14
- package/dist-lib/lib/tools/skill.js +13 -4
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +8 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +38 -32
- package/dist-lib/lib/tools/skills/bundled-hash.d.ts +1 -0
- package/dist-lib/lib/tools/skills/bundled-hash.js +4 -1
- package/dist-lib/lib/tools/skills/catalog-loader.d.ts +12 -0
- package/dist-lib/lib/tools/skills/catalog-loader.js +173 -0
- package/dist-lib/lib/tools/skills/catalog.d.ts +5 -8
- package/dist-lib/lib/tools/skills/catalog.js +1 -162
- package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +3 -0
- package/dist-lib/lib/tools/skills/index.d.ts +1 -0
- package/dist-lib/lib/tools/skills/index.js +1 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- package/dist-lib/lib/tools/skills/overlay-watch.d.ts +2 -2
- package/dist-lib/lib/tools/skills/overlay-watch.js +4 -3
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/skills/skill-tree.d.ts +5 -0
- package/dist-lib/lib/tools/skills/skill-tree.js +54 -0
- package/dist-lib/lib/tools/toolsets.d.ts +1 -1
- package/dist-lib/lib/tools/toolsets.js +2 -0
- package/dist-lib/lib/tools/web-fetch.js +41 -130
- package/dist-lib/lib/wire/download.d.ts +10 -0
- package/dist-lib/lib/wire/download.js +35 -0
- package/dist-lib/lib/wire/event.d.ts +41 -0
- package/dist-lib/lib/wire/event.js +306 -0
- package/dist-lib/lib/wire/fields.d.ts +3 -0
- package/dist-lib/lib/wire/fields.js +12 -0
- package/dist-lib/lib/wire/knowledge.d.ts +9 -0
- package/dist-lib/lib/wire/knowledge.js +68 -0
- package/dist-lib/lib/wire/round.d.ts +14 -0
- package/dist-lib/lib/wire/round.js +45 -0
- package/dist-lib/lib/wire/vectors.d.ts +6 -0
- package/dist-lib/lib/wire/vectors.js +33 -0
- package/dist-lib/lib/wire.d.ts +28 -77
- package/dist-lib/lib/wire.js +24 -463
- package/dist-lib/plugins/charts/chart-tool.d.ts +8 -0
- package/dist-lib/plugins/charts/chart-tool.js +175 -0
- package/dist-lib/plugins/charts/index.d.ts +16 -0
- package/dist-lib/plugins/charts/index.js +21 -0
- package/dist-lib/plugins/coding-guards/index.d.ts +25 -0
- package/dist-lib/plugins/coding-guards/index.js +126 -0
- package/dist-lib/plugins/diagrams/draw.d.ts +10 -0
- package/dist-lib/plugins/diagrams/draw.js +90 -0
- package/dist-lib/plugins/diagrams/index.d.ts +13 -0
- package/dist-lib/plugins/diagrams/index.js +15 -0
- package/dist-lib/plugins/diagrams/render.d.ts +16 -0
- package/dist-lib/plugins/diagrams/render.js +285 -0
- package/dist-lib/plugins/image/edit-image.d.ts +3 -22
- package/dist-lib/plugins/image/edit-image.js +20 -44
- package/dist-lib/plugins/image/fit.d.ts +31 -0
- package/dist-lib/plugins/image/fit.js +28 -0
- package/dist-lib/plugins/image/generate-image.d.ts +24 -4
- package/dist-lib/plugins/image/generate-image.js +198 -72
- package/dist-lib/plugins/image/index.d.ts +2 -1
- package/dist-lib/plugins/image/index.js +17 -8
- package/dist-lib/plugins/knowledge/index.d.ts +3 -0
- package/dist-lib/plugins/knowledge/index.js +5 -0
- package/dist-lib/plugins/knowledge/manifest.d.ts +53 -0
- package/dist-lib/plugins/knowledge/manifest.js +86 -0
- package/dist-lib/plugins/knowledge/search-tool.js +8 -8
- package/dist-lib/plugins/knowledge/store.d.ts +45 -8
- package/dist-lib/plugins/knowledge/store.js +428 -166
- package/dist-lib/plugins/mcp/call.js +15 -4
- package/dist-lib/plugins/mcp/protocol.d.ts +10 -2
- package/dist-lib/plugins/mcp/protocol.js +13 -12
- package/dist-lib/plugins/mcp/tool-listing.d.ts +6 -0
- package/dist-lib/plugins/mcp/tool-listing.js +97 -0
- package/dist-lib/plugins/music/generate-music.d.ts +21 -4
- package/dist-lib/plugins/music/generate-music.js +168 -65
- package/dist-lib/plugins/music/index.d.ts +2 -1
- package/dist-lib/plugins/music/index.js +11 -6
- package/dist-lib/plugins/obsidian/index.js +14 -4
- package/dist-lib/plugins/ocr/bmp.d.ts +2 -0
- package/dist-lib/plugins/ocr/bmp.js +27 -0
- package/dist-lib/plugins/ocr/coverage.d.ts +3 -0
- package/dist-lib/plugins/ocr/coverage.js +67 -0
- package/dist-lib/plugins/ocr/index.d.ts +12 -0
- package/dist-lib/plugins/ocr/index.js +20 -0
- package/dist-lib/plugins/ocr/ocr-runtime.d.ts +25 -0
- package/dist-lib/plugins/ocr/ocr-runtime.js +103 -0
- package/dist-lib/plugins/ocr/reading-order.d.ts +5 -0
- package/dist-lib/plugins/ocr/reading-order.js +218 -0
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/index.d.ts +4 -1
- package/dist-lib/plugins/python/index.js +5 -1
- package/dist-lib/plugins/python/language.js +11 -10
- package/dist-lib/plugins/python/python-adapter.d.ts +6 -1
- package/dist-lib/plugins/python/python-adapter.js +34 -1
- package/dist-lib/plugins/python/worker/client.js +1 -1
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/spawn.js +1 -1
- package/dist-lib/plugins/ripgrep/index.d.ts +15 -0
- package/dist-lib/plugins/ripgrep/index.js +28 -0
- package/dist-lib/plugins/run-report/story.js +4 -1
- package/dist-lib/plugins/sandbox-linux/index.js +2 -2
- package/dist-lib/plugins/sandbox-macos/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/index.d.ts +2 -1
- package/dist-lib/plugins/sandbox-vm/index.js +2 -2
- package/dist-lib/plugins/sandbox-vm/vm-shell.d.ts +3 -1
- package/dist-lib/plugins/sandbox-vm/vm-shell.js +45 -16
- package/dist-lib/plugins/sandbox-windows/index.js +2 -2
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/speech/speech-engine.d.ts +1 -1
- package/dist-lib/plugins/speech/speech-engine.js +10 -5
- package/dist-lib/plugins/speech/speech-text.d.ts +1 -0
- package/dist-lib/plugins/speech/speech-text.js +9 -4
- package/dist-lib/plugins/speech/voice.js +7 -2
- package/dist-lib/plugins/walkie-talkie/index.d.ts +2 -0
- package/dist-lib/plugins/walkie-talkie/index.js +6 -1
- package/dist-lib/plugins/weather/lookup.js +1 -0
- package/dist-lib/schema/baseline.d.ts +2 -1
- package/dist-lib/schema/baseline.js +2 -2
- package/dist-lib/schema/generate.js +8 -1
- package/dist-lib/schema/harness.js +34 -5
- package/dist-lib/schema/release-tags.d.ts +2 -1
- package/dist-lib/schema/release-tags.js +9 -10
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +126 -13
- package/dist-lib/spec/hyperschema/index.js +126 -13
- package/dist-lib/spec/hyperschema/schema.json +86 -2
- package/dist-lib/spec/hyperschema/types.d.ts +18 -3
- package/package.json +96 -36
- package/scripts/addon-externals.cjs +7 -1
- package/worker/harness-sidecar.mjs +10 -0
- package/dist-lib/lib/helpers/buffer-burst.d.ts +0 -1
- package/dist-lib/lib/helpers/buffer-burst.js +0 -22
- package/dist-lib/lib/office/engine/codes.d.ts +0 -62
- package/dist-lib/lib/office/engine/codes.js +0 -61
- package/dist-lib/lib/office/engine/docx/document.d.ts +0 -216
- package/dist-lib/lib/office/engine/docx/document.js +0 -1152
- package/dist-lib/lib/office/engine/docx/index.d.ts +0 -7
- package/dist-lib/lib/office/engine/docx/index.js +0 -8
- package/dist-lib/lib/office/engine/docx/styles.d.ts +0 -31
- package/dist-lib/lib/office/engine/docx/styles.js +0 -173
- package/dist-lib/lib/office/engine/docx/template.d.ts +0 -18
- package/dist-lib/lib/office/engine/docx/template.js +0 -133
- package/dist-lib/lib/office/engine/docx/text.d.ts +0 -55
- package/dist-lib/lib/office/engine/docx/text.js +0 -538
- package/dist-lib/lib/office/engine/drawingml/chart.d.ts +0 -63
- package/dist-lib/lib/office/engine/drawingml/chart.js +0 -539
- package/dist-lib/lib/office/engine/drawingml/text.d.ts +0 -35
- package/dist-lib/lib/office/engine/drawingml/text.js +0 -352
- package/dist-lib/lib/office/engine/errors.d.ts +0 -6
- package/dist-lib/lib/office/engine/errors.js +0 -12
- package/dist-lib/lib/office/engine/image.d.ts +0 -8
- package/dist-lib/lib/office/engine/image.js +0 -48
- package/dist-lib/lib/office/engine/index.d.ts +0 -12
- package/dist-lib/lib/office/engine/index.js +0 -7
- package/dist-lib/lib/office/engine/opc/content-types.d.ts +0 -17
- package/dist-lib/lib/office/engine/opc/content-types.js +0 -74
- package/dist-lib/lib/office/engine/opc/media.d.ts +0 -13
- package/dist-lib/lib/office/engine/opc/media.js +0 -11
- package/dist-lib/lib/office/engine/opc/package.d.ts +0 -51
- package/dist-lib/lib/office/engine/opc/package.js +0 -324
- package/dist-lib/lib/office/engine/opc/paths.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/paths.js +0 -46
- package/dist-lib/lib/office/engine/opc/properties.d.ts +0 -7
- package/dist-lib/lib/office/engine/opc/properties.js +0 -75
- package/dist-lib/lib/office/engine/opc/relationships.d.ts +0 -23
- package/dist-lib/lib/office/engine/opc/relationships.js +0 -65
- package/dist-lib/lib/office/engine/opc/zip.d.ts +0 -15
- package/dist-lib/lib/office/engine/opc/zip.js +0 -264
- package/dist-lib/lib/office/engine/pptx/fit.d.ts +0 -12
- package/dist-lib/lib/office/engine/pptx/fit.js +0 -37
- package/dist-lib/lib/office/engine/pptx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/pptx/index.js +0 -8
- package/dist-lib/lib/office/engine/pptx/inherit.d.ts +0 -29
- package/dist-lib/lib/office/engine/pptx/inherit.js +0 -155
- package/dist-lib/lib/office/engine/pptx/notes.d.ts +0 -5
- package/dist-lib/lib/office/engine/pptx/notes.js +0 -85
- package/dist-lib/lib/office/engine/pptx/picture-area.d.ts +0 -23
- package/dist-lib/lib/office/engine/pptx/picture-area.js +0 -84
- package/dist-lib/lib/office/engine/pptx/presentation.d.ts +0 -56
- package/dist-lib/lib/office/engine/pptx/presentation.js +0 -787
- package/dist-lib/lib/office/engine/pptx/read.d.ts +0 -9
- package/dist-lib/lib/office/engine/pptx/read.js +0 -66
- package/dist-lib/lib/office/engine/pptx/shapes.d.ts +0 -52
- package/dist-lib/lib/office/engine/pptx/shapes.js +0 -276
- package/dist-lib/lib/office/engine/pptx/slides.d.ts +0 -27
- package/dist-lib/lib/office/engine/pptx/slides.js +0 -123
- package/dist-lib/lib/office/engine/pptx/template.d.ts +0 -20
- package/dist-lib/lib/office/engine/pptx/template.js +0 -391
- package/dist-lib/lib/office/engine/pptx/types.d.ts +0 -121
- package/dist-lib/lib/office/engine/units.d.ts +0 -3
- package/dist-lib/lib/office/engine/units.js +0 -12
- package/dist-lib/lib/office/engine/utf8.d.ts +0 -2
- package/dist-lib/lib/office/engine/utf8.js +0 -103
- package/dist-lib/lib/office/engine/xlsx/formula.d.ts +0 -49
- package/dist-lib/lib/office/engine/xlsx/formula.js +0 -381
- package/dist-lib/lib/office/engine/xlsx/index.d.ts +0 -8
- package/dist-lib/lib/office/engine/xlsx/index.js +0 -8
- package/dist-lib/lib/office/engine/xlsx/refs.d.ts +0 -22
- package/dist-lib/lib/office/engine/xlsx/refs.js +0 -82
- package/dist-lib/lib/office/engine/xlsx/reshape.d.ts +0 -21
- package/dist-lib/lib/office/engine/xlsx/reshape.js +0 -424
- package/dist-lib/lib/office/engine/xlsx/sheet.d.ts +0 -108
- package/dist-lib/lib/office/engine/xlsx/sheet.js +0 -662
- package/dist-lib/lib/office/engine/xlsx/strings.d.ts +0 -15
- package/dist-lib/lib/office/engine/xlsx/strings.js +0 -93
- package/dist-lib/lib/office/engine/xlsx/styles.d.ts +0 -38
- package/dist-lib/lib/office/engine/xlsx/styles.js +0 -369
- package/dist-lib/lib/office/engine/xlsx/template.d.ts +0 -7
- package/dist-lib/lib/office/engine/xlsx/template.js +0 -54
- package/dist-lib/lib/office/engine/xlsx/workbook.d.ts +0 -162
- package/dist-lib/lib/office/engine/xlsx/workbook.js +0 -881
- package/dist-lib/lib/office/engine/xlsx/write.d.ts +0 -2
- package/dist-lib/lib/office/engine/xlsx/write.js +0 -42
- package/dist-lib/lib/office/engine/xml.d.ts +0 -45
- package/dist-lib/lib/office/engine/xml.js +0 -258
- package/patches/localwatch@1.4.3.patch +0 -13
- /package/dist-lib/lib/{office/engine/pptx/types.js → contract/media.js} +0 -0
package/dist-lib/lib/connect.js
CHANGED
|
@@ -2,8 +2,6 @@ import b4a from 'b4a';
|
|
|
2
2
|
import { randomBytes } from 'crypto';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
4
|
import fs from 'fs';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
import { HarnessError } from './errors.js';
|
|
7
5
|
import { settleOnClose } from './rpc-session.js';
|
|
8
6
|
import { harnessClient } from '../spec/calls.js';
|
|
9
7
|
import HRPC from '../spec/hrpc/index.js';
|
|
@@ -12,21 +10,25 @@ import { unsupportedKvCacheDeletion } from './capabilities/kv-cache.js';
|
|
|
12
10
|
import { checkGoal, checkMaxToolRounds } from './capabilities/tool-turns.js';
|
|
13
11
|
import { Agent } from './agent/index.js';
|
|
14
12
|
import { readModelSourcePreview } from './capabilities/preview-model-source.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { MediaHost } from './media-host.js';
|
|
14
|
+
import { discardRequestWire, mediaRequestWire } from './media-wire.js';
|
|
17
15
|
import { RoundHost } from './round-host.js';
|
|
18
16
|
import { HarnessLog } from './log.js';
|
|
19
17
|
import { assertEmbedDevice } from './models/embed-config.js';
|
|
20
18
|
import { addonTaskType } from './models/model-task.js';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { stageFile, sweepStaging } from './staging.js';
|
|
19
|
+
import { errorMessage, isRecord } from './guards.js';
|
|
20
|
+
import { sweepStaging } from './staging.js';
|
|
24
21
|
import { sweepSpill } from './spill.js';
|
|
25
22
|
import { readInstall, readSetup } from './tools/skills/manifest-parse.js';
|
|
26
|
-
import { SKILL_STATE } from './tools/skills/skill-state.js';
|
|
27
23
|
import { asToolset } from './tools/toolsets.js';
|
|
28
|
-
import {
|
|
29
|
-
|
|
24
|
+
import { Wire } from './wire.js';
|
|
25
|
+
import { loadedModel, parseSkillState, errorDetails, knobs, explicitEmptyIdentityFields, frames, downloadFrames } from './connect/decode.js';
|
|
26
|
+
import { died, noop, abortable, awaitWithAbort } from './connect/abort.js';
|
|
27
|
+
import { abortedRound, servedRound, servedMedia } from './connect/served.js';
|
|
28
|
+
import { bridgeAttach, bridgeShow, bridgeFetch, bridgeDrive, sendInput, answerQuestion, approvalCall } from './connect/bridges.js';
|
|
29
|
+
import { bridgeRunLog, validateHostRunLogLease, acquireHostRunLogLease } from './connect/host-run-log.js';
|
|
30
|
+
import { RoundLog } from './connect/round-log.js';
|
|
31
|
+
export { HARNESS_DIED } from './connect/abort.js';
|
|
30
32
|
const PAUSE_GRACE_MS = 10_000;
|
|
31
33
|
export function connectHarness(transport, options = {}) {
|
|
32
34
|
return new RemoteHarness(transport, options);
|
|
@@ -133,7 +135,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
133
135
|
payload.explicitEmptyIdentity = explicitEmptyIdentity;
|
|
134
136
|
}
|
|
135
137
|
if (context.knowledge) {
|
|
136
|
-
|
|
138
|
+
const { scopes, focus, k } = context.knowledge;
|
|
139
|
+
payload.knowledge = { scopes: [...scopes], focus: focus && [...focus], k };
|
|
137
140
|
}
|
|
138
141
|
if (context.planMode) {
|
|
139
142
|
payload.planMode = true;
|
|
@@ -156,9 +159,21 @@ export class RemoteHarness extends EventEmitter {
|
|
|
156
159
|
if (context.modelRound) {
|
|
157
160
|
payload.modelRound = true;
|
|
158
161
|
}
|
|
162
|
+
if (context.mediaRound) {
|
|
163
|
+
payload.mediaRound = true;
|
|
164
|
+
}
|
|
159
165
|
if (context.roundCut) {
|
|
160
166
|
payload.roundCut = true;
|
|
161
167
|
}
|
|
168
|
+
if (context.showImage) {
|
|
169
|
+
payload.showImage = true;
|
|
170
|
+
}
|
|
171
|
+
if (context.projectSkills?.length) {
|
|
172
|
+
payload.projectSkills = context.projectSkills;
|
|
173
|
+
}
|
|
174
|
+
if (context.workspaceSkills?.length) {
|
|
175
|
+
payload.workspaceSkills = context.workspaceSkills;
|
|
176
|
+
}
|
|
162
177
|
if (context.maxToolRounds !== undefined && context.maxToolRounds !== 0) {
|
|
163
178
|
payload.maxToolRounds = checkMaxToolRounds(context.maxToolRounds);
|
|
164
179
|
}
|
|
@@ -210,6 +225,30 @@ export class RemoteHarness extends EventEmitter {
|
|
|
210
225
|
duplex.destroy();
|
|
211
226
|
}
|
|
212
227
|
}
|
|
228
|
+
async serveMediaRound(request, io) {
|
|
229
|
+
const aborted = abortedRound(io.signal);
|
|
230
|
+
const { client } = await Promise.race([this._ensure(), aborted]);
|
|
231
|
+
const payload = await mediaRequestWire(request);
|
|
232
|
+
const duplex = client.completion();
|
|
233
|
+
const stop = () => duplex.destroy();
|
|
234
|
+
io.signal?.addEventListener?.('abort', stop, { once: true });
|
|
235
|
+
try {
|
|
236
|
+
const frame = { type: 'media-round-ask', payload };
|
|
237
|
+
encode('@harness/completion-frame', frame);
|
|
238
|
+
duplex.write(frame);
|
|
239
|
+
const served = servedMedia(frames(duplex), io);
|
|
240
|
+
served.catch(noop);
|
|
241
|
+
return await Promise.race([served, aborted]);
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
await discardRequestWire(payload);
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
io.signal?.removeEventListener?.('abort', stop);
|
|
249
|
+
duplex.destroy();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
213
252
|
async *invoke(context) {
|
|
214
253
|
const agent = context.agent ?? {};
|
|
215
254
|
yield* this._run({
|
|
@@ -296,8 +335,19 @@ export class RemoteHarness extends EventEmitter {
|
|
|
296
335
|
};
|
|
297
336
|
let pauseTimer;
|
|
298
337
|
let started = false;
|
|
338
|
+
const slowAppends = { warned: false };
|
|
339
|
+
let ended = 'finished';
|
|
340
|
+
const roundLog = new RoundLog();
|
|
299
341
|
const rounds = context.modelRound &&
|
|
300
342
|
new RoundHost(context.modelRound, (frame) => {
|
|
343
|
+
roundLog.settled('model', frame);
|
|
344
|
+
if (!closed) {
|
|
345
|
+
send({ ...frame });
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const media = context.mediaRound &&
|
|
349
|
+
new MediaHost(context.mediaRound, (frame) => {
|
|
350
|
+
roundLog.settled('media', frame);
|
|
301
351
|
if (!closed) {
|
|
302
352
|
send({ ...frame });
|
|
303
353
|
}
|
|
@@ -341,8 +391,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
341
391
|
(hostLease.boot !== undefined && hostLease.boot.metadata !== null);
|
|
342
392
|
payload.runLog = {
|
|
343
393
|
boot: hostLease.boot ?? null,
|
|
344
|
-
digestKey: b4a.toHex(hostLease.digestKey)
|
|
345
|
-
hostAppendTimeoutMs: context.hostAppendTimeoutMs
|
|
394
|
+
digestKey: b4a.toHex(hostLease.digestKey)
|
|
346
395
|
};
|
|
347
396
|
startFrame = { ...open, payload };
|
|
348
397
|
}
|
|
@@ -427,7 +476,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
427
476
|
}
|
|
428
477
|
if (event.type === 'fetch-ask') {
|
|
429
478
|
const callId = event.callId;
|
|
430
|
-
|
|
479
|
+
const show = isRecord(event.payload) && event.payload.show === true;
|
|
480
|
+
void (show ? bridgeShow(event, context) : bridgeFetch(event, context, staged))
|
|
431
481
|
.then((frame) => {
|
|
432
482
|
if (closed) {
|
|
433
483
|
return reclaim();
|
|
@@ -471,7 +521,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
471
521
|
event,
|
|
472
522
|
context,
|
|
473
523
|
runId: leasedRunId,
|
|
474
|
-
generation: hostLease?.generation
|
|
524
|
+
generation: hostLease?.generation,
|
|
525
|
+
slow: slowAppends
|
|
475
526
|
})
|
|
476
527
|
.then((frame) => {
|
|
477
528
|
if (!closed) {
|
|
@@ -505,20 +556,35 @@ export class RemoteHarness extends EventEmitter {
|
|
|
505
556
|
continue;
|
|
506
557
|
}
|
|
507
558
|
if (event.type === 'model-round-ask') {
|
|
559
|
+
roundLog.ask('model', event.callId ?? '', event.payload);
|
|
508
560
|
rounds?.ask(event.callId ?? '', event.payload);
|
|
509
561
|
continue;
|
|
510
562
|
}
|
|
511
563
|
if (event.type === 'model-round-cancel') {
|
|
564
|
+
roundLog.end('model', event.callId ?? '', 'cancelled');
|
|
512
565
|
rounds?.cancel(event.callId ?? '');
|
|
513
566
|
continue;
|
|
514
567
|
}
|
|
515
|
-
|
|
568
|
+
if (event.type === 'media-round-ask') {
|
|
569
|
+
roundLog.ask('media', event.callId ?? '', event.payload);
|
|
570
|
+
media?.ask(event.callId ?? '', event.payload);
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (event.type === 'media-round-cancel') {
|
|
574
|
+
roundLog.end('media', event.callId ?? '', 'cancelled');
|
|
575
|
+
media?.cancel(event.callId ?? '');
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
const wire = Wire.fromWire(event);
|
|
516
579
|
if (wire.type === 'aborted' || wire.type === 'paused') {
|
|
517
580
|
emittedAborted = true;
|
|
518
581
|
}
|
|
582
|
+
if (wire.type === 'aborted' || wire.type === 'paused' || wire.type === 'error') {
|
|
583
|
+
ended = wire.type;
|
|
584
|
+
}
|
|
519
585
|
yield wire;
|
|
520
586
|
}
|
|
521
|
-
HarnessLog.info('client wire ended', { received });
|
|
587
|
+
HarnessLog.info('client wire ended', { received, reason: ended });
|
|
522
588
|
}
|
|
523
589
|
catch (err) {
|
|
524
590
|
if (failure) {
|
|
@@ -542,6 +608,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
542
608
|
duplex?.destroy();
|
|
543
609
|
closed = true;
|
|
544
610
|
rounds?.close();
|
|
611
|
+
media?.close();
|
|
545
612
|
reclaim();
|
|
546
613
|
if (hostLease && leasedRunId && context.runLog) {
|
|
547
614
|
let timer;
|
|
@@ -586,7 +653,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
586
653
|
}
|
|
587
654
|
context.signal?.addEventListener?.('abort', onAbort, { once: true });
|
|
588
655
|
for await (const event of downloadFrames(stream)) {
|
|
589
|
-
const wire = fromDownloadWire(event);
|
|
656
|
+
const wire = Wire.fromDownloadWire(event);
|
|
590
657
|
if (wire.type === 'aborted') {
|
|
591
658
|
emittedAborted = true;
|
|
592
659
|
}
|
|
@@ -613,7 +680,7 @@ export class RemoteHarness extends EventEmitter {
|
|
|
613
680
|
async embed(context) {
|
|
614
681
|
const { client } = await this._ensure();
|
|
615
682
|
const response = await abortable(client.embed({ model: context.model, texts: context.texts }), context.signal);
|
|
616
|
-
const rows = unpackVectors(response.dimensions, response.vectors);
|
|
683
|
+
const rows = Wire.unpackVectors(response.dimensions, response.vectors);
|
|
617
684
|
if (rows.length !== context.texts.length) {
|
|
618
685
|
throw new Error(`embed returned ${rows.length} vectors for ${context.texts.length} texts`);
|
|
619
686
|
}
|
|
@@ -624,6 +691,16 @@ export class RemoteHarness extends EventEmitter {
|
|
|
624
691
|
const response = await abortable(client.transcribe({ model: context.model, audio: context.audio }), context.signal);
|
|
625
692
|
return response.text;
|
|
626
693
|
}
|
|
694
|
+
async ocrRead(context) {
|
|
695
|
+
const { client } = await this._ensure();
|
|
696
|
+
const { width, height, data } = context.image;
|
|
697
|
+
const response = await abortable(client.ocrRead({
|
|
698
|
+
width,
|
|
699
|
+
height,
|
|
700
|
+
data: b4a.from(data.buffer, data.byteOffset, data.byteLength)
|
|
701
|
+
}), context.signal);
|
|
702
|
+
return { text: response.text, coverage: response.coverage ?? 0 };
|
|
703
|
+
}
|
|
627
704
|
async detectLanguage(context) {
|
|
628
705
|
const { client } = await this._ensure();
|
|
629
706
|
const response = await client.detectLanguage({
|
|
@@ -839,8 +916,8 @@ export class RemoteHarness extends EventEmitter {
|
|
|
839
916
|
}
|
|
840
917
|
async knowledgeUpsert(artifact) {
|
|
841
918
|
const { client } = await this._ensure();
|
|
842
|
-
const response = await client.knowledgeUpsert(toKnowledgeUpsertWire(artifact));
|
|
843
|
-
return fromKnowledgeUpsertResultWire(response, artifact.chunks.length);
|
|
919
|
+
const response = await client.knowledgeUpsert(Wire.toKnowledgeUpsertWire(artifact));
|
|
920
|
+
return Wire.fromKnowledgeUpsertResultWire(response, artifact.chunks.length);
|
|
844
921
|
}
|
|
845
922
|
async knowledgeRemove(artifactId) {
|
|
846
923
|
const { client } = await this._ensure();
|
|
@@ -852,14 +929,15 @@ export class RemoteHarness extends EventEmitter {
|
|
|
852
929
|
const response = await client.knowledgeSearch({
|
|
853
930
|
text: query.text,
|
|
854
931
|
scopes: [...query.scopes],
|
|
855
|
-
k: query.k
|
|
932
|
+
k: query.k,
|
|
933
|
+
focus: query.focus && [...query.focus]
|
|
856
934
|
});
|
|
857
|
-
return response.hits.map(fromKnowledgeHitWire);
|
|
935
|
+
return response.hits.map(Wire.fromKnowledgeHitWire);
|
|
858
936
|
}
|
|
859
937
|
async knowledgeStatus() {
|
|
860
938
|
const { client } = await this._ensure();
|
|
861
939
|
const response = await client.knowledgeStatus({});
|
|
862
|
-
return fromKnowledgeStatusWire(response);
|
|
940
|
+
return Wire.fromKnowledgeStatusWire(response);
|
|
863
941
|
}
|
|
864
942
|
async list(options = {}) {
|
|
865
943
|
const { client } = await this._ensure();
|
|
@@ -986,423 +1064,3 @@ export class RemoteHarness extends EventEmitter {
|
|
|
986
1064
|
};
|
|
987
1065
|
}
|
|
988
1066
|
}
|
|
989
|
-
function loadedModel({ model, refs, fit }) {
|
|
990
|
-
if (!fit) {
|
|
991
|
-
return { model, refs };
|
|
992
|
-
}
|
|
993
|
-
const { verdict, reason, plan, deviceBytes, hostBytes } = fit;
|
|
994
|
-
return {
|
|
995
|
-
model,
|
|
996
|
-
refs,
|
|
997
|
-
fit: {
|
|
998
|
-
verdict,
|
|
999
|
-
reason,
|
|
1000
|
-
plan: plan ?? undefined,
|
|
1001
|
-
deviceBytes: deviceBytes || undefined,
|
|
1002
|
-
hostBytes: hostBytes || undefined
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function parseSkillState(value) {
|
|
1007
|
-
return value ? value : SKILL_STATE.failed;
|
|
1008
|
-
}
|
|
1009
|
-
function errorDetails(err) {
|
|
1010
|
-
return { error: errorMessage(err), code: errorCode(err) };
|
|
1011
|
-
}
|
|
1012
|
-
function isToolCallDisplay(value) {
|
|
1013
|
-
return isRecord(value) && typeof value.label === 'string';
|
|
1014
|
-
}
|
|
1015
|
-
function died(message) {
|
|
1016
|
-
return Object.assign(new Error(message), { code: HARNESS_DIED });
|
|
1017
|
-
}
|
|
1018
|
-
const noop = () => { };
|
|
1019
|
-
function abortedRound(signal) {
|
|
1020
|
-
const aborted = new Promise((_resolve, reject) => {
|
|
1021
|
-
const abort = () => reject(new AbortedError());
|
|
1022
|
-
if (signal?.aborted) {
|
|
1023
|
-
abort();
|
|
1024
|
-
}
|
|
1025
|
-
signal?.addEventListener?.('abort', abort, { once: true });
|
|
1026
|
-
});
|
|
1027
|
-
aborted.catch(noop);
|
|
1028
|
-
return aborted;
|
|
1029
|
-
}
|
|
1030
|
-
async function servedRound(events, io) {
|
|
1031
|
-
let emit = io.emit;
|
|
1032
|
-
for await (const event of events) {
|
|
1033
|
-
if (io.signal?.aborted)
|
|
1034
|
-
break;
|
|
1035
|
-
if (event.type === 'content' || event.type === 'thinking') {
|
|
1036
|
-
emit({ type: event.type, text: event.text ?? '' });
|
|
1037
|
-
}
|
|
1038
|
-
else if (event.type === 'model-round-retake') {
|
|
1039
|
-
emit = io.retake();
|
|
1040
|
-
}
|
|
1041
|
-
else if (event.type === 'model-round-result') {
|
|
1042
|
-
return roundResultFrom(event);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
throw died('the harness ended a served round without its result');
|
|
1046
|
-
}
|
|
1047
|
-
function abortable(promise, signal) {
|
|
1048
|
-
if (!signal)
|
|
1049
|
-
return promise;
|
|
1050
|
-
return new Promise((resolve, reject) => {
|
|
1051
|
-
if (signal.aborted) {
|
|
1052
|
-
promise.then(noop, noop);
|
|
1053
|
-
reject(new HarnessError('EMBED_ABORTED'));
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
const onAbort = () => reject(new HarnessError('EMBED_ABORTED'));
|
|
1057
|
-
signal.addEventListener?.('abort', onAbort, { once: true });
|
|
1058
|
-
promise.then(resolve, reject).finally(() => signal.removeEventListener?.('abort', onAbort));
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
function knobs(agent) {
|
|
1062
|
-
return {
|
|
1063
|
-
id: agent.id,
|
|
1064
|
-
name: agent.name,
|
|
1065
|
-
bio: agent.bio,
|
|
1066
|
-
reasoning: agent.reasoning ?? undefined,
|
|
1067
|
-
enabledTools: agent.enabledTools ?? undefined,
|
|
1068
|
-
enabledSkills: agent.enabledSkills ?? undefined,
|
|
1069
|
-
toolsScope: agent.toolsScope ?? undefined,
|
|
1070
|
-
skillsScope: agent.skillsScope ?? undefined,
|
|
1071
|
-
ctxSize: agent.ctxSize ?? undefined,
|
|
1072
|
-
kvCacheK: agent.kvCacheK ?? undefined,
|
|
1073
|
-
kvCacheV: agent.kvCacheV ?? undefined,
|
|
1074
|
-
imageModelChoice: agent.imageModelChoice ?? undefined,
|
|
1075
|
-
imageSteps: agent.imageSteps ?? undefined,
|
|
1076
|
-
imageWidth: agent.imageWidth ?? undefined,
|
|
1077
|
-
imageHeight: agent.imageHeight ?? undefined,
|
|
1078
|
-
approvalMode: agent.approvalMode ?? undefined,
|
|
1079
|
-
disabledToolsets: agent.disabledToolsets ?? undefined,
|
|
1080
|
-
policy: agent.policy ?? undefined,
|
|
1081
|
-
handoffs: agent.handoffs?.map(({ id, description }) => ({ id, description })),
|
|
1082
|
-
plan: agent.plan ?? undefined,
|
|
1083
|
-
model: agent.model ?? undefined
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
function explicitEmptyIdentityFields(context) {
|
|
1087
|
-
const fields = [];
|
|
1088
|
-
if (context.model === '') {
|
|
1089
|
-
fields.push('model');
|
|
1090
|
-
}
|
|
1091
|
-
if (context.cacheKey === '') {
|
|
1092
|
-
fields.push('cacheKey');
|
|
1093
|
-
}
|
|
1094
|
-
if (context.thinkingDefault === '') {
|
|
1095
|
-
fields.push('thinkingDefault');
|
|
1096
|
-
}
|
|
1097
|
-
if (context.agent?.id === '') {
|
|
1098
|
-
fields.push('agent.id');
|
|
1099
|
-
}
|
|
1100
|
-
if (context.agent?.name === '') {
|
|
1101
|
-
fields.push('agent.name');
|
|
1102
|
-
}
|
|
1103
|
-
if (context.agent?.bio === '') {
|
|
1104
|
-
fields.push('agent.bio');
|
|
1105
|
-
}
|
|
1106
|
-
return fields;
|
|
1107
|
-
}
|
|
1108
|
-
async function bridgeAttach(event, attach) {
|
|
1109
|
-
try {
|
|
1110
|
-
if (!attach) {
|
|
1111
|
-
return { type: 'attach-result', message: 'the host cannot persist attachments' };
|
|
1112
|
-
}
|
|
1113
|
-
const bytes = await fs.promises.readFile(event.path ?? '');
|
|
1114
|
-
const record = await attach({
|
|
1115
|
-
fileName: event.fileName ?? '',
|
|
1116
|
-
mimeType: event.mimeType ?? '',
|
|
1117
|
-
bytes,
|
|
1118
|
-
raw: event.raw === true
|
|
1119
|
-
});
|
|
1120
|
-
return {
|
|
1121
|
-
type: 'attach-result',
|
|
1122
|
-
attachment: {
|
|
1123
|
-
id: record.id,
|
|
1124
|
-
fileName: record.fileName,
|
|
1125
|
-
mimeType: record.mimeType,
|
|
1126
|
-
byteLength: record.byteLength
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
catch (err) {
|
|
1131
|
-
return { type: 'attach-result', message: errorMessage(err) };
|
|
1132
|
-
}
|
|
1133
|
-
finally {
|
|
1134
|
-
if (event.path) {
|
|
1135
|
-
void fs.promises.unlink(event.path).catch(noop);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
async function bridgeFetch(event, context, staged) {
|
|
1140
|
-
if (!context.fetchAttachment) {
|
|
1141
|
-
return { type: 'fetch-result', message: 'the host cannot read attachments' };
|
|
1142
|
-
}
|
|
1143
|
-
try {
|
|
1144
|
-
const metaOnly = event.meta === true;
|
|
1145
|
-
const found = await context.fetchAttachment({
|
|
1146
|
-
attachmentId: event.attachmentId ?? undefined,
|
|
1147
|
-
meta: metaOnly ? true : undefined,
|
|
1148
|
-
signal: context.signal
|
|
1149
|
-
});
|
|
1150
|
-
if (!found) {
|
|
1151
|
-
return { type: 'fetch-result' };
|
|
1152
|
-
}
|
|
1153
|
-
const size = 'bytes' in found && found.bytes !== null ? found.bytes.byteLength : found.byteLength;
|
|
1154
|
-
if (metaOnly) {
|
|
1155
|
-
return {
|
|
1156
|
-
type: 'fetch-result',
|
|
1157
|
-
meta: true,
|
|
1158
|
-
fileName: found.fileName,
|
|
1159
|
-
mimeType: found.mimeType,
|
|
1160
|
-
attachmentId: found.id,
|
|
1161
|
-
size
|
|
1162
|
-
};
|
|
1163
|
-
}
|
|
1164
|
-
if (!('bytes' in found) || found.bytes === null) {
|
|
1165
|
-
return { type: 'fetch-result', message: 'attachment has no bytes' };
|
|
1166
|
-
}
|
|
1167
|
-
const file = await stageFile('fetch', found.bytes);
|
|
1168
|
-
staged.push(file);
|
|
1169
|
-
return {
|
|
1170
|
-
type: 'fetch-result',
|
|
1171
|
-
path: file,
|
|
1172
|
-
fileName: found.fileName,
|
|
1173
|
-
mimeType: found.mimeType,
|
|
1174
|
-
attachmentId: found.id,
|
|
1175
|
-
size
|
|
1176
|
-
};
|
|
1177
|
-
}
|
|
1178
|
-
catch (err) {
|
|
1179
|
-
return { type: 'fetch-result', message: errorMessage(err) };
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
const DriveRequestSchema = z.discriminatedUnion('op', [
|
|
1183
|
-
z.looseObject({ op: z.literal('entry'), driveKey: z.string(), key: z.string() }),
|
|
1184
|
-
z.looseObject({ op: z.literal('get'), driveKey: z.string(), key: z.string() }),
|
|
1185
|
-
z.looseObject({ op: z.literal('read'), driveKey: z.string(), key: z.string() }),
|
|
1186
|
-
z.looseObject({
|
|
1187
|
-
op: z.literal('list'),
|
|
1188
|
-
driveKey: z.string(),
|
|
1189
|
-
folder: z.string(),
|
|
1190
|
-
skip: z.array(z.string()),
|
|
1191
|
-
recursive: z.boolean(),
|
|
1192
|
-
limit: z.number(),
|
|
1193
|
-
cursor: z.string().nullable()
|
|
1194
|
-
}),
|
|
1195
|
-
z.looseObject({
|
|
1196
|
-
op: z.literal('write'),
|
|
1197
|
-
driveKey: z.string(),
|
|
1198
|
-
key: z.string(),
|
|
1199
|
-
path: z.string(),
|
|
1200
|
-
executable: z.boolean().optional()
|
|
1201
|
-
}),
|
|
1202
|
-
z.looseObject({
|
|
1203
|
-
op: z.literal('search'),
|
|
1204
|
-
driveKey: z.string(),
|
|
1205
|
-
folder: z.string(),
|
|
1206
|
-
queries: z.array(z.string()),
|
|
1207
|
-
regex: z.boolean(),
|
|
1208
|
-
caseSensitive: z.boolean(),
|
|
1209
|
-
includeIgnored: z.boolean(),
|
|
1210
|
-
maxMatches: z.number(),
|
|
1211
|
-
maxEntries: z.number(),
|
|
1212
|
-
maxMs: z.number()
|
|
1213
|
-
})
|
|
1214
|
-
]);
|
|
1215
|
-
async function bridgeDrive(event, context) {
|
|
1216
|
-
if (!context.driveOp) {
|
|
1217
|
-
return { type: 'drive-result', message: 'the host cannot proxy drives' };
|
|
1218
|
-
}
|
|
1219
|
-
try {
|
|
1220
|
-
const payload = await context.driveOp(DriveRequestSchema.parse(event.payload));
|
|
1221
|
-
return { type: 'drive-result', payload };
|
|
1222
|
-
}
|
|
1223
|
-
catch (err) {
|
|
1224
|
-
return { type: 'drive-result', message: errorMessage(err) };
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
async function sendInput(input, send) {
|
|
1228
|
-
const iterator = input[Symbol.asyncIterator]();
|
|
1229
|
-
for (;;) {
|
|
1230
|
-
const next = await iterator.next();
|
|
1231
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1232
|
-
if (next.done || !send(next.value)) {
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
function answerQuestion(event, { askUser, reply }) {
|
|
1238
|
-
const callId = event.callId;
|
|
1239
|
-
if (!askUser) {
|
|
1240
|
-
reply({ type: 'question-result', callId, message: 'the host cannot ask questions' });
|
|
1241
|
-
return;
|
|
1242
|
-
}
|
|
1243
|
-
void Promise.resolve()
|
|
1244
|
-
.then(() => askUser({
|
|
1245
|
-
question: event.question ?? '',
|
|
1246
|
-
options: Array.isArray(event.options) ? event.options.map(String) : undefined
|
|
1247
|
-
}))
|
|
1248
|
-
.then((answer) => reply({ type: 'question-result', callId, answer: answer ?? '' }), (err) => reply({ type: 'question-result', callId, message: errorMessage(err) }))
|
|
1249
|
-
.catch((err) => HarnessLog.warn('question reply failed', { callId, message: errorMessage(err) }));
|
|
1250
|
-
}
|
|
1251
|
-
async function bridgeRunLog({ event, context, runId, generation }) {
|
|
1252
|
-
if (!context.runLog || !generation) {
|
|
1253
|
-
return { type: 'run-log-result', message: 'the host does not own this run log' };
|
|
1254
|
-
}
|
|
1255
|
-
const step = event.payload;
|
|
1256
|
-
if (!isEngineStep(step)) {
|
|
1257
|
-
return { type: 'run-log-result', message: 'the worker sent an invalid run-log step' };
|
|
1258
|
-
}
|
|
1259
|
-
try {
|
|
1260
|
-
await context.runLog.append(runId ?? '', generation, step);
|
|
1261
|
-
return { type: 'run-log-result' };
|
|
1262
|
-
}
|
|
1263
|
-
catch (err) {
|
|
1264
|
-
return { type: 'run-log-result', message: errorMessage(err) };
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
function isEngineStep(value) {
|
|
1268
|
-
return (isRecord(value) &&
|
|
1269
|
-
typeof value.seq === 'number' &&
|
|
1270
|
-
Number.isSafeInteger(value.seq) &&
|
|
1271
|
-
value.seq >= 0 &&
|
|
1272
|
-
typeof value.expectedLength === 'number' &&
|
|
1273
|
-
Number.isSafeInteger(value.expectedLength) &&
|
|
1274
|
-
value.expectedLength >= 0 &&
|
|
1275
|
-
Array.isArray(value.records));
|
|
1276
|
-
}
|
|
1277
|
-
function isDigestKey(value) {
|
|
1278
|
-
return value instanceof Uint8Array && value.byteLength === 32;
|
|
1279
|
-
}
|
|
1280
|
-
function releaseLateHostLease(pending, runLog, runId) {
|
|
1281
|
-
void pending
|
|
1282
|
-
.then(async (lease) => {
|
|
1283
|
-
if (!lease || typeof lease.generation !== 'string' || !lease.generation) {
|
|
1284
|
-
throw new Error('host returned an invalid generation for an aborted run-log begin');
|
|
1285
|
-
}
|
|
1286
|
-
await runLog.release(runId, lease.generation);
|
|
1287
|
-
})
|
|
1288
|
-
.catch((err) => HarnessLog.info('aborted run-log begin cleanup failed', {
|
|
1289
|
-
runId,
|
|
1290
|
-
message: errorMessage(err)
|
|
1291
|
-
}));
|
|
1292
|
-
}
|
|
1293
|
-
function validateHostRunLogLease(lease, runId) {
|
|
1294
|
-
if (typeof lease.generation !== 'string' || !lease.generation || !isDigestKey(lease.digestKey)) {
|
|
1295
|
-
throw new Error('host returned an invalid run-log lease');
|
|
1296
|
-
}
|
|
1297
|
-
if (lease.boot) {
|
|
1298
|
-
RunLog.validateEngineBoot(lease.boot);
|
|
1299
|
-
}
|
|
1300
|
-
const metadata = lease.boot?.metadata;
|
|
1301
|
-
if (metadata && metadata.runId !== runId) {
|
|
1302
|
-
throw new Error('host returned a run-log boot for a different run');
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
function approvalCall(event) {
|
|
1306
|
-
const identity = isRecord(event.payload) ? event.payload : {};
|
|
1307
|
-
const approval = {
|
|
1308
|
-
name: event.name ?? '',
|
|
1309
|
-
arguments: isRecord(event.arguments) ? event.arguments : {},
|
|
1310
|
-
resource: event.resource ?? null,
|
|
1311
|
-
effect: event.effect === 'read' ? 'read' : 'write',
|
|
1312
|
-
intent: event.intent || null,
|
|
1313
|
-
display: isToolCallDisplay(event.display) ? event.display : null,
|
|
1314
|
-
quote: event.question || null
|
|
1315
|
-
};
|
|
1316
|
-
if (typeof identity.callId === 'string') {
|
|
1317
|
-
approval.callId = identity.callId;
|
|
1318
|
-
}
|
|
1319
|
-
if (typeof identity.round === 'number') {
|
|
1320
|
-
approval.round = identity.round;
|
|
1321
|
-
}
|
|
1322
|
-
return approval;
|
|
1323
|
-
}
|
|
1324
|
-
async function acquireHostRunLogLease(runLog, runId, signal) {
|
|
1325
|
-
if (!runId) {
|
|
1326
|
-
throw new Error('host-owned run log requires a run id');
|
|
1327
|
-
}
|
|
1328
|
-
const pending = runLog.begin(runId);
|
|
1329
|
-
try {
|
|
1330
|
-
return await awaitWithAbort(pending, signal);
|
|
1331
|
-
}
|
|
1332
|
-
catch (err) {
|
|
1333
|
-
if (!signal?.aborted) {
|
|
1334
|
-
throw err;
|
|
1335
|
-
}
|
|
1336
|
-
releaseLateHostLease(pending, runLog, runId);
|
|
1337
|
-
return null;
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
function awaitWithAbort(promise, signal) {
|
|
1341
|
-
if (!signal)
|
|
1342
|
-
return promise;
|
|
1343
|
-
if (signal.aborted) {
|
|
1344
|
-
return Promise.reject(new Error('operation aborted'));
|
|
1345
|
-
}
|
|
1346
|
-
return new Promise((resolve, reject) => {
|
|
1347
|
-
let settled = false;
|
|
1348
|
-
const cleanup = () => signal.removeEventListener?.('abort', onAbort);
|
|
1349
|
-
const onAbort = () => {
|
|
1350
|
-
if (settled)
|
|
1351
|
-
return;
|
|
1352
|
-
settled = true;
|
|
1353
|
-
cleanup();
|
|
1354
|
-
reject(new Error('operation aborted'));
|
|
1355
|
-
};
|
|
1356
|
-
signal.addEventListener?.('abort', onAbort, { once: true });
|
|
1357
|
-
promise.then((value) => {
|
|
1358
|
-
if (settled)
|
|
1359
|
-
return;
|
|
1360
|
-
settled = true;
|
|
1361
|
-
cleanup();
|
|
1362
|
-
resolve(value);
|
|
1363
|
-
}, (error) => {
|
|
1364
|
-
if (settled)
|
|
1365
|
-
return;
|
|
1366
|
-
settled = true;
|
|
1367
|
-
cleanup();
|
|
1368
|
-
reject(error);
|
|
1369
|
-
});
|
|
1370
|
-
});
|
|
1371
|
-
}
|
|
1372
|
-
async function* frames(stream) {
|
|
1373
|
-
const queue = pushQueue();
|
|
1374
|
-
let error = null;
|
|
1375
|
-
stream.on('data', (frame) => queue.push(frame));
|
|
1376
|
-
stream.on('end', () => {
|
|
1377
|
-
HarnessLog.debug('client stream event', { event: 'end' });
|
|
1378
|
-
queue.end();
|
|
1379
|
-
});
|
|
1380
|
-
stream.on('close', () => {
|
|
1381
|
-
HarnessLog.debug('client stream event', { event: 'close' });
|
|
1382
|
-
queue.end();
|
|
1383
|
-
});
|
|
1384
|
-
stream.on('error', (err) => {
|
|
1385
|
-
HarnessLog.warn('client stream event', { event: 'error', err: err.message });
|
|
1386
|
-
error = err;
|
|
1387
|
-
queue.end();
|
|
1388
|
-
});
|
|
1389
|
-
yield* queue;
|
|
1390
|
-
if (error) {
|
|
1391
|
-
throw error;
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
async function* downloadFrames(stream) {
|
|
1395
|
-
const queue = pushQueue();
|
|
1396
|
-
let error = null;
|
|
1397
|
-
stream.on('data', (frame) => queue.push(frame));
|
|
1398
|
-
stream.on('end', () => queue.end());
|
|
1399
|
-
stream.on('close', () => queue.end());
|
|
1400
|
-
stream.on('error', (err) => {
|
|
1401
|
-
error = err;
|
|
1402
|
-
queue.end();
|
|
1403
|
-
});
|
|
1404
|
-
yield* queue;
|
|
1405
|
-
if (error) {
|
|
1406
|
-
throw error;
|
|
1407
|
-
}
|
|
1408
|
-
}
|