@upstash/qstash 2.6.4-workflow-alpha.4 → 2.6.5

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