@@ -29,6 +29,8 @@ import { ThreadError, UpgradeDialog, ThreadLayout } from '../_components';
29
29
import { useVncPreloader } from '@/hooks/useVncPreloader' ;
30
30
import { useThreadAgent } from '@/hooks/react-query/agents/use-agents' ;
31
31
import { AgentRunLimitDialog } from '@/components/thread/agent-run-limit-dialog' ;
32
+ import { useQueryClient } from '@tanstack/react-query' ;
33
+ import { threadKeys } from '@/hooks/react-query/threads/keys' ;
32
34
33
35
export default function ThreadPage ( {
34
36
params,
@@ -42,6 +44,7 @@ export default function ThreadPage({
42
44
const { projectId, threadId } = unwrappedParams ;
43
45
const isMobile = useIsMobile ( ) ;
44
46
const searchParams = useSearchParams ( ) ;
47
+ const queryClient = useQueryClient ( ) ;
45
48
46
49
// State
47
50
const [ newMessage , setNewMessage ] = useState ( '' ) ;
@@ -61,7 +64,7 @@ export default function ThreadPage({
61
64
runningCount : number ;
62
65
runningThreadIds : string [ ] ;
63
66
} | null > ( null ) ;
64
-
67
+
65
68
66
69
// Refs - simplified for flex-column-reverse
67
70
const latestMessageRef = useRef < HTMLDivElement > ( null ) ;
@@ -184,14 +187,14 @@ export default function ThreadPage({
184
187
} else {
185
188
// If this is a user message, replace any optimistic user message with temp ID
186
189
if ( message . type === 'user' ) {
187
- const optimisticIndex = prev . findIndex ( m =>
188
- m . type === 'user' &&
190
+ const optimisticIndex = prev . findIndex ( m =>
191
+ m . type === 'user' &&
189
192
m . message_id ?. startsWith ( 'temp-' ) &&
190
193
m . content === message . content
191
194
) ;
192
195
if ( optimisticIndex !== - 1 ) {
193
196
// Replace the optimistic message with the real one
194
- return prev . map ( ( m , index ) =>
197
+ return prev . map ( ( m , index ) =>
195
198
index === optimisticIndex ? message : m
196
199
) ;
197
200
}
@@ -329,7 +332,7 @@ export default function ThreadPage({
329
332
if ( error instanceof AgentRunLimitError ) {
330
333
console . log ( "Caught AgentRunLimitError:" , error . detail ) ;
331
334
const { running_thread_ids, running_count } = error . detail ;
332
-
335
+
333
336
// Show the dialog with limit information
334
337
setAgentLimitData ( {
335
338
runningCount : running_count ,
@@ -460,13 +463,13 @@ export default function ThreadPage({
460
463
} , [ initialPanelOpenAttempted , messages , toolCalls , initialLoadCompleted , setIsSidePanelOpen , setCurrentToolIndex ] ) ;
461
464
462
465
useEffect ( ( ) => {
463
- console . log ( '[STREAM STUFF] Stream effect triggered:' , {
464
- agentRunId,
465
- currentHookRunId,
466
- initialLoadCompleted,
467
- userInitiatedRun
466
+ console . log ( '[STREAM STUFF] Stream effect triggered:' , {
467
+ agentRunId,
468
+ currentHookRunId,
469
+ initialLoadCompleted,
470
+ userInitiatedRun
468
471
} ) ;
469
-
472
+
470
473
// Start streaming if user initiated a run (don't wait for initialLoadCompleted for first-time users)
471
474
if ( agentRunId && agentRunId !== currentHookRunId && userInitiatedRun ) {
472
475
console . log ( '[STREAM STUFF] User-initiated stream starting for agentRunId:' , agentRunId ) ;
@@ -575,12 +578,12 @@ export default function ThreadPage({
575
578
useEffect ( ( ) => {
576
579
const handleScroll = ( ) => {
577
580
if ( ! scrollContainerRef . current ) return ;
578
-
581
+
579
582
const scrollTop = scrollContainerRef . current . scrollTop ;
580
583
const scrollHeight = scrollContainerRef . current . scrollHeight ;
581
584
const clientHeight = scrollContainerRef . current . clientHeight ;
582
585
const threshold = 100 ;
583
-
586
+
584
587
// With flex-column-reverse, scrollTop becomes NEGATIVE when scrolling up
585
588
// Show button when scrollTop < -threshold (scrolled up enough from bottom)
586
589
const shouldShow = scrollTop < - threshold && scrollHeight > clientHeight ;
@@ -592,7 +595,7 @@ export default function ThreadPage({
592
595
scrollContainer . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
593
596
// Check initial state
594
597
setTimeout ( ( ) => handleScroll ( ) , 100 ) ;
595
-
598
+
596
599
return ( ) => {
597
600
scrollContainer . removeEventListener ( 'scroll' , handleScroll ) ;
598
601
} ;
0 commit comments