## 主要变更
- 移除所有Claude命令调用和进程管理逻辑
- 简化检测函数,暂时返回"功能开发中"状态
- 添加单独检查状态按钮和相关UI交互
- 保留完整的供应商管理功能(添加、编辑、删除、切换)
## 技术优化
- 删除复杂的超时机制、进程监听、错误处理
- 移除axios依赖和HTTP请求相关代码
- 清理竞态条件和队列管理逻辑
- 保持清晰的UI状态管理
## UI改进
- 添加橙色主题的单独检查按钮
- 增强检查状态的视觉反馈(🔄 进度指示器)
- 保留所有状态显示逻辑等待功能重新实现
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import fs from 'fs/promises'
|
|
import path from 'path'
|
|
import os from 'os'
|
|
import { Provider, ProviderStatus } from '../shared/types'
|
|
|
|
export async function checkProviderStatus(
|
|
provider: Provider
|
|
): Promise<ProviderStatus> {
|
|
// 暂时返回未检查状态
|
|
return {
|
|
isOnline: false,
|
|
responseTime: -1,
|
|
lastChecked: new Date(),
|
|
error: '功能开发中'
|
|
}
|
|
}
|
|
|
|
export function getClaudeCodeConfig() {
|
|
// Claude Code 配置文件路径
|
|
const configDir = path.join(os.homedir(), '.claude')
|
|
const configPath = path.join(configDir, 'settings.json')
|
|
|
|
return { path: configPath, dir: configDir }
|
|
}
|
|
|
|
export async function switchProvider(provider: Provider): Promise<boolean> {
|
|
try {
|
|
const { path: configPath, dir: configDir } = getClaudeCodeConfig()
|
|
|
|
// 确保目录存在
|
|
await fs.mkdir(configDir, { recursive: true })
|
|
|
|
// 读取现有配置
|
|
let config: any = {}
|
|
try {
|
|
const content = await fs.readFile(configPath, 'utf-8')
|
|
config = JSON.parse(content)
|
|
} catch {
|
|
// 文件不存在或解析失败,使用空配置
|
|
}
|
|
|
|
// 确保 env 对象存在
|
|
if (!config.env) {
|
|
config.env = {}
|
|
}
|
|
|
|
// 更新环境变量配置
|
|
config.env.ANTHROPIC_AUTH_TOKEN = provider.apiKey
|
|
config.env.ANTHROPIC_BASE_URL = provider.apiUrl
|
|
|
|
// 写回配置文件
|
|
await fs.writeFile(configPath, JSON.stringify(config, null, 2))
|
|
|
|
return true
|
|
} catch (error) {
|
|
console.error('切换供应商失败:', error)
|
|
return false
|
|
}
|
|
} |