import { type CredentialProvenance } from "../../credentials/index.js"; import { type BuilderCredentialLookupIdentity } from "../../server/credential-provider.js"; import { type EngineCredentialOwner } from "./credential-owner.js"; import type { AgentEngine, EngineCapabilities } from "./types.js"; export interface AgentEngineEnvCredentialSet { envVars: string[]; /** * Injected by a deploy pipeline rather than configured by the owner. Selects * when nothing else resolves, but never outranks an owner-configured * credential — including the legacy Builder pair, which keeps normal priority. */ deployInjected?: boolean; } export interface AgentEngineEntry { name: string; label: string; description: string; installPackage?: string; capabilities: EngineCapabilities; defaultModel: string; supportedModels: readonly string[]; acceptsCustomModels?: boolean; requiredEnvVars: string[]; alternateRequiredEnvVars?: AgentEngineEnvCredentialSet[]; create(config: Record): AgentEngine; } export declare function registerAgentEngine(entry: AgentEngineEntry): void; export declare function unregisterAgentEngine(name: string): void; export declare function getAgentEngineEntry(name: string): AgentEngineEntry | undefined; export declare function listAgentEngines(): AgentEngineEntry[]; export declare function isAgentEnginePackageInstalled(entry: AgentEngineEntry): boolean; export { normalizeModelForEngine, type NormalizeModelOptions, } from "../model-version.js"; type ModelResolvableEngine = Pick; export declare function resolveDelegatedRunModel(engine: ModelResolvableEngine, options: { explicitModel?: string | null; storedModel?: string | null; callerModelHint?: string | null; }): string; export declare function resolveEnginePreservesCustomModels(entry: Pick): Promise; export declare function resolveEngineAcceptsCustomModels(entry: Pick): Promise; export declare function detectEngineFromEnv(): AgentEngineEntry | null; /** Whether a deployment credential can serve this engine for the current request. */ export declare function isDeploymentEngineUsableForRequest(entry: AgentEngineEntry): Promise; export declare function detectEngineFromEnvForRequest(): Promise; /** * Detect a usable engine from the current request user's accessible * `app_secrets` rows. Mirrors `detectEngineFromEnv` but consults the * encrypted secret store instead of `process.env`, including org-scoped * credentials shared with the active organization. * * Required because the Builder OAuth callback (and the settings UI's * "paste your own key" flow) writes credentials to app_secrets, not env. * Without this check, a user who connected Builder would see status * "configured" but the next chat turn would fall through to the default * Anthropic engine and hit `missing_api_key` — exactly Brent's symptom * on the docs site (Loom 2026-04-28: "It doesn't seem to realize I'm * connected once I do a chat"). * * Includes the local dev session (`local@localhost`): the Builder * OAuth flow writes credentials scoped to that email when run from * `pnpm dev`, so detection has to consult those rows or the dev user * sees the same "Connect your AI" card after they've already connected * (Sami, 2026-04-30). Org-scoped Builder credentials must also count here: * `/builder/status` resolves them via the same request org context, and the * chat engine picker must not disagree with that card. */ export declare function detectEngineFromUserSecrets(identity?: BuilderCredentialLookupIdentity, options?: { isBuilderConnectionUsable?: () => Promise; }): Promise; export declare function isAgentEngineSettingConfigured(stored: unknown): boolean; /** @internal exported for unit tests only */ export declare function credentialOwnerForEntry(entry: AgentEngineEntry, apiKey: string | undefined, provenance: CredentialProvenance | undefined, config: Record): EngineCredentialOwner | undefined; export declare function isStoredEngineUsable(stored: unknown, entry: AgentEngineEntry): boolean; export declare function isStoredEngineUsableForRequest(stored: unknown, entry: AgentEngineEntry, options?: { credentialIdentity?: BuilderCredentialLookupIdentity; }): Promise; export declare function isResolvedEngineUsableForRequest(engine: AgentEngine, options?: { apiKey?: string; credentialIdentity?: BuilderCredentialLookupIdentity; }): Promise; export interface ResolveEngineConfig { engineOption?: string | AgentEngine | { name: string; config: Record; }; apiKey?: string; apiKeyEnvVar?: string; apiKeyProvenance?: CredentialProvenance; model?: string; appId?: string; credentialIdentity?: BuilderCredentialLookupIdentity; } export declare function explicitEngineName(engineOption: ResolveEngineConfig["engineOption"]): string | undefined; export declare function getConfiguredEngineNameForRequest(options?: { appId?: string; }): Promise; export declare function resolveEngine(config: ResolveEngineConfig): Promise; export declare function getStoredModelForEngine(engine: AgentEngine | string, options?: { appId?: string; }): Promise;