@elie-laloum/outpost 4.2.0 → 6.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 +56 -0
- package/README.md +13 -11
- package/SECURITY.md +2 -0
- package/dist/adapters/agents/antigravity-adapter.d.ts +3 -0
- package/dist/adapters/agents/antigravity-adapter.js +39 -0
- package/dist/adapters/agents/antigravity-adapter.js.map +1 -0
- package/dist/adapters/agents/antigravity-authentication.d.ts +2 -0
- package/dist/adapters/agents/antigravity-authentication.js +27 -0
- package/dist/adapters/agents/antigravity-authentication.js.map +1 -0
- package/dist/adapters/agents/antigravity-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/antigravity-diagnostics.js +6 -0
- package/dist/adapters/agents/antigravity-diagnostics.js.map +1 -0
- package/dist/adapters/agents/antigravity-events.d.ts +2 -0
- package/dist/adapters/agents/antigravity-events.js +66 -0
- package/dist/adapters/agents/antigravity-events.js.map +1 -0
- package/dist/adapters/agents/antigravity-request.d.ts +5 -0
- package/dist/adapters/agents/antigravity-request.js +29 -0
- package/dist/adapters/agents/antigravity-request.js.map +1 -0
- package/dist/adapters/agents/antigravity.types.d.ts +7 -0
- package/dist/adapters/agents/antigravity.types.js +2 -0
- package/dist/adapters/agents/antigravity.types.js.map +1 -0
- package/dist/adapters/agents/authentication.constants.d.ts +23 -0
- package/dist/adapters/agents/authentication.constants.js +13 -0
- package/dist/adapters/agents/authentication.constants.js.map +1 -0
- package/dist/adapters/agents/authentication.d.ts +11 -0
- package/dist/adapters/agents/authentication.js +75 -0
- package/dist/adapters/agents/authentication.js.map +1 -0
- package/dist/adapters/agents/authentication.types.d.ts +20 -0
- package/dist/adapters/agents/authentication.types.js +2 -0
- package/dist/adapters/agents/authentication.types.js.map +1 -0
- package/dist/adapters/agents/claude-adapter.d.ts +2 -2
- package/dist/adapters/agents/claude-adapter.js +32 -2
- package/dist/adapters/agents/claude-adapter.js.map +1 -1
- package/dist/adapters/agents/claude-authentication.d.ts +2 -0
- package/dist/adapters/agents/claude-authentication.js +34 -0
- package/dist/adapters/agents/claude-authentication.js.map +1 -0
- package/dist/adapters/agents/claude-request.d.ts +2 -2
- package/dist/adapters/agents/claude-request.js +3 -3
- package/dist/adapters/agents/claude-request.js.map +1 -1
- package/dist/adapters/agents/cli-diagnostics.constants.d.ts +6 -6
- package/dist/adapters/agents/cli-diagnostics.constants.js +6 -6
- package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -1
- package/dist/adapters/agents/cli-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/cli-diagnostics.js +11 -0
- package/dist/adapters/agents/cli-diagnostics.js.map +1 -1
- package/dist/adapters/agents/codex-adapter.d.ts +2 -2
- package/dist/adapters/agents/codex-adapter.js +19 -1
- package/dist/adapters/agents/codex-adapter.js.map +1 -1
- package/dist/adapters/agents/codex-authentication.d.ts +3 -0
- package/dist/adapters/agents/codex-authentication.js +47 -0
- package/dist/adapters/agents/codex-authentication.js.map +1 -0
- package/dist/adapters/agents/codex-provider.d.ts +2 -2
- package/dist/adapters/agents/codex-provider.js +1 -1
- package/dist/adapters/agents/codex-provider.js.map +1 -1
- package/dist/adapters/agents/codex-request.d.ts +2 -2
- package/dist/adapters/agents/codex-request.js +3 -3
- package/dist/adapters/agents/codex-request.js.map +1 -1
- package/dist/adapters/agents/copilot-adapter.d.ts +3 -0
- package/dist/adapters/agents/copilot-adapter.js +39 -0
- package/dist/adapters/agents/copilot-adapter.js.map +1 -0
- package/dist/adapters/agents/copilot-authentication.d.ts +2 -0
- package/dist/adapters/agents/copilot-authentication.js +45 -0
- package/dist/adapters/agents/copilot-authentication.js.map +1 -0
- package/dist/adapters/agents/copilot-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/copilot-diagnostics.js +6 -0
- package/dist/adapters/agents/copilot-diagnostics.js.map +1 -0
- package/dist/adapters/agents/copilot-events.d.ts +2 -0
- package/dist/adapters/agents/copilot-events.js +50 -0
- package/dist/adapters/agents/copilot-events.js.map +1 -0
- package/dist/adapters/agents/copilot-request.d.ts +5 -0
- package/dist/adapters/agents/copilot-request.js +19 -0
- package/dist/adapters/agents/copilot-request.js.map +1 -0
- package/dist/adapters/agents/copilot.types.d.ts +6 -0
- package/dist/adapters/agents/copilot.types.js +2 -0
- package/dist/adapters/agents/copilot.types.js.map +1 -0
- package/dist/adapters/agents/event-decoder.d.ts +2 -2
- package/dist/adapters/agents/event-decoder.js +6 -5
- package/dist/adapters/agents/event-decoder.js.map +1 -1
- package/dist/adapters/agents/kimi-adapter.d.ts +3 -0
- package/dist/adapters/agents/kimi-adapter.js +35 -0
- package/dist/adapters/agents/kimi-adapter.js.map +1 -0
- package/dist/adapters/agents/kimi-authentication.d.ts +2 -0
- package/dist/adapters/agents/kimi-authentication.js +48 -0
- package/dist/adapters/agents/kimi-authentication.js.map +1 -0
- package/dist/adapters/agents/kimi-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/kimi-diagnostics.js +6 -0
- package/dist/adapters/agents/kimi-diagnostics.js.map +1 -0
- package/dist/adapters/agents/kimi-events.d.ts +2 -0
- package/dist/adapters/agents/kimi-events.js +51 -0
- package/dist/adapters/agents/kimi-events.js.map +1 -0
- package/dist/adapters/agents/kimi-request.d.ts +5 -0
- package/dist/adapters/agents/kimi-request.js +28 -0
- package/dist/adapters/agents/kimi-request.js.map +1 -0
- package/dist/adapters/agents/kimi.types.d.ts +6 -0
- package/dist/adapters/agents/kimi.types.js +2 -0
- package/dist/adapters/agents/kimi.types.js.map +1 -0
- package/dist/adapters/agents/model-support.constants.d.ts +8 -0
- package/dist/adapters/agents/model-support.constants.js +28 -0
- package/dist/adapters/agents/model-support.constants.js.map +1 -0
- package/dist/adapters/agents/model-support.d.ts +4 -0
- package/dist/adapters/agents/model-support.js +11 -0
- package/dist/adapters/agents/model-support.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -2
- package/dist/adapters/agents/protocol-fixtures.constants.js +135 -9
- package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
- package/dist/adapters/agents/protocol-fixtures.types.d.ts +1 -0
- package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -1
- package/dist/adapters/agents/protocol.d.ts +1 -0
- package/dist/adapters/agents/protocol.js +9 -0
- package/dist/adapters/agents/protocol.js.map +1 -1
- package/dist/adapters/agents/settings.types.d.ts +11 -3
- package/dist/adapters/agents/settings.types.js.map +1 -1
- package/dist/adapters/models/anthropic-model-provider.constants.d.ts +3 -0
- package/dist/adapters/models/anthropic-model-provider.constants.js +17 -0
- package/dist/adapters/models/anthropic-model-provider.constants.js.map +1 -0
- package/dist/adapters/models/anthropic-model-provider.d.ts +3 -0
- package/dist/adapters/models/anthropic-model-provider.js +31 -0
- package/dist/adapters/models/anthropic-model-provider.js.map +1 -0
- package/dist/adapters/models/anthropic-model-provider.types.d.ts +7 -0
- package/dist/adapters/models/anthropic-model-provider.types.js +2 -0
- package/dist/adapters/models/anthropic-model-provider.types.js.map +1 -0
- package/dist/adapters/models/anthropic-request.d.ts +4 -0
- package/dist/adapters/models/anthropic-request.js +81 -0
- package/dist/adapters/models/anthropic-request.js.map +1 -0
- package/dist/adapters/models/anthropic-response.d.ts +3 -0
- package/dist/adapters/models/anthropic-response.js +55 -0
- package/dist/adapters/models/anthropic-response.js.map +1 -0
- package/dist/adapters/models/anthropic-stream.d.ts +2 -0
- package/dist/adapters/models/anthropic-stream.js +96 -0
- package/dist/adapters/models/anthropic-stream.js.map +1 -0
- package/dist/adapters/models/http-provider.d.ts +3 -0
- package/dist/adapters/models/http-provider.js +113 -0
- package/dist/adapters/models/http-provider.js.map +1 -0
- package/dist/adapters/models/{openai-http.js → model-http.js} +1 -1
- package/dist/adapters/models/model-http.js.map +1 -0
- package/dist/adapters/models/model-protocol.types.d.ts +41 -0
- package/dist/adapters/models/model-protocol.types.js +2 -0
- package/dist/adapters/models/model-protocol.types.js.map +1 -0
- package/dist/adapters/models/model-request.d.ts +2 -0
- package/dist/adapters/models/model-request.js +18 -0
- package/dist/adapters/models/model-request.js.map +1 -0
- package/dist/adapters/models/model-response.d.ts +7 -0
- package/dist/adapters/models/model-response.js +41 -0
- package/dist/adapters/models/model-response.js.map +1 -0
- package/dist/adapters/models/{openai-compatible.constants.js → model.constants.js} +6 -1
- package/dist/adapters/models/model.constants.js.map +1 -0
- package/dist/adapters/models/openai-chat-stream.d.ts +2 -0
- package/dist/adapters/models/openai-chat-stream.js +66 -0
- package/dist/adapters/models/openai-chat-stream.js.map +1 -0
- package/dist/adapters/models/openai-chat.d.ts +4 -0
- package/dist/adapters/models/openai-chat.js +108 -0
- package/dist/adapters/models/openai-chat.js.map +1 -0
- package/dist/adapters/models/openai-model-provider.d.ts +3 -0
- package/dist/adapters/models/openai-model-provider.js +13 -0
- package/dist/adapters/models/openai-model-provider.js.map +1 -0
- package/dist/adapters/models/openai-model-provider.types.d.ts +4 -0
- package/dist/adapters/models/openai-model-provider.types.js +2 -0
- package/dist/adapters/models/openai-model-provider.types.js.map +1 -0
- package/dist/adapters/models/openai-protocols.d.ts +2 -0
- package/dist/adapters/models/openai-protocols.js +22 -0
- package/dist/adapters/models/openai-protocols.js.map +1 -0
- package/dist/adapters/models/openai-responses-stream.d.ts +2 -0
- package/dist/adapters/models/openai-responses-stream.js +35 -0
- package/dist/adapters/models/openai-responses-stream.js.map +1 -0
- package/dist/adapters/models/openai-responses.d.ts +4 -0
- package/dist/adapters/models/openai-responses.js +107 -0
- package/dist/adapters/models/openai-responses.js.map +1 -0
- package/dist/adapters/models/openai-usage.d.ts +3 -0
- package/dist/adapters/models/openai-usage.js +20 -0
- package/dist/adapters/models/openai-usage.js.map +1 -0
- package/dist/adapters/models/stop-reasons.constants.d.ts +4 -0
- package/dist/adapters/models/stop-reasons.constants.js +19 -0
- package/dist/adapters/models/stop-reasons.constants.js.map +1 -0
- package/dist/adapters/models/stream-events.d.ts +3 -0
- package/dist/adapters/models/stream-events.js +22 -0
- package/dist/adapters/models/stream-events.js.map +1 -0
- package/dist/adapters/tools/edit-tools.d.ts +2 -0
- package/dist/adapters/tools/edit-tools.js +84 -0
- package/dist/adapters/tools/edit-tools.js.map +1 -0
- package/dist/adapters/tools/file-tools.d.ts +2 -0
- package/dist/adapters/tools/file-tools.js +97 -0
- package/dist/adapters/tools/file-tools.js.map +1 -0
- package/dist/adapters/tools/git-tools.d.ts +2 -0
- package/dist/adapters/tools/git-tools.js +54 -0
- package/dist/adapters/tools/git-tools.js.map +1 -0
- package/dist/adapters/tools/sandbox-files.d.ts +10 -0
- package/dist/adapters/tools/sandbox-files.js +60 -0
- package/dist/adapters/tools/sandbox-files.js.map +1 -0
- package/dist/adapters/tools/search-tools.d.ts +2 -0
- package/dist/adapters/tools/search-tools.js +65 -0
- package/dist/adapters/tools/search-tools.js.map +1 -0
- package/dist/adapters/tools/shell-tools.d.ts +3 -0
- package/dist/adapters/tools/shell-tools.js +38 -0
- package/dist/adapters/tools/shell-tools.js.map +1 -0
- package/dist/adapters/tools/tools.constants.d.ts +11 -0
- package/dist/adapters/tools/tools.constants.js +17 -0
- package/dist/adapters/tools/tools.constants.js.map +1 -0
- package/dist/adapters/tools/tools.types.d.ts +41 -0
- package/dist/adapters/tools/tools.types.js +2 -0
- package/dist/adapters/tools/tools.types.js.map +1 -0
- package/dist/application/activity-watchdog.js +15 -2
- package/dist/application/activity-watchdog.js.map +1 -1
- package/dist/application/agent-authentication.d.ts +4 -0
- package/dist/application/agent-authentication.js +32 -0
- package/dist/application/agent-authentication.js.map +1 -0
- package/dist/application/agent-bootstrap.constants.d.ts +2 -5
- package/dist/application/agent-bootstrap.constants.js +29 -4
- package/dist/application/agent-bootstrap.constants.js.map +1 -1
- package/dist/application/agent-bootstrap.d.ts +2 -2
- package/dist/application/agent-bootstrap.js +35 -12
- package/dist/application/agent-bootstrap.js.map +1 -1
- package/dist/application/agent-bootstrap.types.d.ts +20 -0
- package/dist/application/agent-bootstrap.types.js +2 -0
- package/dist/application/agent-bootstrap.types.js.map +1 -0
- package/dist/application/agent-storage.d.ts +3 -2
- package/dist/application/agent-storage.js +9 -2
- package/dist/application/agent-storage.js.map +1 -1
- package/dist/application/agent-turn.d.ts +3 -3
- package/dist/application/agent-turn.js +7 -1
- package/dist/application/agent-turn.js.map +1 -1
- package/dist/application/attach.js +1 -0
- package/dist/application/attach.js.map +1 -1
- package/dist/application/credential-installer.constants.d.ts +1 -0
- package/dist/application/credential-installer.constants.js +22 -0
- package/dist/application/credential-installer.constants.js.map +1 -0
- package/dist/application/custom-turn.d.ts +5 -0
- package/dist/application/custom-turn.js +190 -0
- package/dist/application/custom-turn.js.map +1 -0
- package/dist/application/dispatch-observation.d.ts +3 -0
- package/dist/application/dispatch-observation.js +51 -0
- package/dist/application/dispatch-observation.js.map +1 -0
- package/dist/application/dispatch-observation.types.d.ts +5 -0
- package/dist/application/dispatch-observation.types.js +2 -0
- package/dist/application/dispatch-observation.types.js.map +1 -0
- package/dist/application/dispatch-validation.d.ts +2 -2
- package/dist/application/dispatch-validation.js.map +1 -1
- package/dist/application/dispatch.js +8 -3
- package/dist/application/dispatch.js.map +1 -1
- package/dist/application/doctor-agent.constants.d.ts +2 -8
- package/dist/application/doctor-agent.constants.js +40 -6
- package/dist/application/doctor-agent.constants.js.map +1 -1
- package/dist/application/doctor-agent.d.ts +2 -1
- package/dist/application/doctor-agent.js +11 -3
- package/dist/application/doctor-agent.js.map +1 -1
- package/dist/application/doctor-image.js +7 -9
- package/dist/application/doctor-image.js.map +1 -1
- package/dist/application/doctor-protocol.js +6 -6
- package/dist/application/doctor-protocol.js.map +1 -1
- package/dist/application/doctor-protocol.types.d.ts +1 -1
- package/dist/application/doctor-protocol.types.js.map +1 -1
- package/dist/application/doctor-sandbox.js +6 -9
- package/dist/application/doctor-sandbox.js.map +1 -1
- package/dist/application/doctor-sandbox.types.d.ts +2 -2
- package/dist/application/doctor-sandbox.types.js.map +1 -1
- package/dist/application/doctor.constants.d.ts +1 -1
- package/dist/application/doctor.constants.js +1 -1
- package/dist/application/doctor.constants.js.map +1 -1
- package/dist/application/doctor.js +12 -13
- package/dist/application/doctor.js.map +1 -1
- package/dist/application/doctor.types.d.ts +12 -4
- package/dist/application/doctor.types.js.map +1 -1
- package/dist/application/execution.d.ts +2 -2
- package/dist/application/execution.js +1 -1
- package/dist/application/execution.js.map +1 -1
- package/dist/application/execution.types.d.ts +9 -2
- package/dist/application/execution.types.js.map +1 -1
- package/dist/application/harness-context.d.ts +2 -0
- package/dist/application/harness-context.js +54 -0
- package/dist/application/harness-context.js.map +1 -0
- package/dist/application/harness-history.d.ts +3 -0
- package/dist/application/harness-history.js +17 -0
- package/dist/application/harness-history.js.map +1 -0
- package/dist/application/harness-hooks.d.ts +9 -0
- package/dist/application/harness-hooks.js +90 -0
- package/dist/application/harness-hooks.js.map +1 -0
- package/dist/application/harness-loop.d.ts +2 -0
- package/dist/application/harness-loop.js +132 -0
- package/dist/application/harness-loop.js.map +1 -0
- package/dist/application/harness.types.d.ts +55 -0
- package/dist/application/harness.types.js +2 -0
- package/dist/application/harness.types.js.map +1 -0
- package/dist/application/lifecycle.constants.d.ts +1 -1
- package/dist/application/lifecycle.constants.js +1 -1
- package/dist/application/lifecycle.constants.js.map +1 -1
- package/dist/application/outpost.types.d.ts +6 -7
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/recovery-retention.js +65 -24
- package/dist/application/recovery-retention.js.map +1 -1
- package/dist/application/remote-download.js +1 -1
- package/dist/application/remote-download.js.map +1 -1
- package/dist/application/sandbox-agents.js +14 -5
- package/dist/application/sandbox-agents.js.map +1 -1
- package/dist/application/sandbox-attach.js +5 -2
- package/dist/application/sandbox-attach.js.map +1 -1
- package/dist/application/sandbox-dispatch.js +3 -5
- package/dist/application/sandbox-dispatch.js.map +1 -1
- package/dist/application/sandbox-provision.js +13 -10
- package/dist/application/sandbox-provision.js.map +1 -1
- package/dist/application/sandbox-session.types.d.ts +13 -8
- package/dist/application/sandbox-session.types.js.map +1 -1
- package/dist/application/sandbox.js +6 -3
- package/dist/application/sandbox.js.map +1 -1
- package/dist/application/speculation.js +1 -1
- package/dist/application/speculation.js.map +1 -1
- package/dist/application/speculation.types.d.ts +3 -3
- package/dist/application/speculation.types.js.map +1 -1
- package/dist/application/startup-recovery.js +1 -1
- package/dist/application/startup-recovery.js.map +1 -1
- package/dist/application/storage-reservation.js +9 -2
- package/dist/application/storage-reservation.js.map +1 -1
- package/dist/application/tasks.types.d.ts +2 -2
- package/dist/application/tasks.types.js.map +1 -1
- package/dist/application/tool-execution.d.ts +3 -0
- package/dist/application/tool-execution.js +211 -0
- package/dist/application/tool-execution.js.map +1 -0
- package/dist/cli/commands.js +4 -2
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor-command.js +11 -7
- package/dist/cli/doctor-command.js.map +1 -1
- package/dist/cli/init-authentication.d.ts +4 -1
- package/dist/cli/init-authentication.js +28 -34
- package/dist/cli/init-authentication.js.map +1 -1
- package/dist/cli/init-command.js +6 -6
- package/dist/cli/init-command.js.map +1 -1
- package/dist/cli/main.constants.d.ts +54 -17
- package/dist/cli/main.constants.js +74 -12
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/recovery-command.js +1 -1
- package/dist/cli/recovery-command.js.map +1 -1
- package/dist/cli/scaffold-files.js +6 -5
- package/dist/cli/scaffold-files.js.map +1 -1
- package/dist/cli/scaffold-validation.js +26 -16
- package/dist/cli/scaffold-validation.js.map +1 -1
- package/dist/cli/scaffold.constants.d.ts +0 -1
- package/dist/cli/scaffold.constants.js +5 -2
- package/dist/cli/scaffold.constants.js.map +1 -1
- package/dist/cli/scaffold.js +8 -4
- package/dist/cli/scaffold.js.map +1 -1
- package/dist/cli/scaffold.types.d.ts +9 -3
- package/dist/cli/scaffold.types.js.map +1 -1
- package/dist/cli/starters.js +8 -10
- package/dist/cli/starters.js.map +1 -1
- package/dist/domain/agent-model.d.ts +3 -0
- package/dist/domain/agent-model.js +22 -0
- package/dist/domain/agent-model.js.map +1 -0
- package/dist/domain/agent.d.ts +4 -0
- package/dist/domain/agent.js +32 -0
- package/dist/domain/agent.js.map +1 -0
- package/dist/domain/agent.types.d.ts +105 -2
- package/dist/domain/agent.types.js.map +1 -1
- package/dist/domain/authentication.constants.d.ts +3 -0
- package/dist/domain/authentication.constants.js +11 -0
- package/dist/domain/authentication.constants.js.map +1 -0
- package/dist/domain/authentication.d.ts +3 -0
- package/dist/domain/authentication.js +22 -0
- package/dist/domain/authentication.js.map +1 -0
- package/dist/domain/authentication.types.d.ts +5 -0
- package/dist/domain/authentication.types.js +2 -0
- package/dist/domain/authentication.types.js.map +1 -0
- package/dist/domain/context.constants.d.ts +7 -0
- package/dist/domain/context.constants.js +8 -0
- package/dist/domain/context.constants.js.map +1 -0
- package/dist/domain/context.d.ts +4 -0
- package/dist/domain/context.js +81 -0
- package/dist/domain/context.js.map +1 -0
- package/dist/domain/context.types.d.ts +26 -0
- package/dist/domain/context.types.js +2 -0
- package/dist/domain/context.types.js.map +1 -0
- package/dist/domain/dispatch-telemetry.types.d.ts +12 -0
- package/dist/domain/dispatch-telemetry.types.js +2 -0
- package/dist/domain/dispatch-telemetry.types.js.map +1 -0
- package/dist/domain/errors.types.d.ts +1 -1
- package/dist/domain/errors.types.js.map +1 -1
- package/dist/domain/glob.d.ts +2 -0
- package/dist/domain/glob.js +25 -0
- package/dist/domain/glob.js.map +1 -0
- package/dist/domain/glob.types.d.ts +1 -0
- package/dist/domain/glob.types.js +2 -0
- package/dist/domain/glob.types.js.map +1 -0
- package/dist/domain/harness.constants.d.ts +11 -0
- package/dist/domain/harness.constants.js +24 -0
- package/dist/domain/harness.constants.js.map +1 -0
- package/dist/domain/harness.d.ts +2 -0
- package/dist/domain/harness.js +89 -0
- package/dist/domain/harness.js.map +1 -0
- package/dist/domain/harness.types.d.ts +60 -0
- package/dist/domain/harness.types.js +2 -0
- package/dist/domain/harness.types.js.map +1 -0
- package/dist/domain/hook.constants.d.ts +3 -0
- package/dist/domain/hook.constants.js +10 -0
- package/dist/domain/hook.constants.js.map +1 -0
- package/dist/domain/hook.d.ts +3 -0
- package/dist/domain/hook.js +25 -0
- package/dist/domain/hook.js.map +1 -0
- package/dist/domain/hook.types.d.ts +66 -0
- package/dist/domain/hook.types.js +2 -0
- package/dist/domain/hook.types.js.map +1 -0
- package/dist/domain/instructions.d.ts +3 -0
- package/dist/domain/instructions.js +25 -0
- package/dist/domain/instructions.js.map +1 -0
- package/dist/domain/model-messages.d.ts +5 -0
- package/dist/domain/model-messages.js +81 -0
- package/dist/domain/model-messages.js.map +1 -0
- package/dist/domain/model-messages.types.d.ts +6 -0
- package/dist/domain/model-messages.types.js +2 -0
- package/dist/domain/model-messages.types.js.map +1 -0
- package/dist/domain/model.constants.d.ts +4 -0
- package/dist/domain/model.constants.js +16 -0
- package/dist/domain/model.constants.js.map +1 -0
- package/dist/domain/model.types.d.ts +59 -2
- package/dist/domain/model.types.js.map +1 -1
- package/dist/domain/permissions.d.ts +3 -0
- package/dist/domain/permissions.js +92 -0
- package/dist/domain/permissions.js.map +1 -0
- package/dist/domain/permissions.types.d.ts +34 -0
- package/dist/domain/permissions.types.js +2 -0
- package/dist/domain/permissions.types.js.map +1 -0
- package/dist/domain/response.js +3 -2
- package/dist/domain/response.js.map +1 -1
- package/dist/domain/response.types.d.ts +12 -0
- package/dist/domain/response.types.js.map +1 -1
- package/dist/domain/skill.constants.d.ts +2 -0
- package/dist/domain/skill.constants.js +8 -0
- package/dist/domain/skill.constants.js.map +1 -0
- package/dist/domain/skill.d.ts +8 -0
- package/dist/domain/skill.js +79 -0
- package/dist/domain/skill.js.map +1 -0
- package/dist/domain/skill.types.d.ts +18 -0
- package/dist/domain/skill.types.js +2 -0
- package/dist/domain/skill.types.js.map +1 -0
- package/dist/domain/standard-schema.d.ts +6 -0
- package/dist/domain/standard-schema.js +45 -0
- package/dist/domain/standard-schema.js.map +1 -0
- package/dist/domain/tool-schema.d.ts +3 -0
- package/dist/domain/tool-schema.js +109 -0
- package/dist/domain/tool-schema.js.map +1 -0
- package/dist/domain/tool.constants.d.ts +4 -0
- package/dist/domain/tool.constants.js +36 -0
- package/dist/domain/tool.constants.js.map +1 -0
- package/dist/domain/tool.d.ts +4 -0
- package/dist/domain/tool.js +66 -0
- package/dist/domain/tool.js.map +1 -0
- package/dist/domain/tool.types.d.ts +62 -0
- package/dist/domain/tool.types.js +2 -0
- package/dist/domain/tool.types.js.map +1 -0
- package/dist/domain/transcript.d.ts +4 -0
- package/dist/domain/transcript.js +48 -0
- package/dist/domain/transcript.js.map +1 -0
- package/dist/domain/transcript.types.d.ts +15 -0
- package/dist/domain/transcript.types.js +2 -0
- package/dist/domain/transcript.types.js.map +1 -0
- package/dist/domain/workflow/workflow-state.js +13 -6
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.d.ts +1 -1
- package/dist/domain/workflow.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +4 -0
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +35 -13
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/conversations/harness-store.d.ts +3 -0
- package/dist/infrastructure/conversations/harness-store.js +27 -0
- package/dist/infrastructure/conversations/harness-store.js.map +1 -0
- package/dist/infrastructure/conversations/harness-transcript.d.ts +2 -0
- package/dist/infrastructure/conversations/harness-transcript.js +50 -0
- package/dist/infrastructure/conversations/harness-transcript.js.map +1 -0
- package/dist/infrastructure/conversations/harness-transcript.types.d.ts +18 -0
- package/dist/infrastructure/conversations/harness-transcript.types.js +2 -0
- package/dist/infrastructure/conversations/harness-transcript.types.js.map +1 -0
- package/dist/infrastructure/conversations.d.ts +4 -1
- package/dist/infrastructure/conversations.js +3 -0
- package/dist/infrastructure/conversations.js.map +1 -1
- package/dist/infrastructure/conversations.types.d.ts +1 -0
- package/dist/infrastructure/conversations.types.js.map +1 -1
- package/dist/infrastructure/custom-reporter.d.ts +2 -0
- package/dist/infrastructure/custom-reporter.js +33 -0
- package/dist/infrastructure/custom-reporter.js.map +1 -0
- package/dist/infrastructure/custom-reporter.types.d.ts +13 -0
- package/dist/infrastructure/custom-reporter.types.js +2 -0
- package/dist/infrastructure/custom-reporter.types.js.map +1 -0
- package/dist/infrastructure/git/git.constants.d.ts +1 -1
- package/dist/infrastructure/git/git.constants.js +2 -0
- package/dist/infrastructure/git/git.constants.js.map +1 -1
- package/dist/infrastructure/host-credentials.constants.d.ts +1 -0
- package/dist/infrastructure/host-credentials.constants.js +2 -0
- package/dist/infrastructure/host-credentials.constants.js.map +1 -0
- package/dist/infrastructure/host-credentials.d.ts +4 -0
- package/dist/infrastructure/host-credentials.js +89 -0
- package/dist/infrastructure/host-credentials.js.map +1 -0
- package/dist/infrastructure/inspection-path.js +4 -3
- package/dist/infrastructure/inspection-path.js.map +1 -1
- package/dist/infrastructure/journal.constants.d.ts +1 -0
- package/dist/infrastructure/journal.constants.js +2 -0
- package/dist/infrastructure/journal.constants.js.map +1 -0
- package/dist/infrastructure/journal.js +7 -71
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/journal.types.d.ts +0 -2
- package/dist/infrastructure/journal.types.js.map +1 -1
- package/dist/infrastructure/local-transport.js +9 -4
- package/dist/infrastructure/local-transport.js.map +1 -1
- package/dist/infrastructure/opentelemetry-dispatch.d.ts +6 -0
- package/dist/infrastructure/opentelemetry-dispatch.js +70 -0
- package/dist/infrastructure/opentelemetry-dispatch.js.map +1 -0
- package/dist/infrastructure/opentelemetry.constants.d.ts +3 -0
- package/dist/infrastructure/opentelemetry.constants.js +3 -0
- package/dist/infrastructure/opentelemetry.constants.js.map +1 -1
- package/dist/infrastructure/opentelemetry.js +4 -0
- package/dist/infrastructure/opentelemetry.js.map +1 -1
- package/dist/infrastructure/opentelemetry.types.d.ts +3 -3
- package/dist/infrastructure/opentelemetry.types.js.map +1 -1
- package/dist/infrastructure/reporter.js +27 -2
- package/dist/infrastructure/reporter.js.map +1 -1
- package/dist/infrastructure/repository-transport.constants.d.ts +1 -0
- package/dist/infrastructure/repository-transport.constants.js +2 -0
- package/dist/infrastructure/repository-transport.constants.js.map +1 -0
- package/dist/infrastructure/repository-transport.d.ts +2 -0
- package/dist/infrastructure/repository-transport.js +9 -0
- package/dist/infrastructure/repository-transport.js.map +1 -0
- package/dist/infrastructure/resource-activity-inspection.js +22 -26
- package/dist/infrastructure/resource-activity-inspection.js.map +1 -1
- package/dist/infrastructure/resource-activity.constants.d.ts +0 -1
- package/dist/infrastructure/resource-activity.constants.js +0 -1
- package/dist/infrastructure/resource-activity.constants.js.map +1 -1
- package/dist/infrastructure/resource-activity.js +22 -85
- package/dist/infrastructure/resource-activity.js.map +1 -1
- package/dist/infrastructure/resource-activity.types.d.ts +2 -2
- package/dist/infrastructure/resource-activity.types.js.map +1 -1
- package/dist/infrastructure/settings.d.ts +1 -1
- package/dist/infrastructure/settings.js +3 -3
- package/dist/infrastructure/settings.js.map +1 -1
- package/dist/infrastructure/sse.d.ts +2 -0
- package/dist/infrastructure/sse.js +64 -0
- package/dist/infrastructure/sse.js.map +1 -0
- package/dist/infrastructure/sse.types.d.ts +4 -0
- package/dist/infrastructure/sse.types.js +2 -0
- package/dist/infrastructure/sse.types.js.map +1 -0
- package/dist/infrastructure/storage-inventory.constants.js +1 -0
- package/dist/infrastructure/storage-inventory.constants.js.map +1 -1
- package/dist/infrastructure/storage-inventory.types.d.ts +1 -1
- package/dist/infrastructure/storage-inventory.types.js.map +1 -1
- package/dist/infrastructure/storage-reservations.types.d.ts +0 -8
- package/dist/infrastructure/storage-reservations.types.js.map +1 -1
- package/dist/infrastructure/transport-conversations.d.ts +2 -2
- package/dist/infrastructure/transport-conversations.js +8 -1
- package/dist/infrastructure/transport-conversations.js.map +1 -1
- package/dist/infrastructure/transport-journal.js +2 -1
- package/dist/infrastructure/transport-journal.js.map +1 -1
- package/dist/infrastructure/transport-reservations.d.ts +1 -1
- package/dist/infrastructure/transport-reservations.js +14 -8
- package/dist/infrastructure/transport-reservations.js.map +1 -1
- package/dist/providers/agents.d.ts +9 -4
- package/dist/providers/agents.js +6 -3
- package/dist/providers/agents.js.map +1 -1
- package/dist/providers/daytona.d.ts +1 -1
- package/dist/providers/daytona.js +1 -1
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/docker.d.ts +1 -1
- package/dist/providers/docker.js +1 -1
- package/dist/providers/docker.js.map +1 -1
- package/dist/providers/factories.d.ts +2 -2
- package/dist/providers/factories.js +3 -3
- package/dist/providers/factories.js.map +1 -1
- package/dist/providers/firecracker.d.ts +1 -1
- package/dist/providers/firecracker.js +1 -1
- package/dist/providers/firecracker.js.map +1 -1
- package/dist/providers/local.d.ts +1 -1
- package/dist/providers/local.js +1 -1
- package/dist/providers/local.js.map +1 -1
- package/dist/providers/podman.d.ts +1 -1
- package/dist/providers/podman.js +1 -1
- package/dist/providers/podman.js.map +1 -1
- package/dist/providers/vercel.d.ts +1 -1
- package/dist/providers/vercel.js +1 -1
- package/dist/providers/vercel.js.map +1 -1
- package/dist/providers/versions.constants.d.ts +3 -1
- package/dist/providers/versions.constants.js +3 -1
- package/dist/providers/versions.constants.js.map +1 -1
- package/package.json +3 -3
- package/dist/adapters/agents/gemini-adapter.d.ts +0 -3
- package/dist/adapters/agents/gemini-adapter.js +0 -15
- package/dist/adapters/agents/gemini-adapter.js.map +0 -1
- package/dist/adapters/agents/gemini-diagnostics.d.ts +0 -2
- package/dist/adapters/agents/gemini-diagnostics.js +0 -15
- package/dist/adapters/agents/gemini-diagnostics.js.map +0 -1
- package/dist/adapters/agents/gemini-events.d.ts +0 -2
- package/dist/adapters/agents/gemini-events.js +0 -50
- package/dist/adapters/agents/gemini-events.js.map +0 -1
- package/dist/adapters/agents/gemini-request.d.ts +0 -4
- package/dist/adapters/agents/gemini-request.js +0 -23
- package/dist/adapters/agents/gemini-request.js.map +0 -1
- package/dist/adapters/agents/gemini.types.d.ts +0 -6
- package/dist/adapters/agents/gemini.types.js +0 -2
- package/dist/adapters/agents/gemini.types.js.map +0 -1
- package/dist/adapters/models/openai-compatible.constants.js.map +0 -1
- package/dist/adapters/models/openai-compatible.d.ts +0 -3
- package/dist/adapters/models/openai-compatible.js +0 -78
- package/dist/adapters/models/openai-compatible.js.map +0 -1
- package/dist/adapters/models/openai-compatible.types.d.ts +0 -14
- package/dist/adapters/models/openai-compatible.types.js +0 -2
- package/dist/adapters/models/openai-compatible.types.js.map +0 -1
- package/dist/adapters/models/openai-http.js.map +0 -1
- package/dist/adapters/models/openai-request.d.ts +0 -4
- package/dist/adapters/models/openai-request.js +0 -46
- package/dist/adapters/models/openai-request.js.map +0 -1
- package/dist/adapters/models/openai-response.d.ts +0 -3
- package/dist/adapters/models/openai-response.js +0 -65
- package/dist/adapters/models/openai-response.js.map +0 -1
- package/dist/cli/init-authentication.constants.d.ts +0 -13
- package/dist/cli/init-authentication.constants.js +0 -10
- package/dist/cli/init-authentication.constants.js.map +0 -1
- package/dist/infrastructure/artifact-store.d.ts +0 -3
- package/dist/infrastructure/artifact-store.js +0 -110
- package/dist/infrastructure/artifact-store.js.map +0 -1
- package/dist/infrastructure/artifact-store.types.d.ts +0 -6
- package/dist/infrastructure/artifact-store.types.js +0 -2
- package/dist/infrastructure/artifact-store.types.js.map +0 -1
- package/dist/infrastructure/journal-retention.constants.d.ts +0 -4
- package/dist/infrastructure/journal-retention.constants.js +0 -5
- package/dist/infrastructure/journal-retention.constants.js.map +0 -1
- package/dist/infrastructure/journal-retention.d.ts +0 -2
- package/dist/infrastructure/journal-retention.js +0 -51
- package/dist/infrastructure/journal-retention.js.map +0 -1
- package/dist/infrastructure/storage-mutation-lock.constants.d.ts +0 -5
- package/dist/infrastructure/storage-mutation-lock.constants.js +0 -6
- package/dist/infrastructure/storage-mutation-lock.constants.js.map +0 -1
- package/dist/infrastructure/storage-mutation-lock.d.ts +0 -1
- package/dist/infrastructure/storage-mutation-lock.js +0 -21
- package/dist/infrastructure/storage-mutation-lock.js.map +0 -1
- package/dist/infrastructure/storage-reservations.constants.d.ts +0 -4
- package/dist/infrastructure/storage-reservations.constants.js +0 -5
- package/dist/infrastructure/storage-reservations.constants.js.map +0 -1
- package/dist/infrastructure/storage-reservations.d.ts +0 -2
- package/dist/infrastructure/storage-reservations.js +0 -150
- package/dist/infrastructure/storage-reservations.js.map +0 -1
- package/dist/infrastructure/workflow-checkpoint.d.ts +0 -3
- package/dist/infrastructure/workflow-checkpoint.js +0 -84
- package/dist/infrastructure/workflow-checkpoint.js.map +0 -1
- package/dist/infrastructure/workflow-checkpoint.types.d.ts +0 -6
- package/dist/infrastructure/workflow-checkpoint.types.js +0 -2
- package/dist/infrastructure/workflow-checkpoint.types.js.map +0 -1
- /package/dist/adapters/models/{openai-http.d.ts → model-http.d.ts} +0 -0
- /package/dist/adapters/models/{openai-compatible.constants.d.ts → model.constants.d.ts} +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { invariant } from "./errors.js";
|
|
2
|
+
import { JSON_SCHEMA_KEYWORDS, JSON_SCHEMA_TYPES } from "./tool.constants.js";
|
|
3
|
+
const plain = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
|
5
|
+
const typeChecks = {
|
|
6
|
+
object: plain,
|
|
7
|
+
array: Array.isArray,
|
|
8
|
+
string: (value) => typeof value === "string",
|
|
9
|
+
number: (value) => typeof value === "number" && Number.isFinite(value),
|
|
10
|
+
integer: (value) => Number.isInteger(value),
|
|
11
|
+
boolean: (value) => typeof value === "boolean",
|
|
12
|
+
null: (value) => value === null,
|
|
13
|
+
};
|
|
14
|
+
const keywordChecks = {
|
|
15
|
+
enum: (schema, value, path) => schema.enum.some((option) => same(option, value))
|
|
16
|
+
? []
|
|
17
|
+
: [`${path} must be one of ${JSON.stringify(schema.enum)}`],
|
|
18
|
+
const: (schema, value, path) => same(schema.const, value)
|
|
19
|
+
? []
|
|
20
|
+
: [`${path} must equal ${JSON.stringify(schema.const)}`],
|
|
21
|
+
minLength: bound((value) => typeof value === "string" ? [...value].length : undefined)("minLength", (size, limit) => size >= limit, "at least", "characters"),
|
|
22
|
+
maxLength: bound((value) => typeof value === "string" ? [...value].length : undefined)("maxLength", (size, limit) => size <= limit, "at most", "characters"),
|
|
23
|
+
minimum: bound((value) => (typeof value === "number" ? value : undefined))("minimum", (size, limit) => size >= limit, "at least", ""),
|
|
24
|
+
maximum: bound((value) => (typeof value === "number" ? value : undefined))("maximum", (size, limit) => size <= limit, "at most", ""),
|
|
25
|
+
minItems: bound((value) => (Array.isArray(value) ? value.length : undefined))("minItems", (size, limit) => size >= limit, "at least", "items"),
|
|
26
|
+
maxItems: bound((value) => (Array.isArray(value) ? value.length : undefined))("maxItems", (size, limit) => size <= limit, "at most", "items"),
|
|
27
|
+
items: (schema, value, path) => Array.isArray(value)
|
|
28
|
+
? value.flatMap((item, index) => schemaIssues(schema.items, item, `${path}[${index}]`))
|
|
29
|
+
: [],
|
|
30
|
+
required: (schema, value, path) => plain(value)
|
|
31
|
+
? schema.required.flatMap((key) => Object.hasOwn(value, key) ? [] : [`${path}.${key} is required`])
|
|
32
|
+
: [],
|
|
33
|
+
properties: (schema, value, path) => plain(value)
|
|
34
|
+
? Object.entries(schema.properties)
|
|
35
|
+
.filter(([key]) => Object.hasOwn(value, key))
|
|
36
|
+
.flatMap(([key, property]) => schemaIssues(property, value[key], `${path}.${key}`))
|
|
37
|
+
: [],
|
|
38
|
+
additionalProperties: (schema, value, path) => {
|
|
39
|
+
if (!plain(value))
|
|
40
|
+
return [];
|
|
41
|
+
const declared = plain(schema.properties) ? schema.properties : {};
|
|
42
|
+
const extra = Object.keys(value).filter((key) => !Object.hasOwn(declared, key));
|
|
43
|
+
if (schema.additionalProperties === false)
|
|
44
|
+
return extra.map((key) => `${path}.${key} is not allowed`);
|
|
45
|
+
if (!plain(schema.additionalProperties))
|
|
46
|
+
return [];
|
|
47
|
+
const additional = schema.additionalProperties;
|
|
48
|
+
return extra.flatMap((key) => schemaIssues(additional, value[key], `${path}.${key}`));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export function validateSchemaDefinition(schema, root = true) {
|
|
52
|
+
invariant(plain(schema), "Tool input schema must be a JSON Schema object");
|
|
53
|
+
invariant(Object.keys(schema).every((key) => JSON_SCHEMA_KEYWORDS.has(key)), `Unsupported JSON Schema keyword; use ${[...JSON_SCHEMA_KEYWORDS].join(", ")}`);
|
|
54
|
+
const types = schemaTypes(schema);
|
|
55
|
+
invariant(types.every((type) => JSON_SCHEMA_TYPES.has(type)), "Unsupported JSON Schema type");
|
|
56
|
+
invariant(!root || (types.length === 1 && types[0] === "object"), "Tool input schema must describe an object");
|
|
57
|
+
invariant(schema.required === undefined ||
|
|
58
|
+
(Array.isArray(schema.required) &&
|
|
59
|
+
schema.required.every((key) => typeof key === "string")), "JSON Schema required must list property names");
|
|
60
|
+
invariant(schema.enum === undefined || Array.isArray(schema.enum), "JSON Schema enum must be an array");
|
|
61
|
+
for (const keyword of [
|
|
62
|
+
"minLength",
|
|
63
|
+
"maxLength",
|
|
64
|
+
"minimum",
|
|
65
|
+
"maximum",
|
|
66
|
+
"minItems",
|
|
67
|
+
"maxItems",
|
|
68
|
+
])
|
|
69
|
+
invariant(schema[keyword] === undefined ||
|
|
70
|
+
(typeof schema[keyword] === "number" &&
|
|
71
|
+
Number.isFinite(schema[keyword])), `JSON Schema ${keyword} must be a number`);
|
|
72
|
+
if (schema.properties !== undefined) {
|
|
73
|
+
invariant(plain(schema.properties), "JSON Schema properties must be an object");
|
|
74
|
+
for (const property of Object.values(schema.properties))
|
|
75
|
+
validateSchemaDefinition(property, false);
|
|
76
|
+
}
|
|
77
|
+
if (schema.items !== undefined)
|
|
78
|
+
validateSchemaDefinition(schema.items, false);
|
|
79
|
+
if (plain(schema.additionalProperties))
|
|
80
|
+
validateSchemaDefinition(schema.additionalProperties, false);
|
|
81
|
+
invariant(schema.additionalProperties === undefined ||
|
|
82
|
+
typeof schema.additionalProperties === "boolean" ||
|
|
83
|
+
plain(schema.additionalProperties), "JSON Schema additionalProperties must be a boolean or a schema");
|
|
84
|
+
}
|
|
85
|
+
export function schemaIssues(schema, value, path = "input") {
|
|
86
|
+
const types = schemaTypes(schema);
|
|
87
|
+
if (types.length && !types.some((type) => typeChecks[type](value)))
|
|
88
|
+
return [`${path} must be ${types.join(" or ")}`];
|
|
89
|
+
return Object.keys(schema)
|
|
90
|
+
.filter((keyword) => Object.hasOwn(keywordChecks, keyword))
|
|
91
|
+
.flatMap((keyword) => keywordChecks[keyword](schema, value, path));
|
|
92
|
+
}
|
|
93
|
+
function schemaTypes(schema) {
|
|
94
|
+
if (schema.type === undefined)
|
|
95
|
+
return [];
|
|
96
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
97
|
+
invariant(types.every((type) => typeof type === "string"), "JSON Schema type must be a name or a list of names");
|
|
98
|
+
return types;
|
|
99
|
+
}
|
|
100
|
+
function bound(measure) {
|
|
101
|
+
return (keyword, accept, relation, unit) => (schema, value, path) => {
|
|
102
|
+
const size = measure(value);
|
|
103
|
+
const limit = typeof schema[keyword] === "number" ? schema[keyword] : undefined;
|
|
104
|
+
if (size === undefined || limit === undefined || accept(size, limit))
|
|
105
|
+
return [];
|
|
106
|
+
return [`${path} must be ${relation} ${limit}${unit ? ` ${unit}` : ""}`];
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=tool-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-schema.js","sourceRoot":"","sources":["../../src/domain/tool-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG9E,MAAM,KAAK,GAAG,CAAC,KAAc,EAA8C,EAAE,CAC3E,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvE,MAAM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AC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { invariant } from \"./errors.ts\";\nimport { JSON_SCHEMA_KEYWORDS, JSON_SCHEMA_TYPES } from \"./tool.constants.ts\";\nimport type { JsonSchema, SchemaKeywordCheck } from \"./tool.types.ts\";\n\nconst plain = (value: unknown): value is Readonly<Record<string, unknown>> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\nconst same = (left: unknown, right: unknown) =>\n JSON.stringify(left) === JSON.stringify(right);\n\nconst typeChecks: Readonly<Record<string, (value: unknown) => boolean>> = {\n object: plain,\n array: Array.isArray,\n string: (value) => typeof value === \"string\",\n number: (value) => typeof value === \"number\" && Number.isFinite(value),\n integer: (value) => Number.isInteger(value),\n boolean: (value) => typeof value === \"boolean\",\n null: (value) => value === null,\n};\n\nconst keywordChecks: Readonly<Record<string, SchemaKeywordCheck>> = {\n enum: (schema, value, path) =>\n (schema.enum as readonly unknown[]).some((option) => same(option, value))\n ? []\n : [`${path} must be one of ${JSON.stringify(schema.enum)}`],\n const: (schema, value, path) =>\n same(schema.const, value)\n ? []\n : [`${path} must equal ${JSON.stringify(schema.const)}`],\n minLength: bound((value) =>\n typeof value === \"string\" ? [...value].length : undefined,\n )(\"minLength\", (size, limit) => size >= limit, \"at least\", \"characters\"),\n maxLength: bound((value) =>\n typeof value === \"string\" ? [...value].length : undefined,\n )(\"maxLength\", (size, limit) => size <= limit, \"at most\", \"characters\"),\n minimum: bound((value) => (typeof value === \"number\" ? value : undefined))(\n \"minimum\",\n (size, limit) => size >= limit,\n \"at least\",\n \"\",\n ),\n maximum: bound((value) => (typeof value === \"number\" ? value : undefined))(\n \"maximum\",\n (size, limit) => size <= limit,\n \"at most\",\n \"\",\n ),\n minItems: bound((value) => (Array.isArray(value) ? value.length : undefined))(\n \"minItems\",\n (size, limit) => size >= limit,\n \"at least\",\n \"items\",\n ),\n maxItems: bound((value) => (Array.isArray(value) ? value.length : undefined))(\n \"maxItems\",\n (size, limit) => size <= limit,\n \"at most\",\n \"items\",\n ),\n items: (schema, value, path) =>\n Array.isArray(value)\n ? value.flatMap((item, index) =>\n schemaIssues(schema.items as JsonSchema, item, `${path}[${index}]`),\n )\n : [],\n required: (schema, value, path) =>\n plain(value)\n ? (schema.required as readonly string[]).flatMap((key) =>\n Object.hasOwn(value, key) ? [] : [`${path}.${key} is required`],\n )\n : [],\n properties: (schema, value, path) =>\n plain(value)\n ? Object.entries(schema.properties as Record<string, JsonSchema>)\n .filter(([key]) => Object.hasOwn(value, key))\n .flatMap(([key, property]) =>\n schemaIssues(property, value[key], `${path}.${key}`),\n )\n : [],\n additionalProperties: (schema, value, path) => {\n if (!plain(value)) return [];\n const declared = plain(schema.properties) ? schema.properties : {};\n const extra = Object.keys(value).filter(\n (key) => !Object.hasOwn(declared, key),\n );\n if (schema.additionalProperties === false)\n return extra.map((key) => `${path}.${key} is not allowed`);\n if (!plain(schema.additionalProperties)) return [];\n const additional = schema.additionalProperties;\n return extra.flatMap((key) =>\n schemaIssues(additional, value[key], `${path}.${key}`),\n );\n },\n};\n\nexport function validateSchemaDefinition(schema: unknown, root = true): void {\n invariant(plain(schema), \"Tool input schema must be a JSON Schema object\");\n invariant(\n Object.keys(schema).every((key) => JSON_SCHEMA_KEYWORDS.has(key)),\n `Unsupported JSON Schema keyword; use ${[...JSON_SCHEMA_KEYWORDS].join(\", \")}`,\n );\n const types = schemaTypes(schema);\n invariant(\n types.every((type) => JSON_SCHEMA_TYPES.has(type)),\n \"Unsupported JSON Schema type\",\n );\n invariant(\n !root || (types.length === 1 && types[0] === \"object\"),\n \"Tool input schema must describe an object\",\n );\n invariant(\n schema.required === undefined ||\n (Array.isArray(schema.required) &&\n schema.required.every((key) => typeof key === \"string\")),\n \"JSON Schema required must list property names\",\n );\n invariant(\n schema.enum === undefined || Array.isArray(schema.enum),\n \"JSON Schema enum must be an array\",\n );\n for (const keyword of [\n \"minLength\",\n \"maxLength\",\n \"minimum\",\n \"maximum\",\n \"minItems\",\n \"maxItems\",\n ])\n invariant(\n schema[keyword] === undefined ||\n (typeof schema[keyword] === \"number\" &&\n Number.isFinite(schema[keyword])),\n `JSON Schema ${keyword} must be a number`,\n );\n if (schema.properties !== undefined) {\n invariant(\n plain(schema.properties),\n \"JSON Schema properties must be an object\",\n );\n for (const property of Object.values(schema.properties))\n validateSchemaDefinition(property, false);\n }\n if (schema.items !== undefined) validateSchemaDefinition(schema.items, false);\n if (plain(schema.additionalProperties))\n validateSchemaDefinition(schema.additionalProperties, false);\n invariant(\n schema.additionalProperties === undefined ||\n typeof schema.additionalProperties === \"boolean\" ||\n plain(schema.additionalProperties),\n \"JSON Schema additionalProperties must be a boolean or a schema\",\n );\n}\n\nexport function schemaIssues(\n schema: JsonSchema,\n value: unknown,\n path = \"input\",\n): readonly string[] {\n const types = schemaTypes(schema);\n if (types.length && !types.some((type) => typeChecks[type]!(value)))\n return [`${path} must be ${types.join(\" or \")}`];\n return Object.keys(schema)\n .filter((keyword) => Object.hasOwn(keywordChecks, keyword))\n .flatMap((keyword) => keywordChecks[keyword]!(schema, value, path));\n}\n\nfunction schemaTypes(schema: JsonSchema): readonly string[] {\n if (schema.type === undefined) return [];\n const types = Array.isArray(schema.type) ? schema.type : [schema.type];\n invariant(\n types.every((type) => typeof type === \"string\"),\n \"JSON Schema type must be a name or a list of names\",\n );\n return types;\n}\n\nfunction bound(measure: (value: unknown) => number | undefined) {\n return (\n keyword: string,\n accept: (size: number, limit: number) => boolean,\n relation: string,\n unit: string,\n ): SchemaKeywordCheck =>\n (schema, value, path) => {\n const size = measure(value);\n const limit =\n typeof schema[keyword] === \"number\" ? schema[keyword] : undefined;\n if (size === undefined || limit === undefined || accept(size, limit))\n return [];\n return [`${path} must be ${relation} ${limit}${unit ? ` ${unit}` : \"\"}`];\n };\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const JSON_SCHEMA_KEYWORDS = new Set([
|
|
2
|
+
"type",
|
|
3
|
+
"title",
|
|
4
|
+
"description",
|
|
5
|
+
"properties",
|
|
6
|
+
"required",
|
|
7
|
+
"additionalProperties",
|
|
8
|
+
"items",
|
|
9
|
+
"enum",
|
|
10
|
+
"const",
|
|
11
|
+
"minLength",
|
|
12
|
+
"maxLength",
|
|
13
|
+
"minimum",
|
|
14
|
+
"maximum",
|
|
15
|
+
"minItems",
|
|
16
|
+
"maxItems",
|
|
17
|
+
]);
|
|
18
|
+
export const JSON_SCHEMA_TYPES = new Set([
|
|
19
|
+
"object",
|
|
20
|
+
"array",
|
|
21
|
+
"string",
|
|
22
|
+
"number",
|
|
23
|
+
"integer",
|
|
24
|
+
"boolean",
|
|
25
|
+
"null",
|
|
26
|
+
]);
|
|
27
|
+
export const STANDARD_JSON_SCHEMA_TARGET = "draft-2020-12";
|
|
28
|
+
export const HARNESS_TOOL_FIELDS = new Set([
|
|
29
|
+
"name",
|
|
30
|
+
"description",
|
|
31
|
+
"input",
|
|
32
|
+
"readOnly",
|
|
33
|
+
"resources",
|
|
34
|
+
"execute",
|
|
35
|
+
]);
|
|
36
|
+
//# sourceMappingURL=tool.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.constants.js","sourceRoot":"","sources":["../../src/domain/tool.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IAC/D,MAAM;IACN,OAAO;IACP,aAAa;IACb,YAAY;IACZ,UAAU;IACV,sBAAsB;IACtB,OAAO;IACP,MAAM;IACN,OAAO;IACP,WAAW;IACX,WAAW;IACX,SAAS;IACT,SAAS;IACT,UAAU;IACV,UAAU;CACX,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IAC5D,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,MAAM;CACP,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,2BAA2B,GAAG,eAAe,CAAC;AAE3D,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IAC9D,MAAM;IACN,aAAa;IACb,OAAO;IACP,UAAU;IACV,WAAW;IACX,SAAS;CACV,CAAC,CAAC","sourcesContent":["export const JSON_SCHEMA_KEYWORDS: ReadonlySet<string> = new Set([\n \"type\",\n \"title\",\n \"description\",\n \"properties\",\n \"required\",\n \"additionalProperties\",\n \"items\",\n \"enum\",\n \"const\",\n \"minLength\",\n \"maxLength\",\n \"minimum\",\n \"maximum\",\n \"minItems\",\n \"maxItems\",\n]);\n\nexport const JSON_SCHEMA_TYPES: ReadonlySet<string> = new Set([\n \"object\",\n \"array\",\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"null\",\n]);\n\nexport const STANDARD_JSON_SCHEMA_TARGET = \"draft-2020-12\";\n\nexport const HARNESS_TOOL_FIELDS: ReadonlySet<string> = new Set([\n \"name\",\n \"description\",\n \"input\",\n \"readOnly\",\n \"resources\",\n \"execute\",\n]);\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HarnessTool, HarnessToolOptions, HarnessToolset, HarnessToolsetOptions } from "./tool.types.ts";
|
|
2
|
+
export declare function defineHarnessTool<Input>(options: HarnessToolOptions<Input>): HarnessTool<Input>;
|
|
3
|
+
export declare function defineHarnessToolset(options: HarnessToolsetOptions): HarnessToolset;
|
|
4
|
+
export declare function harnessTools(entries: readonly (HarnessTool | HarnessToolset)[]): readonly HarnessTool[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { invariant } from "./errors.js";
|
|
2
|
+
import { TOOL_NAME_PATTERN } from "./model.constants.js";
|
|
3
|
+
import { formatIssues, isStandardJsonSchema, standardInputSchema, validateStandard, } from "./standard-schema.js";
|
|
4
|
+
import { HARNESS_TOOL_FIELDS } from "./tool.constants.js";
|
|
5
|
+
import { schemaIssues, validateSchemaDefinition } from "./tool-schema.js";
|
|
6
|
+
export function defineHarnessTool(options) {
|
|
7
|
+
invariant(options !== null && typeof options === "object", "Tool options must be an object");
|
|
8
|
+
invariant(Object.keys(options).every((key) => HARNESS_TOOL_FIELDS.has(key)), "Unsupported tool option");
|
|
9
|
+
invariant(typeof options.name === "string" && TOOL_NAME_PATTERN.test(options.name), "Tool names use 1 to 64 letters, digits, underscores or hyphens");
|
|
10
|
+
invariant(typeof options.description === "string" && options.description.trim(), "Tool description must be nonempty text");
|
|
11
|
+
invariant(typeof options.execute === "function", "Tool execute must be a function");
|
|
12
|
+
invariant(options.readOnly === undefined || typeof options.readOnly === "boolean", "Tool readOnly must be boolean");
|
|
13
|
+
invariant(options.resources === undefined || typeof options.resources === "function", "Tool resources must be a function");
|
|
14
|
+
const standard = isStandardJsonSchema(options.input)
|
|
15
|
+
? options.input
|
|
16
|
+
: undefined;
|
|
17
|
+
if (!standard)
|
|
18
|
+
validateSchemaDefinition(options.input);
|
|
19
|
+
const inputSchema = standard
|
|
20
|
+
? standardInputSchema(standard)
|
|
21
|
+
: Object.freeze(structuredClone(options.input));
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
kind: "tool",
|
|
24
|
+
name: options.name,
|
|
25
|
+
description: options.description,
|
|
26
|
+
readOnly: options.readOnly ?? false,
|
|
27
|
+
inputSchema,
|
|
28
|
+
async validate(value) {
|
|
29
|
+
if (standard) {
|
|
30
|
+
const result = await validateStandard(standard, value);
|
|
31
|
+
return "issues" in result
|
|
32
|
+
? { issues: formatIssues(result.issues) }
|
|
33
|
+
: { value: result.value };
|
|
34
|
+
}
|
|
35
|
+
const issues = schemaIssues(inputSchema, value);
|
|
36
|
+
return issues.length
|
|
37
|
+
? { issues: issues.join("; ") }
|
|
38
|
+
: { value: value };
|
|
39
|
+
},
|
|
40
|
+
resources: (value) => options.resources?.(value) ?? {},
|
|
41
|
+
execute: (value, context) => options.execute(value, context),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function defineHarnessToolset(options) {
|
|
45
|
+
invariant(options !== null && typeof options === "object", "Toolset options must be an object");
|
|
46
|
+
invariant(typeof options.name === "string" && options.name.trim(), "Toolset name must be nonempty text");
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
kind: "toolset",
|
|
49
|
+
name: options.name,
|
|
50
|
+
tools: harnessTools(options.tools),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function harnessTools(entries) {
|
|
54
|
+
invariant(Array.isArray(entries), "Tools must be an array");
|
|
55
|
+
const tools = entries.flatMap((entry) => {
|
|
56
|
+
invariant(entry?.kind === "tool" || entry?.kind === "toolset", "Declare tools with defineHarnessTool or defineHarnessToolset");
|
|
57
|
+
return entry.kind === "tool" ? [entry] : entry.tools;
|
|
58
|
+
});
|
|
59
|
+
const names = new Set();
|
|
60
|
+
for (const tool of tools) {
|
|
61
|
+
invariant(!names.has(tool.name), `Duplicate tool name: ${tool.name}`);
|
|
62
|
+
names.add(tool.name);
|
|
63
|
+
}
|
|
64
|
+
return Object.freeze(tools);
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/domain/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAY1E,MAAM,UAAU,iBAAiB,CAC/B,OAAkC;IAElC,SAAS,CACP,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAC/C,gCAAgC,CACj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EAAE,OAAO,CAAC,IAAI;QAClB,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,OAAkD;IAElD,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtC,SAAS,CACP,KAAK,EAAE,IAAI,KAAK,MAAM,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS,EACnD,8DAA8D,CAC/D,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,wBAAwB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { invariant } from \"./errors.ts\";\nimport { TOOL_NAME_PATTERN } from \"./model.constants.ts\";\nimport {\n formatIssues,\n isStandardJsonSchema,\n standardInputSchema,\n validateStandard,\n} from \"./standard-schema.ts\";\nimport { HARNESS_TOOL_FIELDS } from \"./tool.constants.ts\";\nimport { schemaIssues, validateSchemaDefinition } from \"./tool-schema.ts\";\nimport type {\n HarnessTool,\n HarnessToolContext,\n HarnessToolOptions,\n HarnessToolset,\n HarnessToolsetOptions,\n JsonSchema,\n StandardJsonSchema,\n ToolValidation,\n} from \"./tool.types.ts\";\n\nexport function defineHarnessTool<Input>(\n options: HarnessToolOptions<Input>,\n): HarnessTool<Input> {\n invariant(\n options !== null && typeof options === \"object\",\n \"Tool options must be an object\",\n );\n invariant(\n Object.keys(options).every((key) => HARNESS_TOOL_FIELDS.has(key)),\n \"Unsupported tool option\",\n );\n invariant(\n typeof options.name === \"string\" && TOOL_NAME_PATTERN.test(options.name),\n \"Tool names use 1 to 64 letters, digits, underscores or hyphens\",\n );\n invariant(\n typeof options.description === \"string\" && options.description.trim(),\n \"Tool description must be nonempty text\",\n );\n invariant(\n typeof options.execute === \"function\",\n \"Tool execute must be a function\",\n );\n invariant(\n options.readOnly === undefined || typeof options.readOnly === \"boolean\",\n \"Tool readOnly must be boolean\",\n );\n invariant(\n options.resources === undefined || typeof options.resources === \"function\",\n \"Tool resources must be a function\",\n );\n const standard = isStandardJsonSchema(options.input)\n ? (options.input as StandardJsonSchema<Input>)\n : undefined;\n if (!standard) validateSchemaDefinition(options.input);\n const inputSchema: JsonSchema = standard\n ? standardInputSchema(standard)\n : Object.freeze(structuredClone(options.input as JsonSchema));\n return Object.freeze({\n kind: \"tool\",\n name: options.name,\n description: options.description,\n readOnly: options.readOnly ?? false,\n inputSchema,\n async validate(value: unknown): Promise<ToolValidation<Input>> {\n if (standard) {\n const result = await validateStandard(standard, value);\n return \"issues\" in result\n ? { issues: formatIssues(result.issues) }\n : { value: result.value };\n }\n const issues = schemaIssues(inputSchema, value);\n return issues.length\n ? { issues: issues.join(\"; \") }\n : { value: value as Input };\n },\n resources: (value: Input) => options.resources?.(value) ?? {},\n execute: (value: Input, context: HarnessToolContext) =>\n options.execute(value, context),\n });\n}\n\nexport function defineHarnessToolset(\n options: HarnessToolsetOptions,\n): HarnessToolset {\n invariant(\n options !== null && typeof options === \"object\",\n \"Toolset options must be an object\",\n );\n invariant(\n typeof options.name === \"string\" && options.name.trim(),\n \"Toolset name must be nonempty text\",\n );\n return Object.freeze({\n kind: \"toolset\",\n name: options.name,\n tools: harnessTools(options.tools),\n });\n}\n\nexport function harnessTools(\n entries: readonly (HarnessTool | HarnessToolset)[],\n): readonly HarnessTool[] {\n invariant(Array.isArray(entries), \"Tools must be an array\");\n const tools = entries.flatMap((entry) => {\n invariant(\n entry?.kind === \"tool\" || entry?.kind === \"toolset\",\n \"Declare tools with defineHarnessTool or defineHarnessToolset\",\n );\n return entry.kind === \"tool\" ? [entry] : entry.tools;\n });\n const names = new Set<string>();\n for (const tool of tools) {\n invariant(!names.has(tool.name), `Duplicate tool name: ${tool.name}`);\n names.add(tool.name);\n }\n return Object.freeze(tools);\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AgentEvent } from "./agent.types.ts";
|
|
2
|
+
import type { AgentModel } from "./model.types.ts";
|
|
3
|
+
import type { ToolResources } from "./permissions.types.ts";
|
|
4
|
+
import type { StandardValidator } from "./response.types.ts";
|
|
5
|
+
import type { SandboxLease } from "./sandbox.types.ts";
|
|
6
|
+
export type JsonSchema = Readonly<Record<string, unknown>>;
|
|
7
|
+
export interface StandardJsonSchema<Input> {
|
|
8
|
+
readonly "~standard": StandardValidator<Input>["~standard"] & {
|
|
9
|
+
readonly jsonSchema: {
|
|
10
|
+
input(options: {
|
|
11
|
+
readonly target: string;
|
|
12
|
+
}): Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type HarnessToolEvent = Extract<AgentEvent, {
|
|
17
|
+
readonly kind: "text" | "warning" | "raw";
|
|
18
|
+
}>;
|
|
19
|
+
export interface HarnessToolContext {
|
|
20
|
+
readonly sandbox: SandboxLease;
|
|
21
|
+
readonly signal: AbortSignal;
|
|
22
|
+
readonly callId: string;
|
|
23
|
+
readonly model: AgentModel;
|
|
24
|
+
observe(event: HarnessToolEvent): void;
|
|
25
|
+
}
|
|
26
|
+
export type ToolOutput = string | {
|
|
27
|
+
readonly content: string;
|
|
28
|
+
readonly isError?: boolean;
|
|
29
|
+
};
|
|
30
|
+
export interface HarnessToolOptions<Input> {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly input: StandardJsonSchema<Input> | JsonSchema;
|
|
34
|
+
readonly readOnly?: boolean;
|
|
35
|
+
resources?(input: Input): ToolResources;
|
|
36
|
+
execute(input: Input, context: HarnessToolContext): ToolOutput | Promise<ToolOutput>;
|
|
37
|
+
}
|
|
38
|
+
export type ToolValidation<Input> = {
|
|
39
|
+
readonly value: Input;
|
|
40
|
+
} | {
|
|
41
|
+
readonly issues: string;
|
|
42
|
+
};
|
|
43
|
+
export interface HarnessTool<Input = unknown> {
|
|
44
|
+
readonly kind: "tool";
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly description: string;
|
|
47
|
+
readonly readOnly: boolean;
|
|
48
|
+
readonly inputSchema: JsonSchema;
|
|
49
|
+
validate(value: unknown): Promise<ToolValidation<Input>>;
|
|
50
|
+
resources(input: Input): ToolResources;
|
|
51
|
+
execute(input: Input, context: HarnessToolContext): ToolOutput | Promise<ToolOutput>;
|
|
52
|
+
}
|
|
53
|
+
export interface HarnessToolsetOptions {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly tools: readonly (HarnessTool | HarnessToolset)[];
|
|
56
|
+
}
|
|
57
|
+
export interface HarnessToolset {
|
|
58
|
+
readonly kind: "toolset";
|
|
59
|
+
readonly name: string;
|
|
60
|
+
readonly tools: readonly HarnessTool[];
|
|
61
|
+
}
|
|
62
|
+
export type SchemaKeywordCheck = (schema: JsonSchema, value: unknown, path: string) => readonly string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.types.js","sourceRoot":"","sources":["../../src/domain/tool.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentEvent } from \"./agent.types.ts\";\nimport type { AgentModel } from \"./model.types.ts\";\nimport type { ToolResources } from \"./permissions.types.ts\";\nimport type { StandardValidator } from \"./response.types.ts\";\nimport type { SandboxLease } from \"./sandbox.types.ts\";\n\nexport type JsonSchema = Readonly<Record<string, unknown>>;\n\nexport interface StandardJsonSchema<Input> {\n readonly \"~standard\": StandardValidator<Input>[\"~standard\"] & {\n readonly jsonSchema: {\n input(options: { readonly target: string }): Record<string, unknown>;\n };\n };\n}\n\nexport type HarnessToolEvent = Extract<\n AgentEvent,\n { readonly kind: \"text\" | \"warning\" | \"raw\" }\n>;\n\nexport interface HarnessToolContext {\n readonly sandbox: SandboxLease;\n readonly signal: AbortSignal;\n readonly callId: string;\n readonly model: AgentModel;\n observe(event: HarnessToolEvent): void;\n}\n\nexport type ToolOutput =\n string | { readonly content: string; readonly isError?: boolean };\n\nexport interface HarnessToolOptions<Input> {\n readonly name: string;\n readonly description: string;\n readonly input: StandardJsonSchema<Input> | JsonSchema;\n readonly readOnly?: boolean;\n resources?(input: Input): ToolResources;\n execute(\n input: Input,\n context: HarnessToolContext,\n ): ToolOutput | Promise<ToolOutput>;\n}\n\nexport type ToolValidation<Input> =\n { readonly value: Input } | { readonly issues: string };\n\nexport interface HarnessTool<Input = unknown> {\n readonly kind: \"tool\";\n readonly name: string;\n readonly description: string;\n readonly readOnly: boolean;\n readonly inputSchema: JsonSchema;\n validate(value: unknown): Promise<ToolValidation<Input>>;\n resources(input: Input): ToolResources;\n execute(\n input: Input,\n context: HarnessToolContext,\n ): ToolOutput | Promise<ToolOutput>;\n}\n\nexport interface HarnessToolsetOptions {\n readonly name: string;\n readonly tools: readonly (HarnessTool | HarnessToolset)[];\n}\n\nexport interface HarnessToolset {\n readonly kind: \"toolset\";\n readonly name: string;\n readonly tools: readonly HarnessTool[];\n}\n\nexport type SchemaKeywordCheck = (\n schema: JsonSchema,\n value: unknown,\n path: string,\n) => readonly string[];\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ModelMessage } from "./model.types.ts";
|
|
2
|
+
import type { TranscriptRecord } from "./transcript.types.ts";
|
|
3
|
+
export declare function parseTranscript(text: string): readonly TranscriptRecord[];
|
|
4
|
+
export declare function transcriptMessages(records: readonly TranscriptRecord[]): ModelMessage[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OutpostError } from "./errors.js";
|
|
2
|
+
const folds = {
|
|
3
|
+
session: (messages) => messages,
|
|
4
|
+
message: (messages, record) => record.type === "message" ? [...messages, record.message] : messages,
|
|
5
|
+
compaction: (_messages, record) => record.type === "compaction" ? [...record.messages] : [],
|
|
6
|
+
};
|
|
7
|
+
export function parseTranscript(text) {
|
|
8
|
+
const records = text
|
|
9
|
+
.split("\n")
|
|
10
|
+
.filter((line) => line.trim())
|
|
11
|
+
.map((line) => {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(line);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new OutpostError("session", "Harness transcript is not valid JSONL");
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const first = records[0];
|
|
20
|
+
if (first?.type !== "session" || first.version !== 1)
|
|
21
|
+
throw new OutpostError("session", "Unsupported harness transcript");
|
|
22
|
+
for (const record of records)
|
|
23
|
+
if (!Object.hasOwn(folds, record?.type))
|
|
24
|
+
throw new OutpostError("session", "Unsupported harness transcript record");
|
|
25
|
+
return records;
|
|
26
|
+
}
|
|
27
|
+
export function transcriptMessages(records) {
|
|
28
|
+
const messages = records.reduce((current, record) => folds[record.type](current, record), []);
|
|
29
|
+
const last = messages.at(-1);
|
|
30
|
+
const pending = last?.role === "assistant"
|
|
31
|
+
? last.content.flatMap((block) => block.type === "tool-call" ? [block.id] : [])
|
|
32
|
+
: [];
|
|
33
|
+
if (!pending.length)
|
|
34
|
+
return messages;
|
|
35
|
+
return [
|
|
36
|
+
...messages,
|
|
37
|
+
{
|
|
38
|
+
role: "user",
|
|
39
|
+
content: pending.map((callId) => ({
|
|
40
|
+
type: "tool-result",
|
|
41
|
+
callId,
|
|
42
|
+
content: "The tool call was interrupted before it produced a result.",
|
|
43
|
+
isError: true,
|
|
44
|
+
})),
|
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\";\nimport type { TranscriptRecord } from \"./transcript.types.ts\";\n\nconst folds: Readonly<\n Record<\n TranscriptRecord[\"type\"],\n (messages: ModelMessage[], record: TranscriptRecord) => ModelMessage[]\n >\n> = {\n session: (messages) => messages,\n message: (messages, record) =>\n record.type === \"message\" ? [...messages, record.message] : messages,\n compaction: (_messages, record) =>\n record.type === \"compaction\" ? [...record.messages] : [],\n};\n\nexport function parseTranscript(text: string): readonly TranscriptRecord[] {\n const records = text\n .split(\"\\n\")\n .filter((line) => line.trim())\n .map((line) => {\n try {\n return JSON.parse(line) as TranscriptRecord;\n } catch {\n throw new OutpostError(\n \"session\",\n \"Harness transcript is not valid JSONL\",\n );\n }\n });\n const first = records[0];\n if (first?.type !== \"session\" || first.version !== 1)\n throw new OutpostError(\"session\", \"Unsupported harness transcript\");\n for (const record of records)\n if (!Object.hasOwn(folds, record?.type))\n throw new OutpostError(\n \"session\",\n \"Unsupported harness transcript record\",\n );\n return records;\n}\n\nexport function transcriptMessages(\n records: readonly TranscriptRecord[],\n): ModelMessage[] {\n const messages = records.reduce<ModelMessage[]>(\n (current, record) => folds[record.type](current, record),\n [],\n );\n const last = messages.at(-1);\n const pending =\n last?.role === \"assistant\"\n ? last.content.flatMap((block) =>\n block.type === \"tool-call\" ? [block.id] : [],\n )\n : [];\n if (!pending.length) return messages;\n return [\n ...messages,\n {\n role: \"user\",\n content: pending.map((callId) => ({\n type: \"tool-result\" as const,\n callId,\n content: \"The tool call was interrupted before it produced a result.\",\n isError: true,\n })),\n },\n ];\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ModelMessage } from "./model.types.ts";
|
|
2
|
+
export type TranscriptRecord = {
|
|
3
|
+
readonly type: "session";
|
|
4
|
+
readonly version: 1;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly model: string;
|
|
7
|
+
readonly parent?: string;
|
|
8
|
+
readonly createdAt: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "message";
|
|
11
|
+
readonly message: ModelMessage;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "compaction";
|
|
14
|
+
readonly messages: readonly ModelMessage[];
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.types.js","sourceRoot":"","sources":["../../src/domain/transcript.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ModelMessage } from \"./model.types.ts\";\n\nexport type TranscriptRecord =\n | {\n readonly type: \"session\";\n readonly version: 1;\n readonly id: string;\n readonly model: string;\n readonly parent?: string;\n readonly createdAt: string;\n }\n | { readonly type: \"message\"; readonly message: ModelMessage }\n | { readonly type: \"compaction\"; readonly messages: readonly ModelMessage[] };\n"]}
|
|
@@ -61,13 +61,20 @@ export function workflowState(name, tasks, options, checkpoint) {
|
|
|
61
61
|
}, saved?.usage);
|
|
62
62
|
const record = (item) => records.get(item);
|
|
63
63
|
function emit(event) {
|
|
64
|
+
const notification = {
|
|
65
|
+
...event,
|
|
66
|
+
executionId,
|
|
67
|
+
workflow: name,
|
|
68
|
+
timestamp: new Date().toISOString(),
|
|
69
|
+
};
|
|
64
70
|
try {
|
|
65
|
-
options.observe
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
options.telemetry?.observe(notification);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
observerErrors.push(error);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
options.observe?.(notification);
|
|
71
78
|
}
|
|
72
79
|
catch (error) {
|
|
73
80
|
observerErrors.push(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-state.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EA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eAAe,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;gBAClC,oBAAoB,CAAC,OAAO,CAAC,CAAC;gBAC9B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACzB,CAAC;YACD,KAAK,CAAI,UAAmB;gBAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;oBAClC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,GAAG,2BAA2B,UAAU,CAAC,GAAG,EAAE,CACvD,CAAC;gBACJ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;oBACzB,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,GAAG,0BAA0B,CAAC,CAAC;gBAC/D,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,CAAM,CAAC;YACrC,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAA2B;QACtC,KAAK,CAAC,OAAO;YACX,MAAM,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,WAAW;QACX,UAAU;QACV,YAAY,CAAC,IAAI;YACf,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI;QACJ,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM;QACN,cAAc;QACd,MAAM;QACN,IAAI;QACJ,MAAM;QACN,OAAO;QACP,OAAO;KACR,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { maxUsageReceiptsPerTask } from \"./usage-receipt.constants.ts\";\nimport { validateUsageReceipt } from \"./usage-receipt.ts\";\nimport type { Usage } from \"../agent.types.ts\";\nimport type { WorkflowCheckpointSession } from \"./checkpoint.types.ts\";\nimport { workflowAccounting } from \"./budget.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type {\n Task,\n TaskContext,\n TaskRecord,\n TaskStatus,\n WorkflowEvent,\n WorkflowExecutionState,\n WorkflowOptions,\n} from \"../workflow.types.ts\";\n\nexport function workflowState(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n checkpoint?: WorkflowCheckpointSession,\n): WorkflowExecutionState {\n const executionId = checkpoint?.initial?.executionId ?? randomUUID();\n const stop = new AbortController();\n const signal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n const values = new Map<Task, unknown>();\n const activeAttempts = new Map<Task, number>();\n const records = new Map<Task, TaskRecord>(\n tasks.map((item) => [\n item,\n { key: item.key, status: \"waiting\", attempts: 0 },\n ]),\n );\n const saved = checkpoint?.initial;\n if (saved) {\n const complete = saved.records.every((entry) =>\n [\"done\", \"skipped\"].includes(entry.status),\n );\n const settledPause =\n saved.records.some((entry) =>\n [\"paused\", \"rejected\"].includes(entry.status),\n ) &&\n saved.records.every(\n (entry) =>\n [\"done\", \"skipped\", \"paused\", \"rejected\"].includes(entry.status) ||\n (entry.status === \"waiting\" && entry.attempts === 0),\n );\n for (const item of tasks) {\n const entry = saved.records.find((entry) => entry.key === item.key)!;\n records.set(item, {\n ...entry,\n ...(entry.usageReceipts\n ? { usageReceipts: Object.freeze([...entry.usageReceipts]) }\n : {}),\n ...(entry.pause\n ? {\n pause: Object.freeze({\n ...entry.pause,\n actors: Object.freeze([...entry.pause.actors]),\n }),\n }\n : {}),\n ...(entry.decision\n ? { decision: Object.freeze({ ...entry.decision }) }\n : {}),\n status:\n [\"done\", \"paused\", \"rejected\"].includes(entry.status) ||\n complete ||\n (settledPause && entry.status === \"skipped\")\n ? entry.status\n : \"waiting\",\n });\n if (entry.status === \"done\") {\n const output = saved.values[item.key]!;\n values.set(item, output.kind === \"json\" ? output.value : undefined);\n }\n }\n }\n const errors: unknown[] = [],\n observerErrors: unknown[] = [];\n for (const entry of records.values())\n if (entry.status === \"rejected\") errors.push(new Error(entry.error));\n const accounting = workflowAccounting(\n options.budget,\n (error) => {\n errors.push(error);\n if (error.dimension !== \"attempts\") stop.abort(error);\n },\n saved?.usage,\n );\n const record = (item: Task) => records.get(item)!;\n function emit(\n event: Omit<WorkflowEvent, \"executionId\" | \"workflow\" | \"timestamp\">,\n ): void {\n try {\n options.observe?.({\n ...event,\n executionId,\n workflow: name,\n timestamp: new Date().toISOString(),\n });\n } catch (error) {\n observerErrors.push(error);\n }\n }\n function finish(item: Task, status: TaskStatus): void {\n Object.assign(record(item), {\n status,\n finishedAt: new Date().toISOString(),\n });\n emit({\n type: \"task\",\n key: item.key,\n status,\n attempt: record(item).attempts,\n ...(record(item).startedAt\n ? { durationMs: Date.now() - Date.parse(record(item).startedAt!) }\n : {}),\n });\n }\n function context(\n item: Task,\n attempt: number,\n taskSignal: AbortSignal,\n ): TaskContext {\n if (attempt > 0) activeAttempts.set(item, attempt);\n function report(usage: Usage, receipt?: string): void {\n const current = record(item);\n if (\n attempt === 0 ||\n current.status !== \"active\" ||\n activeAttempts.get(item) !== attempt\n )\n throw new Error(\n \"Usage must be reported during its active task attempt\",\n );\n if (receipt !== undefined) {\n validateUsageReceipt(receipt);\n if (current.usageReceipts?.includes(receipt)) return;\n if ((current.usageReceipts?.length ?? 0) >= maxUsageReceiptsPerTask)\n throw new Error(\"Workflow usage receipt limit exceeded\");\n }\n const previousReceipts = current.usageReceipts;\n if (receipt !== undefined)\n current.usageReceipts = Object.freeze([\n ...(previousReceipts ?? []),\n receipt,\n ]);\n try {\n accounting.report(usage);\n } catch (error) {\n if (previousReceipts) current.usageReceipts = previousReceipts;\n else delete current.usageReceipts;\n throw error;\n }\n void runtime.persist().catch((error: unknown) => stop.abort(error));\n emit({\n type: \"usage\",\n key: item.key,\n attempt,\n usage: Object.freeze({ ...usage }),\n });\n }\n\n return {\n signal: taskSignal,\n attempt,\n executionId,\n checkpoint: () => runtime.persist(),\n reportUsage: (usage) => report(usage),\n reportUsageOnce: (receipt, usage) => {\n validateUsageReceipt(receipt);\n report(usage, receipt);\n },\n value<T>(dependency: Task<T>): T {\n if (!item.after.includes(dependency))\n throw new Error(\n `${item.key}: undeclared dependency ${dependency.key}`,\n );\n if (!values.has(dependency))\n throw new Error(`${dependency.key} has no successful value`);\n return values.get(dependency) as T;\n },\n };\n }\n\n const runtime: WorkflowExecutionState = {\n async persist() {\n await checkpoint?.save(runtime);\n },\n executionId,\n accounting,\n closeAttempt(item) {\n activeAttempts.delete(item);\n },\n stop,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n context,\n options,\n };\n return runtime;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow-state.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,KAAsB,EACtB,OAAwB,EACxB,UAAsC;IAEtC,MAAM,WAAW,GAAG,UAAU,EAAE,OAAO,EAAE,WAAW,IAAI,UAAU,EAAE,CAAC;IACrE,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM;QAC3B,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAChB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IACxC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAgB,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,IAAI;QACJ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,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AAG,CAAC,UAAU,CAAM,CAAC;YACrC,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAA2B;QACtC,KAAK,CAAC,OAAO;YACX,MAAM,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,WAAW;QACX,UAAU;QACV,YAAY,CAAC,IAAI;YACf,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI;QACJ,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM;QACN,cAAc;QACd,MAAM;QACN,IAAI;QACJ,MAAM;QACN,OAAO;QACP,OAAO;KACR,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { maxUsageReceiptsPerTask } from \"./usage-receipt.constants.ts\";\nimport { validateUsageReceipt } from \"./usage-receipt.ts\";\nimport type { Usage } from \"../agent.types.ts\";\nimport type { WorkflowCheckpointSession } from \"./checkpoint.types.ts\";\nimport { workflowAccounting } from \"./budget.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type {\n Task,\n TaskContext,\n TaskRecord,\n TaskStatus,\n WorkflowEvent,\n WorkflowExecutionState,\n WorkflowOptions,\n} from \"../workflow.types.ts\";\n\nexport function workflowState(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n checkpoint?: WorkflowCheckpointSession,\n): WorkflowExecutionState {\n const executionId = checkpoint?.initial?.executionId ?? randomUUID();\n const stop = new AbortController();\n const signal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n const values = new Map<Task, unknown>();\n const activeAttempts = new Map<Task, number>();\n const records = new Map<Task, TaskRecord>(\n tasks.map((item) => [\n item,\n { key: item.key, status: \"waiting\", attempts: 0 },\n ]),\n );\n const saved = checkpoint?.initial;\n if (saved) {\n const complete = saved.records.every((entry) =>\n [\"done\", \"skipped\"].includes(entry.status),\n );\n const settledPause =\n saved.records.some((entry) =>\n [\"paused\", \"rejected\"].includes(entry.status),\n ) &&\n saved.records.every(\n (entry) =>\n [\"done\", \"skipped\", \"paused\", \"rejected\"].includes(entry.status) ||\n (entry.status === \"waiting\" && entry.attempts === 0),\n );\n for (const item of tasks) {\n const entry = saved.records.find((entry) => entry.key === item.key)!;\n records.set(item, {\n ...entry,\n ...(entry.usageReceipts\n ? { usageReceipts: Object.freeze([...entry.usageReceipts]) }\n : {}),\n ...(entry.pause\n ? {\n pause: Object.freeze({\n ...entry.pause,\n actors: Object.freeze([...entry.pause.actors]),\n }),\n }\n : {}),\n ...(entry.decision\n ? { decision: Object.freeze({ ...entry.decision }) }\n : {}),\n status:\n [\"done\", \"paused\", \"rejected\"].includes(entry.status) ||\n complete ||\n (settledPause && entry.status === \"skipped\")\n ? entry.status\n : \"waiting\",\n });\n if (entry.status === \"done\") {\n const output = saved.values[item.key]!;\n values.set(item, output.kind === \"json\" ? output.value : undefined);\n }\n }\n }\n const errors: unknown[] = [],\n observerErrors: unknown[] = [];\n for (const entry of records.values())\n if (entry.status === \"rejected\") errors.push(new Error(entry.error));\n const accounting = workflowAccounting(\n options.budget,\n (error) => {\n errors.push(error);\n if (error.dimension !== \"attempts\") stop.abort(error);\n },\n saved?.usage,\n );\n const record = (item: Task) => records.get(item)!;\n function emit(\n event: Omit<WorkflowEvent, \"executionId\" | \"workflow\" | \"timestamp\">,\n ): void {\n const notification: WorkflowEvent = {\n ...event,\n executionId,\n workflow: name,\n timestamp: new Date().toISOString(),\n };\n try {\n options.telemetry?.observe(notification);\n } catch (error) {\n observerErrors.push(error);\n }\n try {\n options.observe?.(notification);\n } catch (error) {\n observerErrors.push(error);\n }\n }\n function finish(item: Task, status: TaskStatus): void {\n Object.assign(record(item), {\n status,\n finishedAt: new Date().toISOString(),\n });\n emit({\n type: \"task\",\n key: item.key,\n status,\n attempt: record(item).attempts,\n ...(record(item).startedAt\n ? { durationMs: Date.now() - Date.parse(record(item).startedAt!) }\n : {}),\n });\n }\n function context(\n item: Task,\n attempt: number,\n taskSignal: AbortSignal,\n ): TaskContext {\n if (attempt > 0) activeAttempts.set(item, attempt);\n function report(usage: Usage, receipt?: string): void {\n const current = record(item);\n if (\n attempt === 0 ||\n current.status !== \"active\" ||\n activeAttempts.get(item) !== attempt\n )\n throw new Error(\n \"Usage must be reported during its active task attempt\",\n );\n if (receipt !== undefined) {\n validateUsageReceipt(receipt);\n if (current.usageReceipts?.includes(receipt)) return;\n if ((current.usageReceipts?.length ?? 0) >= maxUsageReceiptsPerTask)\n throw new Error(\"Workflow usage receipt limit exceeded\");\n }\n const previousReceipts = current.usageReceipts;\n if (receipt !== undefined)\n current.usageReceipts = Object.freeze([\n ...(previousReceipts ?? []),\n receipt,\n ]);\n try {\n accounting.report(usage);\n } catch (error) {\n if (previousReceipts) current.usageReceipts = previousReceipts;\n else delete current.usageReceipts;\n throw error;\n }\n void runtime.persist().catch((error: unknown) => stop.abort(error));\n emit({\n type: \"usage\",\n key: item.key,\n attempt,\n usage: Object.freeze({ ...usage }),\n });\n }\n\n return {\n signal: taskSignal,\n attempt,\n executionId,\n checkpoint: () => runtime.persist(),\n reportUsage: (usage) => report(usage),\n reportUsageOnce: (receipt, usage) => {\n validateUsageReceipt(receipt);\n report(usage, receipt);\n },\n value<T>(dependency: Task<T>): T {\n if (!item.after.includes(dependency))\n throw new Error(\n `${item.key}: undeclared dependency ${dependency.key}`,\n );\n if (!values.has(dependency))\n throw new Error(`${dependency.key} has no successful value`);\n return values.get(dependency) as T;\n },\n };\n }\n\n const runtime: WorkflowExecutionState = {\n async persist() {\n await checkpoint?.save(runtime);\n },\n executionId,\n accounting,\n closeAttempt(item) {\n activeAttempts.delete(item);\n },\n stop,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n context,\n options,\n };\n return runtime;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Task, Workflow } from "./workflow.types.ts";
|
|
2
|
-
export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Workflow, WorkflowEvent, WorkflowOptions, WorkflowResult, } from "./workflow.types.ts";
|
|
2
|
+
export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Workflow, WorkflowEvent, WorkflowOptions, WorkflowResult, WorkflowTelemetry, } from "./workflow.types.ts";
|
|
3
3
|
export { WorkflowFailure } from "./workflow/failure.ts";
|
|
4
4
|
export { task } from "./workflow/task.ts";
|
|
5
5
|
export declare function workflow(name: string, tasks: readonly Task[]): Workflow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/domain/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/domain/workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAe5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAsB;IAC3D,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI;QACJ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,CAAC,UAA2B,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC;QACxE,OAAO;YACL,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACrE,OAAO;gBACL,cAAc;gBACd,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;oBACzB,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI;oBACnC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CACf,CAAC,UAAU,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAChE;iBACF,CAAC;aACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["import type { Task, Workflow, WorkflowOptions } from \"./workflow.types.ts\";\nimport { validate } from \"./workflow/validation.ts\";\nimport { schedule } from \"./workflow/workflow-scheduler.ts\";\n\nexport type {\n Retry,\n Task,\n TaskContext,\n TaskOptions,\n TaskRecord,\n TaskStatus,\n Workflow,\n WorkflowEvent,\n WorkflowOptions,\n WorkflowResult,\n WorkflowTelemetry,\n} from \"./workflow.types.ts\";\nexport { WorkflowFailure } from \"./workflow/failure.ts\";\nexport { task } from \"./workflow/task.ts\";\n\nexport function workflow(name: string, tasks: readonly Task[]): Workflow {\n if (!name.trim()) throw new Error(\"Workflow name cannot be empty\");\n const graph = Object.freeze([...tasks]);\n validate(graph);\n return Object.freeze({\n name,\n tasks: graph,\n start: (options: WorkflowOptions = {}) => schedule(name, graph, options),\n diagram() {\n const ids = new Map(graph.map((item, index) => [item, `n${index}`]));\n return [\n \"flowchart LR\",\n ...graph.flatMap((item) => [\n ` ${ids.get(item)}[\"${item.key}\"]`,\n ...item.after.map(\n (dependency) => ` ${ids.get(dependency)} --> ${ids.get(item)}`,\n ),\n ]),\n ].join(\"\\n\");\n },\n });\n}\n\nexport { WorkflowBudgetExceeded } from \"./workflow/budget.ts\";\nexport type { WorkflowBudget, WorkflowUsage } from \"./workflow/budget.types.ts\";\n"]}
|
|
@@ -51,6 +51,9 @@ export interface WorkflowEvent {
|
|
|
51
51
|
readonly usage?: Usage;
|
|
52
52
|
readonly durationMs?: number;
|
|
53
53
|
}
|
|
54
|
+
export interface WorkflowTelemetry {
|
|
55
|
+
observe(event: WorkflowEvent): void;
|
|
56
|
+
}
|
|
54
57
|
export interface WorkflowOptions {
|
|
55
58
|
readonly decisions?: readonly WorkflowDecision[];
|
|
56
59
|
readonly checkpoint?: WorkflowCheckpointOptions;
|
|
@@ -58,6 +61,7 @@ export interface WorkflowOptions {
|
|
|
58
61
|
readonly concurrency?: number;
|
|
59
62
|
readonly budget?: WorkflowBudget;
|
|
60
63
|
readonly stopOnError?: boolean;
|
|
64
|
+
readonly telemetry?: WorkflowTelemetry;
|
|
61
65
|
readonly observe?: (event: WorkflowEvent) => void;
|
|
62
66
|
}
|
|
63
67
|
export interface WorkflowResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.types.js","sourceRoot":"","sources":["../../src/domain/workflow.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n WorkflowDecision,\n WorkflowDecisionRecord,\n WorkflowGate,\n WorkflowPauseRequest,\n} from \"./workflow/gates.types.ts\";\nimport type { WorkflowCheckpointOptions } from \"./workflow/checkpoint.types.ts\";\nimport type { Usage } from \"./agent.types.ts\";\nimport type {\n WorkflowAccounting,\n WorkflowBudget,\n WorkflowUsage,\n} from \"./workflow/budget.types.ts\";\n\nexport interface TaskContext {\n readonly signal: AbortSignal;\n readonly attempt: number;\n readonly executionId: string;\n reportUsage(usage: Usage): void;\n reportUsageOnce?(receipt: string, usage: Usage): void;\n checkpoint?(): Promise<void>;\n value<T>(dependency: Task<T>): T;\n}\n\nexport interface Retry {\n readonly attempts: number;\n readonly delayMs?: number;\n readonly accepts?: (error: unknown, attempt: number) => boolean;\n}\n\nexport interface Task<T = unknown> {\n readonly key: string;\n readonly gate?: WorkflowGate;\n readonly after: readonly Task[];\n readonly perform: (context: TaskContext) => T | Promise<T>;\n readonly condition?: (context: TaskContext) => boolean | Promise<boolean>;\n readonly retry?: Retry;\n readonly timeoutMs?: number;\n}\n\nexport type TaskOptions<T> = Omit<Task<T>, \"after\"> & {\n readonly after?: readonly Task[];\n};\n\nexport type TaskStatus =\n | \"waiting\"\n | \"active\"\n | \"done\"\n | \"failed\"\n | \"skipped\"\n | \"cancelled\"\n | \"paused\"\n | \"rejected\";\n\nexport interface TaskRecord {\n usageReceipts?: readonly string[];\n pause?: WorkflowPauseRequest;\n decision?: WorkflowDecisionRecord;\n readonly key: string;\n status: TaskStatus;\n attempts: number;\n startedAt?: string;\n finishedAt?: string;\n error?: string;\n}\n\nexport interface WorkflowEvent {\n readonly executionId: string;\n readonly workflow: string;\n readonly timestamp: string;\n readonly type: \"start\" | \"task\" | \"attempt\" | \"retry\" | \"usage\" | \"finish\";\n readonly key?: string;\n readonly status?: TaskStatus;\n readonly attempt?: number;\n readonly usage?: Usage;\n readonly durationMs?: number;\n}\n\nexport interface WorkflowOptions {\n readonly decisions?: readonly WorkflowDecision[];\n readonly checkpoint?: WorkflowCheckpointOptions;\n readonly signal?: AbortSignal;\n readonly concurrency?: number;\n readonly budget?: WorkflowBudget;\n readonly stopOnError?: boolean;\n readonly observe?: (event: WorkflowEvent) => void;\n}\n\nexport interface WorkflowResult {\n readonly executionId: string;\n readonly name: string;\n readonly status: \"done\" | \"failed\" | \"cancelled\" | \"paused\";\n readonly tasks: readonly Readonly<TaskRecord>[];\n readonly errors: readonly unknown[];\n readonly observerErrors: readonly unknown[];\n readonly usage: WorkflowUsage;\n value<T>(task: Task<T>): T;\n unwrap(): void;\n}\n\nexport interface Workflow {\n readonly name: string;\n readonly tasks: readonly Task[];\n start(options?: WorkflowOptions): Promise<WorkflowResult>;\n diagram(): string;\n}\n\nexport type WorkflowNotification = Omit<\n WorkflowEvent,\n \"executionId\" | \"workflow\" | \"timestamp\"\n>;\nexport interface WorkflowExecutionState {\n readonly executionId: string;\n readonly stop: AbortController;\n readonly signal: AbortSignal;\n readonly values: Map<Task, unknown>;\n readonly records: Map<Task, TaskRecord>;\n readonly errors: unknown[];\n readonly observerErrors: unknown[];\n readonly options: WorkflowOptions;\n readonly accounting: WorkflowAccounting;\n persist(): Promise<void>;\n closeAttempt(task: Task): void;\n record(task: Task): TaskRecord;\n emit(event: WorkflowNotification): void;\n finish(task: Task, status: TaskStatus): void;\n context(task: Task, attempt: number, signal: AbortSignal): TaskContext;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow.types.js","sourceRoot":"","sources":["../../src/domain/workflow.types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n WorkflowDecision,\n WorkflowDecisionRecord,\n WorkflowGate,\n WorkflowPauseRequest,\n} from \"./workflow/gates.types.ts\";\nimport type { WorkflowCheckpointOptions } from \"./workflow/checkpoint.types.ts\";\nimport type { Usage } from \"./agent.types.ts\";\nimport type {\n WorkflowAccounting,\n WorkflowBudget,\n WorkflowUsage,\n} from \"./workflow/budget.types.ts\";\n\nexport interface TaskContext {\n readonly signal: AbortSignal;\n readonly attempt: number;\n readonly executionId: string;\n reportUsage(usage: Usage): void;\n reportUsageOnce?(receipt: string, usage: Usage): void;\n checkpoint?(): Promise<void>;\n value<T>(dependency: Task<T>): T;\n}\n\nexport interface Retry {\n readonly attempts: number;\n readonly delayMs?: number;\n readonly accepts?: (error: unknown, attempt: number) => boolean;\n}\n\nexport interface Task<T = unknown> {\n readonly key: string;\n readonly gate?: WorkflowGate;\n readonly after: readonly Task[];\n readonly perform: (context: TaskContext) => T | Promise<T>;\n readonly condition?: (context: TaskContext) => boolean | Promise<boolean>;\n readonly retry?: Retry;\n readonly timeoutMs?: number;\n}\n\nexport type TaskOptions<T> = Omit<Task<T>, \"after\"> & {\n readonly after?: readonly Task[];\n};\n\nexport type TaskStatus =\n | \"waiting\"\n | \"active\"\n | \"done\"\n | \"failed\"\n | \"skipped\"\n | \"cancelled\"\n | \"paused\"\n | \"rejected\";\n\nexport interface TaskRecord {\n usageReceipts?: readonly string[];\n pause?: WorkflowPauseRequest;\n decision?: WorkflowDecisionRecord;\n readonly key: string;\n status: TaskStatus;\n attempts: number;\n startedAt?: string;\n finishedAt?: string;\n error?: string;\n}\n\nexport interface WorkflowEvent {\n readonly executionId: string;\n readonly workflow: string;\n readonly timestamp: string;\n readonly type: \"start\" | \"task\" | \"attempt\" | \"retry\" | \"usage\" | \"finish\";\n readonly key?: string;\n readonly status?: TaskStatus;\n readonly attempt?: number;\n readonly usage?: Usage;\n readonly durationMs?: number;\n}\n\nexport interface WorkflowTelemetry {\n observe(event: WorkflowEvent): void;\n}\n\nexport interface WorkflowOptions {\n readonly decisions?: readonly WorkflowDecision[];\n readonly checkpoint?: WorkflowCheckpointOptions;\n readonly signal?: AbortSignal;\n readonly concurrency?: number;\n readonly budget?: WorkflowBudget;\n readonly stopOnError?: boolean;\n readonly telemetry?: WorkflowTelemetry;\n readonly observe?: (event: WorkflowEvent) => void;\n}\n\nexport interface WorkflowResult {\n readonly executionId: string;\n readonly name: string;\n readonly status: \"done\" | \"failed\" | \"cancelled\" | \"paused\";\n readonly tasks: readonly Readonly<TaskRecord>[];\n readonly errors: readonly unknown[];\n readonly observerErrors: readonly unknown[];\n readonly usage: WorkflowUsage;\n value<T>(task: Task<T>): T;\n unwrap(): void;\n}\n\nexport interface Workflow {\n readonly name: string;\n readonly tasks: readonly Task[];\n start(options?: WorkflowOptions): Promise<WorkflowResult>;\n diagram(): string;\n}\n\nexport type WorkflowNotification = Omit<\n WorkflowEvent,\n \"executionId\" | \"workflow\" | \"timestamp\"\n>;\nexport interface WorkflowExecutionState {\n readonly executionId: string;\n readonly stop: AbortController;\n readonly signal: AbortSignal;\n readonly values: Map<Task, unknown>;\n readonly records: Map<Task, TaskRecord>;\n readonly errors: unknown[];\n readonly observerErrors: unknown[];\n readonly options: WorkflowOptions;\n readonly accounting: WorkflowAccounting;\n persist(): Promise<void>;\n closeAttempt(task: Task): void;\n record(task: Task): TaskRecord;\n emit(event: WorkflowNotification): void;\n finish(task: Task, status: TaskStatus): void;\n context(task: Task, attempt: number, signal: AbortSignal): TaskContext;\n}\n"]}
|