diff --git a/components/Agent.tsx b/components/Agent.tsx index f3196fc..c40be1c 100644 --- a/components/Agent.tsx +++ b/components/Agent.tsx @@ -6,7 +6,7 @@ import { useRouter } from "next/navigation"; import { cn } from "@/lib/utils"; import { vapi } from "@/lib/vapi.sdk"; -import { interviewer } from "@/constants"; +import { generator, interviewer } from "@/constants"; import { createFeedback } from "@/lib/actions/general.action"; enum CallStatus { @@ -118,12 +118,19 @@ const Agent = ({ setCallStatus(CallStatus.CONNECTING); if (type === "generate") { - await vapi.start(process.env.NEXT_PUBLIC_VAPI_WORKFLOW_ID!, { - variableValues: { - username: userName, - userid: userId, + await vapi.start( + undefined, + { + variableValues: { + username: userName, + userid: userId, + }, + clientMessages: ["transcript"], + serverMessages: [], }, - }); + undefined, + generator + ); } else { let formattedQuestions = ""; if (questions) { @@ -136,6 +143,8 @@ const Agent = ({ variableValues: { questions: formattedQuestions, }, + clientMessages: ["transcript"], + serverMessages: [], }); } }; diff --git a/constants/index.ts b/constants/index.ts index 46be86c..9836566 100644 --- a/constants/index.ts +++ b/constants/index.ts @@ -1,4 +1,4 @@ -import { CreateAssistantDTO } from "@vapi-ai/web/dist/api"; +import { CreateAssistantDTO, CreateWorkflowDTO } from "@vapi-ai/web/dist/api"; import { z } from "zod"; export const mappings = { @@ -97,6 +97,200 @@ export const mappings = { "aws amplify": "amplify", }; +export const generator: CreateWorkflowDTO = { + name: "Generate Interview", + nodes: [ + { + name: "start", + type: "conversation", + isStart: true, + metadata: { + position: { + x: 0, + y: 0, + }, + }, + prompt: + "Speak first. Greet the user and help them create a new AI Interviewer", + voice: { + model: "aura-2", + voiceId: "thalia", + provider: "deepgram", + }, + variableExtractionPlan: { + output: [ + { + title: "level", + description: "The job experience level.", + type: "string", + enum: ["entry", "mid", "senior"], + }, + { + title: "amount", + description: "How many questions would you like to generate?", + type: "number", + enum: [], + }, + { + title: "techstack", + description: + "A list of technologies to cover during the job interview. For example, React, Next.js, Express.js, Node and so on...", + type: "string", + enum: [], + }, + { + title: "role", + description: + "What role should would you like to train for? For example Frontend, Backend, Fullstack, Design, UX?", + type: "string", + enum: [], + }, + { + title: "type", + description: "What type of the interview should it be? ", + type: "string", + enum: ["behavioural", "technical", "mixed"], + }, + ], + }, + }, + { + name: "apiRequest_1747470739045", + type: "apiRequest", + metadata: { + position: { + x: -16.075937072883846, + y: 703.623428447121, + }, + }, + method: "POST", + url: `${process.env.NEXT_PUBLIC_BASE_URL}/api/vapi/generate`, + headers: { + type: "object", + properties: {}, + }, + body: { + type: "object", + properties: { + role: { + type: "string", + description: "", + value: "{{ role }}", + }, + level: { + type: "string", + description: "", + value: "{{ level }}", + }, + type: { + type: "string", + description: "", + value: "{{ type }}", + }, + amount: { + type: "number", + description: "", + value: "{{ amount }}", + }, + userid: { + type: "string", + description: "", + value: "{{ userid }}", + }, + techstack: { + type: "string", + description: "", + value: "{{ techstack }}", + }, + }, + }, + output: { + type: "object", + properties: {}, + }, + mode: "blocking", + hooks: [], + }, + { + name: "conversation_1747721261435", + type: "conversation", + metadata: { + position: { + x: -17.547788169718615, + y: 1003.3409337989506, + }, + }, + prompt: + "Thank the user for the conversation and inform them that the interview was generated successfully.", + voice: { + provider: "deepgram", + voiceId: "thalia", + model: "aura-2", + }, + }, + { + name: "conversation_1747744490967", + type: "conversation", + metadata: { + position: { + x: -11.165436030430953, + y: 484.94857971060617, + }, + }, + prompt: "Say that the Interview will be generated shortly.", + voice: { + provider: "deepgram", + voiceId: "thalia", + model: "aura-2", + }, + }, + { + name: "hangup_1747744730181", + type: "hangup", + metadata: { + position: { + x: 76.01267674000721, + y: 1272.0665127156606, + }, + }, + }, + ], + edges: [ + { + from: "apiRequest_1747470739045", + to: "conversation_1747721261435", + condition: { + type: "ai", + prompt: "", + }, + }, + { + from: "start", + to: "conversation_1747744490967", + condition: { + type: "ai", + prompt: "If user provided all the required variables", + }, + }, + { + from: "conversation_1747744490967", + to: "apiRequest_1747470739045", + condition: { + type: "ai", + prompt: "", + }, + }, + { + from: "conversation_1747721261435", + to: "hangup_1747744730181", + condition: { + type: "ai", + prompt: "", + }, + }, + ], +}; + export const interviewer: CreateAssistantDTO = { name: "Interviewer", firstMessage: diff --git a/package-lock.json b/package-lock.json index 63681c0..d7c4355 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@hookform/resolvers": "^4.1.3", "@radix-ui/react-label": "^2.1.2", "@radix-ui/react-slot": "^1.1.2", - "@vapi-ai/web": "^2.2.4", + "@vapi-ai/web": "^2.3.0", "ai": "^4.1.61", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -2867,9 +2867,9 @@ ] }, "node_modules/@vapi-ai/web": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/@vapi-ai/web/-/web-2.2.4.tgz", - "integrity": "sha512-iKnr/IvECKX5Bb4JC9rfY30QgsQag0BPsY6+unF93QOS5stQycJ630YY+7FFZXjt2x5Ce4xQJu0yGJyjn34Fqg==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@vapi-ai/web/-/web-2.3.0.tgz", + "integrity": "sha512-9Xk5UGQvVaU7kChatRqGAfBXZCvpxLye+N5JlX2yu9RUmimPrQdTz8A/QBB3pIM2Q+1bkoP5v0pnooIkvOdFAQ==", "license": "MIT", "dependencies": { "@daily-co/daily-js": "^0.75.2", diff --git a/package.json b/package.json index 6340663..45a14c8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "@hookform/resolvers": "^4.1.3", "@radix-ui/react-label": "^2.1.2", "@radix-ui/react-slot": "^1.1.2", - "@vapi-ai/web": "^2.2.4", + "@vapi-ai/web": "^2.3.0", "ai": "^4.1.61", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1",