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