fix(session-manager): use sdk data in getSessionInfo
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user