@@ -5,14 +5,16 @@ import { PalicoContext } from '../../context'
55import { ChatHistory } from './history'
66import { ChatInput } from './input'
77
8+ export type GetSendMessageParamsFN = ( userInput : string ) => Promise < {
9+ message : string
10+ context : Record < string , unknown >
11+ } >
12+
813export interface ChatUIProps {
914 headerTitle ?: string
1015 inputPlaceholder ?: string
1116 initialPlaceholderAgentMessage ?: string
12- getSendMessageParams ?: ( userInput : string ) => Promise < {
13- message : string
14- params : Record < string , unknown >
15- } >
17+ getSendMessageParams ?: GetSendMessageParamsFN
1618}
1719
1820const DEFAULT_VALUES = {
@@ -27,16 +29,17 @@ const ChatUI: React.FC<ChatUIProps> = ({
2729 initialPlaceholderAgentMessage = DEFAULT_VALUES . initialPlaceholderAgentMessage ,
2830 getSendMessageParams
2931} ) => {
30- const { conversationHistory, sendMessage } = useContext ( PalicoContext )
32+ const { conversationHistory, loading , sendMessage } = useContext ( PalicoContext )
3133 const [ errorMessage , setErrorMessage ] = React . useState < string | null > ( null )
3234
3335 const handleSend = async ( message : string ) : Promise < void > => {
36+ if ( ! sendMessage ) throw new Error ( 'sendMessage is not defined' )
3437 try {
3538 if ( getSendMessageParams ) {
36- const { message : newMessage , params } = await getSendMessageParams (
39+ const { message : newMessage , context } = await getSendMessageParams (
3740 message
3841 )
39- await sendMessage ( newMessage , params )
42+ await sendMessage ( newMessage , context )
4043 } else {
4144 await sendMessage ( message , { } )
4245 }
@@ -56,8 +59,10 @@ const ChatUI: React.FC<ChatUIProps> = ({
5659 alignItems = "stretch"
5760 spacing = { 2 }
5861 sx = { {
59- p : 2 ,
60- height : '100%'
62+ width : '100%' ,
63+ height : '100%' ,
64+ padding : 2 ,
65+ boxSizing : 'border-box'
6166 } }
6267 >
6368 < Box >
@@ -83,7 +88,7 @@ const ChatUI: React.FC<ChatUIProps> = ({
8388 < Box >
8489 < ChatInput
8590 placeholder = { inputPlaceholder }
86- disabled = { errorMessage !== null }
91+ disabled = { errorMessage !== null || loading }
8792 onSend = { handleSend }
8893 />
8994 </ Box >
0 commit comments