Elffuss BraidHub

kikocis/continue public

main · 3.3 KiBRawPermalink
1import { Cog6ToothIcon } from "@heroicons/react/24/outline";
2import { useContext } from "react";
3import { AssistantIcon } from "../../../components/AssistantAndOrgListbox/AssistantIcon";
4import { ToolTip } from "../../../components/gui/Tooltip";
5import { Button, Card, Divider, EmptyState } from "../../../components/ui";
6import { useAuth } from "../../../context/Auth";
7import { IdeMessengerContext } from "../../../context/IdeMessenger";
8import { useAppSelector } from "../../../redux/hooks";
9import { ConfigHeader } from "../components/ConfigHeader";
10
11export function AgentsSection() {
12 const { profiles, selectedProfile } = useAuth();
13 const ideMessenger = useContext(IdeMessengerContext);
14 const configError = useAppSelector((state) => state.config.configError);
15
16 function handleAddAgent() {
17 void ideMessenger.request("config/newAssistantFile", undefined);
18 }
19
20 function handleConfigureAgent(profileId: string) {
21 ideMessenger.post("config/openProfile", { profileId });
22 }
23
24 return (
25 <>
26 <ConfigHeader
27 title="Agents"
28 onAddClick={handleAddAgent}
29 addButtonTooltip="Add agent"
30 />
31
32 <Card>
33 {profiles && profiles.length > 0 ? (
34 profiles.map((profile, index) => {
35 const isSelected = profile.id === selectedProfile?.id;
36 const errors = isSelected ? configError : profile.errors;
37 return (
38 <div key={profile.id}>
39 <div className="flex items-center justify-between">
40 <div className="flex items-baseline gap-3">
41 <div className="flex h-6 w-6 flex-shrink-0 items-center justify-center">
42 <AssistantIcon assistant={profile} />
43 </div>
44 <div className="flex-1">
45 <h3
46 className={`my-2 text-sm font-medium ${errors && errors.length > 0 ? "text-error" : ""}`}
47 >
48 {profile.title}
49 </h3>
50 {errors && errors.length > 0 && (
51 <div className="mt-2 space-y-1">
52 {errors.map((error, errorIndex) => (
53 <div
54 key={errorIndex}
55 className="text-error bg-error/10 rounded py-1 pr-2 text-xs"
56 >
57 {error.message}
58 </div>
59 ))}
60 </div>
61 )}
62 </div>
63 </div>
64 <ToolTip content="Configure agent">
65 <Button
66 onClick={() => handleConfigureAgent(profile.id)}
67 variant="ghost"
68 size="sm"
69 className="text-description-muted hover:enabled:text-foreground my-0 h-6 w-6 p-0"
70 >
71 <Cog6ToothIcon className="h-4 w-4 flex-shrink-0" />
72 </Button>
73 </ToolTip>
74 </div>
75 {index < profiles.length - 1 && <Divider />}
76 </div>
77 );
78 })
79 ) : (
80 <EmptyState message="No agents configured. Click the + button to add your first agent." />
81 )}
82 </Card>
83 </>
84 );
85}