feat: human-friendly session titles in header and sidebar
Replace raw session keys/UUIDs with readable names derived from session metadata (label, kind, channel). Priority: label > kind-based name (Main, Cron, Task) with channel suffix > cleaned key fallback. New utility: src/lib/sessionName.ts used by both Header and Sidebar.
This commit is contained in:
49
src/lib/sessionName.ts
Normal file
49
src/lib/sessionName.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { Session } from '../types';
|
||||
|
||||
/**
|
||||
* Derive a human-friendly display name for a session.
|
||||
*
|
||||
* Priority:
|
||||
* 1. label (if set, e.g. sub-agent labels)
|
||||
* 2. "Main" for kind=main
|
||||
* 3. Kind + channel (e.g. "Cron · telegram")
|
||||
* 4. Channel name capitalized
|
||||
* 5. Cleaned session key (strip agent:xxx: prefix, truncate UUIDs)
|
||||
*/
|
||||
export function sessionDisplayName(session: Session): string {
|
||||
if (session.label) return session.label;
|
||||
|
||||
const kind = session.kind;
|
||||
const channel = session.channel;
|
||||
|
||||
if (kind === 'main') {
|
||||
return channel ? `Main · ${capitalize(channel)}` : 'Main';
|
||||
}
|
||||
|
||||
if (kind === 'cron') {
|
||||
return channel ? `Cron · ${capitalize(channel)}` : 'Cron';
|
||||
}
|
||||
|
||||
if (kind === 'isolated') {
|
||||
return channel ? `Task · ${capitalize(channel)}` : 'Task';
|
||||
}
|
||||
|
||||
if (channel) return capitalize(channel);
|
||||
|
||||
// Fallback: clean the session key
|
||||
return cleanSessionKey(session.key);
|
||||
}
|
||||
|
||||
function capitalize(s: string): string {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||
}
|
||||
|
||||
function cleanSessionKey(key: string): string {
|
||||
// Strip "agent:<id>:" prefix
|
||||
const stripped = key.replace(/^agent:[^:]+:/, '');
|
||||
// If it looks like a UUID, show first 8 chars
|
||||
if (/^[0-9a-f]{8}-[0-9a-f]{4}-/.test(stripped)) {
|
||||
return stripped.slice(0, 8) + '…';
|
||||
}
|
||||
return stripped;
|
||||
}
|
||||
Reference in New Issue
Block a user