import { IDisposable } from "../../../../base/common/lifecycle.js"; import { DebugOwner, IObservable } from "../../../../base/common/observable.js"; import { IdleDeadline } from "../../../../base/common/async.js"; import { URI } from "../../../../base/common/uri.js"; import type { AgentHostUriMapper, IAgentHostResourceUriMapper } from "../../../../platform/agentHost/common/agentHostUri.js"; import { type Customization, type PluginCustomization, type ClientPluginCustomization, type Turn } from "../../../../platform/agentHost/common/state/sessionState.js"; import { ISessionChatCustomization } from "./sessionChatCustomizations.js"; /** * A reference to a customization extracted from a chat's output stream. * * References are deliberately resolved **against nothing**: they capture only * what the turn said, so a completed turn can be parsed once and cached even * though the session's customization tree keeps changing underneath. */ export declare enum CustomizationRefKind { /** An MCP server addressed by customization id (exact, from the tool contributor). */ Mcp = "mcp", /** A file system path mentioned by a tool call. */ Path = "path", /** A skill invoked by name. */ Skill = "skill" } export interface ICustomizationRef { readonly kind: CustomizationRefKind; readonly value: string; } export declare function customizationRefsEqual(a: readonly ICustomizationRef[], b: readonly ICustomizationRef[]): boolean; export declare function sessionChatCustomizationsEqual(a: readonly ISessionChatCustomization[], b: readonly ISessionChatCustomization[]): boolean; /** Maps a `vscode-agent-host-file:` URI, which names a published same-host plugin resource, back to client space; other URIs are unchanged. */ export declare function fromAgentHostFileUri(uri: URI, resourceUris: Pick): URI; /** Resolves host-authored resources and this client's plugin sources; foreign client sources are opaque. */ export declare function getAgentHostCustomizationUri(uri: URI, connection: { readonly clientId?: string; readonly resourceUris: IAgentHostResourceUriMapper; }, container?: Pick): URI | undefined; /** Publishes same-host client plugins in place without changing their client-side identity. */ export declare function toAgentHostClientCustomization(customization: ClientPluginCustomization, resourceUris: IAgentHostResourceUriMapper): ClientPluginCustomization; /** Extracts the customization references contained in a turn's response parts. */ export declare function parseTurnCustomizationRefs(responseParts: Turn["responseParts"]): readonly ICustomizationRef[]; export interface ICustomizationRefChatState { readonly turns?: readonly { readonly id: string; readonly responseParts: Turn["responseParts"]; }[]; readonly activeTurn?: { readonly id?: string; readonly responseParts: Turn["responseParts"]; }; } /** * Creates a stateful parser that turns a chat state into its customization * references, **parsing each completed turn at most once**. * * Completed turns are immutable once finalized, so each is parsed once and * memoized by turn id. Only the in-progress `activeTurn` is re-parsed on every * call, making streamed-delta updates O(active turn) rather than O(all turns). */ export declare function createIncrementalChatCustomizationRefsParser(parseTurn?: (responseParts: Turn["responseParts"]) => readonly ICustomizationRef[]): (chatState: ICustomizationRefChatState) => readonly ICustomizationRef[]; /** Indexes host-side references while mapping their resources into client space for presentation. */ export declare class CustomizationIndex { private readonly _workspaceRoots; private readonly _byId; private readonly _byPath; private readonly _byContainerPath; private readonly _bySkillName; private readonly _resolvedPaths; /** Tokens looked up on this index; only these are worth carrying to the next one. */ private readonly _usedPathTokens; private readonly _resolvedPathDependencies; private readonly _roots; constructor(customizations: readonly Customization[] | undefined, _workspaceRoots?: readonly URI[], mapHostUri?: AgentHostUriMapper, previous?: CustomizationIndex, clientId?: string); get isEmpty(): boolean; private _add; private _resolvePath; protected _resolvePathUncached(token: string): ISessionChatCustomization | undefined; private _reuseResolvedPaths; resolve(ref: ICustomizationRef): ISessionChatCustomization | undefined; } export type CustomizationIndexFactory = (customizations: readonly Customization[] | undefined, workspaceRoots: readonly URI[], mapHostUri: AgentHostUriMapper | undefined, previous: CustomizationIndex | undefined, clientId?: string) => CustomizationIndex; /** * Creates a customization index whose identity is stable across equivalent * protocol snapshots and workspace-root emissions. Resolved paths are carried * across rebuilds unless a changed customization affects them, and are dropped when * the optional `options.scope` changes (for example when switching chats). */ export declare function createCustomizationIndexObservable(owner: DebugOwner, customizations: IObservable, workspaceRoots: IObservable, mapHostUri?: IObservable, { createIndex, scope, clientId }?: { createIndex?: CustomizationIndexFactory; scope?: IObservable; clientId?: IObservable; }): IObservable; /** * Resolves parsed references to customizations, keeping first-appearance order * and dropping duplicates. */ export declare function resolveChatCustomizations(refs: readonly ICustomizationRef[], index: CustomizationIndex): readonly ISessionChatCustomization[]; /** Runs customization work in cooperative slices, outside the task that requested it. */ export interface ICustomizationJobScheduler { now(): number; /** Runs `callback` in a later task. Disposing cancels it. */ schedule(callback: (deadline?: IdleDeadline) => void): IDisposable; } /** Idle-time scheduler; the timeout keeps work moving while the host is busy streaming. */ export declare const idleCustomizationJobScheduler: ICustomizationJobScheduler; /** Time one slice of customization work may take before yielding. */ export declare const customizationJobSliceBudgetMs = 8; export interface IProgressiveChatCustomizationsOptions { /** Cached per-turn results are dropped when this changes (for example when switching chats). */ readonly scope?: IObservable; readonly scheduler?: ICustomizationJobScheduler; readonly sliceBudgetMs?: number; readonly parseTurn?: (responseParts: Turn["responseParts"]) => readonly ICustomizationRef[]; } /** * Projects a chat's customizations without doing transcript-wide work in the * task that reads it. * * Completed turns are parsed and resolved in time-budgeted slices on the * scheduler, oldest first, and the result grows turn by turn. Only the active * turn is processed synchronously, so streamed updates stay immediate once the * completed turns are done. When the index changes, the previous results stay * visible until each turn is re-resolved. Once the work completes the result * equals {@link resolveChatCustomizations} over all references. * * The work only runs while the returned observable is observed (and for * unobserved reads, until it completes): losing the last observer cancels the * pending slice, while per-turn results stay cached. */ export declare function createProgressiveChatCustomizations(owner: DebugOwner, chatState: IObservable, index: IObservable, { scope, scheduler, sliceBudgetMs, parseTurn }?: IProgressiveChatCustomizationsOptions): IObservable;