diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/create_or_derive_resource/error.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/create_or_derive_resource/error.rs index b735eb645..202e1440a 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/create_or_derive_resource/error.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/create_or_derive_resource/error.rs @@ -254,7 +254,9 @@ impl ToolFailure for CreateOrDeriveResourceError { Self::ProjectRevisionUnavailable { cause } => { format!("生成或派生资源失败:读取项目 revision 失败:{cause}") } - Self::RemoteGenerationFailed(failure) => failure.to_user_msg(), + Self::RemoteGenerationFailed(failure) => { + format!("生成或派生资源失败:{}", failure.to_user_msg()) + } Self::ResourceGenerationFailed { cause } => { format!("生成或派生资源失败:{cause}") } @@ -289,7 +291,7 @@ mod tests { }, ); - assert_eq!(error.to_user_msg(), "资源编辑生成失败:provider detail"); + assert_eq!(error.to_user_msg(), "生成或派生资源失败:provider detail"); assert_eq!( serde_json::to_value(&error).expect("serialize typed failure") ["RemoteGenerationFailed"]["server_message"], @@ -305,7 +307,10 @@ mod tests { }, ); - assert_eq!(error.to_user_msg(), "资源编辑生成失败"); + assert_eq!( + error.to_user_msg(), + "生成或派生资源失败:服务器未返回错误信息" + ); } #[test] diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/error.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/error.rs index f6eab4fc6..734f2b335 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/error.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/error.rs @@ -182,8 +182,8 @@ impl ToolFailure for ResourceCompletionRejection { /// 平台把远端资源编辑判成终态 `failed` 时给出的原因。 /// /// `agc_create_or_derive_resource` 与 `agc_remove_background` 走的是同一条远端资源编辑 -/// 通道,平台 `error` 原文必须作为数据原样带出(不是在产生点拼进前缀),两个工具共用 -/// 这一层文案。 +/// 通道,平台 `error` 原文必须作为数据原样带出(不是在产生点拼进前缀)。这里只负责 +/// 原文与「平台没给」的兜底,前缀由使用它的工具在自己的变体里加,两个工具共用这一份载体。 #[derive(serde::Serialize, Debug)] pub(crate) struct RemoteResourceEditFailure { /// 平台 `error` 字段原文;平台没给时为空。 @@ -193,8 +193,8 @@ pub(crate) struct RemoteResourceEditFailure { impl ToolFailure for RemoteResourceEditFailure { fn to_user_msg(&self) -> String { match &self.server_message { - Some(server_message) => format!("资源编辑生成失败:{server_message}"), - None => "资源编辑生成失败".to_string(), + Some(server_message) => server_message.clone(), + None => "服务器未返回错误信息".to_string(), } } } @@ -274,3 +274,26 @@ impl ToolFailure for DirectExecutionGateRejection { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn remote_resource_edit_failure_keeps_platform_text_verbatim() { + let failure = RemoteResourceEditFailure { + server_message: Some("provider detail".to_string()), + }; + + assert_eq!(failure.to_user_msg(), "provider detail"); + } + + #[test] + fn remote_resource_edit_failure_without_message_blames_the_server() { + let failure = RemoteResourceEditFailure { + server_message: None, + }; + + assert_eq!(failure.to_user_msg(), "服务器未返回错误信息"); + } +} diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/remove_background/error.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/remove_background/error.rs index 1dd849593..f34b8c131 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/tool/remove_background/error.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/tool/remove_background/error.rs @@ -175,7 +175,9 @@ impl ToolFailure for RemoveBackgroundError { Self::ProjectRevisionUnavailable { cause } => { format!("抠图失败:读取项目 revision 失败:{cause}") } - Self::RemoteGenerationFailed(failure) => failure.to_user_msg(), + Self::RemoteGenerationFailed(failure) => { + format!("抠图失败:{}", failure.to_user_msg()) + } Self::BackgroundRemovalFailed { cause } => format!("抠图失败:{cause}"), } } @@ -208,7 +210,7 @@ mod tests { }, ); - assert_eq!(error.to_user_msg(), "资源编辑生成失败:provider detail"); + assert_eq!(error.to_user_msg(), "抠图失败:provider detail"); assert_eq!( serde_json::to_value(&error).expect("serialize typed failure") ["RemoteGenerationFailed"]["server_message"], @@ -224,7 +226,7 @@ mod tests { }, ); - assert_eq!(error.to_user_msg(), "资源编辑生成失败"); + assert_eq!(error.to_user_msg(), "抠图失败:服务器未返回错误信息"); } #[test]