import type { ChatMessage, ProviderId, ReasoningArtifactReplayDecision, ReasoningArtifactReplayTarget, ReasoningPreference, RequestFingerprintSerializerId, ToolChoice, ToolDefinition } from "../types.js"; import { type CachePolicySpec, type ContextLimitSpec, type ProfileReplayScope, type ProfileTriState, type OutputBudgetPolicy, type ReasoningCapability, type ReasoningControlDialect, type ReasoningGeneration, type SamplingPolicySpec } from "./provider-profile.js"; import type { StreamTerminalPolicy } from "./stream-terminal.js"; /** * Canonical request plan (doc 03 §"Canonical request plan", doc 06 §3). * * One immutable, renderer-neutral object describes what a logical generation * will send: route, timeline with stable/mutable boundaries, tools, replay * decisions for every artifact, controls, images, route policy, budget, and a * privacy-safe cache-prefix fingerprint. Provider serializers emit their wire * bodies from a compiled plan; nothing dispatches from ad hoc message arrays * past this boundary. */ export declare const REQUEST_PLAN_VERSION: 1; export declare const REQUEST_PLAN_COMPILER_VERSION: 1; export type RequestPlanSectionKind = "instructions" | "history" | "live"; export interface RequestPlanBoundary { readonly kind: RequestPlanSectionKind; /** Inclusive index into `timeline.messages`. */ readonly messageStart: number; /** Exclusive index into `timeline.messages`. */ readonly messageEnd: number; readonly messageCount: number; } export type RequestPlanControlSuppression = "observed-rejection" | "capability-denied"; export interface RequestPlanControls { readonly reasoning?: ReasoningPreference | undefined; readonly controlSuppression?: RequestPlanControlSuppression | undefined; readonly temperature?: number | undefined; readonly topP?: number | undefined; readonly requestedMaxTokens?: number | undefined; readonly stream: boolean; } export interface RequestPlanRoute { readonly provider: ProviderId; readonly model: string; readonly serializer: RequestFingerprintSerializerId; readonly serializerVersion: 1; readonly compilerVersion: 1; readonly endpointHash?: string | undefined; } export interface RequestPlanArtifactDecision { readonly messageIndex: number; readonly decision: ReasoningArtifactReplayDecision; } export type RequestPlanCacheSectionName = "instructions" | "tools" | "history" | "artifacts" | "settings"; export interface RequestPlanCacheSection { readonly ordinal: number; readonly section: RequestPlanCacheSectionName; readonly sha256: string; readonly byteLength: number; readonly estimatedTokens: number; readonly itemCount: number; } export interface RequestPlanCacheFingerprint { readonly prefixMessageCount: number; readonly replayedArtifactCount: number; readonly sections: readonly RequestPlanCacheSection[]; readonly prefixSha256: string; } export interface RequestPlanRoutePolicy { readonly reasoningGeneration: ReasoningGeneration; readonly controlDialect: ReasoningControlDialect; readonly controlStatus: ProfileTriState; readonly replayScope: ProfileReplayScope; readonly cache: CachePolicySpec; readonly limits: ContextLimitSpec; readonly reasoning: ReasoningCapability; readonly sampling: SamplingPolicySpec; readonly outputBudget: OutputBudgetPolicy; readonly terminal: StreamTerminalPolicy; readonly acceptedParameters?: readonly string[] | undefined; } export interface RequestPlanV1 { readonly version: 1; readonly route: RequestPlanRoute; readonly timeline: { readonly messages: readonly ChatMessage[]; readonly sections: readonly RequestPlanBoundary[]; /** Every message excluded from the cacheable prefix, in timeline order. */ readonly mutableMessageIndexes: readonly number[]; }; readonly tools: { readonly definitions: readonly ToolDefinition[]; readonly choice?: ToolChoice | undefined; readonly parallelToolCalls?: boolean | undefined; }; readonly replay: { readonly target: ReasoningArtifactReplayTarget; readonly decisions: readonly RequestPlanArtifactDecision[]; }; readonly controls: RequestPlanControls; readonly images: { readonly visionAccepted: boolean; readonly imageMessageIndexes: readonly number[]; readonly imageCount: number; }; readonly policy: RequestPlanRoutePolicy; readonly budget: { readonly plannedAdmissions: 1; }; readonly cache: { readonly policy: CachePolicySpec; readonly fingerprint: RequestPlanCacheFingerprint; }; } export interface CompileRequestPlanInput { readonly provider: ProviderId; readonly model: string; readonly messages: readonly ChatMessage[]; readonly stream: boolean; /** Raw endpoint string; only its normalized hash is retained. */ readonly endpoint?: string | undefined; readonly reasoning?: ReasoningPreference | undefined; readonly tools?: readonly ToolDefinition[] | undefined; readonly toolChoice?: ToolChoice | undefined; readonly parallelToolCalls?: boolean | undefined; readonly temperature?: number | undefined; readonly maxTokens?: number | undefined; } export declare function compileRequestPlan(input: CompileRequestPlanInput): RequestPlanV1;