import {z} from 'zod' export type GetApiApiV1UserLinkedAssistantsWithAgentArgs = {agent_user_id?: (string | null) | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiApiV1UserLinkedAssistantsWithAgentOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const agentAssistantMetadata = z.object({id: z.string(), assistant_type: z.string(), name: z.string(), description: z.string(), data_sources_count: z.number().int(), total_word_count: z.number().int(), intents_count: z.number().int(), has_human_agent: z.boolean().nullable()}); export const pageBaseAgentAssistantMetadata = z.object({items: z.array(agentAssistantMetadata), total: z.number().int().gte(0).nullable(), page: z.number().int().gte(1).nullable(), size: z.number().int().gte(1).nullable(), pages: z.number().int().gte(0).nullable().optional(), previous_page: z.number().int().nullable().optional(), next_page: z.number().int().nullable().optional()}); export const iGetResponsePaginatedAgentAssistantMetadata = z.object({message: z.string().nullable().optional(), meta: z.record(z.string(), z.unknown()).optional(), data: pageBaseAgentAssistantMetadata}); 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 }; /** * Linked Assistants With Agent * * GET /api/v1/user/linked_assistants_with_agent/ * * Also accepts auth: HTTPBearer */ export const getApiApiV1UserLinkedAssistantsWithAgent = async (args: GetApiApiV1UserLinkedAssistantsWithAgentArgs, options: GetApiApiV1UserLinkedAssistantsWithAgentOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.agent_user_id != null) query.append("agent_user_id", String(args.agent_user_id)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/user/linked_assistants_with_agent/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(iGetResponsePaginatedAgentAssistantMetadata, await res.json()) };