Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(mascot): cut the face out of the body so it shows the background
aivsomkar16bb791ea034
diff --git a/src/components/Avatar.test.ts b/src/components/Avatar.test.tsindex 9a25444439..177b92b881 100644--- a/src/components/Avatar.test.ts+++ b/src/components/Avatar.test.ts@@ -59,10 +59,12 @@ describe("mascot facial feature colors", () => {}});- it("keeps default inks when an override is reset or comes from an older profile", () => {+ it("cuts the features out of the body when no colour is set", () => {expect(renderBot({ color: "chrome", mascotFaceColor: null })).toContain('stroke="#1E2833"');- expect(renderBot({ mascotBody: "ghost" })).toContain('stroke="#0d0a10"');- expect(renderBot({})).toContain('stroke="#ffffff"');+ for (const markup of [renderBot({ mascotBody: "ghost" }), renderBot({})]) {+ expect(markup).toContain("<mask");+ expect(markup).not.toMatch(/stroke="#(?:ffffff|0d0a10)"/);+ }});it("does not paint features over an uploaded image", () => {diff --git a/src/components/CarvedAvatar.test.ts b/src/components/CarvedAvatar.test.tsindex d6d1456bc0..2f79063154 100644--- a/src/components/CarvedAvatar.test.ts+++ b/src/components/CarvedAvatar.test.ts@@ -11,12 +11,12 @@ const render = (body: (typeof CARVED_BODY_IDS)[number], color: "orange" | "purplrenderToStaticMarkup(createElement(CarvedAvatar, { body, color, animated: false, label: body }));describe("CarvedAvatar", () => {- it("draws every part, two eyes, and a smile unless the drawing has its own mouth", () => {+ it("draws every part, two eyes cut out of a mask, and a smile unless the drawing has its own mouth", () => {for (const id of CARVED_BODY_IDS) {const markup = render(id);const body = CARVED_BODIES[id];expect(markup).toContain(`data-carved-body="${id}"`);- expect(markup.match(/<rect /g)?.length, id).toBe(2);+ expect(markup.match(/<rect /g)?.length, id).toBe(3);expect(markup.match(/<path /g)?.length, id).toBe(body.parts.length + 1 + (body.eyes.mouth ? 1 : 0));expect(markup.includes("<ellipse"), id).toBe(body.eyes.mouth);}diff --git a/src/components/CarvedAvatar.tsx b/src/components/CarvedAvatar.tsxindex 79093af226..318b821255 100644--- a/src/components/CarvedAvatar.tsx+++ b/src/components/CarvedAvatar.tsx@@ -270,6 +270,22 @@ function CarvedAvatarComponent(const fills = carvedFills(body, color);const resolve = (fill: string) => (fill === "body" ? fills.body : fill === "accent" ? fills.accent : fill);+ const cutFace = !faceInk;+ const ink = faceInk ?? "black";+ const face = (+ <>+ <g clipPath={`url(#carved-${uid})`}>+ {initial.eyes.map((rect, i) => <rect key={i} ref={eyes[i]} {...rect} fill={ink} />)}+ </g>+ {body.eyes.mouth && (+ <g>+ <path ref={smile} d={initial.smile.d} transform={initial.smile.transform} opacity={initial.smile.opacity}+ fill="none" stroke={ink} strokeWidth={body.eyes.w * 0.36} strokeLinecap="round" />+ <ellipse ref={open} {...initial.open} fill={ink} />+ </g>+ )}+ </>+ );return (<span{...avatarMarks(kind, "mascot")}@@ -289,19 +305,18 @@ function CarvedAvatarComponent(><defs><clipPath id={`carved-${uid}`}><path d={body.clip} /></clipPath>+ {cutFace && (+ <mask id={`carved-face-${uid}`} maskUnits="userSpaceOnUse" x="-300" y="-300" width="900" height="900">+ <rect x="-300" y="-300" width="900" height="900" fill="white" />+ {face}+ </mask>+ )}</defs><g ref={group} transform={initial.body}>- {body.parts.map((part, i) => <path key={i} d={part.d} fill={resolve(part.fill)} />)}- <g clipPath={`url(#carved-${uid})`}>- {initial.eyes.map((rect, i) => <rect key={i} ref={eyes[i]} {...rect} fill={faceInk ?? body.eyes.ink} />)}+ <g mask={cutFace ? `url(#carved-face-${uid})` : undefined}>+ {body.parts.map((part, i) => <path key={i} d={part.d} fill={resolve(part.fill)} />)}</g>- {body.eyes.mouth && (- <g>- <path ref={smile} d={initial.smile.d} transform={initial.smile.transform} opacity={initial.smile.opacity}- fill="none" stroke={faceInk ?? body.eyes.mouthInk} strokeWidth={body.eyes.w * 0.36} strokeLinecap="round" />- <ellipse ref={open} {...initial.open} fill={faceInk ?? body.eyes.mouthInk} />- </g>- )}+ {!cutFace && face}</g></svg></span>diff --git a/src/components/CursorAvatar.tsx b/src/components/CursorAvatar.tsxindex 632e1f3862..9c829b3bcf 100644--- a/src/components/CursorAvatar.tsx+++ b/src/components/CursorAvatar.tsx@@ -938,7 +938,7 @@ export const CursorAvatar = React.forwardRef<CursorAvatarHandle, CursorAvatarPropaused = false,silhouette = DEFAULT_SILHOUETTE,gradient = DEFAULT_GRADIENT, picture,- eyeColor = "#ffffff",+ eyeColor,title,className,style,@@ -1240,6 +1240,16 @@ export const CursorAvatar = React.forwardRef<CursorAvatarHandle, CursorAvatarProconst dimension = typeof size === 'number' ? `${size}px` : sizeconst label = title === undefined ? mascotLabel(silhouette.name) : titleconst body = silhouette.body.replace(/\{\{GRADIENT\}\}/g, `url(#${uid}-grad)`)+ const cutFace = !eyeColor && !picture+ const ink = cutFace ? 'black' : eyeColor+ const face = (+ <g clipPath={`url(#${uid}-clip)`} visibility={picture ? 'hidden' : undefined}>+ <g transform={anchorTransform(silhouette.anchor)}>+ <path ref={eye0} fill={ink} /><path ref={eye1} fill={ink} />+ {showMouth && <path ref={mouth} fill="none" stroke={ink} strokeWidth={mouthStroke} strokeLinecap="round" />}+ </g>+ </g>+ )return (<svg@@ -1265,27 +1275,17 @@ export const CursorAvatar = React.forwardRef<CursorAvatarHandle, CursorAvatarProtransform={silhouette.fit || undefined}dangerouslySetInnerHTML={{ __html: silhouette.clip }}/>+ {cutFace && <mask id={`${uid}-face`} maskUnits="userSpaceOnUse" x={-VIEW_SPAN} y={-VIEW_SPAN} width={VIEW_SPAN * 3} height={VIEW_SPAN * 3}>+ <rect x={-VIEW_SPAN} y={-VIEW_SPAN} width={VIEW_SPAN * 3} height={VIEW_SPAN * 3} fill="white" />{face}</mask>}</defs><g transform={flip ? `translate(${FACE_BOX} 0) scale(-1 1)` : undefined}><g ref={trailLayer} /><g ref={bodyGroup}><g ref={bodyContent}>- {picture ? <image href={picture} x="-15" y="-15" width={VIEW_SPAN} height={VIEW_SPAN} preserveAspectRatio="none" /> : <g transform={silhouette.fit || undefined} dangerouslySetInnerHTML={{ __html: body }} />}- <g clipPath={`url(#${uid}-clip)`} visibility={picture ? 'hidden' : undefined}>- <g transform={anchorTransform(silhouette.anchor)}>- <path ref={eye0} fill={eyeColor} />- <path ref={eye1} fill={eyeColor} />- {showMouth && (- <path- ref={mouth}- fill="none"- stroke={eyeColor}- strokeWidth={mouthStroke}- strokeLinecap="round"- />- )}- </g>- </g>+ {picture ? <image href={picture} x="-15" y="-15" width={VIEW_SPAN} height={VIEW_SPAN} preserveAspectRatio="none" /> : <g mask={cutFace ? `url(#${uid}-face)` : undefined}>+ <g transform={silhouette.fit || undefined} dangerouslySetInnerHTML={{ __html: body }} />+ </g>}+ {!cutFace && face}</g><g ref={glyphLayer} style={{ opacity: 0 }} /></g>