/** * 聊天历史响应 DTO */ import { ChatHistoryResponseSchema, type ChatHistoryResponseInput, type ChatHistoryResponseData, } from "@/data/schemas/chat/response/chat_history_response"; import { ChatMessage } from "../chat_message"; export class ChatHistoryResponse { declare readonly messages: ChatMessage[]; private constructor(input: ChatHistoryResponseInput) { const data = ChatHistoryResponseSchema.parse(input); Object.assign(this, { ...data, messages: data.messages.map((m) => ChatMessage.from(m)), }); 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); } }