mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-10-24 23:31:47 +08:00
- 实现 5 步引导流程:欢迎 → 选择身份 → 选择插件 → 安装进度 → 完成 - 支持两种用户群体:程序员(预选 config-switch + flow-monitor)和普通用户 - 批量顺序安装选中的插件,显示实时进度 - 设置页添加"重新引导"按钮,可随时重新运行向导 - 重构浏览器拦截器和插件管理器代码 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 KiB
66 KiB
ProxyCast 统一扩展平台架构 PRD
版本: 1.0.0 日期: 2026-01-05 状态: Draft
一、背景与目标
1.1 背景
当前 ProxyCast 已有多种扩展能力,但分散在不同系统中:
| 现有能力 | 实现方式 | 问题 |
|---|---|---|
| Skills | 独立系统 | 与其他扩展隔离 |
| OAuth Provider | 硬编码枚举 | 新增需改核心代码 |
| API Key Provider | 数据库预设 | 无法独立更新 |
| 工具类 (MachineIdTool) | 独立插件 | 缺乏统一管理 |
1.2 目标
构建 统一扩展平台,实现:
- 多类型扩展支持:Skills、Token 供应商、OAuth 凭证、工具类等
- 服务商生态:各服务商可发布自己的扩展应用
- 统一扩展中心:一个入口管理所有类型的扩展
- 独立更新:扩展可独立安装、更新、卸载
- 开放生态:第三方开发者可贡献扩展
二、扩展类型定义
2.1 扩展类型总览
┌─────────────────────────────────────────────────────────────────────────┐
│ ProxyCast 统一扩展平台 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Skills │ │ Token │ │ OAuth │ │ Tools │ │
│ │ 技能包 │ │ 供应商 │ │ 凭证 │ │ 工具类 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Provider │ │ Protocol │ │ Theme │ │
│ │ 服务商插件 │ │ 协议扩展 │ │ 主题包 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
2.2 扩展类型详解
| 类型 | ID | 说明 | 示例 |
|---|---|---|---|
| Skills | skill |
AI 技能包,扩展 Agent 能力 | 代码审查、翻译、写作 |
| Token 供应商 | token_provider |
提供 API Key 的第三方服务 | OpenRouter、TogetherAI |
| OAuth 凭证 | oauth_provider |
第三方 OAuth 授权服务 | Kiro、Claude OAuth、Gemini |
| 工具类 | tool |
实用工具 | Machine ID、Browser Interceptor |
| 服务商插件 | vendor |
服务商官方应用 | Anthropic 官方、OpenAI 官方 |
| 协议扩展 | protocol |
新协议支持 | Doubao、Wenxin |
| 主题包 | theme |
UI 主题 | Dark Pro、Light Minimal |
三、统一扩展架构
3.1 核心架构图
┌─────────────────────────────────────────────────────────────────────────┐
│ Extension Platform Core │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ ExtensionRegistry (统一注册表) │ │
│ │ │ │
│ │ extensions: HashMap<ExtensionId, Arc<dyn Extension>> │ │
│ │ type_index: HashMap<ExtensionType, Vec<ExtensionId>> │ │
│ │ vendor_index: HashMap<VendorId, Vec<ExtensionId>> │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ ExtensionLoader (加载器) │ │
│ │ │ │
│ │ - 扫描 ~/.proxycast/extensions/ │ │
│ │ - 解析 extension.json │ │
│ │ - 加载二进制/脚本/UI │ │
│ │ - 验证签名和权限 │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ ExtensionHost (宿主环境) │ │
│ │ │ │
│ │ - 生命周期管理 (init/start/stop/unload) │ │
│ │ - 权限沙箱 │ │
│ │ - 资源隔离 │ │
│ │ - SDK 注入 │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
3.2 Extension Trait (统一接口)
/// 统一扩展接口 - 所有扩展类型的基础 trait
#[async_trait]
pub trait Extension: Send + Sync {
// ========== 基础信息 ==========
/// 扩展唯一 ID (如 "kiro-provider", "code-review-skill")
fn id(&self) -> &str;
/// 扩展类型
fn extension_type(&self) -> ExtensionType;
/// 显示名称
fn display_name(&self) -> &str;
/// 版本号
fn version(&self) -> &str;
/// 描述
fn description(&self) -> &str { "" }
/// 作者/服务商
fn vendor(&self) -> Option<&VendorInfo> { None }
/// 图标
fn icon(&self) -> Option<&str> { None }
// ========== 能力声明 ==========
/// 扩展清单
fn manifest(&self) -> &ExtensionManifest;
/// 所需权限
fn required_permissions(&self) -> Vec<Permission> { vec![] }
/// 配置 Schema (JSON Schema)
fn config_schema(&self) -> serde_json::Value { serde_json::json!({}) }
// ========== 生命周期 ==========
/// 初始化
async fn init(&mut self, ctx: &ExtensionContext) -> Result<()>;
/// 启动
async fn start(&mut self) -> Result<()> { Ok(()) }
/// 停止
async fn stop(&mut self) -> Result<()> { Ok(()) }
/// 卸载前清理
async fn unload(&mut self) -> Result<()> { Ok(()) }
// ========== 配置管理 ==========
/// 获取当前配置
fn get_config(&self) -> serde_json::Value { serde_json::json!({}) }
/// 更新配置
async fn update_config(&mut self, config: serde_json::Value) -> Result<()> { Ok(()) }
}
/// 扩展类型枚举
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ExtensionType {
Skill, // AI 技能包
TokenProvider, // Token 供应商
OAuthProvider, // OAuth 凭证
Tool, // 工具类
Vendor, // 服务商插件
Protocol, // 协议扩展
Theme, // 主题包
}
/// 服务商信息
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct VendorInfo {
pub id: String, // "anthropic", "openai", "google"
pub name: String, // "Anthropic"
pub homepage: String, // "https://anthropic.com"
pub verified: bool, // 是否官方认证
pub logo: Option<String>, // Logo URL
}
3.3 扩展清单 (extension.json)
{
"$schema": "https://proxycast.dev/schemas/extension.json",
"id": "kiro-provider",
"type": "oauth_provider",
"version": "1.2.0",
"name": "Kiro Provider",
"description": "AWS CodeWhisperer OAuth 凭证管理,支持 Claude 模型",
"vendor": {
"id": "proxycast",
"name": "ProxyCast Team",
"homepage": "https://github.com/aiclientproxy",
"verified": true
},
"license": "MIT",
"homepage": "https://github.com/aiclientproxy/kiro-provider",
"repository": "https://github.com/aiclientproxy/kiro-provider",
"min_proxycast_version": "2.0.0",
"permissions": [
"database:read",
"database:write",
"http:request",
"crypto:encrypt",
"fs:read:credentials"
],
"entry": {
"type": "binary",
"binary_name": "kiro-provider-cli",
"platform_binaries": {
"macos-arm64": "bin/kiro-provider-aarch64-apple-darwin",
"macos-x64": "bin/kiro-provider-x86_64-apple-darwin",
"linux-x64": "bin/kiro-provider-x86_64-unknown-linux-gnu",
"windows-x64": "bin/kiro-provider-x86_64-pc-windows-msvc.exe"
}
},
"ui": {
"entry": "dist/index.js",
"styles": "dist/styles.css",
"surfaces": ["extension_center", "provider_pool"],
"icon": "Cloud",
"width": 800,
"height": 600
},
"config_schema": {
"type": "object",
"properties": {
"risk_control": {
"type": "object",
"properties": {
"machine_id_rotation": { "type": "boolean", "default": true },
"version_spoofing": { "type": "boolean", "default": true }
}
}
}
},
"capabilities": {
"oauth_provider": {
"target_protocol": "anthropic",
"supported_models": ["claude-*"],
"auth_types": ["oauth"],
"credential_schema": {
"type": "object",
"required": ["creds_file_path"],
"properties": {
"creds_file_path": {
"type": "string",
"title": "凭证文件路径"
}
}
}
}
},
"tags": ["oauth", "claude", "aws", "kiro"],
"categories": ["ai-provider", "authentication"]
}
四、各扩展类型详细设计
4.1 Skills (AI 技能包)
/// Skill 扩展 trait
#[async_trait]
pub trait SkillExtension: Extension {
/// 技能触发条件
fn triggers(&self) -> Vec<SkillTrigger>;
/// 系统提示词
fn system_prompt(&self) -> &str;
/// 可用工具
fn tools(&self) -> Vec<ToolDefinition> { vec![] }
/// 执行技能
async fn execute(&self, ctx: &SkillContext, input: &str) -> Result<SkillOutput>;
}
#[derive(Clone, Debug)]
pub enum SkillTrigger {
Command(String), // /review, /translate
Keyword(Vec<String>), // ["代码审查", "review"]
FileType(Vec<String>), // [".rs", ".py"]
Always, // 始终可用
}
Skill extension.json 示例:
{
"id": "code-review-skill",
"type": "skill",
"name": "代码审查",
"description": "专业的代码审查技能,支持多种语言",
"capabilities": {
"skill": {
"triggers": [
{ "type": "command", "value": "/review" },
{ "type": "keyword", "value": ["代码审查", "code review"] }
],
"supported_languages": ["rust", "python", "typescript", "go"],
"system_prompt_file": "prompts/system.md",
"tools": ["read_file", "search_code"]
}
}
}
4.2 Token Provider (Token 供应商)
/// Token 供应商扩展 trait
#[async_trait]
pub trait TokenProviderExtension: Extension {
/// 支持的模型列表
async fn list_models(&self) -> Result<Vec<ModelInfo>>;
/// 获取 API 配置
fn api_config(&self) -> &ApiConfig;
/// 验证 API Key
async fn validate_key(&self, key: &str) -> Result<ValidationResult>;
/// 获取使用量/配额
async fn get_usage(&self, key: &str) -> Result<UsageInfo>;
/// 价格信息
fn pricing(&self) -> Option<&PricingInfo> { None }
}
#[derive(Clone, Debug)]
pub struct ApiConfig {
pub base_url: String,
pub auth_header: String, // "Authorization", "x-api-key"
pub auth_prefix: String, // "Bearer ", ""
pub protocol: String, // "openai", "anthropic"
}
Token Provider extension.json 示例:
{
"id": "openrouter-provider",
"type": "token_provider",
"name": "OpenRouter",
"description": "统一 API 访问多种 AI 模型",
"vendor": {
"id": "openrouter",
"name": "OpenRouter",
"homepage": "https://openrouter.ai",
"verified": true
},
"capabilities": {
"token_provider": {
"base_url": "https://openrouter.ai/api/v1",
"protocol": "openai",
"auth_header": "Authorization",
"auth_prefix": "Bearer ",
"models_endpoint": "/models",
"supports_streaming": true,
"pricing_url": "https://openrouter.ai/docs#models"
}
}
}
4.3 OAuth Provider (OAuth 凭证)
/// OAuth 凭证扩展 trait (继承自现有设计)
#[async_trait]
pub trait OAuthProviderExtension: Extension {
/// 目标协议
fn target_protocol(&self) -> &str;
/// 支持的认证方式
fn supported_auth_types(&self) -> Vec<AuthTypeInfo>;
/// 凭证配置 Schema
fn credential_schema(&self, auth_type: &str) -> serde_json::Value;
/// 获取凭证
async fn acquire_credential(&self, model: &str) -> Result<AcquiredCredential>;
/// 释放凭证
async fn release_credential(&self, id: &str, result: UsageResult);
/// 刷新 Token
async fn refresh_token(&self, id: &str) -> Result<TokenRefreshResult>;
/// 协议转换
async fn transform_request(&self, req: &mut ChatRequest) -> Result<()>;
/// 风控适配
async fn apply_risk_control(&self, req: &mut ChatRequest, cred_id: &str) -> Result<()>;
}
4.4 Tool (工具类)
/// 工具扩展 trait
#[async_trait]
pub trait ToolExtension: Extension {
/// 工具类别
fn category(&self) -> ToolCategory;
/// 可用命令
fn commands(&self) -> Vec<ToolCommand>;
/// 执行命令
async fn execute_command(&self, cmd: &str, args: serde_json::Value) -> Result<serde_json::Value>;
/// 是否需要后台运行
fn requires_background(&self) -> bool { false }
}
#[derive(Clone, Debug)]
pub enum ToolCategory {
Security, // Machine ID, 加密工具
Network, // Browser Interceptor, 代理
Development, // 代码格式化, Lint
Utility, // 剪贴板, 截图
}
#[derive(Clone, Debug)]
pub struct ToolCommand {
pub name: String,
pub description: String,
pub args_schema: serde_json::Value,
}
Tool extension.json 示例:
{
"id": "machine-id-tool",
"type": "tool",
"name": "Machine ID 管理",
"description": "生成和管理 Machine ID,用于风控适配",
"capabilities": {
"tool": {
"category": "security",
"commands": [
{
"name": "generate",
"description": "生成新的 Machine ID",
"args": {}
},
{
"name": "list",
"description": "列出所有 Machine ID",
"args": {}
},
{
"name": "rotate",
"description": "轮换指定凭证的 Machine ID",
"args": {
"credential_id": { "type": "string", "required": true }
}
}
],
"background_service": false
}
}
}
4.5 Vendor (服务商插件)
/// 服务商插件 trait - 聚合多种能力
#[async_trait]
pub trait VendorExtension: Extension {
/// 服务商提供的子扩展
fn sub_extensions(&self) -> Vec<SubExtensionInfo>;
/// 服务商特有功能
fn vendor_features(&self) -> Vec<VendorFeature>;
/// 官方文档链接
fn documentation_url(&self) -> Option<&str> { None }
/// 状态页面
fn status_page_url(&self) -> Option<&str> { None }
}
#[derive(Clone, Debug)]
pub struct SubExtensionInfo {
pub id: String,
pub extension_type: ExtensionType,
pub name: String,
}
#[derive(Clone, Debug)]
pub struct VendorFeature {
pub id: String,
pub name: String,
pub description: String,
}
Vendor extension.json 示例:
{
"id": "anthropic-official",
"type": "vendor",
"name": "Anthropic 官方",
"description": "Anthropic 官方扩展包,包含 API Key 和 OAuth 支持",
"vendor": {
"id": "anthropic",
"name": "Anthropic",
"homepage": "https://anthropic.com",
"verified": true,
"logo": "https://anthropic.com/logo.png"
},
"capabilities": {
"vendor": {
"sub_extensions": [
{
"id": "claude-api",
"type": "token_provider",
"name": "Claude API Key"
},
{
"id": "claude-oauth",
"type": "oauth_provider",
"name": "Claude OAuth"
}
],
"features": [
{
"id": "prompt_caching",
"name": "Prompt Caching",
"description": "缓存系统提示词,降低成本"
},
{
"id": "batch_api",
"name": "Batch API",
"description": "批量处理请求,50% 折扣"
}
],
"documentation": "https://docs.anthropic.com",
"status_page": "https://status.anthropic.com"
}
}
}
4.6 Protocol (协议扩展)
/// 协议扩展 trait
#[async_trait]
pub trait ProtocolExtension: Extension {
/// 协议 ID
fn protocol_id(&self) -> &str;
/// 格式化请求
fn format_request(&self, req: &ChatRequest) -> Result<serde_json::Value>;
/// 解析响应
fn parse_response(&self, resp: &serde_json::Value) -> Result<ChatResponse>;
/// 解析流式响应
fn parse_stream_chunk(&self, chunk: &[u8]) -> Result<Option<ChatChunk>>;
/// 错误解析
fn parse_error(&self, status: u16, body: &str) -> ProviderError;
}
Protocol extension.json 示例:
{
"id": "doubao-protocol",
"type": "protocol",
"name": "豆包协议",
"description": "字节跳动豆包 API 协议支持",
"capabilities": {
"protocol": {
"protocol_id": "doubao",
"base_compatible": "openai",
"differences": [
"model 字段格式不同",
"流式响应格式略有差异"
],
"documentation": "https://www.volcengine.com/docs/82379"
}
}
}
五、扩展中心 UI 设计
5.1 统一入口
┌─────────────────────────────────────────────────────────────────────────┐
│ 扩展中心 (Extension Center) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 🔍 搜索扩展... [+ 安装扩展] [⚙️] │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ │
│ │ 全部 │ Skills │ Token │ OAuth │ 工具 │ 服务商 │ │
│ │ (23) │ (5) │ (8) │ (4) │ (3) │ (3) │ │
│ └─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 已安装扩展 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ 🔌 Kiro Provider v1.2.0 │ │ │
│ │ │ OAuth 凭证 · ProxyCast Team │ │ │
│ │ │ AWS CodeWhisperer OAuth 凭证管理 │ │ │
│ │ │ │ │ │
│ │ │ [● 已启用] [配置] [更新可用 ↑] [卸载] │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ 🛠️ Machine ID Tool v0.3.0 │ │ │
│ │ │ 工具 · ProxyCast Team │ │ │
│ │ │ Machine ID 生成和管理工具 │ │ │
│ │ │ │ │ │
│ │ │ [● 已启用] [打开] [配置] [卸载] │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ ✨ 代码审查 Skill v2.0.0 │ │ │
│ │ │ Skill · Community │ │ │
│ │ │ 专业的代码审查技能,支持多种语言 │ │ │
│ │ │ │ │ │
│ │ │ [○ 已禁用] [启用] [配置] [卸载] │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 扩展市场 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ 🔥 热门扩展 │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │OpenRouter│ │Anthropic │ │ Browser │ │ 翻译 │ │ │
│ │ │ Provider │ │ 官方 │ │Intercept │ │ Skill │ │ │
│ │ │ ⭐ 4.8 │ │ ⭐ 4.9 │ │ ⭐ 4.5 │ │ ⭐ 4.7 │ │ │
│ │ │ [安装] │ │ [安装] │ │ [安装] │ │ [安装] │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ │ │ │
│ │ 📦 官方认证 │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Google │ │ OpenAI │ │ 阿里云 │ │ │
│ │ │ 官方 │ │ 官方 │ │ 通义 │ │ │
│ │ │ ✓ 认证 │ │ ✓ 认证 │ │ ✓ 认证 │ │ │
│ │ │ [安装] │ │ [安装] │ │ [安装] │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
5.2 扩展详情页
┌─────────────────────────────────────────────────────────────────────────┐
│ ← 返回 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ 🔌 Kiro Provider │ │
│ │ ══════════════════════════════════════════════════════════════ │ │
│ │ │ │
│ │ 版本: 1.2.0 类型: OAuth 凭证 │ │
│ │ 作者: ProxyCast Team 许可: MIT │ │
│ │ 下载: 12.5k 评分: ⭐⭐⭐⭐⭐ (4.9) │ │
│ │ │ │
│ │ [安装] [GitHub] [文档] [问题反馈] │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 📝 描述 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ AWS CodeWhisperer OAuth 凭证管理插件,支持: │ │
│ │ - Claude 全系列模型 (Opus, Sonnet, Haiku) │ │
│ │ - 自动 Token 刷新 │ │
│ │ - Machine ID 风控适配 │ │
│ │ - 多凭证负载均衡 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 🔐 所需权限 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ ✓ database:read - 读取数据库 │ │
│ │ ✓ database:write - 写入数据库 │ │
│ │ ✓ http:request - 发送 HTTP 请求 │ │
│ │ ✓ crypto:encrypt - 加密敏感数据 │ │
│ │ ✓ fs:read:credentials - 读取凭证文件 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 📊 更新日志 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ v1.2.0 (2026-01-05) │ │
│ │ - 新增 Machine ID 自动轮换 │ │
│ │ - 修复 Token 刷新失败问题 │ │
│ │ - 优化凭证健康检查逻辑 │ │
│ │ │ │
│ │ v1.1.0 (2025-12-20) │ │
│ │ - 支持 Claude 3.5 Sonnet │ │
│ │ - 新增凭证导入/导出功能 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
5.3 扩展配置面板
┌─────────────────────────────────────────────────────────────────────────┐
│ Kiro Provider 配置 [保存] [×] │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 基础设置 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ 启用状态: [✓] 启用 │ │
│ │ │ │
│ │ 请求超时: [30000] ms │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 风控设置 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ Machine ID 轮换: [✓] 启用 │ │
│ │ │ │
│ │ 版本号伪装: [✓] 启用 │ │
│ │ │ │
│ │ 冷却期 (秒): [300] │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 凭证管理 │ │
│ ├─────────────────────────────────────────────────────────────────┤ │
│ │ │ │
│ │ 已添加凭证: 3 │ │
│ │ │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ 凭证 1 (account1@example.com) ● 健康 [删除] │ │ │
│ │ │ 凭证 2 (account2@example.com) ● 健康 [删除] │ │ │
│ │ │ 凭证 3 (account3@example.com) ○ 冷却 [删除] │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ [+ 添加凭证] │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
六、扩展注册表与加载器
6.1 统一注册表
/// 统一扩展注册表
pub struct ExtensionRegistry {
/// 所有已加载扩展
extensions: HashMap<String, Arc<dyn Extension>>,
/// 按类型索引
type_index: HashMap<ExtensionType, Vec<String>>,
/// 按服务商索引
vendor_index: HashMap<String, Vec<String>>,
/// 扩展目录
extensions_dir: PathBuf,
/// 事件发送器
event_tx: broadcast::Sender<ExtensionEvent>,
}
impl ExtensionRegistry {
/// 创建注册表
pub fn new(extensions_dir: PathBuf) -> Self;
/// 加载所有扩展
pub async fn load_all(&mut self) -> Result<()>;
/// 安装扩展
pub async fn install(&mut self, source: ExtensionSource) -> Result<String>;
/// 卸载扩展
pub async fn uninstall(&mut self, id: &str) -> Result<()>;
/// 启用/禁用扩展
pub async fn set_enabled(&mut self, id: &str, enabled: bool) -> Result<()>;
/// 获取扩展
pub fn get(&self, id: &str) -> Option<Arc<dyn Extension>>;
/// 按类型获取
pub fn get_by_type(&self, ext_type: ExtensionType) -> Vec<Arc<dyn Extension>>;
/// 按服务商获取
pub fn get_by_vendor(&self, vendor_id: &str) -> Vec<Arc<dyn Extension>>;
/// 检查更新
pub async fn check_updates(&self) -> Result<Vec<ExtensionUpdate>>;
/// 更新扩展
pub async fn update(&mut self, id: &str) -> Result<()>;
/// 订阅事件
pub fn subscribe(&self) -> broadcast::Receiver<ExtensionEvent>;
}
/// 扩展来源
pub enum ExtensionSource {
/// 从 GitHub Release
GitHub { owner: String, repo: String, version: Option<String> },
/// 从本地文件
LocalFile(PathBuf),
/// 从 URL
Url(String),
/// 从扩展市场
Marketplace { id: String, version: Option<String> },
}
/// 扩展事件
pub enum ExtensionEvent {
Installed { id: String },
Uninstalled { id: String },
Enabled { id: String },
Disabled { id: String },
Updated { id: String, from: String, to: String },
Error { id: String, error: String },
}
6.2 扩展加载器
/// 扩展加载器
pub struct ExtensionLoader {
extensions_dir: PathBuf,
sdk: Arc<ProxyCastSDK>,
}
impl ExtensionLoader {
/// 加载单个扩展
pub async fn load(&self, ext_dir: &Path) -> Result<Box<dyn Extension>> {
// 1. 读取 extension.json
let manifest_path = ext_dir.join("extension.json");
let manifest: ExtensionManifest = serde_json::from_str(
&fs::read_to_string(&manifest_path)?
)?;
// 2. 验证签名(如果有)
if let Some(signature) = &manifest.signature {
self.verify_signature(ext_dir, signature)?;
}
// 3. 根据类型创建扩展实例
let extension: Box<dyn Extension> = match manifest.extension_type {
ExtensionType::Skill => {
Box::new(SkillExtensionImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::TokenProvider => {
Box::new(TokenProviderImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::OAuthProvider => {
Box::new(OAuthProviderImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::Tool => {
Box::new(ToolExtensionImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::Vendor => {
Box::new(VendorExtensionImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::Protocol => {
Box::new(ProtocolExtensionImpl::new(ext_dir, manifest, self.sdk.clone())?)
}
ExtensionType::Theme => {
Box::new(ThemeExtensionImpl::new(ext_dir, manifest)?)
}
};
Ok(extension)
}
/// 验证签名
fn verify_signature(&self, ext_dir: &Path, signature: &str) -> Result<()>;
}
6.3 ProxyCast SDK
/// ProxyCast SDK - 供扩展使用的能力集
pub struct ProxyCastSDK {
database: Arc<DatabaseService>,
http: Arc<HttpClient>,
crypto: Arc<CryptoService>,
notification: Arc<NotificationService>,
events: Arc<EventBus>,
storage: Arc<StorageService>,
}
impl ProxyCastSDK {
// ========== 数据库 ==========
/// 查询数据
pub async fn db_query<T: DeserializeOwned>(&self, sql: &str, params: &[&dyn ToSql]) -> Result<Vec<T>>;
/// 执行 SQL
pub async fn db_execute(&self, sql: &str, params: &[&dyn ToSql]) -> Result<usize>;
// ========== HTTP ==========
/// 发送请求
pub async fn http_request(&self, req: HttpRequest) -> Result<HttpResponse>;
// ========== 加密 ==========
/// 加密数据
pub fn encrypt(&self, data: &str) -> Result<String>;
/// 解密数据
pub fn decrypt(&self, data: &str) -> Result<String>;
// ========== 通知 ==========
/// 显示通知
pub fn notify(&self, notification: Notification);
// ========== 事件 ==========
/// 发送事件
pub fn emit(&self, event: &str, data: serde_json::Value);
/// 订阅事件
pub fn on(&self, event: &str, callback: Box<dyn Fn(serde_json::Value) + Send + Sync>);
// ========== 存储 ==========
/// 获取扩展专属存储
pub fn storage(&self, extension_id: &str) -> ExtensionStorage;
}
/// 扩展专属存储
pub struct ExtensionStorage {
extension_id: String,
base_path: PathBuf,
}
impl ExtensionStorage {
/// 读取配置
pub fn get_config(&self) -> Result<serde_json::Value>;
/// 保存配置
pub fn set_config(&self, config: serde_json::Value) -> Result<()>;
/// 读取文件
pub fn read_file(&self, path: &str) -> Result<Vec<u8>>;
/// 写入文件
pub fn write_file(&self, path: &str, data: &[u8]) -> Result<()>;
}
七、扩展市场
7.1 市场架构
┌─────────────────────────────────────────────────────────────────────────┐
│ 扩展市场 (Extension Marketplace) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 市场 API (marketplace.proxycast.dev) │ │
│ │ │ │
│ │ GET /api/extensions - 扩展列表 │ │
│ │ GET /api/extensions/:id - 扩展详情 │ │
│ │ GET /api/extensions/:id/versions - 版本列表 │ │
│ │ GET /api/extensions/:id/download - 下载扩展 │ │
│ │ POST /api/extensions - 发布扩展 (需认证) │ │
│ │ GET /api/vendors - 服务商列表 │ │
│ │ GET /api/categories - 分类列表 │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────────────────┐ │
│ │ 扩展索引 (Extension Index) │ │
│ │ │ │
│ │ { │ │
│ │ "id": "kiro-provider", │ │
│ │ "name": "Kiro Provider", │ │
│ │ "type": "oauth_provider", │ │
│ │ "vendor": { "id": "proxycast", "verified": true }, │ │
│ │ "latest_version": "1.2.0", │ │
│ │ "downloads": 12500, │ │
│ │ "rating": 4.9, │ │
│ │ "tags": ["oauth", "claude", "aws"], │ │
│ │ "download_url": "https://..." │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
7.2 发布流程
开发者提交扩展
│
▼
┌─────────────────────────────────────┐
│ 1. 自动化检查 │
│ - extension.json 格式验证 │
│ - 权限声明审核 │
│ - 安全扫描 │
│ - 二进制签名验证 │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ 2. 人工审核 (可选) │
│ - 官方认证扩展需要 │
│ - 高权限扩展需要 │
└─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ 3. 发布到市场 │
│ - 生成下载链接 │
│ - 更新索引 │
│ - 通知订阅用户 │
└─────────────────────────────────────┘
八、权限系统
8.1 权限定义
/// 扩展权限
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Permission {
// 数据库
DatabaseRead,
DatabaseWrite,
// 网络
HttpRequest,
HttpRequestExternal, // 访问外部 URL
// 文件系统
FsReadCredentials, // 读取凭证文件
FsReadConfig, // 读取配置文件
FsWriteConfig, // 写入配置文件
FsReadAny, // 读取任意文件 (高危)
FsWriteAny, // 写入任意文件 (高危)
// 加密
CryptoEncrypt,
CryptoDecrypt,
// 系统
SystemInfo, // 获取系统信息
ProcessSpawn, // 启动子进程 (高危)
// UI
UiNotification,
UiDialog,
UiMainWindow,
// 扩展间通信
ExtensionCommunicate,
}
impl Permission {
/// 是否为高危权限
pub fn is_dangerous(&self) -> bool {
matches!(self,
Permission::FsReadAny |
Permission::FsWriteAny |
Permission::ProcessSpawn |
Permission::HttpRequestExternal
)
}
/// 权限描述
pub fn description(&self) -> &str {
match self {
Permission::DatabaseRead => "读取数据库",
Permission::DatabaseWrite => "写入数据库",
Permission::HttpRequest => "发送 HTTP 请求到 ProxyCast 服务",
Permission::HttpRequestExternal => "发送 HTTP 请求到外部服务",
Permission::FsReadCredentials => "读取凭证文件",
Permission::CryptoEncrypt => "加密敏感数据",
Permission::CryptoDecrypt => "解密敏感数据",
// ...
_ => "未知权限"
}
}
}
8.2 权限检查
/// 权限检查器
pub struct PermissionChecker {
granted: HashSet<Permission>,
}
impl PermissionChecker {
/// 检查权限
pub fn check(&self, permission: Permission) -> Result<()> {
if self.granted.contains(&permission) {
Ok(())
} else {
Err(Error::PermissionDenied(permission))
}
}
/// 请求权限 (弹窗确认)
pub async fn request(&mut self, permissions: Vec<Permission>) -> Result<()>;
}
九、目录结构
9.1 ProxyCast 主项目结构
src-tauri/src/
├── extension/ # 【新增】统一扩展系统
│ ├── mod.rs # 模块入口
│ ├── types.rs # Extension trait 和类型定义
│ ├── registry.rs # ExtensionRegistry 统一注册表
│ ├── loader.rs # ExtensionLoader 加载器
│ ├── host.rs # ExtensionHost 宿主环境
│ ├── sdk.rs # ProxyCastSDK
│ ├── permission.rs # 权限系统
│ │
│ ├── impls/ # 各类型扩展实现
│ │ ├── skill.rs # SkillExtension 实现
│ │ ├── token_provider.rs # TokenProviderExtension 实现
│ │ ├── oauth_provider.rs # OAuthProviderExtension 实现
│ │ ├── tool.rs # ToolExtension 实现
│ │ ├── vendor.rs # VendorExtension 实现
│ │ ├── protocol.rs # ProtocolExtension 实现
│ │ └── theme.rs # ThemeExtension 实现
│ │
│ └── marketplace/ # 扩展市场客户端
│ ├── client.rs # API 客户端
│ └── types.rs # 市场数据类型
│
├── credential/ # 保留,供 OAuth Provider 扩展复用
│ ├── pool.rs
│ ├── balancer.rs
│ └── health.rs
│
└── plugin/ # 现有插件系统,逐步迁移到 extension/
9.2 前端目录结构
src/
├── pages/
│ └── ExtensionCenter/ # 【新增】扩展中心页面
│ ├── index.tsx # 主页面
│ ├── ExtensionList.tsx # 扩展列表
│ ├── ExtensionDetail.tsx # 扩展详情
│ ├── ExtensionConfig.tsx # 扩展配置
│ ├── Marketplace.tsx # 扩展市场
│ └── components/
│ ├── ExtensionCard.tsx
│ ├── TypeFilter.tsx
│ ├── VendorBadge.tsx
│ └── PermissionList.tsx
│
├── components/
│ └── extension/ # 【新增】扩展相关组件
│ ├── ExtensionContainer.tsx # 扩展 UI 容器
│ ├── ExtensionLoader.tsx # 扩展 JS/CSS 加载
│ └── ExtensionRegistry.tsx # 前端扩展注册表
│
└── hooks/
└── useExtension.ts # 【新增】扩展相关 hooks
9.3 扩展安装目录
~/.proxycast/extensions/
├── kiro-provider/ # OAuth Provider 扩展
│ ├── extension.json
│ ├── config.json
│ ├── bin/
│ │ └── kiro-provider-cli
│ └── dist/
│ ├── index.js
│ └── styles.css
│
├── machine-id-tool/ # Tool 扩展
│ ├── extension.json
│ ├── config.json
│ └── bin/
│ └── machine-id-tool
│
├── code-review-skill/ # Skill 扩展
│ ├── extension.json
│ ├── config.json
│ └── prompts/
│ └── system.md
│
├── openrouter-provider/ # Token Provider 扩展
│ ├── extension.json
│ └── config.json
│
└── anthropic-official/ # Vendor 扩展
├── extension.json
├── config.json
└── sub_extensions/
├── claude-api/
└── claude-oauth/
十、数据库设计
10.1 扩展表
-- 已安装扩展
CREATE TABLE extensions (
id TEXT PRIMARY KEY, -- "kiro-provider"
type TEXT NOT NULL, -- "oauth_provider", "skill", etc.
name TEXT NOT NULL,
version TEXT NOT NULL,
vendor_id TEXT,
enabled INTEGER DEFAULT 1,
config TEXT, -- JSON 配置
permissions TEXT, -- JSON 权限列表
install_path TEXT NOT NULL,
installed_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
-- 扩展凭证 (OAuth Provider 专用)
CREATE TABLE extension_credentials (
id TEXT PRIMARY KEY,
extension_id TEXT NOT NULL,
credential_data TEXT NOT NULL, -- 加密的凭证数据
status TEXT DEFAULT 'active',
stats TEXT, -- JSON 统计
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
FOREIGN KEY (extension_id) REFERENCES extensions(id)
);
-- 服务商信息
CREATE TABLE vendors (
id TEXT PRIMARY KEY, -- "anthropic", "openai"
name TEXT NOT NULL,
homepage TEXT,
verified INTEGER DEFAULT 0,
logo_url TEXT,
created_at INTEGER NOT NULL
);
-- 扩展市场缓存
CREATE TABLE marketplace_cache (
id TEXT PRIMARY KEY,
data TEXT NOT NULL, -- JSON 扩展信息
cached_at INTEGER NOT NULL
);
十一、迁移计划
11.1 阶段一:基础架构 (2 周)
| 任务 | 说明 |
|---|---|
| Extension trait 定义 | 统一扩展接口 |
| ExtensionRegistry | 统一注册表 |
| ExtensionLoader | 扩展加载器 |
| ProxyCastSDK | 扩展 SDK |
| 权限系统 | Permission 定义和检查 |
11.2 阶段二:扩展类型实现 (3 周)
| 任务 | 说明 |
|---|---|
| OAuthProviderExtension | 迁移现有 OAuth Provider |
| TokenProviderExtension | 迁移现有 API Key Provider |
| ToolExtension | 迁移 MachineIdTool |
| SkillExtension | 迁移现有 Skills |
11.3 阶段三:UI 与市场 (2 周)
| 任务 | 说明 |
|---|---|
| 扩展中心页面 | 统一管理入口 |
| 扩展配置面板 | 动态表单生成 |
| 扩展市场客户端 | 浏览、安装、更新 |
11.4 阶段四:生态建设 (持续)
| 任务 | 说明 |
|---|---|
| 官方扩展发布 | Kiro、Anthropic、OpenAI 等 |
| 开发者文档 | 扩展开发指南 |
| 市场后端 | marketplace.proxycast.dev |
十二、与现有系统的关系
12.1 兼容性设计
┌─────────────────────────────────────────────────────────────────────────┐
│ 现有系统 → 统一扩展平台 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ 现有 ProviderType 枚举 (11种) │
│ │ │
│ ├── OAuth 类型 (7种) ──────→ OAuthProviderExtension │
│ │ Kiro, Gemini, Qwen, Antigravity, │
│ │ ClaudeOAuth, Codex, IFlow │
│ │ │
│ └── API Key 类型 (4种) ────→ TokenProviderExtension │
│ Claude, OpenAI, GeminiApiKey, Vertex │
│ │
│ ───────────────────────────────────────────────────────────────────── │
│ │
│ 现有 api_key_providers 表 (60+ 预设) │
│ │ │
│ └── 保持不变,作为 TokenProviderExtension 的数据源 │
│ │
│ ───────────────────────────────────────────────────────────────────── │
│ │
│ 现有 Plugin 系统 (MachineIdTool) │
│ │ │
│ └── 迁移为 ToolExtension │
│ │
│ ───────────────────────────────────────────────────────────────────── │
│ │
│ 现有 Skills 系统 │
│ │ │
│ └── 迁移为 SkillExtension │
│ │
└─────────────────────────────────────────────────────────────────────────┘
12.2 渐进式迁移
- 第一步:新建
extension/模块,不影响现有代码 - 第二步:实现各类型 Extension trait
- 第三步:将现有 Provider 包装为 Extension
- 第四步:新功能使用 Extension 系统
- 第五步:逐步删除旧代码
十三、总结
13.1 核心价值
| 价值 | 说明 |
|---|---|
| 统一管理 | 一个入口管理所有扩展类型 |
| 独立更新 | 扩展可独立安装、更新、卸载 |
| 开放生态 | 第三方开发者可贡献扩展 |
| 服务商友好 | 服务商可发布官方扩展 |
| 安全可控 | 权限系统保障安全 |
13.2 扩展类型总结
| 类型 | 数量 | 示例 |
|---|---|---|
| Skills | 5+ | 代码审查、翻译、写作 |
| Token Provider | 10+ | OpenRouter、TogetherAI、官方 API |
| OAuth Provider | 7+ | Kiro、Claude OAuth、Gemini |
| Tool | 3+ | Machine ID、Browser Interceptor |
| Vendor | 5+ | Anthropic、OpenAI、Google |
| Protocol | 3+ | Doubao、Wenxin |
| Theme | 2+ | Dark Pro、Light Minimal |
13.3 关键设计决策
- 统一 Extension trait:所有扩展类型继承同一基础接口
- extension.json 清单:标准化扩展元数据格式
- ProxyCastSDK:为扩展提供统一的能力访问
- 权限系统:细粒度权限控制,保障安全
- 扩展市场:官方市场 + GitHub Release 双渠道
- 渐进式迁移:不破坏现有功能,逐步演进