diff --git a/apps/ai-game-creator-shell/src-tauri/prompts/automatic-project-name.md b/apps/ai-game-creator-shell/src-tauri/prompts/automatic-project-name.md new file mode 100644 index 000000000..b7369c0f5 --- /dev/null +++ b/apps/ai-game-creator-shell/src-tauri/prompts/automatic-project-name.md @@ -0,0 +1 @@ +你是项目命名助手。只根据用户输入提炼一个原创、简短、中文的项目名称;不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释。输出必须有且只有一行纯文本,长度为 2 到 16 个字符。信息不足时输出:未命名游戏原型 diff --git a/apps/ai-game-creator-shell/src-tauri/src/commands.rs b/apps/ai-game-creator-shell/src-tauri/src/commands.rs index 87a713346..76949b928 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/commands.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/commands.rs @@ -17,8 +17,10 @@ const AUTOMATIC_PROJECT_NAME_MAX_PROMPT_CHARS: usize = 8_000; const AUTOMATIC_PROJECT_NAME_MAX_ATTACHMENTS: usize = 20; const AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS: u32 = 64; const AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT: &str = - "你是项目命名助手。只根据用户输入提炼一个原创、简短、中文的项目名称;不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释。输出必须有且只有一行纯文本,长度为 2 到 16 个字符。信息不足时输出:未命名游戏原型"; + include_str!("../prompts/automatic-project-name.md"); +// 自动命名只需要附件名称和媒体类型提示。保持独立的窄 DTO 并拒绝未知字段, +// 避免把 Direct 回合附件中的本地路径、导入状态和文件大小引入无项目命名边界。 #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub(crate) struct AutomaticProjectNameAttachment { @@ -95,7 +97,7 @@ async fn request_automatic_project_name( let app_config = load_game_creator_app_config()?; if app_config.agent_mode == GAME_CREATOR_AGENT_MODE_CODEX_APP_SERVER { let reply = crate::agent::direct_game_creator_home_codex_chat( - AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.to_string(), + AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.trim().to_string(), user_prompt, ) .await?; @@ -104,12 +106,13 @@ async fn request_automatic_project_name( let mut llm = app_config.llm.clone(); llm.max_retries = 0; let client = build_game_creator_llm_client_from_llm_config(&llm, "llm")?; - let request = LlmRunRequest::single_turn(AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT, user_prompt) - .with_api_kind(parse_game_creator_llm_api_kind(&llm.api_kind)?) - .with_model(llm.model.clone()) - .with_request_timeout_ms(llm.request_timeout_ms) - .with_max_output_tokens(AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS) - .with_web_search(false); + let request = + LlmRunRequest::single_turn(AUTOMATIC_PROJECT_NAME_SYSTEM_PROMPT.trim(), user_prompt) + .with_api_kind(parse_game_creator_llm_api_kind(&llm.api_kind)?) + .with_model(llm.model.clone()) + .with_request_timeout_ms(llm.request_timeout_ms) + .with_max_output_tokens(AUTOMATIC_PROJECT_NAME_MAX_OUTPUT_TOKENS) + .with_web_search(false); let response = client .run(request) .await diff --git a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs index 31650cbc1..3dce6ada7 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs @@ -1650,6 +1650,10 @@ fn automatic_project_name_suggestions_are_normalized_fail_closed() { #[test] fn automatic_project_name_prompt_is_bounded_and_uses_attachment_metadata_only() { + let system_prompt = include_str!("../../prompts/automatic-project-name.md"); + assert!(system_prompt.contains("长度为 2 到 16 个字符")); + assert!(system_prompt.contains("不要使用知名作品名、路径、URL、凭据、Markdown、引号或解释")); + let prompt = build_automatic_project_name_prompt( "做一个在月球邮局送信的解谜游戏", &[