@smartspace/chat-ui 1.14.4-dev.c351d13 → 1.14.4-dev.cbcaafb
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 +98 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47,15 +47,15 @@ import vertexaiIcon from '@lobehub/icons-static-svg/icons/vertexai-color.svg';
|
|
|
47
47
|
import xaiIcon from '@lobehub/icons-static-svg/icons/xai.svg';
|
|
48
48
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
49
49
|
import ReactMarkdown, { defaultUrlTransform } from 'react-markdown';
|
|
50
|
-
import
|
|
50
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
51
|
+
import { cva } from 'class-variance-authority';
|
|
51
52
|
import { clsx } from 'clsx';
|
|
52
53
|
import { twMerge } from 'tailwind-merge';
|
|
54
|
+
import MuiSkeleton from '@mui/material/Skeleton';
|
|
53
55
|
import dayjs from 'dayjs';
|
|
54
56
|
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
55
57
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
56
58
|
import utc from 'dayjs/plugin/utc';
|
|
57
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
58
|
-
import { cva } from 'class-variance-authority';
|
|
59
59
|
import { useTheme, Box, Skeleton as Skeleton$1 } from '@mui/material';
|
|
60
60
|
|
|
61
61
|
var __defProp = Object.defineProperty;
|
|
@@ -540,7 +540,10 @@ var threadDetailOptions = ({
|
|
|
540
540
|
queryKey: threadsKeys.detail(workspaceId, threadId),
|
|
541
541
|
queryFn: () => service.fetchThread(workspaceId, threadId),
|
|
542
542
|
refetchOnWindowFocus: false,
|
|
543
|
-
staleTime: 6e4
|
|
543
|
+
staleTime: 6e4,
|
|
544
|
+
// The route loader has just tried and failed. Retrying on mount delays
|
|
545
|
+
// the inline error by several seconds; the user has Try again.
|
|
546
|
+
retryOnMount: false
|
|
544
547
|
});
|
|
545
548
|
function getThreadPlaceholderFromListCache(queryClient, workspaceId, threadId) {
|
|
546
549
|
const entries = queryClient.getQueriesData({
|
|
@@ -4236,7 +4239,10 @@ var workspaceDetailOptions = ({
|
|
|
4236
4239
|
}) => queryOptions({
|
|
4237
4240
|
queryKey: workspaceKeys.byId(workspaceId),
|
|
4238
4241
|
queryFn: () => service.fetchWorkspace(workspaceId),
|
|
4239
|
-
staleTime: 3e4
|
|
4242
|
+
staleTime: 3e4,
|
|
4243
|
+
// The route loader has just tried and failed. Retrying on mount delays
|
|
4244
|
+
// the header's error by several seconds.
|
|
4245
|
+
retryOnMount: false
|
|
4240
4246
|
});
|
|
4241
4247
|
function useWorkspace(workspaceId) {
|
|
4242
4248
|
const service = useChatService();
|
|
@@ -4284,6 +4290,8 @@ function useMessageComposerVm(props = {}) {
|
|
|
4284
4290
|
const isRunning = useThreadIsRunning(workspaceId, threadId);
|
|
4285
4291
|
const isUploadingFiles = props.isUploadingFiles ?? false;
|
|
4286
4292
|
const sendMessage = useSendMessage();
|
|
4293
|
+
const currentThreadId = useRef(threadId);
|
|
4294
|
+
currentThreadId.current = threadId;
|
|
4287
4295
|
const sendDisabled = useMemo(() => {
|
|
4288
4296
|
const nothingToSend = !newMessage.trim() && !props.hasAttachments;
|
|
4289
4297
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
@@ -4295,18 +4303,27 @@ function useMessageComposerVm(props = {}) {
|
|
|
4295
4303
|
newMessage,
|
|
4296
4304
|
props.hasAttachments
|
|
4297
4305
|
]);
|
|
4298
|
-
const internalSend = (text6, files) => {
|
|
4306
|
+
const internalSend = (text6, files, onFailed) => {
|
|
4299
4307
|
if (!workspaceId || !threadId) return;
|
|
4300
4308
|
const trimmed = text6.trim();
|
|
4301
4309
|
const contentList = trimmed ? [{ text: trimmed, image: void 0 }] : void 0;
|
|
4302
4310
|
const vars = variables && Object.keys(variables).length > 0 ? variables : void 0;
|
|
4303
|
-
sendMessage.mutate(
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
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
|
+
);
|
|
4310
4327
|
setNewMessage("");
|
|
4311
4328
|
};
|
|
4312
4329
|
const canSend = (text6, files) => {
|
|
@@ -4315,9 +4332,9 @@ function useMessageComposerVm(props = {}) {
|
|
|
4315
4332
|
const flowBlocked = isRunning || sendMessage.isPending;
|
|
4316
4333
|
return !(isUploadingFiles || flowBlocked || nothingToSend);
|
|
4317
4334
|
};
|
|
4318
|
-
const handleSendMessage = (text6, files) => {
|
|
4335
|
+
const handleSendMessage = (text6, files, onFailed) => {
|
|
4319
4336
|
if (!canSend(text6, files)) return false;
|
|
4320
|
-
internalSend(text6, files);
|
|
4337
|
+
internalSend(text6, files, onFailed);
|
|
4321
4338
|
return true;
|
|
4322
4339
|
};
|
|
4323
4340
|
return {
|
|
@@ -4601,7 +4618,16 @@ function MessageComposer(_props = {}) {
|
|
|
4601
4618
|
}, [editorKey]);
|
|
4602
4619
|
const handleSendMessageAndClear = () => {
|
|
4603
4620
|
const latestText = editorRef.current?.getMarkdown() ?? newMessage;
|
|
4604
|
-
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
|
+
);
|
|
4605
4631
|
if (!sent) return;
|
|
4606
4632
|
stopDictation();
|
|
4607
4633
|
handleClearAttachments();
|
|
@@ -19583,6 +19609,45 @@ function MessageMarkdown({ value, className }) {
|
|
|
19583
19609
|
function cn(...inputs) {
|
|
19584
19610
|
return twMerge(clsx(inputs));
|
|
19585
19611
|
}
|
|
19612
|
+
var buttonVariants = cva(
|
|
19613
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
19614
|
+
{
|
|
19615
|
+
variants: {
|
|
19616
|
+
variant: {
|
|
19617
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
19618
|
+
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
19619
|
+
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
19620
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19621
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
19622
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
19623
|
+
},
|
|
19624
|
+
size: {
|
|
19625
|
+
default: "h-10 px-4 py-2",
|
|
19626
|
+
sm: "h-9 rounded-md px-3",
|
|
19627
|
+
lg: "h-11 rounded-md px-8",
|
|
19628
|
+
icon: "h-10 w-10"
|
|
19629
|
+
}
|
|
19630
|
+
},
|
|
19631
|
+
defaultVariants: {
|
|
19632
|
+
variant: "default",
|
|
19633
|
+
size: "default"
|
|
19634
|
+
}
|
|
19635
|
+
}
|
|
19636
|
+
);
|
|
19637
|
+
var Button = React9.forwardRef(
|
|
19638
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
19639
|
+
const Comp = asChild ? Slot : "button";
|
|
19640
|
+
return /* @__PURE__ */ jsx(
|
|
19641
|
+
Comp,
|
|
19642
|
+
{
|
|
19643
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
19644
|
+
ref,
|
|
19645
|
+
...props
|
|
19646
|
+
}
|
|
19647
|
+
);
|
|
19648
|
+
}
|
|
19649
|
+
);
|
|
19650
|
+
Button.displayName = "Button";
|
|
19586
19651
|
function Skeleton({ className, ...props }) {
|
|
19587
19652
|
return /* @__PURE__ */ jsx(
|
|
19588
19653
|
MuiSkeleton,
|
|
@@ -19872,45 +19937,6 @@ function parseDateTime(date, customFormat) {
|
|
|
19872
19937
|
function parseDateTimeHuman(date) {
|
|
19873
19938
|
return dayjs.utc(date).local().fromNow();
|
|
19874
19939
|
}
|
|
19875
|
-
var buttonVariants = cva(
|
|
19876
|
-
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
19877
|
-
{
|
|
19878
|
-
variants: {
|
|
19879
|
-
variant: {
|
|
19880
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
19881
|
-
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
19882
|
-
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
19883
|
-
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
19884
|
-
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
19885
|
-
link: "text-primary underline-offset-4 hover:underline"
|
|
19886
|
-
},
|
|
19887
|
-
size: {
|
|
19888
|
-
default: "h-10 px-4 py-2",
|
|
19889
|
-
sm: "h-9 rounded-md px-3",
|
|
19890
|
-
lg: "h-11 rounded-md px-8",
|
|
19891
|
-
icon: "h-10 w-10"
|
|
19892
|
-
}
|
|
19893
|
-
},
|
|
19894
|
-
defaultVariants: {
|
|
19895
|
-
variant: "default",
|
|
19896
|
-
size: "default"
|
|
19897
|
-
}
|
|
19898
|
-
}
|
|
19899
|
-
);
|
|
19900
|
-
var Button = React9.forwardRef(
|
|
19901
|
-
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
19902
|
-
const Comp = asChild ? Slot : "button";
|
|
19903
|
-
return /* @__PURE__ */ jsx(
|
|
19904
|
-
Comp,
|
|
19905
|
-
{
|
|
19906
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
19907
|
-
ref,
|
|
19908
|
-
...props
|
|
19909
|
-
}
|
|
19910
|
-
);
|
|
19911
|
-
}
|
|
19912
|
-
);
|
|
19913
|
-
Button.displayName = "Button";
|
|
19914
19940
|
|
|
19915
19941
|
// src/messages/smartCopy.ts
|
|
19916
19942
|
async function copyMessageRich(container, markdown) {
|
|
@@ -20932,14 +20958,16 @@ function MessageList({
|
|
|
20932
20958
|
data: thread,
|
|
20933
20959
|
isPending: threadPending,
|
|
20934
20960
|
isFetching: threadFetching,
|
|
20935
|
-
error: threadError
|
|
20961
|
+
error: threadError,
|
|
20962
|
+
refetch: refetchThread
|
|
20936
20963
|
} = useThread({ workspaceId, threadId });
|
|
20937
20964
|
const isRunning = useThreadIsRunning(workspaceId, threadId);
|
|
20938
20965
|
const {
|
|
20939
20966
|
data: messages,
|
|
20940
20967
|
isPending: messagesPending,
|
|
20941
20968
|
isFetching: messagesFetching,
|
|
20942
|
-
error: messagesError
|
|
20969
|
+
error: messagesError,
|
|
20970
|
+
refetch: refetchMessages
|
|
20943
20971
|
} = useMessages(threadId);
|
|
20944
20972
|
const hostBg = applyHostBackgroundOverride ? "chat-main" : "";
|
|
20945
20973
|
const scrollToBottom = useCallback((behavior = "auto") => {
|
|
@@ -21018,7 +21046,19 @@ function MessageList({
|
|
|
21018
21046
|
messagesError && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-destructive", children: [
|
|
21019
21047
|
/* @__PURE__ */ jsx(AlertTriangle, { className: "h-4 w-4" }),
|
|
21020
21048
|
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Failed to load messages" })
|
|
21021
|
-
] })
|
|
21049
|
+
] }),
|
|
21050
|
+
/* @__PURE__ */ jsx(
|
|
21051
|
+
Button,
|
|
21052
|
+
{
|
|
21053
|
+
size: "sm",
|
|
21054
|
+
variant: "outline",
|
|
21055
|
+
onClick: () => {
|
|
21056
|
+
if (threadError) void refetchThread();
|
|
21057
|
+
if (messagesError) void refetchMessages();
|
|
21058
|
+
},
|
|
21059
|
+
children: "Try again"
|
|
21060
|
+
}
|
|
21061
|
+
)
|
|
21022
21062
|
] }) });
|
|
21023
21063
|
}
|
|
21024
21064
|
if (safeMessages.length === 0 && !hadMessagesBefore) {
|