@lovable.dev/workflows-sdk 0.0.0-dev.1 → 0.0.0-dev.11
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 +507 -28
- package/dist/duplicate-ids-CSzTGBYE.js +115 -0
- package/dist/durable-ids-LsygHSZC.js +17 -0
- package/dist/generate-DkZJkfZ1.js +235 -0
- package/dist/{graph-extract-SXSdcip0.js → graph-CPDci8jW.js} +117 -18
- package/dist/index.d.ts +195 -21
- package/dist/index.js +663 -3
- package/dist/vite.d.ts +18 -5
- package/dist/vite.js +303 -9
- package/package.json +12 -7
- package/dist/manifest-DYEhsHr3.js +0 -114
package/dist/vite.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as generateManifests } from "./
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
1
|
+
import { t as generateManifests } from "./generate-DkZJkfZ1.js";
|
|
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";
|
|
5
|
-
|
|
5
|
+
import { lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
+
//#region src/vite/manifest-files.ts
|
|
6
7
|
async function ensureDirectory(path) {
|
|
7
8
|
try {
|
|
8
9
|
await mkdir(path);
|
|
@@ -30,14 +31,307 @@ async function writeManifests(root, manifests) {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
//#endregion
|
|
33
|
-
//#region src/vite.ts
|
|
34
|
-
function
|
|
34
|
+
//#region src/vite/alias.ts
|
|
35
|
+
function normalize(path) {
|
|
36
|
+
return path.split(sep).join("/");
|
|
37
|
+
}
|
|
38
|
+
function parseTsconfig(text) {
|
|
39
|
+
const withoutComments = text.replace(/"(?:\\.|[^"\\])*"|(\/\/[^\n]*|\/\*[\s\S]*?\*\/)/g, (match, comment) => comment ? "" : match);
|
|
40
|
+
return JSON.parse(withoutComments.replace(/,(\s*[}\]])/g, "$1"));
|
|
41
|
+
}
|
|
42
|
+
function isRecord(value) {
|
|
43
|
+
return typeof value === "object" && value !== null;
|
|
44
|
+
}
|
|
45
|
+
/** Wildcard `paths` entries (`"@/*": ["./src/*"]`), the only shape an emitted import can use. */
|
|
46
|
+
function tsconfigAliases(root, tsconfigPath = "tsconfig.json") {
|
|
47
|
+
let parsed;
|
|
48
|
+
try {
|
|
49
|
+
parsed = parseTsconfig(readFileSync(resolve(root, tsconfigPath), "utf8"));
|
|
50
|
+
} catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
if (!isRecord(parsed)) return [];
|
|
54
|
+
const options = parsed.compilerOptions;
|
|
55
|
+
if (!isRecord(options)) return [];
|
|
56
|
+
const paths = options.paths;
|
|
57
|
+
if (!isRecord(paths)) return [];
|
|
58
|
+
const baseUrl = typeof options.baseUrl === "string" ? resolve(root, options.baseUrl) : root;
|
|
59
|
+
const entries = [];
|
|
60
|
+
for (const [pattern, targets] of Object.entries(paths)) {
|
|
61
|
+
if (!pattern.endsWith("/*") || !Array.isArray(targets)) continue;
|
|
62
|
+
const target = targets[0];
|
|
63
|
+
if (typeof target !== "string" || !target.endsWith("/*")) continue;
|
|
64
|
+
entries.push({
|
|
65
|
+
prefix: pattern.slice(0, -2),
|
|
66
|
+
dir: resolve(baseUrl, target.slice(0, -2)),
|
|
67
|
+
sources: {
|
|
68
|
+
vite: false,
|
|
69
|
+
tsconfig: true
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return entries;
|
|
74
|
+
}
|
|
75
|
+
/** String-`find` entries of a resolved Vite `resolve.alias`; a regex alias cannot be re-emitted. */
|
|
76
|
+
function viteAliases(alias) {
|
|
77
|
+
if (!alias) return [];
|
|
78
|
+
const entries = [];
|
|
79
|
+
for (const { find, replacement } of alias) {
|
|
80
|
+
if (typeof find !== "string" || !find || !isAbsolute(replacement)) continue;
|
|
81
|
+
entries.push({
|
|
82
|
+
prefix: find.replace(/\/$/, ""),
|
|
83
|
+
dir: replacement.replace(/\/$/, ""),
|
|
84
|
+
sources: {
|
|
85
|
+
vite: true,
|
|
86
|
+
tsconfig: false
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return entries;
|
|
91
|
+
}
|
|
92
|
+
function merge(entries) {
|
|
93
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
const key = `${entry.prefix}::${normalize(entry.dir)}`;
|
|
96
|
+
const existing = byKey.get(key);
|
|
97
|
+
if (existing) {
|
|
98
|
+
existing.sources.vite ||= entry.sources.vite;
|
|
99
|
+
existing.sources.tsconfig ||= entry.sources.tsconfig;
|
|
100
|
+
} else byKey.set(key, {
|
|
101
|
+
...entry,
|
|
102
|
+
sources: { ...entry.sources }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return [...byKey.values()];
|
|
106
|
+
}
|
|
107
|
+
function contains(dir, file) {
|
|
108
|
+
return normalize(file).startsWith(`${normalize(dir)}/`);
|
|
109
|
+
}
|
|
110
|
+
function score(entry) {
|
|
111
|
+
if (entry.sources.vite && entry.sources.tsconfig) return 2;
|
|
112
|
+
return entry.sources.vite ? 1 : 0;
|
|
113
|
+
}
|
|
114
|
+
function isResolvable(entry, tsconfigPathsPlugin) {
|
|
115
|
+
return entry.sources.vite || tsconfigPathsPlugin;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The aliased specifier for `target`, or `undefined` when no alias resolves it.
|
|
119
|
+
* Prefers an alias both sources agree on, then the deepest directory.
|
|
120
|
+
*/
|
|
121
|
+
function aliasedSpecifier(target, entries, tsconfigPathsPlugin = false) {
|
|
122
|
+
const matches = merge(entries).filter((entry) => contains(entry.dir, target) && isResolvable(entry, tsconfigPathsPlugin));
|
|
123
|
+
if (matches.length === 0) return void 0;
|
|
124
|
+
matches.sort((a, b) => score(b) - score(a) || normalize(b.dir).length - normalize(a.dir).length);
|
|
125
|
+
const best = matches[0];
|
|
126
|
+
return `${best.prefix}/${normalize(relative(best.dir, target)).replace(/\.tsx?$/, "")}`;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/vite/route-emitter.ts
|
|
130
|
+
const GENERATED_BANNER = "// AUTO-GENERATED by @lovable.dev/workflows-sdk — do not edit. Regenerated by the Vite plugin.\n// To take ownership, delete this banner line; the plugin then leaves the file alone.";
|
|
131
|
+
function isFileMissing(error) {
|
|
132
|
+
const code = error?.code;
|
|
133
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
134
|
+
}
|
|
135
|
+
function normalizePath(path) {
|
|
136
|
+
return path.split(sep).join("/");
|
|
137
|
+
}
|
|
138
|
+
function assertContains(parent, child, label) {
|
|
139
|
+
const from = normalizePath(parent).replace(/\/$/, "");
|
|
140
|
+
const to = normalizePath(child);
|
|
141
|
+
if (to !== from && !to.startsWith(`${from}/`)) throw new Error(`@lovable.dev/workflows-sdk: ${label} must resolve under ${from}, got ${to}`);
|
|
142
|
+
}
|
|
143
|
+
function assertUrlPathShape(urlPath) {
|
|
144
|
+
if (!urlPath.startsWith("/")) throw new Error(`@lovable.dev/workflows-sdk: path must start with "/", got "${urlPath}"`);
|
|
145
|
+
if (/\/{2,}/.test(urlPath)) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" contains empty segments ("//")`);
|
|
146
|
+
const trimmed = urlPath.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
147
|
+
if (!trimmed) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" has no route segment`);
|
|
148
|
+
if (!/^[a-zA-Z0-9_\-/]+$/.test(trimmed)) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" contains unsupported characters`);
|
|
149
|
+
return trimmed;
|
|
150
|
+
}
|
|
151
|
+
function assertParamShape(param) {
|
|
152
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(param)) throw new Error(`@lovable.dev/workflows-sdk: workflowIdParam "${param}" must be a JavaScript identifier`);
|
|
153
|
+
return param;
|
|
154
|
+
}
|
|
155
|
+
function relativeImportSpecifier(routeFile, target) {
|
|
156
|
+
const withoutExt = normalizePath(relative(dirname(routeFile), target)).replace(/\.tsx?$/, "");
|
|
157
|
+
return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
|
|
158
|
+
}
|
|
159
|
+
function collectionSpecifier(routeFile, entry, aliases, tsconfigPathsPlugin) {
|
|
160
|
+
return aliasedSpecifier(entry, aliases, tsconfigPathsPlugin) ?? relativeImportSpecifier(routeFile, entry);
|
|
161
|
+
}
|
|
162
|
+
const SURFACES = [
|
|
163
|
+
{
|
|
164
|
+
segment: "",
|
|
165
|
+
factory: "createRunHandler"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
segment: "nextSteps",
|
|
169
|
+
factory: "createNextStepsHandler"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
segment: "executeSteps",
|
|
173
|
+
factory: "createExecuteStepsHandler"
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
function buildRouteSource(routeFile, routeLiteral, param, specifier, root, factory) {
|
|
177
|
+
return `${GENERATED_BANNER}
|
|
178
|
+
// route: ${routeLiteral}
|
|
179
|
+
// emitted to: ${normalizePath(relative(root, routeFile))}
|
|
180
|
+
// This route is unauthenticated: any caller who reaches it can run any declared
|
|
181
|
+
// workflow. Signed invocation is not available yet.
|
|
182
|
+
|
|
183
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
184
|
+
|
|
185
|
+
import { ${factory} } from "@lovable.dev/workflows-sdk";
|
|
186
|
+
|
|
187
|
+
import workflows from "${specifier}";
|
|
188
|
+
|
|
189
|
+
export const Route = createFileRoute("${routeLiteral}")({
|
|
190
|
+
server: {
|
|
191
|
+
handlers: {
|
|
192
|
+
POST: ${factory}(workflows, { workflowIdParam: "${param}" }),
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
function hasGeneratedBanner(content) {
|
|
199
|
+
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
200
|
+
}
|
|
201
|
+
function writeIfChanged(file, content) {
|
|
202
|
+
let existing;
|
|
203
|
+
try {
|
|
204
|
+
existing = readFileSync(file, "utf8");
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (!isFileMissing(error)) throw error;
|
|
207
|
+
}
|
|
208
|
+
if (existing !== void 0 && (!hasGeneratedBanner(existing) || existing === content)) return;
|
|
209
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
210
|
+
writeFileSync(file, content, "utf8");
|
|
211
|
+
}
|
|
212
|
+
function findAdoptedFiles(routesDir) {
|
|
213
|
+
const adopted = [];
|
|
214
|
+
const visit = (dir) => {
|
|
215
|
+
let entries;
|
|
216
|
+
try {
|
|
217
|
+
entries = readdirSync(dir);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (isFileMissing(error)) return;
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
for (const entry of entries) {
|
|
223
|
+
const full = join(dir, entry);
|
|
224
|
+
let stat;
|
|
225
|
+
try {
|
|
226
|
+
stat = lstatSync(full);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (isFileMissing(error)) continue;
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
if (stat.isDirectory()) visit(full);
|
|
232
|
+
else if (entry.endsWith(".ts")) try {
|
|
233
|
+
if (hasGeneratedBanner(readFileSync(full, "utf8"))) adopted.push(full);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
if (!isFileMissing(error)) throw error;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
visit(routesDir);
|
|
240
|
+
return adopted;
|
|
241
|
+
}
|
|
242
|
+
function createRouteEmitter(options) {
|
|
243
|
+
const param = assertParamShape(options.workflowIdParam);
|
|
244
|
+
const pathSegments = assertUrlPathShape(options.path);
|
|
245
|
+
const base = `/${pathSegments}/$${param}`;
|
|
246
|
+
const surfaces = SURFACES.map((surface) => ({
|
|
247
|
+
...surface,
|
|
248
|
+
literal: surface.segment ? `${base}/${surface.segment}` : base,
|
|
249
|
+
fileName: surface.segment ? join(...pathSegments.split("/"), `$${param}`, `${surface.segment}.ts`) : join(...pathSegments.split("/"), `$${param}.ts`)
|
|
250
|
+
}));
|
|
251
|
+
let root = process.cwd();
|
|
252
|
+
let entry = resolve(root, options.entry);
|
|
253
|
+
let routesDir = resolve(root, options.routesDir);
|
|
254
|
+
let routeFiles = surfaces.map((surface) => resolve(routesDir, surface.fileName));
|
|
255
|
+
let aliases = [];
|
|
256
|
+
let tsconfigPathsPlugin = false;
|
|
257
|
+
return {
|
|
258
|
+
entryPath: () => entry,
|
|
259
|
+
setRoot(next, context) {
|
|
260
|
+
root = next;
|
|
261
|
+
aliases = [...viteAliases(context?.alias), ...tsconfigAliases(next)];
|
|
262
|
+
tsconfigPathsPlugin = context?.tsconfigPathsPlugin === true;
|
|
263
|
+
entry = resolve(root, options.entry);
|
|
264
|
+
assertContains(root, entry, `entry "${options.entry}"`);
|
|
265
|
+
routesDir = resolve(root, options.routesDir);
|
|
266
|
+
assertContains(root, routesDir, `routesDir "${options.routesDir}"`);
|
|
267
|
+
routeFiles = surfaces.map((surface) => resolve(routesDir, surface.fileName));
|
|
268
|
+
routeFiles.forEach((file, index) => assertContains(routesDir, file, `path "${surfaces[index].literal}"`));
|
|
269
|
+
},
|
|
270
|
+
regenerate() {
|
|
271
|
+
let entryExists = true;
|
|
272
|
+
try {
|
|
273
|
+
lstatSync(entry);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (!isFileMissing(error)) throw error;
|
|
276
|
+
entryExists = false;
|
|
277
|
+
}
|
|
278
|
+
const expected = /* @__PURE__ */ new Set();
|
|
279
|
+
if (entryExists) surfaces.forEach((surface, index) => {
|
|
280
|
+
const file = routeFiles[index];
|
|
281
|
+
expected.add(file);
|
|
282
|
+
const specifier = collectionSpecifier(file, entry, aliases, tsconfigPathsPlugin);
|
|
283
|
+
writeIfChanged(file, buildRouteSource(file, surface.literal, param, specifier, root, surface.factory));
|
|
284
|
+
});
|
|
285
|
+
for (const file of findAdoptedFiles(routesDir)) {
|
|
286
|
+
if (expected.has(file)) continue;
|
|
287
|
+
try {
|
|
288
|
+
unlinkSync(file);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
if (!isFileMissing(error)) throw error;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/vite/plugin.ts
|
|
298
|
+
const TSCONFIG_PATHS_PLUGINS = /* @__PURE__ */ new Set(["vite-tsconfig-paths", "vite-plugin-tsconfig-paths"]);
|
|
299
|
+
/**
|
|
300
|
+
* Build the collection's manifests and emit the route serving them; one `entry`
|
|
301
|
+
* feeds both, so the two can never describe different sets.
|
|
302
|
+
*/
|
|
303
|
+
function workflowsPlugin(options = {}) {
|
|
304
|
+
const entry = options.entry ?? "src/lib/workflows/index.ts";
|
|
305
|
+
const emitter = createRouteEmitter({
|
|
306
|
+
entry,
|
|
307
|
+
routesDir: options.routesDir ?? "src/routes",
|
|
308
|
+
path: options.path ?? "/api/workflows",
|
|
309
|
+
workflowIdParam: options.workflowIdParam ?? "workflowId"
|
|
310
|
+
});
|
|
35
311
|
let config;
|
|
36
312
|
return {
|
|
37
|
-
name: "@lovable.dev/workflows-sdk
|
|
38
|
-
apply: "build",
|
|
313
|
+
name: "@lovable.dev/workflows-sdk",
|
|
39
314
|
configResolved(resolved) {
|
|
40
315
|
config = resolved;
|
|
316
|
+
emitter.setRoot(config.root, {
|
|
317
|
+
alias: config.resolve.alias,
|
|
318
|
+
tsconfigPathsPlugin: config.plugins.some((plugin) => TSCONFIG_PATHS_PLUGINS.has(plugin.name))
|
|
319
|
+
});
|
|
320
|
+
emitter.regenerate();
|
|
321
|
+
},
|
|
322
|
+
configureServer(server) {
|
|
323
|
+
const onChange = (file) => {
|
|
324
|
+
if (normalizePath(file) === normalizePath(emitter.entryPath())) emitter.regenerate();
|
|
325
|
+
};
|
|
326
|
+
server.watcher.on("add", onChange);
|
|
327
|
+
server.watcher.on("unlink", onChange);
|
|
328
|
+
server.watcher.once("close", () => {
|
|
329
|
+
server.watcher.off("add", onChange);
|
|
330
|
+
server.watcher.off("unlink", onChange);
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
buildStart() {
|
|
334
|
+
emitter.regenerate();
|
|
41
335
|
},
|
|
42
336
|
async generateBundle() {
|
|
43
337
|
const entryPath = resolve(config.root, entry);
|
|
@@ -63,7 +357,7 @@ function workflowsManifest({ entry }) {
|
|
|
63
357
|
});
|
|
64
358
|
try {
|
|
65
359
|
const module = await server.ssrLoadModule(entryPath);
|
|
66
|
-
if (!module.default || !Array.isArray(module.default.workflows) || !Array.isArray(module.default.
|
|
360
|
+
if (!module.default || !Array.isArray(module.default.workflows) || !Array.isArray(module.default.triggers)) throw new Error(`@lovable.dev/workflows-sdk: ${entry} must default-export a registerWorkflows() collection`);
|
|
67
361
|
const manifests = await generateManifests(module.default);
|
|
68
362
|
await writeManifests(config.root, manifests);
|
|
69
363
|
} finally {
|
|
@@ -74,4 +368,4 @@ function workflowsManifest({ entry }) {
|
|
|
74
368
|
};
|
|
75
369
|
}
|
|
76
370
|
//#endregion
|
|
77
|
-
export {
|
|
371
|
+
export { workflowsPlugin };
|
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.11",
|
|
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",
|
|
@@ -28,7 +29,6 @@
|
|
|
28
29
|
"dist"
|
|
29
30
|
],
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
32
32
|
"@standard-schema/spec": "^1.1.0",
|
|
33
33
|
"@tanstack/workflow-core": "0.0.4"
|
|
34
34
|
},
|
|
@@ -36,20 +36,25 @@
|
|
|
36
36
|
"@types/node": "22.13.13",
|
|
37
37
|
"vite": "^7.3.1",
|
|
38
38
|
"zod": "^4.1.13",
|
|
39
|
-
"tsdown": "^0.22.5"
|
|
39
|
+
"tsdown": "^0.22.5",
|
|
40
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"vite": ">=7.3.1 <9"
|
|
43
|
+
"vite": ">=7.3.1 <9",
|
|
44
|
+
"typescript": ">=5.4"
|
|
43
45
|
},
|
|
44
46
|
"peerDependenciesMeta": {
|
|
45
47
|
"vite": {
|
|
46
48
|
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"typescript": {
|
|
51
|
+
"optional": true
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
54
|
"scripts": {
|
|
50
55
|
"build": "tsdown",
|
|
51
|
-
"test": "node --test
|
|
52
|
-
"typecheck": "
|
|
53
|
-
"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\""
|
|
56
|
+
"test": "node --test tests/*.test.mjs",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
58
|
+
"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\""
|
|
54
59
|
}
|
|
55
60
|
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
//#region src/validation.ts
|
|
2
|
-
function assertIdentifier(kind, id) {
|
|
3
|
-
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`);
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/schedule.ts
|
|
7
|
-
function defineSchedule(schedule) {
|
|
8
|
-
assertIdentifier("schedule", schedule.id);
|
|
9
|
-
if (typeof schedule.cron !== "string" || schedule.cron.trim().split(/\s+/).length !== 5) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" requires a five-field cron expression`);
|
|
10
|
-
const timeZone = schedule.timeZone ?? "UTC";
|
|
11
|
-
new Intl.DateTimeFormat("en", { timeZone });
|
|
12
|
-
return {
|
|
13
|
-
...schedule,
|
|
14
|
-
timeZone
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/register.ts
|
|
19
|
-
function registerWorkflows({ workflows, schedules = [] }) {
|
|
20
|
-
const ids = /* @__PURE__ */ new Set();
|
|
21
|
-
for (const workflow of workflows) {
|
|
22
|
-
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
|
|
23
|
-
assertIdentifier("workflow", workflow.id);
|
|
24
|
-
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");
|
|
25
|
-
if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
|
|
26
|
-
ids.add(workflow.id);
|
|
27
|
-
}
|
|
28
|
-
const scheduleIds = /* @__PURE__ */ new Set();
|
|
29
|
-
const registeredSchedules = schedules.map((schedule) => {
|
|
30
|
-
const definition = defineSchedule(schedule);
|
|
31
|
-
if (scheduleIds.has(definition.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate schedule ID "${definition.id}"`);
|
|
32
|
-
if (!workflows.includes(definition.workflow)) throw new Error(`@lovable.dev/workflows-sdk: schedule "${definition.id}" references an unregistered workflow`);
|
|
33
|
-
scheduleIds.add(definition.id);
|
|
34
|
-
return definition;
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
workflows: [...workflows],
|
|
38
|
-
schedules: registeredSchedules
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/json.ts
|
|
43
|
-
function toJson(value, path, ancestors = /* @__PURE__ */ new Set()) {
|
|
44
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
45
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
46
|
-
if (typeof value !== "object" || ancestors.has(value)) throw new Error(`@lovable.dev/workflows-sdk: ${path} must contain finite, acyclic JSON values`);
|
|
47
|
-
ancestors.add(value);
|
|
48
|
-
try {
|
|
49
|
-
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`@lovable.dev/workflows-sdk: ${path} must not contain symbol keys`);
|
|
50
|
-
if (Array.isArray(value)) {
|
|
51
|
-
if (Object.keys(value).length !== value.length) throw new Error(`@lovable.dev/workflows-sdk: ${path} must be a dense JSON array without extra properties`);
|
|
52
|
-
return Array.from(value, (item, index) => toJson(item, `${path}[${index}]`, ancestors));
|
|
53
|
-
}
|
|
54
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error(`@lovable.dev/workflows-sdk: ${path} must contain plain JSON objects`);
|
|
55
|
-
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, toJson(value[key], `${path}.${key}`, ancestors)]));
|
|
56
|
-
} finally {
|
|
57
|
-
ancestors.delete(value);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/manifest.ts
|
|
62
|
-
function jsonSchema(schema, direction, label) {
|
|
63
|
-
if (!schema) return void 0;
|
|
64
|
-
const standard = schema["~standard"];
|
|
65
|
-
if (typeof standard.jsonSchema?.[direction] !== "function") throw new Error(`@lovable.dev/workflows-sdk: ${label} must support Standard JSON Schema conversion`);
|
|
66
|
-
try {
|
|
67
|
-
return toJson(standard.jsonSchema[direction]({ target: "draft-2020-12" }), label);
|
|
68
|
-
} catch (cause) {
|
|
69
|
-
throw new Error(`@lovable.dev/workflows-sdk: cannot serialize ${label}`, { cause });
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
async function generateManifests(definition) {
|
|
73
|
-
const { extractWorkflowGraph } = await import("./graph-extract-SXSdcip0.js");
|
|
74
|
-
const collection = registerWorkflows(definition);
|
|
75
|
-
const manifests = [];
|
|
76
|
-
for (const workflow of collection.workflows) {
|
|
77
|
-
if (workflow.previousVersions?.length) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" previousVersions are not supported yet`);
|
|
78
|
-
const metadata = {
|
|
79
|
-
id: workflow.id,
|
|
80
|
-
...workflow.description === void 0 ? {} : { description: workflow.description },
|
|
81
|
-
...workflow.version === void 0 ? {} : { version: workflow.version },
|
|
82
|
-
...workflow.inputSchema ? { inputSchema: jsonSchema(workflow.inputSchema, "input", `${workflow.id}.input`) } : {},
|
|
83
|
-
...workflow.outputSchema ? { outputSchema: jsonSchema(workflow.outputSchema, "output", `${workflow.id}.output`) } : {},
|
|
84
|
-
...workflow.stateSchema ? { stateSchema: jsonSchema(workflow.stateSchema, "output", `${workflow.id}.state`) } : {}
|
|
85
|
-
};
|
|
86
|
-
const schedules = [];
|
|
87
|
-
for (const schedule of collection.schedules.filter((schedule) => schedule.workflow === workflow)) {
|
|
88
|
-
const input = toJson(schedule.input, `schedule "${schedule.id}" input`);
|
|
89
|
-
const schema = schedule.workflow.inputSchema;
|
|
90
|
-
if (schema) {
|
|
91
|
-
const result = await schema["~standard"].validate(input);
|
|
92
|
-
if (result.issues) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" input is invalid: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
93
|
-
}
|
|
94
|
-
schedules.push({
|
|
95
|
-
id: schedule.id,
|
|
96
|
-
cron: schedule.cron,
|
|
97
|
-
timeZone: schedule.timeZone ?? "UTC",
|
|
98
|
-
input
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
schedules.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
102
|
-
const manifest = {
|
|
103
|
-
version: 1,
|
|
104
|
-
workflow: metadata,
|
|
105
|
-
schedules,
|
|
106
|
-
graph: extractWorkflowGraph(workflow.handler)
|
|
107
|
-
};
|
|
108
|
-
toJson(manifest, "manifest");
|
|
109
|
-
manifests.push(manifest);
|
|
110
|
-
}
|
|
111
|
-
return manifests.sort((a, b) => a.workflow.id < b.workflow.id ? -1 : a.workflow.id > b.workflow.id ? 1 : 0);
|
|
112
|
-
}
|
|
113
|
-
//#endregion
|
|
114
|
-
export { registerWorkflows as n, defineSchedule as r, generateManifests as t };
|