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:
xintaofei
2026-04-05 16:35:14 +08:00
parent 6359651247
commit ba19299696
32 changed files with 1501 additions and 11 deletions

View File

@@ -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;

View 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(),
}
}
}