/**
 * AI Gateway (aigw) manager — handles model discovery, models.json generation,
 * and HTTP proxying for browser-side API access.
 *
 * When the user configures an aigw URL in preferences:
 * 1. Server fetches available models from the gateway's /v1/models endpoint
 * 2. Server writes/merges an "aigw" provider into ~/.bobbit/agent/models.json
 *    so agent subprocesses can use `set_model` with provider="aigw"
 * 3. Browser discovers models via server proxy (the aigw hostname may not
 *    resolve from the browser)
 *
 * When aigw is removed, the "aigw" provider is cleaned from models.json.
 */
import http from "node:http";
import type { PreferencesStore } from "./preferences-store.js";
export interface AigwModelCost {
    input: number;
    output: number;
    cacheRead: number;
    cacheWrite: number;
}
export interface AigwModel {
    id: string;
    name: string;
    api: string;
    reasoning: boolean;
    input: ("text" | "image")[];
    contextWindow: number;
    maxTokens: number;
    cost?: AigwModelCost;
    compat?: Record<string, unknown>;
}
export interface AigwConfig {
    url: string;
    models: AigwModel[];
}
interface ModelMeta {
    contextWindow: number;
    maxTokens: number;
    reasoning: boolean;
    input: ("text" | "image")[];
    compat?: Record<string, unknown>;
}
export declare function inferMeta(modelId: string): ModelMeta;
/**
 * Derive a short display name from a full gateway model ID.
 * e.g. "aws/us.anthropic.claude-sonnet-4-6" → "Claude Sonnet 4.6 (aws)"
 */
export declare function deriveName(modelId: string): string;
/**
 * Write contextWindow overrides to models.json for all Claude models where
 * inferMeta() returns a larger context window than the built-in 200k.
 *
 * This fixes the 200k compaction bug: pi-ai hardcodes contextWindow: 200000
 * for all Claude models, but Sonnet/Opus actually support 1M tokens.
 * The modelOverrides in models.json tell pi-coding-agent to use the correct value.
 *
 * Preserves existing user modelOverrides — only sets contextWindow if the user
 * hasn't already overridden it for that model.
 */
export declare function writeContextWindowOverrides(): void;
export declare function writeAigwModelsJson(aigwUrl: string, models: AigwModel[]): void;
/**
 * Remove the "aigw" provider from models.json.
 */
export declare function removeAigwModelsJson(): void;
/**
 * Apply `PI_OFFLINE=1` to the gateway process env when no internet was
 * detected at startup. Spawned pi-coding-agent subprocesses inherit
 * `process.env` (see `rpc-bridge.ts`) and pi 0.74.0+ honours this var by
 * skipping the GitHub fd/rg download path in `ensureTool()` — returning
 * `undefined` cleanly instead of timing out (~10s) on each first call.
 *
 * Rules:
 *   • If the user has already set `PI_OFFLINE` (any non-empty value), it is
 *     preserved verbatim — never overridden.
 *   • Otherwise, when `hasInternet === false`, set `PI_OFFLINE=1` and log a
 *     single explanatory line.
 *   • When `hasInternet === true`, do NOT set `PI_OFFLINE`. Leave existing
 *     state alone — don't introduce an unset that would change behaviour
 *     for online users who currently rely on pi's download fallback.
 *
 * Exported for unit testing. Idempotent.
 */
export declare function applyPiOfflineEnv(hasInternet: boolean): void;
/**
 * One-shot internet check at gateway startup. Tries HEAD requests to
 * well-known LLM API endpoints. Returns true if any responds.
 * Called once — not repeated after startup.
 */
export declare function checkInternetAvailable(): Promise<boolean>;
/**
 * Run once at gateway startup:
 * - If aigw is already configured, nothing to do.
 * - If not configured but internet is unavailable, try to auto-discover
 *   a gateway at a well-known local URL and configure it.
 *
 * Returns true if aigw is active after this call.
 */
export declare function startupAigwCheck(prefs: PreferencesStore): Promise<boolean>;
/**
 * Proxy an HTTP request: reads the incoming request body, forwards to the
 * target URL, and pipes the response back.
 */
export declare function proxyRequest(targetUrl: string, incomingReq: http.IncomingMessage, outgoingRes: http.ServerResponse): void;
/**
 * Fetch the model list from an aigw endpoint and return structured model info.
 * Hits GET {baseUrl}/v1/models (or {baseUrl}/models if baseUrl already ends with /v1).
 */
export declare function discoverAigwModels(baseUrl: string): Promise<AigwModel[]>;
/**
 * Full configure flow: discover models, persist preference, write models.json.
 * Returns the discovered models.
 */
export declare function configureAigw(baseUrl: string, prefs: PreferencesStore): Promise<AigwModel[]>;
/**
 * Remove aigw configuration.
 */
export declare function removeAigw(prefs: PreferencesStore): void;
/**
 * Get the currently configured aigw URL (if any).
 */
export declare function getAigwUrl(prefs: PreferencesStore): string | undefined;
export {};
//# sourceMappingURL=aigw-manager.d.ts.map