@leitwerk-dev/server 0.3.1 → 0.4.1

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 (327) hide show
  1. package/dist/{app-BuJCdkvy.d.ts → app-CtlotzYm.d.ts} +312 -121
  2. package/dist/app-KR3N2JAE.js +8 -0
  3. package/dist/app.d.ts +9 -0
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/auth/fastify-auth.d.ts +9 -0
  6. package/dist/auth/fastify-auth.d.ts.map +1 -1
  7. package/dist/{chunk-QCHS3X33.js → chunk-OUA5EZS2.js} +3127 -689
  8. package/dist/chunk-OUA5EZS2.js.map +1 -0
  9. package/dist/{chunk-HK6BLLHA.js → chunk-YLWY4UTT.js} +2424 -1580
  10. package/dist/chunk-YLWY4UTT.js.map +1 -0
  11. package/dist/config/config-loader.d.ts +1 -1
  12. package/dist/config/config-loader.d.ts.map +1 -1
  13. package/dist/config/config-types.d.ts +16 -1
  14. package/dist/config/config-types.d.ts.map +1 -1
  15. package/dist/config/kubernetes-docker-isolation.d.ts +7 -0
  16. package/dist/config/kubernetes-docker-isolation.d.ts.map +1 -0
  17. package/dist/dashboard-model-issues.d.ts +10 -0
  18. package/dist/dashboard-model-issues.d.ts.map +1 -0
  19. package/dist/db/database.d.ts.map +1 -1
  20. package/dist/db/execution-inspection-repo.d.ts +15 -0
  21. package/dist/db/execution-inspection-repo.d.ts.map +1 -0
  22. package/dist/db/history-window.d.ts +11 -0
  23. package/dist/db/history-window.d.ts.map +1 -0
  24. package/dist/db/process-event-repo.d.ts +2 -0
  25. package/dist/db/process-event-repo.d.ts.map +1 -1
  26. package/dist/db/process-instance-repo.d.ts +21 -1
  27. package/dist/db/process-instance-repo.d.ts.map +1 -1
  28. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts +2 -1
  29. package/dist/db/process-leaf-outcome-snapshot-repo.d.ts.map +1 -1
  30. package/dist/db/process-project-repo.d.ts +2 -0
  31. package/dist/db/process-project-repo.d.ts.map +1 -1
  32. package/dist/db/process-skill-repo.d.ts.map +1 -1
  33. package/dist/db/process-turn-annotation-repo.d.ts +4 -1
  34. package/dist/db/process-turn-annotation-repo.d.ts.map +1 -1
  35. package/dist/db/process-turn-record-repo.d.ts +4 -0
  36. package/dist/db/process-turn-record-repo.d.ts.map +1 -1
  37. package/dist/db/publication-repo.d.ts +5 -0
  38. package/dist/db/publication-repo.d.ts.map +1 -0
  39. package/dist/db/repositories.d.ts +12 -0
  40. package/dist/db/repositories.d.ts.map +1 -1
  41. package/dist/db/schema.d.ts +693 -2
  42. package/dist/db/schema.d.ts.map +1 -1
  43. package/dist/db/scoped-settings-repo.d.ts +37 -0
  44. package/dist/db/scoped-settings-repo.d.ts.map +1 -0
  45. package/dist/db/skill-repo.d.ts +3 -0
  46. package/dist/db/skill-repo.d.ts.map +1 -1
  47. package/dist/db/turn-start-record-repo.d.ts +2 -1
  48. package/dist/db/turn-start-record-repo.d.ts.map +1 -1
  49. package/dist/db/turn-summary-repo.d.ts +10 -1
  50. package/dist/db/turn-summary-repo.d.ts.map +1 -1
  51. package/dist/db/worker-lease-repo.d.ts +2 -1
  52. package/dist/db/worker-lease-repo.d.ts.map +1 -1
  53. package/dist/domain-logic/outcome-tools.d.ts.map +1 -1
  54. package/dist/domain-logic/worker-lease-lifecycle.d.ts.map +1 -1
  55. package/dist/external-source-service.d.ts.map +1 -1
  56. package/dist/future-execution/execution.d.ts +4 -1
  57. package/dist/future-execution/execution.d.ts.map +1 -1
  58. package/dist/future-execution/launch-lifecycle.d.ts +9 -25
  59. package/dist/future-execution/launch-lifecycle.d.ts.map +1 -1
  60. package/dist/future-execution/lifecycle.d.ts +3 -28
  61. package/dist/future-execution/lifecycle.d.ts.map +1 -1
  62. package/dist/future-execution/model-projection.d.ts.map +1 -1
  63. package/dist/future-execution/reconciliation.d.ts +1 -0
  64. package/dist/future-execution/reconciliation.d.ts.map +1 -1
  65. package/dist/future-execution-presenter.d.ts.map +1 -1
  66. package/dist/index.js +2 -2
  67. package/dist/integration-tool-registry.d.ts +11 -2
  68. package/dist/integration-tool-registry.d.ts.map +1 -1
  69. package/dist/launch-coordinator.d.ts.map +1 -1
  70. package/dist/launcher-model-config-service.d.ts +7 -1
  71. package/dist/launcher-model-config-service.d.ts.map +1 -1
  72. package/dist/leaf-outcome-snapshot-capture.d.ts +1 -0
  73. package/dist/leaf-outcome-snapshot-capture.d.ts.map +1 -1
  74. package/dist/main.js +3 -3
  75. package/dist/primary-path-snapshot.d.ts.map +1 -1
  76. package/dist/process-action-presenter.d.ts +1 -6
  77. package/dist/process-action-presenter.d.ts.map +1 -1
  78. package/dist/process-action-registry.d.ts.map +1 -1
  79. package/dist/process-engine/decision.d.ts +2 -0
  80. package/dist/process-engine/decision.d.ts.map +1 -1
  81. package/dist/process-engine/engine.d.ts.map +1 -1
  82. package/dist/process-engine/mapped-turns.d.ts.map +1 -1
  83. package/dist/process-engine/ops/automatic-retry-startup.d.ts +8 -0
  84. package/dist/process-engine/ops/automatic-retry-startup.d.ts.map +1 -0
  85. package/dist/process-engine/ops/continue-failed-turn.d.ts.map +1 -1
  86. package/dist/process-engine/ops/process-observation.d.ts +6 -0
  87. package/dist/process-engine/ops/process-observation.d.ts.map +1 -0
  88. package/dist/process-engine/ops/retry-failed-turn.d.ts.map +1 -1
  89. package/dist/process-engine/ops/retry-startup.d.ts +2 -0
  90. package/dist/process-engine/ops/retry-startup.d.ts.map +1 -1
  91. package/dist/process-engine/ops/start-process.d.ts +2 -0
  92. package/dist/process-engine/ops/start-process.d.ts.map +1 -1
  93. package/dist/process-engine/ops/turn-outcome.d.ts.map +1 -1
  94. package/dist/process-engine/ops/turn-wait.d.ts +30 -0
  95. package/dist/process-engine/ops/turn-wait.d.ts.map +1 -0
  96. package/dist/process-engine/ops/update-model-config.d.ts +9 -0
  97. package/dist/process-engine/ops/update-model-config.d.ts.map +1 -0
  98. package/dist/process-engine/recorder.d.ts.map +1 -1
  99. package/dist/process-engine/turn-start-preflight.d.ts +6 -0
  100. package/dist/process-engine/turn-start-preflight.d.ts.map +1 -1
  101. package/dist/process-engine/turn-wait-state.d.ts +24 -0
  102. package/dist/process-engine/turn-wait-state.d.ts.map +1 -0
  103. package/dist/process-engine/turn-worker-requirement.d.ts +2 -0
  104. package/dist/process-engine/turn-worker-requirement.d.ts.map +1 -1
  105. package/dist/process-engine/types.d.ts +13 -2
  106. package/dist/process-engine/types.d.ts.map +1 -1
  107. package/dist/process-engine/writes/build-process-abort-writes.d.ts +3 -1
  108. package/dist/process-engine/writes/build-process-abort-writes.d.ts.map +1 -1
  109. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts +2 -0
  110. package/dist/process-engine/writes/build-turn-outcome-writes.d.ts.map +1 -1
  111. package/dist/process-engine/writes/commit-writes.d.ts +2 -0
  112. package/dist/process-engine/writes/commit-writes.d.ts.map +1 -1
  113. package/dist/process-engine/writes/writes.d.ts +28 -60
  114. package/dist/process-engine/writes/writes.d.ts.map +1 -1
  115. package/dist/process-graph.d.ts +1 -1
  116. package/dist/process-graph.d.ts.map +1 -1
  117. package/dist/process-inspection-reader.d.ts +21 -0
  118. package/dist/process-inspection-reader.d.ts.map +1 -0
  119. package/dist/process-inspection-trace.d.ts +13 -0
  120. package/dist/process-inspection-trace.d.ts.map +1 -0
  121. package/dist/process-inspection.d.ts +22 -0
  122. package/dist/process-inspection.d.ts.map +1 -0
  123. package/dist/process-instance-tree-presenter.d.ts +4 -3
  124. package/dist/process-instance-tree-presenter.d.ts.map +1 -1
  125. package/dist/process-launch-executor.d.ts +2 -0
  126. package/dist/process-launch-executor.d.ts.map +1 -1
  127. package/dist/process-launch-plan.d.ts +1 -0
  128. package/dist/process-launch-plan.d.ts.map +1 -1
  129. package/dist/process-launcher-registry.d.ts.map +1 -1
  130. package/dist/process-model-availability-recovery.d.ts +1 -1
  131. package/dist/process-model-availability-recovery.d.ts.map +1 -1
  132. package/dist/process-model-config.d.ts +19 -0
  133. package/dist/process-model-config.d.ts.map +1 -0
  134. package/dist/process-model-policy/construct.d.ts.map +1 -1
  135. package/dist/process-model-policy/evaluate.d.ts.map +1 -1
  136. package/dist/process-model-policy/index.d.ts +4 -1
  137. package/dist/process-model-policy/index.d.ts.map +1 -1
  138. package/dist/process-model-policy/project.d.ts.map +1 -1
  139. package/dist/process-model-policy/types.d.ts +18 -0
  140. package/dist/process-model-policy/types.d.ts.map +1 -1
  141. package/dist/process-model-policy-presenter.d.ts.map +1 -1
  142. package/dist/process-runtime-availability.d.ts +2 -1
  143. package/dist/process-runtime-availability.d.ts.map +1 -1
  144. package/dist/process-turn-trace.d.ts.map +1 -1
  145. package/dist/process-ui-snapshot-presenter.d.ts +14 -3
  146. package/dist/process-ui-snapshot-presenter.d.ts.map +1 -1
  147. package/dist/routes/dashboard.d.ts +17 -0
  148. package/dist/routes/dashboard.d.ts.map +1 -0
  149. package/dist/routes/future-executions.d.ts.map +1 -1
  150. package/dist/routes/launchers.d.ts.map +1 -1
  151. package/dist/routes/process-actions.d.ts.map +1 -1
  152. package/dist/routes/process-detail.d.ts.map +1 -1
  153. package/dist/routes/process-model-config.d.ts +4 -0
  154. package/dist/routes/process-model-config.d.ts.map +1 -0
  155. package/dist/routes/process-route-helpers.d.ts +8 -9
  156. package/dist/routes/process-route-helpers.d.ts.map +1 -1
  157. package/dist/routes/processes.d.ts.map +1 -1
  158. package/dist/routes/settings.d.ts +11 -0
  159. package/dist/routes/settings.d.ts.map +1 -0
  160. package/dist/routes/ticket-creation.d.ts.map +1 -1
  161. package/dist/scoped-settings-service.d.ts +98 -0
  162. package/dist/scoped-settings-service.d.ts.map +1 -0
  163. package/dist/server-bootstrap/build-host-capabilities.d.ts +2 -0
  164. package/dist/server-bootstrap/build-host-capabilities.d.ts.map +1 -1
  165. package/dist/server-bootstrap/register-http.d.ts.map +1 -1
  166. package/dist/session-summary-projection.d.ts.map +1 -1
  167. package/dist/skills/bundled-skills.d.ts +5 -0
  168. package/dist/skills/bundled-skills.d.ts.map +1 -0
  169. package/dist/skills/catalog-service.d.ts +1 -0
  170. package/dist/skills/catalog-service.d.ts.map +1 -1
  171. package/dist/skills/extension-importer.d.ts +11 -0
  172. package/dist/skills/extension-importer.d.ts.map +1 -0
  173. package/dist/skills/launch-skills.d.ts +11 -0
  174. package/dist/skills/launch-skills.d.ts.map +1 -0
  175. package/dist/skills/skill-frontmatter.d.ts +7 -0
  176. package/dist/skills/skill-frontmatter.d.ts.map +1 -1
  177. package/dist/skills/source-importer.d.ts +3 -0
  178. package/dist/skills/source-importer.d.ts.map +1 -1
  179. package/dist/startup-evidence.d.ts +4 -3
  180. package/dist/startup-evidence.d.ts.map +1 -1
  181. package/dist/startup-retry-policy.d.ts +8 -0
  182. package/dist/startup-retry-policy.d.ts.map +1 -0
  183. package/dist/supervisor/execution-inspection-ingestor.d.ts +9 -0
  184. package/dist/supervisor/execution-inspection-ingestor.d.ts.map +1 -0
  185. package/dist/supervisor/ipc-handler.d.ts +2 -0
  186. package/dist/supervisor/ipc-handler.d.ts.map +1 -1
  187. package/dist/supervisor/worker-event-ingestor.d.ts +1 -0
  188. package/dist/supervisor/worker-event-ingestor.d.ts.map +1 -1
  189. package/dist/supervisor/worker-start-payload-builder.d.ts.map +1 -1
  190. package/dist/supervisor/worker-supervisor.d.ts +2 -0
  191. package/dist/supervisor/worker-supervisor.d.ts.map +1 -1
  192. package/dist/test-helpers/prepared-fixture-start.d.ts.map +1 -1
  193. package/dist/test-helpers/process-model-fixtures.d.ts +1 -0
  194. package/dist/test-helpers/process-model-fixtures.d.ts.map +1 -1
  195. package/dist/test-helpers/scoped-settings-fixtures.d.ts +16 -0
  196. package/dist/test-helpers/scoped-settings-fixtures.d.ts.map +1 -0
  197. package/dist/test-helpers/skill-fixtures.d.ts +4 -0
  198. package/dist/test-helpers/skill-fixtures.d.ts.map +1 -0
  199. package/dist/testing.js +2 -1
  200. package/dist/testing.js.map +1 -1
  201. package/dist/tool-approval-gate.d.ts +3 -0
  202. package/dist/tool-approval-gate.d.ts.map +1 -1
  203. package/dist/turn-progress.d.ts.map +1 -1
  204. package/dist/turn-wait-service.d.ts +28 -0
  205. package/dist/turn-wait-service.d.ts.map +1 -0
  206. package/dist/worker-runtime-profile-selection.d.ts +2 -0
  207. package/dist/worker-runtime-profile-selection.d.ts.map +1 -1
  208. package/package.json +20 -19
  209. package/src/app.ts +177 -25
  210. package/src/auth/fastify-auth.ts +13 -0
  211. package/src/config/config-loader.ts +42 -2
  212. package/src/config/config-types.ts +16 -1
  213. package/src/config/kubernetes-docker-isolation.ts +21 -0
  214. package/src/dashboard-model-issues.ts +199 -0
  215. package/src/db/database.ts +131 -40
  216. package/src/db/execution-inspection-repo.ts +163 -0
  217. package/src/db/history-window.ts +18 -0
  218. package/src/db/process-event-repo.ts +88 -10
  219. package/src/db/process-instance-repo.ts +33 -2
  220. package/src/db/process-leaf-outcome-snapshot-repo.ts +8 -2
  221. package/src/db/process-project-repo.ts +4 -0
  222. package/src/db/process-skill-repo.ts +9 -2
  223. package/src/db/process-turn-annotation-repo.ts +27 -9
  224. package/src/db/process-turn-record-repo.ts +45 -12
  225. package/src/db/publication-repo.ts +63 -0
  226. package/src/db/repositories.ts +17 -0
  227. package/src/db/schema.ts +103 -1
  228. package/src/db/scoped-settings-repo.ts +234 -0
  229. package/src/db/skill-repo.ts +89 -27
  230. package/src/db/turn-start-record-repo.ts +13 -3
  231. package/src/db/turn-summary-repo.ts +36 -4
  232. package/src/db/worker-lease-repo.ts +8 -2
  233. package/src/domain-logic/outcome-tools.ts +18 -216
  234. package/src/domain-logic/worker-lease-lifecycle.ts +2 -1
  235. package/src/external-source-service.ts +33 -7
  236. package/src/future-execution/execution.ts +9 -2
  237. package/src/future-execution/launch-lifecycle.ts +87 -78
  238. package/src/future-execution/lifecycle.ts +5 -34
  239. package/src/future-execution/model-projection.ts +2 -0
  240. package/src/future-execution/reconciliation.ts +7 -0
  241. package/src/future-execution-presenter.ts +7 -8
  242. package/src/integration-tool-registry.ts +59 -26
  243. package/src/launch-coordinator.ts +10 -1
  244. package/src/launcher-model-config-service.ts +24 -3
  245. package/src/leaf-outcome-snapshot-capture.ts +2 -0
  246. package/src/primary-path-snapshot.ts +3 -4
  247. package/src/process-action-presenter.ts +22 -57
  248. package/src/process-action-registry.ts +31 -39
  249. package/src/process-engine/decision.ts +10 -0
  250. package/src/process-engine/engine.ts +25 -2
  251. package/src/process-engine/mapped-turns.ts +5 -7
  252. package/src/process-engine/ops/automatic-retry-startup.ts +93 -0
  253. package/src/process-engine/ops/continue-failed-turn.ts +2 -13
  254. package/src/process-engine/ops/process-observation.ts +119 -0
  255. package/src/process-engine/ops/retry-failed-turn.ts +2 -12
  256. package/src/process-engine/ops/retry-startup.ts +20 -16
  257. package/src/process-engine/ops/start-process.ts +34 -2
  258. package/src/process-engine/ops/turn-outcome.ts +61 -60
  259. package/src/process-engine/ops/turn-wait.ts +225 -0
  260. package/src/process-engine/ops/update-model-config.ts +66 -0
  261. package/src/process-engine/recorder.ts +34 -5
  262. package/src/process-engine/turn-start-preflight.ts +168 -105
  263. package/src/process-engine/turn-wait-state.ts +126 -0
  264. package/src/process-engine/turn-worker-requirement.ts +4 -0
  265. package/src/process-engine/types.ts +21 -0
  266. package/src/process-engine/writes/build-process-abort-writes.ts +30 -20
  267. package/src/process-engine/writes/build-turn-outcome-writes.ts +39 -2
  268. package/src/process-engine/writes/commit-writes.ts +16 -4
  269. package/src/process-engine/writes/writes.ts +59 -74
  270. package/src/process-graph.ts +0 -1
  271. package/src/process-inspection-reader.ts +305 -0
  272. package/src/process-inspection-trace.ts +176 -0
  273. package/src/process-inspection.ts +169 -0
  274. package/src/process-instance-tree-presenter.ts +56 -216
  275. package/src/process-launch-executor.ts +5 -2
  276. package/src/process-launch-plan.ts +17 -2
  277. package/src/process-launcher-registry.ts +28 -16
  278. package/src/process-model-availability-recovery.ts +6 -4
  279. package/src/process-model-config.ts +100 -0
  280. package/src/process-model-policy/construct.ts +1 -0
  281. package/src/process-model-policy/evaluate.ts +34 -32
  282. package/src/process-model-policy/index.ts +45 -3
  283. package/src/process-model-policy/project.ts +62 -76
  284. package/src/process-model-policy/types.ts +26 -0
  285. package/src/process-model-policy-presenter.ts +7 -3
  286. package/src/process-runtime-availability.ts +9 -4
  287. package/src/process-turn-trace.ts +12 -24
  288. package/src/process-ui-snapshot-presenter.ts +210 -295
  289. package/src/routes/dashboard.ts +106 -0
  290. package/src/routes/future-executions.ts +5 -5
  291. package/src/routes/launchers.ts +51 -1
  292. package/src/routes/process-actions.ts +10 -10
  293. package/src/routes/process-detail.ts +25 -2
  294. package/src/routes/process-model-config.ts +70 -0
  295. package/src/routes/process-route-helpers.ts +153 -162
  296. package/src/routes/processes.ts +2 -0
  297. package/src/routes/settings.ts +173 -0
  298. package/src/routes/ticket-creation.ts +28 -5
  299. package/src/scoped-settings-service.ts +797 -0
  300. package/src/server-bootstrap/build-host-capabilities.ts +42 -0
  301. package/src/server-bootstrap/register-http.ts +12 -1
  302. package/src/session-summary-projection.ts +1 -2
  303. package/src/skills/bundled-skills.ts +64 -0
  304. package/src/skills/catalog-service.ts +35 -6
  305. package/src/skills/extension-importer.ts +94 -0
  306. package/src/skills/launch-skills.ts +19 -0
  307. package/src/skills/skill-frontmatter.ts +19 -6
  308. package/src/skills/source-importer.ts +7 -13
  309. package/src/startup-evidence.ts +29 -8
  310. package/src/startup-retry-policy.ts +106 -0
  311. package/src/supervisor/execution-inspection-ingestor.ts +55 -0
  312. package/src/supervisor/ipc-handler.ts +2 -0
  313. package/src/supervisor/worker-event-ingestor.ts +30 -14
  314. package/src/supervisor/worker-start-payload-builder.ts +17 -0
  315. package/src/supervisor/worker-supervisor.ts +26 -1
  316. package/src/test-helpers/prepared-fixture-start.ts +1 -0
  317. package/src/test-helpers/process-model-fixtures.ts +2 -0
  318. package/src/test-helpers/scoped-settings-fixtures.ts +126 -0
  319. package/src/test-helpers/skill-fixtures.ts +28 -0
  320. package/src/tool-approval-gate.ts +16 -0
  321. package/src/turn-progress.ts +3 -2
  322. package/src/turn-wait-service.ts +228 -0
  323. package/src/worker-runtime-profile-selection.ts +8 -1
  324. package/dist/app-MSJXFK33.js +0 -8
  325. package/dist/chunk-HK6BLLHA.js.map +0 -1
  326. package/dist/chunk-QCHS3X33.js.map +0 -1
  327. /package/dist/{app-MSJXFK33.js.map → app-KR3N2JAE.js.map} +0 -0
@@ -0,0 +1,106 @@
1
+ import type { DashboardResponseBody } from "@leitwerk-dev/protocol/http-contracts";
2
+ import type { FastifyInstance } from "fastify";
3
+ import {
4
+ buildDashboardModelIssues,
5
+ type DashboardModelIssueDeps,
6
+ } from "../dashboard-model-issues.js";
7
+ import type { RouteDeps } from "./processes.js";
8
+
9
+ /** @internal */
10
+ export type DashboardRouteDeps = DashboardModelIssueDeps &
11
+ Pick<RouteDeps, "turnSummaries" | "skillCatalog">;
12
+
13
+ /** Aggregate each accepted LLM turn once, including active, failed and retry branches. @internal */
14
+ export function aggregateDashboardCosts(
15
+ rows: readonly {
16
+ /** @internal */ providerId: string | null;
17
+ /** @internal */ modelId: string | null;
18
+ /** @internal */ costUsd: number | null;
19
+ }[],
20
+ ): DashboardResponseBody["costs"] {
21
+ const groups = new Map<string, DashboardResponseBody["costs"]["byModel"][number]>();
22
+ let totalUsd = 0;
23
+ let pricedTurnCount = 0;
24
+ for (const row of rows) {
25
+ if (typeof row.costUsd !== "number" || !Number.isFinite(row.costUsd)) continue;
26
+ const providerId = row.providerId && row.modelId ? row.providerId : null;
27
+ const modelId = providerId ? row.modelId : null;
28
+ const key = JSON.stringify([providerId, modelId]);
29
+ const group = groups.get(key) ?? { providerId, modelId, costUsd: 0, turnCount: 0 };
30
+ group.turnCount += 1;
31
+ group.costUsd += row.costUsd;
32
+ totalUsd += row.costUsd;
33
+ pricedTurnCount += 1;
34
+ groups.set(key, group);
35
+ }
36
+ const missingCostTurnCount = rows.length - pricedTurnCount;
37
+ return {
38
+ totalUsd: rows.length > 0 && pricedTurnCount === 0 ? null : totalUsd,
39
+ totalLlmTurnCount: rows.length,
40
+ pricedTurnCount,
41
+ missingCostTurnCount,
42
+ isPartial: missingCostTurnCount > 0,
43
+ byModel: [...groups.values()].sort(
44
+ (a, b) =>
45
+ b.costUsd - a.costUsd ||
46
+ (a.providerId ?? "").localeCompare(b.providerId ?? "") ||
47
+ (a.modelId ?? "").localeCompare(b.modelId ?? ""),
48
+ ),
49
+ };
50
+ }
51
+
52
+ /** @internal */
53
+ export function buildDashboard(deps: DashboardRouteDeps): DashboardResponseBody {
54
+ const items = [...deps.processGraphs.values()]
55
+ .map((process) => ({ id: process.id, name: process.displayName }))
56
+ .sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
57
+ const watchers = (deps.processWatchers?.listAll() ?? [])
58
+ .map((watcher) => ({
59
+ id: `${watcher.processId}.${watcher.watcherId}`,
60
+ name: watcher.watcherLabel,
61
+ enabled: watcher.enabled,
62
+ }))
63
+ .sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
64
+ const skills = deps.skillCatalog?.list().installedSkills ?? [];
65
+ const bundled = skills.filter((skill) => skill.registrationKind === "bundled").length;
66
+ const lifecycle: Record<string, number> = Object.fromEntries(
67
+ deps.processes.countOverviewByLifecycle({}).map((row) => [row.lifecycleStatus, row.value]),
68
+ );
69
+ const processTotal = Object.values(lifecycle).reduce((sum, count) => sum + count, 0);
70
+ lifecycle.running = (lifecycle.active ?? 0) + (lifecycle.discovered ?? 0);
71
+ const statuses = ["running", "waiting", "error", "completed", "aborted"] as const;
72
+ return {
73
+ generatedAt: new Date().toISOString(),
74
+ definitions: { total: items.length, items },
75
+ watchers: {
76
+ total: watchers.length,
77
+ enabled: watchers.filter((watcher) => watcher.enabled).length,
78
+ items: watchers,
79
+ },
80
+ skills: { total: skills.length, installed: skills.length - bundled, bundled },
81
+ processes: {
82
+ total: processTotal,
83
+ byStatus: statuses.map((status) => ({ status, count: lifecycle[status] ?? 0 })),
84
+ byDefinition: deps.processes
85
+ .listOverviewProcessTypes({ status: "all" })
86
+ .map((row) => ({
87
+ processId: row.processId,
88
+ name: deps.processGraphs.get(row.processId)?.displayName ?? row.processId,
89
+ count: row.value,
90
+ }))
91
+ .sort(
92
+ (a, b) =>
93
+ b.count - a.count ||
94
+ a.name.localeCompare(b.name) ||
95
+ a.processId.localeCompare(b.processId),
96
+ ),
97
+ },
98
+ costs: aggregateDashboardCosts(deps.turnSummaries.listDashboardCosts()),
99
+ configuration: { issues: buildDashboardModelIssues(deps) },
100
+ };
101
+ }
102
+
103
+ /** @internal */
104
+ export function registerDashboardRoutes(app: FastifyInstance, deps: DashboardRouteDeps): void {
105
+ app.get("/api/dashboard", async () => buildDashboard(deps));
106
+ }
@@ -1,10 +1,10 @@
1
+ import { parseActionRequestBody } from "@leitwerk-dev/protocol";
1
2
  import type { CronPreviewResponseBody } from "@leitwerk-dev/protocol/http-contracts";
2
3
  import type { FastifyInstance } from "fastify";
3
4
  import { nextCronOccurrenceUtc } from "../domain-logic/cron.js";
4
5
  import type { FutureExecutionLifecycle } from "../future-execution/index.js";
5
6
  import { buildFutureExecutionListView } from "../future-execution-presenter.js";
6
7
  import {
7
- normalizeActionRequest,
8
8
  normalizeLauncherRequest,
9
9
  type RouteDeps,
10
10
  resolveActor,
@@ -89,13 +89,13 @@ export function registerFutureExecutionRoutes(
89
89
  app.put<{ Params: { futureExecutionId: string }; Body: unknown }>(
90
90
  "/api/future-executions/:futureExecutionId/action",
91
91
  async (req, reply) => {
92
- const normalized = normalizeActionRequest(req.body);
93
- if (!normalized.ok) {
94
- return sendActionRequestNormalizationError(reply, normalized.error);
92
+ const parsed = parseActionRequestBody(req.body);
93
+ if (!parsed.ok) {
94
+ return sendActionRequestNormalizationError(reply, parsed.error);
95
95
  }
96
96
  const result = await futureExecutionLifecycle.reviseScheduledAction(
97
97
  req.params.futureExecutionId,
98
- normalized.request,
98
+ parsed.value,
99
99
  { actor: resolveActor(req) },
100
100
  );
101
101
  return sendScheduledActionMutationResponse(reply, deps, result);
@@ -5,6 +5,7 @@ import type {
5
5
  LauncherOptionsResponseBody,
6
6
  LauncherRecentValuesResponseBody,
7
7
  LaunchersResponseBody,
8
+ LauncherValidationResponseBody,
8
9
  LaunchRunResponseBody,
9
10
  ProcessLaunchRunsResponseBody,
10
11
  StartLaunchRunResponseBody,
@@ -57,7 +58,7 @@ export function registerLauncherRoutes(
57
58
  : {};
58
59
  const warnings: Array<{ code: string; message: string; fieldId?: string }> = [];
59
60
  if (launcher) {
60
- const resolved = await deps.launcherService.resolveUiLauncher(
61
+ const resolved = await deps.launcherService.resolveUiLauncherPreview(
61
62
  req.params.launcherId,
62
63
  defaults,
63
64
  );
@@ -108,6 +109,54 @@ export function registerLauncherRoutes(
108
109
  },
109
110
  );
110
111
 
112
+ app.post<{
113
+ Params: { launcherId: string };
114
+ Querystring: { futureExecutionId?: string };
115
+ Body: unknown;
116
+ }>(
117
+ "/api/launchers/:launcherId/validate",
118
+ {
119
+ schema: {
120
+ querystring: {
121
+ type: "object",
122
+ properties: { futureExecutionId: { type: "string", minLength: 1, pattern: "\\S" } },
123
+ },
124
+ },
125
+ },
126
+ async (req, reply) => {
127
+ const normalized = normalizeLauncherRequest(req.body);
128
+ if (!normalized.ok) {
129
+ return sendLauncherRequestNormalizationError(reply, normalized.error);
130
+ }
131
+ try {
132
+ const resolved = await deps.launcherService.resolveUiLauncherPreview(
133
+ req.params.launcherId,
134
+ normalized.request.launcherInput,
135
+ );
136
+ if (!resolved.ok)
137
+ return { errors: resolved.errors } satisfies LauncherValidationResponseBody;
138
+ // Apply shared skills, models and schedule rules to the preview only.
139
+ // Submission always resolves the complete executable configuration again.
140
+ const result = await futureExecutionLifecycle.prepareLaunch(
141
+ req.params.launcherId,
142
+ normalized.request,
143
+ {
144
+ resolvedLauncher: resolved.launcher,
145
+ futureExecutionId: req.query.futureExecutionId,
146
+ },
147
+ );
148
+ if (result.ok) return { errors: [] } satisfies LauncherValidationResponseBody;
149
+ if (result.outcome.kind === "invalid") {
150
+ return { errors: result.outcome.issues } satisfies LauncherValidationResponseBody;
151
+ }
152
+ return sendLauncherMutationResponse(reply, deps, result.outcome);
153
+ } catch (error) {
154
+ if (sendLauncherLookupFailure(reply, error)) return;
155
+ throw error;
156
+ }
157
+ },
158
+ );
159
+
111
160
  app.post<{ Params: { launcherId: string }; Body: unknown }>(
112
161
  "/api/launchers/:launcherId/model-config-preview",
113
162
  async (req, reply) => {
@@ -120,6 +169,7 @@ export function registerLauncherRoutes(
120
169
  try {
121
170
  previewResult = await buildLauncherModelConfigPreviewForLauncher({
122
171
  launcherService: deps.launcherService,
172
+ scopedSettingsService: deps.scopedSettingsService,
123
173
  launchPlans: deps.launchPlans,
124
174
  launcherId: req.params.launcherId,
125
175
  launcherInput: normalized.request.launcherInput,
@@ -1,3 +1,4 @@
1
+ import { parseActionRequestBody } from "@leitwerk-dev/protocol";
1
2
  import type {
2
3
  ModelProviderOptionsResponseBody,
3
4
  ProcessActionModelPreviewResponseBody,
@@ -9,7 +10,6 @@ import { listVisibleActionsForProcess } from "../process-action-presenter.js";
9
10
  import { sendEngineFailure } from "./process-engine-http.js";
10
11
  import {
11
12
  getProcessOrReply,
12
- normalizeActionRequest,
13
13
  normalizeContinueRequest,
14
14
  normalizeRecoveryModelRequest,
15
15
  type RouteDeps,
@@ -174,7 +174,7 @@ export function registerProcessActionRoutes(
174
174
  const result = await deps.processEngine.retryStartup(
175
175
  req.params.instanceId,
176
176
  req.params.startRecordId,
177
- Object.keys(options).length > 0 ? options : undefined,
177
+ { ...options, actor: resolveActor(req) },
178
178
  );
179
179
  deps.launchCoordinator.refresh(req.params.instanceId);
180
180
  if (!result.ok) {
@@ -219,14 +219,14 @@ export function registerProcessActionRoutes(
219
219
  if (!process) {
220
220
  return null;
221
221
  }
222
- const normalized = normalizeActionRequest(req.body);
223
- if (!normalized.ok) {
224
- sendActionRequestNormalizationError(reply, normalized.error);
222
+ const parsed = parseActionRequestBody(req.body);
223
+ if (!parsed.ok) {
224
+ sendActionRequestNormalizationError(reply, parsed.error);
225
225
  return null;
226
226
  }
227
227
  return {
228
228
  process,
229
- request: normalized.request,
229
+ request: parsed.value,
230
230
  processActionRegistry: deps.processActionRegistry,
231
231
  };
232
232
  }
@@ -234,14 +234,14 @@ export function registerProcessActionRoutes(
234
234
  app.post<{ Params: { instanceId: string; actionId: string }; Body: unknown }>(
235
235
  "/api/processes/:instanceId/actions/:actionId/model-preview",
236
236
  async (req, reply) => {
237
- const normalized = normalizeActionRequest(req.body);
238
- if (!normalized.ok) {
239
- return sendActionRequestNormalizationError(reply, normalized.error);
237
+ const parsed = parseActionRequestBody(req.body);
238
+ if (!parsed.ok) {
239
+ return sendActionRequestNormalizationError(reply, parsed.error);
240
240
  }
241
241
  const result = await deps.processModelSelection.preview(
242
242
  req.params.instanceId,
243
243
  req.params.actionId,
244
- normalized.request.input,
244
+ parsed.value.input,
245
245
  );
246
246
  if (result.kind === "operational_failure") {
247
247
  if (result.code === "process_not_found") {
@@ -4,6 +4,7 @@ import type {
4
4
  } from "@leitwerk-dev/protocol/http-contracts";
5
5
  import type { FastifyInstance, FastifyReply } from "fastify";
6
6
  import { buildFutureExecutionSummaries } from "../future-execution-presenter.js";
7
+ import { ProcessInspectionReader } from "../process-inspection-reader.js";
7
8
  import { getProcessDisplayName } from "../process-operator-attention.js";
8
9
  import {
9
10
  buildProcessBrowse,
@@ -20,6 +21,25 @@ export function registerProcessDetailRoutes(app: FastifyInstance, deps: RouteDep
20
21
  const diagnosticsAssembler = new ProcessDiagnosticsAssembler(deps);
21
22
  const primaryPathAssembler = new ProcessPrimaryPathAssembler(deps);
22
23
  const uiSnapshotAssembler = new ProcessUiSnapshotAssembler(deps);
24
+ const inspection = new ProcessInspectionReader(deps);
25
+ app.get<{
26
+ Params: { instanceId: string; turnRecordId: string };
27
+ Querystring: { section?: string; entryId?: string; itemId?: string; boundaryFor?: string };
28
+ }>("/api/processes/:instanceId/turn-records/:turnRecordId/inspection", async (req, reply) => {
29
+ const { instanceId, turnRecordId } = req.params;
30
+ const section = req.query.section ?? "summary";
31
+ if (!["summary", "trace", "context", "configuration"].includes(section))
32
+ return reply.code(400).send({ error: "Unknown inspection section" });
33
+ const body =
34
+ section === "trace"
35
+ ? await inspection.trace(instanceId, turnRecordId, req.query)
36
+ : section === "context"
37
+ ? await inspection.context(instanceId, turnRecordId)
38
+ : section === "configuration"
39
+ ? inspection.configuration(instanceId, turnRecordId)
40
+ : inspection.summary(instanceId, turnRecordId);
41
+ return body ?? reply.code(404).send({ error: "Execution not found in this process" });
42
+ });
23
43
 
24
44
  app.get("/api/processes", async () => {
25
45
  const instances = deps.processes.listAll();
@@ -99,11 +119,14 @@ export function registerProcessDetailRoutes(app: FastifyInstance, deps: RouteDep
99
119
  );
100
120
  }
101
121
 
102
- app.get<{ Params: { instanceId: string } }>(
122
+ app.get<{ Params: { instanceId: string }; Querystring: { beforeTurnRecordId?: string } }>(
103
123
  "/api/processes/:instanceId/ui-snapshot",
104
124
  async (req, reply) => {
105
125
  const startedAt = performance.now();
106
- const snapshot = await uiSnapshotAssembler.assemble(req.params.instanceId);
126
+ const snapshot = await uiSnapshotAssembler.assemble(
127
+ req.params.instanceId,
128
+ req.query.beforeTurnRecordId,
129
+ );
107
130
  reply.header(
108
131
  "Server-Timing",
109
132
  `ui-snapshot;dur=${(performance.now() - startedAt).toFixed(1)}`,
@@ -0,0 +1,70 @@
1
+ import type { ProcessModelConfigResponseBody } from "@leitwerk-dev/protocol/http-contracts";
2
+ import type { FastifyInstance } from "fastify";
3
+ import { reconcileFutureExecutionModelBlocks } from "../future-execution/reconciliation.js";
4
+ import { UpdateModelConfig } from "../process-engine/ops/update-model-config.js";
5
+ import {
6
+ parseProcessModelConfigPatch,
7
+ prepareProcessModelConfig,
8
+ } from "../process-model-config.js";
9
+ import { getProcessOrReply, type RouteDeps, resolveActor } from "./process-route-helpers.js";
10
+
11
+ export function registerProcessModelConfigRoutes(app: FastifyInstance, deps: RouteDeps) {
12
+ for (const preview of [true, false]) {
13
+ app.route<{ Params: { instanceId: string } }>({
14
+ method: preview ? "POST" : "PATCH",
15
+ url: `/api/processes/:instanceId/model-config${preview ? "/preview" : ""}`,
16
+ async handler(req, reply): Promise<ProcessModelConfigResponseBody | undefined> {
17
+ const process = getProcessOrReply(deps, req.params.instanceId, reply);
18
+ if (!process) return;
19
+ const policy = deps.processModelPolicy;
20
+ const cache = deps.modelStatusCache;
21
+ if (!policy || !cache || !deps.processActionRegistry)
22
+ return reply.code(503).send({ error: "Model policy is unavailable" });
23
+ let patch: ReturnType<typeof parseProcessModelConfigPatch>;
24
+ try {
25
+ patch = parseProcessModelConfigPatch(req.body);
26
+ if (preview) {
27
+ const prepared = prepareProcessModelConfig({
28
+ process,
29
+ patch,
30
+ policy,
31
+ availability: cache.snapshot(),
32
+ });
33
+ return { modelConfiguration: prepared.modelConfiguration };
34
+ }
35
+ } catch (error) {
36
+ return reply.code(400).send({
37
+ error: error instanceof Error ? error.message : "Invalid model configuration",
38
+ });
39
+ }
40
+ const result = await deps.processEngine.run(UpdateModelConfig, {
41
+ instanceId: process.id,
42
+ patch,
43
+ actor: resolveActor(req),
44
+ });
45
+ if (!result.ok)
46
+ return reply
47
+ .code(
48
+ result.code === "process_not_found"
49
+ ? 404
50
+ : result.stage === "post_commit"
51
+ ? 500
52
+ : 400,
53
+ )
54
+ .send({ error: result.message });
55
+ // The engine has released its process lock. Future execution coordination must come after it.
56
+ await reconcileFutureExecutionModelBlocks({
57
+ ...deps,
58
+ processGraphs: deps.processGraphs,
59
+ processActionRegistry: deps.processActionRegistry,
60
+ policy,
61
+ availability: cache.snapshot(),
62
+ getModelAvailabilitySnapshot: () => cache.snapshot(),
63
+ instanceId: process.id,
64
+ asOf: new Date().toISOString(),
65
+ });
66
+ return result.data;
67
+ },
68
+ });
69
+ }
70
+ }