Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ui/desktop/src/components/BaseChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface BaseChatProps {
}

function BaseChatContent({
setChat,
Comment thread
angiejones marked this conversation as resolved.
renderHeader,
customChatInputProps = {},
customMainLayoutProps = {},
Expand Down Expand Up @@ -301,6 +302,23 @@ function BaseChatContent({
name: session?.name || 'No Session',
};

// Update the global chat context when session name changes
const lastSetNameRef = useRef<string>('');

useEffect(() => {
const currentSessionName = session?.name;
if (currentSessionName && currentSessionName !== lastSetNameRef.current) {
lastSetNameRef.current = currentSessionName;
setChat({
messages,
recipe,
sessionId,
name: currentSessionName,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session?.name, setChat]);

Comment thread
angiejones marked this conversation as resolved.
// Only use initialMessage for the prompt if it hasn't been submitted yet
// If we have a recipe prompt and user recipe values, substitute parameters
let recipePrompt = '';
Expand Down
26 changes: 26 additions & 0 deletions ui/desktop/src/hooks/useChatStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { ChatState } from '../types/chatState';

import {
getSession,
Message,
MessageEvent,
reply,
Expand Down Expand Up @@ -209,6 +210,31 @@ export function useChatStream({
window.dispatchEvent(new CustomEvent('message-stream-finished'));
}

// Refresh session name after each reply for the first 3 user messages
// The backend regenerates the name after each of the first 3 user messages
// to refine it as more context becomes available
if (!error && sessionId) {
const userMessageCount = messagesRef.current.filter(
(m) => m.role === 'user'
).length;

// Only refresh for the first 3 user messages
if (userMessageCount <= 3) {
try {
const response = await getSession({
path: { session_id: sessionId },
throwOnError: true,
});
if (response.data?.name) {
setSession((prev) => (prev ? { ...prev, name: response.data.name } : prev));
}
} catch (refreshError) {
// Silently fail - this is a nice-to-have feature
console.warn('Failed to refresh session name:', refreshError);
}
}
}

setChatState(ChatState.Idle);
onStreamFinish();
},
Expand Down
Loading