4
4
*/
5
5
import {
6
6
ChatMessage ,
7
- Tool ,
8
7
ToolResult ,
9
8
ToolResultStatus ,
10
9
UserInputMessage ,
11
10
UserInputMessageContext ,
12
11
} from '@amzn/codewhisperer-streaming'
13
12
import { randomUUID } from '../../shared/crypto'
14
13
import { getLogger } from '../../shared/logger/logger'
15
- import { tools } from '../constants'
14
+ import { tools , noWriteTools } from '../constants'
15
+ import { ChatSessionStorage } from './chatSession'
16
16
17
17
// Maximum number of messages to keep in history
18
18
const MaxConversationHistoryLength = 100
@@ -27,12 +27,12 @@ export class ChatHistoryManager {
27
27
private history : ChatMessage [ ] = [ ]
28
28
private logger = getLogger ( )
29
29
private lastUserMessage ?: ChatMessage
30
- private tools : Tool [ ] = [ ]
30
+ private sessionStorage : ChatSessionStorage
31
31
32
32
constructor ( tabId ?: string ) {
33
33
this . conversationId = randomUUID ( )
34
34
this . tabId = tabId ?? randomUUID ( )
35
- this . tools = tools
35
+ this . sessionStorage = new ChatSessionStorage ( )
36
36
}
37
37
38
38
/**
@@ -46,10 +46,6 @@ export class ChatHistoryManager {
46
46
this . conversationId = conversationId
47
47
}
48
48
49
- public setTools ( tools : Tool [ ] ) {
50
- this . tools = tools
51
- }
52
-
53
49
/**
54
50
* Get the tab ID
55
51
*/
@@ -182,11 +178,14 @@ export class ChatHistoryManager {
182
178
status : ToolResultStatus . ERROR ,
183
179
} ) )
184
180
181
+ const session = this . sessionStorage . getSession ( this . tabId )
182
+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
183
+
185
184
newUserMessage . userInputMessage . userInputMessageContext = {
186
185
shellState : undefined ,
187
186
envState : undefined ,
188
187
toolResults : toolResults ,
189
- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
188
+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
190
189
}
191
190
192
191
return newUserMessage
@@ -203,11 +202,14 @@ export class ChatHistoryManager {
203
202
* Adds tool results to the conversation.
204
203
*/
205
204
addToolResults ( toolResults : ToolResult [ ] ) : void {
205
+ const session = this . sessionStorage . getSession ( this . tabId )
206
+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
207
+
206
208
const userInputMessageContext : UserInputMessageContext = {
207
209
shellState : undefined ,
208
210
envState : undefined ,
209
211
toolResults : toolResults ,
210
- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
212
+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
211
213
}
212
214
213
215
const msg : UserInputMessage = {
@@ -252,12 +254,15 @@ export class ChatHistoryManager {
252
254
status : ToolResultStatus . ERROR ,
253
255
} ) )
254
256
257
+ const session = this . sessionStorage . getSession ( this . tabId )
258
+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
259
+
255
260
// Create a new user message with cancelled tool results
256
261
const userInputMessageContext : UserInputMessageContext = {
257
262
shellState : undefined ,
258
263
envState : undefined ,
259
264
toolResults : toolResults ,
260
- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
265
+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
261
266
}
262
267
263
268
const userMessage : ChatMessage = {
0 commit comments