@lovable.dev/workflows-sdk 0.0.0-dev.44 → 0.0.0-dev.46
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 -0
- package/dist/{branch-metadata-strJDEAy.js → branch-metadata-BwgoU3B3.js} +2 -1
- package/dist/{context-escapes-CNTx3xkk.js → context-escapes-KxFzYeSZ.js} +2 -1
- package/dist/{duplicate-ids-Cq6Y0pgf.js → duplicate-ids-Bd_mn83C.js} +2 -1
- package/dist/{generate-CqXgNBpN.js → generate-DQ_hJH18.js} +9 -9
- package/dist/{graph-3Syx7KCj.js → graph-BbemsojK.js} +68 -13
- package/dist/index.d.ts +46 -45
- package/dist/index.js +5 -1
- package/dist/llm-validation-89xbXKQw.js +59 -0
- package/dist/{nested-operations-BsAo5V1I.js → nested-operations-D2pHgpWr.js} +2 -1
- package/dist/{operation-descriptions-Dh0T3SnD.js → operation-descriptions-Cl3OO7_8.js} +3 -2
- package/dist/{step-metadata-FnRBeBRd.js → step-metadata-DPUZQ-aG.js} +1 -1
- package/dist/vite.js +1 -1
- package/dist/{wait-deadlines-CPg8h2v1.js → wait-deadlines-B6E9n_0Z.js} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,11 +64,21 @@ Every durable operation needs a static, user-facing description:
|
|
|
64
64
|
| Operation | Description field |
|
|
65
65
|
| --- | --- |
|
|
66
66
|
| `ctx.step` | Third argument: `meta.description` |
|
|
67
|
+
| `ctx.llm` | Second argument: `meta.description` |
|
|
67
68
|
| `ctx.sleep`, `ctx.sleepUntil` | Second argument: `meta.description` |
|
|
68
69
|
| `ctx.waitForEvent` | Second argument: `meta.description` |
|
|
69
70
|
| `ctx.now`, `ctx.uuid` | First argument: `meta.description` |
|
|
70
71
|
| `ctx.approve` | First argument: `description` |
|
|
71
72
|
|
|
73
|
+
`ctx.llm(request, options): Promise<string>` declares an LLM step. Pass a
|
|
74
|
+
provider-prefixed `model` and either `prompt` or text-only `messages`, with
|
|
75
|
+
a unique literal `options.id` and `options.meta.description`. The App Workflows
|
|
76
|
+
service currently saves and returns `"[Mock LLM] This is a placeholder response."`;
|
|
77
|
+
it makes no AI Gateway call. Saved results replay, and saved final errors throw
|
|
78
|
+
into the workflow's `try/catch`.
|
|
79
|
+
Run LLM workflows through the generated `/steps` route. The standalone
|
|
80
|
+
`createTanStackWorkflowHandler` uses TanStack's runtime and does not support LLM steps.
|
|
81
|
+
|
|
72
82
|
Both `ctx.approve` and `ctx.waitForEvent` require `timeoutMs`: a duration in
|
|
73
83
|
milliseconds, written as a finite numeric literal of at least 60000 (one minute) (for example,
|
|
74
84
|
`3600000` for one hour or `86400000` for one day). The Vite build fails if it
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.js";
|
|
2
2
|
//#region src/manifests/branch-metadata.ts
|
|
3
3
|
const optionsArgument = {
|
|
4
4
|
step: 2,
|
|
5
|
+
llm: 1,
|
|
5
6
|
approve: 0,
|
|
6
7
|
sleep: 1,
|
|
7
8
|
sleepUntil: 1,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.js";
|
|
2
2
|
//#region src/manifests/context-escapes.ts
|
|
3
3
|
const durableMethods = /* @__PURE__ */ new Set([
|
|
4
4
|
"step",
|
|
5
|
+
"llm",
|
|
5
6
|
"approve",
|
|
6
7
|
"waitForEvent",
|
|
7
8
|
"sleep",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.js";
|
|
2
2
|
//#region src/manifests/duplicate-ids.ts
|
|
3
3
|
/** Where an explicit `{ id }` would sit for each operation. */
|
|
4
4
|
const optionsArgument = {
|
|
@@ -8,6 +8,7 @@ const optionsArgument = {
|
|
|
8
8
|
sleep: 1,
|
|
9
9
|
sleepUntil: 1,
|
|
10
10
|
waitForEvent: 1,
|
|
11
|
+
llm: 1,
|
|
11
12
|
step: -1
|
|
12
13
|
};
|
|
13
14
|
/** Ids provably reached more than once, or why the handler could not be checked. */
|
|
@@ -6626,7 +6626,7 @@ function listValueFromJson(listValue, json) {
|
|
|
6626
6626
|
}
|
|
6627
6627
|
//#endregion
|
|
6628
6628
|
//#region package.json
|
|
6629
|
-
var version = "0.0.0-dev.
|
|
6629
|
+
var version = "0.0.0-dev.46";
|
|
6630
6630
|
//#endregion
|
|
6631
6631
|
//#region src/proto/lovable/appworkflows/v1/workflow_manifest_pb.ts
|
|
6632
6632
|
/**
|
|
@@ -6824,15 +6824,15 @@ function serializeSchema(schema, direction, label) {
|
|
|
6824
6824
|
}
|
|
6825
6825
|
}
|
|
6826
6826
|
async function generateManifests(definition, options = {}) {
|
|
6827
|
-
const { extractWorkflowGraph } = await import("./graph-
|
|
6828
|
-
const { findBranchMetadataIssues } = await import("./branch-metadata-
|
|
6829
|
-
const { findWorkflowContextEscapes } = await import("./context-escapes-
|
|
6830
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-
|
|
6827
|
+
const { extractWorkflowGraph } = await import("./graph-BbemsojK.js");
|
|
6828
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-BwgoU3B3.js");
|
|
6829
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-KxFzYeSZ.js");
|
|
6830
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-Bd_mn83C.js");
|
|
6831
6831
|
const { DURABLE_ID_REQUIRED } = await import("./durable-ids-Cx341nJQ.js").then((n) => n.n);
|
|
6832
|
-
const { findNestedDurableOperations } = await import("./nested-operations-
|
|
6833
|
-
const { findOperationDescriptionIssues } = await import("./operation-descriptions-
|
|
6834
|
-
const { findStepMetadataIssues } = await import("./step-metadata-
|
|
6835
|
-
const { findWaitDeadlineIssues } = await import("./wait-deadlines-
|
|
6832
|
+
const { findNestedDurableOperations } = await import("./nested-operations-D2pHgpWr.js");
|
|
6833
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-Cl3OO7_8.js");
|
|
6834
|
+
const { findStepMetadataIssues } = await import("./step-metadata-DPUZQ-aG.js");
|
|
6835
|
+
const { findWaitDeadlineIssues } = await import("./wait-deadlines-B6E9n_0Z.js");
|
|
6836
6836
|
const { WAIT_DEADLINE_REQUIRED } = await import("./wait-deadlines-DpK-Fgnd.js");
|
|
6837
6837
|
const collection = registerWorkflows(definition);
|
|
6838
6838
|
const manifests = [];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { _ as WorkflowManifestStepNodeV1Schema, a as WorkflowManifestGraphEdgeV1Schema, b as WorkflowManifestWaitForEventNodeV1Schema, c as WorkflowManifestLlmNodeV1Schema, d as WorkflowManifestOrderEdgeV1Schema, f as WorkflowManifestParallelNodeV1Schema, g as WorkflowManifestStepExecutionPolicyV1Schema, h as WorkflowManifestSleepUntilNodeV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestLoopNodeV1Schema, m as WorkflowManifestSleepNodeV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphNodeV1Schema, p as WorkflowManifestRepeatedStepV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphV1Schema, u as WorkflowManifestNowNodeV1Schema, v as WorkflowManifestUnknownNodeV1Schema, x as create, y as WorkflowManifestUuidNodeV1Schema } from "./generate-
|
|
1
|
+
import { _ as WorkflowManifestStepNodeV1Schema, a as WorkflowManifestGraphEdgeV1Schema, b as WorkflowManifestWaitForEventNodeV1Schema, c as WorkflowManifestLlmNodeV1Schema, d as WorkflowManifestOrderEdgeV1Schema, f as WorkflowManifestParallelNodeV1Schema, g as WorkflowManifestStepExecutionPolicyV1Schema, h as WorkflowManifestSleepUntilNodeV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestLoopNodeV1Schema, m as WorkflowManifestSleepNodeV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphNodeV1Schema, p as WorkflowManifestRepeatedStepV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphV1Schema, u as WorkflowManifestNowNodeV1Schema, v as WorkflowManifestUnknownNodeV1Schema, x as create, y as WorkflowManifestUuidNodeV1Schema } from "./generate-DQ_hJH18.js";
|
|
2
|
+
import { n as assertLlmOptions, t as assertLlmModel } from "./llm-validation-89xbXKQw.js";
|
|
2
3
|
//#region src/manifests/handler-source.ts
|
|
3
4
|
const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
|
|
4
5
|
function workflowHandlerSource(handler) {
|
|
@@ -107,6 +108,10 @@ async function extractWorkflowGraph(workflow) {
|
|
|
107
108
|
return graph;
|
|
108
109
|
}
|
|
109
110
|
const context = parameter?.text;
|
|
111
|
+
const recordedLlmCalls = /* @__PURE__ */ new Set();
|
|
112
|
+
function llmError(message) {
|
|
113
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" ctx.llm() ${message}`);
|
|
114
|
+
}
|
|
110
115
|
function contains(node, predicate, skipFunctions = false) {
|
|
111
116
|
if (skipFunctions && ts.isFunctionLike(node)) return false;
|
|
112
117
|
return predicate(node) || Boolean(ts.forEachChild(node, (child) => contains(child, predicate, skipFunctions) || void 0));
|
|
@@ -197,6 +202,24 @@ async function extractWorkflowGraph(workflow) {
|
|
|
197
202
|
if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
|
|
198
203
|
}
|
|
199
204
|
}
|
|
205
|
+
function llmObject(node, label, keys) {
|
|
206
|
+
const options = readableOptions(node);
|
|
207
|
+
if (!options) llmError(`${label} must be an inline object with static field names`);
|
|
208
|
+
const seen = /* @__PURE__ */ new Set();
|
|
209
|
+
for (const property of options.properties) {
|
|
210
|
+
const name = property.name;
|
|
211
|
+
if (!name || !ts.isIdentifier(name) && !ts.isStringLiteral(name) || seen.has(name.text)) llmError(`${label} must have distinct static field names`);
|
|
212
|
+
if (keys && !keys.includes(name.text)) llmError(`${label} contains unsupported fields`);
|
|
213
|
+
seen.add(name.text);
|
|
214
|
+
}
|
|
215
|
+
return options;
|
|
216
|
+
}
|
|
217
|
+
function llmLiteral(node, label) {
|
|
218
|
+
if (!node) return void 0;
|
|
219
|
+
const value = stringLiteral(node) ?? numberLiteral(node);
|
|
220
|
+
if (value === void 0) llmError(`${label} must be a static number or string; callbacks are not supported`);
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
200
223
|
function branchMetadata(meta) {
|
|
201
224
|
const branches = option(meta, "branches");
|
|
202
225
|
if (!branches || !ts.isArrayLiteralExpression(branches)) return void 0;
|
|
@@ -300,20 +323,50 @@ async function extractWorkflowGraph(workflow) {
|
|
|
300
323
|
}, parents);
|
|
301
324
|
}
|
|
302
325
|
if (method === "llm") {
|
|
303
|
-
const options =
|
|
326
|
+
const options = llmObject(call.arguments[1], "options", [
|
|
327
|
+
"id",
|
|
328
|
+
"meta",
|
|
329
|
+
"timeout",
|
|
330
|
+
"retry"
|
|
331
|
+
]);
|
|
304
332
|
const stepId = durableStepId(call.arguments[1], options);
|
|
305
|
-
if (stepId === void 0)
|
|
306
|
-
const description =
|
|
307
|
-
if (description === void 0)
|
|
333
|
+
if (stepId === void 0) llmError("requires a static id; dynamic LLM IDs are not supported");
|
|
334
|
+
const description = stringLiteral(option(llmObject(option(options, "meta"), "meta"), "description"));
|
|
335
|
+
if (description === void 0) llmError("requires a static meta.description");
|
|
308
336
|
const model = stringLiteral(option(readableOptions(call.arguments[0]), "model"));
|
|
309
|
-
|
|
310
|
-
|
|
337
|
+
if (model !== void 0) assertLlmModel(model);
|
|
338
|
+
const retryNode = option(options, "retry");
|
|
339
|
+
let retry = workflow.defaultStepRetry;
|
|
340
|
+
if (retryNode) {
|
|
341
|
+
const retryOptions = llmObject(retryNode, "retry", [
|
|
342
|
+
"maxAttempts",
|
|
343
|
+
"backoff",
|
|
344
|
+
"baseMs"
|
|
345
|
+
]);
|
|
346
|
+
retry = Object.fromEntries(retryOptions.properties.map((property) => {
|
|
347
|
+
const field = property;
|
|
348
|
+
const key = field.name.text;
|
|
349
|
+
return [key, llmLiteral(field.initializer, `retry.${key}`)];
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
const resolved = {
|
|
353
|
+
id: stepId,
|
|
354
|
+
meta: { description },
|
|
355
|
+
retry,
|
|
356
|
+
timeout: llmLiteral(option(options, "timeout"), "timeout")
|
|
357
|
+
};
|
|
358
|
+
assertLlmOptions(resolved);
|
|
359
|
+
const executionPolicy = create(WorkflowManifestStepExecutionPolicyV1Schema, {
|
|
360
|
+
...runtimeRetry(resolved.retry),
|
|
361
|
+
timeoutMs: Math.min(resolved.timeout ?? 12e4, 6e5)
|
|
362
|
+
});
|
|
363
|
+
recordedLlmCalls.add(call);
|
|
311
364
|
return addNode(stepId, {
|
|
312
365
|
case: "llm",
|
|
313
366
|
value: create(WorkflowManifestLlmNodeV1Schema, {
|
|
314
367
|
stepId,
|
|
315
368
|
description,
|
|
316
|
-
|
|
369
|
+
executionPolicy,
|
|
317
370
|
...model === void 0 ? {} : { model }
|
|
318
371
|
})
|
|
319
372
|
}, parents);
|
|
@@ -645,11 +698,13 @@ async function extractWorkflowGraph(workflow) {
|
|
|
645
698
|
return statementFlow(path(unknown("Loops and other control flow are not supported yet", parents)));
|
|
646
699
|
}
|
|
647
700
|
const tails = [];
|
|
648
|
-
if (!ts.isBlock(fn.body))
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
701
|
+
if (!ts.isBlock(fn.body)) expression(fn.body, tails, true);
|
|
702
|
+
else statements(fn.body.statements, tails, 0);
|
|
703
|
+
const checkLlmCalls = (node) => {
|
|
704
|
+
if ((ts.isPropertyAccessExpression(node) && node.name.text === "llm" || ts.isElementAccessExpression(node) && stringLiteral(node.argumentExpression) === "llm") && ts.isIdentifier(node.expression) && node.expression.text === context && (!ts.isCallExpression(node.parent) || !recordedLlmCalls.has(node.parent))) llmError("must be awaited or returned directly, or used in a fixed Promise.all array; loops and helper callbacks are not supported");
|
|
705
|
+
ts.forEachChild(node, checkLlmCalls);
|
|
706
|
+
};
|
|
707
|
+
checkLlmCalls(fn.body);
|
|
653
708
|
return graph;
|
|
654
709
|
}
|
|
655
710
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
1
|
import { AccumulateExtensions, AnyMiddleware, AnyWorkflowDefinition, AnyWorkflowDefinition as AnyWorkflowDefinition$1, ApprovalResult, ApproveOptions as ApproveOptions$1, CreateWorkflowConfig, Ctx as Ctx$1, InferSchema, RunStore, SchemaInput, StepContext, StepOptions, WaitForEventOptions as WaitForEventOptions$1, WorkflowBuilder, WorkflowDefinition, WorkflowDefinition as WorkflowDefinition$1, WorkflowEvent, WorkflowInput, WorkflowInput as WorkflowInput$1, WorkflowMetadata, WorkflowOutput, WorkflowState, createMiddleware } from "@tanstack/workflow-core";
|
|
2
|
+
//#region src/core/step-metadata.d.ts
|
|
3
|
+
interface WorkflowStepGroup {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
interface WorkflowBranchMetadata {
|
|
8
|
+
id: string;
|
|
9
|
+
description: string;
|
|
10
|
+
}
|
|
11
|
+
type WorkflowOperationMetadata = Record<string, unknown> & {
|
|
12
|
+
description: string;
|
|
13
|
+
branches?: WorkflowBranchMetadata[];
|
|
14
|
+
};
|
|
15
|
+
type WorkflowStepMetadata = WorkflowOperationMetadata & {
|
|
16
|
+
group?: WorkflowStepGroup;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/core/llm.d.ts
|
|
20
|
+
type LlmRequest = {
|
|
21
|
+
model: string;
|
|
22
|
+
system?: string;
|
|
23
|
+
maxTokens?: number;
|
|
24
|
+
} & ({
|
|
25
|
+
prompt: string;
|
|
26
|
+
messages?: never;
|
|
27
|
+
} | {
|
|
28
|
+
prompt?: never;
|
|
29
|
+
messages: {
|
|
30
|
+
role: "user" | "assistant";
|
|
31
|
+
content: string;
|
|
32
|
+
}[];
|
|
33
|
+
});
|
|
34
|
+
interface LlmStepOptions {
|
|
35
|
+
id: string;
|
|
36
|
+
meta: WorkflowStepMetadata;
|
|
37
|
+
timeout?: number;
|
|
38
|
+
retry?: {
|
|
39
|
+
maxAttempts: number;
|
|
40
|
+
backoff?: "fixed" | "exponential";
|
|
41
|
+
baseMs?: number;
|
|
42
|
+
shouldRetry?: never;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
type LlmStep = (request: LlmRequest, options: LlmStepOptions) => Promise<string>;
|
|
46
|
+
//#endregion
|
|
2
47
|
//#region src/core/cadence.d.ts
|
|
3
48
|
type Weekday = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
|
|
4
49
|
type Cadence = {
|
|
@@ -55,6 +100,7 @@ type WaitForEventOptions<TPayload = unknown> = Omit<WaitForEventOptions$1<TPaylo
|
|
|
55
100
|
deadline?: never;
|
|
56
101
|
};
|
|
57
102
|
type Ctx<TInput = unknown, TState = Record<string, unknown>, TExtensions = unknown> = Omit<Ctx$1<TInput, TState>, "approve" | "waitForEvent"> & {
|
|
103
|
+
llm: LlmStep;
|
|
58
104
|
approve: (options: ApproveOptions) => Promise<ApprovalResult>;
|
|
59
105
|
waitForEvent: <TPayload = unknown>(name: string, options: WaitForEventOptions<TPayload>) => Promise<TPayload>;
|
|
60
106
|
} & TExtensions;
|
|
@@ -73,51 +119,6 @@ declare function registerWorkflows<const TWorkflows extends readonly AnyWorkflow
|
|
|
73
119
|
triggers?: readonly TriggerDefinition[];
|
|
74
120
|
}): WorkflowsDefinition<TWorkflows[number]>;
|
|
75
121
|
//#endregion
|
|
76
|
-
//#region src/core/step-metadata.d.ts
|
|
77
|
-
interface WorkflowStepGroup {
|
|
78
|
-
id: string;
|
|
79
|
-
label: string;
|
|
80
|
-
}
|
|
81
|
-
interface WorkflowBranchMetadata {
|
|
82
|
-
id: string;
|
|
83
|
-
description: string;
|
|
84
|
-
}
|
|
85
|
-
type WorkflowOperationMetadata = Record<string, unknown> & {
|
|
86
|
-
description: string;
|
|
87
|
-
branches?: WorkflowBranchMetadata[];
|
|
88
|
-
};
|
|
89
|
-
type WorkflowStepMetadata = WorkflowOperationMetadata & {
|
|
90
|
-
group?: WorkflowStepGroup;
|
|
91
|
-
};
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/core/llm.d.ts
|
|
94
|
-
type LlmRequest = {
|
|
95
|
-
model: string;
|
|
96
|
-
system?: string;
|
|
97
|
-
maxTokens?: number;
|
|
98
|
-
} & ({
|
|
99
|
-
prompt: string;
|
|
100
|
-
messages?: never;
|
|
101
|
-
} | {
|
|
102
|
-
prompt?: never;
|
|
103
|
-
messages: {
|
|
104
|
-
role: "user" | "assistant";
|
|
105
|
-
content: string;
|
|
106
|
-
}[];
|
|
107
|
-
});
|
|
108
|
-
interface LlmStepOptions {
|
|
109
|
-
id: string;
|
|
110
|
-
meta: WorkflowStepMetadata;
|
|
111
|
-
timeout?: number;
|
|
112
|
-
retry?: {
|
|
113
|
-
maxAttempts: number;
|
|
114
|
-
backoff?: "fixed" | "exponential";
|
|
115
|
-
baseMs?: number;
|
|
116
|
-
shouldRetry?: never;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
type LlmStep = (request: LlmRequest, options: LlmStepOptions) => Promise<string>;
|
|
120
|
-
//#endregion
|
|
121
122
|
//#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@bufbuild/protobuf/2.10.1/b0955b226816adda68977638196f96a6e65cec2605734621338f49f7ea29042e/node_modules/@bufbuild/protobuf/dist/esm/json-value.d.ts
|
|
122
123
|
/**
|
|
123
124
|
* Represents any possible JSON value:
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as DURABLE_ID_REQUIRED } from "./durable-ids-Cx341nJQ.js";
|
|
2
|
-
import { C as createWorkflow, D as daily, E as defineSchedule, O as hourly, S as createMiddleware, T as workflowVersions, k as weekly, t as generateManifests, w as registerWorkflows } from "./generate-
|
|
2
|
+
import { C as createWorkflow, D as daily, E as defineSchedule, O as hourly, S as createMiddleware, T as workflowVersions, k as weekly, t as generateManifests, w as registerWorkflows } from "./generate-DQ_hJH18.js";
|
|
3
|
+
import { n as assertLlmOptions, r as assertLlmRequest } from "./llm-validation-89xbXKQw.js";
|
|
3
4
|
import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
|
|
4
5
|
//#region src/stacks/tanstack/sse.ts
|
|
5
6
|
const HEADERS = {
|
|
@@ -176,9 +177,11 @@ var ReplayOperations = class {
|
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
llm = (request, options) => {
|
|
180
|
+
assertLlmOptions(options);
|
|
179
181
|
const operation = this.reach("llm", options.id, options.meta);
|
|
180
182
|
if (!operation) return this.never;
|
|
181
183
|
if (operation.answer) return operation.answer;
|
|
184
|
+
assertLlmRequest(request);
|
|
182
185
|
this.pending.push({
|
|
183
186
|
seq: operation.seq,
|
|
184
187
|
stepId: options.id,
|
|
@@ -320,6 +323,7 @@ async function replay(options) {
|
|
|
320
323
|
state,
|
|
321
324
|
signal: controller.signal,
|
|
322
325
|
runtime,
|
|
326
|
+
llm: operations.llm,
|
|
323
327
|
step: (id, fn, stepOptions) => durable("step", id, async () => fn({
|
|
324
328
|
id,
|
|
325
329
|
attempt: 1,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/core/llm-validation.ts
|
|
2
|
+
function fail(message) {
|
|
3
|
+
throw new Error(`@lovable.dev/workflows-sdk: ctx.llm() ${message}`);
|
|
4
|
+
}
|
|
5
|
+
function object(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function uint32(value) {
|
|
9
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 && value <= 4294967295;
|
|
10
|
+
}
|
|
11
|
+
function assertLlmModel(model) {
|
|
12
|
+
if (typeof model !== "string" || !/^[^/\s]+\/[^\s]+$/.test(model)) fail("requires a provider-prefixed model ID, such as openai/gpt-5");
|
|
13
|
+
}
|
|
14
|
+
function assertLlmRequest(request) {
|
|
15
|
+
if (!object(request)) fail("requires a request object");
|
|
16
|
+
if (Object.keys(request).some((key) => ![
|
|
17
|
+
"model",
|
|
18
|
+
"prompt",
|
|
19
|
+
"messages",
|
|
20
|
+
"system",
|
|
21
|
+
"maxTokens"
|
|
22
|
+
].includes(key))) fail("request contains unsupported fields");
|
|
23
|
+
assertLlmModel(request.model);
|
|
24
|
+
if (request.prompt !== void 0 === (request.messages !== void 0)) fail("requires exactly one of prompt or messages");
|
|
25
|
+
if (request.prompt !== void 0 && typeof request.prompt !== "string") fail("prompt must be a string");
|
|
26
|
+
if (request.messages !== void 0) {
|
|
27
|
+
if (!Array.isArray(request.messages) || request.messages.length === 0) fail("messages must be a nonempty array");
|
|
28
|
+
for (const message of request.messages) if (!object(message) || message.role !== "user" && message.role !== "assistant" || typeof message.content !== "string" || Object.keys(message).some((key) => key !== "role" && key !== "content")) fail("messages must contain only user/assistant roles and string content");
|
|
29
|
+
}
|
|
30
|
+
if (request.system !== void 0 && typeof request.system !== "string") fail("system must be a string");
|
|
31
|
+
if (request.maxTokens !== void 0 && !uint32(request.maxTokens)) fail("maxTokens must be an integer between 1 and 4294967295");
|
|
32
|
+
}
|
|
33
|
+
function assertLlmOptions(options) {
|
|
34
|
+
if (!object(options)) fail("requires an options object");
|
|
35
|
+
if (Object.keys(options).some((key) => ![
|
|
36
|
+
"id",
|
|
37
|
+
"meta",
|
|
38
|
+
"timeout",
|
|
39
|
+
"retry"
|
|
40
|
+
].includes(key))) fail("options contain unsupported fields");
|
|
41
|
+
if (typeof options.id !== "string" || options.id.trim() === "") fail("requires a nonempty id");
|
|
42
|
+
if (!object(options.meta) || typeof options.meta.description !== "string" || options.meta.description.trim() === "") fail("requires a nonempty meta.description");
|
|
43
|
+
if (options.timeout !== void 0 && (typeof options.timeout !== "number" || !Number.isFinite(options.timeout) || options.timeout <= 0)) fail("timeout must be finite and positive");
|
|
44
|
+
const retry = options.retry;
|
|
45
|
+
if (retry === void 0) return;
|
|
46
|
+
if (!object(retry)) fail("retry must be an object with serializable settings");
|
|
47
|
+
if (Object.keys(retry).some((key) => ![
|
|
48
|
+
"maxAttempts",
|
|
49
|
+
"backoff",
|
|
50
|
+
"baseMs",
|
|
51
|
+
"shouldRetry"
|
|
52
|
+
].includes(key))) fail("retry contains unsupported fields");
|
|
53
|
+
if (!uint32(retry.maxAttempts)) fail("retry.maxAttempts must be an integer between 1 and 4294967295");
|
|
54
|
+
if (retry.backoff !== void 0 && retry.backoff !== "fixed" && retry.backoff !== "exponential") fail("retry.backoff must be fixed or exponential; callbacks are not supported");
|
|
55
|
+
if (retry.shouldRetry !== void 0) fail("retry.shouldRetry callbacks are not supported");
|
|
56
|
+
if (retry.baseMs !== void 0 && (typeof retry.baseMs !== "number" || !Number.isFinite(retry.baseMs) || retry.baseMs < 0)) fail("retry.baseMs must be finite and nonnegative");
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { assertLlmOptions as n, assertLlmRequest as r, assertLlmModel as t };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.js";
|
|
2
2
|
//#region src/manifests/nested-operations.ts
|
|
3
3
|
const durableMethods = [
|
|
4
4
|
"step",
|
|
5
|
+
"llm",
|
|
5
6
|
"approve",
|
|
6
7
|
"waitForEvent",
|
|
7
8
|
"sleep",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.js";
|
|
2
2
|
//#region src/manifests/operation-descriptions.ts
|
|
3
3
|
const optionsArgument = {
|
|
4
4
|
approve: 0,
|
|
@@ -6,7 +6,8 @@ const optionsArgument = {
|
|
|
6
6
|
sleepUntil: 1,
|
|
7
7
|
waitForEvent: 1,
|
|
8
8
|
now: 0,
|
|
9
|
-
uuid: 0
|
|
9
|
+
uuid: 0,
|
|
10
|
+
llm: 1
|
|
10
11
|
};
|
|
11
12
|
async function findOperationDescriptionIssues(handler) {
|
|
12
13
|
const api = await loadTypeScript();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-BbemsojK.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-DQ_hJH18.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";
|