@dedenlabs/claude-code-router-cli 2.0.0

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.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 外部规则示例文件
3
+ *
4
+ * 演示如何使用 externalFunction 条件类型来加载外部 JS 规则
5
+ */
6
+
7
+ // 示例1:根据用户请求的特定属性进行路由
8
+ const userPreferenceRule = {
9
+ name: 'userPreferenceRouting',
10
+ priority: 100,
11
+ condition: {
12
+ type: 'externalFunction',
13
+ externalFunction: {
14
+ path: './external-rules/user-preference.js',
15
+ functionName: 'checkUserPreference'
16
+ }
17
+ },
18
+ action: {
19
+ route: 'gpt-4,openai'
20
+ }
21
+ };
22
+
23
+ // 示例2:基于时间的动态路由
24
+ const timeBasedRule = {
25
+ name: 'timeBasedRouting',
26
+ priority: 90,
27
+ condition: {
28
+ type: 'externalFunction',
29
+ externalFunction: {
30
+ path: './external-rules/time-based.js',
31
+ functionName: 'isBusinessHours'
32
+ }
33
+ },
34
+ action: {
35
+ route: 'claude-3-opus,anthropic'
36
+ }
37
+ };
38
+
39
+ // 示例3:复杂的多条件判断
40
+ const complexRoutingRule = {
41
+ name: 'complexRouting',
42
+ priority: 80,
43
+ condition: {
44
+ type: 'externalFunction',
45
+ externalFunction: {
46
+ path: './external-rules/complex-routing.js',
47
+ functionName: 'evaluateComplexCondition'
48
+ }
49
+ },
50
+ action: {
51
+ route: 'gemini-pro,google'
52
+ }
53
+ };
54
+
55
+ // 将这些规则添加到配置中
56
+ export const externalRules = [
57
+ userPreferenceRule,
58
+ timeBasedRule,
59
+ complexRoutingRule
60
+ ];
61
+
62
+ // 配置更新函数
63
+ export function addExternalRulesToConfig(config) {
64
+ // 合并外部规则到现有配置
65
+ config.rules = [...(config.rules || []), ...externalRules];
66
+
67
+ // 确保规则按优先级排序
68
+ config.rules.sort((a, b) => (b.priority || 0) - (a.priority || 0));
69
+
70
+ return config;
71
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@dedenlabs/claude-code-router-cli",
3
+ "version": "2.0.0",
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": "https://github.com/dedenlabs/claude-code-router-cli"
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
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "CommonJS",
5
+ "outDir": "./dist",
6
+ "rootDir": "./src",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "resolveJsonModule": true,
12
+ "moduleResolution": "node",
13
+ "noImplicitAny": true,
14
+ "allowSyntheticDefaultImports": true,
15
+ "sourceMap": true,
16
+ "declaration": true
17
+ },
18
+ "include": ["src/**/*.ts"],
19
+ "exclude": ["node_modules", "dist"]
20
+ }