fix(session-manager): use sdk data in getSessionInfo

This commit is contained in:
auyua9
2026-04-05 12:38:50 +08:00
committed by YeonGyu-Kim
parent d7c2b6249b
commit 0bb16e5149
2 changed files with 84 additions and 1 deletions
+38
View File
@@ -119,5 +119,43 @@ export async function readSessionTranscript(sessionID: string): Promise<number>
}
export async function getSessionInfo(sessionID: string): Promise<SessionInfo | null> {
if (isSqliteBackend() && sdkClient) {
try {
const sdkMessages = await getSdkSessionMessages(sdkClient, sessionID)
if (sdkMessages.length > 0) {
const agentsUsed = new Set<string>()
let firstMessage: Date | undefined
let lastMessage: Date | undefined
for (const msg of sdkMessages) {
if (msg.agent) agentsUsed.add(msg.agent)
if (msg.time?.created) {
const date = new Date(msg.time.created)
if (!firstMessage || date < firstMessage) firstMessage = date
if (!lastMessage || date > lastMessage) lastMessage = date
}
}
const todos = await readSessionTodos(sessionID)
const transcriptEntries = await readSessionTranscript(sessionID)
return {
id: sessionID,
message_count: sdkMessages.length,
first_message: firstMessage,
last_message: lastMessage,
agents_used: Array.from(agentsUsed),
has_todos: todos.length > 0,
has_transcript: transcriptEntries > 0,
todos,
transcript_entries: transcriptEntries,
}
}
} catch (error) {
if (!shouldFallbackFromSdkError(error)) throw error
log("[session-manager] falling back to file session info after SDK unavailable error", { error: String(error), sessionID })
}
}
return getFileSessionInfo(sessionID)
}