Track how long each assistant response took to generate and display it subtly next to the timestamp (e.g. '· 12.3s'). The timing is measured from the first streaming delta to the final state, and preserved across the history reload that follows stream completion. Only visible for messages generated during the current session.
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
export interface ChatMessage {
|
|
id: string;
|
|
role: 'user' | 'assistant';
|
|
content: string;
|
|
timestamp: number;
|
|
blocks: MessageBlock[];
|
|
isStreaming?: boolean;
|
|
runId?: string;
|
|
isSystemEvent?: boolean;
|
|
metadata?: Record<string, unknown>;
|
|
/** Optimistic send status for user messages */
|
|
sendStatus?: 'sending' | 'sent' | 'error';
|
|
/** Timestamp (ms) when streaming started for this message */
|
|
streamStartedAt?: number;
|
|
/** Total generation time in milliseconds (set when streaming ends) */
|
|
generationTimeMs?: number;
|
|
}
|
|
|
|
export type MessageBlock =
|
|
| { type: 'text'; text: string }
|
|
| { type: 'thinking'; text: string }
|
|
| { type: 'tool_use'; name: string; input: Record<string, unknown>; id?: string }
|
|
| { type: 'tool_result'; content: string; toolUseId?: string; name?: string }
|
|
| { type: 'image'; mediaType: string; data?: string; url?: string };
|
|
|
|
export interface Session {
|
|
key: string;
|
|
label?: string;
|
|
messageCount?: number;
|
|
isActive?: boolean;
|
|
hasUnread?: boolean;
|
|
totalTokens?: number;
|
|
contextTokens?: number;
|
|
inputTokens?: number;
|
|
outputTokens?: number;
|
|
channel?: string;
|
|
kind?: string;
|
|
model?: string;
|
|
agentId?: string;
|
|
updatedAt?: number;
|
|
lastMessagePreview?: string;
|
|
}
|
|
|
|
export interface AgentIdentity {
|
|
name?: string;
|
|
emoji?: string;
|
|
avatar?: string;
|
|
agentId?: string;
|
|
}
|
|
|
|
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected';
|
|
|
|
export interface GatewayState {
|
|
status: ConnectionStatus;
|
|
sessions: Session[];
|
|
activeSession: string;
|
|
messages: ChatMessage[];
|
|
isGenerating: boolean;
|
|
}
|