Files
cozsweet-frontend-nextjs/src/data/dto/chat/response/chat_history_response.ts
T
admin 759481b621 refactor(schemas): group network schemas by direction
Move request and response schemas into matching subdirectories, extract the shared chat lock type, and update barrels and imports without changing wire formats.
2026-07-14 15:12:19 +08:00

35 lines
926 B
TypeScript

/**
* 聊天历史响应 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);
}
}