Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 3x 5x 5x 20x 28x 57x 15x 5x 3x 5x 8x 12x 1x 1x | import { AppearanceSwatch } from "@/components/appearance/AppearancePicker";
import { REPOSITORY_ICON_REGISTRY } from "@/components/appearance/icons";
import BuiltInBadge from "@/components/badge/BuiltInBadge";
import { isSystemManaged } from "@/objects/Doc";
import type { KnowledgeCategoryKey, KnowledgeRepository } from "@/objects/Knowledge";
import { FolderGit2, X } from "lucide-react";
import React, { useState } from "react";
import {
byCategory,
KNOWLEDGE_CATEGORIES,
knowledgeCategory,
} from "../../knowledge/categories";
/**
* The agent page's picker for granting a repository: the workspace's own and
* the built-ins, by kind, the workspace's own first within each.
*
* Opened from a missing kind (the Knowledge tab's empty kind, the "What this
* agent draws on" panel), it shows that kind alone, with "Show every kind"
* for the rest.
*/
const AddRepositoryModal: React.FC<{
available: KnowledgeRepository[];
assignedIds: Set<string>;
onAdd: (repo: KnowledgeRepository) => void;
onClose: () => void;
/** Opened for one kind of knowledge (a missing kind's Attach): that kind
* alone, until the person asks for every kind. */
category?: KnowledgeCategoryKey | null;
}> = ({ available, assignedIds, onAdd, onClose, category = null }) => {
const [everyKind, setEveryKind] = useState(category === null);
// By kind, and within each the user's own first, the platform's built-ins
// after.
const unassigned = available
.filter((r) => !assignedIds.has(r.id))
.sort(
(a, b) => Number(isSystemManaged(a)) - Number(isSystemManaged(b)),
);
const groups = byCategory(unassigned, (r) => r.category).filter(
([meta, repos]) =>
repos.length > 0 && (everyKind || meta.key === category),
);
// Other kinds were left out: say so, and offer them.
const hidden =
!everyKind &&
unassigned.some((r) => knowledgeCategory(r.category).key !== category);
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/40">
<div className="w-full max-w-md rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 shadow-xl">
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100 dark:border-gray-700">
<div className="flex items-center gap-2">
<FolderGit2 className="size-4 text-violet-500 dark:text-violet-400" />
<h2 className="text-sm font-semibold text-gray-800 dark:text-gray-200">
Attach Repository
</h2>
</div>
<button
onClick={onClose}
className="p-1 rounded text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-colors"
>
<X className="size-4" />
</button>
</div>
<div className="p-5 space-y-2 max-h-96 overflow-y-auto">
{unassigned.length === 0 ? (
<p className="text-sm text-gray-400 dark:text-gray-500 italic text-center py-4">
All your repositories are already attached.
</p>
) : groups.length === 0 ? (
<p className="text-sm text-gray-400 dark:text-gray-500 italic text-center py-4">
No {category ? KNOWLEDGE_CATEGORIES[category].label.toLowerCase() : ""}{" "}
repositories to attach.
</p>
) : (
groups.map(([meta, repos]) => (
<div key={meta.key} className="space-y-2">
<div className="flex items-center gap-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-gray-400">
<meta.Icon className="size-3.5" aria-hidden="true" />
{meta.label}
<span className="font-normal text-gray-400 dark:text-gray-500 truncate">
ยท {meta.use}
</span>
</div>
{repos.map((repo) => (
<button
key={repo.id}
type="button"
onClick={() => onAdd(repo)}
className="w-full flex items-start gap-3 px-4 py-3 rounded-lg border border-gray-200 dark:border-gray-600 hover:border-violet-400 dark:hover:border-violet-500 bg-white dark:bg-gray-800 text-left transition-colors group"
>
<AppearanceSwatch
registry={REPOSITORY_ICON_REGISTRY}
icon={repo.icon}
accent={repo.accent}
size="sm"
className="mt-0.5"
/>
<div className="min-w-0 flex-1">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<div className="text-sm font-medium text-gray-800 dark:text-gray-200 truncate">
{repo.name}
</div>
{isSystemManaged(repo) && <BuiltInBadge size="sm" />}
</div>
<span className="text-xs text-gray-400 dark:text-gray-500 tabular-nums shrink-0">
{repo.knowledge_ids.length} source
{repo.knowledge_ids.length !== 1 ? "s" : ""}
</span>
</div>
{repo.description && (
<div className="text-xs text-gray-500 dark:text-gray-400 mt-0.5 line-clamp-2">
{repo.description}
</div>
)}
</div>
</button>
))}
</div>
))
)}
{hidden && (
<button
type="button"
onClick={() => setEveryKind(true)}
className="w-full pt-1 text-xs text-gray-500 dark:text-gray-400 underline hover:text-gray-700 dark:hover:text-gray-200"
>
Show every kind
</button>
)}
</div>
</div>
</div>
);
};
export default AddRepositoryModal;
|