Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge remote-tracking branch 'origin/main' into feat/template-publish-scrub
milind-soni79e548ca8ebd
diff --cc server/team-library.test.tsindex 2aaa52e079,ab7b81bdd0..07c4c06a89--- a/server/team-library.test.ts+++ b/server/team-library.test.ts@@@ -65,16 -65,25 +65,35 @@@ describe("team library", () =>expect(() => parseTeamCatalog(unsafe)).toThrow("safe catalog path");});+ it("keeps who published an entry as one line, and drops a credit it can't show", () => {+ const entry = catalog.teams[0]!;+ const credited = (author: unknown) => parseTeamCatalog({ ...catalog, teams: [{ ...entry, author }] }).teams[0]!.author;+ expect(credited("Jane Doe")).toBe("Jane Doe");+ expect(credited({ name: " Jane\n Doe " })).toBe("Jane Doe");+ expect(credited("x".repeat(101))).toBeUndefined();+ expect(credited(42)).toBeUndefined();+ expect(parseTeamCatalog(catalog).teams[0]).not.toHaveProperty("author");+ });++ it("keeps a template's kind and each bot's face, leaving out faces it can't trust", () => {+ const entry = {+ ...catalog.teams[0]!, kind: "bot",+ avatars: [+ { key: "lead", name: "Ada", color: "chrome", mascotBody: "cursor", mascotExpression: "happy", picture: "teams/engineering/avatars/lead.webp" },+ { key: "other", name: "Bo", color: "blue", picture: "teams/elsewhere/avatars/x.webp" },+ { key: "Bad Key", name: "Cy", color: "red" },+ { key: "nocolor", name: "Di" },+ ],+ };+ const [parsed] = parseTeamCatalog({ ...catalog, teams: [entry] }).teams;+ expect(parsed!.kind).toBe("bot");+ expect(parsed!.avatars).toEqual([+ { key: "lead", name: "Ada", color: "chrome", mascotBody: "cursor", mascotExpression: "happy", picture: "teams/engineering/avatars/lead.webp" },+ { key: "other", name: "Bo", color: "blue" },+ ]);+ expect(parseTeamCatalog(catalog).teams[0]!.avatars).toBeUndefined();+ });+it("accepts a catalog of hundreds of published templates", () => {const entry = catalog.teams[0]!;const teams = Array.from({ length: 500 }, (_, index) => {diff --cc server/team-library.tsindex 3fe384ba7c,b68e8e5733..4bd7352152--- a/server/team-library.ts+++ b/server/team-library.ts@@@ -28,10 -32,17 +32,19 @@@ export interface TeamCatalogEntrymembers: number;skills: string[];requires: { apps: string[] };+ /** Who published it ("Published by"), as the template's own frontmatter credits them. */+ author?: string;}+ export interface TeamCatalogAvatar {+ key: string;+ name: string;+ color: string;+ mascotBody?: string;+ mascotExpression?: string;+ picture?: string;+ }+export interface TeamCatalog {format: "openmaus.catalog";version: 1;@@@ -70,13 -81,26 +83,33 @@@ function stringList(value: unknown, fiereturn value.map((item, index) => text(item, `${field}[${index}]`, 100));}+/** A catalog entry's credit, as a name or `{ name }`: one line of up to 100 characters, else none. */+function catalogAuthor(value: unknown): string | undefined {+ const name = typeof value === "string" ? value : isRecord(value) && typeof value.name === "string" ? value.name : undefined;+ const line = name?.replace(/[\p{Cc}\p{Cf}]+/gu, " ").replace(/\s+/g, " ").trim();+ return line && line.length <= 100 ? line : undefined;+}++ const LOOK = /^[a-z0-9][a-z0-9-]{0,39}$/;+ const MAX_FACES = 50;++ /** The faces a catalog entry lists. A face that isn't well formed is left out; it never fails the catalog. */+ function catalogAvatars(value: unknown, slug: string): TeamCatalogAvatar[] | undefined {+ if (!Array.isArray(value)) return undefined;+ const picture = new RegExp(`^teams/${slug}/avatars/[a-z0-9][a-z0-9_-]{0,63}\\.(?:webp|png|jpg)$`);+ return value.slice(0, MAX_FACES).flatMap((raw): TeamCatalogAvatar[] => {+ if (!isRecord(raw) || typeof raw.key !== "string" || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(raw.key)) return [];+ if (typeof raw.name !== "string" || !raw.name.trim() || raw.name.trim().length > 100) return [];+ if (typeof raw.color !== "string" || !LOOK.test(raw.color)) return [];+ return [{+ key: raw.key, name: raw.name.trim(), color: raw.color,+ ...(typeof raw.mascotBody === "string" && LOOK.test(raw.mascotBody) ? { mascotBody: raw.mascotBody } : {}),+ ...(typeof raw.mascotExpression === "string" && LOOK.test(raw.mascotExpression) ? { mascotExpression: raw.mascotExpression } : {}),+ ...(typeof raw.picture === "string" && picture.test(raw.picture) ? { picture: raw.picture } : {}),+ }];+ });+ }+/** Validate the remotely maintained index before any of it reaches the renderer. */export function parseTeamCatalog(value: unknown): TeamCatalog {if (!isRecord(value) || value.format !== "openmaus.catalog" || value.version !== 1) {diff --cc src/components/TeamCatalogCard.test.tsindex 0000000000,0000000000..184247c024new file mode 100644--- /dev/null+++ b/src/components/TeamCatalogCard.test.ts@@@ -1,0 -1,0 +1,18 @@@++import { createElement } from "react";++import { renderToStaticMarkup } from "react-dom/server";++import { describe, expect, it } from "vitest";++import type { TeamCatalogEntry } from "@/lib/team-catalog";++import { TeamCatalogCard } from "./TeamCatalogCard";++++const entry: TeamCatalogEntry = {++ slug: "launch-crew", name: "Launch Crew", summary: "Ships launches.", category: "Marketing",++ manifest: "teams/launch-crew/team.mausteam.json", readme: "teams/launch-crew/README.md", members: 2, skills: [], requires: { apps: [] },++};++const shown = (author?: string) => renderToStaticMarkup(createElement(TeamCatalogCard, { entry: { ...entry, ...(author === undefined ? {} : { author }) }, busy: false, disabled: false, onAdd: () => {} }));++++describe("a community template's card", () => {++ it("says who published it, and names nobody for a placeholder credit", () => {++ expect(shown("Jane Doe")).toContain("Published by Jane Doe");++ for (const nobody of [undefined, "Community", "MausBot user"]) expect(shown(nobody)).not.toContain("Published by");++ });++});diff --cc src/components/TeamCatalogCard.tsxindex 0000000000,36010a6035..852bfb6ebcmode 000000,100644..100644--- a/src/components/TeamCatalogCard.tsx+++ b/src/components/TeamCatalogCard.tsx@@@ -1,0 -1,42 +1,45 @@@+ import { Loader2, Plus } from "lucide-react";++ import { t } from "@/lib/i18n";+ import { catalogCopy, catalogFaces, type TeamCatalogEntry } from "@/lib/team-catalog";++import { creditShown } from "@/lib/template-share";+ import { TemplateFaces } from "./TemplateCard";++ /** A community template in the Templates gallery: the same card the ready-made bots have, with every bot's face. */+ export function TeamCatalogCard({ entry, busy, disabled, onAdd }: {+ entry: TeamCatalogEntry;+ busy: boolean;+ disabled: boolean;+ onAdd: () => void;+ }) {+ const copy = catalogCopy(entry);++ const credit = creditShown(entry.author);+ const bots = entry.members === 1 ? t("template.botsOne") : t("template.botsMany", { count: entry.members });+ const details = [+ entry.skills.length > 0 && (entry.skills.length === 1 ? t("template.skillsOne") : t("template.skillsMany", { count: entry.skills.length })),+ entry.requires.apps.length > 0 && entry.requires.apps.join(", "),+ entry.setupMinutes && t("templates.minutes", { count: entry.setupMinutes }),+ ].filter(Boolean).join(" · ");+ return (+ <article data-catalog-template={entry.slug} className="flex flex-col rounded-2xl border border-hairline/40 bg-card p-4">+ <div className="flex items-center justify-between gap-3">+ <TemplateFaces avatars={catalogFaces(entry)} size={36} on="card" />+ <button+ type="button"+ onClick={onAdd}+ disabled={disabled}+ aria-label={busy ? undefined : t("orgLibrary.addAria", { name: copy.name })}+ className="flex h-8 shrink-0 items-center gap-1 rounded-full bg-raised px-3 text-[13px] font-medium text-ink hover:bg-raised-hover focus-visible:outline-2 focus-visible:outline-accent disabled:opacity-40"+ >+ {busy ? <Loader2 size={14} aria-hidden="true" className="animate-spin motion-reduce:animate-none" /> : <Plus size={14} aria-hidden="true" />}+ {busy ? t("templates.loadingShort") : t("common.add")}+ </button>+ </div>+ <h4 dir="auto" className="mt-3 truncate text-[14px] font-medium text-ink" title={copy.name}>{copy.name}</h4>+ <p dir="auto" className="truncate text-[12px] text-ink-secondary">{bots} · {entry.category}</p>++ {credit && <p dir="auto" data-catalog-published-by className="truncate text-[12px] text-ink-tertiary" title={credit}>{t("template.publishedBy", { name: credit })}</p>}+ <p dir="auto" className="mt-2 line-clamp-3 text-[13px] leading-[1.45] text-ink-secondary">{copy.outcome ?? copy.summary}</p>+ {details && <p className="mt-auto truncate pt-2 text-[12px] text-ink-tertiary" title={details}>{details}</p>}+ </article>+ );+ }