{threads.map((thread) => {
- const isActive = pathOfThread(thread, false) === pathname;
+ const isActive = pathOfThread(thread.thread_id) === pathname;
return (
{titleOfThread(thread)}
diff --git a/frontend/src/core/threads/hooks.ts b/frontend/src/core/threads/hooks.ts
index f0c642a..d472cac 100644
--- a/frontend/src/core/threads/hooks.ts
+++ b/frontend/src/core/threads/hooks.ts
@@ -22,16 +22,37 @@ export function useThreadStream({
threadId: string | null | undefined;
}) {
const queryClient = useQueryClient();
- return useStream({
+ const thread = useStream({
client: getAPIClient(),
assistantId: "lead_agent",
threadId: isNewThread ? undefined : threadId,
reconnectOnMount: true,
fetchStateHistory: true,
- onFinish() {
- void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
+ onFinish(state) {
+ // void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
+ queryClient.setQueriesData(
+ {
+ queryKey: ["threads", "search"],
+ exact: false,
+ },
+ (oldData: Array) => {
+ return oldData.map((t) => {
+ if (t.thread_id === threadId) {
+ return {
+ ...t,
+ values: {
+ ...t.values,
+ title: state.values.title,
+ },
+ };
+ }
+ return t;
+ });
+ },
+ );
},
});
+ return thread;
}
export function useSubmitThread({
@@ -39,43 +60,47 @@ export function useSubmitThread({
thread,
threadContext,
isNewThread,
- message,
+ afterSubmit,
}: {
isNewThread: boolean;
- threadId: string;
+ threadId: string | null | undefined;
thread: UseStream;
- threadContext: AgentThreadContext;
- message: PromptInputMessage;
+ threadContext: Omit;
+ afterSubmit?: () => void;
}) {
const queryClient = useQueryClient();
- const text = message.text.trim();
- const callback = useCallback(async () => {
- await thread.submit(
- {
- messages: [
- {
- type: "human",
- content: [
- {
- type: "text",
- text,
- },
- ],
- },
- ] as HumanMessage[],
- },
- {
- threadId: isNewThread ? threadId : undefined,
- streamSubgraphs: true,
- streamResumable: true,
- context: {
- ...threadContext,
- thread_id: threadId,
+ const callback = useCallback(
+ async (message: PromptInputMessage) => {
+ const text = message.text.trim();
+ await thread.submit(
+ {
+ messages: [
+ {
+ type: "human",
+ content: [
+ {
+ type: "text",
+ text,
+ },
+ ],
+ },
+ ] as HumanMessage[],
},
- },
- );
- void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
- }, [queryClient, thread, threadContext, threadId, isNewThread, text]);
+ {
+ threadId: isNewThread ? threadId! : undefined,
+ streamSubgraphs: true,
+ streamResumable: true,
+ context: {
+ ...threadContext,
+ thread_id: threadId,
+ },
+ },
+ );
+ void queryClient.invalidateQueries({ queryKey: ["threads", "search"] });
+ afterSubmit?.();
+ },
+ [thread, isNewThread, threadId, threadContext, queryClient, afterSubmit],
+ );
return callback;
}
@@ -86,12 +111,11 @@ export function useThreads(
sortOrder: "desc",
},
) {
- const langGraphClient = getAPIClient();
+ const apiClient = getAPIClient();
return useQuery({
queryKey: ["threads", "search", params],
queryFn: async () => {
- const response =
- await langGraphClient.threads.search(params);
+ const response = await apiClient.threads.search(params);
return response as AgentThread[];
},
});
@@ -99,10 +123,10 @@ export function useThreads(
export function useDeleteThread() {
const queryClient = useQueryClient();
- const langGraphClient = getAPIClient();
+ const apiClient = getAPIClient();
return useMutation({
mutationFn: async ({ threadId }: { threadId: string }) => {
- await langGraphClient.threads.delete(threadId);
+ await apiClient.threads.delete(threadId);
},
onSuccess(_, { threadId }) {
queryClient.setQueriesData(