import { type IAgentContextUsage, type IAgentChatUsage } from "../../../../../../platform/agentHost/common/meta/agentUsageMeta.js"; import { IMarkdownString, MarkdownString } from "../../../../../../base/common/htmlContent.js"; import { URI } from "../../../../../../base/common/uri.js"; import { ToolCallStatus, type ActiveTurn, type ChatInputAnswer, type ChatInputRequest, type ICompletedToolCall, type InputRequestResponsePart, type Message, type ToolCallPendingConfirmationState, type ToolCallState, type Turn, FileEditKind, ToolResultContentType, type ToolResultContent, type UsageInfo } from "../../../../../../platform/agentHost/common/state/sessionState.js"; import { type IAgentPlanReview } from "../../../../../../platform/agentHost/common/meta/agentPlanReview.js"; import { type IAgentToolOutputChunk } from "../../../../../../platform/agentHost/common/meta/agentToolCallMeta.js"; import { IChatErrorContext } from "../../../common/chatErrorMessages.js"; import { type IAgentHostResourceUriMapper } from "../../../../../../platform/agentHost/common/agentHostUri.js"; import { type MessageAttachment, type ReasoningResponsePart, type ResponsePart, type StringOrMarkdown } from "../../../../../../platform/agentHost/common/state/protocol/state.js"; import { type IChatAutoModeResolutionPart, type IChatExternalEdit, type IChatMcpAuthenticationRequiredServer, type IChatProgress, type IChatQuestionAnswers, type IChatResponseErrorDetails, type IChatSubagentToolInvocationData, type IChatThinkingPart, type IChatToolInvocationSerialized, type IChatUsage } from "../../../common/chatService/chatService.js"; import { type IChatSessionHistoryItem } from "../../../common/chatSessionsService.js"; import { type IQuotaSnapshot, type IRateLimitSnapshot } from "../../../../../services/chat/common/chatEntitlementService.js"; import { ChatToolInvocation } from "../../../common/model/chatProgressTypes/chatToolInvocation.js"; import { ChatPlanReviewData } from "../../../common/model/chatProgressTypes/chatPlanReviewData.js"; import { ChatQuestionCarouselData } from "../../../common/model/chatProgressTypes/chatQuestionCarouselData.js"; import { type ChatRequestSource, type IChatRequestVariableData, type IChatSessionCost } from "../../../common/model/chatModel.js"; import { type IChatRequestOrigin } from "../../../common/chatRequestOrigin.js"; import { type IToolConfirmationMessages, type IPreparedToolInvocation } from "../../../common/tools/languageModelToolsService.js"; import { type IAgentHostManagedPluginRetryTarget } from "./agentHostManagedPluginRetry.js"; export declare const BOOLEAN_TRUE_OPTION_ID = "true"; export declare const BOOLEAN_FALSE_OPTION_ID = "false"; export interface IAgentHostToolInvocationOptions { readonly currentClientId: string; readonly cancelOtherClientToolCall: (toolCall: ToolCallState) => void; } /** * Constructs a terminal tool session ID from a terminal URI and backend session. * The ID is a JSON string containing both so consumers can parse out either. */ export declare function makeAhpTerminalToolSessionId(terminalUri: string, session: URI): string; /** * Parses a terminal tool session ID back into its terminal and session URIs. */ export declare function parseAhpTerminalToolSessionId(id: string): { terminal: string; session: string; } | undefined; export declare function convertProtocolAnswers(raw: Record | undefined): IChatQuestionAnswers | undefined; export declare function containsAutomaticReplyAnswer(raw: Record | undefined): boolean; export declare function createInputRequestCarousel(inputReq: ChatInputRequest, connectionAuthority: string): ChatQuestionCarouselData; export declare function createInputRequestPlanReview(inputReq: ChatInputRequest, planReview: IAgentPlanReview["review"], resourceUris: IAgentHostResourceUriMapper, connectionAuthority: string): ChatPlanReviewData; export declare function getUrlInputRequestPresentation(inputReq: ChatInputRequest, url: string): { authority: string; message: MarkdownString; }; export declare function inputRequestResponsePartToProgress(part: InputRequestResponsePart, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper): IChatProgress; export declare function isSubagentToolName(toolName: string): boolean; /** * @param managedPluginRetry The chat a managed plugin preparation failure can * be retried for. When omitted, for example for a host without the local * retry path, the failure is shown without a Retry link. */ export declare function systemNotificationToChatPart(content: StringOrMarkdown | undefined, connectionAuthority: string, _meta?: Record, managedPluginRetry?: IAgentHostManagedPluginRetryTarget): IChatProgress | undefined; /** Keep live phase activity visible after its own milestones, but not after answer/tool content. */ export declare function getAgentHostActivityProgressId(parts: readonly ResponsePart[]): string | undefined; /** * Returns true if this tool call spawns a subagent session, either because * the server reported `_meta.toolKind === 'subagent'` or because the tool * name is in the known fallback set (older snapshots without `_meta`). */ export declare function isSubagentTool(tc: ToolCallState): boolean; /** Returns whether the tool call can own a child chat: a subagent launch, a Fusion phase, or a call carrying discovery content. */ export declare function canOwnSubagentChat(tc: ToolCallState): boolean; /** Returns whether the tool call can have a child chat worth observing. */ export declare function shouldObserveSubagentChat(tc: ToolCallState, hasCatalogChild?: boolean): boolean; export declare function getTerminalContent(content: ToolResultContent[] | undefined): Extract | undefined; /** * Resolves selected and actual model identifiers independently, along with response display details. */ export interface TurnModelLookup { /** Returns the chat-layer namespaced model id for a raw AHP model id. */ toLanguageModelId(rawModelId: string | undefined): string | undefined; /** Resolves the actual model's registered id when available, without falling back to the selected model. */ toActualModelId(rawModelId: string | undefined): string | undefined; /** Returns the registered display name for a raw AHP model id. */ toModelDisplayName?(rawModelId: string): string | undefined; /** Resolves response details, optionally naming an orchestration model without rewriting billed usage. */ toResponseDetails(rawModelId: string | undefined, usage: UsageInfo | undefined, responseModelId?: string): string | undefined; /** Whether a raw AHP model id names this provider's fusion routing model. */ isFusionModel?(rawModelId: string | undefined): boolean; /** Returns the Auto model routing part carried by this usage report, if any. */ toAutoModeResolution?(usage: UsageInfo | undefined): IChatAutoModeResolutionPart | undefined; /** * Returns the identity and display name of the model a turn bills to, reading Auto's pick * when it routed and folding back to "Auto" while explainability is hidden. */ toBilledModelInfo?(usage: UsageInfo | undefined): ITurnModelInfo | undefined; } export interface ITurnModelInfo { readonly modelId: string; readonly modelName: string; readonly modelConfiguration?: Record; readonly runtimeModelConfiguration?: IChatSubagentToolInvocationData["runtimeModelConfiguration"]; } /** Minimal model metadata needed to render a turn's response footer (kept small for unit testing). */ export interface ITurnResponseModel { readonly name: string; readonly pricing?: string; } /** Fusion is the response-level model; constituent models remain in phase pills and usage. */ export declare function turnToResponseDetails(turn: Turn | ActiveTurn | undefined, lookup?: TurnModelLookup): string | undefined; /** * Result metadata for a finished turn. Records the model Auto routed the turn to as * `resolvedModel`, the key the Copilot extension sets for local requests, so readers * of a response's result (such as the model feedback survey) work for both. Read from * the routing decision rather than the rendered routing row, which an experiment can hide. */ export declare function turnToResultMetadata(turn: Turn | undefined): { readonly resolvedModel: string; } | undefined; /** * Formats a turn's response footer: the model display name plus usage metadata (credits or pricing). * `model` is the resolved model; `billedModelId` is the turn's `usage.model` when it didn't resolve to a * registered model (e.g. an "Auto" pick billed as `raptor-mini`), shown inline as `Auto (raptor-mini)`. * Returns `undefined` when the model is unknown. */ export declare function formatTurnResponseDetails(model: ITurnResponseModel | undefined, billedModelId: string | undefined, usage: UsageInfo | undefined): string | undefined; /** Converts an agent-host Auto routing result into the shared chat UI part. */ export declare function usageInfoToAutoModeResolution(usage: UsageInfo | undefined, resolvedModelName: string | undefined): IChatAutoModeResolutionPart | undefined; export declare function chatUsageToSessionCost(usage: IAgentChatUsage): IChatSessionCost; export declare function usageInfoToChatUsage(usage: UsageInfo | undefined, modelDisplayNameResolver?: (rawModelId: string) => string | undefined, contextUsage?: IAgentContextUsage): IChatUsage | undefined; /** * A partial quota update derived from a usage report's `_meta.quotaSnapshots`. Structurally a * subset of the entitlement service's quota state, so callers merge it onto the existing quotas. */ export interface IAgentHostQuotaUpdate { readonly chat?: IQuotaSnapshot; readonly completions?: IQuotaSnapshot; readonly premiumChat?: IQuotaSnapshot; readonly additionalUsageEnabled?: boolean; readonly additionalUsageCount?: number; readonly additionalUsageEntitlement?: number; readonly usageBasedBilling?: boolean; readonly sessionRateLimit?: IRateLimitSnapshot; readonly weeklyRateLimit?: IRateLimitSnapshot; readonly resetDate?: string; } /** * Maps the per-category quota snapshots carried on a usage report's `_meta.quotaSnapshots` * (reported by the model-call usage event) into a partial quota update for the entitlement * service. Returns `undefined` when no usable snapshot is present. */ export declare function usageInfoToQuotas(usage: UsageInfo | undefined): IAgentHostQuotaUpdate | undefined; /** * Converts completed turns from the protocol state into session history items. * * Requests preserve the selected model. Response details use the actual model, except for Fusion's workflow label. * The `lookup` callback supplies the session-level fallback for missing model metadata. */ export declare function turnsToHistory(backendSession: URI, turns: readonly Turn[], participantId: string, connectionAuthority: string, lookup?: TurnModelLookup, errorContext?: IChatErrorContext, terminalCommandPrefix?: string, resourceUris?: IAgentHostResourceUriMapper, errorDetailsProvider?: (turn: Turn) => IChatResponseErrorDetails | undefined, contextUsage?: IAgentContextUsage, managedPluginRetry?: IAgentHostManagedPluginRetryTarget): IChatSessionHistoryItem[]; /** Maps explicit host metadata to a chat request source. */ export declare function messageToRequestSource(message: Message): ChatRequestSource | undefined; export declare function messageToRequestOrigin(backendSession: URI, message: Message, participantId: string, connectionAuthority?: string): IChatRequestOrigin | undefined; /** * Converts a turn's persisted {@link Message} into the chat-layer * {@link IChatRequestVariableData} shape so attachments survive a * history replay (and pending/server-initiated turn synthesis). Returns * `undefined` when the message has no convertible attachments. */ export declare function messageToVariableData(message: Message, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper): IChatRequestVariableData | undefined; export declare function messageAttachmentsToVariableData(attachments: readonly MessageAttachment[] | undefined, connectionAuthority: string, messageText?: string, resourceUris?: IAgentHostResourceUriMapper): IChatRequestVariableData | undefined; export declare function reasoningPartToThinking(part: ReasoningResponsePart, value?: string): IChatThinkingPart; /** * Converts an active (in-progress) turn's accumulated state into progress * items suitable for replaying into the chat UI when reconnecting to a * session that is mid-turn. * * Returns serialized progress items for content already received (text, * reasoning, completed tool calls) and live {@link ChatToolInvocation} * objects for running tool calls and pending confirmations. */ export declare function activeTurnToProgress(sessionResource: URI, activeTurn: ActiveTurn, connectionAuthority: string, mcpServerAuthority?: string, toolInvocationOptions?: IAgentHostToolInvocationOptions, lookup?: TurnModelLookup, resourceUris?: IAgentHostResourceUriMapper, subagentToolCallIds?: ReadonlySet, managedPluginRetry?: IAgentHostManagedPluginRetryTarget): IChatProgress[]; export declare function appendToolOutput(invocation: ChatToolInvocation, call: ToolCallState, chunk: IAgentToolOutputChunk): void; /** * Converts a completed tool call from the protocol state into a serialized * tool invocation suitable for history replay. */ export declare function completedToolCallToSerialized(tc: ICompletedToolCall, subAgentInvocationId: string | undefined, sessionResource: URI, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper): IChatToolInvocationSerialized; /** * Builds per-file edit pills with protocol diff metadata and connection-scoped resource URIs. * An optional root subagent id keeps child edits out of the parent's own content flow. */ export declare function completedToolCallToEditParts(tc: ICompletedToolCall, connectionAuthority: string, subAgentInvocationId?: string): IChatExternalEdit[]; /** * Rewrites inline markdown link URIs so that non-external schemes are wrapped * in the `vscode-agent-host://` scheme, mirroring {@link toAgentHostUri}. * This allows links in markdown content streamed from a remote agent host * (e.g. `file:///...` or `agenthost-content:///...`) to resolve correctly on * the client through the agent host filesystem provider. * * Links with external schemes (http, https, mailto, command, etc.) and * relative/anchor-only links without a scheme are preserved as-is. The * markdown is parsed with marked and each `link` / `image` token is * rewritten individually, so link-looking text inside code spans or fenced * code blocks is untouched (marked emits those as `code`/`codespan` tokens * with no nested link tokens). */ export declare function rewriteMarkdownLinks(markdown: string, connectionAuthority: string): string; /** * Wraps a raw markdown string into an {@link IMarkdownString}, rewriting * link URIs through {@link rewriteMarkdownLinks} when a connection authority * is provided. */ export declare function rawMarkdownToString(content: string, connectionAuthority: string): MarkdownString; /** Wraps an absolute path or internal URI target for the owning Agent Host connection. */ export declare function rewriteAgentHostLinkTarget(href: string, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper, baseUri?: URI): string; /** * Converts a protocol `StringOrMarkdown` value to a chat-layer `IMarkdownString`. * * When `connectionAuthority` is provided, markdown link URIs are rewritten * through {@link rewriteMarkdownLinks} so that remote resources resolve * through the agent host filesystem provider. */ export declare function stringOrMarkdownToString(value: StringOrMarkdown, connectionAuthority: string): string | IMarkdownString; export declare function stringOrMarkdownToString(value: StringOrMarkdown | undefined, connectionAuthority: string): string | IMarkdownString | undefined; /** * Creates a live {@link ChatToolInvocation} from the protocol's tool-call * state. Used during active turns to represent running tool calls in the UI. * * @param connectionAuthority Sanitized connection identifier used when * wrapping remote file URIs into `vscode-agent-host:` URIs. Omit to skip * URI wrapping (e.g. in tests that don't exercise the confirmation UI). */ export declare function toolCallStateToInvocation(tc: ToolCallState, subAgentInvocationId: string | undefined, sessionResource: URI, connectionAuthority: string, mcpServerAuthority?: string, options?: IAgentHostToolInvocationOptions, resourceUris?: IAgentHostResourceUriMapper, mcpServerName?: string): ChatToolInvocation; export declare function toolCallConfirmationMessages(tc: ToolCallPendingConfirmationState, connectionAuthority: string): IToolConfirmationMessages; export declare function toolCallAuthenticationServer(tc: ToolCallState & { status: ToolCallStatus.AuthRequired; }, sessionAuthority: string, backendSession: URI, name?: string): IChatMcpAuthenticationRequiredServer; /** * Creates a {@link ChatToolInvocation} in the native streaming state for a * tool call that is still streaming its arguments (AHP * {@link ToolCallStatus.Streaming}). The invocation is later driven out of the * streaming state via {@link ChatToolInvocation.transitionFromStreaming} once * the tool reaches confirmation/running, so a single card represents the whole * lifecycle instead of a settled placeholder plus a replacement. */ export declare function toolCallStateToStreamingInvocation(tc: ToolCallState, subAgentInvocationId: string | undefined, sessionResource?: URI, connectionAuthority?: string, mcpServerAuthority?: string): ChatToolInvocation; export declare function updateStreamingToolInvocation(existing: ChatToolInvocation, tc: ToolCallState, connectionAuthority: string): unknown | undefined; /** * Extracts the {@link IPreparedToolInvocation} display fields for a tool-call * state, reusing {@link toolCallStateToInvocation} so the confirmation, * terminal, and other `toolSpecificData` logic stays in one place. Used to * transition a streaming invocation into its confirmation/running presentation * without allocating a second visible card. */ export declare function toolCallStateToPreparedInvocation(tc: ToolCallState, sessionResource: URI, connectionAuthority: string, mcpServerAuthority?: string, options?: IAgentHostToolInvocationOptions, resourceUris?: IAgentHostResourceUriMapper): IPreparedToolInvocation; /** * Updates a running tool invocation's `toolSpecificData` based on the * protocol tool call state. Handles terminal and subagent content detection. * * Called from the session handler when a tool transitions to Running state * to set the initial `toolSpecificData`, or when content changes arrive. */ export declare function updateRunningToolSpecificData(existing: ChatToolInvocation, tc: ToolCallState, sessionResource: URI, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper): void; /** * Data returned by {@link finalizeToolInvocation} describing file edits * that should be routed through the editing session's external edits pipeline. */ export interface IToolCallFileEdit { /** The kind of file operation. */ readonly kind: FileEditKind; /** The primary file URI (after-URI for edits/creates/renames, before-URI for deletes). */ readonly resource: URI; /** For renames, the original file URI before the move. */ readonly originalResource?: URI; /** URI to read the before-snapshot content from. Absent for creates. */ readonly beforeContentUri?: URI; /** URI to read the after-content from. Absent for deletes. */ readonly afterContentUri?: URI; /** Undo stop ID for grouping edits. */ readonly undoStopId: string; /** Optional diff display metadata. */ readonly diff?: { added?: number; removed?: number; }; } /** * Updates a live {@link ChatToolInvocation} with completion data from the * protocol's tool-call state, transitioning it to the completed state. * * Returns file edits that the caller should route through the editing * session's external edits pipeline. */ export declare function finalizeToolInvocation(invocation: ChatToolInvocation, tc: ToolCallState, backendSession: URI, connectionAuthority: string, resourceUris?: IAgentHostResourceUriMapper): IToolCallFileEdit[]; /** * Extracts file edit content entries from a completed tool call and * converts them to {@link IToolCallFileEdit} data for routing through * the editing session's external edits pipeline. */ export declare function fileEditsToExternalEdits(tc: ToolCallState): IToolCallFileEdit[];