import {z} from 'zod' export type StackComponentType = 'alerter' | 'annotator' | 'artifact_store' | 'container_registry' | 'data_validator' | 'experiment_tracker' | 'feature_store' | 'image_builder' | 'model_deployer' | 'orchestrator' | 'step_operator' | 'model_registry'; export type FlavorRequest = {user: string, name: string, type: StackComponentType, config_schema: Record, connector_type?: (string | null) | undefined, connector_resource_type?: (string | null) | undefined, connector_resource_id_attr?: (string | null) | undefined, source: string, integration: string | null, logo_url?: (string | null) | undefined, docs_url?: (string | null) | undefined, sdk_docs_url?: (string | null) | undefined, is_custom?: boolean | undefined, workspace?: (string | null) | undefined}; export type CreateApiApiV1FlavorsArgs = {body: FlavorRequest}; export type CreateApiApiV1FlavorsOptions = {baseUrl: string, CookieOAuth2TokenBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userResponseBody = z.object({created: z.string(), updated: z.string(), active: z.boolean().optional(), activation_token: z.string().max(255).nullable().optional(), full_name: z.string().max(255).optional(), email_opted_in: z.boolean().nullable().optional(), is_service_account: z.boolean(), is_admin: z.boolean()}); export const userResponseMetadata = z.object({email: z.string().max(255).nullable().optional(), external_user_id: z.string().nullable().optional(), user_metadata: z.object({}).optional()}); export const userResponseResources = z.record(z.string(), z.unknown()); export const userResponse = z.object({body: userResponseBody.nullable().optional(), metadata: userResponseMetadata.nullable().optional(), resources: userResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const stackComponentType = z.enum(["alerter", "annotator", "artifact_store", "container_registry", "data_validator", "experiment_tracker", "feature_store", "image_builder", "model_deployer", "orchestrator", "step_operator", "model_registry"]); export const flavorResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), type: stackComponentType, integration: z.string().max(255).nullable(), logo_url: z.string().nullable().optional()}); export const workspaceResponseBody = z.object({created: z.string(), updated: z.string()}); export const workspaceResponseMetadata = z.object({description: z.string().max(255).optional()}); export const workspaceResponseResources = z.record(z.string(), z.unknown()); export const workspaceResponse = z.object({body: workspaceResponseBody.nullable().optional(), metadata: workspaceResponseMetadata.nullable().optional(), resources: workspaceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const flavorResponseMetadata = z.object({workspace: workspaceResponse.nullable(), config_schema: z.object({}), connector_type: z.string().max(255).nullable().optional(), connector_resource_type: z.string().max(255).nullable().optional(), connector_resource_id_attr: z.string().max(255).nullable().optional(), source: z.string().max(255), docs_url: z.string().nullable().optional(), sdk_docs_url: z.string().nullable().optional(), is_custom: z.boolean().optional()}); export const flavorResponseResources = z.record(z.string(), z.unknown()); export const flavorResponse = z.object({body: flavorResponseBody.nullable().optional(), metadata: flavorResponseMetadata.nullable().optional(), resources: flavorResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); 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 Flavor * * POST /api/v1/flavors */ export const createApiApiV1Flavors = async (args: CreateApiApiV1FlavorsArgs, options: CreateApiApiV1FlavorsOptions) => { const {baseUrl, fetch: fetchFn = fetch, CookieOAuth2TokenBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (CookieOAuth2TokenBearer !== undefined) headers.set('authorization', `Bearer ${CookieOAuth2TokenBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/flavors${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(flavorResponse, await res.json()) };