feat(settings): add model provider management with full CRUD support
Add a new settings page for managing API model providers (name, API URL, API key, applicable agent types). Includes database migration, SeaORM entity, backend CRUD commands/handlers, frontend settings UI with agent type filter, add/edit/delete dialogs, and i18n support for all 10 locales. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ pub mod agent;
|
||||
pub mod chat_channel;
|
||||
pub mod conversation;
|
||||
pub mod folder;
|
||||
pub mod model_provider;
|
||||
pub mod message;
|
||||
pub mod system;
|
||||
|
||||
|
||||
42
src-tauri/src/models/model_provider.rs
Normal file
42
src-tauri/src/models/model_provider.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ModelProviderInfo {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub api_url: String,
|
||||
pub api_key_masked: String,
|
||||
pub agent_types: Vec<String>,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
fn mask_api_key(key: &str) -> String {
|
||||
let len = key.len();
|
||||
if len <= 8 {
|
||||
"\u{2022}".repeat(len)
|
||||
} else {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
&key[..4],
|
||||
"\u{2022}".repeat(len.min(20) - 8),
|
||||
&key[len - 4..]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::db::entities::model_provider::Model> for ModelProviderInfo {
|
||||
fn from(m: crate::db::entities::model_provider::Model) -> Self {
|
||||
let agent_types: Vec<String> =
|
||||
serde_json::from_str(&m.agent_types_json).unwrap_or_default();
|
||||
Self {
|
||||
id: m.id,
|
||||
name: m.name,
|
||||
api_url: m.api_url,
|
||||
api_key_masked: mask_api_key(&m.api_key),
|
||||
agent_types,
|
||||
created_at: m.created_at.to_rfc3339(),
|
||||
updated_at: m.updated_at.to_rfc3339(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user