()
| 338 | }; |
| 339 | |
| 340 | const checkForActiveSession = async () => { |
| 341 | // If we have a session prop, check if it's still active |
| 342 | if (session) { |
| 343 | try { |
| 344 | const activeSessions = await api.listRunningClaudeSessions(); |
| 345 | const activeSession = activeSessions.find((s: any) => { |
| 346 | if ('process_type' in s && s.process_type && 'ClaudeSession' in s.process_type) { |
| 347 | return (s.process_type as any).ClaudeSession.session_id === session.id; |
| 348 | } |
| 349 | return false; |
| 350 | }); |
| 351 | |
| 352 | if (activeSession) { |
| 353 | // Session is still active, reconnect to its stream |
| 354 | console.log('[ClaudeCodeSession] Found active session, reconnecting:', session.id); |
| 355 | // IMPORTANT: Set claudeSessionId before reconnecting |
| 356 | setClaudeSessionId(session.id); |
| 357 | |
| 358 | // Don't add buffered messages here - they've already been loaded by loadSessionHistory |
| 359 | // Just set up listeners for new messages |
| 360 | |
| 361 | // Set up listeners for the active session |
| 362 | reconnectToSession(session.id); |
| 363 | } |
| 364 | } catch (err) { |
| 365 | console.error('Failed to check for active sessions:', err); |
| 366 | } |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | const reconnectToSession = async (sessionId: string) => { |
| 371 | console.log('[ClaudeCodeSession] Reconnecting to session:', sessionId); |
no test coverage detected