kind 白名单从 DirectResourceGenerationKind::ALL 取,删掉第二份字符串清单

- 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 通过
This commit is contained in:
2026-10-01 16:45:10 +08:00
parent 3c2dc57c57
commit 9bdeed13a0
2 changed files with 18 additions and 3 deletions
@@ -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<Self, String> {
match value {
"image" => Ok(Self::Image),
@@ -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::<Vec<_>>()
.join("、");
format!("生成或派生资源失败:kind「{got}」不是受支持的媒体资源类型,只允许 {allowed}。")
}
Self::ModeEmpty => "生成或派生资源失败:mode 不能为空。".to_string(),
Self::ModeTooLong {
got_chars,