AgentVersions.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { useTranslation } from "react-i18next";
  2. import { FileCode2 } from "lucide-react";
  3. import { EmptyState } from "@/components/shared/EmptyState";
  4. import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
  5. import { StatusBadge } from "@/components/shared/StatusBadge";
  6. import { formatDateTime } from "@/lib/utils";
  7. import type { AgentVersion } from "@/types";
  8. export function AgentVersions({ versions, loading }: { versions: AgentVersion[]; loading: boolean }) {
  9. const { t } = useTranslation();
  10. if (loading) return <LoadingSpinner label={t("common.loading")} />;
  11. if (!versions.length) return <EmptyState icon={FileCode2} title={t("agents.noVersions")} description={t("agents.createVersionDefine")} />;
  12. const sorted = [...versions].sort((a, b) => b.version_no - a.version_no);
  13. return (
  14. <div className="space-y-3">
  15. {sorted.map((version) => (
  16. <div key={version.id} className="rounded-md border border-border bg-muted/30 p-4">
  17. <div className="flex flex-wrap items-start justify-between gap-3">
  18. <div>
  19. <div className="flex flex-wrap items-center gap-2">
  20. <p className="font-medium">v{version.version_no}</p>
  21. <StatusBadge status={version.status} />
  22. </div>
  23. <p className="mt-1 text-sm text-muted-foreground">{version.goal ?? t("agents.noDescription")}</p>
  24. </div>
  25. <p className="text-xs text-muted-foreground">{formatDateTime(version.created_time)}</p>
  26. </div>
  27. <div className="mt-4 grid gap-3 text-sm md:grid-cols-3">
  28. <div className="min-w-0">
  29. <p className="text-muted-foreground">{t("agents.role")}</p>
  30. <p className="mt-1">{version.role}</p>
  31. </div>
  32. <div className="min-w-0">
  33. <p className="text-muted-foreground">{t("agents.model")}</p>
  34. <p className="mt-1 truncate font-mono text-xs">{stringifyConfigValue(version.model_config_json.model) ?? t("agents.noDescription")}</p>
  35. </div>
  36. <div className="min-w-0">
  37. <p className="text-muted-foreground">{t("agents.published")}</p>
  38. <p className="mt-1">{version.published_time ? formatDateTime(version.published_time) : t("agents.notPublished")}</p>
  39. </div>
  40. </div>
  41. </div>
  42. ))}
  43. </div>
  44. );
  45. }
  46. function stringifyConfigValue(value: unknown) {
  47. if (typeof value === "string") return value;
  48. if (typeof value === "number" || typeof value === "boolean") return String(value);
  49. return undefined;
  50. }