HEL-748: implement S1 frontend with explicit local demo

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
白栖知
2026-10-22 00:56:18 +08:00
co-authored by multica-agent
parent 1e9b08aed8
commit 6c3b09e693
39 changed files with 5414 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
// Demo identity and turn identifiers must also work on the first intranet HTTP preview.
// getRandomValues is available there even where randomUUID requires a secure context.
export function newId(): string {
if (typeof crypto.randomUUID === 'function') return crypto.randomUUID();
const bytes = crypto.getRandomValues(new Uint8Array(16));
bytes[6] = (bytes[6] & 15) | 64;
bytes[8] = (bytes[8] & 63) | 128;
const hex = [...bytes].map(v => v.toString(16).padStart(2, '0')).join('');
return `${hex.slice(0,8)}-${hex.slice(8,12)}-${hex.slice(12,16)}-${hex.slice(16,20)}-${hex.slice(20)}`;
}
+86
View File
@@ -0,0 +1,86 @@
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 '';
}
+12
View File
@@ -0,0 +1,12 @@
import type { DemoState, LifeEvent } from './model';
// Fail closed, including unknown references. Real API must apply this BEFORE transmission.
export const sharedEvents = (events: LifeEvent[]) => events.filter(e => e.shared === true);
export function publicView(state: DemoState): DemoState {
const events = sharedEvents(state.events);
const ids = new Set(events.map(e => e.id));
const allowed = (refs: string[]) => refs.every(id => ids.has(id));
const memories = state.memories.filter(m => allowed(m.lifeIds));
const memoryIds = new Set(memories.map(m => m.id));
return { ...state, events: events.map(e => ({ ...e, memoryIds: e.memoryIds.filter(id => memoryIds.has(id)) })), memories, messages: state.messages.filter(m => allowed(m.lifeIds)) };
}
export function eventById(state: DemoState, id: string) { return publicView(state).events.find(e => e.id === id); }