Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Thread tabs: one frame with the sidebar, the chat as a card, every control on one centre line (#7330)
Milind Soni5fec9298297f
diff --git a/src/components/HeaderThreadTabs.dom.test.ts b/src/components/HeaderThreadTabs.dom.test.tsindex bc6cfc53e0..5dc8d5db02 100644--- a/src/components/HeaderThreadTabs.dom.test.ts+++ b/src/components/HeaderThreadTabs.dom.test.ts@@ -48,7 +48,7 @@ describe("thread tab strip", () => {it("lists pinned threads first, then by recent use, with the open one selected", () => {render(kiwi(FIVE, "launch"));- expect(tabs().map((element) => element.textContent)).toEqual(["Launch plan", "Weekly sales", "Invoice for Acme", "Berlin trip", "Call notes"]);+ expect(tabs().map((element) => element.querySelector("[data-tab-label] > span")?.textContent)).toEqual(["Launch plan", "Weekly sales", "Invoice for Acme", "Berlin trip", "Call notes"]);expect(tab("Launch plan").getAttribute("aria-selected")).toBe("true");expect(tab("Weekly sales").querySelector('[aria-label="Working"]')).not.toBeNull();expect(tab("Launch plan").querySelector('[aria-label="Pinned"]')).not.toBeNull();@@ -86,6 +86,14 @@ describe("thread tab strip", () => {expect(sent()).toEqual([expect.objectContaining({ type: "updateTask", threadId: "notes", patch: { archivedAt: expect.any(Number) } })]);});+ it("leads with the bot's avatar and name, which open its panel", () => {+ render(kiwi(FIVE, "launch"));+ const chip = document.querySelector<HTMLButtonElement>("[data-thread-tabs-bot]")!;+ expect(chip.textContent).toBe("Kiwi");+ act(() => chip.click());+ expect(sent()).toEqual([{ type: "toggleSettings", open: true }]);+ });+it("opens a tab on click and makes a new thread with +", () => {render(kiwi(FIVE, "launch"));act(() => tab("Berlin trip").click());diff --git a/src/components/HeaderThreadTabs.tsx b/src/components/HeaderThreadTabs.tsxindex e6be6e0dd7..8e27fa1dfc 100644--- a/src/components/HeaderThreadTabs.tsx+++ b/src/components/HeaderThreadTabs.tsx@@ -10,10 +10,10 @@ import { useStoreDispatch, useStoreSelector } from "@/state/store-select";import { BotAvatar } from "./Avatar";import { reducedMotion } from "./MenuMotion";import { botShowsTabs, neighbourOf, openTabId, showsTabs, threadTabs, type ThreadTab } from "./thread-tabs";-import { useTabMotion } from "./thread-tab-motion";+import { useSlidingIndicator, useTabMotion } from "./thread-tab-motion";import { UndoToast, useUndoToast } from "./UndoToast";-const TAB = "thread-tab group/tab relative flex h-9 min-w-24 max-w-42 shrink items-center rounded-t-xl ps-3 pe-1 text-[13px] leading-[18px] outline-none transition-colors duration-[120ms] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";+const TAB = "thread-tab group/tab relative z-[1] flex h-8.5 min-w-24 max-w-42 shrink items-center rounded-t-lg ps-3 pe-1 pb-0.5 text-[13px] leading-[18px] outline-none transition-colors duration-[120ms] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";const CLOSE = "pointer-events-none ms-1 flex size-5 shrink-0 items-center justify-center rounded-full text-ink-tertiary opacity-0 transition-opacity duration-[120ms] hover:bg-ink/[0.08] hover:text-ink group-hover/tab:pointer-events-auto group-hover/tab:opacity-100 group-focus-within/tab:pointer-events-auto group-focus-within/tab:opacity-100 touch:pointer-events-auto touch:opacity-100 motion-reduce:transition-none";const FADE = 24;@@ -51,9 +51,11 @@ export function edgeFade(element: HTMLElement, fade = FADE): string | undefinedfunction Strip({ bot, tabs }: { bot: Bot; tabs: ThreadTab[] }) {const dispatch = useStoreDispatch();const panelOpen = useStoreSelector((state) => state.settingsOpen);+ const panelBeside = useStoreSelector((state) => state.settingsOpen || state.computerOpen || state.inspectorOpen);const scroller = useRef<HTMLDivElement>(null);const { shown, entering } = useTabMotion(tabs, scroller);const active = openTabId(bot);+ const indicator = useSlidingIndicator(scroller, active);const [renaming, setRenaming] = useState<string | null>(null);const [draft, setDraft] = useState("");const finishing = useRef(false);@@ -139,15 +141,18 @@ function Strip({ bot, tabs }: { bot: Bot; tabs: ThreadTab[] }) {};return (- <div data-thread-tabs={bot.id} className="flex h-9 min-w-0 flex-1 items-center max-md:hidden">+ <div data-thread-tabs={bot.id} data-panel-beside={panelBeside ? "" : undefined} className="flex h-full min-w-0 flex-1 items-end max-md:hidden"><button type="button" data-thread-tabs-bot aria-label={t("chat.openProfileAria", { name: bot.name })} title={t("chat.openBotPanel")} aria-expanded={panelOpen}onClick={() => dispatch({ type: "toggleSettings", open: !panelOpen })}- className="flex size-7 shrink-0 items-center justify-center rounded-full transition-colors duration-[120ms] hover:bg-ink/[0.06] active:bg-ink/[0.08] motion-reduce:transition-none">- <BotAvatar bot={bot} size={16} />+ className="mb-0.5 flex h-8 max-w-40 shrink-0 items-center gap-1.5 rounded-full ps-1.5 pe-2.5 text-[13px] font-medium leading-[18px] text-ink outline-none transition-colors duration-[120ms] hover:bg-ink/[0.06] active:bg-ink/[0.08] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none">+ <BotAvatar bot={bot} size={20} />+ <span dir="auto" className="min-w-0 truncate">{bot.name}</span></button><div ref={scroller} role="tablist" aria-label={t("task.namedList", { name: bot.name })} onKeyDown={onKey} onScroll={measure} onWheel={scrollSideways}style={{ maskImage: fade, WebkitMaskImage: fade }}- className="flex h-9 min-w-0 items-end overflow-x-auto overflow-y-hidden px-3 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">+ className="relative flex h-full min-w-0 items-end gap-0.5 overflow-x-auto overflow-y-hidden px-2.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">+ {indicator.box && <span aria-hidden="true" data-tab-indicator data-glide={indicator.glide ? "" : undefined} className="thread-tab-indicator"+ style={{ transform: `translateX(${indicator.box.left}px)`, width: indicator.box.width }} />}{shown.map((tab) => {const selected = tab.threadId === active && !tab.leaving;const title = tab.draft ? t("task.newShort") : localizedTaskTitle(tab.title);@@ -157,7 +162,7 @@ function Strip({ bot, tabs }: { bot: Bot; tabs: ThreadTab[] }) {data-entering={entering.has(tab.threadId) ? "" : undefined} data-leaving={tab.leaving ? "" : undefined} aria-hidden={tab.leaving || undefined}onClick={() => { if (renaming !== tab.threadId) open(tab); }} onDoubleClick={() => startRename(tab)}onMouseDown={(event) => { if (event.button === 1) event.preventDefault(); }} onAuxClick={(event) => onAuxClick(event, tab)}- className={cn(TAB, selected ? "text-ink" : "cursor-default text-ink-secondary hover:text-ink")}>+ className={cn(TAB, selected ? "font-medium text-ink" : "cursor-default text-ink-secondary hover:text-ink")}>{renaming === tab.threadId ? (<input autoFocus dir="auto" value={draft} maxLength={80} aria-label={t("task.renameAria")}onFocus={(event) => event.currentTarget.select()} onChange={(event) => setDraft(event.target.value)}@@ -170,8 +175,11 @@ function Strip({ bot, tabs }: { bot: Bot; tabs: ThreadTab[] }) {) : (<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">{tab.working ? <span role="img" aria-label={t("chat.activity.working")} className="size-1.5 shrink-0 animate-pulse rounded-full bg-success motion-reduce:animate-none" />- : tab.pinned ? <Pin size={12} role="img" aria-label={t("task.pinned")} className="shrink-0 text-ink-tertiary" /> : null}- <span dir="auto" className="min-w-0 truncate">{title}</span>+ : tab.pinned ? <Pin size={10} role="img" aria-label={t("task.pinned")} className="shrink-0 text-ink-tertiary" /> : null}+ <span data-tab-label className="grid min-w-0">+ <span dir="auto" className="col-start-1 row-start-1 truncate">{title}</span>+ <span aria-hidden="true" className="invisible col-start-1 row-start-1 truncate font-medium">{title}</span>+ </span></span>)}{renaming === tab.threadId ? null : !closable ? <span aria-hidden="true" className="ms-1 size-5 shrink-0" /> : (@@ -187,7 +195,7 @@ function Strip({ bot, tabs }: { bot: Bot; tabs: ThreadTab[] }) {</div>{canWrite && (<button type="button" data-thread-tabs-new aria-label={t("task.newShort")} title={t("task.newShort")} onClick={() => dispatch({ type: "newTask", botId: bot.id })}- className="ms-0.5 flex size-7 shrink-0 items-center justify-center rounded-full text-ink-secondary transition-colors duration-[120ms] hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.08] motion-reduce:transition-none">+ className="mb-0.5 flex size-8 shrink-0 items-center justify-center rounded-full text-ink-secondary transition-colors duration-[120ms] hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.08] motion-reduce:transition-none"><Plus size={16} aria-hidden="true" /></button>)}diff --git a/src/components/thread-tab-motion.ts b/src/components/thread-tab-motion.tsindex dd1eb3fdeb..289b3c86ec 100644--- a/src/components/thread-tab-motion.ts+++ b/src/components/thread-tab-motion.ts@@ -70,3 +70,30 @@ export function useTabMotion<T extends MotionTab>(tabs: readonly T[], scroller:return { shown: withLeaving(tabs, leaving), entering };}++export type IndicatorBox = { left: number; width: number };++/**+ * Where the open tab's ground sits under the open tab, kept in step as tabs resize or move. It only glides once it has+ * been placed, so the strip's first paint has it in place.+ */+export function useSlidingIndicator(scroller: RefObject<HTMLElement | null>, activeId: string): { box: IndicatorBox | null; glide: boolean } {+ const [box, setBox] = useState<IndicatorBox | null>(null);+ const placed = useRef(false);+ useLayoutEffect(() => {+ const root = scroller.current;+ if (!root) return;+ const place = () => {+ const tab = root.querySelector<HTMLElement>(`[data-tab-id="${CSS.escape(activeId)}"]:not([data-leaving])`);+ const next = tab ? { left: tab.offsetLeft, width: tab.offsetWidth } : null;+ setBox((current) => (current?.left === next?.left && current?.width === next?.width ? current : next));+ };+ place();+ if (typeof ResizeObserver !== "function") return;+ const observer = new ResizeObserver(place);+ for (const tab of root.querySelectorAll("[data-tab-id]")) observer.observe(tab);+ return () => observer.disconnect();+ });+ useEffect(() => { if (box) placed.current = true; }, [box]);+ return { box, glide: placed.current && !reducedMotion() };+}diff --git a/src/styles.css b/src/styles.cssindex 6878b2c98e..491c4df9f9 100644--- a/src/styles.css+++ b/src/styles.css@@ -3909,37 +3909,62 @@ button:disabled.bg-danger {.burger-layer.burger-open { animation: burger-land 1100ms ease-out 180ms both; }@media (prefers-reduced-motion: reduce) { .burger-fold { transition: none; } }:root[data-reduced-motion="true"] .burger-fold { transition: none; }-/* Thread tabs: from tablet width up, the chat header becomes one band in the chat's ground with a touch of ink, whose- tabs replace the pill and stand on its bottom edge; the open tab is the chat's own ground, so it runs into the chat- below, and its foot curves out into the band on both sides. Separators sit between closed tabs only. */+/* Thread tabs, from tablet width up: the sidebar and the chat header's band are one frame in the sidebar's ground, and+ the chat is a card set into it, its top corners rounded where it meets the band (the right one square while a panel+ sits beside the chat). A hairline in the frame's edge colour runs along the card's top, round its corners and down+ the sidebar's side. The open tab's ground is the card's and slides between tabs; its foot curves out into the band.+ Separators sit only between two closed tabs, neither under the pointer. Every control in the band is 32px tall on+ the sidebar buttons' centre line, 10px apart as the sidebar's are, and the band's end inset mirrors the sidebar's. */@media (min-width: 768px) {- [data-chathead-tabs] { background-color: color-mix(in srgb, var(--color-ink) 4%, var(--color-app)); padding-top: 12px; padding-bottom: 0; }+ [data-chathead-tabs] {+ --chat-card-radius: var(--radius-xl);+ position: relative; padding-top: 12px; padding-bottom: 0;+ background: linear-gradient(var(--color-edge), var(--color-edge)) var(--chat-card-radius) 100% / calc(100% - 2 * var(--chat-card-radius)) 0.5px no-repeat, var(--color-panel);+ }[data-chathead-tabs="advanced"] { padding-top: 6px; }- [data-chathead-tabs] [data-chathead-row] { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; }+ [data-chathead-tabs]:has([data-panel-beside]) { background-size: calc(100% - var(--chat-card-radius)) 0.5px, auto; }+ [data-chathead-tabs]::before,+ [data-chathead-tabs]::after { content: ""; position: absolute; top: 100%; width: var(--chat-card-radius); height: var(--chat-card-radius); pointer-events: none; }+ [data-chathead-tabs]::before { left: 0; background: radial-gradient(circle at 100% 100%, transparent calc(var(--chat-card-radius) - 0.5px), var(--color-edge) calc(var(--chat-card-radius) - 0.5px), var(--color-edge) var(--chat-card-radius), var(--color-panel) calc(var(--chat-card-radius) + 0.5px)); }+ [data-chathead-tabs]::after { right: 0; background: radial-gradient(circle at 0 100%, transparent calc(var(--chat-card-radius) - 0.5px), var(--color-edge) calc(var(--chat-card-radius) - 0.5px), var(--color-edge) var(--chat-card-radius), var(--color-panel) calc(var(--chat-card-radius) + 0.5px)); }+ [data-chathead-tabs]:has([data-panel-beside])::after { display: none; }+ :root:has([data-chathead-tabs="simple"]) [data-sidebar] { border-image: linear-gradient(to bottom, transparent 60px, var(--color-edge) 60px) 1; }+ :root:has([data-chathead-tabs="advanced"]) [data-sidebar] { border-image: linear-gradient(to bottom, transparent 54px, var(--color-edge) 54px) 1; }+ [data-chathead-tabs] [data-chathead-row] { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; height: 100%; }[data-chathead-tabs] [data-chathead-identity] { grid-column: 2; justify-self: stretch; align-self: stretch; -webkit-app-region: drag !important; }[data-chathead-tabs] [data-chathead-identity] > :not([data-thread-tabs], [data-chathead-status]) { display: none; }[data-chathead-tabs="advanced"] [data-chathead-identity] { margin-inline-start: 8px; }- [data-chathead-tabs] [data-chathead-controls] { grid-column: 3; margin-inline-start: 8px; }-}-.thread-tab[aria-selected="true"] { background: var(--color-app); }-.thread-tab[aria-selected="true"]::before,-.thread-tab[aria-selected="true"]::after {- content: ""; position: absolute; bottom: 0; width: var(--radius-xl); height: var(--radius-xl); pointer-events: none;-}-.thread-tab[aria-selected="true"]::before { right: 100%; background: radial-gradient(circle at 0 0, transparent calc(var(--radius-xl) - 0.5px), var(--color-app) var(--radius-xl)); }-.thread-tab[aria-selected="true"]::after { left: 100%; background: radial-gradient(circle at 100% 0, transparent calc(var(--radius-xl) - 0.5px), var(--color-app) var(--radius-xl)); }-.thread-tab:not([aria-selected="true"]) + .thread-tab:not([aria-selected="true"])::before {- content: ""; position: absolute; inset-inline-start: 0; top: 8px; bottom: 8px; width: 1px; background: var(--color-hairline);+ [data-chathead-tabs] [data-chathead-controls] { grid-column: 3; margin-inline-start: 8px; gap: 10px; }+ [data-chathead-tabs="simple"] { height: 48px; padding-inline-end: 16px; }+ [data-chathead-tabs="advanced"] { height: 42px; padding-inline-end: 8px; }+ [data-chathead-tabs] [data-chathead-controls] :is(.size-9, .h-9, [data-model-pill]) { height: 32px; }+ [data-chathead-tabs] [data-chathead-controls] .size-9 { width: 32px; }+ [data-chathead-tabs] [data-chathead-controls] .min-w-9 { min-width: 32px; }+}+.thread-tab-indicator {+ --tab-foot: 10px;+ position: absolute; left: 0; bottom: 0; height: 34px; border-radius: var(--tab-foot) var(--tab-foot) 0 0; background: var(--color-app); pointer-events: none;+}+.thread-tab-indicator[data-glide] { transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), width 220ms cubic-bezier(0.22, 1, 0.36, 1); }+.thread-tab-indicator::before,+.thread-tab-indicator::after { content: ""; position: absolute; bottom: 0; width: var(--tab-foot); height: var(--tab-foot); }+.thread-tab-indicator::before { right: 100%; background: radial-gradient(circle at 0 0, transparent calc(var(--tab-foot) - 0.5px), var(--color-app) var(--tab-foot)); }+.thread-tab-indicator::after { left: 100%; background: radial-gradient(circle at 100% 0, transparent calc(var(--tab-foot) - 0.5px), var(--color-app) var(--tab-foot)); }+.thread-tab + .thread-tab::before {+ content: ""; position: absolute; inset-inline-start: -1.5px; top: 8px; width: 1px; height: 16px; background: var(--color-hairline);transition: opacity 120ms ease-out;}-.thread-tab:hover + .thread-tab:not([aria-selected="true"])::before,-.thread-tab:not([aria-selected="true"]):hover::before { opacity: 0; }+.thread-tab[aria-selected="true"]::before,+.thread-tab[aria-selected="true"] + .thread-tab::before,+.thread-tab:hover::before,+.thread-tab:hover + .thread-tab::before { opacity: 0; }.thread-tab[data-entering] { animation: thread-tab-in 200ms cubic-bezier(0.22, 1, 0.36, 1) both; }.thread-tab[data-leaving] { animation: thread-tab-out 180ms cubic-bezier(0.22, 1, 0.36, 1) both; pointer-events: none; }@keyframes thread-tab-in { from { max-width: 0; padding-inline: 0; opacity: 0; } }@keyframes thread-tab-out { to { max-width: 0; padding-inline: 0; opacity: 0; } }@media (prefers-reduced-motion: reduce) {- .thread-tab, .thread-tab::before { animation: none !important; transition: none !important; }+ .thread-tab, .thread-tab::before, .thread-tab-indicator { animation: none !important; transition: none !important; }}:root[data-reduced-motion="true"] .thread-tab,-:root[data-reduced-motion="true"] .thread-tab::before { animation: none !important; transition: none !important; }+:root[data-reduced-motion="true"] .thread-tab::before,+:root[data-reduced-motion="true"] .thread-tab-indicator { animation: none !important; transition: none !important; }