@lovable.dev/workflows-sdk 0.0.0-dev.56 → 0.0.0-dev.58
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/README.md +82 -1
- package/dist/{branch-metadata-DdlPicB2.js → branch-metadata-DR6L1610.js} +1 -1
- package/dist/{context-escapes-BkqZwZQD.js → context-escapes-DhO7d5UB.js} +1 -1
- package/dist/{duplicate-ids-BqvEnwrg.js → duplicate-ids-C3J0tTFi.js} +1 -1
- package/dist/{generate-W-NgD43q.js → generate-sHCzFBzN.js} +12 -11
- package/dist/{graph-DZKqS7JU.js → graph-DNM6HACw.js} +1 -1
- package/dist/index.d.ts +300 -1
- package/dist/index.js +461 -14
- package/dist/{nested-operations-DzqRySTw.js → nested-operations-DroMYJeg.js} +1 -1
- package/dist/{operation-descriptions-CysWwDdv.js → operation-descriptions-CA9zrZ3y.js} +1 -1
- package/dist/{step-metadata-OA665DZL.js → step-metadata-BsrM_6XU.js} +1 -1
- package/dist/vite.js +1 -1
- package/dist/{wait-deadlines-Bq7CK982.js → wait-deadlines-9IpZV-qZ.js} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -276,6 +276,87 @@ Lovable supports only `skip` today. If any schedule of a workflow declares
|
|
|
276
276
|
`allow` or `buffer-one`, publishing registers none of that workflow's
|
|
277
277
|
schedules.
|
|
278
278
|
|
|
279
|
+
## Start runs from app code
|
|
280
|
+
|
|
281
|
+
`startRun`, `getRun` and `deliverEvent` start, read and resume runs of the
|
|
282
|
+
app's published workflows. They require SDK `0.0.0-dev.57` or newer. Call them
|
|
283
|
+
from server code only, such as a server route or a `*.server.ts` helper: they
|
|
284
|
+
send the app's `LOVABLE_API_KEY`, and they throw in a browser. The
|
|
285
|
+
`LOVABLE_WORKFLOWS_KEY` that authenticates the `/steps` route is a different
|
|
286
|
+
key and plays no part here.
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
const run = await startRun(orderShipped, { orderId: shipment.orderId }, { idempotencyKey: `shipment:${shipment.id}` });
|
|
290
|
+
const latest = await getRun(run.runId);
|
|
291
|
+
await deliverEvent(run.runId, { eventId: `approval:${approval.id}`, name: "approved", payload: { by: approval.by } });
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
| Call | Returns |
|
|
295
|
+
| --- | --- |
|
|
296
|
+
| `startRun(workflow, input?, options?)` | `{ runId, workflowId, status, trigger, createdAt }`; `trigger` is `api` |
|
|
297
|
+
| `getRun(runId, options?)` | The summary plus `updatedAt`, `closedAt`, `error`, `input` and `output` |
|
|
298
|
+
| `deliverEvent(runId, { eventId, name, payload? }, options?)` | `{ recorded }`, false when the `eventId` was already recorded |
|
|
299
|
+
|
|
300
|
+
A start runs the published version of the workflow. Preview and sandbox starts
|
|
301
|
+
run the published build too, and a start before the first publish throws
|
|
302
|
+
`WorkflowNotPublishedError`. Pass the workflow's definition to type the input
|
|
303
|
+
and check it against the workflow's input schema before anything is sent. An
|
|
304
|
+
input that fails the check throws `RunInputInvalidError`, creates no run and
|
|
305
|
+
leaves the idempotency key unused. In preview, between a schema change and the
|
|
306
|
+
next publish, the check uses the changed schema while the run uses the
|
|
307
|
+
published one. A workflow id string also works, without the check.
|
|
308
|
+
|
|
309
|
+
Derive `idempotencyKey` (1–64 printable ASCII characters) from the event that
|
|
310
|
+
starts the run. A repeat with the same key and input returns the run the key
|
|
311
|
+
started, in its current state. The same key with another input throws
|
|
312
|
+
`IdempotencyKeyReusedError`; an input object rebuilt with another key order
|
|
313
|
+
counts as another input. The SDK never retries a call and never makes up a key.
|
|
314
|
+
|
|
315
|
+
The input is any JSON value, at most 2 MiB serialized. Pass larger data by
|
|
316
|
+
reference: store it and pass its id. Integers above 2^53 lose precision, so
|
|
317
|
+
pass them as strings. A project can start 100 runs, read 1,000 runs and deliver
|
|
318
|
+
100 events a second.
|
|
319
|
+
|
|
320
|
+
`getRun` reads every run of the app's project, scheduled and editor test runs
|
|
321
|
+
included. `completed`, `failed`, `cancelled` and `skipped` are final; treat
|
|
322
|
+
`unknown` and any status added later as open. `output` is set once the run is
|
|
323
|
+
`completed`.
|
|
324
|
+
|
|
325
|
+
`deliverEvent` resumes the `ctx.waitForEvent(name)` call that waits on `name`.
|
|
326
|
+
Events are not queued: an open run that doesn't wait on the name yet throws
|
|
327
|
+
`RunNotWaitingError`, and a finished run throws `RunClosedError`. A retry with
|
|
328
|
+
the same `eventId` is always safe. An omitted `payload` resolves the wait with
|
|
329
|
+
no value, and `null` resolves it with `null`.
|
|
330
|
+
|
|
331
|
+
Every call takes an optional `signal`. Aborting stops the wait for the answer;
|
|
332
|
+
it does not undo a start or a delivery the gateway already received, so retry
|
|
333
|
+
with the same idempotency key or `eventId`.
|
|
334
|
+
|
|
335
|
+
Every error extends `WorkflowsApiError`, with `type`, `status`, `requestId`,
|
|
336
|
+
`retryable` and `retryAfterMs`. Its `toJSON()` never contains the API key.
|
|
337
|
+
|
|
338
|
+
| Error | Cause | Retryable |
|
|
339
|
+
| --- | --- | --- |
|
|
340
|
+
| `WorkflowNotPublishedError` | The workflow has no published version: ask the user to publish | No |
|
|
341
|
+
| `IdempotencyKeyReusedError` | The key already started a run from another request | No |
|
|
342
|
+
| `RunInputInvalidError` | The input fails the workflow's input schema | No |
|
|
343
|
+
| `RunNotWaitingError` | No step of the open run waits on the event name now | Yes, while the run is open |
|
|
344
|
+
| `RunClosedError` | The run has finished | No |
|
|
345
|
+
| `RunNotFoundError` | No such run in this project | No |
|
|
346
|
+
| `EventAlreadyDeliveredError` | The `eventId` already answered a wait with another name | No |
|
|
347
|
+
| `WorkflowsPayloadTooLargeError` | The input or payload is over its limit | No |
|
|
348
|
+
| `WorkflowsRateLimitedError`, `WorkflowsUnavailableError` | Over the project's limit, or the service is busy | Yes, after `retryAfterMs` |
|
|
349
|
+
| `WorkflowsNetworkError` | No answer arrived; the start may have happened | Yes, with the same key |
|
|
350
|
+
| `WorkflowsAuthenticationError` | The key is invalid or no longer registered: rotate `LOVABLE_API_KEY`, then republish or restart the backend | No |
|
|
351
|
+
| `WorkflowsKeyLookupError` | The gateway could not check the key | Yes |
|
|
352
|
+
| `WorkflowsDevelopmentKeyError` | A development key reached production | No |
|
|
353
|
+
| `WorkflowsDisabledError` | App workflows are off for the project | No |
|
|
354
|
+
| `WorkflowsRequestInvalidError` | An argument or the request is invalid | No |
|
|
355
|
+
| `WorkflowsConfigurationError` | A browser, a missing `LOVABLE_API_KEY` or a bad `LOVABLE_WORKFLOWS_API_URL` | No |
|
|
356
|
+
|
|
357
|
+
`LOVABLE_WORKFLOWS_API_URL` overrides the gateway URL, which defaults to
|
|
358
|
+
`https://connector-gateway.lovable.dev`. Lovable sets it for local development.
|
|
359
|
+
|
|
279
360
|
## Build integration
|
|
280
361
|
|
|
281
362
|
Add `workflowsPlugin()` before the TanStack Start plugin. Its `entry` defaults
|
|
@@ -293,5 +374,5 @@ plugins: [
|
|
|
293
374
|
|
|
294
375
|
| Import | Provides |
|
|
295
376
|
| --- | --- |
|
|
296
|
-
| `@lovable.dev/workflows-sdk` | Workflow authoring, registration, cadences, and
|
|
377
|
+
| `@lovable.dev/workflows-sdk` | Workflow authoring, registration, cadences, schedules, and `startRun`, `getRun` and `deliverEvent` |
|
|
297
378
|
| `@lovable.dev/workflows-sdk/vite` | Lovable build integration |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-DNM6HACw.js";
|
|
2
2
|
//#region src/manifests/duplicate-ids.ts
|
|
3
3
|
/** Where an explicit `{ id }` would sit for each operation. */
|
|
4
4
|
const optionsArgument = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createMiddleware, createWorkflow } from "@tanstack/workflow-core";
|
|
2
2
|
//#region src/core/identifier.ts
|
|
3
|
+
const WORKFLOW_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,127}$/;
|
|
3
4
|
function assertIdentifier(kind, id) {
|
|
4
5
|
if (typeof id !== "string" || id.trim() === "" || id !== id.trim()) throw new Error(`@lovable.dev/workflows-sdk: ${kind} IDs must be non-empty and have no surrounding whitespace`);
|
|
5
6
|
}
|
|
@@ -171,7 +172,7 @@ function registerWorkflows(definition) {
|
|
|
171
172
|
for (const workflow of workflows) {
|
|
172
173
|
if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
|
|
173
174
|
assertIdentifier("workflow", workflow.id);
|
|
174
|
-
if (
|
|
175
|
+
if (!WORKFLOW_ID_PATTERN.test(workflow.id)) throw new Error("@lovable.dev/workflows-sdk: workflow names must be 1–128 lowercase letters, digits, hyphens or underscores, starting with a letter or digit");
|
|
175
176
|
if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
|
|
176
177
|
ids.add(workflow.id);
|
|
177
178
|
workflowVersions(workflow);
|
|
@@ -6643,7 +6644,7 @@ function listValueFromJson(listValue, json) {
|
|
|
6643
6644
|
}
|
|
6644
6645
|
//#endregion
|
|
6645
6646
|
//#region package.json
|
|
6646
|
-
var version = "0.0.0-dev.
|
|
6647
|
+
var version = "0.0.0-dev.58";
|
|
6647
6648
|
//#endregion
|
|
6648
6649
|
//#region src/proto/lovable/appworkflows/v1/workflow_manifest_pb.ts
|
|
6649
6650
|
/**
|
|
@@ -6865,15 +6866,15 @@ function serializeSchema(schema, direction, label) {
|
|
|
6865
6866
|
}
|
|
6866
6867
|
}
|
|
6867
6868
|
async function generateManifests(definition, options = {}) {
|
|
6868
|
-
const { extractWorkflowGraph } = await import("./graph-
|
|
6869
|
-
const { findBranchMetadataIssues } = await import("./branch-metadata-
|
|
6870
|
-
const { findWorkflowContextEscapes } = await import("./context-escapes-
|
|
6871
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-
|
|
6869
|
+
const { extractWorkflowGraph } = await import("./graph-DNM6HACw.js");
|
|
6870
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-DR6L1610.js");
|
|
6871
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-DhO7d5UB.js");
|
|
6872
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-C3J0tTFi.js");
|
|
6872
6873
|
const { DURABLE_ID_REQUIRED } = await import("./durable-ids-Cx341nJQ.js").then((n) => n.n);
|
|
6873
|
-
const { findNestedDurableOperations } = await import("./nested-operations-
|
|
6874
|
-
const { findOperationDescriptionIssues } = await import("./operation-descriptions-
|
|
6875
|
-
const { findStepMetadataIssues } = await import("./step-metadata-
|
|
6876
|
-
const { findWaitDeadlineIssues } = await import("./wait-deadlines-
|
|
6874
|
+
const { findNestedDurableOperations } = await import("./nested-operations-DroMYJeg.js");
|
|
6875
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-CA9zrZ3y.js");
|
|
6876
|
+
const { findStepMetadataIssues } = await import("./step-metadata-BsrM_6XU.js");
|
|
6877
|
+
const { findWaitDeadlineIssues } = await import("./wait-deadlines-9IpZV-qZ.js");
|
|
6877
6878
|
const { WAIT_DEADLINE_REQUIRED } = await import("./wait-deadlines-DpK-Fgnd.js");
|
|
6878
6879
|
const collection = registerWorkflows(definition);
|
|
6879
6880
|
const manifests = [];
|
|
@@ -6981,4 +6982,4 @@ async function generateManifests(definition, options = {}) {
|
|
|
6981
6982
|
});
|
|
6982
6983
|
}
|
|
6983
6984
|
//#endregion
|
|
6984
|
-
export { daily as A, WorkflowManifestWaitForEventNodeV1Schema as C, registerWorkflows as D, createWorkflow$1 as E, hourly as M, weekly as N, workflowVersions as O, WorkflowManifestUuidNodeV1Schema as S, createMiddleware as T, WorkflowManifestSleepNodeV1Schema as _, WorkflowManifestConnectorNodeV1Schema as a, WorkflowManifestStepNodeV1Schema as b, WorkflowManifestGraphV1Schema as c, WorkflowManifestNowNodeV1Schema as d, WorkflowManifestOrderEdgeV1Schema as f, WorkflowManifestRepeatedStepV1Schema as g, WorkflowManifestRepeatedLlmV1Schema as h, WorkflowManifestBranchNodeV1Schema as i, every as j, defineSchedule as k, WorkflowManifestLlmNodeV1Schema as l, WorkflowManifestRepeatedConnectorV1Schema as m, WorkflowManifestApproveNodeV1Schema as n, WorkflowManifestGraphEdgeV1Schema as o, WorkflowManifestParallelNodeV1Schema as p, WorkflowManifestBranchEdgeV1Schema as r, WorkflowManifestGraphNodeV1Schema as s, generateManifests as t, WorkflowManifestLoopNodeV1Schema as u, WorkflowManifestSleepUntilNodeV1Schema as v, create as w, WorkflowManifestUnknownNodeV1Schema as x, WorkflowManifestStepExecutionPolicyV1Schema as y };
|
|
6985
|
+
export { daily as A, WorkflowManifestWaitForEventNodeV1Schema as C, registerWorkflows as D, createWorkflow$1 as E, hourly as M, weekly as N, workflowVersions as O, WORKFLOW_ID_PATTERN as P, WorkflowManifestUuidNodeV1Schema as S, createMiddleware as T, WorkflowManifestSleepNodeV1Schema as _, WorkflowManifestConnectorNodeV1Schema as a, WorkflowManifestStepNodeV1Schema as b, WorkflowManifestGraphV1Schema as c, WorkflowManifestNowNodeV1Schema as d, WorkflowManifestOrderEdgeV1Schema as f, WorkflowManifestRepeatedStepV1Schema as g, WorkflowManifestRepeatedLlmV1Schema as h, WorkflowManifestBranchNodeV1Schema as i, every as j, defineSchedule as k, WorkflowManifestLlmNodeV1Schema as l, WorkflowManifestRepeatedConnectorV1Schema as m, WorkflowManifestApproveNodeV1Schema as n, WorkflowManifestGraphEdgeV1Schema as o, WorkflowManifestParallelNodeV1Schema as p, WorkflowManifestBranchEdgeV1Schema as r, WorkflowManifestGraphNodeV1Schema as s, generateManifests as t, WorkflowManifestLoopNodeV1Schema as u, WorkflowManifestSleepUntilNodeV1Schema as v, create as w, WorkflowManifestUnknownNodeV1Schema as x, WorkflowManifestStepExecutionPolicyV1Schema as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as WorkflowManifestWaitForEventNodeV1Schema, S as WorkflowManifestUuidNodeV1Schema, _ as WorkflowManifestSleepNodeV1Schema, a as WorkflowManifestConnectorNodeV1Schema, b as WorkflowManifestStepNodeV1Schema, c as WorkflowManifestGraphV1Schema, d as WorkflowManifestNowNodeV1Schema, f as WorkflowManifestOrderEdgeV1Schema, g as WorkflowManifestRepeatedStepV1Schema, h as WorkflowManifestRepeatedLlmV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestLlmNodeV1Schema, m as WorkflowManifestRepeatedConnectorV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphEdgeV1Schema, p as WorkflowManifestParallelNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphNodeV1Schema, u as WorkflowManifestLoopNodeV1Schema, v as WorkflowManifestSleepUntilNodeV1Schema, w as create, x as WorkflowManifestUnknownNodeV1Schema, y as WorkflowManifestStepExecutionPolicyV1Schema } from "./generate-
|
|
1
|
+
import { C as WorkflowManifestWaitForEventNodeV1Schema, S as WorkflowManifestUuidNodeV1Schema, _ as WorkflowManifestSleepNodeV1Schema, a as WorkflowManifestConnectorNodeV1Schema, b as WorkflowManifestStepNodeV1Schema, c as WorkflowManifestGraphV1Schema, d as WorkflowManifestNowNodeV1Schema, f as WorkflowManifestOrderEdgeV1Schema, g as WorkflowManifestRepeatedStepV1Schema, h as WorkflowManifestRepeatedLlmV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestLlmNodeV1Schema, m as WorkflowManifestRepeatedConnectorV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphEdgeV1Schema, p as WorkflowManifestParallelNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphNodeV1Schema, u as WorkflowManifestLoopNodeV1Schema, v as WorkflowManifestSleepUntilNodeV1Schema, w as create, x as WorkflowManifestUnknownNodeV1Schema, y as WorkflowManifestStepExecutionPolicyV1Schema } from "./generate-sHCzFBzN.js";
|
|
2
2
|
import { n as assertLlmOptions, t as assertLlmModel } from "./llm-validation-DdDO6csU.js";
|
|
3
3
|
//#region src/manifests/handler-source.ts
|
|
4
4
|
const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AccumulateExtensions, AnyMiddleware, AnyWorkflowDefinition, AnyWorkflowDefinition as AnyWorkflowDefinition$1, ApprovalResult, ApproveOptions as ApproveOptions$1, CreateWorkflowConfig, Ctx as Ctx$1, InferSchema, RunStore, SchemaInput, StepContext, StepContext as StepContext$1, StepOptions, StepOptions as StepOptions$1, WaitForEventOptions as WaitForEventOptions$1, WorkflowBuilder, WorkflowDefinition, WorkflowDefinition as WorkflowDefinition$1, WorkflowEvent, WorkflowInput, WorkflowInput as WorkflowInput$1, WorkflowMetadata, WorkflowOutput, WorkflowState, createMiddleware } from "@tanstack/workflow-core";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
3
|
//#region src/core/step-metadata.d.ts
|
|
3
4
|
interface WorkflowStepGroup {
|
|
4
5
|
id: string;
|
|
@@ -1013,9 +1014,12 @@ interface StepsRequestBase {
|
|
|
1013
1014
|
type StepsRequest = StepsRequestBase & ({
|
|
1014
1015
|
action?: "advance";
|
|
1015
1016
|
step?: never;
|
|
1017
|
+
/** Name the one ready step and run nothing; the caller then runs it with `execute`. */
|
|
1018
|
+
describe?: boolean;
|
|
1016
1019
|
} | {
|
|
1017
1020
|
action: "execute";
|
|
1018
1021
|
step: StepReference;
|
|
1022
|
+
describe?: never;
|
|
1019
1023
|
});
|
|
1020
1024
|
type StepsDisposition = "advanced" | "fork" | "waiting" | "completed" | "failed";
|
|
1021
1025
|
interface StepsResponse {
|
|
@@ -1042,4 +1046,299 @@ declare function createStepsHandler(collection: WorkflowCollection, options?: St
|
|
|
1042
1046
|
*/
|
|
1043
1047
|
declare function toServerSentEventsResponse(events: AsyncIterable<WorkflowEvent>): Response;
|
|
1044
1048
|
//#endregion
|
|
1045
|
-
|
|
1049
|
+
//#region src/client/generated/gateway.d.ts
|
|
1050
|
+
interface components {
|
|
1051
|
+
schemas: {
|
|
1052
|
+
DeliverEventRequest: {
|
|
1053
|
+
/** @description Makes the delivery safe to retry. A delivery that repeats the event_id is accepted and records nothing new. The same event_id with another name answers 409. */
|
|
1054
|
+
event_id: string;
|
|
1055
|
+
/** @description The event name that the run's ctx.waitForEvent call waits on. */
|
|
1056
|
+
name: string;
|
|
1057
|
+
/** @description The value that the ctx.waitForEvent call resolves to, any JSON value. Omit it for an event that carries no data. */
|
|
1058
|
+
payload?: unknown;
|
|
1059
|
+
};
|
|
1060
|
+
DeliverEventResponse: {
|
|
1061
|
+
/** @description Is false when an earlier delivery with the same event_id already recorded the event. */
|
|
1062
|
+
recorded: boolean;
|
|
1063
|
+
};
|
|
1064
|
+
Error: {
|
|
1065
|
+
/** @description Explanation of this occurrence, or null. */
|
|
1066
|
+
detail: string | null;
|
|
1067
|
+
/** @description The invalid request values, or null. */
|
|
1068
|
+
errors: components["schemas"]["ErrorDetail"][] | null;
|
|
1069
|
+
/** @description Extra data for the error type, or null. */
|
|
1070
|
+
props: {
|
|
1071
|
+
[key: string]: unknown;
|
|
1072
|
+
} | null;
|
|
1073
|
+
/** @description Identifier of this request. Quote it when you report a failure. */
|
|
1074
|
+
request_id: string;
|
|
1075
|
+
/**
|
|
1076
|
+
* Format: int64
|
|
1077
|
+
* @description HTTP status code.
|
|
1078
|
+
*/
|
|
1079
|
+
status: number;
|
|
1080
|
+
/** @description Short, human-readable summary. */
|
|
1081
|
+
title: string;
|
|
1082
|
+
/** @description Machine-readable error type in snake_case. */
|
|
1083
|
+
type: string;
|
|
1084
|
+
};
|
|
1085
|
+
ErrorDetail: {
|
|
1086
|
+
/** @description Where the value is, such as body.input, or null. */
|
|
1087
|
+
location: string | null;
|
|
1088
|
+
/** @description What is wrong with the value. */
|
|
1089
|
+
message: string;
|
|
1090
|
+
};
|
|
1091
|
+
Run: {
|
|
1092
|
+
/**
|
|
1093
|
+
* Format: date-time
|
|
1094
|
+
* @description When the run reached a final status, or null while it is open.
|
|
1095
|
+
*/
|
|
1096
|
+
closed_at: string | null;
|
|
1097
|
+
/**
|
|
1098
|
+
* Format: date-time
|
|
1099
|
+
* @description When the run was created.
|
|
1100
|
+
*/
|
|
1101
|
+
created_at: string;
|
|
1102
|
+
/** @description Why the run failed or was cancelled, or null. */
|
|
1103
|
+
error: string | null;
|
|
1104
|
+
/** @description The run's input, any JSON value, or null when the run has no input. */
|
|
1105
|
+
input: unknown;
|
|
1106
|
+
/** @description The value that the workflow returned, any JSON value, or null until the run is completed. */
|
|
1107
|
+
output: unknown;
|
|
1108
|
+
/** @description Identifier of the run. */
|
|
1109
|
+
run_id: string;
|
|
1110
|
+
/**
|
|
1111
|
+
* @description The run's status. completed, failed, cancelled and skipped are final.
|
|
1112
|
+
* @enum {string}
|
|
1113
|
+
*/
|
|
1114
|
+
status: "queued" | "running" | "waiting" | "completed" | "failed" | "cancelled" | "skipped" | "unknown";
|
|
1115
|
+
/**
|
|
1116
|
+
* @description What started the run. A run that the app's code starts is api.
|
|
1117
|
+
* @enum {string}
|
|
1118
|
+
*/
|
|
1119
|
+
trigger: "manual" | "schedule" | "event" | "webhook" | "api" | "unknown";
|
|
1120
|
+
/**
|
|
1121
|
+
* Format: date-time
|
|
1122
|
+
* @description When the run last changed.
|
|
1123
|
+
*/
|
|
1124
|
+
updated_at: string;
|
|
1125
|
+
/** @description The workflow that the run executes. */
|
|
1126
|
+
workflow_id: string;
|
|
1127
|
+
};
|
|
1128
|
+
RunSummary: {
|
|
1129
|
+
/**
|
|
1130
|
+
* Format: date-time
|
|
1131
|
+
* @description When the run was created.
|
|
1132
|
+
*/
|
|
1133
|
+
created_at: string;
|
|
1134
|
+
/** @description Identifier of the run. */
|
|
1135
|
+
run_id: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* @description The run's status when the response was written.
|
|
1138
|
+
* @enum {string}
|
|
1139
|
+
*/
|
|
1140
|
+
status: "queued" | "running" | "waiting" | "completed" | "failed" | "cancelled" | "skipped" | "unknown";
|
|
1141
|
+
/**
|
|
1142
|
+
* @description What started the run. A run that the app's code starts is api.
|
|
1143
|
+
* @enum {string}
|
|
1144
|
+
*/
|
|
1145
|
+
trigger: "manual" | "schedule" | "event" | "webhook" | "api" | "unknown";
|
|
1146
|
+
/** @description The workflow that the run executes. */
|
|
1147
|
+
workflow_id: string;
|
|
1148
|
+
};
|
|
1149
|
+
StartRunRequest: {
|
|
1150
|
+
/** @description The run's input, any JSON value. Omit it for a workflow that takes no input. */
|
|
1151
|
+
input?: unknown;
|
|
1152
|
+
};
|
|
1153
|
+
};
|
|
1154
|
+
responses: never;
|
|
1155
|
+
parameters: never;
|
|
1156
|
+
requestBodies: never;
|
|
1157
|
+
headers: never;
|
|
1158
|
+
pathItems: never;
|
|
1159
|
+
}
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region src/client/runs.d.ts
|
|
1162
|
+
type WireRun = components["schemas"]["Run"];
|
|
1163
|
+
/** `completed`, `failed`, `cancelled` and `skipped` are final. Treat `unknown`, and any status added later, as open. */
|
|
1164
|
+
type RunStatus = WireRun["status"];
|
|
1165
|
+
type RunTrigger = WireRun["trigger"];
|
|
1166
|
+
interface RunSummary {
|
|
1167
|
+
runId: string;
|
|
1168
|
+
workflowId: string;
|
|
1169
|
+
/** The status when the gateway answered. A start that repeats an Idempotency-Key returns the run in its current state. */
|
|
1170
|
+
status: RunStatus;
|
|
1171
|
+
/** `api` for a run that app code started. */
|
|
1172
|
+
trigger: RunTrigger;
|
|
1173
|
+
createdAt: string;
|
|
1174
|
+
}
|
|
1175
|
+
interface Run extends RunSummary {
|
|
1176
|
+
updatedAt: string;
|
|
1177
|
+
/** Null while the run is open. */
|
|
1178
|
+
closedAt: string | null;
|
|
1179
|
+
/** Why the run failed or was cancelled, or null. */
|
|
1180
|
+
error: string | null;
|
|
1181
|
+
input: unknown;
|
|
1182
|
+
/** Set only once the run is `completed`. */
|
|
1183
|
+
output: unknown;
|
|
1184
|
+
}
|
|
1185
|
+
interface StartRunOptions {
|
|
1186
|
+
/**
|
|
1187
|
+
* Makes the start safe to retry: 1–64 printable ASCII characters, derived from the event that starts the run.
|
|
1188
|
+
* A repeat with the same key and input returns the run the key started.
|
|
1189
|
+
*/
|
|
1190
|
+
idempotencyKey?: string;
|
|
1191
|
+
signal?: AbortSignal;
|
|
1192
|
+
}
|
|
1193
|
+
interface GetRunOptions {
|
|
1194
|
+
signal?: AbortSignal;
|
|
1195
|
+
}
|
|
1196
|
+
interface DeliverEventInput {
|
|
1197
|
+
/** Makes the delivery safe to retry. */
|
|
1198
|
+
eventId: string;
|
|
1199
|
+
/** The name that the run's `ctx.waitForEvent` call waits on. */
|
|
1200
|
+
name: string;
|
|
1201
|
+
/** What `ctx.waitForEvent` resolves to. Omit it for an event that carries no data. */
|
|
1202
|
+
payload?: unknown;
|
|
1203
|
+
}
|
|
1204
|
+
interface DeliverEventOptions {
|
|
1205
|
+
signal?: AbortSignal;
|
|
1206
|
+
}
|
|
1207
|
+
interface DeliverEventResult {
|
|
1208
|
+
/** False when an earlier delivery with the same `eventId` already recorded the event. */
|
|
1209
|
+
recorded: boolean;
|
|
1210
|
+
}
|
|
1211
|
+
type StartRunArgs<W extends AnyWorkflowDefinition$1> = undefined extends WorkflowInput$1<W> ? [input?: WorkflowInput$1<W>, options?: StartRunOptions] : [input: WorkflowInput$1<W>, options?: StartRunOptions];
|
|
1212
|
+
/**
|
|
1213
|
+
* Starts a run of the published version of one of the app's workflows. Call it from server code only.
|
|
1214
|
+
*
|
|
1215
|
+
* Pass the workflow's definition to type the input and check it against the workflow's input schema before anything
|
|
1216
|
+
* is sent, or pass the workflow id. The SDK never retries and never makes up an Idempotency-Key: derive the key from
|
|
1217
|
+
* the event, and retry with the same key and input.
|
|
1218
|
+
*/
|
|
1219
|
+
declare function startRun<W extends AnyWorkflowDefinition$1>(workflow: W, ...args: StartRunArgs<W>): Promise<RunSummary>;
|
|
1220
|
+
declare function startRun(workflowId: string, input?: unknown, options?: StartRunOptions): Promise<RunSummary>;
|
|
1221
|
+
/**
|
|
1222
|
+
* Reads one of the app's runs, with its input and output. Call it from server code only.
|
|
1223
|
+
*
|
|
1224
|
+
* The app's key reads every run of its project: runs it started, scheduled runs and editor test runs.
|
|
1225
|
+
*/
|
|
1226
|
+
declare function getRun(runId: string, options?: GetRunOptions): Promise<Run>;
|
|
1227
|
+
/**
|
|
1228
|
+
* Resumes the run's `ctx.waitForEvent` call that waits on the event's name. Call it from server code only.
|
|
1229
|
+
*
|
|
1230
|
+
* Events are not queued: an open run that doesn't wait on the name yet throws `RunNotWaitingError`, which can be
|
|
1231
|
+
* retried, and a finished run throws `RunClosedError`. A retry with the same `eventId` is always safe.
|
|
1232
|
+
*/
|
|
1233
|
+
declare function deliverEvent(runId: string, event: DeliverEventInput, options?: DeliverEventOptions): Promise<DeliverEventResult>;
|
|
1234
|
+
//#endregion
|
|
1235
|
+
//#region src/client/errors.d.ts
|
|
1236
|
+
/** One invalid request value, as the gateway reports it in `errors`. */
|
|
1237
|
+
interface WorkflowsErrorDetail {
|
|
1238
|
+
location: string | null;
|
|
1239
|
+
message: string;
|
|
1240
|
+
}
|
|
1241
|
+
interface WorkflowsApiErrorJSON {
|
|
1242
|
+
name: string;
|
|
1243
|
+
message: string;
|
|
1244
|
+
type: string;
|
|
1245
|
+
status?: number;
|
|
1246
|
+
requestId?: string;
|
|
1247
|
+
title?: string;
|
|
1248
|
+
detail?: string;
|
|
1249
|
+
errors?: WorkflowsErrorDetail[];
|
|
1250
|
+
retryable: boolean;
|
|
1251
|
+
retryAfterMs?: number;
|
|
1252
|
+
}
|
|
1253
|
+
interface WorkflowsApiErrorFields {
|
|
1254
|
+
type: string;
|
|
1255
|
+
retryable: boolean;
|
|
1256
|
+
status?: number;
|
|
1257
|
+
requestId?: string;
|
|
1258
|
+
title?: string;
|
|
1259
|
+
detail?: string;
|
|
1260
|
+
errors?: WorkflowsErrorDetail[];
|
|
1261
|
+
retryAfterMs?: number;
|
|
1262
|
+
cause?: unknown;
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* A failed `startRun`, `getRun` or `deliverEvent` call.
|
|
1266
|
+
*
|
|
1267
|
+
* `status` is the gateway's HTTP status, and is undefined when the SDK refused the call before sending it or got no
|
|
1268
|
+
* response. `retryable` is true when repeating the same call later can succeed without a change to the code, the
|
|
1269
|
+
* configuration or the app; the SDK itself never retries.
|
|
1270
|
+
*/
|
|
1271
|
+
declare class WorkflowsApiError extends Error {
|
|
1272
|
+
readonly name: string;
|
|
1273
|
+
readonly type: string;
|
|
1274
|
+
readonly status?: number;
|
|
1275
|
+
readonly requestId?: string;
|
|
1276
|
+
readonly title?: string;
|
|
1277
|
+
readonly detail?: string;
|
|
1278
|
+
readonly errors?: WorkflowsErrorDetail[];
|
|
1279
|
+
readonly retryable: boolean;
|
|
1280
|
+
readonly retryAfterMs?: number;
|
|
1281
|
+
constructor(message: string, fields: WorkflowsApiErrorFields);
|
|
1282
|
+
toJSON(): WorkflowsApiErrorJSON;
|
|
1283
|
+
}
|
|
1284
|
+
type ConfigurationErrorReason = "server_only" | "missing_api_key" | "invalid_url";
|
|
1285
|
+
declare class WorkflowsConfigurationError extends WorkflowsApiError {
|
|
1286
|
+
readonly name = "WorkflowsConfigurationError";
|
|
1287
|
+
readonly reason: ConfigurationErrorReason;
|
|
1288
|
+
constructor(reason: ConfigurationErrorReason, message: string);
|
|
1289
|
+
}
|
|
1290
|
+
declare class WorkflowsRequestInvalidError extends WorkflowsApiError {
|
|
1291
|
+
readonly name: string;
|
|
1292
|
+
}
|
|
1293
|
+
/** The input fails the workflow's input schema. The SDK sent no request, so the Idempotency-Key is still unused. */
|
|
1294
|
+
declare class RunInputInvalidError extends WorkflowsRequestInvalidError {
|
|
1295
|
+
readonly name = "RunInputInvalidError";
|
|
1296
|
+
readonly issues: readonly StandardSchemaV1.Issue[];
|
|
1297
|
+
constructor(message: string, fields: WorkflowsApiErrorFields & {
|
|
1298
|
+
issues: readonly StandardSchemaV1.Issue[];
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
declare class WorkflowsNetworkError extends WorkflowsApiError {
|
|
1302
|
+
readonly name = "WorkflowsNetworkError";
|
|
1303
|
+
}
|
|
1304
|
+
declare class WorkflowsAuthenticationError extends WorkflowsApiError {
|
|
1305
|
+
readonly name = "WorkflowsAuthenticationError";
|
|
1306
|
+
}
|
|
1307
|
+
declare class WorkflowsKeyLookupError extends WorkflowsApiError {
|
|
1308
|
+
readonly name = "WorkflowsKeyLookupError";
|
|
1309
|
+
}
|
|
1310
|
+
declare class WorkflowsDevelopmentKeyError extends WorkflowsApiError {
|
|
1311
|
+
readonly name = "WorkflowsDevelopmentKeyError";
|
|
1312
|
+
}
|
|
1313
|
+
declare class WorkflowsDisabledError extends WorkflowsApiError {
|
|
1314
|
+
readonly name = "WorkflowsDisabledError";
|
|
1315
|
+
}
|
|
1316
|
+
declare class RunNotFoundError extends WorkflowsApiError {
|
|
1317
|
+
readonly name = "RunNotFoundError";
|
|
1318
|
+
}
|
|
1319
|
+
declare class WorkflowNotPublishedError extends WorkflowsApiError {
|
|
1320
|
+
readonly name = "WorkflowNotPublishedError";
|
|
1321
|
+
}
|
|
1322
|
+
declare class IdempotencyKeyReusedError extends WorkflowsApiError {
|
|
1323
|
+
readonly name = "IdempotencyKeyReusedError";
|
|
1324
|
+
}
|
|
1325
|
+
declare class RunClosedError extends WorkflowsApiError {
|
|
1326
|
+
readonly name = "RunClosedError";
|
|
1327
|
+
}
|
|
1328
|
+
declare class RunNotWaitingError extends WorkflowsApiError {
|
|
1329
|
+
readonly name = "RunNotWaitingError";
|
|
1330
|
+
}
|
|
1331
|
+
declare class EventAlreadyDeliveredError extends WorkflowsApiError {
|
|
1332
|
+
readonly name = "EventAlreadyDeliveredError";
|
|
1333
|
+
}
|
|
1334
|
+
declare class WorkflowsPayloadTooLargeError extends WorkflowsApiError {
|
|
1335
|
+
readonly name = "WorkflowsPayloadTooLargeError";
|
|
1336
|
+
}
|
|
1337
|
+
declare class WorkflowsRateLimitedError extends WorkflowsApiError {
|
|
1338
|
+
readonly name = "WorkflowsRateLimitedError";
|
|
1339
|
+
}
|
|
1340
|
+
declare class WorkflowsUnavailableError extends WorkflowsApiError {
|
|
1341
|
+
readonly name = "WorkflowsUnavailableError";
|
|
1342
|
+
}
|
|
1343
|
+
//#endregion
|
|
1344
|
+
export { type AnyWorkflowDefinition, type ApproveOptions, type Cadence, type ConfigurationErrorReason, type ConnectorStep, type ConnectorStepOptions, type Ctx, type DeliverEventInput, type DeliverEventOptions, type DeliverEventResult, EventAlreadyDeliveredError, type GetRunOptions, IdempotencyKeyReusedError, type LlmRequest, type LlmStep, type LlmStepOptions, type MemoEntry, type MinuteInterval, type NextStep, type OverlapPolicy, type ReplayOutcome, type ResolvedSchedule, type ResolvedTrigger, type Run, RunClosedError, RunInputInvalidError, RunNotFoundError, RunNotWaitingError, type RunStatus, type RunSummary, type RunTrigger, type ScheduleDefinition, type StartRunOptions, 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, WorkflowNotPublishedError, type WorkflowOperationMetadata, type WorkflowOutput, type WorkflowState, type WorkflowStepGroup, type WorkflowStepMetadata, WorkflowsApiError, type WorkflowsApiErrorJSON, WorkflowsAuthenticationError, WorkflowsConfigurationError, type WorkflowsDefinition, WorkflowsDevelopmentKeyError, WorkflowsDisabledError, type WorkflowsErrorDetail, WorkflowsKeyLookupError, WorkflowsNetworkError, WorkflowsPayloadTooLargeError, WorkflowsRateLimitedError, WorkflowsRequestInvalidError, WorkflowsUnavailableError, createMiddleware, createStepsHandler, createTanStackWorkflowHandler, createWorkflow, daily, defineSchedule, deliverEvent, every, generateManifests, getRun, hourly, registerWorkflows, startRun, 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 { A as daily, D as registerWorkflows, E as createWorkflow, M as hourly, N as weekly, O as workflowVersions, T as createMiddleware, j as every, k as defineSchedule, t as generateManifests } from "./generate-
|
|
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-sHCzFBzN.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/
|
|
528
|
-
const PROJECT_SECRET_ENV_VAR = "LOVABLE_WORKFLOWS_KEY";
|
|
527
|
+
//#region src/core/runtime-env.ts
|
|
529
528
|
let cloudflareEnvPromise;
|
|
530
|
-
function
|
|
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
|
-
|
|
540
|
-
return typeof value === "string" && value ? value : void 0;
|
|
534
|
+
return cloudflareEnvPromise;
|
|
541
535
|
}
|
|
542
|
-
|
|
543
|
-
|
|
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");
|
|
@@ -646,6 +654,7 @@ function parseBody(value) {
|
|
|
646
654
|
if (body.action !== void 0 && body.action !== "advance" && body.action !== "execute") return "action must be \"advance\" or \"execute\"";
|
|
647
655
|
if (body.action === "execute" && !isStepReference(body.step)) return "step must be a { kind: \"step\" | \"llm\" | \"connector\", stepId } reference when action is \"execute\"";
|
|
648
656
|
if (body.action !== "execute" && body.step !== void 0) return "step is only valid when action is \"execute\"";
|
|
657
|
+
if (body.describe !== void 0 && typeof body.describe !== "boolean") return "describe must be a boolean";
|
|
649
658
|
if (body.memo !== void 0 && body.memo.length > 0 && !("input" in value)) return "input must be sent with every call, including a resume";
|
|
650
659
|
return body;
|
|
651
660
|
}
|
|
@@ -806,7 +815,7 @@ function createStepsHandler(collection, options = {}) {
|
|
|
806
815
|
shouldExecute: (intent) => !isRunnableKind(intent.kind)
|
|
807
816
|
}));
|
|
808
817
|
const only = described.steps.length === 1 ? described.steps[0] : void 0;
|
|
809
|
-
if (described.status !== "pending" || !only || !isRunnableKind(only.kind)) return json(200, stepsResponse(runId, inputHash, workflow.version, before, described));
|
|
818
|
+
if (described.status !== "pending" || !only || !isRunnableKind(only.kind) || body.describe === true) return json(200, stepsResponse(runId, inputHash, workflow.version, before, described));
|
|
810
819
|
const outcome = await validateOutput(workflow, await replay({
|
|
811
820
|
workflow,
|
|
812
821
|
input,
|
|
@@ -824,4 +833,442 @@ function createStepsHandler(collection, options = {}) {
|
|
|
824
833
|
};
|
|
825
834
|
}
|
|
826
835
|
//#endregion
|
|
827
|
-
|
|
836
|
+
//#region src/client/errors.ts
|
|
837
|
+
/**
|
|
838
|
+
* A failed `startRun`, `getRun` or `deliverEvent` call.
|
|
839
|
+
*
|
|
840
|
+
* `status` is the gateway's HTTP status, and is undefined when the SDK refused the call before sending it or got no
|
|
841
|
+
* response. `retryable` is true when repeating the same call later can succeed without a change to the code, the
|
|
842
|
+
* configuration or the app; the SDK itself never retries.
|
|
843
|
+
*/
|
|
844
|
+
var WorkflowsApiError = class extends Error {
|
|
845
|
+
name = "WorkflowsApiError";
|
|
846
|
+
type;
|
|
847
|
+
status;
|
|
848
|
+
requestId;
|
|
849
|
+
title;
|
|
850
|
+
detail;
|
|
851
|
+
errors;
|
|
852
|
+
retryable;
|
|
853
|
+
retryAfterMs;
|
|
854
|
+
constructor(message, fields) {
|
|
855
|
+
super(message, fields.cause === void 0 ? void 0 : { cause: fields.cause });
|
|
856
|
+
this.type = fields.type;
|
|
857
|
+
this.status = fields.status;
|
|
858
|
+
this.requestId = fields.requestId;
|
|
859
|
+
this.title = fields.title;
|
|
860
|
+
this.detail = fields.detail;
|
|
861
|
+
this.errors = fields.errors;
|
|
862
|
+
this.retryable = fields.retryable;
|
|
863
|
+
this.retryAfterMs = fields.retryAfterMs;
|
|
864
|
+
}
|
|
865
|
+
toJSON() {
|
|
866
|
+
return {
|
|
867
|
+
name: this.name,
|
|
868
|
+
message: this.message,
|
|
869
|
+
type: this.type,
|
|
870
|
+
status: this.status,
|
|
871
|
+
requestId: this.requestId,
|
|
872
|
+
title: this.title,
|
|
873
|
+
detail: this.detail,
|
|
874
|
+
errors: this.errors,
|
|
875
|
+
retryable: this.retryable,
|
|
876
|
+
retryAfterMs: this.retryAfterMs
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
var WorkflowsConfigurationError = class extends WorkflowsApiError {
|
|
881
|
+
name = "WorkflowsConfigurationError";
|
|
882
|
+
reason;
|
|
883
|
+
constructor(reason, message) {
|
|
884
|
+
super(message, {
|
|
885
|
+
type: "configuration_error",
|
|
886
|
+
retryable: false
|
|
887
|
+
});
|
|
888
|
+
this.reason = reason;
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
var WorkflowsRequestInvalidError = class extends WorkflowsApiError {
|
|
892
|
+
name = "WorkflowsRequestInvalidError";
|
|
893
|
+
};
|
|
894
|
+
/** The input fails the workflow's input schema. The SDK sent no request, so the Idempotency-Key is still unused. */
|
|
895
|
+
var RunInputInvalidError = class extends WorkflowsRequestInvalidError {
|
|
896
|
+
name = "RunInputInvalidError";
|
|
897
|
+
issues;
|
|
898
|
+
constructor(message, fields) {
|
|
899
|
+
super(message, fields);
|
|
900
|
+
this.issues = fields.issues;
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
var WorkflowsNetworkError = class extends WorkflowsApiError {
|
|
904
|
+
name = "WorkflowsNetworkError";
|
|
905
|
+
};
|
|
906
|
+
var WorkflowsAuthenticationError = class extends WorkflowsApiError {
|
|
907
|
+
name = "WorkflowsAuthenticationError";
|
|
908
|
+
};
|
|
909
|
+
var WorkflowsKeyLookupError = class extends WorkflowsApiError {
|
|
910
|
+
name = "WorkflowsKeyLookupError";
|
|
911
|
+
};
|
|
912
|
+
var WorkflowsDevelopmentKeyError = class extends WorkflowsApiError {
|
|
913
|
+
name = "WorkflowsDevelopmentKeyError";
|
|
914
|
+
};
|
|
915
|
+
var WorkflowsDisabledError = class extends WorkflowsApiError {
|
|
916
|
+
name = "WorkflowsDisabledError";
|
|
917
|
+
};
|
|
918
|
+
var RunNotFoundError = class extends WorkflowsApiError {
|
|
919
|
+
name = "RunNotFoundError";
|
|
920
|
+
};
|
|
921
|
+
var WorkflowNotPublishedError = class extends WorkflowsApiError {
|
|
922
|
+
name = "WorkflowNotPublishedError";
|
|
923
|
+
};
|
|
924
|
+
var IdempotencyKeyReusedError = class extends WorkflowsApiError {
|
|
925
|
+
name = "IdempotencyKeyReusedError";
|
|
926
|
+
};
|
|
927
|
+
var RunClosedError = class extends WorkflowsApiError {
|
|
928
|
+
name = "RunClosedError";
|
|
929
|
+
};
|
|
930
|
+
var RunNotWaitingError = class extends WorkflowsApiError {
|
|
931
|
+
name = "RunNotWaitingError";
|
|
932
|
+
};
|
|
933
|
+
var EventAlreadyDeliveredError = class extends WorkflowsApiError {
|
|
934
|
+
name = "EventAlreadyDeliveredError";
|
|
935
|
+
};
|
|
936
|
+
var WorkflowsPayloadTooLargeError = class extends WorkflowsApiError {
|
|
937
|
+
name = "WorkflowsPayloadTooLargeError";
|
|
938
|
+
};
|
|
939
|
+
var WorkflowsRateLimitedError = class extends WorkflowsApiError {
|
|
940
|
+
name = "WorkflowsRateLimitedError";
|
|
941
|
+
};
|
|
942
|
+
var WorkflowsUnavailableError = class extends WorkflowsApiError {
|
|
943
|
+
name = "WorkflowsUnavailableError";
|
|
944
|
+
};
|
|
945
|
+
const CLASS_BY_TYPE = /* @__PURE__ */ new Map([
|
|
946
|
+
["invalid_request", WorkflowsRequestInvalidError],
|
|
947
|
+
["invalid_api_key", WorkflowsAuthenticationError],
|
|
948
|
+
["lovable_api_key_not_registered", WorkflowsAuthenticationError],
|
|
949
|
+
["lovable_api_key_registry_lookup_failed", WorkflowsKeyLookupError],
|
|
950
|
+
["lovable_api_key_development_only", WorkflowsDevelopmentKeyError],
|
|
951
|
+
["app_workflows_disabled", WorkflowsDisabledError],
|
|
952
|
+
["run_not_found", RunNotFoundError],
|
|
953
|
+
["workflow_not_published", WorkflowNotPublishedError],
|
|
954
|
+
["idempotency_key_reused", IdempotencyKeyReusedError],
|
|
955
|
+
["run_closed", RunClosedError],
|
|
956
|
+
["run_not_waiting", RunNotWaitingError],
|
|
957
|
+
["event_already_delivered", EventAlreadyDeliveredError],
|
|
958
|
+
["run_input_too_large", WorkflowsPayloadTooLargeError],
|
|
959
|
+
["payload_too_large", WorkflowsPayloadTooLargeError]
|
|
960
|
+
]);
|
|
961
|
+
const RETRYABLE_CLASSES = /* @__PURE__ */ new Set([
|
|
962
|
+
WorkflowsKeyLookupError,
|
|
963
|
+
RunNotWaitingError,
|
|
964
|
+
WorkflowsRateLimitedError,
|
|
965
|
+
WorkflowsUnavailableError
|
|
966
|
+
]);
|
|
967
|
+
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."]]);
|
|
968
|
+
const TYPE_BY_STATUS = /* @__PURE__ */ new Map([
|
|
969
|
+
[400, "bad_request"],
|
|
970
|
+
[401, "unauthorized"],
|
|
971
|
+
[403, "forbidden"],
|
|
972
|
+
[404, "not_found"],
|
|
973
|
+
[405, "method_not_allowed"],
|
|
974
|
+
[408, "request_timeout"],
|
|
975
|
+
[409, "conflict"],
|
|
976
|
+
[413, "request_entity_too_large"],
|
|
977
|
+
[415, "unsupported_media_type"],
|
|
978
|
+
[429, "too_many_requests"],
|
|
979
|
+
[500, "internal_server_error"],
|
|
980
|
+
[502, "bad_gateway"],
|
|
981
|
+
[503, "service_unavailable"],
|
|
982
|
+
[504, "gateway_timeout"]
|
|
983
|
+
]);
|
|
984
|
+
const DEFAULT_RETRY_AFTER_MS = 1e3;
|
|
985
|
+
const MAX_ERROR_BODY_BYTES = 16384;
|
|
986
|
+
const ERROR_BODY_TIMEOUT_MS = 1e3;
|
|
987
|
+
const PACKAGE_PREFIX = "@lovable.dev/workflows-sdk";
|
|
988
|
+
function object(value) {
|
|
989
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
990
|
+
}
|
|
991
|
+
async function readErrorBody(response) {
|
|
992
|
+
if (!response.body) return void 0;
|
|
993
|
+
const reader = response.body.getReader();
|
|
994
|
+
let timer;
|
|
995
|
+
try {
|
|
996
|
+
return await Promise.race([(async () => {
|
|
997
|
+
const decoder = new TextDecoder();
|
|
998
|
+
let text = "";
|
|
999
|
+
let bytes = 0;
|
|
1000
|
+
while (true) {
|
|
1001
|
+
const { done, value } = await reader.read();
|
|
1002
|
+
if (done) return JSON.parse(text + decoder.decode());
|
|
1003
|
+
bytes += value.byteLength;
|
|
1004
|
+
if (bytes > MAX_ERROR_BODY_BYTES) return void 0;
|
|
1005
|
+
text += decoder.decode(value, { stream: true });
|
|
1006
|
+
}
|
|
1007
|
+
})(), new Promise((resolve) => {
|
|
1008
|
+
timer = setTimeout(() => resolve(void 0), ERROR_BODY_TIMEOUT_MS);
|
|
1009
|
+
})]);
|
|
1010
|
+
} catch {
|
|
1011
|
+
return;
|
|
1012
|
+
} finally {
|
|
1013
|
+
clearTimeout(timer);
|
|
1014
|
+
reader.cancel().catch(() => void 0);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function parseRetryAfter(value) {
|
|
1018
|
+
if (!value || value.length > 128) return void 0;
|
|
1019
|
+
const trimmed = value.trim();
|
|
1020
|
+
if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
1021
|
+
const milliseconds = Number(trimmed) * 1e3;
|
|
1022
|
+
return Number.isFinite(milliseconds) ? milliseconds : void 0;
|
|
1023
|
+
}
|
|
1024
|
+
if (!/^[A-Za-z]/.test(trimmed)) return void 0;
|
|
1025
|
+
const timestamp = Date.parse(trimmed);
|
|
1026
|
+
return Number.isFinite(timestamp) ? Math.max(0, timestamp - Date.now()) : void 0;
|
|
1027
|
+
}
|
|
1028
|
+
/** Replaces the API key in text that reaches an error, and caps its length. */
|
|
1029
|
+
function redactor(apiKey) {
|
|
1030
|
+
return (value, maxLength = 2e3) => (apiKey ? value.replaceAll(apiKey, "[redacted]") : value).slice(0, maxLength);
|
|
1031
|
+
}
|
|
1032
|
+
function errorDetails(value, redact) {
|
|
1033
|
+
if (!Array.isArray(value)) return void 0;
|
|
1034
|
+
const details = [];
|
|
1035
|
+
for (const entry of value.slice(0, 50)) {
|
|
1036
|
+
const { location, message } = object(entry);
|
|
1037
|
+
if (typeof message !== "string") continue;
|
|
1038
|
+
details.push({
|
|
1039
|
+
location: typeof location === "string" ? redact(location, 200) : null,
|
|
1040
|
+
message: redact(message)
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return details;
|
|
1044
|
+
}
|
|
1045
|
+
async function errorFromResponse(call, response, apiKey) {
|
|
1046
|
+
const redact = redactor(apiKey);
|
|
1047
|
+
const text = (value, maxLength) => typeof value === "string" && value ? redact(value, maxLength) : void 0;
|
|
1048
|
+
const body = object(await readErrorBody(response));
|
|
1049
|
+
const status = response.status;
|
|
1050
|
+
const envelopeType = text(body.type, 200);
|
|
1051
|
+
const type = envelopeType ?? TYPE_BY_STATUS.get(status) ?? `http_${status}`;
|
|
1052
|
+
let ErrorClass = WorkflowsApiError;
|
|
1053
|
+
if (status === 429) ErrorClass = WorkflowsRateLimitedError;
|
|
1054
|
+
else if (status === 503) ErrorClass = WorkflowsUnavailableError;
|
|
1055
|
+
else if (envelopeType) ErrorClass = CLASS_BY_TYPE.get(envelopeType) ?? WorkflowsApiError;
|
|
1056
|
+
const retryable = RETRYABLE_CLASSES.has(ErrorClass) || ErrorClass === WorkflowsApiError && (status === 408 || status >= 500);
|
|
1057
|
+
const retryAfterMs = parseRetryAfter(response.headers.get("Retry-After")) ?? (status === 429 || status === 503 ? DEFAULT_RETRY_AFTER_MS : void 0);
|
|
1058
|
+
const title = text(body.title, 200);
|
|
1059
|
+
const detail = text(body.detail);
|
|
1060
|
+
const hint = HINT_BY_TYPE.get(type);
|
|
1061
|
+
return new ErrorClass(`${PACKAGE_PREFIX}: ${call} failed (${status} ${type}): ${detail ?? title ?? "The gateway answered without an error body."}${hint ? ` ${hint}` : ""}`, {
|
|
1062
|
+
type,
|
|
1063
|
+
status,
|
|
1064
|
+
requestId: text(response.headers.get("X-Request-Id"), 200) ?? text(body.request_id, 200),
|
|
1065
|
+
title,
|
|
1066
|
+
detail,
|
|
1067
|
+
errors: errorDetails(body.errors, redact),
|
|
1068
|
+
retryable,
|
|
1069
|
+
retryAfterMs
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
//#endregion
|
|
1073
|
+
//#region src/client/transport.ts
|
|
1074
|
+
const DEFAULT_BASE_URL = "https://connector-gateway.lovable.dev";
|
|
1075
|
+
function assertServerRuntime() {
|
|
1076
|
+
const runtime = globalThis;
|
|
1077
|
+
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.`);
|
|
1078
|
+
}
|
|
1079
|
+
async function connect() {
|
|
1080
|
+
const apiKey = (await readRuntimeEnv("LOVABLE_API_KEY"))?.trim();
|
|
1081
|
+
if (!apiKey) throw new WorkflowsConfigurationError("missing_api_key", `${PACKAGE_PREFIX}: LOVABLE_API_KEY is missing from the server environment.`);
|
|
1082
|
+
const baseURL = ((await readRuntimeEnv("LOVABLE_WORKFLOWS_API_URL"))?.trim() || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1083
|
+
let url;
|
|
1084
|
+
try {
|
|
1085
|
+
url = new URL(baseURL);
|
|
1086
|
+
} catch {
|
|
1087
|
+
url = void 0;
|
|
1088
|
+
}
|
|
1089
|
+
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.`);
|
|
1090
|
+
return {
|
|
1091
|
+
apiKey,
|
|
1092
|
+
baseURL
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function networkError(call, cause) {
|
|
1096
|
+
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." : ""}`, {
|
|
1097
|
+
type: "network_error",
|
|
1098
|
+
retryable: true,
|
|
1099
|
+
cause
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
function invalidResponse(call, response, cause) {
|
|
1103
|
+
return new WorkflowsApiError(`${PACKAGE_PREFIX}: ${call} got a ${response.status} response that is not the expected JSON.`, {
|
|
1104
|
+
type: "invalid_response",
|
|
1105
|
+
status: response.status,
|
|
1106
|
+
requestId: response.headers.get("X-Request-Id")?.slice(0, 200) || void 0,
|
|
1107
|
+
retryable: true,
|
|
1108
|
+
cause
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
async function send(request) {
|
|
1112
|
+
const connection = await connect();
|
|
1113
|
+
const headers = new Headers(request.headers);
|
|
1114
|
+
headers.set("Authorization", `Bearer ${connection.apiKey}`);
|
|
1115
|
+
headers.set("Accept", "application/json");
|
|
1116
|
+
headers.set("User-Agent", `lovable-workflows-sdk/0.0.0-dev.58`);
|
|
1117
|
+
if (request.body !== void 0) headers.set("Content-Type", "application/json");
|
|
1118
|
+
let response;
|
|
1119
|
+
try {
|
|
1120
|
+
response = await fetch(`${connection.baseURL}${request.path}`, {
|
|
1121
|
+
method: request.method,
|
|
1122
|
+
headers,
|
|
1123
|
+
body: request.body,
|
|
1124
|
+
signal: request.signal,
|
|
1125
|
+
redirect: "manual"
|
|
1126
|
+
});
|
|
1127
|
+
} catch (cause) {
|
|
1128
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
1129
|
+
throw networkError(request.call, cause);
|
|
1130
|
+
}
|
|
1131
|
+
if (!response.ok) throw await errorFromResponse(request.call, response, connection.apiKey);
|
|
1132
|
+
let parsed;
|
|
1133
|
+
try {
|
|
1134
|
+
parsed = await response.json();
|
|
1135
|
+
} catch (cause) {
|
|
1136
|
+
if (request.signal?.aborted) throw request.signal.reason;
|
|
1137
|
+
if (cause instanceof SyntaxError) throw invalidResponse(request.call, response, cause);
|
|
1138
|
+
throw networkError(request.call, cause);
|
|
1139
|
+
}
|
|
1140
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw invalidResponse(request.call, response);
|
|
1141
|
+
return parsed;
|
|
1142
|
+
}
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region src/client/runs.ts
|
|
1145
|
+
const IDEMPOTENCY_KEY_PATTERN = /^[\x20-\x7E]{1,64}$/;
|
|
1146
|
+
const MAX_RUN_ID_LENGTH = 64;
|
|
1147
|
+
function invalidRequest(call, location, message, cause) {
|
|
1148
|
+
return new WorkflowsRequestInvalidError(`${PACKAGE_PREFIX}: ${call}: ${message}`, {
|
|
1149
|
+
type: "invalid_request",
|
|
1150
|
+
retryable: false,
|
|
1151
|
+
errors: [{
|
|
1152
|
+
location,
|
|
1153
|
+
message
|
|
1154
|
+
}],
|
|
1155
|
+
cause
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
function serialize(call, body, location) {
|
|
1159
|
+
try {
|
|
1160
|
+
return JSON.stringify(body);
|
|
1161
|
+
} catch (cause) {
|
|
1162
|
+
throw invalidRequest(call, location, "the value is not JSON-serializable", cause);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
function checkRunId(call, runId) {
|
|
1166
|
+
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");
|
|
1167
|
+
}
|
|
1168
|
+
function issueLocation(issue) {
|
|
1169
|
+
let location = "body.input";
|
|
1170
|
+
for (const segment of issue.path ?? []) {
|
|
1171
|
+
const key = typeof segment === "object" ? segment.key : segment;
|
|
1172
|
+
location += typeof key === "number" ? `[${key}]` : `.${String(key)}`;
|
|
1173
|
+
}
|
|
1174
|
+
return location;
|
|
1175
|
+
}
|
|
1176
|
+
async function checkInput(workflow, body) {
|
|
1177
|
+
if (!workflow.inputSchema) return;
|
|
1178
|
+
const input = JSON.parse(body).input ?? null;
|
|
1179
|
+
const result = await workflow.inputSchema["~standard"].validate(input);
|
|
1180
|
+
if (!result.issues) return;
|
|
1181
|
+
const summary = result.issues.map((issue) => issue.message).join("; ");
|
|
1182
|
+
throw new RunInputInvalidError(`${PACKAGE_PREFIX}: startRun: the input fails the input schema of workflow "${workflow.id}"${summary ? `: ${summary}` : ""}`, {
|
|
1183
|
+
type: "invalid_input",
|
|
1184
|
+
retryable: false,
|
|
1185
|
+
errors: result.issues.map((issue) => ({
|
|
1186
|
+
location: issueLocation(issue),
|
|
1187
|
+
message: issue.message
|
|
1188
|
+
})),
|
|
1189
|
+
issues: result.issues
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
function toRunSummary(wire) {
|
|
1193
|
+
const run = wire;
|
|
1194
|
+
return {
|
|
1195
|
+
runId: run.run_id,
|
|
1196
|
+
workflowId: run.workflow_id,
|
|
1197
|
+
status: run.status,
|
|
1198
|
+
trigger: run.trigger,
|
|
1199
|
+
createdAt: run.created_at
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
function toRun(wire) {
|
|
1203
|
+
const run = wire;
|
|
1204
|
+
return {
|
|
1205
|
+
...toRunSummary(wire),
|
|
1206
|
+
updatedAt: run.updated_at,
|
|
1207
|
+
closedAt: run.closed_at,
|
|
1208
|
+
error: run.error,
|
|
1209
|
+
input: run.input,
|
|
1210
|
+
output: run.output
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
async function startRun(workflow, input, options = {}) {
|
|
1214
|
+
options.signal?.throwIfAborted();
|
|
1215
|
+
assertServerRuntime();
|
|
1216
|
+
const definition = typeof workflow === "string" ? void 0 : workflow;
|
|
1217
|
+
if (definition !== void 0 && (typeof definition !== "object" || definition?.__kind !== "workflow")) throw invalidRequest("startRun", "path.workflow_id", "pass a workflow id or a createWorkflow() definition");
|
|
1218
|
+
const workflowId = definition?.id ?? workflow;
|
|
1219
|
+
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");
|
|
1220
|
+
const { idempotencyKey } = options;
|
|
1221
|
+
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");
|
|
1222
|
+
const body = serialize("startRun", input === void 0 ? {} : { input }, "body.input");
|
|
1223
|
+
if (definition) await checkInput(definition, body);
|
|
1224
|
+
return toRunSummary(await send({
|
|
1225
|
+
call: "startRun",
|
|
1226
|
+
method: "POST",
|
|
1227
|
+
path: `/api/v1/app-workflows/${encodeURIComponent(workflowId)}/runs`,
|
|
1228
|
+
body,
|
|
1229
|
+
headers: idempotencyKey === void 0 ? void 0 : { "Idempotency-Key": idempotencyKey },
|
|
1230
|
+
signal: options.signal
|
|
1231
|
+
}));
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Reads one of the app's runs, with its input and output. Call it from server code only.
|
|
1235
|
+
*
|
|
1236
|
+
* The app's key reads every run of its project: runs it started, scheduled runs and editor test runs.
|
|
1237
|
+
*/
|
|
1238
|
+
async function getRun(runId, options = {}) {
|
|
1239
|
+
options.signal?.throwIfAborted();
|
|
1240
|
+
assertServerRuntime();
|
|
1241
|
+
checkRunId("getRun", runId);
|
|
1242
|
+
return toRun(await send({
|
|
1243
|
+
call: "getRun",
|
|
1244
|
+
method: "GET",
|
|
1245
|
+
path: `/api/v1/app-workflow-runs/${encodeURIComponent(runId)}`,
|
|
1246
|
+
signal: options.signal
|
|
1247
|
+
}));
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Resumes the run's `ctx.waitForEvent` call that waits on the event's name. Call it from server code only.
|
|
1251
|
+
*
|
|
1252
|
+
* Events are not queued: an open run that doesn't wait on the name yet throws `RunNotWaitingError`, which can be
|
|
1253
|
+
* retried, and a finished run throws `RunClosedError`. A retry with the same `eventId` is always safe.
|
|
1254
|
+
*/
|
|
1255
|
+
async function deliverEvent(runId, event, options = {}) {
|
|
1256
|
+
options.signal?.throwIfAborted();
|
|
1257
|
+
assertServerRuntime();
|
|
1258
|
+
checkRunId("deliverEvent", runId);
|
|
1259
|
+
if (event === null || typeof event !== "object") throw invalidRequest("deliverEvent", "body", "pass the event as { eventId, name, payload? }");
|
|
1260
|
+
const body = serialize("deliverEvent", {
|
|
1261
|
+
event_id: event.eventId,
|
|
1262
|
+
name: event.name,
|
|
1263
|
+
...event.payload === void 0 ? {} : { payload: event.payload }
|
|
1264
|
+
}, "body.payload");
|
|
1265
|
+
return { recorded: (await send({
|
|
1266
|
+
call: "deliverEvent",
|
|
1267
|
+
method: "POST",
|
|
1268
|
+
path: `/api/v1/app-workflow-runs/${encodeURIComponent(runId)}/events`,
|
|
1269
|
+
body,
|
|
1270
|
+
signal: options.signal
|
|
1271
|
+
})).recorded === true };
|
|
1272
|
+
}
|
|
1273
|
+
//#endregion
|
|
1274
|
+
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-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-DNM6HACw.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-sHCzFBzN.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";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lovable.dev/workflows-sdk",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.58",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"tag": "dev",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@standard-schema/spec": "^1.1.0",
|
|
33
33
|
"@tanstack/workflow-core": "0.0.4",
|
|
34
|
-
"@lovable.dev/ai-gateway": "0.1.
|
|
34
|
+
"@lovable.dev/ai-gateway": "0.1.13"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@bufbuild/protobuf": "^2.10.1",
|