Open History to see the last commit
1import { DeviceHostsSettings } from "./DeviceHostsSettings";
2/**
3 * Integrations settings - preferences for surfaces T3 Code embeds rather than
4 * owns. Browser is the first section: the defaults a preview tab opens at,
5 * applied to both hand-opened tabs and agent `preview_open` calls that don't
6 * state their own size.
7 *
8 * @module IntegrationsSettings
9 */
10import {
11 BrowserImportFailureReason,
12 BROWSER_PROFILE_MAX_COUNT,
13 type BrowserLinkTarget,
14 type BrowserProfile,
15 type EnvironmentId,
16 type SshDeviceHostConfig,
17 BROWSER_PROFILE_NAME_MAX_LENGTH,
18 BROWSER_RECORDING_FRAME_RATES,
19 DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW,
20 DEFAULT_BROWSER_PROFILE_ID,
21 DEFAULT_BROWSER_LINK_TARGET,
22 DEFAULT_BROWSER_RECORDING_FRAME_RATE,
23 DEFAULT_BROWSER_VIEWPORT,
24 DEFAULT_PREVIEW_APPEARANCE,
25 DEFAULT_PREVIEW_ZOOM_FACTOR,
26 FILL_PREVIEW_VIEWPORT,
27 PREVIEW_VIEWPORT_MAX_AREA,
28 PREVIEW_VIEWPORT_MAX_DIMENSION,
29 PREVIEW_VIEWPORT_MIN_DIMENSION,
30 PREVIEW_ZOOM_LEVELS,
31 findBrowserProfile,
32 isBuiltInBrowserProfileId,
33 resolveBrowserProfiles,
34 type BrowserImportSource,
35 type PreviewAppearancePreference,
36 type PreviewViewportSetting,
37} from "@t3tools/contracts";
38import { PREVIEW_VIEWPORT_PRESETS } from "@t3tools/shared/previewViewport";
39import { Link } from "@tanstack/react-router";
40import { MoreVertical, Plus as PlusIcon } from "lucide-react";
41import { useCallback, useRef, useState } from "react";
42
43import { ScreenRotationIcon } from "~/browser/ScreenRotationIcon";
44import { AnimatedHeight } from "~/components/AnimatedHeight";
45import { resolveEnvironmentOptionLabel } from "~/components/BranchToolbar.logic";
46import { previewBridge } from "~/components/preview/previewBridge";
47import { cn, randomUUID } from "~/lib/utils";
48import { useEnvironments, usePrimaryEnvironment } from "~/state/environments";
49import { deviceEnvironment, useDeviceState } from "~/state/device";
50import { useAtomCommand } from "~/state/use-atom-command";
51import {
52 AgentDeviceSetupStatus,
53 DeviceHubSetupStatus,
54 PlatformStatus,
55 platformSetupStatus,
56 deviceHubDescription,
57 agentDeviceDescription,
58} from "~/components/device/DeviceSetup";
59import { isElectron } from "../../env";
60
61import { Badge } from "../ui/badge";
62import {
63 Menu,
64 MenuGroup,
65 MenuGroupLabel,
66 MenuItem,
67 MenuPopup,
68 MenuSeparator,
69 MenuTrigger,
70} from "../ui/menu";
71import { readLocalApi } from "~/localApi";
72
73import { toastManager } from "../ui/toast";
74import {
75 AlertDialog,
76 AlertDialogClose,
77 AlertDialogDescription,
78 AlertDialogFooter,
79 AlertDialogHeader,
80 AlertDialogPopup,
81 AlertDialogTitle,
82} from "../ui/alert-dialog";
83import { Button } from "../ui/button";
84import { DraftInput } from "../ui/draft-input";
85import { NumberField, NumberFieldGroup, NumberFieldInput } from "../ui/number-field";
86import {
87 Select,
88 SelectGroup,
89 SelectGroupLabel,
90 SelectItem,
91 SelectPopup,
92 SelectTrigger,
93 SelectValue,
94} from "../ui/select";
95import { Switch } from "../ui/switch";
96import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
97import {
98 getClientSettings,
99 persistClientSettingsUpdate,
100 useClientSettings,
101 useClientSettingsHydrated,
102 useUpdatePrimarySettings,
103} from "~/hooks/useSettings";
104
105import {
106 SettingsUnavailableGroup,
107 SettingResetButton,
108 SettingsPageContainer,
109 SettingsRow,
110 SettingsSection,
111} from "./settingsLayout";
112import { searchableSetting } from "./settingsSearch";
113import { BrowserImportWizard, type WizardTarget } from "./BrowserImportWizard";
114import type { ImportOutcome } from "./browserImportWizard.logic";
115
116const FILL_VALUE = "fill";
117const RESPONSIVE_VALUE = "responsive";
118
119type BrowserProfileDataBridge = Pick<
120 NonNullable<typeof previewBridge>,
121 "clearCookies" | "clearCache"
122>;
123
124export async function clearBrowserProfileData(
125 bridge: BrowserProfileDataBridge | null,
126 environmentIds: ReadonlyArray<EnvironmentId>,
127 profileId: string,
128): Promise<void> {
129 if (bridge === null || environmentIds.length === 0) {
130 throw new Error("Browser profile data is not available to clear.");
131 }
132 await Promise.all(
133 environmentIds.flatMap((environmentId) => [
134 bridge.clearCookies(environmentId, profileId),
135 bridge.clearCache(environmentId, profileId),
136 ]),
137 );
138}
139
140export function browserProfileRemovalAvailable(
141 bridgeAvailable: boolean,
142 environmentsReady: boolean,
143 environmentCount: number,
144): boolean {
145 return bridgeAvailable && environmentsReady && environmentCount > 0;
146}
147
148/**
149 * The size a "Responsive" default falls back to when the user switches away
150 * from Fill and hasn't typed dimensions yet. Fill has no dimensions to carry
151 * over, so the picker needs something concrete to seed the inputs with.
152 */
153const RESPONSIVE_SEED_SIZE = { width: 1280, height: 800 } as const;
154
155const NO_GROUPING: Intl.NumberFormatOptions = { useGrouping: false };
156
157const APPEARANCE_LABELS: Readonly<Record<PreviewAppearancePreference, string>> = {
158 system: "System",
159 light: "Light",
160 dark: "Dark",
161};
162
163const zoomLabel = (zoomFactor: number) => `${Math.round(zoomFactor * 100)}%`;
164
165/**
166 * IPC flattens the failure to its message, so the reason token travels inside
167 * it. Anything unrecognised reads as a plain read failure rather than leaking
168 * the raw message into a toast.
169 */
170/** Thrown from the post-import settings updater when the cap was hit meanwhile. */
171class ProfileLimitReachedError extends Error {
172 constructor() {
173 super("Browser profile limit reached.");
174 this.name = "ProfileLimitReachedError";
175 }
176}
177
178export const importFailureReason = (cause: unknown): BrowserImportFailureReason => {
179 const message = String((cause as { message?: unknown } | undefined)?.message ?? "");
180 return (
181 BrowserImportFailureReason.literals.find((reason) => message.includes(`failed: ${reason}.`)) ??
182 "readFailed"
183 );
184};
185
186const viewportSelectValue = (viewport: PreviewViewportSetting): string => {
187 if (viewport._tag === "fill") return FILL_VALUE;
188 if (
189 viewport._tag === "preset" &&
190 PREVIEW_VIEWPORT_PRESETS.some((preset) => preset.id === viewport.presetId)
191 ) {
192 return viewport.presetId;
193 }
194 return RESPONSIVE_VALUE;
195};
196
197/**
198 * The trigger renders this rather than a bare `SelectValue`, which would fall
199 * back to printing the raw stored value ("fill") because the options are built
200 * inline instead of from an `items` map.
201 */
202const viewportSelectLabel = (viewport: PreviewViewportSetting): string => {
203 const value = viewportSelectValue(viewport);
204 if (value === FILL_VALUE) return "Fill panel";
205 if (value === RESPONSIVE_VALUE) return "Responsive";
206 return PREVIEW_VIEWPORT_PRESETS.find((preset) => preset.id === value)?.label ?? "Responsive";
207};
208
209const isValidDimension = (value: number) =>
210 Number.isInteger(value) &&
211 value >= PREVIEW_VIEWPORT_MIN_DIMENSION &&
212 value <= PREVIEW_VIEWPORT_MAX_DIMENSION;
213
214/**
215 * A sized viewport with width and height swapped. Presets keep their identity
216 * through a rotation — `resolvePreviewViewport` already stores rotated presets
217 * as the preset id plus swapped dimensions — so a rotated iPad is still an
218 * iPad, not an anonymous custom size.
219 */
220const rotateViewport = (
221 viewport: Exclude<PreviewViewportSetting, { readonly _tag: "fill" }>,
222): PreviewViewportSetting => ({
223 ...viewport,
224 width: viewport.height,
225 height: viewport.width,
226});
227
228function BrowserViewportSetting({ disabled }: { readonly disabled: boolean }) {
229 const viewport = useClientSettings((settings) => settings.browserDefaultViewport);
230 const updateSettings = useUpdatePrimarySettings();
231
232 const sized = viewport._tag === "fill" ? null : viewport;
233 const presentedSize = {
234 width: sized?.width ?? RESPONSIVE_SEED_SIZE.width,
235 height: sized?.height ?? RESPONSIVE_SEED_SIZE.height,
236 };
237
238 const selectViewport = (value: string | null) => {
239 if (value === FILL_VALUE) {
240 updateSettings({ browserDefaultViewport: FILL_PREVIEW_VIEWPORT });
241 return;
242 }
243 if (value === RESPONSIVE_VALUE) {
244 updateSettings({
245 browserDefaultViewport: {
246 _tag: "freeform",
247 width: sized?.width ?? RESPONSIVE_SEED_SIZE.width,
248 height: sized?.height ?? RESPONSIVE_SEED_SIZE.height,
249 },
250 });
251 return;
252 }
253 const preset = PREVIEW_VIEWPORT_PRESETS.find((candidate) => candidate.id === value);
254 if (!preset) return;
255 updateSettings({
256 browserDefaultViewport: {
257 _tag: "preset",
258 width: preset.width,
259 height: preset.height,
260 presetId: preset.id,
261 },
262 });
263 };
264
265 // Committed on blur rather than per keystroke: typing "2560" passes through
266 // "256", which is a legal dimension, so an onValueChange handler would
267 // persist that intermediate size and churn the settings file on every key.
268 const commitDimension = (axis: "width" | "height", value: number | null) => {
269 if (value === null || !isValidDimension(value)) return;
270 const next = { ...presentedSize, [axis]: value };
271 if (next.width * next.height > PREVIEW_VIEWPORT_MAX_AREA) return;
272 if (sized && next.width === sized.width && next.height === sized.height) return;
273 // Typing a size means the preset no longer describes it.
274 updateSettings({ browserDefaultViewport: { _tag: "freeform", ...next } });
275 };
276
277 return (
278 <SettingsRow
279 {...searchableSetting("browser-default-viewport")}
280 description="Tab size for you and agents. Fill fits the panel; other sizes show the device toolbar."
281 resetAction={
282 !disabled && viewport._tag !== DEFAULT_BROWSER_VIEWPORT._tag ? (
283 <SettingResetButton
284 label="default browser viewport"
285 onClick={() => updateSettings({ browserDefaultViewport: DEFAULT_BROWSER_VIEWPORT })}
286 />
287 ) : null
288 }
289 control={
290 <div className="flex w-full flex-wrap items-center justify-end gap-2 sm:w-auto">
291 <Select
292 value={viewportSelectValue(viewport)}
293 onValueChange={selectViewport}
294 disabled={disabled}
295 >
296 <SelectTrigger
297 size="sm"
298 className="w-full min-w-0 sm:w-44"
299 aria-label="Default browser viewport"
300 >
301 <SelectValue>{viewportSelectLabel(viewport)}</SelectValue>
302 </SelectTrigger>
303 <SelectPopup align="end" alignItemWithTrigger={false} className="min-w-64">
304 <SelectItem value={FILL_VALUE}>Fill panel</SelectItem>
305 <SelectItem value={RESPONSIVE_VALUE}>Responsive</SelectItem>
306 <SelectGroup>
307 <SelectGroupLabel>Standard</SelectGroupLabel>
308 {PREVIEW_VIEWPORT_PRESETS.map((preset) => (
309 <SelectItem key={preset.id} value={preset.id}>
310 <span className="flex w-full items-center justify-between gap-5">
311 <span>{preset.label}</span>
312 <span className="text-xs tabular-nums text-muted-foreground">
313 {preset.detail}
314 </span>
315 </span>
316 </SelectItem>
317 ))}
318 </SelectGroup>
319 </SelectPopup>
320 </Select>
321
322 {sized ? (
323 <div className="flex min-w-0 items-center gap-1">
324 <NumberField
325 value={presentedSize.width}
326 min={PREVIEW_VIEWPORT_MIN_DIMENSION}
327 max={PREVIEW_VIEWPORT_MAX_DIMENSION}
328 disabled={disabled}
329 // Pixel counts read as raw numbers; grouping would show "1,024".
330 format={NO_GROUPING}
331 size="sm"
332 className="w-20"
333 onValueCommitted={(value) => commitDimension("width", value)}
334 >
335 <NumberFieldGroup>
336 <NumberFieldInput aria-label="Default viewport width" />
337 </NumberFieldGroup>
338 </NumberField>
339 <span className="text-xs text-muted-foreground">×</span>
340 <NumberField
341 value={presentedSize.height}
342 min={PREVIEW_VIEWPORT_MIN_DIMENSION}
343 max={PREVIEW_VIEWPORT_MAX_DIMENSION}
344 disabled={disabled}
345 format={NO_GROUPING}
346 size="sm"
347 className="w-20"
348 onValueCommitted={(value) => commitDimension("height", value)}
349 >
350 <NumberFieldGroup>
351 <NumberFieldInput aria-label="Default viewport height" />
352 </NumberFieldGroup>
353 </NumberField>
354 <Tooltip>
355 <TooltipTrigger
356 render={
357 <Button
358 size="icon-sm"
359 variant="ghost-muted"
360 disabled={disabled}
361 aria-label={`Rotate to ${
362 presentedSize.height >= presentedSize.width ? "landscape" : "portrait"
363 }`}
364 onClick={() =>
365 updateSettings({ browserDefaultViewport: rotateViewport(sized) })
366 }
367 >
368 <ScreenRotationIcon />
369 </Button>
370 }
371 />
372 <TooltipPopup side="top">Rotate</TooltipPopup>
373 </Tooltip>
374 </div>
375 ) : null}
376 </div>
377 }
378 />
379 );
380}
381
382function BrowserZoomSetting({ disabled }: { readonly disabled: boolean }) {
383 const zoomFactor = useClientSettings((settings) => settings.browserDefaultZoomFactor);
384 const updateSettings = useUpdatePrimarySettings();
385
386 return (
387 <SettingsRow
388 {...searchableSetting("browser-default-zoom")}
389 description="Page zoom applied to new browser tabs."
390 resetAction={
391 !disabled && zoomFactor !== DEFAULT_PREVIEW_ZOOM_FACTOR ? (
392 <SettingResetButton
393 label="default browser zoom"
394 onClick={() =>
395 updateSettings({ browserDefaultZoomFactor: DEFAULT_PREVIEW_ZOOM_FACTOR })
396 }
397 />
398 ) : null
399 }
400 control={
401 <Select
402 disabled={disabled}
403 value={String(zoomFactor)}
404 onValueChange={(value) => {
405 const next = PREVIEW_ZOOM_LEVELS.find((level) => String(level) === value);
406 if (next !== undefined) updateSettings({ browserDefaultZoomFactor: next });
407 }}
408 >
409 <SelectTrigger size="sm" className="w-full sm:w-40" aria-label="Default browser zoom">
410 <SelectValue>{zoomLabel(zoomFactor)}</SelectValue>
411 </SelectTrigger>
412 <SelectPopup align="end" alignItemWithTrigger={false}>
413 {PREVIEW_ZOOM_LEVELS.map((level) => (
414 <SelectItem hideIndicator key={level} value={String(level)}>
415 {zoomLabel(level)}
416 </SelectItem>
417 ))}
418 </SelectPopup>
419 </Select>
420 }
421 />
422 );
423}
424
425function BrowserAppearanceSetting({ disabled }: { readonly disabled: boolean }) {
426 const appearance = useClientSettings((settings) => settings.browserDefaultAppearance);
427 const updateSettings = useUpdatePrimarySettings();
428
429 return (
430 <SettingsRow
431 {...searchableSetting("browser-default-appearance")}
432 description="The color scheme pages are told to prefer. System follows your OS setting."
433 resetAction={
434 !disabled && appearance !== DEFAULT_PREVIEW_APPEARANCE ? (
435 <SettingResetButton
436 label="default browser appearance"
437 onClick={() => updateSettings({ browserDefaultAppearance: DEFAULT_PREVIEW_APPEARANCE })}
438 />
439 ) : null
440 }
441 control={
442 <Select
443 disabled={disabled}
444 value={appearance}
445 onValueChange={(value) => {
446 if (value === "system" || value === "light" || value === "dark") {
447 updateSettings({ browserDefaultAppearance: value });
448 }
449 }}
450 >
451 <SelectTrigger
452 size="sm"
453 className="w-full sm:w-40"
454 aria-label="Default browser appearance"
455 >
456 <SelectValue>{APPEARANCE_LABELS[appearance]}</SelectValue>
457 </SelectTrigger>
458 <SelectPopup align="end" alignItemWithTrigger={false}>
459 {Object.entries(APPEARANCE_LABELS).map(([value, label]) => (
460 <SelectItem hideIndicator key={value} value={value}>
461 {label}
462 </SelectItem>
463 ))}
464 </SelectPopup>
465 </Select>
466 }
467 />
468 );
469}
470
471function BrowserRecordingFrameRateSetting({ disabled }: { readonly disabled: boolean }) {
472 const frameRate = useClientSettings((settings) => settings.browserRecordingFrameRate);
473 const updateSettings = useUpdatePrimarySettings();
474
475 return (
476 <SettingsRow
477 {...searchableSetting("browser-recording-frame-rate")}
478 description="Maximum recording rate. 30 fps saves CPU and storage; 60 fps is smoother."
479 resetAction={
480 !disabled && frameRate !== DEFAULT_BROWSER_RECORDING_FRAME_RATE ? (
481 <SettingResetButton
482 label="browser recording frame rate"
483 onClick={() =>
484 updateSettings({ browserRecordingFrameRate: DEFAULT_BROWSER_RECORDING_FRAME_RATE })
485 }
486 />
487 ) : null
488 }
489 control={
490 <Select
491 disabled={disabled}
492 value={String(frameRate)}
493 onValueChange={(value) => {
494 const next = BROWSER_RECORDING_FRAME_RATES.find((rate) => String(rate) === value);
495 if (next !== undefined) {
496 updateSettings({ browserRecordingFrameRate: next });
497 }
498 }}
499 >
500 <SelectTrigger
501 size="sm"
502 className="w-full sm:w-40"
503 aria-label="Browser recording frame rate"
504 >
505 <SelectValue>{frameRate} fps</SelectValue>
506 </SelectTrigger>
507 <SelectPopup align="end" alignItemWithTrigger={false}>
508 {BROWSER_RECORDING_FRAME_RATES.map((rate) => (
509 <SelectItem hideIndicator key={rate} value={String(rate)}>
510 {rate} fps
511 </SelectItem>
512 ))}
513 </SelectPopup>
514 </Select>
515 }
516 />
517 );
518}
519
520const LINK_TARGET_LABELS: Readonly<Record<BrowserLinkTarget, string>> = {
521 system: "Your default browser",
522 app: "T3 Code",
523};
524
525function BrowserLinkTargetSetting({ disabled }: { readonly disabled: boolean }) {
526 const linkTarget = useClientSettings((settings) => settings.browserLinkTarget);
527 const updateSettings = useUpdatePrimarySettings();
528
529 return (
530 <SettingsRow
531 {...searchableSetting("browser-link-target")}
532 description="Where links in the chat and terminal open. Hold ⌘ or Ctrl while clicking a link to open it in your default browser either way."
533 resetAction={
534 !disabled && linkTarget !== DEFAULT_BROWSER_LINK_TARGET ? (
535 <SettingResetButton
536 label="link target"
537 onClick={() => updateSettings({ browserLinkTarget: DEFAULT_BROWSER_LINK_TARGET })}
538 />
539 ) : null
540 }
541 control={
542 <Select
543 disabled={disabled}
544 value={linkTarget}
545 onValueChange={(value) => {
546 if (value === "system" || value === "app") {
547 updateSettings({ browserLinkTarget: value });
548 }
549 }}
550 >
551 <SelectTrigger size="sm" className="w-full sm:w-40" aria-label="Open links in">
552 <SelectValue>{LINK_TARGET_LABELS[linkTarget]}</SelectValue>
553 </SelectTrigger>
554 <SelectPopup align="end" alignItemWithTrigger={false}>
555 {(Object.keys(LINK_TARGET_LABELS) as ReadonlyArray<BrowserLinkTarget>).map((target) => (
556 <SelectItem hideIndicator key={target} value={target}>
557 {LINK_TARGET_LABELS[target]}
558 </SelectItem>
559 ))}
560 </SelectPopup>
561 </Select>
562 }
563 />
564 );
565}
566
567function AgentBrowserAccessSetting() {
568 return (
569 <SettingsRow
570 {...searchableSetting("agent-browser-access")}
571 description="Choose whether agents can use the preview browser for all projects or a specific project."
572 control={
573 <Button
574 render={
575 <Link to="/settings/projects" search={{ project: undefined, machine: undefined }} />
576 }
577 size="sm"
578 variant="outline"
579 >
580 Project settings
581 </Button>
582 }
583 />
584 );
585}
586
587function DeviceIntegrationSettings() {
588 const primaryEnvironment = usePrimaryEnvironment();
589 const { environments } = useEnvironments();
590 const [selectedId, setSelectedId] = useState<string | null>(null);
591 const selected =
592 environments.find((environment) => environment.environmentId === selectedId) ??
593 environments.find(
594 (environment) => environment.environmentId === primaryEnvironment?.environmentId,
595 ) ??
596 environments[0];
597 const connected = selected?.connection.phase === "connected" && selected.serverConfig !== null;
598 const environmentId = connected ? selected.environmentId : null;
599
600 return (
601 <SettingsSection id="devices" title="Devices">
602 {environments.length > 1 ? (
603 <SettingsRow
604 title="Environment"
605 description="Device support and hosts are shared by all projects in this environment."
606 control={
607 <Select
608 value={selected?.environmentId ?? ""}
609 onValueChange={(value) => setSelectedId(value)}
610 >
611 <SelectTrigger size="sm" aria-label="Device environment">
612 <SelectValue>{selected?.label ?? "Select environment"}</SelectValue>
613 </SelectTrigger>
614 <SelectPopup align="end" alignItemWithTrigger={false}>
615 {environments.map((environment) => (
616 <SelectItem key={environment.environmentId} value={environment.environmentId}>
617 {environment.label}
618 {environment.connection.phase === "connected" ? "" : " · Offline"}
619 </SelectItem>
620 ))}
621 </SelectPopup>
622 </Select>
623 }
624 />
625 ) : null}
626 <DeviceIntegrationControls
627 key={selected?.environmentId ?? "none"}
628 environmentId={environmentId}
629 hosts={selected?.serverConfig?.settings.deviceHosts ?? []}
630 enabled={selected?.serverConfig?.settings.enableDeviceSupport ?? false}
631 agentAccessEnabled={selected?.serverConfig?.settings.enableAgentDeviceAccess ?? false}
632 />
633 </SettingsSection>
634 );
635}
636
637function DeviceIntegrationControls({
638 environmentId,
639 hosts,
640 enabled,
641 agentAccessEnabled,
642}: {
643 environmentId: EnvironmentId | null;
644 hosts: ReadonlyArray<SshDeviceHostConfig>;
645 enabled: boolean;
646 agentAccessEnabled: boolean;
647}) {
648 const { state, loaded } = useDeviceState(environmentId);
649 const configure = useAtomCommand(deviceEnvironment.configure);
650 const list = useAtomCommand(deviceEnvironment.list, { reportFailure: false });
651 const [pending, setPending] = useState<"hub" | "check" | "agent" | null>(null);
652 const busy = state.hostStatus === "installing" || state.hostStatus === "starting";
653 const [platformsRevealed, setPlatformsRevealed] = useState(false);
654 // Keep diagnostics visible through subsequent agent setup and refresh phases.
655 if (platformsRevealed && !enabled) setPlatformsRevealed(false);
656 if (enabled && !platformsRevealed && state.hostStatus === "ready" && pending !== "hub") {
657 setPlatformsRevealed(true);
658 }
659
660 const update = async (
661 kind: NonNullable<typeof pending>,
662 input: { enabled?: boolean; agentAccessEnabled?: boolean },
663 ) => {
664 if (!environmentId) return;
665 setPending(kind);
666 try {
667 const result = await configure({ environmentId, input });
668 if (result._tag === "Success" && input.enabled === true && !state.onboardingCompleted) {
669 await configure({ environmentId, input: { onboardingCompleted: true } });
670 }
671 } finally {
672 setPending(null);
673 }
674 };
675
676 return (
677 <>
678 <SettingsRow
679 {...searchableSetting("device-hub")}
680 description={deviceHubDescription}
681 control={
682 <>
683 {pending === "hub" ? <DeviceHubSetupStatus state={state} pending compact /> : null}
684 <Switch
685 checked={enabled}
686 disabled={!loaded || !environmentId || busy || pending !== null}
687 aria-label="Device hub"
688 onCheckedChange={(checked) =>
689 void update("hub", {
690 enabled: Boolean(checked),
691 ...(checked ? {} : { agentAccessEnabled: false }),
692 })
693 }
694 />
695 </>
696 }
697 />
698 <AnimatedHeight>
699 {platformsRevealed ? (
700 <SettingsRow
701 {...searchableSetting("device-platform-support")}
702 status={
703 <div className="flex flex-wrap gap-x-5 gap-y-2">
704 <PlatformStatus compact platform="iOS" status={platformSetupStatus(state, "ios")} />
705 <PlatformStatus
706 compact
707 platform="Android"
708 status={platformSetupStatus(state, "android")}
709 />
710 </div>
711 }
712 control={
713 <Button
714 size="sm"
715 variant="outline"
716 disabled={!environmentId || !enabled || busy || pending !== null}
717 onClick={() => {
718 if (!environmentId) return;
719 setPending("check");
720 void list({ environmentId, input: {} }).finally(() => setPending(null));
721 }}
722 >
723 {pending === "check" ? "Checking…" : "Refresh"}
724 </Button>
725 }
726 />
727 ) : null}
728 </AnimatedHeight>
729 <SettingsRow
730 {...searchableSetting("agent-device-access")}
731 description={agentDeviceDescription}
732 control={
733 <>
734 {pending === "agent" ? <AgentDeviceSetupStatus state={state} pending compact /> : null}
735 <Switch
736 checked={agentAccessEnabled}
737 disabled={!loaded || !environmentId || !enabled || busy || pending !== null}
738 aria-label="Agent device access"
739 onCheckedChange={(checked) =>
740 void update("agent", { agentAccessEnabled: Boolean(checked) })
741 }
742 />
743 </>
744 }
745 />
746 {state.hostStatus === "failed" && state.hostStatusDetail ? (
747 <p role="alert" className="px-4 py-3 text-xs text-destructive">
748 {state.hostStatusDetail}
749 </p>
750 ) : null}
751 <DeviceHostsSettings environmentId={environmentId} hosts={hosts} />
752 </>
753 );
754}
755
756function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled: boolean }) {
757 const autoShow = useClientSettings((settings) => settings.browserAutoShowFloatingPreview);
758 const updateSettings = useUpdatePrimarySettings();
759
760 return (
761 <SettingsRow
762 {...searchableSetting("browser-auto-show-floating-preview")}
763 description="Show the floating preview when an agent opens a browser unless the agent says otherwise."
764 resetAction={
765 !disabled && autoShow !== DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW ? (
766 <SettingResetButton
767 label="auto-show floating preview"
768 onClick={() =>
769 updateSettings({
770 browserAutoShowFloatingPreview: DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW,
771 })
772 }
773 />
774 ) : null
775 }
776 control={
777 <Switch
778 disabled={disabled}
779 checked={autoShow}
780 onCheckedChange={(checked) =>
781 updateSettings({ browserAutoShowFloatingPreview: Boolean(checked) })
782 }
783 aria-label="Auto-show floating preview"
784 />
785 }
786 />
787 );
788}
789
790/**
791 * Profile list, its header menu, and the import flow.
792 *
793 * One menu creates profiles and imports into them, because the two are the
794 * same decision from the user's side: "I want a profile that has my Helium
795 * logins in it". Import targets include "New profile" so that case does not
796 * require creating one first and then finding a second control.
797 *
798 * Built-ins render without a rename field: they are synthesized rather than
799 * stored, so there is nothing to rename and removing them would strand every
800 * tab that opened under them.
801 *
802 * Sources are listed lazily on open: detection touches the other browser's
803 * files, and the answer changes while the app is running (quitting the browser
804 * clears `browserRunning`), so a value cached at mount would go stale.
805 */
806function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) {
807 const userProfiles = useClientSettings((settings) => settings.browserProfiles);
808 const defaultProfileId = useClientSettings((settings) => settings.browserDefaultProfileId);
809 const settingsHydrated = useClientSettingsHydrated();
810 const updateSettings = useUpdatePrimarySettings();
811 const { environments, isReady: environmentsReady } = useEnvironments();
812 const primaryEnvironment = usePrimaryEnvironment();
813 const [sources, setSources] = useState<ReadonlyArray<BrowserImportSource> | null>(null);
814 const [importSession, setImportSession] = useState<{
815 readonly source: BrowserImportSource;
816 readonly environmentId: EnvironmentId;
817 readonly environmentName: string;
818 } | null>(null);
819 const [profilePendingRemoval, setProfilePendingRemoval] = useState<BrowserProfile | null>(null);
820 const [profileRemovalError, setProfileRemovalError] = useState<string | null>(null);
821 const [profileRemovalInFlight, setProfileRemovalInFlight] = useState(false);
822 const removalAvailable = browserProfileRemovalAvailable(
823 previewBridge !== null,
824 environmentsReady,
825 environments.length,
826 );
827 const importInFlightRef = useRef(false);
828 const [importInFlight, setImportInFlight] = useState(false);
829 const profileWritesDisabled = disabled || !settingsHydrated;
830
831 const profiles = resolveBrowserProfiles(userProfiles);
832 // Incognito is deliberately not a row — it holds nothing to manage — so the
833 // default has to resolve against the list that renders. A stored
834 // `browserDefaultProfileId` of "incognito" would otherwise leave the section
835 // with no Default badge at all.
836 const listedProfiles = profiles.filter((profile) => profile.kind !== "incognito");
837 const resolvedDefaultId =
838 findBrowserProfile(listedProfiles, defaultProfileId)?.id ?? DEFAULT_BROWSER_PROFILE_ID;
839
840 const createProfile = (baseName: string) => {
841 if (!settingsHydrated || importInFlightRef.current) return undefined;
842 const currentProfiles = getClientSettings().browserProfiles;
843 // Checked against the live settings, not the rendered list: two clicks
844 // before a re-render would otherwise both pass the disabled control.
845 if (currentProfiles.length >= BROWSER_PROFILE_MAX_COUNT) return undefined;
846 const resolvedProfiles = resolveBrowserProfiles(currentProfiles);
847 const taken = new Set(resolvedProfiles.map((profile) => profile.name));
848 let name = baseName;
849 for (let index = 2; taken.has(name); index += 1) name = `${baseName} ${index}`;
850 const profile = { id: `profile-${randomUUID()}`, name, kind: "persistent" as const };
851 updateSettings({ browserProfiles: [...currentProfiles, profile] });
852 return profile;
853 };
854
855 const renameProfile = (id: string, next: string) => {
856 if (!settingsHydrated || importInFlightRef.current) return;
857 const name = next.trim().slice(0, BROWSER_PROFILE_NAME_MAX_LENGTH);
858 if (name === "") return;
859 const currentProfiles = getClientSettings().browserProfiles;
860 updateSettings({
861 browserProfiles: currentProfiles.map((profile) =>
862 profile.id === id ? { ...profile, name } : profile,
863 ),
864 });
865 };
866
867 const clearProfileData = (id: string, name: string) => {
868 if (!settingsHydrated || importInFlightRef.current) return;
869 if (!previewBridge || !environmentsReady || environments.length === 0) {
870 toastManager.add({
871 type: "error",
872 title: `Could not clear ${name}'s data`,
873 description: "You're not connected to a server yet.",
874 });
875 return;
876 }
877 void clearBrowserProfileData(
878 previewBridge,
879 environments.map((environment) => environment.environmentId),
880 id,
881 )
882 .then(() => {
883 toastManager.add({ type: "success", title: `Cleared ${name}'s cookies and cache` });
884 })
885 .catch(() => {
886 toastManager.add({ type: "error", title: `Could not clear ${name}'s data` });
887 });
888 };
889
890 const removeProfile = async (id: string) => {
891 if (!settingsHydrated || importInFlightRef.current) return;
892 if (!removalAvailable) {
893 setProfileRemovalError("Connect to an environment before removing this profile.");
894 return;
895 }
896 setProfileRemovalError(null);
897 setProfileRemovalInFlight(true);
898 // Drop the partition's data too, otherwise a removed profile's cookies
899 // stay on disk with nothing in the UI pointing at them.
900 try {
901 await clearBrowserProfileData(
902 previewBridge,
903 environmentsReady ? environments.map((environment) => environment.environmentId) : [],
904 id,
905 );
906 } catch {
907 setProfileRemovalError("Profile data could not be deleted. Try again.");
908 setProfileRemovalInFlight(false);
909 return;
910 }
911 const currentSettings = getClientSettings();
912 updateSettings({
913 browserProfiles: currentSettings.browserProfiles.filter((profile) => profile.id !== id),
914 // Reassign the default rather than leaving it pointing at nothing.
915 ...(currentSettings.browserDefaultProfileId === id
916 ? { browserDefaultProfileId: DEFAULT_BROWSER_PROFILE_ID }
917 : {}),
918 });
919 setProfileRemovalInFlight(false);
920 setProfilePendingRemoval(null);
921 };
922
923 // A browser that is not on this machine is left out rather than listed as a
924 // dead row: there is nothing to act on, and the menu is a list of things you
925 // can import from. An unsupported one is left out for the same reason — the
926 // blocked wizard step can't be fixed from here. Every other unavailable
927 // reason stays, since each names a step the user can take.
928 const importableSources = (sources ?? []).filter(
929 (source) =>
930 source.unavailable !== "notInstalled" && source.unavailable !== "unsupportedPlatform",
931 );
932
933 // Refreshed without blanking the last result: the menu shows the cached list
934 // straight away so it doesn't reflow on open, and the source list is stable
935 // (names only) since choosing what to import happens in the wizard, not here.
936 const loadSources = useCallback(() => {
937 if (!previewBridge) return;
938 void previewBridge
939 .listBrowserImportSources()
940 .then(setSources)
941 .catch(() => setSources((previous) => previous ?? []));
942 }, []);
943
944 // Runs one import for the wizard. A new profile is registered only once the
945 // import succeeds — the cookies land in its partition first — so a blocked
946 // attempt never leaves an empty profile behind.
947 const runWizardImport = async (
948 source: BrowserImportSource,
949 environmentId: EnvironmentId,
950 input: { readonly sourceProfileDirectory: string; readonly target: WizardTarget },
951 ): Promise<ImportOutcome> => {
952 if (!previewBridge) return { kind: "blocked", reason: "sessionUnavailable" };
953 if (!settingsHydrated) return { kind: "blocked", reason: "sessionUnavailable" };
954 if (
955 input.target.kind === "existing" &&
956 !resolveBrowserProfiles(getClientSettings().browserProfiles).some(
957 (profile) => profile.id === input.target.profileId,
958 )
959 ) {
960 return { kind: "blocked", reason: "readFailed" };
961 }
962 if (importInFlightRef.current) return { kind: "blocked", reason: "readFailed" };
963 importInFlightRef.current = true;
964 setImportInFlight(true);
965 try {
966 const result = await previewBridge.importBrowserCookies({
967 environmentId,
968 sourceId: source.id,
969 sourceProfileDirectory: input.sourceProfileDirectory,
970 targetProfileId: input.target.profileId,
971 });
972 if (
973 input.target.kind === "existing" &&
974 !resolveBrowserProfiles(getClientSettings().browserProfiles).some(
975 (profile) => profile.id === input.target.profileId,
976 )
977 ) {
978 return { kind: "blocked", reason: "readFailed" };
979 }
980 let targetName: string;
981 if (input.target.kind === "new") {
982 // Registered only when something actually came over: an import that
983 // found no cookies should not leave a new, empty profile behind.
984 if (result.imported > 0) {
985 try {
986 const persisted = await persistClientSettingsUpdate((current) => {
987 const existing = current.browserProfiles.find(
988 (profile) => profile.id === input.target.profileId,
989 );
990 if (existing) return current;
991 // The wizard refuses a new target at the cap, but the cap can be
992 // reached while the import runs; the updater sees the newest
993 // settings, so this is the check that holds.
994 if (current.browserProfiles.length >= BROWSER_PROFILE_MAX_COUNT) {
995 throw new ProfileLimitReachedError();
996 }
997 const taken = new Set(
998 resolveBrowserProfiles(current.browserProfiles).map((profile) => profile.name),
999 );
1000 let name = source.name;
1001 for (let index = 2; taken.has(name); index += 1) name = `${source.name} ${index}`;
1002 return {
1003 ...current,
1004 browserProfiles: [
1005 ...current.browserProfiles,
1006 { id: input.target.profileId, name, kind: "persistent" as const },
1007 ],
1008 };
1009 });
1010 targetName =
1011 persisted.browserProfiles.find((profile) => profile.id === input.target.profileId)
1012 ?.name ?? source.name;
1013 } catch (cause) {
1014 // This target id belongs only to the attempted new profile. Clear
1015 // its partition so a failed registration cannot strand imported
1016 // cookies behind a profile that disappears on restart.
1017 await clearBrowserProfileData(
1018 previewBridge,
1019 [environmentId],
1020 input.target.profileId,
1021 ).catch(() => undefined);
1022 // Not a read failure: the cookies came over and were cleared again
1023 // because the profile could not be kept. Name that, in the same
1024 // token form `importFailureReason` recovers from a bridge error.
1025 const reason =
1026 cause instanceof ProfileLimitReachedError ? "profileLimitReached" : "profileNotSaved";
1027 throw new Error(`Importing cookies from ${source.id} failed: ${reason}.`, { cause });
1028 }
1029 } else {
1030 targetName = source.name;
1031 }
1032 } else {
1033 targetName = input.target.name;
1034 }
1035 return {
1036 kind: "imported",
1037 imported: result.imported,
1038 skipped: result.skipped,
1039 skippedDomains: result.skippedDomains,
1040 targetName,
1041 };
1042 } catch (cause) {
1043 return { kind: "blocked", reason: importFailureReason(cause) };
1044 } finally {
1045 importInFlightRef.current = false;
1046 setImportInFlight(false);
1047 }
1048 };
1049
1050 // Re-checks a source's availability after the user quits the browser, and
1051 // keeps the cached list in step so the menu reflects it too.
1052 const refreshImportSource = async (
1053 sourceId: BrowserImportSource["id"],
1054 ): Promise<BrowserImportSource | undefined> => {
1055 if (!previewBridge) return undefined;
1056 try {
1057 const latest = await previewBridge.listBrowserImportSources();
1058 setSources(latest);
1059 return latest.find((source) => source.id === sourceId);
1060 } catch {
1061 return undefined;
1062 }
1063 };
1064
1065 const atProfileLimit = userProfiles.length >= BROWSER_PROFILE_MAX_COUNT;
1066
1067 return (
1068 <SettingsRow
1069 {...searchableSetting("browser-profiles")}
1070 description="Profiles separate cookies and logins. Incognito data is cleared when the app closes."
1071 control={
1072 <Menu onOpenChange={(open) => open && loadSources()}>
1073 <MenuTrigger
1074 render={
1075 <Button
1076 size="sm"
1077 variant="outline"
1078 disabled={profileWritesDisabled || importInFlight}
1079 />
1080 }
1081 >
1082 <PlusIcon />
1083 Add profile
1084 </MenuTrigger>
1085 <MenuPopup align="end" className="min-w-56">
1086 <MenuItem
1087 disabled={!settingsHydrated || atProfileLimit}
1088 onClick={() => createProfile("New profile")}
1089 >
1090 Blank profile
1091 </MenuItem>
1092 {atProfileLimit ? (
1093 <MenuItem disabled>You’ve reached the profile limit</MenuItem>
1094 ) : null}
1095 <MenuSeparator />
1096 <MenuGroup>
1097 <MenuGroupLabel>Import from</MenuGroupLabel>
1098 {sources === null ? (
1099 <MenuItem disabled>Looking for browsers…</MenuItem>
1100 ) : importableSources.length === 0 ? (
1101 <MenuItem disabled>No supported browsers found</MenuItem>
1102 ) : (
1103 // Every source is a plain row — running, needs-permission and
1104 // ready all look the same here. The wizard picks up whatever
1105 // state the source is in and walks the user forward from there.
1106 <>
1107 {importableSources.map((source) => (
1108 <MenuItem
1109 key={source.id}
1110 disabled={!settingsHydrated || primaryEnvironment == null}
1111 onClick={() => {
1112 if (!settingsHydrated || primaryEnvironment == null) return;
1113 setImportSession({
1114 source,
1115 environmentId: primaryEnvironment.environmentId,
1116 environmentName: resolveEnvironmentOptionLabel({
1117 isPrimary: true,
1118 environmentId: primaryEnvironment.environmentId,
1119 runtimeLabel: primaryEnvironment.label,
1120 }),
1121 });
1122 }}
1123 >
1124 {source.name}
1125 </MenuItem>
1126 ))}
1127 {primaryEnvironment == null ? (
1128 <MenuItem disabled>Connect to an environment to import cookies</MenuItem>
1129 ) : null}
1130 </>
1131 )}
1132 </MenuGroup>
1133 </MenuPopup>
1134 </Menu>
1135 }
1136 >
1137 {/*
1138 The bordered container groups rows unambiguously at any width, and
1139 carries the bottom spacing `SettingsRow` leaves to its children
1140 (`pt-3 pb-1`).
1141 */}
1142 <div className="mt-2 mb-2 overflow-hidden rounded-lg border border-border/60">
1143 {listedProfiles.map((profile, index) => {
1144 const builtIn = isBuiltInBrowserProfileId(profile.id);
1145 const isDefault = profile.id === resolvedDefaultId;
1146 return (
1147 <div
1148 key={profile.id}
1149 className={cn(
1150 "flex items-center gap-3 px-3 py-2",
1151 index > 0 && "border-t border-border/60",
1152 )}
1153 >
1154 <span className="flex min-w-0 flex-1 items-center gap-2">
1155 {builtIn ? (
1156 // Dimmed here rather than on the table: a wrapper-level dim
1157 // stacks with the rename field's and the row menu button's
1158 // own, landing them near 0.41 while every other disabled
1159 // control in the block sits at 0.64.
1160 <span
1161 className={cn(
1162 "truncate text-sm text-foreground",
1163 profileWritesDisabled && "opacity-64",
1164 )}
1165 >
1166 {profile.name}
1167 </span>
1168 ) : (
1169 <DraftInput
1170 nativeInput
1171 size="sm"
1172 className="w-full max-w-56"
1173 aria-label={`Rename ${profile.name}`}
1174 disabled={profileWritesDisabled || importInFlight}
1175 maxLength={BROWSER_PROFILE_NAME_MAX_LENGTH}
1176 value={profile.name}
1177 onCommit={(next) => renameProfile(profile.id, next)}
1178 />
1179 )}
1180 {/*
1181 Dimmed with the rest of the row: a `Badge` has no disabled
1182 treatment of its own, so a solid `bg-primary` pill would
1183 otherwise sit at full strength beside a name, rename field
1184 and menu button that are all at 0.64.
1185 */}
1186 {isDefault ? (
1187 <Badge className={cn(profileWritesDisabled && "opacity-64")}>Default</Badge>
1188 ) : null}
1189 </span>
1190 <Menu>
1191 <MenuTrigger
1192 render={
1193 <Button
1194 size="icon-xs"
1195 variant="ghost-muted"
1196 disabled={profileWritesDisabled || importInFlight}
1197 aria-label={`${profile.name} options`}
1198 />
1199 }
1200 >
1201 <MoreVertical />
1202 </MenuTrigger>
1203 <MenuPopup align="end" className="min-w-44">
1204 <MenuItem
1205 disabled={!settingsHydrated || isDefault}
1206 onClick={() => {
1207 if (settingsHydrated) {
1208 updateSettings({ browserDefaultProfileId: profile.id });
1209 }
1210 }}
1211 >
1212 Set as default
1213 </MenuItem>
1214 <MenuItem
1215 disabled={!settingsHydrated || !removalAvailable}
1216 onClick={() => clearProfileData(profile.id, profile.name)}
1217 >
1218 Clear cookies and cache
1219 </MenuItem>
1220 {builtIn ? null : (
1221 <MenuItem
1222 variant="destructive"
1223 disabled={!settingsHydrated || !removalAvailable}
1224 onClick={() => {
1225 if (settingsHydrated) setProfilePendingRemoval(profile);
1226 }}
1227 >
1228 Remove profile and data
1229 </MenuItem>
1230 )}
1231 {!removalAvailable ? (
1232 <>
1233 <MenuSeparator />
1234 <MenuItem disabled>
1235 {environmentsReady
1236 ? "Connect to an environment to clear profile data"
1237 : "Checking environments…"}
1238 </MenuItem>
1239 </>
1240 ) : null}
1241 </MenuPopup>
1242 </Menu>
1243 </div>
1244 );
1245 })}
1246 </div>
1247 <AlertDialog
1248 open={profilePendingRemoval !== null}
1249 onOpenChange={(open) => {
1250 if (!open && !profileRemovalInFlight) {
1251 setProfilePendingRemoval(null);
1252 setProfileRemovalError(null);
1253 }
1254 }}
1255 >
1256 <AlertDialogPopup>
1257 <AlertDialogHeader>
1258 <AlertDialogTitle>Remove “{profilePendingRemoval?.name}”?</AlertDialogTitle>
1259 <AlertDialogDescription>
1260 Its cookies and logins are deleted. Tabs already open in this profile stay open until
1261 you close them.
1262 </AlertDialogDescription>
1263 {profileRemovalError ? (
1264 <p aria-live="polite" className="text-sm text-destructive">
1265 {profileRemovalError}
1266 </p>
1267 ) : null}
1268 {!removalAvailable ? (
1269 <p className="text-sm text-muted-foreground">
1270 Connect to an environment to remove this profile and its data.
1271 </p>
1272 ) : null}
1273 </AlertDialogHeader>
1274 <AlertDialogFooter>
1275 <AlertDialogClose
1276 disabled={profileRemovalInFlight}
1277 render={<Button variant="outline" disabled={profileRemovalInFlight} />}
1278 >
1279 Cancel
1280 </AlertDialogClose>
1281 <Button
1282 variant="destructive"
1283 disabled={profileRemovalInFlight || !settingsHydrated || !removalAvailable}
1284 onClick={() => {
1285 if (profilePendingRemoval && settingsHydrated && removalAvailable) {
1286 void removeProfile(profilePendingRemoval.id);
1287 }
1288 }}
1289 >
1290 {profileRemovalInFlight ? "Removing…" : "Remove profile"}
1291 </Button>
1292 </AlertDialogFooter>
1293 </AlertDialogPopup>
1294 </AlertDialog>
1295 {importSession ? (
1296 <BrowserImportWizard
1297 source={importSession.source}
1298 destinationEnvironmentName={importSession.environmentName}
1299 targetProfiles={listedProfiles.map((profile) => ({ id: profile.id, name: profile.name }))}
1300 canCreateProfile={settingsHydrated && !atProfileLimit}
1301 onImport={(input) =>
1302 runWizardImport(importSession.source, importSession.environmentId, input)
1303 }
1304 onRefreshSource={() => refreshImportSource(importSession.source.id)}
1305 onOpenFullDiskAccessSettings={() => {
1306 // Rejects outside the desktop shell (and on shells that predate the
1307 // method), so the one toast covers every way the link can fail.
1308 void readLocalApi()
1309 ?.shell.openSystemSettings("full-disk-access")
1310 .catch(() => {
1311 toastManager.add({
1312 type: "error",
1313 title: "Could not open System Settings",
1314 description: "Open Privacy & Security → Full Disk Access manually.",
1315 });
1316 });
1317 }}
1318 onClose={() => setImportSession(null)}
1319 />
1320 ) : null}
1321 </SettingsRow>
1322 );
1323}
1324
1325export function IntegrationsSettingsPanel() {
1326 // Client-local preview defaults are editable only where the preview exists.
1327 const previewDefaultsDisabled = !isElectron;
1328 const previewDefaults = (
1329 <>
1330 <BrowserProfilesSetting disabled={previewDefaultsDisabled} />
1331 <BrowserViewportSetting disabled={previewDefaultsDisabled} />
1332 <BrowserZoomSetting disabled={previewDefaultsDisabled} />
1333 <BrowserAppearanceSetting disabled={previewDefaultsDisabled} />
1334 <BrowserRecordingFrameRateSetting disabled={previewDefaultsDisabled} />
1335 <BrowserLinkTargetSetting disabled={previewDefaultsDisabled} />
1336 <BrowserAutoShowFloatingPreviewSetting disabled={previewDefaultsDisabled} />
1337 </>
1338 );
1339
1340 return (
1341 <SettingsPageContainer>
1342 <SettingsSection id="browser" title="Browser">
1343 {/* Server-authoritative, so it stays editable on any client anchored to
1344 a server; `serverScoped` covers the hosted app, which has none. It
1345 sits outside the block covering the desktop-only defaults. */}
1346 <AgentBrowserAccessSetting />
1347 {previewDefaultsDisabled ? (
1348 <SettingsUnavailableGroup message="Only available in the desktop app.">
1349 {previewDefaults}
1350 </SettingsUnavailableGroup>
1351 ) : (
1352 previewDefaults
1353 )}
1354 </SettingsSection>
1355 <DeviceIntegrationSettings />
1356 </SettingsPageContainer>
1357 );
1358}