From 3721c82ba838d59c4e3ad70b4e2466293bb275af Mon Sep 17 00:00:00 2001 From: JeffJiang Date: Sun, 8 Mar 2026 21:15:03 +0800 Subject: [PATCH] Update Nginx configuration for uploads and improve thread ID handling (#1023) * fix: update nginx configuration for uploads endpoint and improve thread ID handling in hooks * Update docker/nginx/nginx.local.conf Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update frontend/src/core/threads/hooks.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docker/nginx/nginx.conf | 20 ++++++++++---------- docker/nginx/nginx.local.conf | 28 ++++++++++++++-------------- frontend/src/core/threads/hooks.ts | 30 ++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 9513cac..8cb01a5 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -130,16 +130,6 @@ http { proxy_set_header X-Forwarded-Proto $scheme; } - # Custom API: Artifacts endpoint - location ~ ^/api/threads/[^/]+/artifacts { - proxy_pass http://gateway; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - # Custom API: Uploads endpoint location ~ ^/api/threads/[^/]+/uploads { proxy_pass http://gateway; @@ -154,6 +144,16 @@ http { proxy_request_buffering off; } + # Custom API: Other endpoints under /api/threads + location ~ ^/api/threads { + proxy_pass http://gateway; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + # API Documentation: Swagger UI location /docs { proxy_pass http://gateway; diff --git a/docker/nginx/nginx.local.conf b/docker/nginx/nginx.local.conf index 43e70bc..289c388 100644 --- a/docker/nginx/nginx.local.conf +++ b/docker/nginx/nginx.local.conf @@ -14,17 +14,17 @@ http { access_log logs/nginx-access.log; error_log logs/nginx-error.log; - # Upstream servers (using localhost for local development) + # Upstream servers (using 127.0.0.1 for local development) upstream gateway { - server localhost:8001; + server 127.0.0.1:8001; } upstream langgraph { - server localhost:2024; + server 127.0.0.1:2024; } upstream frontend { - server localhost:3000; + server 127.0.0.1:3000; } server { @@ -126,16 +126,6 @@ http { proxy_set_header X-Forwarded-Proto $scheme; } - # Custom API: Artifacts endpoint - location ~ ^/api/threads/[^/]+/artifacts { - proxy_pass http://gateway; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - # Custom API: Uploads endpoint location ~ ^/api/threads/[^/]+/uploads { proxy_pass http://gateway; @@ -150,6 +140,16 @@ http { proxy_request_buffering off; } + # Custom API: Other endpoints under /api/threads + location ~ ^/api/threads { + proxy_pass http://gateway; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + # API Documentation: Swagger UI location /docs { proxy_pass http://gateway; diff --git a/frontend/src/core/threads/hooks.ts b/frontend/src/core/threads/hooks.ts index 0cc8ed2..3cab73e 100644 --- a/frontend/src/core/threads/hooks.ts +++ b/frontend/src/core/threads/hooks.ts @@ -40,6 +40,10 @@ export function useThreadStream({ onToolEnd, }: ThreadStreamOptions) { const { t } = useI18n(); + // Track the thread ID that is currently streaming to handle thread changes during streaming + const [onStreamThreadId, setOnStreamThreadId] = useState(() => threadId); + // Ref to track current thread ID across async callbacks without causing re-renders, + // and to allow access to the current thread id in onUpdateEvent const threadIdRef = useRef(threadId ?? null); const startedRef = useRef(false); @@ -55,30 +59,40 @@ export function useThreadStream({ }, [onStart, onFinish, onToolEnd]); useEffect(() => { - if (threadIdRef.current && threadIdRef.current !== threadId) { - threadIdRef.current = threadId ?? null; + const normalizedThreadId = threadId ?? null; + if (threadIdRef.current !== normalizedThreadId) { + threadIdRef.current = normalizedThreadId; startedRef.current = false; // Reset for new thread + setOnStreamThreadId(normalizedThreadId); } }, [threadId]); - const _handleStart = useCallback((id: string) => { + const _handleOnStart = useCallback((id: string) => { if (!startedRef.current) { listeners.current.onStart?.(id); startedRef.current = true; } }, []); + const handleStreamStart = useCallback( + (_threadId: string) => { + threadIdRef.current = _threadId; + setOnStreamThreadId(_threadId); + _handleOnStart(_threadId); + }, + [_handleOnStart], + ); + const queryClient = useQueryClient(); const updateSubtask = useUpdateSubtask(); const thread = useStream({ client: getAPIClient(isMock), assistantId: "lead_agent", - threadId: threadIdRef.current, + threadId: onStreamThreadId, reconnectOnMount: true, fetchStateHistory: { limit: 1 }, onCreated(meta) { - threadIdRef.current = meta.thread_id; - _handleStart(meta.thread_id); + handleStreamStart(meta.thread_id); }, onLangChainEvent(event) { if (event.event === "on_tool_end") { @@ -194,7 +208,7 @@ export function useThreadStream({ } setOptimisticMessages(newOptimistic); - _handleStart(threadId); + _handleOnStart(threadId); let uploadedFileInfo: UploadedFileInfo[] = []; @@ -330,7 +344,7 @@ export function useThreadStream({ throw error; } }, - [thread, _handleStart, t.uploads.uploadingFiles, context, queryClient], + [thread, _handleOnStart, t.uploads.uploadingFiles, context, queryClient], ); // Merge thread with optimistic messages for display