From 8629a228a185ebe6811c60c08b08ab39e3a7afb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 12 Sep 2026 21:23:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E5=B9=B6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E8=A7=86=E8=A7=89=E7=BB=91=E5=AE=9A=E6=8F=90=E7=A4=BA=E5=A4=87?= =?UTF-8?q?=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为节点描述和返工备注增加长度上限并移除控制字符、代码围栏字符。 --- .../commands/separation/model/note.rs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/model/note.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/model/note.rs index 15c500b59..dbac38464 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/model/note.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/commands/separation/model/note.rs @@ -1,5 +1,24 @@ use serde::{Deserialize, Serialize}; use ts_rs::TS; +use super::MAX_REWORK_NOTE_CHARS; + +pub const MAX_NOTE_DESCRIPTION_CHARS: usize = 1024; + +pub fn sanitize_prompt_text(value: &str, max_chars: usize) -> String { + value + .chars() + .filter_map(|character| { + if character.is_control() { + Some(' ') + } else if character == '`' { + Some(''') + } else { + Some(character) + } + }) + .take(max_chars) + .collect() +} #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)] #[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))] @@ -10,12 +29,15 @@ pub struct SeparationNote { impl SeparationNote { pub fn as_prompt(&self) -> String { - let mut prompt = format!("desc: {}", self.description); + let mut prompt = format!( + "desc: {}", + sanitize_prompt_text(&self.description, MAX_NOTE_DESCRIPTION_CHARS) + ); if !self.rework_notes.is_empty() { prompt.push_str("\nprevious rework notes:"); for note in &self.rework_notes { prompt.push_str("\n- "); - prompt.push_str(note); + prompt.push_str(&sanitize_prompt_text(note, MAX_REWORK_NOTE_CHARS)); } } prompt