Files
proxycast/docs/aiprompts/lib.md
T
cosoandClaude Sonnet 4.6 c2261961c1 refactor: 深度清理旧 UI 表面与 plugin-ui 系统
## 清理范围

### 1. Plugin UI 系统(完整删除)
- 删除 `src/lib/plugin-ui/` 整个渲染运行时
- 保留 `src/lib/api/pluginUI.ts` 元数据 API
- 删除 `docs/plugin-ui-design.md` 设计文档
- 清理 i18n 中的 PluginUIRenderer 引用

### 2. Provider Pool 旧凭证表单链
- 删除 `AntigravityFormStandalone.tsx`
- 删除 `ClaudeFormStandalone.tsx`
- 删除 `GeminiFormStandalone.tsx`
- 删除 `KiroFormStandalone.tsx`
- 删除 `provider-pool/credential-forms/index.ts`

### 3. Agent Chat 旧兼容壳
- 删除 `StableProcessingNotice.tsx`
- 删除 `useStableProcessingNotice.ts`
- 删除固定的 `agent/chat/config.ts`
- 更新治理目录册与守卫

### 4. 更深层 dead UI 组件
- 删除 `ui/alert.tsx`
- 删除 `ui/radio-group.tsx`
- 删除 `ui/separator.tsx`
- 删除 `model-selector/` 整个目录
- 删除 `smart-input/` 整个目录
- 删除 `subagent/` 目录
- 删除 `websocket/` 目录
- 删除 `solutions/ecommerce-review-reply/` 整个目录

### 5. 其他清理
- 删除 `src-tauri/crates/services/src/switch.rs`
- 删除 `src-tauri/src/commands/switch_cmd.rs`
- 删除零入口 barrel 文件
- 同步更新文档与测试

## 验证通过

- ✅ 治理报告:零引用候选 0,分类漂移候选 0,边界违规 0
- ✅ 契约验证:619 frontend commands, 697 rust commands
- ✅ 治理测试:75 个测试全绿

## 影响统计

- 126 个文件变更
- +2566 行, -14468 行
- 净减少约 12000 行代码

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:19:15 +08:00

2.2 KiB

工具库

概述

前端工具库和 API 封装层。

目录结构

src/lib/
├── api/                # API 封装
│   ├── apiKeyProvider.ts
│   └── pluginUI.ts     # 插件元数据 API
├── config/             # 配置
│   └── providers.ts
├── types/              # 类型定义
│   └── provider.ts
├── errors/             # 错误处理
│   └── playwrightErrors.ts
├── tauri/              # Tauri 命令封装
├── utils/              # 工具函数
├── flowEventManager.ts # 流量事件管理
├── terminal-api.ts     # 终端 API
└── utils.ts            # 通用工具

核心模块

Tauri 命令封装

// src/lib/tauri/credentials.ts
export async function addCredential(provider: string, path: string) {
    return invoke<CredentialInfo>('add_credential', { provider, filePath: path });
}

export async function listCredentials() {
    return invoke<CredentialInfo[]>('list_credentials');
}

流量事件管理

// src/lib/flowEventManager.ts
class FlowEventManager {
    private listeners: Map<string, Set<FlowEventListener>> = new Map();
    
    subscribe(event: string, listener: FlowEventListener) {
        if (!this.listeners.has(event)) {
            this.listeners.set(event, new Set());
        }
        this.listeners.get(event)!.add(listener);
        return () => this.listeners.get(event)?.delete(listener);
    }
    
    emit(event: string, data: any) {
        this.listeners.get(event)?.forEach(listener => listener(data));
    }
}

export const flowEventManager = new FlowEventManager();

工具函数

// src/lib/utils.ts
export function cn(...classes: (string | undefined)[]) {
    return classes.filter(Boolean).join(' ');
}

export function formatBytes(bytes: number) {
    if (bytes < 1024) return `${bytes} B`;
    if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
    return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
}

export function formatDuration(ms: number) {
    if (ms < 1000) return `${ms}ms`;
    return `${(ms / 1000).toFixed(2)}s`;
}

相关文档