mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 08:44:41 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a87daebe14 | |||
| ec04132303 | |||
| bbb356a948 | |||
| f582bd58b1 | |||
| a7f1461a33 | |||
| 956e723781 | |||
| 461ba6f418 | |||
| 6b5752db24 | |||
| ec1ae7073f |
-247
@@ -5,247 +5,6 @@ All notable changes to CC Switch will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [3.7.1] - 2025-11-22
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- **Skills third-party repository installation** (#268) - Fixed installation failure for skills repositories with custom subdirectories (e.g., `ComposioHQ/awesome-claude-skills`)
|
|
||||||
- **Gemini configuration persistence** - Resolved issue where settings.json edits were lost when switching providers
|
|
||||||
- **Dialog overlay click protection** - Prevented dialogs from closing when clicking outside, avoiding accidental form data loss (affects 11 dialog components)
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- **Gemini configuration directory support** (#255) - Added custom configuration directory option for Gemini in settings
|
|
||||||
- **ArchLinux installation support** (#259) - Added AUR installation via `paru -S cc-switch-bin`
|
|
||||||
|
|
||||||
### Improved
|
|
||||||
|
|
||||||
- **Skills error messages i18n** - Added 28+ detailed error messages (English & Chinese) with specific resolution suggestions
|
|
||||||
- **Download timeout** - Extended from 15s to 60s to reduce network-related false positives
|
|
||||||
- **Code formatting** - Applied unified Rust (`cargo fmt`) and TypeScript (`prettier`) formatting standards
|
|
||||||
|
|
||||||
### Reverted
|
|
||||||
|
|
||||||
- **Auto-launch on system startup** - Temporarily reverted feature pending further testing and optimization
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## [3.7.0] - 2025-11-19
|
|
||||||
|
|
||||||
### Major Features
|
|
||||||
|
|
||||||
#### Gemini CLI Integration
|
|
||||||
|
|
||||||
- **Complete Gemini CLI support** - Third major application added alongside Claude Code and Codex
|
|
||||||
- **Dual-file configuration** - Support for both `.env` and `settings.json` file formats
|
|
||||||
- **Environment variable detection** - Auto-detect `GOOGLE_GEMINI_BASE_URL`, `GEMINI_MODEL`, etc.
|
|
||||||
- **MCP management** - Full MCP configuration capabilities for Gemini
|
|
||||||
- **Provider presets**
|
|
||||||
- Google Official (OAuth authentication)
|
|
||||||
- PackyCode (partner integration)
|
|
||||||
- Custom endpoint support
|
|
||||||
- **Deep link support** - Import Gemini providers via `ccswitch://` protocol
|
|
||||||
- **System tray integration** - Quick-switch Gemini providers from tray menu
|
|
||||||
- **Backend modules** - New `gemini_config.rs` (20KB) and `gemini_mcp.rs`
|
|
||||||
|
|
||||||
#### MCP v3.7.0 Unified Architecture
|
|
||||||
|
|
||||||
- **Unified management panel** - Single interface for Claude/Codex/Gemini MCP servers
|
|
||||||
- **SSE transport type** - New Server-Sent Events support alongside stdio/http
|
|
||||||
- **Smart JSON parser** - Fault-tolerant parsing of various MCP config formats
|
|
||||||
- **Extended field support** - Preserve custom fields in Codex TOML conversion
|
|
||||||
- **Codex format correction** - Proper `[mcp_servers]` format (auto-cleanup of incorrect `[mcp.servers]`)
|
|
||||||
- **Import/export system** - Unified import from Claude/Codex/Gemini live configs
|
|
||||||
- **UX improvements**
|
|
||||||
- Default app selection in forms
|
|
||||||
- JSON formatter for config validation
|
|
||||||
- Improved layout and visual hierarchy
|
|
||||||
- Better validation error messages
|
|
||||||
|
|
||||||
#### Claude Skills Management System
|
|
||||||
|
|
||||||
- **GitHub repository integration** - Auto-scan and discover skills from GitHub repos
|
|
||||||
- **Pre-configured repositories**
|
|
||||||
- `ComposioHQ/awesome-claude-skills` (curated collection)
|
|
||||||
- `anthropics/skills` (official Anthropic skills)
|
|
||||||
- `cexll/myclaude` (community, with subdirectory scanning)
|
|
||||||
- **Lifecycle management**
|
|
||||||
- One-click install to `~/.claude/skills/`
|
|
||||||
- Safe uninstall with state tracking
|
|
||||||
- Update checking (infrastructure ready)
|
|
||||||
- **Custom repository support** - Add any GitHub repo as a skill source
|
|
||||||
- **Subdirectory scanning** - Optional `skillsPath` for repos with nested skill directories
|
|
||||||
- **Backend architecture** - `SkillService` (526 lines) with GitHub API integration
|
|
||||||
- **Frontend interface**
|
|
||||||
- SkillsPage: Browse and manage skills
|
|
||||||
- SkillCard: Visual skill presentation
|
|
||||||
- RepoManager: Repository management dialog
|
|
||||||
- **State persistence** - Installation state stored in `skills.json`
|
|
||||||
- **Full i18n support** - Complete Chinese/English translations (47+ keys)
|
|
||||||
|
|
||||||
#### Prompts (System Prompts) Management
|
|
||||||
|
|
||||||
- **Multi-preset management** - Create, edit, and switch between multiple system prompts
|
|
||||||
- **Cross-app support**
|
|
||||||
- Claude: `~/.claude/CLAUDE.md`
|
|
||||||
- Codex: `~/.codex/AGENTS.md`
|
|
||||||
- Gemini: `~/.gemini/GEMINI.md`
|
|
||||||
- **Markdown editor** - Full-featured CodeMirror 6 editor with syntax highlighting
|
|
||||||
- **Smart synchronization**
|
|
||||||
- Auto-write to live files on enable
|
|
||||||
- Content backfill protection (save current before switching)
|
|
||||||
- First-launch auto-import from live files
|
|
||||||
- **Single-active enforcement** - Only one prompt can be active at a time
|
|
||||||
- **Delete protection** - Cannot delete active prompts
|
|
||||||
- **Backend service** - `PromptService` (213 lines) with CRUD operations
|
|
||||||
- **Frontend components**
|
|
||||||
- PromptPanel: Main management interface (177 lines)
|
|
||||||
- PromptFormModal: Edit dialog with validation (160 lines)
|
|
||||||
- MarkdownEditor: CodeMirror integration (159 lines)
|
|
||||||
- usePromptActions: Business logic hook (152 lines)
|
|
||||||
- **Full i18n support** - Complete Chinese/English translations (41+ keys)
|
|
||||||
|
|
||||||
#### Deep Link Protocol (ccswitch://)
|
|
||||||
|
|
||||||
- **Protocol registration** - `ccswitch://` URL scheme for one-click imports
|
|
||||||
- **Provider import** - Import provider configurations from URLs or shared links
|
|
||||||
- **Lifecycle integration** - Deep link handling integrated into app startup
|
|
||||||
- **Cross-platform support** - Works on Windows, macOS, and Linux
|
|
||||||
|
|
||||||
#### Environment Variable Conflict Detection
|
|
||||||
|
|
||||||
- **Claude & Codex detection** - Identify conflicting environment variables
|
|
||||||
- **Gemini auto-detection** - Automatic environment variable discovery
|
|
||||||
- **Conflict management** - UI for resolving configuration conflicts
|
|
||||||
- **Prevention system** - Warn before overwriting existing configurations
|
|
||||||
|
|
||||||
### New Features
|
|
||||||
|
|
||||||
#### Provider Management
|
|
||||||
|
|
||||||
- **DouBaoSeed preset** - Added ByteDance's DouBao provider
|
|
||||||
- **Kimi For Coding** - Moonshot AI coding assistant
|
|
||||||
- **BaiLing preset** - BaiLing AI integration
|
|
||||||
- **Removed AnyRouter preset** - Discontinued provider
|
|
||||||
- **Model configuration** - Support for custom model names in Codex and Gemini
|
|
||||||
- **Provider notes field** - Add custom notes to providers for better organization
|
|
||||||
|
|
||||||
#### Configuration Management
|
|
||||||
|
|
||||||
- **Common config migration** - Moved Claude common config snippets from localStorage to `config.json`
|
|
||||||
- **Unified persistence** - Common config snippets now shared across all apps
|
|
||||||
- **Auto-import on first launch** - Automatically import configs from live files on first run
|
|
||||||
- **Backfill priority fix** - Correct priority handling when enabling prompts
|
|
||||||
|
|
||||||
#### UI/UX Improvements
|
|
||||||
|
|
||||||
- **macOS native design** - Migrated color scheme to macOS native design system
|
|
||||||
- **Window centering** - Default window position centered on screen
|
|
||||||
- **Password input fixes** - Disabled Edge/IE reveal and clear buttons
|
|
||||||
- **URL overflow prevention** - Fixed overflow in provider cards
|
|
||||||
- **Error notification enhancement** - Copy-to-clipboard for error messages
|
|
||||||
- **Tray menu sync** - Real-time sync after drag-and-drop sorting
|
|
||||||
|
|
||||||
### Improvements
|
|
||||||
|
|
||||||
#### Architecture
|
|
||||||
|
|
||||||
- **MCP v3.7.0 cleanup** - Removed legacy code and warnings
|
|
||||||
- **Unified structure** - Default initialization with v3.7.0 unified structure
|
|
||||||
- **Backward compatibility** - Compilation fixes for older configs
|
|
||||||
- **Code formatting** - Applied consistent formatting across backend and frontend
|
|
||||||
|
|
||||||
#### Platform Compatibility
|
|
||||||
|
|
||||||
- **Windows fix** - Resolved winreg API compatibility issue (v0.52)
|
|
||||||
- **Safe pattern matching** - Replaced `unwrap()` with safe patterns in tray menu
|
|
||||||
|
|
||||||
#### Configuration
|
|
||||||
|
|
||||||
- **MCP sync on switch** - Sync MCP configs for all apps when switching providers
|
|
||||||
- **Gemini form sync** - Fixed form fields syncing with environment editor
|
|
||||||
- **Gemini config reading** - Read from both `.env` and `settings.json`
|
|
||||||
- **Validation improvements** - Enhanced input validation and boundary checks
|
|
||||||
|
|
||||||
#### Internationalization
|
|
||||||
|
|
||||||
- **JSON syntax fixes** - Resolved syntax errors in locale files
|
|
||||||
- **App name i18n** - Added internationalization support for app names
|
|
||||||
- **Deduplicated labels** - Reused providerForm keys to reduce duplication
|
|
||||||
- **Gemini MCP title** - Added missing Gemini MCP panel title
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
#### Critical Fixes
|
|
||||||
|
|
||||||
- **Usage script validation** - Added input validation and boundary checks
|
|
||||||
- **Gemini validation** - Relaxed validation when adding providers
|
|
||||||
- **TOML quote normalization** - Handle CJK quotes to prevent parsing errors
|
|
||||||
- **MCP field preservation** - Preserve custom fields in Codex TOML editor
|
|
||||||
- **Password input** - Fixed white screen crash (FormLabel → Label)
|
|
||||||
|
|
||||||
#### Stability
|
|
||||||
|
|
||||||
- **Tray menu safety** - Replaced unwrap with safe pattern matching
|
|
||||||
- **Error isolation** - Tray menu update failures don't block main operations
|
|
||||||
- **Import classification** - Set category to custom for imported default configs
|
|
||||||
|
|
||||||
#### UI Fixes
|
|
||||||
|
|
||||||
- **Model placeholders** - Removed misleading model input placeholders
|
|
||||||
- **Base URL population** - Auto-fill base URL for non-official providers
|
|
||||||
- **Drag sort sync** - Fixed tray menu order after drag-and-drop
|
|
||||||
|
|
||||||
### Technical Improvements
|
|
||||||
|
|
||||||
#### Code Quality
|
|
||||||
|
|
||||||
- **Type safety** - Complete TypeScript type coverage across codebase
|
|
||||||
- **Test improvements** - Simplified boolean assertions in tests
|
|
||||||
- **Clippy warnings** - Fixed `uninlined_format_args` warnings
|
|
||||||
- **Code refactoring** - Extracted templates, optimized logic flows
|
|
||||||
|
|
||||||
#### Dependencies
|
|
||||||
|
|
||||||
- **Tauri** - Updated to 2.8.x series
|
|
||||||
- **Rust dependencies** - Added `anyhow`, `zip`, `serde_yaml`, `tempfile` for Skills
|
|
||||||
- **Frontend dependencies** - Added CodeMirror 6 packages for Markdown editor
|
|
||||||
- **winreg** - Updated to v0.52 (Windows compatibility)
|
|
||||||
|
|
||||||
#### Performance
|
|
||||||
|
|
||||||
- **Startup optimization** - Removed legacy migration scanning
|
|
||||||
- **Lock management** - Improved RwLock usage to prevent deadlocks
|
|
||||||
- **Background query** - Enabled background mode for usage polling
|
|
||||||
|
|
||||||
### Statistics
|
|
||||||
|
|
||||||
- **Total commits**: 85 commits from v3.6.0 to v3.7.0
|
|
||||||
- **Code changes**: 152 files changed, 18,104 insertions(+), 3,732 deletions(-)
|
|
||||||
- **New modules**:
|
|
||||||
- Skills: 2,034 lines (21 files)
|
|
||||||
- Prompts: 1,302 lines (20 files)
|
|
||||||
- Gemini: ~1,000 lines (multiple files)
|
|
||||||
- MCP refactor: ~3,000 lines (refactored)
|
|
||||||
|
|
||||||
### Strategic Positioning
|
|
||||||
|
|
||||||
v3.7.0 represents a major evolution from "Provider Switcher" to **"All-in-One AI CLI Management Platform"**:
|
|
||||||
|
|
||||||
1. **Capability Extension** - Skills provide external ability integration
|
|
||||||
2. **Behavior Customization** - Prompts enable AI personality presets
|
|
||||||
3. **Configuration Unification** - MCP v3.7.0 eliminates app silos
|
|
||||||
4. **Ecosystem Openness** - Deep links enable community sharing
|
|
||||||
5. **Multi-AI Support** - Claude/Codex/Gemini trinity
|
|
||||||
6. **Intelligent Detection** - Auto-discovery of environment conflicts
|
|
||||||
|
|
||||||
### Notes
|
|
||||||
|
|
||||||
- Users upgrading from v3.1.0 or earlier should first upgrade to v3.2.x for one-time migration
|
|
||||||
- Skills and Prompts management are new features requiring no migration
|
|
||||||
- Gemini CLI support requires Gemini CLI to be installed separately
|
|
||||||
- MCP v3.7.0 unified structure is backward compatible with previous configs
|
|
||||||
|
|
||||||
## [3.6.0] - 2025-11-07
|
## [3.6.0] - 2025-11-07
|
||||||
|
|
||||||
### ✨ New Features
|
### ✨ New Features
|
||||||
@@ -314,7 +73,6 @@ v3.7.0 represents a major evolution from "Provider Switcher" to **"All-in-One AI
|
|||||||
### 🏗️ Technical Improvements (For Developers)
|
### 🏗️ Technical Improvements (For Developers)
|
||||||
|
|
||||||
**Backend Refactoring (Rust)** - Completed 5-phase refactoring:
|
**Backend Refactoring (Rust)** - Completed 5-phase refactoring:
|
||||||
|
|
||||||
- **Phase 1**: Unified error handling (`AppError` + i18n error messages)
|
- **Phase 1**: Unified error handling (`AppError` + i18n error messages)
|
||||||
- **Phase 2**: Command layer split by domain (`commands/{provider,mcp,config,settings,plugin,misc}.rs`)
|
- **Phase 2**: Command layer split by domain (`commands/{provider,mcp,config,settings,plugin,misc}.rs`)
|
||||||
- **Phase 3**: Integration tests and transaction mechanism (config snapshot + failure rollback)
|
- **Phase 3**: Integration tests and transaction mechanism (config snapshot + failure rollback)
|
||||||
@@ -322,20 +80,17 @@ v3.7.0 represents a major evolution from "Provider Switcher" to **"All-in-One AI
|
|||||||
- **Phase 5**: Concurrency optimization (`RwLock` instead of `Mutex`, scoped guard to avoid deadlock)
|
- **Phase 5**: Concurrency optimization (`RwLock` instead of `Mutex`, scoped guard to avoid deadlock)
|
||||||
|
|
||||||
**Frontend Refactoring (React + TypeScript)** - Completed 4-stage refactoring:
|
**Frontend Refactoring (React + TypeScript)** - Completed 4-stage refactoring:
|
||||||
|
|
||||||
- **Stage 1**: Test infrastructure (vitest + MSW + @testing-library/react)
|
- **Stage 1**: Test infrastructure (vitest + MSW + @testing-library/react)
|
||||||
- **Stage 2**: Extracted custom hooks (`useProviderActions`, `useMcpActions`, `useSettings`, `useImportExport`, etc.)
|
- **Stage 2**: Extracted custom hooks (`useProviderActions`, `useMcpActions`, `useSettings`, `useImportExport`, etc.)
|
||||||
- **Stage 3**: Component splitting and business logic extraction
|
- **Stage 3**: Component splitting and business logic extraction
|
||||||
- **Stage 4**: Code cleanup and formatting unification
|
- **Stage 4**: Code cleanup and formatting unification
|
||||||
|
|
||||||
**Testing System**:
|
**Testing System**:
|
||||||
|
|
||||||
- Hooks unit tests 100% coverage
|
- Hooks unit tests 100% coverage
|
||||||
- Integration tests covering key processes (App, SettingsDialog, MCP Panel)
|
- Integration tests covering key processes (App, SettingsDialog, MCP Panel)
|
||||||
- MSW mocking backend API to ensure test independence
|
- MSW mocking backend API to ensure test independence
|
||||||
|
|
||||||
**Code Quality**:
|
**Code Quality**:
|
||||||
|
|
||||||
- Unified parameter format: All Tauri commands migrated to camelCase (Tauri 2 specification)
|
- Unified parameter format: All Tauri commands migrated to camelCase (Tauri 2 specification)
|
||||||
- `AppType` renamed to `AppId`: Semantically clearer
|
- `AppType` renamed to `AppId`: Semantically clearer
|
||||||
- Unified parsing with `FromStr` trait: Centralized `app` parameter parsing
|
- Unified parsing with `FromStr` trait: Centralized `app` parameter parsing
|
||||||
@@ -343,7 +98,6 @@ v3.7.0 represents a major evolution from "Provider Switcher" to **"All-in-One AI
|
|||||||
- Remove unused code: `missing_param` helper function, deprecated `tauri-api.ts`, redundant `KimiModelSelector` component
|
- Remove unused code: `missing_param` helper function, deprecated `tauri-api.ts`, redundant `KimiModelSelector` component
|
||||||
|
|
||||||
**Internal Optimizations**:
|
**Internal Optimizations**:
|
||||||
|
|
||||||
- **Removed Legacy Migration Logic**: v3.6 removed v1 config auto-migration and copy file scanning logic
|
- **Removed Legacy Migration Logic**: v3.6 removed v1 config auto-migration and copy file scanning logic
|
||||||
- ✅ **Impact**: Improved startup performance, cleaner code
|
- ✅ **Impact**: Improved startup performance, cleaner code
|
||||||
- ✅ **Compatibility**: v2 format configs fully compatible, no action required
|
- ✅ **Compatibility**: v2 format configs fully compatible, no action required
|
||||||
@@ -607,7 +361,6 @@ For users upgrading from v2.x (Electron version):
|
|||||||
- Basic provider management
|
- Basic provider management
|
||||||
- Claude Code integration
|
- Claude Code integration
|
||||||
- Configuration file handling
|
- Configuration file handling
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### ⚠️ Breaking Changes
|
### ⚠️ Breaking Changes
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
# All-in-One Assistant for Claude Code, Codex & Gemini CLI
|
# Claude Code & Codex Provider Switcher
|
||||||
|
|
||||||
[](https://github.com/farion1231/cc-switch/releases)
|
[](https://github.com/farion1231/cc-switch/releases)
|
||||||
[](https://github.com/trending/typescript)
|
[](https://github.com/trending/typescript)
|
||||||
[](https://github.com/farion1231/cc-switch/releases)
|
[](https://github.com/farion1231/cc-switch/releases)
|
||||||
[](https://tauri.app/)
|
[](https://tauri.app/)
|
||||||
@@ -12,9 +12,7 @@
|
|||||||
|
|
||||||
English | [中文](README_ZH.md) | [Changelog](CHANGELOG.md)
|
English | [中文](README_ZH.md) | [Changelog](CHANGELOG.md)
|
||||||
|
|
||||||
**From Provider Switcher to All-in-One AI CLI Management Platform**
|
A desktop application for managing and switching between different provider configurations & MCP for Claude Code and Codex.
|
||||||
|
|
||||||
Unified management for Claude Code, Codex & Gemini CLI provider configurations, MCP servers, Skills extensions, and system prompts.
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -35,12 +33,6 @@ Get 10% OFF the GLM CODING PLAN with [this link](https://z.ai/subscribe?ic=8JVLJ
|
|||||||
<td width="180"><img src="assets/partners/logos/packycode.png" alt="PackyCode" width="150"></td>
|
<td width="180"><img src="assets/partners/logos/packycode.png" alt="PackyCode" width="150"></td>
|
||||||
<td>Thanks to PackyCode for sponsoring this project! PackyCode is a reliable and efficient API relay service provider, offering relay services for Claude Code, Codex, Gemini, and more. PackyCode provides special discounts for our software users: register using <a href="https://www.packyapi.com/register?aff=cc-switch">this link</a> and enter the "cc-switch" promo code during recharge to get 10% off.</td>
|
<td>Thanks to PackyCode for sponsoring this project! PackyCode is a reliable and efficient API relay service provider, offering relay services for Claude Code, Codex, Gemini, and more. PackyCode provides special discounts for our software users: register using <a href="https://www.packyapi.com/register?aff=cc-switch">this link</a> and enter the "cc-switch" promo code during recharge to get 10% off.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td width="180"><img src="assets/partners/logos/sds-en.png" alt="ShanDianShuo" width="150"></td>
|
|
||||||
<td>Thanks to ShanDianShuo for sponsoring this project! ShanDianShuo is a local-first AI voice input: Millisecond latency, data stays on device, 4x faster than typing, AI-powered correction, Privacy-first, completely free. Doubles your coding efficiency with Claude Code! <a href="https://www.shandianshuo.cn">Free download</a> for Mac/Win</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
@@ -51,49 +43,12 @@ Get 10% OFF the GLM CODING PLAN with [this link](https://z.ai/subscribe?ic=8JVLJ
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
### Current Version: v3.7.0 | [Full Changelog](CHANGELOG.md) | [📋 Release Notes](docs/release-note-v3.7.0-en.md)
|
### Current Version: v3.6.2 | [Full Changelog](CHANGELOG.md)
|
||||||
|
|
||||||
**v3.7.0 Major Update (2025-11-19)**
|
|
||||||
|
|
||||||
**Six Core Features, 18,000+ Lines of New Code**
|
|
||||||
|
|
||||||
- **Gemini CLI Integration**
|
|
||||||
- Third supported AI CLI (Claude Code / Codex / Gemini)
|
|
||||||
- Dual-file configuration support (`.env` + `settings.json`)
|
|
||||||
- Complete MCP server management
|
|
||||||
- Presets: Google Official (OAuth) / PackyCode / Custom
|
|
||||||
|
|
||||||
- **Claude Skills Management System**
|
|
||||||
- Auto-scan skills from GitHub repositories (3 pre-configured curated repos)
|
|
||||||
- One-click install/uninstall to `~/.claude/skills/`
|
|
||||||
- Custom repository support + subdirectory scanning
|
|
||||||
- Complete lifecycle management (discover/install/update)
|
|
||||||
|
|
||||||
- **Prompts Management System**
|
|
||||||
- Multi-preset system prompt management (unlimited presets, quick switching)
|
|
||||||
- Cross-app support (Claude: `CLAUDE.md` / Codex: `AGENTS.md` / Gemini: `GEMINI.md`)
|
|
||||||
- Markdown editor (CodeMirror 6 + real-time preview)
|
|
||||||
- Smart backfill protection, preserves manual modifications
|
|
||||||
|
|
||||||
- **MCP v3.7.0 Unified Architecture**
|
|
||||||
- Single panel manages MCP servers across three applications
|
|
||||||
- New SSE (Server-Sent Events) transport type
|
|
||||||
- Smart JSON parser + Codex TOML format auto-correction
|
|
||||||
- Unified import/export + bidirectional sync
|
|
||||||
|
|
||||||
- **Deep Link Protocol**
|
|
||||||
- `ccswitch://` protocol registration (all platforms)
|
|
||||||
- One-click import provider configs via shared links
|
|
||||||
- Security validation + lifecycle integration
|
|
||||||
|
|
||||||
- **Environment Variable Conflict Detection**
|
|
||||||
- Auto-detect cross-app configuration conflicts (Claude/Codex/Gemini/MCP)
|
|
||||||
- Visual conflict indicators + resolution suggestions
|
|
||||||
- Override warnings + backup before changes
|
|
||||||
|
|
||||||
**Core Capabilities**
|
**Core Capabilities**
|
||||||
|
|
||||||
- **Provider Management**: One-click switching between Claude Code, Codex, and Gemini API configurations
|
- **Provider Management**: One-click switching between Claude Code, Codex, and Gemini API configurations
|
||||||
|
- **MCP Integration**: Centralized MCP server management with stdio/http support and real-time sync
|
||||||
- **Speed Testing**: Measure API endpoint latency with visual quality indicators
|
- **Speed Testing**: Measure API endpoint latency with visual quality indicators
|
||||||
- **Import/Export**: Backup and restore configs with auto-rotation (keep 10 most recent)
|
- **Import/Export**: Backup and restore configs with auto-rotation (keep 10 most recent)
|
||||||
- **i18n Support**: Complete Chinese/English localization (UI, errors, tray)
|
- **i18n Support**: Complete Chinese/English localization (UI, errors, tray)
|
||||||
@@ -106,6 +61,7 @@ Get 10% OFF the GLM CODING PLAN with [this link](https://z.ai/subscribe?ic=8JVLJ
|
|||||||
- Granular model configuration (4-tier: Haiku/Sonnet/Opus/Custom)
|
- Granular model configuration (4-tier: Haiku/Sonnet/Opus/Custom)
|
||||||
- WSL environment support with auto-sync on directory change
|
- WSL environment support with auto-sync on directory change
|
||||||
- 100% hooks test coverage & complete architecture refactoring
|
- 100% hooks test coverage & complete architecture refactoring
|
||||||
|
- New presets: DMXAPI, Azure Codex, AnyRouter, AiHubMix, MiniMax
|
||||||
|
|
||||||
**System Features**
|
**System Features**
|
||||||
|
|
||||||
@@ -147,14 +103,6 @@ Download `CC-Switch-v{version}-macOS.zip` from the [Releases](../../releases) pa
|
|||||||
|
|
||||||
> **Note**: Since the author doesn't have an Apple Developer account, you may see an "unidentified developer" warning on first launch. Please close it first, then go to "System Settings" → "Privacy & Security" → click "Open Anyway", and you'll be able to open it normally afterwards.
|
> **Note**: Since the author doesn't have an Apple Developer account, you may see an "unidentified developer" warning on first launch. Please close it first, then go to "System Settings" → "Privacy & Security" → click "Open Anyway", and you'll be able to open it normally afterwards.
|
||||||
|
|
||||||
### ArchLinux 用户
|
|
||||||
|
|
||||||
**Install via paru (Recommended)**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
paru -S cc-switch-bin
|
|
||||||
```
|
|
||||||
|
|
||||||
### Linux Users
|
### Linux Users
|
||||||
|
|
||||||
Download the latest `CC-Switch-v{version}-Linux.deb` package or `CC-Switch-v{version}-Linux.AppImage` from the [Releases](../../releases) page.
|
Download the latest `CC-Switch-v{version}-Linux.deb` package or `CC-Switch-v{version}-Linux.AppImage` from the [Releases](../../releases) page.
|
||||||
@@ -173,36 +121,9 @@ Download the latest `CC-Switch-v{version}-Linux.deb` package or `CC-Switch-v{ver
|
|||||||
### MCP Management
|
### MCP Management
|
||||||
|
|
||||||
- **Location**: Click "MCP" button in top-right corner
|
- **Location**: Click "MCP" button in top-right corner
|
||||||
- **Add Server**:
|
- **Add Server**: Use built-in templates (mcp-fetch, mcp-filesystem) or custom config
|
||||||
- Use built-in templates (mcp-fetch, mcp-filesystem, etc.)
|
|
||||||
- Support stdio / http / sse transport types
|
|
||||||
- Configure independent MCP servers for different apps
|
|
||||||
- **Enable/Disable**: Toggle switches to control which servers sync to live config
|
- **Enable/Disable**: Toggle switches to control which servers sync to live config
|
||||||
- **Sync**: Enabled servers auto-sync to each app's live files
|
- **Sync**: Enabled servers auto-sync to `~/.claude.json` (Claude) or `~/.codex/config.toml` (Codex)
|
||||||
- **Import/Export**: Import existing MCP servers from Claude/Codex/Gemini config files
|
|
||||||
|
|
||||||
### Skills Management (v3.7.0 New)
|
|
||||||
|
|
||||||
- **Location**: Click "Skills" button in top-right corner
|
|
||||||
- **Discover Skills**:
|
|
||||||
- Auto-scan pre-configured GitHub repositories (Anthropic official, ComposioHQ, community, etc.)
|
|
||||||
- Add custom repositories (supports subdirectory scanning)
|
|
||||||
- **Install Skills**: Click "Install" to one-click install to `~/.claude/skills/`
|
|
||||||
- **Uninstall Skills**: Click "Uninstall" to safely remove and clean up state
|
|
||||||
- **Manage Repositories**: Add/remove custom GitHub repositories
|
|
||||||
|
|
||||||
### Prompts Management (v3.7.0 New)
|
|
||||||
|
|
||||||
- **Location**: Click "Prompts" button in top-right corner
|
|
||||||
- **Create Presets**:
|
|
||||||
- Create unlimited system prompt presets
|
|
||||||
- Use Markdown editor to write prompts (syntax highlighting + real-time preview)
|
|
||||||
- **Switch Presets**: Select preset → Click "Activate" to apply immediately
|
|
||||||
- **Sync Mechanism**:
|
|
||||||
- Claude: `~/.claude/CLAUDE.md`
|
|
||||||
- Codex: `~/.codex/AGENTS.md`
|
|
||||||
- Gemini: `~/.gemini/GEMINI.md`
|
|
||||||
- **Protection Mechanism**: Auto-save current prompt content before switching, preserves manual modifications
|
|
||||||
|
|
||||||
### Configuration Files
|
### Configuration Files
|
||||||
|
|
||||||
@@ -220,15 +141,13 @@ Download the latest `CC-Switch-v{version}-Linux.deb` package or `CC-Switch-v{ver
|
|||||||
|
|
||||||
**Gemini**
|
**Gemini**
|
||||||
|
|
||||||
- Live config: `~/.gemini/.env` (API key) + `~/.gemini/settings.json` (auth mode)
|
- Live config: `~/.gemini/.env` (API key) + `~/.gemini/settings.json` (auth type for quick switching)
|
||||||
- API key field: `GEMINI_API_KEY` or `GOOGLE_GEMINI_API_KEY` in `.env`
|
- API key field: `GEMINI_API_KEY` inside `.env`
|
||||||
- Environment variables: Support `GOOGLE_GEMINI_BASE_URL`, `GEMINI_MODEL`, etc.
|
- Tray quick switch: each provider switch rewrites `~/.gemini/.env` so the Gemini CLI picks up the new credentials immediately
|
||||||
- MCP servers: `~/.gemini/settings.json` → `mcpServers`
|
|
||||||
- Tray quick switch: Each provider switch rewrites `~/.gemini/.env`, no need to restart Gemini CLI
|
|
||||||
|
|
||||||
**CC Switch Storage**
|
**CC Switch Storage**
|
||||||
|
|
||||||
- Main config (SSOT): `~/.cc-switch/config.json` (includes providers, MCP, Prompts presets, etc.)
|
- Main config (SSOT): `~/.cc-switch/config.json`
|
||||||
- Settings: `~/.cc-switch/settings.json`
|
- Settings: `~/.cc-switch/settings.json`
|
||||||
- Backups: `~/.cc-switch/backups/` (auto-rotate, keep 10)
|
- Backups: `~/.cc-switch/backups/` (auto-rotate, keep 10)
|
||||||
|
|
||||||
|
|||||||
+13
-94
@@ -1,8 +1,8 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
# Claude Code / Codex / Gemini CLI 全方位辅助工具
|
# Claude Code & Codex 供应商管理器
|
||||||
|
|
||||||
[](https://github.com/farion1231/cc-switch/releases)
|
[](https://github.com/farion1231/cc-switch/releases)
|
||||||
[](https://github.com/trending/typescript)
|
[](https://github.com/trending/typescript)
|
||||||
[](https://github.com/farion1231/cc-switch/releases)
|
[](https://github.com/farion1231/cc-switch/releases)
|
||||||
[](https://tauri.app/)
|
[](https://tauri.app/)
|
||||||
@@ -10,11 +10,9 @@
|
|||||||
|
|
||||||
<a href="https://trendshift.io/repositories/15372" target="_blank"><img src="https://trendshift.io/api/badge/repositories/15372" alt="farion1231%2Fcc-switch | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
<a href="https://trendshift.io/repositories/15372" target="_blank"><img src="https://trendshift.io/api/badge/repositories/15372" alt="farion1231%2Fcc-switch | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||||
|
|
||||||
[English](README.md) | 中文 | [更新日志](CHANGELOG.md) | [📋 v3.7.0 发布说明](docs/release-note-v3.7.0-zh.md)
|
[English](README.md) | 中文 | [更新日志](CHANGELOG.md)
|
||||||
|
|
||||||
**从供应商切换器到 AI CLI 一体化管理平台**
|
一个用于管理和切换 Claude Code 与 Codex 不同供应商配置、MCP的桌面应用。
|
||||||
|
|
||||||
统一管理 Claude Code、Codex 与 Gemini CLI 的供应商配置、MCP 服务器、Skills 扩展和系统提示词。
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -35,12 +33,6 @@ CC Switch 已经预设了智谱GLM,只需要填写 key 即可一键导入编
|
|||||||
<td width="180"><img src="assets/partners/logos/packycode.png" alt="PackyCode" width="150"></td>
|
<td width="180"><img src="assets/partners/logos/packycode.png" alt="PackyCode" width="150"></td>
|
||||||
<td>感谢 PackyCode 赞助了本项目!PackyCode 是一家稳定、高效的API中转服务商,提供 Claude Code、Codex、Gemini 等多种中转服务。PackyCode 为本软件的用户提供了特别优惠,使用<a href="https://www.packyapi.com/register?aff=cc-switch">此链接</a>注册并在充值时填写"cc-switch"优惠码,可以享受9折优惠。</td>
|
<td>感谢 PackyCode 赞助了本项目!PackyCode 是一家稳定、高效的API中转服务商,提供 Claude Code、Codex、Gemini 等多种中转服务。PackyCode 为本软件的用户提供了特别优惠,使用<a href="https://www.packyapi.com/register?aff=cc-switch">此链接</a>注册并在充值时填写"cc-switch"优惠码,可以享受9折优惠。</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td width="180"><img src="assets/partners/logos/sds-zh.png" alt="ShanDianShuo" width="150"></td>
|
|
||||||
<td>感谢闪电说赞助了本项目!闪电说是本地优先的 AI 语音输入法:毫秒级响应,数据不离设备;打字速度提升 4 倍,AI 智能纠错;绝对隐私安全,完全免费,配合 Claude Code 写代码效率翻倍!支持 Mac/Win 双平台,<a href="https://www.shandianshuo.cn">免费下载</a></td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
## 界面预览
|
## 界面预览
|
||||||
@@ -51,49 +43,12 @@ CC Switch 已经预设了智谱GLM,只需要填写 key 即可一键导入编
|
|||||||
|
|
||||||
## 功能特性
|
## 功能特性
|
||||||
|
|
||||||
### 当前版本:v3.7.0 | [完整更新日志](CHANGELOG.md)
|
### 当前版本:v3.6.2 | [完整更新日志](CHANGELOG.md)
|
||||||
|
|
||||||
**v3.7.0 重大更新(2025-11-19)**
|
|
||||||
|
|
||||||
**六大核心功能,18,000+ 行新增代码**
|
|
||||||
|
|
||||||
- **Gemini CLI 集成**
|
|
||||||
- 第三个支持的 AI CLI(Claude Code / Codex / Gemini)
|
|
||||||
- 双文件配置支持(`.env` + `settings.json`)
|
|
||||||
- 完整 MCP 服务器管理
|
|
||||||
- 预设:Google Official (OAuth) / PackyCode / 自定义
|
|
||||||
|
|
||||||
- **Claude Skills 管理系统**
|
|
||||||
- 从 GitHub 仓库自动扫描技能(预配置 3 个精选仓库)
|
|
||||||
- 一键安装/卸载到 `~/.claude/skills/`
|
|
||||||
- 自定义仓库支持 + 子目录扫描
|
|
||||||
- 完整生命周期管理(发现/安装/更新)
|
|
||||||
|
|
||||||
- **Prompts 管理系统**
|
|
||||||
- 多预设系统提示词管理(无限数量,快速切换)
|
|
||||||
- 跨应用支持(Claude: `CLAUDE.md` / Codex: `AGENTS.md` / Gemini: `GEMINI.md`)
|
|
||||||
- Markdown 编辑器(CodeMirror 6 + 实时预览)
|
|
||||||
- 智能回填保护,保留手动修改
|
|
||||||
|
|
||||||
- **MCP v3.7.0 统一架构**
|
|
||||||
- 单一面板管理三个应用的 MCP 服务器
|
|
||||||
- 新增 SSE (Server-Sent Events) 传输类型
|
|
||||||
- 智能 JSON 解析器 + Codex TOML 格式自动修正
|
|
||||||
- 统一导入/导出 + 双向同步
|
|
||||||
|
|
||||||
- **深度链接协议**
|
|
||||||
- `ccswitch://` 协议注册(全平台)
|
|
||||||
- 通过共享链接一键导入供应商配置
|
|
||||||
- 安全验证 + 生命周期集成
|
|
||||||
|
|
||||||
- **环境变量冲突检测**
|
|
||||||
- 自动检测跨应用配置冲突(Claude/Codex/Gemini/MCP)
|
|
||||||
- 可视化冲突指示器 + 解决建议
|
|
||||||
- 覆盖警告 + 更改前备份
|
|
||||||
|
|
||||||
**核心功能**
|
**核心功能**
|
||||||
|
|
||||||
- **供应商管理**:一键切换 Claude Code、Codex 与 Gemini 的 API 配置
|
- **供应商管理**:一键切换 Claude Code、Codex 与 Gemini 的 API 配置
|
||||||
|
- **MCP 集成**:集中管理 MCP 服务器,支持 stdio/http 类型和实时同步
|
||||||
- **速度测试**:测量 API 端点延迟,可视化连接质量指示器
|
- **速度测试**:测量 API 端点延迟,可视化连接质量指示器
|
||||||
- **导入导出**:备份和恢复配置,自动轮换(保留最近 10 个)
|
- **导入导出**:备份和恢复配置,自动轮换(保留最近 10 个)
|
||||||
- **国际化支持**:完整的中英文本地化(UI、错误、托盘)
|
- **国际化支持**:完整的中英文本地化(UI、错误、托盘)
|
||||||
@@ -106,6 +61,7 @@ CC Switch 已经预设了智谱GLM,只需要填写 key 即可一键导入编
|
|||||||
- 细粒度模型配置(四层:Haiku/Sonnet/Opus/自定义)
|
- 细粒度模型配置(四层:Haiku/Sonnet/Opus/自定义)
|
||||||
- WSL 环境支持,配置目录切换自动同步
|
- WSL 环境支持,配置目录切换自动同步
|
||||||
- 100% hooks 测试覆盖 & 完整架构重构
|
- 100% hooks 测试覆盖 & 完整架构重构
|
||||||
|
- 新增预设:DMXAPI、Azure Codex、AnyRouter、AiHubMix、MiniMax
|
||||||
|
|
||||||
**系统功能**
|
**系统功能**
|
||||||
|
|
||||||
@@ -147,14 +103,6 @@ brew upgrade --cask cc-switch
|
|||||||
|
|
||||||
> **注意**:由于作者没有苹果开发者账号,首次打开可能出现"未知开发者"警告,请先关闭,然后前往"系统设置" → "隐私与安全性" → 点击"仍要打开",之后便可以正常打开
|
> **注意**:由于作者没有苹果开发者账号,首次打开可能出现"未知开发者"警告,请先关闭,然后前往"系统设置" → "隐私与安全性" → 点击"仍要打开",之后便可以正常打开
|
||||||
|
|
||||||
### ArchLinux 用户
|
|
||||||
|
|
||||||
**通过 paru 安装(推荐)**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
paru -S cc-switch-bin
|
|
||||||
```
|
|
||||||
|
|
||||||
### Linux 用户
|
### Linux 用户
|
||||||
|
|
||||||
从 [Releases](../../releases) 页面下载最新版本的 `CC-Switch-v{版本号}-Linux.deb` 包或者 `CC-Switch-v{版本号}-Linux.AppImage` 安装包。
|
从 [Releases](../../releases) 页面下载最新版本的 `CC-Switch-v{版本号}-Linux.deb` 包或者 `CC-Switch-v{版本号}-Linux.AppImage` 安装包。
|
||||||
@@ -173,36 +121,9 @@ paru -S cc-switch-bin
|
|||||||
### MCP 管理
|
### MCP 管理
|
||||||
|
|
||||||
- **位置**:点击右上角"MCP"按钮
|
- **位置**:点击右上角"MCP"按钮
|
||||||
- **添加服务器**:
|
- **添加服务器**:使用内置模板(mcp-fetch、mcp-filesystem)或自定义配置
|
||||||
- 使用内置模板(mcp-fetch、mcp-filesystem 等)
|
|
||||||
- 支持 stdio / http / sse 三种传输类型
|
|
||||||
- 为不同应用配置独立的 MCP 服务器
|
|
||||||
- **启用/禁用**:切换开关以控制哪些服务器同步到 live 配置
|
- **启用/禁用**:切换开关以控制哪些服务器同步到 live 配置
|
||||||
- **同步**:启用的服务器自动同步到各应用的 live 文件
|
- **同步**:启用的服务器自动同步到 `~/.claude.json`(Claude)或 `~/.codex/config.toml`(Codex)
|
||||||
- **导入/导出**:支持从 Claude/Codex/Gemini 配置文件导入现有 MCP 服务器
|
|
||||||
|
|
||||||
### Skills 管理(v3.7.0 新增)
|
|
||||||
|
|
||||||
- **位置**:点击右上角"Skills"按钮
|
|
||||||
- **发现技能**:
|
|
||||||
- 自动扫描预配置的 GitHub 仓库(Anthropic 官方、ComposioHQ、社区等)
|
|
||||||
- 添加自定义仓库(支持子目录扫描)
|
|
||||||
- **安装技能**:点击"安装"一键安装到 `~/.claude/skills/`
|
|
||||||
- **卸载技能**:点击"卸载"安全移除并清理状态
|
|
||||||
- **管理仓库**:添加/删除自定义 GitHub 仓库
|
|
||||||
|
|
||||||
### Prompts 管理(v3.7.0 新增)
|
|
||||||
|
|
||||||
- **位置**:点击右上角"Prompts"按钮
|
|
||||||
- **创建预设**:
|
|
||||||
- 创建无限数量的系统提示词预设
|
|
||||||
- 使用 Markdown 编辑器编写提示词(语法高亮 + 实时预览)
|
|
||||||
- **切换预设**:选择预设 → 点击"激活"立即应用
|
|
||||||
- **同步机制**:
|
|
||||||
- Claude: `~/.claude/CLAUDE.md`
|
|
||||||
- Codex: `~/.codex/AGENTS.md`
|
|
||||||
- Gemini: `~/.gemini/GEMINI.md`
|
|
||||||
- **保护机制**:切换前自动保存当前提示词内容,保留手动修改
|
|
||||||
|
|
||||||
### 配置文件
|
### 配置文件
|
||||||
|
|
||||||
@@ -220,15 +141,13 @@ paru -S cc-switch-bin
|
|||||||
|
|
||||||
**Gemini**
|
**Gemini**
|
||||||
|
|
||||||
- Live 配置:`~/.gemini/.env`(API Key)+ `~/.gemini/settings.json`(保存认证模式)
|
- Live 配置:`~/.gemini/.env`(API Key)+ `~/.gemini/settings.json`(保存认证模式,支持托盘快速切换)
|
||||||
- API key 字段:`.env` 文件中的 `GEMINI_API_KEY` 或 `GOOGLE_GEMINI_API_KEY`
|
- API key 字段:`.env` 文件中的 `GEMINI_API_KEY`
|
||||||
- 环境变量:支持 `GOOGLE_GEMINI_BASE_URL`、`GEMINI_MODEL` 等自定义变量
|
- 托盘快速切换:每次切换供应商都会重写 `~/.gemini/.env`,Gemini CLI 无需额外操作即可使用新配置
|
||||||
- MCP 服务器:`~/.gemini/settings.json` → `mcpServers`
|
|
||||||
- 托盘快速切换:每次切换供应商都会重写 `~/.gemini/.env`,无需重启 Gemini CLI 即可生效
|
|
||||||
|
|
||||||
**CC Switch 存储**
|
**CC Switch 存储**
|
||||||
|
|
||||||
- 主配置(SSOT):`~/.cc-switch/config.json`(包含供应商、MCP、Prompts 预设等)
|
- 主配置(SSOT):`~/.cc-switch/config.json`
|
||||||
- 设置:`~/.cc-switch/settings.json`
|
- 设置:`~/.cc-switch/settings.json`
|
||||||
- 备份:`~/.cc-switch/backups/`(自动轮换,保留 10 个)
|
- 备份:`~/.cc-switch/backups/`(自动轮换,保留 10 个)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 179 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 227 KiB After Width: | Height: | Size: 204 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 227 KiB After Width: | Height: | Size: 205 KiB |
+37
-2201
File diff suppressed because it is too large
Load Diff
@@ -1,439 +0,0 @@
|
|||||||
# CC Switch v3.7.0
|
|
||||||
|
|
||||||
> From Provider Switcher to All-in-One AI CLI Management Platform
|
|
||||||
|
|
||||||
**[中文更新说明 Chinese Documentation →](release-note-v3.7.0-zh.md)**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
CC Switch v3.7.0 introduces six major features with over 18,000 lines of new code.
|
|
||||||
|
|
||||||
**Release Date**: 2025-11-19
|
|
||||||
**Commits**: 85 from v3.6.0
|
|
||||||
**Code Changes**: 152 files, +18,104 / -3,732 lines
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## New Features
|
|
||||||
|
|
||||||
### Gemini CLI Integration
|
|
||||||
|
|
||||||
Complete support for Google Gemini CLI, becoming the third supported application (Claude Code, Codex, Gemini).
|
|
||||||
|
|
||||||
**Core Capabilities**:
|
|
||||||
|
|
||||||
- **Dual-file configuration** - Support for both `.env` and `settings.json` formats
|
|
||||||
- **Auto-detection** - Automatically detect `GOOGLE_GEMINI_BASE_URL`, `GEMINI_MODEL`, etc.
|
|
||||||
- **Full MCP support** - Complete MCP server management for Gemini
|
|
||||||
- **Deep link integration** - Import via `ccswitch://` protocol
|
|
||||||
- **System tray** - Quick-switch from tray menu
|
|
||||||
|
|
||||||
**Provider Presets**:
|
|
||||||
|
|
||||||
- **Google Official** - OAuth authentication support
|
|
||||||
- **PackyCode** - Partner integration
|
|
||||||
- **Custom** - Full customization support
|
|
||||||
|
|
||||||
**Technical Implementation**:
|
|
||||||
|
|
||||||
- New backend modules: `gemini_config.rs` (20KB), `gemini_mcp.rs`
|
|
||||||
- Form synchronization with environment editor
|
|
||||||
- Dual-file atomic writes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### MCP v3.7.0 Unified Architecture
|
|
||||||
|
|
||||||
Complete refactoring of MCP management system for cross-application unification.
|
|
||||||
|
|
||||||
**Architecture Improvements**:
|
|
||||||
|
|
||||||
- **Unified panel** - Single interface for Claude/Codex/Gemini MCP servers
|
|
||||||
- **SSE transport** - New Server-Sent Events support
|
|
||||||
- **Smart parser** - Fault-tolerant JSON parsing
|
|
||||||
- **Format correction** - Auto-fix Codex `[mcp_servers]` format
|
|
||||||
- **Extended fields** - Preserve custom TOML fields
|
|
||||||
|
|
||||||
**User Experience**:
|
|
||||||
|
|
||||||
- Default app selection in forms
|
|
||||||
- JSON formatter for validation
|
|
||||||
- Improved visual hierarchy
|
|
||||||
- Better error messages
|
|
||||||
|
|
||||||
**Import/Export**:
|
|
||||||
|
|
||||||
- Unified import from all three apps
|
|
||||||
- Bidirectional synchronization
|
|
||||||
- State preservation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Claude Skills Management System
|
|
||||||
|
|
||||||
**Approximately 2,000 lines of code** - A complete skill ecosystem platform.
|
|
||||||
|
|
||||||
**GitHub Integration**:
|
|
||||||
|
|
||||||
- Auto-scan skills from GitHub repositories
|
|
||||||
- Pre-configured repos:
|
|
||||||
- `ComposioHQ/awesome-claude-skills` - Curated collection
|
|
||||||
- `anthropics/skills` - Official Anthropic skills
|
|
||||||
- `cexll/myclaude` - Community contributions
|
|
||||||
- Add custom repositories
|
|
||||||
- Subdirectory scanning support (`skillsPath`)
|
|
||||||
|
|
||||||
**Lifecycle Management**:
|
|
||||||
|
|
||||||
- **Discover** - Auto-detect `SKILL.md` files
|
|
||||||
- **Install** - One-click to `~/.claude/skills/`
|
|
||||||
- **Uninstall** - Safe removal with tracking
|
|
||||||
- **Update** - Check for updates (infrastructure ready)
|
|
||||||
|
|
||||||
**Technical Architecture**:
|
|
||||||
|
|
||||||
- **Backend**: `SkillService` (526 lines) with GitHub API integration
|
|
||||||
- **Frontend**: SkillsPage, SkillCard, RepoManager
|
|
||||||
- **UI Components**: Badge, Card, Table (shadcn/ui)
|
|
||||||
- **State**: Persistent storage in `skills.json`
|
|
||||||
- **i18n**: 47+ translation keys
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Prompts Management System
|
|
||||||
|
|
||||||
**Approximately 1,300 lines of code** - Complete system prompt management.
|
|
||||||
|
|
||||||
**Multi-Preset Management**:
|
|
||||||
|
|
||||||
- Create unlimited prompt presets
|
|
||||||
- Quick switch between presets
|
|
||||||
- One active prompt at a time
|
|
||||||
- Delete protection for active prompts
|
|
||||||
|
|
||||||
**Cross-App Support**:
|
|
||||||
|
|
||||||
- **Claude**: `~/.claude/CLAUDE.md`
|
|
||||||
- **Codex**: `~/.codex/AGENTS.md`
|
|
||||||
- **Gemini**: `~/.gemini/GEMINI.md`
|
|
||||||
|
|
||||||
**Markdown Editor**:
|
|
||||||
|
|
||||||
- Full-featured CodeMirror 6 integration
|
|
||||||
- Syntax highlighting
|
|
||||||
- Dark theme (One Dark)
|
|
||||||
- Real-time preview
|
|
||||||
|
|
||||||
**Smart Synchronization**:
|
|
||||||
|
|
||||||
- **Auto-write** - Immediately write to live files
|
|
||||||
- **Backfill protection** - Save current content before switching
|
|
||||||
- **Auto-import** - Import from live files on first launch
|
|
||||||
- **Modification protection** - Preserve manual modifications
|
|
||||||
|
|
||||||
**Technical Implementation**:
|
|
||||||
|
|
||||||
- **Backend**: `PromptService` (213 lines)
|
|
||||||
- **Frontend**: PromptPanel (177), PromptFormModal (160), MarkdownEditor (159)
|
|
||||||
- **Hooks**: usePromptActions (152 lines)
|
|
||||||
- **i18n**: 41+ translation keys
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Deep Link Protocol (ccswitch://)
|
|
||||||
|
|
||||||
One-click provider configuration import via URL scheme.
|
|
||||||
|
|
||||||
**Features**:
|
|
||||||
|
|
||||||
- Protocol registration on all platforms
|
|
||||||
- Import from shared links
|
|
||||||
- Lifecycle integration
|
|
||||||
- Security validation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Environment Variable Conflict Detection
|
|
||||||
|
|
||||||
Intelligent detection and management of configuration conflicts.
|
|
||||||
|
|
||||||
**Detection Scope**:
|
|
||||||
|
|
||||||
- **Claude & Codex** - Cross-app conflicts
|
|
||||||
- **Gemini** - Auto-discovery
|
|
||||||
- **MCP** - Server configuration conflicts
|
|
||||||
|
|
||||||
**Management Features**:
|
|
||||||
|
|
||||||
- Visual conflict indicators
|
|
||||||
- Resolution suggestions
|
|
||||||
- Override warnings
|
|
||||||
- Backup before changes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Improvements
|
|
||||||
|
|
||||||
### Provider Management
|
|
||||||
|
|
||||||
**New Presets**:
|
|
||||||
|
|
||||||
- **DouBaoSeed** - ByteDance's DouBao
|
|
||||||
- **Kimi For Coding** - Moonshot AI
|
|
||||||
- **BaiLing** - BaiLing AI
|
|
||||||
- **Removed AnyRouter** - To avoid confusion
|
|
||||||
|
|
||||||
**Enhancements**:
|
|
||||||
|
|
||||||
- Model name configuration for Codex and Gemini
|
|
||||||
- Provider notes field for organization
|
|
||||||
- Enhanced preset metadata
|
|
||||||
|
|
||||||
### Configuration Management
|
|
||||||
|
|
||||||
- **Common config migration** - From localStorage to `config.json`
|
|
||||||
- **Unified persistence** - Shared across all apps
|
|
||||||
- **Auto-import** - First launch configuration import
|
|
||||||
- **Backfill priority** - Correct handling of live files
|
|
||||||
|
|
||||||
### UI/UX Improvements
|
|
||||||
|
|
||||||
**Design System**:
|
|
||||||
|
|
||||||
- **macOS native** - System-aligned color scheme
|
|
||||||
- **Window centering** - Default centered position
|
|
||||||
- **Visual polish** - Improved spacing and hierarchy
|
|
||||||
|
|
||||||
**Interactions**:
|
|
||||||
|
|
||||||
- **Password input** - Fixed Edge/IE reveal buttons
|
|
||||||
- **URL overflow** - Fixed card overflow
|
|
||||||
- **Error copying** - Copy-to-clipboard errors
|
|
||||||
- **Tray sync** - Real-time drag-and-drop sync
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bug Fixes
|
|
||||||
|
|
||||||
### Critical Fixes
|
|
||||||
|
|
||||||
- **Usage script validation** - Boundary checks
|
|
||||||
- **Gemini validation** - Relaxed constraints
|
|
||||||
- **TOML parsing** - CJK quote handling
|
|
||||||
- **MCP fields** - Custom field preservation
|
|
||||||
- **White screen** - FormLabel crash fix
|
|
||||||
|
|
||||||
### Stability
|
|
||||||
|
|
||||||
- **Tray safety** - Pattern matching instead of unwrap
|
|
||||||
- **Error isolation** - Tray failures don't block operations
|
|
||||||
- **Import classification** - Correct category assignment
|
|
||||||
|
|
||||||
### UI Fixes
|
|
||||||
|
|
||||||
- **Model placeholders** - Removed misleading hints
|
|
||||||
- **Base URL** - Auto-fill for third-party providers
|
|
||||||
- **Drag sort** - Tray menu synchronization
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Technical Improvements
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
**MCP v3.7.0**:
|
|
||||||
|
|
||||||
- Removed legacy code (~1,000 lines)
|
|
||||||
- Unified initialization structure
|
|
||||||
- Backward compatibility maintained
|
|
||||||
- Comprehensive code formatting
|
|
||||||
|
|
||||||
**Platform Compatibility**:
|
|
||||||
|
|
||||||
- Windows winreg API fix (v0.52)
|
|
||||||
- Safe pattern matching (no `unwrap()`)
|
|
||||||
- Cross-platform tray handling
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
|
|
||||||
**Synchronization**:
|
|
||||||
|
|
||||||
- MCP sync across all apps
|
|
||||||
- Gemini form-editor sync
|
|
||||||
- Dual-file reading (.env + settings.json)
|
|
||||||
|
|
||||||
**Validation**:
|
|
||||||
|
|
||||||
- Input boundary checks
|
|
||||||
- TOML quote normalization (CJK)
|
|
||||||
- Custom field preservation
|
|
||||||
- Enhanced error messages
|
|
||||||
|
|
||||||
### Code Quality
|
|
||||||
|
|
||||||
**Type Safety**:
|
|
||||||
|
|
||||||
- Complete TypeScript coverage
|
|
||||||
- Rust type refinements
|
|
||||||
- API contract validation
|
|
||||||
|
|
||||||
**Testing**:
|
|
||||||
|
|
||||||
- Simplified assertions
|
|
||||||
- Better test coverage
|
|
||||||
- Integration test updates
|
|
||||||
|
|
||||||
**Dependencies**:
|
|
||||||
|
|
||||||
- Tauri 2.8.x
|
|
||||||
- Rust: `anyhow`, `zip`, `serde_yaml`, `tempfile`
|
|
||||||
- Frontend: CodeMirror 6 packages
|
|
||||||
- winreg 0.52 (Windows)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Technical Statistics
|
|
||||||
|
|
||||||
```
|
|
||||||
Total Changes:
|
|
||||||
- Commits: 85
|
|
||||||
- Files: 152 changed
|
|
||||||
- Additions: +18,104 lines
|
|
||||||
- Deletions: -3,732 lines
|
|
||||||
|
|
||||||
New Modules:
|
|
||||||
- Skills Management: 2,034 lines (21 files)
|
|
||||||
- Prompts Management: 1,302 lines (20 files)
|
|
||||||
- Gemini Integration: ~1,000 lines
|
|
||||||
- MCP Refactor: ~3,000 lines refactored
|
|
||||||
|
|
||||||
Code Distribution:
|
|
||||||
- Backend (Rust): ~4,500 lines new
|
|
||||||
- Frontend (React): ~3,000 lines new
|
|
||||||
- Configuration: ~1,500 lines refactored
|
|
||||||
- Tests: ~500 lines
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Strategic Positioning
|
|
||||||
|
|
||||||
### From Tool to Platform
|
|
||||||
|
|
||||||
v3.7.0 represents a shift in CC Switch's positioning:
|
|
||||||
|
|
||||||
| Aspect | v3.6 | v3.7.0 |
|
|
||||||
| ----------------- | ------------------------ | ---------------------------- |
|
|
||||||
| **Identity** | Provider Switcher | AI CLI Management Platform |
|
|
||||||
| **Scope** | Configuration Management | Ecosystem Management |
|
|
||||||
| **Applications** | Claude + Codex | Claude + Codex + Gemini |
|
|
||||||
| **Capabilities** | Switch configs | Extend capabilities (Skills) |
|
|
||||||
| **Customization** | Manual editing | Visual management (Prompts) |
|
|
||||||
| **Integration** | Isolated apps | Unified management (MCP) |
|
|
||||||
|
|
||||||
### Six Pillars of AI CLI Management
|
|
||||||
|
|
||||||
1. **Configuration Management** - Provider switching and management
|
|
||||||
2. **Capability Extension** - Skills installation and lifecycle
|
|
||||||
3. **Behavior Customization** - System prompt presets
|
|
||||||
4. **Ecosystem Integration** - Deep links and sharing
|
|
||||||
5. **Multi-AI Support** - Claude/Codex/Gemini
|
|
||||||
6. **Intelligent Detection** - Conflict prevention
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Download & Installation
|
|
||||||
|
|
||||||
### System Requirements
|
|
||||||
|
|
||||||
- **Windows**: Windows 10+
|
|
||||||
- **macOS**: macOS 10.15 (Catalina)+
|
|
||||||
- **Linux**: Ubuntu 22.04+ / Debian 11+ / Fedora 34+
|
|
||||||
|
|
||||||
### Download Links
|
|
||||||
|
|
||||||
Visit [Releases](https://github.com/farion1231/cc-switch/releases/latest) to download:
|
|
||||||
|
|
||||||
- **Windows**: `CC-Switch-v3.7.0-Windows.msi` or `-Portable.zip`
|
|
||||||
- **macOS**: `CC-Switch-v3.7.0-macOS.tar.gz` or `.zip`
|
|
||||||
- **Linux**: `CC-Switch-v3.7.0-Linux.AppImage` or `.deb`
|
|
||||||
|
|
||||||
### Homebrew (macOS)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew tap farion1231/ccswitch
|
|
||||||
brew install --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
Update:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew upgrade --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Migration Notes
|
|
||||||
|
|
||||||
### From v3.6.x
|
|
||||||
|
|
||||||
**Automatic migration** - No action required, configs are fully compatible
|
|
||||||
|
|
||||||
### From v3.1.x or Earlier
|
|
||||||
|
|
||||||
**Two-step migration required**:
|
|
||||||
|
|
||||||
1. First upgrade to v3.2.x (performs one-time migration)
|
|
||||||
2. Then upgrade to v3.7.0
|
|
||||||
|
|
||||||
### New Features
|
|
||||||
|
|
||||||
- **Skills**: No migration needed, start fresh
|
|
||||||
- **Prompts**: Auto-import from live files on first launch
|
|
||||||
- **Gemini**: Install Gemini CLI separately if needed
|
|
||||||
- **MCP v3.7.0**: Backward compatible with previous configs
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Acknowledgments
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
Thanks to all contributors who made this release possible:
|
|
||||||
|
|
||||||
- [@YoVinchen](https://github.com/YoVinchen) - Skills & Prompts & Gemini integration implementation
|
|
||||||
- [@farion1231](https://github.com/farion1231) - From developer to issue responder
|
|
||||||
- Community members for testing and feedback
|
|
||||||
|
|
||||||
### Sponsors
|
|
||||||
|
|
||||||
**Z.ai** - GLM CODING PLAN sponsor
|
|
||||||
[Get 10% OFF with this link](https://z.ai/subscribe?ic=8JVLJQFSKB)
|
|
||||||
|
|
||||||
**PackyCode** - API relay service partner
|
|
||||||
[Register with "cc-switch" code for 10% discount](https://www.packyapi.com/register?aff=cc-switch)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Feedback & Support
|
|
||||||
|
|
||||||
- **Issues**: [GitHub Issues](https://github.com/farion1231/cc-switch/issues)
|
|
||||||
- **Discussions**: [GitHub Discussions](https://github.com/farion1231/cc-switch/discussions)
|
|
||||||
- **Documentation**: [README](../README.md)
|
|
||||||
- **Changelog**: [CHANGELOG.md](../CHANGELOG.md)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What's Next
|
|
||||||
|
|
||||||
**v3.8.0 Preview** (Tentative):
|
|
||||||
|
|
||||||
- Local proxy functionality
|
|
||||||
|
|
||||||
Stay tuned for more updates!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Happy Coding!**
|
|
||||||
@@ -1,435 +0,0 @@
|
|||||||
# CC Switch v3.7.0
|
|
||||||
|
|
||||||
> 从供应商切换器到 AI CLI 一体化管理平台
|
|
||||||
|
|
||||||
**[English Version →](release-note-v3.7.0-en.md)**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 概览
|
|
||||||
|
|
||||||
CC Switch v3.7.0 新增六大核心功能,新增超过 18,000 行代码。
|
|
||||||
|
|
||||||
**发布日期**:2025-11-19
|
|
||||||
**提交数量**:从 v3.6.0 开始 85 个提交
|
|
||||||
**代码变更**:152 个文件,+18,104 / -3,732 行
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 新增功能
|
|
||||||
|
|
||||||
### Gemini CLI 集成
|
|
||||||
|
|
||||||
完整支持 Google Gemini CLI,成为第三个支持的应用(Claude Code、Codex、Gemini)。
|
|
||||||
|
|
||||||
**核心能力**:
|
|
||||||
|
|
||||||
- **双文件配置** - 同时支持 `.env` 和 `settings.json` 格式
|
|
||||||
- **自动检测** - 自动检测 `GOOGLE_GEMINI_BASE_URL`、`GEMINI_MODEL` 等环境变量
|
|
||||||
- **完整 MCP 支持** - 为 Gemini 提供完整的 MCP 服务器管理
|
|
||||||
- **深度链接集成** - 通过 `ccswitch://` 协议导入配置
|
|
||||||
- **系统托盘** - 从托盘菜单快速切换
|
|
||||||
|
|
||||||
**供应商预设**:
|
|
||||||
|
|
||||||
- **Google Official** - 支持 OAuth 认证
|
|
||||||
- **PackyCode** - 合作伙伴集成
|
|
||||||
- **自定义** - 完全自定义支持
|
|
||||||
|
|
||||||
**技术实现**:
|
|
||||||
|
|
||||||
- 新增后端模块:`gemini_config.rs`(20KB)、`gemini_mcp.rs`
|
|
||||||
- 表单与环境编辑器同步
|
|
||||||
- 双文件原子写入
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### MCP v3.7.0 统一架构
|
|
||||||
|
|
||||||
MCP 管理系统完整重构,实现跨应用统一管理。
|
|
||||||
|
|
||||||
**架构改进**:
|
|
||||||
|
|
||||||
- **统一管理面板** - 单一界面管理 Claude/Codex/Gemini MCP 服务器
|
|
||||||
- **SSE 传输类型** - 新增 Server-Sent Events 支持
|
|
||||||
- **智能解析器** - 容错性 JSON 解析
|
|
||||||
- **格式修正** - 自动修复 Codex `[mcp_servers]` 格式
|
|
||||||
- **扩展字段** - 保留自定义 TOML 字段
|
|
||||||
|
|
||||||
**用户体验**:
|
|
||||||
|
|
||||||
- 表单中的默认应用选择
|
|
||||||
- JSON 格式化器用于验证
|
|
||||||
- 改进的视觉层次
|
|
||||||
- 更好的错误消息
|
|
||||||
|
|
||||||
**导入/导出**:
|
|
||||||
|
|
||||||
- 统一从三个应用导入
|
|
||||||
- 双向同步
|
|
||||||
- 状态保持
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Claude Skills 管理系统
|
|
||||||
|
|
||||||
**约 2,000 行代码** - 完整的技能生态平台。
|
|
||||||
|
|
||||||
**GitHub 集成**:
|
|
||||||
|
|
||||||
- 从 GitHub 仓库自动扫描技能
|
|
||||||
- 预配置仓库:
|
|
||||||
- `ComposioHQ/awesome-claude-skills` - 精选集合
|
|
||||||
- `anthropics/skills` - Anthropic 官方技能
|
|
||||||
- `cexll/myclaude` - 社区贡献
|
|
||||||
- 添加自定义仓库
|
|
||||||
- 子目录扫描支持(`skillsPath`)
|
|
||||||
|
|
||||||
**生命周期管理**:
|
|
||||||
|
|
||||||
- **发现** - 自动检测 `SKILL.md` 文件
|
|
||||||
- **安装** - 一键安装到 `~/.claude/skills/`
|
|
||||||
- **卸载** - 安全移除并跟踪状态
|
|
||||||
- **更新** - 检查更新(基础设施已就绪)
|
|
||||||
|
|
||||||
**技术架构**:
|
|
||||||
|
|
||||||
- **后端**:`SkillService`(526 行)集成 GitHub API
|
|
||||||
- **前端**:SkillsPage、SkillCard、RepoManager
|
|
||||||
- **UI 组件**:Badge、Card、Table(shadcn/ui)
|
|
||||||
- **状态**:持久化存储在 `skills.json`
|
|
||||||
- **国际化**:47+ 个翻译键
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Prompts 管理系统
|
|
||||||
|
|
||||||
**约 1,300 行代码** - 完整的系统提示词管理。
|
|
||||||
|
|
||||||
**多预设管理**:
|
|
||||||
|
|
||||||
- 创建无限数量的提示词预设
|
|
||||||
- 快速在预设间切换
|
|
||||||
- 同时只能激活一个提示词
|
|
||||||
- 活动提示词删除保护
|
|
||||||
|
|
||||||
**跨应用支持**:
|
|
||||||
|
|
||||||
- **Claude**:`~/.claude/CLAUDE.md`
|
|
||||||
- **Codex**:`~/.codex/AGENTS.md`
|
|
||||||
- **Gemini**:`~/.gemini/GEMINI.md`
|
|
||||||
|
|
||||||
**Markdown 编辑器**:
|
|
||||||
|
|
||||||
- 完整的 CodeMirror 6 集成
|
|
||||||
- 语法高亮
|
|
||||||
- 暗色主题(One Dark)
|
|
||||||
- 实时预览
|
|
||||||
|
|
||||||
**智能同步**:
|
|
||||||
|
|
||||||
- **自动写入** - 立即写入 live 文件
|
|
||||||
- **回填保护** - 切换前保存当前内容
|
|
||||||
- **自动导入** - 首次启动从 live 文件导入
|
|
||||||
- **修改保护** - 保留手动修改
|
|
||||||
|
|
||||||
**技术实现**:
|
|
||||||
|
|
||||||
- **后端**:`PromptService`(213 行)
|
|
||||||
- **前端**:PromptPanel(177)、PromptFormModal(160)、MarkdownEditor(159)
|
|
||||||
- **Hooks**:usePromptActions(152 行)
|
|
||||||
- **国际化**:41+ 个翻译键
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 深度链接协议(ccswitch://)
|
|
||||||
|
|
||||||
通过 URL 方案一键导入供应商配置。
|
|
||||||
|
|
||||||
**功能特性**:
|
|
||||||
|
|
||||||
- 所有平台的协议注册
|
|
||||||
- 从共享链接导入
|
|
||||||
- 生命周期集成
|
|
||||||
- 安全验证
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 环境变量冲突检测
|
|
||||||
|
|
||||||
智能检测和管理配置冲突。
|
|
||||||
|
|
||||||
**检测范围**:
|
|
||||||
|
|
||||||
- **Claude & Codex** - 跨应用冲突
|
|
||||||
- **Gemini** - 自动发现
|
|
||||||
- **MCP** - 服务器配置冲突
|
|
||||||
|
|
||||||
**管理功能**:
|
|
||||||
|
|
||||||
- 可视化冲突指示器
|
|
||||||
- 解决建议
|
|
||||||
- 覆盖警告
|
|
||||||
- 更改前备份
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 改进优化
|
|
||||||
|
|
||||||
### 供应商管理
|
|
||||||
|
|
||||||
**新增预设**:
|
|
||||||
|
|
||||||
- **DouBaoSeed** - 字节跳动的豆包
|
|
||||||
- **Kimi For Coding** - 月之暗面
|
|
||||||
- **BaiLing** - 百灵 AI
|
|
||||||
- **移除 AnyRouter** - 避免误导
|
|
||||||
|
|
||||||
**增强功能**:
|
|
||||||
|
|
||||||
- Codex 和 Gemini 的模型名称配置
|
|
||||||
- 供应商备注字段用于组织
|
|
||||||
- 增强的预设元数据
|
|
||||||
|
|
||||||
### 配置管理
|
|
||||||
|
|
||||||
- **通用配置迁移** - 从 localStorage 迁移到 `config.json`
|
|
||||||
- **统一持久化** - 跨所有应用共享
|
|
||||||
- **自动导入** - 首次启动配置导入
|
|
||||||
- **回填优先级** - 正确处理 live 文件
|
|
||||||
|
|
||||||
### UI/UX 改进
|
|
||||||
|
|
||||||
**设计系统**:
|
|
||||||
|
|
||||||
- **macOS 原生** - 与系统对齐的配色方案
|
|
||||||
- **窗口居中** - 默认居中位置
|
|
||||||
- **视觉优化** - 改进的间距和层次
|
|
||||||
|
|
||||||
**交互优化**:
|
|
||||||
|
|
||||||
- **密码输入** - 修复 Edge/IE 显示按钮
|
|
||||||
- **URL 溢出** - 修复卡片溢出
|
|
||||||
- **错误复制** - 可复制到剪贴板的错误
|
|
||||||
- **托盘同步** - 实时拖放同步
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bug 修复
|
|
||||||
|
|
||||||
### 关键修复
|
|
||||||
|
|
||||||
- **用量脚本验证** - 边界检查
|
|
||||||
- **Gemini 验证** - 放宽约束
|
|
||||||
- **TOML 解析** - CJK 引号处理
|
|
||||||
- **MCP 字段** - 自定义字段保留
|
|
||||||
- **白屏** - FormLabel 崩溃修复
|
|
||||||
|
|
||||||
### 稳定性
|
|
||||||
|
|
||||||
- **托盘安全** - 模式匹配替代 unwrap
|
|
||||||
- **错误隔离** - 托盘失败不阻塞操作
|
|
||||||
- **导入分类** - 正确的类别分配
|
|
||||||
|
|
||||||
### UI 修复
|
|
||||||
|
|
||||||
- **模型占位符** - 移除误导性提示
|
|
||||||
- **Base URL** - 第三方供应商自动填充
|
|
||||||
- **拖拽排序** - 托盘菜单同步
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 技术改进
|
|
||||||
|
|
||||||
### 架构
|
|
||||||
|
|
||||||
**MCP v3.7.0**:
|
|
||||||
|
|
||||||
- 移除遗留代码(约 1,000 行)
|
|
||||||
- 统一初始化结构
|
|
||||||
- 保持向后兼容性
|
|
||||||
- 全面的代码格式化
|
|
||||||
|
|
||||||
**平台兼容性**:
|
|
||||||
|
|
||||||
- Windows winreg API 修复(v0.52)
|
|
||||||
- 安全模式匹配(无 `unwrap()`)
|
|
||||||
- 跨平台托盘处理
|
|
||||||
|
|
||||||
### 配置
|
|
||||||
|
|
||||||
**同步机制**:
|
|
||||||
|
|
||||||
- 跨所有应用的 MCP 同步
|
|
||||||
- Gemini 表单-编辑器同步
|
|
||||||
- 双文件读取(.env + settings.json)
|
|
||||||
|
|
||||||
**验证增强**:
|
|
||||||
|
|
||||||
- 输入边界检查
|
|
||||||
- TOML 引号规范化(CJK)
|
|
||||||
- 自定义字段保留
|
|
||||||
- 增强的错误消息
|
|
||||||
|
|
||||||
### 代码质量
|
|
||||||
|
|
||||||
**类型安全**:
|
|
||||||
|
|
||||||
- 完整的 TypeScript 覆盖
|
|
||||||
- Rust 类型改进
|
|
||||||
- API 契约验证
|
|
||||||
|
|
||||||
**测试**:
|
|
||||||
|
|
||||||
- 简化的断言
|
|
||||||
- 更好的测试覆盖
|
|
||||||
- 集成测试更新
|
|
||||||
|
|
||||||
**依赖项**:
|
|
||||||
|
|
||||||
- Tauri 2.8.x
|
|
||||||
- Rust:`anyhow`、`zip`、`serde_yaml`、`tempfile`
|
|
||||||
- 前端:CodeMirror 6 包
|
|
||||||
- winreg 0.52(Windows)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 技术统计
|
|
||||||
|
|
||||||
```
|
|
||||||
总体变更:
|
|
||||||
- 提交数:85
|
|
||||||
- 文件数:152 个文件变更
|
|
||||||
- 新增:+18,104 行
|
|
||||||
- 删除:-3,732 行
|
|
||||||
|
|
||||||
新增模块:
|
|
||||||
- Skills 管理:2,034 行(21 个文件)
|
|
||||||
- Prompts 管理:1,302 行(20 个文件)
|
|
||||||
- Gemini 集成:约 1,000 行
|
|
||||||
- MCP 重构:约 3,000 行重构
|
|
||||||
|
|
||||||
代码分布:
|
|
||||||
- 后端(Rust):约 4,500 行新增
|
|
||||||
- 前端(React):约 3,000 行新增
|
|
||||||
- 配置:约 1,500 行重构
|
|
||||||
- 测试:约 500 行
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 战略定位
|
|
||||||
|
|
||||||
### 从工具到平台
|
|
||||||
|
|
||||||
v3.7.0 代表了 CC Switch 定位的转变:
|
|
||||||
|
|
||||||
| 方面 | v3.6 | v3.7.0 |
|
|
||||||
| -------- | -------------- | ----------------------- |
|
|
||||||
| **身份** | 供应商切换器 | AI CLI 管理平台 |
|
|
||||||
| **范围** | 配置管理 | 生态系统管理 |
|
|
||||||
| **应用** | Claude + Codex | Claude + Codex + Gemini |
|
|
||||||
| **能力** | 切换配置 | 扩展能力(Skills) |
|
|
||||||
| **定制** | 手动编辑 | 可视化管理(Prompts) |
|
|
||||||
| **集成** | 孤立应用 | 统一管理(MCP) |
|
|
||||||
|
|
||||||
### AI CLI 管理六大支柱
|
|
||||||
|
|
||||||
1. **配置管理** - 供应商切换和管理
|
|
||||||
2. **能力扩展** - Skills 安装和生命周期
|
|
||||||
3. **行为定制** - 系统提示词预设
|
|
||||||
4. **生态集成** - 深度链接和共享
|
|
||||||
5. **多 AI 支持** - Claude/Codex/Gemini
|
|
||||||
6. **智能检测** - 冲突预防
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 下载与安装
|
|
||||||
|
|
||||||
### 系统要求
|
|
||||||
|
|
||||||
- **Windows**:Windows 10+
|
|
||||||
- **macOS**:macOS 10.15(Catalina)+
|
|
||||||
- **Linux**:Ubuntu 22.04+ / Debian 11+ / Fedora 34+
|
|
||||||
|
|
||||||
### 下载链接
|
|
||||||
|
|
||||||
访问 [Releases](https://github.com/farion1231/cc-switch/releases/latest) 下载:
|
|
||||||
|
|
||||||
- **Windows**:`CC-Switch-v3.7.0-Windows.msi` 或 `-Portable.zip`
|
|
||||||
- **macOS**:`CC-Switch-v3.7.0-macOS.tar.gz` 或 `.zip`
|
|
||||||
- **Linux**:`CC-Switch-v3.7.0-Linux.AppImage` 或 `.deb`
|
|
||||||
|
|
||||||
### Homebrew(macOS)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew tap farion1231/ccswitch
|
|
||||||
brew install --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
更新:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew upgrade --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 迁移说明
|
|
||||||
|
|
||||||
### 从 v3.6.x 升级
|
|
||||||
|
|
||||||
**自动迁移** - 无需任何操作,配置完全兼容
|
|
||||||
|
|
||||||
### 从 v3.1.x 或更早版本升级
|
|
||||||
|
|
||||||
**需要两步迁移**:
|
|
||||||
|
|
||||||
1. 首先升级到 v3.2.x(执行一次性迁移)
|
|
||||||
2. 然后升级到 v3.7.0
|
|
||||||
|
|
||||||
### 新功能
|
|
||||||
|
|
||||||
- **Skills**:无需迁移,全新开始
|
|
||||||
- **Prompts**:首次启动时从 live 文件自动导入
|
|
||||||
- **Gemini**:需要单独安装 Gemini CLI
|
|
||||||
- **MCP v3.7.0**:与之前的配置向后兼容
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 致谢
|
|
||||||
|
|
||||||
### 贡献者
|
|
||||||
|
|
||||||
感谢所有让这个版本成为可能的贡献者:
|
|
||||||
|
|
||||||
- [@YoVinchen](https://github.com/YoVinchen) - Skills & Prompts & Geimini 集成实现
|
|
||||||
- [@farion1231](https://github.com/farion1231) - 从开发沦为 issue 回复机
|
|
||||||
- 社区成员的测试和反馈
|
|
||||||
|
|
||||||
### 赞助商
|
|
||||||
|
|
||||||
**Z.ai** - GLM CODING PLAN 赞助商
|
|
||||||
[通过此链接获得 10% 折扣](https://z.ai/subscribe?ic=8JVLJQFSKB)
|
|
||||||
|
|
||||||
**PackyCode** - API 中继服务合作伙伴
|
|
||||||
[使用 "cc-switch" 代码注册可享受 10% 折扣](https://www.packyapi.com/register?aff=cc-switch)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 反馈与支持
|
|
||||||
|
|
||||||
- **问题反馈**:[GitHub Issues](https://github.com/farion1231/cc-switch/issues)
|
|
||||||
- **讨论**:[GitHub Discussions](https://github.com/farion1231/cc-switch/discussions)
|
|
||||||
- **文档**:[README](../README_ZH.md)
|
|
||||||
- **更新日志**:[CHANGELOG.md](../CHANGELOG.md)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 未来展望
|
|
||||||
|
|
||||||
**v3.8.0 预览**(暂定):
|
|
||||||
|
|
||||||
- 本地代理功能
|
|
||||||
|
|
||||||
敬请期待更多更新!
|
|
||||||
@@ -1,481 +0,0 @@
|
|||||||
# CC Switch v3.7.1
|
|
||||||
|
|
||||||
> Stability Enhancements and User Experience Improvements
|
|
||||||
|
|
||||||
**[中文更新说明 Chinese Documentation →](release-note-v3.7.1-zh.md)**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## v3.7.1 Updates
|
|
||||||
|
|
||||||
**Release Date**: 2025-11-22
|
|
||||||
**Code Changes**: 17 files, +524 / -81 lines
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
- **Fix Third-Party Skills Installation Failure** (#268)
|
|
||||||
Fixed installation issues for skills repositories with custom subdirectories, now supports repos like `ComposioHQ/awesome-claude-skills` with subdirectories
|
|
||||||
|
|
||||||
- **Fix Gemini Configuration Persistence Issue**
|
|
||||||
Resolved the issue where settings.json edits in Gemini form were lost when switching providers
|
|
||||||
|
|
||||||
- **Prevent Dialogs from Closing on Overlay Click**
|
|
||||||
Added protection against clicking overlay/backdrop, preventing accidental form data loss across all 11 dialog components
|
|
||||||
|
|
||||||
### New Features
|
|
||||||
|
|
||||||
- **Gemini Configuration Directory Support** (#255)
|
|
||||||
Added Gemini configuration directory option in settings, supports customizing `~/.gemini/` path
|
|
||||||
|
|
||||||
- **ArchLinux Installation Support** (#259)
|
|
||||||
Added AUR installation method: `paru -S cc-switch-bin`
|
|
||||||
|
|
||||||
### Improvements
|
|
||||||
|
|
||||||
- **Skills Error Message i18n Enhancement**
|
|
||||||
Added 28+ detailed error messages (English & Chinese) with specific resolution suggestions, extended download timeout from 15s to 60s
|
|
||||||
|
|
||||||
- **Code Formatting**
|
|
||||||
Applied unified Rust and TypeScript code formatting standards
|
|
||||||
|
|
||||||
### Download
|
|
||||||
|
|
||||||
Visit [Releases](https://github.com/farion1231/cc-switch/releases/latest) to download the latest version
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## v3.7.0 Complete Release Notes
|
|
||||||
|
|
||||||
> From Provider Switcher to All-in-One AI CLI Management Platform
|
|
||||||
|
|
||||||
**Release Date**: 2025-11-19
|
|
||||||
**Commits**: 85 from v3.6.0
|
|
||||||
**Code Changes**: 152 files, +18,104 / -3,732 lines
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## New Features
|
|
||||||
|
|
||||||
### Gemini CLI Integration
|
|
||||||
|
|
||||||
Complete support for Google Gemini CLI, becoming the third supported application (Claude Code, Codex, Gemini).
|
|
||||||
|
|
||||||
**Core Capabilities**:
|
|
||||||
|
|
||||||
- **Dual-file configuration** - Support for both `.env` and `settings.json` formats
|
|
||||||
- **Auto-detection** - Automatically detect `GOOGLE_GEMINI_BASE_URL`, `GEMINI_MODEL`, etc.
|
|
||||||
- **Full MCP support** - Complete MCP server management for Gemini
|
|
||||||
- **Deep link integration** - Import via `ccswitch://` protocol
|
|
||||||
- **System tray** - Quick-switch from tray menu
|
|
||||||
|
|
||||||
**Provider Presets**:
|
|
||||||
|
|
||||||
- **Google Official** - OAuth authentication support
|
|
||||||
- **PackyCode** - Partner integration
|
|
||||||
- **Custom** - Full customization support
|
|
||||||
|
|
||||||
**Technical Implementation**:
|
|
||||||
|
|
||||||
- New backend modules: `gemini_config.rs` (20KB), `gemini_mcp.rs`
|
|
||||||
- Form synchronization with environment editor
|
|
||||||
- Dual-file atomic writes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### MCP v3.7.0 Unified Architecture
|
|
||||||
|
|
||||||
Complete refactoring of MCP management system for cross-application unification.
|
|
||||||
|
|
||||||
**Architecture Improvements**:
|
|
||||||
|
|
||||||
- **Unified panel** - Single interface for Claude/Codex/Gemini MCP servers
|
|
||||||
- **SSE transport** - New Server-Sent Events support
|
|
||||||
- **Smart parser** - Fault-tolerant JSON parsing
|
|
||||||
- **Format correction** - Auto-fix Codex `[mcp_servers]` format
|
|
||||||
- **Extended fields** - Preserve custom TOML fields
|
|
||||||
|
|
||||||
**User Experience**:
|
|
||||||
|
|
||||||
- Default app selection in forms
|
|
||||||
- JSON formatter for validation
|
|
||||||
- Improved visual hierarchy
|
|
||||||
- Better error messages
|
|
||||||
|
|
||||||
**Import/Export**:
|
|
||||||
|
|
||||||
- Unified import from all three apps
|
|
||||||
- Bidirectional synchronization
|
|
||||||
- State preservation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Claude Skills Management System
|
|
||||||
|
|
||||||
**Approximately 2,000 lines of code** - A complete skill ecosystem platform.
|
|
||||||
|
|
||||||
**GitHub Integration**:
|
|
||||||
|
|
||||||
- Auto-scan skills from GitHub repositories
|
|
||||||
- Pre-configured repos:
|
|
||||||
- `ComposioHQ/awesome-claude-skills` - Curated collection
|
|
||||||
- `anthropics/skills` - Official Anthropic skills
|
|
||||||
- `cexll/myclaude` - Community contributions
|
|
||||||
- Add custom repositories
|
|
||||||
- Subdirectory scanning support (`skillsPath`)
|
|
||||||
|
|
||||||
**Lifecycle Management**:
|
|
||||||
|
|
||||||
- **Discover** - Auto-detect `SKILL.md` files
|
|
||||||
- **Install** - One-click to `~/.claude/skills/`
|
|
||||||
- **Uninstall** - Safe removal with tracking
|
|
||||||
- **Update** - Check for updates (infrastructure ready)
|
|
||||||
|
|
||||||
**Technical Architecture**:
|
|
||||||
|
|
||||||
- **Backend**: `SkillService` (526 lines) with GitHub API integration
|
|
||||||
- **Frontend**: SkillsPage, SkillCard, RepoManager
|
|
||||||
- **UI Components**: Badge, Card, Table (shadcn/ui)
|
|
||||||
- **State**: Persistent storage in `config.json`
|
|
||||||
- **i18n**: 47+ translation keys
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Prompts Management System
|
|
||||||
|
|
||||||
**Approximately 1,300 lines of code** - Complete system prompt management.
|
|
||||||
|
|
||||||
**Multi-Preset Management**:
|
|
||||||
|
|
||||||
- Create unlimited prompt presets
|
|
||||||
- Quick switch between presets
|
|
||||||
- One active prompt at a time
|
|
||||||
- Delete protection for active prompts
|
|
||||||
|
|
||||||
**Cross-App Support**:
|
|
||||||
|
|
||||||
- **Claude**: `~/.claude/CLAUDE.md`
|
|
||||||
- **Codex**: `~/.codex/AGENTS.md`
|
|
||||||
- **Gemini**: `~/.gemini/GEMINI.md`
|
|
||||||
|
|
||||||
**Markdown Editor**:
|
|
||||||
|
|
||||||
- Full-featured CodeMirror 6 integration
|
|
||||||
- Syntax highlighting
|
|
||||||
- Dark theme (One Dark)
|
|
||||||
- Real-time preview
|
|
||||||
|
|
||||||
**Smart Synchronization**:
|
|
||||||
|
|
||||||
- **Auto-write** - Immediately write to live files
|
|
||||||
- **Backfill protection** - Save current content before switching
|
|
||||||
- **Auto-import** - Import from live files on first launch
|
|
||||||
- **Modification protection** - Preserve manual modifications
|
|
||||||
|
|
||||||
**Technical Implementation**:
|
|
||||||
|
|
||||||
- **Backend**: `PromptService` (213 lines)
|
|
||||||
- **Frontend**: PromptPanel (177), PromptFormModal (160), MarkdownEditor (159)
|
|
||||||
- **Hooks**: usePromptActions (152 lines)
|
|
||||||
- **i18n**: 41+ translation keys
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Deep Link Protocol (ccswitch://)
|
|
||||||
|
|
||||||
One-click provider configuration import via URL scheme.
|
|
||||||
|
|
||||||
**Features**:
|
|
||||||
|
|
||||||
- Protocol registration on all platforms
|
|
||||||
- Import from shared links
|
|
||||||
- Lifecycle integration
|
|
||||||
- Security validation
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Environment Variable Conflict Detection
|
|
||||||
|
|
||||||
Intelligent detection and management of configuration conflicts.
|
|
||||||
|
|
||||||
**Detection Scope**:
|
|
||||||
|
|
||||||
- **Claude & Codex** - Cross-app conflicts
|
|
||||||
- **Gemini** - Auto-discovery
|
|
||||||
- **MCP** - Server configuration conflicts
|
|
||||||
|
|
||||||
**Management Features**:
|
|
||||||
|
|
||||||
- Visual conflict indicators
|
|
||||||
- Resolution suggestions
|
|
||||||
- Override warnings
|
|
||||||
- Backup before changes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Improvements
|
|
||||||
|
|
||||||
### Provider Management
|
|
||||||
|
|
||||||
**New Presets**:
|
|
||||||
|
|
||||||
- **DouBaoSeed** - ByteDance's DouBao
|
|
||||||
- **Kimi For Coding** - Moonshot AI
|
|
||||||
- **BaiLing** - BaiLing AI
|
|
||||||
- **Removed AnyRouter** - To avoid confusion
|
|
||||||
|
|
||||||
**Enhancements**:
|
|
||||||
|
|
||||||
- Model name configuration for Codex and Gemini
|
|
||||||
- Provider notes field for organization
|
|
||||||
- Enhanced preset metadata
|
|
||||||
|
|
||||||
### Configuration Management
|
|
||||||
|
|
||||||
- **Common config migration** - From localStorage to `config.json`
|
|
||||||
- **Unified persistence** - Shared across all apps
|
|
||||||
- **Auto-import** - First launch configuration import
|
|
||||||
- **Backfill priority** - Correct handling of live files
|
|
||||||
|
|
||||||
### UI/UX Improvements
|
|
||||||
|
|
||||||
**Design System**:
|
|
||||||
|
|
||||||
- **macOS native** - System-aligned color scheme
|
|
||||||
- **Window centering** - Default centered position
|
|
||||||
- **Visual polish** - Improved spacing and hierarchy
|
|
||||||
|
|
||||||
**Interactions**:
|
|
||||||
|
|
||||||
- **Password input** - Fixed Edge/IE reveal buttons
|
|
||||||
- **URL overflow** - Fixed card overflow
|
|
||||||
- **Error copying** - Copy-to-clipboard errors
|
|
||||||
- **Tray sync** - Real-time drag-and-drop sync
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bug Fixes
|
|
||||||
|
|
||||||
### Critical Fixes
|
|
||||||
|
|
||||||
- **Usage script validation** - Boundary checks
|
|
||||||
- **Gemini validation** - Relaxed constraints
|
|
||||||
- **TOML parsing** - CJK quote handling
|
|
||||||
- **MCP fields** - Custom field preservation
|
|
||||||
- **White screen** - FormLabel crash fix
|
|
||||||
|
|
||||||
### Stability
|
|
||||||
|
|
||||||
- **Tray safety** - Pattern matching instead of unwrap
|
|
||||||
- **Error isolation** - Tray failures don't block operations
|
|
||||||
- **Import classification** - Correct category assignment
|
|
||||||
|
|
||||||
### UI Fixes
|
|
||||||
|
|
||||||
- **Model placeholders** - Removed misleading hints
|
|
||||||
- **Base URL** - Auto-fill for third-party providers
|
|
||||||
- **Drag sort** - Tray menu synchronization
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Technical Improvements
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
**MCP v3.7.0**:
|
|
||||||
|
|
||||||
- Removed legacy code (~1,000 lines)
|
|
||||||
- Unified initialization structure
|
|
||||||
- Backward compatibility maintained
|
|
||||||
- Comprehensive code formatting
|
|
||||||
|
|
||||||
**Platform Compatibility**:
|
|
||||||
|
|
||||||
- Windows winreg API fix (v0.52)
|
|
||||||
- Safe pattern matching (no `unwrap()`)
|
|
||||||
- Cross-platform tray handling
|
|
||||||
|
|
||||||
### Configuration
|
|
||||||
|
|
||||||
**Synchronization**:
|
|
||||||
|
|
||||||
- MCP sync across all apps
|
|
||||||
- Gemini form-editor sync
|
|
||||||
- Dual-file reading (.env + settings.json)
|
|
||||||
|
|
||||||
**Validation**:
|
|
||||||
|
|
||||||
- Input boundary checks
|
|
||||||
- TOML quote normalization (CJK)
|
|
||||||
- Custom field preservation
|
|
||||||
- Enhanced error messages
|
|
||||||
|
|
||||||
### Code Quality
|
|
||||||
|
|
||||||
**Type Safety**:
|
|
||||||
|
|
||||||
- Complete TypeScript coverage
|
|
||||||
- Rust type refinements
|
|
||||||
- API contract validation
|
|
||||||
|
|
||||||
**Testing**:
|
|
||||||
|
|
||||||
- Simplified assertions
|
|
||||||
- Better test coverage
|
|
||||||
- Integration test updates
|
|
||||||
|
|
||||||
**Dependencies**:
|
|
||||||
|
|
||||||
- Tauri 2.8.x
|
|
||||||
- Rust: `anyhow`, `zip`, `serde_yaml`, `tempfile`
|
|
||||||
- Frontend: CodeMirror 6 packages
|
|
||||||
- winreg 0.52 (Windows)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Technical Statistics
|
|
||||||
|
|
||||||
```
|
|
||||||
Total Changes:
|
|
||||||
- Commits: 85
|
|
||||||
- Files: 152 changed
|
|
||||||
- Additions: +18,104 lines
|
|
||||||
- Deletions: -3,732 lines
|
|
||||||
|
|
||||||
New Modules:
|
|
||||||
- Skills Management: 2,034 lines (21 files)
|
|
||||||
- Prompts Management: 1,302 lines (20 files)
|
|
||||||
- Gemini Integration: ~1,000 lines
|
|
||||||
- MCP Refactor: ~3,000 lines refactored
|
|
||||||
|
|
||||||
Code Distribution:
|
|
||||||
- Backend (Rust): ~4,500 lines new
|
|
||||||
- Frontend (React): ~3,000 lines new
|
|
||||||
- Configuration: ~1,500 lines refactored
|
|
||||||
- Tests: ~500 lines
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Strategic Positioning
|
|
||||||
|
|
||||||
### From Tool to Platform
|
|
||||||
|
|
||||||
v3.7.0 represents a shift in CC Switch's positioning:
|
|
||||||
|
|
||||||
| Aspect | v3.6 | v3.7.0 |
|
|
||||||
| ----------------- | ------------------------ | ---------------------------- |
|
|
||||||
| **Identity** | Provider Switcher | AI CLI Management Platform |
|
|
||||||
| **Scope** | Configuration Management | Ecosystem Management |
|
|
||||||
| **Applications** | Claude + Codex | Claude + Codex + Gemini |
|
|
||||||
| **Capabilities** | Switch configs | Extend capabilities (Skills) |
|
|
||||||
| **Customization** | Manual editing | Visual management (Prompts) |
|
|
||||||
| **Integration** | Isolated apps | Unified management (MCP) |
|
|
||||||
|
|
||||||
### Six Pillars of AI CLI Management
|
|
||||||
|
|
||||||
1. **Configuration Management** - Provider switching and management
|
|
||||||
2. **Capability Extension** - Skills installation and lifecycle
|
|
||||||
3. **Behavior Customization** - System prompt presets
|
|
||||||
4. **Ecosystem Integration** - Deep links and sharing
|
|
||||||
5. **Multi-AI Support** - Claude/Codex/Gemini
|
|
||||||
6. **Intelligent Detection** - Conflict prevention
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Download & Installation
|
|
||||||
|
|
||||||
### System Requirements
|
|
||||||
|
|
||||||
- **Windows**: Windows 10+
|
|
||||||
- **macOS**: macOS 10.15 (Catalina)+
|
|
||||||
- **Linux**: Ubuntu 22.04+ / Debian 11+ / Fedora 34+ / ArchLinux
|
|
||||||
|
|
||||||
### Download Links
|
|
||||||
|
|
||||||
Visit [Releases](https://github.com/farion1231/cc-switch/releases/latest) to download:
|
|
||||||
|
|
||||||
- **Windows**: `CC-Switch-Windows.msi` or `-Portable.zip`
|
|
||||||
- **macOS**: `CC-Switch-macOS.tar.gz` or `.zip`
|
|
||||||
- **Linux**: `CC-Switch-Linux.AppImage` or `.deb`
|
|
||||||
- **ArchLinux**: `paru -S cc-switch-bin`
|
|
||||||
|
|
||||||
### Homebrew (macOS)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew tap farion1231/ccswitch
|
|
||||||
brew install --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
Update:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew upgrade --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Migration Notes
|
|
||||||
|
|
||||||
### From v3.6.x
|
|
||||||
|
|
||||||
**Automatic migration** - No action required, configs are fully compatible
|
|
||||||
|
|
||||||
### From v3.1.x or Earlier
|
|
||||||
|
|
||||||
**Two-step migration required**:
|
|
||||||
|
|
||||||
1. First upgrade to v3.2.x (performs one-time migration)
|
|
||||||
2. Then upgrade to v3.7.0
|
|
||||||
|
|
||||||
### New Features
|
|
||||||
|
|
||||||
- **Skills**: No migration needed, start fresh
|
|
||||||
- **Prompts**: Auto-import from live files on first launch
|
|
||||||
- **Gemini**: Install Gemini CLI separately if needed
|
|
||||||
- **MCP v3.7.0**: Backward compatible with previous configs
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Acknowledgments
|
|
||||||
|
|
||||||
### Contributors
|
|
||||||
|
|
||||||
Thanks to all contributors who made this release possible:
|
|
||||||
|
|
||||||
- [@YoVinchen](https://github.com/YoVinchen) - Skills & Prompts & Gemini integration implementation
|
|
||||||
- [@farion1231](https://github.com/farion1231) - From developer to issue responder
|
|
||||||
- Community members for testing and feedback
|
|
||||||
|
|
||||||
### Sponsors
|
|
||||||
|
|
||||||
**Z.ai** - GLM CODING PLAN sponsor
|
|
||||||
[Get 10% OFF with this link](https://z.ai/subscribe?ic=8JVLJQFSKB)
|
|
||||||
|
|
||||||
**PackyCode** - API relay service partner
|
|
||||||
[Register with "cc-switch" code for 10% discount](https://www.packyapi.com/register?aff=cc-switch)
|
|
||||||
|
|
||||||
**ShanDianShuo** - Local-first AI voice input
|
|
||||||
[Free download](https://shandianshuo.cn) for Mac/Win
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Feedback & Support
|
|
||||||
|
|
||||||
- **Issues**: [GitHub Issues](https://github.com/farion1231/cc-switch/issues)
|
|
||||||
- **Discussions**: [GitHub Discussions](https://github.com/farion1231/cc-switch/discussions)
|
|
||||||
- **Documentation**: [README](../README.md)
|
|
||||||
- **Changelog**: [CHANGELOG.md](../CHANGELOG.md)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What's Next
|
|
||||||
|
|
||||||
**v3.8.0 Preview** (Tentative):
|
|
||||||
|
|
||||||
- Local proxy functionality
|
|
||||||
|
|
||||||
Stay tuned for more updates!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Happy Coding!**
|
|
||||||
@@ -1,481 +0,0 @@
|
|||||||
# CC Switch v3.7.1
|
|
||||||
|
|
||||||
> 稳定性增强与用户体验改进
|
|
||||||
|
|
||||||
**[English Version →](release-note-v3.7.1-en.md)**
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## v3.7.1 更新内容
|
|
||||||
|
|
||||||
**发布日期**:2025-11-22
|
|
||||||
**代码变更**:17 个文件,+524 / -81 行
|
|
||||||
|
|
||||||
### Bug 修复
|
|
||||||
|
|
||||||
- **修复 Skills 第三方仓库安装失败** (#268)
|
|
||||||
修复使用自定义子目录的 skills 仓库无法安装的问题,支持类似 `ComposioHQ/awesome-claude-skills` 这样带子目录的仓库
|
|
||||||
|
|
||||||
- **修复 Gemini 配置持久化问题**
|
|
||||||
解决在 Gemini 表单中编辑 settings.json 后,切换供应商时修改丢失的问题
|
|
||||||
|
|
||||||
- **防止对话框意外关闭**
|
|
||||||
添加点击遮罩时的保护,避免误操作导致表单数据丢失,影响所有 11 个对话框组件
|
|
||||||
|
|
||||||
### 新增功能
|
|
||||||
|
|
||||||
- **Gemini 配置目录支持** (#255)
|
|
||||||
在设置中添加 Gemini 配置目录选项,支持自定义 `~/.gemini/` 路径
|
|
||||||
|
|
||||||
- **ArchLinux 安装支持** (#259)
|
|
||||||
添加 AUR 安装方式:`paru -S cc-switch-bin`
|
|
||||||
|
|
||||||
### 改进
|
|
||||||
|
|
||||||
- **Skills 错误消息国际化增强**
|
|
||||||
新增 28+ 条详细错误消息(中英文),提供具体的解决建议,下载超时从 15 秒延长到 60 秒
|
|
||||||
|
|
||||||
- **代码格式化**
|
|
||||||
应用统一的 Rust 和 TypeScript 代码格式化标准
|
|
||||||
|
|
||||||
### 下载
|
|
||||||
|
|
||||||
访问 [Releases](https://github.com/farion1231/cc-switch/releases/latest) 下载最新版本
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## v3.7.0 完整更新说明
|
|
||||||
|
|
||||||
> 从供应商切换器到 AI CLI 一体化管理平台
|
|
||||||
|
|
||||||
**发布日期**:2025-11-19
|
|
||||||
**提交数量**:从 v3.6.0 开始 85 个提交
|
|
||||||
**代码变更**:152 个文件,+18,104 / -3,732 行
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 新增功能
|
|
||||||
|
|
||||||
### Gemini CLI 集成
|
|
||||||
|
|
||||||
完整支持 Google Gemini CLI,成为第三个支持的应用(Claude Code、Codex、Gemini)。
|
|
||||||
|
|
||||||
**核心能力**:
|
|
||||||
|
|
||||||
- **双文件配置** - 同时支持 `.env` 和 `settings.json` 格式
|
|
||||||
- **自动检测** - 自动检测 `GOOGLE_GEMINI_BASE_URL`、`GEMINI_MODEL` 等环境变量
|
|
||||||
- **完整 MCP 支持** - 为 Gemini 提供完整的 MCP 服务器管理
|
|
||||||
- **深度链接集成** - 通过 `ccswitch://` 协议导入配置
|
|
||||||
- **系统托盘** - 从托盘菜单快速切换
|
|
||||||
|
|
||||||
**供应商预设**:
|
|
||||||
|
|
||||||
- **Google Official** - 支持 OAuth 认证
|
|
||||||
- **PackyCode** - 合作伙伴集成
|
|
||||||
- **自定义** - 完全自定义支持
|
|
||||||
|
|
||||||
**技术实现**:
|
|
||||||
|
|
||||||
- 新增后端模块:`gemini_config.rs`(20KB)、`gemini_mcp.rs`
|
|
||||||
- 表单与环境编辑器同步
|
|
||||||
- 双文件原子写入
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### MCP v3.7.0 统一架构
|
|
||||||
|
|
||||||
MCP 管理系统完整重构,实现跨应用统一管理。
|
|
||||||
|
|
||||||
**架构改进**:
|
|
||||||
|
|
||||||
- **统一管理面板** - 单一界面管理 Claude/Codex/Gemini MCP 服务器
|
|
||||||
- **SSE 传输类型** - 新增 Server-Sent Events 支持
|
|
||||||
- **智能解析器** - 容错性 JSON 解析
|
|
||||||
- **格式修正** - 自动修复 Codex `[mcp_servers]` 格式
|
|
||||||
- **扩展字段** - 保留自定义 TOML 字段
|
|
||||||
|
|
||||||
**用户体验**:
|
|
||||||
|
|
||||||
- 表单中的默认应用选择
|
|
||||||
- JSON 格式化器用于验证
|
|
||||||
- 改进的视觉层次
|
|
||||||
- 更好的错误消息
|
|
||||||
|
|
||||||
**导入/导出**:
|
|
||||||
|
|
||||||
- 统一从三个应用导入
|
|
||||||
- 双向同步
|
|
||||||
- 状态保持
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Claude Skills 管理系统
|
|
||||||
|
|
||||||
**约 2,000 行代码** - 完整的技能生态平台。
|
|
||||||
|
|
||||||
**GitHub 集成**:
|
|
||||||
|
|
||||||
- 从 GitHub 仓库自动扫描技能
|
|
||||||
- 预配置仓库:
|
|
||||||
- `ComposioHQ/awesome-claude-skills` - 精选集合
|
|
||||||
- `anthropics/skills` - Anthropic 官方技能
|
|
||||||
- `cexll/myclaude` - 社区贡献
|
|
||||||
- 添加自定义仓库
|
|
||||||
- 子目录扫描支持(`skillsPath`)
|
|
||||||
|
|
||||||
**生命周期管理**:
|
|
||||||
|
|
||||||
- **发现** - 自动检测 `SKILL.md` 文件
|
|
||||||
- **安装** - 一键安装到 `~/.claude/skills/`
|
|
||||||
- **卸载** - 安全移除并跟踪状态
|
|
||||||
- **更新** - 检查更新(基础设施已就绪)
|
|
||||||
|
|
||||||
**技术架构**:
|
|
||||||
|
|
||||||
- **后端**:`SkillService`(526 行)集成 GitHub API
|
|
||||||
- **前端**:SkillsPage、SkillCard、RepoManager
|
|
||||||
- **UI 组件**:Badge、Card、Table(shadcn/ui)
|
|
||||||
- **状态**:持久化存储在 `config.json`
|
|
||||||
- **国际化**:47+ 个翻译键
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Prompts 管理系统
|
|
||||||
|
|
||||||
**约 1,300 行代码** - 完整的系统提示词管理。
|
|
||||||
|
|
||||||
**多预设管理**:
|
|
||||||
|
|
||||||
- 创建无限数量的提示词预设
|
|
||||||
- 快速在预设间切换
|
|
||||||
- 同时只能激活一个提示词
|
|
||||||
- 活动提示词删除保护
|
|
||||||
|
|
||||||
**跨应用支持**:
|
|
||||||
|
|
||||||
- **Claude**:`~/.claude/CLAUDE.md`
|
|
||||||
- **Codex**:`~/.codex/AGENTS.md`
|
|
||||||
- **Gemini**:`~/.gemini/GEMINI.md`
|
|
||||||
|
|
||||||
**Markdown 编辑器**:
|
|
||||||
|
|
||||||
- 完整的 CodeMirror 6 集成
|
|
||||||
- 语法高亮
|
|
||||||
- 暗色主题(One Dark)
|
|
||||||
- 实时预览
|
|
||||||
|
|
||||||
**智能同步**:
|
|
||||||
|
|
||||||
- **自动写入** - 立即写入 live 文件
|
|
||||||
- **回填保护** - 切换前保存当前内容
|
|
||||||
- **自动导入** - 首次启动从 live 文件导入
|
|
||||||
- **修改保护** - 保留手动修改
|
|
||||||
|
|
||||||
**技术实现**:
|
|
||||||
|
|
||||||
- **后端**:`PromptService`(213 行)
|
|
||||||
- **前端**:PromptPanel(177)、PromptFormModal(160)、MarkdownEditor(159)
|
|
||||||
- **Hooks**:usePromptActions(152 行)
|
|
||||||
- **国际化**:41+ 个翻译键
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 深度链接协议(ccswitch://)
|
|
||||||
|
|
||||||
通过 URL 方案一键导入供应商配置。
|
|
||||||
|
|
||||||
**功能特性**:
|
|
||||||
|
|
||||||
- 所有平台的协议注册
|
|
||||||
- 从共享链接导入
|
|
||||||
- 生命周期集成
|
|
||||||
- 安全验证
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 环境变量冲突检测
|
|
||||||
|
|
||||||
智能检测和管理配置冲突。
|
|
||||||
|
|
||||||
**检测范围**:
|
|
||||||
|
|
||||||
- **Claude & Codex** - 跨应用冲突
|
|
||||||
- **Gemini** - 自动发现
|
|
||||||
- **MCP** - 服务器配置冲突
|
|
||||||
|
|
||||||
**管理功能**:
|
|
||||||
|
|
||||||
- 可视化冲突指示器
|
|
||||||
- 解决建议
|
|
||||||
- 覆盖警告
|
|
||||||
- 更改前备份
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 改进优化
|
|
||||||
|
|
||||||
### 供应商管理
|
|
||||||
|
|
||||||
**新增预设**:
|
|
||||||
|
|
||||||
- **DouBaoSeed** - 字节跳动的豆包
|
|
||||||
- **Kimi For Coding** - 月之暗面
|
|
||||||
- **BaiLing** - 百灵 AI
|
|
||||||
- **移除 AnyRouter** - 避免误导
|
|
||||||
|
|
||||||
**增强功能**:
|
|
||||||
|
|
||||||
- Codex 和 Gemini 的模型名称配置
|
|
||||||
- 供应商备注字段用于组织
|
|
||||||
- 增强的预设元数据
|
|
||||||
|
|
||||||
### 配置管理
|
|
||||||
|
|
||||||
- **通用配置迁移** - 从 localStorage 迁移到 `config.json`
|
|
||||||
- **统一持久化** - 跨所有应用共享
|
|
||||||
- **自动导入** - 首次启动配置导入
|
|
||||||
- **回填优先级** - 正确处理 live 文件
|
|
||||||
|
|
||||||
### UI/UX 改进
|
|
||||||
|
|
||||||
**设计系统**:
|
|
||||||
|
|
||||||
- **macOS 原生** - 与系统对齐的配色方案
|
|
||||||
- **窗口居中** - 默认居中位置
|
|
||||||
- **视觉优化** - 改进的间距和层次
|
|
||||||
|
|
||||||
**交互优化**:
|
|
||||||
|
|
||||||
- **密码输入** - 修复 Edge/IE 显示按钮
|
|
||||||
- **URL 溢出** - 修复卡片溢出
|
|
||||||
- **错误复制** - 可复制到剪贴板的错误
|
|
||||||
- **托盘同步** - 实时拖放同步
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Bug 修复
|
|
||||||
|
|
||||||
### 关键修复
|
|
||||||
|
|
||||||
- **用量脚本验证** - 边界检查
|
|
||||||
- **Gemini 验证** - 放宽约束
|
|
||||||
- **TOML 解析** - CJK 引号处理
|
|
||||||
- **MCP 字段** - 自定义字段保留
|
|
||||||
- **白屏** - FormLabel 崩溃修复
|
|
||||||
|
|
||||||
### 稳定性
|
|
||||||
|
|
||||||
- **托盘安全** - 模式匹配替代 unwrap
|
|
||||||
- **错误隔离** - 托盘失败不阻塞操作
|
|
||||||
- **导入分类** - 正确的类别分配
|
|
||||||
|
|
||||||
### UI 修复
|
|
||||||
|
|
||||||
- **模型占位符** - 移除误导性提示
|
|
||||||
- **Base URL** - 第三方供应商自动填充
|
|
||||||
- **拖拽排序** - 托盘菜单同步
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 技术改进
|
|
||||||
|
|
||||||
### 架构
|
|
||||||
|
|
||||||
**MCP v3.7.0**:
|
|
||||||
|
|
||||||
- 移除遗留代码(约 1,000 行)
|
|
||||||
- 统一初始化结构
|
|
||||||
- 保持向后兼容性
|
|
||||||
- 全面的代码格式化
|
|
||||||
|
|
||||||
**平台兼容性**:
|
|
||||||
|
|
||||||
- Windows winreg API 修复(v0.52)
|
|
||||||
- 安全模式匹配(无 `unwrap()`)
|
|
||||||
- 跨平台托盘处理
|
|
||||||
|
|
||||||
### 配置
|
|
||||||
|
|
||||||
**同步机制**:
|
|
||||||
|
|
||||||
- 跨所有应用的 MCP 同步
|
|
||||||
- Gemini 表单-编辑器同步
|
|
||||||
- 双文件读取(.env + settings.json)
|
|
||||||
|
|
||||||
**验证增强**:
|
|
||||||
|
|
||||||
- 输入边界检查
|
|
||||||
- TOML 引号规范化(CJK)
|
|
||||||
- 自定义字段保留
|
|
||||||
- 增强的错误消息
|
|
||||||
|
|
||||||
### 代码质量
|
|
||||||
|
|
||||||
**类型安全**:
|
|
||||||
|
|
||||||
- 完整的 TypeScript 覆盖
|
|
||||||
- Rust 类型改进
|
|
||||||
- API 契约验证
|
|
||||||
|
|
||||||
**测试**:
|
|
||||||
|
|
||||||
- 简化的断言
|
|
||||||
- 更好的测试覆盖
|
|
||||||
- 集成测试更新
|
|
||||||
|
|
||||||
**依赖项**:
|
|
||||||
|
|
||||||
- Tauri 2.8.x
|
|
||||||
- Rust:`anyhow`、`zip`、`serde_yaml`、`tempfile`
|
|
||||||
- 前端:CodeMirror 6 包
|
|
||||||
- winreg 0.52(Windows)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 技术统计
|
|
||||||
|
|
||||||
```
|
|
||||||
总体变更:
|
|
||||||
- 提交数:85
|
|
||||||
- 文件数:152 个文件变更
|
|
||||||
- 新增:+18,104 行
|
|
||||||
- 删除:-3,732 行
|
|
||||||
|
|
||||||
新增模块:
|
|
||||||
- Skills 管理:2,034 行(21 个文件)
|
|
||||||
- Prompts 管理:1,302 行(20 个文件)
|
|
||||||
- Gemini 集成:约 1,000 行
|
|
||||||
- MCP 重构:约 3,000 行重构
|
|
||||||
|
|
||||||
代码分布:
|
|
||||||
- 后端(Rust):约 4,500 行新增
|
|
||||||
- 前端(React):约 3,000 行新增
|
|
||||||
- 配置:约 1,500 行重构
|
|
||||||
- 测试:约 500 行
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 战略定位
|
|
||||||
|
|
||||||
### 从工具到平台
|
|
||||||
|
|
||||||
v3.7.0 代表了 CC Switch 定位的转变:
|
|
||||||
|
|
||||||
| 方面 | v3.6 | v3.7.0 |
|
|
||||||
| -------- | -------------- | ----------------------- |
|
|
||||||
| **身份** | 供应商切换器 | AI CLI 管理平台 |
|
|
||||||
| **范围** | 配置管理 | 生态系统管理 |
|
|
||||||
| **应用** | Claude + Codex | Claude + Codex + Gemini |
|
|
||||||
| **能力** | 切换配置 | 扩展能力(Skills) |
|
|
||||||
| **定制** | 手动编辑 | 可视化管理(Prompts) |
|
|
||||||
| **集成** | 孤立应用 | 统一管理(MCP) |
|
|
||||||
|
|
||||||
### AI CLI 管理六大支柱
|
|
||||||
|
|
||||||
1. **配置管理** - 供应商切换和管理
|
|
||||||
2. **能力扩展** - Skills 安装和生命周期
|
|
||||||
3. **行为定制** - 系统提示词预设
|
|
||||||
4. **生态集成** - 深度链接和共享
|
|
||||||
5. **多 AI 支持** - Claude/Codex/Gemini
|
|
||||||
6. **智能检测** - 冲突预防
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 下载与安装
|
|
||||||
|
|
||||||
### 系统要求
|
|
||||||
|
|
||||||
- **Windows**:Windows 10+
|
|
||||||
- **macOS**:macOS 10.15(Catalina)+
|
|
||||||
- **Linux**:Ubuntu 22.04+ / Debian 11+ / Fedora 34+ / ArchLinux
|
|
||||||
|
|
||||||
### 下载链接
|
|
||||||
|
|
||||||
访问 [Releases](https://github.com/farion1231/cc-switch/releases/latest) 下载:
|
|
||||||
|
|
||||||
- **Windows**:`CC-Switch-Windows.msi` 或 `-Portable.zip`
|
|
||||||
- **macOS**:`CC-Switch-macOS.tar.gz` 或 `.zip`
|
|
||||||
- **Linux**:`CC-Switch-Linux.AppImage` 或 `.deb`
|
|
||||||
- **ArchLinux**:`paru -S cc-switch-bin`
|
|
||||||
|
|
||||||
### Homebrew(macOS)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew tap farion1231/ccswitch
|
|
||||||
brew install --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
更新:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
brew upgrade --cask cc-switch
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 迁移说明
|
|
||||||
|
|
||||||
### 从 v3.6.x 升级
|
|
||||||
|
|
||||||
**自动迁移** - 无需任何操作,配置完全兼容
|
|
||||||
|
|
||||||
### 从 v3.1.x 或更早版本升级
|
|
||||||
|
|
||||||
**需要两步迁移**:
|
|
||||||
|
|
||||||
1. 首先升级到 v3.2.x(执行一次性迁移)
|
|
||||||
2. 然后升级到 v3.7.0
|
|
||||||
|
|
||||||
### 新功能
|
|
||||||
|
|
||||||
- **Skills**:无需迁移,全新开始
|
|
||||||
- **Prompts**:首次启动时从 live 文件自动导入
|
|
||||||
- **Gemini**:需要单独安装 Gemini CLI
|
|
||||||
- **MCP v3.7.0**:与之前的配置向后兼容
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 致谢
|
|
||||||
|
|
||||||
### 贡献者
|
|
||||||
|
|
||||||
感谢所有让这个版本成为可能的贡献者:
|
|
||||||
|
|
||||||
- [@YoVinchen](https://github.com/YoVinchen) - Skills & Prompts & Gemini 集成实现
|
|
||||||
- [@farion1231](https://github.com/farion1231) - 从开发沦为 issue 回复机
|
|
||||||
- 社区成员的测试和反馈
|
|
||||||
|
|
||||||
### 赞助商
|
|
||||||
|
|
||||||
**智谱AI** - GLM CODING PLAN 赞助商
|
|
||||||
[使用此链接购买可享九折优惠](https://www.bigmodel.cn/claude-code?ic=RRVJPB5SII)
|
|
||||||
|
|
||||||
**PackyCode** - API 中转服务合作伙伴
|
|
||||||
[使用 "cc-switch" 优惠码注册享 9 折优惠](https://www.packyapi.com/register?aff=cc-switch)
|
|
||||||
|
|
||||||
**闪电说** - 本地优先的 AI 语音输入法
|
|
||||||
[免费下载](https://shandianshuo.cn) Mac/Win 双平台
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 反馈与支持
|
|
||||||
|
|
||||||
- **问题反馈**:[GitHub Issues](https://github.com/farion1231/cc-switch/issues)
|
|
||||||
- **讨论**:[GitHub Discussions](https://github.com/farion1231/cc-switch/discussions)
|
|
||||||
- **文档**:[README](../README_ZH.md)
|
|
||||||
- **更新日志**:[CHANGELOG.md](../CHANGELOG.md)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 未来展望
|
|
||||||
|
|
||||||
**v3.8.0 预览**(暂定):
|
|
||||||
|
|
||||||
- 本地代理功能
|
|
||||||
|
|
||||||
敬请期待更多更新!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Happy Coding!**
|
|
||||||
+2
-3
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "cc-switch",
|
"name": "cc-switch",
|
||||||
"version": "3.7.1",
|
"version": "3.6.2",
|
||||||
"description": "All-in-One Assistant for Claude Code, Codex & Gemini CLI",
|
"description": "Claude Code & Codex 供应商切换工具",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "pnpm tauri dev",
|
"dev": "pnpm tauri dev",
|
||||||
"build": "pnpm tauri build",
|
"build": "pnpm tauri build",
|
||||||
@@ -46,7 +46,6 @@
|
|||||||
"@dnd-kit/sortable": "^10.0.0",
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
"@lobehub/icons-static-svg": "^1.73.0",
|
|
||||||
"@radix-ui/react-checkbox": "^1.3.3",
|
"@radix-ui/react-checkbox": "^1.3.3",
|
||||||
"@radix-ui/react-dialog": "^1.1.15",
|
"@radix-ui/react-dialog": "^1.1.15",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||||
|
|||||||
Generated
-8
@@ -41,9 +41,6 @@ importers:
|
|||||||
'@hookform/resolvers':
|
'@hookform/resolvers':
|
||||||
specifier: ^5.2.2
|
specifier: ^5.2.2
|
||||||
version: 5.2.2(react-hook-form@7.65.0(react@18.3.1))
|
version: 5.2.2(react-hook-form@7.65.0(react@18.3.1))
|
||||||
'@lobehub/icons-static-svg':
|
|
||||||
specifier: ^1.73.0
|
|
||||||
version: 1.73.0
|
|
||||||
'@radix-ui/react-checkbox':
|
'@radix-ui/react-checkbox':
|
||||||
specifier: ^1.3.3
|
specifier: ^1.3.3
|
||||||
version: 1.3.3(@types/react-dom@18.3.7(@types/react@18.3.23))(@types/react@18.3.23)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 1.3.3(@types/react-dom@18.3.7(@types/react@18.3.23))(@types/react@18.3.23)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
@@ -612,9 +609,6 @@ packages:
|
|||||||
'@lezer/markdown@1.6.0':
|
'@lezer/markdown@1.6.0':
|
||||||
resolution: {integrity: sha512-AXb98u3M6BEzTnreBnGtQaF7xFTiMA92Dsy5tqEjpacbjRxDSFdN4bKJo9uvU4cEEOS7D2B9MT7kvDgOEIzJSw==}
|
resolution: {integrity: sha512-AXb98u3M6BEzTnreBnGtQaF7xFTiMA92Dsy5tqEjpacbjRxDSFdN4bKJo9uvU4cEEOS7D2B9MT7kvDgOEIzJSw==}
|
||||||
|
|
||||||
'@lobehub/icons-static-svg@1.73.0':
|
|
||||||
resolution: {integrity: sha512-ydKUCDoopdmulbjDZo/gppaODd5Ju5nPneVcN9A5dAz9IJZUMkLms8bqostMLrqcdMQ8resKjLuV9RhJaWhaag==}
|
|
||||||
|
|
||||||
'@marijn/find-cluster-break@1.0.2':
|
'@marijn/find-cluster-break@1.0.2':
|
||||||
resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}
|
resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}
|
||||||
|
|
||||||
@@ -2845,8 +2839,6 @@ snapshots:
|
|||||||
'@lezer/common': 1.2.3
|
'@lezer/common': 1.2.3
|
||||||
'@lezer/highlight': 1.2.1
|
'@lezer/highlight': 1.2.1
|
||||||
|
|
||||||
'@lobehub/icons-static-svg@1.73.0': {}
|
|
||||||
|
|
||||||
'@marijn/find-cluster-break@1.0.2': {}
|
'@marijn/find-cluster-break@1.0.2': {}
|
||||||
|
|
||||||
'@mswjs/interceptors@0.40.0':
|
'@mswjs/interceptors@0.40.0':
|
||||||
|
|||||||
@@ -1,208 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
// 要提取的图标列表(按分类组织)
|
|
||||||
const ICONS_TO_EXTRACT = {
|
|
||||||
// AI 服务商(必需)
|
|
||||||
aiProviders: [
|
|
||||||
'openai', 'anthropic', 'claude', 'google', 'gemini',
|
|
||||||
'deepseek', 'kimi', 'moonshot', 'zhipu', 'minimax',
|
|
||||||
'baidu', 'alibaba', 'tencent', 'meta', 'microsoft',
|
|
||||||
'cohere', 'perplexity', 'mistral', 'huggingface'
|
|
||||||
],
|
|
||||||
|
|
||||||
// 云平台
|
|
||||||
cloudPlatforms: [
|
|
||||||
'aws', 'azure', 'huawei', 'cloudflare'
|
|
||||||
],
|
|
||||||
|
|
||||||
// 开发工具
|
|
||||||
devTools: [
|
|
||||||
'github', 'gitlab', 'docker', 'kubernetes', 'vscode'
|
|
||||||
],
|
|
||||||
|
|
||||||
// 其他
|
|
||||||
others: [
|
|
||||||
'settings', 'folder', 'file', 'link'
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
// 合并所有图标
|
|
||||||
const ALL_ICONS = [
|
|
||||||
...ICONS_TO_EXTRACT.aiProviders,
|
|
||||||
...ICONS_TO_EXTRACT.cloudPlatforms,
|
|
||||||
...ICONS_TO_EXTRACT.devTools,
|
|
||||||
...ICONS_TO_EXTRACT.others
|
|
||||||
];
|
|
||||||
|
|
||||||
// 提取逻辑
|
|
||||||
const OUTPUT_DIR = path.join(__dirname, '../src/icons/extracted');
|
|
||||||
const SOURCE_DIR = path.join(__dirname, '../node_modules/@lobehub/icons-static-svg/icons');
|
|
||||||
|
|
||||||
// 确保输出目录存在
|
|
||||||
if (!fs.existsSync(OUTPUT_DIR)) {
|
|
||||||
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('🎨 CC-Switch Icon Extractor\n');
|
|
||||||
console.log('========================================');
|
|
||||||
console.log('📦 Extracting icons...\n');
|
|
||||||
|
|
||||||
let extracted = 0;
|
|
||||||
let notFound = [];
|
|
||||||
|
|
||||||
// 提取图标
|
|
||||||
ALL_ICONS.forEach(iconName => {
|
|
||||||
const sourceFile = path.join(SOURCE_DIR, `${iconName}.svg`);
|
|
||||||
const targetFile = path.join(OUTPUT_DIR, `${iconName}.svg`);
|
|
||||||
|
|
||||||
if (fs.existsSync(sourceFile)) {
|
|
||||||
fs.copyFileSync(sourceFile, targetFile);
|
|
||||||
console.log(` ✓ ${iconName}.svg`);
|
|
||||||
extracted++;
|
|
||||||
} else {
|
|
||||||
console.log(` ✗ ${iconName}.svg (not found)`);
|
|
||||||
notFound.push(iconName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 生成索引文件
|
|
||||||
console.log('\n📝 Generating index file...\n');
|
|
||||||
|
|
||||||
const indexContent = `// Auto-generated icon index
|
|
||||||
// Do not edit manually
|
|
||||||
|
|
||||||
export const icons: Record<string, string> = {
|
|
||||||
${ALL_ICONS.filter(name => !notFound.includes(name))
|
|
||||||
.map(name => {
|
|
||||||
const svg = fs.readFileSync(path.join(OUTPUT_DIR, `${name}.svg`), 'utf-8');
|
|
||||||
const escaped = svg.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
||||||
return ` '${name}': \`${escaped}\`,`;
|
|
||||||
})
|
|
||||||
.join('\n')}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const iconList = Object.keys(icons);
|
|
||||||
|
|
||||||
export function getIcon(name: string): string {
|
|
||||||
return icons[name.toLowerCase()] || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hasIcon(name: string): boolean {
|
|
||||||
return name.toLowerCase() in icons;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'index.ts'), indexContent);
|
|
||||||
console.log('✓ Generated: src/icons/extracted/index.ts');
|
|
||||||
|
|
||||||
// 生成图标元数据
|
|
||||||
const metadataContent = `// Icon metadata for search and categorization
|
|
||||||
import { IconMetadata } from '@/types/icon';
|
|
||||||
|
|
||||||
export const iconMetadata: Record<string, IconMetadata> = {
|
|
||||||
// AI Providers
|
|
||||||
openai: { name: 'openai', displayName: 'OpenAI', category: 'ai-provider', keywords: ['gpt', 'chatgpt'], defaultColor: '#00A67E' },
|
|
||||||
anthropic: { name: 'anthropic', displayName: 'Anthropic', category: 'ai-provider', keywords: ['claude'], defaultColor: '#D4915D' },
|
|
||||||
claude: { name: 'claude', displayName: 'Claude', category: 'ai-provider', keywords: ['anthropic'], defaultColor: '#D4915D' },
|
|
||||||
google: { name: 'google', displayName: 'Google', category: 'ai-provider', keywords: ['gemini', 'bard'], defaultColor: '#4285F4' },
|
|
||||||
gemini: { name: 'gemini', displayName: 'Gemini', category: 'ai-provider', keywords: ['google'], defaultColor: '#4285F4' },
|
|
||||||
deepseek: { name: 'deepseek', displayName: 'DeepSeek', category: 'ai-provider', keywords: ['deep', 'seek'], defaultColor: '#1E88E5' },
|
|
||||||
moonshot: { name: 'moonshot', displayName: 'Moonshot', category: 'ai-provider', keywords: ['kimi', 'moonshot'], defaultColor: '#6366F1' },
|
|
||||||
kimi: { name: 'kimi', displayName: 'Kimi', category: 'ai-provider', keywords: ['moonshot'], defaultColor: '#6366F1' },
|
|
||||||
zhipu: { name: 'zhipu', displayName: 'Zhipu AI', category: 'ai-provider', keywords: ['chatglm', 'glm'], defaultColor: '#0F62FE' },
|
|
||||||
minimax: { name: 'minimax', displayName: 'MiniMax', category: 'ai-provider', keywords: ['minimax'], defaultColor: '#FF6B6B' },
|
|
||||||
baidu: { name: 'baidu', displayName: 'Baidu', category: 'ai-provider', keywords: ['ernie', 'wenxin'], defaultColor: '#2932E1' },
|
|
||||||
alibaba: { name: 'alibaba', displayName: 'Alibaba', category: 'ai-provider', keywords: ['qwen', 'tongyi'], defaultColor: '#FF6A00' },
|
|
||||||
tencent: { name: 'tencent', displayName: 'Tencent', category: 'ai-provider', keywords: ['hunyuan'], defaultColor: '#00A4FF' },
|
|
||||||
meta: { name: 'meta', displayName: 'Meta', category: 'ai-provider', keywords: ['facebook', 'llama'], defaultColor: '#0081FB' },
|
|
||||||
microsoft: { name: 'microsoft', displayName: 'Microsoft', category: 'ai-provider', keywords: ['copilot', 'azure'], defaultColor: '#00A4EF' },
|
|
||||||
cohere: { name: 'cohere', displayName: 'Cohere', category: 'ai-provider', keywords: ['cohere'], defaultColor: '#39594D' },
|
|
||||||
perplexity: { name: 'perplexity', displayName: 'Perplexity', category: 'ai-provider', keywords: ['perplexity'], defaultColor: '#20808D' },
|
|
||||||
mistral: { name: 'mistral', displayName: 'Mistral', category: 'ai-provider', keywords: ['mistral'], defaultColor: '#FF7000' },
|
|
||||||
huggingface: { name: 'huggingface', displayName: 'Hugging Face', category: 'ai-provider', keywords: ['huggingface', 'hf'], defaultColor: '#FFD21E' },
|
|
||||||
|
|
||||||
// Cloud Platforms
|
|
||||||
aws: { name: 'aws', displayName: 'AWS', category: 'cloud', keywords: ['amazon', 'cloud'], defaultColor: '#FF9900' },
|
|
||||||
azure: { name: 'azure', displayName: 'Azure', category: 'cloud', keywords: ['microsoft', 'cloud'], defaultColor: '#0078D4' },
|
|
||||||
huawei: { name: 'huawei', displayName: 'Huawei', category: 'cloud', keywords: ['huawei', 'cloud'], defaultColor: '#FF0000' },
|
|
||||||
cloudflare: { name: 'cloudflare', displayName: 'Cloudflare', category: 'cloud', keywords: ['cloudflare', 'cdn'], defaultColor: '#F38020' },
|
|
||||||
|
|
||||||
// Dev Tools
|
|
||||||
github: { name: 'github', displayName: 'GitHub', category: 'tool', keywords: ['git', 'version control'], defaultColor: '#181717' },
|
|
||||||
gitlab: { name: 'gitlab', displayName: 'GitLab', category: 'tool', keywords: ['git', 'version control'], defaultColor: '#FC6D26' },
|
|
||||||
docker: { name: 'docker', displayName: 'Docker', category: 'tool', keywords: ['container'], defaultColor: '#2496ED' },
|
|
||||||
kubernetes: { name: 'kubernetes', displayName: 'Kubernetes', category: 'tool', keywords: ['k8s', 'container'], defaultColor: '#326CE5' },
|
|
||||||
vscode: { name: 'vscode', displayName: 'VS Code', category: 'tool', keywords: ['editor', 'ide'], defaultColor: '#007ACC' },
|
|
||||||
|
|
||||||
// Others
|
|
||||||
settings: { name: 'settings', displayName: 'Settings', category: 'other', keywords: ['config', 'preferences'], defaultColor: '#6B7280' },
|
|
||||||
folder: { name: 'folder', displayName: 'Folder', category: 'other', keywords: ['directory'], defaultColor: '#6B7280' },
|
|
||||||
file: { name: 'file', displayName: 'File', category: 'other', keywords: ['document'], defaultColor: '#6B7280' },
|
|
||||||
link: { name: 'link', displayName: 'Link', category: 'other', keywords: ['url', 'hyperlink'], defaultColor: '#6B7280' },
|
|
||||||
};
|
|
||||||
|
|
||||||
export function getIconMetadata(name: string): IconMetadata | undefined {
|
|
||||||
return iconMetadata[name.toLowerCase()];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function searchIcons(query: string): string[] {
|
|
||||||
const lowerQuery = query.toLowerCase();
|
|
||||||
return Object.values(iconMetadata)
|
|
||||||
.filter(meta =>
|
|
||||||
meta.name.includes(lowerQuery) ||
|
|
||||||
meta.displayName.toLowerCase().includes(lowerQuery) ||
|
|
||||||
meta.keywords.some(k => k.includes(lowerQuery))
|
|
||||||
)
|
|
||||||
.map(meta => meta.name);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'metadata.ts'), metadataContent);
|
|
||||||
console.log('✓ Generated: src/icons/extracted/metadata.ts');
|
|
||||||
|
|
||||||
// 生成 README
|
|
||||||
const readmeContent = `# Extracted Icons
|
|
||||||
|
|
||||||
This directory contains extracted icons from @lobehub/icons-static-svg.
|
|
||||||
|
|
||||||
## Statistics
|
|
||||||
- Total extracted: ${extracted} icons
|
|
||||||
- Not found: ${notFound.length} icons
|
|
||||||
|
|
||||||
## Extracted Icons
|
|
||||||
${ALL_ICONS.filter(name => !notFound.includes(name)).map(name => `- ${name}`).join('\n')}
|
|
||||||
|
|
||||||
${notFound.length > 0 ? `\n## Not Found\n${notFound.map(name => `- ${name}`).join('\n')}` : ''}
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
\`\`\`typescript
|
|
||||||
import { getIcon, hasIcon, iconList } from './extracted';
|
|
||||||
|
|
||||||
// Get icon SVG
|
|
||||||
const svg = getIcon('openai');
|
|
||||||
|
|
||||||
// Check if icon exists
|
|
||||||
if (hasIcon('openai')) {
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all available icons
|
|
||||||
console.log(iconList);
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
---
|
|
||||||
Last updated: ${new Date().toISOString()}
|
|
||||||
Generated by: scripts/extract-icons.js
|
|
||||||
`;
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'README.md'), readmeContent);
|
|
||||||
console.log('✓ Generated: src/icons/extracted/README.md');
|
|
||||||
|
|
||||||
console.log('\n========================================');
|
|
||||||
console.log('✅ Extraction complete!\n');
|
|
||||||
console.log(` ✓ Extracted: ${extracted} icons`);
|
|
||||||
console.log(` ✗ Not found: ${notFound.length} icons`);
|
|
||||||
console.log(` 📉 Bundle size reduction: ~${Math.round((1 - extracted / 723) * 100)}%`);
|
|
||||||
console.log('========================================\n');
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const ICONS_DIR = path.join(__dirname, '../src/icons/extracted');
|
|
||||||
|
|
||||||
// List of "Famous" icons to keep
|
|
||||||
// Based on common AI providers and tools
|
|
||||||
const KEEP_LIST = [
|
|
||||||
// AI Providers
|
|
||||||
'openai', 'anthropic', 'claude', 'google', 'gemini', 'gemma', 'palm',
|
|
||||||
'microsoft', 'azure', 'copilot', 'meta', 'llama',
|
|
||||||
'alibaba', 'qwen', 'tencent', 'hunyuan', 'baidu', 'wenxin',
|
|
||||||
'bytedance', 'doubao', 'deepseek', 'moonshot', 'kimi',
|
|
||||||
'zhipu', 'chatglm', 'glm', 'minimax', 'mistral', 'cohere',
|
|
||||||
'perplexity', 'huggingface', 'midjourney', 'stability',
|
|
||||||
'xai', 'grok', 'yi', 'zeroone', 'ollama',
|
|
||||||
'packycode',
|
|
||||||
|
|
||||||
// Cloud/Tools
|
|
||||||
'aws', 'googlecloud', 'huawei', 'cloudflare',
|
|
||||||
'github', 'githubcopilot', 'vercel', 'notion', 'discord',
|
|
||||||
'gitlab', 'docker', 'kubernetes', 'vscode', 'settings', 'folder', 'file', 'link'
|
|
||||||
];
|
|
||||||
|
|
||||||
// Get all SVG files
|
|
||||||
const files = fs.readdirSync(ICONS_DIR).filter(file => file.endsWith('.svg'));
|
|
||||||
|
|
||||||
console.log(`Scanning ${files.length} files...`);
|
|
||||||
|
|
||||||
let keptCount = 0;
|
|
||||||
let deletedCount = 0;
|
|
||||||
let renamedCount = 0;
|
|
||||||
|
|
||||||
// First pass: Identify files to keep and prefer color versions
|
|
||||||
const fileMap = {}; // name -> { hasColor: bool, hasMono: bool }
|
|
||||||
|
|
||||||
files.forEach(file => {
|
|
||||||
const isColor = file.endsWith('-color.svg');
|
|
||||||
const baseName = isColor ? file.replace('-color.svg', '') : file.replace('.svg', '');
|
|
||||||
|
|
||||||
if (!fileMap[baseName]) {
|
|
||||||
fileMap[baseName] = { hasColor: false, hasMono: false };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isColor) {
|
|
||||||
fileMap[baseName].hasColor = true;
|
|
||||||
} else {
|
|
||||||
fileMap[baseName].hasMono = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Second pass: Process files
|
|
||||||
Object.keys(fileMap).forEach(baseName => {
|
|
||||||
const info = fileMap[baseName];
|
|
||||||
const shouldKeep = KEEP_LIST.includes(baseName);
|
|
||||||
|
|
||||||
if (!shouldKeep) {
|
|
||||||
// Delete both versions if not in keep list
|
|
||||||
if (info.hasColor) {
|
|
||||||
fs.unlinkSync(path.join(ICONS_DIR, `${baseName}-color.svg`));
|
|
||||||
deletedCount++;
|
|
||||||
}
|
|
||||||
if (info.hasMono) {
|
|
||||||
fs.unlinkSync(path.join(ICONS_DIR, `${baseName}.svg`));
|
|
||||||
deletedCount++;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If keeping, prefer color
|
|
||||||
if (info.hasColor) {
|
|
||||||
// Rename color version to base version (overwrite mono if exists)
|
|
||||||
const colorPath = path.join(ICONS_DIR, `${baseName}-color.svg`);
|
|
||||||
const targetPath = path.join(ICONS_DIR, `${baseName}.svg`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// If mono exists, it will be overwritten/replaced
|
|
||||||
fs.renameSync(colorPath, targetPath);
|
|
||||||
renamedCount++;
|
|
||||||
keptCount++;
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Error renaming ${baseName}:`, e);
|
|
||||||
}
|
|
||||||
} else if (info.hasMono) {
|
|
||||||
// Keep mono if no color version
|
|
||||||
keptCount++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`\nCleanup complete:`);
|
|
||||||
console.log(`- Kept: ${keptCount}`);
|
|
||||||
console.log(`- Deleted: ${deletedCount}`);
|
|
||||||
console.log(`- Renamed (Color -> Standard): ${renamedCount}`);
|
|
||||||
|
|
||||||
// Regenerate index and metadata
|
|
||||||
require('./generate-icon-index.js');
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const ICONS_DIR = path.join(__dirname, '../src/icons/extracted');
|
|
||||||
const INDEX_FILE = path.join(ICONS_DIR, 'index.ts');
|
|
||||||
const METADATA_FILE = path.join(ICONS_DIR, 'metadata.ts');
|
|
||||||
|
|
||||||
// Known metadata from previous configuration
|
|
||||||
const KNOWN_METADATA = {
|
|
||||||
openai: { name: 'openai', displayName: 'OpenAI', category: 'ai-provider', keywords: ['gpt', 'chatgpt'], defaultColor: '#00A67E' },
|
|
||||||
anthropic: { name: 'anthropic', displayName: 'Anthropic', category: 'ai-provider', keywords: ['claude'], defaultColor: '#D4915D' },
|
|
||||||
claude: { name: 'claude', displayName: 'Claude', category: 'ai-provider', keywords: ['anthropic'], defaultColor: '#D4915D' },
|
|
||||||
google: { name: 'google', displayName: 'Google', category: 'ai-provider', keywords: ['gemini', 'bard'], defaultColor: '#4285F4' },
|
|
||||||
gemini: { name: 'gemini', displayName: 'Gemini', category: 'ai-provider', keywords: ['google'], defaultColor: '#4285F4' },
|
|
||||||
deepseek: { name: 'deepseek', displayName: 'DeepSeek', category: 'ai-provider', keywords: ['deep', 'seek'], defaultColor: '#1E88E5' },
|
|
||||||
moonshot: { name: 'moonshot', displayName: 'Moonshot', category: 'ai-provider', keywords: ['kimi', 'moonshot'], defaultColor: '#6366F1' },
|
|
||||||
kimi: { name: 'kimi', displayName: 'Kimi', category: 'ai-provider', keywords: ['moonshot'], defaultColor: '#6366F1' },
|
|
||||||
zhipu: { name: 'zhipu', displayName: 'Zhipu AI', category: 'ai-provider', keywords: ['chatglm', 'glm'], defaultColor: '#0F62FE' },
|
|
||||||
minimax: { name: 'minimax', displayName: 'MiniMax', category: 'ai-provider', keywords: ['minimax'], defaultColor: '#FF6B6B' },
|
|
||||||
baidu: { name: 'baidu', displayName: 'Baidu', category: 'ai-provider', keywords: ['ernie', 'wenxin'], defaultColor: '#2932E1' },
|
|
||||||
alibaba: { name: 'alibaba', displayName: 'Alibaba', category: 'ai-provider', keywords: ['qwen', 'tongyi'], defaultColor: '#FF6A00' },
|
|
||||||
tencent: { name: 'tencent', displayName: 'Tencent', category: 'ai-provider', keywords: ['hunyuan'], defaultColor: '#00A4FF' },
|
|
||||||
meta: { name: 'meta', displayName: 'Meta', category: 'ai-provider', keywords: ['facebook', 'llama'], defaultColor: '#0081FB' },
|
|
||||||
microsoft: { name: 'microsoft', displayName: 'Microsoft', category: 'ai-provider', keywords: ['copilot', 'azure'], defaultColor: '#00A4EF' },
|
|
||||||
cohere: { name: 'cohere', displayName: 'Cohere', category: 'ai-provider', keywords: ['cohere'], defaultColor: '#39594D' },
|
|
||||||
perplexity: { name: 'perplexity', displayName: 'Perplexity', category: 'ai-provider', keywords: ['perplexity'], defaultColor: '#20808D' },
|
|
||||||
packycode: { name: 'packycode', displayName: 'PackyCode', category: 'ai-provider', keywords: ['packycode', 'packy', 'packyapi'], defaultColor: 'currentColor' },
|
|
||||||
mistral: { name: 'mistral', displayName: 'Mistral', category: 'ai-provider', keywords: ['mistral'], defaultColor: '#FF7000' },
|
|
||||||
huggingface: { name: 'huggingface', displayName: 'Hugging Face', category: 'ai-provider', keywords: ['huggingface', 'hf'], defaultColor: '#FFD21E' },
|
|
||||||
aws: { name: 'aws', displayName: 'AWS', category: 'cloud', keywords: ['amazon', 'cloud'], defaultColor: '#FF9900' },
|
|
||||||
azure: { name: 'azure', displayName: 'Azure', category: 'cloud', keywords: ['microsoft', 'cloud'], defaultColor: '#0078D4' },
|
|
||||||
huawei: { name: 'huawei', displayName: 'Huawei', category: 'cloud', keywords: ['huawei', 'cloud'], defaultColor: '#FF0000' },
|
|
||||||
cloudflare: { name: 'cloudflare', displayName: 'Cloudflare', category: 'cloud', keywords: ['cloudflare', 'cdn'], defaultColor: '#F38020' },
|
|
||||||
github: { name: 'github', displayName: 'GitHub', category: 'tool', keywords: ['git', 'version control'], defaultColor: '#181717' },
|
|
||||||
gitlab: { name: 'gitlab', displayName: 'GitLab', category: 'tool', keywords: ['git', 'version control'], defaultColor: '#FC6D26' },
|
|
||||||
docker: { name: 'docker', displayName: 'Docker', category: 'tool', keywords: ['container'], defaultColor: '#2496ED' },
|
|
||||||
kubernetes: { name: 'kubernetes', displayName: 'Kubernetes', category: 'tool', keywords: ['k8s', 'container'], defaultColor: '#326CE5' },
|
|
||||||
vscode: { name: 'vscode', displayName: 'VS Code', category: 'tool', keywords: ['editor', 'ide'], defaultColor: '#007ACC' },
|
|
||||||
settings: { name: 'settings', displayName: 'Settings', category: 'other', keywords: ['config', 'preferences'], defaultColor: '#6B7280' },
|
|
||||||
folder: { name: 'folder', displayName: 'Folder', category: 'other', keywords: ['directory'], defaultColor: '#6B7280' },
|
|
||||||
file: { name: 'file', displayName: 'File', category: 'other', keywords: ['document'], defaultColor: '#6B7280' },
|
|
||||||
link: { name: 'link', displayName: 'Link', category: 'other', keywords: ['url', 'hyperlink'], defaultColor: '#6B7280' },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get all SVG files
|
|
||||||
const files = fs.readdirSync(ICONS_DIR).filter(file => file.endsWith('.svg'));
|
|
||||||
|
|
||||||
console.log(`Found ${files.length} SVG files.`);
|
|
||||||
|
|
||||||
// Generate index.ts
|
|
||||||
const indexContent = `// Auto-generated icon index
|
|
||||||
// Do not edit manually
|
|
||||||
|
|
||||||
export const icons: Record<string, string> = {
|
|
||||||
${files.map(file => {
|
|
||||||
const name = path.basename(file, '.svg');
|
|
||||||
const svg = fs.readFileSync(path.join(ICONS_DIR, file), 'utf-8');
|
|
||||||
const escaped = svg.replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
||||||
return ` '${name}': \`${escaped}\`,`;
|
|
||||||
}).join('\n')}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const iconList = Object.keys(icons);
|
|
||||||
|
|
||||||
export function getIcon(name: string): string {
|
|
||||||
return icons[name.toLowerCase()] || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hasIcon(name: string): boolean {
|
|
||||||
return name.toLowerCase() in icons;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
fs.writeFileSync(INDEX_FILE, indexContent);
|
|
||||||
console.log(`Generated ${INDEX_FILE}`);
|
|
||||||
|
|
||||||
// Generate metadata.ts
|
|
||||||
const metadataEntries = files.map(file => {
|
|
||||||
const name = path.basename(file, '.svg').toLowerCase();
|
|
||||||
const known = KNOWN_METADATA[name];
|
|
||||||
|
|
||||||
if (known) {
|
|
||||||
return ` ${name}: ${JSON.stringify(known)},`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default metadata for unknown icons
|
|
||||||
return ` '${name}': { name: '${name}', displayName: '${name}', category: 'other', keywords: [], defaultColor: 'currentColor' },`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const metadataContent = `// Icon metadata for search and categorization
|
|
||||||
import { IconMetadata } from '@/types/icon';
|
|
||||||
|
|
||||||
export const iconMetadata: Record<string, IconMetadata> = {
|
|
||||||
${metadataEntries.join('\n')}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function getIconMetadata(name: string): IconMetadata | undefined {
|
|
||||||
return iconMetadata[name.toLowerCase()];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function searchIcons(query: string): string[] {
|
|
||||||
const lowerQuery = query.toLowerCase();
|
|
||||||
return Object.values(iconMetadata)
|
|
||||||
.filter(meta =>
|
|
||||||
meta.name.includes(lowerQuery) ||
|
|
||||||
meta.displayName.toLowerCase().includes(lowerQuery) ||
|
|
||||||
meta.keywords.some(k => k.includes(lowerQuery))
|
|
||||||
)
|
|
||||||
.map(meta => meta.name);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
fs.writeFileSync(METADATA_FILE, metadataContent);
|
|
||||||
console.log(`Generated ${METADATA_FILE}`);
|
|
||||||
Generated
+2
-114
@@ -39,18 +39,6 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ahash"
|
|
||||||
version = "0.8.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"once_cell",
|
|
||||||
"version_check",
|
|
||||||
"zerocopy",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
@@ -303,17 +291,6 @@ version = "1.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "auto-launch"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
|
|
||||||
dependencies = [
|
|
||||||
"dirs 4.0.0",
|
|
||||||
"thiserror 1.0.69",
|
|
||||||
"winreg 0.10.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@@ -618,23 +595,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc-switch"
|
name = "cc-switch"
|
||||||
version = "3.7.1"
|
version = "3.6.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"auto-launch",
|
|
||||||
"base64 0.22.1",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
"futures",
|
"futures",
|
||||||
"indexmap 2.11.4",
|
|
||||||
"log",
|
"log",
|
||||||
"objc2 0.5.2",
|
"objc2 0.5.2",
|
||||||
"objc2-app-kit 0.2.2",
|
"objc2-app-kit 0.2.2",
|
||||||
"once_cell",
|
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rquickjs",
|
"rquickjs",
|
||||||
"rusqlite",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
@@ -1010,15 +982,6 @@ dependencies = [
|
|||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dirs"
|
|
||||||
version = "4.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
|
|
||||||
dependencies = [
|
|
||||||
"dirs-sys 0.3.7",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "5.0.1"
|
version = "5.0.1"
|
||||||
@@ -1037,17 +1000,6 @@ dependencies = [
|
|||||||
"dirs-sys 0.5.0",
|
"dirs-sys 0.5.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dirs-sys"
|
|
||||||
version = "0.3.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"redox_users 0.4.6",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-sys"
|
name = "dirs-sys"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -1289,18 +1241,6 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fallible-iterator"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fallible-streaming-iterator"
|
|
||||||
version = "0.1.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
@@ -1839,7 +1779,7 @@ version = "0.12.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash 0.7.8",
|
"ahash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1847,9 +1787,6 @@ name = "hashbrown"
|
|||||||
version = "0.14.5"
|
version = "0.14.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||||
dependencies = [
|
|
||||||
"ahash 0.8.12",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
@@ -1857,15 +1794,6 @@ version = "0.16.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashlink"
|
|
||||||
version = "0.9.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af"
|
|
||||||
dependencies = [
|
|
||||||
"hashbrown 0.14.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
@@ -2436,17 +2364,6 @@ dependencies = [
|
|||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libsqlite3-sys"
|
|
||||||
version = "0.28.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"pkg-config",
|
|
||||||
"vcpkg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -3898,20 +3815,6 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rusqlite"
|
|
||||||
version = "0.31.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.9.4",
|
|
||||||
"fallible-iterator",
|
|
||||||
"fallible-streaming-iterator",
|
|
||||||
"hashlink",
|
|
||||||
"libsqlite3-sys",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-ini"
|
name = "rust-ini"
|
||||||
version = "0.21.3"
|
version = "0.21.3"
|
||||||
@@ -5630,12 +5533,6 @@ version = "1.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5"
|
checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "vcpkg"
|
|
||||||
version = "0.2.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version-compare"
|
name = "version-compare"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -6500,15 +6397,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winreg"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
|
|
||||||
dependencies = [
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winreg"
|
name = "winreg"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cc-switch"
|
name = "cc-switch"
|
||||||
version = "3.7.1"
|
version = "3.6.2"
|
||||||
description = "All-in-One Assistant for Claude Code, Codex & Gemini CLI"
|
description = "Claude Code & Codex 供应商配置管理工具"
|
||||||
authors = ["Jason Young"]
|
authors = ["Jason Young"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/farion1231/cc-switch"
|
repository = "https://github.com/farion1231/cc-switch"
|
||||||
@@ -48,11 +48,6 @@ zip = "2.2"
|
|||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
url = "2.5"
|
url = "2.5"
|
||||||
auto-launch = "0.5"
|
|
||||||
once_cell = "1.21.3"
|
|
||||||
base64 = "0.22"
|
|
||||||
rusqlite = { version = "0.31", features = ["bundled", "backup"] }
|
|
||||||
indexmap = { version = "2", features = ["serde"] }
|
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies]
|
[target.'cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))'.dependencies]
|
||||||
tauri-plugin-single-instance = "2"
|
tauri-plugin-single-instance = "2"
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
"opener:default",
|
"opener:default",
|
||||||
"updater:default",
|
"updater:default",
|
||||||
"core:window:allow-set-skip-taskbar",
|
"core:window:allow-set-skip-taskbar",
|
||||||
"core:window:allow-start-dragging",
|
|
||||||
"process:allow-restart",
|
"process:allow-restart",
|
||||||
"dialog:default"
|
"dialog:default"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -494,11 +494,8 @@ impl MultiAppConfig {
|
|||||||
// 创建提示词对象
|
// 创建提示词对象
|
||||||
let timestamp = std::time::SystemTime::now()
|
let timestamp = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.map(|d| d.as_secs() as i64)
|
.unwrap()
|
||||||
.unwrap_or_else(|_| {
|
.as_secs() as i64;
|
||||||
log::warn!("Failed to get system time, using 0 as timestamp");
|
|
||||||
0
|
|
||||||
});
|
|
||||||
|
|
||||||
let id = format!("auto-imported-{timestamp}");
|
let id = format!("auto-imported-{timestamp}");
|
||||||
let prompt = crate::prompt::Prompt {
|
let prompt = crate::prompt::Prompt {
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
use crate::error::AppError;
|
|
||||||
use auto_launch::AutoLaunch;
|
|
||||||
|
|
||||||
/// 初始化 AutoLaunch 实例
|
|
||||||
fn get_auto_launch() -> Result<AutoLaunch, AppError> {
|
|
||||||
let app_name = "CC Switch";
|
|
||||||
let app_path =
|
|
||||||
std::env::current_exe().map_err(|e| AppError::Message(format!("无法获取应用路径: {e}")))?;
|
|
||||||
|
|
||||||
let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), false, &[] as &[&str]);
|
|
||||||
Ok(auto_launch)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 启用开机自启
|
|
||||||
pub fn enable_auto_launch() -> Result<(), AppError> {
|
|
||||||
let auto_launch = get_auto_launch()?;
|
|
||||||
auto_launch
|
|
||||||
.enable()
|
|
||||||
.map_err(|e| AppError::Message(format!("启用开机自启失败: {e}")))?;
|
|
||||||
log::info!("已启用开机自启");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 禁用开机自启
|
|
||||||
pub fn disable_auto_launch() -> Result<(), AppError> {
|
|
||||||
let auto_launch = get_auto_launch()?;
|
|
||||||
auto_launch
|
|
||||||
.disable()
|
|
||||||
.map_err(|e| AppError::Message(format!("禁用开机自启失败: {e}")))?;
|
|
||||||
log::info!("已禁用开机自启");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 检查是否已启用开机自启
|
|
||||||
pub fn is_auto_launch_enabled() -> Result<bool, AppError> {
|
|
||||||
let auto_launch = get_auto_launch()?;
|
|
||||||
auto_launch
|
|
||||||
.is_enabled()
|
|
||||||
.map_err(|e| AppError::Message(format!("检查开机自启状态失败: {e}")))
|
|
||||||
}
|
|
||||||
@@ -29,7 +29,6 @@ pub fn get_codex_config_path() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 获取 Codex 供应商配置文件路径
|
/// 获取 Codex 供应商配置文件路径
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get_codex_provider_paths(
|
pub fn get_codex_provider_paths(
|
||||||
provider_id: &str,
|
provider_id: &str,
|
||||||
provider_name: Option<&str>,
|
provider_name: Option<&str>,
|
||||||
@@ -45,7 +44,6 @@ pub fn get_codex_provider_paths(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 删除 Codex 供应商配置文件
|
/// 删除 Codex 供应商配置文件
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn delete_codex_provider_config(
|
pub fn delete_codex_provider_config(
|
||||||
provider_id: &str,
|
provider_id: &str,
|
||||||
provider_name: &str,
|
provider_name: &str,
|
||||||
|
|||||||
@@ -141,10 +141,11 @@ pub async fn open_app_config_folder(handle: AppHandle) -> Result<bool, String> {
|
|||||||
pub async fn get_claude_common_config_snippet(
|
pub async fn get_claude_common_config_snippet(
|
||||||
state: tauri::State<'_, crate::store::AppState>,
|
state: tauri::State<'_, crate::store::AppState>,
|
||||||
) -> Result<Option<String>, String> {
|
) -> Result<Option<String>, String> {
|
||||||
state
|
let guard = state
|
||||||
.db
|
.config
|
||||||
.get_config_snippet("claude")
|
.read()
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| format!("读取配置锁失败: {e}"))?;
|
||||||
|
Ok(guard.common_config_snippets.claude.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 设置 Claude 通用配置片段(已废弃,使用 set_common_config_snippet)
|
/// 设置 Claude 通用配置片段(已废弃,使用 set_common_config_snippet)
|
||||||
@@ -153,22 +154,24 @@ pub async fn set_claude_common_config_snippet(
|
|||||||
snippet: String,
|
snippet: String,
|
||||||
state: tauri::State<'_, crate::store::AppState>,
|
state: tauri::State<'_, crate::store::AppState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
let mut guard = state
|
||||||
|
.config
|
||||||
|
.write()
|
||||||
|
.map_err(|e| format!("写入配置锁失败: {e}"))?;
|
||||||
|
|
||||||
// 验证是否为有效的 JSON(如果不为空)
|
// 验证是否为有效的 JSON(如果不为空)
|
||||||
if !snippet.trim().is_empty() {
|
if !snippet.trim().is_empty() {
|
||||||
serde_json::from_str::<serde_json::Value>(&snippet)
|
serde_json::from_str::<serde_json::Value>(&snippet)
|
||||||
.map_err(|e| format!("无效的 JSON 格式: {e}"))?;
|
.map_err(|e| format!("无效的 JSON 格式: {e}"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = if snippet.trim().is_empty() {
|
guard.common_config_snippets.claude = if snippet.trim().is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(snippet)
|
Some(snippet)
|
||||||
};
|
};
|
||||||
|
|
||||||
state
|
guard.save().map_err(|e| e.to_string())?;
|
||||||
.db
|
|
||||||
.set_config_snippet("claude", value)
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,10 +181,17 @@ pub async fn get_common_config_snippet(
|
|||||||
app_type: String,
|
app_type: String,
|
||||||
state: tauri::State<'_, crate::store::AppState>,
|
state: tauri::State<'_, crate::store::AppState>,
|
||||||
) -> Result<Option<String>, String> {
|
) -> Result<Option<String>, String> {
|
||||||
state
|
use crate::app_config::AppType;
|
||||||
.db
|
use std::str::FromStr;
|
||||||
.get_config_snippet(&app_type)
|
|
||||||
.map_err(|e| e.to_string())
|
let app = AppType::from_str(&app_type).map_err(|e| format!("无效的应用类型: {e}"))?;
|
||||||
|
|
||||||
|
let guard = state
|
||||||
|
.config
|
||||||
|
.read()
|
||||||
|
.map_err(|e| format!("读取配置锁失败: {e}"))?;
|
||||||
|
|
||||||
|
Ok(guard.common_config_snippets.get(&app).cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 设置通用配置片段(统一接口)
|
/// 设置通用配置片段(统一接口)
|
||||||
@@ -191,31 +201,40 @@ pub async fn set_common_config_snippet(
|
|||||||
snippet: String,
|
snippet: String,
|
||||||
state: tauri::State<'_, crate::store::AppState>,
|
state: tauri::State<'_, crate::store::AppState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
use crate::app_config::AppType;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
let app = AppType::from_str(&app_type).map_err(|e| format!("无效的应用类型: {e}"))?;
|
||||||
|
|
||||||
|
let mut guard = state
|
||||||
|
.config
|
||||||
|
.write()
|
||||||
|
.map_err(|e| format!("写入配置锁失败: {e}"))?;
|
||||||
|
|
||||||
// 验证格式(根据应用类型)
|
// 验证格式(根据应用类型)
|
||||||
if !snippet.trim().is_empty() {
|
if !snippet.trim().is_empty() {
|
||||||
match app_type.as_str() {
|
match app {
|
||||||
"claude" | "gemini" => {
|
AppType::Claude | AppType::Gemini => {
|
||||||
// 验证 JSON 格式
|
// 验证 JSON 格式
|
||||||
serde_json::from_str::<serde_json::Value>(&snippet)
|
serde_json::from_str::<serde_json::Value>(&snippet)
|
||||||
.map_err(|e| format!("无效的 JSON 格式: {e}"))?;
|
.map_err(|e| format!("无效的 JSON 格式: {e}"))?;
|
||||||
}
|
}
|
||||||
"codex" => {
|
AppType::Codex => {
|
||||||
// TOML 格式暂不验证(或可使用 toml crate)
|
// TOML 格式暂不验证(或可使用 toml crate)
|
||||||
// 注意:TOML 验证较为复杂,暂时跳过
|
// 注意:TOML 验证较为复杂,暂时跳过
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = if snippet.trim().is_empty() {
|
guard.common_config_snippets.set(
|
||||||
|
&app,
|
||||||
|
if snippet.trim().is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(snippet)
|
Some(snippet)
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
|
||||||
state
|
guard.save().map_err(|e| e.to_string())?;
|
||||||
.db
|
|
||||||
.set_config_snippet(&app_type, value)
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::deeplink::{
|
use crate::deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
||||||
import_mcp_from_deeplink, import_prompt_from_deeplink, import_provider_from_deeplink,
|
|
||||||
import_skill_from_deeplink, parse_deeplink_url, DeepLinkImportRequest,
|
|
||||||
};
|
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
@@ -12,24 +9,14 @@ pub fn parse_deeplink(url: String) -> Result<DeepLinkImportRequest, String> {
|
|||||||
parse_deeplink_url(&url).map_err(|e| e.to_string())
|
parse_deeplink_url(&url).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Merge configuration from Base64/URL into a deep link request
|
/// Import a provider from a deep link request (after user confirmation)
|
||||||
/// This is used by the frontend to show the complete configuration in the confirmation dialog
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn merge_deeplink_config(
|
|
||||||
request: DeepLinkImportRequest,
|
|
||||||
) -> Result<DeepLinkImportRequest, String> {
|
|
||||||
log::info!("Merging config for deep link request: {:?}", request.name);
|
|
||||||
crate::deeplink::parse_and_merge_config(&request).map_err(|e| e.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Import a provider from a deep link request (legacy, kept for compatibility)
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn import_from_deeplink(
|
pub fn import_from_deeplink(
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
request: DeepLinkImportRequest,
|
request: DeepLinkImportRequest,
|
||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Importing provider from deep link: {:?} for app {:?}",
|
"Importing provider from deep link: {} for app {}",
|
||||||
request.name,
|
request.name,
|
||||||
request.app
|
request.app
|
||||||
);
|
);
|
||||||
@@ -40,50 +27,3 @@ pub fn import_from_deeplink(
|
|||||||
|
|
||||||
Ok(provider_id)
|
Ok(provider_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import resource from a deep link request (unified handler)
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn import_from_deeplink_unified(
|
|
||||||
state: State<'_, AppState>,
|
|
||||||
request: DeepLinkImportRequest,
|
|
||||||
) -> Result<serde_json::Value, String> {
|
|
||||||
log::info!("Importing {} resource from deep link", request.resource);
|
|
||||||
|
|
||||||
match request.resource.as_str() {
|
|
||||||
"provider" => {
|
|
||||||
let provider_id =
|
|
||||||
import_provider_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
||||||
Ok(serde_json::json!({
|
|
||||||
"type": "provider",
|
|
||||||
"id": provider_id
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
"prompt" => {
|
|
||||||
let prompt_id =
|
|
||||||
import_prompt_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
||||||
Ok(serde_json::json!({
|
|
||||||
"type": "prompt",
|
|
||||||
"id": prompt_id
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
"mcp" => {
|
|
||||||
let result = import_mcp_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
||||||
// Add type field to the result
|
|
||||||
Ok(serde_json::json!({
|
|
||||||
"type": "mcp",
|
|
||||||
"importedCount": result.imported_count,
|
|
||||||
"importedIds": result.imported_ids,
|
|
||||||
"failed": result.failed
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
"skill" => {
|
|
||||||
let skill_key =
|
|
||||||
import_skill_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
||||||
Ok(serde_json::json!({
|
|
||||||
"type": "skill",
|
|
||||||
"key": skill_key
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
_ => Err(format!("Unsupported resource type: {}", request.resource)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,22 +6,20 @@ use tauri::State;
|
|||||||
use tauri_plugin_dialog::DialogExt;
|
use tauri_plugin_dialog::DialogExt;
|
||||||
|
|
||||||
use crate::error::AppError;
|
use crate::error::AppError;
|
||||||
use crate::services::provider::ProviderService;
|
use crate::services::ConfigService;
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
|
|
||||||
/// 导出数据库为 SQL 备份
|
/// 导出配置文件
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn export_config_to_file(
|
pub async fn export_config_to_file(
|
||||||
#[allow(non_snake_case)] filePath: String,
|
#[allow(non_snake_case)] filePath: String,
|
||||||
state: State<'_, AppState>,
|
|
||||||
) -> Result<Value, String> {
|
) -> Result<Value, String> {
|
||||||
let db = state.db.clone();
|
|
||||||
tauri::async_runtime::spawn_blocking(move || {
|
tauri::async_runtime::spawn_blocking(move || {
|
||||||
let target_path = PathBuf::from(&filePath);
|
let target_path = PathBuf::from(&filePath);
|
||||||
db.export_sql(&target_path)?;
|
ConfigService::export_config_to_path(&target_path)?;
|
||||||
Ok::<_, AppError>(json!({
|
Ok::<_, AppError>(json!({
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "SQL exported successfully",
|
"message": "Configuration exported successfully",
|
||||||
"filePath": filePath
|
"filePath": filePath
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
@@ -30,49 +28,51 @@ pub async fn export_config_to_file(
|
|||||||
.map_err(|e: AppError| e.to_string())
|
.map_err(|e: AppError| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 SQL 备份导入数据库
|
/// 从文件导入配置
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn import_config_from_file(
|
pub async fn import_config_from_file(
|
||||||
#[allow(non_snake_case)] filePath: String,
|
#[allow(non_snake_case)] filePath: String,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<Value, String> {
|
) -> Result<Value, String> {
|
||||||
let db = state.db.clone();
|
let (new_config, backup_id) = tauri::async_runtime::spawn_blocking(move || {
|
||||||
let db_for_state = db.clone();
|
|
||||||
tauri::async_runtime::spawn_blocking(move || {
|
|
||||||
let path_buf = PathBuf::from(&filePath);
|
let path_buf = PathBuf::from(&filePath);
|
||||||
let backup_id = db.import_sql(&path_buf)?;
|
ConfigService::load_config_for_import(&path_buf)
|
||||||
|
|
||||||
// 导入后同步当前供应商到各自的 live 配置
|
|
||||||
let app_state = AppState::new(db_for_state);
|
|
||||||
if let Err(err) = ProviderService::sync_current_from_db(&app_state) {
|
|
||||||
log::warn!("导入后同步 live 配置失败: {err}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok::<_, AppError>(json!({
|
|
||||||
"success": true,
|
|
||||||
"message": "SQL imported successfully",
|
|
||||||
"backupId": backup_id
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("导入配置失败: {e}"))?
|
.map_err(|e| format!("导入配置失败: {e}"))?
|
||||||
.map_err(|e: AppError| e.to_string())
|
.map_err(|e: AppError| e.to_string())?;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut guard = state
|
||||||
|
.config
|
||||||
|
.write()
|
||||||
|
.map_err(|e| AppError::from(e).to_string())?;
|
||||||
|
*guard = new_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(json!({
|
||||||
|
"success": true,
|
||||||
|
"message": "Configuration imported successfully",
|
||||||
|
"backupId": backup_id
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 同步当前供应商配置到对应的 live 文件
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn sync_current_providers_live(state: State<'_, AppState>) -> Result<Value, String> {
|
pub async fn sync_current_providers_live(state: State<'_, AppState>) -> Result<Value, String> {
|
||||||
let db = state.db.clone();
|
{
|
||||||
tauri::async_runtime::spawn_blocking(move || {
|
let mut config_state = state
|
||||||
let app_state = AppState::new(db);
|
.config
|
||||||
ProviderService::sync_current_from_db(&app_state)?;
|
.write()
|
||||||
Ok::<_, AppError>(json!({
|
.map_err(|e| AppError::from(e).to_string())?;
|
||||||
|
ConfigService::sync_current_providers_to_live(&mut config_state)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(json!({
|
||||||
"success": true,
|
"success": true,
|
||||||
"message": "Live configuration synchronized"
|
"message": "Live configuration synchronized"
|
||||||
}))
|
}))
|
||||||
})
|
|
||||||
.await
|
|
||||||
.map_err(|e| format!("同步当前供应商失败: {e}"))?
|
|
||||||
.map_err(|e: AppError| e.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 保存文件对话框
|
/// 保存文件对话框
|
||||||
@@ -84,7 +84,7 @@ pub async fn save_file_dialog<R: tauri::Runtime>(
|
|||||||
let dialog = app.dialog();
|
let dialog = app.dialog();
|
||||||
let result = dialog
|
let result = dialog
|
||||||
.file()
|
.file()
|
||||||
.add_filter("SQL", &["sql"])
|
.add_filter("JSON", &["json"])
|
||||||
.set_file_name(&defaultName)
|
.set_file_name(&defaultName)
|
||||||
.blocking_save_file();
|
.blocking_save_file();
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ pub async fn open_file_dialog<R: tauri::Runtime>(
|
|||||||
let dialog = app.dialog();
|
let dialog = app.dialog();
|
||||||
let result = dialog
|
let result = dialog
|
||||||
.file()
|
.file()
|
||||||
.add_filter("SQL", &["sql"])
|
.add_filter("JSON", &["json"])
|
||||||
.blocking_pick_file();
|
.blocking_pick_file();
|
||||||
|
|
||||||
Ok(result.map(|p| p.to_string()))
|
Ok(result.map(|p| p.to_string()))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -83,8 +82,12 @@ pub async fn upsert_mcp_server_in_config(
|
|||||||
|
|
||||||
// 读取现有的服务器(如果存在)
|
// 读取现有的服务器(如果存在)
|
||||||
let existing_server = {
|
let existing_server = {
|
||||||
let servers = state.db.get_all_mcp_servers().map_err(|e| e.to_string())?;
|
let cfg = state.config.read().map_err(|e| e.to_string())?;
|
||||||
|
if let Some(servers) = &cfg.mcp.servers {
|
||||||
servers.get(&id).cloned()
|
servers.get(&id).cloned()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 构建新的统一服务器结构
|
// 构建新的统一服务器结构
|
||||||
@@ -162,7 +165,7 @@ use crate::app_config::McpServer;
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_mcp_servers(
|
pub async fn get_mcp_servers(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<IndexMap<String, McpServer>, String> {
|
) -> Result<HashMap<String, McpServer>, String> {
|
||||||
McpService::get_all_servers(&state).map_err(|e| e.to_string())
|
McpService::get_all_servers(&state).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use indexmap::IndexMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
@@ -12,7 +12,7 @@ use crate::store::AppState;
|
|||||||
pub async fn get_prompts(
|
pub async fn get_prompts(
|
||||||
app: String,
|
app: String,
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
) -> Result<IndexMap<String, Prompt>, String> {
|
) -> Result<HashMap<String, Prompt>, String> {
|
||||||
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
||||||
PromptService::get_prompts(&state, app_type).map_err(|e| e.to_string())
|
PromptService::get_prompts(&state, app_type).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use indexmap::IndexMap;
|
use std::collections::HashMap;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
use crate::app_config::AppType;
|
use crate::app_config::AppType;
|
||||||
@@ -13,7 +13,7 @@ use std::str::FromStr;
|
|||||||
pub fn get_providers(
|
pub fn get_providers(
|
||||||
state: State<'_, AppState>,
|
state: State<'_, AppState>,
|
||||||
app: String,
|
app: String,
|
||||||
) -> Result<IndexMap<String, Provider>, String> {
|
) -> Result<HashMap<String, Provider>, String> {
|
||||||
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
let app_type = AppType::from_str(&app).map_err(|e| e.to_string())?;
|
||||||
ProviderService::list(state.inner(), app_type).map_err(|e| e.to_string())
|
ProviderService::list(state.inner(), app_type).map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,20 +37,3 @@ pub async fn set_app_config_dir_override(
|
|||||||
crate::app_store::set_app_config_dir_to_store(&app, path.as_deref())?;
|
crate::app_store::set_app_config_dir_to_store(&app, path.as_deref())?;
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 设置开机自启
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn set_auto_launch(enabled: bool) -> Result<bool, String> {
|
|
||||||
if enabled {
|
|
||||||
crate::auto_launch::enable_auto_launch().map_err(|e| format!("启用开机自启失败: {e}"))?;
|
|
||||||
} else {
|
|
||||||
crate::auto_launch::disable_auto_launch().map_err(|e| format!("禁用开机自启失败: {e}"))?;
|
|
||||||
}
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 获取开机自启状态
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn get_auto_launch_status() -> Result<bool, String> {
|
|
||||||
crate::auto_launch::is_auto_launch_enabled().map_err(|e| format!("获取开机自启状态失败: {e}"))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::error::format_skill_error;
|
|
||||||
use crate::services::skill::SkillState;
|
use crate::services::skill::SkillState;
|
||||||
use crate::services::{Skill, SkillRepo, SkillService};
|
use crate::services::{Skill, SkillRepo, SkillService};
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
@@ -13,34 +12,16 @@ pub async fn get_skills(
|
|||||||
service: State<'_, SkillServiceState>,
|
service: State<'_, SkillServiceState>,
|
||||||
app_state: State<'_, AppState>,
|
app_state: State<'_, AppState>,
|
||||||
) -> Result<Vec<Skill>, String> {
|
) -> Result<Vec<Skill>, String> {
|
||||||
let repos = app_state.db.get_skill_repos().map_err(|e| e.to_string())?;
|
let repos = {
|
||||||
|
let config = app_state.config.read().map_err(|e| e.to_string())?;
|
||||||
|
config.skills.repos.clone()
|
||||||
|
};
|
||||||
|
|
||||||
let skills = service
|
service
|
||||||
.0
|
.0
|
||||||
.list_skills(repos)
|
.list_skills(repos)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())
|
||||||
|
|
||||||
// 自动同步本地已安装的 skills 到数据库
|
|
||||||
// 这样用户在首次运行时,已有的 skills 会被自动记录
|
|
||||||
let existing_states = app_state.db.get_skills().unwrap_or_default();
|
|
||||||
|
|
||||||
for skill in &skills {
|
|
||||||
if skill.installed && !existing_states.contains_key(&skill.directory) {
|
|
||||||
// 本地有该 skill,但数据库中没有记录,自动添加
|
|
||||||
if let Err(e) = app_state.db.update_skill_state(
|
|
||||||
&skill.directory,
|
|
||||||
&SkillState {
|
|
||||||
installed: true,
|
|
||||||
installed_at: Utc::now(),
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
log::warn!("同步本地 skill {} 状态到数据库失败: {}", skill.directory, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(skills)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -50,7 +31,10 @@ pub async fn install_skill(
|
|||||||
app_state: State<'_, AppState>,
|
app_state: State<'_, AppState>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
// 先在不持有写锁的情况下收集仓库与技能信息
|
// 先在不持有写锁的情况下收集仓库与技能信息
|
||||||
let repos = app_state.db.get_skill_repos().map_err(|e| e.to_string())?;
|
let repos = {
|
||||||
|
let config = app_state.config.read().map_err(|e| e.to_string())?;
|
||||||
|
config.skills.repos.clone()
|
||||||
|
};
|
||||||
|
|
||||||
let skills = service
|
let skills = service
|
||||||
.0
|
.0
|
||||||
@@ -61,36 +45,24 @@ pub async fn install_skill(
|
|||||||
let skill = skills
|
let skill = skills
|
||||||
.iter()
|
.iter()
|
||||||
.find(|s| s.directory.eq_ignore_ascii_case(&directory))
|
.find(|s| s.directory.eq_ignore_ascii_case(&directory))
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| "技能不存在".to_string())?;
|
||||||
format_skill_error(
|
|
||||||
"SKILL_NOT_FOUND",
|
|
||||||
&[("directory", &directory)],
|
|
||||||
Some("checkRepoUrl"),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if !skill.installed {
|
if !skill.installed {
|
||||||
let repo = SkillRepo {
|
let repo = SkillRepo {
|
||||||
owner: skill.repo_owner.clone().ok_or_else(|| {
|
owner: skill
|
||||||
format_skill_error(
|
.repo_owner
|
||||||
"MISSING_REPO_INFO",
|
.clone()
|
||||||
&[("directory", &directory), ("field", "owner")],
|
.ok_or_else(|| "缺少仓库信息".to_string())?,
|
||||||
None,
|
name: skill
|
||||||
)
|
.repo_name
|
||||||
})?,
|
.clone()
|
||||||
name: skill.repo_name.clone().ok_or_else(|| {
|
.ok_or_else(|| "缺少仓库信息".to_string())?,
|
||||||
format_skill_error(
|
|
||||||
"MISSING_REPO_INFO",
|
|
||||||
&[("directory", &directory), ("field", "name")],
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
})?,
|
|
||||||
branch: skill
|
branch: skill
|
||||||
.repo_branch
|
.repo_branch
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| "main".to_string()),
|
.unwrap_or_else(|| "main".to_string()),
|
||||||
enabled: true,
|
enabled: true,
|
||||||
skills_path: skill.skills_path.clone(), // 使用技能记录的 skills_path
|
skills_path: None, // 安装时使用默认路径
|
||||||
};
|
};
|
||||||
|
|
||||||
service
|
service
|
||||||
@@ -100,16 +72,19 @@ pub async fn install_skill(
|
|||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_state
|
{
|
||||||
.db
|
let mut config = app_state.config.write().map_err(|e| e.to_string())?;
|
||||||
.update_skill_state(
|
|
||||||
&directory,
|
config.skills.skills.insert(
|
||||||
&SkillState {
|
directory.clone(),
|
||||||
|
SkillState {
|
||||||
installed: true,
|
installed: true,
|
||||||
installed_at: Utc::now(),
|
installed_at: Utc::now(),
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.map_err(|e| e.to_string())?;
|
}
|
||||||
|
|
||||||
|
app_state.save().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@@ -125,17 +100,13 @@ pub fn uninstall_skill(
|
|||||||
.uninstall_skill(directory.clone())
|
.uninstall_skill(directory.clone())
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
// Remove from database by setting installed = false
|
{
|
||||||
app_state
|
let mut config = app_state.config.write().map_err(|e| e.to_string())?;
|
||||||
.db
|
|
||||||
.update_skill_state(
|
config.skills.skills.remove(&directory);
|
||||||
&directory,
|
}
|
||||||
&SkillState {
|
|
||||||
installed: false,
|
app_state.save().map_err(|e| e.to_string())?;
|
||||||
installed_at: Utc::now(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@@ -145,19 +116,28 @@ pub fn get_skill_repos(
|
|||||||
_service: State<'_, SkillServiceState>,
|
_service: State<'_, SkillServiceState>,
|
||||||
app_state: State<'_, AppState>,
|
app_state: State<'_, AppState>,
|
||||||
) -> Result<Vec<SkillRepo>, String> {
|
) -> Result<Vec<SkillRepo>, String> {
|
||||||
app_state.db.get_skill_repos().map_err(|e| e.to_string())
|
let config = app_state.config.read().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
Ok(config.skills.repos.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn add_skill_repo(
|
pub fn add_skill_repo(
|
||||||
repo: SkillRepo,
|
repo: SkillRepo,
|
||||||
_service: State<'_, SkillServiceState>,
|
service: State<'_, SkillServiceState>,
|
||||||
app_state: State<'_, AppState>,
|
app_state: State<'_, AppState>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
app_state
|
{
|
||||||
.db
|
let mut config = app_state.config.write().map_err(|e| e.to_string())?;
|
||||||
.save_skill_repo(&repo)
|
|
||||||
|
service
|
||||||
|
.0
|
||||||
|
.add_repo(&mut config.skills, repo)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
app_state.save().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,12 +145,19 @@ pub fn add_skill_repo(
|
|||||||
pub fn remove_skill_repo(
|
pub fn remove_skill_repo(
|
||||||
owner: String,
|
owner: String,
|
||||||
name: String,
|
name: String,
|
||||||
_service: State<'_, SkillServiceState>,
|
service: State<'_, SkillServiceState>,
|
||||||
app_state: State<'_, AppState>,
|
app_state: State<'_, AppState>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
app_state
|
{
|
||||||
.db
|
let mut config = app_state.config.write().map_err(|e| e.to_string())?;
|
||||||
.delete_skill_repo(&owner, &name)
|
|
||||||
|
service
|
||||||
|
.0
|
||||||
|
.remove_repo(&mut config.skills, owner, name)
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
app_state.save().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ pub fn get_app_config_path() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 清理供应商名称,确保文件名安全
|
/// 清理供应商名称,确保文件名安全
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn sanitize_provider_name(name: &str) -> String {
|
pub fn sanitize_provider_name(name: &str) -> String {
|
||||||
name.chars()
|
name.chars()
|
||||||
.map(|c| match c {
|
.map(|c| match c {
|
||||||
@@ -91,7 +90,6 @@ pub fn sanitize_provider_name(name: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 获取供应商配置文件路径
|
/// 获取供应商配置文件路径
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get_provider_config_path(provider_id: &str, provider_name: Option<&str>) -> PathBuf {
|
pub fn get_provider_config_path(provider_id: &str, provider_name: Option<&str>) -> PathBuf {
|
||||||
let base_name = provider_name
|
let base_name = provider_name
|
||||||
.map(sanitize_provider_name)
|
.map(sanitize_provider_name)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+65
-1299
File diff suppressed because it is too large
Load Diff
@@ -50,8 +50,6 @@ pub enum AppError {
|
|||||||
zh: String,
|
zh: String,
|
||||||
en: String,
|
en: String,
|
||||||
},
|
},
|
||||||
#[error("数据库错误: {0}")]
|
|
||||||
Database(String),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppError {
|
impl AppError {
|
||||||
@@ -96,28 +94,3 @@ impl From<AppError> for String {
|
|||||||
err.to_string()
|
err.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 格式化为 JSON 错误字符串,前端可解析为结构化错误
|
|
||||||
pub fn format_skill_error(
|
|
||||||
code: &str,
|
|
||||||
context: &[(&str, &str)],
|
|
||||||
suggestion: Option<&str>,
|
|
||||||
) -> String {
|
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
let mut ctx_map = serde_json::Map::new();
|
|
||||||
for (key, value) in context {
|
|
||||||
ctx_map.insert(key.to_string(), json!(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
let error_obj = json!({
|
|
||||||
"code": code,
|
|
||||||
"context": ctx_map,
|
|
||||||
"suggestion": suggestion,
|
|
||||||
});
|
|
||||||
|
|
||||||
serde_json::to_string(&error_obj).unwrap_or_else(|_| {
|
|
||||||
// 如果 JSON 序列化失败,返回简单格式
|
|
||||||
format!("ERROR:{code}")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -236,17 +236,6 @@ pub fn validate_gemini_settings(settings: &Value) -> Result<(), AppError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果有 config 字段,验证它是对象或 null
|
|
||||||
if let Some(config) = settings.get("config") {
|
|
||||||
if !(config.is_object() || config.is_null()) {
|
|
||||||
return Err(AppError::localized(
|
|
||||||
"gemini.validation.invalid_config",
|
|
||||||
"Gemini 配置格式错误: config 必须是对象",
|
|
||||||
"Gemini config invalid: config must be an object",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,9 +244,6 @@ pub fn validate_gemini_settings(settings: &Value) -> Result<(), AppError> {
|
|||||||
/// 此函数在切换供应商时使用,确保配置包含所有必需的字段。
|
/// 此函数在切换供应商时使用,确保配置包含所有必需的字段。
|
||||||
/// 对于需要 API Key 的供应商(如 PackyCode),会验证 GEMINI_API_KEY 字段。
|
/// 对于需要 API Key 的供应商(如 PackyCode),会验证 GEMINI_API_KEY 字段。
|
||||||
pub fn validate_gemini_settings_strict(settings: &Value) -> Result<(), AppError> {
|
pub fn validate_gemini_settings_strict(settings: &Value) -> Result<(), AppError> {
|
||||||
// 先做基础格式验证(包含 env/config 类型)
|
|
||||||
validate_gemini_settings(settings)?;
|
|
||||||
|
|
||||||
let env_map = json_to_env(settings)?;
|
let env_map = json_to_env(settings)?;
|
||||||
|
|
||||||
// 如果 env 为空,表示使用 OAuth(如 Google 官方),跳过验证
|
// 如果 env 为空,表示使用 OAuth(如 Google 官方),跳过验证
|
||||||
@@ -382,7 +368,7 @@ mod tests {
|
|||||||
# Comment line
|
# Comment line
|
||||||
GOOGLE_GEMINI_BASE_URL=https://example.com
|
GOOGLE_GEMINI_BASE_URL=https://example.com
|
||||||
GEMINI_API_KEY=sk-test123
|
GEMINI_API_KEY=sk-test123
|
||||||
GEMINI_MODEL=gemini-3-pro-preview
|
GEMINI_MODEL=gemini-2.5-pro
|
||||||
|
|
||||||
# Another comment
|
# Another comment
|
||||||
"#;
|
"#;
|
||||||
@@ -395,25 +381,19 @@ GEMINI_MODEL=gemini-3-pro-preview
|
|||||||
Some(&"https://example.com".to_string())
|
Some(&"https://example.com".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(map.get("GEMINI_API_KEY"), Some(&"sk-test123".to_string()));
|
assert_eq!(map.get("GEMINI_API_KEY"), Some(&"sk-test123".to_string()));
|
||||||
assert_eq!(
|
assert_eq!(map.get("GEMINI_MODEL"), Some(&"gemini-2.5-pro".to_string()));
|
||||||
map.get("GEMINI_MODEL"),
|
|
||||||
Some(&"gemini-3-pro-preview".to_string())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_env_file() {
|
fn test_serialize_env_file() {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("GEMINI_API_KEY".to_string(), "sk-test".to_string());
|
map.insert("GEMINI_API_KEY".to_string(), "sk-test".to_string());
|
||||||
map.insert(
|
map.insert("GEMINI_MODEL".to_string(), "gemini-2.5-pro".to_string());
|
||||||
"GEMINI_MODEL".to_string(),
|
|
||||||
"gemini-3-pro-preview".to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let content = serialize_env_file(&map);
|
let content = serialize_env_file(&map);
|
||||||
|
|
||||||
assert!(content.contains("GEMINI_API_KEY=sk-test"));
|
assert!(content.contains("GEMINI_API_KEY=sk-test"));
|
||||||
assert!(content.contains("GEMINI_MODEL=gemini-3-pro-preview"));
|
assert!(content.contains("GEMINI_MODEL=gemini-2.5-pro"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -437,7 +417,7 @@ GEMINI_MODEL=gemini-3-pro-preview
|
|||||||
# Comment line
|
# Comment line
|
||||||
GOOGLE_GEMINI_BASE_URL=https://example.com
|
GOOGLE_GEMINI_BASE_URL=https://example.com
|
||||||
GEMINI_API_KEY=sk-test123
|
GEMINI_API_KEY=sk-test123
|
||||||
GEMINI_MODEL=gemini-3-pro-preview
|
GEMINI_MODEL=gemini-2.5-pro
|
||||||
|
|
||||||
# Another comment
|
# Another comment
|
||||||
"#;
|
"#;
|
||||||
@@ -452,10 +432,7 @@ GEMINI_MODEL=gemini-3-pro-preview
|
|||||||
Some(&"https://example.com".to_string())
|
Some(&"https://example.com".to_string())
|
||||||
);
|
);
|
||||||
assert_eq!(map.get("GEMINI_API_KEY"), Some(&"sk-test123".to_string()));
|
assert_eq!(map.get("GEMINI_API_KEY"), Some(&"sk-test123".to_string()));
|
||||||
assert_eq!(
|
assert_eq!(map.get("GEMINI_MODEL"), Some(&"gemini-2.5-pro".to_string()));
|
||||||
map.get("GEMINI_MODEL"),
|
|
||||||
Some(&"gemini-3-pro-preview".to_string())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -621,7 +598,7 @@ KEY_WITH-DASH=value";
|
|||||||
let settings = serde_json::json!({
|
let settings = serde_json::json!({
|
||||||
"env": {
|
"env": {
|
||||||
"GEMINI_API_KEY": "sk-test123",
|
"GEMINI_API_KEY": "sk-test123",
|
||||||
"GEMINI_MODEL": "gemini-3-pro-preview"
|
"GEMINI_MODEL": "gemini-2.5-pro"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -634,7 +611,7 @@ KEY_WITH-DASH=value";
|
|||||||
// 测试缺少 API Key 的非空配置在基本验证中可以通过(用户稍后填写)
|
// 测试缺少 API Key 的非空配置在基本验证中可以通过(用户稍后填写)
|
||||||
let settings = serde_json::json!({
|
let settings = serde_json::json!({
|
||||||
"env": {
|
"env": {
|
||||||
"GEMINI_MODEL": "gemini-3-pro-preview"
|
"GEMINI_MODEL": "gemini-2.5-pro"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -96,20 +96,7 @@ pub fn set_mcp_servers_map(
|
|||||||
obj = server_obj;
|
obj = server_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gemini CLI 格式转换:
|
// 移除 UI 辅助字段
|
||||||
// - Gemini 不使用 "type" 字段(从字段名推断传输类型)
|
|
||||||
// - HTTP 使用 "httpUrl" 字段,SSE 使用 "url" 字段
|
|
||||||
let transport_type = obj.get("type").and_then(|v| v.as_str());
|
|
||||||
if transport_type == Some("http") {
|
|
||||||
// HTTP streaming: 将 "url" 重命名为 "httpUrl"
|
|
||||||
if let Some(url_value) = obj.remove("url") {
|
|
||||||
obj.insert("httpUrl".to_string(), url_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// SSE 保持 "url" 字段不变
|
|
||||||
|
|
||||||
// 移除 UI 辅助字段和 type 字段(Gemini 不需要)
|
|
||||||
obj.remove("type");
|
|
||||||
obj.remove("enabled");
|
obj.remove("enabled");
|
||||||
obj.remove("source");
|
obj.remove("source");
|
||||||
obj.remove("id");
|
obj.remove("id");
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ fn cell() -> &'static RwLock<Option<InitErrorPayload>> {
|
|||||||
INIT_ERROR.get_or_init(|| RwLock::new(None))
|
INIT_ERROR.get_or_init(|| RwLock::new(None))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn set_init_error(payload: InitErrorPayload) {
|
pub fn set_init_error(payload: InitErrorPayload) {
|
||||||
#[allow(clippy::unwrap_used)]
|
|
||||||
if let Ok(mut guard) = cell().write() {
|
if let Ok(mut guard) = cell().write() {
|
||||||
*guard = Some(payload);
|
*guard = Some(payload);
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-184
@@ -1,12 +1,10 @@
|
|||||||
mod app_config;
|
mod app_config;
|
||||||
mod app_store;
|
mod app_store;
|
||||||
mod auto_launch;
|
|
||||||
mod claude_mcp;
|
mod claude_mcp;
|
||||||
mod claude_plugin;
|
mod claude_plugin;
|
||||||
mod codex_config;
|
mod codex_config;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod config;
|
mod config;
|
||||||
mod database;
|
|
||||||
mod deeplink;
|
mod deeplink;
|
||||||
mod error;
|
mod error;
|
||||||
mod gemini_config; // 新增
|
mod gemini_config; // 新增
|
||||||
@@ -16,7 +14,6 @@ mod mcp;
|
|||||||
mod prompt;
|
mod prompt;
|
||||||
mod prompt_files;
|
mod prompt_files;
|
||||||
mod provider;
|
mod provider;
|
||||||
mod provider_defaults;
|
|
||||||
mod services;
|
mod services;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod store;
|
mod store;
|
||||||
@@ -26,7 +23,6 @@ pub use app_config::{AppType, McpApps, McpServer, MultiAppConfig};
|
|||||||
pub use codex_config::{get_codex_auth_path, get_codex_config_path, write_codex_live_atomic};
|
pub use codex_config::{get_codex_auth_path, get_codex_config_path, write_codex_live_atomic};
|
||||||
pub use commands::*;
|
pub use commands::*;
|
||||||
pub use config::{get_claude_mcp_path, get_claude_settings_path, read_json_file};
|
pub use config::{get_claude_mcp_path, get_claude_settings_path, read_json_file};
|
||||||
pub use database::Database;
|
|
||||||
pub use deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
pub use deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
||||||
pub use error::AppError;
|
pub use error::AppError;
|
||||||
pub use mcp::{
|
pub use mcp::{
|
||||||
@@ -208,6 +204,8 @@ fn create_tray_menu(
|
|||||||
let app_settings = crate::settings::get_settings();
|
let app_settings = crate::settings::get_settings();
|
||||||
let tray_texts = TrayTexts::from_language(app_settings.language.as_deref().unwrap_or("zh"));
|
let tray_texts = TrayTexts::from_language(app_settings.language.as_deref().unwrap_or("zh"));
|
||||||
|
|
||||||
|
let config = app_state.config.read().map_err(AppError::from)?;
|
||||||
|
|
||||||
let mut menu_builder = MenuBuilder::new(app);
|
let mut menu_builder = MenuBuilder::new(app);
|
||||||
|
|
||||||
// 顶部:打开主界面
|
// 顶部:打开主界面
|
||||||
@@ -218,20 +216,13 @@ fn create_tray_menu(
|
|||||||
|
|
||||||
// 直接添加所有供应商到主菜单(扁平化结构,更简单可靠)
|
// 直接添加所有供应商到主菜单(扁平化结构,更简单可靠)
|
||||||
for section in TRAY_SECTIONS.iter() {
|
for section in TRAY_SECTIONS.iter() {
|
||||||
let app_type_str = section.app_type.as_str();
|
menu_builder = append_provider_section(
|
||||||
let providers = app_state.db.get_all_providers(app_type_str)?;
|
app,
|
||||||
let current_id = app_state
|
menu_builder,
|
||||||
.db
|
config.get_manager(§ion.app_type),
|
||||||
.get_current_provider(app_type_str)?
|
section,
|
||||||
.unwrap_or_default();
|
&tray_texts,
|
||||||
|
)?;
|
||||||
let manager = crate::provider::ProviderManager {
|
|
||||||
providers,
|
|
||||||
current: current_id,
|
|
||||||
};
|
|
||||||
|
|
||||||
menu_builder =
|
|
||||||
append_provider_section(app, menu_builder, Some(&manager), section, &tray_texts)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分隔符和退出菜单
|
// 分隔符和退出菜单
|
||||||
@@ -315,7 +306,7 @@ fn handle_deeplink_url(
|
|||||||
match crate::deeplink::parse_deeplink_url(url_str) {
|
match crate::deeplink::parse_deeplink_url(url_str) {
|
||||||
Ok(request) => {
|
Ok(request) => {
|
||||||
log::info!(
|
log::info!(
|
||||||
"✓ Successfully parsed deep link: resource={}, app={:?}, name={:?}",
|
"✓ Successfully parsed deep link: resource={}, app={}, name={}",
|
||||||
request.resource,
|
request.resource,
|
||||||
request.app,
|
request.app,
|
||||||
request.name
|
request.name
|
||||||
@@ -496,11 +487,10 @@ pub fn run() {
|
|||||||
use objc2::runtime::AnyObject;
|
use objc2::runtime::AnyObject;
|
||||||
use objc2_app_kit::NSColor;
|
use objc2_app_kit::NSColor;
|
||||||
|
|
||||||
match window.ns_window() {
|
let ns_window_ptr = window.ns_window().unwrap();
|
||||||
Ok(ns_window_ptr) => {
|
let ns_window: Retained<AnyObject> =
|
||||||
if let Some(ns_window) =
|
unsafe { Retained::retain(ns_window_ptr as *mut AnyObject).unwrap() };
|
||||||
unsafe { Retained::retain(ns_window_ptr as *mut AnyObject) }
|
|
||||||
{
|
|
||||||
// 使用与主界面 banner 相同的蓝色 #3498db
|
// 使用与主界面 banner 相同的蓝色 #3498db
|
||||||
// #3498db = RGB(52, 152, 219)
|
// #3498db = RGB(52, 152, 219)
|
||||||
let bg_color = unsafe {
|
let bg_color = unsafe {
|
||||||
@@ -516,12 +506,6 @@ pub fn run() {
|
|||||||
use objc2::msg_send;
|
use objc2::msg_send;
|
||||||
let _: () = msg_send![&*ns_window, setBackgroundColor: &*bg_color];
|
let _: () = msg_send![&*ns_window, setBackgroundColor: &*bg_color];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log::warn!("Failed to retain NSWindow reference");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => log::warn!("Failed to get NSWindow pointer: {e}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,157 +521,42 @@ pub fn run() {
|
|||||||
// 预先刷新 Store 覆盖配置,确保 AppState 初始化时可读取到最新路径
|
// 预先刷新 Store 覆盖配置,确保 AppState 初始化时可读取到最新路径
|
||||||
app_store::refresh_app_config_dir_override(app.handle());
|
app_store::refresh_app_config_dir_override(app.handle());
|
||||||
|
|
||||||
// 初始化数据库
|
// 初始化应用状态(仅创建一次,并在本函数末尾注入 manage)
|
||||||
let app_config_dir = crate::config::get_app_config_dir();
|
// 如果配置解析失败,则向前端发送错误事件并提前结束 setup(不落盘、不覆盖配置)。
|
||||||
let db_path = app_config_dir.join("cc-switch.db");
|
let app_state = match AppState::try_new() {
|
||||||
let json_path = app_config_dir.join("config.json");
|
Ok(state) => state,
|
||||||
|
Err(err) => {
|
||||||
// Check if migration is needed (DB doesn't exist but JSON does)
|
let path = crate::config::get_app_config_path();
|
||||||
let migration_needed = !db_path.exists() && json_path.exists();
|
let payload_json = serde_json::json!({
|
||||||
|
"path": path.display().to_string(),
|
||||||
let db = match crate::database::Database::init() {
|
"error": err.to_string(),
|
||||||
Ok(db) => Arc::new(db),
|
});
|
||||||
Err(e) => {
|
// 事件通知(可能早于前端订阅,不保证送达)
|
||||||
log::error!("Failed to init database: {e}");
|
if let Err(e) = app.emit("configLoadError", payload_json) {
|
||||||
// 这里的错误处理比较棘手,因为 setup 返回 Result<Box<dyn Error>>
|
log::error!("发射配置加载错误事件失败: {e}");
|
||||||
// 我们暂时记录日志并让应用继续运行(可能会崩溃)或者返回错误
|
}
|
||||||
return Err(Box::new(e));
|
// 同时缓存错误,供前端启动阶段主动拉取
|
||||||
|
crate::init_status::set_init_error(crate::init_status::InitErrorPayload {
|
||||||
|
path: path.display().to_string(),
|
||||||
|
error: err.to_string(),
|
||||||
|
});
|
||||||
|
// 不再继续构建托盘/命令依赖的状态,交由前端提示后退出。
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if migration_needed {
|
|
||||||
log::info!("Starting migration from config.json to SQLite...");
|
|
||||||
match crate::app_config::MultiAppConfig::load() {
|
|
||||||
Ok(config) => {
|
|
||||||
if let Err(e) = db.migrate_from_json(&config) {
|
|
||||||
log::error!("Migration failed: {e}");
|
|
||||||
} else {
|
|
||||||
log::info!("Migration successful");
|
|
||||||
// Optional: Rename config.json
|
|
||||||
// let _ = std::fs::rename(&json_path, json_path.with_extension("json.bak"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => log::error!("Failed to load config.json for migration: {e}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
crate::settings::bind_db(db.clone());
|
|
||||||
let app_state = AppState::new(db);
|
|
||||||
|
|
||||||
// 检查是否需要首次导入(数据库为空)
|
|
||||||
let need_first_import = app_state
|
|
||||||
.db
|
|
||||||
.is_empty_for_first_import()
|
|
||||||
.unwrap_or_else(|e| {
|
|
||||||
log::warn!("Failed to check if database is empty: {e}");
|
|
||||||
false
|
|
||||||
});
|
|
||||||
|
|
||||||
if need_first_import {
|
|
||||||
// 数据库为空,尝试从用户现有的配置文件导入数据并初始化默认配置
|
|
||||||
log::info!(
|
|
||||||
"Empty database detected, importing existing configurations and initializing defaults..."
|
|
||||||
);
|
|
||||||
|
|
||||||
// 1. 初始化默认 Skills 仓库(3个)
|
|
||||||
match app_state.db.init_default_skill_repos() {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Initialized {count} default skill repositories");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("No default skill repositories to initialize"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to initialize default skill repos: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 导入供应商配置(从 live 配置文件)
|
|
||||||
for app in [
|
|
||||||
crate::app_config::AppType::Claude,
|
|
||||||
crate::app_config::AppType::Codex,
|
|
||||||
crate::app_config::AppType::Gemini,
|
|
||||||
] {
|
|
||||||
match crate::services::provider::ProviderService::import_default_config(
|
|
||||||
&app_state,
|
|
||||||
app.clone(),
|
|
||||||
) {
|
|
||||||
Ok(_) => {
|
|
||||||
log::info!("✓ Imported default provider for {}", app.as_str());
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::debug!(
|
|
||||||
"○ No default provider to import for {}: {}",
|
|
||||||
app.as_str(),
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 导入 MCP 服务器配置
|
|
||||||
match crate::services::mcp::McpService::import_from_claude(&app_state) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} MCP server(s) from Claude");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Claude MCP servers found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Claude MCP: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::services::mcp::McpService::import_from_codex(&app_state) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} MCP server(s) from Codex");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Codex MCP servers found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Codex MCP: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::services::mcp::McpService::import_from_gemini(&app_state) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} MCP server(s) from Gemini");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Gemini MCP servers found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Gemini MCP: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 导入提示词文件
|
|
||||||
match crate::services::prompt::PromptService::import_from_file_on_first_launch(
|
|
||||||
&app_state,
|
|
||||||
crate::app_config::AppType::Claude,
|
|
||||||
) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} prompt(s) from Claude");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Claude prompt file found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Claude prompt: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::services::prompt::PromptService::import_from_file_on_first_launch(
|
|
||||||
&app_state,
|
|
||||||
crate::app_config::AppType::Codex,
|
|
||||||
) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} prompt(s) from Codex");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Codex prompt file found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Codex prompt: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::services::prompt::PromptService::import_from_file_on_first_launch(
|
|
||||||
&app_state,
|
|
||||||
crate::app_config::AppType::Gemini,
|
|
||||||
) {
|
|
||||||
Ok(count) if count > 0 => {
|
|
||||||
log::info!("✓ Imported {count} prompt(s) from Gemini");
|
|
||||||
}
|
|
||||||
Ok(_) => log::debug!("○ No Gemini prompt file found to import"),
|
|
||||||
Err(e) => log::warn!("✗ Failed to import Gemini prompt: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
log::info!("First-time import completed");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 迁移旧的 app_config_dir 配置到 Store
|
// 迁移旧的 app_config_dir 配置到 Store
|
||||||
if let Err(e) = app_store::migrate_app_config_dir_from_settings(app.handle()) {
|
if let Err(e) = app_store::migrate_app_config_dir_from_settings(app.handle()) {
|
||||||
log::warn!("迁移 app_config_dir 失败: {e}");
|
log::warn!("迁移 app_config_dir 失败: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保配置结构就绪(已移除旧版本的副本迁移逻辑)
|
||||||
|
{
|
||||||
|
let mut config_guard = app_state.config.write().unwrap();
|
||||||
|
config_guard.ensure_app(&app_config::AppType::Claude);
|
||||||
|
config_guard.ensure_app(&app_config::AppType::Codex);
|
||||||
|
}
|
||||||
|
|
||||||
// 启动阶段不再无条件保存,避免意外覆盖用户配置。
|
// 启动阶段不再无条件保存,避免意外覆盖用户配置。
|
||||||
|
|
||||||
// 注册 deep-link URL 处理器(使用正确的 DeepLinkExt API)
|
// 注册 deep-link URL 处理器(使用正确的 DeepLinkExt API)
|
||||||
@@ -740,11 +609,7 @@ pub fn run() {
|
|||||||
.show_menu_on_left_click(true);
|
.show_menu_on_left_click(true);
|
||||||
|
|
||||||
// 统一使用应用默认图标;待托盘模板图标就绪后再启用
|
// 统一使用应用默认图标;待托盘模板图标就绪后再启用
|
||||||
if let Some(icon) = app.default_window_icon() {
|
tray_builder = tray_builder.icon(app.default_window_icon().unwrap().clone());
|
||||||
tray_builder = tray_builder.icon(icon.clone());
|
|
||||||
} else {
|
|
||||||
log::warn!("Failed to get default window icon for tray");
|
|
||||||
}
|
|
||||||
|
|
||||||
let _tray = tray_builder.build(app)?;
|
let _tray = tray_builder.build(app)?;
|
||||||
// 将同一个实例注入到全局状态,避免重复创建导致的不一致
|
// 将同一个实例注入到全局状态,避免重复创建导致的不一致
|
||||||
@@ -839,9 +704,7 @@ pub fn run() {
|
|||||||
commands::sync_current_providers_live,
|
commands::sync_current_providers_live,
|
||||||
// Deep link import
|
// Deep link import
|
||||||
commands::parse_deeplink,
|
commands::parse_deeplink,
|
||||||
commands::merge_deeplink_config,
|
|
||||||
commands::import_from_deeplink,
|
commands::import_from_deeplink,
|
||||||
commands::import_from_deeplink_unified,
|
|
||||||
update_tray_menu,
|
update_tray_menu,
|
||||||
// Environment variable management
|
// Environment variable management
|
||||||
commands::check_env_conflicts,
|
commands::check_env_conflicts,
|
||||||
@@ -854,9 +717,6 @@ pub fn run() {
|
|||||||
commands::get_skill_repos,
|
commands::get_skill_repos,
|
||||||
commands::add_skill_repo,
|
commands::add_skill_repo,
|
||||||
commands::remove_skill_repo,
|
commands::remove_skill_repo,
|
||||||
// Auto launch
|
|
||||||
commands::set_auto_launch,
|
|
||||||
commands::get_auto_launch_status,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let app = builder
|
let app = builder
|
||||||
@@ -891,7 +751,7 @@ pub fn run() {
|
|||||||
match crate::deeplink::parse_deeplink_url(&url_str) {
|
match crate::deeplink::parse_deeplink_url(&url_str) {
|
||||||
Ok(request) => {
|
Ok(request) => {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={:?}",
|
"Successfully parsed deep link from RunEvent::Opened: resource={}, app={}",
|
||||||
request.resource,
|
request.resource,
|
||||||
request.app
|
request.app
|
||||||
);
|
);
|
||||||
|
|||||||
+18
-29
@@ -348,7 +348,10 @@ pub fn import_from_claude(config: &mut MultiAppConfig) -> Result<usize, AppError
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 确保新结构存在
|
// 确保新结构存在
|
||||||
let servers = config.mcp.servers.get_or_insert_with(HashMap::new);
|
if config.mcp.servers.is_none() {
|
||||||
|
config.mcp.servers = Some(HashMap::new());
|
||||||
|
}
|
||||||
|
let servers = config.mcp.servers.as_mut().unwrap();
|
||||||
|
|
||||||
let mut changed = 0;
|
let mut changed = 0;
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
@@ -418,7 +421,10 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
|
|||||||
.map_err(|e| AppError::McpValidation(format!("解析 ~/.codex/config.toml 失败: {e}")))?;
|
.map_err(|e| AppError::McpValidation(format!("解析 ~/.codex/config.toml 失败: {e}")))?;
|
||||||
|
|
||||||
// 确保新结构存在
|
// 确保新结构存在
|
||||||
let servers = config.mcp.servers.get_or_insert_with(HashMap::new);
|
if config.mcp.servers.is_none() {
|
||||||
|
config.mcp.servers = Some(HashMap::new());
|
||||||
|
}
|
||||||
|
let servers = config.mcp.servers.as_mut().unwrap();
|
||||||
|
|
||||||
let mut changed_total = 0usize;
|
let mut changed_total = 0usize;
|
||||||
|
|
||||||
@@ -443,7 +449,7 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
|
|||||||
// 核心字段(需要手动处理的字段)
|
// 核心字段(需要手动处理的字段)
|
||||||
let core_fields = match typ {
|
let core_fields = match typ {
|
||||||
"stdio" => vec!["type", "command", "args", "env", "cwd"],
|
"stdio" => vec!["type", "command", "args", "env", "cwd"],
|
||||||
"http" | "sse" => vec!["type", "url", "http_headers"],
|
"http" | "sse" => vec!["type", "url", "headers"],
|
||||||
_ => vec!["type"],
|
_ => vec!["type"],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -484,13 +490,7 @@ pub fn import_from_codex(config: &mut MultiAppConfig) -> Result<usize, AppError>
|
|||||||
if let Some(url) = entry_tbl.get("url").and_then(|v| v.as_str()) {
|
if let Some(url) = entry_tbl.get("url").and_then(|v| v.as_str()) {
|
||||||
spec.insert("url".into(), json!(url));
|
spec.insert("url".into(), json!(url));
|
||||||
}
|
}
|
||||||
// Read from http_headers (correct Codex format) or headers (legacy) with priority to http_headers
|
if let Some(headers_tbl) = entry_tbl.get("headers").and_then(|v| v.as_table()) {
|
||||||
let headers_tbl = entry_tbl
|
|
||||||
.get("http_headers")
|
|
||||||
.and_then(|v| v.as_table())
|
|
||||||
.or_else(|| entry_tbl.get("headers").and_then(|v| v.as_table()));
|
|
||||||
|
|
||||||
if let Some(headers_tbl) = headers_tbl {
|
|
||||||
let mut headers_json = serde_json::Map::new();
|
let mut headers_json = serde_json::Map::new();
|
||||||
for (k, v) in headers_tbl.iter() {
|
for (k, v) in headers_tbl.iter() {
|
||||||
if let Some(sv) = v.as_str() {
|
if let Some(sv) = v.as_str() {
|
||||||
@@ -718,7 +718,10 @@ pub fn import_from_gemini(config: &mut MultiAppConfig) -> Result<usize, AppError
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 确保新结构存在
|
// 确保新结构存在
|
||||||
let servers = config.mcp.servers.get_or_insert_with(HashMap::new);
|
if config.mcp.servers.is_none() {
|
||||||
|
config.mcp.servers = Some(HashMap::new());
|
||||||
|
}
|
||||||
|
let servers = config.mcp.servers.as_mut().unwrap();
|
||||||
|
|
||||||
let mut changed = 0;
|
let mut changed = 0;
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
@@ -843,22 +846,8 @@ fn json_value_to_toml_item(value: &Value, field_name: &str) -> Option<toml_edit:
|
|||||||
for item in arr {
|
for item in arr {
|
||||||
match item {
|
match item {
|
||||||
Value::String(s) => toml_arr.push(s.as_str()),
|
Value::String(s) => toml_arr.push(s.as_str()),
|
||||||
Value::Number(n) if n.is_i64() => {
|
Value::Number(n) if n.is_i64() => toml_arr.push(n.as_i64().unwrap()),
|
||||||
if let Some(i) = n.as_i64() {
|
Value::Number(n) if n.is_f64() => toml_arr.push(n.as_f64().unwrap()),
|
||||||
toml_arr.push(i);
|
|
||||||
} else {
|
|
||||||
all_same_type = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Value::Number(n) if n.is_f64() => {
|
|
||||||
if let Some(f) = n.as_f64() {
|
|
||||||
toml_arr.push(f);
|
|
||||||
} else {
|
|
||||||
all_same_type = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Value::Bool(b) => toml_arr.push(*b),
|
Value::Bool(b) => toml_arr.push(*b),
|
||||||
_ => {
|
_ => {
|
||||||
all_same_type = false;
|
all_same_type = false;
|
||||||
@@ -921,7 +910,7 @@ fn json_server_to_toml_table(spec: &Value) -> Result<toml_edit::Table, AppError>
|
|||||||
// 定义核心字段(已在下方处理,跳过通用转换)
|
// 定义核心字段(已在下方处理,跳过通用转换)
|
||||||
let core_fields = match typ {
|
let core_fields = match typ {
|
||||||
"stdio" => vec!["type", "command", "args", "env", "cwd"],
|
"stdio" => vec!["type", "command", "args", "env", "cwd"],
|
||||||
"http" | "sse" => vec!["type", "url", "http_headers"],
|
"http" | "sse" => vec!["type", "url", "headers"],
|
||||||
_ => vec!["type"],
|
_ => vec!["type"],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -999,7 +988,7 @@ fn json_server_to_toml_table(spec: &Value) -> Result<toml_edit::Table, AppError>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !h_tbl.is_empty() {
|
if !h_tbl.is_empty() {
|
||||||
t["http_headers"] = Item::Table(h_tbl);
|
t["headers"] = Item::Table(h_tbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use indexmap::IndexMap;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -29,13 +28,6 @@ pub struct Provider {
|
|||||||
/// 供应商元数据(不写入 live 配置,仅存于 ~/.cc-switch/config.json)
|
/// 供应商元数据(不写入 live 配置,仅存于 ~/.cc-switch/config.json)
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub meta: Option<ProviderMeta>,
|
pub meta: Option<ProviderMeta>,
|
||||||
/// 图标名称(如 "openai", "anthropic")
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub icon: Option<String>,
|
|
||||||
/// 图标颜色(Hex 格式,如 "#00A67E")
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(rename = "iconColor")]
|
|
||||||
pub icon_color: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Provider {
|
impl Provider {
|
||||||
@@ -56,8 +48,6 @@ impl Provider {
|
|||||||
sort_index: None,
|
sort_index: None,
|
||||||
notes: None,
|
notes: None,
|
||||||
meta: None,
|
meta: None,
|
||||||
icon: None,
|
|
||||||
icon_color: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,7 +55,7 @@ impl Provider {
|
|||||||
/// 供应商管理器
|
/// 供应商管理器
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
pub struct ProviderManager {
|
pub struct ProviderManager {
|
||||||
pub providers: IndexMap<String, Provider>,
|
pub providers: HashMap<String, Provider>,
|
||||||
pub current: String,
|
pub current: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +145,7 @@ pub struct ProviderMeta {
|
|||||||
|
|
||||||
impl ProviderManager {
|
impl ProviderManager {
|
||||||
/// 获取所有供应商
|
/// 获取所有供应商
|
||||||
pub fn get_all_providers(&self) -> &IndexMap<String, Provider> {
|
pub fn get_all_providers(&self) -> &HashMap<String, Provider> {
|
||||||
&self.providers
|
&self.providers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,238 +0,0 @@
|
|||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
/// 供应商图标信息
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub struct ProviderIcon {
|
|
||||||
pub name: &'static str,
|
|
||||||
pub color: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 供应商名称到图标的默认映射
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub static DEFAULT_PROVIDER_ICONS: Lazy<HashMap<&'static str, ProviderIcon>> = Lazy::new(|| {
|
|
||||||
let mut m = HashMap::new();
|
|
||||||
|
|
||||||
// AI 服务商
|
|
||||||
m.insert(
|
|
||||||
"openai",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "openai",
|
|
||||||
color: "#00A67E",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"anthropic",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "anthropic",
|
|
||||||
color: "#D4915D",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"claude",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "claude",
|
|
||||||
color: "#D4915D",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"google",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "google",
|
|
||||||
color: "#4285F4",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"gemini",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "gemini",
|
|
||||||
color: "#4285F4",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"deepseek",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "deepseek",
|
|
||||||
color: "#1E88E5",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"kimi",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "kimi",
|
|
||||||
color: "#6366F1",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"moonshot",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "moonshot",
|
|
||||||
color: "#6366F1",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"zhipu",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "zhipu",
|
|
||||||
color: "#0F62FE",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"minimax",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "minimax",
|
|
||||||
color: "#FF6B6B",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"baidu",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "baidu",
|
|
||||||
color: "#2932E1",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"alibaba",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "alibaba",
|
|
||||||
color: "#FF6A00",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"tencent",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "tencent",
|
|
||||||
color: "#00A4FF",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"meta",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "meta",
|
|
||||||
color: "#0081FB",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"microsoft",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "microsoft",
|
|
||||||
color: "#00A4EF",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"cohere",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "cohere",
|
|
||||||
color: "#39594D",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"perplexity",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "perplexity",
|
|
||||||
color: "#20808D",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"mistral",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "mistral",
|
|
||||||
color: "#FF7000",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"huggingface",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "huggingface",
|
|
||||||
color: "#FFD21E",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// 云平台
|
|
||||||
m.insert(
|
|
||||||
"aws",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "aws",
|
|
||||||
color: "#FF9900",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"azure",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "azure",
|
|
||||||
color: "#0078D4",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"huawei",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "huawei",
|
|
||||||
color: "#FF0000",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
m.insert(
|
|
||||||
"cloudflare",
|
|
||||||
ProviderIcon {
|
|
||||||
name: "cloudflare",
|
|
||||||
color: "#F38020",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
m
|
|
||||||
});
|
|
||||||
|
|
||||||
/// 根据供应商名称智能推断图标
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn infer_provider_icon(provider_name: &str) -> Option<ProviderIcon> {
|
|
||||||
let name_lower = provider_name.to_lowercase();
|
|
||||||
|
|
||||||
// 精确匹配
|
|
||||||
if let Some(icon) = DEFAULT_PROVIDER_ICONS.get(name_lower.as_str()) {
|
|
||||||
return Some(icon.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 模糊匹配(包含关键词)
|
|
||||||
for (key, icon) in DEFAULT_PROVIDER_ICONS.iter() {
|
|
||||||
if name_lower.contains(key) {
|
|
||||||
return Some(icon.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_exact_match() {
|
|
||||||
let icon = infer_provider_icon("openai");
|
|
||||||
assert!(icon.is_some());
|
|
||||||
let icon = icon.unwrap();
|
|
||||||
assert_eq!(icon.name, "openai");
|
|
||||||
assert_eq!(icon.color, "#00A67E");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_fuzzy_match() {
|
|
||||||
let icon = infer_provider_icon("OpenAI Official");
|
|
||||||
assert!(icon.is_some());
|
|
||||||
let icon = icon.unwrap();
|
|
||||||
assert_eq!(icon.name, "openai");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_case_insensitive() {
|
|
||||||
let icon = infer_provider_icon("ANTHROPIC");
|
|
||||||
assert!(icon.is_some());
|
|
||||||
assert_eq!(icon.unwrap().name, "anthropic");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_no_match() {
|
|
||||||
let icon = infer_provider_icon("unknown provider");
|
|
||||||
assert!(icon.is_none());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -109,17 +109,7 @@ impl ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 将外部配置文件内容加载并写入应用状态。
|
/// 将外部配置文件内容加载并写入应用状态。
|
||||||
/// TODO: 需要重构以使用数据库而不是 JSON 配置
|
pub fn import_config_from_path(file_path: &Path, state: &AppState) -> Result<String, AppError> {
|
||||||
pub fn import_config_from_path(
|
|
||||||
_file_path: &Path,
|
|
||||||
_state: &AppState,
|
|
||||||
) -> Result<String, AppError> {
|
|
||||||
// TODO: 实现基于数据库的导入逻辑
|
|
||||||
Err(AppError::Message(
|
|
||||||
"配置导入功能正在重构中,暂时不可用".to_string(),
|
|
||||||
))
|
|
||||||
|
|
||||||
/* 旧的实现,需要重构:
|
|
||||||
let (new_config, backup_id) = Self::load_config_for_import(file_path)?;
|
let (new_config, backup_id) = Self::load_config_for_import(file_path)?;
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -128,7 +118,6 @@ impl ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(backup_id)
|
Ok(backup_id)
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 同步当前供应商到对应的 live 配置。
|
/// 同步当前供应商到对应的 live 配置。
|
||||||
@@ -240,23 +229,43 @@ impl ConfigService {
|
|||||||
provider_id: &str,
|
provider_id: &str,
|
||||||
provider: &Provider,
|
provider: &Provider,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
use crate::gemini_config::{env_to_json, read_gemini_env};
|
use crate::gemini_config::{
|
||||||
|
env_to_json, json_to_env, read_gemini_env, write_gemini_env_atomic,
|
||||||
ProviderService::write_gemini_live(provider)?;
|
|
||||||
|
|
||||||
// 读回实际写入的内容并更新到配置中(包含 settings.json)
|
|
||||||
let live_after_env = read_gemini_env()?;
|
|
||||||
let settings_path = crate::gemini_config::get_gemini_settings_path();
|
|
||||||
let live_after_config = if settings_path.exists() {
|
|
||||||
crate::config::read_json_file(&settings_path)?
|
|
||||||
} else {
|
|
||||||
serde_json::json!({})
|
|
||||||
};
|
};
|
||||||
let mut live_after = env_to_json(&live_after_env);
|
|
||||||
if let Some(obj) = live_after.as_object_mut() {
|
let env_path = crate::gemini_config::get_gemini_env_path();
|
||||||
obj.insert("config".to_string(), live_after_config);
|
if let Some(parent) = env_path.parent() {
|
||||||
|
fs::create_dir_all(parent).map_err(|e| AppError::io(parent, e))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 转换 JSON 配置为 .env 格式
|
||||||
|
let env_map = json_to_env(&provider.settings_config)?;
|
||||||
|
|
||||||
|
// Google 官方(OAuth): env 为空,写入空文件并设置安全标志后返回
|
||||||
|
if env_map.is_empty() {
|
||||||
|
write_gemini_env_atomic(&env_map)?;
|
||||||
|
ProviderService::ensure_google_oauth_security_flag(provider)?;
|
||||||
|
|
||||||
|
let live_after_env = read_gemini_env()?;
|
||||||
|
let live_after = env_to_json(&live_after_env);
|
||||||
|
|
||||||
|
if let Some(manager) = config.get_manager_mut(&AppType::Gemini) {
|
||||||
|
if let Some(target) = manager.providers.get_mut(provider_id) {
|
||||||
|
target.settings_config = live_after;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 非 OAuth:按常规写入,并在必要时设置 Packycode 安全标志
|
||||||
|
write_gemini_env_atomic(&env_map)?;
|
||||||
|
ProviderService::ensure_packycode_security_flag(provider)?;
|
||||||
|
|
||||||
|
// 读回实际写入的内容并更新到配置中
|
||||||
|
let live_after_env = read_gemini_env()?;
|
||||||
|
let live_after = env_to_json(&live_after_env);
|
||||||
|
|
||||||
if let Some(manager) = config.get_manager_mut(&AppType::Gemini) {
|
if let Some(manager) = config.get_manager_mut(&AppType::Gemini) {
|
||||||
if let Some(target) = manager.providers.get_mut(provider_id) {
|
if let Some(target) = manager.providers.get_mut(provider_id) {
|
||||||
target.settings_config = live_after;
|
target.settings_config = live_after;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -36,7 +35,6 @@ fn get_keywords_for_app(app: &str) -> Vec<&str> {
|
|||||||
match app.to_lowercase().as_str() {
|
match app.to_lowercase().as_str() {
|
||||||
"claude" => vec!["ANTHROPIC"],
|
"claude" => vec!["ANTHROPIC"],
|
||||||
"codex" => vec!["OPENAI"],
|
"codex" => vec!["OPENAI"],
|
||||||
"gemini" => vec!["GEMINI", "GOOGLE_GEMINI"],
|
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,15 +48,17 @@ fn check_system_env(keywords: &[&str]) -> Result<Vec<EnvConflict>, String> {
|
|||||||
if let Ok(hkcu) = RegKey::predef(HKEY_CURRENT_USER).open_subkey("Environment") {
|
if let Ok(hkcu) = RegKey::predef(HKEY_CURRENT_USER).open_subkey("Environment") {
|
||||||
for (name, value) in hkcu.enum_values().filter_map(Result::ok) {
|
for (name, value) in hkcu.enum_values().filter_map(Result::ok) {
|
||||||
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
|
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
|
||||||
|
if let Ok(val) = value.to_string() {
|
||||||
conflicts.push(EnvConflict {
|
conflicts.push(EnvConflict {
|
||||||
var_name: name.clone(),
|
var_name: name.clone(),
|
||||||
var_value: value.to_string(),
|
var_value: val,
|
||||||
source_type: "system".to_string(),
|
source_type: "system".to_string(),
|
||||||
source_path: "HKEY_CURRENT_USER\\Environment".to_string(),
|
source_path: "HKEY_CURRENT_USER\\Environment".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
|
// Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
|
||||||
if let Ok(hklm) = RegKey::predef(HKEY_LOCAL_MACHINE)
|
if let Ok(hklm) = RegKey::predef(HKEY_LOCAL_MACHINE)
|
||||||
@@ -66,15 +66,17 @@ fn check_system_env(keywords: &[&str]) -> Result<Vec<EnvConflict>, String> {
|
|||||||
{
|
{
|
||||||
for (name, value) in hklm.enum_values().filter_map(Result::ok) {
|
for (name, value) in hklm.enum_values().filter_map(Result::ok) {
|
||||||
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
|
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
|
||||||
|
if let Ok(val) = value.to_string() {
|
||||||
conflicts.push(EnvConflict {
|
conflicts.push(EnvConflict {
|
||||||
var_name: name.clone(),
|
var_name: name.clone(),
|
||||||
var_value: value.to_string(),
|
var_value: val,
|
||||||
source_type: "system".to_string(),
|
source_type: "system".to_string(),
|
||||||
source_path: "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment".to_string(),
|
source_path: "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(conflicts)
|
Ok(conflicts)
|
||||||
}
|
}
|
||||||
@@ -159,10 +161,6 @@ mod tests {
|
|||||||
fn test_get_keywords() {
|
fn test_get_keywords() {
|
||||||
assert_eq!(get_keywords_for_app("claude"), vec!["ANTHROPIC"]);
|
assert_eq!(get_keywords_for_app("claude"), vec!["ANTHROPIC"]);
|
||||||
assert_eq!(get_keywords_for_app("codex"), vec!["OPENAI"]);
|
assert_eq!(get_keywords_for_app("codex"), vec!["OPENAI"]);
|
||||||
assert_eq!(
|
|
||||||
get_keywords_for_app("gemini"),
|
|
||||||
vec!["GEMINI", "GOOGLE_GEMINI"]
|
|
||||||
);
|
|
||||||
assert_eq!(get_keywords_for_app("unknown"), Vec::<&str>::new());
|
assert_eq!(get_keywords_for_app("unknown"), Vec::<&str>::new());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use indexmap::IndexMap;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::app_config::{AppType, McpServer};
|
use crate::app_config::{AppType, McpServer, MultiAppConfig};
|
||||||
use crate::error::AppError;
|
use crate::error::AppError;
|
||||||
use crate::mcp;
|
use crate::mcp;
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
@@ -11,13 +10,40 @@ pub struct McpService;
|
|||||||
|
|
||||||
impl McpService {
|
impl McpService {
|
||||||
/// 获取所有 MCP 服务器(统一结构)
|
/// 获取所有 MCP 服务器(统一结构)
|
||||||
pub fn get_all_servers(state: &AppState) -> Result<IndexMap<String, McpServer>, AppError> {
|
pub fn get_all_servers(state: &AppState) -> Result<HashMap<String, McpServer>, AppError> {
|
||||||
state.db.get_all_mcp_servers()
|
let cfg = state.config.read()?;
|
||||||
|
|
||||||
|
// 如果是新结构,直接返回
|
||||||
|
if let Some(servers) = &cfg.mcp.servers {
|
||||||
|
return Ok(servers.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 理论上不应该走到这里,因为 load 时会自动迁移
|
||||||
|
Err(AppError::localized(
|
||||||
|
"mcp.old_structure",
|
||||||
|
"检测到旧版 MCP 结构,请重启应用完成迁移",
|
||||||
|
"Old MCP structure detected, please restart app to complete migration",
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 添加或更新 MCP 服务器
|
/// 添加或更新 MCP 服务器
|
||||||
pub fn upsert_server(state: &AppState, server: McpServer) -> Result<(), AppError> {
|
pub fn upsert_server(state: &AppState, server: McpServer) -> Result<(), AppError> {
|
||||||
state.db.save_mcp_server(&server)?;
|
{
|
||||||
|
let mut cfg = state.config.write()?;
|
||||||
|
|
||||||
|
// 确保 servers 字段存在
|
||||||
|
if cfg.mcp.servers.is_none() {
|
||||||
|
cfg.mcp.servers = Some(HashMap::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
let servers = cfg.mcp.servers.as_mut().unwrap();
|
||||||
|
let id = server.id.clone();
|
||||||
|
|
||||||
|
// 插入或更新
|
||||||
|
servers.insert(id, server.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
state.save()?;
|
||||||
|
|
||||||
// 同步到各个启用的应用
|
// 同步到各个启用的应用
|
||||||
Self::sync_server_to_apps(state, &server)?;
|
Self::sync_server_to_apps(state, &server)?;
|
||||||
@@ -27,10 +53,18 @@ impl McpService {
|
|||||||
|
|
||||||
/// 删除 MCP 服务器
|
/// 删除 MCP 服务器
|
||||||
pub fn delete_server(state: &AppState, id: &str) -> Result<bool, AppError> {
|
pub fn delete_server(state: &AppState, id: &str) -> Result<bool, AppError> {
|
||||||
let server = state.db.get_all_mcp_servers()?.shift_remove(id);
|
let server = {
|
||||||
|
let mut cfg = state.config.write()?;
|
||||||
|
|
||||||
|
if let Some(servers) = &mut cfg.mcp.servers {
|
||||||
|
servers.remove(id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(server) = server {
|
if let Some(server) = server {
|
||||||
state.db.delete_mcp_server(id)?;
|
state.save()?;
|
||||||
|
|
||||||
// 从所有应用的 live 配置中移除
|
// 从所有应用的 live 配置中移除
|
||||||
Self::remove_server_from_all_apps(state, id, &server)?;
|
Self::remove_server_from_all_apps(state, id, &server)?;
|
||||||
@@ -47,15 +81,27 @@ impl McpService {
|
|||||||
app: AppType,
|
app: AppType,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
let mut servers = state.db.get_all_mcp_servers()?;
|
let server = {
|
||||||
|
let mut cfg = state.config.write()?;
|
||||||
|
|
||||||
|
if let Some(servers) = &mut cfg.mcp.servers {
|
||||||
if let Some(server) = servers.get_mut(server_id) {
|
if let Some(server) = servers.get_mut(server_id) {
|
||||||
server.apps.set_enabled_for(&app, enabled);
|
server.apps.set_enabled_for(&app, enabled);
|
||||||
state.db.save_mcp_server(server)?;
|
Some(server.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(server) = server {
|
||||||
|
state.save()?;
|
||||||
|
|
||||||
// 同步到对应应用
|
// 同步到对应应用
|
||||||
if enabled {
|
if enabled {
|
||||||
Self::sync_server_to_app(state, server, &app)?;
|
Self::sync_server_to_app(state, &server, &app)?;
|
||||||
} else {
|
} else {
|
||||||
Self::remove_server_from_app(state, server_id, &app)?;
|
Self::remove_server_from_app(state, server_id, &app)?;
|
||||||
}
|
}
|
||||||
@@ -65,9 +111,11 @@ impl McpService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 将 MCP 服务器同步到所有启用的应用
|
/// 将 MCP 服务器同步到所有启用的应用
|
||||||
fn sync_server_to_apps(_state: &AppState, server: &McpServer) -> Result<(), AppError> {
|
fn sync_server_to_apps(state: &AppState, server: &McpServer) -> Result<(), AppError> {
|
||||||
|
let cfg = state.config.read()?;
|
||||||
|
|
||||||
for app in server.apps.enabled_apps() {
|
for app in server.apps.enabled_apps() {
|
||||||
Self::sync_server_to_app_no_config(server, &app)?;
|
Self::sync_server_to_app_internal(&cfg, server, &app)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -75,24 +123,28 @@ impl McpService {
|
|||||||
|
|
||||||
/// 将 MCP 服务器同步到指定应用
|
/// 将 MCP 服务器同步到指定应用
|
||||||
fn sync_server_to_app(
|
fn sync_server_to_app(
|
||||||
_state: &AppState,
|
state: &AppState,
|
||||||
server: &McpServer,
|
server: &McpServer,
|
||||||
app: &AppType,
|
app: &AppType,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
Self::sync_server_to_app_no_config(server, app)
|
let cfg = state.config.read()?;
|
||||||
|
Self::sync_server_to_app_internal(&cfg, server, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sync_server_to_app_no_config(server: &McpServer, app: &AppType) -> Result<(), AppError> {
|
fn sync_server_to_app_internal(
|
||||||
|
cfg: &MultiAppConfig,
|
||||||
|
server: &McpServer,
|
||||||
|
app: &AppType,
|
||||||
|
) -> Result<(), AppError> {
|
||||||
match app {
|
match app {
|
||||||
AppType::Claude => {
|
AppType::Claude => {
|
||||||
mcp::sync_single_server_to_claude(&Default::default(), &server.id, &server.server)?;
|
mcp::sync_single_server_to_claude(cfg, &server.id, &server.server)?;
|
||||||
}
|
}
|
||||||
AppType::Codex => {
|
AppType::Codex => {
|
||||||
// Codex uses TOML format, must use the correct function
|
mcp::sync_single_server_to_codex(cfg, &server.id, &server.server)?;
|
||||||
mcp::sync_single_server_to_codex(&Default::default(), &server.id, &server.server)?;
|
|
||||||
}
|
}
|
||||||
AppType::Gemini => {
|
AppType::Gemini => {
|
||||||
mcp::sync_single_server_to_gemini(&Default::default(), &server.id, &server.server)?;
|
mcp::sync_single_server_to_gemini(cfg, &server.id, &server.server)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -181,67 +233,28 @@ impl McpService {
|
|||||||
|
|
||||||
/// 从 Claude 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Claude 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_claude(state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_claude(state: &AppState) -> Result<usize, AppError> {
|
||||||
// 创建临时 MultiAppConfig 用于导入
|
let mut cfg = state.config.write()?;
|
||||||
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
let count = mcp::import_from_claude(&mut cfg)?;
|
||||||
|
drop(cfg);
|
||||||
// 调用原有的导入逻辑(从 mcp.rs)
|
state.save()?;
|
||||||
let count = crate::mcp::import_from_claude(&mut temp_config)?;
|
|
||||||
|
|
||||||
// 如果有导入的服务器,保存到数据库
|
|
||||||
if count > 0 {
|
|
||||||
if let Some(servers) = &temp_config.mcp.servers {
|
|
||||||
for server in servers.values() {
|
|
||||||
state.db.save_mcp_server(server)?;
|
|
||||||
// 同步到 Claude live 配置
|
|
||||||
Self::sync_server_to_apps(state, server)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 Codex 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Codex 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_codex(state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_codex(state: &AppState) -> Result<usize, AppError> {
|
||||||
// 创建临时 MultiAppConfig 用于导入
|
let mut cfg = state.config.write()?;
|
||||||
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
let count = mcp::import_from_codex(&mut cfg)?;
|
||||||
|
drop(cfg);
|
||||||
// 调用原有的导入逻辑(从 mcp.rs)
|
state.save()?;
|
||||||
let count = crate::mcp::import_from_codex(&mut temp_config)?;
|
|
||||||
|
|
||||||
// 如果有导入的服务器,保存到数据库
|
|
||||||
if count > 0 {
|
|
||||||
if let Some(servers) = &temp_config.mcp.servers {
|
|
||||||
for server in servers.values() {
|
|
||||||
state.db.save_mcp_server(server)?;
|
|
||||||
// 同步到 Codex live 配置
|
|
||||||
Self::sync_server_to_apps(state, server)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 从 Gemini 导入 MCP(v3.7.0 已更新为统一结构)
|
/// 从 Gemini 导入 MCP(v3.7.0 已更新为统一结构)
|
||||||
pub fn import_from_gemini(state: &AppState) -> Result<usize, AppError> {
|
pub fn import_from_gemini(state: &AppState) -> Result<usize, AppError> {
|
||||||
// 创建临时 MultiAppConfig 用于导入
|
let mut cfg = state.config.write()?;
|
||||||
let mut temp_config = crate::app_config::MultiAppConfig::default();
|
let count = mcp::import_from_gemini(&mut cfg)?;
|
||||||
|
drop(cfg);
|
||||||
// 调用原有的导入逻辑(从 mcp.rs)
|
state.save()?;
|
||||||
let count = crate::mcp::import_from_gemini(&mut temp_config)?;
|
|
||||||
|
|
||||||
// 如果有导入的服务器,保存到数据库
|
|
||||||
if count > 0 {
|
|
||||||
if let Some(servers) = &temp_config.mcp.servers {
|
|
||||||
for server in servers.values() {
|
|
||||||
state.db.save_mcp_server(server)?;
|
|
||||||
// 同步到 Gemini live 配置
|
|
||||||
Self::sync_server_to_apps(state, server)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(count)
|
Ok(count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use indexmap::IndexMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::app_config::AppType;
|
use crate::app_config::AppType;
|
||||||
use crate::config::write_text_file;
|
use crate::config::write_text_file;
|
||||||
@@ -7,34 +7,40 @@ use crate::prompt::Prompt;
|
|||||||
use crate::prompt_files::prompt_file_path;
|
use crate::prompt_files::prompt_file_path;
|
||||||
use crate::store::AppState;
|
use crate::store::AppState;
|
||||||
|
|
||||||
/// 安全地获取当前 Unix 时间戳
|
|
||||||
fn get_unix_timestamp() -> Result<i64, AppError> {
|
|
||||||
std::time::SystemTime::now()
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.map(|d| d.as_secs() as i64)
|
|
||||||
.map_err(|e| AppError::Message(format!("Failed to get system time: {e}")))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PromptService;
|
pub struct PromptService;
|
||||||
|
|
||||||
impl PromptService {
|
impl PromptService {
|
||||||
pub fn get_prompts(
|
pub fn get_prompts(
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
app: AppType,
|
app: AppType,
|
||||||
) -> Result<IndexMap<String, Prompt>, AppError> {
|
) -> Result<HashMap<String, Prompt>, AppError> {
|
||||||
state.db.get_prompts(app.as_str())
|
let cfg = state.config.read()?;
|
||||||
|
let prompts = match app {
|
||||||
|
AppType::Claude => &cfg.prompts.claude.prompts,
|
||||||
|
AppType::Codex => &cfg.prompts.codex.prompts,
|
||||||
|
AppType::Gemini => &cfg.prompts.gemini.prompts,
|
||||||
|
};
|
||||||
|
Ok(prompts.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert_prompt(
|
pub fn upsert_prompt(
|
||||||
state: &AppState,
|
state: &AppState,
|
||||||
app: AppType,
|
app: AppType,
|
||||||
_id: &str,
|
id: &str,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
// 检查是否为已启用的提示词
|
// 检查是否为已启用的提示词
|
||||||
let is_enabled = prompt.enabled;
|
let is_enabled = prompt.enabled;
|
||||||
|
|
||||||
state.db.save_prompt(app.as_str(), &prompt)?;
|
let mut cfg = state.config.write()?;
|
||||||
|
let prompts = match app {
|
||||||
|
AppType::Claude => &mut cfg.prompts.claude.prompts,
|
||||||
|
AppType::Codex => &mut cfg.prompts.codex.prompts,
|
||||||
|
AppType::Gemini => &mut cfg.prompts.gemini.prompts,
|
||||||
|
};
|
||||||
|
prompts.insert(id.to_string(), prompt.clone());
|
||||||
|
drop(cfg);
|
||||||
|
state.save()?;
|
||||||
|
|
||||||
// 如果是已启用的提示词,同步更新到对应的文件
|
// 如果是已启用的提示词,同步更新到对应的文件
|
||||||
if is_enabled {
|
if is_enabled {
|
||||||
@@ -46,7 +52,12 @@ impl PromptService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_prompt(state: &AppState, app: AppType, id: &str) -> Result<(), AppError> {
|
pub fn delete_prompt(state: &AppState, app: AppType, id: &str) -> Result<(), AppError> {
|
||||||
let prompts = state.db.get_prompts(app.as_str())?;
|
let mut cfg = state.config.write()?;
|
||||||
|
let prompts = match app {
|
||||||
|
AppType::Claude => &mut cfg.prompts.claude.prompts,
|
||||||
|
AppType::Codex => &mut cfg.prompts.codex.prompts,
|
||||||
|
AppType::Gemini => &mut cfg.prompts.gemini.prompts,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(prompt) = prompts.get(id) {
|
if let Some(prompt) = prompts.get(id) {
|
||||||
if prompt.enabled {
|
if prompt.enabled {
|
||||||
@@ -54,7 +65,9 @@ impl PromptService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.db.delete_prompt(app.as_str(), id)?;
|
prompts.remove(id);
|
||||||
|
drop(cfg);
|
||||||
|
state.save()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +77,12 @@ impl PromptService {
|
|||||||
if target_path.exists() {
|
if target_path.exists() {
|
||||||
if let Ok(live_content) = std::fs::read_to_string(&target_path) {
|
if let Ok(live_content) = std::fs::read_to_string(&target_path) {
|
||||||
if !live_content.trim().is_empty() {
|
if !live_content.trim().is_empty() {
|
||||||
let mut prompts = state.db.get_prompts(app.as_str())?;
|
let mut cfg = state.config.write()?;
|
||||||
|
let prompts = match app {
|
||||||
|
AppType::Claude => &mut cfg.prompts.claude.prompts,
|
||||||
|
AppType::Codex => &mut cfg.prompts.codex.prompts,
|
||||||
|
AppType::Gemini => &mut cfg.prompts.gemini.prompts,
|
||||||
|
};
|
||||||
|
|
||||||
// 尝试回填到当前已启用的提示词
|
// 尝试回填到当前已启用的提示词
|
||||||
if let Some((enabled_id, enabled_prompt)) = prompts
|
if let Some((enabled_id, enabled_prompt)) = prompts
|
||||||
@@ -72,11 +90,15 @@ impl PromptService {
|
|||||||
.find(|(_, p)| p.enabled)
|
.find(|(_, p)| p.enabled)
|
||||||
.map(|(id, p)| (id.clone(), p))
|
.map(|(id, p)| (id.clone(), p))
|
||||||
{
|
{
|
||||||
let timestamp = get_unix_timestamp()?;
|
let timestamp = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs() as i64;
|
||||||
enabled_prompt.content = live_content.clone();
|
enabled_prompt.content = live_content.clone();
|
||||||
enabled_prompt.updated_at = Some(timestamp);
|
enabled_prompt.updated_at = Some(timestamp);
|
||||||
log::info!("回填 live 提示词内容到已启用项: {enabled_id}");
|
log::info!("回填 live 提示词内容到已启用项: {enabled_id}");
|
||||||
state.db.save_prompt(app.as_str(), enabled_prompt)?;
|
drop(cfg); // 释放锁后保存,避免死锁
|
||||||
|
state.save()?; // 第一次保存:回填后立即持久化
|
||||||
} else {
|
} else {
|
||||||
// 没有已启用的提示词,则创建一次备份(避免重复备份)
|
// 没有已启用的提示词,则创建一次备份(避免重复备份)
|
||||||
let content_exists = prompts
|
let content_exists = prompts
|
||||||
@@ -100,8 +122,13 @@ impl PromptService {
|
|||||||
created_at: Some(timestamp),
|
created_at: Some(timestamp),
|
||||||
updated_at: Some(timestamp),
|
updated_at: Some(timestamp),
|
||||||
};
|
};
|
||||||
|
prompts.insert(backup_id.clone(), backup_prompt);
|
||||||
log::info!("回填 live 提示词内容,创建备份: {backup_id}");
|
log::info!("回填 live 提示词内容,创建备份: {backup_id}");
|
||||||
state.db.save_prompt(app.as_str(), &backup_prompt)?;
|
drop(cfg); // 释放锁后保存
|
||||||
|
state.save()?; // 第一次保存:回填后立即持久化
|
||||||
|
} else {
|
||||||
|
// 即使内容已存在,也无需重复备份;但不需要保存任何更改
|
||||||
|
drop(cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +136,12 @@ impl PromptService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 启用目标提示词并写入文件
|
// 启用目标提示词并写入文件
|
||||||
let mut prompts = state.db.get_prompts(app.as_str())?;
|
let mut cfg = state.config.write()?;
|
||||||
|
let prompts = match app {
|
||||||
|
AppType::Claude => &mut cfg.prompts.claude.prompts,
|
||||||
|
AppType::Codex => &mut cfg.prompts.codex.prompts,
|
||||||
|
AppType::Gemini => &mut cfg.prompts.gemini.prompts,
|
||||||
|
};
|
||||||
|
|
||||||
for prompt in prompts.values_mut() {
|
for prompt in prompts.values_mut() {
|
||||||
prompt.enabled = false;
|
prompt.enabled = false;
|
||||||
@@ -118,16 +150,12 @@ impl PromptService {
|
|||||||
if let Some(prompt) = prompts.get_mut(id) {
|
if let Some(prompt) = prompts.get_mut(id) {
|
||||||
prompt.enabled = true;
|
prompt.enabled = true;
|
||||||
write_text_file(&target_path, &prompt.content)?; // 原子写入
|
write_text_file(&target_path, &prompt.content)?; // 原子写入
|
||||||
state.db.save_prompt(app.as_str(), prompt)?;
|
|
||||||
} else {
|
} else {
|
||||||
return Err(AppError::InvalidInput(format!("提示词 {id} 不存在")));
|
return Err(AppError::InvalidInput(format!("提示词 {id} 不存在")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save all prompts to disable others
|
drop(cfg);
|
||||||
for (_, prompt) in prompts.iter() {
|
state.save()?; // 第二次保存:启用目标提示词并写入文件后
|
||||||
state.db.save_prompt(app.as_str(), prompt)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +168,10 @@ impl PromptService {
|
|||||||
|
|
||||||
let content =
|
let content =
|
||||||
std::fs::read_to_string(&file_path).map_err(|e| AppError::io(&file_path, e))?;
|
std::fs::read_to_string(&file_path).map_err(|e| AppError::io(&file_path, e))?;
|
||||||
let timestamp = get_unix_timestamp()?;
|
let timestamp = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs() as i64;
|
||||||
|
|
||||||
let id = format!("imported-{timestamp}");
|
let id = format!("imported-{timestamp}");
|
||||||
let prompt = Prompt {
|
let prompt = Prompt {
|
||||||
@@ -169,56 +200,4 @@ impl PromptService {
|
|||||||
std::fs::read_to_string(&file_path).map_err(|e| AppError::io(&file_path, e))?;
|
std::fs::read_to_string(&file_path).map_err(|e| AppError::io(&file_path, e))?;
|
||||||
Ok(Some(content))
|
Ok(Some(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 首次启动时从现有提示词文件自动导入(如果存在)
|
|
||||||
/// 返回导入的数量
|
|
||||||
pub fn import_from_file_on_first_launch(
|
|
||||||
state: &AppState,
|
|
||||||
app: AppType,
|
|
||||||
) -> Result<usize, AppError> {
|
|
||||||
let file_path = prompt_file_path(&app)?;
|
|
||||||
|
|
||||||
// 检查文件是否存在
|
|
||||||
if !file_path.exists() {
|
|
||||||
return Ok(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取文件内容
|
|
||||||
let content = match std::fs::read_to_string(&file_path) {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => {
|
|
||||||
log::warn!("读取提示词文件失败: {file_path:?}, 错误: {e}");
|
|
||||||
return Ok(0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 检查内容是否为空
|
|
||||||
if content.trim().is_empty() {
|
|
||||||
return Ok(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
log::info!("发现提示词文件,自动导入: {file_path:?}");
|
|
||||||
|
|
||||||
// 创建提示词对象
|
|
||||||
let timestamp = get_unix_timestamp()?;
|
|
||||||
let id = format!("auto-imported-{timestamp}");
|
|
||||||
let prompt = Prompt {
|
|
||||||
id: id.clone(),
|
|
||||||
name: format!(
|
|
||||||
"Auto-imported Prompt {}",
|
|
||||||
chrono::Local::now().format("%Y-%m-%d %H:%M")
|
|
||||||
),
|
|
||||||
content,
|
|
||||||
description: Some("Automatically imported on first launch".to_string()),
|
|
||||||
enabled: true, // 首次导入时自动启用
|
|
||||||
created_at: Some(timestamp),
|
|
||||||
updated_at: Some(timestamp),
|
|
||||||
};
|
|
||||||
|
|
||||||
// 保存到数据库
|
|
||||||
state.db.save_prompt(app.as_str(), &prompt)?;
|
|
||||||
|
|
||||||
log::info!("自动导入完成: {}", app.as_str());
|
|
||||||
Ok(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+655
-263
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,6 @@ use std::fs;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
|
|
||||||
use crate::error::format_skill_error;
|
|
||||||
|
|
||||||
/// 技能对象
|
/// 技能对象
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Skill {
|
pub struct Skill {
|
||||||
@@ -34,9 +32,6 @@ pub struct Skill {
|
|||||||
/// 分支名称
|
/// 分支名称
|
||||||
#[serde(rename = "repoBranch")]
|
#[serde(rename = "repoBranch")]
|
||||||
pub repo_branch: Option<String>,
|
pub repo_branch: Option<String>,
|
||||||
/// 技能所在的子目录路径 (可选, 如 "skills")
|
|
||||||
#[serde(rename = "skillsPath")]
|
|
||||||
pub skills_path: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 仓库配置
|
/// 仓库配置
|
||||||
@@ -135,11 +130,7 @@ impl SkillService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_install_dir() -> Result<PathBuf> {
|
fn get_install_dir() -> Result<PathBuf> {
|
||||||
let home = dirs::home_dir().context(format_skill_error(
|
let home = dirs::home_dir().context("无法获取用户主目录")?;
|
||||||
"GET_HOME_DIR_FAILED",
|
|
||||||
&[],
|
|
||||||
Some("checkPermission"),
|
|
||||||
))?;
|
|
||||||
Ok(home.join(".claude").join("skills"))
|
Ok(home.join(".claude").join("skills"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,19 +170,9 @@ impl SkillService {
|
|||||||
/// 从仓库获取技能列表
|
/// 从仓库获取技能列表
|
||||||
async fn fetch_repo_skills(&self, repo: &SkillRepo) -> Result<Vec<Skill>> {
|
async fn fetch_repo_skills(&self, repo: &SkillRepo) -> Result<Vec<Skill>> {
|
||||||
// 为单个仓库加载增加整体超时,避免无效链接长时间阻塞
|
// 为单个仓库加载增加整体超时,避免无效链接长时间阻塞
|
||||||
let temp_dir = timeout(std::time::Duration::from_secs(60), self.download_repo(repo))
|
let temp_dir = timeout(std::time::Duration::from_secs(15), self.download_repo(repo))
|
||||||
.await
|
.await
|
||||||
.map_err(|_| {
|
.map_err(|_| anyhow!("下载仓库 {}/{} 超时", repo.owner, repo.name))??;
|
||||||
anyhow!(format_skill_error(
|
|
||||||
"DOWNLOAD_TIMEOUT",
|
|
||||||
&[
|
|
||||||
("owner", &repo.owner),
|
|
||||||
("name", &repo.name),
|
|
||||||
("timeout", "60")
|
|
||||||
],
|
|
||||||
Some("checkNetwork"),
|
|
||||||
))
|
|
||||||
})??;
|
|
||||||
let mut skills = Vec::new();
|
let mut skills = Vec::new();
|
||||||
|
|
||||||
// 确定要扫描的目录路径
|
// 确定要扫描的目录路径
|
||||||
@@ -231,12 +212,7 @@ impl SkillService {
|
|||||||
// 解析技能元数据
|
// 解析技能元数据
|
||||||
match self.parse_skill_metadata(&skill_md) {
|
match self.parse_skill_metadata(&skill_md) {
|
||||||
Ok(meta) => {
|
Ok(meta) => {
|
||||||
// 安全地获取目录名
|
let directory = path.file_name().unwrap().to_string_lossy().to_string();
|
||||||
let Some(dir_name) = path.file_name() else {
|
|
||||||
log::warn!("Failed to get directory name from path: {path:?}");
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let directory = dir_name.to_string_lossy().to_string();
|
|
||||||
|
|
||||||
// 构建 README URL(考虑 skillsPath)
|
// 构建 README URL(考虑 skillsPath)
|
||||||
let readme_path = if let Some(ref skills_path) = repo.skills_path {
|
let readme_path = if let Some(ref skills_path) = repo.skills_path {
|
||||||
@@ -258,7 +234,6 @@ impl SkillService {
|
|||||||
repo_owner: Some(repo.owner.clone()),
|
repo_owner: Some(repo.owner.clone()),
|
||||||
repo_name: Some(repo.name.clone()),
|
repo_name: Some(repo.name.clone()),
|
||||||
repo_branch: Some(repo.branch.clone()),
|
repo_branch: Some(repo.branch.clone()),
|
||||||
skills_path: repo.skills_path.clone(),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(e) => log::warn!("解析 {} 元数据失败: {}", skill_md.display(), e),
|
Err(e) => log::warn!("解析 {} 元数据失败: {}", skill_md.display(), e),
|
||||||
@@ -310,12 +285,7 @@ impl SkillService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全地获取目录名
|
let directory = path.file_name().unwrap().to_string_lossy().to_string();
|
||||||
let Some(dir_name) = path.file_name() else {
|
|
||||||
log::warn!("Failed to get directory name from path: {path:?}");
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let directory = dir_name.to_string_lossy().to_string();
|
|
||||||
|
|
||||||
// 更新已安装状态
|
// 更新已安装状态
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
@@ -342,7 +312,6 @@ impl SkillService {
|
|||||||
repo_owner: None,
|
repo_owner: None,
|
||||||
repo_name: None,
|
repo_name: None,
|
||||||
repo_branch: None,
|
repo_branch: None,
|
||||||
skills_path: None,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,17 +374,7 @@ impl SkillService {
|
|||||||
// 下载 ZIP
|
// 下载 ZIP
|
||||||
let response = self.http_client.get(url).send().await?;
|
let response = self.http_client.get(url).send().await?;
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
let status = response.status().as_u16().to_string();
|
return Err(anyhow::anyhow!("下载失败: {}", response.status()));
|
||||||
return Err(anyhow::anyhow!(format_skill_error(
|
|
||||||
"DOWNLOAD_FAILED",
|
|
||||||
&[("status", &status)],
|
|
||||||
match status.as_str() {
|
|
||||||
"403" => Some("http403"),
|
|
||||||
"404" => Some("http404"),
|
|
||||||
"429" => Some("http429"),
|
|
||||||
_ => Some("checkNetwork"),
|
|
||||||
},
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bytes = response.bytes().await?;
|
let bytes = response.bytes().await?;
|
||||||
@@ -430,11 +389,7 @@ impl SkillService {
|
|||||||
let name = first_file.name();
|
let name = first_file.name();
|
||||||
name.split('/').next().unwrap_or("").to_string()
|
name.split('/').next().unwrap_or("").to_string()
|
||||||
} else {
|
} else {
|
||||||
return Err(anyhow::anyhow!(format_skill_error(
|
return Err(anyhow::anyhow!("空的压缩包"));
|
||||||
"EMPTY_ARCHIVE",
|
|
||||||
&[],
|
|
||||||
Some("checkRepoUrl"),
|
|
||||||
)));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 解压所有文件
|
// 解压所有文件
|
||||||
@@ -481,40 +436,18 @@ impl SkillService {
|
|||||||
|
|
||||||
// 下载仓库时增加总超时,防止无效链接导致长时间卡住安装过程
|
// 下载仓库时增加总超时,防止无效链接导致长时间卡住安装过程
|
||||||
let temp_dir = timeout(
|
let temp_dir = timeout(
|
||||||
std::time::Duration::from_secs(60),
|
std::time::Duration::from_secs(15),
|
||||||
self.download_repo(&repo),
|
self.download_repo(&repo),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| {
|
.map_err(|_| anyhow!("下载仓库 {}/{} 超时", repo.owner, repo.name))??;
|
||||||
anyhow!(format_skill_error(
|
|
||||||
"DOWNLOAD_TIMEOUT",
|
|
||||||
&[
|
|
||||||
("owner", &repo.owner),
|
|
||||||
("name", &repo.name),
|
|
||||||
("timeout", "60")
|
|
||||||
],
|
|
||||||
Some("checkNetwork"),
|
|
||||||
))
|
|
||||||
})??;
|
|
||||||
|
|
||||||
// 根据 skills_path 确定源目录路径
|
// 复制到安装目录
|
||||||
let source = if let Some(ref skills_path) = repo.skills_path {
|
let source = temp_dir.join(&directory);
|
||||||
// 如果指定了 skills_path,源路径为: temp_dir/skills_path/directory
|
|
||||||
temp_dir
|
|
||||||
.join(skills_path.trim_matches('/'))
|
|
||||||
.join(&directory)
|
|
||||||
} else {
|
|
||||||
// 否则源路径为: temp_dir/directory
|
|
||||||
temp_dir.join(&directory)
|
|
||||||
};
|
|
||||||
|
|
||||||
if !source.exists() {
|
if !source.exists() {
|
||||||
let _ = fs::remove_dir_all(&temp_dir);
|
let _ = fs::remove_dir_all(&temp_dir);
|
||||||
return Err(anyhow::anyhow!(format_skill_error(
|
return Err(anyhow::anyhow!("技能目录不存在"));
|
||||||
"SKILL_DIR_NOT_FOUND",
|
|
||||||
&[("path", &source.display().to_string())],
|
|
||||||
Some("checkRepoUrl"),
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除旧版本
|
// 删除旧版本
|
||||||
|
|||||||
+11
-73
@@ -2,9 +2,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, OnceLock, RwLock};
|
use std::sync::{OnceLock, RwLock};
|
||||||
|
|
||||||
use crate::database::Database;
|
|
||||||
use crate::error::AppError;
|
use crate::error::AppError;
|
||||||
|
|
||||||
/// 自定义端点配置
|
/// 自定义端点配置
|
||||||
@@ -50,9 +49,6 @@ pub struct AppSettings {
|
|||||||
pub gemini_config_dir: Option<String>,
|
pub gemini_config_dir: Option<String>,
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub language: Option<String>,
|
pub language: Option<String>,
|
||||||
/// 是否开机自启
|
|
||||||
#[serde(default)]
|
|
||||||
pub launch_on_startup: bool,
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub security: Option<SecuritySettings>,
|
pub security: Option<SecuritySettings>,
|
||||||
/// Claude 自定义端点列表
|
/// Claude 自定义端点列表
|
||||||
@@ -81,7 +77,6 @@ impl Default for AppSettings {
|
|||||||
codex_config_dir: None,
|
codex_config_dir: None,
|
||||||
gemini_config_dir: None,
|
gemini_config_dir: None,
|
||||||
language: None,
|
language: None,
|
||||||
launch_on_startup: false,
|
|
||||||
security: None,
|
security: None,
|
||||||
custom_endpoints_claude: HashMap::new(),
|
custom_endpoints_claude: HashMap::new(),
|
||||||
custom_endpoints_codex: HashMap::new(),
|
custom_endpoints_codex: HashMap::new(),
|
||||||
@@ -91,7 +86,8 @@ impl Default for AppSettings {
|
|||||||
|
|
||||||
impl AppSettings {
|
impl AppSettings {
|
||||||
fn settings_path() -> PathBuf {
|
fn settings_path() -> PathBuf {
|
||||||
// settings.json 保留用于旧版本迁移和无数据库场景
|
// settings.json 必须使用固定路径,不能被 app_config_dir 覆盖
|
||||||
|
// 否则会造成循环依赖:读取 settings 需要知道路径,但路径在 settings 中
|
||||||
dirs::home_dir()
|
dirs::home_dir()
|
||||||
.expect("无法获取用户主目录")
|
.expect("无法获取用户主目录")
|
||||||
.join(".cc-switch")
|
.join(".cc-switch")
|
||||||
@@ -128,7 +124,7 @@ impl AppSettings {
|
|||||||
.map(|s| s.to_string());
|
.map(|s| s.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_from_file() -> Self {
|
pub fn load() -> Self {
|
||||||
let path = Self::settings_path();
|
let path = Self::settings_path();
|
||||||
if let Ok(content) = fs::read_to_string(&path) {
|
if let Ok(content) = fs::read_to_string(&path) {
|
||||||
match serde_json::from_str::<AppSettings>(&content) {
|
match serde_json::from_str::<AppSettings>(&content) {
|
||||||
@@ -149,12 +145,11 @@ impl AppSettings {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn save_settings_file(settings: &AppSettings) -> Result<(), AppError> {
|
pub fn save(&self) -> Result<(), AppError> {
|
||||||
let mut normalized = settings.clone();
|
let mut normalized = self.clone();
|
||||||
normalized.normalize_paths();
|
normalized.normalize_paths();
|
||||||
let path = AppSettings::settings_path();
|
let path = Self::settings_path();
|
||||||
|
|
||||||
if let Some(parent) = path.parent() {
|
if let Some(parent) = path.parent() {
|
||||||
fs::create_dir_all(parent).map_err(|e| AppError::io(parent, e))?;
|
fs::create_dir_all(parent).map_err(|e| AppError::io(parent, e))?;
|
||||||
@@ -165,64 +160,11 @@ fn save_settings_file(settings: &AppSettings) -> Result<(), AppError> {
|
|||||||
fs::write(&path, json).map_err(|e| AppError::io(&path, e))?;
|
fs::write(&path, json).map_err(|e| AppError::io(&path, e))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static SETTINGS_STORE: OnceLock<RwLock<AppSettings>> = OnceLock::new();
|
|
||||||
|
|
||||||
fn settings_store() -> &'static RwLock<AppSettings> {
|
fn settings_store() -> &'static RwLock<AppSettings> {
|
||||||
SETTINGS_STORE.get_or_init(|| RwLock::new(load_initial_settings()))
|
static STORE: OnceLock<RwLock<AppSettings>> = OnceLock::new();
|
||||||
}
|
STORE.get_or_init(|| RwLock::new(AppSettings::load()))
|
||||||
|
|
||||||
static SETTINGS_DB: OnceLock<Arc<Database>> = OnceLock::new();
|
|
||||||
const APP_SETTINGS_KEY: &str = "app_settings";
|
|
||||||
|
|
||||||
pub fn bind_db(db: Arc<Database>) {
|
|
||||||
if SETTINGS_DB.set(db).is_err() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(store) = SETTINGS_STORE.get() {
|
|
||||||
let mut guard = store.write().expect("写入设置锁失败");
|
|
||||||
*guard = load_initial_settings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_initial_settings() -> AppSettings {
|
|
||||||
if let Some(db) = SETTINGS_DB.get() {
|
|
||||||
if let Some(from_db) = load_from_db(db.as_ref()) {
|
|
||||||
return from_db;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从文件迁移一次并写入数据库
|
|
||||||
let file_settings = AppSettings::load_from_file();
|
|
||||||
if let Err(e) = save_to_db(db.as_ref(), &file_settings) {
|
|
||||||
log::warn!("迁移设置到数据库失败,将继续使用内存副本: {e}");
|
|
||||||
}
|
|
||||||
return file_settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppSettings::load_from_file()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_from_db(db: &Database) -> Option<AppSettings> {
|
|
||||||
let raw = db.get_setting(APP_SETTINGS_KEY).ok()??;
|
|
||||||
match serde_json::from_str::<AppSettings>(&raw) {
|
|
||||||
Ok(mut settings) => {
|
|
||||||
settings.normalize_paths();
|
|
||||||
Some(settings)
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
log::warn!("解析数据库中 app_settings 失败: {err}");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn save_to_db(db: &Database, settings: &AppSettings) -> Result<(), AppError> {
|
|
||||||
let mut normalized = settings.clone();
|
|
||||||
normalized.normalize_paths();
|
|
||||||
let json =
|
|
||||||
serde_json::to_string(&normalized).map_err(|e| AppError::JsonSerialize { source: e })?;
|
|
||||||
db.set_setting(APP_SETTINGS_KEY, &json)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_override_path(raw: &str) -> PathBuf {
|
fn resolve_override_path(raw: &str) -> PathBuf {
|
||||||
@@ -249,11 +191,7 @@ pub fn get_settings() -> AppSettings {
|
|||||||
|
|
||||||
pub fn update_settings(mut new_settings: AppSettings) -> Result<(), AppError> {
|
pub fn update_settings(mut new_settings: AppSettings) -> Result<(), AppError> {
|
||||||
new_settings.normalize_paths();
|
new_settings.normalize_paths();
|
||||||
if let Some(db) = SETTINGS_DB.get() {
|
new_settings.save()?;
|
||||||
save_to_db(db, &new_settings)?;
|
|
||||||
} else {
|
|
||||||
save_settings_file(&new_settings)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut guard = settings_store().write().expect("写入设置锁失败");
|
let mut guard = settings_store().write().expect("写入设置锁失败");
|
||||||
*guard = new_settings;
|
*guard = new_settings;
|
||||||
|
|||||||
+17
-5
@@ -1,14 +1,26 @@
|
|||||||
use crate::database::Database;
|
use crate::app_config::MultiAppConfig;
|
||||||
use std::sync::Arc;
|
use crate::error::AppError;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
/// 全局应用状态
|
/// 全局应用状态
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub db: Arc<Database>,
|
pub config: RwLock<MultiAppConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
/// 创建新的应用状态
|
/// 创建新的应用状态
|
||||||
pub fn new(db: Arc<Database>) -> Self {
|
/// 注意:仅在配置成功加载时返回;不会在失败时回退默认值。
|
||||||
Self { db }
|
pub fn try_new() -> Result<Self, AppError> {
|
||||||
|
let config = MultiAppConfig::load()?;
|
||||||
|
Ok(Self {
|
||||||
|
config: RwLock::new(config),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 保存配置到文件
|
||||||
|
pub fn save(&self) -> Result<(), AppError> {
|
||||||
|
let config = self.config.read().map_err(AppError::from)?;
|
||||||
|
|
||||||
|
config.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "CC Switch",
|
"productName": "CC Switch",
|
||||||
"version": "3.7.1",
|
"version": "3.6.2",
|
||||||
"identifier": "com.ccswitch.desktop",
|
"identifier": "com.ccswitch.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../dist",
|
"frontendDist": "../dist",
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
{
|
{
|
||||||
"label": "main",
|
"label": "main",
|
||||||
"title": "",
|
"title": "",
|
||||||
"titleBarStyle": "Overlay",
|
|
||||||
"width": 1000,
|
"width": 1000,
|
||||||
"height": 650,
|
"height": 650,
|
||||||
"minWidth": 900,
|
"minWidth": 900,
|
||||||
|
|||||||
@@ -1,36 +1,46 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use cc_switch_lib::{import_provider_from_deeplink, parse_deeplink_url, AppState, Database};
|
use cc_switch_lib::{
|
||||||
|
import_provider_from_deeplink, parse_deeplink_url, AppState, AppType, MultiAppConfig,
|
||||||
|
};
|
||||||
|
|
||||||
#[path = "support.rs"]
|
#[path = "support.rs"]
|
||||||
mod support;
|
mod support;
|
||||||
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deeplink_import_claude_provider_persists_to_db() {
|
fn deeplink_import_claude_provider_persists_to_config() {
|
||||||
let _guard = test_mutex().lock().expect("acquire test mutex");
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
||||||
reset_test_fs();
|
reset_test_fs();
|
||||||
let _home = ensure_test_home();
|
let home = ensure_test_home();
|
||||||
|
|
||||||
let url = "ccswitch://v1/import?resource=provider&app=claude&name=DeepLink%20Claude&homepage=https%3A%2F%2Fexample.com&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-claude-key&model=claude-sonnet-4&icon=claude";
|
let url = "ccswitch://v1/import?resource=provider&app=claude&name=DeepLink%20Claude&homepage=https%3A%2F%2Fexample.com&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-claude-key&model=claude-sonnet-4";
|
||||||
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
||||||
|
|
||||||
let db = Arc::new(Database::memory().expect("create memory db"));
|
let mut config = MultiAppConfig::default();
|
||||||
|
config.ensure_app(&AppType::Claude);
|
||||||
|
|
||||||
let state = AppState { db: db.clone() };
|
let state = AppState {
|
||||||
|
config: RwLock::new(config),
|
||||||
|
};
|
||||||
|
|
||||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||||
.expect("import provider from deeplink");
|
.expect("import provider from deeplink");
|
||||||
|
|
||||||
// Verify DB state
|
// 验证内存状态
|
||||||
let providers = db.get_all_providers("claude").expect("get providers");
|
let guard = state.config.read().expect("read config");
|
||||||
let provider = providers
|
let manager = guard
|
||||||
|
.get_manager(&AppType::Claude)
|
||||||
|
.expect("claude manager should exist");
|
||||||
|
let provider = manager
|
||||||
|
.providers
|
||||||
.get(&provider_id)
|
.get(&provider_id)
|
||||||
.expect("provider created via deeplink");
|
.expect("provider created via deeplink");
|
||||||
|
assert_eq!(provider.name, request.name);
|
||||||
assert_eq!(provider.name, request.name.clone().unwrap());
|
assert_eq!(
|
||||||
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
provider.website_url.as_deref(),
|
||||||
assert_eq!(provider.icon.as_deref(), Some("claude"));
|
Some(request.homepage.as_str())
|
||||||
|
);
|
||||||
let auth_token = provider
|
let auth_token = provider
|
||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
||||||
@@ -39,34 +49,50 @@ fn deeplink_import_claude_provider_persists_to_db() {
|
|||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/env/ANTHROPIC_BASE_URL")
|
.pointer("/env/ANTHROPIC_BASE_URL")
|
||||||
.and_then(|v| v.as_str());
|
.and_then(|v| v.as_str());
|
||||||
assert_eq!(auth_token, request.api_key.as_deref());
|
assert_eq!(auth_token, Some(request.api_key.as_str()));
|
||||||
assert_eq!(base_url, request.endpoint.as_deref());
|
assert_eq!(base_url, Some(request.endpoint.as_str()));
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
|
// 验证配置已持久化
|
||||||
|
let config_path = home.join(".cc-switch").join("config.json");
|
||||||
|
assert!(
|
||||||
|
config_path.exists(),
|
||||||
|
"importing provider from deeplink should persist config.json"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
||||||
let _guard = test_mutex().lock().expect("acquire test mutex");
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
||||||
reset_test_fs();
|
reset_test_fs();
|
||||||
let _home = ensure_test_home();
|
let home = ensure_test_home();
|
||||||
|
|
||||||
let url = "ccswitch://v1/import?resource=provider&app=codex&name=DeepLink%20Codex&homepage=https%3A%2F%2Fopenai.example&endpoint=https%3A%2F%2Fapi.openai.example%2Fv1&apiKey=sk-test-codex-key&model=gpt-4o&icon=openai";
|
let url = "ccswitch://v1/import?resource=provider&app=codex&name=DeepLink%20Codex&homepage=https%3A%2F%2Fopenai.example&endpoint=https%3A%2F%2Fapi.openai.example%2Fv1&apiKey=sk-test-codex-key&model=gpt-4o";
|
||||||
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
||||||
|
|
||||||
let db = Arc::new(Database::memory().expect("create memory db"));
|
let mut config = MultiAppConfig::default();
|
||||||
|
config.ensure_app(&AppType::Codex);
|
||||||
|
|
||||||
let state = AppState { db: db.clone() };
|
let state = AppState {
|
||||||
|
config: RwLock::new(config),
|
||||||
|
};
|
||||||
|
|
||||||
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
||||||
.expect("import provider from deeplink");
|
.expect("import provider from deeplink");
|
||||||
|
|
||||||
let providers = db.get_all_providers("codex").expect("get providers");
|
let guard = state.config.read().expect("read config");
|
||||||
let provider = providers
|
let manager = guard
|
||||||
|
.get_manager(&AppType::Codex)
|
||||||
|
.expect("codex manager should exist");
|
||||||
|
let provider = manager
|
||||||
|
.providers
|
||||||
.get(&provider_id)
|
.get(&provider_id)
|
||||||
.expect("provider created via deeplink");
|
.expect("provider created via deeplink");
|
||||||
|
assert_eq!(provider.name, request.name);
|
||||||
assert_eq!(provider.name, request.name.clone().unwrap());
|
assert_eq!(
|
||||||
assert_eq!(provider.website_url.as_deref(), request.homepage.as_deref());
|
provider.website_url.as_deref(),
|
||||||
assert_eq!(provider.icon.as_deref(), Some("openai"));
|
Some(request.homepage.as_str())
|
||||||
|
);
|
||||||
let auth_value = provider
|
let auth_value = provider
|
||||||
.settings_config
|
.settings_config
|
||||||
.pointer("/auth/OPENAI_API_KEY")
|
.pointer("/auth/OPENAI_API_KEY")
|
||||||
@@ -76,13 +102,20 @@ fn deeplink_import_codex_provider_builds_auth_and_config() {
|
|||||||
.get("config")
|
.get("config")
|
||||||
.and_then(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
assert_eq!(auth_value, request.api_key.as_deref());
|
assert_eq!(auth_value, Some(request.api_key.as_str()));
|
||||||
assert!(
|
assert!(
|
||||||
config_text.contains(request.endpoint.as_deref().unwrap()),
|
config_text.contains(request.endpoint.as_str()),
|
||||||
"config.toml content should contain endpoint"
|
"config.toml content should contain endpoint"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
config_text.contains("model = \"gpt-4o\""),
|
config_text.contains("model = \"gpt-4o\""),
|
||||||
"config.toml content should contain model setting"
|
"config.toml content should contain model setting"
|
||||||
);
|
);
|
||||||
|
drop(guard);
|
||||||
|
|
||||||
|
let config_path = home.join(".cc-switch").join("config.json");
|
||||||
|
assert!(
|
||||||
|
config_path.exists(),
|
||||||
|
"importing provider from deeplink should persist config.json"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,8 +498,8 @@ url = "https://example.com"
|
|||||||
.expect("unified servers should exist");
|
.expect("unified servers should exist");
|
||||||
|
|
||||||
let echo = servers.get("echo_server").expect("echo server");
|
let echo = servers.get("echo_server").expect("echo server");
|
||||||
assert!(
|
assert_eq!(
|
||||||
echo.apps.codex,
|
echo.apps.codex, true,
|
||||||
"Codex app should be enabled for echo_server"
|
"Codex app should be enabled for echo_server"
|
||||||
);
|
);
|
||||||
let server_spec = echo.server.as_object().expect("server spec");
|
let server_spec = echo.server.as_object().expect("server spec");
|
||||||
@@ -512,8 +512,8 @@ url = "https://example.com"
|
|||||||
);
|
);
|
||||||
|
|
||||||
let http = servers.get("http_server").expect("http server");
|
let http = servers.get("http_server").expect("http server");
|
||||||
assert!(
|
assert_eq!(
|
||||||
http.apps.codex,
|
http.apps.codex, true,
|
||||||
"Codex app should be enabled for http_server"
|
"Codex app should be enabled for http_server"
|
||||||
);
|
);
|
||||||
let http_spec = http.server.as_object().expect("http spec");
|
let http_spec = http.server.as_object().expect("http spec");
|
||||||
@@ -577,7 +577,10 @@ command = "echo"
|
|||||||
.expect("existing entry");
|
.expect("existing entry");
|
||||||
|
|
||||||
// 验证 Codex 应用已启用
|
// 验证 Codex 应用已启用
|
||||||
assert!(entry.apps.codex, "Codex app should be enabled after import");
|
assert_eq!(
|
||||||
|
entry.apps.codex, true,
|
||||||
|
"Codex app should be enabled after import"
|
||||||
|
);
|
||||||
|
|
||||||
// 验证现有配置被保留(server 不应被覆盖)
|
// 验证现有配置被保留(server 不应被覆盖)
|
||||||
let spec = entry.server.as_object().expect("server spec");
|
let spec = entry.server.as_object().expect("server spec");
|
||||||
@@ -699,8 +702,8 @@ fn import_from_claude_merges_into_config() {
|
|||||||
.expect("entry exists");
|
.expect("entry exists");
|
||||||
|
|
||||||
// 验证 Claude 应用已启用
|
// 验证 Claude 应用已启用
|
||||||
assert!(
|
assert_eq!(
|
||||||
entry.apps.claude,
|
entry.apps.claude, true,
|
||||||
"Claude app should be enabled after import"
|
"Claude app should be enabled after import"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+94
-243
@@ -1,16 +1,7 @@
|
|||||||
import { useEffect, useMemo, useState, useRef } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import {
|
import { Plus, Settings, Edit3 } from "lucide-react";
|
||||||
Plus,
|
|
||||||
Settings,
|
|
||||||
ArrowLeft,
|
|
||||||
Bot,
|
|
||||||
Book,
|
|
||||||
Wrench,
|
|
||||||
Server,
|
|
||||||
RefreshCw,
|
|
||||||
} from "lucide-react";
|
|
||||||
import type { Provider } from "@/types";
|
import type { Provider } from "@/types";
|
||||||
import type { EnvConflict } from "@/types/env";
|
import type { EnvConflict } from "@/types/env";
|
||||||
import { useProvidersQuery } from "@/lib/query";
|
import { useProvidersQuery } from "@/lib/query";
|
||||||
@@ -28,7 +19,7 @@ import { ProviderList } from "@/components/providers/ProviderList";
|
|||||||
import { AddProviderDialog } from "@/components/providers/AddProviderDialog";
|
import { AddProviderDialog } from "@/components/providers/AddProviderDialog";
|
||||||
import { EditProviderDialog } from "@/components/providers/EditProviderDialog";
|
import { EditProviderDialog } from "@/components/providers/EditProviderDialog";
|
||||||
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
||||||
import { SettingsPage } from "@/components/settings/SettingsPage";
|
import { SettingsDialog } from "@/components/settings/SettingsDialog";
|
||||||
import { UpdateBadge } from "@/components/UpdateBadge";
|
import { UpdateBadge } from "@/components/UpdateBadge";
|
||||||
import { EnvWarningBanner } from "@/components/env/EnvWarningBanner";
|
import { EnvWarningBanner } from "@/components/env/EnvWarningBanner";
|
||||||
import UsageScriptModal from "@/components/UsageScriptModal";
|
import UsageScriptModal from "@/components/UsageScriptModal";
|
||||||
@@ -36,34 +27,34 @@ import UnifiedMcpPanel from "@/components/mcp/UnifiedMcpPanel";
|
|||||||
import PromptPanel from "@/components/prompts/PromptPanel";
|
import PromptPanel from "@/components/prompts/PromptPanel";
|
||||||
import { SkillsPage } from "@/components/skills/SkillsPage";
|
import { SkillsPage } from "@/components/skills/SkillsPage";
|
||||||
import { DeepLinkImportDialog } from "@/components/DeepLinkImportDialog";
|
import { DeepLinkImportDialog } from "@/components/DeepLinkImportDialog";
|
||||||
import { AgentsPanel } from "@/components/agents/AgentsPanel";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
type View = "providers" | "settings" | "prompts" | "skills" | "mcp" | "agents";
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [activeApp, setActiveApp] = useState<AppId>("claude");
|
const [activeApp, setActiveApp] = useState<AppId>("claude");
|
||||||
const [currentView, setCurrentView] = useState<View>("providers");
|
const [isEditMode, setIsEditMode] = useState(false);
|
||||||
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
||||||
const [isAddOpen, setIsAddOpen] = useState(false);
|
const [isAddOpen, setIsAddOpen] = useState(false);
|
||||||
|
const [isMcpOpen, setIsMcpOpen] = useState(false);
|
||||||
|
const [isPromptOpen, setIsPromptOpen] = useState(false);
|
||||||
|
const [isSkillsOpen, setIsSkillsOpen] = useState(false);
|
||||||
const [editingProvider, setEditingProvider] = useState<Provider | null>(null);
|
const [editingProvider, setEditingProvider] = useState<Provider | null>(null);
|
||||||
const [usageProvider, setUsageProvider] = useState<Provider | null>(null);
|
const [usageProvider, setUsageProvider] = useState<Provider | null>(null);
|
||||||
const [confirmDelete, setConfirmDelete] = useState<Provider | null>(null);
|
const [confirmDelete, setConfirmDelete] = useState<Provider | null>(null);
|
||||||
const [envConflicts, setEnvConflicts] = useState<EnvConflict[]>([]);
|
const [envConflicts, setEnvConflicts] = useState<EnvConflict[]>([]);
|
||||||
const [showEnvBanner, setShowEnvBanner] = useState(false);
|
const [showEnvBanner, setShowEnvBanner] = useState(false);
|
||||||
|
|
||||||
const promptPanelRef = useRef<any>(null);
|
|
||||||
const mcpPanelRef = useRef<any>(null);
|
|
||||||
const skillsPageRef = useRef<any>(null);
|
|
||||||
const addActionButtonClass =
|
|
||||||
"bg-orange-500 hover:bg-orange-600 dark:bg-orange-500 dark:hover:bg-orange-600 text-white shadow-lg shadow-orange-500/30 dark:shadow-orange-500/40 rounded-full w-8 h-8";
|
|
||||||
|
|
||||||
const { data, isLoading, refetch } = useProvidersQuery(activeApp);
|
const { data, isLoading, refetch } = useProvidersQuery(activeApp);
|
||||||
const providers = useMemo(() => data?.providers ?? {}, [data]);
|
const providers = useMemo(() => data?.providers ?? {}, [data]);
|
||||||
const currentProviderId = data?.currentProviderId ?? "";
|
const currentProviderId = data?.currentProviderId ?? "";
|
||||||
const isClaudeApp = activeApp === "claude";
|
|
||||||
|
|
||||||
// 🎯 使用 useProviderActions Hook 统一管理所有 Provider 操作
|
// 🎯 使用 useProviderActions Hook 统一管理所有 Provider 操作
|
||||||
const {
|
const {
|
||||||
@@ -107,11 +98,8 @@ function App() {
|
|||||||
|
|
||||||
if (flatConflicts.length > 0) {
|
if (flatConflicts.length > 0) {
|
||||||
setEnvConflicts(flatConflicts);
|
setEnvConflicts(flatConflicts);
|
||||||
const dismissed = sessionStorage.getItem("env_banner_dismissed");
|
|
||||||
if (!dismissed) {
|
|
||||||
setShowEnvBanner(true);
|
setShowEnvBanner(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
"[App] Failed to check environment conflicts on startup:",
|
"[App] Failed to check environment conflicts on startup:",
|
||||||
@@ -140,11 +128,8 @@ function App() {
|
|||||||
);
|
);
|
||||||
return [...prev, ...newConflicts];
|
return [...prev, ...newConflicts];
|
||||||
});
|
});
|
||||||
const dismissed = sessionStorage.getItem("env_banner_dismissed");
|
|
||||||
if (!dismissed) {
|
|
||||||
setShowEnvBanner(true);
|
setShowEnvBanner(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
"[App] Failed to check environment conflicts on app switch:",
|
"[App] Failed to check environment conflicts on app switch:",
|
||||||
@@ -244,81 +229,13 @@ function App() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderContent = () => {
|
|
||||||
switch (currentView) {
|
|
||||||
case "settings":
|
|
||||||
return (
|
return (
|
||||||
<SettingsPage
|
<div className="flex h-screen flex-col bg-gray-50 dark:bg-gray-950">
|
||||||
open={true}
|
|
||||||
onOpenChange={() => setCurrentView("providers")}
|
|
||||||
onImportSuccess={handleImportSuccess}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case "prompts":
|
|
||||||
return (
|
|
||||||
<PromptPanel
|
|
||||||
ref={promptPanelRef}
|
|
||||||
open={true}
|
|
||||||
onOpenChange={() => setCurrentView("providers")}
|
|
||||||
appId={activeApp}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case "skills":
|
|
||||||
return (
|
|
||||||
<SkillsPage
|
|
||||||
ref={skillsPageRef}
|
|
||||||
onClose={() => setCurrentView("providers")}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case "mcp":
|
|
||||||
return (
|
|
||||||
<UnifiedMcpPanel
|
|
||||||
ref={mcpPanelRef}
|
|
||||||
onOpenChange={() => setCurrentView("providers")}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case "agents":
|
|
||||||
return <AgentsPanel onOpenChange={() => setCurrentView("providers")} />;
|
|
||||||
default:
|
|
||||||
return (
|
|
||||||
<div className="mx-auto max-w-[56rem] px-6 space-y-4">
|
|
||||||
<ProviderList
|
|
||||||
providers={providers}
|
|
||||||
currentProviderId={currentProviderId}
|
|
||||||
appId={activeApp}
|
|
||||||
isLoading={isLoading}
|
|
||||||
onSwitch={switchProvider}
|
|
||||||
onEdit={setEditingProvider}
|
|
||||||
onDelete={setConfirmDelete}
|
|
||||||
onDuplicate={handleDuplicateProvider}
|
|
||||||
onConfigureUsage={setUsageProvider}
|
|
||||||
onOpenWebsite={handleOpenWebsite}
|
|
||||||
onCreate={() => setIsAddOpen(true)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className="flex min-h-screen flex-col bg-background text-foreground selection:bg-primary/30"
|
|
||||||
style={{ overflowX: "hidden" }}
|
|
||||||
>
|
|
||||||
{/* 全局拖拽区域(顶部 4px),避免上边框无法拖动 */}
|
|
||||||
<div
|
|
||||||
className="fixed top-0 left-0 right-0 h-4 z-[60]"
|
|
||||||
data-tauri-drag-region
|
|
||||||
style={{ WebkitAppRegion: "drag" } as any}
|
|
||||||
/>
|
|
||||||
{/* 环境变量警告横幅 */}
|
{/* 环境变量警告横幅 */}
|
||||||
{showEnvBanner && envConflicts.length > 0 && (
|
{showEnvBanner && envConflicts.length > 0 && (
|
||||||
<EnvWarningBanner
|
<EnvWarningBanner
|
||||||
conflicts={envConflicts}
|
conflicts={envConflicts}
|
||||||
onDismiss={() => {
|
onDismiss={() => setShowEnvBanner(false)}
|
||||||
setShowEnvBanner(false);
|
|
||||||
sessionStorage.setItem("env_banner_dismissed", "true");
|
|
||||||
}}
|
|
||||||
onDeleted={async () => {
|
onDeleted={async () => {
|
||||||
// 删除后重新检测
|
// 删除后重新检测
|
||||||
try {
|
try {
|
||||||
@@ -338,43 +255,9 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<header
|
<header className="flex-shrink-0 border-b border-gray-200 bg-white px-6 py-4 dark:border-gray-800 dark:bg-gray-900">
|
||||||
className="glass-header fixed top-0 z-50 w-full py-3 transition-all duration-300"
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||||
data-tauri-drag-region
|
<div className="flex items-center gap-1">
|
||||||
style={{ WebkitAppRegion: "drag" } as any}
|
|
||||||
>
|
|
||||||
<div className="h-4 w-full" aria-hidden data-tauri-drag-region />
|
|
||||||
<div
|
|
||||||
className="mx-auto max-w-[56rem] px-6 flex flex-wrap items-center justify-between gap-2"
|
|
||||||
data-tauri-drag-region
|
|
||||||
style={{ WebkitAppRegion: "drag" } as any}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="flex items-center gap-1"
|
|
||||||
style={{ WebkitAppRegion: "no-drag" } as any}
|
|
||||||
>
|
|
||||||
{currentView !== "providers" ? (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
onClick={() => setCurrentView("providers")}
|
|
||||||
className="mr-2 rounded-lg"
|
|
||||||
>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<h1 className="text-lg font-semibold">
|
|
||||||
{currentView === "settings" && t("settings.title")}
|
|
||||||
{currentView === "prompts" &&
|
|
||||||
t("prompts.title", { appName: t(`apps.${activeApp}`) })}
|
|
||||||
{currentView === "skills" && t("skills.title")}
|
|
||||||
{currentView === "mcp" && t("mcp.unifiedPanel.title")}
|
|
||||||
{currentView === "agents" && "Agents"}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<a
|
<a
|
||||||
href="https://github.com/farion1231/cc-switch"
|
href="https://github.com/farion1231/cc-switch"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -383,137 +266,81 @@ function App() {
|
|||||||
>
|
>
|
||||||
CC Switch
|
CC Switch
|
||||||
</a>
|
</a>
|
||||||
<div className="h-5 w-[1px] bg-black/10 dark:bg-white/15" />
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => setCurrentView("settings")}
|
onClick={() => setIsSettingsOpen(true)}
|
||||||
title={t("common.settings")}
|
title={t("common.settings")}
|
||||||
className="hover:bg-black/5 dark:hover:bg-white/5"
|
className="ml-2"
|
||||||
>
|
>
|
||||||
<Settings className="h-4 w-4" />
|
<Settings className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
<Button
|
||||||
<UpdateBadge onClick={() => setCurrentView("settings")} />
|
variant="ghost"
|
||||||
</>
|
size="icon"
|
||||||
|
onClick={() => setIsEditMode(!isEditMode)}
|
||||||
|
title={t(
|
||||||
|
isEditMode ? "header.exitEditMode" : "header.enterEditMode",
|
||||||
)}
|
)}
|
||||||
|
className={
|
||||||
|
isEditMode
|
||||||
|
? "text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Edit3 className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<UpdateBadge onClick={() => setIsSettingsOpen(true)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
className="flex items-center gap-2"
|
|
||||||
style={{ WebkitAppRegion: "no-drag" } as any}
|
|
||||||
>
|
|
||||||
{currentView === "prompts" && (
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
onClick={() => promptPanelRef.current?.openAdd()}
|
|
||||||
className={addActionButtonClass}
|
|
||||||
title={t("prompts.add")}
|
|
||||||
>
|
|
||||||
<Plus className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{currentView === "mcp" && (
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
onClick={() => mcpPanelRef.current?.openAdd()}
|
|
||||||
className={addActionButtonClass}
|
|
||||||
title={t("mcp.unifiedPanel.addServer")}
|
|
||||||
>
|
|
||||||
<Plus className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{currentView === "skills" && (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => skillsPageRef.current?.refresh()}
|
|
||||||
className="hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
>
|
|
||||||
<RefreshCw className="h-4 w-4 mr-2" />
|
|
||||||
{t("skills.refresh")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => skillsPageRef.current?.openRepoManager()}
|
|
||||||
className="hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
>
|
|
||||||
<Settings className="h-4 w-4 mr-2" />
|
|
||||||
{t("skills.repoManager")}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{currentView === "providers" && (
|
|
||||||
<>
|
|
||||||
<AppSwitcher activeApp={activeApp} onSwitch={setActiveApp} />
|
<AppSwitcher activeApp={activeApp} onSwitch={setActiveApp} />
|
||||||
|
|
||||||
<div className="h-8 w-[1px] bg-black/10 dark:bg-white/10 mx-1" />
|
|
||||||
|
|
||||||
<div className="glass p-1 rounded-xl flex items-center gap-1">
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="mcp"
|
||||||
size="sm"
|
onClick={() => setIsPromptOpen(true)}
|
||||||
onClick={() => setCurrentView("prompts")}
|
className="min-w-[80px]"
|
||||||
className="text-muted-foreground hover:text-foreground hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
title={t("prompts.manage")}
|
|
||||||
>
|
>
|
||||||
<Book className="h-4 w-4" />
|
{t("prompts.manage")}
|
||||||
</Button>
|
</Button>
|
||||||
{isClaudeApp && (
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="mcp"
|
||||||
size="sm"
|
onClick={() => setIsMcpOpen(true)}
|
||||||
onClick={() => setCurrentView("skills")}
|
className="min-w-[80px]"
|
||||||
className="text-muted-foreground hover:text-foreground hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
title={t("skills.manage")}
|
|
||||||
>
|
>
|
||||||
<Wrench className="h-4 w-4" />
|
MCP
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="mcp"
|
||||||
size="sm"
|
onClick={() => setIsSkillsOpen(true)}
|
||||||
onClick={() => setCurrentView("mcp")}
|
className="min-w-[80px]"
|
||||||
className="text-muted-foreground hover:text-foreground hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
title="MCP"
|
|
||||||
>
|
>
|
||||||
<Server className="h-4 w-4" />
|
{t("skills.manage")}
|
||||||
</Button>
|
</Button>
|
||||||
{isClaudeApp && (
|
<Button onClick={() => setIsAddOpen(true)}>
|
||||||
<Button
|
<Plus className="h-4 w-4" />
|
||||||
variant="ghost"
|
{t("header.addProvider")}
|
||||||
size="sm"
|
|
||||||
onClick={() => setCurrentView("agents")}
|
|
||||||
className="text-muted-foreground hover:text-foreground hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
title="Agents"
|
|
||||||
>
|
|
||||||
<Bot className="h-4 w-4" />
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
onClick={() => setIsAddOpen(true)}
|
|
||||||
size="icon"
|
|
||||||
className={`ml-2 ${addActionButtonClass}`}
|
|
||||||
>
|
|
||||||
<Plus className="h-5 w-5" />
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main
|
<main className="flex-1 overflow-y-scroll">
|
||||||
className={`flex-1 overflow-y-auto pb-12 animate-fade-in scroll-overlay ${
|
<div className="mx-auto max-w-4xl px-6 py-6">
|
||||||
currentView === "providers" ? "pt-24" : "pt-20"
|
<ProviderList
|
||||||
}`}
|
providers={providers}
|
||||||
style={{ overflowX: "hidden" }}
|
currentProviderId={currentProviderId}
|
||||||
>
|
appId={activeApp}
|
||||||
{renderContent()}
|
isLoading={isLoading}
|
||||||
|
isEditMode={isEditMode}
|
||||||
|
onSwitch={switchProvider}
|
||||||
|
onEdit={setEditingProvider}
|
||||||
|
onDelete={setConfirmDelete}
|
||||||
|
onDuplicate={handleDuplicateProvider}
|
||||||
|
onConfigureUsage={setUsageProvider}
|
||||||
|
onOpenWebsite={handleOpenWebsite}
|
||||||
|
onCreate={() => setIsAddOpen(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<AddProviderDialog
|
<AddProviderDialog
|
||||||
@@ -561,6 +388,30 @@ function App() {
|
|||||||
onCancel={() => setConfirmDelete(null)}
|
onCancel={() => setConfirmDelete(null)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<SettingsDialog
|
||||||
|
open={isSettingsOpen}
|
||||||
|
onOpenChange={setIsSettingsOpen}
|
||||||
|
onImportSuccess={handleImportSuccess}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<PromptPanel
|
||||||
|
open={isPromptOpen}
|
||||||
|
onOpenChange={setIsPromptOpen}
|
||||||
|
appId={activeApp}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UnifiedMcpPanel open={isMcpOpen} onOpenChange={setIsMcpOpen} />
|
||||||
|
|
||||||
|
<Dialog open={isSkillsOpen} onOpenChange={setIsSkillsOpen}>
|
||||||
|
<DialogContent className="max-w-4xl max-h-[85vh] min-h-[600px] flex flex-col p-0">
|
||||||
|
<DialogHeader className="sr-only">
|
||||||
|
<VisuallyHidden>
|
||||||
|
<DialogTitle>{t("skills.title")}</DialogTitle>
|
||||||
|
</VisuallyHidden>
|
||||||
|
</DialogHeader>
|
||||||
|
<SkillsPage onClose={() => setIsSkillsOpen(false)} />
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
<DeepLinkImportDialog />
|
<DeepLinkImportDialog />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { AppId } from "@/lib/api";
|
import type { AppId } from "@/lib/api";
|
||||||
import { ProviderIcon } from "@/components/ProviderIcon";
|
import { ClaudeIcon, CodexIcon, GeminiIcon } from "./BrandIcons";
|
||||||
|
|
||||||
interface AppSwitcherProps {
|
interface AppSwitcherProps {
|
||||||
activeApp: AppId;
|
activeApp: AppId;
|
||||||
@@ -11,40 +11,27 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
if (app === activeApp) return;
|
if (app === activeApp) return;
|
||||||
onSwitch(app);
|
onSwitch(app);
|
||||||
};
|
};
|
||||||
const iconSize = 20;
|
|
||||||
const appIconName: Record<AppId, string> = {
|
|
||||||
claude: "claude",
|
|
||||||
codex: "openai",
|
|
||||||
gemini: "gemini",
|
|
||||||
};
|
|
||||||
const appDisplayName: Record<AppId, string> = {
|
|
||||||
claude: "Claude",
|
|
||||||
codex: "Codex",
|
|
||||||
gemini: "Gemini",
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1 gap-1">
|
<div className="inline-flex bg-gray-100 dark:bg-gray-800 rounded-lg p-1 gap-1 border border-transparent ">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleSwitch("claude")}
|
onClick={() => handleSwitch("claude")}
|
||||||
className={`group inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
className={`group inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
||||||
activeApp === "claude"
|
activeApp === "claude"
|
||||||
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100"
|
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100 dark:shadow-none"
|
||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<ProviderIcon
|
<ClaudeIcon
|
||||||
icon={appIconName.claude}
|
size={16}
|
||||||
name={appDisplayName.claude}
|
|
||||||
size={iconSize}
|
|
||||||
className={
|
className={
|
||||||
activeApp === "claude"
|
activeApp === "claude"
|
||||||
? "text-foreground"
|
? "text-[#D97757] dark:text-[#D97757] transition-colors duration-200"
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
: "text-gray-500 dark:text-gray-400 group-hover:text-[#D97757] dark:group-hover:text-[#D97757] transition-colors duration-200"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>{appDisplayName.claude}</span>
|
<span>Claude</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -52,21 +39,12 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
onClick={() => handleSwitch("codex")}
|
onClick={() => handleSwitch("codex")}
|
||||||
className={`inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
className={`inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
||||||
activeApp === "codex"
|
activeApp === "codex"
|
||||||
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100"
|
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100 dark:shadow-none"
|
||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<ProviderIcon
|
<CodexIcon size={16} />
|
||||||
icon={appIconName.codex}
|
<span>Codex</span>
|
||||||
name={appDisplayName.codex}
|
|
||||||
size={iconSize}
|
|
||||||
className={
|
|
||||||
activeApp === "codex"
|
|
||||||
? "text-foreground"
|
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>{appDisplayName.codex}</span>
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@@ -74,21 +52,19 @@ export function AppSwitcher({ activeApp, onSwitch }: AppSwitcherProps) {
|
|||||||
onClick={() => handleSwitch("gemini")}
|
onClick={() => handleSwitch("gemini")}
|
||||||
className={`inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
className={`inline-flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-all duration-200 ${
|
||||||
activeApp === "gemini"
|
activeApp === "gemini"
|
||||||
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100"
|
? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100 dark:shadow-none"
|
||||||
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
: "text-gray-500 hover:text-gray-900 hover:bg-white/50 dark:text-gray-400 dark:hover:text-gray-100 dark:hover:bg-gray-800/60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<ProviderIcon
|
<GeminiIcon
|
||||||
icon={appIconName.gemini}
|
size={16}
|
||||||
name={appDisplayName.gemini}
|
|
||||||
size={iconSize}
|
|
||||||
className={
|
className={
|
||||||
activeApp === "gemini"
|
activeApp === "gemini"
|
||||||
? "text-foreground"
|
? "text-[#4285F4] dark:text-[#4285F4] transition-colors duration-200"
|
||||||
: "text-gray-500 dark:text-gray-400 group-hover:text-foreground transition-colors"
|
: "text-gray-500 dark:text-gray-400 group-hover:text-[#4285F4] dark:group-hover:text-[#4285F4] transition-colors duration-200"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<span>{appDisplayName.gemini}</span>
|
<span>Gemini</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,76 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Label } from "@/components/ui/label";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
|
|
||||||
interface ColorPickerProps {
|
|
||||||
value?: string;
|
|
||||||
onValueChange: (color: string) => void;
|
|
||||||
label?: string;
|
|
||||||
presets?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEFAULT_PRESETS = [
|
|
||||||
"#00A67E",
|
|
||||||
"#D4915D",
|
|
||||||
"#4285F4",
|
|
||||||
"#FF6A00",
|
|
||||||
"#00A4FF",
|
|
||||||
"#FF9900",
|
|
||||||
"#0078D4",
|
|
||||||
"#FF0000",
|
|
||||||
"#1E88E5",
|
|
||||||
"#6366F1",
|
|
||||||
"#0F62FE",
|
|
||||||
"#2932E1",
|
|
||||||
];
|
|
||||||
|
|
||||||
export const ColorPicker: React.FC<ColorPickerProps> = ({
|
|
||||||
value = "#4285F4",
|
|
||||||
onValueChange,
|
|
||||||
label = "图标颜色",
|
|
||||||
presets = DEFAULT_PRESETS,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div className="space-y-3">
|
|
||||||
<Label>{label}</Label>
|
|
||||||
|
|
||||||
{/* 颜色预设 */}
|
|
||||||
<div className="grid grid-cols-6 gap-2">
|
|
||||||
{presets.map((color) => (
|
|
||||||
<button
|
|
||||||
key={color}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onValueChange(color)}
|
|
||||||
className={cn(
|
|
||||||
"w-full aspect-square rounded-lg border-2 transition-all",
|
|
||||||
"hover:scale-110 hover:shadow-lg",
|
|
||||||
value === color
|
|
||||||
? "border-primary ring-2 ring-primary/20"
|
|
||||||
: "border-border",
|
|
||||||
)}
|
|
||||||
style={{ backgroundColor: color }}
|
|
||||||
title={color}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 自定义颜色输入 */}
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Input
|
|
||||||
type="color"
|
|
||||||
value={value}
|
|
||||||
onChange={(e) => onValueChange(e.target.value)}
|
|
||||||
className="w-16 h-10 p-1 cursor-pointer"
|
|
||||||
/>
|
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
value={value}
|
|
||||||
onChange={(e) => onValueChange(e.target.value)}
|
|
||||||
placeholder="#4285F4"
|
|
||||||
className="flex-1 font-mono"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useMemo } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { DeepLinkImportRequest, deeplinkApi } from "@/lib/api/deeplink";
|
import { DeepLinkImportRequest, deeplinkApi } from "@/lib/api/deeplink";
|
||||||
import {
|
import {
|
||||||
@@ -13,10 +13,6 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { PromptConfirmation } from "./deeplink/PromptConfirmation";
|
|
||||||
import { McpConfirmation } from "./deeplink/McpConfirmation";
|
|
||||||
import { SkillConfirmation } from "./deeplink/SkillConfirmation";
|
|
||||||
import { ProviderIcon } from "./ProviderIcon";
|
|
||||||
|
|
||||||
interface DeeplinkError {
|
interface DeeplinkError {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -30,52 +26,13 @@ export function DeepLinkImportDialog() {
|
|||||||
const [isImporting, setIsImporting] = useState(false);
|
const [isImporting, setIsImporting] = useState(false);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
// 容错判断:MCP 导入结果可能缺少 type 字段
|
|
||||||
const isMcpImportResult = (
|
|
||||||
value: unknown,
|
|
||||||
): value is {
|
|
||||||
importedCount: number;
|
|
||||||
importedIds: string[];
|
|
||||||
failed: Array<{ id: string; error: string }>;
|
|
||||||
type?: "mcp";
|
|
||||||
} => {
|
|
||||||
if (!value || typeof value !== "object") return false;
|
|
||||||
const v = value as Record<string, unknown>;
|
|
||||||
return (
|
|
||||||
typeof v.importedCount === "number" &&
|
|
||||||
Array.isArray(v.importedIds) &&
|
|
||||||
Array.isArray(v.failed)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Listen for deep link import events
|
// Listen for deep link import events
|
||||||
const unlistenImport = listen<DeepLinkImportRequest>(
|
const unlistenImport = listen<DeepLinkImportRequest>(
|
||||||
"deeplink-import",
|
"deeplink-import",
|
||||||
async (event) => {
|
(event) => {
|
||||||
console.log("Deep link import event received:", event.payload);
|
console.log("Deep link import event received:", event.payload);
|
||||||
|
|
||||||
// If config is present, merge it to get the complete configuration
|
|
||||||
if (event.payload.config || event.payload.configUrl) {
|
|
||||||
try {
|
|
||||||
const mergedRequest = await deeplinkApi.mergeDeeplinkConfig(
|
|
||||||
event.payload,
|
|
||||||
);
|
|
||||||
console.log("Config merged successfully:", mergedRequest);
|
|
||||||
setRequest(mergedRequest);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to merge config:", error);
|
|
||||||
toast.error(t("deeplink.configMergeError"), {
|
|
||||||
description:
|
|
||||||
error instanceof Error ? error.message : String(error),
|
|
||||||
});
|
|
||||||
// Fall back to original request
|
|
||||||
setRequest(event.payload);
|
setRequest(event.payload);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setRequest(event.payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsOpen(true);
|
setIsOpen(true);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -100,89 +57,23 @@ export function DeepLinkImportDialog() {
|
|||||||
setIsImporting(true);
|
setIsImporting(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await deeplinkApi.importFromDeeplink(request);
|
await deeplinkApi.importFromDeeplink(request);
|
||||||
const refreshMcp = async (summary: {
|
|
||||||
importedCount: number;
|
|
||||||
importedIds: string[];
|
|
||||||
failed: Array<{ id: string; error: string }>;
|
|
||||||
}) => {
|
|
||||||
// 强制刷新 MCP 相关缓存,确保管理页重新从数据库加载
|
|
||||||
await queryClient.invalidateQueries({
|
|
||||||
queryKey: ["mcp", "all"],
|
|
||||||
refetchType: "all",
|
|
||||||
});
|
|
||||||
await queryClient.refetchQueries({
|
|
||||||
queryKey: ["mcp", "all"],
|
|
||||||
type: "all",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (summary.failed.length > 0) {
|
// Invalidate provider queries to refresh the list
|
||||||
toast.warning(`部分导入成功`, {
|
|
||||||
description: `成功: ${summary.importedCount}, 失败: ${summary.failed.length}`,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
toast.success("MCP Servers 导入成功", {
|
|
||||||
description: `成功导入 ${summary.importedCount} 个服务器`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle different result types
|
|
||||||
if ("type" in result) {
|
|
||||||
if (result.type === "provider") {
|
|
||||||
await queryClient.invalidateQueries({
|
await queryClient.invalidateQueries({
|
||||||
queryKey: ["providers", request.app],
|
queryKey: ["providers", request.app],
|
||||||
});
|
});
|
||||||
|
|
||||||
toast.success(t("deeplink.importSuccess"), {
|
toast.success(t("deeplink.importSuccess"), {
|
||||||
description: t("deeplink.importSuccessDescription", {
|
description: t("deeplink.importSuccessDescription", {
|
||||||
name: request.name,
|
name: request.name,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} else if (result.type === "prompt") {
|
|
||||||
// Prompts don't use React Query, trigger a custom event for refresh
|
|
||||||
window.dispatchEvent(
|
|
||||||
new CustomEvent("prompt-imported", {
|
|
||||||
detail: { app: request.app },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
toast.success("提示词导入成功", {
|
|
||||||
description: `已导入提示词: ${request.name}`,
|
|
||||||
});
|
|
||||||
} else if (result.type === "mcp") {
|
|
||||||
await refreshMcp(result);
|
|
||||||
} else if (result.type === "skill") {
|
|
||||||
// Refresh Skills with aggressive strategy
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["skills"],
|
|
||||||
refetchType: "all",
|
|
||||||
});
|
|
||||||
await queryClient.refetchQueries({
|
|
||||||
queryKey: ["skills"],
|
|
||||||
type: "all",
|
|
||||||
});
|
|
||||||
toast.success("Skill 仓库添加成功", {
|
|
||||||
description: `已添加仓库: ${request.repo}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (isMcpImportResult(result)) {
|
|
||||||
// 兜底处理:旧版本后端可能未返回 type 字段
|
|
||||||
await refreshMcp(result);
|
|
||||||
} else {
|
|
||||||
// Legacy return type (string ID) - assume provider
|
|
||||||
await queryClient.invalidateQueries({
|
|
||||||
queryKey: ["providers", request.app],
|
|
||||||
});
|
|
||||||
toast.success(t("deeplink.importSuccess"), {
|
|
||||||
description: t("deeplink.importSuccessDescription", {
|
|
||||||
name: request.name,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close dialog after all refreshes complete
|
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
setRequest(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to import from deep link:", error);
|
console.error("Failed to import provider from deep link:", error);
|
||||||
toast.error(t("deeplink.importError"), {
|
toast.error(t("deeplink.importError"), {
|
||||||
description: error instanceof Error ? error.message : String(error),
|
description: error instanceof Error ? error.message : String(error),
|
||||||
});
|
});
|
||||||
@@ -193,157 +84,30 @@ export function DeepLinkImportDialog() {
|
|||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
setRequest(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!request) return null;
|
||||||
|
|
||||||
// Mask API key for display (show first 4 chars + ***)
|
// Mask API key for display (show first 4 chars + ***)
|
||||||
const maskedApiKey =
|
const maskedApiKey =
|
||||||
request?.apiKey && request.apiKey.length > 4
|
request.apiKey.length > 4
|
||||||
? `${request.apiKey.substring(0, 4)}${"*".repeat(20)}`
|
? `${request.apiKey.substring(0, 4)}${"*".repeat(20)}`
|
||||||
: "****";
|
: "****";
|
||||||
|
|
||||||
// Check if config file is present
|
|
||||||
const hasConfigFile = !!(request?.config || request?.configUrl);
|
|
||||||
const configSource = request?.config
|
|
||||||
? "base64"
|
|
||||||
: request?.configUrl
|
|
||||||
? "url"
|
|
||||||
: null;
|
|
||||||
|
|
||||||
// Parse config file content for display
|
|
||||||
interface ParsedConfig {
|
|
||||||
type: "claude" | "codex" | "gemini";
|
|
||||||
env?: Record<string, string>;
|
|
||||||
auth?: Record<string, string>;
|
|
||||||
tomlConfig?: string;
|
|
||||||
raw: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to decode base64 with UTF-8 support
|
|
||||||
const b64ToUtf8 = (str: string): string => {
|
|
||||||
try {
|
|
||||||
const binString = atob(str);
|
|
||||||
const bytes = Uint8Array.from(binString, (m) => m.codePointAt(0) || 0);
|
|
||||||
return new TextDecoder().decode(bytes);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to decode base64:", e);
|
|
||||||
return atob(str);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const parsedConfig = useMemo((): ParsedConfig | null => {
|
|
||||||
if (!request?.config) return null;
|
|
||||||
try {
|
|
||||||
const decoded = b64ToUtf8(request.config);
|
|
||||||
const parsed = JSON.parse(decoded) as Record<string, unknown>;
|
|
||||||
|
|
||||||
if (request.app === "claude") {
|
|
||||||
// Claude 格式: { env: { ANTHROPIC_AUTH_TOKEN: ..., ... } }
|
|
||||||
return {
|
|
||||||
type: "claude",
|
|
||||||
env: (parsed.env as Record<string, string>) || {},
|
|
||||||
raw: parsed,
|
|
||||||
};
|
|
||||||
} else if (request.app === "codex") {
|
|
||||||
// Codex 格式: { auth: { OPENAI_API_KEY: ... }, config: "TOML string" }
|
|
||||||
return {
|
|
||||||
type: "codex",
|
|
||||||
auth: (parsed.auth as Record<string, string>) || {},
|
|
||||||
tomlConfig: (parsed.config as string) || "",
|
|
||||||
raw: parsed,
|
|
||||||
};
|
|
||||||
} else if (request.app === "gemini") {
|
|
||||||
// Gemini 格式: 扁平结构 { GEMINI_API_KEY: ..., GEMINI_BASE_URL: ... }
|
|
||||||
return {
|
|
||||||
type: "gemini",
|
|
||||||
env: parsed as Record<string, string>,
|
|
||||||
raw: parsed,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse config:", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, [request?.config, request?.app]);
|
|
||||||
|
|
||||||
// Helper to mask sensitive values
|
|
||||||
const maskValue = (key: string, value: string): string => {
|
|
||||||
const sensitiveKeys = ["TOKEN", "KEY", "SECRET", "PASSWORD"];
|
|
||||||
const isSensitive = sensitiveKeys.some((k) =>
|
|
||||||
key.toUpperCase().includes(k),
|
|
||||||
);
|
|
||||||
if (isSensitive && value.length > 8) {
|
|
||||||
return `${value.substring(0, 8)}${"*".repeat(12)}`;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTitle = () => {
|
|
||||||
if (!request) return t("deeplink.confirmImport");
|
|
||||||
switch (request.resource) {
|
|
||||||
case "prompt":
|
|
||||||
return "导入提示词";
|
|
||||||
case "mcp":
|
|
||||||
return "导入 MCP Servers";
|
|
||||||
case "skill":
|
|
||||||
return "添加 Skill 仓库";
|
|
||||||
default:
|
|
||||||
return t("deeplink.confirmImport");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDescription = () => {
|
|
||||||
if (!request) return t("deeplink.confirmImportDescription");
|
|
||||||
switch (request.resource) {
|
|
||||||
case "prompt":
|
|
||||||
return "请确认是否导入此系统提示词";
|
|
||||||
case "mcp":
|
|
||||||
return "请确认是否导入这些 MCP Servers";
|
|
||||||
case "skill":
|
|
||||||
return "请确认是否添加此 Skill 仓库";
|
|
||||||
default:
|
|
||||||
return t("deeplink.confirmImportDescription");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen && !!request} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DialogContent className="sm:max-w-[500px]" zIndex="top">
|
<DialogContent className="sm:max-w-[500px]">
|
||||||
{request && (
|
|
||||||
<>
|
|
||||||
{/* 标题显式左对齐,避免默认居中样式影响 */}
|
{/* 标题显式左对齐,避免默认居中样式影响 */}
|
||||||
<DialogHeader className="text-left sm:text-left">
|
<DialogHeader className="text-left sm:text-left">
|
||||||
<DialogTitle>{getTitle()}</DialogTitle>
|
<DialogTitle>{t("deeplink.confirmImport")}</DialogTitle>
|
||||||
<DialogDescription>{getDescription()}</DialogDescription>
|
<DialogDescription>
|
||||||
|
{t("deeplink.confirmImportDescription")}
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
{/* 主体内容整体右移,略大于标题内边距,让内容看起来不贴边 */}
|
{/* 主体内容整体右移,略大于标题内边距,让内容看起来不贴边 */}
|
||||||
<div className="space-y-4 px-8 py-4 max-h-[60vh] overflow-y-auto [scrollbar-width:thin] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:block [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-gray-200 dark:[&::-webkit-scrollbar-thumb]:bg-gray-700">
|
<div className="space-y-4 px-8 py-4">
|
||||||
{request.resource === "prompt" && (
|
|
||||||
<PromptConfirmation request={request} />
|
|
||||||
)}
|
|
||||||
{request.resource === "mcp" && (
|
|
||||||
<McpConfirmation request={request} />
|
|
||||||
)}
|
|
||||||
{request.resource === "skill" && (
|
|
||||||
<SkillConfirmation request={request} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Legacy Provider View */}
|
|
||||||
{(request.resource === "provider" || !request.resource) && (
|
|
||||||
<>
|
|
||||||
{/* Provider Icon - enlarge and center near the top */}
|
|
||||||
{request.icon && (
|
|
||||||
<div className="flex justify-center pt-2 pb-1">
|
|
||||||
<ProviderIcon
|
|
||||||
icon={request.icon}
|
|
||||||
name={request.name || request.icon}
|
|
||||||
size={80}
|
|
||||||
className="drop-shadow-sm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* App Type */}
|
{/* App Type */}
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
@@ -359,9 +123,7 @@ export function DeepLinkImportDialog() {
|
|||||||
<div className="font-medium text-sm text-muted-foreground">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
{t("deeplink.providerName")}
|
{t("deeplink.providerName")}
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2 text-sm font-medium">
|
<div className="col-span-2 text-sm font-medium">{request.name}</div>
|
||||||
{request.name}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Homepage */}
|
{/* Homepage */}
|
||||||
@@ -394,54 +156,7 @@ export function DeepLinkImportDialog() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Model Fields - 根据应用类型显示不同的模型字段 */}
|
{/* Model (if present) */}
|
||||||
{request.app === "claude" ? (
|
|
||||||
<>
|
|
||||||
{/* Claude 四种模型字段 */}
|
|
||||||
{request.haikuModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.haikuModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.haikuModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.sonnetModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.sonnetModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.sonnetModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.opusModel && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.opusModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.opusModel}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{request.model && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.multiModel")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono">
|
|
||||||
{request.model}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{/* Codex 和 Gemini 使用通用 model 字段 */}
|
|
||||||
{request.model && (
|
{request.model && (
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
<div className="grid grid-cols-3 items-center gap-4">
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
<div className="font-medium text-sm text-muted-foreground">
|
||||||
@@ -452,8 +167,6 @@ export function DeepLinkImportDialog() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Notes (if present) */}
|
{/* Notes (if present) */}
|
||||||
{request.notes && (
|
{request.notes && (
|
||||||
@@ -467,141 +180,10 @@ export function DeepLinkImportDialog() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Config File Details (v3.8+) */}
|
|
||||||
{hasConfigFile && (
|
|
||||||
<div className="space-y-3 pt-2 border-t border-border-default">
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.configSource")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm">
|
|
||||||
<span className="inline-flex items-center px-2 py-0.5 rounded-md bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 text-xs font-medium">
|
|
||||||
{configSource === "base64"
|
|
||||||
? t("deeplink.configEmbedded")
|
|
||||||
: t("deeplink.configRemote")}
|
|
||||||
</span>
|
|
||||||
{request.configFormat && (
|
|
||||||
<span className="ml-2 text-xs text-muted-foreground uppercase">
|
|
||||||
{request.configFormat}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Parsed Config Details */}
|
|
||||||
{parsedConfig && (
|
|
||||||
<div className="rounded-lg bg-muted/50 p-3 space-y-2">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
|
||||||
{t("deeplink.configDetails")}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Claude config */}
|
|
||||||
{parsedConfig.type === "claude" &&
|
|
||||||
parsedConfig.env && (
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
{Object.entries(parsedConfig.env).map(
|
|
||||||
([key, value]) => (
|
|
||||||
<div
|
|
||||||
key={key}
|
|
||||||
className="grid grid-cols-2 gap-2 text-xs"
|
|
||||||
>
|
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
|
||||||
{key}
|
|
||||||
</span>
|
|
||||||
<span className="font-mono truncate">
|
|
||||||
{maskValue(key, String(value))}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Codex config */}
|
|
||||||
{parsedConfig.type === "codex" && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
{parsedConfig.auth &&
|
|
||||||
Object.keys(parsedConfig.auth).length > 0 && (
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
Auth:
|
|
||||||
</div>
|
|
||||||
{Object.entries(parsedConfig.auth).map(
|
|
||||||
([key, value]) => (
|
|
||||||
<div
|
|
||||||
key={key}
|
|
||||||
className="grid grid-cols-2 gap-2 text-xs pl-2"
|
|
||||||
>
|
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
|
||||||
{key}
|
|
||||||
</span>
|
|
||||||
<span className="font-mono truncate">
|
|
||||||
{maskValue(key, String(value))}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{parsedConfig.tomlConfig && (
|
|
||||||
<div className="space-y-1">
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
TOML Config:
|
|
||||||
</div>
|
|
||||||
<pre className="text-xs font-mono bg-background p-2 rounded overflow-x-auto max-h-24 whitespace-pre-wrap">
|
|
||||||
{parsedConfig.tomlConfig.substring(0, 300)}
|
|
||||||
{parsedConfig.tomlConfig.length > 300 &&
|
|
||||||
"..."}
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Gemini config */}
|
|
||||||
{parsedConfig.type === "gemini" &&
|
|
||||||
parsedConfig.env && (
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
{Object.entries(parsedConfig.env).map(
|
|
||||||
([key, value]) => (
|
|
||||||
<div
|
|
||||||
key={key}
|
|
||||||
className="grid grid-cols-2 gap-2 text-xs"
|
|
||||||
>
|
|
||||||
<span className="font-mono text-muted-foreground truncate">
|
|
||||||
{key}
|
|
||||||
</span>
|
|
||||||
<span className="font-mono truncate">
|
|
||||||
{maskValue(key, String(value))}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Config URL (if remote) */}
|
|
||||||
{request.configUrl && (
|
|
||||||
<div className="grid grid-cols-3 items-center gap-4">
|
|
||||||
<div className="font-medium text-sm text-muted-foreground">
|
|
||||||
{t("deeplink.configUrl")}
|
|
||||||
</div>
|
|
||||||
<div className="col-span-2 text-sm font-mono text-muted-foreground break-all">
|
|
||||||
{request.configUrl}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Warning */}
|
{/* Warning */}
|
||||||
<div className="rounded-lg bg-yellow-50 dark:bg-yellow-900/20 p-3 text-sm text-yellow-800 dark:text-yellow-200">
|
<div className="rounded-lg bg-yellow-50 dark:bg-yellow-900/20 p-3 text-sm text-yellow-800 dark:text-yellow-200">
|
||||||
{t("deeplink.warning")}
|
{t("deeplink.warning")}
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
@@ -616,8 +198,6 @@ export function DeepLinkImportDialog() {
|
|||||||
{isImporting ? t("deeplink.importing") : t("deeplink.import")}
|
{isImporting ? t("deeplink.importing") : t("deeplink.import")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
import React, { useState, useMemo } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Label } from "@/components/ui/label";
|
|
||||||
import { ProviderIcon } from "./ProviderIcon";
|
|
||||||
import { iconList } from "@/icons/extracted";
|
|
||||||
import { searchIcons, getIconMetadata } from "@/icons/extracted/metadata";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
|
|
||||||
interface IconPickerProps {
|
|
||||||
value?: string; // 当前选中的图标
|
|
||||||
onValueChange: (icon: string) => void; // 选择回调
|
|
||||||
color?: string; // 预览颜色
|
|
||||||
}
|
|
||||||
|
|
||||||
export const IconPicker: React.FC<IconPickerProps> = ({
|
|
||||||
value,
|
|
||||||
onValueChange,
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
|
||||||
|
|
||||||
// 过滤图标列表
|
|
||||||
const filteredIcons = useMemo(() => {
|
|
||||||
if (!searchQuery) return iconList;
|
|
||||||
return searchIcons(searchQuery);
|
|
||||||
}, [searchQuery]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="icon-search">
|
|
||||||
{t("iconPicker.search", { defaultValue: "搜索图标" })}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="icon-search"
|
|
||||||
type="text"
|
|
||||||
placeholder={t("iconPicker.searchPlaceholder", {
|
|
||||||
defaultValue: "输入图标名称...",
|
|
||||||
})}
|
|
||||||
value={searchQuery}
|
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="max-h-[65vh] overflow-y-auto pr-1">
|
|
||||||
<div className="grid grid-cols-6 sm:grid-cols-8 lg:grid-cols-10 gap-2">
|
|
||||||
{filteredIcons.map((iconName) => {
|
|
||||||
const meta = getIconMetadata(iconName);
|
|
||||||
const isSelected = value === iconName;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={iconName}
|
|
||||||
type="button"
|
|
||||||
onClick={() => onValueChange(iconName)}
|
|
||||||
className={cn(
|
|
||||||
"flex flex-col items-center gap-1 p-3 rounded-lg",
|
|
||||||
"border-2 transition-all duration-200",
|
|
||||||
"hover:bg-accent hover:border-primary/50",
|
|
||||||
isSelected
|
|
||||||
? "border-primary bg-primary/10"
|
|
||||||
: "border-transparent",
|
|
||||||
)}
|
|
||||||
title={meta?.displayName || iconName}
|
|
||||||
>
|
|
||||||
<ProviderIcon icon={iconName} name={iconName} size={32} />
|
|
||||||
<span className="text-xs text-muted-foreground truncate w-full text-center">
|
|
||||||
{meta?.displayName || iconName}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{filteredIcons.length === 0 && (
|
|
||||||
<div className="text-center py-8 text-muted-foreground">
|
|
||||||
{t("iconPicker.noResults", { defaultValue: "未找到匹配的图标" })}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -12,7 +12,6 @@ import { toast } from "sonner";
|
|||||||
import { formatJSON } from "@/utils/formatters";
|
import { formatJSON } from "@/utils/formatters";
|
||||||
|
|
||||||
interface JsonEditorProps {
|
interface JsonEditorProps {
|
||||||
id?: string;
|
|
||||||
value: string;
|
value: string;
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@@ -20,8 +19,7 @@ interface JsonEditorProps {
|
|||||||
rows?: number;
|
rows?: number;
|
||||||
showValidation?: boolean;
|
showValidation?: boolean;
|
||||||
language?: "json" | "javascript";
|
language?: "json" | "javascript";
|
||||||
height?: string | number;
|
height?: string;
|
||||||
showMinimap?: boolean; // 添加此属性以防未来使用
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const JsonEditor: React.FC<JsonEditorProps> = ({
|
const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||||
@@ -86,47 +84,19 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
|||||||
|
|
||||||
// 使用 baseTheme 定义基础样式,优先级低于 oneDark,但可以正确响应主题
|
// 使用 baseTheme 定义基础样式,优先级低于 oneDark,但可以正确响应主题
|
||||||
const baseTheme = EditorView.baseTheme({
|
const baseTheme = EditorView.baseTheme({
|
||||||
".cm-editor": {
|
"&light .cm-editor, &dark .cm-editor": {
|
||||||
border: "1px solid hsl(var(--border))",
|
border: "1px solid hsl(var(--border))",
|
||||||
borderRadius: "0.5rem",
|
borderRadius: "0.5rem",
|
||||||
background: "transparent",
|
|
||||||
},
|
},
|
||||||
".cm-editor.cm-focused": {
|
"&light .cm-editor.cm-focused, &dark .cm-editor.cm-focused": {
|
||||||
outline: "none",
|
outline: "none",
|
||||||
borderColor: "hsl(var(--primary))",
|
borderColor: "hsl(var(--primary))",
|
||||||
},
|
},
|
||||||
".cm-scroller": {
|
|
||||||
background: "transparent",
|
|
||||||
},
|
|
||||||
".cm-gutters": {
|
|
||||||
background: "transparent",
|
|
||||||
borderRight: "1px solid hsl(var(--border))",
|
|
||||||
color: "hsl(var(--muted-foreground))",
|
|
||||||
},
|
|
||||||
".cm-selectionBackground, .cm-content ::selection": {
|
|
||||||
background: "hsl(var(--primary) / 0.18)",
|
|
||||||
},
|
|
||||||
".cm-selectionMatch": {
|
|
||||||
background: "hsl(var(--primary) / 0.12)",
|
|
||||||
},
|
|
||||||
".cm-activeLine": {
|
|
||||||
background: "hsl(var(--primary) / 0.08)",
|
|
||||||
},
|
|
||||||
".cm-activeLineGutter": {
|
|
||||||
background: "hsl(var(--primary) / 0.08)",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 使用 theme 定义尺寸和字体样式
|
// 使用 theme 定义尺寸和字体样式
|
||||||
const heightValue = height
|
|
||||||
? typeof height === "number"
|
|
||||||
? `${height}px`
|
|
||||||
: height
|
|
||||||
: undefined;
|
|
||||||
const sizingTheme = EditorView.theme({
|
const sizingTheme = EditorView.theme({
|
||||||
"&": heightValue
|
"&": height ? { height } : { minHeight: `${minHeightPx}px` },
|
||||||
? { height: heightValue }
|
|
||||||
: { minHeight: `${minHeightPx}px` },
|
|
||||||
".cm-scroller": { overflow: "auto" },
|
".cm-scroller": { overflow: "auto" },
|
||||||
".cm-content": {
|
".cm-content": {
|
||||||
fontFamily:
|
fontFamily:
|
||||||
@@ -159,32 +129,11 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
|||||||
".cm-editor": {
|
".cm-editor": {
|
||||||
border: "1px solid hsl(var(--border))",
|
border: "1px solid hsl(var(--border))",
|
||||||
borderRadius: "0.5rem",
|
borderRadius: "0.5rem",
|
||||||
background: "transparent",
|
|
||||||
},
|
},
|
||||||
".cm-editor.cm-focused": {
|
".cm-editor.cm-focused": {
|
||||||
outline: "none",
|
outline: "none",
|
||||||
borderColor: "hsl(var(--primary))",
|
borderColor: "hsl(var(--primary))",
|
||||||
},
|
},
|
||||||
".cm-scroller": {
|
|
||||||
background: "transparent",
|
|
||||||
},
|
|
||||||
".cm-gutters": {
|
|
||||||
background: "transparent",
|
|
||||||
borderRight: "1px solid hsl(var(--border))",
|
|
||||||
color: "hsl(var(--muted-foreground))",
|
|
||||||
},
|
|
||||||
".cm-selectionBackground, .cm-content ::selection": {
|
|
||||||
background: "hsl(var(--primary) / 0.18)",
|
|
||||||
},
|
|
||||||
".cm-selectionMatch": {
|
|
||||||
background: "hsl(var(--primary) / 0.12)",
|
|
||||||
},
|
|
||||||
".cm-activeLine": {
|
|
||||||
background: "hsl(var(--primary) / 0.08)",
|
|
||||||
},
|
|
||||||
".cm-activeLineGutter": {
|
|
||||||
background: "hsl(var(--primary) / 0.08)",
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -247,23 +196,14 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isFullHeight = height === "100%";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div style={{ width: "100%" }}>
|
||||||
style={{ width: "100%", height: isFullHeight ? "100%" : "auto" }}
|
<div ref={editorRef} style={{ width: "100%" }} />
|
||||||
className={isFullHeight ? "flex flex-col" : ""}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
ref={editorRef}
|
|
||||||
style={{ width: "100%", height: isFullHeight ? undefined : "auto" }}
|
|
||||||
className={isFullHeight ? "flex-1 min-h-0" : ""}
|
|
||||||
/>
|
|
||||||
{language === "json" && (
|
{language === "json" && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleFormat}
|
onClick={handleFormat}
|
||||||
className={`${isFullHeight ? "mt-2 flex-shrink-0" : "mt-2"} inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors`}
|
className="mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
>
|
>
|
||||||
<Wand2 className="w-3.5 h-3.5" />
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
{t("common.format", { defaultValue: "格式化" })}
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
import React, { useMemo } from "react";
|
|
||||||
import { getIcon, hasIcon } from "@/icons/extracted";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
|
|
||||||
interface ProviderIconProps {
|
|
||||||
icon?: string; // 图标名称
|
|
||||||
name: string; // 供应商名称(用于 fallback)
|
|
||||||
color?: string; // 自定义颜色 (Deprecated, kept for compatibility but ignored for SVG)
|
|
||||||
size?: number | string; // 尺寸
|
|
||||||
className?: string;
|
|
||||||
showFallback?: boolean; // 是否显示 fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ProviderIcon: React.FC<ProviderIconProps> = ({
|
|
||||||
icon,
|
|
||||||
name,
|
|
||||||
size = 32,
|
|
||||||
className,
|
|
||||||
showFallback = true,
|
|
||||||
}) => {
|
|
||||||
// 获取图标 SVG
|
|
||||||
const iconSvg = useMemo(() => {
|
|
||||||
if (icon && hasIcon(icon)) {
|
|
||||||
return getIcon(icon);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}, [icon]);
|
|
||||||
|
|
||||||
// 计算尺寸样式
|
|
||||||
const sizeStyle = useMemo(() => {
|
|
||||||
const sizeValue = typeof size === "number" ? `${size}px` : size;
|
|
||||||
return {
|
|
||||||
width: sizeValue,
|
|
||||||
height: sizeValue,
|
|
||||||
// 内嵌 SVG 使用 1em 作为尺寸基准,这里同步 fontSize 让图标实际跟随 size 放大
|
|
||||||
fontSize: sizeValue,
|
|
||||||
lineHeight: 1,
|
|
||||||
};
|
|
||||||
}, [size]);
|
|
||||||
|
|
||||||
// 如果有图标,显示图标
|
|
||||||
if (iconSvg) {
|
|
||||||
return (
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
"inline-flex items-center justify-center flex-shrink-0",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
style={sizeStyle}
|
|
||||||
dangerouslySetInnerHTML={{ __html: iconSvg }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback:显示首字母
|
|
||||||
if (showFallback) {
|
|
||||||
const initials = name
|
|
||||||
.split(" ")
|
|
||||||
.map((word) => word[0])
|
|
||||||
.join("")
|
|
||||||
.toUpperCase()
|
|
||||||
.slice(0, 2);
|
|
||||||
const fallbackFontSize =
|
|
||||||
typeof size === "number" ? `${Math.max(size * 0.5, 12)}px` : "0.5em";
|
|
||||||
return (
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
"inline-flex items-center justify-center flex-shrink-0 rounded-lg",
|
|
||||||
"bg-muted text-muted-foreground font-semibold",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
style={sizeStyle}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
fontSize: fallbackFontSize,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{initials}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
@@ -60,7 +60,7 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
if (!usage.success) {
|
if (!usage.success) {
|
||||||
if (inline) {
|
if (inline) {
|
||||||
return (
|
return (
|
||||||
<div className="inline-flex items-center gap-2 text-xs rounded-lg border border-border-default bg-card px-3 py-2 shadow-sm">
|
<div className="flex items-center gap-2 text-xs">
|
||||||
<div className="flex items-center gap-1.5 text-red-500 dark:text-red-400">
|
<div className="flex items-center gap-1.5 text-red-500 dark:text-red-400">
|
||||||
<AlertCircle size={12} />
|
<AlertCircle size={12} />
|
||||||
<span>{t("usage.queryFailed")}</span>
|
<span>{t("usage.queryFailed")}</span>
|
||||||
@@ -68,7 +68,7 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
<button
|
<button
|
||||||
onClick={() => refetch()}
|
onClick={() => refetch()}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="p-1 rounded hover:bg-muted transition-colors disabled:opacity-50 flex-shrink-0"
|
className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 flex-shrink-0"
|
||||||
title={t("usage.refreshUsage")}
|
title={t("usage.refreshUsage")}
|
||||||
>
|
>
|
||||||
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
||||||
@@ -78,7 +78,7 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-3 rounded-xl border border-border-default bg-card px-4 py-3 shadow-sm">
|
<div className="mt-3 pt-3 border-t border-border-default ">
|
||||||
<div className="flex items-center justify-between gap-2 text-xs">
|
<div className="flex items-center justify-between gap-2 text-xs">
|
||||||
<div className="flex items-center gap-2 text-red-500 dark:text-red-400">
|
<div className="flex items-center gap-2 text-red-500 dark:text-red-400">
|
||||||
<AlertCircle size={14} />
|
<AlertCircle size={14} />
|
||||||
@@ -110,32 +110,29 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
const isExpired = firstUsage.isValid === false;
|
const isExpired = firstUsage.isValid === false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-end gap-1 text-xs whitespace-nowrap flex-shrink-0">
|
<div className="flex flex-col gap-1 text-xs flex-shrink-0">
|
||||||
{/* 第一行:更新时间和刷新按钮 */}
|
{/* 第一行:刷新时间 + 刷新按钮 */}
|
||||||
<div className="flex items-center gap-2 justify-end">
|
<div className="flex items-center gap-2 justify-end">
|
||||||
{/* 上次查询时间 */}
|
{/* 上次查询时间 */}
|
||||||
|
{lastQueriedAt && (
|
||||||
<span className="text-[10px] text-gray-400 dark:text-gray-500 flex items-center gap-1">
|
<span className="text-[10px] text-gray-400 dark:text-gray-500 flex items-center gap-1">
|
||||||
<Clock size={10} />
|
<Clock size={10} />
|
||||||
{lastQueriedAt
|
{formatRelativeTime(lastQueriedAt, now, t)}
|
||||||
? formatRelativeTime(lastQueriedAt, now, t)
|
|
||||||
: t("usage.never", { defaultValue: "从未更新" })}
|
|
||||||
</span>
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* 刷新按钮 */}
|
{/* 刷新按钮 */}
|
||||||
<button
|
<button
|
||||||
onClick={(e) => {
|
onClick={() => refetch()}
|
||||||
e.stopPropagation();
|
|
||||||
refetch();
|
|
||||||
}}
|
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 flex-shrink-0 text-gray-400 dark:text-gray-500"
|
className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 flex-shrink-0"
|
||||||
title={t("usage.refreshUsage")}
|
title={t("usage.refreshUsage")}
|
||||||
>
|
>
|
||||||
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 第二行:用量和剩余 */}
|
{/* 第二行:已用 + 剩余 + 单位 */}
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{/* 已用 */}
|
{/* 已用 */}
|
||||||
{firstUsage.used !== undefined && (
|
{firstUsage.used !== undefined && (
|
||||||
@@ -182,7 +179,7 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-3 rounded-xl border border-border-default bg-card px-4 py-3 shadow-sm">
|
<div className="mt-3 pt-3 border-t border-border-default ">
|
||||||
{/* 标题行:包含刷新按钮和自动查询时间 */}
|
{/* 标题行:包含刷新按钮和自动查询时间 */}
|
||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<span className="text-xs text-gray-500 dark:text-gray-400 font-medium">
|
<span className="text-xs text-gray-500 dark:text-gray-400 font-medium">
|
||||||
@@ -199,7 +196,7 @@ const UsageFooter: React.FC<UsageFooterProps> = ({
|
|||||||
<button
|
<button
|
||||||
onClick={() => refetch()}
|
onClick={() => refetch()}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
className="p-1 rounded hover:bg-muted transition-colors disabled:opacity-50"
|
className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors disabled:opacity-50"
|
||||||
title={t("usage.refreshUsage")}
|
title={t("usage.refreshUsage")}
|
||||||
>
|
>
|
||||||
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
<RefreshCw size={12} className={loading ? "animate-spin" : ""} />
|
||||||
|
|||||||
+193
-260
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Play, Wand2, Eye, EyeOff, Save } from "lucide-react";
|
import { Play, Wand2, Eye, EyeOff } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Provider, UsageScript } from "@/types";
|
import { Provider, UsageScript } from "@/types";
|
||||||
@@ -8,12 +8,17 @@ import JsonEditor from "./JsonEditor";
|
|||||||
import * as prettier from "prettier/standalone";
|
import * as prettier from "prettier/standalone";
|
||||||
import * as parserBabel from "prettier/parser-babel";
|
import * as parserBabel from "prettier/parser-babel";
|
||||||
import * as pluginEstree from "prettier/plugins/estree";
|
import * as pluginEstree from "prettier/plugins/estree";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
|
|
||||||
interface UsageScriptModalProps {
|
interface UsageScriptModalProps {
|
||||||
provider: Provider;
|
provider: Provider;
|
||||||
@@ -126,53 +131,88 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
|
|
||||||
const [testing, setTesting] = useState(false);
|
const [testing, setTesting] = useState(false);
|
||||||
|
|
||||||
|
// 🔧 输入时的格式化(宽松)- 只清理格式,不约束范围
|
||||||
|
const sanitizeNumberInput = (value: string): string => {
|
||||||
|
// 移除所有非数字字符
|
||||||
|
let cleaned = value.replace(/[^\d]/g, "");
|
||||||
|
|
||||||
|
// 移除前导零(除非输入的就是 "0")
|
||||||
|
if (cleaned.length > 1 && cleaned.startsWith("0")) {
|
||||||
|
cleaned = cleaned.replace(/^0+/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleaned;
|
||||||
|
};
|
||||||
|
|
||||||
// 🔧 失焦时的验证(严格)- 仅确保有效整数
|
// 🔧 失焦时的验证(严格)- 仅确保有效整数
|
||||||
const validateTimeout = (value: string): number => {
|
const validateTimeout = (value: string): number => {
|
||||||
|
// 转换为数字
|
||||||
const num = Number(value);
|
const num = Number(value);
|
||||||
|
|
||||||
|
// 检查是否为有效数字
|
||||||
if (isNaN(num) || value.trim() === "") {
|
if (isNaN(num) || value.trim() === "") {
|
||||||
return 10;
|
return 10; // 默认值
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否为整数
|
||||||
if (!Number.isInteger(num)) {
|
if (!Number.isInteger(num)) {
|
||||||
toast.warning(
|
toast.warning(
|
||||||
t("usageScript.timeoutMustBeInteger") || "超时时间必须为整数",
|
t("usageScript.timeoutMustBeInteger") || "超时时间必须为整数",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查负数
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
toast.error(
|
toast.error(
|
||||||
t("usageScript.timeoutCannotBeNegative") || "超时时间不能为负数",
|
t("usageScript.timeoutCannotBeNegative") || "超时时间不能为负数",
|
||||||
);
|
);
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.floor(num);
|
return Math.floor(num);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 🔧 失焦时的验证(严格)- 自动查询间隔
|
// 🔧 失焦时的验证(严格)- 自动查询间隔
|
||||||
const validateAndClampInterval = (value: string): number => {
|
const validateAndClampInterval = (value: string): number => {
|
||||||
|
// 转换为数字
|
||||||
const num = Number(value);
|
const num = Number(value);
|
||||||
|
|
||||||
|
// 检查是否为有效数字
|
||||||
if (isNaN(num) || value.trim() === "") {
|
if (isNaN(num) || value.trim() === "") {
|
||||||
return 0;
|
return 0; // 禁用自动查询
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否为整数
|
||||||
if (!Number.isInteger(num)) {
|
if (!Number.isInteger(num)) {
|
||||||
toast.warning(
|
toast.warning(
|
||||||
t("usageScript.intervalMustBeInteger") || "自动查询间隔必须为整数",
|
t("usageScript.intervalMustBeInteger") || "自动查询间隔必须为整数",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查负数
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
toast.error(
|
toast.error(
|
||||||
t("usageScript.intervalCannotBeNegative") || "自动查询间隔不能为负数",
|
t("usageScript.intervalCannotBeNegative") || "自动查询间隔不能为负数",
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 约束到 [0, 1440] 范围(最大24小时)
|
||||||
const clamped = Math.max(0, Math.min(1440, Math.floor(num)));
|
const clamped = Math.max(0, Math.min(1440, Math.floor(num)));
|
||||||
|
|
||||||
|
// 如果值被调整,显示提示
|
||||||
if (clamped !== num && num > 0) {
|
if (clamped !== num && num > 0) {
|
||||||
toast.info(
|
toast.info(
|
||||||
t("usageScript.intervalAdjusted", { value: clamped }) ||
|
t("usageScript.intervalAdjusted", { value: clamped }) ||
|
||||||
`自动查询间隔已调整为 ${clamped} 分钟`,
|
`自动查询间隔已调整为 ${clamped} 分钟`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return clamped;
|
return clamped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 跟踪当前选择的模板类型(用于控制高级配置的显示)
|
||||||
|
// 初始化:如果已有 accessToken 或 userId,说明是 NewAPI 模板
|
||||||
const [selectedTemplate, setSelectedTemplate] = useState<string | null>(
|
const [selectedTemplate, setSelectedTemplate] = useState<string | null>(
|
||||||
() => {
|
() => {
|
||||||
const existingScript = provider.meta?.usage_script;
|
const existingScript = provider.meta?.usage_script;
|
||||||
@@ -183,18 +223,23 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 控制 API Key 的显示/隐藏
|
||||||
const [showApiKey, setShowApiKey] = useState(false);
|
const [showApiKey, setShowApiKey] = useState(false);
|
||||||
const [showAccessToken, setShowAccessToken] = useState(false);
|
const [showAccessToken, setShowAccessToken] = useState(false);
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
// 验证脚本格式
|
||||||
if (script.enabled && !script.code.trim()) {
|
if (script.enabled && !script.code.trim()) {
|
||||||
toast.error(t("usageScript.scriptEmpty"));
|
toast.error(t("usageScript.scriptEmpty"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 基本的 JS 语法检查(检查是否包含 return 语句)
|
||||||
if (script.enabled && !script.code.includes("return")) {
|
if (script.enabled && !script.code.includes("return")) {
|
||||||
toast.error(t("usageScript.mustHaveReturn"), { duration: 5000 });
|
toast.error(t("usageScript.mustHaveReturn"), { duration: 5000 });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSave(script);
|
onSave(script);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
@@ -202,6 +247,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
const handleTest = async () => {
|
const handleTest = async () => {
|
||||||
setTesting(true);
|
setTesting(true);
|
||||||
try {
|
try {
|
||||||
|
// 使用当前编辑器中的脚本内容进行测试
|
||||||
const result = await usageApi.testScript(
|
const result = await usageApi.testScript(
|
||||||
provider.id,
|
provider.id,
|
||||||
appId,
|
appId,
|
||||||
@@ -213,6 +259,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
script.userId,
|
script.userId,
|
||||||
);
|
);
|
||||||
if (result.success && result.data && result.data.length > 0) {
|
if (result.success && result.data && result.data.length > 0) {
|
||||||
|
// 显示所有套餐数据
|
||||||
const summary = result.data
|
const summary = result.data
|
||||||
.map((plan) => {
|
.map((plan) => {
|
||||||
const planInfo = plan.planName ? `[${plan.planName}]` : "";
|
const planInfo = plan.planName ? `[${plan.planName}]` : "";
|
||||||
@@ -267,7 +314,9 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
const handleUsePreset = (presetName: string) => {
|
const handleUsePreset = (presetName: string) => {
|
||||||
const preset = PRESET_TEMPLATES[presetName];
|
const preset = PRESET_TEMPLATES[presetName];
|
||||||
if (preset) {
|
if (preset) {
|
||||||
|
// 根据模板类型清空不同的字段
|
||||||
if (presetName === TEMPLATE_KEYS.CUSTOM) {
|
if (presetName === TEMPLATE_KEYS.CUSTOM) {
|
||||||
|
// 自定义:清空所有凭证字段
|
||||||
setScript({
|
setScript({
|
||||||
...script,
|
...script,
|
||||||
code: preset,
|
code: preset,
|
||||||
@@ -277,6 +326,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
userId: undefined,
|
userId: undefined,
|
||||||
});
|
});
|
||||||
} else if (presetName === TEMPLATE_KEYS.GENERAL) {
|
} else if (presetName === TEMPLATE_KEYS.GENERAL) {
|
||||||
|
// 通用:保留 apiKey 和 baseUrl,清空 NewAPI 字段
|
||||||
setScript({
|
setScript({
|
||||||
...script,
|
...script,
|
||||||
code: preset,
|
code: preset,
|
||||||
@@ -284,78 +334,39 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
userId: undefined,
|
userId: undefined,
|
||||||
});
|
});
|
||||||
} else if (presetName === TEMPLATE_KEYS.NEW_API) {
|
} else if (presetName === TEMPLATE_KEYS.NEW_API) {
|
||||||
|
// NewAPI:清空 apiKey(NewAPI 不使用通用的 apiKey)
|
||||||
setScript({
|
setScript({
|
||||||
...script,
|
...script,
|
||||||
code: preset,
|
code: preset,
|
||||||
apiKey: undefined,
|
apiKey: undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setSelectedTemplate(presetName);
|
setSelectedTemplate(presetName); // 记录选择的模板
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 判断是否应该显示凭证配置区域
|
||||||
const shouldShowCredentialsConfig =
|
const shouldShowCredentialsConfig =
|
||||||
selectedTemplate === TEMPLATE_KEYS.GENERAL ||
|
selectedTemplate === TEMPLATE_KEYS.GENERAL ||
|
||||||
selectedTemplate === TEMPLATE_KEYS.NEW_API;
|
selectedTemplate === TEMPLATE_KEYS.NEW_API;
|
||||||
|
|
||||||
const footer = (
|
|
||||||
<>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="secondary"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleTest}
|
|
||||||
disabled={!script.enabled || testing}
|
|
||||||
>
|
|
||||||
<Play size={14} className="mr-1" />
|
|
||||||
{testing ? t("usageScript.testing") : t("usageScript.testScript")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleFormat}
|
|
||||||
disabled={!script.enabled}
|
|
||||||
title={t("usageScript.format")}
|
|
||||||
>
|
|
||||||
<Wand2 size={14} className="mr-1" />
|
|
||||||
{t("usageScript.format")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
onClick={onClose}
|
|
||||||
className="border-border/20 hover:bg-accent hover:text-accent-foreground"
|
|
||||||
>
|
|
||||||
{t("common.cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={handleSave}
|
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
|
||||||
>
|
|
||||||
<Save size={16} className="mr-2" />
|
|
||||||
{t("usageScript.saveConfig")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||||
isOpen={isOpen}
|
<DialogContent className="max-w-3xl max-h-[90vh] flex flex-col">
|
||||||
title={`${t("usageScript.title")} - ${provider.name}`}
|
<DialogHeader>
|
||||||
onClose={onClose}
|
<DialogTitle>
|
||||||
footer={footer}
|
{t("usageScript.title")} - {provider.name}
|
||||||
>
|
</DialogTitle>
|
||||||
<div className="glass rounded-xl border border-white/10 px-6 py-4 flex items-center justify-between gap-4">
|
</DialogHeader>
|
||||||
|
|
||||||
|
{/* Content - Scrollable */}
|
||||||
|
<div className="flex-1 overflow-y-auto px-6 py-4 space-y-4">
|
||||||
|
{/* 启用开关 */}
|
||||||
|
<div className="flex items-center justify-between gap-4 rounded-lg border border-border-default p-4">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<p className="text-sm font-medium leading-none text-foreground">
|
<p className="text-sm font-medium leading-none">
|
||||||
{t("usageScript.enableUsageQuery")}
|
{t("usageScript.enableUsageQuery")}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t("usageScript.autoQueryIntervalHint")}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<Switch
|
<Switch
|
||||||
checked={script.enabled}
|
checked={script.enabled}
|
||||||
@@ -367,48 +378,40 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{script.enabled && (
|
{script.enabled && (
|
||||||
<div className="space-y-6">
|
<>
|
||||||
{/* 预设模板选择 */}
|
{/* 预设模板选择 */}
|
||||||
<div className="space-y-4 glass rounded-xl border border-white/10 p-6">
|
<div>
|
||||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
<Label className="mb-2">
|
||||||
<Label className="text-base font-medium">
|
|
||||||
{t("usageScript.presetTemplate")}
|
{t("usageScript.presetTemplate")}
|
||||||
</Label>
|
</Label>
|
||||||
<span className="text-xs text-muted-foreground">
|
<div className="flex gap-2">
|
||||||
{t("usageScript.variablesHint")}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2 flex-wrap">
|
|
||||||
{Object.keys(PRESET_TEMPLATES).map((name) => {
|
{Object.keys(PRESET_TEMPLATES).map((name) => {
|
||||||
const isSelected = selectedTemplate === name;
|
const isSelected = selectedTemplate === name;
|
||||||
return (
|
return (
|
||||||
<Button
|
<button
|
||||||
key={name}
|
key={name}
|
||||||
type="button"
|
|
||||||
variant={isSelected ? "default" : "outline"}
|
|
||||||
size="sm"
|
|
||||||
className={cn(
|
|
||||||
"rounded-lg border",
|
|
||||||
isSelected
|
|
||||||
? "shadow-sm"
|
|
||||||
: "bg-background text-muted-foreground hover:bg-accent hover:text-accent-foreground",
|
|
||||||
)}
|
|
||||||
onClick={() => handleUsePreset(name)}
|
onClick={() => handleUsePreset(name)}
|
||||||
|
className={`px-3 py-1.5 text-xs rounded transition-colors ${
|
||||||
|
isSelected
|
||||||
|
? "bg-blue-500 text-white dark:bg-blue-600"
|
||||||
|
: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{t(TEMPLATE_NAME_KEYS[name])}
|
{t(TEMPLATE_NAME_KEYS[name])}
|
||||||
</Button>
|
</button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* 凭证配置 */}
|
{/* 凭证配置区域:通用和 NewAPI 模板显示 */}
|
||||||
{shouldShowCredentialsConfig && (
|
{shouldShowCredentialsConfig && (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4 p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
|
||||||
<h4 className="text-sm font-medium text-foreground">
|
<h4 className="text-sm font-medium text-gray-900 dark:text-gray-100">
|
||||||
{t("usageScript.credentialsConfig")}
|
{t("usageScript.credentialsConfig")}
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
{/* 通用模板:显示 apiKey + baseUrl */}
|
||||||
{selectedTemplate === TEMPLATE_KEYS.GENERAL && (
|
{selectedTemplate === TEMPLATE_KEYS.GENERAL && (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -423,13 +426,12 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
}
|
}
|
||||||
placeholder="sk-xxxxx"
|
placeholder="sk-xxxxx"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
{script.apiKey && (
|
{script.apiKey && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowApiKey(!showApiKey)}
|
onClick={() => setShowApiKey(!showApiKey)}
|
||||||
className="absolute inset-y-0 right-0 flex items-center pr-3 text-muted-foreground hover:text-foreground transition-colors"
|
className="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 transition-colors"
|
||||||
aria-label={
|
aria-label={
|
||||||
showApiKey
|
showApiKey
|
||||||
? t("apiKeyInput.hide")
|
? t("apiKeyInput.hide")
|
||||||
@@ -457,12 +459,12 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
}
|
}
|
||||||
placeholder="https://api.example.com"
|
placeholder="https://api.example.com"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* NewAPI 模板:显示 baseUrl + accessToken + userId */}
|
||||||
{selectedTemplate === TEMPLATE_KEYS.NEW_API && (
|
{selectedTemplate === TEMPLATE_KEYS.NEW_API && (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -476,7 +478,6 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
}
|
}
|
||||||
placeholder="https://api.newapi.com"
|
placeholder="https://api.newapi.com"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -499,7 +500,6 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
"usageScript.accessTokenPlaceholder",
|
"usageScript.accessTokenPlaceholder",
|
||||||
)}
|
)}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
{script.accessToken && (
|
{script.accessToken && (
|
||||||
<button
|
<button
|
||||||
@@ -507,7 +507,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
setShowAccessToken(!showAccessToken)
|
setShowAccessToken(!showAccessToken)
|
||||||
}
|
}
|
||||||
className="absolute inset-y-0 right-0 flex items-center pr-3 text-muted-foreground hover:text-foreground transition-colors"
|
className="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 transition-colors"
|
||||||
aria-label={
|
aria-label={
|
||||||
showAccessToken
|
showAccessToken
|
||||||
? t("apiKeyInput.hide")
|
? t("apiKeyInput.hide")
|
||||||
@@ -537,70 +537,32 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
}
|
}
|
||||||
placeholder={t("usageScript.userIdPlaceholder")}
|
placeholder={t("usageScript.userIdPlaceholder")}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 脚本配置 */}
|
{/* 脚本编辑器 */}
|
||||||
<div className="space-y-4 glass rounded-xl border border-white/10 p-6">
|
<div>
|
||||||
<div className="flex items-center justify-between">
|
<Label className="mb-2">{t("usageScript.queryScript")}</Label>
|
||||||
<h4 className="text-base font-medium text-foreground">
|
<JsonEditor
|
||||||
{t("usageScript.scriptConfig")}
|
value={script.code}
|
||||||
</h4>
|
onChange={(code) => setScript({ ...script, code })}
|
||||||
<p className="text-xs text-muted-foreground">
|
height="300px"
|
||||||
{t("usageScript.variablesHint")}
|
language="javascript"
|
||||||
|
/>
|
||||||
|
<p className="mt-2 text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
{t("usageScript.variablesHint", {
|
||||||
|
apiKey: "{{apiKey}}",
|
||||||
|
baseUrl: "{{baseUrl}}",
|
||||||
|
})}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-4">
|
{/* 配置选项 */}
|
||||||
<div className="space-y-2">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
<Label htmlFor="usage-request-url">
|
|
||||||
{t("usageScript.requestUrl")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="usage-request-url"
|
|
||||||
type="text"
|
|
||||||
value={script.request?.url || ""}
|
|
||||||
onChange={(e) => {
|
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
request: { ...script.request, url: e.target.value },
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
placeholder={t("usageScript.requestUrlPlaceholder")}
|
|
||||||
className="border-white/10"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="usage-method">
|
|
||||||
{t("usageScript.method")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="usage-method"
|
|
||||||
type="text"
|
|
||||||
value={script.request?.method || "GET"}
|
|
||||||
onChange={(e) => {
|
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
request: {
|
|
||||||
...script.request,
|
|
||||||
method: e.target.value.toUpperCase(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
placeholder="GET / POST"
|
|
||||||
className="border-white/10"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="usage-timeout">
|
<Label htmlFor="usage-timeout">
|
||||||
{t("usageScript.timeoutSeconds")}
|
{t("usageScript.timeoutSeconds")}
|
||||||
@@ -608,140 +570,71 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
<Input
|
<Input
|
||||||
id="usage-timeout"
|
id="usage-timeout"
|
||||||
type="number"
|
type="number"
|
||||||
min={0}
|
value={script.timeout ?? ""}
|
||||||
value={script.timeout ?? 10}
|
onChange={(e) => {
|
||||||
onChange={(e) =>
|
// 输入时:只清理格式,允许临时为空,避免强制回填默认值
|
||||||
setScript({
|
const cleaned = sanitizeNumberInput(e.target.value);
|
||||||
...script,
|
setScript((prev) => ({
|
||||||
timeout: validateTimeout(e.target.value),
|
...prev,
|
||||||
})
|
timeout:
|
||||||
}
|
cleaned === "" ? undefined : parseInt(cleaned, 10),
|
||||||
onBlur={(e) =>
|
}));
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
timeout: validateTimeout(e.target.value),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
className="border-white/10"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="usage-headers">
|
|
||||||
{t("usageScript.headers")}
|
|
||||||
</Label>
|
|
||||||
<JsonEditor
|
|
||||||
id="usage-headers"
|
|
||||||
value={
|
|
||||||
script.request?.headers
|
|
||||||
? JSON.stringify(script.request.headers, null, 2)
|
|
||||||
: "{}"
|
|
||||||
}
|
|
||||||
onChange={(value) => {
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(value || "{}");
|
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
request: { ...script.request, headers: parsed },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Invalid headers JSON", error);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
height={180}
|
onBlur={(e) => {
|
||||||
/>
|
// 失焦时:严格验证并约束范围
|
||||||
</div>
|
const validated = validateTimeout(e.target.value);
|
||||||
|
setScript({ ...script, timeout: validated });
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="usage-body">{t("usageScript.body")}</Label>
|
|
||||||
<JsonEditor
|
|
||||||
id="usage-body"
|
|
||||||
value={
|
|
||||||
script.request?.body
|
|
||||||
? JSON.stringify(script.request.body, null, 2)
|
|
||||||
: "{}"
|
|
||||||
}
|
|
||||||
onChange={(value) => {
|
|
||||||
try {
|
|
||||||
const parsed =
|
|
||||||
value?.trim() === "" ? undefined : JSON.parse(value);
|
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
request: { ...script.request, body: parsed },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
toast.error(
|
|
||||||
t("usageScript.invalidJson") || "Body 必须是合法 JSON",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
height={220}
|
|
||||||
/>
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{t("usageScript.timeoutHint") || "范围: 2-30 秒"}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* 🆕 自动查询间隔 */}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="usage-interval">
|
<Label htmlFor="usage-auto-interval">
|
||||||
{t("usageScript.autoIntervalMinutes")}
|
{t("usageScript.autoQueryInterval")}
|
||||||
</Label>
|
</Label>
|
||||||
<Input
|
<Input
|
||||||
id="usage-interval"
|
id="usage-auto-interval"
|
||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
max={1440}
|
max={1440}
|
||||||
value={script.autoIntervalMinutes ?? 0}
|
step={1}
|
||||||
onChange={(e) =>
|
value={script.autoQueryInterval ?? ""}
|
||||||
setScript({
|
onChange={(e) => {
|
||||||
...script,
|
// 输入时:只清理格式,允许临时为空
|
||||||
autoIntervalMinutes: validateAndClampInterval(
|
const cleaned = sanitizeNumberInput(e.target.value);
|
||||||
|
setScript((prev) => ({
|
||||||
|
...prev,
|
||||||
|
autoQueryInterval:
|
||||||
|
cleaned === "" ? undefined : parseInt(cleaned, 10),
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
onBlur={(e) => {
|
||||||
|
// 失焦时:严格验证并约束范围
|
||||||
|
const validated = validateAndClampInterval(
|
||||||
e.target.value,
|
e.target.value,
|
||||||
),
|
);
|
||||||
})
|
setScript({ ...script, autoQueryInterval: validated });
|
||||||
}
|
}}
|
||||||
onBlur={(e) =>
|
|
||||||
setScript({
|
|
||||||
...script,
|
|
||||||
autoIntervalMinutes: validateAndClampInterval(
|
|
||||||
e.target.value,
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
className="border-white/10"
|
|
||||||
/>
|
/>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
{t("usageScript.autoQueryIntervalHint")}
|
{t("usageScript.autoQueryIntervalHint")}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 提取器代码 */}
|
{/* 脚本说明 */}
|
||||||
<div className="space-y-4 glass rounded-xl border border-white/10 p-6">
|
<div className="p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg text-sm text-gray-700 dark:text-gray-300">
|
||||||
<div className="flex items-center justify-between">
|
<h4 className="font-medium mb-2">
|
||||||
<Label className="text-base font-medium">
|
{t("usageScript.scriptHelp")}
|
||||||
{t("usageScript.extractorCode")}
|
</h4>
|
||||||
</Label>
|
|
||||||
<div className="text-xs text-muted-foreground">
|
|
||||||
{t("usageScript.extractorHint")}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<JsonEditor
|
|
||||||
id="usage-code"
|
|
||||||
value={script.code || ""}
|
|
||||||
onChange={(value) => setScript({ ...script, code: value })}
|
|
||||||
height={480}
|
|
||||||
language="javascript"
|
|
||||||
showMinimap={false}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 帮助信息 */}
|
|
||||||
<div className="glass rounded-xl border border-white/10 p-6 text-sm text-foreground/90">
|
|
||||||
<h4 className="font-medium mb-2">{t("usageScript.scriptHelp")}</h4>
|
|
||||||
<div className="space-y-3 text-xs">
|
<div className="space-y-3 text-xs">
|
||||||
<div>
|
<div>
|
||||||
<strong>{t("usageScript.configFormat")}</strong>
|
<strong>{t("usageScript.configFormat")}</strong>
|
||||||
<pre className="mt-1 p-2 bg-black/20 text-foreground rounded border border-white/10 text-[10px] overflow-x-auto">
|
<pre className="mt-1 p-2 bg-white/50 dark:bg-black/20 rounded text-[10px] overflow-x-auto">
|
||||||
{`({
|
{`({
|
||||||
request: {
|
request: {
|
||||||
url: "{{baseUrl}}/api/usage",
|
url: "{{baseUrl}}/api/usage",
|
||||||
@@ -749,9 +642,11 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
headers: {
|
headers: {
|
||||||
"Authorization": "Bearer {{apiKey}}",
|
"Authorization": "Bearer {{apiKey}}",
|
||||||
"User-Agent": "cc-switch/1.0"
|
"User-Agent": "cc-switch/1.0"
|
||||||
}
|
},
|
||||||
|
body: JSON.stringify({ key: "value" }) // ${t("usageScript.commentOptional")}
|
||||||
},
|
},
|
||||||
extractor: function(response) {
|
extractor: function(response) {
|
||||||
|
// ${t("usageScript.commentResponseIsJson")}
|
||||||
return {
|
return {
|
||||||
isValid: !response.error,
|
isValid: !response.error,
|
||||||
remaining: response.balance,
|
remaining: response.balance,
|
||||||
@@ -776,7 +671,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-muted-foreground">
|
<div className="text-gray-600 dark:text-gray-400">
|
||||||
<strong>{t("usageScript.tips")}</strong>
|
<strong>{t("usageScript.tips")}</strong>
|
||||||
<ul className="mt-1 space-y-0.5 ml-2">
|
<ul className="mt-1 space-y-0.5 ml-2">
|
||||||
<li>
|
<li>
|
||||||
@@ -791,9 +686,47 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
)}
|
)}
|
||||||
</FullScreenPanel>
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<DialogFooter className="flex-col sm:flex-row sm:justify-between gap-3 pt-4">
|
||||||
|
{/* Left side - Test and Format buttons */}
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleTest}
|
||||||
|
disabled={!script.enabled || testing}
|
||||||
|
>
|
||||||
|
<Play size={14} />
|
||||||
|
{testing ? t("usageScript.testing") : t("usageScript.testScript")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleFormat}
|
||||||
|
disabled={!script.enabled}
|
||||||
|
title={t("usageScript.format")}
|
||||||
|
>
|
||||||
|
<Wand2 size={14} />
|
||||||
|
{t("usageScript.format")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Right side - Cancel and Save buttons */}
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button variant="ghost" size="sm" onClick={onClose}>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button variant="default" size="sm" onClick={handleSave}>
|
||||||
|
{t("usageScript.saveConfig")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import { Bot } from "lucide-react";
|
|
||||||
|
|
||||||
interface AgentsPanelProps {
|
|
||||||
onOpenChange: (open: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function AgentsPanel({}: AgentsPanelProps) {
|
|
||||||
return (
|
|
||||||
<div className="mx-auto max-w-5xl flex flex-col h-[calc(100vh-8rem)]">
|
|
||||||
<div className="flex-1 glass-card rounded-xl p-8 flex flex-col items-center justify-center text-center space-y-4">
|
|
||||||
<div className="w-20 h-20 rounded-full bg-white/5 flex items-center justify-center mb-4 animate-pulse-slow">
|
|
||||||
<Bot className="w-10 h-10 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<h3 className="text-xl font-semibold">Coming Soon</h3>
|
|
||||||
<p className="text-muted-foreground max-w-md">
|
|
||||||
The Agents management feature is currently under development. Stay
|
|
||||||
tuned for powerful autonomous capabilities.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { createPortal } from "react-dom";
|
|
||||||
import { ArrowLeft } from "lucide-react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
|
|
||||||
interface FullScreenPanelProps {
|
|
||||||
isOpen: boolean;
|
|
||||||
title: string;
|
|
||||||
onClose: () => void;
|
|
||||||
children: React.ReactNode;
|
|
||||||
footer?: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reusable full-screen panel component
|
|
||||||
* Handles portal rendering, header with back button, and footer
|
|
||||||
* Uses solid theme colors without transparency
|
|
||||||
*/
|
|
||||||
export const FullScreenPanel: React.FC<FullScreenPanelProps> = ({
|
|
||||||
isOpen,
|
|
||||||
title,
|
|
||||||
onClose,
|
|
||||||
children,
|
|
||||||
footer,
|
|
||||||
}) => {
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (isOpen) {
|
|
||||||
document.body.style.overflow = "hidden";
|
|
||||||
}
|
|
||||||
return () => {
|
|
||||||
document.body.style.overflow = "";
|
|
||||||
};
|
|
||||||
}, [isOpen]);
|
|
||||||
|
|
||||||
if (!isOpen) return null;
|
|
||||||
|
|
||||||
return createPortal(
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 z-[60] flex flex-col"
|
|
||||||
style={{ backgroundColor: "hsl(var(--background))" }}
|
|
||||||
>
|
|
||||||
{/* Header */}
|
|
||||||
<div
|
|
||||||
className="flex-shrink-0 py-3 border-b border-border-default"
|
|
||||||
style={{ backgroundColor: "hsl(var(--background))" }}
|
|
||||||
>
|
|
||||||
<div className="h-4 w-full" data-tauri-drag-region />
|
|
||||||
<div className="mx-auto max-w-[56rem] px-6 flex items-center gap-4">
|
|
||||||
<Button type="button" variant="outline" size="icon" onClick={onClose}>
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<h2 className="text-lg font-semibold text-foreground">{title}</h2>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Content */}
|
|
||||||
<div className="flex-1 overflow-y-auto scroll-overlay">
|
|
||||||
<div className="mx-auto max-w-[56rem] px-6 py-6 space-y-6 w-full">
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Footer */}
|
|
||||||
{footer && (
|
|
||||||
<div
|
|
||||||
className="flex-shrink-0 py-4 border-t border-border-default"
|
|
||||||
style={{ backgroundColor: "hsl(var(--background))" }}
|
|
||||||
>
|
|
||||||
<div className="mx-auto max-w-[56rem] px-6 flex items-center justify-end gap-3">
|
|
||||||
{footer}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>,
|
|
||||||
document.body,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
|
||||||
import { decodeBase64Utf8 } from "../../lib/utils/base64";
|
|
||||||
|
|
||||||
export function McpConfirmation({
|
|
||||||
request,
|
|
||||||
}: {
|
|
||||||
request: DeepLinkImportRequest;
|
|
||||||
}) {
|
|
||||||
const mcpServers = useMemo(() => {
|
|
||||||
if (!request.config) return null;
|
|
||||||
try {
|
|
||||||
const decoded = decodeBase64Utf8(request.config);
|
|
||||||
const parsed = JSON.parse(decoded);
|
|
||||||
return parsed.mcpServers || {};
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse MCP config:", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, [request.config]);
|
|
||||||
|
|
||||||
const targetApps = request.apps?.split(",") || [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h3 className="text-lg font-semibold">批量导入 MCP Servers</h3>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
目标应用
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 flex gap-2 flex-wrap">
|
|
||||||
{targetApps.map((app) => (
|
|
||||||
<span
|
|
||||||
key={app}
|
|
||||||
className="px-2 py-1 bg-primary/10 text-primary text-xs rounded capitalize"
|
|
||||||
>
|
|
||||||
{app.trim()}
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
MCP Servers ({Object.keys(mcpServers || {}).length} 个)
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 space-y-2 max-h-64 overflow-auto border rounded p-2 bg-muted/30">
|
|
||||||
{mcpServers &&
|
|
||||||
Object.entries(mcpServers).map(([id, spec]: [string, any]) => (
|
|
||||||
<div key={id} className="p-2 bg-background rounded border">
|
|
||||||
<div className="font-semibold text-sm">{id}</div>
|
|
||||||
<div className="text-xs text-muted-foreground mt-1 font-mono truncate">
|
|
||||||
{spec.command
|
|
||||||
? `Command: ${spec.command} `
|
|
||||||
: `URL: ${spec.url} `}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{request.enabled && (
|
|
||||||
<div className="text-yellow-600 dark:text-yellow-500 text-sm flex items-center gap-2">
|
|
||||||
<span>⚠️</span>
|
|
||||||
<span>导入后将立即写入所有指定应用的配置文件</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
|
||||||
import { decodeBase64Utf8 } from "../../lib/utils/base64";
|
|
||||||
|
|
||||||
export function PromptConfirmation({
|
|
||||||
request,
|
|
||||||
}: {
|
|
||||||
request: DeepLinkImportRequest;
|
|
||||||
}) {
|
|
||||||
const decodedContent = useMemo(() => {
|
|
||||||
if (!request.content) return "";
|
|
||||||
return decodeBase64Utf8(request.content);
|
|
||||||
}, [request.content]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h3 className="text-lg font-semibold">导入系统提示词</h3>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
应用
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm capitalize">{request.app}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
名称
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm">{request.name}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{request.description && (
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
描述
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm">{request.description}</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
内容预览
|
|
||||||
</label>
|
|
||||||
<pre className="mt-1 max-h-48 overflow-auto bg-muted/50 p-2 rounded text-xs whitespace-pre-wrap border">
|
|
||||||
{decodedContent.substring(0, 500)}
|
|
||||||
{decodedContent.length > 500 && "..."}
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{request.enabled && (
|
|
||||||
<div className="text-yellow-600 dark:text-yellow-500 text-sm flex items-center gap-2">
|
|
||||||
<span>⚠️</span>
|
|
||||||
<span>导入后将立即启用此提示词,其他提示词将被禁用</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { DeepLinkImportRequest } from "../../lib/api/deeplink";
|
|
||||||
|
|
||||||
export function SkillConfirmation({
|
|
||||||
request,
|
|
||||||
}: {
|
|
||||||
request: DeepLinkImportRequest;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h3 className="text-lg font-semibold">添加 Claude Skill 仓库</h3>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
GitHub 仓库
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm font-mono bg-muted/50 p-2 rounded border">
|
|
||||||
{request.repo}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
目标目录
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm font-mono bg-muted/50 p-2 rounded border">
|
|
||||||
{request.directory}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
分支
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm">{request.branch || "main"}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{request.skillsPath && (
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-muted-foreground">
|
|
||||||
Skills 路径
|
|
||||||
</label>
|
|
||||||
<div className="mt-1 text-sm">{request.skillsPath}</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="text-blue-600 dark:text-blue-400 text-sm bg-blue-50 dark:bg-blue-950/30 p-3 rounded border border-blue-200 dark:border-blue-800">
|
|
||||||
<p>ℹ️ 此操作将添加 Skill 仓库到列表。</p>
|
|
||||||
<p className="mt-1">
|
|
||||||
添加后,您可以在 Skills 管理界面中选择安装具体的 Skill。
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+2
-2
@@ -110,7 +110,7 @@ export function EnvWarningBanner({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="fixed top-0 left-0 right-0 z-[100] bg-yellow-50 dark:bg-yellow-950 border-b border-yellow-200 dark:border-yellow-900 shadow-lg animate-slide-down">
|
<div className="bg-yellow-50 dark:bg-yellow-950/20 border-b border-yellow-200 dark:border-yellow-900/50">
|
||||||
<div className="container mx-auto px-4 py-3">
|
<div className="container mx-auto px-4 py-3">
|
||||||
<div className="flex items-start gap-3">
|
<div className="flex items-start gap-3">
|
||||||
<AlertTriangle className="h-5 w-5 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5" />
|
<AlertTriangle className="h-5 w-5 text-yellow-600 dark:text-yellow-500 flex-shrink-0 mt-0.5" />
|
||||||
@@ -241,7 +241,7 @@ export function EnvWarningBanner({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Dialog open={showConfirmDialog} onOpenChange={setShowConfirmDialog}>
|
<Dialog open={showConfirmDialog} onOpenChange={setShowConfirmDialog}>
|
||||||
<DialogContent className="max-w-md" zIndex="top">
|
<DialogContent className="max-w-md">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="flex items-center gap-2">
|
<DialogTitle className="flex items-center gap-2">
|
||||||
<AlertTriangle className="h-5 w-5 text-destructive" />
|
<AlertTriangle className="h-5 w-5 text-destructive" />
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
import React, { useMemo, useState, useEffect } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Save, Plus, AlertCircle, ChevronDown, ChevronUp } from "lucide-react";
|
import {
|
||||||
|
Save,
|
||||||
|
Plus,
|
||||||
|
AlertCircle,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
|
Wand2,
|
||||||
|
} from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import type { AppId } from "@/lib/api/types";
|
import type { AppId } from "@/lib/api/types";
|
||||||
import { McpServer, McpServerSpec } from "@/types";
|
import { McpServer, McpServerSpec } from "@/types";
|
||||||
import { mcpPresets, getMcpPresetWithDescription } from "@/config/mcpPresets";
|
import { mcpPresets, getMcpPresetWithDescription } from "@/config/mcpPresets";
|
||||||
@@ -20,21 +34,25 @@ import {
|
|||||||
mcpServerToToml,
|
mcpServerToToml,
|
||||||
} from "@/utils/tomlUtils";
|
} from "@/utils/tomlUtils";
|
||||||
import { normalizeTomlText } from "@/utils/textNormalization";
|
import { normalizeTomlText } from "@/utils/textNormalization";
|
||||||
import { parseSmartMcpJson } from "@/utils/formatters";
|
import { formatJSON, parseSmartMcpJson } from "@/utils/formatters";
|
||||||
import { useMcpValidation } from "./useMcpValidation";
|
import { useMcpValidation } from "./useMcpValidation";
|
||||||
import { useUpsertMcpServer } from "@/hooks/useMcp";
|
import { useUpsertMcpServer } from "@/hooks/useMcp";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
|
|
||||||
interface McpFormModalProps {
|
interface McpFormModalProps {
|
||||||
editingId?: string;
|
editingId?: string;
|
||||||
initialData?: McpServer;
|
initialData?: McpServer;
|
||||||
onSave: () => Promise<void>;
|
onSave: () => Promise<void>; // v3.7.0: 简化为仅用于关闭表单的回调
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
existingIds?: string[];
|
existingIds?: string[];
|
||||||
defaultFormat?: "json" | "toml";
|
defaultFormat?: "json" | "toml"; // 默认配置格式(可选,默认为 JSON)
|
||||||
defaultEnabledApps?: AppId[];
|
defaultEnabledApps?: AppId[]; // 默认启用到哪些应用(可选,默认为全部应用)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MCP 表单模态框组件(v3.7.0 完整重构版)
|
||||||
|
* - 支持 JSON 和 TOML 两种格式
|
||||||
|
* - 统一管理,通过复选框选择启用到哪些应用
|
||||||
|
*/
|
||||||
const McpFormModal: React.FC<McpFormModalProps> = ({
|
const McpFormModal: React.FC<McpFormModalProps> = ({
|
||||||
editingId,
|
editingId,
|
||||||
initialData,
|
initialData,
|
||||||
@@ -61,6 +79,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
const [formDocs, setFormDocs] = useState(initialData?.docs || "");
|
const [formDocs, setFormDocs] = useState(initialData?.docs || "");
|
||||||
const [formTags, setFormTags] = useState(initialData?.tags?.join(", ") || "");
|
const [formTags, setFormTags] = useState(initialData?.tags?.join(", ") || "");
|
||||||
|
|
||||||
|
// 启用状态:编辑模式使用现有值,新增模式使用默认值
|
||||||
const [enabledApps, setEnabledApps] = useState<{
|
const [enabledApps, setEnabledApps] = useState<{
|
||||||
claude: boolean;
|
claude: boolean;
|
||||||
codex: boolean;
|
codex: boolean;
|
||||||
@@ -69,6 +88,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
if (initialData?.apps) {
|
if (initialData?.apps) {
|
||||||
return { ...initialData.apps };
|
return { ...initialData.apps };
|
||||||
}
|
}
|
||||||
|
// 新增模式:根据 defaultEnabledApps 设置初始值
|
||||||
return {
|
return {
|
||||||
claude: defaultEnabledApps.includes("claude"),
|
claude: defaultEnabledApps.includes("claude"),
|
||||||
codex: defaultEnabledApps.includes("codex"),
|
codex: defaultEnabledApps.includes("codex"),
|
||||||
@@ -76,8 +96,10 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 编辑模式下禁止修改 ID
|
||||||
const isEditing = !!editingId;
|
const isEditing = !!editingId;
|
||||||
|
|
||||||
|
// 判断是否在编辑模式下有附加信息
|
||||||
const hasAdditionalInfo = !!(
|
const hasAdditionalInfo = !!(
|
||||||
initialData?.description ||
|
initialData?.description ||
|
||||||
initialData?.tags?.length ||
|
initialData?.tags?.length ||
|
||||||
@@ -85,17 +107,21 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
initialData?.docs
|
initialData?.docs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 附加信息展开状态(编辑模式下有值时默认展开)
|
||||||
const [showMetadata, setShowMetadata] = useState(
|
const [showMetadata, setShowMetadata] = useState(
|
||||||
isEditing ? hasAdditionalInfo : false,
|
isEditing ? hasAdditionalInfo : false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 配置格式:优先使用 defaultFormat,编辑模式下可从现有数据推断
|
||||||
const useTomlFormat = useMemo(() => {
|
const useTomlFormat = useMemo(() => {
|
||||||
if (initialData?.server) {
|
if (initialData?.server) {
|
||||||
|
// 编辑模式:尝试从现有数据推断格式(这里简化处理,默认 JSON)
|
||||||
return defaultFormat === "toml";
|
return defaultFormat === "toml";
|
||||||
}
|
}
|
||||||
return defaultFormat === "toml";
|
return defaultFormat === "toml";
|
||||||
}, [defaultFormat, initialData]);
|
}, [defaultFormat, initialData]);
|
||||||
|
|
||||||
|
// 根据格式决定初始配置
|
||||||
const [formConfig, setFormConfig] = useState(() => {
|
const [formConfig, setFormConfig] = useState(() => {
|
||||||
const spec = initialData?.server;
|
const spec = initialData?.server;
|
||||||
if (!spec) return "";
|
if (!spec) return "";
|
||||||
@@ -109,23 +135,8 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [isWizardOpen, setIsWizardOpen] = useState(false);
|
const [isWizardOpen, setIsWizardOpen] = useState(false);
|
||||||
const [idError, setIdError] = useState("");
|
const [idError, setIdError] = useState("");
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.documentElement, {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ["class"],
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => observer.disconnect();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
// 判断是否使用 TOML 格式(向后兼容,后续可扩展为格式切换按钮)
|
||||||
const useToml = useTomlFormat;
|
const useToml = useTomlFormat;
|
||||||
|
|
||||||
const wizardInitialSpec = useMemo(() => {
|
const wizardInitialSpec = useMemo(() => {
|
||||||
@@ -153,6 +164,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
}, [formConfig, initialData, useToml]);
|
}, [formConfig, initialData, useToml]);
|
||||||
|
|
||||||
|
// 预设选择状态(仅新增模式显示;-1 表示自定义)
|
||||||
const [selectedPreset, setSelectedPreset] = useState<number | null>(
|
const [selectedPreset, setSelectedPreset] = useState<number | null>(
|
||||||
isEditing ? null : -1,
|
isEditing ? null : -1,
|
||||||
);
|
);
|
||||||
@@ -174,6 +186,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
return `${candidate}-${i}`;
|
return `${candidate}-${i}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 应用预设(写入表单但不落库)
|
||||||
const applyPreset = (index: number) => {
|
const applyPreset = (index: number) => {
|
||||||
if (index < 0 || index >= mcpPresets.length) return;
|
if (index < 0 || index >= mcpPresets.length) return;
|
||||||
const preset = mcpPresets[index];
|
const preset = mcpPresets[index];
|
||||||
@@ -187,6 +200,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
setFormDocs(presetWithDesc.docs || "");
|
setFormDocs(presetWithDesc.docs || "");
|
||||||
setFormTags(presetWithDesc.tags?.join(", ") || "");
|
setFormTags(presetWithDesc.tags?.join(", ") || "");
|
||||||
|
|
||||||
|
// 根据格式转换配置
|
||||||
if (useToml) {
|
if (useToml) {
|
||||||
const toml = mcpServerToToml(presetWithDesc.server);
|
const toml = mcpServerToToml(presetWithDesc.server);
|
||||||
setFormConfig(toml);
|
setFormConfig(toml);
|
||||||
@@ -199,8 +213,10 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
setSelectedPreset(index);
|
setSelectedPreset(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 切回自定义
|
||||||
const applyCustom = () => {
|
const applyCustom = () => {
|
||||||
setSelectedPreset(-1);
|
setSelectedPreset(-1);
|
||||||
|
// 恢复到空白模板
|
||||||
setFormId("");
|
setFormId("");
|
||||||
setFormName("");
|
setFormName("");
|
||||||
setFormDescription("");
|
setFormDescription("");
|
||||||
@@ -212,16 +228,19 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleConfigChange = (value: string) => {
|
const handleConfigChange = (value: string) => {
|
||||||
|
// 若为 TOML 模式,先做引号归一化,避免中文输入法导致的格式错误
|
||||||
const nextValue = useToml ? normalizeTomlText(value) : value;
|
const nextValue = useToml ? normalizeTomlText(value) : value;
|
||||||
setFormConfig(nextValue);
|
setFormConfig(nextValue);
|
||||||
|
|
||||||
if (useToml) {
|
if (useToml) {
|
||||||
|
// TOML validation (use hook's complete validation)
|
||||||
const err = validateTomlConfig(nextValue);
|
const err = validateTomlConfig(nextValue);
|
||||||
if (err) {
|
if (err) {
|
||||||
setConfigError(err);
|
setConfigError(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to extract ID (if user hasn't filled it yet)
|
||||||
if (nextValue.trim() && !formId.trim()) {
|
if (nextValue.trim() && !formId.trim()) {
|
||||||
const extractedId = extractIdFromToml(nextValue);
|
const extractedId = extractIdFromToml(nextValue);
|
||||||
if (extractedId) {
|
if (extractedId) {
|
||||||
@@ -229,8 +248,11 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// JSON validation with smart parsing
|
||||||
try {
|
try {
|
||||||
const result = parseSmartMcpJson(value);
|
const result = parseSmartMcpJson(value);
|
||||||
|
|
||||||
|
// 验证解析后的配置对象
|
||||||
const configJson = JSON.stringify(result.config);
|
const configJson = JSON.stringify(result.config);
|
||||||
const validationErr = validateJsonConfig(configJson);
|
const validationErr = validateJsonConfig(configJson);
|
||||||
|
|
||||||
@@ -239,15 +261,20 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自动填充提取的 id(仅当表单 id 为空且不在编辑模式时)
|
||||||
if (result.id && !formId.trim() && !isEditing) {
|
if (result.id && !formId.trim() && !isEditing) {
|
||||||
const uniqueId = ensureUniqueId(result.id);
|
const uniqueId = ensureUniqueId(result.id);
|
||||||
setFormId(uniqueId);
|
setFormId(uniqueId);
|
||||||
|
|
||||||
|
// 如果 name 也为空,同时填充 name
|
||||||
if (!formName.trim()) {
|
if (!formName.trim()) {
|
||||||
setFormName(result.id);
|
setFormName(result.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不在输入时自动格式化,保持用户输入的原样
|
||||||
|
// 格式清理将在提交时进行
|
||||||
|
|
||||||
setConfigError("");
|
setConfigError("");
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const errorMessage = err?.message || String(err);
|
const errorMessage = err?.message || String(err);
|
||||||
@@ -256,11 +283,30 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFormatJson = () => {
|
||||||
|
if (!formConfig.trim()) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formatted = formatJSON(formConfig);
|
||||||
|
setFormConfig(formatted);
|
||||||
|
toast.success(t("common.formatSuccess"));
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
|
error: errorMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleWizardApply = (title: string, json: string) => {
|
const handleWizardApply = (title: string, json: string) => {
|
||||||
setFormId(title);
|
setFormId(title);
|
||||||
if (!formName.trim()) {
|
if (!formName.trim()) {
|
||||||
setFormName(title);
|
setFormName(title);
|
||||||
}
|
}
|
||||||
|
// Wizard returns JSON, convert based on format if needed
|
||||||
if (useToml) {
|
if (useToml) {
|
||||||
try {
|
try {
|
||||||
const server = JSON.parse(json) as McpServerSpec;
|
const server = JSON.parse(json) as McpServerSpec;
|
||||||
@@ -283,14 +329,17 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增模式:阻止提交重名 ID
|
||||||
if (!isEditing && existingIds.includes(trimmedId)) {
|
if (!isEditing && existingIds.includes(trimmedId)) {
|
||||||
setIdError(t("mcp.error.idExists"));
|
setIdError(t("mcp.error.idExists"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate configuration format
|
||||||
let serverSpec: McpServerSpec;
|
let serverSpec: McpServerSpec;
|
||||||
|
|
||||||
if (useToml) {
|
if (useToml) {
|
||||||
|
// TOML mode
|
||||||
const tomlError = validateTomlConfig(formConfig);
|
const tomlError = validateTomlConfig(formConfig);
|
||||||
setConfigError(tomlError);
|
setConfigError(tomlError);
|
||||||
if (tomlError) {
|
if (tomlError) {
|
||||||
@@ -299,6 +348,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!formConfig.trim()) {
|
if (!formConfig.trim()) {
|
||||||
|
// Empty configuration
|
||||||
serverSpec = {
|
serverSpec = {
|
||||||
type: "stdio",
|
type: "stdio",
|
||||||
command: "",
|
command: "",
|
||||||
@@ -315,7 +365,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// JSON mode
|
||||||
if (!formConfig.trim()) {
|
if (!formConfig.trim()) {
|
||||||
|
// Empty configuration
|
||||||
serverSpec = {
|
serverSpec = {
|
||||||
type: "stdio",
|
type: "stdio",
|
||||||
command: "",
|
command: "",
|
||||||
@@ -323,6 +375,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
// 使用智能解析器,支持带外层键的格式
|
||||||
const result = parseSmartMcpJson(formConfig);
|
const result = parseSmartMcpJson(formConfig);
|
||||||
serverSpec = result.config as McpServerSpec;
|
serverSpec = result.config as McpServerSpec;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -334,6 +387,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 前置必填校验
|
||||||
if (serverSpec?.type === "stdio" && !serverSpec?.command?.trim()) {
|
if (serverSpec?.type === "stdio" && !serverSpec?.command?.trim()) {
|
||||||
toast.error(t("mcp.error.commandRequired"), { duration: 3000 });
|
toast.error(t("mcp.error.commandRequired"), { duration: 3000 });
|
||||||
return;
|
return;
|
||||||
@@ -348,6 +402,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
|
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
|
// 先处理 name 字段(必填)
|
||||||
const nameTrimmed = (formName || trimmedId).trim();
|
const nameTrimmed = (formName || trimmedId).trim();
|
||||||
const finalName = nameTrimmed || trimmedId;
|
const finalName = nameTrimmed || trimmedId;
|
||||||
|
|
||||||
@@ -356,6 +411,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
id: trimmedId,
|
id: trimmedId,
|
||||||
name: finalName,
|
name: finalName,
|
||||||
server: serverSpec,
|
server: serverSpec,
|
||||||
|
// 使用表单中的启用状态(v3.7.0 完整重构)
|
||||||
apps: enabledApps,
|
apps: enabledApps,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -390,9 +446,10 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
delete entry.tags;
|
delete entry.tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存到统一配置
|
||||||
await upsertMutation.mutateAsync(entry);
|
await upsertMutation.mutateAsync(entry);
|
||||||
toast.success(t("common.success"));
|
toast.success(t("common.success"));
|
||||||
await onSave();
|
await onSave(); // 通知父组件关闭表单
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const detail = extractErrorMessage(error);
|
const detail = extractErrorMessage(error);
|
||||||
const mapped = translateMcpBackendError(detail, t);
|
const mapped = translateMcpBackendError(detail, t);
|
||||||
@@ -409,33 +466,18 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FullScreenPanel
|
<Dialog open={true} onOpenChange={(open) => !open && onClose()}>
|
||||||
isOpen={true}
|
<DialogContent className="max-w-3xl max-h-[90vh] flex flex-col">
|
||||||
title={getFormTitle()}
|
<DialogHeader>
|
||||||
onClose={onClose}
|
<DialogTitle>{getFormTitle()}</DialogTitle>
|
||||||
footer={
|
</DialogHeader>
|
||||||
<Button
|
|
||||||
type="button"
|
{/* Content - Scrollable */}
|
||||||
onClick={handleSubmit}
|
<div className="flex-1 overflow-y-auto px-6 py-4 space-y-4">
|
||||||
disabled={saving || (!isEditing && !!idError)}
|
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{isEditing ? <Save size={16} /> : <Plus size={16} />}
|
|
||||||
{saving
|
|
||||||
? t("common.saving")
|
|
||||||
: isEditing
|
|
||||||
? t("common.save")
|
|
||||||
: t("common.add")}
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="flex flex-col h-full gap-6">
|
|
||||||
{/* 上半部分:表单字段 */}
|
|
||||||
<div className="glass rounded-xl p-6 border border-white/10 space-y-6 flex-shrink-0">
|
|
||||||
{/* 预设选择(仅新增时展示) */}
|
{/* 预设选择(仅新增时展示) */}
|
||||||
{!isEditing && (
|
{!isEditing && (
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-3">
|
<label className="block text-sm font-medium text-gray-900 dark:text-gray-100 mb-3">
|
||||||
{t("mcp.presets.title")}
|
{t("mcp.presets.title")}
|
||||||
</label>
|
</label>
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
@@ -445,7 +487,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
||||||
selectedPreset === -1
|
selectedPreset === -1
|
||||||
? "bg-emerald-500 text-white dark:bg-emerald-600"
|
? "bg-emerald-500 text-white dark:bg-emerald-600"
|
||||||
: "bg-accent text-muted-foreground hover:bg-accent/80"
|
: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{t("presetSelector.custom")}
|
{t("presetSelector.custom")}
|
||||||
@@ -460,7 +502,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
||||||
selectedPreset === idx
|
selectedPreset === idx
|
||||||
? "bg-emerald-500 text-white dark:bg-emerald-600"
|
? "bg-emerald-500 text-white dark:bg-emerald-600"
|
||||||
: "bg-accent text-muted-foreground hover:bg-accent/80"
|
: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"
|
||||||
}`}
|
}`}
|
||||||
title={t(descriptionKey)}
|
title={t(descriptionKey)}
|
||||||
>
|
>
|
||||||
@@ -471,11 +513,10 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* ID (标题) */}
|
{/* ID (标题) */}
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<label className="block text-sm font-medium text-foreground">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||||
{t("mcp.form.title")} <span className="text-red-500">*</span>
|
{t("mcp.form.title")} <span className="text-red-500">*</span>
|
||||||
</label>
|
</label>
|
||||||
{!isEditing && idError && (
|
{!isEditing && idError && (
|
||||||
@@ -495,7 +536,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
|
|
||||||
{/* Name */}
|
{/* Name */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-2">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{t("mcp.form.name")}
|
{t("mcp.form.name")}
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
@@ -506,9 +547,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 启用到哪些应用 */}
|
{/* 启用到哪些应用(v3.7.0 新增) */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-3">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">
|
||||||
{t("mcp.form.enabledApps")}
|
{t("mcp.form.enabledApps")}
|
||||||
</label>
|
</label>
|
||||||
<div className="flex flex-wrap gap-4">
|
<div className="flex flex-wrap gap-4">
|
||||||
@@ -522,7 +563,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor="enable-claude"
|
htmlFor="enable-claude"
|
||||||
className="text-sm text-foreground cursor-pointer select-none"
|
className="text-sm text-gray-700 dark:text-gray-300 cursor-pointer select-none"
|
||||||
>
|
>
|
||||||
{t("mcp.unifiedPanel.apps.claude")}
|
{t("mcp.unifiedPanel.apps.claude")}
|
||||||
</label>
|
</label>
|
||||||
@@ -538,7 +579,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor="enable-codex"
|
htmlFor="enable-codex"
|
||||||
className="text-sm text-foreground cursor-pointer select-none"
|
className="text-sm text-gray-700 dark:text-gray-300 cursor-pointer select-none"
|
||||||
>
|
>
|
||||||
{t("mcp.unifiedPanel.apps.codex")}
|
{t("mcp.unifiedPanel.apps.codex")}
|
||||||
</label>
|
</label>
|
||||||
@@ -554,7 +595,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
htmlFor="enable-gemini"
|
htmlFor="enable-gemini"
|
||||||
className="text-sm text-foreground cursor-pointer select-none"
|
className="text-sm text-gray-700 dark:text-gray-300 cursor-pointer select-none"
|
||||||
>
|
>
|
||||||
{t("mcp.unifiedPanel.apps.gemini")}
|
{t("mcp.unifiedPanel.apps.gemini")}
|
||||||
</label>
|
</label>
|
||||||
@@ -567,7 +608,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowMetadata(!showMetadata)}
|
onClick={() => setShowMetadata(!showMetadata)}
|
||||||
className="flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors"
|
className="flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100 transition-colors"
|
||||||
>
|
>
|
||||||
{showMetadata ? (
|
{showMetadata ? (
|
||||||
<ChevronUp size={16} />
|
<ChevronUp size={16} />
|
||||||
@@ -581,8 +622,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
{/* 附加信息区域(可折叠) */}
|
{/* 附加信息区域(可折叠) */}
|
||||||
{showMetadata && (
|
{showMetadata && (
|
||||||
<>
|
<>
|
||||||
|
{/* Description (描述) */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-2">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{t("mcp.form.description")}
|
{t("mcp.form.description")}
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
@@ -593,8 +635,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Tags */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-2">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{t("mcp.form.tags")}
|
{t("mcp.form.tags")}
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
@@ -605,8 +648,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Homepage */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-2">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{t("mcp.form.homepage")}
|
{t("mcp.form.homepage")}
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
@@ -617,8 +661,9 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Docs */}
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-foreground mb-2">
|
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
|
||||||
{t("mcp.form.docs")}
|
{t("mcp.form.docs")}
|
||||||
</label>
|
</label>
|
||||||
<Input
|
<Input
|
||||||
@@ -630,13 +675,14 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 下半部分:JSON 配置编辑器 - 自适应剩余高度 */}
|
{/* 配置输入框(根据格式显示 JSON 或 TOML) */}
|
||||||
<div className="glass rounded-xl p-6 border border-white/10 flex flex-col flex-1 min-h-0">
|
<div>
|
||||||
<div className="flex items-center justify-between mb-4 flex-shrink-0">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<label className="text-sm font-medium text-foreground">
|
<label className="text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||||
{useToml ? t("mcp.form.tomlConfig") : t("mcp.form.jsonConfig")}
|
{useToml
|
||||||
|
? t("mcp.form.tomlConfig")
|
||||||
|
: t("mcp.form.jsonConfig")}
|
||||||
</label>
|
</label>
|
||||||
{(isEditing || selectedPreset === -1) && (
|
{(isEditing || selectedPreset === -1) && (
|
||||||
<button
|
<button
|
||||||
@@ -648,33 +694,60 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 min-h-0 flex flex-col">
|
<Textarea
|
||||||
<div className="flex-1 min-h-0">
|
className="h-48 resize-none font-mono text-xs"
|
||||||
<JsonEditor
|
|
||||||
value={formConfig}
|
|
||||||
onChange={handleConfigChange}
|
|
||||||
placeholder={
|
placeholder={
|
||||||
useToml
|
useToml
|
||||||
? t("mcp.form.tomlPlaceholder")
|
? t("mcp.form.tomlPlaceholder")
|
||||||
: t("mcp.form.jsonPlaceholder")
|
: t("mcp.form.jsonPlaceholder")
|
||||||
}
|
}
|
||||||
darkMode={isDarkMode}
|
value={formConfig}
|
||||||
rows={12}
|
onChange={(e) => handleConfigChange(e.target.value)}
|
||||||
showValidation={!useToml}
|
|
||||||
language={useToml ? "javascript" : "json"}
|
|
||||||
height="100%"
|
|
||||||
/>
|
/>
|
||||||
|
{/* 格式化按钮(仅 JSON 模式) */}
|
||||||
|
{!useToml && (
|
||||||
|
<div className="flex items-center justify-between mt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormatJson}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format")}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{configError && (
|
{configError && (
|
||||||
<div className="flex items-center gap-2 mt-2 text-red-500 dark:text-red-400 text-sm flex-shrink-0">
|
<div className="flex items-center gap-2 mt-2 text-red-500 dark:text-red-400 text-sm">
|
||||||
<AlertCircle size={16} />
|
<AlertCircle size={16} />
|
||||||
<span>{configError}</span>
|
<span>{configError}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
{/* Footer */}
|
||||||
|
<DialogFooter className="flex justify-end gap-3 pt-4">
|
||||||
|
{/* 操作按钮 */}
|
||||||
|
<Button type="button" variant="ghost" onClick={onClose}>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSubmit}
|
||||||
|
disabled={saving || (!isEditing && !!idError)}
|
||||||
|
variant="mcp"
|
||||||
|
>
|
||||||
|
{isEditing ? <Save size={16} /> : <Plus size={16} />}
|
||||||
|
{saving
|
||||||
|
? t("common.saving")
|
||||||
|
: isEditing
|
||||||
|
? t("common.save")
|
||||||
|
: t("common.add")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{/* Wizard Modal */}
|
{/* Wizard Modal */}
|
||||||
<McpWizardModal
|
<McpWizardModal
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import React, { useMemo, useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Server } from "lucide-react";
|
import { Plus, Server, Check } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useAllMcpServers, useToggleMcpApp } from "@/hooks/useMcp";
|
import { useAllMcpServers, useToggleMcpApp } from "@/hooks/useMcp";
|
||||||
import type { McpServer } from "@/types";
|
import type { McpServer } from "@/types";
|
||||||
@@ -15,6 +22,7 @@ import { mcpPresets } from "@/config/mcpPresets";
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
interface UnifiedMcpPanelProps {
|
interface UnifiedMcpPanelProps {
|
||||||
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,14 +30,10 @@ interface UnifiedMcpPanelProps {
|
|||||||
* 统一 MCP 管理面板
|
* 统一 MCP 管理面板
|
||||||
* v3.7.0 新架构:所有 MCP 服务器统一管理,每个服务器通过复选框控制应用到哪些客户端
|
* v3.7.0 新架构:所有 MCP 服务器统一管理,每个服务器通过复选框控制应用到哪些客户端
|
||||||
*/
|
*/
|
||||||
export interface UnifiedMcpPanelHandle {
|
const UnifiedMcpPanel: React.FC<UnifiedMcpPanelProps> = ({
|
||||||
openAdd: () => void;
|
open,
|
||||||
}
|
onOpenChange,
|
||||||
|
}) => {
|
||||||
const UnifiedMcpPanel = React.forwardRef<
|
|
||||||
UnifiedMcpPanelHandle,
|
|
||||||
UnifiedMcpPanelProps
|
|
||||||
>(({ onOpenChange: _onOpenChange }, ref) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
const [editingId, setEditingId] = useState<string | null>(null);
|
const [editingId, setEditingId] = useState<string | null>(null);
|
||||||
@@ -86,10 +90,6 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
|
||||||
openAdd: handleAdd,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const handleDelete = (id: string) => {
|
const handleDelete = (id: string) => {
|
||||||
setConfirmDialog({
|
setConfirmDialog({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
@@ -115,10 +115,22 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-[56rem] px-6 flex flex-col h-[calc(100vh-8rem)] overflow-hidden">
|
<>
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="max-w-3xl max-h-[85vh] min-h-[600px] flex flex-col">
|
||||||
|
<DialogHeader>
|
||||||
|
<div className="flex items-center justify-between pr-8">
|
||||||
|
<DialogTitle>{t("mcp.unifiedPanel.title")}</DialogTitle>
|
||||||
|
<Button type="button" variant="mcp" onClick={handleAdd}>
|
||||||
|
<Plus size={16} />
|
||||||
|
{t("mcp.unifiedPanel.addServer")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
{/* Info Section */}
|
{/* Info Section */}
|
||||||
<div className="flex-shrink-0 py-4 glass rounded-xl border border-white/10 mb-4 px-6">
|
<div className="flex-shrink-0 px-6 py-4">
|
||||||
<div className="text-sm text-muted-foreground">
|
<div className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
{t("mcp.serverCount", { count: serverEntries.length })} ·{" "}
|
{t("mcp.serverCount", { count: serverEntries.length })} ·{" "}
|
||||||
{t("mcp.unifiedPanel.apps.claude")}: {enabledCounts.claude} ·{" "}
|
{t("mcp.unifiedPanel.apps.claude")}: {enabledCounts.claude} ·{" "}
|
||||||
{t("mcp.unifiedPanel.apps.codex")}: {enabledCounts.codex} ·{" "}
|
{t("mcp.unifiedPanel.apps.codex")}: {enabledCounts.codex} ·{" "}
|
||||||
@@ -127,7 +139,7 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Content - Scrollable */}
|
{/* Content - Scrollable */}
|
||||||
<div className="flex-1 overflow-y-auto overflow-x-hidden pb-24">
|
<div className="flex-1 overflow-y-auto px-6 pb-4">
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="text-center py-12 text-gray-500 dark:text-gray-400">
|
<div className="text-center py-12 text-gray-500 dark:text-gray-400">
|
||||||
{t("mcp.loading")}
|
{t("mcp.loading")}
|
||||||
@@ -135,7 +147,10 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
) : serverEntries.length === 0 ? (
|
) : serverEntries.length === 0 ? (
|
||||||
<div className="text-center py-12">
|
<div className="text-center py-12">
|
||||||
<div className="w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center">
|
<div className="w-16 h-16 mx-auto mb-4 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center">
|
||||||
<Server size={24} className="text-gray-400 dark:text-gray-500" />
|
<Server
|
||||||
|
size={24}
|
||||||
|
className="text-gray-400 dark:text-gray-500"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<h3 className="text-lg font-medium text-gray-900 dark:text-gray-100 mb-2">
|
<h3 className="text-lg font-medium text-gray-900 dark:text-gray-100 mb-2">
|
||||||
{t("mcp.unifiedPanel.noServers")}
|
{t("mcp.unifiedPanel.noServers")}
|
||||||
@@ -160,6 +175,19 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="mcp"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
>
|
||||||
|
<Check size={16} />
|
||||||
|
{t("common.done")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{/* Form Modal */}
|
{/* Form Modal */}
|
||||||
{isFormOpen && (
|
{isFormOpen && (
|
||||||
<McpFormModal
|
<McpFormModal
|
||||||
@@ -187,11 +215,9 @@ const UnifiedMcpPanel = React.forwardRef<
|
|||||||
onCancel={() => setConfirmDialog(null)}
|
onCancel={() => setConfirmDialog(null)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
UnifiedMcpPanel.displayName = "UnifiedMcpPanel";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一 MCP 列表项组件
|
* 统一 MCP 列表项组件
|
||||||
@@ -233,7 +259,8 @@ const UnifiedMcpListItem: React.FC<UnifiedMcpListItemProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group relative flex items-center gap-4 p-4 rounded-xl border border-border-default bg-muted/50 hover:bg-muted hover:border-border-default/80 hover:shadow-sm transition-all duration-300">
|
<div className="min-h-16 rounded-lg border border-border-default bg-card p-4 transition-[border-color,box-shadow] duration-200 hover:border-border-hover hover:shadow-sm">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
{/* 左侧:服务器信息 */}
|
{/* 左侧:服务器信息 */}
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
<div className="flex items-center gap-2 mb-1">
|
<div className="flex items-center gap-2 mb-1">
|
||||||
@@ -339,6 +366,7 @@ const UnifiedMcpListItem: React.FC<UnifiedMcpListItemProps> = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Label } from "@/components/ui/label";
|
|
||||||
import MarkdownEditor from "@/components/MarkdownEditor";
|
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
import type { Prompt, AppId } from "@/lib/api";
|
|
||||||
|
|
||||||
interface PromptFormPanelProps {
|
|
||||||
appId: AppId;
|
|
||||||
editingId?: string;
|
|
||||||
initialData?: Prompt;
|
|
||||||
onSave: (id: string, prompt: Prompt) => Promise<void>;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const PromptFormPanel: React.FC<PromptFormPanelProps> = ({
|
|
||||||
appId,
|
|
||||||
editingId,
|
|
||||||
initialData,
|
|
||||||
onSave,
|
|
||||||
onClose,
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const appName = t(`apps.${appId}`);
|
|
||||||
const filenameMap: Record<AppId, string> = {
|
|
||||||
claude: "CLAUDE.md",
|
|
||||||
codex: "AGENTS.md",
|
|
||||||
gemini: "GEMINI.md",
|
|
||||||
};
|
|
||||||
const filename = filenameMap[appId];
|
|
||||||
const [name, setName] = useState("");
|
|
||||||
const [description, setDescription] = useState("");
|
|
||||||
const [content, setContent] = useState("");
|
|
||||||
const [saving, setSaving] = useState(false);
|
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.documentElement, {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ["class"],
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => observer.disconnect();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (initialData) {
|
|
||||||
setName(initialData.name);
|
|
||||||
setDescription(initialData.description || "");
|
|
||||||
setContent(initialData.content);
|
|
||||||
}
|
|
||||||
}, [initialData]);
|
|
||||||
|
|
||||||
const handleSave = async () => {
|
|
||||||
if (!name.trim() || !content.trim()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSaving(true);
|
|
||||||
try {
|
|
||||||
const id = editingId || `prompt-${Date.now()}`;
|
|
||||||
const timestamp = Math.floor(Date.now() / 1000);
|
|
||||||
const prompt: Prompt = {
|
|
||||||
id,
|
|
||||||
name: name.trim(),
|
|
||||||
description: description.trim() || undefined,
|
|
||||||
content: content.trim(),
|
|
||||||
enabled: initialData?.enabled || false,
|
|
||||||
createdAt: initialData?.createdAt || timestamp,
|
|
||||||
updatedAt: timestamp,
|
|
||||||
};
|
|
||||||
await onSave(id, prompt);
|
|
||||||
onClose();
|
|
||||||
} catch (error) {
|
|
||||||
// Error handled by hook
|
|
||||||
} finally {
|
|
||||||
setSaving(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const title = editingId
|
|
||||||
? t("prompts.editTitle", { appName })
|
|
||||||
: t("prompts.addTitle", { appName });
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FullScreenPanel
|
|
||||||
isOpen={true}
|
|
||||||
title={title}
|
|
||||||
onClose={onClose}
|
|
||||||
footer={
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={!name.trim() || !content.trim() || saving}
|
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{saving ? t("common.saving") : t("common.save")}
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className="glass rounded-xl p-6 border border-white/10 space-y-6">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="name" className="text-foreground">
|
|
||||||
{t("prompts.name")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="name"
|
|
||||||
value={name}
|
|
||||||
onChange={(e) => setName(e.target.value)}
|
|
||||||
placeholder={t("prompts.namePlaceholder")}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="description" className="text-foreground">
|
|
||||||
{t("prompts.description")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="description"
|
|
||||||
value={description}
|
|
||||||
onChange={(e) => setDescription(e.target.value)}
|
|
||||||
placeholder={t("prompts.descriptionPlaceholder")}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="content" className="block mb-2 text-foreground">
|
|
||||||
{t("prompts.content")}
|
|
||||||
</Label>
|
|
||||||
<MarkdownEditor
|
|
||||||
value={content}
|
|
||||||
onChange={setContent}
|
|
||||||
placeholder={t("prompts.contentPlaceholder", { filename })}
|
|
||||||
darkMode={isDarkMode}
|
|
||||||
minHeight="167px"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PromptFormPanel;
|
|
||||||
@@ -25,7 +25,7 @@ const PromptListItem: React.FC<PromptListItemProps> = ({
|
|||||||
const enabled = prompt.enabled === true;
|
const enabled = prompt.enabled === true;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group relative h-16 rounded-xl border border-border-default bg-muted/50 p-4 transition-all duration-300 hover:bg-muted hover:border-border-default/80 hover:shadow-sm">
|
<div className="h-16 rounded-lg border border-border-default bg-card p-4 transition-[border-color,box-shadow] duration-200 hover:border-border-hover hover:shadow-sm">
|
||||||
<div className="flex items-center gap-4 h-full">
|
<div className="flex items-center gap-4 h-full">
|
||||||
{/* Toggle 开关 */}
|
{/* Toggle 开关 */}
|
||||||
<div className="flex-shrink-0">
|
<div className="flex-shrink-0">
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
import React, { useEffect, useMemo, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FileText } from "lucide-react";
|
import { Plus, FileText, Check } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { type AppId } from "@/lib/api";
|
import { type AppId } from "@/lib/api";
|
||||||
import { usePromptActions } from "@/hooks/usePromptActions";
|
import { usePromptActions } from "@/hooks/usePromptActions";
|
||||||
import PromptListItem from "./PromptListItem";
|
import PromptListItem from "./PromptListItem";
|
||||||
import PromptFormPanel from "./PromptFormPanel";
|
import PromptFormModal from "./PromptFormModal";
|
||||||
import { ConfirmDialog } from "../ConfirmDialog";
|
import { ConfirmDialog } from "../ConfirmDialog";
|
||||||
|
|
||||||
interface PromptPanelProps {
|
interface PromptPanelProps {
|
||||||
@@ -13,12 +21,11 @@ interface PromptPanelProps {
|
|||||||
appId: AppId;
|
appId: AppId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PromptPanelHandle {
|
const PromptPanel: React.FC<PromptPanelProps> = ({
|
||||||
openAdd: () => void;
|
open,
|
||||||
}
|
onOpenChange,
|
||||||
|
appId,
|
||||||
const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
}) => {
|
||||||
({ open, appId }, ref) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
const [editingId, setEditingId] = useState<string | null>(null);
|
const [editingId, setEditingId] = useState<string | null>(null);
|
||||||
@@ -30,44 +37,18 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
onConfirm: () => void;
|
onConfirm: () => void;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
const {
|
const { prompts, loading, reload, savePrompt, deletePrompt, toggleEnabled } =
|
||||||
prompts,
|
usePromptActions(appId);
|
||||||
loading,
|
|
||||||
reload,
|
|
||||||
savePrompt,
|
|
||||||
deletePrompt,
|
|
||||||
toggleEnabled,
|
|
||||||
} = usePromptActions(appId);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) reload();
|
if (open) reload();
|
||||||
}, [open, reload]);
|
}, [open, reload]);
|
||||||
|
|
||||||
// Listen for prompt import events from deep link
|
|
||||||
useEffect(() => {
|
|
||||||
const handlePromptImported = (event: Event) => {
|
|
||||||
const customEvent = event as CustomEvent;
|
|
||||||
// Reload if the import is for this app
|
|
||||||
if (customEvent.detail?.app === appId) {
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.addEventListener("prompt-imported", handlePromptImported);
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener("prompt-imported", handlePromptImported);
|
|
||||||
};
|
|
||||||
}, [appId, reload]);
|
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
setEditingId(null);
|
setEditingId(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
|
||||||
openAdd: handleAdd,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const handleEdit = (id: string) => {
|
const handleEdit = (id: string) => {
|
||||||
setEditingId(id);
|
setEditingId(id);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
@@ -95,10 +76,25 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
|
|
||||||
const enabledPrompt = promptEntries.find(([_, p]) => p.enabled);
|
const enabledPrompt = promptEntries.find(([_, p]) => p.enabled);
|
||||||
|
|
||||||
|
const appName = t(`apps.${appId}`);
|
||||||
|
const panelTitle = t("prompts.title", { appName });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx-auto max-w-[56rem] flex flex-col h-[calc(100vh-8rem)] px-6">
|
<>
|
||||||
<div className="flex-shrink-0 py-4 glass rounded-xl border border-white/10 mb-4 px-6">
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<div className="text-sm text-muted-foreground">
|
<DialogContent className="max-w-3xl max-h-[85vh] min-h-[600px] flex flex-col">
|
||||||
|
<DialogHeader>
|
||||||
|
<div className="flex items-center justify-between pr-8">
|
||||||
|
<DialogTitle>{panelTitle}</DialogTitle>
|
||||||
|
<Button type="button" variant="mcp" onClick={handleAdd}>
|
||||||
|
<Plus size={16} />
|
||||||
|
{t("prompts.add")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex-shrink-0 px-6 py-4">
|
||||||
|
<div className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
{t("prompts.count", { count: promptEntries.length })} ·{" "}
|
{t("prompts.count", { count: promptEntries.length })} ·{" "}
|
||||||
{enabledPrompt
|
{enabledPrompt
|
||||||
? t("prompts.enabledName", { name: enabledPrompt[1].name })
|
? t("prompts.enabledName", { name: enabledPrompt[1].name })
|
||||||
@@ -106,7 +102,7 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto pb-16">
|
<div className="flex-1 overflow-y-auto px-6 pb-4">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="text-center py-12 text-gray-500 dark:text-gray-400">
|
<div className="text-center py-12 text-gray-500 dark:text-gray-400">
|
||||||
{t("prompts.loading")}
|
{t("prompts.loading")}
|
||||||
@@ -142,8 +138,21 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="mcp"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
>
|
||||||
|
<Check size={16} />
|
||||||
|
{t("common.done")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{isFormOpen && (
|
{isFormOpen && (
|
||||||
<PromptFormPanel
|
<PromptFormModal
|
||||||
appId={appId}
|
appId={appId}
|
||||||
editingId={editingId || undefined}
|
editingId={editingId || undefined}
|
||||||
initialData={editingId ? prompts[editingId] : undefined}
|
initialData={editingId ? prompts[editingId] : undefined}
|
||||||
@@ -161,11 +170,8 @@ const PromptPanel = React.forwardRef<PromptPanelHandle, PromptPanelProps>(
|
|||||||
onCancel={() => setConfirmDialog(null)}
|
onCancel={() => setConfirmDialog(null)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
},
|
};
|
||||||
);
|
|
||||||
|
|
||||||
PromptPanel.displayName = "PromptPanel";
|
|
||||||
|
|
||||||
export default PromptPanel;
|
export default PromptPanel;
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Plus } from "lucide-react";
|
import { Plus } from "lucide-react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
import type { Provider, CustomEndpoint } from "@/types";
|
import type { Provider, CustomEndpoint } from "@/types";
|
||||||
import type { AppId } from "@/lib/api";
|
import type { AppId } from "@/lib/api";
|
||||||
import {
|
import {
|
||||||
@@ -41,8 +48,6 @@ export function AddProviderDialog({
|
|||||||
notes: values.notes?.trim() || undefined,
|
notes: values.notes?.trim() || undefined,
|
||||||
websiteUrl: values.websiteUrl?.trim() || undefined,
|
websiteUrl: values.websiteUrl?.trim() || undefined,
|
||||||
settingsConfig: parsedConfig,
|
settingsConfig: parsedConfig,
|
||||||
icon: values.icon?.trim() || undefined,
|
|
||||||
iconColor: values.iconColor?.trim() || undefined,
|
|
||||||
...(values.presetCategory ? { category: values.presetCategory } : {}),
|
...(values.presetCategory ? { category: values.presetCategory } : {}),
|
||||||
...(values.meta ? { meta: values.meta } : {}),
|
...(values.meta ? { meta: values.meta } : {}),
|
||||||
};
|
};
|
||||||
@@ -53,6 +58,8 @@ export function AddProviderDialog({
|
|||||||
|
|
||||||
if (!hasCustomEndpoints) {
|
if (!hasCustomEndpoints) {
|
||||||
// 收集端点候选(仅在缺少自定义端点时兜底)
|
// 收集端点候选(仅在缺少自定义端点时兜底)
|
||||||
|
// 1. 从预设配置中获取 endpointCandidates
|
||||||
|
// 2. 从当前配置中提取 baseUrl (ANTHROPIC_BASE_URL 或 Codex base_url)
|
||||||
const urlSet = new Set<string>();
|
const urlSet = new Set<string>();
|
||||||
|
|
||||||
const addUrl = (rawUrl?: string) => {
|
const addUrl = (rawUrl?: string) => {
|
||||||
@@ -163,33 +170,15 @@ export function AddProviderDialog({
|
|||||||
? t("provider.addCodexProvider")
|
? t("provider.addCodexProvider")
|
||||||
: t("provider.addGeminiProvider");
|
: t("provider.addGeminiProvider");
|
||||||
|
|
||||||
const footer = (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => onOpenChange(false)}
|
|
||||||
className="border-border/20 hover:bg-accent hover:text-accent-foreground"
|
|
||||||
>
|
|
||||||
{t("common.cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="submit"
|
|
||||||
form="provider-form"
|
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
|
||||||
>
|
|
||||||
<Plus className="h-4 w-4 mr-2" />
|
|
||||||
{t("common.add")}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
isOpen={open}
|
<DialogContent className="max-w-3xl max-h-[85vh] min-h-[600px] flex flex-col">
|
||||||
title={submitLabel}
|
<DialogHeader>
|
||||||
onClose={() => onOpenChange(false)}
|
<DialogTitle>{submitLabel}</DialogTitle>
|
||||||
footer={footer}
|
<DialogDescription>{t("provider.addProviderHint")}</DialogDescription>
|
||||||
>
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto px-6 py-4">
|
||||||
<ProviderForm
|
<ProviderForm
|
||||||
appId={appId}
|
appId={appId}
|
||||||
submitLabel={t("common.add")}
|
submitLabel={t("common.add")}
|
||||||
@@ -197,6 +186,18 @@ export function AddProviderDialog({
|
|||||||
onCancel={() => onOpenChange(false)}
|
onCancel={() => onOpenChange(false)}
|
||||||
showButtons={false}
|
showButtons={false}
|
||||||
/>
|
/>
|
||||||
</FullScreenPanel>
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" form="provider-form">
|
||||||
|
<Plus className="h-4 w-4" />
|
||||||
|
{t("common.add")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Save } from "lucide-react";
|
import { Save } from "lucide-react";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
import type { Provider } from "@/types";
|
import type { Provider } from "@/types";
|
||||||
import {
|
import {
|
||||||
ProviderForm,
|
ProviderForm,
|
||||||
@@ -27,7 +34,7 @@ export function EditProviderDialog({
|
|||||||
}: EditProviderDialogProps) {
|
}: EditProviderDialogProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
// 默认使用传入的 provider.settingsConfig,若当前编辑对象是"当前生效供应商",则尝试读取实时配置替换初始值
|
// 默认使用传入的 provider.settingsConfig,若当前编辑对象是“当前生效供应商”,则尝试读取实时配置替换初始值
|
||||||
const [liveSettings, setLiveSettings] = useState<Record<
|
const [liveSettings, setLiveSettings] = useState<Record<
|
||||||
string,
|
string,
|
||||||
unknown
|
unknown
|
||||||
@@ -78,8 +85,6 @@ export function EditProviderDialog({
|
|||||||
async (values: ProviderFormValues) => {
|
async (values: ProviderFormValues) => {
|
||||||
if (!provider) return;
|
if (!provider) return;
|
||||||
|
|
||||||
// 注意:values.settingsConfig 已经是最终的配置字符串
|
|
||||||
// ProviderForm 已经为不同的 app 类型(Claude/Codex/Gemini)正确组装了配置
|
|
||||||
const parsedConfig = JSON.parse(values.settingsConfig) as Record<
|
const parsedConfig = JSON.parse(values.settingsConfig) as Record<
|
||||||
string,
|
string,
|
||||||
unknown
|
unknown
|
||||||
@@ -91,8 +96,6 @@ export function EditProviderDialog({
|
|||||||
notes: values.notes?.trim() || undefined,
|
notes: values.notes?.trim() || undefined,
|
||||||
websiteUrl: values.websiteUrl?.trim() || undefined,
|
websiteUrl: values.websiteUrl?.trim() || undefined,
|
||||||
settingsConfig: parsedConfig,
|
settingsConfig: parsedConfig,
|
||||||
icon: values.icon?.trim() || undefined,
|
|
||||||
iconColor: values.iconColor?.trim() || undefined,
|
|
||||||
...(values.presetCategory ? { category: values.presetCategory } : {}),
|
...(values.presetCategory ? { category: values.presetCategory } : {}),
|
||||||
// 保留或更新 meta 字段
|
// 保留或更新 meta 字段
|
||||||
...(values.meta ? { meta: values.meta } : {}),
|
...(values.meta ? { meta: values.meta } : {}),
|
||||||
@@ -109,21 +112,16 @@ export function EditProviderDialog({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
isOpen={open}
|
<DialogContent className="max-w-3xl max-h-[85vh] min-h-[600px] flex flex-col">
|
||||||
title={t("provider.editProvider")}
|
<DialogHeader>
|
||||||
onClose={() => onOpenChange(false)}
|
<DialogTitle>{t("provider.editProvider")}</DialogTitle>
|
||||||
footer={
|
<DialogDescription>
|
||||||
<Button
|
{t("provider.editProviderHint")}
|
||||||
type="submit"
|
</DialogDescription>
|
||||||
form="provider-form"
|
</DialogHeader>
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
|
||||||
>
|
<div className="flex-1 overflow-y-auto px-6 py-4">
|
||||||
<Save className="h-4 w-4 mr-2" />
|
|
||||||
{t("common.save")}
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<ProviderForm
|
<ProviderForm
|
||||||
appId={appId}
|
appId={appId}
|
||||||
providerId={provider.id}
|
providerId={provider.id}
|
||||||
@@ -138,11 +136,21 @@ export function EditProviderDialog({
|
|||||||
settingsConfig: initialSettingsConfig,
|
settingsConfig: initialSettingsConfig,
|
||||||
category: provider.category,
|
category: provider.category,
|
||||||
meta: provider.meta,
|
meta: provider.meta,
|
||||||
icon: provider.icon,
|
|
||||||
iconColor: provider.iconColor,
|
|
||||||
}}
|
}}
|
||||||
showButtons={false}
|
showButtons={false}
|
||||||
/>
|
/>
|
||||||
</FullScreenPanel>
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" form="provider-form">
|
||||||
|
<Save className="h-4 w-4" />
|
||||||
|
{t("common.save")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BarChart3, Check, Copy, Edit, Play, Trash2 } from "lucide-react";
|
import { BarChart3, Check, Edit, Play, Trash2 } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -7,7 +7,6 @@ interface ProviderActionsProps {
|
|||||||
isCurrent: boolean;
|
isCurrent: boolean;
|
||||||
onSwitch: () => void;
|
onSwitch: () => void;
|
||||||
onEdit: () => void;
|
onEdit: () => void;
|
||||||
onDuplicate: () => void;
|
|
||||||
onConfigureUsage: () => void;
|
onConfigureUsage: () => void;
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
}
|
}
|
||||||
@@ -16,22 +15,20 @@ export function ProviderActions({
|
|||||||
isCurrent,
|
isCurrent,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDuplicate,
|
|
||||||
onConfigureUsage,
|
onConfigureUsage,
|
||||||
onDelete,
|
onDelete,
|
||||||
}: ProviderActionsProps) {
|
}: ProviderActionsProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const iconButtonClass = "h-8 w-8 p-1";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant={isCurrent ? "secondary" : "default"}
|
variant={isCurrent ? "secondary" : "default"}
|
||||||
onClick={onSwitch}
|
onClick={onSwitch}
|
||||||
disabled={isCurrent}
|
disabled={isCurrent}
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-[4.5rem] px-2.5",
|
"w-20",
|
||||||
isCurrent &&
|
isCurrent &&
|
||||||
"bg-gray-200 text-muted-foreground hover:bg-gray-200 hover:text-muted-foreground dark:bg-gray-700 dark:hover:bg-gray-700",
|
"bg-gray-200 text-muted-foreground hover:bg-gray-200 hover:text-muted-foreground dark:bg-gray-700 dark:hover:bg-gray-700",
|
||||||
)}
|
)}
|
||||||
@@ -55,27 +52,15 @@ export function ProviderActions({
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={onEdit}
|
onClick={onEdit}
|
||||||
title={t("common.edit")}
|
title={t("common.edit")}
|
||||||
className={iconButtonClass}
|
|
||||||
>
|
>
|
||||||
<Edit className="h-4 w-4" />
|
<Edit className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
|
||||||
size="icon"
|
|
||||||
variant="ghost"
|
|
||||||
onClick={onDuplicate}
|
|
||||||
title={t("provider.duplicate")}
|
|
||||||
className={iconButtonClass}
|
|
||||||
>
|
|
||||||
<Copy className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="icon"
|
size="icon"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={onConfigureUsage}
|
onClick={onConfigureUsage}
|
||||||
title={t("provider.configureUsage")}
|
title={t("provider.configureUsage")}
|
||||||
className={iconButtonClass}
|
|
||||||
>
|
>
|
||||||
<BarChart3 className="h-4 w-4" />
|
<BarChart3 className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -86,7 +71,6 @@ export function ProviderActions({
|
|||||||
onClick={isCurrent ? undefined : onDelete}
|
onClick={isCurrent ? undefined : onDelete}
|
||||||
title={t("common.delete")}
|
title={t("common.delete")}
|
||||||
className={cn(
|
className={cn(
|
||||||
iconButtonClass,
|
|
||||||
!isCurrent && "hover:text-red-500 dark:hover:text-red-400",
|
!isCurrent && "hover:text-red-500 dark:hover:text-red-400",
|
||||||
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground",
|
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground",
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { GripVertical } from "lucide-react";
|
import { MoveVertical, Copy } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import type {
|
import type {
|
||||||
DraggableAttributes,
|
DraggableAttributes,
|
||||||
@@ -8,8 +8,8 @@ import type {
|
|||||||
import type { Provider } from "@/types";
|
import type { Provider } from "@/types";
|
||||||
import type { AppId } from "@/lib/api";
|
import type { AppId } from "@/lib/api";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
import { ProviderActions } from "@/components/providers/ProviderActions";
|
import { ProviderActions } from "@/components/providers/ProviderActions";
|
||||||
import { ProviderIcon } from "@/components/ProviderIcon";
|
|
||||||
import UsageFooter from "@/components/UsageFooter";
|
import UsageFooter from "@/components/UsageFooter";
|
||||||
|
|
||||||
interface DragHandleProps {
|
interface DragHandleProps {
|
||||||
@@ -22,6 +22,7 @@ interface ProviderCardProps {
|
|||||||
provider: Provider;
|
provider: Provider;
|
||||||
isCurrent: boolean;
|
isCurrent: boolean;
|
||||||
appId: AppId;
|
appId: AppId;
|
||||||
|
isEditMode?: boolean;
|
||||||
onSwitch: (provider: Provider) => void;
|
onSwitch: (provider: Provider) => void;
|
||||||
onEdit: (provider: Provider) => void;
|
onEdit: (provider: Provider) => void;
|
||||||
onDelete: (provider: Provider) => void;
|
onDelete: (provider: Provider) => void;
|
||||||
@@ -70,6 +71,7 @@ export function ProviderCard({
|
|||||||
provider,
|
provider,
|
||||||
isCurrent,
|
isCurrent,
|
||||||
appId,
|
appId,
|
||||||
|
isEditMode = false,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
@@ -114,40 +116,53 @@ export function ProviderCard({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"glass-card relative overflow-hidden rounded-xl p-4 transition-all duration-300",
|
"rounded-lg bg-card p-4 shadow-sm",
|
||||||
"group hover:bg-black/[0.02] dark:hover:bg-white/[0.02] hover:border-primary/50",
|
"transition-[border-color,background-color,box-shadow,ring] duration-200",
|
||||||
isCurrent
|
isCurrent
|
||||||
? "border-primary/50 bg-primary/5 shadow-[0_0_20px_rgba(59,130,246,0.15)]"
|
? "border border-border-default bg-primary/5 ring-2 ring-blue-500/30 dark:ring-blue-400/30"
|
||||||
: "hover:scale-[1.01]",
|
: "border border-border-default hover:border-border-hover",
|
||||||
dragHandleProps?.isDragging &&
|
dragHandleProps?.isDragging &&
|
||||||
"cursor-grabbing border-primary shadow-lg scale-105 z-10",
|
"cursor-grabbing border-active border-border-dragging shadow-lg",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="absolute inset-0 bg-gradient-to-r from-primary/10 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500 pointer-events-none" />
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div className="relative flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
|
||||||
<div className="flex flex-1 items-center gap-2">
|
<div className="flex flex-1 items-center gap-2">
|
||||||
<button
|
<div
|
||||||
type="button"
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"-ml-1.5 flex-shrink-0 cursor-grab active:cursor-grabbing p-1.5",
|
"flex items-center gap-1 overflow-hidden",
|
||||||
"text-muted-foreground/50 hover:text-muted-foreground transition-colors",
|
"transition-[max-width,opacity] duration-200 ease-in-out",
|
||||||
|
isEditMode ? "max-w-20 opacity-100" : "max-w-0 opacity-0",
|
||||||
|
)}
|
||||||
|
aria-hidden={!isEditMode}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="icon"
|
||||||
|
variant="ghost"
|
||||||
|
className={cn(
|
||||||
|
"flex-shrink-0 cursor-grab active:cursor-grabbing",
|
||||||
dragHandleProps?.isDragging && "cursor-grabbing",
|
dragHandleProps?.isDragging && "cursor-grabbing",
|
||||||
)}
|
)}
|
||||||
aria-label={t("provider.dragHandle")}
|
aria-label={t("provider.dragHandle")}
|
||||||
|
disabled={!isEditMode}
|
||||||
{...(dragHandleProps?.attributes ?? {})}
|
{...(dragHandleProps?.attributes ?? {})}
|
||||||
{...(dragHandleProps?.listeners ?? {})}
|
{...(dragHandleProps?.listeners ?? {})}
|
||||||
>
|
>
|
||||||
<GripVertical className="h-4 w-4" />
|
<MoveVertical className="h-4 w-4" />
|
||||||
</button>
|
</Button>
|
||||||
|
|
||||||
{/* 供应商图标 */}
|
<Button
|
||||||
<div className="h-8 w-8 rounded-lg bg-white/5 flex items-center justify-center border border-gray-200 dark:border-white/10 group-hover:scale-105 transition-transform duration-300">
|
type="button"
|
||||||
<ProviderIcon
|
size="icon"
|
||||||
icon={provider.icon}
|
variant="ghost"
|
||||||
name={provider.name}
|
className="flex-shrink-0"
|
||||||
color={provider.iconColor}
|
onClick={() => onDuplicate(provider)}
|
||||||
size={20}
|
disabled={!isEditMode}
|
||||||
/>
|
aria-label={t("provider.duplicate")}
|
||||||
|
title={t("provider.duplicate")}
|
||||||
|
>
|
||||||
|
<Copy className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
@@ -195,8 +210,7 @@ export function ProviderCard({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative flex items-center ml-auto">
|
<div className="flex items-center gap-3">
|
||||||
<div className="ml-auto transition-transform duration-200 group-hover:-translate-x-[12.25rem] group-focus-within:-translate-x-[12.25rem] sm:group-hover:-translate-x-[14.25rem] sm:group-focus-within:-translate-x-[14.25rem]">
|
|
||||||
<UsageFooter
|
<UsageFooter
|
||||||
provider={provider}
|
provider={provider}
|
||||||
providerId={provider.id}
|
providerId={provider.id}
|
||||||
@@ -205,20 +219,16 @@ export function ProviderCard({
|
|||||||
isCurrent={isCurrent}
|
isCurrent={isCurrent}
|
||||||
inline={true}
|
inline={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="absolute right-0 top-1/2 -translate-y-1/2 flex items-center gap-1.5 opacity-0 pointer-events-none group-hover:opacity-100 group-focus-within:opacity-100 group-hover:pointer-events-auto group-focus-within:pointer-events-auto transition-all duration-200 translate-x-2 group-hover:translate-x-0 group-focus-within:translate-x-0">
|
|
||||||
<ProviderActions
|
<ProviderActions
|
||||||
isCurrent={isCurrent}
|
isCurrent={isCurrent}
|
||||||
onSwitch={() => onSwitch(provider)}
|
onSwitch={() => onSwitch(provider)}
|
||||||
onEdit={() => onEdit(provider)}
|
onEdit={() => onEdit(provider)}
|
||||||
onDuplicate={() => onDuplicate(provider)}
|
|
||||||
onConfigureUsage={() => onConfigureUsage(provider)}
|
onConfigureUsage={() => onConfigureUsage(provider)}
|
||||||
onDelete={() => onDelete(provider)}
|
onDelete={() => onDelete(provider)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ interface ProviderListProps {
|
|||||||
providers: Record<string, Provider>;
|
providers: Record<string, Provider>;
|
||||||
currentProviderId: string;
|
currentProviderId: string;
|
||||||
appId: AppId;
|
appId: AppId;
|
||||||
|
isEditMode?: boolean;
|
||||||
onSwitch: (provider: Provider) => void;
|
onSwitch: (provider: Provider) => void;
|
||||||
onEdit: (provider: Provider) => void;
|
onEdit: (provider: Provider) => void;
|
||||||
onDelete: (provider: Provider) => void;
|
onDelete: (provider: Provider) => void;
|
||||||
@@ -30,6 +31,7 @@ export function ProviderList({
|
|||||||
providers,
|
providers,
|
||||||
currentProviderId,
|
currentProviderId,
|
||||||
appId,
|
appId,
|
||||||
|
isEditMode = false,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
@@ -71,16 +73,14 @@ export function ProviderList({
|
|||||||
items={sortedProviders.map((provider) => provider.id)}
|
items={sortedProviders.map((provider) => provider.id)}
|
||||||
strategy={verticalListSortingStrategy}
|
strategy={verticalListSortingStrategy}
|
||||||
>
|
>
|
||||||
<div
|
<div className="space-y-3">
|
||||||
className="space-y-3 animate-slide-up"
|
|
||||||
style={{ animationDelay: "0.1s" }}
|
|
||||||
>
|
|
||||||
{sortedProviders.map((provider) => (
|
{sortedProviders.map((provider) => (
|
||||||
<SortableProviderCard
|
<SortableProviderCard
|
||||||
key={provider.id}
|
key={provider.id}
|
||||||
provider={provider}
|
provider={provider}
|
||||||
isCurrent={provider.id === currentProviderId}
|
isCurrent={provider.id === currentProviderId}
|
||||||
appId={appId}
|
appId={appId}
|
||||||
|
isEditMode={isEditMode}
|
||||||
onSwitch={onSwitch}
|
onSwitch={onSwitch}
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
@@ -99,6 +99,7 @@ interface SortableProviderCardProps {
|
|||||||
provider: Provider;
|
provider: Provider;
|
||||||
isCurrent: boolean;
|
isCurrent: boolean;
|
||||||
appId: AppId;
|
appId: AppId;
|
||||||
|
isEditMode: boolean;
|
||||||
onSwitch: (provider: Provider) => void;
|
onSwitch: (provider: Provider) => void;
|
||||||
onEdit: (provider: Provider) => void;
|
onEdit: (provider: Provider) => void;
|
||||||
onDelete: (provider: Provider) => void;
|
onDelete: (provider: Provider) => void;
|
||||||
@@ -111,6 +112,7 @@ function SortableProviderCard({
|
|||||||
provider,
|
provider,
|
||||||
isCurrent,
|
isCurrent,
|
||||||
appId,
|
appId,
|
||||||
|
isEditMode,
|
||||||
onSwitch,
|
onSwitch,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
@@ -138,6 +140,7 @@ function SortableProviderCard({
|
|||||||
provider={provider}
|
provider={provider}
|
||||||
isCurrent={isCurrent}
|
isCurrent={isCurrent}
|
||||||
appId={appId}
|
appId={appId}
|
||||||
|
isEditMode={isEditMode}
|
||||||
onSwitch={onSwitch}
|
onSwitch={onSwitch}
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useState } from "react";
|
|
||||||
import {
|
import {
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
@@ -8,17 +7,6 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { ArrowLeft } from "lucide-react";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogTrigger,
|
|
||||||
DialogClose,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { ProviderIcon } from "@/components/ProviderIcon";
|
|
||||||
import { IconPicker } from "@/components/IconPicker";
|
|
||||||
import { getIconMetadata } from "@/icons/extracted/metadata";
|
|
||||||
import type { UseFormReturn } from "react-hook-form";
|
import type { UseFormReturn } from "react-hook-form";
|
||||||
import type { ProviderFormData } from "@/lib/schemas/provider";
|
import type { ProviderFormData } from "@/lib/schemas/provider";
|
||||||
|
|
||||||
@@ -28,84 +16,9 @@ interface BasicFormFieldsProps {
|
|||||||
|
|
||||||
export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [iconDialogOpen, setIconDialogOpen] = useState(false);
|
|
||||||
|
|
||||||
const currentIcon = form.watch("icon");
|
|
||||||
const currentIconColor = form.watch("iconColor");
|
|
||||||
const providerName = form.watch("name") || "Provider";
|
|
||||||
const effectiveIconColor =
|
|
||||||
currentIconColor ||
|
|
||||||
(currentIcon ? getIconMetadata(currentIcon)?.defaultColor : undefined);
|
|
||||||
|
|
||||||
const handleIconSelect = (icon: string) => {
|
|
||||||
const meta = getIconMetadata(icon);
|
|
||||||
form.setValue("icon", icon);
|
|
||||||
form.setValue("iconColor", meta?.defaultColor ?? "");
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* 图标选择区域 - 顶部居中,可选 */}
|
|
||||||
<div className="flex justify-center mb-6">
|
|
||||||
<Dialog open={iconDialogOpen} onOpenChange={setIconDialogOpen}>
|
|
||||||
<DialogTrigger asChild>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="w-20 h-20 p-3 rounded-xl border-2 border-gray-300 dark:border-gray-600 hover:border-primary dark:hover:border-primary transition-colors cursor-pointer bg-gray-50 dark:bg-gray-800/50 flex items-center justify-center"
|
|
||||||
title={currentIcon ? "点击更换图标" : "点击选择图标"}
|
|
||||||
>
|
|
||||||
<ProviderIcon
|
|
||||||
icon={currentIcon}
|
|
||||||
name={providerName}
|
|
||||||
color={effectiveIconColor}
|
|
||||||
size={48}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent
|
|
||||||
variant="fullscreen"
|
|
||||||
zIndex="top"
|
|
||||||
overlayClassName="bg-[hsl(var(--background))] backdrop-blur-0"
|
|
||||||
className="p-0 sm:rounded-none"
|
|
||||||
>
|
|
||||||
<div className="flex h-full flex-col">
|
|
||||||
<div className="flex-shrink-0 py-4 border-b border-border-default bg-muted/40">
|
|
||||||
<div className="mx-auto max-w-[56rem] px-6 flex items-center gap-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button type="button" variant="outline" size="icon">
|
|
||||||
<ArrowLeft className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
<p className="text-lg font-semibold leading-tight">
|
|
||||||
{t("providerIcon.selectIcon", {
|
|
||||||
defaultValue: "选择图标",
|
|
||||||
})}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex-1 overflow-y-auto">
|
|
||||||
<div className="space-y-2 mx-auto max-w-[56rem] px-6 py-6 w-full">
|
|
||||||
<IconPicker
|
|
||||||
value={currentIcon}
|
|
||||||
onValueChange={handleIconSelect}
|
|
||||||
color={effectiveIconColor}
|
|
||||||
/>
|
|
||||||
<div className="flex justify-end gap-2">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button type="button" variant="outline">
|
|
||||||
{t("common.done", { defaultValue: "完成" })}
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 基础信息 - 网格布局 */}
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -120,24 +33,6 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="notes"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>{t("provider.notes")}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
placeholder={t("provider.notesPlaceholder")}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="websiteUrl"
|
name="websiteUrl"
|
||||||
@@ -151,6 +46,20 @@ export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="notes"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t("provider.notes")}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} placeholder={t("provider.notesPlaceholder")} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
import { Save } from "lucide-react";
|
import { Save } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
|
||||||
|
|
||||||
interface CodexCommonConfigModalProps {
|
interface CodexCommonConfigModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -25,30 +30,47 @@ export const CodexCommonConfigModal: React.FC<CodexCommonConfigModalProps> = ({
|
|||||||
error,
|
error,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.documentElement, {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ["class"],
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => observer.disconnect();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||||
isOpen={isOpen}
|
<DialogContent
|
||||||
title={t("codexConfig.editCommonConfigTitle")}
|
zIndex="nested"
|
||||||
onClose={onClose}
|
className="max-w-2xl max-h-[90vh] flex flex-col p-0"
|
||||||
footer={
|
>
|
||||||
<>
|
<DialogHeader className="px-6 pt-6 pb-0">
|
||||||
|
<DialogTitle>{t("codexConfig.editCommonConfigTitle")}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-auto px-6 py-4 space-y-4">
|
||||||
|
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
|
{t("codexConfig.commonConfigHint")}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
placeholder={`# Common Codex config
|
||||||
|
|
||||||
|
# Add your common TOML configuration here`}
|
||||||
|
rows={12}
|
||||||
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 focus:border-border-active transition-colors resize-y"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
<Button type="button" variant="outline" onClick={onClose}>
|
<Button type="button" variant="outline" onClick={onClose}>
|
||||||
{t("common.cancel")}
|
{t("common.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -56,30 +78,8 @@ export const CodexCommonConfigModal: React.FC<CodexCommonConfigModalProps> = ({
|
|||||||
<Save className="w-4 h-4" />
|
<Save className="w-4 h-4" />
|
||||||
{t("common.save")}
|
{t("common.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</DialogFooter>
|
||||||
}
|
</DialogContent>
|
||||||
>
|
</Dialog>
|
||||||
<div className="space-y-4">
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("codexConfig.commonConfigHint")}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<JsonEditor
|
|
||||||
value={value}
|
|
||||||
onChange={onChange}
|
|
||||||
placeholder={`# Common Codex config
|
|
||||||
|
|
||||||
# Add your common TOML configuration here`}
|
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={16}
|
|
||||||
showValidation={false}
|
|
||||||
language="javascript"
|
|
||||||
/>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
import { Wand2 } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { formatJSON } from "@/utils/formatters";
|
||||||
|
|
||||||
interface CodexAuthSectionProps {
|
interface CodexAuthSectionProps {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -19,27 +21,23 @@ export const CodexAuthSection: React.FC<CodexAuthSectionProps> = ({
|
|||||||
error,
|
error,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleFormat = () => {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
if (!value.trim()) return;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
try {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
const formatted = formatJSON(value);
|
||||||
});
|
onChange(formatted);
|
||||||
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
observer.observe(document.documentElement, {
|
} catch (error) {
|
||||||
attributes: true,
|
const errorMessage =
|
||||||
attributeFilter: ["class"],
|
error instanceof Error ? error.message : String(error);
|
||||||
});
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
return () => observer.disconnect();
|
defaultValue: "格式化失败:{{error}}",
|
||||||
}, []);
|
error: errorMessage,
|
||||||
|
}),
|
||||||
const handleChange = (newValue: string) => {
|
);
|
||||||
onChange(newValue);
|
|
||||||
if (onBlur) {
|
|
||||||
onBlur();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,19 +50,39 @@ export const CodexAuthSection: React.FC<CodexAuthSectionProps> = ({
|
|||||||
{t("codexConfig.authJson")}
|
{t("codexConfig.authJson")}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<JsonEditor
|
<textarea
|
||||||
|
id="codexAuth"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={handleChange}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
onBlur={onBlur}
|
||||||
placeholder={t("codexConfig.authJsonPlaceholder")}
|
placeholder={t("codexConfig.authJsonPlaceholder")}
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={6}
|
rows={6}
|
||||||
showValidation={true}
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[8rem]"
|
||||||
language="json"
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormat}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{!error && (
|
{!error && (
|
||||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
@@ -98,22 +116,6 @@ export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
|||||||
configError,
|
configError,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(document.documentElement, {
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ["class"],
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => observer.disconnect();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -152,14 +154,22 @@ export const CodexConfigSection: React.FC<CodexConfigSectionProps> = ({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<JsonEditor
|
<textarea
|
||||||
|
id="codexConfig"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
placeholder=""
|
placeholder=""
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={8}
|
rows={8}
|
||||||
showValidation={false}
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[10rem]"
|
||||||
language="javascript"
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{configError && (
|
{configError && (
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEffect, useState } from "react";
|
import {
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Save } from "lucide-react";
|
import { Save, Wand2 } from "lucide-react";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
import { toast } from "sonner";
|
||||||
|
import { formatJSON } from "@/utils/formatters";
|
||||||
|
|
||||||
interface CommonConfigEditorProps {
|
interface CommonConfigEditorProps {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -32,22 +38,44 @@ export function CommonConfigEditor({
|
|||||||
onModalClose,
|
onModalClose,
|
||||||
}: CommonConfigEditorProps) {
|
}: CommonConfigEditorProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleFormatMain = () => {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
if (!value.trim()) return;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
try {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
const formatted = formatJSON(value);
|
||||||
});
|
onChange(formatted);
|
||||||
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
|
defaultValue: "格式化失败:{{error}}",
|
||||||
|
error: errorMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
observer.observe(document.documentElement, {
|
const handleFormatModal = () => {
|
||||||
attributes: true,
|
if (!commonConfigSnippet.trim()) return;
|
||||||
attributeFilter: ["class"],
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => observer.disconnect();
|
try {
|
||||||
}, []);
|
const formatted = formatJSON(commonConfigSnippet);
|
||||||
|
onCommonConfigSnippetChange(formatted);
|
||||||
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
|
defaultValue: "格式化失败:{{error}}",
|
||||||
|
error: errorMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -87,30 +115,90 @@ export function CommonConfigEditor({
|
|||||||
{commonConfigError}
|
{commonConfigError}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<JsonEditor
|
<textarea
|
||||||
|
id="settingsConfig"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
placeholder={`{
|
placeholder={`{
|
||||||
"env": {
|
"env": {
|
||||||
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com",
|
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com",
|
||||||
"ANTHROPIC_AUTH_TOKEN": "your-api-key-here"
|
"ANTHROPIC_AUTH_TOKEN": "your-api-key-here"
|
||||||
}
|
}
|
||||||
}`}
|
}`}
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={14}
|
rows={14}
|
||||||
showValidation={true}
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[16rem]"
|
||||||
language="json"
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
/>
|
/>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormatMain}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FullScreenPanel
|
<Dialog
|
||||||
isOpen={isModalOpen}
|
open={isModalOpen}
|
||||||
title={t("claudeConfig.editCommonConfigTitle", {
|
onOpenChange={(open) => !open && onModalClose()}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-[600px] max-h-[90vh] flex flex-col p-0">
|
||||||
|
<DialogHeader className="px-6 pt-6 pb-0">
|
||||||
|
<DialogTitle>
|
||||||
|
{t("claudeConfig.editCommonConfigTitle", {
|
||||||
defaultValue: "编辑通用配置片段",
|
defaultValue: "编辑通用配置片段",
|
||||||
})}
|
})}
|
||||||
onClose={onModalClose}
|
</DialogTitle>
|
||||||
footer={
|
</DialogHeader>
|
||||||
<>
|
<div className="flex-1 overflow-auto px-6 py-4 space-y-4">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{t("claudeConfig.commonConfigHint", {
|
||||||
|
defaultValue: "通用配置片段将合并到所有启用它的供应商配置中",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
<textarea
|
||||||
|
value={commonConfigSnippet}
|
||||||
|
onChange={(e) => onCommonConfigSnippetChange(e.target.value)}
|
||||||
|
rows={12}
|
||||||
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[14rem]"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
|
/>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormatModal}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
{commonConfigError && (
|
||||||
|
<p className="text-sm text-red-500 dark:text-red-400">
|
||||||
|
{commonConfigError}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
<Button type="button" variant="outline" onClick={onModalClose}>
|
<Button type="button" variant="outline" onClick={onModalClose}>
|
||||||
{t("common.cancel")}
|
{t("common.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -118,35 +206,9 @@ export function CommonConfigEditor({
|
|||||||
<Save className="w-4 h-4" />
|
<Save className="w-4 h-4" />
|
||||||
{t("common.save")}
|
{t("common.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</DialogFooter>
|
||||||
}
|
</DialogContent>
|
||||||
>
|
</Dialog>
|
||||||
<div className="space-y-4">
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("claudeConfig.commonConfigHint", {
|
|
||||||
defaultValue: "通用配置片段将合并到所有启用它的供应商配置中",
|
|
||||||
})}
|
|
||||||
</p>
|
|
||||||
<JsonEditor
|
|
||||||
value={commonConfigSnippet}
|
|
||||||
onChange={onCommonConfigSnippetChange}
|
|
||||||
placeholder={`{
|
|
||||||
"env": {
|
|
||||||
"ANTHROPIC_BASE_URL": "https://your-api-endpoint.com"
|
|
||||||
}
|
|
||||||
}`}
|
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={16}
|
|
||||||
showValidation={true}
|
|
||||||
language="json"
|
|
||||||
/>
|
|
||||||
{commonConfigError && (
|
|
||||||
<p className="text-sm text-red-500 dark:text-red-400">
|
|
||||||
{commonConfigError}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ import type { AppId } from "@/lib/api";
|
|||||||
import { vscodeApi } from "@/lib/api/vscode";
|
import { vscodeApi } from "@/lib/api/vscode";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import type { CustomEndpoint, EndpointCandidate } from "@/types";
|
import type { CustomEndpoint, EndpointCandidate } from "@/types";
|
||||||
|
|
||||||
// 端点测速超时配置(秒)
|
// 端点测速超时配置(秒)
|
||||||
@@ -425,53 +431,21 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
onClose();
|
onClose();
|
||||||
}, [isEditMode, providerId, entries, initialCustomUrls, appId, onClose, t]);
|
}, [isEditMode, providerId, entries, initialCustomUrls, appId, onClose, t]);
|
||||||
|
|
||||||
if (!visible) return null;
|
|
||||||
|
|
||||||
const footer = (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
onClick={(event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
disabled={isSaving}
|
|
||||||
>
|
|
||||||
{t("common.cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={isSaving}
|
|
||||||
className="gap-2"
|
|
||||||
>
|
|
||||||
{isSaving ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="w-4 h-4 animate-spin" />
|
|
||||||
{t("common.saving")}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Save className="w-4 h-4" />
|
|
||||||
{t("common.save")}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={visible} onOpenChange={(open) => !open && onClose()}>
|
||||||
isOpen={visible}
|
<DialogContent
|
||||||
title={t("endpointTest.title")}
|
zIndex="nested"
|
||||||
onClose={onClose}
|
className="max-w-2xl max-h-[80vh] flex flex-col p-0"
|
||||||
footer={footer}
|
|
||||||
>
|
>
|
||||||
<div className="glass rounded-xl p-6 border border-white/10 flex flex-col gap-6">
|
<DialogHeader className="px-6 pt-6 pb-0">
|
||||||
|
<DialogTitle>{t("endpointTest.title")}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
{/* Content */}
|
||||||
|
<div className="flex-1 overflow-auto px-6 py-4 space-y-4">
|
||||||
{/* 测速控制栏 */}
|
{/* 测速控制栏 */}
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="text-sm text-muted-foreground">
|
<div className="text-sm text-gray-600 dark:text-gray-400">
|
||||||
{entries.length} {t("endpointTest.endpoints")}
|
{entries.length} {t("endpointTest.endpoints")}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
@@ -480,7 +454,7 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={autoSelect}
|
checked={autoSelect}
|
||||||
onChange={(event) => setAutoSelect(event.target.checked)}
|
onChange={(event) => setAutoSelect(event.target.checked)}
|
||||||
className="h-3.5 w-3.5 rounded border-border-default bg-background text-primary focus:ring-2 focus:ring-primary/20"
|
className="h-3.5 w-3.5 rounded border-border-default "
|
||||||
/>
|
/>
|
||||||
{t("endpointTest.autoSelect")}
|
{t("endpointTest.autoSelect")}
|
||||||
</label>
|
</label>
|
||||||
@@ -489,7 +463,7 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
onClick={runSpeedTest}
|
onClick={runSpeedTest}
|
||||||
disabled={isTesting || !hasEndpoints}
|
disabled={isTesting || !hasEndpoints}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="h-7 w-24 gap-1.5 text-xs bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-60"
|
className="h-7 w-20 gap-1.5 text-xs"
|
||||||
>
|
>
|
||||||
{isTesting ? (
|
{isTesting ? (
|
||||||
<>
|
<>
|
||||||
@@ -552,8 +526,8 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
onClick={() => handleSelect(entry.url)}
|
onClick={() => handleSelect(entry.url)}
|
||||||
className={`group flex cursor-pointer items-center justify-between px-3 py-2.5 rounded-lg border transition ${
|
className={`group flex cursor-pointer items-center justify-between px-3 py-2.5 rounded-lg border transition ${
|
||||||
isSelected
|
isSelected
|
||||||
? "border-primary/70 bg-primary/5 shadow-sm"
|
? "border-blue-500 bg-blue-50 dark:border-blue-500 dark:bg-blue-900/20"
|
||||||
: "border-border-default bg-background hover:bg-muted"
|
: "border-border-default bg-white hover:border-border-default hover:bg-gray-50 dark:bg-gray-900 dark:hover:border-gray-600 dark:hover:bg-gray-800"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex min-w-0 flex-1 items-center gap-3">
|
<div className="flex min-w-0 flex-1 items-center gap-3">
|
||||||
@@ -581,7 +555,7 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
<div
|
<div
|
||||||
className={`font-mono text-sm font-medium ${
|
className={`font-mono text-sm font-medium ${
|
||||||
latency < 300
|
latency < 300
|
||||||
? "text-emerald-600 dark:text-emerald-400"
|
? "text-green-600 dark:text-green-400"
|
||||||
: latency < 500
|
: latency < 500
|
||||||
? "text-yellow-600 dark:text-yellow-400"
|
? "text-yellow-600 dark:text-yellow-400"
|
||||||
: latency < 800
|
: latency < 800
|
||||||
@@ -591,11 +565,6 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
>
|
>
|
||||||
{latency}ms
|
{latency}ms
|
||||||
</div>
|
</div>
|
||||||
<div className="text-[10px] text-gray-500 dark:text-gray-400">
|
|
||||||
{entry.status
|
|
||||||
? t("endpointTest.status", { code: entry.status })
|
|
||||||
: t("endpointTest.notTested")}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
) : isTesting ? (
|
) : isTesting ? (
|
||||||
<Loader2 className="h-4 w-4 animate-spin text-gray-400" />
|
<Loader2 className="h-4 w-4 animate-spin text-gray-400" />
|
||||||
@@ -609,8 +578,8 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={(event) => {
|
onClick={(e) => {
|
||||||
event.stopPropagation();
|
e.stopPropagation();
|
||||||
handleRemoveEndpoint(entry);
|
handleRemoveEndpoint(entry);
|
||||||
}}
|
}}
|
||||||
className="opacity-0 transition hover:text-red-600 group-hover:opacity-100 dark:hover:text-red-400"
|
className="opacity-0 transition hover:text-red-600 group-hover:opacity-100 dark:hover:text-red-400"
|
||||||
@@ -623,8 +592,8 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="rounded-md border border-dashed border-border-default bg-muted px-4 py-8 text-center text-sm text-muted-foreground">
|
<div className="rounded-md border border-dashed border-border-default bg-gray-50 py-8 text-center text-xs text-gray-500 dark:bg-gray-900 dark:text-gray-400">
|
||||||
{t("endpointTest.empty")}
|
{t("endpointTest.noEndpoints")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -636,7 +605,37 @@ const EndpointSpeedTest: React.FC<EndpointSpeedTestProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</FullScreenPanel>
|
|
||||||
|
<DialogFooter className="gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={onClose}
|
||||||
|
disabled={isSaving}
|
||||||
|
>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={isSaving}
|
||||||
|
className="gap-2"
|
||||||
|
>
|
||||||
|
{isSaving ? (
|
||||||
|
<>
|
||||||
|
<Loader2 className="w-4 h-4 animate-spin" />
|
||||||
|
{t("common.saving")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Save className="w-4 h-4" />
|
||||||
|
{t("common.save")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
import { Save } from "lucide-react";
|
import { Save, Wand2 } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
import { formatJSON } from "@/utils/formatters";
|
||||||
|
|
||||||
interface GeminiCommonConfigModalProps {
|
interface GeminiCommonConfigModalProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -21,32 +28,86 @@ export const GeminiCommonConfigModal: React.FC<
|
|||||||
GeminiCommonConfigModalProps
|
GeminiCommonConfigModalProps
|
||||||
> = ({ isOpen, onClose, value, onChange, error }) => {
|
> = ({ isOpen, onClose, value, onChange, error }) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleFormat = () => {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
if (!value.trim()) return;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
try {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
const formatted = formatJSON(value);
|
||||||
});
|
onChange(formatted);
|
||||||
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
observer.observe(document.documentElement, {
|
} catch (error) {
|
||||||
attributes: true,
|
const errorMessage =
|
||||||
attributeFilter: ["class"],
|
error instanceof Error ? error.message : String(error);
|
||||||
});
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
return () => observer.disconnect();
|
defaultValue: "格式化失败:{{error}}",
|
||||||
}, []);
|
error: errorMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullScreenPanel
|
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
|
||||||
isOpen={isOpen}
|
<DialogContent
|
||||||
title={t("geminiConfig.editCommonConfigTitle", {
|
zIndex="nested"
|
||||||
|
className="max-w-2xl max-h-[90vh] flex flex-col p-0"
|
||||||
|
>
|
||||||
|
<DialogHeader className="px-6 pt-6 pb-0">
|
||||||
|
<DialogTitle>
|
||||||
|
{t("geminiConfig.editCommonConfigTitle", {
|
||||||
defaultValue: "编辑 Gemini 通用配置片段",
|
defaultValue: "编辑 Gemini 通用配置片段",
|
||||||
})}
|
})}
|
||||||
onClose={onClose}
|
</DialogTitle>
|
||||||
footer={
|
</DialogHeader>
|
||||||
<>
|
|
||||||
|
<div className="flex-1 overflow-auto px-6 py-4 space-y-4">
|
||||||
|
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||||
|
{t("geminiConfig.commonConfigHint", {
|
||||||
|
defaultValue:
|
||||||
|
"通用配置片段将合并到所有启用它的 Gemini 供应商配置中",
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
placeholder={`{
|
||||||
|
"timeout": 30000,
|
||||||
|
"maxRetries": 3,
|
||||||
|
"customField": "value"
|
||||||
|
}`}
|
||||||
|
rows={12}
|
||||||
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 focus:border-border-active transition-colors resize-y"
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormat}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
<Button type="button" variant="outline" onClick={onClose}>
|
<Button type="button" variant="outline" onClick={onClose}>
|
||||||
{t("common.cancel")}
|
{t("common.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -54,35 +115,8 @@ export const GeminiCommonConfigModal: React.FC<
|
|||||||
<Save className="w-4 h-4" />
|
<Save className="w-4 h-4" />
|
||||||
{t("common.save")}
|
{t("common.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</DialogFooter>
|
||||||
}
|
</DialogContent>
|
||||||
>
|
</Dialog>
|
||||||
<div className="space-y-4">
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("geminiConfig.commonConfigHint", {
|
|
||||||
defaultValue:
|
|
||||||
"通用配置片段将合并到所有启用它的 Gemini 供应商配置中",
|
|
||||||
})}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<JsonEditor
|
|
||||||
value={value}
|
|
||||||
onChange={onChange}
|
|
||||||
placeholder={`{
|
|
||||||
"timeout": 30000,
|
|
||||||
"maxRetries": 3,
|
|
||||||
"customField": "value"
|
|
||||||
}`}
|
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={16}
|
|
||||||
showValidation={true}
|
|
||||||
language="json"
|
|
||||||
/>
|
|
||||||
|
|
||||||
{error && (
|
|
||||||
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import JsonEditor from "@/components/JsonEditor";
|
import { Wand2 } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { formatJSON } from "@/utils/formatters";
|
||||||
|
|
||||||
interface GeminiEnvSectionProps {
|
interface GeminiEnvSectionProps {
|
||||||
value: string;
|
value: string;
|
||||||
@@ -19,27 +21,27 @@ export const GeminiEnvSection: React.FC<GeminiEnvSectionProps> = ({
|
|||||||
error,
|
error,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleFormat = () => {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
if (!value.trim()) return;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
try {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
// 重新格式化 .env 内容
|
||||||
});
|
const formatted = value
|
||||||
|
.split("\n")
|
||||||
observer.observe(document.documentElement, {
|
.filter((line) => line.trim())
|
||||||
attributes: true,
|
.join("\n");
|
||||||
attributeFilter: ["class"],
|
onChange(formatted);
|
||||||
});
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
|
} catch (error) {
|
||||||
return () => observer.disconnect();
|
const errorMessage =
|
||||||
}, []);
|
error instanceof Error ? error.message : String(error);
|
||||||
|
toast.error(
|
||||||
const handleChange = (newValue: string) => {
|
t("common.formatError", {
|
||||||
onChange(newValue);
|
defaultValue: "格式化失败:{{error}}",
|
||||||
if (onBlur) {
|
error: errorMessage,
|
||||||
onBlur();
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -52,21 +54,41 @@ export const GeminiEnvSection: React.FC<GeminiEnvSectionProps> = ({
|
|||||||
{t("geminiConfig.envFile", { defaultValue: "环境变量 (.env)" })}
|
{t("geminiConfig.envFile", { defaultValue: "环境变量 (.env)" })}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<JsonEditor
|
<textarea
|
||||||
|
id="geminiEnv"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={handleChange}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
onBlur={onBlur}
|
||||||
placeholder={`GOOGLE_GEMINI_BASE_URL=https://your-api-endpoint.com/
|
placeholder={`GOOGLE_GEMINI_BASE_URL=https://your-api-endpoint.com/
|
||||||
GEMINI_API_KEY=sk-your-api-key-here
|
GEMINI_API_KEY=sk-your-api-key-here
|
||||||
GEMINI_MODEL=gemini-3-pro-preview`}
|
GEMINI_MODEL=gemini-2.5-pro`}
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={6}
|
rows={6}
|
||||||
showValidation={false}
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[8rem]"
|
||||||
language="javascript"
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormat}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
<p className="text-xs text-red-500 dark:text-red-400">{error}</p>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{!error && (
|
{!error && (
|
||||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
@@ -102,22 +124,25 @@ export const GeminiConfigSection: React.FC<GeminiConfigSectionProps> = ({
|
|||||||
configError,
|
configError,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isDarkMode, setIsDarkMode] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const handleFormat = () => {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
if (!value.trim()) return;
|
||||||
|
|
||||||
const observer = new MutationObserver(() => {
|
try {
|
||||||
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
const formatted = formatJSON(value);
|
||||||
});
|
onChange(formatted);
|
||||||
|
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||||
observer.observe(document.documentElement, {
|
} catch (error) {
|
||||||
attributes: true,
|
const errorMessage =
|
||||||
attributeFilter: ["class"],
|
error instanceof Error ? error.message : String(error);
|
||||||
});
|
toast.error(
|
||||||
|
t("common.formatError", {
|
||||||
return () => observer.disconnect();
|
defaultValue: "格式化失败:{{error}}",
|
||||||
}, []);
|
error: errorMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
@@ -162,22 +187,43 @@ export const GeminiConfigSection: React.FC<GeminiConfigSectionProps> = ({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<JsonEditor
|
<textarea
|
||||||
|
id="geminiConfig"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
placeholder={`{
|
placeholder={`{
|
||||||
"timeout": 30000,
|
"timeout": 30000,
|
||||||
"maxRetries": 3
|
"maxRetries": 3
|
||||||
}`}
|
}`}
|
||||||
darkMode={isDarkMode}
|
|
||||||
rows={8}
|
rows={8}
|
||||||
showValidation={true}
|
className="w-full px-3 py-2 border border-border-default dark:bg-gray-800 dark:text-gray-100 rounded-lg text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:focus:ring-blue-400/20 transition-colors resize-y min-h-[10rem]"
|
||||||
language="json"
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
autoCapitalize="none"
|
||||||
|
spellCheck={false}
|
||||||
|
lang="en"
|
||||||
|
inputMode="text"
|
||||||
|
data-gramm="false"
|
||||||
|
data-gramm_editor="false"
|
||||||
|
data-enable-grammarly="false"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleFormat}
|
||||||
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-300 hover:text-blue-600 dark:hover:text-blue-400 transition-colors"
|
||||||
|
>
|
||||||
|
<Wand2 className="w-3.5 h-3.5" />
|
||||||
|
{t("common.format", { defaultValue: "格式化" })}
|
||||||
|
</button>
|
||||||
|
|
||||||
{configError && (
|
{configError && (
|
||||||
<p className="text-xs text-red-500 dark:text-red-400">{configError}</p>
|
<p className="text-xs text-red-500 dark:text-red-400">
|
||||||
|
{configError}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{!configError && (
|
{!configError && (
|
||||||
<p className="text-xs text-gray-500 dark:text-gray-400">
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export function GeminiFormFields({
|
|||||||
id="gemini-model"
|
id="gemini-model"
|
||||||
value={model}
|
value={model}
|
||||||
onChange={(e) => onModelChange(e.target.value)}
|
onChange={(e) => onModelChange(e.target.value)}
|
||||||
placeholder="gemini-3-pro-preview"
|
placeholder="gemini-2.5-pro"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ const GEMINI_DEFAULT_CONFIG = JSON.stringify(
|
|||||||
env: {
|
env: {
|
||||||
GOOGLE_GEMINI_BASE_URL: "",
|
GOOGLE_GEMINI_BASE_URL: "",
|
||||||
GEMINI_API_KEY: "",
|
GEMINI_API_KEY: "",
|
||||||
GEMINI_MODEL: "gemini-3-pro-preview",
|
GEMINI_MODEL: "gemini-2.5-pro",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
@@ -78,8 +78,6 @@ interface ProviderFormProps {
|
|||||||
settingsConfig?: Record<string, unknown>;
|
settingsConfig?: Record<string, unknown>;
|
||||||
category?: ProviderCategory;
|
category?: ProviderCategory;
|
||||||
meta?: ProviderMeta;
|
meta?: ProviderMeta;
|
||||||
icon?: string;
|
|
||||||
iconColor?: string;
|
|
||||||
};
|
};
|
||||||
showButtons?: boolean;
|
showButtons?: boolean;
|
||||||
}
|
}
|
||||||
@@ -149,8 +147,6 @@ export function ProviderForm({
|
|||||||
: appId === "gemini"
|
: appId === "gemini"
|
||||||
? GEMINI_DEFAULT_CONFIG
|
? GEMINI_DEFAULT_CONFIG
|
||||||
: CLAUDE_DEFAULT_CONFIG,
|
: CLAUDE_DEFAULT_CONFIG,
|
||||||
icon: initialData?.icon ?? "",
|
|
||||||
iconColor: initialData?.iconColor ?? "",
|
|
||||||
}),
|
}),
|
||||||
[initialData, appId],
|
[initialData, appId],
|
||||||
);
|
);
|
||||||
@@ -175,12 +171,14 @@ export function ProviderForm({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 使用 Base URL hook (Claude, Codex, Gemini)
|
// 使用 Base URL hook (Claude, Codex, Gemini)
|
||||||
const { baseUrl, handleClaudeBaseUrlChange } = useBaseUrlState({
|
const { baseUrl, handleClaudeBaseUrlChange, handleGeminiBaseUrlChange } =
|
||||||
|
useBaseUrlState({
|
||||||
appType: appId,
|
appType: appId,
|
||||||
category,
|
category,
|
||||||
settingsConfig: form.watch("settingsConfig"),
|
settingsConfig: form.watch("settingsConfig"),
|
||||||
codexConfig: "",
|
codexConfig: "",
|
||||||
onSettingsConfigChange: (config) => form.setValue("settingsConfig", config),
|
onSettingsConfigChange: (config) =>
|
||||||
|
form.setValue("settingsConfig", config),
|
||||||
onCodexConfigChange: () => {
|
onCodexConfigChange: () => {
|
||||||
/* noop */
|
/* noop */
|
||||||
},
|
},
|
||||||
@@ -319,13 +317,9 @@ export function ProviderForm({
|
|||||||
const {
|
const {
|
||||||
geminiEnv,
|
geminiEnv,
|
||||||
geminiConfig,
|
geminiConfig,
|
||||||
geminiApiKey,
|
|
||||||
geminiBaseUrl,
|
|
||||||
geminiModel,
|
geminiModel,
|
||||||
envError,
|
envError,
|
||||||
configError: geminiConfigError,
|
configError: geminiConfigError,
|
||||||
handleGeminiApiKeyChange: originalHandleGeminiApiKeyChange,
|
|
||||||
handleGeminiBaseUrlChange: originalHandleGeminiBaseUrlChange,
|
|
||||||
handleGeminiEnvChange,
|
handleGeminiEnvChange,
|
||||||
handleGeminiConfigChange,
|
handleGeminiConfigChange,
|
||||||
resetGeminiConfig,
|
resetGeminiConfig,
|
||||||
@@ -335,39 +329,6 @@ export function ProviderForm({
|
|||||||
initialData: appId === "gemini" ? initialData : undefined,
|
initialData: appId === "gemini" ? initialData : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 包装 Gemini handlers 以同步 settingsConfig
|
|
||||||
const handleGeminiApiKeyChange = useCallback(
|
|
||||||
(key: string) => {
|
|
||||||
originalHandleGeminiApiKeyChange(key);
|
|
||||||
// 同步更新 settingsConfig
|
|
||||||
try {
|
|
||||||
const config = JSON.parse(form.watch("settingsConfig") || "{}");
|
|
||||||
if (!config.env) config.env = {};
|
|
||||||
config.env.GEMINI_API_KEY = key.trim();
|
|
||||||
form.setValue("settingsConfig", JSON.stringify(config, null, 2));
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[originalHandleGeminiApiKeyChange, form],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleGeminiBaseUrlChange = useCallback(
|
|
||||||
(url: string) => {
|
|
||||||
originalHandleGeminiBaseUrlChange(url);
|
|
||||||
// 同步更新 settingsConfig
|
|
||||||
try {
|
|
||||||
const config = JSON.parse(form.watch("settingsConfig") || "{}");
|
|
||||||
if (!config.env) config.env = {};
|
|
||||||
config.env.GOOGLE_GEMINI_BASE_URL = url.trim().replace(/\/+$/, "");
|
|
||||||
form.setValue("settingsConfig", JSON.stringify(config, null, 2));
|
|
||||||
} catch {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[originalHandleGeminiBaseUrlChange, form],
|
|
||||||
);
|
|
||||||
|
|
||||||
// 使用 Gemini 通用配置 hook (仅 Gemini 模式)
|
// 使用 Gemini 通用配置 hook (仅 Gemini 模式)
|
||||||
const {
|
const {
|
||||||
useCommonConfig: useGeminiCommonConfigFlag,
|
useCommonConfig: useGeminiCommonConfigFlag,
|
||||||
@@ -655,7 +616,7 @@ export function ProviderForm({
|
|||||||
<form
|
<form
|
||||||
id="provider-form"
|
id="provider-form"
|
||||||
onSubmit={form.handleSubmit(handleSubmit)}
|
onSubmit={form.handleSubmit(handleSubmit)}
|
||||||
className="space-y-6 glass rounded-xl p-6 border border-white/10"
|
className="space-y-6"
|
||||||
>
|
>
|
||||||
{/* 预设供应商选择(仅新增模式显示) */}
|
{/* 预设供应商选择(仅新增模式显示) */}
|
||||||
{!initialData && (
|
{!initialData && (
|
||||||
@@ -743,15 +704,15 @@ export function ProviderForm({
|
|||||||
form.watch("settingsConfig"),
|
form.watch("settingsConfig"),
|
||||||
isEditMode,
|
isEditMode,
|
||||||
)}
|
)}
|
||||||
apiKey={geminiApiKey}
|
apiKey={apiKey}
|
||||||
onApiKeyChange={handleGeminiApiKeyChange}
|
onApiKeyChange={handleApiKeyChange}
|
||||||
category={category}
|
category={category}
|
||||||
shouldShowApiKeyLink={shouldShowGeminiApiKeyLink}
|
shouldShowApiKeyLink={shouldShowGeminiApiKeyLink}
|
||||||
websiteUrl={geminiWebsiteUrl}
|
websiteUrl={geminiWebsiteUrl}
|
||||||
isPartner={isGeminiPartner}
|
isPartner={isGeminiPartner}
|
||||||
partnerPromotionKey={geminiPartnerPromotionKey}
|
partnerPromotionKey={geminiPartnerPromotionKey}
|
||||||
shouldShowSpeedTest={shouldShowSpeedTest}
|
shouldShowSpeedTest={shouldShowSpeedTest}
|
||||||
baseUrl={geminiBaseUrl}
|
baseUrl={baseUrl}
|
||||||
onBaseUrlChange={handleGeminiBaseUrlChange}
|
onBaseUrlChange={handleGeminiBaseUrlChange}
|
||||||
isEndpointModalOpen={isEndpointModalOpen}
|
isEndpointModalOpen={isEndpointModalOpen}
|
||||||
onEndpointModalToggle={setIsEndpointModalOpen}
|
onEndpointModalToggle={setIsEndpointModalOpen}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export function ProviderPresetSelector({
|
|||||||
return `${baseClass} bg-blue-500 text-white dark:bg-blue-600`;
|
return `${baseClass} bg-blue-500 text-white dark:bg-blue-600`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${baseClass} bg-accent text-muted-foreground hover:bg-accent/80`;
|
return `${baseClass} bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取预设按钮的内联样式(用于自定义背景色)
|
// 获取预设按钮的内联样式(用于自定义背景色)
|
||||||
@@ -128,7 +128,7 @@ export function ProviderPresetSelector({
|
|||||||
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
className={`inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
|
||||||
selectedPresetId === "custom"
|
selectedPresetId === "custom"
|
||||||
? "bg-blue-500 text-white dark:bg-blue-600"
|
? "bg-blue-500 text-white dark:bg-blue-600"
|
||||||
: "bg-accent text-muted-foreground hover:bg-accent/80"
|
: "bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{t("providerPreset.custom")}
|
{t("providerPreset.custom")}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ interface DirectorySettingsProps {
|
|||||||
onResetAppConfig: () => Promise<void>;
|
onResetAppConfig: () => Promise<void>;
|
||||||
claudeDir?: string;
|
claudeDir?: string;
|
||||||
codexDir?: string;
|
codexDir?: string;
|
||||||
geminiDir?: string;
|
|
||||||
onDirectoryChange: (app: AppId, value?: string) => void;
|
onDirectoryChange: (app: AppId, value?: string) => void;
|
||||||
onBrowseDirectory: (app: AppId) => Promise<void>;
|
onBrowseDirectory: (app: AppId) => Promise<void>;
|
||||||
onResetDirectory: (app: AppId) => Promise<void>;
|
onResetDirectory: (app: AppId) => Promise<void>;
|
||||||
@@ -28,7 +27,6 @@ export function DirectorySettings({
|
|||||||
onResetAppConfig,
|
onResetAppConfig,
|
||||||
claudeDir,
|
claudeDir,
|
||||||
codexDir,
|
codexDir,
|
||||||
geminiDir,
|
|
||||||
onDirectoryChange,
|
onDirectoryChange,
|
||||||
onBrowseDirectory,
|
onBrowseDirectory,
|
||||||
onResetDirectory,
|
onResetDirectory,
|
||||||
@@ -106,17 +104,6 @@ export function DirectorySettings({
|
|||||||
onBrowse={() => onBrowseDirectory("codex")}
|
onBrowse={() => onBrowseDirectory("codex")}
|
||||||
onReset={() => onResetDirectory("codex")}
|
onReset={() => onResetDirectory("codex")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DirectoryInput
|
|
||||||
label={t("settings.geminiConfigDir")}
|
|
||||||
description={undefined}
|
|
||||||
value={geminiDir}
|
|
||||||
resolvedValue={resolvedDirs.gemini}
|
|
||||||
placeholder={t("settings.browsePlaceholderGemini")}
|
|
||||||
onChange={(val) => onDirectoryChange("gemini", val)}
|
|
||||||
onBrowse={() => onBrowseDirectory("gemini")}
|
|
||||||
onReset={() => onResetDirectory("gemini")}
|
|
||||||
/>
|
|
||||||
</section>
|
</section>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -44,73 +44,66 @@ export function ImportExportSection({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="space-y-4">
|
<section className="space-y-4">
|
||||||
<header className="space-y-2">
|
<header className="space-y-1">
|
||||||
<h3 className="text-base font-semibold text-foreground">
|
<h3 className="text-sm font-medium">{t("settings.importExport")}</h3>
|
||||||
{t("settings.importExport")}
|
<p className="text-xs text-muted-foreground">
|
||||||
</h3>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("settings.importExportHint")}
|
{t("settings.importExportHint")}
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div className="space-y-4 rounded-xl glass-card p-6 border border-white/10">
|
<div className="space-y-3 rounded-lg border border-border-default p-4">
|
||||||
{/* Import and Export Buttons Side by Side */}
|
|
||||||
<div className="grid grid-cols-2 gap-4 items-stretch">
|
|
||||||
{/* Import Button */}
|
|
||||||
<div className="relative">
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
className={`w-full h-auto py-3 px-4 bg-blue-500 hover:bg-blue-600 dark:bg-blue-600 dark:hover:bg-blue-700 text-white ${selectedFile && !isImporting ? "flex-col items-start" : "items-center"}`}
|
className="w-full"
|
||||||
onClick={!selectedFile ? onSelectFile : onImport}
|
variant="secondary"
|
||||||
disabled={isImporting}
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2 w-full justify-center">
|
|
||||||
{isImporting ? (
|
|
||||||
<Loader2 className="h-4 w-4 animate-spin flex-shrink-0" />
|
|
||||||
) : selectedFile ? (
|
|
||||||
<CheckCircle2 className="h-4 w-4 flex-shrink-0" />
|
|
||||||
) : (
|
|
||||||
<FolderOpen className="h-4 w-4 flex-shrink-0" />
|
|
||||||
)}
|
|
||||||
<span className="font-medium">
|
|
||||||
{isImporting
|
|
||||||
? t("settings.importing")
|
|
||||||
: selectedFile
|
|
||||||
? t("settings.import")
|
|
||||||
: t("settings.selectConfigFile")}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{selectedFile && !isImporting && (
|
|
||||||
<div className="mt-2 w-full text-left">
|
|
||||||
<p className="text-xs font-mono text-white/80 truncate">
|
|
||||||
📄 {selectedFileName}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
{selectedFile && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClear}
|
|
||||||
className="absolute -top-2 -right-2 h-6 w-6 rounded-full bg-red-500 hover:bg-red-600 text-white flex items-center justify-center shadow-lg transition-colors z-10"
|
|
||||||
aria-label="Clear selection"
|
|
||||||
>
|
|
||||||
<XCircle className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Export Button */}
|
|
||||||
<div>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
className="w-full h-full py-3 px-4 bg-blue-500 hover:bg-blue-600 dark:bg-blue-600 dark:hover:bg-blue-700 text-white items-center"
|
|
||||||
onClick={onExport}
|
onClick={onExport}
|
||||||
>
|
>
|
||||||
<Save className="mr-2 h-4 w-4" />
|
<Save className="mr-2 h-4 w-4" />
|
||||||
{t("settings.exportConfig")}
|
{t("settings.exportConfig")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="flex-1 min-w-[180px]"
|
||||||
|
onClick={onSelectFile}
|
||||||
|
>
|
||||||
|
<FolderOpen className="mr-2 h-4 w-4" />
|
||||||
|
{t("settings.selectConfigFile")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
disabled={!selectedFile || isImporting}
|
||||||
|
onClick={onImport}
|
||||||
|
>
|
||||||
|
{isImporting ? (
|
||||||
|
<span className="inline-flex items-center gap-2">
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
|
{t("settings.importing")}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
t("settings.import")
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
{selectedFile ? (
|
||||||
|
<Button type="button" variant="ghost" onClick={onClear}>
|
||||||
|
<XCircle className="mr-2 h-4 w-4" />
|
||||||
|
{t("common.clear")}
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{selectedFile ? (
|
||||||
|
<p className="truncate rounded-md bg-muted/40 px-3 py-2 text-xs font-mono text-muted-foreground">
|
||||||
|
{selectedFileName}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{t("settings.noFileSelected")}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ImportStatusMessage
|
<ImportStatusMessage
|
||||||
@@ -141,19 +134,15 @@ function ImportStatusMessage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const baseClass =
|
const baseClass =
|
||||||
"flex items-start gap-3 rounded-xl border p-4 text-sm leading-relaxed backdrop-blur-sm";
|
"flex items-start gap-2 rounded-md border px-3 py-2 text-xs leading-relaxed";
|
||||||
|
|
||||||
if (status === "importing") {
|
if (status === "importing") {
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`${baseClass} border-border-default bg-muted/40`}>
|
||||||
className={`${baseClass} border-blue-500/30 bg-blue-500/10 text-blue-600 dark:text-blue-400`}
|
<Loader2 className="mt-0.5 h-4 w-4 animate-spin text-muted-foreground" />
|
||||||
>
|
|
||||||
<Loader2 className="mt-0.5 h-5 w-5 flex-shrink-0 animate-spin" />
|
|
||||||
<div>
|
<div>
|
||||||
<p className="font-semibold">{t("settings.importing")}</p>
|
<p className="font-medium">{t("settings.importing")}</p>
|
||||||
<p className="text-blue-600/80 dark:text-blue-400/80">
|
<p className="text-muted-foreground">{t("common.loading")}</p>
|
||||||
{t("common.loading")}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -162,19 +151,17 @@ function ImportStatusMessage({
|
|||||||
if (status === "success") {
|
if (status === "success") {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`${baseClass} border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-400`}
|
className={`${baseClass} border-green-200 bg-green-100/70 text-green-700`}
|
||||||
>
|
>
|
||||||
<CheckCircle2 className="mt-0.5 h-5 w-5 flex-shrink-0" />
|
<CheckCircle2 className="mt-0.5 h-4 w-4" />
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1">
|
||||||
<p className="font-semibold">{t("settings.importSuccess")}</p>
|
<p className="font-medium">{t("settings.importSuccess")}</p>
|
||||||
{backupId ? (
|
{backupId ? (
|
||||||
<p className="text-xs text-green-600/80 dark:text-green-400/80">
|
<p className="text-xs">
|
||||||
{t("settings.backupId")}: {backupId}
|
{t("settings.backupId")}: {backupId}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
<p className="text-green-600/80 dark:text-green-400/80">
|
<p>{t("settings.autoReload")}</p>
|
||||||
{t("settings.autoReload")}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -183,14 +170,12 @@ function ImportStatusMessage({
|
|||||||
if (status === "partial-success") {
|
if (status === "partial-success") {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`${baseClass} border-yellow-500/30 bg-yellow-500/10 text-yellow-700 dark:text-yellow-400`}
|
className={`${baseClass} border-yellow-200 bg-yellow-100/70 text-yellow-700`}
|
||||||
>
|
>
|
||||||
<AlertCircle className="mt-0.5 h-5 w-5 flex-shrink-0" />
|
<AlertCircle className="mt-0.5 h-4 w-4" />
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1">
|
||||||
<p className="font-semibold">{t("settings.importPartialSuccess")}</p>
|
<p className="font-medium">{t("settings.importPartialSuccess")}</p>
|
||||||
<p className="text-yellow-600/80 dark:text-yellow-400/80">
|
<p>{t("settings.importPartialHint")}</p>
|
||||||
{t("settings.importPartialHint")}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -199,13 +184,11 @@ function ImportStatusMessage({
|
|||||||
const message = errorMessage || t("settings.importFailed");
|
const message = errorMessage || t("settings.importFailed");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`${baseClass} border-red-200 bg-red-100/70 text-red-600`}>
|
||||||
className={`${baseClass} border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400`}
|
<AlertCircle className="mt-0.5 h-4 w-4" />
|
||||||
>
|
<div className="space-y-1">
|
||||||
<AlertCircle className="mt-0.5 h-5 w-5 flex-shrink-0" />
|
<p className="font-medium">{t("settings.importFailed")}</p>
|
||||||
<div className="space-y-1.5">
|
<p>{message}</p>
|
||||||
<p className="font-semibold">{t("settings.importFailed")}</p>
|
|
||||||
<p className="text-red-600/80 dark:text-red-400/80">{message}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,294 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { Loader2, Save } from "lucide-react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { settingsApi } from "@/lib/api";
|
||||||
|
import { LanguageSettings } from "@/components/settings/LanguageSettings";
|
||||||
|
import { ThemeSettings } from "@/components/settings/ThemeSettings";
|
||||||
|
import { WindowSettings } from "@/components/settings/WindowSettings";
|
||||||
|
import { DirectorySettings } from "@/components/settings/DirectorySettings";
|
||||||
|
import { ImportExportSection } from "@/components/settings/ImportExportSection";
|
||||||
|
import { AboutSection } from "@/components/settings/AboutSection";
|
||||||
|
import { useSettings } from "@/hooks/useSettings";
|
||||||
|
import { useImportExport } from "@/hooks/useImportExport";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
interface SettingsDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
onImportSuccess?: () => void | Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SettingsDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onImportSuccess,
|
||||||
|
}: SettingsDialogProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const {
|
||||||
|
settings,
|
||||||
|
isLoading,
|
||||||
|
isSaving,
|
||||||
|
isPortable,
|
||||||
|
appConfigDir,
|
||||||
|
resolvedDirs,
|
||||||
|
updateSettings,
|
||||||
|
updateDirectory,
|
||||||
|
updateAppConfigDir,
|
||||||
|
browseDirectory,
|
||||||
|
browseAppConfigDir,
|
||||||
|
resetDirectory,
|
||||||
|
resetAppConfigDir,
|
||||||
|
saveSettings,
|
||||||
|
resetSettings,
|
||||||
|
requiresRestart,
|
||||||
|
acknowledgeRestart,
|
||||||
|
} = useSettings();
|
||||||
|
|
||||||
|
const {
|
||||||
|
selectedFile,
|
||||||
|
status: importStatus,
|
||||||
|
errorMessage,
|
||||||
|
backupId,
|
||||||
|
isImporting,
|
||||||
|
selectImportFile,
|
||||||
|
importConfig,
|
||||||
|
exportConfig,
|
||||||
|
clearSelection,
|
||||||
|
resetStatus,
|
||||||
|
} = useImportExport({ onImportSuccess });
|
||||||
|
|
||||||
|
const [activeTab, setActiveTab] = useState<string>("general");
|
||||||
|
const [showRestartPrompt, setShowRestartPrompt] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setActiveTab("general");
|
||||||
|
resetStatus();
|
||||||
|
}
|
||||||
|
}, [open, resetStatus]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (requiresRestart) {
|
||||||
|
setShowRestartPrompt(true);
|
||||||
|
}
|
||||||
|
}, [requiresRestart]);
|
||||||
|
|
||||||
|
const closeDialog = useCallback(() => {
|
||||||
|
// 取消/直接关闭:恢复到初始设置(包括语言回滚)
|
||||||
|
resetSettings();
|
||||||
|
acknowledgeRestart();
|
||||||
|
clearSelection();
|
||||||
|
resetStatus();
|
||||||
|
onOpenChange(false);
|
||||||
|
}, [
|
||||||
|
acknowledgeRestart,
|
||||||
|
clearSelection,
|
||||||
|
onOpenChange,
|
||||||
|
resetSettings,
|
||||||
|
resetStatus,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const closeAfterSave = useCallback(() => {
|
||||||
|
// 保存成功后关闭:不再重置语言,避免需要“保存两次”才生效
|
||||||
|
acknowledgeRestart();
|
||||||
|
clearSelection();
|
||||||
|
resetStatus();
|
||||||
|
onOpenChange(false);
|
||||||
|
}, [acknowledgeRestart, clearSelection, onOpenChange, resetStatus]);
|
||||||
|
|
||||||
|
const handleDialogChange = useCallback(
|
||||||
|
(nextOpen: boolean) => {
|
||||||
|
if (!nextOpen) {
|
||||||
|
closeDialog();
|
||||||
|
} else {
|
||||||
|
onOpenChange(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[closeDialog, onOpenChange],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCancel = useCallback(() => {
|
||||||
|
closeDialog();
|
||||||
|
}, [closeDialog]);
|
||||||
|
|
||||||
|
const handleSave = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const result = await saveSettings();
|
||||||
|
if (!result) return;
|
||||||
|
if (result.requiresRestart) {
|
||||||
|
setShowRestartPrompt(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
closeAfterSave();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[SettingsDialog] Failed to save settings", error);
|
||||||
|
}
|
||||||
|
}, [closeDialog, saveSettings]);
|
||||||
|
|
||||||
|
const handleRestartLater = useCallback(() => {
|
||||||
|
setShowRestartPrompt(false);
|
||||||
|
closeAfterSave();
|
||||||
|
}, [closeAfterSave]);
|
||||||
|
|
||||||
|
const handleRestartNow = useCallback(async () => {
|
||||||
|
setShowRestartPrompt(false);
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
toast.success(t("settings.devModeRestartHint"));
|
||||||
|
closeAfterSave();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await settingsApi.restart();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("[SettingsDialog] Failed to restart app", error);
|
||||||
|
toast.error(t("settings.restartFailed"));
|
||||||
|
} finally {
|
||||||
|
closeAfterSave();
|
||||||
|
}
|
||||||
|
}, [closeAfterSave, t]);
|
||||||
|
|
||||||
|
const isBusy = useMemo(() => isLoading && !settings, [isLoading, settings]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleDialogChange}>
|
||||||
|
<DialogContent className="max-w-3xl max-h-[90vh] flex flex-col">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t("settings.title")}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
{isBusy ? (
|
||||||
|
<div className="flex min-h-[320px] items-center justify-center">
|
||||||
|
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex-1 overflow-y-auto px-6 py-4">
|
||||||
|
<Tabs
|
||||||
|
value={activeTab}
|
||||||
|
onValueChange={setActiveTab}
|
||||||
|
className="flex flex-col h-full"
|
||||||
|
>
|
||||||
|
<TabsList className="grid w-full grid-cols-3">
|
||||||
|
<TabsTrigger value="general">
|
||||||
|
{t("settings.tabGeneral")}
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="advanced">
|
||||||
|
{t("settings.tabAdvanced")}
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="about">{t("common.about")}</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
|
||||||
|
<TabsContent
|
||||||
|
value="general"
|
||||||
|
className="space-y-6 mt-6 min-h-[400px]"
|
||||||
|
>
|
||||||
|
{settings ? (
|
||||||
|
<>
|
||||||
|
<LanguageSettings
|
||||||
|
value={settings.language}
|
||||||
|
onChange={(lang) => updateSettings({ language: lang })}
|
||||||
|
/>
|
||||||
|
<ThemeSettings />
|
||||||
|
<WindowSettings
|
||||||
|
settings={settings}
|
||||||
|
onChange={updateSettings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent
|
||||||
|
value="advanced"
|
||||||
|
className="space-y-6 mt-6 min-h-[400px]"
|
||||||
|
>
|
||||||
|
{settings ? (
|
||||||
|
<>
|
||||||
|
<DirectorySettings
|
||||||
|
appConfigDir={appConfigDir}
|
||||||
|
resolvedDirs={resolvedDirs}
|
||||||
|
onAppConfigChange={updateAppConfigDir}
|
||||||
|
onBrowseAppConfig={browseAppConfigDir}
|
||||||
|
onResetAppConfig={resetAppConfigDir}
|
||||||
|
claudeDir={settings.claudeConfigDir}
|
||||||
|
codexDir={settings.codexConfigDir}
|
||||||
|
onDirectoryChange={updateDirectory}
|
||||||
|
onBrowseDirectory={browseDirectory}
|
||||||
|
onResetDirectory={resetDirectory}
|
||||||
|
/>
|
||||||
|
<ImportExportSection
|
||||||
|
status={importStatus}
|
||||||
|
selectedFile={selectedFile}
|
||||||
|
errorMessage={errorMessage}
|
||||||
|
backupId={backupId}
|
||||||
|
isImporting={isImporting}
|
||||||
|
onSelectFile={selectImportFile}
|
||||||
|
onImport={importConfig}
|
||||||
|
onExport={exportConfig}
|
||||||
|
onClear={clearSelection}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</TabsContent>
|
||||||
|
|
||||||
|
<TabsContent value="about" className="mt-6 min-h-[400px]">
|
||||||
|
<AboutSection isPortable={isPortable} />
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={handleCancel}>
|
||||||
|
{t("common.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleSave} disabled={isSaving || isBusy}>
|
||||||
|
{isSaving ? (
|
||||||
|
<span className="inline-flex items-center gap-2">
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin" />
|
||||||
|
{t("settings.saving")}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Save className="mr-2 h-4 w-4" />
|
||||||
|
{t("common.save")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
open={showRestartPrompt}
|
||||||
|
onOpenChange={(open) => !open && handleRestartLater()}
|
||||||
|
>
|
||||||
|
<DialogContent zIndex="alert" className="max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t("settings.restartRequired")}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="px-6">
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
{t("settings.restartRequiredMessage")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" onClick={handleRestartLater}>
|
||||||
|
{t("settings.restartLater")}
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleRestartNow}>
|
||||||
|
{t("settings.restartNow")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
||||||
import { Loader2, Save } from "lucide-react";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { settingsApi } from "@/lib/api";
|
|
||||||
import { LanguageSettings } from "@/components/settings/LanguageSettings";
|
|
||||||
import { ThemeSettings } from "@/components/settings/ThemeSettings";
|
|
||||||
import { WindowSettings } from "@/components/settings/WindowSettings";
|
|
||||||
import { DirectorySettings } from "@/components/settings/DirectorySettings";
|
|
||||||
import { ImportExportSection } from "@/components/settings/ImportExportSection";
|
|
||||||
import { AboutSection } from "@/components/settings/AboutSection";
|
|
||||||
import { useSettings } from "@/hooks/useSettings";
|
|
||||||
import { useImportExport } from "@/hooks/useImportExport";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import type { SettingsFormState } from "@/hooks/useSettings";
|
|
||||||
|
|
||||||
interface SettingsDialogProps {
|
|
||||||
open: boolean;
|
|
||||||
onOpenChange: (open: boolean) => void;
|
|
||||||
onImportSuccess?: () => void | Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SettingsPage({
|
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
onImportSuccess,
|
|
||||||
}: SettingsDialogProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const {
|
|
||||||
settings,
|
|
||||||
isLoading,
|
|
||||||
isSaving,
|
|
||||||
isPortable,
|
|
||||||
appConfigDir,
|
|
||||||
resolvedDirs,
|
|
||||||
updateSettings,
|
|
||||||
updateDirectory,
|
|
||||||
updateAppConfigDir,
|
|
||||||
browseDirectory,
|
|
||||||
browseAppConfigDir,
|
|
||||||
resetDirectory,
|
|
||||||
resetAppConfigDir,
|
|
||||||
saveSettings,
|
|
||||||
autoSaveSettings,
|
|
||||||
requiresRestart,
|
|
||||||
acknowledgeRestart,
|
|
||||||
} = useSettings();
|
|
||||||
|
|
||||||
const {
|
|
||||||
selectedFile,
|
|
||||||
status: importStatus,
|
|
||||||
errorMessage,
|
|
||||||
backupId,
|
|
||||||
isImporting,
|
|
||||||
selectImportFile,
|
|
||||||
importConfig,
|
|
||||||
exportConfig,
|
|
||||||
clearSelection,
|
|
||||||
resetStatus,
|
|
||||||
} = useImportExport({ onImportSuccess });
|
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState<string>("general");
|
|
||||||
const [showRestartPrompt, setShowRestartPrompt] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (open) {
|
|
||||||
setActiveTab("general");
|
|
||||||
resetStatus();
|
|
||||||
}
|
|
||||||
}, [open, resetStatus]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (requiresRestart) {
|
|
||||||
setShowRestartPrompt(true);
|
|
||||||
}
|
|
||||||
}, [requiresRestart]);
|
|
||||||
|
|
||||||
const closeAfterSave = useCallback(() => {
|
|
||||||
// 保存成功后关闭:不再重置语言,避免需要“保存两次”才生效
|
|
||||||
acknowledgeRestart();
|
|
||||||
clearSelection();
|
|
||||||
resetStatus();
|
|
||||||
onOpenChange(false);
|
|
||||||
}, [acknowledgeRestart, clearSelection, onOpenChange, resetStatus]);
|
|
||||||
|
|
||||||
const handleSave = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
const result = await saveSettings(undefined, { silent: false });
|
|
||||||
if (!result) return;
|
|
||||||
if (result.requiresRestart) {
|
|
||||||
setShowRestartPrompt(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
closeAfterSave();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[SettingsPage] Failed to save settings", error);
|
|
||||||
}
|
|
||||||
}, [closeAfterSave, saveSettings]);
|
|
||||||
|
|
||||||
const handleRestartLater = useCallback(() => {
|
|
||||||
setShowRestartPrompt(false);
|
|
||||||
closeAfterSave();
|
|
||||||
}, [closeAfterSave]);
|
|
||||||
|
|
||||||
const handleRestartNow = useCallback(async () => {
|
|
||||||
setShowRestartPrompt(false);
|
|
||||||
if (import.meta.env.DEV) {
|
|
||||||
toast.success(t("settings.devModeRestartHint"));
|
|
||||||
closeAfterSave();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await settingsApi.restart();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[SettingsPage] Failed to restart app", error);
|
|
||||||
toast.error(t("settings.restartFailed"));
|
|
||||||
} finally {
|
|
||||||
closeAfterSave();
|
|
||||||
}
|
|
||||||
}, [closeAfterSave, t]);
|
|
||||||
|
|
||||||
// 通用设置即时保存(无需手动点击)
|
|
||||||
// 使用 autoSaveSettings 避免误触发系统 API(开机自启、Claude 插件等)
|
|
||||||
const handleAutoSave = useCallback(
|
|
||||||
async (updates: Partial<SettingsFormState>) => {
|
|
||||||
if (!settings) return;
|
|
||||||
updateSettings(updates);
|
|
||||||
try {
|
|
||||||
await autoSaveSettings(updates);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[SettingsPage] Failed to autosave settings", error);
|
|
||||||
toast.error(
|
|
||||||
t("settings.saveFailedGeneric", {
|
|
||||||
defaultValue: "保存失败,请重试",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[autoSaveSettings, settings, t, updateSettings],
|
|
||||||
);
|
|
||||||
|
|
||||||
const isBusy = useMemo(() => isLoading && !settings, [isLoading, settings]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="mx-auto max-w-[56rem] flex flex-col h-[calc(100vh-8rem)] px-6">
|
|
||||||
{isBusy ? (
|
|
||||||
<div className="flex flex-1 items-center justify-center">
|
|
||||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Tabs
|
|
||||||
value={activeTab}
|
|
||||||
onValueChange={setActiveTab}
|
|
||||||
className="flex flex-col h-full"
|
|
||||||
>
|
|
||||||
<TabsList className="grid w-full grid-cols-3 mb-6 glass rounded-xl">
|
|
||||||
<TabsTrigger value="general">
|
|
||||||
{t("settings.tabGeneral")}
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="advanced">
|
|
||||||
{t("settings.tabAdvanced")}
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="about">{t("common.about")}</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto pr-2">
|
|
||||||
<TabsContent value="general" className="space-y-6 mt-0">
|
|
||||||
{settings ? (
|
|
||||||
<>
|
|
||||||
<LanguageSettings
|
|
||||||
value={settings.language}
|
|
||||||
onChange={(lang) => handleAutoSave({ language: lang })}
|
|
||||||
/>
|
|
||||||
<ThemeSettings />
|
|
||||||
<WindowSettings
|
|
||||||
settings={settings}
|
|
||||||
onChange={handleAutoSave}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="advanced" className="space-y-6 mt-0 pb-6">
|
|
||||||
{settings ? (
|
|
||||||
<>
|
|
||||||
<DirectorySettings
|
|
||||||
appConfigDir={appConfigDir}
|
|
||||||
resolvedDirs={resolvedDirs}
|
|
||||||
onAppConfigChange={updateAppConfigDir}
|
|
||||||
onBrowseAppConfig={browseAppConfigDir}
|
|
||||||
onResetAppConfig={resetAppConfigDir}
|
|
||||||
claudeDir={settings.claudeConfigDir}
|
|
||||||
codexDir={settings.codexConfigDir}
|
|
||||||
geminiDir={settings.geminiConfigDir}
|
|
||||||
onDirectoryChange={updateDirectory}
|
|
||||||
onBrowseDirectory={browseDirectory}
|
|
||||||
onResetDirectory={resetDirectory}
|
|
||||||
/>
|
|
||||||
<ImportExportSection
|
|
||||||
status={importStatus}
|
|
||||||
selectedFile={selectedFile}
|
|
||||||
errorMessage={errorMessage}
|
|
||||||
backupId={backupId}
|
|
||||||
isImporting={isImporting}
|
|
||||||
onSelectFile={selectImportFile}
|
|
||||||
onImport={importConfig}
|
|
||||||
onExport={exportConfig}
|
|
||||||
onClear={clearSelection}
|
|
||||||
/>
|
|
||||||
<div className="pt-6 border-t border-gray-200 dark:border-white/10">
|
|
||||||
<Button
|
|
||||||
onClick={handleSave}
|
|
||||||
className="w-full"
|
|
||||||
disabled={isSaving}
|
|
||||||
>
|
|
||||||
{isSaving ? (
|
|
||||||
<span className="inline-flex items-center gap-2">
|
|
||||||
<Loader2 className="h-4 w-4 animate-spin" />
|
|
||||||
{t("settings.saving")}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Save className="mr-2 h-4 w-4" />
|
|
||||||
{t("common.save")}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</TabsContent>
|
|
||||||
|
|
||||||
<TabsContent value="about" className="mt-0">
|
|
||||||
<AboutSection isPortable={isPortable} />
|
|
||||||
</TabsContent>
|
|
||||||
</div>
|
|
||||||
</Tabs>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Dialog
|
|
||||||
open={showRestartPrompt}
|
|
||||||
onOpenChange={(open) => !open && handleRestartLater()}
|
|
||||||
>
|
|
||||||
<DialogContent
|
|
||||||
zIndex="alert"
|
|
||||||
className="max-w-md glass border-white/10"
|
|
||||||
>
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>{t("settings.restartRequired")}</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
<div className="px-6">
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("settings.restartRequiredMessage")}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<DialogFooter>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={handleRestartLater}
|
|
||||||
className="hover:bg-white/5"
|
|
||||||
>
|
|
||||||
{t("settings.restartLater")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={handleRestartNow}
|
|
||||||
className="bg-primary hover:bg-primary/90"
|
|
||||||
>
|
|
||||||
{t("settings.restartNow")}
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -19,13 +19,6 @@ export function WindowSettings({ settings, onChange }: WindowSettingsProps) {
|
|||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<ToggleRow
|
|
||||||
title={t("settings.launchOnStartup")}
|
|
||||||
description={t("settings.launchOnStartupDescription")}
|
|
||||||
checked={!!settings.launchOnStartup}
|
|
||||||
onCheckedChange={(value) => onChange({ launchOnStartup: value })}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ToggleRow
|
<ToggleRow
|
||||||
title={t("settings.minimizeToTray")}
|
title={t("settings.minimizeToTray")}
|
||||||
description={t("settings.minimizeToTrayDescription")}
|
description={t("settings.minimizeToTrayDescription")}
|
||||||
|
|||||||
@@ -1,219 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Label } from "@/components/ui/label";
|
|
||||||
import { Trash2, ExternalLink, Plus } from "lucide-react";
|
|
||||||
import { settingsApi } from "@/lib/api";
|
|
||||||
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
|
||||||
import type { Skill, SkillRepo } from "@/lib/api/skills";
|
|
||||||
|
|
||||||
interface RepoManagerPanelProps {
|
|
||||||
repos: SkillRepo[];
|
|
||||||
skills: Skill[];
|
|
||||||
onAdd: (repo: SkillRepo) => Promise<void>;
|
|
||||||
onRemove: (owner: string, name: string) => Promise<void>;
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function RepoManagerPanel({
|
|
||||||
repos,
|
|
||||||
skills,
|
|
||||||
onAdd,
|
|
||||||
onRemove,
|
|
||||||
onClose,
|
|
||||||
}: RepoManagerPanelProps) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [repoUrl, setRepoUrl] = useState("");
|
|
||||||
const [branch, setBranch] = useState("");
|
|
||||||
const [skillsPath, setSkillsPath] = useState("");
|
|
||||||
const [error, setError] = useState("");
|
|
||||||
|
|
||||||
const getSkillCount = (repo: SkillRepo) =>
|
|
||||||
skills.filter(
|
|
||||||
(skill) =>
|
|
||||||
skill.repoOwner === repo.owner &&
|
|
||||||
skill.repoName === repo.name &&
|
|
||||||
(skill.repoBranch || "main") === (repo.branch || "main"),
|
|
||||||
).length;
|
|
||||||
|
|
||||||
const parseRepoUrl = (
|
|
||||||
url: string,
|
|
||||||
): { owner: string; name: string } | null => {
|
|
||||||
let cleaned = url.trim();
|
|
||||||
cleaned = cleaned.replace(/^https?:\/\/github\.com\//, "");
|
|
||||||
cleaned = cleaned.replace(/\.git$/, "");
|
|
||||||
|
|
||||||
const parts = cleaned.split("/");
|
|
||||||
if (parts.length === 2 && parts[0] && parts[1]) {
|
|
||||||
return { owner: parts[0], name: parts[1] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAdd = async () => {
|
|
||||||
setError("");
|
|
||||||
|
|
||||||
const parsed = parseRepoUrl(repoUrl);
|
|
||||||
if (!parsed) {
|
|
||||||
setError(t("skills.repo.invalidUrl"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await onAdd({
|
|
||||||
owner: parsed.owner,
|
|
||||||
name: parsed.name,
|
|
||||||
branch: branch || "main",
|
|
||||||
enabled: true,
|
|
||||||
skillsPath: skillsPath.trim() || undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
setRepoUrl("");
|
|
||||||
setBranch("");
|
|
||||||
setSkillsPath("");
|
|
||||||
} catch (e) {
|
|
||||||
setError(e instanceof Error ? e.message : t("skills.repo.addFailed"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenRepo = async (owner: string, name: string) => {
|
|
||||||
try {
|
|
||||||
await settingsApi.openExternal(`https://github.com/${owner}/${name}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to open URL:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FullScreenPanel
|
|
||||||
isOpen={true}
|
|
||||||
title={t("skills.repo.title")}
|
|
||||||
onClose={onClose}
|
|
||||||
>
|
|
||||||
{/* 添加仓库表单 */}
|
|
||||||
<div className="space-y-4 glass rounded-xl p-6 border border-white/10">
|
|
||||||
<h3 className="text-base font-semibold text-foreground">
|
|
||||||
添加技能仓库
|
|
||||||
</h3>
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="repo-url" className="text-foreground">
|
|
||||||
{t("skills.repo.url")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="repo-url"
|
|
||||||
placeholder={t("skills.repo.urlPlaceholder")}
|
|
||||||
value={repoUrl}
|
|
||||||
onChange={(e) => setRepoUrl(e.target.value)}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="branch" className="text-foreground">
|
|
||||||
{t("skills.repo.branch")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="branch"
|
|
||||||
placeholder={t("skills.repo.branchPlaceholder")}
|
|
||||||
value={branch}
|
|
||||||
onChange={(e) => setBranch(e.target.value)}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label htmlFor="skills-path" className="text-foreground">
|
|
||||||
{t("skills.repo.path")}
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="skills-path"
|
|
||||||
placeholder={t("skills.repo.pathPlaceholder")}
|
|
||||||
value={skillsPath}
|
|
||||||
onChange={(e) => setSkillsPath(e.target.value)}
|
|
||||||
className="mt-2"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{error && (
|
|
||||||
<p className="text-sm text-red-600 dark:text-red-400">{error}</p>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
onClick={handleAdd}
|
|
||||||
className="bg-primary text-primary-foreground hover:bg-primary/90"
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
<Plus className="h-4 w-4 mr-2" />
|
|
||||||
{t("skills.repo.add")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 仓库列表 */}
|
|
||||||
<div className="space-y-4">
|
|
||||||
<h3 className="text-base font-semibold text-foreground">
|
|
||||||
{t("skills.repo.list")}
|
|
||||||
</h3>
|
|
||||||
{repos.length === 0 ? (
|
|
||||||
<div className="text-center py-12 glass rounded-xl border border-white/10">
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{t("skills.repo.empty")}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-3">
|
|
||||||
{repos.map((repo) => (
|
|
||||||
<div
|
|
||||||
key={`${repo.owner}/${repo.name}`}
|
|
||||||
className="flex items-center justify-between rounded-xl border border-white/10 bg-gray-900/40 px-4 py-3"
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<div className="text-sm font-medium text-foreground">
|
|
||||||
{repo.owner}/{repo.name}
|
|
||||||
</div>
|
|
||||||
<div className="mt-1 text-xs text-muted-foreground">
|
|
||||||
{t("skills.repo.branch")}: {repo.branch || "main"}
|
|
||||||
{repo.skillsPath && (
|
|
||||||
<>
|
|
||||||
<span className="mx-2">•</span>
|
|
||||||
{t("skills.repo.path")}: {repo.skillsPath}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<span className="ml-3 inline-flex items-center rounded-full border border-border-default px-2 py-0.5 text-[11px]">
|
|
||||||
{t("skills.repo.skillCount", {
|
|
||||||
count: getSkillCount(repo),
|
|
||||||
})}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
type="button"
|
|
||||||
onClick={() => handleOpenRepo(repo.owner, repo.name)}
|
|
||||||
title={t("common.view", { defaultValue: "查看" })}
|
|
||||||
className="hover:bg-black/5 dark:hover:bg-white/5"
|
|
||||||
>
|
|
||||||
<ExternalLink className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
type="button"
|
|
||||||
onClick={() => onRemove(repo.owner, repo.name)}
|
|
||||||
title={t("common.delete")}
|
|
||||||
className="hover:text-red-500 hover:bg-red-100 dark:hover:text-red-400 dark:hover:bg-red-500/10"
|
|
||||||
>
|
|
||||||
<Trash2 className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</FullScreenPanel>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -57,8 +57,7 @@ export function SkillCard({ skill, onInstall, onUninstall }: SkillCardProps) {
|
|||||||
skill.directory.trim().toLowerCase() !== skill.name.trim().toLowerCase();
|
skill.directory.trim().toLowerCase() !== skill.name.trim().toLowerCase();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="glass flex flex-col h-full border border-white/10 bg-gray-900/40 transition-all duration-300 hover:bg-gray-900/60 hover:border-white/20 hover:shadow-lg group relative overflow-hidden">
|
<Card className="flex flex-col h-full border-border-default bg-card transition-[border-color,box-shadow] duration-200 hover:border-border-hover hover:shadow-md">
|
||||||
<div className="absolute inset-0 bg-gradient-to-br from-primary/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500 pointer-events-none" />
|
|
||||||
<CardHeader className="pb-3">
|
<CardHeader className="pb-3">
|
||||||
<div className="flex items-start justify-between gap-2">
|
<div className="flex items-start justify-between gap-2">
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
@@ -96,7 +95,7 @@ export function SkillCard({ skill, onInstall, onUninstall }: SkillCardProps) {
|
|||||||
{skill.description || t("skills.noDescription")}
|
{skill.description || t("skills.noDescription")}
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter className="flex gap-2 pt-3 border-t border-white/5 relative z-10">
|
<CardFooter className="flex gap-2 pt-3 border-t border-border-default">
|
||||||
{skill.readmeUrl && (
|
{skill.readmeUrl && (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
|
|||||||
@@ -1,47 +1,22 @@
|
|||||||
import {
|
import { useState, useEffect } from "react";
|
||||||
useState,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
forwardRef,
|
|
||||||
useImperativeHandle,
|
|
||||||
} from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { RefreshCw, Settings } from "lucide-react";
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { RefreshCw, Search } from "lucide-react";
|
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { SkillCard } from "./SkillCard";
|
import { SkillCard } from "./SkillCard";
|
||||||
import { RepoManagerPanel } from "./RepoManagerPanel";
|
import { RepoManager } from "./RepoManager";
|
||||||
import { skillsApi, type Skill, type SkillRepo } from "@/lib/api/skills";
|
import { skillsApi, type Skill, type SkillRepo } from "@/lib/api/skills";
|
||||||
import { formatSkillError } from "@/lib/errors/skillErrorParser";
|
|
||||||
|
|
||||||
interface SkillsPageProps {
|
interface SkillsPageProps {
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SkillsPageHandle {
|
export function SkillsPage({ onClose: _onClose }: SkillsPageProps = {}) {
|
||||||
refresh: () => void;
|
|
||||||
openRepoManager: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|
||||||
({ onClose: _onClose }, ref) => {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [skills, setSkills] = useState<Skill[]>([]);
|
const [skills, setSkills] = useState<Skill[]>([]);
|
||||||
const [repos, setRepos] = useState<SkillRepo[]>([]);
|
const [repos, setRepos] = useState<SkillRepo[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [repoManagerOpen, setRepoManagerOpen] = useState(false);
|
const [repoManagerOpen, setRepoManagerOpen] = useState(false);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
|
||||||
const [filterStatus, setFilterStatus] = useState<
|
|
||||||
"all" | "installed" | "uninstalled"
|
|
||||||
>("all");
|
|
||||||
|
|
||||||
const loadSkills = async (afterLoad?: (data: Skill[]) => void) => {
|
const loadSkills = async (afterLoad?: (data: Skill[]) => void) => {
|
||||||
try {
|
try {
|
||||||
@@ -52,22 +27,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
afterLoad(data);
|
afterLoad(data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
toast.error(t("skills.loadFailed"), {
|
||||||
error instanceof Error ? error.message : String(error);
|
description: error instanceof Error ? error.message : t("common.error"),
|
||||||
|
|
||||||
// 传入 "skills.loadFailed" 作为标题
|
|
||||||
const { title, description } = formatSkillError(
|
|
||||||
errorMessage,
|
|
||||||
t,
|
|
||||||
"skills.loadFailed",
|
|
||||||
);
|
|
||||||
|
|
||||||
toast.error(title, {
|
|
||||||
description,
|
|
||||||
duration: 8000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.error("Load skills failed:", error);
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -86,36 +48,14 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
Promise.all([loadSkills(), loadRepos()]);
|
Promise.all([loadSkills(), loadRepos()]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
|
||||||
refresh: () => loadSkills(),
|
|
||||||
openRepoManager: () => setRepoManagerOpen(true),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const handleInstall = async (directory: string) => {
|
const handleInstall = async (directory: string) => {
|
||||||
try {
|
try {
|
||||||
await skillsApi.install(directory);
|
await skillsApi.install(directory);
|
||||||
toast.success(t("skills.installSuccess", { name: directory }));
|
toast.success(t("skills.installSuccess", { name: directory }));
|
||||||
await loadSkills();
|
await loadSkills();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
toast.error(t("skills.installFailed"), {
|
||||||
error instanceof Error ? error.message : String(error);
|
description: error instanceof Error ? error.message : t("common.error"),
|
||||||
|
|
||||||
// 使用错误解析器格式化错误,传入 "skills.installFailed"
|
|
||||||
const { title, description } = formatSkillError(
|
|
||||||
errorMessage,
|
|
||||||
t,
|
|
||||||
"skills.installFailed",
|
|
||||||
);
|
|
||||||
|
|
||||||
toast.error(title, {
|
|
||||||
description,
|
|
||||||
duration: 10000, // 延长显示时间让用户看清
|
|
||||||
});
|
|
||||||
|
|
||||||
console.error("Install skill failed:", {
|
|
||||||
directory,
|
|
||||||
error,
|
|
||||||
message: errorMessage,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -126,25 +66,8 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
toast.success(t("skills.uninstallSuccess", { name: directory }));
|
toast.success(t("skills.uninstallSuccess", { name: directory }));
|
||||||
await loadSkills();
|
await loadSkills();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
toast.error(t("skills.uninstallFailed"), {
|
||||||
error instanceof Error ? error.message : String(error);
|
description: error instanceof Error ? error.message : t("common.error"),
|
||||||
|
|
||||||
// 使用错误解析器格式化错误,传入 "skills.uninstallFailed"
|
|
||||||
const { title, description } = formatSkillError(
|
|
||||||
errorMessage,
|
|
||||||
t,
|
|
||||||
"skills.uninstallFailed",
|
|
||||||
);
|
|
||||||
|
|
||||||
toast.error(title, {
|
|
||||||
description,
|
|
||||||
duration: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
console.error("Uninstall skill failed:", {
|
|
||||||
directory,
|
|
||||||
error,
|
|
||||||
message: errorMessage,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -180,37 +103,45 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
await Promise.all([loadRepos(), loadSkills()]);
|
await Promise.all([loadRepos(), loadSkills()]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 过滤技能列表
|
|
||||||
const filteredSkills = useMemo(() => {
|
|
||||||
const byStatus = skills.filter((skill) => {
|
|
||||||
if (filterStatus === "installed") return skill.installed;
|
|
||||||
if (filterStatus === "uninstalled") return !skill.installed;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!searchQuery.trim()) return byStatus;
|
|
||||||
|
|
||||||
const query = searchQuery.toLowerCase();
|
|
||||||
return byStatus.filter((skill) => {
|
|
||||||
const name = skill.name?.toLowerCase() || "";
|
|
||||||
const description = skill.description?.toLowerCase() || "";
|
|
||||||
const directory = skill.directory?.toLowerCase() || "";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
name.includes(query) ||
|
<div className="flex flex-col h-full min-h-0 bg-background">
|
||||||
description.includes(query) ||
|
{/* 顶部操作栏(固定区域) */}
|
||||||
directory.includes(query)
|
<div className="flex-shrink-0 border-b border-border-default bg-muted/20 px-6 py-4">
|
||||||
);
|
<div className="flex items-center justify-between pr-8">
|
||||||
});
|
<h1 className="text-lg font-semibold leading-tight tracking-tight text-gray-900 dark:text-gray-100">
|
||||||
}, [skills, searchQuery, filterStatus]);
|
{t("skills.title")}
|
||||||
|
</h1>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
variant="mcp"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => loadSkills()}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<RefreshCw
|
||||||
|
className={`h-4 w-4 mr-2 ${loading ? "animate-spin" : ""}`}
|
||||||
|
/>
|
||||||
|
{loading ? t("skills.refreshing") : t("skills.refresh")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="mcp"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setRepoManagerOpen(true)}
|
||||||
|
>
|
||||||
|
<Settings className="h-4 w-4 mr-2" />
|
||||||
|
{t("skills.repoManager")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
return (
|
{/* 描述 */}
|
||||||
<div className="flex flex-col h-full min-h-0 bg-background/50">
|
<p className="mt-1.5 text-sm text-gray-500 dark:text-gray-400">
|
||||||
{/* 顶部操作栏(固定区域)已移除,由 App.tsx 接管 */}
|
{t("skills.description")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* 技能网格(可滚动详情区域) */}
|
{/* 技能网格(可滚动详情区域) */}
|
||||||
<div className="flex-1 min-h-0 overflow-y-auto animate-fade-in">
|
<div className="flex-1 min-h-0 overflow-y-auto px-6 py-6 bg-muted/10">
|
||||||
<div className="mx-auto max-w-[56rem] px-6 py-4">
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="flex items-center justify-center h-64">
|
<div className="flex items-center justify-center h-64">
|
||||||
<RefreshCw className="h-8 w-8 animate-spin text-muted-foreground" />
|
<RefreshCw className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||||
@@ -231,77 +162,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
{t("skills.addRepo")}
|
{t("skills.addRepo")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{/* 搜索框 */}
|
|
||||||
<div className="mb-6 flex flex-col gap-3 md:flex-row md:items-center">
|
|
||||||
<div className="relative flex-1 min-w-0">
|
|
||||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
placeholder={t("skills.searchPlaceholder")}
|
|
||||||
value={searchQuery}
|
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
|
||||||
className="pl-9 pr-3"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="w-full md:w-48">
|
|
||||||
<Select
|
|
||||||
value={filterStatus}
|
|
||||||
onValueChange={(val) =>
|
|
||||||
setFilterStatus(
|
|
||||||
val as "all" | "installed" | "uninstalled",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="bg-card border shadow-sm text-foreground">
|
|
||||||
<SelectValue
|
|
||||||
placeholder={t("skills.filter.placeholder")}
|
|
||||||
className="text-left"
|
|
||||||
/>
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent className="bg-card text-foreground shadow-lg">
|
|
||||||
<SelectItem
|
|
||||||
value="all"
|
|
||||||
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
|
||||||
>
|
|
||||||
{t("skills.filter.all")}
|
|
||||||
</SelectItem>
|
|
||||||
<SelectItem
|
|
||||||
value="installed"
|
|
||||||
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
|
||||||
>
|
|
||||||
{t("skills.filter.installed")}
|
|
||||||
</SelectItem>
|
|
||||||
<SelectItem
|
|
||||||
value="uninstalled"
|
|
||||||
className="text-left pr-3 [&[data-state=checked]>span]:hidden"
|
|
||||||
>
|
|
||||||
{t("skills.filter.uninstalled")}
|
|
||||||
</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
{searchQuery && (
|
|
||||||
<p className="mt-2 text-sm text-muted-foreground">
|
|
||||||
{t("skills.count", { count: filteredSkills.length })}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 技能列表或无结果提示 */}
|
|
||||||
{filteredSkills.length === 0 ? (
|
|
||||||
<div className="flex flex-col items-center justify-center h-48 text-center">
|
|
||||||
<p className="text-lg font-medium text-gray-900 dark:text-gray-100">
|
|
||||||
{t("skills.noResults")}
|
|
||||||
</p>
|
|
||||||
<p className="mt-2 text-sm text-gray-500 dark:text-gray-400">
|
|
||||||
{t("skills.emptyDescription")}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
{filteredSkills.map((skill) => (
|
{skills.map((skill) => (
|
||||||
<SkillCard
|
<SkillCard
|
||||||
key={skill.key}
|
key={skill.key}
|
||||||
skill={skill}
|
skill={skill}
|
||||||
@@ -311,24 +174,17 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 仓库管理面板 */}
|
{/* 仓库管理对话框 */}
|
||||||
{repoManagerOpen && (
|
<RepoManager
|
||||||
<RepoManagerPanel
|
open={repoManagerOpen}
|
||||||
|
onOpenChange={setRepoManagerOpen}
|
||||||
repos={repos}
|
repos={repos}
|
||||||
skills={skills}
|
skills={skills}
|
||||||
onAdd={handleAddRepo}
|
onAdd={handleAddRepo}
|
||||||
onRemove={handleRemoveRepo}
|
onRemove={handleRemoveRepo}
|
||||||
onClose={() => setRepoManagerOpen(false)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
|
||||||
|
|
||||||
SkillsPage.displayName = "SkillsPage";
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||||
|
import { X } from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Dialog = DialogPrimitive.Root;
|
const Dialog = DialogPrimitive.Root;
|
||||||
@@ -13,14 +14,13 @@ const DialogClose = DialogPrimitive.Close;
|
|||||||
const DialogOverlay = React.forwardRef<
|
const DialogOverlay = React.forwardRef<
|
||||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> & {
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> & {
|
||||||
zIndex?: "base" | "nested" | "alert" | "top";
|
zIndex?: "base" | "nested" | "alert";
|
||||||
}
|
}
|
||||||
>(({ className, zIndex = "base", ...props }, ref) => {
|
>(({ className, zIndex = "base", ...props }, ref) => {
|
||||||
const zIndexMap = {
|
const zIndexMap = {
|
||||||
base: "z-40",
|
base: "z-40",
|
||||||
nested: "z-50",
|
nested: "z-50",
|
||||||
alert: "z-[60]",
|
alert: "z-[60]",
|
||||||
top: "z-[110]",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -40,54 +40,36 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|||||||
const DialogContent = React.forwardRef<
|
const DialogContent = React.forwardRef<
|
||||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
||||||
zIndex?: "base" | "nested" | "alert" | "top";
|
zIndex?: "base" | "nested" | "alert";
|
||||||
variant?: "default" | "fullscreen";
|
|
||||||
overlayClassName?: string;
|
|
||||||
}
|
}
|
||||||
>(
|
>(({ className, children, zIndex = "base", ...props }, ref) => {
|
||||||
(
|
|
||||||
{
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
zIndex = "base",
|
|
||||||
variant = "default",
|
|
||||||
overlayClassName,
|
|
||||||
...props
|
|
||||||
},
|
|
||||||
ref,
|
|
||||||
) => {
|
|
||||||
const zIndexMap = {
|
const zIndexMap = {
|
||||||
base: "z-40",
|
base: "z-40",
|
||||||
nested: "z-50",
|
nested: "z-50",
|
||||||
alert: "z-[60]",
|
alert: "z-[60]",
|
||||||
top: "z-[110]",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const variantClass = {
|
|
||||||
default:
|
|
||||||
"fixed left-1/2 top-1/2 flex flex-col w-full max-w-lg max-h-[90vh] translate-x-[-50%] translate-y-[-50%] border border-border-default bg-background text-foreground shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
||||||
fullscreen:
|
|
||||||
"fixed inset-0 flex flex-col w-screen h-screen translate-x-0 translate-y-0 bg-background text-foreground p-0 sm:rounded-none shadow-none",
|
|
||||||
}[variant];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogPortal>
|
<DialogPortal>
|
||||||
<DialogOverlay zIndex={zIndex} className={overlayClassName} />
|
<DialogOverlay zIndex={zIndex} />
|
||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(variantClass, zIndexMap[zIndex], className)}
|
className={cn(
|
||||||
onInteractOutside={(e) => {
|
"fixed left-1/2 top-1/2 flex flex-col w-full max-w-lg max-h-[90vh] translate-x-[-50%] translate-y-[-50%] border border-border-default bg-white dark:bg-gray-900 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||||
// 防止点击遮罩层关闭对话框
|
zIndexMap[zIndex],
|
||||||
e.preventDefault();
|
className,
|
||||||
}}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none">
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
<span className="sr-only">关闭</span>
|
||||||
|
</DialogPrimitive.Close>
|
||||||
</DialogPrimitive.Content>
|
</DialogPrimitive.Content>
|
||||||
</DialogPortal>
|
</DialogPortal>
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||||
|
|
||||||
const DialogHeader = ({
|
const DialogHeader = ({
|
||||||
|
|||||||
@@ -40,9 +40,6 @@ export interface ProviderPreset {
|
|||||||
endpointCandidates?: string[];
|
endpointCandidates?: string[];
|
||||||
// 新增:视觉主题配置
|
// 新增:视觉主题配置
|
||||||
theme?: PresetTheme;
|
theme?: PresetTheme;
|
||||||
// 图标配置
|
|
||||||
icon?: string; // 图标名称
|
|
||||||
iconColor?: string; // 图标颜色
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const providerPresets: ProviderPreset[] = [
|
export const providerPresets: ProviderPreset[] = [
|
||||||
@@ -59,8 +56,6 @@ export const providerPresets: ProviderPreset[] = [
|
|||||||
backgroundColor: "#D97757",
|
backgroundColor: "#D97757",
|
||||||
textColor: "#FFFFFF",
|
textColor: "#FFFFFF",
|
||||||
},
|
},
|
||||||
icon: "anthropic",
|
|
||||||
iconColor: "#D4915D",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "DeepSeek",
|
name: "DeepSeek",
|
||||||
@@ -235,23 +230,6 @@ export const providerPresets: ProviderPreset[] = [
|
|||||||
},
|
},
|
||||||
category: "cn_official",
|
category: "cn_official",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "DouBaoSeed",
|
|
||||||
websiteUrl: "https://www.volcengine.com/product/doubao",
|
|
||||||
apiKeyUrl: "https://www.volcengine.com/product/doubao",
|
|
||||||
settingsConfig: {
|
|
||||||
env: {
|
|
||||||
ANTHROPIC_BASE_URL: "https://ark.cn-beijing.volces.com/api/coding",
|
|
||||||
ANTHROPIC_AUTH_TOKEN: "",
|
|
||||||
API_TIMEOUT_MS: "3000000",
|
|
||||||
ANTHROPIC_MODEL: "doubao-seed-code-preview-latest",
|
|
||||||
ANTHROPIC_DEFAULT_SONNET_MODEL: "doubao-seed-code-preview-latest",
|
|
||||||
ANTHROPIC_DEFAULT_OPUS_MODEL: "doubao-seed-code-preview-latest",
|
|
||||||
ANTHROPIC_DEFAULT_HAIKU_MODEL: "doubao-seed-code-preview-latest",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
category: "cn_official",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "BaiLing",
|
name: "BaiLing",
|
||||||
websiteUrl: "https://alipaytbox.yuque.com/sxs0ba/ling/get_started",
|
websiteUrl: "https://alipaytbox.yuque.com/sxs0ba/ling/get_started",
|
||||||
@@ -316,4 +294,22 @@ export const providerPresets: ProviderPreset[] = [
|
|||||||
isPartner: true, // 合作伙伴
|
isPartner: true, // 合作伙伴
|
||||||
partnerPromotionKey: "packycode", // 促销信息 i18n key
|
partnerPromotionKey: "packycode", // 促销信息 i18n key
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "AnyRouter",
|
||||||
|
websiteUrl: "https://anyrouter.top",
|
||||||
|
apiKeyUrl: "https://anyrouter.top/register?aff=PCel",
|
||||||
|
settingsConfig: {
|
||||||
|
env: {
|
||||||
|
ANTHROPIC_BASE_URL: "https://anyrouter.top",
|
||||||
|
ANTHROPIC_AUTH_TOKEN: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 请求地址候选(用于地址管理/测速)
|
||||||
|
endpointCandidates: [
|
||||||
|
"https://q.quuvv.cn",
|
||||||
|
"https://pmpjfbhq.cn-nb1.rainapp.top",
|
||||||
|
"https://anyrouter.top",
|
||||||
|
],
|
||||||
|
category: "third_party",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -143,4 +143,20 @@ requires_openai_auth = true`,
|
|||||||
isPartner: true, // 合作伙伴
|
isPartner: true, // 合作伙伴
|
||||||
partnerPromotionKey: "packycode", // 促销信息 i18n key
|
partnerPromotionKey: "packycode", // 促销信息 i18n key
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "AnyRouter",
|
||||||
|
websiteUrl: "https://anyrouter.top",
|
||||||
|
category: "third_party",
|
||||||
|
auth: generateThirdPartyAuth(""),
|
||||||
|
config: generateThirdPartyConfig(
|
||||||
|
"anyrouter",
|
||||||
|
"https://anyrouter.top/v1",
|
||||||
|
"gpt-5-codex",
|
||||||
|
),
|
||||||
|
endpointCandidates: [
|
||||||
|
"https://anyrouter.top/v1",
|
||||||
|
"https://q.quuvv.cn/v1",
|
||||||
|
"https://pmpjfbhq.cn-nb1.rainapp.top/v1",
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user