@axiom-lattice/react-sdk 2.2.0 → 2.2.2

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
@@ -3367,6 +3367,13 @@ var WorkspaceContextProvider = ({
3367
3367
  },
3368
3368
  [client, workspaceId, projectId]
3369
3369
  );
3370
+ const getFileDownloadUrl = (0, import_react12.useCallback)(
3371
+ (filePath, assistantId) => {
3372
+ if (!workspaceId || !projectId) return "";
3373
+ return client.getFileDownloadUrl(workspaceId, projectId, filePath, assistantId);
3374
+ },
3375
+ [client, workspaceId, projectId]
3376
+ );
3370
3377
  const getDirectFileUrl = (0, import_react12.useCallback)(
3371
3378
  (filePath) => {
3372
3379
  if (!tenantId || !workspaceId || !projectId) return "";
@@ -3423,6 +3430,7 @@ var WorkspaceContextProvider = ({
3423
3430
  uploadFileToFolder,
3424
3431
  uploadFileToProject,
3425
3432
  getFileViewUrl,
3433
+ getFileDownloadUrl,
3426
3434
  getDirectFileUrl,
3427
3435
  shareFile,
3428
3436
  listShares,
@@ -19868,12 +19876,14 @@ var useStyles24 = (0, import_antd_style33.createStyles)(({ token, css }) => ({
19868
19876
  var MarkdownViewer = ({
19869
19877
  content,
19870
19878
  fileName,
19879
+ downloadUrl,
19871
19880
  className,
19872
19881
  style
19873
19882
  }) => {
19874
19883
  const { styles, cx } = useStyles24();
19875
19884
  const [copied, setCopied] = (0, import_react75.useState)(false);
19876
19885
  const contentRef = (0, import_react75.useRef)(null);
19886
+ const downloadFileName = fileName.split("/").pop() || fileName;
19877
19887
  (0, import_react75.useEffect)(() => {
19878
19888
  if (copied) {
19879
19889
  const timer = setTimeout(() => setCopied(false), 2e3);
@@ -19891,7 +19901,6 @@ var MarkdownViewer = ({
19891
19901
  const url = URL.createObjectURL(blob);
19892
19902
  const a = document.createElement("a");
19893
19903
  a.href = url;
19894
- const downloadFileName = fileName.split("/").pop() || fileName;
19895
19904
  a.download = downloadFileName;
19896
19905
  document.body.appendChild(a);
19897
19906
  a.click();
@@ -20015,7 +20024,10 @@ ${content}
20015
20024
  {
20016
20025
  type: "text",
20017
20026
  icon: /* @__PURE__ */ (0, import_jsx_runtime73.jsx)(import_icons14.DownloadOutlined, {}),
20018
- onClick: handleDownload,
20027
+ "aria-label": "Download File",
20028
+ href: downloadUrl,
20029
+ download: downloadUrl ? downloadFileName : void 0,
20030
+ onClick: downloadUrl ? void 0 : handleDownload,
20019
20031
  size: "small"
20020
20032
  }
20021
20033
  ) }),
@@ -20427,6 +20439,10 @@ var AttachmentsCard = ({
20427
20439
  const { config } = useLatticeChatShellContext();
20428
20440
  const workspaceCtx = (0, import_react77.useContext)(WorkspaceContext);
20429
20441
  const baseURL = config.baseURL;
20442
+ const getSandboxFileUrl = (filePath) => {
20443
+ const params = new URLSearchParams({ path: filePath });
20444
+ return `${baseURL}/api/assistants/${assistantId}/threads/${threadId}/sandbox/downloadfile?${params.toString()}`;
20445
+ };
20430
20446
  const getFileUrl = (item) => {
20431
20447
  if (typeof item.id === "string" && /^https?:\/\//i.test(item.id)) {
20432
20448
  return item.id;
@@ -20434,7 +20450,16 @@ var AttachmentsCard = ({
20434
20450
  if (workspaceCtx?.workspaceId && workspaceCtx?.projectId) {
20435
20451
  return workspaceCtx.getFileViewUrl(item.id, assistantId || void 0);
20436
20452
  }
20437
- return `${baseURL}/api/assistants/${assistantId}/threads/${threadId}/sandbox/downloadfile?path=${item.id}`;
20453
+ return getSandboxFileUrl(item.id);
20454
+ };
20455
+ const getFileDownloadUrl = (item) => {
20456
+ if (typeof item.id === "string" && /^https?:\/\//i.test(item.id)) {
20457
+ return item.id;
20458
+ }
20459
+ if (workspaceCtx?.workspaceId && workspaceCtx?.projectId) {
20460
+ return workspaceCtx.getFileDownloadUrl(item.id, assistantId || void 0);
20461
+ }
20462
+ return getSandboxFileUrl(item.id);
20438
20463
  };
20439
20464
  const { Text: Text77 } = import_antd56.Typography;
20440
20465
  const [showAll, setShowAll] = (0, import_react77.useState)(false);
@@ -20470,7 +20495,12 @@ var AttachmentsCard = ({
20470
20495
  if (getFileCategory(item.name) === "image") return;
20471
20496
  openSideApp({
20472
20497
  component_key: "attachments",
20473
- data: { file_id: item.id, message: "Preview: " + item.name, full_url: getFileUrl(item) },
20498
+ data: {
20499
+ file_id: item.id,
20500
+ message: "Preview: " + item.name,
20501
+ full_url: getFileUrl(item),
20502
+ download_url: getFileDownloadUrl(item)
20503
+ },
20474
20504
  message: "Preview: " + item.name
20475
20505
  });
20476
20506
  };
@@ -20711,6 +20741,7 @@ var useStyles26 = (0, import_antd_style35.createStyles)(({ token, css }) => ({
20711
20741
  var FileRenderer = ({
20712
20742
  fileUrl,
20713
20743
  fileName = "",
20744
+ downloadUrl,
20714
20745
  showHeader = true
20715
20746
  }) => {
20716
20747
  const { styles } = useStyles26();
@@ -20745,7 +20776,14 @@ var FileRenderer = ({
20745
20776
  switch (category) {
20746
20777
  case "markdown":
20747
20778
  case "text":
20748
- return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.container, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(MarkdownViewer, { content, fileName }) });
20779
+ return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.container, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(
20780
+ MarkdownViewer,
20781
+ {
20782
+ content,
20783
+ fileName,
20784
+ downloadUrl
20785
+ }
20786
+ ) });
20749
20787
  case "image":
20750
20788
  return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.container, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.contentWrapper, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.imageContainer, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("img", { src: fileUrl, alt: fileName, className: styles.image }) }) }) });
20751
20789
  case "pdf":
@@ -20772,19 +20810,24 @@ var FileRenderer = ({
20772
20810
  return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: styles.container, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)("div", { className: styles.downloadContainer, children: [
20773
20811
  /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(import_icons17.FileUnknownOutlined, { className: styles.fileIcon }),
20774
20812
  /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("span", { className: styles.fileName, children: fileName || "Unknown file" }),
20775
- /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(import_antd57.Button, { type: "primary", href: fileUrl, download: fileName, children: "Download File" })
20813
+ /* @__PURE__ */ (0, import_jsx_runtime77.jsx)(import_antd57.Button, { type: "primary", href: downloadUrl || fileUrl, download: fileName, children: "Download File" })
20776
20814
  ] }) });
20777
20815
  }
20778
20816
  };
20779
20817
 
20780
20818
  // src/components/GenUI/RenderMDFromURL.tsx
20781
20819
  var import_jsx_runtime78 = require("react/jsx-runtime");
20782
- var RenderMDFromURL = ({ url, file_id }) => {
20820
+ var RenderMDFromURL = ({
20821
+ url,
20822
+ file_id,
20823
+ downloadUrl
20824
+ }) => {
20783
20825
  return /* @__PURE__ */ (0, import_jsx_runtime78.jsx)(
20784
20826
  FileRenderer,
20785
20827
  {
20786
20828
  fileUrl: url,
20787
20829
  fileName: file_id,
20830
+ downloadUrl,
20788
20831
  showHeader: true
20789
20832
  }
20790
20833
  );
@@ -21029,7 +21072,7 @@ function AttachmentsViewerSideApp({
21029
21072
  }) {
21030
21073
  const [loading, setLoading] = (0, import_react80.useState)(false);
21031
21074
  const [shareOpen, setShareOpen] = (0, import_react80.useState)(false);
21032
- const { file_id, url, full_url } = data ?? {};
21075
+ const { file_id, url, full_url, download_url } = data ?? {};
21033
21076
  const [fileUri, setFileUri] = (0, import_react80.useState)({
21034
21077
  url: full_url || "",
21035
21078
  fileName: extractFileName(file_id || "")
@@ -21044,13 +21087,21 @@ function AttachmentsViewerSideApp({
21044
21087
  return /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(import_antd59.Skeleton, { active: true });
21045
21088
  }
21046
21089
  const fileUrl = fileUri?.url || url;
21090
+ const downloadUrl = download_url || fileUrl || "";
21047
21091
  const fileName = fileUri?.fileName || "";
21048
21092
  const isText = isTextFile(fileName);
21049
21093
  const isPreviewable = canPreviewInline(fileName);
21050
21094
  const isDir = !!fileName && !fileName.includes(".");
21051
21095
  let content;
21052
21096
  if (isText && fileUrl) {
21053
- content = /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(RenderMDFromURL, { url: fileUrl, file_id });
21097
+ content = /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
21098
+ RenderMDFromURL,
21099
+ {
21100
+ url: fileUrl,
21101
+ file_id,
21102
+ downloadUrl
21103
+ }
21104
+ );
21054
21105
  } else if (isPreviewable || url || isDir) {
21055
21106
  content = /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
21056
21107
  "iframe",
@@ -21065,10 +21116,10 @@ function AttachmentsViewerSideApp({
21065
21116
  {
21066
21117
  description: /* @__PURE__ */ (0, import_jsx_runtime80.jsxs)(import_jsx_runtime80.Fragment, { children: [
21067
21118
  /* @__PURE__ */ (0, import_jsx_runtime80.jsx)("div", { children: "Preview not supported. Please download to view." }),
21068
- /* @__PURE__ */ (0, import_jsx_runtime80.jsxs)(import_antd59.Button, { type: "link", href: fileUri?.url, download: fileUri?.fileName, children: [
21119
+ downloadUrl ? /* @__PURE__ */ (0, import_jsx_runtime80.jsxs)(import_antd59.Button, { type: "link", href: downloadUrl, download: fileName, children: [
21069
21120
  "Download ",
21070
- fileUri?.fileName
21071
- ] })
21121
+ fileName
21122
+ ] }) : null
21072
21123
  ] }),
21073
21124
  image: import_antd59.Empty.PRESENTED_IMAGE_DEFAULT
21074
21125
  }
@@ -21076,17 +21127,17 @@ function AttachmentsViewerSideApp({
21076
21127
  }
21077
21128
  return /* @__PURE__ */ (0, import_jsx_runtime80.jsxs)("div", { style: { display: "flex", flexDirection: "column", height: "100%" }, children: [
21078
21129
  /* @__PURE__ */ (0, import_jsx_runtime80.jsxs)(import_antd59.Space, { style: { padding: "8px 12px", borderBottom: "1px solid #f0f0f0", width: "100%" }, children: [
21079
- /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
21130
+ downloadUrl ? /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
21080
21131
  import_antd59.Button,
21081
21132
  {
21082
21133
  type: "text",
21083
21134
  size: "small",
21084
21135
  icon: /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(import_icons19.DownloadOutlined, {}),
21085
- href: fileUrl,
21136
+ href: downloadUrl,
21086
21137
  download: fileName,
21087
21138
  children: "Download"
21088
21139
  }
21089
- ),
21140
+ ) : null,
21090
21141
  /* @__PURE__ */ (0, import_jsx_runtime80.jsx)(
21091
21142
  import_antd59.Button,
21092
21143
  {
@@ -31914,25 +31965,28 @@ var FileLink = ({ data }) => {
31914
31965
  const openSideApp = useSideAppOpener();
31915
31966
  const { threadId, assistantId } = useConversationContext();
31916
31967
  const { config } = useLatticeChatShellContext();
31917
- const fileBaseURL = (0, import_react112.useMemo)(() => {
31968
+ const fileEndpoint = (0, import_react112.useMemo)(() => {
31918
31969
  if (!config?.baseURL || !assistantId || !threadId) {
31919
31970
  return null;
31920
31971
  }
31921
- return `${config.baseURL}/api/assistants/${assistantId}/threads/${threadId}/sandbox/downloadfile?path=`;
31972
+ return `${config.baseURL}/api/assistants/${assistantId}/threads/${threadId}/sandbox/downloadfile`;
31922
31973
  }, [config?.baseURL, assistantId, threadId]);
31923
31974
  const handleItemClick = (0, import_react112.useCallback)((path) => {
31924
- if (!fileBaseURL) return;
31975
+ if (!fileEndpoint) return;
31976
+ const params = new URLSearchParams({ path });
31977
+ const fileUrl = `${fileEndpoint}?${params.toString()}`;
31925
31978
  openSideApp({
31926
31979
  component_key: "attachments",
31927
31980
  data: {
31928
31981
  file_id: path,
31929
31982
  message: "\u9884\u89C8\uFF1A" + path.split("/").pop(),
31930
- full_url: `${fileBaseURL}${path}`
31983
+ full_url: fileUrl,
31984
+ download_url: fileUrl
31931
31985
  },
31932
31986
  message: "\u9884\u89C8\uFF1A" + path.split("/").pop()
31933
31987
  });
31934
- }, [fileBaseURL, openSideApp]);
31935
- if (!fileBaseURL) {
31988
+ }, [fileEndpoint, openSideApp]);
31989
+ if (!fileEndpoint) {
31936
31990
  return /* @__PURE__ */ (0, import_jsx_runtime137.jsx)("span", { children: data });
31937
31991
  }
31938
31992
  return /* @__PURE__ */ (0, import_jsx_runtime137.jsx)(import_antd104.Button, { type: "link", size: "small", onClick: () => handleItemClick(data), children: data });
@@ -46363,7 +46417,7 @@ var FileDirectoryPanel = ({
46363
46417
  }) => {
46364
46418
  const { styles } = useStyles48();
46365
46419
  const { currentAssistant } = useAssistantContext();
46366
- const { getFileViewUrl, getDirectFileUrl } = useWorkspaceContext();
46420
+ const { getFileDownloadUrl, getDirectFileUrl } = useWorkspaceContext();
46367
46421
  const { openSideApp } = useChatUIContext();
46368
46422
  const { currentTenant } = useAuth();
46369
46423
  const tenantId = currentTenant?.id || "";
@@ -46635,7 +46689,7 @@ var FileDirectoryPanel = ({
46635
46689
  icon: /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(import_icons50.DownloadOutlined, {}),
46636
46690
  label: "Download",
46637
46691
  onClick: () => {
46638
- const url = getFileViewUrl(
46692
+ const url = getFileDownloadUrl(
46639
46693
  entry.path,
46640
46694
  currentAssistant?.id
46641
46695
  );
@@ -46661,7 +46715,7 @@ var FileDirectoryPanel = ({
46661
46715
  }
46662
46716
  )
46663
46717
  ] }, entry.path);
46664
- }, [directoryChildren, directoryExpanded, directoryLoading, onAssetClick, onToggleDirectory, styles, getFileViewUrl, currentAssistant?.id, enableCustomMenu, pinStates, handleDropdownOpen, handleUnpin]);
46718
+ }, [directoryChildren, directoryExpanded, directoryLoading, onAssetClick, onToggleDirectory, styles, getFileDownloadUrl, currentAssistant?.id, enableCustomMenu, pinStates, handleDropdownOpen, handleUnpin]);
46665
46719
  if (!projectId) {
46666
46720
  return /* @__PURE__ */ (0, import_jsx_runtime194.jsx)("div", { className: styles.emptyState, children: "Please select a project to browse files" });
46667
46721
  }
@@ -46764,6 +46818,7 @@ var ToolPanelFiles = () => {
46764
46818
  listPath,
46765
46819
  listPathByFolder,
46766
46820
  getFileViewUrl,
46821
+ getFileDownloadUrl,
46767
46822
  uploadFileToFolder
46768
46823
  } = useWorkspaceContext();
46769
46824
  const { currentAssistant } = useAssistantContext();
@@ -46841,7 +46896,8 @@ var ToolPanelFiles = () => {
46841
46896
  }, [resourceFolders, loadAssetsForFolder]);
46842
46897
  const handleAssetClick = (0, import_react171.useCallback)((asset) => {
46843
46898
  const fileUrl = getFileViewUrl(asset.path, currentAssistant?.id);
46844
- if (!fileUrl) {
46899
+ const downloadUrl = getFileDownloadUrl(asset.path, currentAssistant?.id);
46900
+ if (!fileUrl || !downloadUrl) {
46845
46901
  import_antd147.message.warning("Please select a workspace and project first.");
46846
46902
  return;
46847
46903
  }
@@ -46850,11 +46906,12 @@ var ToolPanelFiles = () => {
46850
46906
  data: {
46851
46907
  file_id: asset.path,
46852
46908
  message: `Preview: ${asset.name || asset.path}`,
46853
- full_url: fileUrl
46909
+ full_url: fileUrl,
46910
+ download_url: downloadUrl
46854
46911
  },
46855
46912
  message: `Preview: ${asset.name || asset.path}`
46856
46913
  });
46857
- }, [getFileViewUrl, openSideApp, currentAssistant?.id]);
46914
+ }, [getFileViewUrl, getFileDownloadUrl, openSideApp, currentAssistant?.id]);
46858
46915
  const handleUploadFolder = (0, import_react171.useCallback)(async (folderName) => {
46859
46916
  if (!workspaceId || !projectId) {
46860
46917
  import_antd147.message.warning("Please select a workspace and project before uploading.");