@xyne/workflow-sdk 3.2.44 → 3.2.46

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 (268) hide show
  1. package/dist/agents/agent-step.d.ts +5 -5
  2. package/dist/agents/contract.d.ts +5 -5
  3. package/dist/agents/host-agent-step.d.ts +7 -7
  4. package/dist/agents/pi-session-runtime.d.ts +4 -4
  5. package/dist/authz/types.d.ts +8 -2
  6. package/dist/authz/types.d.ts.map +1 -1
  7. package/dist/authz/types.js +8 -1
  8. package/dist/authz/types.js.map +1 -1
  9. package/dist/client/events-client.d.ts +5 -1
  10. package/dist/client/events-client.d.ts.map +1 -1
  11. package/dist/client/events-client.js +6 -2
  12. package/dist/client/events-client.js.map +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.d.ts.map +1 -1
  15. package/dist/client/types.d.ts +87 -19
  16. package/dist/client/types.d.ts.map +1 -1
  17. package/dist/client/workflow-client.d.ts.map +1 -1
  18. package/dist/client/workflow-client.js +102 -32
  19. package/dist/client/workflow-client.js.map +1 -1
  20. package/dist/common/credentials.d.ts +48 -0
  21. package/dist/common/credentials.d.ts.map +1 -1
  22. package/dist/common/credentials.js +34 -0
  23. package/dist/common/credentials.js.map +1 -1
  24. package/dist/connectors/builtin/builtin-connector.d.ts +1 -1
  25. package/dist/connectors/builtin/builtin-connector.d.ts.map +1 -1
  26. package/dist/connectors/builtin/builtin-connector.js +6 -4
  27. package/dist/connectors/builtin/builtin-connector.js.map +1 -1
  28. package/dist/connectors/builtin/credentials.d.ts +8 -0
  29. package/dist/connectors/builtin/credentials.d.ts.map +1 -1
  30. package/dist/connectors/builtin/credentials.js +14 -0
  31. package/dist/connectors/builtin/credentials.js.map +1 -1
  32. package/dist/connectors/builtin/steps/classifier-agent.step.d.ts +176 -0
  33. package/dist/connectors/builtin/steps/classifier-agent.step.d.ts.map +1 -0
  34. package/dist/connectors/builtin/steps/classifier-agent.step.js +248 -0
  35. package/dist/connectors/builtin/steps/classifier-agent.step.js.map +1 -0
  36. package/dist/connectors/builtin/steps/cycle.step.d.ts +4 -4
  37. package/dist/connectors/builtin/steps/http-request.step.d.ts +4 -4
  38. package/dist/connectors/builtin/steps/parallel.step.d.ts +4 -4
  39. package/dist/conversational-flow/create.d.ts +15 -2
  40. package/dist/conversational-flow/create.d.ts.map +1 -1
  41. package/dist/conversational-flow/create.js +29 -10
  42. package/dist/conversational-flow/create.js.map +1 -1
  43. package/dist/conversational-flow/edit.d.ts +21 -20
  44. package/dist/conversational-flow/edit.d.ts.map +1 -1
  45. package/dist/conversational-flow/edit.js +204 -286
  46. package/dist/conversational-flow/edit.js.map +1 -1
  47. package/dist/conversational-flow/index.d.ts +8 -3
  48. package/dist/conversational-flow/index.d.ts.map +1 -1
  49. package/dist/conversational-flow/index.js +7 -2
  50. package/dist/conversational-flow/index.js.map +1 -1
  51. package/dist/conversational-flow/internals.d.ts +51 -0
  52. package/dist/conversational-flow/internals.d.ts.map +1 -0
  53. package/dist/conversational-flow/internals.js +163 -0
  54. package/dist/conversational-flow/internals.js.map +1 -0
  55. package/dist/conversational-flow/lookup-edit.d.ts +96 -0
  56. package/dist/conversational-flow/lookup-edit.d.ts.map +1 -0
  57. package/dist/conversational-flow/lookup-edit.js +266 -0
  58. package/dist/conversational-flow/lookup-edit.js.map +1 -0
  59. package/dist/conversational-flow/lookups.d.ts +46 -0
  60. package/dist/conversational-flow/lookups.d.ts.map +1 -0
  61. package/dist/conversational-flow/lookups.js +145 -0
  62. package/dist/conversational-flow/lookups.js.map +1 -0
  63. package/dist/conversational-flow/read.d.ts.map +1 -1
  64. package/dist/conversational-flow/read.js +48 -7
  65. package/dist/conversational-flow/read.js.map +1 -1
  66. package/dist/conversational-flow/router-edit.d.ts +53 -0
  67. package/dist/conversational-flow/router-edit.d.ts.map +1 -0
  68. package/dist/conversational-flow/router-edit.js +191 -0
  69. package/dist/conversational-flow/router-edit.js.map +1 -0
  70. package/dist/conversational-flow/routers.d.ts +92 -0
  71. package/dist/conversational-flow/routers.d.ts.map +1 -0
  72. package/dist/conversational-flow/routers.js +286 -0
  73. package/dist/conversational-flow/routers.js.map +1 -0
  74. package/dist/conversational-flow/settle.d.ts +26 -0
  75. package/dist/conversational-flow/settle.d.ts.map +1 -0
  76. package/dist/conversational-flow/settle.js +59 -0
  77. package/dist/conversational-flow/settle.js.map +1 -0
  78. package/dist/conversational-flow/tree.d.ts +15 -1
  79. package/dist/conversational-flow/tree.d.ts.map +1 -1
  80. package/dist/conversational-flow/tree.js +28 -0
  81. package/dist/conversational-flow/tree.js.map +1 -1
  82. package/dist/conversational-flow/turn.d.ts +2 -0
  83. package/dist/conversational-flow/turn.d.ts.map +1 -1
  84. package/dist/conversational-flow/turn.js +26 -7
  85. package/dist/conversational-flow/turn.js.map +1 -1
  86. package/dist/conversational-flow/types.d.ts +50 -3
  87. package/dist/conversational-flow/types.d.ts.map +1 -1
  88. package/dist/conversational-flow/types.js +35 -0
  89. package/dist/conversational-flow/types.js.map +1 -1
  90. package/dist/engine/config-validator.d.ts +15 -0
  91. package/dist/engine/config-validator.d.ts.map +1 -1
  92. package/dist/engine/config-validator.js +52 -0
  93. package/dist/engine/config-validator.js.map +1 -1
  94. package/dist/events/types.d.ts +37 -4
  95. package/dist/events/types.d.ts.map +1 -1
  96. package/dist/events/types.js +11 -1
  97. package/dist/events/types.js.map +1 -1
  98. package/dist/index.d.ts +10 -5
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +6 -0
  101. package/dist/index.js.map +1 -1
  102. package/dist/persistence/in-memory-adapter.d.ts +34 -18
  103. package/dist/persistence/in-memory-adapter.d.ts.map +1 -1
  104. package/dist/persistence/in-memory-adapter.js +294 -37
  105. package/dist/persistence/in-memory-adapter.js.map +1 -1
  106. package/dist/persistence/types.d.ts +181 -20
  107. package/dist/persistence/types.d.ts.map +1 -1
  108. package/dist/router/workflow-router.d.ts.map +1 -1
  109. package/dist/router/workflow-router.js +154 -58
  110. package/dist/router/workflow-router.js.map +1 -1
  111. package/dist/runtime/paging.d.ts +29 -0
  112. package/dist/runtime/paging.d.ts.map +1 -0
  113. package/dist/runtime/paging.js +34 -0
  114. package/dist/runtime/paging.js.map +1 -0
  115. package/dist/runtime/types.d.ts +59 -9
  116. package/dist/runtime/types.d.ts.map +1 -1
  117. package/dist/runtime/workflow-runtime.d.ts +95 -25
  118. package/dist/runtime/workflow-runtime.d.ts.map +1 -1
  119. package/dist/runtime/workflow-runtime.js +350 -147
  120. package/dist/runtime/workflow-runtime.js.map +1 -1
  121. package/dist/schema/config-check.d.ts +63 -0
  122. package/dist/schema/config-check.d.ts.map +1 -0
  123. package/dist/schema/config-check.js +18 -0
  124. package/dist/schema/config-check.js.map +1 -0
  125. package/dist/schema/options.d.ts +6 -6
  126. package/dist/schema/options.d.ts.map +1 -1
  127. package/dist/steps/base-step.d.ts +15 -0
  128. package/dist/steps/base-step.d.ts.map +1 -1
  129. package/dist/steps/base-step.js.map +1 -1
  130. package/dist/testing/authz-conformance.d.ts.map +1 -1
  131. package/dist/testing/authz-conformance.js +10 -5
  132. package/dist/testing/authz-conformance.js.map +1 -1
  133. package/dist/triggers/base-trigger.d.ts +15 -0
  134. package/dist/triggers/base-trigger.d.ts.map +1 -1
  135. package/dist/triggers/base-trigger.js.map +1 -1
  136. package/dist/types/approval.d.ts +46 -0
  137. package/dist/types/approval.d.ts.map +1 -0
  138. package/dist/types/approval.js +11 -0
  139. package/dist/types/approval.js.map +1 -0
  140. package/dist/types/component-ref.d.ts +18 -0
  141. package/dist/types/component-ref.d.ts.map +1 -0
  142. package/dist/types/component-ref.js +2 -0
  143. package/dist/types/component-ref.js.map +1 -0
  144. package/dist/types/index.d.ts +2 -0
  145. package/dist/types/index.d.ts.map +1 -1
  146. package/dist/types/index.js +1 -0
  147. package/dist/types/index.js.map +1 -1
  148. package/dist/types/known-types.d.ts +1 -0
  149. package/dist/types/known-types.d.ts.map +1 -1
  150. package/dist/types/known-types.js +1 -0
  151. package/dist/types/known-types.js.map +1 -1
  152. package/dist/types/literal.d.ts +19 -0
  153. package/dist/types/literal.d.ts.map +1 -0
  154. package/dist/types/literal.js +2 -0
  155. package/dist/types/literal.js.map +1 -0
  156. package/dist/types/validation.d.ts +16 -1
  157. package/dist/types/validation.d.ts.map +1 -1
  158. package/dist/types/validation.js +15 -0
  159. package/dist/types/validation.js.map +1 -1
  160. package/dist/util/approval-gate.d.ts +26 -0
  161. package/dist/util/approval-gate.d.ts.map +1 -0
  162. package/dist/util/approval-gate.js +35 -0
  163. package/dist/util/approval-gate.js.map +1 -0
  164. package/dist/util/literal-values.d.ts +22 -0
  165. package/dist/util/literal-values.d.ts.map +1 -0
  166. package/dist/util/literal-values.js +55 -0
  167. package/dist/util/literal-values.js.map +1 -0
  168. package/package.json +1 -1
  169. package/dist/common/expression-eval.d.ts +0 -35
  170. package/dist/common/expression-eval.d.ts.map +0 -1
  171. package/dist/common/expression-eval.js +0 -214
  172. package/dist/common/expression-eval.js.map +0 -1
  173. package/dist/common/principal.d.ts +0 -45
  174. package/dist/common/principal.d.ts.map +0 -1
  175. package/dist/common/principal.js +0 -9
  176. package/dist/common/principal.js.map +0 -1
  177. package/dist/connectors/builtin/steps/repeat.step.d.ts +0 -126
  178. package/dist/connectors/builtin/steps/repeat.step.d.ts.map +0 -1
  179. package/dist/connectors/builtin/steps/repeat.step.js +0 -144
  180. package/dist/connectors/builtin/steps/repeat.step.js.map +0 -1
  181. package/dist/runtime/execution-event-bus.d.ts +0 -38
  182. package/dist/runtime/execution-event-bus.d.ts.map +0 -1
  183. package/dist/runtime/execution-event-bus.js +0 -87
  184. package/dist/runtime/execution-event-bus.js.map +0 -1
  185. package/dist/steps/builtin/code.step.d.ts +0 -99
  186. package/dist/steps/builtin/code.step.d.ts.map +0 -1
  187. package/dist/steps/builtin/code.step.js +0 -152
  188. package/dist/steps/builtin/code.step.js.map +0 -1
  189. package/dist/steps/builtin/conditional.step.d.ts +0 -182
  190. package/dist/steps/builtin/conditional.step.d.ts.map +0 -1
  191. package/dist/steps/builtin/conditional.step.js +0 -82
  192. package/dist/steps/builtin/conditional.step.js.map +0 -1
  193. package/dist/steps/builtin/dedup.step.d.ts +0 -65
  194. package/dist/steps/builtin/dedup.step.d.ts.map +0 -1
  195. package/dist/steps/builtin/dedup.step.js +0 -61
  196. package/dist/steps/builtin/dedup.step.js.map +0 -1
  197. package/dist/steps/builtin/http-request.step.d.ts +0 -1020
  198. package/dist/steps/builtin/http-request.step.d.ts.map +0 -1
  199. package/dist/steps/builtin/http-request.step.js +0 -491
  200. package/dist/steps/builtin/http-request.step.js.map +0 -1
  201. package/dist/steps/builtin/loop.step.d.ts +0 -100
  202. package/dist/steps/builtin/loop.step.d.ts.map +0 -1
  203. package/dist/steps/builtin/loop.step.js +0 -73
  204. package/dist/steps/builtin/loop.step.js.map +0 -1
  205. package/dist/steps/builtin/map.step.d.ts +0 -148
  206. package/dist/steps/builtin/map.step.d.ts.map +0 -1
  207. package/dist/steps/builtin/map.step.js +0 -111
  208. package/dist/steps/builtin/map.step.js.map +0 -1
  209. package/dist/steps/builtin/parallel.step.d.ts +0 -246
  210. package/dist/steps/builtin/parallel.step.d.ts.map +0 -1
  211. package/dist/steps/builtin/parallel.step.js +0 -175
  212. package/dist/steps/builtin/parallel.step.js.map +0 -1
  213. package/dist/steps/builtin/ssrf-guard.d.ts +0 -9
  214. package/dist/steps/builtin/ssrf-guard.d.ts.map +0 -1
  215. package/dist/steps/builtin/ssrf-guard.js +0 -115
  216. package/dist/steps/builtin/ssrf-guard.js.map +0 -1
  217. package/dist/steps/builtin/switch.step.d.ts +0 -235
  218. package/dist/steps/builtin/switch.step.d.ts.map +0 -1
  219. package/dist/steps/builtin/switch.step.js +0 -101
  220. package/dist/steps/builtin/switch.step.js.map +0 -1
  221. package/dist/steps/builtin/transform.step.d.ts +0 -247
  222. package/dist/steps/builtin/transform.step.d.ts.map +0 -1
  223. package/dist/steps/builtin/transform.step.js +0 -135
  224. package/dist/steps/builtin/transform.step.js.map +0 -1
  225. package/dist/steps/builtin/wait.step.d.ts +0 -1072
  226. package/dist/steps/builtin/wait.step.d.ts.map +0 -1
  227. package/dist/steps/builtin/wait.step.js +0 -254
  228. package/dist/steps/builtin/wait.step.js.map +0 -1
  229. package/dist/steps/step-registry.d.ts +0 -62
  230. package/dist/steps/step-registry.d.ts.map +0 -1
  231. package/dist/steps/step-registry.js +0 -103
  232. package/dist/steps/step-registry.js.map +0 -1
  233. package/dist/triggers/builtin/default-cron-trigger.d.ts +0 -44
  234. package/dist/triggers/builtin/default-cron-trigger.d.ts.map +0 -1
  235. package/dist/triggers/builtin/default-cron-trigger.js +0 -31
  236. package/dist/triggers/builtin/default-cron-trigger.js.map +0 -1
  237. package/dist/triggers/builtin/default-event-trigger.d.ts +0 -32
  238. package/dist/triggers/builtin/default-event-trigger.d.ts.map +0 -1
  239. package/dist/triggers/builtin/default-event-trigger.js +0 -21
  240. package/dist/triggers/builtin/default-event-trigger.js.map +0 -1
  241. package/dist/triggers/builtin/default-manual-trigger.d.ts +0 -45
  242. package/dist/triggers/builtin/default-manual-trigger.d.ts.map +0 -1
  243. package/dist/triggers/builtin/default-manual-trigger.js +0 -51
  244. package/dist/triggers/builtin/default-manual-trigger.js.map +0 -1
  245. package/dist/triggers/builtin/default-webhook-trigger.d.ts +0 -72
  246. package/dist/triggers/builtin/default-webhook-trigger.d.ts.map +0 -1
  247. package/dist/triggers/builtin/default-webhook-trigger.js +0 -91
  248. package/dist/triggers/builtin/default-webhook-trigger.js.map +0 -1
  249. package/dist/triggers/builtin/default-webhook-v2-trigger.d.ts +0 -29
  250. package/dist/triggers/builtin/default-webhook-v2-trigger.d.ts.map +0 -1
  251. package/dist/triggers/builtin/default-webhook-v2-trigger.js +0 -38
  252. package/dist/triggers/builtin/default-webhook-v2-trigger.js.map +0 -1
  253. package/dist/triggers/trigger-registry.d.ts +0 -48
  254. package/dist/triggers/trigger-registry.d.ts.map +0 -1
  255. package/dist/triggers/trigger-registry.js +0 -83
  256. package/dist/triggers/trigger-registry.js.map +0 -1
  257. package/dist/types/attachment.d.ts +0 -23
  258. package/dist/types/attachment.d.ts.map +0 -1
  259. package/dist/types/attachment.js +0 -2
  260. package/dist/types/attachment.js.map +0 -1
  261. package/dist/types/resume-payload.d.ts +0 -34
  262. package/dist/types/resume-payload.d.ts.map +0 -1
  263. package/dist/types/resume-payload.js +0 -12
  264. package/dist/types/resume-payload.js.map +0 -1
  265. package/dist/util/executable-check.d.ts +0 -42
  266. package/dist/util/executable-check.d.ts.map +0 -1
  267. package/dist/util/executable-check.js +0 -115
  268. package/dist/util/executable-check.js.map +0 -1
@@ -11,9 +11,14 @@
11
11
  * - Resume paused executions
12
12
  * - Process queued jobs (the worker loop body)
13
13
  */
14
- import { executionTopic, workflowTopic } from '../events/types.js';
14
+ import { executionTopic, workflowTopic, folderTopic } from '../events/types.js';
15
15
  import { projectVariables } from '../types/workflow-variable.js';
16
+ import { ValidationIssueCode } from '../types/validation.js';
17
+ import { WorkflowStatus } from '../types/status.js';
18
+ import { approvalGate } from '../util/approval-gate.js';
16
19
  import { ConfigValidator } from '../engine/config-validator.js';
20
+ import { literalValues } from '../util/literal-values.js';
21
+ import { resolvePage } from './paging.js';
17
22
  import { validateTriggerPayload } from '../common/validate-payload.js';
18
23
  import { AccessDeniedError, ResourceNotFoundError } from '../authz/default.js';
19
24
  import { EventTrigger } from '../triggers/event-trigger.js';
@@ -26,7 +31,6 @@ import { matchesTriggerFilter } from '../ingest/filter.js';
26
31
  import { isDelayedStart, readAnchor, resolveStartAt, startNeedsPayload, startSkipReason, } from '../ingest/start-policy.js';
27
32
  import { CronTrigger } from '../triggers/cron-trigger.js';
28
33
  import { PauseStep } from '../engine/pause-step.js';
29
- import { leafStepId } from '../engine/node-path.js';
30
34
  /** Why an event was not admitted, for logs and for the error a manual run gets. */
31
35
  function reasonOf(decision) {
32
36
  if (decision.kind === 'gone')
@@ -47,48 +51,6 @@ function reasonOf(decision) {
47
51
  * what reads the world.
48
52
  */
49
53
  const EARLY_WAKE_TOLERANCE_MS = 1_000;
50
- /**
51
- * The fields whose values are actually known while editing.
52
- *
53
- * A sibling field may hold `{{trigger.projectId}}` — a promise about run time,
54
- * not an id. A loader filtering by it would search for the literal text and
55
- * quietly find nothing, so references are dropped here and offered separately as
56
- * `config` for the rare loader that wants the raw text.
57
- */
58
- function literalValues(config) {
59
- const out = {};
60
- for (const [key, value] of Object.entries(config)) {
61
- if (isPlainObject(value)) {
62
- // Follow the form as deep as a field path can go: `repository.id` is a
63
- // usable filter even when its neighbour `repository.name` is a reference.
64
- out[key] = literalValues(value);
65
- continue;
66
- }
67
- if (holdsRef(value))
68
- continue;
69
- out[key] = value;
70
- }
71
- return out;
72
- }
73
- function isPlainObject(value) {
74
- return typeof value === 'object' && value !== null && !Array.isArray(value);
75
- }
76
- /**
77
- * Whether a value is waiting on run time anywhere inside it.
78
- *
79
- * An array is all-or-nothing: dropping the one element that holds a reference
80
- * would hand the loader a shorter list and no sign that it is short, which reads
81
- * as a narrower filter rather than an unanswerable one.
82
- */
83
- function holdsRef(value) {
84
- if (typeof value === 'string')
85
- return value.includes('{{');
86
- if (Array.isArray(value))
87
- return value.some(holdsRef);
88
- if (isPlainObject(value))
89
- return Object.values(value).some(holdsRef);
90
- return false;
91
- }
92
54
  function messageOf(err) {
93
55
  return err instanceof Error ? err.message : String(err);
94
56
  }
@@ -112,31 +74,10 @@ function inputSchemaOf(config) {
112
74
  function parseWorkflowConfig(raw) {
113
75
  return JSON.parse(raw ?? '{}');
114
76
  }
115
- /**
116
- * Find a step config by id anywhere in a workflow config tree — top-level or
117
- * nested inside any control-flow branch. A step node is any object carrying
118
- * both `id` and `type`. Used to label paused gates in the approvals queue.
119
- */
120
- function findStepConfigById(config, id) {
121
- let found = null;
122
- const visit = (node) => {
123
- if (found || node === null || typeof node !== 'object')
124
- return;
125
- if (Array.isArray(node)) {
126
- for (const n of node)
127
- visit(n);
128
- return;
129
- }
130
- const obj = node;
131
- if (typeof obj['id'] === 'string' && typeof obj['type'] === 'string' && obj['id'] === id) {
132
- found = { id, ...(typeof obj['title'] === 'string' ? { title: obj['title'] } : {}) };
133
- return;
134
- }
135
- for (const v of Object.values(obj))
136
- visit(v);
137
- };
138
- visit(config);
139
- return found;
77
+ /** The author-given name out of the metadata column, if it has one. */
78
+ function parseWorkflowName(raw) {
79
+ const meta = JSON.parse(raw ?? '{}');
80
+ return typeof meta['name'] === 'string' ? meta['name'] : undefined;
140
81
  }
141
82
  // ─── WorkflowRuntime ───
142
83
  export class WorkflowRuntime {
@@ -163,6 +104,8 @@ export class WorkflowRuntime {
163
104
  defaultCronTimezone;
164
105
  /** AI builder config — when present, the router includes the ai-builder chat route. */
165
106
  aiBuilder;
107
+ /** Which configurations need approval before going live. Host-supplied, always. */
108
+ approval;
166
109
  constructor(opts) {
167
110
  this.persistence = opts.persistence;
168
111
  // No fallback and no cast: the authorizer and the adapter must agree on
@@ -179,7 +122,8 @@ export class WorkflowRuntime {
179
122
  this.eventBus = opts.eventBus;
180
123
  this.storage = opts.storage;
181
124
  this.sandbox = opts.sandbox;
182
- const config = opts.config ?? {};
125
+ const config = opts.config;
126
+ this.approval = config.approval;
183
127
  this.baseUrl = config.baseUrl ?? '';
184
128
  this.allowExecutableUploads = config.allowExecutableUploads ?? false;
185
129
  this.defaultCronTimezone = config.defaultCronTimezone ?? 'Asia/Kolkata';
@@ -203,6 +147,28 @@ export class WorkflowRuntime {
203
147
  publishEvent(executionId, event) {
204
148
  this.publish(executionTopic(executionId), event);
205
149
  }
150
+ /**
151
+ * Announce that a run appeared or changed status, to the workflow's topic and
152
+ * its folder's — the screens that need it are scoped both ways.
153
+ *
154
+ * Fire-and-forget, like every publish here.
155
+ */
156
+ publishRunChange(workflow, executionId, status) {
157
+ if (!this.eventBus)
158
+ return;
159
+ const event = {
160
+ event: 'run_changed',
161
+ data: {
162
+ workflowId: workflow.id,
163
+ executionId,
164
+ status,
165
+ at: new Date().toISOString(),
166
+ },
167
+ };
168
+ this.publish(workflowTopic(workflow.id), event);
169
+ if (workflow.folderId)
170
+ this.publish(folderTopic(workflow.folderId), event);
171
+ }
206
172
  /**
207
173
  * Announce that a workflow definition changed.
208
174
  *
@@ -323,11 +289,23 @@ export class WorkflowRuntime {
323
289
  * `result.valid` is false. Returns structured issues the frontend
324
290
  * can render inline in the workflow builder.
325
291
  */
326
- validateConfig(config) {
327
- const validator = new ConfigValidator(this.connectors);
328
- return validator.validate(config);
292
+ async validateConfig(ctx, config, workflowId) {
293
+ const result = new ConfigValidator(this.connectors).validate(config);
294
+ if (!result.valid || workflowId === undefined)
295
+ return result;
296
+ const attributes = await this.editingScope(ctx, { workflowId });
297
+ const issues = [...result.issues, ...(await this.checkComponents(ctx, config, attributes))];
298
+ return { valid: issues.length === 0, issues };
329
299
  }
330
300
  // ─── Workflow Lifecycle ───
301
+ /**
302
+ * Whether this configuration needs a reviewer, and which component types
303
+ * asked for it. The reading of the policy is {@link approvalGate}; this only
304
+ * supplies it with what the configuration is made of.
305
+ */
306
+ gateFor(config) {
307
+ return approvalGate(this.approval, new ConfigValidator(this.connectors).components(config));
308
+ }
331
309
  /**
332
310
  * Activate a workflow's trigger.
333
311
  *
@@ -336,24 +314,165 @@ export class WorkflowRuntime {
336
314
  *
337
315
  * Only then is the workflow marked ACTIVE. Webhook ingest and event dispatch
338
316
  * both key off that status, so it is what actually turns a workflow on.
317
+ *
318
+ * Unless the deployment's {@link ApprovalConfig} gates this configuration, in
319
+ * which case it goes to PENDING_APPROVAL and none of the above happens yet —
320
+ * a workflow awaiting review must not hold a cron registration.
321
+ *
322
+ * `workflow:activate` stays the maker's action throughout: authorization says
323
+ * whether you may turn workflows on, the policy says whether this one needs a
324
+ * second look first. Neither stands in for the other.
339
325
  */
340
326
  async activateWorkflow(ctx, workflowId, opts) {
341
327
  // Guard up front, before any external side-effects (webhook/scheduler).
342
- const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:activate');
343
- await this.activateInternal(record);
344
- await this.persistence.updateWorkflow(workflowId, { status: 'ACTIVE' });
328
+ const { record, permittedActions } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:activate');
329
+ const gate = this.gateFor(parseWorkflowConfig(record.config));
330
+ // A caller who may approve is approving by activating — otherwise an admin
331
+ // toggling their own workflow would queue a review of their own work.
332
+ // Strict four-eyes is the authorizer's to impose: withhold
333
+ // `workflow:approve` when the caller is the author and this branch stops
334
+ // applying to them.
335
+ if (gate.required && !permittedActions.includes('workflow:approve')) {
336
+ await this.persistence.updateWorkflow(workflowId, {
337
+ status: WorkflowStatus.PENDING_APPROVAL,
338
+ });
339
+ this.log.info(`workflow ${workflowId} submitted for approval — gated by ${gate.gatedBy.join(', ')}`);
340
+ this.publishWorkflowChange(workflowId, 'submitted', opts?.origin);
341
+ return { status: WorkflowStatus.PENDING_APPROVAL, gatedBy: gate.gatedBy };
342
+ }
343
+ await this.activateInternal(ctx, record);
344
+ await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.ACTIVE });
345
345
  // After the side-effects, never before: an activation that failed is not a
346
346
  // change worth telling anyone about.
347
347
  this.publishWorkflowChange(workflowId, 'activated', opts?.origin);
348
+ return { status: WorkflowStatus.ACTIVE, gatedBy: [] };
349
+ }
350
+ /**
351
+ * Approve a workflow awaiting review and put it live.
352
+ *
353
+ * Approval and activation are one act, deliberately: the checker's consent is
354
+ * expressed by the workflow starting, so there is no "approved but off" state
355
+ * to explain, and no second click for someone to forget. The trigger's
356
+ * side-effects run here — at the moment it actually goes live, not when it
357
+ * was submitted.
358
+ */
359
+ async approveWorkflow(ctx, workflowId, opts) {
360
+ const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:approve');
361
+ if (record.status !== WorkflowStatus.PENDING_APPROVAL) {
362
+ throw new Error(`Cannot approve workflow ${workflowId}: it is ${record.status}, not awaiting approval`);
363
+ }
364
+ await this.activateInternal(ctx, record);
365
+ await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.ACTIVE });
366
+ this.log.info(`workflow ${workflowId} approved and activated`);
367
+ this.publishWorkflowChange(workflowId, 'approved', opts?.origin);
368
+ }
369
+ /**
370
+ * Decline a workflow awaiting review.
371
+ *
372
+ * REJECTED rather than back to DRAFT, so the author can tell "declined" from
373
+ * "nobody has looked yet". Editing it returns it to DRAFT — see
374
+ * {@link updateWorkflow}. The reason and the reviewer are the host's to
375
+ * record: this runtime has no notion of who anyone is.
376
+ */
377
+ async rejectWorkflow(ctx, workflowId, opts) {
378
+ const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:approve');
379
+ if (record.status !== WorkflowStatus.PENDING_APPROVAL) {
380
+ throw new Error(`Cannot reject workflow ${workflowId}: it is ${record.status}, not awaiting approval`);
381
+ }
382
+ await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.REJECTED });
383
+ this.log.info(`workflow ${workflowId} rejected`);
384
+ this.publishWorkflowChange(workflowId, 'rejected', opts?.origin);
348
385
  }
349
386
  /**
350
387
  * The activation work, already authorized. Used by the guarded
351
388
  * {@link activateWorkflow} and by `createWorkflow` (whose create was itself
352
389
  * authorized against the target folder).
353
390
  */
354
- async activateInternal(workflow) {
391
+ /**
392
+ * Every component's verdict on the config, merged into issues that path like
393
+ * any other.
394
+ *
395
+ * Components run concurrently and independently: one slow connector must not
396
+ * hold up the rest, and one that throws must not hide what the others found. A
397
+ * rejection becomes a MISCONFIGURED issue rather than an exception — failing
398
+ * closed, because refusing to activate is the safe answer when the check that
399
+ * would have caught a problem could not be made.
400
+ */
401
+ async checkComponents(ctx, config, attributes) {
402
+ const refs = new ConfigValidator(this.connectors)
403
+ .components(config)
404
+ .map((ref) => ({
405
+ ref,
406
+ impl: ref.kind === 'trigger'
407
+ ? this.connectors.getTrigger(ref.type)
408
+ : this.connectors.getStep(ref.type),
409
+ }))
410
+ .filter((entry) => entry.impl.validateConfig !== undefined);
411
+ if (refs.length === 0)
412
+ return [];
413
+ const settled = await Promise.allSettled(refs.map(async ({ ref, impl }) => {
414
+ // A half-configured credential is the component's problem to report, not
415
+ // a reason to crash — the same choice getFieldOptions makes.
416
+ let credentials = {};
417
+ try {
418
+ credentials = await this.credentialResolver.resolve(attributes, impl, ref.config);
419
+ }
420
+ catch (err) {
421
+ this.log.info(`validateConfig for ${ref.kind} "${ref.type}": no usable credential — ${messageOf(err)}`);
422
+ }
423
+ const issues = await impl.validateConfig({
424
+ config: ref.config,
425
+ known: literalValues(ref.config),
426
+ credentials,
427
+ attributes,
428
+ services: this.services,
429
+ caller: ctx,
430
+ });
431
+ return { ref, issues };
432
+ }));
433
+ const out = [];
434
+ settled.forEach((result, index) => {
435
+ const { ref } = refs[index];
436
+ const location = ref.kind === 'trigger'
437
+ ? { scope: 'trigger' }
438
+ : { scope: 'step', ...(ref.stepId !== undefined ? { stepId: ref.stepId } : {}) };
439
+ if (result.status === 'rejected') {
440
+ this.log.warn(`validateConfig threw for ${ref.kind} "${ref.type}": ${messageOf(result.reason)}`);
441
+ out.push({
442
+ path: ref.path,
443
+ code: ValidationIssueCode.MISCONFIGURED,
444
+ // Says "unknown", not "wrong" — the author should retry, not go hunting
445
+ // for a mistake that may not exist.
446
+ message: `Could not verify the ${ref.kind} "${ref.type}" — please try again.`,
447
+ location,
448
+ });
449
+ return;
450
+ }
451
+ for (const issue of result.value.issues) {
452
+ out.push({
453
+ path: issue.path ? `${ref.path}.${issue.path}` : ref.path,
454
+ code: ValidationIssueCode.MISCONFIGURED,
455
+ message: issue.message,
456
+ ...(issue.path !== undefined
457
+ ? { location: { ...location, field: issue.path } }
458
+ : { location }),
459
+ });
460
+ }
461
+ });
462
+ return out;
463
+ }
464
+ async activateInternal(ctx, workflow) {
355
465
  const workflowId = workflow.id;
356
466
  const config = parseWorkflowConfig(workflow.config);
467
+ const activateAttributes = workflow.attributes;
468
+ // A configuration naming things that do not exist, or that its author may
469
+ // not use, fails here — beside the credential check below and for the same
470
+ // reason: better now than on the first event. Saving is deliberately left
471
+ // alone, because a draft in progress is allowed to be wrong.
472
+ const unresolved = await this.checkComponents(ctx, config, activateAttributes);
473
+ if (unresolved.length > 0) {
474
+ throw new Error(`Cannot activate workflow ${workflowId}: ${unresolved.map((issue) => issue.message).join('; ')}`);
475
+ }
357
476
  if (!this.connectors.hasTrigger(config.trigger.type)) {
358
477
  throw new Error(`Trigger type "${config.trigger.type}" is not registered`);
359
478
  }
@@ -630,6 +749,10 @@ export class WorkflowRuntime {
630
749
  throw new Error(`Workflow ${workflowId} not found`);
631
750
  }
632
751
  await this.require(ctx, 'workflow:run', this.workflowRef(workflow));
752
+ if (workflow.status === WorkflowStatus.PENDING_APPROVAL) {
753
+ throw new Error(`Cannot run workflow ${workflowId}: it is awaiting approval. ` +
754
+ `Deactivate it to keep editing and testing, or wait for a decision.`);
755
+ }
633
756
  const config = parseWorkflowConfig(workflow.config);
634
757
  const triggerCfg = (config.trigger.config ?? {});
635
758
  const inputSchema = triggerCfg['inputSchema'];
@@ -826,8 +949,40 @@ export class WorkflowRuntime {
826
949
  */
827
950
  async listWorkflows(ctx, page) {
828
951
  const filter = await this.filterFor(ctx, 'workflow');
829
- const records = await this.persistence.listWorkflows(filter, page);
830
- return this.project(ctx, records, (wf) => this.workflowRef(wf));
952
+ const result = await this.persistence.listWorkflows(filter, {
953
+ ...resolvePage(page),
954
+ ...(page?.folderId !== undefined ? { folderId: page.folderId } : {}),
955
+ });
956
+ const items = await this.project(ctx, result.items, (wf) => this.workflowRef(wf));
957
+ return {
958
+ items,
959
+ ...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
960
+ };
961
+ }
962
+ async listPendingWorkflows(ctx, params) {
963
+ const filter = await this.filterFor(ctx, 'workflow');
964
+ const page = await this.persistence.listPendingWorkflows(filter, resolvePage(params));
965
+ const rows = await this.project(ctx, page.items, (wf) => this.workflowRef(wf));
966
+ const items = rows.map((wf) => {
967
+ const config = parseWorkflowConfig(wf.config);
968
+ const name = parseWorkflowName(wf.metadata);
969
+ return {
970
+ workflowId: wf.id,
971
+ // Spread-when-present, like every other optional the SDK returns: a
972
+ // consumer tests presence rather than comparing against a placeholder.
973
+ ...(name !== undefined ? { name } : {}),
974
+ folderId: wf.folderId,
975
+ triggerType: config.trigger.type,
976
+ gatedBy: this.gateFor(config).gatedBy,
977
+ submittedAt: wf.updatedAt,
978
+ ...(wf.permittedActions !== undefined
979
+ ? { permittedActions: wf.permittedActions }
980
+ : {}),
981
+ };
982
+ });
983
+ return page.nextCursor === undefined
984
+ ? { items }
985
+ : { items, nextCursor: page.nextCursor };
831
986
  }
832
987
  /** Workflow counts for the visible set — total + per-folder, for the folder rail. */
833
988
  async workflowCounts(ctx) {
@@ -852,10 +1007,17 @@ export class WorkflowRuntime {
852
1007
  // exists, so this same decision is what the UI projects onto its "New
853
1008
  // workflow" button. Also proves the folder exists — no separate lookup.
854
1009
  await this.authorizedFolder(ctx, input.folderId, 'workflow:create');
855
- const validation = this.validateConfig(input.config);
1010
+ const validation = new ConfigValidator(this.connectors).validate(input.config);
1011
+ // Create goes live here, so it is an activation and has to face the same
1012
+ // gate — otherwise "build it fresh" is the way around every other check.
1013
+ const gate = this.gateFor(input.config);
856
1014
  const metadata = { ...input.metadata, name: input.name };
857
1015
  const id = await this.persistence.createWorkflow({
858
- status: 'ACTIVE',
1016
+ // A gated configuration lands awaiting review. The promotion below is
1017
+ // what lets someone who may approve create one live, and it has to come
1018
+ // after the insert: the authorizer decides about a workflow, and until
1019
+ // the row exists there is no workflow to decide about.
1020
+ status: gate.required ? WorkflowStatus.PENDING_APPROVAL : WorkflowStatus.ACTIVE,
859
1021
  config: JSON.stringify(input.config),
860
1022
  metadata: JSON.stringify(metadata),
861
1023
  eventType: input.config.trigger.type,
@@ -863,13 +1025,25 @@ export class WorkflowRuntime {
863
1025
  folderId: input.folderId,
864
1026
  attributes: input.attributes,
865
1027
  });
866
- const record = await this.persistence.getWorkflow(id);
1028
+ let record = await this.persistence.getWorkflow(id);
867
1029
  if (!record)
868
1030
  throw new Error('Failed to read created workflow');
869
- if (validation.valid) {
1031
+ let live = !gate.required;
1032
+ if (gate.required) {
1033
+ const permitted = await this.authorizer.permissions(ctx, this.workflowRef(record));
1034
+ if (permitted.includes('workflow:approve')) {
1035
+ await this.persistence.updateWorkflow(id, { status: WorkflowStatus.ACTIVE });
1036
+ record = (await this.persistence.getWorkflow(id)) ?? record;
1037
+ live = true;
1038
+ }
1039
+ else {
1040
+ this.log.info(`created workflow ${id} awaiting approval — gated by ${gate.gatedBy.join(', ')}`);
1041
+ }
1042
+ }
1043
+ if (live && validation.valid) {
870
1044
  try {
871
1045
  // Internal post-create activation — already authorized by the create above.
872
- await this.activateInternal(record);
1046
+ await this.activateInternal(ctx, record);
873
1047
  }
874
1048
  catch (err) {
875
1049
  // Non-fatal — the workflow is created, and its trigger can be activated
@@ -909,6 +1083,26 @@ export class WorkflowRuntime {
909
1083
  if (input.config) {
910
1084
  update.config = JSON.stringify(input.config);
911
1085
  update.eventType = input.config.trigger.type;
1086
+ // An ACTIVE workflow was approved as it stands, so editing it in place
1087
+ // would put something unreviewed live — and it is the obvious way round
1088
+ // the gate: ship something harmless, then edit the rest in. Refusing is
1089
+ // also why a maker cannot take production down by accident: stopping it
1090
+ // stays a separate, deliberate act.
1091
+ //
1092
+ // Only when the NEW configuration is gated. An edit that removes the
1093
+ // gated component, or never had one, is not what this protects — and
1094
+ // under a policy that gates nothing, none of this ever fires.
1095
+ const gate = this.gateFor(input.config);
1096
+ if (gate.required && existing.status === WorkflowStatus.ACTIVE) {
1097
+ throw new Error(`Cannot edit workflow ${workflowId} while it is active: the new configuration ` +
1098
+ `needs approval (${gate.gatedBy.join(', ')}). Deactivate it first.`);
1099
+ }
1100
+ // Editing withdraws a submission and clears a rejection — whatever a
1101
+ // reviewer saw or declined is no longer what is on the table.
1102
+ if (existing.status === WorkflowStatus.PENDING_APPROVAL ||
1103
+ existing.status === WorkflowStatus.REJECTED) {
1104
+ update.status = WorkflowStatus.DRAFT;
1105
+ }
912
1106
  }
913
1107
  // Update metadata if name or metadata provided
914
1108
  if (input.name !== undefined || input.metadata !== undefined) {
@@ -928,10 +1122,14 @@ export class WorkflowRuntime {
928
1122
  return updated;
929
1123
  }
930
1124
  // ─── Folders ───
931
- /** List folders the caller may see. */
932
- async listFolders(ctx) {
933
- const records = await this.persistence.listFolders(await this.filterFor(ctx, 'folder'));
934
- return this.project(ctx, records, (f) => this.folderRef(f));
1125
+ /** List folders the caller may see, one page at a time. */
1126
+ async listFolders(ctx, page) {
1127
+ const result = await this.persistence.listFolders(await this.filterFor(ctx, 'folder'), resolvePage(page));
1128
+ const items = await this.project(ctx, result.items, (f) => this.folderRef(f));
1129
+ return {
1130
+ items,
1131
+ ...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
1132
+ };
935
1133
  }
936
1134
  /**
937
1135
  * Get a single folder by id. Guards `folder:read` and attaches the caller's
@@ -1078,64 +1276,46 @@ export class WorkflowRuntime {
1078
1276
  async listExecutions(ctx, params) {
1079
1277
  // Executions inherit their workflow's visibility — the adapter joins the
1080
1278
  // workflow filter rather than us enumerating workflow ids first.
1081
- return this.persistence.listExecutions(await this.filterFor(ctx, 'workflow'), params);
1279
+ return this.persistence.listExecutions(await this.filterFor(ctx, 'workflow'), {
1280
+ ...resolvePage(params),
1281
+ ...(params.workflowId !== undefined ? { workflowId: params.workflowId } : {}),
1282
+ ...(params.status !== undefined ? { status: params.status } : {}),
1283
+ ...(params.folderId !== undefined ? { folderId: params.folderId } : {}),
1284
+ });
1082
1285
  }
1083
1286
  /**
1084
- * Lightweight list of executions waiting for approval — only the fields
1085
- * needed to render the approval queue without N individual fetches.
1287
+ * One page of the approvals inbox — a pass-through to the adapter, which
1288
+ * answers it in a single joined query.
1086
1289
  */
1087
- async listPendingApprovals(ctx, limit) {
1088
- // Visible-workflow scoped for now: any caller who can see the workflow sees
1089
- // its pending gates. Narrowing this to the step's assignee is P3, and lands
1090
- // as `visibleFilter(ctx, 'approval')` — this stays the workflow filter until
1290
+ async listPendingApprovals(ctx, params) {
1291
+ // Visible-workflow scoped: any caller who can see the workflow sees its
1292
+ // pending gates. Narrowing this to the step's assignee is P3, and lands as
1293
+ // `visibleFilter(ctx, 'approval')` — this stays the workflow filter until
1091
1294
  // approval steps actually carry an assignee.
1092
- const { items } = await this.persistence.listExecutions(await this.filterFor(ctx, 'workflow'), { status: 'EXTERNAL_WAIT', ...(limit !== undefined ? { limit } : {}) });
1093
- const results = await Promise.all(items.map(async (exec) => {
1094
- const steps = await this.persistence.getStepRows(exec.id);
1095
- // Prefer the resumable leaf gate (non-control); fall back to any wait.
1096
- const pausedStep = steps.find((s) => (s.status === 'EXTERNAL_WAIT' || s.status === 'REVIEW_WAIT') &&
1097
- s.executorType !== 'conditional') ?? steps.find((s) => s.status === 'EXTERNAL_WAIT');
1098
- // stepName is a node-path record key (the step id, or a branch-qualified
1099
- // path like "parallel_x:swot#0/approve"). Derive a friendly display name
1100
- // from the leaf step id and its config title.
1101
- let pausedStepName = pausedStep ? leafStepId(pausedStep.stepName) : '';
1102
- let workflowName;
1103
- let workflowTags;
1104
- const workflow = await this.persistence.getWorkflow(exec.workflowId);
1105
- if (workflow) {
1106
- try {
1107
- const meta = JSON.parse(workflow.metadata ?? '{}');
1108
- if (typeof meta['name'] === 'string')
1109
- workflowName = meta['name'];
1110
- if (Array.isArray(meta['tags'])) {
1111
- const tags = meta['tags'].filter((t) => typeof t === 'string');
1112
- if (tags.length > 0)
1113
- workflowTags = tags;
1114
- }
1115
- }
1116
- catch { /* ignore */ }
1117
- if (pausedStep && workflow.config) {
1118
- try {
1119
- const leafId = leafStepId(pausedStep.stepName);
1120
- const stepConfig = findStepConfigById(JSON.parse(workflow.config), leafId);
1121
- if (stepConfig?.title)
1122
- pausedStepName = stepConfig.title;
1123
- else if (stepConfig?.id)
1124
- pausedStepName = stepConfig.id;
1125
- }
1126
- catch { /* ignore */ }
1127
- }
1128
- }
1129
- return {
1130
- id: exec.id,
1131
- workflowId: exec.workflowId,
1132
- ...(workflowName !== undefined ? { name: workflowName } : {}),
1133
- pausedStepName,
1134
- createdAt: exec.createdAt,
1135
- ...(workflowTags !== undefined ? { tags: workflowTags } : {}),
1136
- };
1137
- }));
1138
- return results;
1295
+ return this.persistence.listPendingApprovals(await this.filterFor(ctx, 'workflow'), {
1296
+ ...resolvePage(params),
1297
+ ...(params?.workflowIds !== undefined ? { workflowIds: params.workflowIds } : {}),
1298
+ ...(params?.stages !== undefined ? { stages: params.stages } : {}),
1299
+ ...(params?.tags !== undefined ? { tags: params.tags } : {}),
1300
+ ...(params?.search !== undefined ? { search: params.search } : {}),
1301
+ ...(params?.sort !== undefined ? { sort: params.sort } : {}),
1302
+ });
1303
+ }
1304
+ /** How many runs are waiting on a gate this caller can see. */
1305
+ async countPendingApprovals(ctx) {
1306
+ return this.persistence.countPendingApprovals(await this.filterFor(ctx, 'workflow'));
1307
+ }
1308
+ /**
1309
+ * Filter facets for the approvals inbox, over the whole visible set —
1310
+ * deliberately not derived from a page, which would offer fewer choices the
1311
+ * further someone pages.
1312
+ */
1313
+ async pendingApprovalFacets(ctx) {
1314
+ return this.persistence.pendingApprovalFacets(await this.filterFor(ctx, 'workflow'));
1315
+ }
1316
+ /** The latest run of each workflow in scope, as one grouped query. */
1317
+ async lastRunByWorkflow(ctx, params = {}) {
1318
+ return this.persistence.lastRunByWorkflow(await this.filterFor(ctx, 'workflow'), params);
1139
1319
  }
1140
1320
  /**
1141
1321
  * Get execution detail including step records.
@@ -1195,13 +1375,30 @@ export class WorkflowRuntime {
1195
1375
  }
1196
1376
  await this.persistence.updateExecutionStatus(executionId, 'CANCELLED');
1197
1377
  this.publishEvent(executionId, { event: 'execution_cancelled', data: {} });
1378
+ // A cancel never passes through `processJob`, so the lists need telling here.
1379
+ const owner = await this.persistence.getWorkflow(exec.workflowId);
1380
+ if (owner)
1381
+ this.publishRunChange(owner, executionId, 'CANCELLED');
1198
1382
  this.log.info(`execution ${executionId} cancelled`);
1199
1383
  }
1200
1384
  /** List the credentials visible to `ctx` as safe, paginated summaries. */
1201
1385
  async listCredentials(ctx, page) {
1202
1386
  const filter = await this.filterFor(ctx, 'credential');
1203
- const records = await this.persistence.listCredentials(filter, page);
1204
- return this.project(ctx, records, (credential) => this.credentialRef(credential));
1387
+ const result = await this.persistence.listCredentials(filter, resolvePage(page));
1388
+ const items = await this.project(ctx, result.items, (credential) => this.credentialRef(credential));
1389
+ return {
1390
+ items,
1391
+ ...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
1392
+ };
1393
+ }
1394
+ /** One visible credential by name — an indexed lookup, not a list scan. */
1395
+ async getCredentialByName(ctx, name) {
1396
+ const filter = await this.filterFor(ctx, 'credential');
1397
+ const record = await this.persistence.getCredentialByName(filter, name);
1398
+ if (!record)
1399
+ return null;
1400
+ const [projected] = await this.project(ctx, [record], (credential) => this.credentialRef(credential));
1401
+ return projected ?? null;
1205
1402
  }
1206
1403
  /* Create a new credential in the workspace.*/
1207
1404
  async createCredential(attributes, input) {
@@ -1262,6 +1459,10 @@ export class WorkflowRuntime {
1262
1459
  const final = await this.persistence.getExecution(executionId);
1263
1460
  if (!final)
1264
1461
  return { status: 'not_found' };
1462
+ // One frame per pass, not per step — a list shows only the run's status.
1463
+ const owner = await this.persistence.getWorkflow(final.workflowId);
1464
+ if (owner)
1465
+ this.publishRunChange(owner, executionId, final.status);
1265
1466
  if (final.status === 'EXTERNAL_WAIT') {
1266
1467
  // Liveness (level-triggered): if a resume payload was routed to a gate
1267
1468
  // *during* this pass — after the walk had already read that node's
@@ -1370,7 +1571,7 @@ export class WorkflowRuntime {
1370
1571
  * been authorized against, never from the request body.
1371
1572
  */
1372
1573
  async getFieldOptions(ctx, input) {
1373
- const attributes = await this.optionsScope(ctx, input);
1574
+ const attributes = await this.editingScope(ctx, input);
1374
1575
  const component = input.kind === 'step'
1375
1576
  ? this.connectors.hasStep(input.type)
1376
1577
  ? this.connectors.getStep(input.type)
@@ -1436,7 +1637,7 @@ export class WorkflowRuntime {
1436
1637
  * workspace, and narrowing it per viewer would be a policy the connector
1437
1638
  * cannot express and the tenant did not ask for.
1438
1639
  */
1439
- async optionsScope(ctx, input) {
1640
+ async editingScope(ctx, input) {
1440
1641
  if (input.workflowId !== undefined) {
1441
1642
  const { record } = await this.authorizedWorkflow(ctx, input.workflowId, 'workflow:read');
1442
1643
  return record.attributes;
@@ -1445,7 +1646,7 @@ export class WorkflowRuntime {
1445
1646
  const { record } = await this.authorizedFolder(ctx, input.folderId, 'workflow:create');
1446
1647
  return record.attributes;
1447
1648
  }
1448
- throw new Error('Field options need the workflow being edited, or the folder for a new one');
1649
+ throw new Error('Needs the workflow being edited, or the folder a new one will live in');
1449
1650
  }
1450
1651
  // ─── Internal ───
1451
1652
  /**
@@ -1659,6 +1860,8 @@ export class WorkflowRuntime {
1659
1860
  }
1660
1861
  : {}),
1661
1862
  });
1863
+ // Announced here rather than per call site: every run passes through.
1864
+ this.publishRunChange(workflow, execId, scheduled ? 'SCHEDULED' : 'PENDING');
1662
1865
  if (scheduled) {
1663
1866
  // The delay is the fast path; `fireAt` on the row is the truth. A host that
1664
1867
  // sweeps for overdue runs makes a lost job late rather than lost.