/** * 聊天历史响应 * 原始 Dart: ChatHistoryResponse (lib/data/models/chat/chat_response.dart) */ import { z } from "zod"; import { ChatMessage, ChatMessageSchema } from "./chat_message"; export const ChatHistoryResponseSchema = z.object({ messages: z.array(ChatMessageSchema), total: z.number().default(0), limit: z.number(), offset: z.number(), }); export type ChatHistoryResponseInput = z.input; export type ChatHistoryResponseData = z.output; export class ChatHistoryResponse { declare readonly messages: ChatMessage[]; declare readonly total: number; declare readonly limit: number; declare readonly offset: number; private constructor(input: ChatHistoryResponseInput) { const data = ChatHistoryResponseSchema.parse(input); Object.assign(this, data); Object.freeze(this); } static from(input: ChatHistoryResponseInput): ChatHistoryResponse { return new ChatHistoryResponse(input); } static fromJson(json: unknown): ChatHistoryResponse { return ChatHistoryResponse.from(json as ChatHistoryResponseInput); } toJson(): ChatHistoryResponseData { return ChatHistoryResponseSchema.parse(this); } }