yt-chat-components 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -167,6 +167,7 @@ export default function ChatWindow({
|
|
|
167
167
|
const handleDelayMessage = () => {
|
|
168
168
|
if (delayMessageList.length > 0) {
|
|
169
169
|
const message = delayMessageList.shift();
|
|
170
|
+
console.log("-- add = delay")
|
|
170
171
|
addMessage(message);
|
|
171
172
|
handleDelayMessage();
|
|
172
173
|
}
|
|
@@ -214,7 +215,7 @@ export default function ChatWindow({
|
|
|
214
215
|
const res = {
|
|
215
216
|
data: data['result'],
|
|
216
217
|
};
|
|
217
|
-
if (false&&
|
|
218
|
+
if (false &&
|
|
218
219
|
res.data &&
|
|
219
220
|
res.data.outputs &&
|
|
220
221
|
Object.keys(res.data.outputs).length > 0 &&
|
|
@@ -267,15 +268,19 @@ export default function ChatWindow({
|
|
|
267
268
|
});
|
|
268
269
|
}
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
271
|
+
// 使用完后清理 contentRef
|
|
272
|
+
if (contentRef.current != null) {
|
|
273
|
+
const output = {
|
|
274
|
+
message:contentRef.current,
|
|
275
|
+
type:'text'
|
|
276
|
+
};
|
|
277
|
+
addMessage({
|
|
278
|
+
message: extractMessageFromOutput(output),
|
|
279
|
+
isSend: false,
|
|
280
|
+
rawInfo: output.message,
|
|
281
|
+
});
|
|
282
|
+
contentRef.current = null
|
|
283
|
+
}
|
|
279
284
|
setSendingMessage(false);
|
|
280
285
|
}
|
|
281
286
|
};
|
|
@@ -809,105 +814,59 @@ export default function ChatWindow({
|
|
|
809
814
|
return <></>
|
|
810
815
|
}
|
|
811
816
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
isTitleSideIcon ?
|
|
825
|
-
<img className="p_logoImg" style={{width: logoWidth, height: 'auto', marginRight: 10}}
|
|
826
|
-
src={agentUrl}/> :
|
|
827
|
-
<span className="diamond"/>
|
|
828
|
-
}
|
|
829
|
-
{window_title}
|
|
830
|
-
</div>
|
|
831
|
-
)
|
|
832
|
-
}
|
|
833
|
-
<div className="cl-header-subtitle"/>
|
|
834
|
-
{renderTipsInfo()}
|
|
835
|
-
</div>
|
|
836
|
-
<div
|
|
837
|
-
className="cl-messages_container"
|
|
838
|
-
style={isMobile ? {paddingLeft: '0', paddingRight: '0'} :{}}
|
|
839
|
-
// style={{ maxWidth: '100%', minHeight:'300px', height:'700px', paddingBottom: '56px' }}
|
|
840
|
-
>
|
|
841
|
-
{messages.map((message, index) => (
|
|
842
|
-
<ChatMessage
|
|
843
|
-
bot_message_style={bot_message_style}
|
|
844
|
-
user_message_style={user_message_style}
|
|
845
|
-
error_message_style={error_message_style}
|
|
846
|
-
key={index}
|
|
847
|
-
host_url={hostUrl}
|
|
848
|
-
message={message}
|
|
849
|
-
isSend={message.isSend}
|
|
850
|
-
error={message.error}
|
|
851
|
-
type={message.type}
|
|
852
|
-
rawInfo={message.rawInfo}
|
|
853
|
-
handleSendMessage={handleSendMessage}
|
|
854
|
-
/>
|
|
855
|
-
))}
|
|
856
|
-
{sendingMessage && (nowAIContent?
|
|
857
|
-
<ChatMessage
|
|
858
|
-
bot_message_style={bot_message_style}
|
|
859
|
-
user_message_style={user_message_style}
|
|
860
|
-
error_message_style={error_message_style}
|
|
861
|
-
key={1688574569}
|
|
862
|
-
host_url={hostUrl}
|
|
863
|
-
message={{ message: nowAIContent}}
|
|
864
|
-
isSend={false}
|
|
865
|
-
handleSendMessage={handleSendMessage}
|
|
866
|
-
/>:<ChatMessagePlaceholder bot_message_style={bot_message_style} />
|
|
867
|
-
)}
|
|
868
|
-
<div ref={lastMessage}></div>
|
|
869
|
-
</div>
|
|
817
|
+
const renderInputArea = () => {
|
|
818
|
+
let isRender = messages.length === 0
|
|
819
|
+
if(messages.length > 0){
|
|
820
|
+
isRender = messages[messages.length - 1].type !== MessageType.form
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if(!isRender){
|
|
824
|
+
return <></>
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return (
|
|
828
|
+
<>
|
|
870
829
|
<div
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
:
|
|
885
|
-
{
|
|
830
|
+
className="w_tagListClass"
|
|
831
|
+
style={isMobile ?
|
|
832
|
+
{
|
|
833
|
+
display: tagList?.length > 0 ? '' : 'none',
|
|
834
|
+
zIndex: tagList?.length > 0 ? '2' : '-1',
|
|
835
|
+
maxWidth: 'calc(100vw - 3.2rem)',
|
|
836
|
+
flexWrap: "nowrap",
|
|
837
|
+
overflowX: "auto",
|
|
838
|
+
WebkitOverflowScrolling: 'touch',
|
|
839
|
+
scrollbarWidth: "none",
|
|
840
|
+
overflowY: "hidden",
|
|
841
|
+
background: 'transparent',
|
|
842
|
+
} : {
|
|
886
843
|
// bottom: fileList.length > 0 ? '130px' : '80px',
|
|
887
844
|
display: tagList?.length > 0 ? '' : 'none',
|
|
888
845
|
zIndex: tagList?.length > 0 ? '2' : '-1',
|
|
889
846
|
}}
|
|
890
847
|
>
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
<div className="w_tagItemText" style={isMobile ? {wordBreak: "keep-all"} : {}}>{item?.name}</div>
|
|
848
|
+
{
|
|
849
|
+
tagList.map((item, index) => (
|
|
850
|
+
<div
|
|
851
|
+
key={index}
|
|
852
|
+
className="w_tagItemBox"
|
|
853
|
+
onClick={() => {
|
|
854
|
+
handleSendMessage(item?.name);
|
|
855
|
+
setFileList([]);
|
|
856
|
+
}}
|
|
857
|
+
>
|
|
858
|
+
<div>
|
|
859
|
+
<img
|
|
860
|
+
style={item?.img ? {} : { display: 'none' }}
|
|
861
|
+
src={'https://trans-from-yuntu-resourse.oss-cn-beijing.aliyuncs.com/'+ item?.img}
|
|
862
|
+
className="w_tagImgh"
|
|
863
|
+
alt="Image"
|
|
864
|
+
/>
|
|
909
865
|
</div>
|
|
910
|
-
|
|
866
|
+
<div className="w_tagItemText" style={isMobile ? {wordBreak: "keep-all"} : {}}>{item?.name}</div>
|
|
867
|
+
</div>
|
|
868
|
+
))
|
|
869
|
+
}
|
|
911
870
|
</div>
|
|
912
871
|
<div style={input_container_style} className="cl-input_container">
|
|
913
872
|
<div className="w_file_preview" ref={scrollContainerRef} onScroll={handleScroll}>
|
|
@@ -921,20 +880,23 @@ export default function ChatWindow({
|
|
|
921
880
|
<img src={toRightPng}/>
|
|
922
881
|
</div>
|
|
923
882
|
</div>
|
|
924
|
-
{
|
|
925
|
-
|
|
883
|
+
{
|
|
884
|
+
fileList.map((item, index) => {
|
|
885
|
+
return (
|
|
926
886
|
<div key={item.filePath} className="w_fileBox">
|
|
927
|
-
{
|
|
887
|
+
{
|
|
888
|
+
item.fileType == 'image' && (
|
|
928
889
|
<Image
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
890
|
+
height={40}
|
|
891
|
+
width={40}
|
|
892
|
+
src={item.fileUrl}
|
|
893
|
+
className="w_upImg"
|
|
894
|
+
preview={{
|
|
895
|
+
mask: <span className="custom-mask"></span>,
|
|
896
|
+
}}
|
|
936
897
|
/>
|
|
937
|
-
|
|
898
|
+
)
|
|
899
|
+
}
|
|
938
900
|
{getFileTypeByUrl(item.file.name) == 'pdf' && (
|
|
939
901
|
<img style={{width: 40, height: 40}} src={typePdfPng}/>
|
|
940
902
|
)}
|
|
@@ -974,11 +936,12 @@ export default function ChatWindow({
|
|
|
974
936
|
<img src={closexPng}/>
|
|
975
937
|
</div>
|
|
976
938
|
</div>
|
|
977
|
-
|
|
978
|
-
|
|
939
|
+
);
|
|
940
|
+
})
|
|
941
|
+
}
|
|
979
942
|
</div>
|
|
980
943
|
<div className="w_inputBox" style={{height: inputContainerHeight}}>
|
|
981
|
-
|
|
944
|
+
<textarea
|
|
982
945
|
onFocus={()=>setInputContainerHeight('120px')}
|
|
983
946
|
onBlur={()=>setInputContainerHeight('50px')}
|
|
984
947
|
value={value}
|
|
@@ -995,14 +958,14 @@ export default function ChatWindow({
|
|
|
995
958
|
style={{...input_style,resize:"none"}}
|
|
996
959
|
ref={inputRef}
|
|
997
960
|
className="cl-input-element"
|
|
998
|
-
|
|
961
|
+
/>
|
|
999
962
|
{
|
|
1000
963
|
isShowVoiceButton &&
|
|
1001
964
|
<Tooltip title={recordState ? "点击结束录音" : "点击开始录音"}>
|
|
1002
965
|
<div
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
966
|
+
className="w_send_voice_box"
|
|
967
|
+
style={sendingMessage ? { cursor: 'not-allowed' } : {}}
|
|
968
|
+
onClick={startRecord}
|
|
1006
969
|
>
|
|
1007
970
|
<img src={recordState ? soundWavePng : luyinPng} style={{ width: 23 }} className={recordState ? "w_recordIng" : ''}></img>
|
|
1008
971
|
</div>
|
|
@@ -1013,16 +976,16 @@ export default function ChatWindow({
|
|
|
1013
976
|
isShowUploadButton &&
|
|
1014
977
|
<Tooltip title="支持图片格式">
|
|
1015
978
|
<div
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
979
|
+
className="w_send_file_box"
|
|
980
|
+
style={sendingMessage ? { cursor: 'not-allowed' } : {}}
|
|
981
|
+
onClick={uploadFile}
|
|
1019
982
|
>
|
|
1020
983
|
<img src={fileuploadPng} style={{ width: 23 }}></img>
|
|
1021
984
|
</div>
|
|
1022
985
|
</Tooltip>
|
|
1023
986
|
}
|
|
1024
987
|
<Tooltip title={sendingMessage?'点击暂停':'点击发送'}>
|
|
1025
|
-
|
|
988
|
+
<button
|
|
1026
989
|
style={{ ...(sendingMessage ? { cursor: 'pointer' } : {}), padding: '0 13px', background:'transparent', display:'flex', alignItems:'center', justifyContent:'center' }}
|
|
1027
990
|
onClick={() => {
|
|
1028
991
|
if(sendingMessage){
|
|
@@ -1041,13 +1004,80 @@ export default function ChatWindow({
|
|
|
1041
1004
|
handleSendMessage()
|
|
1042
1005
|
}
|
|
1043
1006
|
}}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
<img src={sendingMessage ? stopmessagePng : sendmessagePng} style={{width: 55}}/>
|
|
1007
|
+
>
|
|
1008
|
+
<img src={sendingMessage ? stopmessagePng : sendmessagePng} style={{width: 55}}/>
|
|
1047
1009
|
</button>
|
|
1048
1010
|
</Tooltip>
|
|
1049
1011
|
</div>
|
|
1050
1012
|
</div>
|
|
1013
|
+
</>
|
|
1014
|
+
)
|
|
1015
|
+
}
|
|
1016
|
+
return (
|
|
1017
|
+
<div
|
|
1018
|
+
style={{...chat_window_style, width: width, height: "100%"}}
|
|
1019
|
+
ref={ref}
|
|
1020
|
+
className="cl-window"
|
|
1021
|
+
>
|
|
1022
|
+
<div className="cl-middle-container">
|
|
1023
|
+
<div className="cl-header" style={isMobile ? {position: 'absolute', top: 20, left: 0, paddingLeft: '1.6rem', paddingRight: '1.6rem'} : {}}>
|
|
1024
|
+
{
|
|
1025
|
+
isShowChatHeader && (
|
|
1026
|
+
<div className="header-title">
|
|
1027
|
+
{
|
|
1028
|
+
isTitleSideIcon ?
|
|
1029
|
+
<img className="p_logoImg" style={{width: logoWidth, height: 'auto', marginRight: 10}}
|
|
1030
|
+
src={agentUrl}/> :
|
|
1031
|
+
<span className="diamond"/>
|
|
1032
|
+
}
|
|
1033
|
+
{window_title}
|
|
1034
|
+
</div>
|
|
1035
|
+
)
|
|
1036
|
+
}
|
|
1037
|
+
<div className="cl-header-subtitle"/>
|
|
1038
|
+
{renderTipsInfo()}
|
|
1039
|
+
</div>
|
|
1040
|
+
<div
|
|
1041
|
+
className="cl-messages_container"
|
|
1042
|
+
style={isMobile ? {paddingLeft: '0', paddingRight: '0'} :{}}
|
|
1043
|
+
// style={{ maxWidth: '100%', minHeight:'300px', height:'700px', paddingBottom: '56px' }}
|
|
1044
|
+
>
|
|
1045
|
+
{
|
|
1046
|
+
messages.map((message, index) => (
|
|
1047
|
+
<ChatMessage
|
|
1048
|
+
bot_message_style={bot_message_style}
|
|
1049
|
+
user_message_style={user_message_style}
|
|
1050
|
+
error_message_style={error_message_style}
|
|
1051
|
+
key={index}
|
|
1052
|
+
host_url={hostUrl}
|
|
1053
|
+
message={message}
|
|
1054
|
+
isSend={message.isSend}
|
|
1055
|
+
error={message.error}
|
|
1056
|
+
type={message.type}
|
|
1057
|
+
rawInfo={message.rawInfo}
|
|
1058
|
+
handleSendMessage={handleSendMessage}
|
|
1059
|
+
/>
|
|
1060
|
+
))
|
|
1061
|
+
}
|
|
1062
|
+
{
|
|
1063
|
+
sendingMessage && (nowAIContent ?
|
|
1064
|
+
<ChatMessage
|
|
1065
|
+
bot_message_style={bot_message_style}
|
|
1066
|
+
user_message_style={user_message_style}
|
|
1067
|
+
error_message_style={error_message_style}
|
|
1068
|
+
key={1688574569}
|
|
1069
|
+
host_url={hostUrl}
|
|
1070
|
+
message={{ message: nowAIContent}}
|
|
1071
|
+
isSend={false}
|
|
1072
|
+
handleSendMessage={handleSendMessage}
|
|
1073
|
+
/> : <ChatMessagePlaceholder bot_message_style={bot_message_style} />
|
|
1074
|
+
)
|
|
1075
|
+
}
|
|
1076
|
+
<div ref={lastMessage}></div>
|
|
1077
|
+
</div>
|
|
1078
|
+
{
|
|
1079
|
+
renderInputArea()
|
|
1080
|
+
}
|
|
1051
1081
|
</div>
|
|
1052
1082
|
</div>
|
|
1053
1083
|
);
|