From db3b2c24b75512e7996523547e1d00e4089b2fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Mon, 24 Aug 2026 02:13:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20AI=20=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=20Markdown=20=E6=B8=B2=E6=9F=93+=E6=89=93=E5=AD=97=E6=9C=BA?= =?UTF-8?q?=E6=B5=81=E5=BC=8F+=E6=A1=8C=E9=9D=A2=20Rust=20=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E4=BF=AE=E5=A4=8D=20CORS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/capabilities/default.json | 12 ++ src-tauri/src/commands.rs | 5 +- src/components/ai/AiPanel.vue | 192 +++++++++++++------------ src/core/ai.ts | 213 ++++++++++++++++++++++------ src/core/bridge.ts | 87 ++++++++---- src/core/markdown.ts | 66 +++++++++ src/styles/chat.css | 39 ++++- vite.config.ts | 16 ++- 8 files changed, 463 insertions(+), 167 deletions(-) create mode 100644 src-tauri/capabilities/default.json create mode 100644 src/core/markdown.ts diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json new file mode 100644 index 0000000..df30d26 --- /dev/null +++ b/src-tauri/capabilities/default.json @@ -0,0 +1,12 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "u-ppt 主窗口默认能力:IPC 命令调用 + AI 流式事件订阅", + "windows": ["main"], + "permissions": [ + "core:default", + "core:event:default", + "core:event:allow-listen", + "core:event:allow-unlisten" + ] +} diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 26a97e5..0ad4196 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -205,8 +205,11 @@ pub async fn ai_proxy_stream( .map_err(|e| format!("请求失败: {}", e))?; if !resp.status().is_success() { + let status = resp.status().as_u16(); let text = resp.text().await.unwrap_or_default(); - return Ok(text); + // 错误体带状态码前缀,前端按「接口返回 N」格式提示 + let _ = app.emit("ai-error", &text); + return Err(format!("__HTTP_{}__{}", status, text)); } // 流式读取 SSE diff --git a/src/components/ai/AiPanel.vue b/src/components/ai/AiPanel.vue index a05d34b..e63ec48 100644 --- a/src/components/ai/AiPanel.vue +++ b/src/components/ai/AiPanel.vue @@ -3,74 +3,14 @@ 发送/停止/生成整套/润色本页/流式渲染/操作应用 ===================================================================== -->