feat: support session-scoped model overrides

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.
This commit is contained in:
Haileyesus
2026-05-18 16:57:29 +03:00
parent bc5e768579
commit 9aa927002e
19 changed files with 872 additions and 191 deletions

View File

@@ -123,6 +123,37 @@ export type ProviderCurrentActiveModel = {
model: string;
};
/**
* Input payload used when one session needs to use a different model on its
* next resumed turn.
*
* This is a backend-owned session override, not a claim that the provider has
* already switched the currently running session in-place. Provider adapters
* persist this request so the next CLI/SDK resume can inject the chosen model
* using the provider-specific mechanism supported by that runtime.
*/
export type ProviderChangeActiveModelInput = {
sessionId: string;
model: string;
};
/**
* Provider-neutral session model-change state.
*
* `supported` indicates whether the provider adapter supports the app's
* session-scoped resume override flow. `changed` is the persisted boolean the
* resume layer checks before forcing a model on the next resumed turn. When
* `changed` is `false`, `model` is `null` and the runtime should use the
* normal request/default model selection path.
*/
export type ProviderSessionActiveModelChange = {
provider: LLMProvider;
sessionId: string;
supported: boolean;
changed: boolean;
model: string | null;
};
/**
* Message/event variants emitted by provider adapters and normalized transports.
*