// Chat-related type definitions — ported and simplified from pi-web's lib/types.ts export interface TextContent { type: "text"; text: string; } export interface ImageContent { type: "image"; source: { type: "base64" | "url"; media_type?: string; data?: string; url?: string; }; } export interface ThinkingContent { type: "thinking"; thinking: string; deferred?: boolean; } export interface ToolCallContent { type: "toolCall"; toolCallId: string; toolName: string; input: Record; } export type AssistantContentBlock = TextContent | ImageContent | ThinkingContent | ToolCallContent; export interface UserMessage { role: "user"; content: string | (TextContent | ImageContent)[]; timestamp?: number; } export interface AssistantMessage { role: "assistant"; content: AssistantContentBlock[]; model: string; provider: string; stopReason?: string; errorMessage?: string; timestamp?: number; usage?: { input: number; output: number; cacheRead: number; cacheWrite: number; cost: { input: number; output: number; cacheRead: number; cacheWrite: number; total: number; }; }; } export interface ToolResultMessage { role: "toolResult"; toolCallId: string; toolName?: string; content: (TextContent | ImageContent)[]; isError?: boolean; details?: unknown; timestamp?: number; } export interface CustomMessage { role: "custom"; customType: string; content: string | (TextContent | ImageContent)[]; display: boolean; details?: unknown; timestamp?: number; } export interface BashExecutionMessage { role: "bashExecution"; command: string; output: string; exitCode?: number; cancelled?: boolean; truncated?: boolean; fullOutputPath?: string; excludeFromContext?: boolean; timestamp?: number; } export type AgentMessage = UserMessage | AssistantMessage | ToolResultMessage | CustomMessage | BashExecutionMessage; export interface SessionInfo { path: string; id: string; cwd: string; name?: string; created: string; modified: string; messageCount: number; firstMessage: string; parentSessionId?: string; projectRoot?: string; worktreeBranch?: string; } export interface SessionContext { messages: AgentMessage[]; entryIds: string[]; thinkingLevel: string; model: { provider: string; modelId: string } | null; } export interface SessionTreeNode { entry: { id: string; type: string }; children: SessionTreeNode[]; label?: string; compressedEntryIds?: string[]; } export interface SessionData { sessionId: string; filePath: string; tree: SessionTreeNode[]; leafId: string | null; context: SessionContext; } export interface ContextUsage { percent: number | null; contextWindow: number; tokens: number | null; } export interface SessionStatsInfo { sessionFile?: string; sessionId: string; sessionName?: string; userMessages: number; assistantMessages: number; toolCalls: number; toolResults: number; totalMessages: number; tokens: { input: number; output: number; cacheRead: number; cacheWrite: number; total: number; }; cost: number; contextUsage?: ContextUsage; } export interface AttachedImage { data: string; mimeType: string; previewUrl: string; } export interface ChatInputHandle { insertText: (text: string) => void; insertIfEmpty: (content: string) => void; prependText: (text: string) => void; addImages: (files: File[]) => void; } export interface ModelEntry { id: string; name: string; provider: string; } export interface ModelsResponse { models: Record; modelList?: ModelEntry[]; defaultModel?: { provider: string; modelId: string } | null; thinkingLevels?: Record; modelError?: string; } export interface AgentStateResponse { isStreaming?: boolean; isPromptRunning?: boolean; isBashRunning?: boolean; isCompacting?: boolean; contextUsage?: ContextUsage | null; systemPrompt?: string; thinkingLevel?: string; model?: { id: string; provider: string }; } export interface NoticeItem { id: string; message: string; type: "info" | "success" | "warning" | "error"; exiting?: boolean; } export type AgentPhase = | { kind: "waiting_model" } | { kind: "running_command" } | { kind: "running_tools"; tools: { id: string; name: string }[] } | null; export interface QueuedMessages { steering: string[]; followUp: string[]; } export interface SlashCommandInfo { name: string; description?: string; source: "extension" | "prompt" | "skill"; }