import {z} from 'zod' export type AssistantContentType = 'conversational_search' | 'text' | 'image' | 'option' | 'pause' | 'iframe' | 'connect_to_agent' | 'suggestion' | 'channel_transfer' | 'search' | 'user_defined' | 'video' | 'audio' | 'date' | 'inline_error' | 'chat_with_docs_upload' | 'disconnected_apps' | 'forms' | 'form_operation' | 'document_processing_response'; export type AssistantContent = {response_type: AssistantContentType, json_schema?: ({[key: string]: unknown} | null) | undefined, ui_schema?: ({[key: string]: unknown} | null) | undefined, form_data?: ({[key: string]: unknown} | null) | undefined, id?: (string | null) | undefined, form_operation?: (string | null) | undefined, sub_type?: (string | null) | undefined, event_type?: (string | null) | undefined, dps_payload_id?: (string | null) | undefined} | {[key: string]: unknown}; export type Mention = {type: string, id: string, name: string}; export type AssistantMention = {assistant_id: string, assistant_name: string}; export type DisplayProperties = {skip_render?: boolean | undefined, is_async?: boolean | undefined, form_operation?: string | undefined}; export type WxoConnectionStatus = {connection_status?: string | undefined, connection_message?: string | undefined}; export type AdditionalProperties = {wxa_message?: ({[key: string]: unknown} | null) | undefined, display_properties?: (DisplayProperties | null) | undefined, tool_calls?: (Array<{[key: string]: unknown}> | null) | undefined, tool_call_id?: (string | null) | undefined, tool_name?: (string | null) | undefined, wxo_connection_status?: (WxoConnectionStatus | null) | undefined}; export type ContextKV = {key: string, value: unknown}; export type Context = {values?: Array | undefined}; export type CreateMessage = {role: string, content: Array | string, mentions?: (Array | null) | undefined, document_ids?: (Array | null) | undefined, parent_message_id?: (string | null) | undefined, additional_properties?: (AdditionalProperties | null) | undefined, assistant_id?: (string | null) | undefined, context?: (Context | null) | undefined, step_history?: (Array<{[key: string]: unknown}> | null) | undefined, message_state?: ({[key: string]: unknown} | null) | undefined}; export type DecodingMethod = 'greedy' | 'sample'; export type LengthPenalty = {decay_factor?: (number | null) | undefined, start_index?: (number | null) | undefined} | {[key: string]: unknown}; export type TextGenerationReturnOptions = {generated_tokens?: (boolean | null) | undefined, input_parameters?: (boolean | null) | undefined, input_text?: (boolean | null) | undefined, input_tokens?: (boolean | null) | undefined, token_logprobs?: (boolean | null) | undefined, token_ranks?: (boolean | null) | undefined, top_n_tokens?: (number | null) | undefined} | {[key: string]: unknown}; export type TextGenerationParameters = {beam_width?: (number | null) | undefined, decoding_method?: (DecodingMethod | null) | undefined, include_stop_sequence?: (boolean | null) | undefined, length_penalty?: (LengthPenalty | null) | undefined, max_new_tokens?: (number | null) | undefined, min_new_tokens?: (number | null) | undefined, random_seed?: (number | null) | undefined, repetition_penalty?: (number | null) | undefined, return_options?: (TextGenerationReturnOptions | null) | undefined, stop_sequences?: (Array | null) | undefined, temperature?: (number | null) | undefined, time_limit?: (number | null) | undefined, top_k?: (number | null) | undefined, top_p?: (number | null) | undefined, truncate_input_tokens?: (number | null) | undefined, typical_p?: (number | null) | undefined} | {[key: string]: unknown}; export type GuardrailConfig = {enabled?: boolean | undefined, threshold?: number | undefined}; export type MaskProperties = {remove_entity_value?: boolean | undefined}; export type Guardrail = {input?: (GuardrailConfig | null) | undefined, output?: (GuardrailConfig | null) | undefined, mask?: (MaskProperties | null) | undefined}; export type GuardrailsInput = {hap?: (Guardrail | null) | undefined, social_bias?: (Guardrail | null) | undefined, pii?: (Guardrail | null) | undefined}; export type RunOrchestrate = {message?: (CreateMessage | null) | undefined, thread_id?: (string | null) | undefined, llm_params?: (TextGenerationParameters | null) | undefined, guardrails?: (GuardrailsInput | null) | undefined, context?: ({[key: string]: unknown} | null) | undefined, agent_id?: (string | null) | undefined, additional_parameters?: ({[key: string]: unknown} | null) | undefined, environment_id?: (string | null) | undefined, version?: (number | null) | undefined, context_variables?: ({[key: string]: unknown} | null) | undefined}; export type CreateApiV1AssistantsAssistantIdRunsArgs = {assistant_id: string, body: RunOrchestrate}; export type CreateApiV1AssistantsAssistantIdRunsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AssistantsAssistantIdRunsResponse = z.unknown(); 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 }; /** * Run Assistant * * POST /v1/assistants/{assistant_id}/runs */ export const createApiV1AssistantsAssistantIdRuns = async (args: CreateApiV1AssistantsAssistantIdRunsArgs, options: CreateApiV1AssistantsAssistantIdRunsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assistants/${encodeURIComponent(String(args.assistant_id))}/runs${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(createApiV1AssistantsAssistantIdRunsResponse, await res.json()) };