/** * Workload heat map + soft fleet affinity (SP-215, #115). * * Colibri learning-cache analog for serve-time routing: a privacy-safe * histogram of successful routes keyed by requirement fingerprint (SHA-256 of * the rounded requirement vector — see `requirementFingerprint` in * degraded-route-sandwich.ts) or operator cluster id, recording * (tier, model id, success proxy, count). NEVER raw prompt text, messages, or * tool arguments — keys are irreversible digests or snake_case catalog ids. * * Uses: * - **First-turn / cold-start soft bias** — `resolveAffinity` produces a * bounded expected-cost discount for the heat-preferred tier, applied in * expected-cost.ts. Soft only: it never overrides capability shortfall, the * price-delta gate, pin cache economics, or absolute release gates. * - **Optional live affinity** — pinning/heat-affinity.ts applies hysteresis * (~25% + swap cap) at pin-safe boundaries when live updates are enabled. * * Distinct from OATS (#77, offline centroid refinement) and from the degraded * neural sandwich (#119 / SP-212, failover-only learned map): heat is a * healthy-path serve-time affinity, not a failover path. No FrugalGPT * generate-then-judge cascades — routing remains pre-generation. */ import { z } from 'zod'; import type { Tier } from '../types/index.js'; import { type WorkloadHeatConfig } from '../types/schemas.js'; /** Max distinct model ids tracked per cell; overflow folds into tier counts. */ export declare const MAX_MODELS_PER_CELL = 16; /** * Privacy-safe heat key. `requirementFingerprint` is a SHA-256 digest prefix * of the rounded requirement vector; `clusterId` is an operator-catalog id. * Neither can be reversed into prompt text. */ export interface WorkloadHeatKey { readonly requirementFingerprint: string | null; readonly clusterId: string | null; } export type HeatKeySpace = 'fingerprint' | 'cluster'; export declare function isValidHeatKey(key: WorkloadHeatKey): boolean; export interface TierHeatCount { readonly attempts: number; readonly successes: number; } /** Aggregated per-tier heat view for a key (fingerprint + cluster merged). */ export interface TierHeatSummary { readonly tier: Tier; readonly attempts: number; readonly successes: number; readonly successRate: number; } export declare const WORKLOAD_HEAT_ARTIFACT_VERSION = 1; export declare const HeatProvenanceSchema: z.ZodObject<{ created_at: z.ZodString; source: z.ZodEnum<{ "operator-local": "operator-local"; "dogfood-export": "dogfood-export"; imported: "imported"; }>; note: z.ZodOptional; }, z.core.$strip>; export type HeatProvenance = z.infer; export declare const WorkloadHeatArtifactSchema: z.ZodObject<{ version: z.ZodLiteral<1>; provenance: z.ZodObject<{ created_at: z.ZodString; source: z.ZodEnum<{ "operator-local": "operator-local"; "dogfood-export": "dogfood-export"; imported: "imported"; }>; note: z.ZodOptional; }, z.core.$strip>; cells: z.ZodArray; key: z.ZodString; tiers: z.ZodRecord>; models: z.ZodOptional>>; updated_at: z.ZodString; }, z.core.$strip>>; }, z.core.$strip>; export type WorkloadHeatArtifact = z.infer; /** * Soft first-turn affinity resolved from heat. `strength` is a fractional * expected-cost discount for `tier`, already capped by config (≤ 0.25). */ export interface HeatAffinity { readonly tier: Tier; readonly strength: number; readonly samples: number; readonly successRate: number; readonly runnerUpRate: number; } /** * In-memory bounded workload heat histogram. Two key spaces (fingerprint, * cluster id) with FIFO eviction per space so adversarial input cannot grow * the map without bound. All writes are validated; invalid keys/tiers are * rejected loudly (console.warn) and never stored. */ export declare class WorkloadHeatMap { private readonly maxEntries; private readonly byFingerprint; private readonly byClusterId; private readonly now; constructor(options?: { readonly maxEntries?: number; readonly clock?: () => string; }); /** Total cells across both key spaces (tests/telemetry). */ get size(): number; /** * Record one routed-turn outcome. `success` is the operator's success proxy * (e.g. no override, no loop escalation, positive feedback — labels are * owned by telemetry, never invented here). */ recordOutcome(key: WorkloadHeatKey, tier: Tier, modelId: string, success: boolean): void; /** Merged per-tier heat for a key (fingerprint first, cluster merged in). */ summarize(key: WorkloadHeatKey): readonly TierHeatSummary[] | null; /** * Resolve the soft first-turn affinity for a key, or null when heat is * insufficient to bias. Gates: config.enabled, min_samples on the leader, * and min_success_margin over the runner-up. Strength is config-capped. */ resolveAffinity(key: WorkloadHeatKey, config: WorkloadHeatConfig): HeatAffinity | null; /** Raw per-tier counts for one key-space entry (export / hysteresis). */ getCell(keySpace: HeatKeySpace, key: string): { readonly tiers: ReadonlyMap; readonly updatedAt: string; } | null; /** * Decaying heat (Colibri analog): multiply all counts by `factor` in (0, 1], * flooring; empty tier/model counts are dropped. Used at live-repin time so * the hot set tracks the live workload instead of accumulating forever. */ decay(factor: number): void; /** Drop all heat (operator clear path — router-reset analog). */ clear(): void; /** Serialize to a versioned artifact with provenance (export path). */ exportArtifact(provenance: HeatProvenance): WorkloadHeatArtifact; /** * Load a histogram from an artifact. Invalid artifacts throw (fail loud); * invalid cells/keys inside a valid artifact are skipped with a warning. */ static importArtifact(artifact: unknown, options?: { readonly maxEntries?: number; readonly clock?: () => string; }): WorkloadHeatMap; private upsertCell; } //# sourceMappingURL=workload-heat.d.ts.map