feat(agents): improve session ID extraction and JSONL file handling
- Fix session ID extraction to use correct field name "session_id" instead of "sessionId" - Add comprehensive database update logging with error handling - Implement cross-project session file search in get_session_output - Add new load_agent_session_history command for robust JSONL loading - Update UI components to prioritize JSONL file loading over fallback methods - Improve error handling and logging throughout the session management flow - Fix BufReader imports and alias conflicts in Tauri backend This enhances the reliability of agent session tracking and output retrieval by properly handling Claude Code's actual JSON structure and implementing better fallback mechanisms for session data access.
This commit is contained in:
@@ -109,6 +109,47 @@ export function SessionOutputViewer({ session, onClose, className }: SessionOutp
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
|
||||
// If we have a session_id, try to load from JSONL file first
|
||||
if (session.session_id && session.session_id !== '') {
|
||||
try {
|
||||
const history = await api.loadAgentSessionHistory(session.session_id);
|
||||
|
||||
// Convert history to messages format using AgentExecution style
|
||||
const loadedMessages: ClaudeStreamMessage[] = history.map(entry => ({
|
||||
...entry,
|
||||
type: entry.type || "assistant"
|
||||
}));
|
||||
|
||||
setMessages(loadedMessages);
|
||||
setRawJsonlOutput(history.map(h => JSON.stringify(h)));
|
||||
|
||||
// Update cache
|
||||
setCachedOutput(session.id, {
|
||||
output: history.map(h => JSON.stringify(h)).join('\n'),
|
||||
messages: loadedMessages,
|
||||
lastUpdated: Date.now(),
|
||||
status: session.status
|
||||
});
|
||||
|
||||
// Set up live event listeners for running sessions
|
||||
if (session.status === 'running') {
|
||||
setupLiveEventListeners();
|
||||
|
||||
try {
|
||||
await api.streamSessionOutput(session.id);
|
||||
} catch (streamError) {
|
||||
console.warn('Failed to start streaming, will poll instead:', streamError);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (err) {
|
||||
console.warn('Failed to load from JSONL, falling back to regular output:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to the original method if JSONL loading fails or no session_id
|
||||
const rawOutput = await api.getSessionOutput(session.id);
|
||||
|
||||
// Parse JSONL output into messages using AgentExecution style
|
||||
|
Reference in New Issue
Block a user