Skip to content

Commit 5c05340

Browse files
Cloud UserCloud User
authored andcommitted
fix: tread name sometimes do not persist
1 parent 489596f commit 5c05340

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/app/api/chat/title/route.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ export async function POST(request: Request) {
4242
experimental_transform: smoothStream({ chunking: "word" }),
4343
prompt: message,
4444
abortSignal: request.signal,
45-
onFinish: (ctx) => {
46-
chatRepository
47-
.upsertThread({
48-
id: threadId,
49-
title: ctx.text,
50-
userId: session.user.id,
51-
})
52-
.catch((err) => logger.error(err));
45+
onFinish: async (ctx) => {
46+
const title = ctx.text.trim();
47+
if (!title) return;
48+
49+
await chatRepository.upsertThread({
50+
id: threadId,
51+
title,
52+
userId: session.user.id,
53+
});
5354
},
5455
});
5556

src/hooks/queries/use-generate-thread-title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useGenerateThreadTitle(option: {
1818
const updateTitle = useCallback(
1919
(title: string) => {
2020
appStore.setState((prev) => {
21-
if (prev.threadList.some((v) => v.id !== option.threadId)) {
21+
if (!prev.threadList.some((v) => v.id === option.threadId)) {
2222
return {
2323
threadList: [
2424
{

0 commit comments

Comments
 (0)