44 *--------------------------------------------------------------------------------------------*/
55
66import { Raw } from '@vscode/prompt-tsx' ;
7+ import type { OpenAI } from 'openai' ;
78import type { CancellationToken } from 'vscode' ;
89import { IAuthenticationService } from '../../../platform/authentication/common/authentication' ;
910import { CopilotToken } from '../../../platform/authentication/common/copilotToken' ;
@@ -14,14 +15,15 @@ import { IConversationOptions } from '../../../platform/chat/common/conversation
1415import { getTextPart , toTextParts } from '../../../platform/chat/common/globalStringUtils' ;
1516import { IInteractionService } from '../../../platform/chat/common/interactionService' ;
1617import { ConfigKey , HARD_TOOL_LIMIT , IConfigurationService } from '../../../platform/configuration/common/configurationService' ;
17- import { isAnthropicToolSearchEnabled } from '../../../platform/networking/common/anthropic' ;
1818import { ICAPIClientService } from '../../../platform/endpoint/common/capiClient' ;
1919import { isAutoModel } from '../../../platform/endpoint/node/autoChatEndpoint' ;
20+ import { responseApiInputToRawMessagesForLogging } from '../../../platform/endpoint/node/responsesApi' ;
2021import { collectSingleLineErrorMessage , ILogService } from '../../../platform/log/common/logService' ;
22+ import { isAnthropicToolSearchEnabled } from '../../../platform/networking/common/anthropic' ;
2123import { FinishedCallback , getRequestId , IResponseDelta , OptionalChatRequestParams } from '../../../platform/networking/common/fetch' ;
2224import { FetcherId , IFetcherService , Response } from '../../../platform/networking/common/fetcherService' ;
2325import { IChatEndpoint , IEndpointBody , postRequest , stringifyUrlOrRequestMetadata } from '../../../platform/networking/common/networking' ;
24- import { CAPIChatMessage , ChatCompletion , FilterReason , FinishedCompletionReason } from '../../../platform/networking/common/openai' ;
26+ import { CAPIChatMessage , ChatCompletion , FilterReason , FinishedCompletionReason , rawMessageToCAPI } from '../../../platform/networking/common/openai' ;
2527import { sendEngineMessagesTelemetry } from '../../../platform/networking/node/chatStream' ;
2628import { sendCommunicationErrorTelemetry } from '../../../platform/networking/node/stream' ;
2729import { ChatFailKind , ChatRequestCanceled , ChatRequestFailed , ChatResults , FetchResponseKind } from '../../../platform/openai/node/fetch' ;
@@ -793,7 +795,20 @@ export class ChatMLFetcherImpl extends AbstractChatMLFetcher {
793795 throw error ;
794796 } )
795797 . finally ( ( ) => {
796- sendEngineMessagesTelemetry ( this . _telemetryService , request . messages ?? [ ] , telemetryData , false , this . _logService ) ;
798+ let messagesToLog = request . messages ;
799+
800+ // For Response API (has input but no messages), convert input to messages for logging
801+ if ( ( ! messagesToLog || messagesToLog . length === 0 ) && ( request as OpenAI . Responses . ResponseCreateParams ) . input ) {
802+ try {
803+ const rawMessages = responseApiInputToRawMessagesForLogging ( request as OpenAI . Responses . ResponseCreateParams ) ;
804+ messagesToLog = rawMessageToCAPI ( rawMessages ) ;
805+ } catch ( e ) {
806+ this . _logService . error ( `Failed to convert Response API input to messages for telemetry:` , e ) ;
807+ messagesToLog = [ ] ;
808+ }
809+ }
810+
811+ sendEngineMessagesTelemetry ( this . _telemetryService , messagesToLog ?? [ ] , telemetryData , false , this . _logService ) ;
797812 } ) ;
798813 }
799814
0 commit comments