import {z} from 'zod' export type IntegrationMode = 'TEXT' | 'AVATAR'; export type VoiceStyleNames = 'advertisement_upbeat' | 'affectionate' | 'angry' | 'assistant' | 'calm' | 'chat' | 'cheerful' | 'customerservice' | 'depressed' | 'disgruntled' | 'documentary-narration' | 'embarassed' | 'empathetic' | 'envious' | 'excited' | 'fearful' | 'friendly' | 'gentle' | 'hopeful' | 'lyrical' | 'narration-professional' | 'narration-relaxed' | 'newscast' | 'newscast-casual' | 'newscast-formal' | 'poetry-reading' | 'sad' | 'serious' | 'shouting' | 'sports_commentary' | 'sports_commentary_excited' | 'whispering' | 'terrified' | 'unfriendly'; export type KBInputField = {input_name: string, input_type: string, input_label: string, input_placeholder: string, is_mandatory: boolean}; export type KnowledgeBaseCustomizationPayload = {kb_id: string, kb_name: string, base_system_prompt?: string | undefined, initial_messages?: Array | undefined, prompt_suggestions?: Array | undefined, display_name: string, integration_mode?: IntegrationMode | undefined, avatar_id?: string | undefined, voice_id?: string | undefined, speaking_style?: VoiceStyleNames | undefined, visitor_chat_color?: string | undefined, dante_chat_color?: string | undefined, embed_logo_url?: string | undefined, embed_page_url?: string | undefined, chatbot_profile_pic?: string | undefined, prompts_color?: string | undefined, custom_url?: string | undefined, show_tooltips?: boolean | undefined, remove_dante_logo?: boolean | undefined, custom_url_favicon?: string | undefined, custom_url_title?: string | undefined, custom_url_meta?: string | undefined, custom_url_meta_image?: string | undefined, custom_url_meta_description?: string | undefined, font_name?: string | undefined, font_size?: number | undefined, dante_font_color?: string | undefined, visitor_font_color?: string | undefined, chat_background_color?: string | undefined, custom_css?: string | undefined, hide_microphone_icon?: boolean | undefined, hide_play_icon?: boolean | undefined, password?: string | undefined, public?: boolean | undefined, enabled?: boolean | undefined, max_number_of_credits?: number | undefined, number_of_messages_per_minutes?: number | undefined, number_of_minutes?: number | undefined, max_messages_in_conversations?: number | undefined, temperature?: number | undefined, prompts_font_color?: string | undefined, input_background?: string | undefined, scrollbar_color?: string | undefined, input_placeholder_text?: string | undefined, show_prompt_messages?: boolean | undefined, is_bubble_opened?: boolean | undefined, disclaimer_text?: string | undefined, dante_border_color?: string | undefined, visitor_border_color?: string | undefined, timestamp_color?: string | undefined, close_icon_color?: string | undefined, data_collection_title?: string | undefined, data_collection_fields?: Array | undefined, data_collection?: boolean | undefined, data_collection_as_nlp?: boolean | undefined, data_collection_consent_text?: string | undefined, is_data_collection_optional?: boolean | undefined, show_data_collection_on_conversation_begin?: boolean | undefined, data_collection_rule?: string | undefined, intercom_api_key?: string | undefined, intercom_company_id?: string | undefined, intercom_company_name?: string | undefined, intercom_company_tag?: string | undefined, disclaimer_text_color?: string | undefined, intercom_enabled?: boolean | undefined, intercom_connection_state?: boolean | undefined, talk_to_live_agent?: boolean | undefined, live_agent_email_prompt?: string | undefined, live_agent_name_prompt?: string | undefined, live_agent_always_active?: boolean | undefined, live_agent_list_of_schedules?: Array> | undefined, live_agent_user_timezone?: string | undefined, show_live_agent_on_conversation_begin?: boolean | undefined, show_live_agent_rule?: string | undefined, hide_email_button?: boolean | undefined, calendly_integration_enabled?: boolean | undefined, calendly_url?: string | undefined, show_calendly_at_the_start?: boolean | undefined, show_calendly_rule?: string | undefined, personalities_template?: string | undefined, suggested_prompts_appearance?: string | undefined, whitelisted_domains?: Array | undefined, finished_steps?: Array | undefined, open_to_internet_knowledge?: boolean | undefined, realtime_voice_access?: boolean | undefined, custom_url_enabled?: boolean | undefined, remove_watermark?: boolean | undefined, show_welcome_message_as_tooltip?: boolean | undefined, show_email_details?: boolean | undefined, show_microphone?: boolean | undefined, show_play_button?: boolean | undefined, open_chat_by_default?: boolean | undefined, brand_color?: string | undefined, element_color?: string | undefined, surface_color?: string | undefined, alert_color?: string | undefined, positive_color?: string | undefined, negative_color?: string | undefined, disclaimer_enabled?: boolean | undefined, brand_website?: string | undefined, chatbot_icon?: string | undefined, calendly_btn_text?: string | undefined, suggested_prompts_enabled?: boolean | undefined}; export type CreateApiKnowledgeBasesCustomizationArgs = {team_id?: string | undefined, body: KnowledgeBaseCustomizationPayload}; export type CreateApiKnowledgeBasesCustomizationOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const integrationMode = z.enum(["TEXT", "AVATAR"]); export const kBInputField = z.object({input_name: z.string(), input_type: z.string(), input_label: z.string(), input_placeholder: z.string(), is_mandatory: z.boolean()}); export const knowledgeBaseCustomization = z.object({id: z.string().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), user_id: z.string().optional(), kb_id: z.string(), kb_name: z.string(), integration_mode: integrationMode.optional(), base_system_prompt: z.string().optional(), initial_messages: z.array(z.string()).optional(), prompt_suggestions: z.array(z.string()).optional(), display_name: z.string(), visitor_chat_color: z.string().optional(), dante_chat_color: z.string().optional(), chatbot_profile_pic: z.string().optional(), embed_logo_url: z.string().optional(), embed_page_url: z.string().optional(), prompts_color: z.string().optional(), custom_url: z.string().optional(), dns_values: z.array(z.record(z.string(), z.union([z.string(), z.number().int()]))).optional(), custom_url_favicon: z.string().optional(), custom_url_title: z.string().optional(), custom_url_meta: z.string().optional(), custom_url_meta_image: z.string().optional(), custom_url_meta_description: z.string().optional(), show_tooltips: z.boolean().optional(), remove_dante_logo: z.boolean().optional(), font_name: z.string().optional(), font_size: z.number().int().optional(), dante_font_color: z.string().optional(), visitor_font_color: z.string().optional(), chat_background_color: z.string().optional(), custom_css: z.string().optional(), hide_microphone_icon: z.boolean().optional(), hide_play_icon: z.boolean().optional(), password: z.string().optional(), public: z.boolean().optional(), enabled: z.boolean().optional(), max_number_of_credits: z.number().int().optional(), prompts_font_color: z.string().optional(), input_background: z.string().optional(), scrollbar_color: z.string().optional(), input_placeholder_text: z.string().optional(), show_prompt_messages: z.boolean().optional(), is_bubble_opened: z.boolean().optional(), disclaimer_text: z.string().optional(), timestamp_color: z.string().optional(), close_icon_color: z.string().optional(), data_collection_title: z.string().optional(), data_collection_fields: z.array(kBInputField).optional(), data_collection: z.boolean().optional(), data_collection_as_nlp: z.boolean().optional(), data_collection_consent_text: z.string().optional(), is_data_collection_optional: z.boolean().optional(), show_data_collection_on_conversation_begin: z.boolean().optional(), data_collection_rule: z.string().optional(), number_of_messages_per_minutes: z.number().int().optional(), number_of_minutes: z.number().int().optional(), max_messages_in_conversations: z.number().int().optional(), temperature: z.number().optional(), intercom_api_key: z.string().optional(), intercom_company_id: z.string().optional(), intercom_company_name: z.string().optional(), intercom_company_tag: z.string().optional(), intercom_enabled: z.boolean().optional(), disclaimer_text_color: z.string().optional(), visitor_border_color: z.string().optional(), dante_border_color: z.string().optional(), intercom_connection_state: z.boolean().optional(), talk_to_live_agent: z.boolean().optional(), live_agent_email_prompt: z.string().optional(), live_agent_name_prompt: z.string().optional(), live_agent_always_active: z.boolean().optional(), live_agent_user_timezone: z.string().optional(), live_agent_list_of_schedules: z.array(z.object({})).optional(), show_live_agent_on_conversation_begin: z.boolean().optional(), show_live_agent_rule: z.string().optional(), hide_email_button: z.boolean().optional(), calendly_integration_enabled: z.boolean().optional(), calendly_url: z.string().optional(), show_calendly_at_the_start: z.boolean().optional(), show_calendly_rule: z.string().optional(), personalities_template: z.string().optional(), finished_steps: z.array(z.string()).optional(), suggested_prompts_appearance: z.string().optional(), whitelisted_domains: z.array(z.string()).optional(), open_to_internet_knowledge: z.boolean().optional(), realtime_voice_access: z.boolean().optional(), custom_url_enabled: z.boolean().optional(), remove_watermark: z.boolean().optional(), show_welcome_message_as_tooltip: z.boolean().optional(), show_email_details: z.boolean().optional(), show_microphone: z.boolean().optional(), show_play_button: z.boolean().optional(), open_chat_by_default: z.boolean().optional(), brand_color: z.string().optional(), element_color: z.string().optional(), surface_color: z.string().optional(), alert_color: z.string().optional(), positive_color: z.string().optional(), negative_color: z.string().optional(), disclaimer_enabled: z.boolean().optional(), brand_website: z.string(), chatbot_icon: z.string(), calendly_btn_text: z.string(), suggested_prompts_enabled: z.boolean().optional(), autorefresh_enabled: z.boolean().optional(), home_tab_enabled: z.boolean().optional(), avatar_enabled: z.boolean().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 Knowledge Base Customization * * POST /knowledge-bases/customization/ * * Also accepts auth: OAuth2PasswordBearer */ export const createApiKnowledgeBasesCustomization = async (args: CreateApiKnowledgeBasesCustomizationArgs, options: CreateApiKnowledgeBasesCustomizationOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/knowledge-bases/customization/${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(knowledgeBaseCustomization, await res.json()) };