@smartspace/chat-ui 1.14.4-pr.642.cfd098f → 1.14.4-pr.645.1250b79
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/index.js +31 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4290,6 +4290,8 @@ function useMessageComposerVm(props = {}) {
|
|
|
4290
4290
|
const isRunning = useThreadIsRunning(workspaceId, threadId);
|
|
4291
4291
|
const isUploadingFiles = props.isUploadingFiles ?? false;
|
|
4292
4292
|
const sendMessage = useSendMessage();
|
|
4293
|
+
const currentThreadId = useRef(threadId);
|
|
4294
|
+
currentThreadId.current = threadId;
|
|
4293
4295
|
const sendDisabled = useMemo(() => {
|
|
4294
4296
|
const nothingToSend = !newMessage.trim() && !props.hasAttachments;
|
|
4295
4297
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
@@ -4301,18 +4303,27 @@ function useMessageComposerVm(props = {}) {
|
|
|
4301
4303
|
newMessage,
|
|
4302
4304
|
props.hasAttachments
|
|
4303
4305
|
]);
|
|
4304
|
-
const internalSend = (text6, files) => {
|
|
4306
|
+
const internalSend = (text6, files, onFailed) => {
|
|
4305
4307
|
if (!workspaceId || !threadId) return;
|
|
4306
4308
|
const trimmed = text6.trim();
|
|
4307
4309
|
const contentList = trimmed ? [{ text: trimmed, image: void 0 }] : void 0;
|
|
4308
4310
|
const vars = variables && Object.keys(variables).length > 0 ? variables : void 0;
|
|
4309
|
-
sendMessage.mutate(
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4311
|
+
sendMessage.mutate(
|
|
4312
|
+
{
|
|
4313
|
+
workspaceId,
|
|
4314
|
+
threadId,
|
|
4315
|
+
contentList,
|
|
4316
|
+
files,
|
|
4317
|
+
variables: vars
|
|
4318
|
+
},
|
|
4319
|
+
// The composer stays mounted across threads: a send that fails after
|
|
4320
|
+
// the user moved to another thread must not put its text in that one.
|
|
4321
|
+
{
|
|
4322
|
+
onError: () => {
|
|
4323
|
+
if (currentThreadId.current === threadId) onFailed?.();
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
);
|
|
4316
4327
|
setNewMessage("");
|
|
4317
4328
|
};
|
|
4318
4329
|
const canSend = (text6, files) => {
|
|
@@ -4321,9 +4332,9 @@ function useMessageComposerVm(props = {}) {
|
|
|
4321
4332
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
4322
4333
|
return !(isUploadingFiles || flowBlocked || nothingToSend);
|
|
4323
4334
|
};
|
|
4324
|
-
const handleSendMessage = (text6, files) => {
|
|
4335
|
+
const handleSendMessage = (text6, files, onFailed) => {
|
|
4325
4336
|
if (!canSend(text6, files)) return false;
|
|
4326
|
-
internalSend(text6, files);
|
|
4337
|
+
internalSend(text6, files, onFailed);
|
|
4327
4338
|
return true;
|
|
4328
4339
|
};
|
|
4329
4340
|
return {
|
|
@@ -4607,7 +4618,16 @@ function MessageComposer(_props = {}) {
|
|
|
4607
4618
|
}, [editorKey]);
|
|
4608
4619
|
const handleSendMessageAndClear = () => {
|
|
4609
4620
|
const latestText = editorRef.current?.getMarkdown() ?? newMessage;
|
|
4610
|
-
const
|
|
4621
|
+
const restoreText = () => {
|
|
4622
|
+
if ((editorRef.current?.getMarkdown() ?? "").trim()) return;
|
|
4623
|
+
setNewMessage(latestText);
|
|
4624
|
+
setEditorKey((k) => k + 1);
|
|
4625
|
+
};
|
|
4626
|
+
const sent = handleSendMessage(
|
|
4627
|
+
latestText,
|
|
4628
|
+
uploadedAttachments,
|
|
4629
|
+
restoreText
|
|
4630
|
+
);
|
|
4611
4631
|
if (!sent) return;
|
|
4612
4632
|
stopDictation();
|
|
4613
4633
|
handleClearAttachments();
|