@@ -37,135 +37,135 @@ const Chat: FC<ChatProps> = memo(({ helloMessage, host, drawerWidth }) => {
37
37
? `calc(${ drawerWidth } px - 90px)`
38
38
: '100%' ;
39
39
return (
40
- < div className = "petercat-lui" >
41
- < div
42
- className = "h-full w-full"
43
- style = { { backgroundColor : globalToken . chatBoxBackgroundColor } }
44
- >
45
- < ProChat
46
- showTitle
47
- chats = { chats }
48
- onChatsChange = { ( chats ) => {
49
- setChats ( chats ) ;
50
- } }
51
- chatRef = { proChatRef }
52
- helloMessage = { helloMessage || BOT_INFO . work_info . prologue }
53
- userMeta = { { title : 'User' } }
54
- chatItemRenderConfig = { {
55
- avatarRender : ( props : ChatItemProps ) => {
56
- if ( props . originData ?. role === Role . user ) {
57
- return < > </ > ;
58
- }
59
- if (
60
- props . originData ?. role === Role . tool ||
61
- props . originData ?. role === Role . knowledge
62
- ) {
63
- return < div className = "w-[40px] h-[40px]" /> ;
64
- }
65
- } ,
66
- contentRender : ( props : ChatItemProps , defaultDom : ReactNode ) => {
67
- const originData = props . originData || { } ;
68
- if ( originData ?. role === Role . user ) {
69
- return defaultDom ;
70
- }
71
- const message = originData . content ;
72
- const defaultMessageContent = (
73
- < div style = { { minWidth : messageMinWidth } } > { defaultDom } </ div >
74
- ) ;
75
-
76
- if ( ! message || ! message . includes ( '<TOOL>' ) ) {
77
- return defaultMessageContent ;
78
- }
79
-
80
- const [ toolStr , answerStr ] = message . split ( '<ANSWER>' ) ;
81
- const tools = toolStr . split ( '\n' ) . filter ( Boolean ) ;
82
- const lastTool = tools [ tools . length - 1 ] ;
40
+ < div className = "petercat-lui" style = { { height : '100%' } } >
41
+ < div
42
+ className = "h-full w-full"
43
+ style = { { backgroundColor : globalToken . chatBoxBackgroundColor } }
44
+ >
45
+ < ProChat
46
+ showTitle
47
+ chats = { chats }
48
+ onChatsChange = { ( chats ) => {
49
+ setChats ( chats ) ;
50
+ } }
51
+ chatRef = { proChatRef }
52
+ helloMessage = { helloMessage || BOT_INFO . work_info . prologue }
53
+ userMeta = { { title : 'User' } }
54
+ chatItemRenderConfig = { {
55
+ avatarRender : ( props : ChatItemProps ) => {
56
+ if ( props . originData ?. role === Role . user ) {
57
+ return < > </ > ;
58
+ }
59
+ if (
60
+ props . originData ?. role === Role . tool ||
61
+ props . originData ?. role === Role . knowledge
62
+ ) {
63
+ return < div className = "w-[40px] h-[40px]" /> ;
64
+ }
65
+ } ,
66
+ contentRender : ( props : ChatItemProps , defaultDom : ReactNode ) => {
67
+ const originData = props . originData || { } ;
68
+ if ( originData ?. role === Role . user ) {
69
+ return defaultDom ;
70
+ }
71
+ const message = originData . content ;
72
+ const defaultMessageContent = (
73
+ < div style = { { minWidth : messageMinWidth } } > { defaultDom } </ div >
74
+ ) ;
83
75
84
- const regex = / < T O O L > ( .* ) / ;
85
- const match = lastTool . match ( regex ) ;
76
+ if ( ! message || ! message . includes ( '<TOOL>' ) ) {
77
+ return defaultMessageContent ;
78
+ }
86
79
87
- if ( ! match ) {
88
- console . error ( 'No valid JSON found in input' ) ;
89
- return defaultMessageContent ;
90
- }
80
+ const [ toolStr , answerStr ] = message . split ( '<ANSWER>' ) ;
81
+ const tools = toolStr . split ( '\n' ) . filter ( Boolean ) ;
82
+ const lastTool = tools [ tools . length - 1 ] ;
91
83
92
- try {
93
- const config = JSON . parse ( match [ 1 ] ) ;
94
- const { type, extra } = config ;
84
+ const regex = / < T O O L > ( .* ) / ;
85
+ const match = lastTool . match ( regex ) ;
95
86
96
- if ( ! [ Role . knowledge , Role . tool ] . includes ( type ) ) {
87
+ if ( ! match ) {
88
+ console . error ( 'No valid JSON found in input' ) ;
97
89
return defaultMessageContent ;
98
90
}
99
91
100
- const { status, source } = extra ;
92
+ try {
93
+ const config = JSON . parse ( match [ 1 ] ) ;
94
+ const { type, extra } = config ;
101
95
102
- return (
103
- < div
104
- className = "p-2 bg-white rounded-md "
105
- style = { { minWidth : messageMinWidth } }
106
- >
107
- < div className = "mb-1" >
108
- < ThoughtChain
109
- content = { extra }
110
- status = { status }
111
- source = { source }
112
- />
96
+ if ( ! [ Role . knowledge , Role . tool ] . includes ( type ) ) {
97
+ return defaultMessageContent ;
98
+ }
99
+
100
+ const { status, source } = extra ;
101
+
102
+ return (
103
+ < div
104
+ className = "p-2 bg-white rounded-md "
105
+ style = { { minWidth : messageMinWidth } }
106
+ >
107
+ < div className = "mb-1" >
108
+ < ThoughtChain
109
+ content = { extra }
110
+ status = { status }
111
+ source = { source }
112
+ />
113
+ </ div >
114
+ < Markdown style = { { overflowX : 'hidden' , overflowY : 'auto' } } >
115
+ { answerStr }
116
+ </ Markdown >
113
117
</ div >
114
- < Markdown style = { { overflowX : 'hidden' , overflowY : 'auto' } } >
115
- { answerStr }
116
- </ Markdown >
117
- </ div >
118
+ ) ;
119
+ } catch ( error ) {
120
+ console . error ( `JSON parse error: ${ error } ` ) ;
121
+ return defaultMessageContent ;
122
+ }
123
+ } ,
124
+ } }
125
+ assistantMeta = { {
126
+ avatar : BOT_INFO . avatar ,
127
+ title : BOT_INFO . resourceName ,
128
+ } }
129
+ autocompleteRequest = { async ( value ) => {
130
+ if ( value === '/' ) {
131
+ return BOT_INFO . work_info . suggested_questions . map (
132
+ ( prompt : string ) => ( {
133
+ value : prompt ,
134
+ label : prompt ,
135
+ } ) ,
118
136
) ;
119
- } catch ( error ) {
120
- console . error ( `JSON parse error: ${ error } ` ) ;
121
- return defaultMessageContent ;
122
137
}
123
- } ,
124
- } }
125
- assistantMeta = { {
126
- avatar : BOT_INFO . avatar ,
127
- title : BOT_INFO . resourceName ,
128
- } }
129
- autocompleteRequest = { async ( value ) => {
130
- if ( value === '/' ) {
131
- return BOT_INFO . work_info . suggested_questions . map (
132
- ( prompt : string ) => ( {
133
- value : prompt ,
134
- label : prompt ,
135
- } ) ,
136
- ) ;
137
- }
138
- return [ ] ;
139
- } }
140
- request = { async ( messages ) => {
141
- const newMessages = messages
142
- . filter (
143
- ( item ) => item . role !== Role . tool && item . role !== Role . knowledge ,
144
- )
145
- . map ( ( message ) => ( {
146
- role : message . role ,
147
- content : message . content as string ,
148
- } ) ) ;
138
+ return [ ] ;
139
+ } }
140
+ request = { async ( messages ) => {
141
+ const newMessages = messages
142
+ . filter (
143
+ ( item ) => item . role !== Role . tool && item . role !== Role . knowledge ,
144
+ )
145
+ . map ( ( message ) => ( {
146
+ role : message . role ,
147
+ content : message . content as string ,
148
+ } ) ) ;
149
149
150
- const response = await streamChat ( newMessages , host ) ;
151
- return handleStream ( response ) ;
152
- } }
153
- inputAreaProps = { { className : 'userInputBox h-24 !important' } }
154
- actions = { {
155
- render : ( ) => [
156
- < StopBtn
157
- key = "StopBtn"
158
- visible = { ! ! proChatRef ?. current ?. getChatLoadingId ( ) }
159
- action = { ( ) => proChatRef ?. current ?. stopGenerateMessage ( ) }
160
- /> ,
161
- < Actions key = "Actions" > </ Actions > ,
162
- ] ,
163
- flexConfig : {
164
- gap : 24 ,
165
- direction : 'vertical' ,
166
- justify : 'space-between' ,
167
- } ,
168
- } }
150
+ const response = await streamChat ( newMessages , host ) ;
151
+ return handleStream ( response ) ;
152
+ } }
153
+ inputAreaProps = { { className : 'userInputBox h-24 !important' } }
154
+ actions = { {
155
+ render : ( ) => [
156
+ < StopBtn
157
+ key = "StopBtn"
158
+ visible = { ! ! proChatRef ?. current ?. getChatLoadingId ( ) }
159
+ action = { ( ) => proChatRef ?. current ?. stopGenerateMessage ( ) }
160
+ /> ,
161
+ < Actions key = "Actions" > </ Actions > ,
162
+ ] ,
163
+ flexConfig : {
164
+ gap : 24 ,
165
+ direction : 'vertical' ,
166
+ justify : 'space-between' ,
167
+ } ,
168
+ } }
169
169
/>
170
170
</ div >
171
171
</ div >
0 commit comments