Skip to content

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

feat: choose white or black mascot facial features (4/4)

guylfe6a5cb9df75b5
diff --git a/server/mascot-face-color.e2e.test.ts b/server/mascot-face-color.e2e.test.ts
new file mode 100644
index 0000000000..b4f8244eb8
--- /dev/null
+++ b/server/mascot-face-color.e2e.test.ts
@@ -0,0 +1,36 @@
+import { readFileSync } from "node:fs";
+import { join } from "node:path";
+import { expect, it } from "vitest";
+import { launchVerificationServer } from "../scripts/control-omb.ts";
+import type { WireBot } from "../shared/wire.ts";
+
+it("saves, reads and resets facial feature color through the isolated HTTP routes", async () => {
+ const fixture = await launchVerificationServer();
+ const api = async (method: string, path: string, body?: unknown, status = 200) => {
+ const response = await fetch(`${fixture.info.url}${path}`, {
+ method, headers: { "content-type": "application/json", origin: fixture.info.url },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
+ });
+ const data = await response.json() as { bot: WireBot; bots: WireBot[] };
+ expect(response.status, JSON.stringify(data)).toBe(status);
+ return data;
+ };
+ try {
+ const { bot } = await api("POST", "/api/bots", {
+ name: "Face color fixture", useDefaults: false, settings: { color: "yellow", mascotFaceColor: "black" },
+ }, 201);
+ expect(bot.mascotFaceColor).toBe("black");
+ const path = `/api/bots/${bot.id}`;
+ for (const mascotFaceColor of ["white", "black", null]) {
+ expect((await api("PATCH", path, { mascotFaceColor })).bot.mascotFaceColor).toBe(mascotFaceColor);
+ expect((await api("GET", "/api/bots")).bots.find((value: { id: string }) => value.id === bot.id)?.mascotFaceColor).toBe(mascotFaceColor);
+ const saved = JSON.parse(readFileSync(join(fixture.info.dataDir, "bots.json"), "utf8"));
+ expect(saved.find((value: { id: string }) => value.id === bot.id).mascotFaceColor).toBe(mascotFaceColor);
+ }
+ await api("PATCH", path, { mascotFaceColor: "red" }, 400);
+ const after = (await api("GET", "/api/bots")).bots.find((value: { id: string }) => value.id === bot.id);
+ expect(after).toMatchObject({ color: "yellow", mascotFaceColor: null });
+ } finally {
+ await fixture.close();
+ }
+}, 60_000);
diff --git a/src/components/MascotFaceColorPicker.tsx b/src/components/MascotFaceColorPicker.tsx
new file mode 100644
index 0000000000..18b5db6437
--- /dev/null
+++ b/src/components/MascotFaceColorPicker.tsx
@@ -0,0 +1,27 @@
+import { t } from "@/lib/i18n";
+import type { Bot } from "@/state/store";
+import { MASCOT_FACE_COLORS } from "../../shared/bot-avatar";
+import type { AvatarPatch } from "./avatar-editing";
+import { Segmented } from "./bot-panel/rows";
+
+export function MascotFaceColorPicker({ bot, disabled, onPatch }: {
+ bot: Bot;
+ disabled: boolean;
+ onPatch: (patch: AvatarPatch) => void;
+}) {
+ return (
+ <div className="mt-3">
+ <div className="mb-1.5 flex items-baseline justify-between gap-2 text-[12px] text-ink-secondary">
+ <span>{t("botIdentity.faceColor")}</span>
+ {!bot.mascotFaceColor && <span className="text-ink-tertiary">{t("botIdentity.faceColor.default")}</span>}
+ </div>
+ <Segmented
+ attr="data-avatar-face-color"
+ label={t("botIdentity.faceColor")}
+ value={bot.mascotFaceColor}
+ onChange={(mascotFaceColor) => onPatch({ mascotFaceColor })}
+ options={MASCOT_FACE_COLORS.map((value) => ({ value, label: t(`botIdentity.faceColor.${value}`), disabled }))}
+ />
+ </div>
+ );
+}
diff --git a/src/state/bot-patch-queue.ts b/src/state/bot-patch-queue.ts
index 45f639315f..77a456ef51 100644
--- a/src/state/bot-patch-queue.ts
+++ b/src/state/bot-patch-queue.ts
@@ -12,6 +12,7 @@ export type BotUpdatePatch = Partial<
| "autoStartVps"
| "color"
| "mascotExpression"
+ | "mascotFaceColor"
| "avatarUrl"
| "avatarCrop"
| "avatarZoom"
diff --git a/src/state/store.tsx b/src/state/store.tsx
index d26f85bdeb..1759e9d172 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -11,7 +11,7 @@ import {
type ReactNode,
} from "react";
import { flushSync } from "react-dom";
-import type { BotMovedTo, BotVisibility, CardAnswerer, CloudBackend, ConnectorToolGrant, EffortLevel, InstalledPackageMetadata, LiveCallState, ServerFrame, GroupThreadUsage, SteerQueueReason, WireGroup, WireTask, OptionCardData as WireOptionCard } from "../../shared/wire";
+import type { BotMovedTo, BotVisibility, CardAnswerer, CloudBackend, ConnectorToolGrant, EffortLevel, InstalledPackageMetadata, LiveCallState, ServerFrame, GroupThreadUsage, SteerQueueReason, WireBot, WireGroup, WireTask, OptionCardData as WireOptionCard } from "../../shared/wire";
import { movesThreadToTop } from "../../shared/wire"; import type { DefaultBotFields } from "../../shared/default-bot";
import { reorderStable } from "../../shared/bot-order";
import { withOneChief } from "../../shared/bot-owner";
@@ -286,7 +286,7 @@ export interface TaskUsage {
context?: { tokens: number; window?: number };
}
-export interface Bot extends DefaultBotFields {
+export interface Bot extends DefaultBotFields, Pick<WireBot, "mascotFaceColor"> {
toolScope?: ToolScope;
waitingForTeammates?: boolean;
id: string;