import {z} from 'zod' export type EBrainModelType = number; export type EPredefinedCallLabelColors = number; export type CallLabelApi = {id?: (string | null) | undefined, name?: (string | null) | undefined, description?: (string | null) | undefined, color?: EPredefinedCallLabelColors | undefined}; export type ENodeTypeApi = number; export type ETransitionApiResult = number; export type TransitionApi = {name?: (string | null) | undefined, toNodeId?: (string | null) | undefined, apiResult?: (ETransitionApiResult | null) | undefined}; export type APIMethod = number; export type EStateDataType = number; export type APIDataSchemaPropertyApi = {key?: (string | null) | undefined, variableId?: (string | null) | undefined, type?: (EStateDataType | null) | undefined, value?: (string | null) | undefined, required?: boolean | undefined}; export type NodeAPISettingsApi = {name?: (string | null) | undefined, method?: APIMethod | undefined, endpointUrl?: (string | null) | undefined, body?: (Array | null) | undefined, headers?: ({[key: string]: string} | null) | undefined, description?: (string | null) | undefined, outputBody?: (Array | null) | undefined, credentialId?: (string | null) | undefined}; export type NodeSMSTemplateApi = {body?: (string | null) | undefined}; export type EmailProvider = number; export type SmtpSettings = {id?: (string | null) | undefined, provider?: (EmailProvider | null) | undefined, smtpServer?: (string | null) | undefined, port?: (number | null) | undefined, enableSsl?: (boolean | null) | undefined, senderEmail?: (string | null) | undefined, senderPassword?: (string | null) | undefined, displayName?: (string | null) | undefined}; export type NodeEmailTemplateApi = {to?: (Array | null) | undefined, cc?: (Array | null) | undefined, subject?: (string | null) | undefined, body?: (string | null) | undefined, smtpSettings?: (SmtpSettings | null) | undefined}; export type TransferCallSettingsApi = {transferCallPhoneNumber?: (string | null) | undefined, triggerDescription?: (string | null) | undefined, warmTransferMessage?: (string | null) | undefined}; export type NodeApi = {nodeId?: (string | null) | undefined, name?: (string | null) | undefined, nodeType?: ENodeTypeApi | undefined, transitions?: (Array | null) | undefined, script?: (string | null) | undefined, instructions?: (string | null) | undefined, apiSettings?: (NodeAPISettingsApi | null) | undefined, smsSettings?: (NodeSMSTemplateApi | null) | undefined, emailSettings?: (NodeEmailTemplateApi | null) | undefined, transferCallSettings?: (TransferCallSettingsApi | null) | undefined, handOffAction?: (Array | null) | undefined, postCallActions?: (Array | null) | undefined}; export type AgentConfigToAddApi = {name?: (string | null) | undefined, voiceId?: (string | null) | undefined}; export type VocabularyEntry = {word?: (string | null) | undefined, pronunciations?: (Array | null) | undefined}; export type AdvancedVoicePearlApi = {agentPersonality?: (string | null) | undefined, timeZone?: (string | null) | undefined, modelType?: (EBrainModelType | null) | undefined, companyName?: (string | null) | undefined, companyDescription?: (string | null) | undefined, generalInstructions?: (string | null) | undefined, knowledgeBase?: (string | null) | undefined, memory?: (boolean | null) | undefined, successDescription?: (string | null) | undefined, indicatorTags?: (Array | null) | undefined, nodes?: (Array | null) | undefined, agents?: (Array | null) | undefined, speechRecognitionKeywords?: (Array | null) | undefined}; export type EDataSettingsGroup = number; export type OptionChoice = {value?: (string | null) | undefined, code?: (string | null) | undefined}; export type DataSettingsApi = {id?: (string | null) | undefined, name?: (string | null) | undefined, group?: EDataSettingsGroup | undefined, type?: EStateDataType | undefined, isList?: boolean | undefined, description?: (string | null) | undefined, value?: (string | null) | undefined, options?: (Array | null) | undefined}; export type Int32OptionalType = {hasValue?: boolean | undefined, value?: number | undefined}; export type ETranscriptOptions = number; export type ETranscriptOptionsOptionalType = {hasValue?: boolean | undefined, value?: ETranscriptOptions | undefined}; export type StringOptionalType = {hasValue?: boolean | undefined, value?: (string | null) | undefined}; export type BooleanOptionalType = {hasValue?: boolean | undefined, value?: boolean | undefined}; export type BooleanNullableOptionalType = {hasValue?: boolean | undefined, value?: (boolean | null) | undefined}; export type InboundVoiceSettingsPatchApi = {totalAgents?: Int32OptionalType | undefined, transcriptOptions?: ETranscriptOptionsOptionalType | undefined, callWebhookUrl?: StringOptionalType | undefined, phoneNumberId?: StringOptionalType | undefined, recordingOptions?: BooleanOptionalType | undefined, isStopRecordingAfterTransferCall?: BooleanNullableOptionalType | undefined, waitingSentence?: StringOptionalType | undefined, isSayQueueDetails?: BooleanOptionalType | undefined}; export type Int32NullableOptionalType = {hasValue?: boolean | undefined, value?: (number | null) | undefined}; export type DayOfWeek = number; export type DayWorkingHours = {day?: DayOfWeek | undefined, start?: unknown | undefined, end?: unknown | undefined}; export type DayWorkingHoursListOptionalType = {hasValue?: boolean | undefined, value?: (Array | null) | undefined}; export type ERecordingTrack = number; export type ERecordingTrackOptionalType = {hasValue?: boolean | undefined, value?: ERecordingTrack | undefined}; export type EMinimumRetryIntervalHours = number; export type EMinimumRetryIntervalHoursOptionalType = {hasValue?: boolean | undefined, value?: EMinimumRetryIntervalHours | undefined}; export type OutboundVoiceSettingsPatchApi = {totalAgents?: Int32OptionalType | undefined, transcriptOptions?: ETranscriptOptionsOptionalType | undefined, budgetTotal?: Int32NullableOptionalType | undefined, timeZone?: StringOptionalType | undefined, callingHours?: DayWorkingHoursListOptionalType | undefined, callWebhookUrl?: StringOptionalType | undefined, leadWebhookUrl?: StringOptionalType | undefined, phoneNumberId?: StringOptionalType | undefined, recordingTrack?: ERecordingTrackOptionalType | undefined, isStopRecordingAfterTransferCall?: BooleanNullableOptionalType | undefined, maximumCallAttempts?: Int32OptionalType | undefined, minimumRetryIntervalHours?: EMinimumRetryIntervalHoursOptionalType | undefined, voiceMail?: StringOptionalType | undefined, bypassIVRInstruction?: StringOptionalType | undefined, ringDuration?: Int32NullableOptionalType | undefined, callTimeout?: Int32NullableOptionalType | undefined}; export type UpdateProjectVoiceApiRequest = {name?: (string | null) | undefined, pearl?: (AdvancedVoicePearlApi | null) | undefined, variables?: (Array | null) | undefined, inbound?: (InboundVoiceSettingsPatchApi | null) | undefined, outbound?: (OutboundVoiceSettingsPatchApi | null) | undefined}; export type UpdateApiV2PearlVoicePearlIdArgs = {pearlId: string, body: UpdateProjectVoiceApiRequest}; export type UpdateApiV2PearlVoicePearlIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2PearlVoicePearlIdResponse = z.boolean(); 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 Pearl * * PUT /v2/Pearl/Voice/{pearlId} */ export const updateApiV2PearlVoicePearlId = async (args: UpdateApiV2PearlVoicePearlIdArgs, options?: UpdateApiV2PearlVoicePearlIdOptions) => { const {baseUrl = "https://api.nlpearl.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/Pearl/Voice/${encodeURIComponent(String(args.pearlId))}${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(updateApiV2PearlVoicePearlIdResponse, await res.json()) };