import {z} from 'zod' export type UpdateApiApiV2ModelsModelIdArgs = {model_id: string, body: {name: string, provider_name: string, model_family: string, model_version: string, display_name?: (string | null) | undefined, provider_info?: ({[key: string]: string} | null) | undefined, supports_tool_use?: boolean | undefined}}; export type UpdateApiApiV2ModelsModelIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiApiV2ModelsModelIdResponse = z.object({id: z.string(), name: z.string(), display_name: z.string().nullable(), provider_name: z.string(), provider_info: z.record(z.string(), z.string()).nullable(), supports_tool_use: z.boolean(), model_family: z.string(), model_version: z.string(), created_at: z.string()}); 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 Model * * PUT /api/v2/models/{model_id} */ export const updateApiApiV2ModelsModelId = async (args: UpdateApiApiV2ModelsModelIdArgs, options: UpdateApiApiV2ModelsModelIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v2/models/${encodeURIComponent(String(args.model_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV2ModelsModelIdResponse, await res.json()) };