From a0ab3a3dd4c6a75a24ec99e1d5481ca4feeaeb7f Mon Sep 17 00:00:00 2001 From: rayhpeng Date: Wed, 22 Apr 2026 11:31:23 +0800 Subject: [PATCH] refactor(frontend): update thread hooks for new API structure - page.tsx - simplify thread page component - hooks.ts - enhance thread hooks with new run APIs Co-Authored-By: Claude Opus 4.5 --- .../app/workspace/chats/[thread_id]/page.tsx | 4 ---- frontend/src/core/threads/hooks.ts | 23 ++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/workspace/chats/[thread_id]/page.tsx b/frontend/src/app/workspace/chats/[thread_id]/page.tsx index 98e53e1c9..f5986d519 100644 --- a/frontend/src/app/workspace/chats/[thread_id]/page.tsx +++ b/frontend/src/app/workspace/chats/[thread_id]/page.tsx @@ -55,10 +55,6 @@ export default function ChatPage() { threadId: isNewThread ? undefined : threadId, context: settings.context, isMock, - onSend: (_threadId) => { - setThreadId(_threadId); - setIsNewThread(false); - }, onStart: (createdThreadId) => { setThreadId(createdThreadId); setIsNewThread(false); diff --git a/frontend/src/core/threads/hooks.ts b/frontend/src/core/threads/hooks.ts index aceb291c3..cd10c2f28 100644 --- a/frontend/src/core/threads/hooks.ts +++ b/frontend/src/core/threads/hooks.ts @@ -364,6 +364,27 @@ export function useThreadStream({ let uploadedFileInfo: UploadedFileInfo[] = []; try { + if (!isMock && threadId) { + await fetch(`${getBackendBaseURL()}/api/threads`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + body: JSON.stringify({ + thread_id: threadId, + assistant_id: + typeof extraContext?.agent_name === "string" + ? extraContext.agent_name + : undefined, + metadata: + typeof extraContext?.agent_name === "string" + ? { agent_name: extraContext.agent_name } + : {}, + }), + }); + } + // Upload files first if any if (message.files && message.files.length > 0) { setIsUploading(true); @@ -493,7 +514,7 @@ export function useThreadStream({ sendInFlightRef.current = false; } }, - [thread, t.uploads.uploadingFiles, context, queryClient], + [thread, t.uploads.uploadingFiles, context, queryClient, isMock], ); // Cache the latest thread messages in a ref to compare against incoming history messages for deduplication,