@lovable.dev/workflows-sdk 0.0.0-dev.13 → 0.0.0-dev.15

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.
package/README.md CHANGED
@@ -273,13 +273,19 @@ every graph carries one `unknown` node and the diagnostic
273
273
  `Install typescript to infer step graphs`.
274
274
  Sequential awaited `ctx.step("name", callback)` calls produce order edges;
275
275
  `await Promise.all([ctx.step(...), ctx.step(...)])` produces parallel branches
276
- that join at the next step. Returned step promises work too. Keep step IDs literal.
276
+ that join at the next step. A `Promise.all()` mapped over a collection with the
277
+ step ID template `step-${item.id}` produces one dynamic parallel node labeled
278
+ `step-{item.id}`. Returned step promises work too. Keep step IDs literal outside
279
+ this mapped form.
277
280
 
278
281
  | Field | Meaning |
279
282
  | --- | --- |
280
283
  | `nodes[].id` | Unique occurrence ID within this graph; use as the UI node key |
281
- | `nodes[].kind` | `step` or `unknown` |
282
- | `nodes[].stepId` | Literal step name, present for known steps |
284
+ | `nodes[].kind` | Durable operation, `parallel`, or `unknown` |
285
+ | `nodes[].stepId` | Runtime durable ID for every statically known operation |
286
+ | `nodes[].cardinality` | `dynamic` for a runtime-sized parallel fan-out |
287
+ | `nodes[].operation.kind` | Durable operation repeated by a parallel node |
288
+ | `nodes[].operation.stepIdTemplate` | Display template for steps in a dynamic parallel node |
283
289
  | `nodes[].label` | Step name or explanation of unsupported code |
284
290
  | `edges[]` | `{ source, target, kind: "order" }`, referencing node IDs |
285
291
  | `complete` | Whether the handler uses only supported syntax |
@@ -290,13 +296,19 @@ For example, `read` followed by parallel `transform-a` and `transform-b`, then
290
296
  Node IDs are deterministic for the same source, but may change when the handler
291
297
  is edited.
292
298
 
299
+ Known durable nodes use the same `stepId` as runtime progress records. An
300
+ explicit `{ id }` wins; otherwise the graph and runtime share the operation's
301
+ derived default. `label` remains the display name.
302
+
293
303
  Graphs have `source: "inferred"` and `scope: "handler"`. They describe source
294
304
  structure, not run history or data dependencies, and exclude middleware and
295
- initialization. Branches, loops, helper calls, dynamic step IDs, and unawaited
296
- steps produce `unknown` nodes and `complete: false`; steps inside unsupported
297
- code are not expanded. The UI should show these unknown nodes and mark partial
298
- graphs. Transforms that rewrite the handler may also produce a partial graph.
299
- A handler with no steps can have an empty graph.
305
+ initialization. A mapped `Promise.all` is complete when its callback directly
306
+ returns `ctx.step()` with a template-literal ID derived from a callback parameter.
307
+ Other branches, loops, helper calls, dynamic step IDs, and unawaited steps produce
308
+ `unknown` nodes and `complete: false`; steps inside unsupported code are not
309
+ expanded. The UI should show these unknown nodes and mark partial graphs.
310
+ Transforms that rewrite the handler may also produce a partial graph. A handler
311
+ with no steps can have an empty graph.
300
312
 
301
313
  A step body is one atomic execution unit. Manifest generation rejects statically
302
314
  visible durable calls inside it, including `ctx.step`, `ctx.sleep`, `ctx.now`,
@@ -1,5 +1,5 @@
1
1
  import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
2
- import { loadTypeScript } from "./graph-CPDci8jW.js";
2
+ import { loadTypeScript } from "./graph-Bt-31WQT.js";
3
3
  //#region src/manifests/duplicate-ids.ts
4
4
  /** Where an explicit `{ id }` would sit for each operation. */
5
5
  const optionsArgument = {
@@ -183,9 +183,9 @@ function serializeSchema(schema, direction, label) {
183
183
  }
184
184
  }
185
185
  async function generateManifests(definition) {
186
- const { extractWorkflowGraph } = await import("./graph-CPDci8jW.js");
187
- const { findDuplicateOperationIds } = await import("./duplicate-ids-CzUHGRC_.js");
188
- const { findNestedDurableOperations } = await import("./nested-operations-BnWB9UhQ.js");
186
+ const { extractWorkflowGraph } = await import("./graph-Bt-31WQT.js");
187
+ const { findDuplicateOperationIds } = await import("./duplicate-ids-ClNLIwAz.js");
188
+ const { findNestedDurableOperations } = await import("./nested-operations-Cpzs_PHo.js");
189
189
  const collection = registerWorkflows(definition);
190
190
  const manifests = [];
191
191
  for (const workflow of collection.workflows) {
@@ -1,3 +1,4 @@
1
+ import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
1
2
  //#region src/manifests/graph.ts
2
3
  const durableMethods = {
3
4
  step: 0,
@@ -85,6 +86,39 @@ async function extractWorkflowGraph(handler) {
85
86
  const value = Number(node.text);
86
87
  return Number.isFinite(value) ? value : void 0;
87
88
  }
89
+ function templateReference(node, parameters) {
90
+ while (ts.isParenthesizedExpression(node)) node = node.expression;
91
+ if (ts.isIdentifier(node)) return parameters.has(node.text) ? node.text : void 0;
92
+ if (ts.isPropertyAccessExpression(node) && !node.questionDotToken) {
93
+ const expression = templateReference(node.expression, parameters);
94
+ return expression === void 0 ? void 0 : `${expression}.${node.name.text}`;
95
+ }
96
+ }
97
+ function stepIdTemplate(node, parameters) {
98
+ if (!node || !ts.isTemplateExpression(node)) return void 0;
99
+ let template = node.head.text;
100
+ for (const span of node.templateSpans) {
101
+ const reference = templateReference(span.expression, parameters);
102
+ if (reference === void 0) return void 0;
103
+ template += `{${reference}}${span.literal.text}`;
104
+ }
105
+ return template;
106
+ }
107
+ function mappedStepTemplate(node) {
108
+ while (ts.isParenthesizedExpression(node)) node = node.expression;
109
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression) || node.expression.name.text !== "map" || node.arguments.length !== 1) return;
110
+ const callback = node.arguments[0];
111
+ if (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback)) return void 0;
112
+ const parameters = new Set(callback.parameters.flatMap((parameter) => ts.isIdentifier(parameter.name) ? [parameter.name.text] : []));
113
+ let body;
114
+ if (ts.isBlock(callback.body)) {
115
+ const statement = callback.body.statements.length === 1 ? callback.body.statements[0] : void 0;
116
+ body = statement && ts.isReturnStatement(statement) ? statement.expression : void 0;
117
+ } else body = callback.body;
118
+ while (body && (ts.isParenthesizedExpression(body) || ts.isAwaitExpression(body))) body = body.expression;
119
+ if (!body || !durableCall(body) || body.expression.name.text !== "step") return;
120
+ return stepIdTemplate(body.arguments[0], parameters);
121
+ }
88
122
  function readableOptions(node) {
89
123
  return node && ts.isObjectLiteralExpression(node) && node.properties.every(ts.isPropertyAssignment) ? node : void 0;
90
124
  }
@@ -94,6 +128,11 @@ async function extractWorkflowGraph(handler) {
94
128
  if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
95
129
  }
96
130
  }
131
+ function durableStepId(argument, options, fallback) {
132
+ if (argument && !options) return void 0;
133
+ const given = option(options, "id");
134
+ return given ? stringLiteral(given) : fallback;
135
+ }
97
136
  function durableNode(call, parents) {
98
137
  const method = call.expression.name.text;
99
138
  if (method === "step") {
@@ -109,11 +148,17 @@ async function extractWorkflowGraph(handler) {
109
148
  const options = readableOptions(call.arguments[0]);
110
149
  const title = stringLiteral(option(options, "title"));
111
150
  if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
151
+ const stepId = durableStepId(call.arguments[0], options, defaultDurableId({
152
+ kind: "approve",
153
+ title
154
+ }));
155
+ if (stepId === void 0) return unknown("Dynamic approval IDs are not supported yet", parents);
112
156
  const given = option(options, "description");
113
157
  const description = stringLiteral(given);
114
158
  if (given && description === void 0) degrade("Dynamic approval descriptions are not recorded");
115
159
  return addNode({
116
160
  kind: "approve",
161
+ stepId,
117
162
  config: {
118
163
  title,
119
164
  ...description === void 0 ? {} : { description }
@@ -125,12 +170,17 @@ async function extractWorkflowGraph(handler) {
125
170
  const event = stringLiteral(call.arguments[0]);
126
171
  if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
127
172
  const options = readableOptions(call.arguments[1]);
128
- if (call.arguments[1] && !options) degrade("Dynamic waitForEvent options are not recorded");
173
+ const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
174
+ kind: "waitForEvent",
175
+ name: event
176
+ }));
177
+ if (stepId === void 0) return unknown("Dynamic waitForEvent IDs are not supported yet", parents);
129
178
  const given = option(options, "deadline");
130
179
  const deadline = numberLiteral(given);
131
180
  if (given && deadline === void 0) degrade("Dynamic waitForEvent deadlines are not recorded");
132
181
  return addNode({
133
182
  kind: "wait-for-event",
183
+ stepId,
134
184
  config: {
135
185
  event,
136
186
  ...deadline === void 0 ? {} : { deadline }
@@ -141,16 +191,30 @@ async function extractWorkflowGraph(handler) {
141
191
  if (method === "sleep") {
142
192
  const ms = numberLiteral(call.arguments[0]);
143
193
  if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
194
+ const options = readableOptions(call.arguments[1]);
195
+ const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
196
+ kind: "sleep",
197
+ ms
198
+ }));
199
+ if (stepId === void 0) return unknown("Dynamic sleep IDs are not supported yet", parents);
144
200
  return addNode({
145
201
  kind: "sleep",
202
+ stepId,
146
203
  config: { ms },
147
204
  label: `sleep ${ms}ms`
148
205
  }, parents);
149
206
  }
150
207
  const timestamp = numberLiteral(call.arguments[0]);
151
208
  if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
209
+ const options = readableOptions(call.arguments[1]);
210
+ const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
211
+ kind: "sleepUntil",
212
+ timestamp
213
+ }));
214
+ if (stepId === void 0) return unknown("Dynamic sleepUntil IDs are not supported yet", parents);
152
215
  return addNode({
153
216
  kind: "sleep-until",
217
+ stepId,
154
218
  config: { timestamp },
155
219
  label: `sleep until ${timestamp}`
156
220
  }, parents);
@@ -164,13 +228,26 @@ async function extractWorkflowGraph(handler) {
164
228
  if (node.arguments.some((argument) => contains(argument, durableCall))) return unknown("Nested durable calls are not supported yet", tails);
165
229
  return tails;
166
230
  }
167
- if (awaited && ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === "Promise" && node.expression.name.text === "all" && node.arguments.length === 1 && ts.isArrayLiteralExpression(node.arguments[0])) {
168
- const elements = node.arguments[0].elements;
169
- if (elements.some((element) => contains(element, ts.isAwaitExpression, true))) return unknown("Await expressions inside Promise.all are not supported yet", parents);
170
- return elements.length > 0 ? elements.flatMap((element) => {
171
- while (ts.isParenthesizedExpression(element)) element = element.expression;
172
- return ts.isCallExpression(element) ? expression(element, parents, true) : unknown("Dynamic Promise.all entries are not followed", parents);
173
- }) : parents;
231
+ if (awaited && ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === "Promise" && node.expression.name.text === "all" && node.arguments.length === 1) {
232
+ const argument = node.arguments[0];
233
+ if (ts.isArrayLiteralExpression(argument)) {
234
+ const elements = argument.elements;
235
+ if (elements.some((element) => contains(element, ts.isAwaitExpression, true))) return unknown("Await expressions inside Promise.all are not supported yet", parents);
236
+ return elements.length > 0 ? elements.flatMap((element) => {
237
+ while (ts.isParenthesizedExpression(element)) element = element.expression;
238
+ return ts.isCallExpression(element) ? expression(element, parents, true) : unknown("Dynamic Promise.all entries are not followed", parents);
239
+ }) : parents;
240
+ }
241
+ const template = mappedStepTemplate(argument);
242
+ if (template !== void 0) return addNode({
243
+ kind: "parallel",
244
+ cardinality: "dynamic",
245
+ operation: {
246
+ kind: "step",
247
+ stepIdTemplate: template
248
+ },
249
+ label: template
250
+ }, parents);
174
251
  }
175
252
  if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child))) return unknown("Helper calls and dynamic expressions are not followed", parents);
176
253
  if (ts.isIdentifier(node) && node.text === context) return unknown("Workflow context aliases are not followed", parents);
package/dist/index.d.ts CHANGED
@@ -55,25 +55,36 @@ declare function registerWorkflows<const TWorkflows extends readonly AnyWorkflow
55
55
  type WorkflowGraphNodeDetails = {
56
56
  kind: "step";
57
57
  stepId: string;
58
+ } | {
59
+ kind: "parallel";
60
+ cardinality: "dynamic";
61
+ operation: {
62
+ kind: "step";
63
+ stepIdTemplate: string;
64
+ };
58
65
  } | {
59
66
  kind: "approve";
67
+ stepId: string;
60
68
  config: {
61
69
  title: string;
62
70
  description?: string;
63
71
  };
64
72
  } | {
65
73
  kind: "wait-for-event";
74
+ stepId: string;
66
75
  config: {
67
76
  event: string;
68
77
  deadline?: number;
69
78
  };
70
79
  } | {
71
80
  kind: "sleep";
81
+ stepId: string;
72
82
  config: {
73
83
  ms: number;
74
84
  };
75
85
  } | {
76
86
  kind: "sleep-until";
87
+ stepId: string;
77
88
  config: {
78
89
  timestamp: number;
79
90
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defineSchedule, c as weekly, i as registerWorkflows, n as createMiddleware, o as daily, r as createWorkflow, s as hourly, t as generateManifests } from "./generate-CKSL3f8L.js";
1
+ import { a as defineSchedule, c as weekly, i as registerWorkflows, n as createMiddleware, o as daily, r as createWorkflow, s as hourly, t as generateManifests } from "./generate-CVoNE4Kn.js";
2
2
  import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
3
3
  import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
4
4
  //#region src/stacks/tanstack/sse.ts
@@ -1,4 +1,4 @@
1
- import { loadTypeScript } from "./graph-CPDci8jW.js";
1
+ import { loadTypeScript } from "./graph-Bt-31WQT.js";
2
2
  //#region src/manifests/nested-operations.ts
3
3
  const durableMethods = [
4
4
  "step",
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as generateManifests } from "./generate-CKSL3f8L.js";
1
+ import { t as generateManifests } from "./generate-CVoNE4Kn.js";
2
2
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
3
  import { createServer } from "vite";
4
4
  import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile } from "node:fs/promises";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/workflows-sdk",
3
- "version": "0.0.0-dev.13",
3
+ "version": "0.0.0-dev.15",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",