import {z} from 'zod' export type PatchApiV1WorkspacesIdArgs = {id: string, body: {knowledge_graph?: {[key: string]: unknown} | undefined, currency?: ({[key: string]: unknown} | null) | undefined, global_context?: string | undefined, name?: string | undefined}}; export type PatchApiV1WorkspacesIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accessLabel = z.object({name: z.string(), description: z.string()}); export const workspaceAccess = z.object({labels: z.array(accessLabel).optional(), default_label: z.string().nullable().optional()}); export const workspaceStorage = z.object({type: z.enum(["managed", "tenant_bucket", "external"]), connection_id: z.string().nullable().optional(), provider: z.enum(["s3", "azure_blob", "null"]).nullable().optional(), location: z.string().nullable().optional(), health: z.enum(["draft", "ready", "degraded", "revoked", "null"]).nullable().optional()}).and(z.record(z.string(), z.unknown())); export const workspace = z.object({workspace_id: z.string(), name: z.string(), owner_user_id: z.string().nullable().optional(), access: workspaceAccess.optional(), knowledge_graph: z.record(z.string(), z.unknown()).optional(), currency: z.record(z.string(), z.unknown()).nullable().optional(), domain_id: z.string().optional(), domain_slug: z.string().optional(), domain_version: z.number().int().optional(), global_context: z.string().optional(), config_version: z.number().int().optional(), status: z.enum(["active", "deleting", "unavailable"]), created_at: z.string().optional(), updated_at: z.string().optional(), storage: workspaceStorage.optional()}).and(z.record(z.string(), 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 }; /** * Update a workspace * * PATCH /v1/workspaces/{id} */ export const patchApiV1WorkspacesId = async (args: PatchApiV1WorkspacesIdArgs, options?: PatchApiV1WorkspacesIdOptions) => { const {baseUrl = "https://console.nace.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.id))}${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(workspace, await res.json()) };