@smartspace/chat-ui 1.14.4-dev.df9addb → 1.14.4-dev.e013452

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.d.ts CHANGED
@@ -451,7 +451,6 @@ interface ChatService {
451
451
  uploadFiles(files: File[], scope: FileScope, onFileUploaded?: (file: File, fileInfo: FileInfo$1) => void, onChunkUploaded?: (chunkIndex: number, totalChunks: number, file: File) => void): Promise<FileInfo$1[]>;
452
452
  downloadFile(id: string, scope?: FileScope): Promise<Blob>;
453
453
  getFileInfo(id: string, scope: FileScope): Promise<FileInfo$1>;
454
- getFileDownloadUrl(sourceUri: string): Promise<string>;
455
454
  fetchThread(workspaceId: string, threadId: string): Promise<MessageThread>;
456
455
  fetchWorkspace(workspaceId: string): Promise<Workspace>;
457
456
  fetchTaggableUsers(workspaceId: string): Promise<MentionUser[]>;
@@ -1256,9 +1255,6 @@ declare const filesKeys: {
1256
1255
  downloadBlob: (fileId: string) => readonly ["files", "mutation", "downloadBlob", {
1257
1256
  readonly fileId: string;
1258
1257
  }];
1259
- downloadByUri: (uri: string) => readonly ["files", "mutation", "downloadByUri", {
1260
- readonly uri: string;
1261
- }];
1262
1258
  };
1263
1259
  };
1264
1260
 
@@ -1354,10 +1350,6 @@ declare function useMessages(threadId: string): _tanstack_react_query.UseQueryRe
1354
1350
  declare const useFileMutations: (scope: FileScope) => {
1355
1351
  uploadFilesMutation: _tanstack_react_query.UseMutationResult<FileInfo$1[], Error, File[], unknown>;
1356
1352
  downloadFileMutation: _tanstack_react_query.UseMutationResult<void, Error, FileInfo$1, unknown>;
1357
- downloadFileByUriMutation: _tanstack_react_query.UseMutationResult<Blob, Error, {
1358
- name: string;
1359
- sourceUri: string;
1360
- }, unknown>;
1361
1353
  getFileBlobUrl: (id: string) => Promise<string>;
1362
1354
  fileProgress: Record<string, number>;
1363
1355
  uploadedFiles: FileInfo$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 MuiSkeleton from '@mui/material/Skeleton';
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;
@@ -115,8 +115,7 @@ var filesKeys = {
115
115
  mutation: {
116
116
  upload: (scope) => [...filesKeys.mutations(), "upload", { scope }],
117
117
  download: (fileId) => [...filesKeys.mutations(), "download", { fileId }],
118
- downloadBlob: (fileId) => [...filesKeys.mutations(), "downloadBlob", { fileId }],
119
- downloadByUri: (uri) => [...filesKeys.mutations(), "downloadByUri", { uri }]
118
+ downloadBlob: (fileId) => [...filesKeys.mutations(), "downloadBlob", { fileId }]
120
119
  }
121
120
  };
122
121
 
@@ -163,20 +162,6 @@ var useFileMutations = (scope) => {
163
162
  },
164
163
  onError: () => toast.error("Failed to download file")
165
164
  });
166
- const downloadFileByUriMutation = useMutation({
167
- mutationFn: async ({
168
- name,
169
- sourceUri
170
- }) => {
171
- const uri = await service.getFileDownloadUrl(sourceUri);
172
- if (!uri) throw new Error("No download URL");
173
- const response = await fetch(uri);
174
- const blob = await response.blob();
175
- saveFile(blob, name);
176
- return blob;
177
- },
178
- onError: () => toast.error("Failed to download file")
179
- });
180
165
  const fileStates = (files) => files.map((file) => ({
181
166
  name: file.name,
182
167
  progress: fileProgress[file.name] ?? 0,
@@ -200,7 +185,6 @@ var useFileMutations = (scope) => {
200
185
  return {
201
186
  uploadFilesMutation,
202
187
  downloadFileMutation,
203
- downloadFileByUriMutation,
204
188
  getFileBlobUrl,
205
189
  fileProgress,
206
190
  uploadedFiles,
@@ -556,7 +540,10 @@ var threadDetailOptions = ({
556
540
  queryKey: threadsKeys.detail(workspaceId, threadId),
557
541
  queryFn: () => service.fetchThread(workspaceId, threadId),
558
542
  refetchOnWindowFocus: false,
559
- 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
560
547
  });
561
548
  function getThreadPlaceholderFromListCache(queryClient, workspaceId, threadId) {
562
549
  const entries = queryClient.getQueriesData({
@@ -2620,7 +2607,8 @@ function kickOff(fn) {
2620
2607
  var isSupported = () => typeof window !== "undefined" && window.isSecureContext && !!navigator.mediaDevices?.getUserMedia;
2621
2608
  function classifyTokenFailure(error) {
2622
2609
  const code3 = error?.code;
2623
- if (code3 === "SP500") return "unavailable";
2610
+ if (code3 === "speech.identity_misconfigured" || code3 === "SP500")
2611
+ return "unavailable";
2624
2612
  if (error?.type === "NotFound") {
2625
2613
  return "unavailable";
2626
2614
  }
@@ -4251,7 +4239,10 @@ var workspaceDetailOptions = ({
4251
4239
  }) => queryOptions({
4252
4240
  queryKey: workspaceKeys.byId(workspaceId),
4253
4241
  queryFn: () => service.fetchWorkspace(workspaceId),
4254
- 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
4255
4246
  });
4256
4247
  function useWorkspace(workspaceId) {
4257
4248
  const service = useChatService();
@@ -19598,6 +19589,45 @@ function MessageMarkdown({ value, className }) {
19598
19589
  function cn(...inputs) {
19599
19590
  return twMerge(clsx(inputs));
19600
19591
  }
19592
+ var buttonVariants = cva(
19593
+ "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",
19594
+ {
19595
+ variants: {
19596
+ variant: {
19597
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
19598
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
19599
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
19600
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19601
+ ghost: "hover:bg-accent hover:text-accent-foreground",
19602
+ link: "text-primary underline-offset-4 hover:underline"
19603
+ },
19604
+ size: {
19605
+ default: "h-10 px-4 py-2",
19606
+ sm: "h-9 rounded-md px-3",
19607
+ lg: "h-11 rounded-md px-8",
19608
+ icon: "h-10 w-10"
19609
+ }
19610
+ },
19611
+ defaultVariants: {
19612
+ variant: "default",
19613
+ size: "default"
19614
+ }
19615
+ }
19616
+ );
19617
+ var Button = React9.forwardRef(
19618
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
19619
+ const Comp = asChild ? Slot : "button";
19620
+ return /* @__PURE__ */ jsx(
19621
+ Comp,
19622
+ {
19623
+ className: cn(buttonVariants({ variant, size, className })),
19624
+ ref,
19625
+ ...props
19626
+ }
19627
+ );
19628
+ }
19629
+ );
19630
+ Button.displayName = "Button";
19601
19631
  function Skeleton({ className, ...props }) {
19602
19632
  return /* @__PURE__ */ jsx(
19603
19633
  MuiSkeleton,
@@ -19627,12 +19657,21 @@ var ERROR_CODE_TEXT = {
19627
19657
  "llm.schema_validation": "\u26A0\uFE0F **The model returned an invalid response**\n\nPlease try again.",
19628
19658
  "llm.unsupported_modality": "\u26A0\uFE0F **This model can't read images**\n\nSwitch to a vision-capable model, or remove the attachment and describe it instead.",
19629
19659
  "llm.unknown": GENERIC_ERROR_TEXT,
19660
+ // The AI API's current name for llm.auth; older messages stored that one.
19661
+ "llm.auth_failed": "\u26A0\uFE0F **The model connection isn't authorised**\n\nAn administrator needs to check the model configuration.",
19662
+ "llm.unsupported_tools": "\u26A0\uFE0F **This model can't use tools**\n\nAn administrator needs to choose a model that supports tools for this step.",
19663
+ "embeddings.model_not_found": "\u26A0\uFE0F **The model or deployment could not be found**\n\nAn administrator needs to check the model configuration.",
19664
+ // The app API's names for losing the AI API before or part-way through a reply.
19665
+ "ai_api.unavailable": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
19666
+ "ai_api.stream_broken": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
19630
19667
  // Managed secrets. A secret's failure arrives as a 404 or 400, which the
19631
19668
  // status table below would read as a missing model or a generic error.
19632
19669
  "secret.user_value_not_set": "\u26A0\uFE0F **Your own key for this isn't set**\n\nThis step uses a credential each person sets for themselves, and none is set for you yet. Ask an administrator to add it.",
19633
19670
  "secret.run_has_no_user": "\u26A0\uFE0F **This step needs a signed-in user**\n\nIt uses a person's own credential, so it can't run when no one started the run.",
19634
19671
  "secret.user_mismatch": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
19635
19672
  "secret.run_required": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
19673
+ "secret.not_found": "\u26A0\uFE0F **A secret this flow uses doesn't exist**\n\nAn administrator needs to add it, or point the flow at another one.",
19674
+ // The API's name for secret.not_found before it was renamed; older messages stored it.
19636
19675
  MS404: "\u26A0\uFE0F **A secret this flow uses doesn't exist**\n\nAn administrator needs to add it, or point the flow at another one."
19637
19676
  };
19638
19677
  var STATUS_CODE_TEXT = {
@@ -19653,6 +19692,9 @@ var getMessageErrorText = (error) => {
19653
19692
  if (error.errorCode && ERROR_CODE_TEXT[error.errorCode]) {
19654
19693
  return ERROR_CODE_TEXT[error.errorCode];
19655
19694
  }
19695
+ if (error.errorCode && !error.errorCode.startsWith("llm.")) {
19696
+ return GENERIC_ERROR_TEXT;
19697
+ }
19656
19698
  return STATUS_CODE_TEXT[error.code] ?? GENERIC_ERROR_TEXT;
19657
19699
  };
19658
19700
  function extractProviderErrorDetail(raw2) {
@@ -19875,45 +19917,6 @@ function parseDateTime(date, customFormat) {
19875
19917
  function parseDateTimeHuman(date) {
19876
19918
  return dayjs.utc(date).local().fromNow();
19877
19919
  }
19878
- var buttonVariants = cva(
19879
- "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",
19880
- {
19881
- variants: {
19882
- variant: {
19883
- default: "bg-primary text-primary-foreground hover:bg-primary/90",
19884
- destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
19885
- outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
19886
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19887
- ghost: "hover:bg-accent hover:text-accent-foreground",
19888
- link: "text-primary underline-offset-4 hover:underline"
19889
- },
19890
- size: {
19891
- default: "h-10 px-4 py-2",
19892
- sm: "h-9 rounded-md px-3",
19893
- lg: "h-11 rounded-md px-8",
19894
- icon: "h-10 w-10"
19895
- }
19896
- },
19897
- defaultVariants: {
19898
- variant: "default",
19899
- size: "default"
19900
- }
19901
- }
19902
- );
19903
- var Button = React9.forwardRef(
19904
- ({ className, variant, size, asChild = false, ...props }, ref) => {
19905
- const Comp = asChild ? Slot : "button";
19906
- return /* @__PURE__ */ jsx(
19907
- Comp,
19908
- {
19909
- className: cn(buttonVariants({ variant, size, className })),
19910
- ref,
19911
- ...props
19912
- }
19913
- );
19914
- }
19915
- );
19916
- Button.displayName = "Button";
19917
19920
 
19918
19921
  // src/messages/smartCopy.ts
19919
19922
  async function copyMessageRich(container, markdown) {
@@ -20935,14 +20938,16 @@ function MessageList({
20935
20938
  data: thread,
20936
20939
  isPending: threadPending,
20937
20940
  isFetching: threadFetching,
20938
- error: threadError
20941
+ error: threadError,
20942
+ refetch: refetchThread
20939
20943
  } = useThread({ workspaceId, threadId });
20940
20944
  const isRunning = useThreadIsRunning(workspaceId, threadId);
20941
20945
  const {
20942
20946
  data: messages,
20943
20947
  isPending: messagesPending,
20944
20948
  isFetching: messagesFetching,
20945
- error: messagesError
20949
+ error: messagesError,
20950
+ refetch: refetchMessages
20946
20951
  } = useMessages(threadId);
20947
20952
  const hostBg = applyHostBackgroundOverride ? "chat-main" : "";
20948
20953
  const scrollToBottom = useCallback((behavior = "auto") => {
@@ -21021,7 +21026,19 @@ function MessageList({
21021
21026
  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: [
21022
21027
  /* @__PURE__ */ jsx(AlertTriangle, { className: "h-4 w-4" }),
21023
21028
  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "Failed to load messages" })
21024
- ] })
21029
+ ] }),
21030
+ /* @__PURE__ */ jsx(
21031
+ Button,
21032
+ {
21033
+ size: "sm",
21034
+ variant: "outline",
21035
+ onClick: () => {
21036
+ if (threadError) void refetchThread();
21037
+ if (messagesError) void refetchMessages();
21038
+ },
21039
+ children: "Try again"
21040
+ }
21041
+ )
21025
21042
  ] }) });
21026
21043
  }
21027
21044
  if (safeMessages.length === 0 && !hadMessagesBefore) {