import { type AnyModel, type Api, type AssistantMessageEventStream, type AuthCheck, type AuthContext, type AuthResult, type ClassifierApi, type ImageApi, type Model, type OAuthCredential, type OAuthCredentials, type OAuthLoginCallbacks, type Provider, type ProviderClassifier, type ProviderImages, type RefreshModelsContext, type SimpleStreamOptions, type TranscriptContext } from "@earendil-works/pi-ai";
import type { RetryPolicyProfile } from "@earendil-works/pi-ai/utils/retry-profile/types";
import type { ModelConfig, ModelsJsonProvider } from "./model-config.ts";
import { type StoredProviderEnvReader } from "./provider-api-key-auth.ts";
import type { HeaderAuthStatusSource } from "./provider-header-auth.ts";
import { clearConfigValueCache } from "./resolve-config-value.ts";
export interface ExtensionOAuthConfig {
    name: string;
    /** Whether access through this auth method is backed by a provider subscription. */
    isSubscription?: boolean;
    /** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */
    usesCallbackServer?: boolean;
    check?(input: {
        ctx: AuthContext;
        credential?: OAuthCredential;
    }): Promise<AuthCheck | undefined>;
    /**
     * Request auth for providers whose credentials live outside auth.json —
     * an environment token, or a CLI the provider shells out to. Supplying this
     * gives the provider api-key auth it would otherwise be denied for having
     * `oauth`, so ambient users resolve instead of hitting
     * "Provider is not configured". Never consulted once a credential is stored.
     */
    resolveAmbient?(input: {
        ctx: AuthContext;
        signal?: AbortSignal;
    }): Promise<AuthResult | undefined>;
    login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
    refreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;
    getApiKey(credentials: OAuthCredentials): string;
    modifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];
}
interface ProviderModelConfigBase {
    id: string;
    name: string;
    upstreamModelId?: string;
    api?: string;
    baseUrl?: string;
    input: ("text" | "image" | "video")[];
    inputLimits?: AnyModel["inputLimits"];
    cost: AnyModel["cost"];
    headers?: Record<string, string>;
}
export interface ProviderChatModelConfig extends ProviderModelConfigBase {
    type?: "chat";
    api?: Api;
    serviceTier?: "auto" | "flex" | "priority" | "ultrafast";
    promptPreset?: string;
    recoverTextToolCalls?: boolean;
    reasoning: boolean;
    thinkingLevelMap?: Model<Api>["thinkingLevelMap"];
    promptCache?: Model<Api>["promptCache"];
    contextWindow: number;
    maxTokens: number;
    samplingParams?: Record<string, unknown>;
    extraBody?: Record<string, unknown>;
    cacheRetention?: Model<Api>["cacheRetention"];
    compat?: Model<Api>["compat"];
}
export interface ProviderImageModelConfig extends ProviderModelConfigBase {
    type: "image";
    api?: ImageApi;
    output: ("text" | "image")[];
}
export interface ProviderClassifierModelConfig extends ProviderModelConfigBase {
    type: "classifier";
    api?: ClassifierApi;
    contextWindow: number;
}
export type ProviderModelConfig = ProviderChatModelConfig | ProviderImageModelConfig | ProviderClassifierModelConfig;
/** Input type for the extension registerProvider API. */
export interface ProviderConfigInput {
    name?: string;
    baseUrl?: string;
    apiKey?: string;
    api?: Api;
    streamSimple?: (model: Model<Api>, context: TranscriptContext, options?: SimpleStreamOptions) => AssistantMessageEventStream;
    images?: Partial<Record<ImageApi, ProviderImages>>;
    classifiers?: Partial<Record<ClassifierApi, ProviderClassifier>>;
    headers?: Record<string, string>;
    extraBody?: Record<string, unknown>;
    authHeader?: boolean;
    oauth?: ExtensionOAuthConfig;
    /**
     * Ambient api-key auth resolved from a shared cloud credential chain (Google
     * ADC, AWS env) rather than a credential configured for this provider. The
     * provider counts as configured only while `resolve` yields a result, and the
     * ambient marker keeps it from outranking a provider the user configured when
     * the automatic default model is chosen (senpi#2327). Ignored when `apiKey`,
     * credential headers, or a base provider already supply auth.
     */
    ambientAuth?: ProviderAmbientAuth;
    retryPolicy?: RetryPolicyProfile;
    models?: ProviderModelConfig[];
    refreshModels?(context: RefreshModelsContext): Promise<ProviderModelConfig[]>;
    /**
     * Deterministic usability gate for implicit fallback expansion. Return `false`
     * while this lane is guaranteed to refuse unattended execution (for example an
     * unacknowledged approval gate); the provider stays registered and explicitly
     * selectable, but bare-family fallback expansion skips it. Re-evaluated on
     * every expansion, so a settings change takes effect without re-registration.
     */
    fallbackEligible?(): boolean;
    /**
     * Set by a provider whose own lane chooses among the accounts stored for it (pin, session
     * stickiness, per-account limits) and fails over between them. The generic credential pool then
     * never wraps it: two layers choosing accounts pinned the lane's verdicts on slots the lane never
     * used and blocked all of them (senpi#2081).
     */
    ownsAccountSelection?: boolean;
    /** Capability flag (see `ProviderConfig.localOnly`): served only on the machine holding the binary and login. Metadata only. */
    localOnly?: boolean;
}
/** Ambient api-key auth hook for extension providers (see `ProviderConfigInput.ambientAuth`). */
export interface ProviderAmbientAuth {
    /** Display name, e.g. "Google Cloud credentials". */
    name?: string;
    /**
     * Resolve from the ambient chain. `undefined` means the chain currently
     * supplies no credential, so the provider stays unavailable. A returned
     * result should carry `ambient: true`.
     */
    resolve(input: {
        ctx: AuthContext;
        signal: AbortSignal;
        /** Read-only env of another provider's stored credential; routing metadata only, never keys. */
        storedProviderEnv?(providerId: string): Promise<Record<string, string> | undefined>;
    }): Promise<AuthResult | undefined>;
}
export type AuthStatus = {
    configured: boolean;
    source?: "stored" | "runtime" | "environment" | "fallback" | "models_json_key" | "models_json_command" | HeaderAuthStatusSource;
    label?: string;
    /** Environment auth that came only from a shared cloud credential chain (`AuthCheck.ambient`). */
    ambient?: true;
};
export { configuredRequestAuthStatus, resolveCompatibilityRequestHeaders, resolveConfiguredModelHeaders, } from "./provider-request-auth.ts";
export declare const clearApiKeyCache: typeof clearConfigValueCache;
export declare function validateExtensionProvider(providerId: string, base: Provider | undefined, modelsConfig: ModelsJsonProvider | undefined, extension: ProviderConfigInput): void;
/** Compose built-in, models.json, and extension layers without reading credentials. */
export declare function composeModelProvider(providerId: string, base: Provider | undefined, modelConfig: ModelConfig, extension: ProviderConfigInput | undefined, 
/** Deferred ambient reads; the reader runs during auth resolution, never at composition. */
options?: {
    storedProviderEnv?: StoredProviderEnvReader;
}): Provider;
/**
 * Request shape a compatibility provider needs beside its credential. Headers are NOT
 * part of it: a configured header value can be a `!command`, and resolving one requires
 * a shell - see `resolveCompatibilityRequestHeaders`.
 */
export interface CompatibilityRequestConfig {
    extraBody?: Record<string, unknown>;
    upstreamModelId?: string;
    serviceTier?: "auto" | "flex" | "priority" | "ultrafast";
    authHeader: boolean;
}
export declare function resolveCompatibilityRequestConfig(model: Model<Api>, config: ModelsJsonProvider | undefined, extension: ProviderConfigInput | undefined): CompatibilityRequestConfig;
//# sourceMappingURL=provider-composer.d.ts.map