@upstash/workflow 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { HTTPMethods, Client, Receiver } from '@upstash/qstash';
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)
@@ -162,6 +162,230 @@ declare class AutoExecutor {
162
162
  private deferExecution;
163
163
  }
164
164
 
165
+ type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
166
+
167
+ type ProviderInfo = {
168
+ /**
169
+ * full url used for request
170
+ */
171
+ url: string;
172
+ /**
173
+ * base url of the request
174
+ */
175
+ baseUrl: string;
176
+ /**
177
+ * route elements which will follow the baseUrl
178
+ */
179
+ route: string[];
180
+ /**
181
+ * headers to include in the request
182
+ */
183
+ appendHeaders: Record<string, string>;
184
+ /**
185
+ * provider owner
186
+ */
187
+ owner: Owner;
188
+ /**
189
+ * method to use in the request
190
+ */
191
+ method: HTTPMethods;
192
+ };
193
+ type Owner = EmailOwner | LLMOwner;
194
+ /**
195
+ * Email
196
+ */
197
+ type EmailOwner = "resend";
198
+ /**
199
+ * LLM
200
+ */
201
+ type LLMOwner = "upstash" | "openai" | "anthropic" | "custom";
202
+
203
+ /**
204
+ * copies and updates the request by removing the api field and adding url & headers.
205
+ *
206
+ * @param api api field of PublishRequest
207
+ * @returns updated request
208
+ */
209
+ declare const getProviderInfo: (api: Required<PublishRequest>["api"]) => ProviderInfo;
210
+
211
+ type ApiCallSettings<TBody = unknown, TFields extends object = object> = Omit<CallSettings<TBody>, "url"> & TFields;
212
+ declare abstract class BaseWorkflowApi {
213
+ protected context: WorkflowContext;
214
+ constructor({ context }: {
215
+ context: WorkflowContext;
216
+ });
217
+ /**
218
+ * context.call which uses a QStash API
219
+ *
220
+ * @param stepName
221
+ * @param settings
222
+ * @returns
223
+ */
224
+ protected callApi<TResult = unknown, TBody = unknown>(stepName: string, settings: ApiCallSettings<TBody, {
225
+ api: Parameters<typeof getProviderInfo>[0];
226
+ }>): Promise<CallResponse<TResult>>;
227
+ }
228
+
229
+ type CreateChatCompletion$1 = {
230
+ model: string;
231
+ messages: {
232
+ role: "user" | "assistant";
233
+ content: unknown;
234
+ }[];
235
+ max_tokens: number;
236
+ metadata?: object;
237
+ stop_sequences?: string[];
238
+ /**
239
+ * streaming is not possible Upstash Workflow.
240
+ */
241
+ stream?: false;
242
+ system?: string;
243
+ temparature?: number;
244
+ top_k?: number;
245
+ top_p?: number;
246
+ };
247
+ type ChatCompletion$1 = {
248
+ id: string;
249
+ type: "message";
250
+ role: "assistant";
251
+ content: {
252
+ type: "text";
253
+ text: string;
254
+ }[];
255
+ model: string;
256
+ stop_reasong: string;
257
+ stop_sequence: string[];
258
+ usage: unknown;
259
+ };
260
+ declare class AnthropicAPI extends BaseWorkflowApi {
261
+ call<TResult = ChatCompletion$1, TBody = CreateChatCompletion$1>(stepName: string, settings: ApiCallSettings<TBody, {
262
+ token: string;
263
+ operation: "messages.create";
264
+ }>): Promise<CallResponse<TResult>>;
265
+ }
266
+
267
+ type Messages = {
268
+ content: string;
269
+ role: "developer" | "system";
270
+ name?: string;
271
+ } | {
272
+ content: unknown;
273
+ role: "user";
274
+ name?: string;
275
+ } | {
276
+ content: unknown;
277
+ refusal?: string;
278
+ role: "assistant";
279
+ name?: string;
280
+ audio?: unknown;
281
+ tool_calls?: unknown;
282
+ } | {
283
+ role: "tool";
284
+ content: string | unknown;
285
+ tool_call_id: string;
286
+ } | {
287
+ role: "function";
288
+ content: string | undefined;
289
+ name: string;
290
+ };
291
+ type CreateChatCompletion = {
292
+ messages: Messages[];
293
+ model: string;
294
+ store?: boolean;
295
+ reasoning_effort?: string;
296
+ metadata?: unknown;
297
+ frequency_penalty?: number;
298
+ logit_bias?: Record<string, number>;
299
+ logprobs?: boolean;
300
+ top_logprobs?: number;
301
+ max_completion_tokens?: number;
302
+ n?: number;
303
+ modalities?: string[];
304
+ prediction?: unknown;
305
+ audio?: unknown;
306
+ presence_penalty?: number;
307
+ response_format?: unknown;
308
+ seed?: number;
309
+ service_tier?: string;
310
+ stop?: string | string[];
311
+ /**
312
+ * streaming is not supported in Upstash Workflow.
313
+ */
314
+ stream?: false;
315
+ temperature?: number;
316
+ top_p?: number;
317
+ tools?: unknown;
318
+ tool_choice?: string;
319
+ parallel_tool_calls?: boolean;
320
+ user?: string;
321
+ };
322
+ type ChatCompletion = {
323
+ id: string;
324
+ choices: ChatCompletionChoice[];
325
+ created: number;
326
+ model: string;
327
+ object: "chat.completion";
328
+ service_tier?: "scale" | "default" | null;
329
+ system_fingerprint?: string;
330
+ usage?: unknown;
331
+ };
332
+ type ChatCompletionChoice = {
333
+ finish_reason: "stop" | "length" | "tool_calls" | "content_filter" | "function_call";
334
+ index: number;
335
+ logprobs: unknown;
336
+ message: {
337
+ content: string | null;
338
+ refusal: string | null;
339
+ role: "assistant";
340
+ audio?: unknown;
341
+ tool_calls?: unknown;
342
+ };
343
+ };
344
+ declare class OpenAIAPI extends BaseWorkflowApi {
345
+ call<TResult = ChatCompletion, TBody = CreateChatCompletion>(stepName: string, settings: ApiCallSettings<TBody, {
346
+ token: string;
347
+ organization?: string;
348
+ operation: "chat.completions.create";
349
+ }>): Promise<CallResponse<TResult>>;
350
+ }
351
+
352
+ type SendEmail = {
353
+ from: string;
354
+ to: string;
355
+ subject: string;
356
+ bcc?: string | string[];
357
+ cc?: string | string[];
358
+ scheduled_at?: string;
359
+ reply_to?: string | string[];
360
+ html?: string;
361
+ text?: string;
362
+ headers: unknown;
363
+ attachments: unknown;
364
+ tags: {
365
+ name: string;
366
+ value: string;
367
+ }[];
368
+ };
369
+ type SendEmailResponse = {
370
+ id: string;
371
+ };
372
+ type SendBatchEmail = SendEmail[];
373
+ type SendBatchEmailResponse = {
374
+ data: SendEmailResponse[];
375
+ };
376
+ declare class ResendAPI extends BaseWorkflowApi {
377
+ call<TBatch extends boolean = false, TResult = TBatch extends true ? SendBatchEmailResponse : SendEmailResponse, TBody = TBatch extends true ? SendBatchEmail : SendEmail>(stepName: string, settings: ApiCallSettings<TBody, {
378
+ token: string;
379
+ batch?: TBatch;
380
+ }>): Promise<CallResponse<TResult>>;
381
+ }
382
+
383
+ declare class WorkflowApi extends BaseWorkflowApi {
384
+ get openai(): OpenAIAPI;
385
+ get resend(): ResendAPI;
386
+ get anthropic(): AnthropicAPI;
387
+ }
388
+
165
389
  /**
166
390
  * Upstash Workflow context
167
391
  *
@@ -385,14 +609,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
385
609
  * header: Record<string, string[]>
386
610
  * }
387
611
  */
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>>;
612
+ call<TResult = unknown, TBody = unknown>(stepName: string, settings: CallSettings<TBody>): Promise<CallResponse<TResult>>;
396
613
  /**
397
614
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
398
615
  *
@@ -462,6 +679,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
462
679
  * DisabledWorkflowContext.
463
680
  */
464
681
  protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
682
+ get api(): WorkflowApi;
465
683
  }
466
684
 
467
685
  /**
@@ -493,7 +711,7 @@ type ThirdPartyCallFields<TBody = unknown> = {
493
711
  /**
494
712
  * Third party call method. Set when context.call is used.
495
713
  */
496
- callMethod: HTTPMethods;
714
+ callMethod: HTTPMethods$1;
497
715
  /**
498
716
  * Third party call body. Set when context.call is used.
499
717
  */
@@ -745,5 +963,13 @@ interface WaitEventOptions {
745
963
  */
746
964
  timeout?: number | Duration;
747
965
  }
966
+ type CallSettings<TBody = unknown> = {
967
+ url: string;
968
+ method?: HTTPMethods$1;
969
+ body?: TBody;
970
+ headers?: Record<string, string>;
971
+ retries?: number;
972
+ timeout?: Duration | number;
973
+ };
748
974
 
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 WorkflowLoggerOptions as q, WorkflowLogger as r };
975
+ 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 CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };
@@ -1,4 +1,4 @@
1
- import { HTTPMethods, Client, Receiver } from '@upstash/qstash';
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)
@@ -162,6 +162,230 @@ declare class AutoExecutor {
162
162
  private deferExecution;
163
163
  }
164
164
 
165
+ type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
166
+
167
+ type ProviderInfo = {
168
+ /**
169
+ * full url used for request
170
+ */
171
+ url: string;
172
+ /**
173
+ * base url of the request
174
+ */
175
+ baseUrl: string;
176
+ /**
177
+ * route elements which will follow the baseUrl
178
+ */
179
+ route: string[];
180
+ /**
181
+ * headers to include in the request
182
+ */
183
+ appendHeaders: Record<string, string>;
184
+ /**
185
+ * provider owner
186
+ */
187
+ owner: Owner;
188
+ /**
189
+ * method to use in the request
190
+ */
191
+ method: HTTPMethods;
192
+ };
193
+ type Owner = EmailOwner | LLMOwner;
194
+ /**
195
+ * Email
196
+ */
197
+ type EmailOwner = "resend";
198
+ /**
199
+ * LLM
200
+ */
201
+ type LLMOwner = "upstash" | "openai" | "anthropic" | "custom";
202
+
203
+ /**
204
+ * copies and updates the request by removing the api field and adding url & headers.
205
+ *
206
+ * @param api api field of PublishRequest
207
+ * @returns updated request
208
+ */
209
+ declare const getProviderInfo: (api: Required<PublishRequest>["api"]) => ProviderInfo;
210
+
211
+ type ApiCallSettings<TBody = unknown, TFields extends object = object> = Omit<CallSettings<TBody>, "url"> & TFields;
212
+ declare abstract class BaseWorkflowApi {
213
+ protected context: WorkflowContext;
214
+ constructor({ context }: {
215
+ context: WorkflowContext;
216
+ });
217
+ /**
218
+ * context.call which uses a QStash API
219
+ *
220
+ * @param stepName
221
+ * @param settings
222
+ * @returns
223
+ */
224
+ protected callApi<TResult = unknown, TBody = unknown>(stepName: string, settings: ApiCallSettings<TBody, {
225
+ api: Parameters<typeof getProviderInfo>[0];
226
+ }>): Promise<CallResponse<TResult>>;
227
+ }
228
+
229
+ type CreateChatCompletion$1 = {
230
+ model: string;
231
+ messages: {
232
+ role: "user" | "assistant";
233
+ content: unknown;
234
+ }[];
235
+ max_tokens: number;
236
+ metadata?: object;
237
+ stop_sequences?: string[];
238
+ /**
239
+ * streaming is not possible Upstash Workflow.
240
+ */
241
+ stream?: false;
242
+ system?: string;
243
+ temparature?: number;
244
+ top_k?: number;
245
+ top_p?: number;
246
+ };
247
+ type ChatCompletion$1 = {
248
+ id: string;
249
+ type: "message";
250
+ role: "assistant";
251
+ content: {
252
+ type: "text";
253
+ text: string;
254
+ }[];
255
+ model: string;
256
+ stop_reasong: string;
257
+ stop_sequence: string[];
258
+ usage: unknown;
259
+ };
260
+ declare class AnthropicAPI extends BaseWorkflowApi {
261
+ call<TResult = ChatCompletion$1, TBody = CreateChatCompletion$1>(stepName: string, settings: ApiCallSettings<TBody, {
262
+ token: string;
263
+ operation: "messages.create";
264
+ }>): Promise<CallResponse<TResult>>;
265
+ }
266
+
267
+ type Messages = {
268
+ content: string;
269
+ role: "developer" | "system";
270
+ name?: string;
271
+ } | {
272
+ content: unknown;
273
+ role: "user";
274
+ name?: string;
275
+ } | {
276
+ content: unknown;
277
+ refusal?: string;
278
+ role: "assistant";
279
+ name?: string;
280
+ audio?: unknown;
281
+ tool_calls?: unknown;
282
+ } | {
283
+ role: "tool";
284
+ content: string | unknown;
285
+ tool_call_id: string;
286
+ } | {
287
+ role: "function";
288
+ content: string | undefined;
289
+ name: string;
290
+ };
291
+ type CreateChatCompletion = {
292
+ messages: Messages[];
293
+ model: string;
294
+ store?: boolean;
295
+ reasoning_effort?: string;
296
+ metadata?: unknown;
297
+ frequency_penalty?: number;
298
+ logit_bias?: Record<string, number>;
299
+ logprobs?: boolean;
300
+ top_logprobs?: number;
301
+ max_completion_tokens?: number;
302
+ n?: number;
303
+ modalities?: string[];
304
+ prediction?: unknown;
305
+ audio?: unknown;
306
+ presence_penalty?: number;
307
+ response_format?: unknown;
308
+ seed?: number;
309
+ service_tier?: string;
310
+ stop?: string | string[];
311
+ /**
312
+ * streaming is not supported in Upstash Workflow.
313
+ */
314
+ stream?: false;
315
+ temperature?: number;
316
+ top_p?: number;
317
+ tools?: unknown;
318
+ tool_choice?: string;
319
+ parallel_tool_calls?: boolean;
320
+ user?: string;
321
+ };
322
+ type ChatCompletion = {
323
+ id: string;
324
+ choices: ChatCompletionChoice[];
325
+ created: number;
326
+ model: string;
327
+ object: "chat.completion";
328
+ service_tier?: "scale" | "default" | null;
329
+ system_fingerprint?: string;
330
+ usage?: unknown;
331
+ };
332
+ type ChatCompletionChoice = {
333
+ finish_reason: "stop" | "length" | "tool_calls" | "content_filter" | "function_call";
334
+ index: number;
335
+ logprobs: unknown;
336
+ message: {
337
+ content: string | null;
338
+ refusal: string | null;
339
+ role: "assistant";
340
+ audio?: unknown;
341
+ tool_calls?: unknown;
342
+ };
343
+ };
344
+ declare class OpenAIAPI extends BaseWorkflowApi {
345
+ call<TResult = ChatCompletion, TBody = CreateChatCompletion>(stepName: string, settings: ApiCallSettings<TBody, {
346
+ token: string;
347
+ organization?: string;
348
+ operation: "chat.completions.create";
349
+ }>): Promise<CallResponse<TResult>>;
350
+ }
351
+
352
+ type SendEmail = {
353
+ from: string;
354
+ to: string;
355
+ subject: string;
356
+ bcc?: string | string[];
357
+ cc?: string | string[];
358
+ scheduled_at?: string;
359
+ reply_to?: string | string[];
360
+ html?: string;
361
+ text?: string;
362
+ headers: unknown;
363
+ attachments: unknown;
364
+ tags: {
365
+ name: string;
366
+ value: string;
367
+ }[];
368
+ };
369
+ type SendEmailResponse = {
370
+ id: string;
371
+ };
372
+ type SendBatchEmail = SendEmail[];
373
+ type SendBatchEmailResponse = {
374
+ data: SendEmailResponse[];
375
+ };
376
+ declare class ResendAPI extends BaseWorkflowApi {
377
+ call<TBatch extends boolean = false, TResult = TBatch extends true ? SendBatchEmailResponse : SendEmailResponse, TBody = TBatch extends true ? SendBatchEmail : SendEmail>(stepName: string, settings: ApiCallSettings<TBody, {
378
+ token: string;
379
+ batch?: TBatch;
380
+ }>): Promise<CallResponse<TResult>>;
381
+ }
382
+
383
+ declare class WorkflowApi extends BaseWorkflowApi {
384
+ get openai(): OpenAIAPI;
385
+ get resend(): ResendAPI;
386
+ get anthropic(): AnthropicAPI;
387
+ }
388
+
165
389
  /**
166
390
  * Upstash Workflow context
167
391
  *
@@ -385,14 +609,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
385
609
  * header: Record<string, string[]>
386
610
  * }
387
611
  */
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>>;
612
+ call<TResult = unknown, TBody = unknown>(stepName: string, settings: CallSettings<TBody>): Promise<CallResponse<TResult>>;
396
613
  /**
397
614
  * Pauses workflow execution until a specific event occurs or a timeout is reached.
398
615
  *
@@ -462,6 +679,7 @@ declare class WorkflowContext<TInitialPayload = unknown> {
462
679
  * DisabledWorkflowContext.
463
680
  */
464
681
  protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
682
+ get api(): WorkflowApi;
465
683
  }
466
684
 
467
685
  /**
@@ -493,7 +711,7 @@ type ThirdPartyCallFields<TBody = unknown> = {
493
711
  /**
494
712
  * Third party call method. Set when context.call is used.
495
713
  */
496
- callMethod: HTTPMethods;
714
+ callMethod: HTTPMethods$1;
497
715
  /**
498
716
  * Third party call body. Set when context.call is used.
499
717
  */
@@ -745,5 +963,13 @@ interface WaitEventOptions {
745
963
  */
746
964
  timeout?: number | Duration;
747
965
  }
966
+ type CallSettings<TBody = unknown> = {
967
+ url: string;
968
+ method?: HTTPMethods$1;
969
+ body?: TBody;
970
+ headers?: Record<string, string>;
971
+ retries?: number;
972
+ timeout?: Duration | number;
973
+ };
748
974
 
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 WorkflowLoggerOptions as q, WorkflowLogger as r };
975
+ 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 CallSettings as q, type WorkflowLoggerOptions as r, WorkflowLogger as s };