759481b621
Move request and response schemas into matching subdirectories, extract the shared chat lock type, and update barrels and imports without changing wire formats.
35 lines
926 B
TypeScript
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);
|
|
}
|
|
}
|