@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.
- package/README.md +10 -9
- package/dist/{branch-metadata-IXuazOmY.js → branch-metadata-CZSd2-Zh.js} +1 -1
- package/dist/{context-escapes-x0J0HUgC.js → context-escapes-B0s8Zd-K.js} +1 -1
- package/dist/{duplicate-ids-NnTrnieX.js → duplicate-ids-DYq29CI7.js} +1 -1
- package/dist/generate-Cns4YbeL.js +6898 -0
- package/dist/{graph-Qx9mvqnC.js → graph-Bdvk16K9.js} +146 -83
- package/dist/index.d.ts +611 -124
- package/dist/index.js +1 -1
- package/dist/{nested-operations-DYVa5c5A.js → nested-operations-D1XKtDSh.js} +1 -1
- package/dist/{operation-descriptions-BLZC8bxV.js → operation-descriptions-bE60irWv.js} +1 -1
- package/dist/{step-metadata-MjyYQjOy.js → step-metadata-VvCbyokO.js} +1 -1
- package/dist/vite.js +3 -3
- package/package.json +2 -1
- package/dist/generate-DHIXkk21.js +0 -287
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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:
|
|
55
|
-
|
|
56
|
-
|
|
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:
|
|
60
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
title
|
|
264
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
}
|