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

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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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.42";
6629
+ var version = "0.0.0-dev.44";
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-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");
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");
6831
6831
  const { DURABLE_ID_REQUIRED } = await import("./durable-ids-Cx341nJQ.js").then((n) => n.n);
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");
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");
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-BFIKNu5F.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-CqXgNBpN.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
@@ -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,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-BFIKNu5F.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";
3
3
  import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
4
4
  //#region src/stacks/tanstack/sse.ts
5
5
  const HEADERS = {
@@ -417,7 +417,8 @@ async function replay(options) {
417
417
  if (pending.length > 0) return {
418
418
  ...base,
419
419
  status: "pending",
420
- steps: pending
420
+ steps: pending,
421
+ llmRequests: operations.requests
421
422
  };
422
423
  return {
423
424
  ...base,
@@ -479,6 +480,62 @@ async function authorizeProjectRequest(request, getProjectSecret) {
479
480
  }
480
481
  }
481
482
  //#endregion
483
+ //#region src/stacks/tanstack/steps-response.ts
484
+ function disposition(outcome) {
485
+ if (outcome.status === "completed") return "completed";
486
+ if (outcome.status === "failed") return "failed";
487
+ if (!outcome.steps.some((step) => step.kind === "step" || step.kind === "llm")) return "waiting";
488
+ return outcome.steps.length > 1 ? "fork" : "advanced";
489
+ }
490
+ function memoDelta(before, after) {
491
+ const existing = new Set(before.map((entry) => entry.stepId));
492
+ return after.filter((entry) => !existing.has(entry.stepId));
493
+ }
494
+ function isExternalMemoEntry(entry) {
495
+ 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);
496
+ }
497
+ function stepsResponse(runId, inputHash, workflowVersion, before, outcome, executed, selected) {
498
+ const { steps, emitted, output, error } = outcome;
499
+ const delta = memoDelta(before, outcome.memo);
500
+ const base = {
501
+ runId,
502
+ inputHash,
503
+ workflowVersion,
504
+ memoDelta: delta,
505
+ next: steps,
506
+ ...emitted.length > 0 ? { emitted } : {}
507
+ };
508
+ if (outcome.status === "pending" && executed === void 0) {
509
+ const candidate = selected ? steps.find((step) => selected.kind === "llm" && step.kind === "llm" && step.stepId === selected.stepId) : steps.length === 1 ? steps[0] : void 0;
510
+ if (candidate?.kind === "llm") {
511
+ const aiGateway = outcome.llmRequests?.get(candidate.stepId);
512
+ if (!aiGateway || !delta.every(isExternalMemoEntry)) return {
513
+ ...base,
514
+ disposition: "failed",
515
+ error: "external LLM work requires a prepared request and only completed now/uuid memo entries"
516
+ };
517
+ return {
518
+ ...base,
519
+ ...candidate,
520
+ disposition: "external",
521
+ memoDelta: delta,
522
+ next: steps.filter((step) => step.stepId !== candidate.stepId),
523
+ external: { aiGateway }
524
+ };
525
+ }
526
+ }
527
+ const nextDisposition = disposition(outcome);
528
+ const deferred = executed?.status === "completed" && nextDisposition !== "fork";
529
+ return {
530
+ ...base,
531
+ disposition: deferred ? "advanced" : nextDisposition,
532
+ next: deferred && nextDisposition === "waiting" ? [] : steps,
533
+ ...executed === void 0 ? {} : { executed },
534
+ ...deferred || output === void 0 ? {} : { output },
535
+ ...deferred || error === void 0 ? {} : { error }
536
+ };
537
+ }
538
+ //#endregion
482
539
  //#region src/stacks/tanstack/steps.ts
483
540
  function json(status, body) {
484
541
  return new Response(JSON.stringify(body), {
@@ -515,7 +572,7 @@ function parseBody(value) {
515
572
  if (new Set(body.memo.map((entry) => entry.stepId)).size !== body.memo.length) return "memo entries must be unique per stepId";
516
573
  }
517
574
  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\"";
575
+ if (body.action === "execute" && !isStepReference(body.step)) return "step must be a { kind: \"step\" | \"llm\", stepId } reference when action is \"execute\"";
519
576
  if (body.action !== "execute" && body.step !== void 0) return "step is only valid when action is \"execute\"";
520
577
  if (body.memo !== void 0 && body.memo.length > 0 && !("input" in value)) return "input must be sent with every call, including a resume";
521
578
  return body;
@@ -527,32 +584,7 @@ async function readBody(request) {
527
584
  }
528
585
  function isStepReference(value) {
529
586
  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
- return json(200, {
545
- runId,
546
- inputHash,
547
- workflowVersion,
548
- disposition: disposition(outcome),
549
- memoDelta: memoDelta(before, outcome.memo),
550
- next: steps,
551
- ...executed === void 0 ? {} : { executed },
552
- ...emitted.length > 0 ? { emitted } : {},
553
- ...output === void 0 ? {} : { output },
554
- ...error === void 0 ? {} : { error }
555
- });
587
+ return typeof step === "object" && step !== null && (step.kind === "step" || step.kind === "llm") && typeof step.stepId === "string";
556
588
  }
557
589
  function prepare(collection, options) {
558
590
  return {
@@ -586,7 +618,7 @@ async function validateInput(workflow, input) {
586
618
  return { input: result.value };
587
619
  }
588
620
  async function validateOutput(workflow, outcome) {
589
- if (outcome.status !== "completed" || !workflow.outputSchema) return outcome;
621
+ if (outcome.status !== "completed" || !workflow.outputSchema || outcome.results.some((result) => result.kind === "step" && result.status === "completed")) return outcome;
590
622
  let result;
591
623
  try {
592
624
  result = await validateSchema(workflow.outputSchema, outcome.output);
@@ -683,14 +715,15 @@ function createStepsHandler(collection, options = {}) {
683
715
  input,
684
716
  memo: before,
685
717
  runId,
686
- shouldExecute: (intent) => intent.kind !== "step" || intent.stepId === selected.stepId
718
+ shouldExecute: (intent) => intent.kind !== "step" || selected.kind === "step" && intent.stepId === selected.stepId
687
719
  }));
688
720
  const executed = outcome.results.find((result) => result.kind === "step" && result.stepId === selected.stepId);
689
- if (executed === void 0 && outcome.status !== "failed") return json(409, {
721
+ const pendingLlm = selected.kind === "llm" && outcome.steps.some((intent) => intent.kind === "llm" && intent.stepId === selected.stepId);
722
+ if (executed === void 0 && !pendingLlm && outcome.status !== "failed") return json(409, {
690
723
  error: "stale_step",
691
724
  message: `step "${selected.stepId}" is not executable from this memo`
692
725
  });
693
- return respond(runId, inputHash, workflow.version, before, outcome, executed);
726
+ return json(200, stepsResponse(runId, inputHash, workflow.version, before, outcome, executed, selected));
694
727
  }
695
728
  const described = await validateOutput(workflow, await replay({
696
729
  workflow,
@@ -700,7 +733,7 @@ function createStepsHandler(collection, options = {}) {
700
733
  shouldExecute: (intent) => intent.kind !== "step"
701
734
  }));
702
735
  const only = described.steps.length === 1 ? described.steps[0] : void 0;
703
- if (described.status !== "pending" || only?.kind !== "step") return respond(runId, inputHash, workflow.version, before, described);
736
+ if (described.status !== "pending" || only?.kind !== "step") return json(200, stepsResponse(runId, inputHash, workflow.version, before, described));
704
737
  const outcome = await validateOutput(workflow, await replay({
705
738
  workflow,
706
739
  input,
@@ -713,7 +746,7 @@ function createStepsHandler(collection, options = {}) {
713
746
  error: "stale_step",
714
747
  message: `step "${only.stepId}" is not executable from this memo`
715
748
  });
716
- return respond(runId, inputHash, workflow.version, before, outcome, executed);
749
+ return json(200, stepsResponse(runId, inputHash, workflow.version, before, outcome, executed));
717
750
  };
718
751
  }
719
752
  //#endregion
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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-BFIKNu5F.js";
1
+ import { t as generateManifests } from "./generate-CqXgNBpN.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-3gOUq6Fj.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-3Syx7KCj.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.42",
3
+ "version": "0.0.0-dev.44",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",