fix: restore Hermes session history listing (#716)
This commit is contained in:
@@ -114,7 +114,7 @@ export async function listHermesSessions(ctx: any) {
|
||||
const profile = getActiveProfileName()
|
||||
const effectiveLimit = limit && limit > 0 ? limit : 2000
|
||||
|
||||
const allSessions = localListSessions(profile, source, effectiveLimit)
|
||||
const allSessions = await listSessionSummaries(source, effectiveLimit, profile)
|
||||
ctx.body = { sessions: filterPendingDeletedSessions(allSessions.filter(s => s.source !== 'api_server')) }
|
||||
}
|
||||
|
||||
|
||||
@@ -86,18 +86,19 @@ function normalizeNullableString(value: unknown): string | null {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function titleFromPreview(preview: string): string | null {
|
||||
if (!preview) return null
|
||||
return preview.length > 40 ? `${preview.slice(0, 40)}...` : preview
|
||||
}
|
||||
|
||||
function mapRow(row: Record<string, unknown>): HermesSessionRow {
|
||||
const startedAt = normalizeNumber(row.started_at)
|
||||
const rawTitle = normalizeNullableString(row.title)
|
||||
const preview = String(row.preview || '')
|
||||
// Fallback: when no explicit title, use first user message as title (same as CLI path)
|
||||
const title = rawTitle || (preview ? (preview.length > 40 ? preview.slice(0, 40) + '...' : preview) : null)
|
||||
return {
|
||||
id: String(row.id || ''),
|
||||
source: String(row.source || ''),
|
||||
user_id: normalizeNullableString(row.user_id),
|
||||
model: String(row.model || ''),
|
||||
title,
|
||||
title: normalizeNullableString(row.title),
|
||||
started_at: startedAt,
|
||||
ended_at: normalizeNullableNumber(row.ended_at),
|
||||
end_reason: normalizeNullableString(row.end_reason),
|
||||
@@ -373,12 +374,13 @@ function latestSessionInChain(chain: HermesSessionInternalRow[]): HermesSessionI
|
||||
|
||||
function projectSessionSummary(root: HermesSessionInternalRow, chain: HermesSessionInternalRow[]): HermesSessionRow {
|
||||
const latest = latestSessionInChain(chain)
|
||||
const firstPreview = chain.map(session => session.preview).find(Boolean) || root.preview
|
||||
const { parent_session_id: _parentSessionId, ...rootRow } = root
|
||||
return {
|
||||
...rootRow,
|
||||
id: latest.id,
|
||||
model: latest.model || root.model,
|
||||
title: latest.title || root.title,
|
||||
title: latest.title || root.title || titleFromPreview(firstPreview),
|
||||
ended_at: latest.ended_at,
|
||||
end_reason: latest.end_reason,
|
||||
message_count: latest.message_count,
|
||||
@@ -392,7 +394,7 @@ function projectSessionSummary(root: HermesSessionInternalRow, chain: HermesSess
|
||||
estimated_cost_usd: latest.estimated_cost_usd,
|
||||
actual_cost_usd: latest.actual_cost_usd,
|
||||
cost_status: latest.cost_status,
|
||||
preview: latest.preview || root.preview,
|
||||
preview: latest.preview || root.preview || firstPreview || '',
|
||||
last_active: latest.last_active || root.last_active,
|
||||
}
|
||||
}
|
||||
@@ -543,7 +545,7 @@ function aggregateSessionDetail(
|
||||
...rootRow,
|
||||
id: requestedSessionId,
|
||||
source: latest.source || root.source,
|
||||
title: latest.title || root.title || (firstPreview ? (firstPreview.length > 40 ? `${firstPreview.slice(0, 40)}...` : firstPreview) : null),
|
||||
title: latest.title || root.title || titleFromPreview(firstPreview),
|
||||
preview: latest.preview || root.preview || firstPreview || '',
|
||||
model: latest.model || root.model,
|
||||
ended_at: latest.ended_at,
|
||||
|
||||
Reference in New Issue
Block a user