import { Event } from "../../../../base/common/event.js"; import { Disposable } from "../../../../base/common/lifecycle.js"; import { URI } from "../../../../base/common/uri.js"; import { ISessionsManagementService } from "../../../services/sessions/common/sessionsManagement.service.js"; import { ISessionsProvidersService } from "../../../services/sessions/browser/sessionsProvidersService.service.js"; import { ISessionsService } from "../../../services/sessions/browser/sessionsService.service.js"; import { IAgentFeedback } from "./agentFeedbackModel.js"; /** * Storage strategy for the per-session feedback item list used by * {@link IAgentFeedbackService}. A backend owns ONLY the list of feedback * items keyed by session; all events, telemetry, navigation anchors, recency * ordering and submit behavior live in the service. * * {@link onDidChangeItems} fires whenever the items for a session change, * whether due to a local mutation or (for the annotations-backed * implementation) an externally-driven update arriving over the protocol. */ export interface IAgentFeedbackItemsBackend { readonly onDidChangeItems: Event; /** Returns the feedback items for a session in stable display order. */ getItems(sessionResource: URI): readonly IAgentFeedback[]; /** * Whether {@link getItems} reflects the authoritative item set for the * session. For the in-memory backend this is always `true`; for the * annotations-backed backend it is `false` until the session's annotations * snapshot has been received, so callers that seed items (e.g. mirroring PR * review comments) can avoid acting on a transiently-empty list. */ hasLoaded(sessionResource: URI): boolean; /** Adds a new feedback item or replaces an existing one with the same id. */ upsert(feedback: IAgentFeedback): void; /** Removes a single feedback item. */ remove(sessionResource: URI, feedbackId: string): void; /** Removes all feedback items for a session. */ clear(sessionResource: URI): void; /** Returns the session resources that currently hold at least one item. */ getSessionsWithItems(): URI[]; } /** * Orders feedback items for display: files are grouped by the order in which * they first appear in {@link items}, and within a file items are sorted by * {@link IAgentFeedback.range} start line. Uses a stable sort so items sharing * a file and start line keep their relative order. */ export declare function orderFeedbackItems(items: readonly IAgentFeedback[]): IAgentFeedback[]; /** * Client-side, in-memory feedback store used for every non-agent-host * provider. State is not persisted and is cleared on session close. */ export declare class InMemoryAgentFeedbackItemsBackend extends Disposable implements IAgentFeedbackItemsBackend { private readonly _onDidChangeItems; readonly onDidChangeItems: Event; /** sessionResource → feedback items (insertion order; display order applied on read) */ private readonly _bySession; private readonly _sessionResourceByKey; getItems(sessionResource: URI): readonly IAgentFeedback[]; hasLoaded(_sessionResource: URI): boolean; upsert(feedback: IAgentFeedback): void; remove(sessionResource: URI, feedbackId: string): void; clear(sessionResource: URI): void; getSessionsWithItems(): URI[]; } /** * Feedback store backed by the agent host's annotations channel. Feedback * items round-trip as {@link Annotation}s on `/annotations`, mutated * via the `annotations/set` upsert (and `annotations/removed`) actions, with * feedback semantics carried in {@link Annotation._meta}. * * A per-session subscription is acquired lazily and held while the session is * visible so reads are synchronous and server-driven changes surface via * {@link onDidChangeItems}. It is released once the session leaves the screen * and the host has acknowledged its feedback writes, and acquired again on the * next read. A local cache backs reads before the first snapshot arrives. */ export declare class AnnotationsAgentFeedbackItemsBackend extends Disposable implements IAgentFeedbackItemsBackend { private readonly _sessionsManagementService; private readonly _sessionsProvidersService; private readonly _sessionsService; private static readonly OWNER; private readonly _onDidChangeItems; readonly onDidChangeItems: Event; private readonly _channels; private readonly _channelBySession; private readonly _sessionResourceByKey; /** Optimistic local state, reconciled from each annotations snapshot/action. */ private readonly _cacheBySession; /** * Signature of the feedback set we last fired {@link onDidChangeItems} for, * per session. The annotations channel is shared and may carry non-feedback * annotations; comparing signatures means churn from those does not fire a * spurious feedback-items change (which would bump recency / navigation). */ private readonly _signatureBySession; /** * Sessions whose annotations snapshot has been received. Used to fire * {@link onDidChangeItems} exactly once when loading completes (even when the * loaded feedback set is empty), so consumers that seed feedback can wait for * the authoritative set before acting. */ private readonly _loadedBySession; private readonly _suspendedAnnotationsReconciliation; /** Sessions on screen, whose annotations subscriptions are held. */ private _visibleSessionKeys; /** Hidden sessions whose subscriptions are released once the host acknowledges their feedback writes. */ private readonly _releaseOnAcknowledgement; constructor(_sessionsManagementService: ISessionsManagementService, _sessionsProvidersService: ISessionsProvidersService, _sessionsService: ISessionsService); getItems(sessionResource: URI): readonly IAgentFeedback[]; hasLoaded(sessionResource: URI): boolean; upsert(feedback: IAgentFeedback): void; remove(sessionResource: URI, feedbackId: string): void; clear(sessionResource: URI): void; getSessionsWithItems(): URI[]; /** * Returns the annotations channel URI backing the given session's feedback, * or `undefined` when the session is not an agent-host session (or no channel * could be resolved). Each feedback item id is an annotation id on this * channel, so callers can reference specific comments by id. */ getAnnotationsChannelResource(sessionResource: URI): URI | undefined; private _hasSnapshot; private _decode; /** * Fire {@link onDidChangeItems} only when the session's feedback set actually * changed. The annotations channel is generic and may carry annotations from * other features; without this guard their churn would bump feedback recency * ordering and navigation even though no feedback changed. */ private _onAnnotationsChange; private _emitIfChanged; /** * A stable signature of the visible feedback state, sorted by id. */ private _feedbackSignature; private _cacheUpsert; private _cacheRemove; private _suspendChannel; private _releaseChannel; /** * Releases the subscription of every session that is no longer visible; the * next read acquires it again. */ private _releaseHiddenChannels; /** * Releases a hidden session's subscription. A session with feedback keeps * its last known items, so reads stay consistent while the snapshot reloads. */ private _releaseHiddenChannel; private _ensureChannel; }