feat: clear ongoingResearchId on failure

This commit is contained in:
Yu Chao
2025-04-28 11:38:40 +08:00
parent 53d5b68ac8
commit 834d5221ca

View File

@@ -25,7 +25,9 @@ export const useStore = create<{
researchActivityIds: Map<string, string[]>; researchActivityIds: Map<string, string[]>;
ongoingResearchId: string | null; ongoingResearchId: string | null;
openResearchId: string | null; openResearchId: string | null;
}>(() => ({
setOngoingResearchId: (value: string | null) => void;
}>((set) => ({
responding: false, responding: false,
threadId: THREAD_ID, threadId: THREAD_ID,
messageIds: [], messageIds: [],
@@ -36,6 +38,10 @@ export const useStore = create<{
researchActivityIds: new Map<string, string[]>(), researchActivityIds: new Map<string, string[]>(),
ongoingResearchId: null, ongoingResearchId: null,
openResearchId: null, openResearchId: null,
setOngoingResearchId(value: string | null) {
set({ ongoingResearchId: value });
}
})); }));
export async function sendMessage( export async function sendMessage(
@@ -64,14 +70,14 @@ export async function sendMessage(
const mcpServers = settings.mcp.servers.filter((server) => server.enabled); const mcpServers = settings.mcp.servers.filter((server) => server.enabled);
let mcpSettings: let mcpSettings:
| { | {
servers: Record< servers: Record<
string, string,
MCPServerMetadata & { MCPServerMetadata & {
enabled_tools: string[]; enabled_tools: string[];
add_to_agents: string[]; add_to_agents: string[];
} }
>; >;
} }
| undefined = undefined; | undefined = undefined;
if (mcpServers.length > 0) { if (mcpServers.length > 0) {
mcpSettings = { mcpSettings = {
@@ -143,6 +149,8 @@ export async function sendMessage(
updateMessage(message); updateMessage(message);
} }
} }
} catch {
setOngoingResearchId(null);
} finally { } finally {
setResponding(false); setResponding(false);
} }
@@ -215,9 +223,7 @@ function getOngoingResearchId() {
} }
function setOngoingResearchId(value: string | null) { function setOngoingResearchId(value: string | null) {
return useStore.setState({ useStore.getState().setOngoingResearchId(value);
ongoingResearchId: value,
});
} }
function appendResearch(researchId: string) { function appendResearch(researchId: string) {