import {z} from 'zod' export type CoreWeaveAuth = Record; export type WeightsAndBiasesAuth = {apiKey?: string | undefined, serverUrl?: string | undefined, enableUsageReports?: boolean | undefined, enableRateLimiting?: boolean | undefined}; export type EndpointConfiguration = {additionalDns?: Array | undefined}; export type BodyBasedRouting = {apiType: 'API_TYPE_OPENAI'}; export type HeaderBasedRouting = {headerName: string}; export type PathBasedRouting = Record; export type UpdateGatewayRequest = {id: string, name: string, zones?: Array | undefined, coreWeaveAuth?: CoreWeaveAuth | undefined, weightsAndBiasesAuth?: WeightsAndBiasesAuth | undefined, endpointConfiguration?: EndpointConfiguration | undefined, bodyBasedRouting?: BodyBasedRouting | undefined, headerBasedRouting?: HeaderBasedRouting | undefined, pathBasedRouting?: PathBasedRouting | undefined}; export type PatchApiV1alpha1InferenceGatewaysIdArgs = {id: string, body: UpdateGatewayRequest}; export type PatchApiV1alpha1InferenceGatewaysIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const coreWeaveAuth = z.object({}); export const weightsAndBiasesAuth = z.object({apiKey: z.string().optional(), serverUrl: z.string().optional(), enableUsageReports: z.boolean().optional(), enableRateLimiting: z.boolean().optional()}); export const endpointConfiguration = z.object({additionalDns: z.array(z.string()).optional()}); export const bodyBasedRouting = z.object({apiType: z.literal("API_TYPE_OPENAI")}); export const headerBasedRouting = z.object({headerName: z.string()}); export const pathBasedRouting = z.object({}); export const gatewaySpec = z.object({id: z.string().optional(), name: z.string().optional(), zones: z.array(z.string()).optional(), coreWeaveAuth: coreWeaveAuth.optional(), weightsAndBiasesAuth: weightsAndBiasesAuth.optional(), organizationId: z.string().optional(), endpointConfiguration: endpointConfiguration.optional(), bodyBasedRouting: bodyBasedRouting.optional(), headerBasedRouting: headerBasedRouting.optional(), pathBasedRouting: pathBasedRouting.optional()}); export const condition = z.object({type: z.string().optional(), lastUpdateTime: z.string().optional(), reason: z.string().optional(), message: z.string().optional(), zone: z.string().optional(), status: z.enum(["True", "False", "Unknown"]).optional()}); export const gatewayStatus = z.object({createdAt: z.string().optional(), updatedAt: z.string().optional(), conditions: z.array(condition).optional(), endpoints: z.array(z.string()).optional(), status: z.enum(["STATUS_CREATING", "STATUS_READY", "STATUS_UPDATING", "STATUS_DELETING", "STATUS_ERROR"]).optional()}); export const gateway = z.object({spec: gatewaySpec.optional(), status: gatewayStatus.optional()}); export const updateGatewayResponse = z.object({gateway: gateway.optional()}); 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 gateway * * PATCH /v1alpha1/inference/gateways/{id} */ export const patchApiV1alpha1InferenceGatewaysId = async (args: PatchApiV1alpha1InferenceGatewaysIdArgs, options?: PatchApiV1alpha1InferenceGatewaysIdOptions) => { const {baseUrl = "https://api.coreweave.com", 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(/\/+$/, '')}/v1alpha1/inference/gateways/${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(updateGatewayResponse, await res.json()) };