import type { Tool } from "@modelcontextprotocol/sdk/types.js";
import { StitchConfig, StitchToolClientSpec, VirtualToolDefinition } from "./spec/client.js";
import { EntityManager } from "./entity-manager.js";
/** Test-only: re-arm the once-per-process STITCH_HOST deprecation warning. */
export declare function __resetStitchHostWarning(): void;
/**
 * Resolve a config input against the environment (D5 REVISED).
 *
 * Precedence: explicit config > STITCH_* vars > legacy aliases.
 *   - apiKey:      input ?? STITCH_API_KEY
 *   - accessToken: input ?? STITCH_ACCESS_TOKEN
 *   - projectId:   input ?? STITCH_PROJECT_ID ?? GOOGLE_CLOUD_PROJECT
 *                  (GOOGLE_CLOUD_PROJECT is the GCP-wide convention and
 *                  stays first-class — no warning)
 *   - baseUrl:     input ?? STITCH_BASE_URL ?? STITCH_HOST
 *                  (STITCH_HOST is a deprecated alias — warns once per
 *                  process, removed in 2.0)
 *
 * Shared by StitchToolClient and the singleton so both resolve the exact
 * same env set (the singleton derives its cache key from this output).
 */
export declare function resolveConfigWithEnv(input?: Partial<StitchConfig>): Partial<StitchConfig>;
/**
 * Parse a raw MCP CallToolResult envelope into the tool's payload.
 *
 * Shared by StitchToolClient and the proxy's virtual-tool path so both
 * see identical payloads (structuredContent first, then JSON-in-text)
 * and identical error behavior (isError → StitchError).
 */
export declare function parseToolResult<T>(result: any, name: string): T;
/**
 * Exponential backoff with full jitter:
 *   delay = min(maxMs, baseMs * 2^attempt) * random(0..1)
 *
 * `rand` is injectable for deterministic tests.
 */
export declare function computeBackoffMs(attempt: number, baseMs: number, maxMs: number, rand?: () => number): number;
/**
 * Parse a Retry-After header (seconds or HTTP date) to milliseconds.
 */
export declare function parseRetryAfter(header: string | number | null | undefined): number | undefined;
/**
 * Authenticated tool pipe for the Stitch MCP Server.
 *
 * Designed for agents and orchestration scripts that forward JSON payloads
 * to MCP tools. Handles auth injection via the transport layer (not global fetch).
 *
 * Usage:
 *   const client = new StitchToolClient();          // reads STITCH_API_KEY from env
 *   const result = await client.callTool("generate_screen_from_text", { ... });
 */
export declare class StitchToolClient implements StitchToolClientSpec {
    name: "stitch-tool-client";
    description: "Authenticated tool pipe for Stitch MCP Server";
    private client;
    private transport;
    private config;
    private isConnected;
    private isClosed;
    private connectPromise;
    private localVirtualTools;
    entities: EntityManager;
    /** Whether close() has been called on this client. */
    get closed(): boolean;
    constructor(inputConfig?: Partial<StitchConfig> & {
        localVirtualTools?: VirtualToolDefinition[];
    });
    /**
     * A fresh MCP Client is required per transport: calling connect() twice
     * on a single Client instance is undefined behavior in the MCP SDK.
     */
    private createMcpClient;
    /**
     * Guard for the terminal close() state. Once close() has been called,
     * this client is permanently unusable — create a new StitchToolClient.
     */
    private assertNotClosed;
    /**
     * Build auth headers based on config (API key or OAuth).
     */
    private buildAuthHeaders;
    private parseToolResponse;
    connect(): Promise<void>;
    private doConnect;
    /**
     * Generic tool caller with type support and error parsing.
     *
     * RATE_LIMITED failures on idempotent reads (get_* / list_*) are retried
     * with exponential backoff + full jitter, per `config.retry`. MCP text
     * errors carry no Retry-After header, so nothing else is honored.
     */
    callTool<T>(name: string, args: Record<string, any>): Promise<T>;
    /**
     * Call a tool and return the RAW MCP CallToolResult envelope
     * (content / structuredContent / isError) WITHOUT parsing and WITHOUT
     * retry.
     *
     * This is the proxy's forwarding path: the proxy relays envelopes
     * verbatim to its downstream MCP client, which owns error semantics —
     * parsing or retrying here would change downstream-visible behavior.
     * SDK users want callTool() instead.
     */
    callToolRaw(name: string, args: Record<string, any>): Promise<any>;
    /**
     * Make a direct REST POST to the Stitch API.
     *
     * Used for endpoints not available as MCP tools (e.g. BatchCreateScreens).
     * Reuses the same auth headers as callTool — both API key and OAuth Bearer
     * token are supported by all current REST POST endpoints.
     *
     * Throws StitchError on HTTP errors. Common failure modes:
     *   - 401 CREDENTIALS_MISSING → the API key was empty (source .env first)
     *   - 403 PERMISSION_DENIED   → the key doesn't own the target project
     *   Neither means "API keys are unsupported." See upload-handler.ts for full context.
     */
    httpPost<T>(path: string, body: unknown): Promise<T>;
    /**
     * List remote tools and return the RAW result — schemas exactly as the
     * server served them, with NO repair and NO local virtual tools appended.
     *
     * Used where the raw schemas are the source of truth: the capture
     * pipeline (tools-manifest must not be coupled to repair heuristics)
     * and the proxy (repair happens at serving time in its listTools
     * handler). SDK users want listTools() instead.
     *
     * CRITICAL: We use a raw request() instead of this.client.listTools()
     * because Client.listTools() eagerly compiles outputSchema with AJV
     * via cacheToolMetadata(). If the Stitch backend returns schemas with
     * $ref to missing $defs (e.g. #/$defs/ScreenInstance), AJV throws a
     * MissingRefError BEFORE any schema repair code can run.
     */
    listToolsRaw(): Promise<{
        tools: Tool[];
    }>;
    listTools(): Promise<{
        tools: ({
            inputSchema: {
                [x: string]: unknown;
                type: "object";
                properties?: {
                    [x: string]: object;
                } | undefined;
                required?: string[] | undefined;
            };
            name: string;
            description?: string | undefined;
            outputSchema?: {
                [x: string]: unknown;
                type: "object";
                properties?: {
                    [x: string]: object;
                } | undefined;
                required?: string[] | undefined;
            } | undefined;
            annotations?: {
                title?: string | undefined;
                readOnlyHint?: boolean | undefined;
                destructiveHint?: boolean | undefined;
                idempotentHint?: boolean | undefined;
                openWorldHint?: boolean | undefined;
            } | undefined;
            execution?: {
                taskSupport?: "required" | "optional" | "forbidden" | undefined;
            } | undefined;
            _meta?: {
                [x: string]: unknown;
            } | undefined;
            icons?: {
                src: string;
                mimeType?: string | undefined;
                sizes?: string[] | undefined;
                theme?: "light" | "dark" | undefined;
            }[] | undefined;
            title?: string | undefined;
        } | {
            name: string;
            description: string;
            inputSchema: any;
            source: string | undefined;
        })[];
    }>;
    /**
     * Close the connection. TERMINAL: after close(), every subsequent
     * connect/callTool/httpPost/listTools throws CLIENT_CLOSED — create a
     * new StitchToolClient instead. Calling close() again is a no-op.
     */
    close(): Promise<void>;
}
//# sourceMappingURL=client.d.ts.map