import {z} from 'zod' export type AgentConfigToAddApi = {name?: (string | null) | undefined, voiceId?: (string | null) | undefined}; export type EBrainModelType = number; export type VocabularyEntry = {word?: (string | null) | undefined, pronunciations?: (Array | null) | undefined}; export type TransferCallSettingsApi = {transferCallPhoneNumber?: (string | null) | undefined, triggerDescription?: (string | null) | undefined, warmTransferMessage?: (string | null) | undefined}; export type SMSTemplateApi = {body?: (string | null) | undefined, triggerDescription?: (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 EmailTemplateApi = {subject?: (string | null) | undefined, body?: (string | null) | undefined, triggerDescription?: (string | null) | undefined, smtpSettings?: (SmtpSettings | 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 APISettingsApi = {name?: (string | null) | undefined, method?: APIMethod | undefined, endpointUrl?: (string | null) | undefined, body?: (Array | null) | undefined, headers?: ({[key: string]: string} | null) | undefined, triggerDescription?: (string | null) | undefined, description?: (string | null) | undefined, outputBody?: (Array | null) | undefined, credentialId?: (string | null) | undefined}; export type EPredefinedCallLabelColors = number; export type CallLabelApi = {id?: (string | null) | undefined, name?: (string | null) | undefined, description?: (string | null) | undefined, color?: EPredefinedCallLabelColors | undefined}; export type EmailEndCallTemplateApi = {to?: (Array | null) | undefined, cc?: (Array | null) | undefined, subject?: (string | null) | undefined, body?: (string | null) | undefined, triggerDescription?: (string | null) | undefined, smtpSettings?: (SmtpSettings | null) | undefined}; export type CallEndNotificationApi = {apiSettings?: (APISettingsApi | null) | undefined, emailTemplate?: (EmailEndCallTemplateApi | null) | undefined, indicatorTagsIds?: (Array | null) | undefined}; export type PearlSettingsApi = {agents?: (Array | null) | undefined, agentPersonality?: (string | null) | undefined, timeZone?: (string | null) | undefined, modelType?: (EBrainModelType | null) | undefined, companyName?: (string | null) | undefined, companyDescription?: (string | null) | undefined, knowledgeBase?: (string | null) | undefined, memory?: (boolean | null) | undefined, speechRecognitionKeywords?: (Array | null) | undefined, openingSentence?: (string | null) | undefined, flowScript?: (string | null) | undefined, transferCallSettings?: (Array | null) | undefined, smsSettings?: (Array | null) | undefined, emailSettings?: (Array | null) | undefined, apiSettings?: (Array | null) | undefined, successDescription?: (string | null) | undefined, indicatorTags?: (Array | null) | undefined, notifications?: (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 UpdateProjectApiRequest = {name?: (string | null) | undefined, pearl?: (PearlSettingsApi | null) | undefined, variables?: (Array | null) | undefined}; export type UpdateApiV2PearlPearlIdArgs = {pearlId: string, body: UpdateProjectApiRequest}; export type UpdateApiV2PearlPearlIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2PearlPearlIdResponse = 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 Pearl * * PUT /v2/Pearl/{pearlId} */ export const updateApiV2PearlPearlId = async (args: UpdateApiV2PearlPearlIdArgs, options?: UpdateApiV2PearlPearlIdOptions) => { 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/${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(updateApiV2PearlPearlIdResponse, await res.json()) };