/** * Gateway Hono router — the FROZEN v1 wire surface (spec §3, D7, §16.2): * POST /v1/messages (Anthropic Messages compat) * POST /v1/chat/completions (OpenAI Chat Completions compat) * POST /responses (OpenAI Responses compat, no redirect) * POST /v1/responses (OpenAI Responses compat, same handler) * GET /v1/models (filtered by caller/pool policy) * GET /muse-code/models (Muse CLI catalog; same filtered list) * GET /healthz (liveness — real) * GET /readyz (readiness — real; DB + secret-store + pool) * * v0 PERSONAL-PASSTHROUGH: the provider-compat routes run the REAL flow * (spec §2) via `runJsonFlow` / `runStreamFlow` over `GatewayFlowDeps`. The * dispatch is a faithful provider-compat passthrough (native JSON + SSE frames, * spec §3b). Failures map to provider-SHAPED errors (spec §3b) — the gateway * NEVER exposes pooled account ids/tokens/pool errors. When no flow deps are * supplied the routes fall back to a provider-shaped 501 (used by the scaffold * unit test; the contract surface stays mounted + frozen either way). */ import { Hono } from 'hono'; import { type RoutePlanner } from '@sentropic/llm-mesh'; import type { GatewayConfig } from '../config.js'; import type { GatewayFlowDeps, MeteringSink, TargetResolver } from '../flow.js'; import { type RouteFlowDeps, type RouteMeteringSink } from '../route-flow-core.js'; import type { RouteAttemptDispatchPort } from '../ports/dispatch.js'; import { type ResponsesLimits } from '../responses-egress.js'; import { type RequestBodyLimitOptions } from '../request-body-limit.js'; import type { GatewayBudgetOptions } from '../ports/budget.js'; import { type NativeCountTokensPort } from '../native-count-tokens.js'; import type { NativeCountTokensRateLimiter } from '../native-count-rate.js'; import type { StageRewritePort } from '../rewrite/stage-rewrite.js'; import type { GuardPort } from '../ports/guards.js'; import type { GuardedTurnCaptureRecord } from '../guards/sse-guard-tee.js'; export interface ReadinessProbe { /** True when DB + secret-store + pool are all ready (spec §8 fail-closed). */ isReady(): Promise; } export interface CreateGatewayRouterOptions { readonly routeDispatch?: RouteAttemptDispatchPort; /** Trusted ingress reconstruction, including external scheme and rewritten path. */ readonly publicUrl?: (req: Request) => string; readonly config: GatewayConfig; /** Optional readiness probe; defaults to always-ready in the v0 scaffold. */ readonly readiness?: ReadinessProbe; /** * Provider/model resolver (spec §2). When omitted the provider-compat routes * return a provider-shaped 501 (scaffold mode). When present the real flow runs. */ readonly resolveTarget?: TargetResolver; /** Metering settle hook (spec §5). Required to run the real flow. */ readonly metering?: MeteringSink; /** Usage estimator for never-zero settlement (spec §5). */ readonly estimateUsage?: GatewayFlowDeps['estimateUsage']; /** Mesh-owned opaque route planner. Enables the consumer-neutral data plane. */ readonly routePlanner?: RoutePlanner; /** Single aggregate financial settlement for an opaque route plan. */ readonly routeMetering?: RouteMeteringSink; /** Trusted host/workspace/request policy projection; never reads body ownership. */ readonly routeInput?: RouteFlowDeps['routeInput']; readonly requestAudit?: RouteFlowDeps['requestAudit']; /** `X-Sentropic-Request-Id` source (spec §3b). Defaults to a per-call id. */ readonly requestId?: () => string; /** * Opt-in budget admission (BR-47). Requires `routePlanner` with `quote()` * and `routeMetering`; construction fails otherwise. Absent: no quote call. */ readonly budget?: GatewayBudgetOptions; /** Trusted construction-time switch; absent hosts rely on capability gates. */ readonly nativeMessagesEnabled?: boolean; /** * Host-owned provider count transport (spec §15.2): when present, * `POST /v1/messages/count_tokens` relays the authenticated caller body and * returns the provider count verbatim (real counting, never an estimate). * Absent: explicit provider-shaped refusal — the client falls back to its * own local counting. Trusted injection, never caller-selected. */ readonly nativeCountTokens?: NativeCountTokensPort; /** Per-principal count engineering limits; omitted routers share the process-wide limiter. */ readonly nativeCountRate?: NativeCountTokensRateLimiter; /** * Responses engineering bounds (spec §16.7). Validated at construction; * each field takes the stricter of the spec default and the host value. * Only the Responses wire enforces them; other wires stay frozen. */ readonly responsesLimits?: Partial; /** * Trusted host body policy (spec §17.4): shared pool, host byte caps and * mount prefix. Absent means the process-wide bounded default; the * resolved Responses maxBodyBytes always bounds the Responses paths. */ readonly requestBody?: RequestBodyLimitOptions; /** Optional stage rewrite port (D4 B, L1.2). */ readonly stageRewrite?: StageRewritePort; /** Optional PII + technical-secret guard engine (D6a/D6d, L1.3b). */ readonly guard?: GuardPort; /** Body capture persistence flag — defaults strictly OFF (`false`). */ readonly captureEnabled?: boolean; /** Masked capture callback — invoked only when `captureEnabled === true`. */ readonly onCapture?: (record: GuardedTurnCaptureRecord) => Promise | void; /** Refusal receipt callback for legacy passthrough flows (L1.5). */ readonly onRefusalReceipt?: GatewayFlowDeps['onRefusalReceipt']; } /** * Build the gateway Hono app. With flow deps the provider-compat routes run the * REAL personal-passthrough flow; without them they return a provider-shaped * 501 (scaffold). The wire stays FROZEN + mountable (spec §6) either way. */ export declare const createGatewayRouter: (options: CreateGatewayRouterOptions) => Hono; //# sourceMappingURL=index.d.ts.map