import {z} from 'zod' export type GetApiVersionsVersionIdArgs = {version_id: string}; export type GetApiVersionsVersionIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const aCPType = z.enum(["sync", "async"]); export const sDKType = z.enum(["claude_agent_sdk", "codex_agent_sdk"]); export const versionStatus = z.enum(["DEPLOYING", "ACTIVE", "FAILED", "UNHEALTHY", "DRAINING", "RETIRED", "ROLLED_BACK"]); export const versionResponse = z.object({acp_type: aCPType, author_email: z.string(), author_name: z.string(), branch_id: z.string(), created_at: z.string().nullable().optional(), deployed_at: z.string(), failure_diagnostics: z.record(z.string(), z.string()).nullable().optional(), failure_reason: z.string().nullable().optional(), git_branch: z.string(), git_hash: z.string(), git_message: z.string().optional(), id: z.string(), image_expires_at: z.string().nullable().optional(), image_url: z.string(), is_dirty: z.boolean().optional(), last_rollback_at: z.string().nullable().optional(), replicas: z.number().int().optional(), retired_at: z.string().nullable().optional(), rollback_count: z.number().int().optional(), rolled_back_at: z.string().nullable().optional(), sdk_type: sDKType, source_filesystem_id: z.string().nullable().optional(), status: versionStatus, updated_at: z.string().nullable().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 }; /** * Get Version * * GET /versions/{version_id} */ export const getApiVersionsVersionId = async (args: GetApiVersionsVersionIdArgs, options: GetApiVersionsVersionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/versions/${encodeURIComponent(String(args.version_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(versionResponse, await res.json()) };