@shipfox/api-workflows 4.0.0 → 6.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.
Files changed (277) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +104 -0
  3. package/dist/core/agent-defaults.d.ts +17 -0
  4. package/dist/core/agent-defaults.d.ts.map +1 -0
  5. package/dist/core/agent-defaults.js +21 -0
  6. package/dist/core/agent-defaults.js.map +1 -0
  7. package/dist/core/agent-tool-capability-warning.d.ts +4 -0
  8. package/dist/core/agent-tool-capability-warning.d.ts.map +1 -1
  9. package/dist/core/agent-tool-capability-warning.js +15 -17
  10. package/dist/core/agent-tool-capability-warning.js.map +1 -1
  11. package/dist/core/agent-tools.d.ts +11 -9
  12. package/dist/core/agent-tools.d.ts.map +1 -1
  13. package/dist/core/agent-tools.js +23 -18
  14. package/dist/core/agent-tools.js.map +1 -1
  15. package/dist/core/checkout.d.ts +21 -7
  16. package/dist/core/checkout.d.ts.map +1 -1
  17. package/dist/core/checkout.js +23 -11
  18. package/dist/core/checkout.js.map +1 -1
  19. package/dist/core/entities/workflow-run-attempt.d.ts +1 -1
  20. package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -1
  21. package/dist/core/entities/workflow-run-attempt.js.map +1 -1
  22. package/dist/core/job-execution.d.ts +3 -1
  23. package/dist/core/job-execution.d.ts.map +1 -1
  24. package/dist/core/job-execution.js +14 -12
  25. package/dist/core/job-execution.js.map +1 -1
  26. package/dist/core/job-transition/derive-job-execution-outputs.d.ts +1 -1
  27. package/dist/core/job-transition/derive-job-execution-outputs.d.ts.map +1 -1
  28. package/dist/core/job-transition/derive-job-execution-outputs.js.map +1 -1
  29. package/dist/core/job-transition/derive-job-success.js +1 -1
  30. package/dist/core/job-transition/derive-job-success.js.map +1 -1
  31. package/dist/core/listener-execution-materialization.d.ts +3 -3
  32. package/dist/core/listener-execution-materialization.d.ts.map +1 -1
  33. package/dist/core/listener-execution-materialization.js +3 -4
  34. package/dist/core/listener-execution-materialization.js.map +1 -1
  35. package/dist/core/run-workflow.d.ts +12 -1
  36. package/dist/core/run-workflow.d.ts.map +1 -1
  37. package/dist/core/run-workflow.js +13 -8
  38. package/dist/core/run-workflow.js.map +1 -1
  39. package/dist/core/step-config/agent.d.ts +8 -8
  40. package/dist/core/step-config/agent.d.ts.map +1 -1
  41. package/dist/core/step-config/agent.js +12 -10
  42. package/dist/core/step-config/agent.js.map +1 -1
  43. package/dist/core/step-config/complete-step-dispatch-config.d.ts +4 -4
  44. package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -1
  45. package/dist/core/step-config/complete-step-dispatch-config.js +2 -2
  46. package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -1
  47. package/dist/core/step-config/materialize-job-execution-steps.d.ts +3 -3
  48. package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -1
  49. package/dist/core/step-config/materialize-job-execution-steps.js +5 -6
  50. package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -1
  51. package/dist/core/step-config/materialize-workflow-model.d.ts +3 -3
  52. package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -1
  53. package/dist/core/step-config/materialize-workflow-model.js +4 -4
  54. package/dist/core/step-config/materialize-workflow-model.js.map +1 -1
  55. package/dist/core/step-config/resolve-job-execution-name.d.ts +1 -1
  56. package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -1
  57. package/dist/core/step-config/resolve-job-execution-name.js.map +1 -1
  58. package/dist/core/step-config/resolve-step-config.d.ts +4 -4
  59. package/dist/core/step-config/resolve-step-config.d.ts.map +1 -1
  60. package/dist/core/step-config/resolve-step-config.js +6 -6
  61. package/dist/core/step-config/resolve-step-config.js.map +1 -1
  62. package/dist/core/step-config/run.d.ts +1 -1
  63. package/dist/core/step-config/run.d.ts.map +1 -1
  64. package/dist/core/step-config/run.js.map +1 -1
  65. package/dist/core/workflow-run-creation.d.ts +3 -3
  66. package/dist/core/workflow-run-creation.d.ts.map +1 -1
  67. package/dist/core/workflow-run-creation.js +3 -4
  68. package/dist/core/workflow-run-creation.js.map +1 -1
  69. package/dist/db/db.d.ts +16 -4
  70. package/dist/db/db.d.ts.map +1 -1
  71. package/dist/db/job-listeners.d.ts +7 -1
  72. package/dist/db/job-listeners.d.ts.map +1 -1
  73. package/dist/db/job-listeners.js +10 -5
  74. package/dist/db/job-listeners.js.map +1 -1
  75. package/dist/db/runner-lease-table.d.ts +5 -5
  76. package/dist/db/runner-lease-table.d.ts.map +1 -1
  77. package/dist/db/runner-lease-table.js +3 -2
  78. package/dist/db/runner-lease-table.js.map +1 -1
  79. package/dist/db/schema/workflow-run-attempts.d.ts +9 -3
  80. package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -1
  81. package/dist/db/schema/workflow-run-attempts.js +2 -1
  82. package/dist/db/schema/workflow-run-attempts.js.map +1 -1
  83. package/dist/db/schema/workflow-runs.js +1 -1
  84. package/dist/db/schema/workflow-runs.js.map +1 -1
  85. package/dist/db/workflow-runs/job-executions.d.ts +5 -0
  86. package/dist/db/workflow-runs/job-executions.d.ts.map +1 -1
  87. package/dist/db/workflow-runs/job-executions.js +14 -7
  88. package/dist/db/workflow-runs/job-executions.js.map +1 -1
  89. package/dist/db/workflow-runs/jobs.d.ts.map +1 -1
  90. package/dist/db/workflow-runs/jobs.js +3 -1
  91. package/dist/db/workflow-runs/jobs.js.map +1 -1
  92. package/dist/db/workflow-runs/run-create.d.ts +9 -2
  93. package/dist/db/workflow-runs/run-create.d.ts.map +1 -1
  94. package/dist/db/workflow-runs/run-create.js +12 -9
  95. package/dist/db/workflow-runs/run-create.js.map +1 -1
  96. package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -1
  97. package/dist/db/workflow-runs/run-rerun.js +3 -1
  98. package/dist/db/workflow-runs/run-rerun.js.map +1 -1
  99. package/dist/index.d.ts +18 -4
  100. package/dist/index.d.ts.map +1 -1
  101. package/dist/index.js +61 -37
  102. package/dist/index.js.map +1 -1
  103. package/dist/presentation/dto/checkout-token.d.ts +14 -1
  104. package/dist/presentation/dto/checkout-token.d.ts.map +1 -1
  105. package/dist/presentation/dto/checkout-token.js.map +1 -1
  106. package/dist/presentation/index.d.ts +1 -1
  107. package/dist/presentation/index.d.ts.map +1 -1
  108. package/dist/presentation/index.js +1 -1
  109. package/dist/presentation/index.js.map +1 -1
  110. package/dist/presentation/inter-module.d.ts +18 -0
  111. package/dist/presentation/inter-module.d.ts.map +1 -0
  112. package/dist/presentation/inter-module.js +113 -0
  113. package/dist/presentation/inter-module.js.map +1 -0
  114. package/dist/presentation/routes/agent-runtime-config.d.ts +6 -1
  115. package/dist/presentation/routes/agent-runtime-config.d.ts.map +1 -1
  116. package/dist/presentation/routes/agent-runtime-config.js +59 -57
  117. package/dist/presentation/routes/agent-runtime-config.js.map +1 -1
  118. package/dist/presentation/routes/cancel-run.d.ts +2 -1
  119. package/dist/presentation/routes/cancel-run.d.ts.map +1 -1
  120. package/dist/presentation/routes/cancel-run.js +37 -34
  121. package/dist/presentation/routes/cancel-run.js.map +1 -1
  122. package/dist/presentation/routes/checkout-token.d.ts +8 -1
  123. package/dist/presentation/routes/checkout-token.d.ts.map +1 -1
  124. package/dist/presentation/routes/checkout-token.js +65 -47
  125. package/dist/presentation/routes/checkout-token.js.map +1 -1
  126. package/dist/presentation/routes/get-run-aggregates.d.ts +2 -1
  127. package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -1
  128. package/dist/presentation/routes/get-run-aggregates.js +44 -53
  129. package/dist/presentation/routes/get-run-aggregates.js.map +1 -1
  130. package/dist/presentation/routes/get-run.d.ts +2 -1
  131. package/dist/presentation/routes/get-run.d.ts.map +1 -1
  132. package/dist/presentation/routes/get-run.js +53 -50
  133. package/dist/presentation/routes/get-run.js.map +1 -1
  134. package/dist/presentation/routes/get-step-secrets.d.ts +3 -1
  135. package/dist/presentation/routes/get-step-secrets.d.ts.map +1 -1
  136. package/dist/presentation/routes/get-step-secrets.js +72 -68
  137. package/dist/presentation/routes/get-step-secrets.js.map +1 -1
  138. package/dist/presentation/routes/index.d.ts +19 -2
  139. package/dist/presentation/routes/index.d.ts.map +1 -1
  140. package/dist/presentation/routes/index.js +38 -30
  141. package/dist/presentation/routes/index.js.map +1 -1
  142. package/dist/presentation/routes/leased-step.d.ts +2 -0
  143. package/dist/presentation/routes/leased-step.d.ts.map +1 -1
  144. package/dist/presentation/routes/leased-step.js +1 -2
  145. package/dist/presentation/routes/leased-step.js.map +1 -1
  146. package/dist/presentation/routes/list-run-attempts.d.ts +2 -1
  147. package/dist/presentation/routes/list-run-attempts.d.ts.map +1 -1
  148. package/dist/presentation/routes/list-run-attempts.js +29 -26
  149. package/dist/presentation/routes/list-run-attempts.js.map +1 -1
  150. package/dist/presentation/routes/list-runs.d.ts +2 -1
  151. package/dist/presentation/routes/list-runs.d.ts.map +1 -1
  152. package/dist/presentation/routes/list-runs.js +51 -60
  153. package/dist/presentation/routes/list-runs.js.map +1 -1
  154. package/dist/presentation/routes/next-step.d.ts +10 -1
  155. package/dist/presentation/routes/next-step.d.ts.map +1 -1
  156. package/dist/presentation/routes/next-step.js +64 -50
  157. package/dist/presentation/routes/next-step.js.map +1 -1
  158. package/dist/presentation/routes/project-access.d.ts +10 -0
  159. package/dist/presentation/routes/project-access.d.ts.map +1 -0
  160. package/dist/presentation/routes/project-access.js +17 -0
  161. package/dist/presentation/routes/project-access.js.map +1 -0
  162. package/dist/presentation/routes/report-step.d.ts +2 -1
  163. package/dist/presentation/routes/report-step.d.ts.map +1 -1
  164. package/dist/presentation/routes/report-step.js +62 -61
  165. package/dist/presentation/routes/report-step.js.map +1 -1
  166. package/dist/presentation/routes/require-accessible-run.d.ts +3 -1
  167. package/dist/presentation/routes/require-accessible-run.d.ts.map +1 -1
  168. package/dist/presentation/routes/require-accessible-run.js +3 -6
  169. package/dist/presentation/routes/require-accessible-run.js.map +1 -1
  170. package/dist/presentation/routes/rerun-run.d.ts +2 -1
  171. package/dist/presentation/routes/rerun-run.d.ts.map +1 -1
  172. package/dist/presentation/routes/rerun-run.js +46 -43
  173. package/dist/presentation/routes/rerun-run.js.map +1 -1
  174. package/dist/temporal/activities/index.d.ts +44 -9
  175. package/dist/temporal/activities/index.d.ts.map +1 -1
  176. package/dist/temporal/activities/index.js +13 -9
  177. package/dist/temporal/activities/index.js.map +1 -1
  178. package/dist/temporal/activities/orchestration-activities.d.ts +20 -11
  179. package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -1
  180. package/dist/temporal/activities/orchestration-activities.js +48 -33
  181. package/dist/temporal/activities/orchestration-activities.js.map +1 -1
  182. package/dist/tsconfig.test.tsbuildinfo +1 -1
  183. package/package.json +41 -44
  184. package/src/core/agent-defaults.test.ts +28 -0
  185. package/src/core/agent-defaults.ts +36 -0
  186. package/src/core/agent-tool-capability-warning.test.ts +36 -11
  187. package/src/core/agent-tool-capability-warning.ts +27 -25
  188. package/src/core/agent-tools.ts +33 -36
  189. package/src/core/checkout.test.ts +38 -25
  190. package/src/core/checkout.ts +41 -14
  191. package/src/core/entities/workflow-run-attempt.ts +1 -1
  192. package/src/core/job-execution.ts +19 -9
  193. package/src/core/job-transition/derive-job-execution-outputs.ts +1 -1
  194. package/src/core/job-transition/derive-job-success.ts +1 -1
  195. package/src/core/listener-execution-materialization.test.ts +4 -2
  196. package/src/core/listener-execution-materialization.ts +6 -9
  197. package/src/core/run-workflow.test.ts +43 -38
  198. package/src/core/run-workflow.ts +26 -9
  199. package/src/core/step-config/agent.ts +24 -26
  200. package/src/core/step-config/complete-step-dispatch-config.test.ts +22 -23
  201. package/src/core/step-config/complete-step-dispatch-config.ts +6 -6
  202. package/src/core/step-config/materialize-job-execution-steps.test.ts +34 -23
  203. package/src/core/step-config/materialize-job-execution-steps.ts +38 -39
  204. package/src/core/step-config/materialize-workflow-model.test.ts +94 -82
  205. package/src/core/step-config/materialize-workflow-model.ts +31 -29
  206. package/src/core/step-config/resolve-job-execution-name.ts +1 -1
  207. package/src/core/step-config/resolve-step-config.ts +11 -9
  208. package/src/core/step-config/run.ts +1 -1
  209. package/src/core/workflow-run-creation.test.ts +14 -10
  210. package/src/core/workflow-run-creation.ts +6 -9
  211. package/src/db/job-listeners.ts +20 -5
  212. package/src/db/runner-lease-table.ts +2 -2
  213. package/src/db/schema/workflow-run-attempts.ts +7 -3
  214. package/src/db/schema/workflow-runs.ts +1 -1
  215. package/src/db/workflow-runs/job-executions.ts +15 -1
  216. package/src/db/workflow-runs/jobs.ts +4 -1
  217. package/src/db/workflow-runs/run-create.test.ts +7 -1
  218. package/src/db/workflow-runs/run-create.ts +25 -15
  219. package/src/db/workflow-runs/run-rerun.test.ts +1 -1
  220. package/src/db/workflow-runs/run-rerun.ts +6 -3
  221. package/src/index.ts +75 -33
  222. package/src/presentation/dto/checkout-token.ts +7 -1
  223. package/src/presentation/index.ts +1 -1
  224. package/src/presentation/inter-module.test.ts +149 -0
  225. package/src/presentation/inter-module.ts +132 -0
  226. package/src/presentation/routes/agent-runtime-config.test.ts +53 -10
  227. package/src/presentation/routes/agent-runtime-config.ts +89 -64
  228. package/src/presentation/routes/cancel-run.test.ts +10 -20
  229. package/src/presentation/routes/cancel-run.ts +30 -27
  230. package/src/presentation/routes/checkout-token.test.ts +52 -33
  231. package/src/presentation/routes/checkout-token.ts +109 -49
  232. package/src/presentation/routes/get-run-aggregates.test.ts +13 -7
  233. package/src/presentation/routes/get-run-aggregates.ts +54 -57
  234. package/src/presentation/routes/get-run.test.ts +10 -18
  235. package/src/presentation/routes/get-run.ts +51 -48
  236. package/src/presentation/routes/get-step-secrets.test.ts +29 -7
  237. package/src/presentation/routes/get-step-secrets.ts +72 -61
  238. package/src/presentation/routes/index.test.ts +16 -1
  239. package/src/presentation/routes/index.ts +54 -29
  240. package/src/presentation/routes/leased-step.ts +3 -2
  241. package/src/presentation/routes/list-run-attempts.test.ts +9 -19
  242. package/src/presentation/routes/list-run-attempts.ts +21 -18
  243. package/src/presentation/routes/list-runs.test.ts +13 -7
  244. package/src/presentation/routes/list-runs.ts +64 -67
  245. package/src/presentation/routes/next-step.test.ts +30 -11
  246. package/src/presentation/routes/next-step.ts +68 -48
  247. package/src/presentation/routes/project-access.ts +16 -0
  248. package/src/presentation/routes/report-step.test.ts +18 -2
  249. package/src/presentation/routes/report-step.ts +51 -49
  250. package/src/presentation/routes/require-accessible-run.ts +5 -2
  251. package/src/presentation/routes/rerun-run.test.ts +9 -19
  252. package/src/presentation/routes/rerun-run.ts +39 -36
  253. package/src/temporal/activities/index.ts +32 -12
  254. package/src/temporal/activities/orchestration-activities.test.ts +10 -8
  255. package/src/temporal/activities/orchestration-activities.ts +74 -50
  256. package/src/temporal/workflows/job-execution-orchestration.test.ts +47 -2
  257. package/test/env.ts +1 -3
  258. package/test/factories/project.ts +10 -5
  259. package/test/factories/workflow-model.test.ts +5 -1
  260. package/test/factories/workflow-model.ts +1 -1
  261. package/test/factories/workflow-run.ts +1 -1
  262. package/test/fixtures/agent-inter-module.ts +27 -0
  263. package/test/fixtures/annotations-inter-module.ts +5 -0
  264. package/test/fixtures/auth-inter-module.ts +22 -0
  265. package/test/fixtures/lease-token.ts +2 -1
  266. package/test/fixtures/projects-inter-module.ts +8 -0
  267. package/test/fixtures/runners-inter-module.ts +52 -0
  268. package/test/fixtures/secrets-inter-module.ts +61 -0
  269. package/test/globalSetup.ts +11 -11
  270. package/tsconfig.build.tsbuildinfo +1 -1
  271. package/dist/core/source-control.d.ts +0 -5
  272. package/dist/core/source-control.d.ts.map +0 -1
  273. package/dist/core/source-control.js +0 -19
  274. package/dist/core/source-control.js.map +0 -1
  275. package/src/core/source-control.test.ts +0 -17
  276. package/src/core/source-control.ts +0 -22
  277. package/src/temporal/workflows/job-execution-orchestration-timeout.test.ts +0 -165
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/temporal/activities/orchestration-activities.ts"],"sourcesContent":["import {cancelRunnerJobs, enqueueJobExecution, releaseJobExecution} from '@shipfox/api-runners';\nimport {ApplicationFailure} from '@temporalio/common';\nimport {defaultJobConditionTrace} from '#core/condition-trace.js';\nimport type {JobStatus, JobStatusReason, ResolutionReason} from '#core/entities/job.js';\nimport type {PersistedEvaluationTraceEntry, StepStatus} from '#core/entities/step.js';\nimport type {WorkflowRunStatus} from '#core/entities/workflow-run.js';\nimport {JobNotFoundError} from '#core/errors.js';\nimport type {\n RuntimeCompletionStatus,\n RuntimeDagNode,\n} from '#core/workflow-scheduling/runtime-dag.js';\nimport {\n activateJobListener,\n bulkUpdateStepStatuses,\n drainListenerEventsIntoExecution,\n type EvaluateJobActivationsParams,\n evaluateJobActivations,\n failJobExecutionAsTimedOut,\n failWorkflowRunAsTimedOut,\n getJobExecutionsByWorkflowRunAttemptId,\n getJobsByWorkflowRunAttemptId,\n getWorkflowRunAttemptById,\n getWorkflowRunByAttemptId,\n type JobActivationDecision,\n peekListenerBuffer,\n resolveJobExecutionAfterLeaseExpiry,\n resolveJobListener,\n resolveJobStatusFromJobExecutions,\n settleListenerJobExecution,\n updateJobExecutionStatus,\n updateJobStatus,\n updateWorkflowRunStatus,\n} from '#db/index.js';\nimport {recordWorkflowListenerExecution} from '#metrics/instance.js';\n\nexport interface DagJob extends RuntimeDagNode {\n id: string;\n key: string;\n mode: 'one_shot' | 'listening';\n status: JobStatus;\n jobExecutionId?: string | undefined;\n executionVersion?: number;\n executionTimeoutMs?: number | null | undefined;\n listeningTimeoutMs?: number | null | undefined;\n maxExecutions?: number | null | undefined;\n onResolve?: 'finish' | 'cancel' | null | undefined;\n batchDebounceMs?: number | null | undefined;\n batchMaxSize?: number | null | undefined;\n batchMaxWaitMs?: number | null | undefined;\n dependencies: string[];\n runner: string[];\n version: number;\n}\n\nexport interface RunDag {\n workflowRunId: string;\n runAttemptId: string;\n workspaceId: string;\n projectId: string;\n runVersion: number;\n runTimeoutMs: number;\n jobs: DagJob[];\n}\n\nexport async function loadRunAttemptDag(runAttemptId: string): Promise<RunDag> {\n const run = await getWorkflowRunByAttemptId(runAttemptId);\n if (!run) throw new Error(`Run not found for attempt: ${runAttemptId}`);\n const attempt = await getWorkflowRunAttemptById(runAttemptId);\n if (!attempt) throw new Error(`Run attempt not found: ${runAttemptId}`);\n\n const jobs = await getJobsByWorkflowRunAttemptId(runAttemptId);\n const jobExecutions = await getJobExecutionsByWorkflowRunAttemptId(runAttemptId);\n const firstJobExecutions = new Map<string, (typeof jobExecutions)[number]>();\n for (const jobExecution of jobExecutions) {\n if (!firstJobExecutions.has(jobExecution.jobId)) {\n firstJobExecutions.set(jobExecution.jobId, jobExecution);\n }\n }\n\n return {\n workflowRunId: run.id,\n runAttemptId,\n workspaceId: run.workspaceId,\n projectId: run.projectId,\n runVersion: attempt.version,\n runTimeoutMs: run.timeoutMs,\n jobs: jobs.flatMap((job) => {\n const jobExecution = firstJobExecutions.get(job.id);\n const modelJob = attempt.model?.jobs.find((item) => item.key === job.key);\n if (!jobExecution && job.mode !== 'listening') return [];\n return [\n {\n id: job.id,\n key: job.key,\n mode: job.mode,\n status: job.status,\n ...(jobExecution === undefined\n ? {}\n : {jobExecutionId: jobExecution.id, executionVersion: jobExecution.version}),\n executionTimeoutMs: job.executionTimeoutMs,\n listeningTimeoutMs: job.listeningTimeoutMs,\n maxExecutions: job.maxExecutions,\n onResolve: job.onResolve,\n batchDebounceMs: job.batchDebounceMs,\n batchMaxSize: job.batchMaxSize,\n batchMaxWaitMs: job.batchMaxWaitMs,\n dependencies: job.dependencies,\n hasActivationCondition: modelJob?.if !== undefined,\n runner: jobExecution?.runner ?? job.runner ?? [],\n version: job.version,\n },\n ];\n }),\n };\n}\n\nexport async function evaluateJobActivationsActivity(\n params: EvaluateJobActivationsParams,\n): Promise<JobActivationDecision[]> {\n return await evaluateJobActivations(params);\n}\n\nexport async function setRunAttemptStatus(params: {\n runAttemptId: string;\n status: WorkflowRunStatus;\n version: number;\n}): Promise<{newVersion: number; status: WorkflowRunStatus}> {\n const updated = await updateWorkflowRunStatus({\n workflowRunAttemptId: params.runAttemptId,\n status: params.status,\n expectedVersion: params.version,\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nexport async function setJobStatus(params: {\n jobId: string;\n status: JobStatus;\n version: number;\n statusReason?: JobStatusReason | null | undefined;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null | undefined;\n}): Promise<{newVersion: number; status: JobStatus}> {\n const updated = await updateJobStatus({\n jobId: params.jobId,\n status: params.status,\n expectedVersion: params.version,\n statusReason: params.statusReason,\n evaluationTrace: jobStatusEvaluationTrace(params),\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nfunction jobStatusEvaluationTrace(params: {\n status: JobStatus;\n statusReason?: JobStatusReason | null | undefined;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null | undefined;\n}): readonly PersistedEvaluationTraceEntry[] | null | undefined {\n if (params.evaluationTrace !== undefined) return params.evaluationTrace;\n return params.status === 'skipped' && params.statusReason === 'default_gate_rejected'\n ? defaultJobConditionTrace()\n : undefined;\n}\n\nexport async function setJobExecutionStatus(params: {\n jobExecutionId: string;\n status: Exclude<JobStatus, 'skipped'>;\n version: number;\n statusReason?: JobStatusReason | null | undefined;\n}): Promise<{newVersion: number; status: Exclude<JobStatus, 'skipped'>}> {\n const updated = await updateJobExecutionStatus({\n jobExecutionId: params.jobExecutionId,\n status: params.status,\n expectedVersion: params.version,\n statusReason: params.statusReason,\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nexport async function bulkSetStepStatuses(params: {\n jobExecutionId: string;\n status: Extract<StepStatus, 'failed' | 'cancelled'>;\n}): Promise<void> {\n await bulkUpdateStepStatuses(params);\n}\n\nexport async function resolveLeaseExpiredJobExecutionActivity(params: {\n jobExecutionId: string;\n expectedVersion: number;\n}): Promise<{status: RuntimeCompletionStatus; executionVersion: number}> {\n try {\n return await resolveJobExecutionAfterLeaseExpiry(params);\n } catch (err) {\n if (err instanceof JobNotFoundError) {\n throw ApplicationFailure.nonRetryable(err.message, err.name);\n }\n throw err;\n }\n}\n\n// Best-effort lease cleanup on job finalization. Idempotent: deleting an\n// already-released (or already-reaped) lease is a no-op. The workflow wraps the\n// call so a persistent failure never blocks the DAG result.\nexport async function releaseLeaseActivity(params: {jobExecutionId: string}): Promise<void> {\n await releaseJobExecution({jobExecutionId: params.jobExecutionId});\n}\n\nexport async function enqueueJobExecutionForRunner(params: {\n workspaceId: string;\n workflowRunId: string;\n jobId: string;\n jobExecutionId: string;\n runAttemptId: string;\n projectId: string;\n requiredLabels: string[];\n}): Promise<void> {\n try {\n await enqueueJobExecution({\n workspaceId: params.workspaceId,\n workflowRunId: params.workflowRunId,\n workflowRunAttemptId: params.runAttemptId,\n jobId: params.jobId,\n jobExecutionId: params.jobExecutionId,\n projectId: params.projectId,\n requiredLabels: params.requiredLabels,\n });\n } catch (err) {\n if (err instanceof Error && err.name === 'EmptyRequiredLabelsError') {\n throw ApplicationFailure.nonRetryable(err.message, err.name);\n }\n throw err;\n }\n}\n\nexport async function cancelRunnerJobsActivity(params: {jobIds: string[]}): Promise<void> {\n await cancelRunnerJobs({jobIds: params.jobIds});\n}\n\nexport async function failJobExecutionAsTimedOutActivity(params: {\n jobExecutionId: string;\n runAttemptId: string;\n expectedVersion: number;\n}): Promise<{newVersion: number}> {\n const jobExecution = await failJobExecutionAsTimedOut({\n jobExecutionId: params.jobExecutionId,\n workflowRunAttemptId: params.runAttemptId,\n expectedVersion: params.expectedVersion,\n });\n return {newVersion: jobExecution.version};\n}\n\nexport async function failRunAsTimedOutActivity(params: {runAttemptId: string}): Promise<void> {\n await failWorkflowRunAsTimedOut({runAttemptId: params.runAttemptId});\n}\n\nexport async function resolveJobStatusFromJobExecutionsActivity(params: {\n jobId: string;\n}): Promise<{status: RuntimeCompletionStatus; jobVersion: number}> {\n return await resolveJobStatusFromJobExecutions(params);\n}\n\nexport async function activateJobListenerActivity(params: {\n jobId: string;\n expectedVersion: number;\n}) {\n return await activateJobListener(params);\n}\n\nexport async function drainListenerEventsActivity(params: {\n jobId: string;\n expectedSequence: number;\n maxSize?: number | undefined;\n}) {\n return await drainListenerEventsIntoExecution(params);\n}\n\nexport async function peekListenerBufferActivity(params: {jobId: string}) {\n return await peekListenerBuffer(params);\n}\n\nexport async function resolveJobListenerActivity(params: {\n jobId: string;\n reason: ResolutionReason;\n}) {\n return await resolveJobListener(params);\n}\n\nexport async function settleListenerJobExecutionActivity(params: {\n jobExecutionId: string;\n status: 'failed' | 'cancelled';\n}) {\n await settleListenerJobExecution(params);\n}\n\n// The listener workflow owns every firing's terminal outcome, but a workflow\n// sandbox cannot emit metrics. This activity is the single recording point so\n// each firing is counted exactly once, including successes that settle through\n// the child's own resolution path rather than a listener DB write. The body is\n// synchronous; it returns a resolved promise because Temporal invokes activities\n// asynchronously.\nexport function recordListenerFiringOutcomeActivity(params: {\n outcome: 'succeeded' | 'failed' | 'cancelled';\n}): Promise<void> {\n recordWorkflowListenerExecution(params.outcome);\n return Promise.resolve();\n}\n"],"names":["cancelRunnerJobs","enqueueJobExecution","releaseJobExecution","ApplicationFailure","defaultJobConditionTrace","JobNotFoundError","activateJobListener","bulkUpdateStepStatuses","drainListenerEventsIntoExecution","evaluateJobActivations","failJobExecutionAsTimedOut","failWorkflowRunAsTimedOut","getJobExecutionsByWorkflowRunAttemptId","getJobsByWorkflowRunAttemptId","getWorkflowRunAttemptById","getWorkflowRunByAttemptId","peekListenerBuffer","resolveJobExecutionAfterLeaseExpiry","resolveJobListener","resolveJobStatusFromJobExecutions","settleListenerJobExecution","updateJobExecutionStatus","updateJobStatus","updateWorkflowRunStatus","recordWorkflowListenerExecution","loadRunAttemptDag","runAttemptId","run","Error","attempt","jobs","jobExecutions","firstJobExecutions","Map","jobExecution","has","jobId","set","workflowRunId","id","workspaceId","projectId","runVersion","version","runTimeoutMs","timeoutMs","flatMap","job","get","modelJob","model","find","item","key","mode","status","undefined","jobExecutionId","executionVersion","executionTimeoutMs","listeningTimeoutMs","maxExecutions","onResolve","batchDebounceMs","batchMaxSize","batchMaxWaitMs","dependencies","hasActivationCondition","if","runner","evaluateJobActivationsActivity","params","setRunAttemptStatus","updated","workflowRunAttemptId","expectedVersion","newVersion","setJobStatus","statusReason","evaluationTrace","jobStatusEvaluationTrace","setJobExecutionStatus","bulkSetStepStatuses","resolveLeaseExpiredJobExecutionActivity","err","nonRetryable","message","name","releaseLeaseActivity","enqueueJobExecutionForRunner","requiredLabels","cancelRunnerJobsActivity","jobIds","failJobExecutionAsTimedOutActivity","failRunAsTimedOutActivity","resolveJobStatusFromJobExecutionsActivity","activateJobListenerActivity","drainListenerEventsActivity","peekListenerBufferActivity","resolveJobListenerActivity","settleListenerJobExecutionActivity","recordListenerFiringOutcomeActivity","outcome","Promise","resolve"],"mappings":"AAAA,SAAQA,gBAAgB,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAO,uBAAuB;AAChG,SAAQC,kBAAkB,QAAO,qBAAqB;AACtD,SAAQC,wBAAwB,QAAO,2BAA2B;AAIlE,SAAQC,gBAAgB,QAAO,kBAAkB;AAKjD,SACEC,mBAAmB,EACnBC,sBAAsB,EACtBC,gCAAgC,EAEhCC,sBAAsB,EACtBC,0BAA0B,EAC1BC,yBAAyB,EACzBC,sCAAsC,EACtCC,6BAA6B,EAC7BC,yBAAyB,EACzBC,yBAAyB,EAEzBC,kBAAkB,EAClBC,mCAAmC,EACnCC,kBAAkB,EAClBC,iCAAiC,EACjCC,0BAA0B,EAC1BC,wBAAwB,EACxBC,eAAe,EACfC,uBAAuB,QAClB,eAAe;AACtB,SAAQC,+BAA+B,QAAO,uBAAuB;AA+BrE,OAAO,eAAeC,kBAAkBC,YAAoB;IAC1D,MAAMC,MAAM,MAAMZ,0BAA0BW;IAC5C,IAAI,CAACC,KAAK,MAAM,IAAIC,MAAM,CAAC,2BAA2B,EAAEF,cAAc;IACtE,MAAMG,UAAU,MAAMf,0BAA0BY;IAChD,IAAI,CAACG,SAAS,MAAM,IAAID,MAAM,CAAC,uBAAuB,EAAEF,cAAc;IAEtE,MAAMI,OAAO,MAAMjB,8BAA8Ba;IACjD,MAAMK,gBAAgB,MAAMnB,uC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MAAM5D,0BAA0B;QAACe,cAAc6C,OAAO7C,YAAY;IAAA;AACpE;AAEA,OAAO,eAAeqE,0CAA0CxB,MAE/D;IACC,OAAO,MAAMpD,kCAAkCoD;AACjD;AAEA,OAAO,eAAeyB,4BAA4BzB,MAGjD;IACC,OAAO,MAAMjE,oBAAoBiE;AACnC;AAEA,OAAO,eAAe0B,4BAA4B1B,MAIjD;IACC,OAAO,MAAM/D,iCAAiC+D;AAChD;AAEA,OAAO,eAAe2B,2BAA2B3B,MAAuB;IACtE,OAAO,MAAMvD,mBAAmBuD;AAClC;AAEA,OAAO,eAAe4B,2BAA2B5B,MAGhD;IACC,OAAO,MAAMrD,mBAAmBqD;AAClC;AAEA,OAAO,eAAe6B,mCAAmC7B,MAGxD;IACC,MAAMnD,2BAA2BmD;AACnC;AAEA,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,kBAAkB;AAClB,OAAO,SAAS8B,oCAAoC9B,MAEnD;IACC/C,gCAAgC+C,OAAO+B,OAAO;IAC9C,OAAOC,QAAQC,OAAO;AACxB"}
1
+ {"version":3,"sources":["../../../src/temporal/activities/orchestration-activities.ts"],"sourcesContent":["import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {\n type RunnersInterModuleClient,\n runnersInterModuleContract,\n} from '@shipfox/api-runners-dto/inter-module';\nimport type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';\nimport {isInterModuleKnownError} from '@shipfox/inter-module';\nimport {ApplicationFailure} from '@temporalio/common';\nimport {defaultJobConditionTrace} from '#core/condition-trace.js';\nimport type {JobStatus, JobStatusReason, ResolutionReason} from '#core/entities/job.js';\nimport type {PersistedEvaluationTraceEntry, StepStatus} from '#core/entities/step.js';\nimport type {WorkflowRunStatus} from '#core/entities/workflow-run.js';\nimport {JobNotFoundError} from '#core/errors.js';\nimport type {\n RuntimeCompletionStatus,\n RuntimeDagNode,\n} from '#core/workflow-scheduling/runtime-dag.js';\nimport {\n activateJobListener,\n bulkUpdateStepStatuses,\n drainListenerEventsIntoExecution,\n type EvaluateJobActivationsParams,\n evaluateJobActivations,\n failJobExecutionAsTimedOut,\n failWorkflowRunAsTimedOut,\n getJobExecutionsByWorkflowRunAttemptId,\n getJobsByWorkflowRunAttemptId,\n getWorkflowRunAttemptById,\n getWorkflowRunByAttemptId,\n type JobActivationDecision,\n peekListenerBuffer,\n resolveJobExecutionAfterLeaseExpiry,\n resolveJobListener,\n resolveJobStatusFromJobExecutions,\n settleListenerJobExecution,\n updateJobExecutionStatus,\n updateJobStatus,\n updateWorkflowRunStatus,\n} from '#db/index.js';\nimport {recordWorkflowListenerExecution} from '#metrics/instance.js';\n\nexport interface DagJob extends RuntimeDagNode {\n id: string;\n key: string;\n mode: 'one_shot' | 'listening';\n status: JobStatus;\n jobExecutionId?: string | undefined;\n executionVersion?: number;\n executionTimeoutMs?: number | null | undefined;\n listeningTimeoutMs?: number | null | undefined;\n maxExecutions?: number | null | undefined;\n onResolve?: 'finish' | 'cancel' | null | undefined;\n batchDebounceMs?: number | null | undefined;\n batchMaxSize?: number | null | undefined;\n batchMaxWaitMs?: number | null | undefined;\n dependencies: string[];\n runner: string[];\n version: number;\n}\n\nexport interface RunDag {\n workflowRunId: string;\n runAttemptId: string;\n workspaceId: string;\n projectId: string;\n runVersion: number;\n runTimeoutMs: number;\n jobs: DagJob[];\n}\n\nexport async function loadRunAttemptDag(runAttemptId: string): Promise<RunDag> {\n const run = await getWorkflowRunByAttemptId(runAttemptId);\n if (!run) throw new Error(`Run not found for attempt: ${runAttemptId}`);\n const attempt = await getWorkflowRunAttemptById(runAttemptId);\n if (!attempt) throw new Error(`Run attempt not found: ${runAttemptId}`);\n\n const jobs = await getJobsByWorkflowRunAttemptId(runAttemptId);\n const jobExecutions = await getJobExecutionsByWorkflowRunAttemptId(runAttemptId);\n const firstJobExecutions = new Map<string, (typeof jobExecutions)[number]>();\n for (const jobExecution of jobExecutions) {\n if (!firstJobExecutions.has(jobExecution.jobId)) {\n firstJobExecutions.set(jobExecution.jobId, jobExecution);\n }\n }\n\n return {\n workflowRunId: run.id,\n runAttemptId,\n workspaceId: run.workspaceId,\n projectId: run.projectId,\n runVersion: attempt.version,\n runTimeoutMs: run.timeoutMs,\n jobs: jobs.flatMap((job) => {\n const jobExecution = firstJobExecutions.get(job.id);\n const modelJob = attempt.model?.jobs.find((item) => item.key === job.key);\n if (!jobExecution && job.mode !== 'listening') return [];\n return [\n {\n id: job.id,\n key: job.key,\n mode: job.mode,\n status: job.status,\n ...(jobExecution === undefined\n ? {}\n : {jobExecutionId: jobExecution.id, executionVersion: jobExecution.version}),\n executionTimeoutMs: job.executionTimeoutMs,\n listeningTimeoutMs: job.listeningTimeoutMs,\n maxExecutions: job.maxExecutions,\n onResolve: job.onResolve,\n batchDebounceMs: job.batchDebounceMs,\n batchMaxSize: job.batchMaxSize,\n batchMaxWaitMs: job.batchMaxWaitMs,\n dependencies: job.dependencies,\n hasActivationCondition: modelJob?.if !== undefined,\n runner: jobExecution?.runner ?? job.runner ?? [],\n version: job.version,\n },\n ];\n }),\n };\n}\n\nexport async function evaluateJobActivationsActivity(\n params: EvaluateJobActivationsParams,\n): Promise<JobActivationDecision[]> {\n return await evaluateJobActivations(params);\n}\n\nexport async function setRunAttemptStatus(params: {\n runAttemptId: string;\n status: WorkflowRunStatus;\n version: number;\n}): Promise<{newVersion: number; status: WorkflowRunStatus}> {\n const updated = await updateWorkflowRunStatus({\n workflowRunAttemptId: params.runAttemptId,\n status: params.status,\n expectedVersion: params.version,\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nexport async function setJobStatus(params: {\n jobId: string;\n status: JobStatus;\n version: number;\n statusReason?: JobStatusReason | null | undefined;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null | undefined;\n}): Promise<{newVersion: number; status: JobStatus}> {\n const updated = await updateJobStatus({\n jobId: params.jobId,\n status: params.status,\n expectedVersion: params.version,\n statusReason: params.statusReason,\n evaluationTrace: jobStatusEvaluationTrace(params),\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nfunction jobStatusEvaluationTrace(params: {\n status: JobStatus;\n statusReason?: JobStatusReason | null | undefined;\n evaluationTrace?: readonly PersistedEvaluationTraceEntry[] | null | undefined;\n}): readonly PersistedEvaluationTraceEntry[] | null | undefined {\n if (params.evaluationTrace !== undefined) return params.evaluationTrace;\n return params.status === 'skipped' && params.statusReason === 'default_gate_rejected'\n ? defaultJobConditionTrace()\n : undefined;\n}\n\nexport async function setJobExecutionStatus(\n params: {\n jobExecutionId: string;\n status: Exclude<JobStatus, 'skipped'>;\n version: number;\n statusReason?: JobStatusReason | null | undefined;\n },\n secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'>,\n): Promise<{newVersion: number; status: Exclude<JobStatus, 'skipped'>}> {\n const updated = await updateJobExecutionStatus({\n jobExecutionId: params.jobExecutionId,\n status: params.status,\n expectedVersion: params.version,\n statusReason: params.statusReason,\n secrets,\n });\n return {newVersion: updated.version, status: updated.status};\n}\n\nexport async function bulkSetStepStatuses(params: {\n jobExecutionId: string;\n status: Extract<StepStatus, 'failed' | 'cancelled'>;\n}): Promise<void> {\n await bulkUpdateStepStatuses(params);\n}\n\nexport async function resolveLeaseExpiredJobExecutionActivity(\n params: {jobExecutionId: string; expectedVersion: number},\n secrets: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'>,\n): Promise<{status: RuntimeCompletionStatus; executionVersion: number}> {\n try {\n return await resolveJobExecutionAfterLeaseExpiry({...params, secrets});\n } catch (err) {\n if (err instanceof JobNotFoundError) {\n throw ApplicationFailure.nonRetryable(err.message, err.name);\n }\n throw err;\n }\n}\n\n// Best-effort lease cleanup on job finalization. Idempotent: deleting an\n// already-released (or already-reaped) lease is a no-op. The workflow wraps the\n// call so a persistent failure never blocks the DAG result.\nexport function createReleaseLeaseActivity(runners: RunnersInterModuleClient) {\n return async function releaseLeaseActivity(params: {jobExecutionId: string}): Promise<void> {\n await runners.releaseJobExecution({jobExecutionId: params.jobExecutionId});\n };\n}\n\nexport function createEnqueueJobExecutionForRunner(runners: RunnersInterModuleClient) {\n return async function enqueueJobExecutionForRunner(params: {\n workspaceId: string;\n workflowRunId: string;\n jobId: string;\n jobExecutionId: string;\n runAttemptId: string;\n projectId: string;\n requiredLabels: string[];\n }): Promise<void> {\n try {\n await runners.enqueueJobExecution({\n workspaceId: params.workspaceId,\n workflowRunId: params.workflowRunId,\n workflowRunAttemptId: params.runAttemptId,\n jobId: params.jobId,\n jobExecutionId: params.jobExecutionId,\n projectId: params.projectId,\n requiredLabels: params.requiredLabels,\n });\n } catch (err) {\n if (isInterModuleKnownError(runnersInterModuleContract.methods.enqueueJobExecution, err)) {\n throw ApplicationFailure.nonRetryable(err.message, err.name);\n }\n throw err;\n }\n };\n}\n\nexport function createCancelRunnerJobsActivity(runners: RunnersInterModuleClient) {\n return async function cancelRunnerJobsActivity(params: {jobIds: string[]}): Promise<void> {\n await runners.cancelJobs(params);\n };\n}\n\nexport async function failJobExecutionAsTimedOutActivity(\n params: {jobExecutionId: string; runAttemptId: string; expectedVersion: number},\n secrets: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'>,\n): Promise<{newVersion: number}> {\n const jobExecution = await failJobExecutionAsTimedOut({\n jobExecutionId: params.jobExecutionId,\n workflowRunAttemptId: params.runAttemptId,\n expectedVersion: params.expectedVersion,\n secrets,\n });\n return {newVersion: jobExecution.version};\n}\n\nexport async function failRunAsTimedOutActivity(params: {runAttemptId: string}): Promise<void> {\n await failWorkflowRunAsTimedOut({runAttemptId: params.runAttemptId});\n}\n\nexport async function resolveJobStatusFromJobExecutionsActivity(params: {\n jobId: string;\n}): Promise<{status: RuntimeCompletionStatus; jobVersion: number}> {\n return await resolveJobStatusFromJobExecutions(params);\n}\n\nexport async function activateJobListenerActivity(params: {\n jobId: string;\n expectedVersion: number;\n}) {\n return await activateJobListener(params);\n}\n\nexport function createDrainListenerEventsActivity(clients: {\n agent: AgentInterModuleClient;\n integrations?: IntegrationsModuleClient | undefined;\n projects?: ProjectsModuleClient | undefined;\n}) {\n return async function drainListenerEventsActivity(params: {\n jobId: string;\n expectedSequence: number;\n maxSize?: number | undefined;\n }) {\n return await drainListenerEventsIntoExecution({...params, ...clients});\n };\n}\n\nexport async function peekListenerBufferActivity(params: {jobId: string}) {\n return await peekListenerBuffer(params);\n}\n\nexport async function resolveJobListenerActivity(params: {\n jobId: string;\n reason: ResolutionReason;\n}) {\n return await resolveJobListener(params);\n}\n\nexport async function settleListenerJobExecutionActivity(params: {\n jobExecutionId: string;\n status: 'failed' | 'cancelled';\n}) {\n await settleListenerJobExecution(params);\n}\n\n// The listener workflow owns every firing's terminal outcome, but a workflow\n// sandbox cannot emit metrics. This activity is the single recording point so\n// each firing is counted exactly once, including successes that settle through\n// the child's own resolution path rather than a listener DB write. The body is\n// synchronous; it returns a resolved promise because Temporal invokes activities\n// asynchronously.\nexport function recordListenerFiringOutcomeActivity(params: {\n outcome: 'succeeded' | 'failed' | 'cancelled';\n}): Promise<void> {\n recordWorkflowListenerExecution(params.outcome);\n return Promise.resolve();\n}\n"],"names":["runnersInterModuleContract","isInterModuleKnownError","ApplicationFailure","defaultJobConditionTrace","JobNotFoundError","activateJobListener","bulkUpdateStepStatuses","drainListenerEventsIntoExecution","evaluateJobActivations","failJobExecutionAsTimedOut","failWorkflowRunAsTimedOut","getJobExecutionsByWorkflowRunAttemptId","getJobsByWorkflowRunAttemptId","getWorkflowRunAttemptById","getWorkflowRunByAttemptId","peekListenerBuffer","resolveJobExecutionAfterLeaseExpiry","resolveJobListener","resolveJobStatusFromJobExecutions","settleListenerJobExecution","updateJobExecutionStatus","updateJobStatus","updateWorkflowRunStatus","recordWorkflowListenerExecution","loadRunAttemptDag","runAttemptId","run","Error","attempt","jobs","jobExecutions","firstJobExecutions","Map","jobExecution","has","jobId","set","workflowRunId","id","workspaceId","projectId","runVersion","version","runTimeoutMs","timeoutMs","flatMap","job","get","modelJob","model","find","item","key","mode","status","undefined","jobExecutionId","executionVersion","executionTimeoutMs","listeningTimeoutMs","maxExecutions","onResolve","batchDebounceMs","batchMaxSize","batchMaxWaitMs","dependencies","hasActivationCondition","if","runner","evaluateJobActivationsActivity","params","setRunAttemptStatus","updated","workflowRunAttemptId","expectedVersion","newVersion","setJobStatus","statusReason","evaluationTrace","jobStatusEvaluationTrace","setJobExecutionStatus","secrets","bulkSetStepStatuses","resolveLeaseExpiredJobExecutionActivity","err","nonRetryable","message","name","createReleaseLeaseActivity","runners","releaseLeaseActivity","releaseJobExecution","createEnqueueJobExecutionForRunner","enqueueJobExecutionForRunner","enqueueJobExecution","requiredLabels","methods","createCancelRunnerJobsActivity","cancelRunnerJobsActivity","cancelJobs","failJobExecutionAsTimedOutActivity","failRunAsTimedOutActivity","resolveJobStatusFromJobExecutionsActivity","activateJobListenerActivity","createDrainListenerEventsActivity","clients","drainListenerEventsActivity","peekListenerBufferActivity","resolveJobListenerActivity","settleListenerJobExecutionActivity","recordListenerFiringOutcomeActivity","outcome","Promise","resolve"],"mappings":"AAGA,SAEEA,0BAA0B,QACrB,wCAAwC;AAE/C,SAAQC,uBAAuB,QAAO,wBAAwB;AAC9D,SAAQC,kBAAkB,QAAO,qBAAqB;AACtD,SAAQC,wBAAwB,QAAO,2BAA2B;AAIlE,SAAQC,gBAAgB,QAAO,kBAAkB;AAKjD,SACEC,mBAAmB,EACnBC,sBAAsB,EACtBC,gCAAgC,EAEhCC,sBAAsB,EACtBC,0BAA0B,EAC1BC,yBAAyB,EACzBC,sCAAsC,EACtCC,6BAA6B,EAC7BC,yBAAyB,EACzBC,yBAAyB,EAEzBC,kBAAkB,EAClBC,mCAAmC,EACnCC,kBAAkB,EAClBC,iCAAiC,EACjCC,0BAA0B,EAC1BC,wBAAwB,EACxBC,eAAe,EACfC,uBAAuB,QAClB,eAAe;AACt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