Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge main into train/nov27-u2
milind-soni23e71362a97c
diff --cc src/components/AttachmentPreview.test.tsindex e9ff7b17b1,75c1b4157a..1212675f3b--- a/src/components/AttachmentPreview.test.ts+++ b/src/components/AttachmentPreview.test.ts@@@ -366,71 -366,39 +366,108 @@@ describe("image preview copy button", (});});+describe("image preview wheel", () => {+ const images = [+ { src: "/api/files/tall.png", name: "tall.png" },+ { src: "/api/files/next.png", name: "next.png" },+ ];++ it("zooms around the pointer, back to fit, and never scrolls the chat behind it", async () => {+ const chatWheel = vi.fn();+ const container = document.createElement("div");+ document.body.append(container);+ const root = createRoot(container);+ await act(async () => {+ root.render(createElement("div", { onWheel: chatWheel }, createElement(AttachmentPreviewDialog, { image: images[0]!, images, onClose: () => {} })));+ });+ const picture = () => document.querySelector<HTMLImageElement>("[role=dialog] img")!;+ const wheel = async (deltaY: number, target: Element = picture()) => {+ const event = new WheelEvent("wheel", { deltaY, bubbles: true, cancelable: true });+ // happy-dom 21's WheelEvent drops clientX and clientY from its init.+ Object.defineProperties(event, { clientX: { value: 120 }, clientY: { value: 80 } });+ await act(async () => { target.dispatchEvent(event); });+ return event;+ };+ const zoom = () => {+ const [x, y, scale] = (/^translate\((\S+)px, (\S+)px\) scale\((\S+)\)$/.exec(picture().style.transform) ?? []).slice(1).map(Number);+ return { x, y, scale };+ };+ try {+ const zoomIn = await wheel(-200);+ expect(zoomIn.defaultPrevented).toBe(true);+ const { x, y, scale } = zoom();+ expect(scale).toBeCloseTo(Math.E);+ expect((120 - x!) / scale!).toBeCloseTo(120);+ expect((80 - y!) / scale!).toBeCloseTo(80);++ expect((await wheel(400)).defaultPrevented).toBe(true);+ expect(picture().style.transform).toBe("");++ expect((await wheel(-200, document.querySelector("[role=dialog] header")!)).defaultPrevented).toBe(true);+ expect(picture().style.transform).toBe("");++ const beside = picture().parentElement!;+ expect((await wheel(-200, beside)).defaultPrevented).toBe(true);+ expect(picture().style.transform).toBe("");+ await wheel(-200);+ await wheel(400, beside);+ expect(picture().style.transform).toBe("");++ await wheel(-200);+ await act(async () => { window.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight" })); });+ expect(picture().alt).toBe("next.png");+ expect(picture().style.transform).toBe("");++ await wheel(-200);+ expect(picture().style.transform).not.toBe("");+ const replaced = [images[0]!, { src: "/api/files/replaced.png", name: "replaced.png" }];+ await act(async () => {+ root.render(createElement("div", { onWheel: chatWheel }, createElement(AttachmentPreviewDialog, { image: replaced[0]!, images: replaced, onClose: () => {} })));+ });+ expect(picture().alt).toBe("replaced.png");+ expect(picture().style.transform).toBe("");++ expect(chatWheel).not.toHaveBeenCalled();+ } finally {+ act(() => root.unmount());+ container.remove();+ }+ });+});+++ describe("opening a single outside-workspace file when permitted by owner", () => {+ it("preserves canOpenOutside on outside_workspace errors and omits listFolder on retry", async () => {+ const fetch = vi.fn()+ .mockResolvedValueOnce(new Response(JSON.stringify({+ error: "the linked file is outside this conversation's workspace",+ code: "outside_workspace",+ canOpenOutside: true,+ }), { status: 403, headers: { "content-type": "application/json" } }))+ .mockResolvedValueOnce(new Response(new Blob(["hello"], { type: "text/plain" }), { status: 200 }));+ vi.stubGlobal("fetch", fetch);+ vi.stubGlobal("URL", { createObjectURL: vi.fn(() => "blob:test"), revokeObjectURL: vi.fn() });+ const seen: { current: ReturnType<typeof useLocalFileSave> | null } = { current: null };+ const Probe = () => {+ seen.current = useLocalFileSave("/outside/notes.md", "notes.md", { threadId: "t1", messageId: "m1" });+ return null;+ };+ const root = createRoot(document.createElement("div"));+ try {+ await act(async () => { root.render(createElement(Probe)); });+ await act(async () => { await seen.current!.save(); });+ expect(seen.current!.state).toBe("failed");+ expect(seen.current!.outsideWorkspace).toBe(true);+ expect(seen.current!.canOpenOutside).toBe(true);++ await act(async () => { await seen.current!.save({ allowOutsideWorkspace: true }); });+ expect(seen.current!.state).toBe("saved");+ expect(JSON.parse(String(fetch.mock.calls[1]![1]!.body))).toEqual({+ path: "/outside/notes.md",+ allowOutsideWorkspace: true,+ });+ } finally {+ await act(async () => { root.unmount(); });+ vi.unstubAllGlobals();+ }+ });+ });diff --cc src/components/AttachmentPreview.tsxindex 8a195dfd5b,e6c06fe4d0..abf19bf6dc--- a/src/components/AttachmentPreview.tsx+++ b/src/components/AttachmentPreview.tsx@@@ -31,9 -36,10 +29,11 @@@ import { serverErrorText } from "@/lib/import { CopyImageButton } from "./CopyImageButton";import { FilePreviewButton } from "./FilePreviewButton";import { chipNameAction, SaveIconButton, useHtmlPreview } from "./HtmlFilePreview";- import { ImageLoading } from "./ImageLoading"; import { openLinkedFolder } from "./RevealOriginalMenu"; import { serverFetch } from "@/lib/relay-server";+ import { ImageLoading } from "./ImageLoading"; import { OutsideWorkspaceFile } from "./OutsideWorkspacePreview"; import { openLinkedFolder } from "./RevealOriginalMenu"; import { serverFetch } from "@/lib/relay-server";+import { usePreviewZoom } from "./preview-zoom";+ export { OutsideWorkspaceFile };+export interface PreviewImage {src: string;name: string;diff --cc src/components/ChatMarkdown.tsxindex 8cdb6899be,8a1745d3a5..35ec2b6835--- a/src/components/ChatMarkdown.tsx+++ b/src/components/ChatMarkdown.tsx@@@ -438,9 -438,13 +438,13 @@@ function LocalFileLink({ filePath, show{save.state === "failed" ? saveFailureText(save) : label}</span>)}- {save.state === "failed" && save.outsideWorkspace && !revealOnClick && (+ {save.state === "failed" && save.outsideWorkspace && (!revealOnClick || save.canOpenOutside) && (- <span className="inline-flex flex-wrap items-center gap-x-1.5 text-[12px]">+ <span className="inline-flex max-w-full min-w-0 flex-wrap items-center gap-x-1.5 text-[12px]">- <OutsideWorkspaceFile filePath={shownPath} />+ <OutsideWorkspaceFile+ filePath={shownPath}+ onOpenOutside={save.canOpenOutside ? () => void save.save({ allowOutsideWorkspace: true }) : undefined}+ openOutsideLabel={t("attach.saveOutsideFile")}+ /></span>)}{save.folder && <MessageFolderFiles folderPath={filePath} listing={save.folder} message={message} />}diff --cc src/components/OutsideWorkspacePreview.tsxindex 786b19c72f,43655de02f..d9bcffaa69--- a/src/components/OutsideWorkspacePreview.tsx+++ b/src/components/OutsideWorkspacePreview.tsx@@@ -1,10 -1,74 +1,74 @@@- import { OutsideWorkspaceFile } from "./AttachmentPreview";- import { REVEALABLE_PATH, revealBridge } from "@/lib/reveal-host-path";+ import { useState } from "react";+ import { FolderOpen } from "lucide-react";++ import { REVEALABLE_PATH, revealBridge, revealHostPath, revealProblemText } from "@/lib/reveal-host-path";import { t } from "@/lib/i18n";+ export function OutsideWorkspaceFile({+ filePath,+ standalone = false,+ onOpenOutside,+ openOutsideLabel,+ }: {+ filePath: string;+ standalone?: boolean;+ onOpenOutside?: () => void;+ openOutsideLabel?: string;+ }) {+ const [problem, setProblem] = useState("");+ const reveal = revealBridge();+ const openButton = onOpenOutside ? (+ <button+ type="button"+ onClick={onOpenOutside}- className={standalone ? "ui-button touch:min-h-10" : "inline-flex items-center gap-1 text-accent underline decoration-accent/40 hover:decoration-accent"}++ className={standalone ? "ui-button touch:min-h-10" : "inline-flex max-w-full min-w-0 items-center gap-1 text-accent underline decoration-accent/40 hover:decoration-accent"}+ >+ {openOutsideLabel ?? t("attach.openOutsideFile")}+ </button>+ ) : null;+ if (!reveal || !REVEALABLE_PATH.test(filePath)) {+ const pathCode = (+ <code title={t("attach.outsideWorkspacePath")} className="select-all whitespace-pre-wrap break-all text-ink">+ {filePath}+ </code>+ );+ if (!openButton) return pathCode;+ return (+ <>+ {openButton}+ {pathCode}+ </>+ );+ }+ const show = async () => {+ setProblem("");+ const result = await revealHostPath(filePath);+ const text = revealProblemText(result);+ if (text) setProblem(text);+ };+ return (+ <>+ {openButton}+ <button+ type="button"+ onClick={() => void show()}+ title={filePath}- className={standalone ? "ui-button touch:min-h-10" : "inline-flex items-center gap-1 text-accent underline decoration-accent/40 hover:decoration-accent"}++ className={standalone ? "ui-button touch:min-h-10" : "inline-flex max-w-full min-w-0 items-center gap-1 text-accent underline decoration-accent/40 hover:decoration-accent"}+ >+ <FolderOpen size={standalone ? 14 : 12} className="shrink-0" aria-hidden="true" />+ {t("attach.showInFolder")}+ </button>+ {problem && <span role="alert" className="text-danger">{problem}</span>}+ </>+ );+ }+export const refusedAsOutsideWorkspace = (error: unknown): boolean => (error as { code?: unknown } | null)?.code === "outside_workspace";- export function OutsideWorkspacePreview({ filePath }: { filePath: string }) {+ export const canOpenOutsideWorkspace = (error: unknown): boolean =>+ refusedAsOutsideWorkspace(error) && (error as { canOpenOutside?: unknown } | null)?.canOpenOutside === true;++ export function OutsideWorkspacePreview({ filePath, onOpenOutside }: { filePath: string; onOpenOutside?: () => void }) {const absolute = REVEALABLE_PATH.test(filePath) || /^(?:\\\\|\/\/)/.test(filePath);const revealable = Boolean(revealBridge()) && REVEALABLE_PATH.test(filePath);return (