@lovable.dev/workflows-sdk 0.0.0-dev.14 → 0.0.0-dev.16
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 +58 -11
- package/dist/{duplicate-ids-DFD8TO2y.js → duplicate-ids-CosMS6qZ.js} +1 -1
- package/dist/{generate-CUlH7Z2x.js → generate-DTzFAh96.js} +14 -3
- package/dist/{graph-CZDg07_0.js → graph-BEfFBC6v.js} +73 -13
- package/dist/index.d.ts +22 -2
- package/dist/index.js +22 -7
- package/dist/{nested-operations-OEvIJ3AZ.js → nested-operations-hWj5wt1m.js} +1 -1
- package/dist/step-metadata-Cly35okS.js +63 -0
- package/dist/vite.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,37 @@ definitions as immutable after registration.
|
|
|
46
46
|
See [the authoring example](examples/src/lib/workflows/greet/index.ts) for schemas,
|
|
47
47
|
typed middleware, and a durable step. The package typecheck includes this example.
|
|
48
48
|
|
|
49
|
+
Every `ctx.step()` needs a static, user-facing description. Lovable's agent
|
|
50
|
+
supplies this text so the workflow UI can explain what the step does before and
|
|
51
|
+
during a run:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
await ctx.step("load-customer", () => loadCustomer(ctx.input.customerId), {
|
|
55
|
+
meta: { description: "Load the customer record" },
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Manifest generation rejects a missing or computed description. A step declared
|
|
60
|
+
inside a loop or callback also needs a group with a stable ID and user-facing
|
|
61
|
+
label. The group identifies the repeated callsite while each runtime step keeps
|
|
62
|
+
its own concrete ID:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
await Promise.all(
|
|
66
|
+
ctx.input.items.map((item) =>
|
|
67
|
+
ctx.step(`process-${item.id}`, () => processItem(item), {
|
|
68
|
+
meta: {
|
|
69
|
+
description: "Process an item",
|
|
70
|
+
group: { id: "process-items", label: "Process items" },
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Group IDs are unique per workflow callsite. Ordinary sequential steps and
|
|
78
|
+
fixed `Promise.all([stepA, stepB])` branches do not need a group.
|
|
79
|
+
|
|
49
80
|
## Triggers
|
|
50
81
|
|
|
51
82
|
A workflow runs when something triggers it, and a schedule is the first kind of
|
|
@@ -271,22 +302,25 @@ from a Lovable template already have it. Without it — or with a copy exposing
|
|
|
271
302
|
stable JS API, as TypeScript 7 does before 7.1 — the build still succeeds and
|
|
272
303
|
every graph carries one `unknown` node and the diagnostic
|
|
273
304
|
`Install typescript to infer step graphs`.
|
|
274
|
-
Sequential awaited `ctx.step("name", callback)` calls produce order edges;
|
|
305
|
+
Sequential awaited `ctx.step("name", callback, options)` calls produce order edges;
|
|
275
306
|
`await Promise.all([ctx.step(...), ctx.step(...)])` produces parallel branches
|
|
276
307
|
that join at the next step. A `Promise.all()` mapped over a collection with the
|
|
277
308
|
step ID template `step-${item.id}` produces one dynamic parallel node labeled
|
|
278
|
-
`
|
|
279
|
-
this mapped form.
|
|
309
|
+
from `meta.group.label`. Returned step promises work too. Keep step IDs literal
|
|
310
|
+
outside this mapped form.
|
|
280
311
|
|
|
281
312
|
| Field | Meaning |
|
|
282
313
|
| --- | --- |
|
|
283
314
|
| `nodes[].id` | Unique occurrence ID within this graph; use as the UI node key |
|
|
284
315
|
| `nodes[].kind` | Durable operation, `parallel`, or `unknown` |
|
|
285
|
-
| `nodes[].stepId` |
|
|
316
|
+
| `nodes[].stepId` | Runtime durable ID for every statically known operation |
|
|
317
|
+
| `nodes[].description` | User-facing description for a static step |
|
|
318
|
+
| `nodes[].groupId` | Stable callsite ID for a dynamic parallel node |
|
|
286
319
|
| `nodes[].cardinality` | `dynamic` for a runtime-sized parallel fan-out |
|
|
287
320
|
| `nodes[].operation.kind` | Durable operation repeated by a parallel node |
|
|
288
321
|
| `nodes[].operation.stepIdTemplate` | Display template for steps in a dynamic parallel node |
|
|
289
|
-
| `nodes[].
|
|
322
|
+
| `nodes[].operation.description` | User-facing description shared by the repeated steps |
|
|
323
|
+
| `nodes[].label` | Step ID, group label, or explanation of unsupported code |
|
|
290
324
|
| `edges[]` | `{ source, target, kind: "order" }`, referencing node IDs |
|
|
291
325
|
| `complete` | Whether the handler uses only supported syntax |
|
|
292
326
|
| `diagnostics` | Reasons the graph is partial |
|
|
@@ -296,6 +330,10 @@ For example, `read` followed by parallel `transform-a` and `transform-b`, then
|
|
|
296
330
|
Node IDs are deterministic for the same source, but may change when the handler
|
|
297
331
|
is edited.
|
|
298
332
|
|
|
333
|
+
Known durable nodes use the same `stepId` as runtime progress records. An
|
|
334
|
+
explicit `{ id }` wins; otherwise the graph and runtime share the operation's
|
|
335
|
+
derived default. `label` remains the display name.
|
|
336
|
+
|
|
299
337
|
Graphs have `source: "inferred"` and `scope: "handler"`. They describe source
|
|
300
338
|
structure, not run history or data dependencies, and exclude middleware and
|
|
301
339
|
initialization. A mapped `Promise.all` is complete when its callback directly
|
|
@@ -413,7 +451,15 @@ There is no run store. A run's entire state is its **memo** — the list of
|
|
|
413
451
|
settled operations — and the caller carries it between calls:
|
|
414
452
|
|
|
415
453
|
```jsonc
|
|
416
|
-
[{
|
|
454
|
+
[{
|
|
455
|
+
"seq": 0,
|
|
456
|
+
"stepId": "greeting",
|
|
457
|
+
"occurrence": 0,
|
|
458
|
+
"kind": "step",
|
|
459
|
+
"meta": { "description": "Create a personalized greeting" },
|
|
460
|
+
"status": "completed",
|
|
461
|
+
"result": "Hello, yehya!"
|
|
462
|
+
}]
|
|
417
463
|
```
|
|
418
464
|
|
|
419
465
|
An entry is keyed by `stepId` and `occurrence` (which call of that id in the
|
|
@@ -532,11 +578,12 @@ inside the step and return the key.
|
|
|
532
578
|
Each call re-runs the handler from the top. Step bodies run only in their
|
|
533
579
|
selected request, so side effects belong inside a step.
|
|
534
580
|
|
|
535
|
-
`next` reports a step's `stepId
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
581
|
+
`next` reports a step's `stepId`, `kind`, and author-supplied `meta`, including
|
|
582
|
+
its description and group. It does not report the step input:
|
|
583
|
+
`ctx.step(id, fn, options)` closes over its arguments rather than declaring
|
|
584
|
+
them, so the input is not knowable without running `fn`. Deterministic values
|
|
585
|
+
(`ctx.now`, `ctx.uuid`) are pinned into `memoDelta`, so concurrent calls replay
|
|
586
|
+
the same values after the engine merges the delta.
|
|
540
587
|
|
|
541
588
|
### Waiting on something outside the app
|
|
542
589
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
2
|
-
import { loadTypeScript } from "./graph-
|
|
2
|
+
import { loadTypeScript } from "./graph-BEfFBC6v.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,9 +183,10 @@ function serializeSchema(schema, direction, label) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
async function generateManifests(definition) {
|
|
186
|
-
const { extractWorkflowGraph } = await import("./graph-
|
|
187
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-
|
|
188
|
-
const { findNestedDurableOperations } = await import("./nested-operations-
|
|
186
|
+
const { extractWorkflowGraph } = await import("./graph-BEfFBC6v.js");
|
|
187
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-CosMS6qZ.js");
|
|
188
|
+
const { findNestedDurableOperations } = await import("./nested-operations-hWj5wt1m.js");
|
|
189
|
+
const { findStepMetadataIssues } = await import("./step-metadata-Cly35okS.js");
|
|
189
190
|
const collection = registerWorkflows(definition);
|
|
190
191
|
const manifests = [];
|
|
191
192
|
for (const workflow of collection.workflows) {
|
|
@@ -203,6 +204,16 @@ async function generateManifests(definition) {
|
|
|
203
204
|
const where = duplicate.reason === "loop" ? "inside a loop" : "more than once";
|
|
204
205
|
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}() ${where} with the default id "${duplicate.id}"; replay cannot tell the occurrences apart, so pass an explicit { id } per call site`);
|
|
205
206
|
}
|
|
207
|
+
const metadataIssue = (await findStepMetadataIssues(workflow.handler))[0];
|
|
208
|
+
if (metadataIssue?.kind === "description") {
|
|
209
|
+
const step = metadataIssue.stepId ? `ctx.step(${JSON.stringify(metadataIssue.stepId)})` : "ctx.step()";
|
|
210
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} must include a static { meta: { description: "..." } }`);
|
|
211
|
+
}
|
|
212
|
+
if (metadataIssue?.kind === "group") {
|
|
213
|
+
const step = metadataIssue.stepId ? `ctx.step(${JSON.stringify(metadataIssue.stepId)})` : "ctx.step()";
|
|
214
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} is declared in a loop or callback and must include a static { meta: { group: { id: "...", label: "..." } } }`);
|
|
215
|
+
}
|
|
216
|
+
if (metadataIssue?.kind === "duplicate-group") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses group id ${JSON.stringify(metadataIssue.groupId)} at more than one repeated step callsite; every group id must identify one callsite`);
|
|
206
217
|
const metadata = {
|
|
207
218
|
id: workflow.id,
|
|
208
219
|
...workflow.description === void 0 ? {} : { description: workflow.description },
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
1
2
|
//#region src/manifests/graph.ts
|
|
2
3
|
const durableMethods = {
|
|
3
4
|
step: 0,
|
|
@@ -103,7 +104,7 @@ async function extractWorkflowGraph(handler) {
|
|
|
103
104
|
}
|
|
104
105
|
return template;
|
|
105
106
|
}
|
|
106
|
-
function
|
|
107
|
+
function mappedStep(node) {
|
|
107
108
|
while (ts.isParenthesizedExpression(node)) node = node.expression;
|
|
108
109
|
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression) || node.expression.name.text !== "map" || node.arguments.length !== 1) return;
|
|
109
110
|
const callback = node.arguments[0];
|
|
@@ -116,7 +117,11 @@ async function extractWorkflowGraph(handler) {
|
|
|
116
117
|
} else body = callback.body;
|
|
117
118
|
while (body && (ts.isParenthesizedExpression(body) || ts.isAwaitExpression(body))) body = body.expression;
|
|
118
119
|
if (!body || !durableCall(body) || body.expression.name.text !== "step") return;
|
|
119
|
-
|
|
120
|
+
const template = stepIdTemplate(body.arguments[0], parameters);
|
|
121
|
+
return template === void 0 ? void 0 : {
|
|
122
|
+
call: body,
|
|
123
|
+
template
|
|
124
|
+
};
|
|
120
125
|
}
|
|
121
126
|
function readableOptions(node) {
|
|
122
127
|
return node && ts.isObjectLiteralExpression(node) && node.properties.every(ts.isPropertyAssignment) ? node : void 0;
|
|
@@ -127,14 +132,38 @@ async function extractWorkflowGraph(handler) {
|
|
|
127
132
|
if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
|
|
128
133
|
}
|
|
129
134
|
}
|
|
135
|
+
function stepMetadata(call) {
|
|
136
|
+
const meta = readableOptions(option(readableOptions(call.arguments[2]), "meta"));
|
|
137
|
+
const description = stringLiteral(option(meta, "description"));
|
|
138
|
+
if (description === void 0) return void 0;
|
|
139
|
+
const groupOptions = readableOptions(option(meta, "group"));
|
|
140
|
+
if (!groupOptions) return { description };
|
|
141
|
+
const id = stringLiteral(option(groupOptions, "id"));
|
|
142
|
+
const label = stringLiteral(option(groupOptions, "label"));
|
|
143
|
+
return id === void 0 || label === void 0 ? void 0 : {
|
|
144
|
+
description,
|
|
145
|
+
group: {
|
|
146
|
+
id,
|
|
147
|
+
label
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function durableStepId(argument, options, fallback) {
|
|
152
|
+
if (argument && !options) return void 0;
|
|
153
|
+
const given = option(options, "id");
|
|
154
|
+
return given ? stringLiteral(given) : fallback;
|
|
155
|
+
}
|
|
130
156
|
function durableNode(call, parents) {
|
|
131
157
|
const method = call.expression.name.text;
|
|
132
158
|
if (method === "step") {
|
|
133
159
|
const stepId = stringLiteral(call.arguments[0]);
|
|
134
160
|
if (stepId === void 0) return unknown("Dynamic step IDs are not supported yet", parents);
|
|
161
|
+
const metadata = stepMetadata(call);
|
|
162
|
+
if (!metadata) return unknown("Step descriptions must be static strings", parents);
|
|
135
163
|
return addNode({
|
|
136
164
|
kind: "step",
|
|
137
165
|
stepId,
|
|
166
|
+
description: metadata.description,
|
|
138
167
|
label: stepId
|
|
139
168
|
}, parents);
|
|
140
169
|
}
|
|
@@ -142,11 +171,17 @@ async function extractWorkflowGraph(handler) {
|
|
|
142
171
|
const options = readableOptions(call.arguments[0]);
|
|
143
172
|
const title = stringLiteral(option(options, "title"));
|
|
144
173
|
if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
|
|
174
|
+
const stepId = durableStepId(call.arguments[0], options, defaultDurableId({
|
|
175
|
+
kind: "approve",
|
|
176
|
+
title
|
|
177
|
+
}));
|
|
178
|
+
if (stepId === void 0) return unknown("Dynamic approval IDs are not supported yet", parents);
|
|
145
179
|
const given = option(options, "description");
|
|
146
180
|
const description = stringLiteral(given);
|
|
147
181
|
if (given && description === void 0) degrade("Dynamic approval descriptions are not recorded");
|
|
148
182
|
return addNode({
|
|
149
183
|
kind: "approve",
|
|
184
|
+
stepId,
|
|
150
185
|
config: {
|
|
151
186
|
title,
|
|
152
187
|
...description === void 0 ? {} : { description }
|
|
@@ -158,12 +193,17 @@ async function extractWorkflowGraph(handler) {
|
|
|
158
193
|
const event = stringLiteral(call.arguments[0]);
|
|
159
194
|
if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
|
|
160
195
|
const options = readableOptions(call.arguments[1]);
|
|
161
|
-
|
|
196
|
+
const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
|
|
197
|
+
kind: "waitForEvent",
|
|
198
|
+
name: event
|
|
199
|
+
}));
|
|
200
|
+
if (stepId === void 0) return unknown("Dynamic waitForEvent IDs are not supported yet", parents);
|
|
162
201
|
const given = option(options, "deadline");
|
|
163
202
|
const deadline = numberLiteral(given);
|
|
164
203
|
if (given && deadline === void 0) degrade("Dynamic waitForEvent deadlines are not recorded");
|
|
165
204
|
return addNode({
|
|
166
205
|
kind: "wait-for-event",
|
|
206
|
+
stepId,
|
|
167
207
|
config: {
|
|
168
208
|
event,
|
|
169
209
|
...deadline === void 0 ? {} : { deadline }
|
|
@@ -174,16 +214,30 @@ async function extractWorkflowGraph(handler) {
|
|
|
174
214
|
if (method === "sleep") {
|
|
175
215
|
const ms = numberLiteral(call.arguments[0]);
|
|
176
216
|
if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
|
|
217
|
+
const options = readableOptions(call.arguments[1]);
|
|
218
|
+
const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
|
|
219
|
+
kind: "sleep",
|
|
220
|
+
ms
|
|
221
|
+
}));
|
|
222
|
+
if (stepId === void 0) return unknown("Dynamic sleep IDs are not supported yet", parents);
|
|
177
223
|
return addNode({
|
|
178
224
|
kind: "sleep",
|
|
225
|
+
stepId,
|
|
179
226
|
config: { ms },
|
|
180
227
|
label: `sleep ${ms}ms`
|
|
181
228
|
}, parents);
|
|
182
229
|
}
|
|
183
230
|
const timestamp = numberLiteral(call.arguments[0]);
|
|
184
231
|
if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
|
|
232
|
+
const options = readableOptions(call.arguments[1]);
|
|
233
|
+
const stepId = durableStepId(call.arguments[1], options, defaultDurableId({
|
|
234
|
+
kind: "sleepUntil",
|
|
235
|
+
timestamp
|
|
236
|
+
}));
|
|
237
|
+
if (stepId === void 0) return unknown("Dynamic sleepUntil IDs are not supported yet", parents);
|
|
185
238
|
return addNode({
|
|
186
239
|
kind: "sleep-until",
|
|
240
|
+
stepId,
|
|
187
241
|
config: { timestamp },
|
|
188
242
|
label: `sleep until ${timestamp}`
|
|
189
243
|
}, parents);
|
|
@@ -207,16 +261,22 @@ async function extractWorkflowGraph(handler) {
|
|
|
207
261
|
return ts.isCallExpression(element) ? expression(element, parents, true) : unknown("Dynamic Promise.all entries are not followed", parents);
|
|
208
262
|
}) : parents;
|
|
209
263
|
}
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
kind: "
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
264
|
+
const mapped = mappedStep(argument);
|
|
265
|
+
if (mapped !== void 0) {
|
|
266
|
+
const metadata = stepMetadata(mapped.call);
|
|
267
|
+
if (!metadata?.group) return unknown("Dynamic parallel steps need static group metadata", parents);
|
|
268
|
+
return addNode({
|
|
269
|
+
kind: "parallel",
|
|
270
|
+
groupId: metadata.group.id,
|
|
271
|
+
cardinality: "dynamic",
|
|
272
|
+
operation: {
|
|
273
|
+
kind: "step",
|
|
274
|
+
stepIdTemplate: mapped.template,
|
|
275
|
+
description: metadata.description
|
|
276
|
+
},
|
|
277
|
+
label: metadata.group.label
|
|
278
|
+
}, parents);
|
|
279
|
+
}
|
|
220
280
|
}
|
|
221
281
|
if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child))) return unknown("Helper calls and dynamic expressions are not followed", parents);
|
|
222
282
|
if (ts.isIdentifier(node) && node.text === context) return unknown("Workflow context aliases are not followed", parents);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyWorkflowDefinition, AnyWorkflowDefinition as AnyWorkflowDefinition$1, Ctx, RunStore, StepContext, StepOptions, WorkflowDefinition, WorkflowEvent, WorkflowInput, WorkflowInput as WorkflowInput$1, WorkflowOutput, WorkflowState, createMiddleware, createWorkflow } from "@tanstack/workflow-core";
|
|
1
|
+
import { AnyWorkflowDefinition, AnyWorkflowDefinition as AnyWorkflowDefinition$1, Ctx, RunStore, StepContext, StepOptions, WorkflowDefinition, WorkflowEvent, WorkflowInput, WorkflowInput as WorkflowInput$1, WorkflowMetadata, WorkflowOutput, WorkflowState, createMiddleware, createWorkflow } from "@tanstack/workflow-core";
|
|
2
2
|
import "typescript";
|
|
3
3
|
//#region src/core/cadence.d.ts
|
|
4
4
|
type Weekday = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
|
|
@@ -51,36 +51,53 @@ declare function registerWorkflows<const TWorkflows extends readonly AnyWorkflow
|
|
|
51
51
|
triggers?: readonly TriggerDefinition[];
|
|
52
52
|
}): WorkflowsDefinition<TWorkflows[number]>;
|
|
53
53
|
//#endregion
|
|
54
|
+
//#region src/core/step-metadata.d.ts
|
|
55
|
+
interface WorkflowStepGroup {
|
|
56
|
+
id: string;
|
|
57
|
+
label: string;
|
|
58
|
+
}
|
|
59
|
+
type WorkflowStepMetadata = Record<string, unknown> & {
|
|
60
|
+
description: string;
|
|
61
|
+
group?: WorkflowStepGroup;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
54
64
|
//#region src/manifests/graph.d.ts
|
|
55
65
|
type WorkflowGraphNodeDetails = {
|
|
56
66
|
kind: "step";
|
|
57
67
|
stepId: string;
|
|
68
|
+
description: string;
|
|
58
69
|
} | {
|
|
59
70
|
kind: "parallel";
|
|
71
|
+
groupId: string;
|
|
60
72
|
cardinality: "dynamic";
|
|
61
73
|
operation: {
|
|
62
74
|
kind: "step";
|
|
63
75
|
stepIdTemplate: string;
|
|
76
|
+
description: string;
|
|
64
77
|
};
|
|
65
78
|
} | {
|
|
66
79
|
kind: "approve";
|
|
80
|
+
stepId: string;
|
|
67
81
|
config: {
|
|
68
82
|
title: string;
|
|
69
83
|
description?: string;
|
|
70
84
|
};
|
|
71
85
|
} | {
|
|
72
86
|
kind: "wait-for-event";
|
|
87
|
+
stepId: string;
|
|
73
88
|
config: {
|
|
74
89
|
event: string;
|
|
75
90
|
deadline?: number;
|
|
76
91
|
};
|
|
77
92
|
} | {
|
|
78
93
|
kind: "sleep";
|
|
94
|
+
stepId: string;
|
|
79
95
|
config: {
|
|
80
96
|
ms: number;
|
|
81
97
|
};
|
|
82
98
|
} | {
|
|
83
99
|
kind: "sleep-until";
|
|
100
|
+
stepId: string;
|
|
84
101
|
config: {
|
|
85
102
|
timestamp: number;
|
|
86
103
|
};
|
|
@@ -172,6 +189,7 @@ interface MemoEntry {
|
|
|
172
189
|
/** Key of the step whose body recorded this, if any; a memoized parent hides it. */
|
|
173
190
|
parent?: string;
|
|
174
191
|
kind: StepKind;
|
|
192
|
+
meta?: WorkflowMetadata;
|
|
175
193
|
status: "completed" | "failed";
|
|
176
194
|
result?: unknown;
|
|
177
195
|
error?: string;
|
|
@@ -182,6 +200,7 @@ interface StepIntentBase {
|
|
|
182
200
|
occurrence: number;
|
|
183
201
|
/** Kind-specific detail: sleep `ms`, `waitForEvent` name, approval title. */
|
|
184
202
|
config?: Record<string, unknown>;
|
|
203
|
+
meta?: WorkflowMetadata;
|
|
185
204
|
}
|
|
186
205
|
/** A durable operation the replay reached but could not answer. */
|
|
187
206
|
type StepIntent = StepIntentBase & ({
|
|
@@ -194,6 +213,7 @@ interface StepResult<K extends StepKind = StepKind> {
|
|
|
194
213
|
stepId: string;
|
|
195
214
|
occurrence: number;
|
|
196
215
|
kind: K;
|
|
216
|
+
meta?: WorkflowMetadata;
|
|
197
217
|
status: "completed" | "failed";
|
|
198
218
|
result?: unknown;
|
|
199
219
|
error?: string;
|
|
@@ -268,4 +288,4 @@ declare function createStepsHandler(collection: WorkflowCollection, options?: St
|
|
|
268
288
|
*/
|
|
269
289
|
declare function toServerSentEventsResponse(events: AsyncIterable<WorkflowEvent>): Response;
|
|
270
290
|
//#endregion
|
|
271
|
-
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 WorkflowOutput, type WorkflowState, type WorkflowsDefinition, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
|
|
291
|
+
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 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-
|
|
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-DTzFAh96.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
|
|
@@ -129,6 +129,12 @@ const EXECUTABLE = /* @__PURE__ */ new Set([
|
|
|
129
129
|
function describe(error) {
|
|
130
130
|
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
131
131
|
}
|
|
132
|
+
function groupId(meta) {
|
|
133
|
+
const group = meta?.group;
|
|
134
|
+
if (group === null || typeof group !== "object") return void 0;
|
|
135
|
+
const id = group.id;
|
|
136
|
+
return typeof id === "string" ? id : void 0;
|
|
137
|
+
}
|
|
132
138
|
function runtimeContext() {
|
|
133
139
|
return {
|
|
134
140
|
timeRemaining: () => Number.POSITIVE_INFINITY,
|
|
@@ -178,6 +184,7 @@ async function replay(options) {
|
|
|
178
184
|
stepId: entry.stepId,
|
|
179
185
|
occurrence: entry.occurrence,
|
|
180
186
|
kind: entry.kind,
|
|
187
|
+
...entry.meta ? { meta: entry.meta } : {},
|
|
181
188
|
status: entry.status,
|
|
182
189
|
result: entry.result,
|
|
183
190
|
error: entry.error
|
|
@@ -185,7 +192,7 @@ async function replay(options) {
|
|
|
185
192
|
results.push(result);
|
|
186
193
|
options.onStepSettle?.(result);
|
|
187
194
|
}
|
|
188
|
-
function durable(kind, stepId, run, config, defaulted = false) {
|
|
195
|
+
function durable(kind, stepId, run, config, defaulted = false, meta) {
|
|
189
196
|
const index = seq++;
|
|
190
197
|
const occurrence = occurrences.get(stepId) ?? 0;
|
|
191
198
|
occurrences.set(stepId, occurrence + 1);
|
|
@@ -205,6 +212,11 @@ async function replay(options) {
|
|
|
205
212
|
nonDeterminism = `memo has ${answered.kind} "${stepId}" (#${occurrence}), replay produced ${kind}`;
|
|
206
213
|
return never;
|
|
207
214
|
}
|
|
215
|
+
const recordedGroupId = groupId(answered.meta);
|
|
216
|
+
if (recordedGroupId !== void 0 && recordedGroupId !== groupId(meta)) {
|
|
217
|
+
nonDeterminism = `memo has group "${recordedGroupId}" for step "${stepId}", replay produced a different group`;
|
|
218
|
+
return never;
|
|
219
|
+
}
|
|
208
220
|
if (answered.status === "completed") return Promise.resolve(answered.result);
|
|
209
221
|
return Promise.reject(new Error(answered.error ?? `step "${stepId}" failed`));
|
|
210
222
|
}
|
|
@@ -214,7 +226,8 @@ async function replay(options) {
|
|
|
214
226
|
stepId,
|
|
215
227
|
occurrence,
|
|
216
228
|
kind,
|
|
217
|
-
...config ? { config } : {}
|
|
229
|
+
...config ? { config } : {},
|
|
230
|
+
...meta ? { meta } : {}
|
|
218
231
|
};
|
|
219
232
|
if (!run || !EXECUTABLE.has(kind) || !allow(intent, pass)) {
|
|
220
233
|
pending.push(intent);
|
|
@@ -237,7 +250,8 @@ async function replay(options) {
|
|
|
237
250
|
kind,
|
|
238
251
|
status: "completed",
|
|
239
252
|
result,
|
|
240
|
-
...parent ? { parent } : {}
|
|
253
|
+
...parent ? { parent } : {},
|
|
254
|
+
...meta ? { meta } : {}
|
|
241
255
|
});
|
|
242
256
|
return result;
|
|
243
257
|
}, (error) => {
|
|
@@ -248,7 +262,8 @@ async function replay(options) {
|
|
|
248
262
|
kind,
|
|
249
263
|
status: "failed",
|
|
250
264
|
error: describe(error),
|
|
251
|
-
...parent ? { parent } : {}
|
|
265
|
+
...parent ? { parent } : {},
|
|
266
|
+
...meta ? { meta } : {}
|
|
252
267
|
});
|
|
253
268
|
throw error;
|
|
254
269
|
});
|
|
@@ -264,12 +279,12 @@ async function replay(options) {
|
|
|
264
279
|
state,
|
|
265
280
|
signal: controller.signal,
|
|
266
281
|
runtime,
|
|
267
|
-
step: (id, fn,
|
|
282
|
+
step: (id, fn, stepOptions) => durable("step", id, async () => fn({
|
|
268
283
|
id,
|
|
269
284
|
attempt: 1,
|
|
270
285
|
runtime,
|
|
271
286
|
signal: controller.signal
|
|
272
|
-
})),
|
|
287
|
+
}), void 0, false, stepOptions?.meta),
|
|
273
288
|
sleep: (ms, opts) => durable("sleep", opts?.id ?? defaultDurableId({
|
|
274
289
|
kind: "sleep",
|
|
275
290
|
ms
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { loadTypeScript } from "./graph-BEfFBC6v.js";
|
|
2
|
+
//#region src/manifests/step-metadata.ts
|
|
3
|
+
async function findStepMetadataIssues(handler) {
|
|
4
|
+
const api = await loadTypeScript();
|
|
5
|
+
if (!api) return [];
|
|
6
|
+
const ts = api;
|
|
7
|
+
const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
|
|
8
|
+
const declaration = source.statements[0];
|
|
9
|
+
const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
|
|
10
|
+
if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) return [];
|
|
11
|
+
const parameter = fn.parameters[0]?.name;
|
|
12
|
+
if (!parameter || !ts.isIdentifier(parameter)) return [];
|
|
13
|
+
const context = parameter.text;
|
|
14
|
+
function literalString(node) {
|
|
15
|
+
return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
|
|
16
|
+
}
|
|
17
|
+
function property(node, name) {
|
|
18
|
+
if (!node || !ts.isObjectLiteralExpression(node)) return void 0;
|
|
19
|
+
for (const entry of node.properties) {
|
|
20
|
+
if (!ts.isPropertyAssignment(entry)) continue;
|
|
21
|
+
if ((ts.isIdentifier(entry.name) || ts.isStringLiteral(entry.name) ? entry.name.text : void 0) === name) return entry.initializer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function repeatable(call) {
|
|
25
|
+
let parent = call.parent;
|
|
26
|
+
while (parent && parent !== fn) {
|
|
27
|
+
if (ts.isForStatement(parent) || ts.isForOfStatement(parent) || ts.isForInStatement(parent) || ts.isWhileStatement(parent) || ts.isDoStatement(parent) || ts.isFunctionLike(parent)) return true;
|
|
28
|
+
parent = parent.parent;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const issues = [];
|
|
33
|
+
const groups = /* @__PURE__ */ new Set();
|
|
34
|
+
const visit = (node) => {
|
|
35
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text === "step") {
|
|
36
|
+
const stepId = literalString(node.arguments[0]);
|
|
37
|
+
const meta = property(node.arguments[2], "meta");
|
|
38
|
+
if (literalString(property(meta, "description")) === void 0) issues.push({
|
|
39
|
+
kind: "description",
|
|
40
|
+
...stepId === void 0 ? {} : { stepId }
|
|
41
|
+
});
|
|
42
|
+
if (repeatable(node)) {
|
|
43
|
+
const group = property(meta, "group");
|
|
44
|
+
const groupId = literalString(property(group, "id"));
|
|
45
|
+
const label = literalString(property(group, "label"));
|
|
46
|
+
if (groupId === void 0 || label === void 0) issues.push({
|
|
47
|
+
kind: "group",
|
|
48
|
+
...stepId === void 0 ? {} : { stepId }
|
|
49
|
+
});
|
|
50
|
+
else if (groups.has(groupId)) issues.push({
|
|
51
|
+
kind: "duplicate-group",
|
|
52
|
+
groupId
|
|
53
|
+
});
|
|
54
|
+
else groups.add(groupId);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
ts.forEachChild(node, visit);
|
|
58
|
+
};
|
|
59
|
+
visit(fn);
|
|
60
|
+
return issues;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { findStepMetadataIssues };
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as generateManifests } from "./generate-
|
|
1
|
+
import { t as generateManifests } from "./generate-DTzFAh96.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";
|