fix: restore Hermes session history listing (#716)

This commit is contained in:
ekko
2026-05-14 15:23:19 +08:00
committed by GitHub
parent f6df0fecfa
commit bd6c4dc82e
13 changed files with 28 additions and 10 deletions
+10 -8
View File
@@ -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,