Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

5.3 KB
Raw Blame
"use client";

import { track } from "@vercel/analytics";
import { Input } from "@vercel/geistdocs/components/input";
import { SearchIcon } from "lucide-react";
import Link from "next/link";
import { useEffect, useMemo, useRef, useState } from "react";
import {
  analyticsEvents,
  getCountBucket,
  getQueryLengthBucket,
  normalizeSearchQuery,
} from "@/lib/analytics/events";
import type { Integration } from "@/lib/integrations/data";
import { filterIntegrations, type GalleryFilter } from "@/lib/integrations/gallery";
import { cn } from "@/lib/utils";
import { IntegrationCard } from "./integration-card";

export type { GalleryFilter };

const FILTERS: { value: GalleryFilter; label: string }[] = [
  { value: "all", label: "All" },
  { value: "channel", label: "Channels" },
  { value: "connection", label: "Connections" },
  { value: "extension", label: "Extensions" },
  { value: "memory", label: "Memory" },
  { value: "instrumentation", label: "Observability" },
];

const FILTER_DESCRIPTIONS: Record<Exclude<GalleryFilter, "all">, string> = {
  channel:
    "Channels are the surfaces where users talk to your agent: Slack, Discord, web chat, and more.",
  connection:
    "Connections are the tools your agent calls during a run: services reached over MCP or OpenAPI.",
  extension: "Extensions are packages that add reusable tools, skills, connections, and hooks.",
  memory: "Memory providers store and recall context across sessions through eve-managed scopes.",
  instrumentation:
    "Observability providers are OpenTelemetry backends that receive your agent's traces: every model call, tool execution, and turn.",
};

interface GalleryProps {
  filter: GalleryFilter;
  integrations: Integration[];
}

export const Gallery = ({ filter, integrations }: GalleryProps) => {
  const [query, setQuery] = useState("");
  const lastTrackedSearch = useRef("");

  const results = useMemo(
    () => filterIntegrations(integrations, filter, query),
    [integrations, filter, query],
  );

  useEffect(() => {
    const normalizedQuery = normalizeSearchQuery(query);
    if (!normalizedQuery) {
      lastTrackedSearch.current = "";
      return;
    }

    const searchKey = `${filter}:${normalizedQuery}`;
    if (searchKey === lastTrackedSearch.current) return;

    const timer = setTimeout(() => {
      track(analyticsEvents.integrationsSearched, {
        filter,
        query: normalizedQuery,
        query_length: getQueryLengthBucket(normalizedQuery),
        results: getCountBucket(results.length),
      });
      lastTrackedSearch.current = searchKey;
    }, 500);

    return () => clearTimeout(timer);
  }, [filter, query, results.length]);

  return (
    <div className="flex min-w-0 flex-col gap-6">
      <div className="flex min-w-0 flex-col gap-3 min-[1024px]:flex-row min-[1024px]:items-center min-[1024px]:justify-between">
        <div
          aria-label="Integration filter"
          className="flex w-full gap-0.5 overflow-x-auto rounded-md border bg-background-100 p-1 [scrollbar-width:none] min-[1024px]:w-fit [&::-webkit-scrollbar]:hidden"
          role="group"
        >
          {FILTERS.map(({ value, label }) => (
            <Link
              aria-current={filter === value ? "page" : undefined}
              className={cn(
                "shrink-0 whitespace-nowrap rounded px-3 py-1 font-medium text-sm no-underline transition-colors",
                filter === value
                  ? "bg-gray-100 text-gray-1000"
                  : "text-gray-900 hover:bg-gray-100/40 hover:text-gray-1000",
              )}
              href={value === "all" ? "/integrations" : `/integrations?filter=${value}`}
              key={value}
              onClick={() => track(analyticsEvents.integrationFilterSelected, { filter: value })}
              prefetch={true}
              scroll={false}
            >
              {label}
            </Link>
          ))}
        </div>
        <Input
          aria-label="Search integrations"
          className="[&_input]:pl-2"
          onChange={(event) => setQuery(event.target.value)}
          placeholder="Search integrations"
          prefix={<SearchIcon aria-hidden="true" className="ml-3 size-4 text-gray-700" />}
          prefixStyling={false}
          value={query}
          wrapperClassName="w-full min-[1024px]:w-64"
        />
      </div>

      {filter !== "all" && <p className="text-gray-800 text-sm">{FILTER_DESCRIPTIONS[filter]}</p>}

      {results.length > 0 ? (
        <div className="grid min-w-0 grid-cols-1 gap-4 min-[1024px]:grid-cols-2 min-[1200px]:grid-cols-3">
          {results.map((integration) => (
            <IntegrationCard
              integration={integration}
              key={integration.slug}
              onSelect={() =>
                track(analyticsEvents.integrationOpened, {
                  filter,
                  integration: integration.slug,
                  search: query.trim().length > 0,
                })
              }
            />
          ))}
        </div>
      ) : (
        <div className="flex flex-col items-center justify-center gap-1 rounded-lg border border-dashed py-16 text-center">
          <p className="font-medium text-gray-1000">No integrations found</p>
          <p className="text-gray-800 text-sm">Try a different search or filter.</p>
        </div>
      )}
    </div>
  );
};