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 <noreply@anthropic.com>
This commit is contained in:
rayhpeng 2026-04-22 11:31:23 +08:00
parent 4fa2c15613
commit a0ab3a3dd4
2 changed files with 22 additions and 5 deletions

View File

@ -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);

View File

@ -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,