@shipfox/api-workflows 2.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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +311 -0
- package/LICENSE +21 -0
- package/dist/core/agent-tool-capability-warning.d.ts +7 -0
- package/dist/core/agent-tool-capability-warning.d.ts.map +1 -0
- package/dist/core/agent-tool-capability-warning.js +149 -0
- package/dist/core/agent-tool-capability-warning.js.map +1 -0
- package/dist/core/agent-tools.d.ts +51 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +296 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/checkout.d.ts +29 -0
- package/dist/core/checkout.d.ts.map +1 -0
- package/dist/core/checkout.js +42 -0
- package/dist/core/checkout.js.map +1 -0
- package/dist/core/condition-trace.d.ts +13 -0
- package/dist/core/condition-trace.d.ts.map +1 -0
- package/dist/core/condition-trace.js +51 -0
- package/dist/core/condition-trace.js.map +1 -0
- package/dist/core/entities/index.d.ts +5 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +3 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/job-execution.d.ts +30 -0
- package/dist/core/entities/job-execution.d.ts.map +1 -0
- package/dist/core/entities/job-execution.js +3 -0
- package/dist/core/entities/job-execution.js.map +1 -0
- package/dist/core/entities/job-listener-event.d.ts +15 -0
- package/dist/core/entities/job-listener-event.d.ts.map +1 -0
- package/dist/core/entities/job-listener-event.js +3 -0
- package/dist/core/entities/job-listener-event.js.map +1 -0
- package/dist/core/entities/job.d.ts +54 -0
- package/dist/core/entities/job.d.ts.map +1 -0
- package/dist/core/entities/job.js +29 -0
- package/dist/core/entities/job.js.map +1 -0
- package/dist/core/entities/step.d.ts +86 -0
- package/dist/core/entities/step.d.ts.map +1 -0
- package/dist/core/entities/step.js +12 -0
- package/dist/core/entities/step.js.map +1 -0
- package/dist/core/entities/workflow-run-attempt.d.ts +20 -0
- package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -0
- package/dist/core/entities/workflow-run-attempt.js +3 -0
- package/dist/core/entities/workflow-run-attempt.js.map +1 -0
- package/dist/core/entities/workflow-run.d.ts +66 -0
- package/dist/core/entities/workflow-run.d.ts.map +1 -0
- package/dist/core/entities/workflow-run.js +10 -0
- package/dist/core/entities/workflow-run.js.map +1 -0
- package/dist/core/errors.d.ts +85 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +134 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-execution-outcome.d.ts +29 -0
- package/dist/core/job-execution-outcome.d.ts.map +1 -0
- package/dist/core/job-execution-outcome.js +31 -0
- package/dist/core/job-execution-outcome.js.map +1 -0
- package/dist/core/job-execution.d.ts +37 -0
- package/dist/core/job-execution.d.ts.map +1 -0
- package/dist/core/job-execution.js +425 -0
- package/dist/core/job-execution.js.map +1 -0
- package/dist/core/job-transition/decide-job-activation.d.ts +29 -0
- package/dist/core/job-transition/decide-job-activation.d.ts.map +1 -0
- package/dist/core/job-transition/decide-job-activation.js +51 -0
- package/dist/core/job-transition/decide-job-activation.js.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts +18 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js +23 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js.map +1 -0
- package/dist/core/job-transition/derive-job-success.d.ts +16 -0
- package/dist/core/job-transition/derive-job-success.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-success.js +47 -0
- package/dist/core/job-transition/derive-job-success.js.map +1 -0
- package/dist/core/job-transition/index.d.ts +5 -0
- package/dist/core/job-transition/index.d.ts.map +1 -0
- package/dist/core/job-transition/index.js +6 -0
- package/dist/core/job-transition/index.js.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts +4 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js +8 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js.map +1 -0
- package/dist/core/listener-execution-materialization.d.ts +30 -0
- package/dist/core/listener-execution-materialization.d.ts.map +1 -0
- package/dist/core/listener-execution-materialization.js +87 -0
- package/dist/core/listener-execution-materialization.js.map +1 -0
- package/dist/core/run-workflow.d.ts +11 -0
- package/dist/core/run-workflow.d.ts.map +1 -0
- package/dist/core/run-workflow.js +28 -0
- package/dist/core/run-workflow.js.map +1 -0
- package/dist/core/source-control.d.ts +5 -0
- package/dist/core/source-control.d.ts.map +1 -0
- package/dist/core/source-control.js +19 -0
- package/dist/core/source-control.js.map +1 -0
- package/dist/core/step-config/agent.d.ts +49 -0
- package/dist/core/step-config/agent.d.ts.map +1 -0
- package/dist/core/step-config/agent.js +337 -0
- package/dist/core/step-config/agent.js.map +1 -0
- package/dist/core/step-config/assemble-run-context.d.ts +94 -0
- package/dist/core/step-config/assemble-run-context.d.ts.map +1 -0
- package/dist/core/step-config/assemble-run-context.js +393 -0
- package/dist/core/step-config/assemble-run-context.js.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts +13 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.js +38 -0
- package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -0
- package/dist/core/step-config/fields.d.ts +38 -0
- package/dist/core/step-config/fields.d.ts.map +1 -0
- package/dist/core/step-config/fields.js +72 -0
- package/dist/core/step-config/fields.js.map +1 -0
- package/dist/core/step-config/index.d.ts +8 -0
- package/dist/core/step-config/index.d.ts.map +1 -0
- package/dist/core/step-config/index.js +7 -0
- package/dist/core/step-config/index.js.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts +35 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.js +92 -0
- package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts +42 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.js +96 -0
- package/dist/core/step-config/materialize-workflow-model.js.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts +18 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.js +36 -0
- package/dist/core/step-config/resolve-job-execution-name.js.map +1 -0
- package/dist/core/step-config/resolve-step-config.d.ts +33 -0
- package/dist/core/step-config/resolve-step-config.d.ts.map +1 -0
- package/dist/core/step-config/resolve-step-config.js +164 -0
- package/dist/core/step-config/resolve-step-config.js.map +1 -0
- package/dist/core/step-config/run.d.ts +39 -0
- package/dist/core/step-config/run.d.ts.map +1 -0
- package/dist/core/step-config/run.js +360 -0
- package/dist/core/step-config/run.js.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts +6 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.js +3 -0
- package/dist/core/step-config/workflow-evaluation-context.js.map +1 -0
- package/dist/core/step-transition/apply-step-transition.d.ts +26 -0
- package/dist/core/step-transition/apply-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/apply-step-transition.js +141 -0
- package/dist/core/step-transition/apply-step-transition.js.map +1 -0
- package/dist/core/step-transition/decide-step-transition.d.ts +71 -0
- package/dist/core/step-transition/decide-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/decide-step-transition.js +110 -0
- package/dist/core/step-transition/decide-step-transition.js.map +1 -0
- package/dist/core/step-transition/evaluate-gate.d.ts +28 -0
- package/dist/core/step-transition/evaluate-gate.d.ts.map +1 -0
- package/dist/core/step-transition/evaluate-gate.js +159 -0
- package/dist/core/step-transition/evaluate-gate.js.map +1 -0
- package/dist/core/step-transition/read-step-outputs.d.ts +3 -0
- package/dist/core/step-transition/read-step-outputs.d.ts.map +1 -0
- package/dist/core/step-transition/read-step-outputs.js +24 -0
- package/dist/core/step-transition/read-step-outputs.js.map +1 -0
- package/dist/core/workflow-run-creation.d.ts +43 -0
- package/dist/core/workflow-run-creation.d.ts.map +1 -0
- package/dist/core/workflow-run-creation.js +80 -0
- package/dist/core/workflow-run-creation.js.map +1 -0
- package/dist/core/workflow-scheduling/index.d.ts +5 -0
- package/dist/core/workflow-scheduling/index.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/index.js +4 -0
- package/dist/core/workflow-scheduling/index.js.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts +20 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.js +40 -0
- package/dist/core/workflow-scheduling/run-progress.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts +10 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.js +3 -0
- package/dist/core/workflow-scheduling/runtime-dag.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts +16 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js +3 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts +9 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js +72 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js.map +1 -0
- package/dist/db/db.d.ts +4959 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +37 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +9 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-listener-events.d.ts +18 -0
- package/dist/db/job-listener-events.d.ts.map +1 -0
- package/dist/db/job-listener-events.js +59 -0
- package/dist/db/job-listener-events.js.map +1 -0
- package/dist/db/job-listeners.d.ts +55 -0
- package/dist/db/job-listeners.d.ts.map +1 -0
- package/dist/db/job-listeners.js +358 -0
- package/dist/db/job-listeners.js.map +1 -0
- package/dist/db/outbox-writes.d.ts +12 -0
- package/dist/db/outbox-writes.d.ts.map +1 -0
- package/dist/db/outbox-writes.js +20 -0
- package/dist/db/outbox-writes.js.map +1 -0
- package/dist/db/runner-lease-table.d.ts +469 -0
- package/dist/db/runner-lease-table.d.ts.map +1 -0
- package/dist/db/runner-lease-table.js +42 -0
- package/dist/db/runner-lease-table.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/job-executions.d.ts +311 -0
- package/dist/db/schema/job-executions.d.ts.map +1 -0
- package/dist/db/schema/job-executions.js +76 -0
- package/dist/db/schema/job-executions.js.map +1 -0
- package/dist/db/schema/job-listener-events.d.ts +200 -0
- package/dist/db/schema/job-listener-events.d.ts.map +1 -0
- package/dist/db/schema/job-listener-events.js +50 -0
- package/dist/db/schema/job-listener-events.js.map +1 -0
- package/dist/db/schema/jobs.d.ts +542 -0
- package/dist/db/schema/jobs.d.ts.map +1 -0
- package/dist/db/schema/jobs.js +121 -0
- package/dist/db/schema/jobs.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/step-attempts.d.ts +330 -0
- package/dist/db/schema/step-attempts.d.ts.map +1 -0
- package/dist/db/schema/step-attempts.js +80 -0
- package/dist/db/schema/step-attempts.js.map +1 -0
- package/dist/db/schema/steps.d.ts +352 -0
- package/dist/db/schema/steps.d.ts.map +1 -0
- package/dist/db/schema/steps.js +80 -0
- package/dist/db/schema/steps.js.map +1 -0
- package/dist/db/schema/workflow-run-attempts.d.ts +239 -0
- package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -0
- package/dist/db/schema/workflow-run-attempts.js +53 -0
- package/dist/db/schema/workflow-run-attempts.js.map +1 -0
- package/dist/db/schema/workflow-runs.d.ts +360 -0
- package/dist/db/schema/workflow-runs.d.ts.map +1 -0
- package/dist/db/schema/workflow-runs.js +85 -0
- package/dist/db/schema/workflow-runs.js.map +1 -0
- package/dist/db/workflow-runs/job-executions.d.ts +49 -0
- package/dist/db/workflow-runs/job-executions.d.ts.map +1 -0
- package/dist/db/workflow-runs/job-executions.js +271 -0
- package/dist/db/workflow-runs/job-executions.js.map +1 -0
- package/dist/db/workflow-runs/jobs.d.ts +60 -0
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -0
- package/dist/db/workflow-runs/jobs.js +288 -0
- package/dist/db/workflow-runs/jobs.js.map +1 -0
- package/dist/db/workflow-runs/outbox.d.ts +20 -0
- package/dist/db/workflow-runs/outbox.d.ts.map +1 -0
- package/dist/db/workflow-runs/outbox.js +68 -0
- package/dist/db/workflow-runs/outbox.js.map +1 -0
- package/dist/db/workflow-runs/queries.d.ts +71 -0
- package/dist/db/workflow-runs/queries.d.ts.map +1 -0
- package/dist/db/workflow-runs/queries.js +253 -0
- package/dist/db/workflow-runs/queries.js.map +1 -0
- package/dist/db/workflow-runs/run-create.d.ts +32 -0
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-create.js +288 -0
- package/dist/db/workflow-runs/run-create.js.map +1 -0
- package/dist/db/workflow-runs/run-graph.d.ts +27 -0
- package/dist/db/workflow-runs/run-graph.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-graph.js +63 -0
- package/dist/db/workflow-runs/run-graph.js.map +1 -0
- package/dist/db/workflow-runs/run-rerun.d.ts +8 -0
- package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-rerun.js +207 -0
- package/dist/db/workflow-runs/run-rerun.js.map +1 -0
- package/dist/db/workflow-runs/run-status.d.ts +24 -0
- package/dist/db/workflow-runs/run-status.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-status.js +249 -0
- package/dist/db/workflow-runs/run-status.js.map +1 -0
- package/dist/db/workflow-runs/runs.d.ts +7 -0
- package/dist/db/workflow-runs/runs.d.ts.map +1 -0
- package/dist/db/workflow-runs/runs.js +5 -0
- package/dist/db/workflow-runs/runs.js.map +1 -0
- package/dist/db/workflow-runs/shared.d.ts +24 -0
- package/dist/db/workflow-runs/shared.d.ts.map +1 -0
- package/dist/db/workflow-runs/shared.js +50 -0
- package/dist/db/workflow-runs/shared.js.map +1 -0
- package/dist/db/workflow-runs/steps.d.ts +83 -0
- package/dist/db/workflow-runs/steps.d.ts.map +1 -0
- package/dist/db/workflow-runs/steps.js +246 -0
- package/dist/db/workflow-runs/steps.js.map +1 -0
- package/dist/db/workflow-runs.d.ts +12 -0
- package/dist/db/workflow-runs.d.ts.map +1 -0
- package/dist/db/workflow-runs.js +8 -0
- package/dist/db/workflow-runs.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +20 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +127 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +30 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/dto/checkout-token.d.ts +6 -0
- package/dist/presentation/dto/checkout-token.d.ts.map +1 -0
- package/dist/presentation/dto/checkout-token.js +74 -0
- package/dist/presentation/dto/checkout-token.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +4 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +5 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/job.d.ts +6 -0
- package/dist/presentation/dto/job.d.ts.map +1 -0
- package/dist/presentation/dto/job.js +59 -0
- package/dist/presentation/dto/job.js.map +1 -0
- package/dist/presentation/dto/step.d.ts +6 -0
- package/dist/presentation/dto/step.d.ts.map +1 -0
- package/dist/presentation/dto/step.js +162 -0
- package/dist/presentation/dto/step.js.map +1 -0
- package/dist/presentation/dto/workflow-run.d.ts +6 -0
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -0
- package/dist/presentation/dto/workflow-run.js +35 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -0
- package/dist/presentation/index.d.ts +3 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +4 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts +2 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.js +71 -0
- package/dist/presentation/routes/agent-runtime-config.js.map +1 -0
- package/dist/presentation/routes/cancel-run.d.ts +2 -0
- package/dist/presentation/routes/cancel-run.d.ts.map +1 -0
- package/dist/presentation/routes/cancel-run.js +46 -0
- package/dist/presentation/routes/cancel-run.js.map +1 -0
- package/dist/presentation/routes/checkout-token.d.ts +2 -0
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -0
- package/dist/presentation/routes/checkout-token.js +64 -0
- package/dist/presentation/routes/checkout-token.js.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts +2 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.js +60 -0
- package/dist/presentation/routes/get-run-aggregates.js.map +1 -0
- package/dist/presentation/routes/get-run.d.ts +2 -0
- package/dist/presentation/routes/get-run.d.ts.map +1 -0
- package/dist/presentation/routes/get-run.js +60 -0
- package/dist/presentation/routes/get-run.js.map +1 -0
- package/dist/presentation/routes/get-step-secrets.d.ts +2 -0
- package/dist/presentation/routes/get-step-secrets.d.ts.map +1 -0
- package/dist/presentation/routes/get-step-secrets.js +115 -0
- package/dist/presentation/routes/get-step-secrets.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +4 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +41 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/leased-step.d.ts +14 -0
- package/dist/presentation/routes/leased-step.d.ts.map +1 -0
- package/dist/presentation/routes/leased-step.js +50 -0
- package/dist/presentation/routes/leased-step.js.map +1 -0
- package/dist/presentation/routes/list-run-attempts.d.ts +2 -0
- package/dist/presentation/routes/list-run-attempts.d.ts.map +1 -0
- package/dist/presentation/routes/list-run-attempts.js +35 -0
- package/dist/presentation/routes/list-run-attempts.js.map +1 -0
- package/dist/presentation/routes/list-runs.d.ts +2 -0
- package/dist/presentation/routes/list-runs.d.ts.map +1 -0
- package/dist/presentation/routes/list-runs.js +70 -0
- package/dist/presentation/routes/list-runs.js.map +1 -0
- package/dist/presentation/routes/next-step.d.ts +2 -0
- package/dist/presentation/routes/next-step.d.ts.map +1 -0
- package/dist/presentation/routes/next-step.js +65 -0
- package/dist/presentation/routes/next-step.js.map +1 -0
- package/dist/presentation/routes/report-step.d.ts +2 -0
- package/dist/presentation/routes/report-step.d.ts.map +1 -0
- package/dist/presentation/routes/report-step.js +73 -0
- package/dist/presentation/routes/report-step.js.map +1 -0
- package/dist/presentation/routes/require-accessible-run.d.ts +7 -0
- package/dist/presentation/routes/require-accessible-run.d.ts.map +1 -0
- package/dist/presentation/routes/require-accessible-run.js +25 -0
- package/dist/presentation/routes/require-accessible-run.js.map +1 -0
- package/dist/presentation/routes/rerun-run.d.ts +2 -0
- package/dist/presentation/routes/rerun-run.d.ts.map +1 -0
- package/dist/presentation/routes/rerun-run.js +56 -0
- package/dist/presentation/routes/rerun-run.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +8 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +9 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js +24 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js +36 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js +35 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js +35 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js +25 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +23 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +26 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/orchestration-activities.d.ts +130 -0
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -0
- package/dist/temporal/activities/orchestration-activities.js +188 -0
- package/dist/temporal/activities/orchestration-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +7 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +8 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/index.d.ts +3 -0
- package/dist/temporal/index.d.ts.map +1 -0
- package/dist/temporal/index.js +4 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/workflow-not-found.d.ts +2 -0
- package/dist/temporal/workflow-not-found.d.ts.map +1 -0
- package/dist/temporal/workflow-not-found.js +10 -0
- package/dist/temporal/workflow-not-found.js.map +1 -0
- package/dist/temporal/workflows/deadline.d.ts +3 -0
- package/dist/temporal/workflows/deadline.d.ts.map +1 -0
- package/dist/temporal/workflows/deadline.js +8 -0
- package/dist/temporal/workflows/deadline.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +4 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +5 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts +27 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.js +265 -0
- package/dist/temporal/workflows/job-execution-orchestration.js.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts +40 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.js +332 -0
- package/dist/temporal/workflows/job-listener-orchestration.js.map +1 -0
- package/dist/temporal/workflows/run-orchestration.d.ts +8 -0
- package/dist/temporal/workflows/run-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/run-orchestration.js +243 -0
- package/dist/temporal/workflows/run-orchestration.js.map +1 -0
- package/dist/temporal/workflows/test-env.d.ts +114 -0
- package/dist/temporal/workflows/test-env.d.ts.map +1 -0
- package/dist/temporal/workflows/test-env.js +323 -0
- package/dist/temporal/workflows/test-env.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +211 -0
- package/drizzle/0001_agent_tool_materialization.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +1613 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +7 -0
- package/package.json +91 -0
- package/src/core/README.md +79 -0
- package/src/core/agent-tool-capability-warning.test.ts +280 -0
- package/src/core/agent-tool-capability-warning.ts +200 -0
- package/src/core/agent-tools.ts +422 -0
- package/src/core/checkout.test.ts +112 -0
- package/src/core/checkout.ts +63 -0
- package/src/core/condition-trace.ts +64 -0
- package/src/core/entities/index.ts +9 -0
- package/src/core/entities/job-execution.ts +32 -0
- package/src/core/entities/job-listener-event.ts +15 -0
- package/src/core/entities/job.ts +91 -0
- package/src/core/entities/step.ts +126 -0
- package/src/core/entities/workflow-run-attempt.ts +21 -0
- package/src/core/entities/workflow-run.ts +94 -0
- package/src/core/errors.test.ts +45 -0
- package/src/core/errors.ts +209 -0
- package/src/core/index.ts +54 -0
- package/src/core/job-execution-outcome.ts +64 -0
- package/src/core/job-execution.test.ts +1560 -0
- package/src/core/job-execution.ts +581 -0
- package/src/core/job-transition/decide-job-activation.test.ts +196 -0
- package/src/core/job-transition/decide-job-activation.ts +79 -0
- package/src/core/job-transition/derive-job-execution-outputs.ts +41 -0
- package/src/core/job-transition/derive-job-success.test.ts +133 -0
- package/src/core/job-transition/derive-job-success.ts +67 -0
- package/src/core/job-transition/index.ts +11 -0
- package/src/core/job-transition/runtime-completion-status-for-job.ts +14 -0
- package/src/core/listener-execution-materialization.test.ts +49 -0
- package/src/core/listener-execution-materialization.ts +162 -0
- package/src/core/run-workflow.test.ts +229 -0
- package/src/core/run-workflow.ts +41 -0
- package/src/core/source-control.test.ts +17 -0
- package/src/core/source-control.ts +22 -0
- package/src/core/step-config/agent.ts +459 -0
- package/src/core/step-config/assemble-run-context.test.ts +1021 -0
- package/src/core/step-config/assemble-run-context.ts +535 -0
- package/src/core/step-config/complete-step-dispatch-config.test.ts +354 -0
- package/src/core/step-config/complete-step-dispatch-config.ts +40 -0
- package/src/core/step-config/fields.ts +111 -0
- package/src/core/step-config/index.ts +41 -0
- package/src/core/step-config/materialize-job-execution-steps.test.ts +494 -0
- package/src/core/step-config/materialize-job-execution-steps.ts +136 -0
- package/src/core/step-config/materialize-workflow-model.test.ts +1214 -0
- package/src/core/step-config/materialize-workflow-model.ts +140 -0
- package/src/core/step-config/resolve-job-execution-name.test.ts +94 -0
- package/src/core/step-config/resolve-job-execution-name.ts +51 -0
- package/src/core/step-config/resolve-step-config.ts +199 -0
- package/src/core/step-config/run.ts +467 -0
- package/src/core/step-config/workflow-evaluation-context.ts +6 -0
- package/src/core/step-transition/apply-step-transition.ts +163 -0
- package/src/core/step-transition/decide-step-transition.test.ts +307 -0
- package/src/core/step-transition/decide-step-transition.ts +200 -0
- package/src/core/step-transition/evaluate-gate.test.ts +317 -0
- package/src/core/step-transition/evaluate-gate.ts +168 -0
- package/src/core/step-transition/read-step-outputs.ts +27 -0
- package/src/core/workflow-run-creation.test.ts +155 -0
- package/src/core/workflow-run-creation.ts +131 -0
- package/src/core/workflow-scheduling/index.ts +15 -0
- package/src/core/workflow-scheduling/run-progress.test.ts +46 -0
- package/src/core/workflow-scheduling/run-progress.ts +68 -0
- package/src/core/workflow-scheduling/runtime-dag.ts +10 -0
- package/src/core/workflow-scheduling/runtime-scheduling-command.ts +20 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.test.ts +197 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.ts +115 -0
- package/src/db/db.ts +40 -0
- package/src/db/index.ts +86 -0
- package/src/db/job-listener-events.test.ts +113 -0
- package/src/db/job-listener-events.ts +73 -0
- package/src/db/job-listeners.test.ts +865 -0
- package/src/db/job-listeners.ts +564 -0
- package/src/db/outbox-writes.ts +40 -0
- package/src/db/rerun-listener.test.ts +64 -0
- package/src/db/run-timeout.test.ts +102 -0
- package/src/db/runner-lease-table.ts +39 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/job-executions.ts +85 -0
- package/src/db/schema/job-listener-events.ts +58 -0
- package/src/db/schema/jobs.ts +136 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/step-attempts.ts +99 -0
- package/src/db/schema/steps.ts +99 -0
- package/src/db/schema/workflow-run-attempts.ts +59 -0
- package/src/db/schema/workflow-runs.ts +112 -0
- package/src/db/workflow-runs/job-executions.test.ts +99 -0
- package/src/db/workflow-runs/job-executions.ts +421 -0
- package/src/db/workflow-runs/job-status.test.ts +532 -0
- package/src/db/workflow-runs/jobs.test.ts +194 -0
- package/src/db/workflow-runs/jobs.ts +418 -0
- package/src/db/workflow-runs/outbox.ts +109 -0
- package/src/db/workflow-runs/queries.test.ts +256 -0
- package/src/db/workflow-runs/queries.ts +437 -0
- package/src/db/workflow-runs/run-create.test.ts +1281 -0
- package/src/db/workflow-runs/run-create.ts +373 -0
- package/src/db/workflow-runs/run-graph.ts +95 -0
- package/src/db/workflow-runs/run-rerun.test.ts +625 -0
- package/src/db/workflow-runs/run-rerun.ts +266 -0
- package/src/db/workflow-runs/run-status.test.ts +425 -0
- package/src/db/workflow-runs/run-status.ts +391 -0
- package/src/db/workflow-runs/runs.ts +17 -0
- package/src/db/workflow-runs/shared.ts +84 -0
- package/src/db/workflow-runs/steps.test.ts +191 -0
- package/src/db/workflow-runs/steps.ts +476 -0
- package/src/db/workflow-runs.ts +111 -0
- package/src/index.ts +99 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +160 -0
- package/src/metrics/service.ts +30 -0
- package/src/presentation/dto/checkout-token.test.ts +107 -0
- package/src/presentation/dto/checkout-token.ts +85 -0
- package/src/presentation/dto/index.ts +3 -0
- package/src/presentation/dto/job.test.ts +108 -0
- package/src/presentation/dto/job.ts +64 -0
- package/src/presentation/dto/step.test.ts +307 -0
- package/src/presentation/dto/step.ts +145 -0
- package/src/presentation/dto/workflow-run.ts +38 -0
- package/src/presentation/index.ts +10 -0
- package/src/presentation/routes/agent-runtime-config.test.ts +478 -0
- package/src/presentation/routes/agent-runtime-config.ts +81 -0
- package/src/presentation/routes/cancel-run.test.ts +156 -0
- package/src/presentation/routes/cancel-run.ts +37 -0
- package/src/presentation/routes/checkout-token.test.ts +366 -0
- package/src/presentation/routes/checkout-token.ts +61 -0
- package/src/presentation/routes/get-run-aggregates.test.ts +114 -0
- package/src/presentation/routes/get-run-aggregates.ts +69 -0
- package/src/presentation/routes/get-run.test.ts +604 -0
- package/src/presentation/routes/get-run.ts +66 -0
- package/src/presentation/routes/get-step-secrets.test.ts +260 -0
- package/src/presentation/routes/get-step-secrets.ts +117 -0
- package/src/presentation/routes/index.test.ts +71 -0
- package/src/presentation/routes/index.ts +42 -0
- package/src/presentation/routes/leased-step.ts +54 -0
- package/src/presentation/routes/list-run-attempts.test.ts +163 -0
- package/src/presentation/routes/list-run-attempts.ts +27 -0
- package/src/presentation/routes/list-runs.test.ts +244 -0
- package/src/presentation/routes/list-runs.ts +83 -0
- package/src/presentation/routes/next-step.test.ts +366 -0
- package/src/presentation/routes/next-step.ts +62 -0
- package/src/presentation/routes/report-step.test.ts +374 -0
- package/src/presentation/routes/report-step.ts +61 -0
- package/src/presentation/routes/require-accessible-run.ts +27 -0
- package/src/presentation/routes/rerun-run.test.ts +202 -0
- package/src/presentation/routes/rerun-run.ts +48 -0
- package/src/presentation/subscribers/index.ts +7 -0
- package/src/presentation/subscribers/on-job-event-delivered.test.ts +71 -0
- package/src/presentation/subscribers/on-job-event-delivered.ts +30 -0
- package/src/presentation/subscribers/on-job-steps-settled.test.ts +75 -0
- package/src/presentation/subscribers/on-job-steps-settled.ts +42 -0
- package/src/presentation/subscribers/on-runner-job-claimed.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-claimed.ts +23 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.test.ts +73 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.ts +36 -0
- package/src/presentation/subscribers/on-runner-job-queued.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-queued.ts +23 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.test.ts +69 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.ts +40 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.test.ts +59 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.ts +29 -0
- package/src/temporal/activities/index.ts +45 -0
- package/src/temporal/activities/orchestration-activities.test.ts +115 -0
- package/src/temporal/activities/orchestration-activities.ts +305 -0
- package/src/temporal/constants.ts +6 -0
- package/src/temporal/index.ts +6 -0
- package/src/temporal/workflow-not-found.ts +9 -0
- package/src/temporal/workflows/deadline.ts +7 -0
- package/src/temporal/workflows/index.ts +11 -0
- package/src/temporal/workflows/job-execution-orchestration-timeout.test.ts +165 -0
- package/src/temporal/workflows/job-execution-orchestration.test.ts +311 -0
- package/src/temporal/workflows/job-execution-orchestration.ts +314 -0
- package/src/temporal/workflows/job-listener-orchestration-continuation.test.ts +93 -0
- package/src/temporal/workflows/job-listener-orchestration.test.ts +406 -0
- package/src/temporal/workflows/job-listener-orchestration.ts +490 -0
- package/src/temporal/workflows/run-orchestration.test.ts +409 -0
- package/src/temporal/workflows/run-orchestration.ts +283 -0
- package/src/temporal/workflows/test-env.ts +409 -0
- package/test/env.ts +11 -0
- package/test/factories/job.ts +83 -0
- package/test/factories/project.ts +16 -0
- package/test/factories/workflow-model.test.ts +26 -0
- package/test/factories/workflow-model.ts +268 -0
- package/test/factories/workflow-run.ts +58 -0
- package/test/fixtures/active-lease-token.ts +85 -0
- package/test/fixtures/job-with-steps.ts +42 -0
- package/test/fixtures/lease-token.ts +44 -0
- package/test/fixtures/strip-setup-step.ts +23 -0
- package/test/globalSetup.ts +54 -0
- package/test/helpers/workflow-runs.ts +210 -0
- package/test/index.ts +3 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { paginateTimestampIdRows, timestampIdCursorWhere } from '@shipfox/node-drizzle';
|
|
2
|
+
import { and, asc, count, desc, eq, gte, lte, sql } from 'drizzle-orm';
|
|
3
|
+
import { db } from '../db.js';
|
|
4
|
+
import { jobExecutions, toJobExecution } from '../schema/job-executions.js';
|
|
5
|
+
import { jobs, toJob } from '../schema/jobs.js';
|
|
6
|
+
import { stepAttempts, toStepAttempt } from '../schema/step-attempts.js';
|
|
7
|
+
import { steps, toStep } from '../schema/steps.js';
|
|
8
|
+
import { toWorkflowRunAttempt, workflowRunAttempts } from '../schema/workflow-run-attempts.js';
|
|
9
|
+
import { toWorkflowRun, workflowRuns } from '../schema/workflow-runs.js';
|
|
10
|
+
export async function getWorkflowRunById(id) {
|
|
11
|
+
const rows = await db().select().from(workflowRuns).where(eq(workflowRuns.id, id)).limit(1);
|
|
12
|
+
const row = rows[0];
|
|
13
|
+
if (!row) return undefined;
|
|
14
|
+
return toWorkflowRun(row);
|
|
15
|
+
}
|
|
16
|
+
export async function getWorkflowRunByAttemptId(workflowRunAttemptId) {
|
|
17
|
+
const rows = await db().select({
|
|
18
|
+
run: workflowRuns
|
|
19
|
+
}).from(workflowRunAttempts).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).where(eq(workflowRunAttempts.id, workflowRunAttemptId)).limit(1);
|
|
20
|
+
const row = rows[0];
|
|
21
|
+
return row ? toWorkflowRun(row.run) : undefined;
|
|
22
|
+
}
|
|
23
|
+
export async function getWorkflowRunAttemptById(workflowRunAttemptId) {
|
|
24
|
+
const rows = await db().select().from(workflowRunAttempts).where(eq(workflowRunAttempts.id, workflowRunAttemptId)).limit(1);
|
|
25
|
+
const row = rows[0];
|
|
26
|
+
return row ? toWorkflowRunAttempt(row) : undefined;
|
|
27
|
+
}
|
|
28
|
+
export async function listRunAttempts(params) {
|
|
29
|
+
return (await db().select({
|
|
30
|
+
attempt: workflowRunAttempts
|
|
31
|
+
}).from(workflowRunAttempts).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).where(and(eq(workflowRunAttempts.workflowRunId, params.workflowRunId), eq(workflowRuns.projectId, params.projectId))).orderBy(asc(workflowRunAttempts.attempt))).map((row)=>toWorkflowRunAttempt(row.attempt));
|
|
32
|
+
}
|
|
33
|
+
export async function getLatestAttempt(params) {
|
|
34
|
+
const [row] = await db().select({
|
|
35
|
+
value: sql`coalesce(max(${workflowRunAttempts.attempt}), 1)`
|
|
36
|
+
}).from(workflowRunAttempts).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).where(and(eq(workflowRunAttempts.workflowRunId, params.workflowRunId), eq(workflowRuns.projectId, params.projectId))).limit(1);
|
|
37
|
+
return Number(row?.value ?? 1);
|
|
38
|
+
}
|
|
39
|
+
export function buildWorkflowRunListConditions(params) {
|
|
40
|
+
const filters = params.filters;
|
|
41
|
+
const conditions = [
|
|
42
|
+
eq(workflowRuns.projectId, params.projectId)
|
|
43
|
+
];
|
|
44
|
+
const cursorCondition = timestampIdCursorWhere({
|
|
45
|
+
timestampColumn: workflowRuns.createdAt,
|
|
46
|
+
idColumn: workflowRuns.id,
|
|
47
|
+
cursor: params.cursor
|
|
48
|
+
});
|
|
49
|
+
if (cursorCondition) conditions.push(cursorCondition);
|
|
50
|
+
if (filters?.status && params.omit !== 'status') {
|
|
51
|
+
conditions.push(eq(workflowRuns.status, filters.status));
|
|
52
|
+
}
|
|
53
|
+
if (filters?.definitionId && params.omit !== 'definitionId') {
|
|
54
|
+
conditions.push(eq(workflowRuns.definitionId, filters.definitionId));
|
|
55
|
+
}
|
|
56
|
+
if (filters?.triggerSource && params.omit !== 'triggerSource') {
|
|
57
|
+
conditions.push(eq(workflowRuns.triggerSource, filters.triggerSource));
|
|
58
|
+
}
|
|
59
|
+
if (filters?.createdFrom) {
|
|
60
|
+
conditions.push(gte(workflowRuns.createdAt, filters.createdFrom));
|
|
61
|
+
}
|
|
62
|
+
if (filters?.createdTo) {
|
|
63
|
+
conditions.push(lte(workflowRuns.createdAt, filters.createdTo));
|
|
64
|
+
}
|
|
65
|
+
return conditions;
|
|
66
|
+
}
|
|
67
|
+
export async function listWorkflowRuns(params) {
|
|
68
|
+
const conditions = buildWorkflowRunListConditions(params);
|
|
69
|
+
const rows = await db().select().from(workflowRuns).where(and(...conditions)).orderBy(desc(workflowRuns.createdAt), desc(workflowRuns.id)).limit(params.limit + 1);
|
|
70
|
+
let totalCount = null;
|
|
71
|
+
if (params.includeTotal) {
|
|
72
|
+
const [{ value } = {
|
|
73
|
+
value: 0
|
|
74
|
+
}] = await db().select({
|
|
75
|
+
value: count()
|
|
76
|
+
}).from(workflowRuns).where(and(...buildWorkflowRunListConditions({
|
|
77
|
+
projectId: params.projectId,
|
|
78
|
+
filters: params.filters
|
|
79
|
+
})));
|
|
80
|
+
totalCount = value;
|
|
81
|
+
}
|
|
82
|
+
const page = paginateTimestampIdRows({
|
|
83
|
+
rows,
|
|
84
|
+
limit: params.limit,
|
|
85
|
+
timestampKey: 'createdAt'
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
runs: page.pageRows.map(toWorkflowRun),
|
|
89
|
+
nextCursor: page.nextCursor,
|
|
90
|
+
filteredTotalCount: totalCount
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export async function listWorkflowRunsByProject(projectId) {
|
|
94
|
+
const result = await listWorkflowRuns({
|
|
95
|
+
projectId,
|
|
96
|
+
limit: 100
|
|
97
|
+
});
|
|
98
|
+
return result.runs;
|
|
99
|
+
}
|
|
100
|
+
export async function getWorkflowRunAggregates(params) {
|
|
101
|
+
const [statusRows, triggerRows, workflowRows] = await Promise.all([
|
|
102
|
+
db().select({
|
|
103
|
+
value: workflowRuns.status,
|
|
104
|
+
count: count()
|
|
105
|
+
}).from(workflowRuns).where(and(...buildWorkflowRunListConditions({
|
|
106
|
+
projectId: params.projectId,
|
|
107
|
+
filters: params.filters,
|
|
108
|
+
omit: 'status'
|
|
109
|
+
}))).groupBy(workflowRuns.status),
|
|
110
|
+
db().select({
|
|
111
|
+
value: workflowRuns.triggerSource,
|
|
112
|
+
count: count()
|
|
113
|
+
}).from(workflowRuns).where(and(...buildWorkflowRunListConditions({
|
|
114
|
+
projectId: params.projectId,
|
|
115
|
+
filters: params.filters,
|
|
116
|
+
omit: 'triggerSource'
|
|
117
|
+
}))).groupBy(workflowRuns.triggerSource),
|
|
118
|
+
db().select({
|
|
119
|
+
value: workflowRuns.definitionId,
|
|
120
|
+
count: count()
|
|
121
|
+
}).from(workflowRuns).where(and(...buildWorkflowRunListConditions({
|
|
122
|
+
projectId: params.projectId,
|
|
123
|
+
filters: params.filters,
|
|
124
|
+
omit: 'definitionId'
|
|
125
|
+
}))).groupBy(workflowRuns.definitionId)
|
|
126
|
+
]);
|
|
127
|
+
return {
|
|
128
|
+
status: statusRows,
|
|
129
|
+
triggerSource: triggerRows,
|
|
130
|
+
workflow: workflowRows
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export async function getWorkflowJobExecutionDepth(params = {}) {
|
|
134
|
+
const runConditions = [
|
|
135
|
+
eq(workflowRuns.status, 'running')
|
|
136
|
+
];
|
|
137
|
+
const jobConditions = [
|
|
138
|
+
eq(jobExecutions.status, 'running')
|
|
139
|
+
];
|
|
140
|
+
if (params.workspaceId) {
|
|
141
|
+
runConditions.push(eq(workflowRuns.workspaceId, params.workspaceId));
|
|
142
|
+
jobConditions.push(eq(workflowRuns.workspaceId, params.workspaceId));
|
|
143
|
+
}
|
|
144
|
+
const [runRows, jobRows] = await Promise.all([
|
|
145
|
+
db().select({
|
|
146
|
+
value: count()
|
|
147
|
+
}).from(workflowRuns).where(and(...runConditions)),
|
|
148
|
+
db().select({
|
|
149
|
+
value: count()
|
|
150
|
+
}).from(jobExecutions).innerJoin(jobs, eq(jobExecutions.jobId, jobs.id)).innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id)).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).where(and(...jobConditions))
|
|
151
|
+
]);
|
|
152
|
+
return {
|
|
153
|
+
runningRuns: runRows[0]?.value ?? 0,
|
|
154
|
+
runningJobExecutions: jobRows[0]?.value ?? 0
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export async function getWorkflowRunDetail(workflowRunId, attempt) {
|
|
158
|
+
const [target] = await db().select({
|
|
159
|
+
run: workflowRuns,
|
|
160
|
+
attempt: workflowRunAttempts
|
|
161
|
+
}).from(workflowRuns).innerJoin(workflowRunAttempts, and(eq(workflowRunAttempts.workflowRunId, workflowRuns.id), eq(workflowRunAttempts.attempt, attempt ?? workflowRuns.currentAttempt))).where(eq(workflowRuns.id, workflowRunId)).limit(1);
|
|
162
|
+
if (!target) return undefined;
|
|
163
|
+
const latestAttempt = await getLatestAttempt({
|
|
164
|
+
workflowRunId: target.run.id,
|
|
165
|
+
projectId: target.run.projectId
|
|
166
|
+
});
|
|
167
|
+
const rows = await db().select({
|
|
168
|
+
run: workflowRuns,
|
|
169
|
+
job: jobs,
|
|
170
|
+
jobExecution: jobExecutions,
|
|
171
|
+
step: steps,
|
|
172
|
+
stepAttempt: stepAttempts
|
|
173
|
+
}).from(workflowRuns).innerJoin(workflowRunAttempts, eq(workflowRunAttempts.id, target.attempt.id)).leftJoin(jobs, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id)).leftJoin(jobExecutions, eq(jobExecutions.jobId, jobs.id)).leftJoin(steps, eq(steps.jobExecutionId, jobExecutions.id)).leftJoin(stepAttempts, eq(stepAttempts.stepId, steps.id)).where(eq(workflowRuns.id, workflowRunId)).orderBy(asc(jobs.position), asc(jobs.id), asc(jobExecutions.sequence), asc(jobExecutions.id), asc(steps.position), asc(steps.id), asc(stepAttempts.executionOrder), asc(stepAttempts.id));
|
|
174
|
+
return hydrateWorkflowRunDetail(rows, target.attempt, latestAttempt);
|
|
175
|
+
}
|
|
176
|
+
export async function getJobExecutionDetail(jobExecutionId) {
|
|
177
|
+
const rows = await db().select({
|
|
178
|
+
jobExecution: jobExecutions,
|
|
179
|
+
step: steps,
|
|
180
|
+
stepAttempt: stepAttempts
|
|
181
|
+
}).from(jobExecutions).innerJoin(jobs, eq(jobExecutions.jobId, jobs.id)).innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id)).innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id)).leftJoin(steps, eq(steps.jobExecutionId, jobExecutions.id)).leftJoin(stepAttempts, eq(stepAttempts.stepId, steps.id)).where(eq(jobExecutions.id, jobExecutionId)).orderBy(asc(steps.position), asc(steps.id), asc(stepAttempts.executionOrder), asc(stepAttempts.id));
|
|
182
|
+
const first = rows[0];
|
|
183
|
+
if (!first) return undefined;
|
|
184
|
+
const detail = {
|
|
185
|
+
...toJobExecution(first.jobExecution),
|
|
186
|
+
steps: []
|
|
187
|
+
};
|
|
188
|
+
const stepById = new Map();
|
|
189
|
+
for (const row of rows){
|
|
190
|
+
if (row.step) {
|
|
191
|
+
const step = getOrCreateStepDetail(stepById, detail.steps, row.step);
|
|
192
|
+
if (row.stepAttempt) {
|
|
193
|
+
step.attempts.push(toStepAttempt(row.stepAttempt));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return detail;
|
|
198
|
+
}
|
|
199
|
+
function hydrateWorkflowRunDetail(rows, attempt, latestAttempt) {
|
|
200
|
+
const first = rows[0];
|
|
201
|
+
if (!first) return undefined;
|
|
202
|
+
const detail = {
|
|
203
|
+
...toWorkflowRun(first.run),
|
|
204
|
+
runAttempt: toWorkflowRunAttempt(attempt),
|
|
205
|
+
latestAttempt,
|
|
206
|
+
jobs: []
|
|
207
|
+
};
|
|
208
|
+
const jobById = new Map();
|
|
209
|
+
const jobExecutionById = new Map();
|
|
210
|
+
const stepById = new Map();
|
|
211
|
+
for (const row of rows){
|
|
212
|
+
if (!row.job) continue;
|
|
213
|
+
let job = jobById.get(row.job.id);
|
|
214
|
+
if (!job) {
|
|
215
|
+
job = {
|
|
216
|
+
...toJob(row.job),
|
|
217
|
+
jobExecutions: []
|
|
218
|
+
};
|
|
219
|
+
jobById.set(row.job.id, job);
|
|
220
|
+
detail.jobs.push(job);
|
|
221
|
+
}
|
|
222
|
+
if (!row.jobExecution) continue;
|
|
223
|
+
let jobExecution = jobExecutionById.get(row.jobExecution.id);
|
|
224
|
+
if (!jobExecution) {
|
|
225
|
+
jobExecution = {
|
|
226
|
+
...toJobExecution(row.jobExecution),
|
|
227
|
+
steps: []
|
|
228
|
+
};
|
|
229
|
+
jobExecutionById.set(row.jobExecution.id, jobExecution);
|
|
230
|
+
job.jobExecutions.push(jobExecution);
|
|
231
|
+
}
|
|
232
|
+
if (!row.step) continue;
|
|
233
|
+
const step = getOrCreateStepDetail(stepById, jobExecution.steps, row.step);
|
|
234
|
+
if (row.stepAttempt) {
|
|
235
|
+
step.attempts.push(toStepAttempt(row.stepAttempt));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return detail;
|
|
239
|
+
}
|
|
240
|
+
function getOrCreateStepDetail(stepById, target, row) {
|
|
241
|
+
let step = stepById.get(row.id);
|
|
242
|
+
if (!step) {
|
|
243
|
+
step = {
|
|
244
|
+
...toStep(row),
|
|
245
|
+
attempts: []
|
|
246
|
+
};
|
|
247
|
+
stepById.set(row.id, step);
|
|
248
|
+
target.push(step);
|
|
249
|
+
}
|
|
250
|
+
return step;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/db/workflow-runs/queries.ts"],"sourcesContent":["import {\n paginateTimestampIdRows,\n type TimestampIdCursor,\n timestampIdCursorWhere,\n} from '@shipfox/node-drizzle';\nimport {and, asc, count, desc, eq, gte, lte, type SQL, sql} from 'drizzle-orm';\nimport type {\n JobExecutionDetail,\n StepDetail,\n WorkflowJobDetail,\n WorkflowRun,\n WorkflowRunDetail,\n WorkflowRunStatus,\n} from '#core/entities/workflow-run.js';\nimport {db} from '../db.js';\nimport {jobExecutions, toJobExecution} from '../schema/job-executions.js';\nimport {jobs, toJob} from '../schema/jobs.js';\nimport {stepAttempts, toStepAttempt} from '../schema/step-attempts.js';\nimport {steps, toStep} from '../schema/steps.js';\nimport {toWorkflowRunAttempt, workflowRunAttempts} from '../schema/workflow-run-attempts.js';\nimport {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';\n\nexport type WorkflowRunCursor = TimestampIdCursor;\n\nexport interface WorkflowRunFilters {\n status?: WorkflowRunStatus | undefined;\n definitionId?: string | undefined;\n triggerSource?: string | undefined;\n createdFrom?: Date | undefined;\n createdTo?: Date | undefined;\n}\n\nexport interface ListWorkflowRunsParams {\n projectId: string;\n limit: number;\n cursor?: WorkflowRunCursor | undefined;\n filters?: WorkflowRunFilters | undefined;\n includeTotal?: boolean | undefined;\n}\n\nexport interface ListWorkflowRunsResult {\n runs: WorkflowRun[];\n nextCursor: WorkflowRunCursor | null;\n filteredTotalCount: number | null;\n}\n\nexport interface WorkflowRunAggregates {\n status: Array<{value: WorkflowRunStatus; count: number}>;\n triggerSource: Array<{value: string; count: number}>;\n workflow: Array<{value: string; count: number}>;\n}\n\nexport interface WorkflowJobExecutionDepth {\n runningRuns: number;\n runningJobExecutions: number;\n}\n\nexport interface WorkflowJobExecutionDepthParams {\n workspaceId?: string;\n}\n\nexport async function getWorkflowRunById(id: string): Promise<WorkflowRun | undefined> {\n const rows = await db().select().from(workflowRuns).where(eq(workflowRuns.id, id)).limit(1);\n const row = rows[0];\n if (!row) return undefined;\n return toWorkflowRun(row);\n}\n\nexport async function getWorkflowRunByAttemptId(\n workflowRunAttemptId: string,\n): Promise<WorkflowRun | undefined> {\n const rows = await db()\n .select({run: workflowRuns})\n .from(workflowRunAttempts)\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(eq(workflowRunAttempts.id, workflowRunAttemptId))\n .limit(1);\n const row = rows[0];\n return row ? toWorkflowRun(row.run) : undefined;\n}\n\nexport async function getWorkflowRunAttemptById(workflowRunAttemptId: string) {\n const rows = await db()\n .select()\n .from(workflowRunAttempts)\n .where(eq(workflowRunAttempts.id, workflowRunAttemptId))\n .limit(1);\n const row = rows[0];\n return row ? toWorkflowRunAttempt(row) : undefined;\n}\n\nexport async function listRunAttempts(params: {workflowRunId: string; projectId: string}) {\n return (\n await db()\n .select({\n attempt: workflowRunAttempts,\n })\n .from(workflowRunAttempts)\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(\n and(\n eq(workflowRunAttempts.workflowRunId, params.workflowRunId),\n eq(workflowRuns.projectId, params.projectId),\n ),\n )\n .orderBy(asc(workflowRunAttempts.attempt))\n ).map((row) => toWorkflowRunAttempt(row.attempt));\n}\n\nexport async function getLatestAttempt(params: {\n workflowRunId: string;\n projectId: string;\n}): Promise<number> {\n const [row] = await db()\n .select({value: sql<number>`coalesce(max(${workflowRunAttempts.attempt}), 1)`})\n .from(workflowRunAttempts)\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(\n and(\n eq(workflowRunAttempts.workflowRunId, params.workflowRunId),\n eq(workflowRuns.projectId, params.projectId),\n ),\n )\n .limit(1);\n\n return Number(row?.value ?? 1);\n}\n\nexport function buildWorkflowRunListConditions(params: {\n projectId: string;\n filters?: WorkflowRunFilters | undefined;\n cursor?: WorkflowRunCursor | undefined;\n omit?: 'status' | 'definitionId' | 'triggerSource' | undefined;\n}): SQL[] {\n const filters = params.filters;\n const conditions: SQL[] = [eq(workflowRuns.projectId, params.projectId)];\n const cursorCondition = timestampIdCursorWhere({\n timestampColumn: workflowRuns.createdAt,\n idColumn: workflowRuns.id,\n cursor: params.cursor,\n });\n if (cursorCondition) conditions.push(cursorCondition);\n if (filters?.status && params.omit !== 'status') {\n conditions.push(eq(workflowRuns.status, filters.status));\n }\n if (filters?.definitionId && params.omit !== 'definitionId') {\n conditions.push(eq(workflowRuns.definitionId, filters.definitionId));\n }\n if (filters?.triggerSource && params.omit !== 'triggerSource') {\n conditions.push(eq(workflowRuns.triggerSource, filters.triggerSource));\n }\n if (filters?.createdFrom) {\n conditions.push(gte(workflowRuns.createdAt, filters.createdFrom));\n }\n if (filters?.createdTo) {\n conditions.push(lte(workflowRuns.createdAt, filters.createdTo));\n }\n return conditions;\n}\n\nexport async function listWorkflowRuns(\n params: ListWorkflowRunsParams,\n): Promise<ListWorkflowRunsResult> {\n const conditions = buildWorkflowRunListConditions(params);\n const rows = await db()\n .select()\n .from(workflowRuns)\n .where(and(...conditions))\n .orderBy(desc(workflowRuns.createdAt), desc(workflowRuns.id))\n .limit(params.limit + 1);\n\n let totalCount: number | null = null;\n if (params.includeTotal) {\n const [{value} = {value: 0}] = await db()\n .select({value: count()})\n .from(workflowRuns)\n .where(\n and(\n ...buildWorkflowRunListConditions({projectId: params.projectId, filters: params.filters}),\n ),\n );\n totalCount = value;\n }\n\n const page = paginateTimestampIdRows({rows, limit: params.limit, timestampKey: 'createdAt'});\n\n return {\n runs: page.pageRows.map(toWorkflowRun),\n nextCursor: page.nextCursor,\n filteredTotalCount: totalCount,\n };\n}\n\nexport async function listWorkflowRunsByProject(projectId: string): Promise<WorkflowRun[]> {\n const result = await listWorkflowRuns({projectId, limit: 100});\n return result.runs;\n}\n\nexport async function getWorkflowRunAggregates(params: {\n projectId: string;\n filters?: WorkflowRunFilters | undefined;\n}): Promise<WorkflowRunAggregates> {\n const [statusRows, triggerRows, workflowRows] = await Promise.all([\n db()\n .select({value: workflowRuns.status, count: count()})\n .from(workflowRuns)\n .where(\n and(\n ...buildWorkflowRunListConditions({\n projectId: params.projectId,\n filters: params.filters,\n omit: 'status',\n }),\n ),\n )\n .groupBy(workflowRuns.status),\n db()\n .select({value: workflowRuns.triggerSource, count: count()})\n .from(workflowRuns)\n .where(\n and(\n ...buildWorkflowRunListConditions({\n projectId: params.projectId,\n filters: params.filters,\n omit: 'triggerSource',\n }),\n ),\n )\n .groupBy(workflowRuns.triggerSource),\n db()\n .select({value: workflowRuns.definitionId, count: count()})\n .from(workflowRuns)\n .where(\n and(\n ...buildWorkflowRunListConditions({\n projectId: params.projectId,\n filters: params.filters,\n omit: 'definitionId',\n }),\n ),\n )\n .groupBy(workflowRuns.definitionId),\n ]);\n\n return {\n status: statusRows,\n triggerSource: triggerRows,\n workflow: workflowRows,\n };\n}\n\nexport async function getWorkflowJobExecutionDepth(\n params: WorkflowJobExecutionDepthParams = {},\n): Promise<WorkflowJobExecutionDepth> {\n const runConditions = [eq(workflowRuns.status, 'running')];\n const jobConditions = [eq(jobExecutions.status, 'running')];\n if (params.workspaceId) {\n runConditions.push(eq(workflowRuns.workspaceId, params.workspaceId));\n jobConditions.push(eq(workflowRuns.workspaceId, params.workspaceId));\n }\n\n const [runRows, jobRows] = await Promise.all([\n db()\n .select({value: count()})\n .from(workflowRuns)\n .where(and(...runConditions)),\n db()\n .select({value: count()})\n .from(jobExecutions)\n .innerJoin(jobs, eq(jobExecutions.jobId, jobs.id))\n .innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .where(and(...jobConditions)),\n ]);\n\n return {\n runningRuns: runRows[0]?.value ?? 0,\n runningJobExecutions: jobRows[0]?.value ?? 0,\n };\n}\n\nexport async function getWorkflowRunDetail(\n workflowRunId: string,\n attempt?: number | undefined,\n): Promise<WorkflowRunDetail | undefined> {\n const [target] = await db()\n .select({run: workflowRuns, attempt: workflowRunAttempts})\n .from(workflowRuns)\n .innerJoin(\n workflowRunAttempts,\n and(\n eq(workflowRunAttempts.workflowRunId, workflowRuns.id),\n eq(workflowRunAttempts.attempt, attempt ?? workflowRuns.currentAttempt),\n ),\n )\n .where(eq(workflowRuns.id, workflowRunId))\n .limit(1);\n if (!target) return undefined;\n\n const latestAttempt = await getLatestAttempt({\n workflowRunId: target.run.id,\n projectId: target.run.projectId,\n });\n\n const rows = await db()\n .select({\n run: workflowRuns,\n job: jobs,\n jobExecution: jobExecutions,\n step: steps,\n stepAttempt: stepAttempts,\n })\n .from(workflowRuns)\n .innerJoin(workflowRunAttempts, eq(workflowRunAttempts.id, target.attempt.id))\n .leftJoin(jobs, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))\n .leftJoin(jobExecutions, eq(jobExecutions.jobId, jobs.id))\n .leftJoin(steps, eq(steps.jobExecutionId, jobExecutions.id))\n .leftJoin(stepAttempts, eq(stepAttempts.stepId, steps.id))\n .where(eq(workflowRuns.id, workflowRunId))\n .orderBy(\n asc(jobs.position),\n asc(jobs.id),\n asc(jobExecutions.sequence),\n asc(jobExecutions.id),\n asc(steps.position),\n asc(steps.id),\n asc(stepAttempts.executionOrder),\n asc(stepAttempts.id),\n );\n\n return hydrateWorkflowRunDetail(rows, target.attempt, latestAttempt);\n}\n\nexport async function getJobExecutionDetail(\n jobExecutionId: string,\n): Promise<JobExecutionDetail | undefined> {\n const rows = await db()\n .select({\n jobExecution: jobExecutions,\n step: steps,\n stepAttempt: stepAttempts,\n })\n .from(jobExecutions)\n .innerJoin(jobs, eq(jobExecutions.jobId, jobs.id))\n .innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))\n .innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))\n .leftJoin(steps, eq(steps.jobExecutionId, jobExecutions.id))\n .leftJoin(stepAttempts, eq(stepAttempts.stepId, steps.id))\n .where(eq(jobExecutions.id, jobExecutionId))\n .orderBy(\n asc(steps.position),\n asc(steps.id),\n asc(stepAttempts.executionOrder),\n asc(stepAttempts.id),\n );\n\n const first = rows[0];\n if (!first) return undefined;\n\n const detail: JobExecutionDetail = {...toJobExecution(first.jobExecution), steps: []};\n const stepById = new Map<string, StepDetail>();\n for (const row of rows) {\n if (row.step) {\n const step = getOrCreateStepDetail(stepById, detail.steps, row.step);\n if (row.stepAttempt) {\n step.attempts.push(toStepAttempt(row.stepAttempt));\n }\n }\n }\n\n return detail;\n}\n\nfunction hydrateWorkflowRunDetail(\n rows: {\n run: typeof workflowRuns.$inferSelect;\n job: typeof jobs.$inferSelect | null;\n jobExecution: typeof jobExecutions.$inferSelect | null;\n step: typeof steps.$inferSelect | null;\n stepAttempt: typeof stepAttempts.$inferSelect | null;\n }[],\n attempt: typeof workflowRunAttempts.$inferSelect,\n latestAttempt: number,\n): WorkflowRunDetail | undefined {\n const first = rows[0];\n if (!first) return undefined;\n\n const detail: WorkflowRunDetail = {\n ...toWorkflowRun(first.run),\n runAttempt: toWorkflowRunAttempt(attempt),\n latestAttempt,\n jobs: [],\n };\n const jobById = new Map<string, WorkflowJobDetail>();\n const jobExecutionById = new Map<string, JobExecutionDetail>();\n const stepById = new Map<string, StepDetail>();\n\n for (const row of rows) {\n if (!row.job) continue;\n let job = jobById.get(row.job.id);\n if (!job) {\n job = {...toJob(row.job), jobExecutions: []};\n jobById.set(row.job.id, job);\n detail.jobs.push(job);\n }\n\n if (!row.jobExecution) continue;\n let jobExecution = jobExecutionById.get(row.jobExecution.id);\n if (!jobExecution) {\n jobExecution = {...toJobExecution(row.jobExecution), steps: []};\n jobExecutionById.set(row.jobExecution.id, jobExecution);\n job.jobExecutions.push(jobExecution);\n }\n\n if (!row.step) continue;\n const step = getOrCreateStepDetail(stepById, jobExecution.steps, row.step);\n if (row.stepAttempt) {\n step.attempts.push(toStepAttempt(row.stepAttempt));\n }\n }\n\n return detail;\n}\n\nfunction getOrCreateStepDetail(\n stepById: Map<string, StepDetail>,\n target: StepDetail[],\n row: typeof steps.$inferSelect,\n): StepDetail {\n let step = stepById.get(row.id);\n if (!step) {\n step = {...toStep(row), attempts: []};\n stepById.set(row.id, step);\n target.push(step);\n }\n return step;\n}\n"],"names":["paginateTimestampIdRows","timestampIdCursorWhere","and","asc","count","desc","eq","gte","lte","sql","db","jobExecutions","toJobExecution","jobs","toJob","stepAttempts","toStepAttempt","steps","toStep","toWorkflowRunAttempt","workflowRunAttempts","toWorkflowRun","workflowRuns","getWorkflowRunById","id","rows","select","from","where","limit","row","undefined","getWorkflowRunByAttemptId","workflowRunAttemptId","run","innerJoin","workflowRunId","getWorkflowRunAttemptById","listRunAttempts","params","attempt","projectId","orderBy","map","getLatestAttempt","value","Number","buildWorkflowRunListConditions","filters","conditions","cursorCondition","timestampColumn","createdAt","idColumn","cursor","push","status","omit","definitionId","triggerSource","createdFrom","createdTo","listWorkflowRuns","totalCount","includeTotal","page","timestampKey","runs","pageRows","nextCursor","filteredTotalCount","listWorkflowRunsByProject","result","getWorkflowRunAggregates","statusRows","triggerRows","workflowRows","Promise","all","groupBy","workflow","getWorkflowJobExecutionDepth","runConditions","jobConditions","workspaceId","runRows","jobRows","jobId","runningRuns","runningJobExecutions","getWorkflowRunDetail","target","currentAttempt","latestAttempt","job","jobExecution","step","stepAttempt","leftJoin","jobExecutionId","stepId","position","sequence","executionOrder","hydrateWorkflowRunDetail","getJobExecutionDetail","first","detail","stepById","Map","getOrCreateStepDetail","attempts","runAttempt","jobById","jobExecutionById","get","set"],"mappings":"AAAA,SACEA,uBAAuB,EAEvBC,sBAAsB,QACjB,wBAAwB;AAC/B,SAAQC,GAAG,EAAEC,GAAG,EAAEC,KAAK,EAAEC,IAAI,EAAEC,EAAE,EAAEC,GAAG,EAAEC,GAAG,EAAYC,GAAG,QAAO,cAAc;AAS/E,SAAQC,EAAE,QAAO,WAAW;AAC5B,SAAQC,aAAa,EAAEC,cAAc,QAAO,8BAA8B;AAC1E,SAAQC,IAAI,EAAEC,KAAK,QAAO,oBAAoB;AAC9C,SAAQC,YAAY,EAAEC,aAAa,QAAO,6BAA6B;AACvE,SAAQC,KAAK,EAAEC,MAAM,QAAO,qBAAqB;AACjD,SAAQC,oBAAoB,EAAEC,mBAAmB,QAAO,qCAAqC;AAC7F,SAAQC,aAAa,EAAEC,YAAY,QAAO,6BAA6B;AAyCvE,OAAO,eAAeC,mBAAmBC,EAAU;IACjD,MAAMC,OAAO,MAAMf,KAAKgB,MAAM,GAAGC,IAAI,CAACL,cAAcM,KAAK,CAACtB,GAAGgB,aAAaE,EAAE,EAAEA,KAAKK,KAAK,CAAC;IACzF,MAAMC,MAAML,IAAI,CAAC,EAAE;IACnB,IAAI,CAACK,KAAK,OAAOC;IACjB,OAAOV,cAAcS;AACvB;AAEA,OAAO,eAAeE,0BACpBC,oBAA4B;IAE5B,MAAMR,OAAO,MAAMf,KAChBgB,MAAM,CAAC;QAACQ,KAAKZ;IAAY,GACzBK,IAAI,CAACP,qBACLe,SAAS,CAACb,cAAchB,GAAGc,oBAAoBgB,aAAa,EAAEd,aAAaE,EAAE,GAC7EI,KAAK,CAACtB,GAAGc,oBAAoBI,EAAE,EAAES,uBACjCJ,KAAK,CAAC;IACT,MAAMC,MAAML,IAAI,CAAC,EAAE;IACnB,OA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QAEA,IAAI,CAACjE,IAAIkE,IAAI,EAAE;QACf,MAAMA,OAAOc,sBAAsBF,UAAUb,aAAa9E,KAAK,EAAEa,IAAIkE,IAAI;QACzE,IAAIlE,IAAImE,WAAW,EAAE;YACnBD,KAAKe,QAAQ,CAACxD,IAAI,CAACvC,cAAcc,IAAImE,WAAW;QAClD;IACF;IAEA,OAAOU;AACT;AAEA,SAASG,sBACPF,QAAiC,EACjCjB,MAAoB,EACpB7D,GAA8B;IAE9B,IAAIkE,OAAOY,SAASO,GAAG,CAACrF,IAAIN,EAAE;IAC9B,IAAI,CAACwE,MAAM;QACTA,OAAO;YAAC,GAAG9E,OAAOY,IAAI;YAAEiF,UAAU,EAAE;QAAA;QACpCH,SAASQ,GAAG,CAACtF,IAAIN,EAAE,EAAEwE;QACrBL,OAAOpC,IAAI,CAACyC;IACd;IACA,OAAOA;AACT"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AgentDefaultsResolver } from '@shipfox/api-agent/core/resolve-agent-config';
|
|
2
|
+
import type { WorkflowModel } from '@shipfox/api-definitions';
|
|
3
|
+
import type { TriggerPayload, WorkflowRun, WorkflowSourceSnapshot } from '#core/entities/workflow-run.js';
|
|
4
|
+
import { InterpolationUnresolvableError } from '#core/errors.js';
|
|
5
|
+
export type WorkflowModelJob = WorkflowModel['jobs'][number];
|
|
6
|
+
export interface ReferencedVariable {
|
|
7
|
+
readonly key: string;
|
|
8
|
+
readonly field: InterpolationUnresolvableError['field'];
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly envKey?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface CreateWorkflowRunParams {
|
|
13
|
+
workspaceId: string;
|
|
14
|
+
projectId: string;
|
|
15
|
+
definitionId: string;
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
model: WorkflowModel;
|
|
18
|
+
triggerPayload: TriggerPayload;
|
|
19
|
+
inputs?: Record<string, unknown> | undefined;
|
|
20
|
+
sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;
|
|
21
|
+
triggerIdempotencyKey?: string | undefined;
|
|
22
|
+
resolveAgentDefaults?: AgentDefaultsResolver | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare function createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun>;
|
|
25
|
+
export declare function loadReferencedVariables(params: {
|
|
26
|
+
readonly model: WorkflowModel;
|
|
27
|
+
readonly jobs?: readonly WorkflowModelJob[] | undefined;
|
|
28
|
+
readonly workspaceId: string;
|
|
29
|
+
readonly projectId: string;
|
|
30
|
+
readonly definitionId: string;
|
|
31
|
+
}): Promise<Record<string, string> | undefined>;
|
|
32
|
+
//# sourceMappingURL=run-create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-create.d.ts","sourceRoot":"","sources":["../../../src/db/workflow-runs/run-create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE3B,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAS5D,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,sBAAsB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAC,8BAA8B,EAAC,MAAM,iBAAiB,CAAC;AAa/D,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7C,cAAc,CAAC,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3D,qBAAqB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC1D;AAED,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC,CAuH7F;AAED,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,gBAAgB,EAAE,GAAG,SAAS,CAAC;IACxD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAqB9C"}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { catalogDefaultAgentResolver } from '@shipfox/api-agent/core/resolve-agent-config';
|
|
2
|
+
import { getVariablesByNamespace } from '@shipfox/api-secrets';
|
|
3
|
+
import { analyzeContextKeyAccess } from '@shipfox/expression';
|
|
4
|
+
import { logger } from '@shipfox/node-opentelemetry';
|
|
5
|
+
import { eq } from 'drizzle-orm';
|
|
6
|
+
import { createAgentToolMaterializationSnapshot, loadAgentToolMaterializationContext } from '#core/agent-tools.js';
|
|
7
|
+
import { InterpolationUnresolvableError } from '#core/errors.js';
|
|
8
|
+
import { deriveInitialJobExecutionPlan, materializeWorkflowRunJobs } from '#core/workflow-run-creation.js';
|
|
9
|
+
import { recordWorkflowRunCreated } from '#metrics/instance.js';
|
|
10
|
+
import { db } from '../db.js';
|
|
11
|
+
import { workflowRunAttempts } from '../schema/workflow-run-attempts.js';
|
|
12
|
+
import { toWorkflowRun, workflowRuns } from '../schema/workflow-runs.js';
|
|
13
|
+
import { persistMaterializedRunGraph } from './run-graph.js';
|
|
14
|
+
export async function createWorkflowRun(params) {
|
|
15
|
+
const agentToolContext = await loadAgentToolMaterializationContext({
|
|
16
|
+
model: params.model,
|
|
17
|
+
workspaceId: params.workspaceId,
|
|
18
|
+
projectId: params.projectId
|
|
19
|
+
});
|
|
20
|
+
const agentToolMaterialization = createAgentToolMaterializationSnapshot({
|
|
21
|
+
model: params.model,
|
|
22
|
+
context: agentToolContext
|
|
23
|
+
});
|
|
24
|
+
const result = await db().transaction(async (tx)=>{
|
|
25
|
+
const insertResult = await tx.insert(workflowRuns).values({
|
|
26
|
+
workspaceId: params.workspaceId,
|
|
27
|
+
projectId: params.projectId,
|
|
28
|
+
definitionId: params.definitionId,
|
|
29
|
+
name: params.name ?? params.model.name,
|
|
30
|
+
status: 'pending',
|
|
31
|
+
currentAttempt: 1,
|
|
32
|
+
triggerProvider: params.triggerPayload.provider ?? null,
|
|
33
|
+
triggerSource: params.triggerPayload.source,
|
|
34
|
+
triggerEvent: params.triggerPayload.event,
|
|
35
|
+
triggerPayload: params.triggerPayload,
|
|
36
|
+
inputs: params.inputs ?? null,
|
|
37
|
+
sourceSnapshot: params.sourceSnapshot ?? null,
|
|
38
|
+
triggerIdempotencyKey: params.triggerIdempotencyKey ?? null
|
|
39
|
+
}).onConflictDoNothing({
|
|
40
|
+
target: workflowRuns.triggerIdempotencyKey
|
|
41
|
+
}).returning();
|
|
42
|
+
const runRow = insertResult[0];
|
|
43
|
+
if (!runRow) {
|
|
44
|
+
// Conflict path: skip jobs/steps/outbox so the first insert keeps ownership of side effects.
|
|
45
|
+
if (!params.triggerIdempotencyKey) {
|
|
46
|
+
throw new Error('Insert returned no rows');
|
|
47
|
+
}
|
|
48
|
+
const existing = await tx.select().from(workflowRuns).where(eq(workflowRuns.triggerIdempotencyKey, params.triggerIdempotencyKey)).limit(1);
|
|
49
|
+
const existingRow = existing[0];
|
|
50
|
+
if (!existingRow) {
|
|
51
|
+
throw new Error(`Idempotency conflict but existing run missing for key ${params.triggerIdempotencyKey}`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
run: toWorkflowRun(existingRow),
|
|
55
|
+
created: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const run = toWorkflowRun(runRow);
|
|
59
|
+
const [attemptRow] = await tx.insert(workflowRunAttempts).values({
|
|
60
|
+
workflowRunId: runRow.id,
|
|
61
|
+
attempt: 1,
|
|
62
|
+
status: 'pending',
|
|
63
|
+
model: params.model,
|
|
64
|
+
agentToolMaterialization
|
|
65
|
+
}).returning();
|
|
66
|
+
if (!attemptRow) throw new Error('Insert returned no rows');
|
|
67
|
+
// Resolving one-shot templates here gives interpolation access to the inserted run id.
|
|
68
|
+
// If resolution fails, the transaction rolls back the run, jobs, steps, and outbox event together.
|
|
69
|
+
// Listening steps are resolved later when a job execution is created.
|
|
70
|
+
const oneShotJobs = params.model.jobs.filter((job)=>job.mode !== 'listening');
|
|
71
|
+
const vars = await loadReferencedVariables({
|
|
72
|
+
model: params.model,
|
|
73
|
+
jobs: oneShotJobs,
|
|
74
|
+
workspaceId: params.workspaceId,
|
|
75
|
+
projectId: params.projectId,
|
|
76
|
+
definitionId: params.definitionId
|
|
77
|
+
});
|
|
78
|
+
const materializedJobs = materializeWorkflowRunJobs({
|
|
79
|
+
run,
|
|
80
|
+
model: params.model,
|
|
81
|
+
triggerPayload: params.triggerPayload,
|
|
82
|
+
inputs: params.inputs ?? null,
|
|
83
|
+
vars,
|
|
84
|
+
resolveAgentDefaults: params.resolveAgentDefaults ?? catalogDefaultAgentResolver,
|
|
85
|
+
definitionId: params.definitionId,
|
|
86
|
+
agentToolContext,
|
|
87
|
+
agentToolSnapshot: agentToolMaterialization
|
|
88
|
+
});
|
|
89
|
+
const graphJobs = materializeRunGraphJobs({
|
|
90
|
+
params,
|
|
91
|
+
run,
|
|
92
|
+
vars,
|
|
93
|
+
materializedJobs
|
|
94
|
+
});
|
|
95
|
+
await persistMaterializedRunGraph(tx, {
|
|
96
|
+
run,
|
|
97
|
+
workflowRunAttempt: attemptRow,
|
|
98
|
+
materializedJobs: graphJobs
|
|
99
|
+
});
|
|
100
|
+
logTemplateDiagnostics({
|
|
101
|
+
workflowRunId: runRow.id,
|
|
102
|
+
diagnostics: materializedJobs.flatMap((job)=>job.steps.flatMap((step)=>(step.diagnostics ?? []).map((diagnostic)=>({
|
|
103
|
+
jobKey: job.key,
|
|
104
|
+
stepName: step.name,
|
|
105
|
+
...diagnostic
|
|
106
|
+
}))))
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
run,
|
|
110
|
+
created: true
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
if (result.created) recordWorkflowRunCreated(result.run.triggerPayload.provider ?? result.run.triggerSource);
|
|
114
|
+
return result.run;
|
|
115
|
+
}
|
|
116
|
+
export async function loadReferencedVariables(params) {
|
|
117
|
+
const references = referencedVariables(params.model, params.jobs ?? params.model.jobs);
|
|
118
|
+
const keys = [
|
|
119
|
+
...new Set(references.map((reference)=>reference.key))
|
|
120
|
+
].sort();
|
|
121
|
+
if (keys.length === 0) return undefined;
|
|
122
|
+
const vars = await getVariablesByNamespace({
|
|
123
|
+
workspaceId: params.workspaceId,
|
|
124
|
+
projectId: params.projectId,
|
|
125
|
+
namespace: ''
|
|
126
|
+
});
|
|
127
|
+
const missingKey = keys.find((key)=>!(key in vars));
|
|
128
|
+
if (missingKey !== undefined) {
|
|
129
|
+
const reference = references.find((candidate)=>candidate.key === missingKey);
|
|
130
|
+
throw new InterpolationUnresolvableError(params.definitionId, {
|
|
131
|
+
field: reference?.field ?? 'env',
|
|
132
|
+
source: reference?.source ?? `vars.${missingKey}`,
|
|
133
|
+
...reference?.envKey === undefined ? {} : {
|
|
134
|
+
envKey: reference.envKey
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return vars;
|
|
139
|
+
}
|
|
140
|
+
function materializeRunGraphJobs(params) {
|
|
141
|
+
return params.materializedJobs.map((job, jobIndex)=>({
|
|
142
|
+
job: {
|
|
143
|
+
key: job.key,
|
|
144
|
+
mode: job.mode,
|
|
145
|
+
name: workflowTemplateSource(job.name),
|
|
146
|
+
status: 'pending',
|
|
147
|
+
checkoutPersistCredentials: job.checkout.persistCredentials,
|
|
148
|
+
checkoutPermissionsContents: job.checkout.permissions.contents,
|
|
149
|
+
success: job.success ?? null,
|
|
150
|
+
executionTimeoutMs: job.executionTimeoutMs ?? null,
|
|
151
|
+
listeningTimeoutMs: job.listening?.timeoutMs ?? null,
|
|
152
|
+
maxExecutions: job.listening?.maxExecutions ?? null,
|
|
153
|
+
onResolve: job.listening?.onResolve ?? null,
|
|
154
|
+
batchDebounceMs: job.listening?.batch?.debounceMs ?? null,
|
|
155
|
+
batchMaxSize: job.listening?.batch?.maxSize ?? null,
|
|
156
|
+
batchMaxWaitMs: job.listening?.batch?.maxWaitMs ?? null,
|
|
157
|
+
listeningOn: job.listening?.on ? [
|
|
158
|
+
...job.listening.on
|
|
159
|
+
] : null,
|
|
160
|
+
listeningUntil: job.listening?.until ? [
|
|
161
|
+
...job.listening.until
|
|
162
|
+
] : null,
|
|
163
|
+
dependencies: [
|
|
164
|
+
...job.dependencies
|
|
165
|
+
],
|
|
166
|
+
runner: job.runner.length === 0 ? null : [
|
|
167
|
+
...job.runner
|
|
168
|
+
],
|
|
169
|
+
position: job.position
|
|
170
|
+
},
|
|
171
|
+
createExecution: (jobRow)=>{
|
|
172
|
+
if (jobRow.mode === 'listening') return undefined;
|
|
173
|
+
const fallbackName = `${jobRow.key} #1`;
|
|
174
|
+
const modelJob = params.params.model.jobs[jobIndex];
|
|
175
|
+
if (!modelJob) return undefined;
|
|
176
|
+
const executionPlan = deriveInitialJobExecutionPlan({
|
|
177
|
+
run: params.run,
|
|
178
|
+
modelJob,
|
|
179
|
+
job,
|
|
180
|
+
jobId: jobRow.id,
|
|
181
|
+
sequence: 1,
|
|
182
|
+
fallbackName,
|
|
183
|
+
triggerPayload: params.params.triggerPayload,
|
|
184
|
+
inputs: params.params.inputs ?? null,
|
|
185
|
+
vars: params.vars
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
sequence: 1,
|
|
189
|
+
name: executionPlan.name,
|
|
190
|
+
runner: [
|
|
191
|
+
...executionPlan.runner
|
|
192
|
+
],
|
|
193
|
+
status: 'pending',
|
|
194
|
+
evaluationTrace: executionPlan.evaluationTrace?.length === 0 ? null : executionPlan.evaluationTrace
|
|
195
|
+
};
|
|
196
|
+
},
|
|
197
|
+
createSteps: ()=>job.steps.map((step)=>({
|
|
198
|
+
key: step.key,
|
|
199
|
+
name: step.name,
|
|
200
|
+
sourceLocation: step.sourceLocation,
|
|
201
|
+
status: step.status,
|
|
202
|
+
type: step.type,
|
|
203
|
+
config: step.config,
|
|
204
|
+
condition: step.condition ?? null,
|
|
205
|
+
configPlan: step.configPlan ?? null,
|
|
206
|
+
authoredConfig: step.authoredConfig,
|
|
207
|
+
position: step.position
|
|
208
|
+
}))
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
function referencedVariables(model, jobs) {
|
|
212
|
+
const references = [];
|
|
213
|
+
if (jobs.length > 0) {
|
|
214
|
+
collectTemplateVariableReferences(model.templates?.env, references);
|
|
215
|
+
}
|
|
216
|
+
for (const job of jobs){
|
|
217
|
+
collectFieldVariableReferences(job.name, references, {
|
|
218
|
+
field: 'job.name'
|
|
219
|
+
});
|
|
220
|
+
for (const template of job.runnerTemplates ?? []){
|
|
221
|
+
collectFieldVariableReferences(template, references, {
|
|
222
|
+
field: 'job.runner'
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
collectTemplateVariableReferences(job.outputs, references, {
|
|
226
|
+
field: 'job.outputs'
|
|
227
|
+
});
|
|
228
|
+
collectTemplateVariableReferences(job.templates?.env, references);
|
|
229
|
+
for (const step of job.steps){
|
|
230
|
+
collectFieldVariableReferences(step.templates?.name, references, {
|
|
231
|
+
field: 'step.name'
|
|
232
|
+
});
|
|
233
|
+
if (step.kind === 'run') {
|
|
234
|
+
collectFieldVariableReferences(step.templates?.command, references, {
|
|
235
|
+
field: 'run'
|
|
236
|
+
});
|
|
237
|
+
collectTemplateVariableReferences(step.templates?.env, references);
|
|
238
|
+
} else {
|
|
239
|
+
collectFieldVariableReferences(step.templates?.prompt, references, {
|
|
240
|
+
field: 'agent.prompt'
|
|
241
|
+
});
|
|
242
|
+
collectFieldVariableReferences(step.templates?.model, references, {
|
|
243
|
+
field: 'agent.model'
|
|
244
|
+
});
|
|
245
|
+
collectFieldVariableReferences(step.templates?.provider, references, {
|
|
246
|
+
field: 'agent.provider'
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return references;
|
|
252
|
+
}
|
|
253
|
+
function collectTemplateVariableReferences(templates, references, source) {
|
|
254
|
+
for (const [envKey, template] of Object.entries(templates ?? {})){
|
|
255
|
+
collectFieldVariableReferences(template, references, source === undefined ? {
|
|
256
|
+
field: 'env',
|
|
257
|
+
envKey
|
|
258
|
+
} : source);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function collectFieldVariableReferences(template, references, source) {
|
|
262
|
+
for (const segment of template ?? []){
|
|
263
|
+
if (segment.kind === 'literal') continue;
|
|
264
|
+
const keyAccess = analyzeContextKeyAccess(segment.expression);
|
|
265
|
+
for (const reference of keyAccess.references){
|
|
266
|
+
if (reference.root !== 'vars') continue;
|
|
267
|
+
references.push({
|
|
268
|
+
key: reference.key,
|
|
269
|
+
field: source.field,
|
|
270
|
+
source: segment.expression.source,
|
|
271
|
+
envKey: source.envKey
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function workflowTemplateSource(template) {
|
|
277
|
+
if (template === undefined) return null;
|
|
278
|
+
return template.map((segment)=>segment.kind === 'literal' ? segment.value : `$${'{{'} ${segment.expression.source} ${'}}'}`).join('');
|
|
279
|
+
}
|
|
280
|
+
function logTemplateDiagnostics(params) {
|
|
281
|
+
if (params.diagnostics.length === 0) return;
|
|
282
|
+
logger().warn({
|
|
283
|
+
workflowRunId: params.workflowRunId,
|
|
284
|
+
diagnostics: params.diagnostics
|
|
285
|
+
}, 'Workflow interpolation resolved with diagnostics');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//# sourceMappingURL=run-create.js.map
|