Skip to content
TypeScript

fix(web): project default model works on the hosted app (#9142)

Julius Marminge0e1570bde5b6
diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsx
index d6c52a21e0a..2757866ecbb 100644
--- a/apps/web/src/components/settings/IntegrationsSettings.tsx
+++ b/apps/web/src/components/settings/IntegrationsSettings.tsx
@@ -408,6 +408,7 @@ function AgentBrowserAccessSetting() {
return (
<SettingsRow
+ serverScoped
{...searchableSetting("agent-browser-access")}
description="Let agents open and drive the preview browser. When off, the browser tools and the instructions describing them are withheld from agent sessions. Your own browser panel is unaffected."
status={
@@ -516,8 +517,9 @@ export function IntegrationsSettingsPanel() {
return (
<SettingsPageContainer>
<SettingsSection id="browser" title="Browser">
- {/* Server-authoritative, so it stays editable on every client and sits
- outside the block covering the desktop-only defaults. */}
+ {/* Server-authoritative, so it stays editable on any client anchored to
+ a server; `serverScoped` covers the hosted app, which has none. It
+ sits outside the block covering the desktop-only defaults. */}
<AgentBrowserAccessSetting />
{previewDefaultsDisabled ? (
<DesktopOnlyBrowserDefaults>{previewDefaults}</DesktopOnlyBrowserDefaults>
diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.tsx
index dd9c899430b..ea88d05066f 100644
--- a/apps/web/src/components/settings/ProjectSettingsPanel.tsx
+++ b/apps/web/src/components/settings/ProjectSettingsPanel.tsx
@@ -39,6 +39,7 @@ import { useComposerDraftStore } from "../../composerDraftStore";
import { isElectron } from "../../env";
import {
useClientSettings,
+ useEnvironmentSettings,
useUpdateClientSettings,
usePrimarySettings,
} from "../../hooks/useSettings";
@@ -69,7 +70,7 @@ import {
import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments";
import { useProjects, useThreadShells } from "../../state/entities";
import { projectEnvironment } from "../../state/projects";
-import { primaryServerProvidersAtom, serverEnvironment } from "../../state/server";
+import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server";
import { useAtomCommand } from "../../state/use-atom-command";
import { ProviderModelPicker } from "../chat/ProviderModelPicker";
import { TraitsPicker } from "../chat/TraitsPicker";
@@ -292,10 +293,20 @@ export function ProjectSettingsPanel({ projectKey }: { projectKey: string }) {
function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
const navigate = useNavigate();
const primaryEnvironmentId = usePrimaryEnvironmentId();
+ const representative =
+ group.memberProjects.find(
+ (member) => member.environmentId === group.environmentId && member.id === group.id,
+ ) ?? group.memberProjects[0]!;
const settings = usePrimarySettings();
+ // Provider instances and model options belong to the environment that runs
+ // the project's threads. The hosted app has no primary environment, so
+ // reading them from there would show "No providers available" everywhere.
+ const projectSettings = useEnvironmentSettings(representative.environmentId);
+ const serverProviders =
+ useAtomValue(serverEnvironment.providersValueAtom(representative.environmentId)) ??
+ EMPTY_SERVER_PROVIDERS;
const updateClientSettings = useUpdateClientSettings();
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
- const serverProviders = useAtomValue(primaryServerProvidersAtom);
const threads = useThreadShells();
const updateProject = useAtomCommand(projectEnvironment.update, { reportFailure: false });
const deleteProject = useAtomCommand(projectEnvironment.delete, { reportFailure: false });
@@ -321,10 +332,6 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
},
});
- const representative =
- group.memberProjects.find(
- (member) => member.environmentId === group.environmentId && member.id === group.id,
- ) ?? group.memberProjects[0]!;
const faviconPath = representative.faviconPath ?? null;
const pickProjectFavicon =
typeof window !== "undefined" &&
@@ -422,14 +429,22 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
const instanceEntries = useMemo(
() =>
sortProviderInstanceEntries(
- applyProviderInstanceSettings(deriveProviderInstanceEntries(serverProviders), settings),
+ applyProviderInstanceSettings(
+ deriveProviderInstanceEntries(serverProviders),
+ projectSettings,
+ ),
),
- [serverProviders, settings],
+ [serverProviders, projectSettings],
);
const modelOptionsByInstance = useMemo(
() =>
- getCustomModelOptionsByInstance(settings, serverProviders, resolvedInstanceId, resolvedModel),
- [resolvedInstanceId, resolvedModel, serverProviders, settings],
+ getCustomModelOptionsByInstance(
+ projectSettings,
+ serverProviders,
+ resolvedInstanceId,
+ resolvedModel,
+ ),
+ [resolvedInstanceId, resolvedModel, serverProviders, projectSettings],
);
const activeEntry = instanceEntries.find((entry) => entry.instanceId === resolvedInstanceId);
const setDefaultModel = useCallback(
@@ -864,7 +879,7 @@ function ProjectDetail({ group }: { group: SidebarProjectSnapshot }) {
onPromptChange={() => {}}
modelOptions={resolvedSelection.options ?? []}
allowPromptInjectedEffort={false}
- planModeEnabled={settings.planModeEnabled}
+ planModeEnabled={projectSettings.planModeEnabled}
triggerVariant="outline"
triggerClassName="min-w-0 max-w-none shrink-0 text-foreground/90 hover:text-foreground"
onModelOptionsChange={(nextOptions) => {
diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx
index 666ff4ff6eb..2bc748db35a 100644
--- a/apps/web/src/components/settings/SettingsPanels.tsx
+++ b/apps/web/src/components/settings/SettingsPanels.tsx
@@ -1827,6 +1827,7 @@ function LegacyFeaturesSection() {
}
/>
<SettingsRow
+ serverScoped
{...searchableSetting("legacy-token-streaming")}
description="Paints assistant output token by token instead of in complete chunks. Not recommended: it is significantly slower, and long responses become harder to follow. Kept only for compatibility with the old behavior."
control={
@@ -1970,6 +1971,7 @@ export function GeneralSettingsPanel() {
{supportsAutoSettlement ? (
<>
<SettingsRow
+ serverScoped
{...searchableSetting("auto-settle-merged-threads")}
description="Settle a thread when its pull request merges. Closed pull requests still settle automatically."
resetAction={
@@ -1997,6 +1999,7 @@ export function GeneralSettingsPanel() {
/>
<SettingsRow
+ serverScoped
{...searchableSetting("auto-settle-inactive-threads")}
description="Sidebar threads with no activity for this long settle automatically."
resetAction={
@@ -2027,6 +2030,7 @@ export function GeneralSettingsPanel() {
/>
{settings.sidebarAutoSettleAfterDays !== null ? (
<SettingsRow
+ serverScoped
title={searchableSetting("days-before-auto-settle").title}
description="Any new activity un-settles a thread automatically."
control={
@@ -2135,6 +2139,7 @@ export function GeneralSettingsPanel() {
/>
<SettingsRow
+ serverScoped
{...searchableSetting("provider-update-checks")}
description="Check installed provider CLIs for newer available versions."
resetAction={
@@ -2162,6 +2167,7 @@ export function GeneralSettingsPanel() {
/>
<SettingsRow
+ serverScoped
id={searchableSetting("background-activity").id}
title={
<span className="inline-flex items-center gap-1.5">
@@ -2245,6 +2251,7 @@ export function GeneralSettingsPanel() {
/>
<SettingsRow
+ serverScoped
{...searchableSetting("new-threads")}
description="Pick the default workspace mode for newly created draft threads."
resetAction={
@@ -2291,6 +2298,7 @@ export function GeneralSettingsPanel() {
{settings.defaultThreadEnvMode === "worktree" ? (
<SettingsRow
+ serverScoped
className="bg-muted/20 sm:pl-9"
title={searchableSetting("start-from-origin").title}
description="Creates the worktree from the latest matching branch on origin instead of your local branch."
@@ -2321,6 +2329,7 @@ export function GeneralSettingsPanel() {
) : null}
<SettingsRow
+ serverScoped
{...searchableSetting("add-project-starts-in")}
description='Leave empty to use "~/" when the Add Project browser opens.'
resetAction={
@@ -2465,6 +2474,7 @@ export function GeneralSettingsPanel() {
) : null}
<SettingsRow
+ serverScoped
{...searchableSetting("text-generation-model")}
description="Default model for generated text like thread titles and source control content. Source control settings can override it with a dedicated source control writer model."
resetAction={
diff --git a/apps/web/src/components/settings/SourceControlSettings.tsx b/apps/web/src/components/settings/SourceControlSettings.tsx
index f2b0578e1c5..51f3e7bfa93 100644
--- a/apps/web/src/components/settings/SourceControlSettings.tsx
+++ b/apps/web/src/components/settings/SourceControlSettings.tsx
@@ -593,7 +593,9 @@ export function SourceControlSettingsPanel() {
/>
)}
- {isPrimaryEnvironment ? <SourceControlWritingSettingsSection /> : null}
+ {/* Its rows are serverScoped: without a primary they render inert with
+ an explanation, which beats disappearing. */}
+ <SourceControlWritingSettingsSection />
</SettingsPageContainer>
);
}
diff --git a/apps/web/src/components/settings/SourceControlWritingSettings.tsx b/apps/web/src/components/settings/SourceControlWritingSettings.tsx
index 7f3660c52b2..33da931b9db 100644
--- a/apps/web/src/components/settings/SourceControlWritingSettings.tsx
+++ b/apps/web/src/components/settings/SourceControlWritingSettings.tsx
@@ -74,6 +74,7 @@ export function SourceControlWritingSettingsSection() {
return (
<SettingsSection title="Text generation">
<SettingsRow
+ serverScoped
{...searchableSetting("source-control-writing-style")}
description={MODE_OPTIONS[style.mode].description}
resetAction={
@@ -138,6 +139,7 @@ export function SourceControlWritingSettingsSection() {
</SettingsRow>
<SettingsRow
+ serverScoped
{...searchableSetting("follow-change-request-templates")}
description="Structures change request descriptions using the current repository's template when one is available."
resetAction={
@@ -170,6 +172,7 @@ export function SourceControlWritingSettingsSection() {
/>
<SettingsRow
+ serverScoped
{...searchableSetting("source-control-writer-model")}
description="Optional model override for change descriptions, change request titles and descriptions, and branch or bookmark names. Off uses the global text generation model."
control={
diff --git a/apps/web/src/components/settings/settingsLayout.tsx b/apps/web/src/components/settings/settingsLayout.tsx
index 5fdcb24433b..e9b7a988836 100644
--- a/apps/web/src/components/settings/settingsLayout.tsx
+++ b/apps/web/src/components/settings/settingsLayout.tsx
@@ -11,6 +11,10 @@ import {
useState,
} from "react";
+import {
+ PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE,
+ usePrimarySettingsAvailable,
+} from "../../hooks/useSettings";
import { cn } from "../../lib/utils";
import { WorkspacePageContainer, type WorkspacePageWidth } from "../WorkspacePageContainer";
import { Button } from "../ui/button";
@@ -159,12 +163,19 @@ export function SettingsSection({
);
}
+/**
+ * One setting. `serverScoped` marks rows whose value lives in the primary
+ * environment's settings.json; where there is no primary (the hosted app)
+ * the control goes inert with a tooltip instead of showing an editable
+ * default that would never save.
+ */
export function SettingsRow({
title,
description,
status,
resetAction,
control,
+ serverScoped = false,
children,
className,
...rowProps
@@ -174,9 +185,36 @@ export function SettingsRow({
status?: ReactNode;
resetAction?: ReactNode;
control?: ReactNode;
+ serverScoped?: boolean;
children?: ReactNode;
}) {
const targetRef = useSettingsSearchTarget<HTMLDivElement>(rowProps.id);
+ const primarySettingsAvailable = usePrimarySettingsAvailable();
+ const unavailable = serverScoped && !primarySettingsAvailable;
+ const renderedReset = unavailable ? null : resetAction;
+ const renderedControl =
+ unavailable && control ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ // Focusable so keyboard users can still reach the explanation.
+ <span
+ tabIndex={0}
+ className="flex w-full items-center rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring sm:w-auto"
+ />
+ }
+ >
+ <div inert className="flex w-full items-center gap-2 opacity-50 sm:w-auto">
+ {control}
+ </div>
+ </TooltipTrigger>
+ <TooltipPopup side="top" className="max-w-72">
+ {PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE}
+ </TooltipPopup>
+ </Tooltip>
+ ) : (
+ control
+ );
return (
<div
@@ -190,7 +228,7 @@ export function SettingsRow({
<div className="flex min-h-5 items-center gap-1.5">
<h3 className="text-sm font-medium tracking-[-0.005em] text-foreground">{title}</h3>
<span className="inline-flex h-5 w-5 shrink-0 items-center justify-center">
- {resetAction}
+ {renderedReset}
</span>
</div>
{description ? (
@@ -200,13 +238,19 @@ export function SettingsRow({
) : null}
{status ? <div className="pt-0.5 text-xs text-muted-foreground">{status}</div> : null}
</div>
- {control ? (
+ {renderedControl ? (
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
- {control}
+ {renderedControl}
</div>
) : null}
</div>
- {children}
+ {unavailable && children ? (
+ <div inert className="opacity-50">
+ {children}
+ </div>
+ ) : (
+ children
+ )}
</div>
);
}
diff --git a/apps/web/src/hooks/useSettings.ts b/apps/web/src/hooks/useSettings.ts
index 23221067b27..a04c514fb45 100644
--- a/apps/web/src/hooks/useSettings.ts
+++ b/apps/web/src/hooks/useSettings.ts
@@ -39,6 +39,8 @@ import {
themeAllowsSidebarArtwork,
} from "~/themePalette";
import * as Struct from "effect/Struct";
+import { toastManager } from "~/components/ui/toast";
+import { isHostedStaticApp } from "~/hostedPairing";
import { primaryServerSettingsAtom, serverEnvironment } from "~/state/server";
import {
type EnvironmentPresentation,
@@ -316,6 +318,20 @@ export function usePrimarySettings<T = UnifiedSettings>(
return useMergedSettings(useAtomValue(primaryServerSettingsAtom), selector);
}
+export const PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE =
+ "This setting is saved on a server, and the hosted app is not anchored to one. Change it from the desktop app or from the server's own address.";
+
+/**
+ * Whether primary-scoped server settings have a server to live on. The
+ * hosted app connects to every environment as a remote, so it has no primary:
+ * `usePrimarySettings` reads schema defaults there and writes have nowhere
+ * to go. Desktop and server-served web always have one.
+ */
+export function usePrimarySettingsAvailable(): boolean {
+ const primaryEnvironment = usePrimaryEnvironment();
+ return primaryEnvironment !== null || !isHostedStaticApp();
+}
+
/**
* Whether an environment can hold every shared key right now. Gated on the
* auto-settlement capability because it is the newest of the shared keys: a
@@ -366,6 +382,13 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
environmentId,
input: { patch: localPatch },
});
+ } else {
+ // Dropping the write silently leaves the control looking saved.
+ toastManager.add({
+ type: "warning",
+ title: "Setting not saved",
+ description: PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE,
+ });
}
if (Object.keys(sharedPatch).length > 0) {
const targets = new Set(connectedEnvironmentIds);
diff --git a/apps/web/src/hostedPairing.ts b/apps/web/src/hostedPairing.ts
index 6a9815b4b33..6c5ac58cb35 100644
--- a/apps/web/src/hostedPairing.ts
+++ b/apps/web/src/hostedPairing.ts
@@ -31,7 +31,7 @@ function originFromUrl(value: string): string | null {
}
}
-export function isHostedStaticApp(url: URL = new URL(window.location.href)): boolean {
+export function isHostedStaticApp(url?: URL): boolean {
if (configuredBackendUrl()) {
return false;
}
@@ -40,8 +40,13 @@ export function isHostedStaticApp(url: URL = new URL(window.location.href)): boo
return true;
}
+ // No window (tests, static render) means no origin to be hosted at.
+ if (url === undefined && typeof window === "undefined") {
+ return false;
+ }
+
const hostedOrigin = originFromUrl(configuredHostedAppUrl());
- return hostedOrigin !== null && url.origin === hostedOrigin;
+ return hostedOrigin !== null && (url ?? new URL(window.location.href)).origin === hostedOrigin;
}
export function readHostedPairingRequest(url: URL = new URL(window.location.href)) {