@@ -39,6 +39,7 @@ import {
3939 NotificationType ,
4040 MynahUIProps ,
4141 QuickActionCommand ,
42+ ChatItemFormItem ,
4243} from '@aws/mynah-ui'
4344import { VoteParams } from '../contracts/telemetry'
4445import { Messager } from './messager'
@@ -48,7 +49,12 @@ import { ChatClientAdapter, ChatEventHandler } from '../contracts/chatClientAdap
4849import { withAdapter } from './withAdapter'
4950import { toDetailsWithoutIcon , toMynahButtons , toMynahContextCommand , toMynahHeader , toMynahIcon } from './utils'
5051import { ChatHistory , ChatHistoryList } from './features/history'
51- import { pairProgrammingModeOff , pairProgrammingModeOn , programmerModeCard } from './texts/pairProgramming'
52+ import {
53+ pairProgrammingModeOff ,
54+ pairProgrammingModeOn ,
55+ pairProgrammingPromptInput ,
56+ programmerModeCard ,
57+ } from './texts/pairProgramming'
5258
5359export interface InboundChatApi {
5460 addChatResponse ( params : ChatResult , tabId : string , isPartialResult : boolean ) : void
@@ -72,13 +78,34 @@ const ContextPrompt = {
7278 PromptNameFieldId : 'prompt-name' ,
7379} as const
7480
81+ const getTabPairProgrammingMode = ( mynahUi : MynahUI , tabId : string ) => {
82+ const promptInputOptions = mynahUi . getTabData ( tabId ) ?. getStore ( ) ?. promptInputOptions ?? [ ]
83+ return promptInputOptions . find ( item => item . id === 'pair-programmer-mode' ) ?. value === 'true'
84+ }
85+
7586export const handlePromptInputChange = ( mynahUi : MynahUI , tabId : string , optionsValues : Record < string , string > ) => {
7687 const promptTypeValue = optionsValues [ 'pair-programmer-mode' ]
88+
89+ const store = mynahUi . getTabData ( tabId ) ?. getStore ( )
90+ const currentPromptInputOptions = store ?. promptInputOptions ?? [ ]
91+ const updatedPromptInputOptions : ChatItemFormItem [ ] = currentPromptInputOptions . map ( item =>
92+ item . id === 'pair-programmer-mode' ? ( { ...item , value : promptTypeValue } as ChatItemFormItem ) : item
93+ )
94+ // If the option wasn't found, add it
95+ if ( ! updatedPromptInputOptions . some ( item => item . id === 'pair-programmer-mode' ) ) {
96+ updatedPromptInputOptions . push ( { ...pairProgrammingPromptInput , value : promptTypeValue } as ChatItemFormItem )
97+ }
98+
7799 if ( promptTypeValue === 'true' ) {
78100 mynahUi . addChatItem ( tabId , pairProgrammingModeOn )
79101 } else {
80102 mynahUi . addChatItem ( tabId , pairProgrammingModeOff )
81103 }
104+
105+ // Update the store with the new promptInputOptions array
106+ mynahUi . updateStore ( tabId , {
107+ promptInputOptions : updatedPromptInputOptions ,
108+ } )
82109}
83110
84111export const handleChatPrompt = (
@@ -147,7 +174,6 @@ export const createMynahUi = (
147174 let disclaimerCardActive = ! disclaimerAcknowledged
148175 let programmingModeCardActive = ! pairProgrammingCardAcknowledged
149176 let contextCommandGroups : ContextCommandGroups | undefined
150- let isPairProgrammingMode = true
151177
152178 let chatEventHandlers : ChatEventHandler = {
153179 onCodeInsertToCursorPosition (
@@ -409,9 +435,6 @@ export const createMynahUi = (
409435 throw new Error ( `Unhandled tab bar button id: ${ buttonId } ` )
410436 } ,
411437 onPromptInputOptionChange : ( tabId , optionsValues ) => {
412- if ( optionsValues [ 'pair-programmer-mode' ] !== undefined ) {
413- isPairProgrammingMode = optionsValues [ 'pair-programmer-mode' ] === 'true'
414- }
415438 handlePromptInputChange ( mynahUi , tabId , optionsValues )
416439 messager . onPromptInputOptionChange ( { tabId, optionsValues } )
417440 } ,
@@ -542,6 +565,7 @@ export const createMynahUi = (
542565
543566 const store = mynahUi . getTabData ( tabId ) ?. getStore ( ) || { }
544567 const chatItems = store . chatItems || [ ]
568+ const isPairProgrammingMode : boolean = getTabPairProgrammingMode ( mynahUi , tabId )
545569
546570 if ( chatResult . additionalMessages ?. length ) {
547571 mynahUi . updateStore ( tabId , {
@@ -557,7 +581,7 @@ export const createMynahUi = (
557581 : am . type === 'directive'
558582 ? ChatItemType . DIRECTIVE
559583 : ChatItemType . ANSWER_STREAM ,
560- ...prepareChatItemFromMessage ( am ) ,
584+ ...prepareChatItemFromMessage ( am , isPairProgrammingMode ) ,
561585 }
562586
563587 if ( ! chatItems . find ( ci => ci . messageId === am . messageId ) ) {
@@ -660,15 +684,15 @@ export const createMynahUi = (
660684
661685 const chatItem : ChatItem = {
662686 type : oldMessage . type ,
663- ...prepareChatItemFromMessage ( updatedMessage ) ,
687+ ...prepareChatItemFromMessage ( updatedMessage , getTabPairProgrammingMode ( mynahUi , tabId ) ) ,
664688 }
665689
666690 mynahUi . updateChatAnswerWithMessageId ( tabId , updatedMessage . messageId , chatItem )
667691 } )
668692 }
669693 }
670694
671- const prepareChatItemFromMessage = ( message : ChatMessage ) : Partial < ChatItem > => {
695+ const prepareChatItemFromMessage = ( message : ChatMessage , isPairProgrammingMode : boolean ) : Partial < ChatItem > => {
672696 const contextHeader = contextListToHeader ( message . contextList )
673697 const header = contextHeader || toMynahHeader ( message . header ) // Is this mutually exclusive?
674698
0 commit comments