diff --git a/apps/server/src/services/auto_name.ts b/apps/server/src/services/auto_name.ts index 38831e9..d058e82 100644 --- a/apps/server/src/services/auto_name.ts +++ b/apps/server/src/services/auto_name.ts @@ -37,9 +37,11 @@ export async function maybeAutoNameChat( if ((counts[0]?.n ?? 0) < 1) return; const chatRows = await ctx.sql< - { id: string; name: string | null; session_id: string }[] + { id: string; name: string | null; session_id: string; model: string | null }[] >` - SELECT id, name, session_id FROM chats WHERE id = ${chatId} + SELECT c.id, c.name, c.session_id, s.model + FROM chats c JOIN sessions s ON s.id = c.session_id + WHERE c.id = ${chatId} `; const chat = chatRows[0]; if (!chat) return; @@ -67,6 +69,7 @@ export async function maybeAutoNameChat( user: namingInput, maxTokens: 30, temperature: 0.3, + fallbackModel: chat.model ?? undefined, }); const name = cleanTitle(raw); if (!name) { diff --git a/apps/web/src/hooks/useWorkspacePanes.ts b/apps/web/src/hooks/useWorkspacePanes.ts index 101193f..14c01f5 100644 --- a/apps/web/src/hooks/useWorkspacePanes.ts +++ b/apps/web/src/hooks/useWorkspacePanes.ts @@ -391,6 +391,13 @@ export function useWorkspacePanes(sessionId: string): UseWorkspacePanesResult { const pane = next[paneIdx]!; const nextIds = pane.chatIds.filter((id) => id !== chatId); if (nextIds.length === 0) { + if (next.length > 1) { + // Last tab closed and other panes exist — remove the whole pane + // instead of leaving an orphaned empty panel. + const spliced = next.filter((_, i) => i !== paneIdx); + setActivePaneIdx((ai) => Math.min(ai, spliced.length - 1)); + return spliced; + } next[paneIdx] = { ...pane, kind: 'empty', chatId: undefined, chatIds: [], activeChatIdx: -1 }; } else { const nextActiveIdx = Math.min(pane.activeChatIdx, nextIds.length - 1);