@upstash/qstash 2.6.4-workflow-alpha.0 → 2.6.4-workflow-alpha.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.
@@ -1,1515 +0,0 @@
1
- import { Ok, Err } from 'neverthrow';
2
-
3
- /**
4
- * Necessary to verify the signature of a request.
5
- */
6
- type ReceiverConfig = {
7
- /**
8
- * The current signing key. Get it from `https://console.upstash.com/qstash
9
- */
10
- currentSigningKey: string;
11
- /**
12
- * The next signing key. Get it from `https://console.upstash.com/qstash
13
- */
14
- nextSigningKey: string;
15
- };
16
- type VerifyRequest = {
17
- /**
18
- * The signature from the `upstash-signature` header.
19
- */
20
- signature: string;
21
- /**
22
- * The raw request body.
23
- */
24
- body: string;
25
- /**
26
- * URL of the endpoint where the request was sent to.
27
- *
28
- * Omit empty to disable checking the url.
29
- */
30
- url?: string;
31
- /**
32
- * Number of seconds to tolerate when checking `nbf` and `exp` claims, to deal with small clock differences among different servers
33
- *
34
- * @default 0
35
- */
36
- clockTolerance?: number;
37
- };
38
- declare class SignatureError extends Error {
39
- constructor(message: string);
40
- }
41
- /**
42
- * Receiver offers a simple way to verify the signature of a request.
43
- */
44
- declare class Receiver {
45
- private readonly currentSigningKey;
46
- private readonly nextSigningKey;
47
- constructor(config: ReceiverConfig);
48
- /**
49
- * Verify the signature of a request.
50
- *
51
- * Tries to verify the signature with the current signing key.
52
- * If that fails, maybe because you have rotated the keys recently, it will
53
- * try to verify the signature with the next signing key.
54
- *
55
- * If that fails, the signature is invalid and a `SignatureError` is thrown.
56
- */
57
- verify(request: VerifyRequest): Promise<boolean>;
58
- /**
59
- * Verify signature with a specific signing key
60
- */
61
- private verifyWithKey;
62
- }
63
-
64
- type State = "CREATED" | "ACTIVE" | "DELIVERED" | "ERROR" | "RETRY" | "FAILED";
65
- type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
66
- type Event = {
67
- time: number;
68
- state: State;
69
- messageId: string;
70
- nextDeliveryTime?: number;
71
- error?: string;
72
- url: string;
73
- urlGroup?: string;
74
- topicName?: string;
75
- endpointName?: string;
76
- header?: Record<string, string>;
77
- body?: string;
78
- };
79
- type EventPayload = Omit<Event, "urlGroup"> & {
80
- topicName: string;
81
- };
82
- type GetEventsPayload = {
83
- cursor?: number;
84
- events: EventPayload[];
85
- };
86
- type WithCursor<T> = T & {
87
- cursor?: number;
88
- };
89
- type BodyInit = Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | string;
90
- type HeadersInit = Headers | Record<string, string> | [string, string][] | IterableIterator<[string, string]>;
91
- type RequestOptions = RequestInit & {
92
- backend?: string;
93
- };
94
- type ChatRateLimit = {
95
- "limit-requests": string | null;
96
- "limit-tokens": string | null;
97
- "remaining-requests": string | null;
98
- "remaining-tokens": string | null;
99
- "reset-requests": string | null;
100
- "reset-tokens": string | null;
101
- };
102
- type RateLimit = {
103
- limit: string | null;
104
- remaining: string | null;
105
- reset: string | null;
106
- };
107
-
108
- type ProviderReturnType = {
109
- owner: "upstash" | "openai" | "custom";
110
- baseUrl: string;
111
- token: string;
112
- };
113
- declare const upstash: () => {
114
- owner: "upstash";
115
- baseUrl: "https://qstash.upstash.io/llm";
116
- token: string;
117
- };
118
- declare const openai: ({ token, }: {
119
- token: string;
120
- }) => {
121
- owner: "openai";
122
- baseUrl: "https://api.openai.com";
123
- token: string;
124
- };
125
- declare const custom: ({ baseUrl, token, }: {
126
- token: string;
127
- baseUrl: string;
128
- }) => {
129
- owner: "custom";
130
- baseUrl: string;
131
- token: string;
132
- };
133
-
134
- type ChatCompletionMessage = {
135
- role: "system" | "assistant" | "user";
136
- content: string;
137
- };
138
- type ChatModel = "meta-llama/Meta-Llama-3-8B-Instruct" | "mistralai/Mistral-7B-Instruct-v0.2";
139
- type ChatResponseFormat = {
140
- type: "text" | "json_object";
141
- };
142
- type TopLogprob = {
143
- token: string;
144
- bytes: number[];
145
- logprob: number;
146
- };
147
- type ChatCompletionTokenLogprob = {
148
- token: string;
149
- bytes: number[];
150
- logprob: number;
151
- top_logprobs: TopLogprob[];
152
- };
153
- type ChoiceLogprobs = {
154
- content: ChatCompletionTokenLogprob[];
155
- };
156
- type Choice = {
157
- finish_reason: "stop" | "length";
158
- index: number;
159
- logprobs: ChoiceLogprobs;
160
- message: ChatCompletionMessage;
161
- };
162
- type CompletionUsage = {
163
- completion_tokens: number;
164
- prompt_tokens: number;
165
- total_tokens: number;
166
- };
167
- type ChatCompletion = {
168
- id: string;
169
- choices: Choice[];
170
- created: number;
171
- model: string;
172
- object: "chat.completion";
173
- system_fingerprint: string;
174
- usage: CompletionUsage;
175
- };
176
- type ChunkChoice = {
177
- delta: ChatCompletionMessage;
178
- finish_reason: "stop" | "length";
179
- index: number;
180
- logprobs: ChoiceLogprobs;
181
- };
182
- type ChatCompletionChunk = {
183
- id: string;
184
- choices: ChunkChoice[];
185
- created: number;
186
- model: string;
187
- object: "chat.completion.chunk";
188
- system_fingerprint: string;
189
- usage: CompletionUsage;
190
- };
191
- type StreamEnabled = {
192
- stream: true;
193
- };
194
- type StreamDisabled = {
195
- stream: false;
196
- } | object;
197
- type StreamParameter = StreamEnabled | StreamDisabled;
198
- type OpenAIChatModel = "gpt-4-turbo" | "gpt-4-turbo-2024-04-09" | "gpt-4-0125-preview" | "gpt-4-turbo-preview" | "gpt-4-1106-preview" | "gpt-4-vision-preview" | "gpt-4" | "gpt-4-0314" | "gpt-4-0613" | "gpt-4-32k" | "gpt-4-32k-0314" | "gpt-4-32k-0613" | "gpt-3.5-turbo" | "gpt-3.5-turbo-16k" | "gpt-3.5-turbo-0301" | "gpt-3.5-turbo-0613" | "gpt-3.5-turbo-1106" | "gpt-3.5-turbo-0125" | "gpt-3.5-turbo-16k-0613";
199
- type ChatRequestCommonFields = {
200
- frequency_penalty?: number;
201
- logit_bias?: Record<string, number>;
202
- logprobs?: boolean;
203
- top_logprobs?: number;
204
- max_tokens?: number;
205
- n?: number;
206
- presence_penalty?: number;
207
- response_format?: ChatResponseFormat;
208
- seed?: number;
209
- stop?: string | string[];
210
- temperature?: number;
211
- top_p?: number;
212
- };
213
- type PromptChatRequestFields = ChatRequestCommonFields & {
214
- system: string;
215
- user: string;
216
- };
217
- type ChatRequestFields = ChatRequestCommonFields & {
218
- messages: ChatCompletionMessage[];
219
- };
220
- type ChatRequestProviders = {
221
- provider: ProviderReturnType;
222
- model: OpenAIChatModel;
223
- } | {
224
- provider: ProviderReturnType;
225
- model: string;
226
- } | {
227
- provider: ProviderReturnType;
228
- model: ChatModel;
229
- };
230
- type PromptChatRequest<TStream extends StreamParameter> = ChatRequestProviders & PromptChatRequestFields & TStream;
231
- type ChatRequest<TStream extends StreamParameter> = ChatRequestProviders & ChatRequestFields & TStream;
232
-
233
- type UpstashRequest = {
234
- /**
235
- * The path to the resource.
236
- */
237
- path: string[];
238
- /**
239
- * A BodyInit object or null to set request's body.
240
- */
241
- body?: BodyInit | null;
242
- /**
243
- * A Headers object, an object literal, or an array of two-item arrays to set
244
- * request's headers.
245
- */
246
- headers?: HeadersInit;
247
- /**
248
- * A boolean to set request's keepalive.
249
- */
250
- keepalive?: boolean;
251
- /**
252
- * A string to set request's method.
253
- */
254
- method?: HTTPMethods;
255
- query?: Record<string, string | number | boolean | undefined>;
256
- /**
257
- * if enabled, call `res.json()`
258
- *
259
- * @default true
260
- */
261
- parseResponseAsJson?: boolean;
262
- baseUrl?: string;
263
- };
264
- type UpstashResponse<TResult> = TResult & {
265
- error?: string;
266
- };
267
- type Requester = {
268
- request: <TResult = unknown>(request: UpstashRequest) => Promise<UpstashResponse<TResult>>;
269
- requestStream: (request: UpstashRequest) => AsyncIterable<ChatCompletionChunk>;
270
- };
271
- type RetryConfig = false | {
272
- /**
273
- * The number of retries to attempt before giving up.
274
- *
275
- * @default 5
276
- */
277
- retries?: number;
278
- /**
279
- * A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
280
- *
281
- * @default
282
- * ```ts
283
- * Math.exp(retryCount) * 50
284
- * ```
285
- */
286
- backoff?: (retryCount: number) => number;
287
- };
288
-
289
- type Message = {
290
- /**
291
- * A unique identifier for this message.
292
- */
293
- messageId: string;
294
- /**
295
- * The url group name if this message was sent to a urlGroup.
296
- */
297
- urlGroup?: string;
298
- /**
299
- * Deprecated. The topic name if this message was sent to a urlGroup. Use urlGroup instead
300
- */
301
- topicName?: string;
302
- /**
303
- * The url where this message is sent to.
304
- */
305
- url: string;
306
- /**
307
- * The endpoint name of the message if the endpoint is given a
308
- * name within the url group.
309
- */
310
- endpointName?: string;
311
- /**
312
- * The api name if this message was sent to an api
313
- */
314
- api?: string;
315
- /**
316
- * The http method used to deliver the message
317
- */
318
- method?: HTTPMethods;
319
- /**
320
- * The http headers sent along with the message to your API.
321
- */
322
- header?: Record<string, string[]>;
323
- /**
324
- * The http body sent to your API
325
- */
326
- body?: string;
327
- /**
328
- * The base64 encoded body if the body contains non-UTF-8 characters,
329
- * `None` otherwise.
330
- */
331
- bodyBase64?: string;
332
- /**
333
- * Maxmimum number of retries.
334
- */
335
- maxRetries?: number;
336
- /**
337
- * A unix timestamp (milliseconds) after which this message may get delivered.
338
- */
339
- notBefore?: number;
340
- /**
341
- * A unix timestamp (milliseconds) when this messages was created.
342
- */
343
- createdAt: number;
344
- /**
345
- * The callback url if configured.
346
- */
347
- callback?: string;
348
- /**
349
- * The failure callback url if configured.
350
- */
351
- failureCallback?: string;
352
- /**
353
- * The queue name if this message was sent to a queue.
354
- */
355
- queueName?: string;
356
- /**
357
- * The scheduleId of the message if the message is triggered by a schedule
358
- */
359
- scheduleId?: string;
360
- /**
361
- * IP address of the publisher of this message
362
- */
363
- callerIp?: string;
364
- };
365
- type MessagePayload = Omit<Message, "urlGroup"> & {
366
- topicName: string;
367
- };
368
- declare class Messages {
369
- private readonly http;
370
- constructor(http: Requester);
371
- /**
372
- * Get a message
373
- */
374
- get(messageId: string): Promise<Message>;
375
- /**
376
- * Cancel a message
377
- */
378
- delete(messageId: string): Promise<void>;
379
- deleteMany(messageIds: string[]): Promise<number>;
380
- deleteAll(): Promise<number>;
381
- }
382
-
383
- type DlqMessage = Message & {
384
- /**
385
- * The unique id within the DLQ
386
- */
387
- dlqId: string;
388
- /**
389
- * The HTTP status code of the last failed delivery attempt
390
- */
391
- responseStatus?: number;
392
- /**
393
- * The response headers of the last failed delivery attempt
394
- */
395
- responseHeader?: Record<string, string[]>;
396
- /**
397
- * The response body of the last failed delivery attempt if it is
398
- * composed of UTF-8 characters only, `None` otherwise.
399
- */
400
- responseBody?: string;
401
- /**
402
- * The base64 encoded response body of the last failed delivery attempt
403
- * if the response body contains non-UTF-8 characters, `None` otherwise.
404
- */
405
- responseBodyBase64?: string;
406
- };
407
- type DLQFilter = {
408
- /**
409
- * Filter DLQ entries by message id
410
- */
411
- messageId?: string;
412
- /**
413
- * Filter DLQ entries by url
414
- */
415
- url?: string;
416
- /**
417
- * Filter DLQ entries by url group name
418
- */
419
- urlGroup?: string;
420
- /**
421
- * Filter DLQ entries by api name
422
- */
423
- api?: string;
424
- /**
425
- * Filter DLQ entries by queue name
426
- */
427
- queueName?: string;
428
- /**
429
- * Filter DLQ entries by schedule id
430
- */
431
- scheduleId?: string;
432
- /**
433
- * Filter DLQ entries by starting time, in milliseconds
434
- */
435
- fromDate?: number;
436
- /**
437
- * Filter DLQ entries by ending time, in milliseconds
438
- */
439
- toDate?: number;
440
- /**
441
- * Filter DLQ entries by HTTP status of the response
442
- */
443
- responseStatus?: number;
444
- /**
445
- * Filter DLQ entries by IP address of the publisher of the message
446
- */
447
- callerIp?: string;
448
- };
449
- declare class DLQ {
450
- private readonly http;
451
- constructor(http: Requester);
452
- /**
453
- * List messages in the dlq
454
- */
455
- listMessages(options?: {
456
- cursor?: string;
457
- count?: number;
458
- filter?: DLQFilter;
459
- }): Promise<{
460
- messages: DlqMessage[];
461
- cursor?: string;
462
- }>;
463
- /**
464
- * Remove a message from the dlq using it's `dlqId`
465
- */
466
- delete(dlqMessageId: string): Promise<void>;
467
- /**
468
- * Remove multiple messages from the dlq using their `dlqId`s
469
- */
470
- deleteMany(request: {
471
- dlqIds: string[];
472
- }): Promise<{
473
- deleted: number;
474
- }>;
475
- }
476
-
477
- declare class Chat {
478
- private http;
479
- private token;
480
- constructor(http: Requester, token: string);
481
- private static toChatRequest;
482
- /**
483
- * Calls the Upstash completions api given a ChatRequest.
484
- *
485
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
486
- * if stream is enabled.
487
- *
488
- * @param request ChatRequest with messages
489
- * @returns Chat completion or stream
490
- */
491
- create: <TStream extends StreamParameter>(request: ChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
492
- /**
493
- * Calls the Upstash completions api given a ChatRequest.
494
- *
495
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
496
- * if stream is enabled.
497
- *
498
- * @param request ChatRequest with messages
499
- * @returns Chat completion or stream
500
- */
501
- private createThirdParty;
502
- /**
503
- * Calls the Upstash completions api given a PromptRequest.
504
- *
505
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
506
- * if stream is enabled.
507
- *
508
- * @param request PromptRequest with system and user messages.
509
- * Note that system parameter shouldn't be passed in the case of
510
- * mistralai/Mistral-7B-Instruct-v0.2 model.
511
- * @returns Chat completion or stream
512
- */
513
- prompt: <TStream extends StreamParameter>(request: PromptChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
514
- }
515
-
516
- type QueueResponse = {
517
- createdAt: number;
518
- updatedAt: number;
519
- name: string;
520
- parallelism: number;
521
- lag: number;
522
- paused: boolean;
523
- };
524
- type UpsertQueueRequest = {
525
- /**
526
- * The number of parallel consumers consuming from the queue.
527
- *
528
- * @default 1
529
- */
530
- parallelism?: number;
531
- /**
532
- * Whether to pause the queue or not. A paused queue will not
533
- * deliver new messages until it is resumed.
534
- *
535
- * @default false
536
- */
537
- paused?: boolean;
538
- };
539
- declare class Queue {
540
- private readonly http;
541
- private readonly queueName;
542
- constructor(http: Requester, queueName?: string);
543
- /**
544
- * Create or update the queue
545
- */
546
- upsert(request: UpsertQueueRequest): Promise<void>;
547
- /**
548
- * Get the queue details
549
- */
550
- get(): Promise<QueueResponse>;
551
- /**
552
- * List queues
553
- */
554
- list(): Promise<QueueResponse[]>;
555
- /**
556
- * Delete the queue
557
- */
558
- delete(): Promise<void>;
559
- /**
560
- * Enqueue a message to a queue.
561
- */
562
- enqueue<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
563
- /**
564
- * Enqueue a message to a queue, serializing the body to JSON.
565
- */
566
- enqueueJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
567
- /**
568
- * Pauses the queue.
569
- *
570
- * A paused queue will not deliver messages until
571
- * it is resumed.
572
- */
573
- pause(): Promise<void>;
574
- /**
575
- * Resumes the queue.
576
- */
577
- resume(): Promise<void>;
578
- }
579
-
580
- type Schedule = {
581
- scheduleId: string;
582
- cron: string;
583
- createdAt: number;
584
- destination: string;
585
- method: string;
586
- header?: Record<string, string[]>;
587
- body?: string;
588
- bodyBase64?: string;
589
- retries: number;
590
- delay?: number;
591
- callback?: string;
592
- failureCallback?: string;
593
- callerIp?: string;
594
- isPaused: boolean;
595
- };
596
- type CreateScheduleRequest = {
597
- /**
598
- * Either a URL or urlGroup name
599
- */
600
- destination: string;
601
- /**
602
- * The message to send.
603
- *
604
- * This can be anything, but please set the `Content-Type` header accordingly.
605
- *
606
- * You can leave this empty if you want to send a message with no body.
607
- */
608
- body?: BodyInit;
609
- /**
610
- * Optionally send along headers with the message.
611
- * These headers will be sent to your destination.
612
- *
613
- * We highly recommend sending a `Content-Type` header along, as this will help your destination
614
- * server to understand the content of the message.
615
- */
616
- headers?: HeadersInit;
617
- /**
618
- * Optionally delay the delivery of this message.
619
- *
620
- * In seconds.
621
- *
622
- * @default undefined
623
- */
624
- delay?: number;
625
- /**
626
- * In case your destination server is unavailable or returns a status code outside of the 200-299
627
- * range, we will retry the request after a certain amount of time.
628
- *
629
- * Configure how many times you would like the delivery to be retried
630
- *
631
- * @default The maximum retry quota associated with your account.
632
- */
633
- retries?: number;
634
- /**
635
- * Use a callback url to forward the response of your destination server to your callback url.
636
- *
637
- * The callback url must be publicly accessible
638
- *
639
- * @default undefined
640
- */
641
- callback?: string;
642
- /**
643
- * Use a failure callback url to handle messages that could not be delivered.
644
- *
645
- * The failure callback url must be publicly accessible
646
- *
647
- * @default undefined
648
- */
649
- failureCallback?: string;
650
- /**
651
- * The method to use when sending a request to your API
652
- *
653
- * @default `POST`
654
- */
655
- method?: HTTPMethods;
656
- /**
657
- * Specify a cron expression to repeatedly send this message to the destination.
658
- */
659
- cron: string;
660
- /**
661
- * The HTTP timeout value to use while calling the destination URL.
662
- * When a timeout is specified, it will be used instead of the maximum timeout
663
- * value permitted by the QStash plan. It is useful in scenarios, where a message
664
- * should be delivered with a shorter timeout.
665
- *
666
- * In seconds.
667
- *
668
- * @default undefined
669
- */
670
- timeout?: number;
671
- };
672
- declare class Schedules {
673
- private readonly http;
674
- constructor(http: Requester);
675
- /**
676
- * Create a schedule
677
- */
678
- create(request: CreateScheduleRequest): Promise<{
679
- scheduleId: string;
680
- }>;
681
- /**
682
- * Get a schedule
683
- */
684
- get(scheduleId: string): Promise<Schedule>;
685
- /**
686
- * List your schedules
687
- */
688
- list(): Promise<Schedule[]>;
689
- /**
690
- * Delete a schedule
691
- */
692
- delete(scheduleId: string): Promise<void>;
693
- /**
694
- * Pauses the schedule.
695
- *
696
- * A paused schedule will not deliver messages until
697
- * it is resumed.
698
- */
699
- pause({ schedule }: {
700
- schedule: string;
701
- }): Promise<void>;
702
- /**
703
- * Resumes the schedule.
704
- */
705
- resume({ schedule }: {
706
- schedule: string;
707
- }): Promise<void>;
708
- }
709
-
710
- type Endpoint = {
711
- /**
712
- * The name of the endpoint (optional)
713
- */
714
- name?: string;
715
- /**
716
- * The url of the endpoint
717
- */
718
- url: string;
719
- };
720
- type AddEndpointsRequest = {
721
- /**
722
- * The name of the url group.
723
- * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
724
- */
725
- name: string;
726
- endpoints: Endpoint[];
727
- };
728
- type RemoveEndpointsRequest = {
729
- /**
730
- * The name of the url group.
731
- * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
732
- */
733
- name: string;
734
- endpoints: ({
735
- name: string;
736
- url?: string;
737
- } | {
738
- name?: string;
739
- url: string;
740
- })[];
741
- };
742
- type UrlGroup = {
743
- /**
744
- * A unix timestamp (milliseconds)
745
- */
746
- createdAt: number;
747
- /**
748
- * A unix timestamp (milliseconds)
749
- */
750
- updatedAt: number;
751
- /**
752
- * The name of this url group.
753
- */
754
- name: string;
755
- /**
756
- * A list of all subscribed endpoints
757
- */
758
- endpoints: Endpoint[];
759
- };
760
- declare class UrlGroups {
761
- private readonly http;
762
- constructor(http: Requester);
763
- /**
764
- * Create a new url group with the given name and endpoints
765
- */
766
- addEndpoints(request: AddEndpointsRequest): Promise<void>;
767
- /**
768
- * Remove endpoints from a url group.
769
- */
770
- removeEndpoints(request: RemoveEndpointsRequest): Promise<void>;
771
- /**
772
- * Get a list of all url groups.
773
- */
774
- list(): Promise<UrlGroup[]>;
775
- /**
776
- * Get a single url group
777
- */
778
- get(name: string): Promise<UrlGroup>;
779
- /**
780
- * Delete a url group
781
- */
782
- delete(name: string): Promise<void>;
783
- }
784
-
785
- type ClientConfig = {
786
- /**
787
- * Url of the qstash api server.
788
- *
789
- * This is only used for testing.
790
- *
791
- * @default "https://qstash.upstash.io"
792
- */
793
- baseUrl?: string;
794
- /**
795
- * The authorization token from the upstash console.
796
- */
797
- token: string;
798
- /**
799
- * Configure how the client should retry requests.
800
- */
801
- retry?: RetryConfig;
802
- };
803
- type PublishBatchRequest<TBody = BodyInit> = PublishRequest<TBody> & {
804
- queueName?: string;
805
- };
806
- type PublishRequest<TBody = BodyInit> = {
807
- /**
808
- * The message to send.
809
- *
810
- * This can be anything, but please set the `Content-Type` header accordingly.
811
- *
812
- * You can leave this empty if you want to send a message with no body.
813
- */
814
- body?: TBody;
815
- /**
816
- * Optionally send along headers with the message.
817
- * These headers will be sent to your destination.
818
- *
819
- * We highly recommend sending a `Content-Type` header along, as this will help your destination
820
- * server to understand the content of the message.
821
- */
822
- headers?: HeadersInit;
823
- /**
824
- * Optionally delay the delivery of this message.
825
- *
826
- * In seconds.
827
- *
828
- * @default undefined
829
- */
830
- delay?: number;
831
- /**
832
- * Optionally set the absolute delay of this message.
833
- * This will override the delay option.
834
- * The message will not delivered until the specified time.
835
- *
836
- * Unix timestamp in seconds.
837
- *
838
- * @default undefined
839
- */
840
- notBefore?: number;
841
- /**
842
- * Provide a unique id for deduplication. This id will be used to detect duplicate messages.
843
- * If a duplicate message is detected, the request will be accepted but not enqueued.
844
- *
845
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
846
- * same deduplication id is delivered again.
847
- *
848
- * When scheduling a message, the deduplication happens before the schedule is created.
849
- *
850
- * @default undefined
851
- */
852
- deduplicationId?: string;
853
- /**
854
- * If true, the message content will get hashed and used as deduplication id.
855
- * If a duplicate message is detected, the request will be accepted but not enqueued.
856
- *
857
- * The content based hash includes the following values:
858
- * - All headers, except Upstash-Authorization, this includes all headers you are sending.
859
- * - The entire raw request body The destination from the url path
860
- *
861
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
862
- * same deduplication id is delivered again.
863
- *
864
- * When scheduling a message, the deduplication happens before the schedule is created.
865
- *
866
- * @default false
867
- */
868
- contentBasedDeduplication?: boolean;
869
- /**
870
- * In case your destination server is unavaialble or returns a status code outside of the 200-299
871
- * range, we will retry the request after a certain amount of time.
872
- *
873
- * Configure how many times you would like the delivery to be retried up to the maxRetries limit
874
- * defined in your plan.
875
- *
876
- * @default 3
877
- */
878
- retries?: number;
879
- /**
880
- * Use a failure callback url to handle messages that could not be delivered.
881
- *
882
- * The failure callback url must be publicly accessible
883
- *
884
- * @default undefined
885
- */
886
- failureCallback?: string;
887
- /**
888
- * The method to use when sending a request to your API
889
- *
890
- * @default `POST`
891
- */
892
- method?: HTTPMethods;
893
- /**
894
- * The HTTP timeout value to use while calling the destination URL.
895
- * When a timeout is specified, it will be used instead of the maximum timeout
896
- * value permitted by the QStash plan. It is useful in scenarios, where a message
897
- * should be delivered with a shorter timeout.
898
- *
899
- * In seconds.
900
- *
901
- * @default undefined
902
- */
903
- timeout?: number;
904
- } & ({
905
- /**
906
- * The url where the message should be sent to.
907
- */
908
- url: string;
909
- urlGroup?: never;
910
- api?: never;
911
- topic?: never;
912
- /**
913
- * Use a callback url to forward the response of your destination server to your callback url.
914
- *
915
- * The callback url must be publicly accessible
916
- *
917
- * @default undefined
918
- */
919
- callback?: string;
920
- } | {
921
- url?: never;
922
- /**
923
- * The url group the message should be sent to.
924
- */
925
- urlGroup: string;
926
- api?: never;
927
- topic?: never;
928
- /**
929
- * Use a callback url to forward the response of your destination server to your callback url.
930
- *
931
- * The callback url must be publicly accessible
932
- *
933
- * @default undefined
934
- */
935
- callback?: string;
936
- } | {
937
- url?: string;
938
- urlGroup?: never;
939
- /**
940
- * The api endpoint the request should be sent to.
941
- */
942
- api: {
943
- name: "llm";
944
- provider?: ProviderReturnType;
945
- };
946
- /**
947
- * Use a callback url to forward the response of your destination server to your callback url.
948
- *
949
- * The callback url must be publicly accessible
950
- *
951
- * @default undefined
952
- */
953
- callback: string;
954
- topic?: never;
955
- } | {
956
- url?: never;
957
- urlGroup?: never;
958
- api: never;
959
- /**
960
- * Deprecated. The topic the message should be sent to. Same as urlGroup
961
- */
962
- topic?: string;
963
- /**
964
- * Use a callback url to forward the response of your destination server to your callback url.
965
- *
966
- * The callback url must be publicly accessible
967
- *
968
- * @default undefined
969
- */
970
- callback?: string;
971
- });
972
- type PublishJsonRequest = Omit<PublishRequest, "body"> & {
973
- /**
974
- * The message to send.
975
- * This can be anything as long as it can be serialized to JSON.
976
- */
977
- body: unknown;
978
- };
979
- type EventsRequest = {
980
- cursor?: number;
981
- filter?: EventsRequestFilter;
982
- };
983
- type EventsRequestFilter = {
984
- messageId?: string;
985
- state?: State;
986
- url?: string;
987
- urlGroup?: string;
988
- topicName?: string;
989
- api?: string;
990
- scheduleId?: string;
991
- queueName?: string;
992
- fromDate?: number;
993
- toDate?: number;
994
- count?: number;
995
- };
996
- type GetEventsResponse = {
997
- cursor?: number;
998
- events: Event[];
999
- };
1000
- type QueueRequest = {
1001
- queueName?: string;
1002
- };
1003
- declare class Client {
1004
- http: Requester;
1005
- private token;
1006
- constructor(config: ClientConfig);
1007
- /**
1008
- * Access the urlGroup API.
1009
- *
1010
- * Create, read, update or delete urlGroups.
1011
- */
1012
- get urlGroups(): UrlGroups;
1013
- /**
1014
- * Deprecated. Use urlGroups instead.
1015
- *
1016
- * Access the topic API.
1017
- *
1018
- * Create, read, update or delete topics.
1019
- */
1020
- get topics(): UrlGroups;
1021
- /**
1022
- * Access the dlq API.
1023
- *
1024
- * List or remove messages from the DLQ.
1025
- */
1026
- get dlq(): DLQ;
1027
- /**
1028
- * Access the message API.
1029
- *
1030
- * Read or cancel messages.
1031
- */
1032
- get messages(): Messages;
1033
- /**
1034
- * Access the schedule API.
1035
- *
1036
- * Create, read or delete schedules.
1037
- */
1038
- get schedules(): Schedules;
1039
- /**
1040
- * Access the queue API.
1041
- *
1042
- * Create, read, update or delete queues.
1043
- */
1044
- queue(request?: QueueRequest): Queue;
1045
- /**
1046
- * Access the Chat API
1047
- *
1048
- * Call the create or prompt methods
1049
- */
1050
- chat(): Chat;
1051
- publish<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
1052
- /**
1053
- * publishJSON is a utility wrapper around `publish` that automatically serializes the body
1054
- * and sets the `Content-Type` header to `application/json`.
1055
- */
1056
- publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
1057
- /**
1058
- * Batch publish messages to QStash.
1059
- */
1060
- batch(request: PublishBatchRequest[]): Promise<PublishResponse<PublishRequest>[]>;
1061
- /**
1062
- * Batch publish messages to QStash, serializing each body to JSON.
1063
- */
1064
- batchJSON<TBody = unknown, TRequest extends PublishBatchRequest<TBody> = PublishBatchRequest<TBody>>(request: TRequest[]): Promise<PublishResponse<TRequest>[]>;
1065
- /**
1066
- * Retrieve your logs.
1067
- *
1068
- * The logs endpoint is paginated and returns only 100 logs at a time.
1069
- * If you want to receive more logs, you can use the cursor to paginate.
1070
- *
1071
- * The cursor is a unix timestamp with millisecond precision
1072
- *
1073
- * @example
1074
- * ```ts
1075
- * let cursor = Date.now()
1076
- * const logs: Log[] = []
1077
- * while (cursor > 0) {
1078
- * const res = await qstash.logs({ cursor })
1079
- * logs.push(...res.logs)
1080
- * cursor = res.cursor ?? 0
1081
- * }
1082
- * ```
1083
- */
1084
- events(request?: EventsRequest): Promise<GetEventsResponse>;
1085
- }
1086
- type PublishToApiResponse = {
1087
- messageId: string;
1088
- };
1089
- type PublishToUrlResponse = PublishToApiResponse & {
1090
- url: string;
1091
- deduplicated?: boolean;
1092
- };
1093
- type PublishToUrlGroupsResponse = PublishToUrlResponse[];
1094
- type PublishResponse<TRequest> = TRequest extends {
1095
- url: string;
1096
- } ? PublishToUrlResponse : TRequest extends {
1097
- urlGroup: string;
1098
- } ? PublishToUrlGroupsResponse : PublishToApiResponse;
1099
-
1100
- /**
1101
- * Base class outlining steps. Basically, each step kind (run/sleep/sleepUntil)
1102
- * should have two methods: getPlanStep & getResultStep.
1103
- *
1104
- * getPlanStep works the same way for all so it's implemented here.
1105
- * The different step types will implement their own getResultStep method.
1106
- */
1107
- declare abstract class BaseLazyStep<TResult = unknown> {
1108
- readonly stepName: string;
1109
- abstract readonly stepType: StepType;
1110
- constructor(stepName: string);
1111
- /**
1112
- * plan step to submit when step will run parallel with other
1113
- * steps (parallel call state `first`)
1114
- *
1115
- * @param concurrent number of steps running parallel
1116
- * @param targetStep target step id corresponding to this step
1117
- * @returns
1118
- */
1119
- abstract getPlanStep(concurrent: number, targetStep: number): Step<undefined>;
1120
- /**
1121
- * result step to submit after the step executes. Used in single step executions
1122
- * and when a plan step executes in parallel executions (parallel call state `partial`).
1123
- *
1124
- * @param concurrent
1125
- * @param stepId
1126
- */
1127
- abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
1128
- }
1129
-
1130
- declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
1131
- type LogLevel = (typeof LOG_LEVELS)[number];
1132
- type ChatLogEntry = {
1133
- timestamp: number;
1134
- logLevel: LogLevel;
1135
- eventType: "ENDPOINT_START" | "SUBMIT_THIRD_PARTY_RESULT" | "CREATE_CONTEXT" | "SUBMIT_FIRST_INVOCATION" | "RUN_SINGLE" | "RUN_PARALLEL" | "SUBMIT_STEP" | "SUBMIT_CLEANUP" | "RESPONSE_WORKFLOW" | "RESPONSE_DEFAULT" | "ERROR";
1136
- details: unknown;
1137
- };
1138
- type WorkflowLoggerOptions = {
1139
- logLevel: LogLevel;
1140
- logOutput: "console";
1141
- };
1142
- declare class WorkflowLogger {
1143
- private logs;
1144
- private options;
1145
- constructor(options: WorkflowLoggerOptions);
1146
- log(level: LogLevel, eventType: ChatLogEntry["eventType"], details?: unknown): Promise<void>;
1147
- private writeToConsole;
1148
- private shouldLog;
1149
- static getLogger(verbose: boolean | WorkflowLogger): WorkflowLogger | undefined;
1150
- }
1151
-
1152
- declare class AutoExecutor {
1153
- private context;
1154
- private promises;
1155
- private activeLazyStepList?;
1156
- private debug?;
1157
- private readonly nonPlanStepCount;
1158
- private indexInCurrentList;
1159
- stepCount: number;
1160
- planStepCount: number;
1161
- protected executingStep: string | false;
1162
- constructor(context: WorkflowContext, debug?: WorkflowLogger);
1163
- /**
1164
- * Adds the step function to the list of step functions to run in
1165
- * parallel. After adding the function, defers the execution, so
1166
- * that if there is another step function to be added, it's also
1167
- * added.
1168
- *
1169
- * After all functions are added, list of functions are executed.
1170
- * If there is a single function, it's executed by itself. If there
1171
- * are multiple, they are run in parallel.
1172
- *
1173
- * If a function is already executing (this.executingStep), this
1174
- * means that there is a nested step which is not allowed. In this
1175
- * case, addStep throws QstashWorkflowError.
1176
- *
1177
- * @param stepInfo step plan to add
1178
- * @returns result of the step function
1179
- */
1180
- addStep<TResult>(stepInfo: BaseLazyStep<TResult>): Promise<TResult>;
1181
- /**
1182
- * Wraps a step function to set this.executingStep to step name
1183
- * before running and set this.executingStep to False after execution
1184
- * ends.
1185
- *
1186
- * this.executingStep allows us to detect nested steps which are not
1187
- * allowed.
1188
- *
1189
- * @param stepName name of the step being wrapped
1190
- * @param stepFunction step function to wrap
1191
- * @returns wrapped step function
1192
- */
1193
- wrapStep<TResult = unknown>(stepName: string, stepFunction: AsyncStepFunction<TResult>): Promise<TResult>;
1194
- /**
1195
- * Executes a step:
1196
- * - If the step result is available in the steps, returns the result
1197
- * - If the result is not avaiable, runs the function
1198
- * - Sends the result to QStash
1199
- *
1200
- * @param lazyStep lazy step to execute
1201
- * @returns step result
1202
- */
1203
- protected runSingle<TResult>(lazyStep: BaseLazyStep<TResult>): Promise<TResult>;
1204
- /**
1205
- * Runs steps in parallel.
1206
- *
1207
- * @param stepName parallel step name
1208
- * @param stepFunctions list of async functions to run in parallel
1209
- * @returns results of the functions run in parallel
1210
- */
1211
- protected runParallel<TResults extends unknown[]>(parallelSteps: {
1212
- [K in keyof TResults]: BaseLazyStep<TResults[K]>;
1213
- }): Promise<TResults>;
1214
- /**
1215
- * Determines the parallel call state
1216
- *
1217
- * First filters the steps to get the steps which are after `initialStepCount` parameter.
1218
- *
1219
- * Depending on the remaining steps, decides the parallel state:
1220
- * - "first": If there are no steps
1221
- * - "last" If there are equal to or more than `2 * parallelStepCount`. We multiply by two
1222
- * because each step in a parallel execution will have 2 steps: a plan step and a result
1223
- * step.
1224
- * - "partial": If the last step is a plan step
1225
- * - "discard": If the last step is not a plan step. This means that the parallel execution
1226
- * is in progress (there are still steps to run) and one step has finished and submitted
1227
- * its result to QStash
1228
- *
1229
- * @param parallelStepCount number of steps to run in parallel
1230
- * @param initialStepCount steps after the parallel invocation
1231
- * @returns parallel call state
1232
- */
1233
- protected getParallelCallState(parallelStepCount: number, initialStepCount: number): ParallelCallState;
1234
- /**
1235
- * sends the steps to QStash as batch
1236
- *
1237
- * @param steps steps to send
1238
- */
1239
- private submitStepsToQstash;
1240
- /**
1241
- * Get the promise by executing the lazt steps list. If there is a single
1242
- * step, we call `runSingle`. Otherwise `runParallel` is called.
1243
- *
1244
- * @param lazyStepList steps list to execute
1245
- * @returns promise corresponding to the execution
1246
- */
1247
- private getExecutionPromise;
1248
- /**
1249
- * @param lazyStepList steps we executed
1250
- * @param result result of the promise from `getExecutionPromise`
1251
- * @param index index of the current step
1252
- * @returns result[index] if lazyStepList > 1, otherwise result
1253
- */
1254
- private static getResult;
1255
- private deferExecution;
1256
- }
1257
-
1258
- declare class WorkflowContext<TInitialPayload = unknown> {
1259
- protected readonly executor: AutoExecutor;
1260
- readonly client: Client;
1261
- readonly workflowRunId: string;
1262
- readonly steps: Step[];
1263
- readonly url: string;
1264
- readonly failureUrl: string | false;
1265
- readonly requestPayload: TInitialPayload;
1266
- readonly headers: Headers;
1267
- readonly rawInitialPayload: string;
1268
- constructor({ client, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, rawInitialPayload, }: {
1269
- client: Client;
1270
- workflowRunId: string;
1271
- headers: Headers;
1272
- steps: Step[];
1273
- url: string;
1274
- failureUrl?: string | false;
1275
- debug?: WorkflowLogger;
1276
- initialPayload: TInitialPayload;
1277
- rawInitialPayload?: string;
1278
- });
1279
- /**
1280
- * Executes a workflow step
1281
- *
1282
- * ```typescript
1283
- * const result = await context.run("step 1", async () => {
1284
- * return await Promise.resolve("result")
1285
- * })
1286
- * ```
1287
- *
1288
- * Can also be called in parallel and the steps will be executed
1289
- * simulatenously:
1290
- *
1291
- * ```typescript
1292
- * const [result1, result2] = await Promise.all([
1293
- * context.run("step 1", async () => {
1294
- * return await Promise.resolve("result1")
1295
- * })
1296
- * context.run("step 2", async () => {
1297
- * return await Promise.resolve("result2")
1298
- * })
1299
- * ])
1300
- * ```
1301
- *
1302
- * @param stepName name of the step
1303
- * @param stepFunction step function to be executed
1304
- * @returns result of the step function
1305
- */
1306
- run<TResult>(stepName: string, stepFunction: AsyncStepFunction<TResult>): Promise<TResult>;
1307
- /**
1308
- * Stops the execution for the duration provided.
1309
- *
1310
- * @param stepName
1311
- * @param duration sleep duration in seconds
1312
- * @returns
1313
- */
1314
- sleep(stepName: string, duration: number): Promise<void>;
1315
- /**
1316
- * Stops the execution until the date time provided.
1317
- *
1318
- * @param stepName
1319
- * @param datetime time to sleep until. Can be provided as a number (in unix seconds),
1320
- * as a Date object or a string (passed to `new Date(datetimeString)`)
1321
- * @returns
1322
- */
1323
- sleepUntil(stepName: string, datetime: Date | string | number): Promise<void>;
1324
- call<TResult = unknown, TBody = unknown>(stepName: string, url: string, method: HTTPMethods, body?: TBody, headers?: Record<string, string>): Promise<TResult>;
1325
- /**
1326
- * Adds steps to the executor. Needed so that it can be overwritten in
1327
- * DisabledWorkflowContext.
1328
- */
1329
- protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
1330
- }
1331
- /**
1332
- * Workflow context which throws QstashWorkflowAbort before running the steps.
1333
- *
1334
- * Used for making a dry run before running any steps to check authentication.
1335
- *
1336
- * Consider an endpoint like this:
1337
- * ```ts
1338
- * export const POST = serve({
1339
- * routeFunction: context => {
1340
- * if (context.headers.get("authentication") !== "Bearer secretPassword") {
1341
- * console.error("Authentication failed.");
1342
- * return;
1343
- * }
1344
- *
1345
- * // ...
1346
- * }
1347
- * })
1348
- * ```
1349
- *
1350
- * the serve method will first call the routeFunction with an DisabledWorkflowContext.
1351
- * Here is the action we take in different cases
1352
- * - "step-found": we will run the workflow related sections of `serve`.
1353
- * - "run-ended": simply return success and end the workflow
1354
- * - error: returns 500.
1355
- */
1356
- declare class DisabledWorkflowContext<TInitialPayload = unknown> extends WorkflowContext<TInitialPayload> {
1357
- private static readonly disabledMessage;
1358
- /**
1359
- * overwrite the WorkflowContext.addStep method to always raise QstashWorkflowAbort
1360
- * error in order to stop the execution whenever we encounter a step.
1361
- *
1362
- * @param _step
1363
- */
1364
- protected addStep<TResult = unknown>(_step: BaseLazyStep<TResult>): Promise<TResult>;
1365
- /**
1366
- * copies the passed context to create a DisabledWorkflowContext. Then, runs the
1367
- * route function with the new context.
1368
- *
1369
- * - returns "run-ended" if there are no steps found or
1370
- * if the auth failed and user called `return`
1371
- * - returns "step-found" if DisabledWorkflowContext.addStep is called.
1372
- * - if there is another error, returns the error.
1373
- *
1374
- * @param routeFunction
1375
- */
1376
- static tryAuthentication<TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, context: WorkflowContext<TInitialPayload>): Promise<Ok<"step-found" | "run-ended", never> | Err<never, Error>>;
1377
- }
1378
-
1379
- declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call"];
1380
- type StepType = (typeof StepTypes)[number];
1381
- type ThirdPartyCallFields<TBody = unknown> = {
1382
- /**
1383
- * Third party call URL. Set when context.call is used.
1384
- */
1385
- callUrl: string;
1386
- /**
1387
- * Third party call method. Set when context.call is used.
1388
- */
1389
- callMethod: HTTPMethods;
1390
- /**
1391
- * Third party call body. Set when context.call is used.
1392
- */
1393
- callBody: TBody;
1394
- /**
1395
- * Third party call headers. Set when context.call is used.
1396
- */
1397
- callHeaders: Record<string, string>;
1398
- };
1399
- type Step<TResult = unknown, TBody = unknown> = {
1400
- /**
1401
- * index of the step
1402
- */
1403
- stepId: number;
1404
- /**
1405
- * name of the step
1406
- */
1407
- stepName: string;
1408
- /**
1409
- * type of the step (Initial/Run/SleepFor/SleepUntil/Call)
1410
- */
1411
- stepType: StepType;
1412
- /**
1413
- * step result. Set if context.run or context.call are used.
1414
- */
1415
- out?: TResult;
1416
- /**
1417
- * sleep duration in seconds. Set when context.sleep is used.
1418
- */
1419
- sleepFor?: number;
1420
- /**
1421
- * unix timestamp (in seconds) to wait until. Set when context.sleepUntil is used.
1422
- */
1423
- sleepUntil?: number;
1424
- /**
1425
- * number of steps running concurrently if the step is in a parallel run.
1426
- * Set to 1 if step is not parallel.
1427
- */
1428
- concurrent: number;
1429
- /**
1430
- * target step of a plan step. In other words, the step to assign the
1431
- * result of a plan step.
1432
- *
1433
- * undefined if the step is not a plan step (of a parallel run). Otherwise,
1434
- * set to the target step.
1435
- */
1436
- targetStep?: number;
1437
- } & (ThirdPartyCallFields<TBody> | {
1438
- [P in keyof ThirdPartyCallFields]?: never;
1439
- });
1440
- type RawStep = {
1441
- messageId: string;
1442
- body: string;
1443
- callType: "step" | "toCallback" | "fromCallback";
1444
- };
1445
- type SyncStepFunction<TResult> = () => TResult;
1446
- type AsyncStepFunction<TResult> = () => Promise<TResult>;
1447
- type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
1448
- type ParallelCallState = "first" | "partial" | "discard" | "last";
1449
- type RouteFunction<TInitialPayload> = (context: WorkflowContext<TInitialPayload>) => Promise<void>;
1450
- type WorkflowServeParameters<TInitialPayload, TResponse = Response> = {
1451
- routeFunction: RouteFunction<TInitialPayload>;
1452
- options?: WorkflowServeOptions<TResponse, TInitialPayload>;
1453
- };
1454
- /**
1455
- * Not all frameworks use env variables like nextjs does. In this case, we need
1456
- * to be able to get the client and receiver explicitly.
1457
- *
1458
- * In this case, we extend the WorkflowServeParameters by requiring an explicit
1459
- * client & receiever parameters and removing client & receiever from options.
1460
- */
1461
- type WorkflowServeParametersExtended<TInitialPayload = unknown, TResponse = Response> = Pick<WorkflowServeParameters<TInitialPayload, TResponse>, "routeFunction"> & {
1462
- client: Client;
1463
- receiver: WorkflowServeOptions["receiver"];
1464
- options?: Omit<WorkflowServeOptions<TResponse, TInitialPayload>, "client" | "receiver">;
1465
- };
1466
- type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback";
1467
- type WorkflowServeOptions<TResponse = Response, TInitialPayload = unknown> = {
1468
- /**
1469
- * QStash client
1470
- */
1471
- client?: Client;
1472
- /**
1473
- * Function called to return a response after each step execution
1474
- *
1475
- * @param workflowRunId
1476
- * @returns response
1477
- */
1478
- onStepFinish?: (workflowRunId: string, finishCondition: FinishCondition) => TResponse;
1479
- /**
1480
- * Function to parse the initial payload passed by the user
1481
- */
1482
- initialPayloadParser?: (initialPayload: string) => TInitialPayload;
1483
- /**
1484
- * Url of the endpoint where the workflow is set up.
1485
- *
1486
- * If not set, url will be inferred from the request.
1487
- */
1488
- url?: string;
1489
- /**
1490
- * Verbose mode
1491
- *
1492
- * Disabled if set to false. If set to true, a logger is created automatically.
1493
- *
1494
- * Alternatively, a WorkflowLogger can be passed.
1495
- *
1496
- * Disabled by default
1497
- */
1498
- verbose?: WorkflowLogger | boolean;
1499
- /**
1500
- * Receiver to verify requests coming from QStash
1501
- *
1502
- * All requests except the first invocation are verified.
1503
- *
1504
- * Enabled by default. A receiver is created from the env variables
1505
- * QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY.
1506
- */
1507
- receiver?: Receiver | false;
1508
- /**
1509
- *
1510
- */
1511
- failureUrl?: string | false;
1512
- failureFunction?: ((status: number, header: Record<string, string>, body: string) => Promise<void>) | false;
1513
- };
1514
-
1515
- export { WorkflowContext as $, type AddEndpointsRequest as A, type BodyInit as B, type ChatRateLimit as C, type ChatCompletion as D, type EventsRequest as E, type ChatCompletionChunk as F, type GetEventsResponse as G, type HTTPMethods as H, type StreamEnabled as I, type StreamDisabled as J, type StreamParameter as K, type PromptChatRequest as L, type Message as M, type ChatRequest as N, type OpenAIChatModel as O, type PublishBatchRequest as P, type QueueRequest as Q, type RateLimit as R, type Step as S, custom as T, type UrlGroup as U, type VerifyRequest as V, type WithCursor as W, openai as X, upstash as Y, type ProviderReturnType as Z, type WorkflowServeParameters as _, type ReceiverConfig as a, DisabledWorkflowContext as a0, StepTypes as a1, type StepType as a2, type RawStep as a3, type SyncStepFunction as a4, type AsyncStepFunction as a5, type StepFunction as a6, type ParallelCallState as a7, type RouteFunction as a8, type WorkflowServeParametersExtended as a9, type FinishCondition as aa, type WorkflowServeOptions as ab, type LogLevel as ac, type WorkflowLoggerOptions as ad, WorkflowLogger as ae, SignatureError as b, Receiver as c, type PublishRequest as d, type PublishJsonRequest as e, Client as f, type PublishToApiResponse as g, type PublishToUrlResponse as h, type PublishToUrlGroupsResponse as i, type PublishResponse as j, type MessagePayload as k, Messages as l, type Schedule as m, type CreateScheduleRequest as n, Schedules as o, type Endpoint as p, type RemoveEndpointsRequest as q, UrlGroups as r, type State as s, type Event as t, type EventPayload as u, type GetEventsPayload as v, type HeadersInit as w, type RequestOptions as x, Chat as y, type ChatCompletionMessage as z };