@lovable.dev/workflows-sdk 0.0.0-dev.44 → 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.
@@ -1,7 +1,8 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.js";
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-3Syx7KCj.js";
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-3Syx7KCj.js";
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.44";
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-3Syx7KCj.js");
6828
- const { findBranchMetadataIssues } = await import("./branch-metadata-strJDEAy.js");
6829
- const { findWorkflowContextEscapes } = await import("./context-escapes-CNTx3xkk.js");
6830
- const { findDuplicateOperationIds } = await import("./duplicate-ids-Cq6Y0pgf.js");
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-BsAo5V1I.js");
6833
- const { findOperationDescriptionIssues } = await import("./operation-descriptions-Dh0T3SnD.js");
6834
- const { findStepMetadataIssues } = await import("./step-metadata-FnRBeBRd.js");
6835
- const { findWaitDeadlineIssues } = await import("./wait-deadlines-CPg8h2v1.js");
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-CqXgNBpN.js";
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 = readableOptions(call.arguments[1]);
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) return unknown("ctx.llm needs a static { id }", parents);
306
- const description = operationDescription(options);
307
- if (description === void 0) return unknown("LLM descriptions must be static strings", parents);
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
- const executionPolicy = stepExecutionPolicy(options);
310
- if (executionPolicy) executionPolicy.timeoutMs = Math.min(executionPolicy.timeoutMs ?? 12e4, 6e5);
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
- ...executionPolicy === void 0 ? {} : { executionPolicy },
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
- expression(fn.body, tails, true);
650
- return graph;
651
- }
652
- statements(fn.body.statements, tails, 0);
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.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-CqXgNBpN.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-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,
@@ -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-3Syx7KCj.js";
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-3Syx7KCj.js";
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-3Syx7KCj.js";
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-CqXgNBpN.js";
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";
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-yRbzJp-c.js";
2
2
  //#region src/manifests/wait-deadlines.ts
3
3
  const optionsArgument = {
4
4
  approve: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/workflows-sdk",
3
- "version": "0.0.0-dev.44",
3
+ "version": "0.0.0-dev.45",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",