
import { defineAgent, voice,cli } from '@livekit/agents';
import * as google from '@livekit/agents-plugin-google';

export default defineAgent({
  entry: async (ctx) => {
    console.log('agent entry running, room=', ctx.room?.name);
    const { Agent } = voice;
    const agent = new Agent({
      instructions: 'You are an AI interviewer. Ask one question at a time.',
    });

    const model = new google.beta.realtime.RealtimeModel({
      model: 'gemini-1.0-realtime', // pick the model name you have access to
      voice: 'puck',
      instructions: 'Act as the interviewer and wait for answer.',
      modalities: ['AUDIO'],
    });

    const session = new voice.AgentSession({ llm: model });

    // start session and publish an initial chat/data message for testing
    await session.start({ agent, room: ctx.room });

    // publish a test data message (so clients see something)
    const payload = JSON.stringify({ type: 'chat', text: 'Hello from agent', from: 'agent' });
    await ctx.room.localParticipant.publishData(Buffer.from(payload), 1);
    console.log('agent published initial data message');

    // keep running until stopped by runtime
    await ctx.waitForStop();
  },
});
