Add session duration computation to discovery pipeline
Extend SessionEntry with an optional duration field (milliseconds) computed from the delta between created and modified timestamps. The computeDuration helper handles missing or invalid dates gracefully, returning 0 for any edge case. This enables downstream UI to show how long each session lasted without additional API calls. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,7 @@ export async function discoverSessions(
|
||||
modified: entry.modified || "",
|
||||
messageCount: entry.messageCount || 0,
|
||||
path: resolved,
|
||||
duration: computeDuration(entry.created, entry.modified),
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
@@ -102,3 +103,12 @@ export async function discoverSessions(
|
||||
|
||||
return sessions;
|
||||
}
|
||||
|
||||
function computeDuration(created?: string, modified?: string): number {
|
||||
if (!created || !modified) return 0;
|
||||
const createdMs = new Date(created).getTime();
|
||||
const modifiedMs = new Date(modified).getTime();
|
||||
if (isNaN(createdMs) || isNaN(modifiedMs)) return 0;
|
||||
const diff = modifiedMs - createdMs;
|
||||
return diff > 0 ? diff : 0;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface SessionEntry {
|
||||
modified: string;
|
||||
messageCount: number;
|
||||
path: string;
|
||||
duration?: number; // Duration in milliseconds from first to last message
|
||||
}
|
||||
|
||||
export interface SessionListResponse {
|
||||
|
||||
Reference in New Issue
Block a user