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