#!/usr/bin/env bun import { type Env } from "../lib/runtime-config.js"; import { type CircuitBreakerThreshold } from "../lib/advancement.js"; import type { LoopStorageContract } from "../lib/storage/contract.js"; import { type RoutePolicy } from "../lib/auth/route-policy.js"; import type { TenantAuthContext, TenantAuthDecision } from "../lib/auth/tenant-auth.js"; /** The serve OpenAPI document (source of the generated SDK), version-synced. */ export declare function openApiDocument(): Record; export declare function apiStatus(env?: Env): { ok: boolean; service: string; status: import("../index.js").StorageConnectionReport; }; export interface ApiAuthenticator { authenticate(headers: Headers, context: { method: string; path: string; policy: RoutePolicy; }): Promise; } export interface LoopsApiServerOptions { host?: string; port?: number; storage?: LoopStorageContract; bodyLimitBytes?: number; evidenceLimitBytes?: number; importLimitBytes?: number; now?: () => Date; random?: () => number; circuitBreakerThreshold?: CircuitBreakerThreshold; /** * API-key verifier (from `@hasna/contracts/auth`). When present, every * request outside the open foundation probes (`/health`, `/ready`, * `/version`, `/openapi.json`) must present a valid `loops:*` scoped key. This is * the internet-facing auth path (no bearer token, no loopback bypass). */ authenticator?: ApiAuthenticator; withTenantStorage?: (principal: TenantAuthContext, fn: (storage: LoopStorageContract) => Promise) => Promise; /** * Readiness probe. Should prove the storage backend is reachable AND fully * migrated. Returns a stable public code only. Defaults to a storage list probe. */ readyCheck?: () => Promise<{ ready: boolean; code?: "storage_unconfigured" | "storage_unreachable" | "auth_unreachable" | "unsafe_database_role" | "pending_migrations" | "unknown_migrations" | "migration_checksum_mismatch"; }>; } /** * Strict health payload for the @hasna/contracts 0.10.6 `HealthResponseSchema` * ({ status, version, backend } — extra keys are rejected). This is the * conformance sample, not the wire envelope: the runtime /health probe serves * the richer foundationEnvelope ({ status, version, storage, connection }). * `backend` maps 1:1 from the runtime storage backend (sqlite | postgresql). */ export declare function contractHealthResponse(env?: Env): { status: "ok"; version: string; backend: "sqlite" | "postgresql"; }; export declare function createLoopsApiServer(opts?: LoopsApiServerOptions): Bun.Server; export declare function logApiCommandFailure(error: unknown): void; export declare function main(argv?: string[]): Promise;