@musistudio/claude-code-router 1.0.15 → 1.0.17

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 +9 -2
  2. package/dist/cli.js +39 -37
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -239,6 +239,13 @@ Thanks to the following sponsors for supporting the continued development of thi
239
239
  @\*更 (可通过主页邮箱联系我修改 github 用户名)
240
240
  @K\*g (可通过主页邮箱联系我修改 github 用户名)
241
241
  @R\*R (可通过主页邮箱联系我修改 github 用户名)
242
- @[@bobleer](https://github.com/bobleer) (可通过主页邮箱联系我修改 github 用户名)
242
+ [@bobleer](https://github.com/bobleer)
243
243
  @\*苗 (可通过主页邮箱联系我修改 github 用户名)
244
- @\*划 (可通过主页邮箱联系我修改 github 用户名)
244
+ @\*划 (可通过主页邮箱联系我修改 github 用户名)
245
+ [@Clarence-pan](https://github.com/Clarence-pan)
246
+ [@carter003](https://github.com/carter003)
247
+ @S\*r (可通过主页邮箱联系我修改 github 用户名)
248
+ @\*晖 (可通过主页邮箱联系我修改 github 用户名)
249
+ @\*敏 (可通过主页邮箱联系我修改 github 用户名)
250
+ @Z\*z (可通过主页邮箱联系我修改 github 用户名)
251
+ @\*然 (可通过主页邮箱联系我修改 github 用户名)
package/dist/cli.js CHANGED
@@ -5263,7 +5263,7 @@ var require_thread_stream = __commonJS({
5263
5263
  var { version: version2 } = require_package();
5264
5264
  var { EventEmitter } = require("events");
5265
5265
  var { Worker } = require("worker_threads");
5266
- var { join: join3 } = require("path");
5266
+ var { join: join4 } = require("path");
5267
5267
  var { pathToFileURL } = require("url");
5268
5268
  var { wait } = require_wait();
5269
5269
  var {
@@ -5299,7 +5299,7 @@ var require_thread_stream = __commonJS({
5299
5299
  function createWorker(stream, opts) {
5300
5300
  const { filename, workerData } = opts;
5301
5301
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
5302
- const toExecute = bundlerOverrides["thread-stream-worker"] || join3(__dirname, "lib", "worker.js");
5302
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join4(__dirname, "lib", "worker.js");
5303
5303
  const worker = new Worker(toExecute, {
5304
5304
  ...opts.workerOpts,
5305
5305
  trackUnmanagedFds: false,
@@ -5685,7 +5685,7 @@ var require_transport = __commonJS({
5685
5685
  "use strict";
5686
5686
  var { createRequire } = require("module");
5687
5687
  var getCallers = require_caller();
5688
- var { join: join3, isAbsolute, sep } = require("node:path");
5688
+ var { join: join4, isAbsolute, sep } = require("node:path");
5689
5689
  var sleep = require_atomic_sleep();
5690
5690
  var onExit = require_on_exit_leak_free();
5691
5691
  var ThreadStream = require_thread_stream();
@@ -5748,7 +5748,7 @@ var require_transport = __commonJS({
5748
5748
  throw new Error("only one of target or targets can be specified");
5749
5749
  }
5750
5750
  if (targets) {
5751
- target = bundlerOverrides["pino-worker"] || join3(__dirname, "worker.js");
5751
+ target = bundlerOverrides["pino-worker"] || join4(__dirname, "worker.js");
5752
5752
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
5753
5753
  return {
5754
5754
  ...dest,
@@ -5766,7 +5766,7 @@ var require_transport = __commonJS({
5766
5766
  });
5767
5767
  });
5768
5768
  } else if (pipeline) {
5769
- target = bundlerOverrides["pino-worker"] || join3(__dirname, "worker.js");
5769
+ target = bundlerOverrides["pino-worker"] || join4(__dirname, "worker.js");
5770
5770
  options.pipelines = [pipeline.map((dest) => {
5771
5771
  return {
5772
5772
  ...dest,
@@ -5788,7 +5788,7 @@ var require_transport = __commonJS({
5788
5788
  return origin;
5789
5789
  }
5790
5790
  if (origin === "pino/file") {
5791
- return join3(__dirname, "..", "file.js");
5791
+ return join4(__dirname, "..", "file.js");
5792
5792
  }
5793
5793
  let fixTarget2;
5794
5794
  for (const filePath of callers) {
@@ -6739,7 +6739,7 @@ var require_safe_stable_stringify = __commonJS({
6739
6739
  return circularValue;
6740
6740
  }
6741
6741
  let res = "";
6742
- let join3 = ",";
6742
+ let join4 = ",";
6743
6743
  const originalIndentation = indentation;
6744
6744
  if (Array.isArray(value)) {
6745
6745
  if (value.length === 0) {
@@ -6753,7 +6753,7 @@ var require_safe_stable_stringify = __commonJS({
6753
6753
  indentation += spacer;
6754
6754
  res += `
6755
6755
  ${indentation}`;
6756
- join3 = `,
6756
+ join4 = `,
6757
6757
  ${indentation}`;
6758
6758
  }
6759
6759
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -6761,13 +6761,13 @@ ${indentation}`;
6761
6761
  for (; i < maximumValuesToStringify - 1; i++) {
6762
6762
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
6763
6763
  res += tmp2 !== void 0 ? tmp2 : "null";
6764
- res += join3;
6764
+ res += join4;
6765
6765
  }
6766
6766
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
6767
6767
  res += tmp !== void 0 ? tmp : "null";
6768
6768
  if (value.length - 1 > maximumBreadth) {
6769
6769
  const removedKeys = value.length - maximumBreadth - 1;
6770
- res += `${join3}"... ${getItemCount(removedKeys)} not stringified"`;
6770
+ res += `${join4}"... ${getItemCount(removedKeys)} not stringified"`;
6771
6771
  }
6772
6772
  if (spacer !== "") {
6773
6773
  res += `
@@ -6788,7 +6788,7 @@ ${originalIndentation}`;
6788
6788
  let separator = "";
6789
6789
  if (spacer !== "") {
6790
6790
  indentation += spacer;
6791
- join3 = `,
6791
+ join4 = `,
6792
6792
  ${indentation}`;
6793
6793
  whitespace = " ";
6794
6794
  }
@@ -6802,13 +6802,13 @@ ${indentation}`;
6802
6802
  const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
6803
6803
  if (tmp !== void 0) {
6804
6804
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
6805
- separator = join3;
6805
+ separator = join4;
6806
6806
  }
6807
6807
  }
6808
6808
  if (keyLength > maximumBreadth) {
6809
6809
  const removedKeys = keyLength - maximumBreadth;
6810
6810
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
6811
- separator = join3;
6811
+ separator = join4;
6812
6812
  }
6813
6813
  if (spacer !== "" && separator.length > 1) {
6814
6814
  res = `
@@ -6849,7 +6849,7 @@ ${originalIndentation}`;
6849
6849
  }
6850
6850
  const originalIndentation = indentation;
6851
6851
  let res = "";
6852
- let join3 = ",";
6852
+ let join4 = ",";
6853
6853
  if (Array.isArray(value)) {
6854
6854
  if (value.length === 0) {
6855
6855
  return "[]";
@@ -6862,7 +6862,7 @@ ${originalIndentation}`;
6862
6862
  indentation += spacer;
6863
6863
  res += `
6864
6864
  ${indentation}`;
6865
- join3 = `,
6865
+ join4 = `,
6866
6866
  ${indentation}`;
6867
6867
  }
6868
6868
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -6870,13 +6870,13 @@ ${indentation}`;
6870
6870
  for (; i < maximumValuesToStringify - 1; i++) {
6871
6871
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
6872
6872
  res += tmp2 !== void 0 ? tmp2 : "null";
6873
- res += join3;
6873
+ res += join4;
6874
6874
  }
6875
6875
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
6876
6876
  res += tmp !== void 0 ? tmp : "null";
6877
6877
  if (value.length - 1 > maximumBreadth) {
6878
6878
  const removedKeys = value.length - maximumBreadth - 1;
6879
- res += `${join3}"... ${getItemCount(removedKeys)} not stringified"`;
6879
+ res += `${join4}"... ${getItemCount(removedKeys)} not stringified"`;
6880
6880
  }
6881
6881
  if (spacer !== "") {
6882
6882
  res += `
@@ -6889,7 +6889,7 @@ ${originalIndentation}`;
6889
6889
  let whitespace = "";
6890
6890
  if (spacer !== "") {
6891
6891
  indentation += spacer;
6892
- join3 = `,
6892
+ join4 = `,
6893
6893
  ${indentation}`;
6894
6894
  whitespace = " ";
6895
6895
  }
@@ -6898,7 +6898,7 @@ ${indentation}`;
6898
6898
  const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
6899
6899
  if (tmp !== void 0) {
6900
6900
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
6901
- separator = join3;
6901
+ separator = join4;
6902
6902
  }
6903
6903
  }
6904
6904
  if (spacer !== "" && separator.length > 1) {
@@ -6956,20 +6956,20 @@ ${originalIndentation}`;
6956
6956
  indentation += spacer;
6957
6957
  let res2 = `
6958
6958
  ${indentation}`;
6959
- const join4 = `,
6959
+ const join5 = `,
6960
6960
  ${indentation}`;
6961
6961
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
6962
6962
  let i = 0;
6963
6963
  for (; i < maximumValuesToStringify - 1; i++) {
6964
6964
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
6965
6965
  res2 += tmp2 !== void 0 ? tmp2 : "null";
6966
- res2 += join4;
6966
+ res2 += join5;
6967
6967
  }
6968
6968
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
6969
6969
  res2 += tmp !== void 0 ? tmp : "null";
6970
6970
  if (value.length - 1 > maximumBreadth) {
6971
6971
  const removedKeys = value.length - maximumBreadth - 1;
6972
- res2 += `${join4}"... ${getItemCount(removedKeys)} not stringified"`;
6972
+ res2 += `${join5}"... ${getItemCount(removedKeys)} not stringified"`;
6973
6973
  }
6974
6974
  res2 += `
6975
6975
  ${originalIndentation}`;
@@ -6985,16 +6985,16 @@ ${originalIndentation}`;
6985
6985
  return '"[Object]"';
6986
6986
  }
6987
6987
  indentation += spacer;
6988
- const join3 = `,
6988
+ const join4 = `,
6989
6989
  ${indentation}`;
6990
6990
  let res = "";
6991
6991
  let separator = "";
6992
6992
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
6993
6993
  if (isTypedArrayWithEntries(value)) {
6994
- res += stringifyTypedArray(value, join3, maximumBreadth);
6994
+ res += stringifyTypedArray(value, join4, maximumBreadth);
6995
6995
  keys = keys.slice(value.length);
6996
6996
  maximumPropertiesToStringify -= value.length;
6997
- separator = join3;
6997
+ separator = join4;
6998
6998
  }
6999
6999
  if (deterministic) {
7000
7000
  keys = sort(keys, comparator);
@@ -7005,13 +7005,13 @@ ${indentation}`;
7005
7005
  const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
7006
7006
  if (tmp !== void 0) {
7007
7007
  res += `${separator}${strEscape(key2)}: ${tmp}`;
7008
- separator = join3;
7008
+ separator = join4;
7009
7009
  }
7010
7010
  }
7011
7011
  if (keyLength > maximumBreadth) {
7012
7012
  const removedKeys = keyLength - maximumBreadth;
7013
7013
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
7014
- separator = join3;
7014
+ separator = join4;
7015
7015
  }
7016
7016
  if (separator !== "") {
7017
7017
  res = `
@@ -54884,10 +54884,10 @@ var import_node_readline = __toESM(require("node:readline"));
54884
54884
  var import_node_path = __toESM(require("node:path"));
54885
54885
  var import_node_os = __toESM(require("node:os"));
54886
54886
  var HOME_DIR = import_node_path.default.join(import_node_os.default.homedir(), ".claude-code-router");
54887
- var CONFIG_FILE = `${HOME_DIR}/config.json`;
54888
- var PLUGINS_DIR = `${HOME_DIR}/plugins`;
54887
+ var CONFIG_FILE = import_node_path.default.join(HOME_DIR, "config.json");
54888
+ var PLUGINS_DIR = import_node_path.default.join(HOME_DIR, "plugins");
54889
54889
  var PID_FILE = import_node_path.default.join(HOME_DIR, ".claude-code-router.pid");
54890
- var REFERENCE_COUNT_FILE = "/tmp/claude-code-reference-count.txt";
54890
+ var REFERENCE_COUNT_FILE = import_node_path.default.join(import_node_os.default.tmpdir(), "claude-code-reference-count.txt");
54891
54891
  var DEFAULT_CONFIG = {
54892
54892
  LOG: false,
54893
54893
  OPENAI_API_KEY: "",
@@ -55951,15 +55951,15 @@ var getUseModel = (req, tokenCount, config) => {
55951
55951
  if (req.body.model.includes(",")) {
55952
55952
  return req.body.model;
55953
55953
  }
55954
- if (tokenCount > 1e3 * 60) {
55954
+ if (tokenCount > 1e3 * 60 && config.Router.longContext) {
55955
55955
  log("Using long context model due to token count:", tokenCount);
55956
55956
  return config.Router.longContext;
55957
55957
  }
55958
- if (req.body.model?.startsWith("claude-3-5-haiku")) {
55958
+ if (req.body.model?.startsWith("claude-3-5-haiku") && config.Router.background) {
55959
55959
  log("Using background model for ", req.body.model);
55960
55960
  return config.Router.background;
55961
55961
  }
55962
- if (req.body.thinking) {
55962
+ if (req.body.thinking && config.Router.think) {
55963
55963
  log("Using think model for ", req.body.thinking);
55964
55964
  return config.Router.think;
55965
55965
  }
@@ -56098,8 +56098,8 @@ function getServiceInfo() {
56098
56098
 
56099
56099
  // src/index.ts
56100
56100
  async function initializeClaudeConfig() {
56101
- const homeDir = process.env.HOME;
56102
- const configPath = `${homeDir}/.claude.json`;
56101
+ const homeDir = (0, import_os.homedir)();
56102
+ const configPath = (0, import_path2.join)(homeDir, ".claude.json");
56103
56103
  if (!(0, import_fs3.existsSync)(configPath)) {
56104
56104
  const userID = Array.from(
56105
56105
  { length: 64 },
@@ -56237,11 +56237,12 @@ async function executeCodeCommand(args = []) {
56237
56237
  }
56238
56238
 
56239
56239
  // package.json
56240
- var version = "1.0.15";
56240
+ var version = "1.0.17";
56241
56241
 
56242
56242
  // src/cli.ts
56243
56243
  var import_child_process2 = require("child_process");
56244
56244
  var import_fs5 = require("fs");
56245
+ var import_path4 = require("path");
56245
56246
  var command = process.argv[2];
56246
56247
  var HELP_TEXT = `
56247
56248
  Usage: ccr [command]
@@ -56302,7 +56303,8 @@ async function main() {
56302
56303
  case "code":
56303
56304
  if (!isServiceRunning()) {
56304
56305
  console.log("Service not running, starting service...");
56305
- const startProcess = (0, import_child_process2.spawn)("ccr", ["start"], {
56306
+ const cliPath = (0, import_path4.join)(__dirname, "cli.js");
56307
+ const startProcess = (0, import_child_process2.spawn)("node", [cliPath, "start"], {
56306
56308
  detached: true,
56307
56309
  stdio: "ignore"
56308
56310
  });
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@musistudio/claude-code-router",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Use Claude Code without an Anthropics account and route it to another LLM provider",
5
5
  "bin": {
6
6
  "ccr": "./dist/cli.js"
7
7
  },
8
8
  "scripts": {
9
- "build": "esbuild src/cli.ts --bundle --platform=node --outfile=dist/cli.js && cp node_modules/tiktoken/tiktoken_bg.wasm dist/tiktoken_bg.wasm"
9
+ "build": "esbuild src/cli.ts --bundle --platform=node --outfile=dist/cli.js && shx cp node_modules/tiktoken/tiktoken_bg.wasm dist/tiktoken_bg.wasm"
10
10
  },
11
11
  "keywords": [
12
12
  "claude",
@@ -18,13 +18,14 @@
18
18
  "author": "musistudio",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@musistudio/llms": "^1.0.4",
21
+ "@musistudio/llms": "^1.0.5",
22
22
  "dotenv": "^16.4.7",
23
23
  "tiktoken": "^1.0.21",
24
24
  "uuid": "^11.1.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "esbuild": "^0.25.1",
28
+ "shx": "^0.4.0",
28
29
  "typescript": "^5.8.2"
29
30
  },
30
31
  "publishConfig": {