diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host-tabs.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host-tabs.ts index 5c9f5215a95e..f74532ac9aef 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host-tabs.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host-tabs.ts @@ -1,4 +1,5 @@ import type { AgentSessionRecord } from '../../../shared/agent-session-record' +import type { AgentSessionRecordStore } from '../../runtime/agent-session-record-store' import type { StructuredAgentSessionLogger } from './structured-agent-session-logger' /** @@ -54,3 +55,44 @@ export function listStructuredAgentSessionTabs( agent: session.params.provider })) } + +type TabSessions = ReadonlyMap< + string, + { + child?: unknown + params: { location: { workspaceId: string }; provider: AgentSessionRecord['provider'] } + } +> + +/** The host's chat-tab surface; reads `host.deps` per call, so it sees the host's wrapped deps. */ +export function createStructuredAgentSessionTabSurface( + host: Parameters[0] & { + deps: { + store: Pick< + AgentSessionRecordStore, + 'getVisibleSessionTabIndex' | 'getSessionTabId' | 'showSessionTabs' + > + } + }, + sessions: TabSessions, + forgetStatus: (sessionId: string) => void +) { + return { + listSessionTabs: () => listStructuredAgentSessionTabs(sessions), + getPersistedVisibleSessionTabIndex: () => host.deps.store.getVisibleSessionTabIndex(), + getSessionTabId: (sessionId: string): string | null => + host.deps.store.getSessionTabId(sessionId), + showSessionTabs: (sessionIds: readonly string[]) => host.deps.store.showSessionTabs(sessionIds), + setSessionTabVisibility: async ( + sessionId: string, + visible: boolean, + tabId?: string + ): Promise => { + await setStructuredAgentSessionTabVisibility(host, sessionId, visible, tabId) + // The tab edge of the row's lifetime; the handle close is the other. + if (!visible && !sessions.get(sessionId)?.child) { + forgetStatus(sessionId) + } + } + } +} diff --git a/src/main/native-chat/agent-session-wire/structured-agent-session-host.ts b/src/main/native-chat/agent-session-wire/structured-agent-session-host.ts index 4c29fd5e3d04..44a576e2f781 100644 --- a/src/main/native-chat/agent-session-wire/structured-agent-session-host.ts +++ b/src/main/native-chat/agent-session-wire/structured-agent-session-host.ts @@ -216,28 +216,22 @@ export class StructuredAgentSessionHost { supportsCreate = (location: AgentSessionExecutionLocation, agent: string): boolean => providerSupport.adapterSupportsCreate(this.deps.adapter, location, agent) - listSessionTabs = () => sessionTabs.listStructuredAgentSessionTabs(this.sessions) - getPersistedVisibleSessionTabIndex = () => this.deps.store.getVisibleSessionTabIndex() - getSessionTabId = (sessionId: string): string | null => this.deps.store.getSessionTabId(sessionId) - showSessionTabs = (sessionIds: readonly string[]) => this.deps.store.showSessionTabs(sessionIds) + private readonly tabs = sessionTabs.createStructuredAgentSessionTabSurface( + this, + this.sessions, + (sessionId) => this.clientDelivery.forgetStatus(sessionId) + ) + listSessionTabs = this.tabs.listSessionTabs + getPersistedVisibleSessionTabIndex = this.tabs.getPersistedVisibleSessionTabIndex + getSessionTabId = this.tabs.getSessionTabId + showSessionTabs = this.tabs.showSessionTabs + setSessionTabVisibility = this.tabs.setSessionTabVisibility /** The records file could not be read this launch, so chats it holds are not listed yet. */ legacyRecordImportOwed = (): boolean => this.deps.journalDatabase.legacyRecordImportOwed === true /** This runtime holds a chat: a record, or the records file's chats still owed their copy. */ holdsSessions = (): boolean => this.deps.store.holdsRecords() || this.legacyRecordImportOwed() onSessionsHeld = (listener: () => void): (() => void) => this.deps.store.onFirstRecord(listener) - setSessionTabVisibility = async ( - sessionId: string, - visible: boolean, - tabId?: string - ): Promise => { - await sessionTabs.setStructuredAgentSessionTabVisibility(this, sessionId, visible, tabId) - // The tab edge of the row's lifetime; the handle close is the other. - if (!visible && !this.sessions.get(sessionId)?.child) { - this.clientDelivery.forgetStatus(sessionId) - } - } - reconcileRestartLeases = (): Promise => this.restore.reconcileRestartLeases() restoreReadableSessions = (sessionIds?: readonly string[]): Promise =>