From bca0c667c9f1d99f93313e5d7a4002f939f346de Mon Sep 17 00:00:00 2001 From: Arda Erzin Date: Thu, 23 Jul 2026 17:48:48 +0200 Subject: [PATCH] refactor(frontend): drop duplicate EvaluationRun, align step-reference shape usePreviewEvaluations declared its own EvaluationRun while @agenta/entities/evaluationRun already had the canonical zod-derived one. The local copy over-declared requiredness (name/description/status/meta/flags as non-null) where the schema says the backend can send null, so #5464 had to hand-add updated_at to keep it current. Deleted it; the two importers and the hook now take the type from the package. Swapping surfaced drift inside @agenta/entities itself: the step-reference shape was redeclared three times with different types. The core zod schema has {id, slug?: string|null, version?: number|null}, while the ETL RunStep said slug?: string and version?: STRING, and ColumnGroup.refs said id?: string. Both now reference the exported EvaluationRunStepReference from the validated schema. CandidateRun.status widened to match. Scoped out, with reasons: - PreviewTestset is NOT the entities Testset (different endpoint shape: it carries slug plus embedded data.testcases; entities Testset is lean metadata). PreviewTestCase does match Fern TestcaseOutput, but entities has no canonical testcase entity type to route it through yet. - OrganizationProvider has no entities domain at all, and the response settings is a free-form dict while Fern's SsoProviderSettingsDto models create-input. Creating a domain for one interface is disproportionate. --- .../EvalRunDetails/atoms/table/run.ts | 3 +- .../components/CompareRunsMenu.tsx | 2 +- .../EvaluationRunsTablePOC/types.ts | 4 +- .../lib/hooks/usePreviewEvaluations/index.ts | 4 +- .../lib/hooks/usePreviewEvaluations/types.ts | 40 +------------------ .../src/evaluationRun/core/schema.ts | 1 + .../src/evaluationRun/etl/resolveMappings.ts | 6 ++- 7 files changed, 13 insertions(+), 47 deletions(-) diff --git a/web/oss/src/components/EvalRunDetails/atoms/table/run.ts b/web/oss/src/components/EvalRunDetails/atoms/table/run.ts index d26f04baaf..692c547076 100644 --- a/web/oss/src/components/EvalRunDetails/atoms/table/run.ts +++ b/web/oss/src/components/EvalRunDetails/atoms/table/run.ts @@ -1,3 +1,4 @@ +import type {EvaluationRun} from "@agenta/entities/evaluationRun" import {fetchWorkflowsBatch} from "@agenta/entities/workflow" import {atomFamily, selectAtom} from "jotai/utils" import {atomWithQuery} from "jotai-tanstack-query" @@ -13,8 +14,6 @@ import { import {TERMINAL_STATUSES} from "../compare" import {effectiveProjectIdAtom} from "../run" -import type {EvaluationRun} from "@/agenta-oss-common/lib/hooks/usePreviewEvaluations/types" - export interface EvaluationRunQueryResult { rawRun: EvaluationRun camelRun: any diff --git a/web/oss/src/components/EvalRunDetails/components/CompareRunsMenu.tsx b/web/oss/src/components/EvalRunDetails/components/CompareRunsMenu.tsx index c29a6cea9b..e4f0ec5a32 100644 --- a/web/oss/src/components/EvalRunDetails/components/CompareRunsMenu.tsx +++ b/web/oss/src/components/EvalRunDetails/components/CompareRunsMenu.tsx @@ -34,7 +34,7 @@ interface CompareRunsMenuProps { interface CandidateRun { id: string name: string - status?: string + status?: string | null description?: string | null createdAt?: string testsetNames: string[] diff --git a/web/oss/src/components/EvaluationRunsTablePOC/types.ts b/web/oss/src/components/EvaluationRunsTablePOC/types.ts index 531c1c4908..119b9d0300 100644 --- a/web/oss/src/components/EvaluationRunsTablePOC/types.ts +++ b/web/oss/src/components/EvaluationRunsTablePOC/types.ts @@ -1,9 +1,9 @@ +import type {EvaluationRun} from "@agenta/entities/evaluationRun" + import type {InfiniteTableRowBase} from "@/oss/components/InfiniteVirtualTable/types" import type {WindowingState} from "@/oss/components/InfiniteVirtualTable/types" import type {SnakeToCamelCaseKeys} from "@/oss/lib/Types" -import type {EvaluationRun} from "@/agenta-oss-common/lib/hooks/usePreviewEvaluations/types" - // The original `@/oss/state/evaluations/legacyAtoms` module no longer exists, and `legacy` // is only ever read through `any` casts — represented as an opaque record (per WP-4i). export type LegacyAutoEvaluation = Record diff --git a/web/oss/src/lib/hooks/usePreviewEvaluations/index.ts b/web/oss/src/lib/hooks/usePreviewEvaluations/index.ts index 11c2c03400..12829321c7 100644 --- a/web/oss/src/lib/hooks/usePreviewEvaluations/index.ts +++ b/web/oss/src/lib/hooks/usePreviewEvaluations/index.ts @@ -127,7 +127,9 @@ interface PreviewEvaluationsQueryState { error: unknown } import {searchQueryAtom} from "./states/queryFilterAtoms" -import {EnrichedEvaluationRun, EvaluationRun} from "./types" +import type {EvaluationRun} from "@agenta/entities/evaluationRun" + +import {EnrichedEvaluationRun} from "./types" const SCENARIOS_ENDPOINT = "/evaluations/scenarios/" diff --git a/web/oss/src/lib/hooks/usePreviewEvaluations/types.ts b/web/oss/src/lib/hooks/usePreviewEvaluations/types.ts index 2a56892fc3..ae8f25b49f 100644 --- a/web/oss/src/lib/hooks/usePreviewEvaluations/types.ts +++ b/web/oss/src/lib/hooks/usePreviewEvaluations/types.ts @@ -1,3 +1,4 @@ +import type {EvaluationRun} from "@agenta/entities/evaluationRun" import type {Workflow} from "@agenta/entities/workflow" import {PreviewTestset, SnakeToCamelCaseKeys, WorkspaceMember} from "@/oss/lib/Types" @@ -37,45 +38,6 @@ export type EvaluationRunDataStep = } export type IEvaluationRunDataStep = SnakeToCamelCaseKeys -export interface EvaluationRun { - /** Unique identifier for the evaluation run */ - id: string - /** Display name for the run */ - name: string - /** Optional description text for the run */ - description: string - /** ISO timestamp of when the run was created */ - created_at: string - /** ISO timestamp of when the run was last updated (present on backend run payloads) */ - updated_at?: string - /** ID of the user who created the run */ - created_by_id: string - /** Optional metadata object (arbitrary key-value pairs) */ - meta: Record - /** Flags associated with the run (internal use) */ - flags: Record - /** Current status of the run (e.g., "pending", "completed") */ - status: string - data: { - /** Array of evaluation steps that define execution flow */ - steps: EvaluationRunDataStep[] - /** Mappings define how to extract values from steps for display or evaluation */ - mappings: { - /** Type of the mapping, determines what the value represents */ - kind: "input" | "ground_truth" | "application" | "evaluator" - /** Display name for the mapped value */ - name: string - /** Path reference to the data inside a step */ - step: { - /** The step key this mapping belongs to */ - key: string - /** Path within the step data (e.g., 'country' or 'data.outputs.metric') */ - path: string - } - }[] - } -} - export interface EnrichedEvaluationRun extends SnakeToCamelCaseKeys { /** All distinct testsets referenced in this run */ testsets: PreviewTestset[] diff --git a/web/packages/agenta-entities/src/evaluationRun/core/schema.ts b/web/packages/agenta-entities/src/evaluationRun/core/schema.ts index cc53584944..d42dccc706 100644 --- a/web/packages/agenta-entities/src/evaluationRun/core/schema.ts +++ b/web/packages/agenta-entities/src/evaluationRun/core/schema.ts @@ -47,6 +47,7 @@ export const evaluationRunStepReferenceSchema = z.object({ slug: z.string().nullable().optional(), version: z.coerce.number().nullable().optional(), }) +export type EvaluationRunStepReference = z.infer export const evaluationRunDataStepSchema = z.object({ key: z.string(), diff --git a/web/packages/agenta-entities/src/evaluationRun/etl/resolveMappings.ts b/web/packages/agenta-entities/src/evaluationRun/etl/resolveMappings.ts index 671a854ff4..55121fb424 100644 --- a/web/packages/agenta-entities/src/evaluationRun/etl/resolveMappings.ts +++ b/web/packages/agenta-entities/src/evaluationRun/etl/resolveMappings.ts @@ -39,6 +39,7 @@ */ import type {EvaluationResult} from "../core" +import type {EvaluationRunStepReference} from "../core/schema" import type {HydratedScenarioRow, HydratableScenario} from "./hydrateScenariosTransform" @@ -54,7 +55,8 @@ export interface RunStep { */ type: string origin?: string | null - references?: Record | null + /** Shape comes from the validated core schema; do not redeclare it here. */ + references?: Record | null inputs?: {key: string}[] | null } @@ -108,7 +110,7 @@ export interface ColumnGroup { /** Stable cache key for this group — useful for grouping in renderers. */ key: string /** The step.references that drove the grouping (preserved for downstream code). */ - refs: Record | null + refs: Record | null } export interface ResolvedColumn {