VibeGame / src /lib /models /chat-data.ts
dylanebert's picture
refactor
bc7e9cd
export type MessageRole = "user" | "assistant" | "system";
export type MessageSegmentType =
| "text"
| "tool-invocation"
| "tool-result"
| "reasoning";
export type ToolStatus = "pending" | "running" | "completed" | "error";
export type StreamingStatus = "idle" | "thinking" | "streaming" | "completing";
export interface MessageSegment {
readonly id: string;
readonly type: MessageSegmentType;
readonly content: string;
readonly toolName?: string;
readonly toolArgs?: Record<string, unknown>;
readonly toolStatus?: ToolStatus;
readonly toolOutput?: string;
readonly toolResult?: string;
readonly toolError?: string;
readonly startTime?: number;
readonly endTime?: number;
readonly consoleOutput?: string[];
readonly expanded?: boolean;
readonly streaming?: boolean;
}
export interface ChatMessage {
readonly id: string;
readonly role: MessageRole;
readonly content: string;
readonly timestamp: number;
readonly streaming?: boolean;
readonly reasoning?: string;
readonly showReasoning?: boolean;
readonly segments?: ReadonlyArray<MessageSegment>;
}
export interface ChatState {
readonly messages: ReadonlyArray<ChatMessage>;
readonly connected: boolean;
readonly processing: boolean;
readonly error: string | null;
readonly streamingContent: string;
readonly streamingStatus: StreamingStatus;
readonly thinkingStartTime: number | null;
}
export function createMessage(
role: MessageRole,
content: string,
id?: string,
): ChatMessage {
return {
id: id || `${role}_${Date.now()}`,
role,
content,
timestamp: Date.now(),
streaming: false,
};
}
export function createSegment(
type: MessageSegmentType,
content: string = "",
id?: string,
): MessageSegment {
return {
id: id || `seg_${Date.now()}`,
type,
content,
streaming: type === "text",
startTime: Date.now(),
};
}
export function createInitialChatState(): ChatState {
return {
messages: [],
connected: false,
processing: false,
error: null,
streamingContent: "",
streamingStatus: "idle",
thinkingStartTime: null,
};
}