import {z} from 'zod' export type LogicalOperators = 'or' | 'and'; export type GetApiApiV1StepsArgs = {hydrate?: boolean | undefined, sort_by?: string | undefined, logical_operator?: LogicalOperators | undefined, page?: number | undefined, size?: number | undefined, id?: (string | string | null) | undefined, created?: (string | string | null) | undefined, updated?: (string | string | null) | undefined, scope_workspace?: (string | null) | undefined, name?: (string | null) | undefined, code_hash?: (string | null) | undefined, cache_key?: (string | null) | undefined, status?: (string | null) | undefined, start_time?: (string | string | null) | undefined, end_time?: (string | string | null) | undefined, pipeline_run_id?: (string | string | null) | undefined, original_step_run_id?: (string | string | null) | undefined, user_id?: (string | string | null) | undefined, workspace_id?: (string | string | null) | undefined}; export type GetApiApiV1StepsOptions = {baseUrl: string, CookieOAuth2TokenBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userResponseBody = z.object({created: z.string(), updated: z.string(), active: z.boolean().optional(), activation_token: z.string().max(255).nullable().optional(), full_name: z.string().max(255).optional(), email_opted_in: z.boolean().nullable().optional(), is_service_account: z.boolean(), is_admin: z.boolean()}); export const userResponseMetadata = z.object({email: z.string().max(255).nullable().optional(), external_user_id: z.string().nullable().optional(), user_metadata: z.object({}).optional()}); export const userResponseResources = z.record(z.string(), z.unknown()); export const userResponse = z.object({body: userResponseBody.nullable().optional(), metadata: userResponseMetadata.nullable().optional(), resources: userResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const executionStatus = z.enum(["initializing", "failed", "completed", "running", "cached"]); export const colorVariants = z.enum(["grey", "purple", "red", "green", "yellow", "orange", "lime", "teal", "turquoise", "magenta", "blue"]); export const tagResponseBody = z.object({created: z.string(), updated: z.string(), color: colorVariants.optional(), tagged_count: z.number().int()}); export const baseResponseMetadata = z.object({}); export const tagResponseResources = z.record(z.string(), z.unknown()); export const tagResponse = z.object({body: tagResponseBody.nullable().optional(), metadata: baseResponseMetadata.nullable().optional(), resources: tagResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const artifactResponseBody = z.object({created: z.string(), updated: z.string(), tags: z.array(tagResponse), latest_version_name: z.string().nullable().optional(), latest_version_id: z.string().nullable().optional()}); export const artifactResponseMetadata = z.object({has_custom_name: z.boolean().optional()}); export const artifactResponseResources = z.record(z.string(), z.unknown()); export const artifactResponse = z.object({body: artifactResponseBody.nullable().optional(), metadata: artifactResponseMetadata.nullable().optional(), resources: artifactResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const artifactType = z.enum(["DataAnalysisArtifact", "DataArtifact", "ModelArtifact", "SchemaArtifact", "ServiceArtifact", "StatisticsArtifact", "BaseArtifact"]); export const sourceType = z.enum(["user", "builtin", "internal", "distribution_package", "code_repository", "notebook", "unknown"]); export const source = z.object({module: z.string(), attribute: z.string().nullable().optional(), type: sourceType}).and(z.record(z.string(), z.unknown())); export const artifactVersionResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), artifact: artifactResponse, version: z.string(), uri: z.string().max(65535), type: artifactType, materializer: source, data_type: source, tags: z.array(tagResponse), producer_pipeline_run_id: z.string().nullable().optional()}); export const workspaceResponseBody = z.object({created: z.string(), updated: z.string()}); export const workspaceResponseMetadata = z.object({description: z.string().max(255).optional()}); export const workspaceResponseResources = z.record(z.string(), z.unknown()); export const workspaceResponse = z.object({body: workspaceResponseBody.nullable().optional(), metadata: workspaceResponseMetadata.nullable().optional(), resources: workspaceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const visualizationType = z.enum(["csv", "html", "image", "markdown"]); export const artifactVisualizationResponseBody = z.object({created: z.string(), updated: z.string(), type: visualizationType, uri: z.string()}); export const artifactVisualizationResponseMetadata = z.object({artifact_version_id: z.string()}); export const artifactVisualizationResponseResources = z.record(z.string(), z.unknown()); export const artifactVisualizationResponse = z.object({body: artifactVisualizationResponseBody.nullable().optional(), metadata: artifactVisualizationResponseMetadata.nullable().optional(), resources: artifactVisualizationResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const metadataTypeEnum = z.enum(["str", "int", "float", "bool", "list", "dict", "tuple", "set", "Uri", "Path", "DType", "StorageSize"]); export const runMetadataResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), key: z.string(), value: z.union([z.string(), z.number().int(), z.number(), z.boolean(), z.object({}), z.array(z.unknown()), z.array(z.unknown())]), type: metadataTypeEnum}); export const metadataResourceTypes = z.enum(["pipeline_run", "step_run", "artifact_version", "model_version"]); export const runMetadataResponseMetadata = z.object({workspace: workspaceResponse, resource_id: z.string(), resource_type: metadataResourceTypes, stack_component_id: z.string().nullable()}); export const runMetadataResponseResources = z.record(z.string(), z.unknown()); export const runMetadataResponse = z.object({body: runMetadataResponseBody.nullable().optional(), metadata: runMetadataResponseMetadata.nullable().optional(), resources: runMetadataResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const artifactVersionResponseMetadata = z.object({workspace: workspaceResponse, artifact_store_id: z.string().nullable().optional(), producer_step_run_id: z.string().nullable().optional(), visualizations: z.array(artifactVisualizationResponse).nullable().optional(), run_metadata: z.record(z.string(), runMetadataResponse).optional()}); export const artifactVersionResponseResources = z.record(z.string(), z.unknown()); export const artifactVersionResponse = z.object({body: artifactVersionResponseBody.nullable().optional(), metadata: artifactVersionResponseMetadata.nullable().optional(), resources: artifactVersionResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const stepRunResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), status: executionStatus, inputs: z.record(z.string(), artifactVersionResponse).optional(), outputs: z.record(z.string(), artifactVersionResponse).optional(), model_version_id: z.string().nullable().optional()}); export const baseSettings = z.record(z.string(), z.unknown()); export const modelStages = z.enum(["none", "staging", "production", "archived", "latest"]); export const model = z.object({name: z.string(), license: z.string().nullable().optional(), description: z.string().nullable().optional(), audience: z.string().nullable().optional(), use_cases: z.string().nullable().optional(), limitations: z.string().nullable().optional(), trade_offs: z.string().nullable().optional(), ethics: z.string().nullable().optional(), tags: z.array(z.string()).nullable().optional(), version: z.union([modelStages, z.number().int(), z.string()]).nullable().optional(), save_models_to_registry: z.boolean().optional(), model_version_id: z.string().nullable().optional(), suppress_class_validation_warnings: z.boolean().optional(), was_created_in_this_run: z.boolean().optional()}); export const stepRetryConfig = z.object({max_retries: z.number().int().optional(), delay: z.number().int().optional(), backoff: z.number().int().optional()}); export const artifactConfigurationOutput = z.object({materializer_source: z.array(source), default_materializer_source: source.nullable().optional()}); export const externalArtifactConfigurationOutput = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), version: z.string().nullable().optional(), model: model.nullable().optional()}); export const modelVersionDataLazyLoaderOutput = z.object({model: model, artifact_name: z.string().nullable().optional(), artifact_version: z.string().nullable().optional(), metadata_name: z.string().nullable().optional()}); export const callStep = z.object({attribute_name: z.string().nullable().optional(), is_call: z.boolean().nullable().optional(), call_args: z.array(z.unknown()).nullable().optional(), call_kwargs: z.object({}).nullable().optional(), selector: z.unknown()}); export const clientLazyLoader = z.object({method_name: z.string(), call_chain: z.array(callStep).optional(), exclude_next_call: z.boolean().optional()}); export const stepConfigurationOutput = z.object({name: z.string(), enable_cache: z.boolean().nullable().optional(), enable_artifact_metadata: z.boolean().nullable().optional(), enable_artifact_visualization: z.boolean().nullable().optional(), enable_step_logs: z.boolean().nullable().optional(), step_operator: z.string().nullable().optional(), experiment_tracker: z.string().nullable().optional(), parameters: z.object({}).optional(), settings: z.record(z.string(), baseSettings).optional(), extra: z.object({}).optional(), failure_hook_source: source.nullable().optional(), success_hook_source: source.nullable().optional(), model: model.nullable().optional(), retry: stepRetryConfig.nullable().optional(), outputs: z.record(z.string(), artifactConfigurationOutput).optional(), caching_parameters: z.object({}).optional(), external_input_artifacts: z.record(z.string(), externalArtifactConfigurationOutput).optional(), model_artifacts_or_metadata: z.record(z.string(), modelVersionDataLazyLoaderOutput).optional(), client_lazy_loaders: z.record(z.string(), clientLazyLoader).optional()}); export const inputSpec = z.object({step_name: z.string(), output_name: z.string()}); export const stepSpecOutput = z.object({source: source, upstream_steps: z.array(z.string()), inputs: z.record(z.string(), inputSpec).optional(), pipeline_parameter_name: z.string().optional()}); export const logsResponseBody = z.object({created: z.string(), updated: z.string(), uri: z.string().max(65535)}); export const logsResponseMetadata = z.object({step_run_id: z.union([z.string(), z.string()]).nullable().optional(), pipeline_run_id: z.union([z.string(), z.string()]).nullable().optional(), artifact_store_id: z.union([z.string(), z.string()])}); export const logsResponseResources = z.record(z.string(), z.unknown()); export const logsResponse = z.object({body: logsResponseBody.nullable().optional(), metadata: logsResponseMetadata.nullable().optional(), resources: logsResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional()}); export const stepRunResponseMetadata = z.object({workspace: workspaceResponse, config: stepConfigurationOutput, spec: stepSpecOutput, cache_key: z.string().max(255).nullable().optional(), code_hash: z.string().max(255).nullable().optional(), docstring: z.string().max(65535).nullable().optional(), source_code: z.string().max(65535).nullable().optional(), start_time: z.string().nullable().optional(), end_time: z.string().nullable().optional(), logs: logsResponse.nullable().optional(), deployment_id: z.string(), pipeline_run_id: z.string(), original_step_run_id: z.string().nullable().optional(), parent_step_ids: z.array(z.string()).optional(), run_metadata: z.record(z.string(), runMetadataResponse).optional()}); export const modelResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), tags: z.array(tagResponse), latest_version_name: z.string().nullable().optional(), latest_version_id: z.string().nullable().optional()}); export const modelResponseMetadata = z.object({workspace: workspaceResponse, license: z.string().max(65535).nullable().optional(), description: z.string().max(65535).nullable().optional(), audience: z.string().max(65535).nullable().optional(), use_cases: z.string().max(65535).nullable().optional(), limitations: z.string().max(65535).nullable().optional(), trade_offs: z.string().max(65535).nullable().optional(), ethics: z.string().max(65535).nullable().optional(), save_models_to_registry: z.boolean().optional()}); export const modelResponseResources = z.record(z.string(), z.unknown()); export const modelResponse = z.object({body: modelResponseBody.nullable().optional(), metadata: modelResponseMetadata.nullable().optional(), resources: modelResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const modelVersionResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), stage: z.string().max(255).nullable().optional(), number: z.number().int(), model: modelResponse, model_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), data_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), deployment_artifact_ids: z.record(z.string(), z.record(z.string(), z.string())).optional(), pipeline_run_ids: z.record(z.string(), z.string()).optional(), tags: z.array(tagResponse).optional()}); export const modelVersionResponseMetadata = z.object({workspace: workspaceResponse, description: z.string().max(65535).nullable().optional(), run_metadata: z.record(z.string(), runMetadataResponse).optional()}); export const serviceType = z.object({type: z.string(), flavor: z.string(), name: z.string().optional(), description: z.string().optional(), logo_url: z.string().optional()}); export const serviceState = z.enum(["inactive", "active", "pending_startup", "pending_shutdown", "error", "scaled_to_zero"]); export const serviceResponseBody = z.object({created: z.string(), updated: z.string(), user: userResponse.nullable().optional(), service_type: serviceType, labels: z.record(z.string(), z.string()).nullable().optional(), state: serviceState.nullable().optional()}); export const serviceResponseMetadata = z.object({workspace: workspaceResponse, service_source: z.string().nullable(), admin_state: serviceState.nullable(), config: z.object({}), status: z.object({}).nullable(), endpoint: z.object({}).nullable().optional(), prediction_url: z.string().nullable().optional(), health_check_url: z.string().nullable().optional()}); export const serviceResponseResources = z.record(z.string(), z.unknown()); export const serviceResponse = z.object({body: serviceResponseBody.nullable().optional(), metadata: serviceResponseMetadata.nullable().optional(), resources: serviceResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const pageServiceResponse = z.object({index: z.number().int().gt(0), max_size: z.number().int().gt(0), total_pages: z.number().int().gte(0), total: z.number().int().gte(0), items: z.array(serviceResponse)}); export const modelVersionResponseResources = z.object({services: pageServiceResponse}).and(z.record(z.string(), z.unknown())); export const modelVersionResponse = z.object({body: modelVersionResponseBody.nullable().optional(), metadata: modelVersionResponseMetadata.nullable().optional(), resources: modelVersionResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255).nullable().optional()}); export const stepRunResponseResources = z.object({model_version: modelVersionResponse.nullable().optional()}).and(z.record(z.string(), z.unknown())); export const stepRunResponse = z.object({body: stepRunResponseBody.nullable().optional(), metadata: stepRunResponseMetadata.nullable().optional(), resources: stepRunResponseResources.nullable().optional(), id: z.string(), permission_denied: z.boolean().optional(), name: z.string().max(255)}); export const pageStepRunResponse = z.object({index: z.number().int().gt(0), max_size: z.number().int().gt(0), total_pages: z.number().int().gte(0), total: z.number().int().gte(0), items: z.array(stepRunResponse)}); 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 }; /** * List Run Steps * * GET /api/v1/steps */ export const getApiApiV1Steps = async (args: GetApiApiV1StepsArgs, options: GetApiApiV1StepsOptions) => { const {baseUrl, fetch: fetchFn = fetch, CookieOAuth2TokenBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.hydrate != null) query.append("hydrate", String(args.hydrate)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.logical_operator != null) query.append("logical_operator", String(args.logical_operator)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.id != null) query.append("id", String(args.id)) if (args.created != null) query.append("created", String(args.created)) if (args.updated != null) query.append("updated", String(args.updated)) if (args.scope_workspace != null) query.append("scope_workspace", String(args.scope_workspace)) if (args.name != null) query.append("name", String(args.name)) if (args.code_hash != null) query.append("code_hash", String(args.code_hash)) if (args.cache_key != null) query.append("cache_key", String(args.cache_key)) if (args.status != null) query.append("status", String(args.status)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.pipeline_run_id != null) query.append("pipeline_run_id", String(args.pipeline_run_id)) if (args.original_step_run_id != null) query.append("original_step_run_id", String(args.original_step_run_id)) if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (CookieOAuth2TokenBearer !== undefined) headers.set('authorization', `Bearer ${CookieOAuth2TokenBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/steps${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(pageStepRunResponse, await res.json()) };