@lovable.dev/workflows-sdk 0.0.0-dev.55 → 0.0.0-dev.57

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as DURABLE_ID_REQUIRED } from "./durable-ids-Cx341nJQ.js";
2
- import { A as daily, D as registerWorkflows, E as createWorkflow, M as weekly, O as workflowVersions, T as createMiddleware, j as hourly, k as defineSchedule, t as generateManifests } from "./generate-DOuPyG-r.js";
2
+ import { A as daily, D as registerWorkflows, E as createWorkflow, M as hourly, N as weekly, O as workflowVersions, P as WORKFLOW_ID_PATTERN, T as createMiddleware, j as every, k as defineSchedule, t as generateManifests } from "./generate-CzKPbFyR.js";
3
3
  import { n as assertLlmOptions, r as assertLlmRequest } from "./llm-validation-DdDO6csU.js";
4
4
  import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
5
5
  import { generateChatCompletion, generateMessage } from "@lovable.dev/ai-gateway";
@@ -524,23 +524,31 @@ async function replay(options) {
524
524
  }
525
525
  function noop() {}
526
526
  //#endregion
527
- //#region src/stacks/tanstack/project-auth.ts
528
- const PROJECT_SECRET_ENV_VAR = "LOVABLE_WORKFLOWS_KEY";
527
+ //#region src/core/runtime-env.ts
529
528
  let cloudflareEnvPromise;
530
- function readProcessSecret() {
531
- const value = (globalThis.process?.env)?.[PROJECT_SECRET_ENV_VAR];
532
- return typeof value === "string" && value ? value : void 0;
533
- }
534
- async function readCloudflareSecret() {
529
+ function readCloudflareEnv() {
535
530
  cloudflareEnvPromise ??= import(
536
531
  /* @vite-ignore */
537
532
  "cloudflare:workers"
538
533
  ).then((module) => module.env).catch(() => void 0);
539
- const value = (await cloudflareEnvPromise)?.[PROJECT_SECRET_ENV_VAR];
540
- return typeof value === "string" && value ? value : void 0;
534
+ return cloudflareEnvPromise;
541
535
  }
542
- async function resolveProjectSecret() {
543
- return readProcessSecret() ?? await readCloudflareSecret();
536
+ /**
537
+ * Returns a server environment variable from `process.env`, or else from the `cloudflare:workers` env.
538
+ *
539
+ * Call it inside a request: on Workers, `process.env` can be empty at module scope. An empty value counts as unset.
540
+ */
541
+ async function readRuntimeEnv(name) {
542
+ const value = (globalThis.process?.env)?.[name];
543
+ if (typeof value === "string" && value) return value;
544
+ const cloudflareValue = (await readCloudflareEnv())?.[name];
545
+ return typeof cloudflareValue === "string" && cloudflareValue ? cloudflareValue : void 0;
546
+ }
547
+ //#endregion
548
+ //#region src/stacks/tanstack/project-auth.ts
549
+ const PROJECT_SECRET_ENV_VAR = "LOVABLE_WORKFLOWS_KEY";
550
+ function resolveProjectSecret() {
551
+ return readRuntimeEnv(PROJECT_SECRET_ENV_VAR);
544
552
  }
545
553
  function bearerToken(request) {
546
554
  const header = request.headers.get("authorization");
@@ -824,4 +832,442 @@ function createStepsHandler(collection, options = {}) {
824
832
  };
825
833
  }
826
834
  //#endregion
827
- export { createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, generateManifests, hourly, registerWorkflows, toServerSentEventsResponse, weekly };
835
+ //#region src/client/errors.ts
836
+ /**
837
+ * A failed `startRun`, `getRun` or `deliverEvent` call.
838
+ *
839
+ * `status` is the gateway's HTTP status, and is undefined when the SDK refused the call before sending it or got no
840
+ * response. `retryable` is true when repeating the same call later can succeed without a change to the code, the
841
+ * configuration or the app; the SDK itself never retries.
842
+ */
843
+ var WorkflowsApiError = class extends Error {
844
+ name = "WorkflowsApiError";
845
+ type;
846
+ status;
847
+ requestId;
848
+ title;
849
+ detail;
850
+ errors;
851
+ retryable;
852
+ retryAfterMs;
853
+ constructor(message, fields) {
854
+ super(message, fields.cause === void 0 ? void 0 : { cause: fields.cause });
855
+ this.type = fields.type;
856
+ this.status = fields.status;
857
+ this.requestId = fields.requestId;
858
+ this.title = fields.title;
859
+ this.detail = fields.detail;
860
+ this.errors = fields.errors;
861
+ this.retryable = fields.retryable;
862
+ this.retryAfterMs = fields.retryAfterMs;
863
+ }
864
+ toJSON() {
865
+ return {
866
+ name: this.name,
867
+ message: this.message,
868
+ type: this.type,
869
+ status: this.status,
870
+ requestId: this.requestId,
871
+ title: this.title,
872
+ detail: this.detail,
873
+ errors: this.errors,
874
+ retryable: this.retryable,
875
+ retryAfterMs: this.retryAfterMs
876
+ };
877
+ }
878
+ };
879
+ var WorkflowsConfigurationError = class extends WorkflowsApiError {
880
+ name = "WorkflowsConfigurationError";
881
+ reason;
882
+ constructor(reason, message) {
883
+ super(message, {
884
+ type: "configuration_error",
885
+ retryable: false
886
+ });
887
+ this.reason = reason;
888
+ }
889
+ };
890
+ var WorkflowsRequestInvalidError = class extends WorkflowsApiError {
891
+ name = "WorkflowsRequestInvalidError";
892
+ };
893
+ /** The input fails the workflow's input schema. The SDK sent no request, so the Idempotency-Key is still unused. */
894
+ var RunInputInvalidError = class extends WorkflowsRequestInvalidError {
895
+ name = "RunInputInvalidError";
896
+ issues;
897
+ constructor(message, fields) {
898
+ super(message, fields);
899
+ this.issues = fields.issues;
900
+ }
901
+ };
902
+ var WorkflowsNetworkError = class extends WorkflowsApiError {
903
+ name = "WorkflowsNetworkError";
904
+ };
905
+ var WorkflowsAuthenticationError = class extends WorkflowsApiError {
906
+ name = "WorkflowsAuthenticationError";
907
+ };
908
+ var WorkflowsKeyLookupError = class extends WorkflowsApiError {
909
+ name = "WorkflowsKeyLookupError";
910
+ };
911
+ var WorkflowsDevelopmentKeyError = class extends WorkflowsApiError {
912
+ name = "WorkflowsDevelopmentKeyError";
913
+ };
914
+ var WorkflowsDisabledError = class extends WorkflowsApiError {
915
+ name = "WorkflowsDisabledError";
916
+ };
917
+ var RunNotFoundError = class extends WorkflowsApiError {
918
+ name = "RunNotFoundError";
919
+ };
920
+ var WorkflowNotPublishedError = class extends WorkflowsApiError {
921
+ name = "WorkflowNotPublishedError";
922
+ };
923
+ var IdempotencyKeyReusedError = class extends WorkflowsApiError {
924
+ name = "IdempotencyKeyReusedError";
925
+ };
926
+ var RunClosedError = class extends WorkflowsApiError {
927
+ name = "RunClosedError";
928
+ };
929
+ var RunNotWaitingError = class extends WorkflowsApiError {
930
+ name = "RunNotWaitingError";
931
+ };
932
+ var EventAlreadyDeliveredError = class extends WorkflowsApiError {
933
+ name = "EventAlreadyDeliveredError";
934
+ };
935
+ var WorkflowsPayloadTooLargeError = class extends WorkflowsApiError {
936
+ name = "WorkflowsPayloadTooLargeError";
937
+ };
938
+ var WorkflowsRateLimitedError = class extends WorkflowsApiError {
939
+ name = "WorkflowsRateLimitedError";
940
+ };
941
+ var WorkflowsUnavailableError = class extends WorkflowsApiError {
942
+ name = "WorkflowsUnavailableError";
943
+ };
944
+ const CLASS_BY_TYPE = /* @__PURE__ */ new Map([
945
+ ["invalid_request", WorkflowsRequestInvalidError],
946
+ ["invalid_api_key", WorkflowsAuthenticationError],
947
+ ["lovable_api_key_not_registered", WorkflowsAuthenticationError],
948
+ ["lovable_api_key_registry_lookup_failed", WorkflowsKeyLookupError],
949
+ ["lovable_api_key_development_only", WorkflowsDevelopmentKeyError],
950
+ ["app_workflows_disabled", WorkflowsDisabledError],
951
+ ["run_not_found", RunNotFoundError],
952
+ ["workflow_not_published", WorkflowNotPublishedError],
953
+ ["idempotency_key_reused", IdempotencyKeyReusedError],
954
+ ["run_closed", RunClosedError],
955
+ ["run_not_waiting", RunNotWaitingError],
956
+ ["event_already_delivered", EventAlreadyDeliveredError],
957
+ ["run_input_too_large", WorkflowsPayloadTooLargeError],
958
+ ["payload_too_large", WorkflowsPayloadTooLargeError]
959
+ ]);
960
+ const RETRYABLE_CLASSES = /* @__PURE__ */ new Set([
961
+ WorkflowsKeyLookupError,
962
+ RunNotWaitingError,
963
+ WorkflowsRateLimitedError,
964
+ WorkflowsUnavailableError
965
+ ]);
966
+ const HINT_BY_TYPE = /* @__PURE__ */ new Map([["lovable_api_key_not_registered", "Rotate the project's LOVABLE_API_KEY, then republish the app or restart its backend so the server sends the new key."], ["invalid_api_key", "Check that the server's LOVABLE_API_KEY is this project's current key."]]);
967
+ const TYPE_BY_STATUS = /* @__PURE__ */ new Map([
968
+ [400, "bad_request"],
969
+ [401, "unauthorized"],
970
+ [403, "forbidden"],
971
+ [404, "not_found"],
972
+ [405, "method_not_allowed"],
973
+ [408, "request_timeout"],
974
+ [409, "conflict"],
975
+ [413, "request_entity_too_large"],
976
+ [415, "unsupported_media_type"],
977
+ [429, "too_many_requests"],
978
+ [500, "internal_server_error"],
979
+ [502, "bad_gateway"],
980
+ [503, "service_unavailable"],
981
+ [504, "gateway_timeout"]
982
+ ]);
983
+ const DEFAULT_RETRY_AFTER_MS = 1e3;
984
+ const MAX_ERROR_BODY_BYTES = 16384;
985
+ const ERROR_BODY_TIMEOUT_MS = 1e3;
986
+ const PACKAGE_PREFIX = "@lovable.dev/workflows-sdk";
987
+ function object(value) {
988
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
989
+ }
990
+ async function readErrorBody(response) {
991
+ if (!response.body) return void 0;
992
+ const reader = response.body.getReader();
993
+ let timer;
994
+ try {
995
+ return await Promise.race([(async () => {
996
+ const decoder = new TextDecoder();
997
+ let text = "";
998
+ let bytes = 0;
999
+ while (true) {
1000
+ const { done, value } = await reader.read();
1001
+ if (done) return JSON.parse(text + decoder.decode());
1002
+ bytes += value.byteLength;
1003
+ if (bytes > MAX_ERROR_BODY_BYTES) return void 0;
1004
+ text += decoder.decode(value, { stream: true });
1005
+ }
1006
+ })(), new Promise((resolve) => {
1007
+ timer = setTimeout(() => resolve(void 0), ERROR_BODY_TIMEOUT_MS);
1008
+ })]);
1009
+ } catch {
1010
+ return;
1011
+ } finally {
1012
+ clearTimeout(timer);
1013
+ reader.cancel().catch(() => void 0);
1014
+ }
1015
+ }
1016
+ function parseRetryAfter(value) {
1017
+ if (!value || value.length > 128) return void 0;
1018
+ const trimmed = value.trim();
1019
+ if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
1020
+ const milliseconds = Number(trimmed) * 1e3;
1021
+ return Number.isFinite(milliseconds) ? milliseconds : void 0;
1022
+ }
1023
+ if (!/^[A-Za-z]/.test(trimmed)) return void 0;
1024
+ const timestamp = Date.parse(trimmed);
1025
+ return Number.isFinite(timestamp) ? Math.max(0, timestamp - Date.now()) : void 0;
1026
+ }
1027
+ /** Replaces the API key in text that reaches an error, and caps its length. */
1028
+ function redactor(apiKey) {
1029
+ return (value, maxLength = 2e3) => (apiKey ? value.replaceAll(apiKey, "[redacted]") : value).slice(0, maxLength);
1030
+ }
1031
+ function errorDetails(value, redact) {
1032
+ if (!Array.isArray(value)) return void 0;
1033
+ const details = [];
1034
+ for (const entry of value.slice(0, 50)) {
1035
+ const { location, message } = object(entry);
1036
+ if (typeof message !== "string") continue;
1037
+ details.push({
1038
+ location: typeof location === "string" ? redact(location, 200) : null,
1039
+ message: redact(message)
1040
+ });
1041
+ }
1042
+ return details;
1043
+ }
1044
+ async function errorFromResponse(call, response, apiKey) {
1045
+ const redact = redactor(apiKey);
1046
+ const text = (value, maxLength) => typeof value === "string" && value ? redact(value, maxLength) : void 0;
1047
+ const body = object(await readErrorBody(response));
1048
+ const status = response.status;
1049
+ const envelopeType = text(body.type, 200);
1050
+ const type = envelopeType ?? TYPE_BY_STATUS.get(status) ?? `http_${status}`;
1051
+ let ErrorClass = WorkflowsApiError;
1052
+ if (status === 429) ErrorClass = WorkflowsRateLimitedError;
1053
+ else if (status === 503) ErrorClass = WorkflowsUnavailableError;
1054
+ else if (envelopeType) ErrorClass = CLASS_BY_TYPE.get(envelopeType) ?? WorkflowsApiError;
1055
+ const retryable = RETRYABLE_CLASSES.has(ErrorClass) || ErrorClass === WorkflowsApiError && (status === 408 || status >= 500);
1056
+ const retryAfterMs = parseRetryAfter(response.headers.get("Retry-After")) ?? (status === 429 || status === 503 ? DEFAULT_RETRY_AFTER_MS : void 0);
1057
+ const title = text(body.title, 200);
1058
+ const detail = text(body.detail);
1059
+ const hint = HINT_BY_TYPE.get(type);
1060
+ return new ErrorClass(`${PACKAGE_PREFIX}: ${call} failed (${status} ${type}): ${detail ?? title ?? "The gateway answered without an error body."}${hint ? ` ${hint}` : ""}`, {
1061
+ type,
1062
+ status,
1063
+ requestId: text(response.headers.get("X-Request-Id"), 200) ?? text(body.request_id, 200),
1064
+ title,
1065
+ detail,
1066
+ errors: errorDetails(body.errors, redact),
1067
+ retryable,
1068
+ retryAfterMs
1069
+ });
1070
+ }
1071
+ //#endregion
1072
+ //#region src/client/transport.ts
1073
+ const DEFAULT_BASE_URL = "https://connector-gateway.lovable.dev";
1074
+ function assertServerRuntime() {
1075
+ const runtime = globalThis;
1076
+ if (typeof runtime.window !== "undefined" && typeof runtime.document !== "undefined") throw new WorkflowsConfigurationError("server_only", `${PACKAGE_PREFIX}: startRun, getRun and deliverEvent run only in server code, because they send the app's LOVABLE_API_KEY.`);
1077
+ }
1078
+ async function connect() {
1079
+ const apiKey = (await readRuntimeEnv("LOVABLE_API_KEY"))?.trim();
1080
+ if (!apiKey) throw new WorkflowsConfigurationError("missing_api_key", `${PACKAGE_PREFIX}: LOVABLE_API_KEY is missing from the server environment.`);
1081
+ const baseURL = ((await readRuntimeEnv("LOVABLE_WORKFLOWS_API_URL"))?.trim() || DEFAULT_BASE_URL).replace(/\/+$/, "");
1082
+ let url;
1083
+ try {
1084
+ url = new URL(baseURL);
1085
+ } catch {
1086
+ url = void 0;
1087
+ }
1088
+ if (!url || !["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new WorkflowsConfigurationError("invalid_url", `${PACKAGE_PREFIX}: LOVABLE_WORKFLOWS_API_URL must be an http or https URL without credentials, a query or a fragment.`);
1089
+ return {
1090
+ apiKey,
1091
+ baseURL
1092
+ };
1093
+ }
1094
+ function networkError(call, cause) {
1095
+ return new WorkflowsNetworkError(`${PACKAGE_PREFIX}: ${call} failed before the gateway answered.${call === "startRun" ? " The run may have started. Retry with the same idempotency key and input." : call === "deliverEvent" ? " The event may have been recorded. Retry with the same eventId." : ""}`, {
1096
+ type: "network_error",
1097
+ retryable: true,
1098
+ cause
1099
+ });
1100
+ }
1101
+ function invalidResponse(call, response, cause) {
1102
+ return new WorkflowsApiError(`${PACKAGE_PREFIX}: ${call} got a ${response.status} response that is not the expected JSON.`, {
1103
+ type: "invalid_response",
1104
+ status: response.status,
1105
+ requestId: response.headers.get("X-Request-Id")?.slice(0, 200) || void 0,
1106
+ retryable: true,
1107
+ cause
1108
+ });
1109
+ }
1110
+ async function send(request) {
1111
+ const connection = await connect();
1112
+ const headers = new Headers(request.headers);
1113
+ headers.set("Authorization", `Bearer ${connection.apiKey}`);
1114
+ headers.set("Accept", "application/json");
1115
+ headers.set("User-Agent", `lovable-workflows-sdk/0.0.0-dev.57`);
1116
+ if (request.body !== void 0) headers.set("Content-Type", "application/json");
1117
+ let response;
1118
+ try {
1119
+ response = await fetch(`${connection.baseURL}${request.path}`, {
1120
+ method: request.method,
1121
+ headers,
1122
+ body: request.body,
1123
+ signal: request.signal,
1124
+ redirect: "manual"
1125
+ });
1126
+ } catch (cause) {
1127
+ if (request.signal?.aborted) throw request.signal.reason;
1128
+ throw networkError(request.call, cause);
1129
+ }
1130
+ if (!response.ok) throw await errorFromResponse(request.call, response, connection.apiKey);
1131
+ let parsed;
1132
+ try {
1133
+ parsed = await response.json();
1134
+ } catch (cause) {
1135
+ if (request.signal?.aborted) throw request.signal.reason;
1136
+ if (cause instanceof SyntaxError) throw invalidResponse(request.call, response, cause);
1137
+ throw networkError(request.call, cause);
1138
+ }
1139
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw invalidResponse(request.call, response);
1140
+ return parsed;
1141
+ }
1142
+ //#endregion
1143
+ //#region src/client/runs.ts
1144
+ const IDEMPOTENCY_KEY_PATTERN = /^[\x20-\x7E]{1,64}$/;
1145
+ const MAX_RUN_ID_LENGTH = 64;
1146
+ function invalidRequest(call, location, message, cause) {
1147
+ return new WorkflowsRequestInvalidError(`${PACKAGE_PREFIX}: ${call}: ${message}`, {
1148
+ type: "invalid_request",
1149
+ retryable: false,
1150
+ errors: [{
1151
+ location,
1152
+ message
1153
+ }],
1154
+ cause
1155
+ });
1156
+ }
1157
+ function serialize(call, body, location) {
1158
+ try {
1159
+ return JSON.stringify(body);
1160
+ } catch (cause) {
1161
+ throw invalidRequest(call, location, "the value is not JSON-serializable", cause);
1162
+ }
1163
+ }
1164
+ function checkRunId(call, runId) {
1165
+ if (typeof runId !== "string" || runId === "" || runId.length > MAX_RUN_ID_LENGTH) throw invalidRequest(call, "path.run_id", "runId must be a non-empty string of at most 64 characters");
1166
+ }
1167
+ function issueLocation(issue) {
1168
+ let location = "body.input";
1169
+ for (const segment of issue.path ?? []) {
1170
+ const key = typeof segment === "object" ? segment.key : segment;
1171
+ location += typeof key === "number" ? `[${key}]` : `.${String(key)}`;
1172
+ }
1173
+ return location;
1174
+ }
1175
+ async function checkInput(workflow, body) {
1176
+ if (!workflow.inputSchema) return;
1177
+ const input = JSON.parse(body).input ?? null;
1178
+ const result = await workflow.inputSchema["~standard"].validate(input);
1179
+ if (!result.issues) return;
1180
+ const summary = result.issues.map((issue) => issue.message).join("; ");
1181
+ throw new RunInputInvalidError(`${PACKAGE_PREFIX}: startRun: the input fails the input schema of workflow "${workflow.id}"${summary ? `: ${summary}` : ""}`, {
1182
+ type: "invalid_input",
1183
+ retryable: false,
1184
+ errors: result.issues.map((issue) => ({
1185
+ location: issueLocation(issue),
1186
+ message: issue.message
1187
+ })),
1188
+ issues: result.issues
1189
+ });
1190
+ }
1191
+ function toRunSummary(wire) {
1192
+ const run = wire;
1193
+ return {
1194
+ runId: run.run_id,
1195
+ workflowId: run.workflow_id,
1196
+ status: run.status,
1197
+ trigger: run.trigger,
1198
+ createdAt: run.created_at
1199
+ };
1200
+ }
1201
+ function toRun(wire) {
1202
+ const run = wire;
1203
+ return {
1204
+ ...toRunSummary(wire),
1205
+ updatedAt: run.updated_at,
1206
+ closedAt: run.closed_at,
1207
+ error: run.error,
1208
+ input: run.input,
1209
+ output: run.output
1210
+ };
1211
+ }
1212
+ async function startRun(workflow, input, options = {}) {
1213
+ options.signal?.throwIfAborted();
1214
+ assertServerRuntime();
1215
+ const definition = typeof workflow === "string" ? void 0 : workflow;
1216
+ if (definition !== void 0 && (typeof definition !== "object" || definition?.__kind !== "workflow")) throw invalidRequest("startRun", "path.workflow_id", "pass a workflow id or a createWorkflow() definition");
1217
+ const workflowId = definition?.id ?? workflow;
1218
+ if (typeof workflowId !== "string" || !WORKFLOW_ID_PATTERN.test(workflowId)) throw invalidRequest("startRun", "path.workflow_id", "workflow ids are 1–128 lowercase letters, digits, hyphens or underscores, starting with a letter or digit");
1219
+ const { idempotencyKey } = options;
1220
+ if (idempotencyKey !== void 0 && (typeof idempotencyKey !== "string" || !IDEMPOTENCY_KEY_PATTERN.test(idempotencyKey))) throw invalidRequest("startRun", "header.Idempotency-Key", "idempotencyKey must be 1–64 printable ASCII characters");
1221
+ const body = serialize("startRun", input === void 0 ? {} : { input }, "body.input");
1222
+ if (definition) await checkInput(definition, body);
1223
+ return toRunSummary(await send({
1224
+ call: "startRun",
1225
+ method: "POST",
1226
+ path: `/api/v1/app-workflows/${encodeURIComponent(workflowId)}/runs`,
1227
+ body,
1228
+ headers: idempotencyKey === void 0 ? void 0 : { "Idempotency-Key": idempotencyKey },
1229
+ signal: options.signal
1230
+ }));
1231
+ }
1232
+ /**
1233
+ * Reads one of the app's runs, with its input and output. Call it from server code only.
1234
+ *
1235
+ * The app's key reads every run of its project: runs it started, scheduled runs and editor test runs.
1236
+ */
1237
+ async function getRun(runId, options = {}) {
1238
+ options.signal?.throwIfAborted();
1239
+ assertServerRuntime();
1240
+ checkRunId("getRun", runId);
1241
+ return toRun(await send({
1242
+ call: "getRun",
1243
+ method: "GET",
1244
+ path: `/api/v1/app-workflow-runs/${encodeURIComponent(runId)}`,
1245
+ signal: options.signal
1246
+ }));
1247
+ }
1248
+ /**
1249
+ * Resumes the run's `ctx.waitForEvent` call that waits on the event's name. Call it from server code only.
1250
+ *
1251
+ * Events are not queued: an open run that doesn't wait on the name yet throws `RunNotWaitingError`, which can be
1252
+ * retried, and a finished run throws `RunClosedError`. A retry with the same `eventId` is always safe.
1253
+ */
1254
+ async function deliverEvent(runId, event, options = {}) {
1255
+ options.signal?.throwIfAborted();
1256
+ assertServerRuntime();
1257
+ checkRunId("deliverEvent", runId);
1258
+ if (event === null || typeof event !== "object") throw invalidRequest("deliverEvent", "body", "pass the event as { eventId, name, payload? }");
1259
+ const body = serialize("deliverEvent", {
1260
+ event_id: event.eventId,
1261
+ name: event.name,
1262
+ ...event.payload === void 0 ? {} : { payload: event.payload }
1263
+ }, "body.payload");
1264
+ return { recorded: (await send({
1265
+ call: "deliverEvent",
1266
+ method: "POST",
1267
+ path: `/api/v1/app-workflow-runs/${encodeURIComponent(runId)}/events`,
1268
+ body,
1269
+ signal: options.signal
1270
+ })).recorded === true };
1271
+ }
1272
+ //#endregion
1273
+ export { EventAlreadyDeliveredError, IdempotencyKeyReusedError, RunClosedError, RunInputInvalidError, RunNotFoundError, RunNotWaitingError, WorkflowNotPublishedError, WorkflowsApiError, WorkflowsAuthenticationError, WorkflowsConfigurationError, WorkflowsDevelopmentKeyError, WorkflowsDisabledError, WorkflowsKeyLookupError, WorkflowsNetworkError, WorkflowsPayloadTooLargeError, WorkflowsRateLimitedError, WorkflowsRequestInvalidError, WorkflowsUnavailableError, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, deliverEvent, every, generateManifests, getRun, hourly, registerWorkflows, startRun, toServerSentEventsResponse, weekly };
@@ -1,4 +1,4 @@
1
- import { loadTypeScript, t as workflowHandlerSource } from "./graph-B8nm_0lL.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-qDFxy3v5.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-B8nm_0lL.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-qDFxy3v5.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-B8nm_0lL.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-qDFxy3v5.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-DOuPyG-r.js";
1
+ import { t as generateManifests } from "./generate-CzKPbFyR.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-B8nm_0lL.js";
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-qDFxy3v5.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.55",
3
+ "version": "0.0.0-dev.57",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "dev",