Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Open the containing folder for local links in messages

guylfeaedd9e78ae27
diff --git a/src/components/AttachmentGallery.tsx b/src/components/AttachmentGallery.tsx
index c5b71b4efc..7b905ff868 100644
--- a/src/components/AttachmentGallery.tsx
+++ b/src/components/AttachmentGallery.tsx
@@ -472,7 +472,8 @@ export function AttachmentGallery({ images = [], files = [], originals, message,
if (seen.has(key)) continue;
seen.add(key);
const trusted = Boolean(message && (file.private || file.linked));
- result.push({ key, source: originalOf(originals, file.path), kind: trusted && isVideoAttachment(file.path) ? "video" : trusted && isAudioAttachment(file.path) ? "audio" : "file", file });
+ const source = originalOf(originals, file.path) ?? (message && file.linked ? key : undefined);
+ result.push({ key, source, kind: trusted && isVideoAttachment(file.path) ? "video" : trusted && isAudioAttachment(file.path) ? "audio" : "file", file });
}
return result;
}, [images, files, originals, message]);
diff --git a/src/components/AttachmentPreview.test.ts b/src/components/AttachmentPreview.test.ts
index c922a937cd..0e510f3c34 100644
--- a/src/components/AttachmentPreview.test.ts
+++ b/src/components/AttachmentPreview.test.ts
@@ -172,16 +172,16 @@ describe("attachment preview surfaces", () => {
});
});
-describe("Show in folder for a file outside the workspace", () => {
+describe("Open containing folder for a file outside the workspace", () => {
const render = (filePath: string) => renderToStaticMarkup(createElement(OutsideWorkspaceFile, { filePath }));
it("offers the reveal only for an absolute local path, and only in the local desktop app", () => {
vi.stubGlobal("window", { ogb: { revealInFolder: vi.fn(), remoteClient: { active: false } } });
try {
- expect(render("/Users/maus/_draft/ollama-gen.js")).toContain("Show in folder");
- expect(render("C:\\Users\\Maus\\_draft\\ollama-gen.js")).toContain("Show in folder");
+ expect(render("/Users/maus/_draft/ollama-gen.js")).toContain("Open containing folder");
+ expect(render("C:\\Users\\Maus\\_draft\\ollama-gen.js")).toContain("Open containing folder");
for (const filePath of ["_draft/ollama-gen.js", "\\\\server\\share\\ollama-gen.js"]) {
- expect(render(filePath)).not.toContain("Show in folder");
+ expect(render(filePath)).not.toContain("Open containing folder");
expect(render(filePath)).toContain(`>${filePath}</code>`);
}
} finally {
diff --git a/src/components/ChatMarkdown.test.ts b/src/components/ChatMarkdown.test.ts
index 71236c0cc9..d96df1b0bf 100644
--- a/src/components/ChatMarkdown.test.ts
+++ b/src/components/ChatMarkdown.test.ts
@@ -948,13 +948,13 @@ describe("ChatMarkdown attachments", () => {
};
const revealInFolder = vi.fn(async () => "shown" as const);
- it("offers Show in folder in the local desktop app, without printing the path", () => {
+ it("offers Open containing folder in the local desktop app, without printing the path", () => {
vi.stubGlobal("window", { ogb: { revealInFolder, remoteClient: { active: false } } });
try {
const html = render(true);
expect(html).toContain("This file is outside this chat&#x27;s working folder, so it can&#x27;t be saved from here");
expect(html).not.toContain("the linked file is outside");
- expect(html).toContain("Show in folder");
+ expect(html).toContain("Open containing folder");
expect(html).not.toContain("<code");
} finally {
vi.unstubAllGlobals();
@@ -965,7 +965,7 @@ describe("ChatMarkdown attachments", () => {
vi.stubGlobal("window", { ogb: { revealInFolder, remoteClient: { active: true } } });
try {
const html = render(true);
- expect(html).not.toContain("Show in folder");
+ expect(html).not.toContain("Open containing folder");
expect(html).toMatch(/<code[^>]*select-all[^>]*>C:\\Users\\Maus\\_draft\\ollama-gen\.js<\/code>/);
} finally {
vi.unstubAllGlobals();
@@ -1021,7 +1021,7 @@ describe("ChatMarkdown attachments", () => {
const root = createRoot(host);
try {
await act(async () => root.render(createElement(ChatMarkdown, { text, message: { threadId: "thread-1", messageId: "message-1" } })));
- const show = [...host.querySelectorAll("button")].find((button) => button.textContent === "Show in folder")!;
+ const show = [...host.querySelectorAll("button")].find((button) => button.textContent === "Open containing folder")!;
await act(async () => show.click());
expect(reveal).toHaveBeenCalledWith(folder);
} finally {
@@ -1038,7 +1038,7 @@ describe("ChatMarkdown attachments", () => {
try {
const html = render(false);
expect(html).toContain("the linked file is outside this conversation&#x27;s workspace");
- expect(html).not.toContain("Show in folder");
+ expect(html).not.toContain("Open containing folder");
expect(html).not.toContain(filePath);
} finally {
vi.unstubAllGlobals();
diff --git a/src/components/ChatMarkdown.tsx b/src/components/ChatMarkdown.tsx
index 1e64a4cf38..a7de2e563b 100644
--- a/src/components/ChatMarkdown.tsx
+++ b/src/components/ChatMarkdown.tsx
@@ -674,12 +674,12 @@ function MarkdownLink({ href, children, ...rest }: { href?: string; children?: R
const localPath = localFilePath(href);
if (localPath) {
const copy = delivered && Object.hasOwn(delivered, fileName(localPath)) ? delivered[fileName(localPath)] : undefined;
- const source = copy && originals && Object.hasOwn(originals, copy) ? originals[copy] : undefined;
// localFilePath already decodes a file:// URL; a plain path link is still encoded and gets the server's single decode.
// A delivered copy keeps its literal name.
const shownPath = copy ?? (/^file:\/\//i.test(href) ? localPath : decodedLinkPath(localPath));
+ const original = copy && originals && Object.hasOwn(originals, copy) ? originals[copy] : undefined;
const shownName = copy ? fileName(localPath) : fileName(shownPath);
- return <LocalFileLink filePath={copy ?? localPath} shownPath={shownPath} shownName={shownName} name={copy ? fileName(localPath) : undefined} source={source} message={message}>{children}</LocalFileLink>;
+ return <LocalFileLink filePath={copy ?? localPath} shownPath={shownPath} shownName={shownName} name={copy ? fileName(localPath) : undefined} source={copy ? original : shownPath} message={message}>{children}</LocalFileLink>;
}
if (!/^https?:\/\//i.test(href)) {
return (
diff --git a/src/components/RevealOriginalMenu.dom.test.ts b/src/components/RevealOriginalMenu.dom.test.ts
index 791d6bb654..c68159c230 100644
--- a/src/components/RevealOriginalMenu.dom.test.ts
+++ b/src/components/RevealOriginalMenu.dom.test.ts
@@ -3,6 +3,7 @@ import { act, createElement } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, expect, it, vi } from "vitest";
import { useRevealOriginalMenu } from "./RevealOriginalMenu";
+import { MessageAttachmentGallery } from "./AttachmentGallery";
import { ChatMarkdown } from "./ChatMarkdown";
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -68,8 +69,37 @@ it("offers the original on a file the reply links inline instead of showing it i
}));
const link = [...document.querySelectorAll("span[dir=ltr]")].at(-1)!;
await openMenu(link);
- expect(menuButton()?.textContent).toBe("Show in folder");
+ expect(menuButton()?.textContent).toBe("Open containing folder");
await act(async () => { menuButton()!.click(); });
expect(revealInFolder).toHaveBeenCalledWith(ORIGINAL);
act(() => root.unmount());
});
+
+it("reveals an ordinary Windows file link without a delivered attachment", async () => {
+ const revealInFolder = vi.fn(async () => "shown");
+ (window as { ogb?: unknown }).ogb = { platform: "win32", revealInFolder };
+ const root = await mount(createElement(ChatMarkdown, {
+ text: "[report](file:///C:/My%20Files/report.pdf)",
+ message: { threadId: "t1", messageId: "m1" },
+ }));
+ const link = [...document.querySelectorAll("button")].find(button => button.textContent === "report")!;
+ await openMenu(link);
+ expect(menuButton()?.textContent).toBe("Open containing folder");
+ await act(async () => { menuButton()!.click(); });
+ expect(revealInFolder).toHaveBeenCalledWith("C:/My Files/report.pdf");
+ act(() => root.unmount());
+});
+
+it("reveals the linked file from its gallery chip", async () => {
+ const revealInFolder = vi.fn(async () => "shown");
+ (window as { ogb?: unknown }).ogb = { platform: "linux", revealInFolder };
+ const root = await mount(createElement(MessageAttachmentGallery, {
+ text: "[report](/home/me/Reports/quarter%201.pdf)",
+ message: { threadId: "t1", messageId: "m1" },
+ }));
+ const chip = document.querySelector('button[aria-label="Save a copy of quarter 1.pdf"]')!;
+ await openMenu(chip);
+ await act(async () => { menuButton()!.click(); });
+ expect(revealInFolder).toHaveBeenCalledWith("/home/me/Reports/quarter 1.pdf");
+ act(() => root.unmount());
+});
diff --git a/src/components/RevealOriginalMenu.test.ts b/src/components/RevealOriginalMenu.test.ts
index 0eaf853bfc..245401bdfa 100644
--- a/src/components/RevealOriginalMenu.test.ts
+++ b/src/components/RevealOriginalMenu.test.ts
@@ -25,8 +25,8 @@ describe("Show in Finder for the original of a bot's attachment", () => {
it("says Finder on a Mac and folder elsewhere", () => {
expect(revealOriginalLabel("darwin")).toBe("Show in Finder");
- expect(revealOriginalLabel("win32")).toBe("Show in folder");
- expect(revealOriginalLabel("linux")).toBe("Show in folder");
+ expect(revealOriginalLabel("win32")).toBe("Open containing folder");
+ expect(revealOriginalLabel("linux")).toBe("Open containing folder");
});
it("shows the original, and says so when it moved or is gone instead of falling back to the copy", async () => {
diff --git a/src/locales/en.json b/src/locales/en.json
index 21d8d49d08..70d55bccea 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -3202,7 +3202,7 @@
"attach.retrySaveAria": "Retry saving {name}",
"attach.downloading": "Downloading…",
"attach.downloaded": "Downloaded",
- "attach.showInFolder": "Show in folder",
+ "attach.showInFolder": "Open containing folder",
"attach.showInFinder": "Show in Finder",
"attach.originalMissing": "The original file was moved or deleted",
"attach.folderEmpty": "This folder has no files to open here",