import {z} from 'zod' export type AdminWorkspaceIn = {name: string, description?: string | undefined, icon?: string | undefined, add_all_org_members?: boolean | undefined, admin_user_id: string}; export type CreateApiV1AdminWorkspacesArgs = {body: AdminWorkspaceIn}; export type CreateApiV1AdminWorkspacesOptions = {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 workspaceRole = z.enum(["A", "M"]); export const staticWorkspaceRoles = z.enum(["d7ea77c5-9260-41d0-ab26-52b5add3ee56", "48436751-ee56-44bd-8a2d-712233977821", "375cd0db-3bbe-4b79-80f3-954ccf04f3d1", "578584f1-4319-4c88-9948-38a5184483b6", "d79b3027-4eb2-4521-8722-825acfee7d8b", "252a0825-40b9-4b98-be80-7658956f13e9", "17aa61c5-1c61-477e-a40a-e52c8ccd74b9", "348fc8da-f6da-4464-ad3e-af7bc137e221", "b23cd6e0-91cd-4a8a-9869-b30366bf3966", "731eb2be-a74f-4070-b797-35bf7009e553", "ff86d432-7f27-47f8-b02f-b5c102ef6a55", "0f9acbf6-93b5-42c7-a227-fc7652755f65", "94ef59cf-56bf-4383-9dd6-1fee77d370af", "7e69e493-caf6-4671-af60-84951754d9fc", "b23cd6e0-91cd-4a8a-9869-b30366bf3966"]); export const staticOrganizationRoles = z.enum(["0d48f530-095c-43fe-8aea-6673bcacabe6", "c955f4e1-9477-43f0-8349-6fbc629fccc9", "7bde5959-d676-47d2-b779-35b64323d278"]); export const workspaceEnrichedOUT = 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(), raw_roles: z.array(z.union([workspaceRole, staticWorkspaceRoles, staticOrganizationRoles])), raw_role: z.union([workspaceRole, staticWorkspaceRoles, staticOrganizationRoles])}); 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 }; /** * Create Workspace * * POST /v1/admin/workspaces */ export const createApiV1AdminWorkspaces = async (args: CreateApiV1AdminWorkspacesArgs, options?: CreateApiV1AdminWorkspacesOptions) => { 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${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(workspaceEnrichedOUT, await res.json()) };