@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,6 +1,6 @@
1
- import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
2
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowModel} from '@shipfox/api-definitions-dto';
3
2
  import {canonicalizeLabels, findInvalidLabels, MAX_RUNNER_LABELS} from '@shipfox/runner-labels';
3
+ import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
4
4
  import type {
5
5
  AgentToolMaterializationContext,
6
6
  AgentToolMaterializationSnapshot,
@@ -38,9 +38,9 @@ export interface MaterializeWorkflowModelParams {
38
38
  readonly agentToolSnapshot?: AgentToolMaterializationSnapshot | null | undefined;
39
39
  }
40
40
 
41
- export function materializeWorkflowModel(
41
+ export async function materializeWorkflowModel(
42
42
  params: MaterializeWorkflowModelParams,
43
- ): readonly MaterializedWorkflowJob[] {
43
+ ): Promise<readonly MaterializedWorkflowJob[]> {
44
44
  const {
45
45
  model,
46
46
  context = {site: 'run-creation', values: {}},
@@ -51,31 +51,33 @@ export function materializeWorkflowModel(
51
51
  } = params;
52
52
  const jobsById = new Map(model.jobs.map((job) => [job.id, job]));
53
53
 
54
- return model.jobs.map((job, position) => ({
55
- key: job.key,
56
- mode: job.mode,
57
- ...(job.success === undefined ? {} : {success: job.success}),
58
- ...(job.executionTimeoutMs === undefined ? {} : {executionTimeoutMs: job.executionTimeoutMs}),
59
- checkout: job.checkout,
60
- ...(job.listening === undefined ? {} : {listening: job.listening}),
61
- ...(job.name === undefined ? {} : {name: job.name}),
62
- ...(job.outputs === undefined ? {} : {outputs: job.outputs}),
63
- dependencies: dependencySourceNames(job, jobsById),
64
- runner: job.runner,
65
- position,
66
- steps:
67
- job.mode === 'listening'
68
- ? []
69
- : materializeJobExecutionSteps({
70
- model,
71
- job,
72
- context,
73
- resolveAgentDefaults,
74
- definitionId,
75
- agentToolContext,
76
- agentToolSnapshot,
77
- }),
78
- }));
54
+ return await Promise.all(
55
+ model.jobs.map(async (job, position) => ({
56
+ key: job.key,
57
+ mode: job.mode,
58
+ ...(job.success === undefined ? {} : {success: job.success}),
59
+ ...(job.executionTimeoutMs === undefined ? {} : {executionTimeoutMs: job.executionTimeoutMs}),
60
+ checkout: job.checkout,
61
+ ...(job.listening === undefined ? {} : {listening: job.listening}),
62
+ ...(job.name === undefined ? {} : {name: job.name}),
63
+ ...(job.outputs === undefined ? {} : {outputs: job.outputs}),
64
+ dependencies: dependencySourceNames(job, jobsById),
65
+ runner: job.runner,
66
+ position,
67
+ steps:
68
+ job.mode === 'listening'
69
+ ? []
70
+ : await materializeJobExecutionSteps({
71
+ model,
72
+ job,
73
+ context,
74
+ resolveAgentDefaults,
75
+ definitionId,
76
+ agentToolContext,
77
+ agentToolSnapshot,
78
+ }),
79
+ })),
80
+ );
79
81
  }
80
82
 
81
83
  export function materializeJobRunner(params: {
@@ -1,4 +1,4 @@
1
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowModel} from '@shipfox/api-definitions-dto';
2
2
  import {
3
3
  capTraceEntries,
4
4
  getWorkflowInterpolationFieldFailurePolicy,
@@ -1,11 +1,11 @@
1
- import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
2
- import type {WorkflowEnvTemplates, WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowEnvTemplates, WorkflowModel} from '@shipfox/api-definitions-dto';
3
2
  import {
4
3
  type AvailabilitySite,
5
4
  capTraceEntries,
6
5
  type EvaluationTraceLimitEntry,
7
6
  type WorkflowExpressionEvaluationContext,
8
7
  } from '@shipfox/expression';
8
+ import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
9
9
  import type {
10
10
  AgentToolMaterializationContext,
11
11
  AgentToolMaterializationSnapshot,
@@ -46,7 +46,7 @@ export interface ResolveStepConfigParams {
46
46
  readonly jobEnvTemplates: WorkflowEnvTemplates | undefined;
47
47
  readonly context: WorkflowExpressionEvaluationContext;
48
48
  readonly site: AvailabilitySite;
49
- readonly resolveAgentDefaults: AgentDefaultsResolver;
49
+ readonly resolveAgentDefaults?: AgentDefaultsResolver | undefined;
50
50
  readonly definitionId: string;
51
51
  readonly agentToolContext?: AgentToolMaterializationContext | undefined;
52
52
  readonly agentToolSnapshot?: AgentToolMaterializationSnapshot | null | undefined;
@@ -62,11 +62,13 @@ interface BuiltStepConfig {
62
62
  readonly hasTemplates: boolean;
63
63
  }
64
64
 
65
- export function resolveStepConfig(params: ResolveStepConfigParams): ResolvedStepConfig {
65
+ export async function resolveStepConfig(
66
+ params: ResolveStepConfigParams,
67
+ ): Promise<ResolvedStepConfig> {
66
68
  const context = evaluationContext(params);
67
- const effective = buildStepConfig({...params, context, mode: 'effective'});
69
+ const effective = await buildStepConfig({...params, context, mode: 'effective'});
68
70
  const authoredConfig = effective.hasTemplates
69
- ? buildStepConfig({...params, context, mode: 'authored'}).config
71
+ ? (await buildStepConfig({...params, context, mode: 'authored'})).config
70
72
  : null;
71
73
  const name = resolveStepName(params.step, context, params.definitionId);
72
74
 
@@ -80,9 +82,9 @@ export function resolveStepConfig(params: ResolveStepConfigParams): ResolvedStep
80
82
  };
81
83
  }
82
84
 
83
- function buildStepConfig(
85
+ async function buildStepConfig(
84
86
  params: Omit<BuildStepConfigParams, 'context'> & {readonly context: WorkflowEvaluationContext},
85
- ): BuiltStepConfig {
87
+ ): Promise<BuiltStepConfig> {
86
88
  const gate = gateConfigForStep(params.step);
87
89
  const outputs = outputsConfigForStep(params.step);
88
90
  const runStep = runStepOrNull(params.step);
@@ -102,7 +104,7 @@ function buildStepConfig(
102
104
  const agentStep = agentStepOrNull(params.step);
103
105
  if (agentStep === null) throw new Error(`Unsupported workflow step kind: ${params.step.kind}`);
104
106
 
105
- const agent = resolveAgentStepConfig({...params, step: agentStep});
107
+ const agent = await resolveAgentStepConfig({...params, step: agentStep});
106
108
  return {
107
109
  config: {...agent.config, ...gate, ...outputs},
108
110
  configPlan: agent.configPlan,
@@ -1,4 +1,4 @@
1
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowModel} from '@shipfox/api-definitions-dto';
2
2
  import {
3
3
  type MaterializedSecretBindingDto,
4
4
  materializedSecretBindingSchema,
@@ -1,6 +1,7 @@
1
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowModel} from '@shipfox/api-definitions-dto';
2
2
  import {buildModel, template} from '#test/helpers/workflow-runs.js';
3
3
  import type {TriggerPayload, WorkflowRun} from './entities/workflow-run.js';
4
+ import type {MaterializedWorkflowJob} from './step-config/materialize-workflow-model.js';
4
5
  import {
5
6
  deriveInitialJobExecutionPlan,
6
7
  materializeWorkflowRunJobs,
@@ -14,7 +15,7 @@ const triggerPayload: TriggerPayload = {
14
15
  };
15
16
 
16
17
  describe('deriveInitialJobExecutionPlan', () => {
17
- it('resolves initial execution name and runner templates from creation context', () => {
18
+ it('resolves initial execution name and runner templates from creation context', async () => {
18
19
  const model = buildModel({
19
20
  jobs: {
20
21
  deploy: {
@@ -26,7 +27,7 @@ describe('deriveInitialJobExecutionPlan', () => {
26
27
  },
27
28
  });
28
29
  const run = workflowRun({inputs: {environment: 'prod', runner: 'GPU'}});
29
- const {modelJob, job} = materializedJob(model, run, {inputs: run.inputs});
30
+ const {modelJob, job} = await materializedJob(model, run, {inputs: run.inputs});
30
31
 
31
32
  const plan = deriveInitialJobExecutionPlan({
32
33
  run,
@@ -55,7 +56,7 @@ describe('deriveInitialJobExecutionPlan', () => {
55
56
  });
56
57
  });
57
58
 
58
- it('resolves variables referenced only by job runner templates', () => {
59
+ it('resolves variables referenced only by job runner templates', async () => {
59
60
  const model = buildModel({
60
61
  jobs: {
61
62
  build: {
@@ -65,7 +66,7 @@ describe('deriveInitialJobExecutionPlan', () => {
65
66
  },
66
67
  });
67
68
  const run = workflowRun();
68
- const {modelJob, job} = materializedJob(model, run, {vars: {RUNNER: 'GPU'}});
69
+ const {modelJob, job} = await materializedJob(model, run, {vars: {RUNNER: 'GPU'}});
69
70
 
70
71
  const plan = deriveInitialJobExecutionPlan({
71
72
  run,
@@ -81,7 +82,7 @@ describe('deriveInitialJobExecutionPlan', () => {
81
82
  expect(plan.runner).toEqual(['gpu', 'ubuntu-latest']);
82
83
  });
83
84
 
84
- it('uses the fallback name for execution-name self references', () => {
85
+ it('uses the fallback name for execution-name self references', async () => {
85
86
  const model = buildModel({
86
87
  jobs: {
87
88
  deploy: {
@@ -91,7 +92,7 @@ describe('deriveInitialJobExecutionPlan', () => {
91
92
  },
92
93
  });
93
94
  const run = workflowRun();
94
- const {modelJob, job} = materializedJob(model, run);
95
+ const {modelJob, job} = await materializedJob(model, run);
95
96
 
96
97
  const plan = deriveInitialJobExecutionPlan({
97
98
  run,
@@ -107,15 +108,18 @@ describe('deriveInitialJobExecutionPlan', () => {
107
108
  });
108
109
  });
109
110
 
110
- function materializedJob(
111
+ async function materializedJob(
111
112
  model: WorkflowModel,
112
113
  run: WorkflowRun,
113
114
  context: {
114
115
  inputs?: Record<string, unknown> | null | undefined;
115
116
  vars?: Record<string, string> | undefined;
116
117
  } = {},
117
- ) {
118
- const [job] = materializeWorkflowRunJobs({
118
+ ): Promise<{
119
+ job: MaterializedWorkflowJob;
120
+ modelJob: WorkflowModel['jobs'][number];
121
+ }> {
122
+ const [job] = await materializeWorkflowRunJobs({
119
123
  run,
120
124
  model,
121
125
  triggerPayload,
@@ -1,8 +1,5 @@
1
- import {
2
- type AgentDefaultsResolver,
3
- catalogDefaultAgentResolver,
4
- } from '@shipfox/api-agent/core/resolve-agent-config';
5
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import type {WorkflowModel} from '@shipfox/api-definitions-dto';
2
+ import type {AgentDefaultsResolver} from './agent-defaults.js';
6
3
  import type {
7
4
  AgentToolMaterializationContext,
8
5
  AgentToolMaterializationSnapshot,
@@ -20,7 +17,7 @@ import {
20
17
  } from './step-config/materialize-workflow-model.js';
21
18
  import {resolveJobExecutionName} from './step-config/resolve-job-execution-name.js';
22
19
 
23
- export function materializeWorkflowRunJobs(params: {
20
+ export async function materializeWorkflowRunJobs(params: {
24
21
  run: WorkflowRun;
25
22
  model: WorkflowModel;
26
23
  triggerPayload: TriggerPayload;
@@ -30,17 +27,17 @@ export function materializeWorkflowRunJobs(params: {
30
27
  definitionId: string;
31
28
  agentToolContext?: AgentToolMaterializationContext | undefined;
32
29
  agentToolSnapshot?: AgentToolMaterializationSnapshot | null | undefined;
33
- }): readonly MaterializedWorkflowJob[] {
30
+ }): Promise<readonly MaterializedWorkflowJob[]> {
34
31
  const context = assembleCreationContext({
35
32
  run: params.run,
36
33
  triggerPayload: params.triggerPayload,
37
34
  inputs: params.inputs ?? null,
38
35
  vars: params.vars,
39
36
  });
40
- return materializeWorkflowModel({
37
+ return await materializeWorkflowModel({
41
38
  model: params.model,
42
39
  context,
43
- resolveAgentDefaults: params.resolveAgentDefaults ?? catalogDefaultAgentResolver,
40
+ resolveAgentDefaults: params.resolveAgentDefaults,
44
41
  definitionId: params.definitionId,
45
42
  agentToolContext: params.agentToolContext,
46
43
  agentToolSnapshot: params.agentToolSnapshot,
@@ -1,9 +1,13 @@
1
- import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
1
+ import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';
2
+ import {readPersistedWorkflowModel} from '@shipfox/api-definitions-dto';
3
+ import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';
4
+ import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
2
5
  import {
3
6
  WORKFLOWS_JOB_ACTIVATED,
4
7
  type WorkflowsJobActivatedEventDto,
5
8
  } from '@shipfox/api-workflows-dto';
6
9
  import {and, asc, count, eq, inArray, isNull, notInArray, sql} from 'drizzle-orm';
10
+ import {type AgentDefaultsResolver, createAgentDefaultsResolver} from '#core/agent-defaults.js';
7
11
  import {loadAgentToolMaterializationContext} from '#core/agent-tools.js';
8
12
  import {isJobTerminal, type JobStatus, type ResolutionReason} from '#core/entities/job.js';
9
13
  import type {JobExecutionStatus, WorkflowExecutionEvent} from '#core/entities/job-execution.js';
@@ -174,7 +178,10 @@ export interface DrainListenerEventsParams {
174
178
  jobId: string;
175
179
  expectedSequence: number;
176
180
  maxSize?: number | undefined;
181
+ integrations?: IntegrationsModuleClient | undefined;
182
+ projects?: ProjectsModuleClient | undefined;
177
183
  resolveAgentDefaults?: AgentDefaultsResolver | undefined;
184
+ agent?: AgentInterModuleClient | undefined;
178
185
  }
179
186
 
180
187
  export async function drainListenerEventsIntoExecution(
@@ -191,22 +198,30 @@ export async function drainListenerEventsIntoExecution(
191
198
  if (bufferedEvents.length === 0) return {result: {kind: 'empty' as const}};
192
199
 
193
200
  const target = await loadListenerMaterializationTarget(params.jobId, tx);
201
+ const model =
202
+ target.attempt.model === null ? null : readPersistedWorkflowModel(target.attempt.model);
194
203
  const agentToolContext =
195
204
  target.attempt.agentToolMaterialization === null
196
205
  ? await loadAgentToolMaterializationContext({
197
- model: target.attempt.model,
206
+ model,
198
207
  workspaceId: target.run.workspaceId,
199
208
  projectId: target.run.projectId,
209
+ integrations: params.integrations,
210
+ projects: params.projects,
200
211
  })
201
212
  : undefined;
202
- const materialized = materializeListenerExecution({
203
- model: target.attempt.model,
213
+ const materialized = await materializeListenerExecution({
214
+ model,
204
215
  run: toWorkflowRun(target.run),
205
216
  job: toJob(target.job),
206
217
  sequence: params.expectedSequence,
207
218
  triggerEvents: listenerTriggerEvents(bufferedEvents),
208
219
  priorExecutions: target.priorExecutions,
209
- resolveAgentDefaults: params.resolveAgentDefaults,
220
+ resolveAgentDefaults:
221
+ params.resolveAgentDefaults ??
222
+ (params.agent
223
+ ? createAgentDefaultsResolver(params.agent, target.run.workspaceId)
224
+ : undefined),
210
225
  agentToolContext,
211
226
  agentToolSnapshot: target.attempt.agentToolMaterialization,
212
227
  });
@@ -6,7 +6,7 @@ const pgTable = pgTableCreator((name) => `runners_${name}`);
6
6
  export const runnerSessionScopeEnum = pgEnum('runners_runner_session_scope', ['workspace']);
7
7
  export const runnerSessionRegistrationTokenKindEnum = pgEnum(
8
8
  'runners_runner_session_registration_token_kind',
9
- ['manual', 'ephemeral'],
9
+ ['manual', 'ephemeral', 'activation'],
10
10
  );
11
11
 
12
12
  export const runnerSessions = pgTable('runner_sessions', {
@@ -17,7 +17,7 @@ export const runnerSessions = pgTable('runner_sessions', {
17
17
  registrationTokenKind:
18
18
  runnerSessionRegistrationTokenKindEnum('registration_token_kind').notNull(),
19
19
  provisionerId: uuid('provisioner_id'),
20
- provisionedRunnerId: text('provisioned_runner_id'),
20
+ providerRunnerId: text('provider_runner_id'),
21
21
  labels: text('labels').array().notNull(),
22
22
  maxClaims: integer('max_claims'),
23
23
  claimsUsed: integer('claims_used').notNull().default(0),
@@ -1,4 +1,8 @@
1
- import type {WorkflowModel} from '@shipfox/api-definitions';
1
+ import {
2
+ readPersistedWorkflowModel,
3
+ type WorkflowModel,
4
+ type WorkflowModelSnapshot,
5
+ } from '@shipfox/api-definitions-dto';
2
6
  import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
3
7
  import {sql} from 'drizzle-orm';
4
8
  import {check, integer, jsonb, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
@@ -18,7 +22,7 @@ export const workflowRunAttempts = pgTable(
18
22
  status: workflowRunStatusEnum('status').notNull().default('pending'),
19
23
  rerunMode: workflowRunRerunModeEnum('rerun_mode'),
20
24
  rerunByUserId: uuid('rerun_by_user_id'),
21
- model: jsonb('model').$type<WorkflowModel>(),
25
+ model: jsonb('model').$type<WorkflowModel | WorkflowModelSnapshot>(),
22
26
  agentToolMaterialization: jsonb(
23
27
  'agent_tool_materialization',
24
28
  ).$type<AgentToolMaterializationSnapshot>(),
@@ -48,7 +52,7 @@ export function toWorkflowRunAttempt(row: WorkflowRunAttemptDb): WorkflowRunAtte
48
52
  status: row.status,
49
53
  rerunMode: row.rerunMode ?? null,
50
54
  rerunByUserId: row.rerunByUserId,
51
- model: row.model ?? null,
55
+ model: row.model === null ? null : readPersistedWorkflowModel(row.model),
52
56
  agentToolMaterialization: row.agentToolMaterialization ?? null,
53
57
  version: row.version,
54
58
  createdAt: row.createdAt,
@@ -1,4 +1,4 @@
1
- import {DEFAULT_RUN_TIMEOUT_MS} from '@shipfox/api-definitions';
1
+ import {DEFAULT_RUN_TIMEOUT_MS} from '@shipfox/api-definitions-dto';
2
2
  import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
3
3
  import {sql} from 'drizzle-orm';
4
4
  import {
@@ -1,3 +1,5 @@
1
+ import {readPersistedWorkflowModel} from '@shipfox/api-definitions-dto';
2
+ import type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';
1
3
  import {WORKFLOWS_JOB_EXECUTION_TIMED_OUT} from '@shipfox/api-workflows-dto';
2
4
  import {and, asc, desc, eq, isNull, notInArray, sql} from 'drizzle-orm';
3
5
  import type {JobStatusReason} from '#core/entities/job.js';
@@ -116,6 +118,7 @@ export interface UpdateJobExecutionStatusAtVersionParams {
116
118
  expectedVersion: number;
117
119
  statusReason?: JobStatusReason | null | undefined;
118
120
  markTimedOut?: boolean;
121
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
119
122
  }
120
123
 
121
124
  async function resolveJobExecutionOutputs(
@@ -124,6 +127,7 @@ async function resolveJobExecutionOutputs(
124
127
  jobExecutionId: string;
125
128
  status: JobExecutionStatus;
126
129
  statusReason: JobStatusReason | null;
130
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
127
131
  },
128
132
  ): Promise<Record<string, unknown> | null> {
129
133
  const [target] = await tx
@@ -135,7 +139,8 @@ async function resolveJobExecutionOutputs(
135
139
  .where(eq(jobExecutions.id, params.jobExecutionId))
136
140
  .limit(1);
137
141
  if (!target) throw new JobNotFoundError(params.jobExecutionId);
138
- const model = target.attempt.model;
142
+ const model =
143
+ target.attempt.model === null ? null : readPersistedWorkflowModel(target.attempt.model);
139
144
  if (!model) return null;
140
145
  const modelJob = model.jobs.find((job) => job.key === target.job.key);
141
146
  if (!modelJob || modelJob.outputs === undefined) return null;
@@ -180,6 +185,7 @@ async function resolveJobExecutionOutputs(
180
185
  workspaceId: target.run.workspaceId,
181
186
  projectId: target.run.projectId,
182
187
  definitionId: target.run.definitionId,
188
+ secrets: params.secrets,
183
189
  }),
184
190
  });
185
191
  }
@@ -200,6 +206,7 @@ async function updateJobExecutionStatusAtVersion(
200
206
  jobExecutionId: params.jobExecutionId,
201
207
  status,
202
208
  statusReason,
209
+ secrets: params.secrets,
203
210
  });
204
211
  } catch (error) {
205
212
  if (!(error instanceof InterpolationUnresolvableError)) throw error;
@@ -239,6 +246,7 @@ export interface UpdateJobExecutionStatusParams {
239
246
  status: JobExecutionStatus;
240
247
  expectedVersion: number;
241
248
  statusReason?: JobStatusReason | null | undefined;
249
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
242
250
  }
243
251
 
244
252
  export async function updateJobExecutionStatus(
@@ -253,6 +261,7 @@ export async function updateJobExecutionStatus(
253
261
  status: params.status,
254
262
  expectedVersion: params.expectedVersion,
255
263
  statusReason,
264
+ secrets: params.secrets,
256
265
  }),
257
266
  fetchFn: async () => {
258
267
  const row = (
@@ -308,6 +317,7 @@ export async function failJobExecutionAsTimedOut(params: {
308
317
  jobExecutionId: string;
309
318
  workflowRunAttemptId: string;
310
319
  expectedVersion: number;
320
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
311
321
  }): Promise<JobExecution> {
312
322
  const result = await db().transaction(async (tx) => {
313
323
  const updated = await optimisticLockRetry({
@@ -318,6 +328,7 @@ export async function failJobExecutionAsTimedOut(params: {
318
328
  expectedVersion: params.expectedVersion,
319
329
  statusReason: 'timed_out',
320
330
  markTimedOut: true,
331
+ secrets: params.secrets,
321
332
  }),
322
333
  fetchFn: async () => {
323
334
  const row = (
@@ -359,6 +370,7 @@ export async function failJobExecutionAsTimedOut(params: {
359
370
  export async function resolveJobExecutionAfterLeaseExpiry(params: {
360
371
  jobExecutionId: string;
361
372
  expectedVersion: number;
373
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
362
374
  }): Promise<{status: RuntimeCompletionStatus; executionVersion: number}> {
363
375
  const result = await db().transaction(async (tx) => {
364
376
  const jobExecutionSteps = await getStepsByJobExecutionIdForUpdate(params.jobExecutionId, tx);
@@ -375,6 +387,7 @@ export async function resolveJobExecutionAfterLeaseExpiry(params: {
375
387
  status,
376
388
  expectedVersion: params.expectedVersion,
377
389
  statusReason: statusReasonForStepCompletion(status),
390
+ secrets: params.secrets,
378
391
  });
379
392
  changedJobExecution = updated?.changed ? updated.execution : null;
380
393
  } else {
@@ -383,6 +396,7 @@ export async function resolveJobExecutionAfterLeaseExpiry(params: {
383
396
  status: 'failed',
384
397
  expectedVersion: params.expectedVersion,
385
398
  statusReason: 'runner_lost',
399
+ secrets: params.secrets,
386
400
  });
387
401
  if (updated?.changed) {
388
402
  changedJobExecution = updated.execution;
@@ -1,3 +1,4 @@
1
+ import {readPersistedWorkflowModel} from '@shipfox/api-definitions-dto';
1
2
  import {WORKFLOWS_JOB_TERMINATED} from '@shipfox/api-workflows-dto';
2
3
  import {and, asc, desc, eq, inArray, notInArray, sql} from 'drizzle-orm';
3
4
  import {isJobTerminal, type Job, type JobStatus, type JobStatusReason} from '#core/entities/job.js';
@@ -161,7 +162,9 @@ export async function evaluateJobActivations(
161
162
  const target = targetsByJobId.get(input.jobId);
162
163
  if (!target) throw new Error(`Cannot evaluate missing activation job: ${input.jobId}`);
163
164
  const job = toJob(target.job);
164
- const modelJob = target.attempt.model?.jobs.find((item) => item.key === target.job.key);
165
+ const model =
166
+ target.attempt.model === null ? null : readPersistedWorkflowModel(target.attempt.model);
167
+ const modelJob = model?.jobs.find((item) => item.key === target.job.key);
165
168
  const decision = decideJobActivation({
166
169
  run: toWorkflowRun(target.run),
167
170
  job,
@@ -1,9 +1,11 @@
1
- import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
2
1
  import {normalizeWorkflowDocument} from '@shipfox/api-definitions';
3
2
  import {WORKFLOWS_WORKFLOW_RUN_ATTEMPT_CREATED} from '@shipfox/api-workflows-dto';
4
3
  import {and, eq, sql} from 'drizzle-orm';
4
+ import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
5
5
  import {InterpolationUnresolvableError} from '#core/errors.js';
6
6
  import {nextStepForJob, recordStepResult} from '#core/job-execution.js';
7
+ import {resolveTestAgentDefaults} from '#test/fixtures/agent-inter-module.js';
8
+ import {createTestSecretsClient} from '#test/fixtures/secrets-inter-module.js';
7
9
  import {buildModel, expression, shellRef, template} from '#test/helpers/workflow-runs.js';
8
10
  import {db} from '../db.js';
9
11
  import {workflowsOutbox} from '../schema/outbox.js';
@@ -45,6 +47,7 @@ describe('workflow run queries', () => {
45
47
  subscriptionId: crypto.randomUUID(),
46
48
  userId: crypto.randomUUID(),
47
49
  },
50
+ resolveAgentDefaults: resolveTestAgentDefaults,
48
51
  });
49
52
 
50
53
  expect(run.id).toBeDefined();
@@ -121,6 +124,7 @@ describe('workflow run queries', () => {
121
124
  subscriptionId: crypto.randomUUID(),
122
125
  userId: crypto.randomUUID(),
123
126
  },
127
+ resolveAgentDefaults: resolveTestAgentDefaults,
124
128
  });
125
129
  const [build, deploy] = await getJobsByWorkflowRunId(run.id);
126
130
  if (!build || !deploy) throw new Error('Expected build and deploy jobs');
@@ -564,6 +568,7 @@ describe('workflow run queries', () => {
564
568
  subscriptionId: crypto.randomUUID(),
565
569
  userId: crypto.randomUUID(),
566
570
  },
571
+ secrets: createTestSecretsClient(),
567
572
  });
568
573
  } catch (caught) {
569
574
  error = caught;
@@ -842,6 +847,7 @@ describe('workflow run queries', () => {
842
847
  subscriptionId: crypto.randomUUID(),
843
848
  userId: crypto.randomUUID(),
844
849
  },
850
+ resolveAgentDefaults: resolveTestAgentDefaults,
845
851
  });
846
852
 
847
853
  const runJobs = await getJobsByWorkflowRunId(run.id);
@@ -1,12 +1,11 @@
1
- import {
2
- type AgentDefaultsResolver,
3
- catalogDefaultAgentResolver,
4
- } from '@shipfox/api-agent/core/resolve-agent-config';
5
- import type {WorkflowModel} from '@shipfox/api-definitions';
6
- import {getVariablesByNamespace} from '@shipfox/api-secrets';
1
+ import {createWorkflowModelSnapshot, type WorkflowModel} from '@shipfox/api-definitions-dto';
2
+ import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';
3
+ import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
4
+ import type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';
7
5
  import {analyzeContextKeyAccess, type ResolvedFieldSegment} from '@shipfox/expression';
8
6
  import {logger} from '@shipfox/node-opentelemetry';
9
7
  import {eq} from 'drizzle-orm';
8
+ import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
10
9
  import {
11
10
  createAgentToolMaterializationSnapshot,
12
11
  loadAgentToolMaterializationContext,
@@ -49,14 +48,22 @@ export interface CreateWorkflowRunParams {
49
48
  sourceSnapshot?: WorkflowSourceSnapshot | null | undefined;
50
49
  triggerIdempotencyKey?: string | undefined;
51
50
  resolveAgentDefaults?: AgentDefaultsResolver | undefined;
51
+ secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
52
+ integrations?: IntegrationsModuleClient | undefined;
53
+ projects?: ProjectsModuleClient | undefined;
52
54
  }
53
55
 
54
56
  export async function createWorkflowRun(params: CreateWorkflowRunParams): Promise<WorkflowRun> {
55
- const agentToolContext = await loadAgentToolMaterializationContext({
56
- model: params.model,
57
- workspaceId: params.workspaceId,
58
- projectId: params.projectId,
59
- });
57
+ const agentToolContext =
58
+ params.integrations === undefined
59
+ ? undefined
60
+ : await loadAgentToolMaterializationContext({
61
+ model: params.model,
62
+ workspaceId: params.workspaceId,
63
+ projectId: params.projectId,
64
+ integrations: params.integrations,
65
+ projects: params.projects,
66
+ });
60
67
  const agentToolMaterialization = createAgentToolMaterializationSnapshot({
61
68
  model: params.model,
62
69
  context: agentToolContext,
@@ -109,7 +116,7 @@ export async function createWorkflowRun(params: CreateWorkflowRunParams): Promis
109
116
  workflowRunId: runRow.id,
110
117
  attempt: 1,
111
118
  status: 'pending',
112
- model: params.model,
119
+ model: createWorkflowModelSnapshot(params.model),
113
120
  agentToolMaterialization,
114
121
  })
115
122
  .returning();
@@ -125,14 +132,15 @@ export async function createWorkflowRun(params: CreateWorkflowRunParams): Promis
125
132
  workspaceId: params.workspaceId,
126
133
  projectId: params.projectId,
127
134
  definitionId: params.definitionId,
135
+ secrets: params.secrets,
128
136
  });
129
- const materializedJobs = materializeWorkflowRunJobs({
137
+ const materializedJobs = await materializeWorkflowRunJobs({
130
138
  run,
131
139
  model: params.model,
132
140
  triggerPayload: params.triggerPayload,
133
141
  inputs: params.inputs ?? null,
134
142
  vars,
135
- resolveAgentDefaults: params.resolveAgentDefaults ?? catalogDefaultAgentResolver,
143
+ resolveAgentDefaults: params.resolveAgentDefaults,
136
144
  definitionId: params.definitionId,
137
145
  agentToolContext,
138
146
  agentToolSnapshot: agentToolMaterialization,
@@ -178,12 +186,14 @@ export async function loadReferencedVariables(params: {
178
186
  readonly workspaceId: string;
179
187
  readonly projectId: string;
180
188
  readonly definitionId: string;
189
+ readonly secrets?: Pick<SecretsInterModuleClient, 'getVariablesByNamespace'> | undefined;
181
190
  }): Promise<Record<string, string> | undefined> {
182
191
  const references = referencedVariables(params.model, params.jobs ?? params.model.jobs);
183
192
  const keys = [...new Set(references.map((reference) => reference.key))].sort();
184
193
  if (keys.length === 0) return undefined;
185
194
 
186
- const vars = await getVariablesByNamespace({
195
+ if (!params.secrets) throw new Error('Secrets client is not configured.');
196
+ const {values: vars} = await params.secrets.getVariablesByNamespace({
187
197
  workspaceId: params.workspaceId,
188
198
  projectId: params.projectId,
189
199
  namespace: '',
@@ -1,5 +1,5 @@
1
- import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
2
1
  import {eq, inArray} from 'drizzle-orm';
2
+ import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
3
3
  import type {AgentToolMaterializationSnapshot} from '#core/agent-tools.js';
4
4
  import {NoFailedJobsError, RunNotTerminalError, SourceRunNotFoundError} from '#core/errors.js';
5
5
  import {nextStepForJob, recordStepResult} from '#core/job-execution.js';