@@ -13,8 +13,6 @@ import { IChatQuotaService } from '../../chat/common/chatQuotaService';
1313import { ChatLocation } from '../../chat/common/commonTypes' ;
1414import { IInteractionService } from '../../chat/common/interactionService' ;
1515import { ICAPIClientService } from '../../endpoint/common/capiClient' ;
16- import { IDomainService } from '../../endpoint/common/domainService' ;
17- import { IEnvService } from '../../env/common/envService' ;
1816import { ILogService } from '../../log/common/logService' ;
1917import { FinishedCallback , OptionalChatRequestParams , RequestId , getProcessingTime , getRequestId } from '../../networking/common/fetch' ;
2018import { FetcherId , IFetcherService , Response } from '../../networking/common/fetcherService' ;
@@ -113,13 +111,8 @@ export async function fetchAndStreamChat(
113111) : Promise < ChatResults | ChatRequestFailed | ChatRequestCanceled > {
114112 const logService = accessor . get ( ILogService ) ;
115113 const telemetryService = accessor . get ( ITelemetryService ) ;
116- const fetcherService = accessor . get ( IFetcherService ) ;
117- const envService = accessor . get ( IEnvService ) ;
118114 const chatQuotaService = accessor . get ( IChatQuotaService ) ;
119- const domainService = accessor . get ( IDomainService ) ;
120- const capiClientService = accessor . get ( ICAPIClientService ) ;
121115 const authenticationService = accessor . get ( IAuthenticationService ) ;
122- const interactionService = accessor . get ( IInteractionService ) ;
123116 const instantiationService = accessor . get ( IInstantiationService ) ;
124117 if ( cancel ?. isCancellationRequested ) {
125118 return { type : FetchResponseKind . Canceled , reason : 'before fetch request' } ;
@@ -146,24 +139,19 @@ export async function fetchAndStreamChat(
146139 // Generate unique ID to link input and output messages
147140 const modelCallId = generateUuid ( ) ;
148141
149- const response = await fetchWithInstrumentation (
150- logService ,
151- telemetryService ,
152- fetcherService ,
153- envService ,
154- domainService ,
155- capiClientService ,
156- interactionService ,
157- chatEndpointInfo ,
158- ourRequestId ,
159- request ,
160- secretKey ,
161- location ,
162- userInitiatedRequest ,
163- cancel ,
164- { ...telemetryProperties , modelCallId } ,
165- useFetcher ,
166- ) ;
142+ const response = await instantiationService . invokeFunction ( accessor =>
143+ fetchWithInstrumentation (
144+ accessor ,
145+ chatEndpointInfo ,
146+ ourRequestId ,
147+ request ,
148+ secretKey ,
149+ location ,
150+ userInitiatedRequest ,
151+ cancel ,
152+ { ...telemetryProperties , modelCallId } ,
153+ useFetcher ,
154+ ) ) ;
167155
168156 if ( cancel ?. isCancellationRequested ) {
169157 const body = await response ! . body ( ) ;
@@ -463,13 +451,7 @@ async function handleError(
463451}
464452
465453async function fetchWithInstrumentation (
466- logService : ILogService ,
467- telemetryService : ITelemetryService ,
468- fetcherService : IFetcherService ,
469- envService : IEnvService ,
470- domainService : IDomainService ,
471- capiClientService : ICAPIClientService ,
472- interactionService : IInteractionService ,
454+ accessor : ServicesAccessor ,
473455 chatEndpoint : IChatEndpoint ,
474456 ourRequestId : string ,
475457 request : IEndpointBody ,
@@ -480,6 +462,11 @@ async function fetchWithInstrumentation(
480462 telemetryProperties ?: TelemetryProperties ,
481463 useFetcher ?: FetcherId ,
482464) : Promise < Response > {
465+ const logService = accessor . get ( ILogService ) ;
466+ const telemetryService = accessor . get ( ITelemetryService ) ;
467+ const fetcherService = accessor . get ( IFetcherService ) ;
468+ const capiClientService = accessor . get ( ICAPIClientService ) ;
469+ const interactionService = accessor . get ( IInteractionService ) ;
483470
484471 // If request contains an image, we include this header.
485472 const additionalHeaders : Record < string , string > = {
0 commit comments