@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.
- package/README.md +12 -4
- package/chunk-B3NB4QLV.mjs +2920 -0
- package/chunk-IJ3475FO.mjs +403 -0
- package/chunk-IJ5AEYLN.js +1 -0
- package/chunk-NMSGEGBP.js +403 -0
- package/chunk-S7JMIMW4.mjs +0 -0
- package/chunk-WQZ4U6LJ.js +2920 -0
- package/{dist/workflow/index.d.mts → client-aUVEwn93.d.mts} +868 -800
- package/{dist/nextjs/index.d.mts → client-aUVEwn93.d.ts} +871 -743
- package/cloudflare.d.mts +33 -0
- package/cloudflare.d.ts +33 -0
- package/cloudflare.js +37 -0
- package/cloudflare.mjs +37 -0
- package/h3.d.mts +17 -0
- package/h3.d.ts +17 -0
- package/h3.js +10 -0
- package/h3.mjs +10 -0
- package/hono.d.mts +25 -0
- package/hono.d.ts +25 -0
- package/hono.js +22 -0
- package/hono.mjs +22 -0
- package/index.d.mts +54 -0
- package/index.d.ts +54 -0
- package/index.js +41 -0
- package/index.mjs +41 -0
- package/nextjs.d.mts +38 -0
- package/nextjs.d.ts +38 -0
- package/nextjs.js +178 -0
- package/nextjs.mjs +178 -0
- package/nuxt.d.mts +12 -0
- package/nuxt.d.ts +12 -0
- package/nuxt.js +11 -0
- package/nuxt.mjs +11 -0
- package/package.json +1 -1
- package/solidjs.d.mts +22 -0
- package/solidjs.d.ts +22 -0
- package/solidjs.js +56 -0
- package/solidjs.mjs +56 -0
- package/svelte.d.mts +24 -0
- package/svelte.d.ts +24 -0
- package/svelte.js +53 -0
- package/svelte.mjs +53 -0
- package/workflow.d.mts +2 -0
- package/workflow.d.ts +2 -0
- package/workflow.js +18 -0
- package/workflow.mjs +18 -0
- package/dist/base/index.d.mts +0 -1279
- package/dist/base/index.mjs +0 -2
- package/dist/cloudflare/index.d.mts +0 -1652
- package/dist/cloudflare/index.mjs +0 -11
- package/dist/h3/index.d.mts +0 -1637
- package/dist/h3/index.mjs +0 -11
- package/dist/hono/index.d.mts +0 -1645
- package/dist/hono/index.mjs +0 -11
- package/dist/nextjs/index.mjs +0 -11
- package/dist/solidjs/index.d.mts +0 -1642
- package/dist/solidjs/index.mjs +0 -11
- package/dist/svelte/index.d.mts +0 -1644
- package/dist/svelte/index.mjs +0 -11
- package/dist/workflow/index.mjs +0 -11
|
@@ -1,1652 +0,0 @@
|
|
|
1
|
-
type State = "CREATED" | "ACTIVE" | "DELIVERED" | "ERROR" | "RETRY" | "FAILED";
|
|
2
|
-
type HTTPMethods = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
3
|
-
type Event = {
|
|
4
|
-
time: number;
|
|
5
|
-
state: State;
|
|
6
|
-
messageId: string;
|
|
7
|
-
nextDeliveryTime?: number;
|
|
8
|
-
error?: string;
|
|
9
|
-
url: string;
|
|
10
|
-
urlGroup?: string;
|
|
11
|
-
topicName?: string;
|
|
12
|
-
endpointName?: string;
|
|
13
|
-
header?: Record<string, string>;
|
|
14
|
-
body?: string;
|
|
15
|
-
};
|
|
16
|
-
type BodyInit = Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | string;
|
|
17
|
-
type HeadersInit = Headers | Record<string, string> | [string, string][] | IterableIterator<[string, string]>;
|
|
18
|
-
|
|
19
|
-
type ProviderReturnType = {
|
|
20
|
-
owner: "upstash" | "openai" | "custom";
|
|
21
|
-
baseUrl: string;
|
|
22
|
-
token: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type ChatCompletionMessage = {
|
|
26
|
-
role: "system" | "assistant" | "user";
|
|
27
|
-
content: string;
|
|
28
|
-
};
|
|
29
|
-
type ChatModel = "meta-llama/Meta-Llama-3-8B-Instruct" | "mistralai/Mistral-7B-Instruct-v0.2";
|
|
30
|
-
type ChatResponseFormat = {
|
|
31
|
-
type: "text" | "json_object";
|
|
32
|
-
};
|
|
33
|
-
type TopLogprob = {
|
|
34
|
-
token: string;
|
|
35
|
-
bytes: number[];
|
|
36
|
-
logprob: number;
|
|
37
|
-
};
|
|
38
|
-
type ChatCompletionTokenLogprob = {
|
|
39
|
-
token: string;
|
|
40
|
-
bytes: number[];
|
|
41
|
-
logprob: number;
|
|
42
|
-
top_logprobs: TopLogprob[];
|
|
43
|
-
};
|
|
44
|
-
type ChoiceLogprobs = {
|
|
45
|
-
content: ChatCompletionTokenLogprob[];
|
|
46
|
-
};
|
|
47
|
-
type Choice = {
|
|
48
|
-
finish_reason: "stop" | "length";
|
|
49
|
-
index: number;
|
|
50
|
-
logprobs: ChoiceLogprobs;
|
|
51
|
-
message: ChatCompletionMessage;
|
|
52
|
-
};
|
|
53
|
-
type CompletionUsage = {
|
|
54
|
-
completion_tokens: number;
|
|
55
|
-
prompt_tokens: number;
|
|
56
|
-
total_tokens: number;
|
|
57
|
-
};
|
|
58
|
-
type ChatCompletion = {
|
|
59
|
-
id: string;
|
|
60
|
-
choices: Choice[];
|
|
61
|
-
created: number;
|
|
62
|
-
model: string;
|
|
63
|
-
object: "chat.completion";
|
|
64
|
-
system_fingerprint: string;
|
|
65
|
-
usage: CompletionUsage;
|
|
66
|
-
};
|
|
67
|
-
type ChunkChoice = {
|
|
68
|
-
delta: ChatCompletionMessage;
|
|
69
|
-
finish_reason: "stop" | "length";
|
|
70
|
-
index: number;
|
|
71
|
-
logprobs: ChoiceLogprobs;
|
|
72
|
-
};
|
|
73
|
-
type ChatCompletionChunk = {
|
|
74
|
-
id: string;
|
|
75
|
-
choices: ChunkChoice[];
|
|
76
|
-
created: number;
|
|
77
|
-
model: string;
|
|
78
|
-
object: "chat.completion.chunk";
|
|
79
|
-
system_fingerprint: string;
|
|
80
|
-
usage: CompletionUsage;
|
|
81
|
-
};
|
|
82
|
-
type StreamEnabled = {
|
|
83
|
-
stream: true;
|
|
84
|
-
};
|
|
85
|
-
type StreamDisabled = {
|
|
86
|
-
stream: false;
|
|
87
|
-
} | object;
|
|
88
|
-
type StreamParameter = StreamEnabled | StreamDisabled;
|
|
89
|
-
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";
|
|
90
|
-
type ChatRequestCommonFields = {
|
|
91
|
-
frequency_penalty?: number;
|
|
92
|
-
logit_bias?: Record<string, number>;
|
|
93
|
-
logprobs?: boolean;
|
|
94
|
-
top_logprobs?: number;
|
|
95
|
-
max_tokens?: number;
|
|
96
|
-
n?: number;
|
|
97
|
-
presence_penalty?: number;
|
|
98
|
-
response_format?: ChatResponseFormat;
|
|
99
|
-
seed?: number;
|
|
100
|
-
stop?: string | string[];
|
|
101
|
-
temperature?: number;
|
|
102
|
-
top_p?: number;
|
|
103
|
-
};
|
|
104
|
-
type PromptChatRequestFields = ChatRequestCommonFields & {
|
|
105
|
-
system: string;
|
|
106
|
-
user: string;
|
|
107
|
-
};
|
|
108
|
-
type ChatRequestFields = ChatRequestCommonFields & {
|
|
109
|
-
messages: ChatCompletionMessage[];
|
|
110
|
-
};
|
|
111
|
-
type ChatRequestProviders = {
|
|
112
|
-
provider: ProviderReturnType;
|
|
113
|
-
model: OpenAIChatModel;
|
|
114
|
-
analytics?: {
|
|
115
|
-
name: "helicone";
|
|
116
|
-
token: string;
|
|
117
|
-
};
|
|
118
|
-
} | {
|
|
119
|
-
provider: ProviderReturnType;
|
|
120
|
-
model: string;
|
|
121
|
-
analytics?: {
|
|
122
|
-
name: "helicone";
|
|
123
|
-
token: string;
|
|
124
|
-
};
|
|
125
|
-
} | {
|
|
126
|
-
provider: ProviderReturnType;
|
|
127
|
-
model: ChatModel;
|
|
128
|
-
analytics?: {
|
|
129
|
-
name: "helicone";
|
|
130
|
-
token: string;
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
type PromptChatRequest<TStream extends StreamParameter> = ChatRequestProviders & PromptChatRequestFields & TStream;
|
|
134
|
-
type ChatRequest<TStream extends StreamParameter> = ChatRequestProviders & ChatRequestFields & TStream;
|
|
135
|
-
|
|
136
|
-
type UpstashRequest = {
|
|
137
|
-
/**
|
|
138
|
-
* The path to the resource.
|
|
139
|
-
*/
|
|
140
|
-
path: string[];
|
|
141
|
-
/**
|
|
142
|
-
* A BodyInit object or null to set request's body.
|
|
143
|
-
*/
|
|
144
|
-
body?: BodyInit | null;
|
|
145
|
-
/**
|
|
146
|
-
* A Headers object, an object literal, or an array of two-item arrays to set
|
|
147
|
-
* request's headers.
|
|
148
|
-
*/
|
|
149
|
-
headers?: HeadersInit;
|
|
150
|
-
/**
|
|
151
|
-
* A boolean to set request's keepalive.
|
|
152
|
-
*/
|
|
153
|
-
keepalive?: boolean;
|
|
154
|
-
/**
|
|
155
|
-
* A string to set request's method.
|
|
156
|
-
*/
|
|
157
|
-
method?: HTTPMethods;
|
|
158
|
-
query?: Record<string, string | number | boolean | undefined>;
|
|
159
|
-
/**
|
|
160
|
-
* if enabled, call `res.json()`
|
|
161
|
-
*
|
|
162
|
-
* @default true
|
|
163
|
-
*/
|
|
164
|
-
parseResponseAsJson?: boolean;
|
|
165
|
-
baseUrl?: string;
|
|
166
|
-
};
|
|
167
|
-
type UpstashResponse<TResult> = TResult & {
|
|
168
|
-
error?: string;
|
|
169
|
-
};
|
|
170
|
-
type Requester = {
|
|
171
|
-
request: <TResult = unknown>(request: UpstashRequest) => Promise<UpstashResponse<TResult>>;
|
|
172
|
-
requestStream: (request: UpstashRequest) => AsyncIterable<ChatCompletionChunk>;
|
|
173
|
-
};
|
|
174
|
-
type RetryConfig = false | {
|
|
175
|
-
/**
|
|
176
|
-
* The number of retries to attempt before giving up.
|
|
177
|
-
*
|
|
178
|
-
* @default 5
|
|
179
|
-
*/
|
|
180
|
-
retries?: number;
|
|
181
|
-
/**
|
|
182
|
-
* A backoff function receives the current retry cound and returns a number in milliseconds to wait before retrying.
|
|
183
|
-
*
|
|
184
|
-
* @default
|
|
185
|
-
* ```ts
|
|
186
|
-
* Math.exp(retryCount) * 50
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
backoff?: (retryCount: number) => number;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Necessary to verify the signature of a request.
|
|
194
|
-
*/
|
|
195
|
-
type ReceiverConfig = {
|
|
196
|
-
/**
|
|
197
|
-
* The current signing key. Get it from `https://console.upstash.com/qstash
|
|
198
|
-
*/
|
|
199
|
-
currentSigningKey: string;
|
|
200
|
-
/**
|
|
201
|
-
* The next signing key. Get it from `https://console.upstash.com/qstash
|
|
202
|
-
*/
|
|
203
|
-
nextSigningKey: string;
|
|
204
|
-
};
|
|
205
|
-
type VerifyRequest = {
|
|
206
|
-
/**
|
|
207
|
-
* The signature from the `upstash-signature` header.
|
|
208
|
-
*/
|
|
209
|
-
signature: string;
|
|
210
|
-
/**
|
|
211
|
-
* The raw request body.
|
|
212
|
-
*/
|
|
213
|
-
body: string;
|
|
214
|
-
/**
|
|
215
|
-
* URL of the endpoint where the request was sent to.
|
|
216
|
-
*
|
|
217
|
-
* Omit empty to disable checking the url.
|
|
218
|
-
*/
|
|
219
|
-
url?: string;
|
|
220
|
-
/**
|
|
221
|
-
* Number of seconds to tolerate when checking `nbf` and `exp` claims, to deal with small clock differences among different servers
|
|
222
|
-
*
|
|
223
|
-
* @default 0
|
|
224
|
-
*/
|
|
225
|
-
clockTolerance?: number;
|
|
226
|
-
};
|
|
227
|
-
/**
|
|
228
|
-
* Receiver offers a simple way to verify the signature of a request.
|
|
229
|
-
*/
|
|
230
|
-
declare class Receiver {
|
|
231
|
-
private readonly currentSigningKey;
|
|
232
|
-
private readonly nextSigningKey;
|
|
233
|
-
constructor(config: ReceiverConfig);
|
|
234
|
-
/**
|
|
235
|
-
* Verify the signature of a request.
|
|
236
|
-
*
|
|
237
|
-
* Tries to verify the signature with the current signing key.
|
|
238
|
-
* If that fails, maybe because you have rotated the keys recently, it will
|
|
239
|
-
* try to verify the signature with the next signing key.
|
|
240
|
-
*
|
|
241
|
-
* If that fails, the signature is invalid and a `SignatureError` is thrown.
|
|
242
|
-
*/
|
|
243
|
-
verify(request: VerifyRequest): Promise<boolean>;
|
|
244
|
-
/**
|
|
245
|
-
* Verify signature with a specific signing key
|
|
246
|
-
*/
|
|
247
|
-
private verifyWithKey;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
type Message = {
|
|
251
|
-
/**
|
|
252
|
-
* A unique identifier for this message.
|
|
253
|
-
*/
|
|
254
|
-
messageId: string;
|
|
255
|
-
/**
|
|
256
|
-
* The url group name if this message was sent to a urlGroup.
|
|
257
|
-
*/
|
|
258
|
-
urlGroup?: string;
|
|
259
|
-
/**
|
|
260
|
-
* Deprecated. The topic name if this message was sent to a urlGroup. Use urlGroup instead
|
|
261
|
-
*/
|
|
262
|
-
topicName?: string;
|
|
263
|
-
/**
|
|
264
|
-
* The url where this message is sent to.
|
|
265
|
-
*/
|
|
266
|
-
url: string;
|
|
267
|
-
/**
|
|
268
|
-
* The endpoint name of the message if the endpoint is given a
|
|
269
|
-
* name within the url group.
|
|
270
|
-
*/
|
|
271
|
-
endpointName?: string;
|
|
272
|
-
/**
|
|
273
|
-
* The api name if this message was sent to an api
|
|
274
|
-
*/
|
|
275
|
-
api?: string;
|
|
276
|
-
/**
|
|
277
|
-
* The http method used to deliver the message
|
|
278
|
-
*/
|
|
279
|
-
method?: HTTPMethods;
|
|
280
|
-
/**
|
|
281
|
-
* The http headers sent along with the message to your API.
|
|
282
|
-
*/
|
|
283
|
-
header?: Record<string, string[]>;
|
|
284
|
-
/**
|
|
285
|
-
* The http body sent to your API
|
|
286
|
-
*/
|
|
287
|
-
body?: string;
|
|
288
|
-
/**
|
|
289
|
-
* The base64 encoded body if the body contains non-UTF-8 characters,
|
|
290
|
-
* `None` otherwise.
|
|
291
|
-
*/
|
|
292
|
-
bodyBase64?: string;
|
|
293
|
-
/**
|
|
294
|
-
* Maxmimum number of retries.
|
|
295
|
-
*/
|
|
296
|
-
maxRetries?: number;
|
|
297
|
-
/**
|
|
298
|
-
* A unix timestamp (milliseconds) after which this message may get delivered.
|
|
299
|
-
*/
|
|
300
|
-
notBefore?: number;
|
|
301
|
-
/**
|
|
302
|
-
* A unix timestamp (milliseconds) when this messages was created.
|
|
303
|
-
*/
|
|
304
|
-
createdAt: number;
|
|
305
|
-
/**
|
|
306
|
-
* The callback url if configured.
|
|
307
|
-
*/
|
|
308
|
-
callback?: string;
|
|
309
|
-
/**
|
|
310
|
-
* The failure callback url if configured.
|
|
311
|
-
*/
|
|
312
|
-
failureCallback?: string;
|
|
313
|
-
/**
|
|
314
|
-
* The queue name if this message was sent to a queue.
|
|
315
|
-
*/
|
|
316
|
-
queueName?: string;
|
|
317
|
-
/**
|
|
318
|
-
* The scheduleId of the message if the message is triggered by a schedule
|
|
319
|
-
*/
|
|
320
|
-
scheduleId?: string;
|
|
321
|
-
/**
|
|
322
|
-
* IP address of the publisher of this message
|
|
323
|
-
*/
|
|
324
|
-
callerIp?: string;
|
|
325
|
-
};
|
|
326
|
-
declare class Messages {
|
|
327
|
-
private readonly http;
|
|
328
|
-
constructor(http: Requester);
|
|
329
|
-
/**
|
|
330
|
-
* Get a message
|
|
331
|
-
*/
|
|
332
|
-
get(messageId: string): Promise<Message>;
|
|
333
|
-
/**
|
|
334
|
-
* Cancel a message
|
|
335
|
-
*/
|
|
336
|
-
delete(messageId: string): Promise<void>;
|
|
337
|
-
deleteMany(messageIds: string[]): Promise<number>;
|
|
338
|
-
deleteAll(): Promise<number>;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
type DlqMessage = Message & {
|
|
342
|
-
/**
|
|
343
|
-
* The unique id within the DLQ
|
|
344
|
-
*/
|
|
345
|
-
dlqId: string;
|
|
346
|
-
/**
|
|
347
|
-
* The HTTP status code of the last failed delivery attempt
|
|
348
|
-
*/
|
|
349
|
-
responseStatus?: number;
|
|
350
|
-
/**
|
|
351
|
-
* The response headers of the last failed delivery attempt
|
|
352
|
-
*/
|
|
353
|
-
responseHeader?: Record<string, string[]>;
|
|
354
|
-
/**
|
|
355
|
-
* The response body of the last failed delivery attempt if it is
|
|
356
|
-
* composed of UTF-8 characters only, `None` otherwise.
|
|
357
|
-
*/
|
|
358
|
-
responseBody?: string;
|
|
359
|
-
/**
|
|
360
|
-
* The base64 encoded response body of the last failed delivery attempt
|
|
361
|
-
* if the response body contains non-UTF-8 characters, `None` otherwise.
|
|
362
|
-
*/
|
|
363
|
-
responseBodyBase64?: string;
|
|
364
|
-
};
|
|
365
|
-
type DLQFilter = {
|
|
366
|
-
/**
|
|
367
|
-
* Filter DLQ entries by message id
|
|
368
|
-
*/
|
|
369
|
-
messageId?: string;
|
|
370
|
-
/**
|
|
371
|
-
* Filter DLQ entries by url
|
|
372
|
-
*/
|
|
373
|
-
url?: string;
|
|
374
|
-
/**
|
|
375
|
-
* Filter DLQ entries by url group name
|
|
376
|
-
*/
|
|
377
|
-
urlGroup?: string;
|
|
378
|
-
/**
|
|
379
|
-
* Filter DLQ entries by api name
|
|
380
|
-
*/
|
|
381
|
-
api?: string;
|
|
382
|
-
/**
|
|
383
|
-
* Filter DLQ entries by queue name
|
|
384
|
-
*/
|
|
385
|
-
queueName?: string;
|
|
386
|
-
/**
|
|
387
|
-
* Filter DLQ entries by schedule id
|
|
388
|
-
*/
|
|
389
|
-
scheduleId?: string;
|
|
390
|
-
/**
|
|
391
|
-
* Filter DLQ entries by starting time, in milliseconds
|
|
392
|
-
*/
|
|
393
|
-
fromDate?: number;
|
|
394
|
-
/**
|
|
395
|
-
* Filter DLQ entries by ending time, in milliseconds
|
|
396
|
-
*/
|
|
397
|
-
toDate?: number;
|
|
398
|
-
/**
|
|
399
|
-
* Filter DLQ entries by HTTP status of the response
|
|
400
|
-
*/
|
|
401
|
-
responseStatus?: number;
|
|
402
|
-
/**
|
|
403
|
-
* Filter DLQ entries by IP address of the publisher of the message
|
|
404
|
-
*/
|
|
405
|
-
callerIp?: string;
|
|
406
|
-
};
|
|
407
|
-
declare class DLQ {
|
|
408
|
-
private readonly http;
|
|
409
|
-
constructor(http: Requester);
|
|
410
|
-
/**
|
|
411
|
-
* List messages in the dlq
|
|
412
|
-
*/
|
|
413
|
-
listMessages(options?: {
|
|
414
|
-
cursor?: string;
|
|
415
|
-
count?: number;
|
|
416
|
-
filter?: DLQFilter;
|
|
417
|
-
}): Promise<{
|
|
418
|
-
messages: DlqMessage[];
|
|
419
|
-
cursor?: string;
|
|
420
|
-
}>;
|
|
421
|
-
/**
|
|
422
|
-
* Remove a message from the dlq using it's `dlqId`
|
|
423
|
-
*/
|
|
424
|
-
delete(dlqMessageId: string): Promise<void>;
|
|
425
|
-
/**
|
|
426
|
-
* Remove multiple messages from the dlq using their `dlqId`s
|
|
427
|
-
*/
|
|
428
|
-
deleteMany(request: {
|
|
429
|
-
dlqIds: string[];
|
|
430
|
-
}): Promise<{
|
|
431
|
-
deleted: number;
|
|
432
|
-
}>;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
type Unit = "s" | "m" | "h" | "d";
|
|
436
|
-
type Duration = `${bigint}${Unit}`;
|
|
437
|
-
|
|
438
|
-
declare class Chat {
|
|
439
|
-
private http;
|
|
440
|
-
private token;
|
|
441
|
-
constructor(http: Requester, token: string);
|
|
442
|
-
private static toChatRequest;
|
|
443
|
-
/**
|
|
444
|
-
* Calls the Upstash completions api given a ChatRequest.
|
|
445
|
-
*
|
|
446
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
447
|
-
* if stream is enabled.
|
|
448
|
-
*
|
|
449
|
-
* @param request ChatRequest with messages
|
|
450
|
-
* @returns Chat completion or stream
|
|
451
|
-
*/
|
|
452
|
-
create: <TStream extends StreamParameter>(request: ChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
|
|
453
|
-
/**
|
|
454
|
-
* Calls the Upstash completions api given a ChatRequest.
|
|
455
|
-
*
|
|
456
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
457
|
-
* if stream is enabled.
|
|
458
|
-
*
|
|
459
|
-
* @param request ChatRequest with messages
|
|
460
|
-
* @returns Chat completion or stream
|
|
461
|
-
*/
|
|
462
|
-
private createThirdParty;
|
|
463
|
-
private getAuthorizationToken;
|
|
464
|
-
/**
|
|
465
|
-
* Calls the Upstash completions api given a PromptRequest.
|
|
466
|
-
*
|
|
467
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
468
|
-
* if stream is enabled.
|
|
469
|
-
*
|
|
470
|
-
* @param request PromptRequest with system and user messages.
|
|
471
|
-
* Note that system parameter shouldn't be passed in the case of
|
|
472
|
-
* mistralai/Mistral-7B-Instruct-v0.2 model.
|
|
473
|
-
* @returns Chat completion or stream
|
|
474
|
-
*/
|
|
475
|
-
prompt: <TStream extends StreamParameter>(request: PromptChatRequest<TStream>) => Promise<TStream extends StreamEnabled ? AsyncIterable<ChatCompletionChunk> : ChatCompletion>;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
type QueueResponse = {
|
|
479
|
-
createdAt: number;
|
|
480
|
-
updatedAt: number;
|
|
481
|
-
name: string;
|
|
482
|
-
parallelism: number;
|
|
483
|
-
lag: number;
|
|
484
|
-
paused: boolean;
|
|
485
|
-
};
|
|
486
|
-
type UpsertQueueRequest = {
|
|
487
|
-
/**
|
|
488
|
-
* The number of parallel consumers consuming from the queue.
|
|
489
|
-
*
|
|
490
|
-
* @default 1
|
|
491
|
-
*/
|
|
492
|
-
parallelism?: number;
|
|
493
|
-
/**
|
|
494
|
-
* Whether to pause the queue or not. A paused queue will not
|
|
495
|
-
* deliver new messages until it is resumed.
|
|
496
|
-
*
|
|
497
|
-
* @default false
|
|
498
|
-
*/
|
|
499
|
-
paused?: boolean;
|
|
500
|
-
};
|
|
501
|
-
declare class Queue {
|
|
502
|
-
private readonly http;
|
|
503
|
-
private readonly queueName;
|
|
504
|
-
constructor(http: Requester, queueName?: string);
|
|
505
|
-
/**
|
|
506
|
-
* Create or update the queue
|
|
507
|
-
*/
|
|
508
|
-
upsert(request: UpsertQueueRequest): Promise<void>;
|
|
509
|
-
/**
|
|
510
|
-
* Get the queue details
|
|
511
|
-
*/
|
|
512
|
-
get(): Promise<QueueResponse>;
|
|
513
|
-
/**
|
|
514
|
-
* List queues
|
|
515
|
-
*/
|
|
516
|
-
list(): Promise<QueueResponse[]>;
|
|
517
|
-
/**
|
|
518
|
-
* Delete the queue
|
|
519
|
-
*/
|
|
520
|
-
delete(): Promise<void>;
|
|
521
|
-
/**
|
|
522
|
-
* Enqueue a message to a queue.
|
|
523
|
-
*/
|
|
524
|
-
enqueue<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
|
|
525
|
-
/**
|
|
526
|
-
* Enqueue a message to a queue, serializing the body to JSON.
|
|
527
|
-
*/
|
|
528
|
-
enqueueJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
|
|
529
|
-
/**
|
|
530
|
-
* Pauses the queue.
|
|
531
|
-
*
|
|
532
|
-
* A paused queue will not deliver messages until
|
|
533
|
-
* it is resumed.
|
|
534
|
-
*/
|
|
535
|
-
pause(): Promise<void>;
|
|
536
|
-
/**
|
|
537
|
-
* Resumes the queue.
|
|
538
|
-
*/
|
|
539
|
-
resume(): Promise<void>;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
type Schedule = {
|
|
543
|
-
scheduleId: string;
|
|
544
|
-
cron: string;
|
|
545
|
-
createdAt: number;
|
|
546
|
-
destination: string;
|
|
547
|
-
method: string;
|
|
548
|
-
header?: Record<string, string[]>;
|
|
549
|
-
body?: string;
|
|
550
|
-
bodyBase64?: string;
|
|
551
|
-
retries: number;
|
|
552
|
-
delay?: number;
|
|
553
|
-
callback?: string;
|
|
554
|
-
failureCallback?: string;
|
|
555
|
-
callerIp?: string;
|
|
556
|
-
isPaused: boolean;
|
|
557
|
-
};
|
|
558
|
-
type CreateScheduleRequest = {
|
|
559
|
-
/**
|
|
560
|
-
* Either a URL or urlGroup name
|
|
561
|
-
*/
|
|
562
|
-
destination: string;
|
|
563
|
-
/**
|
|
564
|
-
* The message to send.
|
|
565
|
-
*
|
|
566
|
-
* This can be anything, but please set the `Content-Type` header accordingly.
|
|
567
|
-
*
|
|
568
|
-
* You can leave this empty if you want to send a message with no body.
|
|
569
|
-
*/
|
|
570
|
-
body?: BodyInit;
|
|
571
|
-
/**
|
|
572
|
-
* Optionally send along headers with the message.
|
|
573
|
-
* These headers will be sent to your destination.
|
|
574
|
-
*
|
|
575
|
-
* We highly recommend sending a `Content-Type` header along, as this will help your destination
|
|
576
|
-
* server to understand the content of the message.
|
|
577
|
-
*/
|
|
578
|
-
headers?: HeadersInit;
|
|
579
|
-
/**
|
|
580
|
-
* Optionally delay the delivery of this message.
|
|
581
|
-
*
|
|
582
|
-
* In seconds.
|
|
583
|
-
*
|
|
584
|
-
* @default undefined
|
|
585
|
-
*/
|
|
586
|
-
delay?: Duration | number;
|
|
587
|
-
/**
|
|
588
|
-
* In case your destination server is unavailable or returns a status code outside of the 200-299
|
|
589
|
-
* range, we will retry the request after a certain amount of time.
|
|
590
|
-
*
|
|
591
|
-
* Configure how many times you would like the delivery to be retried
|
|
592
|
-
*
|
|
593
|
-
* @default The maximum retry quota associated with your account.
|
|
594
|
-
*/
|
|
595
|
-
retries?: number;
|
|
596
|
-
/**
|
|
597
|
-
* Use a callback url to forward the response of your destination server to your callback url.
|
|
598
|
-
*
|
|
599
|
-
* The callback url must be publicly accessible
|
|
600
|
-
*
|
|
601
|
-
* @default undefined
|
|
602
|
-
*/
|
|
603
|
-
callback?: string;
|
|
604
|
-
/**
|
|
605
|
-
* Use a failure callback url to handle messages that could not be delivered.
|
|
606
|
-
*
|
|
607
|
-
* The failure callback url must be publicly accessible
|
|
608
|
-
*
|
|
609
|
-
* @default undefined
|
|
610
|
-
*/
|
|
611
|
-
failureCallback?: string;
|
|
612
|
-
/**
|
|
613
|
-
* The method to use when sending a request to your API
|
|
614
|
-
*
|
|
615
|
-
* @default `POST`
|
|
616
|
-
*/
|
|
617
|
-
method?: HTTPMethods;
|
|
618
|
-
/**
|
|
619
|
-
* Specify a cron expression to repeatedly send this message to the destination.
|
|
620
|
-
*/
|
|
621
|
-
cron: string;
|
|
622
|
-
/**
|
|
623
|
-
* The HTTP timeout value to use while calling the destination URL.
|
|
624
|
-
* When a timeout is specified, it will be used instead of the maximum timeout
|
|
625
|
-
* value permitted by the QStash plan. It is useful in scenarios, where a message
|
|
626
|
-
* should be delivered with a shorter timeout.
|
|
627
|
-
*
|
|
628
|
-
* In seconds.
|
|
629
|
-
*
|
|
630
|
-
* @default undefined
|
|
631
|
-
*/
|
|
632
|
-
timeout?: Duration | number;
|
|
633
|
-
/**
|
|
634
|
-
* Schedule id to use.
|
|
635
|
-
*
|
|
636
|
-
* Can be used to updatine the settings of an existing schedule.
|
|
637
|
-
*
|
|
638
|
-
* @default undefined
|
|
639
|
-
*/
|
|
640
|
-
scheduleId?: string;
|
|
641
|
-
};
|
|
642
|
-
declare class Schedules {
|
|
643
|
-
private readonly http;
|
|
644
|
-
constructor(http: Requester);
|
|
645
|
-
/**
|
|
646
|
-
* Create a schedule
|
|
647
|
-
*/
|
|
648
|
-
create(request: CreateScheduleRequest): Promise<{
|
|
649
|
-
scheduleId: string;
|
|
650
|
-
}>;
|
|
651
|
-
/**
|
|
652
|
-
* Get a schedule
|
|
653
|
-
*/
|
|
654
|
-
get(scheduleId: string): Promise<Schedule>;
|
|
655
|
-
/**
|
|
656
|
-
* List your schedules
|
|
657
|
-
*/
|
|
658
|
-
list(): Promise<Schedule[]>;
|
|
659
|
-
/**
|
|
660
|
-
* Delete a schedule
|
|
661
|
-
*/
|
|
662
|
-
delete(scheduleId: string): Promise<void>;
|
|
663
|
-
/**
|
|
664
|
-
* Pauses the schedule.
|
|
665
|
-
*
|
|
666
|
-
* A paused schedule will not deliver messages until
|
|
667
|
-
* it is resumed.
|
|
668
|
-
*/
|
|
669
|
-
pause({ schedule }: {
|
|
670
|
-
schedule: string;
|
|
671
|
-
}): Promise<void>;
|
|
672
|
-
/**
|
|
673
|
-
* Resumes the schedule.
|
|
674
|
-
*/
|
|
675
|
-
resume({ schedule }: {
|
|
676
|
-
schedule: string;
|
|
677
|
-
}): Promise<void>;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
type Endpoint = {
|
|
681
|
-
/**
|
|
682
|
-
* The name of the endpoint (optional)
|
|
683
|
-
*/
|
|
684
|
-
name?: string;
|
|
685
|
-
/**
|
|
686
|
-
* The url of the endpoint
|
|
687
|
-
*/
|
|
688
|
-
url: string;
|
|
689
|
-
};
|
|
690
|
-
type AddEndpointsRequest = {
|
|
691
|
-
/**
|
|
692
|
-
* The name of the url group.
|
|
693
|
-
* Must be unique and only contain alphanumeric, hyphen, underscore and periods.
|
|
694
|
-
*/
|
|
695
|
-
name: string;
|
|
696
|
-
endpoints: Endpoint[];
|
|
697
|
-
};
|
|
698
|
-
type RemoveEndpointsRequest = {
|
|
699
|
-
/**
|
|
700
|
-
* The name of the url group.
|
|
701
|
-
* Must be unique and only contain alphanumeric, hyphen, underscore and periods.
|
|
702
|
-
*/
|
|
703
|
-
name: string;
|
|
704
|
-
endpoints: ({
|
|
705
|
-
name: string;
|
|
706
|
-
url?: string;
|
|
707
|
-
} | {
|
|
708
|
-
name?: string;
|
|
709
|
-
url: string;
|
|
710
|
-
})[];
|
|
711
|
-
};
|
|
712
|
-
type UrlGroup = {
|
|
713
|
-
/**
|
|
714
|
-
* A unix timestamp (milliseconds)
|
|
715
|
-
*/
|
|
716
|
-
createdAt: number;
|
|
717
|
-
/**
|
|
718
|
-
* A unix timestamp (milliseconds)
|
|
719
|
-
*/
|
|
720
|
-
updatedAt: number;
|
|
721
|
-
/**
|
|
722
|
-
* The name of this url group.
|
|
723
|
-
*/
|
|
724
|
-
name: string;
|
|
725
|
-
/**
|
|
726
|
-
* A list of all subscribed endpoints
|
|
727
|
-
*/
|
|
728
|
-
endpoints: Endpoint[];
|
|
729
|
-
};
|
|
730
|
-
declare class UrlGroups {
|
|
731
|
-
private readonly http;
|
|
732
|
-
constructor(http: Requester);
|
|
733
|
-
/**
|
|
734
|
-
* Create a new url group with the given name and endpoints
|
|
735
|
-
*/
|
|
736
|
-
addEndpoints(request: AddEndpointsRequest): Promise<void>;
|
|
737
|
-
/**
|
|
738
|
-
* Remove endpoints from a url group.
|
|
739
|
-
*/
|
|
740
|
-
removeEndpoints(request: RemoveEndpointsRequest): Promise<void>;
|
|
741
|
-
/**
|
|
742
|
-
* Get a list of all url groups.
|
|
743
|
-
*/
|
|
744
|
-
list(): Promise<UrlGroup[]>;
|
|
745
|
-
/**
|
|
746
|
-
* Get a single url group
|
|
747
|
-
*/
|
|
748
|
-
get(name: string): Promise<UrlGroup>;
|
|
749
|
-
/**
|
|
750
|
-
* Delete a url group
|
|
751
|
-
*/
|
|
752
|
-
delete(name: string): Promise<void>;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
type ClientConfig = {
|
|
756
|
-
/**
|
|
757
|
-
* Url of the QStash api server.
|
|
758
|
-
*
|
|
759
|
-
* This is only used for testing.
|
|
760
|
-
*
|
|
761
|
-
* @default "https://qstash.upstash.io"
|
|
762
|
-
*/
|
|
763
|
-
baseUrl?: string;
|
|
764
|
-
/**
|
|
765
|
-
* The authorization token from the upstash console.
|
|
766
|
-
*/
|
|
767
|
-
token: string;
|
|
768
|
-
/**
|
|
769
|
-
* Configure how the client should retry requests.
|
|
770
|
-
*/
|
|
771
|
-
retry?: RetryConfig;
|
|
772
|
-
};
|
|
773
|
-
type PublishBatchRequest<TBody = BodyInit> = PublishRequest<TBody> & {
|
|
774
|
-
queueName?: string;
|
|
775
|
-
};
|
|
776
|
-
type PublishRequest<TBody = BodyInit> = {
|
|
777
|
-
/**
|
|
778
|
-
* The message to send.
|
|
779
|
-
*
|
|
780
|
-
* This can be anything, but please set the `Content-Type` header accordingly.
|
|
781
|
-
*
|
|
782
|
-
* You can leave this empty if you want to send a message with no body.
|
|
783
|
-
*/
|
|
784
|
-
body?: TBody;
|
|
785
|
-
/**
|
|
786
|
-
* Optionally send along headers with the message.
|
|
787
|
-
* These headers will be sent to your destination.
|
|
788
|
-
*
|
|
789
|
-
* We highly recommend sending a `Content-Type` header along, as this will help your destination
|
|
790
|
-
* server to understand the content of the message.
|
|
791
|
-
*/
|
|
792
|
-
headers?: HeadersInit;
|
|
793
|
-
/**
|
|
794
|
-
* Optionally delay the delivery of this message.
|
|
795
|
-
*
|
|
796
|
-
* In seconds.
|
|
797
|
-
*
|
|
798
|
-
* @default undefined
|
|
799
|
-
*/
|
|
800
|
-
delay?: Duration | number;
|
|
801
|
-
/**
|
|
802
|
-
* Optionally set the absolute delay of this message.
|
|
803
|
-
* This will override the delay option.
|
|
804
|
-
* The message will not delivered until the specified time.
|
|
805
|
-
*
|
|
806
|
-
* Unix timestamp in seconds.
|
|
807
|
-
*
|
|
808
|
-
* @default undefined
|
|
809
|
-
*/
|
|
810
|
-
notBefore?: number;
|
|
811
|
-
/**
|
|
812
|
-
* Provide a unique id for deduplication. This id will be used to detect duplicate messages.
|
|
813
|
-
* If a duplicate message is detected, the request will be accepted but not enqueued.
|
|
814
|
-
*
|
|
815
|
-
* We store deduplication ids for 90 days. Afterwards it is possible that the message with the
|
|
816
|
-
* same deduplication id is delivered again.
|
|
817
|
-
*
|
|
818
|
-
* When scheduling a message, the deduplication happens before the schedule is created.
|
|
819
|
-
*
|
|
820
|
-
* @default undefined
|
|
821
|
-
*/
|
|
822
|
-
deduplicationId?: string;
|
|
823
|
-
/**
|
|
824
|
-
* If true, the message content will get hashed and used as deduplication id.
|
|
825
|
-
* If a duplicate message is detected, the request will be accepted but not enqueued.
|
|
826
|
-
*
|
|
827
|
-
* The content based hash includes the following values:
|
|
828
|
-
* - All headers, except Upstash-Authorization, this includes all headers you are sending.
|
|
829
|
-
* - The entire raw request body The destination from the url path
|
|
830
|
-
*
|
|
831
|
-
* We store deduplication ids for 90 days. Afterwards it is possible that the message with the
|
|
832
|
-
* same deduplication id is delivered again.
|
|
833
|
-
*
|
|
834
|
-
* When scheduling a message, the deduplication happens before the schedule is created.
|
|
835
|
-
*
|
|
836
|
-
* @default false
|
|
837
|
-
*/
|
|
838
|
-
contentBasedDeduplication?: boolean;
|
|
839
|
-
/**
|
|
840
|
-
* In case your destination server is unavaialble or returns a status code outside of the 200-299
|
|
841
|
-
* range, we will retry the request after a certain amount of time.
|
|
842
|
-
*
|
|
843
|
-
* Configure how many times you would like the delivery to be retried up to the maxRetries limit
|
|
844
|
-
* defined in your plan.
|
|
845
|
-
*
|
|
846
|
-
* @default 3
|
|
847
|
-
*/
|
|
848
|
-
retries?: number;
|
|
849
|
-
/**
|
|
850
|
-
* Use a failure callback url to handle messages that could not be delivered.
|
|
851
|
-
*
|
|
852
|
-
* The failure callback url must be publicly accessible
|
|
853
|
-
*
|
|
854
|
-
* @default undefined
|
|
855
|
-
*/
|
|
856
|
-
failureCallback?: string;
|
|
857
|
-
/**
|
|
858
|
-
* The method to use when sending a request to your API
|
|
859
|
-
*
|
|
860
|
-
* @default `POST`
|
|
861
|
-
*/
|
|
862
|
-
method?: HTTPMethods;
|
|
863
|
-
/**
|
|
864
|
-
* The HTTP timeout value to use while calling the destination URL.
|
|
865
|
-
* When a timeout is specified, it will be used instead of the maximum timeout
|
|
866
|
-
* value permitted by the QStash plan. It is useful in scenarios, where a message
|
|
867
|
-
* should be delivered with a shorter timeout.
|
|
868
|
-
*
|
|
869
|
-
* In seconds.
|
|
870
|
-
*
|
|
871
|
-
* @default undefined
|
|
872
|
-
*/
|
|
873
|
-
timeout?: Duration | number;
|
|
874
|
-
} & ({
|
|
875
|
-
/**
|
|
876
|
-
* The url where the message should be sent to.
|
|
877
|
-
*/
|
|
878
|
-
url: string;
|
|
879
|
-
urlGroup?: never;
|
|
880
|
-
api?: never;
|
|
881
|
-
topic?: never;
|
|
882
|
-
/**
|
|
883
|
-
* Use a callback url to forward the response of your destination server to your callback url.
|
|
884
|
-
*
|
|
885
|
-
* The callback url must be publicly accessible
|
|
886
|
-
*
|
|
887
|
-
* @default undefined
|
|
888
|
-
*/
|
|
889
|
-
callback?: string;
|
|
890
|
-
} | {
|
|
891
|
-
url?: never;
|
|
892
|
-
/**
|
|
893
|
-
* The url group the message should be sent to.
|
|
894
|
-
*/
|
|
895
|
-
urlGroup: string;
|
|
896
|
-
api?: never;
|
|
897
|
-
topic?: never;
|
|
898
|
-
/**
|
|
899
|
-
* Use a callback url to forward the response of your destination server to your callback url.
|
|
900
|
-
*
|
|
901
|
-
* The callback url must be publicly accessible
|
|
902
|
-
*
|
|
903
|
-
* @default undefined
|
|
904
|
-
*/
|
|
905
|
-
callback?: string;
|
|
906
|
-
} | {
|
|
907
|
-
url?: string;
|
|
908
|
-
urlGroup?: never;
|
|
909
|
-
/**
|
|
910
|
-
* The api endpoint the request should be sent to.
|
|
911
|
-
*/
|
|
912
|
-
api: {
|
|
913
|
-
name: "llm";
|
|
914
|
-
provider?: ProviderReturnType;
|
|
915
|
-
analytics?: {
|
|
916
|
-
name: "helicone";
|
|
917
|
-
token: string;
|
|
918
|
-
};
|
|
919
|
-
};
|
|
920
|
-
/**
|
|
921
|
-
* Use a callback url to forward the response of your destination server to your callback url.
|
|
922
|
-
*
|
|
923
|
-
* The callback url must be publicly accessible
|
|
924
|
-
*
|
|
925
|
-
* @default undefined
|
|
926
|
-
*/
|
|
927
|
-
callback: string;
|
|
928
|
-
topic?: never;
|
|
929
|
-
} | {
|
|
930
|
-
url?: never;
|
|
931
|
-
urlGroup?: never;
|
|
932
|
-
api: never;
|
|
933
|
-
/**
|
|
934
|
-
* Deprecated. The topic the message should be sent to. Same as urlGroup
|
|
935
|
-
*/
|
|
936
|
-
topic?: string;
|
|
937
|
-
/**
|
|
938
|
-
* Use a callback url to forward the response of your destination server to your callback url.
|
|
939
|
-
*
|
|
940
|
-
* The callback url must be publicly accessible
|
|
941
|
-
*
|
|
942
|
-
* @default undefined
|
|
943
|
-
*/
|
|
944
|
-
callback?: string;
|
|
945
|
-
});
|
|
946
|
-
type EventsRequest = {
|
|
947
|
-
cursor?: number;
|
|
948
|
-
filter?: EventsRequestFilter;
|
|
949
|
-
};
|
|
950
|
-
type EventsRequestFilter = {
|
|
951
|
-
messageId?: string;
|
|
952
|
-
state?: State;
|
|
953
|
-
url?: string;
|
|
954
|
-
urlGroup?: string;
|
|
955
|
-
topicName?: string;
|
|
956
|
-
api?: string;
|
|
957
|
-
scheduleId?: string;
|
|
958
|
-
queueName?: string;
|
|
959
|
-
fromDate?: number;
|
|
960
|
-
toDate?: number;
|
|
961
|
-
count?: number;
|
|
962
|
-
};
|
|
963
|
-
type GetEventsResponse = {
|
|
964
|
-
cursor?: number;
|
|
965
|
-
events: Event[];
|
|
966
|
-
};
|
|
967
|
-
type QueueRequest = {
|
|
968
|
-
queueName?: string;
|
|
969
|
-
};
|
|
970
|
-
declare class Client {
|
|
971
|
-
http: Requester;
|
|
972
|
-
private token;
|
|
973
|
-
constructor(config: ClientConfig);
|
|
974
|
-
/**
|
|
975
|
-
* Access the urlGroup API.
|
|
976
|
-
*
|
|
977
|
-
* Create, read, update or delete urlGroups.
|
|
978
|
-
*/
|
|
979
|
-
get urlGroups(): UrlGroups;
|
|
980
|
-
/**
|
|
981
|
-
* Deprecated. Use urlGroups instead.
|
|
982
|
-
*
|
|
983
|
-
* Access the topic API.
|
|
984
|
-
*
|
|
985
|
-
* Create, read, update or delete topics.
|
|
986
|
-
*/
|
|
987
|
-
get topics(): UrlGroups;
|
|
988
|
-
/**
|
|
989
|
-
* Access the dlq API.
|
|
990
|
-
*
|
|
991
|
-
* List or remove messages from the DLQ.
|
|
992
|
-
*/
|
|
993
|
-
get dlq(): DLQ;
|
|
994
|
-
/**
|
|
995
|
-
* Access the message API.
|
|
996
|
-
*
|
|
997
|
-
* Read or cancel messages.
|
|
998
|
-
*/
|
|
999
|
-
get messages(): Messages;
|
|
1000
|
-
/**
|
|
1001
|
-
* Access the schedule API.
|
|
1002
|
-
*
|
|
1003
|
-
* Create, read or delete schedules.
|
|
1004
|
-
*/
|
|
1005
|
-
get schedules(): Schedules;
|
|
1006
|
-
/**
|
|
1007
|
-
* Access the workflow API.
|
|
1008
|
-
*
|
|
1009
|
-
* cancel workflows.
|
|
1010
|
-
*/
|
|
1011
|
-
get workflow(): Workflow;
|
|
1012
|
-
/**
|
|
1013
|
-
* Access the queue API.
|
|
1014
|
-
*
|
|
1015
|
-
* Create, read, update or delete queues.
|
|
1016
|
-
*/
|
|
1017
|
-
queue(request?: QueueRequest): Queue;
|
|
1018
|
-
/**
|
|
1019
|
-
* Access the Chat API
|
|
1020
|
-
*
|
|
1021
|
-
* Call the create or prompt methods
|
|
1022
|
-
*/
|
|
1023
|
-
chat(): Chat;
|
|
1024
|
-
publish<TRequest extends PublishRequest>(request: TRequest): Promise<PublishResponse<TRequest>>;
|
|
1025
|
-
/**
|
|
1026
|
-
* publishJSON is a utility wrapper around `publish` that automatically serializes the body
|
|
1027
|
-
* and sets the `Content-Type` header to `application/json`.
|
|
1028
|
-
*/
|
|
1029
|
-
publishJSON<TBody = unknown, TRequest extends PublishRequest<TBody> = PublishRequest<TBody>>(request: TRequest): Promise<PublishResponse<TRequest>>;
|
|
1030
|
-
/**
|
|
1031
|
-
* Batch publish messages to QStash.
|
|
1032
|
-
*/
|
|
1033
|
-
batch(request: PublishBatchRequest[]): Promise<PublishResponse<PublishRequest>[]>;
|
|
1034
|
-
/**
|
|
1035
|
-
* Batch publish messages to QStash, serializing each body to JSON.
|
|
1036
|
-
*/
|
|
1037
|
-
batchJSON<TBody = unknown, TRequest extends PublishBatchRequest<TBody> = PublishBatchRequest<TBody>>(request: TRequest[]): Promise<PublishResponse<TRequest>[]>;
|
|
1038
|
-
/**
|
|
1039
|
-
* Retrieve your logs.
|
|
1040
|
-
*
|
|
1041
|
-
* The logs endpoint is paginated and returns only 100 logs at a time.
|
|
1042
|
-
* If you want to receive more logs, you can use the cursor to paginate.
|
|
1043
|
-
*
|
|
1044
|
-
* The cursor is a unix timestamp with millisecond precision
|
|
1045
|
-
*
|
|
1046
|
-
* @example
|
|
1047
|
-
* ```ts
|
|
1048
|
-
* let cursor = Date.now()
|
|
1049
|
-
* const logs: Log[] = []
|
|
1050
|
-
* while (cursor > 0) {
|
|
1051
|
-
* const res = await qstash.logs({ cursor })
|
|
1052
|
-
* logs.push(...res.logs)
|
|
1053
|
-
* cursor = res.cursor ?? 0
|
|
1054
|
-
* }
|
|
1055
|
-
* ```
|
|
1056
|
-
*/
|
|
1057
|
-
events(request?: EventsRequest): Promise<GetEventsResponse>;
|
|
1058
|
-
}
|
|
1059
|
-
type PublishToApiResponse = {
|
|
1060
|
-
messageId: string;
|
|
1061
|
-
};
|
|
1062
|
-
type PublishToUrlResponse = PublishToApiResponse & {
|
|
1063
|
-
url: string;
|
|
1064
|
-
deduplicated?: boolean;
|
|
1065
|
-
};
|
|
1066
|
-
type PublishToUrlGroupsResponse = PublishToUrlResponse[];
|
|
1067
|
-
type PublishResponse<TRequest> = TRequest extends {
|
|
1068
|
-
url: string;
|
|
1069
|
-
} ? PublishToUrlResponse : TRequest extends {
|
|
1070
|
-
urlGroup: string;
|
|
1071
|
-
} ? PublishToUrlGroupsResponse : PublishToApiResponse;
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* Base class outlining steps. Basically, each step kind (run/sleep/sleepUntil)
|
|
1075
|
-
* should have two methods: getPlanStep & getResultStep.
|
|
1076
|
-
*
|
|
1077
|
-
* getPlanStep works the same way for all so it's implemented here.
|
|
1078
|
-
* The different step types will implement their own getResultStep method.
|
|
1079
|
-
*/
|
|
1080
|
-
declare abstract class BaseLazyStep<TResult = unknown> {
|
|
1081
|
-
readonly stepName: string;
|
|
1082
|
-
abstract readonly stepType: StepType;
|
|
1083
|
-
constructor(stepName: string);
|
|
1084
|
-
/**
|
|
1085
|
-
* plan step to submit when step will run parallel with other
|
|
1086
|
-
* steps (parallel call state `first`)
|
|
1087
|
-
*
|
|
1088
|
-
* @param concurrent number of steps running parallel
|
|
1089
|
-
* @param targetStep target step id corresponding to this step
|
|
1090
|
-
* @returns
|
|
1091
|
-
*/
|
|
1092
|
-
abstract getPlanStep(concurrent: number, targetStep: number): Step<undefined>;
|
|
1093
|
-
/**
|
|
1094
|
-
* result step to submit after the step executes. Used in single step executions
|
|
1095
|
-
* and when a plan step executes in parallel executions (parallel call state `partial`).
|
|
1096
|
-
*
|
|
1097
|
-
* @param concurrent
|
|
1098
|
-
* @param stepId
|
|
1099
|
-
*/
|
|
1100
|
-
abstract getResultStep(concurrent: number, stepId: number): Promise<Step<TResult>>;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
declare const LOG_LEVELS: readonly ["DEBUG", "INFO", "SUBMIT", "WARN", "ERROR"];
|
|
1104
|
-
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
1105
|
-
type ChatLogEntry = {
|
|
1106
|
-
timestamp: number;
|
|
1107
|
-
workflowRunId: string;
|
|
1108
|
-
logLevel: LogLevel;
|
|
1109
|
-
eventType: "ENDPOINT_START" | "SUBMIT_THIRD_PARTY_RESULT" | "CREATE_CONTEXT" | "SUBMIT_FIRST_INVOCATION" | "RUN_SINGLE" | "RUN_PARALLEL" | "SUBMIT_STEP" | "SUBMIT_CLEANUP" | "RESPONSE_WORKFLOW" | "RESPONSE_DEFAULT" | "ERROR";
|
|
1110
|
-
details: unknown;
|
|
1111
|
-
};
|
|
1112
|
-
type WorkflowLoggerOptions = {
|
|
1113
|
-
logLevel: LogLevel;
|
|
1114
|
-
logOutput: "console";
|
|
1115
|
-
};
|
|
1116
|
-
declare class WorkflowLogger {
|
|
1117
|
-
private logs;
|
|
1118
|
-
private options;
|
|
1119
|
-
private workflowRunId?;
|
|
1120
|
-
constructor(options: WorkflowLoggerOptions);
|
|
1121
|
-
log(level: LogLevel, eventType: ChatLogEntry["eventType"], details?: unknown): Promise<void>;
|
|
1122
|
-
setWorkflowRunId(workflowRunId: string): void;
|
|
1123
|
-
private writeToConsole;
|
|
1124
|
-
private shouldLog;
|
|
1125
|
-
static getLogger(verbose?: boolean | WorkflowLogger): WorkflowLogger | undefined;
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
declare class AutoExecutor {
|
|
1129
|
-
private context;
|
|
1130
|
-
private promises;
|
|
1131
|
-
private activeLazyStepList?;
|
|
1132
|
-
private debug?;
|
|
1133
|
-
private readonly nonPlanStepCount;
|
|
1134
|
-
private readonly steps;
|
|
1135
|
-
private indexInCurrentList;
|
|
1136
|
-
stepCount: number;
|
|
1137
|
-
planStepCount: number;
|
|
1138
|
-
protected executingStep: string | false;
|
|
1139
|
-
constructor(context: WorkflowContext, steps: Step[], debug?: WorkflowLogger);
|
|
1140
|
-
/**
|
|
1141
|
-
* Adds the step function to the list of step functions to run in
|
|
1142
|
-
* parallel. After adding the function, defers the execution, so
|
|
1143
|
-
* that if there is another step function to be added, it's also
|
|
1144
|
-
* added.
|
|
1145
|
-
*
|
|
1146
|
-
* After all functions are added, list of functions are executed.
|
|
1147
|
-
* If there is a single function, it's executed by itself. If there
|
|
1148
|
-
* are multiple, they are run in parallel.
|
|
1149
|
-
*
|
|
1150
|
-
* If a function is already executing (this.executingStep), this
|
|
1151
|
-
* means that there is a nested step which is not allowed. In this
|
|
1152
|
-
* case, addStep throws QStashWorkflowError.
|
|
1153
|
-
*
|
|
1154
|
-
* @param stepInfo step plan to add
|
|
1155
|
-
* @returns result of the step function
|
|
1156
|
-
*/
|
|
1157
|
-
addStep<TResult>(stepInfo: BaseLazyStep<TResult>): Promise<TResult>;
|
|
1158
|
-
/**
|
|
1159
|
-
* Wraps a step function to set this.executingStep to step name
|
|
1160
|
-
* before running and set this.executingStep to False after execution
|
|
1161
|
-
* ends.
|
|
1162
|
-
*
|
|
1163
|
-
* this.executingStep allows us to detect nested steps which are not
|
|
1164
|
-
* allowed.
|
|
1165
|
-
*
|
|
1166
|
-
* @param stepName name of the step being wrapped
|
|
1167
|
-
* @param stepFunction step function to wrap
|
|
1168
|
-
* @returns wrapped step function
|
|
1169
|
-
*/
|
|
1170
|
-
wrapStep<TResult = unknown>(stepName: string, stepFunction: StepFunction<TResult>): TResult | Promise<TResult>;
|
|
1171
|
-
/**
|
|
1172
|
-
* Executes a step:
|
|
1173
|
-
* - If the step result is available in the steps, returns the result
|
|
1174
|
-
* - If the result is not avaiable, runs the function
|
|
1175
|
-
* - Sends the result to QStash
|
|
1176
|
-
*
|
|
1177
|
-
* @param lazyStep lazy step to execute
|
|
1178
|
-
* @returns step result
|
|
1179
|
-
*/
|
|
1180
|
-
protected runSingle<TResult>(lazyStep: BaseLazyStep<TResult>): Promise<TResult>;
|
|
1181
|
-
/**
|
|
1182
|
-
* Runs steps in parallel.
|
|
1183
|
-
*
|
|
1184
|
-
* @param stepName parallel step name
|
|
1185
|
-
* @param stepFunctions list of async functions to run in parallel
|
|
1186
|
-
* @returns results of the functions run in parallel
|
|
1187
|
-
*/
|
|
1188
|
-
protected runParallel<TResults extends unknown[]>(parallelSteps: {
|
|
1189
|
-
[K in keyof TResults]: BaseLazyStep<TResults[K]>;
|
|
1190
|
-
}): Promise<TResults>;
|
|
1191
|
-
/**
|
|
1192
|
-
* Determines the parallel call state
|
|
1193
|
-
*
|
|
1194
|
-
* First filters the steps to get the steps which are after `initialStepCount` parameter.
|
|
1195
|
-
*
|
|
1196
|
-
* Depending on the remaining steps, decides the parallel state:
|
|
1197
|
-
* - "first": If there are no steps
|
|
1198
|
-
* - "last" If there are equal to or more than `2 * parallelStepCount`. We multiply by two
|
|
1199
|
-
* because each step in a parallel execution will have 2 steps: a plan step and a result
|
|
1200
|
-
* step.
|
|
1201
|
-
* - "partial": If the last step is a plan step
|
|
1202
|
-
* - "discard": If the last step is not a plan step. This means that the parallel execution
|
|
1203
|
-
* is in progress (there are still steps to run) and one step has finished and submitted
|
|
1204
|
-
* its result to QStash
|
|
1205
|
-
*
|
|
1206
|
-
* @param parallelStepCount number of steps to run in parallel
|
|
1207
|
-
* @param initialStepCount steps after the parallel invocation
|
|
1208
|
-
* @returns parallel call state
|
|
1209
|
-
*/
|
|
1210
|
-
protected getParallelCallState(parallelStepCount: number, initialStepCount: number): ParallelCallState;
|
|
1211
|
-
/**
|
|
1212
|
-
* sends the steps to QStash as batch
|
|
1213
|
-
*
|
|
1214
|
-
* @param steps steps to send
|
|
1215
|
-
*/
|
|
1216
|
-
private submitStepsToQStash;
|
|
1217
|
-
/**
|
|
1218
|
-
* Get the promise by executing the lazt steps list. If there is a single
|
|
1219
|
-
* step, we call `runSingle`. Otherwise `runParallel` is called.
|
|
1220
|
-
*
|
|
1221
|
-
* @param lazyStepList steps list to execute
|
|
1222
|
-
* @returns promise corresponding to the execution
|
|
1223
|
-
*/
|
|
1224
|
-
private getExecutionPromise;
|
|
1225
|
-
/**
|
|
1226
|
-
* @param lazyStepList steps we executed
|
|
1227
|
-
* @param result result of the promise from `getExecutionPromise`
|
|
1228
|
-
* @param index index of the current step
|
|
1229
|
-
* @returns result[index] if lazyStepList > 1, otherwise result
|
|
1230
|
-
*/
|
|
1231
|
-
private static getResult;
|
|
1232
|
-
private deferExecution;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
* QStash workflow context
|
|
1237
|
-
*
|
|
1238
|
-
* See the docs for fields and methods https://upstash.com/docs/qstash/workflows/basics/context
|
|
1239
|
-
*/
|
|
1240
|
-
declare class WorkflowContext<TInitialPayload = unknown> {
|
|
1241
|
-
protected readonly executor: AutoExecutor;
|
|
1242
|
-
protected readonly steps: Step[];
|
|
1243
|
-
/**
|
|
1244
|
-
* QStash client of the workflow
|
|
1245
|
-
*
|
|
1246
|
-
* Can be overwritten by passing `qstashClient` parameter in `serve`:
|
|
1247
|
-
*
|
|
1248
|
-
* ```ts
|
|
1249
|
-
* import { Client } from "@upstash/qstash"
|
|
1250
|
-
*
|
|
1251
|
-
* export const POST = serve(
|
|
1252
|
-
* async (context) => {
|
|
1253
|
-
* ...
|
|
1254
|
-
* },
|
|
1255
|
-
* {
|
|
1256
|
-
* qstashClient: new Client({...})
|
|
1257
|
-
* }
|
|
1258
|
-
* )
|
|
1259
|
-
* ```
|
|
1260
|
-
*/
|
|
1261
|
-
readonly qstashClient: WorkflowClient;
|
|
1262
|
-
/**
|
|
1263
|
-
* Run id of the workflow
|
|
1264
|
-
*/
|
|
1265
|
-
readonly workflowRunId: string;
|
|
1266
|
-
/**
|
|
1267
|
-
* URL of the workflow
|
|
1268
|
-
*
|
|
1269
|
-
* Can be overwritten by passing a `url` parameter in `serve`:
|
|
1270
|
-
*
|
|
1271
|
-
* ```ts
|
|
1272
|
-
* export const POST = serve(
|
|
1273
|
-
* async (context) => {
|
|
1274
|
-
* ...
|
|
1275
|
-
* },
|
|
1276
|
-
* {
|
|
1277
|
-
* url: "new-url-value"
|
|
1278
|
-
* }
|
|
1279
|
-
* )
|
|
1280
|
-
* ```
|
|
1281
|
-
*/
|
|
1282
|
-
readonly url: string;
|
|
1283
|
-
/**
|
|
1284
|
-
* URL to call in case of workflow failure with QStash failure callback
|
|
1285
|
-
*
|
|
1286
|
-
* https://upstash.com/docs/qstash/features/callbacks#what-is-a-failure-callback
|
|
1287
|
-
*
|
|
1288
|
-
* Can be overwritten by passing a `failureUrl` parameter in `serve`:
|
|
1289
|
-
*
|
|
1290
|
-
* ```ts
|
|
1291
|
-
* export const POST = serve(
|
|
1292
|
-
* async (context) => {
|
|
1293
|
-
* ...
|
|
1294
|
-
* },
|
|
1295
|
-
* {
|
|
1296
|
-
* failureUrl: "new-url-value"
|
|
1297
|
-
* }
|
|
1298
|
-
* )
|
|
1299
|
-
* ```
|
|
1300
|
-
*/
|
|
1301
|
-
readonly failureUrl?: string;
|
|
1302
|
-
/**
|
|
1303
|
-
* Payload of the request which started the workflow.
|
|
1304
|
-
*
|
|
1305
|
-
* To specify its type, you can define `serve` as follows:
|
|
1306
|
-
*
|
|
1307
|
-
* ```ts
|
|
1308
|
-
* // set requestPayload type to MyPayload:
|
|
1309
|
-
* export const POST = serve<MyPayload>(
|
|
1310
|
-
* async (context) => {
|
|
1311
|
-
* ...
|
|
1312
|
-
* }
|
|
1313
|
-
* )
|
|
1314
|
-
* ```
|
|
1315
|
-
*
|
|
1316
|
-
* By default, `serve` tries to apply `JSON.parse` to the request payload.
|
|
1317
|
-
* If your payload is encoded in a format other than JSON, you can utilize
|
|
1318
|
-
* the `initialPayloadParser` parameter:
|
|
1319
|
-
*
|
|
1320
|
-
* ```ts
|
|
1321
|
-
* export const POST = serve<MyPayload>(
|
|
1322
|
-
* async (context) => {
|
|
1323
|
-
* ...
|
|
1324
|
-
* },
|
|
1325
|
-
* {
|
|
1326
|
-
* initialPayloadParser: (initialPayload) => {return doSomething(initialPayload)}
|
|
1327
|
-
* }
|
|
1328
|
-
* )
|
|
1329
|
-
* ```
|
|
1330
|
-
*/
|
|
1331
|
-
readonly requestPayload: TInitialPayload;
|
|
1332
|
-
/**
|
|
1333
|
-
* headers of the initial request
|
|
1334
|
-
*/
|
|
1335
|
-
readonly headers: Headers;
|
|
1336
|
-
/**
|
|
1337
|
-
* initial payload as a raw string
|
|
1338
|
-
*/
|
|
1339
|
-
readonly rawInitialPayload: string;
|
|
1340
|
-
/**
|
|
1341
|
-
* Map of environment variables and their values.
|
|
1342
|
-
*
|
|
1343
|
-
* Can be set using the `env` option of serve:
|
|
1344
|
-
*
|
|
1345
|
-
* ```ts
|
|
1346
|
-
* export const POST = serve<MyPayload>(
|
|
1347
|
-
* async (context) => {
|
|
1348
|
-
* const key = context.env["API_KEY"];
|
|
1349
|
-
* },
|
|
1350
|
-
* {
|
|
1351
|
-
* env: {
|
|
1352
|
-
* "API_KEY": "*****";
|
|
1353
|
-
* }
|
|
1354
|
-
* }
|
|
1355
|
-
* )
|
|
1356
|
-
* ```
|
|
1357
|
-
*
|
|
1358
|
-
* Default value is set to `process.env`.
|
|
1359
|
-
*/
|
|
1360
|
-
readonly env: Record<string, string | undefined>;
|
|
1361
|
-
constructor({ qstashClient, workflowRunId, headers, steps, url, failureUrl, debug, initialPayload, rawInitialPayload, env, }: {
|
|
1362
|
-
qstashClient: WorkflowClient;
|
|
1363
|
-
workflowRunId: string;
|
|
1364
|
-
headers: Headers;
|
|
1365
|
-
steps: Step[];
|
|
1366
|
-
url: string;
|
|
1367
|
-
failureUrl?: string;
|
|
1368
|
-
debug?: WorkflowLogger;
|
|
1369
|
-
initialPayload: TInitialPayload;
|
|
1370
|
-
rawInitialPayload?: string;
|
|
1371
|
-
env?: Record<string, string | undefined>;
|
|
1372
|
-
});
|
|
1373
|
-
/**
|
|
1374
|
-
* Executes a workflow step
|
|
1375
|
-
*
|
|
1376
|
-
* ```typescript
|
|
1377
|
-
* const result = await context.run("step 1", () => {
|
|
1378
|
-
* return "result"
|
|
1379
|
-
* })
|
|
1380
|
-
* ```
|
|
1381
|
-
*
|
|
1382
|
-
* Can also be called in parallel and the steps will be executed
|
|
1383
|
-
* simulatenously:
|
|
1384
|
-
*
|
|
1385
|
-
* ```typescript
|
|
1386
|
-
* const [result1, result2] = await Promise.all([
|
|
1387
|
-
* context.run("step 1", () => {
|
|
1388
|
-
* return "result1"
|
|
1389
|
-
* })
|
|
1390
|
-
* context.run("step 2", async () => {
|
|
1391
|
-
* return await fetchResults()
|
|
1392
|
-
* })
|
|
1393
|
-
* ])
|
|
1394
|
-
* ```
|
|
1395
|
-
*
|
|
1396
|
-
* @param stepName name of the step
|
|
1397
|
-
* @param stepFunction step function to be executed
|
|
1398
|
-
* @returns result of the step function
|
|
1399
|
-
*/
|
|
1400
|
-
run<TResult>(stepName: string, stepFunction: StepFunction<TResult>): Promise<TResult>;
|
|
1401
|
-
/**
|
|
1402
|
-
* Stops the execution for the duration provided.
|
|
1403
|
-
*
|
|
1404
|
-
* @param stepName
|
|
1405
|
-
* @param duration sleep duration in seconds
|
|
1406
|
-
* @returns undefined
|
|
1407
|
-
*/
|
|
1408
|
-
sleep(stepName: string, duration: number): Promise<void>;
|
|
1409
|
-
/**
|
|
1410
|
-
* Stops the execution until the date time provided.
|
|
1411
|
-
*
|
|
1412
|
-
* @param stepName
|
|
1413
|
-
* @param datetime time to sleep until. Can be provided as a number (in unix seconds),
|
|
1414
|
-
* as a Date object or a string (passed to `new Date(datetimeString)`)
|
|
1415
|
-
* @returns undefined
|
|
1416
|
-
*/
|
|
1417
|
-
sleepUntil(stepName: string, datetime: Date | string | number): Promise<void>;
|
|
1418
|
-
/**
|
|
1419
|
-
* Makes a third party call through QStash in order to make a
|
|
1420
|
-
* network call without consuming any runtime.
|
|
1421
|
-
*
|
|
1422
|
-
* ```ts
|
|
1423
|
-
* const postResult = await context.call<string>(
|
|
1424
|
-
* "post call step",
|
|
1425
|
-
* `https://www.some-endpoint.com/api`,
|
|
1426
|
-
* "POST",
|
|
1427
|
-
* "my-payload"
|
|
1428
|
-
* );
|
|
1429
|
-
* ```
|
|
1430
|
-
*
|
|
1431
|
-
* tries to parse the result of the request as JSON. If it's
|
|
1432
|
-
* not a JSON which can be parsed, simply returns the response
|
|
1433
|
-
* body as it is.
|
|
1434
|
-
*
|
|
1435
|
-
* @param stepName
|
|
1436
|
-
* @param url url to call
|
|
1437
|
-
* @param method call method
|
|
1438
|
-
* @param body call body
|
|
1439
|
-
* @param headers call headers
|
|
1440
|
-
* @returns call result (parsed as JSON if possible)
|
|
1441
|
-
*/
|
|
1442
|
-
call<TResult = unknown, TBody = unknown>(stepName: string, url: string, method: HTTPMethods, body?: TBody, headers?: Record<string, string>): Promise<TResult>;
|
|
1443
|
-
/**
|
|
1444
|
-
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
1445
|
-
* DisabledWorkflowContext.
|
|
1446
|
-
*/
|
|
1447
|
-
protected addStep<TResult = unknown>(step: BaseLazyStep<TResult>): Promise<TResult>;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
/**
|
|
1451
|
-
* Interface for Client with required methods
|
|
1452
|
-
*
|
|
1453
|
-
* Neeeded to resolve import issues
|
|
1454
|
-
*/
|
|
1455
|
-
type WorkflowClient = {
|
|
1456
|
-
batchJSON: InstanceType<typeof Client>["batchJSON"];
|
|
1457
|
-
publishJSON: InstanceType<typeof Client>["publishJSON"];
|
|
1458
|
-
http: InstanceType<typeof Client>["http"];
|
|
1459
|
-
};
|
|
1460
|
-
/**
|
|
1461
|
-
* Interface for Receiver with required methods
|
|
1462
|
-
*
|
|
1463
|
-
* Neeeded to resolve import issues
|
|
1464
|
-
*/
|
|
1465
|
-
type WorkflowReceiver = {
|
|
1466
|
-
verify: InstanceType<typeof Receiver>["verify"];
|
|
1467
|
-
};
|
|
1468
|
-
declare const StepTypes: readonly ["Initial", "Run", "SleepFor", "SleepUntil", "Call"];
|
|
1469
|
-
type StepType = (typeof StepTypes)[number];
|
|
1470
|
-
type ThirdPartyCallFields<TBody = unknown> = {
|
|
1471
|
-
/**
|
|
1472
|
-
* Third party call URL. Set when context.call is used.
|
|
1473
|
-
*/
|
|
1474
|
-
callUrl: string;
|
|
1475
|
-
/**
|
|
1476
|
-
* Third party call method. Set when context.call is used.
|
|
1477
|
-
*/
|
|
1478
|
-
callMethod: HTTPMethods;
|
|
1479
|
-
/**
|
|
1480
|
-
* Third party call body. Set when context.call is used.
|
|
1481
|
-
*/
|
|
1482
|
-
callBody: TBody;
|
|
1483
|
-
/**
|
|
1484
|
-
* Third party call headers. Set when context.call is used.
|
|
1485
|
-
*/
|
|
1486
|
-
callHeaders: Record<string, string>;
|
|
1487
|
-
};
|
|
1488
|
-
type Step<TResult = unknown, TBody = unknown> = {
|
|
1489
|
-
/**
|
|
1490
|
-
* index of the step
|
|
1491
|
-
*/
|
|
1492
|
-
stepId: number;
|
|
1493
|
-
/**
|
|
1494
|
-
* name of the step
|
|
1495
|
-
*/
|
|
1496
|
-
stepName: string;
|
|
1497
|
-
/**
|
|
1498
|
-
* type of the step (Initial/Run/SleepFor/SleepUntil/Call)
|
|
1499
|
-
*/
|
|
1500
|
-
stepType: StepType;
|
|
1501
|
-
/**
|
|
1502
|
-
* step result. Set if context.run or context.call are used.
|
|
1503
|
-
*/
|
|
1504
|
-
out?: TResult;
|
|
1505
|
-
/**
|
|
1506
|
-
* sleep duration in seconds. Set when context.sleep is used.
|
|
1507
|
-
*/
|
|
1508
|
-
sleepFor?: number;
|
|
1509
|
-
/**
|
|
1510
|
-
* unix timestamp (in seconds) to wait until. Set when context.sleepUntil is used.
|
|
1511
|
-
*/
|
|
1512
|
-
sleepUntil?: number;
|
|
1513
|
-
/**
|
|
1514
|
-
* number of steps running concurrently if the step is in a parallel run.
|
|
1515
|
-
* Set to 1 if step is not parallel.
|
|
1516
|
-
*/
|
|
1517
|
-
concurrent: number;
|
|
1518
|
-
/**
|
|
1519
|
-
* target step of a plan step. In other words, the step to assign the
|
|
1520
|
-
* result of a plan step.
|
|
1521
|
-
*
|
|
1522
|
-
* undefined if the step is not a plan step (of a parallel run). Otherwise,
|
|
1523
|
-
* set to the target step.
|
|
1524
|
-
*/
|
|
1525
|
-
targetStep?: number;
|
|
1526
|
-
} & (ThirdPartyCallFields<TBody> | {
|
|
1527
|
-
[P in keyof ThirdPartyCallFields]?: never;
|
|
1528
|
-
});
|
|
1529
|
-
type SyncStepFunction<TResult> = () => TResult;
|
|
1530
|
-
type AsyncStepFunction<TResult> = () => Promise<TResult>;
|
|
1531
|
-
type StepFunction<TResult> = AsyncStepFunction<TResult> | SyncStepFunction<TResult>;
|
|
1532
|
-
type ParallelCallState = "first" | "partial" | "discard" | "last";
|
|
1533
|
-
type RouteFunction<TInitialPayload> = (context: WorkflowContext<TInitialPayload>) => Promise<void>;
|
|
1534
|
-
type FinishCondition = "success" | "duplicate-step" | "fromCallback" | "auth-fail" | "failure-callback";
|
|
1535
|
-
type WorkflowServeOptions<TResponse extends Response = Response, TInitialPayload = unknown> = {
|
|
1536
|
-
/**
|
|
1537
|
-
* QStash client
|
|
1538
|
-
*/
|
|
1539
|
-
qstashClient?: WorkflowClient;
|
|
1540
|
-
/**
|
|
1541
|
-
* Function called to return a response after each step execution
|
|
1542
|
-
*
|
|
1543
|
-
* @param workflowRunId
|
|
1544
|
-
* @returns response
|
|
1545
|
-
*/
|
|
1546
|
-
onStepFinish?: (workflowRunId: string, finishCondition: FinishCondition) => TResponse;
|
|
1547
|
-
/**
|
|
1548
|
-
* Function to parse the initial payload passed by the user
|
|
1549
|
-
*/
|
|
1550
|
-
initialPayloadParser?: (initialPayload: string) => TInitialPayload;
|
|
1551
|
-
/**
|
|
1552
|
-
* Url of the endpoint where the workflow is set up.
|
|
1553
|
-
*
|
|
1554
|
-
* If not set, url will be inferred from the request.
|
|
1555
|
-
*/
|
|
1556
|
-
url?: string;
|
|
1557
|
-
/**
|
|
1558
|
-
* Verbose mode
|
|
1559
|
-
*
|
|
1560
|
-
* Disabled if not set. If set to true, a logger is created automatically.
|
|
1561
|
-
*
|
|
1562
|
-
* Alternatively, a WorkflowLogger can be passed.
|
|
1563
|
-
*/
|
|
1564
|
-
verbose?: WorkflowLogger | true;
|
|
1565
|
-
/**
|
|
1566
|
-
* Receiver to verify *all* requests by checking if they come from QStash
|
|
1567
|
-
*
|
|
1568
|
-
* By default, a receiver is created from the env variables
|
|
1569
|
-
* QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY if they are set.
|
|
1570
|
-
*/
|
|
1571
|
-
receiver?: WorkflowReceiver;
|
|
1572
|
-
/**
|
|
1573
|
-
* Url to call if QStash retries are exhausted while executing the workflow
|
|
1574
|
-
*/
|
|
1575
|
-
failureUrl?: string;
|
|
1576
|
-
/**
|
|
1577
|
-
* Failure function called when QStash retries are exhausted while executing
|
|
1578
|
-
* the workflow. Will overwrite `failureUrl` parameter with the workflow
|
|
1579
|
-
* endpoint if passed.
|
|
1580
|
-
*
|
|
1581
|
-
* @param context workflow context at the moment of error
|
|
1582
|
-
* @param failStatus error status
|
|
1583
|
-
* @param failResponse error message
|
|
1584
|
-
* @returns void
|
|
1585
|
-
*/
|
|
1586
|
-
failureFunction?: (context: Omit<WorkflowContext, "run" | "sleepUntil" | "sleep" | "call">, failStatus: number, failResponse: string, failHeader: Record<string, string[]>) => Promise<void> | void;
|
|
1587
|
-
/**
|
|
1588
|
-
* Base Url of the workflow endpoint
|
|
1589
|
-
*
|
|
1590
|
-
* Can be used to set if there is a local tunnel or a proxy between
|
|
1591
|
-
* QStash and the workflow endpoint.
|
|
1592
|
-
*
|
|
1593
|
-
* Will be set to the env variable UPSTASH_WORKFLOW_URL if not passed.
|
|
1594
|
-
* If the env variable is not set, the url will be infered as usual from
|
|
1595
|
-
* the `request.url` or the `url` parameter in `serve` options.
|
|
1596
|
-
*
|
|
1597
|
-
* @default undefined
|
|
1598
|
-
*/
|
|
1599
|
-
baseUrl?: string;
|
|
1600
|
-
/**
|
|
1601
|
-
* Optionally, one can pass an env object mapping environment
|
|
1602
|
-
* variables to their keys.
|
|
1603
|
-
*
|
|
1604
|
-
* Useful in cases like cloudflare with hono.
|
|
1605
|
-
*/
|
|
1606
|
-
env?: Record<string, string | undefined>;
|
|
1607
|
-
};
|
|
1608
|
-
|
|
1609
|
-
declare class Workflow {
|
|
1610
|
-
private readonly http;
|
|
1611
|
-
constructor(http: Requester);
|
|
1612
|
-
/**
|
|
1613
|
-
* Cancel an ongoing workflow
|
|
1614
|
-
*
|
|
1615
|
-
* @param workflowRunId run id of the workflow to delete
|
|
1616
|
-
* @returns true if workflow is succesfully deleted. Otherwise throws QStashError
|
|
1617
|
-
*/
|
|
1618
|
-
cancel(workflowRunId: string): Promise<true | {
|
|
1619
|
-
error: string;
|
|
1620
|
-
}>;
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
type WorkflowBindings = {
|
|
1624
|
-
QSTASH_TOKEN: string;
|
|
1625
|
-
QSTASH_URL?: string;
|
|
1626
|
-
QSTASH_CURRENT_SIGNING_KEY?: string;
|
|
1627
|
-
QSTASH_NEXT_SIGNING_KEY?: string;
|
|
1628
|
-
UPSTASH_WORKFLOW_URL?: string;
|
|
1629
|
-
};
|
|
1630
|
-
/**
|
|
1631
|
-
* Cloudflare Pages Function arguments
|
|
1632
|
-
*/
|
|
1633
|
-
type PagesHandlerArgs = [{
|
|
1634
|
-
request: Request;
|
|
1635
|
-
env: Record<string, string | undefined>;
|
|
1636
|
-
}];
|
|
1637
|
-
/**
|
|
1638
|
-
* Cloudflare Worker arguments
|
|
1639
|
-
*/
|
|
1640
|
-
type WorkersHandlerArgs = [Request, Record<string, string | undefined>];
|
|
1641
|
-
/**
|
|
1642
|
-
* Serve method to serve a QStash workflow in a Nextjs project
|
|
1643
|
-
*
|
|
1644
|
-
* See for options https://upstash.com/docs/qstash/workflows/basics/serve
|
|
1645
|
-
*
|
|
1646
|
-
* @param routeFunction workflow function
|
|
1647
|
-
* @param options workflow options
|
|
1648
|
-
* @returns
|
|
1649
|
-
*/
|
|
1650
|
-
declare const serve: <TInitialPayload = unknown>(routeFunction: RouteFunction<TInitialPayload>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">) => ((...args: PagesHandlerArgs | WorkersHandlerArgs) => Promise<Response>);
|
|
1651
|
-
|
|
1652
|
-
export { type PagesHandlerArgs, type WorkersHandlerArgs, type WorkflowBindings, serve };
|