@musistudio/claude-code-router 1.0.19 → 1.0.21

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/dist/cli.js CHANGED
@@ -1517,19 +1517,19 @@ var require_process_warning = __commonJS({
1517
1517
  if (typeof unlimited !== "boolean") throw new Error("Warning opts.unlimited must be a boolean");
1518
1518
  code = code.toUpperCase();
1519
1519
  let warningContainer = {
1520
- [name]: function(a, b, c) {
1520
+ [name]: function(a, b2, c) {
1521
1521
  if (warning.emitted === true && warning.unlimited !== true) {
1522
1522
  return;
1523
1523
  }
1524
1524
  warning.emitted = true;
1525
- process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
1525
+ process.emitWarning(warning.format(a, b2, c), warning.name, warning.code);
1526
1526
  }
1527
1527
  };
1528
1528
  if (unlimited) {
1529
1529
  warningContainer = {
1530
- [name]: function(a, b, c) {
1530
+ [name]: function(a, b2, c) {
1531
1531
  warning.emitted = true;
1532
- process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
1532
+ process.emitWarning(warning.format(a, b2, c), warning.name, warning.code);
1533
1533
  }
1534
1534
  };
1535
1535
  }
@@ -1538,12 +1538,12 @@ var require_process_warning = __commonJS({
1538
1538
  warning.message = message;
1539
1539
  warning.unlimited = unlimited;
1540
1540
  warning.code = code;
1541
- warning.format = function(a, b, c) {
1541
+ warning.format = function(a, b2, c) {
1542
1542
  let formatted;
1543
- if (a && b && c) {
1544
- formatted = format(message, a, b, c);
1545
- } else if (a && b) {
1546
- formatted = format(message, a, b);
1543
+ if (a && b2 && c) {
1544
+ formatted = format(message, a, b2, c);
1545
+ } else if (a && b2) {
1546
+ formatted = format(message, a, b2);
1547
1547
  } else if (a) {
1548
1548
  formatted = format(message, a);
1549
1549
  } else {
@@ -2150,20 +2150,20 @@ var require_hooks = __commonJS({
2150
2150
  this.validate(hook, fn);
2151
2151
  this[hook].push(fn);
2152
2152
  };
2153
- function buildHooks(h2) {
2153
+ function buildHooks(h) {
2154
2154
  const hooks = new Hooks();
2155
- hooks.onRequest = h2.onRequest.slice();
2156
- hooks.preParsing = h2.preParsing.slice();
2157
- hooks.preValidation = h2.preValidation.slice();
2158
- hooks.preSerialization = h2.preSerialization.slice();
2159
- hooks.preHandler = h2.preHandler.slice();
2160
- hooks.onSend = h2.onSend.slice();
2161
- hooks.onResponse = h2.onResponse.slice();
2162
- hooks.onError = h2.onError.slice();
2163
- hooks.onRoute = h2.onRoute.slice();
2164
- hooks.onRegister = h2.onRegister.slice();
2165
- hooks.onTimeout = h2.onTimeout.slice();
2166
- hooks.onRequestAbort = h2.onRequestAbort.slice();
2155
+ hooks.onRequest = h.onRequest.slice();
2156
+ hooks.preParsing = h.preParsing.slice();
2157
+ hooks.preValidation = h.preValidation.slice();
2158
+ hooks.preSerialization = h.preSerialization.slice();
2159
+ hooks.preHandler = h.preHandler.slice();
2160
+ hooks.onSend = h.onSend.slice();
2161
+ hooks.onResponse = h.onResponse.slice();
2162
+ hooks.onError = h.onError.slice();
2163
+ hooks.onRoute = h.onRoute.slice();
2164
+ hooks.onRegister = h.onRegister.slice();
2165
+ hooks.onTimeout = h.onTimeout.slice();
2166
+ hooks.onRequestAbort = h.onRequestAbort.slice();
2167
2167
  hooks.onReady = [];
2168
2168
  hooks.onListen = [];
2169
2169
  hooks.preClose = [];
@@ -2782,7 +2782,7 @@ var require_validation = __commonJS({
2782
2782
  headersSchemaLowerCase[k] = headers[k];
2783
2783
  });
2784
2784
  if (headersSchemaLowerCase.required instanceof Array) {
2785
- headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((h2) => h2.toLowerCase());
2785
+ headersSchemaLowerCase.required = headersSchemaLowerCase.required.map((h) => h.toLowerCase());
2786
2786
  }
2787
2787
  if (headers.properties) {
2788
2788
  headersSchemaLowerCase.properties = {};
@@ -7299,8 +7299,8 @@ var require_multistream = __commonJS({
7299
7299
  };
7300
7300
  }
7301
7301
  }
7302
- function compareByLevel(a, b) {
7303
- return a.level - b.level;
7302
+ function compareByLevel(a, b2) {
7303
+ return a.level - b2.level;
7304
7304
  }
7305
7305
  function initLoopVar(length, dedupe) {
7306
7306
  return dedupe ? length - 1 : 0;
@@ -12189,22 +12189,22 @@ var require_code = __commonJS({
12189
12189
  i++;
12190
12190
  }
12191
12191
  }
12192
- function mergeExprItems(a, b) {
12193
- if (b === '""')
12192
+ function mergeExprItems(a, b2) {
12193
+ if (b2 === '""')
12194
12194
  return a;
12195
12195
  if (a === '""')
12196
- return b;
12196
+ return b2;
12197
12197
  if (typeof a == "string") {
12198
- if (b instanceof Name || a[a.length - 1] !== '"')
12198
+ if (b2 instanceof Name || a[a.length - 1] !== '"')
12199
12199
  return;
12200
- if (typeof b != "string")
12201
- return `${a.slice(0, -1)}${b}"`;
12202
- if (b[0] === '"')
12203
- return a.slice(0, -1) + b.slice(1);
12200
+ if (typeof b2 != "string")
12201
+ return `${a.slice(0, -1)}${b2}"`;
12202
+ if (b2[0] === '"')
12203
+ return a.slice(0, -1) + b2.slice(1);
12204
12204
  return;
12205
12205
  }
12206
- if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
12207
- return `"${a}${b.slice(1)}`;
12206
+ if (typeof b2 == "string" && b2[0] === '"' && !(a instanceof Name))
12207
+ return `"${a}${b2.slice(1)}`;
12208
12208
  return;
12209
12209
  }
12210
12210
  function strConcat(c1, c2) {
@@ -14097,33 +14097,33 @@ var require_subschema = __commonJS({
14097
14097
  var require_fast_deep_equal = __commonJS({
14098
14098
  "node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports2, module2) {
14099
14099
  "use strict";
14100
- module2.exports = function equal(a, b) {
14101
- if (a === b) return true;
14102
- if (a && b && typeof a == "object" && typeof b == "object") {
14103
- if (a.constructor !== b.constructor) return false;
14100
+ module2.exports = function equal(a, b2) {
14101
+ if (a === b2) return true;
14102
+ if (a && b2 && typeof a == "object" && typeof b2 == "object") {
14103
+ if (a.constructor !== b2.constructor) return false;
14104
14104
  var length, i, keys;
14105
14105
  if (Array.isArray(a)) {
14106
14106
  length = a.length;
14107
- if (length != b.length) return false;
14107
+ if (length != b2.length) return false;
14108
14108
  for (i = length; i-- !== 0; )
14109
- if (!equal(a[i], b[i])) return false;
14109
+ if (!equal(a[i], b2[i])) return false;
14110
14110
  return true;
14111
14111
  }
14112
- if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
14113
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
14114
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
14112
+ if (a.constructor === RegExp) return a.source === b2.source && a.flags === b2.flags;
14113
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b2.valueOf();
14114
+ if (a.toString !== Object.prototype.toString) return a.toString() === b2.toString();
14115
14115
  keys = Object.keys(a);
14116
14116
  length = keys.length;
14117
- if (length !== Object.keys(b).length) return false;
14117
+ if (length !== Object.keys(b2).length) return false;
14118
14118
  for (i = length; i-- !== 0; )
14119
- if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
14119
+ if (!Object.prototype.hasOwnProperty.call(b2, keys[i])) return false;
14120
14120
  for (i = length; i-- !== 0; ) {
14121
14121
  var key = keys[i];
14122
- if (!equal(a[key], b[key])) return false;
14122
+ if (!equal(a[key], b2[key])) return false;
14123
14123
  }
14124
14124
  return true;
14125
14125
  }
14126
- return a !== a && b !== b;
14126
+ return a !== a && b2 !== b2;
14127
14127
  };
14128
14128
  }
14129
14129
  });
@@ -15916,14 +15916,14 @@ var require_core = __commonJS({
15916
15916
  };
15917
15917
  var MAX_EXPRESSION = 200;
15918
15918
  function requiredOptions(o) {
15919
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
15919
+ var _a, _b, _c, _d, _e2, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
15920
15920
  const s = o.strict;
15921
15921
  const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize;
15922
15922
  const optimize = _optz === true || _optz === void 0 ? 1 : _optz || 0;
15923
15923
  const regExp = (_c = (_b = o.code) === null || _b === void 0 ? void 0 : _b.regExp) !== null && _c !== void 0 ? _c : defaultRegExp;
15924
15924
  const uriResolver = (_d = o.uriResolver) !== null && _d !== void 0 ? _d : uri_1.default;
15925
15925
  return {
15926
- strictSchema: (_f = (_e = o.strictSchema) !== null && _e !== void 0 ? _e : s) !== null && _f !== void 0 ? _f : true,
15926
+ strictSchema: (_f = (_e2 = o.strictSchema) !== null && _e2 !== void 0 ? _e2 : s) !== null && _f !== void 0 ? _f : true,
15927
15927
  strictNumbers: (_h = (_g = o.strictNumbers) !== null && _g !== void 0 ? _g : s) !== null && _h !== void 0 ? _h : true,
15928
15928
  strictTypes: (_k = (_j = o.strictTypes) !== null && _j !== void 0 ? _j : s) !== null && _k !== void 0 ? _k : "log",
15929
15929
  strictTuples: (_m = (_l = o.strictTuples) !== null && _l !== void 0 ? _l : s) !== null && _m !== void 0 ? _m : "log",
@@ -20043,8 +20043,8 @@ var require_resolvers = __commonJS({
20043
20043
  mergedSchema[keyword] = Math.max(...values);
20044
20044
  }
20045
20045
  function commonMultiple(keyword, values, mergedSchema) {
20046
- const gcd = (a, b) => !b ? a : gcd(b, a % b);
20047
- const lcm = (a, b) => a * b / gcd(a, b);
20046
+ const gcd = (a, b2) => !b2 ? a : gcd(b2, a % b2);
20047
+ const lcm = (a, b2) => a * b2 / gcd(a, b2);
20048
20048
  let scale = 1;
20049
20049
  for (const value of values) {
20050
20050
  while (value * scale % 1 !== 0) {
@@ -23504,7 +23504,7 @@ var require_re = __commonJS({
23504
23504
  } = require_constants2();
23505
23505
  var debug = require_debug2();
23506
23506
  exports2 = module2.exports = {};
23507
- var re = exports2.re = [];
23507
+ var re2 = exports2.re = [];
23508
23508
  var safeRe = exports2.safeRe = [];
23509
23509
  var src = exports2.src = [];
23510
23510
  var safeSrc = exports2.safeSrc = [];
@@ -23529,7 +23529,7 @@ var require_re = __commonJS({
23529
23529
  t[name] = index;
23530
23530
  src[index] = value;
23531
23531
  safeSrc[index] = safe;
23532
- re[index] = new RegExp(value, isGlobal ? "g" : void 0);
23532
+ re2[index] = new RegExp(value, isGlobal ? "g" : void 0);
23533
23533
  safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
23534
23534
  };
23535
23535
  createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
@@ -23605,16 +23605,16 @@ var require_identifiers = __commonJS({
23605
23605
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/internal/identifiers.js"(exports2, module2) {
23606
23606
  "use strict";
23607
23607
  var numeric = /^[0-9]+$/;
23608
- var compareIdentifiers = (a, b) => {
23608
+ var compareIdentifiers = (a, b2) => {
23609
23609
  const anum = numeric.test(a);
23610
- const bnum = numeric.test(b);
23610
+ const bnum = numeric.test(b2);
23611
23611
  if (anum && bnum) {
23612
23612
  a = +a;
23613
- b = +b;
23613
+ b2 = +b2;
23614
23614
  }
23615
- return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
23615
+ return a === b2 ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b2 ? -1 : 1;
23616
23616
  };
23617
- var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
23617
+ var rcompareIdentifiers = (a, b2) => compareIdentifiers(b2, a);
23618
23618
  module2.exports = {
23619
23619
  compareIdentifiers,
23620
23620
  rcompareIdentifiers
@@ -23628,7 +23628,7 @@ var require_semver = __commonJS({
23628
23628
  "use strict";
23629
23629
  var debug = require_debug2();
23630
23630
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants2();
23631
- var { safeRe: re, t } = require_re();
23631
+ var { safeRe: re2, t } = require_re();
23632
23632
  var parseOptions = require_parse_options();
23633
23633
  var { compareIdentifiers } = require_identifiers();
23634
23634
  var SemVer = class _SemVer {
@@ -23652,7 +23652,7 @@ var require_semver = __commonJS({
23652
23652
  this.options = options;
23653
23653
  this.loose = !!options.loose;
23654
23654
  this.includePrerelease = !!options.includePrerelease;
23655
- const m = version2.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
23655
+ const m = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
23656
23656
  if (!m) {
23657
23657
  throw new TypeError(`Invalid Version: ${version2}`);
23658
23658
  }
@@ -23728,18 +23728,18 @@ var require_semver = __commonJS({
23728
23728
  let i = 0;
23729
23729
  do {
23730
23730
  const a = this.prerelease[i];
23731
- const b = other.prerelease[i];
23732
- debug("prerelease compare", i, a, b);
23733
- if (a === void 0 && b === void 0) {
23731
+ const b2 = other.prerelease[i];
23732
+ debug("prerelease compare", i, a, b2);
23733
+ if (a === void 0 && b2 === void 0) {
23734
23734
  return 0;
23735
- } else if (b === void 0) {
23735
+ } else if (b2 === void 0) {
23736
23736
  return 1;
23737
23737
  } else if (a === void 0) {
23738
23738
  return -1;
23739
- } else if (a === b) {
23739
+ } else if (a === b2) {
23740
23740
  continue;
23741
23741
  } else {
23742
- return compareIdentifiers(a, b);
23742
+ return compareIdentifiers(a, b2);
23743
23743
  }
23744
23744
  } while (++i);
23745
23745
  }
@@ -23750,18 +23750,18 @@ var require_semver = __commonJS({
23750
23750
  let i = 0;
23751
23751
  do {
23752
23752
  const a = this.build[i];
23753
- const b = other.build[i];
23754
- debug("build compare", i, a, b);
23755
- if (a === void 0 && b === void 0) {
23753
+ const b2 = other.build[i];
23754
+ debug("build compare", i, a, b2);
23755
+ if (a === void 0 && b2 === void 0) {
23756
23756
  return 0;
23757
- } else if (b === void 0) {
23757
+ } else if (b2 === void 0) {
23758
23758
  return 1;
23759
23759
  } else if (a === void 0) {
23760
23760
  return -1;
23761
- } else if (a === b) {
23761
+ } else if (a === b2) {
23762
23762
  continue;
23763
23763
  } else {
23764
- return compareIdentifiers(a, b);
23764
+ return compareIdentifiers(a, b2);
23765
23765
  }
23766
23766
  } while (++i);
23767
23767
  }
@@ -23773,7 +23773,7 @@ var require_semver = __commonJS({
23773
23773
  throw new Error("invalid increment argument: identifier is empty");
23774
23774
  }
23775
23775
  if (identifier) {
23776
- const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
23776
+ const match = `-${identifier}`.match(this.options.loose ? re2[t.PRERELEASELOOSE] : re2[t.PRERELEASE]);
23777
23777
  if (!match || match[1] !== identifier) {
23778
23778
  throw new Error(`invalid identifier: ${identifier}`);
23779
23779
  }
@@ -24047,7 +24047,7 @@ var require_compare = __commonJS({
24047
24047
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare.js"(exports2, module2) {
24048
24048
  "use strict";
24049
24049
  var SemVer = require_semver();
24050
- var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
24050
+ var compare = (a, b2, loose) => new SemVer(a, loose).compare(new SemVer(b2, loose));
24051
24051
  module2.exports = compare;
24052
24052
  }
24053
24053
  });
@@ -24057,7 +24057,7 @@ var require_rcompare = __commonJS({
24057
24057
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rcompare.js"(exports2, module2) {
24058
24058
  "use strict";
24059
24059
  var compare = require_compare();
24060
- var rcompare = (a, b, loose) => compare(b, a, loose);
24060
+ var rcompare = (a, b2, loose) => compare(b2, a, loose);
24061
24061
  module2.exports = rcompare;
24062
24062
  }
24063
24063
  });
@@ -24067,7 +24067,7 @@ var require_compare_loose = __commonJS({
24067
24067
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-loose.js"(exports2, module2) {
24068
24068
  "use strict";
24069
24069
  var compare = require_compare();
24070
- var compareLoose = (a, b) => compare(a, b, true);
24070
+ var compareLoose = (a, b2) => compare(a, b2, true);
24071
24071
  module2.exports = compareLoose;
24072
24072
  }
24073
24073
  });
@@ -24077,9 +24077,9 @@ var require_compare_build = __commonJS({
24077
24077
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/compare-build.js"(exports2, module2) {
24078
24078
  "use strict";
24079
24079
  var SemVer = require_semver();
24080
- var compareBuild = (a, b, loose) => {
24080
+ var compareBuild = (a, b2, loose) => {
24081
24081
  const versionA = new SemVer(a, loose);
24082
- const versionB = new SemVer(b, loose);
24082
+ const versionB = new SemVer(b2, loose);
24083
24083
  return versionA.compare(versionB) || versionA.compareBuild(versionB);
24084
24084
  };
24085
24085
  module2.exports = compareBuild;
@@ -24091,7 +24091,7 @@ var require_sort = __commonJS({
24091
24091
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/sort.js"(exports2, module2) {
24092
24092
  "use strict";
24093
24093
  var compareBuild = require_compare_build();
24094
- var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
24094
+ var sort = (list, loose) => list.sort((a, b2) => compareBuild(a, b2, loose));
24095
24095
  module2.exports = sort;
24096
24096
  }
24097
24097
  });
@@ -24101,7 +24101,7 @@ var require_rsort = __commonJS({
24101
24101
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/rsort.js"(exports2, module2) {
24102
24102
  "use strict";
24103
24103
  var compareBuild = require_compare_build();
24104
- var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
24104
+ var rsort = (list, loose) => list.sort((a, b2) => compareBuild(b2, a, loose));
24105
24105
  module2.exports = rsort;
24106
24106
  }
24107
24107
  });
@@ -24111,7 +24111,7 @@ var require_gt = __commonJS({
24111
24111
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gt.js"(exports2, module2) {
24112
24112
  "use strict";
24113
24113
  var compare = require_compare();
24114
- var gt = (a, b, loose) => compare(a, b, loose) > 0;
24114
+ var gt = (a, b2, loose) => compare(a, b2, loose) > 0;
24115
24115
  module2.exports = gt;
24116
24116
  }
24117
24117
  });
@@ -24121,7 +24121,7 @@ var require_lt = __commonJS({
24121
24121
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lt.js"(exports2, module2) {
24122
24122
  "use strict";
24123
24123
  var compare = require_compare();
24124
- var lt = (a, b, loose) => compare(a, b, loose) < 0;
24124
+ var lt = (a, b2, loose) => compare(a, b2, loose) < 0;
24125
24125
  module2.exports = lt;
24126
24126
  }
24127
24127
  });
@@ -24131,7 +24131,7 @@ var require_eq = __commonJS({
24131
24131
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/eq.js"(exports2, module2) {
24132
24132
  "use strict";
24133
24133
  var compare = require_compare();
24134
- var eq = (a, b, loose) => compare(a, b, loose) === 0;
24134
+ var eq = (a, b2, loose) => compare(a, b2, loose) === 0;
24135
24135
  module2.exports = eq;
24136
24136
  }
24137
24137
  });
@@ -24141,7 +24141,7 @@ var require_neq = __commonJS({
24141
24141
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/neq.js"(exports2, module2) {
24142
24142
  "use strict";
24143
24143
  var compare = require_compare();
24144
- var neq = (a, b, loose) => compare(a, b, loose) !== 0;
24144
+ var neq = (a, b2, loose) => compare(a, b2, loose) !== 0;
24145
24145
  module2.exports = neq;
24146
24146
  }
24147
24147
  });
@@ -24151,7 +24151,7 @@ var require_gte = __commonJS({
24151
24151
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/gte.js"(exports2, module2) {
24152
24152
  "use strict";
24153
24153
  var compare = require_compare();
24154
- var gte = (a, b, loose) => compare(a, b, loose) >= 0;
24154
+ var gte = (a, b2, loose) => compare(a, b2, loose) >= 0;
24155
24155
  module2.exports = gte;
24156
24156
  }
24157
24157
  });
@@ -24161,7 +24161,7 @@ var require_lte = __commonJS({
24161
24161
  "node_modules/.pnpm/semver@7.7.2/node_modules/semver/functions/lte.js"(exports2, module2) {
24162
24162
  "use strict";
24163
24163
  var compare = require_compare();
24164
- var lte = (a, b, loose) => compare(a, b, loose) <= 0;
24164
+ var lte = (a, b2, loose) => compare(a, b2, loose) <= 0;
24165
24165
  module2.exports = lte;
24166
24166
  }
24167
24167
  });
@@ -24176,38 +24176,38 @@ var require_cmp = __commonJS({
24176
24176
  var gte = require_gte();
24177
24177
  var lt = require_lt();
24178
24178
  var lte = require_lte();
24179
- var cmp = (a, op, b, loose) => {
24179
+ var cmp = (a, op, b2, loose) => {
24180
24180
  switch (op) {
24181
24181
  case "===":
24182
24182
  if (typeof a === "object") {
24183
24183
  a = a.version;
24184
24184
  }
24185
- if (typeof b === "object") {
24186
- b = b.version;
24185
+ if (typeof b2 === "object") {
24186
+ b2 = b2.version;
24187
24187
  }
24188
- return a === b;
24188
+ return a === b2;
24189
24189
  case "!==":
24190
24190
  if (typeof a === "object") {
24191
24191
  a = a.version;
24192
24192
  }
24193
- if (typeof b === "object") {
24194
- b = b.version;
24193
+ if (typeof b2 === "object") {
24194
+ b2 = b2.version;
24195
24195
  }
24196
- return a !== b;
24196
+ return a !== b2;
24197
24197
  case "":
24198
24198
  case "=":
24199
24199
  case "==":
24200
- return eq(a, b, loose);
24200
+ return eq(a, b2, loose);
24201
24201
  case "!=":
24202
- return neq(a, b, loose);
24202
+ return neq(a, b2, loose);
24203
24203
  case ">":
24204
- return gt(a, b, loose);
24204
+ return gt(a, b2, loose);
24205
24205
  case ">=":
24206
- return gte(a, b, loose);
24206
+ return gte(a, b2, loose);
24207
24207
  case "<":
24208
- return lt(a, b, loose);
24208
+ return lt(a, b2, loose);
24209
24209
  case "<=":
24210
- return lte(a, b, loose);
24210
+ return lte(a, b2, loose);
24211
24211
  default:
24212
24212
  throw new TypeError(`Invalid operator: ${op}`);
24213
24213
  }
@@ -24222,7 +24222,7 @@ var require_coerce = __commonJS({
24222
24222
  "use strict";
24223
24223
  var SemVer = require_semver();
24224
24224
  var parse = require_parse3();
24225
- var { safeRe: re, t } = require_re();
24225
+ var { safeRe: re2, t } = require_re();
24226
24226
  var coerce = (version2, options) => {
24227
24227
  if (version2 instanceof SemVer) {
24228
24228
  return version2;
@@ -24236,9 +24236,9 @@ var require_coerce = __commonJS({
24236
24236
  options = options || {};
24237
24237
  let match = null;
24238
24238
  if (!options.rtl) {
24239
- match = version2.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
24239
+ match = version2.match(options.includePrerelease ? re2[t.COERCEFULL] : re2[t.COERCE]);
24240
24240
  } else {
24241
- const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
24241
+ const coerceRtlRegex = options.includePrerelease ? re2[t.COERCERTLFULL] : re2[t.COERCERTL];
24242
24242
  let next;
24243
24243
  while ((next = coerceRtlRegex.exec(version2)) && (!match || match.index + match[0].length !== version2.length)) {
24244
24244
  if (!match || next.index + next[0].length !== match.index + match[0].length) {
@@ -24377,20 +24377,20 @@ var require_range = __commonJS({
24377
24377
  return cached;
24378
24378
  }
24379
24379
  const loose = this.options.loose;
24380
- const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
24380
+ const hr = loose ? re2[t.HYPHENRANGELOOSE] : re2[t.HYPHENRANGE];
24381
24381
  range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
24382
24382
  debug("hyphen replace", range);
24383
- range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
24383
+ range = range.replace(re2[t.COMPARATORTRIM], comparatorTrimReplace);
24384
24384
  debug("comparator trim", range);
24385
- range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
24385
+ range = range.replace(re2[t.TILDETRIM], tildeTrimReplace);
24386
24386
  debug("tilde trim", range);
24387
- range = range.replace(re[t.CARETTRIM], caretTrimReplace);
24387
+ range = range.replace(re2[t.CARETTRIM], caretTrimReplace);
24388
24388
  debug("caret trim", range);
24389
24389
  let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
24390
24390
  if (loose) {
24391
24391
  rangeList = rangeList.filter((comp) => {
24392
24392
  debug("loose invalid filter", comp, this.options);
24393
- return !!comp.match(re[t.COMPARATORLOOSE]);
24393
+ return !!comp.match(re2[t.COMPARATORLOOSE]);
24394
24394
  });
24395
24395
  }
24396
24396
  debug("range list", rangeList);
@@ -24451,7 +24451,7 @@ var require_range = __commonJS({
24451
24451
  var debug = require_debug2();
24452
24452
  var SemVer = require_semver();
24453
24453
  var {
24454
- safeRe: re,
24454
+ safeRe: re2,
24455
24455
  t,
24456
24456
  comparatorTrimReplace,
24457
24457
  tildeTrimReplace,
@@ -24489,7 +24489,7 @@ var require_range = __commonJS({
24489
24489
  return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
24490
24490
  };
24491
24491
  var replaceTilde = (comp, options) => {
24492
- const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
24492
+ const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE];
24493
24493
  return comp.replace(r, (_, M, m, p, pr) => {
24494
24494
  debug("tilde", comp, _, M, m, p, pr);
24495
24495
  let ret;
@@ -24514,20 +24514,20 @@ var require_range = __commonJS({
24514
24514
  };
24515
24515
  var replaceCaret = (comp, options) => {
24516
24516
  debug("caret", comp, options);
24517
- const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
24518
- const z = options.includePrerelease ? "-0" : "";
24517
+ const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET];
24518
+ const z2 = options.includePrerelease ? "-0" : "";
24519
24519
  return comp.replace(r, (_, M, m, p, pr) => {
24520
24520
  debug("caret", comp, _, M, m, p, pr);
24521
24521
  let ret;
24522
24522
  if (isX(M)) {
24523
24523
  ret = "";
24524
24524
  } else if (isX(m)) {
24525
- ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
24525
+ ret = `>=${M}.0.0${z2} <${+M + 1}.0.0-0`;
24526
24526
  } else if (isX(p)) {
24527
24527
  if (M === "0") {
24528
- ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
24528
+ ret = `>=${M}.${m}.0${z2} <${M}.${+m + 1}.0-0`;
24529
24529
  } else {
24530
- ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
24530
+ ret = `>=${M}.${m}.0${z2} <${+M + 1}.0.0-0`;
24531
24531
  }
24532
24532
  } else if (pr) {
24533
24533
  debug("replaceCaret pr", pr);
@@ -24544,9 +24544,9 @@ var require_range = __commonJS({
24544
24544
  debug("no pr");
24545
24545
  if (M === "0") {
24546
24546
  if (m === "0") {
24547
- ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
24547
+ ret = `>=${M}.${m}.${p}${z2} <${M}.${m}.${+p + 1}-0`;
24548
24548
  } else {
24549
- ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
24549
+ ret = `>=${M}.${m}.${p}${z2} <${M}.${+m + 1}.0-0`;
24550
24550
  }
24551
24551
  } else {
24552
24552
  ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
@@ -24562,7 +24562,7 @@ var require_range = __commonJS({
24562
24562
  };
24563
24563
  var replaceXRange = (comp, options) => {
24564
24564
  comp = comp.trim();
24565
- const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
24565
+ const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
24566
24566
  return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
24567
24567
  debug("xRange", comp, ret, gtlt, M, m, p, pr);
24568
24568
  const xM = isX(M);
@@ -24617,11 +24617,11 @@ var require_range = __commonJS({
24617
24617
  };
24618
24618
  var replaceStars = (comp, options) => {
24619
24619
  debug("replaceStars", comp, options);
24620
- return comp.trim().replace(re[t.STAR], "");
24620
+ return comp.trim().replace(re2[t.STAR], "");
24621
24621
  };
24622
24622
  var replaceGTE0 = (comp, options) => {
24623
24623
  debug("replaceGTE0", comp, options);
24624
- return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
24624
+ return comp.trim().replace(re2[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
24625
24625
  };
24626
24626
  var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
24627
24627
  if (isX(fM)) {
@@ -24707,7 +24707,7 @@ var require_comparator = __commonJS({
24707
24707
  debug("comp", this);
24708
24708
  }
24709
24709
  parse(comp) {
24710
- const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
24710
+ const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR];
24711
24711
  const m = comp.match(r);
24712
24712
  if (!m) {
24713
24713
  throw new TypeError(`Invalid comparator: ${comp}`);
@@ -24781,7 +24781,7 @@ var require_comparator = __commonJS({
24781
24781
  };
24782
24782
  module2.exports = Comparator;
24783
24783
  var parseOptions = require_parse_options();
24784
- var { safeRe: re, t } = require_re();
24784
+ var { safeRe: re2, t } = require_re();
24785
24785
  var cmp = require_cmp();
24786
24786
  var debug = require_debug2();
24787
24787
  var SemVer = require_semver();
@@ -25062,7 +25062,7 @@ var require_simplify = __commonJS({
25062
25062
  const set = [];
25063
25063
  let first = null;
25064
25064
  let prev = null;
25065
- const v = versions.sort((a, b) => compare(a, b, options));
25065
+ const v = versions.sort((a, b2) => compare(a, b2, options));
25066
25066
  for (const version2 of v) {
25067
25067
  const included = satisfies(version2, range, options);
25068
25068
  if (included) {
@@ -25246,19 +25246,19 @@ var require_subset = __commonJS({
25246
25246
  }
25247
25247
  return true;
25248
25248
  };
25249
- var higherGT = (a, b, options) => {
25249
+ var higherGT = (a, b2, options) => {
25250
25250
  if (!a) {
25251
- return b;
25251
+ return b2;
25252
25252
  }
25253
- const comp = compare(a.semver, b.semver, options);
25254
- return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
25253
+ const comp = compare(a.semver, b2.semver, options);
25254
+ return comp > 0 ? a : comp < 0 ? b2 : b2.operator === ">" && a.operator === ">=" ? b2 : a;
25255
25255
  };
25256
- var lowerLT = (a, b, options) => {
25256
+ var lowerLT = (a, b2, options) => {
25257
25257
  if (!a) {
25258
- return b;
25258
+ return b2;
25259
25259
  }
25260
- const comp = compare(a.semver, b.semver, options);
25261
- return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
25260
+ const comp = compare(a.semver, b2.semver, options);
25261
+ return comp < 0 ? a : comp > 0 ? b2 : b2.operator === "<" && a.operator === "<=" ? b2 : a;
25262
25262
  };
25263
25263
  module2.exports = subset;
25264
25264
  }
@@ -26477,11 +26477,11 @@ var require_util2 = __commonJS({
26477
26477
  var CTRL = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?";
26478
26478
  exports2.strToChars = (str) => {
26479
26479
  const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
26480
- return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {
26480
+ return str.replace(charsRegex, (s, b2, lbs, a16, b16, dctrl, eslsh) => {
26481
26481
  if (lbs) {
26482
26482
  return s;
26483
26483
  }
26484
- let code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : dctrl ? CTRL.indexOf(dctrl) : {
26484
+ let code = b2 ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : dctrl ? CTRL.indexOf(dctrl) : {
26485
26485
  0: 0,
26486
26486
  t: 9,
26487
26487
  n: 10,
@@ -26494,11 +26494,11 @@ var require_util2 = __commonJS({
26494
26494
  });
26495
26495
  };
26496
26496
  exports2.tokenizeClass = (str, regexpStr) => {
26497
- var _a, _b, _c, _d, _e, _f, _g;
26497
+ var _a, _b, _c, _d, _e2, _f, _g;
26498
26498
  let tokens = [], rs, c;
26499
26499
  const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
26500
26500
  while ((rs = regexp.exec(str)) !== null) {
26501
- const p = (_g = (_f = (_e = (_d = (_c = (_b = (_a = rs[1] && sets.words()) !== null && _a !== void 0 ? _a : rs[2] && sets.ints()) !== null && _b !== void 0 ? _b : rs[3] && sets.whitespace()) !== null && _c !== void 0 ? _c : rs[4] && sets.notWords()) !== null && _d !== void 0 ? _d : rs[5] && sets.notInts()) !== null && _e !== void 0 ? _e : rs[6] && sets.notWhitespace()) !== null && _f !== void 0 ? _f : rs[7] && {
26501
+ const p = (_g = (_f = (_e2 = (_d = (_c = (_b = (_a = rs[1] && sets.words()) !== null && _a !== void 0 ? _a : rs[2] && sets.ints()) !== null && _b !== void 0 ? _b : rs[3] && sets.whitespace()) !== null && _c !== void 0 ? _c : rs[4] && sets.notWords()) !== null && _d !== void 0 ? _d : rs[5] && sets.notInts()) !== null && _e2 !== void 0 ? _e2 : rs[6] && sets.notWhitespace()) !== null && _f !== void 0 ? _f : rs[7] && {
26502
26502
  type: types_1.types.RANGE,
26503
26503
  from: (rs[8] || rs[9]).charCodeAt(0),
26504
26504
  to: (c = rs[10]).charCodeAt(c.length - 1)
@@ -27063,13 +27063,13 @@ var require_safe_regex2 = __commonJS({
27063
27063
  "use strict";
27064
27064
  var parse = require_dist3();
27065
27065
  var types = parse.types;
27066
- function safeRegex(re, opts) {
27066
+ function safeRegex(re2, opts) {
27067
27067
  if (!opts) opts = {};
27068
27068
  const replimit = opts.limit === void 0 ? 25 : opts.limit;
27069
- if (isRegExp(re)) re = re.source;
27070
- else if (typeof re !== "string") re = String(re);
27069
+ if (isRegExp(re2)) re2 = re2.source;
27070
+ else if (typeof re2 !== "string") re2 = String(re2);
27071
27071
  try {
27072
- re = parse(re);
27072
+ re2 = parse(re2);
27073
27073
  } catch {
27074
27074
  return false;
27075
27075
  }
@@ -27097,7 +27097,7 @@ var require_safe_regex2 = __commonJS({
27097
27097
  if (!ok) return false;
27098
27098
  }
27099
27099
  return true;
27100
- }(re, 0);
27100
+ }(re2, 0);
27101
27101
  }
27102
27102
  function isRegExp(x) {
27103
27103
  return {}.toString.call(x) === "[object RegExp]";
@@ -27330,7 +27330,7 @@ var require_handler_storage = __commonJS({
27330
27330
  throw new Error("find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached");
27331
27331
  }
27332
27332
  this.handlers.push(handlerObject);
27333
- this.handlers.sort((a, b) => Object.keys(a.constraints).length - Object.keys(b.constraints).length);
27333
+ this.handlers.sort((a, b2) => Object.keys(a.constraints).length - Object.keys(b2.constraints).length);
27334
27334
  if (!isMergedTree) {
27335
27335
  this._compileGetHandlerMatchingConstraints(constrainer, constraints);
27336
27336
  }
@@ -28943,7 +28943,7 @@ var require_route = __commonJS({
28943
28943
  context.schemaErrorFormatter = opts.schemaErrorFormatter || this[kSchemaErrorFormatter] || context.schemaErrorFormatter;
28944
28944
  avvio.once("preReady", () => {
28945
28945
  for (const hook of lifecycleHooks) {
28946
- const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h2) => h2.bind(this));
28946
+ const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h) => h.bind(this));
28947
28947
  context[hook] = toSet.length ? toSet : null;
28948
28948
  }
28949
28949
  while (!context.Request[kHasBeenDecorated] && context.Request.parent) {
@@ -29231,7 +29231,7 @@ var require_fourOhFour = __commonJS({
29231
29231
  avvio.once("preReady", () => {
29232
29232
  const context2 = this[kFourOhFourContext];
29233
29233
  for (const hook of lifecycleHooks) {
29234
- const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h2) => h2.bind(this));
29234
+ const toSet = this[kHooks][hook].concat(opts[hook] || []).map((h) => h.bind(this));
29235
29235
  context2[hook] = toSet.length ? toSet : null;
29236
29236
  }
29237
29237
  context2.errorHandler = opts.errorHandler ? buildErrorHandler(this[kErrorHandler], opts.errorHandler) : this[kErrorHandler];
@@ -30410,10 +30410,10 @@ var require_dist4 = __commonJS({
30410
30410
  var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
30411
30411
  var __toString = Object.prototype.toString;
30412
30412
  var NullObject = /* @__PURE__ */ (() => {
30413
- const C = function() {
30413
+ const C2 = function() {
30414
30414
  };
30415
- C.prototype = /* @__PURE__ */ Object.create(null);
30416
- return C;
30415
+ C2.prototype = /* @__PURE__ */ Object.create(null);
30416
+ return C2;
30417
30417
  })();
30418
30418
  function parse(str, options) {
30419
30419
  const obj = new NullObject();
@@ -30571,19 +30571,19 @@ var require_process_warning2 = __commonJS({
30571
30571
  if (typeof unlimited !== "boolean") throw new Error("Warning opts.unlimited must be a boolean");
30572
30572
  code = code.toUpperCase();
30573
30573
  let warningContainer = {
30574
- [name]: function(a, b, c) {
30574
+ [name]: function(a, b2, c) {
30575
30575
  if (warning.emitted === true && warning.unlimited !== true) {
30576
30576
  return;
30577
30577
  }
30578
30578
  warning.emitted = true;
30579
- process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
30579
+ process.emitWarning(warning.format(a, b2, c), warning.name, warning.code);
30580
30580
  }
30581
30581
  };
30582
30582
  if (unlimited) {
30583
30583
  warningContainer = {
30584
- [name]: function(a, b, c) {
30584
+ [name]: function(a, b2, c) {
30585
30585
  warning.emitted = true;
30586
- process.emitWarning(warning.format(a, b, c), warning.name, warning.code);
30586
+ process.emitWarning(warning.format(a, b2, c), warning.name, warning.code);
30587
30587
  }
30588
30588
  };
30589
30589
  }
@@ -30592,12 +30592,12 @@ var require_process_warning2 = __commonJS({
30592
30592
  warning.message = message;
30593
30593
  warning.unlimited = unlimited;
30594
30594
  warning.code = code;
30595
- warning.format = function(a, b, c) {
30595
+ warning.format = function(a, b2, c) {
30596
30596
  let formatted;
30597
- if (a && b && c) {
30598
- formatted = format(message, a, b, c);
30599
- } else if (a && b) {
30600
- formatted = format(message, a, b);
30597
+ if (a && b2 && c) {
30598
+ formatted = format(message, a, b2, c);
30599
+ } else if (a && b2) {
30600
+ formatted = format(message, a, b2);
30601
30601
  } else if (a) {
30602
30602
  formatted = format(message, a);
30603
30603
  } else {
@@ -32538,7 +32538,7 @@ var require_fastify = __commonJS({
32538
32538
  listen,
32539
32539
  server,
32540
32540
  addresses: function() {
32541
- const binded = this[kServerBindings].map((b) => b.address());
32541
+ const binded = this[kServerBindings].map((b2) => b2.address());
32542
32542
  binded.push(this.server.address());
32543
32543
  return binded.filter((adr) => adr);
32544
32544
  },
@@ -38882,15 +38882,15 @@ var require_formdata = __commonJS({
38882
38882
  }
38883
38883
  }
38884
38884
  [nodeUtil.inspect.custom](depth, options) {
38885
- const state = this.#state.reduce((a, b) => {
38886
- if (a[b.name]) {
38887
- if (Array.isArray(a[b.name])) {
38888
- a[b.name].push(b.value);
38885
+ const state = this.#state.reduce((a, b2) => {
38886
+ if (a[b2.name]) {
38887
+ if (Array.isArray(a[b2.name])) {
38888
+ a[b2.name].push(b2.value);
38889
38889
  } else {
38890
- a[b.name] = [a[b.name], b.value];
38890
+ a[b2.name] = [a[b2.name], b2.value];
38891
38891
  }
38892
38892
  } else {
38893
- a[b.name] = b.value;
38893
+ a[b2.name] = b2.value;
38894
38894
  }
38895
38895
  return a;
38896
38896
  }, { __proto__: null });
@@ -42132,11 +42132,11 @@ var require_balanced_pool = __commonJS({
42132
42132
  var kWeight = Symbol("kWeight");
42133
42133
  var kMaxWeightPerServer = Symbol("kMaxWeightPerServer");
42134
42134
  var kErrorPenalty = Symbol("kErrorPenalty");
42135
- function getGreatestCommonDivisor(a, b) {
42136
- if (a === 0) return b;
42137
- while (b !== 0) {
42138
- const t = b;
42139
- b = a % b;
42135
+ function getGreatestCommonDivisor(a, b2) {
42136
+ if (a === 0) return b2;
42137
+ while (b2 !== 0) {
42138
+ const t = b2;
42139
+ b2 = a % b2;
42140
42140
  a = t;
42141
42141
  }
42142
42142
  return a;
@@ -42217,7 +42217,7 @@ var require_balanced_pool = __commonJS({
42217
42217
  if (!dispatcher) {
42218
42218
  return;
42219
42219
  }
42220
- const allClientsBusy = this[kClients].map((pool) => pool[kNeedDrain]).reduce((a, b) => a && b, true);
42220
+ const allClientsBusy = this[kClients].map((pool) => pool[kNeedDrain]).reduce((a, b2) => a && b2, true);
42221
42221
  if (allClientsBusy) {
42222
42222
  return;
42223
42223
  }
@@ -47932,8 +47932,8 @@ var require_headers = __commonJS({
47932
47932
  }
47933
47933
  return headersList.sortedMap = headers;
47934
47934
  }
47935
- function compareHeaderName(a, b) {
47936
- return a[0] < b[0] ? -1 : 1;
47935
+ function compareHeaderName(a, b2) {
47936
+ return a[0] < b2[0] ? -1 : 1;
47937
47937
  }
47938
47938
  var HeadersList = class _HeadersList {
47939
47939
  /** @type {[string, string][]|null} */
@@ -54928,7 +54928,7 @@ var readConfigFile = async () => {
54928
54928
  return JSON.parse(config);
54929
54929
  } catch {
54930
54930
  const name = await question("Enter Provider Name: ");
54931
- const apiKey = await question("Enter Provider API KEY: ");
54931
+ const APIKEY = await question("Enter Provider API KEY: ");
54932
54932
  const baseUrl = await question("Enter Provider URL: ");
54933
54933
  const model = await question("Enter MODEL Name: ");
54934
54934
  const config = Object.assign({}, DEFAULT_CONFIG, {
@@ -54936,7 +54936,7 @@ var readConfigFile = async () => {
54936
54936
  {
54937
54937
  name,
54938
54938
  api_base_url: baseUrl,
54939
- api_key: apiKey,
54939
+ api_key: APIKEY,
54940
54940
  models: [model]
54941
54941
  }
54942
54942
  ],
@@ -54958,7 +54958,7 @@ var initConfig = async () => {
54958
54958
  return config;
54959
54959
  };
54960
54960
 
54961
- // node_modules/.pnpm/@musistudio+llms@1.0.6_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54961
+ // node_modules/.pnpm/@musistudio+llms@1.0.8_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54962
54962
  var import_fastify = __toESM(require_fastify(), 1);
54963
54963
  var import_cors = __toESM(require_cors(), 1);
54964
54964
  var import_fs = require("fs");
@@ -54966,19 +54966,21 @@ var import_path = require("path");
54966
54966
  var import_dotenv = __toESM(require_main(), 1);
54967
54967
  var import_node_fs = __toESM(require("node:fs"), 1);
54968
54968
  var import_undici = __toESM(require_undici(), 1);
54969
+ var import_crypto = require("crypto");
54970
+ var import_crypto2 = require("crypto");
54969
54971
  var import_node_module = __toESM(require("node:module"), 1);
54970
- var W = ((a) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(a, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : a)(function(a) {
54972
+ var Z = ((s) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(s, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : s)(function(s) {
54971
54973
  if (typeof require < "u") return require.apply(this, arguments);
54972
- throw Error('Dynamic require of "' + a + '" is not supported');
54974
+ throw Error('Dynamic require of "' + s + '" is not supported');
54973
54975
  });
54974
- var N = class {
54976
+ var $ = class {
54975
54977
  config = {};
54976
54978
  options;
54977
54979
  constructor(e = { jsonPath: "./config.json" }) {
54978
54980
  this.options = { envPath: e.envPath || ".env", jsonPath: e.jsonPath, useEnvFile: false, useJsonFile: e.useJsonFile !== false, useEnvironmentVariables: e.useEnvironmentVariables !== false, ...e }, this.loadConfig();
54979
54981
  }
54980
54982
  loadConfig() {
54981
- this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
54983
+ this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
54982
54984
  }
54983
54985
  loadJsonConfig() {
54984
54986
  if (!this.options.jsonPath) return;
@@ -55035,85 +55037,85 @@ var N = class {
55035
55037
  return this.options.initialConfig && e.push("Initial Config"), this.options.useJsonFile && this.options.jsonPath && e.push(`JSON: ${this.options.jsonPath}`), this.options.useEnvFile && e.push(`ENV: ${this.options.envPath}`), this.options.useEnvironmentVariables && e.push("Environment Variables"), `Config sources: ${e.join(", ")}`;
55036
55038
  }
55037
55039
  };
55038
- function h(...a) {
55039
- if (console.log(...a), !(process.env.LOG === "true")) return;
55040
- let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(a) ? a.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
55041
- `, o = process.env.LOG_FILE || "app.log";
55042
- import_node_fs.default.appendFileSync(o, n, "utf8");
55040
+ function C(...s) {
55041
+ if (console.log(...s), !(process.env.LOG === "true")) return;
55042
+ let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((o) => typeof o == "object" ? JSON.stringify(o) : String(o)).join(" ") : ""}
55043
+ `, r = process.env.LOG_FILE || "app.log";
55044
+ import_node_fs.default.appendFileSync(r, n, "utf8");
55043
55045
  }
55044
- function L(a, e = 500, t = "internal_error", n = "api_error") {
55045
- let o = new Error(a);
55046
- return o.statusCode = e, o.code = t, o.type = n, o;
55046
+ function L(s, e = 500, t = "internal_error", n = "api_error") {
55047
+ let r = new Error(s);
55048
+ return r.statusCode = e, r.code = t, r.type = n, r;
55047
55049
  }
55048
- async function Z(a, e, t) {
55049
- e.log.error(a);
55050
- let n = a.statusCode || 500, o = { error: { message: a.message || "Internal Server Error", type: a.type || "api_error", code: a.code || "internal_error" } };
55051
- return t.code(n).send(o);
55050
+ async function le(s, e, t) {
55051
+ e.log.error(s);
55052
+ let n = s.statusCode || 500, r = { error: { message: s.message || "Internal Server Error", type: s.type || "api_error", code: s.code || "internal_error" } };
55053
+ return t.code(n).send(r);
55052
55054
  }
55053
- function ee(a, e, t) {
55055
+ function de(s, e, t) {
55054
55056
  let n = new Headers({ "Content-Type": "application/json" });
55055
- t.headers && Object.entries(t.headers).forEach(([d, u]) => {
55056
- n.set(d, u);
55057
+ t.headers && Object.entries(t.headers).forEach(([d, c]) => {
55058
+ n.set(d, c);
55057
55059
  });
55058
- let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55060
+ let r, o = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55059
55061
  if (t.signal) {
55060
- let d = new AbortController(), u = () => d.abort();
55061
- t.signal.addEventListener("abort", u), r.addEventListener("abort", u), o = d.signal;
55062
- } else o = r;
55063
- let l = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
55064
- return t.httpsProxy && (l.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), h("final request:", typeof a == "string" ? a : a.toString(), t.httpsProxy, l), fetch(typeof a == "string" ? a : a.toString(), l);
55062
+ let d = new AbortController(), c = () => d.abort();
55063
+ t.signal.addEventListener("abort", c), o.addEventListener("abort", c), r = d.signal;
55064
+ } else r = o;
55065
+ let l = { method: "POST", headers: n, body: JSON.stringify(e), signal: r };
55066
+ return t.httpsProxy && (l.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), C("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, l), fetch(typeof s == "string" ? s : s.toString(), l);
55065
55067
  }
55066
- var te = async (a) => {
55067
- a.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), a.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
55068
- let e = a._server.transformerService.getTransformersWithEndpoint();
55069
- for (let { name: t, transformer: n } of e) n.endPoint && a.post(n.endPoint, async (o, r) => {
55070
- let l = o.body, d = o.provider, u = a._server.providerService.getProvider(d);
55071
- if (!u) throw L(`Provider '${d}' not found`, 404, "provider_not_found");
55072
- let i = l, c = {};
55068
+ var fe = async (s) => {
55069
+ s.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), s.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
55070
+ let e = s._server.transformerService.getTransformersWithEndpoint();
55071
+ for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (r, o) => {
55072
+ let l = r.body, d = r.provider, c = s._server.providerService.getProvider(d);
55073
+ if (!c) throw L(`Provider '${d}' not found`, 404, "provider_not_found");
55074
+ let a = l, u = {};
55073
55075
  if (typeof n.transformRequestOut == "function") {
55074
- let s = await n.transformRequestOut(l);
55075
- s.body ? (i = s.body, c = s.config || {}) : i = s;
55076
- }
55077
- if (h("use transformers:", u.transformer?.use), u.transformer?.use?.length) for (let s of u.transformer.use) {
55078
- if (!s || typeof s.transformRequestIn != "function") continue;
55079
- let y = await s.transformRequestIn(i, u);
55080
- y.body ? (i = y.body, c = { ...c, ...y.config }) : i = y;
55081
- }
55082
- if (u.transformer?.[o.body.model]?.use?.length) for (let s of u.transformer[o.body.model].use) !s || typeof s.transformRequestIn != "function" || (i = await s.transformRequestIn(i, u));
55083
- let k = c.url || new URL(u.baseUrl), v = await ee(k, i, { httpsProxy: a._server.configService.getHttpsProxy(), ...c, headers: { Authorization: `Bearer ${u.apiKey}`, ...c?.headers || {} } });
55084
- if (!v.ok) {
55085
- let s = await v.text();
55086
- throw h(`Error response from ${k}: ${s}`), L(`Error from provider: ${s}`, v.status, "provider_response_error");
55087
- }
55088
- let m = v;
55089
- if (u.transformer?.use?.length) for (let s of u.transformer.use) !s || typeof s.transformResponseOut != "function" || (m = await s.transformResponseOut(m));
55090
- if (u.transformer?.[o.body.model]?.use?.length) for (let s of u.transformer[o.body.model].use) !s || typeof s.transformResponseOut != "function" || (m = await s.transformResponseOut(m));
55091
- return n.transformResponseIn && (m = await n.transformResponseIn(m)), m.ok || r.code(m.status), l?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(m.body)) : m.json();
55076
+ let i = await n.transformRequestOut(l);
55077
+ i.body ? (a = i.body, u = i.config || {}) : a = i;
55078
+ }
55079
+ if (C("use transformers:", c.transformer?.use), c.transformer?.use?.length) for (let i of c.transformer.use) {
55080
+ if (!i || typeof i.transformRequestIn != "function") continue;
55081
+ let v = await i.transformRequestIn(a, c);
55082
+ v.body ? (a = v.body, u = { ...u, ...v.config }) : a = v;
55083
+ }
55084
+ if (c.transformer?.[r.body.model]?.use?.length) for (let i of c.transformer[r.body.model].use) !i || typeof i.transformRequestIn != "function" || (a = await i.transformRequestIn(a, c));
55085
+ let y = u.url || new URL(c.baseUrl), k = await de(y, a, { httpsProxy: s._server.configService.getHttpsProxy(), ...u, headers: { Authorization: `Bearer ${c.apiKey}`, ...u?.headers || {} } });
55086
+ if (!k.ok) {
55087
+ let i = await k.text();
55088
+ throw C(`Error response from ${y}: ${i}`), L(`Error from provider: ${i}`, k.status, "provider_response_error");
55089
+ }
55090
+ let g = k;
55091
+ if (c.transformer?.use?.length) for (let i of c.transformer.use) !i || typeof i.transformResponseOut != "function" || (g = await i.transformResponseOut(g));
55092
+ if (c.transformer?.[r.body.model]?.use?.length) for (let i of c.transformer[r.body.model].use) !i || typeof i.transformResponseOut != "function" || (g = await i.transformResponseOut(g));
55093
+ return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status), l?.stream === true ? (o.header("Content-Type", "text/event-stream"), o.header("Cache-Control", "no-cache"), o.header("Connection", "keep-alive"), o.send(g.body)) : g.json();
55092
55094
  });
55093
- a.post("/providers", { schema: { body: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } } }, required: ["id", "name", "type", "baseUrl", "apiKey", "models"] } } }, async (t, n) => {
55094
- let { name: o, type: r, baseUrl: l, apiKey: d, models: u } = t.body;
55095
- if (!o?.trim()) throw L("Provider name is required", 400, "invalid_request");
55096
- if (!l || !de(l)) throw L("Valid base URL is required", 400, "invalid_request");
55095
+ s.post("/providers", { schema: { body: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } } }, required: ["id", "name", "type", "baseUrl", "apiKey", "models"] } } }, async (t, n) => {
55096
+ let { name: r, type: o, baseUrl: l, apiKey: d, models: c } = t.body;
55097
+ if (!r?.trim()) throw L("Provider name is required", 400, "invalid_request");
55098
+ if (!l || !ke(l)) throw L("Valid base URL is required", 400, "invalid_request");
55097
55099
  if (!d?.trim()) throw L("API key is required", 400, "invalid_request");
55098
- if (!u || !Array.isArray(u) || u.length === 0) throw L("At least one model is required", 400, "invalid_request");
55099
- if (a._server.providerService.getProvider(id)) throw L(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55100
- return a._server.providerService.registerProvider(t.body);
55101
- }), a.get("/providers", async (t, n) => a._server.providerService.getProviders()), a.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
55102
- let o = a._server.providerService.getProvider(t.params.id);
55103
- return o || n.code(404).send({ error: "Provider not found" });
55104
- }), a.put("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } }, enabled: { type: "boolean" } } } } }, async (t, n) => {
55105
- let o = a._server.providerService.updateProvider(t.params.id, t.body);
55106
- return o || n.code(404).send({ error: "Provider not found" });
55107
- }), a.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => a._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), a.patch("/providers/:id/toggle", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { enabled: { type: "boolean" } }, required: ["enabled"] } } }, async (t, n) => a._server.providerService.toggleProvider(t.params.id, t.body.enabled) ? { message: `Provider ${t.body.enabled ? "enabled" : "disabled"} successfully` } : n.code(404).send({ error: "Provider not found" }));
55100
+ if (!c || !Array.isArray(c) || c.length === 0) throw L("At least one model is required", 400, "invalid_request");
55101
+ if (s._server.providerService.getProvider(id)) throw L(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55102
+ return s._server.providerService.registerProvider(t.body);
55103
+ }), s.get("/providers", async (t, n) => s._server.providerService.getProviders()), s.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
55104
+ let r = s._server.providerService.getProvider(t.params.id);
55105
+ return r || n.code(404).send({ error: "Provider not found" });
55106
+ }), s.put("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } }, enabled: { type: "boolean" } } } } }, async (t, n) => {
55107
+ let r = s._server.providerService.updateProvider(t.params.id, t.body);
55108
+ return r || n.code(404).send({ error: "Provider not found" });
55109
+ }), s.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => s._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), s.patch("/providers/:id/toggle", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { enabled: { type: "boolean" } }, required: ["enabled"] } } }, async (t, n) => s._server.providerService.toggleProvider(t.params.id, t.body.enabled) ? { message: `Provider ${t.body.enabled ? "enabled" : "disabled"} successfully` } : n.code(404).send({ error: "Provider not found" }));
55108
55110
  };
55109
- function de(a) {
55111
+ function ke(s) {
55110
55112
  try {
55111
- return new URL(a), true;
55113
+ return new URL(s), true;
55112
55114
  } catch {
55113
55115
  return false;
55114
55116
  }
55115
55117
  }
55116
- var $ = class {
55118
+ var q = class {
55117
55119
  constructor(e) {
55118
55120
  this.providerService = e;
55119
55121
  }
@@ -55170,31 +55172,31 @@ var F = class {
55170
55172
  try {
55171
55173
  if (!t.name || !t.api_base_url || !t.api_key) return;
55172
55174
  let n = {};
55173
- t.transformer && Object.keys(t.transformer).forEach((o) => {
55174
- o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
55175
- if (Array.isArray(r) && typeof r[0] == "string") {
55176
- let l = this.transformerService.getTransformer(r[0]);
55177
- if (l) return new l(r[1]);
55178
- }
55179
- if (typeof r == "string") return this.transformerService.getTransformer(r);
55180
- }).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
55181
- if (Array.isArray(r) && typeof r[0] == "string") {
55182
- let l = this.transformerService.getTransformer(r[0]);
55183
- if (l) return new l(r[1]);
55184
- }
55185
- if (typeof r == "string") return this.transformerService.getTransformer(r);
55186
- }).filter((r) => typeof r < "u") });
55187
- }), console.log("providerConfig: ", t.name, n.use), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), h(`${t.name} provider registered`);
55175
+ t.transformer && Object.keys(t.transformer).forEach((r) => {
55176
+ r === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((o) => {
55177
+ if (Array.isArray(o) && typeof o[0] == "string") {
55178
+ let l = this.transformerService.getTransformer(o[0]);
55179
+ if (l) return new l(o[1]);
55180
+ }
55181
+ if (typeof o == "string") return this.transformerService.getTransformer(o);
55182
+ }).filter((o) => typeof o < "u")) : Array.isArray(t.transformer[r]?.use) && (n[r] = { use: t.transformer[r].use.map((o) => {
55183
+ if (Array.isArray(o) && typeof o[0] == "string") {
55184
+ let l = this.transformerService.getTransformer(o[0]);
55185
+ if (l) return new l(o[1]);
55186
+ }
55187
+ if (typeof o == "string") return this.transformerService.getTransformer(o);
55188
+ }).filter((o) => typeof o < "u") });
55189
+ }), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), C(`${t.name} provider registered`);
55188
55190
  } catch (n) {
55189
- h(`${t.name} provider registered error: ${n}`);
55191
+ C(`${t.name} provider registered error: ${n}`);
55190
55192
  }
55191
55193
  });
55192
55194
  }
55193
55195
  registerProvider(e) {
55194
55196
  let t = { ...e };
55195
55197
  return this.providers.set(t.name, t), e.models.forEach((n) => {
55196
- let o = `${t.name},${n}`, r = { provider: t.name, model: n, fullModel: o };
55197
- this.modelRoutes.set(o, r), this.modelRoutes.has(n) || this.modelRoutes.set(n, r);
55198
+ let r = `${t.name},${n}`, o = { provider: t.name, model: n, fullModel: r };
55199
+ this.modelRoutes.set(r, o), this.modelRoutes.has(n) || this.modelRoutes.set(n, o);
55198
55200
  }), t;
55199
55201
  }
55200
55202
  getProviders() {
@@ -55206,20 +55208,20 @@ var F = class {
55206
55208
  updateProvider(e, t) {
55207
55209
  let n = this.providers.get(e);
55208
55210
  if (!n) return null;
55209
- let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
55210
- return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
55211
- let l = `${n.id},${r}`;
55212
- this.modelRoutes.delete(l), this.modelRoutes.delete(r);
55213
- }), t.models.forEach((r) => {
55214
- let l = `${n.name},${r}`, d = { provider: n.name, model: r, fullModel: l };
55215
- this.modelRoutes.set(l, d), this.modelRoutes.has(r) || this.modelRoutes.set(r, d);
55216
- })), o;
55211
+ let r = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
55212
+ return this.providers.set(e, r), t.models && (n.models.forEach((o) => {
55213
+ let l = `${n.id},${o}`;
55214
+ this.modelRoutes.delete(l), this.modelRoutes.delete(o);
55215
+ }), t.models.forEach((o) => {
55216
+ let l = `${n.name},${o}`, d = { provider: n.name, model: o, fullModel: l };
55217
+ this.modelRoutes.set(l, d), this.modelRoutes.has(o) || this.modelRoutes.set(o, d);
55218
+ })), r;
55217
55219
  }
55218
55220
  deleteProvider(e) {
55219
55221
  let t = this.providers.get(e);
55220
55222
  return t ? (t.models.forEach((n) => {
55221
- let o = `${t.name},${n}`;
55222
- this.modelRoutes.delete(o), this.modelRoutes.delete(n);
55223
+ let r = `${t.name},${n}`;
55224
+ this.modelRoutes.delete(r), this.modelRoutes.delete(n);
55223
55225
  }), this.providers.delete(e), true) : false;
55224
55226
  }
55225
55227
  toggleProvider(e, t) {
@@ -55245,8 +55247,8 @@ var F = class {
55245
55247
  parseTransformerConfig(e) {
55246
55248
  return e ? Array.isArray(e) ? e.reduce((t, n) => {
55247
55249
  if (Array.isArray(n)) {
55248
- let [o, r = {}] = n;
55249
- t[o] = r;
55250
+ let [r, o = {}] = n;
55251
+ t[r] = o;
55250
55252
  } else t[n] = {};
55251
55253
  return t;
55252
55254
  }, {}) : e : {};
@@ -55260,37 +55262,38 @@ var F = class {
55260
55262
  }), { object: "list", data: e };
55261
55263
  }
55262
55264
  };
55263
- var I = class {
55265
+ var U = class {
55264
55266
  name = "Anthropic";
55265
55267
  endPoint = "/v1/messages";
55266
55268
  transformRequestOut(e) {
55267
- h("Anthropic Request:", JSON.stringify(e, null, 2));
55269
+ C("Anthropic Request:", JSON.stringify(e, null, 2));
55268
55270
  let t = [];
55269
55271
  if (e.system) {
55270
55272
  if (typeof e.system == "string") t.push({ role: "system", content: e.system });
55271
55273
  else if (Array.isArray(e.system)) {
55272
- let r = e.system.filter((l) => l.type === "text" && l.text).map((l) => ({ type: "text", text: l.text, cache_control: l.cache_control }));
55273
- t.push({ role: "system", content: r });
55274
- }
55275
- }
55276
- return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, l) => {
55277
- if (r.role === "user" || r.role === "assistant") {
55278
- let d = { role: r.role, content: null };
55279
- if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
55280
- else if (Array.isArray(r.content)) {
55281
- if (r.role === "user") {
55282
- let u = r.content.filter((c) => c.type === "tool_result" && c.tool_use_id);
55283
- u.length && u.forEach((c, k) => {
55284
- let v = { role: "tool", content: typeof c.content == "string" ? c.content : JSON.stringify(c.content), tool_call_id: c.tool_use_id, cache_control: c.cache_control };
55285
- t.push(v);
55274
+ let o = e.system.filter((l) => l.type === "text" && l.text).map((l) => ({ type: "text", text: l.text, cache_control: l.cache_control }));
55275
+ t.push({ role: "system", content: o });
55276
+ }
55277
+ }
55278
+ return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o, l) => {
55279
+ if (o.role === "user" || o.role === "assistant") {
55280
+ let d = { role: o.role, content: null };
55281
+ if (typeof o.content == "string") t.push({ role: o.role, content: o.content });
55282
+ else if (Array.isArray(o.content)) {
55283
+ if (o.role === "user") {
55284
+ let c = o.content.filter((u) => u.type === "tool_result" && u.tool_use_id);
55285
+ c.length && c.forEach((u, y) => {
55286
+ let k = { role: "tool", content: typeof u.content == "string" ? u.content : JSON.stringify(u.content), tool_call_id: u.tool_use_id, cache_control: u.cache_control };
55287
+ t.push(k);
55286
55288
  });
55287
- let i = r.content.filter((c) => c.type === "text" && c.text);
55288
- i.length && t.push({ role: "user", content: i });
55289
- } else if (r.role === "assistant") {
55290
- let u = r.content.filter((c) => c.type === "text" && c.text);
55291
- u.length && t.push(...u.map((c) => ({ role: "assistant", content: c.text })));
55292
- let i = r.content.filter((c) => c.type === "tool_use" && c.id);
55293
- i.length && t.push({ role: "assistant", content: null, tool_calls: i.map((c) => ({ id: c.id, type: "function", function: { name: c.name, arguments: JSON.stringify(c.input || {}) } })) });
55289
+ let a = o.content.filter((u) => u.type === "text" && u.text);
55290
+ a.length && t.push({ role: "user", content: a });
55291
+ } else if (o.role === "assistant") {
55292
+ let c = { role: "assistant", content: null }, a = o.content.filter((y) => y.type === "text" && y.text);
55293
+ a.length && (c.content = a.map((y) => y.text).join(`
55294
+ `));
55295
+ let u = o.content.filter((y) => y.type === "tool_use" && y.id);
55296
+ u.length && (c.tool_calls = u.map((y) => ({ id: y.id, type: "function", function: { name: y.name, arguments: JSON.stringify(y.input || {}) } }))), t.push(c);
55294
55297
  }
55295
55298
  return;
55296
55299
  }
@@ -55303,8 +55306,8 @@ var I = class {
55303
55306
  let n = await this.convertOpenAIStreamToAnthropic(e.body);
55304
55307
  return new Response(n, { headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55305
55308
  } else {
55306
- let n = await e.json(), o = this.convertOpenAIResponseToAnthropic(n);
55307
- return new Response(JSON.stringify(o), { headers: { "Content-Type": "application/json" } });
55309
+ let n = await e.json(), r = this.convertOpenAIResponseToAnthropic(n);
55310
+ return new Response(JSON.stringify(r), { headers: { "Content-Type": "application/json" } });
55308
55311
  }
55309
55312
  }
55310
55313
  convertAnthropicToolsToUnified(e) {
@@ -55312,280 +55315,297 @@ var I = class {
55312
55315
  }
55313
55316
  async convertOpenAIStreamToAnthropic(e) {
55314
55317
  return new ReadableStream({ async start(n) {
55315
- let o = new TextEncoder(), r = `msg_${Date.now()}`, l = "unknown", d = false, u = false, i = false, c = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), v = 0, m = 0, f = 0, s = false, y = false, g = 0, p = (_) => {
55316
- if (!s) try {
55317
- n.enqueue(_);
55318
- let R = new TextDecoder().decode(_);
55319
- h("send data:", R.trim());
55318
+ let r = new TextEncoder(), o = `msg_${Date.now()}`, l = "unknown", d = false, c = false, a = false, u = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), k = 0, g = 0, f = 0, i = false, v = false, h = 0, p = (x) => {
55319
+ if (!i) try {
55320
+ n.enqueue(x);
55321
+ let R = new TextDecoder().decode(x);
55322
+ C("send data:", R.trim());
55320
55323
  } catch (R) {
55321
- if (R instanceof TypeError && R.message.includes("Controller is already closed")) s = true;
55322
- else throw h(`send data error: ${R.message}`), R;
55324
+ if (R instanceof TypeError && R.message.includes("Controller is already closed")) i = true;
55325
+ else throw C(`send data error: ${R.message}`), R;
55323
55326
  }
55324
- }, S = () => {
55325
- if (!s) try {
55326
- n.close(), s = true;
55327
- } catch (_) {
55328
- if (_ instanceof TypeError && _.message.includes("Controller is already closed")) s = true;
55329
- else throw _;
55327
+ }, m = () => {
55328
+ if (!i) try {
55329
+ n.close(), i = true;
55330
+ } catch (x) {
55331
+ if (x instanceof TypeError && x.message.includes("Controller is already closed")) i = true;
55332
+ else throw x;
55330
55333
  }
55331
- }, P = null;
55334
+ }, T = null;
55332
55335
  try {
55333
- P = e.getReader();
55334
- let _ = new TextDecoder(), R = "";
55335
- for (; !s; ) {
55336
- let { done: oe, value: re } = await P.read();
55337
- if (oe) break;
55338
- R += _.decode(re, { stream: true });
55339
- let K = R.split(`
55336
+ T = e.getReader();
55337
+ let x = new TextDecoder(), R = "";
55338
+ for (; !i; ) {
55339
+ let { done: X, value: me } = await T.read();
55340
+ if (X) break;
55341
+ R += x.decode(me, { stream: true });
55342
+ let se = R.split(`
55340
55343
  `);
55341
- R = K.pop() || "";
55342
- for (let Y of K) {
55343
- if (s || i) break;
55344
- if (!Y.startsWith("data: ")) continue;
55345
- let z = Y.slice(6);
55346
- if (z !== "[DONE]") try {
55347
- let w = JSON.parse(z);
55348
- if (v++, h("Original Response:", JSON.stringify(w, null, 2)), l = w.model || l, !d && !s && !i) {
55344
+ R = se.pop() || "";
55345
+ for (let ie of se) {
55346
+ if (i || a) break;
55347
+ if (!ie.startsWith("data: ")) continue;
55348
+ let Q = ie.slice(6);
55349
+ if (Q !== "[DONE]") try {
55350
+ let O = JSON.parse(Q);
55351
+ if (k++, C("Original Response:", JSON.stringify(O, null, 2)), O.error) {
55352
+ let _ = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
55353
+ p(r.encode(`event: error
55354
+ data: ${JSON.stringify(_)}
55355
+
55356
+ `));
55357
+ continue;
55358
+ }
55359
+ if (l = O.model || l, !d && !i && !a) {
55349
55360
  d = true;
55350
- let b = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: l, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55351
- p(o.encode(`event: message_start
55352
- data: ${JSON.stringify(b)}
55361
+ let _ = { type: "message_start", message: { id: o, type: "message", role: "assistant", content: [], model: l, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55362
+ p(r.encode(`event: message_start
55363
+ data: ${JSON.stringify(_)}
55353
55364
 
55354
55365
  `));
55355
55366
  }
55356
- let T = w.choices?.[0];
55357
- if (!T) continue;
55358
- if (T?.delta?.thinking && !s && !i) {
55359
- if (!y) {
55360
- let b = { type: "content_block_start", index: g, content_block: { type: "thinking", thinking: "" } };
55361
- p(o.encode(`event: content_block_start
55362
- data: ${JSON.stringify(b)}
55363
-
55364
- `)), y = true;
55367
+ let w = O.choices?.[0];
55368
+ if (!w) continue;
55369
+ if (w?.delta?.thinking && !i && !a) {
55370
+ if (!v) {
55371
+ let _ = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
55372
+ p(r.encode(`event: content_block_start
55373
+ data: ${JSON.stringify(_)}
55374
+
55375
+ `)), v = true;
55365
55376
  }
55366
- if (T.delta.thinking.signature) {
55367
- let b = { type: "content_block_delta", index: g, delta: { type: "signature_delta", signature: T.delta.thinking.signature } };
55368
- p(o.encode(`event: content_block_delta
55369
- data: ${JSON.stringify(b)}
55377
+ if (w.delta.thinking.signature) {
55378
+ let _ = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
55379
+ p(r.encode(`event: content_block_delta
55380
+ data: ${JSON.stringify(_)}
55370
55381
 
55371
55382
  `));
55372
- let C = { type: "content_block_stop", index: g };
55373
- p(o.encode(`event: content_block_stop
55374
- data: ${JSON.stringify(C)}
55383
+ let S = { type: "content_block_stop", index: h };
55384
+ p(r.encode(`event: content_block_stop
55385
+ data: ${JSON.stringify(S)}
55375
55386
 
55376
- `)), g++;
55377
- } else if (T.delta.thinking.content) {
55378
- let b = { type: "content_block_delta", index: g, delta: { type: "thinking_delta", thinking: T.delta.thinking.content || "" } };
55379
- p(o.encode(`event: content_block_delta
55380
- data: ${JSON.stringify(b)}
55387
+ `)), h++;
55388
+ } else if (w.delta.thinking.content) {
55389
+ let _ = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
55390
+ p(r.encode(`event: content_block_delta
55391
+ data: ${JSON.stringify(_)}
55381
55392
 
55382
55393
  `));
55383
55394
  }
55384
55395
  }
55385
- if (T?.delta?.content && !s && !i) {
55386
- if (m++, !u && !i) {
55387
- u = true;
55388
- let b = { type: "content_block_start", index: g, content_block: { type: "text", text: "" } };
55389
- p(o.encode(`event: content_block_start
55390
- data: ${JSON.stringify(b)}
55396
+ if (w?.delta?.content && !i && !a) {
55397
+ if (g++, !c && !a) {
55398
+ c = true;
55399
+ let _ = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
55400
+ p(r.encode(`event: content_block_start
55401
+ data: ${JSON.stringify(_)}
55391
55402
 
55392
55403
  `));
55393
55404
  }
55394
- if (!s && !i) {
55395
- let b = { type: "content_block_delta", index: g, delta: { type: "text_delta", text: T.delta.content } };
55396
- p(o.encode(`event: content_block_delta
55397
- data: ${JSON.stringify(b)}
55405
+ if (!i && !a) {
55406
+ let _ = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
55407
+ p(r.encode(`event: content_block_delta
55408
+ data: ${JSON.stringify(_)}
55398
55409
 
55399
55410
  `));
55400
55411
  }
55401
55412
  }
55402
- if (T?.delta?.tool_calls && !s && !i) {
55413
+ if (w?.delta?.tool_calls && !i && !a) {
55403
55414
  f++;
55404
- let b = /* @__PURE__ */ new Set();
55405
- for (let C of T.delta.tool_calls) {
55406
- if (s) break;
55407
- let x = C.index ?? 0;
55408
- if (b.has(x)) continue;
55409
- if (b.add(x), !k.has(x)) {
55410
- let O = u ? k.size + 1 : k.size;
55411
- if (O !== 0) {
55412
- h("content_block_stop2");
55413
- let se = { type: "content_block_stop", index: g };
55414
- p(o.encode(`event: content_block_stop
55415
- data: ${JSON.stringify(se)}
55416
-
55417
- `)), g++;
55415
+ let _ = /* @__PURE__ */ new Set();
55416
+ for (let S of w.delta.tool_calls) {
55417
+ if (i) break;
55418
+ let P = S.index ?? 0;
55419
+ if (_.has(P)) continue;
55420
+ if (_.add(P), !y.has(P)) {
55421
+ let E = c ? y.size + 1 : y.size;
55422
+ if (E !== 0) {
55423
+ C("content_block_stop2");
55424
+ let he = { type: "content_block_stop", index: h };
55425
+ p(r.encode(`event: content_block_stop
55426
+ data: ${JSON.stringify(he)}
55427
+
55428
+ `)), h++;
55418
55429
  }
55419
- k.set(x, O);
55420
- let H = C.id || `call_${Date.now()}_${x}`, A = C.function?.name || `tool_${x}`, E = { type: "content_block_start", index: g, content_block: { type: "tool_use", id: H, name: A, input: {} } };
55421
- p(o.encode(`event: content_block_start
55422
- data: ${JSON.stringify(E)}
55430
+ y.set(P, E);
55431
+ let M = S.id || `call_${Date.now()}_${P}`, A = S.function?.name || `tool_${P}`, N = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: M, name: A, input: {} } };
55432
+ p(r.encode(`event: content_block_start
55433
+ data: ${JSON.stringify(N)}
55423
55434
 
55424
55435
  `));
55425
- let M = { id: H, name: A, arguments: "", contentBlockIndex: O };
55426
- c.set(x, M);
55427
- } else if (C.id && C.function?.name) {
55428
- let O = c.get(x);
55429
- O.id.startsWith("call_") && O.name.startsWith("tool_") && (O.id = C.id, O.name = C.function.name);
55436
+ let H = { id: M, name: A, arguments: "", contentBlockIndex: E };
55437
+ u.set(P, H);
55438
+ } else if (S.id && S.function?.name) {
55439
+ let E = u.get(P);
55440
+ E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = S.id, E.name = S.function.name);
55430
55441
  }
55431
- if (C.function?.arguments && !s && !i) {
55432
- if (k.get(x) === void 0) continue;
55433
- let H = c.get(x);
55434
- if (H) {
55435
- H.arguments += C.function.arguments;
55442
+ if (S.function?.arguments && !i && !a) {
55443
+ if (y.get(P) === void 0) continue;
55444
+ let M = u.get(P);
55445
+ if (M) {
55446
+ M.arguments += S.function.arguments;
55436
55447
  try {
55437
- let A = null, E = H.arguments.trim();
55438
- if (E.startsWith("{") && E.endsWith("}")) try {
55439
- A = JSON.parse(E);
55440
- } catch (M) {
55441
- h("Tool call index:", x, "error", M.message);
55448
+ let A = null, N = M.arguments.trim();
55449
+ if (N.startsWith("{") && N.endsWith("}")) try {
55450
+ A = JSON.parse(N);
55451
+ } catch (H) {
55452
+ C("Tool call index:", P, "error", H.message);
55442
55453
  }
55443
55454
  } catch (A) {
55444
- h("Tool call index:", x, "error", A.message);
55455
+ C("Tool call index:", P, "error", A.message);
55445
55456
  }
55446
55457
  }
55447
55458
  try {
55448
- let A = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: C.function.arguments } };
55449
- p(o.encode(`event: content_block_delta
55459
+ let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: S.function.arguments } };
55460
+ p(r.encode(`event: content_block_delta
55450
55461
  data: ${JSON.stringify(A)}
55451
55462
 
55452
55463
  `));
55453
55464
  } catch {
55454
55465
  try {
55455
- let E = C.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: g, delta: { type: "input_json_delta", partial_json: E } };
55456
- p(o.encode(`event: content_block_delta
55457
- data: ${JSON.stringify(M)}
55466
+ let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), H = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: N } };
55467
+ p(r.encode(`event: content_block_delta
55468
+ data: ${JSON.stringify(H)}
55458
55469
 
55459
55470
  `));
55460
- } catch (E) {
55461
- console.error(E);
55471
+ } catch (N) {
55472
+ console.error(N);
55462
55473
  }
55463
55474
  }
55464
55475
  }
55465
55476
  }
55466
55477
  }
55467
- if (T?.finish_reason && !s && !i) {
55468
- if (i = true, m === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (u || f > 0) && !s) {
55469
- h("content_block_stop hasTextContentStarted");
55470
- let b = { type: "content_block_stop", index: g };
55471
- p(o.encode(`event: content_block_stop
55472
- data: ${JSON.stringify(b)}
55478
+ if (w?.finish_reason && !i && !a) {
55479
+ if (a = true, g === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (c || f > 0) && !i) {
55480
+ C("content_block_stop hasTextContentStarted");
55481
+ let _ = { type: "content_block_stop", index: h };
55482
+ p(r.encode(`event: content_block_stop
55483
+ data: ${JSON.stringify(_)}
55473
55484
 
55474
55485
  `));
55475
55486
  }
55476
- if (!s) {
55477
- let x = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[T.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: w.usage?.prompt_tokens || 0, output_tokens: w.usage?.completion_tokens || 0 } };
55478
- p(o.encode(`event: message_delta
55479
- data: ${JSON.stringify(x)}
55487
+ if (!i) {
55488
+ let P = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[w.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: O.usage?.prompt_tokens || 0, output_tokens: O.usage?.completion_tokens || 0 } };
55489
+ p(r.encode(`event: message_delta
55490
+ data: ${JSON.stringify(P)}
55480
55491
 
55481
55492
  `));
55482
55493
  }
55483
- if (!s) {
55484
- let b = { type: "message_stop" };
55485
- p(o.encode(`event: message_stop
55486
- data: ${JSON.stringify(b)}
55494
+ if (!i) {
55495
+ let _ = { type: "message_stop" };
55496
+ p(r.encode(`event: message_stop
55497
+ data: ${JSON.stringify(_)}
55487
55498
 
55488
55499
  `));
55489
55500
  }
55490
55501
  break;
55491
55502
  }
55492
- } catch (w) {
55493
- h(`parseError: ${w.name} message: ${w.message} stack: ${w.stack} data: ${z}`);
55503
+ } catch (O) {
55504
+ C(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${Q}`);
55494
55505
  }
55495
55506
  }
55496
55507
  }
55497
- S();
55498
- } catch (_) {
55499
- if (!s) try {
55500
- n.error(_);
55508
+ m();
55509
+ } catch (x) {
55510
+ if (!i) try {
55511
+ n.error(x);
55501
55512
  } catch (R) {
55502
55513
  console.error(R);
55503
55514
  }
55504
55515
  } finally {
55505
- if (P) try {
55506
- P.releaseLock();
55507
- } catch (_) {
55508
- console.error(_);
55516
+ if (T) try {
55517
+ T.releaseLock();
55518
+ } catch (x) {
55519
+ console.error(x);
55509
55520
  }
55510
55521
  }
55511
55522
  }, cancel(n) {
55512
- h("cancle stream:", n);
55523
+ C("cancle stream:", n);
55513
55524
  } });
55514
55525
  }
55515
55526
  convertOpenAIResponseToAnthropic(e) {
55516
- h("Original OpenAI response:", JSON.stringify(e, null, 2));
55527
+ C("Original OpenAI response:", JSON.stringify(e, null, 2));
55517
55528
  let t = e.choices[0];
55518
55529
  if (!t) throw new Error("No choices found in OpenAI response");
55519
55530
  let n = [];
55520
- t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((r, l) => {
55531
+ t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((o, l) => {
55521
55532
  let d = {};
55522
55533
  try {
55523
- let u = r.function.arguments || "{}";
55524
- typeof u == "object" ? d = u : typeof u == "string" && (d = JSON.parse(u));
55534
+ let c = o.function.arguments || "{}";
55535
+ typeof c == "object" ? d = c : typeof c == "string" && (d = JSON.parse(c));
55525
55536
  } catch {
55526
- d = { text: r.function.arguments || "" };
55537
+ d = { text: o.function.arguments || "" };
55527
55538
  }
55528
- n.push({ type: "tool_use", id: r.id, name: r.function.name, input: d });
55539
+ n.push({ type: "tool_use", id: o.id, name: o.function.name, input: d });
55529
55540
  });
55530
- let o = { id: e.id, type: "message", role: "assistant", model: e.model, content: n, stop_reason: t.finish_reason === "stop" ? "end_turn" : t.finish_reason === "length" ? "max_tokens" : t.finish_reason === "tool_calls" ? "tool_use" : t.finish_reason === "content_filter" ? "stop_sequence" : "end_turn", stop_sequence: null, usage: { input_tokens: e.usage?.prompt_tokens || 0, output_tokens: e.usage?.completion_tokens || 0 } };
55531
- return h("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
55541
+ let r = { id: e.id, type: "message", role: "assistant", model: e.model, content: n, stop_reason: t.finish_reason === "stop" ? "end_turn" : t.finish_reason === "length" ? "max_tokens" : t.finish_reason === "tool_calls" ? "tool_use" : t.finish_reason === "content_filter" ? "stop_sequence" : "end_turn", stop_sequence: null, usage: { input_tokens: e.usage?.prompt_tokens || 0, output_tokens: e.usage?.completion_tokens || 0 } };
55542
+ return C("Conversion complete, final Anthropic response:", JSON.stringify(r, null, 2)), r;
55532
55543
  }
55533
55544
  };
55534
- var q = class {
55545
+ function ee(s) {
55546
+ if (!(!s || typeof s != "object")) {
55547
+ if (Array.isArray(s)) {
55548
+ s.forEach(ee);
55549
+ return;
55550
+ }
55551
+ delete s.$schema, delete s.additionalProperties, s.type === "string" && s.format && !["enum", "date-time"].includes(s.format) && delete s.format, Object.keys(s).forEach((e) => {
55552
+ ee(s[e]);
55553
+ });
55554
+ }
55555
+ }
55556
+ var J = class {
55535
55557
  name = "gemini";
55536
55558
  endPoint = "/v1beta/models/:modelAndAction";
55537
55559
  transformRequestIn(e, t) {
55538
55560
  return { body: { contents: e.messages.map((n) => {
55539
- let o;
55540
- n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
55541
- let r = [];
55542
- return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((l) => {
55561
+ let r;
55562
+ n.role === "assistant" ? r = "model" : (["user", "system", "tool"].includes(n.role), r = "user");
55563
+ let o = [];
55564
+ return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((l) => {
55543
55565
  if (l.type === "text") return { text: l.text || "" };
55544
- })), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((l) => ({ functionCall: { id: l.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: l.function.name, args: JSON.parse(l.function.arguments || "{}") } }))), { role: o, parts: r };
55545
- }), tools: [{ functionDeclarations: e.tools?.map((n) => (delete n.function.parameters?.$schema, delete n.function.parameters?.additionalProperties, n.function.parameters?.properties && Object.keys(n.function.parameters.properties).forEach((o) => {
55546
- delete n.function.parameters.properties[o].$schema, delete n.function.parameters.properties[o].additionalProperties, n.function.parameters.properties[o].items && typeof n.function.parameters.properties[o].items == "object" && (delete n.function.parameters.properties[o].items.$schema, delete n.function.parameters.properties[o].items.additionalProperties), n.function.parameters.properties[o].type === "string" && (["enum", "date-time"].includes(n.function.parameters.properties[o].format) || delete n.function.parameters.properties[o].format);
55547
- }), { name: n.function.name, description: n.function.description, parameters: n.function.parameters })) || [] }] }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
55566
+ })), Array.isArray(n.tool_calls) && o.push(...n.tool_calls.map((l) => ({ functionCall: { id: l.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: l.function.name, args: JSON.parse(l.function.arguments || "{}") } }))), { role: r, parts: o };
55567
+ }), tools: [{ functionDeclarations: e.tools?.map((n) => (n.function.parameters && ee(n.function.parameters), { name: n.function.name, description: n.function.description, parameters: n.function.parameters })) || [] }] }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
55548
55568
  }
55549
55569
  transformRequestOut(e) {
55550
- let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, l = e.temperature, d = e.stream, u = e.tool_choice, i = { messages: [], model: o, max_tokens: r, temperature: l, stream: d, tool_choice: u };
55551
- return Array.isArray(t) && t.forEach((c) => {
55552
- typeof c == "string" ? i.messages.push({ role: "user", content: c }) : typeof c.text == "string" ? i.messages.push({ role: "user", content: c.text || null }) : c.role === "user" ? i.messages.push({ role: "user", content: c?.parts?.map((k) => ({ type: "text", text: k.text || "" })) || [] }) : c.role === "model" && i.messages.push({ role: "assistant", content: c?.parts?.map((k) => ({ type: "text", text: k.text || "" })) || [] });
55553
- }), Array.isArray(n) && (i.tools = [], n.forEach((c) => {
55554
- Array.isArray(c.functionDeclarations) && c.functionDeclarations.forEach((k) => {
55555
- i.tools.push({ type: "function", function: { name: k.name, description: k.description, parameters: k.parameters } });
55570
+ let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens, l = e.temperature, d = e.stream, c = e.tool_choice, a = { messages: [], model: r, max_tokens: o, temperature: l, stream: d, tool_choice: c };
55571
+ return Array.isArray(t) && t.forEach((u) => {
55572
+ typeof u == "string" ? a.messages.push({ role: "user", content: u }) : typeof u.text == "string" ? a.messages.push({ role: "user", content: u.text || null }) : u.role === "user" ? a.messages.push({ role: "user", content: u?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] }) : u.role === "model" && a.messages.push({ role: "assistant", content: u?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] });
55573
+ }), Array.isArray(n) && (a.tools = [], n.forEach((u) => {
55574
+ Array.isArray(u.functionDeclarations) && u.functionDeclarations.forEach((y) => {
55575
+ a.tools.push({ type: "function", function: { name: y.name, description: y.description, parameters: y.parameters } });
55556
55576
  });
55557
- })), i;
55577
+ })), a;
55558
55578
  }
55559
55579
  async transformResponseOut(e) {
55560
55580
  if (e.headers.get("Content-Type")?.includes("application/json")) {
55561
- let t = await e.json(), n = t.candidates[0].content.parts.filter((r) => r.functionCall).map((r) => ({ id: r.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: r.functionCall?.name, arguments: JSON.stringify(r.functionCall?.args || {}) } })), o = { id: t.responseId, choices: [{ finish_reason: t.candidates[0].finishReason?.toLowerCase() || null, index: 0, message: { content: t.candidates[0].content.parts.filter((r) => r.text).map((r) => r.text).join(`
55581
+ let t = await e.json(), n = t.candidates[0].content.parts.filter((o) => o.functionCall).map((o) => ({ id: o.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: o.functionCall?.name, arguments: JSON.stringify(o.functionCall?.args || {}) } })), r = { id: t.responseId, choices: [{ finish_reason: t.candidates[0].finishReason?.toLowerCase() || null, index: 0, message: { content: t.candidates[0].content.parts.filter((o) => o.text).map((o) => o.text).join(`
55562
55582
  `), role: "assistant", tool_calls: n.length > 0 ? n : void 0 } }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), model: t.modelVersion, object: "chat.completion", usage: { completion_tokens: t.usageMetadata.candidatesTokenCount, prompt_tokens: t.usageMetadata.promptTokenCount, total_tokens: t.usageMetadata.totalTokenCount } };
55563
- return new Response(JSON.stringify(o), { status: e.status, statusText: e.statusText, headers: e.headers });
55583
+ return new Response(JSON.stringify(r), { status: e.status, statusText: e.statusText, headers: e.headers });
55564
55584
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55565
55585
  if (!e.body) return e;
55566
- let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
55586
+ let t = new TextDecoder(), n = new TextEncoder(), r = new ReadableStream({ async start(o) {
55567
55587
  let l = e.body.getReader();
55568
55588
  try {
55569
55589
  for (; ; ) {
55570
- let { done: d, value: u } = await l.read();
55590
+ let { done: d, value: c } = await l.read();
55571
55591
  if (d) break;
55572
- let i = t.decode(u, { stream: true });
55573
- if (i.startsWith("data: ")) i = i.slice(6).trim();
55592
+ let a = t.decode(c, { stream: true });
55593
+ if (a.startsWith("data: ")) a = a.slice(6).trim();
55574
55594
  else break;
55575
- h("gemini chunk:", i), i = JSON.parse(i);
55576
- let c = i.candidates[0].content.parts.filter((v) => v.functionCall).map((v) => ({ id: v.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: v.functionCall?.name, arguments: JSON.stringify(v.functionCall?.args || {}) } })), k = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((v) => v.text).map((v) => v.text).join(`
55577
- `), tool_calls: c.length > 0 ? c : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || c.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: i.responseId || "", model: i.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
55578
- h("gemini response:", JSON.stringify(k, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(k)}
55595
+ C("gemini chunk:", a), a = JSON.parse(a);
55596
+ let u = a.candidates[0].content.parts.filter((k) => k.functionCall).map((k) => ({ id: k.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: k.functionCall?.name, arguments: JSON.stringify(k.functionCall?.args || {}) } })), y = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((k) => k.text).map((k) => k.text).join(`
55597
+ `), tool_calls: u.length > 0 ? u : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || u.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: a.responseId || "", model: a.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
55598
+ C("gemini response:", JSON.stringify(y, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(y)}
55579
55599
 
55580
55600
  `));
55581
55601
  }
55582
55602
  } catch (d) {
55583
- r.error(d);
55603
+ o.error(d);
55584
55604
  } finally {
55585
- r.close();
55605
+ o.close();
55586
55606
  }
55587
55607
  } });
55588
- return new Response(o, { status: e.status, statusText: e.statusText, headers: e.headers });
55608
+ return new Response(r, { status: e.status, statusText: e.statusText, headers: e.headers });
55589
55609
  }
55590
55610
  return e;
55591
55611
  }
@@ -55601,56 +55621,56 @@ var j = class {
55601
55621
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55602
55622
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55603
55623
  if (!e.body) return e;
55604
- let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, l = new ReadableStream({ async start(d) {
55605
- let u = e.body.getReader();
55624
+ let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false, l = new ReadableStream({ async start(d) {
55625
+ let c = e.body.getReader();
55606
55626
  try {
55607
55627
  for (; ; ) {
55608
- let { done: i, value: c } = await u.read();
55609
- if (i) break;
55610
- let v = t.decode(c, { stream: true }).split(`
55628
+ let { done: a, value: u } = await c.read();
55629
+ if (a) break;
55630
+ let k = t.decode(u, { stream: true }).split(`
55611
55631
  `);
55612
- for (let m of v) if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") try {
55613
- let f = JSON.parse(m.slice(6));
55632
+ for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55633
+ let f = JSON.parse(g.slice(6));
55614
55634
  if (f.choices?.[0]?.delta?.reasoning_content) {
55615
- o += f.choices[0].delta.reasoning_content;
55616
- let s = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, thinking: { content: f.choices[0].delta.reasoning_content } } }] };
55617
- delete s.choices[0].delta.reasoning_content;
55618
- let y = `data: ${JSON.stringify(s)}
55635
+ r += f.choices[0].delta.reasoning_content;
55636
+ let i = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, thinking: { content: f.choices[0].delta.reasoning_content } } }] };
55637
+ delete i.choices[0].delta.reasoning_content;
55638
+ let v = `data: ${JSON.stringify(i)}
55619
55639
 
55620
55640
  `;
55621
- d.enqueue(n.encode(y));
55641
+ d.enqueue(n.encode(v));
55622
55642
  continue;
55623
55643
  }
55624
- if (f.choices?.[0]?.delta?.content && o && !r) {
55625
- r = true;
55626
- let s = Date.now().toString(), y = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: o, signature: s } } }] };
55627
- delete y.choices[0].delta.reasoning_content;
55628
- let g = `data: ${JSON.stringify(y)}
55644
+ if (f.choices?.[0]?.delta?.content && r && !o) {
55645
+ o = true;
55646
+ let i = Date.now().toString(), v = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: r, signature: i } } }] };
55647
+ delete v.choices[0].delta.reasoning_content;
55648
+ let h = `data: ${JSON.stringify(v)}
55629
55649
 
55630
55650
  `;
55631
- d.enqueue(n.encode(g));
55651
+ d.enqueue(n.encode(h));
55632
55652
  }
55633
55653
  if (f.choices[0]?.delta?.reasoning_content && delete f.choices[0].delta.reasoning_content, f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55634
- r && f.choices[0].index++;
55635
- let s = `data: ${JSON.stringify(f)}
55654
+ o && f.choices[0].index++;
55655
+ let i = `data: ${JSON.stringify(f)}
55636
55656
 
55637
55657
  `;
55638
- d.enqueue(n.encode(s));
55658
+ d.enqueue(n.encode(i));
55639
55659
  }
55640
55660
  } catch {
55641
- d.enqueue(n.encode(m + `
55661
+ d.enqueue(n.encode(g + `
55642
55662
  `));
55643
55663
  }
55644
- else d.enqueue(n.encode(m + `
55664
+ else d.enqueue(n.encode(g + `
55645
55665
  `));
55646
55666
  }
55647
- } catch (i) {
55648
- d.error(i);
55667
+ } catch (a) {
55668
+ d.error(a);
55649
55669
  } finally {
55650
55670
  try {
55651
- u.releaseLock();
55652
- } catch (i) {
55653
- console.error("Error releasing reader lock:", i);
55671
+ c.releaseLock();
55672
+ } catch (a) {
55673
+ console.error("Error releasing reader lock:", a);
55654
55674
  }
55655
55675
  d.close();
55656
55676
  }
@@ -55660,7 +55680,7 @@ var j = class {
55660
55680
  return e;
55661
55681
  }
55662
55682
  };
55663
- var J = class {
55683
+ var D = class {
55664
55684
  name = "tooluse";
55665
55685
  transformRequestIn(e) {
55666
55686
  return e.messages.push({ role: "system", content: "<system-reminder>Tool mode is active. The user expects you to proactively execute the most suitable tool to help complete the task. \nBefore invoking a tool, you must carefully evaluate whether it matches the current task. If no available tool is appropriate for the task, you MUST call the `ExitTool` to exit tool mode \u2014 this is the only valid way to terminate tool mode.\nAlways prioritize completing the user's task effectively and efficiently by using tools whenever appropriate.</system-reminder>" }), e.tools?.length && (e.tool_choice = "required", e.tools.unshift({ type: "function", function: { name: "ExitTool", description: `Use this tool when you are in tool mode and have completed the task. This is the only valid way to exit tool mode.
@@ -55673,61 +55693,61 @@ Examples:
55673
55693
  if (e.headers.get("Content-Type")?.includes("application/json")) {
55674
55694
  let t = await e.json();
55675
55695
  if (t?.choices[0]?.message.tool_calls?.length && t?.choices[0]?.message.tool_calls[0]?.function?.name === "ExitTool") {
55676
- let n = t?.choices[0]?.message.tool_calls[0], o = JSON.parse(n.function.arguments || "{}");
55677
- t.choices[0].message.content = o.response || "", delete t.choices[0].message.tool_calls;
55696
+ let n = t?.choices[0]?.message.tool_calls[0], r = JSON.parse(n.function.arguments || "{}");
55697
+ t.choices[0].message.content = r.response || "", delete t.choices[0].message.tool_calls;
55678
55698
  }
55679
55699
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55680
55700
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55681
55701
  if (!e.body) return e;
55682
- let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", l = new ReadableStream({ async start(d) {
55683
- let u = e.body.getReader();
55702
+ let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "", l = new ReadableStream({ async start(d) {
55703
+ let c = e.body.getReader();
55684
55704
  try {
55685
55705
  for (; ; ) {
55686
- let { done: i, value: c } = await u.read();
55687
- if (i) break;
55688
- let v = t.decode(c, { stream: true }).split(`
55706
+ let { done: a, value: u } = await c.read();
55707
+ if (a) break;
55708
+ let k = t.decode(u, { stream: true }).split(`
55689
55709
  `);
55690
- for (let m of v) if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") try {
55691
- let f = JSON.parse(m.slice(6));
55710
+ for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55711
+ let f = JSON.parse(g.slice(6));
55692
55712
  if (f.choices[0]?.delta?.tool_calls?.length) {
55693
- let s = f.choices[0].delta.tool_calls[0];
55694
- if (s.function?.name === "ExitTool") {
55695
- o = s.index;
55713
+ let i = f.choices[0].delta.tool_calls[0];
55714
+ if (i.function?.name === "ExitTool") {
55715
+ r = i.index;
55696
55716
  continue;
55697
- } else if (o > -1 && s.index === o && s.function.arguments) {
55698
- r += s.function.arguments;
55717
+ } else if (r > -1 && i.index === r && i.function.arguments) {
55718
+ o += i.function.arguments;
55699
55719
  try {
55700
- let y = JSON.parse(r);
55701
- f.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
55702
- let g = `data: ${JSON.stringify(f)}
55720
+ let v = JSON.parse(o);
55721
+ f.choices = [{ delta: { role: "assistant", content: v.response || "" } }];
55722
+ let h = `data: ${JSON.stringify(f)}
55703
55723
 
55704
55724
  `;
55705
- d.enqueue(n.encode(g));
55725
+ d.enqueue(n.encode(h));
55706
55726
  } catch {
55707
55727
  }
55708
55728
  continue;
55709
55729
  }
55710
55730
  }
55711
55731
  if (f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55712
- let s = `data: ${JSON.stringify(f)}
55732
+ let i = `data: ${JSON.stringify(f)}
55713
55733
 
55714
55734
  `;
55715
- d.enqueue(n.encode(s));
55735
+ d.enqueue(n.encode(i));
55716
55736
  }
55717
55737
  } catch {
55718
- d.enqueue(n.encode(m + `
55738
+ d.enqueue(n.encode(g + `
55719
55739
  `));
55720
55740
  }
55721
- else d.enqueue(n.encode(m + `
55741
+ else d.enqueue(n.encode(g + `
55722
55742
  `));
55723
55743
  }
55724
- } catch (i) {
55725
- d.error(i);
55744
+ } catch (a) {
55745
+ d.error(a);
55726
55746
  } finally {
55727
55747
  try {
55728
- u.releaseLock();
55729
- } catch (i) {
55730
- console.error("Error releasing reader lock:", i);
55748
+ c.releaseLock();
55749
+ } catch (a) {
55750
+ console.error("Error releasing reader lock:", a);
55731
55751
  }
55732
55752
  d.close();
55733
55753
  }
@@ -55737,7 +55757,31 @@ Examples:
55737
55757
  return e;
55738
55758
  }
55739
55759
  };
55740
- var U = class {
55760
+ var b = [];
55761
+ for (let s = 0; s < 256; ++s) b.push((s + 256).toString(16).slice(1));
55762
+ function ue(s, e = 0) {
55763
+ return (b[s[e + 0]] + b[s[e + 1]] + b[s[e + 2]] + b[s[e + 3]] + "-" + b[s[e + 4]] + b[s[e + 5]] + "-" + b[s[e + 6]] + b[s[e + 7]] + "-" + b[s[e + 8]] + b[s[e + 9]] + "-" + b[s[e + 10]] + b[s[e + 11]] + b[s[e + 12]] + b[s[e + 13]] + b[s[e + 14]] + b[s[e + 15]]).toLowerCase();
55764
+ }
55765
+ var z = new Uint8Array(256);
55766
+ var B = z.length;
55767
+ function te() {
55768
+ return B > z.length - 16 && ((0, import_crypto.randomFillSync)(z), B = 0), z.slice(B, B += 16);
55769
+ }
55770
+ var ne = { randomUUID: import_crypto2.randomUUID };
55771
+ function Re(s, e, t) {
55772
+ if (ne.randomUUID && !e && !s) return ne.randomUUID();
55773
+ s = s || {};
55774
+ let n = s.random ?? s.rng?.() ?? te();
55775
+ if (n.length < 16) throw new Error("Random bytes length must be >= 16");
55776
+ if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
55777
+ if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
55778
+ for (let r = 0; r < 16; ++r) e[t + r] = n[r];
55779
+ return e;
55780
+ }
55781
+ return ue(n);
55782
+ }
55783
+ var I = Re;
55784
+ var V = class {
55741
55785
  name = "openrouter";
55742
55786
  transformRequestIn(e) {
55743
55787
  return e.model.includes("claude") || e.messages.forEach((t) => {
@@ -55752,105 +55796,109 @@ var U = class {
55752
55796
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55753
55797
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55754
55798
  if (!e.body) return e;
55755
- let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", l = false, d = "", u = new ReadableStream({ async start(i) {
55756
- let c = e.body.getReader(), k = (m, f, s) => {
55757
- let y = m.split(`
55799
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", l = false, d = false, c = "", a = new ReadableStream({ async start(u) {
55800
+ let y = e.body.getReader(), k = (f, i, v) => {
55801
+ let h = f.split(`
55758
55802
  `);
55759
- for (let g of y) g.trim() && f.enqueue(s.encode(g + `
55803
+ for (let p of h) p.trim() && i.enqueue(v.encode(p + `
55760
55804
  `));
55761
- }, v = (m, f) => {
55762
- let { controller: s, encoder: y } = f;
55763
- if (m.startsWith("data: ") && m.trim() !== "data: [DONE]") {
55764
- let g = m.slice(6);
55805
+ }, g = (f, i) => {
55806
+ let { controller: v, encoder: h } = i;
55807
+ if (f.startsWith("data: ") && f.trim() !== "data: [DONE]") {
55808
+ let p = f.slice(6);
55765
55809
  try {
55766
- let p = JSON.parse(g);
55767
- if (p.choices?.[0]?.delta?.content && !f.hasTextContent() && f.setHasTextContent(true), p.choices?.[0]?.delta?.reasoning) {
55768
- f.appendReasoningContent(p.choices[0].delta.reasoning);
55769
- let P = { ...p, choices: [{ ...p.choices?.[0], delta: { ...p.choices[0].delta, thinking: { content: p.choices[0].delta.reasoning } } }] };
55770
- P.choices?.[0]?.delta && delete P.choices[0].delta.reasoning;
55771
- let _ = `data: ${JSON.stringify(P)}
55810
+ let m = JSON.parse(p);
55811
+ if (m.usage && (C("usage", m.usage, d), m.choices[0].finish_reason = d ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && v.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
55812
+
55813
+ `)), m.choices?.[0]?.delta?.content && !i.hasTextContent() && i.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
55814
+ i.appendReasoningContent(m.choices[0].delta.reasoning);
55815
+ let x = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning } } }] };
55816
+ x.choices?.[0]?.delta && delete x.choices[0].delta.reasoning;
55817
+ let R = `data: ${JSON.stringify(x)}
55772
55818
 
55773
55819
  `;
55774
- s.enqueue(y.encode(_));
55820
+ v.enqueue(h.encode(R));
55775
55821
  return;
55776
55822
  }
55777
- if (p.choices?.[0]?.delta?.content && f.reasoningContent() && !f.isReasoningComplete()) {
55778
- f.setReasoningComplete(true);
55779
- let P = Date.now().toString(), _ = { ...p, choices: [{ ...p.choices?.[0], delta: { ...p.choices[0].delta, content: null, thinking: { content: f.reasoningContent(), signature: P } } }] };
55780
- _.choices?.[0]?.delta && delete _.choices[0].delta.reasoning;
55781
- let R = `data: ${JSON.stringify(_)}
55823
+ if (m.choices?.[0]?.delta?.content && i.reasoningContent() && !i.isReasoningComplete()) {
55824
+ i.setReasoningComplete(true);
55825
+ let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: i.reasoningContent(), signature: x } } }] };
55826
+ R.choices?.[0]?.delta && delete R.choices[0].delta.reasoning;
55827
+ let X = `data: ${JSON.stringify(R)}
55782
55828
 
55783
55829
  `;
55784
- s.enqueue(y.encode(R));
55830
+ v.enqueue(h.encode(X));
55785
55831
  }
55786
- p.choices?.[0]?.delta?.reasoning && delete p.choices[0].delta.reasoning, p.choices?.[0]?.delta?.tool_calls?.length && f.hasTextContent() && (typeof p.choices[0].index == "number" ? p.choices[0].index += 1 : p.choices[0].index = 1);
55787
- let S = `data: ${JSON.stringify(p)}
55832
+ m.choices?.[0]?.delta?.reasoning && delete m.choices[0].delta.reasoning, m.choices?.[0]?.delta?.tool_calls?.length && !Number.isNaN(parseInt(m.choices?.[0]?.delta?.tool_calls[0].id, 10)) && m.choices?.[0]?.delta?.tool_calls.forEach((x) => {
55833
+ x.id = `call_${I()}`;
55834
+ }), m.choices?.[0]?.delta?.tool_calls?.length && !d && (C("hasToolCall", true), d = true), m.choices?.[0]?.delta?.tool_calls?.length && i.hasTextContent() && (typeof m.choices[0].index == "number" ? m.choices[0].index += 1 : m.choices[0].index = 1);
55835
+ let T = `data: ${JSON.stringify(m)}
55788
55836
 
55789
55837
  `;
55790
- s.enqueue(y.encode(S));
55838
+ v.enqueue(h.encode(T));
55791
55839
  } catch {
55792
- s.enqueue(y.encode(m + `
55840
+ v.enqueue(h.encode(f + `
55793
55841
  `));
55794
55842
  }
55795
- } else s.enqueue(y.encode(m + `
55843
+ } else v.enqueue(h.encode(f + `
55796
55844
  `));
55797
55845
  };
55798
55846
  try {
55799
55847
  for (; ; ) {
55800
- let { done: m, value: f } = await c.read();
55801
- if (m) {
55802
- d.trim() && k(d, i, n);
55848
+ let { done: f, value: i } = await y.read();
55849
+ if (f) {
55850
+ c.trim() && k(c, u, n);
55803
55851
  break;
55804
55852
  }
55805
- if (!f || f.length === 0) continue;
55806
- let s;
55853
+ if (!i || i.length === 0) continue;
55854
+ let v;
55807
55855
  try {
55808
- s = t.decode(f, { stream: true });
55809
- } catch (g) {
55810
- console.warn("Failed to decode chunk", g);
55856
+ v = t.decode(i, { stream: true });
55857
+ } catch (p) {
55858
+ console.warn("Failed to decode chunk", p);
55811
55859
  continue;
55812
55860
  }
55813
- if (s.length === 0) continue;
55814
- if (d += s, d.length > 1e6) {
55861
+ if (v.length === 0) continue;
55862
+ if (c += v, c.length > 1e6) {
55815
55863
  console.warn("Buffer size exceeds limit, processing partial data");
55816
- let g = d.split(`
55864
+ let p = c.split(`
55817
55865
  `);
55818
- d = g.pop() || "";
55819
- for (let p of g) if (p.trim()) try {
55820
- v(p, { controller: i, encoder: n, hasTextContent: () => o, setHasTextContent: (S) => o = S, reasoningContent: () => r, appendReasoningContent: (S) => r += S, isReasoningComplete: () => l, setReasoningComplete: (S) => l = S });
55821
- } catch (S) {
55822
- console.error("Error processing line:", p, S), i.enqueue(n.encode(p + `
55866
+ c = p.pop() || "";
55867
+ for (let m of p) if (m.trim()) try {
55868
+ g(m, { controller: u, encoder: n, hasTextContent: () => r, setHasTextContent: (T) => r = T, reasoningContent: () => o, appendReasoningContent: (T) => o += T, isReasoningComplete: () => l, setReasoningComplete: (T) => l = T });
55869
+ } catch (T) {
55870
+ console.error("Error processing line:", m, T), u.enqueue(n.encode(m + `
55823
55871
  `));
55824
55872
  }
55825
55873
  continue;
55826
55874
  }
55827
- let y = d.split(`
55875
+ let h = c.split(`
55828
55876
  `);
55829
- d = y.pop() || "";
55830
- for (let g of y) if (g.trim()) try {
55831
- v(g, { controller: i, encoder: n, hasTextContent: () => o, setHasTextContent: (p) => o = p, reasoningContent: () => r, appendReasoningContent: (p) => r += p, isReasoningComplete: () => l, setReasoningComplete: (p) => l = p });
55832
- } catch (p) {
55833
- console.error("Error processing line:", g, p), i.enqueue(n.encode(g + `
55877
+ c = h.pop() || "";
55878
+ for (let p of h) if (p.trim()) try {
55879
+ g(p, { controller: u, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => l, setReasoningComplete: (m) => l = m });
55880
+ } catch (m) {
55881
+ console.error("Error processing line:", p, m), u.enqueue(n.encode(p + `
55834
55882
  `));
55835
55883
  }
55836
55884
  }
55837
- } catch (m) {
55838
- console.error("Stream error:", m), i.error(m);
55885
+ } catch (f) {
55886
+ console.error("Stream error:", f), u.error(f);
55839
55887
  } finally {
55840
55888
  try {
55841
- c.releaseLock();
55842
- } catch (m) {
55843
- console.error("Error releasing reader lock:", m);
55889
+ y.releaseLock();
55890
+ } catch (f) {
55891
+ console.error("Error releasing reader lock:", f);
55844
55892
  }
55845
- i.close();
55893
+ u.close();
55846
55894
  }
55847
55895
  } });
55848
- return new Response(u, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55896
+ return new Response(a, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55849
55897
  }
55850
55898
  return e;
55851
55899
  }
55852
55900
  };
55853
- var D = class {
55901
+ var W = class {
55854
55902
  constructor(e) {
55855
55903
  this.options = e;
55856
55904
  this.max_tokens = this.options?.max_tokens;
@@ -55861,14 +55909,123 @@ var D = class {
55861
55909
  return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
55862
55910
  }
55863
55911
  };
55864
- var ne = { AnthropicTransformer: I, GeminiTransformer: q, DeepseekTransformer: j, TooluseTransformer: J, OpenrouterTransformer: U, MaxTokenTransformer: D };
55865
- var B = class {
55912
+ var G = class {
55913
+ name = "groq";
55914
+ async transformRequestIn(e) {
55915
+ return e.messages.forEach((t) => {
55916
+ Array.isArray(t.content) ? t.content.forEach((n) => {
55917
+ n.cache_control && delete n.cache_control;
55918
+ }) : t.cache_control && delete t.cache_control;
55919
+ }), Array.isArray(e.tools) && e.tools.forEach((t) => {
55920
+ delete t.function.parameters.$schema;
55921
+ }), e;
55922
+ }
55923
+ async transformResponseOut(e) {
55924
+ if (e.headers.get("Content-Type")?.includes("application/json")) {
55925
+ let t = await e.json();
55926
+ return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55927
+ } else if (e.headers.get("Content-Type")?.includes("stream")) {
55928
+ if (!e.body) return e;
55929
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", l = false, d = "", c = new ReadableStream({ async start(a) {
55930
+ let u = e.body.getReader(), y = (g, f, i) => {
55931
+ let v = g.split(`
55932
+ `);
55933
+ for (let h of v) h.trim() && f.enqueue(i.encode(h + `
55934
+ `));
55935
+ }, k = (g, f) => {
55936
+ let { controller: i, encoder: v } = f;
55937
+ if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") {
55938
+ let h = g.slice(6);
55939
+ try {
55940
+ let p = JSON.parse(h);
55941
+ if (p.error) throw new Error(JSON.stringify(p));
55942
+ p.choices?.[0]?.delta?.content && !f.hasTextContent() && f.setHasTextContent(true), p.choices?.[0]?.delta?.tool_calls?.length && p.choices?.[0]?.delta?.tool_calls.forEach((T) => {
55943
+ T.id = `call_${I()}`;
55944
+ }), p.choices?.[0]?.delta?.tool_calls?.length && f.hasTextContent() && (typeof p.choices[0].index == "number" ? p.choices[0].index += 1 : p.choices[0].index = 1);
55945
+ let m = `data: ${JSON.stringify(p)}
55946
+
55947
+ `;
55948
+ i.enqueue(v.encode(m));
55949
+ } catch {
55950
+ i.enqueue(v.encode(g + `
55951
+ `));
55952
+ }
55953
+ } else i.enqueue(v.encode(g + `
55954
+ `));
55955
+ };
55956
+ try {
55957
+ for (; ; ) {
55958
+ let { done: g, value: f } = await u.read();
55959
+ if (g) {
55960
+ d.trim() && y(d, a, n);
55961
+ break;
55962
+ }
55963
+ if (!f || f.length === 0) continue;
55964
+ let i;
55965
+ try {
55966
+ i = t.decode(f, { stream: true });
55967
+ } catch (h) {
55968
+ console.warn("Failed to decode chunk", h);
55969
+ continue;
55970
+ }
55971
+ if (i.length === 0) continue;
55972
+ if (d += i, d.length > 1e6) {
55973
+ console.warn("Buffer size exceeds limit, processing partial data");
55974
+ let h = d.split(`
55975
+ `);
55976
+ d = h.pop() || "";
55977
+ for (let p of h) if (p.trim()) try {
55978
+ k(p, { controller: a, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => l, setReasoningComplete: (m) => l = m });
55979
+ } catch (m) {
55980
+ console.error("Error processing line:", p, m), a.enqueue(n.encode(p + `
55981
+ `));
55982
+ }
55983
+ continue;
55984
+ }
55985
+ let v = d.split(`
55986
+ `);
55987
+ d = v.pop() || "";
55988
+ for (let h of v) if (h.trim()) try {
55989
+ k(h, { controller: a, encoder: n, hasTextContent: () => r, setHasTextContent: (p) => r = p, reasoningContent: () => o, appendReasoningContent: (p) => o += p, isReasoningComplete: () => l, setReasoningComplete: (p) => l = p });
55990
+ } catch (p) {
55991
+ console.error("Error processing line:", h, p), a.enqueue(n.encode(h + `
55992
+ `));
55993
+ }
55994
+ }
55995
+ } catch (g) {
55996
+ console.error("Stream error:", g), a.error(g);
55997
+ } finally {
55998
+ try {
55999
+ u.releaseLock();
56000
+ } catch (g) {
56001
+ console.error("Error releasing reader lock:", g);
56002
+ }
56003
+ a.close();
56004
+ }
56005
+ } });
56006
+ return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
56007
+ }
56008
+ return e;
56009
+ }
56010
+ };
56011
+ var K = class {
56012
+ name = "cleancache";
56013
+ async transformRequestIn(e) {
56014
+ return Array.isArray(e.messages) && e.messages.forEach((t) => {
56015
+ Array.isArray(t.content) ? t.content.forEach((n) => {
56016
+ n.cache_control && delete n.cache_control;
56017
+ }) : t.cache_control && delete t.cache_control;
56018
+ }), e;
56019
+ }
56020
+ };
56021
+ var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer: V, MaxTokenTransformer: W, GroqTransformer: G, CleancacheTransformer: K };
56022
+ var Y = class {
55866
56023
  constructor(e) {
55867
56024
  this.configService = e;
55868
56025
  }
55869
56026
  transformers = /* @__PURE__ */ new Map();
55870
56027
  registerTransformer(e, t) {
55871
- this.transformers.set(e, t), h(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
56028
+ this.transformers.set(e, t), C(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
55872
56029
  }
55873
56030
  getTransformer(e) {
55874
56031
  return this.transformers.get(e);
@@ -55897,31 +56054,31 @@ var B = class {
55897
56054
  async registerTransformerFromConfig(e) {
55898
56055
  try {
55899
56056
  let t = import_node_module.default._load;
55900
- if (import_node_module.default._load = function(n, o, r) {
55901
- return n === "claude-code-router" ? { log: h } : t.apply(import_node_module.default, arguments);
56057
+ if (import_node_module.default._load = function(n, r, o) {
56058
+ return n === "claude-code-router" ? { log: C } : t.apply(import_node_module.default, arguments);
55902
56059
  }, e.path) {
55903
- let n = W(W.resolve(e.path));
56060
+ let n = Z(Z.resolve(e.path));
55904
56061
  if (n) {
55905
- let o = new n(e.options);
55906
- if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
55907
- return this.registerTransformer(o.name, o), true;
56062
+ let r = new n(e.options);
56063
+ if (!r.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
56064
+ return this.registerTransformer(r.name, r), true;
55908
56065
  }
55909
56066
  }
55910
56067
  return false;
55911
56068
  } catch (t) {
55912
- return h(`load transformer (${e.path}) error:`, t.message, t.stack), false;
56069
+ return C(`load transformer (${e.path}) error:`, t.message, t.stack), false;
55913
56070
  }
55914
56071
  }
55915
56072
  async initialize() {
55916
56073
  try {
55917
56074
  await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
55918
56075
  } catch (e) {
55919
- h("TransformerService init error:", e);
56076
+ C("TransformerService init error:", e);
55920
56077
  }
55921
56078
  }
55922
56079
  async registerDefaultTransformersInternal() {
55923
56080
  try {
55924
- Object.values(ne).forEach((e) => {
56081
+ Object.values(pe).forEach((e) => {
55925
56082
  if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
55926
56083
  else {
55927
56084
  let t = new e();
@@ -55929,7 +56086,7 @@ var B = class {
55929
56086
  }
55930
56087
  });
55931
56088
  } catch (e) {
55932
- h("transformer regist error:", e);
56089
+ C("transformer regist error:", e);
55933
56090
  }
55934
56091
  }
55935
56092
  async loadFromConfig() {
@@ -55937,20 +56094,20 @@ var B = class {
55937
56094
  for (let t of e) await this.registerTransformerFromConfig(t);
55938
56095
  }
55939
56096
  };
55940
- function pe() {
55941
- let a = (0, import_fastify.default)({});
55942
- return a.setErrorHandler(Z), a.register(import_cors.default), a;
56097
+ function Se() {
56098
+ let s = (0, import_fastify.default)({});
56099
+ return s.setErrorHandler(le), s.register(import_cors.default), s;
55943
56100
  }
55944
- var G = class {
56101
+ var re = class {
55945
56102
  app;
55946
56103
  configService;
55947
56104
  llmService;
55948
56105
  providerService;
55949
56106
  transformerService;
55950
56107
  constructor(e = {}) {
55951
- this.configService = new N(e), this.transformerService = new B(this.configService), this.transformerService.initialize().finally(() => {
55952
- this.providerService = new F(this.configService, this.transformerService), this.llmService = new $(this.providerService);
55953
- }), this.app = pe();
56108
+ this.configService = new $(e), this.transformerService = new Y(this.configService), this.transformerService.initialize().finally(() => {
56109
+ this.providerService = new F(this.configService, this.transformerService), this.llmService = new q(this.providerService);
56110
+ }), this.app = Se();
55954
56111
  }
55955
56112
  async register(e, t) {
55956
56113
  await this.app.register(e, t);
@@ -55960,33 +56117,33 @@ var G = class {
55960
56117
  }
55961
56118
  async start() {
55962
56119
  try {
55963
- this.app._server = this, this.app.addHook("preHandler", async (n, o) => {
56120
+ this.app._server = this, this.app.addHook("preHandler", async (n, r) => {
55964
56121
  try {
55965
- let r = n.body;
55966
- if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
55967
- let [l, d] = r.model.split(",");
55968
- r.model = d, n.provider = l;
56122
+ let o = n.body;
56123
+ if (!o || !o.model) return r.code(400).send({ error: "Missing model in request body" });
56124
+ let [l, d] = o.model.split(",");
56125
+ o.model = d, n.provider = l;
55969
56126
  return;
55970
- } catch (r) {
55971
- return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
56127
+ } catch (o) {
56128
+ return n.log.error("Error in modelProviderMiddleware:", o), r.code(500).send({ error: "Internal server error" });
55972
56129
  }
55973
- }), this.app.register(te);
56130
+ }), this.app.register(fe);
55974
56131
  let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
55975
- h(`\u{1F680} LLMs API server listening on ${e}`);
56132
+ C(`\u{1F680} LLMs API server listening on ${e}`);
55976
56133
  let t = async (n) => {
55977
- h(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
56134
+ C(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
55978
56135
  };
55979
56136
  process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
55980
56137
  } catch (e) {
55981
- h(`Error starting server: ${e}`), process.exit(1);
56138
+ C(`Error starting server: ${e}`), process.exit(1);
55982
56139
  }
55983
56140
  }
55984
56141
  };
55985
- var At = G;
56142
+ var cn = re;
55986
56143
 
55987
56144
  // src/server.ts
55988
56145
  var createServer = (config) => {
55989
- const server = new At(config);
56146
+ const server = new cn(config);
55990
56147
  return server;
55991
56148
  };
55992
56149
 
@@ -56091,6 +56248,33 @@ var router = async (req, res, config) => {
56091
56248
  return;
56092
56249
  };
56093
56250
 
56251
+ // src/middleware/auth.ts
56252
+ var apiKeyAuth = (config) => (req, reply, done) => {
56253
+ if (["/", "/health"].includes(req.url)) {
56254
+ return done();
56255
+ }
56256
+ const apiKey = config.APIKEY;
56257
+ if (!apiKey) {
56258
+ return done();
56259
+ }
56260
+ const authKey = req.headers.authorization || req.headers["x-api-key"];
56261
+ if (!authKey) {
56262
+ reply.status(401).send("APIKEY is missing");
56263
+ return;
56264
+ }
56265
+ let token = "";
56266
+ if (authKey.startsWith("Bearer")) {
56267
+ token = authKey.split(" ")[1];
56268
+ } else {
56269
+ token = authKey;
56270
+ }
56271
+ if (token !== apiKey) {
56272
+ reply.status(401).send("Invalid API key");
56273
+ return;
56274
+ }
56275
+ done();
56276
+ };
56277
+
56094
56278
  // src/utils/processCheck.ts
56095
56279
  var import_fs2 = require("fs");
56096
56280
  function incrementReferenceCount() {
@@ -56192,6 +56376,13 @@ async function run(options = {}) {
56192
56376
  await initializeClaudeConfig();
56193
56377
  await initDir();
56194
56378
  const config = await initConfig();
56379
+ let HOST = config.HOST;
56380
+ if (config.HOST && !config.APIKEY) {
56381
+ HOST = "127.0.0.1";
56382
+ console.warn(
56383
+ "\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
56384
+ );
56385
+ }
56195
56386
  const port = options.port || 3456;
56196
56387
  savePid(process.pid);
56197
56388
  process.on("SIGINT", () => {
@@ -56203,12 +56394,14 @@ async function run(options = {}) {
56203
56394
  cleanupPidFile();
56204
56395
  process.exit(0);
56205
56396
  });
56397
+ console.log(HOST);
56206
56398
  const servicePort = process.env.SERVICE_PORT ? parseInt(process.env.SERVICE_PORT) : port;
56207
56399
  const server = createServer({
56208
56400
  jsonPath: CONFIG_FILE,
56209
56401
  initialConfig: {
56210
56402
  // ...config,
56211
56403
  providers: config.Providers || config.providers,
56404
+ HOST,
56212
56405
  PORT: servicePort,
56213
56406
  LOG_FILE: (0, import_path2.join)(
56214
56407
  (0, import_os.homedir)(),
@@ -56217,6 +56410,7 @@ async function run(options = {}) {
56217
56410
  )
56218
56411
  }
56219
56412
  });
56413
+ server.addHook("preHandler", apiKeyAuth(config));
56220
56414
  server.addHook(
56221
56415
  "preHandler",
56222
56416
  async (req, reply) => router(req, reply, config)
@@ -56276,12 +56470,17 @@ async function closeService() {
56276
56470
 
56277
56471
  // src/utils/codeCommand.ts
56278
56472
  async function executeCodeCommand(args = []) {
56473
+ const config = await readConfigFile();
56279
56474
  const env = {
56280
56475
  ...process.env,
56281
56476
  ANTHROPIC_AUTH_TOKEN: "test",
56282
56477
  ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`,
56283
56478
  API_TIMEOUT_MS: "600000"
56284
56479
  };
56480
+ if (config?.APIKEY) {
56481
+ env.ANTHROPIC_API_KEY = config.APIKEY;
56482
+ delete env.ANTHROPIC_AUTH_TOKEN;
56483
+ }
56285
56484
  incrementReferenceCount();
56286
56485
  const claudePath = process.env.CLAUDE_PATH || "claude";
56287
56486
  const claudeProcess = (0, import_child_process.spawn)(claudePath, args, {
@@ -56305,7 +56504,7 @@ async function executeCodeCommand(args = []) {
56305
56504
  }
56306
56505
 
56307
56506
  // package.json
56308
- var version = "1.0.19";
56507
+ var version = "1.0.21";
56309
56508
 
56310
56509
  // src/cli.ts
56311
56510
  var import_child_process2 = require("child_process");