@dedenlabs/claude-code-router-cli 2.0.2 → 2.0.4

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/package.json CHANGED
@@ -1,64 +1,76 @@
1
- {
2
- "name": "@dedenlabs/claude-code-router-cli",
3
- "version": "2.0.2",
4
- "description": "基于@musistudio/claude-code-router的增强版CLI路由工具 - 支持统一路由引擎、外部规则加载、智能日志系统、自动配置迁移和GLM思考模式",
5
- "bin": {
6
- "ccr": "dist/cli.js"
7
- },
8
- "scripts": {
9
- "build": "node scripts/build.js",
10
- "release": "npm run build && npm publish",
11
- "prepublishOnly": "node scripts/prepublish-check.js"
12
- },
13
- "keywords": [
14
- "claude",
15
- "code",
16
- "router",
17
- "llm",
18
- "anthropic",
19
- "cli",
20
- "unified",
21
- "external-rules"
22
- ],
23
- "author": "dedenlabs <deden.labs@gmail.com> (Original by musistudio)",
24
- "license": "MIT",
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/dedenlabs/claude-code-router-cli.git"
28
- },
29
- "bugs": {
30
- "url": "https://github.com/dedenlabs/claude-code-router-cli/issues"
31
- },
32
- "homepage": "https://github.com/dedenlabs/claude-code-router-cli#readme",
33
- "dependencies": {
34
- "@fastify/static": "^8.2.0",
35
- "@inquirer/prompts": "^5.0.0",
36
- "@musistudio/llms": "^1.0.48",
37
- "dotenv": "^16.4.7",
38
- "find-process": "^2.0.0",
39
- "json5": "^2.2.3",
40
- "lru-cache": "^11.2.2",
41
- "minimist": "^1.2.8",
42
- "rotating-file-stream": "^3.2.7",
43
- "shell-quote": "^1.8.3",
44
- "tiktoken": "^1.0.21",
45
- "uuid": "^11.1.0"
46
- },
47
- "devDependencies": {
48
- "@types/node": "^24.0.15",
49
- "esbuild": "^0.25.1",
50
- "fastify": "^5.4.0",
51
- "shx": "^0.4.0",
52
- "typescript": "^5.8.2"
53
- },
54
- "files": [
55
- "dist/",
56
- "examples/",
57
- "LICENSE",
58
- "README.md",
59
- "tsconfig.json"
60
- ],
61
- "publishConfig": {
62
- "access": "public"
63
- }
64
- }
1
+ {
2
+ "name": "@dedenlabs/claude-code-router-cli",
3
+ "version": "2.0.4",
4
+ "description": "基于@musistudio/claude-code-router的增强版CLI路由工具 - 支持统一路由引擎、外部规则加载、智能日志系统、自动配置迁移和GLM思考模式",
5
+ "bin": {
6
+ "ccr": "dist/cli.js"
7
+ },
8
+ "scripts": {
9
+ "build": "node scripts/build.js",
10
+ "release": "npm run build && npm publish",
11
+ "prepublishOnly": "node scripts/prepublish-check.js",
12
+ "test": "vitest run",
13
+ "test:watch": "vitest",
14
+ "test:coverage": "vitest run --coverage",
15
+ "test:ui": "vitest --ui",
16
+ "test:integration": "vitest run --config ./vitest.config.ts tests/integration",
17
+ "test:unit": "vitest run --config ./vitest.config.ts tests/unit",
18
+ "test:ui:unit": "vitest run --config ./vitest.config.ts tests/ui"
19
+ },
20
+ "keywords": [
21
+ "claude",
22
+ "code",
23
+ "router",
24
+ "llm",
25
+ "anthropic",
26
+ "cli",
27
+ "unified",
28
+ "external-rules"
29
+ ],
30
+ "author": "dedenlabs <deden.labs@gmail.com> (Original by musistudio)",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/dedenlabs/claude-code-router-cli.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/dedenlabs/claude-code-router-cli/issues"
38
+ },
39
+ "homepage": "https://github.com/dedenlabs/claude-code-router-cli#readme",
40
+ "dependencies": {
41
+ "@fastify/static": "^8.2.0",
42
+ "@inquirer/prompts": "^5.0.0",
43
+ "@musistudio/llms": "^1.0.48",
44
+ "dotenv": "^16.4.7",
45
+ "find-process": "^2.0.0",
46
+ "json5": "^2.2.3",
47
+ "lru-cache": "^11.2.2",
48
+ "minimist": "^1.2.8",
49
+ "rotating-file-stream": "^3.2.7",
50
+ "shell-quote": "^1.8.3",
51
+ "tiktoken": "^1.0.21",
52
+ "uuid": "^11.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@testing-library/react": "^14.3.1",
56
+ "@types/node": "^24.0.15",
57
+ "@vitest/coverage-v8": "^2.1.9",
58
+ "@vitest/ui": "^2.1.9",
59
+ "esbuild": "^0.25.1",
60
+ "fastify": "^5.4.0",
61
+ "jsdom": "^25.0.1",
62
+ "shx": "^0.4.0",
63
+ "typescript": "^5.8.2",
64
+ "vitest": "^2.1.9"
65
+ },
66
+ "files": [
67
+ "dist/",
68
+ "examples/",
69
+ "LICENSE",
70
+ "README.md",
71
+ "tsconfig.json"
72
+ ],
73
+ "publishConfig": {
74
+ "access": "public"
75
+ }
76
+ }
@@ -1,70 +0,0 @@
1
- /**
2
- * 用户偏好路由规则
3
- * 根据用户的系统消息中保存的偏好设置进行路由
4
- */
5
-
6
- // 模拟用户偏好数据库
7
- const userPreferences = {
8
- 'user@example.com': {
9
- preferredModel: 'gpt-4',
10
- provider: 'openai'
11
- },
12
- 'admin@example.com': {
13
- preferredModel: 'claude-3-opus',
14
- provider: 'anthropic'
15
- }
16
- };
17
-
18
- /**
19
- * 检查用户偏好
20
- * @param {RouteContext} context - 路由上下文
21
- * @returns {boolean} - 是否匹配用户偏好
22
- */
23
- function checkUserPreference(context) {
24
- // 从系统消息或会话信息中提取用户标识
25
- const userEmail = extractUserEmail(context);
26
-
27
- if (!userEmail) {
28
- console.log(`无法识别用户邮箱,使用默认路由`);
29
- return false;
30
- }
31
-
32
- const preference = userPreferences[userEmail];
33
- if (!preference) {
34
- console.log(`用户 ${userEmail} 没有设置偏好,使用默认路由`);
35
- return false;
36
- }
37
-
38
- // 记录匹配结果
39
- console.log(`用户偏好匹配: ${userEmail} -> ${preference.provider}/${preference.preferredModel}`);
40
- return true;
41
- }
42
-
43
- /**
44
- * 从上下文中提取用户邮箱
45
- */
46
- function extractUserEmail(context) {
47
- // 尝试从多个可能的来源获取用户邮箱
48
- if (context.req?.headers?.['x-user-email']) {
49
- return context.req.headers['x-user-email'];
50
- }
51
-
52
- if (context.sessionId && context.sessionId.includes('@')) {
53
- return context.sessionId;
54
- }
55
-
56
- // 可以从系统消息中解析
57
- if (context.system && context.system[0]?.text) {
58
- const emailMatch = context.system[0].text.match(/user:\s*([^\s]+)/);
59
- if (emailMatch) {
60
- return emailMatch[1];
61
- }
62
- }
63
-
64
- return null;
65
- }
66
-
67
- // 导出函数
68
- module.exports = {
69
- checkUserPreference
70
- };