@dedenlabs/claude-code-router-cli 2.0.3 → 2.0.5

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Claude Code Router CLI v2.0
1
+ # Claude Code Router CLI v2.0.5
2
2
 
3
3
  <div align="center">
4
4
 
5
- [![Version](https://img.shields.io/badge/version-2.0.3-blue.svg)](https://github.com/dedenlabs/claude-code-router-cli)
5
+ [![Version](https://img.shields.io/badge/version-2.0.5-blue.svg)](https://github.com/dedenlabs/claude-code-router-cli)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
7
  [![Node](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen.svg)](https://nodejs.org/)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
@@ -72,6 +72,18 @@ Respond with the title for the conversation and nothing else.
72
72
  ### 🔄 配置自动迁移 (Auto Migration)
73
73
  一键从旧版本配置迁移到新的统一路由格式
74
74
 
75
+ **一行代码即可完成迁移:**
76
+ ```bash
77
+ ccr migrate
78
+ ```
79
+
80
+ 迁移工具会自动:
81
+ - ✅ 备份现有配置到 `~/.claude-code-router/config.backup.json`
82
+ - ✅ 转换为统一路由引擎格式
83
+ - ✅ 保留所有原有路由逻辑
84
+ - ✅ 生成详细迁移报告
85
+
86
+
75
87
  ### 🎛️ GLM思考模式 (GLM Thinking)
76
88
  内置GLM模型思考转换器,提升推理质量
77
89
 
@@ -179,24 +191,66 @@ ccr stop # 停止服务
179
191
  }
180
192
  }
181
193
  ```
194
+ #### 🌐 可视化配置界面
195
+ 提供直观的 Web UI 界面,方便配置路由规则和监控服务状态
196
+
197
+ **访问地址:** http://localhost:3456/ui/
198
+
199
+ ![可视化配置界面](examples/image/README/1765879508612.png)
182
200
 
183
- ### 🔌 外部规则支持
201
+ **功能特性:**
202
+ - ✅ 可视化路由规则管理
203
+ - ✅ 实时服务状态监控
204
+ - ✅ 交互式配置编辑器
205
+ - ✅ 模型使用统计展示
184
206
 
185
- 通过外部JavaScript文件定义复杂路由逻辑:
207
+ ### 🔌 外部规则支持 (示例)
186
208
 
209
+ 通过外部JavaScript文件定义复杂路由逻辑,支持:
210
+
211
+ **1. 调试日志收集** 📊
187
212
  ```javascript
188
- // external-rules/user-preference.js
189
- const userPreferences = {
190
- 'premium@company.com': { provider: 'opus', model: 'glm-4.6' },
191
- 'standard@company.com': { provider: 'sonnet', model: 'glm-4.5-air' }
192
- };
213
+ // examples/external-rules/debug-logger.js
214
+ function printModelRequestData(context) {
215
+ // 变量式日志收集,每种类型单独存储
216
+ const outputTypes = ['basic', 'messages', 'tools', 'usage'];
193
217
 
194
- function checkUserPreference(context) {
195
- const userEmail = extractUserEmail(context);
196
- return userPreferences[userEmail] !== undefined;
218
+ // 收集基本信息
219
+ let basicInfo = `Token数量: ${context.tokenCount}`;
220
+
221
+ // 收集消息内容
222
+ let messages = '';
223
+ context.messages.forEach(msg => {
224
+ messages += `${msg.role}: ${msg.content.substring(0, 100)}...`;
225
+ });
226
+
227
+ // 选择性输出到控制台和文件
228
+ console.log(`[调试] ${basicInfo}\n${messages}`);
229
+
230
+ return false; // 不拦截路由
197
231
  }
198
232
 
199
- module.exports = { checkUserPreference };
233
+ module.exports = printModelRequestData;
234
+ ```
235
+
236
+ 详细使用说明请参考:[🔍 调试日志脚本使用指南](./examples/README-调试日志脚本.md)
237
+
238
+ **2. 用户偏好路由** 👤
239
+ ```javascript
240
+ // 根据用户邮箱路由到偏好模型
241
+ function checkUserPreference(context) {
242
+ const userId = extractUserId(context); //context.body.metadata.user_id
243
+ return userPreferences[userId] !== undefined;
244
+ }
245
+ ```
246
+
247
+ **3. 时间路由** ⏰
248
+ ```javascript
249
+ // 根据工作时间路由到不同模型
250
+ function isBusinessHours(context) {
251
+ const hour = new Date().getHours();
252
+ return hour >= 9 && hour < 18;
253
+ }
200
254
  ```
201
255
 
202
256
  ### 📊 智能日志输出
@@ -569,6 +623,36 @@ export class MyTransformer extends BaseTransformer {
569
623
 
570
624
  ## 📈 版本历史
571
625
 
626
+ ### v2.0.5 (2025-12-21)
627
+
628
+ **🔧 UI修复版本**
629
+
630
+ **✅ 静态文件服务修复**
631
+ - 修复UI无法加载显示的问题
632
+ - 将静态文件服务目录从原来路径改为 `dist` 目录
633
+ - 确保Web UI界面正常访问和显示
634
+ - 优化构建流程,确保UI文件正确输出
635
+
636
+ ### v2.0.4 (2025-12-17)
637
+
638
+ **🚀 性能优化与功能增强**
639
+
640
+ **⚡ 外部函数加载机制优化**
641
+ - 优化外部函数加载优先级:配置指定方法名 → 默认导出 → evaluate函数
642
+ - 提升统一路由引擎的性能和响应速度
643
+ - 改进错误处理和调试日志输出
644
+ - 增强变量替换功能的稳定性
645
+
646
+ **🔧 调试工具完善**
647
+ - 完善调试日志脚本,支持变量收集和选择性输出
648
+ - 新增文件输出和深度拷贝功能
649
+ - 添加调试日志配置示例文件
650
+
651
+ **📚 文档与示例更新**
652
+ - 完善README.md和外部规则文档
653
+ - 新增路由目标输入组件演示文档
654
+ - 更新外部规则使用示例和说明
655
+
572
656
  ### v2.0.3 (2025-12-16)
573
657
 
574
658
  **🔧 核心问题修复**
package/dist/cli.js CHANGED
@@ -67706,7 +67706,7 @@ var require_package3 = __commonJS({
67706
67706
  "package.json"(exports2, module2) {
67707
67707
  module2.exports = {
67708
67708
  name: "@dedenlabs/claude-code-router-cli",
67709
- version: "2.0.3",
67709
+ version: "2.0.4",
67710
67710
  description: "\u57FA\u4E8E@musistudio/claude-code-router\u7684\u589E\u5F3A\u7248CLI\u8DEF\u7531\u5DE5\u5177 - \u652F\u6301\u7EDF\u4E00\u8DEF\u7531\u5F15\u64CE\u3001\u5916\u90E8\u89C4\u5219\u52A0\u8F7D\u3001\u667A\u80FD\u65E5\u5FD7\u7CFB\u7EDF\u3001\u81EA\u52A8\u914D\u7F6E\u8FC1\u79FB\u548CGLM\u601D\u8003\u6A21\u5F0F",
67711
67711
  bin: {
67712
67712
  ccr: "dist/cli.js"
@@ -85069,7 +85069,17 @@ ${allLines[totalLines - 1] || ""}`
85069
85069
  }
85070
85070
  try {
85071
85071
  const externalModule = await import(condition.externalFunction.path);
85072
- const conditionFunction = externalModule.default || externalModule[condition.externalFunction.functionName || "evaluate"];
85072
+ const functionName = condition.externalFunction.functionName;
85073
+ let conditionFunction;
85074
+ if (functionName && externalModule[functionName]) {
85075
+ conditionFunction = externalModule[functionName];
85076
+ } else if (externalModule.default) {
85077
+ conditionFunction = externalModule.default;
85078
+ } else if (externalModule["evaluate"]) {
85079
+ conditionFunction = externalModule["evaluate"];
85080
+ } else {
85081
+ conditionFunction = void 0;
85082
+ }
85073
85083
  if (typeof conditionFunction !== "function") {
85074
85084
  this.logger.error(
85075
85085
  `\u5916\u90E8\u51FD\u6570 ${condition.externalFunction.path} \u4E0D\u662F\u4E00\u4E2A\u6709\u6548\u7684\u51FD\u6570`
@@ -85904,7 +85914,7 @@ var createServer = (config) => {
85904
85914
  }, 1e3);
85905
85915
  });
85906
85916
  server.app.register(import_static.default, {
85907
- root: (0, import_path3.join)(__dirname, "..", "ui", "dist"),
85917
+ root: (0, import_path3.join)(__dirname, "..", "dist"),
85908
85918
  prefix: "/ui/",
85909
85919
  maxAge: "1h"
85910
85920
  });
@@ -87201,7 +87211,8 @@ function getAccessibleIPs(HOST) {
87201
87211
  function getPrimaryIP(HOST) {
87202
87212
  const addresses = getAccessibleIPs(HOST);
87203
87213
  const privateIPRegex = /^(10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.|192\.168\.)/;
87204
- return addresses.find((ip) => privateIPRegex.test(ip)) || addresses[0] || HOST;
87214
+ const priorityIP = addresses.find((ip) => /^192\.168\./.test(ip)) || addresses.find((ip) => privateIPRegex.test(ip));
87215
+ return priorityIP || addresses[0] || HOST;
87205
87216
  }
87206
87217
  async function initializeClaudeConfig() {
87207
87218
  const homeDir = (0, import_os2.homedir)();