Files
CyberGril/web/src/domain/model.ts
T
2026-10-22 00:56:18 +08:00

87 lines
2.4 KiB
TypeScript

export type Theme = 'moon' | 'fog';
export type Relation = '朋友' | '恋人';
export interface Identity {
id: string;
name: string;
birth: string;
hour: string;
relation: Relation;
nickname: string;
boundary: string;
}
export interface Settings {
city: string;
appearance: string;
reduced: boolean;
services: Record<string, string>;
}
export interface LifeEvent {
id: string;
title: string;
text: string;
time: string;
place: string;
kind: 'done' | 'now' | 'plan';
shared: boolean;
memoryIds: string[];
}
export interface Memory {
id: string;
title: string;
text: string;
group: string;
source: string;
lifeIds: string[];
}
export interface Message {
id: string;
role: 'user' | 'companion';
text: string;
lifeIds: string[];
turnId?: string;
status?: 'pending' | 'failed' | 'sent' | 'cancelled';
proactive?: boolean;
}
export interface DemoState {
version: 1;
identity: Identity;
settings: Settings;
events: LifeEvent[];
memories: Memory[];
messages: Message[];
lastVisit: number;
}
export interface SceneDesc {
mode: 'daily' | 'talk';
activity: string;
time_band: string;
weather: string;
outfit: string;
}
export type ServerEvent = {
t: 'chat.delta';
epoch: number;
turn_id: string;
delta: string;
} | {
t: 'chat.final';
epoch: number;
turn_id: string;
utterance: {
text: string;
speech_tags: string[];
};
};
export const defaultSettings: Settings = { city: '杭州', appearance: 'reference-v1', reduced: false, services: { '对话模型': '', 'ASR': '', 'TTS': '', '视觉观察': '' } };
export function validateCreation(name: string, birth: string, relation: string, now = new Date()): string {
if (!name.trim() || name.trim().length > 20 || (/[<>]/u.test(name) || [...name].some(c => c.charCodeAt(0) < 32)))
return '请为她起一个 1–20 字的名字,不含控制字符或尖括号。';
const d = new Date(birth + 'T00:00:00');
const limit = new Date(now.getFullYear() - 18, now.getMonth(), now.getDate());
if (!/^\d{4}-\d{2}-\d{2}$/.test(birth) || !Number.isFinite(d.getTime()) || d > limit || d.getFullYear() < 1900)
return '请填写有效的出生日期,且已满 18 岁。';
if (!['朋友', '恋人'].includes(relation))
return '请亲自选择你们的关系。';
return '';
}