import {z} from 'zod' export type GetApiIntegrationsSharepointV1RootsArgs = {chat_id?: (number | null) | undefined, library_id?: (number | null) | undefined, assistant_id?: (number | null) | undefined, project_id?: (number | null) | undefined, cookie_name?: (string | null) | undefined}; export type GetApiIntegrationsSharepointV1RootsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const dataSourceSiteModel = z.object({id: z.string(), web_url: z.string(), name: z.string().nullable(), display_name: z.string().nullable(), description: z.string().nullable(), imported_count: z.number().int().optional()}); export const dataSourceFolderModel = z.object({child_count: z.number().int()}); export const dataSourceItemModel = z.object({id: z.string(), web_url: z.string(), drive_id: z.string(), site_id: z.string().nullable(), parent_folder_id: z.string(), parent_path: z.string().nullable(), name: z.string().nullable(), description: z.string().nullable(), size: z.number().int().nullable(), last_modified_date_time: z.string().nullable(), mimetype: z.string().nullable(), folder: dataSourceFolderModel.nullable(), imported: z.boolean().nullable().optional(), imported_count: z.number().int().nullable().optional()}); export const dataSourceDriveModel = z.object({id: z.string(), web_url: z.string(), name: z.string().nullable(), description: z.string().nullable(), root: dataSourceItemModel, imported_count: z.number().int().optional()}); export const getApiIntegrationsSharepointV1RootsResponse = z.union([z.array(dataSourceSiteModel), z.array(dataSourceDriveModel)]); 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 }; /** * List top-level browse entries * * GET /integrations/sharepoint/v1/roots */ export const getApiIntegrationsSharepointV1Roots = async (args: GetApiIntegrationsSharepointV1RootsArgs, options?: GetApiIntegrationsSharepointV1RootsOptions) => { const {baseUrl = "https://api.your-domain.com", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.chat_id != null) query.append("chat_id", String(args.chat_id)) if (args.library_id != null) query.append("library_id", String(args.library_id)) if (args.assistant_id != null) query.append("assistant_id", String(args.assistant_id)) if (args.project_id != null) query.append("project_id", String(args.project_id)) if (args.cookie_name != null) query.append("cookie_name", String(args.cookie_name)) if (APIKeyHeader !== undefined) headers.set("X-API-KEY", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/integrations/sharepoint/v1/roots${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(getApiIntegrationsSharepointV1RootsResponse, await res.json()) };