From 65a65f1a293dfac700985b80aa2226b4915b727d Mon Sep 17 00:00:00 2001 From: dongtran16092006 Date: Tue, 7 Apr 2026 16:48:28 +0700 Subject: [PATCH] fix: resolve MCP and system prompt saving issues --- crates/openfang-api/src/routes.rs | 4 ++ crates/openfang-api/static/js/pages/agents.js | 37 ++++++++++++------- crates/openfang-runtime/src/mcp.rs | 7 +--- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/crates/openfang-api/src/routes.rs b/crates/openfang-api/src/routes.rs index b3ce41dc7b..ce818c5016 100644 --- a/crates/openfang-api/src/routes.rs +++ b/crates/openfang-api/src/routes.rs @@ -1380,11 +1380,15 @@ pub async fn get_agent( "network": entry.manifest.capabilities.network, }, "description": entry.manifest.description, + "system_prompt": entry.manifest.model.system_prompt, "tags": entry.manifest.tags, "identity": { "emoji": entry.identity.emoji, "avatar_url": entry.identity.avatar_url, "color": entry.identity.color, + "archetype": entry.identity.archetype, + "vibe": entry.identity.vibe, + "greeting_style": entry.identity.greeting_style, }, "skills": entry.manifest.skills, "skills_mode": if entry.manifest.skills.is_empty() { "all" } else { "allowlist" }, diff --git a/crates/openfang-api/static/js/pages/agents.js b/crates/openfang-api/static/js/pages/agents.js index b46b24bfdb..6acccf9ba6 100644 --- a/crates/openfang-api/static/js/pages/agents.js +++ b/crates/openfang-api/static/js/pages/agents.js @@ -316,29 +316,38 @@ function agentsPage() { OpenFangAPI.wsDisconnect(); }, + buildConfigForm(agent) { + var identity = (agent && agent.identity) || {}; + return { + name: (agent && agent.name) || '', + system_prompt: (agent && agent.system_prompt) || '', + emoji: identity.emoji || '', + color: identity.color || '#FF5C00', + archetype: identity.archetype || '', + vibe: identity.vibe || '' + }; + }, + async showDetail(agent) { - this.detailAgent = agent; - this.detailAgent._fallbacks = []; this.detailTab = 'info'; this.agentFiles = []; this.editingFile = null; this.fileContent = ''; this.editingFallback = false; this.newFallbackValue = ''; - this.configForm = { - name: agent.name || '', - system_prompt: agent.system_prompt || '', - emoji: (agent.identity && agent.identity.emoji) || '', - color: (agent.identity && agent.identity.color) || '#FF5C00', - archetype: (agent.identity && agent.identity.archetype) || '', - vibe: (agent.identity && agent.identity.vibe) || '' - }; - this.showDetailModal = true; - // Fetch full agent detail to get fallback_models + // Load the full detail payload before opening the modal so editable + // fields such as system_prompt and identity metadata are hydrated. + var detail = agent; try { var full = await OpenFangAPI.get('/api/agents/' + agent.id); - this.detailAgent._fallbacks = full.fallback_models || []; - } catch(e) { /* ignore */ } + detail = Object.assign({}, agent, full, { + identity: Object.assign({}, (agent && agent.identity) || {}, (full && full.identity) || {}) + }); + } catch(e) { /* fall back to list payload */ } + this.detailAgent = detail; + this.detailAgent._fallbacks = detail.fallback_models || []; + this.configForm = this.buildConfigForm(detail); + this.showDetailModal = true; }, killAgent(agent) { diff --git a/crates/openfang-runtime/src/mcp.rs b/crates/openfang-runtime/src/mcp.rs index b9f5f3819f..f016f36026 100644 --- a/crates/openfang-runtime/src/mcp.rs +++ b/crates/openfang-runtime/src/mcp.rs @@ -14,7 +14,6 @@ use rmcp::service::RunningService; use rmcp::{RoleClient, ServiceExt}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::sync::Arc; use tracing::{debug, info}; // --------------------------------------------------------------------------- @@ -307,11 +306,7 @@ impl McpConnection { } } - let config = StreamableHttpClientTransportConfig { - uri: Arc::from(url), - custom_headers, - ..Default::default() - }; + let config = StreamableHttpClientTransportConfig::with_uri(url).custom_headers(custom_headers); let transport = StreamableHttpClientTransport::from_config(config);