44 */
55import {
66 ChatMessage ,
7- Tool ,
87 ToolResult ,
98 ToolResultStatus ,
109 UserInputMessage ,
1110 UserInputMessageContext ,
1211} from '@amzn/codewhisperer-streaming'
1312import { randomUUID } from '../../shared/crypto'
1413import { getLogger } from '../../shared/logger/logger'
15- import { tools } from '../constants'
14+ import { tools , noWriteTools } from '../constants'
15+ import { ChatSessionStorage } from './chatSession'
1616
1717// Maximum number of messages to keep in history
1818const MaxConversationHistoryLength = 100
@@ -27,12 +27,12 @@ export class ChatHistoryManager {
2727 private history : ChatMessage [ ] = [ ]
2828 private logger = getLogger ( )
2929 private lastUserMessage ?: ChatMessage
30- private tools : Tool [ ] = [ ]
30+ private sessionStorage : ChatSessionStorage
3131
3232 constructor ( tabId ?: string ) {
3333 this . conversationId = randomUUID ( )
3434 this . tabId = tabId ?? randomUUID ( )
35- this . tools = tools
35+ this . sessionStorage = new ChatSessionStorage ( )
3636 }
3737
3838 /**
@@ -46,10 +46,6 @@ export class ChatHistoryManager {
4646 this . conversationId = conversationId
4747 }
4848
49- public setTools ( tools : Tool [ ] ) {
50- this . tools = tools
51- }
52-
5349 /**
5450 * Get the tab ID
5551 */
@@ -182,11 +178,14 @@ export class ChatHistoryManager {
182178 status : ToolResultStatus . ERROR ,
183179 } ) )
184180
181+ const session = this . sessionStorage . getSession ( this . tabId )
182+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
183+
185184 newUserMessage . userInputMessage . userInputMessageContext = {
186185 shellState : undefined ,
187186 envState : undefined ,
188187 toolResults : toolResults ,
189- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
188+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
190189 }
191190
192191 return newUserMessage
@@ -203,11 +202,14 @@ export class ChatHistoryManager {
203202 * Adds tool results to the conversation.
204203 */
205204 addToolResults ( toolResults : ToolResult [ ] ) : void {
205+ const session = this . sessionStorage . getSession ( this . tabId )
206+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
207+
206208 const userInputMessageContext : UserInputMessageContext = {
207209 shellState : undefined ,
208210 envState : undefined ,
209211 toolResults : toolResults ,
210- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
212+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
211213 }
212214
213215 const msg : UserInputMessage = {
@@ -252,12 +254,15 @@ export class ChatHistoryManager {
252254 status : ToolResultStatus . ERROR ,
253255 } ) )
254256
257+ const session = this . sessionStorage . getSession ( this . tabId )
258+ const availableTools = session . pairProgrammingModeOn ? tools : noWriteTools
259+
255260 // Create a new user message with cancelled tool results
256261 const userInputMessageContext : UserInputMessageContext = {
257262 shellState : undefined ,
258263 envState : undefined ,
259264 toolResults : toolResults ,
260- tools : this . tools . length === 0 ? undefined : [ ...this . tools ] ,
265+ tools : availableTools . length === 0 ? undefined : [ ...availableTools ] ,
261266 }
262267
263268 const userMessage : ChatMessage = {
0 commit comments