Skip to content

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

Merge #4485

milind-soni69762d06564b
diff --cc src/components/ChatMarkdown.tsx
index c0bda891f5,a9a861cf85..bad379f8c8
--- a/src/components/ChatMarkdown.tsx
+++ b/src/components/ChatMarkdown.tsx
@@@ -28,7 -28,7 +28,8 @@@ import { MarkdownTable } from "./Markdo
import { CodeBlock, CodePlate, codeHash } from "./CodeBlock";
export { CodeBlock, HIGHLIGHT_CACHE_MAX, HIGHLIGHT_CACHE_MAX_CHARS, HIGHLIGHT_MAX_CHARS, type CodeBlockProps } from "./CodeBlock";
import { FilePreviewButton } from "./FilePreviewButton";
+import { SaveIconButton, useHtmlPreview } from "./HtmlFilePreview";
+ import { useRevealOriginalMenu } from "./RevealOriginalMenu";
const mermaidCache = new Map<string, string>();
const MERMAID_CACHE_MAX = 50;
@@@ -320,9 -320,10 +321,11 @@@ export function MermaidDiagram({ code }
// Security: no href at all, since an <a href="file://…"> reaches setWindowOpenHandler on a middle or modifier click,
// which calls shell.openExternal without main's containment check.
- function LocalFileLink({ filePath, name, children, message }: { filePath: string; name?: string; children?: ReactNode; message?: MessageAttachmentContext }) {
+ // source: the original a delivered copy came from, offered on right-click (Show in Finder) like in the gallery.
+ function LocalFileLink({ filePath, name, source, children, message }: { filePath: string; name?: string; source?: string; children?: ReactNode; message?: MessageAttachmentContext }) {
const save = useLocalFileSave(filePath, name, message);
+ const preview = useHtmlPreview(filePath, name ?? fileName(filePath), message);
+ const revealMenu = useRevealOriginalMenu();
if (!message) {
return <span title="Unavailable legacy file reference" className="break-words text-ink-secondary">{children}</span>;
}
@@@ -335,15 -336,14 +338,16 @@@
: null;
return (
- <span dir="ltr" className="inline-flex flex-wrap items-center gap-x-1.5 [unicode-bidi:isolate]">
+ <span dir="ltr" className="inline-flex flex-wrap items-center gap-x-1.5 [unicode-bidi:isolate]" {...revealMenu.targetProps(source)}>
+ {revealMenu.menu}
- <FilePreviewButton path={filePath} name={name ?? fileName(filePath)} message={message} />
+ {preview.html
+ ? <SaveIconButton name={name ?? fileName(filePath)} save={save} retryable={save.state === "failed" && !save.outsideWorkspace} />
+ : <FilePreviewButton path={filePath} name={name ?? fileName(filePath)} message={message} />}
<button
type="button"
- onClick={() => void save.save()}
- disabled={save.state === "saving"}
- title="Save a copy"
+ onClick={preview.html ? preview.show : () => void save.save()}
+ disabled={!preview.html && save.state === "saving"}
+ title={preview.html ? t("html.preview", { name: name ?? fileName(filePath) }) : "Save a copy"}
className="inline-flex items-center gap-1 break-words text-start text-accent underline decoration-accent/40 hover:decoration-accent disabled:cursor-wait"
>
{children}