@upstash/qstash 2.6.3 → 2.6.4-workflow-alpha.0
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 +4 -49
- package/dist/LICENSE +21 -0
- package/dist/README.md +160 -0
- package/{chunk-PTZPACVC.mjs → dist/chunk-AP5AZGAQ.mjs} +492 -472
- package/dist/chunk-EXC7PGHF.mjs +1540 -0
- package/dist/chunk-F6QRAN74.js +30 -0
- package/dist/chunk-OAS6SVLB.js +1540 -0
- package/dist/chunk-TAUBWUPA.mjs +30 -0
- package/{chunk-DZD3BOMO.js → dist/chunk-Z3TALRVS.js} +507 -487
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +38 -0
- package/{index.mjs → dist/index.mjs} +13 -11
- package/{nextjs.d.mts → dist/nextjs.d.mts} +4 -1
- package/{nextjs.d.ts → dist/nextjs.d.ts} +4 -1
- package/{nextjs.js → dist/nextjs.js} +21 -5
- package/{nextjs.mjs → dist/nextjs.mjs} +17 -1
- package/dist/nuxt.d.mts +22 -0
- package/dist/nuxt.d.ts +22 -0
- package/{nuxt.js → dist/nuxt.js} +59 -4
- package/dist/nuxt.mjs +103 -0
- package/dist/package.json +105 -0
- package/dist/solidjs.d.mts +13 -0
- package/dist/solidjs.d.ts +13 -0
- package/{solidjs.js → dist/solidjs.js} +25 -4
- package/{solidjs.mjs → dist/solidjs.mjs} +23 -2
- package/{svelte.d.mts → dist/svelte.d.mts} +4 -1
- package/{svelte.d.ts → dist/svelte.d.ts} +4 -1
- package/{svelte.js → dist/svelte.js} +27 -4
- package/{svelte.mjs → dist/svelte.mjs} +25 -2
- package/{index.d.mts → dist/types-BBuddmpw.d.mts} +416 -50
- package/{index.d.ts → dist/types-BBuddmpw.d.ts} +416 -50
- package/dist/workflow.d.mts +15 -0
- package/dist/workflow.d.ts +15 -0
- package/dist/workflow.js +15 -0
- package/dist/workflow.mjs +15 -0
- package/package.json +105 -1
- package/chunk-CP4IU45K.mjs +0 -59
- package/chunk-UUR7N6E6.js +0 -59
- package/index.js +0 -36
- package/nuxt.d.mts +0 -11
- package/nuxt.d.ts +0 -11
- package/nuxt.mjs +0 -48
- package/solidjs.d.mts +0 -10
- package/solidjs.d.ts +0 -10
|
@@ -1,4 +1,484 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// src/
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;// src/receiver.ts
|
|
2
|
+
var _jose = require('jose'); var jose = _interopRequireWildcard(_jose);
|
|
3
|
+
var _cryptojs = require('crypto-js'); var _cryptojs2 = _interopRequireDefault(_cryptojs);
|
|
4
|
+
var SignatureError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "SignatureError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var Receiver = class {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.currentSigningKey = config.currentSigningKey;
|
|
15
|
+
this.nextSigningKey = config.nextSigningKey;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Verify the signature of a request.
|
|
19
|
+
*
|
|
20
|
+
* Tries to verify the signature with the current signing key.
|
|
21
|
+
* If that fails, maybe because you have rotated the keys recently, it will
|
|
22
|
+
* try to verify the signature with the next signing key.
|
|
23
|
+
*
|
|
24
|
+
* If that fails, the signature is invalid and a `SignatureError` is thrown.
|
|
25
|
+
*/
|
|
26
|
+
async verify(request) {
|
|
27
|
+
const isValid = await this.verifyWithKey(this.currentSigningKey, request);
|
|
28
|
+
if (isValid) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return this.verifyWithKey(this.nextSigningKey, request);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Verify signature with a specific signing key
|
|
35
|
+
*/
|
|
36
|
+
async verifyWithKey(key, request) {
|
|
37
|
+
const jwt = await jose.jwtVerify(request.signature, new TextEncoder().encode(key), {
|
|
38
|
+
issuer: "Upstash",
|
|
39
|
+
clockTolerance: request.clockTolerance
|
|
40
|
+
}).catch((error) => {
|
|
41
|
+
throw new SignatureError(error.message);
|
|
42
|
+
});
|
|
43
|
+
const p = jwt.payload;
|
|
44
|
+
if (request.url !== void 0 && p.sub !== request.url) {
|
|
45
|
+
throw new SignatureError(`invalid subject: ${p.sub}, want: ${request.url}`);
|
|
46
|
+
}
|
|
47
|
+
const bodyHash = _cryptojs2.default.SHA256(request.body).toString(_cryptojs2.default.enc.Base64url);
|
|
48
|
+
const padding = new RegExp(/=+$/);
|
|
49
|
+
if (p.body.replace(padding, "") !== bodyHash.replace(padding, "")) {
|
|
50
|
+
throw new SignatureError(`body hash does not match, want: ${p.body}, got: ${bodyHash}`);
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/client/error.ts
|
|
57
|
+
var QstashError = class extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "QstashError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var QstashRatelimitError = class extends QstashError {
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
constructor(args) {
|
|
68
|
+
super(`Exceeded burst rate limit. ${JSON.stringify(args)} `);
|
|
69
|
+
this.name = "QstashRatelimitError";
|
|
70
|
+
this.limit = args.limit;
|
|
71
|
+
this.remaining = args.remaining;
|
|
72
|
+
this.reset = args.reset;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var QstashChatRatelimitError = class extends QstashError {
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
constructor(args) {
|
|
83
|
+
super(`Exceeded chat rate limit. ${JSON.stringify(args)} `);
|
|
84
|
+
this.limitRequests = args["limit-requests"];
|
|
85
|
+
this.limitTokens = args["limit-tokens"];
|
|
86
|
+
this.remainingRequests = args["remaining-requests"];
|
|
87
|
+
this.remainingTokens = args["remaining-tokens"];
|
|
88
|
+
this.resetRequests = args["reset-requests"];
|
|
89
|
+
this.resetTokens = args["reset-tokens"];
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var QstashDailyRatelimitError = class extends QstashError {
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
constructor(args) {
|
|
97
|
+
super(`Exceeded daily rate limit. ${JSON.stringify(args)} `);
|
|
98
|
+
this.limit = args.limit;
|
|
99
|
+
this.remaining = args.remaining;
|
|
100
|
+
this.reset = args.reset;
|
|
101
|
+
this.name = "QstashChatRatelimitError";
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var QstashWorkflowError = class extends QstashError {
|
|
105
|
+
constructor(message) {
|
|
106
|
+
super(message);
|
|
107
|
+
this.name = "QstashWorkflowError";
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var QstashWorkflowAbort = class extends Error {
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
constructor(stepName, stepInfo) {
|
|
114
|
+
super(`Aborting workflow after executing step '${stepName}'.`);
|
|
115
|
+
this.name = "QstashWorkflowAbort";
|
|
116
|
+
this.stepName = stepName;
|
|
117
|
+
this.stepInfo = stepInfo;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/client/llm/chat.ts
|
|
122
|
+
var Chat = (_class = class _Chat {
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
constructor(http, token) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
126
|
+
this.http = http;
|
|
127
|
+
this.token = token;
|
|
128
|
+
}
|
|
129
|
+
static toChatRequest(request) {
|
|
130
|
+
const messages = [];
|
|
131
|
+
messages.push(
|
|
132
|
+
{ role: "system", content: request.system },
|
|
133
|
+
{ role: "user", content: request.user }
|
|
134
|
+
);
|
|
135
|
+
const chatRequest = { ...request, messages };
|
|
136
|
+
return chatRequest;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Calls the Upstash completions api given a ChatRequest.
|
|
140
|
+
*
|
|
141
|
+
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
142
|
+
* if stream is enabled.
|
|
143
|
+
*
|
|
144
|
+
* @param request ChatRequest with messages
|
|
145
|
+
* @returns Chat completion or stream
|
|
146
|
+
*/
|
|
147
|
+
__init() {this.create = async (request) => {
|
|
148
|
+
if (request.provider.owner != "upstash")
|
|
149
|
+
return this.createThirdParty(request);
|
|
150
|
+
const body = JSON.stringify(request);
|
|
151
|
+
if ("stream" in request && request.stream) {
|
|
152
|
+
return this.http.requestStream({
|
|
153
|
+
path: ["llm", "v1", "chat", "completions"],
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: {
|
|
156
|
+
"Content-Type": "application/json",
|
|
157
|
+
Connection: "keep-alive",
|
|
158
|
+
Accept: "text/event-stream",
|
|
159
|
+
"Cache-Control": "no-cache",
|
|
160
|
+
Authorization: `Bearer ${this.token}`
|
|
161
|
+
},
|
|
162
|
+
body
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return this.http.request({
|
|
166
|
+
path: ["llm", "v1", "chat", "completions"],
|
|
167
|
+
method: "POST",
|
|
168
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.token}` },
|
|
169
|
+
body
|
|
170
|
+
});
|
|
171
|
+
}}
|
|
172
|
+
/**
|
|
173
|
+
* Calls the Upstash completions api given a ChatRequest.
|
|
174
|
+
*
|
|
175
|
+
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
176
|
+
* if stream is enabled.
|
|
177
|
+
*
|
|
178
|
+
* @param request ChatRequest with messages
|
|
179
|
+
* @returns Chat completion or stream
|
|
180
|
+
*/
|
|
181
|
+
__init2() {this.createThirdParty = async (request) => {
|
|
182
|
+
const { baseUrl, token, owner } = request.provider;
|
|
183
|
+
if (owner === "upstash")
|
|
184
|
+
throw new Error("Upstash is not 3rd party provider!");
|
|
185
|
+
delete request.provider;
|
|
186
|
+
delete request.system;
|
|
187
|
+
const body = JSON.stringify(request);
|
|
188
|
+
if ("stream" in request && request.stream) {
|
|
189
|
+
return this.http.requestStream({
|
|
190
|
+
path: ["v1", "chat", "completions"],
|
|
191
|
+
method: "POST",
|
|
192
|
+
headers: {
|
|
193
|
+
"Content-Type": "application/json",
|
|
194
|
+
Connection: "keep-alive",
|
|
195
|
+
Accept: "text/event-stream",
|
|
196
|
+
"Cache-Control": "no-cache",
|
|
197
|
+
Authorization: `Bearer ${token}`
|
|
198
|
+
},
|
|
199
|
+
body,
|
|
200
|
+
baseUrl
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return this.http.request({
|
|
204
|
+
path: ["v1", "chat", "completions"],
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: {
|
|
207
|
+
"Content-Type": "application/json",
|
|
208
|
+
Authorization: `Bearer ${token}`
|
|
209
|
+
},
|
|
210
|
+
body,
|
|
211
|
+
baseUrl
|
|
212
|
+
});
|
|
213
|
+
}}
|
|
214
|
+
/**
|
|
215
|
+
* Calls the Upstash completions api given a PromptRequest.
|
|
216
|
+
*
|
|
217
|
+
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
218
|
+
* if stream is enabled.
|
|
219
|
+
*
|
|
220
|
+
* @param request PromptRequest with system and user messages.
|
|
221
|
+
* Note that system parameter shouldn't be passed in the case of
|
|
222
|
+
* mistralai/Mistral-7B-Instruct-v0.2 model.
|
|
223
|
+
* @returns Chat completion or stream
|
|
224
|
+
*/
|
|
225
|
+
__init3() {this.prompt = async (request) => {
|
|
226
|
+
const chatRequest = _Chat.toChatRequest(request);
|
|
227
|
+
return this.create(chatRequest);
|
|
228
|
+
}}
|
|
229
|
+
}, _class);
|
|
230
|
+
|
|
231
|
+
// src/client/messages.ts
|
|
232
|
+
var Messages = class {
|
|
233
|
+
|
|
234
|
+
constructor(http) {
|
|
235
|
+
this.http = http;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Get a message
|
|
239
|
+
*/
|
|
240
|
+
async get(messageId) {
|
|
241
|
+
const messagePayload = await this.http.request({
|
|
242
|
+
method: "GET",
|
|
243
|
+
path: ["v2", "messages", messageId]
|
|
244
|
+
});
|
|
245
|
+
const message = {
|
|
246
|
+
...messagePayload,
|
|
247
|
+
urlGroup: messagePayload.topicName
|
|
248
|
+
};
|
|
249
|
+
return message;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Cancel a message
|
|
253
|
+
*/
|
|
254
|
+
async delete(messageId) {
|
|
255
|
+
return await this.http.request({
|
|
256
|
+
method: "DELETE",
|
|
257
|
+
path: ["v2", "messages", messageId],
|
|
258
|
+
parseResponseAsJson: false
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async deleteMany(messageIds) {
|
|
262
|
+
const result = await this.http.request({
|
|
263
|
+
method: "DELETE",
|
|
264
|
+
path: ["v2", "messages"],
|
|
265
|
+
headers: { "Content-Type": "application/json" },
|
|
266
|
+
body: JSON.stringify({ messageIds })
|
|
267
|
+
});
|
|
268
|
+
return result.cancelled;
|
|
269
|
+
}
|
|
270
|
+
async deleteAll() {
|
|
271
|
+
const result = await this.http.request({
|
|
272
|
+
method: "DELETE",
|
|
273
|
+
path: ["v2", "messages"]
|
|
274
|
+
});
|
|
275
|
+
return result.cancelled;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// src/client/utils.ts
|
|
280
|
+
var isIgnoredHeader = (header) => {
|
|
281
|
+
const lowerCaseHeader = header.toLowerCase();
|
|
282
|
+
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
|
|
283
|
+
};
|
|
284
|
+
function prefixHeaders(headers) {
|
|
285
|
+
const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key));
|
|
286
|
+
for (const key of keysToBePrefixed) {
|
|
287
|
+
const value = headers.get(key);
|
|
288
|
+
if (value !== null) {
|
|
289
|
+
headers.set(`Upstash-Forward-${key}`, value);
|
|
290
|
+
}
|
|
291
|
+
headers.delete(key);
|
|
292
|
+
}
|
|
293
|
+
return headers;
|
|
294
|
+
}
|
|
295
|
+
function processHeaders(request) {
|
|
296
|
+
const headers = prefixHeaders(new Headers(request.headers));
|
|
297
|
+
headers.set("Upstash-Method", _nullishCoalesce(request.method, () => ( "POST")));
|
|
298
|
+
if (request.delay !== void 0) {
|
|
299
|
+
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
|
|
300
|
+
}
|
|
301
|
+
if (request.notBefore !== void 0) {
|
|
302
|
+
headers.set("Upstash-Not-Before", request.notBefore.toFixed(0));
|
|
303
|
+
}
|
|
304
|
+
if (request.deduplicationId !== void 0) {
|
|
305
|
+
headers.set("Upstash-Deduplication-Id", request.deduplicationId);
|
|
306
|
+
}
|
|
307
|
+
if (request.contentBasedDeduplication !== void 0) {
|
|
308
|
+
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
309
|
+
}
|
|
310
|
+
if (request.retries !== void 0) {
|
|
311
|
+
headers.set("Upstash-Retries", request.retries.toFixed(0));
|
|
312
|
+
}
|
|
313
|
+
if (request.callback !== void 0) {
|
|
314
|
+
headers.set("Upstash-Callback", request.callback);
|
|
315
|
+
}
|
|
316
|
+
if (request.failureCallback !== void 0) {
|
|
317
|
+
headers.set("Upstash-Failure-Callback", request.failureCallback);
|
|
318
|
+
}
|
|
319
|
+
if (request.timeout !== void 0) {
|
|
320
|
+
headers.set("Upstash-Timeout", `${request.timeout}s`);
|
|
321
|
+
}
|
|
322
|
+
return headers;
|
|
323
|
+
}
|
|
324
|
+
function getRequestPath(request) {
|
|
325
|
+
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(request.url, () => ( request.urlGroup)), () => ( request.topic)), () => ( `api/${_optionalChain([request, 'access', _ => _.api, 'optionalAccess', _2 => _2.name])}`));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/client/schedules.ts
|
|
329
|
+
var Schedules = class {
|
|
330
|
+
|
|
331
|
+
constructor(http) {
|
|
332
|
+
this.http = http;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Create a schedule
|
|
336
|
+
*/
|
|
337
|
+
async create(request) {
|
|
338
|
+
const headers = prefixHeaders(new Headers(request.headers));
|
|
339
|
+
if (!headers.has("Content-Type")) {
|
|
340
|
+
headers.set("Content-Type", "application/json");
|
|
341
|
+
}
|
|
342
|
+
headers.set("Upstash-Cron", request.cron);
|
|
343
|
+
if (request.method !== void 0) {
|
|
344
|
+
headers.set("Upstash-Method", request.method);
|
|
345
|
+
}
|
|
346
|
+
if (request.delay !== void 0) {
|
|
347
|
+
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
|
|
348
|
+
}
|
|
349
|
+
if (request.retries !== void 0) {
|
|
350
|
+
headers.set("Upstash-Retries", request.retries.toFixed(0));
|
|
351
|
+
}
|
|
352
|
+
if (request.callback !== void 0) {
|
|
353
|
+
headers.set("Upstash-Callback", request.callback);
|
|
354
|
+
}
|
|
355
|
+
if (request.failureCallback !== void 0) {
|
|
356
|
+
headers.set("Upstash-Failure-Callback", request.failureCallback);
|
|
357
|
+
}
|
|
358
|
+
if (request.timeout !== void 0) {
|
|
359
|
+
headers.set("Upstash-Timeout", `${request.timeout}s`);
|
|
360
|
+
}
|
|
361
|
+
return await this.http.request({
|
|
362
|
+
method: "POST",
|
|
363
|
+
headers,
|
|
364
|
+
path: ["v2", "schedules", request.destination],
|
|
365
|
+
body: request.body
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get a schedule
|
|
370
|
+
*/
|
|
371
|
+
async get(scheduleId) {
|
|
372
|
+
return await this.http.request({
|
|
373
|
+
method: "GET",
|
|
374
|
+
path: ["v2", "schedules", scheduleId]
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* List your schedules
|
|
379
|
+
*/
|
|
380
|
+
async list() {
|
|
381
|
+
return await this.http.request({
|
|
382
|
+
method: "GET",
|
|
383
|
+
path: ["v2", "schedules"]
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Delete a schedule
|
|
388
|
+
*/
|
|
389
|
+
async delete(scheduleId) {
|
|
390
|
+
return await this.http.request({
|
|
391
|
+
method: "DELETE",
|
|
392
|
+
path: ["v2", "schedules", scheduleId],
|
|
393
|
+
parseResponseAsJson: false
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Pauses the schedule.
|
|
398
|
+
*
|
|
399
|
+
* A paused schedule will not deliver messages until
|
|
400
|
+
* it is resumed.
|
|
401
|
+
*/
|
|
402
|
+
async pause({ schedule }) {
|
|
403
|
+
await this.http.request({
|
|
404
|
+
method: "PATCH",
|
|
405
|
+
path: ["v2", "schedules", schedule, "pause"],
|
|
406
|
+
parseResponseAsJson: false
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Resumes the schedule.
|
|
411
|
+
*/
|
|
412
|
+
async resume({ schedule }) {
|
|
413
|
+
await this.http.request({
|
|
414
|
+
method: "PATCH",
|
|
415
|
+
path: ["v2", "schedules", schedule, "resume"],
|
|
416
|
+
parseResponseAsJson: false
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/client/url-groups.ts
|
|
422
|
+
var UrlGroups = class {
|
|
423
|
+
|
|
424
|
+
constructor(http) {
|
|
425
|
+
this.http = http;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Create a new url group with the given name and endpoints
|
|
429
|
+
*/
|
|
430
|
+
async addEndpoints(request) {
|
|
431
|
+
await this.http.request({
|
|
432
|
+
method: "POST",
|
|
433
|
+
path: ["v2", "topics", request.name, "endpoints"],
|
|
434
|
+
headers: { "Content-Type": "application/json" },
|
|
435
|
+
body: JSON.stringify({ endpoints: request.endpoints }),
|
|
436
|
+
parseResponseAsJson: false
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Remove endpoints from a url group.
|
|
441
|
+
*/
|
|
442
|
+
async removeEndpoints(request) {
|
|
443
|
+
await this.http.request({
|
|
444
|
+
method: "DELETE",
|
|
445
|
+
path: ["v2", "topics", request.name, "endpoints"],
|
|
446
|
+
headers: { "Content-Type": "application/json" },
|
|
447
|
+
body: JSON.stringify({ endpoints: request.endpoints }),
|
|
448
|
+
parseResponseAsJson: false
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Get a list of all url groups.
|
|
453
|
+
*/
|
|
454
|
+
async list() {
|
|
455
|
+
return await this.http.request({
|
|
456
|
+
method: "GET",
|
|
457
|
+
path: ["v2", "topics"]
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Get a single url group
|
|
462
|
+
*/
|
|
463
|
+
async get(name) {
|
|
464
|
+
return await this.http.request({
|
|
465
|
+
method: "GET",
|
|
466
|
+
path: ["v2", "topics", name]
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Delete a url group
|
|
471
|
+
*/
|
|
472
|
+
async delete(name) {
|
|
473
|
+
return await this.http.request({
|
|
474
|
+
method: "DELETE",
|
|
475
|
+
path: ["v2", "topics", name],
|
|
476
|
+
parseResponseAsJson: false
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/client/dlq.ts
|
|
2
482
|
var DLQ = class {
|
|
3
483
|
|
|
4
484
|
constructor(http) {
|
|
@@ -9,15 +489,15 @@ var DLQ = class {
|
|
|
9
489
|
*/
|
|
10
490
|
async listMessages(options) {
|
|
11
491
|
const filterPayload = {
|
|
12
|
-
..._optionalChain([options, 'optionalAccess',
|
|
13
|
-
topicName: _optionalChain([options, 'optionalAccess',
|
|
492
|
+
..._optionalChain([options, 'optionalAccess', _3 => _3.filter]),
|
|
493
|
+
topicName: _optionalChain([options, 'optionalAccess', _4 => _4.filter, 'optionalAccess', _5 => _5.urlGroup])
|
|
14
494
|
};
|
|
15
495
|
const messagesPayload = await this.http.request({
|
|
16
496
|
method: "GET",
|
|
17
497
|
path: ["v2", "dlq"],
|
|
18
498
|
query: {
|
|
19
|
-
cursor: _optionalChain([options, 'optionalAccess',
|
|
20
|
-
count: _optionalChain([options, 'optionalAccess',
|
|
499
|
+
cursor: _optionalChain([options, 'optionalAccess', _6 => _6.cursor]),
|
|
500
|
+
count: _optionalChain([options, 'optionalAccess', _7 => _7.count]),
|
|
21
501
|
...filterPayload
|
|
22
502
|
}
|
|
23
503
|
});
|
|
@@ -55,60 +535,13 @@ var DLQ = class {
|
|
|
55
535
|
}
|
|
56
536
|
};
|
|
57
537
|
|
|
58
|
-
// src/client/error.ts
|
|
59
|
-
var QstashError = class extends Error {
|
|
60
|
-
constructor(message) {
|
|
61
|
-
super(message);
|
|
62
|
-
this.name = "QstashError";
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var QstashRatelimitError = class extends QstashError {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
constructor(args) {
|
|
70
|
-
super(`Exceeded burst rate limit. ${JSON.stringify(args)} `);
|
|
71
|
-
this.limit = args.limit;
|
|
72
|
-
this.remaining = args.remaining;
|
|
73
|
-
this.reset = args.reset;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var QstashChatRatelimitError = class extends QstashError {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
constructor(args) {
|
|
84
|
-
super(`Exceeded chat rate limit. ${JSON.stringify(args)} `);
|
|
85
|
-
this.limitRequests = args["limit-requests"];
|
|
86
|
-
this.limitTokens = args["limit-tokens"];
|
|
87
|
-
this.remainingRequests = args["remaining-requests"];
|
|
88
|
-
this.remainingTokens = args["remaining-tokens"];
|
|
89
|
-
this.resetRequests = args["reset-requests"];
|
|
90
|
-
this.resetTokens = args["reset-tokens"];
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var QstashDailyRatelimitError = class extends QstashError {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
constructor(args) {
|
|
98
|
-
super(`Exceeded daily rate limit. ${JSON.stringify(args)} `);
|
|
99
|
-
this.limit = args.limit;
|
|
100
|
-
this.remaining = args.remaining;
|
|
101
|
-
this.reset = args.reset;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
538
|
// src/client/http.ts
|
|
106
|
-
var HttpClient = (
|
|
539
|
+
var HttpClient = (_class2 = class {
|
|
107
540
|
|
|
108
541
|
|
|
109
542
|
|
|
110
543
|
|
|
111
|
-
constructor(config) {;
|
|
544
|
+
constructor(config) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
|
|
112
545
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
113
546
|
this.authorization = config.authorization;
|
|
114
547
|
this.retry = // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -116,8 +549,8 @@ var HttpClient = (_class = class {
|
|
|
116
549
|
attempts: 1,
|
|
117
550
|
backoff: () => 0
|
|
118
551
|
} : {
|
|
119
|
-
attempts: _optionalChain([config, 'access',
|
|
120
|
-
backoff: _nullishCoalesce(_optionalChain([config, 'access',
|
|
552
|
+
attempts: _optionalChain([config, 'access', _8 => _8.retry, 'optionalAccess', _9 => _9.retries]) ? config.retry.retries + 1 : 5,
|
|
553
|
+
backoff: _nullishCoalesce(_optionalChain([config, 'access', _10 => _10.retry, 'optionalAccess', _11 => _11.backoff]), () => ( ((retryCount) => Math.exp(retryCount) * 50)))
|
|
121
554
|
};
|
|
122
555
|
}
|
|
123
556
|
async request(request) {
|
|
@@ -157,7 +590,7 @@ var HttpClient = (_class = class {
|
|
|
157
590
|
await reader.cancel();
|
|
158
591
|
}
|
|
159
592
|
}
|
|
160
|
-
|
|
593
|
+
__init4() {this.requestWithBackoff = async (request) => {
|
|
161
594
|
const [url, requestOptions] = this.processRequest(request);
|
|
162
595
|
let response = void 0;
|
|
163
596
|
let error = void 0;
|
|
@@ -179,7 +612,7 @@ var HttpClient = (_class = class {
|
|
|
179
612
|
error
|
|
180
613
|
};
|
|
181
614
|
}}
|
|
182
|
-
|
|
615
|
+
__init5() {this.processRequest = (request) => {
|
|
183
616
|
const headers = new Headers(request.headers);
|
|
184
617
|
if (!headers.has("Authorization")) {
|
|
185
618
|
headers.set("Authorization", this.authorization);
|
|
@@ -224,296 +657,35 @@ var HttpClient = (_class = class {
|
|
|
224
657
|
reset: response.headers.get("Burst-RateLimit-Reset")
|
|
225
658
|
});
|
|
226
659
|
}
|
|
227
|
-
if (response.status < 200 || response.status >= 300) {
|
|
228
|
-
const body = await response.text();
|
|
229
|
-
throw new QstashError(body.length > 0 ? body : `Error: status=${response.status}`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}, _class);
|
|
233
|
-
|
|
234
|
-
// src/client/llm/providers.ts
|
|
235
|
-
var analyticsBaseUrlMap = (analyticsName, analyticsToken, providerApiKey, providerBaseUrl) => {
|
|
236
|
-
return {
|
|
237
|
-
helicone: {
|
|
238
|
-
baseURL: "https://gateway.helicone.ai/v1/chat/completions",
|
|
239
|
-
headers: {
|
|
240
|
-
"Helicone-Auth": `Bearer ${analyticsToken}`,
|
|
241
|
-
"Helicone-Target-Url": providerBaseUrl,
|
|
242
|
-
Authorization: `Bearer ${providerApiKey}`
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}[analyticsName];
|
|
246
|
-
};
|
|
247
|
-
var upstash = () => {
|
|
248
|
-
return {
|
|
249
|
-
owner: "upstash",
|
|
250
|
-
baseUrl: "https://qstash.upstash.io/llm",
|
|
251
|
-
token: ""
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
var openai = ({
|
|
255
|
-
token
|
|
256
|
-
}) => {
|
|
257
|
-
return { token, owner: "openai", baseUrl: "https://api.openai.com" };
|
|
258
|
-
};
|
|
259
|
-
var custom = ({
|
|
260
|
-
baseUrl,
|
|
261
|
-
token
|
|
262
|
-
}) => {
|
|
263
|
-
const trimmedBaseUrl = baseUrl.replace(/\/(v1\/)?chat\/completions$/, "");
|
|
264
|
-
return {
|
|
265
|
-
token,
|
|
266
|
-
owner: "custom",
|
|
267
|
-
baseUrl: trimmedBaseUrl
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// src/client/llm/chat.ts
|
|
272
|
-
var Chat = (_class2 = class _Chat {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
constructor(http, token) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
|
|
276
|
-
this.http = http;
|
|
277
|
-
this.token = token;
|
|
278
|
-
}
|
|
279
|
-
static toChatRequest(request) {
|
|
280
|
-
const messages = [];
|
|
281
|
-
messages.push(
|
|
282
|
-
{ role: "system", content: request.system },
|
|
283
|
-
{ role: "user", content: request.user }
|
|
284
|
-
);
|
|
285
|
-
const chatRequest = { ...request, messages };
|
|
286
|
-
return chatRequest;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Calls the Upstash completions api given a ChatRequest.
|
|
290
|
-
*
|
|
291
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
292
|
-
* if stream is enabled.
|
|
293
|
-
*
|
|
294
|
-
* @param request ChatRequest with messages
|
|
295
|
-
* @returns Chat completion or stream
|
|
296
|
-
*/
|
|
297
|
-
__init3() {this.create = async (request) => {
|
|
298
|
-
if (request.provider.owner != "upstash")
|
|
299
|
-
return this.createThirdParty(request);
|
|
300
|
-
const body = JSON.stringify(request);
|
|
301
|
-
if ("stream" in request && request.stream) {
|
|
302
|
-
return this.http.requestStream({
|
|
303
|
-
path: ["llm", "v1", "chat", "completions"],
|
|
304
|
-
method: "POST",
|
|
305
|
-
headers: {
|
|
306
|
-
"Content-Type": "application/json",
|
|
307
|
-
Connection: "keep-alive",
|
|
308
|
-
Accept: "text/event-stream",
|
|
309
|
-
"Cache-Control": "no-cache",
|
|
310
|
-
Authorization: `Bearer ${this.token}`
|
|
311
|
-
},
|
|
312
|
-
body
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return this.http.request({
|
|
316
|
-
path: ["llm", "v1", "chat", "completions"],
|
|
317
|
-
method: "POST",
|
|
318
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.token}` },
|
|
319
|
-
body
|
|
320
|
-
});
|
|
321
|
-
}}
|
|
322
|
-
/**
|
|
323
|
-
* Calls the Upstash completions api given a ChatRequest.
|
|
324
|
-
*
|
|
325
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
326
|
-
* if stream is enabled.
|
|
327
|
-
*
|
|
328
|
-
* @param request ChatRequest with messages
|
|
329
|
-
* @returns Chat completion or stream
|
|
330
|
-
*/
|
|
331
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
332
|
-
__init4() {this.createThirdParty = async (request) => {
|
|
333
|
-
const { baseUrl, token, owner } = request.provider;
|
|
334
|
-
if (owner === "upstash")
|
|
335
|
-
throw new Error("Upstash is not 3rd party provider!");
|
|
336
|
-
delete request.provider;
|
|
337
|
-
delete request.system;
|
|
338
|
-
const analytics = request.analytics;
|
|
339
|
-
delete request.analytics;
|
|
340
|
-
const body = JSON.stringify(request);
|
|
341
|
-
const isAnalyticsEnabled = _optionalChain([analytics, 'optionalAccess', _12 => _12.name]) && analytics.token;
|
|
342
|
-
const analyticsConfig = (
|
|
343
|
-
// This is exact copy of "isAnalyticsEnabled" but required in order to satify ts
|
|
344
|
-
_optionalChain([analytics, 'optionalAccess', _13 => _13.name]) && analytics.token ? analyticsBaseUrlMap(analytics.name, analytics.token, token, baseUrl) : { headers: void 0, baseURL: baseUrl }
|
|
345
|
-
);
|
|
346
|
-
const isStream = "stream" in request && request.stream;
|
|
347
|
-
const headers = {
|
|
348
|
-
"Content-Type": "application/json",
|
|
349
|
-
Authorization: `Bearer ${token}`,
|
|
350
|
-
...isStream ? {
|
|
351
|
-
Connection: "keep-alive",
|
|
352
|
-
Accept: "text/event-stream",
|
|
353
|
-
"Cache-Control": "no-cache"
|
|
354
|
-
} : {},
|
|
355
|
-
...analyticsConfig.headers
|
|
356
|
-
};
|
|
357
|
-
const response = await this.http[isStream ? "requestStream" : "request"]({
|
|
358
|
-
path: isAnalyticsEnabled ? [] : ["v1", "chat", "completions"],
|
|
359
|
-
method: "POST",
|
|
360
|
-
headers,
|
|
361
|
-
body,
|
|
362
|
-
baseUrl: analyticsConfig.baseURL
|
|
363
|
-
});
|
|
364
|
-
return response;
|
|
365
|
-
}}
|
|
366
|
-
/**
|
|
367
|
-
* Calls the Upstash completions api given a PromptRequest.
|
|
368
|
-
*
|
|
369
|
-
* Returns a ChatCompletion or a stream of ChatCompletionChunks
|
|
370
|
-
* if stream is enabled.
|
|
371
|
-
*
|
|
372
|
-
* @param request PromptRequest with system and user messages.
|
|
373
|
-
* Note that system parameter shouldn't be passed in the case of
|
|
374
|
-
* mistralai/Mistral-7B-Instruct-v0.2 model.
|
|
375
|
-
* @returns Chat completion or stream
|
|
376
|
-
*/
|
|
377
|
-
__init5() {this.prompt = async (request) => {
|
|
378
|
-
const chatRequest = _Chat.toChatRequest(request);
|
|
379
|
-
return this.create(chatRequest);
|
|
380
|
-
}}
|
|
660
|
+
if (response.status < 200 || response.status >= 300) {
|
|
661
|
+
const body = await response.text();
|
|
662
|
+
throw new QstashError(body.length > 0 ? body : `Error: status=${response.status}`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
381
665
|
}, _class2);
|
|
382
666
|
|
|
383
667
|
// src/client/llm/utils.ts
|
|
384
668
|
function appendLLMOptionsIfNeeded(request, headers) {
|
|
385
|
-
if (_optionalChain([request, 'access',
|
|
669
|
+
if (_optionalChain([request, 'access', _12 => _12.api, 'optionalAccess', _13 => _13.provider, 'optionalAccess', _14 => _14.owner]) === "upstash") {
|
|
386
670
|
request.api = { name: "llm" };
|
|
387
671
|
return;
|
|
388
672
|
}
|
|
389
673
|
if (request.api && "provider" in request.api) {
|
|
390
674
|
const provider = request.api.provider;
|
|
391
|
-
if (!_optionalChain([provider, 'optionalAccess',
|
|
675
|
+
if (!_optionalChain([provider, 'optionalAccess', _15 => _15.baseUrl]))
|
|
392
676
|
throw new Error("baseUrl cannot be empty or undefined!");
|
|
393
677
|
if (!provider.token)
|
|
394
678
|
throw new Error("token cannot be empty or undefined!");
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const analyticsName = request.api.analytics.name;
|
|
398
|
-
const { baseURL, headers: defaultHeaders } = analyticsBaseUrlMap(
|
|
399
|
-
analyticsName,
|
|
400
|
-
analyticsToken,
|
|
401
|
-
provider.token,
|
|
402
|
-
provider.baseUrl
|
|
403
|
-
);
|
|
404
|
-
request.url = baseURL;
|
|
405
|
-
headers.set("Helicone-Auth", defaultHeaders["Helicone-Auth"]);
|
|
406
|
-
headers.set("Helicone-Target-Url", defaultHeaders["Helicone-Target-Url"]);
|
|
407
|
-
headers.set("Authorization", defaultHeaders.Authorization);
|
|
408
|
-
} else {
|
|
409
|
-
request.url = `${provider.baseUrl}/v1/chat/completions`;
|
|
410
|
-
headers.set("Authorization", `Bearer ${provider.token}`);
|
|
411
|
-
}
|
|
679
|
+
request.url = `${provider.baseUrl}/v1/chat/completions`;
|
|
680
|
+
headers.set("Authorization", `Bearer ${provider.token}`);
|
|
412
681
|
}
|
|
413
682
|
}
|
|
414
683
|
function ensureCallbackPresent(request) {
|
|
415
|
-
if (_optionalChain([request, 'access',
|
|
684
|
+
if (_optionalChain([request, 'access', _16 => _16.api, 'optionalAccess', _17 => _17.name]) === "llm" && !request.callback) {
|
|
416
685
|
throw new TypeError("Callback cannot be undefined when using LLM");
|
|
417
686
|
}
|
|
418
687
|
}
|
|
419
688
|
|
|
420
|
-
// src/client/messages.ts
|
|
421
|
-
var Messages = class {
|
|
422
|
-
|
|
423
|
-
constructor(http) {
|
|
424
|
-
this.http = http;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Get a message
|
|
428
|
-
*/
|
|
429
|
-
async get(messageId) {
|
|
430
|
-
const messagePayload = await this.http.request({
|
|
431
|
-
method: "GET",
|
|
432
|
-
path: ["v2", "messages", messageId]
|
|
433
|
-
});
|
|
434
|
-
const message = {
|
|
435
|
-
...messagePayload,
|
|
436
|
-
urlGroup: messagePayload.topicName
|
|
437
|
-
};
|
|
438
|
-
return message;
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Cancel a message
|
|
442
|
-
*/
|
|
443
|
-
async delete(messageId) {
|
|
444
|
-
return await this.http.request({
|
|
445
|
-
method: "DELETE",
|
|
446
|
-
path: ["v2", "messages", messageId],
|
|
447
|
-
parseResponseAsJson: false
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
async deleteMany(messageIds) {
|
|
451
|
-
const result = await this.http.request({
|
|
452
|
-
method: "DELETE",
|
|
453
|
-
path: ["v2", "messages"],
|
|
454
|
-
headers: { "Content-Type": "application/json" },
|
|
455
|
-
body: JSON.stringify({ messageIds })
|
|
456
|
-
});
|
|
457
|
-
return result.cancelled;
|
|
458
|
-
}
|
|
459
|
-
async deleteAll() {
|
|
460
|
-
const result = await this.http.request({
|
|
461
|
-
method: "DELETE",
|
|
462
|
-
path: ["v2", "messages"]
|
|
463
|
-
});
|
|
464
|
-
return result.cancelled;
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// src/client/utils.ts
|
|
469
|
-
var isIgnoredHeader = (header) => {
|
|
470
|
-
const lowerCaseHeader = header.toLowerCase();
|
|
471
|
-
return lowerCaseHeader.startsWith("content-type") || lowerCaseHeader.startsWith("upstash-");
|
|
472
|
-
};
|
|
473
|
-
function prefixHeaders(headers) {
|
|
474
|
-
const keysToBePrefixed = [...headers.keys()].filter((key) => !isIgnoredHeader(key));
|
|
475
|
-
for (const key of keysToBePrefixed) {
|
|
476
|
-
const value = headers.get(key);
|
|
477
|
-
if (value !== null) {
|
|
478
|
-
headers.set(`Upstash-Forward-${key}`, value);
|
|
479
|
-
}
|
|
480
|
-
headers.delete(key);
|
|
481
|
-
}
|
|
482
|
-
return headers;
|
|
483
|
-
}
|
|
484
|
-
function processHeaders(request) {
|
|
485
|
-
const headers = prefixHeaders(new Headers(request.headers));
|
|
486
|
-
headers.set("Upstash-Method", _nullishCoalesce(request.method, () => ( "POST")));
|
|
487
|
-
if (request.delay !== void 0) {
|
|
488
|
-
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
|
|
489
|
-
}
|
|
490
|
-
if (request.notBefore !== void 0) {
|
|
491
|
-
headers.set("Upstash-Not-Before", request.notBefore.toFixed(0));
|
|
492
|
-
}
|
|
493
|
-
if (request.deduplicationId !== void 0) {
|
|
494
|
-
headers.set("Upstash-Deduplication-Id", request.deduplicationId);
|
|
495
|
-
}
|
|
496
|
-
if (request.contentBasedDeduplication !== void 0) {
|
|
497
|
-
headers.set("Upstash-Content-Based-Deduplication", "true");
|
|
498
|
-
}
|
|
499
|
-
if (request.retries !== void 0) {
|
|
500
|
-
headers.set("Upstash-Retries", request.retries.toFixed(0));
|
|
501
|
-
}
|
|
502
|
-
if (request.callback !== void 0) {
|
|
503
|
-
headers.set("Upstash-Callback", request.callback);
|
|
504
|
-
}
|
|
505
|
-
if (request.failureCallback !== void 0) {
|
|
506
|
-
headers.set("Upstash-Failure-Callback", request.failureCallback);
|
|
507
|
-
}
|
|
508
|
-
if (request.timeout !== void 0) {
|
|
509
|
-
headers.set("Upstash-Timeout", `${request.timeout}s`);
|
|
510
|
-
}
|
|
511
|
-
return headers;
|
|
512
|
-
}
|
|
513
|
-
function getRequestPath(request) {
|
|
514
|
-
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(request.url, () => ( request.urlGroup)), () => ( request.topic)), () => ( `api/${_optionalChain([request, 'access', _20 => _20.api, 'optionalAccess', _21 => _21.name])}`));
|
|
515
|
-
}
|
|
516
|
-
|
|
517
689
|
// src/client/queue.ts
|
|
518
690
|
var Queue = class {
|
|
519
691
|
|
|
@@ -641,159 +813,6 @@ var Queue = class {
|
|
|
641
813
|
}
|
|
642
814
|
};
|
|
643
815
|
|
|
644
|
-
// src/client/schedules.ts
|
|
645
|
-
var Schedules = class {
|
|
646
|
-
|
|
647
|
-
constructor(http) {
|
|
648
|
-
this.http = http;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* Create a schedule
|
|
652
|
-
*/
|
|
653
|
-
async create(request) {
|
|
654
|
-
const headers = prefixHeaders(new Headers(request.headers));
|
|
655
|
-
if (!headers.has("Content-Type")) {
|
|
656
|
-
headers.set("Content-Type", "application/json");
|
|
657
|
-
}
|
|
658
|
-
headers.set("Upstash-Cron", request.cron);
|
|
659
|
-
if (request.method !== void 0) {
|
|
660
|
-
headers.set("Upstash-Method", request.method);
|
|
661
|
-
}
|
|
662
|
-
if (request.delay !== void 0) {
|
|
663
|
-
headers.set("Upstash-Delay", `${request.delay.toFixed(0)}s`);
|
|
664
|
-
}
|
|
665
|
-
if (request.retries !== void 0) {
|
|
666
|
-
headers.set("Upstash-Retries", request.retries.toFixed(0));
|
|
667
|
-
}
|
|
668
|
-
if (request.callback !== void 0) {
|
|
669
|
-
headers.set("Upstash-Callback", request.callback);
|
|
670
|
-
}
|
|
671
|
-
if (request.failureCallback !== void 0) {
|
|
672
|
-
headers.set("Upstash-Failure-Callback", request.failureCallback);
|
|
673
|
-
}
|
|
674
|
-
if (request.timeout !== void 0) {
|
|
675
|
-
headers.set("Upstash-Timeout", `${request.timeout}s`);
|
|
676
|
-
}
|
|
677
|
-
return await this.http.request({
|
|
678
|
-
method: "POST",
|
|
679
|
-
headers,
|
|
680
|
-
path: ["v2", "schedules", request.destination],
|
|
681
|
-
body: request.body
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* Get a schedule
|
|
686
|
-
*/
|
|
687
|
-
async get(scheduleId) {
|
|
688
|
-
return await this.http.request({
|
|
689
|
-
method: "GET",
|
|
690
|
-
path: ["v2", "schedules", scheduleId]
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* List your schedules
|
|
695
|
-
*/
|
|
696
|
-
async list() {
|
|
697
|
-
return await this.http.request({
|
|
698
|
-
method: "GET",
|
|
699
|
-
path: ["v2", "schedules"]
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Delete a schedule
|
|
704
|
-
*/
|
|
705
|
-
async delete(scheduleId) {
|
|
706
|
-
return await this.http.request({
|
|
707
|
-
method: "DELETE",
|
|
708
|
-
path: ["v2", "schedules", scheduleId],
|
|
709
|
-
parseResponseAsJson: false
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Pauses the schedule.
|
|
714
|
-
*
|
|
715
|
-
* A paused schedule will not deliver messages until
|
|
716
|
-
* it is resumed.
|
|
717
|
-
*/
|
|
718
|
-
async pause({ schedule }) {
|
|
719
|
-
await this.http.request({
|
|
720
|
-
method: "PATCH",
|
|
721
|
-
path: ["v2", "schedules", schedule, "pause"],
|
|
722
|
-
parseResponseAsJson: false
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Resumes the schedule.
|
|
727
|
-
*/
|
|
728
|
-
async resume({ schedule }) {
|
|
729
|
-
await this.http.request({
|
|
730
|
-
method: "PATCH",
|
|
731
|
-
path: ["v2", "schedules", schedule, "resume"],
|
|
732
|
-
parseResponseAsJson: false
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
// src/client/url-groups.ts
|
|
738
|
-
var UrlGroups = class {
|
|
739
|
-
|
|
740
|
-
constructor(http) {
|
|
741
|
-
this.http = http;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Create a new url group with the given name and endpoints
|
|
745
|
-
*/
|
|
746
|
-
async addEndpoints(request) {
|
|
747
|
-
await this.http.request({
|
|
748
|
-
method: "POST",
|
|
749
|
-
path: ["v2", "topics", request.name, "endpoints"],
|
|
750
|
-
headers: { "Content-Type": "application/json" },
|
|
751
|
-
body: JSON.stringify({ endpoints: request.endpoints }),
|
|
752
|
-
parseResponseAsJson: false
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* Remove endpoints from a url group.
|
|
757
|
-
*/
|
|
758
|
-
async removeEndpoints(request) {
|
|
759
|
-
await this.http.request({
|
|
760
|
-
method: "DELETE",
|
|
761
|
-
path: ["v2", "topics", request.name, "endpoints"],
|
|
762
|
-
headers: { "Content-Type": "application/json" },
|
|
763
|
-
body: JSON.stringify({ endpoints: request.endpoints }),
|
|
764
|
-
parseResponseAsJson: false
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Get a list of all url groups.
|
|
769
|
-
*/
|
|
770
|
-
async list() {
|
|
771
|
-
return await this.http.request({
|
|
772
|
-
method: "GET",
|
|
773
|
-
path: ["v2", "topics"]
|
|
774
|
-
});
|
|
775
|
-
}
|
|
776
|
-
/**
|
|
777
|
-
* Get a single url group
|
|
778
|
-
*/
|
|
779
|
-
async get(name) {
|
|
780
|
-
return await this.http.request({
|
|
781
|
-
method: "GET",
|
|
782
|
-
path: ["v2", "topics", name]
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* Delete a url group
|
|
787
|
-
*/
|
|
788
|
-
async delete(name) {
|
|
789
|
-
return await this.http.request({
|
|
790
|
-
method: "DELETE",
|
|
791
|
-
path: ["v2", "topics", name],
|
|
792
|
-
parseResponseAsJson: false
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
};
|
|
796
|
-
|
|
797
816
|
// src/client/client.ts
|
|
798
817
|
var Client = class {
|
|
799
818
|
|
|
@@ -854,7 +873,7 @@ var Client = class {
|
|
|
854
873
|
* Create, read, update or delete queues.
|
|
855
874
|
*/
|
|
856
875
|
queue(request) {
|
|
857
|
-
return new Queue(this.http, _optionalChain([request, 'optionalAccess',
|
|
876
|
+
return new Queue(this.http, _optionalChain([request, 'optionalAccess', _18 => _18.queueName]));
|
|
858
877
|
}
|
|
859
878
|
/**
|
|
860
879
|
* Access the Chat API
|
|
@@ -913,7 +932,8 @@ var Client = class {
|
|
|
913
932
|
},
|
|
914
933
|
method: "POST"
|
|
915
934
|
});
|
|
916
|
-
|
|
935
|
+
const arrayResposne = Array.isArray(response) ? response : [response];
|
|
936
|
+
return arrayResposne;
|
|
917
937
|
}
|
|
918
938
|
/**
|
|
919
939
|
* Batch publish messages to QStash, serializing each body to JSON.
|
|
@@ -952,10 +972,10 @@ var Client = class {
|
|
|
952
972
|
*/
|
|
953
973
|
async events(request) {
|
|
954
974
|
const query = {};
|
|
955
|
-
if (_optionalChain([request, 'optionalAccess',
|
|
975
|
+
if (_optionalChain([request, 'optionalAccess', _19 => _19.cursor]) && request.cursor > 0) {
|
|
956
976
|
query.cursor = request.cursor.toString();
|
|
957
977
|
}
|
|
958
|
-
for (const [key, value] of Object.entries(_nullishCoalesce(_optionalChain([request, 'optionalAccess',
|
|
978
|
+
for (const [key, value] of Object.entries(_nullishCoalesce(_optionalChain([request, 'optionalAccess', _20 => _20.filter]), () => ( {})))) {
|
|
959
979
|
if (typeof value === "number" && value < 0) {
|
|
960
980
|
continue;
|
|
961
981
|
}
|
|
@@ -996,4 +1016,4 @@ var Client = class {
|
|
|
996
1016
|
|
|
997
1017
|
|
|
998
1018
|
|
|
999
|
-
exports.
|
|
1019
|
+
exports.SignatureError = SignatureError; exports.Receiver = Receiver; exports.QstashError = QstashError; exports.QstashRatelimitError = QstashRatelimitError; exports.QstashChatRatelimitError = QstashChatRatelimitError; exports.QstashDailyRatelimitError = QstashDailyRatelimitError; exports.QstashWorkflowError = QstashWorkflowError; exports.QstashWorkflowAbort = QstashWorkflowAbort; exports.Chat = Chat; exports.Messages = Messages; exports.Schedules = Schedules; exports.UrlGroups = UrlGroups; exports.Client = Client;
|