Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

13.4 KB
Raw Blame
import { docs } from '@/.source';
import { loader } from 'fumadocs-core/source';
import { icons } from 'lucide-react';
import { cloneElement, createElement } from 'react';
import { SiAnthropic, SiGooglegemini, SiMeta, SiOllama, SiOpenai } from 'react-icons/si';

import fs from 'node:fs/promises';
import path from 'node:path';

// Custom brand icons (not available in Lucide)
const brandIcons: Record<string, () => React.ReactElement> = {
  anthropic: () => createElement(SiAnthropic, { className: 'w-4 h-4' }),
  gemini: () => createElement(SiGooglegemini, { className: 'w-4 h-4' }),
  meta: () => createElement(SiMeta, { className: 'w-4 h-4' }),
  ollama: () => createElement(SiOllama, { className: 'w-4 h-4' }),
  openai: () => createElement(SiOpenai, { className: 'w-4 h-4' }),
  github: () =>
    createElement(
      'svg',
      {
        viewBox: '0 0 24 24',
        fill: 'currentColor',
        className: 'w-4 h-4',
      },
      createElement('path', {
        d: 'M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z',
      })
    ),
  discord: () =>
    createElement(
      'svg',
      {
        viewBox: '0 0 24 24',
        fill: 'currentColor',
        className: 'w-4 h-4',
      },
      createElement('path', {
        d: 'M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z',
      })
    ),
  'claude-code': () =>
    createElement(
      'svg',
      {
        viewBox: '0 0 24 24',
        fill: '#D97757',
        className: 'w-4 h-4',
      },
      createElement('path', {
        d: 'M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z',
        fillRule: 'nonzero',
      })
    ),
  laminar: () =>
    createElement(
      'svg',
      {
        viewBox: '0 16 76 76',
        fill: 'currentColor',
        className: 'w-4 h-4',
      },
      createElement('path', {
        fillRule: 'evenodd',
        clipRule: 'evenodd',
        d: 'M0.653968 84.1461C0.0802819 85.9866 0.00220402 88.0862 1.32507 89.4885C2.78376 91.0347 4.85185 91.9999 7.14535 91.9999H37.1454C58.1322 91.9999 75.1454 74.9867 75.1454 53.9999C75.1454 33.013 58.1322 15.9999 37.1454 15.9999H7.14535C4.56777 15.9999 2.27491 17.2189 0.811824 19.1119C-0.266346 20.5068-0.129499 22.4002 0.408998 24.079C3.48464 33.6675 5.14534 43.8898 5.14534 54.4999C5.14534 64.8247 3.57273 74.7823 0.653968 84.1461Z',
      })
    ),
  hud: () =>
    createElement(
      'svg',
      {
        viewBox: '140 320 750 350',
        fill: 'currentColor',
        className: 'w-4 h-4',
      },
      createElement('path', {
        d: 'M153.488 660.583V634.232H177.478V386.173L147.604 372.544V353.917L232.247 332.109H248.995V476.129L249.9 476.583C269.364 451.141 291.543 432.06 324.586 432.06C362.608 432.06 388.408 461.136 388.408 506.568V634.232H408.325V660.583H298.333V634.232H316.891V502.025C316.891 484.307 310.102 479.763 294.712 479.763C278.417 479.763 263.027 484.761 248.995 495.21V634.232H267.553V660.583H153.488Z',
      }),
      createElement('path', {
        d: 'M467.193 664.217C428.719 664.217 403.371 635.595 403.371 589.709V465.68H378.928V439.329H474.888V598.795C474.888 616.06 481.678 621.057 496.615 621.057C514.268 621.057 527.847 612.879 542.784 601.067V465.68H516.984V439.329H614.301V618.785L642.818 631.052V648.771L562.248 662.854H545.953V618.331L545.047 617.877C523.773 644.227 500.688 664.217 467.193 664.217Z',
      }),
      createElement('path', {
        d: 'M716.334 664.217C666.996 664.217 623.995 623.329 623.995 546.549C623.995 470.223 674.691 432.06 726.292 432.06C752.092 432.06 771.103 442.509 785.588 457.956V386.173L753.903 372.544V353.917L839.905 332.109H856.653V618.785L885.622 631.052V648.771L805.051 662.854H788.304V621.057L787.398 620.603C768.388 647.408 747.566 664.217 716.334 664.217ZM739.419 630.143C759.335 630.143 773.819 614.697 785.588 599.25V481.126C774.725 472.949 762.503 467.042 746.208 467.042C732.629 467.042 723.123 472.04 716.786 479.763C708.639 489.758 704.113 515.655 704.113 551.546C704.113 589.255 709.092 612.879 717.239 621.511C723.576 627.872 730.366 630.143 739.419 630.143Z',
      })
    ),
  yutori: () =>
    createElement(
      'svg',
      {
        viewBox: '0 0 64 16',
        fill: 'currentColor',
        className: 'w-4 h-4',
      },
      createElement('path', {
        d: 'M60.4103 3.57025C59.896 3.57025 59.4699 3.40129 59.132 3.06336C58.7941 2.72544 58.6251 2.29936 58.6251 1.78512C58.6251 1.27089 58.7941 0.844812 59.132 0.506887C59.4699 0.168963 59.896 0 60.4103 0C60.9245 0 61.3506 0.168963 61.6885 0.506887C62.0264 0.844812 62.1954 1.27089 62.1954 1.78512C62.1954 2.29936 62.0264 2.72544 61.6885 3.06336C61.3506 3.40129 60.9245 3.57025 60.4103 3.57025ZM56.9502 15.7796V15.427L58.4709 14.7218V7.93388L57.0163 6.98623V6.63361L62.0852 5.42149H62.4378V14.7218L63.694 15.427V15.7796H56.9502Z',
      }),
      createElement('path', {
        d: 'M46.9587 15.78V15.4274L48.4794 14.7222V8.15466L47.0249 7.207V6.85438L51.8733 5.42188H52.226L52.4243 7.47146H52.5345C52.9165 6.89846 53.2471 6.46503 53.5262 6.17119C53.8054 5.87734 54.0625 5.67899 54.2976 5.57614C54.5474 5.4733 54.8265 5.42188 55.135 5.42188C55.2673 5.42188 55.4069 5.43657 55.5538 5.46595C55.7007 5.49534 55.8403 5.53207 55.9725 5.57614C56.2223 5.64961 56.3912 5.74511 56.4794 5.86265C56.5822 5.96549 56.6337 6.08303 56.6337 6.21526C56.6337 6.31811 56.6116 6.43565 56.5676 6.56788L55.9725 8.24281H55.8182L55.4216 8.11058C55.1718 8.02243 54.9514 7.96366 54.7604 7.93427C54.5841 7.89019 54.3564 7.86816 54.0772 7.86816C53.754 7.86816 53.4528 7.94896 53.1736 8.11058C52.8945 8.2575 52.652 8.4485 52.4463 8.68358V14.7222L54.3637 15.4274V15.78H46.9587Z',
      }),
      createElement('path', {
        d: 'M40.8815 16.0004C39.7943 16.0004 38.8319 15.758 37.9945 15.2731C37.157 14.7736 36.5032 14.1271 36.0331 13.3337C35.5776 12.5256 35.3499 11.6514 35.3499 10.7111C35.3499 9.77082 35.5776 8.89662 36.0331 8.08854C36.5032 7.28046 37.157 6.634 37.9945 6.14915C38.8319 5.6643 39.7943 5.42188 40.8815 5.42188C41.9688 5.42188 42.9311 5.6643 43.7686 6.14915C44.6061 6.634 45.2525 7.28046 45.708 8.08854C46.1781 8.89662 46.4132 9.77082 46.4132 10.7111C46.4132 11.6514 46.1781 12.5256 45.708 13.3337C45.2525 14.1271 44.6061 14.7736 43.7686 15.2731C42.9311 15.758 41.9688 16.0004 40.8815 16.0004ZM41.0799 14.8323C41.3884 14.8323 41.6455 14.6634 41.8512 14.3255C42.0569 13.9875 42.2038 13.5468 42.292 13.0031C42.3948 12.4448 42.4463 11.8278 42.4463 11.1519C42.4463 10.3291 42.3875 9.57247 42.27 8.88193C42.1524 8.19139 41.9614 7.63308 41.697 7.207C41.4472 6.78092 41.124 6.56788 40.7273 6.56788C40.3893 6.56788 40.1175 6.73684 39.9118 7.07477C39.7061 7.398 39.5519 7.83877 39.449 8.39708C39.3609 8.9407 39.3168 9.55778 39.3168 10.2483C39.3168 11.0564 39.3756 11.8131 39.4931 12.5183C39.6253 13.2088 39.8163 13.7671 40.0661 14.1932C40.3306 14.6193 40.6685 14.8323 41.0799 14.8323Z',
      }),
      createElement('path', {
        d: 'M31.9897 16.0001C30.9318 16.0001 30.0797 15.8091 29.4332 15.4271C28.7867 15.0451 28.4635 14.5089 28.4635 13.8183V6.61171H27.031V6.19298L29.1687 5.64202L31.7913 3.21777H32.4305V5.64202H35.5599V6.61171H32.4305V13.1351C32.4305 13.5171 32.5847 13.7963 32.8933 13.9726C33.2165 14.1489 33.5912 14.2371 34.0172 14.2371C34.2817 14.2371 34.5094 14.2224 34.7004 14.193C34.9061 14.1636 35.1192 14.1269 35.3395 14.0828L35.4057 14.1269V14.6117C35.1118 14.979 34.6343 15.3023 33.9732 15.5814C33.3267 15.8606 32.6655 16.0001 31.9897 16.0001Z',
      }),
      createElement('path', {
        d: 'M18.6262 15.9997C17.73 15.9997 16.9953 15.7647 16.4223 15.2945C15.864 14.8243 15.5849 14.1264 15.5849 13.2008V6.69945L14.0642 5.99422V5.6416H19.5518V12.3854C19.5518 12.8115 19.662 13.1421 19.8824 13.3771C20.1028 13.5975 20.3819 13.7077 20.7199 13.7077C20.9109 13.7077 21.1092 13.6636 21.3149 13.5755C21.5353 13.4873 21.7336 13.3845 21.9099 13.2669V6.69945L20.7199 5.99422V5.6416H25.8769V14.7215L27.1331 15.4267V15.7793H21.9099V14.3689H21.8218C21.3369 14.8537 20.8594 15.2504 20.3893 15.559C19.9191 15.8528 19.3314 15.9997 18.6262 15.9997Z',
      }),
      createElement('path', {
        d: 'M4.69158 15.7798V15.4272L6.65302 14.5016V8.99195L1.89269 2.51261L0.305908 1.58699V1.23438H8.08552V1.58699L6.38855 2.4465V2.53465L10.1571 7.60352L13.529 2.57873V2.49057L11.766 1.58699V1.23438H17.0111V1.58699L15.4905 2.31427L10.8403 8.99195V14.5016L12.8018 15.4272V15.7798H4.69158Z',
      })
    ),
};

// Icon resolver
function iconResolver(icon: string | undefined) {
  if (!icon) return;
  // Check brand icons first (github, discord, etc.)
  if (icon in brandIcons) return cloneElement(brandIcons[icon](), { key: icon });
  // Fall back to Lucide icons
  if (icon in icons) return createElement(icons[icon as keyof typeof icons], { key: icon });
}

/**
 * Returns available API doc versions for a given section (e.g., 'agent').
 * Each version is an object: { label, slug }
 * - 'Current' (index.mdx) → slug: []
 * - '[version].mdx' → slug: [version]
 */
export async function getApiVersions(
  section: string
): Promise<{ label: string; slug: string[] }[]> {
  const dir = path.join(process.cwd(), 'content/docs/api', section);
  let files: string[] = [];
  try {
    files = (await fs.readdir(dir)).filter((f) => f.endsWith('.mdx'));
  } catch (_e) {
    return [];
  }
  const versions = files.map((file) => {
    if (file === 'index.mdx') {
      return { label: 'Current', slug: [] };
    }
    const version = file.replace(/\.mdx$/, '');
    return { label: version, slug: [version] };
  });
  // Always put 'Current' first, then others sorted descending (semver-ish)
  return [
    ...versions.filter((v) => v.label === 'Current'),
    ...versions
      .filter((v) => v.label !== 'Current')
      .sort((a, b) => b.label.localeCompare(a.label, undefined, { numeric: true })),
  ];
}

// Single docs source
export const source = loader({
  baseUrl: '/',
  source: docs.toFumadocsSource(),
  icon: iconResolver,
  plugins: [
    {
      name: 'sidebar-title',
      // `sidebarTitle` in a page's frontmatter labels it in the sidebar.
      transformPageTree: {
        file(node, filePath) {
          const file = filePath ? this.storage.read(filePath) : undefined;
          const label =
            file?.format === 'page'
              ? (file.data as { sidebarTitle?: string }).sidebarTitle
              : undefined;
          return label ? { ...node, name: label } : node;
        },
      },
    },
  ],
});