import {z} from 'zod' export type UpdateWorkspaceIN = {name?: (string | null) | undefined, description?: (string | null) | undefined, icon?: (string | null) | undefined}; export type PatchApiV1AdminWorkspacesWorkspaceUuidArgs = {workspace_uuid: string, body: UpdateWorkspaceIN}; export type PatchApiV1AdminWorkspacesWorkspaceUuidOptions = {baseUrl?: string | undefined, AdminApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const workspaceSpendLimitOUT = z.object({value: z.number().nullable(), currency: z.string().nullable(), no_monthly_limit: z.boolean().nullable()}); export const workspaceOUT = z.object({uuid: z.string(), name: z.string().max(255), description: z.string().nullable(), icon: z.string().nullable(), members_count: z.number().int().nullable().optional(), groups_count: z.number().int().nullable().optional(), spend_limit: workspaceSpendLimitOUT.nullable().optional(), is_default: z.boolean()}); 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 Workspaces * * PATCH /v1/admin/workspaces/{workspace_uuid} */ export const patchApiV1AdminWorkspacesWorkspaceUuid = async (args: PatchApiV1AdminWorkspacesWorkspaceUuidArgs, options?: PatchApiV1AdminWorkspacesWorkspaceUuidOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, AdminApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AdminApiKey !== undefined) headers.set('authorization', `Bearer ${AdminApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/workspaces/${encodeURIComponent(String(args.workspace_uuid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(workspaceOUT, await res.json()) };