-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathAgentBuilderHeaderControls.tsx
More file actions
124 lines (120 loc) · 4.33 KB
/
Copy pathAgentBuilderHeaderControls.tsx
File metadata and controls
124 lines (120 loc) · 4.33 KB
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
import { SidebarSimpleIcon, SparkleIcon } from "@phosphor-icons/react";
import {
Button,
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@posthog/quill";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
import { Flex } from "@radix-ui/themes";
import { AGENT_PLATFORM_FLAG } from "../featureFlag";
import { headerActionForPage } from "./agentBuilderActions";
import { useAgentBuilderStore } from "./agentBuilderStore";
/**
* The agents-header control cluster — identical across every agents view.
*
* Pinned absolutely to the top-right of the nearest `relative` ancestor so it
* sits on the same row as the Agent Builder dock header (matching `py-2`),
* keeping the two halves of the agents UI visually aligned across views.
*
* One split button is the single entry point into the Agent Builder dock:
* - the primary segment is the contextual "edit with AI" action for the view
* you're on (New agent / Edit configuration / Explain this session / …) — it
* opens the dock and seeds the matching prompt,
* - the trailing segment just opens the dock without seeding, so you can peek
* at the existing conversation; once the dock is open it disappears so we
* don't double up with the dock's own close button.
* Views with no obvious action (Scouts) collapse to the lone open toggle.
* Renders nothing unless the `agent-platform` flag is on.
*/
export function AgentBuilderHeaderControls() {
const enabled = useFeatureFlag(AGENT_PLATFORM_FLAG);
const visible = useAgentBuilderStore((s) => s.visible);
const page = useAgentBuilderStore((s) => s.page);
const toggleVisible = useAgentBuilderStore((s) => s.toggleVisible);
const startAgentBuilder = useAgentBuilderStore((s) => s.startAgentBuilder);
if (!enabled) return null;
const action = headerActionForPage(page);
const openTip = "Open the agent builder (⌘⇧I)";
return (
<TooltipProvider delay={500}>
<Flex
align="center"
gap="2"
className="absolute top-0 right-0 z-10 shrink-0 px-6 py-2"
>
{action ? (
<div className="flex items-center">
<Tooltip>
<TooltipTrigger
render={
<Button
variant="outline"
size="sm"
className={
visible
? "rounded-[3px]"
: "rounded-s-[3px] rounded-e-none"
}
onClick={() =>
startAgentBuilder(action.prompt, action.agentSlug)
}
>
<SparkleIcon
size={14}
weight="fill"
className="text-(--accent-9)"
/>
{action.label}
</Button>
}
/>
<TooltipContent side="top">
Open the agent builder and start here
</TooltipContent>
</Tooltip>
{visible ? null : (
<Tooltip>
<TooltipTrigger
render={
<Button
variant="outline"
size="icon-sm"
className="rounded-s-none rounded-e-[3px] border-s-0"
aria-label={openTip}
onClick={toggleVisible}
>
<SidebarSimpleIcon size={14} weight="regular" />
</Button>
}
/>
<TooltipContent side="top">{openTip}</TooltipContent>
</Tooltip>
)}
</div>
) : visible ? null : (
<Tooltip>
<TooltipTrigger
render={
<Button
variant="outline"
size="icon-sm"
aria-label={openTip}
onClick={toggleVisible}
>
<SparkleIcon
size={14}
weight="fill"
className="text-(--accent-9)"
/>
</Button>
}
/>
<TooltipContent side="top">{openTip}</TooltipContent>
</Tooltip>
)}
</Flex>
</TooltipProvider>
);
}