40 lines
1018 B
TypeScript
40 lines
1018 B
TypeScript
/**
|
|
* 最近记忆模型
|
|
* 原始 Dart: RecentMemory (lib/data/models/user/recent_memory.dart)
|
|
*/
|
|
import { z } from "zod";
|
|
|
|
export const RecentMemorySchema = z.object({
|
|
type: z.string(),
|
|
content: z.string(),
|
|
importance: z.number(),
|
|
createdAt: z.string().default(""),
|
|
});
|
|
|
|
export type RecentMemoryInput = z.input<typeof RecentMemorySchema>;
|
|
export type RecentMemoryData = z.output<typeof RecentMemorySchema>;
|
|
|
|
export class RecentMemory {
|
|
declare readonly type: string;
|
|
declare readonly content: string;
|
|
declare readonly importance: number;
|
|
declare readonly createdAt: string;
|
|
|
|
private constructor(data: RecentMemoryData) {
|
|
Object.assign(this, data);
|
|
Object.freeze(this);
|
|
}
|
|
|
|
static from(input: RecentMemoryInput): RecentMemory {
|
|
return new RecentMemory(RecentMemorySchema.parse(input));
|
|
}
|
|
|
|
static fromJson(json: unknown): RecentMemory {
|
|
return RecentMemory.from(json as RecentMemoryInput);
|
|
}
|
|
|
|
toJson(): RecentMemoryData {
|
|
return RecentMemorySchema.parse(this);
|
|
}
|
|
}
|