From 9bdeed13a09dfb82b71933823fd72e54d6213b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 1 Oct 2026 16:45:10 +0800 Subject: [PATCH] =?UTF-8?q?kind=20=E7=99=BD=E5=90=8D=E5=8D=95=E4=BB=8E=20D?= =?UTF-8?q?irectResourceGenerationKind::ALL=20=E5=8F=96=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E6=8E=89=E7=AC=AC=E4=BA=8C=E4=BB=BD=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DirectResourceGenerationKind 新增 ALL: [Self; 5],顺序与 parse/as_str 一致 - KindUnsupported 的「只允许 …」改为由 ALL 生成,新增 kind 时不再需要手动同步这句文案 - 文案字面不变:image、video、character-animation、sound-effect、background-music 验证:cargo fmt --all --manifest-path apps/ai-game-creator-shell/src-tauri/Cargo.toml -- --check 通过 --- .../src-tauri/src/agent/direct_tool_bridge.rs | 10 ++++++++++ .../src/agent/tool/create_or_derive_resource/error.rs | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs index fefb925df..bfff40a20 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_tool_bridge.rs @@ -203,6 +203,16 @@ pub(crate) enum DirectResourceGenerationKind { } impl DirectResourceGenerationKind { + /// 全部受支持的 kind,顺序与 `parse`/`as_str` 一致;需要把清单讲给模型听的文案从这里取, + /// 免得新增 kind 时留下第二份会漂移的字符串白名单。 + pub(crate) const ALL: [Self; 5] = [ + Self::Image, + Self::Video, + Self::CharacterAnimation, + Self::SoundEffect, + Self::BackgroundMusic, + ]; + pub(crate) fn parse(value: &str) -> Result { match value { "image" => Ok(Self::Image), 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 9b2597b51..8b4e27c87 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 @@ -141,9 +141,14 @@ impl ToolFailure for CreateOrDeriveResourceError { Self::KindNotText { got } => format!( "生成或派生资源失败:kind 必须是字符串,当前是「{got}」。" ), - Self::KindUnsupported { got } => format!( - "生成或派生资源失败:kind「{got}」不是受支持的媒体资源类型,只允许 image、video、character-animation、sound-effect、background-music。" - ), + Self::KindUnsupported { got } => { + let allowed = DirectResourceGenerationKind::ALL + .into_iter() + .map(DirectResourceGenerationKind::as_str) + .collect::>() + .join("、"); + format!("生成或派生资源失败:kind「{got}」不是受支持的媒体资源类型,只允许 {allowed}。") + } Self::ModeEmpty => "生成或派生资源失败:mode 不能为空。".to_string(), Self::ModeTooLong { got_chars,