/** * Provider Router Types (RFC-0054) */ import type { ProviderState } from "../../types/src/runtime-types.ts"; import type { Capability } from "../../capability-registry/src/types.ts"; // Re-export Latency from here for convenience export type Latency = "fast" | "medium" | "slow"; // ─── Routing Types ───────────────────────────────────────────────────── export type RoutingStrategy = | "cheapest" | "fastest" | "best_quality" | "balanced" | "quota_aware"; export interface RoutingPolicy { defaultStrategy: RoutingStrategy; costWeight: number; // 0-100 qualityWeight: number; // 0-100 latencyWeight: number; // 0-100 quotaWeight: number; // 0-100 fallbackProviders: string[]; taskTypeOverrides: Record; providerPreferences: Record; } export interface QuotaState { exhausted: boolean; remainingPct: number; } export interface RoutingContext { task: { id: string; title: string; description: string; type: string; }; requirement?: { id: string; description: string; }; providerStates: Record; quotaStates: Record; costBudget?: { remaining: number; }; } export interface RoutingOptions { preferCheapest?: boolean; preferFastest?: boolean; preferHighestQuality?: boolean; maxCostPerTask?: number; requiredCapabilities?: Capability[]; preferProviders?: string[]; avoidProviders?: string[]; } export interface ProviderCandidate { providerId: string; modelId: string; capabilities: Capability[]; estimatedCost?: number; estimatedLatency: Latency; qualityScore?: number; remainingQuotaPct: number; } export interface RoutingDecision { providerId: string; modelId: string; reason: string; estimatedCost?: number; estimatedLatency?: Latency; confidence: number; } // ─── Router Interface ────────────────────────────────────────────────── export interface ProviderRouter { selectProvider( task: RoutingContext["task"], context: RoutingContext, options?: RoutingOptions, ): Promise; selectProviders( task: RoutingContext["task"], context: RoutingContext, count: number, ): Promise; getRoutingPolicy(): RoutingPolicy; setRoutingPolicy(policy: RoutingPolicy): void; } // ─── Event Types ───────────────────────────────────────────────────── export type ProviderRouterEvent = | { type: "router.provider_selected"; taskId: string; providerId: string; reason: string; } | { type: "router.no_candidates"; taskId: string; reason: string } | { type: "router.policy_updated"; oldPolicy: RoutingPolicy; newPolicy: RoutingPolicy; } | { type: "router.fallback_triggered"; taskId: string; originalProvider: string; fallbackProvider: string; }; // ─── Latency Ranking ───────────────────────────────────────────────── export const LATENCY_RANK: Record = { fast: 1, medium: 2, slow: 3, };