aicodeswitch 2.1.2 → 2.1.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/README.md +29 -12
- package/dist/server/database.js +4 -0
- package/dist/server/main.js +39 -0
- package/dist/server/proxy-server.js +6 -4
- package/dist/types/index.js +9 -0
- package/dist/ui/assets/index-BVblbmz5.css +1 -0
- package/dist/ui/assets/index-BqBZrCTy.js +470 -0
- package/dist/ui/assets/logo-CRx_w1Ov.png +0 -0
- package/dist/ui/index.html +2 -2
- package/package.json +6 -2
- package/.github/workflows/publish-to-npm.yaml +0 -34
- package/CHANGELOG.md +0 -43
- package/CLAUDE.md +0 -253
- package/TECH.md +0 -315
- package/dist/ui/assets/index-B9EyKK90.js +0 -452
- package/dist/ui/assets/index-Bf2ZEtnh.css +0 -1
- package/dist/ui/vendors-recommand.md +0 -14
- package/public/donate-to-me.png +0 -0
- package/public/migration.md +0 -7
- package/public/vendors-recommand.md +0 -14
- package/schemes/claude.schema.md +0 -945
- package/schemes/openai.schema.md +0 -2162
|
Binary file
|
package/dist/ui/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>AI Code Switch</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-BqBZrCTy.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BVblbmz5.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicodeswitch",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "A tool to help you manage AI programming tools to access large language models locally. It allows your Claude Code, Codex and other tools to no longer be limited to official models.",
|
|
5
5
|
"author": "tangshuang",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -44,7 +44,10 @@
|
|
|
44
44
|
"build:server": "tsc -p tsconfig.server.json",
|
|
45
45
|
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
46
46
|
"prepublishOnly": "npm run build",
|
|
47
|
-
"release": "standard-version"
|
|
47
|
+
"release": "standard-version",
|
|
48
|
+
"tauri:dev": "tauri dev",
|
|
49
|
+
"tauri:build": "tauri build && node tauri/move-bundle.js",
|
|
50
|
+
"tauri:icon": "tauri icon src/ui/assets/logo.png"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
53
|
"@types/jsonwebtoken": "^9.0.10",
|
|
@@ -63,6 +66,7 @@
|
|
|
63
66
|
"ws": "^8.19.0"
|
|
64
67
|
},
|
|
65
68
|
"devDependencies": {
|
|
69
|
+
"@tauri-apps/cli": "^2.0.0",
|
|
66
70
|
"@types/better-sqlite3": "^7.6.9",
|
|
67
71
|
"@types/cors": "^2.8.17",
|
|
68
72
|
"@types/crypto-js": "^4.2.2",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: Publish To NPM
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
types:
|
|
5
|
-
- closed
|
|
6
|
-
branches:
|
|
7
|
-
- main
|
|
8
|
-
jobs:
|
|
9
|
-
publish:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write
|
|
13
|
-
id-token: write
|
|
14
|
-
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v5
|
|
17
|
-
- uses: actions/setup-node@v4
|
|
18
|
-
with:
|
|
19
|
-
node-version: '24.x'
|
|
20
|
-
registry-url: 'https://registry.npmjs.org'
|
|
21
|
-
- run: npm install --verbose
|
|
22
|
-
- run: |
|
|
23
|
-
git config --global user.name 'github-actions[bot]'
|
|
24
|
-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
|
25
|
-
- run: npm run release
|
|
26
|
-
- run: npx can-npm-publish
|
|
27
|
-
- run: npm publish --provenance
|
|
28
|
-
env:
|
|
29
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
30
|
-
- uses: ad-m/github-push-action@master
|
|
31
|
-
with:
|
|
32
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
33
|
-
branch: main
|
|
34
|
-
tags: true
|
package/CHANGELOG.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### 2.1.2 (2026-02-04)
|
|
6
|
-
|
|
7
|
-
### 2.1.1 (2026-02-03)
|
|
8
|
-
|
|
9
|
-
### 2.0.11 (2026-02-03)
|
|
10
|
-
|
|
11
|
-
### 2.0.10 (2026-02-03)
|
|
12
|
-
|
|
13
|
-
### 2.0.9 (2026-02-02)
|
|
14
|
-
|
|
15
|
-
### 2.0.8 (2026-02-02)
|
|
16
|
-
|
|
17
|
-
### 2.0.7 (2026-02-02)
|
|
18
|
-
|
|
19
|
-
### 2.0.6 (2026-02-01)
|
|
20
|
-
|
|
21
|
-
### 2.0.5 (2026-01-27)
|
|
22
|
-
|
|
23
|
-
### 2.0.4 (2026-01-27)
|
|
24
|
-
|
|
25
|
-
### 2.0.3 (2026-01-27)
|
|
26
|
-
|
|
27
|
-
### 2.0.2 (2026-01-27)
|
|
28
|
-
|
|
29
|
-
### 2.0.1 (2026-01-27)
|
|
30
|
-
|
|
31
|
-
### 1.10.2 (2026-01-26)
|
|
32
|
-
|
|
33
|
-
### 1.10.1 (2026-01-25)
|
|
34
|
-
|
|
35
|
-
## [1.10.0](https://github.com/tangshuang/aicodeswitch/compare/v1.9.0...v1.10.0) (2026-01-25)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Features
|
|
39
|
-
|
|
40
|
-
* 日志分页 ([0e68786](https://github.com/tangshuang/aicodeswitch/commit/0e68786b4e5bdce9bf7fc5ce85a1d4bdaf5a710c))
|
|
41
|
-
* 新增了代理能力 ([d6254ae](https://github.com/tangshuang/aicodeswitch/commit/d6254ae463f01f583601ed71f64f346b63718853))
|
|
42
|
-
* 优化细节 ([e4bdaef](https://github.com/tangshuang/aicodeswitch/commit/e4bdaef14bb0088e7feb5371490124c8dd169fdd))
|
|
43
|
-
* github workflows ([37dd371](https://github.com/tangshuang/aicodeswitch/commit/37dd3717e79dab1c4aec99b762774cc549f1efc8))
|
package/CLAUDE.md
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
```
|
|
2
|
-
# CLAUDE.md
|
|
3
|
-
|
|
4
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
## AI Code Switch - Project Overview
|
|
8
|
-
|
|
9
|
-
AI Code Switch is a local proxy server that manages AI programming tool connections to large language models, allowing tools like Claude Code and Codex to use custom model APIs instead of official ones.
|
|
10
|
-
|
|
11
|
-
## Development Commands
|
|
12
|
-
|
|
13
|
-
### Installation
|
|
14
|
-
```bash
|
|
15
|
-
npm install
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### Development
|
|
19
|
-
```bash
|
|
20
|
-
npm run dev # Run both UI and server in watch mode
|
|
21
|
-
npm run dev:ui # Run only React UI (Vite dev server)
|
|
22
|
-
npm run dev:server # Run only Node.js server (TSX watch)
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Build
|
|
26
|
-
```bash
|
|
27
|
-
npm run build # Build both UI and server
|
|
28
|
-
npm run build:ui # Build React UI to dist/ui
|
|
29
|
-
npm run build:server # Build TypeScript server to dist/server
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Linting
|
|
33
|
-
```bash
|
|
34
|
-
npm run lint # Run ESLint on all .ts/.tsx files
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### CLI Commands
|
|
38
|
-
```bash
|
|
39
|
-
npm link # Link local package for CLI testing
|
|
40
|
-
aicos start # Start the proxy server
|
|
41
|
-
aicos stop # Stop the proxy server
|
|
42
|
-
aicos restart # Restart the proxy server
|
|
43
|
-
aicos ui # Open web UI in browser (starts server if needed)
|
|
44
|
-
aicos update # Update to the latest version and restart
|
|
45
|
-
aicos restore # Restore original configuration files
|
|
46
|
-
aicos version # Show current version information
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Architecture
|
|
50
|
-
|
|
51
|
-
### High-Level Structure
|
|
52
|
-
```
|
|
53
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
54
|
-
│ AI Code Switch │
|
|
55
|
-
├─────────────────────────────────────────────────────────────┤
|
|
56
|
-
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
57
|
-
│ │ React UI │ │ Express API │ │ Proxy Core │ │
|
|
58
|
-
│ │ (Vite dev) │ │ (Node.js) │ │ │ │
|
|
59
|
-
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
|
60
|
-
│ │ │ │ │
|
|
61
|
-
│ └──────────────┼──────────────┘ │
|
|
62
|
-
│ ▼ │
|
|
63
|
-
│ ┌──────────────┐ │
|
|
64
|
-
│ │ Database │ │
|
|
65
|
-
│ │ (SQLite3) │ │
|
|
66
|
-
│ └──────────────┘ │
|
|
67
|
-
│ │ │
|
|
68
|
-
│ ▼ │
|
|
69
|
-
│ ┌──────────────┐ │
|
|
70
|
-
│ │ Transformers │ │
|
|
71
|
-
│ │ (Stream/SSE) │ │
|
|
72
|
-
│ └──────────────┘ │
|
|
73
|
-
│ │ │
|
|
74
|
-
│ ▼ │
|
|
75
|
-
│ ┌──────────────┐ │
|
|
76
|
-
│ │ Upstream │ │
|
|
77
|
-
│ │ APIs (LLMs) │ │
|
|
78
|
-
│ └──────────────┘ │
|
|
79
|
-
└─────────────────────────────────────────────────────────────┘
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Core Components
|
|
83
|
-
|
|
84
|
-
#### 1. Server (Node.js/Express) - `server/main.ts`
|
|
85
|
-
- Main entry point
|
|
86
|
-
- Configures Express with CORS, body parsing
|
|
87
|
-
- Reads configuration from `~/.aicodeswitch/aicodeswitch.conf`
|
|
88
|
-
- Sets up authentication middleware
|
|
89
|
-
- Registers all API routes
|
|
90
|
-
- Initializes database and proxy server
|
|
91
|
-
|
|
92
|
-
#### 2. Proxy Server - `server/proxy-server.ts`
|
|
93
|
-
- **Route Matching**: Finds active route based on target type (claude-code/codex)
|
|
94
|
-
- **Rule Matching**: Determines content type from request (image-understanding/thinking/long-context/background/default)
|
|
95
|
-
- **Request Transformation**: Converts between different API formats (Claude ↔ OpenAI Chat)
|
|
96
|
-
- **Streaming**: Handles SSE (Server-Sent Events) streaming responses with real-time transformation
|
|
97
|
-
- **Logging**: Tracks requests, responses, and errors
|
|
98
|
-
|
|
99
|
-
#### 3. Transformers - `server/transformers/`
|
|
100
|
-
- **streaming.ts**: SSE parsing/serialization and event transformation
|
|
101
|
-
- **claude-openai.ts**: Claude ↔ OpenAI Chat format conversion
|
|
102
|
-
- Image content block conversion (Claude ↔ OpenAI formats)
|
|
103
|
-
- Tool choice mapping (auto/any/tool ↔ auto/none/required)
|
|
104
|
-
- Stop reason mapping (including max_thinking_length)
|
|
105
|
-
- System prompt handling (string and array formats)
|
|
106
|
-
- Thinking/Reasoning content conversion
|
|
107
|
-
- **chunk-collector.ts**: Collects streaming chunks for logging
|
|
108
|
-
|
|
109
|
-
**API 转换功能**:
|
|
110
|
-
转换器实现了以下 API 格式之间的双向转换:
|
|
111
|
-
- **Claude Messages API** ↔ **OpenAI Chat Completions API**
|
|
112
|
-
- **Claude Messages API** ↔ **OpenAI Responses API**
|
|
113
|
-
- **DeepSeek Chat** ↔ 其他格式(支持 developer 角色映射)
|
|
114
|
-
|
|
115
|
-
**支持的转换内容**:
|
|
116
|
-
- 文本内容 (text)
|
|
117
|
-
- 图像内容 (image ↔ image_url)
|
|
118
|
-
- 工具调用 (tool_use ↔ tool_calls)
|
|
119
|
-
- 工具结果 (tool_result)
|
|
120
|
-
- 思考内容 (thinking ↔ reasoning/thinking)
|
|
121
|
-
- 系统提示词 (system - 支持字符串和数组格式)
|
|
122
|
-
|
|
123
|
-
#### 4. Database - `server/database.ts`
|
|
124
|
-
- SQLite3 database wrapper
|
|
125
|
-
- Manages: Vendors, API Services, Routes, Rules, Logs
|
|
126
|
-
- Configuration storage (API key, logging settings, etc.)
|
|
127
|
-
|
|
128
|
-
#### 5. UI (React) - `ui/`
|
|
129
|
-
- Main app: `App.tsx` - Navigation and layout with collapsible sidebar
|
|
130
|
-
- Components:
|
|
131
|
-
- `Tooltip.tsx` - Tooltip component for displaying menu text when sidebar is collapsed
|
|
132
|
-
- `Toast.tsx` - Toast notification component
|
|
133
|
-
- `Confirm.tsx` - Confirmation dialog component
|
|
134
|
-
- `ToolsInstallModal.tsx` - Tools installation modal
|
|
135
|
-
- `NotificationBar.tsx` - Notification bar component
|
|
136
|
-
- Pages:
|
|
137
|
-
- `VendorsPage.tsx` - Manage AI service vendors
|
|
138
|
-
- `SkillsPage.tsx` - Manage global Skills and discovery
|
|
139
|
-
- `RoutesPage.tsx` - Configure routing rules
|
|
140
|
-
- `LogsPage.tsx` - View request/access/error logs
|
|
141
|
-
- `SettingsPage.tsx` - Application settings
|
|
142
|
-
- `WriteConfigPage.tsx` - Overwrite Claude Code/Codex config files
|
|
143
|
-
- `UsagePage.tsx` - Usage statistics
|
|
144
|
-
- Styles:
|
|
145
|
-
- `App.css` - Main application styles with sidebar collapse animations
|
|
146
|
-
- `Tooltip.css` - Tooltip component styles
|
|
147
|
-
|
|
148
|
-
#### 6. Types - `types/`
|
|
149
|
-
- TypeScript type definitions for:
|
|
150
|
-
- Database models (Vendors, Services, Routes, Rules)
|
|
151
|
-
- API requests/responses
|
|
152
|
-
- Configuration
|
|
153
|
-
- Token usage tracking
|
|
154
|
-
|
|
155
|
-
#### 7. CLI - `bin/`
|
|
156
|
-
- `cli.js` - Main CLI entry point
|
|
157
|
-
- `start.js` - Server startup with PID management
|
|
158
|
-
- `stop.js` - Server shutdown
|
|
159
|
-
- `restart.js` - Restart server
|
|
160
|
-
|
|
161
|
-
## Key Features
|
|
162
|
-
|
|
163
|
-
### Routing System
|
|
164
|
-
- **Routes**: Define target type (Claude Code or Codex) and activation status
|
|
165
|
-
- **Rules**: Match requests by content type and route to specific API services
|
|
166
|
-
- **Content Type Detection**:
|
|
167
|
-
- `image-understanding`: Requests with image content
|
|
168
|
-
- `thinking`: Requests with reasoning/thinking signals
|
|
169
|
-
- `long-context`: Requests with large context (≥12000 chars or ≥8000 max tokens)
|
|
170
|
-
- `background`: Background/priority requests, including `/count_tokens` endpoint requests and token counting requests with `{"role": "user", "content": "count"}`
|
|
171
|
-
- `default`: All other requests
|
|
172
|
-
|
|
173
|
-
### Request Transformation
|
|
174
|
-
- Supports multiple source types:
|
|
175
|
-
- OpenAI Chat
|
|
176
|
-
- OpenAI Code
|
|
177
|
-
- OpenAI Responses
|
|
178
|
-
- Claude Chat
|
|
179
|
-
- Claude Code
|
|
180
|
-
- DeepSeek Chat
|
|
181
|
-
|
|
182
|
-
### Configuration Management
|
|
183
|
-
- Writes/ restores Claude Code config files (`~/.claude/settings.json`, `~/.claude.json`)
|
|
184
|
-
- Writes/ restores Codex config files (`~/.codex/config.toml`, `~/.codex/auth.json`)
|
|
185
|
-
- Exports/ imports encrypted configuration data
|
|
186
|
-
|
|
187
|
-
### Skills Management
|
|
188
|
-
- Lists global Skills for Claude Code and Codex
|
|
189
|
-
- Provides discovery search (discover/return toggle button) and installs Skills into target tool directories
|
|
190
|
-
|
|
191
|
-
### Logging
|
|
192
|
-
- Request logs: Detailed API call records with token usage
|
|
193
|
-
- Access logs: System access records
|
|
194
|
-
- Error logs: Error and exception records with comprehensive context
|
|
195
|
-
- **Error Log Details**:
|
|
196
|
-
- Basic error information: timestamp, method, path, status code, error message, error stack
|
|
197
|
-
- Request context: targetType (client type), requestModel (requested model)
|
|
198
|
-
- Routing context: ruleId (used rule), targetServiceId/Name (API service), targetModel (actual model)
|
|
199
|
-
- Vendor context: vendorId/Name (service provider)
|
|
200
|
-
- Request details: request headers, request body, response headers, response body
|
|
201
|
-
- **Upstream Request Information**: URL, headers, body, proxy usage
|
|
202
|
-
- Response time metrics
|
|
203
|
-
- **Data Sanitization**:
|
|
204
|
-
- Sensitive authentication fields (api_key, authorization, password, secret, etc.) are automatically masked in the UI
|
|
205
|
-
- Technical fields like `max_tokens`, `input_tokens`, `output_tokens` are NOT masked - they are legitimate API parameters
|
|
206
|
-
- **Session Management**:
|
|
207
|
-
- Tracks user sessions based on session ID (Claude Code: `metadata.user_id`, Codex: `headers.session_id`)
|
|
208
|
-
- Auto-generates session title from first user message content:
|
|
209
|
-
- Extracts text from first user message
|
|
210
|
-
- Cleans up whitespace and newlines
|
|
211
|
-
- Intelligently truncates at word boundaries (max 100 chars)
|
|
212
|
-
- Adds "..." for truncated titles
|
|
213
|
-
- Records first request time, last request time, request count, and total tokens per session
|
|
214
|
-
|
|
215
|
-
### Usage Limits Auto-Sync
|
|
216
|
-
- **Service-Level Limits**: API services can have token and request count limits configured
|
|
217
|
-
- **Auto-Sync to Rules**: When an API service's usage limits are modified, all rules using that service are automatically updated with the new limits
|
|
218
|
-
- **Inheritance Detection**: When editing a rule, the system detects if the rule's limits match the service's limits and displays them as "inherited" (read-only)
|
|
219
|
-
- **Manual Override**: Rules can be configured with custom limits that differ from the service defaults
|
|
220
|
-
|
|
221
|
-
## Development Tips
|
|
222
|
-
|
|
223
|
-
1. **Environment Variables**: Copy `.env.example` to `.env` and modify as needed
|
|
224
|
-
2. **Data Directory**: Default: `~/.aicodeswitch/data/` (SQLite3 database)
|
|
225
|
-
3. **Config File**: `~/.aicodeswitch/aicodeswitch.conf` (HOST, PORT, AUTH)
|
|
226
|
-
4. **Dev Ports**: UI (4568), Server (4567) - configured in `vite.config.ts` and `server/main.ts`
|
|
227
|
-
5. **Skills Search**: `SKILLSMP_API_KEY` is required for Skills discovery via SkillsMP
|
|
228
|
-
6. **API Endpoints**: All routes are prefixed with `/api/` except proxy routes (`/claude-code/`, `/codex/`)
|
|
229
|
-
|
|
230
|
-
## Build and Deployment
|
|
231
|
-
|
|
232
|
-
1. Run `npm run build` to create production builds
|
|
233
|
-
2. UI build outputs to `dist/ui/` (static files)
|
|
234
|
-
3. Server build outputs to `dist/server/` (JavaScript)
|
|
235
|
-
4. Configuration files are created in user's home directory on first run
|
|
236
|
-
|
|
237
|
-
## Technology Stack
|
|
238
|
-
|
|
239
|
-
- **Backend**: Node.js, Express, TypeScript, SQLite3
|
|
240
|
-
- **Frontend**: React 18, TypeScript, Vite, React Router
|
|
241
|
-
- **Streaming**: SSE (Server-Sent Events)
|
|
242
|
-
- **HTTP Client**: Axios
|
|
243
|
-
- **Encryption**: CryptoJS (AES)
|
|
244
|
-
- **CLI**: Yargs-like custom implementation
|
|
245
|
-
|
|
246
|
-
## Development
|
|
247
|
-
|
|
248
|
-
* 使用yarn作为包管理器,请使用yarn安装依赖。
|
|
249
|
-
* 前端依赖库安装在devDependencies中,请使用yarn install --dev安装。
|
|
250
|
-
* 所有对话请使用中文。生成代码中的文案及相关注释根据代码原本的语言生成。
|
|
251
|
-
* 在服务端,直接使用 __dirname 来获取当前目录,不要使用 process.cwd()
|
|
252
|
-
* 每次有新的变化时,你需要更新 CLAUDE.md 来让文档保持最新。
|
|
253
|
-
* 禁止在项目中使用依赖GPU的css样式处理。
|