@lovable.dev/workflows-sdk 0.0.0-dev.26 → 0.0.0-dev.27
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 +10 -9
- package/dist/{branch-metadata-IXuazOmY.js → branch-metadata-Bv-K2WAN.js} +1 -1
- package/dist/{context-escapes-x0J0HUgC.js → context-escapes-BXC37F36.js} +1 -1
- package/dist/{duplicate-ids-NnTrnieX.js → duplicate-ids-Dv2ICco3.js} +1 -1
- package/dist/generate-Dgj2-55O.js +6893 -0
- package/dist/{graph-Qx9mvqnC.js → graph-CVgB49lW.js} +93 -81
- package/dist/index.d.ts +566 -124
- package/dist/index.js +1 -1
- package/dist/{nested-operations-DYVa5c5A.js → nested-operations-QZiiJCxT.js} +1 -1
- package/dist/{operation-descriptions-BLZC8bxV.js → operation-descriptions-CJxYUpLf.js} +1 -1
- package/dist/{step-metadata-MjyYQjOy.js → step-metadata-DelsyoE1.js} +1 -1
- package/dist/vite.js +3 -3
- package/package.json +2 -1
- package/dist/generate-DHIXkk21.js +0 -287
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as defineSchedule, E as weekly, S as registerWorkflows, T as hourly, b as createMiddleware, t as generateManifests, w as daily, x as createWorkflow } from "./generate-Dgj2-55O.js";
|
|
2
2
|
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
3
3
|
import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
|
|
4
4
|
//#region src/stacks/tanstack/sse.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-CVgB49lW.js";
|
|
2
2
|
//#region src/manifests/step-metadata.ts
|
|
3
3
|
async function findStepMetadataIssues(handler) {
|
|
4
4
|
const api = await loadTypeScript();
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as generateManifests } from "./generate-
|
|
1
|
+
import { t as generateManifests } from "./generate-Dgj2-55O.js";
|
|
2
2
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { createServer } from "vite";
|
|
4
4
|
import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -18,9 +18,9 @@ async function writeManifests(root, manifests) {
|
|
|
18
18
|
const directory = join(lovable, "workflows");
|
|
19
19
|
await ensureDirectory(directory);
|
|
20
20
|
const staging = await mkdtemp(join(directory, ".tmp-"));
|
|
21
|
-
const names = new Set(manifests.map((manifest) => `${manifest.
|
|
21
|
+
const names = new Set(manifests.map((manifest) => `${manifest.workflowId}.json`));
|
|
22
22
|
try {
|
|
23
|
-
for (const manifest of manifests) await writeFile(join(staging, `${manifest.
|
|
23
|
+
for (const manifest of manifests) await writeFile(join(staging, `${manifest.workflowId}.json`), JSON.stringify(manifest, null, 2) + "\n");
|
|
24
24
|
for (const name of names) await rename(join(staging, name), join(directory, name));
|
|
25
25
|
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 });
|
|
26
26
|
} finally {
|
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.27",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"tag": "dev",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@tanstack/workflow-core": "0.0.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@bufbuild/protobuf": "^2.10.1",
|
|
36
37
|
"@types/node": "22.13.13",
|
|
37
38
|
"vite": "^7.3.1",
|
|
38
39
|
"zod": "^4.1.13",
|
|
@@ -1,287 +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 WEEKDAYS = [
|
|
9
|
-
"mon",
|
|
10
|
-
"tue",
|
|
11
|
-
"wed",
|
|
12
|
-
"thu",
|
|
13
|
-
"fri",
|
|
14
|
-
"sat",
|
|
15
|
-
"sun"
|
|
16
|
-
];
|
|
17
|
-
const WEEKDAY_NAMES = {
|
|
18
|
-
mon: "mon",
|
|
19
|
-
monday: "mon",
|
|
20
|
-
tue: "tue",
|
|
21
|
-
tuesday: "tue",
|
|
22
|
-
wed: "wed",
|
|
23
|
-
wednesday: "wed",
|
|
24
|
-
thu: "thu",
|
|
25
|
-
thursday: "thu",
|
|
26
|
-
fri: "fri",
|
|
27
|
-
friday: "fri",
|
|
28
|
-
sat: "sat",
|
|
29
|
-
saturday: "sat",
|
|
30
|
-
sun: "sun",
|
|
31
|
-
sunday: "sun"
|
|
32
|
-
};
|
|
33
|
-
function fail$1(message) {
|
|
34
|
-
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
35
|
-
}
|
|
36
|
-
function parseWeekday(value, label) {
|
|
37
|
-
const day = typeof value === "string" ? WEEKDAY_NAMES[value.toLowerCase()] : void 0;
|
|
38
|
-
if (day === void 0) fail$1(`${label} names an unknown day "${String(value)}"; use ${WEEKDAYS.join(", ")}`);
|
|
39
|
-
return day;
|
|
40
|
-
}
|
|
41
|
-
function parseDays(value, label) {
|
|
42
|
-
if (!Array.isArray(value) || value.length === 0) fail$1(`${label} must be a non-empty array of days`);
|
|
43
|
-
const days = [...new Set(value.map((entry) => parseWeekday(entry, label)))].sort((a, b) => WEEKDAYS.indexOf(a) - WEEKDAYS.indexOf(b));
|
|
44
|
-
return days.length === WEEKDAYS.length ? null : days;
|
|
45
|
-
}
|
|
46
|
-
function parseHoursOfDay(value, label) {
|
|
47
|
-
const entries = Array.isArray(value) ? value : [value];
|
|
48
|
-
if (entries.length === 0) fail$1(`${label} must name at least one hour`);
|
|
49
|
-
for (const entry of entries) if (!Number.isInteger(entry) || entry < 0 || entry > 23) fail$1(`${label}: ${JSON.stringify(entry)} must be a whole hour from 0 to 23; the platform picks the minute`);
|
|
50
|
-
return [...new Set(entries)].sort((a, b) => a - b);
|
|
51
|
-
}
|
|
52
|
-
function hourly(options) {
|
|
53
|
-
if (options !== void 0) fail$1(`hourly() takes no options; the platform decides where in the hour a schedule runs`);
|
|
54
|
-
return { kind: "hourly" };
|
|
55
|
-
}
|
|
56
|
-
function daily(options = {}) {
|
|
57
|
-
return {
|
|
58
|
-
kind: "daily",
|
|
59
|
-
at: options.at === void 0 ? null : parseHoursOfDay(options.at, "daily({ at })"),
|
|
60
|
-
days: options.days === void 0 ? null : parseDays(options.days, "daily({ days })")
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function weekly(options) {
|
|
64
|
-
if (typeof options !== "object" || options === null) fail$1(`weekly() requires { on: "monday", at: 7 }`);
|
|
65
|
-
return {
|
|
66
|
-
kind: "daily",
|
|
67
|
-
at: options.at === void 0 ? null : parseHoursOfDay(options.at, "weekly({ at })"),
|
|
68
|
-
days: [parseWeekday(options.on, "weekly({ on })")]
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function isHourSet(value) {
|
|
72
|
-
if (value === null) return true;
|
|
73
|
-
if (!Array.isArray(value) || value.length === 0) return false;
|
|
74
|
-
return value.every((hour, index) => Number.isInteger(hour) && hour >= 0 && hour <= 23 && (index === 0 || hour > value[index - 1]));
|
|
75
|
-
}
|
|
76
|
-
function isDaySet(value) {
|
|
77
|
-
if (value === null) return true;
|
|
78
|
-
if (!Array.isArray(value) || value.length === 0 || value.length >= WEEKDAYS.length) return false;
|
|
79
|
-
const indexes = value.map((day) => WEEKDAYS.indexOf(day));
|
|
80
|
-
return indexes.every((index, position) => index >= 0 && (position === 0 || index > indexes[position - 1]));
|
|
81
|
-
}
|
|
82
|
-
function isCadence(value) {
|
|
83
|
-
if (typeof value !== "object" || value === null) return false;
|
|
84
|
-
const cadence = value;
|
|
85
|
-
if (cadence.kind === "hourly") return Object.keys(cadence).length === 1;
|
|
86
|
-
if (cadence.kind === "daily") return isHourSet(cadence.at) && isDaySet(cadence.days);
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/core/schedule.ts
|
|
91
|
-
const OVERLAP_POLICIES = [
|
|
92
|
-
"skip",
|
|
93
|
-
"allow",
|
|
94
|
-
"buffer-one"
|
|
95
|
-
];
|
|
96
|
-
function fail(message) {
|
|
97
|
-
throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
|
|
98
|
-
}
|
|
99
|
-
const CANONICAL_ZONES = new Set(typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : []);
|
|
100
|
-
function resolveTimeZone(schedule) {
|
|
101
|
-
const timeZone = schedule.timeZone;
|
|
102
|
-
if (typeof timeZone !== "string" || timeZone === "") fail(`schedule "${schedule.id}" needs a timeZone, such as "Europe/Stockholm" or "UTC"`);
|
|
103
|
-
if (timeZone !== "UTC" && CANONICAL_ZONES.size > 0 && !CANONICAL_ZONES.has(timeZone)) fail(`schedule "${schedule.id}" timeZone "${timeZone}" must be "UTC" or a canonical IANA name such as "Europe/Stockholm"; fixed offsets and aliases such as "EST", "GMT", "Etc/GMT+5", and "US/Pacific" are not accepted`);
|
|
104
|
-
new Intl.DateTimeFormat("en", { timeZone });
|
|
105
|
-
return timeZone;
|
|
106
|
-
}
|
|
107
|
-
function defineSchedule(schedule) {
|
|
108
|
-
assertIdentifier("schedule", schedule.id);
|
|
109
|
-
if (!isCadence(schedule.cadence)) fail(`schedule "${schedule.id}" cadence must come from hourly(), daily(), or weekly()`);
|
|
110
|
-
const cadence = schedule.cadence;
|
|
111
|
-
const timeZone = resolveTimeZone(schedule);
|
|
112
|
-
const overlapPolicy = schedule.overlapPolicy ?? "skip";
|
|
113
|
-
if (!OVERLAP_POLICIES.includes(overlapPolicy)) fail(`schedule "${schedule.id}" overlapPolicy must be one of ${OVERLAP_POLICIES.join(", ")}`);
|
|
114
|
-
const enabled = schedule.enabled ?? true;
|
|
115
|
-
if (typeof enabled !== "boolean") fail(`schedule "${schedule.id}" enabled must be a boolean`);
|
|
116
|
-
return {
|
|
117
|
-
...schedule,
|
|
118
|
-
type: "schedule",
|
|
119
|
-
cadence,
|
|
120
|
-
timeZone,
|
|
121
|
-
overlapPolicy,
|
|
122
|
-
enabled
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
|
-
//#region src/core/workflow.ts
|
|
127
|
-
function registerWorkflows(definition) {
|
|
128
|
-
for (const key of Object.keys(definition)) {
|
|
129
|
-
if (key === "workflows" || key === "triggers") continue;
|
|
130
|
-
throw new Error(key === "schedules" ? `@lovable.dev/workflows-sdk: registerWorkflows() no longer takes "schedules"; rename the key to "triggers"` : `@lovable.dev/workflows-sdk: registerWorkflows() does not take "${key}"`);
|
|
131
|
-
}
|
|
132
|
-
const { workflows, triggers = [] } = definition;
|
|
133
|
-
const ids = /* @__PURE__ */ new Set();
|
|
134
|
-
for (const workflow of workflows) {
|
|
135
|
-
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
|
|
136
|
-
assertIdentifier("workflow", workflow.id);
|
|
137
|
-
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");
|
|
138
|
-
if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
|
|
139
|
-
ids.add(workflow.id);
|
|
140
|
-
}
|
|
141
|
-
const scheduleIds = /* @__PURE__ */ new Set();
|
|
142
|
-
const registeredTriggers = triggers.map((trigger) => {
|
|
143
|
-
const definition = defineSchedule(trigger);
|
|
144
|
-
if (scheduleIds.has(definition.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate schedule ID "${definition.id}"`);
|
|
145
|
-
if (!workflows.includes(definition.workflow)) throw new Error(`@lovable.dev/workflows-sdk: schedule "${definition.id}" references an unregistered workflow`);
|
|
146
|
-
scheduleIds.add(definition.id);
|
|
147
|
-
return definition;
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
workflows: [...workflows],
|
|
151
|
-
triggers: registeredTriggers
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region package.json
|
|
156
|
-
var version = "0.0.0-dev.26";
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/manifests/json.ts
|
|
159
|
-
function toJson(value, jsonPath, ancestors = /* @__PURE__ */ new Set()) {
|
|
160
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
161
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
162
|
-
if (typeof value !== "object" || ancestors.has(value)) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain finite, acyclic JSON values`);
|
|
163
|
-
ancestors.add(value);
|
|
164
|
-
try {
|
|
165
|
-
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must not contain symbol keys`);
|
|
166
|
-
if (Array.isArray(value)) {
|
|
167
|
-
if (Object.keys(value).length !== value.length) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must be a dense JSON array without extra properties`);
|
|
168
|
-
return Array.from(value, (item, index) => toJson(item, `${jsonPath}[${index}]`, ancestors));
|
|
169
|
-
}
|
|
170
|
-
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain plain JSON objects`);
|
|
171
|
-
return Object.fromEntries(Object.keys(value).sort().map((key) => [key, toJson(value[key], `${jsonPath}.${key}`, ancestors)]));
|
|
172
|
-
} finally {
|
|
173
|
-
ancestors.delete(value);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/manifests/generate.ts
|
|
178
|
-
function serializeSchema(schema, direction, label) {
|
|
179
|
-
if (!schema) return void 0;
|
|
180
|
-
const standard = schema["~standard"];
|
|
181
|
-
if (typeof standard.jsonSchema?.[direction] !== "function") throw new Error(`@lovable.dev/workflows-sdk: ${label} must support Standard JSON Schema conversion`);
|
|
182
|
-
try {
|
|
183
|
-
return toJson(standard.jsonSchema[direction]({ target: "draft-2020-12" }), label);
|
|
184
|
-
} catch (cause) {
|
|
185
|
-
throw new Error(`@lovable.dev/workflows-sdk: cannot serialize ${label}`, { cause });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
async function generateManifests(definition) {
|
|
189
|
-
const { extractWorkflowGraph } = await import("./graph-Qx9mvqnC.js");
|
|
190
|
-
const { findBranchMetadataIssues } = await import("./branch-metadata-IXuazOmY.js");
|
|
191
|
-
const { findWorkflowContextEscapes } = await import("./context-escapes-x0J0HUgC.js");
|
|
192
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-NnTrnieX.js");
|
|
193
|
-
const { findNestedDurableOperations } = await import("./nested-operations-DYVa5c5A.js");
|
|
194
|
-
const { findOperationDescriptionIssues } = await import("./operation-descriptions-BLZC8bxV.js");
|
|
195
|
-
const { findStepMetadataIssues } = await import("./step-metadata-MjyYQjOy.js");
|
|
196
|
-
const collection = registerWorkflows(definition);
|
|
197
|
-
const manifests = [];
|
|
198
|
-
for (const workflow of collection.workflows) {
|
|
199
|
-
if (workflow.previousVersions?.length) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" previousVersions are not supported yet`);
|
|
200
|
-
const contextEscape = (await findWorkflowContextEscapes(workflow.handler))[0];
|
|
201
|
-
if (contextEscape?.kind === "destructured") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" destructures its workflow context parameter; accept one context identifier and read its properties directly in the workflow handler`);
|
|
202
|
-
if (contextEscape?.kind === "method") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context}.${contextEscape.method} as a value; durable context methods must be called directly in the workflow handler`);
|
|
203
|
-
if (contextEscape?.kind === "context") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses ${contextEscape.context} as a value; the workflow context cannot be passed or aliased, so pass only extracted values such as ${contextEscape.context}.input to helpers`);
|
|
204
|
-
const nested = (await findNestedDurableOperations(workflow.handler))[0];
|
|
205
|
-
if (nested) {
|
|
206
|
-
const parent = nested.parentStepId ? `ctx.step(${JSON.stringify(nested.parentStepId)})` : "ctx.step()";
|
|
207
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${nested.method}() inside ${parent}; step bodies are atomic and cannot contain durable operations`);
|
|
208
|
-
}
|
|
209
|
-
for (const duplicate of await findDuplicateOperationIds(workflow.handler)) {
|
|
210
|
-
if (duplicate.method === "step") {
|
|
211
|
-
const use = duplicate.reason === "loop" ? "inside a loop or callback" : "more than once";
|
|
212
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses step id ${JSON.stringify(duplicate.id)} ${use}; every step id must be unique within a workflow`);
|
|
213
|
-
}
|
|
214
|
-
const where = duplicate.reason === "loop" ? "inside a loop" : "more than once";
|
|
215
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}() ${where} with the default id "${duplicate.id}"; replay cannot tell the occurrences apart, so pass an explicit { id } per call site`);
|
|
216
|
-
}
|
|
217
|
-
const metadataIssue = (await findStepMetadataIssues(workflow.handler))[0];
|
|
218
|
-
if (metadataIssue?.kind === "description") {
|
|
219
|
-
const step = metadataIssue.stepId ? `ctx.step(${JSON.stringify(metadataIssue.stepId)})` : "ctx.step()";
|
|
220
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} must include a static { meta: { description: "..." } }`);
|
|
221
|
-
}
|
|
222
|
-
if (metadataIssue?.kind === "group") {
|
|
223
|
-
const step = metadataIssue.stepId ? `ctx.step(${JSON.stringify(metadataIssue.stepId)})` : "ctx.step()";
|
|
224
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} is declared in a loop or callback and must include a static { meta: { group: { id: "...", label: "..." } } }`);
|
|
225
|
-
}
|
|
226
|
-
if (metadataIssue?.kind === "loop-form") {
|
|
227
|
-
const step = metadataIssue.stepId ? `ctx.step(${JSON.stringify(metadataIssue.stepId)})` : "ctx.step()";
|
|
228
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${step} uses an unsupported loop form; await ctx.step() directly as the only statement in a for...of loop for sequential execution, or use Promise.all(items.map((item) => ctx.step(...))) for parallel execution`);
|
|
229
|
-
}
|
|
230
|
-
if (metadataIssue?.kind === "duplicate-group") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses group id ${JSON.stringify(metadataIssue.groupId)} at more than one repeated step callsite; every group id must identify one callsite`);
|
|
231
|
-
const operationDescriptionIssue = (await findOperationDescriptionIssues(workflow.handler))[0];
|
|
232
|
-
if (operationDescriptionIssue) {
|
|
233
|
-
const { method } = operationDescriptionIssue;
|
|
234
|
-
const description = method === "approve" ? "{ description: \"...\" }" : "{ meta: { description: \"...\" } }";
|
|
235
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ctx.${method}() must include a static ${description}`);
|
|
236
|
-
}
|
|
237
|
-
const branchMetadataIssue = (await findBranchMetadataIssues(workflow.handler))[0];
|
|
238
|
-
if (branchMetadataIssue?.kind === "path") {
|
|
239
|
-
const operation = branchMetadataIssue.method === "step" && branchMetadataIssue.stepId ? `ctx.step(${JSON.stringify(branchMetadataIssue.stepId)})` : `ctx.${branchMetadataIssue.method}()`;
|
|
240
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ${operation} must include a static meta.branches path matching its enclosing if/else branches; each entry needs { id, description }`);
|
|
241
|
-
}
|
|
242
|
-
if (branchMetadataIssue?.kind === "inconsistent") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses inconsistent metadata for branch ${JSON.stringify(branchMetadataIssue.branchId)}; every operation under one if statement must use the same branch id and description`);
|
|
243
|
-
if (branchMetadataIssue?.kind === "duplicate-id") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses branch id ${JSON.stringify(branchMetadataIssue.branchId)} for more than one if statement; every branch id must identify one condition`);
|
|
244
|
-
const metadata = {
|
|
245
|
-
id: workflow.id,
|
|
246
|
-
...workflow.description === void 0 ? {} : { description: workflow.description },
|
|
247
|
-
...workflow.version === void 0 ? {} : { version: workflow.version },
|
|
248
|
-
...workflow.inputSchema ? { inputSchema: serializeSchema(workflow.inputSchema, "input", `${workflow.id}.input`) } : {},
|
|
249
|
-
...workflow.outputSchema ? { outputSchema: serializeSchema(workflow.outputSchema, "output", `${workflow.id}.output`) } : {},
|
|
250
|
-
...workflow.stateSchema ? { stateSchema: serializeSchema(workflow.stateSchema, "output", `${workflow.id}.state`) } : {}
|
|
251
|
-
};
|
|
252
|
-
const triggers = [];
|
|
253
|
-
for (const schedule of collection.triggers.filter((trigger) => trigger.workflow === workflow)) {
|
|
254
|
-
const input = toJson(schedule.input, `schedule "${schedule.id}" input`);
|
|
255
|
-
const schema = schedule.workflow.inputSchema;
|
|
256
|
-
if (schema) {
|
|
257
|
-
const result = await schema["~standard"].validate(input);
|
|
258
|
-
if (result.issues) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" input is invalid: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
259
|
-
}
|
|
260
|
-
triggers.push({
|
|
261
|
-
type: schedule.type,
|
|
262
|
-
id: schedule.id,
|
|
263
|
-
cadence: schedule.cadence,
|
|
264
|
-
timeZone: schedule.timeZone,
|
|
265
|
-
enabled: schedule.enabled,
|
|
266
|
-
overlapPolicy: schedule.overlapPolicy,
|
|
267
|
-
input
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
triggers.sort((a, b) => {
|
|
271
|
-
const key = (entry) => `${entry.type}\u0000${entry.id}`;
|
|
272
|
-
return key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0;
|
|
273
|
-
});
|
|
274
|
-
const manifest = {
|
|
275
|
-
version: 1,
|
|
276
|
-
sdkVersion: version,
|
|
277
|
-
workflow: metadata,
|
|
278
|
-
triggers,
|
|
279
|
-
graph: await extractWorkflowGraph(workflow.handler)
|
|
280
|
-
};
|
|
281
|
-
toJson(manifest, "manifest");
|
|
282
|
-
manifests.push(manifest);
|
|
283
|
-
}
|
|
284
|
-
return manifests.sort((a, b) => a.workflow.id < b.workflow.id ? -1 : a.workflow.id > b.workflow.id ? 1 : 0);
|
|
285
|
-
}
|
|
286
|
-
//#endregion
|
|
287
|
-
export { defineSchedule as a, weekly as c, registerWorkflows as i, createMiddleware as n, daily as o, createWorkflow as r, hourly as s, generateManifests as t };
|