import {z} from 'zod' export type VoiceAgentInboundConfigUpsert = {is_enabled: boolean}; export type PhoneNumberFieldInput = {type?: 'phone_number' | undefined, user_field_name: string}; export type StringFieldInput = {type?: 'string' | undefined, user_field_name: string}; export type TimePeriod = {day: 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday', hour: number, minute: number}; export type AutoRetryScheduleWeekly = {type?: 'weekly' | undefined, monday?: Array | undefined, tuesday?: Array | undefined, wednesday?: Array | undefined, thursday?: Array | undefined, friday?: Array | undefined, saturday?: Array | undefined, sunday?: Array | undefined}; export type VoiceAgentOutboundAutoRetryConfigSettings = {base_max_attempts: number, schedule: AutoRetryScheduleWeekly}; export type VoiceAgentOutboundAutoRetryConfigUpsert = {name: string, settings: VoiceAgentOutboundAutoRetryConfigSettings, id?: (string | null) | undefined}; export type IntegrationOutboundConfigRelationStatus = 'DISABLED' | 'CREATE_BATCH' | 'CREATE_RUN'; export type IntegrationVoiceAgentOutboundConfigRelationUpsertAPI = {integration_id: string, status: IntegrationOutboundConfigRelationStatus}; export type VoiceAgentOutboundConfigUpsertAPI = {phone_number_field: PhoneNumberFieldInput, data_schema: Array, is_enabled: boolean, outbound_auto_retry_configs: Array, outbound_config_integration_relations: Array}; export type VoiceAgentUpdateData = {name: string, inbound_config: VoiceAgentInboundConfigUpsert, outbound_config: VoiceAgentOutboundConfigUpsertAPI, voice_platform?: ('livekit' | null) | undefined}; export type UpdateApiVoiceAgentsVoiceAgentsVoiceAgentIdArgs = {voice_agent_id: string, body: VoiceAgentUpdateData}; export type UpdateApiVoiceAgentsVoiceAgentsVoiceAgentIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const updateApiVoiceAgentsVoiceAgentsVoiceAgentIdResponse = z.unknown(); 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 }; /** * Update Voice Agent * * PUT /voice_agents/voice-agents/{voice_agent_id} */ export const updateApiVoiceAgentsVoiceAgentsVoiceAgentId = async (args: UpdateApiVoiceAgentsVoiceAgentsVoiceAgentIdArgs, options: UpdateApiVoiceAgentsVoiceAgentsVoiceAgentIdOptions) => { 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(/\/+$/, '')}/voice_agents/voice-agents/${encodeURIComponent(String(args.voice_agent_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiVoiceAgentsVoiceAgentsVoiceAgentIdResponse, await res.json()) };