Skip to content

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

fix(bot-settings): the large instructions editor follows DESIGN.md

Absterrg08eaea76e27f2
diff --git a/src/components/SoulField.large.dom.test.ts b/src/components/SoulField.large.dom.test.ts
index 6e13a20fce..8b7f3e4d04 100644
--- a/src/components/SoulField.large.dom.test.ts
+++ b/src/components/SoulField.large.dom.test.ts
@@ -57,7 +57,9 @@ describe("the standing instructions editor opened large", () => {
const large = panel.querySelector("textarea")!;
expect(large.value).toBe("# Rules\nBe brief.");
expect(document.activeElement).toBe(large);
- expect(panel.textContent).toContain("17 / 24,000 bytes");
+ expect(document.getElementById(large.getAttribute("aria-labelledby")!)!.textContent).toBe("Standing instructions (SOUL.md)");
+ expect(panel.getAttribute("aria-labelledby")).toBe(large.getAttribute("aria-labelledby"));
+ expect(document.getElementById(large.getAttribute("aria-describedby")!)!.textContent).toBe("17 / 24,000 bytes");
type(large, "# Rules\nBe brief and kind.");
expect(onPatch).toHaveBeenLastCalledWith({ soul: "# Rules\nBe brief and kind." });
@@ -73,11 +75,27 @@ describe("the standing instructions editor opened large", () => {
expect(document.activeElement).toBe(openLarge());
});
- it("closes with Done", () => {
+ it("shows an edit over the limit as not saved", () => {
+ const onPatch = vi.fn();
+ render(bot("Be brief."), onPatch);
+ flushSync(() => openLarge()!.click());
+ const large = dialog()!.querySelector("textarea")!;
+ type(large, "x".repeat(24_001));
+ expect(onPatch).not.toHaveBeenCalled();
+ expect(large.getAttribute("aria-invalid")).toBe("true");
+ expect(document.getElementById(large.getAttribute("aria-describedby")!)!.textContent).toBe("24,001 / 24,000 bytes — not saved");
+ });
+
+ it("closes with Done or a click outside", () => {
render(bot(""), vi.fn());
flushSync(() => openLarge()!.click());
const done = [...dialog()!.querySelectorAll("button")].find((button) => button.textContent === "Done")!;
flushSync(() => done.click());
expect(dialog()).toBeNull();
+
+ flushSync(() => openLarge()!.click());
+ const scrim = dialog()!.parentElement!;
+ flushSync(() => scrim.dispatchEvent(new MouseEvent("mousedown", { bubbles: true })));
+ expect(dialog()).toBeNull();
});
});
diff --git a/src/components/SoulField.tsx b/src/components/SoulField.tsx
index 969ed21414..d166663bf7 100644
--- a/src/components/SoulField.tsx
+++ b/src/components/SoulField.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef, useState, type ReactNode } from "react";
+import { useEffect, useId, useRef, useState, type ReactNode, type TextareaHTMLAttributes } from "react";
import { BOT_PROFILE_LIMITS } from "../../shared/bot-profile";
import { cn } from "@/lib/cn";
@@ -28,6 +28,8 @@ export function SoulField({
const [info, setInfo] = useState<SoulRead | null>(null);
const [resolving, setResolving] = useState(false);
const [large, setLarge] = useState(false);
+ const largeTitleId = useId();
+ const largeCountId = useId();
useEffect(() => {
setDraft(bot.soul ?? "");
@@ -67,11 +69,11 @@ export function SoulField({
};
const canMigrate = bot.description.length > 400 && !(bot.soul ?? "").trim();
const label = simple ? simple.label : t("botIdentity.soul.label");
- const editor = (className: string, id?: string) => (
+ const editor = (className: string, attrs: TextareaHTMLAttributes<HTMLTextAreaElement>) => (
<textarea
- id={id}
- aria-label={id ? undefined : label}
- className={cn(inputCls, className, over && "ring-2 ring-red-500/60")}
+ {...attrs}
+ dir="auto"
+ className={cn(inputCls, className, over && "ring-2 ring-danger/60")}
placeholder={simple ? simple.placeholder : t("bot.soul.placeholder")}
aria-invalid={over || undefined}
disabled={resolving}
@@ -79,8 +81,8 @@ export function SoulField({
onChange={(e) => change(e.target.value)}
/>
);
- const byteCount = (
- <span className={cn("shrink-0 tabular-nums", over && "font-medium text-red-500")}>
+ const byteCount = (id?: string) => (
+ <span id={id} className={cn("shrink-0 tabular-nums", over && "font-medium text-danger")}>
{t(over ? "botIdentity.soul.bytesOver" : "botIdentity.soul.bytes", { bytes: bytes.toLocaleString(intlLocale()), limit: limit.toLocaleString(intlLocale()) })}
</span>
);
@@ -124,17 +126,20 @@ export function SoulField({
</div>
</div>
)}
- {editor(simple ? "min-h-[140px] resize-y rounded-xl text-[14px] leading-relaxed" : "min-h-[220px] resize-y font-mono leading-relaxed", `bot-soul-${bot.id}`)}
+ {editor(simple ? "min-h-[140px] resize-y rounded-xl text-[14px] leading-relaxed" : "min-h-[220px] resize-y font-mono leading-relaxed", { id: `bot-soul-${bot.id}` })}
{(!simple || over) && <div className="mt-1.5 flex items-start justify-between gap-3 text-[11px] text-ink-secondary">
<span>
{!simple && <>{t("botIdentity.soul.contextHelp")}{info?.file ? <> {t("botIdentity.soul.mirroredTo")} <span className="break-all">{info.file}</span>.</> : null}</>}
</span>
- {byteCount}
+ {byteCount()}
</div>}
{large && (
<Layer modal>
- <SoulLargeDialog title={label} byteCount={byteCount} onClose={() => setLarge(false)}>
- {editor(cn("min-h-0 flex-1 resize-none leading-relaxed", simple ? "rounded-xl text-[14px]" : "font-mono"))}
+ <SoulLargeDialog titleId={largeTitleId} title={label} byteCount={byteCount(largeCountId)} onClose={() => setLarge(false)}>
+ {editor(
+ cn("min-h-0 flex-1 resize-none leading-relaxed", simple ? "rounded-xl text-[14px]" : "font-mono"),
+ { "aria-labelledby": largeTitleId, "aria-describedby": largeCountId },
+ )}
</SoulLargeDialog>
</Layer>
)}
@@ -142,30 +147,34 @@ export function SoulField({
);
}
-const HEADER_BUTTON = "rounded-md px-1.5 py-1 text-[12px] font-medium text-accent-text hover:bg-accent/10 disabled:opacity-50";
+const HEADER_BUTTON = "rounded-md px-1.5 py-1 text-[12px] font-medium text-accent-text enabled:hover:bg-ink/[0.06] disabled:opacity-50";
-function SoulLargeDialog({ title, byteCount, onClose, children }: { title: string; byteCount: ReactNode; onClose: () => void; children: ReactNode }) {
+function SoulLargeDialog({ titleId, title, byteCount, onClose, children }: {
+ titleId: string;
+ title: string;
+ byteCount: ReactNode;
+ onClose: () => void;
+ children: ReactNode;
+}) {
const dialogRef = useRef<HTMLDivElement>(null);
useModalDialog(dialogRef, onClose);
useEffect(() => { dialogRef.current?.querySelector("textarea")?.focus(); }, []);
return (
- <div
- ref={dialogRef}
- tabIndex={-1}
- role="dialog"
- aria-modal="true"
- aria-labelledby="bot-soul-large-title"
- className="fixed inset-0 z-[90] flex items-center justify-center bg-black/45 p-6"
- >
- <div className="flex h-[min(760px,90vh)] w-full max-w-3xl flex-col rounded-2xl bg-card p-5 shadow-2xl">
- <div className="mb-3 flex items-center justify-between gap-3">
- <h2 id="bot-soul-large-title" className="min-w-0 truncate text-[16px] font-semibold text-ink">{title}</h2>
- <button type="button" onClick={onClose} className="rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink">
- {t("common.done")}
- </button>
- </div>
- {children}
- <div className="mt-1.5 flex justify-end text-[11px] text-ink-secondary">{byteCount}</div>
+ <div className="ui-scrim fixed inset-0 z-[90] flex items-center justify-center p-4" onMouseDown={(event) => { if (event.target === event.currentTarget) onClose(); }}>
+ <div
+ ref={dialogRef}
+ tabIndex={-1}
+ role="dialog"
+ aria-modal="true"
+ aria-labelledby={titleId}
+ className="ui-modal animate-pop-in flex h-[min(760px,100%)] w-full max-w-3xl flex-col text-ink outline-none motion-reduce:animate-none"
+ >
+ <h2 id={titleId} className="min-w-0 truncate px-5 pb-3 pt-4 text-[20px] font-semibold tracking-[-0.01em]">{title}</h2>
+ <div className="flex min-h-0 flex-1 flex-col px-5">{children}</div>
+ <footer className="flex items-center justify-between gap-3 px-5 pb-4 pt-3 text-[12px] text-ink-secondary">
+ {byteCount}
+ <button type="button" onClick={onClose} className="ui-button ui-button-md">{t("common.done")}</button>
+ </footer>
</div>
</div>
);