@upstash/qstash 2.7.11-canary-3 → 2.7.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -223,7 +223,7 @@ var QStashWorkflowAbort = class extends Error {
223
223
  stepName;
224
224
  constructor(stepName, stepInfo) {
225
225
  super(
226
- `This is an QStash Workflow error thrown after a step executes. It is expected to be raised. Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch. Aborting workflow after executing step '${stepName}'.`
226
+ `This is an Upstash Workflow error thrown after a step executes. It is expected to be raised. Make sure that you await for each step. Also, if you are using try/catch blocks, you should not wrap context.run/sleep/sleepUntil/call methods with try/catch. Aborting workflow after executing step '${stepName}'.`
227
227
  );
228
228
  this.name = "QStashWorkflowAbort";
229
229
  this.stepName = stepName;
@@ -406,13 +406,20 @@ var upstash = () => {
406
406
  return {
407
407
  owner: "upstash",
408
408
  baseUrl: "https://qstash.upstash.io/llm",
409
- token: ""
409
+ token: "",
410
+ organization: void 0
410
411
  };
411
412
  };
412
413
  var openai = ({
413
- token
414
+ token,
415
+ organization
414
416
  }) => {
415
- return { token, owner: "openai", baseUrl: "https://api.openai.com" };
417
+ return {
418
+ token,
419
+ owner: "openai",
420
+ baseUrl: "https://api.openai.com",
421
+ organization
422
+ };
416
423
  };
417
424
  var custom = ({
418
425
  baseUrl,
@@ -422,7 +429,8 @@ var custom = ({
422
429
  return {
423
430
  token,
424
431
  owner: "custom",
425
- baseUrl: trimmedBaseUrl
432
+ baseUrl: trimmedBaseUrl,
433
+ organization: void 0
426
434
  };
427
435
  };
428
436
 
@@ -502,7 +510,7 @@ var Chat = class _Chat {
502
510
  */
503
511
  // eslint-disable-next-line @typescript-eslint/require-await
504
512
  createThirdParty = async (request) => {
505
- const { baseUrl, token, owner } = request.provider;
513
+ const { baseUrl, token, owner, organization } = request.provider;
506
514
  if (owner === "upstash")
507
515
  throw new Error("Upstash is not 3rd party provider!");
508
516
  delete request.provider;
@@ -516,6 +524,9 @@ var Chat = class _Chat {
516
524
  const headers = {
517
525
  "Content-Type": "application/json",
518
526
  Authorization: `Bearer ${token}`,
527
+ ...organization ? {
528
+ "OpenAI-Organization": organization
529
+ } : {},
519
530
  ...isStream ? {
520
531
  Connection: "keep-alive",
521
532
  Accept: "text/event-stream",
@@ -726,7 +737,7 @@ function decodeBase64(base64) {
726
737
  return new TextDecoder().decode(intArray);
727
738
  } catch (error) {
728
739
  console.warn(
729
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. Error: ${error}`
740
+ `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
730
741
  );
731
742
  return atob(base64);
732
743
  }
@@ -1023,377 +1034,14 @@ var UrlGroups = class {
1023
1034
  }
1024
1035
  };
1025
1036
 
1026
- // node_modules/neverthrow/dist/index.es.js
1027
- var defaultErrorConfig = {
1028
- withStackTrace: false
1029
- };
1030
- var createNeverThrowError = (message, result, config = defaultErrorConfig) => {
1031
- const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
1032
- const maybeStack = config.withStackTrace ? new Error().stack : void 0;
1033
- return {
1034
- data,
1035
- message,
1036
- stack: maybeStack
1037
- };
1038
- };
1039
- function __awaiter(thisArg, _arguments, P, generator) {
1040
- function adopt(value) {
1041
- return value instanceof P ? value : new P(function(resolve) {
1042
- resolve(value);
1043
- });
1044
- }
1045
- return new (P || (P = Promise))(function(resolve, reject) {
1046
- function fulfilled(value) {
1047
- try {
1048
- step(generator.next(value));
1049
- } catch (e) {
1050
- reject(e);
1051
- }
1052
- }
1053
- function rejected(value) {
1054
- try {
1055
- step(generator["throw"](value));
1056
- } catch (e) {
1057
- reject(e);
1058
- }
1059
- }
1060
- function step(result) {
1061
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1062
- }
1063
- step((generator = generator.apply(thisArg, [])).next());
1064
- });
1065
- }
1066
- function __values(o) {
1067
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1068
- if (m)
1069
- return m.call(o);
1070
- if (o && typeof o.length === "number")
1071
- return {
1072
- next: function() {
1073
- if (o && i >= o.length)
1074
- o = void 0;
1075
- return { value: o && o[i++], done: !o };
1076
- }
1077
- };
1078
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1079
- }
1080
- function __await(v) {
1081
- return this instanceof __await ? (this.v = v, this) : new __await(v);
1082
- }
1083
- function __asyncGenerator(thisArg, _arguments, generator) {
1084
- if (!Symbol.asyncIterator)
1085
- throw new TypeError("Symbol.asyncIterator is not defined.");
1086
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
1087
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1088
- return this;
1089
- }, i;
1090
- function verb(n) {
1091
- if (g[n])
1092
- i[n] = function(v) {
1093
- return new Promise(function(a, b) {
1094
- q.push([n, v, a, b]) > 1 || resume(n, v);
1095
- });
1096
- };
1097
- }
1098
- function resume(n, v) {
1099
- try {
1100
- step(g[n](v));
1101
- } catch (e) {
1102
- settle(q[0][3], e);
1103
- }
1104
- }
1105
- function step(r) {
1106
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
1107
- }
1108
- function fulfill(value) {
1109
- resume("next", value);
1110
- }
1111
- function reject(value) {
1112
- resume("throw", value);
1113
- }
1114
- function settle(f, v) {
1115
- if (f(v), q.shift(), q.length)
1116
- resume(q[0][0], q[0][1]);
1117
- }
1118
- }
1119
- function __asyncDelegator(o) {
1120
- var i, p;
1121
- return i = {}, verb("next"), verb("throw", function(e) {
1122
- throw e;
1123
- }), verb("return"), i[Symbol.iterator] = function() {
1124
- return this;
1125
- }, i;
1126
- function verb(n, f) {
1127
- i[n] = o[n] ? function(v) {
1128
- return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
1129
- } : f;
1130
- }
1131
- }
1132
- function __asyncValues(o) {
1133
- if (!Symbol.asyncIterator)
1134
- throw new TypeError("Symbol.asyncIterator is not defined.");
1135
- var m = o[Symbol.asyncIterator], i;
1136
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1137
- return this;
1138
- }, i);
1139
- function verb(n) {
1140
- i[n] = o[n] && function(v) {
1141
- return new Promise(function(resolve, reject) {
1142
- v = o[n](v), settle(resolve, reject, v.done, v.value);
1143
- });
1144
- };
1145
- }
1146
- function settle(resolve, reject, d, v) {
1147
- Promise.resolve(v).then(function(v2) {
1148
- resolve({ value: v2, done: d });
1149
- }, reject);
1150
- }
1151
- }
1152
- var ResultAsync = class _ResultAsync {
1153
- constructor(res) {
1154
- this._promise = res;
1155
- }
1156
- static fromSafePromise(promise) {
1157
- const newPromise = promise.then((value) => new Ok(value));
1158
- return new _ResultAsync(newPromise);
1159
- }
1160
- static fromPromise(promise, errorFn) {
1161
- const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e)));
1162
- return new _ResultAsync(newPromise);
1163
- }
1164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1165
- static fromThrowable(fn, errorFn) {
1166
- return (...args) => {
1167
- return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () {
1168
- try {
1169
- return new Ok(yield fn(...args));
1170
- } catch (error) {
1171
- return new Err(errorFn ? errorFn(error) : error);
1172
- }
1173
- }))());
1174
- };
1175
- }
1176
- static combine(asyncResultList) {
1177
- return combineResultAsyncList(asyncResultList);
1178
- }
1179
- static combineWithAllErrors(asyncResultList) {
1180
- return combineResultAsyncListWithAllErrors(asyncResultList);
1181
- }
1182
- map(f) {
1183
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1184
- if (res.isErr()) {
1185
- return new Err(res.error);
1186
- }
1187
- return new Ok(yield f(res.value));
1188
- })));
1189
- }
1190
- mapErr(f) {
1191
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1192
- if (res.isOk()) {
1193
- return new Ok(res.value);
1194
- }
1195
- return new Err(yield f(res.error));
1196
- })));
1197
- }
1198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1199
- andThen(f) {
1200
- return new _ResultAsync(this._promise.then((res) => {
1201
- if (res.isErr()) {
1202
- return new Err(res.error);
1203
- }
1204
- const newValue = f(res.value);
1205
- return newValue instanceof _ResultAsync ? newValue._promise : newValue;
1206
- }));
1207
- }
1208
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1209
- orElse(f) {
1210
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1211
- if (res.isErr()) {
1212
- return f(res.error);
1213
- }
1214
- return new Ok(res.value);
1215
- })));
1216
- }
1217
- match(ok2, _err) {
1218
- return this._promise.then((res) => res.match(ok2, _err));
1219
- }
1220
- unwrapOr(t) {
1221
- return this._promise.then((res) => res.unwrapOr(t));
1222
- }
1223
- /**
1224
- * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
1225
- */
1226
- safeUnwrap() {
1227
- return __asyncGenerator(this, arguments, function* safeUnwrap_1() {
1228
- return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap()))))));
1229
- });
1230
- }
1231
- // Makes ResultAsync implement PromiseLike<Result>
1232
- then(successCallback, failureCallback) {
1233
- return this._promise.then(successCallback, failureCallback);
1234
- }
1235
- };
1236
- var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2)));
1237
- var fromPromise = ResultAsync.fromPromise;
1238
- var fromSafePromise = ResultAsync.fromSafePromise;
1239
- var fromAsyncThrowable = ResultAsync.fromThrowable;
1240
- var combineResultList = (resultList) => {
1241
- let acc = ok([]);
1242
- for (const result of resultList) {
1243
- if (result.isErr()) {
1244
- acc = err(result.error);
1245
- break;
1246
- } else {
1247
- acc.map((list) => list.push(result.value));
1248
- }
1249
- }
1250
- return acc;
1251
- };
1252
- var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList);
1253
- var combineResultListWithAllErrors = (resultList) => {
1254
- let acc = ok([]);
1255
- for (const result of resultList) {
1256
- if (result.isErr() && acc.isErr()) {
1257
- acc.error.push(result.error);
1258
- } else if (result.isErr() && acc.isOk()) {
1259
- acc = err([result.error]);
1260
- } else if (result.isOk() && acc.isOk()) {
1261
- acc.value.push(result.value);
1262
- }
1263
- }
1264
- return acc;
1265
- };
1266
- var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors);
1267
- var Result;
1268
- (function(Result2) {
1269
- function fromThrowable2(fn, errorFn) {
1270
- return (...args) => {
1271
- try {
1272
- const result = fn(...args);
1273
- return ok(result);
1274
- } catch (e) {
1275
- return err(errorFn ? errorFn(e) : e);
1276
- }
1277
- };
1278
- }
1279
- Result2.fromThrowable = fromThrowable2;
1280
- function combine(resultList) {
1281
- return combineResultList(resultList);
1282
- }
1283
- Result2.combine = combine;
1284
- function combineWithAllErrors(resultList) {
1285
- return combineResultListWithAllErrors(resultList);
1286
- }
1287
- Result2.combineWithAllErrors = combineWithAllErrors;
1288
- })(Result || (Result = {}));
1289
- var ok = (value) => new Ok(value);
1290
- var err = (err2) => new Err(err2);
1291
- var Ok = class {
1292
- constructor(value) {
1293
- this.value = value;
1294
- }
1295
- isOk() {
1296
- return true;
1297
- }
1298
- isErr() {
1299
- return !this.isOk();
1300
- }
1301
- map(f) {
1302
- return ok(f(this.value));
1303
- }
1304
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1305
- mapErr(_f) {
1306
- return ok(this.value);
1307
- }
1308
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1309
- andThen(f) {
1310
- return f(this.value);
1311
- }
1312
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1313
- orElse(_f) {
1314
- return ok(this.value);
1315
- }
1316
- asyncAndThen(f) {
1317
- return f(this.value);
1318
- }
1319
- asyncMap(f) {
1320
- return ResultAsync.fromSafePromise(f(this.value));
1321
- }
1322
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1323
- unwrapOr(_v) {
1324
- return this.value;
1325
- }
1326
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1327
- match(ok2, _err) {
1328
- return ok2(this.value);
1329
- }
1330
- safeUnwrap() {
1331
- const value = this.value;
1332
- return function* () {
1333
- return value;
1334
- }();
1335
- }
1336
- _unsafeUnwrap(_) {
1337
- return this.value;
1338
- }
1339
- _unsafeUnwrapErr(config) {
1340
- throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config);
1341
- }
1342
- };
1343
- var Err = class {
1344
- constructor(error) {
1345
- this.error = error;
1346
- }
1347
- isOk() {
1348
- return false;
1349
- }
1350
- isErr() {
1351
- return !this.isOk();
1352
- }
1353
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1354
- map(_f) {
1355
- return err(this.error);
1356
- }
1357
- mapErr(f) {
1358
- return err(f(this.error));
1359
- }
1360
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1361
- andThen(_f) {
1362
- return err(this.error);
1363
- }
1364
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1365
- orElse(f) {
1366
- return f(this.error);
1367
- }
1368
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1369
- asyncAndThen(_f) {
1370
- return errAsync(this.error);
1371
- }
1372
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1373
- asyncMap(_f) {
1374
- return errAsync(this.error);
1375
- }
1376
- unwrapOr(v) {
1377
- return v;
1378
- }
1379
- match(_ok, err2) {
1380
- return err2(this.error);
1381
- }
1382
- safeUnwrap() {
1383
- const error = this.error;
1384
- return function* () {
1385
- yield err(error);
1386
- throw new Error("Do not use this generator out of `safeTry`");
1387
- }();
1388
- }
1389
- _unsafeUnwrap(config) {
1390
- throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config);
1391
- }
1392
- _unsafeUnwrapErr(_) {
1393
- return this.error;
1394
- }
1395
- };
1396
- var fromThrowable = Result.fromThrowable;
1037
+ // src/client/workflow/context.ts
1038
+ var import_neverthrow2 = require("neverthrow");
1039
+
1040
+ // src/client/workflow/workflow-requests.ts
1041
+ var import_neverthrow = require("neverthrow");
1042
+
1043
+ // src/client/workflow/workflow-parser.ts
1044
+ var import_neverthrow3 = require("neverthrow");
1397
1045
 
1398
1046
  // src/client/workflow/index.ts
1399
1047
  var Workflow = class {
package/index.mjs CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  openai,
20
20
  setupAnalytics,
21
21
  upstash
22
- } from "./chunk-KGI26PDH.mjs";
22
+ } from "./chunk-Q6E5NF42.mjs";
23
23
  export {
24
24
  Chat,
25
25
  Client,
package/nextjs.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler } from 'next';
2
2
  import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
3
- import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DkrYCqaq.mjs';
3
+ import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DEZq0-qk.mjs';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {
@@ -24,7 +24,7 @@ declare function verifySignatureEdge(handler: (request: NextRequest, nfe?: NextF
24
24
  type VerifySignatureAppRouterResponse = NextResponse | Promise<NextResponse> | Response | Promise<Response>;
25
25
  declare function verifySignatureAppRouter(handler: ((request: Request, params?: unknown) => VerifySignatureAppRouterResponse) | ((request: NextRequest, params?: unknown) => VerifySignatureAppRouterResponse), config?: VerifySignatureConfig): (request: NextRequest | Request, params?: unknown) => Promise<Response>;
26
26
  /**
27
- * Serve method to serve a QStash workflow in a Nextjs project
27
+ * Serve method to serve a Upstash Workflow in a Nextjs project
28
28
  *
29
29
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
30
30
  *
package/nextjs.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NextApiHandler } from 'next';
2
2
  import { NextRequest, NextFetchEvent, NextResponse } from 'next/server';
3
- import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DkrYCqaq.js';
3
+ import { a2 as RouteFunction, a3 as WorkflowServeOptions } from './client-DEZq0-qk.js';
4
4
  import 'neverthrow';
5
5
 
6
6
  type VerifySignatureConfig = {
@@ -24,7 +24,7 @@ declare function verifySignatureEdge(handler: (request: NextRequest, nfe?: NextF
24
24
  type VerifySignatureAppRouterResponse = NextResponse | Promise<NextResponse> | Response | Promise<Response>;
25
25
  declare function verifySignatureAppRouter(handler: ((request: Request, params?: unknown) => VerifySignatureAppRouterResponse) | ((request: NextRequest, params?: unknown) => VerifySignatureAppRouterResponse), config?: VerifySignatureConfig): (request: NextRequest | Request, params?: unknown) => Promise<Response>;
26
26
  /**
27
- * Serve method to serve a QStash workflow in a Nextjs project
27
+ * Serve method to serve a Upstash Workflow in a Nextjs project
28
28
  *
29
29
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
30
30
  *