@lovable.dev/sdk 1.4.0 → 1.6.1

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.
@@ -0,0 +1,233 @@
1
+ //#region ../workflow-sdk/src/index.d.ts
2
+ interface JournalEntry {
3
+ result?: unknown;
4
+ resultType?: "undefined" | "ref";
5
+ /** Payload pointer when resultType is "ref"; see docs/workflows/payload-offload.md. */
6
+ ref?: PayloadRef;
7
+ /** Marks an auto-offloaded ref that replays as its parsed value instead of a WorkflowFile. */
8
+ transparent?: boolean;
9
+ /** Ephemeral read grant the engine hydrates per invocation; never persisted. */
10
+ grant?: PayloadGrant;
11
+ }
12
+ type Journal = Record<string, JournalEntry>;
13
+ type PayloadAeadScheme = "CHUNKED_AES_256_GCM_V1";
14
+ interface PayloadRef {
15
+ bucket: string;
16
+ key: string;
17
+ /** Lowercase hex SHA-256 of the plaintext bytes. */
18
+ sha256: string;
19
+ sizeBytes: number;
20
+ contentType: string;
21
+ /** Base64 AES-256 DEK sealed by the workflows payload KEK. */
22
+ wrappedDek: string;
23
+ kekId: string;
24
+ scheme: PayloadAeadScheme;
25
+ }
26
+ interface PayloadGrant {
27
+ getUrl: string;
28
+ /** Base64 raw AES-256 DEK for this object. */
29
+ dek: string;
30
+ }
31
+ interface PayloadOffload {
32
+ /** Absolute URL of the runtime payload endpoint (POST /runtime/v1/payloads). */
33
+ endpoint: string;
34
+ /** Step results whose JSON serialization is <= threshold bytes stay inline. */
35
+ threshold: number;
36
+ /** Per-object plaintext byte cap. */
37
+ maxBytes: number;
38
+ }
39
+ /** Lazy handle over an offloaded payload; reads stream-decrypt on access. */
40
+ interface WorkflowFile {
41
+ readonly sha256: string;
42
+ readonly sizeBytes: number;
43
+ readonly contentType: string;
44
+ stream(): ReadableStream<Uint8Array>;
45
+ arrayBuffer(): Promise<ArrayBuffer>;
46
+ text(): Promise<string>;
47
+ json(): Promise<unknown>;
48
+ }
49
+ interface WorkflowFilesApi {
50
+ /** Offloads `data` and returns a handle; stream inputs are buffered in memory (tranche 1). */
51
+ create(data: ReadableStream<Uint8Array> | ArrayBuffer | Uint8Array | string, options: {
52
+ contentType: string;
53
+ }): Promise<WorkflowFile>;
54
+ }
55
+ interface WorkerRequest<Input = unknown> {
56
+ input: Input;
57
+ journal: Journal;
58
+ /** Present when the engine enables large-payload offload for this run. */
59
+ payloadOffload?: PayloadOffload;
60
+ }
61
+ interface WorkerTaskRequest<Input = unknown> {
62
+ operation: "task";
63
+ task: string;
64
+ input: Input;
65
+ runName: string;
66
+ stepId: string;
67
+ attempt: number;
68
+ workflowTenant: string;
69
+ workflowApiUrl: string;
70
+ }
71
+ type ExecutionEnvironment = "cloudflare";
72
+ interface StepDispatch {
73
+ id: string;
74
+ task: string;
75
+ environment: ExecutionEnvironment;
76
+ input: unknown;
77
+ maxConcurrency?: number;
78
+ /** Durable-promise park request (ctx.promise); the engine parks the run instead of executing. */
79
+ promise?: {
80
+ name: string;
81
+ timeoutSeconds?: number;
82
+ };
83
+ }
84
+ /** `completed` is this invocation's unpersisted delta, including on workflow failure. */
85
+ type WorkerResponse<Output = unknown> = {
86
+ status: "done";
87
+ output: Output;
88
+ outputType?: never;
89
+ completed: Journal;
90
+ } | {
91
+ status: "done";
92
+ output: null;
93
+ outputType: "undefined";
94
+ completed: Journal;
95
+ } | {
96
+ status: "failed";
97
+ error: string;
98
+ failedStep?: string;
99
+ completed: Journal;
100
+ } | {
101
+ status: "dispatch";
102
+ steps: StepDispatch[];
103
+ completed: Journal;
104
+ };
105
+ interface TaskDefinitionBase {
106
+ readonly name: string;
107
+ readonly environment: ExecutionEnvironment;
108
+ readonly maxConcurrency?: number;
109
+ }
110
+ type WorkflowLogLevel = "debug" | "info" | "warn" | "error";
111
+ interface WorkflowLogEntry {
112
+ readonly level: WorkflowLogLevel;
113
+ readonly message: string;
114
+ readonly fields?: Record<string, unknown>;
115
+ }
116
+ type WorkflowLogEmitter = (entry: WorkflowLogEntry) => void;
117
+ /**
118
+ * Fire-and-forget structured logging. Entries are scrubbed for
119
+ * credential-shaped values, capped in size and count, and not journaled;
120
+ * workflow-body entries are suppressed while journaled effects replay, so
121
+ * each entry is emitted once across engine round-trips.
122
+ */
123
+ interface WorkflowLogger {
124
+ debug(message: string, fields?: Record<string, unknown>): void;
125
+ info(message: string, fields?: Record<string, unknown>): void;
126
+ warn(message: string, fields?: Record<string, unknown>): void;
127
+ error(message: string, fields?: Record<string, unknown>): void;
128
+ }
129
+ interface TaskContext {
130
+ readonly runName: string;
131
+ readonly stepId: string;
132
+ readonly attempt: number;
133
+ readonly workflows: WorkflowsApi;
134
+ readonly log: WorkflowLogger;
135
+ }
136
+ interface WorkflowRunRequest {
137
+ readonly workspaceId: string;
138
+ readonly projectId: string;
139
+ readonly workflowId: string;
140
+ readonly inputs?: unknown;
141
+ readonly invocationKey?: string;
142
+ }
143
+ interface WorkflowRun {
144
+ readonly id: string;
145
+ readonly state: string;
146
+ readonly error?: string;
147
+ readonly inputs?: unknown;
148
+ readonly outputs?: unknown;
149
+ readonly codeAttempt?: number;
150
+ readonly createTime?: string;
151
+ readonly startTime?: string;
152
+ readonly endTime?: string;
153
+ }
154
+ interface WorkflowsApi {
155
+ run(request: WorkflowRunRequest): Promise<WorkflowRun>;
156
+ }
157
+ interface CloudflareTaskDefinition<Input = unknown, Output = unknown> extends TaskDefinitionBase {
158
+ readonly environment: "cloudflare";
159
+ readonly run: (input: Input, context: TaskContext) => Promise<Output> | Output;
160
+ }
161
+ type TaskDefinition<Input = unknown, Output = unknown> = CloudflareTaskDefinition<Input, Output>;
162
+ interface CloudflareTaskConfig<Input, Output> {
163
+ name: string;
164
+ environment: "cloudflare";
165
+ run: (input: Input, context: TaskContext) => Promise<Output> | Output;
166
+ maxConcurrency?: number;
167
+ }
168
+ interface StepRunOptions {
169
+ id?: string;
170
+ }
171
+ declare function defineTask<Input, Output>(config: CloudflareTaskConfig<Input, Output>): CloudflareTaskDefinition<Input, Output>;
172
+ interface StepApi {
173
+ /** Replays a stable, unique name from the journal; effects must tolerate deliberate retries. */
174
+ run<T>(name: string, effect: () => Promise<T> | T): Promise<T>;
175
+ run<Input, Output>(task: TaskDefinition<Input, Output>, input: Input, options?: StepRunOptions): Promise<Output>;
176
+ }
177
+ interface WorkflowPromiseOptions {
178
+ /** Auto-reject deadline in seconds (1..86400); unset means bounded only by the run deadline. */
179
+ timeoutSeconds?: number;
180
+ }
181
+ /** A durable promise was rejected (explicitly or by its timeout sweep). Catchable to branch on rejection. */
182
+ declare class PromiseRejectedError extends Error {
183
+ readonly promiseName: string;
184
+ readonly reason: string;
185
+ constructor(promiseName: string, reason: string);
186
+ }
187
+ interface WorkflowContext<Input = unknown> {
188
+ readonly input: Input;
189
+ readonly step: StepApi;
190
+ readonly files: WorkflowFilesApi;
191
+ readonly log: WorkflowLogger;
192
+ /** Journaled wall clock keyed by a stable name. */
193
+ now(name: string): Promise<number>;
194
+ /** Journaled random UUID keyed by a stable name. */
195
+ uuid(name: string): Promise<string>;
196
+ /** Parks until external resolution; replay returns the value or throws PromiseRejectedError. */
197
+ promise<T = unknown>(name: string, options?: WorkflowPromiseOptions): Promise<T>;
198
+ }
199
+ interface WorkflowDefinition<Input = unknown, Output = unknown> {
200
+ readonly name: string;
201
+ readonly handler: (ctx: WorkflowContext<Input>) => Promise<Output>;
202
+ }
203
+ declare function defineWorkflow<Input = unknown, Output = unknown>(name: string, handler: (ctx: WorkflowContext<Input>) => Promise<Output>): WorkflowDefinition<Input, Output>;
204
+ type PayloadCryptoKey = Awaited<ReturnType<typeof crypto.subtle.importKey>>;
205
+ /** Chunked AES-256-GCM encryptor emitting [payloadLen u32 BE][nonce 12][ciphertext||tag] frames. */
206
+ declare function encryptPayloadStream(key: PayloadCryptoKey): TransformStream<Uint8Array, Uint8Array>;
207
+ /** Decrypts CHUNKED_AES_256_GCM_V1; rejects truncation, reordering, splices, and digest or size mismatches. */
208
+ declare function decryptPayloadStream(key: PayloadCryptoKey, expected: {
209
+ sha256: string;
210
+ sizeBytes: number;
211
+ }): TransformStream<Uint8Array, Uint8Array>;
212
+ interface InvokeOptions {
213
+ /** Receives each capped and scrubbed entry; defaults to JSON envelopes on the console. */
214
+ onLog?: WorkflowLogEmitter;
215
+ }
216
+ declare function invoke<Input, Output>(workflow: WorkflowDefinition<Input, Output>, request: WorkerRequest<Input>, options?: InvokeOptions): Promise<WorkerResponse<Output>>;
217
+ interface WorkerOptions {
218
+ tasks?: unknown;
219
+ }
220
+ interface Worker {
221
+ fetch: (request: Request) => Promise<Response>;
222
+ }
223
+ declare function toWorker<Input, Output>(workflowValue: WorkflowDefinition<Input, Output>, options?: WorkerOptions): Worker;
224
+ interface DriveOptions {
225
+ /** Total invocations before a failure is surfaced. Default 1 (no retry). */
226
+ maxAttempts?: number;
227
+ /** Receives each capped and scrubbed entry; defaults to JSON envelopes on the console. */
228
+ onLog?: WorkflowLogEmitter;
229
+ }
230
+ declare function driveToCompletion<Input, Output>(workflow: WorkflowDefinition<Input, Output>, input: Input, options?: DriveOptions): Promise<Output>;
231
+ //#endregion
232
+ export { CloudflareTaskConfig, CloudflareTaskDefinition, DriveOptions, ExecutionEnvironment, InvokeOptions, Journal, JournalEntry, PayloadAeadScheme, PayloadCryptoKey, PayloadGrant, PayloadOffload, PayloadRef, PromiseRejectedError, StepApi, StepDispatch, StepRunOptions, TaskContext, TaskDefinition, Worker, WorkerOptions, WorkerRequest, WorkerResponse, WorkerTaskRequest, WorkflowContext, WorkflowDefinition, WorkflowFile, WorkflowFilesApi, WorkflowLogEmitter, WorkflowLogEntry, WorkflowLogLevel, WorkflowLogger, WorkflowPromiseOptions, WorkflowRun, WorkflowRunRequest, WorkflowsApi, decryptPayloadStream, defineTask, defineWorkflow, driveToCompletion, encryptPayloadStream, invoke, toWorker };
233
+ //# sourceMappingURL=workflows.d.ts.map