From 8d15125f12164846ba65567bfa4d4240c83428f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 11 Sep 2026 18:52:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E5=88=87=E5=88=86=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D=E4=B8=AD=E7=9A=84=E8=8A=82=E7=82=B9=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 | 22 +++++++++++++++++-- 1 file changed, 20 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..cb1df4fd7 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,6 +1,24 @@ use serde::{Deserialize, Serialize}; use ts_rs::TS; +const MAX_PROMPT_NOTE_CHARS: usize = 512; + +fn sanitize_prompt_text(value: &str) -> String { + value + .chars() + .filter_map(|character| { + if character == '`' { + Some('\'') + } else if character.is_control() { + Some(' ') + } else { + Some(character) + } + }) + .take(MAX_PROMPT_NOTE_CHARS) + .collect() +} + #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)] #[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))] pub struct SeparationNote { @@ -10,12 +28,12 @@ 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)); 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)); } } prompt