Skip to content

Commit e0921fe

Browse files
committed
add show file widget to the
1 parent 36cdb1e commit e0921fe

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

helpers/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ For better results, you can specify the region parameter to get results from a s
139139
dependencies: [
140140
{
141141
name: "e2b_code_interpreter",
142-
version: "^0.0.11b38",
142+
version: "0.0.11b38",
143143
},
144144
],
145145
supportedFrameworks: ["fastapi", "express", "nextjs"],

templates/types/streaming/nextjs/app/components/ui/chat/chat-message/chat-sources.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ export function SourceNumberButton({
9797
);
9898
}
9999

100-
function DocumentInfo({ document }: { document: Document }) {
101-
if (!document.sources.length) return null;
100+
export function DocumentInfo({ document }: { document: Document }) {
102101
const { url, sources } = document;
103-
const fileName = sources[0].metadata.file_name as string | undefined;
102+
let fileName: string | undefined;
103+
if (sources.length > 0) {
104+
fileName = sources[0].metadata.file_name as string | undefined;
105+
} else {
106+
// Extract filename from URL if sources is empty
107+
const urlParts = url.split("/");
108+
fileName = urlParts[urlParts.length - 1];
109+
}
104110
const fileExt = fileName?.split(".").pop();
105111
const fileImage = fileExt ? FileIcon[fileExt as DocumentFileType] : null;
106112

templates/types/streaming/nextjs/app/components/ui/chat/chat-message/markdown.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import remarkGfm from "remark-gfm";
66
import remarkMath from "remark-math";
77

88
import { SourceData } from "..";
9-
import { SourceNumberButton } from "./chat-sources";
9+
import { useClientConfig } from "../hooks/use-config";
10+
import { DocumentInfo, SourceNumberButton } from "./chat-sources";
1011
import { CodeBlock } from "./codeblock";
1112

1213
const MemoizedReactMarkdown: FC<Options> = memo(
@@ -78,6 +79,7 @@ export default function Markdown({
7879
sources?: SourceData;
7980
}) {
8081
const processedContent = preprocessContent(content, sources);
82+
const { backend } = useClientConfig();
8183

8284
return (
8385
<MemoizedReactMarkdown
@@ -119,6 +121,17 @@ export default function Markdown({
119121
);
120122
},
121123
a({ href, children }) {
124+
// If href starts with http://localhost:8000/api/files, render DocumentPreview
125+
if (href?.startsWith(backend + "/api/files")) {
126+
return (
127+
<DocumentInfo
128+
document={{
129+
url: href,
130+
sources: [],
131+
}}
132+
/>
133+
);
134+
}
122135
// If a text link starts with 'citation:', then render it as a citation reference
123136
if (
124137
Array.isArray(children) &&

0 commit comments

Comments
 (0)