BID · Console
Baseline · Intelligence · Decision
src/agents/intelligence/performance-metrics/schema.ts 1,817 bytes · typescript
/**
 * Performance Metrics — input and output schemas (Std 2 + Std 11).
 *
 * Input: AnalyticalTable from Agent 1.
 * Output: ComputedMetrics — values + methodology used + lineage.
 */

import { z } from 'zod';
import { analyticalTableOutputSchema } from '../analytical-table/schema.js';

export const performanceMetricsInputSchema = analyticalTableOutputSchema;
export type PerformanceMetricsInput = z.infer<typeof performanceMetricsInputSchema>;

export const computedMetricSchema = z.object({
  /** Canonical metric key the JobRequest asked for. */
  metricKey: z.string(),
  entity: z.string(),
  period: z.string(),
  value: z.number().nullable(),
  unit: z.string(),
  /** methodology_id from the library that was applied, or null if no
   *  methodology was needed (identity / direct pass-through). */
  methodologyId: z.string().nullable(),
  /** Why this methodology was chosen — Std 3 explainability. */
  methodologyRationale: z.string(),
  /** Lineage from this metric back through the analytical table cells. */
  inputLineage: z.array(z.string()),
  /** 0-1 per-metric confidence. */
  confidence: z.number().min(0).max(1),
  /** Any per-metric flags raised (Std 8). */
  flags: z.array(z.string()),
});
export type ComputedMetric = z.infer<typeof computedMetricSchema>;

export const methodologyGapSchema = z.object({
  metricKey: z.string(),
  entity: z.string(),
  period: z.string(),
  reason: z.string(),
});
export type MethodologyGap = z.infer<typeof methodologyGapSchema>;

export const performanceMetricsOutputSchema = z.object({
  metrics: z.array(computedMetricSchema),
  methodologyGaps: z.array(methodologyGapSchema),
  appliedMethodologies: z.array(z.string()),
  notes: z.array(z.string()),
});
export type PerformanceMetricsOutput = z.infer<typeof performanceMetricsOutputSchema>;