@lovable.dev/workflows-sdk 0.0.0-dev.43 → 0.0.0-dev.45
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-B6uZRRY3.js → branch-metadata-G62WrSYO.js} +2 -1
- package/dist/{context-escapes-Bk0DN2MM.js → context-escapes-amNGeKeM.js} +2 -1
- package/dist/{duplicate-ids-CB-xAZH3.js → duplicate-ids-DfN0cqRh.js} +2 -1
- package/dist/{generate-BlCztUNP.js → generate-BjN4ePEF.js} +9 -9
- package/dist/{graph-C34bH2ul.js → graph-yRbzJp-c.js} +68 -13
- package/dist/index.d.ts +13 -2
- package/dist/index.js +70 -36
- package/dist/llm-validation-89xbXKQw.js +59 -0
- package/dist/{nested-operations-CWaP7rOJ.js → nested-operations-BHCaoshq.js} +2 -1
- package/dist/{operation-descriptions-Ca6Wprd9.js → operation-descriptions-D6eGQn7m.js} +3 -2
- package/dist/{step-metadata-nQwvzDPb.js → step-metadata-DsDhO79e.js} +1 -1
- package/dist/vite.js +1 -1
- package/dist/{wait-deadlines-BHDEShlG.js → wait-deadlines-QkmYD9-l.js} +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-yRbzJp-c.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-yRbzJp-c.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-yRbzJp-c.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.45";
|
|
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-yRbzJp-c.js");
|
|
6828
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-G62WrSYO.js");
|
|
6829
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-amNGeKeM.js");
|
|
6830
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-DfN0cqRh.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-BHCaoshq.js");
|
|
6833
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-D6eGQn7m.js");
|
|
6834
|
+
const { findStepMetadataIssues } = await import("./step-metadata-DsDhO79e.js");
|
|
6835
|
+
const { findWaitDeadlineIssues } = await import("./wait-deadlines-QkmYD9-l.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-BjN4ePEF.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
|
@@ -873,6 +873,16 @@ interface MemoEntry {
|
|
|
873
873
|
result?: unknown;
|
|
874
874
|
error?: string;
|
|
875
875
|
}
|
|
876
|
+
type ExternalMemoEntry = Omit<MemoEntry, "kind" | "status" | "result" | "error"> & {
|
|
877
|
+
status: "completed";
|
|
878
|
+
error?: never;
|
|
879
|
+
} & ({
|
|
880
|
+
kind: "now";
|
|
881
|
+
result: number;
|
|
882
|
+
} | {
|
|
883
|
+
kind: "uuid";
|
|
884
|
+
result: string;
|
|
885
|
+
});
|
|
876
886
|
interface StepIntentBase {
|
|
877
887
|
seq: number;
|
|
878
888
|
stepId: string;
|
|
@@ -922,6 +932,7 @@ interface ReplayOutcome {
|
|
|
922
932
|
name: string;
|
|
923
933
|
value: Record<string, unknown>;
|
|
924
934
|
}[];
|
|
935
|
+
llmRequests?: ReadonlyMap<string, LlmRequest>;
|
|
925
936
|
output?: unknown;
|
|
926
937
|
error?: string;
|
|
927
938
|
}
|
|
@@ -978,7 +989,7 @@ type StepsResponse = StepsResponseBase & ({
|
|
|
978
989
|
executed?: StepResult<"step">;
|
|
979
990
|
external?: never;
|
|
980
991
|
} | (ExternalStep & {
|
|
981
|
-
memoDelta: [];
|
|
992
|
+
memoDelta: ExternalMemoEntry[];
|
|
982
993
|
executed?: never;
|
|
983
994
|
}));
|
|
984
995
|
declare function createStepsHandler(collection: WorkflowCollection, options?: StepsHandlerOptions): StepsHandler;
|
|
@@ -990,4 +1001,4 @@ declare function createStepsHandler(collection: WorkflowCollection, options?: St
|
|
|
990
1001
|
*/
|
|
991
1002
|
declare function toServerSentEventsResponse(events: AsyncIterable<WorkflowEvent>): Response;
|
|
992
1003
|
//#endregion
|
|
993
|
-
export { type AnyWorkflowDefinition, type ApproveOptions, type Cadence, type Ctx, type ExternalOperation, type ExternalStep, type LlmRequest, type LlmStep, type LlmStepOptions, type MemoEntry, type NextStep, type OverlapPolicy, type ReplayOutcome, type ResolvedSchedule, type ResolvedTrigger, type ScheduleDefinition, type StepContext, type StepIntent, type StepKind, type StepOptions, type StepReference, type StepResult, type StepsDisposition, type StepsHandler, type StepsHandlerOptions, type StepsRequest, type StepsResponse, type TanStackWorkflowHandler, type TanStackWorkflowHandlerOptions, type TriggerDefinition, type WaitForEventOptions, type Weekday, type WorkflowBranchMetadata, type WorkflowCollection, type WorkflowDefinition, type WorkflowInput, type WorkflowManifest, type WorkflowOperationMetadata, type WorkflowOutput, type WorkflowState, type WorkflowStepGroup, type WorkflowStepMetadata, type WorkflowsDefinition, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
|
|
1004
|
+
export { type AnyWorkflowDefinition, type ApproveOptions, type Cadence, type Ctx, type ExternalMemoEntry, type ExternalOperation, type ExternalStep, type LlmRequest, type LlmStep, type LlmStepOptions, type MemoEntry, type NextStep, type OverlapPolicy, type ReplayOutcome, type ResolvedSchedule, type ResolvedTrigger, type ScheduleDefinition, type StepContext, type StepIntent, type StepKind, type StepOptions, type StepReference, type StepResult, type StepsDisposition, type StepsHandler, type StepsHandlerOptions, type StepsRequest, type StepsResponse, type TanStackWorkflowHandler, type TanStackWorkflowHandlerOptions, type TriggerDefinition, type WaitForEventOptions, type Weekday, type WorkflowBranchMetadata, type WorkflowCollection, type WorkflowDefinition, type WorkflowInput, type WorkflowManifest, type WorkflowOperationMetadata, type WorkflowOutput, type WorkflowState, type WorkflowStepGroup, type WorkflowStepMetadata, type WorkflowsDefinition, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
|
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-BjN4ePEF.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,
|
|
@@ -417,7 +420,8 @@ async function replay(options) {
|
|
|
417
420
|
if (pending.length > 0) return {
|
|
418
421
|
...base,
|
|
419
422
|
status: "pending",
|
|
420
|
-
steps: pending
|
|
423
|
+
steps: pending,
|
|
424
|
+
llmRequests: operations.requests
|
|
421
425
|
};
|
|
422
426
|
return {
|
|
423
427
|
...base,
|
|
@@ -479,6 +483,62 @@ async function authorizeProjectRequest(request, getProjectSecret) {
|
|
|
479
483
|
}
|
|
480
484
|
}
|
|
481
485
|
//#endregion
|
|
486
|
+
//#region src/stacks/tanstack/steps-response.ts
|
|
487
|
+
function disposition(outcome) {
|
|
488
|
+
if (outcome.status === "completed") return "completed";
|
|
489
|
+
if (outcome.status === "failed") return "failed";
|
|
490
|
+
if (!outcome.steps.some((step) => step.kind === "step" || step.kind === "llm")) return "waiting";
|
|
491
|
+
return outcome.steps.length > 1 ? "fork" : "advanced";
|
|
492
|
+
}
|
|
493
|
+
function memoDelta(before, after) {
|
|
494
|
+
const existing = new Set(before.map((entry) => entry.stepId));
|
|
495
|
+
return after.filter((entry) => !existing.has(entry.stepId));
|
|
496
|
+
}
|
|
497
|
+
function isExternalMemoEntry(entry) {
|
|
498
|
+
return entry.status === "completed" && entry.error === void 0 && (entry.kind === "now" ? typeof entry.result === "number" && Number.isFinite(entry.result) : entry.kind === "uuid" && typeof entry.result === "string" && entry.result.length > 0);
|
|
499
|
+
}
|
|
500
|
+
function stepsResponse(runId, inputHash, workflowVersion, before, outcome, executed, selected) {
|
|
501
|
+
const { steps, emitted, output, error } = outcome;
|
|
502
|
+
const delta = memoDelta(before, outcome.memo);
|
|
503
|
+
const base = {
|
|
504
|
+
runId,
|
|
505
|
+
inputHash,
|
|
506
|
+
workflowVersion,
|
|
507
|
+
memoDelta: delta,
|
|
508
|
+
next: steps,
|
|
509
|
+
...emitted.length > 0 ? { emitted } : {}
|
|
510
|
+
};
|
|
511
|
+
if (outcome.status === "pending" && executed === void 0) {
|
|
512
|
+
const candidate = selected ? steps.find((step) => selected.kind === "llm" && step.kind === "llm" && step.stepId === selected.stepId) : steps.length === 1 ? steps[0] : void 0;
|
|
513
|
+
if (candidate?.kind === "llm") {
|
|
514
|
+
const aiGateway = outcome.llmRequests?.get(candidate.stepId);
|
|
515
|
+
if (!aiGateway || !delta.every(isExternalMemoEntry)) return {
|
|
516
|
+
...base,
|
|
517
|
+
disposition: "failed",
|
|
518
|
+
error: "external LLM work requires a prepared request and only completed now/uuid memo entries"
|
|
519
|
+
};
|
|
520
|
+
return {
|
|
521
|
+
...base,
|
|
522
|
+
...candidate,
|
|
523
|
+
disposition: "external",
|
|
524
|
+
memoDelta: delta,
|
|
525
|
+
next: steps.filter((step) => step.stepId !== candidate.stepId),
|
|
526
|
+
external: { aiGateway }
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const nextDisposition = disposition(outcome);
|
|
531
|
+
const deferred = executed?.status === "completed" && nextDisposition !== "fork";
|
|
532
|
+
return {
|
|
533
|
+
...base,
|
|
534
|
+
disposition: deferred ? "advanced" : nextDisposition,
|
|
535
|
+
next: deferred && nextDisposition === "waiting" ? [] : steps,
|
|
536
|
+
...executed === void 0 ? {} : { executed },
|
|
537
|
+
...deferred || output === void 0 ? {} : { output },
|
|
538
|
+
...deferred || error === void 0 ? {} : { error }
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
//#endregion
|
|
482
542
|
//#region src/stacks/tanstack/steps.ts
|
|
483
543
|
function json(status, body) {
|
|
484
544
|
return new Response(JSON.stringify(body), {
|
|
@@ -515,7 +575,7 @@ function parseBody(value) {
|
|
|
515
575
|
if (new Set(body.memo.map((entry) => entry.stepId)).size !== body.memo.length) return "memo entries must be unique per stepId";
|
|
516
576
|
}
|
|
517
577
|
if (body.action !== void 0 && body.action !== "advance" && body.action !== "execute") return "action must be \"advance\" or \"execute\"";
|
|
518
|
-
if (body.action === "execute" && !isStepReference(body.step)) return "step must be a { kind: \"step\", stepId } reference when action is \"execute\"";
|
|
578
|
+
if (body.action === "execute" && !isStepReference(body.step)) return "step must be a { kind: \"step\" | \"llm\", stepId } reference when action is \"execute\"";
|
|
519
579
|
if (body.action !== "execute" && body.step !== void 0) return "step is only valid when action is \"execute\"";
|
|
520
580
|
if (body.memo !== void 0 && body.memo.length > 0 && !("input" in value)) return "input must be sent with every call, including a resume";
|
|
521
581
|
return body;
|
|
@@ -527,34 +587,7 @@ async function readBody(request) {
|
|
|
527
587
|
}
|
|
528
588
|
function isStepReference(value) {
|
|
529
589
|
const step = value;
|
|
530
|
-
return typeof step === "object" && step !== null && step.kind === "step" && typeof step.stepId === "string";
|
|
531
|
-
}
|
|
532
|
-
function disposition(outcome) {
|
|
533
|
-
if (outcome.status === "completed") return "completed";
|
|
534
|
-
if (outcome.status === "failed") return "failed";
|
|
535
|
-
if (!outcome.steps.some((step) => step.kind === "step")) return "waiting";
|
|
536
|
-
return outcome.steps.length > 1 ? "fork" : "advanced";
|
|
537
|
-
}
|
|
538
|
-
function memoDelta(before, after) {
|
|
539
|
-
const existing = new Set(before.map((entry) => entry.stepId));
|
|
540
|
-
return after.filter((entry) => !existing.has(entry.stepId));
|
|
541
|
-
}
|
|
542
|
-
function respond(runId, inputHash, workflowVersion, before, outcome, executed) {
|
|
543
|
-
const { steps, emitted, output, error } = outcome;
|
|
544
|
-
const nextDisposition = disposition(outcome);
|
|
545
|
-
const deferred = executed?.status === "completed" && nextDisposition !== "fork";
|
|
546
|
-
return json(200, {
|
|
547
|
-
runId,
|
|
548
|
-
inputHash,
|
|
549
|
-
workflowVersion,
|
|
550
|
-
disposition: deferred ? "advanced" : nextDisposition,
|
|
551
|
-
memoDelta: memoDelta(before, outcome.memo),
|
|
552
|
-
next: deferred && nextDisposition === "waiting" ? [] : steps,
|
|
553
|
-
...executed === void 0 ? {} : { executed },
|
|
554
|
-
...emitted.length > 0 ? { emitted } : {},
|
|
555
|
-
...deferred || output === void 0 ? {} : { output },
|
|
556
|
-
...deferred || error === void 0 ? {} : { error }
|
|
557
|
-
});
|
|
590
|
+
return typeof step === "object" && step !== null && (step.kind === "step" || step.kind === "llm") && typeof step.stepId === "string";
|
|
558
591
|
}
|
|
559
592
|
function prepare(collection, options) {
|
|
560
593
|
return {
|
|
@@ -685,14 +718,15 @@ function createStepsHandler(collection, options = {}) {
|
|
|
685
718
|
input,
|
|
686
719
|
memo: before,
|
|
687
720
|
runId,
|
|
688
|
-
shouldExecute: (intent) => intent.kind !== "step" || intent.stepId === selected.stepId
|
|
721
|
+
shouldExecute: (intent) => intent.kind !== "step" || selected.kind === "step" && intent.stepId === selected.stepId
|
|
689
722
|
}));
|
|
690
723
|
const executed = outcome.results.find((result) => result.kind === "step" && result.stepId === selected.stepId);
|
|
691
|
-
|
|
724
|
+
const pendingLlm = selected.kind === "llm" && outcome.steps.some((intent) => intent.kind === "llm" && intent.stepId === selected.stepId);
|
|
725
|
+
if (executed === void 0 && !pendingLlm && outcome.status !== "failed") return json(409, {
|
|
692
726
|
error: "stale_step",
|
|
693
727
|
message: `step "${selected.stepId}" is not executable from this memo`
|
|
694
728
|
});
|
|
695
|
-
return
|
|
729
|
+
return json(200, stepsResponse(runId, inputHash, workflow.version, before, outcome, executed, selected));
|
|
696
730
|
}
|
|
697
731
|
const described = await validateOutput(workflow, await replay({
|
|
698
732
|
workflow,
|
|
@@ -702,7 +736,7 @@ function createStepsHandler(collection, options = {}) {
|
|
|
702
736
|
shouldExecute: (intent) => intent.kind !== "step"
|
|
703
737
|
}));
|
|
704
738
|
const only = described.steps.length === 1 ? described.steps[0] : void 0;
|
|
705
|
-
if (described.status !== "pending" || only?.kind !== "step") return
|
|
739
|
+
if (described.status !== "pending" || only?.kind !== "step") return json(200, stepsResponse(runId, inputHash, workflow.version, before, described));
|
|
706
740
|
const outcome = await validateOutput(workflow, await replay({
|
|
707
741
|
workflow,
|
|
708
742
|
input,
|
|
@@ -715,7 +749,7 @@ function createStepsHandler(collection, options = {}) {
|
|
|
715
749
|
error: "stale_step",
|
|
716
750
|
message: `step "${only.stepId}" is not executable from this memo`
|
|
717
751
|
});
|
|
718
|
-
return
|
|
752
|
+
return json(200, stepsResponse(runId, inputHash, workflow.version, before, outcome, executed));
|
|
719
753
|
};
|
|
720
754
|
}
|
|
721
755
|
//#endregion
|
|
@@ -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-yRbzJp-c.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-yRbzJp-c.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-yRbzJp-c.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-BjN4ePEF.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";
|