feat(chat): persist safe Codex next-turn model selection

This commit is contained in:
2026-10-20 16:32:42 +01:00
parent d92fa60259
commit ed0abb976d
16 changed files with 682 additions and 27 deletions
+16
View File
@@ -0,0 +1,16 @@
/** Harnesses with a verified catalog and model-selection path. */
export function supportsChatModels(backend) {
return ["", "opencode", "codex"].includes(String(backend ?? "").trim());
}
/** Never turn an unknown remote model into an invented model name. */
export function chatModelLabel(session) {
const model = String(session?.model ?? "").trim() || "Model";
return session?.model_selection === "next_turn" ? `${model} · next turn` : model;
}
export function chatModelSelectionNote(backend) {
return backend === "codex"
? "Saved by Pipelines for the next turn you send. Does not resume this thread or edit global Codex configuration."
: "Applies to the next turn in this chat.";
}
+9 -8
View File
@@ -5,6 +5,7 @@
import { backChevronIcon, h } from "../dom.js";
import { readChatStars, writeChatStars } from "../chatStars.js";
import { chatModelLabel, chatModelSelectionNote, supportsChatModels } from "../chatModels.js";
import { describeError } from "../format.js";
import { SHELL_OUTPUT_LIMIT, nativeChatMessageId, newChatOperationId } from "../repository.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
@@ -2578,8 +2579,8 @@ function renderChatSnackbar() {
/** The chat header's model control: current model, opens the switcher. */
function renderChatModelButton(session) {
const backend = String(session?.backend ?? "").trim();
if (backend !== "" && backend !== "opencode") return null;
const label = String(session?.model ?? "").trim() || "Model";
if (!supportsChatModels(backend)) return null;
const label = chatModelLabel(session);
return h(
"button",
{
@@ -2617,7 +2618,7 @@ function closeChatModelPicker() {
async function loadChatModels(sessionId) {
const backend = state.chatSessions.find((row) => row.id === sessionId)?.backend ?? "opencode";
if (backend !== "" && backend !== "opencode") {
if (!supportsChatModels(backend)) {
state.chatModelsLoading = false;
state.chatModelsError = `${chatBackendLabel(backend)} does not support changing models from this client.`;
if (state.chatModelPicker?.id === sessionId) renderContent();
@@ -2644,8 +2645,8 @@ async function selectChatModel(session, model) {
state.chatModelsError = "";
renderContent();
try {
await repo.switchChatModel(session.id, model.provider, model.id);
applyChatSessionModel(session.id, model.provider, model.id);
const selected = await repo.switchChatModel(session.id, model.provider, model.id);
applyChatSessionModel(session.id, model.provider, model.id, selected.selection);
state.chatModelPicker = null;
} catch (error) {
state.chatModelsError = describeError(error);
@@ -2655,9 +2656,9 @@ async function selectChatModel(session, model) {
}
/** Apply a successful model switch to the list row and the open thread. */
function applyChatSessionModel(sessionId, provider, model) {
function applyChatSessionModel(sessionId, provider, model, selection = "") {
state.chatSessions = (state.chatSessions ?? []).map((row) =>
row.id === sessionId ? { ...row, model, model_provider: provider } : row,
row.id === sessionId ? { ...row, model, model_provider: provider, model_selection: selection } : row,
);
const thread = state.chatThreads.get(sessionId);
if (thread) setThread(sessionId, { model, modelProvider: provider });
@@ -2682,7 +2683,7 @@ function renderChatModelDialog(session) {
panel.append(
h("p", {
class: "chat-model-helper muted",
text: "Applies to the next turn in this chat.",
text: chatModelSelectionNote(session.backend),
}),
);
if (state.chatModelsLoading) {