// Kiểu dữ liệu dùng chung giữa main thread và worker. export interface TextContent { type: 'text'; text: string; } export interface ThinkingContent { type: 'thinking'; thinking: string; } export interface ToolCall { type: 'toolCall'; id: string; name: string; arguments: Record; } export type AssistantContent = TextContent | ThinkingContent | ToolCall; export interface Usage { input: number; output: number; totalTokens: number; } export interface UserMessage { role: 'user'; content: string; timestamp: number; } export type StopReason = 'stop' | 'length' | 'toolUse' | 'error' | 'aborted'; export interface AssistantMessage { role: 'assistant'; content: AssistantContent[]; stopReason?: StopReason; errorMessage?: string; usage: Usage; timestamp: number; } export interface ToolResultMessage { role: 'toolResult'; toolCallId: string; toolName: string; content: TextContent[]; details: { exitCode?: number; path?: string }; isError: boolean; timestamp: number; } export type AgentMessage = UserMessage | AssistantMessage | ToolResultMessage; /** Schema JSON của tham số tool (đủ dùng cho chat template của MiniCPM). */ export interface ToolSchema { type: 'object'; properties: Record; required: string[]; } export interface ToolDef { name: string; label: string; description: string; parameters: ToolSchema; } /** Cặp [đường dẫn, mục] để lưu/khôi phục toàn bộ workspace (file, thư mục, symlink). */ export type SerializedEntry = | { type: 'file'; base64: string; mode: number } | { type: 'directory'; mode: number } | { type: 'symlink'; target: string }; export interface WorkspaceState { version: 1; files: Record; entries: Array<[string, SerializedEntry]>; messages: AgentMessage[]; } export interface DeviceInfo { vendor?: string; architecture?: string; maxStorageBufferBindingSize?: number; features?: string[]; } export interface ShellResult { stdout: string; stderr: string; exitCode: number; }