import type * as vscode from 'vscode';
import { IConfigurationService } from '../../../platform/configuration/common/configurationService';
import { DocumentId } from '../../../platform/inlineEdits/common/dataTypes/documentId';
import { InlineEditRequestLogContext } from '../../../platform/inlineEdits/common/inlineEditLogContext';
import { ObservableWorkspace } from '../../../platform/inlineEdits/common/observableWorkspace';
import { IStatelessNextEditProvider } from '../../../platform/inlineEdits/common/statelessNextEditProvider';
import { IHistoryContextProvider } from '../../../platform/inlineEdits/common/workspaceEditTracker/historyContextProvider';
import { NesXtabHistoryTracker } from '../../../platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker';
import { ILogService } from '../../../platform/log/common/logService';
import { IRequestLogger } from '../../../platform/requestLogger/common/requestLogger';
import { ISnippyService } from '../../../platform/snippy/common/snippyService';
import { IExperimentationService } from '../../../platform/telemetry/common/nullExperimentationService';
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
import { Disposable, IDisposable } from '../../../util/vs/base/common/lifecycle';
import { NesChangeHint } from '../common/nesTriggerHint';
import { DebugRecorder } from './debugRecorder';
import { LlmNESTelemetryBuilder } from './nextEditProviderTelemetry';
import { INextEditResult, NextEditResult } from './nextEditResult';
export interface NESInlineCompletionContext extends vscode.InlineCompletionContext {
    enforceCacheDelay: boolean;
    changeHint?: NesChangeHint;
}
export declare enum NesOutcome {
    Accepted = "accepted",
    Rejected = "rejected",
    Ignored = "ignored"
}
export interface INextEditProvider<T extends INextEditResult, TTelemetry, TData = void> extends IDisposable {
    readonly ID: string;
    getNextEdit(docId: DocumentId, context: NESInlineCompletionContext, logContext: InlineEditRequestLogContext, cancellationToken: CancellationToken, telemetryBuilder: TTelemetry, data?: TData): Promise<T>;
    handleShown(suggestion: T): void;
    handleAcceptance(docId: DocumentId, suggestion: T): void;
    handleRejection(docId: DocumentId, suggestion: T): void;
    handleIgnored(docId: DocumentId, suggestion: T, supersededBy: INextEditResult | undefined): void;
    lastRejectionTime: number;
    lastTriggerTime: number;
    lastOutcome: NesOutcome | undefined;
}
export declare class NextEditProvider extends Disposable implements INextEditProvider<NextEditResult, LlmNESTelemetryBuilder> {
    private readonly _workspace;
    private readonly _statelessNextEditProvider;
    private readonly _historyContextProvider;
    private readonly _xtabHistoryTracker;
    private readonly _debugRecorder;
    private readonly _configService;
    private readonly _snippyService;
    private readonly _logService;
    private readonly _expService;
    private readonly _requestLogger;
    readonly ID: string;
    private readonly _rejectionCollector;
    private readonly _nextEditCache;
    private _pendingStatelessNextEditRequest;
    private readonly _specManager;
    private _lastShownTime;
    /** The requestId of the last shown suggestion. We store only the requestId (not the object) to avoid preventing garbage collection. */
    private _lastShownSuggestionId;
    private _lastRejectionTime;
    get lastRejectionTime(): number;
    private _lastTriggerTime;
    get lastTriggerTime(): number;
    private _lastOutcome;
    get lastOutcome(): NesOutcome | undefined;
    private _lastNextEditResult;
    private _shouldExpandEditWindow;
    private _logger;
    constructor(_workspace: ObservableWorkspace, _statelessNextEditProvider: IStatelessNextEditProvider, _historyContextProvider: IHistoryContextProvider, _xtabHistoryTracker: NesXtabHistoryTracker, _debugRecorder: DebugRecorder | undefined, _configService: IConfigurationService, _snippyService: ISnippyService, _logService: ILogService, _expService: IExperimentationService, _requestLogger: IRequestLogger);
    /**
     * Cancels the in-flight stateless next-edit request when the document it
     * was issued for has diverged from the request's expected post-edit state.
     *
     * Invoked from the per-document `runOnChange` autorun in the constructor
     * whenever an open document's value changes. The pending request was built
     * against a specific snapshot (`documentAfterEdits`); if the user has since
     * typed something that makes the current value differ from that snapshot,
     * the result would no longer be applicable and is cancelled eagerly.
     *
     * Skipped when:
     * - the `InlineEditsAsyncCompletions` experiment is enabled (that path
     *   tolerates divergence and rebases later), or
     * - there is no pending request, or
     * - the changed document is not the one the pending request targets.
     *
     * Note: this only handles the regular pending stateless request. Speculative
     * requests have their own divergence handling via
     * `SpeculativeRequestManager.onActiveDocumentChanged` (trajectory check).
     */
    private _cancelPendingRequestDueToDocChange;
    getNextEdit(docId: DocumentId, context: NESInlineCompletionContext, logContext: InlineEditRequestLogContext, cancellationToken: CancellationToken, telemetryBuilder: LlmNESTelemetryBuilder): Promise<NextEditResult>;
    private _getNextEditCanThrow;
    private determineNesConfigs;
    private _processDoc;
    private fetchNextEdit;
    private _joinNextEditRequest;
    private _logRebaseFailure;
    private _executeNewNextEditRequest;
    private _hookupCancellation;
    private computeMinimumResponseDelay;
    handleShown(suggestion: NextEditResult): void;
    private _triggerSpeculativeRequest;
    /**
     * Creates and starts a speculative request for the post-edit document state.
     * The request will populate the cache so that when the user accepts the suggestion,
     * the next NES request can reuse or find the result in cache.
     */
    private _createSpeculativeRequest;
    /**
     * Runs the provider call for a speculative request and caches results.
     */
    private _runSpeculativeProviderCall;
    private static shiftSelectionAfterEditWindow;
    handleAcceptance(docId: DocumentId, suggestion: NextEditResult): void;
    handleRejection(docId: DocumentId, suggestion: NextEditResult): void;
    handleIgnored(docId: DocumentId, suggestion: NextEditResult, supersededBy: INextEditResult | undefined): void;
    private runSnippy;
    private _addLiveLogContextEntry;
    clearCache(): void;
}
export declare class NextEditFetchRequest {
    readonly opportunityId: string;
    readonly log: InlineEditRequestLogContext;
    readonly providerRequestStartDateTime: number | undefined;
    readonly isSpeculative: boolean;
    readonly headerRequestId: string;
    constructor(opportunityId: string, log: InlineEditRequestLogContext, providerRequestStartDateTime: number | undefined, isSpeculative: boolean, headerRequestId?: string);
}
//# sourceMappingURL=nextEditProvider.d.ts.map