import { AIVariableResolutionRequest, CompactionMessage, CompactionSettings, GenericCapabilitySelections, LanguageModelMessage, ReasoningSettings, ResolvedAIContextVariable, ServerToolUseMessage, TextMessage, ThinkingMessage, ToolCallResult, ToolRequest, ToolResultMessage, ToolUseMessage } from '@theia/ai-core'; import { CancellationToken, CancellationTokenSource, Command, Disposable, DisposableCollection, Emitter, Event, URI } from '@theia/core'; import { MarkdownString, MarkdownStringImpl } from '@theia/core/lib/common/markdown-rendering'; import { Position } from '@theia/core/shared/vscode-languageserver-protocol'; import { ChangeSet, ChangeSetElement, ChangeSetImpl, ChatUpdateChangeSetEvent } from './change-set'; import { ChatAgentLocation } from './chat-agents'; import { SerializedChatModel, SerializableChatRequestData, SerializableChatResponseContentData, SerializableChatResponseData, SerializableHierarchy, SerializableHierarchyBranch, SerializableParsedRequest } from './chat-model-serialization'; import { ParsedChatRequest } from './parsed-chat-request'; export { ChangeSet, ChangeSetElement, ChangeSetImpl }; /********************** * INTERFACES AND TYPE GUARDS **********************/ export type ChatChangeEvent = ChatAddRequestEvent | ChatAddResponseEvent | ChatAddVariableEvent | ChatRemoveVariableEvent | ChatSetVariablesEvent | ChatRemoveRequestEvent | ChatSuggestionsChangedEvent | ChatUpdateChangeSetEvent | ChatEditRequestEvent | ChatEditCancelEvent | ChatEditSubmitEvent | ChatResponseChangedEvent | ChatChangeHierarchyBranchEvent | ChatInteractionNeededEvent | ChatSessionStatusChangedEvent | ChatSettingsChangedEvent; export interface ChatAddRequestEvent { kind: 'addRequest'; request: ChatRequestModel; } export interface ChatEditRequestEvent { kind: 'enableEdit'; request: EditableChatRequestModel; branch: ChatHierarchyBranch; } export interface ChatEditCancelEvent { kind: 'cancelEdit'; request: EditableChatRequestModel; branch: ChatHierarchyBranch; } export interface ChatEditSubmitEvent { kind: 'submitEdit'; request: EditableChatRequestModel; branch: ChatHierarchyBranch; newRequest: ChatRequest; } export interface ChatChangeHierarchyBranchEvent { kind: 'changeHierarchyBranch'; branch: ChatHierarchyBranch; } export interface ChatAddResponseEvent { kind: 'addResponse'; response: ChatResponseModel; } export interface ChatAddVariableEvent { kind: 'addVariable'; } export interface ChatRemoveVariableEvent { kind: 'removeVariable'; } export interface ChatSetVariablesEvent { kind: 'setVariables'; } export interface ChatSuggestionsChangedEvent { kind: 'suggestionsChanged'; suggestions: ChatSuggestion[]; } export interface ChatResponseChangedEvent { kind: 'responseChanged'; } export interface ChatInteractionNeededEvent { kind: 'interactionNeeded'; contentPart: InteractiveContent & ChatResponseContent; } export interface ChatSessionStatusChangedEvent { kind: 'statusChanged'; status: ChatSessionStatus; } export interface ChatSettingsChangedEvent { kind: 'settingsChanged'; settings: ChatSessionSettings; } export declare namespace ChatChangeEvent { function isChangeSetEvent(event: ChatChangeEvent): event is ChatUpdateChangeSetEvent; function isInteractionNeededEvent(event: ChatChangeEvent): event is ChatInteractionNeededEvent; function isStatusChangedEvent(event: ChatChangeEvent): event is ChatSessionStatusChangedEvent; } export type ChatRequestRemovalReason = 'removal' | 'resend' | 'adoption'; export interface ChatRemoveRequestEvent { kind: 'removeRequest'; requestId: string; responseId?: string; reason: ChatRequestRemovalReason; } /** * A model that contains information about a chat request that may branch off. * * The hierarchy of requests is represented by a tree structure. * - The root of the tree is the initial request * - Within each branch, the requests are stored in a list. Those requests are the alternatives to the original request. * Each of those items can have a next branch, which is the next request in the hierarchy. */ export interface ChatRequestHierarchy extends Disposable { readonly branch: ChatHierarchyBranch; onDidChange: Event>; append(request: TRequest): ChatHierarchyBranch; activeRequests(): TRequest[]; activeBranches(): ChatHierarchyBranch[]; findRequest(requestId: string): TRequest | undefined; findBranch(requestId: string): ChatHierarchyBranch | undefined; notifyChange(event: ChangeActiveBranchEvent): void; toSerializable(): SerializableHierarchy; } export interface ChangeActiveBranchEvent { branch: ChatHierarchyBranch; item: ChatHierarchyBranchItem; } /** * A branch of the chat request hierarchy. * It contains a list of items, each representing a request. * Those items can have a next branch, which is the next request in the hierarchy. */ export interface ChatHierarchyBranch extends Disposable { readonly id: string; readonly hierarchy: ChatRequestHierarchy; readonly previous?: ChatHierarchyBranch; readonly items: ChatHierarchyBranchItem[]; readonly activeBranchIndex: number; next(): ChatHierarchyBranch | undefined; get(): TRequest; add(request: TRequest): void; remove(request: TRequest | string): void; /** * Create a new branch by inserting it as the next branch of the active item. */ continue(request: TRequest): ChatHierarchyBranch; enable(request: TRequest): ChatHierarchyBranchItem; enablePrevious(): ChatHierarchyBranchItem; enableNext(): ChatHierarchyBranchItem; succeedingBranches(): ChatHierarchyBranch[]; } export interface ChatHierarchyBranchItem { readonly element: TRequest; readonly next?: ChatHierarchyBranch; } export interface CommonChatSessionSettings { /** * Language model (or alias) id to use for this session only, overriding the agent's default. * New sessions start without an override and use the agent's configured model. Cleared to * revert to the default. */ modelId?: string; /** Reasoning configuration for this session; applied to reasoning-capable models. */ reasoning?: ReasoningSettings; /** Per-session tool confirmation timeout in seconds. Overrides the global preference when set. */ confirmationTimeout?: number; /** Per-session server-side compaction settings; set values win over the per-provider and global settings. */ compaction?: CompactionSettings; } export interface ChatSessionSettings { /** * Theia-specific common settings processed by Theia. * This key is excluded when passing settings to LLM providers. */ commonSettings?: CommonChatSessionSettings; /** * Allow arbitrary provider-specific settings. * These correspond to the "Advanced Settings (JSON)" in the UI * and are passed directly to the LLM. */ [key: string]: unknown; } /** * Aggregated, observable status of a chat session, derived from the state of the session's last request. */ export type ChatSessionStatus = /** No request is in progress. The last request, if any, completed successfully or was canceled. */ 'idle' /** A request is in progress. */ | 'running' /** A tool call requires user confirmation before it can be executed. */ | 'awaitingApproval' /** An approved or confirmation-free tool call is still executing. */ | 'awaitingToolCall' /** The agent is waiting for user input, e.g. an answer to a structured question. */ | 'awaitingInput' /** The last request ended in an error. */ | 'failed'; export declare namespace ChatSessionStatus { /** * All {@link ChatSessionStatus} values, e.g. for schema declarations. Derived from an * exhaustive record so that adding a status without listing it here fails to compile. */ const VALUES: readonly ChatSessionStatus[]; /** * Whether a request is in progress in this status, including the states waiting on the user or a tool. */ function isInProgress(status: ChatSessionStatus): boolean; /** * Whether the session is blocked on the user, i.e. a tool approval or another input is required to proceed. */ function requiresUserAction(status: ChatSessionStatus): boolean; /** * Derives the session status from the state of the given request (usually the session's last request). */ function fromRequest(request: ChatRequestModel | undefined): ChatSessionStatus; } export interface ChatModel { readonly onDidChange: Event; readonly id: string; readonly location: ChatAgentLocation; readonly context: ChatContextManager; readonly suggestions: readonly ChatSuggestion[]; readonly settings?: ChatSessionSettings; readonly changeSet: ChangeSet; /** * Aggregated status of this session, derived from the state of its last request. * Changes are announced via {@link onDidChange} with a {@link ChatSessionStatusChangedEvent}. */ readonly status: ChatSessionStatus; /** ID of the root session in the delegation chain. For delegated sessions, this points to the topmost session where task contexts are stored. */ rootSessionId?: string; /** ID of the immediate parent session that delegated this one. Undefined for top-level sessions. */ parentSessionId?: string; getRequests(): ChatRequestModel[]; getBranches(): ChatHierarchyBranch[]; isEmpty(): boolean; toSerializable(): SerializedChatModel; } export interface ChatSuggestionCallback { kind: 'callback'; callback: () => unknown; content: string | MarkdownString; } export declare namespace ChatSuggestionCallback { function is(candidate: ChatSuggestion): candidate is ChatSuggestionCallback; function containsCallbackLink(candidate: ChatSuggestion): candidate is ChatSuggestionCallback; } export type ChatSuggestion = string | MarkdownString | ChatSuggestionCallback; export interface ChatContextManager { onDidChange: Event; getVariables(): readonly AIVariableResolutionRequest[]; addVariables(...variables: AIVariableResolutionRequest[]): void; deleteVariables(...indices: number[]): void; clear(): void; } export interface ChangeSetDecoration { readonly priority?: number; readonly additionalInfoSuffixIcon?: string[]; } export interface ChatRequest { readonly text: string; readonly displayText?: string; /** * If the request has been triggered in the context of * an existing request, this id will be set to the id of the * referenced request. */ readonly referencedRequestId?: string; readonly variables?: readonly AIVariableResolutionRequest[]; readonly modeId?: string; /** * Capability overrides for this request. * Maps capability fragment IDs to enabled/disabled state. * Only includes capabilities that differ from their default value. */ readonly capabilityOverrides?: Record; /** * Generic capability selections for this request. * Contains user-selected skills, functions, MCP tools, etc. * from the capabilities panel dropdowns. */ readonly genericCapabilitySelections?: GenericCapabilitySelections; /** * Server tool selections for this request, keyed by model vendor. Only the entry matching * the actually selected model's vendor is applied when sending the request. */ readonly serverToolSelections?: Record; } export interface ChatContext { variables: ResolvedAIContextVariable[]; } export interface ChatRequestModel { readonly id: string; readonly session: ChatModel; readonly request: ChatRequest; readonly response: ChatResponseModel; readonly message: ParsedChatRequest; readonly context: ChatContext; readonly agentId?: string; readonly data?: { [key: string]: unknown; }; toSerializable(): SerializableChatRequestData; } export declare namespace ChatRequestModel { function is(request: unknown): request is ChatRequestModel; function isInProgress(request: ChatRequestModel | undefined): boolean; } export interface EditableChatRequestModel extends ChatRequestModel { readonly isEditing: boolean; editContextManager: ChatContextManagerImpl; enableEdit(): void; cancelEdit(): void; submitEdit(newRequest: ChatRequest): void; } export declare namespace EditableChatRequestModel { function is(request: unknown): request is EditableChatRequestModel; function isEditing(request: unknown): request is EditableChatRequestModel; } export interface ChatProgressMessage { kind: 'progressMessage'; id: string; status: 'inProgress' | 'completed' | 'failed'; show: 'untilFirstContent' | 'whileIncomplete' | 'forever'; content: string; } /** * Interface for ChatResponseContent parts that require user interaction. * Content parts that implement this interface can be tracked by the delegation * renderer without content-type-specific checks. */ export interface InteractiveContent { /** Stable identifier for deduplication in pending interaction tracking. */ readonly interactionId: string | undefined; /** Whether the interaction has been resolved (e.g., confirmed/denied, option selected). */ readonly isResolved: boolean; /** Resolves when the interaction is resolved. Used for cleanup in delegation chains. */ readonly whenResolved: Promise; /** * Whether the interaction currently requires user action. Unlike {@link isResolved}, * this reflects the momentary state: e.g. a tool call whose confirmation was granted * is not yet resolved (the tool is still executing) but no longer awaits interaction. * When `undefined`, consumers should fall back to `!isResolved`. */ readonly isAwaitingInteraction?: boolean; } export declare namespace InteractiveContent { function is(content: unknown): content is InteractiveContent; } export interface ChatResponseContent { kind: string; /** * Represents the content as a string. Returns `undefined` if the content * is purely informational and/or visual and should not be included in the overall * representation of the response. */ asString?(): string | undefined; asDisplayString?(): string | undefined; merge?(nextChatResponseContent: ChatResponseContent): boolean; toLanguageModelMessage?(): LanguageModelMessage | LanguageModelMessage[]; toSerializable?(): SerializableChatResponseContentData; } export declare namespace ChatResponseContent { function is(obj: unknown): obj is ChatResponseContent; function hasAsString(obj: ChatResponseContent): obj is Required> & ChatResponseContent; function hasDisplayString(obj: ChatResponseContent): obj is Required> & ChatResponseContent; function hasMerge(obj: ChatResponseContent): obj is Required> & ChatResponseContent; function hasToLanguageModelMessage(obj: ChatResponseContent): obj is Required> & ChatResponseContent; } /** * Data interfaces for chat response content serialization. * These define the structure of the data property in SerializableChatResponseContentData. */ export interface TextContentData { content: string; } export interface ThinkingContentData { content: string; signature: string; } export interface CompactionContentData { provider: string; data: unknown; summary?: string; } export interface MarkdownContentData { content: string; } export interface InformationalContentData { content: string; } export interface CodeContentData { code: string; language?: string; location?: Location; } export interface ToolCallContentData { id?: string; name?: string; arguments?: string; result?: ToolCallResult; data?: Record; } export interface ServerToolCallContentData { id?: string; name?: string; arguments?: string; result?: ToolCallResult; data?: Record; } export interface CommandContentData { commandId?: string; commandLabel?: string; arguments?: unknown[]; } export interface HorizontalLayoutContentData { content: SerializableChatResponseContentData[]; } export interface ProgressContentData { message: string; } export interface ErrorContentData { message: string; stack?: string; } /** * Restored questions display the question, options, and any previously selected answer, * but do not allow new selections. */ export interface QuestionContentData { question: string; header?: string; options: { text: string; value?: string; description?: string; }[]; multiSelect?: boolean; selectedOption?: { text: string; value?: string; }; selectedOptions?: { text: string; value?: string; }[]; } export interface TextChatResponseContent extends Required { kind: 'text'; content: string; } export interface ErrorChatResponseContent extends ChatResponseContent { kind: 'error'; error: Error; } export interface MarkdownChatResponseContent extends Required { kind: 'markdownContent'; content: MarkdownString; } export interface CodeChatResponseContent extends ChatResponseContent { kind: 'code'; code: string; language?: string; location?: Location; } export interface HorizontalLayoutChatResponseContent extends ChatResponseContent { kind: 'horizontal'; content: ChatResponseContent[]; } export interface ToolCallChatResponseContent extends Required, InteractiveContent { kind: 'toolCall'; id?: string; name?: string; arguments?: string; finished: boolean; result?: ToolCallResult; /** Timeout in seconds for confirmation dialogs. 0 means no timeout. */ confirmationTimeout?: number; confirmed: Promise; /** Resolves when the tool call requires user confirmation (show Allow/Deny UI). */ needsUserConfirmation: Promise; /** * Whether the tool call is currently awaiting the user's confirmation decision, i.e. * {@link requestUserConfirmation} was called and the user has neither confirmed nor denied it yet. */ readonly isAwaitingUserConfirmation: boolean; whenFinished: Promise; /** * Provider-specific metadata about the tool call that the language model needs back on * subsequent turns (e.g. Google's `thoughtSignature`, cache pointers). The full record is * passed to the model via {@link toLanguageModelMessage} as `ToolUseMessage.data`. */ data?: Record; /** * Fires when the serialized form of this tool call changes outside of the agent's stream * (e.g. after a renderer persists intermediate state via {@link updateResult}). The * parent {@link ChatResponse} forwards this event so chat-session auto-save picks up * the change. */ readonly onDidChange: Event; confirm(): void; deny(reason?: string): void; cancelConfirmation(reason?: unknown): void; /** Signal that this tool call needs user confirmation. Resolves the needsUserConfirmation promise. */ requestUserConfirmation(): void; /** * Whether the tool execution is currently blocked waiting for user input provided * through the tool's own UI (e.g. an interactive wizard). Cleared when the tool * call finishes or {@link userInputHandled} is called. */ readonly isAwaitingUserInput: boolean; /** Signal that the tool execution is blocked waiting for user input. */ requestUserInput(): void; /** Signal that the tool execution is no longer waiting for user input. */ userInputHandled(): void; /** * Update the tool call's result without marking it finished. Use this to persist * intermediate state for long-running tools (e.g. the user-interaction wizard) so * progress survives chat-session reloads. On restore the tool call is always marked * finished (no live handler exists anymore), so a partial result must be * self-describing; consumers should not rely on `finished` to tell partial from final. */ updateResult(result: ToolCallResult): void; /** * Mark the tool call as completed with the given result. * * This is used to update the UI immediately when a tool finishes execution, * without waiting for all parallel tool calls to complete. The language model * batches tool results (via Promise.all) before yielding them to the stream, * so without this early completion signal, the UI wouldn't update until all * tools finish. The values set here will be overwritten by merge() when the * language model eventually yields the results, but they should be identical. */ complete(result: ToolCallResult): void; } /** * A tool the provider executed on its own infrastructure (a server tool). Unlike * {@link ToolCallChatResponseContent}, it has no confirmation members because it is * auto-approved/server-executed; the invocation and its result are surfaced together. */ export interface ServerToolCallChatResponseContent extends Required { kind: 'serverToolCall'; id?: string; name?: string; arguments?: string; finished: boolean; result?: ToolCallResult; /** Provider-specific metadata needed to faithfully reconstruct the server tool on replay. */ data?: Record; } export declare namespace ServerToolCallChatResponseContent { function is(obj: unknown): obj is ServerToolCallChatResponseContent; } export interface ThinkingChatResponseContent extends Required { kind: 'thinking'; content: string; signature: string; } export interface ProgressChatResponseContent extends Required { kind: 'progress'; message: string; } export interface Location { uri: URI; position: Position; } export declare namespace Location { function is(obj: unknown): obj is Location; } export interface CustomCallback { label: string; callback: () => Promise; } /** * A command chat response content represents a command that is offered to the user for execution. * It either refers to an already registered Theia command or provides a custom callback. * If both are given, the custom callback will be preferred. */ export interface CommandChatResponseContent extends ChatResponseContent { kind: 'command'; command?: Command; customCallback?: CustomCallback; arguments?: unknown[]; } /** * An informational chat response content represents a message that is purely informational and should not be included in the overall representation of the response. */ export interface InformationalChatResponseContent extends ChatResponseContent { kind: 'informational'; content: MarkdownString; } export declare namespace TextChatResponseContent { function is(obj: unknown): obj is TextChatResponseContent; } export declare namespace MarkdownChatResponseContent { function is(obj: unknown): obj is MarkdownChatResponseContent; } export declare namespace InformationalChatResponseContent { function is(obj: unknown): obj is InformationalChatResponseContent; } export declare namespace CommandChatResponseContent { function is(obj: unknown): obj is CommandChatResponseContent; } export declare namespace CodeChatResponseContent { function is(obj: unknown): obj is CodeChatResponseContent; } export declare namespace HorizontalLayoutChatResponseContent { function is(obj: unknown): obj is HorizontalLayoutChatResponseContent; } export declare namespace ToolCallChatResponseContent { function is(obj: unknown): obj is ToolCallChatResponseContent; interface DenialResult { denied: true; /** User-provided reason for the denial */ reason?: string; } function isDenialResult(result: unknown): result is DenialResult; /** * Checks if a tool call result contains an error. * Supports both ToolCallContent with ToolCallErrorResult items and legacy simple error format. */ function isErrorResult(result: unknown): boolean; /** * Extracts the error message from a tool call result. * Supports both ToolCallContent with ToolCallErrorResult items and legacy simple error format. */ function getErrorMessage(result: unknown): string | undefined; /** * Checks if a tool call result indicates the tool was not available. * This happens when the LLM tries to call a tool that wasn't provided in the request. */ function isNotAvailableResult(result: unknown): boolean; } /** * Represents a streaming delta update for tool call arguments. * This content type is used during streaming to append argument fragments * to an existing ToolCallChatResponseContent rather than replacing the full arguments. */ export interface ToolCallArgumentsDeltaContent extends ChatResponseContent { kind: 'toolCallArgumentsDelta'; /** The tool call ID this delta belongs to */ id: string; /** The argument fragment to append */ delta: string; } export declare namespace ToolCallArgumentsDeltaContent { function is(obj: unknown): obj is ToolCallArgumentsDeltaContent; } export declare namespace ErrorChatResponseContent { function is(obj: unknown): obj is ErrorChatResponseContent; } export declare namespace ThinkingChatResponseContent { function is(obj: unknown): obj is ThinkingChatResponseContent; } export interface CompactionChatResponseContent extends ChatResponseContent { kind: 'compaction'; provider: string; data: unknown; summary?: string; } export declare namespace CompactionChatResponseContent { function is(obj: unknown): obj is CompactionChatResponseContent; } export declare namespace ProgressChatResponseContent { function is(obj: unknown): obj is ProgressChatResponseContent; } export type QuestionResponseHandler = (selectedOption: { text: string; value?: string; }) => void; export type MultiSelectQuestionResponseHandler = (selectedOptions: { text: string; value?: string; }[]) => void; export interface QuestionResponseContent extends ChatResponseContent, InteractiveContent { kind: 'question'; question: string; header?: string; options: { text: string; value?: string; description?: string; }[]; multiSelect?: boolean; selectedOption?: { text: string; value?: string; }; selectedOptions?: { text: string; value?: string; }[]; handler?: QuestionResponseHandler | MultiSelectQuestionResponseHandler; /** Called when the user dismisses a single-select question without choosing an option. */ onSkip?: () => void; request?: MutableChatRequestModel; /** * Whether this question is read-only (restored from persistence without handler). * When true, the UI should disable option selection. */ readonly isReadOnly: boolean; } export declare namespace QuestionResponseContent { function is(obj: unknown): obj is QuestionResponseContent; } export interface ResponseTokenUsage { readonly inputTokens: number; readonly outputTokens: number; readonly cacheCreationInputTokens?: number; readonly cacheReadInputTokens?: number; } export interface ChatResponse { readonly content: ChatResponseContent[]; asString(): string; asDisplayString(): string; } /** * The ChatResponseModel wraps the actual ChatResponse with additional information like the current state, progress messages, a unique id etc. */ export interface ChatResponseModel { /** * Use this to be notified for any change in the response model */ readonly onDidChange: Event; /** * Fires when this response requires user interaction (e.g., tool confirmation, question response). * The content part that needs interaction is provided as the event payload. */ readonly onInteractionNeeded: Event; /** * Content parts announced via {@link onInteractionNeeded} that currently await user * interaction (see {@link InteractiveContent.isAwaitingInteraction}). Lets late * subscribers (e.g. a remounted delegation renderer) rebuild pending interaction * state instead of relying solely on the push event. */ readonly pendingInteractions: ReadonlyArray; /** * The unique identifier of the response model */ readonly id: string; /** * The unique identifier of the request model this response is associated with */ readonly requestId: string; /** * In case there are progress messages, then they will be stored here */ readonly progressMessages: ChatProgressMessage[]; /** * The actual response content */ readonly response: ChatResponse; /** * Indicates whether this response is complete. No further changes are expected if 'true'. */ readonly isComplete: boolean; /** * Indicates whether this response is canceled. No further changes are expected if 'true'. */ readonly isCanceled: boolean; /** * Some agents might need to wait for user input to continue. This flag indicates that. */ readonly isWaitingForInput: boolean; /** * Indicates whether an error occurred when processing the response. No further changes are expected if 'true'. */ readonly isError: boolean; /** * The agent who produced the response content, if there is one. */ readonly agentId?: string; /** * An optional error object that caused the response to be in an error state. */ readonly errorObject?: Error; /** * Some functionality might want to store some data associated with the response. * This can be used to store and retrieve such data. */ readonly data: { [key: string]: unknown; }; /** * The ID of the prompt variant used to generate this response */ readonly promptVariantId?: string; /** * Indicates whether the prompt variant was customized/edited */ readonly isPromptVariantEdited?: boolean; /** * The identifier of the language model that produced this response, if recorded. */ readonly languageModel?: string; readonly tokenUsage?: ResponseTokenUsage; toSerializable(): SerializableChatResponseData; } /********************** * Implementations **********************/ export declare class MutableChatModel implements ChatModel, Disposable { protected readonly _onDidChangeEmitter: Emitter; onDidChange: Event; protected readonly toDispose: DisposableCollection; protected _hierarchy: ChatRequestHierarchy; protected _id: string; protected _suggestions: readonly ChatSuggestion[]; protected readonly _contextManager: ChatContextManagerImpl; protected _changeSet: ChatTreeChangeSet; protected _settings: ChatSessionSettings; protected _location: ChatAgentLocation; protected _status: ChatSessionStatus; rootSessionId?: string; parentSessionId?: string; get location(): ChatAgentLocation; constructor(locationOrSerializedData?: ChatAgentLocation | SerializedChatModel); /** * Type guard to determine if we're receiving serialized data */ protected isSerializedChatModel(data: ChatAgentLocation | SerializedChatModel): data is SerializedChatModel; /** * Restore this chat model from serialized data * * Does not restore response content or changesets. * This handled by the chat service using the deserializer registries. */ protected restoreFromSerializedData(data: SerializedChatModel): void; get id(): string; get changeSet(): ChangeSet; getBranches(): ChatHierarchyBranch[]; getBranch(requestId: string): ChatHierarchyBranch | undefined; getRequests(): MutableChatRequestModel[]; getRequest(id: string): MutableChatRequestModel | undefined; get suggestions(): readonly ChatSuggestion[]; get status(): ChatSessionStatus; protected computeStatus(): ChatSessionStatus; protected updateStatus(): void; get context(): ChatContextManager; get settings(): ChatSessionSettings; setSettings(settings: ChatSessionSettings): void; addChildModel(child: MutableChatModel): Disposable; addRequest(parsedChatRequest: ParsedChatRequest, agentId?: string, context?: ChatContext): MutableChatRequestModel; protected getTargetForRequestAddition(request: ParsedChatRequest): (addendum: MutableChatRequestModel) => void; setSuggestions(suggestions: ChatSuggestion[]): void; isEmpty(): boolean; toSerializable(): SerializedChatModel; /** * Get all requests from the hierarchy. * This is used for operations that need to process all requests, such as serialization. */ getAllRequests(): MutableChatRequestModel[]; dispose(): void; } export declare class ChatTreeChangeSet implements Omit { protected readonly hierarchy: ChatRequestHierarchy; protected readonly onDidChangeEmitter: Emitter; get onDidChange(): Event; protected readonly toDispose: DisposableCollection; constructor(hierarchy: ChatRequestHierarchy); get title(): string; removeElements(...uris: URI[]): boolean; addElements(...elements: ChangeSetElement[]): boolean; setElements(...elements: ChangeSetElement[]): void; setTitle(title: string): void; getElementByURI(uri: URI): ChangeSetElement | undefined; protected currentElements: ChangeSetElement[]; protected handleChangeSetChange: import("lodash").DebouncedFunc; protected doHandleChangeSetChange(): void; getElements(): ChangeSetElement[]; protected computeChangeSetElements(): ChangeSetElement[]; protected handleElementChange(newElements: ChangeSetElement[]): void; protected toDisposeOnRequestAdded: DisposableCollection; registerRequest(request: MutableChatRequestModel): void; protected localChangeSet?: ChangeSetImpl; protected getMutableChangeSet(): ChangeSetImpl; protected getCurrentChangeSet(): ChangeSet | undefined; /** Returns the lowest node among active nodes that satisfies {@link criterion} */ getBranchParent(criterion: (branch: ChatHierarchyBranch) => boolean): ChatHierarchyBranch | undefined; dispose(): void; } export declare class ChatRequestHierarchyImpl implements ChatRequestHierarchy { protected readonly onDidChangeActiveBranchEmitter: Emitter>; readonly onDidChange: Event>; readonly branch: ChatHierarchyBranch; constructor(serializedHierarchy?: SerializableHierarchy, requestMap?: Map); /** * Restore the hierarchy from serialized data. */ protected restoreFromSerialized(serializedHierarchy: SerializableHierarchy, requestMap: Map): void; append(request: TRequest): ChatHierarchyBranch; activeRequests(): TRequest[]; activeBranches(): ChatHierarchyBranch[]; protected iterateBranches(): Generator>; findRequest(requestId: string): TRequest | undefined; findBranch(requestId: string): ChatHierarchyBranch | undefined; protected findInBranch(branch: ChatHierarchyBranch, requestId: string): ChatHierarchyBranch | undefined; notifyChange(event: ChangeActiveBranchEvent): void; toSerializable(): SerializableHierarchy; protected serializeBranch(branch: ChatHierarchyBranch, branches: { [branchId: string]: SerializableHierarchyBranch; }): void; dispose(): void; } export declare class ChatRequestHierarchyBranchImpl implements ChatHierarchyBranch { readonly hierarchy: ChatRequestHierarchy; readonly previous?: ChatHierarchyBranch | undefined; readonly items: ChatHierarchyBranchItem[]; protected _activeIndex: number; readonly id: string; constructor(hierarchy: ChatRequestHierarchy, previous?: ChatHierarchyBranch | undefined, items?: ChatHierarchyBranchItem[], _activeIndex?: number, id?: string); get activeBranchIndex(): number; protected set activeBranchIndex(value: number); next(): ChatHierarchyBranch | undefined; get(): TRequest; add(request: TRequest): void; remove(request: TRequest | string): void; continue(request: TRequest): ChatHierarchyBranch; enable(request: TRequest): ChatHierarchyBranchItem; enablePrevious(): ChatHierarchyBranchItem; enableNext(): ChatHierarchyBranchItem; succeedingBranches(): ChatHierarchyBranch[]; dispose(): void; } export declare class ChatContextManagerImpl implements ChatContextManager { protected readonly variables: AIVariableResolutionRequest[]; protected readonly onDidChangeEmitter: Emitter; get onDidChange(): Event; constructor(context?: ChatContext); getVariables(): readonly AIVariableResolutionRequest[]; addVariables(...variables: AIVariableResolutionRequest[]): void; deleteVariables(...indices: number[]): void; setVariables(variables: AIVariableResolutionRequest[]): void; clear(): void; } export declare class MutableChatRequestModel implements ChatRequestModel, EditableChatRequestModel, Disposable { protected readonly _onDidChangeEmitter: Emitter; onDidChange: Event; protected _id: string; protected _session: MutableChatModel; protected _request: ChatRequest; protected _response: MutableChatResponseModel; protected _changeSet?: ChangeSetImpl; protected _context: ChatContext; protected _agentId?: string; protected _data: { [key: string]: unknown; }; protected _isEditing: boolean; protected _message: ParsedChatRequest; protected readonly toDispose: DisposableCollection; readonly editContextManager: ChatContextManagerImpl; constructor(session: MutableChatModel, messageOrData: ParsedChatRequest | SerializableChatRequestData, agentIdOrResponseData?: string | SerializableChatResponseData, context?: ChatContext, data?: { [key: string]: unknown; }); /** * Type guard to determine if we're receiving serialized data */ protected isSerializedRequestData(data: ParsedChatRequest | SerializableChatRequestData): data is SerializableChatRequestData; /** * Restore this request model from serialized data */ protected restoreFromSerializedData(reqData: SerializableChatRequestData, respData?: SerializableChatResponseData): void; /** * Deserialize ParsedChatRequest from serialized data. * Creates placeholder tool requests - actual tools will be restored by ChatService. */ protected deserializeParsedRequest(data: SerializableParsedRequest, request: ChatRequest): ParsedChatRequest; /** * Creates a placeholder tool request that will be replaced during restoration. */ protected createPlaceholderToolRequest(toolId: string): ToolRequest; /** * Restores the tool requests in the parsed request by replacing placeholders with actual tools. * Called after deserialization to upgrade placeholder tools to real tools from the registry. */ restoreToolRequests(toolRequests: Map): void; get message(): ParsedChatRequest; get changeSet(): ChangeSetImpl | undefined; set changeSet(changeSet: ChangeSetImpl); get isEditing(): boolean; enableEdit(): void; get data(): { [key: string]: unknown; } | undefined; addData(key: string, value: unknown): void; getDataByKey(key: string): T; removeData(key: string): void; get id(): string; get session(): MutableChatModel; get request(): ChatRequest; get response(): MutableChatResponseModel; get context(): ChatContext; get agentId(): string | undefined; cancelEdit(): void; submitEdit(newRequest: ChatRequest): void; cancel(): void; toSerializable(): SerializableChatRequestData; dispose(): void; protected clearEditContext(): void; protected emitEditRequest(request: MutableChatRequestModel): void; protected emitCancelEdit(request: MutableChatRequestModel): void; protected emitSubmitEdit(request: MutableChatRequestModel, newRequest: ChatRequest): void; } export declare class ErrorChatResponseContentImpl implements ErrorChatResponseContent { readonly kind = "error"; protected _error: Error; constructor(error: Error); get error(): Error; asString(): string | undefined; asDisplayString(): string | undefined; toSerializable(): SerializableChatResponseContentData; } export declare class TextChatResponseContentImpl implements TextChatResponseContent { readonly kind = "text"; protected _content: string; constructor(content: string); get content(): string; asString(): string; asDisplayString(): string | undefined; merge(nextChatResponseContent: TextChatResponseContent): boolean; toLanguageModelMessage(): TextMessage; toSerializable(): SerializableChatResponseContentData; } export declare class ThinkingChatResponseContentImpl implements ThinkingChatResponseContent { readonly kind = "thinking"; protected _content: string; protected _signature: string; constructor(content: string, signature: string); get content(): string; get signature(): string; asString(): string; asDisplayString(): string | undefined; merge(nextChatResponseContent: ThinkingChatResponseContent): boolean; toLanguageModelMessage(): ThinkingMessage; toSerializable(): SerializableChatResponseContentData; } export declare class CompactionChatResponseContentImpl implements CompactionChatResponseContent { readonly kind = "compaction"; protected _provider: string; protected _data: unknown; protected _summary?: string; constructor(provider: string, data: unknown, summary?: string); get provider(): string; get data(): unknown; get summary(): string | undefined; asString(): string | undefined; asDisplayString(): string | undefined; toLanguageModelMessage(): CompactionMessage; toSerializable(): SerializableChatResponseContentData; } export declare class MarkdownChatResponseContentImpl implements MarkdownChatResponseContent { readonly kind = "markdownContent"; protected _content: MarkdownStringImpl; constructor(content: string); get content(): MarkdownString; asString(): string; asDisplayString(): string | undefined; merge(nextChatResponseContent: MarkdownChatResponseContent): boolean; toLanguageModelMessage(): TextMessage; toSerializable(): SerializableChatResponseContentData; } export declare class InformationalChatResponseContentImpl implements InformationalChatResponseContent { readonly kind = "informational"; protected _content: MarkdownStringImpl; constructor(content: string); get content(): MarkdownString; asString(): string | undefined; merge(nextChatResponseContent: InformationalChatResponseContent): boolean; toSerializable(): SerializableChatResponseContentData; } export declare class CodeChatResponseContentImpl implements CodeChatResponseContent { readonly kind = "code"; protected _code: string; protected _language?: string; protected _location?: Location; constructor(code: string, language?: string, location?: Location); get code(): string; get language(): string | undefined; get location(): Location | undefined; asString(): string; merge(nextChatResponseContent: CodeChatResponseContent): boolean; toSerializable(): SerializableChatResponseContentData; } export declare class ToolCallChatResponseContentImpl implements ToolCallChatResponseContent, InteractiveContent { readonly kind = "toolCall"; protected _id?: string; protected _name?: string; protected _arguments?: string; protected _finished?: boolean; protected _result?: ToolCallResult; protected _data?: Record; protected _confirmationTimeout?: number; protected _needsUserConfirmation: Promise; protected _needsUserConfirmationResolver?: () => void; protected _isAwaitingUserConfirmation: boolean; protected _isAwaitingUserInput: boolean; protected _confirmed: Promise; protected _confirmationResolver?: (value: boolean) => void; protected _confirmationRejecter?: (reason?: unknown) => void; protected _whenFinished: Promise; protected _finishedResolver?: () => void; protected readonly _onDidChangeEmitter: Emitter; readonly onDidChange: Event; constructor(id?: string, name?: string, arg_string?: string, finished?: boolean, result?: ToolCallResult, data?: Record); get id(): string | undefined; get name(): string | undefined; get arguments(): string | undefined; get finished(): boolean; get result(): ToolCallResult | undefined; get data(): Record | undefined; get confirmationTimeout(): number | undefined; set confirmationTimeout(value: number | undefined); get interactionId(): string | undefined; get isResolved(): boolean; get confirmed(): Promise; get needsUserConfirmation(): Promise; get isAwaitingUserConfirmation(): boolean; get isAwaitingUserInput(): boolean; get isAwaitingInteraction(): boolean; get whenFinished(): Promise; get whenResolved(): Promise; createConfirmationPromise(): Promise; createFinishedPromise(): Promise; /** * Confirm the tool execution */ confirm(): void; deny(reason?: string): void; requestUserConfirmation(): void; requestUserInput(): void; userInputHandled(): void; updateResult(result: ToolCallResult): void; cancelConfirmation(reason?: unknown): void; complete(result: ToolCallResult): void; protected resolveFinished(): void; asString(): string; asDisplayString(): string; merge(nextChatResponseContent: ToolCallChatResponseContent | ToolCallArgumentsDeltaContent): boolean; protected parseArgumentsSafe(): object; toLanguageModelMessage(): [ToolUseMessage, ToolResultMessage]; toSerializable(): SerializableChatResponseContentData; } export declare class ServerToolCallChatResponseContentImpl implements ServerToolCallChatResponseContent { readonly kind = "serverToolCall"; protected _id?: string; protected _name?: string; protected _arguments?: string; protected _finished: boolean; protected _result?: ToolCallResult; protected _data?: Record; constructor(id?: string, name?: string, arg_string?: string, finished?: boolean, result?: ToolCallResult, data?: Record); get id(): string | undefined; get name(): string | undefined; get arguments(): string | undefined; get finished(): boolean; get result(): ToolCallResult | undefined; get data(): Record | undefined; asString(): string; asDisplayString(): string; merge(nextChatResponseContent: ChatResponseContent): boolean; protected parseArgumentsSafe(): object; toLanguageModelMessage(): ServerToolUseMessage; toSerializable(): SerializableChatResponseContentData; } export declare const COMMAND_CHAT_RESPONSE_COMMAND: Command; export declare class CommandChatResponseContentImpl implements CommandChatResponseContent { command?: Command | undefined; customCallback?: CustomCallback | undefined; protected args?: unknown[] | undefined; readonly kind = "command"; constructor(command?: Command | undefined, customCallback?: CustomCallback | undefined, args?: unknown[] | undefined); get arguments(): unknown[]; asString(): string; toSerializable(): SerializableChatResponseContentData; } export declare class HorizontalLayoutChatResponseContentImpl implements HorizontalLayoutChatResponseContent { readonly kind = "horizontal"; protected _content: ChatResponseContent[]; constructor(content?: ChatResponseContent[]); get content(): ChatResponseContent[]; asString(): string; asDisplayString(): string | undefined; merge(nextChatResponseContent: ChatResponseContent): boolean; toSerializable(): SerializableChatResponseContentData; } /** * Options bag for constructing a {@link QuestionResponseContentImpl}. */ export interface QuestionResponseContentOptions { selectedOption?: { text: string; value?: string; }; selectedOptions?: { text: string; value?: string; }[]; multiSelect?: boolean; header?: string; /** Called when the user dismisses a single-select question without choosing an option. */ onSkip?: () => void; } /** * Default implementation for the QuestionResponseContent. * Can be created with or without handler/request for read-only (restored) mode. */ export declare class QuestionResponseContentImpl implements QuestionResponseContent, InteractiveContent { question: string; options: { text: string; value?: string; description?: string; }[]; request: MutableChatRequestModel | undefined; handler: QuestionResponseHandler | MultiSelectQuestionResponseHandler | undefined; readonly kind = "question"; multiSelect?: boolean; header?: string; onSkip?: () => void; protected _selectedOptions: { text: string; value?: string; }[] | undefined; protected _resolvedResolver?: () => void; readonly whenResolved: Promise; constructor(question: string, options: { text: string; value?: string; description?: string; }[], request: MutableChatRequestModel | undefined, handler: QuestionResponseHandler | undefined, questionOptions?: Omit & { multiSelect?: false; }); constructor(question: string, options: { text: string; value?: string; description?: string; }[], request: MutableChatRequestModel | undefined, handler: MultiSelectQuestionResponseHandler | undefined, questionOptions: QuestionResponseContentOptions & { multiSelect: true; }); get isReadOnly(): boolean; get interactionId(): string | undefined; get isResolved(): boolean; get isAwaitingInteraction(): boolean; set selectedOption(option: { text: string; value?: string; } | undefined); get selectedOption(): { text: string; value?: string; } | undefined; set selectedOptions(options: { text: string; value?: string; }[] | undefined); get selectedOptions(): { text: string; value?: string; }[] | undefined; asString?(): string | undefined; merge?(): boolean; toSerializable(): SerializableChatResponseContentData; } declare class ChatResponseImpl implements ChatResponse { protected readonly _onDidChangeEmitter: Emitter; onDidChange: Event; protected _content: ChatResponseContent[]; protected _responseRepresentation: string; protected _responseRepresentationForDisplay: string; protected readonly contentChangeListeners: Map; constructor(); get content(): ChatResponseContent[]; clearContent(): void; addContents(contents: ChatResponseContent[]): void; addContent(nextContent: ChatResponseContent): void; protected doAddContent(nextContent: ChatResponseContent): void; responseContentChanged(): void; protected _updateResponseRepresentation(): void; protected responseRepresentationsToString(content: ChatResponseContent[], collect: 'asString' | 'asDisplayString'): string; asString(): string; asDisplayString(): string; } export declare class MutableChatResponseModel implements ChatResponseModel { protected readonly _onDidChangeEmitter: Emitter; onDidChange: Event; protected readonly _onInteractionNeededEmitter: Emitter; readonly onInteractionNeeded: Event; protected _pendingInteractions: (InteractiveContent & ChatResponseContent)[]; data: {}; protected _id: string; protected _requestId: string; protected _progressMessages: ChatProgressMessage[]; protected _response: ChatResponseImpl; protected _isComplete: boolean; protected _waitingForInputCount: number; protected _agentId?: string; protected _isError: boolean; protected _errorObject: Error | undefined; protected _cancellationToken: CancellationTokenSource; protected _promptVariantId?: string; protected _isPromptVariantEdited?: boolean; protected _languageModel?: string; protected _tokenUsage?: ResponseTokenUsage; protected _tokenUsageEntries: ResponseTokenUsage[]; constructor(requestId: string, agentId?: string, serializedData?: SerializableChatResponseData); /** * Restore this response model from serialized data */ protected restoreFromSerializedData(data: SerializableChatResponseData): void; get id(): string; get requestId(): string; get progressMessages(): ChatProgressMessage[]; addProgressMessage(message: { content: string; } & Partial>): ChatProgressMessage; getProgressMessage(id: string): ChatProgressMessage | undefined; updateProgressMessage(message: { id: string; } & Partial>): void; get response(): ChatResponseImpl; get isComplete(): boolean; get isCanceled(): boolean; get isWaitingForInput(): boolean; get agentId(): string | undefined; get promptVariantId(): string | undefined; get isPromptVariantEdited(): boolean; get languageModel(): string | undefined; get tokenUsage(): ResponseTokenUsage | undefined; setTokenUsage(usage: ResponseTokenUsage): void; addTokenUsageEntry(usage: ResponseTokenUsage): void; get tokenUsageEntries(): readonly ResponseTokenUsage[]; setPromptVariantInfo(variantId: string | undefined, isEdited: boolean): void; /** Records the identifier of the language model that produced this response. */ setLanguageModel(languageModel: string | undefined): void; overrideAgentId(agentId: string): void; /** Reset all pending-input state; the response no longer accepts user interaction. */ protected resetPendingInput(): void; complete(): void; cancel(): void; get cancellationToken(): CancellationToken; waitForInput(): void; stopWaitingForInput(): void; get pendingInteractions(): ReadonlyArray; fireInteractionNeeded(contentPart: InteractiveContent & ChatResponseContent): void; notifyChanged(): void; error(error: Error): void; get errorObject(): Error | undefined; get isError(): boolean; toSerializable(): SerializableChatResponseData; } export declare class ErrorChatResponseModel extends MutableChatResponseModel { constructor(requestId: string, error: Error, agentId?: string); } export declare class ProgressChatResponseContentImpl implements ProgressChatResponseContent { readonly kind = "progress"; protected _message: string; constructor(message: string); get message(): string; asString(): string; asDisplayString(): string | undefined; merge(nextChatResponseContent: ProgressChatResponseContent): boolean; toLanguageModelMessage(): TextMessage; toSerializable(): SerializableChatResponseContentData; } /** * Fallback content for unknown content types. * Used when a deserializer is not available (e.g., content from removed extension). */ export interface UnknownChatResponseContent extends ChatResponseContent { kind: 'unknown'; originalKind: string; fallbackMessage?: string; data: unknown; } export declare class UnknownChatResponseContentImpl implements UnknownChatResponseContent { readonly originalKind: string; readonly fallbackMessage: string | undefined; readonly data: unknown; readonly kind = "unknown"; constructor(originalKind: string, fallbackMessage: string | undefined, data: unknown); asString(): string | undefined; toSerializable(): SerializableChatResponseContentData; } //# sourceMappingURL=chat-model.d.ts.map