diff --git a/apps/web/src/components/chat/chatViewSend.ts b/apps/web/src/components/chat/chatViewSend.ts index e6d802ffe7f92..7651dfa97ea5e 100644 --- a/apps/web/src/components/chat/chatViewSend.ts +++ b/apps/web/src/components/chat/chatViewSend.ts @@ -310,6 +310,7 @@ export function resolveMultipleModelTargets(input: { readonly messageText: string; }): Array { const { messageText } = input; + const { stickyOptionsByModelByProvider } = useComposerDraftStore.getState(); return input.selections.map((selection) => { const provider = input.providerInstanceEntries.find( (entry) => entry.instanceId === selection.instanceId, @@ -324,6 +325,7 @@ export function resolveMultipleModelTargets(input: { model: selection.model, models: provider.models, modelOptions: selection.options, + modelOwnedOptions: stickyOptionsByModelByProvider[selection.instanceId]?.[selection.model], promptInjectionState: getComposerPromptInjectionState(messageText), }); return { diff --git a/apps/web/src/components/chat/composerProviderState.test.tsx b/apps/web/src/components/chat/composerProviderState.test.tsx index a1c4e65930236..9e2edfb664436 100644 --- a/apps/web/src/components/chat/composerProviderState.test.tsx +++ b/apps/web/src/components/chat/composerProviderState.test.tsx @@ -399,3 +399,65 @@ describe("getComposerReasoningStep", () => { } }); }); + +describe("Antigravity thinking level dispatch", () => { + const provider = ProviderDriverKind.make("antigravity"); + const model = "gemini-4-carbon"; + const state = ( + current: "medium" | "high" | undefined, + explicit?: "medium" | "high", + remembered?: "medium" | "high", + ) => + getComposerProviderState({ + provider, + model, + models: [ + { + slug: model, + name: "Gemini 4 Carbon", + isCustom: false, + capabilities: { + optionDescriptors: + current === undefined + ? [] + : [ + { + ...selectDescriptor("thought_level", [ + { id: "medium", label: "Medium" }, + { id: "high", label: "High" }, + ]), + role: "reasoning", + currentValue: current, + }, + ], + }, + }, + ], + modelOptions: explicit === undefined ? undefined : selections(["thought_level", explicit]), + modelOwnedOptions: + remembered === undefined ? undefined : selections(["thought_level", remembered]), + }); + + it("preserves explicit High when the advertised options are temporarily absent", () => { + expect(state(undefined, "high", "high").modelOptionsForDispatch).toEqual( + selections(["thought_level", "high"]), + ); + expect(state(undefined, "medium", "medium").modelOptionsForDispatch).toEqual( + selections(["thought_level", "medium"]), + ); + }); + + it("dispatches explicit High over an advertised Medium", () => { + expect(state("medium", "high").modelOptionsForDispatch).toEqual( + selections(["thought_level", "high"]), + ); + }); + + it("does not dispatch a thinking level the user has not chosen", () => { + expect(state("high").promptEffort).toBe("high"); + expect(state("high").modelOptionsForDispatch).toBeUndefined(); + expect(state("medium").promptEffort).toBe("medium"); + expect(state("medium").modelOptionsForDispatch).toBeUndefined(); + expect(state(undefined).modelOptionsForDispatch).toBeUndefined(); + }); +}); diff --git a/apps/web/src/components/chat/composerProviderState.tsx b/apps/web/src/components/chat/composerProviderState.tsx index b8d4bdad4b382..15ff73510f0a5 100644 --- a/apps/web/src/components/chat/composerProviderState.tsx +++ b/apps/web/src/components/chat/composerProviderState.tsx @@ -30,6 +30,7 @@ type ComposerProviderStateInput = { models: ReadonlyArray; promptInjectionState?: ComposerPromptInjectionState; modelOptions: ReadonlyArray | null | undefined; + modelOwnedOptions?: ReadonlyArray | undefined; includePlanAgent?: boolean | undefined; }; @@ -113,6 +114,25 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com (descriptor): descriptor is Extract<(typeof descriptors)[number], { type: "select" }> => descriptor.type === "select", ); + let modelOptionsForDispatch = buildExplicitProviderOptionSelectionsFromDescriptors( + descriptors, + selections, + ); + if (provider === "antigravity" && !descriptors.some(({ id }) => id === "thought_level")) { + // Sticky selections can carry options from another model. + const chosenLevel = selections?.find(({ id }) => id === "thought_level")?.value; + if ( + typeof chosenLevel === "string" && + input.modelOwnedOptions?.some( + ({ id, value }) => id === "thought_level" && value === chosenLevel, + ) + ) { + modelOptionsForDispatch = [ + ...(modelOptionsForDispatch ?? []), + { id: "thought_level", value: chosenLevel }, + ]; + } + } const primaryValue = getProviderOptionCurrentValue(primarySelectDescriptor ?? null); const promptEffort = typeof primaryValue === "string" ? primaryValue : null; const ultrathinkActive = @@ -122,10 +142,7 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com return { provider, promptEffort, - modelOptionsForDispatch: buildExplicitProviderOptionSelectionsFromDescriptors( - descriptors, - selections, - ), + modelOptionsForDispatch, ...(ultrathinkActive ? { composerFrameClassName: "ultrathink-frame", diff --git a/apps/web/src/components/chat/useComposerProviderModel.ts b/apps/web/src/components/chat/useComposerProviderModel.ts index a3db11d09a0fa..2ac4129dc176e 100644 --- a/apps/web/src/components/chat/useComposerProviderModel.ts +++ b/apps/web/src/components/chat/useComposerProviderModel.ts @@ -2,6 +2,7 @@ import { type DraftId, deriveEffectiveComposerModelState, useComposerDraftModelState, + useComposerDraftStore, } from "../../composerDraftStore"; import { draftModelSelectionApplies } from "../../lib/chatThreadActions"; import { @@ -24,8 +25,9 @@ const NO_PROVIDER_MODELS: ServerProvider["models"] = []; /** * The provider instances the composer offers, which one is selected, and the model and options - * the draft resolves to on it. The draft store is read first so every derivation follows the only - * hook here; in the composer body they would straddle its later hooks and lose their cache. + * the draft resolves to on it. Keep both draft-store reads before the derivations so React + * Compiler can cache the derived values; in the composer body they would straddle its later hooks + * and lose their cache. */ export function useComposerProviderModel( input: Omit[0], "entries"> & { @@ -53,6 +55,9 @@ export function useComposerProviderModel( threadStarted, } = input; const draftModelState = useComposerDraftModelState(threadRef); + const stickyOptionsByModelByProvider = useComposerDraftStore( + (store) => store.stickyOptionsByModelByProvider, + ); const providerInstanceEntries: ReadonlyArray = providerInstanceEntriesFor( providerStatuses, settings, @@ -91,6 +96,8 @@ export function useComposerProviderModel( models: selectedProviderModels, promptInjectionState, modelOptions: modelState.modelOptions?.[selectedInstanceId], + modelOwnedOptions: + stickyOptionsByModelByProvider[selectedInstanceId]?.[modelState.selectedModel], }); return { providerInstanceEntries, diff --git a/apps/web/src/composerDraftStore.test.ts b/apps/web/src/composerDraftStore.test.ts index a04d00cbbc2de..e6f439e660109 100644 --- a/apps/web/src/composerDraftStore.test.ts +++ b/apps/web/src/composerDraftStore.test.ts @@ -97,6 +97,7 @@ import { useComposerDraftStore, DraftId, } from "./composerDraftStore"; +import { getComposerProviderState } from "./components/chat/composerProviderState"; import { waitForDraftHeroTransition } from "./components/chat/draftHeroTransition"; import { insertInlineContextReference } from "./lib/composerContextReferences"; import { @@ -2114,6 +2115,85 @@ describe("composerDraftStore sticky composer settings", () => { resetComposerDraftStore(); }); + describe("Antigravity thinking level with a missing descriptor", () => { + const provider = ProviderDriverKind.make("antigravity"); + const instanceId = defaultInstanceIdForDriver(provider); + const carbon = "gemini-4-carbon"; + const otherModel = "other-antigravity-model"; + const high = toSelections({ thought_level: "high" }); + const draftId = DraftId.make("antigravity-current-draft"); + const freshDraftId = DraftId.make("antigravity-fresh-draft"); + + const pickModel = (model: string) => { + const store = useComposerDraftStore.getState(); + const selection = createModelSelection( + instanceId, + model, + store.stickyOptionsByModelByProvider[instanceId]?.[model], + ); + store.setModelSelection(draftId, selection, { explicit: true, replaceOptions: true }); + store.setStickyModelSelection(selection); + }; + + const chooseHigh = (model: string) => { + pickModel(model); + useComposerDraftStore.getState().setProviderModelOptions(draftId, provider, high, { + instanceId, + model, + persistSticky: true, + }); + }; + + const dispatchOptions = (target: DraftId, model: string) => { + const store = useComposerDraftStore.getState(); + const selection = store.draftsByThreadKey[target]?.modelSelectionByProvider[instanceId]; + expect(selection?.model).toBe(model); + const input = { + provider, + model, + models: [{ slug: model, name: model, isCustom: false, capabilities: {} }], + modelOptions: selection?.options, + modelOwnedOptions: store.stickyOptionsByModelByProvider[instanceId]?.[model], + }; + return getComposerProviderState(input).modelOptionsForDispatch; + }; + + it("omits Carbon's High after switching to another model in the current and fresh drafts", () => { + chooseHigh(carbon); + pickModel(otherModel); + useComposerDraftStore.getState().applyStickyState(freshDraftId); + + expect(draftByKey(freshDraftId)?.modelSelectionByProvider[instanceId]?.options).toEqual(high); + expect(dispatchOptions(draftId, otherModel)).toBeUndefined(); + expect(dispatchOptions(freshDraftId, otherModel)).toBeUndefined(); + }); + + it("keeps Carbon's own High in the current draft, after reload, and in a fresh draft", () => { + chooseHigh(carbon); + expect(dispatchOptions(draftId, carbon)).toEqual(high); + + const persisted = JSON.parse( + JSON.stringify(partializeComposerDraftStoreState(useComposerDraftStore.getState())), + ); + const merge = useComposerDraftStore.persist.getOptions().merge!; + useComposerDraftStore.setState(merge(persisted, useComposerDraftStore.getInitialState())); + + expect(dispatchOptions(draftId, carbon)).toEqual(high); + useComposerDraftStore.getState().applyStickyState(freshDraftId); + expect(dispatchOptions(freshDraftId, carbon)).toEqual(high); + }); + + it("keeps the other model's own remembered High after switching back to it", () => { + chooseHigh(otherModel); + pickModel(carbon); + pickModel(otherModel); + useComposerDraftStore.getState().applyStickyState(freshDraftId); + + expect(dispatchOptions(draftId, otherModel)).toEqual(high); + expect(dispatchOptions(freshDraftId, otherModel)).toEqual(high); + }); + }); + it("preserves sticky provider options when model selection omits options", () => { const store = useComposerDraftStore.getState(); diff --git a/apps/web/src/modelSelection.test.ts b/apps/web/src/modelSelection.test.ts index 7df4c4d339a9e..f623e3b044f2b 100644 --- a/apps/web/src/modelSelection.test.ts +++ b/apps/web/src/modelSelection.test.ts @@ -1029,6 +1029,24 @@ describe("instance-scoped model selection", () => { ); }); + it("keeps the Antigravity thinking level saved for text generation while its descriptor is missing", () => { + const instanceId = ProviderInstanceId.make("antigravity"); + const antigravity = provider({ + provider: ProviderDriverKind.make("antigravity"), + instanceId, + models: ["gemini-4-carbon"], + }); + const options = [{ id: "thought_level", value: "high" }]; + const settings = { + ...settingsWithProviderInstances(), + textGenerationModelSelection: createModelSelection(instanceId, "gemini-4-carbon", options), + }; + + expect(resolveAppModelSelectionState(settings, [antigravity])).toEqual( + createModelSelection(instanceId, "gemini-4-carbon", options), + ); + }); + it("excludes customized extension models while preserving unknown custom and thread models", () => { const pi = provider({ provider: ProviderDriverKind.make("pi"), diff --git a/apps/web/src/modelSelection.ts b/apps/web/src/modelSelection.ts index ff8ac2b1a80eb..15d52d8fed7b2 100644 --- a/apps/web/src/modelSelection.ts +++ b/apps/web/src/modelSelection.ts @@ -425,8 +425,9 @@ export function resolveAppModelSelectionState( const selectedModel = selectedEntry ? selection.model : null; // Use the cheap generation default; the catalog default is the expensive chat flagship. const options = getTextGenerationModelOptionsForInstance(settings, entry); + const resolvedSelectedModel = resolveSelectableModel(entry.driverKind, selectedModel, options); const model = - resolveSelectableModel(entry.driverKind, selectedModel, options) ?? + resolvedSelectedModel ?? resolveSelectableModel( entry.driverKind, DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[entry.driverKind], @@ -445,6 +446,7 @@ export function resolveAppModelSelectionState( model, models: entry.models, modelOptions: selectedEntry ? selection.options : undefined, + modelOwnedOptions: resolvedSelectedModel === model ? selection.options : undefined, includePlanAgent: selectsPlanAgent(selection.options), });