Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

10.2 KB
Raw Blame
import type { CSSProperties } from "react";
import {
  AppWindow,
  BookOpen,
  Compass,
  Keyboard,
  Brain,
  CalendarClock,
  Code2,
  Database,
  FileText,
  FolderOpen,
  Globe,
  Image,
  Mail,
  Monitor,
  MousePointer2,
  PenLine,
  Plug,
  Presentation,
  Search,
  Shapes,
  ShieldCheck,
  Sparkles,
  Terminal,
  Users,
  Workflow,
  Wrench,
} from "lucide-react";
import { McpLogo } from "@/components/extensions/McpLogo";
import { CLI_VENDOR_LOGOS, cliVendor } from "@/lib/cliVendors";
import { brandIdVariants, bundledPluginLogo, isRasterLogo } from "@/lib/pluginLogos";
import type { ToolCategory, ToolChoice } from "./toolChoices";

type Palette = readonly [string, string];
type Mark = "colour" | "mono";
interface Brand {
  palette: Palette;
  aliases?: string[];
  mark?: Mark;
}

// Ink pairs tint the chip around a mark (its wash and selected label), never
// the mark itself: original colour artwork stays intact and single-colour
// glyphs render in neutral monochrome (see .tool-choice-mask).
const NEUTRAL: Palette = ["#24292e", "#e6edf3"];
const BLUE: Palette = ["#1558b0", "#8ab4f8"];
const VIOLET: Palette = ["#6840bb", "#c4abff"];
const GREEN: Palette = ["#167344", "#79dca4"];
const BRANDS: Record<string, Brand> = {
  gmail: { palette: ["#b3261e", "#ff938a"], aliases: ["google-mail", "gws-gmail"] },
  github: { palette: NEUTRAL, mark: "mono", aliases: ["gh"] },
  x: { palette: NEUTRAL, mark: "mono", aliases: ["twitter"] },
  google_drive: { palette: GREEN, aliases: ["google-drive", "gdrive", "gws-drive"] },
  google_calendar: { palette: BLUE, aliases: ["google-calendar", "gws-calendar"] },
  airtable: { palette: ["#96650b", "#efc561"] },
  asana: { palette: ["#be3652", "#ff99ac"] },
  cal_com: { palette: NEUTRAL, mark: "mono", aliases: ["cal.com", "cal-com"] },
  canva: { palette: ["#087f88", "#69d6dd"] },
  clickup: { palette: VIOLET },
  discord: { palette: ["#454abe", "#a8acff"] },
  dropbox: { palette: BLUE },
  higgsfield: { palette: ["#50700a", "#ccf052"] },
  home_assistant: { palette: BLUE, aliases: ["home-assistant", "homeassistant"] },
  linear: { palette: VIOLET },
  notion: { palette: NEUTRAL },
  slack: { palette: ["#8d367d", "#e6a0d6"] },
  spotify: { palette: GREEN },
  supabase: { palette: GREEN },
  telegram: { palette: BLUE },
  todoist: { palette: ["#b12d27", "#ff9c92"] },
  vercel: { palette: NEUTRAL, mark: "mono" },
  youtube_music: { palette: ["#bb2424", "#ff9494"], aliases: ["youtube-music", "ytmusic", "youtube"] },
  stripe: { palette: VIOLET },
  cloudflare: { palette: ["#a84c14", "#ffb276"], aliases: ["wrangler"] },
  figma: { palette: ["#9c3a28", "#ffa18e"] },
  gitlab: { palette: ["#a8441a", "#ffad83"], aliases: ["glab"] },
  docker: { palette: BLUE, mark: "colour" },
  aws: { palette: ["#a15b00", "#f0b429"], mark: "mono" },
  azure: { palette: BLUE, aliases: ["az"] },
  firebase: { palette: ["#b45309", "#ffb74d"] },
  fly: { palette: VIOLET, aliases: ["flyctl"] },
  heroku: { palette: VIOLET },
  kubernetes: { palette: BLUE, aliases: ["kubectl"] },
  neon: { palette: GREEN, aliases: ["neonctl"] },
  netlify: { palette: GREEN },
  planetscale: { palette: NEUTRAL, mark: "mono", aliases: ["pscale"] },
  railway: { palette: VIOLET, mark: "mono" },
  render: { palette: GREEN, mark: "mono" },
  twilio: { palette: ["#b3261e", "#ff938a"] },
  n8n: { palette: ["#b43351", "#f69ab1"], mark: "mono" },
  postgresql: { palette: BLUE, aliases: ["postgres"] },
  obsidian: { palette: VIOLET, mark: "mono" },
  openai: { palette: NEUTRAL, mark: "mono", aliases: ["codex", "chatgpt"] },
  openrouter: { palette: NEUTRAL, mark: "mono" },
  claude: { palette: ["#a04f31", "#e6aa89"], aliases: ["anthropic", "claude-code"] },
  gemini: { palette: BLUE },
  "google-cloud": { palette: BLUE, aliases: ["gcloud", "vertex", "google_cloud"] },
  antigravity: { palette: BLUE, aliases: ["agy"] },
  ollama: { palette: NEUTRAL, mark: "mono" },
  nvidia: { palette: GREEN },
  amd_gpu: { palette: NEUTRAL, mark: "mono", aliases: ["amd-gpu"] },
  agentmail: { palette: NEUTRAL, aliases: ["agent-mail"] },
  groq: { palette: ["#b14628", "#ffaa8e"], mark: "mono" },
  elevenlabs: { palette: NEUTRAL, mark: "mono" },
  cartesia: { palette: GREEN },
  inworld: { palette: VIOLET },
  xai: { palette: NEUTRAL, mark: "mono", aliases: ["grok", "grok-build"] },
  cursor: { palette: NEUTRAL, mark: "mono" },
  deepseek: { palette: BLUE, mark: "mono", aliases: ["deepseek-harness"] },
  kimi: { palette: BLUE, mark: "mono" },
  opencode: { palette: NEUTRAL, mark: "mono" },
  zai: { palette: NEUTRAL, mark: "mono", aliases: ["glm", "z.ai"] },
};

const assets = import.meta.glob("../../assets/{brands,providers,tool-brands,clis,agents}/*.{svg,png}", {
  eager: true,
  query: "?url",
  import: "default",
}) as Record<string, string>;

function assetFor(key: string, preferCli = false): string | undefined {
  for (const id of brandIdVariants(key)) {
    const cliFile = CLI_VENDOR_LOGOS[id]?.file ?? `${id}.svg`;
    const cli = assets[`../../assets/clis/${cliFile}`] || assets[`../../assets/clis/${id}.svg`];
    if (preferCli && cli) return cli;
    const found =
      bundledPluginLogo(id) ||
      assets[`../../assets/brands/${id}.svg`] ||
      assets[`../../assets/brands/${id}.png`] ||
      assets[`../../assets/tool-brands/${id}.svg`] ||
      assets[`../../assets/providers/${id}.svg`] ||
      assets[`../../assets/providers/${id}.png`] ||
      assets[`../../assets/agents/${id}.svg`] ||
      cli;
    if (found) return found;
  }
  return undefined;
}

const normalize = (value: string) => value.toLowerCase().replace(/[^a-z0-9]/g, "");
const bundledKeys = Object.keys(assets)
  .filter((path) => !path.includes("/clis/"))
  .map((path) => path.split("/").pop()!.replace(/\.(svg|png)$/, ""));
const aliases = [...new Set([...Object.keys(BRANDS), ...bundledKeys])]
  .flatMap((key) =>
    [key, ...(BRANDS[key]?.aliases ?? [])].map((alias) => ({ key, alias: alias.replace(/[_. ]/g, "-") })),
  )
  .sort((a, b) => b.alias.length - a.alias.length);

function brandFor(value: string): string | undefined {
  // Identity segments only: "my-github-helper" is not GitHub and
  // "drive-jarvis" is not Drive. Descriptions never establish brand identity.
  for (const segment of value.replace(/__/g, ":").split(/[/:]/)) {
    const clean = segment
      .toLowerCase()
      .replace(/^(?:cli|mcp)[_-]/, "")
      .replace(/[-_](?:mcp|server|cli)$/, "")
      .replace(/[_. ]/g, "-");
    const exact = aliases.find((entry) => normalize(entry.alias) === normalize(clean));
    if (exact) return exact.key;
    const action = aliases.find((entry) => clean.startsWith(entry.alias + "-"));
    if (action) return action.key;
  }
  return undefined;
}

export const CATEGORY_ICONS = {
  plugins: Plug,
  skills: Sparkles,
  mcp: McpLogo,
  memory: Brain,
  web: Globe,
  files: FolderOpen,
  automation: CalendarClock,
  system: Wrench,
  cli: Terminal,
};
const CATEGORY_PALETTES: Record<ToolCategory, Palette> = {
  plugins: BLUE,
  skills: VIOLET,
  mcp: ["#127576", "#7ed5d0"],
  memory: VIOLET,
  web: BLUE,
  files: ["#8c610c", "#e3bf78"],
  automation: GREEN,
  system: NEUTRAL,
  cli: NEUTRAL,
};

const DETAIL_ICONS = [
  [/\b(artifact|artefakt|artefact)\b/, Shapes],
  [/\b(wiki|recall|knowledge)\b/, BookOpen],
  [/\b(pdf|document|docs|word|read)\b/, FileText],
  [/\b(slides|presentation|powerpoint)\b/, Presentation],
  [/\b(image|design|photo|imagegen)\b/, Image],
  [/\b(search|find|research)\b/, Search],
  [/\b(email|mail)\b/, Mail],
  [/\b(contact|contacts|people)\b/, Users],
  [/\b(database|sql)\b/, Database],
  [/\b(security|audit)\b/, ShieldCheck],
  [/\b(code|coding|develop)\b/, Code2],
  [/\b(write|edit)\b/, PenLine],
  [/\b(click|mouse|pointer)\b/, MousePointer2],
  [/\b(screen|desktop|computer)\b/, Monitor],
  [/\b(workflow|automation)\b/, Workflow],
  [/\b(shell|terminal)\b/, Terminal],
  [/\b(type|hotkey|keyboard)\b/, Keyboard],
  [/\b(app)\b/, AppWindow],
  [/\b(navigate)\b/, Compass],
] as const;

/** The Artifacts section mark — shared by the section and the Add-menu pin. */
export const ARTIFACT_GLYPH = Shapes;
const ARTIFACT_PALETTE: Palette = VIOLET;

function isArtifactRow(row: ToolChoice): boolean {
  const hay = `${row.id} ${row.brand} ${row.group} ${row.label}`.toLowerCase();
  return (
    row.id === "tool:create_artifact" ||
    row.brand.toLowerCase() === "artifact" ||
    /\bartefakt|\bartifact|\bartefact/.test(hay)
  );
}

export function toolIdentity(row: ToolChoice) {
  if (isArtifactRow(row)) {
    return {
      key: "artifact",
      logo: undefined,
      mark: "colour" as const,
      palette: ARTIFACT_PALETTE,
      Glyph: ARTIFACT_GLYPH,
    };
  }
  const cliName = [row.brand, row.label, row.id.replace(/^(cli:|tool:|plugin:)/, "")]
    .map((value) => cliVendor(value || ""))
    .find(Boolean);
  const preferCli = row.category === "cli" || row.id.startsWith("cli:") || Boolean(cliName);
  const key =
    (preferCli ? cliName : undefined) ||
    (row.brand && brandFor(row.brand)) ||
    [row.id, row.group, row.skill, row.label].map((s) => brandFor(s || "")).find(Boolean) ||
    cliName;
  const brand = key ? BRANDS[key] ?? BRANDS[key.replace(/-/g, "_")] ?? BRANDS[key.replace(/_/g, "-")] : undefined;
  const palette = brand?.palette ?? CATEGORY_PALETTES[row.category];
  const words = `${row.id} ${row.skill} ${row.label}`.toLowerCase().replace(/[_:-]/g, " ");
  const Glyph =
    row.category === "mcp"
      ? McpLogo
      : (DETAIL_ICONS.find(([pattern]) => pattern.test(words))?.[1] ??
        CATEGORY_ICONS[row.category]);
  const logo = key ? assetFor(key, preferCli) : undefined;
  const mark =
    isRasterLogo(logo)
      ? "colour"
      : preferCli && key && CLI_VENDOR_LOGOS[key]
        ? CLI_VENDOR_LOGOS[key].render
        : (brand?.mark ?? "colour");
  return {
    key,
    logo,
    mark,
    palette,
    Glyph,
  };
}

function wash(hex: string, opacity: number): string {
  const channels = [1, 3, 5].map((start) => parseInt(hex.slice(start, start + 2), 16));
  return `rgba(${channels.join(",")},${opacity})`;
}

export function toolIdentityStyle(row: ToolChoice): CSSProperties {
  const {
    palette: [light, dark],
  } = toolIdentity(row);
  return {
    "--tool-ink-light": light,
    "--tool-ink-dark": dark,
    "--tool-wash-light": wash(light, 0.07),
    "--tool-wash-dark": wash(dark, 0.09),
  } as CSSProperties;
}