@lovable.dev/workflows-sdk 0.0.0-dev.59 → 0.0.0-dev.60
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/dist/{branch-metadata-D1b9OmsG.js → branch-metadata-C8JF4mRD.js} +1 -1
- package/dist/cli/generate-manifests.d.ts +1 -0
- package/dist/cli/generate-manifests.js +30 -0
- package/dist/{context-escapes-CcYvmmKH.js → context-escapes-CaWQZiKA.js} +1 -1
- package/dist/{duplicate-ids-BZhMnS7n.js → duplicate-ids-piCSoy97.js} +1 -1
- package/dist/durable-ids-B8WBvR9R.js +2 -0
- package/dist/durable-ids-CdlFkNKw.js +4 -0
- package/dist/generate-DGdzUQcG.js +1251 -0
- package/dist/graph-C_Y_mGVf.js +2 -0
- package/dist/{graph-CwRl2SGh.js → graph-DSYE4aER.js} +2 -2
- package/dist/index.js +3 -3
- package/dist/{nested-operations-CoaLLZl0.js → nested-operations-CEA4t4q_.js} +1 -1
- package/dist/{operation-descriptions-DlYyD27h.js → operation-descriptions-BtUOwQoK.js} +1 -1
- package/dist/plugin-CXlzS4_y.js +379 -0
- package/dist/{step-metadata-CCsEws4V.js → step-metadata-DvieDJGl.js} +1 -1
- package/dist/vite.js +1 -360
- package/dist/{wait-deadlines-CCgWwxqQ.js → wait-deadlines-DULtPtuu.js} +1 -1
- package/dist/{generate-DI9qaUrI.js → workflow_manifest_pb-DnavtUll.js} +26 -1275
- package/package.json +4 -1
- package/dist/durable-ids-Cx341nJQ.js +0 -17
package/dist/vite.js
CHANGED
|
@@ -1,361 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { createServer } from "vite";
|
|
4
|
-
import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
5
|
-
import { lstatSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
-
//#region src/vite/manifest-files.ts
|
|
7
|
-
async function ensureDirectory(path) {
|
|
8
|
-
try {
|
|
9
|
-
await mkdir(path);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
if (error.code !== "EEXIST") throw error;
|
|
12
|
-
}
|
|
13
|
-
if (!(await lstat(path)).isDirectory()) throw new Error(`@lovable.dev/workflows-sdk: ${path} must be a directory, not a file or symlink`);
|
|
14
|
-
}
|
|
15
|
-
async function writeManifests(root, manifests) {
|
|
16
|
-
const lovable = join(root, ".lovable");
|
|
17
|
-
await ensureDirectory(lovable);
|
|
18
|
-
const directory = join(lovable, "workflows");
|
|
19
|
-
await ensureDirectory(directory);
|
|
20
|
-
const staging = await mkdtemp(join(directory, ".tmp-"));
|
|
21
|
-
const nameOf = (manifest) => `${manifest.workflowId}.${manifest.workflowVersion}.json`;
|
|
22
|
-
const names = new Set(manifests.map(nameOf));
|
|
23
|
-
try {
|
|
24
|
-
for (const manifest of manifests) await writeFile(join(staging, nameOf(manifest)), JSON.stringify(manifest, null, 2) + "\n");
|
|
25
|
-
for (const name of names) await rename(join(staging, name), join(directory, name));
|
|
26
|
-
for (const entry of await readdir(directory, { withFileTypes: true })) if (entry.name.endsWith(".json") && !names.has(entry.name) && !entry.isDirectory()) await rm(join(directory, entry.name), { force: true });
|
|
27
|
-
} finally {
|
|
28
|
-
await rm(staging, {
|
|
29
|
-
recursive: true,
|
|
30
|
-
force: true
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/vite/alias.ts
|
|
36
|
-
function normalize(path) {
|
|
37
|
-
return path.split(sep).join("/");
|
|
38
|
-
}
|
|
39
|
-
function parseTsconfig(text) {
|
|
40
|
-
const withoutComments = text.replace(/"(?:\\.|[^"\\])*"|(\/\/[^\n]*|\/\*[\s\S]*?\*\/)/g, (match, comment) => comment ? "" : match);
|
|
41
|
-
return JSON.parse(withoutComments.replace(/,(\s*[}\]])/g, "$1"));
|
|
42
|
-
}
|
|
43
|
-
function isRecord(value) {
|
|
44
|
-
return typeof value === "object" && value !== null;
|
|
45
|
-
}
|
|
46
|
-
/** Wildcard `paths` entries (`"@/*": ["./src/*"]`), the only shape an emitted import can use. */
|
|
47
|
-
function tsconfigAliases(root, tsconfigPath = "tsconfig.json") {
|
|
48
|
-
let parsed;
|
|
49
|
-
try {
|
|
50
|
-
parsed = parseTsconfig(readFileSync(resolve(root, tsconfigPath), "utf8"));
|
|
51
|
-
} catch {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
if (!isRecord(parsed)) return [];
|
|
55
|
-
const options = parsed.compilerOptions;
|
|
56
|
-
if (!isRecord(options)) return [];
|
|
57
|
-
const paths = options.paths;
|
|
58
|
-
if (!isRecord(paths)) return [];
|
|
59
|
-
const baseUrl = typeof options.baseUrl === "string" ? resolve(root, options.baseUrl) : root;
|
|
60
|
-
const entries = [];
|
|
61
|
-
for (const [pattern, targets] of Object.entries(paths)) {
|
|
62
|
-
if (!pattern.endsWith("/*") || !Array.isArray(targets)) continue;
|
|
63
|
-
const target = targets[0];
|
|
64
|
-
if (typeof target !== "string" || !target.endsWith("/*")) continue;
|
|
65
|
-
entries.push({
|
|
66
|
-
prefix: pattern.slice(0, -2),
|
|
67
|
-
dir: resolve(baseUrl, target.slice(0, -2)),
|
|
68
|
-
sources: {
|
|
69
|
-
vite: false,
|
|
70
|
-
tsconfig: true
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return entries;
|
|
75
|
-
}
|
|
76
|
-
/** String-`find` entries of a resolved Vite `resolve.alias`; a regex alias cannot be re-emitted. */
|
|
77
|
-
function viteAliases(alias) {
|
|
78
|
-
if (!alias) return [];
|
|
79
|
-
const entries = [];
|
|
80
|
-
for (const { find, replacement } of alias) {
|
|
81
|
-
if (typeof find !== "string" || !find || !isAbsolute(replacement)) continue;
|
|
82
|
-
entries.push({
|
|
83
|
-
prefix: find.replace(/\/$/, ""),
|
|
84
|
-
dir: replacement.replace(/\/$/, ""),
|
|
85
|
-
sources: {
|
|
86
|
-
vite: true,
|
|
87
|
-
tsconfig: false
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return entries;
|
|
92
|
-
}
|
|
93
|
-
function merge(entries) {
|
|
94
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
95
|
-
for (const entry of entries) {
|
|
96
|
-
const key = `${entry.prefix}::${normalize(entry.dir)}`;
|
|
97
|
-
const existing = byKey.get(key);
|
|
98
|
-
if (existing) {
|
|
99
|
-
existing.sources.vite ||= entry.sources.vite;
|
|
100
|
-
existing.sources.tsconfig ||= entry.sources.tsconfig;
|
|
101
|
-
} else byKey.set(key, {
|
|
102
|
-
...entry,
|
|
103
|
-
sources: { ...entry.sources }
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return [...byKey.values()];
|
|
107
|
-
}
|
|
108
|
-
function contains(dir, file) {
|
|
109
|
-
return normalize(file).startsWith(`${normalize(dir)}/`);
|
|
110
|
-
}
|
|
111
|
-
function score(entry) {
|
|
112
|
-
if (entry.sources.vite && entry.sources.tsconfig) return 2;
|
|
113
|
-
return entry.sources.vite ? 1 : 0;
|
|
114
|
-
}
|
|
115
|
-
function isResolvable(entry, tsconfigPathsPlugin) {
|
|
116
|
-
return entry.sources.vite || tsconfigPathsPlugin;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* The aliased specifier for `target`, or `undefined` when no alias resolves it.
|
|
120
|
-
* Prefers an alias both sources agree on, then the deepest directory.
|
|
121
|
-
*/
|
|
122
|
-
function aliasedSpecifier(target, entries, tsconfigPathsPlugin = false) {
|
|
123
|
-
const matches = merge(entries).filter((entry) => contains(entry.dir, target) && isResolvable(entry, tsconfigPathsPlugin));
|
|
124
|
-
if (matches.length === 0) return void 0;
|
|
125
|
-
matches.sort((a, b) => score(b) - score(a) || normalize(b.dir).length - normalize(a.dir).length);
|
|
126
|
-
const best = matches[0];
|
|
127
|
-
return `${best.prefix}/${normalize(relative(best.dir, target)).replace(/\.tsx?$/, "")}`;
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/vite/route-emitter.ts
|
|
131
|
-
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.";
|
|
132
|
-
function isFileMissing(error) {
|
|
133
|
-
const code = error?.code;
|
|
134
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
135
|
-
}
|
|
136
|
-
function normalizePath(path) {
|
|
137
|
-
return path.split(sep).join("/");
|
|
138
|
-
}
|
|
139
|
-
function assertContains(parent, child, label) {
|
|
140
|
-
const from = normalizePath(parent).replace(/\/$/, "");
|
|
141
|
-
const to = normalizePath(child);
|
|
142
|
-
if (to !== from && !to.startsWith(`${from}/`)) throw new Error(`@lovable.dev/workflows-sdk: ${label} must resolve under ${from}, got ${to}`);
|
|
143
|
-
}
|
|
144
|
-
function assertUrlPathShape(urlPath) {
|
|
145
|
-
if (!urlPath.startsWith("/")) throw new Error(`@lovable.dev/workflows-sdk: path must start with "/", got "${urlPath}"`);
|
|
146
|
-
if (/\/{2,}/.test(urlPath)) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" contains empty segments ("//")`);
|
|
147
|
-
const trimmed = urlPath.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
148
|
-
if (!trimmed) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" has no route segment`);
|
|
149
|
-
if (!/^[a-zA-Z0-9_\-/]+$/.test(trimmed)) throw new Error(`@lovable.dev/workflows-sdk: path "${urlPath}" contains unsupported characters`);
|
|
150
|
-
return trimmed;
|
|
151
|
-
}
|
|
152
|
-
function assertParamShape(param) {
|
|
153
|
-
if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(param)) throw new Error(`@lovable.dev/workflows-sdk: workflowIdParam "${param}" must be a JavaScript identifier`);
|
|
154
|
-
return param;
|
|
155
|
-
}
|
|
156
|
-
function relativeImportSpecifier(routeFile, target) {
|
|
157
|
-
const withoutExt = normalizePath(relative(dirname(routeFile), target)).replace(/\.tsx?$/, "");
|
|
158
|
-
return withoutExt.startsWith(".") ? withoutExt : `./${withoutExt}`;
|
|
159
|
-
}
|
|
160
|
-
function collectionSpecifier(routeFile, entry, aliases, tsconfigPathsPlugin) {
|
|
161
|
-
return aliasedSpecifier(entry, aliases, tsconfigPathsPlugin) ?? relativeImportSpecifier(routeFile, entry);
|
|
162
|
-
}
|
|
163
|
-
const SURFACES = [{
|
|
164
|
-
segment: "steps",
|
|
165
|
-
factory: "createStepsHandler"
|
|
166
|
-
}];
|
|
167
|
-
function buildRouteSource(routeFile, routeLiteral, param, specifier, root, factory) {
|
|
168
|
-
return `${GENERATED_BANNER}
|
|
169
|
-
// route: ${routeLiteral}
|
|
170
|
-
// emitted to: ${normalizePath(relative(root, routeFile))}
|
|
171
|
-
|
|
172
|
-
import { createFileRoute } from "@tanstack/react-router";
|
|
173
|
-
|
|
174
|
-
import { ${factory} } from "@lovable.dev/workflows-sdk";
|
|
175
|
-
|
|
176
|
-
import workflows from "${specifier}";
|
|
177
|
-
|
|
178
|
-
export const Route = createFileRoute("${routeLiteral}")({
|
|
179
|
-
server: {
|
|
180
|
-
handlers: {
|
|
181
|
-
POST: ${factory}(workflows, { workflowIdParam: "${param}" }),
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
`;
|
|
186
|
-
}
|
|
187
|
-
function hasGeneratedBanner(content) {
|
|
188
|
-
return content.replace(/\r\n/g, "\n").startsWith(GENERATED_BANNER);
|
|
189
|
-
}
|
|
190
|
-
function writeIfChanged(file, content) {
|
|
191
|
-
let existing;
|
|
192
|
-
try {
|
|
193
|
-
existing = readFileSync(file, "utf8");
|
|
194
|
-
} catch (error) {
|
|
195
|
-
if (!isFileMissing(error)) throw error;
|
|
196
|
-
}
|
|
197
|
-
if (existing !== void 0 && (!hasGeneratedBanner(existing) || existing === content)) return;
|
|
198
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
199
|
-
writeFileSync(file, content, "utf8");
|
|
200
|
-
}
|
|
201
|
-
function findAdoptedFiles(routesDir) {
|
|
202
|
-
const adopted = [];
|
|
203
|
-
const visit = (dir) => {
|
|
204
|
-
let entries;
|
|
205
|
-
try {
|
|
206
|
-
entries = readdirSync(dir);
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if (isFileMissing(error)) return;
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
for (const entry of entries) {
|
|
212
|
-
const full = join(dir, entry);
|
|
213
|
-
let stat;
|
|
214
|
-
try {
|
|
215
|
-
stat = lstatSync(full);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
if (isFileMissing(error)) continue;
|
|
218
|
-
throw error;
|
|
219
|
-
}
|
|
220
|
-
if (stat.isDirectory()) visit(full);
|
|
221
|
-
else if (entry.endsWith(".ts")) try {
|
|
222
|
-
if (hasGeneratedBanner(readFileSync(full, "utf8"))) adopted.push(full);
|
|
223
|
-
} catch (error) {
|
|
224
|
-
if (!isFileMissing(error)) throw error;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
visit(routesDir);
|
|
229
|
-
return adopted;
|
|
230
|
-
}
|
|
231
|
-
function createRouteEmitter(options) {
|
|
232
|
-
const param = assertParamShape(options.workflowIdParam);
|
|
233
|
-
const pathSegments = assertUrlPathShape(options.path);
|
|
234
|
-
const base = `/${pathSegments}/$${param}`;
|
|
235
|
-
const surfaces = SURFACES.map((surface) => ({
|
|
236
|
-
...surface,
|
|
237
|
-
literal: surface.segment ? `${base}/${surface.segment}` : base,
|
|
238
|
-
fileName: surface.segment ? join(...pathSegments.split("/"), `$${param}`, `${surface.segment}.ts`) : join(...pathSegments.split("/"), `$${param}.ts`)
|
|
239
|
-
}));
|
|
240
|
-
let root = process.cwd();
|
|
241
|
-
let entry = resolve(root, options.entry);
|
|
242
|
-
let routesDir = resolve(root, options.routesDir);
|
|
243
|
-
let routeFiles = surfaces.map((surface) => resolve(routesDir, surface.fileName));
|
|
244
|
-
let aliases = [];
|
|
245
|
-
let tsconfigPathsPlugin = false;
|
|
246
|
-
return {
|
|
247
|
-
entryPath: () => entry,
|
|
248
|
-
setRoot(next, context) {
|
|
249
|
-
root = next;
|
|
250
|
-
aliases = [...viteAliases(context?.alias), ...tsconfigAliases(next)];
|
|
251
|
-
tsconfigPathsPlugin = context?.tsconfigPathsPlugin === true;
|
|
252
|
-
entry = resolve(root, options.entry);
|
|
253
|
-
assertContains(root, entry, `entry "${options.entry}"`);
|
|
254
|
-
routesDir = resolve(root, options.routesDir);
|
|
255
|
-
assertContains(root, routesDir, `routesDir "${options.routesDir}"`);
|
|
256
|
-
routeFiles = surfaces.map((surface) => resolve(routesDir, surface.fileName));
|
|
257
|
-
routeFiles.forEach((file, index) => assertContains(routesDir, file, `path "${surfaces[index].literal}"`));
|
|
258
|
-
},
|
|
259
|
-
regenerate() {
|
|
260
|
-
let entryExists = true;
|
|
261
|
-
try {
|
|
262
|
-
lstatSync(entry);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (!isFileMissing(error)) throw error;
|
|
265
|
-
entryExists = false;
|
|
266
|
-
}
|
|
267
|
-
const expected = /* @__PURE__ */ new Set();
|
|
268
|
-
if (entryExists) surfaces.forEach((surface, index) => {
|
|
269
|
-
const file = routeFiles[index];
|
|
270
|
-
expected.add(file);
|
|
271
|
-
const specifier = collectionSpecifier(file, entry, aliases, tsconfigPathsPlugin);
|
|
272
|
-
writeIfChanged(file, buildRouteSource(file, surface.literal, param, specifier, root, surface.factory));
|
|
273
|
-
});
|
|
274
|
-
for (const file of findAdoptedFiles(routesDir)) {
|
|
275
|
-
if (expected.has(file)) continue;
|
|
276
|
-
try {
|
|
277
|
-
unlinkSync(file);
|
|
278
|
-
} catch (error) {
|
|
279
|
-
if (!isFileMissing(error)) throw error;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
//#endregion
|
|
286
|
-
//#region src/vite/plugin.ts
|
|
287
|
-
const TSCONFIG_PATHS_PLUGINS = /* @__PURE__ */ new Set(["vite-tsconfig-paths", "vite-plugin-tsconfig-paths"]);
|
|
288
|
-
/**
|
|
289
|
-
* Build the collection's manifests and emit the route serving them; one `entry`
|
|
290
|
-
* feeds both, so the two can never describe different sets.
|
|
291
|
-
*/
|
|
292
|
-
function workflowsPlugin(options = {}) {
|
|
293
|
-
const entry = options.entry ?? "src/lib/workflows/index.ts";
|
|
294
|
-
const path = options.path ?? "/api/workflows";
|
|
295
|
-
const emitter = createRouteEmitter({
|
|
296
|
-
entry,
|
|
297
|
-
routesDir: options.routesDir ?? "src/routes",
|
|
298
|
-
path,
|
|
299
|
-
workflowIdParam: options.workflowIdParam ?? "workflowId"
|
|
300
|
-
});
|
|
301
|
-
let config;
|
|
302
|
-
return {
|
|
303
|
-
name: "@lovable.dev/workflows-sdk",
|
|
304
|
-
configResolved(resolved) {
|
|
305
|
-
config = resolved;
|
|
306
|
-
emitter.setRoot(config.root, {
|
|
307
|
-
alias: config.resolve.alias,
|
|
308
|
-
tsconfigPathsPlugin: config.plugins.some((plugin) => TSCONFIG_PATHS_PLUGINS.has(plugin.name))
|
|
309
|
-
});
|
|
310
|
-
emitter.regenerate();
|
|
311
|
-
},
|
|
312
|
-
configureServer(server) {
|
|
313
|
-
const onChange = (file) => {
|
|
314
|
-
if (normalizePath(file) === normalizePath(emitter.entryPath())) emitter.regenerate();
|
|
315
|
-
};
|
|
316
|
-
server.watcher.on("add", onChange);
|
|
317
|
-
server.watcher.on("unlink", onChange);
|
|
318
|
-
server.watcher.once("close", () => {
|
|
319
|
-
server.watcher.off("add", onChange);
|
|
320
|
-
server.watcher.off("unlink", onChange);
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
buildStart() {
|
|
324
|
-
emitter.regenerate();
|
|
325
|
-
},
|
|
326
|
-
async generateBundle() {
|
|
327
|
-
const entryPath = resolve(config.root, entry);
|
|
328
|
-
this.addWatchFile(entryPath);
|
|
329
|
-
const server = await createServer({
|
|
330
|
-
configFile: false,
|
|
331
|
-
root: config.root,
|
|
332
|
-
mode: config.mode,
|
|
333
|
-
envDir: config.envDir,
|
|
334
|
-
define: config.define,
|
|
335
|
-
logLevel: "silent",
|
|
336
|
-
resolve: { alias: config.resolve.alias },
|
|
337
|
-
ssr: {
|
|
338
|
-
external: config.ssr.external,
|
|
339
|
-
noExternal: config.ssr.noExternal
|
|
340
|
-
},
|
|
341
|
-
server: {
|
|
342
|
-
middlewareMode: true,
|
|
343
|
-
hmr: false,
|
|
344
|
-
watch: null
|
|
345
|
-
},
|
|
346
|
-
optimizeDeps: { noDiscovery: true }
|
|
347
|
-
});
|
|
348
|
-
try {
|
|
349
|
-
const module = await server.ssrLoadModule(entryPath);
|
|
350
|
-
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`);
|
|
351
|
-
const manifests = await generateManifests(module.default, { routePath: path });
|
|
352
|
-
await writeManifests(config.root, manifests);
|
|
353
|
-
} finally {
|
|
354
|
-
for (const file of server.moduleGraph.fileToModulesMap.keys()) this.addWatchFile(file);
|
|
355
|
-
await server.close();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
//#endregion
|
|
1
|
+
import { r as workflowsPlugin } from "./plugin-CXlzS4_y.js";
|
|
361
2
|
export { workflowsPlugin };
|