@ai-group/chat-sdk 3.6.11 → 3.7.0
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/dist/cjs/components/XAdkChatbot/index.js +27 -15
- package/dist/cjs/components/XAdkChatbot/index.js.map +2 -2
- package/dist/cjs/components/XAdkProvider/compound/Sender.d.ts +2 -2
- package/dist/cjs/components/XAdkProvider/compound/Sender.js +20 -17
- package/dist/cjs/components/XAdkProvider/compound/Sender.js.map +2 -2
- package/dist/cjs/components/XAdkProvider/compound/Sidebar.js +6 -2
- package/dist/cjs/components/XAdkProvider/compound/Sidebar.js.map +2 -2
- package/dist/cjs/components/XAdkProvider/context/ChatSenderStateContext.d.ts +6 -2
- package/dist/cjs/components/XAdkProvider/context/ChatSenderStateContext.js.map +2 -2
- package/dist/cjs/components/XAdkProvider/index.js +8 -5
- package/dist/cjs/components/XAdkProvider/index.js.map +2 -2
- package/dist/cjs/components/XAdkSender/index.js +502 -496
- package/dist/cjs/components/XAdkSender/index.js.map +2 -2
- package/dist/cjs/components/XAdkSender/styles.js +0 -13
- package/dist/cjs/components/XAdkSender/styles.js.map +2 -2
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.js +26 -0
- package/dist/cjs/core/index.js.map +7 -0
- package/dist/cjs/core/protocol/index.d.ts +3 -0
- package/dist/cjs/core/protocol/index.js +28 -0
- package/dist/cjs/core/protocol/index.js.map +7 -0
- package/dist/cjs/core/protocol/messages.d.ts +55 -0
- package/dist/cjs/core/protocol/messages.js +307 -0
- package/dist/cjs/core/protocol/messages.js.map +7 -0
- package/dist/cjs/core/protocol/parts.d.ts +24 -0
- package/dist/cjs/core/protocol/parts.js +106 -0
- package/dist/cjs/core/protocol/parts.js.map +7 -0
- package/dist/cjs/core/protocol/types.d.ts +57 -0
- package/dist/cjs/core/protocol/types.js +18 -0
- package/dist/cjs/core/protocol/types.js.map +7 -0
- package/dist/cjs/core/runtime/createAdkConversationController.d.ts +8 -0
- package/dist/cjs/core/runtime/createAdkConversationController.js +424 -0
- package/dist/cjs/core/runtime/createAdkConversationController.js.map +7 -0
- package/dist/cjs/core/runtime/index.d.ts +2 -0
- package/dist/cjs/core/runtime/index.js +26 -0
- package/dist/cjs/core/runtime/index.js.map +7 -0
- package/dist/cjs/core/runtime/types.d.ts +130 -0
- package/dist/cjs/core/runtime/types.js +18 -0
- package/dist/cjs/core/runtime/types.js.map +7 -0
- package/dist/{esm/utils/umdEntry.d.ts → cjs/entries/umd.d.ts} +7 -0
- package/dist/cjs/{utils/umdEntry.js → entries/umd.js} +19 -9
- package/dist/cjs/entries/umd.js.map +7 -0
- package/dist/cjs/hooks/useADKChat.js +1 -0
- package/dist/cjs/hooks/useADKChat.js.map +2 -2
- package/dist/cjs/index.d.ts +6 -1
- package/dist/cjs/index.js +19 -11
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/presets/xgroup/index.d.ts +4 -0
- package/dist/cjs/presets/xgroup/index.js +30 -0
- package/dist/cjs/presets/xgroup/index.js.map +7 -0
- package/dist/cjs/presets/xgroup/preset.d.ts +15 -0
- package/dist/cjs/presets/xgroup/preset.js +69 -0
- package/dist/cjs/presets/xgroup/preset.js.map +7 -0
- package/dist/cjs/presets/xgroup/strategies.d.ts +8 -0
- package/dist/cjs/presets/xgroup/strategies.js +53 -0
- package/dist/cjs/presets/xgroup/strategies.js.map +7 -0
- package/dist/cjs/presets/xgroup/transport.d.ts +15 -0
- package/dist/cjs/presets/xgroup/transport.js +183 -0
- package/dist/cjs/presets/xgroup/transport.js.map +7 -0
- package/dist/cjs/presets/xgroup/upload.d.ts +8 -0
- package/dist/cjs/presets/xgroup/upload.js +65 -0
- package/dist/cjs/presets/xgroup/upload.js.map +7 -0
- package/dist/cjs/react/index.d.ts +6 -0
- package/dist/cjs/react/index.js +53 -0
- package/dist/cjs/react/index.js.map +7 -0
- package/dist/cjs/react/useAdkConversation.d.ts +27 -0
- package/dist/cjs/react/useAdkConversation.js +69 -0
- package/dist/cjs/react/useAdkConversation.js.map +7 -0
- package/dist/cjs/types/XAdkSender.d.ts +0 -2
- package/dist/cjs/types/XAdkSender.js.map +1 -1
- package/dist/esm/components/XAdkChatbot/index.js +1 -1
- package/dist/esm/components/XAdkChatbot/index.js.map +1 -1
- package/dist/esm/components/XAdkProvider/compound/Sender.d.ts +2 -2
- package/dist/esm/components/XAdkProvider/compound/Sender.js +7 -4
- package/dist/esm/components/XAdkProvider/compound/Sender.js.map +1 -1
- package/dist/esm/components/XAdkProvider/compound/Sidebar.js +7 -2
- package/dist/esm/components/XAdkProvider/compound/Sidebar.js.map +1 -1
- package/dist/esm/components/XAdkProvider/context/ChatSenderStateContext.d.ts +6 -2
- package/dist/esm/components/XAdkProvider/context/ChatSenderStateContext.js.map +1 -1
- package/dist/esm/components/XAdkProvider/index.js +13 -4
- package/dist/esm/components/XAdkProvider/index.js.map +1 -1
- package/dist/esm/components/XAdkSender/index.js +2 -5
- package/dist/esm/components/XAdkSender/index.js.map +1 -1
- package/dist/esm/components/XAdkSender/styles.js +1 -1
- package/dist/esm/components/XAdkSender/styles.js.map +1 -1
- package/dist/esm/core/index.d.ts +2 -0
- package/dist/esm/core/index.js +3 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/protocol/index.d.ts +3 -0
- package/dist/esm/core/protocol/index.js +4 -0
- package/dist/esm/core/protocol/index.js.map +1 -0
- package/dist/esm/core/protocol/messages.d.ts +55 -0
- package/dist/esm/core/protocol/messages.js +315 -0
- package/dist/esm/core/protocol/messages.js.map +1 -0
- package/dist/esm/core/protocol/parts.d.ts +24 -0
- package/dist/esm/core/protocol/parts.js +100 -0
- package/dist/esm/core/protocol/parts.js.map +1 -0
- package/dist/esm/core/protocol/types.d.ts +57 -0
- package/dist/esm/core/protocol/types.js +2 -0
- package/dist/esm/core/protocol/types.js.map +1 -0
- package/dist/esm/core/runtime/createAdkConversationController.d.ts +8 -0
- package/dist/esm/core/runtime/createAdkConversationController.js +742 -0
- package/dist/esm/core/runtime/createAdkConversationController.js.map +1 -0
- package/dist/esm/core/runtime/index.d.ts +2 -0
- package/dist/esm/core/runtime/index.js +3 -0
- package/dist/esm/core/runtime/index.js.map +1 -0
- package/dist/esm/core/runtime/types.d.ts +130 -0
- package/dist/esm/core/runtime/types.js +2 -0
- package/dist/esm/core/runtime/types.js.map +1 -0
- package/dist/{cjs/utils/umdEntry.d.ts → esm/entries/umd.d.ts} +7 -0
- package/dist/esm/{utils/umdEntry.js → entries/umd.js} +10 -1
- package/dist/esm/entries/umd.js.map +1 -0
- package/dist/esm/hooks/useADKChat.js +2 -1
- package/dist/esm/hooks/useADKChat.js.map +1 -1
- package/dist/esm/index.d.ts +6 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/presets/xgroup/index.d.ts +4 -0
- package/dist/esm/presets/xgroup/index.js +5 -0
- package/dist/esm/presets/xgroup/index.js.map +1 -0
- package/dist/esm/presets/xgroup/preset.d.ts +15 -0
- package/dist/esm/presets/xgroup/preset.js +44 -0
- package/dist/esm/presets/xgroup/preset.js.map +1 -0
- package/dist/esm/presets/xgroup/strategies.d.ts +8 -0
- package/dist/esm/presets/xgroup/strategies.js +30 -0
- package/dist/esm/presets/xgroup/strategies.js.map +1 -0
- package/dist/esm/presets/xgroup/transport.d.ts +15 -0
- package/dist/esm/presets/xgroup/transport.js +322 -0
- package/dist/esm/presets/xgroup/transport.js.map +1 -0
- package/dist/esm/presets/xgroup/upload.d.ts +8 -0
- package/dist/esm/presets/{xGroupAdk.js → xgroup/upload.js} +9 -63
- package/dist/esm/presets/xgroup/upload.js.map +1 -0
- package/dist/esm/react/index.d.ts +6 -0
- package/dist/esm/react/index.js +5 -0
- package/dist/esm/react/index.js.map +1 -0
- package/dist/esm/react/useAdkConversation.d.ts +27 -0
- package/dist/esm/react/useAdkConversation.js +53 -0
- package/dist/esm/react/useAdkConversation.js.map +1 -0
- package/dist/esm/types/XAdkSender.d.ts +0 -2
- package/dist/esm/types/XAdkSender.js.map +1 -1
- package/dist/umd/chat-sdk.min.js +1 -1
- package/package.json +36 -2
- package/dist/cjs/presets/xGroupAdk.d.ts +0 -20
- package/dist/cjs/presets/xGroupAdk.js +0 -130
- package/dist/cjs/presets/xGroupAdk.js.map +0 -7
- package/dist/cjs/utils/umdEntry.js.map +0 -7
- package/dist/esm/presets/xGroupAdk.d.ts +0 -20
- package/dist/esm/presets/xGroupAdk.js.map +0 -1
- package/dist/esm/utils/umdEntry.js.map +0 -1
|
@@ -40,542 +40,548 @@ var import_FileGallery = __toESM(require("../FileGallery"));
|
|
|
40
40
|
var import_file = require("../../utils/file");
|
|
41
41
|
var import_Switch = __toESM(require("./Switch"));
|
|
42
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
-
var XAdkSender = (0, import_react.forwardRef)(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
onClear,
|
|
55
|
-
onChange,
|
|
56
|
-
onSubmit,
|
|
57
|
-
onStop,
|
|
58
|
-
onFilesChange,
|
|
59
|
-
onUploadSuccess,
|
|
60
|
-
onUploadError,
|
|
61
|
-
maxFileSize = 10,
|
|
62
|
-
validators: customValidators = [],
|
|
63
|
-
// allowedFileTypes = [
|
|
64
|
-
// "image/*",
|
|
65
|
-
// "audio/*",
|
|
66
|
-
// "video/*",
|
|
67
|
-
// "application/pdf",
|
|
68
|
-
// "text/plain",
|
|
69
|
-
// ".doc",
|
|
70
|
-
// ".docx",
|
|
71
|
-
// ".xls",
|
|
72
|
-
// ".xlsx",
|
|
73
|
-
// ".ppt",
|
|
74
|
-
// ".pptx",
|
|
75
|
-
// "",
|
|
76
|
-
// ],
|
|
77
|
-
allowedFileTypes = [],
|
|
78
|
-
maxFiles = Infinity,
|
|
79
|
-
sendButtonRender,
|
|
80
|
-
suffix,
|
|
81
|
-
header,
|
|
82
|
-
prefix,
|
|
83
|
-
footer
|
|
84
|
-
}, ref) => {
|
|
85
|
-
const styles = (0, import_styles.useStyles)();
|
|
86
|
-
const isControlled = controlledValue !== void 0;
|
|
87
|
-
const [internalValue, setInternalValue] = (0, import_react.useState)(defaultValue);
|
|
88
|
-
const value = isControlled ? controlledValue : internalValue;
|
|
89
|
-
const setValue = (newValue) => {
|
|
90
|
-
if (!isControlled) {
|
|
91
|
-
setInternalValue(newValue);
|
|
92
|
-
}
|
|
93
|
-
onChange == null ? void 0 : onChange(newValue);
|
|
94
|
-
};
|
|
95
|
-
const [files, setFiles] = (0, import_react.useState)([]);
|
|
96
|
-
const [isDragOver, setIsDragOver] = (0, import_react.useState)(false);
|
|
97
|
-
const containerRef = (0, import_react.useRef)(null);
|
|
98
|
-
const fileInputRef = (0, import_react.useRef)(null);
|
|
99
|
-
const generateId = () => {
|
|
100
|
-
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
101
|
-
};
|
|
102
|
-
const normalizeUploadResponse = (response) => {
|
|
103
|
-
const data = (response == null ? void 0 : response.data) ?? response;
|
|
104
|
-
return (Array.isArray(data) ? data[0] : data) ?? {};
|
|
105
|
-
};
|
|
106
|
-
const checkFileType = (file) => {
|
|
107
|
-
if ((allowedFileTypes == null ? void 0 : allowedFileTypes.length) > 0) {
|
|
108
|
-
const ext = (0, import_file.getExt)(file);
|
|
109
|
-
return allowedFileTypes.some((type) => {
|
|
110
|
-
if (type.includes("/")) {
|
|
111
|
-
if (type.endsWith("/*")) {
|
|
112
|
-
return file.type.startsWith(type.split("/")[0]);
|
|
113
|
-
}
|
|
114
|
-
return file.type === type;
|
|
115
|
-
}
|
|
116
|
-
if (type.startsWith(".")) {
|
|
117
|
-
return ext === type.slice(1);
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
123
|
-
};
|
|
124
|
-
const checkFileSize = (file) => {
|
|
125
|
-
const maxSize = maxFileSize * 1024 * 1024;
|
|
126
|
-
return file.size <= maxSize;
|
|
127
|
-
};
|
|
128
|
-
const isDuplicateFile = (file, files2) => {
|
|
129
|
-
return files2.some((f) => f.name === file.name && f.size === file.size);
|
|
130
|
-
};
|
|
131
|
-
const builtInValidators = [
|
|
132
|
-
// 数量校验(修复批量 bug)
|
|
133
|
-
(_file, { files: files2 }) => {
|
|
134
|
-
if (files2.length >= maxFiles) {
|
|
135
|
-
return `最多只能上传 ${maxFiles} 个文件`;
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
},
|
|
139
|
-
// 大小校验
|
|
140
|
-
(file) => {
|
|
141
|
-
const maxSize = maxFileSize * 1024 * 1024;
|
|
142
|
-
if (file.size > maxSize) {
|
|
143
|
-
return `文件大小不能超过 ${maxFileSize}MB`;
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
},
|
|
147
|
-
// 类型校验
|
|
148
|
-
(file) => {
|
|
149
|
-
if (!checkFileType(file)) {
|
|
150
|
-
return "不支持的文件类型";
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
43
|
+
var XAdkSender = (0, import_react.forwardRef)(
|
|
44
|
+
({
|
|
45
|
+
clearBtnShow = true,
|
|
46
|
+
allowUpload = false,
|
|
47
|
+
draggable = true,
|
|
48
|
+
loading = false,
|
|
49
|
+
disabled = false,
|
|
50
|
+
value: controlledValue,
|
|
51
|
+
defaultValue = "",
|
|
52
|
+
uploadRequest = () => {
|
|
153
53
|
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
54
|
+
onClear,
|
|
55
|
+
onChange,
|
|
56
|
+
onSubmit,
|
|
57
|
+
onStop,
|
|
58
|
+
onFilesChange,
|
|
59
|
+
onUploadSuccess,
|
|
60
|
+
onUploadError,
|
|
61
|
+
maxFileSize = 10,
|
|
62
|
+
validators: customValidators = [],
|
|
63
|
+
// allowedFileTypes = [
|
|
64
|
+
// "image/*",
|
|
65
|
+
// "audio/*",
|
|
66
|
+
// "video/*",
|
|
67
|
+
// "application/pdf",
|
|
68
|
+
// "text/plain",
|
|
69
|
+
// ".doc",
|
|
70
|
+
// ".docx",
|
|
71
|
+
// ".xls",
|
|
72
|
+
// ".xlsx",
|
|
73
|
+
// ".ppt",
|
|
74
|
+
// ".pptx",
|
|
75
|
+
// "",
|
|
76
|
+
// ],
|
|
77
|
+
allowedFileTypes = [],
|
|
78
|
+
maxFiles = Infinity,
|
|
79
|
+
sendButtonRender,
|
|
80
|
+
suffix,
|
|
81
|
+
header,
|
|
82
|
+
prefix,
|
|
83
|
+
footer
|
|
84
|
+
}, ref) => {
|
|
85
|
+
const styles = (0, import_styles.useStyles)();
|
|
86
|
+
const isControlled = controlledValue !== void 0;
|
|
87
|
+
const [internalValue, setInternalValue] = (0, import_react.useState)(defaultValue);
|
|
88
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
89
|
+
const setValue = (newValue) => {
|
|
90
|
+
if (!isControlled) {
|
|
91
|
+
setInternalValue(newValue);
|
|
158
92
|
}
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
93
|
+
onChange == null ? void 0 : onChange(newValue);
|
|
94
|
+
};
|
|
95
|
+
const [files, setFiles] = (0, import_react.useState)([]);
|
|
96
|
+
const [isDragOver, setIsDragOver] = (0, import_react.useState)(false);
|
|
97
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
98
|
+
const fileInputRef = (0, import_react.useRef)(null);
|
|
99
|
+
const generateId = () => {
|
|
100
|
+
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
101
|
+
};
|
|
102
|
+
const normalizeUploadResponse = (response) => {
|
|
103
|
+
const data = (response == null ? void 0 : response.data) ?? response;
|
|
104
|
+
return (Array.isArray(data) ? data[0] : data) ?? {};
|
|
105
|
+
};
|
|
106
|
+
const checkFileType = (file) => {
|
|
107
|
+
if ((allowedFileTypes == null ? void 0 : allowedFileTypes.length) > 0) {
|
|
108
|
+
const ext = (0, import_file.getExt)(file);
|
|
109
|
+
return allowedFileTypes.some((type) => {
|
|
110
|
+
if (type.includes("/")) {
|
|
111
|
+
if (type.endsWith("/*")) {
|
|
112
|
+
return file.type.startsWith(type.split("/")[0]);
|
|
113
|
+
}
|
|
114
|
+
return file.type === type;
|
|
115
|
+
}
|
|
116
|
+
if (type.startsWith(".")) {
|
|
117
|
+
return ext === type.slice(1);
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
});
|
|
168
121
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
const checkFileSize = (file) => {
|
|
125
|
+
const maxSize = maxFileSize * 1024 * 1024;
|
|
126
|
+
return file.size <= maxSize;
|
|
127
|
+
};
|
|
128
|
+
const isDuplicateFile = (file, files2) => {
|
|
129
|
+
return files2.some((f) => f.name === file.name && f.size === file.size);
|
|
130
|
+
};
|
|
131
|
+
const builtInValidators = [
|
|
132
|
+
// 数量校验(修复批量 bug)
|
|
133
|
+
(_file, { files: files2 }) => {
|
|
134
|
+
if (files2.length >= maxFiles) {
|
|
135
|
+
return `最多只能上传 ${maxFiles} 个文件`;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
},
|
|
139
|
+
// 大小校验
|
|
140
|
+
(file) => {
|
|
141
|
+
const maxSize = maxFileSize * 1024 * 1024;
|
|
142
|
+
if (file.size > maxSize) {
|
|
143
|
+
return `文件大小不能超过 ${maxFileSize}MB`;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
},
|
|
147
|
+
// 类型校验
|
|
148
|
+
(file) => {
|
|
149
|
+
if (!checkFileType(file)) {
|
|
150
|
+
return "不支持的文件类型";
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
},
|
|
154
|
+
// ⭐ 新增:去重校验
|
|
155
|
+
(file, { files: files2 }) => {
|
|
156
|
+
if (isDuplicateFile(file, files2)) {
|
|
157
|
+
return "文件已存在";
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
178
160
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
name: file.name,
|
|
187
|
-
size: file.size,
|
|
188
|
-
type: file.type,
|
|
189
|
-
file,
|
|
190
|
-
progress: 0,
|
|
191
|
-
status: "pending",
|
|
192
|
-
response: null
|
|
193
|
-
});
|
|
194
|
-
} else {
|
|
195
|
-
import_antd.message.error(validation.message);
|
|
161
|
+
];
|
|
162
|
+
const allValidators = [...builtInValidators, ...customValidators];
|
|
163
|
+
const validateFile = (file) => {
|
|
164
|
+
for (const validator of allValidators) {
|
|
165
|
+
const error = validator(file, { files });
|
|
166
|
+
if (error) {
|
|
167
|
+
return { valid: false, message: error };
|
|
196
168
|
}
|
|
197
|
-
});
|
|
198
|
-
if (validFiles.length > 0) {
|
|
199
|
-
setFiles((prev) => {
|
|
200
|
-
const next = [...prev, ...validFiles];
|
|
201
|
-
onFilesChange == null ? void 0 : onFilesChange(next);
|
|
202
|
-
return next;
|
|
203
|
-
});
|
|
204
|
-
uploadFiles(validFiles);
|
|
205
169
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
);
|
|
230
|
-
},
|
|
231
|
-
onSuccess: (response) => {
|
|
232
|
-
const responseData = normalizeUploadResponse(response);
|
|
233
|
-
setFiles(
|
|
234
|
-
(prev) => prev.map(
|
|
235
|
-
(f) => f.id === localFile.id ? {
|
|
236
|
-
...f,
|
|
237
|
-
status: "success",
|
|
238
|
-
progress: 100,
|
|
239
|
-
response,
|
|
240
|
-
fileId: responseData.fileId || responseData.id,
|
|
241
|
-
tempUrl: responseData.tempUrl || responseData.fileUrl || responseData.url
|
|
242
|
-
} : f
|
|
243
|
-
)
|
|
244
|
-
);
|
|
245
|
-
onUploadSuccess == null ? void 0 : onUploadSuccess({
|
|
246
|
-
...localFile,
|
|
247
|
-
status: "success",
|
|
248
|
-
response,
|
|
249
|
-
fileId: responseData.fileId || responseData.id,
|
|
250
|
-
tempUrl: responseData.tempUrl || responseData.fileUrl || responseData.url
|
|
170
|
+
return { valid: true };
|
|
171
|
+
};
|
|
172
|
+
const handleFileSelect = (0, import_react.useCallback)(
|
|
173
|
+
(selectedFiles) => {
|
|
174
|
+
const fileArray = Array.from(selectedFiles);
|
|
175
|
+
if (files.length + fileArray.length > maxFiles) {
|
|
176
|
+
import_antd.message.error(`最多只能上传 ${maxFiles} 个文件`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const validFiles = [];
|
|
180
|
+
fileArray.forEach((file) => {
|
|
181
|
+
const validation = validateFile(file);
|
|
182
|
+
if (validation.valid) {
|
|
183
|
+
validFiles.push({
|
|
184
|
+
id: generateId(),
|
|
185
|
+
uid: generateId(),
|
|
186
|
+
name: file.name,
|
|
187
|
+
size: file.size,
|
|
188
|
+
type: file.type,
|
|
189
|
+
file,
|
|
190
|
+
progress: 0,
|
|
191
|
+
status: "pending",
|
|
192
|
+
response: null
|
|
251
193
|
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
setFiles(
|
|
255
|
-
(prev) => prev.map(
|
|
256
|
-
(f) => f.id === localFile.id ? {
|
|
257
|
-
...f,
|
|
258
|
-
status: "error",
|
|
259
|
-
errorMessage: error.message
|
|
260
|
-
} : f
|
|
261
|
-
)
|
|
262
|
-
);
|
|
263
|
-
onUploadError == null ? void 0 : onUploadError(localFile, error);
|
|
194
|
+
} else {
|
|
195
|
+
import_antd.message.error(validation.message);
|
|
264
196
|
}
|
|
265
197
|
});
|
|
266
|
-
|
|
267
|
-
|
|
198
|
+
if (validFiles.length > 0) {
|
|
199
|
+
setFiles((prev) => {
|
|
200
|
+
const next = [...prev, ...validFiles];
|
|
201
|
+
onFilesChange == null ? void 0 : onFilesChange(next);
|
|
202
|
+
return next;
|
|
203
|
+
});
|
|
204
|
+
uploadFiles(validFiles);
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
[files, maxFiles, maxFileSize, allowedFileTypes]
|
|
208
|
+
);
|
|
209
|
+
(0, import_react.useImperativeHandle)(
|
|
210
|
+
ref,
|
|
211
|
+
() => ({
|
|
212
|
+
addFiles: (rawFiles) => {
|
|
213
|
+
handleFileSelect(rawFiles);
|
|
214
|
+
}
|
|
215
|
+
}),
|
|
216
|
+
[handleFileSelect]
|
|
217
|
+
);
|
|
218
|
+
const uploadFiles = async (fileList) => {
|
|
219
|
+
for (const localFile of fileList) {
|
|
268
220
|
setFiles(
|
|
269
221
|
(prev) => prev.map(
|
|
270
|
-
(f) => f.id === localFile.id ? {
|
|
271
|
-
...f,
|
|
272
|
-
status: "error",
|
|
273
|
-
errorMessage: error instanceof Error ? error.message : "上传处理失败"
|
|
274
|
-
} : f
|
|
222
|
+
(f) => f.id === localFile.id ? { ...f, status: "uploading" } : f
|
|
275
223
|
)
|
|
276
224
|
);
|
|
277
|
-
|
|
225
|
+
try {
|
|
226
|
+
await uploadRequest({
|
|
227
|
+
file: localFile.file,
|
|
228
|
+
onProgress: (e) => {
|
|
229
|
+
setFiles(
|
|
230
|
+
(prev) => prev.map(
|
|
231
|
+
(f) => f.id === localFile.id ? { ...f, progress: e.percent } : f
|
|
232
|
+
)
|
|
233
|
+
);
|
|
234
|
+
},
|
|
235
|
+
onSuccess: (response) => {
|
|
236
|
+
const responseData = normalizeUploadResponse(response);
|
|
237
|
+
setFiles(
|
|
238
|
+
(prev) => prev.map(
|
|
239
|
+
(f) => f.id === localFile.id ? {
|
|
240
|
+
...f,
|
|
241
|
+
status: "success",
|
|
242
|
+
progress: 100,
|
|
243
|
+
response,
|
|
244
|
+
fileId: responseData.fileId || responseData.id,
|
|
245
|
+
tempUrl: responseData.tempUrl || responseData.fileUrl || responseData.url
|
|
246
|
+
} : f
|
|
247
|
+
)
|
|
248
|
+
);
|
|
249
|
+
onUploadSuccess == null ? void 0 : onUploadSuccess({
|
|
250
|
+
...localFile,
|
|
251
|
+
status: "success",
|
|
252
|
+
response,
|
|
253
|
+
fileId: responseData.fileId || responseData.id,
|
|
254
|
+
tempUrl: responseData.tempUrl || responseData.fileUrl || responseData.url
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
onError: (error) => {
|
|
258
|
+
setFiles(
|
|
259
|
+
(prev) => prev.map(
|
|
260
|
+
(f) => f.id === localFile.id ? {
|
|
261
|
+
...f,
|
|
262
|
+
status: "error",
|
|
263
|
+
errorMessage: error.message
|
|
264
|
+
} : f
|
|
265
|
+
)
|
|
266
|
+
);
|
|
267
|
+
onUploadError == null ? void 0 : onUploadError(localFile, error);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
} catch (error) {
|
|
271
|
+
console.error("上传处理错误:", error);
|
|
272
|
+
setFiles(
|
|
273
|
+
(prev) => prev.map(
|
|
274
|
+
(f) => f.id === localFile.id ? {
|
|
275
|
+
...f,
|
|
276
|
+
status: "error",
|
|
277
|
+
errorMessage: error instanceof Error ? error.message : "上传处理失败"
|
|
278
|
+
} : f
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
import_antd.message.error(`${localFile.name} 上传失败`);
|
|
282
|
+
}
|
|
278
283
|
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
fileInputRef.current.click();
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
const handleDragOver = (0, import_react.useCallback)(
|
|
294
|
-
(e) => {
|
|
295
|
-
e.preventDefault();
|
|
296
|
-
e.stopPropagation();
|
|
297
|
-
if (allowUpload) {
|
|
298
|
-
setIsDragOver(true);
|
|
284
|
+
};
|
|
285
|
+
const handleRemoveFile = (id) => {
|
|
286
|
+
setFiles((prev) => {
|
|
287
|
+
const next = prev.filter((file) => file.id !== id);
|
|
288
|
+
onFilesChange == null ? void 0 : onFilesChange(next);
|
|
289
|
+
return next;
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
const triggerFileSelect = () => {
|
|
293
|
+
if (fileInputRef.current) {
|
|
294
|
+
fileInputRef.current.click();
|
|
299
295
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
296
|
+
};
|
|
297
|
+
const handleDragOver = (0, import_react.useCallback)(
|
|
298
|
+
(e) => {
|
|
299
|
+
e.preventDefault();
|
|
300
|
+
e.stopPropagation();
|
|
301
|
+
if (allowUpload) {
|
|
302
|
+
setIsDragOver(true);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
[allowUpload]
|
|
306
|
+
);
|
|
307
|
+
const handleDragLeave = (0, import_react.useCallback)(
|
|
308
|
+
(e) => {
|
|
309
|
+
e.preventDefault();
|
|
310
|
+
e.stopPropagation();
|
|
311
|
+
if (allowUpload) {
|
|
312
|
+
setIsDragOver(false);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
[allowUpload]
|
|
316
|
+
);
|
|
317
|
+
const handleDrop = (0, import_react.useCallback)(
|
|
318
|
+
(e) => {
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
e.stopPropagation();
|
|
308
321
|
setIsDragOver(false);
|
|
322
|
+
if (allowUpload && e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
323
|
+
handleFileSelect(Array.from(e.dataTransfer.files));
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
[allowUpload, handleFileSelect]
|
|
327
|
+
);
|
|
328
|
+
const handleSubmit = () => {
|
|
329
|
+
if (!value.trim() && files.length === 0) {
|
|
330
|
+
import_antd.message.warning("请输入消息或选择文件");
|
|
331
|
+
return;
|
|
309
332
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
title: "文件上传中",
|
|
334
|
-
content: `还有 ${uploadingFiles.length} 个文件正在上传,是否继续发送?`,
|
|
335
|
-
okText: "发送已完成的",
|
|
336
|
-
cancelText: "等待全部完成",
|
|
337
|
-
onOk: () => {
|
|
338
|
-
const formattedFiles = formatFilesForServer(successFiles);
|
|
339
|
-
if (onSubmit) {
|
|
340
|
-
onSubmit({
|
|
341
|
-
text: value,
|
|
342
|
-
files: formattedFiles
|
|
343
|
-
});
|
|
333
|
+
const successFiles = files.filter((file) => file.status === "success");
|
|
334
|
+
const uploadingFiles = files.filter(
|
|
335
|
+
(file) => file.status === "uploading"
|
|
336
|
+
);
|
|
337
|
+
if (uploadingFiles.length > 0) {
|
|
338
|
+
import_antd.Modal.confirm({
|
|
339
|
+
title: "文件上传中",
|
|
340
|
+
content: `还有 ${uploadingFiles.length} 个文件正在上传,是否继续发送?`,
|
|
341
|
+
okText: "发送已完成的",
|
|
342
|
+
cancelText: "等待全部完成",
|
|
343
|
+
onOk: () => {
|
|
344
|
+
const formattedFiles = formatFilesForServer(successFiles);
|
|
345
|
+
if (onSubmit) {
|
|
346
|
+
onSubmit({
|
|
347
|
+
text: value,
|
|
348
|
+
files: formattedFiles
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
setValue("");
|
|
352
|
+
setFiles((prev) => prev.filter((f) => f.status !== "success"));
|
|
353
|
+
},
|
|
354
|
+
onCancel: () => {
|
|
355
|
+
import_antd.message.info("请等待文件上传完成后再发送");
|
|
344
356
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
357
|
+
});
|
|
358
|
+
} else {
|
|
359
|
+
const formattedFiles = formatFilesForServer(successFiles);
|
|
360
|
+
if (onSubmit) {
|
|
361
|
+
onSubmit({
|
|
362
|
+
text: value,
|
|
363
|
+
files: formattedFiles
|
|
364
|
+
});
|
|
350
365
|
}
|
|
366
|
+
setValue("");
|
|
367
|
+
setFiles((prev) => prev.filter((f) => f.status !== "success"));
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
const formatFilesForServer = (fileList) => {
|
|
371
|
+
return fileList.filter((file) => file.status === "success" && file.response).map((file) => {
|
|
372
|
+
const responseData = normalizeUploadResponse(file.response);
|
|
373
|
+
return {
|
|
374
|
+
fileName: responseData.fileName || file.name,
|
|
375
|
+
fileId: responseData.fileId || responseData.id || "",
|
|
376
|
+
tempUrl: responseData.tempUrl || responseData.fileUrl || responseData.url || "",
|
|
377
|
+
type: responseData.fileType || responseData.type || (0, import_file.getExt)(file),
|
|
378
|
+
size: responseData.fileSize || responseData.size || file.size,
|
|
379
|
+
mimeType: responseData.mimeType || file.type,
|
|
380
|
+
raw: {
|
|
381
|
+
...responseData
|
|
382
|
+
}
|
|
383
|
+
};
|
|
351
384
|
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
385
|
+
};
|
|
386
|
+
const handleInputChange = (e) => {
|
|
387
|
+
const newValue = e.target.value;
|
|
388
|
+
setValue(newValue);
|
|
389
|
+
};
|
|
390
|
+
const handleKeyDown = (e) => {
|
|
391
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
392
|
+
e.preventDefault();
|
|
393
|
+
handleSubmit();
|
|
359
394
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
size: responseData.fileSize || responseData.size || file.size,
|
|
373
|
-
mimeType: responseData.mimeType || file.type,
|
|
374
|
-
raw: {
|
|
375
|
-
...responseData
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
});
|
|
379
|
-
};
|
|
380
|
-
const handleInputChange = (e) => {
|
|
381
|
-
const newValue = e.target.value;
|
|
382
|
-
setValue(newValue);
|
|
383
|
-
};
|
|
384
|
-
const handleKeyDown = (e) => {
|
|
385
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
386
|
-
e.preventDefault();
|
|
387
|
-
handleSubmit();
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
const renderFileList = () => {
|
|
391
|
-
if (files.length === 0)
|
|
392
|
-
return null;
|
|
393
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
394
|
-
"div",
|
|
395
|
-
{
|
|
396
|
-
style: {
|
|
397
|
-
display: "flex",
|
|
398
|
-
flexWrap: "wrap",
|
|
399
|
-
gap: "8px",
|
|
400
|
-
padding: "12px 0"
|
|
401
|
-
},
|
|
402
|
-
children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
403
|
-
import_FileGallery.default,
|
|
404
|
-
{
|
|
405
|
-
file,
|
|
406
|
-
type: "file",
|
|
407
|
-
removable: true,
|
|
408
|
-
onRemove: handleRemoveFile
|
|
395
|
+
};
|
|
396
|
+
const renderFileList = () => {
|
|
397
|
+
if (files.length === 0)
|
|
398
|
+
return null;
|
|
399
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
400
|
+
"div",
|
|
401
|
+
{
|
|
402
|
+
style: {
|
|
403
|
+
display: "flex",
|
|
404
|
+
flexWrap: "wrap",
|
|
405
|
+
gap: "8px",
|
|
406
|
+
padding: "12px 0"
|
|
409
407
|
},
|
|
410
|
-
file.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
...props,
|
|
439
|
-
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.LoadingOutlined, { spin: true }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ArrowUpOutlined, {})
|
|
408
|
+
children: files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
409
|
+
import_FileGallery.default,
|
|
410
|
+
{
|
|
411
|
+
file,
|
|
412
|
+
type: "file",
|
|
413
|
+
removable: true,
|
|
414
|
+
onRemove: handleRemoveFile
|
|
415
|
+
},
|
|
416
|
+
file.id
|
|
417
|
+
))
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
};
|
|
421
|
+
const containerClass = `${styles.container} ${isDragOver ? "drag-over" : ""}`;
|
|
422
|
+
const uploading = files.some((f) => f.status === "uploading");
|
|
423
|
+
const isDisabled = disabled || uploading || loading;
|
|
424
|
+
const hasContent = value.trim().length > 0;
|
|
425
|
+
const hasFiles = files.some((f) => f.status === "success");
|
|
426
|
+
const canSend = hasContent || hasFiles;
|
|
427
|
+
const SendButton = (props) => {
|
|
428
|
+
if (sendButtonRender) {
|
|
429
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: sendButtonRender({
|
|
430
|
+
loading,
|
|
431
|
+
disabled: uploading || disabled,
|
|
432
|
+
canSend,
|
|
433
|
+
onSend: handleSubmit,
|
|
434
|
+
onStop
|
|
435
|
+
}) });
|
|
440
436
|
}
|
|
441
|
-
|
|
442
|
-
};
|
|
443
|
-
const UploadButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: "上传文件", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
444
|
-
"button",
|
|
445
|
-
{
|
|
446
|
-
className: `${styles.iconButton} ${styles.uploadButton}`,
|
|
447
|
-
onClick: triggerFileSelect,
|
|
448
|
-
disabled: isDisabled,
|
|
449
|
-
"aria-label": "上传文件",
|
|
450
|
-
...props,
|
|
451
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PaperClipOutlined, {})
|
|
452
|
-
}
|
|
453
|
-
) });
|
|
454
|
-
const ClearButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
455
|
-
import_antd.Popconfirm,
|
|
456
|
-
{
|
|
457
|
-
title: "确定要清空聊天记录吗?",
|
|
458
|
-
onConfirm: onClear,
|
|
459
|
-
placement: "top",
|
|
460
|
-
okText: "确定",
|
|
461
|
-
cancelText: "取消",
|
|
462
|
-
disabled: isDisabled,
|
|
463
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: loading ? "停止生成" : "发送消息", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
464
438
|
"button",
|
|
465
439
|
{
|
|
466
|
-
className: `${styles.iconButton} ${styles.
|
|
467
|
-
|
|
468
|
-
|
|
440
|
+
className: `${styles.iconButton} ${styles.sendButton} ${loading ? "stop" : ""}`,
|
|
441
|
+
onClick: loading ? onStop : handleSubmit,
|
|
442
|
+
disabled: uploading || disabled,
|
|
443
|
+
"aria-label": loading ? "停止生成" : "发送消息",
|
|
469
444
|
...props,
|
|
470
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.
|
|
445
|
+
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.LoadingOutlined, { spin: true }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ArrowUpOutlined, {})
|
|
471
446
|
}
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
const actionsComponents = {
|
|
476
|
-
SendButton,
|
|
477
|
-
UploadButton,
|
|
478
|
-
ClearButton
|
|
479
|
-
};
|
|
480
|
-
const renderSlot = (slot, oriNode) => {
|
|
481
|
-
if (slot === false)
|
|
482
|
-
return null;
|
|
483
|
-
if (slot === void 0)
|
|
484
|
-
return oriNode;
|
|
485
|
-
if (typeof slot === "function") {
|
|
486
|
-
const result = slot(oriNode, { components: actionsComponents });
|
|
487
|
-
return result === false ? null : result;
|
|
488
|
-
}
|
|
489
|
-
return slot;
|
|
490
|
-
};
|
|
491
|
-
const defaultSuffix = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.buttonGroup, children: [
|
|
492
|
-
allowUpload && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: "上传文件", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
447
|
+
) });
|
|
448
|
+
};
|
|
449
|
+
const UploadButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: "上传文件", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
493
450
|
"button",
|
|
494
451
|
{
|
|
495
452
|
className: `${styles.iconButton} ${styles.uploadButton}`,
|
|
496
453
|
onClick: triggerFileSelect,
|
|
497
454
|
disabled: isDisabled,
|
|
498
455
|
"aria-label": "上传文件",
|
|
456
|
+
...props,
|
|
499
457
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PaperClipOutlined, {})
|
|
500
458
|
}
|
|
501
|
-
) })
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
disabled: uploading || disabled,
|
|
505
|
-
canSend,
|
|
506
|
-
onSend: handleSubmit,
|
|
507
|
-
onStop
|
|
508
|
-
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: loading ? "停止生成" : "发送消息", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
509
|
-
"button",
|
|
459
|
+
) });
|
|
460
|
+
const ClearButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
461
|
+
import_antd.Popconfirm,
|
|
510
462
|
{
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
520
|
-
"div",
|
|
521
|
-
{
|
|
522
|
-
ref: containerRef,
|
|
523
|
-
className: containerClass,
|
|
524
|
-
onDragOver: allowUpload && draggable ? handleDragOver : void 0,
|
|
525
|
-
onDragLeave: allowUpload && draggable ? handleDragLeave : void 0,
|
|
526
|
-
onDrop: allowUpload && draggable ? handleDrop : void 0,
|
|
527
|
-
children: [
|
|
528
|
-
renderSlot(header, false),
|
|
529
|
-
allowUpload && files.length > 0 && renderFileList(),
|
|
530
|
-
allowUpload && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
531
|
-
"input",
|
|
463
|
+
title: "确定要清空聊天记录吗?",
|
|
464
|
+
onConfirm: onClear,
|
|
465
|
+
placement: "top",
|
|
466
|
+
okText: "确定",
|
|
467
|
+
cancelText: "取消",
|
|
468
|
+
disabled: isDisabled,
|
|
469
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
470
|
+
"button",
|
|
532
471
|
{
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
onChange: (e) => {
|
|
539
|
-
if (e.target.files) {
|
|
540
|
-
handleFileSelect(Array.from(e.target.files));
|
|
541
|
-
e.target.value = "";
|
|
542
|
-
}
|
|
543
|
-
}
|
|
472
|
+
className: `${styles.iconButton} ${styles.clearButton}`,
|
|
473
|
+
disabled: isDisabled,
|
|
474
|
+
"aria-label": "清空聊天记录",
|
|
475
|
+
...props,
|
|
476
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ClearOutlined, {})
|
|
544
477
|
}
|
|
545
|
-
)
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
const actionsComponents = {
|
|
482
|
+
SendButton,
|
|
483
|
+
UploadButton,
|
|
484
|
+
ClearButton
|
|
485
|
+
};
|
|
486
|
+
const renderSlot = (slot, oriNode) => {
|
|
487
|
+
if (slot === false)
|
|
488
|
+
return null;
|
|
489
|
+
if (slot === void 0)
|
|
490
|
+
return oriNode;
|
|
491
|
+
if (typeof slot === "function") {
|
|
492
|
+
const result = slot(oriNode, { components: actionsComponents });
|
|
493
|
+
return result === false ? null : result;
|
|
494
|
+
}
|
|
495
|
+
return slot;
|
|
496
|
+
};
|
|
497
|
+
const defaultSuffix = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.buttonGroup, children: [
|
|
498
|
+
allowUpload && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: "上传文件", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
499
|
+
"button",
|
|
500
|
+
{
|
|
501
|
+
className: `${styles.iconButton} ${styles.uploadButton}`,
|
|
502
|
+
onClick: triggerFileSelect,
|
|
503
|
+
disabled: isDisabled,
|
|
504
|
+
"aria-label": "上传文件",
|
|
505
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.PaperClipOutlined, {})
|
|
506
|
+
}
|
|
507
|
+
) }),
|
|
508
|
+
sendButtonRender ? sendButtonRender({
|
|
509
|
+
loading,
|
|
510
|
+
disabled: uploading || disabled,
|
|
511
|
+
canSend,
|
|
512
|
+
onSend: handleSubmit,
|
|
513
|
+
onStop
|
|
514
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.Tooltip, { title: loading ? "停止生成" : "发送消息", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
515
|
+
"button",
|
|
516
|
+
{
|
|
517
|
+
className: `${styles.iconButton} ${styles.sendButton} ${loading ? "stop" : ""}`,
|
|
518
|
+
onClick: loading ? onStop : handleSubmit,
|
|
519
|
+
disabled: uploading || disabled,
|
|
520
|
+
"aria-label": loading ? "停止生成" : "发送消息",
|
|
521
|
+
children: loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.LoadingOutlined, { spin: true }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ArrowUpOutlined, {})
|
|
522
|
+
}
|
|
523
|
+
) })
|
|
524
|
+
] });
|
|
525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
526
|
+
"div",
|
|
527
|
+
{
|
|
528
|
+
ref: containerRef,
|
|
529
|
+
className: containerClass,
|
|
530
|
+
onDragOver: allowUpload && draggable ? handleDragOver : void 0,
|
|
531
|
+
onDragLeave: allowUpload && draggable ? handleDragLeave : void 0,
|
|
532
|
+
onDrop: allowUpload && draggable ? handleDrop : void 0,
|
|
533
|
+
children: [
|
|
534
|
+
renderSlot(header, false),
|
|
535
|
+
allowUpload && files.length > 0 && renderFileList(),
|
|
536
|
+
allowUpload && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
537
|
+
"input",
|
|
538
|
+
{
|
|
539
|
+
ref: fileInputRef,
|
|
540
|
+
type: "file",
|
|
541
|
+
multiple: true,
|
|
542
|
+
accept: allowedFileTypes.join(","),
|
|
543
|
+
style: { display: "none" },
|
|
544
|
+
onChange: (e) => {
|
|
545
|
+
if (e.target.files) {
|
|
546
|
+
handleFileSelect(Array.from(e.target.files));
|
|
547
|
+
e.target.value = "";
|
|
565
548
|
}
|
|
566
549
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
550
|
+
}
|
|
551
|
+
),
|
|
552
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.mainArea, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.senderWrap, children: [
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: styles.inputAndButtons, children: [
|
|
554
|
+
clearBtnShow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClearButton, {}),
|
|
555
|
+
renderSlot(prefix, false),
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.textAreaWrapper, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
557
|
+
import_antd.Input.TextArea,
|
|
558
|
+
{
|
|
559
|
+
className: styles.textArea,
|
|
560
|
+
value,
|
|
561
|
+
onChange: handleInputChange,
|
|
562
|
+
onKeyDown: handleKeyDown,
|
|
563
|
+
placeholder: "请输入消息...",
|
|
564
|
+
autoSize: { minRows: 1, maxRows: 4 },
|
|
565
|
+
style: {
|
|
566
|
+
border: "none",
|
|
567
|
+
boxShadow: "none",
|
|
568
|
+
outline: "none",
|
|
569
|
+
padding: 0
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
) }),
|
|
573
|
+
renderSlot(suffix, defaultSuffix)
|
|
574
|
+
] }),
|
|
575
|
+
renderSlot(
|
|
576
|
+
footer,
|
|
577
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: styles.tip, children: "内容由AI生成,无法确保真实准确,仅供参考" })
|
|
578
|
+
)
|
|
579
|
+
] }) })
|
|
580
|
+
]
|
|
581
|
+
}
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
);
|
|
579
585
|
XAdkSender.displayName = "XAdkSender";
|
|
580
586
|
var CompoundSender = XAdkSender;
|
|
581
587
|
CompoundSender.Switch = import_Switch.default;
|