@lovable.dev/workflows-sdk 0.0.0-dev.18 → 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
|
@@ -373,6 +373,12 @@ visible durable calls inside it, including `ctx.step`, `ctx.sleep`, `ctx.now`,
|
|
|
373
373
|
and the other `ctx.*` operations. Move each durable operation into the workflow
|
|
374
374
|
handler and pass its result into the step instead.
|
|
375
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
|
+
|
|
376
382
|
## Steps endpoint (TanStack Start)
|
|
377
383
|
|
|
378
384
|
The same `workflowsPlugin` that writes the manifests also emits
|
|
@@ -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 };
|
|
@@ -185,6 +185,7 @@ function serializeSchema(schema, direction, label) {
|
|
|
185
185
|
async function generateManifests(definition) {
|
|
186
186
|
const { extractWorkflowGraph } = await import("./graph-V2yqSs3X.js");
|
|
187
187
|
const { findBranchMetadataIssues } = await import("./branch-metadata-DeUhEFah.js");
|
|
188
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-DRzfr4f6.js");
|
|
188
189
|
const { findDuplicateOperationIds } = await import("./duplicate-ids-BSJNfUhh.js");
|
|
189
190
|
const { findNestedDurableOperations } = await import("./nested-operations-DsecXS12.js");
|
|
190
191
|
const { findOperationDescriptionIssues } = await import("./operation-descriptions-C_f87Bmr.js");
|
|
@@ -193,6 +194,10 @@ async function generateManifests(definition) {
|
|
|
193
194
|
const manifests = [];
|
|
194
195
|
for (const workflow of collection.workflows) {
|
|
195
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`);
|
|
196
201
|
const nested = (await findNestedDurableOperations(workflow.handler))[0];
|
|
197
202
|
if (nested) {
|
|
198
203
|
const parent = nested.parentStepId ? `ctx.step(${JSON.stringify(nested.parentStepId)})` : "ctx.step()";
|
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-
|
|
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
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as generateManifests } from "./generate-
|
|
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";
|