mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-05-28 23:15:33 +08:00
Model selection was acting like a provider-level preference. That made resumed sessions drift back to a default or request-time model. Users expect /models changes made inside a conversation to affect that session. Store explicit session choices in app-owned ~/.cloudcli state. This avoids editing provider transcripts or native provider config. Resolve the effective model before launching each provider runtime. Claude, Cursor, Codex, Gemini, and OpenCode now honor stored resume choices. Expose a backend active-model change endpoint for existing sessions. The models modal can now distinguish default changes from session overrides. It also shows when a selected model will apply on the next response. For Claude, stop probing active model state by resuming with a dummy prompt. Read the indexed JSONL transcript from the end instead. This preserves provider history while honoring /model stdout or model fields. Add service tests for adapter delegation and resume-model precedence. The tests keep cache state, override state, and requested fallback separate.
157 lines
5.5 KiB
TypeScript
157 lines
5.5 KiB
TypeScript
import type {
|
|
FetchHistoryOptions,
|
|
FetchHistoryResult,
|
|
LLMProvider,
|
|
McpScope,
|
|
NormalizedMessage,
|
|
ProviderSkill,
|
|
ProviderSkillListOptions,
|
|
ProviderAuthStatus,
|
|
ProviderChangeActiveModelInput,
|
|
ProviderCurrentActiveModel,
|
|
ProviderModelsDefinition,
|
|
ProviderMcpServer,
|
|
ProviderSessionActiveModelChange,
|
|
UpsertProviderMcpServerInput,
|
|
} from '@/shared/types.js';
|
|
|
|
//----------------- PROVIDER CONTRACT INTERFACES ------------
|
|
/**
|
|
* Main provider contract for CLI and SDK integrations.
|
|
*
|
|
* Each concrete provider owns its MCP/auth handlers plus the provider-specific
|
|
* logic for converting native events/history into the app's normalized shape.
|
|
*/
|
|
export interface IProvider {
|
|
readonly id: LLMProvider;
|
|
readonly models: IProviderModels;
|
|
readonly mcp: IProviderMcp;
|
|
readonly auth: IProviderAuth;
|
|
readonly skills: IProviderSkills;
|
|
readonly sessions: IProviderSessions;
|
|
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>;
|
|
|
|
/**
|
|
* Returns the currently active model for one session or provider runtime.
|
|
*
|
|
* Implementations must use the provider-specific lookup mechanism approved
|
|
* for that provider and fall back only to the provider catalog default when
|
|
* no active model can be resolved.
|
|
*/
|
|
getCurrentActiveModel(sessionId?: string): Promise<ProviderCurrentActiveModel>;
|
|
|
|
/**
|
|
* Persists a session-scoped model override that the next resumed turn should
|
|
* honor for this provider.
|
|
*
|
|
* This does not require the provider to mutate an already running remote
|
|
* session in-place. Instead, adapters store the user's explicit model choice
|
|
* so the backend resume path can add the correct provider-native model option
|
|
* on the next CLI/SDK invocation for the same session.
|
|
*/
|
|
changeActiveModel(
|
|
input: ProviderChangeActiveModelInput,
|
|
): Promise<ProviderSessionActiveModelChange>;
|
|
}
|
|
|
|
// ---------------------------
|
|
//----------------- PROVIDER AUTH INTERFACE ------------
|
|
/**
|
|
* Auth contract for one provider.
|
|
*
|
|
* Implementations should return a complete installation/authentication status
|
|
* without throwing for normal "not installed" or "not authenticated" states.
|
|
*/
|
|
export interface IProviderAuth {
|
|
/**
|
|
* Checks whether the provider is installed and has usable credentials.
|
|
*/
|
|
getStatus(): Promise<ProviderAuthStatus>;
|
|
}
|
|
|
|
// ---------------------------
|
|
//----------------- PROVIDER SKILLS INTERFACE ------------
|
|
/**
|
|
* Skills contract for one provider.
|
|
*
|
|
* Implementations discover provider-native skill markdown locations and return
|
|
* normalized skill records with the exact command syntax expected by that
|
|
* provider. Each skill is read from a `SKILL.md` file under its skill directory.
|
|
*/
|
|
export interface IProviderSkills {
|
|
/**
|
|
* Lists all skills visible to this provider for the optional workspace.
|
|
*/
|
|
listSkills(options?: ProviderSkillListOptions): Promise<ProviderSkill[]>;
|
|
}
|
|
|
|
// ---------------------------
|
|
//----------------- PROVIDER MCP INTERFACE ------------
|
|
/**
|
|
* MCP contract for one provider.
|
|
*
|
|
* Implementations must map provider-native MCP config formats to shared
|
|
* `ProviderMcpServer` records used by routes and frontend state.
|
|
*/
|
|
export interface IProviderMcp {
|
|
listServers(options?: { workspacePath?: string }): Promise<Record<McpScope, ProviderMcpServer[]>>;
|
|
listServersForScope(scope: McpScope, options?: { workspacePath?: string }): Promise<ProviderMcpServer[]>;
|
|
upsertServer(input: UpsertProviderMcpServerInput): Promise<ProviderMcpServer>;
|
|
removeServer(
|
|
input: { name: string; scope?: McpScope; workspacePath?: string },
|
|
): Promise<{ removed: boolean; provider: LLMProvider; name: string; scope: McpScope }>;
|
|
}
|
|
|
|
// ---------------------------
|
|
//----------------- PROVIDER SESSION INTERFACE ------------
|
|
/**
|
|
* Session/history contract for one provider.
|
|
*
|
|
* Implementations normalize provider-specific events and message history into
|
|
* shared transport shapes consumed by API routes and realtime streams.
|
|
*/
|
|
export interface IProviderSessions {
|
|
normalizeMessage(raw: unknown, sessionId: string | null): NormalizedMessage[];
|
|
fetchHistory(sessionId: string, options?: FetchHistoryOptions): Promise<FetchHistoryResult>;
|
|
}
|
|
|
|
// ---------------------------
|
|
//----------------- PROVIDER SESSION SYNCHRONIZER INTERFACE ------------
|
|
/**
|
|
* Session indexing contract for one provider.
|
|
*
|
|
* Implementations scan provider-specific session artifacts on disk and upsert
|
|
* normalized session metadata into the database. The service layer uses this
|
|
* interface for both full rescans and single-file incremental sync triggered
|
|
* by filesystem watcher events.
|
|
*/
|
|
export interface IProviderSessionSynchronizer {
|
|
/**
|
|
* Scans provider session artifacts and upserts discovered sessions into DB.
|
|
*/
|
|
synchronize(since?: Date): Promise<number>;
|
|
|
|
/**
|
|
* Parses and upserts one provider artifact file without running a full scan.
|
|
*/
|
|
synchronizeFile(filePath: string): Promise<string | null>;
|
|
}
|