@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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Receiver,
3
3
  serve
4
- } from "./chunk-KGI26PDH.mjs";
4
+ } from "./chunk-Q6E5NF42.mjs";
5
5
 
6
6
  // node_modules/defu/dist/defu.mjs
7
7
  function isPlainObject(value) {
@@ -169,7 +169,7 @@ var QStashWorkflowAbort = class extends Error {
169
169
  stepName;
170
170
  constructor(stepName, stepInfo) {
171
171
  super(
172
- `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}'.`
172
+ `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}'.`
173
173
  );
174
174
  this.name = "QStashWorkflowAbort";
175
175
  this.stepName = stepName;
@@ -352,13 +352,20 @@ var upstash = () => {
352
352
  return {
353
353
  owner: "upstash",
354
354
  baseUrl: "https://qstash.upstash.io/llm",
355
- token: ""
355
+ token: "",
356
+ organization: void 0
356
357
  };
357
358
  };
358
359
  var openai = ({
359
- token
360
+ token,
361
+ organization
360
362
  }) => {
361
- return { token, owner: "openai", baseUrl: "https://api.openai.com" };
363
+ return {
364
+ token,
365
+ owner: "openai",
366
+ baseUrl: "https://api.openai.com",
367
+ organization
368
+ };
362
369
  };
363
370
  var custom = ({
364
371
  baseUrl,
@@ -368,7 +375,8 @@ var custom = ({
368
375
  return {
369
376
  token,
370
377
  owner: "custom",
371
- baseUrl: trimmedBaseUrl
378
+ baseUrl: trimmedBaseUrl,
379
+ organization: void 0
372
380
  };
373
381
  };
374
382
 
@@ -448,7 +456,7 @@ var Chat = class _Chat {
448
456
  */
449
457
  // eslint-disable-next-line @typescript-eslint/require-await
450
458
  createThirdParty = async (request) => {
451
- const { baseUrl, token, owner } = request.provider;
459
+ const { baseUrl, token, owner, organization } = request.provider;
452
460
  if (owner === "upstash")
453
461
  throw new Error("Upstash is not 3rd party provider!");
454
462
  delete request.provider;
@@ -462,6 +470,9 @@ var Chat = class _Chat {
462
470
  const headers = {
463
471
  "Content-Type": "application/json",
464
472
  Authorization: `Bearer ${token}`,
473
+ ...organization ? {
474
+ "OpenAI-Organization": organization
475
+ } : {},
465
476
  ...isStream ? {
466
477
  Connection: "keep-alive",
467
478
  Accept: "text/event-stream",
@@ -677,7 +688,7 @@ function decodeBase64(base64) {
677
688
  return new TextDecoder().decode(intArray);
678
689
  } catch (error) {
679
690
  console.warn(
680
- `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. Error: ${error}`
691
+ `Upstash Qstash: Failed while decoding base64 "${base64}". Decoding with atob and returning it instead. ${error}`
681
692
  );
682
693
  return atob(base64);
683
694
  }
@@ -1184,377 +1195,11 @@ var DEFAULT_CONTENT_TYPE = "application/json";
1184
1195
  var NO_CONCURRENCY = 1;
1185
1196
  var DEFAULT_RETRIES = 3;
1186
1197
 
1187
- // node_modules/neverthrow/dist/index.es.js
1188
- var defaultErrorConfig = {
1189
- withStackTrace: false
1190
- };
1191
- var createNeverThrowError = (message, result, config = defaultErrorConfig) => {
1192
- const data = result.isOk() ? { type: "Ok", value: result.value } : { type: "Err", value: result.error };
1193
- const maybeStack = config.withStackTrace ? new Error().stack : void 0;
1194
- return {
1195
- data,
1196
- message,
1197
- stack: maybeStack
1198
- };
1199
- };
1200
- function __awaiter(thisArg, _arguments, P, generator) {
1201
- function adopt(value) {
1202
- return value instanceof P ? value : new P(function(resolve) {
1203
- resolve(value);
1204
- });
1205
- }
1206
- return new (P || (P = Promise))(function(resolve, reject) {
1207
- function fulfilled(value) {
1208
- try {
1209
- step(generator.next(value));
1210
- } catch (e) {
1211
- reject(e);
1212
- }
1213
- }
1214
- function rejected(value) {
1215
- try {
1216
- step(generator["throw"](value));
1217
- } catch (e) {
1218
- reject(e);
1219
- }
1220
- }
1221
- function step(result) {
1222
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1223
- }
1224
- step((generator = generator.apply(thisArg, [])).next());
1225
- });
1226
- }
1227
- function __values(o) {
1228
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1229
- if (m)
1230
- return m.call(o);
1231
- if (o && typeof o.length === "number")
1232
- return {
1233
- next: function() {
1234
- if (o && i >= o.length)
1235
- o = void 0;
1236
- return { value: o && o[i++], done: !o };
1237
- }
1238
- };
1239
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1240
- }
1241
- function __await(v) {
1242
- return this instanceof __await ? (this.v = v, this) : new __await(v);
1243
- }
1244
- function __asyncGenerator(thisArg, _arguments, generator) {
1245
- if (!Symbol.asyncIterator)
1246
- throw new TypeError("Symbol.asyncIterator is not defined.");
1247
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
1248
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1249
- return this;
1250
- }, i;
1251
- function verb(n) {
1252
- if (g[n])
1253
- i[n] = function(v) {
1254
- return new Promise(function(a, b) {
1255
- q.push([n, v, a, b]) > 1 || resume(n, v);
1256
- });
1257
- };
1258
- }
1259
- function resume(n, v) {
1260
- try {
1261
- step(g[n](v));
1262
- } catch (e) {
1263
- settle(q[0][3], e);
1264
- }
1265
- }
1266
- function step(r) {
1267
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
1268
- }
1269
- function fulfill(value) {
1270
- resume("next", value);
1271
- }
1272
- function reject(value) {
1273
- resume("throw", value);
1274
- }
1275
- function settle(f, v) {
1276
- if (f(v), q.shift(), q.length)
1277
- resume(q[0][0], q[0][1]);
1278
- }
1279
- }
1280
- function __asyncDelegator(o) {
1281
- var i, p;
1282
- return i = {}, verb("next"), verb("throw", function(e) {
1283
- throw e;
1284
- }), verb("return"), i[Symbol.iterator] = function() {
1285
- return this;
1286
- }, i;
1287
- function verb(n, f) {
1288
- i[n] = o[n] ? function(v) {
1289
- return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
1290
- } : f;
1291
- }
1292
- }
1293
- function __asyncValues(o) {
1294
- if (!Symbol.asyncIterator)
1295
- throw new TypeError("Symbol.asyncIterator is not defined.");
1296
- var m = o[Symbol.asyncIterator], i;
1297
- 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() {
1298
- return this;
1299
- }, i);
1300
- function verb(n) {
1301
- i[n] = o[n] && function(v) {
1302
- return new Promise(function(resolve, reject) {
1303
- v = o[n](v), settle(resolve, reject, v.done, v.value);
1304
- });
1305
- };
1306
- }
1307
- function settle(resolve, reject, d, v) {
1308
- Promise.resolve(v).then(function(v2) {
1309
- resolve({ value: v2, done: d });
1310
- }, reject);
1311
- }
1312
- }
1313
- var ResultAsync = class _ResultAsync {
1314
- constructor(res) {
1315
- this._promise = res;
1316
- }
1317
- static fromSafePromise(promise) {
1318
- const newPromise = promise.then((value) => new Ok(value));
1319
- return new _ResultAsync(newPromise);
1320
- }
1321
- static fromPromise(promise, errorFn) {
1322
- const newPromise = promise.then((value) => new Ok(value)).catch((e) => new Err(errorFn(e)));
1323
- return new _ResultAsync(newPromise);
1324
- }
1325
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1326
- static fromThrowable(fn, errorFn) {
1327
- return (...args) => {
1328
- return new _ResultAsync((() => __awaiter(this, void 0, void 0, function* () {
1329
- try {
1330
- return new Ok(yield fn(...args));
1331
- } catch (error) {
1332
- return new Err(errorFn ? errorFn(error) : error);
1333
- }
1334
- }))());
1335
- };
1336
- }
1337
- static combine(asyncResultList) {
1338
- return combineResultAsyncList(asyncResultList);
1339
- }
1340
- static combineWithAllErrors(asyncResultList) {
1341
- return combineResultAsyncListWithAllErrors(asyncResultList);
1342
- }
1343
- map(f) {
1344
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1345
- if (res.isErr()) {
1346
- return new Err(res.error);
1347
- }
1348
- return new Ok(yield f(res.value));
1349
- })));
1350
- }
1351
- mapErr(f) {
1352
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1353
- if (res.isOk()) {
1354
- return new Ok(res.value);
1355
- }
1356
- return new Err(yield f(res.error));
1357
- })));
1358
- }
1359
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1360
- andThen(f) {
1361
- return new _ResultAsync(this._promise.then((res) => {
1362
- if (res.isErr()) {
1363
- return new Err(res.error);
1364
- }
1365
- const newValue = f(res.value);
1366
- return newValue instanceof _ResultAsync ? newValue._promise : newValue;
1367
- }));
1368
- }
1369
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1370
- orElse(f) {
1371
- return new _ResultAsync(this._promise.then((res) => __awaiter(this, void 0, void 0, function* () {
1372
- if (res.isErr()) {
1373
- return f(res.error);
1374
- }
1375
- return new Ok(res.value);
1376
- })));
1377
- }
1378
- match(ok2, _err) {
1379
- return this._promise.then((res) => res.match(ok2, _err));
1380
- }
1381
- unwrapOr(t) {
1382
- return this._promise.then((res) => res.unwrapOr(t));
1383
- }
1384
- /**
1385
- * Emulates Rust's `?` operator in `safeTry`'s body. See also `safeTry`.
1386
- */
1387
- safeUnwrap() {
1388
- return __asyncGenerator(this, arguments, function* safeUnwrap_1() {
1389
- return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(yield __await(this._promise.then((res) => res.safeUnwrap()))))));
1390
- });
1391
- }
1392
- // Makes ResultAsync implement PromiseLike<Result>
1393
- then(successCallback, failureCallback) {
1394
- return this._promise.then(successCallback, failureCallback);
1395
- }
1396
- };
1397
- var errAsync = (err2) => new ResultAsync(Promise.resolve(new Err(err2)));
1398
- var fromPromise = ResultAsync.fromPromise;
1399
- var fromSafePromise = ResultAsync.fromSafePromise;
1400
- var fromAsyncThrowable = ResultAsync.fromThrowable;
1401
- var combineResultList = (resultList) => {
1402
- let acc = ok([]);
1403
- for (const result of resultList) {
1404
- if (result.isErr()) {
1405
- acc = err(result.error);
1406
- break;
1407
- } else {
1408
- acc.map((list) => list.push(result.value));
1409
- }
1410
- }
1411
- return acc;
1412
- };
1413
- var combineResultAsyncList = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultList);
1414
- var combineResultListWithAllErrors = (resultList) => {
1415
- let acc = ok([]);
1416
- for (const result of resultList) {
1417
- if (result.isErr() && acc.isErr()) {
1418
- acc.error.push(result.error);
1419
- } else if (result.isErr() && acc.isOk()) {
1420
- acc = err([result.error]);
1421
- } else if (result.isOk() && acc.isOk()) {
1422
- acc.value.push(result.value);
1423
- }
1424
- }
1425
- return acc;
1426
- };
1427
- var combineResultAsyncListWithAllErrors = (asyncResultList) => ResultAsync.fromSafePromise(Promise.all(asyncResultList)).andThen(combineResultListWithAllErrors);
1428
- var Result;
1429
- (function(Result2) {
1430
- function fromThrowable2(fn, errorFn) {
1431
- return (...args) => {
1432
- try {
1433
- const result = fn(...args);
1434
- return ok(result);
1435
- } catch (e) {
1436
- return err(errorFn ? errorFn(e) : e);
1437
- }
1438
- };
1439
- }
1440
- Result2.fromThrowable = fromThrowable2;
1441
- function combine(resultList) {
1442
- return combineResultList(resultList);
1443
- }
1444
- Result2.combine = combine;
1445
- function combineWithAllErrors(resultList) {
1446
- return combineResultListWithAllErrors(resultList);
1447
- }
1448
- Result2.combineWithAllErrors = combineWithAllErrors;
1449
- })(Result || (Result = {}));
1450
- var ok = (value) => new Ok(value);
1451
- var err = (err2) => new Err(err2);
1452
- var Ok = class {
1453
- constructor(value) {
1454
- this.value = value;
1455
- }
1456
- isOk() {
1457
- return true;
1458
- }
1459
- isErr() {
1460
- return !this.isOk();
1461
- }
1462
- map(f) {
1463
- return ok(f(this.value));
1464
- }
1465
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1466
- mapErr(_f) {
1467
- return ok(this.value);
1468
- }
1469
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1470
- andThen(f) {
1471
- return f(this.value);
1472
- }
1473
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1474
- orElse(_f) {
1475
- return ok(this.value);
1476
- }
1477
- asyncAndThen(f) {
1478
- return f(this.value);
1479
- }
1480
- asyncMap(f) {
1481
- return ResultAsync.fromSafePromise(f(this.value));
1482
- }
1483
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1484
- unwrapOr(_v) {
1485
- return this.value;
1486
- }
1487
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1488
- match(ok2, _err) {
1489
- return ok2(this.value);
1490
- }
1491
- safeUnwrap() {
1492
- const value = this.value;
1493
- return function* () {
1494
- return value;
1495
- }();
1496
- }
1497
- _unsafeUnwrap(_) {
1498
- return this.value;
1499
- }
1500
- _unsafeUnwrapErr(config) {
1501
- throw createNeverThrowError("Called `_unsafeUnwrapErr` on an Ok", this, config);
1502
- }
1503
- };
1504
- var Err = class {
1505
- constructor(error) {
1506
- this.error = error;
1507
- }
1508
- isOk() {
1509
- return false;
1510
- }
1511
- isErr() {
1512
- return !this.isOk();
1513
- }
1514
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1515
- map(_f) {
1516
- return err(this.error);
1517
- }
1518
- mapErr(f) {
1519
- return err(f(this.error));
1520
- }
1521
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1522
- andThen(_f) {
1523
- return err(this.error);
1524
- }
1525
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1526
- orElse(f) {
1527
- return f(this.error);
1528
- }
1529
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1530
- asyncAndThen(_f) {
1531
- return errAsync(this.error);
1532
- }
1533
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1534
- asyncMap(_f) {
1535
- return errAsync(this.error);
1536
- }
1537
- unwrapOr(v) {
1538
- return v;
1539
- }
1540
- match(_ok, err2) {
1541
- return err2(this.error);
1542
- }
1543
- safeUnwrap() {
1544
- const error = this.error;
1545
- return function* () {
1546
- yield err(error);
1547
- throw new Error("Do not use this generator out of `safeTry`");
1548
- }();
1549
- }
1550
- _unsafeUnwrap(config) {
1551
- throw createNeverThrowError("Called `_unsafeUnwrap` on an Err", this, config);
1552
- }
1553
- _unsafeUnwrapErr(_) {
1554
- return this.error;
1555
- }
1556
- };
1557
- var fromThrowable = Result.fromThrowable;
1198
+ // src/client/workflow/context.ts
1199
+ import { err as err2, ok as ok2 } from "neverthrow";
1200
+
1201
+ // src/client/workflow/workflow-requests.ts
1202
+ import { err, ok } from "neverthrow";
1558
1203
 
1559
1204
  // src/client/workflow/types.ts
1560
1205
  var StepTypes = ["Initial", "Run", "SleepFor", "SleepUntil", "Call"];
@@ -1630,11 +1275,11 @@ var handleThirdPartyCallResult = async (request, requestPayload, client, workflo
1630
1275
  if (!(callbackMessage.status >= 200 && callbackMessage.status < 300)) {
1631
1276
  await debug?.log("WARN", "SUBMIT_THIRD_PARTY_RESULT", {
1632
1277
  status: callbackMessage.status,
1633
- body: decodeBase64(callbackMessage.body)
1278
+ body: atob(callbackMessage.body)
1634
1279
  });
1635
1280
  console.warn(
1636
1281
  `Workflow Warning: "context.call" failed with status ${callbackMessage.status} and will retry (if there are retries remaining). Error Message:
1637
- ${decodeBase64(callbackMessage.body)}`
1282
+ ${atob(callbackMessage.body)}`
1638
1283
  );
1639
1284
  return ok("call-will-retry");
1640
1285
  }
@@ -1670,7 +1315,7 @@ ${decodeBase64(callbackMessage.body)}`
1670
1315
  stepId: Number(stepIdString),
1671
1316
  stepName,
1672
1317
  stepType,
1673
- out: decodeBase64(callbackMessage.body),
1318
+ out: atob(callbackMessage.body),
1674
1319
  concurrent: Number(concurrentString)
1675
1320
  };
1676
1321
  await debug?.log("SUBMIT", "SUBMIT_THIRD_PARTY_RESULT", {
@@ -2549,11 +2194,11 @@ var DisabledWorkflowContext = class _DisabledWorkflowContext extends WorkflowCon
2549
2194
  await routeFunction(disabledContext);
2550
2195
  } catch (error) {
2551
2196
  if (error instanceof QStashWorkflowAbort && error.stepName === this.disabledMessage) {
2552
- return ok("step-found");
2197
+ return ok2("step-found");
2553
2198
  }
2554
- return err(error);
2199
+ return err2(error);
2555
2200
  }
2556
- return ok("run-ended");
2201
+ return ok2("run-ended");
2557
2202
  }
2558
2203
  };
2559
2204
 
@@ -2606,6 +2251,7 @@ var WorkflowLogger = class _WorkflowLogger {
2606
2251
  };
2607
2252
 
2608
2253
  // src/client/workflow/workflow-parser.ts
2254
+ import { err as err3, ok as ok3 } from "neverthrow";
2609
2255
  var getPayload = async (request) => {
2610
2256
  try {
2611
2257
  return await request.text();
@@ -2662,7 +2308,7 @@ var checkIfLastOneIsDuplicate = async (steps, debug) => {
2662
2308
  for (let index = 0; index < steps.length - 1; index++) {
2663
2309
  const step = steps[index];
2664
2310
  if (step.stepId === lastStepId && step.targetStep === lastTargetStepId) {
2665
- const message = `QStash Workflow: The step '${step.stepName}' with id '${step.stepId}' has run twice during workflow execution. Rest of the workflow will continue running as usual.`;
2311
+ const message = `Upstash Workflow: The step '${step.stepName}' with id '${step.stepId}' has run twice during workflow execution. Rest of the workflow will continue running as usual.`;
2666
2312
  await debug?.log("WARN", "RESPONSE_DEFAULT", message);
2667
2313
  console.warn(message);
2668
2314
  return true;
@@ -2710,10 +2356,10 @@ var parseRequest = async (requestPayload, isFirstInvocation, debug) => {
2710
2356
  };
2711
2357
  var handleFailure = async (request, requestPayload, qstashClient, initialPayloadParser, failureFunction, debug) => {
2712
2358
  if (request.headers.get(WORKFLOW_FAILURE_HEADER) !== "true") {
2713
- return ok("not-failure-callback");
2359
+ return ok3("not-failure-callback");
2714
2360
  }
2715
2361
  if (!failureFunction) {
2716
- return err(
2362
+ return err3(
2717
2363
  new QStashWorkflowError(
2718
2364
  "Workflow endpoint is called to handle a failure, but a failureFunction is not provided in serve options. Either provide a failureUrl or a failureFunction."
2719
2365
  )
@@ -2743,9 +2389,9 @@ var handleFailure = async (request, requestPayload, qstashClient, initialPayload
2743
2389
  });
2744
2390
  await failureFunction(workflowContext, status, errorPayload.message, header);
2745
2391
  } catch (error) {
2746
- return err(error);
2392
+ return err3(error);
2747
2393
  }
2748
- return ok("is-failure-callback");
2394
+ return ok3("is-failure-callback");
2749
2395
  };
2750
2396
 
2751
2397
  // src/client/workflow/serve.ts
@@ -2807,7 +2453,7 @@ var serve = (routeFunction, options) => {
2807
2453
  }) : initialWorkflowUrl;
2808
2454
  if (workflowUrl !== initialWorkflowUrl) {
2809
2455
  await debug?.log("WARN", "ENDPOINT_START", {
2810
- warning: `QStash Workflow: replacing the base of the url with "${baseUrl}" and using it as workflow endpoint.`,
2456
+ warning: `Upstash Workflow: replacing the base of the url with "${baseUrl}" and using it as workflow endpoint.`,
2811
2457
  originalURL: initialWorkflowUrl,
2812
2458
  updatedURL: workflowUrl
2813
2459
  });
@@ -105,10 +105,12 @@ type RateLimit = {
105
105
  reset: string | null;
106
106
  };
107
107
 
108
- type ProviderReturnType = {
109
- owner: "upstash" | "openai" | "custom";
110
- baseUrl: string;
111
- token: string;
108
+ type Owner = "upstash" | "openai" | "custom";
109
+ type ProviderReturnType<TOwner extends Owner = Owner, TBaseUrl extends string = string, TToken extends string = string, TOrganization extends string | undefined = string | undefined> = {
110
+ owner: TOwner;
111
+ baseUrl: TBaseUrl;
112
+ token: TToken;
113
+ organization: TOrganization;
112
114
  };
113
115
  type AnalyticsConfig = {
114
116
  name: "helicone";
@@ -119,26 +121,15 @@ type AnalyticsSetup = {
119
121
  defaultHeaders?: Record<string, string | undefined>;
120
122
  };
121
123
  declare const setupAnalytics: (analytics: AnalyticsConfig | undefined, providerApiKey: string, providerBaseUrl?: string, provider?: "openai" | "upstash" | "custom") => AnalyticsSetup;
122
- declare const upstash: () => {
123
- owner: "upstash";
124
- baseUrl: "https://qstash.upstash.io/llm";
125
- token: string;
126
- };
127
- declare const openai: ({ token, }: {
128
- token: string;
129
- }) => {
130
- owner: "openai";
131
- baseUrl: "https://api.openai.com";
132
- token: string;
133
- };
134
- declare const custom: ({ baseUrl, token, }: {
135
- token: string;
136
- baseUrl: string;
137
- }) => {
138
- owner: "custom";
124
+ declare const upstash: () => ProviderReturnType<"upstash", "https://qstash.upstash.io/llm", "">;
125
+ declare const openai: <TToken extends string = string, TOrganization extends string | undefined = undefined>({ token, organization, }: {
126
+ token: TToken;
127
+ organization?: TOrganization;
128
+ }) => ProviderReturnType<"openai", "https://api.openai.com", TToken, TOrganization extends string ? TOrganization : undefined>;
129
+ declare const custom: <TToken extends string = string>({ baseUrl, token, }: {
139
130
  baseUrl: string;
140
- token: string;
141
- };
131
+ token: TToken;
132
+ }) => ProviderReturnType<"custom", string, TToken>;
142
133
 
143
134
  type ChatCompletionMessage = {
144
135
  role: "system" | "assistant" | "user";
@@ -227,21 +218,21 @@ type ChatRequestFields = ChatRequestCommonFields & {
227
218
  messages: ChatCompletionMessage[];
228
219
  };
229
220
  type ChatRequestProviders = {
230
- provider: ProviderReturnType;
221
+ provider: ProviderReturnType<"openai">;
231
222
  model: OpenAIChatModel;
232
223
  analytics?: {
233
224
  name: "helicone";
234
225
  token: string;
235
226
  };
236
227
  } | {
237
- provider: ProviderReturnType;
228
+ provider: ProviderReturnType<"custom">;
238
229
  model: string;
239
230
  analytics?: {
240
231
  name: "helicone";
241
232
  token: string;
242
233
  };
243
234
  } | {
244
- provider: ProviderReturnType;
235
+ provider: ProviderReturnType<"upstash">;
245
236
  model: ChatModel;
246
237
  analytics?: {
247
238
  name: "helicone";
@@ -978,7 +969,7 @@ declare class AutoExecutor {
978
969
  }
979
970
 
980
971
  /**
981
- * QStash workflow context
972
+ * Upstash Workflow context
982
973
  *
983
974
  * See the docs for fields and methods https://upstash.com/docs/qstash/workflows/basics/context
984
975
  */