File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
packages/core/src/codewhispererChat Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,19 @@ import { ToolkitError } from '../../../../shared/errors'
14
14
import { createCodeWhispererChatStreamingClient } from '../../../../shared/clients/codewhispererChatClient'
15
15
import { createQDeveloperStreamingClient } from '../../../../shared/clients/qDeveloperChatClient'
16
16
import { UserWrittenCodeTracker } from '../../../../codewhisperer/tracker/userWrittenCodeTracker'
17
+ import { PromptMessage } from '../../../controllers/chat/model'
17
18
18
19
export class ChatSession {
19
20
private sessionId ?: string
20
21
/**
21
22
* _readFiles = list of files read from the project to gather context before generating response.
22
23
* _showDiffOnFileWrite = Controls whether to show diff view (true) or file context view (false) to the user
24
+ * _context = Additional context to be passed to the LLM for generating the response
23
25
*/
24
26
private _readFiles : string [ ] = [ ]
25
27
private _toolUse : ToolUse | undefined
26
28
private _showDiffOnFileWrite : boolean = false
29
+ private _context : PromptMessage [ 'context' ]
27
30
28
31
contexts : Map < string , { first : number ; second : number } [ ] > = new Map ( )
29
32
// TODO: doesn't handle the edge case when two files share the same relativePath string but from different root
@@ -41,6 +44,14 @@ export class ChatSession {
41
44
this . _toolUse = toolUse
42
45
}
43
46
47
+ public get context ( ) : PromptMessage [ 'context' ] {
48
+ return this . _context
49
+ }
50
+
51
+ public setContext ( context : PromptMessage [ 'context' ] ) {
52
+ this . _context = context
53
+ }
54
+
44
55
public tokenSource ! : vscode . CancellationTokenSource
45
56
46
57
constructor ( ) {
Original file line number Diff line number Diff line change @@ -709,7 +709,7 @@ export class ChatController {
709
709
toolResults : toolResults ,
710
710
origin : Origin . IDE ,
711
711
chatHistory : this . chatHistoryManager . getHistory ( ) ,
712
- context : [ ] ,
712
+ context : session . context ?? [ ] ,
713
713
relevantTextDocuments : [ ] ,
714
714
additionalContents : [ ] ,
715
715
documentReferences : [ ] ,
@@ -1081,6 +1081,10 @@ export class ChatController {
1081
1081
type : 'chat_message' ,
1082
1082
context,
1083
1083
} )
1084
+
1085
+ // Save the context for the agentic loop
1086
+ session . setContext ( message . context )
1087
+
1084
1088
await this . generateResponse (
1085
1089
{
1086
1090
message : message . message ?? '' ,
You can’t perform that action at this time.
0 commit comments