import {z} from 'zod' export type GetApiApiV1RunsRunIdGraphArgs = {run_id: string}; export type GetApiApiV1RunsRunIdGraphOptions = {baseUrl: string, CookieOAuth2TokenBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const executionStatus = z.enum(["initializing", "failed", "completed", "running", "cached"]); export const stepNodeDetails = z.object({execution_id: z.string(), name: z.string(), status: executionStatus, entrypoint_name: z.string(), parameters: z.object({}), configuration: z.object({}), inputs: z.object({}), outputs: z.object({}), metadata: z.array(z.array(z.unknown()))}); export const stepNode = z.object({id: z.string(), type: z.string().optional(), data: stepNodeDetails}); export const artifactNodeStatus = z.enum(["cached", "created", "external", "unknown"]); export const artifactNodeDetails = z.object({execution_id: z.string(), name: z.string(), status: artifactNodeStatus, is_cached: z.boolean(), artifact_type: z.string(), artifact_data_type: z.string(), parent_step_id: z.string(), producer_step_id: z.string().nullable(), uri: z.string(), metadata: z.array(z.array(z.unknown()))}); export const artifactNode = z.object({id: z.string(), type: z.string().optional(), data: artifactNodeDetails}); export const edge = z.object({id: z.string(), source: z.string(), target: z.string()}); export const lineageGraph = z.object({nodes: z.array(z.union([stepNode, artifactNode])).optional(), edges: z.array(edge).optional(), root_step_id: z.string().nullable().optional(), run_metadata: z.array(z.array(z.unknown())).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 Run Dag * * GET /api/v1/runs/{run_id}/graph */ export const getApiApiV1RunsRunIdGraph = async (args: GetApiApiV1RunsRunIdGraphArgs, options: GetApiApiV1RunsRunIdGraphOptions) => { const {baseUrl, fetch: fetchFn = fetch, CookieOAuth2TokenBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (CookieOAuth2TokenBearer !== undefined) headers.set('authorization', `Bearer ${CookieOAuth2TokenBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/runs/${encodeURIComponent(String(args.run_id))}/graph${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(lineageGraph, await res.json()) };