Files
gemini-cli/packages/core/src/routing/strategies/fallbackStrategy.ts
T
Sehoon Shon 2ef6149684 feat(core,ui): support Gemini 3.1 Pro Preview and active model filtering (#125)
* feat(core,ui): support Gemini 3.1 Pro Preview and active model filtering

* fix(core,ui): use optional chaining for config methods to support mocks

* fix(core): clear stale authType in refreshAuth to avoid incorrect model resolution

* do not show gemini 3.1 model when users do not have access to gemini 3.1 in stats
2026-02-19 11:38:15 -05:00

56 lines
1.5 KiB
TypeScript

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { selectModelForAvailability } from '../../availability/policyHelpers.js';
import type { Config } from '../../config/config.js';
import { resolveModel } from '../../config/models.js';
import type { BaseLlmClient } from '../../core/baseLlmClient.js';
import type {
RoutingContext,
RoutingDecision,
RoutingStrategy,
} from '../routingStrategy.js';
export class FallbackStrategy implements RoutingStrategy {
readonly name = 'fallback';
async route(
context: RoutingContext,
config: Config,
_baseLlmClient: BaseLlmClient,
): Promise<RoutingDecision | null> {
const requestedModel = context.requestedModel ?? config.getModel();
const resolvedModel = resolveModel(
requestedModel,
config.getGemini31LaunchedSync?.() ?? false,
);
const service = config.getModelAvailabilityService();
const snapshot = service.snapshot(resolvedModel);
if (snapshot.available) {
return null;
}
const selection = selectModelForAvailability(config, requestedModel);
if (
selection?.selectedModel &&
selection.selectedModel !== requestedModel
) {
return {
model: selection.selectedModel,
metadata: {
source: this.name,
latencyMs: 0,
reasoning: `Model ${requestedModel} is unavailable (${snapshot.reason}). Using fallback: ${selection.selectedModel}`,
},
};
}
return null;
}
}