@musistudio/claude-code-router 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -9138,7 +9138,7 @@ var require_reply = __commonJS({
9138
9138
  handled--;
9139
9139
  const result = reply[kReplyTrailers][trailerName](reply, payload, cb);
9140
9140
  if (typeof result === "object" && typeof result.then === "function") {
9141
- result.then((v) => cb(null, v), cb);
9141
+ result.then((v2) => cb(null, v2), cb);
9142
9142
  }
9143
9143
  }
9144
9144
  if (skipped) res.end(null, null, null);
@@ -15991,17 +15991,17 @@ var require_core = __commonJS({
15991
15991
  return this.opts.defaultMeta = typeof meta == "object" ? meta[schemaId] || meta : void 0;
15992
15992
  }
15993
15993
  validate(schemaKeyRef, data) {
15994
- let v;
15994
+ let v2;
15995
15995
  if (typeof schemaKeyRef == "string") {
15996
- v = this.getSchema(schemaKeyRef);
15997
- if (!v)
15996
+ v2 = this.getSchema(schemaKeyRef);
15997
+ if (!v2)
15998
15998
  throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
15999
15999
  } else {
16000
- v = this.compile(schemaKeyRef);
16000
+ v2 = this.compile(schemaKeyRef);
16001
16001
  }
16002
- const valid = v(data);
16003
- if (!("$async" in v))
16004
- this.errors = v.errors;
16002
+ const valid = v2(data);
16003
+ if (!("$async" in v2))
16004
+ this.errors = v2.errors;
16005
16005
  return valid;
16006
16006
  }
16007
16007
  compile(schema, _meta) {
@@ -16495,8 +16495,8 @@ var require_ref = __commonJS({
16495
16495
  return callRef(cxt, (0, codegen_1._)`${rootName}.validate`, root, root.$async);
16496
16496
  }
16497
16497
  function callValidate(sch) {
16498
- const v = getValidate(cxt, sch);
16499
- callRef(cxt, v, sch, sch.$async);
16498
+ const v2 = getValidate(cxt, sch);
16499
+ callRef(cxt, v2, sch, sch.$async);
16500
16500
  }
16501
16501
  function inlineRefSchema(sch) {
16502
16502
  const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
@@ -16518,7 +16518,7 @@ var require_ref = __commonJS({
16518
16518
  return sch.validate ? gen.scopeValue("validate", { ref: sch.validate }) : (0, codegen_1._)`${gen.scopeValue("wrapper", { ref: sch })}.validate`;
16519
16519
  }
16520
16520
  exports2.getValidate = getValidate;
16521
- function callRef(cxt, v, sch, $async) {
16521
+ function callRef(cxt, v2, sch, $async) {
16522
16522
  const { gen, it } = cxt;
16523
16523
  const { allErrors, schemaEnv: env, opts } = it;
16524
16524
  const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
@@ -16531,8 +16531,8 @@ var require_ref = __commonJS({
16531
16531
  throw new Error("async schema referenced by sync schema");
16532
16532
  const valid = gen.let("valid");
16533
16533
  gen.try(() => {
16534
- gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt, v, passCxt)}`);
16535
- addEvaluatedFrom(v);
16534
+ gen.code((0, codegen_1._)`await ${(0, code_1.callValidateCode)(cxt, v2, passCxt)}`);
16535
+ addEvaluatedFrom(v2);
16536
16536
  if (!allErrors)
16537
16537
  gen.assign(valid, true);
16538
16538
  }, (e) => {
@@ -16544,7 +16544,7 @@ var require_ref = __commonJS({
16544
16544
  cxt.ok(valid);
16545
16545
  }
16546
16546
  function callSyncRef() {
16547
- cxt.result((0, code_1.callValidateCode)(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
16547
+ cxt.result((0, code_1.callValidateCode)(cxt, v2, passCxt), () => addEvaluatedFrom(v2), () => addErrorsFrom(v2));
16548
16548
  }
16549
16549
  function addErrorsFrom(source) {
16550
16550
  const errs = (0, codegen_1._)`${source}.errors`;
@@ -17034,7 +17034,7 @@ var require_enum = __commonJS({
17034
17034
  cxt.pass(valid);
17035
17035
  function loopEnum() {
17036
17036
  gen.assign(valid, false);
17037
- gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v})`, () => gen.assign(valid, true).break()));
17037
+ gen.forOf("v", schemaCode, (v2) => gen.if((0, codegen_1._)`${getEql()}(${data}, ${v2})`, () => gen.assign(valid, true).break()));
17038
17038
  }
17039
17039
  function equalCode(vSchema, i) {
17040
17040
  const sch = schema[i];
@@ -18420,7 +18420,7 @@ var require_ajv = __commonJS({
18420
18420
  var Ajv = class extends core_1.default {
18421
18421
  _addVocabularies() {
18422
18422
  super._addVocabularies();
18423
- draft7_1.default.forEach((v) => this.addVocabulary(v));
18423
+ draft7_1.default.forEach((v2) => this.addVocabulary(v2));
18424
18424
  if (this.opts.discriminator)
18425
18425
  this.addKeyword(discriminator_1.default);
18426
18426
  }
@@ -21449,9 +21449,9 @@ var require_ref2 = __commonJS({
21449
21449
  }
21450
21450
  function callValidate(schema) {
21451
21451
  const sch = compile_1.compileSchema.call(it.self, new compile_1.SchemaEnv({ schema, root, schemaPath: `/definitions/${ref}` }));
21452
- const v = (0, ref_1.getValidate)(cxt, sch);
21452
+ const v2 = (0, ref_1.getValidate)(cxt, sch);
21453
21453
  const errsCount = gen.const("_errs", names_1.default.errors);
21454
- (0, ref_1.callRef)(cxt, v, sch, sch.$async);
21454
+ (0, ref_1.callRef)(cxt, v2, sch, sch.$async);
21455
21455
  gen.assign(valid, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
21456
21456
  }
21457
21457
  function inlineRefSchema(schema) {
@@ -21681,7 +21681,7 @@ var require_enum2 = __commonJS({
21681
21681
  }
21682
21682
  cxt.pass(valid);
21683
21683
  function loopEnum() {
21684
- gen.forOf("v", schemaValue, (v) => gen.if((0, codegen_1._)`${valid} = ${data} === ${v}`, () => gen.break()));
21684
+ gen.forOf("v", schemaValue, (v2) => gen.if((0, codegen_1._)`${valid} = ${data} === ${v2}`, () => gen.break()));
21685
21685
  }
21686
21686
  }
21687
21687
  };
@@ -23173,10 +23173,10 @@ var require_standalone3 = __commonJS({
23173
23173
  const { _n } = ajv.scope.opts;
23174
23174
  return typeof refsOrFunc == "function" ? funcExportCode(refsOrFunc.source) : refsOrFunc !== void 0 ? multiExportsCode(refsOrFunc, getValidate) : multiExportsCode(ajv.schemas, (sch) => sch.meta ? void 0 : ajv.compile(sch.schema));
23175
23175
  function getValidate(id2) {
23176
- const v = ajv.getSchema(id2);
23177
- if (!v)
23176
+ const v2 = ajv.getSchema(id2);
23177
+ if (!v2)
23178
23178
  throw new Error(`moduleCode: no schema with id ${id2}`);
23179
- return v;
23179
+ return v2;
23180
23180
  }
23181
23181
  function funcExportCode(source) {
23182
23182
  const usedValues = {};
@@ -23192,11 +23192,11 @@ var require_standalone3 = __commonJS({
23192
23192
  const usedValues = {};
23193
23193
  let code = (0, code_1._)`"use strict";`;
23194
23194
  for (const name in schemas) {
23195
- const v = getValidateFunc(schemas[name]);
23196
- if (v) {
23197
- const vCode = validateCode(usedValues, v.source);
23195
+ const v2 = getValidateFunc(schemas[name]);
23196
+ if (v2) {
23197
+ const vCode = validateCode(usedValues, v2.source);
23198
23198
  const exportSyntax = ajv.opts.code.esm ? (0, code_1._)`export const ${(0, code_1.getEsmExportName)(name)}` : (0, code_1._)`exports${(0, code_1.getProperty)(name)}`;
23199
- code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a = v.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
23199
+ code = (0, code_1._)`${code}${_n}${exportSyntax} = ${(_a = v2.source) === null || _a === void 0 ? void 0 : _a.validateName};${_n}${vCode}`;
23200
23200
  }
23201
23201
  }
23202
23202
  return `${code}`;
@@ -23214,8 +23214,8 @@ var require_standalone3 = __commonJS({
23214
23214
  var _a;
23215
23215
  const vRef = (_a = n.value) === null || _a === void 0 ? void 0 : _a.ref;
23216
23216
  if (n.prefix === "validate" && typeof vRef == "function") {
23217
- const v = vRef;
23218
- return validateCode(usedValues, v.source);
23217
+ const v2 = vRef;
23218
+ return validateCode(usedValues, v2.source);
23219
23219
  } else if ((n.prefix === "root" || n.prefix === "wrapper") && typeof vRef == "object") {
23220
23220
  const { validate, validateName } = vRef;
23221
23221
  if (!validateName)
@@ -23911,8 +23911,8 @@ var require_valid = __commonJS({
23911
23911
  "use strict";
23912
23912
  var parse = require_parse3();
23913
23913
  var valid = (version2, options) => {
23914
- const v = parse(version2, options);
23915
- return v ? v.version : null;
23914
+ const v2 = parse(version2, options);
23915
+ return v2 ? v2.version : null;
23916
23916
  };
23917
23917
  module2.exports = valid;
23918
23918
  }
@@ -24831,10 +24831,10 @@ var require_max_satisfying = __commonJS({
24831
24831
  } catch (er) {
24832
24832
  return null;
24833
24833
  }
24834
- versions.forEach((v) => {
24835
- if (rangeObj.test(v)) {
24836
- if (!max || maxSV.compare(v) === -1) {
24837
- max = v;
24834
+ versions.forEach((v2) => {
24835
+ if (rangeObj.test(v2)) {
24836
+ if (!max || maxSV.compare(v2) === -1) {
24837
+ max = v2;
24838
24838
  maxSV = new SemVer(max, options);
24839
24839
  }
24840
24840
  }
@@ -24860,10 +24860,10 @@ var require_min_satisfying = __commonJS({
24860
24860
  } catch (er) {
24861
24861
  return null;
24862
24862
  }
24863
- versions.forEach((v) => {
24864
- if (rangeObj.test(v)) {
24865
- if (!min || minSV.compare(v) === 1) {
24866
- min = v;
24863
+ versions.forEach((v2) => {
24864
+ if (rangeObj.test(v2)) {
24865
+ if (!min || minSV.compare(v2) === 1) {
24866
+ min = v2;
24867
24867
  minSV = new SemVer(min, options);
24868
24868
  }
24869
24869
  }
@@ -25062,8 +25062,8 @@ var require_simplify = __commonJS({
25062
25062
  const set = [];
25063
25063
  let first = null;
25064
25064
  let prev = null;
25065
- const v = versions.sort((a, b2) => compare(a, b2, options));
25066
- for (const version2 of v) {
25065
+ const v2 = versions.sort((a, b2) => compare(a, b2, options));
25066
+ for (const version2 of v2) {
25067
25067
  const included = satisfies(version2, range, options);
25068
25068
  if (included) {
25069
25069
  prev = version2;
@@ -25085,11 +25085,11 @@ var require_simplify = __commonJS({
25085
25085
  for (const [min, max] of set) {
25086
25086
  if (min === max) {
25087
25087
  ranges.push(min);
25088
- } else if (!max && min === v[0]) {
25088
+ } else if (!max && min === v2[0]) {
25089
25089
  ranges.push("*");
25090
25090
  } else if (!max) {
25091
25091
  ranges.push(`>=${min}`);
25092
- } else if (min === v[0]) {
25092
+ } else if (min === v2[0]) {
25093
25093
  ranges.push(`<=${max}`);
25094
25094
  } else {
25095
25095
  ranges.push(`${min} - ${max}`);
@@ -26456,10 +26456,10 @@ var require_util2 = __commonJS({
26456
26456
  if (k2 === void 0) k2 = k;
26457
26457
  o[k2] = m[k];
26458
26458
  });
26459
- var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26460
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26461
- } : function(o, v) {
26462
- o["default"] = v;
26459
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
26460
+ Object.defineProperty(o, "default", { enumerable: true, value: v2 });
26461
+ } : function(o, v2) {
26462
+ o["default"] = v2;
26463
26463
  });
26464
26464
  var __importStar = exports2 && exports2.__importStar || function(mod) {
26465
26465
  if (mod && mod.__esModule) return mod;
@@ -26527,10 +26527,10 @@ var require_tokenizer = __commonJS({
26527
26527
  if (k2 === void 0) k2 = k;
26528
26528
  o[k2] = m[k];
26529
26529
  });
26530
- var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26531
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26532
- } : function(o, v) {
26533
- o["default"] = v;
26530
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
26531
+ Object.defineProperty(o, "default", { enumerable: true, value: v2 });
26532
+ } : function(o, v2) {
26533
+ o["default"] = v2;
26534
26534
  });
26535
26535
  var __importStar = exports2 && exports2.__importStar || function(mod) {
26536
26536
  if (mod && mod.__esModule) return mod;
@@ -26828,10 +26828,10 @@ var require_sets_lookup = __commonJS({
26828
26828
  if (k2 === void 0) k2 = k;
26829
26829
  o[k2] = m[k];
26830
26830
  });
26831
- var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26832
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26833
- } : function(o, v) {
26834
- o["default"] = v;
26831
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
26832
+ Object.defineProperty(o, "default", { enumerable: true, value: v2 });
26833
+ } : function(o, v2) {
26834
+ o["default"] = v2;
26835
26835
  });
26836
26836
  var __importStar = exports2 && exports2.__importStar || function(mod) {
26837
26837
  if (mod && mod.__esModule) return mod;
@@ -26883,10 +26883,10 @@ var require_write_set_tokens = __commonJS({
26883
26883
  if (k2 === void 0) k2 = k;
26884
26884
  o[k2] = m[k];
26885
26885
  });
26886
- var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
26887
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26888
- } : function(o, v) {
26889
- o["default"] = v;
26886
+ var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v2) {
26887
+ Object.defineProperty(o, "default", { enumerable: true, value: v2 });
26888
+ } : function(o, v2) {
26889
+ o["default"] = v2;
26890
26890
  });
26891
26891
  var __importStar = exports2 && exports2.__importStar || function(mod) {
26892
26892
  if (mod && mod.__esModule) return mod;
@@ -30410,10 +30410,10 @@ var require_dist4 = __commonJS({
30410
30410
  var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
30411
30411
  var __toString = Object.prototype.toString;
30412
30412
  var NullObject = /* @__PURE__ */ (() => {
30413
- const C2 = function() {
30413
+ const C = function() {
30414
30414
  };
30415
- C2.prototype = /* @__PURE__ */ Object.create(null);
30416
- return C2;
30415
+ C.prototype = /* @__PURE__ */ Object.create(null);
30416
+ return C;
30417
30417
  })();
30418
30418
  function parse(str, options) {
30419
30419
  const obj = new NullObject();
@@ -34619,7 +34619,7 @@ var require_util3 = __commonJS({
34619
34619
  var { InvalidArgumentError, ConnectTimeoutError } = require_errors5();
34620
34620
  var { headerNameLowerCasedRecord } = require_constants3();
34621
34621
  var { tree } = require_tree();
34622
- var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((v) => Number(v));
34622
+ var [nodeMajor, nodeMinor] = process.versions.node.split(".", 2).map((v2) => Number(v2));
34623
34623
  var BodyAsyncIterable = class {
34624
34624
  constructor(body) {
34625
34625
  this[kBody] = body;
@@ -35763,14 +35763,14 @@ var require_wrap_handler = __commonJS({
35763
35763
  onRequestUpgrade(controller, statusCode, headers, socket) {
35764
35764
  const rawHeaders = [];
35765
35765
  for (const [key, val] of Object.entries(headers)) {
35766
- rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v) => Buffer.from(v)) : Buffer.from(val));
35766
+ rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
35767
35767
  }
35768
35768
  this.#handler.onUpgrade?.(statusCode, rawHeaders, socket);
35769
35769
  }
35770
35770
  onResponseStart(controller, statusCode, headers, statusMessage) {
35771
35771
  const rawHeaders = [];
35772
35772
  for (const [key, val] of Object.entries(headers)) {
35773
- rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v) => Buffer.from(v)) : Buffer.from(val));
35773
+ rawHeaders.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
35774
35774
  }
35775
35775
  if (this.#handler.onHeaders?.(statusCode, rawHeaders, () => controller.resume(), statusMessage) === false) {
35776
35776
  controller.pause();
@@ -35784,7 +35784,7 @@ var require_wrap_handler = __commonJS({
35784
35784
  onResponseEnd(controller, trailers) {
35785
35785
  const rawTrailers = [];
35786
35786
  for (const [key, val] of Object.entries(trailers)) {
35787
- rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((v) => Buffer.from(v)) : Buffer.from(val));
35787
+ rawTrailers.push(Buffer.from(key), Array.isArray(val) ? val.map((v2) => Buffer.from(v2)) : Buffer.from(val));
35788
35788
  }
35789
35789
  this.#handler.onComplete?.(rawTrailers);
35790
35790
  }
@@ -44490,8 +44490,8 @@ var require_mock_utils = __commonJS({
44490
44490
  }
44491
44491
  if (value.includes(",")) {
44492
44492
  const values = value.split(",");
44493
- for (const v of values) {
44494
- normalizedQp.append(key, v);
44493
+ for (const v2 of values) {
44494
+ normalizedQp.append(key, v2);
44495
44495
  }
44496
44496
  continue;
44497
44497
  }
@@ -54958,7 +54958,7 @@ var initConfig = async () => {
54958
54958
  return config;
54959
54959
  };
54960
54960
 
54961
- // node_modules/.pnpm/@musistudio+llms@1.0.8_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54961
+ // node_modules/.pnpm/@musistudio+llms@1.0.9_ws@8.18.3_zod@3.25.67/node_modules/@musistudio/llms/dist/esm/server.mjs
54962
54962
  var import_fastify = __toESM(require_fastify(), 1);
54963
54963
  var import_cors = __toESM(require_cors(), 1);
54964
54964
  var import_fs = require("fs");
@@ -55037,7 +55037,7 @@ var $ = class {
55037
55037
  return this.options.initialConfig && e.push("Initial Config"), this.options.useJsonFile && this.options.jsonPath && e.push(`JSON: ${this.options.jsonPath}`), this.options.useEnvFile && e.push(`ENV: ${this.options.envPath}`), this.options.useEnvironmentVariables && e.push("Environment Variables"), `Config sources: ${e.join(", ")}`;
55038
55038
  }
55039
55039
  };
55040
- function C(...s) {
55040
+ function v(...s) {
55041
55041
  if (console.log(...s), !(process.env.LOG === "true")) return;
55042
55042
  let n = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${Array.isArray(s) ? s.map((o) => typeof o == "object" ? JSON.stringify(o) : String(o)).join(" ") : ""}
55043
55043
  `, r = process.env.LOG_FILE || "app.log";
@@ -55054,50 +55054,50 @@ async function le(s, e, t) {
55054
55054
  }
55055
55055
  function de(s, e, t) {
55056
55056
  let n = new Headers({ "Content-Type": "application/json" });
55057
- t.headers && Object.entries(t.headers).forEach(([d, c]) => {
55058
- n.set(d, c);
55057
+ t.headers && Object.entries(t.headers).forEach(([l, d]) => {
55058
+ n.set(l, d);
55059
55059
  });
55060
55060
  let r, o = AbortSignal.timeout(t.TIMEOUT ?? 60 * 1e3 * 60);
55061
55061
  if (t.signal) {
55062
- let d = new AbortController(), c = () => d.abort();
55063
- t.signal.addEventListener("abort", c), o.addEventListener("abort", c), r = d.signal;
55062
+ let l = new AbortController(), d = () => l.abort();
55063
+ t.signal.addEventListener("abort", d), o.addEventListener("abort", d), r = l.signal;
55064
55064
  } else r = o;
55065
- let l = { method: "POST", headers: n, body: JSON.stringify(e), signal: r };
55066
- return t.httpsProxy && (l.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), C("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, l), fetch(typeof s == "string" ? s : s.toString(), l);
55065
+ let c = { method: "POST", headers: n, body: JSON.stringify(e), signal: r };
55066
+ return t.httpsProxy && (c.dispatcher = new import_undici.ProxyAgent(new URL(t.httpsProxy).toString())), v("final request:", typeof s == "string" ? s : s.toString(), t.httpsProxy, c), fetch(typeof s == "string" ? s : s.toString(), c);
55067
55067
  }
55068
- var fe = async (s) => {
55068
+ var ue = async (s) => {
55069
55069
  s.get("/", async (t, n) => ({ message: "LLMs API", version: "1.0.0" })), s.get("/health", async (t, n) => ({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
55070
55070
  let e = s._server.transformerService.getTransformersWithEndpoint();
55071
55071
  for (let { name: t, transformer: n } of e) n.endPoint && s.post(n.endPoint, async (r, o) => {
55072
- let l = r.body, d = r.provider, c = s._server.providerService.getProvider(d);
55073
- if (!c) throw L(`Provider '${d}' not found`, 404, "provider_not_found");
55074
- let a = l, u = {};
55072
+ let c = r.body, l = r.provider, d = s._server.providerService.getProvider(l);
55073
+ if (!d) throw L(`Provider '${l}' not found`, 404, "provider_not_found");
55074
+ let i = c, p = {};
55075
55075
  if (typeof n.transformRequestOut == "function") {
55076
- let i = await n.transformRequestOut(l);
55077
- i.body ? (a = i.body, u = i.config || {}) : a = i;
55078
- }
55079
- if (C("use transformers:", c.transformer?.use), c.transformer?.use?.length) for (let i of c.transformer.use) {
55080
- if (!i || typeof i.transformRequestIn != "function") continue;
55081
- let v = await i.transformRequestIn(a, c);
55082
- v.body ? (a = v.body, u = { ...u, ...v.config }) : a = v;
55083
- }
55084
- if (c.transformer?.[r.body.model]?.use?.length) for (let i of c.transformer[r.body.model].use) !i || typeof i.transformRequestIn != "function" || (a = await i.transformRequestIn(a, c));
55085
- let y = u.url || new URL(c.baseUrl), k = await de(y, a, { httpsProxy: s._server.configService.getHttpsProxy(), ...u, headers: { Authorization: `Bearer ${c.apiKey}`, ...u?.headers || {} } });
55086
- if (!k.ok) {
55087
- let i = await k.text();
55088
- throw C(`Error response from ${y}: ${i}`), L(`Error from provider: ${i}`, k.status, "provider_response_error");
55089
- }
55090
- let g = k;
55091
- if (c.transformer?.use?.length) for (let i of c.transformer.use) !i || typeof i.transformResponseOut != "function" || (g = await i.transformResponseOut(g));
55092
- if (c.transformer?.[r.body.model]?.use?.length) for (let i of c.transformer[r.body.model].use) !i || typeof i.transformResponseOut != "function" || (g = await i.transformResponseOut(g));
55093
- return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status), l?.stream === true ? (o.header("Content-Type", "text/event-stream"), o.header("Cache-Control", "no-cache"), o.header("Connection", "keep-alive"), o.send(g.body)) : g.json();
55076
+ let a = await n.transformRequestOut(c);
55077
+ a.body ? (i = a.body, p = a.config || {}) : i = a;
55078
+ }
55079
+ if (v("use transformers:", d.transformer?.use), d.transformer?.use?.length) for (let a of d.transformer.use) {
55080
+ if (!a || typeof a.transformRequestIn != "function") continue;
55081
+ let y = await a.transformRequestIn(i, d);
55082
+ y.body ? (i = y.body, p = { ...p, ...y.config }) : i = y;
55083
+ }
55084
+ if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformRequestIn != "function" || (i = await a.transformRequestIn(i, d));
55085
+ let _ = p.url || new URL(d.baseUrl), C = await de(_, i, { httpsProxy: s._server.configService.getHttpsProxy(), ...p, headers: { Authorization: `Bearer ${d.apiKey}`, ...p?.headers || {} } });
55086
+ if (!C.ok) {
55087
+ let a = await C.text();
55088
+ throw v(`Error response from ${_}: ${a}`), L(`Error from provider: ${a}`, C.status, "provider_response_error");
55089
+ }
55090
+ let g = C;
55091
+ if (d.transformer?.use?.length) for (let a of d.transformer.use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
55092
+ if (d.transformer?.[r.body.model]?.use?.length) for (let a of d.transformer[r.body.model].use) !a || typeof a.transformResponseOut != "function" || (g = await a.transformResponseOut(g));
55093
+ return n.transformResponseIn && (g = await n.transformResponseIn(g)), g.ok || o.code(g.status), c?.stream === true ? (o.header("Content-Type", "text/event-stream"), o.header("Cache-Control", "no-cache"), o.header("Connection", "keep-alive"), o.send(g.body)) : g.json();
55094
55094
  });
55095
55095
  s.post("/providers", { schema: { body: { type: "object", properties: { id: { type: "string" }, name: { type: "string" }, type: { type: "string", enum: ["openai", "anthropic"] }, baseUrl: { type: "string" }, apiKey: { type: "string" }, models: { type: "array", items: { type: "string" } } }, required: ["id", "name", "type", "baseUrl", "apiKey", "models"] } } }, async (t, n) => {
55096
- let { name: r, type: o, baseUrl: l, apiKey: d, models: c } = t.body;
55096
+ let { name: r, type: o, baseUrl: c, apiKey: l, models: d } = t.body;
55097
55097
  if (!r?.trim()) throw L("Provider name is required", 400, "invalid_request");
55098
- if (!l || !ke(l)) throw L("Valid base URL is required", 400, "invalid_request");
55099
- if (!d?.trim()) throw L("API key is required", 400, "invalid_request");
55100
- if (!c || !Array.isArray(c) || c.length === 0) throw L("At least one model is required", 400, "invalid_request");
55098
+ if (!c || !Ce(c)) throw L("Valid base URL is required", 400, "invalid_request");
55099
+ if (!l?.trim()) throw L("API key is required", 400, "invalid_request");
55100
+ if (!d || !Array.isArray(d) || d.length === 0) throw L("At least one model is required", 400, "invalid_request");
55101
55101
  if (s._server.providerService.getProvider(id)) throw L(`Provider with ID '${id}' already exists`, 400, "provider_exists");
55102
55102
  return s._server.providerService.registerProvider(t.body);
55103
55103
  }), s.get("/providers", async (t, n) => s._server.providerService.getProviders()), s.get("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => {
@@ -55108,7 +55108,7 @@ var fe = async (s) => {
55108
55108
  return r || n.code(404).send({ error: "Provider not found" });
55109
55109
  }), s.delete("/providers/:id", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] } } }, async (t, n) => s._server.providerService.deleteProvider(t.params.id) ? { message: "Provider deleted successfully" } : n.code(404).send({ error: "Provider not found" })), s.patch("/providers/:id/toggle", { schema: { params: { type: "object", properties: { id: { type: "string" } }, required: ["id"] }, body: { type: "object", properties: { enabled: { type: "boolean" } }, required: ["enabled"] } } }, async (t, n) => s._server.providerService.toggleProvider(t.params.id, t.body.enabled) ? { message: `Provider ${t.body.enabled ? "enabled" : "disabled"} successfully` } : n.code(404).send({ error: "Provider not found" }));
55110
55110
  };
55111
- function ke(s) {
55111
+ function Ce(s) {
55112
55112
  try {
55113
55113
  return new URL(s), true;
55114
55114
  } catch {
@@ -55175,20 +55175,20 @@ var F = class {
55175
55175
  t.transformer && Object.keys(t.transformer).forEach((r) => {
55176
55176
  r === "use" ? Array.isArray(t.transformer.use) && (n.use = t.transformer.use.map((o) => {
55177
55177
  if (Array.isArray(o) && typeof o[0] == "string") {
55178
- let l = this.transformerService.getTransformer(o[0]);
55179
- if (l) return new l(o[1]);
55178
+ let c = this.transformerService.getTransformer(o[0]);
55179
+ if (c) return new c(o[1]);
55180
55180
  }
55181
55181
  if (typeof o == "string") return this.transformerService.getTransformer(o);
55182
55182
  }).filter((o) => typeof o < "u")) : Array.isArray(t.transformer[r]?.use) && (n[r] = { use: t.transformer[r].use.map((o) => {
55183
55183
  if (Array.isArray(o) && typeof o[0] == "string") {
55184
- let l = this.transformerService.getTransformer(o[0]);
55185
- if (l) return new l(o[1]);
55184
+ let c = this.transformerService.getTransformer(o[0]);
55185
+ if (c) return new c(o[1]);
55186
55186
  }
55187
55187
  if (typeof o == "string") return this.transformerService.getTransformer(o);
55188
55188
  }).filter((o) => typeof o < "u") });
55189
- }), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), C(`${t.name} provider registered`);
55189
+ }), this.registerProvider({ name: t.name, baseUrl: t.api_base_url, apiKey: t.api_key, models: t.models || [], transformer: t.transformer ? n : void 0 }), v(`${t.name} provider registered`);
55190
55190
  } catch (n) {
55191
- C(`${t.name} provider registered error: ${n}`);
55191
+ v(`${t.name} provider registered error: ${n}`);
55192
55192
  }
55193
55193
  });
55194
55194
  }
@@ -55210,11 +55210,11 @@ var F = class {
55210
55210
  if (!n) return null;
55211
55211
  let r = { ...n, ...t, updatedAt: /* @__PURE__ */ new Date() };
55212
55212
  return this.providers.set(e, r), t.models && (n.models.forEach((o) => {
55213
- let l = `${n.id},${o}`;
55214
- this.modelRoutes.delete(l), this.modelRoutes.delete(o);
55213
+ let c = `${n.id},${o}`;
55214
+ this.modelRoutes.delete(c), this.modelRoutes.delete(o);
55215
55215
  }), t.models.forEach((o) => {
55216
- let l = `${n.name},${o}`, d = { provider: n.name, model: o, fullModel: l };
55217
- this.modelRoutes.set(l, d), this.modelRoutes.has(o) || this.modelRoutes.set(o, d);
55216
+ let c = `${n.name},${o}`, l = { provider: n.name, model: o, fullModel: c };
55217
+ this.modelRoutes.set(c, l), this.modelRoutes.has(o) || this.modelRoutes.set(o, l);
55218
55218
  })), r;
55219
55219
  }
55220
55220
  deleteProvider(e) {
@@ -55265,35 +55265,37 @@ var F = class {
55265
55265
  var U = class {
55266
55266
  name = "Anthropic";
55267
55267
  endPoint = "/v1/messages";
55268
- transformRequestOut(e) {
55269
- C("Anthropic Request:", JSON.stringify(e, null, 2));
55268
+ async transformRequestOut(e) {
55269
+ v("Anthropic Request:", JSON.stringify(e, null, 2));
55270
55270
  let t = [];
55271
55271
  if (e.system) {
55272
55272
  if (typeof e.system == "string") t.push({ role: "system", content: e.system });
55273
55273
  else if (Array.isArray(e.system)) {
55274
- let o = e.system.filter((l) => l.type === "text" && l.text).map((l) => ({ type: "text", text: l.text, cache_control: l.cache_control }));
55274
+ let o = e.system.filter((c) => c.type === "text" && c.text).map((c) => ({ type: "text", text: c.text, cache_control: c.cache_control }));
55275
55275
  t.push({ role: "system", content: o });
55276
55276
  }
55277
55277
  }
55278
- return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o, l) => {
55278
+ return JSON.parse(JSON.stringify(e.messages || []))?.forEach((o, c) => {
55279
55279
  if (o.role === "user" || o.role === "assistant") {
55280
- let d = { role: o.role, content: null };
55281
- if (typeof o.content == "string") t.push({ role: o.role, content: o.content });
55282
- else if (Array.isArray(o.content)) {
55280
+ if (typeof o.content == "string") {
55281
+ t.push({ role: o.role, content: o.content });
55282
+ return;
55283
+ }
55284
+ if (Array.isArray(o.content)) {
55283
55285
  if (o.role === "user") {
55284
- let c = o.content.filter((u) => u.type === "tool_result" && u.tool_use_id);
55285
- c.length && c.forEach((u, y) => {
55286
- let k = { role: "tool", content: typeof u.content == "string" ? u.content : JSON.stringify(u.content), tool_call_id: u.tool_use_id, cache_control: u.cache_control };
55287
- t.push(k);
55286
+ let l = o.content.filter((i) => i.type === "tool_result" && i.tool_use_id);
55287
+ l.length && l.forEach((i, p) => {
55288
+ let _ = { role: "tool", content: typeof i.content == "string" ? i.content : JSON.stringify(i.content), tool_call_id: i.tool_use_id, cache_control: i.cache_control };
55289
+ t.push(_);
55288
55290
  });
55289
- let a = o.content.filter((u) => u.type === "text" && u.text);
55290
- a.length && t.push({ role: "user", content: a });
55291
+ let d = o.content.filter((i) => i.type === "text" && i.text || i.type === "image" && i.source);
55292
+ d.length && t.push({ role: "user", content: d.map((i) => i?.type === "image" ? { type: "image_url", image_url: { url: i.source?.type === "base64" ? i.source.data : i.source.url }, media_type: i.source.media_type } : i) });
55291
55293
  } else if (o.role === "assistant") {
55292
- let c = { role: "assistant", content: null }, a = o.content.filter((y) => y.type === "text" && y.text);
55293
- a.length && (c.content = a.map((y) => y.text).join(`
55294
+ let l = { role: "assistant", content: null }, d = o.content.filter((p) => p.type === "text" && p.text);
55295
+ d.length && (l.content = d.map((p) => p.text).join(`
55294
55296
  `));
55295
- let u = o.content.filter((y) => y.type === "tool_use" && y.id);
55296
- u.length && (c.tool_calls = u.map((y) => ({ id: y.id, type: "function", function: { name: y.name, arguments: JSON.stringify(y.input || {}) } }))), t.push(c);
55297
+ let i = o.content.filter((p) => p.type === "tool_use" && p.id);
55298
+ i.length && (l.tool_calls = i.map((p) => ({ id: p.id, type: "function", function: { name: p.name, arguments: JSON.stringify(p.input || {}) } }))), t.push(l);
55297
55299
  }
55298
55300
  return;
55299
55301
  }
@@ -55315,27 +55317,27 @@ var U = class {
55315
55317
  }
55316
55318
  async convertOpenAIStreamToAnthropic(e) {
55317
55319
  return new ReadableStream({ async start(n) {
55318
- let r = new TextEncoder(), o = `msg_${Date.now()}`, l = "unknown", d = false, c = false, a = false, u = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), k = 0, g = 0, f = 0, i = false, v = false, h = 0, p = (x) => {
55319
- if (!i) try {
55320
+ let r = new TextEncoder(), o = `msg_${Date.now()}`, c = "unknown", l = false, d = false, i = false, p = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), C = 0, g = 0, u = 0, a = false, y = false, h = 0, f = (x) => {
55321
+ if (!a) try {
55320
55322
  n.enqueue(x);
55321
55323
  let R = new TextDecoder().decode(x);
55322
- C("send data:", R.trim());
55324
+ v("send data:", R.trim());
55323
55325
  } catch (R) {
55324
- if (R instanceof TypeError && R.message.includes("Controller is already closed")) i = true;
55325
- else throw C(`send data error: ${R.message}`), R;
55326
+ if (R instanceof TypeError && R.message.includes("Controller is already closed")) a = true;
55327
+ else throw v(`send data error: ${R.message}`), R;
55326
55328
  }
55327
55329
  }, m = () => {
55328
- if (!i) try {
55329
- n.close(), i = true;
55330
+ if (!a) try {
55331
+ n.close(), a = true;
55330
55332
  } catch (x) {
55331
- if (x instanceof TypeError && x.message.includes("Controller is already closed")) i = true;
55333
+ if (x instanceof TypeError && x.message.includes("Controller is already closed")) a = true;
55332
55334
  else throw x;
55333
55335
  }
55334
55336
  }, T = null;
55335
55337
  try {
55336
55338
  T = e.getReader();
55337
55339
  let x = new TextDecoder(), R = "";
55338
- for (; !i; ) {
55340
+ for (; !a; ) {
55339
55341
  let { done: X, value: me } = await T.read();
55340
55342
  if (X) break;
55341
55343
  R += x.decode(me, { stream: true });
@@ -55343,129 +55345,129 @@ var U = class {
55343
55345
  `);
55344
55346
  R = se.pop() || "";
55345
55347
  for (let ie of se) {
55346
- if (i || a) break;
55348
+ if (a || i) break;
55347
55349
  if (!ie.startsWith("data: ")) continue;
55348
55350
  let Q = ie.slice(6);
55349
55351
  if (Q !== "[DONE]") try {
55350
55352
  let O = JSON.parse(Q);
55351
- if (k++, C("Original Response:", JSON.stringify(O, null, 2)), O.error) {
55352
- let _ = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
55353
- p(r.encode(`event: error
55354
- data: ${JSON.stringify(_)}
55353
+ if (C++, v("Original Response:", JSON.stringify(O, null, 2)), O.error) {
55354
+ let k = { type: "error", message: { type: "api_error", message: JSON.stringify(O.error) } };
55355
+ f(r.encode(`event: error
55356
+ data: ${JSON.stringify(k)}
55355
55357
 
55356
55358
  `));
55357
55359
  continue;
55358
55360
  }
55359
- if (l = O.model || l, !d && !i && !a) {
55360
- d = true;
55361
- let _ = { type: "message_start", message: { id: o, type: "message", role: "assistant", content: [], model: l, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55362
- p(r.encode(`event: message_start
55363
- data: ${JSON.stringify(_)}
55361
+ if (c = O.model || c, !l && !a && !i) {
55362
+ l = true;
55363
+ let k = { type: "message_start", message: { id: o, type: "message", role: "assistant", content: [], model: c, stop_reason: null, stop_sequence: null, usage: { input_tokens: 1, output_tokens: 1 } } };
55364
+ f(r.encode(`event: message_start
55365
+ data: ${JSON.stringify(k)}
55364
55366
 
55365
55367
  `));
55366
55368
  }
55367
55369
  let w = O.choices?.[0];
55368
55370
  if (!w) continue;
55369
- if (w?.delta?.thinking && !i && !a) {
55370
- if (!v) {
55371
- let _ = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
55372
- p(r.encode(`event: content_block_start
55373
- data: ${JSON.stringify(_)}
55371
+ if (w?.delta?.thinking && !a && !i) {
55372
+ if (!y) {
55373
+ let k = { type: "content_block_start", index: h, content_block: { type: "thinking", thinking: "" } };
55374
+ f(r.encode(`event: content_block_start
55375
+ data: ${JSON.stringify(k)}
55374
55376
 
55375
- `)), v = true;
55377
+ `)), y = true;
55376
55378
  }
55377
55379
  if (w.delta.thinking.signature) {
55378
- let _ = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
55379
- p(r.encode(`event: content_block_delta
55380
- data: ${JSON.stringify(_)}
55380
+ let k = { type: "content_block_delta", index: h, delta: { type: "signature_delta", signature: w.delta.thinking.signature } };
55381
+ f(r.encode(`event: content_block_delta
55382
+ data: ${JSON.stringify(k)}
55381
55383
 
55382
55384
  `));
55383
55385
  let S = { type: "content_block_stop", index: h };
55384
- p(r.encode(`event: content_block_stop
55386
+ f(r.encode(`event: content_block_stop
55385
55387
  data: ${JSON.stringify(S)}
55386
55388
 
55387
55389
  `)), h++;
55388
55390
  } else if (w.delta.thinking.content) {
55389
- let _ = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
55390
- p(r.encode(`event: content_block_delta
55391
- data: ${JSON.stringify(_)}
55391
+ let k = { type: "content_block_delta", index: h, delta: { type: "thinking_delta", thinking: w.delta.thinking.content || "" } };
55392
+ f(r.encode(`event: content_block_delta
55393
+ data: ${JSON.stringify(k)}
55392
55394
 
55393
55395
  `));
55394
55396
  }
55395
55397
  }
55396
- if (w?.delta?.content && !i && !a) {
55397
- if (g++, !c && !a) {
55398
- c = true;
55399
- let _ = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
55400
- p(r.encode(`event: content_block_start
55401
- data: ${JSON.stringify(_)}
55398
+ if (w?.delta?.content && !a && !i) {
55399
+ if (g++, !d && !i) {
55400
+ d = true;
55401
+ let k = { type: "content_block_start", index: h, content_block: { type: "text", text: "" } };
55402
+ f(r.encode(`event: content_block_start
55403
+ data: ${JSON.stringify(k)}
55402
55404
 
55403
55405
  `));
55404
55406
  }
55405
- if (!i && !a) {
55406
- let _ = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
55407
- p(r.encode(`event: content_block_delta
55408
- data: ${JSON.stringify(_)}
55407
+ if (!a && !i) {
55408
+ let k = { type: "content_block_delta", index: h, delta: { type: "text_delta", text: w.delta.content } };
55409
+ f(r.encode(`event: content_block_delta
55410
+ data: ${JSON.stringify(k)}
55409
55411
 
55410
55412
  `));
55411
55413
  }
55412
55414
  }
55413
- if (w?.delta?.tool_calls && !i && !a) {
55414
- f++;
55415
- let _ = /* @__PURE__ */ new Set();
55415
+ if (w?.delta?.tool_calls && !a && !i) {
55416
+ u++;
55417
+ let k = /* @__PURE__ */ new Set();
55416
55418
  for (let S of w.delta.tool_calls) {
55417
- if (i) break;
55419
+ if (a) break;
55418
55420
  let P = S.index ?? 0;
55419
- if (_.has(P)) continue;
55420
- if (_.add(P), !y.has(P)) {
55421
- let E = c ? y.size + 1 : y.size;
55421
+ if (k.has(P)) continue;
55422
+ if (k.add(P), !_.has(P)) {
55423
+ let E = d ? _.size + 1 : _.size;
55422
55424
  if (E !== 0) {
55423
- C("content_block_stop2");
55425
+ v("content_block_stop2");
55424
55426
  let he = { type: "content_block_stop", index: h };
55425
- p(r.encode(`event: content_block_stop
55427
+ f(r.encode(`event: content_block_stop
55426
55428
  data: ${JSON.stringify(he)}
55427
55429
 
55428
55430
  `)), h++;
55429
55431
  }
55430
- y.set(P, E);
55431
- let M = S.id || `call_${Date.now()}_${P}`, A = S.function?.name || `tool_${P}`, N = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: M, name: A, input: {} } };
55432
- p(r.encode(`event: content_block_start
55432
+ _.set(P, E);
55433
+ let H = S.id || `call_${Date.now()}_${P}`, A = S.function?.name || `tool_${P}`, N = { type: "content_block_start", index: h, content_block: { type: "tool_use", id: H, name: A, input: {} } };
55434
+ f(r.encode(`event: content_block_start
55433
55435
  data: ${JSON.stringify(N)}
55434
55436
 
55435
55437
  `));
55436
- let H = { id: M, name: A, arguments: "", contentBlockIndex: E };
55437
- u.set(P, H);
55438
+ let M = { id: H, name: A, arguments: "", contentBlockIndex: E };
55439
+ p.set(P, M);
55438
55440
  } else if (S.id && S.function?.name) {
55439
- let E = u.get(P);
55441
+ let E = p.get(P);
55440
55442
  E.id.startsWith("call_") && E.name.startsWith("tool_") && (E.id = S.id, E.name = S.function.name);
55441
55443
  }
55442
- if (S.function?.arguments && !i && !a) {
55443
- if (y.get(P) === void 0) continue;
55444
- let M = u.get(P);
55445
- if (M) {
55446
- M.arguments += S.function.arguments;
55444
+ if (S.function?.arguments && !a && !i) {
55445
+ if (_.get(P) === void 0) continue;
55446
+ let H = p.get(P);
55447
+ if (H) {
55448
+ H.arguments += S.function.arguments;
55447
55449
  try {
55448
- let A = null, N = M.arguments.trim();
55450
+ let A = null, N = H.arguments.trim();
55449
55451
  if (N.startsWith("{") && N.endsWith("}")) try {
55450
55452
  A = JSON.parse(N);
55451
- } catch (H) {
55452
- C("Tool call index:", P, "error", H.message);
55453
+ } catch (M) {
55454
+ v("Tool call index:", P, "error", M.message);
55453
55455
  }
55454
55456
  } catch (A) {
55455
- C("Tool call index:", P, "error", A.message);
55457
+ v("Tool call index:", P, "error", A.message);
55456
55458
  }
55457
55459
  }
55458
55460
  try {
55459
55461
  let A = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: S.function.arguments } };
55460
- p(r.encode(`event: content_block_delta
55462
+ f(r.encode(`event: content_block_delta
55461
55463
  data: ${JSON.stringify(A)}
55462
55464
 
55463
55465
  `));
55464
55466
  } catch {
55465
55467
  try {
55466
- let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), H = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: N } };
55467
- p(r.encode(`event: content_block_delta
55468
- data: ${JSON.stringify(H)}
55468
+ let N = S.function.arguments.replace(/[\x00-\x1F\x7F-\x9F]/g, "").replace(/\\/g, "\\\\").replace(/"/g, '\\"'), M = { type: "content_block_delta", index: h, delta: { type: "input_json_delta", partial_json: N } };
55469
+ f(r.encode(`event: content_block_delta
55470
+ data: ${JSON.stringify(M)}
55469
55471
 
55470
55472
  `));
55471
55473
  } catch (N) {
@@ -55475,39 +55477,39 @@ data: ${JSON.stringify(H)}
55475
55477
  }
55476
55478
  }
55477
55479
  }
55478
- if (w?.finish_reason && !i && !a) {
55479
- if (a = true, g === 0 && f === 0 && console.error("Warning: No content in the stream response!"), (c || f > 0) && !i) {
55480
- C("content_block_stop hasTextContentStarted");
55481
- let _ = { type: "content_block_stop", index: h };
55482
- p(r.encode(`event: content_block_stop
55483
- data: ${JSON.stringify(_)}
55480
+ if (w?.finish_reason && !a && !i) {
55481
+ if (i = true, g === 0 && u === 0 && console.error("Warning: No content in the stream response!"), (d || u > 0) && !a) {
55482
+ v("content_block_stop hasTextContentStarted");
55483
+ let k = { type: "content_block_stop", index: h };
55484
+ f(r.encode(`event: content_block_stop
55485
+ data: ${JSON.stringify(k)}
55484
55486
 
55485
55487
  `));
55486
55488
  }
55487
- if (!i) {
55489
+ if (!a) {
55488
55490
  let P = { type: "message_delta", delta: { stop_reason: { stop: "end_turn", length: "max_tokens", tool_calls: "tool_use", content_filter: "stop_sequence" }[w.finish_reason] || "end_turn", stop_sequence: null }, usage: { input_tokens: O.usage?.prompt_tokens || 0, output_tokens: O.usage?.completion_tokens || 0 } };
55489
- p(r.encode(`event: message_delta
55491
+ f(r.encode(`event: message_delta
55490
55492
  data: ${JSON.stringify(P)}
55491
55493
 
55492
55494
  `));
55493
55495
  }
55494
- if (!i) {
55495
- let _ = { type: "message_stop" };
55496
- p(r.encode(`event: message_stop
55497
- data: ${JSON.stringify(_)}
55496
+ if (!a) {
55497
+ let k = { type: "message_stop" };
55498
+ f(r.encode(`event: message_stop
55499
+ data: ${JSON.stringify(k)}
55498
55500
 
55499
55501
  `));
55500
55502
  }
55501
55503
  break;
55502
55504
  }
55503
55505
  } catch (O) {
55504
- C(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${Q}`);
55506
+ v(`parseError: ${O.name} message: ${O.message} stack: ${O.stack} data: ${Q}`);
55505
55507
  }
55506
55508
  }
55507
55509
  }
55508
55510
  m();
55509
55511
  } catch (x) {
55510
- if (!i) try {
55512
+ if (!a) try {
55511
55513
  n.error(x);
55512
55514
  } catch (R) {
55513
55515
  console.error(R);
@@ -55520,26 +55522,26 @@ data: ${JSON.stringify(_)}
55520
55522
  }
55521
55523
  }
55522
55524
  }, cancel(n) {
55523
- C("cancle stream:", n);
55525
+ v("cancle stream:", n);
55524
55526
  } });
55525
55527
  }
55526
55528
  convertOpenAIResponseToAnthropic(e) {
55527
- C("Original OpenAI response:", JSON.stringify(e, null, 2));
55529
+ v("Original OpenAI response:", JSON.stringify(e, null, 2));
55528
55530
  let t = e.choices[0];
55529
55531
  if (!t) throw new Error("No choices found in OpenAI response");
55530
55532
  let n = [];
55531
- t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((o, l) => {
55532
- let d = {};
55533
+ t.message.content && n.push({ type: "text", text: t.message.content }), t.message.tool_calls && t.message.tool_calls.length > 0 && t.message.tool_calls.forEach((o, c) => {
55534
+ let l = {};
55533
55535
  try {
55534
- let c = o.function.arguments || "{}";
55535
- typeof c == "object" ? d = c : typeof c == "string" && (d = JSON.parse(c));
55536
+ let d = o.function.arguments || "{}";
55537
+ typeof d == "object" ? l = d : typeof d == "string" && (l = JSON.parse(d));
55536
55538
  } catch {
55537
- d = { text: o.function.arguments || "" };
55539
+ l = { text: o.function.arguments || "" };
55538
55540
  }
55539
- n.push({ type: "tool_use", id: o.id, name: o.function.name, input: d });
55541
+ n.push({ type: "tool_use", id: o.id, name: o.function.name, input: l });
55540
55542
  });
55541
55543
  let r = { id: e.id, type: "message", role: "assistant", model: e.model, content: n, stop_reason: t.finish_reason === "stop" ? "end_turn" : t.finish_reason === "length" ? "max_tokens" : t.finish_reason === "tool_calls" ? "tool_use" : t.finish_reason === "content_filter" ? "stop_sequence" : "end_turn", stop_sequence: null, usage: { input_tokens: e.usage?.prompt_tokens || 0, output_tokens: e.usage?.completion_tokens || 0 } };
55542
- return C("Conversion complete, final Anthropic response:", JSON.stringify(r, null, 2)), r;
55544
+ return v("Conversion complete, final Anthropic response:", JSON.stringify(r, null, 2)), r;
55543
55545
  }
55544
55546
  };
55545
55547
  function ee(s) {
@@ -55556,25 +55558,26 @@ function ee(s) {
55556
55558
  var J = class {
55557
55559
  name = "gemini";
55558
55560
  endPoint = "/v1beta/models/:modelAndAction";
55559
- transformRequestIn(e, t) {
55561
+ async transformRequestIn(e, t) {
55560
55562
  return { body: { contents: e.messages.map((n) => {
55561
55563
  let r;
55562
55564
  n.role === "assistant" ? r = "model" : (["user", "system", "tool"].includes(n.role), r = "user");
55563
55565
  let o = [];
55564
- return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((l) => {
55565
- if (l.type === "text") return { text: l.text || "" };
55566
- })), Array.isArray(n.tool_calls) && o.push(...n.tool_calls.map((l) => ({ functionCall: { id: l.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: l.function.name, args: JSON.parse(l.function.arguments || "{}") } }))), { role: r, parts: o };
55566
+ return typeof n.content == "string" ? o.push({ text: n.content }) : Array.isArray(n.content) && o.push(...n.content.map((c) => {
55567
+ if (c.type === "text") return { text: c.text || "" };
55568
+ if (c.type === "image_url") return c.image_url.url.startsWith("http") ? { file_data: { mime_type: c.media_type, file_uri: c.image_url.url } } : { inlineData: { mime_type: c.media_type, data: c.image_url.url } };
55569
+ })), Array.isArray(n.tool_calls) && o.push(...n.tool_calls.map((c) => ({ functionCall: { id: c.id || `tool_${Math.random().toString(36).substring(2, 15)}`, name: c.function.name, args: JSON.parse(c.function.arguments || "{}") } }))), { role: r, parts: o };
55567
55570
  }), tools: [{ functionDeclarations: e.tools?.map((n) => (n.function.parameters && ee(n.function.parameters), { name: n.function.name, description: n.function.description, parameters: n.function.parameters })) || [] }] }, config: { url: new URL(`./${e.model}:${e.stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, t.baseUrl), headers: { "x-goog-api-key": t.apiKey, Authorization: void 0 } } };
55568
55571
  }
55569
55572
  transformRequestOut(e) {
55570
- let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens, l = e.temperature, d = e.stream, c = e.tool_choice, a = { messages: [], model: r, max_tokens: o, temperature: l, stream: d, tool_choice: c };
55571
- return Array.isArray(t) && t.forEach((u) => {
55572
- typeof u == "string" ? a.messages.push({ role: "user", content: u }) : typeof u.text == "string" ? a.messages.push({ role: "user", content: u.text || null }) : u.role === "user" ? a.messages.push({ role: "user", content: u?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] }) : u.role === "model" && a.messages.push({ role: "assistant", content: u?.parts?.map((y) => ({ type: "text", text: y.text || "" })) || [] });
55573
- }), Array.isArray(n) && (a.tools = [], n.forEach((u) => {
55574
- Array.isArray(u.functionDeclarations) && u.functionDeclarations.forEach((y) => {
55575
- a.tools.push({ type: "function", function: { name: y.name, description: y.description, parameters: y.parameters } });
55573
+ let t = e.contents, n = e.tools, r = e.model, o = e.max_tokens, c = e.temperature, l = e.stream, d = e.tool_choice, i = { messages: [], model: r, max_tokens: o, temperature: c, stream: l, tool_choice: d };
55574
+ return Array.isArray(t) && t.forEach((p) => {
55575
+ typeof p == "string" ? i.messages.push({ role: "user", content: p }) : typeof p.text == "string" ? i.messages.push({ role: "user", content: p.text || null }) : p.role === "user" ? i.messages.push({ role: "user", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] }) : p.role === "model" && i.messages.push({ role: "assistant", content: p?.parts?.map((_) => ({ type: "text", text: _.text || "" })) || [] });
55576
+ }), Array.isArray(n) && (i.tools = [], n.forEach((p) => {
55577
+ Array.isArray(p.functionDeclarations) && p.functionDeclarations.forEach((_) => {
55578
+ i.tools.push({ type: "function", function: { name: _.name, description: _.description, parameters: _.parameters } });
55576
55579
  });
55577
- })), a;
55580
+ })), i;
55578
55581
  }
55579
55582
  async transformResponseOut(e) {
55580
55583
  if (e.headers.get("Content-Type")?.includes("application/json")) {
@@ -55584,23 +55587,23 @@ var J = class {
55584
55587
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55585
55588
  if (!e.body) return e;
55586
55589
  let t = new TextDecoder(), n = new TextEncoder(), r = new ReadableStream({ async start(o) {
55587
- let l = e.body.getReader();
55590
+ let c = e.body.getReader();
55588
55591
  try {
55589
55592
  for (; ; ) {
55590
- let { done: d, value: c } = await l.read();
55591
- if (d) break;
55592
- let a = t.decode(c, { stream: true });
55593
- if (a.startsWith("data: ")) a = a.slice(6).trim();
55593
+ let { done: l, value: d } = await c.read();
55594
+ if (l) break;
55595
+ let i = t.decode(d, { stream: true });
55596
+ if (i.startsWith("data: ")) i = i.slice(6).trim();
55594
55597
  else break;
55595
- C("gemini chunk:", a), a = JSON.parse(a);
55596
- let u = a.candidates[0].content.parts.filter((k) => k.functionCall).map((k) => ({ id: k.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: k.functionCall?.name, arguments: JSON.stringify(k.functionCall?.args || {}) } })), y = { choices: [{ delta: { role: "assistant", content: a.candidates[0].content.parts.filter((k) => k.text).map((k) => k.text).join(`
55597
- `), tool_calls: u.length > 0 ? u : void 0 }, finish_reason: a.candidates[0].finishReason?.toLowerCase() || null, index: a.candidates[0].index || u.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: a.responseId || "", model: a.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
55598
- C("gemini response:", JSON.stringify(y, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(y)}
55598
+ v("gemini chunk:", i), i = JSON.parse(i);
55599
+ let p = i.candidates[0].content.parts.filter((C) => C.functionCall).map((C) => ({ id: C.functionCall?.id || `tool_${Math.random().toString(36).substring(2, 15)}`, type: "function", function: { name: C.functionCall?.name, arguments: JSON.stringify(C.functionCall?.args || {}) } })), _ = { choices: [{ delta: { role: "assistant", content: i.candidates[0].content.parts.filter((C) => C.text).map((C) => C.text).join(`
55600
+ `), tool_calls: p.length > 0 ? p : void 0 }, finish_reason: i.candidates[0].finishReason?.toLowerCase() || null, index: i.candidates[0].index || p.length > 0 ? 1 : 0, logprobs: null }], created: parseInt((/* @__PURE__ */ new Date()).getTime() / 1e3 + "", 10), id: i.responseId || "", model: i.modelVersion || "", object: "chat.completion.chunk", system_fingerprint: "fp_a49d71b8a1" };
55601
+ v("gemini response:", JSON.stringify(_, null, 2)), o.enqueue(n.encode(`data: ${JSON.stringify(_)}
55599
55602
 
55600
55603
  `));
55601
55604
  }
55602
- } catch (d) {
55603
- o.error(d);
55605
+ } catch (l) {
55606
+ o.error(l);
55604
55607
  } finally {
55605
55608
  o.close();
55606
55609
  }
@@ -55621,61 +55624,61 @@ var j = class {
55621
55624
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55622
55625
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55623
55626
  if (!e.body) return e;
55624
- let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false, l = new ReadableStream({ async start(d) {
55625
- let c = e.body.getReader();
55627
+ let t = new TextDecoder(), n = new TextEncoder(), r = "", o = false, c = new ReadableStream({ async start(l) {
55628
+ let d = e.body.getReader();
55626
55629
  try {
55627
55630
  for (; ; ) {
55628
- let { done: a, value: u } = await c.read();
55629
- if (a) break;
55630
- let k = t.decode(u, { stream: true }).split(`
55631
+ let { done: i, value: p } = await d.read();
55632
+ if (i) break;
55633
+ let C = t.decode(p, { stream: true }).split(`
55631
55634
  `);
55632
- for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55633
- let f = JSON.parse(g.slice(6));
55634
- if (f.choices?.[0]?.delta?.reasoning_content) {
55635
- r += f.choices[0].delta.reasoning_content;
55636
- let i = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, thinking: { content: f.choices[0].delta.reasoning_content } } }] };
55637
- delete i.choices[0].delta.reasoning_content;
55638
- let v = `data: ${JSON.stringify(i)}
55635
+ for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55636
+ let u = JSON.parse(g.slice(6));
55637
+ if (u.choices?.[0]?.delta?.reasoning_content) {
55638
+ r += u.choices[0].delta.reasoning_content;
55639
+ let a = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, thinking: { content: u.choices[0].delta.reasoning_content } } }] };
55640
+ delete a.choices[0].delta.reasoning_content;
55641
+ let y = `data: ${JSON.stringify(a)}
55639
55642
 
55640
55643
  `;
55641
- d.enqueue(n.encode(v));
55644
+ l.enqueue(n.encode(y));
55642
55645
  continue;
55643
55646
  }
55644
- if (f.choices?.[0]?.delta?.content && r && !o) {
55647
+ if (u.choices?.[0]?.delta?.content && r && !o) {
55645
55648
  o = true;
55646
- let i = Date.now().toString(), v = { ...f, choices: [{ ...f.choices[0], delta: { ...f.choices[0].delta, content: null, thinking: { content: r, signature: i } } }] };
55647
- delete v.choices[0].delta.reasoning_content;
55648
- let h = `data: ${JSON.stringify(v)}
55649
+ let a = Date.now().toString(), y = { ...u, choices: [{ ...u.choices[0], delta: { ...u.choices[0].delta, content: null, thinking: { content: r, signature: a } } }] };
55650
+ delete y.choices[0].delta.reasoning_content;
55651
+ let h = `data: ${JSON.stringify(y)}
55649
55652
 
55650
55653
  `;
55651
- d.enqueue(n.encode(h));
55654
+ l.enqueue(n.encode(h));
55652
55655
  }
55653
- if (f.choices[0]?.delta?.reasoning_content && delete f.choices[0].delta.reasoning_content, f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55654
- o && f.choices[0].index++;
55655
- let i = `data: ${JSON.stringify(f)}
55656
+ if (u.choices[0]?.delta?.reasoning_content && delete u.choices[0].delta.reasoning_content, u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
55657
+ o && u.choices[0].index++;
55658
+ let a = `data: ${JSON.stringify(u)}
55656
55659
 
55657
55660
  `;
55658
- d.enqueue(n.encode(i));
55661
+ l.enqueue(n.encode(a));
55659
55662
  }
55660
55663
  } catch {
55661
- d.enqueue(n.encode(g + `
55664
+ l.enqueue(n.encode(g + `
55662
55665
  `));
55663
55666
  }
55664
- else d.enqueue(n.encode(g + `
55667
+ else l.enqueue(n.encode(g + `
55665
55668
  `));
55666
55669
  }
55667
- } catch (a) {
55668
- d.error(a);
55670
+ } catch (i) {
55671
+ l.error(i);
55669
55672
  } finally {
55670
55673
  try {
55671
- c.releaseLock();
55672
- } catch (a) {
55673
- console.error("Error releasing reader lock:", a);
55674
+ d.releaseLock();
55675
+ } catch (i) {
55676
+ console.error("Error releasing reader lock:", i);
55674
55677
  }
55675
- d.close();
55678
+ l.close();
55676
55679
  }
55677
55680
  } });
55678
- 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" } });
55681
+ return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55679
55682
  }
55680
55683
  return e;
55681
55684
  }
@@ -55699,73 +55702,73 @@ Examples:
55699
55702
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55700
55703
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55701
55704
  if (!e.body) return e;
55702
- let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "", l = new ReadableStream({ async start(d) {
55703
- let c = e.body.getReader();
55705
+ let t = new TextDecoder(), n = new TextEncoder(), r = -1, o = "", c = new ReadableStream({ async start(l) {
55706
+ let d = e.body.getReader();
55704
55707
  try {
55705
55708
  for (; ; ) {
55706
- let { done: a, value: u } = await c.read();
55707
- if (a) break;
55708
- let k = t.decode(u, { stream: true }).split(`
55709
+ let { done: i, value: p } = await d.read();
55710
+ if (i) break;
55711
+ let C = t.decode(p, { stream: true }).split(`
55709
55712
  `);
55710
- for (let g of k) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55711
- let f = JSON.parse(g.slice(6));
55712
- if (f.choices[0]?.delta?.tool_calls?.length) {
55713
- let i = f.choices[0].delta.tool_calls[0];
55714
- if (i.function?.name === "ExitTool") {
55715
- r = i.index;
55713
+ for (let g of C) if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") try {
55714
+ let u = JSON.parse(g.slice(6));
55715
+ if (u.choices[0]?.delta?.tool_calls?.length) {
55716
+ let a = u.choices[0].delta.tool_calls[0];
55717
+ if (a.function?.name === "ExitTool") {
55718
+ r = a.index;
55716
55719
  continue;
55717
- } else if (r > -1 && i.index === r && i.function.arguments) {
55718
- o += i.function.arguments;
55720
+ } else if (r > -1 && a.index === r && a.function.arguments) {
55721
+ o += a.function.arguments;
55719
55722
  try {
55720
- let v = JSON.parse(o);
55721
- f.choices = [{ delta: { role: "assistant", content: v.response || "" } }];
55722
- let h = `data: ${JSON.stringify(f)}
55723
+ let y = JSON.parse(o);
55724
+ u.choices = [{ delta: { role: "assistant", content: y.response || "" } }];
55725
+ let h = `data: ${JSON.stringify(u)}
55723
55726
 
55724
55727
  `;
55725
- d.enqueue(n.encode(h));
55728
+ l.enqueue(n.encode(h));
55726
55729
  } catch {
55727
55730
  }
55728
55731
  continue;
55729
55732
  }
55730
55733
  }
55731
- if (f.choices?.[0]?.delta && Object.keys(f.choices[0].delta).length > 0) {
55732
- let i = `data: ${JSON.stringify(f)}
55734
+ if (u.choices?.[0]?.delta && Object.keys(u.choices[0].delta).length > 0) {
55735
+ let a = `data: ${JSON.stringify(u)}
55733
55736
 
55734
55737
  `;
55735
- d.enqueue(n.encode(i));
55738
+ l.enqueue(n.encode(a));
55736
55739
  }
55737
55740
  } catch {
55738
- d.enqueue(n.encode(g + `
55741
+ l.enqueue(n.encode(g + `
55739
55742
  `));
55740
55743
  }
55741
- else d.enqueue(n.encode(g + `
55744
+ else l.enqueue(n.encode(g + `
55742
55745
  `));
55743
55746
  }
55744
- } catch (a) {
55745
- d.error(a);
55747
+ } catch (i) {
55748
+ l.error(i);
55746
55749
  } finally {
55747
55750
  try {
55748
- c.releaseLock();
55749
- } catch (a) {
55750
- console.error("Error releasing reader lock:", a);
55751
+ d.releaseLock();
55752
+ } catch (i) {
55753
+ console.error("Error releasing reader lock:", i);
55751
55754
  }
55752
- d.close();
55755
+ l.close();
55753
55756
  }
55754
55757
  } });
55755
- 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" } });
55758
+ return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55756
55759
  }
55757
55760
  return e;
55758
55761
  }
55759
55762
  };
55760
55763
  var b = [];
55761
55764
  for (let s = 0; s < 256; ++s) b.push((s + 256).toString(16).slice(1));
55762
- function ue(s, e = 0) {
55765
+ function fe(s, e = 0) {
55763
55766
  return (b[s[e + 0]] + b[s[e + 1]] + b[s[e + 2]] + b[s[e + 3]] + "-" + b[s[e + 4]] + b[s[e + 5]] + "-" + b[s[e + 6]] + b[s[e + 7]] + "-" + b[s[e + 8]] + b[s[e + 9]] + "-" + b[s[e + 10]] + b[s[e + 11]] + b[s[e + 12]] + b[s[e + 13]] + b[s[e + 14]] + b[s[e + 15]]).toLowerCase();
55764
55767
  }
55765
- var z = new Uint8Array(256);
55766
- var B = z.length;
55768
+ var W = new Uint8Array(256);
55769
+ var B = W.length;
55767
55770
  function te() {
55768
- return B > z.length - 16 && ((0, import_crypto.randomFillSync)(z), B = 0), z.slice(B, B += 16);
55771
+ return B > W.length - 16 && ((0, import_crypto.randomFillSync)(W), B = 0), W.slice(B, B += 16);
55769
55772
  }
55770
55773
  var ne = { randomUUID: import_crypto2.randomUUID };
55771
55774
  function Re(s, e, t) {
@@ -55778,15 +55781,15 @@ function Re(s, e, t) {
55778
55781
  for (let r = 0; r < 16; ++r) e[t + r] = n[r];
55779
55782
  return e;
55780
55783
  }
55781
- return ue(n);
55784
+ return fe(n);
55782
55785
  }
55783
55786
  var I = Re;
55784
- var V = class {
55787
+ var z = class {
55785
55788
  name = "openrouter";
55786
- transformRequestIn(e) {
55789
+ async transformRequestIn(e) {
55787
55790
  return e.model.includes("claude") || e.messages.forEach((t) => {
55788
55791
  Array.isArray(t.content) ? t.content.forEach((n) => {
55789
- n.cache_control && delete n.cache_control;
55792
+ n.cache_control && delete n.cache_control, n.type === "image_url" && (n.image_url.url.startsWith("http") || (n.image_url.url = `data:${n.media_type};base64,${n.image_url.url}`), delete n.media_type);
55790
55793
  }) : t.cache_control && delete t.cache_control;
55791
55794
  }), e;
55792
55795
  }
@@ -55796,109 +55799,109 @@ var V = class {
55796
55799
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55797
55800
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55798
55801
  if (!e.body) return e;
55799
- let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", l = false, d = false, c = "", a = new ReadableStream({ async start(u) {
55800
- let y = e.body.getReader(), k = (f, i, v) => {
55801
- let h = f.split(`
55802
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = false, d = "", i = new ReadableStream({ async start(p) {
55803
+ let _ = e.body.getReader(), C = (u, a, y) => {
55804
+ let h = u.split(`
55802
55805
  `);
55803
- for (let p of h) p.trim() && i.enqueue(v.encode(p + `
55806
+ for (let f of h) f.trim() && a.enqueue(y.encode(f + `
55804
55807
  `));
55805
- }, g = (f, i) => {
55806
- let { controller: v, encoder: h } = i;
55807
- if (f.startsWith("data: ") && f.trim() !== "data: [DONE]") {
55808
- let p = f.slice(6);
55808
+ }, g = (u, a) => {
55809
+ let { controller: y, encoder: h } = a;
55810
+ if (u.startsWith("data: ") && u.trim() !== "data: [DONE]") {
55811
+ let f = u.slice(6);
55809
55812
  try {
55810
- let m = JSON.parse(p);
55811
- if (m.usage && (C("usage", m.usage, d), m.choices[0].finish_reason = d ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && v.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
55813
+ let m = JSON.parse(f);
55814
+ if (m.usage && (v("usage", m.usage, l), m.choices[0].finish_reason = l ? "tool_calls" : "stop"), m.choices?.[0]?.finish_reason === "error" && y.enqueue(h.encode(`data: ${JSON.stringify({ error: m.choices?.[0].error })}
55812
55815
 
55813
- `)), m.choices?.[0]?.delta?.content && !i.hasTextContent() && i.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
55814
- i.appendReasoningContent(m.choices[0].delta.reasoning);
55816
+ `)), m.choices?.[0]?.delta?.content && !a.hasTextContent() && a.setHasTextContent(true), m.choices?.[0]?.delta?.reasoning) {
55817
+ a.appendReasoningContent(m.choices[0].delta.reasoning);
55815
55818
  let x = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, thinking: { content: m.choices[0].delta.reasoning } } }] };
55816
55819
  x.choices?.[0]?.delta && delete x.choices[0].delta.reasoning;
55817
55820
  let R = `data: ${JSON.stringify(x)}
55818
55821
 
55819
55822
  `;
55820
- v.enqueue(h.encode(R));
55823
+ y.enqueue(h.encode(R));
55821
55824
  return;
55822
55825
  }
55823
- if (m.choices?.[0]?.delta?.content && i.reasoningContent() && !i.isReasoningComplete()) {
55824
- i.setReasoningComplete(true);
55825
- let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: i.reasoningContent(), signature: x } } }] };
55826
+ if (m.choices?.[0]?.delta?.content && a.reasoningContent() && !a.isReasoningComplete()) {
55827
+ a.setReasoningComplete(true);
55828
+ let x = Date.now().toString(), R = { ...m, choices: [{ ...m.choices?.[0], delta: { ...m.choices[0].delta, content: null, thinking: { content: a.reasoningContent(), signature: x } } }] };
55826
55829
  R.choices?.[0]?.delta && delete R.choices[0].delta.reasoning;
55827
55830
  let X = `data: ${JSON.stringify(R)}
55828
55831
 
55829
55832
  `;
55830
- v.enqueue(h.encode(X));
55833
+ y.enqueue(h.encode(X));
55831
55834
  }
55832
55835
  m.choices?.[0]?.delta?.reasoning && delete m.choices[0].delta.reasoning, m.choices?.[0]?.delta?.tool_calls?.length && !Number.isNaN(parseInt(m.choices?.[0]?.delta?.tool_calls[0].id, 10)) && m.choices?.[0]?.delta?.tool_calls.forEach((x) => {
55833
55836
  x.id = `call_${I()}`;
55834
- }), m.choices?.[0]?.delta?.tool_calls?.length && !d && (C("hasToolCall", true), d = true), m.choices?.[0]?.delta?.tool_calls?.length && i.hasTextContent() && (typeof m.choices[0].index == "number" ? m.choices[0].index += 1 : m.choices[0].index = 1);
55837
+ }), m.choices?.[0]?.delta?.tool_calls?.length && !l && (v("hasToolCall", true), l = true), m.choices?.[0]?.delta?.tool_calls?.length && a.hasTextContent() && (typeof m.choices[0].index == "number" ? m.choices[0].index += 1 : m.choices[0].index = 1);
55835
55838
  let T = `data: ${JSON.stringify(m)}
55836
55839
 
55837
55840
  `;
55838
- v.enqueue(h.encode(T));
55841
+ y.enqueue(h.encode(T));
55839
55842
  } catch {
55840
- v.enqueue(h.encode(f + `
55843
+ y.enqueue(h.encode(u + `
55841
55844
  `));
55842
55845
  }
55843
- } else v.enqueue(h.encode(f + `
55846
+ } else y.enqueue(h.encode(u + `
55844
55847
  `));
55845
55848
  };
55846
55849
  try {
55847
55850
  for (; ; ) {
55848
- let { done: f, value: i } = await y.read();
55849
- if (f) {
55850
- c.trim() && k(c, u, n);
55851
+ let { done: u, value: a } = await _.read();
55852
+ if (u) {
55853
+ d.trim() && C(d, p, n);
55851
55854
  break;
55852
55855
  }
55853
- if (!i || i.length === 0) continue;
55854
- let v;
55856
+ if (!a || a.length === 0) continue;
55857
+ let y;
55855
55858
  try {
55856
- v = t.decode(i, { stream: true });
55857
- } catch (p) {
55858
- console.warn("Failed to decode chunk", p);
55859
+ y = t.decode(a, { stream: true });
55860
+ } catch (f) {
55861
+ console.warn("Failed to decode chunk", f);
55859
55862
  continue;
55860
55863
  }
55861
- if (v.length === 0) continue;
55862
- if (c += v, c.length > 1e6) {
55864
+ if (y.length === 0) continue;
55865
+ if (d += y, d.length > 1e6) {
55863
55866
  console.warn("Buffer size exceeds limit, processing partial data");
55864
- let p = c.split(`
55867
+ let f = d.split(`
55865
55868
  `);
55866
- c = p.pop() || "";
55867
- for (let m of p) if (m.trim()) try {
55868
- g(m, { controller: u, encoder: n, hasTextContent: () => r, setHasTextContent: (T) => r = T, reasoningContent: () => o, appendReasoningContent: (T) => o += T, isReasoningComplete: () => l, setReasoningComplete: (T) => l = T });
55869
+ d = f.pop() || "";
55870
+ for (let m of f) if (m.trim()) try {
55871
+ g(m, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (T) => r = T, reasoningContent: () => o, appendReasoningContent: (T) => o += T, isReasoningComplete: () => c, setReasoningComplete: (T) => c = T });
55869
55872
  } catch (T) {
55870
- console.error("Error processing line:", m, T), u.enqueue(n.encode(m + `
55873
+ console.error("Error processing line:", m, T), p.enqueue(n.encode(m + `
55871
55874
  `));
55872
55875
  }
55873
55876
  continue;
55874
55877
  }
55875
- let h = c.split(`
55878
+ let h = d.split(`
55876
55879
  `);
55877
- c = h.pop() || "";
55878
- for (let p of h) if (p.trim()) try {
55879
- g(p, { controller: u, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => l, setReasoningComplete: (m) => l = m });
55880
+ d = h.pop() || "";
55881
+ for (let f of h) if (f.trim()) try {
55882
+ g(f, { controller: p, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
55880
55883
  } catch (m) {
55881
- console.error("Error processing line:", p, m), u.enqueue(n.encode(p + `
55884
+ console.error("Error processing line:", f, m), p.enqueue(n.encode(f + `
55882
55885
  `));
55883
55886
  }
55884
55887
  }
55885
- } catch (f) {
55886
- console.error("Stream error:", f), u.error(f);
55888
+ } catch (u) {
55889
+ console.error("Stream error:", u), p.error(u);
55887
55890
  } finally {
55888
55891
  try {
55889
- y.releaseLock();
55890
- } catch (f) {
55891
- console.error("Error releasing reader lock:", f);
55892
+ _.releaseLock();
55893
+ } catch (u) {
55894
+ console.error("Error releasing reader lock:", u);
55892
55895
  }
55893
- u.close();
55896
+ p.close();
55894
55897
  }
55895
55898
  } });
55896
- return new Response(a, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55899
+ return new Response(i, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
55897
55900
  }
55898
55901
  return e;
55899
55902
  }
55900
55903
  };
55901
- var W = class {
55904
+ var V = class {
55902
55905
  constructor(e) {
55903
55906
  this.options = e;
55904
55907
  this.max_tokens = this.options?.max_tokens;
@@ -55926,84 +55929,84 @@ var G = class {
55926
55929
  return new Response(JSON.stringify(t), { status: e.status, statusText: e.statusText, headers: e.headers });
55927
55930
  } else if (e.headers.get("Content-Type")?.includes("stream")) {
55928
55931
  if (!e.body) return e;
55929
- let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", l = false, d = "", c = new ReadableStream({ async start(a) {
55930
- let u = e.body.getReader(), y = (g, f, i) => {
55931
- let v = g.split(`
55932
+ let t = new TextDecoder(), n = new TextEncoder(), r = false, o = "", c = false, l = "", d = new ReadableStream({ async start(i) {
55933
+ let p = e.body.getReader(), _ = (g, u, a) => {
55934
+ let y = g.split(`
55932
55935
  `);
55933
- for (let h of v) h.trim() && f.enqueue(i.encode(h + `
55936
+ for (let h of y) h.trim() && u.enqueue(a.encode(h + `
55934
55937
  `));
55935
- }, k = (g, f) => {
55936
- let { controller: i, encoder: v } = f;
55938
+ }, C = (g, u) => {
55939
+ let { controller: a, encoder: y } = u;
55937
55940
  if (g.startsWith("data: ") && g.trim() !== "data: [DONE]") {
55938
55941
  let h = g.slice(6);
55939
55942
  try {
55940
- let p = JSON.parse(h);
55941
- if (p.error) throw new Error(JSON.stringify(p));
55942
- p.choices?.[0]?.delta?.content && !f.hasTextContent() && f.setHasTextContent(true), p.choices?.[0]?.delta?.tool_calls?.length && p.choices?.[0]?.delta?.tool_calls.forEach((T) => {
55943
+ let f = JSON.parse(h);
55944
+ if (f.error) throw new Error(JSON.stringify(f));
55945
+ f.choices?.[0]?.delta?.content && !u.hasTextContent() && u.setHasTextContent(true), f.choices?.[0]?.delta?.tool_calls?.length && f.choices?.[0]?.delta?.tool_calls.forEach((T) => {
55943
55946
  T.id = `call_${I()}`;
55944
- }), p.choices?.[0]?.delta?.tool_calls?.length && f.hasTextContent() && (typeof p.choices[0].index == "number" ? p.choices[0].index += 1 : p.choices[0].index = 1);
55945
- let m = `data: ${JSON.stringify(p)}
55947
+ }), f.choices?.[0]?.delta?.tool_calls?.length && u.hasTextContent() && (typeof f.choices[0].index == "number" ? f.choices[0].index += 1 : f.choices[0].index = 1);
55948
+ let m = `data: ${JSON.stringify(f)}
55946
55949
 
55947
55950
  `;
55948
- i.enqueue(v.encode(m));
55951
+ a.enqueue(y.encode(m));
55949
55952
  } catch {
55950
- i.enqueue(v.encode(g + `
55953
+ a.enqueue(y.encode(g + `
55951
55954
  `));
55952
55955
  }
55953
- } else i.enqueue(v.encode(g + `
55956
+ } else a.enqueue(y.encode(g + `
55954
55957
  `));
55955
55958
  };
55956
55959
  try {
55957
55960
  for (; ; ) {
55958
- let { done: g, value: f } = await u.read();
55961
+ let { done: g, value: u } = await p.read();
55959
55962
  if (g) {
55960
- d.trim() && y(d, a, n);
55963
+ l.trim() && _(l, i, n);
55961
55964
  break;
55962
55965
  }
55963
- if (!f || f.length === 0) continue;
55964
- let i;
55966
+ if (!u || u.length === 0) continue;
55967
+ let a;
55965
55968
  try {
55966
- i = t.decode(f, { stream: true });
55969
+ a = t.decode(u, { stream: true });
55967
55970
  } catch (h) {
55968
55971
  console.warn("Failed to decode chunk", h);
55969
55972
  continue;
55970
55973
  }
55971
- if (i.length === 0) continue;
55972
- if (d += i, d.length > 1e6) {
55974
+ if (a.length === 0) continue;
55975
+ if (l += a, l.length > 1e6) {
55973
55976
  console.warn("Buffer size exceeds limit, processing partial data");
55974
- let h = d.split(`
55977
+ let h = l.split(`
55975
55978
  `);
55976
- d = h.pop() || "";
55977
- for (let p of h) if (p.trim()) try {
55978
- k(p, { controller: a, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => l, setReasoningComplete: (m) => l = m });
55979
+ l = h.pop() || "";
55980
+ for (let f of h) if (f.trim()) try {
55981
+ C(f, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (m) => r = m, reasoningContent: () => o, appendReasoningContent: (m) => o += m, isReasoningComplete: () => c, setReasoningComplete: (m) => c = m });
55979
55982
  } catch (m) {
55980
- console.error("Error processing line:", p, m), a.enqueue(n.encode(p + `
55983
+ console.error("Error processing line:", f, m), i.enqueue(n.encode(f + `
55981
55984
  `));
55982
55985
  }
55983
55986
  continue;
55984
55987
  }
55985
- let v = d.split(`
55988
+ let y = l.split(`
55986
55989
  `);
55987
- d = v.pop() || "";
55988
- for (let h of v) if (h.trim()) try {
55989
- k(h, { controller: a, encoder: n, hasTextContent: () => r, setHasTextContent: (p) => r = p, reasoningContent: () => o, appendReasoningContent: (p) => o += p, isReasoningComplete: () => l, setReasoningComplete: (p) => l = p });
55990
- } catch (p) {
55991
- console.error("Error processing line:", h, p), a.enqueue(n.encode(h + `
55990
+ l = y.pop() || "";
55991
+ for (let h of y) if (h.trim()) try {
55992
+ C(h, { controller: i, encoder: n, hasTextContent: () => r, setHasTextContent: (f) => r = f, reasoningContent: () => o, appendReasoningContent: (f) => o += f, isReasoningComplete: () => c, setReasoningComplete: (f) => c = f });
55993
+ } catch (f) {
55994
+ console.error("Error processing line:", h, f), i.enqueue(n.encode(h + `
55992
55995
  `));
55993
55996
  }
55994
55997
  }
55995
55998
  } catch (g) {
55996
- console.error("Stream error:", g), a.error(g);
55999
+ console.error("Stream error:", g), i.error(g);
55997
56000
  } finally {
55998
56001
  try {
55999
- u.releaseLock();
56002
+ p.releaseLock();
56000
56003
  } catch (g) {
56001
56004
  console.error("Error releasing reader lock:", g);
56002
56005
  }
56003
- a.close();
56006
+ i.close();
56004
56007
  }
56005
56008
  } });
56006
- return new Response(c, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
56009
+ return new Response(d, { status: e.status, statusText: e.statusText, headers: { "Content-Type": e.headers.get("Content-Type") || "text/plain", "Cache-Control": "no-cache", Connection: "keep-alive" } });
56007
56010
  }
56008
56011
  return e;
56009
56012
  }
@@ -56018,14 +56021,14 @@ var K = class {
56018
56021
  }), e;
56019
56022
  }
56020
56023
  };
56021
- var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer: V, MaxTokenTransformer: W, GroqTransformer: G, CleancacheTransformer: K };
56024
+ var pe = { AnthropicTransformer: U, GeminiTransformer: J, DeepseekTransformer: j, TooluseTransformer: D, OpenrouterTransformer: z, MaxTokenTransformer: V, GroqTransformer: G, CleancacheTransformer: K };
56022
56025
  var Y = class {
56023
56026
  constructor(e) {
56024
56027
  this.configService = e;
56025
56028
  }
56026
56029
  transformers = /* @__PURE__ */ new Map();
56027
56030
  registerTransformer(e, t) {
56028
- this.transformers.set(e, t), C(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
56031
+ this.transformers.set(e, t), v(`register transformer: ${e}${t.endPoint ? ` (endpoint: ${t.endPoint})` : " (no endpoint)"}`);
56029
56032
  }
56030
56033
  getTransformer(e) {
56031
56034
  return this.transformers.get(e);
@@ -56055,7 +56058,7 @@ var Y = class {
56055
56058
  try {
56056
56059
  let t = import_node_module.default._load;
56057
56060
  if (import_node_module.default._load = function(n, r, o) {
56058
- return n === "claude-code-router" ? { log: C } : t.apply(import_node_module.default, arguments);
56061
+ return n === "claude-code-router" ? { log: v } : t.apply(import_node_module.default, arguments);
56059
56062
  }, e.path) {
56060
56063
  let n = Z(Z.resolve(e.path));
56061
56064
  if (n) {
@@ -56066,14 +56069,14 @@ var Y = class {
56066
56069
  }
56067
56070
  return false;
56068
56071
  } catch (t) {
56069
- return C(`load transformer (${e.path}) error:`, t.message, t.stack), false;
56072
+ return v(`load transformer (${e.path}) error:`, t.message, t.stack), false;
56070
56073
  }
56071
56074
  }
56072
56075
  async initialize() {
56073
56076
  try {
56074
56077
  await this.registerDefaultTransformersInternal(), await this.loadFromConfig();
56075
56078
  } catch (e) {
56076
- C("TransformerService init error:", e);
56079
+ v("TransformerService init error:", e);
56077
56080
  }
56078
56081
  }
56079
56082
  async registerDefaultTransformersInternal() {
@@ -56086,7 +56089,7 @@ var Y = class {
56086
56089
  }
56087
56090
  });
56088
56091
  } catch (e) {
56089
- C("transformer regist error:", e);
56092
+ v("transformer regist error:", e);
56090
56093
  }
56091
56094
  }
56092
56095
  async loadFromConfig() {
@@ -56095,7 +56098,7 @@ var Y = class {
56095
56098
  }
56096
56099
  };
56097
56100
  function Se() {
56098
- let s = (0, import_fastify.default)({});
56101
+ let s = (0, import_fastify.default)({ bodyLimit: 52428800 });
56099
56102
  return s.setErrorHandler(le), s.register(import_cors.default), s;
56100
56103
  }
56101
56104
  var re = class {
@@ -56121,21 +56124,21 @@ var re = class {
56121
56124
  try {
56122
56125
  let o = n.body;
56123
56126
  if (!o || !o.model) return r.code(400).send({ error: "Missing model in request body" });
56124
- let [l, d] = o.model.split(",");
56125
- o.model = d, n.provider = l;
56127
+ let [c, l] = o.model.split(",");
56128
+ o.model = l, n.provider = c;
56126
56129
  return;
56127
56130
  } catch (o) {
56128
56131
  return n.log.error("Error in modelProviderMiddleware:", o), r.code(500).send({ error: "Internal server error" });
56129
56132
  }
56130
- }), this.app.register(fe);
56133
+ }), this.app.register(ue);
56131
56134
  let e = await this.app.listen({ port: parseInt(this.configService.get("PORT") || "3000", 10), host: this.configService.get("HOST") || "127.0.0.1" });
56132
- C(`\u{1F680} LLMs API server listening on ${e}`);
56135
+ v(`\u{1F680} LLMs API server listening on ${e}`);
56133
56136
  let t = async (n) => {
56134
- C(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
56137
+ v(`Received ${n}, shutting down gracefully...`), await this.app.close(), process.exit(0);
56135
56138
  };
56136
56139
  process.on("SIGINT", () => t("SIGINT")), process.on("SIGTERM", () => t("SIGTERM"));
56137
56140
  } catch (e) {
56138
- C(`Error starting server: ${e}`), process.exit(1);
56141
+ v(`Error starting server: ${e}`), process.exit(1);
56139
56142
  }
56140
56143
  }
56141
56144
  };
@@ -56335,14 +56338,15 @@ function getServicePid() {
56335
56338
  return null;
56336
56339
  }
56337
56340
  }
56338
- function getServiceInfo() {
56341
+ async function getServiceInfo() {
56339
56342
  const pid = getServicePid();
56340
56343
  const running = isServiceRunning();
56344
+ const config = await readConfigFile();
56341
56345
  return {
56342
56346
  running,
56343
56347
  pid,
56344
- port: 3456,
56345
- endpoint: "http://127.0.0.1:3456",
56348
+ port: config.PORT,
56349
+ endpoint: `http://127.0.0.1:${config.PORT}`,
56346
56350
  pidFile: PID_FILE,
56347
56351
  referenceCount: getReferenceCount()
56348
56352
  };
@@ -56383,7 +56387,7 @@ async function run(options = {}) {
56383
56387
  "\u26A0\uFE0F API key is not set. HOST is forced to 127.0.0.1."
56384
56388
  );
56385
56389
  }
56386
- const port = options.port || 3456;
56390
+ const port = config.PORT || 3456;
56387
56391
  savePid(process.pid);
56388
56392
  process.on("SIGINT", () => {
56389
56393
  console.log("Received SIGINT, cleaning up...");
@@ -56419,8 +56423,8 @@ async function run(options = {}) {
56419
56423
  }
56420
56424
 
56421
56425
  // src/utils/status.ts
56422
- function showStatus() {
56423
- const info = getServiceInfo();
56426
+ async function showStatus() {
56427
+ const info = await getServiceInfo();
56424
56428
  console.log("\n\u{1F4CA} Claude Code Router Status");
56425
56429
  console.log("\u2550".repeat(40));
56426
56430
  if (info.running) {
@@ -56474,7 +56478,7 @@ async function executeCodeCommand(args = []) {
56474
56478
  const env = {
56475
56479
  ...process.env,
56476
56480
  ANTHROPIC_AUTH_TOKEN: "test",
56477
- ANTHROPIC_BASE_URL: `http://127.0.0.1:3456`,
56481
+ ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.PORT || 3456}`,
56478
56482
  API_TIMEOUT_MS: "600000"
56479
56483
  };
56480
56484
  if (config?.APIKEY) {
@@ -56504,7 +56508,7 @@ async function executeCodeCommand(args = []) {
56504
56508
  }
56505
56509
 
56506
56510
  // package.json
56507
- var version = "1.0.21";
56511
+ var version = "1.0.22";
56508
56512
 
56509
56513
  // src/cli.ts
56510
56514
  var import_child_process2 = require("child_process");
@@ -56565,7 +56569,7 @@ async function main() {
56565
56569
  }
56566
56570
  break;
56567
56571
  case "status":
56568
- showStatus();
56572
+ await showStatus();
56569
56573
  break;
56570
56574
  case "code":
56571
56575
  if (!isServiceRunning()) {