import {z} from 'zod' export type GatewayEksCluster = {awsAccountId: string, fireworksManagerRole?: string | undefined, region: string, clusterName?: string | undefined, storageBucketName?: string | undefined, metricWriterRole?: string | undefined, loadBalancerControllerRole?: string | undefined, workloadIdentityPoolProviderId?: string | undefined, inferenceRole?: string | undefined}; export type GatewayFakeCluster = {projectId?: string | undefined, location?: string | undefined, clusterName?: string | undefined}; export type GatewayClusterState = 'STATE_UNSPECIFIED' | 'CREATING' | 'READY' | 'DELETING' | 'FAILED'; export type GatewayCode = 'OK' | 'CANCELLED' | 'UNKNOWN' | 'INVALID_ARGUMENT' | 'DEADLINE_EXCEEDED' | 'NOT_FOUND' | 'ALREADY_EXISTS' | 'PERMISSION_DENIED' | 'UNAUTHENTICATED' | 'RESOURCE_EXHAUSTED' | 'FAILED_PRECONDITION' | 'ABORTED' | 'OUT_OF_RANGE' | 'UNIMPLEMENTED' | 'INTERNAL' | 'UNAVAILABLE' | 'DATA_LOSS'; export type GatewayStatus = {code?: GatewayCode | undefined, message?: string | undefined}; export type GatewayCluster = {name?: string | undefined, displayName?: string | undefined, createTime?: string | undefined, eksCluster?: GatewayEksCluster | undefined, fakeCluster?: GatewayFakeCluster | undefined, state?: GatewayClusterState | undefined, status?: GatewayStatus | undefined, updateTime?: string | undefined}; export type GatewayGatewayCreateClusterBody = {cluster: GatewayCluster, clusterId: string}; export type CreateApiV1AccountsAccountIdClustersArgs = {account_id: string, body: GatewayGatewayCreateClusterBody}; export type CreateApiV1AccountsAccountIdClustersOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayEksCluster = z.object({awsAccountId: z.string(), fireworksManagerRole: z.string().optional(), region: z.string(), clusterName: z.string().optional(), storageBucketName: z.string().optional(), metricWriterRole: z.string().optional(), loadBalancerControllerRole: z.string().optional(), workloadIdentityPoolProviderId: z.string().optional(), inferenceRole: z.string().optional()}); export const gatewayFakeCluster = z.object({projectId: z.string().optional(), location: z.string().optional(), clusterName: z.string().optional()}); export const gatewayClusterState = z.enum(["STATE_UNSPECIFIED", "CREATING", "READY", "DELETING", "FAILED"]); export const gatewayCode = z.enum(["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "UNAUTHENTICATED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS"]); export const gatewayStatus = z.object({code: gatewayCode.optional(), message: z.string().optional()}); export const gatewayCluster = z.object({name: z.string().optional(), displayName: z.string().optional(), createTime: z.string().optional(), eksCluster: gatewayEksCluster.optional(), fakeCluster: gatewayFakeCluster.optional(), state: gatewayClusterState.optional(), status: gatewayStatus.optional(), updateTime: z.string().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 }; /** * Create Cluster * * POST /v1/accounts/{account_id}/clusters */ export const createApiV1AccountsAccountIdClusters = async (args: CreateApiV1AccountsAccountIdClustersArgs, options: CreateApiV1AccountsAccountIdClustersOptions) => { 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(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/clusters${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(gatewayCluster, await res.json()) };