Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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<typeof setStructuredAgentSessionTabVisibility>[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<void> => {
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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<void> => this.restore.reconcileRestartLeases()

restoreReadableSessions = (sessionIds?: readonly string[]): Promise<void> =>
Expand Down
Loading