@elie-laloum/outpost 5.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/README.md +11 -11
- package/SECURITY.md +10 -0
- package/dist/adapters/agents/antigravity-adapter.d.ts +3 -0
- package/dist/adapters/agents/antigravity-adapter.js +41 -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 +75 -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 +37 -0
- package/dist/adapters/agents/antigravity-request.js.map +1 -0
- package/dist/adapters/agents/antigravity.constants.d.ts +3 -0
- package/dist/adapters/agents/antigravity.constants.js +4 -0
- package/dist/adapters/agents/antigravity.constants.js.map +1 -0
- package/dist/adapters/agents/{gemini.types.d.ts → antigravity.types.d.ts} +2 -2
- 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 +19 -9
- package/dist/adapters/agents/authentication.constants.js +12 -9
- package/dist/adapters/agents/authentication.constants.js.map +1 -1
- package/dist/adapters/agents/authentication.d.ts +11 -2
- package/dist/adapters/agents/authentication.js +70 -47
- package/dist/adapters/agents/authentication.js.map +1 -1
- 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.js +4 -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-events.js +52 -9
- package/dist/adapters/agents/claude-events.js.map +1 -1
- package/dist/adapters/agents/claude-request.js +2 -0
- 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 +18 -0
- package/dist/adapters/agents/cli-diagnostics.js.map +1 -1
- package/dist/adapters/agents/codex-adapter.js +4 -2
- 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-events.js +28 -2
- package/dist/adapters/agents/codex-events.js.map +1 -1
- package/dist/adapters/agents/copilot-adapter.d.ts +3 -0
- package/dist/adapters/agents/copilot-adapter.js +45 -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 +46 -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 +66 -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 +24 -0
- package/dist/adapters/agents/copilot-request.js.map +1 -0
- package/dist/adapters/agents/copilot-usage.d.ts +3 -0
- package/dist/adapters/agents/copilot-usage.js +19 -0
- package/dist/adapters/agents/copilot-usage.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 +51 -0
- package/dist/adapters/agents/kimi-adapter.js.map +1 -0
- package/dist/adapters/agents/kimi-authentication.d.ts +3 -0
- package/dist/adapters/agents/kimi-authentication.js +63 -0
- package/dist/adapters/agents/kimi-authentication.js.map +1 -0
- package/dist/adapters/agents/kimi-diagnostics.d.ts +2 -0
- package/dist/adapters/agents/kimi-diagnostics.js +14 -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 +55 -0
- package/dist/adapters/agents/kimi-events.js.map +1 -0
- package/dist/adapters/agents/kimi-fork.d.ts +2 -0
- package/dist/adapters/agents/kimi-fork.js +11 -0
- package/dist/adapters/agents/kimi-fork.js.map +1 -0
- package/dist/adapters/agents/{gemini-request.d.ts → kimi-request.d.ts} +2 -2
- package/dist/adapters/agents/kimi-request.js +33 -0
- package/dist/adapters/agents/kimi-request.js.map +1 -0
- package/dist/adapters/agents/kimi-usage.d.ts +2 -0
- package/dist/adapters/agents/kimi-usage.js +7 -0
- package/dist/adapters/agents/kimi-usage.js.map +1 -0
- package/dist/adapters/agents/kimi.constants.d.ts +13 -0
- package/dist/adapters/agents/kimi.constants.js +14 -0
- package/dist/adapters/agents/kimi.constants.js.map +1 -0
- package/dist/adapters/agents/kimi.types.d.ts +7 -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 +3 -1
- package/dist/adapters/agents/model-support.constants.js +12 -2
- package/dist/adapters/agents/model-support.constants.js.map +1 -1
- package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -2
- package/dist/adapters/agents/protocol-fixtures.constants.js +131 -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/session-usage.constants.d.ts +10 -0
- package/dist/adapters/agents/session-usage.constants.js +110 -0
- package/dist/adapters/agents/session-usage.constants.js.map +1 -0
- package/dist/adapters/agents/session-usage.d.ts +5 -0
- package/dist/adapters/agents/session-usage.js +45 -0
- package/dist/adapters/agents/session-usage.js.map +1 -0
- package/dist/adapters/agents/settings.types.d.ts +1 -0
- package/dist/adapters/agents/settings.types.js.map +1 -1
- package/dist/adapters/agents/tool-result.d.ts +2 -0
- package/dist/adapters/agents/tool-result.js +17 -0
- package/dist/adapters/agents/tool-result.js.map +1 -0
- package/dist/adapters/models/anthropic-response.js +3 -0
- package/dist/adapters/models/anthropic-response.js.map +1 -1
- package/dist/adapters/models/http-provider.js +6 -1
- package/dist/adapters/models/http-provider.js.map +1 -1
- package/dist/adapters/models/openai-responses.js +10 -0
- package/dist/adapters/models/openai-responses.js.map +1 -1
- package/dist/adapters/models/retry-after.d.ts +1 -0
- package/dist/adapters/models/retry-after.js +16 -0
- package/dist/adapters/models/retry-after.js.map +1 -0
- package/dist/application/activity-watchdog.js +1 -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 +27 -4
- package/dist/application/agent-bootstrap.constants.js.map +1 -1
- package/dist/application/agent-bootstrap.js +39 -12
- package/dist/application/agent-bootstrap.js.map +1 -1
- package/dist/application/agent-bootstrap.types.d.ts +19 -0
- package/dist/application/agent-bootstrap.types.js +2 -0
- package/dist/application/agent-bootstrap.types.js.map +1 -0
- package/dist/application/agent-output.js +74 -8
- package/dist/application/agent-output.js.map +1 -1
- package/dist/application/agent-request.d.ts +3 -0
- package/dist/application/agent-request.js +11 -0
- package/dist/application/agent-request.js.map +1 -0
- package/dist/application/agent-turn.js +74 -6
- package/dist/application/agent-turn.js.map +1 -1
- package/dist/application/agent-usage.d.ts +6 -0
- package/dist/application/agent-usage.js +57 -0
- package/dist/application/agent-usage.js.map +1 -0
- package/dist/application/attach.js +2 -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.js +44 -49
- package/dist/application/custom-turn.js.map +1 -1
- package/dist/application/dispatch-observation.d.ts +1 -1
- package/dist/application/dispatch-observation.js +141 -21
- package/dist/application/dispatch-observation.js.map +1 -1
- package/dist/application/dispatch-observation.types.d.ts +2 -0
- package/dist/application/dispatch-observation.types.js.map +1 -1
- package/dist/application/dispatch-validation.js +2 -0
- package/dist/application/dispatch-validation.js.map +1 -1
- package/dist/application/dispatch.js +1 -1
- 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 +43 -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 +15 -3
- package/dist/application/doctor-agent.js.map +1 -1
- package/dist/application/doctor-image.js +4 -6
- package/dist/application/doctor-image.js.map +1 -1
- package/dist/application/doctor-protocol.js +6 -11
- 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 +2 -5
- package/dist/application/doctor-sandbox.js.map +1 -1
- package/dist/application/doctor.js +28 -10
- package/dist/application/doctor.js.map +1 -1
- package/dist/application/doctor.types.d.ts +10 -1
- package/dist/application/doctor.types.js.map +1 -1
- package/dist/application/execution.constants.d.ts +2 -0
- package/dist/application/execution.constants.js +2 -0
- package/dist/application/execution.constants.js.map +1 -1
- package/dist/application/execution.types.d.ts +8 -0
- package/dist/application/execution.types.js.map +1 -1
- package/dist/application/harness-budget.d.ts +3 -0
- package/dist/application/harness-budget.js +42 -0
- package/dist/application/harness-budget.js.map +1 -0
- package/dist/application/harness-budget.types.d.ts +5 -0
- package/dist/application/harness-budget.types.js +2 -0
- package/dist/application/harness-budget.types.js.map +1 -0
- package/dist/application/harness-hooks.js +34 -3
- package/dist/application/harness-hooks.js.map +1 -1
- package/dist/application/harness-loop.js +52 -24
- package/dist/application/harness-loop.js.map +1 -1
- package/dist/application/harness-model-provider.d.ts +3 -0
- package/dist/application/harness-model-provider.js +49 -0
- package/dist/application/harness-model-provider.js.map +1 -0
- package/dist/application/harness-model-provider.types.d.ts +10 -0
- package/dist/application/harness-model-provider.types.js +2 -0
- package/dist/application/harness-model-provider.types.js.map +1 -0
- package/dist/application/harness-subagent.d.ts +4 -0
- package/dist/application/harness-subagent.js +110 -0
- package/dist/application/harness-subagent.js.map +1 -0
- package/dist/application/harness.types.d.ts +11 -0
- package/dist/application/harness.types.js.map +1 -1
- package/dist/application/lifecycle-hooks.d.ts +1 -1
- package/dist/application/lifecycle-hooks.js +5 -4
- package/dist/application/lifecycle-hooks.js.map +1 -1
- package/dist/application/observed-lease.d.ts +3 -0
- package/dist/application/observed-lease.js +26 -0
- package/dist/application/observed-lease.js.map +1 -0
- package/dist/application/outpost.types.d.ts +3 -1
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/output-lines.d.ts +4 -0
- package/dist/application/output-lines.js +28 -0
- package/dist/application/output-lines.js.map +1 -0
- package/dist/application/queue-worker.js +1 -1
- package/dist/application/queue-worker.js.map +1 -1
- package/dist/application/queue-worker.types.d.ts +1 -0
- package/dist/application/queue-worker.types.js.map +1 -1
- package/dist/application/queued-task.js +24 -5
- package/dist/application/queued-task.js.map +1 -1
- package/dist/application/recovery-archive.d.ts +3 -2
- package/dist/application/recovery-archive.js +9 -2
- package/dist/application/recovery-archive.js.map +1 -1
- package/dist/application/recovery-restore.d.ts +3 -2
- package/dist/application/recovery-restore.js +9 -2
- package/dist/application/recovery-restore.js.map +1 -1
- package/dist/application/recovery-retention.d.ts +3 -2
- package/dist/application/recovery-retention.js +74 -26
- package/dist/application/recovery-retention.js.map +1 -1
- package/dist/application/remote-workspace.js +5 -4
- package/dist/application/remote-workspace.js.map +1 -1
- package/dist/application/remote-workspace.types.d.ts +1 -0
- package/dist/application/remote-workspace.types.js.map +1 -1
- package/dist/application/sandbox-agents.js +19 -19
- package/dist/application/sandbox-agents.js.map +1 -1
- package/dist/application/sandbox-attach.js +12 -3
- package/dist/application/sandbox-attach.js.map +1 -1
- package/dist/application/sandbox-dispatch.js +13 -27
- package/dist/application/sandbox-dispatch.js.map +1 -1
- package/dist/application/sandbox-provision.js +15 -9
- package/dist/application/sandbox-provision.js.map +1 -1
- package/dist/application/sandbox-session.types.d.ts +7 -2
- package/dist/application/sandbox-session.types.js.map +1 -1
- package/dist/application/sandbox.js +13 -6
- package/dist/application/sandbox.js.map +1 -1
- package/dist/application/speculation-checkpoint.d.ts +6 -0
- package/dist/application/speculation-checkpoint.js +206 -0
- package/dist/application/speculation-checkpoint.js.map +1 -0
- package/dist/application/speculation-checkpoint.types.d.ts +24 -0
- package/dist/application/speculation-checkpoint.types.js +2 -0
- package/dist/application/speculation-checkpoint.types.js.map +1 -0
- package/dist/application/speculation-integration.constants.d.ts +4 -0
- package/dist/application/speculation-integration.constants.js +5 -0
- package/dist/application/speculation-integration.constants.js.map +1 -0
- package/dist/application/speculation-integration.d.ts +2 -0
- package/dist/application/speculation-integration.js +67 -0
- package/dist/application/speculation-integration.js.map +1 -0
- package/dist/application/speculation-resume.d.ts +4 -0
- package/dist/application/speculation-resume.js +71 -0
- package/dist/application/speculation-resume.js.map +1 -0
- package/dist/application/speculation-run.d.ts +4 -0
- package/dist/application/speculation-run.js +320 -0
- package/dist/application/speculation-run.js.map +1 -0
- package/dist/application/speculation-timeout.d.ts +1 -0
- package/dist/application/speculation-timeout.js +15 -0
- package/dist/application/speculation-timeout.js.map +1 -0
- package/dist/application/speculation.constants.d.ts +1 -0
- package/dist/application/speculation.constants.js +5 -1
- package/dist/application/speculation.constants.js.map +1 -1
- package/dist/application/speculation.js +41 -149
- package/dist/application/speculation.js.map +1 -1
- package/dist/application/speculation.types.d.ts +23 -0
- package/dist/application/speculation.types.js.map +1 -1
- package/dist/application/startup-recovery.js +14 -1
- package/dist/application/startup-recovery.js.map +1 -1
- package/dist/application/startup-recovery.types.d.ts +1 -0
- package/dist/application/startup-recovery.types.js.map +1 -1
- package/dist/application/stop-reason.d.ts +2 -0
- package/dist/application/stop-reason.js +21 -0
- package/dist/application/stop-reason.js.map +1 -0
- package/dist/application/stop-reason.types.d.ts +4 -0
- package/dist/application/stop-reason.types.js +2 -0
- package/dist/application/stop-reason.types.js.map +1 -0
- package/dist/application/storage-reservation.js +9 -2
- package/dist/application/storage-reservation.js.map +1 -1
- package/dist/application/task-observation.d.ts +3 -0
- package/dist/application/task-observation.js +22 -0
- package/dist/application/task-observation.js.map +1 -0
- package/dist/application/task-usage.js +5 -12
- package/dist/application/task-usage.js.map +1 -1
- package/dist/application/tasks.js +41 -16
- package/dist/application/tasks.js.map +1 -1
- package/dist/application/tool-execution.js +42 -19
- package/dist/application/tool-execution.js.map +1 -1
- package/dist/application/workspace.js +6 -4
- package/dist/application/workspace.js.map +1 -1
- package/dist/cli/doctor-command.js +6 -2
- 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 -33
- package/dist/cli/init-authentication.js.map +1 -1
- package/dist/cli/init-command.js +3 -3
- package/dist/cli/init-command.js.map +1 -1
- package/dist/cli/main.constants.d.ts +50 -13
- package/dist/cli/main.constants.js +70 -8
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/main.js +2 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/scaffold-files.js +1 -1
- package/dist/cli/scaffold-files.js.map +1 -1
- package/dist/cli/scaffold-validation.js +29 -22
- package/dist/cli/scaffold-validation.js.map +1 -1
- package/dist/cli/scaffold.constants.d.ts +0 -1
- package/dist/cli/scaffold.constants.js +6 -2
- package/dist/cli/scaffold.constants.js.map +1 -1
- package/dist/cli/scaffold.types.d.ts +8 -2
- package/dist/cli/scaffold.types.js.map +1 -1
- package/dist/cli/starters.js +1 -3
- package/dist/cli/starters.js.map +1 -1
- package/dist/domain/agent-observation.d.ts +4 -0
- package/dist/domain/agent-observation.js +27 -0
- package/dist/domain/agent-observation.js.map +1 -0
- package/dist/domain/agent.types.d.ts +122 -14
- 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/harness.d.ts +2 -2
- package/dist/domain/harness.js +6 -0
- package/dist/domain/harness.js.map +1 -1
- package/dist/domain/harness.types.d.ts +4 -3
- package/dist/domain/harness.types.js.map +1 -1
- package/dist/domain/model.types.d.ts +8 -0
- package/dist/domain/model.types.js.map +1 -1
- package/dist/domain/observation.constants.d.ts +8 -0
- package/dist/domain/observation.constants.js +9 -0
- package/dist/domain/observation.constants.js.map +1 -0
- package/dist/domain/observation.d.ts +2 -0
- package/dist/domain/observation.js +190 -0
- package/dist/domain/observation.js.map +1 -0
- package/dist/domain/observation.types.d.ts +84 -0
- package/dist/domain/observation.types.js +2 -0
- package/dist/domain/observation.types.js.map +1 -0
- package/dist/domain/observed-operation.d.ts +2 -0
- package/dist/domain/observed-operation.js +30 -0
- package/dist/domain/observed-operation.js.map +1 -0
- package/dist/domain/sandbox.types.d.ts +2 -0
- package/dist/domain/sandbox.types.js.map +1 -1
- package/dist/domain/subagent.constants.d.ts +13 -0
- package/dist/domain/subagent.constants.js +9 -0
- package/dist/domain/subagent.constants.js.map +1 -0
- package/dist/domain/subagent.d.ts +4 -0
- package/dist/domain/subagent.js +28 -0
- package/dist/domain/subagent.js.map +1 -0
- package/dist/domain/subagent.types.d.ts +13 -0
- package/dist/domain/subagent.types.js +2 -0
- package/dist/domain/subagent.types.js.map +1 -0
- package/dist/domain/transcript.types.d.ts +2 -0
- package/dist/domain/transcript.types.js.map +1 -1
- package/dist/domain/usage.d.ts +1 -0
- package/dist/domain/usage.js +16 -0
- package/dist/domain/usage.js.map +1 -1
- package/dist/domain/workflow/budget.d.ts +7 -3
- package/dist/domain/workflow/budget.js +26 -0
- package/dist/domain/workflow/budget.js.map +1 -1
- package/dist/domain/workflow/budget.types.d.ts +1 -1
- package/dist/domain/workflow/budget.types.js.map +1 -1
- package/dist/domain/workflow/checkpoint-validation.js +7 -1
- package/dist/domain/workflow/checkpoint-validation.js.map +1 -1
- package/dist/domain/workflow/checkpoint.js +3 -0
- package/dist/domain/workflow/checkpoint.js.map +1 -1
- package/dist/domain/workflow/gate-validation.js +14 -1
- package/dist/domain/workflow/gate-validation.js.map +1 -1
- package/dist/domain/workflow/gates.d.ts +1 -1
- package/dist/domain/workflow/gates.js +52 -4
- package/dist/domain/workflow/gates.js.map +1 -1
- package/dist/domain/workflow/gates.types.d.ts +15 -1
- package/dist/domain/workflow/gates.types.js.map +1 -1
- package/dist/domain/workflow/idempotency.d.ts +1 -0
- package/dist/domain/workflow/idempotency.js +7 -0
- package/dist/domain/workflow/idempotency.js.map +1 -0
- package/dist/domain/workflow/retry.constants.d.ts +2 -0
- package/dist/domain/workflow/retry.constants.js +3 -0
- package/dist/domain/workflow/retry.constants.js.map +1 -0
- package/dist/domain/workflow/retry.d.ts +4 -0
- package/dist/domain/workflow/retry.js +49 -0
- package/dist/domain/workflow/retry.js.map +1 -0
- package/dist/domain/workflow/task-runner.js +9 -5
- package/dist/domain/workflow/task-runner.js.map +1 -1
- package/dist/domain/workflow/task.js +6 -6
- package/dist/domain/workflow/task.js.map +1 -1
- package/dist/domain/workflow/workflow-scheduler.js +110 -72
- package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
- package/dist/domain/workflow/workflow-state.js +28 -12
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.d.ts +1 -1
- package/dist/domain/workflow.js +1 -1
- package/dist/domain/workflow.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +13 -2
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/conversations/capture.js +10 -0
- package/dist/infrastructure/conversations/capture.js.map +1 -1
- package/dist/infrastructure/conversations/harness-transcript.js +6 -0
- package/dist/infrastructure/conversations/harness-transcript.js.map +1 -1
- package/dist/infrastructure/conversations/harness-transcript.types.d.ts +2 -0
- package/dist/infrastructure/conversations/harness-transcript.types.js.map +1 -1
- package/dist/infrastructure/conversations/layout.js +2 -0
- package/dist/infrastructure/conversations/layout.js.map +1 -1
- package/dist/infrastructure/conversations/locate.js +7 -1
- package/dist/infrastructure/conversations/locate.js.map +1 -1
- package/dist/infrastructure/conversations/native-store.js +8 -1
- package/dist/infrastructure/conversations/native-store.js.map +1 -1
- package/dist/infrastructure/conversations/paths.js +3 -0
- package/dist/infrastructure/conversations/paths.js.map +1 -1
- package/dist/infrastructure/conversations/restore.js +7 -0
- package/dist/infrastructure/conversations/restore.js.map +1 -1
- package/dist/infrastructure/conversations/session-bundle.constants.d.ts +5 -0
- package/dist/infrastructure/conversations/session-bundle.constants.js +173 -0
- package/dist/infrastructure/conversations/session-bundle.constants.js.map +1 -0
- package/dist/infrastructure/conversations/session-bundle.d.ts +6 -0
- package/dist/infrastructure/conversations/session-bundle.js +98 -0
- package/dist/infrastructure/conversations/session-bundle.js.map +1 -0
- package/dist/infrastructure/conversations/session-bundle.types.d.ts +1 -0
- package/dist/infrastructure/conversations/session-bundle.types.js +2 -0
- package/dist/infrastructure/conversations/session-bundle.types.js.map +1 -0
- package/dist/infrastructure/conversations.js +4 -2
- package/dist/infrastructure/conversations.js.map +1 -1
- package/dist/infrastructure/conversations.types.d.ts +1 -1
- package/dist/infrastructure/conversations.types.js.map +1 -1
- package/dist/infrastructure/custom-reporter.js +32 -24
- package/dist/infrastructure/custom-reporter.js.map +1 -1
- package/dist/infrastructure/custom-reporter.types.d.ts +2 -0
- package/dist/infrastructure/custom-reporter.types.js.map +1 -1
- package/dist/infrastructure/git/git.constants.d.ts +1 -1
- package/dist/infrastructure/git/git.constants.js +1 -0
- package/dist/infrastructure/git/git.constants.js.map +1 -1
- package/dist/infrastructure/git/workspace-lease.js +4 -3
- package/dist/infrastructure/git/workspace-lease.js.map +1 -1
- package/dist/infrastructure/git/workspace.js +7 -6
- package/dist/infrastructure/git/workspace.js.map +1 -1
- package/dist/infrastructure/git/workspace.types.d.ts +1 -0
- package/dist/infrastructure/git/workspace.types.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.js +10 -1
- package/dist/infrastructure/journal.constants.js.map +1 -1
- package/dist/infrastructure/journal.d.ts +1 -1
- package/dist/infrastructure/journal.js +8 -75
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/journal.types.d.ts +2 -4
- 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 +3 -3
- package/dist/infrastructure/opentelemetry-dispatch.js +5 -4
- package/dist/infrastructure/opentelemetry-dispatch.js.map +1 -1
- package/dist/infrastructure/opentelemetry-observation.d.ts +5 -0
- package/dist/infrastructure/opentelemetry-observation.js +59 -0
- package/dist/infrastructure/opentelemetry-observation.js.map +1 -0
- package/dist/infrastructure/opentelemetry.js +15 -1
- package/dist/infrastructure/opentelemetry.js.map +1 -1
- package/dist/infrastructure/opentelemetry.types.d.ts +9 -1
- package/dist/infrastructure/opentelemetry.types.js.map +1 -1
- package/dist/infrastructure/reporter.d.ts +2 -2
- package/dist/infrastructure/reporter.js +5 -1
- 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 +19 -24
- 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 +20 -83
- package/dist/infrastructure/resource-activity.js.map +1 -1
- package/dist/infrastructure/s3-transport.constants.d.ts +2 -0
- package/dist/infrastructure/s3-transport.constants.js +3 -0
- package/dist/infrastructure/s3-transport.constants.js.map +1 -0
- package/dist/infrastructure/s3-transport.js +57 -3
- package/dist/infrastructure/s3-transport.js.map +1 -1
- package/dist/infrastructure/s3-transport.types.d.ts +1 -0
- package/dist/infrastructure/s3-transport.types.js.map +1 -1
- package/dist/infrastructure/speculation-store.constants.d.ts +3 -0
- package/dist/infrastructure/speculation-store.constants.js +2 -0
- package/dist/infrastructure/speculation-store.constants.js.map +1 -0
- package/dist/infrastructure/speculation-store.d.ts +4 -0
- package/dist/infrastructure/speculation-store.js +73 -0
- package/dist/infrastructure/speculation-store.js.map +1 -0
- package/dist/infrastructure/speculation-store.types.d.ts +12 -0
- package/dist/infrastructure/speculation-store.types.js +2 -0
- package/dist/infrastructure/speculation-store.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/task-queue-bullmq-resources.js +3 -0
- package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -1
- package/dist/infrastructure/task-queue-http.js +29 -4
- package/dist/infrastructure/task-queue-http.js.map +1 -1
- package/dist/infrastructure/task-queue-http.types.d.ts +2 -2
- package/dist/infrastructure/task-queue-http.types.js.map +1 -1
- package/dist/infrastructure/transport-conversations.js +2 -0
- package/dist/infrastructure/transport-conversations.js.map +1 -1
- package/dist/infrastructure/transport-journal.d.ts +1 -1
- package/dist/infrastructure/transport-journal.js +8 -2
- 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/infrastructure/workflow-decision-signature.constants.d.ts +4 -0
- package/dist/infrastructure/workflow-decision-signature.constants.js +5 -0
- package/dist/infrastructure/workflow-decision-signature.constants.js.map +1 -0
- package/dist/infrastructure/workflow-decision-signature.d.ts +4 -0
- package/dist/infrastructure/workflow-decision-signature.js +83 -0
- package/dist/infrastructure/workflow-decision-signature.js.map +1 -0
- package/dist/infrastructure/workflow-decision-signature.types.d.ts +16 -0
- package/dist/infrastructure/workflow-decision-signature.types.js +2 -0
- package/dist/infrastructure/workflow-decision-signature.types.js.map +1 -0
- package/dist/providers/agents.d.ts +7 -2
- package/dist/providers/agents.js +4 -1
- package/dist/providers/agents.js.map +1 -1
- package/dist/providers/antigravity-install.constants.d.ts +2 -0
- package/dist/providers/antigravity-install.constants.js +28 -0
- package/dist/providers/antigravity-install.constants.js.map +1 -0
- package/dist/providers/antigravity-install.d.ts +2 -0
- package/dist/providers/antigravity-install.js +29 -0
- package/dist/providers/antigravity-install.js.map +1 -0
- package/dist/providers/antigravity-install.types.d.ts +4 -0
- package/dist/providers/antigravity-install.types.js +2 -0
- package/dist/providers/antigravity-install.types.js.map +1 -0
- package/dist/providers/container-recovery.d.ts +4 -0
- package/dist/providers/container-recovery.js +28 -0
- package/dist/providers/container-recovery.js.map +1 -0
- package/dist/providers/container.js +8 -0
- package/dist/providers/container.js.map +1 -1
- package/dist/providers/daytona-network.constants.d.ts +5 -0
- package/dist/providers/daytona-network.constants.js +8 -0
- package/dist/providers/daytona-network.constants.js.map +1 -0
- package/dist/providers/daytona-network.d.ts +4 -0
- package/dist/providers/daytona-network.js +33 -0
- package/dist/providers/daytona-network.js.map +1 -0
- package/dist/providers/daytona.d.ts +1 -0
- package/dist/providers/daytona.js +9 -3
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/daytona.types.d.ts +2 -0
- package/dist/providers/daytona.types.js.map +1 -1
- package/dist/providers/firecracker-command.js +1 -1
- package/dist/providers/firecracker-command.js.map +1 -1
- package/dist/providers/firecracker-jailer.constants.d.ts +9 -0
- package/dist/providers/firecracker-jailer.constants.js +10 -0
- package/dist/providers/firecracker-jailer.constants.js.map +1 -0
- package/dist/providers/firecracker-jailer.d.ts +4 -0
- package/dist/providers/firecracker-jailer.js +171 -0
- package/dist/providers/firecracker-jailer.js.map +1 -0
- package/dist/providers/firecracker-machine.js +30 -8
- package/dist/providers/firecracker-machine.js.map +1 -1
- package/dist/providers/firecracker.types.d.ts +16 -0
- package/dist/providers/firecracker.types.js.map +1 -1
- package/dist/providers/vercel-network.js +1 -1
- package/dist/providers/vercel-network.js.map +1 -1
- package/dist/providers/vercel.js +6 -3
- 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 -34
- 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.js +0 -23
- package/dist/adapters/agents/gemini-request.js.map +0 -1
- package/dist/adapters/agents/gemini.types.js +0 -2
- package/dist/adapters/agents/gemini.types.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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../src/domain/workflow/budget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAOxD,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,SAAS,
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../src/domain/workflow/budget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAA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,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CACb,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;KACpE,CAAC;AACJ,CAAC","sourcesContent":["import type { Usage } from \"../agent.types.ts\";\nimport { addUsage } from \"../usage.ts\";\nimport { usageDimensions } from \"./budget.constants.ts\";\nimport type {\n WorkflowAccounting,\n WorkflowBudget,\n WorkflowUsage,\n} from \"./budget.types.ts\";\n\nexport class WorkflowBudgetExceeded extends Error {\n readonly dimension: \"attempts\" | Exclude<keyof Usage, \"complete\">;\n readonly limit: number;\n readonly observed: number;\n constructor(\n dimension: \"attempts\" | Exclude<keyof Usage, \"complete\">,\n limit: number,\n observed: number,\n ) {\n super(\n `Workflow budget exhausted: ${dimension} limit ${limit}, observed ${observed}`,\n );\n this.name = \"WorkflowBudgetExceeded\";\n this.dimension = dimension;\n this.limit = limit;\n this.observed = observed;\n }\n}\n\nexport class WorkflowUsageUnavailable extends Error {\n readonly dimension = \"usage\";\n constructor() {\n super(\n \"Token usage is incomplete; configure budget.attempts and task timeouts or dispatch deadlines before continuing\",\n );\n this.name = \"WorkflowUsageUnavailable\";\n }\n}\n\nexport function workflowAccounting(\n budget: WorkflowBudget | undefined,\n exhaust: (error: WorkflowBudgetExceeded | WorkflowUsageUnavailable) => void,\n initial?: WorkflowUsage,\n): WorkflowAccounting {\n for (const [key, value] of Object.entries({\n attempts: budget?.attempts,\n ...budget?.usage,\n })) {\n if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))\n throw new Error(\n `Workflow budget ${key} must be a nonnegative safe integer`,\n );\n }\n let attempts = initial?.attempts ?? 0;\n let tokens: Usage = initial\n ? { ...initial.tokens }\n : { input: 0, cached: 0, output: 0 };\n let exhausted = false;\n let usageExhausted = false;\n function fail(\n dimension: \"attempts\" | Exclude<keyof Usage, \"complete\">,\n limit: number,\n observed: number,\n ): WorkflowBudgetExceeded {\n const error = new WorkflowBudgetExceeded(dimension, limit, observed);\n if (!exhausted || (dimension !== \"attempts\" && !usageExhausted)) {\n exhausted = true;\n if (dimension !== \"attempts\") usageExhausted = true;\n exhaust(error);\n }\n return error;\n }\n function checkCompleteness(): WorkflowUsageUnavailable | undefined {\n if (\n tokens.complete !== false ||\n budget?.attempts !== undefined ||\n !usageDimensions.some(\n (dimension) => budget?.usage?.[dimension] !== undefined,\n )\n )\n return;\n const error = new WorkflowUsageUnavailable();\n if (!usageExhausted) {\n exhausted = true;\n usageExhausted = true;\n exhaust(error);\n }\n return error;\n }\n return {\n get exhausted() {\n return exhausted;\n },\n admit() {\n const unavailable = checkCompleteness();\n if (unavailable) throw unavailable;\n if (budget?.attempts !== undefined && attempts >= budget.attempts)\n throw fail(\"attempts\", budget.attempts, attempts);\n for (const dimension of usageDimensions) {\n const limit = budget?.usage?.[dimension];\n if (limit !== undefined && (tokens[dimension] ?? 0) >= limit)\n throw fail(dimension, limit, tokens[dimension] ?? 0);\n }\n attempts++;\n },\n report(usage) {\n if (usage.complete !== undefined && typeof usage.complete !== \"boolean\")\n throw new Error(\"Reported usage complete must be a boolean\");\n for (const dimension of usageDimensions) {\n const value = usage[dimension] ?? 0;\n if (!Number.isSafeInteger(value) || value < 0)\n throw new Error(\n `Reported usage ${dimension} must be a nonnegative safe integer`,\n );\n }\n tokens = addUsage(tokens, usage);\n checkCompleteness();\n for (const dimension of usageDimensions) {\n const limit = budget?.usage?.[dimension];\n if (limit !== undefined && (tokens[dimension] ?? 0) >= limit)\n fail(dimension, limit, tokens[dimension] ?? 0);\n }\n },\n snapshot: () =>\n Object.freeze({ attempts, tokens: Object.freeze({ ...tokens }) }),\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Usage } from "../agent.types.ts";
|
|
2
2
|
export interface WorkflowBudget {
|
|
3
3
|
readonly attempts?: number;
|
|
4
|
-
readonly usage?: Partial<Usage
|
|
4
|
+
readonly usage?: Partial<Omit<Usage, "complete">>;
|
|
5
5
|
}
|
|
6
6
|
export interface WorkflowUsage {
|
|
7
7
|
readonly attempts: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget.types.js","sourceRoot":"","sources":["../../../src/domain/workflow/budget.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Usage } from \"../agent.types.ts\";\n\nexport interface WorkflowBudget {\n readonly attempts?: number;\n readonly usage?: Partial<Usage
|
|
1
|
+
{"version":3,"file":"budget.types.js","sourceRoot":"","sources":["../../../src/domain/workflow/budget.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Usage } from \"../agent.types.ts\";\n\nexport interface WorkflowBudget {\n readonly attempts?: number;\n readonly usage?: Partial<Omit<Usage, \"complete\">>;\n}\n\nexport interface WorkflowUsage {\n readonly attempts: number;\n readonly tokens: Usage;\n}\n\nexport interface WorkflowAccounting {\n readonly exhausted: boolean;\n admit(): void;\n report(usage: Usage): void;\n snapshot(): WorkflowUsage;\n}\n"]}
|
|
@@ -23,9 +23,15 @@ export function validateCheckpoint(value, identity, tasks) {
|
|
|
23
23
|
for (const dimension of ["input", "cached", "output"])
|
|
24
24
|
if (!integer(value.usage.tokens[dimension]))
|
|
25
25
|
throw invalid();
|
|
26
|
-
for (const count of Object.
|
|
26
|
+
for (const [dimension, count] of Object.entries(value.usage.tokens)) {
|
|
27
|
+
if (dimension === "complete") {
|
|
28
|
+
if (typeof count !== "boolean")
|
|
29
|
+
throw invalid();
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
27
32
|
if (!integer(count))
|
|
28
33
|
throw invalid();
|
|
34
|
+
}
|
|
29
35
|
if (value.records.length !== tasks.length)
|
|
30
36
|
throw invalid();
|
|
31
37
|
const keys = new Set(tasks.map((item) => item.key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkp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.ts\";\nimport type { WorkflowCheckpoint } from \"./checkpoint.types.ts\";\nimport type { Task } from \"../workflow.types.ts\";\nimport { checkpointValue } from \"./checkpoint-value.ts\";\n\nfunction object(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\nfunction integer(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nexport function validateCheckpoint(\n value: unknown,\n identity: string,\n tasks: readonly Task[],\n): asserts value is WorkflowCheckpoint {\n const invalid = () =>\n new Error(\"Invalid or incompatible workflow checkpoint\");\n if (\n !object(value) ||\n value.format !== 1 ||\n value.identity !== identity ||\n typeof value.executionId !== \"string\" ||\n !value.executionId ||\n !Array.isArray(value.records) ||\n !object(value.values) ||\n !object(value.usage)\n )\n throw invalid();\n if (!integer(value.usage.attempts) || !object(value.usage.tokens))\n throw invalid();\n for (const dimension of [\"input\", \"cached\", \"output\"])\n if (!integer(value.usage.tokens[dimension])) throw invalid();\n for (const [dimension, count] of Object.entries(value.usage.tokens)) {\n if (dimension === \"complete\") {\n if (typeof count !== \"boolean\") throw invalid();\n continue;\n }\n if (!integer(count)) throw invalid();\n }\n if (value.records.length !== tasks.length) throw invalid();\n const keys = new Set(tasks.map((item) => item.key));\n let attempts = 0;\n for (const record of value.records) {\n if (\n !object(record) ||\n typeof record.key !== \"string\" ||\n !keys.delete(record.key) ||\n !integer(record.attempts) ||\n ![\n \"waiting\",\n \"active\",\n \"done\",\n \"failed\",\n \"skipped\",\n \"cancelled\",\n \"paused\",\n \"rejected\",\n ].includes(String(record.status))\n )\n throw invalid();\n for (const field of [\"startedAt\", \"finishedAt\", \"error\"])\n if (record[field] !== undefined && typeof record[field] !== \"string\")\n throw invalid();\n validateUsageReceipts(record.usageReceipts);\n attempts += record.attempts;\n const output = Object.hasOwn(value.values, record.key)\n ? value.values[record.key]\n : undefined;\n validateGateRecord(\n record,\n tasks.find((item) => item.key === record.key)!,\n value.executionId,\n output,\n );\n if (record.status !== \"done\") {\n if (output !== undefined) throw invalid();\n continue;\n }\n if (!object(output) || ![\"undefined\", \"json\"].includes(String(output.kind)))\n throw invalid();\n if (output.kind === \"json\") {\n if (!Object.hasOwn(output, \"value\") || output.value === undefined)\n throw invalid();\n checkpointValue(output.value);\n }\n }\n if (attempts !== value.usage.attempts) throw invalid();\n if (\n Object.keys(value.values).some(\n (key) => !tasks.some((item) => item.key === key),\n )\n )\n throw invalid();\n const records = new Map(value.records.map((entry) => [entry.key, entry]));\n for (const item of tasks)\n if (\n [\"done\", \"paused\", \"rejected\"].includes(\n String(records.get(item.key)?.status),\n ) &&\n item.after.some(\n (dependency) => records.get(dependency.key)?.status !== \"done\",\n )\n )\n throw invalid();\n}\n"]}
|
|
@@ -12,6 +12,9 @@ export async function openCheckpoint(name, tasks, options) {
|
|
|
12
12
|
timeoutMs: item.timeoutMs,
|
|
13
13
|
retry: item.retry?.attempts,
|
|
14
14
|
delayMs: item.retry?.delayMs,
|
|
15
|
+
backoff: item.retry?.backoff,
|
|
16
|
+
maxDelayMs: item.retry?.maxDelayMs,
|
|
17
|
+
jitter: item.retry?.jitter,
|
|
15
18
|
condition: !!item.condition,
|
|
16
19
|
accepts: !!item.retry?.accepts,
|
|
17
20
|
}))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../../src/domain/workflow/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,KAAsB,EACtB,OAAkC;IAElC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE;QAClD,MAAM,I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,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;wBACvC,IAAI,CAAC,GAAG;wBACR,eAAe,CAAC,KAAK,CAAC;qBACvB,CAAC,CACH;oBACD,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE;iBACnC,CAAC;gBACF,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAClD,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,KAAK,CAAC,OAAO;gBACX,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBAC7B,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Task, WorkflowExecutionState } from \"../workflow.types.ts\";\nimport type {\n WorkflowCheckpoint,\n WorkflowCheckpointOptions,\n WorkflowCheckpointSession,\n} from \"./checkpoint.types.ts\";\nimport { checkpointValue } from \"./checkpoint-value.ts\";\nimport { validateCheckpoint } from \"./checkpoint-validation.ts\";\n\nexport async function openCheckpoint(\n name: string,\n tasks: readonly Task[],\n options: WorkflowCheckpointOptions,\n): Promise<WorkflowCheckpointSession> {\n if (!options.runId.trim() || !options.version.trim())\n throw new Error(\"Checkpoint runId and version must not be empty\");\n const graph = tasks\n .map((item) => ({\n key: item.key,\n ...(item.gate ? { gate: item.gate } : {}),\n after: item.after.map((dependency) => dependency.key).sort(),\n timeoutMs: item.timeoutMs,\n retry: item.retry?.attempts,\n delayMs: item.retry?.delayMs,\n condition: !!item.condition,\n accepts: !!item.retry?.accepts,\n }))\n .sort((a, b) => {\n if (a.key === b.key) return 0;\n return a.key < b.key ? -1 : 1;\n });\n const identity = createHash(\"sha256\")\n .update(JSON.stringify({ name, version: options.version, graph }))\n .digest(\"hex\");\n const lease = await options.store.acquire(options.runId);\n try {\n const saved = await lease.read();\n let initial: WorkflowCheckpoint | undefined;\n if (saved !== undefined) {\n validateCheckpoint(saved, identity, tasks);\n initial = saved;\n const settledGate = saved.records.some((record) =>\n [\"paused\", \"rejected\"].includes(record.status),\n );\n if (\n saved.records.some(\n (record) =>\n ![\"done\", \"skipped\", \"paused\", \"rejected\"].includes(\n record.status,\n ) &&\n !(\n settledGate &&\n record.status === \"waiting\" &&\n record.attempts === 0\n ),\n ) &&\n options.resume !== \"retry-incomplete\"\n )\n throw new Error(\n \"Incomplete workflow checkpoint: resume retry-incomplete must explicitly authorize replay\",\n );\n }\n let writes = Promise.resolve();\n return {\n initial,\n save(state: WorkflowExecutionState) {\n const snapshot: WorkflowCheckpoint = {\n format: 1,\n identity,\n executionId: state.executionId,\n records: [...state.records.values()].map((record) => ({ ...record })),\n values: Object.fromEntries(\n [...state.values].map(([item, value]) => [\n item.key,\n checkpointValue(value),\n ]),\n ),\n usage: state.accounting.snapshot(),\n };\n writes = writes.then(() => lease.write(snapshot));\n return writes;\n },\n async release() {\n await writes.catch(() => {});\n await lease.release();\n },\n };\n } catch (error) {\n await lease.release();\n throw error;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../../src/domain/workflow/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,KAAsB,EACtB,OAAkC;IAElC,IAAI,CAAC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;oBACR,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;oBACrE,MAAM,EAAE,MAAM,CAAC,WAAW,CACxB,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;wBACvC,IAAI,CAAC,GAAG;wBACR,eAAe,CAAC,KAAK,CAAC;qBACvB,CAAC,CACH;oBACD,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE;iBACnC,CAAC;gBACF,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAClD,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,KAAK,CAAC,OAAO;gBACX,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBAC7B,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Task, WorkflowExecutionState } from \"../workflow.types.ts\";\nimport type {\n WorkflowCheckpoint,\n WorkflowCheckpointOptions,\n WorkflowCheckpointSession,\n} from \"./checkpoint.types.ts\";\nimport { checkpointValue } from \"./checkpoint-value.ts\";\nimport { validateCheckpoint } from \"./checkpoint-validation.ts\";\n\nexport async function openCheckpoint(\n name: string,\n tasks: readonly Task[],\n options: WorkflowCheckpointOptions,\n): Promise<WorkflowCheckpointSession> {\n if (!options.runId.trim() || !options.version.trim())\n throw new Error(\"Checkpoint runId and version must not be empty\");\n const graph = tasks\n .map((item) => ({\n key: item.key,\n ...(item.gate ? { gate: item.gate } : {}),\n after: item.after.map((dependency) => dependency.key).sort(),\n timeoutMs: item.timeoutMs,\n retry: item.retry?.attempts,\n delayMs: item.retry?.delayMs,\n backoff: item.retry?.backoff,\n maxDelayMs: item.retry?.maxDelayMs,\n jitter: item.retry?.jitter,\n condition: !!item.condition,\n accepts: !!item.retry?.accepts,\n }))\n .sort((a, b) => {\n if (a.key === b.key) return 0;\n return a.key < b.key ? -1 : 1;\n });\n const identity = createHash(\"sha256\")\n .update(JSON.stringify({ name, version: options.version, graph }))\n .digest(\"hex\");\n const lease = await options.store.acquire(options.runId);\n try {\n const saved = await lease.read();\n let initial: WorkflowCheckpoint | undefined;\n if (saved !== undefined) {\n validateCheckpoint(saved, identity, tasks);\n initial = saved;\n const settledGate = saved.records.some((record) =>\n [\"paused\", \"rejected\"].includes(record.status),\n );\n if (\n saved.records.some(\n (record) =>\n ![\"done\", \"skipped\", \"paused\", \"rejected\"].includes(\n record.status,\n ) &&\n !(\n settledGate &&\n record.status === \"waiting\" &&\n record.attempts === 0\n ),\n ) &&\n options.resume !== \"retry-incomplete\"\n )\n throw new Error(\n \"Incomplete workflow checkpoint: resume retry-incomplete must explicitly authorize replay\",\n );\n }\n let writes = Promise.resolve();\n return {\n initial,\n save(state: WorkflowExecutionState) {\n const snapshot: WorkflowCheckpoint = {\n format: 1,\n identity,\n executionId: state.executionId,\n records: [...state.records.values()].map((record) => ({ ...record })),\n values: Object.fromEntries(\n [...state.values].map(([item, value]) => [\n item.key,\n checkpointValue(value),\n ]),\n ),\n usage: state.accounting.snapshot(),\n };\n writes = writes.then(() => lease.write(snapshot));\n return writes;\n },\n async release() {\n await writes.catch(() => {});\n await lease.release();\n },\n };\n } catch (error) {\n await lease.release();\n throw error;\n }\n}\n"]}
|
|
@@ -3,6 +3,8 @@ function object(value) {
|
|
|
3
3
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
4
|
}
|
|
5
5
|
export function validateGate(gate) {
|
|
6
|
+
if (gate.authentication !== undefined && gate.authentication !== "signed")
|
|
7
|
+
throw new Error("Invalid gate authentication policy");
|
|
6
8
|
if (!["approval", "pause"].includes(gate.kind))
|
|
7
9
|
throw new Error("Invalid workflow gate kind");
|
|
8
10
|
if (!gate.prompt.trim())
|
|
@@ -38,6 +40,7 @@ export function validateGateRecord(record, item, executionId, output) {
|
|
|
38
40
|
!request.id.trim() ||
|
|
39
41
|
typeof request.requestedAt !== "string" ||
|
|
40
42
|
!Number.isFinite(Date.parse(request.requestedAt)) ||
|
|
43
|
+
request.authentication !== gate.authentication ||
|
|
41
44
|
request.kind !== gate.kind ||
|
|
42
45
|
request.prompt !== gate.prompt ||
|
|
43
46
|
JSON.stringify(request.actors) !== JSON.stringify(gate.actors))
|
|
@@ -60,12 +63,22 @@ export function validateGateRecord(record, item, executionId, output) {
|
|
|
60
63
|
typeof decision.decidedAt !== "string" ||
|
|
61
64
|
!Number.isFinite(Date.parse(decision.decidedAt)))
|
|
62
65
|
throw invalid();
|
|
66
|
+
const verification = decision.verification;
|
|
67
|
+
if (gate.authentication === "signed" || verification !== undefined) {
|
|
68
|
+
if (!object(verification) ||
|
|
69
|
+
typeof verification.keyId !== "string" ||
|
|
70
|
+
!verification.keyId.trim() ||
|
|
71
|
+
typeof verification.verifiedAt !== "string" ||
|
|
72
|
+
!Number.isFinite(Date.parse(verification.verifiedAt)))
|
|
73
|
+
throw invalid();
|
|
74
|
+
}
|
|
63
75
|
if (record.status === "done" &&
|
|
64
76
|
(!object(output) ||
|
|
65
77
|
output.kind !== "json" ||
|
|
66
78
|
!object(output.value) ||
|
|
67
79
|
Object.keys(output.value).length !== Object.keys(decision).length ||
|
|
68
|
-
!Object.entries(decision).every(([key, value]) => object(output.value) &&
|
|
80
|
+
!Object.entries(decision).every(([key, value]) => object(output.value) &&
|
|
81
|
+
JSON.stringify(output.value[key]) === JSON.stringify(value))))
|
|
69
82
|
throw invalid();
|
|
70
83
|
}
|
|
71
84
|
//# sourceMappingURL=gate-validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate-validation.js","sourceRoot":"","sources":["../../../src/domain/workflow/gate-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAkB;IAC7C,IAAI,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACxE,IACE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;QACnB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM;QAEhD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,MAA+B,EAC/B,IAAU,EACV,WAAmB,EACnB,MAAe;IAEf,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAG,IAAI,CAAC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AAC,MAAM,CAAC,YAAY,CAAC;YACrB,OAAO,YAAY,CAAC,KAAK,KAAK,QAAQ;YACtC,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE;YAC1B,OAAO,YAAY,CAAC,UAAU,KAAK,QAAQ;YAC3C,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;YAErD,MAAM,OAAO,EAAE,CAAC;IACpB,CAAC;IACD,IACE,MAAM,CAAC,MAAM,KAAK,MAAM;QACxB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;YACd,MAAM,CAAC,IAAI,KAAK,MAAM;YACtB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;YACrB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM;YACjE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAC7B,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACf,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;gBACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAC9D,CAAC;QAEJ,MAAM,OAAO,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import { gateActions } from \"./gates.constants.ts\";\nimport type { Task } from \"../workflow.types.ts\";\nimport type { WorkflowGate } from \"./gates.types.ts\";\n\nfunction object(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function validateGate(gate: WorkflowGate): void {\n if (gate.authentication !== undefined && gate.authentication !== \"signed\")\n throw new Error(\"Invalid gate authentication policy\");\n if (![\"approval\", \"pause\"].includes(gate.kind))\n throw new Error(\"Invalid workflow gate kind\");\n if (!gate.prompt.trim()) throw new Error(\"Gate prompt cannot be empty\");\n if (\n !gate.actors.length ||\n gate.actors.some((actor) => !actor.trim()) ||\n new Set(gate.actors).size !== gate.actors.length\n )\n throw new Error(\"Gate actors must be nonempty and unique\");\n}\n\nexport function validateGateRecord(\n record: Record<string, unknown>,\n item: Task,\n executionId: string,\n output: unknown,\n): void {\n const invalid = () => new Error(\"Invalid workflow checkpoint gate record\");\n const gate = item.gate;\n const request = record.pause;\n const decision = record.decision;\n if (!gate) {\n if (\n request !== undefined ||\n decision !== undefined ||\n [\"paused\", \"rejected\"].includes(String(record.status))\n )\n throw invalid();\n return;\n }\n if (record.attempts !== 0) throw invalid();\n if (![\"paused\", \"done\", \"rejected\"].includes(String(record.status))) {\n if (\n ![\"waiting\", \"skipped\", \"cancelled\"].includes(String(record.status)) ||\n request !== undefined ||\n decision !== undefined\n )\n throw invalid();\n return;\n }\n if (\n !object(request) ||\n typeof request.id !== \"string\" ||\n !request.id.trim() ||\n typeof request.requestedAt !== \"string\" ||\n !Number.isFinite(Date.parse(request.requestedAt)) ||\n request.authentication !== gate.authentication ||\n request.kind !== gate.kind ||\n request.prompt !== gate.prompt ||\n JSON.stringify(request.actors) !== JSON.stringify(gate.actors)\n )\n throw invalid();\n if (record.status === \"paused\") {\n if (decision !== undefined) throw invalid();\n return;\n }\n const action =\n record.status === \"rejected\" ? \"reject\" : gateActions[gate.kind];\n if (\n !object(decision) ||\n decision.executionId !== executionId ||\n decision.key !== item.key ||\n decision.requestId !== request.id ||\n decision.action !== action ||\n typeof decision.actor !== \"string\" ||\n !gate.actors.includes(decision.actor) ||\n typeof decision.reason !== \"string\" ||\n !decision.reason.trim() ||\n typeof decision.decidedAt !== \"string\" ||\n !Number.isFinite(Date.parse(decision.decidedAt))\n )\n throw invalid();\n const verification = decision.verification;\n if (gate.authentication === \"signed\" || verification !== undefined) {\n if (\n !object(verification) ||\n typeof verification.keyId !== \"string\" ||\n !verification.keyId.trim() ||\n typeof verification.verifiedAt !== \"string\" ||\n !Number.isFinite(Date.parse(verification.verifiedAt))\n )\n throw invalid();\n }\n if (\n record.status === \"done\" &&\n (!object(output) ||\n output.kind !== \"json\" ||\n !object(output.value) ||\n Object.keys(output.value).length !== Object.keys(decision).length ||\n !Object.entries(decision).every(\n ([key, value]) =>\n object(output.value) &&\n JSON.stringify(output.value[key]) === JSON.stringify(value),\n ))\n )\n throw invalid();\n}\n"]}
|
|
@@ -3,5 +3,5 @@ import type { WorkflowDecisionRecord, WorkflowGateOptions } from "./gates.types.
|
|
|
3
3
|
export declare function approvalTask(options: WorkflowGateOptions): Task<WorkflowDecisionRecord>;
|
|
4
4
|
export declare function pauseTask(options: WorkflowGateOptions): Task<WorkflowDecisionRecord>;
|
|
5
5
|
export declare function pauseGate(item: Task, runtime: WorkflowExecutionState): Promise<void>;
|
|
6
|
-
export declare function prepareDecisions(runtime: WorkflowExecutionState): readonly WorkflowDecisionRecord[]
|
|
6
|
+
export declare function prepareDecisions(runtime: WorkflowExecutionState): Promise<readonly WorkflowDecisionRecord[]>;
|
|
7
7
|
export declare function applyDecisions(runtime: WorkflowExecutionState, decisions: readonly WorkflowDecisionRecord[]): void;
|
|
@@ -3,11 +3,21 @@ import { task } from "./task.js";
|
|
|
3
3
|
import { gateActions } from "./gates.constants.js";
|
|
4
4
|
import { validateGate } from "./gate-validation.js";
|
|
5
5
|
function gateTask(kind, options) {
|
|
6
|
-
validateGate({
|
|
6
|
+
validateGate({
|
|
7
|
+
kind,
|
|
8
|
+
prompt: options.prompt,
|
|
9
|
+
actors: options.actors,
|
|
10
|
+
...(options.authentication !== undefined
|
|
11
|
+
? { authentication: options.authentication }
|
|
12
|
+
: {}),
|
|
13
|
+
});
|
|
7
14
|
return task({
|
|
8
15
|
key: options.key,
|
|
9
16
|
after: options.after ?? [],
|
|
10
17
|
gate: Object.freeze({
|
|
18
|
+
...(options.authentication !== undefined
|
|
19
|
+
? { authentication: options.authentication }
|
|
20
|
+
: {}),
|
|
11
21
|
kind,
|
|
12
22
|
prompt: options.prompt,
|
|
13
23
|
actors: Object.freeze([...options.actors]),
|
|
@@ -30,11 +40,18 @@ export async function pauseGate(item, runtime) {
|
|
|
30
40
|
id: randomUUID(),
|
|
31
41
|
requestedAt: new Date().toISOString(),
|
|
32
42
|
});
|
|
43
|
+
runtime.emit({ type: "gate", key: item.key, status: "paused" });
|
|
33
44
|
runtime.finish(item, "paused");
|
|
34
45
|
await runtime.persist();
|
|
35
46
|
}
|
|
36
|
-
export function prepareDecisions(runtime) {
|
|
37
|
-
const
|
|
47
|
+
export async function prepareDecisions(runtime) {
|
|
48
|
+
const inputs = (runtime.options.decisions ?? []).map((decision) => Object.freeze({
|
|
49
|
+
...decision,
|
|
50
|
+
...(decision.proof
|
|
51
|
+
? { proof: Object.freeze({ ...decision.proof }) }
|
|
52
|
+
: {}),
|
|
53
|
+
}));
|
|
54
|
+
const decisions = inputs.map((decision) => Object.freeze({
|
|
38
55
|
executionId: decision.executionId,
|
|
39
56
|
key: decision.key,
|
|
40
57
|
requestId: decision.requestId,
|
|
@@ -64,7 +81,33 @@ export function prepareDecisions(runtime) {
|
|
|
64
81
|
throw new Error(`Invalid or unauthorized workflow decision: ${decision.key}`);
|
|
65
82
|
seen.add(decision.key);
|
|
66
83
|
}
|
|
67
|
-
|
|
84
|
+
const verified = [];
|
|
85
|
+
for (const [index, decision] of decisions.entries()) {
|
|
86
|
+
const input = inputs[index];
|
|
87
|
+
const signed = pending.get(decision.key).gate.authentication === "signed";
|
|
88
|
+
if (!signed && !input.proof) {
|
|
89
|
+
verified.push(decision);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!input.proof || !runtime.options.decisionVerifier)
|
|
93
|
+
throw new Error(`Signed workflow decision required: ${decision.key}`);
|
|
94
|
+
const verification = await runtime.options.decisionVerifier(input);
|
|
95
|
+
if (!verification ||
|
|
96
|
+
typeof verification.keyId !== "string" ||
|
|
97
|
+
!verification.keyId.trim() ||
|
|
98
|
+
verification.keyId !== input.proof.keyId ||
|
|
99
|
+
typeof verification.verifiedAt !== "string" ||
|
|
100
|
+
!Number.isFinite(Date.parse(verification.verifiedAt)))
|
|
101
|
+
throw new Error("Invalid workflow decision verification");
|
|
102
|
+
verified.push(Object.freeze({
|
|
103
|
+
...decision,
|
|
104
|
+
verification: Object.freeze({
|
|
105
|
+
keyId: verification.keyId,
|
|
106
|
+
verifiedAt: verification.verifiedAt,
|
|
107
|
+
}),
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
return verified;
|
|
68
111
|
}
|
|
69
112
|
export function applyDecisions(runtime, decisions) {
|
|
70
113
|
const pending = new Map([...runtime.records.keys()].map((item) => [item.key, item]));
|
|
@@ -72,6 +115,11 @@ export function applyDecisions(runtime, decisions) {
|
|
|
72
115
|
const item = pending.get(decision.key);
|
|
73
116
|
const record = runtime.record(item);
|
|
74
117
|
record.decision = decision;
|
|
118
|
+
runtime.emit({
|
|
119
|
+
type: "decision",
|
|
120
|
+
key: item.key,
|
|
121
|
+
status: decision.action === "reject" ? "rejected" : "done",
|
|
122
|
+
});
|
|
75
123
|
if (decision.action === "reject") {
|
|
76
124
|
record.error = `${item.key} rejected by ${decision.actor}: ${decision.reason}`;
|
|
77
125
|
runtime.errors.push(new Error(record.error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gates.js","sourceRoot":"","sources":["../../../src/domain/workflow/gates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,SAAS,QAAQ,CACf,IAA0B,EAC1B,OAA4B;IAE5B,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,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C;QACD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Task, WorkflowExecutionState } from \"../workflow.types.ts\";\nimport type {\n WorkflowDecisionRecord,\n WorkflowGate,\n WorkflowGateOptions,\n} from \"./gates.types.ts\";\nimport { task } from \"./task.ts\";\nimport { gateActions } from \"./gates.constants.ts\";\nimport { validateGate } from \"./gate-validation.ts\";\n\nfunction gateTask(\n kind: WorkflowGate[\"kind\"],\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n validateGate({ kind, prompt: options.prompt, actors: options.actors });\n return task({\n key: options.key,\n after: options.after ?? [],\n gate: Object.freeze({\n kind,\n prompt: options.prompt,\n actors: Object.freeze([...options.actors]),\n }),\n perform() {\n throw new Error(\"Workflow gates must be scheduled with a checkpoint\");\n },\n });\n}\n\nexport function approvalTask(\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n return gateTask(\"approval\", options);\n}\n\nexport function pauseTask(\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n return gateTask(\"pause\", options);\n}\n\nexport async function pauseGate(\n item: Task,\n runtime: WorkflowExecutionState,\n): Promise<void> {\n const gate = item.gate!;\n runtime.record(item).pause = Object.freeze({\n ...gate,\n id: randomUUID(),\n requestedAt: new Date().toISOString(),\n });\n runtime.finish(item, \"paused\");\n await runtime.persist();\n}\n\nexport function prepareDecisions(\n runtime: WorkflowExecutionState,\n): readonly WorkflowDecisionRecord[] {\n const decisions = (runtime.options.decisions ?? []).map((decision) =>\n Object.freeze({\n executionId: decision.executionId,\n key: decision.key,\n requestId: decision.requestId,\n action: decision.action,\n actor: decision.actor,\n reason: decision.reason,\n decidedAt: new Date().toISOString(),\n }),\n );\n const pending = new Map(\n [...runtime.records.keys()].map((item) => [item.key, item]),\n );\n const seen = new Set<string>();\n for (const decision of decisions) {\n const item = pending.get(decision.key);\n const record = item && runtime.record(item);\n const request = record?.pause;\n if (\n !record ||\n !request ||\n record.status !== \"paused\" ||\n record.decision ||\n decision.executionId !== runtime.executionId ||\n decision.requestId !== request.id ||\n seen.has(decision.key) ||\n typeof decision.actor !== \"string\" ||\n !request.actors.includes(decision.actor) ||\n typeof decision.reason !== \"string\" ||\n !decision.reason.trim() ||\n ![gateActions[request.kind], \"reject\"].includes(decision.action)\n )\n throw new Error(\n `Invalid or unauthorized workflow decision: ${decision.key}`,\n );\n seen.add(decision.key);\n }\n return decisions;\n}\n\nexport function applyDecisions(\n runtime: WorkflowExecutionState,\n decisions: readonly WorkflowDecisionRecord[],\n): void {\n const pending = new Map(\n [...runtime.records.keys()].map((item) => [item.key, item]),\n );\n for (const decision of decisions) {\n const item = pending.get(decision.key)!;\n const record = runtime.record(item);\n record.decision = decision;\n if (decision.action === \"reject\") {\n record.error = `${item.key} rejected by ${decision.actor}: ${decision.reason}`;\n runtime.errors.push(new Error(record.error));\n runtime.finish(item, \"rejected\");\n continue;\n }\n runtime.values.set(item, decision);\n runtime.finish(item, \"done\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gates.js","sourceRoot":"","sources":["../../../src/domain/workflow/gates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,SAAS,QAAQ,CACf,IAA0B,EAC1B,OAA4B;IAE5B,YAAY,CAAC;QACX,IAAI;QACJ,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,CAAC,OAAO,CAAC,cAAc,KAAK,SAA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C,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAC5D,CAAC;IACF,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAE,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,UAAU;YAChB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,MAAM,EAAE,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM;SAC3D,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACjC,MAAM,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,GAAG,gBAAgB,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC/E,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YACjC,SAAS;QACX,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACnC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Task, WorkflowExecutionState } from \"../workflow.types.ts\";\nimport type {\n WorkflowDecisionRecord,\n WorkflowGate,\n WorkflowGateOptions,\n} from \"./gates.types.ts\";\nimport { task } from \"./task.ts\";\nimport { gateActions } from \"./gates.constants.ts\";\nimport { validateGate } from \"./gate-validation.ts\";\n\nfunction gateTask(\n kind: WorkflowGate[\"kind\"],\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n validateGate({\n kind,\n prompt: options.prompt,\n actors: options.actors,\n ...(options.authentication !== undefined\n ? { authentication: options.authentication }\n : {}),\n });\n return task({\n key: options.key,\n after: options.after ?? [],\n gate: Object.freeze({\n ...(options.authentication !== undefined\n ? { authentication: options.authentication }\n : {}),\n kind,\n prompt: options.prompt,\n actors: Object.freeze([...options.actors]),\n }),\n perform() {\n throw new Error(\"Workflow gates must be scheduled with a checkpoint\");\n },\n });\n}\n\nexport function approvalTask(\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n return gateTask(\"approval\", options);\n}\n\nexport function pauseTask(\n options: WorkflowGateOptions,\n): Task<WorkflowDecisionRecord> {\n return gateTask(\"pause\", options);\n}\n\nexport async function pauseGate(\n item: Task,\n runtime: WorkflowExecutionState,\n): Promise<void> {\n const gate = item.gate!;\n runtime.record(item).pause = Object.freeze({\n ...gate,\n id: randomUUID(),\n requestedAt: new Date().toISOString(),\n });\n runtime.emit({ type: \"gate\", key: item.key, status: \"paused\" });\n runtime.finish(item, \"paused\");\n await runtime.persist();\n}\n\nexport async function prepareDecisions(\n runtime: WorkflowExecutionState,\n): Promise<readonly WorkflowDecisionRecord[]> {\n const inputs = (runtime.options.decisions ?? []).map((decision) =>\n Object.freeze({\n ...decision,\n ...(decision.proof\n ? { proof: Object.freeze({ ...decision.proof }) }\n : {}),\n }),\n );\n const decisions = inputs.map((decision) =>\n Object.freeze({\n executionId: decision.executionId,\n key: decision.key,\n requestId: decision.requestId,\n action: decision.action,\n actor: decision.actor,\n reason: decision.reason,\n decidedAt: new Date().toISOString(),\n }),\n );\n const pending = new Map(\n [...runtime.records.keys()].map((item) => [item.key, item]),\n );\n const seen = new Set<string>();\n for (const decision of decisions) {\n const item = pending.get(decision.key);\n const record = item && runtime.record(item);\n const request = record?.pause;\n if (\n !record ||\n !request ||\n record.status !== \"paused\" ||\n record.decision ||\n decision.executionId !== runtime.executionId ||\n decision.requestId !== request.id ||\n seen.has(decision.key) ||\n typeof decision.actor !== \"string\" ||\n !request.actors.includes(decision.actor) ||\n typeof decision.reason !== \"string\" ||\n !decision.reason.trim() ||\n ![gateActions[request.kind], \"reject\"].includes(decision.action)\n )\n throw new Error(\n `Invalid or unauthorized workflow decision: ${decision.key}`,\n );\n seen.add(decision.key);\n }\n const verified: WorkflowDecisionRecord[] = [];\n for (const [index, decision] of decisions.entries()) {\n const input = inputs[index]!;\n const signed = pending.get(decision.key)!.gate!.authentication === \"signed\";\n if (!signed && !input.proof) {\n verified.push(decision);\n continue;\n }\n if (!input.proof || !runtime.options.decisionVerifier)\n throw new Error(`Signed workflow decision required: ${decision.key}`);\n const verification = await runtime.options.decisionVerifier(input);\n if (\n !verification ||\n typeof verification.keyId !== \"string\" ||\n !verification.keyId.trim() ||\n verification.keyId !== input.proof.keyId ||\n typeof verification.verifiedAt !== \"string\" ||\n !Number.isFinite(Date.parse(verification.verifiedAt))\n )\n throw new Error(\"Invalid workflow decision verification\");\n verified.push(\n Object.freeze({\n ...decision,\n verification: Object.freeze({\n keyId: verification.keyId,\n verifiedAt: verification.verifiedAt,\n }),\n }),\n );\n }\n return verified;\n}\n\nexport function applyDecisions(\n runtime: WorkflowExecutionState,\n decisions: readonly WorkflowDecisionRecord[],\n): void {\n const pending = new Map(\n [...runtime.records.keys()].map((item) => [item.key, item]),\n );\n for (const decision of decisions) {\n const item = pending.get(decision.key)!;\n const record = runtime.record(item);\n record.decision = decision;\n runtime.emit({\n type: \"decision\",\n key: item.key,\n status: decision.action === \"reject\" ? \"rejected\" : \"done\",\n });\n if (decision.action === \"reject\") {\n record.error = `${item.key} rejected by ${decision.actor}: ${decision.reason}`;\n runtime.errors.push(new Error(record.error));\n runtime.finish(item, \"rejected\");\n continue;\n }\n runtime.values.set(item, decision);\n runtime.finish(item, \"done\");\n }\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Task } from "../workflow.types.ts";
|
|
2
2
|
export interface WorkflowGate {
|
|
3
|
+
readonly authentication?: "signed";
|
|
3
4
|
readonly kind: "approval" | "pause";
|
|
4
5
|
readonly prompt: string;
|
|
5
6
|
readonly actors: readonly string[];
|
|
6
7
|
}
|
|
7
8
|
export interface WorkflowGateOptions {
|
|
9
|
+
readonly authentication?: "signed";
|
|
8
10
|
readonly key: string;
|
|
9
11
|
readonly after?: readonly Task[];
|
|
10
12
|
readonly prompt: string;
|
|
@@ -15,6 +17,7 @@ export interface WorkflowPauseRequest extends WorkflowGate {
|
|
|
15
17
|
readonly requestedAt: string;
|
|
16
18
|
}
|
|
17
19
|
export interface WorkflowDecision {
|
|
20
|
+
readonly proof?: WorkflowDecisionProof;
|
|
18
21
|
readonly executionId: string;
|
|
19
22
|
readonly key: string;
|
|
20
23
|
readonly requestId: string;
|
|
@@ -22,6 +25,17 @@ export interface WorkflowDecision {
|
|
|
22
25
|
readonly actor: string;
|
|
23
26
|
readonly reason: string;
|
|
24
27
|
}
|
|
25
|
-
export interface
|
|
28
|
+
export interface WorkflowDecisionProof {
|
|
29
|
+
readonly keyId: string;
|
|
30
|
+
readonly expiresAt: string;
|
|
31
|
+
readonly signature: string;
|
|
32
|
+
}
|
|
33
|
+
export interface WorkflowDecisionVerification {
|
|
34
|
+
readonly keyId: string;
|
|
35
|
+
readonly verifiedAt: string;
|
|
36
|
+
}
|
|
37
|
+
export type WorkflowDecisionVerifier = (decision: WorkflowDecision) => Promise<WorkflowDecisionVerification> | WorkflowDecisionVerification;
|
|
38
|
+
export interface WorkflowDecisionRecord extends Omit<WorkflowDecision, "proof"> {
|
|
39
|
+
readonly verification?: WorkflowDecisionVerification;
|
|
26
40
|
readonly decidedAt: string;
|
|
27
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gates.types.js","sourceRoot":"","sources":["../../../src/domain/workflow/gates.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Task } from \"../workflow.types.ts\";\n\nexport interface WorkflowGate {\n readonly kind: \"approval\" | \"pause\";\n readonly prompt: string;\n readonly actors: readonly string[];\n}\n\nexport interface WorkflowGateOptions {\n readonly key: string;\n readonly after?: readonly Task[];\n readonly prompt: string;\n readonly actors: readonly string[];\n}\n\nexport interface WorkflowPauseRequest extends WorkflowGate {\n readonly id: string;\n readonly requestedAt: string;\n}\n\nexport interface WorkflowDecision {\n readonly executionId: string;\n readonly key: string;\n readonly requestId: string;\n readonly action: \"approve\" | \"resume\" | \"reject\";\n readonly actor: string;\n readonly reason: string;\n}\n\nexport interface WorkflowDecisionRecord extends WorkflowDecision {\n readonly decidedAt: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gates.types.js","sourceRoot":"","sources":["../../../src/domain/workflow/gates.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Task } from \"../workflow.types.ts\";\n\nexport interface WorkflowGate {\n readonly authentication?: \"signed\";\n readonly kind: \"approval\" | \"pause\";\n readonly prompt: string;\n readonly actors: readonly string[];\n}\n\nexport interface WorkflowGateOptions {\n readonly authentication?: \"signed\";\n readonly key: string;\n readonly after?: readonly Task[];\n readonly prompt: string;\n readonly actors: readonly string[];\n}\n\nexport interface WorkflowPauseRequest extends WorkflowGate {\n readonly id: string;\n readonly requestedAt: string;\n}\n\nexport interface WorkflowDecision {\n readonly proof?: WorkflowDecisionProof;\n readonly executionId: string;\n readonly key: string;\n readonly requestId: string;\n readonly action: \"approve\" | \"resume\" | \"reject\";\n readonly actor: string;\n readonly reason: string;\n}\n\nexport interface WorkflowDecisionProof {\n readonly keyId: string;\n readonly expiresAt: string;\n readonly signature: string;\n}\n\nexport interface WorkflowDecisionVerification {\n readonly keyId: string;\n readonly verifiedAt: string;\n}\n\nexport type WorkflowDecisionVerifier = (\n decision: WorkflowDecision,\n) => Promise<WorkflowDecisionVerification> | WorkflowDecisionVerification;\n\nexport interface WorkflowDecisionRecord extends Omit<\n WorkflowDecision,\n \"proof\"\n> {\n readonly verification?: WorkflowDecisionVerification;\n readonly decidedAt: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function taskIdempotencyKey(executionId: string, key: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../../../src/domain/workflow/idempotency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,GAAW;IACjE,OAAO,UAAU,CAAC,QAAQ,CAAC;SACxB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;SAC1C,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\n\nexport function taskIdempotencyKey(executionId: string, key: string): string {\n return createHash(\"sha256\")\n .update(JSON.stringify([executionId, key]))\n .digest(\"hex\");\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.constants.js","sourceRoot":"","sources":["../../../src/domain/workflow/retry.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC","sourcesContent":["export const maxTimerMs = 2 ** 31 - 1;\nexport const defaultMaxRetryDelayMs = 30_000;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Retry } from "../workflow.types.ts";
|
|
2
|
+
export declare function validateRetry(retry: Retry): void;
|
|
3
|
+
export declare function retryDelay(retry: Retry | undefined, cycle: number, error: unknown, random?: () => number): number;
|
|
4
|
+
export declare function waitForRetry(duration: number, signal: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import timers from "node:timers/promises";
|
|
2
|
+
import { OutpostError } from "../errors.js";
|
|
3
|
+
import { defaultMaxRetryDelayMs, maxTimerMs } from "./retry.constants.js";
|
|
4
|
+
import { positive } from "./validation.js";
|
|
5
|
+
export function validateRetry(retry) {
|
|
6
|
+
positive(retry.attempts, "retry.attempts");
|
|
7
|
+
for (const [name, value] of [
|
|
8
|
+
["delayMs", retry.delayMs],
|
|
9
|
+
["maxDelayMs", retry.maxDelayMs],
|
|
10
|
+
]) {
|
|
11
|
+
if (value !== undefined &&
|
|
12
|
+
(!Number.isFinite(value) || value < 0 || value > Number.MAX_SAFE_INTEGER))
|
|
13
|
+
throw new Error(`retry.${name} must be nonnegative and safely bounded`);
|
|
14
|
+
}
|
|
15
|
+
if (retry.backoff !== undefined &&
|
|
16
|
+
!["fixed", "exponential"].includes(retry.backoff))
|
|
17
|
+
throw new Error("retry.backoff must be fixed or exponential");
|
|
18
|
+
if (retry.jitter !== undefined && !["none", "full"].includes(retry.jitter))
|
|
19
|
+
throw new Error("retry.jitter must be none or full");
|
|
20
|
+
}
|
|
21
|
+
export function retryDelay(retry, cycle, error, random = Math.random) {
|
|
22
|
+
let duration = retry?.delayMs ?? 0;
|
|
23
|
+
if (retry?.backoff === "exponential" && duration > 0)
|
|
24
|
+
duration *= 2 ** Math.min(cycle - 1, 1024);
|
|
25
|
+
const cap = retry?.maxDelayMs ??
|
|
26
|
+
(retry?.backoff === "exponential"
|
|
27
|
+
? defaultMaxRetryDelayMs
|
|
28
|
+
: Number.MAX_SAFE_INTEGER);
|
|
29
|
+
duration = Math.min(duration, cap);
|
|
30
|
+
if (retry?.jitter === "full")
|
|
31
|
+
duration *= random();
|
|
32
|
+
const server = error instanceof OutpostError ? error.details.retryAfterMs : undefined;
|
|
33
|
+
if (typeof server === "number" &&
|
|
34
|
+
Number.isFinite(server) &&
|
|
35
|
+
server >= 0 &&
|
|
36
|
+
server <= Number.MAX_SAFE_INTEGER)
|
|
37
|
+
duration = Math.max(duration, server);
|
|
38
|
+
return Math.ceil(duration);
|
|
39
|
+
}
|
|
40
|
+
export async function waitForRetry(duration, signal) {
|
|
41
|
+
signal.throwIfAborted();
|
|
42
|
+
let remaining = duration;
|
|
43
|
+
do {
|
|
44
|
+
const chunk = Math.min(remaining, maxTimerMs);
|
|
45
|
+
await timers.setTimeout(chunk, undefined, { signal });
|
|
46
|
+
remaining -= chunk;
|
|
47
|
+
} while (remaining > 0);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/domain/workflow/retry.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAC3C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI;QAC1B,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC;QAC1B,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC;KACxB,EAAE,CAAC;QACX,IACE,KAAK,KAAK,SAAS;YACnB,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC;YAEzE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,yCAAyC,CAAC,CAAC;IAC5E,CAAC;IACD,IACE,KAAK,CAAC,OAAO,KAAK,SAAS;QAC3B,CA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,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,MAAmB;IAEnB,MAAM,CAAC,cAAc,EAAE,CAAC;IACxB,IAAI,SAAS,GAAG,QAAQ,CAAC;IACzB,GAAG,CAAC;QACF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC9C,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QACtD,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC,QAAQ,SAAS,GAAG,CAAC,EAAE;AAC1B,CAAC","sourcesContent":["import timers from \"node:timers/promises\";\nimport { OutpostError } from \"../errors.ts\";\nimport type { Retry } from \"../workflow.types.ts\";\nimport { defaultMaxRetryDelayMs, maxTimerMs } from \"./retry.constants.ts\";\nimport { positive } from \"./validation.ts\";\n\nexport function validateRetry(retry: Retry): void {\n positive(retry.attempts, \"retry.attempts\");\n for (const [name, value] of [\n [\"delayMs\", retry.delayMs],\n [\"maxDelayMs\", retry.maxDelayMs],\n ] as const) {\n if (\n value !== undefined &&\n (!Number.isFinite(value) || value < 0 || value > Number.MAX_SAFE_INTEGER)\n )\n throw new Error(`retry.${name} must be nonnegative and safely bounded`);\n }\n if (\n retry.backoff !== undefined &&\n ![\"fixed\", \"exponential\"].includes(retry.backoff)\n )\n throw new Error(\"retry.backoff must be fixed or exponential\");\n if (retry.jitter !== undefined && ![\"none\", \"full\"].includes(retry.jitter))\n throw new Error(\"retry.jitter must be none or full\");\n}\n\nexport function retryDelay(\n retry: Retry | undefined,\n cycle: number,\n error: unknown,\n random = Math.random,\n): number {\n let duration = retry?.delayMs ?? 0;\n if (retry?.backoff === \"exponential\" && duration > 0)\n duration *= 2 ** Math.min(cycle - 1, 1024);\n const cap =\n retry?.maxDelayMs ??\n (retry?.backoff === \"exponential\"\n ? defaultMaxRetryDelayMs\n : Number.MAX_SAFE_INTEGER);\n duration = Math.min(duration, cap);\n if (retry?.jitter === \"full\") duration *= random();\n const server =\n error instanceof OutpostError ? error.details.retryAfterMs : undefined;\n if (\n typeof server === \"number\" &&\n Number.isFinite(server) &&\n server >= 0 &&\n server <= Number.MAX_SAFE_INTEGER\n )\n duration = Math.max(duration, server);\n return Math.ceil(duration);\n}\n\nexport async function waitForRetry(\n duration: number,\n signal: AbortSignal,\n): Promise<void> {\n signal.throwIfAborted();\n let remaining = duration;\n do {\n const chunk = Math.min(remaining, maxTimerMs);\n await timers.setTimeout(chunk, undefined, { signal });\n remaining -= chunk;\n } while (remaining > 0);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { checkpointValue } from "./checkpoint-value.js";
|
|
2
|
-
import { WorkflowBudgetExceeded } from "./budget.js";
|
|
3
|
-
import {
|
|
2
|
+
import { WorkflowBudgetExceeded, WorkflowUsageUnavailable } from "./budget.js";
|
|
3
|
+
import { retryDelay, waitForRetry } from "./retry.js";
|
|
4
4
|
export async function runTask(item, runtime) {
|
|
5
5
|
const { record, signal, context, emit, finish, values, errors, options, stop, } = runtime;
|
|
6
6
|
const state = record(item);
|
|
@@ -26,6 +26,7 @@ export async function runTask(item, runtime) {
|
|
|
26
26
|
state.attempts = attempt;
|
|
27
27
|
emit({ type: "attempt", key: item.key, attempt });
|
|
28
28
|
await runtime.persist();
|
|
29
|
+
let delayMs = 0;
|
|
29
30
|
const deadline = new AbortController();
|
|
30
31
|
const timer = item.timeoutMs === undefined
|
|
31
32
|
? undefined
|
|
@@ -47,19 +48,22 @@ export async function runTask(item, runtime) {
|
|
|
47
48
|
cycle === limit ||
|
|
48
49
|
item.retry?.accepts?.(error, attempt) === false)
|
|
49
50
|
throw error;
|
|
50
|
-
|
|
51
|
+
delayMs = retryDelay(item.retry, cycle, error);
|
|
52
|
+
emit({ type: "retry", key: item.key, attempt, delayMs });
|
|
51
53
|
}
|
|
52
54
|
finally {
|
|
53
55
|
runtime.closeAttempt(item);
|
|
54
56
|
clearTimeout(timer);
|
|
55
57
|
}
|
|
56
|
-
await
|
|
58
|
+
await waitForRetry(delayMs, signal);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
catch (error) {
|
|
60
62
|
state.error = error instanceof Error ? error.message : String(error);
|
|
61
63
|
if (signal.aborted ||
|
|
62
|
-
(error instanceof WorkflowBudgetExceeded
|
|
64
|
+
((error instanceof WorkflowBudgetExceeded ||
|
|
65
|
+
error instanceof WorkflowUsageUnavailable) &&
|
|
66
|
+
runtime.accounting.exhausted))
|
|
63
67
|
finish(item, "cancelled");
|
|
64
68
|
else {
|
|
65
69
|
errors.push(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-runner.js","sourceRoot":"","sources":["../../../src/domain/workflow/task-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"task-runner.js","sourceRoot":"","sources":["../../../src/domain/workflow/task-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAGtD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,IAAU,EACV,OAA+B;IAE/B,MAAM,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,GACL,GAAG,OAAO,CAAC;IACZ,MAAM,KAAK,GAAG,MAAM,CAAC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OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;YAC3D,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC3B,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,MAAM,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,CAAC,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrE,IACE,MAAM,CAAC,OAAO;YACd,CAAC,CAAC,KAAK,YAAY,sBAAsB;gBACvC,KAAK,YAAY,wBAAwB,CAAC;gBAC1C,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;YAE/B,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;aACvB,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACvB,IAAI,OAAO,CAAC,WAAW,KAAK,KAAK;gBAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC","sourcesContent":["import { checkpointValue } from \"./checkpoint-value.ts\";\nimport { WorkflowBudgetExceeded, WorkflowUsageUnavailable } from \"./budget.ts\";\nimport { retryDelay, waitForRetry } from \"./retry.ts\";\nimport type { Task, WorkflowExecutionState } from \"../workflow.types.ts\";\n\nexport async function runTask(\n item: Task,\n runtime: WorkflowExecutionState,\n): Promise<void> {\n const {\n record,\n signal,\n context,\n emit,\n finish,\n values,\n errors,\n options,\n stop,\n } = runtime;\n const state = record(item);\n state.status = \"active\";\n delete state.error;\n delete state.finishedAt;\n state.startedAt = new Date().toISOString();\n emit({ type: \"task\", key: item.key, status: \"active\", attempt: 0 });\n try {\n await runtime.persist();\n signal.throwIfAborted();\n if (item.condition && !(await item.condition(context(item, 0, signal)))) {\n signal.throwIfAborted();\n finish(item, \"skipped\");\n return;\n }\n const limit = item.retry?.attempts ?? 1;\n const priorAttempts = state.attempts;\n for (let cycle = 1; cycle <= limit; cycle++) {\n const attempt = priorAttempts + cycle;\n signal.throwIfAborted();\n runtime.accounting.admit();\n state.attempts = attempt;\n emit({ type: \"attempt\", key: item.key, attempt });\n await runtime.persist();\n let delayMs = 0;\n const deadline = new AbortController();\n const timer =\n item.timeoutMs === undefined\n ? undefined\n : setTimeout(\n () => deadline.abort(new Error(`${item.key} timed out`)),\n item.timeoutMs,\n );\n const taskSignal = AbortSignal.any([signal, deadline.signal]);\n try {\n taskSignal.throwIfAborted();\n const value = await item.perform(context(item, attempt, taskSignal));\n taskSignal.throwIfAborted();\n if (options.checkpoint) checkpointValue(value);\n values.set(item, value);\n finish(item, \"done\");\n return;\n } catch (error) {\n runtime.closeAttempt(item);\n if (\n signal.aborted ||\n cycle === limit ||\n item.retry?.accepts?.(error, attempt) === false\n )\n throw error;\n delayMs = retryDelay(item.retry, cycle, error);\n emit({ type: \"retry\", key: item.key, attempt, delayMs });\n } finally {\n runtime.closeAttempt(item);\n clearTimeout(timer);\n }\n await waitForRetry(delayMs, signal);\n }\n } catch (error) {\n state.error = error instanceof Error ? error.message : String(error);\n if (\n signal.aborted ||\n ((error instanceof WorkflowBudgetExceeded ||\n error instanceof WorkflowUsageUnavailable) &&\n runtime.accounting.exhausted)\n )\n finish(item, \"cancelled\");\n else {\n errors.push(error);\n finish(item, \"failed\");\n if (options.stopOnError !== false) stop.abort(error);\n }\n } finally {\n await runtime.persist();\n }\n}\n"]}
|