From fe4a968eef489f7c6305792593f9cb8a44c84011 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Sun, 25 Jan 2026 19:46:22 +0800 Subject: [PATCH] feat(provider): add FormatTransformConfig for API format conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add FormatTransformConfig struct to support API format transformation between different providers (e.g., Anthropic ↔ OpenAI). This enables providers like OpenRouter that use OpenAI-compatible interfaces. --- src-tauri/src/provider.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src-tauri/src/provider.rs b/src-tauri/src/provider.rs index d13020737..eb401d3c9 100644 --- a/src-tauri/src/provider.rs +++ b/src-tauri/src/provider.rs @@ -191,6 +191,23 @@ pub struct ProviderProxyConfig { pub proxy_password: Option, } +/// 格式转换配置(用于 OpenRouter 等需要 API 格式转换的供应商) +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct FormatTransformConfig { + /// 是否启用格式转换 + #[serde(default)] + pub enabled: bool, + /// 源格式:anthropic, openai, gemini + #[serde(rename = "sourceFormat", skip_serializing_if = "Option::is_none")] + pub source_format: Option, + /// 目标格式:anthropic, openai, gemini + #[serde(rename = "targetFormat", skip_serializing_if = "Option::is_none")] + pub target_format: Option, + /// 是否转换流式响应(默认 true) + #[serde(rename = "transformStreaming", skip_serializing_if = "Option::is_none")] + pub transform_streaming: Option, +} + /// 供应商元数据 #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct ProviderMeta { @@ -227,6 +244,9 @@ pub struct ProviderMeta { /// 供应商单独的代理配置 #[serde(rename = "proxyConfig", skip_serializing_if = "Option::is_none")] pub proxy_config: Option, + /// 格式转换配置(用于 OpenRouter 等需要 API 格式转换的供应商) + #[serde(rename = "formatTransform", skip_serializing_if = "Option::is_none")] + pub format_transform: Option, } impl ProviderManager {