PI / src /shared /types.ts
noodcon's picture
Upload 64 files
9b9eafc verified
Raw
History Blame Contribute Delete
2.18 kB
// 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;
}