Skip to content

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

Star a model to keep it at the top of its provider

milind-soni601b9098ad5a
diff --git a/src/components/FavoriteStar.dom.test.ts b/src/components/FavoriteStar.dom.test.ts
new file mode 100644
index 0000000000..dd9c7608eb
--- /dev/null
+++ b/src/components/FavoriteStar.dom.test.ts
@@ -0,0 +1,41 @@
+// @vitest-environment happy-dom
+import { createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { favoriteKey, favoriteModels, forgetFavoriteModelsForTest } from "@/lib/favorite-models";
+import { FavoriteStar } from "./SimpleModelMenu";
+
+let host: HTMLDivElement;
+let root: Root;
+
+beforeEach(() => {
+ const stored = new Map<string, string>();
+ vi.stubGlobal("localStorage", { getItem: (key: string) => stored.get(key) ?? null, setItem: (key: string, value: string) => stored.set(key, value) });
+ forgetFavoriteModelsForTest();
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+});
+
+afterEach(() => {
+ flushSync(() => root.unmount());
+ host.remove();
+ vi.unstubAllGlobals();
+});
+
+describe("the star on a model", () => {
+ it("toggles in place, says which way it will go, and is remembered", () => {
+ flushSync(() => root.render(createElement(FavoriteStar, { instanceId: "openaiCompat", model: "qwen3:4b", name: "qwen3:4b" })));
+ const star = host.querySelector<HTMLButtonElement>("[data-model-favorite]")!;
+ expect(star.getAttribute("aria-pressed")).toBe("false");
+ expect(star.getAttribute("aria-label")).toBe("Add qwen3:4b to favorites");
+ flushSync(() => star.click());
+ expect(star.getAttribute("aria-pressed")).toBe("true");
+ expect(star.getAttribute("aria-label")).toBe("Remove qwen3:4b from favorites");
+ expect(favoriteModels().has(favoriteKey("openaiCompat", "qwen3:4b"))).toBe(true);
+ expect(JSON.parse(localStorage.getItem("omb-favorite-models")!)).toEqual([favoriteKey("openaiCompat", "qwen3:4b")]);
+ flushSync(() => star.click());
+ expect(star.getAttribute("aria-pressed")).toBe("false");
+ });
+});
diff --git a/src/components/SimpleModelMenu.tsx b/src/components/SimpleModelMenu.tsx
index f116c9eb57..3e4a91839c 100644
--- a/src/components/SimpleModelMenu.tsx
+++ b/src/components/SimpleModelMenu.tsx
@@ -1,8 +1,9 @@
import { useState, type ReactNode } from "react";
-import { Check, ChevronDown, ChevronRight, ChevronUp, Download, Lightbulb, Loader2, LogIn, RefreshCw, Search, Settings, X } from "lucide-react";
+import { Check, ChevronDown, ChevronRight, ChevronUp, Download, Lightbulb, Loader2, LogIn, RefreshCw, Search, Settings, Star, X } from "lucide-react";
import type { Bot, InstanceInfo } from "@/state/store";
import type { EffortLevel } from "../../shared/wire";
import type { MenuGroup, MenuModelRow, SimpleMenu } from "@/lib/simple-model-menu";
+import { favoriteKey, toggleFavoriteModel, useFavoriteModels } from "@/lib/favorite-models";
import { modelOptionLabel } from "@/lib/model-label";
import { cn } from "@/lib/cn";
import { t } from "@/lib/i18n";
@@ -50,10 +51,31 @@ function RowLines({ label, children }: { label: ReactNode; children?: ReactNode
);
}
+/** Stays where it is when pressed: the row moves up the next time the menu opens, not under the pointer. */
+export function FavoriteStar({ instanceId, model, name }: { instanceId: string; model: string; name: string }) {
+ const favorite = useFavoriteModels().has(favoriteKey(instanceId, model));
+ return (
+ <button
+ type="button"
+ data-model-favorite
+ tabIndex={-1}
+ aria-pressed={favorite}
+ aria-label={t(favorite ? "model.favorite.remove" : "model.favorite.add", { name })}
+ title={t(favorite ? "model.favorite.remove" : "model.favorite.add", { name })}
+ onClick={() => toggleFavoriteModel(instanceId, model)}
+ className={cn("absolute end-1.5 top-1/2 flex size-6 -translate-y-1/2 items-center justify-center rounded-md text-ink-tertiary hover:text-ink",
+ favorite ? "opacity-100" : "opacity-0 group-hover/model:opacity-100 touch:opacity-100")}
+ >
+ <Star size={13} aria-hidden="true" className={cn(favorite && "fill-current")} />
+ </button>
+ );
+}
+
function MenuModel({ instance, row, onPick }: { instance: InstanceInfo; row: MenuModelRow; onPick: SimpleMenuActions["onPick"] }) {
const { option } = row;
const reason = row.blocked ? t("model.orgBlocked") : undefined;
return (
+ <div className="group/model relative">
<button
type="button"
data-menu-row
@@ -64,7 +86,7 @@ function MenuModel({ instance, row, onPick }: { instance: InstanceInfo; row: Men
title={[modelOptionLabel(option), option.provider, row.detail, reason].filter(Boolean).join(" · ")}
tabIndex={-1}
onClick={() => onPick(instance, row.model ?? option.id, row.variant)}
- className={SIMPLE_MENU_ROW}
+ className={cn(SIMPLE_MENU_ROW, "pe-8")}
>
<Gutter />
<RowLines label={row.label}>
@@ -74,6 +96,8 @@ function MenuModel({ instance, row, onPick }: { instance: InstanceInfo; row: Men
</RowLines>
{row.current && <Check size={14} className="shrink-0 text-ink" aria-hidden="true" />}
</button>
+ {!row.blocked && <FavoriteStar instanceId={instance.instanceId} model={option.id} name={modelOptionLabel(option)} />}
+ </div>
);
}
diff --git a/src/lib/favorite-models.ts b/src/lib/favorite-models.ts
new file mode 100644
index 0000000000..4ece9d3207
--- /dev/null
+++ b/src/lib/favorite-models.ts
@@ -0,0 +1,39 @@
+import { useSyncExternalStore } from "react";
+
+const STORAGE_KEY = "omb-favorite-models";
+const NONE: ReadonlySet<string> = new Set();
+const listeners = new Set<() => void>();
+let current: ReadonlySet<string> | null = null;
+
+export const favoriteKey = (instanceId: string, model: string) => `${instanceId}\n${model}`;
+
+function read(): ReadonlySet<string> {
+ if (current) return current;
+ try {
+ const saved: unknown = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "[]");
+ current = Array.isArray(saved) ? new Set(saved.filter((entry): entry is string => typeof entry === "string")) : NONE;
+ } catch {
+ current = NONE;
+ }
+ return current;
+}
+
+/** The models starred on this device. */
+export const favoriteModels = read;
+
+export function toggleFavoriteModel(instanceId: string, model: string): void {
+ const key = favoriteKey(instanceId, model);
+ const next = new Set(read());
+ if (!next.delete(key)) next.add(key);
+ current = next;
+ try { localStorage.setItem(STORAGE_KEY, JSON.stringify([...next])); } catch {}
+ for (const listener of listeners) listener();
+}
+
+export function useFavoriteModels(): ReadonlySet<string> {
+ return useSyncExternalStore((listener) => { listeners.add(listener); return () => { listeners.delete(listener); }; }, read, () => NONE);
+}
+
+export function forgetFavoriteModelsForTest(): void {
+ current = null;
+}
diff --git a/src/lib/simple-model-menu.test.ts b/src/lib/simple-model-menu.test.ts
index 32b9c628d2..fdd2d366b2 100644
--- a/src/lib/simple-model-menu.test.ts
+++ b/src/lib/simple-model-menu.test.ts
@@ -1,5 +1,6 @@
-import { describe, expect, it, vi } from "vitest";
+import { beforeEach, describe, expect, it, vi } from "vitest";
import type { InstanceInfo, ModelSelection } from "@/state/store";
+import { favoriteKey, favoriteModels, forgetFavoriteModelsForTest, toggleFavoriteModel } from "./favorite-models";
import { modelName, simpleModelMenu, SIMPLE_SEARCH_AFTER } from "./simple-model-menu";
vi.hoisted(() => {
@@ -51,6 +52,40 @@ const rows = (built: Menu, index = 0) => {
};
const body = (built: Menu, index = 0) => built.groups[index]!.body;
+describe("a starred model", () => {
+ const stored = new Map<string, string>();
+ beforeEach(() => {
+ stored.clear();
+ forgetFavoriteModelsForTest();
+ vi.stubGlobal("localStorage", { getItem: (key: string) => stored.get(key) ?? null, setItem: (key: string, value: string) => stored.set(key, value) });
+ });
+
+ it("comes first among its provider's suggestions, and counts against them", () => {
+ toggleFavoriteModel("claude", "haiku-5");
+ expect(rows(menu([claude()]))).toEqual(["Haiku 5", "Fable 5.1", "Fable 5", "Opus 5.5"]);
+ });
+
+ it("stays out of another provider, and goes back when unstarred", () => {
+ toggleFavoriteModel("codex", "haiku-5");
+ expect(rows(menu([claude()]))).toEqual(["Fable 5.1", "Fable 5", "Opus 5.5", "Opus 5"]);
+ toggleFavoriteModel("claude", "haiku-5");
+ toggleFavoriteModel("claude", "haiku-5");
+ expect(rows(menu([claude()]))).toEqual(["Fable 5.1", "Fable 5", "Opus 5.5", "Opus 5"]);
+ });
+
+ it("survives a reload, and a saved list that makes no sense counts as none", () => {
+ toggleFavoriteModel("claude", "haiku-5");
+ forgetFavoriteModelsForTest();
+ expect(favoriteModels().has(favoriteKey("claude", "haiku-5"))).toBe(true);
+ stored.set("omb-favorite-models", "{not json");
+ forgetFavoriteModelsForTest();
+ expect(favoriteModels().size).toBe(0);
+ stored.set("omb-favorite-models", JSON.stringify({ a: 1 }));
+ forgetFavoriteModelsForTest();
+ expect(favoriteModels().size).toBe(0);
+ });
+});
+
describe("Ollama in the Simple model menu", () => {
const ollama = engine("openaiCompat", "openai-compat", "Ollama", "api", [
{ id: "llama3.2:latest", label: "llama3.2:latest", custom: true, local: { bytes: 2_019_393_189, parameters: "3.2B", quantization: "Q4_K_M", tools: true } },
diff --git a/src/lib/simple-model-menu.ts b/src/lib/simple-model-menu.ts
index d69d3a4a8e..458f535188 100644
--- a/src/lib/simple-model-menu.ts
+++ b/src/lib/simple-model-menu.ts
@@ -4,6 +4,7 @@ import { t } from "./i18n";
import { modelOptionLabel } from "./model-label";
import { filterCustomModels, partitionCustomModels, suggestedModels } from "./custom-models";
import { engineDisplayName, isCustomOnly, SIGN_IN_FAMILY_LABEL, signInFamily, splitEngineRail } from "./engine-rail";
+import { favoriteKey, favoriteModels } from "./favorite-models";
import { localModelDetail } from "./local-model";
import { displayModelLabel, shortModelLabel } from "./model-friendly";
import { choiceIsSelected, modelChoices, takesTypedModels, type ModelChoice } from "./model-choices";
@@ -198,8 +199,10 @@ export function simpleModelMenu(input: SimpleMenuInput): SimpleMenu {
}
const others = all.filter((option) => (!currentSelection || !choiceIsSelected(option, currentSelection))
&& (!botSelection || !choiceIsSelected(option, botSelection)));
- const suggested = suggestedModels(others, instance.models.default, undefined,
- currentSelection === undefined ? GROUP_SUGGESTIONS : CURRENT_GROUP_SUGGESTIONS);
+ const starred = favoriteModels();
+ const favorites = others.filter((option) => starred.has(favoriteKey(instance.instanceId, option.id)));
+ const limit = currentSelection === undefined ? GROUP_SUGGESTIONS : CURRENT_GROUP_SUGGESTIONS;
+ const suggested = [...favorites, ...suggestedModels(others.filter((option) => !favorites.includes(option)), instance.models.default, undefined, Math.max(0, limit - favorites.length))];
const rest = others.filter((option) => !suggested.includes(option));
const open = expanded.has(instance.instanceId) || rest.length === 1;
const rows = (open ? [...suggested, ...rest] : suggested).map(row);
diff --git a/src/locales/en.json b/src/locales/en.json
index 58f2ad2298..8c905d0bd0 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -3104,6 +3104,8 @@
"model.unconfirmed": "{name} hasn't listed its models yet. These may be out of date.",
"model.localModels": "Local models",
"model.local.noTools": "No tools",
+ "model.favorite.add": "Add {name} to favorites",
+ "model.favorite.remove": "Remove {name} from favorites",
"model.localHint": "Run this agent with a model already on your machine.",
"model.apiKeyHint": "Runs on your API key. The provider bills you for what it uses.",
"model.chooseHint": "Choose a model for this bot.",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 83d887dc69..419aee2986 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2974,6 +2974,8 @@
"model.unconfirmed": "{name} ainda não informou quais modelos oferece. Esta lista pode estar desatualizada.",
"model.localModels": "Modelos locais",
"model.local.noTools": "Sem ferramentas",
+ "model.favorite.add": "Adicionar {name} aos favoritos",
+ "model.favorite.remove": "Remover {name} dos favoritos",
"model.localHint": "Rode este agente com um modelo que já está na sua máquina.",
"model.apiKeyHint": "Usa sua chave de API. O provedor cobra pelo uso.",
"model.chooseHint": "Escolha um modelo para este bot.",