import type { PreparedRouteAttempt, RouteAttemptUsage, RouteFailureClassification, RoutePlan, RoutePlanInput, RoutePlanner, VerifiedRoutingSubject } from '@sentropic/llm-mesh'; import type { GatewayConfig } from './config.js'; import { type CanonicalIngressResult } from './canonical-ingress.js'; import { type NativeFeatureSelection } from './native-features.js'; import type { GatewayFlowRequest, ResolvedTarget, SettleUsage } from './flow.js'; import type { CostContext } from './ports/cost-context.js'; import { GatewayError } from './router/errors.js'; import type { RouteAttemptDispatchPort } from './ports/dispatch.js'; import type { GatewayBudgetOptions, RouteBudgetOverrun } from './ports/budget.js'; import { type AdmittedRoute } from './admission.js'; import type { StageRewritePort, StageRewriteTrace } from './rewrite/stage-rewrite.js'; import type { GuardPort, GuardVerdict, MaskedCapturePayload } from './ports/guards.js'; import type { GuardedTurnCaptureRecord } from './guards/sse-guard-tee.js'; import type { ReceiptIntegrity } from './ports/gateway-state.js'; import { type CanonicalProtectedSnapshot, type ProtectedIdentificationSnapshot } from './guards/protected-identification.js'; export interface RequestAuditRefuseDetail { readonly integrity?: ReceiptIntegrity; readonly reason?: string; } export interface RouteAttemptSettlement { readonly reportedUsage?: boolean; readonly observedServedModel?: string; readonly candidateRef: string; readonly providerId: string; readonly modelId: string; readonly transportProviderId: string; readonly outcome: RouteFailureClassification['reason']; readonly usage: SettleUsage; } export interface RouteRequestSettlement { readonly cost: CostContext; readonly wire: GatewayFlowRequest['wire']; readonly requestedModel: string; readonly outcome: 'success' | 'failed' | 'cancelled'; readonly usage: SettleUsage; readonly attempts: readonly RouteAttemptSettlement[]; /** Budget admission only: server request id, the settlement idempotency key. */ readonly requestId?: string; /** Budget admission only: hold settled (debited and released) by this aggregate. */ readonly holdRef?: string; /** Budget admission only: the in-process quote the hold was priced from. */ readonly quoteRef?: string; /** Budget admission only: dispatched attempts whose usage exceeded their allowance. */ readonly overrun?: readonly RouteBudgetOverrun[]; } export interface RouteMeteringSink { settleRoute(context: RouteRequestSettlement): Promise | void; } export interface RouteFlowDeps { readonly requestAudit?: { admit(input: { cost: CostContext; requestId: string; model: string; originModel?: string; stageRewrites?: readonly StageRewriteTrace[]; guardVerdict?: GuardVerdict; }): Promise<{ receiptId: string; }>; refuse?(receiptId: string, detail?: RequestAuditRefuseDetail): Promise; beginAttempt?(input: { cost: CostContext; attemptRef: string; diagnostic: RoutePlan['diagnostics'][number]; }): Promise; }; readonly dispatch?: RouteAttemptDispatchPort; readonly config: GatewayConfig; readonly routePlanner: RoutePlanner; readonly metering: RouteMeteringSink; readonly routeInput?: (input: { readonly cost: CostContext; readonly request: GatewayFlowRequest; readonly canonical: CanonicalIngressResult; }) => Omit; /** Opt-in budget admission; absent means no quote and no reservation. */ readonly budget?: GatewayBudgetOptions; /** Trusted construction-time switch; absent hosts rely on capability gates. */ readonly nativeMessagesEnabled?: boolean; /** Optional catalog-validated single-step stage rewrite port (D4 B, L1.2). */ readonly stageRewrite?: StageRewritePort; /** Optional decoded-JSON PII + technical-secret guard (D6a/D6d, L1.3b). */ readonly guard?: GuardPort; /** Body capture persistence flag — strictly OFF (`false`) by default. */ readonly captureEnabled?: boolean; /** Masked turn capture sink — invoked only when `captureEnabled === true`. */ readonly onCapture?: (record: GuardedTurnCaptureRecord) => Promise | void; } export interface PreparedRouteFlow { readonly cost: CostContext; readonly subject: VerifiedRoutingSubject; canonical: CanonicalIngressResult; readonly plan: RoutePlan; readonly nativeFeatures: NativeFeatureSelection; /** Present only when budget admission admitted the request. */ readonly admission?: AdmittedRoute; readonly originModel?: string; readonly stageRewrites?: readonly StageRewriteTrace[]; readonly guardVerdict?: GuardVerdict; readonly requestCapture?: MaskedCapturePayload; readonly effectiveBody?: unknown; readonly protectedIngress: ProtectedIdentificationSnapshot; readonly canonicalProtectedIngress: CanonicalProtectedSnapshot; } export declare class RequestAuditError extends Error { } export declare const markDurableAttempt: (deps: RouteFlowDeps, cost: CostContext, attemptRef: string, diagnostic: RoutePlan['diagnostics'][number]) => Promise; /** Retry projection is detached only when upload/commit or terminal SDK cleanup permits it. */ export declare const retainRouteBody: (prepared: PreparedRouteFlow, request: GatewayFlowRequest) => void; export declare const routingSubjectForCost: (cost: CostContext) => VerifiedRoutingSubject; export declare const prepareRouteFlow: (deps: RouteFlowDeps, request: GatewayFlowRequest) => Promise; /** * The single aggregate settlement of a routed request. With budget admission * it releases the hold first when nothing was dispatched, charges missing * usage of dispatched attempts at their allowance and records overruns. */ export declare const settleRouteRequest: (deps: RouteFlowDeps, prepared: Pick, request: GatewayFlowRequest, outcome: RouteRequestSettlement['outcome'], attempts: readonly RouteAttemptSettlement[]) => Promise; /** * The dispatch marker failed: the provider was never called. Release the * prepared attempt without health penalty, settle once, sanitized 503. */ export declare const refuseUnmarkedDispatch: (attempt: PreparedRouteAttempt | undefined, settle: () => Promise) => Promise; /** * Required native capability unavailable: release attempt without health penalty, * settle once with failed outcome, return native-required refusal. */ export declare const refuseNativeAttempt: (attempt: PreparedRouteAttempt | undefined, settle: () => Promise) => Promise; /** * Egress Protected Identification invariant violation (L1.5, r8-F1): release attempt * without health penalty, record durable refusal audit receipt, settle failed * (releasing budget hold because dispatched.size === 0), and rethrow the 400 error. */ export declare const refuseProtectedIdentification: (deps: RouteFlowDeps, attempt: PreparedRouteAttempt | undefined, request: GatewayFlowRequest, error: GatewayError, settle: () => Promise) => Promise; export declare const classifyRouteError: (error: unknown, aborted?: boolean) => RouteFailureClassification; /** * Map a terminal (no more candidates) route classification to the public * GatewayError. A terminal upstream invalid refusal is the caller's request, * not pool exhaustion: it surfaces as bad-request (400). A terminal upstream * unsupported-model becomes the Lot 1 unknown-model 404 with the fixed * internal detail; the served target is preserved so the router keeps the * `X-Sentropic-Served` actual-model header. Terminal upstream auth/quota * refusals keep their class (401/429 + Retry-After) instead of collapsing * into pooled-account-unavailable (503). Only genuine unavailability falls * back to the pooled 503. */ export declare const terminalGatewayError: (classification: RouteFailureClassification, target: ResolvedTarget, fallbackMessage: string, originalError?: unknown) => GatewayError; export declare const routeUsage: (usage?: { readonly inputTokens?: number; readonly outputTokens?: number; }) => SettleUsage; export declare const attemptUsage: (usage: SettleUsage) => RouteAttemptUsage; export declare const aggregateUsage: (attempts: readonly RouteAttemptSettlement[]) => SettleUsage; //# sourceMappingURL=route-flow-core.d.ts.map