Skip to content

The agent that grows with you

refactor(desktop): drop openPreview's unused source argument

yoniebans9b68399138ba
diff --git a/apps/desktop/src/app/chat/close-tab.test.ts b/apps/desktop/src/app/chat/close-tab.test.ts
index e8b102396be..08c5c35a891 100644
--- a/apps/desktop/src/app/chat/close-tab.test.ts
+++ b/apps/desktop/src/app/chat/close-tab.test.ts
@@ -74,7 +74,7 @@ describe('closeActiveTab', () => {
// pane's registered closer) rather than a rail-shaped special case. Open
// previews must therefore NOT claim the key on their own.
it('leaves ⌘W to the zone rungs even with previews open', () => {
- openPreview(fileTarget('/work/notes.md'), 'manual')
+ openPreview(fileTarget('/work/notes.md'))
closeFocusedToolTab.mockReturnValue(true)
expect($previewTabs.get()).toHaveLength(1)
diff --git a/apps/desktop/src/app/chat/composer/attachments.tsx b/apps/desktop/src/app/chat/composer/attachments.tsx
index 00063f39954..f9582a1256a 100644
--- a/apps/desktop/src/app/chat/composer/attachments.tsx
+++ b/apps/desktop/src/app/chat/composer/attachments.tsx
@@ -133,7 +133,7 @@ function AttachmentPill({ attachment, onRemove }: { attachment: ComposerAttachme
throw new Error(c.couldNotPreview(attachment.label))
}
- openPreview(preview, 'manual')
+ openPreview(preview)
} catch (error) {
notifyError(error, c.previewUnavailable)
}
diff --git a/apps/desktop/src/app/chat/composer/status-stack/preview-row.tsx b/apps/desktop/src/app/chat/composer/status-stack/preview-row.tsx
index 506801da44b..510d0f534c2 100644
--- a/apps/desktop/src/app/chat/composer/status-stack/preview-row.tsx
+++ b/apps/desktop/src/app/chat/composer/status-stack/preview-row.tsx
@@ -49,7 +49,7 @@ export const PreviewStatusRow = memo(function PreviewStatusRow({ item, onDismiss
setOpening(true)
try {
- openPreview(await resolveTarget(), 'tool-result')
+ openPreview(await resolveTarget())
} catch (error) {
notifyError(error, t.preview.unavailable)
} finally {
@@ -68,7 +68,7 @@ export const PreviewStatusRow = memo(function PreviewStatusRow({ item, onDismiss
// (Remote HTML stays on openPreviewTargetInBrowser, which stages a
// sanitized local copy before opening it.)
if (target.kind === 'file' && target.previewKind !== 'html' && isDesktopFsRemoteMode()) {
- openPreview(target, 'tool-result')
+ openPreview(target)
return
}
diff --git a/apps/desktop/src/app/chat/preview-tile.test.ts b/apps/desktop/src/app/chat/preview-tile.test.ts
index 62d1861e3fc..eac79de3bba 100644
--- a/apps/desktop/src/app/chat/preview-tile.test.ts
+++ b/apps/desktop/src/app/chat/preview-tile.test.ts
@@ -51,7 +51,7 @@ describe('browserTabLabel', () => {
describe('browserTabExternalUrl', () => {
const openBrowser = (url: string) => {
- openPreview({ kind: 'url', label: 'Browser', source: url, url }, 'explicit-link')
+ openPreview({ kind: 'url', label: 'Browser', source: url, url })
return $previewTabs.get().find(tab => tab.target.kind === 'url')!.id
}
@@ -73,7 +73,7 @@ describe('browserTabExternalUrl', () => {
})
it('is null for a file peek', () => {
- openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
+ openPreview(fileTarget('/tmp/a.ts'))
expect(browserTabExternalUrl('file:/tmp/a.ts')).toBeNull()
})
@@ -97,11 +97,8 @@ const fileTarget = (path: string) =>
// just be declared on the tile.
describe('preview tiles keep a live page alive across Hide', () => {
it('registers a Browser tab with lifecycleKeepAlive while a text peek stays evictable', () => {
- openPreview(
- { kind: 'url', label: 'Browser', source: 'https://example.com', url: 'https://example.com' },
- 'explicit-link'
- )
- openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
+ openPreview({ kind: 'url', label: 'Browser', source: 'https://example.com', url: 'https://example.com' })
+ openPreview(fileTarget('/tmp/a.ts'))
const browserId = $previewTabs.get().find(tab => tab.target.kind === 'url')!.id
@@ -112,13 +109,13 @@ describe('preview tiles keep a live page alive across Hide', () => {
describe('preview tiles stack, not split (#93610)', () => {
it('docks the first preview right and stacks the second as a center tab in the same zone', () => {
- openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
+ openPreview(fileTarget('/tmp/a.ts'))
const first = dockOf('preview-tile:file:/tmp/a.ts')
expect(first?.pos).toBe('right')
- openPreview(fileTarget('/tmp/b.ts'), 'file-browser')
+ openPreview(fileTarget('/tmp/b.ts'))
const second = dockOf('preview-tile:file:/tmp/b.ts')
@@ -130,8 +127,8 @@ describe('preview tiles stack, not split (#93610)', () => {
})
it('stacks an artifact opened after a file into the same preview zone', () => {
- openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
- openPreview({ kind: 'artifact', label: 'Chart', source: 'artifact-1', url: 'artifact-1' }, 'explicit-link')
+ openPreview(fileTarget('/tmp/a.ts'))
+ openPreview({ kind: 'artifact', label: 'Chart', source: 'artifact-1', url: 'artifact-1' })
const artifact = dockOf('preview-tile:artifact:artifact-1')
@@ -140,11 +137,11 @@ describe('preview tiles stack, not split (#93610)', () => {
})
it('lets a lone preview open its own right-docked zone again after all tabs closed', () => {
- openPreview(fileTarget('/tmp/a.ts'), 'file-browser')
- openPreview(fileTarget('/tmp/b.ts'), 'file-browser')
+ openPreview(fileTarget('/tmp/a.ts'))
+ openPreview(fileTarget('/tmp/b.ts'))
closeRightRail()
- openPreview(fileTarget('/tmp/c.ts'), 'file-browser')
+ openPreview(fileTarget('/tmp/c.ts'))
expect(dockOf('preview-tile:file:/tmp/c.ts')?.pos).toBe('right')
})
diff --git a/apps/desktop/src/app/chat/right-rail/preview-act.test.ts b/apps/desktop/src/app/chat/right-rail/preview-act.test.ts
index bd82e2ac179..dcee5341b9f 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-act.test.ts
+++ b/apps/desktop/src/app/chat/right-rail/preview-act.test.ts
@@ -20,7 +20,7 @@ describe('actOnActivePreview (drive_preview tool)', () => {
let cleanups: Array<() => void> = []
const openBrowserTab = () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
return $rightRailActiveTabId.get()!
}
diff --git a/apps/desktop/src/app/chat/right-rail/preview-pane.test.tsx b/apps/desktop/src/app/chat/right-rail/preview-pane.test.tsx
index 1c37163b298..f4b92814b13 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-pane.test.tsx
+++ b/apps/desktop/src/app/chat/right-rail/preview-pane.test.tsx
@@ -793,7 +793,7 @@ describe('PreviewPane local HTML Render|Source toggle', () => {
})
it('defaults a browsed HTML file to Render and toggles Source on the same tab', async () => {
- openPreview(target, 'file-browser')
+ openPreview(target)
const tabId = previewTabId(target)
let rendered!: ReturnType<typeof render>
diff --git a/apps/desktop/src/app/chat/right-rail/preview-reader.test.ts b/apps/desktop/src/app/chat/right-rail/preview-reader.test.ts
index 9e9d6359e26..fce9c41014d 100644
--- a/apps/desktop/src/app/chat/right-rail/preview-reader.test.ts
+++ b/apps/desktop/src/app/chat/right-rail/preview-reader.test.ts
@@ -41,7 +41,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('serializes the Browser tab through its registered page reader', async () => {
- openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
+ openPreview(urlTarget('https://news.ycombinator.com'))
register($rightRailActiveTabId.get()!, async () => ({
text: 'Top stories…',
title: 'Hacker News',
@@ -59,7 +59,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('windows long pages with start/count and reports the full length', async () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
register($rightRailActiveTabId.get()!, async () => ({
text: 'abcdefghij',
title: 't',
@@ -75,7 +75,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('caps a single read at PREVIEW_READ_MAX_CHARS even when asked for more', async () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
register($rightRailActiveTabId.get()!, async () => ({
text: 'x'.repeat(PREVIEW_READ_MAX_CHARS + 5000),
title: 't',
@@ -89,7 +89,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('answers identity + retry note for a Browser tab whose pane is not mounted', async () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
expect(await readActivePreview()).toMatchObject({
kind: 'url',
@@ -100,7 +100,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('answers a file tab with its identity and points at read_file', async () => {
- openPreview(fileTarget('/work/notes.md'), 'file-browser')
+ openPreview(fileTarget('/work/notes.md'))
expect(await readActivePreview()).toMatchObject({
kind: 'file',
@@ -110,15 +110,15 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('reads the tab the user is LOOKING at, not the last one opened', async () => {
- openPreview(fileTarget('/work/one.md'), 'file-browser')
- openPreview(fileTarget('/work/two.md'), 'file-browser')
+ openPreview(fileTarget('/work/one.md'))
+ openPreview(fileTarget('/work/two.md'))
selectRightRailTab('file:file:///work/one.md')
expect(await readActivePreview()).toMatchObject({ path: '/work/one.md' })
})
it('falls back to the identity answer when the reader throws (webview booting)', async () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
register($rightRailActiveTabId.get()!, async () => {
throw new Error('webview gone')
})
@@ -127,7 +127,7 @@ describe('readActivePreview (read_preview tool)', () => {
})
it('unregister is idempotent and scoped to the same reader', async () => {
- openPreview(urlTarget('https://example.com'), 'tool-result')
+ openPreview(urlTarget('https://example.com'))
const tabId = $rightRailActiveTabId.get()!
const first = register(tabId, async () => ({ text: 'first', title: '', url: '' }))
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.tsx b/apps/desktop/src/app/context-menu/app-context-menu.tsx
index 8c4162b816c..d2d813e938b 100644
--- a/apps/desktop/src/app/context-menu/app-context-menu.tsx
+++ b/apps/desktop/src/app/context-menu/app-context-menu.tsx
@@ -201,12 +201,7 @@ function domSections(open: Extract<OpenContextMenu, { kind: 'dom' }>, t: Transla
icon="globe"
key="link-open-app"
label={copy.link.openInApp}
- onSelect={() =>
- openPreview(
- { kind: 'url', label: hostPathLabel(linkUrl), source: linkUrl, url: linkUrl },
- 'explicit-link'
- )
- }
+ onSelect={() => openPreview({ kind: 'url', label: hostPathLabel(linkUrl), source: linkUrl, url: linkUrl })}
/>
) : null,
<Item
@@ -242,10 +237,12 @@ function domSections(open: Extract<OpenContextMenu, { kind: 'dom' }>, t: Transla
key="image-open-app"
label={copy.link.openInApp}
onSelect={() =>
- openPreview(
- { kind: 'url', label: hostPathLabel(target.imageUrl), source: target.imageUrl, url: target.imageUrl },
- 'explicit-link'
- )
+ openPreview({
+ kind: 'url',
+ label: hostPathLabel(target.imageUrl),
+ source: target.imageUrl,
+ url: target.imageUrl
+ })
}
/>
) : null,
@@ -401,12 +398,7 @@ function guestSections(open: Extract<OpenContextMenu, { kind: 'guest' }>, t: Tra
icon="globe"
key="guest-link-open-app"
label={copy.link.openInApp}
- onSelect={() =>
- openPreview(
- { kind: 'url', label: hostPathLabel(linkUrl), source: linkUrl, url: linkUrl },
- 'explicit-link'
- )
- }
+ onSelect={() => openPreview({ kind: 'url', label: hostPathLabel(linkUrl), source: linkUrl, url: linkUrl })}
/>
) : null,
<Item
diff --git a/apps/desktop/src/app/contrib/panes.tsx b/apps/desktop/src/app/contrib/panes.tsx
index bd2b86c5f30..428770b78a9 100644
--- a/apps/desktop/src/app/contrib/panes.tsx
+++ b/apps/desktop/src/app/contrib/panes.tsx
@@ -74,7 +74,7 @@ function previewFile(path: string) {
void normalizeOrLocalPreviewTarget(path, $currentCwd.get() || undefined)
.then(target => {
if (target) {
- openPreview(target, 'file-browser')
+ openPreview(target)
}
})
.catch(() => undefined)
diff --git a/apps/desktop/src/app/right-sidebar/index.tsx b/apps/desktop/src/app/right-sidebar/index.tsx
index aa3ddb261c5..77a7a70aede 100644
--- a/apps/desktop/src/app/right-sidebar/index.tsx
+++ b/apps/desktop/src/app/right-sidebar/index.tsx
@@ -69,7 +69,7 @@ export function RightSidebarPane({ onActivateFile, onActivateFolder }: RightSide
throw new Error(r.couldNotPreview(path))
}
- openPreview(preview, 'file-browser')
+ openPreview(preview)
} catch (error) {
notifyError(error, r.previewUnavailable)
}
diff --git a/apps/desktop/src/app/right-sidebar/review/file-tree.tsx b/apps/desktop/src/app/right-sidebar/review/file-tree.tsx
index 1ae6e21bc66..2821a32b11d 100644
--- a/apps/desktop/src/app/right-sidebar/review/file-tree.tsx
+++ b/apps/desktop/src/app/right-sidebar/review/file-tree.tsx
@@ -361,7 +361,7 @@ function ReviewFileRow({ node, depth }: { node: ReviewTreeNode; depth: number })
const preview = await normalizeOrLocalPreviewTarget(dragPath)
if (preview) {
- openPreview(preview, 'file-browser')
+ openPreview(preview)
}
} catch (error) {
notifyError(error, t.rightSidebar.previewUnavailable)
diff --git a/apps/desktop/src/app/session/hooks/use-preview-routing.ts b/apps/desktop/src/app/session/hooks/use-preview-routing.ts
index ac21a264ddf..854864502b7 100644
--- a/apps/desktop/src/app/session/hooks/use-preview-routing.ts
+++ b/apps/desktop/src/app/session/hooks/use-preview-routing.ts
@@ -100,7 +100,7 @@ export function usePreviewRouting({ baseHandleGatewayEvent, currentCwd, requestG
const url = resolved.kind === 'url' ? await reachablePreviewUrl(resolved.url) : resolved.url
const reached = url === resolved.url ? resolved : { ...resolved, label: resolved.label || target, url }
- openPreview(trimmedLabel ? { ...reached, label: trimmedLabel } : reached, 'tool-result')
+ openPreview(trimmedLabel ? { ...reached, label: trimmedLabel } : reached)
}
)
}
diff --git a/apps/desktop/src/components/assistant-ui/inline-preview-directive.tsx b/apps/desktop/src/components/assistant-ui/inline-preview-directive.tsx
index ac52ba5839b..0005d2c91e5 100644
--- a/apps/desktop/src/components/assistant-ui/inline-preview-directive.tsx
+++ b/apps/desktop/src/components/assistant-ui/inline-preview-directive.tsx
@@ -259,7 +259,7 @@ export function InlinePreviewDirective({
// which fetches over the authenticated /api/fs bridge in remote mode, so a
// URL connection — including a same-machine `hermes serve` — renders live.)
if (!file || !HTML_FILE_RE.test(file)) {
- return file ? <PreviewAttachment source="explicit-link" target={file} /> : null
+ return file ? <PreviewAttachment target={file} /> : null
}
return <InlineHtmlFrame file={file} initialHeight={directiveFrameHeight(attrs.height)} streaming={streaming} />
@@ -382,7 +382,7 @@ function InlineHtmlFrame({
}, [doc, token])
if (!path || failed) {
- return <PreviewAttachment source="explicit-link" target={file} />
+ return <PreviewAttachment target={file} />
}
const height = measured ?? initialHeight ?? DEFAULT_HEIGHT
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
index 62606b61ea8..237750d650e 100644
--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
@@ -269,7 +269,7 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'a
// rendered/source toggle) instead of the download-link fallback that
// `mediaKind() === 'file'` would produce. (#84951)
if (isMarkdownDocumentPath(mediaPath)) {
- return <PreviewAttachment source="tool-result" target={mediaPath} />
+ return <PreviewAttachment target={mediaPath} />
}
// Non-media files (PDFs, data files, anything outside MEDIA_BY_EXT):
@@ -279,7 +279,7 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'a
// branch below produces — so MEDIA: uniformly delivers the richest
// rendering for every file type.
if (mediaKind(mediaPath) === 'file') {
- return <PreviewAttachment source="tool-result" target={mediaPath} />
+ return <PreviewAttachment target={mediaPath} />
}
return <MediaAttachment path={mediaPath} />
@@ -288,7 +288,7 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'a
const previewTarget = previewTargetFromMarkdownHref(href)
if (previewTarget) {
- return <PreviewAttachment source="explicit-link" target={previewTarget} />
+ return <PreviewAttachment target={previewTarget} />
}
const sessionRef = sessionRefFromMarkdownHref(href)
@@ -313,7 +313,7 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'a
if (fileHref) {
return mediaKind(fileHref) === 'file' ? (
- <PreviewAttachment source="explicit-link" target={fileHref} />
+ <PreviewAttachment target={fileHref} />
) : (
<MediaAttachment path={fileHref} />
)
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
index ab43854f549..dfbf763bc8b 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
@@ -427,7 +427,7 @@ const AssistantPreviewEmbeds: FC = () => {
return (
<div className="mt-3 flex flex-wrap gap-2">
{previewTargets.map(target => (
- <PreviewAttachment key={target} source="explicit-link" target={target} />
+ <PreviewAttachment key={target} target={target} />
))}
</div>
)
diff --git a/apps/desktop/src/components/chat/preview-attachment.tsx b/apps/desktop/src/components/chat/preview-attachment.tsx
index a8c2563132f..0146982c24f 100644
--- a/apps/desktop/src/components/chat/preview-attachment.tsx
+++ b/apps/desktop/src/components/chat/preview-attachment.tsx
@@ -8,9 +8,9 @@ import { normalizeOrLocalPreviewTarget } from '@/lib/local-preview'
import { downloadGatewayMediaFile } from '@/lib/media'
import { previewName } from '@/lib/preview-targets'
import { notifyError } from '@/store/notifications'
-import { $previewTabSources, closePreviewForSource, openPreview, type PreviewRecordSource } from '@/store/preview'
+import { $previewTabSources, closePreviewForSource, openPreview } from '@/store/preview'
-export function PreviewAttachment({ source = 'manual', target }: { source?: PreviewRecordSource; target: string }) {
+export function PreviewAttachment({ target }: { target: string }) {
const { t } = useI18n()
// This link lives in one session's transcript; resolve it against THAT
// session's cwd, not the primary chat's.
@@ -78,7 +78,7 @@ export function PreviewAttachment({ source = 'manual', target }: { source?: Prev
throw new Error(`Could not open preview target: ${requestTarget}`)
}
- openPreview(preview, source)
+ openPreview(preview)
} catch (error) {
if (
!mountedRef.current ||
diff --git a/apps/desktop/src/lib/external-link.tsx b/apps/desktop/src/lib/external-link.tsx
index 4635323d3c0..26b0b69de8d 100644
--- a/apps/desktop/src/lib/external-link.tsx
+++ b/apps/desktop/src/lib/external-link.tsx
@@ -269,7 +269,7 @@ export function openLink(href: string, options: { native?: boolean } = {}): void
// link helper drag that whole tree into anything that renders a link. The
// tab lands a microtask later, which is invisible.
void import('@/store/preview').then(({ openPreview }) =>
- openPreview({ kind: 'url', label: hostPathLabel(target), source: target, url: target }, 'explicit-link')
+ openPreview({ kind: 'url', label: hostPathLabel(target), source: target, url: target })
)
}
diff --git a/apps/desktop/src/store/preview.test.ts b/apps/desktop/src/store/preview.test.ts
index 0f0082ad839..626dcc49b1f 100644
--- a/apps/desktop/src/store/preview.test.ts
+++ b/apps/desktop/src/store/preview.test.ts
@@ -58,15 +58,15 @@ describe('preview store', () => {
})
it('opens the pane and fronts the new tab', () => {
- openPreview(fileTarget('/work/demo.html'), 'tool-result')
+ openPreview(fileTarget('/work/demo.html'))
expect($rightRailActiveTabId.get()).toBe('file:file:///work/demo.html')
expect($previewTarget.get()?.path).toBe('/work/demo.html')
})
it('gives every kind of target its own tab, side by side', () => {
- openPreview(fileTarget('/work/demo.html'), 'file-browser')
- openPreview(urlTarget('http://localhost:5174'), 'tool-result')
+ openPreview(fileTarget('/work/demo.html'))
+ openPreview(urlTarget('http://localhost:5174'))
openPreview(artifactTarget('session-1:dashboard'))
expect($previewTabs.get().map(tab => tab.target.kind)).toEqual(['file', 'url', 'artifact'])
@@ -76,8 +76,8 @@ describe('preview store', () => {
// already looking at. New tabs are something you ask for (`newBrowserTab`) —
// otherwise an agent opening five pages leaves five Browsers behind.
it('navigates the open Browser rather than stacking a second one', () => {
- openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
- openPreview(urlTarget('https://www.reddit.com'), 'tool-result')
+ openPreview(urlTarget('https://news.ycombinator.com'))
+ openPreview(urlTarget('https://www.reddit.com'))
const urlTabs = $previewTabs.get().filter(tab => tab.target.kind === 'url')
@@ -87,7 +87,7 @@ describe('preview store', () => {
})
it('commits the live page onto a Browser tab without changing its id', () => {
- openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
+ openPreview(urlTarget('https://news.ycombinator.com'))
const id = $previewTabs.get()[0].id
commitBrowserTabLocation(id, 'https://news.ycombinator.com/item?id=1', 'Item')
@@ -99,9 +99,9 @@ describe('preview store', () => {
})
it('opens more than one Browser on request, each holding its own page', () => {
- openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
+ openPreview(urlTarget('https://news.ycombinator.com'))
newBrowserTab()
- openPreview(urlTarget('https://www.reddit.com'), 'tool-result')
+ openPreview(urlTarget('https://www.reddit.com'))
const urlTabs = $previewTabs.get().filter(tab => tab.target.kind === 'url')
@@ -112,12 +112,12 @@ describe('preview store', () => {
// Which Browser a link lands in: the one on screen. Selecting the older tab
// must send the next page there, not to whichever was opened most recently.
it('navigates the Browser you are looking at', () => {
- openPreview(urlTarget('https://news.ycombinator.com'), 'tool-result')
+ openPreview(urlTarget('https://news.ycombinator.com'))
const first = $previewTabs.get()[0].id
newBrowserTab()
selectRightRailTab(first)
- openPreview(urlTarget('https://www.reddit.com'), 'tool-result')
+ openPreview(urlTarget('https://www.reddit.com'))
expect($previewTabs.get().find(tab => tab.id === first)?.target.url).toBe('https://www.reddit.com')
expect($previewTabs.get()).toHaveLength(2)
@@ -140,8 +140,8 @@ describe('preview store', () => {
})
it('re-fronts an existing tab instead of duplicating it, refreshing its target', () => {
- openPreview({ ...fileTarget('/work/demo.html'), label: 'old' }, 'file-browser')
- openPreview({ ...fileTarget('/work/demo.html'), label: 'new' }, 'file-browser')
+ openPreview({ ...fileTarget('/work/demo.html'), label: 'old' })
+ openPreview({ ...fileTarget('/work/demo.html'), label: 'new' })
expect($previewTabs.get()).toHaveLength(1)
expect($previewTarget.get()?.label).toBe('new')
@@ -150,24 +150,24 @@ describe('preview store', () => {
// Local HTML files default to a live Render, whether opened from the file
// browser or handed over by a tool. Source is an explicit fallback only.
it('renders browsed html and handed-over html live', () => {
- openPreview(fileTarget('/work/browsed.html'), 'file-browser')
+ openPreview(fileTarget('/work/browsed.html'))
expect($previewTarget.get()?.renderMode).toBe('preview')
- openPreview(fileTarget('/work/handed.html'), 'tool-result')
+ openPreview(fileTarget('/work/handed.html'))
expect($previewTarget.get()?.renderMode).toBe('preview')
- openPreview(fileTarget('/work/manual.html'), 'manual')
+ openPreview(fileTarget('/work/manual.html'))
expect($previewTarget.get()?.renderMode).toBe('preview')
})
it('preserves an explicit HTML source fallback from the file browser', () => {
- openPreview({ ...fileTarget('/work/fallback.html'), renderMode: 'source' }, 'file-browser')
+ openPreview({ ...fileTarget('/work/fallback.html'), renderMode: 'source' })
expect($previewTarget.get()?.renderMode).toBe('source')
})
it('switches render mode on the same tab without duplicating it', () => {
- openPreview(fileTarget('/work/toggle.html'), 'file-browser')
+ openPreview(fileTarget('/work/toggle.html'))
const tabId = previewTabId(fileTarget('/work/toggle.html'))
@@ -188,8 +188,8 @@ describe('preview store', () => {
})
it('falls back to a neighbouring tab when the active one closes, and clears the selection on the last', () => {
- openPreview(fileTarget('/work/one.html'), 'file-browser')
- openPreview(fileTarget('/work/two.html'), 'file-browser')
+ openPreview(fileTarget('/work/one.html'))
+ openPreview(fileTarget('/work/two.html'))
closeRightRailTab(previewTabId(fileTarget('/work/two.html')))
@@ -207,7 +207,7 @@ describe('preview store', () => {
})
it('closes by the raw source the composer rows were handed', () => {
- openPreview(urlTarget('http://localhost:5174'), 'tool-result')
+ openPreview(urlTarget('http://localhost:5174'))
expect(closePreviewForSource('http://localhost:5174')).toBe(true)
expect($previewTabs.get()).toHaveLength(0)
@@ -215,22 +215,24 @@ describe('preview store', () => {
})
it('closes a tab whose url or label matches even when source differs', () => {
- openPreview(
- { kind: 'url', label: 'HN', source: 'https://news.ycombinator.com', url: 'https://news.ycombinator.com/' },
- 'tool-result'
- )
+ openPreview({
+ kind: 'url',
+ label: 'HN',
+ source: 'https://news.ycombinator.com',
+ url: 'https://news.ycombinator.com/'
+ })
expect(closePreviewMatching('https://news.ycombinator.com/')).toBe(true)
expect($previewTabs.get()).toHaveLength(0)
- openPreview({ ...fileTarget('/work/demo.html'), label: 'Demo' }, 'tool-result')
+ openPreview({ ...fileTarget('/work/demo.html'), label: 'Demo' })
expect(closePreviewMatching('Demo')).toBe(true)
expect($previewTabs.get()).toHaveLength(0)
})
it('does not wipe the rail on an empty or unknown close query', () => {
- openPreview(fileTarget('/work/keep.html'), 'file-browser')
+ openPreview(fileTarget('/work/keep.html'))
expect(closePreviewMatching()).toBe(false)
expect(closePreviewMatching(' ')).toBe(false)
@@ -239,8 +241,8 @@ describe('preview store', () => {
})
it('persists file and url tabs but never artifacts, whose content is memory-only', () => {
- openPreview(fileTarget('/work/demo.html'), 'file-browser')
- openPreview(urlTarget('http://localhost:5174'), 'tool-result')
+ openPreview(fileTarget('/work/demo.html'))
+ openPreview(urlTarget('http://localhost:5174'))
openPreview(artifactTarget('session-1:dashboard'))
const stored = window.localStorage.getItem('hermes.desktop.previewTabs.v2') ?? ''
@@ -265,7 +267,7 @@ describe('preview store', () => {
})
it('preserves an explicit HTML source fallback', () => {
- openPreview({ ...fileTarget('/remote/report.html'), renderMode: 'source' }, 'tool-result')
+ openPreview({ ...fileTarget('/remote/report.html'), renderMode: 'source' })
expect($previewTarget.get()?.renderMode).toBe('source')
})
@@ -273,7 +275,7 @@ describe('preview store', () => {
it('does not persist transient remote HTML source fallbacks', () => {
const target = { ...fileTarget('/remote/report.html'), renderMode: 'source' as const, transient: true }
- openPreview(target, 'tool-result')
+ openPreview(target)
// Nothing persistable, so the profile's bucket is empty and the key is
// removed rather than stored as an empty list (matching the tiles store).
diff --git a/apps/desktop/src/store/preview.ts b/apps/desktop/src/store/preview.ts
index dcb42891296..3b6530d2441 100644
--- a/apps/desktop/src/store/preview.ts
+++ b/apps/desktop/src/store/preview.ts
@@ -52,10 +52,6 @@ export interface PreviewServerRestart {
url: string
}
-/** Where an open came from. HTML files default to a live Render for every
- * source; an explicit `target.renderMode` is never overridden. */
-export type PreviewRecordSource = 'explicit-link' | 'file-browser' | 'manual' | 'tool-result'
-
export interface PreviewTab {
id: RightRailTabId
target: PreviewTarget
@@ -504,7 +500,8 @@ function browserTabId(tabs: PreviewTab[]): RightRailTabId {
return tabs.findLast(isBrowserTab)?.id ?? mintBrowserTabId()
}
-function previewTargetForSource(target: PreviewTarget, _source: PreviewRecordSource): PreviewTarget {
+/** HTML files open rendered unless the caller asks for a mode. */
+function withRenderMode(target: PreviewTarget): PreviewTarget {
if (target.kind !== 'file' || target.previewKind !== 'html' || target.renderMode) {
return target
}
@@ -527,12 +524,11 @@ export function setPreviewRenderMode(tabId: string, renderMode: 'preview' | 'sou
/** Open (or re-front) the tab for `target`. Re-opening an existing tab refreshes
* its target so a stale label/path can't outlive the thing it points at. The
* only way anything reaches a preview. */
-export function openPreview(target: PreviewTarget, source: PreviewRecordSource = 'manual') {
- const resolved = previewTargetForSource(target, source)
+export function openPreview(target: PreviewTarget) {
const current = $previewTabs.get()
- const id = resolved.kind === 'url' ? browserTabId(current) : previewTabId(resolved)
+ const id = target.kind === 'url' ? browserTabId(current) : previewTabId(target)
const index = current.findIndex(tab => tab.id === id)
- const tab: PreviewTab = { id, target: resolved }
+ const tab: PreviewTab = { id, target: withRenderMode(target) }
$previewTabs.set(index === -1 ? [...current, tab] : current.map((item, i) => (i === index ? tab : item)))
selectRightRailTab(id)