@musistudio/claude-code-router 1.0.20 → 1.0.22

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 {
@@ -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;
@@ -9200,8 +9200,8 @@ var require_reply = __commonJS({
9200
9200
  responseTime
9201
9201
  }, "request completed");
9202
9202
  }
9203
- function buildReply(R2) {
9204
- const props = R2.props.slice();
9203
+ function buildReply(R) {
9204
+ const props = R.props.slice();
9205
9205
  function _Reply(res, request, log2) {
9206
9206
  this.raw = res;
9207
9207
  this[kReplyIsError] = false;
@@ -9220,9 +9220,9 @@ var require_reply = __commonJS({
9220
9220
  this[prop.key] = prop.value;
9221
9221
  }
9222
9222
  }
9223
- Object.setPrototypeOf(_Reply.prototype, R2.prototype);
9224
- Object.setPrototypeOf(_Reply, R2);
9225
- _Reply.parent = R2;
9223
+ Object.setPrototypeOf(_Reply.prototype, R.prototype);
9224
+ Object.setPrototypeOf(_Reply, R);
9225
+ _Reply.parent = R;
9226
9226
  _Reply.props = props;
9227
9227
  return _Reply;
9228
9228
  }
@@ -10300,14 +10300,14 @@ var require_request = __commonJS({
10300
10300
  }
10301
10301
  return proxyAddr.compile(tp);
10302
10302
  }
10303
- function buildRequest(R2, trustProxy) {
10303
+ function buildRequest(R, trustProxy) {
10304
10304
  if (trustProxy) {
10305
- return buildRequestWithTrustProxy(R2, trustProxy);
10305
+ return buildRequestWithTrustProxy(R, trustProxy);
10306
10306
  }
10307
- return buildRegularRequest(R2);
10307
+ return buildRegularRequest(R);
10308
10308
  }
10309
- function buildRegularRequest(R2) {
10310
- const props = R2.props.slice();
10309
+ function buildRegularRequest(R) {
10310
+ const props = R.props.slice();
10311
10311
  function _Request(id2, params, req, query, log2, context) {
10312
10312
  this.id = id2;
10313
10313
  this[kRouteContext] = context;
@@ -10322,18 +10322,18 @@ var require_request = __commonJS({
10322
10322
  this[prop.key] = prop.value;
10323
10323
  }
10324
10324
  }
10325
- Object.setPrototypeOf(_Request.prototype, R2.prototype);
10326
- Object.setPrototypeOf(_Request, R2);
10325
+ Object.setPrototypeOf(_Request.prototype, R.prototype);
10326
+ Object.setPrototypeOf(_Request, R);
10327
10327
  _Request.props = props;
10328
- _Request.parent = R2;
10328
+ _Request.parent = R;
10329
10329
  return _Request;
10330
10330
  }
10331
10331
  function getLastEntryInMultiHeaderValue(headerValue) {
10332
10332
  const lastIndex = headerValue.lastIndexOf(",");
10333
10333
  return lastIndex === -1 ? headerValue.trim() : headerValue.slice(lastIndex + 1).trim();
10334
10334
  }
10335
- function buildRequestWithTrustProxy(R2, trustProxy) {
10336
- const _Request = buildRegularRequest(R2);
10335
+ function buildRequestWithTrustProxy(R, trustProxy) {
10336
+ const _Request = buildRegularRequest(R);
10337
10337
  const proxyFn = getTrustProxyFn(trustProxy);
10338
10338
  _Request[kHasBeenDecorated] = true;
10339
10339
  Object.defineProperties(_Request.prototype, {
@@ -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
  });
@@ -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) {
@@ -23509,7 +23509,7 @@ var require_re = __commonJS({
23509
23509
  var src = exports2.src = [];
23510
23510
  var safeSrc = exports2.safeSrc = [];
23511
23511
  var t = exports2.t = {};
23512
- var R2 = 0;
23512
+ var R = 0;
23513
23513
  var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
23514
23514
  var safeRegexReplacements = [
23515
23515
  ["\\s", 1],
@@ -23524,7 +23524,7 @@ var require_re = __commonJS({
23524
23524
  };
23525
23525
  var createToken = (name, value, isGlobal) => {
23526
23526
  const safe = makeSafeRegex(value);
23527
- const index = R2++;
23527
+ const index = R++;
23528
23528
  debug(name, index, value);
23529
23529
  t[name] = index;
23530
23530
  src[index] = value;
@@ -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
@@ -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
  }
@@ -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
  }
@@ -25062,7 +25062,7 @@ var require_simplify = __commonJS({
25062
25062
  const set = [];
25063
25063
  let first = null;
25064
25064
  let prev = null;
25065
- const v2 = versions.sort((a, b) => compare(a, b, options));
25065
+ const v2 = versions.sort((a, b2) => compare(a, b2, options));
25066
25066
  for (const version2 of v2) {
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,
@@ -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
  }
@@ -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} */
@@ -54958,7 +54958,7 @@ var initConfig = async () => {
54958
54958
  return config;
54959
54959
  };
54960
54960
 
54961
- // node_modules/.pnpm/@musistudio+llms@1.0.7_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54961
+ // node_modules/.pnpm/@musistudio+llms@1.0.9_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");
@@ -54969,11 +54969,11 @@ var import_undici = __toESM(require_undici(), 1);
54969
54969
  var import_crypto = require("crypto");
54970
54970
  var import_crypto2 = require("crypto");
54971
54971
  var import_node_module = __toESM(require("node:module"), 1);
54972
- var Y = ((s) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(s, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : s)(function(s) {
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) {
54973
54973
  if (typeof require < "u") return require.apply(this, arguments);
54974
54974
  throw Error('Dynamic require of "' + s + '" is not supported');
54975
54975
  });
54976
- var I = class {
54976
+ var $ = class {
54977
54977
  config = {};
54978
54978
  options;
54979
54979
  constructor(e = { jsonPath: "./config.json" }) {
@@ -55039,83 +55039,83 @@ var I = class {
55039
55039
  };
55040
55040
  function v(...s) {
55041
55041
  if (console.log(...s), !(process.env.LOG === "true")) return;
55042
- let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
55043
- `, o = process.env.LOG_FILE || "app.log";
55044
- import_node_fs.default.appendFileSync(o, n, "utf8");
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");
55045
55045
  }
55046
- function N(s, e = 500, t = "internal_error", n = "api_error") {
55047
- let o = new Error(s);
55048
- 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;
55049
55049
  }
55050
- async function ie(s, e, t) {
55050
+ async function le(s, e, t) {
55051
55051
  e.log.error(s);
55052
- let n = s.statusCode || 500, o = { error: { message: s.message || "Internal Server Error", type: s.type || "api_error", code: s.code || "internal_error" } };
55053
- return t.code(n).send(o);
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);
55054
55054
  }
55055
- function ae(s, e, t) {
55055
+ function de(s, e, t) {
55056
55056
  let n = new Headers({ "Content-Type": "application/json" });
55057
- t.headers && Object.entries(t.headers).forEach(([l, f]) => {
55058
- n.set(l, f);
55057
+ t.headers && Object.entries(t.headers).forEach(([l, d]) => {
55058
+ n.set(l, d);
55059
55059
  });
55060
- let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55060
+ let r, o = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55061
55061
  if (t.signal) {
55062
- let l = new AbortController(), f = () => l.abort();
55063
- t.signal.addEventListener("abort", f), r.addEventListener("abort", f), o = l.signal;
55064
- } else o = r;
55065
- let d = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
55066
- return t.httpsProxy && (d.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, d), fetch(typeof s == "string" ? s : s.toString(), d);
55062
+ let l = new AbortController(), d = () => l.abort();
55063
+ t.signal.addEventListener("abort", d), o.addEventListener("abort", d), r = l.signal;
55064
+ } else r = o;
55065
+ let c = { method: "POST", headers: n, body: JSON.stringify(e), signal: r };
55066
+ return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, c), fetch(typeof s == "string" ? s : s.toString(), c);
55067
55067
  }
55068
- var ce = async (s) => {
55068
+ var ue = async (s) => {
55069
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
55070
  let e = s._server.transformerService.getTransformersWithEndpoint();
55071
- for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (o, r) => {
55072
- let d = o.body, l = o.provider, f = s._server.providerService.getProvider(l);
55073
- if (!f) throw N(`Provider '${l}' not found`, 404, "provider_not_found");
55074
- let a = d, m = {};
55071
+ for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (r, o) => {
55072
+ let c = r.body, l = r.provider, d = s._server.providerService.getProvider(l);
55073
+ if (!d) throw L(`Provider '${l}' not found`, 404, "provider_not_found");
55074
+ let i = c, p = {};
55075
55075
  if (typeof n.transformRequestOut == "function") {
55076
- let i = await n.transformRequestOut(d);
55077
- i.body ? (a = i.body, m = i.config || {}) : a = i;
55076
+ let a = await n.transformRequestOut(c);
55077
+ a.body ? (i = a.body, p = a.config || {}) : i = a;
55078
55078
  }
55079
- if (v("use transformers:", f.transformer?.use), f.transformer?.use?.length) for (let i of f.transformer.use) {
55080
- if (!i || typeof i.transformRequestIn != "function") continue;
55081
- let y = await i.transformRequestIn(a, f);
55082
- y.body ? (a = y.body, m = { ...m, ...y.config }) : a = y;
55079
+ if (v("use transformers:", d.transformer?.use), d.transformer?.use?.length) for (let a of d.transformer.use) {
55080
+ if (!a || typeof a.transformRequestIn != "function") continue;
55081
+ let y = await a.transformRequestIn(i, d);
55082
+ y.body ? (i = y.body, p = { ...p, ...y.config }) : i = y;
55083
55083
  }
55084
- if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformRequestIn != "function" || (a = await i.transformRequestIn(a, f));
55085
- let g = m.url || new URL(f.baseUrl), C = await ae(g, a, { httpsProxy: s._server.configService.getHttpsProxy(), ...m, headers: { Authorization: `Bearer ${f.apiKey}`, ...m?.headers || {} } });
55084
+ if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformRequestIn != "function" || (i = await a.transformRequestIn(i, d));
55085
+ let _ = p.url || new URL(d.baseUrl), C = await de(_, i, { httpsProxy: s._server.configService.getHttpsProxy(), ...p, headers: { Authorization: `Bearer ${d.apiKey}`, ...p?.headers || {} } });
55086
55086
  if (!C.ok) {
55087
- let i = await C.text();
55088
- throw v(`Error response from ${g}: ${i}`), N(`Error from provider: ${i}`, C.status, "provider_response_error");
55087
+ let a = await C.text();
55088
+ throw v(`Error response from ${_}: ${a}`), L(`Error from provider: ${a}`, C.status, "provider_response_error");
55089
55089
  }
55090
- let p = C;
55091
- if (f.transformer?.use?.length) for (let i of f.transformer.use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
55092
- if (f.transformer?.[o.body.model]?.use?.length) for (let i of f.transformer[o.body.model].use) !i || typeof i.transformResponseOut != "function" || (p = await i.transformResponseOut(p));
55093
- return n.transformResponseIn && (p = await n.transformResponseIn(p)), p.ok || r.code(p.status), d?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(p.body)) : p.json();
55090
+ let g = C;
55091
+ if (d.transformer?.use?.length) for (let a of d.transformer.use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
55092
+ if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
55093
+ return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status), c?.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();
55094
55094
  });
55095
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: o, type: r, baseUrl: d, apiKey: l, models: f } = t.body;
55097
- if (!o?.trim()) throw N("Provider name is required", 400, "invalid_request");
55098
- if (!d || !ve(d)) throw N("Valid base URL is required", 400, "invalid_request");
55099
- if (!l?.trim()) throw N("API key is required", 400, "invalid_request");
55100
- if (!f || !Array.isArray(f) || f.length === 0) throw N("At least one model is required", 400, "invalid_request");
55101
- if (s._server.providerService.getProvider(id)) throw N(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55096
+ let { name: r, type: o, baseUrl: c, apiKey: l, models: d } = t.body;
55097
+ if (!r?.trim()) throw L("Provider name is required", 400, "invalid_request");
55098
+ if (!c || !Ce(c)) throw L("Valid base URL is required", 400, "invalid_request");
55099
+ if (!l?.trim()) throw L("API key is required", 400, "invalid_request");
55100
+ if (!d || !Array.isArray(d) || d.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
55102
  return s._server.providerService.registerProvider(t.body);
55103
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 o = s._server.providerService.getProvider(t.params.id);
55105
- return o || n.code(404).send({ error: "Provider not found" });
55104
+ let r = s._server.providerService.getProvider(t.params.id);
55105
+ return r || n.code(404).send({ error: "Provider not found" });
55106
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 o = s._server.providerService.updateProvider(t.params.id, t.body);
55108
- return o || n.code(404).send({ error: "Provider not found" });
55107
+ let r = s._server.providerService.updateProvider(t.params.id, t.body);
55108
+ return r || n.code(404).send({ error: "Provider not found" });
55109
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" }));
55110
55110
  };
55111
- function ve(s) {
55111
+ function Ce(s) {
55112
55112
  try {
55113
55113
  return new URL(s), true;
55114
55114
  } catch {
55115
55115
  return false;
55116
55116
  }
55117
55117
  }
55118
- var $ = class {
55118
+ var q = class {
55119
55119
  constructor(e) {
55120
55120
  this.providerService = e;
55121
55121
  }
@@ -55172,20 +55172,20 @@ var F = class {
55172
55172
  try {
55173
55173
  if (!t.name || !t.api_base_url || !t.api_key) return;
55174
55174
  let n = {};
55175
- t.transformer && Object.keys(t.transformer).forEach((o) => {
55176
- o === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((r) => {
55177
- if (Array.isArray(r) && typeof r[0] == "string") {
55178
- let d = this.transformerService.getTransformer(r[0]);
55179
- if (d) return new d(r[1]);
55180
- }
55181
- if (typeof r == "string") return this.transformerService.getTransformer(r);
55182
- }).filter((r) => typeof r < "u")) : Array.isArray(t.transformer[o]?.use) && (n[o] = { use: t.transformer[o].use.map((r) => {
55183
- if (Array.isArray(r) && typeof r[0] == "string") {
55184
- let d = this.transformerService.getTransformer(r[0]);
55185
- if (d) return new d(r[1]);
55186
- }
55187
- if (typeof r == "string") return this.transformerService.getTransformer(r);
55188
- }).filter((r) => typeof r < "u") });
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 c = this.transformerService.getTransformer(o[0]);
55179
+ if (c) return new c(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 c = this.transformerService.getTransformer(o[0]);
55185
+ if (c) return new c(o[1]);
55186
+ }
55187
+ if (typeof o == "string") return this.transformerService.getTransformer(o);
55188
+ }).filter((o) => typeof o < "u") });
55189
55189
  }), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), v(`${t.name} provider registered`);
55190
55190
  } catch (n) {
55191
55191
  v(`${t.name} provider registered error: ${n}`);
@@ -55195,8 +55195,8 @@ var F = class {
55195
55195
  registerProvider(e) {
55196
55196
  let t = { ...e };
55197
55197
  return this.providers.set(t.name, t), e.models.forEach((n) => {
55198
- let o = `${t.name},${n}`, r = { provider: t.name, model: n, fullModel: o };
55199
- 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);
55200
55200
  }), t;
55201
55201
  }
55202
55202
  getProviders() {
@@ -55208,20 +55208,20 @@ var F = class {
55208
55208
  updateProvider(e, t) {
55209
55209
  let n = this.providers.get(e);
55210
55210
  if (!n) return null;
55211
- let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
55212
- return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
55213
- let d = `${n.id},${r}`;
55214
- this.modelRoutes.delete(d), this.modelRoutes.delete(r);
55215
- }), t.models.forEach((r) => {
55216
- let d = `${n.name},${r}`, l = { provider: n.name, model: r, fullModel: d };
55217
- this.modelRoutes.set(d, l), this.modelRoutes.has(r) || this.modelRoutes.set(r, l);
55218
- })), 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 c = `${n.id},${o}`;
55214
+ this.modelRoutes.delete(c), this.modelRoutes.delete(o);
55215
+ }), t.models.forEach((o) => {
55216
+ let c = `${n.name},${o}`, l = { provider: n.name, model: o, fullModel: c };
55217
+ this.modelRoutes.set(c, l), this.modelRoutes.has(o) || this.modelRoutes.set(o, l);
55218
+ })), r;
55219
55219
  }
55220
55220
  deleteProvider(e) {
55221
55221
  let t = this.providers.get(e);
55222
55222
  return t ? (t.models.forEach((n) => {
55223
- let o = `${t.name},${n}`;
55224
- this.modelRoutes.delete(o), this.modelRoutes.delete(n);
55223
+ let r = `${t.name},${n}`;
55224
+ this.modelRoutes.delete(r), this.modelRoutes.delete(n);
55225
55225
  }), this.providers.delete(e), true) : false;
55226
55226
  }
55227
55227
  toggleProvider(e, t) {
@@ -55247,8 +55247,8 @@ var F = class {
55247
55247
  parseTransformerConfig(e) {
55248
55248
  return e ? Array.isArray(e) ? e.reduce((t, n) => {
55249
55249
  if (Array.isArray(n)) {
55250
- let [o, r = {}] = n;
55251
- t[o] = r;
55250
+ let [r, o = {}] = n;
55251
+ t[r] = o;
55252
55252
  } else t[n] = {};
55253
55253
  return t;
55254
55254
  }, {}) : e : {};
@@ -55262,38 +55262,40 @@ var F = class {
55262
55262
  }), { object: "list", data: e };
55263
55263
  }
55264
55264
  };
55265
- var q = class {
55265
+ var U = class {
55266
55266
  name = "Anthropic";
55267
55267
  endPoint = "/v1/messages";
55268
- transformRequestOut(e) {
55268
+ async transformRequestOut(e) {
55269
55269
  v("Anthropic Request:", JSON.stringify(e, null, 2));
55270
55270
  let t = [];
55271
55271
  if (e.system) {
55272
55272
  if (typeof e.system == "string") t.push({ role: "system", content: e.system });
55273
55273
  else if (Array.isArray(e.system)) {
55274
- let r = e.system.filter((d) => d.type === "text" && d.text).map((d) => ({ type: "text", text: d.text, cache_control: d.cache_control }));
55275
- t.push({ role: "system", content: r });
55276
- }
55277
- }
55278
- return JSON.parse(JSON.stringify(e.messages || []))?.forEach((r, d) => {
55279
- if (r.role === "user" || r.role === "assistant") {
55280
- let l = { role: r.role, content: null };
55281
- if (typeof r.content == "string") t.push({ role: r.role, content: r.content });
55282
- else if (Array.isArray(r.content)) {
55283
- if (r.role === "user") {
55284
- let f = r.content.filter((m) => m.type === "tool_result" && m.tool_use_id);
55285
- f.length && f.forEach((m, g) => {
55286
- let C = { role: "tool", content: typeof m.content == "string" ? m.content : JSON.stringify(m.content), tool_call_id: m.tool_use_id, cache_control: m.cache_control };
55287
- t.push(C);
55274
+ let o = e.system.filter((c) => c.type === "text" && c.text).map((c) => ({ type: "text", text: c.text, cache_control: c.cache_control }));
55275
+ t.push({ role: "system", content: o });
55276
+ }
55277
+ }
55278
+ return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o, c) => {
55279
+ if (o.role === "user" || o.role === "assistant") {
55280
+ if (typeof o.content == "string") {
55281
+ t.push({ role: o.role, content: o.content });
55282
+ return;
55283
+ }
55284
+ if (Array.isArray(o.content)) {
55285
+ if (o.role === "user") {
55286
+ let l = o.content.filter((i) => i.type === "tool_result" && i.tool_use_id);
55287
+ l.length && l.forEach((i, p) => {
55288
+ let _ = { role: "tool", content: typeof i.content == "string" ? i.content : JSON.stringify(i.content), tool_call_id: i.tool_use_id, cache_control: i.cache_control };
55289
+ t.push(_);
55288
55290
  });
55289
- let a = r.content.filter((m) => m.type === "text" && m.text);
55290
- a.length && t.push({ role: "user", content: a });
55291
- } else if (r.role === "assistant") {
55292
- let f = { role: "assistant", content: null }, a = r.content.filter((g) => g.type === "text" && g.text);
55293
- a.length && (f.content = a.map((g) => g.text).join(`
55291
+ let d = o.content.filter((i) => i.type === "text" && i.text || i.type === "image" && i.source);
55292
+ d.length && t.push({ role: "user", content: d.map((i) => i?.type === "image" ? { type: "image_url", image_url: { url: i.source?.type === "base64" ? i.source.data : i.source.url }, media_type: i.source.media_type } : i) });
55293
+ } else if (o.role === "assistant") {
55294
+ let l = { role: "assistant", content: null }, d = o.content.filter((p) => p.type === "text" && p.text);
55295
+ d.length && (l.content = d.map((p) => p.text).join(`
55294
55296
  `));
55295
- let m = r.content.filter((g) => g.type === "tool_use" && g.id);
55296
- m.length && (f.tool_calls = m.map((g) => ({ id: g.id, type: "function", function: { name: g.name, arguments: JSON.stringify(g.input || {}) } }))), t.push(f);
55297
+ let i = o.content.filter((p) => p.type === "tool_use" && p.id);
55298
+ i.length && (l.tool_calls = i.map((p) => ({ id: p.id, type: "function", function: { name: p.name, arguments: JSON.stringify(p.input || {}) } }))), t.push(l);
55297
55299
  }
55298
55300
  return;
55299
55301
  }
@@ -55306,8 +55308,8 @@ var q = class {
55306
55308
  let n = await this.convertOpenAIStreamToAnthropic(e.body);
55307
55309
  return new Response(n, { headers: { "Content-Type": "text/event-stream", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55308
55310
  } else {
55309
- let n = await e.json(), o = this.convertOpenAIResponseToAnthropic(n);
55310
- return new Response(JSON.stringify(o), { headers: { "Content-Type": "application/json" } });
55311
+ let n = await e.json(), r = this.convertOpenAIResponseToAnthropic(n);
55312
+ return new Response(JSON.stringify(r), { headers: { "Content-Type": "application/json" } });
55311
55313
  }
55312
55314
  }
55313
55315
  convertAnthropicToolsToUnified(e) {
@@ -55315,208 +55317,208 @@ var q = class {
55315
55317
  }
55316
55318
  async convertOpenAIStreamToAnthropic(e) {
55317
55319
  return new ReadableStream({ async start(n) {
55318
- let o = new TextEncoder(), r = `msg_${Date.now()}`, d = "unknown", l = false, f = false, a = false, m = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), C = 0, p = 0, u = 0, i = false, y = false, h = 0, c = (b) => {
55319
- if (!i) try {
55320
- n.enqueue(b);
55321
- let _ = new TextDecoder().decode(b);
55322
- v("send data:", _.trim());
55323
- } catch (_) {
55324
- if (_ instanceof TypeError && _.message.includes("Controller is already closed")) i = true;
55325
- else throw v(`send data error: ${_.message}`), _;
55326
- }
55327
- }, k = () => {
55328
- if (!i) try {
55329
- n.close(), i = true;
55330
- } catch (b) {
55331
- if (b instanceof TypeError && b.message.includes("Controller is already closed")) i = true;
55332
- else throw b;
55333
- }
55334
- }, P = null;
55320
+ let r = new TextEncoder(), o = `msg_${Date.now()}`, c = "unknown", l = false, d = false, i = false, p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), C = 0, g = 0, u = 0, a = false, y = false, h = 0, f = (x) => {
55321
+ if (!a) try {
55322
+ n.enqueue(x);
55323
+ let R = new TextDecoder().decode(x);
55324
+ v("send data:", R.trim());
55325
+ } catch (R) {
55326
+ if (R instanceof TypeError && R.message.includes("Controller is already closed")) a = true;
55327
+ else throw v(`send data error: ${R.message}`), R;
55328
+ }
55329
+ }, m = () => {
55330
+ if (!a) try {
55331
+ n.close(), a = true;
55332
+ } catch (x) {
55333
+ if (x instanceof TypeError && x.message.includes("Controller is already closed")) a = true;
55334
+ else throw x;
55335
+ }
55336
+ }, T = null;
55335
55337
  try {
55336
- P = e.getReader();
55337
- let b = new TextDecoder(), _ = "";
55338
- for (; !i; ) {
55339
- let { done: ue, value: fe } = await P.read();
55340
- if (ue) break;
55341
- _ += b.decode(fe, { stream: true });
55342
- let ne = _.split(`
55338
+ T = e.getReader();
55339
+ let x = new TextDecoder(), R = "";
55340
+ for (; !a; ) {
55341
+ let { done: X, value: me } = await T.read();
55342
+ if (X) break;
55343
+ R += x.decode(me, { stream: true });
55344
+ let se = R.split(`
55343
55345
  `);
55344
- _ = ne.pop() || "";
55345
- for (let oe of ne) {
55346
- if (i || a) break;
55347
- if (!oe.startsWith("data: ")) continue;
55348
- let K = oe.slice(6);
55349
- if (K !== "[DONE]") try {
55350
- let O = JSON.parse(K);
55346
+ R = se.pop() || "";
55347
+ for (let ie of se) {
55348
+ if (a || i) break;
55349
+ if (!ie.startsWith("data: ")) continue;
55350
+ let Q = ie.slice(6);
55351
+ if (Q !== "[DONE]") try {
55352
+ let O = JSON.parse(Q);
55351
55353
  if (C++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
55352
- let x = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
55353
- c(o.encode(`event: error
55354
- data: ${JSON.stringify(x)}
55354
+ let k = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
55355
+ f(r.encode(`event: error
55356
+ data: ${JSON.stringify(k)}
55355
55357
 
55356
55358
  `));
55357
55359
  continue;
55358
55360
  }
55359
- if (d = O.model || d, !l && !i && !a) {
55361
+ if (c = O.model || c, !l && !a && !i) {
55360
55362
  l = true;
55361
- let x = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: d, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55362
- c(o.encode(`event: message_start
55363
- data: ${JSON.stringify(x)}
55363
+ let k = { type: "message_start", message: { id: o, type: "message", role: "assistant", content: [], model: c, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55364
+ f(r.encode(`event: message_start
55365
+ data: ${JSON.stringify(k)}
55364
55366
 
55365
55367
  `));
55366
55368
  }
55367
55369
  let w = O.choices?.[0];
55368
55370
  if (!w) continue;
55369
- if (w?.delta?.thinking && !i && !a) {
55371
+ if (w?.delta?.thinking && !a && !i) {
55370
55372
  if (!y) {
55371
- let x = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
55372
- c(o.encode(`event: content_block_start
55373
- data: ${JSON.stringify(x)}
55373
+ let k = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
55374
+ f(r.encode(`event: content_block_start
55375
+ data: ${JSON.stringify(k)}
55374
55376
 
55375
55377
  `)), y = true;
55376
55378
  }
55377
55379
  if (w.delta.thinking.signature) {
55378
- let x = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
55379
- c(o.encode(`event: content_block_delta
55380
- data: ${JSON.stringify(x)}
55380
+ let k = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
55381
+ f(r.encode(`event: content_block_delta
55382
+ data: ${JSON.stringify(k)}
55381
55383
 
55382
55384
  `));
55383
- let T = { type: "content_block_stop", index: h };
55384
- c(o.encode(`event: content_block_stop
55385
- data: ${JSON.stringify(T)}
55385
+ let S = { type: "content_block_stop", index: h };
55386
+ f(r.encode(`event: content_block_stop
55387
+ data: ${JSON.stringify(S)}
55386
55388
 
55387
55389
  `)), h++;
55388
55390
  } else if (w.delta.thinking.content) {
55389
- let x = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
55390
- c(o.encode(`event: content_block_delta
55391
- data: ${JSON.stringify(x)}
55391
+ let k = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
55392
+ f(r.encode(`event: content_block_delta
55393
+ data: ${JSON.stringify(k)}
55392
55394
 
55393
55395
  `));
55394
55396
  }
55395
55397
  }
55396
- if (w?.delta?.content && !i && !a) {
55397
- if (p++, !f && !a) {
55398
- f = true;
55399
- let x = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
55400
- c(o.encode(`event: content_block_start
55401
- data: ${JSON.stringify(x)}
55398
+ if (w?.delta?.content && !a && !i) {
55399
+ if (g++, !d && !i) {
55400
+ d = true;
55401
+ let k = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
55402
+ f(r.encode(`event: content_block_start
55403
+ data: ${JSON.stringify(k)}
55402
55404
 
55403
55405
  `));
55404
55406
  }
55405
- if (!i && !a) {
55406
- let x = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
55407
- c(o.encode(`event: content_block_delta
55408
- data: ${JSON.stringify(x)}
55407
+ if (!a && !i) {
55408
+ let k = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
55409
+ f(r.encode(`event: content_block_delta
55410
+ data: ${JSON.stringify(k)}
55409
55411
 
55410
55412
  `));
55411
55413
  }
55412
55414
  }
55413
- if (w?.delta?.tool_calls && !i && !a) {
55415
+ if (w?.delta?.tool_calls && !a && !i) {
55414
55416
  u++;
55415
- let x = /* @__PURE__ */ new Set();
55416
- for (let T of w.delta.tool_calls) {
55417
- if (i) break;
55418
- let S = T.index ?? 0;
55419
- if (x.has(S)) continue;
55420
- if (x.add(S), !g.has(S)) {
55421
- let E = f ? g.size + 1 : g.size;
55417
+ let k = /* @__PURE__ */ new Set();
55418
+ for (let S of w.delta.tool_calls) {
55419
+ if (a) break;
55420
+ let P = S.index ?? 0;
55421
+ if (k.has(P)) continue;
55422
+ if (k.add(P), !_.has(P)) {
55423
+ let E = d ? _.size + 1 : _.size;
55422
55424
  if (E !== 0) {
55423
55425
  v("content_block_stop2");
55424
- let pe = { type: "content_block_stop", index: h };
55425
- c(o.encode(`event: content_block_stop
55426
- data: ${JSON.stringify(pe)}
55426
+ let he = { type: "content_block_stop", index: h };
55427
+ f(r.encode(`event: content_block_stop
55428
+ data: ${JSON.stringify(he)}
55427
55429
 
55428
55430
  `)), h++;
55429
55431
  }
55430
- g.set(S, E);
55431
- let H = T.id || `call_${Date.now()}_${S}`, A = T.function?.name || `tool_${S}`, L = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: H, name: A, input: {} } };
55432
- c(o.encode(`event: content_block_start
55433
- data: ${JSON.stringify(L)}
55432
+ _.set(P, E);
55433
+ let H = 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: H, name: A, input: {} } };
55434
+ f(r.encode(`event: content_block_start
55435
+ data: ${JSON.stringify(N)}
55434
55436
 
55435
55437
  `));
55436
55438
  let M = { id: H, name: A, arguments: "", contentBlockIndex: E };
55437
- m.set(S, M);
55438
- } else if (T.id && T.function?.name) {
55439
- let E = m.get(S);
55440
- E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = T.id, E.name = T.function.name);
55439
+ p.set(P, M);
55440
+ } else if (S.id && S.function?.name) {
55441
+ let E = p.get(P);
55442
+ E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = S.id, E.name = S.function.name);
55441
55443
  }
55442
- if (T.function?.arguments && !i && !a) {
55443
- if (g.get(S) === void 0) continue;
55444
- let H = m.get(S);
55444
+ if (S.function?.arguments && !a && !i) {
55445
+ if (_.get(P) === void 0) continue;
55446
+ let H = p.get(P);
55445
55447
  if (H) {
55446
- H.arguments += T.function.arguments;
55448
+ H.arguments += S.function.arguments;
55447
55449
  try {
55448
- let A = null, L = H.arguments.trim();
55449
- if (L.startsWith("{") && L.endsWith("}")) try {
55450
- A = JSON.parse(L);
55450
+ let A = null, N = H.arguments.trim();
55451
+ if (N.startsWith("{") && N.endsWith("}")) try {
55452
+ A = JSON.parse(N);
55451
55453
  } catch (M) {
55452
- v("Tool call index:", S, "error", M.message);
55454
+ v("Tool call index:", P, "error", M.message);
55453
55455
  }
55454
55456
  } catch (A) {
55455
- v("Tool call index:", S, "error", A.message);
55457
+ v("Tool call index:", P, "error", A.message);
55456
55458
  }
55457
55459
  }
55458
55460
  try {
55459
- let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: T.function.arguments } };
55460
- c(o.encode(`event: content_block_delta
55461
+ let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: S.function.arguments } };
55462
+ f(r.encode(`event: content_block_delta
55461
55463
  data: ${JSON.stringify(A)}
55462
55464
 
55463
55465
  `));
55464
55466
  } catch {
55465
55467
  try {
55466
- let L = T.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: L } };
55467
- c(o.encode(`event: content_block_delta
55468
+ let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: N } };
55469
+ f(r.encode(`event: content_block_delta
55468
55470
  data: ${JSON.stringify(M)}
55469
55471
 
55470
55472
  `));
55471
- } catch (L) {
55472
- console.error(L);
55473
+ } catch (N) {
55474
+ console.error(N);
55473
55475
  }
55474
55476
  }
55475
55477
  }
55476
55478
  }
55477
55479
  }
55478
- if (w?.finish_reason && !i && !a) {
55479
- if (a = true, p === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (f || u > 0) && !i) {
55480
+ if (w?.finish_reason && !a && !i) {
55481
+ if (i = true, g === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (d || u > 0) && !a) {
55480
55482
  v("content_block_stop hasTextContentStarted");
55481
- let x = { type: "content_block_stop", index: h };
55482
- c(o.encode(`event: content_block_stop
55483
- data: ${JSON.stringify(x)}
55483
+ let k = { type: "content_block_stop", index: h };
55484
+ f(r.encode(`event: content_block_stop
55485
+ data: ${JSON.stringify(k)}
55484
55486
 
55485
55487
  `));
55486
55488
  }
55487
- if (!i) {
55488
- let S = { 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
- c(o.encode(`event: message_delta
55490
- data: ${JSON.stringify(S)}
55489
+ if (!a) {
55490
+ 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 } };
55491
+ f(r.encode(`event: message_delta
55492
+ data: ${JSON.stringify(P)}
55491
55493
 
55492
55494
  `));
55493
55495
  }
55494
- if (!i) {
55495
- let x = { type: "message_stop" };
55496
- c(o.encode(`event: message_stop
55497
- data: ${JSON.stringify(x)}
55496
+ if (!a) {
55497
+ let k = { type: "message_stop" };
55498
+ f(r.encode(`event: message_stop
55499
+ data: ${JSON.stringify(k)}
55498
55500
 
55499
55501
  `));
55500
55502
  }
55501
55503
  break;
55502
55504
  }
55503
55505
  } catch (O) {
55504
- v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${K}`);
55506
+ v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${Q}`);
55505
55507
  }
55506
55508
  }
55507
55509
  }
55508
- k();
55509
- } catch (b) {
55510
- if (!i) try {
55511
- n.error(b);
55512
- } catch (_) {
55513
- console.error(_);
55510
+ m();
55511
+ } catch (x) {
55512
+ if (!a) try {
55513
+ n.error(x);
55514
+ } catch (R) {
55515
+ console.error(R);
55514
55516
  }
55515
55517
  } finally {
55516
- if (P) try {
55517
- P.releaseLock();
55518
- } catch (b) {
55519
- console.error(b);
55518
+ if (T) try {
55519
+ T.releaseLock();
55520
+ } catch (x) {
55521
+ console.error(x);
55520
55522
  }
55521
55523
  }
55522
55524
  }, cancel(n) {
@@ -55528,75 +55530,85 @@ data: ${JSON.stringify(x)}
55528
55530
  let t = e.choices[0];
55529
55531
  if (!t) throw new Error("No choices found in OpenAI response");
55530
55532
  let n = [];
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((r, d) => {
55533
+ 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, c) => {
55532
55534
  let l = {};
55533
55535
  try {
55534
- let f = r.function.arguments || "{}";
55535
- typeof f == "object" ? l = f : typeof f == "string" && (l = JSON.parse(f));
55536
+ let d = o.function.arguments || "{}";
55537
+ typeof d == "object" ? l = d : typeof d == "string" && (l = JSON.parse(d));
55536
55538
  } catch {
55537
- l = { text: r.function.arguments || "" };
55539
+ l = { text: o.function.arguments || "" };
55538
55540
  }
55539
- n.push({ type: "tool_use", id: r.id, name: r.function.name, input: l });
55541
+ n.push({ type: "tool_use", id: o.id, name: o.function.name, input: l });
55540
55542
  });
55541
- 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 } };
55542
- return v("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
55543
+ 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 } };
55544
+ return v("Conversion complete, final Anthropic response:", JSON.stringify(r, null, 2)), r;
55543
55545
  }
55544
55546
  };
55545
- var U = class {
55547
+ function ee(s) {
55548
+ if (!(!s || typeof s != "object")) {
55549
+ if (Array.isArray(s)) {
55550
+ s.forEach(ee);
55551
+ return;
55552
+ }
55553
+ 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) => {
55554
+ ee(s[e]);
55555
+ });
55556
+ }
55557
+ }
55558
+ var J = class {
55546
55559
  name = "gemini";
55547
55560
  endPoint = "/v1beta/models/:modelAndAction";
55548
- transformRequestIn(e, t) {
55561
+ async transformRequestIn(e, t) {
55549
55562
  return { body: { contents: e.messages.map((n) => {
55550
- let o;
55551
- n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
55552
- let r = [];
55553
- return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((d) => {
55554
- if (d.type === "text") return { text: d.text || "" };
55555
- })), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((d) => ({ functionCall: { id: d.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: d.function.name, args: JSON.parse(d.function.arguments || "{}") } }))), { role: o, parts: r };
55556
- }), 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) => {
55557
- 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);
55558
- }), { 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 } } };
55563
+ let r;
55564
+ n.role === "assistant" ? r = "model" : (["user", "system", "tool"].includes(n.role), r = "user");
55565
+ let o = [];
55566
+ return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((c) => {
55567
+ if (c.type === "text") return { text: c.text || "" };
55568
+ if (c.type === "image_url") return c.image_url.url.startsWith("http") ? { file_data: { mime_type: c.media_type, file_uri: c.image_url.url } } : { inlineData: { mime_type: c.media_type, data: c.image_url.url } };
55569
+ })), Array.isArray(n.tool_calls) && o.push(...n.tool_calls.map((c) => ({ functionCall: { id: c.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: c.function.name, args: JSON.parse(c.function.arguments || "{}") } }))), { role: r, parts: o };
55570
+ }), 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 } } };
55559
55571
  }
55560
55572
  transformRequestOut(e) {
55561
- let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, d = e.temperature, l = e.stream, f = e.tool_choice, a = { messages: [], model: o, max_tokens: r, temperature: d, stream: l, tool_choice: f };
55562
- return Array.isArray(t) && t.forEach((m) => {
55563
- typeof m == "string" ? a.messages.push({ role: "user", content: m }) : typeof m.text == "string" ? a.messages.push({ role: "user", content: m.text || null }) : m.role === "user" ? a.messages.push({ role: "user", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] }) : m.role === "model" && a.messages.push({ role: "assistant", content: m?.parts?.map((g) => ({ type: "text", text: g.text || "" })) || [] });
55564
- }), Array.isArray(n) && (a.tools = [], n.forEach((m) => {
55565
- Array.isArray(m.functionDeclarations) && m.functionDeclarations.forEach((g) => {
55566
- a.tools.push({ type: "function", function: { name: g.name, description: g.description, parameters: g.parameters } });
55573
+ let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens, c = e.temperature, l = e.stream, d = e.tool_choice, i = { messages: [], model: r, max_tokens: o, temperature: c, stream: l, tool_choice: d };
55574
+ return Array.isArray(t) && t.forEach((p) => {
55575
+ typeof p == "string" ? i.messages.push({ role: "user", content: p }) : typeof p.text == "string" ? i.messages.push({ role: "user", content: p.text || null }) : p.role === "user" ? i.messages.push({ role: "user", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] }) : p.role === "model" && i.messages.push({ role: "assistant", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] });
55576
+ }), Array.isArray(n) && (i.tools = [], n.forEach((p) => {
55577
+ Array.isArray(p.functionDeclarations) && p.functionDeclarations.forEach((_) => {
55578
+ i.tools.push({ type: "function", function: { name: _.name, description: _.description, parameters: _.parameters } });
55567
55579
  });
55568
- })), a;
55580
+ })), i;
55569
55581
  }
55570
55582
  async transformResponseOut(e) {
55571
55583
  if (e.headers.get("Content-Type")?.includes("application/json")) {
55572
- 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(`
55584
+ 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(`
55573
55585
  `), 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 } };
55574
- return new Response(JSON.stringify(o), { status: e.status, statusText: e.statusText, headers: e.headers });
55586
+ return new Response(JSON.stringify(r), { status: e.status, statusText: e.statusText, headers: e.headers });
55575
55587
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55576
55588
  if (!e.body) return e;
55577
- let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
55578
- let d = e.body.getReader();
55589
+ let t = new TextDecoder(), n = new TextEncoder(), r = new ReadableStream({ async start(o) {
55590
+ let c = e.body.getReader();
55579
55591
  try {
55580
55592
  for (; ; ) {
55581
- let { done: l, value: f } = await d.read();
55593
+ let { done: l, value: d } = await c.read();
55582
55594
  if (l) break;
55583
- let a = t.decode(f, { stream: true });
55584
- if (a.startsWith("data: ")) a = a.slice(6).trim();
55595
+ let i = t.decode(d, { stream: true });
55596
+ if (i.startsWith("data: ")) i = i.slice(6).trim();
55585
55597
  else break;
55586
- v("gemini chunk:", a), a = JSON.parse(a);
55587
- let m = a.candidates[0].content.parts.filter((C) => C.functionCall).map((C) => ({ id: C.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: C.functionCall?.name, arguments: JSON.stringify(C.functionCall?.args || {}) } })), g = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
55588
- `), tool_calls: m.length > 0 ? m : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || m.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" };
55589
- v("gemini response:", JSON.stringify(g, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(g)}
55598
+ v("gemini chunk:", i), i = JSON.parse(i);
55599
+ let p = i.candidates[0].content.parts.filter((C) => C.functionCall).map((C) => ({ id: C.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: C.functionCall?.name, arguments: JSON.stringify(C.functionCall?.args || {}) } })), _ = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
55600
+ `), tool_calls: p.length > 0 ? p : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || p.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" };
55601
+ v("gemini response:", JSON.stringify(_, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(_)}
55590
55602
 
55591
55603
  `));
55592
55604
  }
55593
55605
  } catch (l) {
55594
- r.error(l);
55606
+ o.error(l);
55595
55607
  } finally {
55596
- r.close();
55608
+ o.close();
55597
55609
  }
55598
55610
  } });
55599
- return new Response(o, { status: e.status, statusText: e.statusText, headers: e.headers });
55611
+ return new Response(r, { status: e.status, statusText: e.statusText, headers: e.headers });
55600
55612
  }
55601
55613
  return e;
55602
55614
  }
@@ -55612,29 +55624,29 @@ var j = class {
55612
55624
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55613
55625
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55614
55626
  if (!e.body) return e;
55615
- let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, d = new ReadableStream({ async start(l) {
55616
- let f = e.body.getReader();
55627
+ let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false, c = new ReadableStream({ async start(l) {
55628
+ let d = e.body.getReader();
55617
55629
  try {
55618
55630
  for (; ; ) {
55619
- let { done: a, value: m } = await f.read();
55620
- if (a) break;
55621
- let C = t.decode(m, { stream: true }).split(`
55631
+ let { done: i, value: p } = await d.read();
55632
+ if (i) break;
55633
+ let C = t.decode(p, { stream: true }).split(`
55622
55634
  `);
55623
- for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
55624
- let u = JSON.parse(p.slice(6));
55635
+ for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55636
+ let u = JSON.parse(g.slice(6));
55625
55637
  if (u.choices?.[0]?.delta?.reasoning_content) {
55626
- o += u.choices[0].delta.reasoning_content;
55627
- let i = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
55628
- delete i.choices[0].delta.reasoning_content;
55629
- let y = `data: ${JSON.stringify(i)}
55638
+ r += u.choices[0].delta.reasoning_content;
55639
+ let a = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
55640
+ delete a.choices[0].delta.reasoning_content;
55641
+ let y = `data: ${JSON.stringify(a)}
55630
55642
 
55631
55643
  `;
55632
55644
  l.enqueue(n.encode(y));
55633
55645
  continue;
55634
55646
  }
55635
- if (u.choices?.[0]?.delta?.content && o && !r) {
55636
- r = true;
55637
- let i = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: o, signature: i } } }] };
55647
+ if (u.choices?.[0]?.delta?.content && r && !o) {
55648
+ o = true;
55649
+ let a = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: r, signature: a } } }] };
55638
55650
  delete y.choices[0].delta.reasoning_content;
55639
55651
  let h = `data: ${JSON.stringify(y)}
55640
55652
 
@@ -55642,36 +55654,36 @@ var j = class {
55642
55654
  l.enqueue(n.encode(h));
55643
55655
  }
55644
55656
  if (u.choices[0]?.delta?.reasoning_content && delete u.choices[0].delta.reasoning_content, u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
55645
- r && u.choices[0].index++;
55646
- let i = `data: ${JSON.stringify(u)}
55657
+ o && u.choices[0].index++;
55658
+ let a = `data: ${JSON.stringify(u)}
55647
55659
 
55648
55660
  `;
55649
- l.enqueue(n.encode(i));
55661
+ l.enqueue(n.encode(a));
55650
55662
  }
55651
55663
  } catch {
55652
- l.enqueue(n.encode(p + `
55664
+ l.enqueue(n.encode(g + `
55653
55665
  `));
55654
55666
  }
55655
- else l.enqueue(n.encode(p + `
55667
+ else l.enqueue(n.encode(g + `
55656
55668
  `));
55657
55669
  }
55658
- } catch (a) {
55659
- l.error(a);
55670
+ } catch (i) {
55671
+ l.error(i);
55660
55672
  } finally {
55661
55673
  try {
55662
- f.releaseLock();
55663
- } catch (a) {
55664
- console.error("Error releasing reader lock:", a);
55674
+ d.releaseLock();
55675
+ } catch (i) {
55676
+ console.error("Error releasing reader lock:", i);
55665
55677
  }
55666
55678
  l.close();
55667
55679
  }
55668
55680
  } });
55669
- return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55681
+ 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" } });
55670
55682
  }
55671
55683
  return e;
55672
55684
  }
55673
55685
  };
55674
- var J = class {
55686
+ var D = class {
55675
55687
  name = "tooluse";
55676
55688
  transformRequestIn(e) {
55677
55689
  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.
@@ -55684,31 +55696,31 @@ Examples:
55684
55696
  if (e.headers.get("Content-Type")?.includes("application/json")) {
55685
55697
  let t = await e.json();
55686
55698
  if (t?.choices[0]?.message.tool_calls?.length && t?.choices[0]?.message.tool_calls[0]?.function?.name === "ExitTool") {
55687
- let n = t?.choices[0]?.message.tool_calls[0], o = JSON.parse(n.function.arguments || "{}");
55688
- t.choices[0].message.content = o.response || "", delete t.choices[0].message.tool_calls;
55699
+ let n = t?.choices[0]?.message.tool_calls[0], r = JSON.parse(n.function.arguments || "{}");
55700
+ t.choices[0].message.content = r.response || "", delete t.choices[0].message.tool_calls;
55689
55701
  }
55690
55702
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55691
55703
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55692
55704
  if (!e.body) return e;
55693
- let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", d = new ReadableStream({ async start(l) {
55694
- let f = e.body.getReader();
55705
+ let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "", c = new ReadableStream({ async start(l) {
55706
+ let d = e.body.getReader();
55695
55707
  try {
55696
55708
  for (; ; ) {
55697
- let { done: a, value: m } = await f.read();
55698
- if (a) break;
55699
- let C = t.decode(m, { stream: true }).split(`
55709
+ let { done: i, value: p } = await d.read();
55710
+ if (i) break;
55711
+ let C = t.decode(p, { stream: true }).split(`
55700
55712
  `);
55701
- for (let p of C) if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") try {
55702
- let u = JSON.parse(p.slice(6));
55713
+ for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55714
+ let u = JSON.parse(g.slice(6));
55703
55715
  if (u.choices[0]?.delta?.tool_calls?.length) {
55704
- let i = u.choices[0].delta.tool_calls[0];
55705
- if (i.function?.name === "ExitTool") {
55706
- o = i.index;
55716
+ let a = u.choices[0].delta.tool_calls[0];
55717
+ if (a.function?.name === "ExitTool") {
55718
+ r = a.index;
55707
55719
  continue;
55708
- } else if (o > -1 && i.index === o && i.function.arguments) {
55709
- r += i.function.arguments;
55720
+ } else if (r > -1 && a.index === r && a.function.arguments) {
55721
+ o += a.function.arguments;
55710
55722
  try {
55711
- let y = JSON.parse(r);
55723
+ let y = JSON.parse(o);
55712
55724
  u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
55713
55725
  let h = `data: ${JSON.stringify(u)}
55714
55726
 
@@ -55720,40 +55732,64 @@ Examples:
55720
55732
  }
55721
55733
  }
55722
55734
  if (u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
55723
- let i = `data: ${JSON.stringify(u)}
55735
+ let a = `data: ${JSON.stringify(u)}
55724
55736
 
55725
55737
  `;
55726
- l.enqueue(n.encode(i));
55738
+ l.enqueue(n.encode(a));
55727
55739
  }
55728
55740
  } catch {
55729
- l.enqueue(n.encode(p + `
55741
+ l.enqueue(n.encode(g + `
55730
55742
  `));
55731
55743
  }
55732
- else l.enqueue(n.encode(p + `
55744
+ else l.enqueue(n.encode(g + `
55733
55745
  `));
55734
55746
  }
55735
- } catch (a) {
55736
- l.error(a);
55747
+ } catch (i) {
55748
+ l.error(i);
55737
55749
  } finally {
55738
55750
  try {
55739
- f.releaseLock();
55740
- } catch (a) {
55741
- console.error("Error releasing reader lock:", a);
55751
+ d.releaseLock();
55752
+ } catch (i) {
55753
+ console.error("Error releasing reader lock:", i);
55742
55754
  }
55743
55755
  l.close();
55744
55756
  }
55745
55757
  } });
55746
- return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55758
+ 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" } });
55747
55759
  }
55748
55760
  return e;
55749
55761
  }
55750
55762
  };
55751
- var D = class {
55763
+ var b = [];
55764
+ for (let s = 0; s < 256; ++s) b.push((s + 256).toString(16).slice(1));
55765
+ function fe(s, e = 0) {
55766
+ 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();
55767
+ }
55768
+ var W = new Uint8Array(256);
55769
+ var B = W.length;
55770
+ function te() {
55771
+ return B > W.length - 16 && ((0, import_crypto.randomFillSync)(W), B = 0), W.slice(B, B += 16);
55772
+ }
55773
+ var ne = { randomUUID: import_crypto2.randomUUID };
55774
+ function Re(s, e, t) {
55775
+ if (ne.randomUUID && !e && !s) return ne.randomUUID();
55776
+ s = s || {};
55777
+ let n = s.random ?? s.rng?.() ?? te();
55778
+ if (n.length < 16) throw new Error("Random bytes length must be >= 16");
55779
+ if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
55780
+ if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
55781
+ for (let r = 0; r < 16; ++r) e[t + r] = n[r];
55782
+ return e;
55783
+ }
55784
+ return fe(n);
55785
+ }
55786
+ var I = Re;
55787
+ var z = class {
55752
55788
  name = "openrouter";
55753
- transformRequestIn(e) {
55789
+ async transformRequestIn(e) {
55754
55790
  return e.model.includes("claude") || e.messages.forEach((t) => {
55755
55791
  Array.isArray(t.content) ? t.content.forEach((n) => {
55756
- n.cache_control && delete n.cache_control;
55792
+ n.cache_control && delete n.cache_control, n.type === "image_url" && (n.image_url.url.startsWith("http") || (n.image_url.url = `data:${n.media_type};base64,${n.image_url.url}`), delete n.media_type);
55757
55793
  }) : t.cache_control && delete t.cache_control;
55758
55794
  }), e;
55759
55795
  }
@@ -55763,105 +55799,109 @@ var D = class {
55763
55799
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55764
55800
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55765
55801
  if (!e.body) return e;
55766
- let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
55767
- let m = e.body.getReader(), g = (p, u, i) => {
55768
- let y = p.split(`
55802
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = false, d = "", i = new ReadableStream({ async start(p) {
55803
+ let _ = e.body.getReader(), C = (u, a, y) => {
55804
+ let h = u.split(`
55769
55805
  `);
55770
- for (let h of y) h.trim() && u.enqueue(i.encode(h + `
55806
+ for (let f of h) f.trim() && a.enqueue(y.encode(f + `
55771
55807
  `));
55772
- }, C = (p, u) => {
55773
- let { controller: i, encoder: y } = u;
55774
- if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
55775
- let h = p.slice(6);
55808
+ }, g = (u, a) => {
55809
+ let { controller: y, encoder: h } = a;
55810
+ if (u.startsWith("data: ") && u.trim() !== "data: [DONE]") {
55811
+ let f = u.slice(6);
55776
55812
  try {
55777
- let c = JSON.parse(h);
55778
- if (c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.reasoning) {
55779
- u.appendReasoningContent(c.choices[0].delta.reasoning);
55780
- let P = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, thinking: { content: c.choices[0].delta.reasoning } } }] };
55781
- P.choices?.[0]?.delta && delete P.choices[0].delta.reasoning;
55782
- let b = `data: ${JSON.stringify(P)}
55813
+ let m = JSON.parse(f);
55814
+ if (m.usage && (v("usage", m.usage, l), m.choices[0].finish_reason = l ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && y.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
55815
+
55816
+ `)), m.choices?.[0]?.delta?.content && !a.hasTextContent() && a.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
55817
+ a.appendReasoningContent(m.choices[0].delta.reasoning);
55818
+ let x = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning } } }] };
55819
+ x.choices?.[0]?.delta && delete x.choices[0].delta.reasoning;
55820
+ let R = `data: ${JSON.stringify(x)}
55783
55821
 
55784
55822
  `;
55785
- i.enqueue(y.encode(b));
55823
+ y.enqueue(h.encode(R));
55786
55824
  return;
55787
55825
  }
55788
- if (c.choices?.[0]?.delta?.content && u.reasoningContent() && !u.isReasoningComplete()) {
55789
- u.setReasoningComplete(true);
55790
- let P = Date.now().toString(), b = { ...c, choices: [{ ...c.choices?.[0], delta: { ...c.choices[0].delta, content: null, thinking: { content: u.reasoningContent(), signature: P } } }] };
55791
- b.choices?.[0]?.delta && delete b.choices[0].delta.reasoning;
55792
- let _ = `data: ${JSON.stringify(b)}
55826
+ if (m.choices?.[0]?.delta?.content && a.reasoningContent() && !a.isReasoningComplete()) {
55827
+ a.setReasoningComplete(true);
55828
+ let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: a.reasoningContent(), signature: x } } }] };
55829
+ R.choices?.[0]?.delta && delete R.choices[0].delta.reasoning;
55830
+ let X = `data: ${JSON.stringify(R)}
55793
55831
 
55794
55832
  `;
55795
- i.enqueue(y.encode(_));
55833
+ y.enqueue(h.encode(X));
55796
55834
  }
55797
- c.choices?.[0]?.delta?.reasoning && delete c.choices[0].delta.reasoning, c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
55798
- let k = `data: ${JSON.stringify(c)}
55835
+ 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) => {
55836
+ x.id = `call_${I()}`;
55837
+ }), m.choices?.[0]?.delta?.tool_calls?.length && !l && (v("hasToolCall", true), l = true), m.choices?.[0]?.delta?.tool_calls?.length && a.hasTextContent() && (typeof m.choices[0].index == "number" ? m.choices[0].index += 1 : m.choices[0].index = 1);
55838
+ let T = `data: ${JSON.stringify(m)}
55799
55839
 
55800
55840
  `;
55801
- i.enqueue(y.encode(k));
55841
+ y.enqueue(h.encode(T));
55802
55842
  } catch {
55803
- i.enqueue(y.encode(p + `
55843
+ y.enqueue(h.encode(u + `
55804
55844
  `));
55805
55845
  }
55806
- } else i.enqueue(y.encode(p + `
55846
+ } else y.enqueue(h.encode(u + `
55807
55847
  `));
55808
55848
  };
55809
55849
  try {
55810
55850
  for (; ; ) {
55811
- let { done: p, value: u } = await m.read();
55812
- if (p) {
55813
- l.trim() && g(l, a, n);
55851
+ let { done: u, value: a } = await _.read();
55852
+ if (u) {
55853
+ d.trim() && C(d, p, n);
55814
55854
  break;
55815
55855
  }
55816
- if (!u || u.length === 0) continue;
55817
- let i;
55856
+ if (!a || a.length === 0) continue;
55857
+ let y;
55818
55858
  try {
55819
- i = t.decode(u, { stream: true });
55820
- } catch (h) {
55821
- console.warn("Failed to decode chunk", h);
55859
+ y = t.decode(a, { stream: true });
55860
+ } catch (f) {
55861
+ console.warn("Failed to decode chunk", f);
55822
55862
  continue;
55823
55863
  }
55824
- if (i.length === 0) continue;
55825
- if (l += i, l.length > 1e6) {
55864
+ if (y.length === 0) continue;
55865
+ if (d += y, d.length > 1e6) {
55826
55866
  console.warn("Buffer size exceeds limit, processing partial data");
55827
- let h = l.split(`
55867
+ let f = d.split(`
55828
55868
  `);
55829
- l = h.pop() || "";
55830
- for (let c of h) if (c.trim()) try {
55831
- C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
55832
- } catch (k) {
55833
- console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
55869
+ d = f.pop() || "";
55870
+ for (let m of f) if (m.trim()) try {
55871
+ g(m, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (T) => r = T, reasoningContent: () => o, appendReasoningContent: (T) => o += T, isReasoningComplete: () => c, setReasoningComplete: (T) => c = T });
55872
+ } catch (T) {
55873
+ console.error("Error processing line:", m, T), p.enqueue(n.encode(m + `
55834
55874
  `));
55835
55875
  }
55836
55876
  continue;
55837
55877
  }
55838
- let y = l.split(`
55878
+ let h = d.split(`
55839
55879
  `);
55840
- l = y.pop() || "";
55841
- for (let h of y) if (h.trim()) try {
55842
- C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
55843
- } catch (c) {
55844
- console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
55880
+ d = h.pop() || "";
55881
+ for (let f of h) if (f.trim()) try {
55882
+ g(f, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
55883
+ } catch (m) {
55884
+ console.error("Error processing line:", f, m), p.enqueue(n.encode(f + `
55845
55885
  `));
55846
55886
  }
55847
55887
  }
55848
- } catch (p) {
55849
- console.error("Stream error:", p), a.error(p);
55888
+ } catch (u) {
55889
+ console.error("Stream error:", u), p.error(u);
55850
55890
  } finally {
55851
55891
  try {
55852
- m.releaseLock();
55853
- } catch (p) {
55854
- console.error("Error releasing reader lock:", p);
55892
+ _.releaseLock();
55893
+ } catch (u) {
55894
+ console.error("Error releasing reader lock:", u);
55855
55895
  }
55856
- a.close();
55896
+ p.close();
55857
55897
  }
55858
55898
  } });
55859
- return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55899
+ return new Response(i, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55860
55900
  }
55861
55901
  return e;
55862
55902
  }
55863
55903
  };
55864
- var B = class {
55904
+ var V = class {
55865
55905
  constructor(e) {
55866
55906
  this.options = e;
55867
55907
  this.max_tokens = this.options?.max_tokens;
@@ -55872,31 +55912,7 @@ var B = class {
55872
55912
  return e.max_tokens && e.max_tokens > this.max_tokens && (e.max_tokens = this.max_tokens), e;
55873
55913
  }
55874
55914
  };
55875
- var R = [];
55876
- for (let s = 0; s < 256; ++s) R.push((s + 256).toString(16).slice(1));
55877
- function le(s, e = 0) {
55878
- return (R[s[e + 0]] + R[s[e + 1]] + R[s[e + 2]] + R[s[e + 3]] + "-" + R[s[e + 4]] + R[s[e + 5]] + "-" + R[s[e + 6]] + R[s[e + 7]] + "-" + R[s[e + 8]] + R[s[e + 9]] + "-" + R[s[e + 10]] + R[s[e + 11]] + R[s[e + 12]] + R[s[e + 13]] + R[s[e + 14]] + R[s[e + 15]]).toLowerCase();
55879
- }
55880
- var V = new Uint8Array(256);
55881
- var z = V.length;
55882
- function X() {
55883
- return z > V.length - 16 && ((0, import_crypto.randomFillSync)(V), z = 0), V.slice(z, z += 16);
55884
- }
55885
- var Q = { randomUUID: import_crypto2.randomUUID };
55886
- function xe(s, e, t) {
55887
- if (Q.randomUUID && !e && !s) return Q.randomUUID();
55888
- s = s || {};
55889
- let n = s.random ?? s.rng?.() ?? X();
55890
- if (n.length < 16) throw new Error("Random bytes length must be >= 16");
55891
- if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
55892
- if (t = t || 0, t < 0 || t + 16 > e.length) throw new RangeError(`UUID byte range ${t}:${t + 15} is out of buffer bounds`);
55893
- for (let o = 0; o < 16; ++o) e[t + o] = n[o];
55894
- return e;
55895
- }
55896
- return le(n);
55897
- }
55898
- var Z = xe;
55899
- var W = class {
55915
+ var G = class {
55900
55916
  name = "groq";
55901
55917
  async transformRequestIn(e) {
55902
55918
  return e.messages.forEach((t) => {
@@ -55913,58 +55929,58 @@ var W = class {
55913
55929
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55914
55930
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55915
55931
  if (!e.body) return e;
55916
- let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", d = false, l = "", f = new ReadableStream({ async start(a) {
55917
- let m = e.body.getReader(), g = (p, u, i) => {
55918
- let y = p.split(`
55932
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = "", d = new ReadableStream({ async start(i) {
55933
+ let p = e.body.getReader(), _ = (g, u, a) => {
55934
+ let y = g.split(`
55919
55935
  `);
55920
- for (let h of y) h.trim() && u.enqueue(i.encode(h + `
55936
+ for (let h of y) h.trim() && u.enqueue(a.encode(h + `
55921
55937
  `));
55922
- }, C = (p, u) => {
55923
- let { controller: i, encoder: y } = u;
55924
- if (p.startsWith("data: ") && p.trim() !== "data: [DONE]") {
55925
- let h = p.slice(6);
55938
+ }, C = (g, u) => {
55939
+ let { controller: a, encoder: y } = u;
55940
+ if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") {
55941
+ let h = g.slice(6);
55926
55942
  try {
55927
- let c = JSON.parse(h);
55928
- if (c.error) throw new Error(JSON.stringify(c));
55929
- c.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), c.choices?.[0]?.delta?.tool_calls?.length && c.choices?.[0]?.delta?.tool_calls.forEach((P) => {
55930
- P.id = `call_${Z()}`;
55931
- }), c.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof c.choices[0].index == "number" ? c.choices[0].index += 1 : c.choices[0].index = 1);
55932
- let k = `data: ${JSON.stringify(c)}
55943
+ let f = JSON.parse(h);
55944
+ if (f.error) throw new Error(JSON.stringify(f));
55945
+ f.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), f.choices?.[0]?.delta?.tool_calls?.length && f.choices?.[0]?.delta?.tool_calls.forEach((T) => {
55946
+ T.id = `call_${I()}`;
55947
+ }), f.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof f.choices[0].index == "number" ? f.choices[0].index += 1 : f.choices[0].index = 1);
55948
+ let m = `data: ${JSON.stringify(f)}
55933
55949
 
55934
55950
  `;
55935
- i.enqueue(y.encode(k));
55951
+ a.enqueue(y.encode(m));
55936
55952
  } catch {
55937
- i.enqueue(y.encode(p + `
55953
+ a.enqueue(y.encode(g + `
55938
55954
  `));
55939
55955
  }
55940
- } else i.enqueue(y.encode(p + `
55956
+ } else a.enqueue(y.encode(g + `
55941
55957
  `));
55942
55958
  };
55943
55959
  try {
55944
55960
  for (; ; ) {
55945
- let { done: p, value: u } = await m.read();
55946
- if (p) {
55947
- l.trim() && g(l, a, n);
55961
+ let { done: g, value: u } = await p.read();
55962
+ if (g) {
55963
+ l.trim() && _(l, i, n);
55948
55964
  break;
55949
55965
  }
55950
55966
  if (!u || u.length === 0) continue;
55951
- let i;
55967
+ let a;
55952
55968
  try {
55953
- i = t.decode(u, { stream: true });
55969
+ a = t.decode(u, { stream: true });
55954
55970
  } catch (h) {
55955
55971
  console.warn("Failed to decode chunk", h);
55956
55972
  continue;
55957
55973
  }
55958
- if (i.length === 0) continue;
55959
- if (l += i, l.length > 1e6) {
55974
+ if (a.length === 0) continue;
55975
+ if (l += a, l.length > 1e6) {
55960
55976
  console.warn("Buffer size exceeds limit, processing partial data");
55961
55977
  let h = l.split(`
55962
55978
  `);
55963
55979
  l = h.pop() || "";
55964
- for (let c of h) if (c.trim()) try {
55965
- C(c, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (k) => o = k, reasoningContent: () => r, appendReasoningContent: (k) => r += k, isReasoningComplete: () => d, setReasoningComplete: (k) => d = k });
55966
- } catch (k) {
55967
- console.error("Error processing line:", c, k), a.enqueue(n.encode(c + `
55980
+ for (let f of h) if (f.trim()) try {
55981
+ C(f, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
55982
+ } catch (m) {
55983
+ console.error("Error processing line:", f, m), i.enqueue(n.encode(f + `
55968
55984
  `));
55969
55985
  }
55970
55986
  continue;
@@ -55973,30 +55989,40 @@ var W = class {
55973
55989
  `);
55974
55990
  l = y.pop() || "";
55975
55991
  for (let h of y) if (h.trim()) try {
55976
- C(h, { controller: a, encoder: n, hasTextContent: () => o, setHasTextContent: (c) => o = c, reasoningContent: () => r, appendReasoningContent: (c) => r += c, isReasoningComplete: () => d, setReasoningComplete: (c) => d = c });
55977
- } catch (c) {
55978
- console.error("Error processing line:", h, c), a.enqueue(n.encode(h + `
55992
+ C(h, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (f) => r = f, reasoningContent: () => o, appendReasoningContent: (f) => o += f, isReasoningComplete: () => c, setReasoningComplete: (f) => c = f });
55993
+ } catch (f) {
55994
+ console.error("Error processing line:", h, f), i.enqueue(n.encode(h + `
55979
55995
  `));
55980
55996
  }
55981
55997
  }
55982
- } catch (p) {
55983
- console.error("Stream error:", p), a.error(p);
55998
+ } catch (g) {
55999
+ console.error("Stream error:", g), i.error(g);
55984
56000
  } finally {
55985
56001
  try {
55986
- m.releaseLock();
55987
- } catch (p) {
55988
- console.error("Error releasing reader lock:", p);
56002
+ p.releaseLock();
56003
+ } catch (g) {
56004
+ console.error("Error releasing reader lock:", g);
55989
56005
  }
55990
- a.close();
56006
+ i.close();
55991
56007
  }
55992
56008
  } });
55993
- return new Response(f, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
56009
+ return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55994
56010
  }
55995
56011
  return e;
55996
56012
  }
55997
56013
  };
55998
- var de = { AnthropicTransformer: q, GeminiTransformer: U, DeepseekTransformer: j, TooluseTransformer: J, OpenrouterTransformer: D, MaxTokenTransformer: B, GroqTransformer: W };
55999
- var G = class {
56014
+ var K = class {
56015
+ name = "cleancache";
56016
+ async transformRequestIn(e) {
56017
+ return Array.isArray(e.messages) && e.messages.forEach((t) => {
56018
+ Array.isArray(t.content) ? t.content.forEach((n) => {
56019
+ n.cache_control && delete n.cache_control;
56020
+ }) : t.cache_control && delete t.cache_control;
56021
+ }), e;
56022
+ }
56023
+ };
56024
+ var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer: z, MaxTokenTransformer: V, GroqTransformer: G, CleancacheTransformer: K };
56025
+ var Y = class {
56000
56026
  constructor(e) {
56001
56027
  this.configService = e;
56002
56028
  }
@@ -56031,14 +56057,14 @@ var G = class {
56031
56057
  async registerTransformerFromConfig(e) {
56032
56058
  try {
56033
56059
  let t = import_node_module.default._load;
56034
- if (import_node_module.default._load = function(n, o, r) {
56060
+ if (import_node_module.default._load = function(n, r, o) {
56035
56061
  return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
56036
56062
  }, e.path) {
56037
- let n = Y(Y.resolve(e.path));
56063
+ let n = Z(Z.resolve(e.path));
56038
56064
  if (n) {
56039
- let o = new n(e.options);
56040
- if (!o.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
56041
- return this.registerTransformer(o.name, o), true;
56065
+ let r = new n(e.options);
56066
+ if (!r.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
56067
+ return this.registerTransformer(r.name, r), true;
56042
56068
  }
56043
56069
  }
56044
56070
  return false;
@@ -56055,7 +56081,7 @@ var G = class {
56055
56081
  }
56056
56082
  async registerDefaultTransformersInternal() {
56057
56083
  try {
56058
- Object.values(de).forEach((e) => {
56084
+ Object.values(pe).forEach((e) => {
56059
56085
  if ("TransformerName" in e && typeof e.TransformerName == "string") this.registerTransformer(e.TransformerName, e);
56060
56086
  else {
56061
56087
  let t = new e();
@@ -56071,20 +56097,20 @@ var G = class {
56071
56097
  for (let t of e) await this.registerTransformerFromConfig(t);
56072
56098
  }
56073
56099
  };
56074
- function _e() {
56075
- let s = (0, import_fastify.default)({});
56076
- return s.setErrorHandler(ie), s.register(import_cors.default), s;
56100
+ function Se() {
56101
+ let s = (0, import_fastify.default)({ bodyLimit: 52428800 });
56102
+ return s.setErrorHandler(le), s.register(import_cors.default), s;
56077
56103
  }
56078
- var te = class {
56104
+ var re = class {
56079
56105
  app;
56080
56106
  configService;
56081
56107
  llmService;
56082
56108
  providerService;
56083
56109
  transformerService;
56084
56110
  constructor(e = {}) {
56085
- this.configService = new I(e), this.transformerService = new G(this.configService), this.transformerService.initialize().finally(() => {
56086
- this.providerService = new F(this.configService, this.transformerService), this.llmService = new $(this.providerService);
56087
- }), this.app = _e();
56111
+ this.configService = new $(e), this.transformerService = new Y(this.configService), this.transformerService.initialize().finally(() => {
56112
+ this.providerService = new F(this.configService, this.transformerService), this.llmService = new q(this.providerService);
56113
+ }), this.app = Se();
56088
56114
  }
56089
56115
  async register(e, t) {
56090
56116
  await this.app.register(e, t);
@@ -56094,17 +56120,17 @@ var te = class {
56094
56120
  }
56095
56121
  async start() {
56096
56122
  try {
56097
- this.app._server = this, this.app.addHook("preHandler", async (n, o) => {
56123
+ this.app._server = this, this.app.addHook("preHandler", async (n, r) => {
56098
56124
  try {
56099
- let r = n.body;
56100
- if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
56101
- let [d, l] = r.model.split(",");
56102
- r.model = l, n.provider = d;
56125
+ let o = n.body;
56126
+ if (!o || !o.model) return r.code(400).send({ error: "Missing model in request body" });
56127
+ let [c, l] = o.model.split(",");
56128
+ o.model = l, n.provider = c;
56103
56129
  return;
56104
- } catch (r) {
56105
- return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
56130
+ } catch (o) {
56131
+ return n.log.error("Error in modelProviderMiddleware:", o), r.code(500).send({ error: "Internal server error" });
56106
56132
  }
56107
- }), this.app.register(ce);
56133
+ }), this.app.register(ue);
56108
56134
  let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
56109
56135
  v(`\u{1F680} LLMs API server listening on ${e}`);
56110
56136
  let t = async (n) => {
@@ -56116,11 +56142,11 @@ var te = class {
56116
56142
  }
56117
56143
  }
56118
56144
  };
56119
- var tn = te;
56145
+ var cn = re;
56120
56146
 
56121
56147
  // src/server.ts
56122
56148
  var createServer = (config) => {
56123
- const server = new tn(config);
56149
+ const server = new cn(config);
56124
56150
  return server;
56125
56151
  };
56126
56152
 
@@ -56312,14 +56338,15 @@ function getServicePid() {
56312
56338
  return null;
56313
56339
  }
56314
56340
  }
56315
- function getServiceInfo() {
56341
+ async function getServiceInfo() {
56316
56342
  const pid = getServicePid();
56317
56343
  const running = isServiceRunning();
56344
+ const config = await readConfigFile();
56318
56345
  return {
56319
56346
  running,
56320
56347
  pid,
56321
- port: 3456,
56322
- endpoint: "http://127.0.0.1:3456",
56348
+ port: config.PORT,
56349
+ endpoint: `http://127.0.0.1:${config.PORT}`,
56323
56350
  pidFile: PID_FILE,
56324
56351
  referenceCount: getReferenceCount()
56325
56352
  };
@@ -56360,7 +56387,7 @@ async function run(options = {}) {
56360
56387
  "\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
56361
56388
  );
56362
56389
  }
56363
- const port = options.port || 3456;
56390
+ const port = config.PORT || 3456;
56364
56391
  savePid(process.pid);
56365
56392
  process.on("SIGINT", () => {
56366
56393
  console.log("Received SIGINT, cleaning up...");
@@ -56396,8 +56423,8 @@ async function run(options = {}) {
56396
56423
  }
56397
56424
 
56398
56425
  // src/utils/status.ts
56399
- function showStatus() {
56400
- const info = getServiceInfo();
56426
+ async function showStatus() {
56427
+ const info = await getServiceInfo();
56401
56428
  console.log("\n\u{1F4CA} Claude Code Router Status");
56402
56429
  console.log("\u2550".repeat(40));
56403
56430
  if (info.running) {
@@ -56451,7 +56478,7 @@ async function executeCodeCommand(args = []) {
56451
56478
  const env = {
56452
56479
  ...process.env,
56453
56480
  ANTHROPIC_AUTH_TOKEN: "test",
56454
- ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`,
56481
+ ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
56455
56482
  API_TIMEOUT_MS: "600000"
56456
56483
  };
56457
56484
  if (config?.APIKEY) {
@@ -56481,7 +56508,7 @@ async function executeCodeCommand(args = []) {
56481
56508
  }
56482
56509
 
56483
56510
  // package.json
56484
- var version = "1.0.20";
56511
+ var version = "1.0.22";
56485
56512
 
56486
56513
  // src/cli.ts
56487
56514
  var import_child_process2 = require("child_process");
@@ -56542,7 +56569,7 @@ async function main() {
56542
56569
  }
56543
56570
  break;
56544
56571
  case "status":
56545
- showStatus();
56572
+ await showStatus();
56546
56573
  break;
56547
56574
  case "code":
56548
56575
  if (!isServiceRunning()) {