@upstash/workflow 0.2.2 → 0.2.4
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/astro.d.mts +1 -1
- package/astro.d.ts +1 -1
- package/astro.js +267 -73
- package/astro.mjs +7 -1
- package/{chunk-Z7WS5XIR.mjs → chunk-ETDFMXER.mjs} +265 -69
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +273 -77
- package/cloudflare.mjs +13 -5
- package/express.d.mts +1 -1
- package/express.d.ts +1 -1
- package/express.js +1625 -1295
- package/express.mjs +1384 -1242
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +271 -74
- package/h3.mjs +11 -2
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +275 -79
- package/hono.mjs +15 -7
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +281 -78
- package/index.mjs +10 -4
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +276 -74
- package/nextjs.mjs +16 -2
- package/package.json +1 -1
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +271 -74
- package/solidjs.mjs +11 -2
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +273 -77
- package/svelte.mjs +13 -5
- package/{types-APRap-aV.d.mts → types-Bt4-paRy.d.mts} +325 -14
- package/{types-APRap-aV.d.ts → types-Bt4-paRy.d.ts} +325 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublishRequest, Client, Receiver, HTTPMethods as HTTPMethods$1 } from '@upstash/qstash';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base class outlining steps. Basically, each step kind (run/sleep/sleepUntil)
|
|
@@ -63,10 +63,11 @@ declare class AutoExecutor {
|
|
|
63
63
|
private readonly nonPlanStepCount;
|
|
64
64
|
private readonly steps;
|
|
65
65
|
private indexInCurrentList;
|
|
66
|
+
private telemetry?;
|
|
66
67
|
stepCount: number;
|
|
67
68
|
planStepCount: number;
|
|
68
69
|
protected executingStep: string | false;
|
|
69
|
-
constructor(context: WorkflowContext, steps: Step[], debug?: WorkflowLogger);
|
|
70
|
+
constructor(context: WorkflowContext, steps: Step[], telemetry?: Telemetry, debug?: WorkflowLogger);
|
|
70
71
|
/**
|
|
71
72
|
* Adds the step function to the list of step functions to run in
|
|
72
73
|
* parallel. After adding the function, defers the execution, so
|
|
@@ -162,6 +163,230 @@ declare class AutoExecutor {
|
|
|
162
163
|
private deferExecution;
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
167
|
+
|
|
168
|
+
type ProviderInfo = {
|
|
169
|
+
/**
|
|
170
|
+
* full url used for request
|
|
171
|
+
*/
|
|
172
|
+
url: string;
|
|
173
|
+
/**
|
|
174
|
+
* base url of the request
|
|
175
|
+
*/
|
|
176
|
+
baseUrl: string;
|
|
177
|
+
/**
|
|
178
|
+
* route elements which will follow the baseUrl
|
|
179
|
+
*/
|
|
180
|
+
route: string[];
|
|
181
|
+
/**
|
|
182
|
+
* headers to include in the request
|
|
183
|
+
*/
|
|
184
|
+
appendHeaders: Record<string, string>;
|
|
185
|
+
/**
|
|
186
|
+
* provider owner
|
|
187
|
+
*/
|
|
188
|
+
owner: Owner;
|
|
189
|
+
/**
|
|
190
|
+
* method to use in the request
|
|
191
|
+
*/
|
|
192
|
+
method: HTTPMethods;
|
|
193
|
+
};
|
|
194
|
+
type Owner = EmailOwner | LLMOwner;
|
|
195
|
+
/**
|
|
196
|
+
* Email
|
|
197
|
+
*/
|
|
198
|
+
type EmailOwner = "resend";
|
|
199
|
+
/**
|
|
200
|
+
* LLM
|
|
201
|
+
*/
|
|
202
|
+
type LLMOwner = "upstash" | "openai" | "anthropic" | "custom";
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* copies and updates the request by removing the api field and adding url & headers.
|
|
206
|
+
*
|
|
207
|
+
* @param api api field of PublishRequest
|
|
208
|
+
* @returns updated request
|
|
209
|
+
*/
|
|
210
|
+
declare const getProviderInfo: (api: Required<PublishRequest>["api"]) => ProviderInfo;
|
|
211
|
+
|
|
212
|
+
type ApiCallSettings<TBody = unknown, TFields extends object = object> = Omit<CallSettings<TBody>, "url"> & TFields;
|
|
213
|
+
declare abstract class BaseWorkflowApi {
|
|
214
|
+
protected context: WorkflowContext;
|
|
215
|
+
constructor({ context }: {
|
|
216
|
+
context: WorkflowContext;
|
|
217
|
+
});
|
|
218
|
+
/**
|
|
219
|
+
* context.call which uses a QStash API
|
|
220
|
+
*
|
|
221
|
+
* @param stepName
|
|
222
|
+
* @param settings
|
|
223
|
+
* @returns
|
|
224
|
+
*/
|
|
225
|
+
protected callApi<TResult = unknown, TBody = unknown>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
226
|
+
api: Parameters<typeof getProviderInfo>[0];
|
|
227
|
+
}>): Promise<CallResponse<TResult>>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type CreateChatCompletion$1 = {
|
|
231
|
+
model: string;
|
|
232
|
+
messages: {
|
|
233
|
+
role: "user" | "assistant";
|
|
234
|
+
content: unknown;
|
|
235
|
+
}[];
|
|
236
|
+
max_tokens: number;
|
|
237
|
+
metadata?: object;
|
|
238
|
+
stop_sequences?: string[];
|
|
239
|
+
/**
|
|
240
|
+
* streaming is not possible Upstash Workflow.
|
|
241
|
+
*/
|
|
242
|
+
stream?: false;
|
|
243
|
+
system?: string;
|
|
244
|
+
temparature?: number;
|
|
245
|
+
top_k?: number;
|
|
246
|
+
top_p?: number;
|
|
247
|
+
};
|
|
248
|
+
type ChatCompletion$1 = {
|
|
249
|
+
id: string;
|
|
250
|
+
type: "message";
|
|
251
|
+
role: "assistant";
|
|
252
|
+
content: {
|
|
253
|
+
type: "text";
|
|
254
|
+
text: string;
|
|
255
|
+
}[];
|
|
256
|
+
model: string;
|
|
257
|
+
stop_reasong: string;
|
|
258
|
+
stop_sequence: string[];
|
|
259
|
+
usage: unknown;
|
|
260
|
+
};
|
|
261
|
+
declare class AnthropicAPI extends BaseWorkflowApi {
|
|
262
|
+
call<TResult = ChatCompletion$1, TBody = CreateChatCompletion$1>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
263
|
+
token: string;
|
|
264
|
+
operation: "messages.create";
|
|
265
|
+
}>): Promise<CallResponse<TResult>>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
type Messages = {
|
|
269
|
+
content: string;
|
|
270
|
+
role: "developer" | "system";
|
|
271
|
+
name?: string;
|
|
272
|
+
} | {
|
|
273
|
+
content: unknown;
|
|
274
|
+
role: "user";
|
|
275
|
+
name?: string;
|
|
276
|
+
} | {
|
|
277
|
+
content: unknown;
|
|
278
|
+
refusal?: string;
|
|
279
|
+
role: "assistant";
|
|
280
|
+
name?: string;
|
|
281
|
+
audio?: unknown;
|
|
282
|
+
tool_calls?: unknown;
|
|
283
|
+
} | {
|
|
284
|
+
role: "tool";
|
|
285
|
+
content: string | unknown;
|
|
286
|
+
tool_call_id: string;
|
|
287
|
+
} | {
|
|
288
|
+
role: "function";
|
|
289
|
+
content: string | undefined;
|
|
290
|
+
name: string;
|
|
291
|
+
};
|
|
292
|
+
type CreateChatCompletion = {
|
|
293
|
+
messages: Messages[];
|
|
294
|
+
model: string;
|
|
295
|
+
store?: boolean;
|
|
296
|
+
reasoning_effort?: string;
|
|
297
|
+
metadata?: unknown;
|
|
298
|
+
frequency_penalty?: number;
|
|
299
|
+
logit_bias?: Record<string, number>;
|
|
300
|
+
logprobs?: boolean;
|
|
301
|
+
top_logprobs?: number;
|
|
302
|
+
max_completion_tokens?: number;
|
|
303
|
+
n?: number;
|
|
304
|
+
modalities?: string[];
|
|
305
|
+
prediction?: unknown;
|
|
306
|
+
audio?: unknown;
|
|
307
|
+
presence_penalty?: number;
|
|
308
|
+
response_format?: unknown;
|
|
309
|
+
seed?: number;
|
|
310
|
+
service_tier?: string;
|
|
311
|
+
stop?: string | string[];
|
|
312
|
+
/**
|
|
313
|
+
* streaming is not supported in Upstash Workflow.
|
|
314
|
+
*/
|
|
315
|
+
stream?: false;
|
|
316
|
+
temperature?: number;
|
|
317
|
+
top_p?: number;
|
|
318
|
+
tools?: unknown;
|
|
319
|
+
tool_choice?: string;
|
|
320
|
+
parallel_tool_calls?: boolean;
|
|
321
|
+
user?: string;
|
|
322
|
+
};
|
|
323
|
+
type ChatCompletion = {
|
|
324
|
+
id: string;
|
|
325
|
+
choices: ChatCompletionChoice[];
|
|
326
|
+
created: number;
|
|
327
|
+
model: string;
|
|
328
|
+
object: "chat.completion";
|
|
329
|
+
service_tier?: "scale" | "default" | null;
|
|
330
|
+
system_fingerprint?: string;
|
|
331
|
+
usage?: unknown;
|
|
332
|
+
};
|
|
333
|
+
type ChatCompletionChoice = {
|
|
334
|
+
finish_reason: "stop" | "length" | "tool_calls" | "content_filter" | "function_call";
|
|
335
|
+
index: number;
|
|
336
|
+
logprobs: unknown;
|
|
337
|
+
message: {
|
|
338
|
+
content: string | null;
|
|
339
|
+
refusal: string | null;
|
|
340
|
+
role: "assistant";
|
|
341
|
+
audio?: unknown;
|
|
342
|
+
tool_calls?: unknown;
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
declare class OpenAIAPI extends BaseWorkflowApi {
|
|
346
|
+
call<TResult = ChatCompletion, TBody = CreateChatCompletion>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
347
|
+
token: string;
|
|
348
|
+
organization?: string;
|
|
349
|
+
operation: "chat.completions.create";
|
|
350
|
+
}>): Promise<CallResponse<TResult>>;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
type SendEmail = {
|
|
354
|
+
from: string;
|
|
355
|
+
to: string;
|
|
356
|
+
subject: string;
|
|
357
|
+
bcc?: string | string[];
|
|
358
|
+
cc?: string | string[];
|
|
359
|
+
scheduled_at?: string;
|
|
360
|
+
reply_to?: string | string[];
|
|
361
|
+
html?: string;
|
|
362
|
+
text?: string;
|
|
363
|
+
headers: unknown;
|
|
364
|
+
attachments: unknown;
|
|
365
|
+
tags: {
|
|
366
|
+
name: string;
|
|
367
|
+
value: string;
|
|
368
|
+
}[];
|
|
369
|
+
};
|
|
370
|
+
type SendEmailResponse = {
|
|
371
|
+
id: string;
|
|
372
|
+
};
|
|
373
|
+
type SendBatchEmail = SendEmail[];
|
|
374
|
+
type SendBatchEmailResponse = {
|
|
375
|
+
data: SendEmailResponse[];
|
|
376
|
+
};
|
|
377
|
+
declare class ResendAPI extends BaseWorkflowApi {
|
|
378
|
+
call<TBatch extends boolean = false, TResult = TBatch extends true ? SendBatchEmailResponse : SendEmailResponse, TBody = TBatch extends true ? SendBatchEmail : SendEmail>(stepName: string, settings: ApiCallSettings<TBody, {
|
|
379
|
+
token: string;
|
|
380
|
+
batch?: TBatch;
|
|
381
|
+
}>): Promise<CallResponse<TResult>>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
declare class WorkflowApi extends BaseWorkflowApi {
|
|
385
|
+
get openai(): OpenAIAPI;
|
|
386
|
+
get resend(): ResendAPI;
|
|
387
|
+
get anthropic(): AnthropicAPI;
|
|
388
|
+
}
|
|
389
|
+
|
|
165
390
|
/**
|
|
166
391
|
* Upstash Workflow context
|
|
167
392
|
*
|
|
@@ -288,7 +513,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
288
513
|
* Number of retries
|
|
289
514
|
*/
|
|
290
515
|
readonly retries: number;
|
|
291
|
-
constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, }: {
|
|
516
|
+
constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, env, retries, telemetry, }: {
|
|
292
517
|
qstashClient: WorkflowClient;
|
|
293
518
|
workflowRunId: string;
|
|
294
519
|
headers: Headers;
|
|
@@ -299,6 +524,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
299
524
|
initialPayload: TInitialPayload;
|
|
300
525
|
env?: Record<string, string | undefined>;
|
|
301
526
|
retries?: number;
|
|
527
|
+
telemetry?: Telemetry;
|
|
302
528
|
});
|
|
303
529
|
/**
|
|
304
530
|
* Executes a workflow step
|
|
@@ -385,14 +611,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
385
611
|
* header: Record<string, string[]>
|
|
386
612
|
* }
|
|
387
613
|
*/
|
|
388
|
-
call<TResult = unknown>(stepName: string, settings:
|
|
389
|
-
url: string;
|
|
390
|
-
method?: HTTPMethods;
|
|
391
|
-
body?: unknown;
|
|
392
|
-
headers?: Record<string, string>;
|
|
393
|
-
retries?: number;
|
|
394
|
-
timeout?: Duration | number;
|
|
395
|
-
}): Promise<CallResponse<TResult>>;
|
|
614
|
+
call<TResult = unknown, TBody = unknown>(stepName: string, settings: CallSettings<TBody>): Promise<CallResponse<TResult>>;
|
|
396
615
|
/**
|
|
397
616
|
* Pauses workflow execution until a specific event occurs or a timeout is reached.
|
|
398
617
|
*
|
|
@@ -462,6 +681,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
|
|
|
462
681
|
* DisabledWorkflowContext.
|
|
463
682
|
*/
|
|
464
683
|
protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
|
|
684
|
+
get api(): WorkflowApi;
|
|
465
685
|
}
|
|
466
686
|
|
|
467
687
|
/**
|
|
@@ -493,7 +713,7 @@ type ThirdPartyCallFields<TBody = unknown> = {
|
|
|
493
713
|
/**
|
|
494
714
|
* Third party call method. Set when context.call is used.
|
|
495
715
|
*/
|
|
496
|
-
callMethod: HTTPMethods;
|
|
716
|
+
callMethod: HTTPMethods$1;
|
|
497
717
|
/**
|
|
498
718
|
* Third party call body. Set when context.call is used.
|
|
499
719
|
*/
|
|
@@ -620,7 +840,7 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
620
840
|
* @returns void
|
|
621
841
|
*/
|
|
622
842
|
failureFunction?: (failureData: {
|
|
623
|
-
context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify">;
|
|
843
|
+
context: Omit<WorkflowContext<TInitialPayload>, "run" | "sleepUntil" | "sleep" | "call" | "waitForEvent" | "notify" | "cancel" | "api">;
|
|
624
844
|
failStatus: number;
|
|
625
845
|
failResponse: string;
|
|
626
846
|
failHeaders: Record<string, string[]>;
|
|
@@ -658,6 +878,26 @@ type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload
|
|
|
658
878
|
* Not part of the public API. Only available in serveBase, which is not exported.
|
|
659
879
|
*/
|
|
660
880
|
useJSONContent?: boolean;
|
|
881
|
+
/**
|
|
882
|
+
* By default, Workflow SDK sends telemetry about SDK version, framework or runtime.
|
|
883
|
+
*
|
|
884
|
+
* Set `disableTelemetry` to disable this behavior.
|
|
885
|
+
*/
|
|
886
|
+
disableTelemetry?: boolean;
|
|
887
|
+
};
|
|
888
|
+
type Telemetry = {
|
|
889
|
+
/**
|
|
890
|
+
* sdk version
|
|
891
|
+
*/
|
|
892
|
+
sdk: string;
|
|
893
|
+
/**
|
|
894
|
+
* platform (such as nextjs/cloudflare)
|
|
895
|
+
*/
|
|
896
|
+
framework: string;
|
|
897
|
+
/**
|
|
898
|
+
* node version
|
|
899
|
+
*/
|
|
900
|
+
runtime?: string;
|
|
661
901
|
};
|
|
662
902
|
type PublicServeOptions<TInitialPayload = unknown, TResponse extends Response = Response> = Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "onStepFinish" | "useJSONContent">;
|
|
663
903
|
/**
|
|
@@ -745,5 +985,76 @@ interface WaitEventOptions {
|
|
|
745
985
|
*/
|
|
746
986
|
timeout?: number | Duration;
|
|
747
987
|
}
|
|
988
|
+
type CallSettings<TBody = unknown> = {
|
|
989
|
+
url: string;
|
|
990
|
+
method?: HTTPMethods$1;
|
|
991
|
+
body?: TBody;
|
|
992
|
+
headers?: Record<string, string>;
|
|
993
|
+
retries?: number;
|
|
994
|
+
timeout?: Duration | number;
|
|
995
|
+
};
|
|
996
|
+
type HeaderParams = {
|
|
997
|
+
/**
|
|
998
|
+
* whether the request is a first invocation request.
|
|
999
|
+
*/
|
|
1000
|
+
initHeaderValue: "true" | "false";
|
|
1001
|
+
/**
|
|
1002
|
+
* run id of the workflow
|
|
1003
|
+
*/
|
|
1004
|
+
workflowRunId: string;
|
|
1005
|
+
/**
|
|
1006
|
+
* url where the workflow is hosted
|
|
1007
|
+
*/
|
|
1008
|
+
workflowUrl: string;
|
|
1009
|
+
/**
|
|
1010
|
+
* user headers which will be forwarded in the request
|
|
1011
|
+
*/
|
|
1012
|
+
userHeaders?: Headers;
|
|
1013
|
+
/**
|
|
1014
|
+
* failure url to call incase of failure
|
|
1015
|
+
*/
|
|
1016
|
+
failureUrl?: WorkflowServeOptions["failureUrl"];
|
|
1017
|
+
/**
|
|
1018
|
+
* retry setting of requests except context.call
|
|
1019
|
+
*/
|
|
1020
|
+
retries?: number;
|
|
1021
|
+
/**
|
|
1022
|
+
* telemetry to include in timeoutHeaders.
|
|
1023
|
+
*
|
|
1024
|
+
* Only needed/used when the step is a waitForEvent step
|
|
1025
|
+
*/
|
|
1026
|
+
telemetry?: Telemetry;
|
|
1027
|
+
} & ({
|
|
1028
|
+
/**
|
|
1029
|
+
* step to generate headers for
|
|
1030
|
+
*/
|
|
1031
|
+
step: Step;
|
|
1032
|
+
/**
|
|
1033
|
+
* number of retries in context.call
|
|
1034
|
+
*/
|
|
1035
|
+
callRetries?: number;
|
|
1036
|
+
/**
|
|
1037
|
+
* timeout duration in context.call
|
|
1038
|
+
*/
|
|
1039
|
+
callTimeout?: number | Duration;
|
|
1040
|
+
} | {
|
|
1041
|
+
/**
|
|
1042
|
+
* step not passed. Either first invocation or simply getting headers for
|
|
1043
|
+
* third party callack.
|
|
1044
|
+
*/
|
|
1045
|
+
step?: never;
|
|
1046
|
+
/**
|
|
1047
|
+
* number of retries in context.call
|
|
1048
|
+
*
|
|
1049
|
+
* set to never because this is not a context.call step
|
|
1050
|
+
*/
|
|
1051
|
+
callRetries?: never;
|
|
1052
|
+
/**
|
|
1053
|
+
* timeout duration in context.call
|
|
1054
|
+
*
|
|
1055
|
+
* set to never because this is not a context.call step
|
|
1056
|
+
*/
|
|
1057
|
+
callTimeout?: never;
|
|
1058
|
+
});
|
|
748
1059
|
|
|
749
|
-
export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type FinishCondition as F, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type
|
|
1060
|
+
export { type AsyncStepFunction as A, type CallResponse as C, type Duration as D, type FinishCondition as F, type HeaderParams as H, type LogLevel as L, type NotifyResponse as N, type ParallelCallState as P, type RouteFunction as R, type Step as S, type Telemetry as T, type WorkflowServeOptions as W, type Waiter as a, WorkflowContext as b, type WorkflowClient as c, type WorkflowReceiver as d, StepTypes as e, type StepType as f, type RawStep as g, type SyncStepFunction as h, type StepFunction as i, type PublicServeOptions as j, type FailureFunctionPayload as k, type RequiredExceptFields as l, type WaitRequest as m, type WaitStepResponse as n, type NotifyStepResponse as o, type WaitEventOptions as p, type CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };
|