@lovable.dev/workflows-sdk 0.0.0-dev.26 → 0.0.0-dev.28

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.
@@ -1,3 +1,4 @@
1
+ import { _ as WorkflowManifestUnknownNodeV1Schema, a as WorkflowManifestGraphEdgeV1Schema, b as create, c as WorkflowManifestLoopNodeV1Schema, d as WorkflowManifestParallelNodeV1Schema, f as WorkflowManifestRepeatedStepV1Schema, g as WorkflowManifestStepNodeV1Schema, h as WorkflowManifestStepExecutionPolicyV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestNowNodeV1Schema, m as WorkflowManifestSleepUntilNodeV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphNodeV1Schema, p as WorkflowManifestSleepNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphV1Schema, u as WorkflowManifestOrderEdgeV1Schema, v as WorkflowManifestUuidNodeV1Schema, y as WorkflowManifestWaitForEventNodeV1Schema } from "./generate-Cns4YbeL.js";
1
2
  import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
2
3
  //#region src/manifests/handler-source.ts
3
4
  const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
@@ -28,37 +29,43 @@ async function loadTypeScript() {
28
29
  }
29
30
  return loaded;
30
31
  }
31
- async function extractWorkflowGraph(handler) {
32
- const graph = {
32
+ async function extractWorkflowGraph(workflow) {
33
+ const graph = create(WorkflowManifestGraphV1Schema, {
33
34
  source: "inferred",
34
35
  scope: "handler",
35
36
  complete: true,
36
37
  nodes: [],
37
38
  edges: [],
38
39
  diagnostics: []
39
- };
40
- function addNode(node, parents) {
40
+ });
41
+ function addNode(label, kind, parents) {
41
42
  const id = `node-${graph.nodes.length}`;
42
- graph.nodes.push({
43
+ graph.nodes.push(create(WorkflowManifestGraphNodeV1Schema, {
43
44
  id,
44
- ...node
45
- });
45
+ label,
46
+ kind
47
+ }));
46
48
  const seen = /* @__PURE__ */ new Set();
47
49
  for (const parent of parents) {
48
50
  const key = JSON.stringify(parent);
49
51
  if (seen.has(key)) continue;
50
52
  seen.add(key);
51
- if (parent.kind === "order") graph.edges.push({
53
+ if (parent.kind === "order") graph.edges.push(create(WorkflowManifestGraphEdgeV1Schema, {
52
54
  source: parent.source,
53
55
  target: id,
54
- kind: "order"
55
- });
56
- else graph.edges.push({
56
+ kind: {
57
+ case: "order",
58
+ value: create(WorkflowManifestOrderEdgeV1Schema)
59
+ }
60
+ }));
61
+ else graph.edges.push(create(WorkflowManifestGraphEdgeV1Schema, {
57
62
  source: parent.source,
58
63
  target: id,
59
- kind: "branch",
60
- outcome: parent.outcome
61
- });
64
+ kind: {
65
+ case: "branch",
66
+ value: create(WorkflowManifestBranchEdgeV1Schema, { outcome: parent.outcome })
67
+ }
68
+ }));
62
69
  }
63
70
  return [{
64
71
  source: id,
@@ -71,9 +78,9 @@ async function extractWorkflowGraph(handler) {
71
78
  }
72
79
  function unknown(reason, parents) {
73
80
  degrade(reason);
74
- return addNode({
75
- kind: "unknown",
76
- label: reason
81
+ return addNode(reason, {
82
+ case: "unknown",
83
+ value: create(WorkflowManifestUnknownNodeV1Schema)
77
84
  }, parents);
78
85
  }
79
86
  const api = await loadTypeScript();
@@ -82,7 +89,7 @@ async function extractWorkflowGraph(handler) {
82
89
  return graph;
83
90
  }
84
91
  const ts = api;
85
- const handlerSource = workflowHandlerSource(handler);
92
+ const handlerSource = workflowHandlerSource(workflow.handler);
86
93
  if (!handlerSource) {
87
94
  unknown("Handler source is unavailable", []);
88
95
  return graph;
@@ -115,6 +122,14 @@ async function extractWorkflowGraph(handler) {
115
122
  const value = Number(node.text);
116
123
  return Number.isFinite(value) ? value : void 0;
117
124
  }
125
+ function runtimeRetry(retry) {
126
+ return {
127
+ maxAttempts: Math.min(4294967295, Math.max(1, Math.floor(retry?.maxAttempts ?? 1))),
128
+ retryBackoffStrategy: typeof retry?.backoff === "function" ? 3 : retry?.backoff === "fixed" ? 2 : 1,
129
+ retryBaseMs: retry?.baseMs ?? 500,
130
+ hasCustomShouldRetry: retry?.shouldRetry !== void 0
131
+ };
132
+ }
118
133
  function templateReference(node, parameters) {
119
134
  while (ts.isParenthesizedExpression(node)) node = node.expression;
120
135
  if (ts.isIdentifier(node)) return parameters.has(node.text) ? node.text : void 0;
@@ -222,6 +237,43 @@ async function extractWorkflowGraph(handler) {
222
237
  }
223
238
  };
224
239
  }
240
+ function stepExecutionPolicy(call) {
241
+ const options = readableOptions(call.arguments[2]);
242
+ const retryNode = option(options, "retry");
243
+ let retryPolicy = runtimeRetry(workflow.defaultStepRetry);
244
+ if (retryNode) {
245
+ const retryOptions = readableOptions(retryNode);
246
+ const maxAttemptsNode = option(retryOptions, "maxAttempts");
247
+ const maxAttempts = maxAttemptsNode === void 0 ? 1 : numberLiteral(maxAttemptsNode);
248
+ const backoffNode = option(retryOptions, "backoff");
249
+ const baseMsNode = option(retryOptions, "baseMs");
250
+ const baseMs = baseMsNode === void 0 ? 500 : numberLiteral(baseMsNode);
251
+ const shouldRetryNode = option(retryOptions, "shouldRetry");
252
+ const backoff = backoffNode === void 0 ? "exponential" : stringLiteral(backoffNode) ?? (ts.isArrowFunction(backoffNode) || ts.isFunctionExpression(backoffNode) || ts.isIdentifier(backoffNode) ? "custom" : void 0);
253
+ const supportedBackoff = backoff === "exponential" || backoff === "fixed" || backoff === "custom";
254
+ const customCondition = shouldRetryNode === void 0 ? false : ts.isArrowFunction(shouldRetryNode) || ts.isFunctionExpression(shouldRetryNode) || ts.isIdentifier(shouldRetryNode) ? true : void 0;
255
+ if (retryOptions && maxAttempts !== void 0 && baseMs !== void 0 && supportedBackoff && customCondition !== void 0) retryPolicy = {
256
+ maxAttempts: Math.min(4294967295, Math.max(1, Math.floor(maxAttempts))),
257
+ retryBackoffStrategy: backoff === "custom" ? 3 : backoff === "fixed" ? 2 : 1,
258
+ retryBaseMs: baseMs,
259
+ hasCustomShouldRetry: customCondition
260
+ };
261
+ else {
262
+ degrade("Dynamic step retry policies are not recorded");
263
+ return;
264
+ }
265
+ }
266
+ const timeoutNode = option(options, "timeout");
267
+ const timeoutMs = numberLiteral(timeoutNode);
268
+ if (timeoutNode !== void 0 && timeoutMs === void 0) {
269
+ degrade("Dynamic step timeouts are not recorded");
270
+ return;
271
+ }
272
+ return create(WorkflowManifestStepExecutionPolicyV1Schema, {
273
+ ...retryPolicy,
274
+ ...timeoutMs === void 0 || timeoutMs <= 0 ? {} : { timeoutMs }
275
+ });
276
+ }
225
277
  function operationDescription(options) {
226
278
  return stringLiteral(option(readableOptions(option(options, "meta")), "description"));
227
279
  }
@@ -237,11 +289,14 @@ async function extractWorkflowGraph(handler) {
237
289
  if (stepId === void 0) return unknown("Dynamic step IDs are not supported yet", parents);
238
290
  const metadata = stepMetadata(call);
239
291
  if (!metadata) return unknown("Step descriptions must be static strings", parents);
240
- return addNode({
241
- kind: "step",
242
- stepId,
243
- description: metadata.description,
244
- label: stepId
292
+ const executionPolicy = stepExecutionPolicy(call);
293
+ return addNode(stepId, {
294
+ case: "step",
295
+ value: create(WorkflowManifestStepNodeV1Schema, {
296
+ stepId,
297
+ description: metadata.description,
298
+ ...executionPolicy === void 0 ? {} : { executionPolicy }
299
+ })
245
300
  }, parents);
246
301
  }
247
302
  if (method === "approve") {
@@ -255,15 +310,13 @@ async function extractWorkflowGraph(handler) {
255
310
  if (stepId === void 0) return unknown("Dynamic approval IDs are not supported yet", parents);
256
311
  const description = stringLiteral(option(options, "description"));
257
312
  if (description === void 0) return unknown("Approval descriptions must be static strings", parents);
258
- return addNode({
259
- kind: "approve",
260
- stepId,
261
- description,
262
- config: {
263
- title,
264
- description
265
- },
266
- label: title
313
+ return addNode(title, {
314
+ case: "approve",
315
+ value: create(WorkflowManifestApproveNodeV1Schema, {
316
+ stepId,
317
+ description,
318
+ title
319
+ })
267
320
  }, parents);
268
321
  }
269
322
  if (method === "waitForEvent") {
@@ -280,15 +333,14 @@ async function extractWorkflowGraph(handler) {
280
333
  const given = option(options, "deadline");
281
334
  const deadline = numberLiteral(given);
282
335
  if (given && deadline === void 0) degrade("Dynamic waitForEvent deadlines are not recorded");
283
- return addNode({
284
- kind: "wait-for-event",
285
- stepId,
286
- description,
287
- config: {
336
+ return addNode(event, {
337
+ case: "waitForEvent",
338
+ value: create(WorkflowManifestWaitForEventNodeV1Schema, {
339
+ stepId,
340
+ description,
288
341
  event,
289
342
  ...deadline === void 0 ? {} : { deadline }
290
- },
291
- label: event
343
+ })
292
344
  }, parents);
293
345
  }
294
346
  if (method === "sleep") {
@@ -302,12 +354,13 @@ async function extractWorkflowGraph(handler) {
302
354
  if (stepId === void 0) return unknown("Dynamic sleep IDs are not supported yet", parents);
303
355
  const description = operationDescription(options);
304
356
  if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
305
- return addNode({
306
- kind: "sleep",
307
- stepId,
308
- description,
309
- config: { ms },
310
- label: `sleep ${ms}ms`
357
+ return addNode(`sleep ${ms}ms`, {
358
+ case: "sleep",
359
+ value: create(WorkflowManifestSleepNodeV1Schema, {
360
+ stepId,
361
+ description,
362
+ ms
363
+ })
311
364
  }, parents);
312
365
  }
313
366
  if (method === "sleepUntil") {
@@ -321,12 +374,13 @@ async function extractWorkflowGraph(handler) {
321
374
  if (stepId === void 0) return unknown("Dynamic sleepUntil IDs are not supported yet", parents);
322
375
  const description = operationDescription(options);
323
376
  if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
324
- return addNode({
325
- kind: "sleep-until",
326
- stepId,
327
- description,
328
- config: { timestamp },
329
- label: `sleep until ${timestamp}`
377
+ return addNode(`sleep until ${timestamp}`, {
378
+ case: "sleepUntil",
379
+ value: create(WorkflowManifestSleepUntilNodeV1Schema, {
380
+ stepId,
381
+ description,
382
+ timestamp
383
+ })
330
384
  }, parents);
331
385
  }
332
386
  const options = readableOptions(call.arguments[0]);
@@ -334,11 +388,18 @@ async function extractWorkflowGraph(handler) {
334
388
  if (stepId === void 0) return unknown(`Dynamic ${method} IDs are not supported yet`, parents);
335
389
  const description = operationDescription(options);
336
390
  if (description === void 0) return unknown(`${method} descriptions must be static strings`, parents);
337
- return addNode({
338
- kind: method,
339
- stepId,
340
- description,
341
- label: stepId
391
+ return addNode(stepId, method === "now" ? {
392
+ case: "now",
393
+ value: create(WorkflowManifestNowNodeV1Schema, {
394
+ stepId,
395
+ description
396
+ })
397
+ } : {
398
+ case: "uuid",
399
+ value: create(WorkflowManifestUuidNodeV1Schema, {
400
+ stepId,
401
+ description
402
+ })
342
403
  }, parents);
343
404
  }
344
405
  function path(tails, reachable = true) {
@@ -401,16 +462,17 @@ async function extractWorkflowGraph(handler) {
401
462
  const mapped = mappedStep(argument);
402
463
  if (mapped !== void 0) {
403
464
  const metadata = stepMetadata(mapped.call);
404
- const tails = metadata?.group ? addNode({
405
- kind: "parallel",
406
- groupId: metadata.group.id,
407
- cardinality: "dynamic",
408
- operation: {
409
- kind: "step",
410
- stepIdTemplate: mapped.template,
411
- description: metadata.description
412
- },
413
- label: metadata.group.label
465
+ const executionPolicy = stepExecutionPolicy(mapped.call);
466
+ const tails = metadata?.group ? addNode(metadata.group.label, {
467
+ case: "parallel",
468
+ value: create(WorkflowManifestParallelNodeV1Schema, {
469
+ groupId: metadata.group.id,
470
+ step: create(WorkflowManifestRepeatedStepV1Schema, {
471
+ stepIdTemplate: mapped.template,
472
+ description: metadata.description,
473
+ ...executionPolicy === void 0 ? {} : { executionPolicy }
474
+ })
475
+ })
414
476
  }, parents) : unknown("Dynamic parallel steps need static group metadata", parents);
415
477
  return {
416
478
  tails,
@@ -507,12 +569,13 @@ async function extractWorkflowGraph(handler) {
507
569
  const conditionFlow = expression(statement.expression, parents);
508
570
  const metadata = branchInfo(statement, branchDepth);
509
571
  const condition = statement.expression.getText(source);
510
- const branchTails = metadata ? addNode({
511
- kind: "branch",
512
- branchId: metadata.id,
513
- condition,
514
- description: metadata.description,
515
- label: metadata.description
572
+ const branchTails = metadata ? addNode(metadata.description, {
573
+ case: "branch",
574
+ value: create(WorkflowManifestBranchNodeV1Schema, {
575
+ branchId: metadata.id,
576
+ condition,
577
+ description: metadata.description
578
+ })
516
579
  }, conditionFlow.tails) : conditionFlow.tails;
517
580
  const sourceId = metadata ? branchTails[0]?.source : void 0;
518
581
  const thenParents = sourceId ? [{
@@ -556,17 +619,17 @@ async function extractWorkflowGraph(handler) {
556
619
  if (repeated) {
557
620
  const iterable = expression(statement.expression, parents);
558
621
  const metadata = stepMetadata(repeated.call);
559
- const tails = metadata?.group ? addNode({
560
- kind: "loop",
561
- groupId: metadata.group.id,
562
- cardinality: "dynamic",
563
- execution: "sequential",
564
- operation: {
565
- kind: "step",
566
- stepIdTemplate: repeated.template,
567
- description: metadata.description
568
- },
569
- label: metadata.group.label
622
+ const executionPolicy = stepExecutionPolicy(repeated.call);
623
+ const tails = metadata?.group ? addNode(metadata.group.label, {
624
+ case: "loop",
625
+ value: create(WorkflowManifestLoopNodeV1Schema, {
626
+ groupId: metadata.group.id,
627
+ step: create(WorkflowManifestRepeatedStepV1Schema, {
628
+ stepIdTemplate: repeated.template,
629
+ description: metadata.description,
630
+ ...executionPolicy === void 0 ? {} : { executionPolicy }
631
+ })
632
+ })
570
633
  }, iterable.tails) : unknown("Dynamic sequential steps need static group metadata", iterable.tails);
571
634
  return statementFlow(path(tails), mergePaths(iterable.thrown, path(tails)));
572
635
  }