@upstash/qstash 2.7.0-canary-1 → 2.7.0-workflow-alpha.2

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/index.d.mts CHANGED
@@ -1,1061 +1,54 @@
1
+ import { R as RateLimit, C as ChatRateLimit, S as Step, F as FailureFunctionPayload } from './client-BBvt1wQq.mjs';
2
+ export { A as AddEndpointsRequest, $ as AnalyticsConfig, a0 as AnalyticsSetup, B as BodyInit, y as Chat, D as ChatCompletion, I as ChatCompletionChunk, z as ChatCompletionMessage, T as ChatRequest, f as Client, n as CreateScheduleRequest, p as Endpoint, t as Event, u as EventPayload, E as EventsRequest, v as GetEventsPayload, G as GetEventsResponse, H as HTTPMethods, w as HeadersInit, M as Message, k as MessagePayload, l as Messages, O as OpenAIChatModel, N as PromptChatRequest, _ as ProviderReturnType, P as PublishBatchRequest, e as PublishJsonRequest, d as PublishRequest, j as PublishResponse, g as PublishToApiResponse, i as PublishToUrlGroupsResponse, h as PublishToUrlResponse, Q as QueueRequest, c as Receiver, a as ReceiverConfig, q as RemoveEndpointsRequest, x as RequestOptions, m as Schedule, o as Schedules, b as SignatureError, s as State, K as StreamDisabled, J as StreamEnabled, L as StreamParameter, U as UrlGroup, r as UrlGroups, V as VerifyRequest, W as WithCursor, X as custom, Y as openai, a1 as setupAnalytics, Z as upstash } from './client-BBvt1wQq.mjs';
3
+ import 'neverthrow';
4
+
1
5
  /**
2
- * Necessary to verify the signature of a request.
6
+ * Result of 500 Internal Server Error
3
7
  */
4
- type ReceiverConfig = {
5
- /**
6
- * The current signing key. Get it from `https://console.upstash.com/qstash
7
- */
8
- currentSigningKey: string;
9
- /**
10
- * The next signing key. Get it from `https://console.upstash.com/qstash
11
- */
12
- nextSigningKey: string;
13
- };
14
- type VerifyRequest = {
15
- /**
16
- * The signature from the `upstash-signature` header.
17
- */
18
- signature: string;
19
- /**
20
- * The raw request body.
21
- */
22
- body: string;
23
- /**
24
- * URL of the endpoint where the request was sent to.
25
- *
26
- * Omit empty to disable checking the url.
27
- */
28
- url?: string;
29
- /**
30
- * Number of seconds to tolerate when checking `nbf` and `exp` claims, to deal with small clock differences among different servers
31
- *
32
- * @default 0
33
- */
34
- clockTolerance?: number;
35
- };
36
- declare class SignatureError extends Error {
8
+ declare class QstashError extends Error {
37
9
  constructor(message: string);
38
10
  }
39
- /**
40
- * Receiver offers a simple way to verify the signature of a request.
41
- */
42
- declare class Receiver {
43
- private readonly currentSigningKey;
44
- private readonly nextSigningKey;
45
- constructor(config: ReceiverConfig);
46
- /**
47
- * Verify the signature of a request.
48
- *
49
- * Tries to verify the signature with the current signing key.
50
- * If that fails, maybe because you have rotated the keys recently, it will
51
- * try to verify the signature with the next signing key.
52
- *
53
- * If that fails, the signature is invalid and a `SignatureError` is thrown.
54
- */
55
- verify(request: VerifyRequest): Promise<boolean>;
56
- /**
57
- * Verify signature with a specific signing key
58
- */
59
- private verifyWithKey;
60
- }
61
-
62
- type State = "CREATED" | "ACTIVE" | "DELIVERED" | "ERROR" | "RETRY" | "FAILED";
63
- type Event = {
64
- time: number;
65
- state: State;
66
- messageId: string;
67
- nextDeliveryTime?: number;
68
- error?: string;
69
- url: string;
70
- urlGroup?: string;
71
- endpointName?: string;
72
- header?: Record<string, string>;
73
- body?: string;
74
- };
75
- type EventPayload = Omit<Event, "urlGroup"> & {
76
- topicName: string;
77
- };
78
- type GetEventsPayload = {
79
- cursor?: number;
80
- events: EventPayload[];
81
- };
82
- type WithCursor<T> = T & {
83
- cursor?: number;
84
- };
85
- type BodyInit = Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | string;
86
- type HeadersInit = Headers | Record<string, string> | [string, string][] | IterableIterator<[string, string]>;
87
- type RequestOptions = RequestInit & {
88
- backend?: string;
89
- };
90
- type ChatRateLimit = {
91
- "limit-requests": string | null;
92
- "limit-tokens": string | null;
93
- "remaining-requests": string | null;
94
- "remaining-tokens": string | null;
95
- "reset-requests": string | null;
96
- "reset-tokens": string | null;
97
- };
98
- type RateLimit = {
11
+ declare class QstashRatelimitError extends QstashError {
99
12
  limit: string | null;
100
13
  remaining: string | null;
101
14
  reset: string | null;
102
- };
103
-
104
- type ProviderReturnType = {
105
- owner: "upstash" | "openai" | "custom";
106
- baseUrl: string;
107
- token: string;
108
- };
109
- declare const upstash: () => {
110
- owner: "upstash";
111
- baseUrl: "https://qstash.upstash.io/llm";
112
- token: string;
113
- };
114
- declare const openai: ({ token, }: {
115
- token: string;
116
- }) => {
117
- owner: "openai";
118
- baseUrl: "https://api.openai.com";
119
- token: string;
120
- };
121
- declare const custom: ({ baseUrl, token, }: {
122
- token: string;
123
- baseUrl: string;
124
- }) => {
125
- owner: "custom";
126
- baseUrl: string;
127
- token: string;
128
- };
129
-
130
- type ChatCompletionMessage = {
131
- role: "system" | "assistant" | "user";
132
- content: string;
133
- };
134
- type ChatModel = "meta-llama/Meta-Llama-3-8B-Instruct" | "mistralai/Mistral-7B-Instruct-v0.2";
135
- type ChatResponseFormat = {
136
- type: "text" | "json_object";
137
- };
138
- type TopLogprob = {
139
- token: string;
140
- bytes: number[];
141
- logprob: number;
142
- };
143
- type ChatCompletionTokenLogprob = {
144
- token: string;
145
- bytes: number[];
146
- logprob: number;
147
- top_logprobs: TopLogprob[];
148
- };
149
- type ChoiceLogprobs = {
150
- content: ChatCompletionTokenLogprob[];
151
- };
152
- type Choice = {
153
- finish_reason: "stop" | "length";
154
- index: number;
155
- logprobs: ChoiceLogprobs;
156
- message: ChatCompletionMessage;
157
- };
158
- type CompletionUsage = {
159
- completion_tokens: number;
160
- prompt_tokens: number;
161
- total_tokens: number;
162
- };
163
- type ChatCompletion = {
164
- id: string;
165
- choices: Choice[];
166
- created: number;
167
- model: string;
168
- object: "chat.completion";
169
- system_fingerprint: string;
170
- usage: CompletionUsage;
171
- };
172
- type ChunkChoice = {
173
- delta: ChatCompletionMessage;
174
- finish_reason: "stop" | "length";
175
- index: number;
176
- logprobs: ChoiceLogprobs;
177
- };
178
- type ChatCompletionChunk = {
179
- id: string;
180
- choices: ChunkChoice[];
181
- created: number;
182
- model: string;
183
- object: "chat.completion.chunk";
184
- system_fingerprint: string;
185
- usage: CompletionUsage;
186
- };
187
- type StreamEnabled = {
188
- stream: true;
189
- };
190
- type StreamDisabled = {
191
- stream: false;
192
- } | object;
193
- type StreamParameter = StreamEnabled | StreamDisabled;
194
- 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";
195
- type ChatRequestCommonFields = {
196
- frequency_penalty?: number;
197
- logit_bias?: Record<string, number>;
198
- logprobs?: boolean;
199
- top_logprobs?: number;
200
- max_tokens?: number;
201
- n?: number;
202
- presence_penalty?: number;
203
- response_format?: ChatResponseFormat;
204
- seed?: number;
205
- stop?: string | string[];
206
- temperature?: number;
207
- top_p?: number;
208
- };
209
- type PromptChatRequestFields = ChatRequestCommonFields & {
210
- system: string;
211
- user: string;
212
- };
213
- type ChatRequestFields = ChatRequestCommonFields & {
214
- messages: ChatCompletionMessage[];
215
- };
216
- type ChatRequestProviders = {
217
- provider: ProviderReturnType;
218
- model: OpenAIChatModel;
219
- } | {
220
- provider: ProviderReturnType;
221
- model: string;
222
- } | {
223
- provider: ProviderReturnType;
224
- model: ChatModel;
225
- };
226
- type PromptChatRequest<TStream extends StreamParameter> = ChatRequestProviders & PromptChatRequestFields & TStream;
227
- type ChatRequest<TStream extends StreamParameter> = ChatRequestProviders & ChatRequestFields & TStream;
228
-
229
- type UpstashRequest = {
230
- /**
231
- * The path to the resource.
232
- */
233
- path: string[];
234
- /**
235
- * A BodyInit object or null to set request's body.
236
- */
237
- body?: BodyInit | null;
238
- /**
239
- * A Headers object, an object literal, or an array of two-item arrays to set
240
- * request's headers.
241
- */
242
- headers?: HeadersInit;
243
- /**
244
- * A boolean to set request's keepalive.
245
- */
246
- keepalive?: boolean;
247
- /**
248
- * A string to set request's method.
249
- */
250
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
251
- query?: Record<string, string | number | boolean | undefined>;
252
- /**
253
- * if enabled, call `res.json()`
254
- *
255
- * @default true
256
- */
257
- parseResponseAsJson?: boolean;
258
- baseUrl?: string;
259
- };
260
- type UpstashResponse<TResult> = TResult & {
261
- error?: string;
262
- };
263
- type Requester = {
264
- request: <TResult = unknown>(request: UpstashRequest) => Promise<UpstashResponse<TResult>>;
265
- requestStream: (request: UpstashRequest) => AsyncIterable<ChatCompletionChunk>;
266
- };
267
- type RetryConfig = false | {
268
- /**
269
- * The number of retries to attempt before giving up.
270
- *
271
- * @default 5
272
- */
273
- retries?: number;
274
- /**
275
- * A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
276
- *
277
- * @default
278
- * ```ts
279
- * Math.exp(retryCount) * 50
280
- * ```
281
- */
282
- backoff?: (retryCount: number) => number;
283
- };
284
-
285
- type Message = {
286
- /**
287
- * A unique identifier for this message.
288
- */
289
- messageId: string;
290
- /**
291
- * The url group name if this message was sent to a urlGroup.
292
- */
293
- urlGroup?: string;
294
- /**
295
- * The url where this message is sent to.
296
- */
297
- url: string;
298
- /**
299
- * The endpoint name of the message if the endpoint is given a
300
- * name within the url group.
301
- */
302
- endpointName?: string;
303
- /**
304
- * The api name if this message was sent to an api
305
- */
306
- api?: string;
307
- /**
308
- * The http method used to deliver the message
309
- */
310
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
311
- /**
312
- * The http headers sent along with the message to your API.
313
- */
314
- header?: Record<string, string[]>;
315
- /**
316
- * The http body sent to your API
317
- */
318
- body?: string;
319
- /**
320
- * The base64 encoded body if the body contains non-UTF-8 characters,
321
- * `None` otherwise.
322
- */
323
- bodyBase64?: string;
324
- /**
325
- * Maxmimum number of retries.
326
- */
327
- maxRetries?: number;
328
- /**
329
- * A unix timestamp (milliseconds) after which this message may get delivered.
330
- */
331
- notBefore?: number;
332
- /**
333
- * A unix timestamp (milliseconds) when this messages was created.
334
- */
335
- createdAt: number;
336
- /**
337
- * The callback url if configured.
338
- */
339
- callback?: string;
340
- /**
341
- * The failure callback url if configured.
342
- */
343
- failureCallback?: string;
344
- /**
345
- * The queue name if this message was sent to a queue.
346
- */
347
- queueName?: string;
348
- /**
349
- * The scheduleId of the message if the message is triggered by a schedule
350
- */
351
- scheduleId?: string;
352
- /**
353
- * IP address of the publisher of this message
354
- */
355
- callerIp?: string;
356
- };
357
- type MessagePayload = Omit<Message, "urlGroup"> & {
358
- topicName: string;
359
- };
360
- declare class Messages {
361
- private readonly http;
362
- constructor(http: Requester);
363
- /**
364
- * Get a message
365
- */
366
- get(messageId: string): Promise<Message>;
367
- /**
368
- * Cancel a message
369
- */
370
- delete(messageId: string): Promise<void>;
371
- deleteMany(messageIds: string[]): Promise<number>;
372
- deleteAll(): Promise<number>;
373
- }
374
-
375
- type DlqMessage = Message & {
376
- /**
377
- * The unique id within the DLQ
378
- */
379
- dlqId: string;
380
- /**
381
- * The HTTP status code of the last failed delivery attempt
382
- */
383
- responseStatus?: number;
384
- /**
385
- * The response headers of the last failed delivery attempt
386
- */
387
- responseHeader?: Record<string, string[]>;
388
- /**
389
- * The response body of the last failed delivery attempt if it is
390
- * composed of UTF-8 characters only, `None` otherwise.
391
- */
392
- responseBody?: string;
393
- /**
394
- * The base64 encoded response body of the last failed delivery attempt
395
- * if the response body contains non-UTF-8 characters, `None` otherwise.
396
- */
397
- responseBodyBase64?: string;
398
- };
399
- type DLQFilter = {
400
- /**
401
- * Filter DLQ entries by message id
402
- */
403
- messageId?: string;
404
- /**
405
- * Filter DLQ entries by url
406
- */
407
- url?: string;
408
- /**
409
- * Filter DLQ entries by url group name
410
- */
411
- urlGroup?: string;
412
- /**
413
- * Filter DLQ entries by api name
414
- */
415
- api?: string;
416
- /**
417
- * Filter DLQ entries by queue name
418
- */
419
- queueName?: string;
420
- /**
421
- * Filter DLQ entries by schedule id
422
- */
423
- scheduleId?: string;
424
- /**
425
- * Filter DLQ entries by starting time, in milliseconds
426
- */
427
- fromDate?: number;
428
- /**
429
- * Filter DLQ entries by ending time, in milliseconds
430
- */
431
- toDate?: number;
432
- /**
433
- * Filter DLQ entries by HTTP status of the response
434
- */
435
- responseStatus?: number;
436
- /**
437
- * Filter DLQ entries by IP address of the publisher of the message
438
- */
439
- callerIp?: string;
440
- };
441
- declare class DLQ {
442
- private readonly http;
443
- constructor(http: Requester);
444
- /**
445
- * List messages in the dlq
446
- */
447
- listMessages(options?: {
448
- cursor?: string;
449
- count?: number;
450
- filter?: DLQFilter;
451
- }): Promise<{
452
- messages: DlqMessage[];
453
- cursor?: string;
454
- }>;
455
- /**
456
- * Remove a message from the dlq using it's `dlqId`
457
- */
458
- delete(dlqMessageId: string): Promise<void>;
459
- /**
460
- * Remove multiple messages from the dlq using their `dlqId`s
461
- */
462
- deleteMany(request: {
463
- dlqIds: string[];
464
- }): Promise<{
465
- deleted: number;
466
- }>;
467
- }
468
-
469
- declare class Chat {
470
- private http;
471
- private token;
472
- constructor(http: Requester, token: string);
473
- private static toChatRequest;
474
- /**
475
- * Calls the Upstash completions api given a ChatRequest.
476
- *
477
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
478
- * if stream is enabled.
479
- *
480
- * @param request ChatRequest with messages
481
- * @returns Chat completion or stream
482
- */
483
- create: <TStream extends StreamParameter>(request: ChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
484
- /**
485
- * Calls the Upstash completions api given a ChatRequest.
486
- *
487
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
488
- * if stream is enabled.
489
- *
490
- * @param request ChatRequest with messages
491
- * @returns Chat completion or stream
492
- */
493
- private createThirdParty;
494
- /**
495
- * Calls the Upstash completions api given a PromptRequest.
496
- *
497
- * Returns a ChatCompletion or a stream of ChatCompletionChunks
498
- * if stream is enabled.
499
- *
500
- * @param request PromptRequest with system and user messages.
501
- * Note that system parameter shouldn't be passed in the case of
502
- * mistralai/Mistral-7B-Instruct-v0.2 model.
503
- * @returns Chat completion or stream
504
- */
505
- prompt: <TStream extends StreamParameter>(request: PromptChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
506
- }
507
-
508
- type QueueResponse = {
509
- createdAt: number;
510
- updatedAt: number;
511
- name: string;
512
- parallelism: number;
513
- lag: number;
514
- paused?: boolean;
515
- };
516
- type UpsertQueueRequest = {
517
- /**
518
- * The number of parallel consumers consuming from the queue.
519
- *
520
- * @default 1
521
- */
522
- parallelism?: number;
523
- /**
524
- * Whether to pause the queue or not. A paused queue will not
525
- * deliver new messages until it is resumed.
526
- *
527
- * @default false
528
- */
529
- paused?: boolean;
530
- };
531
- declare class Queue {
532
- private readonly http;
533
- private readonly queueName;
534
- constructor(http: Requester, queueName?: string);
535
- /**
536
- * Create or update the queue
537
- */
538
- upsert(request: UpsertQueueRequest): Promise<void>;
539
- /**
540
- * Get the queue details
541
- */
542
- get(): Promise<QueueResponse>;
543
- /**
544
- * List queues
545
- */
546
- list(): Promise<QueueResponse[]>;
547
- /**
548
- * Delete the queue
549
- */
550
- delete(): Promise<void>;
551
- /**
552
- * Enqueue a message to a queue.
553
- */
554
- enqueue<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
555
- /**
556
- * Enqueue a message to a queue, serializing the body to JSON.
557
- */
558
- enqueueJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
559
- /**
560
- * Pauses the queue.
561
- *
562
- * A paused queue will not deliver messages until
563
- * it is resumed.
564
- */
565
- pause(): Promise<void>;
566
- /**
567
- * Resumes the queue.
568
- */
569
- resume(): Promise<void>;
570
- }
571
-
572
- type Schedule = {
573
- scheduleId: string;
574
- cron: string;
575
- createdAt: number;
576
- destination: string;
577
- method: string;
578
- header?: Record<string, string[]>;
579
- body?: string;
580
- bodyBase64?: string;
581
- retries: number;
582
- delay?: number;
583
- callback?: string;
584
- failureCallback?: string;
585
- callerIp?: string;
586
- isPaused: true | undefined;
587
- };
588
- type CreateScheduleRequest = {
589
- /**
590
- * Either a URL or urlGroup name
591
- */
592
- destination: string;
593
- /**
594
- * The message to send.
595
- *
596
- * This can be anything, but please set the `Content-Type` header accordingly.
597
- *
598
- * You can leave this empty if you want to send a message with no body.
599
- */
600
- body?: BodyInit;
601
- /**
602
- * Optionally send along headers with the message.
603
- * These headers will be sent to your destination.
604
- *
605
- * We highly recommend sending a `Content-Type` header along, as this will help your destination
606
- * server to understand the content of the message.
607
- */
608
- headers?: HeadersInit;
609
- /**
610
- * Optionally delay the delivery of this message.
611
- *
612
- * In seconds.
613
- *
614
- * @default undefined
615
- */
616
- delay?: number;
617
- /**
618
- * In case your destination server is unavailable or returns a status code outside of the 200-299
619
- * range, we will retry the request after a certain amount of time.
620
- *
621
- * Configure how many times you would like the delivery to be retried
622
- *
623
- * @default The maximum retry quota associated with your account.
624
- */
625
- retries?: number;
626
- /**
627
- * Use a callback url to forward the response of your destination server to your callback url.
628
- *
629
- * The callback url must be publicly accessible
630
- *
631
- * @default undefined
632
- */
633
- callback?: string;
634
- /**
635
- * Use a failure callback url to handle messages that could not be delivered.
636
- *
637
- * The failure callback url must be publicly accessible
638
- *
639
- * @default undefined
640
- */
641
- failureCallback?: string;
642
- /**
643
- * The method to use when sending a request to your API
644
- *
645
- * @default `POST`
646
- */
647
- method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
648
- /**
649
- * Specify a cron expression to repeatedly send this message to the destination.
650
- */
651
- cron: string;
652
- /**
653
- * The HTTP timeout value to use while calling the destination URL.
654
- * When a timeout is specified, it will be used instead of the maximum timeout
655
- * value permitted by the QStash plan. It is useful in scenarios, where a message
656
- * should be delivered with a shorter timeout.
657
- *
658
- * In seconds.
659
- *
660
- * @default undefined
661
- */
662
- timeout?: number;
663
- };
664
- declare class Schedules {
665
- private readonly http;
666
- constructor(http: Requester);
667
- /**
668
- * Create a schedule
669
- */
670
- create(request: CreateScheduleRequest): Promise<{
671
- scheduleId: string;
672
- }>;
673
- /**
674
- * Get a schedule
675
- */
676
- get(scheduleId: string): Promise<Schedule>;
677
- /**
678
- * List your schedules
679
- */
680
- list(): Promise<Schedule[]>;
681
- /**
682
- * Delete a schedule
683
- */
684
- delete(scheduleId: string): Promise<void>;
685
- /**
686
- * Pauses the schedule.
687
- *
688
- * A paused schedule will not deliver messages until
689
- * it is resumed.
690
- */
691
- pause({ schedule }: {
692
- schedule: string;
693
- }): Promise<void>;
694
- /**
695
- * Resumes the schedule.
696
- */
697
- resume({ schedule }: {
698
- schedule: string;
699
- }): Promise<void>;
15
+ constructor(args: RateLimit);
700
16
  }
701
-
702
- type Endpoint = {
703
- /**
704
- * The name of the endpoint (optional)
705
- */
706
- name?: string;
707
- /**
708
- * The url of the endpoint
709
- */
710
- url: string;
711
- };
712
- type AddEndpointsRequest = {
713
- /**
714
- * The name of the url group.
715
- * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
716
- */
717
- name: string;
718
- endpoints: Endpoint[];
719
- };
720
- type RemoveEndpointsRequest = {
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: ({
727
- name: string;
728
- url?: string;
729
- } | {
730
- name?: string;
731
- url: string;
732
- })[];
733
- };
734
- type UrlGroup = {
735
- /**
736
- * A unix timestamp (milliseconds)
737
- */
738
- createdAt: number;
739
- /**
740
- * A unix timestamp (milliseconds)
741
- */
742
- updatedAt: number;
743
- /**
744
- * The name of this url group.
745
- */
746
- name: string;
747
- /**
748
- * A list of all subscribed endpoints
749
- */
750
- endpoints: Endpoint[];
751
- };
752
- declare class UrlGroups {
753
- private readonly http;
754
- constructor(http: Requester);
755
- /**
756
- * Create a new url group with the given name and endpoints
757
- */
758
- addEndpoints(request: AddEndpointsRequest): Promise<void>;
759
- /**
760
- * Remove endpoints from a url group.
761
- */
762
- removeEndpoints(request: RemoveEndpointsRequest): Promise<void>;
763
- /**
764
- * Get a list of all url groups.
765
- */
766
- list(): Promise<UrlGroup[]>;
767
- /**
768
- * Get a single url group
769
- */
770
- get(name: string): Promise<UrlGroup>;
771
- /**
772
- * Delete a url group
773
- */
774
- delete(name: string): Promise<void>;
17
+ declare class QstashChatRatelimitError extends QstashError {
18
+ limitRequests: string | null;
19
+ limitTokens: string | null;
20
+ remainingRequests: string | null;
21
+ remainingTokens: string | null;
22
+ resetRequests: string | null;
23
+ resetTokens: string | null;
24
+ constructor(args: ChatRateLimit);
775
25
  }
776
-
777
- type ClientConfig = {
778
- /**
779
- * Url of the qstash api server.
780
- *
781
- * This is only used for testing.
782
- *
783
- * @default "https://qstash.upstash.io"
784
- */
785
- baseUrl?: string;
786
- /**
787
- * The authorization token from the upstash console.
788
- */
789
- token: string;
790
- /**
791
- * Configure how the client should retry requests.
792
- */
793
- retry?: RetryConfig;
794
- };
795
- type PublishBatchRequest<TBody = BodyInit> = PublishRequest<TBody> & {
796
- queueName?: string;
797
- };
798
- type PublishRequest<TBody = BodyInit> = {
799
- /**
800
- * The message to send.
801
- *
802
- * This can be anything, but please set the `Content-Type` header accordingly.
803
- *
804
- * You can leave this empty if you want to send a message with no body.
805
- */
806
- body?: TBody;
807
- /**
808
- * Optionally send along headers with the message.
809
- * These headers will be sent to your destination.
810
- *
811
- * We highly recommend sending a `Content-Type` header along, as this will help your destination
812
- * server to understand the content of the message.
813
- */
814
- headers?: HeadersInit;
815
- /**
816
- * Optionally delay the delivery of this message.
817
- *
818
- * In seconds.
819
- *
820
- * @default undefined
821
- */
822
- delay?: number;
823
- /**
824
- * Optionally set the absolute delay of this message.
825
- * This will override the delay option.
826
- * The message will not delivered until the specified time.
827
- *
828
- * Unix timestamp in seconds.
829
- *
830
- * @default undefined
831
- */
832
- notBefore?: number;
833
- /**
834
- * Provide a unique id for deduplication. This id will be used to detect duplicate messages.
835
- * If a duplicate message is detected, the request will be accepted but not enqueued.
836
- *
837
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
838
- * same deduplication id is delivered again.
839
- *
840
- * When scheduling a message, the deduplication happens before the schedule is created.
841
- *
842
- * @default undefined
843
- */
844
- deduplicationId?: string;
845
- /**
846
- * If true, the message content will get hashed and used as deduplication id.
847
- * If a duplicate message is detected, the request will be accepted but not enqueued.
848
- *
849
- * The content based hash includes the following values:
850
- * - All headers, except Upstash-Authorization, this includes all headers you are sending.
851
- * - The entire raw request body The destination from the url path
852
- *
853
- * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
854
- * same deduplication id is delivered again.
855
- *
856
- * When scheduling a message, the deduplication happens before the schedule is created.
857
- *
858
- * @default false
859
- */
860
- contentBasedDeduplication?: boolean;
861
- /**
862
- * In case your destination server is unavaialble or returns a status code outside of the 200-299
863
- * range, we will retry the request after a certain amount of time.
864
- *
865
- * Configure how many times you would like the delivery to be retried up to the maxRetries limit
866
- * defined in your plan.
867
- *
868
- * @default 3
869
- */
870
- retries?: number;
871
- /**
872
- * Use a callback url to forward the response of your destination server to your callback url.
873
- *
874
- * The callback url must be publicly accessible
875
- *
876
- * @default undefined
877
- */
878
- callback?: string;
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?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
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
- } | {
912
- url?: never;
913
- /**
914
- * The url group the message should be sent to.
915
- */
916
- urlGroup: string;
917
- api?: never;
918
- } | {
919
- url?: string;
920
- urlGroup?: never;
921
- /**
922
- * The api endpoint the request should be sent to.
923
- */
924
- api: {
925
- name: "llm";
926
- provider?: ProviderReturnType;
927
- };
928
- });
929
- type PublishJsonRequest = Omit<PublishRequest, "body"> & {
930
- /**
931
- * The message to send.
932
- * This can be anything as long as it can be serialized to JSON.
933
- */
934
- body: unknown;
935
- };
936
- type EventsRequest = {
937
- cursor?: number;
938
- filter?: EventsRequestFilter;
939
- };
940
- type EventsRequestFilter = {
941
- messageId?: string;
942
- state?: State;
943
- url?: string;
944
- urlGroup?: string;
945
- api?: string;
946
- scheduleId?: string;
947
- queueName?: string;
948
- fromDate?: number;
949
- toDate?: number;
950
- count?: number;
951
- };
952
- type GetEventsResponse = {
953
- cursor?: number;
954
- events: Event[];
955
- };
956
- type QueueRequest = {
957
- queueName?: string;
958
- };
959
- declare class Client {
960
- http: Requester;
961
- private token;
962
- constructor(config: ClientConfig);
963
- /**
964
- * Access the urlGroup API.
965
- *
966
- * Create, read, update or delete urlGroups.
967
- */
968
- get urlGroups(): UrlGroups;
969
- /**
970
- * Access the dlq API.
971
- *
972
- * List or remove messages from the DLQ.
973
- */
974
- get dlq(): DLQ;
975
- /**
976
- * Access the message API.
977
- *
978
- * Read or cancel messages.
979
- */
980
- get messages(): Messages;
981
- /**
982
- * Access the schedule API.
983
- *
984
- * Create, read or delete schedules.
985
- */
986
- get schedules(): Schedules;
987
- /**
988
- * Access the queue API.
989
- *
990
- * Create, read, update or delete queues.
991
- */
992
- queue(request?: QueueRequest): Queue;
993
- /**
994
- * Access the Chat API
995
- *
996
- * Call the create or prompt methods
997
- */
998
- chat(): Chat;
999
- publish<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
1000
- /**
1001
- * publishJSON is a utility wrapper around `publish` that automatically serializes the body
1002
- * and sets the `Content-Type` header to `application/json`.
1003
- */
1004
- publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
1005
- /**
1006
- * Batch publish messages to QStash.
1007
- */
1008
- batch(request: PublishBatchRequest[]): Promise<PublishResponse<PublishRequest>[]>;
1009
- /**
1010
- * Batch publish messages to QStash, serializing each body to JSON.
1011
- */
1012
- batchJSON<TBody = unknown, TRequest extends PublishBatchRequest<TBody> = PublishBatchRequest<TBody>>(request: TRequest[]): Promise<PublishResponse<TRequest>[]>;
1013
- /**
1014
- * Retrieve your logs.
1015
- *
1016
- * The logs endpoint is paginated and returns only 100 logs at a time.
1017
- * If you want to receive more logs, you can use the cursor to paginate.
1018
- *
1019
- * The cursor is a unix timestamp with millisecond precision
1020
- *
1021
- * @example
1022
- * ```ts
1023
- * let cursor = Date.now()
1024
- * const logs: Log[] = []
1025
- * while (cursor > 0) {
1026
- * const res = await qstash.logs({ cursor })
1027
- * logs.push(...res.logs)
1028
- * cursor = res.cursor ?? 0
1029
- * }
1030
- * ```
1031
- */
1032
- events(request?: EventsRequest): Promise<GetEventsResponse>;
26
+ declare class QstashDailyRatelimitError extends QstashError {
27
+ limit: string | null;
28
+ remaining: string | null;
29
+ reset: string | null;
30
+ constructor(args: RateLimit);
1033
31
  }
1034
- type PublishToApiResponse = {
1035
- messageId: string;
1036
- };
1037
- type PublishToUrlResponse = PublishToApiResponse & {
1038
- url: string;
1039
- deduplicated?: boolean;
1040
- };
1041
- type PublishToUrlGroupsResponse = PublishToUrlResponse[];
1042
- type PublishResponse<TRequest> = TRequest extends {
1043
- url: string;
1044
- } ? PublishToUrlResponse : TRequest extends {
1045
- urlGroup: string;
1046
- } ? PublishToUrlGroupsResponse : PublishToApiResponse;
1047
-
1048
32
  /**
1049
- * Result of 500 Internal Server Error
33
+ * Error raised during Workflow execution
1050
34
  */
1051
- declare class QstashError extends Error {
35
+ declare class QstashWorkflowError extends QstashError {
1052
36
  constructor(message: string);
1053
37
  }
1054
- declare class QstashRatelimitError extends QstashError {
1055
- constructor(args: RateLimit);
1056
- }
1057
- declare class QstashChatRatelimitError extends QstashError {
1058
- constructor(args: ChatRateLimit);
38
+ /**
39
+ * Raised when the workflow executes a function and aborts
40
+ */
41
+ declare class QstashWorkflowAbort extends Error {
42
+ stepInfo?: Step;
43
+ stepName: string;
44
+ constructor(stepName: string, stepInfo?: Step);
1059
45
  }
46
+ /**
47
+ * Formats an unknown error to match the FailureFunctionPayload format
48
+ *
49
+ * @param error
50
+ * @returns
51
+ */
52
+ declare const formatWorkflowError: (error: unknown) => FailureFunctionPayload;
1060
53
 
1061
- export { type AddEndpointsRequest, type BodyInit, Chat, type ChatCompletion, type ChatCompletionChunk, type ChatCompletionMessage, type ChatRateLimit, type ChatRequest, Client, type CreateScheduleRequest, type Endpoint, type Event, type EventPayload, type EventsRequest, type GetEventsPayload, type GetEventsResponse, type HeadersInit, type Message, type MessagePayload, Messages, type OpenAIChatModel, type PromptChatRequest, type ProviderReturnType, type PublishBatchRequest, type PublishJsonRequest, type PublishRequest, type PublishResponse, type PublishToApiResponse, type PublishToUrlGroupsResponse, type PublishToUrlResponse, QstashChatRatelimitError, QstashError, QstashRatelimitError, type QueueRequest, type RateLimit, Receiver, type ReceiverConfig, type RemoveEndpointsRequest, type RequestOptions, type Schedule, Schedules, SignatureError, type State, type StreamDisabled, type StreamEnabled, type StreamParameter, type UrlGroup, UrlGroups, type VerifyRequest, type WithCursor, custom, openai, upstash };
54
+ export { ChatRateLimit, QstashChatRatelimitError, QstashDailyRatelimitError, QstashError, QstashRatelimitError, QstashWorkflowAbort, QstashWorkflowError, RateLimit, formatWorkflowError };