@@ -98,11 +98,11 @@ type ChatProps = {
98
98
humanText ? : string ;
99
99
onPrompt : ( prompt : string ) => void ;
100
100
onResponse : ( { prompt, response, contentType, entryId} : { prompt : string , response : string , contentType : ChatContent , entryId : number } ) => void ;
101
- modifyResponse : ( id : number , delta ?: any ) => void ;
102
101
clearConversation : ( ) => void ;
103
102
} ;
104
- function Chat ( { entries, humanText, onPrompt, onResponse, modifyResponse , clearConversation} : ChatProps ) : JSX . Element {
103
+ function Chat ( { entries, humanText, onPrompt, onResponse, clearConversation} : ChatProps ) : JSX . Element {
105
104
const styles = React . useContext ( StylesContext ) ;
105
+ const chatHistory = React . useContext ( ChatHistoryContext ) ;
106
106
const [ showFeedbackPopup , setShowFeedbackPopup ] = React . useState ( false ) ;
107
107
const [ showSettingsPopup , setShowSettingsPopup ] = React . useState ( false ) ;
108
108
const [ feedbackIsPositive , setFeedbackIsPositive ] = React . useState ( false ) ;
@@ -124,78 +124,76 @@ function Chat({entries, humanText, onPrompt, onResponse, modifyResponse, clearCo
124
124
125
125
return (
126
126
< FeedbackContext . Provider value = { feedbackContext } >
127
- < ChatHistoryContext . Provider value = { { entries : entries , modifyResponse : modifyResponse } } >
128
- < ChatScrollContext . Provider value = { { scrollToEnd : scrollToEnd } } >
129
- < View style = { styles . appContent } >
130
- < ScrollView
131
- contentInsetAdjustmentBehavior = "automatic"
132
- ref = { scrollViewRef }
133
- style = { { flexShrink : 1 } } >
134
- < View
135
- style = { { gap : 12 } } >
136
- { // For each item in the chat log, render the appropriate component
137
- entries . map ( ( entry ) => (
138
- < View key = { entry . id } >
139
- {
140
- entry . type === ChatSource . Human ?
141
- // Human inputs are always plain text
142
- < HumanSection content = { entry . text } /> :
143
- entry . content ?
144
- // The element may have provided its own UI
145
- entry . content :
146
- // Otherwise, either render the completed query or start a query to get the resolved text
147
- entry . text ?
148
- < AiSectionContent
149
- id = { entry . id }
150
- content = { entry } /> :
151
- < AiSectionWithQuery
152
- id = { entry . id }
153
- prompt = { entry . prompt ?? "" }
154
- intent = { entry . intent }
155
- onResponse = { ( { prompt, response, contentType} ) => onResponse ( { prompt : prompt , response : response , contentType : contentType , entryId : entry . id } ) } />
156
- }
157
- </ View >
158
- ) ) }
159
- { ( entries . length > 0 ) &&
160
- < View style = { { alignSelf : 'center' } } >
161
- < Button
162
- title = "🔁 Regenerate response"
163
- onPress = { ( ) => {
164
- // Clear the response for the last entry
165
- modifyResponse ( entries . length - 1 , { text : undefined } ) ;
166
- } } />
167
- </ View >
168
- }
169
- </ View >
170
- </ ScrollView >
127
+ < ChatScrollContext . Provider value = { { scrollToEnd : scrollToEnd } } >
128
+ < View style = { styles . appContent } >
129
+ < ScrollView
130
+ contentInsetAdjustmentBehavior = "automatic"
131
+ ref = { scrollViewRef }
132
+ style = { { flexShrink : 1 } } >
171
133
< View
172
- style = { { flexShrink : 0 , marginBottom : 12 } } >
173
- < HumanSection
174
- disableEdit = { true }
175
- disableCopy = { true }
176
- contentShownOnHover = {
177
- < HoverButton content = "⚙️" onPress = { ( ) => setShowSettingsPopup ( true ) } />
178
- } >
179
- < ChatEntry
180
- defaultText = { humanText }
181
- submit = { ( newEntry ) => {
182
- onPrompt ( newEntry ) ;
183
- scrollToEnd ( ) ;
184
- } }
185
- clearConversation = { clearConversation } />
186
- </ HumanSection >
134
+ style = { { gap : 12 } } >
135
+ { // For each item in the chat log, render the appropriate component
136
+ entries . map ( ( entry ) => (
137
+ < View key = { entry . id } >
138
+ {
139
+ entry . type === ChatSource . Human ?
140
+ // Human inputs are always plain text
141
+ < HumanSection content = { entry . text } /> :
142
+ entry . content ?
143
+ // The element may have provided its own UI
144
+ entry . content :
145
+ // Otherwise, either render the completed query or start a query to get the resolved text
146
+ entry . text ?
147
+ < AiSectionContent
148
+ id = { entry . id }
149
+ content = { entry } /> :
150
+ < AiSectionWithQuery
151
+ id = { entry . id }
152
+ prompt = { entry . prompt ?? "" }
153
+ intent = { entry . intent }
154
+ onResponse = { ( { prompt, response, contentType} ) => onResponse ( { prompt : prompt , response : response , contentType : contentType , entryId : entry . id } ) } />
155
+ }
156
+ </ View >
157
+ ) ) }
158
+ { ( entries . length > 0 ) &&
159
+ < View style = { { alignSelf : 'center' } } >
160
+ < Button
161
+ title = "🔁 Regenerate response"
162
+ onPress = { ( ) => {
163
+ // Clear the response for the last entry
164
+ chatHistory . modifyResponse ( entries . length - 1 , { text : undefined } ) ;
165
+ } } />
166
+ </ View >
167
+ }
187
168
</ View >
188
- { ( showFeedbackPopup || showSettingsPopup ) && < View style = { styles . popupBackground } /> }
189
- < FeedbackPopup
190
- show = { showFeedbackPopup }
191
- isPositive = { feedbackIsPositive }
192
- close = { ( ) => setShowFeedbackPopup ( false ) } />
193
- < SettingsPopup
194
- show = { showSettingsPopup }
195
- close = { ( ) => setShowSettingsPopup ( false ) } />
169
+ </ ScrollView >
170
+ < View
171
+ style = { { flexShrink : 0 , marginBottom : 12 } } >
172
+ < HumanSection
173
+ disableEdit = { true }
174
+ disableCopy = { true }
175
+ contentShownOnHover = {
176
+ < HoverButton content = "⚙️" onPress = { ( ) => setShowSettingsPopup ( true ) } />
177
+ } >
178
+ < ChatEntry
179
+ defaultText = { humanText }
180
+ submit = { ( newEntry ) => {
181
+ onPrompt ( newEntry ) ;
182
+ scrollToEnd ( ) ;
183
+ } }
184
+ clearConversation = { clearConversation } />
185
+ </ HumanSection >
196
186
</ View >
197
- </ ChatScrollContext . Provider >
198
- </ ChatHistoryContext . Provider >
187
+ { ( showFeedbackPopup || showSettingsPopup ) && < View style = { styles . popupBackground } /> }
188
+ < FeedbackPopup
189
+ show = { showFeedbackPopup }
190
+ isPositive = { feedbackIsPositive }
191
+ close = { ( ) => setShowFeedbackPopup ( false ) } />
192
+ < SettingsPopup
193
+ show = { showSettingsPopup }
194
+ close = { ( ) => setShowSettingsPopup ( false ) } />
195
+ </ View >
196
+ </ ChatScrollContext . Provider >
199
197
</ FeedbackContext . Provider >
200
198
) ;
201
199
}
0 commit comments