@elie-laloum/outpost 2.0.0 → 4.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 +42 -0
- package/README.md +3 -1
- package/SECURITY.md +3 -1
- package/dist/adapters/agents/claude-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/claude-diagnostics.js +7 -0
- package/dist/adapters/agents/claude-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.constants.d.ts +12 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js +24 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.d.ts +4 -0
- package/dist/adapters/agents/cli-diagnostics.js +14 -0
- package/dist/adapters/agents/cli-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.types.d.ts +13 -0
- package/dist/adapters/agents/cli-diagnostics.types.js +2 -0
- package/dist/adapters/agents/cli-diagnostics.types.js.map +1 -0
- package/dist/adapters/agents/codex-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/codex-diagnostics.js +7 -0
- package/dist/adapters/agents/codex-diagnostics.js.map +1 -0
- package/dist/adapters/agents/gemini-adapter.d.ts +3 -0
- package/dist/adapters/agents/gemini-adapter.js +15 -0
- package/dist/adapters/agents/gemini-adapter.js.map +1 -0
- package/dist/adapters/agents/gemini-diagnostics.d.ts +2 -0
- package/dist/adapters/agents/gemini-diagnostics.js +15 -0
- package/dist/adapters/agents/gemini-diagnostics.js.map +1 -0
- package/dist/adapters/agents/gemini-events.d.ts +2 -0
- package/dist/adapters/agents/gemini-events.js +50 -0
- package/dist/adapters/agents/gemini-events.js.map +1 -0
- package/dist/adapters/agents/gemini-request.d.ts +4 -0
- package/dist/adapters/agents/gemini-request.js +21 -0
- package/dist/adapters/agents/gemini-request.js.map +1 -0
- package/dist/adapters/agents/gemini.types.d.ts +6 -0
- package/dist/adapters/agents/gemini.types.js +2 -0
- package/dist/adapters/agents/gemini.types.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js +105 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.types.d.ts +6 -0
- package/dist/adapters/agents/protocol-fixtures.types.js +2 -0
- package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -0
- package/dist/application/agent-bootstrap.constants.d.ts +1 -0
- package/dist/application/agent-bootstrap.constants.js +1 -0
- package/dist/application/agent-bootstrap.constants.js.map +1 -1
- package/dist/application/agent-bootstrap.js +6 -2
- package/dist/application/agent-bootstrap.js.map +1 -1
- package/dist/application/agent-output.js +9 -2
- package/dist/application/agent-output.js.map +1 -1
- package/dist/application/artifact-tasks.d.ts +5 -0
- package/dist/application/artifact-tasks.js +31 -0
- package/dist/application/artifact-tasks.js.map +1 -0
- package/dist/application/artifact-tasks.types.d.ts +8 -0
- package/dist/application/artifact-tasks.types.js +2 -0
- package/dist/application/artifact-tasks.types.js.map +1 -0
- package/dist/application/diagnostic-probe.d.ts +3 -0
- package/dist/application/diagnostic-probe.js +55 -0
- package/dist/application/diagnostic-probe.js.map +1 -0
- package/dist/application/dispatch-validation.js +2 -0
- package/dist/application/dispatch-validation.js.map +1 -1
- package/dist/application/doctor-agent.constants.d.ts +11 -0
- package/dist/application/doctor-agent.constants.js +10 -0
- package/dist/application/doctor-agent.constants.js.map +1 -0
- package/dist/application/doctor-agent.d.ts +3 -0
- package/dist/application/doctor-agent.js +53 -0
- package/dist/application/doctor-agent.js.map +1 -0
- package/dist/application/doctor-image.d.ts +3 -0
- package/dist/application/doctor-image.js +133 -0
- package/dist/application/doctor-image.js.map +1 -0
- package/dist/application/doctor-protocol.d.ts +3 -0
- package/dist/application/doctor-protocol.js +30 -0
- package/dist/application/doctor-protocol.js.map +1 -0
- package/dist/application/doctor-protocol.types.d.ts +10 -0
- package/dist/application/doctor-protocol.types.js +2 -0
- package/dist/application/doctor-protocol.types.js.map +1 -0
- package/dist/application/doctor-sandbox.constants.d.ts +5 -0
- package/dist/application/doctor-sandbox.constants.js +6 -0
- package/dist/application/doctor-sandbox.constants.js.map +1 -0
- package/dist/application/doctor-sandbox.d.ts +4 -0
- package/dist/application/doctor-sandbox.js +133 -0
- package/dist/application/doctor-sandbox.js.map +1 -0
- package/dist/application/doctor-sandbox.types.d.ts +23 -0
- package/dist/application/doctor-sandbox.types.js +2 -0
- package/dist/application/doctor-sandbox.types.js.map +1 -0
- package/dist/application/doctor-transfers.constants.d.ts +6 -0
- package/dist/application/doctor-transfers.constants.js +7 -0
- package/dist/application/doctor-transfers.constants.js.map +1 -0
- package/dist/application/doctor-transfers.d.ts +4 -0
- package/dist/application/doctor-transfers.js +88 -0
- package/dist/application/doctor-transfers.js.map +1 -0
- package/dist/application/doctor.constants.d.ts +9 -0
- package/dist/application/doctor.constants.js +15 -0
- package/dist/application/doctor.constants.js.map +1 -0
- package/dist/application/doctor.d.ts +3 -0
- package/dist/application/doctor.js +106 -0
- package/dist/application/doctor.js.map +1 -0
- package/dist/application/doctor.types.d.ts +39 -0
- package/dist/application/doctor.types.js +2 -0
- package/dist/application/doctor.types.js.map +1 -0
- package/dist/application/execution.js +1 -0
- package/dist/application/execution.js.map +1 -1
- package/dist/application/outpost.types.d.ts +4 -0
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/queue-worker.d.ts +2 -0
- package/dist/application/queue-worker.js +75 -0
- package/dist/application/queue-worker.js.map +1 -0
- package/dist/application/queue-worker.types.d.ts +15 -0
- package/dist/application/queue-worker.types.js +2 -0
- package/dist/application/queue-worker.types.js.map +1 -0
- package/dist/application/queued-task.d.ts +3 -0
- package/dist/application/queued-task.js +56 -0
- package/dist/application/queued-task.js.map +1 -0
- package/dist/application/queued-task.types.d.ts +11 -0
- package/dist/application/queued-task.types.js +2 -0
- package/dist/application/queued-task.types.js.map +1 -0
- package/dist/application/recovery-checksum-capture.d.ts +2 -0
- package/dist/application/recovery-checksum-capture.js +32 -0
- package/dist/application/recovery-checksum-capture.js.map +1 -0
- package/dist/application/recovery-checksum-paths.d.ts +2 -0
- package/dist/application/recovery-checksum-paths.js +11 -0
- package/dist/application/recovery-checksum-paths.js.map +1 -0
- package/dist/application/recovery-checksums.constants.d.ts +5 -0
- package/dist/application/recovery-checksums.constants.js +6 -0
- package/dist/application/recovery-checksums.constants.js.map +1 -0
- package/dist/application/recovery-checksums.d.ts +3 -0
- package/dist/application/recovery-checksums.js +94 -0
- package/dist/application/recovery-checksums.js.map +1 -0
- package/dist/application/recovery-checksums.types.d.ts +17 -0
- package/dist/application/recovery-checksums.types.js +2 -0
- package/dist/application/recovery-checksums.types.js.map +1 -0
- package/dist/application/recovery-inspection.d.ts +2 -0
- package/dist/application/recovery-inspection.js +32 -0
- package/dist/application/recovery-inspection.js.map +1 -0
- package/dist/application/recovery-inspection.types.d.ts +18 -0
- package/dist/application/recovery-inspection.types.js +2 -0
- package/dist/application/recovery-inspection.types.js.map +1 -0
- package/dist/application/recovery-restorability.d.ts +2 -0
- package/dist/application/recovery-restorability.js +137 -0
- package/dist/application/recovery-restorability.js.map +1 -0
- package/dist/application/recovery-restore-snapshot.d.ts +2 -0
- package/dist/application/recovery-restore-snapshot.js +57 -0
- package/dist/application/recovery-restore-snapshot.js.map +1 -0
- package/dist/application/recovery-restore.d.ts +3 -0
- package/dist/application/recovery-restore.js +161 -0
- package/dist/application/recovery-restore.js.map +1 -0
- package/dist/application/recovery-restore.types.d.ts +28 -0
- package/dist/application/recovery-restore.types.js +2 -0
- package/dist/application/recovery-restore.types.js.map +1 -0
- package/dist/application/recovery-retention-policy.d.ts +2 -0
- package/dist/application/recovery-retention-policy.js +21 -0
- package/dist/application/recovery-retention-policy.js.map +1 -0
- package/dist/application/recovery-retention.constants.d.ts +3 -0
- package/dist/application/recovery-retention.constants.js +2 -0
- package/dist/application/recovery-retention.constants.js.map +1 -0
- package/dist/application/recovery-retention.d.ts +4 -0
- package/dist/application/recovery-retention.js +207 -0
- package/dist/application/recovery-retention.js.map +1 -0
- package/dist/application/recovery-retention.types.d.ts +52 -0
- package/dist/application/recovery-retention.types.js +2 -0
- package/dist/application/recovery-retention.types.js.map +1 -0
- package/dist/application/recovery-verification.constants.d.ts +5 -0
- package/dist/application/recovery-verification.constants.js +10 -0
- package/dist/application/recovery-verification.constants.js.map +1 -0
- package/dist/application/recovery-verification.d.ts +3 -0
- package/dist/application/recovery-verification.js +107 -0
- package/dist/application/recovery-verification.js.map +1 -0
- package/dist/application/recovery-verification.types.d.ts +26 -0
- package/dist/application/recovery-verification.types.js +2 -0
- package/dist/application/recovery-verification.types.js.map +1 -0
- package/dist/application/remote-apply.js +30 -6
- package/dist/application/remote-apply.js.map +1 -1
- package/dist/application/remote-backup.js +6 -2
- package/dist/application/remote-backup.js.map +1 -1
- package/dist/application/remote-download.js +38 -6
- package/dist/application/remote-download.js.map +1 -1
- package/dist/application/remote-history.d.ts +6 -0
- package/dist/application/remote-history.js +114 -0
- package/dist/application/remote-history.js.map +1 -0
- package/dist/application/remote-upload.d.ts +2 -0
- package/dist/application/remote-upload.js +17 -0
- package/dist/application/remote-upload.js.map +1 -0
- package/dist/application/remote-validation.js +39 -28
- package/dist/application/remote-validation.js.map +1 -1
- package/dist/application/remote-workspace.constants.d.ts +3 -0
- package/dist/application/remote-workspace.constants.js +2 -0
- package/dist/application/remote-workspace.constants.js.map +1 -0
- package/dist/application/remote-workspace.js +10 -10
- package/dist/application/remote-workspace.js.map +1 -1
- package/dist/application/remote-workspace.types.d.ts +3 -1
- package/dist/application/remote-workspace.types.js.map +1 -1
- package/dist/application/sandbox-activity.d.ts +3 -0
- package/dist/application/sandbox-activity.js +25 -0
- package/dist/application/sandbox-activity.js.map +1 -0
- package/dist/application/sandbox-provision.js +55 -10
- package/dist/application/sandbox-provision.js.map +1 -1
- package/dist/application/sandbox-session.types.d.ts +2 -0
- package/dist/application/sandbox-session.types.js.map +1 -1
- package/dist/application/sandbox.js +33 -10
- package/dist/application/sandbox.js.map +1 -1
- package/dist/application/speculation-host.d.ts +2 -0
- package/dist/application/speculation-host.js +30 -0
- package/dist/application/speculation-host.js.map +1 -0
- package/dist/application/speculation.constants.d.ts +4 -0
- package/dist/application/speculation.constants.js +2 -0
- package/dist/application/speculation.constants.js.map +1 -0
- package/dist/application/speculation.d.ts +2 -0
- package/dist/application/speculation.js +166 -0
- package/dist/application/speculation.js.map +1 -0
- package/dist/application/speculation.types.d.ts +56 -0
- package/dist/application/speculation.types.js +2 -0
- package/dist/application/speculation.types.js.map +1 -0
- package/dist/application/storage-reservation.d.ts +3 -0
- package/dist/application/storage-reservation.js +10 -0
- package/dist/application/storage-reservation.js.map +1 -0
- package/dist/application/storage-reservation.types.d.ts +4 -0
- package/dist/application/storage-reservation.types.js +2 -0
- package/dist/application/storage-reservation.types.js.map +1 -0
- package/dist/application/task-usage.d.ts +4 -0
- package/dist/application/task-usage.js +41 -0
- package/dist/application/task-usage.js.map +1 -0
- package/dist/application/task-usage.types.d.ts +5 -0
- package/dist/application/task-usage.types.js +2 -0
- package/dist/application/task-usage.types.js.map +1 -0
- package/dist/application/tasks.js +23 -2
- package/dist/application/tasks.js.map +1 -1
- package/dist/application/tasks.types.d.ts +4 -3
- package/dist/application/tasks.types.js.map +1 -1
- package/dist/application/workspace-allocation.d.ts +3 -0
- package/dist/application/workspace-allocation.js +34 -0
- package/dist/application/workspace-allocation.js.map +1 -0
- package/dist/application/workspace.js +2 -2
- package/dist/application/workspace.js.map +1 -1
- package/dist/cli/commands.js +4 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor-command.d.ts +3 -0
- package/dist/cli/doctor-command.js +38 -0
- package/dist/cli/doctor-command.js.map +1 -0
- package/dist/cli/main.constants.d.ts +38 -2
- package/dist/cli/main.constants.js +21 -2
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/recovery-command.d.ts +2 -0
- package/dist/cli/recovery-command.js +93 -0
- package/dist/cli/recovery-command.js.map +1 -0
- package/dist/cli/recovery-prune-command.d.ts +2 -0
- package/dist/cli/recovery-prune-command.js +34 -0
- package/dist/cli/recovery-prune-command.js.map +1 -0
- package/dist/cli/recovery-restore-command.d.ts +2 -0
- package/dist/cli/recovery-restore-command.js +34 -0
- package/dist/cli/recovery-restore-command.js.map +1 -0
- package/dist/cli/recovery-verify-command.d.ts +2 -0
- package/dist/cli/recovery-verify-command.js +43 -0
- package/dist/cli/recovery-verify-command.js.map +1 -0
- package/dist/cli/scaffold-files.js +2 -2
- package/dist/cli/scaffold-files.js.map +1 -1
- package/dist/cli/scaffold-validation.js +1 -1
- package/dist/cli/scaffold-validation.js.map +1 -1
- package/dist/cli/scaffold.constants.d.ts +5 -0
- package/dist/cli/scaffold.constants.js +7 -2
- package/dist/cli/scaffold.constants.js.map +1 -1
- package/dist/cli/scaffold.types.d.ts +1 -1
- package/dist/cli/scaffold.types.js.map +1 -1
- package/dist/domain/agent.types.d.ts +2 -0
- package/dist/domain/agent.types.js.map +1 -1
- package/dist/domain/artifact-reference.d.ts +4 -0
- package/dist/domain/artifact-reference.js +90 -0
- package/dist/domain/artifact-reference.js.map +1 -0
- package/dist/domain/artifact.constants.d.ts +2 -0
- package/dist/domain/artifact.constants.js +3 -0
- package/dist/domain/artifact.constants.js.map +1 -0
- package/dist/domain/artifact.d.ts +7 -0
- package/dist/domain/artifact.js +104 -0
- package/dist/domain/artifact.js.map +1 -0
- package/dist/domain/artifact.types.d.ts +44 -0
- package/dist/domain/artifact.types.js +2 -0
- package/dist/domain/artifact.types.js.map +1 -0
- package/dist/domain/egress.constants.d.ts +1 -0
- package/dist/domain/egress.constants.js +7 -0
- package/dist/domain/egress.constants.js.map +1 -0
- package/dist/domain/egress.d.ts +2 -0
- package/dist/domain/egress.js +48 -0
- package/dist/domain/egress.js.map +1 -0
- package/dist/domain/egress.types.d.ts +8 -0
- package/dist/domain/egress.types.js +2 -0
- package/dist/domain/egress.types.js.map +1 -0
- package/dist/domain/ports.d.ts +1 -1
- package/dist/domain/ports.js.map +1 -1
- package/dist/domain/sandbox.types.d.ts +13 -0
- package/dist/domain/sandbox.types.js.map +1 -1
- package/dist/domain/task-queue.constants.d.ts +8 -0
- package/dist/domain/task-queue.constants.js +9 -0
- package/dist/domain/task-queue.constants.js.map +1 -0
- package/dist/domain/task-queue.d.ts +11 -0
- package/dist/domain/task-queue.js +105 -0
- package/dist/domain/task-queue.js.map +1 -0
- package/dist/domain/task-queue.types.d.ts +41 -0
- package/dist/domain/task-queue.types.js +2 -0
- package/dist/domain/task-queue.types.js.map +1 -0
- package/dist/domain/workflow/budget.constants.d.ts +1 -0
- package/dist/domain/workflow/budget.constants.js +7 -0
- package/dist/domain/workflow/budget.constants.js.map +1 -0
- package/dist/domain/workflow/budget.d.ts +9 -0
- package/dist/domain/workflow/budget.js +69 -0
- package/dist/domain/workflow/budget.js.map +1 -0
- package/dist/domain/workflow/budget.types.d.ts +15 -0
- package/dist/domain/workflow/budget.types.js +2 -0
- package/dist/domain/workflow/budget.types.js.map +1 -0
- package/dist/domain/workflow/checkpoint-validation.d.ts +3 -0
- package/dist/domain/workflow/checkpoint-validation.js +81 -0
- package/dist/domain/workflow/checkpoint-validation.js.map +1 -0
- package/dist/domain/workflow/checkpoint-value.d.ts +2 -0
- package/dist/domain/workflow/checkpoint-value.js +49 -0
- package/dist/domain/workflow/checkpoint-value.js.map +1 -0
- package/dist/domain/workflow/checkpoint.d.ts +3 -0
- package/dist/domain/workflow/checkpoint.js +70 -0
- package/dist/domain/workflow/checkpoint.js.map +1 -0
- package/dist/domain/workflow/checkpoint.types.d.ts +40 -0
- package/dist/domain/workflow/checkpoint.types.js +2 -0
- package/dist/domain/workflow/checkpoint.types.js.map +1 -0
- package/dist/domain/workflow/gate-validation.d.ts +4 -0
- package/dist/domain/workflow/gate-validation.js +71 -0
- package/dist/domain/workflow/gate-validation.js.map +1 -0
- package/dist/domain/workflow/gates.constants.d.ts +4 -0
- package/dist/domain/workflow/gates.constants.js +5 -0
- package/dist/domain/workflow/gates.constants.js.map +1 -0
- package/dist/domain/workflow/gates.d.ts +7 -0
- package/dist/domain/workflow/gates.js +85 -0
- package/dist/domain/workflow/gates.js.map +1 -0
- package/dist/domain/workflow/gates.types.d.ts +27 -0
- package/dist/domain/workflow/gates.types.js +2 -0
- package/dist/domain/workflow/gates.types.js.map +1 -0
- package/dist/domain/workflow/task-runner.js +22 -3
- package/dist/domain/workflow/task-runner.js.map +1 -1
- package/dist/domain/workflow/usage-receipt.constants.d.ts +2 -0
- package/dist/domain/workflow/usage-receipt.constants.js +3 -0
- package/dist/domain/workflow/usage-receipt.constants.js.map +1 -0
- package/dist/domain/workflow/usage-receipt.d.ts +2 -0
- package/dist/domain/workflow/usage-receipt.js +18 -0
- package/dist/domain/workflow/usage-receipt.js.map +1 -0
- package/dist/domain/workflow/validation.js +6 -0
- package/dist/domain/workflow/validation.js.map +1 -1
- package/dist/domain/workflow/workflow-scheduler.js +68 -33
- package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
- package/dist/domain/workflow/workflow-state.d.ts +2 -1
- package/dist/domain/workflow/workflow-state.js +107 -3
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.d.ts +2 -0
- package/dist/domain/workflow.js +1 -0
- package/dist/domain/workflow.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +23 -3
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +44 -5
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/artifact-store.constants.d.ts +1 -0
- package/dist/infrastructure/artifact-store.constants.js +2 -0
- package/dist/infrastructure/artifact-store.constants.js.map +1 -0
- package/dist/infrastructure/artifact-store.d.ts +3 -0
- package/dist/infrastructure/artifact-store.js +100 -0
- package/dist/infrastructure/artifact-store.js.map +1 -0
- package/dist/infrastructure/artifact-store.types.d.ts +4 -0
- package/dist/infrastructure/artifact-store.types.js +2 -0
- package/dist/infrastructure/artifact-store.types.js.map +1 -0
- package/dist/infrastructure/file-manifest.d.ts +6 -0
- package/dist/infrastructure/file-manifest.js +92 -0
- package/dist/infrastructure/file-manifest.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.constants.d.ts +4 -0
- package/dist/infrastructure/git/lock-inspection.constants.js +5 -0
- package/dist/infrastructure/git/lock-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.d.ts +3 -0
- package/dist/infrastructure/git/lock-inspection.js +64 -0
- package/dist/infrastructure/git/lock-inspection.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.types.d.ts +27 -0
- package/dist/infrastructure/git/lock-inspection.types.js +2 -0
- package/dist/infrastructure/git/lock-inspection.types.js.map +1 -0
- package/dist/infrastructure/git/lock.d.ts +1 -0
- package/dist/infrastructure/git/lock.js +70 -29
- package/dist/infrastructure/git/lock.js.map +1 -1
- package/dist/infrastructure/git/process-identity.d.ts +3 -0
- package/dist/infrastructure/git/process-identity.js +73 -0
- package/dist/infrastructure/git/process-identity.js.map +1 -0
- package/dist/infrastructure/git/process-identity.types.d.ts +10 -0
- package/dist/infrastructure/git/process-identity.types.js +2 -0
- package/dist/infrastructure/git/process-identity.types.js.map +1 -0
- package/dist/infrastructure/git/verification-command.d.ts +1 -0
- package/dist/infrastructure/git/verification-command.js +37 -0
- package/dist/infrastructure/git/verification-command.js.map +1 -0
- package/dist/infrastructure/git/workspace-lease.js +1 -0
- package/dist/infrastructure/git/workspace-lease.js.map +1 -1
- package/dist/infrastructure/git/workspace.js +5 -1
- package/dist/infrastructure/git/workspace.js.map +1 -1
- package/dist/infrastructure/git/worktree-inspection.constants.d.ts +5 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js +16 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.d.ts +3 -0
- package/dist/infrastructure/git/worktree-inspection.js +120 -0
- package/dist/infrastructure/git/worktree-inspection.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.types.d.ts +19 -0
- package/dist/infrastructure/git/worktree-inspection.types.js +2 -0
- package/dist/infrastructure/git/worktree-inspection.types.js.map +1 -0
- package/dist/infrastructure/inspection-file.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-file.constants.js +5 -0
- package/dist/infrastructure/inspection-file.constants.js.map +1 -0
- package/dist/infrastructure/inspection-file.d.ts +1 -0
- package/dist/infrastructure/inspection-file.js +43 -0
- package/dist/infrastructure/inspection-file.js.map +1 -0
- package/dist/infrastructure/inspection-hash.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-hash.constants.js +2 -0
- package/dist/infrastructure/inspection-hash.constants.js.map +1 -0
- package/dist/infrastructure/inspection-hash.d.ts +2 -0
- package/dist/infrastructure/inspection-hash.js +62 -0
- package/dist/infrastructure/inspection-hash.js.map +1 -0
- package/dist/infrastructure/inspection-hash.types.d.ts +5 -0
- package/dist/infrastructure/inspection-hash.types.js +2 -0
- package/dist/infrastructure/inspection-hash.types.js.map +1 -0
- package/dist/infrastructure/journal-retention.constants.d.ts +4 -0
- package/dist/infrastructure/journal-retention.constants.js +5 -0
- package/dist/infrastructure/journal-retention.constants.js.map +1 -0
- package/dist/infrastructure/journal-retention.d.ts +2 -0
- package/dist/infrastructure/journal-retention.js +51 -0
- package/dist/infrastructure/journal-retention.js.map +1 -0
- package/dist/infrastructure/journal.js +37 -13
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/opentelemetry.constants.d.ts +10 -0
- package/dist/infrastructure/opentelemetry.constants.js +11 -0
- package/dist/infrastructure/opentelemetry.constants.js.map +1 -0
- package/dist/infrastructure/opentelemetry.d.ts +3 -0
- package/dist/infrastructure/opentelemetry.js +131 -0
- package/dist/infrastructure/opentelemetry.js.map +1 -0
- package/dist/infrastructure/opentelemetry.types.d.ts +21 -0
- package/dist/infrastructure/opentelemetry.types.js +2 -0
- package/dist/infrastructure/opentelemetry.types.js.map +1 -0
- package/dist/infrastructure/resource-activity-inspection.d.ts +2 -0
- package/dist/infrastructure/resource-activity-inspection.js +152 -0
- package/dist/infrastructure/resource-activity-inspection.js.map +1 -0
- package/dist/infrastructure/resource-activity.constants.d.ts +8 -0
- package/dist/infrastructure/resource-activity.constants.js +26 -0
- package/dist/infrastructure/resource-activity.constants.js.map +1 -0
- package/dist/infrastructure/resource-activity.d.ts +2 -0
- package/dist/infrastructure/resource-activity.js +166 -0
- package/dist/infrastructure/resource-activity.js.map +1 -0
- package/dist/infrastructure/resource-activity.types.d.ts +53 -0
- package/dist/infrastructure/resource-activity.types.js +2 -0
- package/dist/infrastructure/resource-activity.types.js.map +1 -0
- package/dist/infrastructure/storage-inventory.constants.d.ts +6 -0
- package/dist/infrastructure/storage-inventory.constants.js +11 -0
- package/dist/infrastructure/storage-inventory.constants.js.map +1 -0
- package/dist/infrastructure/storage-inventory.d.ts +2 -0
- package/dist/infrastructure/storage-inventory.js +123 -0
- package/dist/infrastructure/storage-inventory.js.map +1 -0
- package/dist/infrastructure/storage-inventory.types.d.ts +38 -0
- package/dist/infrastructure/storage-inventory.types.js +2 -0
- package/dist/infrastructure/storage-inventory.types.js.map +1 -0
- package/dist/infrastructure/storage-mutation-lock.constants.d.ts +5 -0
- package/dist/infrastructure/storage-mutation-lock.constants.js +6 -0
- package/dist/infrastructure/storage-mutation-lock.constants.js.map +1 -0
- package/dist/infrastructure/storage-mutation-lock.d.ts +1 -0
- package/dist/infrastructure/storage-mutation-lock.js +21 -0
- package/dist/infrastructure/storage-mutation-lock.js.map +1 -0
- package/dist/infrastructure/storage-reservations.constants.d.ts +4 -0
- package/dist/infrastructure/storage-reservations.constants.js +5 -0
- package/dist/infrastructure/storage-reservations.constants.js.map +1 -0
- package/dist/infrastructure/storage-reservations.d.ts +2 -0
- package/dist/infrastructure/storage-reservations.js +150 -0
- package/dist/infrastructure/storage-reservations.js.map +1 -0
- package/dist/infrastructure/storage-reservations.types.d.ts +21 -0
- package/dist/infrastructure/storage-reservations.types.js +2 -0
- package/dist/infrastructure/storage-reservations.types.js.map +1 -0
- package/dist/infrastructure/task-queue-http.constants.d.ts +2 -0
- package/dist/infrastructure/task-queue-http.constants.js +3 -0
- package/dist/infrastructure/task-queue-http.constants.js.map +1 -0
- package/dist/infrastructure/task-queue-http.d.ts +4 -0
- package/dist/infrastructure/task-queue-http.js +158 -0
- package/dist/infrastructure/task-queue-http.js.map +1 -0
- package/dist/infrastructure/task-queue-http.types.d.ts +16 -0
- package/dist/infrastructure/task-queue-http.types.js +2 -0
- package/dist/infrastructure/task-queue-http.types.js.map +1 -0
- package/dist/infrastructure/task-queue.d.ts +2 -0
- package/dist/infrastructure/task-queue.js +134 -0
- package/dist/infrastructure/task-queue.js.map +1 -0
- package/dist/infrastructure/transfer.js +17 -0
- package/dist/infrastructure/transfer.js.map +1 -1
- package/dist/infrastructure/workflow-checkpoint.constants.d.ts +1 -0
- package/dist/infrastructure/workflow-checkpoint.constants.js +2 -0
- package/dist/infrastructure/workflow-checkpoint.constants.js.map +1 -0
- package/dist/infrastructure/workflow-checkpoint.d.ts +3 -0
- package/dist/infrastructure/workflow-checkpoint.js +77 -0
- package/dist/infrastructure/workflow-checkpoint.js.map +1 -0
- package/dist/infrastructure/workflow-checkpoint.types.d.ts +4 -0
- package/dist/infrastructure/workflow-checkpoint.types.js +2 -0
- package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -0
- package/dist/providers/agents.d.ts +2 -0
- package/dist/providers/agents.js +1 -0
- package/dist/providers/agents.js.map +1 -1
- package/dist/providers/cloud.constants.d.ts +1 -0
- package/dist/providers/cloud.constants.js +1 -0
- package/dist/providers/cloud.constants.js.map +1 -1
- package/dist/providers/container-cache.constants.d.ts +11 -0
- package/dist/providers/container-cache.constants.js +9 -0
- package/dist/providers/container-cache.constants.js.map +1 -0
- package/dist/providers/container-cache.d.ts +4 -0
- package/dist/providers/container-cache.js +48 -0
- package/dist/providers/container-cache.js.map +1 -0
- package/dist/providers/container-cache.types.d.ts +8 -0
- package/dist/providers/container-cache.types.js +2 -0
- package/dist/providers/container-cache.types.js.map +1 -0
- package/dist/providers/container-isolation.d.ts +2 -0
- package/dist/providers/container-isolation.js +29 -0
- package/dist/providers/container-isolation.js.map +1 -0
- package/dist/providers/container-mounts.js +7 -2
- package/dist/providers/container-mounts.js.map +1 -1
- package/dist/providers/container-network.d.ts +2 -0
- package/dist/providers/container-network.js +14 -0
- package/dist/providers/container-network.js.map +1 -0
- package/dist/providers/container-plan.js +6 -2
- package/dist/providers/container-plan.js.map +1 -1
- package/dist/providers/container.constants.d.ts +1 -0
- package/dist/providers/container.constants.js +1 -0
- package/dist/providers/container.constants.js.map +1 -1
- package/dist/providers/container.js +50 -3
- package/dist/providers/container.js.map +1 -1
- package/dist/providers/container.types.d.ts +5 -0
- package/dist/providers/container.types.js.map +1 -1
- package/dist/providers/daytona-command.js +10 -6
- package/dist/providers/daytona-command.js.map +1 -1
- package/dist/providers/daytona-terminal.d.ts +3 -0
- package/dist/providers/daytona-terminal.js +128 -0
- package/dist/providers/daytona-terminal.js.map +1 -0
- package/dist/providers/daytona.js +15 -4
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/diagnostic-container.d.ts +4 -0
- package/dist/providers/diagnostic-container.js +15 -0
- package/dist/providers/diagnostic-container.js.map +1 -0
- package/dist/providers/docker.d.ts +2 -0
- package/dist/providers/docker.js.map +1 -1
- package/dist/providers/file-batches.constants.d.ts +10 -0
- package/dist/providers/file-batches.constants.js +57 -0
- package/dist/providers/file-batches.constants.js.map +1 -0
- package/dist/providers/file-batches.d.ts +2 -0
- package/dist/providers/file-batches.js +160 -0
- package/dist/providers/file-batches.js.map +1 -0
- package/dist/providers/file-upload.constants.d.ts +1 -0
- package/dist/providers/file-upload.constants.js +68 -0
- package/dist/providers/file-upload.constants.js.map +1 -0
- package/dist/providers/file-upload.d.ts +2 -0
- package/dist/providers/file-upload.js +146 -0
- package/dist/providers/file-upload.js.map +1 -0
- package/dist/providers/firecracker-command.d.ts +5 -0
- package/dist/providers/firecracker-command.js +114 -0
- package/dist/providers/firecracker-command.js.map +1 -0
- package/dist/providers/firecracker-files.constants.d.ts +1 -0
- package/dist/providers/firecracker-files.constants.js +21 -0
- package/dist/providers/firecracker-files.constants.js.map +1 -0
- package/dist/providers/firecracker-files.d.ts +3 -0
- package/dist/providers/firecracker-files.js +110 -0
- package/dist/providers/firecracker-files.js.map +1 -0
- package/dist/providers/firecracker-machine.d.ts +3 -0
- package/dist/providers/firecracker-machine.js +155 -0
- package/dist/providers/firecracker-machine.js.map +1 -0
- package/dist/providers/firecracker.constants.d.ts +10 -0
- package/dist/providers/firecracker.constants.js +11 -0
- package/dist/providers/firecracker.constants.js.map +1 -0
- package/dist/providers/firecracker.d.ts +4 -0
- package/dist/providers/firecracker.js +103 -0
- package/dist/providers/firecracker.js.map +1 -0
- package/dist/providers/firecracker.types.d.ts +36 -0
- package/dist/providers/firecracker.types.js +2 -0
- package/dist/providers/firecracker.types.js.map +1 -0
- package/dist/providers/local.js +2 -1
- package/dist/providers/local.js.map +1 -1
- package/dist/providers/podman.d.ts +2 -0
- package/dist/providers/podman.js.map +1 -1
- package/dist/providers/terminal-bridge.d.ts +14 -0
- package/dist/providers/terminal-bridge.js +100 -0
- package/dist/providers/terminal-bridge.js.map +1 -0
- package/dist/providers/vercel-directory.d.ts +2 -0
- package/dist/providers/vercel-directory.js +7 -0
- package/dist/providers/vercel-directory.js.map +1 -0
- package/dist/providers/vercel-files.js +3 -2
- package/dist/providers/vercel-files.js.map +1 -1
- package/dist/providers/vercel-network.d.ts +2 -0
- package/dist/providers/vercel-network.js +18 -0
- package/dist/providers/vercel-network.js.map +1 -0
- package/dist/providers/vercel.d.ts +1 -0
- package/dist/providers/vercel.js +8 -2
- package/dist/providers/vercel.js.map +1 -1
- package/dist/providers/vercel.types.d.ts +2 -0
- package/dist/providers/vercel.types.js.map +1 -1
- package/dist/providers/versions.constants.d.ts +1 -0
- package/dist/providers/versions.constants.js +1 -0
- package/dist/providers/versions.constants.js.map +1 -1
- package/package.json +16 -1
|
@@ -0,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MAAM,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,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({ 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"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Task } from "../workflow.types.ts";
|
|
2
|
+
export interface WorkflowGate {
|
|
3
|
+
readonly kind: "approval" | "pause";
|
|
4
|
+
readonly prompt: string;
|
|
5
|
+
readonly actors: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export interface WorkflowGateOptions {
|
|
8
|
+
readonly key: string;
|
|
9
|
+
readonly after?: readonly Task[];
|
|
10
|
+
readonly prompt: string;
|
|
11
|
+
readonly actors: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export interface WorkflowPauseRequest extends WorkflowGate {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly requestedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface WorkflowDecision {
|
|
18
|
+
readonly executionId: string;
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly requestId: string;
|
|
21
|
+
readonly action: "approve" | "resume" | "reject";
|
|
22
|
+
readonly actor: string;
|
|
23
|
+
readonly reason: string;
|
|
24
|
+
}
|
|
25
|
+
export interface WorkflowDecisionRecord extends WorkflowDecision {
|
|
26
|
+
readonly decidedAt: string;
|
|
27
|
+
}
|
|
@@ -0,0 +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,11 +1,16 @@
|
|
|
1
|
+
import { checkpointValue } from "./checkpoint-value.js";
|
|
2
|
+
import { WorkflowBudgetExceeded } from "./budget.js";
|
|
1
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
2
4
|
export async function runTask(item, runtime) {
|
|
3
5
|
const { record, signal, context, emit, finish, values, errors, options, stop, } = runtime;
|
|
4
6
|
const state = record(item);
|
|
5
7
|
state.status = "active";
|
|
8
|
+
delete state.error;
|
|
9
|
+
delete state.finishedAt;
|
|
6
10
|
state.startedAt = new Date().toISOString();
|
|
7
11
|
emit({ type: "task", key: item.key, status: "active", attempt: 0 });
|
|
8
12
|
try {
|
|
13
|
+
await runtime.persist();
|
|
9
14
|
signal.throwIfAborted();
|
|
10
15
|
if (item.condition && !(await item.condition(context(item, 0, signal)))) {
|
|
11
16
|
signal.throwIfAborted();
|
|
@@ -13,29 +18,39 @@ export async function runTask(item, runtime) {
|
|
|
13
18
|
return;
|
|
14
19
|
}
|
|
15
20
|
const limit = item.retry?.attempts ?? 1;
|
|
16
|
-
|
|
21
|
+
const priorAttempts = state.attempts;
|
|
22
|
+
for (let cycle = 1; cycle <= limit; cycle++) {
|
|
23
|
+
const attempt = priorAttempts + cycle;
|
|
17
24
|
signal.throwIfAborted();
|
|
25
|
+
runtime.accounting.admit();
|
|
18
26
|
state.attempts = attempt;
|
|
27
|
+
emit({ type: "attempt", key: item.key, attempt });
|
|
28
|
+
await runtime.persist();
|
|
19
29
|
const deadline = new AbortController();
|
|
20
30
|
const timer = item.timeoutMs === undefined
|
|
21
31
|
? undefined
|
|
22
32
|
: setTimeout(() => deadline.abort(new Error(`${item.key} timed out`)), item.timeoutMs);
|
|
23
33
|
const taskSignal = AbortSignal.any([signal, deadline.signal]);
|
|
24
34
|
try {
|
|
35
|
+
taskSignal.throwIfAborted();
|
|
25
36
|
const value = await item.perform(context(item, attempt, taskSignal));
|
|
26
37
|
taskSignal.throwIfAborted();
|
|
38
|
+
if (options.checkpoint)
|
|
39
|
+
checkpointValue(value);
|
|
27
40
|
values.set(item, value);
|
|
28
41
|
finish(item, "done");
|
|
29
42
|
return;
|
|
30
43
|
}
|
|
31
44
|
catch (error) {
|
|
45
|
+
runtime.closeAttempt(item);
|
|
32
46
|
if (signal.aborted ||
|
|
33
|
-
|
|
47
|
+
cycle === limit ||
|
|
34
48
|
item.retry?.accepts?.(error, attempt) === false)
|
|
35
49
|
throw error;
|
|
36
50
|
emit({ type: "retry", key: item.key, attempt });
|
|
37
51
|
}
|
|
38
52
|
finally {
|
|
53
|
+
runtime.closeAttempt(item);
|
|
39
54
|
clearTimeout(timer);
|
|
40
55
|
}
|
|
41
56
|
await delay(item.retry?.delayMs ?? 0, undefined, { signal });
|
|
@@ -43,7 +58,8 @@ export async function runTask(item, runtime) {
|
|
|
43
58
|
}
|
|
44
59
|
catch (error) {
|
|
45
60
|
state.error = error instanceof Error ? error.message : String(error);
|
|
46
|
-
if (signal.aborted
|
|
61
|
+
if (signal.aborted ||
|
|
62
|
+
(error instanceof WorkflowBudgetExceeded && runtime.accounting.exhausted))
|
|
47
63
|
finish(item, "cancelled");
|
|
48
64
|
else {
|
|
49
65
|
errors.push(error);
|
|
@@ -52,5 +68,8 @@ export async function runTask(item, runtime) {
|
|
|
52
68
|
stop.abort(error);
|
|
53
69
|
}
|
|
54
70
|
}
|
|
71
|
+
finally {
|
|
72
|
+
await runtime.persist();
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
75
|
//# sourceMappingURL=task-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-runner.js","sourceRoot":"","sources":["../../../src/domain/workflow/task-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,IAAU,EACV,OAA+B;IAE/B,MAAM,EACJ,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,MAAM,EACN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S,CAAC;gBACT,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC3B,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/D,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,KAAK,YAAY,sBAAsB,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;YAEzE,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 } from \"./budget.ts\";\nimport { setTimeout as delay } from \"node:timers/promises\";\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 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 emit({ type: \"retry\", key: item.key, attempt });\n } finally {\n runtime.closeAttempt(item);\n clearTimeout(timer);\n }\n await delay(item.retry?.delayMs ?? 0, undefined, { signal });\n }\n } catch (error) {\n state.error = error instanceof Error ? error.message : String(error);\n if (\n signal.aborted ||\n (error instanceof WorkflowBudgetExceeded && 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-receipt.constants.js","sourceRoot":"","sources":["../../../src/domain/workflow/usage-receipt.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC","sourcesContent":["export const maxUsageReceiptsPerTask = 65_536;\nexport const maxUsageReceiptLength = 512;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { maxUsageReceiptLength, maxUsageReceiptsPerTask, } from "./usage-receipt.constants.js";
|
|
2
|
+
export function validateUsageReceipt(receipt) {
|
|
3
|
+
if (typeof receipt !== "string" ||
|
|
4
|
+
!receipt.length ||
|
|
5
|
+
receipt.length > maxUsageReceiptLength)
|
|
6
|
+
throw new Error("Invalid workflow usage receipt");
|
|
7
|
+
}
|
|
8
|
+
export function validateUsageReceipts(receipts) {
|
|
9
|
+
if (receipts === undefined)
|
|
10
|
+
return;
|
|
11
|
+
if (!Array.isArray(receipts) || receipts.length > maxUsageReceiptsPerTask)
|
|
12
|
+
throw new Error("Invalid workflow usage receipts");
|
|
13
|
+
for (const receipt of receipts)
|
|
14
|
+
validateUsageReceipt(receipt);
|
|
15
|
+
if (new Set(receipts).size !== receipts.length)
|
|
16
|
+
throw new Error("Duplicate workflow usage receipts");
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=usage-receipt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-receipt.js","sourceRoot":"","sources":["../../../src/domain/workflow/usage-receipt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,UAAU,oBAAoB,CAClC,OAAgB;IAEhB,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,CAAC,OAAO,CAAC,MAAM;QACf,OAAO,CAAC,MAAM,GAAG,qBAAqB;QAEtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACtD,CAAC;AACD,MAAM,UAAU,qBAAqB,CAAC,QAAiB;IACrD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO;IACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,uBAAuB;QACvE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,KAAK,MAAM,OAAO,IAAI,QAAQ;QAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM;QAC5C,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import {\n maxUsageReceiptLength,\n maxUsageReceiptsPerTask,\n} from \"./usage-receipt.constants.ts\";\n\nexport function validateUsageReceipt(\n receipt: unknown,\n): asserts receipt is string {\n if (\n typeof receipt !== \"string\" ||\n !receipt.length ||\n receipt.length > maxUsageReceiptLength\n )\n throw new Error(\"Invalid workflow usage receipt\");\n}\nexport function validateUsageReceipts(receipts: unknown): void {\n if (receipts === undefined) return;\n if (!Array.isArray(receipts) || receipts.length > maxUsageReceiptsPerTask)\n throw new Error(\"Invalid workflow usage receipts\");\n for (const receipt of receipts) validateUsageReceipt(receipt);\n if (new Set(receipts).size !== receipts.length)\n throw new Error(\"Duplicate workflow usage receipts\");\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateGate } from "./gate-validation.js";
|
|
1
2
|
export function positive(value, label) {
|
|
2
3
|
if (!Number.isSafeInteger(value) || value < 1)
|
|
3
4
|
throw new Error(`${label} must be a positive integer`);
|
|
@@ -8,6 +9,11 @@ export function validate(tasks) {
|
|
|
8
9
|
const visiting = new Set();
|
|
9
10
|
const visited = new Set();
|
|
10
11
|
for (const item of tasks) {
|
|
12
|
+
if (item.gate) {
|
|
13
|
+
validateGate(item.gate);
|
|
14
|
+
if (item.condition || item.retry || item.timeoutMs !== undefined)
|
|
15
|
+
throw new Error("Workflow gates cannot have conditions, retries or timeouts");
|
|
16
|
+
}
|
|
11
17
|
if (keys.has(item.key))
|
|
12
18
|
throw new Error(`Duplicate task: ${item.key}`);
|
|
13
19
|
keys.add(item.key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/domain/workflow/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/domain/workflow/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,KAAa;IACnD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAsB;IAC7C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAQ,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAQ,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACxB,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;gBAC9D,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;QACN,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,KAAK;YACjC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,wBAAwB,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,SAAS,KAAK,CAAC,IAAU;QACvB,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3E,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO;QAC9B,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1B,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { validateGate } from \"./gate-validation.ts\";\nimport type { Task } from \"../workflow.types.ts\";\n\nexport function positive(value: number, label: string): void {\n if (!Number.isSafeInteger(value) || value < 1)\n throw new Error(`${label} must be a positive integer`);\n}\n\nexport function validate(tasks: readonly Task[]): void {\n const keys = new Set<string>();\n const members = new Set(tasks);\n const visiting = new Set<Task>();\n const visited = new Set<Task>();\n for (const item of tasks) {\n if (item.gate) {\n validateGate(item.gate);\n if (item.condition || item.retry || item.timeoutMs !== undefined)\n throw new Error(\n \"Workflow gates cannot have conditions, retries or timeouts\",\n );\n }\n if (keys.has(item.key)) throw new Error(`Duplicate task: ${item.key}`);\n keys.add(item.key);\n for (const dependency of item.after)\n if (!members.has(dependency))\n throw new Error(`${item.key}: missing dependency ${dependency.key}`);\n }\n function visit(item: Task): void {\n if (visiting.has(item)) throw new Error(`Dependency cycle at ${item.key}`);\n if (visited.has(item)) return;\n visiting.add(item);\n item.after.forEach(visit);\n visiting.delete(item);\n visited.add(item);\n }\n tasks.forEach(visit);\n}\n"]}
|
|
@@ -1,58 +1,93 @@
|
|
|
1
|
+
import { applyDecisions, pauseGate, prepareDecisions } from "./gates.js";
|
|
2
|
+
import { openCheckpoint } from "./checkpoint.js";
|
|
1
3
|
import { WorkflowFailure } from "./failure.js";
|
|
2
4
|
import { runTask } from "./task-runner.js";
|
|
3
5
|
import { positive } from "./validation.js";
|
|
4
6
|
import { workflowState } from "./workflow-state.js";
|
|
5
7
|
export async function schedule(name, tasks, options) {
|
|
8
|
+
if (!options.checkpoint &&
|
|
9
|
+
(tasks.some((item) => item.gate) || options.decisions?.length))
|
|
10
|
+
throw new Error("Workflow gates and decisions require a checkpoint");
|
|
11
|
+
if (options.decisions && !options.decisions.length)
|
|
12
|
+
throw new Error("Workflow decisions cannot be empty");
|
|
13
|
+
const checkpoint = options.checkpoint
|
|
14
|
+
? await openCheckpoint(name, tasks, options.checkpoint)
|
|
15
|
+
: undefined;
|
|
16
|
+
try {
|
|
17
|
+
return await scheduleRun(name, tasks, options, checkpoint);
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
await checkpoint?.release();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function scheduleRun(name, tasks, options, checkpoint) {
|
|
6
24
|
const concurrency = options.concurrency ?? 1;
|
|
7
25
|
positive(concurrency, "concurrency");
|
|
8
|
-
const state = workflowState(name, tasks, options);
|
|
26
|
+
const state = workflowState(name, tasks, options, checkpoint);
|
|
9
27
|
const { executionId, signal, values, records, errors, observerErrors, record, emit, finish, } = state;
|
|
10
28
|
const active = new Map();
|
|
29
|
+
const started = Date.now();
|
|
30
|
+
const decisions = prepareDecisions(state);
|
|
11
31
|
emit({ type: "start" });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
applyDecisions(state, decisions);
|
|
33
|
+
await state.persist();
|
|
34
|
+
try {
|
|
35
|
+
while (true) {
|
|
36
|
+
let changed = false;
|
|
37
|
+
for (const item of tasks) {
|
|
38
|
+
if (record(item).status !== "waiting")
|
|
39
|
+
continue;
|
|
40
|
+
if (signal.aborted || state.accounting.exhausted) {
|
|
41
|
+
finish(item, "cancelled");
|
|
42
|
+
changed = true;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const dependencies = item.after.map((dependency) => record(dependency).status);
|
|
46
|
+
if (dependencies.some((status) => ["failed", "skipped", "cancelled", "rejected"].includes(status))) {
|
|
47
|
+
finish(item, "skipped");
|
|
48
|
+
changed = true;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (active.size >= concurrency ||
|
|
52
|
+
item.after.some((dependency) => active.has(dependency)) ||
|
|
53
|
+
!dependencies.every((status) => status === "done"))
|
|
54
|
+
continue;
|
|
55
|
+
const running = (item.gate ? pauseGate(item, state) : runTask(item, state)).finally(() => {
|
|
56
|
+
active.delete(item);
|
|
57
|
+
});
|
|
58
|
+
active.set(item, running);
|
|
19
59
|
changed = true;
|
|
20
|
-
continue;
|
|
21
60
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
finish(item, "skipped");
|
|
25
|
-
changed = true;
|
|
61
|
+
if (active.size) {
|
|
62
|
+
await Promise.race(active.values());
|
|
26
63
|
continue;
|
|
27
64
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
continue;
|
|
31
|
-
const running = runTask(item, state).finally(() => {
|
|
32
|
-
active.delete(item);
|
|
33
|
-
});
|
|
34
|
-
active.set(item, running);
|
|
35
|
-
changed = true;
|
|
36
|
-
}
|
|
37
|
-
if (active.size) {
|
|
38
|
-
await Promise.race(active.values());
|
|
39
|
-
continue;
|
|
65
|
+
if (!changed)
|
|
66
|
+
break;
|
|
40
67
|
}
|
|
41
|
-
if (!changed)
|
|
42
|
-
break;
|
|
43
68
|
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
state.stop.abort(error);
|
|
71
|
+
await Promise.allSettled(active.values());
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
await state.persist();
|
|
44
75
|
if (options.signal?.aborted)
|
|
45
76
|
errors.push(options.signal.reason);
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
const paused = [...records.values()].some((entry) => entry.status === "paused");
|
|
78
|
+
let status = "done";
|
|
79
|
+
if (paused)
|
|
80
|
+
status = "paused";
|
|
81
|
+
if (errors.length)
|
|
82
|
+
status = "failed";
|
|
83
|
+
if (options.signal?.aborted)
|
|
84
|
+
status = "cancelled";
|
|
85
|
+
emit({ type: "finish", status, durationMs: Date.now() - started });
|
|
52
86
|
const result = Object.freeze({
|
|
53
87
|
executionId,
|
|
54
88
|
name,
|
|
55
89
|
status,
|
|
90
|
+
usage: state.accounting.snapshot(),
|
|
56
91
|
tasks: Object.freeze([...records.values()].map((value) => Object.freeze({ ...value }))),
|
|
57
92
|
errors: Object.freeze(errors),
|
|
58
93
|
observerErrors: Object.freeze(observerErrors),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-scheduler.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-scheduler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-scheduler.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM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AAI,MAAM;QAAE,MAAM,GAAG,QAAQ,CAAC;IAC9B,IAAI,MAAM,CAAC,MAAM;QAAE,MAAM,GAAG,QAAQ,CAAC;IACrC,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO;QAAE,MAAM,GAAG,WAAW,CAAC;IAClD,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACnE,MAAM,MAAM,GAAmB,MAAM,CAAC,MAAM,CAAC;QAC3C,WAAW;QACX,IAAI;QACJ,MAAM;QACN,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE;QAClC,KAAK,EAAE,MAAM,CAAC,MAAM,CAClB,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAClE;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAC7B,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;QAC7C,KAAK,CAAI,IAAa;YACpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;gBACnB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,GAAG,4CAA4C,CACxD,CAAC;YACJ,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAM,CAAC;QAC/B,CAAC;QACD,MAAM;YACJ,IAAI,MAAM,KAAK,MAAM;gBAAE,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { applyDecisions, pauseGate, prepareDecisions } from \"./gates.ts\";\nimport { openCheckpoint } from \"./checkpoint.ts\";\nimport type { WorkflowCheckpointSession } from \"./checkpoint.types.ts\";\nimport type {\n Task,\n WorkflowOptions,\n WorkflowResult,\n} from \"../workflow.types.ts\";\nimport { WorkflowFailure } from \"./failure.ts\";\nimport { runTask } from \"./task-runner.ts\";\nimport { positive } from \"./validation.ts\";\nimport { workflowState } from \"./workflow-state.ts\";\n\nexport async function schedule(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n): Promise<WorkflowResult> {\n if (\n !options.checkpoint &&\n (tasks.some((item) => item.gate) || options.decisions?.length)\n )\n throw new Error(\"Workflow gates and decisions require a checkpoint\");\n if (options.decisions && !options.decisions.length)\n throw new Error(\"Workflow decisions cannot be empty\");\n const checkpoint = options.checkpoint\n ? await openCheckpoint(name, tasks, options.checkpoint)\n : undefined;\n try {\n return await scheduleRun(name, tasks, options, checkpoint);\n } finally {\n await checkpoint?.release();\n }\n}\n\nasync function scheduleRun(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n checkpoint?: WorkflowCheckpointSession,\n): Promise<WorkflowResult> {\n const concurrency = options.concurrency ?? 1;\n positive(concurrency, \"concurrency\");\n const state = workflowState(name, tasks, options, checkpoint);\n const {\n executionId,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n } = state;\n const active = new Map<Task, Promise<void>>();\n const started = Date.now();\n const decisions = prepareDecisions(state);\n emit({ type: \"start\" });\n applyDecisions(state, decisions);\n await state.persist();\n try {\n while (true) {\n let changed = false;\n for (const item of tasks) {\n if (record(item).status !== \"waiting\") continue;\n if (signal.aborted || state.accounting.exhausted) {\n finish(item, \"cancelled\");\n changed = true;\n continue;\n }\n const dependencies = item.after.map(\n (dependency) => record(dependency).status,\n );\n if (\n dependencies.some((status) =>\n [\"failed\", \"skipped\", \"cancelled\", \"rejected\"].includes(status),\n )\n ) {\n finish(item, \"skipped\");\n changed = true;\n continue;\n }\n if (\n active.size >= concurrency ||\n item.after.some((dependency) => active.has(dependency)) ||\n !dependencies.every((status) => status === \"done\")\n )\n continue;\n const running = (\n item.gate ? pauseGate(item, state) : runTask(item, state)\n ).finally(() => {\n active.delete(item);\n });\n active.set(item, running);\n changed = true;\n }\n if (active.size) {\n await Promise.race(active.values());\n continue;\n }\n if (!changed) break;\n }\n } catch (error) {\n state.stop.abort(error);\n await Promise.allSettled(active.values());\n throw error;\n }\n await state.persist();\n if (options.signal?.aborted) errors.push(options.signal.reason);\n const paused = [...records.values()].some(\n (entry) => entry.status === \"paused\",\n );\n let status: WorkflowResult[\"status\"] = \"done\";\n if (paused) status = \"paused\";\n if (errors.length) status = \"failed\";\n if (options.signal?.aborted) status = \"cancelled\";\n emit({ type: \"finish\", status, durationMs: Date.now() - started });\n const result: WorkflowResult = Object.freeze({\n executionId,\n name,\n status,\n usage: state.accounting.snapshot(),\n tasks: Object.freeze(\n [...records.values()].map((value) => Object.freeze({ ...value })),\n ),\n errors: Object.freeze(errors),\n observerErrors: Object.freeze(observerErrors),\n value<T>(item: Task<T>): T {\n if (!values.has(item))\n throw new Error(\n `${item.key} has no successful value in this execution`,\n );\n return values.get(item) as T;\n },\n unwrap() {\n if (status !== \"done\") throw new WorkflowFailure(result);\n },\n });\n return result;\n}\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { WorkflowCheckpointSession } from "./checkpoint.types.ts";
|
|
1
2
|
import type { Task, WorkflowExecutionState, WorkflowOptions } from "../workflow.types.ts";
|
|
2
|
-
export declare function workflowState(name: string, tasks: readonly Task[], options: WorkflowOptions): WorkflowExecutionState;
|
|
3
|
+
export declare function workflowState(name: string, tasks: readonly Task[], options: WorkflowOptions, checkpoint?: WorkflowCheckpointSession): WorkflowExecutionState;
|
|
@@ -1,16 +1,64 @@
|
|
|
1
|
+
import { maxUsageReceiptsPerTask } from "./usage-receipt.constants.js";
|
|
2
|
+
import { validateUsageReceipt } from "./usage-receipt.js";
|
|
3
|
+
import { workflowAccounting } from "./budget.js";
|
|
1
4
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
export function workflowState(name, tasks, options) {
|
|
3
|
-
const executionId = randomUUID();
|
|
5
|
+
export function workflowState(name, tasks, options, checkpoint) {
|
|
6
|
+
const executionId = checkpoint?.initial?.executionId ?? randomUUID();
|
|
4
7
|
const stop = new AbortController();
|
|
5
8
|
const signal = options.signal
|
|
6
9
|
? AbortSignal.any([options.signal, stop.signal])
|
|
7
10
|
: stop.signal;
|
|
8
11
|
const values = new Map();
|
|
12
|
+
const activeAttempts = new Map();
|
|
9
13
|
const records = new Map(tasks.map((item) => [
|
|
10
14
|
item,
|
|
11
15
|
{ key: item.key, status: "waiting", attempts: 0 },
|
|
12
16
|
]));
|
|
17
|
+
const saved = checkpoint?.initial;
|
|
18
|
+
if (saved) {
|
|
19
|
+
const complete = saved.records.every((entry) => ["done", "skipped"].includes(entry.status));
|
|
20
|
+
const settledPause = saved.records.some((entry) => ["paused", "rejected"].includes(entry.status)) &&
|
|
21
|
+
saved.records.every((entry) => ["done", "skipped", "paused", "rejected"].includes(entry.status) ||
|
|
22
|
+
(entry.status === "waiting" && entry.attempts === 0));
|
|
23
|
+
for (const item of tasks) {
|
|
24
|
+
const entry = saved.records.find((entry) => entry.key === item.key);
|
|
25
|
+
records.set(item, {
|
|
26
|
+
...entry,
|
|
27
|
+
...(entry.usageReceipts
|
|
28
|
+
? { usageReceipts: Object.freeze([...entry.usageReceipts]) }
|
|
29
|
+
: {}),
|
|
30
|
+
...(entry.pause
|
|
31
|
+
? {
|
|
32
|
+
pause: Object.freeze({
|
|
33
|
+
...entry.pause,
|
|
34
|
+
actors: Object.freeze([...entry.pause.actors]),
|
|
35
|
+
}),
|
|
36
|
+
}
|
|
37
|
+
: {}),
|
|
38
|
+
...(entry.decision
|
|
39
|
+
? { decision: Object.freeze({ ...entry.decision }) }
|
|
40
|
+
: {}),
|
|
41
|
+
status: ["done", "paused", "rejected"].includes(entry.status) ||
|
|
42
|
+
complete ||
|
|
43
|
+
(settledPause && entry.status === "skipped")
|
|
44
|
+
? entry.status
|
|
45
|
+
: "waiting",
|
|
46
|
+
});
|
|
47
|
+
if (entry.status === "done") {
|
|
48
|
+
const output = saved.values[item.key];
|
|
49
|
+
values.set(item, output.kind === "json" ? output.value : undefined);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
13
53
|
const errors = [], observerErrors = [];
|
|
54
|
+
for (const entry of records.values())
|
|
55
|
+
if (entry.status === "rejected")
|
|
56
|
+
errors.push(new Error(entry.error));
|
|
57
|
+
const accounting = workflowAccounting(options.budget, (error) => {
|
|
58
|
+
errors.push(error);
|
|
59
|
+
if (error.dimension !== "attempts")
|
|
60
|
+
stop.abort(error);
|
|
61
|
+
}, saved?.usage);
|
|
14
62
|
const record = (item) => records.get(item);
|
|
15
63
|
function emit(event) {
|
|
16
64
|
try {
|
|
@@ -35,13 +83,61 @@ export function workflowState(name, tasks, options) {
|
|
|
35
83
|
key: item.key,
|
|
36
84
|
status,
|
|
37
85
|
attempt: record(item).attempts,
|
|
86
|
+
...(record(item).startedAt
|
|
87
|
+
? { durationMs: Date.now() - Date.parse(record(item).startedAt) }
|
|
88
|
+
: {}),
|
|
38
89
|
});
|
|
39
90
|
}
|
|
40
91
|
function context(item, attempt, taskSignal) {
|
|
92
|
+
if (attempt > 0)
|
|
93
|
+
activeAttempts.set(item, attempt);
|
|
94
|
+
function report(usage, receipt) {
|
|
95
|
+
const current = record(item);
|
|
96
|
+
if (attempt === 0 ||
|
|
97
|
+
current.status !== "active" ||
|
|
98
|
+
activeAttempts.get(item) !== attempt)
|
|
99
|
+
throw new Error("Usage must be reported during its active task attempt");
|
|
100
|
+
if (receipt !== undefined) {
|
|
101
|
+
validateUsageReceipt(receipt);
|
|
102
|
+
if (current.usageReceipts?.includes(receipt))
|
|
103
|
+
return;
|
|
104
|
+
if ((current.usageReceipts?.length ?? 0) >= maxUsageReceiptsPerTask)
|
|
105
|
+
throw new Error("Workflow usage receipt limit exceeded");
|
|
106
|
+
}
|
|
107
|
+
const previousReceipts = current.usageReceipts;
|
|
108
|
+
if (receipt !== undefined)
|
|
109
|
+
current.usageReceipts = Object.freeze([
|
|
110
|
+
...(previousReceipts ?? []),
|
|
111
|
+
receipt,
|
|
112
|
+
]);
|
|
113
|
+
try {
|
|
114
|
+
accounting.report(usage);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (previousReceipts)
|
|
118
|
+
current.usageReceipts = previousReceipts;
|
|
119
|
+
else
|
|
120
|
+
delete current.usageReceipts;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
void runtime.persist().catch((error) => stop.abort(error));
|
|
124
|
+
emit({
|
|
125
|
+
type: "usage",
|
|
126
|
+
key: item.key,
|
|
127
|
+
attempt,
|
|
128
|
+
usage: Object.freeze({ ...usage }),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
41
131
|
return {
|
|
42
132
|
signal: taskSignal,
|
|
43
133
|
attempt,
|
|
44
134
|
executionId,
|
|
135
|
+
checkpoint: () => runtime.persist(),
|
|
136
|
+
reportUsage: (usage) => report(usage),
|
|
137
|
+
reportUsageOnce: (receipt, usage) => {
|
|
138
|
+
validateUsageReceipt(receipt);
|
|
139
|
+
report(usage, receipt);
|
|
140
|
+
},
|
|
45
141
|
value(dependency) {
|
|
46
142
|
if (!item.after.includes(dependency))
|
|
47
143
|
throw new Error(`${item.key}: undeclared dependency ${dependency.key}`);
|
|
@@ -51,8 +147,15 @@ export function workflowState(name, tasks, options) {
|
|
|
51
147
|
},
|
|
52
148
|
};
|
|
53
149
|
}
|
|
54
|
-
|
|
150
|
+
const runtime = {
|
|
151
|
+
async persist() {
|
|
152
|
+
await checkpoint?.save(runtime);
|
|
153
|
+
},
|
|
55
154
|
executionId,
|
|
155
|
+
accounting,
|
|
156
|
+
closeAttempt(item) {
|
|
157
|
+
activeAttempts.delete(item);
|
|
158
|
+
},
|
|
56
159
|
stop,
|
|
57
160
|
signal,
|
|
58
161
|
values,
|
|
@@ -65,5 +168,6 @@ export function workflowState(name, tasks, options) {
|
|
|
65
168
|
context,
|
|
66
169
|
options,
|
|
67
170
|
};
|
|
171
|
+
return runtime;
|
|
68
172
|
}
|
|
69
173
|
//# sourceMappingURL=workflow-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-state.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,KAAsB,EACtB,OAAwB;IAExB,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM;QAC3B,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAChB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,CACrB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QAClB,IAAI;QACJ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,EAAE;KAClD,CAAC,CACH,CAAC;IACF,MAAM,MAAM,GAAc,EAAE,EAC1B,cAAc,GAAc,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAClD,SAAS,IAAI,CACX,KAAoE;QAEpE,IAAI,CAAC;YACH,OAAO,CAAC,OAAO,EAAE,CAAC;gBAChB,GAAG,KAAK;gBACR,WAAW;gBACX,QAAQ,EAAE,IAAI;gBACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WA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,\n TaskContext,\n TaskRecord,\n TaskStatus,\n WorkflowEvent,\n WorkflowExecutionState,\n WorkflowOptions,\n} from \"../workflow.types.ts\";\n\nexport function workflowState(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n): WorkflowExecutionState {\n const executionId = randomUUID();\n const stop = new AbortController();\n const signal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n const values = new Map<Task, unknown>();\n const records = new Map<Task, TaskRecord>(\n tasks.map((item) => [\n item,\n { key: item.key, status: \"waiting\", attempts: 0 },\n ]),\n );\n const errors: unknown[] = [],\n observerErrors: unknown[] = [];\n const record = (item: Task) => records.get(item)!;\n function emit(\n event: Omit<WorkflowEvent, \"executionId\" | \"workflow\" | \"timestamp\">,\n ): void {\n try {\n options.observe?.({\n ...event,\n executionId,\n workflow: name,\n timestamp: new Date().toISOString(),\n });\n } catch (error) {\n observerErrors.push(error);\n }\n }\n function finish(item: Task, status: TaskStatus): void {\n Object.assign(record(item), {\n status,\n finishedAt: new Date().toISOString(),\n });\n emit({\n type: \"task\",\n key: item.key,\n status,\n attempt: record(item).attempts,\n });\n }\n function context(\n item: Task,\n attempt: number,\n taskSignal: AbortSignal,\n ): TaskContext {\n return {\n signal: taskSignal,\n attempt,\n executionId,\n value<T>(dependency: Task<T>): T {\n if (!item.after.includes(dependency))\n throw new Error(\n `${item.key}: undeclared dependency ${dependency.key}`,\n );\n if (!values.has(dependency))\n throw new Error(`${dependency.key} has no successful value`);\n return values.get(dependency) as T;\n },\n };\n }\n\n return {\n executionId,\n stop,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n context,\n options,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflow-state.js","sourceRoot":"","sources":["../../../src/domain/workflow/workflow-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;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MAAM,CAAC,KAAK,CAAC;YACrC,eAAe,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;gBAClC,oBAAoB,CAAC,OAAO,CAAC,CAAC;gBAC9B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACzB,CAAC;YACD,KAAK,CAAI,UAAmB;gBAC1B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;oBAClC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,GAAG,2BAA2B,UAAU,CAAC,GAAG,EAAE,CACvD,CAAC;gBACJ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;oBACzB,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,GAAG,0BAA0B,CAAC,CAAC;gBAC/D,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,CAAM,CAAC;YACrC,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAA2B;QACtC,KAAK,CAAC,OAAO;YACX,MAAM,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,WAAW;QACX,UAAU;QACV,YAAY,CAAC,IAAI;YACf,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI;QACJ,MAAM;QACN,MAAM;QACN,OAAO;QACP,MAAM;QACN,cAAc;QACd,MAAM;QACN,IAAI;QACJ,MAAM;QACN,OAAO;QACP,OAAO;KACR,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { maxUsageReceiptsPerTask } from \"./usage-receipt.constants.ts\";\nimport { validateUsageReceipt } from \"./usage-receipt.ts\";\nimport type { Usage } from \"../agent.types.ts\";\nimport type { WorkflowCheckpointSession } from \"./checkpoint.types.ts\";\nimport { workflowAccounting } from \"./budget.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type {\n Task,\n TaskContext,\n TaskRecord,\n TaskStatus,\n WorkflowEvent,\n WorkflowExecutionState,\n WorkflowOptions,\n} from \"../workflow.types.ts\";\n\nexport function workflowState(\n name: string,\n tasks: readonly Task[],\n options: WorkflowOptions,\n checkpoint?: WorkflowCheckpointSession,\n): WorkflowExecutionState {\n const executionId = checkpoint?.initial?.executionId ?? randomUUID();\n const stop = new AbortController();\n const signal = options.signal\n ? AbortSignal.any([options.signal, stop.signal])\n : stop.signal;\n const values = new Map<Task, unknown>();\n const activeAttempts = new Map<Task, number>();\n const records = new Map<Task, TaskRecord>(\n tasks.map((item) => [\n item,\n { key: item.key, status: \"waiting\", attempts: 0 },\n ]),\n );\n const saved = checkpoint?.initial;\n if (saved) {\n const complete = saved.records.every((entry) =>\n [\"done\", \"skipped\"].includes(entry.status),\n );\n const settledPause =\n saved.records.some((entry) =>\n [\"paused\", \"rejected\"].includes(entry.status),\n ) &&\n saved.records.every(\n (entry) =>\n [\"done\", \"skipped\", \"paused\", \"rejected\"].includes(entry.status) ||\n (entry.status === \"waiting\" && entry.attempts === 0),\n );\n for (const item of tasks) {\n const entry = saved.records.find((entry) => entry.key === item.key)!;\n records.set(item, {\n ...entry,\n ...(entry.usageReceipts\n ? { usageReceipts: Object.freeze([...entry.usageReceipts]) }\n : {}),\n ...(entry.pause\n ? {\n pause: Object.freeze({\n ...entry.pause,\n actors: Object.freeze([...entry.pause.actors]),\n }),\n }\n : {}),\n ...(entry.decision\n ? { decision: Object.freeze({ ...entry.decision }) }\n : {}),\n status:\n [\"done\", \"paused\", \"rejected\"].includes(entry.status) ||\n complete ||\n (settledPause && entry.status === \"skipped\")\n ? entry.status\n : \"waiting\",\n });\n if (entry.status === \"done\") {\n const output = saved.values[item.key]!;\n values.set(item, output.kind === \"json\" ? output.value : undefined);\n }\n }\n }\n const errors: unknown[] = [],\n observerErrors: unknown[] = [];\n for (const entry of records.values())\n if (entry.status === \"rejected\") errors.push(new Error(entry.error));\n const accounting = workflowAccounting(\n options.budget,\n (error) => {\n errors.push(error);\n if (error.dimension !== \"attempts\") stop.abort(error);\n },\n saved?.usage,\n );\n const record = (item: Task) => records.get(item)!;\n function emit(\n event: Omit<WorkflowEvent, \"executionId\" | \"workflow\" | \"timestamp\">,\n ): void {\n try {\n options.observe?.({\n ...event,\n executionId,\n workflow: name,\n timestamp: new Date().toISOString(),\n });\n } catch (error) {\n observerErrors.push(error);\n }\n }\n function finish(item: Task, status: TaskStatus): void {\n Object.assign(record(item), {\n status,\n finishedAt: new Date().toISOString(),\n });\n emit({\n type: \"task\",\n key: item.key,\n status,\n attempt: record(item).attempts,\n ...(record(item).startedAt\n ? { durationMs: Date.now() - Date.parse(record(item).startedAt!) }\n : {}),\n });\n }\n function context(\n item: Task,\n attempt: number,\n taskSignal: AbortSignal,\n ): TaskContext {\n if (attempt > 0) activeAttempts.set(item, attempt);\n function report(usage: Usage, receipt?: string): void {\n const current = record(item);\n if (\n attempt === 0 ||\n current.status !== \"active\" ||\n activeAttempts.get(item) !== attempt\n )\n throw new Error(\n \"Usage must be reported during its active task attempt\",\n );\n if (receipt !== undefined) {\n validateUsageReceipt(receipt);\n if (current.usageReceipts?.includes(receipt)) return;\n if ((current.usageReceipts?.length ?? 0) >= maxUsageReceiptsPerTask)\n throw new Error(\"Workflow usage receipt limit exceeded\");\n }\n const previousReceipts = current.usageReceipts;\n if (receipt !== undefined)\n current.usageReceipts = Object.freeze([\n ...(previousReceipts ?? []),\n receipt,\n ]);\n try {\n accounting.report(usage);\n } catch (error) {\n if (previousReceipts) current.usageReceipts = previousReceipts;\n else delete current.usageReceipts;\n throw error;\n }\n void runtime.persist().catch((error: unknown) => stop.abort(error));\n emit({\n type: \"usage\",\n key: item.key,\n attempt,\n usage: Object.freeze({ ...usage }),\n });\n }\n\n return {\n signal: taskSignal,\n attempt,\n executionId,\n checkpoint: () => runtime.persist(),\n reportUsage: (usage) => report(usage),\n reportUsageOnce: (receipt, usage) => {\n validateUsageReceipt(receipt);\n report(usage, receipt);\n },\n value<T>(dependency: Task<T>): T {\n if (!item.after.includes(dependency))\n throw new Error(\n `${item.key}: undeclared dependency ${dependency.key}`,\n );\n if (!values.has(dependency))\n throw new Error(`${dependency.key} has no successful value`);\n return values.get(dependency) as T;\n },\n };\n }\n\n const runtime: WorkflowExecutionState = {\n async persist() {\n await checkpoint?.save(runtime);\n },\n executionId,\n accounting,\n closeAttempt(item) {\n activeAttempts.delete(item);\n },\n stop,\n signal,\n values,\n records,\n errors,\n observerErrors,\n record,\n emit,\n finish,\n context,\n options,\n };\n return runtime;\n}\n"]}
|
|
@@ -3,3 +3,5 @@ export type { Retry, Task, TaskContext, TaskOptions, TaskRecord, TaskStatus, Wor
|
|
|
3
3
|
export { WorkflowFailure } from "./workflow/failure.ts";
|
|
4
4
|
export { task } from "./workflow/task.ts";
|
|
5
5
|
export declare function workflow(name: string, tasks: readonly Task[]): Workflow;
|
|
6
|
+
export { WorkflowBudgetExceeded } from "./workflow/budget.ts";
|
|
7
|
+
export type { WorkflowBudget, WorkflowUsage } from "./workflow/budget.types.ts";
|