import { Event } from "../../../../base/common/event.js"; import { Disposable, IDisposable } from "../../../../base/common/lifecycle.js"; import { IObservable } from "../../../../base/common/observable.js"; import { URI } from "../../../../base/common/uri.js"; import { IRange } from "../../../../editor/common/core/range.js"; import { IInstantiationService } from "../../../../platform/instantiation/common/instantiation.js"; import { IChatEditingService } from "../../../../workbench/contrib/chat/common/editing/chatEditingService.service.js"; import { ISessionsManagementService } from "../../../services/sessions/common/sessionsManagement.service.js"; import { ISessionsService } from "../../../services/sessions/browser/sessionsService.service.js"; import { ISessionsProvidersService } from "../../../services/sessions/browser/sessionsProvidersService.service.js"; import { IAgentFeedbackContext } from "./agentFeedbackEditorUtils.js"; import { IEditorService } from "../../../../workbench/services/editor/common/editorService.service.js"; import { IChatWidgetService } from "../../../../workbench/contrib/chat/browser/chat.service.js"; import { ILogService } from "../../../../platform/log/common/log.service.js"; import { IFeedbackPullRequest } from "../../../../platform/agentHost/common/meta/agentFeedbackAnnotations.js"; import { ICodeReviewSuggestion } from "../../codeReview/browser/codeReviewService.js"; import { ISession, ISessionFileChange } from "../../../services/sessions/common/session.js"; import { AgentFeedbackKind, AgentFeedbackState, type IAgentFeedback } from "./agentFeedbackModel.js"; import { IAgentFeedbackService } from "./agentFeedbackService.service.js"; export { AgentFeedbackKind, AgentFeedbackState, type IAgentFeedback }; /** Shared feedback scope for every undefined or uncreated active session. */ export declare const AGENT_FEEDBACK_NEW_SESSION_RESOURCE: URI; export interface INavigableSessionComment { readonly id: string; } /** Options for {@link IAgentFeedbackService.acceptFeedback}. */ export interface IAcceptFeedbackOptions { /** * Flag the accepted item as pending reveal to the agent so the * `viewUnreviewedComments` server tool returns it (and only the items * revealed in the same invocation). */ readonly revealToAgent?: boolean; } export interface IAgentFeedbackChangeEvent { readonly sessionResource: URI; readonly feedbackItems: readonly IAgentFeedback[]; } export interface IAgentFeedbackNavigationBearing { readonly activeIdx: number; readonly totalCount: number; } export interface IAgentFeedbackCommentRevealEvent { readonly sessionResource: URI; readonly commentId: string; readonly resourceUri: URI; } /** Fired when a brand-new agent feedback item is added by the user. */ export interface IAgentFeedbackAddedEvent { readonly sessionResource: URI; readonly feedback: IAgentFeedback; readonly hasExistingFeedbackForFile: boolean; } /** Fired when an existing PR/code-review comment is converted into agent feedback. */ export interface IAgentFeedbackConvertedEvent { readonly sessionResource: URI; readonly feedback: IAgentFeedback; readonly kind: AgentFeedbackKind.AgentReview | AgentFeedbackKind.PRReview; readonly hasExistingFeedbackForFile: boolean; } /** Fired when a reply is appended to an existing feedback thread. */ export interface IAgentFeedbackReplyAddedEvent { readonly sessionResource: URI; readonly feedback: IAgentFeedback; readonly replyCount: number; } /** Fired when feedback items are submitted to the agent for action. */ export interface IAgentFeedbackSubmittedEvent { readonly sessionResource: URI; readonly totalCount: number; readonly userCount: number; readonly codeReviewCount: number; readonly prReviewCount: number; readonly replyCount: number; } /** Controls which accepted feedback items are submitted and the request used for them. */ export interface ISubmitFeedbackOptions { readonly query?: string; /** Selected feedback for Agent Host requests. Other providers submit their complete reactive attachment. */ readonly feedbackIds?: readonly string[]; /** * The chat to send the request to, when it differs from the feedback's * session resource: feedback is read and marked under the session, and the * request goes to this chat's widget. */ readonly targetChat?: URI; readonly onRequestAccepted?: () => void; } export declare function shouldIncludeRawPRReviewComments(agentFeedbackService: IAgentFeedbackService, sessionResource: URI): boolean; export declare class AgentFeedbackService extends Disposable implements IAgentFeedbackService { private readonly _chatEditingService; private readonly _sessionsManagementService; private readonly _sessionsService; private readonly _sessionsProvidersService; private readonly _editorService; private readonly _chatWidgetService; private readonly _logService; private readonly _instantiationService; readonly _serviceBrand: undefined; private readonly _onDidChangeFeedback; readonly onDidChangeFeedback: Event; private readonly _onDidChangeFeedbackVisibility; readonly onDidChangeFeedbackVisibility: Event; private readonly _onDidChangeNavigation; readonly onDidChangeNavigation: Event; private readonly _onDidRevealSessionComment; readonly onDidRevealSessionComment: Event; private readonly _onDidChangeFeedbackScope; readonly onDidChangeFeedbackScope: Event; private readonly _onDidAddFeedback; readonly onDidAddFeedback: Event; private readonly _onDidConvertFeedback; readonly onDidConvertFeedback: Event; private readonly _onDidAddReply; readonly onDidAddReply: Event; private readonly _onDidSubmitFeedback; readonly onDidSubmitFeedback: Event; readonly activeFeedbackSessionResource: IObservable; /** sessionResource → recency sequence (set on every feedback change) */ private readonly _sessionUpdatedOrder; private _sessionUpdatedSequence; private readonly _navigationAnchorBySession; private readonly _visibleResolvedFeedbackIds; /** fileResource → sessionResource active when the editor for that file was first seen */ private readonly _fileToSession; private readonly _explicitResourceScopes; /** * The last {@link _resolveSession} lookup, hit or miss. Feedback resolution * runs once per resource of the active editor, so a Changes multi-diff asks * for the same session thousands of times in a row. A single entry is enough * to collapse that run; it is dropped whenever the session catalog changes. */ private _lastResolvedSession; /** Workspace the shared new-session comments are bound to; `undefined` when there are none. */ private _boundNewSessionWorkspaceKey; /** Workspace of the draft the new-session scope currently targets. */ private readonly _newSessionWorkspaceKey; /** In-memory store used for every non-agent-host provider. */ private readonly _inMemoryBackend; /** Annotations-channel-backed store for agent-host sessions; created lazily. */ private _annotationsBackend; constructor(_chatEditingService: IChatEditingService, _sessionsManagementService: ISessionsManagementService, _sessionsService: ISessionsService, _sessionsProvidersService: ISessionsProvidersService, _editorService: IEditorService, _chatWidgetService: IChatWidgetService, _logService: ILogService, _instantiationService: IInstantiationService); /** * Drops this service's per-session bookkeeping for a deleted session. The * backend is left alone: its channel is already released with the session, * and clearing it would write to a store that no longer exists. */ private _forgetSession; /** * The shared new-session comments belong to the workspace of the draft they * were written for. An empty set releases the binding so the next draft can * adopt its own workspace instead of being measured against a stale one. */ private _rebindNewSessionWorkspace; /** Resolves the storage backend that owns feedback for the given session. */ private _backendForSession; private _getAnnotationsBackend; private _backends; /** * Centralized handler for backend item changes (local mutations and * server-driven updates). Maintains recency ordering and re-broadcasts the * generic feedback / navigation change events. */ private _handleBackendChange; private _trackVisibleEditorResources; /** * Resolves a session by resource, answering from the active session facade * whenever it is the one asked for and otherwise from the last lookup. * `ISessionsManagementService.getSession` rebuilds every provider's session * catalog and then scans it linearly, which is far too expensive for the * per-resource lookups this service performs while a Changes editor with * thousands of resources is open. */ private _resolveSession; getSessionForFile(resourceUri: URI): ISession | undefined; getChatChanges(sessionResource: URI): readonly ISessionFileChange[]; getFeedbackSessionResource(resourceUri: URI): URI | undefined; registerFeedbackResourceScope(resourceUri: URI, sessionResource: URI): IDisposable; /** * Whether the given file is eligible for agent feedback. The Output view * renders into a code editor but is not a real file the user can give * feedback on, and a terminal shown as an editor has no document at all, * so neither is in the scope of a session (nor shows its comments). */ private _isFileEligibleForFeedback; addFeedback(sessionResource: URI, resourceUri: URI, range: IRange, text: string, suggestion?: ICodeReviewSuggestion, context?: IAgentFeedbackContext, sourcePRReviewCommentId?: string, kind?: AgentFeedbackKind, state?: AgentFeedbackState, sourcePullRequest?: IFeedbackPullRequest, sourcePRReviewCommentAuthor?: string): IAgentFeedback; acceptFeedback(sessionResource: URI, feedbackId: string, options?: IAcceptFeedbackOptions): void; removeFeedback(sessionResource: URI, feedbackId: string): void; updateFeedback(sessionResource: URI, feedbackId: string, newText: string): void; updateFeedbackSourcePullRequest(sessionResource: URI, feedbackId: string, sourcePullRequest: IFeedbackPullRequest, sourcePRReviewCommentAuthor?: string): void; setFeedbackResolved(sessionResource: URI, feedbackId: string, resolved: boolean): void; addReply(sessionResource: URI, feedbackId: string, replyText: string): void; getFeedback(sessionResource: URI): readonly IAgentFeedback[]; showFeedbackInEditor(sessionResource: URI, feedbackIds: readonly string[]): void; hideFeedbackInEditor(sessionResource: URI, feedbackId: string): void; getVisibleResolvedFeedbackIds(sessionResource: URI): ReadonlySet; hasLoadedFeedback(sessionResource: URI): boolean; getMostRecentSessionForResource(resourceUri: URI): URI | undefined; private _sessionContainsResource; revealFeedback(sessionResource: URI, feedbackId: string): Promise; revealSessionComment(sessionResource: URI, commentId: string, resourceUri: URI, range: IRange): Promise; private _getSessionChange; getNextFeedback(sessionResource: URI, next: boolean): IAgentFeedback | undefined; getNextNavigableItem(sessionResource: URI, items: readonly T[], next: boolean): T | undefined; setNavigationAnchor(sessionResource: URI, itemId: string | undefined): void; getNavigationBearing(sessionResource: URI, items?: readonly INavigableSessionComment[]): IAgentFeedbackNavigationBearing; clearFeedback(sessionResource: URI): void; addFeedbackAndSubmit(sessionResource: URI, resourceUri: URI, range: IRange, text: string, suggestion?: ICodeReviewSuggestion, context?: IAgentFeedbackContext, sourcePRReviewCommentId?: string, kind?: AgentFeedbackKind): Promise; isAgentHostSession(sessionResource: URI): boolean; submitFeedback(sessionResource: URI, options?: ISubmitFeedbackOptions): Promise; /** * Sends the `/act-on-feedback` request and marks the accepted feedback as * submitted as soon as the request has been accepted by the chat widget. * The request is queued when the agent is still working on another request, * in which case awaiting {@link IChatWidget.acceptInput} would only resolve * once that queued request eventually runs — the feedback items must move to * the submitted state right away. */ private _sendActOnFeedbackRequest; markFeedbackSubmitted(sessionResource: URI, feedbackIds?: readonly string[]): void; }