mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-28 14:55:34 +08:00
feat: load models through provider adapters
Provider model selection had outgrown a single hardcoded service. The old service mixed shared caching with provider catalogs and CLI lookup details. That made stale model lists more likely as providers changed on separate schedules. Move model discovery behind each provider so lookup lives next to the integration. The shared service now focuses on provider resolution, caching, persistence, and dedupe. Return cache metadata and add bypassCache because model availability changes outside the app. The UI and /models command can show freshness and let users force a provider refresh. Surface model descriptions while keeping fallback catalogs for unavailable CLIs or SDKs.
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
ProviderSkill,
|
||||
ProviderSkillListOptions,
|
||||
ProviderAuthStatus,
|
||||
ProviderModelsDefinition,
|
||||
ProviderMcpServer,
|
||||
UpsertProviderMcpServerInput,
|
||||
} from '@/shared/types.js';
|
||||
@@ -20,6 +21,7 @@ import type {
|
||||
*/
|
||||
export interface IProvider {
|
||||
readonly id: LLMProvider;
|
||||
readonly models: IProviderModels;
|
||||
readonly mcp: IProviderMcp;
|
||||
readonly auth: IProviderAuth;
|
||||
readonly skills: IProviderSkills;
|
||||
@@ -27,6 +29,24 @@ export interface IProvider {
|
||||
readonly sessionSynchronizer: IProviderSessionSynchronizer;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
//----------------- PROVIDER MODEL INTERFACE ------------
|
||||
/**
|
||||
* Model catalog contract for one provider.
|
||||
*
|
||||
* Implementations are responsible for resolving the provider's currently
|
||||
* supported models and converting them into the shared
|
||||
* `ProviderModelsDefinition` shape used by backend routes and frontend model
|
||||
* pickers. The `DEFAULT` field should be the most appropriate default selection
|
||||
* for that provider at the time the catalog is read.
|
||||
*/
|
||||
export interface IProviderModels {
|
||||
/**
|
||||
* Returns the provider's currently supported model catalog.
|
||||
*/
|
||||
getSupportedModels(): Promise<ProviderModelsDefinition>;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
//----------------- PROVIDER AUTH INTERFACE ------------
|
||||
/**
|
||||
|
||||
@@ -73,6 +73,7 @@ export type LLMProvider = 'claude' | 'codex' | 'gemini' | 'cursor' | 'opencode';
|
||||
export type ProviderModelOption = {
|
||||
value: string;
|
||||
label: string;
|
||||
description?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -83,6 +84,31 @@ export type ProviderModelsDefinition = {
|
||||
DEFAULT: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache metadata returned alongside one provider model catalog.
|
||||
*
|
||||
* `updatedAt` is when the current cached snapshot was last refreshed from the
|
||||
* provider itself. `expiresAt` is the backend cache expiry timestamp, and
|
||||
* `source` tells callers whether the current response came from in-memory cache,
|
||||
* persisted disk cache, or a fresh provider fetch.
|
||||
*/
|
||||
export type ProviderModelsCacheInfo = {
|
||||
updatedAt: string;
|
||||
expiresAt: string;
|
||||
source: 'memory' | 'disk' | 'fresh';
|
||||
};
|
||||
|
||||
/**
|
||||
* Full provider model lookup result returned by the backend service layer.
|
||||
*
|
||||
* Use this shape when a caller needs both the selectable model catalog and the
|
||||
* cache metadata that explains how current the catalog is.
|
||||
*/
|
||||
export type ProviderModelsResult = {
|
||||
models: ProviderModelsDefinition;
|
||||
cache: ProviderModelsCacheInfo;
|
||||
};
|
||||
|
||||
/**
|
||||
* Message/event variants emitted by provider adapters and normalized transports.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user