Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/lib/agents/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TextBlock } from '@/lib/types';

class SearchAgent {
async searchAsync(session: SessionManager, input: SearchAgentInput) {
try {
const exists = await db.query.messages.findFirst({
where: and(
eq(messages.chatId, input.chatId),
Expand Down Expand Up @@ -180,6 +181,24 @@ class SearchAgent {
),
)
.execute();
} catch (err) {
console.error('Search agent error:', err);

session.emit('error', {
data: err instanceof Error ? err.message : 'An error occurred during search',
});

await db
.update(messages)
.set({ status: 'error' })
.where(
and(
eq(messages.chatId, input.chatId),
eq(messages.messageId, input.messageId),
),
)
.execute();
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/lib/hooks/useChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ export const ChatProvider = ({ children }: { children: React.ReactNode }) => {
method: 'POST',
});

if (!res.ok) {
// Session no longer exists (e.g. server restarted) - mark message as error
setLoading(false);
isReconnectingRef.current = false;
setMessages((prev) =>
prev.map((msg) =>
msg.messageId === lastMsg.messageId
? { ...msg, status: 'error' as const }
: msg,
),
);
return;
}

if (!res.body) throw new Error('No response body');

const reader = res.body?.getReader();
Expand Down