import { Disposable, IDisposable } from "../../../../../../base/common/lifecycle.js"; import { IObservable } from "../../../../../../base/common/observable.js"; import { ILanguageModelChatMetadataAndIdentifier } from "../../../common/languageModels.js"; import { IIntendedModelHolder } from "../../../common/model/chatModel.js"; import { ModelSelectionReason, RestoredModelReason } from "../../../common/modelSelection.js"; import { IsModelSupportedHere } from "./chatInputModelUtils.js"; import { IChatModelSelectionDiagnostics } from "./chatModelSelectionDiagnostics.js"; /** What a surface supplies: its catalog, its idea of usable, and what to do with a decision. */ export interface IChatInputModelSelectionRuntime { readonly getCurrentSessionType: () => string | undefined; readonly getModels: (sessionType: string | undefined) => ILanguageModelChatMetadataAndIdentifier[]; readonly getAllModels: () => ILanguageModelChatMetadataAndIdentifier[]; readonly getConfiguredModelValue: () => string | undefined; readonly isEmpty: () => boolean; /** Whether this surface can run the model at all. Asked, so surfaces are not second-guessed. */ readonly isModelSupportedHere: IsModelSupportedHere; /** The model the surface declares as its default, when the pool declares one. */ readonly getDeclaredDefaultModel: (models: readonly ILanguageModelChatMetadataAndIdentifier[]) => ILanguageModelChatMetadataAndIdentifier | undefined; readonly getBoundConversationKey: () => string | undefined; /** Whoever speaks for the bound conversation's intended model — the conversation, else the composer. */ readonly getIntentHolder: () => IIntendedModelHolder; readonly applyModel: (model: ILanguageModelChatMetadataAndIdentifier) => void; /** Whether this session type's models are still loading, so defaulting would pick over them. */ readonly isAwaitingSessionModels?: (sessionType: string) => boolean; /** Whether a model the pool does not offer is gone for good rather than not yet published. */ readonly isModelAbsenceConclusive?: (modelId: string) => boolean; /** Omitted by a surface that drives reconciliation itself rather than being notified. */ readonly subscribeToModelChanges?: (listener: () => void) => IDisposable; /** Omitted by a surface with no per-model configuration to restore. */ readonly restoreModelConfiguration?: (modelId: string, configuration: Record | undefined) => void; } /** The one implementation of "pick and remember the chat model", shared by both surfaces. */ export declare class ChatInputModelSelectionController extends Disposable { private readonly _runtime; private readonly _diagnostics; private readonly _currentModel; readonly currentModel: IObservable; private readonly _onDidChangeUserSelectedModel; readonly onDidChangeUserSelectedModel: import("../../../../../../base/common/event.js").Event<{ readonly fromModelId: string; readonly toModelId: string; }>; private _selectionReason; /** The model {@link currentModel} is shown in place of, see {@link applyEquivalentSelection}. */ private _equivalentOf; private _pendingProgrammaticSelection; constructor(_runtime: IChatInputModelSelectionRuntime, _diagnostics?: IChatModelSelectionDiagnostics); get selectionReason(): ModelSelectionReason | undefined; /** Drops what spoke for the outgoing conversation, so it is not read as the incoming one's. */ beginConversationSwitch(): void; /** * True while the remembered model is not selectable, i.e. whatever is currently selected is a * stand-in that {@link _restoreRememberedModel} will replace once the catalog offers the real * one. Callers use this to avoid acting on a selection that is about to change. */ isAwaitingRememberedModel(): boolean; hasPendingProgrammaticSelection(): boolean; /** A user action claims the conversation and rolls back if `apply` throws; anything else does not. */ applySelection(model: ILanguageModelChatMetadataAndIdentifier, apply: () => void, isUserAction: boolean, rollbackOnError?: boolean): void; applyProgrammaticSelection(model: ILanguageModelChatMetadataAndIdentifier): void; /** * Shows `model` as the current selection presented differently (the picker shows HydraFusion as * Fusion at High). The selection keeps its reason, so a fallback stays a fallback, and * the conversation's intended model moves only if it was the model being re-presented. */ applyEquivalentSelection(model: ILanguageModelChatMetadataAndIdentifier): void; requestProgrammaticSelection(resolveModel: () => ILanguageModelChatMetadataAndIdentifier | undefined, conversationKey: string | undefined): Promise; initialize(rememberedModelId: string | undefined): void; /** Takes the default and forgets the preference it overrides, which would otherwise come back. */ resetToDefault(sessionType?: string | undefined): void; ensureCurrentModelSupported(): void; selectDefault(sessionType?: string | undefined): void; /** * What `chat.defaultModel` would seed this conversation with, or nothing if it would not. * * @param conversationModelReason How the conversation's own model stands, for a caller deciding * whether to wait for one this controller has not been given yet. Omit to use what it applied. */ configuredDefaultToSeed(conversationModelReason?: RestoredModelReason): ILanguageModelChatMetadataAndIdentifier | undefined; private _configuredModel; applyConfiguredDefault(): boolean; reconcileModelListChange(models: readonly ILanguageModelChatMetadataAndIdentifier[]): void; /** * Reclaims the conversation's intended model whenever the catalog offers it, however late. * Catalogs publish in waves, so anything shown meanwhile is a stand-in. Read from the bound * conversation, so another conversation's choice is unreachable here. */ private _restoreRememberedModel; /** Adopts the model the conversation carries. `restoredAs` says whether it is a choice. */ syncFromConversationState(desiredModel: ILanguageModelChatMetadataAndIdentifier, modelConfiguration: Record | undefined, sessionType: string | undefined, conversationKey: string, isRemoteEdit?: boolean, restoredAs?: RestoredModelReason): void; /** * Whether an arriving carried-over model must leave alone the model the conversation is waiting * for. True while the conversation awaits a model the pool cannot offer, the arrival is not * that model, and one of: * * - the awaited model is one the conversation answered for, so a model merely carried onto it * cannot speak for it — this is what a surface that records where a model came from can say; * - the arrival is the stand-in currently on screen, i.e. this controller put it there and the * conversation is only echoing it back — what a surface whose draft state cannot say where a * model came from has to fall back on. * * Anything else is a real statement about the conversation and supersedes the wait. A remote * edit is a peer answering for the conversation, so it always does. */ private _keepsAwaitedModel; /** Replaces the bound conversation's intended model. */ private _remember; /** The intended model of the conversation this input is currently bound to. */ private get _intendedModel(); /** * The model to fall back to: the declared default, else the first non-BYOK model, else the first * on offer — but never a billable stand-in for a model the conversation is still awaiting. */ private _defaultModel; /** The models selectable for the bound session right now. */ private _pool; /** Records the model to reclaim, with how it stands — forgetting that lets the default claim it. */ private _rememberOnBoundConversation; revalidateForSessionType(initialize: () => void): void; private _applySessionRestore; private _reconcilePendingProgrammaticSelection; private _clearPendingProgrammaticSelection; /** Shows `model`; see {@link _stillShown} for the result. */ private _display; /** Whether `modelId` is the current model, or the one it is shown in place of. */ private _isSelected; /** * False once something selected another model in place of `model` while it was being shown or * applied (the picker normalizes what it is shown). That selection stands, so the caller * finishes nothing on top of it. */ private _stillShown; /** * Shows the model and hands it to the surface. The reason is recorded first because a surface * that persists reads it during `applyModel`. Pass {@link selectionReason} to carry it over. */ private _applyModel; private _reportInitialization; }