import {z} from 'zod' export type CreateAssistantExternal = {name?: string | undefined, assistant_type?: string | undefined, query_condensation?: ({instructions_choice?: string | undefined, custom_instructions?: string | undefined, messages_to_condensate?: number | undefined, chat_model?: ({model_name?: string | undefined, model_id?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined}) | undefined, query_expansion?: ({instructions_choice?: string | undefined, custom_instructions?: string | undefined, messages_to_generate?: number | undefined, llm_model?: ({model_name?: string | undefined, model_id?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined}) | undefined, reranking?: ({algorithm?: string | undefined, llm_reranking_instructions?: string | undefined, llm_model?: ({model_name?: string | undefined, model_id?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined}) | undefined, answer_generation?: ({instructions_choice?: ('both' | 'semantic' | 'hybrid' | 'custom') | undefined, main_instructions?: string | undefined, formatting_instructions?: string | undefined, no_document_instructions?: string | undefined, maximum_answer_length?: number | undefined, llm_model?: ({model_name?: string | undefined, model_id?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined}) | undefined, post_processing?: ({is_activated?: boolean | undefined, custom_instructions?: string | undefined, llm_model?: ({model_name?: string | undefined, model_id?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined, always_show_sources?: boolean | undefined, max_sources_to_show?: number | undefined, surveys?: ({activation?: boolean | undefined, survey?: ({_id?: string | undefined, name?: string | undefined}) | undefined, instructions?: string | undefined}) | undefined, topic_detection?: ({activation?: boolean | undefined, instructions?: string | undefined}) | undefined, auto_eval?: ({activation?: boolean | undefined}) | undefined, anonymization?: ({activation?: boolean | undefined, instructions?: string | undefined}) | undefined}) | undefined, answer_formatting?: ({waiting_messages_for_answer_generation?: string | undefined, waiting_messages_for_search?: string | undefined, waiting_messages_for_analysis?: string | undefined}) | undefined, is_archived?: boolean | undefined, is_shared?: boolean | undefined, source?: ({sources?: (Array<{name?: string | undefined, _id?: string | undefined}>) | undefined}) | undefined, search?: ({strategy?: string | undefined, llm_model?: ({model_id?: string | undefined, model_name?: string | undefined, _id?: string | undefined, name?: string | undefined, provider?: string | undefined, model?: ({_id?: string | undefined, provider?: string | undefined, name?: string | undefined, model_name?: string | undefined}) | undefined, config?: Record | undefined}) | undefined, custom_instructions?: string | undefined, is_smart_filtering_activated?: boolean | undefined, similarity_threshold?: number | undefined, number_best_results_llm_context?: number | undefined, search_results_per_query?: number | undefined, weights?: ({semantic?: number | undefined, keyword?: number | undefined}) | undefined}) | undefined, LLM?: ({model_id?: string | undefined, model_name?: string | undefined, reuse_these_models?: boolean | undefined}) | undefined, company?: ({contact_mail?: string | undefined, contact_page?: string | undefined, phone_number?: string | undefined, location?: string | undefined, website?: string | undefined, description?: string | undefined, name?: string | undefined}) | undefined, tools?: (Array<{_id?: string | undefined, name?: string | undefined}>) | undefined, collaborators?: Array | undefined, type?: string | undefined}; export type UpdateApiGenerativeAiAssistantIdArgs = {assistant_id: string, body: CreateAssistantExternal}; export type UpdateApiGenerativeAiAssistantIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const success = z.object({success: 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 }; /** * Update assistant * * PUT /generative_ai/{assistant_id} */ export const updateApiGenerativeAiAssistantId = async (args: UpdateApiGenerativeAiAssistantIdArgs, options?: UpdateApiGenerativeAiAssistantIdOptions) => { const {baseUrl = "https://apis.smartly.ai", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/generative_ai/${encodeURIComponent(String(args.assistant_id))}${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(success, await res.json()) };