@lovable.dev/workflows-sdk 0.0.0-dev.17 → 0.0.0-dev.19

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
@@ -317,19 +317,35 @@ step ID template `step-${item.id}` produces one dynamic parallel node labeled
317
317
  from `meta.group.label`. Returned step promises work too. Keep step IDs literal
318
318
  outside this mapped form.
319
319
 
320
+ An `if` whose body contains durable operations produces a `branch` node. Every
321
+ durable operation inside it includes an outer-to-inner `meta.branches` path;
322
+ each entry has a static `id` and agent-written `description`. Both sides of one
323
+ condition use the same entry. The AST determines nesting and whether an edge is
324
+ the `true` or `false` outcome, so metadata never declares topology. Branch IDs
325
+ identify one `if` statement within the workflow.
326
+
327
+ ```ts
328
+ meta: {
329
+ description: "Publish the approved draft",
330
+ branches: [{ id: "editor-approved", description: "The editor approved the draft" }],
331
+ }
332
+ ```
333
+
320
334
  | Field | Meaning |
321
335
  | --- | --- |
322
336
  | `nodes[].id` | Unique occurrence ID within this graph; use as the UI node key |
323
- | `nodes[].kind` | Durable operation, `parallel`, or `unknown` |
337
+ | `nodes[].kind` | Durable operation, `branch`, `parallel`, or `unknown` |
324
338
  | `nodes[].stepId` | Runtime durable ID for every statically known operation |
325
- | `nodes[].description` | User-facing description for every known durable operation |
339
+ | `nodes[].description` | User-facing description for every known durable operation and branch |
340
+ | `nodes[].branchId` | Stable ID for an inferred `if` node |
341
+ | `nodes[].condition` | Source expression from the corresponding `if` statement |
326
342
  | `nodes[].groupId` | Stable callsite ID for a dynamic parallel node |
327
343
  | `nodes[].cardinality` | `dynamic` for a runtime-sized parallel fan-out |
328
344
  | `nodes[].operation.kind` | Durable operation repeated by a parallel node |
329
345
  | `nodes[].operation.stepIdTemplate` | Display template for steps in a dynamic parallel node |
330
346
  | `nodes[].operation.description` | User-facing description shared by the repeated steps |
331
- | `nodes[].label` | Step ID, group label, or explanation of unsupported code |
332
- | `edges[]` | `{ source, target, kind: "order" }`, referencing node IDs |
347
+ | `nodes[].label` | Step ID, branch description, group label, or explanation of unsupported code |
348
+ | `edges[]` | Order edges or branch edges with an AST-derived boolean `outcome`, referencing node IDs |
333
349
  | `complete` | Whether the handler uses only supported syntax |
334
350
  | `diagnostics` | Reasons the graph is partial |
335
351
 
@@ -346,17 +362,23 @@ Graphs have `source: "inferred"` and `scope: "handler"`. They describe source
346
362
  structure, not run history or data dependencies, and exclude middleware and
347
363
  initialization. A mapped `Promise.all` is complete when its callback directly
348
364
  returns `ctx.step()` with a template-literal ID derived from a callback parameter.
349
- Other branches, loops, helper calls, dynamic step IDs, and unawaited steps produce
350
- `unknown` nodes and `complete: false`; steps inside unsupported code are not
351
- expanded. The UI should show these unknown nodes and mark partial graphs.
352
- Transforms that rewrite the handler may also produce a partial graph. A handler
353
- with no steps can have an empty graph.
365
+ Loops, switch statements, conditional expressions, helper calls, dynamic step IDs,
366
+ and unawaited steps produce `unknown` nodes and `complete: false`; steps inside
367
+ unsupported code are not expanded. The UI should show these unknown nodes and mark
368
+ partial graphs. Transforms that rewrite the handler may also produce a partial
369
+ graph. A handler with no steps can have an empty graph.
354
370
 
355
371
  A step body is one atomic execution unit. Manifest generation rejects statically
356
372
  visible durable calls inside it, including `ctx.step`, `ctx.sleep`, `ctx.now`,
357
373
  and the other `ctx.*` operations. Move each durable operation into the workflow
358
374
  handler and pass its result into the step instead.
359
375
 
376
+ Keep the workflow context in the handler. Manifest generation rejects passing,
377
+ aliasing, destructuring, or returning `ctx`, and rejects detached durable methods
378
+ such as `helper(ctx.step)`. Pass only extracted data such as `ctx.input` to
379
+ helpers instead. This keeps durable control flow visible in the handler source
380
+ used to build the graph.
381
+
360
382
  ## Steps endpoint (TanStack Start)
361
383
 
362
384
  The same `workflowsPlugin` that writes the manifests also emits
@@ -0,0 +1,110 @@
1
+ import { loadTypeScript } from "./graph-V2yqSs3X.js";
2
+ //#region src/manifests/branch-metadata.ts
3
+ const optionsArgument = {
4
+ step: 2,
5
+ approve: 0,
6
+ sleep: 1,
7
+ sleepUntil: 1,
8
+ waitForEvent: 1,
9
+ now: 0,
10
+ uuid: 0
11
+ };
12
+ async function findBranchMetadataIssues(handler) {
13
+ const api = await loadTypeScript();
14
+ if (!api) return [];
15
+ const ts = api;
16
+ const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
17
+ const declaration = source.statements[0];
18
+ const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
19
+ if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) return [];
20
+ const parameter = fn.parameters[0]?.name;
21
+ if (!parameter || !ts.isIdentifier(parameter)) return [];
22
+ const context = parameter.text;
23
+ function property(node, name) {
24
+ if (!node || !ts.isObjectLiteralExpression(node)) return void 0;
25
+ for (const entry of node.properties) {
26
+ if (!ts.isPropertyAssignment(entry)) continue;
27
+ if ((ts.isIdentifier(entry.name) || ts.isStringLiteral(entry.name) ? entry.name.text : void 0) === name) return entry.initializer;
28
+ }
29
+ }
30
+ function literalString(node) {
31
+ return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
32
+ }
33
+ function durableCall(node) {
34
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression) || !ts.isIdentifier(node.expression.expression) || node.expression.expression.text !== context || !(node.expression.name.text in optionsArgument)) return;
35
+ return {
36
+ call: node,
37
+ method: node.expression.name.text
38
+ };
39
+ }
40
+ function branchPath(call, method) {
41
+ const options = call.arguments[optionsArgument[method]];
42
+ const branches = property(property(options, "meta"), "branches");
43
+ if (!branches || !ts.isArrayLiteralExpression(branches)) return void 0;
44
+ const path = [];
45
+ for (const element of branches.elements) {
46
+ if (!ts.isObjectLiteralExpression(element)) return void 0;
47
+ const id = literalString(property(element, "id"));
48
+ const description = literalString(property(element, "description"));
49
+ if (id === void 0 || description === void 0) return void 0;
50
+ path.push({
51
+ id,
52
+ description
53
+ });
54
+ }
55
+ return path;
56
+ }
57
+ const issues = [];
58
+ const metadataByBranch = /* @__PURE__ */ new Map();
59
+ const branchById = /* @__PURE__ */ new Map();
60
+ function visit(node, branches) {
61
+ if (issues.length > 0) return;
62
+ if (ts.isIfStatement(node)) {
63
+ visit(node.expression, branches);
64
+ visit(node.thenStatement, [...branches, node]);
65
+ if (node.elseStatement) visit(node.elseStatement, [...branches, node]);
66
+ return;
67
+ }
68
+ const durable = durableCall(node);
69
+ if (durable) {
70
+ const path = branchPath(durable.call, durable.method);
71
+ const stepId = durable.method === "step" ? literalString(durable.call.arguments[0]) : void 0;
72
+ if (branches.length === 0 && path !== void 0 || branches.length > 0 && (path === void 0 || path.length !== branches.length)) {
73
+ issues.push({
74
+ kind: "path",
75
+ method: durable.method,
76
+ ...stepId === void 0 ? {} : { stepId }
77
+ });
78
+ return;
79
+ }
80
+ for (let index = 0; index < branches.length; index++) {
81
+ const branch = branches[index];
82
+ const entry = path?.[index];
83
+ if (!branch || !entry) continue;
84
+ const existing = metadataByBranch.get(branch);
85
+ if (existing && (existing.id !== entry.id || existing.description !== entry.description)) {
86
+ issues.push({
87
+ kind: "inconsistent",
88
+ branchId: existing.id
89
+ });
90
+ return;
91
+ }
92
+ const existingNode = branchById.get(entry.id);
93
+ if (existingNode && existingNode !== branch) {
94
+ issues.push({
95
+ kind: "duplicate-id",
96
+ branchId: entry.id
97
+ });
98
+ return;
99
+ }
100
+ metadataByBranch.set(branch, entry);
101
+ branchById.set(entry.id, branch);
102
+ }
103
+ }
104
+ ts.forEachChild(node, (child) => visit(child, branches));
105
+ }
106
+ visit(fn, []);
107
+ return issues;
108
+ }
109
+ //#endregion
110
+ export { findBranchMetadataIssues };
@@ -0,0 +1,77 @@
1
+ import { loadTypeScript } from "./graph-V2yqSs3X.js";
2
+ //#region src/manifests/context-escapes.ts
3
+ const durableMethods = /* @__PURE__ */ new Set([
4
+ "step",
5
+ "approve",
6
+ "waitForEvent",
7
+ "sleep",
8
+ "sleepUntil",
9
+ "now",
10
+ "uuid"
11
+ ]);
12
+ async function findWorkflowContextEscapes(handler) {
13
+ const api = await loadTypeScript();
14
+ if (!api) return [];
15
+ const ts = api;
16
+ const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
17
+ const declaration = source.statements[0];
18
+ const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
19
+ if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) return [];
20
+ const parameter = fn.parameters[0]?.name;
21
+ if (!parameter) return [];
22
+ if (!ts.isIdentifier(parameter)) return [{ kind: "destructured" }];
23
+ const context = parameter.text;
24
+ function bindingContains(node, name) {
25
+ if (ts.isIdentifier(node)) return node.text === name;
26
+ return node.elements.some((element) => !ts.isOmittedExpression(element) && bindingContains(element.name, name));
27
+ }
28
+ function contextMethod(node) {
29
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === context) return node.name.text;
30
+ if (ts.isElementAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === context && node.argumentExpression && (ts.isStringLiteral(node.argumentExpression) || ts.isNoSubstitutionTemplateLiteral(node.argumentExpression))) return node.argumentExpression.text;
31
+ }
32
+ function directCallTarget(node) {
33
+ let target = node;
34
+ while (ts.isParenthesizedExpression(target.parent)) target = target.parent;
35
+ return ts.isCallExpression(target.parent) && target.parent.expression === target;
36
+ }
37
+ function identifierIsValue(node) {
38
+ const parent = node.parent;
39
+ if (parent.name === node && !ts.isShorthandPropertyAssignment(parent)) return false;
40
+ return parent.label !== node;
41
+ }
42
+ const escapes = [];
43
+ const visit = (node, shadowed) => {
44
+ if (escapes.length > 0) return;
45
+ if (node !== fn && ts.isFunctionLike(node)) {
46
+ const hidesContext = node.parameters.some((item) => bindingContains(item.name, context));
47
+ ts.forEachChild(node, (child) => visit(child, shadowed || hidesContext));
48
+ return;
49
+ }
50
+ if (!shadowed) {
51
+ const method = contextMethod(node);
52
+ if (method && durableMethods.has(method) && !directCallTarget(node)) {
53
+ escapes.push({
54
+ kind: "method",
55
+ context,
56
+ method
57
+ });
58
+ return;
59
+ }
60
+ if (ts.isIdentifier(node) && node.text === context && identifierIsValue(node)) {
61
+ const parent = node.parent;
62
+ if (!((ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === node)) {
63
+ escapes.push({
64
+ kind: "context",
65
+ context
66
+ });
67
+ return;
68
+ }
69
+ }
70
+ }
71
+ ts.forEachChild(node, (child) => visit(child, shadowed));
72
+ };
73
+ visit(fn.body, false);
74
+ return escapes;
75
+ }
76
+ //#endregion
77
+ export { findWorkflowContextEscapes };
@@ -1,5 +1,5 @@
1
1
  import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
2
- import { loadTypeScript } from "./graph-DW4JTyGa.js";
2
+ import { loadTypeScript } from "./graph-V2yqSs3X.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,15 +183,21 @@ function serializeSchema(schema, direction, label) {
183
183
  }
184
184
  }
185
185
  async function generateManifests(definition) {
186
- const { extractWorkflowGraph } = await import("./graph-DW4JTyGa.js");
187
- const { findDuplicateOperationIds } = await import("./duplicate-ids-DeCwJVrP.js");
188
- const { findNestedDurableOperations } = await import("./nested-operations-CPCNe0xy.js");
189
- const { findOperationDescriptionIssues } = await import("./operation-descriptions-BalrfRnU.js");
190
- const { findStepMetadataIssues } = await import("./step-metadata-CIGA9vth.js");
186
+ const { extractWorkflowGraph } = await import("./graph-V2yqSs3X.js");
187
+ const { findBranchMetadataIssues } = await import("./branch-metadata-DeUhEFah.js");
188
+ const { findWorkflowContextEscapes } = await import("./context-escapes-DRzfr4f6.js");
189
+ const { findDuplicateOperationIds } = await import("./duplicate-ids-BSJNfUhh.js");
190
+ const { findNestedDurableOperations } = await import("./nested-operations-DsecXS12.js");
191
+ const { findOperationDescriptionIssues } = await import("./operation-descriptions-C_f87Bmr.js");
192
+ const { findStepMetadataIssues } = await import("./step-metadata-D4OpY6r1.js");
191
193
  const collection = registerWorkflows(definition);
192
194
  const manifests = [];
193
195
  for (const workflow of collection.workflows) {
194
196
  if (workflow.previousVersions?.length) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" previousVersions are not supported yet`);
197
+ const contextEscape = (await findWorkflowContextEscapes(workflow.handler))[0];
198
+ if (contextEscape?.kind === "destructured") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" destructures its workflow context parameter; accept one context identifier and read its properties directly in the workflow handler`);
199
+ if (contextEscape?.kind === "method") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context}.${contextEscape.method} as a value; durable context methods must be called directly in the workflow handler`);
200
+ if (contextEscape?.kind === "context") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context} as a value; the workflow context cannot be passed or aliased, so pass only extracted values such as ${contextEscape.context}.input to helpers`);
195
201
  const nested = (await findNestedDurableOperations(workflow.handler))[0];
196
202
  if (nested) {
197
203
  const parent = nested.parentStepId ? `ctx.step(${JSON.stringify(nested.parentStepId)})` : "ctx.step()";
@@ -221,6 +227,13 @@ async function generateManifests(definition) {
221
227
  const description = method === "approve" ? "{ description: \"...\" }" : "{ meta: { description: \"...\" } }";
222
228
  throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ctx.${method}() must include a static ${description}`);
223
229
  }
230
+ const branchMetadataIssue = (await findBranchMetadataIssues(workflow.handler))[0];
231
+ if (branchMetadataIssue?.kind === "path") {
232
+ const operation = branchMetadataIssue.method === "step" && branchMetadataIssue.stepId ? `ctx.step(${JSON.stringify(branchMetadataIssue.stepId)})` : `ctx.${branchMetadataIssue.method}()`;
233
+ throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${operation} must include a static meta.branches path matching its enclosing if/else branches; each entry needs { id, description }`);
234
+ }
235
+ if (branchMetadataIssue?.kind === "inconsistent") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses inconsistent metadata for branch ${JSON.stringify(branchMetadataIssue.branchId)}; every operation under one if statement must use the same branch id and description`);
236
+ if (branchMetadataIssue?.kind === "duplicate-id") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses branch id ${JSON.stringify(branchMetadataIssue.branchId)} for more than one if statement; every branch id must identify one condition`);
224
237
  const metadata = {
225
238
  id: workflow.id,
226
239
  ...workflow.description === void 0 ? {} : { description: workflow.description },
@@ -36,12 +36,27 @@ async function extractWorkflowGraph(handler) {
36
36
  id,
37
37
  ...node
38
38
  });
39
- for (const parent of new Set(parents)) graph.edges.push({
40
- source: parent,
41
- target: id,
39
+ const seen = /* @__PURE__ */ new Set();
40
+ for (const parent of parents) {
41
+ const key = JSON.stringify(parent);
42
+ if (seen.has(key)) continue;
43
+ seen.add(key);
44
+ if (parent.kind === "order") graph.edges.push({
45
+ source: parent.source,
46
+ target: id,
47
+ kind: "order"
48
+ });
49
+ else graph.edges.push({
50
+ source: parent.source,
51
+ target: id,
52
+ kind: "branch",
53
+ outcome: parent.outcome
54
+ });
55
+ }
56
+ return [{
57
+ source: id,
42
58
  kind: "order"
43
- });
44
- return [id];
59
+ }];
45
60
  }
46
61
  function degrade(reason) {
47
62
  graph.complete = false;
@@ -134,6 +149,30 @@ async function extractWorkflowGraph(handler) {
134
149
  if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
135
150
  }
136
151
  }
152
+ function branchMetadata(meta) {
153
+ const branches = option(meta, "branches");
154
+ if (!branches || !ts.isArrayLiteralExpression(branches)) return void 0;
155
+ const path = [];
156
+ for (const element of branches.elements) {
157
+ const entry = readableOptions(element);
158
+ const id = stringLiteral(option(entry, "id"));
159
+ const description = stringLiteral(option(entry, "description"));
160
+ if (id === void 0 || description === void 0) return void 0;
161
+ path.push({
162
+ id,
163
+ description
164
+ });
165
+ }
166
+ return path;
167
+ }
168
+ function operationMeta(call) {
169
+ const method = call.expression.name.text;
170
+ const optionsIndex = method === "step" ? 2 : method === "sleep" || method === "sleepUntil" || method === "waitForEvent" ? 1 : 0;
171
+ return readableOptions(option(readableOptions(call.arguments[optionsIndex]), "meta"));
172
+ }
173
+ function operationBranches(call) {
174
+ return branchMetadata(operationMeta(call));
175
+ }
137
176
  function stepMetadata(call) {
138
177
  const meta = readableOptions(option(readableOptions(call.arguments[2]), "meta"));
139
178
  const description = stringLiteral(option(meta, "description"));
@@ -309,25 +348,110 @@ async function extractWorkflowGraph(handler) {
309
348
  if (ts.isIdentifier(node) && node.text === context) return unknown("Workflow context aliases are not followed", parents);
310
349
  return parents;
311
350
  }
312
- let tails = [];
313
- if (!ts.isBlock(fn.body)) {
314
- expression(fn.body, tails, true);
315
- return graph;
351
+ function branchInfo(statement, depth) {
352
+ let result;
353
+ const visit = (node) => {
354
+ if (result) return;
355
+ if (durableCall(node)) {
356
+ result = operationBranches(node)?.[depth];
357
+ return;
358
+ }
359
+ ts.forEachChild(node, visit);
360
+ };
361
+ visit(statement.thenStatement);
362
+ if (statement.elseStatement) visit(statement.elseStatement);
363
+ return result;
364
+ }
365
+ function statements(items, parents, branchDepth) {
366
+ let flow = {
367
+ tails: parents,
368
+ fallsThrough: true
369
+ };
370
+ for (const statement of items) {
371
+ if (!flow.fallsThrough) break;
372
+ flow = walkStatement(statement, flow.tails, branchDepth);
373
+ }
374
+ return flow;
316
375
  }
317
- for (const statement of fn.body.statements) {
376
+ function walkStatement(statement, parents, branchDepth) {
377
+ if (ts.isBlock(statement)) return statements(statement.statements, parents, branchDepth);
318
378
  if (ts.isReturnStatement(statement)) {
319
- if (statement.expression) expression(statement.expression, tails, true);
320
- break;
379
+ if (statement.expression) expression(statement.expression, parents, true);
380
+ return {
381
+ tails: [],
382
+ fallsThrough: false
383
+ };
384
+ }
385
+ if (ts.isThrowStatement(statement)) {
386
+ expression(statement.expression, parents);
387
+ return {
388
+ tails: [],
389
+ fallsThrough: false
390
+ };
321
391
  }
322
392
  if (ts.isVariableStatement(statement)) {
323
- if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context)))) {
324
- tails = unknown("Shadowed context or Promise bindings are not supported yet", tails);
325
- break;
326
- }
393
+ if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context)))) return {
394
+ tails: unknown("Shadowed context or Promise bindings are not supported yet", parents),
395
+ fallsThrough: false
396
+ };
397
+ let tails = parents;
327
398
  for (const item of statement.declarationList.declarations) if (item.initializer) tails = expression(item.initializer, tails);
328
- } else if (ts.isExpressionStatement(statement)) tails = expression(statement.expression, tails);
329
- else tails = unknown("Branches, loops, and other control flow are not supported yet", tails);
399
+ return {
400
+ tails,
401
+ fallsThrough: true
402
+ };
403
+ }
404
+ if (ts.isExpressionStatement(statement)) return {
405
+ tails: expression(statement.expression, parents),
406
+ fallsThrough: true
407
+ };
408
+ if (ts.isIfStatement(statement)) {
409
+ const conditionTails = expression(statement.expression, parents);
410
+ const metadata = branchInfo(statement, branchDepth);
411
+ const condition = statement.expression.getText(source);
412
+ const branchTails = metadata ? addNode({
413
+ kind: "branch",
414
+ branchId: metadata.id,
415
+ condition,
416
+ description: metadata.description,
417
+ label: metadata.description
418
+ }, conditionTails) : conditionTails;
419
+ const sourceId = metadata ? branchTails[0]?.source : void 0;
420
+ const thenParents = sourceId ? [{
421
+ source: sourceId,
422
+ kind: "branch",
423
+ outcome: true
424
+ }] : branchTails;
425
+ const elseParents = sourceId ? [{
426
+ source: sourceId,
427
+ kind: "branch",
428
+ outcome: false
429
+ }] : branchTails;
430
+ const thenFlow = walkStatement(statement.thenStatement, thenParents, branchDepth + 1);
431
+ const elseFlow = statement.elseStatement ? walkStatement(statement.elseStatement, elseParents, branchDepth + 1) : {
432
+ tails: elseParents,
433
+ fallsThrough: true
434
+ };
435
+ return {
436
+ tails: [...thenFlow.fallsThrough ? thenFlow.tails : [], ...elseFlow.fallsThrough ? elseFlow.tails : []],
437
+ fallsThrough: thenFlow.fallsThrough || elseFlow.fallsThrough
438
+ };
439
+ }
440
+ if (ts.isEmptyStatement(statement)) return {
441
+ tails: parents,
442
+ fallsThrough: true
443
+ };
444
+ return {
445
+ tails: unknown("Loops and other control flow are not supported yet", parents),
446
+ fallsThrough: true
447
+ };
448
+ }
449
+ const tails = [];
450
+ if (!ts.isBlock(fn.body)) {
451
+ expression(fn.body, tails, true);
452
+ return graph;
330
453
  }
454
+ statements(fn.body.statements, tails, 0);
331
455
  return graph;
332
456
  }
333
457
  //#endregion
package/dist/index.d.ts CHANGED
@@ -56,8 +56,13 @@ interface WorkflowStepGroup {
56
56
  id: string;
57
57
  label: string;
58
58
  }
59
+ interface WorkflowBranchMetadata {
60
+ id: string;
61
+ description: string;
62
+ }
59
63
  type WorkflowOperationMetadata = Record<string, unknown> & {
60
64
  description: string;
65
+ branches?: WorkflowBranchMetadata[];
61
66
  };
62
67
  type WorkflowStepMetadata = WorkflowOperationMetadata & {
63
68
  group?: WorkflowStepGroup;
@@ -115,6 +120,11 @@ type WorkflowGraphNodeDetails = {
115
120
  kind: "uuid";
116
121
  stepId: string;
117
122
  description: string;
123
+ } | {
124
+ kind: "branch";
125
+ branchId: string;
126
+ condition: string;
127
+ description: string;
118
128
  } | {
119
129
  kind: "unknown";
120
130
  };
@@ -122,16 +132,22 @@ type WorkflowGraphNode = {
122
132
  id: string;
123
133
  label: string;
124
134
  } & WorkflowGraphNodeDetails;
135
+ type WorkflowGraphEdge = {
136
+ source: string;
137
+ target: string;
138
+ kind: "order";
139
+ } | {
140
+ source: string;
141
+ target: string;
142
+ kind: "branch";
143
+ outcome: boolean;
144
+ };
125
145
  interface WorkflowGraph {
126
146
  source: "inferred";
127
147
  scope: "handler";
128
148
  complete: boolean;
129
149
  nodes: WorkflowGraphNode[];
130
- edges: {
131
- source: string;
132
- target: string;
133
- kind: "order";
134
- }[];
150
+ edges: WorkflowGraphEdge[];
135
151
  diagnostics: string[];
136
152
  }
137
153
  //#endregion
@@ -302,4 +318,4 @@ declare function createStepsHandler(collection: WorkflowCollection, options?: St
302
318
  */
303
319
  declare function toServerSentEventsResponse(events: AsyncIterable<WorkflowEvent>): Response;
304
320
  //#endregion
305
- export { type AnyWorkflowDefinition, type Cadence, type Ctx, type MemoEntry, type OverlapPolicy, type ReplayOutcome, type ResolvedSchedule, type ResolvedTrigger, type ScheduleDefinition, type StepContext, type StepIntent, type StepKind, type StepOptions, type StepReference, type StepResult, type StepsDisposition, type StepsHandler, type StepsHandlerOptions, type StepsRequest, type StepsResponse, type TanStackWorkflowHandler, type TanStackWorkflowHandlerOptions, type TriggerDefinition, type Weekday, type WorkflowCollection, type WorkflowDefinition, type WorkflowGraph, type WorkflowGraphNode, type WorkflowGraphNodeDetails, type WorkflowInput, type WorkflowManifest, type WorkflowOperationMetadata, type WorkflowOutput, type WorkflowState, type WorkflowStepGroup, type WorkflowStepMetadata, type WorkflowsDefinition, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
321
+ export { type AnyWorkflowDefinition, type Cadence, type Ctx, type MemoEntry, type OverlapPolicy, type ReplayOutcome, type ResolvedSchedule, type ResolvedTrigger, type ScheduleDefinition, type StepContext, type StepIntent, type StepKind, type StepOptions, type StepReference, type StepResult, type StepsDisposition, type StepsHandler, type StepsHandlerOptions, type StepsRequest, type StepsResponse, type TanStackWorkflowHandler, type TanStackWorkflowHandlerOptions, type TriggerDefinition, type Weekday, type WorkflowBranchMetadata, type WorkflowCollection, type WorkflowDefinition, type WorkflowGraph, type WorkflowGraphEdge, type WorkflowGraphNode, type WorkflowGraphNodeDetails, type WorkflowInput, type WorkflowManifest, type WorkflowOperationMetadata, type WorkflowOutput, type WorkflowState, type WorkflowStepGroup, type WorkflowStepMetadata, type WorkflowsDefinition, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
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-B-owFpem.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-CLOdvpgq.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-DW4JTyGa.js";
1
+ import { loadTypeScript } from "./graph-V2yqSs3X.js";
2
2
  //#region src/manifests/nested-operations.ts
3
3
  const durableMethods = [
4
4
  "step",
@@ -1,4 +1,4 @@
1
- import { loadTypeScript } from "./graph-DW4JTyGa.js";
1
+ import { loadTypeScript } from "./graph-V2yqSs3X.js";
2
2
  //#region src/manifests/operation-descriptions.ts
3
3
  const optionsArgument = {
4
4
  approve: 0,
@@ -1,4 +1,4 @@
1
- import { loadTypeScript } from "./graph-DW4JTyGa.js";
1
+ import { loadTypeScript } from "./graph-V2yqSs3X.js";
2
2
  //#region src/manifests/step-metadata.ts
3
3
  async function findStepMetadataIssues(handler) {
4
4
  const api = await loadTypeScript();
package/dist/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as generateManifests } from "./generate-B-owFpem.js";
1
+ import { t as generateManifests } from "./generate-CLOdvpgq.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.17",
3
+ "version": "0.0.0-dev.19",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",