File size: 2,184 Bytes
9b9eafc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | // 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<string, unknown>;
}
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<string, { type: 'string' | 'number' | 'boolean' | 'object' | 'array'; description?: string }>;
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<string, string>;
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;
}
|