import { URI } from "../../../../../base/common/uri.js"; import { IAgentHostConnectionsService } from "../../../../../platform/agentHost/common/agentHostConnectionsService.service.js"; import { ITelemetryService } from "../../../../../platform/telemetry/common/telemetry.service.js"; import { IChatAgentData } from "../participants/chatAgents.js"; import { ChatRequestModel } from "../model/chatModel.js"; import { ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart } from "../requestParser/chatParserTypes.js"; import { IChatSendRequestOptions, IChatUserActionEvent } from "./chatService.js"; import { ChatAgentLocation, ChatPermissionLevel } from "../constants.js"; import { ILanguageModelsService } from "../languageModels.service.js"; import { IChatSessionsService } from "../chatSessionsService.service.js"; import { IChatEntitlementService } from "../../../../services/chat/common/chatEntitlementService.service.js"; type ChatSessionModeEvent = { isAgentHostSession: boolean; }; type ChatSessionModeClassification = { isAgentHostSession: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "Whether the action was performed in an Agent Host-backed chat session."; }; }; export type ChatProviderInvokedEvent = ChatSessionModeEvent & { provider: string | undefined; requestIndex: number; timeToFirstProgress: number | undefined; totalTime: number | undefined; result: "success" | "error" | "errorWithOutput" | "cancelled" | "filtered"; requestType: "string" | "followup" | "slashCommand"; chatSessionId: string; requestId: string; agent: string; agentExtensionId: string | undefined; slashCommand: string | undefined; location: ChatAgentLocation; citations: number; numCodeBlocks: number; isParticipantDetected: boolean; enableCommandDetection: boolean; attachmentKinds: string[]; model: string | undefined; requestStartCopilotSku: string | undefined; selectedModelSource: "copilot" | "byok" | "other" | "unknown"; permissionLevel: ChatPermissionLevel | undefined; chatMode: string | undefined; sessionType: string | undefined; harness: string | undefined; sessionTypeSelectionReason: string | undefined; isVirtualWorkspace: boolean; settingDefaultToCopilotHarness: boolean; settingPreferCopilotHarness: boolean; settingLocalAgentEnabled: boolean; settingCopilotHarnessIntroductionMode: string; }; export type ChatProviderInvokedClassification = ChatSessionModeClassification & { provider: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "Identifies the agent implementation handling the associated chat session, such as copilotcli, claude, or codex."; }; requestIndex: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The zero-based index of the request within the chat session."; }; timeToFirstProgress: { classification: "SystemMetaData"; purpose: "PerformanceAndHealth"; isMeasurement: true; comment: "The time in milliseconds from invoking the provider to getting the first data."; }; totalTime: { classification: "SystemMetaData"; purpose: "PerformanceAndHealth"; isMeasurement: true; comment: "The total time it took to run the provider's `provideResponseWithProgress`."; }; result: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "Whether invoking the ChatProvider resulted in an error."; }; requestType: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The type of request that the user made."; }; chatSessionId: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "A random ID for the session."; }; requestId: { classification: "SystemMetaData"; purpose: "PerformanceAndHealth"; comment: "The identifier of the chat request, used to correlate workbench and agent host telemetry."; }; agent: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The type of agent used."; }; agentExtensionId: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The extension that contributed the agent."; }; slashCommand?: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The type of slashCommand used."; }; location: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The location at which chat request was made."; }; citations: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The number of public code citations that were returned with the response."; }; numCodeBlocks: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The number of code blocks in the response."; }; isParticipantDetected: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "Whether the participant was automatically detected."; }; enableCommandDetection: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "Whether participation detection was disabled for this invocation."; }; attachmentKinds: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The types of variables/attachments that the user included with their query."; }; model: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The model used to generate the response."; }; requestStartCopilotSku: { classification: "SystemMetaData"; purpose: "PerformanceAndHealth"; comment: "The workbench Copilot entitlement SKU when the request started, if known. Not the credential used by a remote host."; }; selectedModelSource: { classification: "SystemMetaData"; purpose: "PerformanceAndHealth"; comment: "Source of the selected model at request start: copilot catalog, explicitly marked byok, other catalog, or unknown. Not the actual routed model or billing provider."; }; permissionLevel: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The tool auto-approval permission level selected in the permission picker (default, assisted, autoApprove, or autopilot). Undefined when the picker is not applicable (e.g. ask mode or API-driven requests)."; }; chatMode: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The chat mode used for the request. Built-in modes (ask, agent, edit), extension-contributed names (e.g. Plan), or a hashed identifier for user-created custom agents."; }; sessionType: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The session type scheme (e.g. vscodeLocalChatSession for local, or remote session scheme)."; }; harness: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "For remote agent host sessions, the underlying harness/provider (e.g. copilotcli, claude, codex) so remote activity can be split by harness. Undefined for non-remote sessions."; }; sessionTypeSelectionReason: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "Why the session type was selected when the session was created. Undefined for restored or reused sessions."; }; isVirtualWorkspace: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "Whether the chat request was made in a virtual workspace."; }; settingDefaultToCopilotHarness: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The effective value of the chat.defaultToCopilotHarness setting when the request started."; }; settingPreferCopilotHarness: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The effective value of the chat.editor.preferCopilotHarness setting when the request started."; }; settingLocalAgentEnabled: { classification: "SystemMetaData"; purpose: "FeatureInsight"; isMeasurement: true; comment: "The effective value of the chat.editor.localAgent.enabled setting when the request started."; }; settingCopilotHarnessIntroductionMode: { classification: "SystemMetaData"; purpose: "FeatureInsight"; comment: "The effective Copilot harness introduction experiment mode when the request started."; }; owner: "roblourens"; comment: "Provides insight into the performance of Chat agents."; }; export declare class ChatServiceTelemetry { private readonly telemetryService; constructor(telemetryService: ITelemetryService); notifyUserAction(action: IChatUserActionEvent): void; retrievedFollowups(sessionResource: URI, agentId: string, command: string | undefined, numFollowups: number): void; } export declare class ChatRequestTelemetry { private readonly opts; private readonly telemetryService; private readonly languageModelsService; private readonly chatSessionsService; private isComplete; private readonly requestStartCopilotSku; private readonly selectedModelSource; constructor(opts: { agent: IChatAgentData; agentSlashCommandPart: ChatRequestAgentSubcommandPart | undefined; commandPart: ChatRequestSlashCommandPart | undefined; requestIndex: number; sessionTypeSelectionReason: string | undefined; sessionResource: URI; location: ChatAgentLocation; options: IChatSendRequestOptions | undefined; enableCommandDetection: boolean; isVirtualWorkspace: boolean; settingDefaultToCopilotHarness: boolean; settingPreferCopilotHarness: boolean; settingLocalAgentEnabled: boolean; settingCopilotHarnessIntroductionMode: string; }, telemetryService: ITelemetryService, languageModelsService: ILanguageModelsService, chatSessionsService: IChatSessionsService, chatEntitlementService: IChatEntitlementService); complete({ timeToFirstProgress, totalTime, result, requestType, request, detectedAgent }: { timeToFirstProgress: number | undefined; totalTime: number | undefined; result: ChatProviderInvokedEvent["result"]; requestType: ChatProviderInvokedEvent["requestType"]; request: ChatRequestModel; detectedAgent: IChatAgentData | undefined; }): void; private attachmentKindsForTelemetry; private resolveModelId; } interface IChatSessionTelemetryContext { readonly chatSessionId: string; readonly sessionType: string; readonly harness: string | undefined; } /** Preserves workbench chat IDs while resolving the owning Agent Host session, without its connection authority. */ export declare function getChatSessionTelemetryIds(sessionResource: URI, connectionsService: Pick): { chatSessionId: string; agentSessionId?: string; }; /** Returns telemetry-safe session context, excluding remote Agent Host connection authorities. */ export declare function getChatSessionTelemetryContext(sessionResource: URI): IChatSessionTelemetryContext; export {};