@lovable.dev/workflows-sdk 0.0.0-dev.40 → 0.0.0-dev.42

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,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
2
2
  //#region src/manifests/branch-metadata.ts
3
3
  const optionsArgument = {
4
4
  step: 2,
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
2
2
  //#region src/manifests/context-escapes.ts
3
3
  const durableMethods = /* @__PURE__ */ new Set([
4
4
  "step",
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
2
2
  //#region src/manifests/duplicate-ids.ts
3
3
  /** Where an explicit `{ id }` would sit for each operation. */
4
4
  const optionsArgument = {
@@ -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.40";
6629
+ var version = "0.0.0-dev.42";
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-oG4uFJ0o.js");
6828
- const { findBranchMetadataIssues } = await import("./branch-metadata-7KoYCvVR.js");
6829
- const { findWorkflowContextEscapes } = await import("./context-escapes-5F9gQw59.js");
6830
- const { findDuplicateOperationIds } = await import("./duplicate-ids-CJTxhI0b.js");
6827
+ const { extractWorkflowGraph } = await import("./graph-3gOUq6Fj.js");
6828
+ const { findBranchMetadataIssues } = await import("./branch-metadata-B_AYFR_q.js");
6829
+ const { findWorkflowContextEscapes } = await import("./context-escapes-BDFqA3Vj.js");
6830
+ const { findDuplicateOperationIds } = await import("./duplicate-ids-DKz9hLiV.js");
6831
6831
  const { DURABLE_ID_REQUIRED } = await import("./durable-ids-Cx341nJQ.js").then((n) => n.n);
6832
- const { findNestedDurableOperations } = await import("./nested-operations-CiJJpl5w.js");
6833
- const { findOperationDescriptionIssues } = await import("./operation-descriptions-CARt7Myx.js");
6834
- const { findStepMetadataIssues } = await import("./step-metadata-CdZSDCpP.js");
6835
- const { findWaitDeadlineIssues } = await import("./wait-deadlines-DTUJbmVC.js");
6832
+ const { findNestedDurableOperations } = await import("./nested-operations-Brojvxz6.js");
6833
+ const { findOperationDescriptionIssues } = await import("./operation-descriptions-t_polWSM.js");
6834
+ const { findStepMetadataIssues } = await import("./step-metadata-CsJWX9X4.js");
6835
+ const { findWaitDeadlineIssues } = await import("./wait-deadlines-BVlkmfZO.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,4 @@
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-Bv_Ep6yM.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-BFIKNu5F.js";
2
2
  //#region src/manifests/handler-source.ts
3
3
  const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
4
4
  function workflowHandlerSource(handler) {
package/dist/index.d.ts CHANGED
@@ -876,25 +876,29 @@ interface MemoEntry {
876
876
  interface StepIntentBase {
877
877
  seq: number;
878
878
  stepId: string;
879
- /** Kind-specific detail: sleep `ms`, `waitForEvent` name, approval title. */
880
- config?: Record<string, unknown>;
881
879
  meta?: WorkflowMetadata;
882
880
  }
883
881
  /** A durable operation the replay reached but could not answer. */
884
882
  type StepIntent = StepIntentBase & {
885
- kind: Exclude<StepKind, "llm">;
886
883
  disposition?: never;
887
884
  external?: never;
888
- };
885
+ } & ({
886
+ kind: Exclude<StepKind, "llm">;
887
+ /** Kind-specific detail: sleep `ms`, `waitForEvent` name, approval title. */
888
+ config?: Record<string, unknown>;
889
+ } | {
890
+ kind: "llm";
891
+ config?: never;
892
+ });
889
893
  type ExternalOperation = Required<WorkflowExternalOperationV1Json> & {
890
894
  aiGateway: LlmRequest;
891
895
  };
892
- type ExternalStep = Pick<StepIntentBase, "seq" | "stepId" | "meta"> & {
896
+ type ExternalStep = StepIntentBase & {
893
897
  kind: "llm";
894
898
  disposition: "external";
895
899
  external: ExternalOperation;
896
900
  };
897
- type NextStep = StepIntent | ExternalStep;
901
+ type NextStep = StepIntent;
898
902
  interface StepResult<K extends StepKind = StepKind> {
899
903
  seq: number;
900
904
  stepId: string;
@@ -922,7 +926,7 @@ interface ReplayOutcome {
922
926
  error?: string;
923
927
  }
924
928
  interface StepReference {
925
- kind: "step";
929
+ kind: "step" | "llm";
926
930
  stepId: string;
927
931
  }
928
932
  //#endregion
@@ -960,9 +964,7 @@ interface StepsResponseBase {
960
964
  workflowVersion: string;
961
965
  runId: string;
962
966
  inputHash: string;
963
- memoDelta: MemoEntry[];
964
967
  next: NextStep[];
965
- executed?: StepResult<"step">;
966
968
  emitted?: {
967
969
  name: string;
968
970
  value: Record<string, unknown>;
@@ -972,8 +974,13 @@ interface StepsResponseBase {
972
974
  }
973
975
  type StepsResponse = StepsResponseBase & ({
974
976
  disposition: Exclude<StepsDisposition, "external">;
977
+ memoDelta: MemoEntry[];
978
+ executed?: StepResult<"step">;
975
979
  external?: never;
976
- } | ExternalStep);
980
+ } | (ExternalStep & {
981
+ memoDelta: [];
982
+ executed?: never;
983
+ }));
977
984
  declare function createStepsHandler(collection: WorkflowCollection, options?: StepsHandlerOptions): StepsHandler;
978
985
  //#endregion
979
986
  //#region src/stacks/tanstack/sse.d.ts
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
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-Bv_Ep6yM.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-BFIKNu5F.js";
3
3
  import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
4
4
  //#region src/stacks/tanstack/sse.ts
5
5
  const HEADERS = {
@@ -124,6 +124,78 @@ async function hashInput(input) {
124
124
  return [...new Uint8Array(digest)].slice(0, 16).map((byte) => byte.toString(16).padStart(2, "0")).join("");
125
125
  }
126
126
  //#endregion
127
+ //#region src/runtime/operations.ts
128
+ var ReplayOperations = class {
129
+ memo;
130
+ settled;
131
+ pending = [];
132
+ requests = /* @__PURE__ */ new Map();
133
+ consumed = /* @__PURE__ */ new Set();
134
+ never = new Promise(() => {});
135
+ error;
136
+ seq = 0;
137
+ constructor(memo, settled) {
138
+ this.memo = memo;
139
+ this.settled = settled;
140
+ }
141
+ reach(kind, stepId, meta) {
142
+ if (!stepId) {
143
+ this.error = `ctx.${kind}() was called without an id; ${DURABLE_ID_REQUIRED}`;
144
+ return;
145
+ }
146
+ const seq = this.seq++;
147
+ if (this.consumed.has(stepId)) {
148
+ this.error = `id "${stepId}" was reached more than once; every durable operation id must be unique within a workflow`;
149
+ return;
150
+ }
151
+ this.consumed.add(stepId);
152
+ const answered = this.memo.get(stepId) ?? this.settled.get(stepId);
153
+ if (!answered) return { seq };
154
+ if (answered.kind !== kind) {
155
+ this.error = `memo has ${answered.kind} "${stepId}", replay produced ${kind}`;
156
+ return;
157
+ }
158
+ const recordedGroupId = groupId(answered.meta);
159
+ if (recordedGroupId !== void 0 && recordedGroupId !== groupId(meta)) {
160
+ this.error = `memo has group "${recordedGroupId}" for step "${stepId}", replay produced a different group`;
161
+ return;
162
+ }
163
+ if (answered.status === "completed") {
164
+ if (kind === "llm" && typeof answered.result !== "string") {
165
+ this.error = `memo has a non-string result for llm "${stepId}"`;
166
+ return;
167
+ }
168
+ return {
169
+ seq,
170
+ answer: Promise.resolve(answered.result)
171
+ };
172
+ }
173
+ return {
174
+ seq,
175
+ answer: Promise.reject(new Error(answered.error ?? `step "${stepId}" failed`))
176
+ };
177
+ }
178
+ llm = (request, options) => {
179
+ const operation = this.reach("llm", options.id, options.meta);
180
+ if (!operation) return this.never;
181
+ if (operation.answer) return operation.answer;
182
+ this.pending.push({
183
+ seq: operation.seq,
184
+ stepId: options.id,
185
+ kind: "llm",
186
+ meta: options.meta
187
+ });
188
+ this.requests.set(options.id, request);
189
+ return this.never;
190
+ };
191
+ };
192
+ function groupId(meta) {
193
+ const group = meta?.group;
194
+ if (group === null || typeof group !== "object") return void 0;
195
+ const id = group.id;
196
+ return typeof id === "string" ? id : void 0;
197
+ }
198
+ //#endregion
127
199
  //#region src/runtime/replay.ts
128
200
  /** How long a pass waits for handler work that is not a durable operation. */
129
201
  const DEFAULT_SETTLE_MS = 5e3;
@@ -135,12 +207,6 @@ const EXECUTABLE = /* @__PURE__ */ new Set([
135
207
  function describe(error) {
136
208
  return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
137
209
  }
138
- function groupId(meta) {
139
- const group = meta?.group;
140
- if (group === null || typeof group !== "object") return void 0;
141
- const id = group.id;
142
- return typeof id === "string" ? id : void 0;
143
- }
144
210
  function runtimeContext() {
145
211
  return {
146
212
  timeRemaining: () => Number.POSITIVE_INFINITY,
@@ -168,19 +234,15 @@ async function replay(options) {
168
234
  const { workflow, input, runId } = options;
169
235
  const byKey = new Map(options.memo.map((entry) => [entry.stepId, entry]));
170
236
  const allow = options.shouldExecute ?? (() => true);
171
- const never = new Promise(() => {});
172
- const pending = [];
173
237
  const settled = /* @__PURE__ */ new Map();
238
+ const operations = new ReplayOperations(byKey, settled);
239
+ const { pending, consumed, never } = operations;
174
240
  const pass = { stepsSettled: 0 };
175
- const reached = /* @__PURE__ */ new Set();
176
- const consumed = /* @__PURE__ */ new Set();
177
241
  let lastProgress = Date.now();
178
242
  let currentParent;
179
243
  const results = [];
180
244
  const emitted = [];
181
245
  const inflight = [];
182
- let seq = 0;
183
- let nonDeterminism;
184
246
  function record(entry) {
185
247
  settled.set(entry.stepId, entry);
186
248
  lastProgress = Date.now();
@@ -198,31 +260,10 @@ async function replay(options) {
198
260
  options.onStepSettle?.(result);
199
261
  }
200
262
  function durable(kind, stepId, run, config, meta) {
201
- if (!stepId) {
202
- nonDeterminism = `ctx.${kind}() was called without an id; ${DURABLE_ID_REQUIRED}`;
203
- return never;
204
- }
205
- const index = seq++;
206
- if (reached.has(stepId)) {
207
- nonDeterminism = `id "${stepId}" was reached more than once; every durable operation id must be unique within a workflow`;
208
- return never;
209
- }
210
- reached.add(stepId);
211
- consumed.add(stepId);
212
- const answered = byKey.get(stepId) ?? settled.get(stepId);
213
- if (answered) {
214
- if (answered.kind !== kind) {
215
- nonDeterminism = `memo has ${answered.kind} "${stepId}", replay produced ${kind}`;
216
- return never;
217
- }
218
- const recordedGroupId = groupId(answered.meta);
219
- if (recordedGroupId !== void 0 && recordedGroupId !== groupId(meta)) {
220
- nonDeterminism = `memo has group "${recordedGroupId}" for step "${stepId}", replay produced a different group`;
221
- return never;
222
- }
223
- if (answered.status === "completed") return Promise.resolve(answered.result);
224
- return Promise.reject(new Error(answered.error ?? `step "${stepId}" failed`));
225
- }
263
+ const operation = operations.reach(kind, stepId, meta);
264
+ if (!operation || !stepId) return never;
265
+ if (operation.answer) return operation.answer;
266
+ const index = operation.seq;
226
267
  const parent = currentParent;
227
268
  const intent = {
228
269
  seq: index,
@@ -319,7 +360,7 @@ async function replay(options) {
319
360
  const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
320
361
  for (;;) {
321
362
  for (let tick = 0; tick < 20; tick++) await new Promise((resolve) => setTimeout(resolve, 0));
322
- if (outcome || nonDeterminism) break;
363
+ if (outcome || operations.error) break;
323
364
  if (inflight.length > 0) {
324
365
  await Promise.all(inflight.splice(0));
325
366
  lastProgress = Date.now();
@@ -349,11 +390,11 @@ async function replay(options) {
349
390
  results,
350
391
  emitted
351
392
  };
352
- if (nonDeterminism) return {
393
+ if (operations.error) return {
353
394
  ...base,
354
395
  status: "failed",
355
396
  steps: [],
356
- error: `non-deterministic replay: ${nonDeterminism}`
397
+ error: `non-deterministic replay: ${operations.error}`
357
398
  };
358
399
  if (orphan !== void 0) return {
359
400
  ...base,
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
2
2
  //#region src/manifests/nested-operations.ts
3
3
  const durableMethods = [
4
4
  "step",
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
2
2
  //#region src/manifests/operation-descriptions.ts
3
3
  const optionsArgument = {
4
4
  approve: 0,
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.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-Bv_Ep6yM.js";
1
+ import { t as generateManifests } from "./generate-BFIKNu5F.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-oG4uFJ0o.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.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.40",
3
+ "version": "0.0.0-dev.42",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",