@musistudio/claude-code-router 1.0.11 → 1.0.13

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.
Files changed (3) hide show
  1. package/README.md +4 -3
  2. package/dist/cli.js +681 -634
  3. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -4311,32 +4311,32 @@ var require_quick_format_unescaped = __commonJS({
4311
4311
  }
4312
4312
  }
4313
4313
  module2.exports = format;
4314
- function format(f2, args, opts) {
4314
+ function format(f, args, opts) {
4315
4315
  var ss = opts && opts.stringify || tryStringify;
4316
4316
  var offset = 1;
4317
- if (typeof f2 === "object" && f2 !== null) {
4317
+ if (typeof f === "object" && f !== null) {
4318
4318
  var len = args.length + offset;
4319
- if (len === 1) return f2;
4319
+ if (len === 1) return f;
4320
4320
  var objects = new Array(len);
4321
- objects[0] = ss(f2);
4321
+ objects[0] = ss(f);
4322
4322
  for (var index = 1; index < len; index++) {
4323
4323
  objects[index] = ss(args[index]);
4324
4324
  }
4325
4325
  return objects.join(" ");
4326
4326
  }
4327
- if (typeof f2 !== "string") {
4328
- return f2;
4327
+ if (typeof f !== "string") {
4328
+ return f;
4329
4329
  }
4330
4330
  var argLen = args.length;
4331
- if (argLen === 0) return f2;
4331
+ if (argLen === 0) return f;
4332
4332
  var str = "";
4333
4333
  var a = 1 - offset;
4334
4334
  var lastPos = -1;
4335
- var flen = f2 && f2.length || 0;
4335
+ var flen = f && f.length || 0;
4336
4336
  for (var i = 0; i < flen; ) {
4337
- if (f2.charCodeAt(i) === 37 && i + 1 < flen) {
4337
+ if (f.charCodeAt(i) === 37 && i + 1 < flen) {
4338
4338
  lastPos = lastPos > -1 ? lastPos : 0;
4339
- switch (f2.charCodeAt(i + 1)) {
4339
+ switch (f.charCodeAt(i + 1)) {
4340
4340
  case 100:
4341
4341
  // 'd'
4342
4342
  case 102:
@@ -4344,7 +4344,7 @@ var require_quick_format_unescaped = __commonJS({
4344
4344
  break;
4345
4345
  if (args[a] == null) break;
4346
4346
  if (lastPos < i)
4347
- str += f2.slice(lastPos, i);
4347
+ str += f.slice(lastPos, i);
4348
4348
  str += Number(args[a]);
4349
4349
  lastPos = i + 2;
4350
4350
  i++;
@@ -4354,7 +4354,7 @@ var require_quick_format_unescaped = __commonJS({
4354
4354
  break;
4355
4355
  if (args[a] == null) break;
4356
4356
  if (lastPos < i)
4357
- str += f2.slice(lastPos, i);
4357
+ str += f.slice(lastPos, i);
4358
4358
  str += Math.floor(Number(args[a]));
4359
4359
  lastPos = i + 2;
4360
4360
  i++;
@@ -4368,7 +4368,7 @@ var require_quick_format_unescaped = __commonJS({
4368
4368
  break;
4369
4369
  if (args[a] === void 0) break;
4370
4370
  if (lastPos < i)
4371
- str += f2.slice(lastPos, i);
4371
+ str += f.slice(lastPos, i);
4372
4372
  var type = typeof args[a];
4373
4373
  if (type === "string") {
4374
4374
  str += "'" + args[a] + "'";
@@ -4390,14 +4390,14 @@ var require_quick_format_unescaped = __commonJS({
4390
4390
  if (a >= argLen)
4391
4391
  break;
4392
4392
  if (lastPos < i)
4393
- str += f2.slice(lastPos, i);
4393
+ str += f.slice(lastPos, i);
4394
4394
  str += String(args[a]);
4395
4395
  lastPos = i + 2;
4396
4396
  i++;
4397
4397
  break;
4398
4398
  case 37:
4399
4399
  if (lastPos < i)
4400
- str += f2.slice(lastPos, i);
4400
+ str += f.slice(lastPos, i);
4401
4401
  str += "%";
4402
4402
  lastPos = i + 2;
4403
4403
  i++;
@@ -4409,9 +4409,9 @@ var require_quick_format_unescaped = __commonJS({
4409
4409
  ++i;
4410
4410
  }
4411
4411
  if (lastPos === -1)
4412
- return f2;
4412
+ return f;
4413
4413
  else if (lastPos < flen) {
4414
- str += f2.slice(lastPos);
4414
+ str += f.slice(lastPos);
4415
4415
  }
4416
4416
  return str;
4417
4417
  }
@@ -13188,12 +13188,12 @@ var require_util = __commonJS({
13188
13188
  return str.replace(/~1/g, "/").replace(/~0/g, "~");
13189
13189
  }
13190
13190
  exports2.unescapeJsonPointer = unescapeJsonPointer;
13191
- function eachItem(xs, f2) {
13191
+ function eachItem(xs, f) {
13192
13192
  if (Array.isArray(xs)) {
13193
13193
  for (const x of xs)
13194
- f2(x);
13194
+ f(x);
13195
13195
  } else {
13196
- f2(xs);
13196
+ f(xs);
13197
13197
  }
13198
13198
  }
13199
13199
  exports2.eachItem = eachItem;
@@ -13240,10 +13240,10 @@ var require_util = __commonJS({
13240
13240
  }
13241
13241
  exports2.setEvaluated = setEvaluated;
13242
13242
  var snippets = {};
13243
- function useFunc(gen, f2) {
13243
+ function useFunc(gen, f) {
13244
13244
  return gen.scopeValue("func", {
13245
- ref: f2,
13246
- code: snippets[f2.code] || (snippets[f2.code] = new code_1._Code(f2.code))
13245
+ ref: f,
13246
+ code: snippets[f.code] || (snippets[f.code] = new code_1._Code(f.code))
13247
13247
  });
13248
13248
  }
13249
13249
  exports2.useFunc = useFunc;
@@ -18774,17 +18774,17 @@ var require_dist2 = __commonJS({
18774
18774
  };
18775
18775
  formatsPlugin.get = (name, mode = "full") => {
18776
18776
  const formats = mode === "fast" ? formats_1.fastFormats : formats_1.fullFormats;
18777
- const f2 = formats[name];
18778
- if (!f2)
18777
+ const f = formats[name];
18778
+ if (!f)
18779
18779
  throw new Error(`Unknown format "${name}"`);
18780
- return f2;
18780
+ return f;
18781
18781
  };
18782
18782
  function addFormats(ajv, list, fs3, exportName) {
18783
18783
  var _a;
18784
18784
  var _b;
18785
18785
  (_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
18786
- for (const f2 of list)
18787
- ajv.addFormat(f2, fs3[f2]);
18786
+ for (const f of list)
18787
+ ajv.addFormat(f, fs3[f]);
18788
18788
  }
18789
18789
  module2.exports = exports2 = formatsPlugin;
18790
18790
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -21498,10 +21498,10 @@ var require_timestamp = __commonJS({
21498
21498
  if (!matches)
21499
21499
  return false;
21500
21500
  const y = +matches[1];
21501
- const m = +matches[2];
21501
+ const m2 = +matches[2];
21502
21502
  const d = +matches[3];
21503
- return m >= 1 && m <= 12 && d >= 1 && (d <= DAYS[m] || // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
21504
- m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0));
21503
+ return m2 >= 1 && m2 <= 12 && d >= 1 && (d <= DAYS[m2] || // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
21504
+ m2 === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0));
21505
21505
  }
21506
21506
  function validTime(str) {
21507
21507
  const matches = TIME.exec(str);
@@ -23652,14 +23652,14 @@ var require_semver = __commonJS({
23652
23652
  this.options = options;
23653
23653
  this.loose = !!options.loose;
23654
23654
  this.includePrerelease = !!options.includePrerelease;
23655
- const m = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
23656
- if (!m) {
23655
+ const m2 = version2.trim().match(options.loose ? re2[t.LOOSE] : re2[t.FULL]);
23656
+ if (!m2) {
23657
23657
  throw new TypeError(`Invalid Version: ${version2}`);
23658
23658
  }
23659
23659
  this.raw = version2;
23660
- this.major = +m[1];
23661
- this.minor = +m[2];
23662
- this.patch = +m[3];
23660
+ this.major = +m2[1];
23661
+ this.minor = +m2[2];
23662
+ this.patch = +m2[3];
23663
23663
  if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
23664
23664
  throw new TypeError("Invalid major version");
23665
23665
  }
@@ -23669,10 +23669,10 @@ var require_semver = __commonJS({
23669
23669
  if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
23670
23670
  throw new TypeError("Invalid patch version");
23671
23671
  }
23672
- if (!m[4]) {
23672
+ if (!m2[4]) {
23673
23673
  this.prerelease = [];
23674
23674
  } else {
23675
- this.prerelease = m[4].split(".").map((id2) => {
23675
+ this.prerelease = m2[4].split(".").map((id2) => {
23676
23676
  if (/^[0-9]+$/.test(id2)) {
23677
23677
  const num = +id2;
23678
23678
  if (num >= 0 && num < MAX_SAFE_INTEGER) {
@@ -23682,7 +23682,7 @@ var require_semver = __commonJS({
23682
23682
  return id2;
23683
23683
  });
23684
23684
  }
23685
- this.build = m[5] ? m[5].split(".") : [];
23685
+ this.build = m2[5] ? m2[5].split(".") : [];
23686
23686
  this.format();
23687
23687
  }
23688
23688
  format() {
@@ -24490,20 +24490,20 @@ var require_range = __commonJS({
24490
24490
  };
24491
24491
  var replaceTilde = (comp, options) => {
24492
24492
  const r = options.loose ? re2[t.TILDELOOSE] : re2[t.TILDE];
24493
- return comp.replace(r, (_, M, m, p, pr) => {
24494
- debug("tilde", comp, _, M, m, p, pr);
24493
+ return comp.replace(r, (_, M2, m2, p, pr) => {
24494
+ debug("tilde", comp, _, M2, m2, p, pr);
24495
24495
  let ret;
24496
- if (isX(M)) {
24496
+ if (isX(M2)) {
24497
24497
  ret = "";
24498
- } else if (isX(m)) {
24499
- ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
24498
+ } else if (isX(m2)) {
24499
+ ret = `>=${M2}.0.0 <${+M2 + 1}.0.0-0`;
24500
24500
  } else if (isX(p)) {
24501
- ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
24501
+ ret = `>=${M2}.${m2}.0 <${M2}.${+m2 + 1}.0-0`;
24502
24502
  } else if (pr) {
24503
24503
  debug("replaceTilde pr", pr);
24504
- ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
24504
+ ret = `>=${M2}.${m2}.${p}-${pr} <${M2}.${+m2 + 1}.0-0`;
24505
24505
  } else {
24506
- ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
24506
+ ret = `>=${M2}.${m2}.${p} <${M2}.${+m2 + 1}.0-0`;
24507
24507
  }
24508
24508
  debug("tilde return", ret);
24509
24509
  return ret;
@@ -24516,40 +24516,40 @@ var require_range = __commonJS({
24516
24516
  debug("caret", comp, options);
24517
24517
  const r = options.loose ? re2[t.CARETLOOSE] : re2[t.CARET];
24518
24518
  const z = options.includePrerelease ? "-0" : "";
24519
- return comp.replace(r, (_, M, m, p, pr) => {
24520
- debug("caret", comp, _, M, m, p, pr);
24519
+ return comp.replace(r, (_, M2, m2, p, pr) => {
24520
+ debug("caret", comp, _, M2, m2, p, pr);
24521
24521
  let ret;
24522
- if (isX(M)) {
24522
+ if (isX(M2)) {
24523
24523
  ret = "";
24524
- } else if (isX(m)) {
24525
- ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
24524
+ } else if (isX(m2)) {
24525
+ ret = `>=${M2}.0.0${z} <${+M2 + 1}.0.0-0`;
24526
24526
  } else if (isX(p)) {
24527
- if (M === "0") {
24528
- ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
24527
+ if (M2 === "0") {
24528
+ ret = `>=${M2}.${m2}.0${z} <${M2}.${+m2 + 1}.0-0`;
24529
24529
  } else {
24530
- ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
24530
+ ret = `>=${M2}.${m2}.0${z} <${+M2 + 1}.0.0-0`;
24531
24531
  }
24532
24532
  } else if (pr) {
24533
24533
  debug("replaceCaret pr", pr);
24534
- if (M === "0") {
24535
- if (m === "0") {
24536
- ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
24534
+ if (M2 === "0") {
24535
+ if (m2 === "0") {
24536
+ ret = `>=${M2}.${m2}.${p}-${pr} <${M2}.${m2}.${+p + 1}-0`;
24537
24537
  } else {
24538
- ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
24538
+ ret = `>=${M2}.${m2}.${p}-${pr} <${M2}.${+m2 + 1}.0-0`;
24539
24539
  }
24540
24540
  } else {
24541
- ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
24541
+ ret = `>=${M2}.${m2}.${p}-${pr} <${+M2 + 1}.0.0-0`;
24542
24542
  }
24543
24543
  } else {
24544
24544
  debug("no pr");
24545
- if (M === "0") {
24546
- if (m === "0") {
24547
- ret = `>=${M}.${m}.${p}${z} <${M}.${m}.${+p + 1}-0`;
24545
+ if (M2 === "0") {
24546
+ if (m2 === "0") {
24547
+ ret = `>=${M2}.${m2}.${p}${z} <${M2}.${m2}.${+p + 1}-0`;
24548
24548
  } else {
24549
- ret = `>=${M}.${m}.${p}${z} <${M}.${+m + 1}.0-0`;
24549
+ ret = `>=${M2}.${m2}.${p}${z} <${M2}.${+m2 + 1}.0-0`;
24550
24550
  }
24551
24551
  } else {
24552
- ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
24552
+ ret = `>=${M2}.${m2}.${p} <${+M2 + 1}.0.0-0`;
24553
24553
  }
24554
24554
  }
24555
24555
  debug("caret return", ret);
@@ -24563,10 +24563,10 @@ var require_range = __commonJS({
24563
24563
  var replaceXRange = (comp, options) => {
24564
24564
  comp = comp.trim();
24565
24565
  const r = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
24566
- return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
24567
- debug("xRange", comp, ret, gtlt, M, m, p, pr);
24568
- const xM = isX(M);
24569
- const xm = xM || isX(m);
24566
+ return comp.replace(r, (ret, gtlt, M2, m2, p, pr) => {
24567
+ debug("xRange", comp, ret, gtlt, M2, m2, p, pr);
24568
+ const xM = isX(M2);
24569
+ const xm = xM || isX(m2);
24570
24570
  const xp = xm || isX(p);
24571
24571
  const anyX = xp;
24572
24572
  if (gtlt === "=" && anyX) {
@@ -24581,35 +24581,35 @@ var require_range = __commonJS({
24581
24581
  }
24582
24582
  } else if (gtlt && anyX) {
24583
24583
  if (xm) {
24584
- m = 0;
24584
+ m2 = 0;
24585
24585
  }
24586
24586
  p = 0;
24587
24587
  if (gtlt === ">") {
24588
24588
  gtlt = ">=";
24589
24589
  if (xm) {
24590
- M = +M + 1;
24591
- m = 0;
24590
+ M2 = +M2 + 1;
24591
+ m2 = 0;
24592
24592
  p = 0;
24593
24593
  } else {
24594
- m = +m + 1;
24594
+ m2 = +m2 + 1;
24595
24595
  p = 0;
24596
24596
  }
24597
24597
  } else if (gtlt === "<=") {
24598
24598
  gtlt = "<";
24599
24599
  if (xm) {
24600
- M = +M + 1;
24600
+ M2 = +M2 + 1;
24601
24601
  } else {
24602
- m = +m + 1;
24602
+ m2 = +m2 + 1;
24603
24603
  }
24604
24604
  }
24605
24605
  if (gtlt === "<") {
24606
24606
  pr = "-0";
24607
24607
  }
24608
- ret = `${gtlt + M}.${m}.${p}${pr}`;
24608
+ ret = `${gtlt + M2}.${m2}.${p}${pr}`;
24609
24609
  } else if (xm) {
24610
- ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
24610
+ ret = `>=${M2}.0.0${pr} <${+M2 + 1}.0.0-0`;
24611
24611
  } else if (xp) {
24612
- ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
24612
+ ret = `>=${M2}.${m2}.0${pr} <${M2}.${+m2 + 1}.0-0`;
24613
24613
  }
24614
24614
  debug("xRange return", ret);
24615
24615
  return ret;
@@ -24708,18 +24708,18 @@ var require_comparator = __commonJS({
24708
24708
  }
24709
24709
  parse(comp) {
24710
24710
  const r = this.options.loose ? re2[t.COMPARATORLOOSE] : re2[t.COMPARATOR];
24711
- const m = comp.match(r);
24712
- if (!m) {
24711
+ const m2 = comp.match(r);
24712
+ if (!m2) {
24713
24713
  throw new TypeError(`Invalid comparator: ${comp}`);
24714
24714
  }
24715
- this.operator = m[1] !== void 0 ? m[1] : "";
24715
+ this.operator = m2[1] !== void 0 ? m2[1] : "";
24716
24716
  if (this.operator === "=") {
24717
24717
  this.operator = "";
24718
24718
  }
24719
- if (!m[2]) {
24719
+ if (!m2[2]) {
24720
24720
  this.semver = ANY;
24721
24721
  } else {
24722
- this.semver = new SemVer(m[2], this.options.loose);
24722
+ this.semver = new SemVer(m2[2], this.options.loose);
24723
24723
  }
24724
24724
  }
24725
24725
  toString() {
@@ -26377,17 +26377,17 @@ var require_set_lookup = __commonJS({
26377
26377
  var require_types4 = __commonJS({
26378
26378
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/types/index.js"(exports2) {
26379
26379
  "use strict";
26380
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
26380
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
26381
26381
  if (k2 === void 0) k2 = k;
26382
26382
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
26383
- return m[k];
26383
+ return m2[k];
26384
26384
  } });
26385
- } : function(o, m, k, k2) {
26385
+ } : function(o, m2, k, k2) {
26386
26386
  if (k2 === void 0) k2 = k;
26387
- o[k2] = m[k];
26387
+ o[k2] = m2[k];
26388
26388
  });
26389
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
26390
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
26389
+ var __exportStar = exports2 && exports2.__exportStar || function(m2, exports3) {
26390
+ for (var p in m2) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m2, p);
26391
26391
  };
26392
26392
  Object.defineProperty(exports2, "__esModule", { value: true });
26393
26393
  __exportStar(require_tokens(), exports2);
@@ -26447,14 +26447,14 @@ var require_sets = __commonJS({
26447
26447
  var require_util2 = __commonJS({
26448
26448
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/util.js"(exports2) {
26449
26449
  "use strict";
26450
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
26450
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
26451
26451
  if (k2 === void 0) k2 = k;
26452
26452
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
26453
- return m[k];
26453
+ return m2[k];
26454
26454
  } });
26455
- } : function(o, m, k, k2) {
26455
+ } : function(o, m2, k, k2) {
26456
26456
  if (k2 === void 0) k2 = k;
26457
- o[k2] = m[k];
26457
+ o[k2] = m2[k];
26458
26458
  });
26459
26459
  var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26460
26460
  Object.defineProperty(o, "default", { enumerable: true, value: v });
@@ -26518,14 +26518,14 @@ var require_util2 = __commonJS({
26518
26518
  var require_tokenizer = __commonJS({
26519
26519
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/tokenizer.js"(exports2) {
26520
26520
  "use strict";
26521
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
26521
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
26522
26522
  if (k2 === void 0) k2 = k;
26523
26523
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
26524
- return m[k];
26524
+ return m2[k];
26525
26525
  } });
26526
- } : function(o, m, k, k2) {
26526
+ } : function(o, m2, k, k2) {
26527
26527
  if (k2 === void 0) k2 = k;
26528
- o[k2] = m[k];
26528
+ o[k2] = m2[k];
26529
26529
  });
26530
26530
  var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26531
26531
  Object.defineProperty(o, "default", { enumerable: true, value: v });
@@ -26819,14 +26819,14 @@ var require_tokenizer = __commonJS({
26819
26819
  var require_sets_lookup = __commonJS({
26820
26820
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/sets-lookup.js"(exports2) {
26821
26821
  "use strict";
26822
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
26822
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
26823
26823
  if (k2 === void 0) k2 = k;
26824
26824
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
26825
- return m[k];
26825
+ return m2[k];
26826
26826
  } });
26827
- } : function(o, m, k, k2) {
26827
+ } : function(o, m2, k, k2) {
26828
26828
  if (k2 === void 0) k2 = k;
26829
- o[k2] = m[k];
26829
+ o[k2] = m2[k];
26830
26830
  });
26831
26831
  var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26832
26832
  Object.defineProperty(o, "default", { enumerable: true, value: v });
@@ -26874,14 +26874,14 @@ var require_sets_lookup = __commonJS({
26874
26874
  var require_write_set_tokens = __commonJS({
26875
26875
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/write-set-tokens.js"(exports2) {
26876
26876
  "use strict";
26877
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
26877
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
26878
26878
  if (k2 === void 0) k2 = k;
26879
26879
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
26880
- return m[k];
26880
+ return m2[k];
26881
26881
  } });
26882
- } : function(o, m, k, k2) {
26882
+ } : function(o, m2, k, k2) {
26883
26883
  if (k2 === void 0) k2 = k;
26884
- o[k2] = m[k];
26884
+ o[k2] = m2[k];
26885
26885
  });
26886
26886
  var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26887
26887
  Object.defineProperty(o, "default", { enumerable: true, value: v });
@@ -27027,17 +27027,17 @@ var require_reconstruct = __commonJS({
27027
27027
  var require_dist3 = __commonJS({
27028
27028
  "node_modules/.pnpm/ret@0.5.0/node_modules/ret/dist/index.js"(exports2, module2) {
27029
27029
  "use strict";
27030
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
27030
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m2, k, k2) {
27031
27031
  if (k2 === void 0) k2 = k;
27032
27032
  Object.defineProperty(o, k2, { enumerable: true, get: function() {
27033
- return m[k];
27033
+ return m2[k];
27034
27034
  } });
27035
- } : function(o, m, k, k2) {
27035
+ } : function(o, m2, k, k2) {
27036
27036
  if (k2 === void 0) k2 = k;
27037
- o[k2] = m[k];
27037
+ o[k2] = m2[k];
27038
27038
  });
27039
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
27040
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
27039
+ var __exportStar = exports2 && exports2.__exportStar || function(m2, exports3) {
27040
+ for (var p in m2) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m2, p);
27041
27041
  };
27042
27042
  Object.defineProperty(exports2, "__esModule", { value: true });
27043
27043
  exports2.types = void 0;
@@ -27162,7 +27162,7 @@ var require_pretty_print = __commonJS({
27162
27162
  return fName;
27163
27163
  }
27164
27164
  function parseMeta(meta) {
27165
- if (Array.isArray(meta)) return meta.map((m) => parseMeta(m));
27165
+ if (Array.isArray(meta)) return meta.map((m2) => parseMeta(m2));
27166
27166
  if (typeof meta === "symbol") return meta.toString();
27167
27167
  if (typeof meta === "function") return parseFunctionName(meta);
27168
27168
  return meta;
@@ -28551,10 +28551,10 @@ var require_find_my_way = __commonJS({
28551
28551
  };
28552
28552
  for (const i in httpMethods) {
28553
28553
  if (!httpMethods.hasOwnProperty(i)) continue;
28554
- const m = httpMethods[i];
28555
- const methodName = m.toLowerCase();
28554
+ const m2 = httpMethods[i];
28555
+ const methodName = m2.toLowerCase();
28556
28556
  Router.prototype[methodName] = function(path3, handler, store) {
28557
- return this.on(m, path3, handler, store);
28557
+ return this.on(m2, path3, handler, store);
28558
28558
  };
28559
28559
  }
28560
28560
  Router.prototype.all = function(path3, handler, store) {
@@ -33051,8 +33051,8 @@ var require_getPluginName = __commonJS({
33051
33051
  }
33052
33052
  };
33053
33053
  function extractPluginName(stack) {
33054
- const m = stack.match(fpStackTracePattern);
33055
- return m ? m[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
33054
+ const m2 = stack.match(fpStackTracePattern);
33055
+ return m2 ? m2[1].split(/[/\\]/).slice(-1)[0].match(fileNamePattern)[1] : "anonymous";
33056
33056
  }
33057
33057
  module2.exports.extractPluginName = extractPluginName;
33058
33058
  }
@@ -34806,8 +34806,8 @@ var require_util3 = __commonJS({
34806
34806
  }
34807
34807
  var KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/;
34808
34808
  function parseKeepAliveTimeout(val) {
34809
- const m = val.match(KEEPALIVE_TIMEOUT_EXPR);
34810
- return m ? parseInt(m[1], 10) * 1e3 : null;
34809
+ const m2 = val.match(KEEPALIVE_TIMEOUT_EXPR);
34810
+ return m2 ? parseInt(m2[1], 10) * 1e3 : null;
34811
34811
  }
34812
34812
  function headerNameToString(value) {
34813
34813
  return typeof value === "string" ? headerNameLowerCasedRecord[value] ?? value.toLowerCase() : tree.lookup(value) ?? value.toString("latin1").toLowerCase();
@@ -35009,11 +35009,11 @@ var require_util3 = __commonJS({
35009
35009
  var rangeHeaderRegex = /^bytes (\d+)-(\d+)\/(\d+)?$/;
35010
35010
  function parseRangeHeader(range) {
35011
35011
  if (range == null || range === "") return { start: 0, end: null, size: null };
35012
- const m = range ? range.match(rangeHeaderRegex) : null;
35013
- return m ? {
35014
- start: parseInt(m[1]),
35015
- end: m[2] ? parseInt(m[2]) : null,
35016
- size: m[3] ? parseInt(m[3]) : null
35012
+ const m2 = range ? range.match(rangeHeaderRegex) : null;
35013
+ return m2 ? {
35014
+ start: parseInt(m2[1]),
35015
+ end: m2[2] ? parseInt(m2[2]) : null,
35016
+ size: m2[3] ? parseInt(m2[3]) : null
35017
35017
  } : null;
35018
35018
  }
35019
35019
  function addListener(obj, name, listener) {
@@ -37452,8 +37452,8 @@ var require_webidl = __commonJS({
37452
37452
  message: `"${context.value}" is an invalid ${context.type}.`
37453
37453
  });
37454
37454
  };
37455
- webidl.brandCheck = function(V, I2) {
37456
- if (!FunctionPrototypeSymbolHasInstance(I2, V)) {
37455
+ webidl.brandCheck = function(V2, I) {
37456
+ if (!FunctionPrototypeSymbolHasInstance(I, V2)) {
37457
37457
  const err = new TypeError("Illegal invocation");
37458
37458
  err.code = "ERR_INVALID_THIS";
37459
37459
  throw err;
@@ -37461,8 +37461,8 @@ var require_webidl = __commonJS({
37461
37461
  };
37462
37462
  webidl.brandCheckMultiple = function(List) {
37463
37463
  const prototypes = List.map((c) => webidl.util.MakeTypeAssertion(c));
37464
- return (V) => {
37465
- if (prototypes.every((typeCheck) => !typeCheck(V))) {
37464
+ return (V2) => {
37465
+ if (prototypes.every((typeCheck) => !typeCheck(V2))) {
37466
37466
  const err = new TypeError("Illegal invocation");
37467
37467
  err.code = "ERR_INVALID_THIS";
37468
37468
  throw err;
@@ -37483,11 +37483,11 @@ var require_webidl = __commonJS({
37483
37483
  message: "Illegal constructor"
37484
37484
  });
37485
37485
  };
37486
- webidl.util.MakeTypeAssertion = function(I2) {
37487
- return (O2) => FunctionPrototypeSymbolHasInstance(I2, O2);
37486
+ webidl.util.MakeTypeAssertion = function(I) {
37487
+ return (O) => FunctionPrototypeSymbolHasInstance(I, O);
37488
37488
  };
37489
- webidl.util.Type = function(V) {
37490
- switch (typeof V) {
37489
+ webidl.util.Type = function(V2) {
37490
+ switch (typeof V2) {
37491
37491
  case "undefined":
37492
37492
  return UNDEFINED;
37493
37493
  case "boolean":
@@ -37502,7 +37502,7 @@ var require_webidl = __commonJS({
37502
37502
  return BIGINT;
37503
37503
  case "function":
37504
37504
  case "object": {
37505
- if (V === null) {
37505
+ if (V2 === null) {
37506
37506
  return NULL;
37507
37507
  }
37508
37508
  return OBJECT;
@@ -37541,7 +37541,7 @@ var require_webidl = __commonJS({
37541
37541
  };
37542
37542
  webidl.util.markAsUncloneable = markAsUncloneable || (() => {
37543
37543
  });
37544
- webidl.util.ConvertToInt = function(V, bitLength, signedness, opts) {
37544
+ webidl.util.ConvertToInt = function(V2, bitLength, signedness, opts) {
37545
37545
  let upperBound;
37546
37546
  let lowerBound;
37547
37547
  if (bitLength === 64) {
@@ -37558,7 +37558,7 @@ var require_webidl = __commonJS({
37558
37558
  lowerBound = Math.pow(-2, bitLength) - 1;
37559
37559
  upperBound = Math.pow(2, bitLength - 1) - 1;
37560
37560
  }
37561
- let x = Number(V);
37561
+ let x = Number(V2);
37562
37562
  if (x === 0) {
37563
37563
  x = 0;
37564
37564
  }
@@ -37566,7 +37566,7 @@ var require_webidl = __commonJS({
37566
37566
  if (Number.isNaN(x) || x === Number.POSITIVE_INFINITY || x === Number.NEGATIVE_INFINITY) {
37567
37567
  throw webidl.errors.exception({
37568
37568
  header: "Integer conversion",
37569
- message: `Could not convert ${webidl.util.Stringify(V)} to an integer.`
37569
+ message: `Could not convert ${webidl.util.Stringify(V2)} to an integer.`
37570
37570
  });
37571
37571
  }
37572
37572
  x = webidl.util.IntegerPart(x);
@@ -37604,30 +37604,30 @@ var require_webidl = __commonJS({
37604
37604
  }
37605
37605
  return r;
37606
37606
  };
37607
- webidl.util.Stringify = function(V) {
37608
- const type = webidl.util.Type(V);
37607
+ webidl.util.Stringify = function(V2) {
37608
+ const type = webidl.util.Type(V2);
37609
37609
  switch (type) {
37610
37610
  case SYMBOL:
37611
- return `Symbol(${V.description})`;
37611
+ return `Symbol(${V2.description})`;
37612
37612
  case OBJECT:
37613
- return inspect(V);
37613
+ return inspect(V2);
37614
37614
  case STRING:
37615
- return `"${V}"`;
37615
+ return `"${V2}"`;
37616
37616
  case BIGINT:
37617
- return `${V}n`;
37617
+ return `${V2}n`;
37618
37618
  default:
37619
- return `${V}`;
37619
+ return `${V2}`;
37620
37620
  }
37621
37621
  };
37622
37622
  webidl.sequenceConverter = function(converter) {
37623
- return (V, prefix, argument, Iterable) => {
37624
- if (webidl.util.Type(V) !== OBJECT) {
37623
+ return (V2, prefix, argument, Iterable) => {
37624
+ if (webidl.util.Type(V2) !== OBJECT) {
37625
37625
  throw webidl.errors.exception({
37626
37626
  header: prefix,
37627
- message: `${argument} (${webidl.util.Stringify(V)}) is not iterable.`
37627
+ message: `${argument} (${webidl.util.Stringify(V2)}) is not iterable.`
37628
37628
  });
37629
37629
  }
37630
- const method = typeof Iterable === "function" ? Iterable() : V?.[Symbol.iterator]?.();
37630
+ const method = typeof Iterable === "function" ? Iterable() : V2?.[Symbol.iterator]?.();
37631
37631
  const seq = [];
37632
37632
  let index = 0;
37633
37633
  if (method === void 0 || typeof method.next !== "function") {
@@ -37647,30 +37647,30 @@ var require_webidl = __commonJS({
37647
37647
  };
37648
37648
  };
37649
37649
  webidl.recordConverter = function(keyConverter, valueConverter) {
37650
- return (O2, prefix, argument) => {
37651
- if (webidl.util.Type(O2) !== OBJECT) {
37650
+ return (O, prefix, argument) => {
37651
+ if (webidl.util.Type(O) !== OBJECT) {
37652
37652
  throw webidl.errors.exception({
37653
37653
  header: prefix,
37654
- message: `${argument} ("${webidl.util.TypeValueToString(O2)}") is not an Object.`
37654
+ message: `${argument} ("${webidl.util.TypeValueToString(O)}") is not an Object.`
37655
37655
  });
37656
37656
  }
37657
37657
  const result = {};
37658
- if (!types.isProxy(O2)) {
37659
- const keys2 = [...Object.getOwnPropertyNames(O2), ...Object.getOwnPropertySymbols(O2)];
37658
+ if (!types.isProxy(O)) {
37659
+ const keys2 = [...Object.getOwnPropertyNames(O), ...Object.getOwnPropertySymbols(O)];
37660
37660
  for (const key of keys2) {
37661
37661
  const keyName = webidl.util.Stringify(key);
37662
37662
  const typedKey = keyConverter(key, prefix, `Key ${keyName} in ${argument}`);
37663
- const typedValue = valueConverter(O2[key], prefix, `${argument}[${keyName}]`);
37663
+ const typedValue = valueConverter(O[key], prefix, `${argument}[${keyName}]`);
37664
37664
  result[typedKey] = typedValue;
37665
37665
  }
37666
37666
  return result;
37667
37667
  }
37668
- const keys = Reflect.ownKeys(O2);
37668
+ const keys = Reflect.ownKeys(O);
37669
37669
  for (const key of keys) {
37670
- const desc = Reflect.getOwnPropertyDescriptor(O2, key);
37670
+ const desc = Reflect.getOwnPropertyDescriptor(O, key);
37671
37671
  if (desc?.enumerable) {
37672
37672
  const typedKey = keyConverter(key, prefix, argument);
37673
- const typedValue = valueConverter(O2[key], prefix, argument);
37673
+ const typedValue = valueConverter(O[key], prefix, argument);
37674
37674
  result[typedKey] = typedValue;
37675
37675
  }
37676
37676
  }
@@ -37678,14 +37678,14 @@ var require_webidl = __commonJS({
37678
37678
  };
37679
37679
  };
37680
37680
  webidl.interfaceConverter = function(TypeCheck, name) {
37681
- return (V, prefix, argument) => {
37682
- if (!TypeCheck(V)) {
37681
+ return (V2, prefix, argument) => {
37682
+ if (!TypeCheck(V2)) {
37683
37683
  throw webidl.errors.exception({
37684
37684
  header: prefix,
37685
- message: `Expected ${argument} ("${webidl.util.Stringify(V)}") to be an instance of ${name}.`
37685
+ message: `Expected ${argument} ("${webidl.util.Stringify(V2)}") to be an instance of ${name}.`
37686
37686
  });
37687
37687
  }
37688
- return V;
37688
+ return V2;
37689
37689
  };
37690
37690
  };
37691
37691
  webidl.dictionaryConverter = function(converters) {
@@ -37727,11 +37727,11 @@ var require_webidl = __commonJS({
37727
37727
  };
37728
37728
  };
37729
37729
  webidl.nullableConverter = function(converter) {
37730
- return (V, prefix, argument) => {
37731
- if (V === null) {
37732
- return V;
37730
+ return (V2, prefix, argument) => {
37731
+ if (V2 === null) {
37732
+ return V2;
37733
37733
  }
37734
- return converter(V, prefix, argument);
37734
+ return converter(V2, prefix, argument);
37735
37735
  };
37736
37736
  };
37737
37737
  webidl.is.USVString = function(value) {
@@ -37744,26 +37744,26 @@ var require_webidl = __commonJS({
37744
37744
  webidl.is.URL = webidl.util.MakeTypeAssertion(URL);
37745
37745
  webidl.is.AbortSignal = webidl.util.MakeTypeAssertion(AbortSignal);
37746
37746
  webidl.is.MessagePort = webidl.util.MakeTypeAssertion(MessagePort);
37747
- webidl.converters.DOMString = function(V, prefix, argument, opts) {
37748
- if (V === null && opts?.legacyNullToEmptyString) {
37747
+ webidl.converters.DOMString = function(V2, prefix, argument, opts) {
37748
+ if (V2 === null && opts?.legacyNullToEmptyString) {
37749
37749
  return "";
37750
37750
  }
37751
- if (typeof V === "symbol") {
37751
+ if (typeof V2 === "symbol") {
37752
37752
  throw webidl.errors.exception({
37753
37753
  header: prefix,
37754
37754
  message: `${argument} is a symbol, which cannot be converted to a DOMString.`
37755
37755
  });
37756
37756
  }
37757
- return String(V);
37757
+ return String(V2);
37758
37758
  };
37759
- webidl.converters.ByteString = function(V, prefix, argument) {
37760
- if (typeof V === "symbol") {
37759
+ webidl.converters.ByteString = function(V2, prefix, argument) {
37760
+ if (typeof V2 === "symbol") {
37761
37761
  throw webidl.errors.exception({
37762
37762
  header: prefix,
37763
37763
  message: `${argument} is a symbol, which cannot be converted to a ByteString.`
37764
37764
  });
37765
37765
  }
37766
- const x = String(V);
37766
+ const x = String(V2);
37767
37767
  for (let index = 0; index < x.length; index++) {
37768
37768
  if (x.charCodeAt(index) > 255) {
37769
37769
  throw new TypeError(
@@ -37779,93 +37779,93 @@ var require_webidl = __commonJS({
37779
37779
  }
37780
37780
  return `${value}`.toWellFormed();
37781
37781
  };
37782
- webidl.converters.boolean = function(V) {
37783
- const x = Boolean(V);
37782
+ webidl.converters.boolean = function(V2) {
37783
+ const x = Boolean(V2);
37784
37784
  return x;
37785
37785
  };
37786
- webidl.converters.any = function(V) {
37787
- return V;
37786
+ webidl.converters.any = function(V2) {
37787
+ return V2;
37788
37788
  };
37789
- webidl.converters["long long"] = function(V, prefix, argument) {
37790
- const x = webidl.util.ConvertToInt(V, 64, "signed", void 0, prefix, argument);
37789
+ webidl.converters["long long"] = function(V2, prefix, argument) {
37790
+ const x = webidl.util.ConvertToInt(V2, 64, "signed", void 0, prefix, argument);
37791
37791
  return x;
37792
37792
  };
37793
- webidl.converters["unsigned long long"] = function(V, prefix, argument) {
37794
- const x = webidl.util.ConvertToInt(V, 64, "unsigned", void 0, prefix, argument);
37793
+ webidl.converters["unsigned long long"] = function(V2, prefix, argument) {
37794
+ const x = webidl.util.ConvertToInt(V2, 64, "unsigned", void 0, prefix, argument);
37795
37795
  return x;
37796
37796
  };
37797
- webidl.converters["unsigned long"] = function(V, prefix, argument) {
37798
- const x = webidl.util.ConvertToInt(V, 32, "unsigned", void 0, prefix, argument);
37797
+ webidl.converters["unsigned long"] = function(V2, prefix, argument) {
37798
+ const x = webidl.util.ConvertToInt(V2, 32, "unsigned", void 0, prefix, argument);
37799
37799
  return x;
37800
37800
  };
37801
- webidl.converters["unsigned short"] = function(V, prefix, argument, opts) {
37802
- const x = webidl.util.ConvertToInt(V, 16, "unsigned", opts, prefix, argument);
37801
+ webidl.converters["unsigned short"] = function(V2, prefix, argument, opts) {
37802
+ const x = webidl.util.ConvertToInt(V2, 16, "unsigned", opts, prefix, argument);
37803
37803
  return x;
37804
37804
  };
37805
- webidl.converters.ArrayBuffer = function(V, prefix, argument, opts) {
37806
- if (webidl.util.Type(V) !== OBJECT || !types.isAnyArrayBuffer(V)) {
37805
+ webidl.converters.ArrayBuffer = function(V2, prefix, argument, opts) {
37806
+ if (webidl.util.Type(V2) !== OBJECT || !types.isAnyArrayBuffer(V2)) {
37807
37807
  throw webidl.errors.conversionFailed({
37808
37808
  prefix,
37809
- argument: `${argument} ("${webidl.util.Stringify(V)}")`,
37809
+ argument: `${argument} ("${webidl.util.Stringify(V2)}")`,
37810
37810
  types: ["ArrayBuffer"]
37811
37811
  });
37812
37812
  }
37813
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V)) {
37813
+ if (opts?.allowShared === false && types.isSharedArrayBuffer(V2)) {
37814
37814
  throw webidl.errors.exception({
37815
37815
  header: "ArrayBuffer",
37816
37816
  message: "SharedArrayBuffer is not allowed."
37817
37817
  });
37818
37818
  }
37819
- if (V.resizable || V.growable) {
37819
+ if (V2.resizable || V2.growable) {
37820
37820
  throw webidl.errors.exception({
37821
37821
  header: "ArrayBuffer",
37822
37822
  message: "Received a resizable ArrayBuffer."
37823
37823
  });
37824
37824
  }
37825
- return V;
37825
+ return V2;
37826
37826
  };
37827
- webidl.converters.TypedArray = function(V, T, prefix, name, opts) {
37828
- if (webidl.util.Type(V) !== OBJECT || !types.isTypedArray(V) || V.constructor.name !== T.name) {
37827
+ webidl.converters.TypedArray = function(V2, T, prefix, name, opts) {
37828
+ if (webidl.util.Type(V2) !== OBJECT || !types.isTypedArray(V2) || V2.constructor.name !== T.name) {
37829
37829
  throw webidl.errors.conversionFailed({
37830
37830
  prefix,
37831
- argument: `${name} ("${webidl.util.Stringify(V)}")`,
37831
+ argument: `${name} ("${webidl.util.Stringify(V2)}")`,
37832
37832
  types: [T.name]
37833
37833
  });
37834
37834
  }
37835
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
37835
+ if (opts?.allowShared === false && types.isSharedArrayBuffer(V2.buffer)) {
37836
37836
  throw webidl.errors.exception({
37837
37837
  header: "ArrayBuffer",
37838
37838
  message: "SharedArrayBuffer is not allowed."
37839
37839
  });
37840
37840
  }
37841
- if (V.buffer.resizable || V.buffer.growable) {
37841
+ if (V2.buffer.resizable || V2.buffer.growable) {
37842
37842
  throw webidl.errors.exception({
37843
37843
  header: "ArrayBuffer",
37844
37844
  message: "Received a resizable ArrayBuffer."
37845
37845
  });
37846
37846
  }
37847
- return V;
37847
+ return V2;
37848
37848
  };
37849
- webidl.converters.DataView = function(V, prefix, name, opts) {
37850
- if (webidl.util.Type(V) !== OBJECT || !types.isDataView(V)) {
37849
+ webidl.converters.DataView = function(V2, prefix, name, opts) {
37850
+ if (webidl.util.Type(V2) !== OBJECT || !types.isDataView(V2)) {
37851
37851
  throw webidl.errors.exception({
37852
37852
  header: prefix,
37853
37853
  message: `${name} is not a DataView.`
37854
37854
  });
37855
37855
  }
37856
- if (opts?.allowShared === false && types.isSharedArrayBuffer(V.buffer)) {
37856
+ if (opts?.allowShared === false && types.isSharedArrayBuffer(V2.buffer)) {
37857
37857
  throw webidl.errors.exception({
37858
37858
  header: "ArrayBuffer",
37859
37859
  message: "SharedArrayBuffer is not allowed."
37860
37860
  });
37861
37861
  }
37862
- if (V.buffer.resizable || V.buffer.growable) {
37862
+ if (V2.buffer.resizable || V2.buffer.growable) {
37863
37863
  throw webidl.errors.exception({
37864
37864
  header: "ArrayBuffer",
37865
37865
  message: "Received a resizable ArrayBuffer."
37866
37866
  });
37867
37867
  }
37868
- return V;
37868
+ return V2;
37869
37869
  };
37870
37870
  webidl.converters["sequence<ByteString>"] = webidl.sequenceConverter(
37871
37871
  webidl.converters.ByteString
@@ -38306,11 +38306,11 @@ var require_util4 = __commonJS({
38306
38306
  }
38307
38307
  function tryUpgradeRequestToAPotentiallyTrustworthyURL(request) {
38308
38308
  }
38309
- function sameOrigin(A, B2) {
38310
- if (A.origin === B2.origin && A.origin === "null") {
38309
+ function sameOrigin(A2, B2) {
38310
+ if (A2.origin === B2.origin && A2.origin === "null") {
38311
38311
  return true;
38312
38312
  }
38313
- if (A.protocol === B2.protocol && A.hostname === B2.hostname && A.port === B2.port) {
38313
+ if (A2.protocol === B2.protocol && A2.hostname === B2.hostname && A2.port === B2.port) {
38314
38314
  return true;
38315
38315
  }
38316
38316
  return false;
@@ -48264,19 +48264,19 @@ var require_headers = __commonJS({
48264
48264
  enumerable: false
48265
48265
  }
48266
48266
  });
48267
- webidl.converters.HeadersInit = function(V, prefix, argument) {
48268
- if (webidl.util.Type(V) === webidl.util.Types.OBJECT) {
48269
- const iterator = Reflect.get(V, Symbol.iterator);
48270
- if (!util.types.isProxy(V) && iterator === Headers2.prototype.entries) {
48267
+ webidl.converters.HeadersInit = function(V2, prefix, argument) {
48268
+ if (webidl.util.Type(V2) === webidl.util.Types.OBJECT) {
48269
+ const iterator = Reflect.get(V2, Symbol.iterator);
48270
+ if (!util.types.isProxy(V2) && iterator === Headers2.prototype.entries) {
48271
48271
  try {
48272
- return getHeadersList(V).entriesList;
48272
+ return getHeadersList(V2).entriesList;
48273
48273
  } catch {
48274
48274
  }
48275
48275
  }
48276
48276
  if (typeof iterator === "function") {
48277
- return webidl.converters["sequence<sequence<ByteString>>"](V, prefix, argument, iterator.bind(V));
48277
+ return webidl.converters["sequence<sequence<ByteString>>"](V2, prefix, argument, iterator.bind(V2));
48278
48278
  }
48279
- return webidl.converters["record<ByteString, ByteString>"](V, prefix, argument);
48279
+ return webidl.converters["record<ByteString, ByteString>"](V2, prefix, argument);
48280
48280
  }
48281
48281
  throw webidl.errors.conversionFailed({
48282
48282
  prefix: "Headers constructor",
@@ -48661,32 +48661,32 @@ var require_response2 = __commonJS({
48661
48661
  }
48662
48662
  return response;
48663
48663
  }
48664
- webidl.converters.XMLHttpRequestBodyInit = function(V, prefix, name) {
48665
- if (typeof V === "string") {
48666
- return webidl.converters.USVString(V, prefix, name);
48664
+ webidl.converters.XMLHttpRequestBodyInit = function(V2, prefix, name) {
48665
+ if (typeof V2 === "string") {
48666
+ return webidl.converters.USVString(V2, prefix, name);
48667
48667
  }
48668
- if (webidl.is.Blob(V)) {
48669
- return V;
48668
+ if (webidl.is.Blob(V2)) {
48669
+ return V2;
48670
48670
  }
48671
- if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) {
48672
- return V;
48671
+ if (ArrayBuffer.isView(V2) || types.isArrayBuffer(V2)) {
48672
+ return V2;
48673
48673
  }
48674
- if (webidl.is.FormData(V)) {
48675
- return V;
48674
+ if (webidl.is.FormData(V2)) {
48675
+ return V2;
48676
48676
  }
48677
- if (webidl.is.URLSearchParams(V)) {
48678
- return V;
48677
+ if (webidl.is.URLSearchParams(V2)) {
48678
+ return V2;
48679
48679
  }
48680
- return webidl.converters.DOMString(V, prefix, name);
48680
+ return webidl.converters.DOMString(V2, prefix, name);
48681
48681
  };
48682
- webidl.converters.BodyInit = function(V, prefix, argument) {
48683
- if (webidl.is.ReadableStream(V)) {
48684
- return V;
48682
+ webidl.converters.BodyInit = function(V2, prefix, argument) {
48683
+ if (webidl.is.ReadableStream(V2)) {
48684
+ return V2;
48685
48685
  }
48686
- if (V?.[Symbol.asyncIterator]) {
48687
- return V;
48686
+ if (V2?.[Symbol.asyncIterator]) {
48687
+ return V2;
48688
48688
  }
48689
- return webidl.converters.XMLHttpRequestBodyInit(V, prefix, argument);
48689
+ return webidl.converters.XMLHttpRequestBodyInit(V2, prefix, argument);
48690
48690
  };
48691
48691
  webidl.converters.ResponseInit = webidl.dictionaryConverter([
48692
48692
  {
@@ -49376,14 +49376,14 @@ var require_request4 = __commonJS({
49376
49376
  }
49377
49377
  });
49378
49378
  webidl.is.Request = webidl.util.MakeTypeAssertion(Request);
49379
- webidl.converters.RequestInfo = function(V, prefix, argument) {
49380
- if (typeof V === "string") {
49381
- return webidl.converters.USVString(V);
49379
+ webidl.converters.RequestInfo = function(V2, prefix, argument) {
49380
+ if (typeof V2 === "string") {
49381
+ return webidl.converters.USVString(V2);
49382
49382
  }
49383
- if (webidl.is.Request(V)) {
49384
- return V;
49383
+ if (webidl.is.Request(V2)) {
49384
+ return V2;
49385
49385
  }
49386
- return webidl.converters.USVString(V);
49386
+ return webidl.converters.USVString(V2);
49387
49387
  };
49388
49388
  webidl.converters.RequestInit = webidl.dictionaryConverter([
49389
49389
  {
@@ -50552,8 +50552,8 @@ var require_util5 = __commonJS({
50552
50552
  var assert = require("node:assert");
50553
50553
  var { URLSerializer } = require_data_url();
50554
50554
  var { isValidHeaderName } = require_util4();
50555
- function urlEquals(A, B2, excludeFragment = false) {
50556
- const serializedA = URLSerializer(A, excludeFragment);
50555
+ function urlEquals(A2, B2, excludeFragment = false) {
50556
+ const serializedA = URLSerializer(A2, excludeFragment);
50557
50557
  const serializedB = URLSerializer(B2, excludeFragment);
50558
50558
  return serializedA === serializedB;
50559
50559
  }
@@ -53306,11 +53306,11 @@ var require_websocket = __commonJS({
53306
53306
  webidl.converters["sequence<DOMString>"] = webidl.sequenceConverter(
53307
53307
  webidl.converters.DOMString
53308
53308
  );
53309
- webidl.converters["DOMString or sequence<DOMString>"] = function(V, prefix, argument) {
53310
- if (webidl.util.Type(V) === webidl.util.Types.OBJECT && Symbol.iterator in V) {
53311
- return webidl.converters["sequence<DOMString>"](V);
53309
+ webidl.converters["DOMString or sequence<DOMString>"] = function(V2, prefix, argument) {
53310
+ if (webidl.util.Type(V2) === webidl.util.Types.OBJECT && Symbol.iterator in V2) {
53311
+ return webidl.converters["sequence<DOMString>"](V2);
53312
53312
  }
53313
- return webidl.converters.DOMString(V, prefix, argument);
53313
+ return webidl.converters.DOMString(V2, prefix, argument);
53314
53314
  };
53315
53315
  webidl.converters.WebSocketInit = webidl.dictionaryConverter([
53316
53316
  {
@@ -53328,22 +53328,22 @@ var require_websocket = __commonJS({
53328
53328
  converter: webidl.nullableConverter(webidl.converters.HeadersInit)
53329
53329
  }
53330
53330
  ]);
53331
- webidl.converters["DOMString or sequence<DOMString> or WebSocketInit"] = function(V) {
53332
- if (webidl.util.Type(V) === webidl.util.Types.OBJECT && !(Symbol.iterator in V)) {
53333
- return webidl.converters.WebSocketInit(V);
53331
+ webidl.converters["DOMString or sequence<DOMString> or WebSocketInit"] = function(V2) {
53332
+ if (webidl.util.Type(V2) === webidl.util.Types.OBJECT && !(Symbol.iterator in V2)) {
53333
+ return webidl.converters.WebSocketInit(V2);
53334
53334
  }
53335
- return { protocols: webidl.converters["DOMString or sequence<DOMString>"](V) };
53335
+ return { protocols: webidl.converters["DOMString or sequence<DOMString>"](V2) };
53336
53336
  };
53337
- webidl.converters.WebSocketSendData = function(V) {
53338
- if (webidl.util.Type(V) === webidl.util.Types.OBJECT) {
53339
- if (webidl.is.Blob(V)) {
53340
- return V;
53337
+ webidl.converters.WebSocketSendData = function(V2) {
53338
+ if (webidl.util.Type(V2) === webidl.util.Types.OBJECT) {
53339
+ if (webidl.is.Blob(V2)) {
53340
+ return V2;
53341
53341
  }
53342
- if (ArrayBuffer.isView(V) || types.isArrayBuffer(V)) {
53343
- return V;
53342
+ if (ArrayBuffer.isView(V2) || types.isArrayBuffer(V2)) {
53343
+ return V2;
53344
53344
  }
53345
53345
  }
53346
- return webidl.converters.USVString(V);
53346
+ return webidl.converters.USVString(V2);
53347
53347
  };
53348
53348
  module2.exports = {
53349
53349
  WebSocket
@@ -53706,7 +53706,7 @@ var require_websocketstream = __commonJS({
53706
53706
  webidl.converters.WebSocketCloseInfo = webidl.dictionaryConverter([
53707
53707
  {
53708
53708
  key: "closeCode",
53709
- converter: (V) => webidl.converters["unsigned short"](V, { enforceRange: true })
53709
+ converter: (V2) => webidl.converters["unsigned short"](V2, { enforceRange: true })
53710
53710
  },
53711
53711
  {
53712
53712
  key: "reason",
@@ -54471,9 +54471,9 @@ var require_tiktoken_bg = __commonJS({
54471
54471
  heap[idx] = obj;
54472
54472
  return idx;
54473
54473
  }
54474
- function handleError(f2, args) {
54474
+ function handleError(f, args) {
54475
54475
  try {
54476
- return f2.apply(this, args);
54476
+ return f.apply(this, args);
54477
54477
  } catch (e) {
54478
54478
  wasm.__wbindgen_export_0(addHeapObject(e));
54479
54479
  }
@@ -54957,7 +54957,7 @@ var initConfig = async () => {
54957
54957
  return config;
54958
54958
  };
54959
54959
 
54960
- // node_modules/.pnpm/@musistudio+llms@1.0.0_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54960
+ // node_modules/.pnpm/@musistudio+llms@1.0.2_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54961
54961
  var import_fastify = __toESM(require_fastify(), 1);
54962
54962
  var import_cors = __toESM(require_cors(), 1);
54963
54963
  var import_fs = require("fs");
@@ -54965,18 +54965,18 @@ var import_path = require("path");
54965
54965
  var import_dotenv = __toESM(require_main(), 1);
54966
54966
  var import_node_fs = __toESM(require("node:fs"), 1);
54967
54967
  var import_undici = __toESM(require_undici(), 1);
54968
- var G = ((s) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(s, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : s)(function(s) {
54968
+ var V = ((i) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(i, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : i)(function(i) {
54969
54969
  if (typeof require < "u") return require.apply(this, arguments);
54970
- throw Error('Dynamic require of "' + s + '" is not supported');
54970
+ throw Error('Dynamic require of "' + i + '" is not supported');
54971
54971
  });
54972
54972
  var j = class {
54973
54973
  config = {};
54974
54974
  options;
54975
54975
  constructor(e = { jsonPath: "./config.json" }) {
54976
- this.options = { envPath: e.envPath || ".env", jsonPath: e.jsonPath, useEnvFile: e.useEnvFile !== false, useJsonFile: e.useJsonFile !== false, useEnvironmentVariables: e.useEnvironmentVariables !== false, ...e }, this.loadConfig();
54976
+ this.options = { envPath: e.envPath || ".env", jsonPath: e.jsonPath, useEnvFile: false, useJsonFile: e.useJsonFile !== false, useEnvironmentVariables: e.useEnvironmentVariables !== false, ...e }, this.loadConfig();
54977
54977
  }
54978
54978
  loadConfig() {
54979
- this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.options.useEnvironmentVariables && this.loadEnvironmentVariables(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
54979
+ this.options.initialConfig && (this.config = { ...this.config, ...this.options.initialConfig }), this.options.useEnvFile && this.loadEnvConfig(), this.options.useJsonFile && this.options.jsonPath && this.loadJsonConfig(), this.config.LOG_FILE && (process.env.LOG_FILE = this.config.LOG_FILE), this.config.LOG && (process.env.LOG = this.config.LOG);
54980
54980
  }
54981
54981
  loadJsonConfig() {
54982
54982
  if (!this.options.jsonPath) return;
@@ -55033,96 +55033,95 @@ var j = class {
55033
55033
  return this.options.initialConfig && e.push("Initial Config"), this.options.useJsonFile && this.options.jsonPath && e.push(`JSON: ${this.options.jsonPath}`), this.options.useEnvFile && e.push(`ENV: ${this.options.envPath}`), this.options.useEnvironmentVariables && e.push("Environment Variables"), `Config sources: ${e.join(", ")}`;
55034
55034
  }
55035
55035
  };
55036
- var ie = process.env.LOG_FILE || "app.log";
55037
- function f(...s) {
55038
- if (console.log(...s), !process.env.LOG) return;
55039
- let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((o) => typeof o == "object" ? JSON.stringify(o) : String(o)).join(" ") : ""}
55040
- `;
55041
- import_node_fs.default.appendFileSync(ie, n, "utf8");
55036
+ function m(...i) {
55037
+ if (console.log(...i), !(process.env.LOG === "true")) return;
55038
+ let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(i) ? i.map((r) => typeof r == "object" ? JSON.stringify(r) : String(r)).join(" ") : ""}
55039
+ `, o = process.env.LOG_FILE || "app.log";
55040
+ import_node_fs.default.appendFileSync(o, n, "utf8");
55042
55041
  }
55043
- function O(s, e = 500, t = "internal_error", n = "api_error") {
55044
- let o = new Error(s);
55042
+ function A(i, e = 500, t = "internal_error", n = "api_error") {
55043
+ let o = new Error(i);
55045
55044
  return o.statusCode = e, o.code = t, o.type = n, o;
55046
55045
  }
55047
- async function X(s, e, t) {
55048
- e.log.error(s);
55049
- let n = s.statusCode || 500, o = { error: { message: s.message || "Internal Server Error", type: s.type || "api_error", code: s.code || "internal_error" } };
55046
+ async function X(i, e, t) {
55047
+ e.log.error(i);
55048
+ let n = i.statusCode || 500, o = { error: { message: i.message || "Internal Server Error", type: i.type || "api_error", code: i.code || "internal_error" } };
55050
55049
  return t.code(n).send(o);
55051
55050
  }
55052
- function Q(s, e, t) {
55051
+ function Q(i, e, t) {
55053
55052
  let n = new Headers({ "Content-Type": "application/json" });
55054
- t.headers && Object.entries(t.headers).forEach(([d, p]) => {
55055
- n.set(d, p);
55053
+ t.headers && Object.entries(t.headers).forEach(([l, d]) => {
55054
+ n.set(l, d);
55056
55055
  });
55057
55056
  let o, r = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55058
55057
  if (t.signal) {
55059
- let d = new AbortController(), p = () => d.abort();
55060
- t.signal.addEventListener("abort", p), r.addEventListener("abort", p), o = d.signal;
55058
+ let l = new AbortController(), d = () => l.abort();
55059
+ t.signal.addEventListener("abort", d), r.addEventListener("abort", d), o = l.signal;
55061
55060
  } else o = r;
55062
- let a = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
55063
- return t.httpsProxy && (a.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), f("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, a), fetch(typeof s == "string" ? s : s.toString(), a);
55061
+ let c = { method: "POST", headers: n, body: JSON.stringify(e), signal: o };
55062
+ return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), m("final request:", typeof i == "string" ? i : i.toString(), t.httpsProxy, c), fetch(typeof i == "string" ? i : i.toString(), c);
55064
55063
  }
55065
- var Z = async (s) => {
55066
- 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() }));
55067
- let e = s._server.transformerService.getTransformersWithEndpoint();
55068
- for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (o, r) => {
55069
- let a = o.body, d = o.provider, p = s._server.providerService.getProvider(d);
55070
- if (!p) throw O(`Provider '${d}' not found`, 404, "provider_not_found");
55071
- let i = a, u = {};
55064
+ var Z = async (i) => {
55065
+ i.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), i.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
55066
+ let e = i._server.transformerService.getTransformersWithEndpoint();
55067
+ for (let { name: t, transformer: n } of e) n.endPoint && i.post(n.endPoint, async (o, r) => {
55068
+ let c = o.body, l = o.provider, d = i._server.providerService.getProvider(l);
55069
+ if (!d) throw A(`Provider '${l}' not found`, 404, "provider_not_found");
55070
+ let a = c, p = {};
55072
55071
  if (typeof n.transformRequestOut == "function") {
55073
- let c = n.transformRequestOut(a);
55074
- c.body ? (i = c.body, u = c.config || {}) : i = c;
55072
+ let s = n.transformRequestOut(c);
55073
+ s.body ? (a = s.body, p = s.config || {}) : a = s;
55075
55074
  }
55076
- if (p.transformer?.use?.length) for (let c of p.transformer.use) {
55077
- let g = s._server.transformerService.getTransformer(c);
55075
+ if (d.transformer?.use?.length) for (let s of d.transformer.use) {
55076
+ let g = i._server.transformerService.getTransformer(s);
55078
55077
  if (!g || typeof g.transformRequestIn != "function") continue;
55079
- let _ = g.transformRequestIn(i, p);
55080
- _.body ? (i = _.body, u = { ...u, ..._.config }) : i = _;
55078
+ let y = g.transformRequestIn(a, d);
55079
+ y.body ? (a = y.body, p = { ...p, ...y.config }) : a = y;
55081
55080
  }
55082
- if (p.transformer?.[o.body.model]?.use?.length) for (let c of p.transformer[o.body.model].use) {
55083
- let g = s._server.transformerService.getTransformer(c);
55084
- !g || typeof g.transformRequestIn != "function" || (i = g.transformRequestIn(i, p));
55081
+ if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) {
55082
+ let g = i._server.transformerService.getTransformer(s);
55083
+ !g || typeof g.transformRequestIn != "function" || (a = g.transformRequestIn(a, d));
55085
55084
  }
55086
- let l = u.url || new URL(p.baseUrl), v = await Q(l, i, { httpsProxy: s._server.configService.getHttpsProxy(), ...u, headers: { Authorization: `Bearer ${p.apiKey}`, ...u?.headers || {} } });
55085
+ let u = p.url || new URL(d.baseUrl), v = await Q(u, a, { httpsProxy: i._server.configService.getHttpsProxy(), ...p, headers: { Authorization: `Bearer ${d.apiKey}`, ...p?.headers || {} } });
55087
55086
  if (!v.ok) {
55088
- let c = await v.text();
55089
- throw f(`Error response from ${l}: ${c}`), O(`Error from provider: ${c}`, v.status, "provider_response_error");
55087
+ let s = await v.text();
55088
+ throw m(`Error response from ${u}: ${s}`), A(`Error from provider: ${s}`, v.status, "provider_response_error");
55090
55089
  }
55091
55090
  let h = v;
55092
- if (p.transformer?.use?.length) for (let c of p.transformer.use) {
55093
- let g = s._server.transformerService.getTransformer(c);
55091
+ if (d.transformer?.use?.length) for (let s of d.transformer.use) {
55092
+ let g = i._server.transformerService.getTransformer(s);
55094
55093
  !g || typeof g.transformResponseOut != "function" || (h = await g.transformResponseOut(h));
55095
55094
  }
55096
- if (p.transformer?.[o.body.model]?.use?.length) for (let c of p.transformer[o.body.model].use) {
55097
- let g = s._server.transformerService.getTransformer(c);
55095
+ if (d.transformer?.[o.body.model]?.use?.length) for (let s of d.transformer[o.body.model].use) {
55096
+ let g = i._server.transformerService.getTransformer(s);
55098
55097
  !g || typeof g.transformResponseOut != "function" || (h = await g.transformResponseOut(h));
55099
55098
  }
55100
- return n.transformResponseIn && (h = await n.transformResponseIn(h)), h.ok || r.code(h.status), a?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(h.body)) : h.json();
55099
+ return n.transformResponseIn && (h = await n.transformResponseIn(h)), h.ok || r.code(h.status), c?.stream === true ? (r.header("Content-Type", "text/event-stream"), r.header("Cache-Control", "no-cache"), r.header("Connection", "keep-alive"), r.send(h.body)) : h.json();
55101
55100
  });
55102
- 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) => {
55103
- let { name: o, type: r, baseUrl: a, apiKey: d, models: p } = t.body;
55104
- if (!o?.trim()) throw O("Provider name is required", 400, "invalid_request");
55105
- if (!a || !ce(a)) throw O("Valid base URL is required", 400, "invalid_request");
55106
- if (!d?.trim()) throw O("API key is required", 400, "invalid_request");
55107
- if (!p || !Array.isArray(p) || p.length === 0) throw O("At least one model is required", 400, "invalid_request");
55108
- if (s._server.providerService.getProvider(id)) throw O(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55109
- return s._server.providerService.registerProvider(t.body);
55110
- }), 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) => {
55111
- let o = s._server.providerService.getProvider(t.params.id);
55101
+ i.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) => {
55102
+ let { name: o, type: r, baseUrl: c, apiKey: l, models: d } = t.body;
55103
+ if (!o?.trim()) throw A("Provider name is required", 400, "invalid_request");
55104
+ if (!c || !ae(c)) throw A("Valid base URL is required", 400, "invalid_request");
55105
+ if (!l?.trim()) throw A("API key is required", 400, "invalid_request");
55106
+ if (!d || !Array.isArray(d) || d.length === 0) throw A("At least one model is required", 400, "invalid_request");
55107
+ if (i._server.providerService.getProvider(id)) throw A(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55108
+ return i._server.providerService.registerProvider(t.body);
55109
+ }), i.get("/providers", async (t, n) => i._server.providerService.getProviders()), i.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
55110
+ let o = i._server.providerService.getProvider(t.params.id);
55112
55111
  return o || n.code(404).send({ error: "Provider not found" });
55113
- }), 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) => {
55114
- let o = s._server.providerService.updateProvider(t.params.id, t.body);
55112
+ }), i.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) => {
55113
+ let o = i._server.providerService.updateProvider(t.params.id, t.body);
55115
55114
  return o || n.code(404).send({ error: "Provider not found" });
55116
- }), 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" }));
55115
+ }), i.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => i._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), i.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) => i._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" }));
55117
55116
  };
55118
- function ce(s) {
55117
+ function ae(i) {
55119
55118
  try {
55120
- return new URL(s), true;
55119
+ return new URL(i), true;
55121
55120
  } catch {
55122
55121
  return false;
55123
55122
  }
55124
55123
  }
55125
- var J = class {
55124
+ var q = class {
55126
55125
  constructor(e) {
55127
55126
  this.providerService = e;
55128
55127
  }
@@ -55159,7 +55158,7 @@ var J = class {
55159
55158
  return this.providerService.getModelRoutes();
55160
55159
  }
55161
55160
  };
55162
- var q = class {
55161
+ var J = class {
55163
55162
  constructor(e) {
55164
55163
  this.configService = e;
55165
55164
  this.initializeCustomProviders();
@@ -55177,9 +55176,9 @@ var q = class {
55177
55176
  e.forEach((t) => {
55178
55177
  try {
55179
55178
  if (!t.name || !t.api_base_url || !t.api_key) return;
55180
- this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: this.parseTransformerConfig(t.transformer) || {} }), f(`${t.name} provider registered`);
55179
+ this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: this.parseTransformerConfig(t.transformer) || {} }), m(`${t.name} provider registered`);
55181
55180
  } catch (n) {
55182
- f(`${t.name} provider registered error: ${n}`);
55181
+ m(`${t.name} provider registered error: ${n}`);
55183
55182
  }
55184
55183
  });
55185
55184
  }
@@ -55201,11 +55200,11 @@ var q = class {
55201
55200
  if (!n) return null;
55202
55201
  let o = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
55203
55202
  return this.providers.set(e, o), t.models && (n.models.forEach((r) => {
55204
- let a = `${n.id},${r}`;
55205
- this.modelRoutes.delete(a), this.modelRoutes.delete(r);
55203
+ let c = `${n.id},${r}`;
55204
+ this.modelRoutes.delete(c), this.modelRoutes.delete(r);
55206
55205
  }), t.models.forEach((r) => {
55207
- let a = `${n.id},${r}`, d = { providerId: n.id, model: r, fullModel: a };
55208
- this.modelRoutes.set(a, d), this.modelRoutes.has(r) || this.modelRoutes.set(r, d);
55206
+ let c = `${n.id},${r}`, l = { providerId: n.id, model: r, fullModel: c };
55207
+ this.modelRoutes.set(c, l), this.modelRoutes.has(r) || this.modelRoutes.set(r, l);
55209
55208
  })), o;
55210
55209
  }
55211
55210
  deleteProvider(e) {
@@ -55254,37 +55253,37 @@ var q = class {
55254
55253
  }), { object: "list", data: e };
55255
55254
  }
55256
55255
  };
55257
- var L = class {
55256
+ var N = class {
55258
55257
  name = "Anthropic";
55259
55258
  endPoint = "/v1/messages";
55260
55259
  transformRequestOut(e) {
55261
- f("Anthropic Request:", JSON.stringify(e, null, 2));
55260
+ m("Anthropic Request:", JSON.stringify(e, null, 2));
55262
55261
  let t = [], n = [];
55263
55262
  if (e.system) {
55264
55263
  if (typeof e.system == "string") t.push({ role: "system", content: e.system });
55265
55264
  else if (Array.isArray(e.system)) {
55266
- let a = e.system.filter((d) => d.type === "text" && d.text).map((d) => ({ role: "system", content: d.text }));
55267
- t.push(...a);
55268
- }
55269
- }
55270
- return JSON.parse(JSON.stringify(e.messages || []))?.forEach((a, d) => {
55271
- if (a.role === "user" || a.role === "assistant") {
55272
- let p = { role: a.role, content: null };
55273
- if (typeof a.content == "string") t.push({ role: a.role, content: a.content });
55274
- else if (Array.isArray(a.content)) {
55275
- if (a.role === "user") {
55276
- let i = a.content.filter((l) => l.type === "tool_result" && l.tool_use_id);
55277
- i.length && i.forEach((l, v) => {
55278
- let h = { role: "tool", content: typeof l.content == "string" ? l.content : JSON.stringify(l.content), tool_call_id: l.tool_use_id };
55265
+ let c = e.system.filter((l) => l.type === "text" && l.text).map((l) => ({ role: "system", content: l.text }));
55266
+ t.push(...c);
55267
+ }
55268
+ }
55269
+ return JSON.parse(JSON.stringify(e.messages || []))?.forEach((c, l) => {
55270
+ if (c.role === "user" || c.role === "assistant") {
55271
+ let d = { role: c.role, content: null };
55272
+ if (typeof c.content == "string") t.push({ role: c.role, content: c.content });
55273
+ else if (Array.isArray(c.content)) {
55274
+ if (c.role === "user") {
55275
+ let a = c.content.filter((u) => u.type === "tool_result" && u.tool_use_id);
55276
+ a.length && a.forEach((u, v) => {
55277
+ let h = { role: "tool", content: typeof u.content == "string" ? u.content : JSON.stringify(u.content), tool_call_id: u.tool_use_id };
55279
55278
  t.push(h);
55280
55279
  });
55281
- let u = a.content.filter((l) => l.type === "text" && l.text);
55282
- u.length && t.push({ role: "user", content: u });
55283
- } else if (a.role === "assistant") {
55284
- let i = a.content.filter((l) => l.type === "text" && l.text);
55285
- i.length && t.push(...i.map((l) => ({ role: "assistant", content: l.text })));
55286
- let u = a.content.filter((l) => l.type === "tool_use" && l.id);
55287
- u.length && t.push({ role: "assistant", content: null, tool_calls: u.map((l) => ({ id: l.id, type: "function", function: { name: l.name, arguments: JSON.stringify(l.input || {}) } })) });
55280
+ let p = c.content.filter((u) => u.type === "text" && u.text);
55281
+ p.length && t.push({ role: "user", content: p });
55282
+ } else if (c.role === "assistant") {
55283
+ let a = c.content.filter((u) => u.type === "text" && u.text);
55284
+ a.length && t.push(...a.map((u) => ({ role: "assistant", content: u.text })));
55285
+ let p = c.content.filter((u) => u.type === "tool_use" && u.id);
55286
+ p.length && t.push({ role: "assistant", content: null, tool_calls: p.map((u) => ({ id: u.id, type: "function", function: { name: u.name, arguments: JSON.stringify(u.input || {}) } })) });
55288
55287
  }
55289
55288
  return;
55290
55289
  }
@@ -55306,248 +55305,226 @@ var L = class {
55306
55305
  }
55307
55306
  async convertOpenAIStreamToAnthropic(e) {
55308
55307
  return new ReadableStream({ async start(n) {
55309
- let o = new TextEncoder(), r = `msg_${Date.now()}`, a = "unknown", d = false, p = false, i = false, u = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), v = 0, h = 0, m = 0, c = false, g = false, _ = { originalChunks: 0, processedChunks: 0, textDeltas: 0, toolCallDeltas: 0, errorChunks: 0, skippedChunks: 0, sentEvents: 0 }, S = (x) => {
55310
- if (!c) try {
55311
- n.enqueue(x), _.sentEvents++;
55312
- let C = new TextDecoder().decode(x);
55313
- f("send data:", C.trim());
55314
- } catch (C) {
55315
- if (C instanceof TypeError && C.message.includes("Controller is already closed")) c = true;
55316
- else throw f(`send data error: ${C.message}`), C;
55317
- }
55318
- }, ee = () => {
55319
- if (!c) try {
55320
- n.close(), c = true;
55321
- } catch (x) {
55322
- if (x instanceof TypeError && x.message.includes("Controller is already closed")) c = true;
55323
- else throw x;
55324
- }
55325
- }, $ = null;
55308
+ let o = new TextEncoder(), r = `msg_${Date.now()}`, c = "unknown", l = false, d = false, a = false, p = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), v = 0, h = 0, f = 0, s = false, g = false, y = 0, k = (S) => {
55309
+ if (!s) try {
55310
+ n.enqueue(S);
55311
+ let P = new TextDecoder().decode(S);
55312
+ m("send data:", P.trim());
55313
+ } catch (P) {
55314
+ if (P instanceof TypeError && P.message.includes("Controller is already closed")) s = true;
55315
+ else throw m(`send data error: ${P.message}`), P;
55316
+ }
55317
+ }, D = () => {
55318
+ if (!s) try {
55319
+ n.close(), s = true;
55320
+ } catch (S) {
55321
+ if (S instanceof TypeError && S.message.includes("Controller is already closed")) s = true;
55322
+ else throw S;
55323
+ }
55324
+ }, I = null;
55326
55325
  try {
55327
- $ = e.getReader();
55328
- let x = new TextDecoder(), C = "";
55329
- for (; !c; ) {
55330
- let { done: te, value: ne } = await $.read();
55331
- if (te) break;
55332
- C += x.decode(ne, { stream: true });
55333
- let V = C.split(`
55326
+ I = e.getReader();
55327
+ let S = new TextDecoder(), P = "";
55328
+ for (; !s; ) {
55329
+ let { done: ee, value: te } = await I.read();
55330
+ if (ee) break;
55331
+ P += S.decode(te, { stream: true });
55332
+ let W = P.split(`
55334
55333
  `);
55335
- C = V.pop() || "";
55336
- for (let W of V) {
55337
- if (c || i) break;
55338
- if (W.startsWith("data: ")) {
55339
- let z = W.slice(6);
55340
- if (z === "[DONE]") continue;
55341
- try {
55342
- let A = JSON.parse(z);
55343
- if (_.originalChunks++, v++, f("Original Response:", JSON.stringify(A, null, 2)), a = A.model || a, !d && !c && !i) {
55344
- d = true;
55345
- let k = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: a, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55346
- S(o.encode(`event: message_start
55347
- data: ${JSON.stringify(k)}
55334
+ P = W.pop() || "";
55335
+ for (let G of W) {
55336
+ if (s || a) break;
55337
+ if (!G.startsWith("data: ")) continue;
55338
+ let z = G.slice(6);
55339
+ if (z !== "[DONE]") try {
55340
+ let T = JSON.parse(z);
55341
+ if (v++, m("Original Response:", JSON.stringify(T, null, 2)), c = T.model || c, !l && !s && !a) {
55342
+ l = true;
55343
+ let b = { type: "message_start", message: { id: r, type: "message", role: "assistant", content: [], model: c, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55344
+ k(o.encode(`event: message_start
55345
+ data: ${JSON.stringify(b)}
55348
55346
 
55349
55347
  `));
55350
- }
55351
- let b = A.choices?.[0];
55352
- if (!b) {
55353
- _.skippedChunks++;
55354
- continue;
55355
- }
55356
- if (f("Choice Data:", JSON.stringify(b, null, 2)), _.processedChunks++, b?.delta?.thinking && !c && !i) {
55357
- if (!g) {
55358
- let k = { type: "content_block_start", index: b.index || 0, content_block: { type: "thinking", thinking: "" } };
55359
- S(o.encode(`event: content_block_start
55360
- data: ${JSON.stringify(k)}
55348
+ }
55349
+ let x = T.choices?.[0];
55350
+ if (!x) continue;
55351
+ if (x?.delta?.thinking && !s && !a) {
55352
+ if (!g) {
55353
+ let b = { type: "content_block_start", index: y, content_block: { type: "thinking", thinking: "" } };
55354
+ k(o.encode(`event: content_block_start
55355
+ data: ${JSON.stringify(b)}
55361
55356
 
55362
55357
  `)), g = true;
55363
- }
55364
- if (b.delta.thinking.signature) {
55365
- let k = { type: "content_block_delta", index: b.index || 0, delta: { type: "signature_delta", signature: b.delta.thinking.signature } };
55366
- S(o.encode(`event: content_block_delta
55367
- data: ${JSON.stringify(k)}
55358
+ }
55359
+ if (x.delta.thinking.signature) {
55360
+ let b = { type: "content_block_delta", index: y, delta: { type: "signature_delta", signature: x.delta.thinking.signature } };
55361
+ k(o.encode(`event: content_block_delta
55362
+ data: ${JSON.stringify(b)}
55368
55363
 
55369
55364
  `));
55370
- let R = { type: "content_block_stop", index: b.index || 0 };
55371
- S(o.encode(`event: content_block_stop
55372
- data: ${JSON.stringify(R)}
55365
+ let _ = { type: "content_block_stop", index: y };
55366
+ k(o.encode(`event: content_block_stop
55367
+ data: ${JSON.stringify(_)}
55373
55368
 
55374
- `));
55375
- } else if (b.delta.thinking.content) {
55376
- let k = { type: "content_block_delta", index: b.index || 0, delta: { type: "thinking_delta", thinking: b.delta.thinking.content || "" } };
55377
- S(o.encode(`event: content_block_delta
55378
- data: ${JSON.stringify(k)}
55369
+ `)), y++;
55370
+ } else if (x.delta.thinking.content) {
55371
+ let b = { type: "content_block_delta", index: y, delta: { type: "thinking_delta", thinking: x.delta.thinking.content || "" } };
55372
+ k(o.encode(`event: content_block_delta
55373
+ data: ${JSON.stringify(b)}
55379
55374
 
55380
55375
  `));
55381
- }
55382
55376
  }
55383
- if (b?.delta?.content && !c && !i) {
55384
- if (h++, _.textDeltas++, !p && !i) {
55385
- p = true;
55386
- let k = { type: "content_block_start", index: b.index || 0, content_block: { type: "text", text: "" } };
55387
- S(o.encode(`event: content_block_start
55388
- data: ${JSON.stringify(k)}
55389
-
55390
- `));
55391
- }
55392
- if (!c && !i) {
55393
- let k = { type: "content_block_delta", index: b.index || 0, delta: { type: "text_delta", text: b.delta.content } };
55394
- S(o.encode(`event: content_block_delta
55395
- data: ${JSON.stringify(k)}
55377
+ }
55378
+ if (x?.delta?.content && !s && !a) {
55379
+ if (h++, !d && !a) {
55380
+ d = true;
55381
+ let b = { type: "content_block_start", index: y, content_block: { type: "text", text: "" } };
55382
+ k(o.encode(`event: content_block_start
55383
+ data: ${JSON.stringify(b)}
55396
55384
 
55397
55385
  `));
55398
- }
55399
55386
  }
55400
- if (b?.delta?.tool_calls && !c && !i) {
55401
- m++, _.toolCallDeltas++;
55402
- let k = /* @__PURE__ */ new Set();
55403
- for (let R of b.delta.tool_calls) {
55404
- if (c) break;
55405
- let P = R.index ?? 0;
55406
- if (k.has(P)) continue;
55407
- if (k.add(P), !l.has(P)) {
55408
- let y = p ? l.size + 1 : l.size;
55409
- if (y !== 0) {
55410
- let D = { type: "content_block_stop", index: y - 1 };
55411
- S(o.encode(`event: content_block_stop
55412
- data: ${JSON.stringify(D)}
55387
+ if (!s && !a) {
55388
+ let b = { type: "content_block_delta", index: y, delta: { type: "text_delta", text: x.delta.content } };
55389
+ k(o.encode(`event: content_block_delta
55390
+ data: ${JSON.stringify(b)}
55413
55391
 
55414
55392
  `));
55415
- }
55416
- l.set(P, y);
55417
- let w = R.id || `call_${Date.now()}_${P}`, M = R.function?.name || `tool_${P}`, T = { type: "content_block_start", index: y, content_block: { type: "tool_use", id: w, name: M, input: {} } };
55418
- S(o.encode(`event: content_block_start
55419
- data: ${JSON.stringify(T)}
55393
+ }
55394
+ }
55395
+ if (x?.delta?.tool_calls && !s && !a) {
55396
+ f++;
55397
+ let b = /* @__PURE__ */ new Set();
55398
+ for (let _ of x.delta.tool_calls) {
55399
+ if (s) break;
55400
+ let R = _.index ?? 0;
55401
+ if (b.has(R)) continue;
55402
+ if (b.add(R), !u.has(R)) {
55403
+ let C = d ? u.size + 1 : u.size;
55404
+ if (C !== 0) {
55405
+ m("content_block_stop2");
55406
+ let ne = { type: "content_block_stop", index: y };
55407
+ k(o.encode(`event: content_block_stop
55408
+ data: ${JSON.stringify(ne)}
55409
+
55410
+ `)), y++;
55411
+ }
55412
+ u.set(R, C);
55413
+ let E = _.id || `call_${Date.now()}_${R}`, w = _.function?.name || `tool_${R}`, O = { type: "content_block_start", index: y, content_block: { type: "tool_use", id: E, name: w, input: {} } };
55414
+ k(o.encode(`event: content_block_start
55415
+ data: ${JSON.stringify(O)}
55420
55416
 
55421
55417
  `));
55422
- let E = { id: w, name: M, arguments: "", contentBlockIndex: y };
55423
- u.set(P, E);
55424
- } else if (R.id && R.function?.name) {
55425
- let y = u.get(P);
55426
- y.id.startsWith("call_") && y.name.startsWith("tool_") && (y.id = R.id, y.name = R.function.name);
55427
- }
55428
- if (R.function?.arguments && !c && !i) {
55429
- let y = l.get(P);
55430
- if (y === void 0) continue;
55431
- let w = u.get(P);
55432
- if (w) {
55433
- let M = w.arguments;
55434
- w.arguments += R.function.arguments;
55435
- try {
55436
- let T = null, E = w.arguments.trim();
55437
- if (E.startsWith("{") && E.endsWith("}")) try {
55438
- T = JSON.parse(E);
55439
- } catch (D) {
55440
- f("Tool call index:", P, "error", D.message);
55441
- }
55442
- } catch (T) {
55443
- f("Tool call index:", P, "error", T.message);
55418
+ let L = { id: E, name: w, arguments: "", contentBlockIndex: C };
55419
+ p.set(R, L);
55420
+ } else if (_.id && _.function?.name) {
55421
+ let C = p.get(R);
55422
+ C.id.startsWith("call_") && C.name.startsWith("tool_") && (C.id = _.id, C.name = _.function.name);
55423
+ }
55424
+ if (_.function?.arguments && !s && !a) {
55425
+ if (u.get(R) === void 0) continue;
55426
+ let E = p.get(R);
55427
+ if (E) {
55428
+ E.arguments += _.function.arguments;
55429
+ try {
55430
+ let w = null, O = E.arguments.trim();
55431
+ if (O.startsWith("{") && O.endsWith("}")) try {
55432
+ w = JSON.parse(O);
55433
+ } catch (L) {
55434
+ m("Tool call index:", R, "error", L.message);
55444
55435
  }
55436
+ } catch (w) {
55437
+ m("Tool call index:", R, "error", w.message);
55445
55438
  }
55446
- try {
55447
- let M = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: R.function.arguments } };
55448
- S(o.encode(`event: content_block_delta
55449
- data: ${JSON.stringify(M)}
55439
+ }
55440
+ try {
55441
+ let w = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: _.function.arguments } };
55442
+ k(o.encode(`event: content_block_delta
55443
+ data: ${JSON.stringify(w)}
55450
55444
 
55451
55445
  `));
55452
- } catch {
55453
- try {
55454
- let T = R.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), E = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: T } };
55455
- S(o.encode(`event: content_block_delta
55456
- data: ${JSON.stringify(E)}
55446
+ } catch {
55447
+ try {
55448
+ let O = _.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), L = { type: "content_block_delta", index: y, delta: { type: "input_json_delta", partial_json: O } };
55449
+ k(o.encode(`event: content_block_delta
55450
+ data: ${JSON.stringify(L)}
55457
55451
 
55458
55452
  `));
55459
- } catch (T) {
55460
- console.error(T);
55461
- }
55453
+ } catch (O) {
55454
+ console.error(O);
55462
55455
  }
55463
55456
  }
55464
55457
  }
55465
55458
  }
55466
- if (b?.finish_reason && !c && !i) {
55467
- if (i = true, h === 0 && m === 0 && console.error("Warning: No content in the stream response!"), p && !c) {
55468
- let k = { type: "content_block_stop", index: b.index || 0 };
55469
- S(o.encode(`event: content_block_stop
55470
- data: ${JSON.stringify(k)}
55471
-
55472
- `));
55473
- }
55474
- if (m > 0 && !c) {
55475
- for (let [R, P] of l.entries()) {
55476
- if (c) break;
55477
- let H = u.get(R);
55478
- if (H && H.arguments) try {
55479
- let y = H.arguments.trim();
55480
- y.startsWith("{") || (y = "{" + y), y.endsWith("}") || (y = y + "}"), JSON.parse(y);
55481
- } catch (y) {
55482
- f("Tool call final arguments parsing failed:", y.message, "original arguments:", H.arguments);
55483
- }
55484
- }
55485
- let k = { type: "content_block_stop", index: l.size - 1 };
55486
- S(o.encode(`event: content_block_stop
55487
- data: ${JSON.stringify(k)}
55459
+ }
55460
+ if (x?.finish_reason && !s && !a) {
55461
+ if (a = true, h === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (d || f > 0) && !s) {
55462
+ m("content_block_stop hasTextContentStarted");
55463
+ let b = { type: "content_block_stop", index: y };
55464
+ k(o.encode(`event: content_block_stop
55465
+ data: ${JSON.stringify(b)}
55488
55466
 
55489
55467
  `));
55490
- }
55491
- if (!c) {
55492
- let P = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[b.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: A.usage?.prompt_tokens || 0, output_tokens: A.usage?.completion_tokens || 0 } };
55493
- S(o.encode(`event: message_delta
55494
- data: ${JSON.stringify(P)}
55468
+ }
55469
+ if (!s) {
55470
+ let R = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[x.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: T.usage?.prompt_tokens || 0, output_tokens: T.usage?.completion_tokens || 0 } };
55471
+ k(o.encode(`event: message_delta
55472
+ data: ${JSON.stringify(R)}
55495
55473
 
55496
55474
  `));
55497
- }
55498
- if (!c) {
55499
- let k = { type: "message_stop" };
55500
- S(o.encode(`event: message_stop
55501
- data: ${JSON.stringify(k)}
55475
+ }
55476
+ if (!s) {
55477
+ let b = { type: "message_stop" };
55478
+ k(o.encode(`event: message_stop
55479
+ data: ${JSON.stringify(b)}
55502
55480
 
55503
55481
  `));
55504
- }
55505
- break;
55506
55482
  }
55507
- } catch (A) {
55508
- f("parseError: ", A), _.errorChunks++;
55483
+ break;
55509
55484
  }
55485
+ } catch (T) {
55486
+ m(`parseError: ${T.name} message: ${T.message} stack: ${T.stack} data: ${z}`);
55510
55487
  }
55511
55488
  }
55512
55489
  }
55513
- ee();
55514
- } catch (x) {
55515
- if (!c) try {
55516
- n.error(x);
55517
- } catch (C) {
55518
- console.error(C);
55490
+ D();
55491
+ } catch (S) {
55492
+ if (!s) try {
55493
+ n.error(S);
55494
+ } catch (P) {
55495
+ console.error(P);
55519
55496
  }
55520
55497
  } finally {
55521
- if ($) try {
55522
- $.releaseLock();
55523
- } catch (x) {
55524
- console.error(x);
55498
+ if (I) try {
55499
+ I.releaseLock();
55500
+ } catch (S) {
55501
+ console.error(S);
55525
55502
  }
55526
55503
  }
55527
55504
  }, cancel(n) {
55528
- f("cancle stream:", n);
55505
+ m("cancle stream:", n);
55529
55506
  } });
55530
55507
  }
55531
55508
  convertOpenAIResponseToAnthropic(e) {
55532
- f("Original OpenAI response:", JSON.stringify(e, null, 2));
55509
+ m("Original OpenAI response:", JSON.stringify(e, null, 2));
55533
55510
  let t = e.choices[0];
55534
55511
  if (!t) throw new Error("No choices found in OpenAI response");
55535
55512
  let n = [];
55536
- 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, a) => {
55537
- let d = {};
55513
+ 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, c) => {
55514
+ let l = {};
55538
55515
  try {
55539
- let p = r.function.arguments || "{}";
55540
- typeof p == "object" ? d = p : typeof p == "string" && (d = JSON.parse(p));
55516
+ let d = r.function.arguments || "{}";
55517
+ typeof d == "object" ? l = d : typeof d == "string" && (l = JSON.parse(d));
55541
55518
  } catch {
55542
- d = { text: r.function.arguments || "" };
55519
+ l = { text: r.function.arguments || "" };
55543
55520
  }
55544
- n.push({ type: "tool_use", id: r.id, name: r.function.name, input: d });
55521
+ n.push({ type: "tool_use", id: r.id, name: r.function.name, input: l });
55545
55522
  });
55546
55523
  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 } };
55547
- return f("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
55524
+ return m("Conversion complete, final Anthropic response:", JSON.stringify(o, null, 2)), o;
55548
55525
  }
55549
55526
  };
55550
- var N = class {
55527
+ var M = class {
55551
55528
  name = "gemini";
55552
55529
  endPoint = "/v1beta/models/:modelAndAction";
55553
55530
  transformRequestIn(e, t) {
@@ -55555,22 +55532,22 @@ var N = class {
55555
55532
  let o;
55556
55533
  n.role === "assistant" ? o = "model" : (["user", "system", "tool"].includes(n.role), o = "user");
55557
55534
  let r = [];
55558
- return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((a) => {
55559
- if (a.type === "text") return { text: a.text || "" };
55560
- })), Array.isArray(n.tool_calls) && r.push(...n.tool_calls.map((a) => ({ functionCall: { id: a.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: a.function.name, args: JSON.parse(a.function.arguments || "{}") } }))), { role: o, parts: r };
55535
+ return typeof n.content == "string" ? r.push({ text: n.content }) : Array.isArray(n.content) && r.push(...n.content.map((c) => {
55536
+ if (c.type === "text") return { text: c.text || "" };
55537
+ })), Array.isArray(n.tool_calls) && r.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: o, parts: r };
55561
55538
  }), 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) => {
55562
55539
  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);
55563
- }), { 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 } } };
55540
+ }), { 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 } } };
55564
55541
  }
55565
55542
  transformRequestOut(e) {
55566
- let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, a = e.temperature, d = e.stream, p = e.tool_choice, i = { messages: [], model: o, max_tokens: r, temperature: a, stream: d, tool_choice: p };
55567
- return Array.isArray(t) && t.forEach((u) => {
55568
- typeof u == "string" ? i.messages.push({ role: "user", content: u }) : typeof u.text == "string" ? i.messages.push({ role: "user", content: u.text || null }) : u.role === "user" ? i.messages.push({ role: "user", content: u?.parts?.map((l) => ({ type: "text", text: l.text || "" })) || [] }) : u.role === "model" && i.messages.push({ role: "assistant", content: u?.parts?.map((l) => ({ type: "text", text: l.text || "" })) || [] });
55569
- }), Array.isArray(n) && (i.tools = [], n.forEach((u) => {
55570
- Array.isArray(u.functionDeclarations) && u.functionDeclarations.forEach((l) => {
55571
- i.tools.push({ type: "function", function: { name: l.name, description: l.description, parameters: l.parameters } });
55543
+ let t = e.contents, n = e.tools, o = e.model, r = e.max_tokens, c = e.temperature, l = e.stream, d = e.tool_choice, a = { messages: [], model: o, max_tokens: r, temperature: c, stream: l, tool_choice: d };
55544
+ return Array.isArray(t) && t.forEach((p) => {
55545
+ typeof p == "string" ? a.messages.push({ role: "user", content: p }) : typeof p.text == "string" ? a.messages.push({ role: "user", content: p.text || null }) : p.role === "user" ? a.messages.push({ role: "user", content: p?.parts?.map((u) => ({ type: "text", text: u.text || "" })) || [] }) : p.role === "model" && a.messages.push({ role: "assistant", content: p?.parts?.map((u) => ({ type: "text", text: u.text || "" })) || [] });
55546
+ }), Array.isArray(n) && (a.tools = [], n.forEach((p) => {
55547
+ Array.isArray(p.functionDeclarations) && p.functionDeclarations.forEach((u) => {
55548
+ a.tools.push({ type: "function", function: { name: u.name, description: u.description, parameters: u.parameters } });
55572
55549
  });
55573
- })), i;
55550
+ })), a;
55574
55551
  }
55575
55552
  async transformResponseOut(e) {
55576
55553
  if (e.headers.get("Content-Type")?.includes("application/json")) {
@@ -55580,23 +55557,23 @@ var N = class {
55580
55557
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55581
55558
  if (!e.body) return e;
55582
55559
  let t = new TextDecoder(), n = new TextEncoder(), o = new ReadableStream({ async start(r) {
55583
- let a = e.body.getReader();
55560
+ let c = e.body.getReader();
55584
55561
  try {
55585
55562
  for (; ; ) {
55586
- let { done: d, value: p } = await a.read();
55587
- if (d) break;
55588
- let i = t.decode(p, { stream: true });
55589
- if (i.startsWith("data: ")) i = i.slice(6).trim();
55563
+ let { done: l, value: d } = await c.read();
55564
+ if (l) break;
55565
+ let a = t.decode(d, { stream: true });
55566
+ if (a.startsWith("data: ")) a = a.slice(6).trim();
55590
55567
  else break;
55591
- f("gemini chunk:", i), i = JSON.parse(i);
55592
- let u = i.candidates[0].content.parts.filter((v) => v.functionCall).map((v) => ({ id: v.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: v.functionCall?.name, arguments: JSON.stringify(v.functionCall?.args || {}) } })), l = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((v) => v.text).map((v) => v.text).join(`
55593
- `), tool_calls: u.length > 0 ? u : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || u.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" };
55594
- f("gemini response:", JSON.stringify(l, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(l)}
55568
+ m("gemini chunk:", a), a = JSON.parse(a);
55569
+ let p = a.candidates[0].content.parts.filter((v) => v.functionCall).map((v) => ({ id: v.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: v.functionCall?.name, arguments: JSON.stringify(v.functionCall?.args || {}) } })), u = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((v) => v.text).map((v) => v.text).join(`
55570
+ `), tool_calls: p.length > 0 ? p : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || p.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" };
55571
+ m("gemini response:", JSON.stringify(u, null, 2)), r.enqueue(n.encode(`data: ${JSON.stringify(u)}
55595
55572
 
55596
55573
  `));
55597
55574
  }
55598
- } catch (d) {
55599
- r.error(d);
55575
+ } catch (l) {
55576
+ r.error(l);
55600
55577
  } finally {
55601
55578
  r.close();
55602
55579
  }
@@ -55606,7 +55583,7 @@ var N = class {
55606
55583
  return e;
55607
55584
  }
55608
55585
  };
55609
- var F = class {
55586
+ var H = class {
55610
55587
  name = "deepseek";
55611
55588
  transformRequestIn(e) {
55612
55589
  return e.max_tokens && e.max_tokens > 8192 && (e.max_tokens = 8192), e;
@@ -55617,66 +55594,66 @@ var F = class {
55617
55594
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55618
55595
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55619
55596
  if (!e.body) return e;
55620
- let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, a = new ReadableStream({ async start(d) {
55621
- let p = e.body.getReader();
55597
+ let t = new TextDecoder(), n = new TextEncoder(), o = "", r = false, c = new ReadableStream({ async start(l) {
55598
+ let d = e.body.getReader();
55622
55599
  try {
55623
55600
  for (; ; ) {
55624
- let { done: i, value: u } = await p.read();
55625
- if (i) break;
55626
- let v = t.decode(u, { stream: true }).split(`
55601
+ let { done: a, value: p } = await d.read();
55602
+ if (a) break;
55603
+ let v = t.decode(p, { stream: true }).split(`
55627
55604
  `);
55628
55605
  for (let h of v) if (h.startsWith("data: ") && h.trim() !== "data: [DONE]") try {
55629
- let m = JSON.parse(h.slice(6));
55630
- if (m.choices?.[0]?.delta?.reasoning_content) {
55631
- o += m.choices[0].delta.reasoning_content;
55632
- let c = { ...m, choices: [{ ...m.choices[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning_content } } }] };
55633
- delete c.choices[0].delta.reasoning_content;
55634
- let g = `data: ${JSON.stringify(c)}
55606
+ let f = JSON.parse(h.slice(6));
55607
+ if (f.choices?.[0]?.delta?.reasoning_content) {
55608
+ o += f.choices[0].delta.reasoning_content;
55609
+ let s = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, thinking: { content: f.choices[0].delta.reasoning_content } } }] };
55610
+ delete s.choices[0].delta.reasoning_content;
55611
+ let g = `data: ${JSON.stringify(s)}
55635
55612
 
55636
55613
  `;
55637
- d.enqueue(n.encode(g));
55614
+ l.enqueue(n.encode(g));
55638
55615
  continue;
55639
55616
  }
55640
- if (m.choices?.[0]?.delta?.content && o && !r) {
55617
+ if (f.choices?.[0]?.delta?.content && o && !r) {
55641
55618
  r = true;
55642
- let c = Date.now().toString(), g = { ...m, choices: [{ ...m.choices[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: o, signature: c } } }] };
55619
+ let s = Date.now().toString(), g = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: o, signature: s } } }] };
55643
55620
  delete g.choices[0].delta.reasoning_content;
55644
- let _ = `data: ${JSON.stringify(g)}
55621
+ let y = `data: ${JSON.stringify(g)}
55645
55622
 
55646
55623
  `;
55647
- d.enqueue(n.encode(_));
55624
+ l.enqueue(n.encode(y));
55648
55625
  }
55649
- if (m.choices[0]?.delta?.reasoning_content && delete m.choices[0].delta.reasoning_content, m.choices?.[0]?.delta && Object.keys(m.choices[0].delta).length > 0) {
55650
- r && m.choices[0].index++;
55651
- let c = `data: ${JSON.stringify(m)}
55626
+ if (f.choices[0]?.delta?.reasoning_content && delete f.choices[0].delta.reasoning_content, f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55627
+ r && f.choices[0].index++;
55628
+ let s = `data: ${JSON.stringify(f)}
55652
55629
 
55653
55630
  `;
55654
- d.enqueue(n.encode(c));
55631
+ l.enqueue(n.encode(s));
55655
55632
  }
55656
55633
  } catch {
55657
- d.enqueue(n.encode(h + `
55634
+ l.enqueue(n.encode(h + `
55658
55635
  `));
55659
55636
  }
55660
- else d.enqueue(n.encode(h + `
55637
+ else l.enqueue(n.encode(h + `
55661
55638
  `));
55662
55639
  }
55663
- } catch (i) {
55664
- d.error(i);
55640
+ } catch (a) {
55641
+ l.error(a);
55665
55642
  } finally {
55666
55643
  try {
55667
- p.releaseLock();
55668
- } catch (i) {
55669
- console.error("Error releasing reader lock:", i);
55644
+ d.releaseLock();
55645
+ } catch (a) {
55646
+ console.error("Error releasing reader lock:", a);
55670
55647
  }
55671
- d.close();
55648
+ l.close();
55672
55649
  }
55673
55650
  } });
55674
- return new Response(a, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55651
+ 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" } });
55675
55652
  }
55676
55653
  return e;
55677
55654
  }
55678
55655
  };
55679
- var I = class {
55656
+ var $ = class {
55680
55657
  name = "tooluse";
55681
55658
  transformRequestIn(e) {
55682
55659
  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.
@@ -55695,60 +55672,125 @@ Examples:
55695
55672
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55696
55673
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55697
55674
  if (!e.body) return e;
55698
- let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", a = new ReadableStream({ async start(d) {
55699
- let p = e.body.getReader();
55675
+ let t = new TextDecoder(), n = new TextEncoder(), o = -1, r = "", c = new ReadableStream({ async start(l) {
55676
+ let d = e.body.getReader();
55700
55677
  try {
55701
55678
  for (; ; ) {
55702
- let { done: i, value: u } = await p.read();
55703
- if (i) break;
55704
- let v = t.decode(u, { stream: true }).split(`
55679
+ let { done: a, value: p } = await d.read();
55680
+ if (a) break;
55681
+ let v = t.decode(p, { stream: true }).split(`
55705
55682
  `);
55706
55683
  for (let h of v) if (h.startsWith("data: ") && h.trim() !== "data: [DONE]") try {
55707
- let m = JSON.parse(h.slice(6));
55708
- if (m.choices[0]?.delta?.tool_calls?.length) {
55709
- let c = m.choices[0].delta.tool_calls[0];
55710
- if (c.function?.name === "ExitTool") {
55711
- o = c.index;
55684
+ let f = JSON.parse(h.slice(6));
55685
+ if (f.choices[0]?.delta?.tool_calls?.length) {
55686
+ let s = f.choices[0].delta.tool_calls[0];
55687
+ if (s.function?.name === "ExitTool") {
55688
+ o = s.index;
55712
55689
  continue;
55713
- } else if (o > -1 && c.index === o && c.function.arguments) {
55714
- r += c.function.arguments;
55690
+ } else if (o > -1 && s.index === o && s.function.arguments) {
55691
+ r += s.function.arguments;
55715
55692
  try {
55716
55693
  let g = JSON.parse(r);
55717
- m.choices = [{ delta: { role: "assistant", content: g.response || "" } }];
55718
- let _ = `data: ${JSON.stringify(m)}
55694
+ f.choices = [{ delta: { role: "assistant", content: g.response || "" } }];
55695
+ let y = `data: ${JSON.stringify(f)}
55719
55696
 
55720
55697
  `;
55721
- d.enqueue(n.encode(_));
55698
+ l.enqueue(n.encode(y));
55722
55699
  } catch {
55723
55700
  }
55724
55701
  continue;
55725
55702
  }
55726
55703
  }
55727
- if (m.choices?.[0]?.delta && Object.keys(m.choices[0].delta).length > 0) {
55728
- let c = `data: ${JSON.stringify(m)}
55704
+ if (f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55705
+ let s = `data: ${JSON.stringify(f)}
55706
+
55707
+ `;
55708
+ l.enqueue(n.encode(s));
55709
+ }
55710
+ } catch {
55711
+ l.enqueue(n.encode(h + `
55712
+ `));
55713
+ }
55714
+ else l.enqueue(n.encode(h + `
55715
+ `));
55716
+ }
55717
+ } catch (a) {
55718
+ l.error(a);
55719
+ } finally {
55720
+ try {
55721
+ d.releaseLock();
55722
+ } catch (a) {
55723
+ console.error("Error releasing reader lock:", a);
55724
+ }
55725
+ l.close();
55726
+ }
55727
+ } });
55728
+ 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" } });
55729
+ }
55730
+ return e;
55731
+ }
55732
+ };
55733
+ var F = class {
55734
+ name = "openrouter";
55735
+ async transformResponseOut(e) {
55736
+ if (e.headers.get("Content-Type")?.includes("application/json")) {
55737
+ let t = await e.json();
55738
+ return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55739
+ } else if (e.headers.get("Content-Type")?.includes("stream")) {
55740
+ if (!e.body) return e;
55741
+ let t = new TextDecoder(), n = new TextEncoder(), o = false, r = "", c = false, l = new ReadableStream({ async start(d) {
55742
+ let a = e.body.getReader();
55743
+ try {
55744
+ for (; ; ) {
55745
+ let { done: p, value: u } = await a.read();
55746
+ if (p) break;
55747
+ let h = t.decode(u, { stream: true }).split(`
55748
+ `);
55749
+ for (let f of h) if (f.startsWith("data: ") && f.trim() !== "data: [DONE]") try {
55750
+ let s = JSON.parse(f.slice(6));
55751
+ if (s.choices[0]?.delta?.content && !o && (o = true), s.choices?.[0]?.delta?.reasoning) {
55752
+ r += s.choices[0].delta.reasoning;
55753
+ let y = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, thinking: { content: s.choices[0].delta.reasoning } } }] };
55754
+ delete y.choices[0].delta.reasoning;
55755
+ let k = `data: ${JSON.stringify(y)}
55756
+
55757
+ `;
55758
+ d.enqueue(n.encode(k));
55759
+ continue;
55760
+ }
55761
+ if (s.choices?.[0]?.delta?.content && r && !c) {
55762
+ c = true;
55763
+ let y = Date.now().toString(), k = { ...s, choices: [{ ...s.choices[0], delta: { ...s.choices[0].delta, content: null, thinking: { content: r, signature: y } } }] };
55764
+ delete k.choices[0].delta.reasoning;
55765
+ let D = `data: ${JSON.stringify(k)}
55729
55766
 
55730
55767
  `;
55731
- d.enqueue(n.encode(c));
55768
+ d.enqueue(n.encode(D));
55732
55769
  }
55770
+ s.choices[0]?.delta?.reasoning && delete s.choices[0].delta.reasoning, s.choices[0]?.delta?.tool_calls?.length && o && (s.choices[0].index += 1);
55771
+ let g = `data: ${JSON.stringify(s)}
55772
+
55773
+ `;
55774
+ d.enqueue(n.encode(g));
55733
55775
  } catch {
55734
- d.enqueue(n.encode(h + `
55776
+ d.enqueue(n.encode(f + `
55735
55777
  `));
55736
55778
  }
55737
- else d.enqueue(n.encode(h + `
55779
+ else d.enqueue(n.encode(f + `
55738
55780
  `));
55739
55781
  }
55740
- } catch (i) {
55741
- d.error(i);
55782
+ } catch (p) {
55783
+ d.error(p);
55742
55784
  } finally {
55743
55785
  try {
55744
- p.releaseLock();
55745
- } catch (i) {
55746
- console.error("Error releasing reader lock:", i);
55786
+ a.releaseLock();
55787
+ } catch (p) {
55788
+ console.error("Error releasing reader lock:", p);
55747
55789
  }
55748
55790
  d.close();
55749
55791
  }
55750
55792
  } });
55751
- return new Response(a, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55793
+ return new Response(l, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55752
55794
  }
55753
55795
  return e;
55754
55796
  }
@@ -55760,7 +55802,7 @@ var U = class {
55760
55802
  }
55761
55803
  transformers = /* @__PURE__ */ new Map();
55762
55804
  registerTransformer(e, t) {
55763
- this.transformers.set(e, t), f(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
55805
+ this.transformers.set(e, t), m(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
55764
55806
  }
55765
55807
  getTransformer(e) {
55766
55808
  return this.transformers.get(e);
@@ -55789,7 +55831,7 @@ var U = class {
55789
55831
  async registerTransformerFromConfig(e) {
55790
55832
  try {
55791
55833
  if (e.path) {
55792
- let t = G(e.path);
55834
+ let t = V(e.path);
55793
55835
  if (t) {
55794
55836
  let n = new t(e.options);
55795
55837
  if (!n.name) throw new Error(`Transformer instance from ${e.path} does not have a name property.`);
@@ -55798,22 +55840,22 @@ var U = class {
55798
55840
  }
55799
55841
  return false;
55800
55842
  } catch (t) {
55801
- return f(`load transformer (${e.path}):`, t), false;
55843
+ return m(`load transformer (${e.path}):`, t), false;
55802
55844
  }
55803
55845
  }
55804
55846
  async initialize() {
55805
55847
  try {
55806
55848
  await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
55807
55849
  } catch (e) {
55808
- f("TransformerService init error:", e);
55850
+ m("TransformerService init error:", e);
55809
55851
  }
55810
55852
  }
55811
55853
  async registerDefaultTransformersInternal() {
55812
55854
  try {
55813
- let e = new L(), t = new N(), n = new F(), o = new I();
55814
- this.registerTransformer(e.name, e), this.registerTransformer(t.name, t), this.registerTransformer(n.name, n), this.registerTransformer(o.name, o);
55855
+ let e = new N(), t = new M(), n = new H(), o = new $(), r = new F();
55856
+ this.registerTransformer(e.name, e), this.registerTransformer(t.name, t), this.registerTransformer(n.name, n), this.registerTransformer(o.name, o), this.registerTransformer(r.name, r);
55815
55857
  } catch (e) {
55816
- f("transformer regist error:", e);
55858
+ m("transformer regist error:", e);
55817
55859
  }
55818
55860
  }
55819
55861
  async loadFromConfig() {
@@ -55821,9 +55863,9 @@ var U = class {
55821
55863
  for (let t of e) await this.registerTransformerFromConfig(t);
55822
55864
  }
55823
55865
  };
55824
- function pe() {
55825
- let s = (0, import_fastify.default)({});
55826
- return s.setErrorHandler(X), s.register(import_cors.default), s;
55866
+ function le() {
55867
+ let i = (0, import_fastify.default)({});
55868
+ return i.setErrorHandler(X), i.register(import_cors.default), i;
55827
55869
  }
55828
55870
  var B = class {
55829
55871
  app;
@@ -55832,7 +55874,7 @@ var B = class {
55832
55874
  providerService;
55833
55875
  transformerService;
55834
55876
  constructor(e = {}) {
55835
- this.configService = new j({ initialConfig: e.initialConfig }), this.providerService = new q(this.configService), this.llmService = new J(this.providerService), this.transformerService = new U(this.configService), this.app = pe();
55877
+ this.configService = new j(e), this.providerService = new J(this.configService), this.llmService = new q(this.providerService), this.transformerService = new U(this.configService), this.app = le();
55836
55878
  }
55837
55879
  async register(e, t) {
55838
55880
  await this.app.register(e, t);
@@ -55846,31 +55888,29 @@ var B = class {
55846
55888
  try {
55847
55889
  let r = n.body;
55848
55890
  if (!r || !r.model) return o.code(400).send({ error: "Missing model in request body" });
55849
- let [a, d] = r.model.split(",");
55850
- r.model = d, n.provider = a;
55891
+ let [c, l] = r.model.split(",");
55892
+ r.model = l, n.provider = c;
55851
55893
  return;
55852
55894
  } catch (r) {
55853
55895
  return n.log.error("Error in modelProviderMiddleware:", r), o.code(500).send({ error: "Internal server error" });
55854
55896
  }
55855
55897
  }), this.app.register(Z);
55856
55898
  let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
55857
- f(`\u{1F680} LLMs API server listening on ${e}`);
55899
+ m(`\u{1F680} LLMs API server listening on ${e}`);
55858
55900
  let t = async (n) => {
55859
- f(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
55901
+ m(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
55860
55902
  };
55861
55903
  process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
55862
55904
  } catch (e) {
55863
- f(`Error starting server: ${e}`), process.exit(1);
55905
+ m(`Error starting server: ${e}`), process.exit(1);
55864
55906
  }
55865
55907
  }
55866
55908
  };
55867
- var Rt = B;
55909
+ var Pt = B;
55868
55910
 
55869
55911
  // src/server.ts
55870
55912
  var createServer = (config) => {
55871
- const server = new Rt({
55872
- initialConfig: config
55873
- });
55913
+ const server = new Pt(config);
55874
55914
  return server;
55875
55915
  };
55876
55916
 
@@ -56089,10 +56129,17 @@ async function run(options = {}) {
56089
56129
  });
56090
56130
  const servicePort = process.env.SERVICE_PORT ? parseInt(process.env.SERVICE_PORT) : port;
56091
56131
  const server = createServer({
56092
- ...config,
56093
- providers: config.Providers || config.providers,
56094
- PORT: servicePort,
56095
- LOG_FILE: (0, import_path2.join)((0, import_os.homedir)(), ".claude-code-router", "claude-code-router.log")
56132
+ jsonPath: CONFIG_FILE,
56133
+ initialConfig: {
56134
+ // ...config,
56135
+ providers: config.Providers || config.providers,
56136
+ PORT: servicePort,
56137
+ LOG_FILE: (0, import_path2.join)(
56138
+ (0, import_os.homedir)(),
56139
+ ".claude-code-router",
56140
+ "claude-code-router.log"
56141
+ )
56142
+ }
56096
56143
  });
56097
56144
  server.addHook(
56098
56145
  "preHandler",
@@ -56182,7 +56229,7 @@ async function executeCodeCommand(args = []) {
56182
56229
  }
56183
56230
 
56184
56231
  // package.json
56185
- var version = "1.0.11";
56232
+ var version = "1.0.13";
56186
56233
 
56187
56234
  // src/cli.ts
56188
56235
  var import_child_process2 = require("child_process");