import {z} from 'zod' export type VoiceAgentCreateInGroup = {name: string, label: string, description?: (string | null) | undefined}; export type CreateApiApiV1VoiceAiVoiceAgentGroupsGroupIdAgentsArgs = {group_id: string, body: VoiceAgentCreateInGroup}; export type CreateApiApiV1VoiceAiVoiceAgentGroupsGroupIdAgentsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const prePickupMode = z.enum(["audio", "text", "synthesized"]); export const prePickupVoiceProvider = z.enum(["elevenlabs", "cartesia", "google"]); export const voicePrePickupPromptSegment = z.object({language: z.string(), text: z.string(), voice_provider: prePickupVoiceProvider, voice_id: z.string(), audio_object_key: z.string().nullable().optional(), audio_filename: z.string().nullable().optional()}); export const voicePrePickupVariant = z.object({language: z.string(), text: z.string(), voice_provider: prePickupVoiceProvider, voice_id: z.string(), audio_object_key: z.string().nullable().optional(), audio_filename: z.string().nullable().optional(), dtmf_digit: z.string().nullable().optional(), greeting: z.string().nullable().optional()}); export const agentVoiceVariant = z.object({language: z.string(), voice_provider: prePickupVoiceProvider, voice_id: z.string().min(1)}); export const voiceTransferScenarioConfig = z.object({condition: z.string().nullable().optional(), pre_instruction: z.string().nullable().optional(), post_instruction: z.string().nullable().optional(), transfer_announcement: z.enum(["silent", "announced"]).optional(), speak_first_message_on_transfer: z.boolean().optional(), languages: z.array(z.string()).optional()}); export const voiceAgentGroupEntry = z.object({label: z.string().min(1).max(39), description: z.string().nullable().optional(), voice_agent_id: z.string(), transfer_config: voiceTransferScenarioConfig.nullable().optional()}); export const voiceAgentGroupDirection = z.enum(["inbound", "outbound"]); export const voiceAgentGroupRead = z.object({id: z.string(), pre_pickup_enabled: z.boolean().optional(), pre_pickup_mode: prePickupMode.nullable().optional(), pre_pickup_text: z.string().nullable().optional(), pre_pickup_voice_provider: prePickupVoiceProvider.nullable().optional(), pre_pickup_voice_id: z.string().nullable().optional(), pre_pickup_language: z.string().nullable().optional(), pre_pickup_prompt_segments: z.array(voicePrePickupPromptSegment).optional(), pre_pickup_variants: z.array(voicePrePickupVariant).optional(), pre_pickup_menu_grace_seconds: z.number().gte(0).lte(30).nullable().optional(), agent_voice_variants: z.array(agentVoiceVariant).optional(), name: z.string().min(1).max(255), entries: z.array(voiceAgentGroupEntry).optional(), enabled: z.boolean().optional(), direction: voiceAgentGroupDirection.optional(), tenant_id: z.string(), created_at: z.string(), updated_at: z.string(), pre_pickup_audio_filename: z.string().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create Agent In Voice Group * * POST /api/v1/voice-ai/voice-agent-groups/{group_id}/agents */ export const createApiApiV1VoiceAiVoiceAgentGroupsGroupIdAgents = async (args: CreateApiApiV1VoiceAiVoiceAgentGroupsGroupIdAgentsArgs, options: CreateApiApiV1VoiceAiVoiceAgentGroupsGroupIdAgentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/voice-ai/voice-agent-groups/${encodeURIComponent(String(args.group_id))}/agents${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(voiceAgentGroupRead, await res.json()) };