/** * Which models each provider shows in the model picker. * * A selection is stored at the same scope as the provider's key: a personal * key's models are the member's own, an organization key's models belong to * the organization and only owners and admins change them. No stored row means * the provider's recommended models (`model-config.ts`). * * A selection only narrows what the picker and the default-model select offer. * A chat already pinned to an unchecked model keeps running on it. */ import { type AgentProviderId } from "../client/agent-provider-catalog.js"; export declare const PROVIDER_MODEL_SELECTION_KEY_PREFIX = "agent-provider-models"; /** Audit target type for selection changes and refused attempts. */ export declare const PROVIDER_MODEL_SELECTION_AUDIT_TARGET_TYPE = "provider-models"; export type ProviderModelSelectionProvider = AgentProviderId | "builder"; export type ProviderModelSelectionScope = "user" | "org"; export declare const PROVIDER_MODEL_SELECTION_PROVIDERS: readonly ProviderModelSelectionProvider[]; export declare const MAX_SELECTED_MODELS = 500; export interface ProviderModelSelectionContext { userEmail?: string | null; orgId?: string | null; } /** One scope's stored row. `models: null` means nothing is stored there. */ export interface ProviderModelSelectionRow { provider: ProviderModelSelectionProvider; scope: ProviderModelSelectionScope; models: string[] | null; preserveCustomModels?: boolean; updatedAt?: number; updatedBy?: string; } /** * The selection that applies to the current request. `default` shows the * recommended models; `unreadable` is a store failure, never an empty choice. */ export type EffectiveProviderModelSelection = { state: "default"; provider: ProviderModelSelectionProvider; scope: ProviderModelSelectionScope; preserveCustomModels?: boolean; } | { state: "selected"; provider: ProviderModelSelectionProvider; scope: ProviderModelSelectionScope; models: string[]; preserveCustomModels?: boolean; } | { state: "unreadable"; provider: ProviderModelSelectionProvider; error: string; }; /** A request the selection store refuses before touching anything. */ export declare class ProviderModelSelectionError extends Error { readonly statusCode: 400 | 401 | 403; constructor(message: string, statusCode: 400 | 401 | 403); } export declare function isProviderModelSelectionProvider(value: unknown): value is ProviderModelSelectionProvider; export declare function providerModelSelectionSettingsKey(provider: ProviderModelSelectionProvider): string; /** * The provider whose selection governs an engine. `anthropic` and * `ai-sdk:anthropic` share one key, so they share one selection. Engines with * no provider key (a ChatGPT subscription, a custom engine) have none. */ export declare function providerForEngineName(engineName: string): ProviderModelSelectionProvider | null; /** What an unset selection shows. */ export declare function recommendedProviderModels(provider: ProviderModelSelectionProvider): readonly string[]; /** * Trim, drop empties, and de-duplicate, keeping the caller's order. Builder * only routes its own catalog, so ids outside it are refused rather than * stored as choices the gateway would silently swap for its default. */ export declare function normalizeSelectedModels(provider: ProviderModelSelectionProvider, models: readonly unknown[], options?: { preserveCustomModels?: boolean; }): string[]; /** Read one scope's row. Throws when the store can't be read. */ export declare function readProviderModelSelection(ctx: ProviderModelSelectionContext, provider: ProviderModelSelectionProvider, scope: ProviderModelSelectionScope): Promise; /** * Whether the caller may change `scope`'s selection. Personal selections are * always the caller's own; organization ones need an owner or admin. */ export declare function assertMayWriteProviderModelSelection(ctx: ProviderModelSelectionContext, scope: ProviderModelSelectionScope): Promise; export declare function writeProviderModelSelection(ctx: ProviderModelSelectionContext, provider: ProviderModelSelectionProvider, scope: ProviderModelSelectionScope, models: readonly unknown[]): Promise; /** Forget a scope's selection so it shows the recommended models again. */ export declare function resetProviderModelSelection(ctx: ProviderModelSelectionContext, provider: ProviderModelSelectionProvider, scope: ProviderModelSelectionScope): Promise; /** * The scope whose selection applies to this request: the member's own when * their personal key (or personal Builder.io connection) is the one in effect, * otherwise the organization's. Without an organization everything is * personal. Throws when the credential store can't be read. */ export declare function resolveProviderModelSelectionScope(provider: ProviderModelSelectionProvider, ctx?: ProviderModelSelectionContext): Promise; /** The selection the current request's picker shows for `provider`. */ export declare function resolveEffectiveProviderModelSelection(provider: ProviderModelSelectionProvider, ctx?: ProviderModelSelectionContext): Promise; /** * One scope's selection, for a surface that is fixed to a scope (the * organization's default-model select offers organization models only). */ export declare function resolveProviderModelSelectionAtScope(provider: ProviderModelSelectionProvider, scope: ProviderModelSelectionScope, ctx: ProviderModelSelectionContext): Promise; /** * The models a picker offers for an engine: the selection when one is stored, * the engine's own catalog otherwise (including when the selection couldn't * be read, which `selection.state` reports). */ export declare function applyProviderModelSelection(catalog: readonly string[], selection: EffectiveProviderModelSelection | null): string[]; /** * The model to run when nothing picked one and the engine's default is no * longer checked: the first checked model in the order it was saved, which is * not a ranking of the models. `undefined` keeps the engine default, which is * also what happens when the selection can't be read. */ export declare function resolveUncheckedDefaultModelReplacement(engine: { name: string; defaultModel: string; }): Promise; /** * `selection` with the unchecked-default replacement applied. Only the engine * default yields to the provider's checked models: a model the request or a * stored default names still runs after it is unchecked, so chats already on * it keep working. A replaced model is labelled `provider-selection-fallback`, * never `default`, so logs and traces can tell a checkbox swap from the * engine's own default. */ export declare function applyUncheckedDefaultModelReplacement(engine: { name: string; defaultModel: string; }, selection: { model: string; source: Source; }): Promise<{ model: string; source: Source | "provider-selection-fallback"; }>;