import { Event } from "../../../../../base/common/event.js"; import { IMarkdownString } from "../../../../../base/common/htmlContent.js"; import { Disposable } from "../../../../../base/common/lifecycle.js"; import { ResourceMap } from "../../../../../base/common/map.js"; import { MarshalledId } from "../../../../../base/common/marshallingIds.js"; import { IObservable } from "../../../../../base/common/observable.js"; import { ThemeIcon } from "../../../../../base/common/themables.js"; import { URI } from "../../../../../base/common/uri.js"; import { IInstantiationService } from "../../../../../platform/instantiation/common/instantiation.js"; import { IProductService } from "../../../../../platform/product/common/productService.service.js"; import { IStorageService } from "../../../../../platform/storage/common/storage.service.js"; import { IWorkspaceContextService } from "../../../../../platform/workspace/common/workspace.service.js"; import { IWorkspaceTrustManagementService } from "../../../../../platform/workspace/common/workspaceTrust.service.js"; import { IChatEntitlementService } from "../../../../services/chat/common/chatEntitlementService.service.js"; import { ILifecycleService } from "../../../../services/lifecycle/common/lifecycle.service.js"; import { ChatSessionRefreshReason, ChatSessionStatus as AgentSessionStatus, IChatSessionItem } from "../../common/chatSessionsService.js"; import { IChatSessionsService } from "../../common/chatSessionsService.service.js"; import { IChatWidgetService } from "../chat.service.js"; export { ChatSessionStatus as AgentSessionStatus, isSessionInProgressStatus } from "../../common/chatSessionsService.js"; export type AgentSessionRefreshReason = Exclude; export interface IAgentSessionsModel { readonly onWillResolve: Event; readonly onDidResolve: Event; readonly onDidChangeSessions: Event; readonly onDidChangeSessionArchivedState: Event; readonly resolved: boolean; readonly sessions: IAgentSession[]; getSession(resource: URI): IAgentSession | undefined; /** * Returns an observable that emits the latest {@link IAgentSession} for the * given resource (or `undefined` if no session is currently known). * * The observable updates whenever the underlying session collection changes. * The first call for a given resource lazily triggers * {@link IChatSessionsService.resolveChatSessionItem} so consumers reading * lazy properties (e.g. `changes`) see fresh values once the provider has * resolved them. In-flight resolves are deduplicated by the chat sessions * service. */ observeSession(resource: URI): IObservable; /** Resolves sessions; automatic refreshes may reuse fresh data. Errors are logged and isolated, with an optional observer. */ resolve(provider: string | string[] | undefined, onError?: (error: unknown) => void, reason?: AgentSessionRefreshReason): Promise; } interface IAgentSessionData extends Omit { readonly providerType: string; readonly providerLabel: string; readonly resource: URI; readonly status: AgentSessionStatus; readonly statusKnown?: boolean; readonly tooltip?: string | IMarkdownString; readonly label: string; readonly description?: string | IMarkdownString; readonly badge?: string | IMarkdownString; readonly icon: ThemeIcon; readonly timing: IChatSessionItem["timing"]; readonly changes?: IChatSessionItem["changes"]; readonly children?: readonly IAgentSession[]; readonly parentSession?: { readonly resource: URI; readonly label: string; }; } /** * Checks if the provided changes object represents valid diff information. */ export declare function hasValidDiff(changes: IAgentSession["changes"]): boolean; /** * Gets a summary of agent session changes, converting from array format to object format if needed. */ export declare function getAgentChangesSummary(changes: IAgentSession["changes"]): { readonly files: number; readonly insertions: number; readonly deletions: number; } | undefined; export interface IAgentSession extends IAgentSessionData { isArchived(): boolean; setArchived(archived: boolean): void; isPinned(): boolean; setPinned(pinned: boolean): void; isRead(): boolean; isMarkedUnread(): boolean; setRead(read: boolean): void; } interface IInternalAgentSessionData extends Omit { readonly children?: readonly IInternalAgentSessionData[]; /** * The `archived` property is provided by the session provider * and will be used as the initial value if the user has not * changed the archived state for the session previously. It * is kept internal to not expose it publicly. Use `isArchived()` * and `setArchived()` methods instead. */ readonly archived: boolean | undefined; /** * Read state as reported by the session's provider, authoritative for * providers that own it (see {@link ownsReadState}). Kept internal — use * `isRead()` / `setRead()`. */ readonly providerIsRead: boolean | undefined; } export declare function isLocalAgentSessionItem(session: IAgentSession): boolean; /** * Resolves the pull request associated with an agent session from its provider metadata, * preferring an explicit `pullRequestUrl` and falling back to `pullRequestNumber` combined * with `owner`/`name`. Returns `undefined` when the session has no associated pull request. */ export declare function getAgentSessionPullRequestUri(session: Pick): URI | undefined; /** * The value for the `chatSessionPullRequest` context key for a session. Never returns an * "unknown" value: callers here always have the session's metadata in hand. */ export declare function getAgentSessionPullRequestContextValue(session: Pick): "available" | "none"; export declare function isAgentHostAgentSessionItem(session: IAgentSession): boolean; export declare function isAgentSession(obj: unknown): obj is IAgentSession; export declare function isAgentSessionChild(session: IAgentSession): session is IAgentSession & { readonly parentSession: NonNullable; }; export declare function isAgentSessionsModel(obj: unknown): obj is IAgentSessionsModel; export declare function countUnreadSessions(sessions: IAgentSession[]): number; interface IAgentSessionState { readonly archived?: boolean; readonly pinned?: boolean; readonly read?: number; } export declare enum AgentSessionSection { Pinned = "pinned", Today = "today", Yesterday = "yesterday", Week = "week", Older = "older", Archived = "archived", More = "more", Repository = "repository" } export interface IAgentSessionSection { readonly section: AgentSessionSection; readonly label: string; readonly sessions: IAgentSession[]; } export declare function isAgentSessionSection(obj: unknown): obj is IAgentSessionSection; /** * A "Show N More..." item that appears as the last child * of a capped repository group section. */ export interface IAgentSessionShowMore { readonly showMore: true; readonly sectionLabel: string; readonly remainingCount: number; } export declare function isAgentSessionShowMore(obj: unknown): obj is IAgentSessionShowMore; /** * A "Show less" item that appears as the last child * of an expanded repository group section to allow collapsing back. */ export interface IAgentSessionShowLess { readonly showLess: true; readonly sectionLabel: string; } export declare function isAgentSessionShowLess(obj: unknown): obj is IAgentSessionShowLess; export interface IMarshalledAgentSessionContext { readonly $mid: MarshalledId.AgentSessionContext; readonly session: IAgentSession; readonly sessions: IAgentSession[]; } export declare function isMarshalledAgentSessionContext(thing: unknown): thing is IMarshalledAgentSessionContext; export declare class AgentSessionsModel extends Disposable implements IAgentSessionsModel { private readonly chatSessionsService; private readonly lifecycleService; private readonly instantiationService; private readonly storageService; private readonly productService; private readonly chatWidgetService; private readonly workspaceContextService; private readonly workspaceTrustManagementService; private readonly chatEntitlementService; private readonly _onWillResolve; readonly onWillResolve: Event; private readonly _onDidResolve; readonly onDidResolve: Event; private readonly _onDidChangeSessions; readonly onDidChangeSessions: Event; private readonly _onDidChangeSessionArchivedState; readonly onDidChangeSessionArchivedState: Event; private _resolved; get resolved(): boolean; private _sessions; get sessions(): IAgentSession[]; private readonly resolvers; private readonly providersToRefresh; private readonly providersToResolveItems; private readonly cache; private readonly logger; constructor(chatSessionsService: IChatSessionsService, lifecycleService: ILifecycleService, instantiationService: IInstantiationService, storageService: IStorageService, productService: IProductService, chatWidgetService: IChatWidgetService, workspaceContextService: IWorkspaceContextService, workspaceTrustManagementService: IWorkspaceTrustManagementService, chatEntitlementService: IChatEntitlementService); private registerListeners; getSession(resource: URI): IAgentSession | undefined; /** * Lists each legacy Copilot CLI session once. The extension-host `copilotcli:` * row is hidden once its agent-host `agent-host-copilotcli:` twin has been * adopted; while the twin is still un-opened, the twin is hidden instead (see * {@link dedupeMigratedCopilotCliSessions}). * * A legacy row with no twin yet stays visible: opening it redirects through the * agent host and adopts it, so it is never a dead end. * * Only display is deduped; {@link getSession} and the cache use the full map. */ private _dedupeMigratedCopilotCliSessions; private _changedSignal; private readonly _sessionObservables; private readonly _resolvedResources; observeSession(resource: URI): IObservable; resolve(provider: string | string[] | undefined, onError?: (error: unknown) => void, reason?: AgentSessionRefreshReason): Promise; private resolveProvider; private doResolveProvider; /** Refreshes lazy properties after a provider has populated its items. */ private resolveObservedSessionItems; private toAgentSession; private static readonly UNREAD_MARKER; private readonly sessionStates; private readonly explicitlyMarkedUnreadSessions; /** * Resolve the state entry for a session, honoring a one-way migration from * {@link IAgentSessionData.legacyResource} when no entry yet exists for the * session's current resource. Adopts the legacy entry forward (copies it onto * the current resource key and removes the legacy entry). Returns undefined if * neither a current nor a legacy entry exists. * * A migrated Copilot CLI session (`copilotcli:` → `agent-host-copilotcli:`) * changes scheme, so it inherits the pin and the stored read date: the local * store owns the pin, and the read date feeds the one-time hand-off of read * state to the agent host. Archived state is owned by the agent host. The * legacy entry is kept so the legacy row keeps its state if migration is * turned off again. */ private resolveStateEntry; private isArchived; private setArchived; private isPinned; private setPinned; private isMarkedUnread; /** * Whether the session's provider owns read state. When it does the value is * shared with every other client on the same backend (the agent window, or * another window on the same agent host), so the local heuristics below must * not second-guess it. */ private ownsReadState; private isRead; /** Grace window absorbing a click away from a session just before it finishes. */ private static readonly READ_GRACE_WINDOW; /** * Whether the locally-stored read timestamp covers the session's last * activity. Falls back to the read-date baseline when nothing is stored. */ private localReadDateCoversActivity; private sessionTimeForReadStateTracking; private setRead; private static readonly READ_MIGRATION_DONE_KEY; private readonly migratedReadResources; /** * One-time hand-off of locally-tracked read state to providers that own it, * so sessions read before the provider took ownership don't all resurface as * unread. Only ever promotes to read, and runs at most once per session so a * later "Mark as Unread" is not undone on the next refresh. Un-opened * migrated Copilot CLI sessions are skipped (see {@link isUnopenedMigratedCopilotCli}). * * The ledger is application-scoped even though the local state it hands off * is per-workspace: the provider-owned state it writes to is global, so a * second workspace that can see the same session (an empty window lists them * all) must not migrate it again and re-promote a deliberate "Mark as Unread". */ private migrateReadStateToProvider; /** * Whether this is a migrated Copilot CLI session the agent host lists but * that has not been opened (adopted) yet. The host deliberately drops read * toggles on such rows so listing cannot adopt them, so their read state is * kept in the local store until they are opened. */ private isUnopenedMigratedCopilotCli; private loadMigratedReadResources; private static readonly READ_DATE_BASELINE_KEY; private readonly readDateBaseline; private resolveReadDateBaseline; } export declare class AgentSessionsCache { private readonly storageService; private static readonly SESSIONS_STORAGE_KEY; private static readonly STATE_STORAGE_KEY; constructor(storageService: IStorageService); saveCachedSessions(sessions: IInternalAgentSessionData[]): void; loadCachedSessions(): IInternalAgentSessionData[]; saveSessionStates(states: ResourceMap): void; loadSessionStates(): ResourceMap; }