fix: return real message id from chat_send so editing fresh messages works

This commit is contained in:
Xianren Studio
2026-08-13 23:06:52 +08:00
parent 496be1f032
commit 57df39e4ce
3 changed files with 19 additions and 9 deletions
+9 -6
View File
@@ -458,12 +458,12 @@ pub async fn chat_send(
app: AppHandle,
state: State<'_, App>,
payload: ChatSendPayload,
) -> Result<(), String> {
) -> Result<serde_json::Value, String> {
let core = state.core.clone();
let engine = state.engine.clone();
let base = state.engine_base.clone();
let (history, model, engine_bin) = {
let (history, model, engine_bin, user_message_id) = {
let db = core.db.lock().unwrap();
if sessions_db::get_conversation(&db, &payload.conversation_id)
.map_err(|e| e.to_string())?
@@ -479,7 +479,7 @@ pub async fn chat_send(
)
.map_err(|e| e.to_string())?;
}
sessions_db::add_message(
let user_message_id = sessions_db::add_message(
&db,
&payload.conversation_id,
"user",
@@ -508,7 +508,7 @@ pub async fn chat_send(
let bin = settings_db::get(&db, "engine_bin")
.map_err(|e| e.to_string())?
.unwrap_or_default();
(history, model, bin)
(history, model, bin, user_message_id)
};
let conversation_id = payload.conversation_id.clone();
@@ -523,13 +523,16 @@ pub async fn chat_send(
core,
engine,
base,
conversation_id,
conversation_id.clone(),
history,
model,
engine_bin,
payload.params,
));
Ok(())
Ok(serde_json::json!({
"conversation_id": conversation_id,
"message_id": user_message_id,
}))
}
/// 统一的生成与流式转发:支持本地引擎 / 远程 API,统计首字延迟、token 数与耗时。