@upstash/qstash 2.7.0-workflow-alpha.3 → 2.7.0-workflow-alpha.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.
Files changed (61) hide show
  1. package/dist/base/index.d.mts +1276 -0
  2. package/dist/base/index.d.ts +1276 -0
  3. package/dist/base/index.js +2 -0
  4. package/dist/base/index.mjs +2 -0
  5. package/dist/cloudlfare/cloudflare.d.mts +1645 -0
  6. package/dist/cloudlfare/cloudflare.d.ts +1645 -0
  7. package/dist/cloudlfare/cloudflare.js +10 -0
  8. package/dist/cloudlfare/cloudflare.mjs +10 -0
  9. package/dist/h3/h3.d.mts +1630 -0
  10. package/dist/h3/h3.d.ts +1630 -0
  11. package/dist/h3/h3.js +10 -0
  12. package/dist/h3/h3.mjs +10 -0
  13. package/dist/hono/hono.d.mts +1638 -0
  14. package/dist/hono/hono.d.ts +1638 -0
  15. package/dist/hono/hono.js +10 -0
  16. package/dist/hono/hono.mjs +10 -0
  17. package/dist/nextjs/nextjs.d.mts +1650 -0
  18. package/dist/nextjs/nextjs.d.ts +1650 -0
  19. package/dist/nextjs/nextjs.js +10 -0
  20. package/dist/nextjs/nextjs.mjs +10 -0
  21. package/dist/solidjs/solidjs.d.mts +1635 -0
  22. package/dist/solidjs/solidjs.d.ts +1635 -0
  23. package/dist/solidjs/solidjs.js +10 -0
  24. package/dist/solidjs/solidjs.mjs +10 -0
  25. package/dist/svelte/svelte.d.mts +1637 -0
  26. package/dist/svelte/svelte.d.ts +1637 -0
  27. package/dist/svelte/svelte.js +10 -0
  28. package/dist/svelte/svelte.mjs +10 -0
  29. package/{client-CMBMVtW3.d.mts → dist/workflow/index.d.mts} +799 -833
  30. package/{client-CMBMVtW3.d.ts → dist/workflow/index.d.ts} +799 -833
  31. package/dist/workflow/index.js +10 -0
  32. package/dist/workflow/index.mjs +10 -0
  33. package/package.json +1 -1
  34. package/chunk-IJ5AEYLN.js +0 -1
  35. package/chunk-M4XG6QUQ.mjs +0 -2876
  36. package/chunk-NYJWM6N6.js +0 -2876
  37. package/chunk-S7JMIMW4.mjs +0 -0
  38. package/index.d.mts +0 -54
  39. package/index.d.ts +0 -54
  40. package/index.js +0 -41
  41. package/index.mjs +0 -41
  42. package/nextjs.d.mts +0 -28
  43. package/nextjs.d.ts +0 -28
  44. package/nextjs.js +0 -163
  45. package/nextjs.mjs +0 -163
  46. package/nuxt.d.mts +0 -17
  47. package/nuxt.d.ts +0 -17
  48. package/nuxt.js +0 -87
  49. package/nuxt.mjs +0 -87
  50. package/solidjs.d.mts +0 -13
  51. package/solidjs.d.ts +0 -13
  52. package/solidjs.js +0 -63
  53. package/solidjs.mjs +0 -63
  54. package/svelte.d.mts +0 -13
  55. package/svelte.d.ts +0 -13
  56. package/svelte.js +0 -62
  57. package/svelte.mjs +0 -62
  58. package/workflow.d.mts +0 -2
  59. package/workflow.d.ts +0 -2
  60. package/workflow.js +0 -18
  61. package/workflow.mjs +0 -18
@@ -0,0 +1,1276 @@
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
+ declare class Chat {
497
+ private http;
498
+ private token;
499
+ constructor(http: Requester, token: string);
500
+ private static toChatRequest;
501
+ /**
502
+ * Calls the Upstash completions api given a ChatRequest.
503
+ *
504
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
505
+ * if stream is enabled.
506
+ *
507
+ * @param request ChatRequest with messages
508
+ * @returns Chat completion or stream
509
+ */
510
+ create: <TStream extends StreamParameter>(request: ChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
511
+ /**
512
+ * Calls the Upstash completions api given a ChatRequest.
513
+ *
514
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
515
+ * if stream is enabled.
516
+ *
517
+ * @param request ChatRequest with messages
518
+ * @returns Chat completion or stream
519
+ */
520
+ private createThirdParty;
521
+ private getAuthorizationToken;
522
+ /**
523
+ * Calls the Upstash completions api given a PromptRequest.
524
+ *
525
+ * Returns a ChatCompletion or a stream of ChatCompletionChunks
526
+ * if stream is enabled.
527
+ *
528
+ * @param request PromptRequest with system and user messages.
529
+ * Note that system parameter shouldn't be passed in the case of
530
+ * mistralai/Mistral-7B-Instruct-v0.2 model.
531
+ * @returns Chat completion or stream
532
+ */
533
+ prompt: <TStream extends StreamParameter>(request: PromptChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
534
+ }
535
+
536
+ type QueueResponse = {
537
+ createdAt: number;
538
+ updatedAt: number;
539
+ name: string;
540
+ parallelism: number;
541
+ lag: number;
542
+ paused: boolean;
543
+ };
544
+ type UpsertQueueRequest = {
545
+ /**
546
+ * The number of parallel consumers consuming from the queue.
547
+ *
548
+ * @default 1
549
+ */
550
+ parallelism?: number;
551
+ /**
552
+ * Whether to pause the queue or not. A paused queue will not
553
+ * deliver new messages until it is resumed.
554
+ *
555
+ * @default false
556
+ */
557
+ paused?: boolean;
558
+ };
559
+ declare class Queue {
560
+ private readonly http;
561
+ private readonly queueName;
562
+ constructor(http: Requester, queueName?: string);
563
+ /**
564
+ * Create or update the queue
565
+ */
566
+ upsert(request: UpsertQueueRequest): Promise<void>;
567
+ /**
568
+ * Get the queue details
569
+ */
570
+ get(): Promise<QueueResponse>;
571
+ /**
572
+ * List queues
573
+ */
574
+ list(): Promise<QueueResponse[]>;
575
+ /**
576
+ * Delete the queue
577
+ */
578
+ delete(): Promise<void>;
579
+ /**
580
+ * Enqueue a message to a queue.
581
+ */
582
+ enqueue<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
583
+ /**
584
+ * Enqueue a message to a queue, serializing the body to JSON.
585
+ */
586
+ enqueueJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
587
+ /**
588
+ * Pauses the queue.
589
+ *
590
+ * A paused queue will not deliver messages until
591
+ * it is resumed.
592
+ */
593
+ pause(): Promise<void>;
594
+ /**
595
+ * Resumes the queue.
596
+ */
597
+ resume(): Promise<void>;
598
+ }
599
+
600
+ type Schedule = {
601
+ scheduleId: string;
602
+ cron: string;
603
+ createdAt: number;
604
+ destination: string;
605
+ method: string;
606
+ header?: Record<string, string[]>;
607
+ body?: string;
608
+ bodyBase64?: string;
609
+ retries: number;
610
+ delay?: number;
611
+ callback?: string;
612
+ failureCallback?: string;
613
+ callerIp?: string;
614
+ isPaused: boolean;
615
+ };
616
+ type CreateScheduleRequest = {
617
+ /**
618
+ * Either a URL or urlGroup name
619
+ */
620
+ destination: string;
621
+ /**
622
+ * The message to send.
623
+ *
624
+ * This can be anything, but please set the `Content-Type` header accordingly.
625
+ *
626
+ * You can leave this empty if you want to send a message with no body.
627
+ */
628
+ body?: BodyInit;
629
+ /**
630
+ * Optionally send along headers with the message.
631
+ * These headers will be sent to your destination.
632
+ *
633
+ * We highly recommend sending a `Content-Type` header along, as this will help your destination
634
+ * server to understand the content of the message.
635
+ */
636
+ headers?: HeadersInit;
637
+ /**
638
+ * Optionally delay the delivery of this message.
639
+ *
640
+ * In seconds.
641
+ *
642
+ * @default undefined
643
+ */
644
+ delay?: number;
645
+ /**
646
+ * In case your destination server is unavailable or returns a status code outside of the 200-299
647
+ * range, we will retry the request after a certain amount of time.
648
+ *
649
+ * Configure how many times you would like the delivery to be retried
650
+ *
651
+ * @default The maximum retry quota associated with your account.
652
+ */
653
+ retries?: number;
654
+ /**
655
+ * Use a callback url to forward the response of your destination server to your callback url.
656
+ *
657
+ * The callback url must be publicly accessible
658
+ *
659
+ * @default undefined
660
+ */
661
+ callback?: string;
662
+ /**
663
+ * Use a failure callback url to handle messages that could not be delivered.
664
+ *
665
+ * The failure callback url must be publicly accessible
666
+ *
667
+ * @default undefined
668
+ */
669
+ failureCallback?: string;
670
+ /**
671
+ * The method to use when sending a request to your API
672
+ *
673
+ * @default `POST`
674
+ */
675
+ method?: HTTPMethods;
676
+ /**
677
+ * Specify a cron expression to repeatedly send this message to the destination.
678
+ */
679
+ cron: string;
680
+ /**
681
+ * The HTTP timeout value to use while calling the destination URL.
682
+ * When a timeout is specified, it will be used instead of the maximum timeout
683
+ * value permitted by the QStash plan. It is useful in scenarios, where a message
684
+ * should be delivered with a shorter timeout.
685
+ *
686
+ * In seconds.
687
+ *
688
+ * @default undefined
689
+ */
690
+ timeout?: number;
691
+ /**
692
+ * Schedule id to use.
693
+ *
694
+ * Can be used to updatine the settings of an existing schedule.
695
+ *
696
+ * @default undefined
697
+ */
698
+ scheduleId?: string;
699
+ };
700
+ declare class Schedules {
701
+ private readonly http;
702
+ constructor(http: Requester);
703
+ /**
704
+ * Create a schedule
705
+ */
706
+ create(request: CreateScheduleRequest): Promise<{
707
+ scheduleId: string;
708
+ }>;
709
+ /**
710
+ * Get a schedule
711
+ */
712
+ get(scheduleId: string): Promise<Schedule>;
713
+ /**
714
+ * List your schedules
715
+ */
716
+ list(): Promise<Schedule[]>;
717
+ /**
718
+ * Delete a schedule
719
+ */
720
+ delete(scheduleId: string): Promise<void>;
721
+ /**
722
+ * Pauses the schedule.
723
+ *
724
+ * A paused schedule will not deliver messages until
725
+ * it is resumed.
726
+ */
727
+ pause({ schedule }: {
728
+ schedule: string;
729
+ }): Promise<void>;
730
+ /**
731
+ * Resumes the schedule.
732
+ */
733
+ resume({ schedule }: {
734
+ schedule: string;
735
+ }): Promise<void>;
736
+ }
737
+
738
+ type Endpoint = {
739
+ /**
740
+ * The name of the endpoint (optional)
741
+ */
742
+ name?: string;
743
+ /**
744
+ * The url of the endpoint
745
+ */
746
+ url: string;
747
+ };
748
+ type AddEndpointsRequest = {
749
+ /**
750
+ * The name of the url group.
751
+ * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
752
+ */
753
+ name: string;
754
+ endpoints: Endpoint[];
755
+ };
756
+ type RemoveEndpointsRequest = {
757
+ /**
758
+ * The name of the url group.
759
+ * Must be unique and only contain alphanumeric, hyphen, underscore and periods.
760
+ */
761
+ name: string;
762
+ endpoints: ({
763
+ name: string;
764
+ url?: string;
765
+ } | {
766
+ name?: string;
767
+ url: string;
768
+ })[];
769
+ };
770
+ type UrlGroup = {
771
+ /**
772
+ * A unix timestamp (milliseconds)
773
+ */
774
+ createdAt: number;
775
+ /**
776
+ * A unix timestamp (milliseconds)
777
+ */
778
+ updatedAt: number;
779
+ /**
780
+ * The name of this url group.
781
+ */
782
+ name: string;
783
+ /**
784
+ * A list of all subscribed endpoints
785
+ */
786
+ endpoints: Endpoint[];
787
+ };
788
+ declare class UrlGroups {
789
+ private readonly http;
790
+ constructor(http: Requester);
791
+ /**
792
+ * Create a new url group with the given name and endpoints
793
+ */
794
+ addEndpoints(request: AddEndpointsRequest): Promise<void>;
795
+ /**
796
+ * Remove endpoints from a url group.
797
+ */
798
+ removeEndpoints(request: RemoveEndpointsRequest): Promise<void>;
799
+ /**
800
+ * Get a list of all url groups.
801
+ */
802
+ list(): Promise<UrlGroup[]>;
803
+ /**
804
+ * Get a single url group
805
+ */
806
+ get(name: string): Promise<UrlGroup>;
807
+ /**
808
+ * Delete a url group
809
+ */
810
+ delete(name: string): Promise<void>;
811
+ }
812
+
813
+ declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call"];
814
+ type StepType = (typeof StepTypes)[number];
815
+ type ThirdPartyCallFields<TBody = unknown> = {
816
+ /**
817
+ * Third party call URL. Set when context.call is used.
818
+ */
819
+ callUrl: string;
820
+ /**
821
+ * Third party call method. Set when context.call is used.
822
+ */
823
+ callMethod: HTTPMethods;
824
+ /**
825
+ * Third party call body. Set when context.call is used.
826
+ */
827
+ callBody: TBody;
828
+ /**
829
+ * Third party call headers. Set when context.call is used.
830
+ */
831
+ callHeaders: Record<string, string>;
832
+ };
833
+ type Step<TResult = unknown, TBody = unknown> = {
834
+ /**
835
+ * index of the step
836
+ */
837
+ stepId: number;
838
+ /**
839
+ * name of the step
840
+ */
841
+ stepName: string;
842
+ /**
843
+ * type of the step (Initial/Run/SleepFor/SleepUntil/Call)
844
+ */
845
+ stepType: StepType;
846
+ /**
847
+ * step result. Set if context.run or context.call are used.
848
+ */
849
+ out?: TResult;
850
+ /**
851
+ * sleep duration in seconds. Set when context.sleep is used.
852
+ */
853
+ sleepFor?: number;
854
+ /**
855
+ * unix timestamp (in seconds) to wait until. Set when context.sleepUntil is used.
856
+ */
857
+ sleepUntil?: number;
858
+ /**
859
+ * number of steps running concurrently if the step is in a parallel run.
860
+ * Set to 1 if step is not parallel.
861
+ */
862
+ concurrent: number;
863
+ /**
864
+ * target step of a plan step. In other words, the step to assign the
865
+ * result of a plan step.
866
+ *
867
+ * undefined if the step is not a plan step (of a parallel run). Otherwise,
868
+ * set to the target step.
869
+ */
870
+ targetStep?: number;
871
+ } & (ThirdPartyCallFields<TBody> | {
872
+ [P in keyof ThirdPartyCallFields]?: never;
873
+ });
874
+ /**
875
+ * Payload passed as body in failureFunction
876
+ */
877
+ type FailureFunctionPayload = {
878
+ /**
879
+ * error name
880
+ */
881
+ error: string;
882
+ /**
883
+ * error message
884
+ */
885
+ message: string;
886
+ };
887
+
888
+ declare class Workflow {
889
+ private readonly http;
890
+ constructor(http: Requester);
891
+ /**
892
+ * Cancel an ongoing workflow
893
+ *
894
+ * @param workflowRunId run id of the workflow to delete
895
+ * @returns true if workflow is succesfully deleted. Otherwise throws QStashError
896
+ */
897
+ cancel(workflowRunId: string): Promise<true | {
898
+ error: string;
899
+ }>;
900
+ }
901
+
902
+ type ClientConfig = {
903
+ /**
904
+ * Url of the QStash api server.
905
+ *
906
+ * This is only used for testing.
907
+ *
908
+ * @default "https://qstash.upstash.io"
909
+ */
910
+ baseUrl?: string;
911
+ /**
912
+ * The authorization token from the upstash console.
913
+ */
914
+ token: string;
915
+ /**
916
+ * Configure how the client should retry requests.
917
+ */
918
+ retry?: RetryConfig;
919
+ };
920
+ type PublishBatchRequest<TBody = BodyInit> = PublishRequest<TBody> & {
921
+ queueName?: string;
922
+ };
923
+ type PublishRequest<TBody = BodyInit> = {
924
+ /**
925
+ * The message to send.
926
+ *
927
+ * This can be anything, but please set the `Content-Type` header accordingly.
928
+ *
929
+ * You can leave this empty if you want to send a message with no body.
930
+ */
931
+ body?: TBody;
932
+ /**
933
+ * Optionally send along headers with the message.
934
+ * These headers will be sent to your destination.
935
+ *
936
+ * We highly recommend sending a `Content-Type` header along, as this will help your destination
937
+ * server to understand the content of the message.
938
+ */
939
+ headers?: HeadersInit;
940
+ /**
941
+ * Optionally delay the delivery of this message.
942
+ *
943
+ * In seconds.
944
+ *
945
+ * @default undefined
946
+ */
947
+ delay?: number;
948
+ /**
949
+ * Optionally set the absolute delay of this message.
950
+ * This will override the delay option.
951
+ * The message will not delivered until the specified time.
952
+ *
953
+ * Unix timestamp in seconds.
954
+ *
955
+ * @default undefined
956
+ */
957
+ notBefore?: number;
958
+ /**
959
+ * Provide a unique id for deduplication. This id will be used to detect duplicate messages.
960
+ * If a duplicate message is detected, the request will be accepted but not enqueued.
961
+ *
962
+ * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
963
+ * same deduplication id is delivered again.
964
+ *
965
+ * When scheduling a message, the deduplication happens before the schedule is created.
966
+ *
967
+ * @default undefined
968
+ */
969
+ deduplicationId?: string;
970
+ /**
971
+ * If true, the message content will get hashed and used as deduplication id.
972
+ * If a duplicate message is detected, the request will be accepted but not enqueued.
973
+ *
974
+ * The content based hash includes the following values:
975
+ * - All headers, except Upstash-Authorization, this includes all headers you are sending.
976
+ * - The entire raw request body The destination from the url path
977
+ *
978
+ * We store deduplication ids for 90 days. Afterwards it is possible that the message with the
979
+ * same deduplication id is delivered again.
980
+ *
981
+ * When scheduling a message, the deduplication happens before the schedule is created.
982
+ *
983
+ * @default false
984
+ */
985
+ contentBasedDeduplication?: boolean;
986
+ /**
987
+ * In case your destination server is unavaialble or returns a status code outside of the 200-299
988
+ * range, we will retry the request after a certain amount of time.
989
+ *
990
+ * Configure how many times you would like the delivery to be retried up to the maxRetries limit
991
+ * defined in your plan.
992
+ *
993
+ * @default 3
994
+ */
995
+ retries?: number;
996
+ /**
997
+ * Use a failure callback url to handle messages that could not be delivered.
998
+ *
999
+ * The failure callback url must be publicly accessible
1000
+ *
1001
+ * @default undefined
1002
+ */
1003
+ failureCallback?: string;
1004
+ /**
1005
+ * The method to use when sending a request to your API
1006
+ *
1007
+ * @default `POST`
1008
+ */
1009
+ method?: HTTPMethods;
1010
+ /**
1011
+ * The HTTP timeout value to use while calling the destination URL.
1012
+ * When a timeout is specified, it will be used instead of the maximum timeout
1013
+ * value permitted by the QStash plan. It is useful in scenarios, where a message
1014
+ * should be delivered with a shorter timeout.
1015
+ *
1016
+ * In seconds.
1017
+ *
1018
+ * @default undefined
1019
+ */
1020
+ timeout?: number;
1021
+ } & ({
1022
+ /**
1023
+ * The url where the message should be sent to.
1024
+ */
1025
+ url: string;
1026
+ urlGroup?: never;
1027
+ api?: never;
1028
+ topic?: never;
1029
+ /**
1030
+ * Use a callback url to forward the response of your destination server to your callback url.
1031
+ *
1032
+ * The callback url must be publicly accessible
1033
+ *
1034
+ * @default undefined
1035
+ */
1036
+ callback?: string;
1037
+ } | {
1038
+ url?: never;
1039
+ /**
1040
+ * The url group the message should be sent to.
1041
+ */
1042
+ urlGroup: string;
1043
+ api?: never;
1044
+ topic?: never;
1045
+ /**
1046
+ * Use a callback url to forward the response of your destination server to your callback url.
1047
+ *
1048
+ * The callback url must be publicly accessible
1049
+ *
1050
+ * @default undefined
1051
+ */
1052
+ callback?: string;
1053
+ } | {
1054
+ url?: string;
1055
+ urlGroup?: never;
1056
+ /**
1057
+ * The api endpoint the request should be sent to.
1058
+ */
1059
+ api: {
1060
+ name: "llm";
1061
+ provider?: ProviderReturnType;
1062
+ analytics?: {
1063
+ name: "helicone";
1064
+ token: string;
1065
+ };
1066
+ };
1067
+ /**
1068
+ * Use a callback url to forward the response of your destination server to your callback url.
1069
+ *
1070
+ * The callback url must be publicly accessible
1071
+ *
1072
+ * @default undefined
1073
+ */
1074
+ callback: string;
1075
+ topic?: never;
1076
+ } | {
1077
+ url?: never;
1078
+ urlGroup?: never;
1079
+ api: never;
1080
+ /**
1081
+ * Deprecated. The topic the message should be sent to. Same as urlGroup
1082
+ */
1083
+ topic?: string;
1084
+ /**
1085
+ * Use a callback url to forward the response of your destination server to your callback url.
1086
+ *
1087
+ * The callback url must be publicly accessible
1088
+ *
1089
+ * @default undefined
1090
+ */
1091
+ callback?: string;
1092
+ });
1093
+ type PublishJsonRequest = Omit<PublishRequest, "body"> & {
1094
+ /**
1095
+ * The message to send.
1096
+ * This can be anything as long as it can be serialized to JSON.
1097
+ */
1098
+ body: unknown;
1099
+ };
1100
+ type EventsRequest = {
1101
+ cursor?: number;
1102
+ filter?: EventsRequestFilter;
1103
+ };
1104
+ type EventsRequestFilter = {
1105
+ messageId?: string;
1106
+ state?: State;
1107
+ url?: string;
1108
+ urlGroup?: string;
1109
+ topicName?: string;
1110
+ api?: string;
1111
+ scheduleId?: string;
1112
+ queueName?: string;
1113
+ fromDate?: number;
1114
+ toDate?: number;
1115
+ count?: number;
1116
+ };
1117
+ type GetEventsResponse = {
1118
+ cursor?: number;
1119
+ events: Event[];
1120
+ };
1121
+ type QueueRequest = {
1122
+ queueName?: string;
1123
+ };
1124
+ declare class Client {
1125
+ http: Requester;
1126
+ private token;
1127
+ constructor(config: ClientConfig);
1128
+ /**
1129
+ * Access the urlGroup API.
1130
+ *
1131
+ * Create, read, update or delete urlGroups.
1132
+ */
1133
+ get urlGroups(): UrlGroups;
1134
+ /**
1135
+ * Deprecated. Use urlGroups instead.
1136
+ *
1137
+ * Access the topic API.
1138
+ *
1139
+ * Create, read, update or delete topics.
1140
+ */
1141
+ get topics(): UrlGroups;
1142
+ /**
1143
+ * Access the dlq API.
1144
+ *
1145
+ * List or remove messages from the DLQ.
1146
+ */
1147
+ get dlq(): DLQ;
1148
+ /**
1149
+ * Access the message API.
1150
+ *
1151
+ * Read or cancel messages.
1152
+ */
1153
+ get messages(): Messages;
1154
+ /**
1155
+ * Access the schedule API.
1156
+ *
1157
+ * Create, read or delete schedules.
1158
+ */
1159
+ get schedules(): Schedules;
1160
+ /**
1161
+ * Access the workflow API.
1162
+ *
1163
+ * cancel workflows.
1164
+ */
1165
+ get workflow(): Workflow;
1166
+ /**
1167
+ * Access the queue API.
1168
+ *
1169
+ * Create, read, update or delete queues.
1170
+ */
1171
+ queue(request?: QueueRequest): Queue;
1172
+ /**
1173
+ * Access the Chat API
1174
+ *
1175
+ * Call the create or prompt methods
1176
+ */
1177
+ chat(): Chat;
1178
+ publish<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
1179
+ /**
1180
+ * publishJSON is a utility wrapper around `publish` that automatically serializes the body
1181
+ * and sets the `Content-Type` header to `application/json`.
1182
+ */
1183
+ publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
1184
+ /**
1185
+ * Batch publish messages to QStash.
1186
+ */
1187
+ batch(request: PublishBatchRequest[]): Promise<PublishResponse<PublishRequest>[]>;
1188
+ /**
1189
+ * Batch publish messages to QStash, serializing each body to JSON.
1190
+ */
1191
+ batchJSON<TBody = unknown, TRequest extends PublishBatchRequest<TBody> = PublishBatchRequest<TBody>>(request: TRequest[]): Promise<PublishResponse<TRequest>[]>;
1192
+ /**
1193
+ * Retrieve your logs.
1194
+ *
1195
+ * The logs endpoint is paginated and returns only 100 logs at a time.
1196
+ * If you want to receive more logs, you can use the cursor to paginate.
1197
+ *
1198
+ * The cursor is a unix timestamp with millisecond precision
1199
+ *
1200
+ * @example
1201
+ * ```ts
1202
+ * let cursor = Date.now()
1203
+ * const logs: Log[] = []
1204
+ * while (cursor > 0) {
1205
+ * const res = await qstash.logs({ cursor })
1206
+ * logs.push(...res.logs)
1207
+ * cursor = res.cursor ?? 0
1208
+ * }
1209
+ * ```
1210
+ */
1211
+ events(request?: EventsRequest): Promise<GetEventsResponse>;
1212
+ }
1213
+ type PublishToApiResponse = {
1214
+ messageId: string;
1215
+ };
1216
+ type PublishToUrlResponse = PublishToApiResponse & {
1217
+ url: string;
1218
+ deduplicated?: boolean;
1219
+ };
1220
+ type PublishToUrlGroupsResponse = PublishToUrlResponse[];
1221
+ type PublishResponse<TRequest> = TRequest extends {
1222
+ url: string;
1223
+ } ? PublishToUrlResponse : TRequest extends {
1224
+ urlGroup: string;
1225
+ } ? PublishToUrlGroupsResponse : PublishToApiResponse;
1226
+
1227
+ /**
1228
+ * Result of 500 Internal Server Error
1229
+ */
1230
+ declare class QstashError extends Error {
1231
+ constructor(message: string);
1232
+ }
1233
+ declare class QstashRatelimitError extends QstashError {
1234
+ limit: string | null;
1235
+ remaining: string | null;
1236
+ reset: string | null;
1237
+ constructor(args: RateLimit);
1238
+ }
1239
+ declare class QstashChatRatelimitError extends QstashError {
1240
+ limitRequests: string | null;
1241
+ limitTokens: string | null;
1242
+ remainingRequests: string | null;
1243
+ remainingTokens: string | null;
1244
+ resetRequests: string | null;
1245
+ resetTokens: string | null;
1246
+ constructor(args: ChatRateLimit);
1247
+ }
1248
+ declare class QstashDailyRatelimitError extends QstashError {
1249
+ limit: string | null;
1250
+ remaining: string | null;
1251
+ reset: string | null;
1252
+ constructor(args: RateLimit);
1253
+ }
1254
+ /**
1255
+ * Error raised during Workflow execution
1256
+ */
1257
+ declare class QStashWorkflowError extends QstashError {
1258
+ constructor(message: string);
1259
+ }
1260
+ /**
1261
+ * Raised when the workflow executes a function and aborts
1262
+ */
1263
+ declare class QStashWorkflowAbort extends Error {
1264
+ stepInfo?: Step;
1265
+ stepName: string;
1266
+ constructor(stepName: string, stepInfo?: Step);
1267
+ }
1268
+ /**
1269
+ * Formats an unknown error to match the FailureFunctionPayload format
1270
+ *
1271
+ * @param error
1272
+ * @returns
1273
+ */
1274
+ declare const formatWorkflowError: (error: unknown) => FailureFunctionPayload;
1275
+
1276
+ 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 };