import {z} from 'zod' export type GetApiV2DeploymentsDeploymentIdRevisionsRevisionIdArgs = {deployment_id: string, revision_id: string}; export type GetApiV2DeploymentsDeploymentIdRevisionsRevisionIdOptions = {baseUrl: string, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const sourceRevisionConfig = z.object({repo_ref: z.string().nullable().optional(), langgraph_config_path: z.string().nullable().optional(), image_uri: z.string().nullable().optional(), source_tarball_path: z.string().nullable().optional(), repo_commit_sha: z.string().nullable().optional()}); export const revision = z.object({id: z.string(), created_at: z.string(), updated_at: z.string(), status: z.enum(["CREATING", "QUEUED", "AWAITING_BUILD", "BUILDING", "AWAITING_DEPLOY", "DEPLOYING", "CREATE_FAILED", "BUILD_FAILED", "DEPLOY_FAILED", "DEPLOYED", "SKIPPED", "INTERRUPTED", "UNKNOWN"]), source: z.enum(["github", "external_docker", "internal_docker", "internal_source", "internal_template"]), source_revision_config: sourceRevisionConfig}); 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 Revision * * GET /v2/deployments/{deployment_id}/revisions/{revision_id} * * Also accepts auth: Tenant ID, Bearer Auth */ export const getApiV2DeploymentsDeploymentIdRevisionsRevisionId = async (args: GetApiV2DeploymentsDeploymentIdRevisionsRevisionIdArgs, options: GetApiV2DeploymentsDeploymentIdRevisionsRevisionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-API-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/deployments/${encodeURIComponent(String(args.deployment_id))}/revisions/${encodeURIComponent(String(args.revision_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(revision, await res.json()) };