/** Prompt optimization hooks, complete trace records, and score aggregation. Hosts own persistence. */ import type { UUID } from "./types/primitives.js"; import type { IAgentRuntime } from "./types/runtime.js"; import type { SchemaRow } from "./types/state.js"; export interface MergePromptTemplateContext { baselineTemplate: string; modelId: string; modelSlot: string; promptKey: string; } export interface PromptOptimizationRegistryWrite { promptKey: string; schemaFingerprint: string; templateHash: string; promptTemplate: string; schema: SchemaRow[]; } /** Disk- or service-backed I/O invoked from DPE when `getPromptOptimizationHooks()` is non-null. */ export interface PromptOptimizationRuntimeHooks { mergePromptTemplate(runtime: IAgentRuntime, ctx: MergePromptTemplateContext): Promise<{ template: string; variant: string; artifactVersion?: number; }>; persistRegistryEntry(runtime: IAgentRuntime, entry: PromptOptimizationRegistryWrite): Promise; appendBaselineTrace(runtime: IAgentRuntime, ctx: { trace: ExecutionTrace; }): Promise; appendFailureTrace(runtime: IAgentRuntime, ctx: { trace: ExecutionTrace; }): Promise; } /** Aggregates trace signals using explicit or default weights; NaN values are ignored. */ export declare class ScoreCard { private _signals; private _weightOverrides?; constructor(weightOverrides?: Record); add(signal: ScoreSignal): void; addAll(signals: ScoreSignal[]): void; get signals(): readonly ScoreSignal[]; bySource(source: string): ScoreSignal[]; byKind(kind: string): ScoreSignal[]; composite(weightOverrides?: Record): number; toJSON(): ScoreCardData; static fromJSON(data: ScoreCardData, weightOverrides?: Record): ScoreCard; } /** JSON trace records remain independent of persistence and ORM implementations. */ export type SlotKey = string; export type PromptKey = string; export interface ScoreSignal { source: string; kind: string; value: number; weight?: number; reason?: string; metadata?: Record; /** If set, `enrichTrace` applies only to the trace with this `ExecutionTrace.id`. */ traceId?: string; } export interface ScoreCardData { signals: ScoreSignal[]; compositeScore: number; } export interface ExecutionTrace { id: string; traceVersion: number; type: "trace"; promptKey: PromptKey; modelSlot: SlotKey; modelId: string; runId?: UUID; roomId?: string; messageId?: string; templateHash: string; schemaFingerprint: string; artifactVersion?: number; variant: "baseline" | "optimized" | string; parseSuccess: boolean; schemaValid: boolean; validationCodesMatched: boolean; retriesUsed: number; tokenEstimate: number; latencyMs: number; response?: Record; scoreCard: ScoreCardData; createdAt: number; enrichedAt?: number; seq?: number; } export declare const DEFAULT_SIGNAL_WEIGHTS: Record;