BID · Console
Baseline · Intelligence · Decision
src/agents/intelligence/insight-synthesis/schema.ts 1,687 bytes · typescript
/**
 * Insight Synthesis — input and output schemas (Std 2 + Std 11).
 */

import { z } from 'zod';
import { comparisonsSynthesisOutputSchema } from '../comparisons-synthesis/schema.js';

export const insightSynthesisInputSchema = comparisonsSynthesisOutputSchema;
export type InsightSynthesisInput = z.infer<typeof insightSynthesisInputSchema>;

export const insightSupportSchema = z.object({
  /** "comparison" | "metric" | "methodology" — what the citation refers to. */
  kind: z.enum(['comparison', 'metric', 'methodology']),
  /** The id of the supporting object — comparisonId / metricKey / methodology_id. */
  ref: z.string(),
  detail: z.string(),
});
export type InsightSupport = z.infer<typeof insightSupportSchema>;

export const insightSchema = z.object({
  insightId: z.string(),
  claim: z.string(),
  /** Free-text framework name (e.g. "peer-positioning", "trend-interpretation") or methodology_id. */
  frameworkUsed: z.string(),
  /** Marked `true` if the claim is inference beyond direct data support (Std 4 — must be flagged, not hidden). */
  isInference: z.boolean(),
  supportingEvidence: z.array(insightSupportSchema),
  reasoningLineage: z.array(z.string()),
  confidence: z.number().min(0).max(1),
  flags: z.array(z.string()),
});
export type Insight = z.infer<typeof insightSchema>;

export const insightSynthesisOutputSchema = z.object({
  insights: z.array(insightSchema),
  unsupportedClaimsRemoved: z.array(
    z.object({
      claim: z.string(),
      reason: z.string(),
    }),
  ),
  appliedFrameworks: z.array(z.string()),
  notes: z.array(z.string()),
});
export type InsightSynthesisOutput = z.infer<typeof insightSynthesisOutputSchema>;