@upstash/qstash 2.7.5 → 2.7.6

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