Skip to content

Commit 78f588a

Browse files
fix(web): agent browsers open as a right-panel tab when floating previews are off
1 parent 4642660 commit 78f588a

5 files changed

Lines changed: 75 additions & 16 deletions

File tree

‎apps/web/src/components/preview/agentOpenedPreviews.test.ts‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,44 @@ describe("revealServerTabs", () => {
212212
return source?.kind === "browser" ? source.tabId : null;
213213
};
214214

215-
it("floats revealed tabs, and only forced ones when floating previews are off", () => {
215+
const panelBrowserTabs = () =>
216+
useRightPanelStore
217+
.getState()
218+
.byThreadKey[threadKey]?.surfaces.filter((surface) => surface.kind === "preview")
219+
.map((surface) => surface.resourceId) ?? [];
220+
221+
it("floats revealed tabs when floating previews are on", () => {
222+
setup();
223+
revealServerTabs(ref, [tab("tab_plain")], {
224+
autoShowFloatingPreview: true,
225+
sheetLayout: false,
226+
});
227+
expect(floatingTabId()).toBe("tab_plain");
228+
expect(panelBrowserTabs()).toEqual([]);
229+
});
230+
231+
it("opens revealed tabs as panel tabs when floating previews are off", () => {
216232
setup();
217-
revealServerTabs(ref, [tab("tab_plain")], { autoShowFloatingPreview: false });
233+
revealServerTabs(ref, [tab("tab_plain")], {
234+
autoShowFloatingPreview: false,
235+
sheetLayout: false,
236+
});
218237
expect(floatingTabId()).toBeNull();
219-
revealServerTabs(ref, [tab("tab_forced", true)], { autoShowFloatingPreview: false });
238+
expect(panelBrowserTabs()).toEqual(["tab_plain"]);
239+
});
240+
241+
it("in a sheet, floats only forced reveals when floating previews are off", () => {
242+
setup();
243+
revealServerTabs(ref, [tab("tab_plain")], {
244+
autoShowFloatingPreview: false,
245+
sheetLayout: true,
246+
});
247+
expect(floatingTabId()).toBeNull();
248+
expect(panelBrowserTabs()).toEqual([]);
249+
revealServerTabs(ref, [tab("tab_forced", true)], {
250+
autoShowFloatingPreview: false,
251+
sheetLayout: true,
252+
});
220253
expect(floatingTabId()).toBe("tab_forced");
221254
});
222255

@@ -226,11 +259,17 @@ describe("revealServerTabs", () => {
226259
const browserSurfaceId = useRightPanelStore.getState().byThreadKey[threadKey]?.activeSurfaceId;
227260
useRightPanelStore.getState().open(ref, "diff");
228261

229-
revealServerTabs(ref, [tab("tab_a", false)], { autoShowFloatingPreview: true });
262+
revealServerTabs(ref, [tab("tab_a", false)], {
263+
autoShowFloatingPreview: true,
264+
sheetLayout: false,
265+
});
230266
expect(useRightPanelStore.getState().byThreadKey[threadKey]?.activeSurfaceId).not.toBe(
231267
browserSurfaceId,
232268
);
233-
revealServerTabs(ref, [tab("tab_a", true)], { autoShowFloatingPreview: true });
269+
revealServerTabs(ref, [tab("tab_a", true)], {
270+
autoShowFloatingPreview: true,
271+
sheetLayout: false,
272+
});
234273
expect(useRightPanelStore.getState().byThreadKey[threadKey]?.activeSurfaceId).toBe(
235274
browserSurfaceId,
236275
);
@@ -296,7 +335,14 @@ describe("startAgentOpenedPreviews", () => {
296335
});
297336
const following = () => {
298337
setup();
299-
return { [Symbol.dispose]: startAgentOpenedPreviews() };
338+
vi.stubGlobal("window", { matchMedia: () => ({ matches: false }) });
339+
const stop = startAgentOpenedPreviews();
340+
return {
341+
[Symbol.dispose]: () => {
342+
stop();
343+
vi.unstubAllGlobals();
344+
},
345+
};
300346
};
301347
const navigated = (revision: number, snapshot: PreviewSessionSnapshot) =>
302348
applyPreviewServerEvent(ref, {

‎apps/web/src/components/preview/agentOpenedPreviews.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,29 @@ import { environmentSummaries } from "../../state/presentation";
3333

3434
/**
3535
* Shows browsers an agent or another client revealed for a thread: floating
36-
* over chat, or focusing an existing panel tab when the reveal is forced.
36+
* over chat, as a panel tab when floating previews are off, or focusing an
37+
* existing panel tab when the reveal is forced. A sheet has no panel to open
38+
* into, so a forced reveal still floats there.
3739
*/
3840
export function revealServerTabs(
3941
threadRef: ScopedThreadRef,
4042
sessions: ReadonlyArray<PreviewSessionSnapshot>,
41-
options: { readonly autoShowFloatingPreview: boolean },
43+
options: { readonly autoShowFloatingPreview: boolean; readonly sheetLayout: boolean },
4244
): void {
4345
if (!readEnvironmentSupportsServerBrowser(threadRef.environmentId)) return;
4446
for (const session of sessions) {
4547
const force = session.revealRequest?.force === true;
46-
if (!options.autoShowFloatingPreview && !force) continue;
4748
const surface = useRightPanelStore
4849
.getState()
4950
.byThreadKey[scopedThreadKey(threadRef)]?.surfaces.find(
5051
(surface) => surface.kind === "preview" && surface.resourceId === session.tabId,
5152
);
52-
if (surface && force) {
53-
useRightPanelStore.getState().activateSurface(threadRef, surface.id);
54-
} else if (!surface) {
53+
if (surface) {
54+
if (force) useRightPanelStore.getState().activateSurface(threadRef, surface.id);
55+
} else if (options.autoShowFloatingPreview || (options.sheetLayout && force)) {
5556
usePreviewMiniPlayerStore.getState().open(threadRef, browserMiniPlayerSource(session.tabId));
57+
} else if (!options.sheetLayout) {
58+
useRightPanelStore.getState().openBrowser(threadRef, session.tabId, true);
5659
}
5760
}
5861
}
@@ -110,6 +113,7 @@ function followThread(threadKey: string, threadRef: ScopedThreadRef): () => void
110113
if (revealed.length > 0) {
111114
revealServerTabs(threadRef, revealed, {
112115
autoShowFloatingPreview: getClientSettings().browserAutoShowFloatingPreview,
116+
sheetLayout: window.matchMedia(RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY).matches,
113117
});
114118
}
115119
if (before.sessions !== next.sessions || before.listLoaded !== next.listLoaded) {

‎apps/web/src/components/settings/IntegrationsSettings.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled
11101110
return (
11111111
<SettingsRow
11121112
{...searchableSetting("browser-auto-show-floating-preview")}
1113-
description="Show the floating preview when an agent opens a browser or device unless the agent says otherwise."
1113+
description="Show the floating preview when an agent opens a browser or device unless the agent says otherwise. When off, it opens as a right-panel tab."
11141114
resetAction={
11151115
!disabled && autoShow !== DEFAULT_BROWSER_AUTO_SHOW_FLOATING_PREVIEW ? (
11161116
<SettingResetButton

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ describe("rightPanelStore", () => {
301301
});
302302
});
303303

304+
it("still opens proactive panels after an agent's browser opens automatically", () => {
305+
const store = useRightPanelStore.getState();
306+
const revision = store.getUserActionRevision(refA);
307+
store.openBrowser(refA, "agent-browser", true);
308+
309+
expect(store.openProactive(refA, completedDiff, revision)).toBe(true);
310+
expect(store.openProactive(refA, linkedPullRequest, revision)).toBe(true);
311+
});
312+
304313
it.each([
305314
{
306315
surface: linkedPullRequest,

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ interface RightPanelStoreState {
124124
) => void;
125125
openDevice: (ref: ScopedThreadRef, target: DeviceTabTarget, automatic?: boolean) => void;
126126
renameDevice: (ref: ScopedThreadRef, surfaceId: string, title: string) => void;
127-
openBrowser: (ref: ScopedThreadRef, tabId: string | null) => void;
127+
openBrowser: (ref: ScopedThreadRef, tabId: string | null, automatic?: boolean) => void;
128128
openFile: (ref: ScopedThreadRef, relativePath: string, line?: number) => void;
129129
/** Moves in place; "" opens the root explorer. folderTrail keeps the return path; keepSource opens beside the source. */
130130
navigateFolder: (
@@ -682,9 +682,9 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
682682
),
683683
})),
684684
),
685-
openBrowser: (ref, tabId) =>
685+
openBrowser: (ref, tabId, automatic = false) =>
686686
set((state) =>
687-
userAction(state, scopedThreadKey(ref), (current) => {
687+
(automatic ? automaticUpdate : userAction)(state, scopedThreadKey(ref), (current) => {
688688
const surface = browserSurface(tabId);
689689
const withoutPlaceholder = tabId
690690
? current.surfaces.filter((entry) => entry.id !== "browser:new")

0 commit comments

Comments
 (0)