/** * model-proxy/loopback-server.ts — in-sandbox loopback proxy. * * Runs inside the cloud sandbox. The Agent SDK is pointed here via * `ANTHROPIC_BASE_URL=http://127.0.0.1:` and authenticates with a * per-session relay token via `ANTHROPIC_AUTH_TOKEN`. This server: * 1. binds to 127.0.0.1 ONLY (never routable off-box), * 2. constant-time validates the relay bearer the SDK presents, * 3. forwards each request through an injected {@link ModelProxyForwarder} * (the Socket.IO tunnel up to the backend → home daemon), * 4. streams the upstream response back to the SDK unchanged. * * The sandbox therefore never holds the real subscription credential and never * needs egress to api.anthropic.com — only to the OverSky control plane. */ /** The sandbox-side transport seam: forwards one exchange up to the home daemon. */ export interface ModelProxyForwarder { forward(req: { method: string; path: string; headers: Record; body: Uint8Array | null; }, opts: { signal: AbortSignal; }): Promise<{ status: number; headers: Record; body: AsyncIterable; }>; } export interface LoopbackServerOptions { /** Per-session relay token the SDK must present as `Authorization: Bearer …`. */ relayToken: string; forwarder: ModelProxyForwarder; /** Loopback host. Defaults to 127.0.0.1; never bind to 0.0.0.0. */ host?: string; /** Fixed port, or 0 (default) for an ephemeral port. */ port?: number; /** Private Unix-domain socket transport. Mutually exclusive with TCP host/port. */ socketPath?: string; /** Optional trusted group that may connect to the per-session Unix socket. */ socketGroupId?: number; /** URL advertised to a client that uses `fetch(..., { unix: socketPath })`. */ advertisedBaseUrl?: string; /** Bounded before buffering so a local child cannot exhaust daemon memory. */ maxBodyBytes?: number; onError?: (err: Error) => void; } export declare class ModelProxyLoopbackServer { private server; /** * `server.close()` only stops accepting new connections. A managed lease * must also stop requests which have already reached this relay: otherwise a * cancelled session can keep an upstream stream alive until the provider * happens to finish. Track both transport sockets and forward abort signals * so `stop()` is an authority revocation, not merely a listener shutdown. */ private readonly activeSockets; private readonly activeRequests; private readonly opts; private boundPort; constructor(opts: LoopbackServerOptions); /** Starts the server and returns the base URL to put in `ANTHROPIC_BASE_URL`. */ start(): Promise<{ baseUrl: string; port: number; }>; stop(): Promise; baseUrl(): string; private handle; private authorize; }