@lovable.dev/workflows-sdk 0.0.0-dev.5 → 0.0.0-dev.52
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 +184 -317
- package/dist/branch-metadata-DIu0sMPS.js +113 -0
- package/dist/context-escapes-CMZlpkct.js +80 -0
- package/dist/duplicate-ids-DiBCVnwz.js +105 -0
- package/dist/durable-ids-Cx341nJQ.js +17 -0
- package/dist/generate-C9MJlJBn.js +6958 -0
- package/dist/graph-RIBcr2Xd.js +791 -0
- package/dist/index.d.ts +970 -103
- package/dist/index.js +802 -16
- package/dist/llm-validation-DdDO6csU.js +61 -0
- package/dist/nested-operations-xQdnHHR7.js +60 -0
- package/dist/operation-descriptions-BGSwAA0h.js +47 -0
- package/dist/step-metadata-CzUMB8XT.js +105 -0
- package/dist/vite.d.ts +3 -7
- package/dist/vite.js +143 -29
- package/dist/wait-deadlines-Dg0U2ZK5.js +63 -0
- package/dist/wait-deadlines-DpK-Fgnd.js +4 -0
- package/package.json +6 -7
- package/dist/generate-IXn3QGVb.js +0 -333
- package/dist/graph-BgdiEUHq.js +0 -201
- package/dist/stacks/tanstack/index.d.ts +0 -31
- package/dist/stacks/tanstack/index.js +0 -99
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
import { C as WorkflowManifestWaitForEventNodeV1Schema, S as WorkflowManifestUuidNodeV1Schema, _ as WorkflowManifestSleepNodeV1Schema, a as WorkflowManifestConnectorNodeV1Schema, b as WorkflowManifestStepNodeV1Schema, c as WorkflowManifestGraphV1Schema, d as WorkflowManifestNowNodeV1Schema, f as WorkflowManifestOrderEdgeV1Schema, g as WorkflowManifestRepeatedStepV1Schema, h as WorkflowManifestRepeatedLlmV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestLlmNodeV1Schema, m as WorkflowManifestRepeatedConnectorV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphEdgeV1Schema, p as WorkflowManifestParallelNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphNodeV1Schema, u as WorkflowManifestLoopNodeV1Schema, v as WorkflowManifestSleepUntilNodeV1Schema, w as create, x as WorkflowManifestUnknownNodeV1Schema, y as WorkflowManifestStepExecutionPolicyV1Schema } from "./generate-C9MJlJBn.js";
|
|
2
|
+
import { n as assertLlmOptions, t as assertLlmModel } from "./llm-validation-DdDO6csU.js";
|
|
3
|
+
//#region src/manifests/handler-source.ts
|
|
4
|
+
const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
|
|
5
|
+
function workflowHandlerSource(handler) {
|
|
6
|
+
const source = Function.prototype.toString.call(handler);
|
|
7
|
+
return nativeFunctionSource.test(source) ? void 0 : source;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/manifests/graph.ts
|
|
11
|
+
const durableMethods = {
|
|
12
|
+
step: 0,
|
|
13
|
+
llm: 0,
|
|
14
|
+
connector: 0,
|
|
15
|
+
approve: 0,
|
|
16
|
+
waitForEvent: 0,
|
|
17
|
+
sleep: 0,
|
|
18
|
+
sleepUntil: 0,
|
|
19
|
+
now: 0,
|
|
20
|
+
uuid: 0
|
|
21
|
+
};
|
|
22
|
+
let loaded;
|
|
23
|
+
async function loadTypeScript() {
|
|
24
|
+
if (loaded !== void 0) return loaded;
|
|
25
|
+
try {
|
|
26
|
+
const module = await import("typescript");
|
|
27
|
+
const api = module.default ?? module;
|
|
28
|
+
loaded = typeof api?.createSourceFile === "function" ? api : null;
|
|
29
|
+
} catch {
|
|
30
|
+
loaded = null;
|
|
31
|
+
}
|
|
32
|
+
return loaded;
|
|
33
|
+
}
|
|
34
|
+
async function extractWorkflowGraph(workflow) {
|
|
35
|
+
const graph = create(WorkflowManifestGraphV1Schema, {
|
|
36
|
+
source: "inferred",
|
|
37
|
+
scope: "handler",
|
|
38
|
+
complete: true,
|
|
39
|
+
nodes: [],
|
|
40
|
+
edges: [],
|
|
41
|
+
diagnostics: []
|
|
42
|
+
});
|
|
43
|
+
function addNode(label, kind, parents) {
|
|
44
|
+
const id = `node-${graph.nodes.length}`;
|
|
45
|
+
graph.nodes.push(create(WorkflowManifestGraphNodeV1Schema, {
|
|
46
|
+
id,
|
|
47
|
+
label,
|
|
48
|
+
kind
|
|
49
|
+
}));
|
|
50
|
+
const seen = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const parent of parents) {
|
|
52
|
+
const key = JSON.stringify(parent);
|
|
53
|
+
if (seen.has(key)) continue;
|
|
54
|
+
seen.add(key);
|
|
55
|
+
if (parent.kind === "order") graph.edges.push(create(WorkflowManifestGraphEdgeV1Schema, {
|
|
56
|
+
source: parent.source,
|
|
57
|
+
target: id,
|
|
58
|
+
kind: {
|
|
59
|
+
case: "order",
|
|
60
|
+
value: create(WorkflowManifestOrderEdgeV1Schema)
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
else graph.edges.push(create(WorkflowManifestGraphEdgeV1Schema, {
|
|
64
|
+
source: parent.source,
|
|
65
|
+
target: id,
|
|
66
|
+
kind: {
|
|
67
|
+
case: "branch",
|
|
68
|
+
value: create(WorkflowManifestBranchEdgeV1Schema, { outcome: parent.outcome })
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
return [{
|
|
73
|
+
source: id,
|
|
74
|
+
kind: "order"
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
function degrade(reason) {
|
|
78
|
+
graph.complete = false;
|
|
79
|
+
if (!graph.diagnostics.includes(reason)) graph.diagnostics.push(reason);
|
|
80
|
+
}
|
|
81
|
+
function unknown(reason, parents) {
|
|
82
|
+
degrade(reason);
|
|
83
|
+
return addNode(reason, {
|
|
84
|
+
case: "unknown",
|
|
85
|
+
value: create(WorkflowManifestUnknownNodeV1Schema)
|
|
86
|
+
}, parents);
|
|
87
|
+
}
|
|
88
|
+
const api = await loadTypeScript();
|
|
89
|
+
if (!api) {
|
|
90
|
+
unknown("Install typescript to infer step graphs", []);
|
|
91
|
+
return graph;
|
|
92
|
+
}
|
|
93
|
+
const ts = api;
|
|
94
|
+
const handlerSource = workflowHandlerSource(workflow.handler);
|
|
95
|
+
if (!handlerSource) {
|
|
96
|
+
unknown("Handler source is unavailable", []);
|
|
97
|
+
return graph;
|
|
98
|
+
}
|
|
99
|
+
const source = ts.createSourceFile("handler.js", `const handler = ${handlerSource};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
|
|
100
|
+
const declaration = source.statements[0];
|
|
101
|
+
const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
|
|
102
|
+
if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) {
|
|
103
|
+
unknown("Handler source is unavailable", []);
|
|
104
|
+
return graph;
|
|
105
|
+
}
|
|
106
|
+
const parameter = fn.parameters[0]?.name;
|
|
107
|
+
if (parameter && !ts.isIdentifier(parameter)) {
|
|
108
|
+
unknown("Destructured workflow context is not supported yet", []);
|
|
109
|
+
return graph;
|
|
110
|
+
}
|
|
111
|
+
const context = parameter?.text;
|
|
112
|
+
const recordedCalls = /* @__PURE__ */ new Set();
|
|
113
|
+
function operationError(method, message) {
|
|
114
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ctx.${method}() ${message}`);
|
|
115
|
+
}
|
|
116
|
+
function llmError(message) {
|
|
117
|
+
operationError("llm", message);
|
|
118
|
+
}
|
|
119
|
+
function contains(node, predicate, skipFunctions = false) {
|
|
120
|
+
if (skipFunctions && ts.isFunctionLike(node)) return false;
|
|
121
|
+
return predicate(node) || Boolean(ts.forEachChild(node, (child) => contains(child, predicate, skipFunctions) || void 0));
|
|
122
|
+
}
|
|
123
|
+
function durableCall(node) {
|
|
124
|
+
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text in durableMethods;
|
|
125
|
+
}
|
|
126
|
+
function stringLiteral(node) {
|
|
127
|
+
return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
|
|
128
|
+
}
|
|
129
|
+
function numberLiteral(node) {
|
|
130
|
+
if (!node || !ts.isNumericLiteral(node)) return void 0;
|
|
131
|
+
const value = Number(node.text);
|
|
132
|
+
return Number.isFinite(value) ? value : void 0;
|
|
133
|
+
}
|
|
134
|
+
function runtimeRetry(retry) {
|
|
135
|
+
return {
|
|
136
|
+
maxAttempts: Math.min(4294967295, Math.max(1, Math.floor(retry?.maxAttempts ?? 1))),
|
|
137
|
+
retryBackoffStrategy: typeof retry?.backoff === "function" ? 3 : retry?.backoff === "fixed" ? 2 : 1,
|
|
138
|
+
retryBaseMs: retry?.baseMs ?? 500,
|
|
139
|
+
hasCustomShouldRetry: retry?.shouldRetry !== void 0
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function templateReference(node, parameters) {
|
|
143
|
+
while (ts.isParenthesizedExpression(node)) node = node.expression;
|
|
144
|
+
if (ts.isIdentifier(node)) return parameters.has(node.text) ? node.text : void 0;
|
|
145
|
+
if (ts.isPropertyAccessExpression(node) && !node.questionDotToken) {
|
|
146
|
+
const expression = templateReference(node.expression, parameters);
|
|
147
|
+
return expression === void 0 ? void 0 : `${expression}.${node.name.text}`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function stepIdTemplate(node, parameters) {
|
|
151
|
+
if (!node || !ts.isTemplateExpression(node)) return void 0;
|
|
152
|
+
let template = node.head.text;
|
|
153
|
+
for (const span of node.templateSpans) {
|
|
154
|
+
const reference = templateReference(span.expression, parameters);
|
|
155
|
+
if (reference === void 0) return void 0;
|
|
156
|
+
template += `{${reference}}${span.literal.text}`;
|
|
157
|
+
}
|
|
158
|
+
return template;
|
|
159
|
+
}
|
|
160
|
+
function repeatedOperation(call, parameters) {
|
|
161
|
+
if (!durableCall(call)) return void 0;
|
|
162
|
+
const method = call.expression.name.text;
|
|
163
|
+
if (method !== "step" && method !== "llm" && method !== "connector") return void 0;
|
|
164
|
+
const template = stepIdTemplate(method === "llm" ? option(readableOptions(call.arguments[1]), "id") : call.arguments[0], parameters);
|
|
165
|
+
return template === void 0 ? void 0 : {
|
|
166
|
+
call,
|
|
167
|
+
template
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function mappedStep(node) {
|
|
171
|
+
while (ts.isParenthesizedExpression(node)) node = node.expression;
|
|
172
|
+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression) || node.expression.name.text !== "map" || node.arguments.length !== 1) return;
|
|
173
|
+
const callback = node.arguments[0];
|
|
174
|
+
if (!ts.isArrowFunction(callback) && !ts.isFunctionExpression(callback)) return void 0;
|
|
175
|
+
const parameters = new Set(callback.parameters.flatMap((parameter) => ts.isIdentifier(parameter.name) ? [parameter.name.text] : []));
|
|
176
|
+
let body;
|
|
177
|
+
if (ts.isBlock(callback.body)) {
|
|
178
|
+
const statement = callback.body.statements.length === 1 ? callback.body.statements[0] : void 0;
|
|
179
|
+
body = statement && ts.isReturnStatement(statement) ? statement.expression : void 0;
|
|
180
|
+
} else body = callback.body;
|
|
181
|
+
while (body && (ts.isParenthesizedExpression(body) || ts.isAwaitExpression(body))) body = body.expression;
|
|
182
|
+
return body ? repeatedOperation(body, parameters) : void 0;
|
|
183
|
+
}
|
|
184
|
+
function sequentialLoopStep(node) {
|
|
185
|
+
if (node.awaitModifier || !ts.isVariableDeclarationList(node.initializer)) return void 0;
|
|
186
|
+
const declarations = node.initializer.declarations;
|
|
187
|
+
if (declarations.length !== 1) return void 0;
|
|
188
|
+
const declaration = declarations[0];
|
|
189
|
+
if (!ts.isIdentifier(declaration.name) || declaration.initializer) return void 0;
|
|
190
|
+
let statement = node.statement;
|
|
191
|
+
if (ts.isBlock(statement)) statement = statement.statements.length === 1 ? statement.statements[0] : void 0;
|
|
192
|
+
if (!statement || !ts.isExpressionStatement(statement)) return void 0;
|
|
193
|
+
let body = statement.expression;
|
|
194
|
+
while (ts.isParenthesizedExpression(body)) body = body.expression;
|
|
195
|
+
if (!ts.isAwaitExpression(body)) return void 0;
|
|
196
|
+
let awaited = body.expression;
|
|
197
|
+
while (ts.isParenthesizedExpression(awaited)) awaited = awaited.expression;
|
|
198
|
+
return repeatedOperation(awaited, /* @__PURE__ */ new Set([declaration.name.text]));
|
|
199
|
+
}
|
|
200
|
+
function readableOptions(node) {
|
|
201
|
+
return node && ts.isObjectLiteralExpression(node) && node.properties.every(ts.isPropertyAssignment) ? node : void 0;
|
|
202
|
+
}
|
|
203
|
+
function option(options, name) {
|
|
204
|
+
for (const property of options?.properties ?? []) {
|
|
205
|
+
if (!ts.isPropertyAssignment(property)) continue;
|
|
206
|
+
if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function operationObject(method, node, label, keys) {
|
|
210
|
+
const options = readableOptions(node);
|
|
211
|
+
if (!options) operationError(method, `${label} must be an inline object with static field names`);
|
|
212
|
+
const seen = /* @__PURE__ */ new Set();
|
|
213
|
+
for (const property of options.properties) {
|
|
214
|
+
const name = property.name;
|
|
215
|
+
if (!name || !ts.isIdentifier(name) && !ts.isStringLiteral(name) || seen.has(name.text)) operationError(method, `${label} must have distinct static field names`);
|
|
216
|
+
if (keys && !keys.includes(name.text)) operationError(method, `${label} contains unsupported fields`);
|
|
217
|
+
seen.add(name.text);
|
|
218
|
+
}
|
|
219
|
+
return options;
|
|
220
|
+
}
|
|
221
|
+
function llmLiteral(node, label) {
|
|
222
|
+
if (!node) return void 0;
|
|
223
|
+
const value = stringLiteral(node) ?? numberLiteral(node);
|
|
224
|
+
if (value === void 0) llmError(`${label} must be a static number or string; callbacks are not supported`);
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
function branchMetadata(meta) {
|
|
228
|
+
const branches = option(meta, "branches");
|
|
229
|
+
if (!branches || !ts.isArrayLiteralExpression(branches)) return void 0;
|
|
230
|
+
const path = [];
|
|
231
|
+
for (const element of branches.elements) {
|
|
232
|
+
const entry = readableOptions(element);
|
|
233
|
+
const id = stringLiteral(option(entry, "id"));
|
|
234
|
+
const description = stringLiteral(option(entry, "description"));
|
|
235
|
+
if (id === void 0 || description === void 0) return void 0;
|
|
236
|
+
path.push({
|
|
237
|
+
id,
|
|
238
|
+
description
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return path;
|
|
242
|
+
}
|
|
243
|
+
function operationMeta(call) {
|
|
244
|
+
const method = call.expression.name.text;
|
|
245
|
+
const optionsIndex = method === "step" || method === "connector" ? 2 : method === "llm" || method === "sleep" || method === "sleepUntil" || method === "waitForEvent" ? 1 : 0;
|
|
246
|
+
return readableOptions(option(readableOptions(call.arguments[optionsIndex]), "meta"));
|
|
247
|
+
}
|
|
248
|
+
function operationBranches(call) {
|
|
249
|
+
return branchMetadata(operationMeta(call));
|
|
250
|
+
}
|
|
251
|
+
function stepMetadata(call) {
|
|
252
|
+
const meta = operationMeta(call);
|
|
253
|
+
const description = stringLiteral(option(meta, "description"));
|
|
254
|
+
if (description === void 0) return void 0;
|
|
255
|
+
const groupOptions = readableOptions(option(meta, "group"));
|
|
256
|
+
if (!groupOptions) return { description };
|
|
257
|
+
const id = stringLiteral(option(groupOptions, "id"));
|
|
258
|
+
const label = stringLiteral(option(groupOptions, "label"));
|
|
259
|
+
return id === void 0 || label === void 0 ? { description } : {
|
|
260
|
+
description,
|
|
261
|
+
group: {
|
|
262
|
+
id,
|
|
263
|
+
label
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function stepExecutionPolicy(options) {
|
|
268
|
+
const retryNode = option(options, "retry");
|
|
269
|
+
let retryPolicy = runtimeRetry(workflow.defaultStepRetry);
|
|
270
|
+
if (retryNode) {
|
|
271
|
+
const retryOptions = readableOptions(retryNode);
|
|
272
|
+
const maxAttemptsNode = option(retryOptions, "maxAttempts");
|
|
273
|
+
const maxAttempts = maxAttemptsNode === void 0 ? 1 : numberLiteral(maxAttemptsNode);
|
|
274
|
+
const backoffNode = option(retryOptions, "backoff");
|
|
275
|
+
const baseMsNode = option(retryOptions, "baseMs");
|
|
276
|
+
const baseMs = baseMsNode === void 0 ? 500 : numberLiteral(baseMsNode);
|
|
277
|
+
const shouldRetryNode = option(retryOptions, "shouldRetry");
|
|
278
|
+
const backoff = backoffNode === void 0 ? "exponential" : stringLiteral(backoffNode) ?? (ts.isArrowFunction(backoffNode) || ts.isFunctionExpression(backoffNode) || ts.isIdentifier(backoffNode) ? "custom" : void 0);
|
|
279
|
+
const supportedBackoff = backoff === "exponential" || backoff === "fixed" || backoff === "custom";
|
|
280
|
+
const customCondition = shouldRetryNode === void 0 ? false : ts.isArrowFunction(shouldRetryNode) || ts.isFunctionExpression(shouldRetryNode) || ts.isIdentifier(shouldRetryNode) ? true : void 0;
|
|
281
|
+
if (retryOptions && maxAttempts !== void 0 && baseMs !== void 0 && supportedBackoff && customCondition !== void 0) retryPolicy = {
|
|
282
|
+
maxAttempts: Math.min(4294967295, Math.max(1, Math.floor(maxAttempts))),
|
|
283
|
+
retryBackoffStrategy: backoff === "custom" ? 3 : backoff === "fixed" ? 2 : 1,
|
|
284
|
+
retryBaseMs: baseMs,
|
|
285
|
+
hasCustomShouldRetry: customCondition
|
|
286
|
+
};
|
|
287
|
+
else {
|
|
288
|
+
degrade("Dynamic step retry policies are not recorded");
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const timeoutNode = option(options, "timeout");
|
|
293
|
+
const timeoutMs = numberLiteral(timeoutNode);
|
|
294
|
+
if (timeoutNode !== void 0 && timeoutMs === void 0) {
|
|
295
|
+
degrade("Dynamic step timeouts are not recorded");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
return create(WorkflowManifestStepExecutionPolicyV1Schema, {
|
|
299
|
+
...retryPolicy,
|
|
300
|
+
...timeoutMs === void 0 || timeoutMs <= 0 ? {} : { timeoutMs }
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function operationDescription(options) {
|
|
304
|
+
return stringLiteral(option(readableOptions(option(options, "meta")), "description"));
|
|
305
|
+
}
|
|
306
|
+
/** Undefined when the call names no static id, which the graph cannot invent. */
|
|
307
|
+
function durableStepId(argument, options) {
|
|
308
|
+
if (argument && !options) return void 0;
|
|
309
|
+
const given = option(options, "id");
|
|
310
|
+
return given ? stringLiteral(given) : void 0;
|
|
311
|
+
}
|
|
312
|
+
function llmDefinition(call, stepId) {
|
|
313
|
+
const options = operationObject("llm", call.arguments[1], "options", [
|
|
314
|
+
"id",
|
|
315
|
+
"meta",
|
|
316
|
+
"timeout",
|
|
317
|
+
"retry"
|
|
318
|
+
]);
|
|
319
|
+
const description = stringLiteral(option(operationObject("llm", option(options, "meta"), "meta"), "description"));
|
|
320
|
+
if (description === void 0) llmError("requires a static meta.description");
|
|
321
|
+
const model = stringLiteral(option(readableOptions(call.arguments[0]), "model"));
|
|
322
|
+
if (model !== void 0) assertLlmModel(model);
|
|
323
|
+
const retryNode = option(options, "retry");
|
|
324
|
+
let retry = workflow.defaultStepRetry;
|
|
325
|
+
if (retryNode) {
|
|
326
|
+
const retryOptions = operationObject("llm", retryNode, "retry", [
|
|
327
|
+
"maxAttempts",
|
|
328
|
+
"backoff",
|
|
329
|
+
"baseMs"
|
|
330
|
+
]);
|
|
331
|
+
retry = Object.fromEntries(retryOptions.properties.map((property) => {
|
|
332
|
+
const field = property;
|
|
333
|
+
const key = field.name.text;
|
|
334
|
+
return [key, llmLiteral(field.initializer, `retry.${key}`)];
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
const resolved = {
|
|
338
|
+
id: stepId,
|
|
339
|
+
meta: { description },
|
|
340
|
+
retry,
|
|
341
|
+
timeout: llmLiteral(option(options, "timeout"), "timeout")
|
|
342
|
+
};
|
|
343
|
+
assertLlmOptions(resolved);
|
|
344
|
+
const executionPolicy = create(WorkflowManifestStepExecutionPolicyV1Schema, {
|
|
345
|
+
...runtimeRetry(resolved.retry),
|
|
346
|
+
timeoutMs: Math.min(resolved.timeout ?? 12e4, 6e5)
|
|
347
|
+
});
|
|
348
|
+
recordedCalls.add(call);
|
|
349
|
+
return create(WorkflowManifestLlmNodeV1Schema, {
|
|
350
|
+
stepId,
|
|
351
|
+
description,
|
|
352
|
+
executionPolicy,
|
|
353
|
+
...model === void 0 ? {} : { model }
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function connectorDefinition(call, stepId) {
|
|
357
|
+
const options = operationObject("connector", call.arguments[2], "options", [
|
|
358
|
+
"connectorId",
|
|
359
|
+
"connectionId",
|
|
360
|
+
"meta",
|
|
361
|
+
"retry",
|
|
362
|
+
"timeout"
|
|
363
|
+
]);
|
|
364
|
+
const connectorId = stringLiteral(option(options, "connectorId"));
|
|
365
|
+
const connectionId = stringLiteral(option(options, "connectionId"));
|
|
366
|
+
if (!connectorId?.trim()) operationError("connector", "requires a non-empty static connectorId");
|
|
367
|
+
if (!connectionId?.trim()) operationError("connector", "requires a non-empty static connectionId");
|
|
368
|
+
if (!stepId.trim()) operationError("connector", "requires a non-empty step id");
|
|
369
|
+
const meta = operationObject("connector", option(options, "meta"), "meta");
|
|
370
|
+
const description = stringLiteral(option(meta, "description"));
|
|
371
|
+
if (description === void 0) operationError("connector", "requires a static meta.description");
|
|
372
|
+
const groupNode = option(meta, "group");
|
|
373
|
+
if (groupNode) {
|
|
374
|
+
const group = operationObject("connector", groupNode, "meta.group");
|
|
375
|
+
if (!stringLiteral(option(group, "id"))?.trim() || !stringLiteral(option(group, "label"))?.trim()) operationError("connector", "requires non-empty static meta.group.id and meta.group.label");
|
|
376
|
+
}
|
|
377
|
+
const branches = option(meta, "branches");
|
|
378
|
+
if (branches) {
|
|
379
|
+
if (!ts.isArrayLiteralExpression(branches)) operationError("connector", "meta.branches must be an inline array");
|
|
380
|
+
for (const branch of branches.elements) operationObject("connector", branch, "meta.branches entry");
|
|
381
|
+
}
|
|
382
|
+
const retry = option(options, "retry");
|
|
383
|
+
if (retry) operationObject("connector", retry, "retry", [
|
|
384
|
+
"maxAttempts",
|
|
385
|
+
"backoff",
|
|
386
|
+
"baseMs",
|
|
387
|
+
"shouldRetry"
|
|
388
|
+
]);
|
|
389
|
+
const executionPolicy = stepExecutionPolicy(options);
|
|
390
|
+
if (!executionPolicy) operationError("connector", "requires retry and timeout policies the manifest can record");
|
|
391
|
+
recordedCalls.add(call);
|
|
392
|
+
return create(WorkflowManifestConnectorNodeV1Schema, {
|
|
393
|
+
stepId,
|
|
394
|
+
description,
|
|
395
|
+
connectorId,
|
|
396
|
+
connectionId,
|
|
397
|
+
executionPolicy
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
function repeatedNode(repeated, kind, parents) {
|
|
401
|
+
const method = repeated.call.expression.name.text;
|
|
402
|
+
const connector = method === "connector" ? connectorDefinition(repeated.call, repeated.template) : void 0;
|
|
403
|
+
const metadata = stepMetadata(repeated.call);
|
|
404
|
+
if (!metadata?.group) return unknown("Repeated operations need static group metadata", parents);
|
|
405
|
+
if (method === "llm") assertLlmOptions({
|
|
406
|
+
id: repeated.template,
|
|
407
|
+
meta: metadata
|
|
408
|
+
});
|
|
409
|
+
const definition = method === "llm" ? llmDefinition(repeated.call, repeated.template) : void 0;
|
|
410
|
+
const operation = definition ? { llm: create(WorkflowManifestRepeatedLlmV1Schema, {
|
|
411
|
+
stepIdTemplate: repeated.template,
|
|
412
|
+
description: definition.description,
|
|
413
|
+
executionPolicy: definition.executionPolicy,
|
|
414
|
+
...definition.model === void 0 ? {} : { model: definition.model }
|
|
415
|
+
}) } : connector ? { connector: create(WorkflowManifestRepeatedConnectorV1Schema, {
|
|
416
|
+
stepIdTemplate: repeated.template,
|
|
417
|
+
description: connector.description,
|
|
418
|
+
connectorId: connector.connectorId,
|
|
419
|
+
connectionId: connector.connectionId,
|
|
420
|
+
executionPolicy: connector.executionPolicy
|
|
421
|
+
}) } : { step: create(WorkflowManifestRepeatedStepV1Schema, {
|
|
422
|
+
stepIdTemplate: repeated.template,
|
|
423
|
+
description: metadata.description,
|
|
424
|
+
executionPolicy: stepExecutionPolicy(readableOptions(repeated.call.arguments[2]))
|
|
425
|
+
}) };
|
|
426
|
+
const details = {
|
|
427
|
+
groupId: metadata.group.id,
|
|
428
|
+
...operation
|
|
429
|
+
};
|
|
430
|
+
return addNode(metadata.group.label, kind === "parallel" ? {
|
|
431
|
+
case: "parallel",
|
|
432
|
+
value: create(WorkflowManifestParallelNodeV1Schema, details)
|
|
433
|
+
} : {
|
|
434
|
+
case: "loop",
|
|
435
|
+
value: create(WorkflowManifestLoopNodeV1Schema, details)
|
|
436
|
+
}, parents);
|
|
437
|
+
}
|
|
438
|
+
function durableNode(call, parents) {
|
|
439
|
+
const method = call.expression.name.text;
|
|
440
|
+
if (method === "step") {
|
|
441
|
+
const stepId = stringLiteral(call.arguments[0]);
|
|
442
|
+
if (stepId === void 0) return unknown("Dynamic step IDs are not supported yet", parents);
|
|
443
|
+
const metadata = stepMetadata(call);
|
|
444
|
+
if (!metadata) return unknown("Step descriptions must be static strings", parents);
|
|
445
|
+
const executionPolicy = stepExecutionPolicy(readableOptions(call.arguments[2]));
|
|
446
|
+
return addNode(stepId, {
|
|
447
|
+
case: "step",
|
|
448
|
+
value: create(WorkflowManifestStepNodeV1Schema, {
|
|
449
|
+
stepId,
|
|
450
|
+
description: metadata.description,
|
|
451
|
+
...executionPolicy === void 0 ? {} : { executionPolicy }
|
|
452
|
+
})
|
|
453
|
+
}, parents);
|
|
454
|
+
}
|
|
455
|
+
if (method === "llm") {
|
|
456
|
+
const options = operationObject("llm", call.arguments[1], "options", [
|
|
457
|
+
"id",
|
|
458
|
+
"meta",
|
|
459
|
+
"timeout",
|
|
460
|
+
"retry"
|
|
461
|
+
]);
|
|
462
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
463
|
+
if (stepId === void 0) llmError("requires a static id outside a repeated operation");
|
|
464
|
+
return addNode(stepId, {
|
|
465
|
+
case: "llm",
|
|
466
|
+
value: llmDefinition(call, stepId)
|
|
467
|
+
}, parents);
|
|
468
|
+
}
|
|
469
|
+
if (method === "connector") {
|
|
470
|
+
const stepId = stringLiteral(call.arguments[0]);
|
|
471
|
+
if (stepId === void 0) operationError("connector", "requires a static step id outside a repeated operation");
|
|
472
|
+
return addNode(stepId, {
|
|
473
|
+
case: "connector",
|
|
474
|
+
value: connectorDefinition(call, stepId)
|
|
475
|
+
}, parents);
|
|
476
|
+
}
|
|
477
|
+
if (method === "approve") {
|
|
478
|
+
const options = readableOptions(call.arguments[0]);
|
|
479
|
+
const title = stringLiteral(option(options, "title"));
|
|
480
|
+
if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
|
|
481
|
+
const stepId = durableStepId(call.arguments[0], options);
|
|
482
|
+
if (stepId === void 0) return unknown("ctx.approve needs a static { id }", parents);
|
|
483
|
+
const description = stringLiteral(option(options, "description"));
|
|
484
|
+
if (description === void 0) return unknown("Approval descriptions must be static strings", parents);
|
|
485
|
+
const deadline = numberLiteral(option(options, "timeoutMs"));
|
|
486
|
+
return addNode(title, {
|
|
487
|
+
case: "approve",
|
|
488
|
+
value: create(WorkflowManifestApproveNodeV1Schema, {
|
|
489
|
+
stepId,
|
|
490
|
+
description,
|
|
491
|
+
title,
|
|
492
|
+
...deadline === void 0 ? {} : { deadline }
|
|
493
|
+
})
|
|
494
|
+
}, parents);
|
|
495
|
+
}
|
|
496
|
+
if (method === "waitForEvent") {
|
|
497
|
+
const event = stringLiteral(call.arguments[0]);
|
|
498
|
+
if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
|
|
499
|
+
const options = readableOptions(call.arguments[1]);
|
|
500
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
501
|
+
if (stepId === void 0) return unknown("Dynamic waitForEvent IDs are not supported yet", parents);
|
|
502
|
+
const description = operationDescription(options);
|
|
503
|
+
if (description === void 0) return unknown("Wait descriptions must be static strings", parents);
|
|
504
|
+
const deadline = numberLiteral(option(options, "timeoutMs"));
|
|
505
|
+
return addNode(event, {
|
|
506
|
+
case: "waitForEvent",
|
|
507
|
+
value: create(WorkflowManifestWaitForEventNodeV1Schema, {
|
|
508
|
+
stepId,
|
|
509
|
+
description,
|
|
510
|
+
event,
|
|
511
|
+
...deadline === void 0 ? {} : { deadline }
|
|
512
|
+
})
|
|
513
|
+
}, parents);
|
|
514
|
+
}
|
|
515
|
+
if (method === "sleep") {
|
|
516
|
+
const ms = numberLiteral(call.arguments[0]);
|
|
517
|
+
if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
|
|
518
|
+
const options = readableOptions(call.arguments[1]);
|
|
519
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
520
|
+
if (stepId === void 0) return unknown("Dynamic sleep IDs are not supported yet", parents);
|
|
521
|
+
const description = operationDescription(options);
|
|
522
|
+
if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
|
|
523
|
+
return addNode(`sleep ${ms}ms`, {
|
|
524
|
+
case: "sleep",
|
|
525
|
+
value: create(WorkflowManifestSleepNodeV1Schema, {
|
|
526
|
+
stepId,
|
|
527
|
+
description,
|
|
528
|
+
ms
|
|
529
|
+
})
|
|
530
|
+
}, parents);
|
|
531
|
+
}
|
|
532
|
+
if (method === "sleepUntil") {
|
|
533
|
+
const timestamp = numberLiteral(call.arguments[0]);
|
|
534
|
+
if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
|
|
535
|
+
const options = readableOptions(call.arguments[1]);
|
|
536
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
537
|
+
if (stepId === void 0) return unknown("Dynamic sleepUntil IDs are not supported yet", parents);
|
|
538
|
+
const description = operationDescription(options);
|
|
539
|
+
if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
|
|
540
|
+
return addNode(`sleep until ${timestamp}`, {
|
|
541
|
+
case: "sleepUntil",
|
|
542
|
+
value: create(WorkflowManifestSleepUntilNodeV1Schema, {
|
|
543
|
+
stepId,
|
|
544
|
+
description,
|
|
545
|
+
timestamp
|
|
546
|
+
})
|
|
547
|
+
}, parents);
|
|
548
|
+
}
|
|
549
|
+
const options = readableOptions(call.arguments[0]);
|
|
550
|
+
const stepId = durableStepId(call.arguments[0], options);
|
|
551
|
+
if (stepId === void 0) return unknown(`Dynamic ${method} IDs are not supported yet`, parents);
|
|
552
|
+
const description = operationDescription(options);
|
|
553
|
+
if (description === void 0) return unknown(`${method} descriptions must be static strings`, parents);
|
|
554
|
+
return addNode(stepId, method === "now" ? {
|
|
555
|
+
case: "now",
|
|
556
|
+
value: create(WorkflowManifestNowNodeV1Schema, {
|
|
557
|
+
stepId,
|
|
558
|
+
description
|
|
559
|
+
})
|
|
560
|
+
} : {
|
|
561
|
+
case: "uuid",
|
|
562
|
+
value: create(WorkflowManifestUuidNodeV1Schema, {
|
|
563
|
+
stepId,
|
|
564
|
+
description
|
|
565
|
+
})
|
|
566
|
+
}, parents);
|
|
567
|
+
}
|
|
568
|
+
function path(tails, reachable = true) {
|
|
569
|
+
return {
|
|
570
|
+
tails: reachable ? tails : [],
|
|
571
|
+
reachable
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
function mergePaths(...items) {
|
|
575
|
+
const tails = [];
|
|
576
|
+
const seen = /* @__PURE__ */ new Set();
|
|
577
|
+
for (const item of items) for (const tail of item.tails) {
|
|
578
|
+
const key = JSON.stringify(tail);
|
|
579
|
+
if (seen.has(key)) continue;
|
|
580
|
+
seen.add(key);
|
|
581
|
+
tails.push(tail);
|
|
582
|
+
}
|
|
583
|
+
return path(tails, items.some((item) => item.reachable));
|
|
584
|
+
}
|
|
585
|
+
function expression(node, parents, awaited = false) {
|
|
586
|
+
if (ts.isParenthesizedExpression(node)) return expression(node.expression, parents, awaited);
|
|
587
|
+
if (ts.isAwaitExpression(node)) return expression(node.expression, parents, true);
|
|
588
|
+
if (durableCall(node)) {
|
|
589
|
+
let tails = awaited ? durableNode(node, parents) : unknown("Unawaited durable calls are not supported yet", parents);
|
|
590
|
+
if (node.arguments.some((argument) => contains(argument, durableCall))) tails = unknown("Nested durable calls are not supported yet", tails);
|
|
591
|
+
return {
|
|
592
|
+
tails,
|
|
593
|
+
thrown: path(tails)
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
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) {
|
|
597
|
+
const argument = node.arguments[0];
|
|
598
|
+
if (ts.isArrayLiteralExpression(argument)) {
|
|
599
|
+
const elements = argument.elements;
|
|
600
|
+
if (elements.some((element) => contains(element, ts.isAwaitExpression, true))) {
|
|
601
|
+
const tails = unknown("Await expressions inside Promise.all are not supported yet", parents);
|
|
602
|
+
return {
|
|
603
|
+
tails,
|
|
604
|
+
thrown: path(tails)
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (elements.length === 0) return {
|
|
608
|
+
tails: parents,
|
|
609
|
+
thrown: path([], false)
|
|
610
|
+
};
|
|
611
|
+
const flows = elements.map((element) => {
|
|
612
|
+
while (ts.isParenthesizedExpression(element)) element = element.expression;
|
|
613
|
+
if (ts.isCallExpression(element)) return expression(element, parents, true);
|
|
614
|
+
const tails = unknown("Dynamic Promise.all entries are not followed", parents);
|
|
615
|
+
return {
|
|
616
|
+
tails,
|
|
617
|
+
thrown: path(tails)
|
|
618
|
+
};
|
|
619
|
+
});
|
|
620
|
+
return {
|
|
621
|
+
tails: flows.flatMap((flow) => flow.tails),
|
|
622
|
+
thrown: mergePaths(...flows.map((flow) => flow.thrown))
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
const mapped = mappedStep(argument);
|
|
626
|
+
if (mapped !== void 0) {
|
|
627
|
+
const tails = repeatedNode(mapped, "parallel", parents);
|
|
628
|
+
return {
|
|
629
|
+
tails,
|
|
630
|
+
thrown: path(tails)
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child))) {
|
|
635
|
+
const tails = unknown("Helper calls and dynamic expressions are not followed", parents);
|
|
636
|
+
return {
|
|
637
|
+
tails,
|
|
638
|
+
thrown: path(tails)
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (ts.isIdentifier(node) && node.text === context) return {
|
|
642
|
+
tails: unknown("Workflow context aliases are not followed", parents),
|
|
643
|
+
thrown: path([], false)
|
|
644
|
+
};
|
|
645
|
+
return {
|
|
646
|
+
tails: parents,
|
|
647
|
+
thrown: path([], false)
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
function branchInfo(statement, depth) {
|
|
651
|
+
let result;
|
|
652
|
+
const visit = (node) => {
|
|
653
|
+
if (result) return;
|
|
654
|
+
if (durableCall(node)) {
|
|
655
|
+
result = operationBranches(node)?.[depth];
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
ts.forEachChild(node, visit);
|
|
659
|
+
};
|
|
660
|
+
visit(statement.thenStatement);
|
|
661
|
+
if (statement.elseStatement) visit(statement.elseStatement);
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
function statementFlow(normal, thrown = path([], false), returned = path([], false), stopped = path([], false)) {
|
|
665
|
+
return {
|
|
666
|
+
normal,
|
|
667
|
+
thrown,
|
|
668
|
+
returned,
|
|
669
|
+
stopped
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function statements(items, parents, branchDepth) {
|
|
673
|
+
let normal = path(parents);
|
|
674
|
+
let thrown = path([], false);
|
|
675
|
+
let returned = path([], false);
|
|
676
|
+
let stopped = path([], false);
|
|
677
|
+
for (const statement of items) {
|
|
678
|
+
if (!normal.reachable) break;
|
|
679
|
+
const flow = walkStatement(statement, normal.tails, branchDepth);
|
|
680
|
+
normal = flow.normal;
|
|
681
|
+
thrown = mergePaths(thrown, flow.thrown);
|
|
682
|
+
returned = mergePaths(returned, flow.returned);
|
|
683
|
+
stopped = mergePaths(stopped, flow.stopped);
|
|
684
|
+
}
|
|
685
|
+
return statementFlow(normal, thrown, returned, stopped);
|
|
686
|
+
}
|
|
687
|
+
function walkStatement(statement, parents, branchDepth) {
|
|
688
|
+
if (ts.isBlock(statement)) return statements(statement.statements, parents, branchDepth);
|
|
689
|
+
if (ts.isReturnStatement(statement)) {
|
|
690
|
+
const result = statement.expression ? expression(statement.expression, parents, true) : {
|
|
691
|
+
tails: parents,
|
|
692
|
+
thrown: path([], false)
|
|
693
|
+
};
|
|
694
|
+
return statementFlow(path([], false), result.thrown, path(result.tails));
|
|
695
|
+
}
|
|
696
|
+
if (ts.isThrowStatement(statement)) {
|
|
697
|
+
const result = expression(statement.expression, parents);
|
|
698
|
+
return statementFlow(path([], false), mergePaths(result.thrown, path(result.tails)));
|
|
699
|
+
}
|
|
700
|
+
if (ts.isVariableStatement(statement)) {
|
|
701
|
+
if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context)))) {
|
|
702
|
+
const tails = unknown("Shadowed context or Promise bindings are not supported yet", parents);
|
|
703
|
+
return statementFlow(path([], false), path([], false), path([], false), path(tails));
|
|
704
|
+
}
|
|
705
|
+
let tails = parents;
|
|
706
|
+
let thrown = path([], false);
|
|
707
|
+
for (const item of statement.declarationList.declarations) {
|
|
708
|
+
if (!item.initializer) continue;
|
|
709
|
+
const result = expression(item.initializer, tails);
|
|
710
|
+
tails = result.tails;
|
|
711
|
+
thrown = mergePaths(thrown, result.thrown);
|
|
712
|
+
}
|
|
713
|
+
return statementFlow(path(tails), thrown);
|
|
714
|
+
}
|
|
715
|
+
if (ts.isExpressionStatement(statement)) {
|
|
716
|
+
const result = expression(statement.expression, parents);
|
|
717
|
+
return statementFlow(path(result.tails), result.thrown);
|
|
718
|
+
}
|
|
719
|
+
if (ts.isIfStatement(statement)) {
|
|
720
|
+
const conditionFlow = expression(statement.expression, parents);
|
|
721
|
+
const metadata = branchInfo(statement, branchDepth);
|
|
722
|
+
const condition = statement.expression.getText(source);
|
|
723
|
+
const branchTails = metadata ? addNode(metadata.description, {
|
|
724
|
+
case: "branch",
|
|
725
|
+
value: create(WorkflowManifestBranchNodeV1Schema, {
|
|
726
|
+
branchId: metadata.id,
|
|
727
|
+
condition,
|
|
728
|
+
description: metadata.description
|
|
729
|
+
})
|
|
730
|
+
}, conditionFlow.tails) : conditionFlow.tails;
|
|
731
|
+
const sourceId = metadata ? branchTails[0]?.source : void 0;
|
|
732
|
+
const thenParents = sourceId ? [{
|
|
733
|
+
source: sourceId,
|
|
734
|
+
kind: "branch",
|
|
735
|
+
outcome: true
|
|
736
|
+
}] : branchTails;
|
|
737
|
+
const elseParents = sourceId ? [{
|
|
738
|
+
source: sourceId,
|
|
739
|
+
kind: "branch",
|
|
740
|
+
outcome: false
|
|
741
|
+
}] : branchTails;
|
|
742
|
+
const thenFlow = walkStatement(statement.thenStatement, thenParents, branchDepth + 1);
|
|
743
|
+
const elseFlow = statement.elseStatement ? walkStatement(statement.elseStatement, elseParents, branchDepth + 1) : statementFlow(path(elseParents));
|
|
744
|
+
return statementFlow(mergePaths(thenFlow.normal, elseFlow.normal), mergePaths(conditionFlow.thrown, thenFlow.thrown, elseFlow.thrown), mergePaths(thenFlow.returned, elseFlow.returned), mergePaths(thenFlow.stopped, elseFlow.stopped));
|
|
745
|
+
}
|
|
746
|
+
if (ts.isTryStatement(statement)) {
|
|
747
|
+
const tryFlow = walkStatement(statement.tryBlock, parents, branchDepth);
|
|
748
|
+
const catchBlock = statement.catchClause?.block;
|
|
749
|
+
const catchHasDurableOperations = catchBlock ? contains(catchBlock, durableCall) : false;
|
|
750
|
+
const catchHasAbruptCompletion = catchBlock ? contains(catchBlock, (node) => ts.isReturnStatement(node) || ts.isThrowStatement(node), true) : false;
|
|
751
|
+
let catchFlow = statementFlow(path([], false));
|
|
752
|
+
if (catchBlock && (tryFlow.thrown.reachable || catchHasDurableOperations || catchHasAbruptCompletion)) if (catchHasDurableOperations || catchHasAbruptCompletion) catchFlow = walkStatement(catchBlock, unknown(catchHasDurableOperations ? "Durable catch paths are conditional on errors" : "Catch completion paths are conditional on errors", tryFlow.thrown.reachable ? tryFlow.thrown.tails : parents), branchDepth);
|
|
753
|
+
else catchFlow = statementFlow(path(tryFlow.thrown.tails));
|
|
754
|
+
const normal = mergePaths(tryFlow.normal, catchFlow.normal);
|
|
755
|
+
const thrown = catchBlock ? catchFlow.thrown : tryFlow.thrown;
|
|
756
|
+
const returned = mergePaths(tryFlow.returned, catchFlow.returned);
|
|
757
|
+
const stopped = mergePaths(tryFlow.stopped, catchFlow.stopped);
|
|
758
|
+
const flow = statementFlow(normal, thrown, returned, stopped);
|
|
759
|
+
if (!statement.finallyBlock) return flow;
|
|
760
|
+
const finallyHasDurableOperations = contains(statement.finallyBlock, durableCall);
|
|
761
|
+
const finallyHasAbruptCompletion = contains(statement.finallyBlock, (node) => ts.isReturnStatement(node) || ts.isThrowStatement(node), true);
|
|
762
|
+
if (!finallyHasDurableOperations && !finallyHasAbruptCompletion) return flow;
|
|
763
|
+
const finallyParents = mergePaths(normal, thrown, returned, stopped);
|
|
764
|
+
const finallyFlow = walkStatement(statement.finallyBlock, finallyParents.tails, branchDepth);
|
|
765
|
+
const completedFinally = finallyFlow.normal.reachable;
|
|
766
|
+
return statementFlow(path(finallyFlow.normal.tails, normal.reachable && completedFinally), mergePaths(finallyFlow.thrown, path(finallyFlow.normal.tails, thrown.reachable && completedFinally)), mergePaths(finallyFlow.returned, path(finallyFlow.normal.tails, returned.reachable && completedFinally)), mergePaths(finallyFlow.stopped, path(finallyFlow.normal.tails, stopped.reachable && completedFinally)));
|
|
767
|
+
}
|
|
768
|
+
if (ts.isForOfStatement(statement)) {
|
|
769
|
+
const repeated = sequentialLoopStep(statement);
|
|
770
|
+
if (repeated) {
|
|
771
|
+
const iterable = expression(statement.expression, parents);
|
|
772
|
+
const tails = repeatedNode(repeated, "loop", iterable.tails);
|
|
773
|
+
return statementFlow(path(tails), mergePaths(iterable.thrown, path(tails)));
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (ts.isEmptyStatement(statement)) return statementFlow(path(parents));
|
|
777
|
+
return statementFlow(path(unknown("Loops and other control flow are not supported yet", parents)));
|
|
778
|
+
}
|
|
779
|
+
const tails = [];
|
|
780
|
+
if (!ts.isBlock(fn.body)) expression(fn.body, tails, true);
|
|
781
|
+
else statements(fn.body.statements, tails, 0);
|
|
782
|
+
const checkRecordedCalls = (node) => {
|
|
783
|
+
const method = ts.isPropertyAccessExpression(node) ? node.name.text : ts.isElementAccessExpression(node) ? stringLiteral(node.argumentExpression) : void 0;
|
|
784
|
+
if ((method === "llm" || method === "connector") && (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && ts.isIdentifier(node.expression) && node.expression.text === context && (!ts.isCallExpression(node.parent) || !recordedCalls.has(node.parent))) operationError(method, "must be awaited or returned directly, used in a fixed or mapped Promise.all, or directly awaited in a for...of loop");
|
|
785
|
+
ts.forEachChild(node, checkRecordedCalls);
|
|
786
|
+
};
|
|
787
|
+
checkRecordedCalls(fn.body);
|
|
788
|
+
return graph;
|
|
789
|
+
}
|
|
790
|
+
//#endregion
|
|
791
|
+
export { extractWorkflowGraph, loadTypeScript, workflowHandlerSource as t };
|