@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovable.dev/workflows-sdk",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.52",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"tag": "dev",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"description": "Author workflows for Lovable apps.",
|
|
10
10
|
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
13
14
|
"url": "git+https://github.com/lovablelabs/lovable.git",
|
|
@@ -22,10 +23,6 @@
|
|
|
22
23
|
"./vite": {
|
|
23
24
|
"types": "./dist/vite.d.ts",
|
|
24
25
|
"import": "./dist/vite.js"
|
|
25
|
-
},
|
|
26
|
-
"./stacks/tanstack": {
|
|
27
|
-
"types": "./dist/stacks/tanstack/index.d.ts",
|
|
28
|
-
"import": "./dist/stacks/tanstack/index.js"
|
|
29
26
|
}
|
|
30
27
|
},
|
|
31
28
|
"files": [
|
|
@@ -33,9 +30,11 @@
|
|
|
33
30
|
],
|
|
34
31
|
"dependencies": {
|
|
35
32
|
"@standard-schema/spec": "^1.1.0",
|
|
36
|
-
"@tanstack/workflow-core": "0.0.4"
|
|
33
|
+
"@tanstack/workflow-core": "0.0.4",
|
|
34
|
+
"@lovable.dev/ai-gateway": "0.1.9"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
37
|
+
"@bufbuild/protobuf": "^2.10.1",
|
|
39
38
|
"@types/node": "22.13.13",
|
|
40
39
|
"vite": "^7.3.1",
|
|
41
40
|
"zod": "^4.1.13",
|
|
@@ -55,7 +54,7 @@
|
|
|
55
54
|
}
|
|
56
55
|
},
|
|
57
56
|
"scripts": {
|
|
58
|
-
"build": "tsdown",
|
|
57
|
+
"build": "pnpm --filter @lovable.dev/workflows-sdk^... build && tsdown",
|
|
59
58
|
"test": "node --test tests/*.test.mjs",
|
|
60
59
|
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
61
60
|
"check:package": "tmp=$(mktemp -d) && pnpm pack --out \"$tmp/pkg.tgz\" && tar -xzf \"$tmp/pkg.tgz\" -C \"$tmp\" && publint \"$tmp/package\" --strict && attw \"$tmp/pkg.tgz\" && node scripts/check-deps.mjs \"$tmp/package/package.json\""
|
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
import { createMiddleware, createWorkflow } from "@tanstack/workflow-core";
|
|
2
|
-
//#region src/core/identifier.ts
|
|
3
|
-
function assertIdentifier(kind, id) {
|
|
4
|
-
if (typeof id !== "string" || id.trim() === "" || id !== id.trim()) throw new Error(`@lovable.dev/workflows-sdk: ${kind} IDs must be non-empty and have no surrounding whitespace`);
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/core/cadence.ts
|
|
8
|
-
const MINUTE_DIVISORS = [
|
|
9
|
-
1,
|
|
10
|
-
2,
|
|
11
|
-
3,
|
|
12
|
-
4,
|
|
13
|
-
5,
|
|
14
|
-
6,
|
|
15
|
-
10,
|
|
16
|
-
12,
|
|
17
|
-
15,
|
|
18
|
-
20,
|
|
19
|
-
30
|
|
20
|
-
];
|
|
21
|
-
const HOUR_DIVISORS = [
|
|
22
|
-
1,
|
|
23
|
-
2,
|
|
24
|
-
3,
|
|
25
|
-
4,
|
|
26
|
-
6,
|
|
27
|
-
8,
|
|
28
|
-
12
|
|
29
|
-
];
|
|
30
|
-
const WEEKDAYS = [
|
|
31
|
-
"mon",
|
|
32
|
-
"tue",
|
|
33
|
-
"wed",
|
|
34
|
-
"thu",
|
|
35
|
-
"fri",
|
|
36
|
-
"sat",
|
|
37
|
-
"sun"
|
|
38
|
-
];
|
|
39
|
-
const WEEKDAY_NAMES = {
|
|
40
|
-
mon: "mon",
|
|
41
|
-
monday: "mon",
|
|
42
|
-
tue: "tue",
|
|
43
|
-
tuesday: "tue",
|
|
44
|
-
wed: "wed",
|
|
45
|
-
wednesday: "wed",
|
|
46
|
-
thu: "thu",
|
|
47
|
-
thursday: "thu",
|
|
48
|
-
fri: "fri",
|
|
49
|
-
friday: "fri",
|
|
50
|
-
sat: "sat",
|
|
51
|
-
saturday: "sat",
|
|
52
|
-
sun: "sun",
|
|
53
|
-
sunday: "sun"
|
|
54
|
-
};
|
|
55
|
-
const CRON_DAY = {
|
|
56
|
-
sun: 0,
|
|
57
|
-
mon: 1,
|
|
58
|
-
tue: 2,
|
|
59
|
-
wed: 3,
|
|
60
|
-
thu: 4,
|
|
61
|
-
fri: 5,
|
|
62
|
-
sat: 6
|
|
63
|
-
};
|
|
64
|
-
function fail$1(message) {
|
|
65
|
-
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
66
|
-
}
|
|
67
|
-
function parseWeekday(value, label) {
|
|
68
|
-
const day = typeof value === "string" ? WEEKDAY_NAMES[value.toLowerCase()] : void 0;
|
|
69
|
-
if (day === void 0) fail$1(`${label} names an unknown day "${String(value)}"; use ${WEEKDAYS.join(", ")}`);
|
|
70
|
-
return day;
|
|
71
|
-
}
|
|
72
|
-
function parseDays(value, label) {
|
|
73
|
-
if (!Array.isArray(value) || value.length === 0) fail$1(`${label} must be a non-empty array of days`);
|
|
74
|
-
const days = [...new Set(value.map((entry) => parseWeekday(entry, label)))].sort((a, b) => WEEKDAYS.indexOf(a) - WEEKDAYS.indexOf(b));
|
|
75
|
-
return days.length === WEEKDAYS.length ? null : days;
|
|
76
|
-
}
|
|
77
|
-
function parseTimeOfDay(value, label) {
|
|
78
|
-
if (typeof value !== "string" || !/^([01][0-9]|2[0-3]):[0-5][0-9]$/.test(value)) fail$1(`${label}: "${String(value)}" must be a 24-hour "HH:MM" time`);
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
function every(interval) {
|
|
82
|
-
if (typeof interval !== "string" || !/^[0-9]+[mhd]$/.test(interval)) fail$1(`every("${String(interval)}") must be a whole number of minutes, hours, or days, such as "5m", "2h", or "1d"`);
|
|
83
|
-
const amount = Number(interval.slice(0, -1));
|
|
84
|
-
const unit = interval.slice(-1);
|
|
85
|
-
if (amount < 1) fail$1(`every("${interval}") must be at least one unit`);
|
|
86
|
-
if (unit === "m" && !MINUTE_DIVISORS.includes(amount)) fail$1(`every("${interval}") must divide an hour evenly: ${MINUTE_DIVISORS.map((n) => `${n}m`).join(", ")}`);
|
|
87
|
-
if (unit === "h" && !HOUR_DIVISORS.includes(amount)) fail$1(`every("${interval}") must divide a day evenly: ${HOUR_DIVISORS.map((n) => `${n}h`).join(", ")}`);
|
|
88
|
-
if (unit === "d" && amount !== 1) fail$1(`every("${interval}") supports only "1d"; use daily() for calendar days`);
|
|
89
|
-
return {
|
|
90
|
-
kind: "every",
|
|
91
|
-
seconds: amount * (unit === "m" ? 60 : unit === "h" ? 3600 : 86400)
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function hourly(options = {}) {
|
|
95
|
-
if (options.at === void 0) return {
|
|
96
|
-
kind: "hourly",
|
|
97
|
-
minute: null
|
|
98
|
-
};
|
|
99
|
-
if (typeof options.at !== "string" || !/^:[0-5][0-9]$/.test(options.at)) fail$1(`hourly({ at: "${String(options.at)}" }) must pin a minute past the hour, such as ":30"`);
|
|
100
|
-
return {
|
|
101
|
-
kind: "hourly",
|
|
102
|
-
minute: Number(options.at.slice(1))
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function daily(options = {}) {
|
|
106
|
-
return {
|
|
107
|
-
kind: "daily",
|
|
108
|
-
at: options.at === void 0 ? null : parseTimeOfDay(options.at, "daily({ at })"),
|
|
109
|
-
days: options.days === void 0 ? null : parseDays(options.days, "daily({ days })")
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function weekly(options) {
|
|
113
|
-
if (typeof options !== "object" || options === null) fail$1(`weekly() requires { on: "monday", at: "07:00" }`);
|
|
114
|
-
return {
|
|
115
|
-
kind: "daily",
|
|
116
|
-
at: options.at === void 0 ? null : parseTimeOfDay(options.at, "weekly({ at })"),
|
|
117
|
-
days: [parseWeekday(options.on, "weekly({ on })")]
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function isCadence(value) {
|
|
121
|
-
if (typeof value !== "object" || value === null) return false;
|
|
122
|
-
const kind = value.kind;
|
|
123
|
-
return kind === "every" || kind === "hourly" || kind === "daily";
|
|
124
|
-
}
|
|
125
|
-
function cronDayField(days) {
|
|
126
|
-
if (days === null) return "*";
|
|
127
|
-
const numbers = days.map((day) => CRON_DAY[day]).sort((a, b) => a - b);
|
|
128
|
-
const parts = [];
|
|
129
|
-
let start = 0;
|
|
130
|
-
for (let index = 1; index <= numbers.length; index += 1) {
|
|
131
|
-
if (index < numbers.length && numbers[index] === numbers[index - 1] + 1) continue;
|
|
132
|
-
const run = numbers.slice(start, index);
|
|
133
|
-
parts.push(run.length >= 3 ? `${run[0]}-${run[run.length - 1]}` : run.join(","));
|
|
134
|
-
start = index;
|
|
135
|
-
}
|
|
136
|
-
return parts.join(",");
|
|
137
|
-
}
|
|
138
|
-
function cadenceCron(cadence) {
|
|
139
|
-
if (cadence.kind === "every") {
|
|
140
|
-
const seconds = cadence.seconds;
|
|
141
|
-
if (seconds < 3600) return `*/${seconds / 60} * * * *`;
|
|
142
|
-
if (seconds < 86400) return `0 */${seconds / 3600} * * *`;
|
|
143
|
-
return "0 0 * * *";
|
|
144
|
-
}
|
|
145
|
-
if (cadence.kind === "hourly") return `${cadence.minute ?? 0} * * * *`;
|
|
146
|
-
const [hour, minute] = (cadence.at ?? "00:00").split(":");
|
|
147
|
-
return `${Number(minute)} ${Number(hour)} * * ${cronDayField(cadence.days)}`;
|
|
148
|
-
}
|
|
149
|
-
function cadencePeriodSeconds(cadence) {
|
|
150
|
-
if (cadence.kind === "every") return cadence.seconds;
|
|
151
|
-
if (cadence.kind === "hourly") return 3600;
|
|
152
|
-
if (cadence.days === null) return 86400;
|
|
153
|
-
const indexes = cadence.days.map((day) => WEEKDAYS.indexOf(day)).sort((a, b) => a - b);
|
|
154
|
-
let gap = WEEKDAYS.length - indexes[indexes.length - 1] + indexes[0];
|
|
155
|
-
for (let index = 1; index < indexes.length; index += 1) gap = Math.min(gap, indexes[index] - indexes[index - 1]);
|
|
156
|
-
return gap * 86400;
|
|
157
|
-
}
|
|
158
|
-
function parseWindowSeconds(interval, id) {
|
|
159
|
-
if (typeof interval !== "string" || !/^[0-9]+[mhd]$/.test(interval)) fail$1(`schedule "${id}" smear window must be an interval such as "15m", "1h", or "1d"`);
|
|
160
|
-
const amount = Number(interval.slice(0, -1));
|
|
161
|
-
const unit = interval.slice(-1);
|
|
162
|
-
const seconds = amount * (unit === "m" ? 60 : unit === "h" ? 3600 : 86400);
|
|
163
|
-
if (seconds < 60 || seconds > 86400) fail$1(`schedule "${id}" smear window must be between "1m" and "1d"`);
|
|
164
|
-
return seconds;
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/core/schedule.ts
|
|
168
|
-
const OVERLAP_POLICIES = [
|
|
169
|
-
"skip",
|
|
170
|
-
"cancel-previous",
|
|
171
|
-
"terminate-previous"
|
|
172
|
-
];
|
|
173
|
-
function fail(message) {
|
|
174
|
-
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
175
|
-
}
|
|
176
|
-
function resolveTimeZone(schedule) {
|
|
177
|
-
const timeZone = schedule.timeZone;
|
|
178
|
-
if (typeof timeZone !== "string" || timeZone === "") fail(`schedule "${schedule.id}" needs a timeZone, such as "Europe/Stockholm" or "UTC"`);
|
|
179
|
-
if (timeZone !== "UTC" && !timeZone.includes("/")) fail(`schedule "${schedule.id}" timeZone "${timeZone}" must be an IANA region name such as "Europe/Stockholm", not a fixed offset or abbreviation`);
|
|
180
|
-
new Intl.DateTimeFormat("en", { timeZone });
|
|
181
|
-
return timeZone;
|
|
182
|
-
}
|
|
183
|
-
function unpinnedWindowSeconds(cadence) {
|
|
184
|
-
if (cadence.kind === "daily" && cadence.at === null) return 86400;
|
|
185
|
-
if (cadence.kind === "hourly" && cadence.minute === null) return 3600;
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
function resolveSmear(schedule, cadence) {
|
|
189
|
-
const unpinned = unpinnedWindowSeconds(cadence);
|
|
190
|
-
if (schedule.smear === void 0) return unpinned === null ? { strategy: "none" } : {
|
|
191
|
-
strategy: "hash",
|
|
192
|
-
windowSeconds: unpinned
|
|
193
|
-
};
|
|
194
|
-
if (schedule.smear === false || typeof schedule.smear === "object" && "strategy" in schedule.smear && schedule.smear.strategy === "none") {
|
|
195
|
-
if (unpinned !== null) fail(`schedule "${schedule.id}" uses ${cadence.kind}() with no time; pass { at } or keep the smear`);
|
|
196
|
-
return { strategy: "none" };
|
|
197
|
-
}
|
|
198
|
-
if (typeof schedule.smear !== "object") fail(`schedule "${schedule.id}" smear must be false or { window }`);
|
|
199
|
-
const windowSeconds = "window" in schedule.smear ? parseWindowSeconds(schedule.smear.window, schedule.id) : schedule.smear.windowSeconds;
|
|
200
|
-
const period = cadencePeriodSeconds(cadence);
|
|
201
|
-
if (windowSeconds > period) fail(`schedule "${schedule.id}" smear window must not exceed its ${period}s firing period`);
|
|
202
|
-
return {
|
|
203
|
-
strategy: "hash",
|
|
204
|
-
windowSeconds
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function defineSchedule(schedule) {
|
|
208
|
-
assertIdentifier("schedule", schedule.id);
|
|
209
|
-
if (!isCadence(schedule.cadence)) fail(`schedule "${schedule.id}" cadence must come from every(), hourly(), daily(), or weekly()`);
|
|
210
|
-
const cadence = schedule.cadence;
|
|
211
|
-
const cron = cadenceCron(cadence);
|
|
212
|
-
const timeZone = resolveTimeZone(schedule);
|
|
213
|
-
const overlapPolicy = schedule.overlapPolicy ?? "skip";
|
|
214
|
-
if (!OVERLAP_POLICIES.includes(overlapPolicy)) fail(`schedule "${schedule.id}" overlapPolicy must be one of ${OVERLAP_POLICIES.join(", ")}`);
|
|
215
|
-
const enabled = schedule.enabled ?? true;
|
|
216
|
-
if (typeof enabled !== "boolean") fail(`schedule "${schedule.id}" enabled must be a boolean`);
|
|
217
|
-
return {
|
|
218
|
-
...schedule,
|
|
219
|
-
type: "schedule",
|
|
220
|
-
cadence,
|
|
221
|
-
cron,
|
|
222
|
-
timeZone,
|
|
223
|
-
overlapPolicy,
|
|
224
|
-
enabled,
|
|
225
|
-
smear: resolveSmear(schedule, cadence)
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/core/workflow.ts
|
|
230
|
-
function registerWorkflows({ workflows, triggers = [] }) {
|
|
231
|
-
const ids = /* @__PURE__ */ new Set();
|
|
232
|
-
for (const workflow of workflows) {
|
|
233
|
-
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
|
|
234
|
-
assertIdentifier("workflow", workflow.id);
|
|
235
|
-
if (!/^[a-z0-9][a-z0-9_-]{0,127}$/.test(workflow.id)) throw new Error("@lovable.dev/workflows-sdk: workflow names must be 1–128 lowercase letters, digits, hyphens or underscores, starting with a letter or digit");
|
|
236
|
-
if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
|
|
237
|
-
ids.add(workflow.id);
|
|
238
|
-
}
|
|
239
|
-
const scheduleIds = /* @__PURE__ */ new Set();
|
|
240
|
-
const registeredTriggers = triggers.map((trigger) => {
|
|
241
|
-
const definition = defineSchedule(trigger);
|
|
242
|
-
if (scheduleIds.has(definition.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate schedule ID "${definition.id}"`);
|
|
243
|
-
if (!workflows.includes(definition.workflow)) throw new Error(`@lovable.dev/workflows-sdk: schedule "${definition.id}" references an unregistered workflow`);
|
|
244
|
-
scheduleIds.add(definition.id);
|
|
245
|
-
return definition;
|
|
246
|
-
});
|
|
247
|
-
return {
|
|
248
|
-
workflows: [...workflows],
|
|
249
|
-
triggers: registeredTriggers
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region src/manifests/json.ts
|
|
254
|
-
function toJson(value, jsonPath, ancestors = /* @__PURE__ */ new Set()) {
|
|
255
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
256
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
257
|
-
if (typeof value !== "object" || ancestors.has(value)) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain finite, acyclic JSON values`);
|
|
258
|
-
ancestors.add(value);
|
|
259
|
-
try {
|
|
260
|
-
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must not contain symbol keys`);
|
|
261
|
-
if (Array.isArray(value)) {
|
|
262
|
-
if (Object.keys(value).length !== value.length) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must be a dense JSON array without extra properties`);
|
|
263
|
-
return Array.from(value, (item, index) => toJson(item, `${jsonPath}[${index}]`, ancestors));
|
|
264
|
-
}
|
|
265
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain plain JSON objects`);
|
|
266
|
-
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, toJson(value[key], `${jsonPath}.${key}`, ancestors)]));
|
|
267
|
-
} finally {
|
|
268
|
-
ancestors.delete(value);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
//#endregion
|
|
272
|
-
//#region src/manifests/generate.ts
|
|
273
|
-
function serializeSchema(schema, direction, label) {
|
|
274
|
-
if (!schema) return void 0;
|
|
275
|
-
const standard = schema["~standard"];
|
|
276
|
-
if (typeof standard.jsonSchema?.[direction] !== "function") throw new Error(`@lovable.dev/workflows-sdk: ${label} must support Standard JSON Schema conversion`);
|
|
277
|
-
try {
|
|
278
|
-
return toJson(standard.jsonSchema[direction]({ target: "draft-2020-12" }), label);
|
|
279
|
-
} catch (cause) {
|
|
280
|
-
throw new Error(`@lovable.dev/workflows-sdk: cannot serialize ${label}`, { cause });
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
async function generateManifests(definition) {
|
|
284
|
-
const { extractWorkflowGraph } = await import("./graph-BgdiEUHq.js");
|
|
285
|
-
const collection = registerWorkflows(definition);
|
|
286
|
-
const manifests = [];
|
|
287
|
-
for (const workflow of collection.workflows) {
|
|
288
|
-
if (workflow.previousVersions?.length) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" previousVersions are not supported yet`);
|
|
289
|
-
const metadata = {
|
|
290
|
-
id: workflow.id,
|
|
291
|
-
...workflow.description === void 0 ? {} : { description: workflow.description },
|
|
292
|
-
...workflow.version === void 0 ? {} : { version: workflow.version },
|
|
293
|
-
...workflow.inputSchema ? { inputSchema: serializeSchema(workflow.inputSchema, "input", `${workflow.id}.input`) } : {},
|
|
294
|
-
...workflow.outputSchema ? { outputSchema: serializeSchema(workflow.outputSchema, "output", `${workflow.id}.output`) } : {},
|
|
295
|
-
...workflow.stateSchema ? { stateSchema: serializeSchema(workflow.stateSchema, "output", `${workflow.id}.state`) } : {}
|
|
296
|
-
};
|
|
297
|
-
const triggers = [];
|
|
298
|
-
for (const schedule of collection.triggers.filter((trigger) => trigger.workflow === workflow)) {
|
|
299
|
-
const input = toJson(schedule.input, `schedule "${schedule.id}" input`);
|
|
300
|
-
const schema = schedule.workflow.inputSchema;
|
|
301
|
-
if (schema) {
|
|
302
|
-
const result = await schema["~standard"].validate(input);
|
|
303
|
-
if (result.issues) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" input is invalid: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
304
|
-
}
|
|
305
|
-
triggers.push({
|
|
306
|
-
type: schedule.type,
|
|
307
|
-
id: schedule.id,
|
|
308
|
-
cadence: schedule.cadence,
|
|
309
|
-
cron: schedule.cron,
|
|
310
|
-
timeZone: schedule.timeZone,
|
|
311
|
-
enabled: schedule.enabled,
|
|
312
|
-
overlapPolicy: schedule.overlapPolicy,
|
|
313
|
-
smear: schedule.smear,
|
|
314
|
-
input
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
triggers.sort((a, b) => {
|
|
318
|
-
const key = (entry) => `${entry.type}\u0000${entry.id}`;
|
|
319
|
-
return key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0;
|
|
320
|
-
});
|
|
321
|
-
const manifest = {
|
|
322
|
-
version: 1,
|
|
323
|
-
workflow: metadata,
|
|
324
|
-
triggers,
|
|
325
|
-
graph: await extractWorkflowGraph(workflow.handler)
|
|
326
|
-
};
|
|
327
|
-
toJson(manifest, "manifest");
|
|
328
|
-
manifests.push(manifest);
|
|
329
|
-
}
|
|
330
|
-
return manifests.sort((a, b) => a.workflow.id < b.workflow.id ? -1 : a.workflow.id > b.workflow.id ? 1 : 0);
|
|
331
|
-
}
|
|
332
|
-
//#endregion
|
|
333
|
-
export { defineSchedule as a, hourly as c, registerWorkflows as i, weekly as l, createMiddleware as n, daily as o, createWorkflow as r, every as s, generateManifests as t };
|
package/dist/graph-BgdiEUHq.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
//#region src/manifests/graph.ts
|
|
2
|
-
const durableMethods = {
|
|
3
|
-
step: 0,
|
|
4
|
-
approve: 0,
|
|
5
|
-
waitForEvent: 0,
|
|
6
|
-
sleep: 0,
|
|
7
|
-
sleepUntil: 0
|
|
8
|
-
};
|
|
9
|
-
let loaded;
|
|
10
|
-
async function loadTypeScript() {
|
|
11
|
-
if (loaded !== void 0) return loaded;
|
|
12
|
-
try {
|
|
13
|
-
const module = await import("typescript");
|
|
14
|
-
const api = module.default ?? module;
|
|
15
|
-
loaded = typeof api?.createSourceFile === "function" ? api : null;
|
|
16
|
-
} catch {
|
|
17
|
-
loaded = null;
|
|
18
|
-
}
|
|
19
|
-
return loaded;
|
|
20
|
-
}
|
|
21
|
-
async function extractWorkflowGraph(handler) {
|
|
22
|
-
const graph = {
|
|
23
|
-
source: "inferred",
|
|
24
|
-
scope: "handler",
|
|
25
|
-
complete: true,
|
|
26
|
-
nodes: [],
|
|
27
|
-
edges: [],
|
|
28
|
-
diagnostics: []
|
|
29
|
-
};
|
|
30
|
-
function addNode(node, parents) {
|
|
31
|
-
const id = `node-${graph.nodes.length}`;
|
|
32
|
-
graph.nodes.push({
|
|
33
|
-
id,
|
|
34
|
-
...node
|
|
35
|
-
});
|
|
36
|
-
for (const parent of new Set(parents)) graph.edges.push({
|
|
37
|
-
source: parent,
|
|
38
|
-
target: id,
|
|
39
|
-
kind: "order"
|
|
40
|
-
});
|
|
41
|
-
return [id];
|
|
42
|
-
}
|
|
43
|
-
function degrade(reason) {
|
|
44
|
-
graph.complete = false;
|
|
45
|
-
if (!graph.diagnostics.includes(reason)) graph.diagnostics.push(reason);
|
|
46
|
-
}
|
|
47
|
-
function unknown(reason, parents) {
|
|
48
|
-
degrade(reason);
|
|
49
|
-
return addNode({
|
|
50
|
-
kind: "unknown",
|
|
51
|
-
label: reason
|
|
52
|
-
}, parents);
|
|
53
|
-
}
|
|
54
|
-
const api = await loadTypeScript();
|
|
55
|
-
if (!api) {
|
|
56
|
-
unknown("Install typescript to infer step graphs", []);
|
|
57
|
-
return graph;
|
|
58
|
-
}
|
|
59
|
-
const ts = api;
|
|
60
|
-
const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
|
|
61
|
-
const declaration = source.statements[0];
|
|
62
|
-
const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
|
|
63
|
-
if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) {
|
|
64
|
-
unknown("Handler source is unavailable", []);
|
|
65
|
-
return graph;
|
|
66
|
-
}
|
|
67
|
-
const parameter = fn.parameters[0]?.name;
|
|
68
|
-
if (parameter && !ts.isIdentifier(parameter)) {
|
|
69
|
-
unknown("Destructured workflow context is not supported yet", []);
|
|
70
|
-
return graph;
|
|
71
|
-
}
|
|
72
|
-
const context = parameter?.text;
|
|
73
|
-
function contains(node, predicate, skipFunctions = false) {
|
|
74
|
-
if (skipFunctions && ts.isFunctionLike(node)) return false;
|
|
75
|
-
return predicate(node) || Boolean(ts.forEachChild(node, (child) => contains(child, predicate, skipFunctions) || void 0));
|
|
76
|
-
}
|
|
77
|
-
function durableCall(node) {
|
|
78
|
-
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text in durableMethods;
|
|
79
|
-
}
|
|
80
|
-
function stringLiteral(node) {
|
|
81
|
-
return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
|
|
82
|
-
}
|
|
83
|
-
function numberLiteral(node) {
|
|
84
|
-
if (!node || !ts.isNumericLiteral(node)) return void 0;
|
|
85
|
-
const value = Number(node.text);
|
|
86
|
-
return Number.isFinite(value) ? value : void 0;
|
|
87
|
-
}
|
|
88
|
-
function readableOptions(node) {
|
|
89
|
-
return node && ts.isObjectLiteralExpression(node) && node.properties.every(ts.isPropertyAssignment) ? node : void 0;
|
|
90
|
-
}
|
|
91
|
-
function option(options, name) {
|
|
92
|
-
for (const property of options?.properties ?? []) {
|
|
93
|
-
if (!ts.isPropertyAssignment(property)) continue;
|
|
94
|
-
if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function durableNode(call, parents) {
|
|
98
|
-
const method = call.expression.name.text;
|
|
99
|
-
if (method === "step") {
|
|
100
|
-
const stepId = stringLiteral(call.arguments[0]);
|
|
101
|
-
if (stepId === void 0) return unknown("Dynamic step IDs are not supported yet", parents);
|
|
102
|
-
return addNode({
|
|
103
|
-
kind: "step",
|
|
104
|
-
stepId,
|
|
105
|
-
label: stepId
|
|
106
|
-
}, parents);
|
|
107
|
-
}
|
|
108
|
-
if (method === "approve") {
|
|
109
|
-
const options = readableOptions(call.arguments[0]);
|
|
110
|
-
const title = stringLiteral(option(options, "title"));
|
|
111
|
-
if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
|
|
112
|
-
const given = option(options, "description");
|
|
113
|
-
const description = stringLiteral(given);
|
|
114
|
-
if (given && description === void 0) degrade("Dynamic approval descriptions are not recorded");
|
|
115
|
-
return addNode({
|
|
116
|
-
kind: "approve",
|
|
117
|
-
config: {
|
|
118
|
-
title,
|
|
119
|
-
...description === void 0 ? {} : { description }
|
|
120
|
-
},
|
|
121
|
-
label: title
|
|
122
|
-
}, parents);
|
|
123
|
-
}
|
|
124
|
-
if (method === "waitForEvent") {
|
|
125
|
-
const event = stringLiteral(call.arguments[0]);
|
|
126
|
-
if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
|
|
127
|
-
const options = readableOptions(call.arguments[1]);
|
|
128
|
-
if (call.arguments[1] && !options) degrade("Dynamic waitForEvent options are not recorded");
|
|
129
|
-
const given = option(options, "deadline");
|
|
130
|
-
const deadline = numberLiteral(given);
|
|
131
|
-
if (given && deadline === void 0) degrade("Dynamic waitForEvent deadlines are not recorded");
|
|
132
|
-
return addNode({
|
|
133
|
-
kind: "wait-for-event",
|
|
134
|
-
config: {
|
|
135
|
-
event,
|
|
136
|
-
...deadline === void 0 ? {} : { deadline }
|
|
137
|
-
},
|
|
138
|
-
label: event
|
|
139
|
-
}, parents);
|
|
140
|
-
}
|
|
141
|
-
if (method === "sleep") {
|
|
142
|
-
const ms = numberLiteral(call.arguments[0]);
|
|
143
|
-
if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
|
|
144
|
-
return addNode({
|
|
145
|
-
kind: "sleep",
|
|
146
|
-
config: { ms },
|
|
147
|
-
label: `sleep ${ms}ms`
|
|
148
|
-
}, parents);
|
|
149
|
-
}
|
|
150
|
-
const timestamp = numberLiteral(call.arguments[0]);
|
|
151
|
-
if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
|
|
152
|
-
return addNode({
|
|
153
|
-
kind: "sleep-until",
|
|
154
|
-
config: { timestamp },
|
|
155
|
-
label: `sleep until ${timestamp}`
|
|
156
|
-
}, parents);
|
|
157
|
-
}
|
|
158
|
-
function expression(node, parents, awaited = false) {
|
|
159
|
-
if (ts.isParenthesizedExpression(node)) return expression(node.expression, parents, awaited);
|
|
160
|
-
if (ts.isAwaitExpression(node)) return expression(node.expression, parents, true);
|
|
161
|
-
if (durableCall(node)) {
|
|
162
|
-
if (!awaited) return unknown("Unawaited durable calls are not supported yet", parents);
|
|
163
|
-
const tails = durableNode(node, parents);
|
|
164
|
-
if (node.arguments.some((argument) => contains(argument, durableCall))) return unknown("Nested durable calls are not supported yet", tails);
|
|
165
|
-
return tails;
|
|
166
|
-
}
|
|
167
|
-
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 && ts.isArrayLiteralExpression(node.arguments[0])) {
|
|
168
|
-
const elements = node.arguments[0].elements;
|
|
169
|
-
if (elements.some((element) => contains(element, ts.isAwaitExpression, true))) return unknown("Await expressions inside Promise.all are not supported yet", parents);
|
|
170
|
-
return elements.length > 0 ? elements.flatMap((element) => {
|
|
171
|
-
while (ts.isParenthesizedExpression(element)) element = element.expression;
|
|
172
|
-
return ts.isCallExpression(element) ? expression(element, parents, true) : unknown("Dynamic Promise.all entries are not followed", parents);
|
|
173
|
-
}) : parents;
|
|
174
|
-
}
|
|
175
|
-
if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child))) return unknown("Helper calls and dynamic expressions are not followed", parents);
|
|
176
|
-
if (ts.isIdentifier(node) && node.text === context) return unknown("Workflow context aliases are not followed", parents);
|
|
177
|
-
return parents;
|
|
178
|
-
}
|
|
179
|
-
let tails = [];
|
|
180
|
-
if (!ts.isBlock(fn.body)) {
|
|
181
|
-
expression(fn.body, tails, true);
|
|
182
|
-
return graph;
|
|
183
|
-
}
|
|
184
|
-
for (const statement of fn.body.statements) {
|
|
185
|
-
if (ts.isReturnStatement(statement)) {
|
|
186
|
-
if (statement.expression) expression(statement.expression, tails, true);
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
if (ts.isVariableStatement(statement)) {
|
|
190
|
-
if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context)))) {
|
|
191
|
-
tails = unknown("Shadowed context or Promise bindings are not supported yet", tails);
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
for (const item of statement.declarationList.declarations) if (item.initializer) tails = expression(item.initializer, tails);
|
|
195
|
-
} else if (ts.isExpressionStatement(statement)) tails = expression(statement.expression, tails);
|
|
196
|
-
else tails = unknown("Branches, loops, and other control flow are not supported yet", tails);
|
|
197
|
-
}
|
|
198
|
-
return graph;
|
|
199
|
-
}
|
|
200
|
-
//#endregion
|
|
201
|
-
export { extractWorkflowGraph };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { AnyWorkflowDefinition, RunStore, WorkflowEvent } from "@tanstack/workflow-core";
|
|
2
|
-
//#region src/stacks/tanstack/handlers.d.ts
|
|
3
|
-
/** The shape `registerWorkflows()` returns; only the list is needed to dispatch. */
|
|
4
|
-
interface WorkflowCollection {
|
|
5
|
-
readonly workflows: readonly AnyWorkflowDefinition[];
|
|
6
|
-
}
|
|
7
|
-
interface TanStackWorkflowHandlerOptions {
|
|
8
|
-
/** @default a process-local `inMemoryRunStore()`, lost on restart */
|
|
9
|
-
runStore?: RunStore;
|
|
10
|
-
/**
|
|
11
|
-
* Route parameter carrying the workflow ID.
|
|
12
|
-
* @default "workflowId"
|
|
13
|
-
*/
|
|
14
|
-
workflowIdParam?: string;
|
|
15
|
-
}
|
|
16
|
-
interface TanStackRouteCtx {
|
|
17
|
-
request: Request;
|
|
18
|
-
params?: Record<string, string | undefined>;
|
|
19
|
-
}
|
|
20
|
-
type TanStackWorkflowHandler = (ctx: TanStackRouteCtx) => Promise<Response>;
|
|
21
|
-
/** Build a TanStack Start `POST` handler serving every workflow in the collection. */
|
|
22
|
-
declare function createTanStackWorkflowHandler(collection: WorkflowCollection, options?: TanStackWorkflowHandlerOptions): TanStackWorkflowHandler;
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/stacks/tanstack/sse.d.ts
|
|
25
|
-
/**
|
|
26
|
-
* Encode a workflow event stream as `text/event-stream`. Each event keeps its
|
|
27
|
-
* engine `type` as the SSE event name and its whole JSON as the data line.
|
|
28
|
-
*/
|
|
29
|
-
declare function toServerSentEventsResponse(events: AsyncIterable<WorkflowEvent>): Response;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { type TanStackWorkflowHandler, type TanStackWorkflowHandlerOptions, type WorkflowCollection, createTanStackWorkflowHandler, toServerSentEventsResponse };
|