import {z} from 'zod' export type GetApiV1ExperimentsExperimentIdAssetsArgs = {experiment_id: string, limit?: number | undefined, selected_job_id?: (string | null) | undefined}; export type GetApiV1ExperimentsExperimentIdAssetsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const experimentAssetSummary = z.object({active_job_count: z.number().int().gte(0), total_job_count: z.number().int().gte(0), failed_job_count: z.number().int().gte(0), dataset_count: z.number().int().gte(0), evaluation_count: z.number().int().gte(0), base_models: z.array(z.string()), base_models_truncated: z.boolean(), last_activity_at: z.string(), category_label: z.string().max(120).nullable().optional(), last_agent_message: z.string().max(241).nullable().optional(), agent_step_count: z.number().int().gte(0).nullable().optional(), agent_turn_active: z.boolean()}); export const experimentJobDatasetResponse = z.object({dataset_id: z.string(), name: z.string(), version_number: z.string()}); export const experimentTrainingJobResponse = z.object({id: z.string(), model_name: z.string().nullable(), version_number: z.string(), base_model: z.string(), status: z.string(), normalized_status: z.string(), is_active: z.boolean(), is_serving_incumbent: z.boolean().optional(), progress_percent: z.number().int().nullable(), dataset_versions: z.array(experimentJobDatasetResponse), dataset_versions_truncated: z.boolean(), created_at: z.string(), last_activity_at: z.string(), started_at: z.string().nullable(), completed_at: z.string().nullable(), hub_model_id: z.string().nullable().optional(), hub_model_private: z.boolean().nullable().optional()}); export const experimentDatasetResponse = z.object({id: z.string(), name: z.string(), version_number: z.string(), dataset_type: z.string(), sample_size: z.number().int().nullable(), status: z.string().nullable(), attached_at: z.string(), source_experiment_id: z.string().nullable(), last_activity_at: z.string()}); export const experimentEvaluationResponse = z.object({id: z.string(), model_id: z.string(), model_name: z.string().nullable(), incumbent_model_id: z.string().nullable().optional(), dataset_id: z.string().nullable(), status: z.string(), f1_score: z.number().nullable(), f1_std: z.number().nullable().optional(), precision_score: z.number().nullable(), precision_std: z.number().nullable().optional(), recall_score: z.number().nullable(), recall_std: z.number().nullable().optional(), accuracy: z.number().nullable(), accuracy_std: z.number().nullable().optional(), validation_loss: z.number().nullable(), validation_loss_std: z.number().nullable().optional(), draw_count: z.number().int().nullable().optional(), sample_count: z.number().int().nullable(), created_at: z.string().nullable(), completed_at: z.string().nullable()}); export const experimentAssetsResponse = z.object({experiment_id: z.string(), summary: experimentAssetSummary, training_jobs: z.array(experimentTrainingJobResponse), datasets: z.array(experimentDatasetResponse), evaluations: z.array(experimentEvaluationResponse), selected_training_job: experimentTrainingJobResponse.nullable(), training_jobs_has_more: z.boolean(), datasets_has_more: z.boolean(), evaluations_has_more: z.boolean(), serving_model_id: 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 }; /** * Read bounded Experiment jobs, datasets, and evaluations * * GET /v1/experiments/{experiment_id}/assets * * Also accepts auth: BearerAuth */ export const getApiV1ExperimentsExperimentIdAssets = async (args: GetApiV1ExperimentsExperimentIdAssetsArgs, options: GetApiV1ExperimentsExperimentIdAssetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.selected_job_id != null) query.append("selected_job_id", String(args.selected_job_id)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/experiments/${encodeURIComponent(String(args.experiment_id))}/assets${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(experimentAssetsResponse, await res.json()) };