Compare commits

...

2 Commits

Author SHA1 Message Date
openhands
29ce9f9822 Fix linting issues in use-update-conversation.ts 2025-04-24 20:23:52 +00:00
openhands
b29252fbef Fix title tag synchronization issues 2025-04-24 20:19:24 +00:00
3 changed files with 32 additions and 8 deletions

View File

@@ -11,8 +11,14 @@ export const useUpdateConversation = () => {
conversation: Partial<Omit<Conversation, "id">>;
}) =>
OpenHands.updateUserConversation(variables.id, variables.conversation),
onSuccess: () => {
onSuccess: (_, variables) => {
// Invalidate the conversations list
queryClient.invalidateQueries({ queryKey: ["user", "conversations"] });
// Also invalidate the specific conversation to ensure title updates are reflected
queryClient.invalidateQueries({
queryKey: ["user", "conversation", variables.id],
});
},
});
};

View File

@@ -7,6 +7,6 @@ export const useUserConversation = (cid: string | null) =>
queryFn: () => OpenHands.getConversation(cid!),
enabled: !!cid,
retry: false,
staleTime: 1000 * 60 * 5, // 5 minutes
staleTime: 1000 * 30, // 30 seconds - reduced from 5 minutes for more responsive title updates
gcTime: 1000 * 60 * 15, // 15 minutes
});

View File

@@ -48,6 +48,7 @@ export function useAutoTitle() {
return;
}
// Request title generation from the backend
updateConversation(
{
id: conversationId,
@@ -56,13 +57,30 @@ export function useAutoTitle() {
{
onSuccess: async () => {
try {
const updatedConversation =
await OpenHands.getConversation(conversationId);
// Add a small delay to allow the backend to generate the title
// This helps avoid race conditions where we fetch before the title is ready
setTimeout(async () => {
try {
const updatedConversation =
await OpenHands.getConversation(conversationId);
queryClient.setQueryData(
["user", "conversation", conversationId],
updatedConversation,
);
if (updatedConversation && updatedConversation.title) {
queryClient.setQueryData(
["user", "conversation", conversationId],
updatedConversation,
);
} else {
// If we still don't have a title, invalidate the query to trigger a refetch
queryClient.invalidateQueries({
queryKey: ["user", "conversation", conversationId],
});
}
} catch (error) {
queryClient.invalidateQueries({
queryKey: ["user", "conversation", conversationId],
});
}
}, 1000); // 1 second delay
} catch (error) {
queryClient.invalidateQueries({
queryKey: ["user", "conversation", conversationId],