Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859export type ChatMessage = { author: string; text: string; timestamp: string;};
export type AvatarAction = | { type: 'talk:start' } | { type: 'talk:stop' } | { type: 'emotion'; value: 'neutral' | 'happy' | 'excited' | 'curious' } | { type: 'gesture'; value: 'nod' | 'wave' | 'tilt' };
export type AgentResponse = { reply: string; actions: AvatarAction[]; audio?: { provider: 'gemini-live' | 'stub'; text: string; };};
export interface ResponseProvider { generateReply(message: ChatMessage): Promise<string>;}
function planAvatarActions(reply: string): AvatarAction[] { const lower = reply.toLowerCase(); return [ { type: 'talk:start' }, { type: 'emotion', value: lower.includes('!') ? 'excited' : lower.includes('?') ? 'curious' : 'happy' }, { type: 'gesture', value: lower.includes('?') ? 'tilt' : 'nod' }, { type: 'talk:stop' } ];}
export class StubResponseProvider implements ResponseProvider { async generateReply(message: ChatMessage): Promise<string> { return `Hey ${message.author} — I heard: ${message.text}`; }}
export class CharacterRuntime { constructor(private readonly provider: ResponseProvider) {}
async handleMessage(message: ChatMessage): Promise<AgentResponse> { const reply = await this.provider.generateReply(message); const actions = planAvatarActions(reply); return { reply, actions, audio: { provider: 'stub', text: reply } }; }}