modelSelection.ts ×10

Frontier kind: Code frontier

unlabeled · c_c2cfbdea147f

16 tests · 29395 LOC · 143 files · introduces 0 tests · 117 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges117 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2832 ranges29395 lines · 143 files · Browse complete extent
All tests (intent)
16 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 117 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/modelSelection.ts 117 introduced LOC · 10 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- modelSelection.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { ILanguageModelChatMetadataAndIdentifier, ILanguageModelsService, isLanguageModelVendorAbsenceConclusive } from './languageModels.js';
7 > import { isAgentHostTarget } from './chatSessionsService.js';
8 >
9 > export type ModelIdentifierResolution =
10 > | { readonly kind: 'notRequested' }
11 > | { readonly kind: 'pending'; readonly identifier: string }
12 > | { readonly kind: 'available'; readonly model: ILanguageModelChatMetadataAndIdentifier }
13 > | { readonly kind: 'unavailable'; readonly identifier: string };
14 >
15 > export interface IModelVendorResolution {
16 > hasLiveModels(vendor: string): boolean;
17 > hasResolved(vendor: string): boolean;
18 > }
19 >
20 > /** Resolves a requested model identifier against the current model catalog. */
21 > export function resolveModelIdentifier(
22 models: readonly ILanguageModelChatMetadataAndIdentifier[],
23 identifier: string | undefined,
37 : { kind: 'pending', identifier };
38 }
40 > /** Resolves a model identifier using vendor-level catalog readiness. */
41 > export function resolveModelIdentifierFromCatalog(
42 models: readonly ILanguageModelChatMetadataAndIdentifier[],
43 identifier: string | undefined,
65 return resolveModelIdentifier(models, identifier, isAbsenceConclusive);
66 }
68 > export function getRegisteredLanguageModels(languageModelsService: Pick<ILanguageModelsService, 'getLanguageModelIds' | 'lookupLanguageModel'>): ILanguageModelChatMetadataAndIdentifier[] {
69 return languageModelsService.getLanguageModelIds()
70 .map(identifier => {
74 .filter(model => model !== undefined);
75 }
77 > export function resolveModelIdentifierFromLanguageModels(
78 models: readonly ILanguageModelChatMetadataAndIdentifier[],
79 identifier: string | undefined,
87 });
88 }
90 > const AUTO_MODEL_ID = 'auto';
91 >
92 function compareModelVersions(a: string | undefined, b: string | undefined): number {
93 const rawA = a ?? '';
105 return rawA.localeCompare(rawB);
106 }
108 > /** Resolves a configured model id, family, or `auto` value against a model pool. */
109 > export function resolveConfiguredModel(
110 configuredValue: string | undefined,
111 models: readonly ILanguageModelChatMetadataAndIdentifier[],
130 : undefined;
131 }
133 > export const enum ModelSelectionReason {
134 > ConfiguredDefault = 'configuredDefault',
135 > FirstAvailable = 'firstAvailable',
136 > NoModels = 'noModels',
137 > ProgrammaticSelection = 'programmaticSelection',
138 > Remembered = 'remembered',
139 > RemovedModelFallback = 'removedModelFallback',
140 > SessionRestore = 'sessionRestore',
141 > NewChatRepush = 'newChatRepush',
142 > UserSelection = 'userSelection',
143 > }
144 >
145 > export type ModelSelectionApplyReason = Exclude<ModelSelectionReason, ModelSelectionReason.NoModels>;
146 >
147 > export function isAuthoritativeModelSelectionReason(reason: ModelSelectionApplyReason | undefined): boolean {
148 return reason === ModelSelectionReason.ProgrammaticSelection
149 || reason === ModelSelectionReason.SessionRestore
150 || reason === ModelSelectionReason.UserSelection;
151 }
153 > export interface IPendingModelSelection {
154 > readonly reference: string;
155 > }
156 >
157 > export type InitialModelSelectionResult =
158 > | { readonly kind: 'none' }
159 > | { readonly kind: 'pending'; readonly selection: IPendingModelSelection }
160 > | { readonly kind: 'apply'; readonly model: ILanguageModelChatMetadataAndIdentifier; readonly reason: ModelSelectionApplyReason };
161 >
162 > export interface IInitialModelSelectionInput {
163 > readonly configuredModel: ILanguageModelChatMetadataAndIdentifier | undefined;
164 > readonly desiredModelResolution: ModelIdentifierResolution;
165 > readonly desiredReason: ModelSelectionReason.SessionRestore | ModelSelectionReason.Remembered;
166 > readonly fallbackModel: ILanguageModelChatMetadataAndIdentifier | undefined;
167 > readonly fallbackReason: ModelSelectionReason.FirstAvailable | ModelSelectionReason.RemovedModelFallback;
168 > }
169 >
170 > /** Applies the shared configured, desired, pending, then fallback precedence. */
171 > export function resolveInitialModelSelection(input: IInitialModelSelectionInput): InitialModelSelectionResult {
172 if (input.configuredModel) {
173 return { kind: 'apply', model: input.configuredModel, reason: ModelSelectionReason.ConfiguredDefault };
183 : { kind: 'none' };
184 }
186 > export type ModelSelectionEffect =
187 > | { readonly kind: 'none' }
188 > | { readonly kind: 'clear'; readonly reason: ModelSelectionReason.NoModels | ModelSelectionReason.SessionRestore }
189 > | { readonly kind: 'apply'; readonly model: ILanguageModelChatMetadataAndIdentifier; readonly reason: ModelSelectionApplyReason };
190 >
191 > export type IModelSelectionSessionContext =
192 > | { readonly kind: 'none' }
193 > | {
194 > readonly kind: 'untitled' | 'existing';
195 > readonly key: string;
196 > readonly chatKey: string | undefined;
197 > readonly modelId: string | undefined;
198 > };
199 >
200 > export interface IModelSelectionModelsContext {
201 > readonly available: readonly ILanguageModelChatMetadataAndIdentifier[];
202 > readonly configuredModel: string | undefined;
203 > readonly rememberedModelId: string | undefined;
204 > readonly desiredModelResolution: ModelIdentifierResolution;
205 > readonly fallbackModel: ILanguageModelChatMetadataAndIdentifier | undefined;
206 > }
207 >
208 > export interface IModelSelectionMemory {
209 > readonly sessionKey: string | undefined;
210 > readonly lastPushedChatKey: string | undefined;
211 > readonly currentModel: ILanguageModelChatMetadataAndIdentifier | undefined;
212 > readonly currentReason: ModelSelectionApplyReason | undefined;
213 > }
214 >
215 > export interface IModelSelectionTransitionInput {
216 > readonly session: IModelSelectionSessionContext;
217 > readonly models: IModelSelectionModelsContext;
218 > readonly previous: IModelSelectionMemory;
219 > }
220 >
221 > export interface IModelSelectionTransitionResult {
222 > readonly currentModel: ILanguageModelChatMetadataAndIdentifier | undefined;
223 > readonly currentReason: ModelSelectionApplyReason | undefined;
224 > readonly pendingSelection: IPendingModelSelection | undefined;
225 > readonly effect: ModelSelectionEffect;
226 > readonly sessionKey: string | undefined;
227 > readonly lastPushedChatKey: string | undefined;
228 > }
229 >
230 > export function transitionModelSelection(input: IModelSelectionTransitionInput): IModelSelectionTransitionResult {
231 const { session, models, previous } = input;
232 const sessionKey = session.kind === 'none' ? undefined : session.key;
372 return { currentModel, currentReason, pendingSelection: undefined, effect: { kind: 'none' }, sessionKey, lastPushedChatKey: previous.lastPushedChatKey };
373 }
375 function applyResult(
376 sessionKey: string | undefined,