@smartspace/chat-ui 1.14.4-dev.b35149c → 1.14.4-dev.c351d13

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  import MuiButton from '@mui/material/Button';
2
2
  import IconButton2 from '@mui/material/IconButton';
3
- import { Loader2, ChevronDown, Check, Cpu, SlidersHorizontal, X, Globe, Zap, Square, Mic, Paperclip, Send, Minimize2, AlertTriangle, FileImage, FileVideo, FileAudio, FileArchive, FileCode, FileSpreadsheet, Presentation, FileText, ChevronUp, ExternalLink, Download, ShieldAlert, Copy } from 'lucide-react';
3
+ import { Loader2, ChevronDown, Check, Cpu, SlidersHorizontal, X, Globe, Zap, Square, Mic, Paperclip, Send, Minimize2, AlertTriangle, FileImage, FileVideo, FileAudio, FileArchive, FileCode, FileSpreadsheet, Presentation, FileText, ChevronRight, ChevronUp, ExternalLink, Download, ShieldAlert, Copy } from 'lucide-react';
4
4
  import * as React9 from 'react';
5
- import React9__default, { createContext, forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback, useContext, useSyncExternalStore } from 'react';
5
+ import React9__default, { createContext, forwardRef, useImperativeHandle, useRef, useState, useEffect, useMemo, useCallback, useContext, useSyncExternalStore, Fragment as Fragment$1 } from 'react';
6
6
  import { createPortal } from 'react-dom';
7
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
8
  import { useQuery, queryOptions, useQueryClient, useMutation } from '@tanstack/react-query';
@@ -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,
@@ -2620,7 +2604,8 @@ function kickOff(fn) {
2620
2604
  var isSupported = () => typeof window !== "undefined" && window.isSecureContext && !!navigator.mediaDevices?.getUserMedia;
2621
2605
  function classifyTokenFailure(error) {
2622
2606
  const code3 = error?.code;
2623
- if (code3 === "SP500") return "unavailable";
2607
+ if (code3 === "speech.identity_misconfigured" || code3 === "SP500")
2608
+ return "unavailable";
2624
2609
  if (error?.type === "NotFound") {
2625
2610
  return "unavailable";
2626
2611
  }
@@ -19626,7 +19611,23 @@ var ERROR_CODE_TEXT = {
19626
19611
  "llm.content_policy": "\u26A0\uFE0F **The response was blocked by a content filter**\n\nPlease rephrase your request.",
19627
19612
  "llm.schema_validation": "\u26A0\uFE0F **The model returned an invalid response**\n\nPlease try again.",
19628
19613
  "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
- "llm.unknown": GENERIC_ERROR_TEXT
19614
+ "llm.unknown": GENERIC_ERROR_TEXT,
19615
+ // The AI API's current name for llm.auth; older messages stored that one.
19616
+ "llm.auth_failed": "\u26A0\uFE0F **The model connection isn't authorised**\n\nAn administrator needs to check the model configuration.",
19617
+ "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.",
19618
+ "embeddings.model_not_found": "\u26A0\uFE0F **The model or deployment could not be found**\n\nAn administrator needs to check the model configuration.",
19619
+ // The app API's names for losing the AI API before or part-way through a reply.
19620
+ "ai_api.unavailable": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
19621
+ "ai_api.stream_broken": "\u26A0\uFE0F **The connection to the model was interrupted**\n\nThis is usually temporary. Please try again.",
19622
+ // Managed secrets. A secret's failure arrives as a 404 or 400, which the
19623
+ // status table below would read as a missing model or a generic error.
19624
+ "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.",
19625
+ "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.",
19626
+ "secret.user_mismatch": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
19627
+ "secret.run_required": "\u26A0\uFE0F **A credential couldn't be loaded**\n\nAn administrator needs to check this flow's secrets.",
19628
+ "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.",
19629
+ // The API's name for secret.not_found before it was renamed; older messages stored it.
19630
+ 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."
19630
19631
  };
19631
19632
  var STATUS_CODE_TEXT = {
19632
19633
  408: ERROR_CODE_TEXT["llm.timeout"],
@@ -19646,8 +19647,39 @@ var getMessageErrorText = (error) => {
19646
19647
  if (error.errorCode && ERROR_CODE_TEXT[error.errorCode]) {
19647
19648
  return ERROR_CODE_TEXT[error.errorCode];
19648
19649
  }
19650
+ if (error.errorCode && !error.errorCode.startsWith("llm.")) {
19651
+ return GENERIC_ERROR_TEXT;
19652
+ }
19649
19653
  return STATUS_CODE_TEXT[error.code] ?? GENERIC_ERROR_TEXT;
19650
19654
  };
19655
+ function extractProviderErrorDetail(raw2) {
19656
+ const start = raw2.indexOf("{");
19657
+ if (start === -1) return null;
19658
+ let parsed;
19659
+ try {
19660
+ parsed = JSON.parse(raw2.slice(start));
19661
+ } catch {
19662
+ return null;
19663
+ }
19664
+ if (typeof parsed !== "object" || parsed === null) return null;
19665
+ const record = parsed;
19666
+ const inner = typeof record.error === "object" && record.error !== null ? record.error : record;
19667
+ if (typeof inner.message !== "string") return null;
19668
+ return {
19669
+ message: inner.message,
19670
+ param: typeof inner.param === "string" ? inner.param : void 0
19671
+ };
19672
+ }
19673
+ var getMessageErrorDetail = (error) => {
19674
+ if (typeof error === "number" || !error.message) {
19675
+ return null;
19676
+ }
19677
+ const detail = extractProviderErrorDetail(error.message);
19678
+ if (!detail) {
19679
+ return error.message;
19680
+ }
19681
+ return detail.param ? `${detail.message} (param: ${detail.param})` : detail.message;
19682
+ };
19651
19683
  var FileInfoSchema = z.object({
19652
19684
  id: z.string(),
19653
19685
  name: z.string()
@@ -19691,7 +19723,8 @@ var MessageErrorMessageSchema = z.object({
19691
19723
  error_code: z.string().nullish(),
19692
19724
  message: z.string().nullish(),
19693
19725
  data: z.string().nullish(),
19694
- blockId: z.string().nullish()
19726
+ blockId: z.string().nullish(),
19727
+ traceId: z.string().nullish()
19695
19728
  });
19696
19729
  var MessageSchema = z.object({
19697
19730
  id: z.string().nullish(),
@@ -20539,6 +20572,34 @@ var MessageBubble = (props) => {
20539
20572
  /* @__PURE__ */ jsx("div", { className: "mt-1.5", children: metaRow })
20540
20573
  ] });
20541
20574
  };
20575
+ function MessageErrorDetails({
20576
+ detail,
20577
+ traceId
20578
+ }) {
20579
+ const [expanded, setExpanded] = useState(false);
20580
+ return /* @__PURE__ */ jsxs("div", { className: "mt-1", children: [
20581
+ /* @__PURE__ */ jsxs(
20582
+ "button",
20583
+ {
20584
+ type: "button",
20585
+ onClick: () => setExpanded((prev) => !prev),
20586
+ "aria-expanded": expanded,
20587
+ className: "m-0 inline-flex w-auto cursor-pointer appearance-none items-center gap-1 border-0 bg-transparent p-0 text-[11px] font-medium leading-none text-muted-foreground hover:text-foreground",
20588
+ children: [
20589
+ expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-3 w-3 shrink-0" }),
20590
+ expanded ? "Hide details" : "Show details"
20591
+ ]
20592
+ }
20593
+ ),
20594
+ expanded && /* @__PURE__ */ jsxs("div", { className: "mt-1.5 whitespace-pre-wrap break-words rounded-md bg-secondary/60 p-2 font-mono text-[11px] leading-relaxed text-muted-foreground", children: [
20595
+ detail,
20596
+ traceId && /* @__PURE__ */ jsxs("div", { className: detail ? "mt-1.5" : void 0, children: [
20597
+ "Reference: ",
20598
+ traceId
20599
+ ] })
20600
+ ] })
20601
+ ] });
20602
+ }
20542
20603
  var ThinkingSection = ({ status }) => /* @__PURE__ */ jsxs(
20543
20604
  "div",
20544
20605
  {
@@ -20826,22 +20887,26 @@ var MessageItem = ({
20826
20887
  );
20827
20888
  }
20828
20889
  (message.errors ?? []).forEach((error, errorIndex) => {
20890
+ const key = `error-${message.id ?? "msg"}-${errorIndex}-${error.errorCode ?? error.code}`;
20891
+ const detail = getMessageErrorDetail(error);
20829
20892
  bubbles.push(
20830
- /* @__PURE__ */ jsx(
20831
- MessageBubble,
20832
- {
20833
- createdBy: chatbotName,
20834
- createdAt: message.createdAt,
20835
- type: "Output" /* OUTPUT */,
20836
- content: [{ text: getMessageErrorText(error) }],
20837
- files: [],
20838
- sources: [],
20839
- chatbotName,
20840
- userOutput: null,
20841
- userInput: null
20842
- },
20843
- `error-${message.id ?? "msg"}-${errorIndex}-${error.errorCode ?? error.code}`
20844
- )
20893
+ /* @__PURE__ */ jsxs(Fragment$1, { children: [
20894
+ /* @__PURE__ */ jsx(
20895
+ MessageBubble,
20896
+ {
20897
+ createdBy: chatbotName,
20898
+ createdAt: message.createdAt,
20899
+ type: "Output" /* OUTPUT */,
20900
+ content: [{ text: getMessageErrorText(error) }],
20901
+ files: [],
20902
+ sources: [],
20903
+ chatbotName,
20904
+ userOutput: null,
20905
+ userInput: null
20906
+ }
20907
+ ),
20908
+ (detail || error.traceId) && /* @__PURE__ */ jsx(MessageErrorDetails, { detail, traceId: error.traceId })
20909
+ ] }, key)
20845
20910
  );
20846
20911
  });
20847
20912
  return bubbles;
@@ -21096,6 +21161,11 @@ function MessageListSkeleton() {
21096
21161
  i
21097
21162
  )) });
21098
21163
  }
21164
+
21165
+ // src/shared/utils/enums.ts
21166
+ var isMember = (e, value) => Object.values(e).includes(value);
21167
+
21168
+ // src/domains/messages/mapper.ts
21099
21169
  var {
21100
21170
  messageThreadsThreadMessagesIdMessagesResponse: messagesResponseSchema
21101
21171
  } = ChatZod;
@@ -21122,6 +21192,7 @@ function mapMessageValueDtoToModel(dto) {
21122
21192
  createdByUserId: dto.createdByUserId ?? void 0
21123
21193
  };
21124
21194
  }
21195
+ var mapMessageValuesDtoToModels = (dtos) => dtos.filter((dto) => isMember(MessageValueType, dto.type)).map(mapMessageValueDtoToModel);
21125
21196
  function mapMessageErrorDtoToModel(dto) {
21126
21197
  const { error_code, ...rest } = dto;
21127
21198
  return {
@@ -21139,7 +21210,7 @@ function mapMessageDtoToModel(dto) {
21139
21210
  createdByUserId: dto.createdByUserId ?? void 0,
21140
21211
  messageThreadId: dto.messageThreadId ?? void 0,
21141
21212
  errors: dto.errors?.map(mapMessageErrorDtoToModel) ?? void 0,
21142
- values: dto.values?.map(mapMessageValueDtoToModel)
21213
+ values: dto.values && mapMessageValuesDtoToModels(dto.values)
21143
21214
  };
21144
21215
  }
21145
21216
  function mapMessagesDtoToModels(dto) {
@@ -21255,8 +21326,7 @@ var mapWorkspacesDtoToModels = (arr) => arr.map(mapWorkspaceDtoToModel);
21255
21326
  function getChatApiBaseUrl() {
21256
21327
  try {
21257
21328
  const w = window;
21258
- const env2 = import.meta.env;
21259
- const cfg = w?.ssconfig?.Chat_Api_Uri ?? env2?.VITE_CHAT_API_URI;
21329
+ const cfg = w?.ssconfig?.Chat_Api_Uri;
21260
21330
  return typeof cfg === "string" && cfg.trim() ? cfg.trim() : "";
21261
21331
  } catch {
21262
21332
  return "";
@@ -21269,6 +21339,6 @@ function getUserPhotoUrl(userId) {
21269
21339
  return `${base2}/users/${userId}/photo`;
21270
21340
  }
21271
21341
 
21272
- export { ChatProvider, ChatVariablesForm, DRAFT_THREAD_PREFIX, DateFromApi, DictationButton, MarkdownEditor, MessageComposer, MessageList, MessageListSkeleton, MessageMarkdown, MessageValueType, NEW_THREAD_ID, THREAD_LIST_PAGE_SIZE, applyDeltaToMessage, applyThreadToCache, createDraftThreadId, createThreadId, downloadFileBlobOptions, filesKeys, flowRunsKeys, getMessageErrorText, getModelIcon, getRetryStatusText, getThreadPlaceholderFromListCache, getUserPhotoUrl, invalidateWorkspaceThreadLists, isDraftThreadId, mapFileInfoDtoToModel, mapMentionUserDtoToModel, mapMessageDtoToModel, mapMessageErrorDtoToModel, mapMessageValueDtoToModel, mapMessagesDtoToModels, mapSignalRThreadSummaryToModel, mapThreadDtoToModel, mapThreadsResponseDtoToModel, mapWorkspaceDtoToModel, mapWorkspacesDtoToModels, markDraftThreadId, messagesKeys, messagesListOptions, messagesMutationsKeys, modelsKeys, parseDateTime, parseDateTimeHuman, parseRetryStatus, randomUUID, setThreadOptimisticRunning, setThreadRunningInLists, speechKeys, taggableUsersOptions, threadDetailOptions, threadsKeys, unmarkDraftThreadId, useAddInputToMessage, useChatContext, useChatIdentity, useChatService, useDictation, useDownloadFileBlobQuery, useFileMutations, useFlowRunVariables, useIsDraftThreadId, useMessages, useModels, useSendMessage, useSpeechConfig, useTaggableWorkspaceUsers, useThread, useThreadIsRunning, useUpdateFlowRunVariable, useWorkspace, utcDate, workspaceDetailOptions, workspaceKeys };
21342
+ export { ChatProvider, ChatVariablesForm, DRAFT_THREAD_PREFIX, DateFromApi, DictationButton, MarkdownEditor, MessageComposer, MessageList, MessageListSkeleton, MessageMarkdown, MessageValueType, NEW_THREAD_ID, THREAD_LIST_PAGE_SIZE, applyDeltaToMessage, applyThreadToCache, createDraftThreadId, createThreadId, downloadFileBlobOptions, filesKeys, flowRunsKeys, getMessageErrorDetail, getMessageErrorText, getModelIcon, getRetryStatusText, getThreadPlaceholderFromListCache, getUserPhotoUrl, invalidateWorkspaceThreadLists, isDraftThreadId, mapFileInfoDtoToModel, mapMentionUserDtoToModel, mapMessageDtoToModel, mapMessageErrorDtoToModel, mapMessageValueDtoToModel, mapMessageValuesDtoToModels, mapMessagesDtoToModels, mapSignalRThreadSummaryToModel, mapThreadDtoToModel, mapThreadsResponseDtoToModel, mapWorkspaceDtoToModel, mapWorkspacesDtoToModels, markDraftThreadId, messagesKeys, messagesListOptions, messagesMutationsKeys, modelsKeys, parseDateTime, parseDateTimeHuman, parseRetryStatus, randomUUID, setThreadOptimisticRunning, setThreadRunningInLists, speechKeys, taggableUsersOptions, threadDetailOptions, threadsKeys, unmarkDraftThreadId, useAddInputToMessage, useChatContext, useChatIdentity, useChatService, useDictation, useDownloadFileBlobQuery, useFileMutations, useFlowRunVariables, useIsDraftThreadId, useMessages, useModels, useSendMessage, useSpeechConfig, useTaggableWorkspaceUsers, useThread, useThreadIsRunning, useUpdateFlowRunVariable, useWorkspace, utcDate, workspaceDetailOptions, workspaceKeys };
21273
21343
  //# sourceMappingURL=index.js.map
21274
21344
  //# sourceMappingURL=index.js.map