Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | /** * Ultravox Voice AI Service * Creates calls via Ultravox API and manages voice configuration */ // API Configuration const ULTRAVOX_API_URL = 'https://api.ultravox.ai/api'; const ULTRAVOX_API_KEY = '4miSVLym.HF3lV9y4euiuzcEbPPTLHEugrOu4jpNU'; // Available voices export interface UltravoxVoice { id: string; name: string; description: string; language: string; gender: 'female' | 'male'; flag: string; } export const ULTRAVOX_VOICES: UltravoxVoice[] = [ { id: 'Sarah', name: 'Sarah', description: 'Warm and friendly', language: 'English', gender: 'female', flag: 'πΊπΈ', }, { id: 'Wendy', name: 'Wendy', description: 'Professional', language: 'English', gender: 'female', flag: 'πΊπΈ', }, { id: 'Timothy', name: 'Timothy', description: 'Calm and clear', language: 'English', gender: 'male', flag: 'πΊπΈ', }, { id: 'Larisa', name: 'Larisa', description: 'Russian voice', language: 'Russian', gender: 'female', flag: 'π·πΊ', }, ]; // Default voice export const DEFAULT_VOICE = ULTRAVOX_VOICES[0]; // Sarah // Tool definitions for function calling export interface UltravoxTool { temporaryTool: { modelToolName: string; description: string; dynamicParameters?: Array<{ name: string; location: string; schema: { type: string; description: string; }; required: boolean; }>; client?: Record<string, unknown>; }; } export const ULTRAVOX_TOOLS: UltravoxTool[] = [ { temporaryTool: { modelToolName: 'navigateToBeneficiaries', description: 'Navigate to the beneficiaries list screen when user wants to see or manage their loved ones', client: {}, }, }, { temporaryTool: { modelToolName: 'navigateToChat', description: 'Navigate to the chat screen for text-based conversation', client: {}, }, }, { temporaryTool: { modelToolName: 'navigateToProfile', description: 'Navigate to the user profile settings screen', client: {}, }, }, { temporaryTool: { modelToolName: 'checkBeneficiaryStatus', description: 'Check the current wellness status of a specific beneficiary', dynamicParameters: [ { name: 'beneficiaryName', location: 'PARAMETER_LOCATION_BODY', schema: { type: 'string', description: 'The name of the beneficiary to check', }, required: true, }, ], client: {}, }, }, ]; // System prompt generator export function getSystemPrompt(beneficiaryName: string): string { return `You are Julia, a compassionate and knowledgeable AI wellness assistant for WellNuo app. Your role is to help caregivers monitor and understand the wellbeing of their loved ones. Current beneficiary: ${beneficiaryName} Guidelines: - Be warm, empathetic, and supportive in your responses - Provide clear, concise information about wellness metrics - Offer practical suggestions for improving wellbeing - If asked about specific health concerns, recommend consulting healthcare professionals - You can navigate the app using available tools when the user requests it - Keep responses conversational and natural for voice interaction - Speak in a calm, reassuring tone Remember: You're speaking with a caregiver who wants the best for their loved one. Be supportive and helpful while maintaining appropriate boundaries about medical advice.`; } // API Response types export interface CreateCallResponse { callId: string; joinUrl: string; created: string; ended?: string; model: string; voice: string; firstSpeaker: string; transcriptOptional: boolean; recordingEnabled: boolean; } export interface UltravoxError { error: string; message: string; } /** * Create a new Ultravox call */ export async function createCall(options: { systemPrompt: string; voice?: string; tools?: UltravoxTool[]; firstSpeaker?: 'FIRST_SPEAKER_AGENT' | 'FIRST_SPEAKER_USER'; }): Promise<{ success: true; data: CreateCallResponse } | { success: false; error: string }> { try { const response = await fetch(`${ULTRAVOX_API_URL}/calls`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-Key': ULTRAVOX_API_KEY, }, body: JSON.stringify({ systemPrompt: options.systemPrompt, model: 'fixie-ai/ultravox', voice: options.voice || 'Sarah', firstSpeaker: options.firstSpeaker || 'FIRST_SPEAKER_AGENT', selectedTools: options.tools || ULTRAVOX_TOOLS, medium: { webRtc: {} }, recordingEnabled: false, maxDuration: '1800s', // 30 minutes max }), }); if (!response.ok) { const errorData = await response.json().catch(() => ({})); return { success: false, error: errorData.message || `API error: ${response.status}`, }; } const data: CreateCallResponse = await response.json(); return { success: true, data }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to create call', }; } } /** * Get call details */ export async function getCall(callId: string): Promise<CreateCallResponse | null> { try { const response = await fetch(`${ULTRAVOX_API_URL}/calls/${callId}`, { method: 'GET', headers: { 'X-API-Key': ULTRAVOX_API_KEY, }, }); if (!response.ok) { return null; } return await response.json(); } catch (error) { return null; } } /** * End a call */ export async function endCall(callId: string): Promise<boolean> { try { const response = await fetch(`${ULTRAVOX_API_URL}/calls/${callId}`, { method: 'DELETE', headers: { 'X-API-Key': ULTRAVOX_API_KEY, }, }); return response.ok; } catch (error) { return false; } } |