Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

3.7 KB
Raw Blame
import { useI18n } from "../../i18n";
import { cn } from "../../lib/utils";
import { BotAvatarView } from "./BotAvatarView";
import {
  BOT_PERSONALITY_TONE_OPTIONS,
  botPersonalityToneLabel,
  botPersonalityToneSamplePrompt,
  localizeBotPersonalityToneBand,
  resolveBotPersonalityToneBand,
  resolveBotPersonalityToneOption,
} from "./botPersonalityTone";
import type { Bot } from "./types";

/**
 * Three personality baselines and a written sample. The sample is local copy,
 * so changing the choice never calls a provider.
 */
export function BotPersonalityToneField({
  bot,
  tone,
  onToneChange,
  className,
}: {
  readonly bot: Pick<Bot, "name" | "avatar">;
  readonly tone: number | undefined;
  readonly onToneChange: (tone: number) => void;
  readonly className?: string;
}) {
  const { t } = useI18n();
  const selected = resolveBotPersonalityToneOption(tone ?? 50);
  const band = localizeBotPersonalityToneBand(resolveBotPersonalityToneBand(selected.value), t);

  return (
    <div className={cn("space-y-4", className)}>
      <div className="space-y-3">
        <div
          role="radiogroup"
          aria-label={t("Personality for {name}", { name: bot.name })}
          className="grid grid-cols-3 gap-2"
        >
          {BOT_PERSONALITY_TONE_OPTIONS.map((option) => {
            const active = option.value === selected.value;

            return (
              <button
                key={option.value}
                type="button"
                role="radio"
                aria-checked={active}
                onClick={() => onToneChange(option.value)}
                className={cn(
                  "min-h-10 rounded-lg border px-3 text-sm font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring",
                  active
                    ? "border-primary/60 bg-primary/10 text-foreground"
                    : "border-border bg-muted/20 text-muted-foreground hover:bg-muted/40 hover:text-foreground",
                )}
              >
                {botPersonalityToneLabel(option.value, t)}
              </button>
            );
          })}
        </div>
        <p className="text-13px leading-copy text-muted-foreground/80">{band.summary}</p>
      </div>

      <BotPersonalityTonePreview bot={bot} tone={selected.value} />
    </div>
  );
}

/**
 * A worked example of the current band. Written copy, not a generated reply,
 * so it costs nothing and stays stable while the choice changes.
 */
export function BotPersonalityTonePreview({
  bot,
  tone,
}: {
  readonly bot: Pick<Bot, "name" | "avatar">;
  readonly tone: number | undefined;
}) {
  const { t } = useI18n();
  const band = localizeBotPersonalityToneBand(resolveBotPersonalityToneBand(tone ?? 50), t);

  return (
    <figure
      className="space-y-3 rounded-xl bg-muted/30 p-4"
      data-testid="bot-personality-tone-preview"
    >
      <figcaption className="text-xs font-medium text-muted-foreground">
        {t("How {name} might sound", { name: bot.name })}
      </figcaption>

      <div className="flex justify-end">
        <p className="max-w-17/20 rounded-2xl rounded-br-sm bg-primary/10 px-3 py-2 text-13px leading-copy text-foreground">
          {botPersonalityToneSamplePrompt(t)}
        </p>
      </div>

      <div className="flex items-end gap-2">
        <BotAvatarView avatar={bot.avatar} name={bot.name} className="size-6 shrink-0" />
        <p
          key={band.id}
          className="max-w-17/20 rounded-2xl rounded-bl-sm bg-background px-3 py-2 text-13px leading-copy text-foreground shadow-sm/5"
        >
          {band.sample}
        </p>
      </div>

      <p className="text-11px leading-copy-tight text-muted-foreground/70">
        {t("An illustration of the band, not a live reply.")}
      </p>
    </figure>
  );
}