Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge pull request #6747 from guylfe/fix/preview-large-files
milind-soni4d328a88f679
diff --cc src/components/HtmlFilePreview.tsxindex fbca93fc98,ef50f36ad1..d9cefd40f5--- a/src/components/HtmlFilePreview.tsx+++ b/src/components/HtmlFilePreview.tsx@@@ -1,15 -1,10 +1,14 @@@import { Component, lazy, Suspense, useEffect, useRef, useState, type ReactNode } from "react";import { Check, Code2, Download, ExternalLink, Eye, LoaderCircle, RotateCcw } from "lucide-react";import { requestMessageFile, useLocalFileSave, type MessageAttachmentContext } from "./AttachmentPreview";+import { OutsideWorkspacePreview, refusedAsOutsideWorkspace } from "./OutsideWorkspacePreview";import { TableDialog } from "./RichTable";-import { readTableResponse } from "./TableFilePreview";+import { readTableResponse, TableFileContent } from "./TableFilePreview";+import { cn } from "@/lib/cn";+import { useFileBesideChat, type FilePreview } from "@/lib/file-preview";import { t } from "@/lib/i18n";+import { tableDelimiter } from "@/lib/table-data";-- export const HTML_PREVIEW_MAX_BYTES = 2 * 1024 * 1024;+ import { PREVIEW_MAX_BYTES } from "../../shared/upload-limits";/** Security: the frame may draw what the file carries inline, and fetch nothing at all. */export const HTML_PREVIEW_CSP = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; media-src data:";@@@ -159,10 -140,9 +158,10 @@@ function HtmlFileContent({ path, shownP})();return () => controller.abort();}, [path, message.threadId, message.messageId, attempt]);+ if (error === "outside") return <OutsideWorkspacePreview filePath={shownPath} />;- if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="mb-3 text-ink-secondary">{typeof error === "object" ? t("html.refused", { reason: error.reason }) : t(error === "size" ? "html.tooLarge" : "html.loadFailed")}</p><button type="button" className="rounded-lg border border-hairline px-3 py-2 hover:bg-raised" onClick={() => setAttempt(attempt + 1)}>{t("chat.retry")}</button></div>;+ if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="mb-3 text-ink-secondary">{typeof error === "object" ? t("html.refused", { reason: error.reason }) : t(error === "size" ? "attach.fileTooLarge" : "html.loadFailed")}</p><button type="button" className="rounded-lg border border-hairline px-3 py-2 hover:bg-raised" onClick={() => setAttempt(attempt + 1)}>{t("chat.retry")}</button></div>;if (source === null) return <div role="status" className="flex items-center justify-center gap-2 p-12 text-sm text-ink-secondary"><LoaderCircle size={16} className="animate-spin" />{t("html.loading")}</div>;- return <div className="flex flex-col gap-2">+ return <div className={cn("flex flex-col gap-2", fill && "min-h-0 flex-1")}><div className="flex items-center justify-end gap-1"><button type="button" className="table-action" aria-pressed={showSource} aria-label={t(showSource ? "html.rendered" : "html.source")} title={t(showSource ? "html.rendered" : "html.source")} onClick={() => setShowSource(!showSource)}>{showSource ? <Eye size={14} /> : <Code2 size={14} />}</button><button type="button" className="table-action" aria-label={t("html.reload")} title={t("html.reload")} onClick={() => setAttempt(attempt + 1)}><RotateCcw size={14} /></button>diff --cc src/components/MarkdownFilePreview.tsxindex cd23aea9c3,7984161211..016cca562e--- a/src/components/MarkdownFilePreview.tsx+++ b/src/components/MarkdownFilePreview.tsx@@@ -1,14 -1,12 +1,15 @@@import { useEffect, useState } from "react";import { Code2, Download, Eye, LoaderCircle, RotateCcw } from "lucide-react";import { requestMessageFile, useLocalFileSave, type MessageAttachmentContext } from "./AttachmentPreview";+import { OutsideWorkspacePreview, refusedAsOutsideWorkspace } from "./OutsideWorkspacePreview";import { ChatMarkdown } from "./ChatMarkdown";+import { previewHeight } from "./HtmlFilePreview";import { readTableResponse } from "./TableFilePreview";+import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";+ import { PREVIEW_MAX_BYTES } from "../../shared/upload-limits";- export const MARKDOWN_PREVIEW_MAX_BYTES = 2 * 1024 * 1024;+ const AUTO_RENDER_MAX_CHARS = 2 * 1024 * 1024;/** A Markdown file in a message, drawn the way the chat draws a reply. Security: no message context is passed on, so* paths written in the file stay plain text instead of becoming links that fetch other files. */@@@ -42,10 -42,9 +46,10 @@@ export default function MarkdownFileCon}, [path, message.threadId, message.messageId, attempt]);// Save and Retry stay on screen while loading too, so a stalled request never leaves only a spinner; they wrap so a long name can't push Retry off a narrow dialog.const recovery = <><div className="mt-3 flex flex-wrap justify-center gap-2"><button type="button" className="inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-lg border border-hairline px-3 py-2 hover:bg-raised" disabled={save.state === "saving"} onClick={() => void save.save()}><Download size={14} className="shrink-0" /><span className="min-w-0 break-all">{t("attach.saveAria", { name })}</span></button><button type="button" className="rounded-lg border border-hairline px-3 py-2 hover:bg-raised" onClick={() => setAttempt(attempt + 1)}>{t("chat.retry")}</button></div>{save.state === "failed" && <p role="alert" className="mt-2 text-[12px] text-danger">{save.reason}</p>}</>;+ if (error === "outside") return <OutsideWorkspacePreview filePath={shownPath} />;- if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="text-ink-secondary">{typeof error === "object" ? t("markdown.refused", { reason: error.reason }) : t(error === "size" ? "markdown.tooLarge" : error === "encoding" ? "markdown.notText" : "markdown.loadFailed")}</p>{recovery}</div>;+ if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="text-ink-secondary">{typeof error === "object" ? t("markdown.refused", { reason: error.reason }) : t(error === "size" ? "attach.fileTooLarge" : error === "encoding" ? "markdown.notText" : "markdown.loadFailed")}</p>{recovery}</div>;if (source === null) return <div className="p-12 text-center text-sm text-ink-secondary"><span role="status" className="inline-flex items-center gap-2"><LoaderCircle size={16} className="animate-spin" />{t("markdown.loading")}</span>{recovery}</div>;- return <div className="flex flex-col gap-2">+ return <div className={cn("flex flex-col gap-2", fill && "min-h-0 flex-1")}><div className="flex items-center justify-end gap-1"><button type="button" className="table-action" aria-pressed={showSource} aria-label={t(showSource ? "markdown.rendered" : "html.source")} title={t(showSource ? "markdown.rendered" : "html.source")} onClick={() => setShowSource(!showSource)}>{showSource ? <Eye size={14} /> : <Code2 size={14} />}</button><button type="button" className="table-action" aria-label={t("html.reload")} title={t("html.reload")} onClick={() => setAttempt(attempt + 1)}><RotateCcw size={14} /></button>