@shipfox/api-workflows 5.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 +72 -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 +28 -21
  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
@@ -4,32 +4,35 @@ import { z } from 'zod';
4
4
  import { listRunAttempts } from '#db/index.js';
5
5
  import { toRunAttemptDto } from '#presentation/dto/index.js';
6
6
  import { requireAccessibleRun } from './require-accessible-run.js';
7
- export const listRunAttemptsRoute = defineRoute({
8
- method: 'GET',
9
- path: '/:id/attempts',
10
- description: 'List attempts in a workflow run lineage',
11
- schema: {
12
- params: z.object({
13
- id: z.string().uuid()
14
- }),
15
- response: {
16
- 200: workflowRunAttemptsResponseSchema
7
+ export function listRunAttemptsRoute(projects) {
8
+ return defineRoute({
9
+ method: 'GET',
10
+ path: '/:id/attempts',
11
+ description: 'List attempts in a workflow run lineage',
12
+ schema: {
13
+ params: z.object({
14
+ id: z.string().uuid()
15
+ }),
16
+ response: {
17
+ 200: workflowRunAttemptsResponseSchema
18
+ }
19
+ },
20
+ handler: async (request)=>{
21
+ const { id } = request.params;
22
+ const run = await requireAccessibleRun({
23
+ request,
24
+ id,
25
+ projects
26
+ });
27
+ const attempts = await listRunAttempts({
28
+ workflowRunId: run.id,
29
+ projectId: run.projectId
30
+ });
31
+ return {
32
+ attempts: attempts.map(toRunAttemptDto)
33
+ };
17
34
  }
18
- },
19
- handler: async (request)=>{
20
- const { id } = request.params;
21
- const run = await requireAccessibleRun({
22
- request,
23
- id
24
- });
25
- const attempts = await listRunAttempts({
26
- workflowRunId: run.id,
27
- projectId: run.projectId
28
- });
29
- return {
30
- attempts: attempts.map(toRunAttemptDto)
31
- };
32
- }
33
- });
35
+ });
36
+ }
34
37
 
35
38
  //# sourceMappingURL=list-run-attempts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/routes/list-run-attempts.ts"],"sourcesContent":["import {workflowRunAttemptsResponseSchema} from '@shipfox/api-workflows-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {listRunAttempts} from '#db/index.js';\nimport {toRunAttemptDto} from '#presentation/dto/index.js';\nimport {requireAccessibleRun} from './require-accessible-run.js';\n\nexport const listRunAttemptsRoute = defineRoute({\n method: 'GET',\n path: '/:id/attempts',\n description: 'List attempts in a workflow run lineage',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n response: {\n 200: workflowRunAttemptsResponseSchema,\n },\n },\n handler: async (request) => {\n const {id} = request.params;\n const run = await requireAccessibleRun({request, id});\n const attempts = await listRunAttempts({workflowRunId: run.id, projectId: run.projectId});\n\n return {attempts: attempts.map(toRunAttemptDto)};\n },\n});\n"],"names":["workflowRunAttemptsResponseSchema","defineRoute","z","listRunAttempts","toRunAttemptDto","requireAccessibleRun","listRunAttemptsRoute","method","path","description","schema","params","object","id","string","uuid","response","handler","request","run","attempts","workflowRunId","projectId","map"],"mappings":"AAAA,SAAQA,iCAAiC,QAAO,6BAA6B;AAC7E,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,eAAe,QAAO,eAAe;AAC7C,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,oBAAoB,QAAO,8BAA8B;AAEjE,OAAO,MAAMC,uBAAuBL,YAAY;IAC9CM,QAAQ;IACRC,MAAM;IACNC,aAAa;IACbC,QAAQ;QACNC,QAAQT,EAAEU,MAAM,CAAC;YACfC,IAAIX,EAAEY,MAAM,GAAGC,IAAI;QACrB;QACAC,UAAU;YACR,KAAKhB;QACP;IACF;IACAiB,SAAS,OAAOC;QACd,MAAM,EAACL,EAAE,EAAC,GAAGK,QAAQP,MAAM;QAC3B,MAAMQ,MAAM,MAAMd,qBAAqB;YAACa;YAASL;QAAE;QACnD,MAAMO,WAAW,MAAMjB,gBAAgB;YAACkB,eAAeF,IAAIN,EAAE;YAAES,WAAWH,IAAIG,SAAS;QAAA;QAEvF,OAAO;YAACF,UAAUA,SAASG,GAAG,CAACnB;QAAgB;IACjD;AACF,GAAG"}
1
+ {"version":3,"sources":["../../../src/presentation/routes/list-run-attempts.ts"],"sourcesContent":["import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {workflowRunAttemptsResponseSchema} from '@shipfox/api-workflows-dto';\nimport {defineRoute} from '@shipfox/node-fastify';\nimport {z} from 'zod';\nimport {listRunAttempts} from '#db/index.js';\nimport {toRunAttemptDto} from '#presentation/dto/index.js';\nimport {requireAccessibleRun} from './require-accessible-run.js';\n\nexport function listRunAttemptsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/:id/attempts',\n description: 'List attempts in a workflow run lineage',\n schema: {\n params: z.object({\n id: z.string().uuid(),\n }),\n response: {\n 200: workflowRunAttemptsResponseSchema,\n },\n },\n handler: async (request) => {\n const {id} = request.params;\n const run = await requireAccessibleRun({request, id, projects});\n const attempts = await listRunAttempts({workflowRunId: run.id, projectId: run.projectId});\n\n return {attempts: attempts.map(toRunAttemptDto)};\n },\n });\n}\n"],"names":["workflowRunAttemptsResponseSchema","defineRoute","z","listRunAttempts","toRunAttemptDto","requireAccessibleRun","listRunAttemptsRoute","projects","method","path","description","schema","params","object","id","string","uuid","response","handler","request","run","attempts","workflowRunId","projectId","map"],"mappings":"AACA,SAAQA,iCAAiC,QAAO,6BAA6B;AAC7E,SAAQC,WAAW,QAAO,wBAAwB;AAClD,SAAQC,CAAC,QAAO,MAAM;AACtB,SAAQC,eAAe,QAAO,eAAe;AAC7C,SAAQC,eAAe,QAAO,6BAA6B;AAC3D,SAAQC,oBAAoB,QAAO,8BAA8B;AAEjE,OAAO,SAASC,qBAAqBC,QAA8B;IACjE,OAAON,YAAY;QACjBO,QAAQ;QACRC,MAAM;QACNC,aAAa;QACbC,QAAQ;YACNC,QAAQV,EAAEW,MAAM,CAAC;gBACfC,IAAIZ,EAAEa,MAAM,GAAGC,IAAI;YACrB;YACAC,UAAU;gBACR,KAAKjB;YACP;QACF;QACAkB,SAAS,OAAOC;YACd,MAAM,EAACL,EAAE,EAAC,GAAGK,QAAQP,MAAM;YAC3B,MAAMQ,MAAM,MAAMf,qBAAqB;gBAACc;gBAASL;gBAAIP;YAAQ;YAC7D,MAAMc,WAAW,MAAMlB,gBAAgB;gBAACmB,eAAeF,IAAIN,EAAE;gBAAES,WAAWH,IAAIG,SAAS;YAAA;YAEvF,OAAO;gBAACF,UAAUA,SAASG,GAAG,CAACpB;YAAgB;QACjD;IACF;AACF"}
@@ -1,2 +1,3 @@
1
- export declare const listRunsRoute: import("@shipfox/node-fastify").RouteDefinition;
1
+ import type { ProjectsModuleClient } from '@shipfox/api-projects-dto';
2
+ export declare function listRunsRoute(projects: ProjectsModuleClient): import("@shipfox/node-fastify").RouteDefinition;
2
3
  //# sourceMappingURL=list-runs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"list-runs.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-runs.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa,iDAuExB,CAAC"}
1
+ {"version":3,"file":"list-runs.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/list-runs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAYpE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,oBAAoB,mDAmE3D"}
@@ -1,70 +1,61 @@
1
- import { ProjectNotFoundError, requireProjectAccess } from '@shipfox/api-projects';
2
1
  import { workflowRunListQuerySchema, workflowRunListResponseSchema } from '@shipfox/api-workflows-dto';
3
2
  import { decodeTimestampIdCursor, encodeTimestampIdCursor } from '@shipfox/node-drizzle';
4
3
  import { ClientError, defineRoute } from '@shipfox/node-fastify';
5
4
  import { logger } from '@shipfox/node-opentelemetry';
6
5
  import { listWorkflowRuns } from '#db/index.js';
7
6
  import { toRunDto } from '#presentation/dto/index.js';
8
- export const listRunsRoute = defineRoute({
9
- method: 'GET',
10
- path: '/',
11
- description: 'List workflow runs for a project',
12
- schema: {
13
- querystring: workflowRunListQuerySchema,
14
- response: {
15
- 200: workflowRunListResponseSchema
16
- }
17
- },
18
- errorHandler: (error)=>{
19
- if (error instanceof ProjectNotFoundError) {
20
- throw new ClientError(error.message, 'project-not-found', {
21
- status: 404
22
- });
23
- }
24
- throw error;
25
- },
26
- handler: async (request)=>{
27
- const startedAt = performance.now();
28
- const { project_id: projectId, limit, cursor, status, definition_id: definitionId, trigger_source: triggerSource, created_from: createdFrom, created_to: createdTo } = request.query;
29
- const decodedCursor = decodeTimestampIdCursor(cursor);
30
- if (cursor && !decodedCursor) {
31
- throw new ClientError('Invalid cursor', 'invalid-cursor', {
32
- status: 400
7
+ import { requireProjectAccess } from './project-access.js';
8
+ export function listRunsRoute(projects) {
9
+ return defineRoute({
10
+ method: 'GET',
11
+ path: '/',
12
+ description: 'List workflow runs for a project',
13
+ schema: {
14
+ querystring: workflowRunListQuerySchema,
15
+ response: {
16
+ 200: workflowRunListResponseSchema
17
+ }
18
+ },
19
+ handler: async (request)=>{
20
+ const startedAt = performance.now();
21
+ const { project_id: projectId, limit, cursor, status, definition_id: definitionId, trigger_source: triggerSource, created_from: createdFrom, created_to: createdTo } = request.query;
22
+ const decodedCursor = decodeTimestampIdCursor(cursor);
23
+ if (cursor && !decodedCursor) {
24
+ throw new ClientError('Invalid cursor', 'invalid-cursor', {
25
+ status: 400
26
+ });
27
+ }
28
+ const project = await requireProjectAccess(request, projectId, projects);
29
+ const filters = {
30
+ status,
31
+ definitionId,
32
+ triggerSource,
33
+ createdFrom: createdFrom ? new Date(createdFrom) : undefined,
34
+ createdTo: createdTo ? new Date(createdTo) : undefined
35
+ };
36
+ const result = await listWorkflowRuns({
37
+ projectId: project.id,
38
+ limit,
39
+ cursor: decodedCursor,
40
+ filters,
41
+ includeTotal: !decodedCursor
33
42
  });
43
+ logger().info({
44
+ projectId: project.id,
45
+ filterKeys: Object.entries(filters).filter(([, value])=>value !== undefined).map(([key])=>key),
46
+ limit,
47
+ cursorPresent: Boolean(cursor),
48
+ resultCount: result.runs.length,
49
+ nextCursorPresent: Boolean(result.nextCursor),
50
+ durationMs: Math.round(performance.now() - startedAt)
51
+ }, 'Listed workflow runs');
52
+ return {
53
+ runs: result.runs.map((run)=>toRunDto(run)),
54
+ next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,
55
+ filtered_total_count: result.filteredTotalCount
56
+ };
34
57
  }
35
- const { project } = await requireProjectAccess({
36
- request,
37
- projectId
38
- });
39
- const filters = {
40
- status,
41
- definitionId,
42
- triggerSource,
43
- createdFrom: createdFrom ? new Date(createdFrom) : undefined,
44
- createdTo: createdTo ? new Date(createdTo) : undefined
45
- };
46
- const result = await listWorkflowRuns({
47
- projectId: project.id,
48
- limit,
49
- cursor: decodedCursor,
50
- filters,
51
- includeTotal: !decodedCursor
52
- });
53
- logger().info({
54
- projectId: project.id,
55
- filterKeys: Object.entries(filters).filter(([, value])=>value !== undefined).map(([key])=>key),
56
- limit,
57
- cursorPresent: Boolean(cursor),
58
- resultCount: result.runs.length,
59
- nextCursorPresent: Boolean(result.nextCursor),
60
- durationMs: Math.round(performance.now() - startedAt)
61
- }, 'Listed workflow runs');
62
- return {
63
- runs: result.runs.map((run)=>toRunDto(run)),
64
- next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,
65
- filtered_total_count: result.filteredTotalCount
66
- };
67
- }
68
- });
58
+ });
59
+ }
69
60
 
70
61
  //# sourceMappingURL=list-runs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/routes/list-runs.ts"],"sourcesContent":["import {ProjectNotFoundError, requireProjectAccess} from '@shipfox/api-projects';\nimport {\n workflowRunListQuerySchema,\n workflowRunListResponseSchema,\n} from '@shipfox/api-workflows-dto';\nimport {decodeTimestampIdCursor, encodeTimestampIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {listWorkflowRuns} from '#db/index.js';\nimport {toRunDto} from '#presentation/dto/index.js';\n\nexport const listRunsRoute = defineRoute({\n method: 'GET',\n path: '/',\n description: 'List workflow runs for a project',\n schema: {\n querystring: workflowRunListQuerySchema,\n response: {\n 200: workflowRunListResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof ProjectNotFoundError) {\n throw new ClientError(error.message, 'project-not-found', {status: 404});\n }\n throw error;\n },\n handler: async (request) => {\n const startedAt = performance.now();\n const {\n project_id: projectId,\n limit,\n cursor,\n status,\n definition_id: definitionId,\n trigger_source: triggerSource,\n created_from: createdFrom,\n created_to: createdTo,\n } = request.query;\n const decodedCursor = decodeTimestampIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const {project} = await requireProjectAccess({request, projectId});\n\n const filters = {\n status,\n definitionId,\n triggerSource,\n createdFrom: createdFrom ? new Date(createdFrom) : undefined,\n createdTo: createdTo ? new Date(createdTo) : undefined,\n };\n const result = await listWorkflowRuns({\n projectId: project.id,\n limit,\n cursor: decodedCursor,\n filters,\n includeTotal: !decodedCursor,\n });\n\n logger().info(\n {\n projectId: project.id,\n filterKeys: Object.entries(filters)\n .filter(([, value]) => value !== undefined)\n .map(([key]) => key),\n limit,\n cursorPresent: Boolean(cursor),\n resultCount: result.runs.length,\n nextCursorPresent: Boolean(result.nextCursor),\n durationMs: Math.round(performance.now() - startedAt),\n },\n 'Listed workflow runs',\n );\n\n return {\n runs: result.runs.map((run) => toRunDto(run)),\n next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,\n filtered_total_count: result.filteredTotalCount,\n };\n },\n});\n"],"names":["ProjectNotFoundError","requireProjectAccess","workflowRunListQuerySchema","workflowRunListResponseSchema","decodeTimestampIdCursor","encodeTimestampIdCursor","ClientError","defineRoute","logger","listWorkflowRuns","toRunDto","listRunsRoute","method","path","description","schema","querystring","response","errorHandler","error","message","status","handler","request","startedAt","performance","now","project_id","projectId","limit","cursor","definition_id","definitionId","trigger_source","triggerSource","created_from","createdFrom","created_to","createdTo","query","decodedCursor","project","filters","Date","undefined","result","id","includeTotal","info","filterKeys","Object","entries","filter","value","map","key","cursorPresent","Boolean","resultCount","runs","length","nextCursorPresent","nextCursor","durationMs","Math","round","run","next_cursor","filtered_total_count","filteredTotalCount"],"mappings":"AAAA,SAAQA,oBAAoB,EAAEC,oBAAoB,QAAO,wBAAwB;AACjF,S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ASwC,IAAI,CACX;YACEpB,WAAWa,QAAQK,EAAE;YACrBG,YAAYC,OAAOC,OAAO,CAACT,SACxBU,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAKA,UAAUT,WAChCU,GAAG,CAAC,CAAC,CAACC,IAAI,GAAKA;YAClB1B;YACA2B,eAAeC,QAAQ3B;YACvB4B,aAAab,OAAOc,IAAI,CAACC,MAAM;YAC/BC,mBAAmBJ,QAAQZ,OAAOiB,UAAU;YAC5CC,YAAYC,KAAKC,KAAK,CAACxC,YAAYC,GAAG,KAAKF;QAC7C,GACA;QAGF,OAAO;YACLmC,MAAMd,OAAOc,IAAI,CAACL,GAAG,CAAC,CAACY,MAAQxD,SAASwD;YACxCC,aAAatB,OAAOiB,UAAU,GAAGzD,wBAAwBwC,OAAOiB,UAAU,IAAI;YAC9EM,sBAAsBvB,OAAOwB,kBAAkB;QACjD;IACF;AACF,GAAG"}
1
+ {"version":3,"sources":["../../../src/presentation/routes/list-runs.ts"],"sourcesContent":["import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {\n workflowRunListQuerySchema,\n workflowRunListResponseSchema,\n} from '@shipfox/api-workflows-dto';\nimport {decodeTimestampIdCursor, encodeTimestampIdCursor} from '@shipfox/node-drizzle';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {logger} from '@shipfox/node-opentelemetry';\nimport {listWorkflowRuns} from '#db/index.js';\nimport {toRunDto} from '#presentation/dto/index.js';\nimport {requireProjectAccess} from './project-access.js';\n\nexport function listRunsRoute(projects: ProjectsModuleClient) {\n return defineRoute({\n method: 'GET',\n path: '/',\n description: 'List workflow runs for a project',\n schema: {\n querystring: workflowRunListQuerySchema,\n response: {\n 200: workflowRunListResponseSchema,\n },\n },\n handler: async (request) => {\n const startedAt = performance.now();\n const {\n project_id: projectId,\n limit,\n cursor,\n status,\n definition_id: definitionId,\n trigger_source: triggerSource,\n created_from: createdFrom,\n created_to: createdTo,\n } = request.query;\n const decodedCursor = decodeTimestampIdCursor(cursor);\n if (cursor && !decodedCursor) {\n throw new ClientError('Invalid cursor', 'invalid-cursor', {status: 400});\n }\n\n const project = await requireProjectAccess(request, projectId, projects);\n\n const filters = {\n status,\n definitionId,\n triggerSource,\n createdFrom: createdFrom ? new Date(createdFrom) : undefined,\n createdTo: createdTo ? new Date(createdTo) : undefined,\n };\n const result = await listWorkflowRuns({\n projectId: project.id,\n limit,\n cursor: decodedCursor,\n filters,\n includeTotal: !decodedCursor,\n });\n\n logger().info(\n {\n projectId: project.id,\n filterKeys: Object.entries(filters)\n .filter(([, value]) => value !== undefined)\n .map(([key]) => key),\n limit,\n cursorPresent: Boolean(cursor),\n resultCount: result.runs.length,\n nextCursorPresent: Boolean(result.nextCursor),\n durationMs: Math.round(performance.now() - startedAt),\n },\n 'Listed workflow runs',\n );\n\n return {\n runs: result.runs.map((run) => toRunDto(run)),\n next_cursor: result.nextCursor ? encodeTimestampIdCursor(result.nextCursor) : null,\n filtered_total_count: result.filteredTotalCount,\n };\n },\n });\n}\n"],"names":["workflowRunListQuerySchema","workflowRunListResponseSchema","decodeTimestampIdCursor","encodeTimestampIdCursor","ClientError","defineRoute","logger","listWorkflowRuns","toRunDto","requireProjectAccess","listRunsRoute","projects","method","path","description","schema","querystring","response","handler","request","startedAt","performance","now","project_id","projectId","limit","cursor","status","definition_id","definitionId","trigger_source","triggerSource","created_from","createdFrom","created_to","createdTo","query","decodedCursor","project","filters","Date","undefined","result","id","includeTotal","info","filterKeys","Object","entries","filter","value","map","key","cursorPresent","Boolean","resultCount","runs","length","nextCursorPresent","nextCursor","durationMs","Math","round","run","next_cursor","filtered_total_count","filteredTotalCount"],"mappings":"AACA,SACEA,0BAA0B,EAC1BC,6BAA6B,QACxB,6BAA6B;AACpC,SAAQC,uBAAuB,EAAEC,uBAAuB,QAAO,wBAAwB;AACvF,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,MAAM,QAAO,8BAA8B;AACnD,SAAQC,gBAAgB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U;gBAC5CC,YAAYC,KAAKC,KAAK,CAACzC,YAAYC,GAAG,KAAKF;YAC7C,GACA;YAGF,OAAO;gBACLoC,MAAMd,OAAOc,IAAI,CAACL,GAAG,CAAC,CAACY,MAAQvD,SAASuD;gBACxCC,aAAatB,OAAOiB,UAAU,GAAGxD,wBAAwBuC,OAAOiB,UAAU,IAAI;gBAC9EM,sBAAsBvB,OAAOwB,kBAAkB;YACjD;QACF;IACF;AACF"}
@@ -1,2 +1,11 @@
1
- export declare const nextStepRoute: import("@shipfox/node-fastify").RouteDefinition;
1
+ import type { AnnotationsInterModuleClient } from '@shipfox/annotations-dto/inter-module';
2
+ import type { AgentInterModuleClient } from '@shipfox/api-agent-dto/inter-module';
3
+ import type { AuthInterModuleClient } from '@shipfox/api-auth-dto/inter-module';
4
+ import type { RunnersInterModuleClient } from '@shipfox/api-runners-dto/inter-module';
5
+ export declare function createNextStepRoute(params: {
6
+ agent: AgentInterModuleClient;
7
+ annotations: AnnotationsInterModuleClient;
8
+ auth: AuthInterModuleClient;
9
+ runners: RunnersInterModuleClient;
10
+ }): import("@shipfox/node-fastify").RouteDefinition;
2
11
  //# sourceMappingURL=next-step.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"next-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/next-step.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,iDAoDxB,CAAC"}
1
+ {"version":3,"file":"next-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/next-step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,uCAAuC,CAAC;AACxF,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAC;AAEhF,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,oCAAoC,CAAC;AAC9E,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAQpF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,KAAK,EAAE,sBAAsB,CAAC;IAC9B,WAAW,EAAE,4BAA4B,CAAC;IAC1C,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,EAAE,wBAAwB,CAAC;CACnC,mDAgEA"}
@@ -1,4 +1,3 @@
1
- import { issueJobLeaseToken, jobLeaseParamsFrom } from '@shipfox/api-auth';
2
1
  import { requireLeasedJobContext } from '@shipfox/api-auth-context';
3
2
  import { nextStepResponseSchema } from '@shipfox/api-workflows-dto';
4
3
  import { ClientError, defineRoute } from '@shipfox/node-fastify';
@@ -6,60 +5,75 @@ import { warnAgentToolCapabilityMismatchOnDispatch } from '#core/agent-tool-capa
6
5
  import { JobLeaseNotActiveError, JobNotFoundError } from '#core/errors.js';
7
6
  import { nextStepForLeasedJobExecution } from '#core/job-execution.js';
8
7
  import { toStepDto } from '#presentation/dto/step.js';
9
- export const nextStepRoute = defineRoute({
10
- method: 'POST',
11
- path: '/steps/next',
12
- description: 'Returns the next step for the runner to run on its job. The job is identified by the access token, so no job ID is needed. Calling this again before reporting the current step returns that same step, so retries are safe. When no runnable steps remain, the response reports that there are no more steps to run, along with the job status; the runner then stops. Finalization is driven server-side from recorded step results and dispatch-time skips, not by the runner calling a job-completion endpoint.',
13
- schema: {
14
- response: {
15
- 200: nextStepResponseSchema
16
- }
17
- },
18
- errorHandler: (error)=>{
19
- if (error instanceof JobNotFoundError) {
20
- throw new ClientError(error.message, 'job-not-found', {
21
- status: 404
22
- });
23
- }
24
- if (error instanceof JobLeaseNotActiveError) {
25
- throw new ClientError('Job lease is no longer active', 'lease-not-active', {
26
- status: 404
8
+ export function createNextStepRoute(params) {
9
+ return defineRoute({
10
+ method: 'POST',
11
+ path: '/steps/next',
12
+ description: 'Returns the next step for the runner to run on its job. The job is identified by the access token, so no job ID is needed. Calling this again before reporting the current step returns that same step, so retries are safe. When no runnable steps remain, the response reports that there are no more steps to run, along with the job status; the runner then stops. Finalization is driven server-side from recorded step results and dispatch-time skips, not by the runner calling a job-completion endpoint.',
13
+ schema: {
14
+ response: {
15
+ 200: nextStepResponseSchema
16
+ }
17
+ },
18
+ errorHandler: (error)=>{
19
+ if (error instanceof JobNotFoundError) {
20
+ throw new ClientError(error.message, 'job-not-found', {
21
+ status: 404
22
+ });
23
+ }
24
+ if (error instanceof JobLeaseNotActiveError) {
25
+ throw new ClientError('Job lease is no longer active', 'lease-not-active', {
26
+ status: 404
27
+ });
28
+ }
29
+ throw error;
30
+ },
31
+ handler: async (request)=>{
32
+ const leasedJob = requireLeasedJobContext(request);
33
+ const next = await nextStepForLeasedJobExecution({
34
+ jobId: leasedJob.jobId,
35
+ jobExecutionId: leasedJob.jobExecutionId,
36
+ runnerSessionId: leasedJob.runnerSessionId,
37
+ agent: params.agent
27
38
  });
28
- }
29
- throw error;
30
- },
31
- handler: async (request)=>{
32
- const leasedJob = requireLeasedJobContext(request);
33
- const next = await nextStepForLeasedJobExecution({
34
- jobId: leasedJob.jobId,
35
- jobExecutionId: leasedJob.jobExecutionId,
36
- runnerSessionId: leasedJob.runnerSessionId
37
- });
38
- if (next.kind === 'step') {
39
- const leaseToken = await issueJobLeaseToken(jobLeaseParamsFrom(leasedJob, {
40
- currentStepId: next.step.id,
41
- currentStepAttempt: next.step.currentAttempt
42
- }));
43
- if (next.dispatched) {
44
- await warnAgentToolCapabilityMismatchOnDispatch({
45
- leaseIdentity: leasedJob,
46
- step: next.step
39
+ if (next.kind === 'step') {
40
+ const { token: leaseToken } = await params.auth.mintJobLeaseToken({
41
+ workflowRunId: leasedJob.workflowRunId,
42
+ ...leasedJob.workflowRunAttempt === undefined ? {} : {
43
+ workflowRunAttempt: leasedJob.workflowRunAttempt
44
+ },
45
+ workflowRunAttemptId: leasedJob.workflowRunAttemptId,
46
+ jobId: leasedJob.jobId,
47
+ jobExecutionId: leasedJob.jobExecutionId,
48
+ projectId: leasedJob.projectId,
49
+ workspaceId: leasedJob.workspaceId,
50
+ runnerSessionId: leasedJob.runnerSessionId,
51
+ currentStepId: next.step.id,
52
+ currentStepAttempt: next.step.currentAttempt
47
53
  });
54
+ if (next.dispatched) {
55
+ await warnAgentToolCapabilityMismatchOnDispatch({
56
+ annotations: params.annotations,
57
+ runners: params.runners,
58
+ leaseIdentity: leasedJob,
59
+ step: next.step
60
+ });
61
+ }
62
+ // The runner echoes this back on report so a stale report from a superseded
63
+ // attempt is ignored.
64
+ return {
65
+ kind: 'step',
66
+ step: toStepDto(next.step),
67
+ attempt: next.step.currentAttempt,
68
+ lease_token: leaseToken
69
+ };
48
70
  }
49
- // The runner echoes this back on report so a stale report from a superseded
50
- // attempt is ignored.
51
71
  return {
52
- kind: 'step',
53
- step: toStepDto(next.step),
54
- attempt: next.step.currentAttempt,
55
- lease_token: leaseToken
72
+ kind: 'done',
73
+ status: next.status
56
74
  };
57
75
  }
58
- return {
59
- kind: 'done',
60
- status: next.status
61
- };
62
- }
63
- });
76
+ });
77
+ }
64
78
 
65
79
  //# sourceMappingURL=next-step.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/presentation/routes/next-step.ts"],"sourcesContent":["import {issueJobLeaseToken, jobLeaseParamsFrom} from '@shipfox/api-auth';\nimport {requireLeasedJobContext} from '@shipfox/api-auth-context';\nimport {nextStepResponseSchema} from '@shipfox/api-workflows-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {warnAgentToolCapabilityMismatchOnDispatch} from '#core/agent-tool-capability-warning.js';\nimport {JobLeaseNotActiveError, JobNotFoundError} from '#core/errors.js';\nimport {nextStepForLeasedJobExecution} from '#core/job-execution.js';\nimport {toStepDto} from '#presentation/dto/step.js';\n\nexport const nextStepRoute = defineRoute({\n method: 'POST',\n path: '/steps/next',\n description:\n 'Returns the next step for the runner to run on its job. The job is identified by the access token, so no job ID is needed. Calling this again before reporting the current step returns that same step, so retries are safe. When no runnable steps remain, the response reports that there are no more steps to run, along with the job status; the runner then stops. Finalization is driven server-side from recorded step results and dispatch-time skips, not by the runner calling a job-completion endpoint.',\n schema: {\n response: {\n 200: nextStepResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof JobNotFoundError) {\n throw new ClientError(error.message, 'job-not-found', {status: 404});\n }\n if (error instanceof JobLeaseNotActiveError) {\n throw new ClientError('Job lease is no longer active', 'lease-not-active', {status: 404});\n }\n throw error;\n },\n handler: async (request) => {\n const leasedJob = requireLeasedJobContext(request);\n\n const next = await nextStepForLeasedJobExecution({\n jobId: leasedJob.jobId,\n jobExecutionId: leasedJob.jobExecutionId,\n runnerSessionId: leasedJob.runnerSessionId,\n });\n\n if (next.kind === 'step') {\n const leaseToken = await issueJobLeaseToken(\n jobLeaseParamsFrom(leasedJob, {\n currentStepId: next.step.id,\n currentStepAttempt: next.step.currentAttempt,\n }),\n );\n if (next.dispatched) {\n await warnAgentToolCapabilityMismatchOnDispatch({\n leaseIdentity: leasedJob,\n step: next.step,\n });\n }\n // The runner echoes this back on report so a stale report from a superseded\n // attempt is ignored.\n return {\n kind: 'step' as const,\n step: toStepDto(next.step),\n attempt: next.step.currentAttempt,\n lease_token: leaseToken,\n };\n }\n return {kind: 'done' as const, status: next.status};\n },\n});\n"],"names":["issueJobLeaseToken","jobLeaseParamsFrom","requireLeasedJobContext","nextStepResponseSchema","ClientError","defineRoute","warnAgentToolCapabilityMismatchOnDispatch","JobLeaseNotActiveError","JobNotFoundError","nextStepForLeasedJobExecution","toStepDto","nextStepRoute","method","path","description","schema","response","errorHandler","error","message","status","handler","request","leasedJob","next","jobId","jobExecutionId","runnerSessionId","kind","leaseToken","currentStepId","step","id","currentStepAttempt","currentAttempt","dispatched","leaseIdentity","attempt","lease_token"],"mappings":"AAAA,SAAQA,kBAAkB,EAAEC,kBAAkB,QAAO,oBAAoB;AACzE,SAAQC,uBAAuB,QAAO,4BAA4B;AAClE,SAAQC,sBAAsB,QAAO,6BAA6B;AAClE,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,yCAAyC,QAAO,yCAAyC;AACjG,SAAQC,sBAAsB,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ourcesContent":["import type {AnnotationsInterModuleClient} from '@shipfox/annotations-dto/inter-module';\nimport type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';\nimport {requireLeasedJobContext} from '@shipfox/api-auth-context';\nimport type {AuthInterModuleClient} from '@shipfox/api-auth-dto/inter-module';\nimport type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';\nimport {nextStepResponseSchema} from '@shipfox/api-workflows-dto';\nimport {ClientError, defineRoute} from '@shipfox/node-fastify';\nimport {warnAgentToolCapabilityMismatchOnDispatch} from '#core/agent-tool-capability-warning.js';\nimport {JobLeaseNotActiveError, JobNotFoundError} from '#core/errors.js';\nimport {nextStepForLeasedJobExecution} from '#core/job-execution.js';\nimport {toStepDto} from '#presentation/dto/step.js';\n\nexport function createNextStepRoute(params: {\n agent: AgentInterModuleClient;\n annotations: AnnotationsInterModuleClient;\n auth: AuthInterModuleClient;\n runners: RunnersInterModuleClient;\n}) {\n return defineRoute({\n method: 'POST',\n path: '/steps/next',\n description:\n 'Returns the next step for the runner to run on its job. The job is identified by the access token, so no job ID is needed. Calling this again before reporting the current step returns that same step, so retries are safe. When no runnable steps remain, the response reports that there are no more steps to run, along with the job status; the runner then stops. Finalization is driven server-side from recorded step results and dispatch-time skips, not by the runner calling a job-completion endpoint.',\n schema: {\n response: {\n 200: nextStepResponseSchema,\n },\n },\n errorHandler: (error) => {\n if (error instanceof JobNotFoundError) {\n throw new ClientError(error.message, 'job-not-found', {status: 404});\n }\n if (error instanceof JobLeaseNotActiveError) {\n throw new ClientError('Job lease is no longer active', 'lease-not-active', {status: 404});\n }\n throw error;\n },\n handler: async (request) => {\n const leasedJob = requireLeasedJobContext(request);\n const next = await nextStepForLeasedJobExecution({\n jobId: leasedJob.jobId,\n jobExecutionId: leasedJob.jobExecutionId,\n runnerSessionId: leasedJob.runnerSessionId,\n agent: params.agent,\n });\n\n if (next.kind === 'step') {\n const {token: leaseToken} = await params.auth.mintJobLeaseToken({\n workflowRunId: leasedJob.workflowRunId,\n ...(leasedJob.workflowRunAttempt === undefined\n ? {}\n : {workflowRunAttempt: leasedJob.workflowRunAttempt}),\n workflowRunAttemptId: leasedJob.workflowRunAttemptId,\n jobId: leasedJob.jobId,\n jobExecutionId: leasedJob.jobExecutionId,\n projectId: leasedJob.projectId,\n workspaceId: leasedJob.workspaceId,\n runnerSessionId: leasedJob.runnerSessionId,\n currentStepId: next.step.id,\n currentStepAttempt: next.step.currentAttempt,\n });\n if (next.dispatched) {\n await warnAgentToolCapabilityMismatchOnDispatch({\n annotations: params.annotations,\n runners: params.runners,\n leaseIdentity: leasedJob,\n step: next.step,\n });\n }\n // The runner echoes this back on report so a stale report from a superseded\n // attempt is ignored.\n return {\n kind: 'step' as const,\n step: toStepDto(next.step),\n attempt: next.step.currentAttempt,\n lease_token: leaseToken,\n };\n }\n return {kind: 'done' as const, status: next.status};\n },\n });\n}\n"],"names":["requireLeasedJobContext","nextStepResponseSchema","ClientError","defineRoute","warnAgentToolCapabilityMismatchOnDispatch","JobLeaseNotActiveError","JobNotFoundError","nextStepForLeasedJobExecution","toStepDto","createNextStepRoute","params","method","path","description","schema","response","errorHandler","error","message","status","handler","request","leasedJob","next","jobId","jobExecutionId","runnerSessionId","agent","kind","token","leaseToken","auth","mintJobLeaseToken","workflowRunId","workflowRunAttempt","undefined","workflowRunAttemptId","projectId","workspaceId","currentStepId","step","id","currentStepAttempt","currentAttempt","dispatched","annotations","runners","leaseIdentity","attempt","lease_token"],"mappings":"AAEA,SAAQA,uBAAuB,QAAO,4BAA4B;AAGlE,SAAQC,sBAAsB,QAAO,6BAA6B;AAClE,SAAQC,WAAW,EAAEC,WAAW,QAAO,wBAAwB;AAC/D,SAAQC,yCAAyC,QAAO,yCAAyC;AACjG,SAAQC,sBAAsB,EAAEC,gBAAgB,QAAO,kBAAkB;AACzE,SAAQC,6BAA6B,QAAO,yBAAyB;AACrE,SAAQC,SAAS,QAAO,4BAA4B;AAEpD,OAAO,SAASC,oBAAoBC,MAKnC;I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C,OAAOoC,OAAO;wBACvBC,eAAezB;wBACfkB,MAAMjB,KAAKiB,IAAI;oBACjB;gBACF;gBACA,4EAA4E;gBAC5E,sBAAsB;gBACtB,OAAO;oBACLZ,MAAM;oBACNY,MAAMhC,UAAUe,KAAKiB,IAAI;oBACzBQ,SAASzB,KAAKiB,IAAI,CAACG,cAAc;oBACjCM,aAAanB;gBACf;YACF;YACA,OAAO;gBAACF,MAAM;gBAAiBT,QAAQI,KAAKJ,MAAM;YAAA;QACpD;IACF;AACF"}
@@ -0,0 +1,10 @@
1
+ import type { ProjectsModuleClient } from '@shipfox/api-projects-dto';
2
+ import type { FastifyRequest } from 'fastify';
3
+ export declare function requireProjectAccess(request: FastifyRequest, projectId: string, projects: ProjectsModuleClient): Promise<{
4
+ id: string;
5
+ workspaceId: string;
6
+ sourceConnectionId: string;
7
+ sourceExternalRepositoryId: string;
8
+ name: string;
9
+ }>;
10
+ //# sourceMappingURL=project-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-access.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/project-access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAE5C,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,oBAAoB;;;;;;GAO/B"}
@@ -0,0 +1,17 @@
1
+ import { requireWorkspaceAccess } from '@shipfox/api-auth-context';
2
+ import { ClientError } from '@shipfox/node-fastify';
3
+ export async function requireProjectAccess(request, projectId, projects) {
4
+ const result = await projects.getProjectById({
5
+ projectId
6
+ });
7
+ if (result.project === null) throw new ClientError('Project not found', 'project-not-found', {
8
+ status: 404
9
+ });
10
+ requireWorkspaceAccess({
11
+ request,
12
+ workspaceId: result.project.workspaceId
13
+ });
14
+ return result.project;
15
+ }
16
+
17
+ //# sourceMappingURL=project-access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/presentation/routes/project-access.ts"],"sourcesContent":["import {requireWorkspaceAccess} from '@shipfox/api-auth-context';\nimport type {ProjectsModuleClient} from '@shipfox/api-projects-dto';\nimport {ClientError} from '@shipfox/node-fastify';\nimport type {FastifyRequest} from 'fastify';\n\nexport async function requireProjectAccess(\n request: FastifyRequest,\n projectId: string,\n projects: ProjectsModuleClient,\n) {\n const result = await projects.getProjectById({projectId});\n if (result.project === null)\n throw new ClientError('Project not found', 'project-not-found', {status: 404});\n requireWorkspaceAccess({request, workspaceId: result.project.workspaceId});\n return result.project;\n}\n"],"names":["requireWorkspaceAccess","ClientError","requireProjectAccess","request","projectId","projects","result","getProjectById","project","status","workspaceId"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,4BAA4B;AAEjE,SAAQC,WAAW,QAAO,wBAAwB;AAGlD,OAAO,eAAeC,qBACpBC,OAAuB,EACvBC,SAAiB,EACjBC,QAA8B;IAE9B,MAAMC,SAAS,MAAMD,SAASE,cAAc,CAAC;QAACH;IAAS;IACvD,IAAIE,OAAOE,OAAO,KAAK,MACrB,MAAM,IAAIP,YAAY,qBAAqB,qBAAqB;QAACQ,QAAQ;IAAG;IAC9ET,uBAAuB;QAACG;QAASO,aAAaJ,OAAOE,OAAO,CAACE,WAAW;IAAA;IACxE,OAAOJ,OAAOE,OAAO;AACvB"}
@@ -1,2 +1,3 @@
1
- export declare const reportStepRoute: import("@shipfox/node-fastify").RouteDefinition;
1
+ import type { RunnersInterModuleClient } from '@shipfox/api-runners-dto/inter-module';
2
+ export declare function createReportStepRoute(runners: RunnersInterModuleClient): import("@shipfox/node-fastify").RouteDefinition;
2
3
  //# sourceMappingURL=report-step.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"report-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/report-step.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,iDAmD1B,CAAC"}
1
+ {"version":3,"file":"report-step.d.ts","sourceRoot":"","sources":["../../../src/presentation/routes/report-step.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,wBAAwB,EAAC,MAAM,uCAAuC,CAAC;AAQpF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,wBAAwB,mDAqDtE"}
@@ -1,73 +1,74 @@
1
1
  import { requireLeasedJobContext } from '@shipfox/api-auth-context';
2
- import { isJobLeaseActive } from '@shipfox/api-runners';
3
2
  import { reportStepBodySchema, reportStepResponseSchema } from '@shipfox/api-workflows-dto';
4
3
  import { ClientError, defineRoute } from '@shipfox/node-fastify';
5
4
  import { z } from 'zod';
6
5
  import { StepAttemptAheadError, StepNotFoundError, StepNotRunningError } from '#core/errors.js';
7
6
  import { recordStepResult } from '#core/job-execution.js';
8
7
  import { fromStepErrorDto } from '#presentation/dto/step.js';
9
- export const reportStepRoute = defineRoute({
10
- method: 'POST',
11
- path: '/steps/:stepId/report',
12
- description: 'Reports whether a step succeeded or failed. The job is identified by the access token. Reporting the same step more than once is safe: once a step has finished, later reports for it are ignored. The runner does not call a separate job-completion endpoint — finalization is driven server-side from the recorded step results, and the `cancel` flag tells the runner to stop once the job has finished without full success.',
13
- schema: {
14
- params: z.object({
15
- stepId: z.string().uuid()
16
- }),
17
- body: reportStepBodySchema,
18
- response: {
19
- 200: reportStepResponseSchema
20
- }
21
- },
22
- errorHandler: (error)=>{
23
- if (error instanceof StepNotFoundError) {
24
- throw new ClientError(error.message, 'step-not-found', {
25
- status: 404
26
- });
27
- }
28
- if (error instanceof StepNotRunningError) {
29
- throw new ClientError(error.message, 'step-not-running', {
30
- status: 409
8
+ export function createReportStepRoute(runners) {
9
+ return defineRoute({
10
+ method: 'POST',
11
+ path: '/steps/:stepId/report',
12
+ description: 'Reports whether a step succeeded or failed. The job is identified by the access token. Reporting the same step more than once is safe: once a step has finished, later reports for it are ignored. The runner does not call a separate job-completion endpoint — finalization is driven server-side from the recorded step results, and the `cancel` flag tells the runner to stop once the job has finished without full success.',
13
+ schema: {
14
+ params: z.object({
15
+ stepId: z.string().uuid()
16
+ }),
17
+ body: reportStepBodySchema,
18
+ response: {
19
+ 200: reportStepResponseSchema
20
+ }
21
+ },
22
+ errorHandler: (error)=>{
23
+ if (error instanceof StepNotFoundError) {
24
+ throw new ClientError(error.message, 'step-not-found', {
25
+ status: 404
26
+ });
27
+ }
28
+ if (error instanceof StepNotRunningError) {
29
+ throw new ClientError(error.message, 'step-not-running', {
30
+ status: 409
31
+ });
32
+ }
33
+ if (error instanceof StepAttemptAheadError) {
34
+ throw new ClientError(error.message, 'step-attempt-ahead', {
35
+ status: 409
36
+ });
37
+ }
38
+ throw error;
39
+ },
40
+ handler: async (request)=>{
41
+ const { stepId } = request.params;
42
+ const leasedJob = requireLeasedJobContext(request);
43
+ const { active: leaseIsActive } = await runners.getLeaseState({
44
+ jobId: leasedJob.jobId,
45
+ jobExecutionId: leasedJob.jobExecutionId,
46
+ runnerSessionId: leasedJob.runnerSessionId
31
47
  });
32
- }
33
- if (error instanceof StepAttemptAheadError) {
34
- throw new ClientError(error.message, 'step-attempt-ahead', {
35
- status: 409
36
- });
37
- }
38
- throw error;
39
- },
40
- handler: async (request)=>{
41
- const { stepId } = request.params;
42
- const leasedJob = requireLeasedJobContext(request);
43
- const leaseIsActive = await isJobLeaseActive({
44
- jobId: leasedJob.jobId,
45
- jobExecutionId: leasedJob.jobExecutionId,
46
- runnerSessionId: leasedJob.runnerSessionId
47
- });
48
- if (!leaseIsActive) {
49
- throw new ClientError('Job lease is no longer active', 'lease-not-active', {
50
- status: 404
48
+ if (!leaseIsActive) {
49
+ throw new ClientError('Job lease is no longer active', 'lease-not-active', {
50
+ status: 404
51
+ });
52
+ }
53
+ const outcome = await recordStepResult({
54
+ jobExecutionId: leasedJob.jobExecutionId,
55
+ stepId,
56
+ status: request.body.status,
57
+ error: fromStepErrorDto(request.body.error),
58
+ output: request.body.output ?? null,
59
+ response: request.body.response ?? null,
60
+ exitCode: request.body.exit_code ?? request.body.error?.exit_code ?? null,
61
+ logOutcome: request.body.log_outcome,
62
+ ...request.body.attempt !== undefined ? {
63
+ attempt: request.body.attempt
64
+ } : {}
51
65
  });
66
+ return {
67
+ ok: true,
68
+ cancel: outcome.jobFinished && outcome.status === 'failed'
69
+ };
52
70
  }
53
- const outcome = await recordStepResult({
54
- jobExecutionId: leasedJob.jobExecutionId,
55
- stepId,
56
- status: request.body.status,
57
- error: fromStepErrorDto(request.body.error),
58
- output: request.body.output ?? null,
59
- response: request.body.response ?? null,
60
- exitCode: request.body.exit_code ?? request.body.error?.exit_code ?? null,
61
- logOutcome: request.body.log_outcome,
62
- ...request.body.attempt !== undefined ? {
63
- attempt: request.body.attempt
64
- } : {}
65
- });
66
- return {
67
- ok: true,
68
- cancel: outcome.jobFinished && outcome.status === 'failed'
69
- };
70
- }
71
- });
71
+ });
72
+ }
72
73
 
73
74
  //# sourceMappingURL=report-step.js.map