@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
|
@@ -7,7 +7,11 @@ export const PPTX_OPS = {
|
|
|
7
7
|
setText: { slots: [['slide', 'shape'], 'text'] },
|
|
8
8
|
setCellText: { slots: [['slide', 'shape', 'row', 'column'], 'text'] },
|
|
9
9
|
setStyle: { slots: [['slide', 'shape'], 'style', ['paragraph']] },
|
|
10
|
-
addSlide: {
|
|
10
|
+
addSlide: {
|
|
11
|
+
slots: [['like', 'layout', 'at', 'title', 'body', 'image']],
|
|
12
|
+
aliases: { subtitle: 'body' },
|
|
13
|
+
skipsLooks: true
|
|
14
|
+
},
|
|
11
15
|
addPicture: { slots: ['slide', 'image', [...BOX, 'name', 'description']], inches: true },
|
|
12
16
|
addTextBox: { slots: ['slide', [...BOX, 'text', 'style', 'fill', 'name']], inches: true },
|
|
13
17
|
addTable: { slots: ['slide', [...BOX, 'rows', 'header', 'name']], inches: true },
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { ToolDefinition } from '../contract/index.ts';
|
|
2
|
-
import { pptx, xlsx } from '
|
|
2
|
+
import { pptx, xlsx } from 'qvac-office';
|
|
3
3
|
type Deck = ReturnType<typeof pptx.open>;
|
|
4
4
|
type Workbook = ReturnType<typeof xlsx.open>;
|
|
5
5
|
type FormatName = 'pptx' | 'docx' | 'xlsx';
|
|
6
6
|
type Args = Record<string, unknown>;
|
|
7
|
+
export declare function bodyLines(op: Args): Args;
|
|
7
8
|
export declare function shapeFor(deck: Deck, op: Args): Args;
|
|
8
9
|
export declare function sheetFor(book: Workbook, op: Args, created: boolean): Args;
|
|
9
|
-
export declare function normalizeArgs(
|
|
10
|
+
export declare function normalizeArgs(raw: Args): Args;
|
|
10
11
|
export declare function revisedName(format: FormatName, fileName: string): string;
|
|
11
12
|
export declare function createOfficeTools(): ToolDefinition[];
|
|
12
13
|
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
1
|
import { HarnessError } from '../errors.js';
|
|
3
2
|
import { errorMessage, isRecord } from '../guards.js';
|
|
4
|
-
import { DocsError, docx, pptx, units, xlsx } from '
|
|
5
|
-
import { stageInputs } from './attachments/staging.js';
|
|
3
|
+
import { DocsError, docx, pptx, units, xlsx } from 'qvac-office';
|
|
4
|
+
import { stageInputs, uploadsAvailable } from './attachments/staging.js';
|
|
6
5
|
import { checkOutputBytes, RUN_OUTPUT_BUDGET_BYTES } from './attachments/output-policy.js';
|
|
6
|
+
import { attachmentOf, deliveredFile, recordDelivered, sha256 } from './attachments/delivered.js';
|
|
7
7
|
import { DOCX_OPS, opArguments, opKeys, PPTX_OPS, withAliases, XLSX_OPS } from './office/ops.js';
|
|
8
8
|
const READ_CELL_LIMIT = 10_000;
|
|
9
|
-
const attachedThisTurn = new WeakMap();
|
|
10
9
|
const FIRST_SHEET = /^sheet ?1$/i;
|
|
11
10
|
const NEW_DECK_HINT = '; a new deck has only the slides its addSlide ops make, slides count from 0, and an op on a slide goes after the addSlide that makes it';
|
|
12
11
|
const SHAPE_ROLES = new Set(['title', 'subtitle', 'body']);
|
|
@@ -17,6 +16,21 @@ const WHERE_IDS_ARE = 'copy the id from the [Attached file "…" — attachmentI
|
|
|
17
16
|
function isObject(value) {
|
|
18
17
|
return isRecord(value) && !Array.isArray(value);
|
|
19
18
|
}
|
|
19
|
+
const LOOK_KEY = /colou?r|background|^bg|font|style|theme|^level$/i;
|
|
20
|
+
function isLook(key, value) {
|
|
21
|
+
return value === null || LOOK_KEY.test(key);
|
|
22
|
+
}
|
|
23
|
+
const TYPED_BULLET = /^\s*[•◦▪●]\s+/;
|
|
24
|
+
export function bodyLines(op) {
|
|
25
|
+
const items = typeof op.body === 'string' ? [op.body] : op.body;
|
|
26
|
+
if (op.op !== 'addSlide' || !Array.isArray(items)) {
|
|
27
|
+
return op;
|
|
28
|
+
}
|
|
29
|
+
const body = items.flatMap((item) => typeof item === 'string'
|
|
30
|
+
? item.split('\n').map((line) => line.replace(TYPED_BULLET, ''))
|
|
31
|
+
: [item]);
|
|
32
|
+
return { ...op, body };
|
|
33
|
+
}
|
|
20
34
|
export function shapeFor(deck, op) {
|
|
21
35
|
const { shape, slide } = op;
|
|
22
36
|
if (typeof shape !== 'string' || SHAPE_ROLES.has(shape) || typeof slide !== 'number') {
|
|
@@ -80,11 +94,13 @@ const PPTX_FORMAT = {
|
|
|
80
94
|
stem: 'presentation',
|
|
81
95
|
ops: PPTX_OPS,
|
|
82
96
|
createKeys: ['size', 'title', 'fonts', 'colors'],
|
|
97
|
+
looks: ['fonts', 'colors'],
|
|
83
98
|
open: (bytes) => pptx.open(bytes),
|
|
84
99
|
create: (options) => pptx.create(options),
|
|
85
100
|
read: (deck) => deck.read(),
|
|
86
101
|
count: (deck) => ({ slides: deck.slideCount }),
|
|
87
|
-
prepare: (deck, op) => shapeFor(deck, op),
|
|
102
|
+
prepare: (deck, op) => shapeFor(deck, bodyLines(op)),
|
|
103
|
+
retry: withoutLayout,
|
|
88
104
|
hint: newDeckHint
|
|
89
105
|
};
|
|
90
106
|
const DOCX_FORMAT = {
|
|
@@ -114,13 +130,24 @@ const XLSX_FORMAT = {
|
|
|
114
130
|
? 'the workbook has macros, which cannot be saved as .xlsx — add a removeMacros op'
|
|
115
131
|
: null
|
|
116
132
|
};
|
|
117
|
-
export function normalizeArgs(
|
|
118
|
-
|
|
133
|
+
export function normalizeArgs(raw) {
|
|
134
|
+
const blankId = raw.attachmentId === '' || raw.attachmentId === null;
|
|
135
|
+
const args = blankId && isObject(raw.create) ? withoutKeys(raw, ['attachmentId']) : raw;
|
|
136
|
+
if (!Array.isArray(args.ops)) {
|
|
119
137
|
return args;
|
|
138
|
+
}
|
|
120
139
|
const lifted = { ...args };
|
|
121
140
|
const ops = [];
|
|
122
|
-
|
|
123
|
-
|
|
141
|
+
const entries = args.ops.flat();
|
|
142
|
+
for (const [i, entry] of entries.entries()) {
|
|
143
|
+
if (entries[i - 1] === 'output' && entry === ':') {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (entries[i - 2] === 'output' && entries[i - 1] === ':') {
|
|
147
|
+
lifted.output ??= typeof entry === 'string' && FILE_NAME.test(entry) ? entry : undefined;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const op = typeof entry === 'string' ? { op: entry } : opNamedByKey(entry);
|
|
124
151
|
if (!isObject(op)) {
|
|
125
152
|
ops.push(op);
|
|
126
153
|
continue;
|
|
@@ -147,6 +174,12 @@ export function normalizeArgs(args) {
|
|
|
147
174
|
lifted.ops = lifted.attachmentId === undefined ? ops.map(insertedWhereAsked) : ops;
|
|
148
175
|
return lifted;
|
|
149
176
|
}
|
|
177
|
+
function opNamedByKey(entry) {
|
|
178
|
+
if (!isObject(entry) || 'op' in entry)
|
|
179
|
+
return entry;
|
|
180
|
+
const [only, ...more] = Object.entries(entry);
|
|
181
|
+
return only && !more.length && isObject(only[1]) ? { ...only[1], op: only[0] } : entry;
|
|
182
|
+
}
|
|
150
183
|
function insertedWhereAsked(op) {
|
|
151
184
|
return isObject(op) && op.op === 'appendParagraphs' && op.at !== undefined
|
|
152
185
|
? { ...op, op: 'insertParagraphs' }
|
|
@@ -161,9 +194,16 @@ function parseOp(format, op, i) {
|
|
|
161
194
|
return `ops[${i}]: unknown op "${op.op}"; ops are ${Object.keys(format.ops).join(', ')}`;
|
|
162
195
|
}
|
|
163
196
|
const keys = opKeys(spec);
|
|
164
|
-
const
|
|
197
|
+
const extra = Object.keys(op).filter((key) => key !== 'op' && !keys.includes(key));
|
|
198
|
+
const skippable = spec.skipsLooks ? extra.filter((key) => isLook(key, op[key])) : [];
|
|
199
|
+
const unknown = extra.filter((key) => !skippable.includes(key));
|
|
165
200
|
if (!unknown.length) {
|
|
166
|
-
|
|
201
|
+
const kept = Object.fromEntries(Object.entries(op).filter(([key]) => !skippable.includes(key)));
|
|
202
|
+
const shadowed = Object.entries(spec.aliases ?? {})
|
|
203
|
+
.filter(([alias, key]) => kept[alias] !== undefined && kept[key] !== undefined)
|
|
204
|
+
.map(([alias]) => alias);
|
|
205
|
+
const skipped = [...skippable, ...shadowed].map((key) => `ops[${i}].${key}`);
|
|
206
|
+
return { op: { name: op.op, spec, args: withAliases(spec, kept) }, skipped };
|
|
167
207
|
}
|
|
168
208
|
if (op.op === 'sheets' && 'name' in op && format.ops.addSheet) {
|
|
169
209
|
return `ops[${i}] sheets lists the sheets and takes no arguments; to add a sheet use { op: "addSheet", name }`;
|
|
@@ -180,14 +220,16 @@ function parseOps(format, ops) {
|
|
|
180
220
|
return 'ops must be an array of { op, ...args }';
|
|
181
221
|
}
|
|
182
222
|
const parsed = [];
|
|
223
|
+
const skipped = [];
|
|
183
224
|
for (const [i, op] of ops.entries()) {
|
|
184
225
|
const result = parseOp(format, op, i);
|
|
185
226
|
if (typeof result === 'string') {
|
|
186
227
|
return result;
|
|
187
228
|
}
|
|
188
|
-
parsed.push(result);
|
|
229
|
+
parsed.push(result.op);
|
|
230
|
+
skipped.push(...result.skipped);
|
|
189
231
|
}
|
|
190
|
-
return parsed;
|
|
232
|
+
return { ops: parsed, skipped };
|
|
191
233
|
}
|
|
192
234
|
function argumentError(format, args) {
|
|
193
235
|
const { attachmentId, create, output } = args;
|
|
@@ -215,24 +257,25 @@ function parseRequest(format, raw) {
|
|
|
215
257
|
if (error) {
|
|
216
258
|
return error;
|
|
217
259
|
}
|
|
218
|
-
const
|
|
219
|
-
if (typeof
|
|
220
|
-
return
|
|
260
|
+
const parsed = parseOps(format, args.ops ?? []);
|
|
261
|
+
if (typeof parsed === 'string') {
|
|
262
|
+
return parsed;
|
|
221
263
|
}
|
|
222
264
|
const attachmentId = typeof args.attachmentId === 'string' ? args.attachmentId : undefined;
|
|
223
|
-
if (attachmentId === undefined && !ops.length) {
|
|
265
|
+
if (attachmentId === undefined && !parsed.ops.length && !isObject(args.create)) {
|
|
224
266
|
return `nothing to read: pass the attachmentId of a ${format.noun} (${WHERE_IDS_ARE}), or ops to build one`;
|
|
225
267
|
}
|
|
226
268
|
return {
|
|
227
269
|
attachmentId,
|
|
228
270
|
create: isObject(args.create) ? args.create : undefined,
|
|
229
|
-
ops,
|
|
230
|
-
output: typeof args.output === 'string' ? args.output : undefined
|
|
271
|
+
ops: parsed.ops,
|
|
272
|
+
output: typeof args.output === 'string' ? args.output : undefined,
|
|
273
|
+
skipped: parsed.skipped
|
|
231
274
|
};
|
|
232
275
|
}
|
|
233
276
|
async function sourceDocument(format, request, ctx) {
|
|
234
277
|
if (request.attachmentId === undefined) {
|
|
235
|
-
return
|
|
278
|
+
return createDocument(format, request.create ?? {});
|
|
236
279
|
}
|
|
237
280
|
const found = await ctx.fetchAttachment?.({
|
|
238
281
|
attachmentId: request.attachmentId,
|
|
@@ -243,7 +286,43 @@ async function sourceDocument(format, request, ctx) {
|
|
|
243
286
|
error: `attachment ${request.attachmentId} not found in this chat; ${WHERE_IDS_ARE}, not a file name`
|
|
244
287
|
};
|
|
245
288
|
}
|
|
246
|
-
return { document: format.open(found.bytes), fileName: found.fileName };
|
|
289
|
+
return { document: format.open(found.bytes), fileName: found.fileName, skipped: [] };
|
|
290
|
+
}
|
|
291
|
+
function createDocument(format, options) {
|
|
292
|
+
try {
|
|
293
|
+
return { document: format.create(options), fileName: null, skipped: [] };
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
const looks = (format.looks ?? []).filter((key) => options[key] !== undefined);
|
|
297
|
+
if (!invalidOptions(err) || !looks.length) {
|
|
298
|
+
throw err;
|
|
299
|
+
}
|
|
300
|
+
const plain = withoutKeys(options, looks);
|
|
301
|
+
const refused = looks.filter((key) => !creates(format, { ...plain, [key]: options[key] }));
|
|
302
|
+
return {
|
|
303
|
+
document: format.create(withoutKeys(options, refused)),
|
|
304
|
+
fileName: null,
|
|
305
|
+
skipped: refused.map((key) => `create.${key}`)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function creates(format, options) {
|
|
310
|
+
try {
|
|
311
|
+
format.create(options);
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
if (!invalidOptions(err)) {
|
|
316
|
+
throw err;
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function invalidOptions(err) {
|
|
322
|
+
return err instanceof DocsError && err.code === 'INVALID_OPTIONS';
|
|
323
|
+
}
|
|
324
|
+
function withoutKeys(args, keys) {
|
|
325
|
+
return Object.fromEntries(Object.entries(args).filter(([key]) => !keys.includes(key)));
|
|
247
326
|
}
|
|
248
327
|
export function revisedName(format, fileName) {
|
|
249
328
|
const dot = fileName.lastIndexOf('.');
|
|
@@ -290,7 +369,7 @@ async function imageInput(op, i, ctx) {
|
|
|
290
369
|
if (!isObject(image)) {
|
|
291
370
|
return { error: `ops[${i}]: image must be { attachmentId } or {}` };
|
|
292
371
|
}
|
|
293
|
-
const id = image.attachmentId;
|
|
372
|
+
const id = image.attachmentId ?? undefined;
|
|
294
373
|
if (id !== undefined && (typeof id !== 'string' || !id)) {
|
|
295
374
|
return { error: `ops[${i}]: image.attachmentId must be a non-empty string` };
|
|
296
375
|
}
|
|
@@ -299,6 +378,44 @@ async function imageInput(op, i, ctx) {
|
|
|
299
378
|
function takesImage(op) {
|
|
300
379
|
return op.spec.slots.includes('image') || op.args.image !== undefined;
|
|
301
380
|
}
|
|
381
|
+
async function withoutMissingUploads(request, ctx) {
|
|
382
|
+
if (!ctx.fetchAttachment || !request.ops.some((op) => idless(op) && optionalImage(op))) {
|
|
383
|
+
return request;
|
|
384
|
+
}
|
|
385
|
+
const available = await uploadsAvailable(ctx.fetchAttachment, {
|
|
386
|
+
turnImages: ctx.turnImages,
|
|
387
|
+
signal: ctx.signal
|
|
388
|
+
});
|
|
389
|
+
if (available === null) {
|
|
390
|
+
return request;
|
|
391
|
+
}
|
|
392
|
+
const uploading = await Promise.all(request.ops.map((op) => takesUpload(op, ctx)));
|
|
393
|
+
let uploads = 0;
|
|
394
|
+
const skipped = [];
|
|
395
|
+
const ops = request.ops.map((op, i) => {
|
|
396
|
+
if (!uploading[i] || uploads++ < available || !optionalImage(op)) {
|
|
397
|
+
return op;
|
|
398
|
+
}
|
|
399
|
+
skipped.push(`ops[${i}].image`);
|
|
400
|
+
return { ...op, args: withoutKeys(op.args, ['image']) };
|
|
401
|
+
});
|
|
402
|
+
return { ...request, ops, skipped: [...request.skipped, ...skipped] };
|
|
403
|
+
}
|
|
404
|
+
function idless(op) {
|
|
405
|
+
const { image } = op.args;
|
|
406
|
+
const id = isObject(image) ? image.attachmentId : image;
|
|
407
|
+
return takesImage(op) && (id === undefined || id === null);
|
|
408
|
+
}
|
|
409
|
+
async function takesUpload(op, ctx) {
|
|
410
|
+
const id = isObject(op.args.image) ? op.args.image.attachmentId : undefined;
|
|
411
|
+
if (typeof id !== 'string' || !id) {
|
|
412
|
+
return idless(op);
|
|
413
|
+
}
|
|
414
|
+
return (await imageId(ctx, id)) === undefined;
|
|
415
|
+
}
|
|
416
|
+
function optionalImage({ spec }) {
|
|
417
|
+
return spec.slots.some((slot) => typeof slot !== 'string' && slot.includes('image'));
|
|
418
|
+
}
|
|
302
419
|
async function stagedImages(request, ctx) {
|
|
303
420
|
const wanted = request.ops.flatMap((op, i) => (takesImage(op) ? [i] : []));
|
|
304
421
|
const images = new Map();
|
|
@@ -348,22 +465,22 @@ async function attachOutput(job, ctx) {
|
|
|
348
465
|
return { error: refused ?? 'nothing to save' };
|
|
349
466
|
}
|
|
350
467
|
const { output, document } = job;
|
|
351
|
-
const
|
|
352
|
-
const earlier =
|
|
468
|
+
const budget = ctx.runBudget;
|
|
469
|
+
const earlier = deliveredFile(budget, output);
|
|
353
470
|
const bytes = document.save();
|
|
354
|
-
|
|
355
|
-
|
|
471
|
+
const hash = sha256(bytes);
|
|
472
|
+
if (earlier?.sha256 === hash) {
|
|
473
|
+
return { attachment: attachmentOf(earlier), repeated: true };
|
|
356
474
|
}
|
|
357
475
|
if (earlier) {
|
|
358
476
|
return {
|
|
359
|
-
error: `${earlier.
|
|
477
|
+
error: `${earlier.fileName} is already attached with different content; save this version under a new name in output`
|
|
360
478
|
};
|
|
361
479
|
}
|
|
362
480
|
const verdict = checkOutputBytes(output, bytes, 0);
|
|
363
481
|
if ('error' in verdict) {
|
|
364
482
|
return verdict;
|
|
365
483
|
}
|
|
366
|
-
const budget = ctx.runBudget;
|
|
367
484
|
if (budget && budget.outputBytesUsed + bytes.byteLength > RUN_OUTPUT_BUDGET_BYTES) {
|
|
368
485
|
return { error: 'run output budget exceeded' };
|
|
369
486
|
}
|
|
@@ -381,8 +498,7 @@ async function attachOutput(job, ctx) {
|
|
|
381
498
|
fileName: record.fileName,
|
|
382
499
|
byteLength: record.byteLength
|
|
383
500
|
};
|
|
384
|
-
|
|
385
|
-
attachedThisTurn.set(ctx.attach, delivered);
|
|
501
|
+
recordDelivered(budget, { name: output.toLowerCase(), sha256: hash, ...attachment });
|
|
386
502
|
return { attachment, repeated: false };
|
|
387
503
|
}
|
|
388
504
|
function runOp(document, op, input) {
|
|
@@ -394,6 +510,7 @@ function runOp(document, op, input) {
|
|
|
394
510
|
}
|
|
395
511
|
function runOps({ format, document, request, images }) {
|
|
396
512
|
const results = [];
|
|
513
|
+
const skipped = [];
|
|
397
514
|
const created = request.attachmentId === undefined;
|
|
398
515
|
for (const [i, op] of request.ops.entries()) {
|
|
399
516
|
const placed = format.prepare?.(document, op.args, created) ?? op.args;
|
|
@@ -402,11 +519,35 @@ function runOps({ format, document, request, images }) {
|
|
|
402
519
|
results.push(runOp(document, op, input));
|
|
403
520
|
}
|
|
404
521
|
catch (err) {
|
|
522
|
+
const retry = format.retry?.(err, op, input);
|
|
523
|
+
const again = retry ? rerun(document, op, retry.input) : RETRY_FAILED;
|
|
524
|
+
if (retry && again !== RETRY_FAILED) {
|
|
525
|
+
results.push(again);
|
|
526
|
+
skipped.push(`ops[${i}].${retry.skipped}`);
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
405
529
|
const hint = format.hint?.(err, created) ?? '';
|
|
406
530
|
return { error: `ops[${i}] ${op.name}: ${errorMessage(err)}${hint}` };
|
|
407
531
|
}
|
|
408
532
|
}
|
|
409
|
-
return results;
|
|
533
|
+
return { results, skipped };
|
|
534
|
+
}
|
|
535
|
+
const RETRY_FAILED = Symbol('retry failed');
|
|
536
|
+
function rerun(document, op, input) {
|
|
537
|
+
try {
|
|
538
|
+
return runOp(document, op, input);
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
return RETRY_FAILED;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function withoutLayout(err, op, input) {
|
|
545
|
+
const shapeMissing = err instanceof DocsError && err.code === 'SHAPE_NOT_FOUND';
|
|
546
|
+
if (op.name !== 'addSlide' || input.layout === undefined || !shapeMissing) {
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
const { layout: _layout, ...rest } = input;
|
|
550
|
+
return { input: rest, skipped: 'layout' };
|
|
410
551
|
}
|
|
411
552
|
function countLine(counts) {
|
|
412
553
|
return Object.entries(counts)
|
|
@@ -444,6 +585,7 @@ function parameters(format) {
|
|
|
444
585
|
items: {
|
|
445
586
|
type: 'object',
|
|
446
587
|
properties: { op: { type: 'string', enum: Object.keys(format.ops) } },
|
|
588
|
+
additionalProperties: true,
|
|
447
589
|
required: ['op']
|
|
448
590
|
}
|
|
449
591
|
},
|
|
@@ -455,10 +597,11 @@ function parameters(format) {
|
|
|
455
597
|
};
|
|
456
598
|
}
|
|
457
599
|
async function execute(format, args, ctx) {
|
|
458
|
-
const
|
|
459
|
-
if (typeof
|
|
460
|
-
return { error:
|
|
600
|
+
const parsed = parseRequest(format, args);
|
|
601
|
+
if (typeof parsed === 'string') {
|
|
602
|
+
return { error: parsed };
|
|
461
603
|
}
|
|
604
|
+
const request = await withoutMissingUploads(parsed, ctx);
|
|
462
605
|
if (request.attachmentId !== undefined && !ctx.fetchAttachment) {
|
|
463
606
|
return { error: 'this device cannot read chat attachments' };
|
|
464
607
|
}
|
|
@@ -477,13 +620,19 @@ async function execute(format, args, ctx) {
|
|
|
477
620
|
return source;
|
|
478
621
|
}
|
|
479
622
|
const { document, fileName } = source;
|
|
623
|
+
if (!request.ops.length && request.attachmentId === undefined) {
|
|
624
|
+
return {
|
|
625
|
+
next: `No ${format.noun} exists yet, so there is nothing to open: make it in one call with create, ops and output.`
|
|
626
|
+
};
|
|
627
|
+
}
|
|
480
628
|
if (!request.ops.length) {
|
|
481
629
|
return { document: format.read(document) };
|
|
482
630
|
}
|
|
483
|
-
const
|
|
484
|
-
if ('error' in
|
|
485
|
-
return
|
|
631
|
+
const ran = runOps({ format, document, request, images });
|
|
632
|
+
if ('error' in ran) {
|
|
633
|
+
return ran;
|
|
486
634
|
}
|
|
635
|
+
const { results } = ran;
|
|
487
636
|
const onlyQueries = request.ops.every(({ spec }) => spec.query);
|
|
488
637
|
if (onlyQueries || (!document.changed && request.attachmentId !== undefined)) {
|
|
489
638
|
return { results };
|
|
@@ -494,27 +643,39 @@ async function execute(format, args, ctx) {
|
|
|
494
643
|
return saved;
|
|
495
644
|
}
|
|
496
645
|
const { attachment, repeated } = saved;
|
|
646
|
+
const skipped = [...source.skipped, ...request.skipped, ...ran.skipped];
|
|
497
647
|
const counts = format.count(document);
|
|
498
648
|
const renamed = fileName !== null && output !== request.output
|
|
499
649
|
? `Saved as ${output}, so the attached ${fileName} keeps its own name. `
|
|
500
650
|
: '';
|
|
501
|
-
const unplaced =
|
|
651
|
+
const unplaced = images.size ? null : await leftOutImage(request, ctx);
|
|
502
652
|
return {
|
|
503
653
|
results,
|
|
504
654
|
attachments: [attachment],
|
|
505
655
|
...counts,
|
|
656
|
+
skipped: skipped.length ? skipped : undefined,
|
|
506
657
|
reply: `${attachment.fileName} — ${countLine(counts)}`,
|
|
507
658
|
next: renamed +
|
|
508
659
|
`Done: ${attachment.fileName} ${repeated ? 'was already' : 'is'} attached to the chat and shown to the user. ` +
|
|
509
660
|
afterSave(format, attachment.attachmentId, unplaced)
|
|
510
661
|
};
|
|
511
662
|
}
|
|
663
|
+
async function leftOutImage(request, ctx) {
|
|
664
|
+
if (ctx.turnImages?.length) {
|
|
665
|
+
return 'The image the user attached to their message';
|
|
666
|
+
}
|
|
667
|
+
if (request.attachmentId !== undefined || !ctx.fetchAttachment) {
|
|
668
|
+
return null;
|
|
669
|
+
}
|
|
670
|
+
const available = await uploadsAvailable(ctx.fetchAttachment, { signal: ctx.signal });
|
|
671
|
+
return available ? 'An image in this chat' : null;
|
|
672
|
+
}
|
|
512
673
|
function afterSave(format, attachmentId, unplaced) {
|
|
513
674
|
const reply = 'Your answer is the reply value alone, word for word.';
|
|
514
675
|
if (!unplaced) {
|
|
515
676
|
return `Do not call ${format.name} again for it. ${reply}`;
|
|
516
677
|
}
|
|
517
|
-
return (
|
|
678
|
+
return (`${unplaced} is not in it. If they asked for that image in the ${format.noun}, ` +
|
|
518
679
|
`call ${format.name} once more with attachmentId "${attachmentId}" and one op that adds it with "image": {}. ` +
|
|
519
680
|
`Otherwise: ${reply}`);
|
|
520
681
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ToolExecuteContext } from '../../contract/index.ts';
|
|
1
2
|
export interface OperationRequest {
|
|
2
3
|
body?: Record<string, unknown>;
|
|
3
4
|
params?: Record<string, unknown>;
|
|
@@ -10,9 +11,9 @@ export type BuilderOutcome = {
|
|
|
10
11
|
error: string;
|
|
11
12
|
};
|
|
12
13
|
export interface OperationBuilder {
|
|
13
|
-
build: (args: Record<string, unknown
|
|
14
|
+
build: (args: Record<string, unknown>, context?: ToolExecuteContext) => BuilderOutcome;
|
|
14
15
|
}
|
|
15
|
-
export declare const BUILDER_POLICY_VERSION =
|
|
16
|
-
export declare const BUILDER_NAMES: readonly ['gmail-send', 'gmail-draft', 'gmail-get', 'calendar-meet-event', 'calendar-add-meet', 'docs-create', 'docs-append-text', 'sheets-create', 'sheets-write-values', 'sheets-append-values', 'drive-create-folder', 'drive-trash', 'notion-create-page', 'notion-insert-content'];
|
|
16
|
+
export declare const BUILDER_POLICY_VERSION = 3;
|
|
17
|
+
export declare const BUILDER_NAMES: readonly ['gmail-send', 'gmail-draft', 'gmail-get', 'calendar-list-events', 'calendar-list-calendars', 'calendar-meet-event', 'calendar-add-meet', 'docs-create', 'docs-append-text', 'sheets-create', 'sheets-write-values', 'sheets-append-values', 'drive-create-folder', 'drive-trash', 'notion-create-page', 'notion-insert-content'];
|
|
17
18
|
export type BuilderName = (typeof BUILDER_NAMES)[number];
|
|
18
19
|
export declare const BUILDERS: Record<BuilderName, OperationBuilder>;
|
|
@@ -2,11 +2,14 @@ import { randomBytes } from 'crypto';
|
|
|
2
2
|
import b4a from 'b4a';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { buildGmailMessage, GmailEnvelopeSchema } from './gmail-message.js';
|
|
5
|
-
|
|
5
|
+
import { calendarBounds, CalendarRangeSchema } from './calendar-range.js';
|
|
6
|
+
export const BUILDER_POLICY_VERSION = 3;
|
|
6
7
|
export const BUILDER_NAMES = [
|
|
7
8
|
'gmail-send',
|
|
8
9
|
'gmail-draft',
|
|
9
10
|
'gmail-get',
|
|
11
|
+
'calendar-list-events',
|
|
12
|
+
'calendar-list-calendars',
|
|
10
13
|
'calendar-meet-event',
|
|
11
14
|
'calendar-add-meet',
|
|
12
15
|
'docs-create',
|
|
@@ -21,12 +24,12 @@ export const BUILDER_NAMES = [
|
|
|
21
24
|
];
|
|
22
25
|
function builder(schema, build) {
|
|
23
26
|
return {
|
|
24
|
-
build(args) {
|
|
27
|
+
build(args, context) {
|
|
25
28
|
const parsed = schema.safeParse(args);
|
|
26
29
|
if (!parsed.success) {
|
|
27
30
|
return { error: parsed.error.issues[0]?.message ?? 'invalid arguments' };
|
|
28
31
|
}
|
|
29
|
-
return { request: build(parsed.data) };
|
|
32
|
+
return { request: build(parsed.data, context) };
|
|
30
33
|
}
|
|
31
34
|
};
|
|
32
35
|
}
|
|
@@ -58,6 +61,39 @@ function createRequest() {
|
|
|
58
61
|
}
|
|
59
62
|
};
|
|
60
63
|
}
|
|
64
|
+
const CalendarListEventsSchema = z
|
|
65
|
+
.object({
|
|
66
|
+
...CalendarRangeSchema.shape,
|
|
67
|
+
calendarId: z.string().optional(),
|
|
68
|
+
q: z.string().optional(),
|
|
69
|
+
maxResults: z.number().int().min(1).max(2500).optional(),
|
|
70
|
+
pageToken: z.string().optional()
|
|
71
|
+
})
|
|
72
|
+
.refine((args) => !(args.range && args.date), {
|
|
73
|
+
message: 'Choose range or date, not both'
|
|
74
|
+
})
|
|
75
|
+
.refine((args) => !((args.range || args.date) && (args.timeMin || args.timeMax)), {
|
|
76
|
+
message: 'Use range or date for local dates; use timeMin/timeMax for explicit bounds'
|
|
77
|
+
})
|
|
78
|
+
.refine((args) => !args.timeMin || !args.timeMax || Date.parse(args.timeMax) > Date.parse(args.timeMin), {
|
|
79
|
+
message: 'timeMax must be later than timeMin'
|
|
80
|
+
});
|
|
81
|
+
const calendarListEvents = builder(CalendarListEventsSchema, (args, context) => ({
|
|
82
|
+
query: {
|
|
83
|
+
...calendarBounds(args, context?.currentTime),
|
|
84
|
+
q: args.q,
|
|
85
|
+
maxResults: args.maxResults ?? 10,
|
|
86
|
+
pageToken: args.pageToken || undefined,
|
|
87
|
+
singleEvents: true,
|
|
88
|
+
orderBy: 'startTime'
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
const calendarListCalendars = builder(z.object({
|
|
92
|
+
maxResults: z.number().int().min(1).max(250).optional(),
|
|
93
|
+
pageToken: z.string().optional()
|
|
94
|
+
}), (args) => ({
|
|
95
|
+
query: { maxResults: args.maxResults ?? 100, pageToken: args.pageToken || undefined }
|
|
96
|
+
}));
|
|
61
97
|
const MeetEventSchema = z.object({
|
|
62
98
|
summary: z.string(),
|
|
63
99
|
start: z.iso.datetime({ offset: true }),
|
|
@@ -179,6 +215,8 @@ export const BUILDERS = {
|
|
|
179
215
|
'gmail-send': gmailSend,
|
|
180
216
|
'gmail-draft': gmailDraft,
|
|
181
217
|
'gmail-get': gmailGet,
|
|
218
|
+
'calendar-list-events': calendarListEvents,
|
|
219
|
+
'calendar-list-calendars': calendarListCalendars,
|
|
182
220
|
'calendar-meet-event': calendarMeetEvent,
|
|
183
221
|
'calendar-add-meet': calendarAddMeet,
|
|
184
222
|
'docs-create': docsCreate,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CalendarRangeSchema: z.ZodObject<{
|
|
3
|
+
range: z.ZodPreprocess<z.ZodOptional<z.ZodEnum<{
|
|
4
|
+
all: "all";
|
|
5
|
+
today: "today";
|
|
6
|
+
tomorrow: "tomorrow";
|
|
7
|
+
upcoming: "upcoming";
|
|
8
|
+
}>>, unknown>;
|
|
9
|
+
date: z.ZodPreprocess<z.ZodOptional<z.ZodISODate>, unknown>;
|
|
10
|
+
timeMin: z.ZodPreprocess<z.ZodOptional<z.ZodISODateTime>, unknown>;
|
|
11
|
+
timeMax: z.ZodPreprocess<z.ZodOptional<z.ZodISODateTime>, unknown>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
type CalendarRange = z.infer<typeof CalendarRangeSchema>;
|
|
14
|
+
type CalendarBounds = Pick<CalendarRange, 'timeMin' | 'timeMax'>;
|
|
15
|
+
export declare function calendarBounds(args: CalendarRange, currentTime?: number): CalendarBounds;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const emptyToAbsent = (value) => (value === '' ? undefined : value);
|
|
3
|
+
export const CalendarRangeSchema = z.object({
|
|
4
|
+
range: z.preprocess(emptyToAbsent, z
|
|
5
|
+
.enum(['upcoming', 'today', 'tomorrow', 'all'], {
|
|
6
|
+
error: 'range must be upcoming, today, tomorrow or all'
|
|
7
|
+
})
|
|
8
|
+
.optional()),
|
|
9
|
+
date: z.preprocess(emptyToAbsent, z.iso.date({ error: 'date must be YYYY-MM-DD' }).optional()),
|
|
10
|
+
timeMin: z.preprocess(emptyToAbsent, z.iso
|
|
11
|
+
.datetime({ offset: true, error: 'timeMin must be an RFC 3339 datetime with an offset' })
|
|
12
|
+
.optional()),
|
|
13
|
+
timeMax: z.preprocess(emptyToAbsent, z.iso
|
|
14
|
+
.datetime({ offset: true, error: 'timeMax must be an RFC 3339 datetime with an offset' })
|
|
15
|
+
.optional())
|
|
16
|
+
});
|
|
17
|
+
export function calendarBounds(args, currentTime = Date.now()) {
|
|
18
|
+
if (args.timeMin || args.timeMax) {
|
|
19
|
+
return { timeMin: args.timeMin ?? new Date(currentTime).toISOString(), timeMax: args.timeMax };
|
|
20
|
+
}
|
|
21
|
+
if (args.range === 'all')
|
|
22
|
+
return {};
|
|
23
|
+
const now = new Date(currentTime);
|
|
24
|
+
if (!args.date && (!args.range || args.range === 'upcoming')) {
|
|
25
|
+
return { timeMin: now.toISOString() };
|
|
26
|
+
}
|
|
27
|
+
const start = new Date(now);
|
|
28
|
+
if (args.date) {
|
|
29
|
+
const [year, month, day] = args.date.split('-').map(Number);
|
|
30
|
+
start.setFullYear(year, month - 1, day);
|
|
31
|
+
}
|
|
32
|
+
else if (args.range === 'tomorrow') {
|
|
33
|
+
start.setDate(start.getDate() + 1);
|
|
34
|
+
}
|
|
35
|
+
start.setHours(0, 0, 0, 0);
|
|
36
|
+
const end = new Date(start);
|
|
37
|
+
end.setDate(end.getDate() + 1);
|
|
38
|
+
end.setHours(0, 0, 0, 0);
|
|
39
|
+
return { timeMin: start.toISOString(), timeMax: end.toISOString() };
|
|
40
|
+
}
|
|
@@ -3,7 +3,7 @@ import { BUILDERS, BUILDER_POLICY_VERSION } from './builders.js';
|
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
import { stableStringify } from '../../helpers/stable-stringify.js';
|
|
5
5
|
import { READ_METHODS } from '../http-methods.js';
|
|
6
|
-
import {
|
|
6
|
+
import { capResponseBody } from '../http-request/truncate-response.js';
|
|
7
7
|
import { DECODERS } from './decoders.js';
|
|
8
8
|
export function compileOperationTools(catalog, { httpRequestTool, mcpCallTool }) {
|
|
9
9
|
return catalog.flatMap((entry) => (entry.operations ?? []).flatMap((operation) => {
|
|
@@ -42,7 +42,7 @@ function operationTool(owningSkill, operation, transportTool) {
|
|
|
42
42
|
},
|
|
43
43
|
async execute(args, ctx) {
|
|
44
44
|
const skillContext = { ...ctx, skills: [owningSkill] };
|
|
45
|
-
const built = builder.build(args);
|
|
45
|
+
const built = builder.build(args, ctx);
|
|
46
46
|
if ('error' in built) {
|
|
47
47
|
return { error: `${operation.tool}: ${built.error}` };
|
|
48
48
|
}
|
|
@@ -65,17 +65,17 @@ function operationTool(owningSkill, operation, transportTool) {
|
|
|
65
65
|
body: built.request.body,
|
|
66
66
|
encode: built.request.encode
|
|
67
67
|
}, response ? { ...skillContext, uncappedResponse: true } : skillContext);
|
|
68
|
-
return response ? capBody(shapeResponse(result, response)) : result;
|
|
68
|
+
return response ? capBody(shapeResponse(result, response), ctx) : result;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
const JsonResult = z.looseObject({ status: z.number().optional(), body: z.string() });
|
|
73
|
-
function capBody(result) {
|
|
73
|
+
function capBody(result, ctx) {
|
|
74
74
|
const parsed = JsonResult.safeParse(result);
|
|
75
75
|
if (!parsed.success) {
|
|
76
76
|
return result;
|
|
77
77
|
}
|
|
78
|
-
return { ...parsed.data,
|
|
78
|
+
return { ...parsed.data, ...capResponseBody(parsed.data.body, ctx) };
|
|
79
79
|
}
|
|
80
80
|
function shapeResponse(result, response) {
|
|
81
81
|
const parsed = JsonResult.safeParse(result);
|
|
@@ -115,7 +115,9 @@ const PLACEHOLDER = /\{(\w+)\}/g;
|
|
|
115
115
|
function fillTemplate(template, args, defaults) {
|
|
116
116
|
const missing = [];
|
|
117
117
|
const value = template.replace(PLACEHOLDER, (_match, name) => {
|
|
118
|
-
const filled = args[name]
|
|
118
|
+
const filled = args[name] === '' && defaults?.[name] !== undefined
|
|
119
|
+
? defaults[name]
|
|
120
|
+
: (args[name] ?? defaults?.[name]);
|
|
119
121
|
if (filled === undefined) {
|
|
120
122
|
missing.push(name);
|
|
121
123
|
}
|