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 AdvancedTextPearlApi = {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, agentName?: (string | 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 ETranscriptOptions = number; export type InactivityFollowUp = {delayMinutes?: number | undefined, message?: (string | null) | undefined}; export type InboundTextSettingsApi = {totalAgents?: number | undefined, transcriptOptions?: ETranscriptOptions | undefined, callWebhookUrl?: (string | null) | undefined, textChannelId?: (string | null) | undefined, maxTurns?: (number | null) | undefined, autoCloseAfterInactivityHours?: (number | null) | undefined, inactivityFollowUps?: (Array | null) | undefined}; export type DayOfWeek = number; export type DayWorkingHours = {day?: DayOfWeek | undefined, start?: unknown | undefined, end?: unknown | undefined}; export type OutboundTextSettingsApi = {totalAgents?: number | undefined, transcriptOptions?: ETranscriptOptions | undefined, budgetTotal?: (number | null) | undefined, timeZone?: (string | null) | undefined, callingHours?: (Array | null) | undefined, callWebhookUrl?: (string | null) | undefined, leadWebhookUrl?: (string | null) | undefined, textChannelId?: (string | null) | undefined, maxTurns?: (number | null) | undefined, autoCloseAfterInactivityHours?: (number | null) | undefined, inactivityFollowUps?: (Array | null) | undefined}; export type AddProjectTextApiRequest = {name?: (string | null) | undefined, pearl?: (AdvancedTextPearlApi | null) | undefined, variables?: (Array | null) | undefined, inbound?: (InboundTextSettingsApi | null) | undefined, outbound?: (OutboundTextSettingsApi | null) | undefined}; export type CreateApiV2PearlTextArgs = {body: AddProjectTextApiRequest}; export type CreateApiV2PearlTextOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2PearlTextResponse = z.string(); 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 Text Pearl * * POST /v2/Pearl/Text */ export const createApiV2PearlText = async (args: CreateApiV2PearlTextArgs, options?: CreateApiV2PearlTextOptions) => { 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/Text${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(createApiV2PearlTextResponse, await res.json()) };