import {z} from 'zod' export type TurnConfig = {confidence?: (number | null) | undefined, start_secs?: (number | null) | undefined, stop_secs?: (number | null) | undefined, min_volume?: (number | null) | undefined, unfinished_pause_secs?: (number | null) | undefined, min_interrupt_words?: (number | null) | undefined}; export type PromptDataSource = {name?: string | undefined, type: 'text' | 'url', text?: (string | null) | undefined, url?: (string | null) | undefined, headers?: ({[key: string]: string} | null) | undefined, token_limit?: (number | null) | undefined}; export type MCPServerConfig = {name: string, enabled?: boolean | undefined, url?: (string | null) | undefined, headers?: ({[key: string]: string} | null) | undefined, transport?: ('http' | 'streamable_http' | 'sse' | null) | undefined, tools?: (Array | null) | undefined, tool_allowlist?: (Array | null) | undefined, timeout_seconds?: (number | null) | undefined, instructions?: (string | null) | undefined}; export type MCPConfig = {servers?: Array | undefined, instructions?: (string | null) | undefined}; export type BotCredentials = {llm_api_key?: (string | null) | undefined, stt_api_key?: (string | null) | undefined, tts_api_key?: (string | null) | undefined}; export type AuthorityConfig = {owner_name: string, approved_positions?: Array | undefined, escalate_on?: Array | undefined, forbidden?: Array | undefined}; export type BriefingConfig = {enabled?: boolean | undefined, language?: (string | null) | undefined, instructions?: (string | null) | undefined}; export type BotRequest = {meeting_url: string, bot_name?: string | undefined, personas?: (Array | null) | undefined, bot_image?: (string | null) | undefined, entry_message?: (string | null) | undefined, extra?: ({[key: string]: unknown} | null) | undefined, enable_tools?: boolean | undefined, prompt?: (string | null) | undefined, websocket_url?: (string | null) | undefined, turn_config?: (TurnConfig | null) | undefined, prompt_data_sources?: (Array | null) | undefined, prompt_data_token_limit?: number | undefined, mcp?: (MCPConfig | null) | undefined, mcp_profile?: ('professional' | 'personal' | 'all' | null) | undefined, mcp_profile_tool_access?: ('read_only' | 'read_write') | undefined, llm_provider?: ('openai' | 'anthropic' | 'zai' | null) | undefined, llm_model?: (string | null) | undefined, speech_speed?: (number | null) | undefined, speech_volume?: (number | null) | undefined, speech_emotion?: (string | null) | undefined, wake_phrases?: (Array | null) | undefined, respond_mode?: ('always' | 'mentioned') | undefined, credentials?: (BotCredentials | null) | undefined, transcription_enabled?: boolean | undefined, transcription_provider?: ('gladia' | 'deepgram' | 'assemblyai' | 'speechmatics' | 'soniox') | undefined, language?: (string | null) | undefined, callback_url?: (string | null) | undefined, callback_secret?: (string | null) | undefined, authority?: (AuthorityConfig | null) | undefined, briefing?: (BriefingConfig | null) | undefined}; export type CreateApiBotsArgs = {body: BotRequest}; export type CreateApiBotsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const joinResponse = z.object({bot_id: 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 }; /** * Join Meeting * * POST /bots */ export const createApiBots = async (args: CreateApiBotsArgs, options?: CreateApiBotsOptions) => { const {baseUrl = "https://speaking.meetingbaas.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-meeting-baas-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/bots${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(joinResponse, await res.json()) };