perf: 机器人支持新会话

This commit is contained in:
kuaifan
2025-07-25 11:38:51 +08:00
parent 0b86fa7bee
commit 4cec0a7350
5 changed files with 6 additions and 10 deletions

View File

@@ -66,15 +66,14 @@ class WebSocketDialogSession extends AbstractModel
if ($dialogMsg->type != 'text') {
return;
}
if ($dialogMsg->msg['text'] === '...') {
return;
}
$cacheKey = 'dialog_session_title_' . $sessionId;
if (Cache::has($cacheKey)) {
return;
}
$originalTitle = $dialogMsg->key ?: $dialogMsg->msg['text'] ?: 'Untitled';
$title = Base::cutStr($originalTitle, 100);
if ($title == '...') {
return;
}
$title = $dialogMsg->key ?: WebSocketDialogMsg::previewTextMsg($dialogMsg->msg) ?: 'Untitled';
$session = self::whereId($sessionId)->first();
if (!$session) {
return;
@@ -82,6 +81,6 @@ class WebSocketDialogSession extends AbstractModel
$session->title = $title;
$session->save();
Cache::forever($cacheKey, true);
Task::deliver(new UpdateSessionTitleViaAiTask($session->id, $originalTitle));
Task::deliver(new UpdateSessionTitleViaAiTask($session->id, $dialogMsg->msg['text']));
}
}