@@ -35,7 +35,7 @@ import { IIntentService } from '../../intents/node/intentService';
35
35
import { UnknownIntent } from '../../intents/node/unknownIntent' ;
36
36
import { ContributedToolName } from '../../tools/common/toolNames' ;
37
37
import { ChatVariablesCollection } from '../common/chatVariablesCollection' ;
38
- import { Conversation , GlobalContextMessageMetadata , ICopilotChatResult , ICopilotChatResultIn , normalizeSummariesOnRounds , RenderedUserMessageMetadata , Turn , TurnStatus } from '../common/conversation' ;
38
+ import { Conversation , getGlobalContextCacheKey , GlobalContextMessageMetadata , ICopilotChatResult , ICopilotChatResultIn , normalizeSummariesOnRounds , RenderedUserMessageMetadata , Turn , TurnStatus } from '../common/conversation' ;
39
39
import { InternalToolReference } from '../common/intents' ;
40
40
import { ChatTelemetryBuilder } from './chatParticipantTelemetry' ;
41
41
import { DefaultIntentRequestHandler } from './defaultIntentRequestHandler' ;
@@ -325,9 +325,7 @@ export class ChatParticipantRequestHandler {
325
325
326
326
327
327
export function addHistoryToConversation ( accessor : ServicesAccessor , history : ReadonlyArray < ChatRequestTurn | ChatResponseTurn > ) : { turns : Turn [ ] ; sessionId : string | undefined } {
328
- const commandService = accessor . get ( ICommandService ) ;
329
- const conversationStore = accessor . get ( IConversationStore ) ;
330
- const workspaceService = accessor . get ( IWorkspaceService ) ;
328
+ const instaService = accessor . get ( IInstantiationService ) ;
331
329
332
330
const turns : Turn [ ] = [ ] ;
333
331
let sessionId : string | undefined ;
@@ -339,12 +337,12 @@ export function addHistoryToConversation(accessor: ServicesAccessor, history: Re
339
337
if ( entry instanceof ChatRequestTurn ) {
340
338
previousChatRequestTurn = entry ;
341
339
} else {
342
- const existingTurn = findExistingTurnFromVSCodeChatHistoryTurn ( conversationStore , entry ) ;
340
+ const existingTurn = instaService . invokeFunction ( findExistingTurnFromVSCodeChatHistoryTurn , entry ) ;
343
341
if ( existingTurn ) {
344
342
turns . push ( existingTurn ) ;
345
343
} else {
346
344
if ( previousChatRequestTurn ) {
347
- const deserializedTurn = createTurnFromVSCodeChatHistoryTurns ( previousChatRequestTurn , entry , commandService , workspaceService ) ;
345
+ const deserializedTurn = instaService . invokeFunction ( createTurnFromVSCodeChatHistoryTurns , previousChatRequestTurn , entry ) ;
348
346
previousChatRequestTurn = undefined ;
349
347
turns . push ( deserializedTurn ) ;
350
348
}
@@ -363,7 +361,8 @@ export function addHistoryToConversation(accessor: ServicesAccessor, history: Re
363
361
/**
364
362
* Try to find an existing `Turn` instance that we created previously based on the responseId of a vscode turn.
365
363
*/
366
- function findExistingTurnFromVSCodeChatHistoryTurn ( conversationStore : IConversationStore , turn : ChatRequestTurn | ChatResponseTurn ) : Turn | undefined {
364
+ function findExistingTurnFromVSCodeChatHistoryTurn ( accessor : ServicesAccessor , turn : ChatRequestTurn | ChatResponseTurn ) : Turn | undefined {
365
+ const conversationStore = accessor . get ( IConversationStore ) ;
367
366
const responseId = getResponseIdFromVSCodeChatHistoryTurn ( turn ) ;
368
367
const conversation = responseId ? conversationStore . getConversation ( responseId ) : undefined ;
369
368
return conversation ?. turns . find ( turn => turn . id === responseId ) ;
@@ -381,11 +380,14 @@ function getResponseIdFromVSCodeChatHistoryTurn(turn: ChatRequestTurn | ChatResp
381
380
* Try as best as possible to create a `Turn` object from data that comes from vscode.
382
381
*/
383
382
function createTurnFromVSCodeChatHistoryTurns (
383
+ accessor : ServicesAccessor ,
384
384
chatRequestTurn : ChatRequestTurn2 ,
385
- chatResponseTurn : ChatResponseTurn ,
386
- commandService : ICommandService ,
387
- workspaceService : IWorkspaceService
385
+ chatResponseTurn : ChatResponseTurn
388
386
) : Turn {
387
+ const commandService = accessor . get ( ICommandService ) ;
388
+ const workspaceService = accessor . get ( IWorkspaceService ) ;
389
+ const instaService = accessor . get ( IInstantiationService ) ;
390
+
389
391
const currentTurn = new Turn (
390
392
undefined ,
391
393
{ message : chatRequestTurn . prompt , type : 'user' } ,
@@ -428,7 +430,8 @@ function createTurnFromVSCodeChatHistoryTurns(
428
430
currentTurn . setResponse ( status , { message : content , type : 'model' , name : command ?. commandId || UnknownIntent . ID } , undefined , chatResponseTurn . result ) ;
429
431
const turnMetadata = ( chatResponseTurn . result as ICopilotChatResultIn ) . metadata ;
430
432
if ( turnMetadata ?. renderedGlobalContext ) {
431
- currentTurn . setMetadata ( new GlobalContextMessageMetadata ( turnMetadata ?. renderedGlobalContext ) ) ;
433
+ const cacheKey = turnMetadata . globalContextCacheKey ?? instaService . invokeFunction ( getGlobalContextCacheKey ) ;
434
+ currentTurn . setMetadata ( new GlobalContextMessageMetadata ( turnMetadata ?. renderedGlobalContext , cacheKey ) ) ;
432
435
}
433
436
if ( turnMetadata ?. renderedUserMessage ) {
434
437
currentTurn . setMetadata ( new RenderedUserMessageMetadata ( turnMetadata . renderedUserMessage ) ) ;
0 commit comments