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