@qvac/harness 1.0.0-rc.9 → 1.0.1
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 +701 -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/shell-guidance.d.ts +2 -0
- package/dist-lib/lib/tools/exec/shell-guidance.js +29 -0
- package/dist-lib/lib/tools/exec.js +4 -2
- 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 +93 -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/tls-failure.d.ts +1 -0
- package/dist-lib/lib/tools/tls-failure.js +8 -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 +46 -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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { displayPath, isDeniedPath } from './scope.js';
|
|
3
|
+
import { shownPath } from './tool-path.js';
|
|
4
|
+
import { WALK_SKIP_DIRS } from './walk.js';
|
|
5
|
+
const SUGGESTIONS = 3;
|
|
6
|
+
const HINT = 'Use list_dir or glob to find the right path.';
|
|
7
|
+
export async function missingFile({ requested, resolved: { root, key }, anchor, deny }) {
|
|
8
|
+
const show = (at) => shownPath(displayPath(root, at), anchor);
|
|
9
|
+
let child = key;
|
|
10
|
+
let parent = parentOf(key);
|
|
11
|
+
let found = await children(root, parent, deny);
|
|
12
|
+
while (found.length === 0 && parent !== '/') {
|
|
13
|
+
child = parent;
|
|
14
|
+
parent = parentOf(parent);
|
|
15
|
+
found = await children(root, parent, deny);
|
|
16
|
+
}
|
|
17
|
+
const folderMissing = child !== key;
|
|
18
|
+
const near = similar(found.filter((entry) => entry.folder === folderMissing).map((entry) => entry.name), child.slice(child.lastIndexOf('/') + 1)).map((name) => show(under(parent, name)));
|
|
19
|
+
const picks = [...(await rerooted(requested, deny, anchor)), ...near].slice(0, SUGGESTIONS);
|
|
20
|
+
const nearest = show(parent) === '.' ? 'the shared folder' : show(parent);
|
|
21
|
+
const head = folderMissing
|
|
22
|
+
? `no such file: ${requested}. The folder ${show(child)} does not exist; the nearest that does is ${nearest}.`
|
|
23
|
+
: `no such file: ${requested}.`;
|
|
24
|
+
return { error: picks.length ? `${head} Did you mean:\n${picks.join('\n')}` : `${head} ${HINT}` };
|
|
25
|
+
}
|
|
26
|
+
async function rerooted(requested, deny, anchor) {
|
|
27
|
+
if (anchor?.kind !== 'local' || !path.isAbsolute(requested)) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const given = path.resolve(requested);
|
|
31
|
+
if (inside(anchor.root, given) || !inside(path.dirname(anchor.root), given)) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const key = `/${path.relative(path.dirname(anchor.root), given).split(path.sep).join('/')}`;
|
|
35
|
+
const shown = displayPath(anchor, key);
|
|
36
|
+
return (await anchor.drive.entry(key)) && !isDeniedPath(shown, deny) ? [shown] : [];
|
|
37
|
+
}
|
|
38
|
+
function inside(folder, target) {
|
|
39
|
+
const relative = path.relative(folder, target);
|
|
40
|
+
return relative !== '' && relative.split(path.sep)[0] !== '..' && !path.isAbsolute(relative);
|
|
41
|
+
}
|
|
42
|
+
async function children(root, folder, deny) {
|
|
43
|
+
const found = [];
|
|
44
|
+
for await (const entry of root.drive.list(folder, { recursive: false, skip: WALK_SKIP_DIRS })) {
|
|
45
|
+
if (!isDeniedPath(displayPath(root, entry.key), deny)) {
|
|
46
|
+
found.push({ name: entry.key.slice(entry.key.lastIndexOf('/') + 1), folder: 'dir' in entry });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return found;
|
|
50
|
+
}
|
|
51
|
+
function parentOf(key) {
|
|
52
|
+
return key.slice(0, key.lastIndexOf('/')) || '/';
|
|
53
|
+
}
|
|
54
|
+
function under(folder, name) {
|
|
55
|
+
return folder === '/' ? `/${name}` : `${folder}/${name}`;
|
|
56
|
+
}
|
|
57
|
+
function similar(names, requested) {
|
|
58
|
+
const name = requested.toLowerCase();
|
|
59
|
+
const wanted = stem(name);
|
|
60
|
+
const typos = allowedTypos(wanted.length);
|
|
61
|
+
const tier = (candidate) => {
|
|
62
|
+
if (candidate === name) {
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
const found = stem(candidate);
|
|
66
|
+
if (found === wanted) {
|
|
67
|
+
return 2;
|
|
68
|
+
}
|
|
69
|
+
if (Math.min(found.length, wanted.length) >= 3 &&
|
|
70
|
+
(candidate.includes(name) ||
|
|
71
|
+
name.includes(candidate) ||
|
|
72
|
+
found.includes(wanted) ||
|
|
73
|
+
wanted.includes(found))) {
|
|
74
|
+
return 3;
|
|
75
|
+
}
|
|
76
|
+
const near = typos > 0 && Math.abs(found.length - wanted.length) <= typos;
|
|
77
|
+
return near && editDistance(found, wanted) <= typos ? 4 : undefined;
|
|
78
|
+
};
|
|
79
|
+
return names
|
|
80
|
+
.flatMap((entry) => {
|
|
81
|
+
const rank = tier(entry.toLowerCase());
|
|
82
|
+
return rank === undefined
|
|
83
|
+
? []
|
|
84
|
+
: [{ entry, rank, distance: editDistance(entry.toLowerCase(), name) }];
|
|
85
|
+
})
|
|
86
|
+
.sort((a, b) => a.rank - b.rank || a.distance - b.distance || a.entry.localeCompare(b.entry))
|
|
87
|
+
.slice(0, SUGGESTIONS)
|
|
88
|
+
.map((match) => match.entry);
|
|
89
|
+
}
|
|
90
|
+
function allowedTypos(length) {
|
|
91
|
+
if (length < 3) {
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
return length < 5 ? 1 : 2;
|
|
95
|
+
}
|
|
96
|
+
function stem(name) {
|
|
97
|
+
return name.slice(0, name.length - path.extname(name).length) || name;
|
|
98
|
+
}
|
|
99
|
+
function editDistance(a, b) {
|
|
100
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
101
|
+
for (let i = 1; i <= a.length; i++) {
|
|
102
|
+
const current = [i];
|
|
103
|
+
for (let j = 1; j <= b.length; j++) {
|
|
104
|
+
const substitute = (previous[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1);
|
|
105
|
+
current.push(Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, substitute));
|
|
106
|
+
}
|
|
107
|
+
previous = current;
|
|
108
|
+
}
|
|
109
|
+
return previous[b.length] ?? 0;
|
|
110
|
+
}
|
|
@@ -5,6 +5,8 @@ export interface Grants {
|
|
|
5
5
|
readonly fsWriteRoots?: readonly DriveRoot[] | undefined;
|
|
6
6
|
readonly policy?: CompiledPolicy | undefined;
|
|
7
7
|
}
|
|
8
|
+
export declare const MAX_LIMIT = 500;
|
|
9
|
+
export declare function pagingError(args: Record<string, unknown>): string | null;
|
|
8
10
|
export declare function anchorOf(grants: Grants | undefined): DriveRoot | undefined;
|
|
9
11
|
export declare function rootedPath(p: string, anchor: DriveRoot | undefined): string;
|
|
10
12
|
export declare function shownPath(full: string, anchor: DriveRoot | undefined): string;
|
|
@@ -18,6 +20,7 @@ export declare function resolveRooted(p: string, { grants, write, realpath, deni
|
|
|
18
20
|
export declare function rootedArgs(args: Record<string, unknown>, grants: Grants | undefined, keys: readonly string[]): string[] | null;
|
|
19
21
|
export declare function stringArg(args: Record<string, unknown>, key: string): string | null;
|
|
20
22
|
export declare function positiveInt(value: unknown): number | undefined;
|
|
23
|
+
export declare function signedLine(value: unknown): number | undefined;
|
|
21
24
|
export declare function existsNow(p: string | null, grants: Grants | undefined): boolean;
|
|
22
25
|
export interface LabelPaths {
|
|
23
26
|
readonly grants: Grants | undefined;
|
|
@@ -2,6 +2,15 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { callDenyRoots, hostPath, resolveKey } from './scope.js';
|
|
4
4
|
const HYPER_PREFIX = 'hyper://';
|
|
5
|
+
export const MAX_LIMIT = 500;
|
|
6
|
+
export function pagingError(args) {
|
|
7
|
+
for (const key of ['limit', 'offset']) {
|
|
8
|
+
if (args[key] !== undefined && !(Number.isInteger(args[key]) && Number(args[key]) >= 0)) {
|
|
9
|
+
return `${key} is a whole number`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
5
14
|
export function anchorOf(grants) {
|
|
6
15
|
return grants?.fsRoots?.[0] ?? grants?.fsWriteRoots?.[0];
|
|
7
16
|
}
|
|
@@ -53,6 +62,10 @@ export function positiveInt(value) {
|
|
|
53
62
|
const n = Number(value);
|
|
54
63
|
return value === undefined || value === null || !Number.isInteger(n) || n < 1 ? undefined : n;
|
|
55
64
|
}
|
|
65
|
+
export function signedLine(value) {
|
|
66
|
+
const n = Number(value);
|
|
67
|
+
return Number.isInteger(n) && n < 0 ? n : positiveInt(value);
|
|
68
|
+
}
|
|
56
69
|
export function existsNow(p, grants) {
|
|
57
70
|
const anchor = anchorOf(grants);
|
|
58
71
|
if (!p || !anchor || anchor.kind !== 'local') {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DriveRoot, WalkSummary } from '../../contract/drive.ts';
|
|
2
|
+
import { IgnoreRules } from './ignore.ts';
|
|
2
3
|
export declare const WALK_SKIP_DIRS: Set<string>;
|
|
4
|
+
export declare const HIDDEN_DIRS: Set<string>;
|
|
3
5
|
export declare const MAX_WALK_ENTRIES = 10000;
|
|
4
6
|
export declare const MAX_WALK_MS = 30000;
|
|
5
7
|
export interface WalkedFile {
|
|
6
8
|
path: string;
|
|
7
9
|
key: string;
|
|
8
10
|
byteLength: number;
|
|
9
|
-
|
|
10
|
-
export interface WalkSummary {
|
|
11
|
-
truncated: boolean;
|
|
12
|
-
skippedLinks: number;
|
|
11
|
+
mtime?: number;
|
|
13
12
|
}
|
|
14
13
|
export interface WalkResult extends WalkSummary {
|
|
15
14
|
files: WalkedFile[];
|
|
@@ -23,5 +22,6 @@ export interface WalkOptions {
|
|
|
23
22
|
maxEntries?: number;
|
|
24
23
|
maxMs?: number;
|
|
25
24
|
}
|
|
25
|
+
export declare function rootRules(root: DriveRoot, folder: string): Promise<IgnoreRules>;
|
|
26
26
|
export declare function walkFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): Promise<WalkResult>;
|
|
27
27
|
export declare function streamFiles(root: DriveRoot, folder?: string, opts?: WalkOptions): WalkStream;
|
|
@@ -5,13 +5,29 @@ import { pushQueue } from '../../queue.js';
|
|
|
5
5
|
import { IgnoreRules } from './ignore.js';
|
|
6
6
|
import { displayPath } from './scope.js';
|
|
7
7
|
export const WALK_SKIP_DIRS = new Set(['.git', 'node_modules', '.trash']);
|
|
8
|
-
const HIDDEN_DIRS = new Set(['.hg', '.svn', '.venv', '.cache', '.next']);
|
|
8
|
+
export const HIDDEN_DIRS = new Set(['.hg', '.svn', '.venv', '.cache', '.next']);
|
|
9
9
|
const IGNORE_FILES = ['.gitignore', '.ignore'];
|
|
10
10
|
export const MAX_WALK_ENTRIES = 10_000;
|
|
11
11
|
export const MAX_WALK_MS = 30_000;
|
|
12
12
|
function childKey(dir, name) {
|
|
13
13
|
return dir === '/' ? `/${name}` : `${dir}/${name}`;
|
|
14
14
|
}
|
|
15
|
+
async function withIgnoreFile(root, rules, key) {
|
|
16
|
+
const bytes = await root.drive.get(key);
|
|
17
|
+
const dir = key.slice(0, key.lastIndexOf('/'));
|
|
18
|
+
return bytes === null ? rules : rules.add(dir.slice(1), b4a.toString(bytes, 'utf8'));
|
|
19
|
+
}
|
|
20
|
+
export async function rootRules(root, folder) {
|
|
21
|
+
let rules = new IgnoreRules();
|
|
22
|
+
const parts = folder.split('/').filter(Boolean);
|
|
23
|
+
for (let depth = 0; depth < parts.length; depth++) {
|
|
24
|
+
const dir = '/' + parts.slice(0, depth).join('/');
|
|
25
|
+
for (const name of IGNORE_FILES) {
|
|
26
|
+
rules = await withIgnoreFile(root, rules, childKey(dir, name));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return rules;
|
|
30
|
+
}
|
|
15
31
|
function isIgnoreFile(child, key) {
|
|
16
32
|
return !('dir' in child) && child.value.linkname === null && child.key === key;
|
|
17
33
|
}
|
|
@@ -30,24 +46,8 @@ class Walk {
|
|
|
30
46
|
this.#maxEntries = maxEntries;
|
|
31
47
|
this.#deadline = Date.now() + maxMs;
|
|
32
48
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const dir = key.slice(0, key.lastIndexOf('/'));
|
|
36
|
-
return bytes === null ? rules : rules.add(dir.slice(1), b4a.toString(bytes, 'utf8'));
|
|
37
|
-
}
|
|
38
|
-
async rootRules(folder) {
|
|
39
|
-
let rules = new IgnoreRules();
|
|
40
|
-
if (this.#includeIgnored) {
|
|
41
|
-
return rules;
|
|
42
|
-
}
|
|
43
|
-
const parts = folder.split('/').filter(Boolean);
|
|
44
|
-
for (let depth = 0; depth < parts.length; depth++) {
|
|
45
|
-
const dir = '/' + parts.slice(0, depth).join('/');
|
|
46
|
-
for (const name of IGNORE_FILES) {
|
|
47
|
-
rules = await this.#withIgnoreFile(rules, childKey(dir, name));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return rules;
|
|
49
|
+
rootRules(folder) {
|
|
50
|
+
return this.#includeIgnored ? Promise.resolve(new IgnoreRules()) : rootRules(this.#root, folder);
|
|
51
51
|
}
|
|
52
52
|
async #list(dir) {
|
|
53
53
|
const children = [];
|
|
@@ -71,7 +71,7 @@ class Walk {
|
|
|
71
71
|
for (const name of IGNORE_FILES) {
|
|
72
72
|
const key = childKey(dir, name);
|
|
73
73
|
if (!this.#includeIgnored && children.some((child) => isIgnoreFile(child, key))) {
|
|
74
|
-
rules = await this.#
|
|
74
|
+
rules = await withIgnoreFile(this.#root, rules, key);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
return rules;
|
|
@@ -100,7 +100,8 @@ class Walk {
|
|
|
100
100
|
this.#onFile({
|
|
101
101
|
path: displayPath(this.#root, child.key),
|
|
102
102
|
key: child.key,
|
|
103
|
-
byteLength: child.value.blob?.byteLength ?? 0
|
|
103
|
+
byteLength: child.value.blob?.byteLength ?? 0,
|
|
104
|
+
mtime: child.mtime
|
|
104
105
|
});
|
|
105
106
|
}
|
|
106
107
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
export declare const MAX_RESPONSE_CHARS = 8192;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const IDLE_TIMEOUT_MS = 10000;
|
|
4
|
+
export declare const TIMEOUT_MS = 120000;
|
|
4
5
|
export interface FetchInit {
|
|
5
6
|
method: string;
|
|
6
7
|
headers: Record<string, string>;
|
|
@@ -8,8 +9,9 @@ export interface FetchInit {
|
|
|
8
9
|
signal: BareAbortSignal;
|
|
9
10
|
redirect?: 'manual';
|
|
10
11
|
validatedAddresses?: readonly string[] | undefined;
|
|
11
|
-
maxBytes?: number;
|
|
12
|
+
maxBytes?: number | ((contentType: string) => number);
|
|
12
13
|
truncate?: boolean;
|
|
14
|
+
idleTimeoutMs?: number;
|
|
13
15
|
}
|
|
14
16
|
export declare function isRedirectStatus(status: number): boolean;
|
|
15
17
|
export type ParseResult<T> = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isRecord } from '../../guards.js';
|
|
2
2
|
const BLOCKED_HEADERS = new Set(['authorization', 'cookie', 'proxy-authorization']);
|
|
3
3
|
export const MAX_RESPONSE_CHARS = 8192;
|
|
4
|
-
export const
|
|
4
|
+
export const IDLE_TIMEOUT_MS = 10_000;
|
|
5
|
+
export const TIMEOUT_MS = 120_000;
|
|
5
6
|
export function isRedirectStatus(status) {
|
|
6
7
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
7
8
|
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ToolExecuteContext } from '../../contract/index.ts';
|
|
2
|
+
type BudgetContext = Pick<ToolExecuteContext, 'ctxSize' | 'runBudget'> | undefined;
|
|
3
|
+
export declare function responseBudgetChars(ctx: BudgetContext): number;
|
|
4
|
+
export declare function capResponseBody(body: string, ctx: BudgetContext): CappedBody;
|
|
5
|
+
export interface ResponseCoverage {
|
|
6
|
+
readonly keptChars: number;
|
|
7
|
+
readonly totalChars: number;
|
|
8
|
+
readonly percent: number;
|
|
9
|
+
readonly note: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CappedBody {
|
|
12
|
+
readonly body: string;
|
|
13
|
+
readonly truncated?: ResponseCoverage;
|
|
14
|
+
}
|
|
15
|
+
export declare function truncateResponseBody(body: string, budget: number): CappedBody;
|
|
2
16
|
export declare const ELISION = "\u2026 [truncated]";
|
|
17
|
+
export {};
|
|
@@ -1,19 +1,55 @@
|
|
|
1
1
|
import { MAX_RESPONSE_CHARS } from './request.js';
|
|
2
2
|
import { isRecord } from '../../guards.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const RESPONSE_FLOOR_CHARS = 2048;
|
|
4
|
+
export function responseBudgetChars(ctx) {
|
|
5
|
+
const room = ctx?.runBudget?.responseRoomChars;
|
|
6
|
+
if (room !== undefined) {
|
|
7
|
+
return Math.max(RESPONSE_FLOOR_CHARS, room);
|
|
8
|
+
}
|
|
9
|
+
const ctxSize = ctx?.ctxSize;
|
|
10
|
+
return ctxSize ? Math.max(MAX_RESPONSE_CHARS, Math.floor(ctxSize / 4)) : MAX_RESPONSE_CHARS;
|
|
11
|
+
}
|
|
12
|
+
export function capResponseBody(body, ctx) {
|
|
13
|
+
const capped = truncateResponseBody(body, responseBudgetChars(ctx));
|
|
14
|
+
const budget = ctx?.runBudget;
|
|
15
|
+
if (budget?.responseRoomChars !== undefined) {
|
|
16
|
+
budget.responseRoomChars = Math.max(0, budget.responseRoomChars - capped.body.length);
|
|
17
|
+
}
|
|
18
|
+
return capped;
|
|
19
|
+
}
|
|
20
|
+
const NOT_JSON = Symbol('not-json');
|
|
21
|
+
export function truncateResponseBody(body, budget) {
|
|
22
|
+
if (body.length <= budget) {
|
|
23
|
+
return { body };
|
|
24
|
+
}
|
|
25
|
+
const parsed = parseJson(body);
|
|
26
|
+
if (parsed !== NOT_JSON) {
|
|
27
|
+
const compact = JSON.stringify(parsed);
|
|
28
|
+
if (compact.length <= budget) {
|
|
29
|
+
return { body: compact };
|
|
30
|
+
}
|
|
31
|
+
const kept = JSON.stringify(fit(parsed, budget));
|
|
32
|
+
return { body: kept, truncated: coverageOf(Math.min(kept.length, budget), compact.length) };
|
|
33
|
+
}
|
|
34
|
+
const kept = `${body.slice(0, budget)}${ELISION}`;
|
|
35
|
+
return { body: kept, truncated: coverageOf(budget, body.length) };
|
|
36
|
+
}
|
|
37
|
+
function coverageOf(keptChars, totalChars) {
|
|
38
|
+
const percent = Math.max(1, Math.floor((keptChars / totalChars) * 100));
|
|
39
|
+
return {
|
|
40
|
+
keptChars,
|
|
41
|
+
totalChars,
|
|
42
|
+
percent,
|
|
43
|
+
note: `Only the first ${percent}% of this response was read, to fit the context window. Tell the user that your answer covers that part only.`
|
|
44
|
+
};
|
|
7
45
|
}
|
|
8
|
-
function
|
|
9
|
-
let parsed;
|
|
46
|
+
function parseJson(body) {
|
|
10
47
|
try {
|
|
11
|
-
|
|
48
|
+
return JSON.parse(body);
|
|
12
49
|
}
|
|
13
50
|
catch {
|
|
14
|
-
return
|
|
51
|
+
return NOT_JSON;
|
|
15
52
|
}
|
|
16
|
-
return JSON.stringify(fit(parsed, MAX_RESPONSE_CHARS));
|
|
17
53
|
}
|
|
18
54
|
const MARKER_CHARS = 64;
|
|
19
55
|
function shrinkable(value) {
|
|
@@ -27,7 +63,16 @@ function fitString(value, budget) {
|
|
|
27
63
|
if (room <= 0) {
|
|
28
64
|
return ELISION;
|
|
29
65
|
}
|
|
30
|
-
|
|
66
|
+
let cut = Math.min(value.length, room);
|
|
67
|
+
let size = serializedLength(value.slice(0, cut));
|
|
68
|
+
while (size > room) {
|
|
69
|
+
cut = Math.min(cut - 1, Math.floor((cut * room) / size));
|
|
70
|
+
size = serializedLength(value.slice(0, cut));
|
|
71
|
+
}
|
|
72
|
+
return `${value.slice(0, cut)}${ELISION}`;
|
|
73
|
+
}
|
|
74
|
+
function serializedLength(value) {
|
|
75
|
+
return JSON.stringify(value).length - 2;
|
|
31
76
|
}
|
|
32
77
|
function fitArray(value, room) {
|
|
33
78
|
const kept = [];
|
|
@@ -88,7 +133,7 @@ function fit(value, budget) {
|
|
|
88
133
|
return fitObject(value, room);
|
|
89
134
|
}
|
|
90
135
|
if (typeof value === 'string' && JSON.stringify(value).length > budget) {
|
|
91
|
-
return fitString(value,
|
|
136
|
+
return fitString(value, room);
|
|
92
137
|
}
|
|
93
138
|
return value;
|
|
94
139
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { noRedirectFetch } from '#no-redirect-fetch';
|
|
2
2
|
import { AbortController } from 'bare-abort-controller';
|
|
3
|
+
import { URL } from 'url';
|
|
3
4
|
import { lookupHost } from '../dns-lookup.js';
|
|
4
5
|
import { READ_METHODS } from './http-methods.js';
|
|
5
6
|
import { encodeDeclaredFields } from './http-request/encode-fields.js';
|
|
6
|
-
import {
|
|
7
|
+
import { capResponseBody } from './http-request/truncate-response.js';
|
|
7
8
|
import { AbortedError } from '../helpers/race-abort.js';
|
|
8
|
-
import { applyQuery, buildHeaders, contentTypeOf, encodeBody, isRedirectStatus, parseJsonBody, parseObjectArg, TIMEOUT_MS } from './http-request/request.js';
|
|
9
|
+
import { applyQuery, buildHeaders, contentTypeOf, encodeBody, isRedirectStatus, parseJsonBody, IDLE_TIMEOUT_MS, parseObjectArg, TIMEOUT_MS } from './http-request/request.js';
|
|
9
10
|
import { parseAuth, resolveBearerHeader, resolveRedirectBearerHeader } from './skills/auth-resolver.js';
|
|
10
11
|
import { recordCredentialHealth } from './skills/credential-health.js';
|
|
11
12
|
import { Policy } from '../policy/index.js';
|
|
13
|
+
import { attachFetchedFile, attachTextFile, bareMime, dispositionFileName, isFileMime, MAX_FILE_BYTES } from './attachments/fetched-file.js';
|
|
12
14
|
import { resolveOutboundUrl } from './url-guard.js';
|
|
15
|
+
import { tlsFailure } from './tls-failure.js';
|
|
13
16
|
const MAX_REDIRECTS = 5;
|
|
14
17
|
export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credentialStore, credentialAllowList, resolveHost = lookupHost } = {}) {
|
|
15
18
|
return {
|
|
@@ -17,7 +20,7 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
17
20
|
policyVersion,
|
|
18
21
|
toolset: 'http-request',
|
|
19
22
|
defer: true,
|
|
20
|
-
description: 'Make an outbound HTTP or HTTPS request and return the response status and body
|
|
23
|
+
description: 'Make an outbound HTTP or HTTPS request and return the response status and body as text. A body too large for the context window is cut, and `truncated` then says what share of it was read. Authorization/Cookie headers are stripped before sending. Stored skill credentials are attached automatically for their allow-listed hosts; `auth` is only needed to force a specific credential key. A response that is a file — PDF, .docx, .xlsx, an image, audio, video, any binary — is attached to the chat instead of returned as text: the result carries its attachmentId, and `fileName` names it.',
|
|
21
24
|
parameters: {
|
|
22
25
|
type: 'object',
|
|
23
26
|
properties: {
|
|
@@ -43,6 +46,10 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
43
46
|
auth: {
|
|
44
47
|
type: 'object',
|
|
45
48
|
description: 'Optional bearer auth: {"type": "bearer", "tokenCredentialKey": "<key>"}. Pass ONLY the credential key name — NEVER a token value. The tool resolves the actual secret itself; the model never sees it.'
|
|
49
|
+
},
|
|
50
|
+
fileName: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'Optional. The name to attach a file response under, e.g. "report.pdf"'
|
|
46
53
|
}
|
|
47
54
|
},
|
|
48
55
|
required: ['url']
|
|
@@ -66,6 +73,9 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
66
73
|
},
|
|
67
74
|
async execute(rawArgs, ctx) {
|
|
68
75
|
const args = rawArgs;
|
|
76
|
+
if (ctx?.signal?.aborted) {
|
|
77
|
+
return { error: 'request cancelled', code: 'cancelled' };
|
|
78
|
+
}
|
|
69
79
|
let url;
|
|
70
80
|
try {
|
|
71
81
|
url = new URL(args.url);
|
|
@@ -100,11 +110,24 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
100
110
|
if (!auth.ok) {
|
|
101
111
|
return { error: auth.error };
|
|
102
112
|
}
|
|
103
|
-
|
|
113
|
+
if (args.fileName !== undefined && typeof args.fileName !== 'string') {
|
|
114
|
+
return { error: 'fileName must be a string' };
|
|
115
|
+
}
|
|
104
116
|
const hosts = Policy.hostsOf(ctx?.policy);
|
|
105
117
|
const controller = new AbortController();
|
|
106
|
-
|
|
118
|
+
let timedOut = false;
|
|
119
|
+
const timeout = setTimeout(() => {
|
|
120
|
+
timedOut = true;
|
|
121
|
+
controller.abort(undefined);
|
|
122
|
+
}, TIMEOUT_MS);
|
|
123
|
+
const onCallerAbort = () => controller.abort(undefined);
|
|
124
|
+
ctx?.signal?.addEventListener('abort', onCallerAbort);
|
|
125
|
+
const requestCtx = ctx ? { ...ctx, signal: controller.signal } : undefined;
|
|
107
126
|
try {
|
|
127
|
+
const allowList = credentialAllowList?.(requestCtx);
|
|
128
|
+
if (controller.signal.aborted) {
|
|
129
|
+
throw new AbortedError();
|
|
130
|
+
}
|
|
108
131
|
const initialCheck = await resolveOutboundUrl(url, {
|
|
109
132
|
resolveHost,
|
|
110
133
|
signal: controller.signal,
|
|
@@ -113,7 +136,7 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
113
136
|
if (initialCheck.blocked) {
|
|
114
137
|
return { error: initialCheck.blocked };
|
|
115
138
|
}
|
|
116
|
-
const bearer = await resolveBearerHeader(auth.value, url, credentialStore, allowList,
|
|
139
|
+
const bearer = await resolveBearerHeader(auth.value, url, credentialStore, allowList, requestCtx, controller.signal);
|
|
117
140
|
if ('error' in bearer) {
|
|
118
141
|
return { error: bearer.error };
|
|
119
142
|
}
|
|
@@ -131,6 +154,9 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
131
154
|
let validatedAddresses = initialCheck.addresses;
|
|
132
155
|
let response;
|
|
133
156
|
for (let redirects = 0;; redirects++) {
|
|
157
|
+
if (controller.signal.aborted) {
|
|
158
|
+
throw new AbortedError();
|
|
159
|
+
}
|
|
134
160
|
const hopHeaders = { ...headers };
|
|
135
161
|
delete hopHeaders['Authorization'];
|
|
136
162
|
if (header) {
|
|
@@ -142,7 +168,10 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
142
168
|
body,
|
|
143
169
|
signal: controller.signal,
|
|
144
170
|
redirect: 'manual',
|
|
145
|
-
validatedAddresses
|
|
171
|
+
validatedAddresses,
|
|
172
|
+
idleTimeoutMs: IDLE_TIMEOUT_MS,
|
|
173
|
+
maxBytes: MAX_FILE_BYTES,
|
|
174
|
+
truncate: true
|
|
146
175
|
});
|
|
147
176
|
if (credentialKey) {
|
|
148
177
|
recordCredentialHealth(credentialKey, response.status, ctx?.agentId);
|
|
@@ -182,27 +211,77 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
182
211
|
}
|
|
183
212
|
currentUrl = nextUrl;
|
|
184
213
|
validatedAddresses = hopCheck.addresses;
|
|
185
|
-
const next = await resolveRedirectBearerHeader(redirectAuth, currentUrl, credentialStore, allowList,
|
|
214
|
+
const next = await resolveRedirectBearerHeader(redirectAuth, currentUrl, credentialStore, allowList, requestCtx, controller.signal);
|
|
186
215
|
header = next.header;
|
|
187
216
|
credentialKey = next.credentialKey;
|
|
188
217
|
}
|
|
218
|
+
const mimeType = bareMime(response.headers?.get('content-type'));
|
|
219
|
+
if (ctx?.attach && isSuccess(response.status) && isFileMime(mimeType)) {
|
|
220
|
+
const attached = await attachFetchedFile(await response.bytes?.(), {
|
|
221
|
+
url: currentUrl,
|
|
222
|
+
mimeType,
|
|
223
|
+
attach: ctx.attach,
|
|
224
|
+
maxBytes: MAX_FILE_BYTES,
|
|
225
|
+
fileName: args.fileName ?? dispositionFileName(response.headers?.get('content-disposition'))
|
|
226
|
+
});
|
|
227
|
+
if ('error' in attached) {
|
|
228
|
+
return attached;
|
|
229
|
+
}
|
|
230
|
+
const { content, ...file } = attached;
|
|
231
|
+
return { status: response.status, ...file, body: content };
|
|
232
|
+
}
|
|
189
233
|
const text = await response.text();
|
|
234
|
+
if (ctx?.uncappedResponse) {
|
|
235
|
+
return { status: response.status, body: text };
|
|
236
|
+
}
|
|
237
|
+
const capped = capResponseBody(text, ctx);
|
|
238
|
+
const whole = capped.truncated && isSuccess(response.status) && isTextFile(mimeType, args.fileName)
|
|
239
|
+
? await attachTextFile(await response.bytes?.(), {
|
|
240
|
+
url: currentUrl,
|
|
241
|
+
mimeType,
|
|
242
|
+
attach: ctx?.attach,
|
|
243
|
+
maxBytes: MAX_FILE_BYTES,
|
|
244
|
+
fileName: args.fileName ?? dispositionFileName(response.headers?.get('content-disposition'))
|
|
245
|
+
})
|
|
246
|
+
: null;
|
|
247
|
+
if (!whole || !capped.truncated) {
|
|
248
|
+
return { status: response.status, ...capped };
|
|
249
|
+
}
|
|
190
250
|
return {
|
|
191
251
|
status: response.status,
|
|
192
|
-
body:
|
|
252
|
+
body: capped.body,
|
|
253
|
+
attachmentId: whole.id,
|
|
254
|
+
fileName: whole.fileName,
|
|
255
|
+
truncated: {
|
|
256
|
+
...capped.truncated,
|
|
257
|
+
note: `${capped.truncated.note} The whole file is attached as "${whole.fileName}": stage it with exec as inputs [{ "attachmentId": "${whole.id}", "path": "${whole.fileName}" }] to read or search past the cut.`
|
|
258
|
+
}
|
|
193
259
|
};
|
|
194
260
|
}
|
|
195
261
|
catch (err) {
|
|
196
262
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
263
|
+
if (ctx?.signal?.aborted) {
|
|
264
|
+
return { error: 'request cancelled', code: 'cancelled' };
|
|
265
|
+
}
|
|
266
|
+
if (timedOut || error.name === 'TimeoutError') {
|
|
267
|
+
return { error: 'request timed out', code: 'timeout' };
|
|
268
|
+
}
|
|
269
|
+
const tls = tlsFailure(err, url.hostname);
|
|
270
|
+
if (tls) {
|
|
271
|
+
return { error: tls, code: 'tls' };
|
|
272
|
+
}
|
|
273
|
+
return { error: `request failed: ${error.message}`, code: 'transport' };
|
|
202
274
|
}
|
|
203
275
|
finally {
|
|
204
276
|
clearTimeout(timeout);
|
|
277
|
+
ctx?.signal?.removeEventListener('abort', onCallerAbort);
|
|
205
278
|
}
|
|
206
279
|
}
|
|
207
280
|
};
|
|
208
281
|
}
|
|
282
|
+
function isTextFile(mimeType, fileName) {
|
|
283
|
+
return fileName !== undefined || (mimeType.startsWith('text/') && mimeType !== 'text/html');
|
|
284
|
+
}
|
|
285
|
+
function isSuccess(status) {
|
|
286
|
+
return status >= 200 && status < 300;
|
|
287
|
+
}
|
|
@@ -6,17 +6,19 @@ import type { CredentialStoreFn } from './skills/auth-resolver.ts';
|
|
|
6
6
|
import { ensureBundledSkillsDir } from './skills/bundled-dir.ts';
|
|
7
7
|
import type { SkillCatalogEntry } from './skills/catalog.ts';
|
|
8
8
|
export type { ExecInput } from './attachments/staging.ts';
|
|
9
|
+
export type { SkillsBundle } from './skills/bundled-dir.ts';
|
|
9
10
|
export interface ProductToolsOptions {
|
|
10
11
|
readonly sdkHome: string;
|
|
11
12
|
readonly skillsDir?: string | undefined;
|
|
12
13
|
readonly skillCatalog?: readonly SkillCatalogEntry[] | undefined;
|
|
13
14
|
readonly credentialStore?: CredentialStoreFn | undefined;
|
|
14
15
|
readonly files?: boolean | undefined;
|
|
16
|
+
readonly ask?: boolean | undefined;
|
|
15
17
|
}
|
|
16
18
|
export declare class Tools {
|
|
17
19
|
static deniedRoots: typeof deniedRootsFor;
|
|
18
20
|
static bundledSkillsDir: typeof ensureBundledSkillsDir;
|
|
19
21
|
static stageInputs: typeof stageInputs;
|
|
20
22
|
static operations: typeof compileOperationTools;
|
|
21
|
-
static product({ sdkHome, skillsDir, skillCatalog, credentialStore, files }: ProductToolsOptions): ToolDefinition[];
|
|
23
|
+
static product({ sdkHome, skillsDir, skillCatalog, credentialStore, files, ask }: ProductToolsOptions): ToolDefinition[];
|
|
22
24
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createAskUserTool } from './ask-user.js';
|
|
1
2
|
import { createFileTools } from './files/index.js';
|
|
2
3
|
import { deniedRootsFor } from './fs/scope.js';
|
|
3
4
|
import { createHttpRequestTool } from './http-request.js';
|
|
@@ -14,7 +15,7 @@ export class Tools {
|
|
|
14
15
|
static bundledSkillsDir = ensureBundledSkillsDir;
|
|
15
16
|
static stageInputs = stageInputs;
|
|
16
17
|
static operations = compileOperationTools;
|
|
17
|
-
static product({ sdkHome, skillsDir, skillCatalog, credentialStore, files = true }) {
|
|
18
|
+
static product({ sdkHome, skillsDir, skillCatalog, credentialStore, files = true, ask = false }) {
|
|
18
19
|
const deniedRoots = deniedRootsFor(sdkHome);
|
|
19
20
|
const credentialed = skillCatalog
|
|
20
21
|
? { credentialStore, credentialAllowList: credentialAllowListFor(skillCatalog) }
|
|
@@ -30,9 +31,12 @@ export class Tools {
|
|
|
30
31
|
if (skillCatalog) {
|
|
31
32
|
tools.push(...compileOperationTools(skillCatalog, { httpRequestTool }));
|
|
32
33
|
}
|
|
33
|
-
if (skillsDir) {
|
|
34
|
+
if (skillsDir || skillCatalog?.length) {
|
|
34
35
|
tools.push(createSkillTool({ skillsDir }));
|
|
35
36
|
}
|
|
37
|
+
if (ask) {
|
|
38
|
+
tools.push(createAskUserTool());
|
|
39
|
+
}
|
|
36
40
|
return tools;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -4,6 +4,7 @@ export interface OpSpec {
|
|
|
4
4
|
readonly inches?: boolean;
|
|
5
5
|
readonly query?: boolean;
|
|
6
6
|
readonly aliases?: Readonly<Record<string, string>>;
|
|
7
|
+
readonly skipsLooks?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const PPTX_OPS: Readonly<Record<string, OpSpec>>;
|
|
9
10
|
export declare const DOCX_OPS: Readonly<Record<string, OpSpec>>;
|