Retain transient content across sessions and close its tabs on reload

This commit is contained in:
yudshj committed 2026-11-19 16:38:47 +08:00
1 parent ed08ff8364
commit ce5bc3df56
17 files changed
+115 -23

No files matched your search

+3 -1
View File
@@ -338,7 +338,9 @@ describe('minimal manual compaction', () => {
const warningStart = tripwire.warnings.length
await page.reload({ waitUntil: 'load' })
acknowledgeReloadConnectionLoss(tripwire, warningStart)
await preview.getByRole('status').waitFor()
await card.waitFor()
expect(await preview.count()).toBe(0)
expect(await column.locator('[data-dockkit-tab-title]').allTextContents()).not.toContain('Context summary')
await card.click()
await rendered.waitFor({ state: 'visible', timeout: 15_000 })
expect(await column.locator('[data-dockkit-tab-title]').allTextContents()).toEqual(['Context summary'])
+4 -2
View File
@@ -712,7 +712,7 @@ describe('web e2e: seeded history renders through cold resume', () => {
expect(restoredPreview).toBe(preview)
})
it.skipIf(MODE === 'record')('reopens the expired summary from its chat row after reload', async () => {
it.skipIf(MODE === 'record')('restores the file tab and reopens the summary from its chat row after reload', async () => {
onTestFailed(() => saveFailureShot(page, 'web-e2e-seeded-compaction-reload'))
// Runs after the cases that capture Chat goldens: reloading resets their
// expanded rows. The previous case left the Sidebar open on the file tab.
@@ -725,7 +725,9 @@ describe('web e2e: seeded history renders through cold resume', () => {
const warningStart = tripwire.warnings.length
await page.reload({ waitUntil: 'load' })
acknowledgeReloadConnectionLoss(tripwire, warningStart)
await column.locator(`${SUMMARY_PREVIEW} [role="status"]`).waitFor()
await column.locator('[data-textpreview-line="1"]').waitFor()
expect(await column.locator('[data-dockkit-tab-title]').allTextContents()).toEqual(['a.txt'])
expect(await rendered.count()).toBe(0)
await compactionMarker(page).click()
await rendered.waitFor({ state: 'visible', timeout: 15_000 })
expect(await column.locator('[data-dockkit-tab-title]').allTextContents()).toEqual(['a.txt', CHECKPOINT_TITLE])
@@ -12,5 +12,5 @@
en: 77b9478cf1488ada
zh: 644ee2a694039987
/compaction-summary-previews/migration:
en: 8ee49ba1671c9a5a
zh: c2b8485b42be9451
en: 8cfe8679c83e8875
zh: 06ba7ef4c307de6b
@@ -13,4 +13,4 @@ Chat compaction markers retain counts and the summary event sequence. Their view
## Migration
Use the marker’s non-null `summaryEventSeq` and its Session address to read the corresponding `compaction/summary` event. In Chat, select the completed compaction row to read the summary in the sidebar. Reopen it from the same row after a browser reload.
Use the marker’s non-null `summaryEventSeq` and its Session address to read the corresponding `compaction/summary` event. In Chat, select the completed compaction row to read the summary in the sidebar. Switching Sessions retains the open preview. Reloading closes its tab; reopen it from the same row.
@@ -13,4 +13,4 @@ description: 从会话事件读取压缩摘要。
## 迁移
使用标记上非空的 `summaryEventSeq` 和会话地址读取对应的 `compaction/summary` 事件。在聊天中点击已完成的压缩行,即可在侧栏查看摘要。刷新浏览器后可从同一行重新打开。
使用标记上非空的 `summaryEventSeq` 和会话地址读取对应的 `compaction/summary` 事件。在聊天中点击已完成的压缩行,即可在侧栏查看摘要。切换会话会保留预览。刷新浏览器会关闭摘要标签,可从同一行重新打开。
@@ -15,8 +15,8 @@
en: 0dd8c3a22e28aacf
zh: c27c11bf4b5cceba
/deepseek-ai-dsh-client-ui-sidebar-documentpreview/what-it-registers:
en: bc0f7951aec5b229
zh: 09b1f180d1b3b007
en: d5f37a47c428b770
zh: 91fc3e933b0c04a9
/deepseek-ai-dsh-client-ui-sidebar-documentpreview/addresses:
en: 57942270e23d3a8e
zh: 6617124e652b3f67
@@ -28,7 +28,7 @@ Preview files in the right Sidebar and choose among registered renderers. Markdo
<a id="what-it-registers"></a>
## What it registers
The compaction summary tab shows the Markdown supplied by the selected Chat row. Its navigation content expires on reload. Reopen the row to read the same event again.
The compaction summary tab shows the Markdown supplied by the selected Chat row. It stays open across Session switches and closes on reload. Reopen the row to read the same event again.
Image drag actions arrive through the image entry’s inject face from [ui-file-drag](../ui-file-drag/README.md).
@@ -28,7 +28,7 @@ kind: "package-reference"
<a id="what-it-registers"></a>
## 注册了什么
压缩摘要标签显示所选聊天行提供的 Markdown。刷新页面后临时正文失效,从原行重新打开即可再次读取对应事件。
压缩摘要标签显示所选聊天行提供的 Markdown。切换会话时保留标签,刷新页面后标签关闭,从原行重新打开即可再次读取对应事件。
图片拖放回调通过图片入口的注入接口从 [ui-file-drag](../ui-file-drag/README.zh.md) 获取。
@@ -30,8 +30,8 @@
en: 9533f5af50898daf
zh: 78d3b77c25962145
/deepseek-ai-dsh-client-ui-sidebar-right/ctx-sidebarright:
en: 10a2ce86c7047585
zh: 44f1a75bd61fdf2c
en: e91ee30e5484b747
zh: 1f8aa428c12c082a
/deepseek-ai-dsh-client-ui-sidebar-right/the-tab-domain:
en: b6c64c7649203e12
zh: c9341bbfd548a5eb
+1 -1
View File
@@ -94,7 +94,7 @@ Two more seats extend what is already there: `sidebar.right.tab.guide` (chain) r
`openResource(address, options?)` and `openTab(kind, options?)` open resources and pages: the conversation's file links and a tool row's line reference (`openResource(fileAddress, { params: { line } })`), the strip's add control and a guide entry box (`openTab`), a file tree's rows (`tab.actions.openResource`). A resource address is a `dsh-resource://<type>/…` URI; without `options.kind` the registry claims it (globs and `canOpen`, best band wins), with it that kind's type in force opens it. A page is named by kind; the tab is recorded under an address this package composes and nobody else spells (`contract/seed.ts`). Both run the same steps as one history entry: a resource tab already showing the same (kind, contentId) is focused wherever it sits unless `revealIfOpened: false`; ordinary page tabs always deduplicate within the target pane, regardless of that option; otherwise a new tab takes the place of `options.replaceTab` (closing that tab, described below), else in `options.paneId`, else in the active docked pane, which is the first docked pane while a floating pane is active. The panel expands, because content the user cannot see is not opened, unless the new tab replaces a floating one or the open reveals a tab in a floating panel. A reveal of a tab that was already on screen — the active tab of a floating panel, or of a docked pane while the column is expanded — makes the pane holding it glow once for about 600ms, whatever opened it and whatever type the tab is; providers do nothing for it. A reveal that switches to a background tab or expands the column does not glow, because that change is already visible. A docked pane glows inward, above its content's sticky bars such as code banners; a floating panel glows outward over its own shadow. The glow uses the accent colour in light mode and white in dark mode. A repeated reveal restarts the glow, the pane carries `data-sidebar-right-flash` while it shows, and with reduced motion the glow holds steady for the same time instead of fading. Each reveal plays once and only while its Session is on screen: hiding the Session ends a glow in progress, a reveal made while it is hidden is dropped rather than played on return, and a Sidebar mounted later does not replay an earlier reveal. Then the Tab domain records the navigation — `params` reach the body as `navigation.params`, with `revision` stepped — outside the layout history. `params` is typed by what is opened: a viewer for a resource type merges its entry into `SidebarRightResourceParamsMap` (the text preview declares `{ line?: number }`); a page type that takes parameters merges into `SidebarRightTabParamsMap` under its kind; values are JSON-shaped by convention, unchecked at run time. An address outside `dsh-resource://`, one no type claims, or a kind nothing registered throws: that is a wiring mistake, not a user error.
`openContent(kind, content, { key?, destination? })` sends the registered tab its typed content as transient navigation parameters. The tab provider declares the content under its kind in `SidebarRightTabParamsMap`. The default destination is the sidebar; use `float` to open directly in a floating panel. Reusing a key in the same Session and kind updates the existing tab and moves it to the requested host. Omit the key to open another tab. Reload restores tab identity only.
`openContent(kind, content, { key?, destination? })` sends the registered tab its typed content as transient navigation parameters. The tab provider declares the content under its kind in `SidebarRightTabParamsMap`. The default destination is the sidebar; use `float` to open directly in a floating panel. Reusing a key in the same Session and kind updates the existing tab and moves it to the requested host. Omit the key to open another tab. A visited content tab stays mounted across Session switches. Reload closes content tabs, including floats, and restores the other tabs.
`preferNewPane: true` first asks the target docked pane to split under the normal two-pane and room rules, then falls back to that pane when no split is available. `replaceTab` takes precedence and disables this preference.
@@ -94,7 +94,7 @@ tab 类型分两阶段注册,随包发布的引导类型走的正是别的包
`openResource(address, options?)` 与 `openTab(kind, options?)` 分别打开资源和页面:会话区的文件链接与工具行的行号引用(`openResource(fileAddress, { params: { line } })`),tab 条的添加控件与引导入口框(`openTab`),文件树的行(`tab.actions.openResource`)。资源地址是 `dsh-resource://<type>/…` URI;不带 `options.kind` 时由注册表认领(glob 与 `canOpen`,最高档胜出),带它时由该 kind 生效的类型打开。页按 kind 命名;tab 记录在本包拼出、别处无人书写的地址下(`contract/seed.ts`)。两者以同一组步骤作为一条历史运行:已展示同一 (kind, contentId) 的资源 tab 被聚焦,不限所在分栏,除非 `revealIfOpened: false`;页 tab 始终只在目标分栏内去重,不受该选项影响;否则新 tab 取代 `options.replaceTab` 的位置(并关掉那个 tab,见下文),再退而落到 `options.paneId`,再退而落到活跃停靠格;活动格是浮窗时为第一个停靠格。面板展开,因为用户看不到的内容不算打开;新 tab 替换浮动 tab、或这次打开揭示的是浮窗中的 tab 时除外。揭示一个原本就在屏幕上的 tab(浮窗的活动 tab,或该列展开时停靠格的活动 tab)时,存放它的格发光提示一次,约 600ms,与由谁打开、tab 是什么类型无关,提供方无需做任何事。揭示需要切到后台 tab 或展开该列时不发光,因为这一变化本身已经可见。停靠格向内发光,位于其内容的吸顶栏(如代码块标题栏)之上;浮窗在自身阴影之上向外发光。浅色模式用强调色,深色模式用白色。再次揭示会重新开始发光,发光期间该格带有 `data-sidebar-right-flash`;减少动态效果时发光在同样时长内保持不变而不淡出。每次揭示只在其会话位于屏幕上时播放一次:隐藏该会话会结束进行中的发光,会话隐藏期间的揭示直接丢弃、不在切回时补播,之后挂载的侧栏也不会重放先前的揭示。随后 Tab 域记录这次导航——`params` 以 `navigation.params` 抵达正文,`revision` 递增——不进布局历史。`params` 按所开之物定型:某资源类型的查看器把自己那项并入 `SidebarRightResourceParamsMap`(文本预览声明 `{ line?: number }`);接受参数的页类型按其 kind 并入 `SidebarRightTabParamsMap`;值约定为 JSON 形状,运行时不校验。`dsh-resource://` 之外的地址、无人认领的地址、或未注册的 kind 都会 throw:那是接线错误,不是用户错误。
`openContent(kind, content, { key?, destination? })` 将正文作为临时导航参数传给已注册的标签。标签提供方在 `SidebarRightTabParamsMap` 中按 kind 声明正文类型。默认在侧栏打开,使用 `float` 可直接打开浮窗。同一会话及 kind 下复用 key 会更新已有标签,并将它移到指定位置。省略 key 则新开标签。刷新后仅恢复标签身份。
`openContent(kind, content, { key?, destination? })` 将正文作为临时导航参数传给已注册的标签。标签提供方在 `SidebarRightTabParamsMap` 中按 kind 声明正文类型。默认在侧栏打开,使用 `float` 可直接打开浮窗。同一会话及 kind 下复用 key 会更新已有标签,并将它移到指定位置。省略 key 则新开标签。切换会话时,已查看的正文标签保持挂载。刷新后关闭这类标签及其浮窗,恢复其他标签。
`preferNewPane: true` 会先按普通的两格上限与空间规则尝试分割目标停靠格,无法分栏时回退到该格。`replaceTab` 优先并会禁用这项偏好。
@@ -10,6 +10,7 @@
* type would use — the guide is not special in the machinery, only in being
* always available.
*/
import type { TabRecord } from '@deepseek-ai/dsh-client-ui-dockkit'
import type { SidebarRightTabRegistry } from '../tab-registry.ts'
/** One pane's initial page, resolved from the current registered guide entries. */
@@ -45,3 +46,19 @@ export const GUIDE_KIND = 'guide'
export function pageAddress(kind: string): string {
return `sidebar://${kind}`
}
/** Namespace content keys separately from page instances of the same kind.
* @param kind - registered tab kind.
* @returns the reserved address prefix for a window's transient content.
*/
export function contentPrefix(kind: string): string {
return `${pageAddress(kind)}/content/`
}
/** Recognize a transient content occurrence without loading its plugin.
* @param tab - tab identity saved in the layout.
* @returns whether openContent owns this occurrence's window-local content.
*/
export function isContentTab(tab: TabRecord): boolean {
return tab.contentId.startsWith(contentPrefix(tab.kind))
}
@@ -1,6 +1,7 @@
/** Validated current-layout snapshots; undo history belongs to the live window. */
import { z } from 'zod'
import { EMPTY_HISTORY, type LayoutState } from '@deepseek-ai/dsh-client-ui-dockkit'
import { applyOp, createIdMinter, EMPTY_HISTORY, planSettle, replay, type LayoutState } from '@deepseek-ai/dsh-client-ui-dockkit'
import { isContentTab } from './contract/seed.ts'
import type { SurfaceState } from './stores.ts'
/** Persistence namespace shared by scoped stores and startup discovery. */
@@ -55,6 +56,19 @@ function validateReferences(value: z.infer<typeof surface>): void {
|| layout.nodes[layout.activePaneId]?.kind !== 'pane') reject()
}
function restoredLayout(layout: LayoutState, minted: number): LayoutState {
const transient = Object.values(layout.tabs).filter(isContentTab)
if (transient.length === 0) return layout
let restored = layout
for (const tab of transient) restored = applyOp(restored, { type: 'closeTab', tabId: tab.id }).state
restored = replay(restored, planSettle(restored, createIdMinter(minted).next))
const root = restored.nodes[restored.rootId]
if (root?.kind === 'pane' && root.tabs.length === 0) {
return { ...restored, expanded: false, mode: 'push' }
}
return restored
}
/**
* Restore one validated Session layout with a fresh in-window undo history.
* @param sessionId - storage scope.
@@ -71,7 +85,7 @@ export function readSidebarLayout(sessionId: string): SurfaceState | undefined {
if (saved === undefined) return undefined
const parsed = surface.parse(saved)
validateReferences(parsed)
return { layout: parsed.layout as unknown as LayoutState, minted: parsed.minted, history: EMPTY_HISTORY }
return { layout: restoredLayout(parsed.layout as unknown as LayoutState, parsed.minted), minted: parsed.minted, history: EMPTY_HISTORY }
} catch (_invalidLayout) {
clearSidebarLayout(sessionId)
return undefined
@@ -41,7 +41,7 @@ import { activeDockPaneId, canSplit, findContentTab, findPaneContentTab, dockPan
import type { BoundActions } from '@deepseek-ai/dsh-client-ui-slots'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import type { SidebarRightNavigationParams, SidebarRightResourceParams, SidebarRightTabParamsFor, SidebarRightTabParamsMap } from './contract/params.ts'
import { pageAddress } from './contract/seed.ts'
import { contentPrefix, pageAddress } from './contract/seed.ts'
import type { SidebarRightDestination } from './contract/slots.ts'
import type { SidebarRightTabClaim, SidebarRightTabRegistry } from './tab-registry.ts'
import { canCloseTab, findHostContentTab, type SidebarRightState, type SurfaceState } from './stores.ts'
@@ -250,7 +250,7 @@ export interface ISidebarRight {
*/
openResource(address: string, options?: SidebarRightOpenResourceOptions): void
/**
* Open transient content with its registered tab kind. Only the tab identity survives a reload.
* Open transient content with its registered tab kind. The visited body stays mounted across Session switches. Reload closes its tab.
* @param kind - tab kind declaring the content in SidebarRightTabParamsMap.
* @param content - input delivered to the tab body as navigation parameters.
* @param options - reuse key and destination host.
@@ -403,7 +403,7 @@ export class SidebarRightController implements ISidebarRight {
kind: K, content: SidebarRightTabParamsMap[K], options: SidebarRightOpenContentOptions = {},
): void {
const { sessionId, actions } = this.require()
const address = `${pageAddress(kind)}/content/${encodeURIComponent(options.key ?? randomUUID())}`
const address = `${contentPrefix(kind)}${encodeURIComponent(options.key ?? randomUUID())}`
this.placeIn(sessionId, actions, this.tabs.claim(address, kind), address, options.destination ?? 'sidebar', content)
}
@@ -42,7 +42,7 @@ import type { DockIntents, DockMode, DockSurfaceProps, FloatRect, TabId, TabReco
import { canSplit, dockPaneIds, DockLayout, findPaneContentTab } from '@deepseek-ai/dsh-client-ui-dockkit'
import type { HalvesFit, LayoutState, PaneId } from '@deepseek-ai/dsh-client-ui-dockkit'
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import { GUIDE_KIND, pageAddress } from '../contract/seed.ts'
import { GUIDE_KIND, isContentTab, pageAddress } from '../contract/seed.ts'
import { dockLabels } from '../labels.ts'
import type { SidebarRightFlash, SidebarRightOpenTabOptions } from '../service.ts'
import type { SidebarRightTabDefinition } from '../tab-registry.ts'
@@ -190,6 +190,10 @@ export function intentsFor(sessionId: SessionId, actions: Store['actions'], open
}
}
function retainsBody(tab: TabRecord, definition: SidebarRightTabDefinition | undefined): boolean {
return definition !== undefined && (definition.keepMounted === true || isContentTab(tab))
}
/** One tab's slot dispatch: which seat, and what to render when no type registered. */
interface TabSlotProps extends Pick<PanelProps, 'renderSlot' | 'occurrence' | 'useTabTypes' | 'useTabNavigation' | 'useStore' | 'fullscreen' | 'active' | 'retainTab' | 'shortcuts'> {
readonly tab: TabRecord
@@ -205,7 +209,7 @@ function TabSlot({
}: TabSlotProps): ReactNode {
const { id, signal, tabActions } = occurrence(tab)
const definition = useTabTypes(types => types.find(definition => definition.kind === tab.kind))
const retained = seat === 'sidebar.right.pane.tab' && definition?.keepMounted === true
const retained = seat === 'sidebar.right.pane.tab' && retainsBody(tab, definition)
useLayoutEffect(() => retained ? retainTab(tab.id, signal) : undefined, [retained, retainTab, tab.id, signal])
const hookContext = useMemo((): TabHookContext => ({
tabId: tab.id,
@@ -365,7 +369,7 @@ function SidebarPanel(panel: PanelProps & { width: number; panelRef: RefObject<H
renderTab={bodiesFor(panel)}
renderTabTitle={titlesFor(panel)}
active={panel.active}
keepMounted={tab => types.find(type => type.kind === tab.kind)?.keepMounted === true}
keepMounted={tab => retainsBody(tab, types.find(type => type.kind === tab.kind))}
getTabTriggerProps={panel.getTabTriggerProps} tabMenuOpen={panel.tabMenuOpen}
chrome={<PanelChrome
sessionId={sessionId} fullscreen={fullscreen} actions={actions} t={t}
@@ -55,6 +55,33 @@ it('restores current layout independently by Session with a fresh undo history',
expect(createSidebarRightStore(seed).create('second').getSnapshot()).toEqual(second.getSnapshot())
})
it('removes transient occurrences from docked and floating layouts before restoring a Session', () => {
storage()
const first = createSidebarRightStore(seed).create(sessionId)
const open = (contentId: string, destination: 'sidebar' | 'float') => {
first.actions.openContent(sessionId, { kind: 'preview', contentId, title: contentId, destination }, () => {})
}
open('sidebar://preview', 'sidebar')
open('sidebar://preview/content/summary', 'sidebar')
open('sidebar://preview/content/diagram', 'float')
const restored = createSidebarRightStore(seed).create(sessionId).getSnapshot().bySession[sessionId]!.layout
expect(Object.values(restored.tabs).map(tab => tab.contentId)).toEqual(['sidebar://preview'])
expect(restored.floats).toEqual([])
expect(restored.expanded).toBe(true)
const active = restored.nodes[restored.activePaneId]
expect(active?.kind === 'pane' && active.activeTabId).toBe(Object.values(restored.tabs)[0]!.id)
})
it('collapses a restored sidebar whose only tab was transient', () => {
storage()
const first = createSidebarRightStore(seed).create(sessionId)
first.actions.openContent(sessionId, { kind: 'preview', contentId: 'sidebar://preview/content/1', title: 'Summary', destination: 'sidebar' }, () => {})
first.actions.setMode(sessionId, 'fullscreen')
const restored = createSidebarRightStore(seed).create(sessionId).getSnapshot().bySession[sessionId]!
expect(restored.layout).toMatchObject({ expanded: false, mode: 'push', tabs: {}, floats: [] })
expect(restored.history.entries).toHaveLength(0)
})
it('pins restored records during adoption before the first render or store mutation', async () => {
storage()
const first = createSidebarRightStore(seed).create(sessionId)
@@ -21,6 +21,12 @@ import { ShortcutRegistry } from '@deepseek-ai/dsh-client-shortcuts/src/client/r
import type { SidebarRightTabInfo, SidebarRightTabMenuOwnerProps } from '../src/client/contract/slots.ts'
import type { createSidebarRightStore } from '../src/client/stores.ts'
declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
interface SidebarRightTabParamsMap {
'transient-view': { text: string }
}
}
declare module '../src/client/contract/params.ts' {
interface SidebarRightResourceParamsMap {
test: { line?: number; x?: number }
@@ -172,6 +178,26 @@ async function mountSeat(viewportWidth = 1440, canShow = true, entryCount = 0, o
}
}
it('keeps an openContent body and its navigation through tab and Session switches', async () => {
const h = await mountSeat()
act(() => { h.registerPage('transient-view') })
act(() => { h.controller.openContent('transient-view', { text: 'In memory' }, { key: 'k' }) })
const tab = h.controller.active()!
const selector = `[data-tab-body="${tab.id}"]`
const body = element(h.view.container, selector)
act(() => { h.controller.openTab('guide') })
expect(body.isConnected).toBe(true)
await act(async () => { await h.runtime.sessions.add({ id: OTHER }) })
act(() => { h.selectSession(OTHER) })
expect(body.isConnected).toBe(true)
act(() => { h.selectSession(SESSION) })
act(() => { h.controller.focus(tab.id) })
expect(element(h.view.container, selector)).toBe(body)
expect(h.bodies.get(tab.id)?.tab.navigation.params).toEqual({ text: 'In memory' })
act(() => { h.controller.close(tab.id) })
expect(body.isConnected).toBe(false)
})
it('keeps duplicate Session Tabs independent and preserves a body through docking and float focus', async () => {
const h = await mountSeat()
await act(async () => {