Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend/copilot): voice mode in the + menu; model and token usage open as dialogs (#15585)

Ubbe35412eb0acac
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
index 2b9af69531..8d1f5662c8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
@@ -524,18 +524,16 @@ export const ChatContainer = ({
expertId={expertIdentity?.id ?? null}
modeSelector={modeSelector}
expertName={expertIdentity?.name ?? null}
- voiceToggle={
- isVoiceModeEnabled ? (
- <VoiceModeButton
- isActive={voice.isActive}
- disabled={
- isInputDisabled ||
- isSendLocked ||
- voice.isStarting
+ voiceMode={
+ isVoiceModeEnabled
+ ? {
+ onStart: voice.toggle,
+ disabled:
+ isInputDisabled ||
+ isSendLocked ||
+ voice.isStarting,
}
- onClick={voice.toggle}
- />
- ) : undefined
+ : undefined
}
voiceBar={
voice.isActive ? (
@@ -575,16 +573,14 @@ export const ChatContainer = ({
onCreateSession={onCreateSession}
onSend={guardedOnSend}
modeSelector={modeSelector}
- voiceToggle={
- isVoiceModeEnabled ? (
- <VoiceModeButton
- isActive={false}
- disabled={
- isInputDisabled || isSendLocked || isCreatingSession
+ voiceMode={
+ isVoiceModeEnabled
+ ? {
+ onStart: handleStartVoiceInNewChat,
+ disabled:
+ isInputDisabled || isSendLocked || isCreatingSession,
}
- onClick={handleStartVoiceInNewChat}
- />
- ) : undefined
+ : undefined
}
isUploadingFiles={isUploadingFiles}
droppedFiles={droppedFiles}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
index 1c092cb413..7be9fcffea 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
@@ -38,7 +38,7 @@ import {
import { DryRunToggleButton } from "./components/DryRunToggleButton";
import { FileChips } from "./components/FileChips";
import { MentionDropdown } from "./components/MentionDropdown";
-import { ConnectionPicker } from "./components/ConnectionPicker/ConnectionPicker";
+import { ConnectionPickerDialog } from "./components/ConnectionPicker/ConnectionPickerDialog";
import { NoAIConnectionNotice } from "./components/NoAIConnectionNotice/NoAIConnectionNotice";
import { RecordingButton } from "./components/RecordingButton";
import { RecordingIndicator } from "./components/RecordingIndicator";
@@ -47,7 +47,7 @@ import { TranscriptionErrorBar } from "./components/TranscriptionErrorBar";
import { WorkspaceFilePicker } from "./components/WorkspaceFilePicker/WorkspaceFilePicker";
import { useCopilotUIStore } from "../../store";
import { isTokenDevtoolEnabled } from "../../tokenDevtool/gate";
-import { TokenDevtoolBadge } from "../TokenDevtoolBadge/TokenDevtoolBadge";
+import { TokenDevtoolDialog } from "../TokenDevtoolBadge/TokenDevtoolDialog";
import {
sendAtResetFailureTitle,
SEND_AT_RESET_LABEL,
@@ -69,6 +69,7 @@ import {
ArrowUp02Icon,
DashboardSpeed02Icon,
FlashIcon,
+ VoiceIcon,
} from "@hugeicons/core-free-icons";
import { Icon } from "@/components/atoms/Icon/Icon";
@@ -107,8 +108,8 @@ interface Props {
/** Card composer: the text always keeps its own row above the controls,
* instead of sharing a single pill row until it wraps. Empty state only. */
stacked?: boolean;
- /** Voice-mode toggle, rendered beside the mic. Absent when the flag is off. */
- voiceToggle?: ReactNode;
+ /** Starts voice mode from the + menu. Absent when the flag is off. */
+ voiceMode?: { onStart: () => void; disabled?: boolean };
/** The chat's approval-mode selector. Absent when the flag is off. */
modeSelector?: ReactNode;
/**
@@ -153,7 +154,7 @@ export function ChatInput({
hideSubmitWhenEmpty = false,
recipientPicker,
stacked = false,
- voiceToggle,
+ voiceMode,
modeSelector,
voiceBar,
variant = "default",
@@ -368,24 +369,33 @@ export function ChatInput({
}
const isCompact = variant === "compact";
- // Model tier and the dev token readout sit behind the + instead of as
- // icons in the tray; their sheets anchor to the + side of the composer.
+ // Voice mode, model tier and the dev token readout sit behind the +
+ // instead of as icons in the tray; the last two open in a dialog.
const [plusPanel, setPlusPanel] = useState<"model" | "devtool" | null>(null);
const showModelControl =
!stacked && !isCompact && (!hasSession || !isStreaming);
- // Wait for the menu to close and hand focus back before the sheet opens,
- // or the returning focus dismisses it straight away.
- function openPlusPanel(panel: "model" | "devtool") {
- setTimeout(() => setPlusPanel(panel), 0);
+ if (!showModelControl && plusPanel === "model") {
+ setPlusPanel(null);
}
const plusMenuItems: ComposerMenuItem[] = [
+ ...(voiceMode
+ ? [
+ {
+ key: "voice",
+ label: "Voice mode",
+ icon: VoiceIcon,
+ disabled: voiceMode.disabled,
+ onSelect: voiceMode.onStart,
+ },
+ ]
+ : []),
...(showModelControl
? [
{
key: "model",
label: "Model and connection",
icon: FlashIcon,
- onSelect: () => openPlusPanel("model"),
+ onSelect: () => setPlusPanel("model"),
},
]
: []),
@@ -395,7 +405,7 @@ export function ChatInput({
key: "devtool",
label: "Token usage",
icon: DashboardSpeed02Icon,
- onSelect: () => openPlusPanel("devtool"),
+ onSelect: () => setPlusPanel("devtool"),
},
]
: []),
@@ -411,11 +421,10 @@ export function ChatInput({
? COMPACT_SEND_BUTTON_CLASS
: MOBILE_SEND_BUTTON_CLASS;
- // Per-message settings and voice mode sit behind the "..." button, so the
- // row stays usable at phone width. Model and token usage live in the + menu.
+ // Per-message settings sit behind the "..." button, so the row stays
+ // usable at phone width.
const showDryRunToggle = showAdvancedComposerControls && !hasSession;
- const hasOverflowControls =
- !!modeSelector || showDryRunToggle || !!voiceToggle;
+ const hasOverflowControls = !!modeSelector || showDryRunToggle;
return (
<form onSubmit={handleSubmit} className={cn("relative flex-1", className)}>
@@ -510,22 +519,6 @@ export function ChatInput({
}
/>
{recipientPicker}
- {showModelControl && (
- <ConnectionPicker
- connectionLocked={hasSession}
- anchorOnly
- open={plusPanel === "model"}
- onOpenChange={(open) => setPlusPanel(open ? "model" : null)}
- />
- )}
- {devtoolSessionId && (
- <TokenDevtoolBadge
- sessionId={devtoolSessionId}
- anchorOnly
- open={plusPanel === "devtool"}
- onOpenChange={(open) => setPlusPanel(open ? "devtool" : null)}
- />
- )}
</InputGroupAddon>
{/* Must be a real flex item: `order`/`w-full` are ignored on a
`display: contents` box, which is what PromptInputBody was. */}
@@ -583,7 +576,6 @@ export function ChatInput({
onToggle={handleToggleDryRun}
/>
)}
- {voiceToggle}
</ComposerOverflowMenu>
)}
{showMicButton && (
@@ -647,6 +639,20 @@ export function ChatInput({
Press Enter to send, Shift+Enter for new line, Space to record voice
</span>
</InputGroup>
+ {showModelControl && (
+ <ConnectionPickerDialog
+ connectionLocked={hasSession}
+ open={plusPanel === "model"}
+ onOpenChange={(open) => setPlusPanel(open ? "model" : null)}
+ />
+ )}
+ {devtoolSessionId && (
+ <TokenDevtoolDialog
+ sessionId={devtoolSessionId}
+ open={plusPanel === "devtool"}
+ onOpenChange={(open) => setPlusPanel(open ? "devtool" : null)}
+ />
+ )}
{showWorkspaceFiles && (
<WorkspaceFilePicker
key={expertId ?? "everyone"}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
index 189185e32a..39237b2a31 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
@@ -207,7 +207,12 @@ vi.mock("../components/ComposerPlusMenu", () => ({
extraItems = [],
}: {
onClearGuidedPrompt?: () => void;
- extraItems?: { key: string; label: string; onSelect: () => void }[];
+ extraItems?: {
+ key: string;
+ label: string;
+ onSelect: () => void;
+ disabled?: boolean;
+ }[];
}) => (
<>
<button
@@ -220,6 +225,7 @@ vi.mock("../components/ComposerPlusMenu", () => ({
key={item.key}
type="button"
role="menuitem"
+ disabled={item.disabled}
onClick={item.onSelect}
>
{item.label}
@@ -340,6 +346,98 @@ describe("ChatInput token devtool entry", () => {
});
});
+describe("ChatInput + menu entries", () => {
+ it("starts voice mode from the + menu, not the overflow panel", () => {
+ const onStart = vi.fn();
+ render(
+ <ChatInput
+ onSend={mockOnSend}
+ sessionId="session-1"
+ voiceMode={{ onStart }}
+ />,
+ );
+
+ fireEvent.click(screen.getByRole("menuitem", { name: "Voice mode" }));
+
+ expect(onStart).toHaveBeenCalledTimes(1);
+ expect(screen.queryByTestId("composer-overflow-button")).toBeNull();
+ });
+
+ it("keeps Voice mode out of the menu when the flag is off", () => {
+ render(<ChatInput onSend={mockOnSend} sessionId="session-1" />);
+
+ expect(screen.queryByRole("menuitem", { name: "Voice mode" })).toBeNull();
+ });
+
+ it("disables Voice mode while it cannot start", () => {
+ render(
+ <ChatInput
+ onSend={mockOnSend}
+ sessionId="session-1"
+ voiceMode={{ onStart: vi.fn(), disabled: true }}
+ />,
+ );
+
+ const item = screen.getByRole("menuitem", {
+ name: "Voice mode",
+ }) as HTMLButtonElement;
+ expect(item.disabled).toBe(true);
+ });
+
+ it("opens Model and connection in a dialog, even with nothing to choose", async () => {
+ // The mocked lone connection has one model behind both tiers, which is
+ // the case where the old anchored sheet rendered nothing at all.
+ render(<ChatInput onSend={mockOnSend} />);
+
+ fireEvent.click(
+ screen.getByRole("menuitem", { name: "Model and connection" }),
+ );
+
+ expect(await screen.findByText("AutoGPT Platform")).toBeDefined();
+ });
+
+ it.each([
+ { isStreaming: true },
+ { stacked: true },
+ { variant: "compact" as const },
+ ])(
+ "keeps the model dialog closed after hiding its control: %o",
+ async (props) => {
+ const { rerender } = render(<ChatInput onSend={mockOnSend} hasSession />);
+
+ fireEvent.click(
+ screen.getByRole("menuitem", { name: "Model and connection" }),
+ );
+ expect(
+ await screen.findByRole("dialog", { name: "Model and connection" }),
+ ).toBeDefined();
+
+ rerender(<ChatInput onSend={mockOnSend} hasSession {...props} />);
+ expect(screen.queryByRole("dialog")).toBeNull();
+
+ rerender(<ChatInput onSend={mockOnSend} hasSession />);
+ expect(screen.queryByRole("dialog")).toBeNull();
+
+ fireEvent.click(
+ screen.getByRole("menuitem", { name: "Model and connection" }),
+ );
+ expect(
+ await screen.findByRole("dialog", { name: "Model and connection" }),
+ ).toBeDefined();
+ },
+ );
+
+ it("opens Token usage in a dialog", async () => {
+ mockTokenDevtoolEnabled = true;
+ render(<ChatInput onSend={mockOnSend} sessionId="session-1" />);
+
+ expect(screen.queryByText("Context window")).toBeNull();
+ fireEvent.click(screen.getByRole("menuitem", { name: "Token usage" }));
+
+ expect(await screen.findByText("Context window")).toBeDefined();
+ });
+});
+
describe("ChatInput Codex route", () => {
it("keeps Claude SDK file attachments available for the Codex route", () => {
mockCopilotLlmAuthProvider = "codex";
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
index 746b0d9d00..02b466c585 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
@@ -33,7 +33,7 @@ interface Props {
isAtCap?: boolean;
className?: string;
/** Composer settings that live behind the + rather than as icons in the
- * tray (model tier, the dev token readout). */
+ * tray (voice mode, model tier, the dev token readout). */
extraItems?: ComposerMenuItem[];
}
@@ -42,6 +42,7 @@ export interface ComposerMenuItem {
label: string;
icon: IconSvgElement;
onSelect: () => void;
+ disabled?: boolean;
}
export function ComposerPlusMenu({
@@ -162,7 +163,11 @@ export function ComposerPlusMenu({
</DropdownMenuItem>
{extraItems.length > 0 && <DropdownMenuSeparator />}
{extraItems.map((item) => (
- <DropdownMenuItem key={item.key} onSelect={item.onSelect}>
+ <DropdownMenuItem
+ key={item.key}
+ disabled={item.disabled}
+ onSelect={item.onSelect}
+ >
<Icon icon={item.icon} className="mr-2 h-4 w-4" />
{item.label}
</DropdownMenuItem>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPicker.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPicker.tsx
index 5a0d3553c1..a1f2061ed1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPicker.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPicker.tsx
@@ -2,7 +2,6 @@
import {
Popover,
- PopoverAnchor,
PopoverContent,
PopoverTrigger,
} from "@/components/molecules/Popover/Popover";
@@ -11,42 +10,29 @@ import {
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
-import type { AIConnectionOffer } from "@/app/api/__generated__/models/aIConnectionOffer";
import {
AlertCircleIcon,
ArrowDown01Icon,
AiBrain01Icon,
- CloudServerIcon,
FlashIcon,
} from "@hugeicons/core-free-icons";
import Link from "next/link";
import { Button } from "@/components/atoms/Button/Button";
import { Icon } from "@/components/atoms/Icon/Icon";
-import { IntegrationLogo } from "@/components/molecules/IntegrationLogo/IntegrationLogo";
import { cn } from "@/lib/utils";
-import { ChoiceRow } from "./ChoiceRow";
-import { ConnectAccountRow } from "./ConnectAccountRow";
-import { MaxUpgradeCard } from "./MaxUpgradeCard";
+import { ConnectionPickerPanel } from "./ConnectionPickerPanel";
import { Swap } from "./Swap";
import {
isLinkedAccount,
- isSelectable,
- offerSubtitle,
+ listedConnections,
tierLabel,
- tierModel,
- tierName,
tierLock,
- tierSummary,
+ tierName,
} from "./helpers";
-import { isComposingEvent } from "@/lib/keyboard";
-import { nextRovingValue, rovingTabIndex } from "./radioKeys";
-import { TierToggle } from "./TierToggle";
import { useConnectionPicker } from "./useConnectionPicker";
-const TIERS = ["standard", "advanced"] as const;
-
interface Props {
/**
* The connection is settled and only the tier is still open.
@@ -58,11 +44,6 @@ interface Props {
*/
connectionLocked?: boolean;
className?: string;
- /** Opened from somewhere else (the composer's + menu): no chip of its
- * own, the sheet anchors to its parent box instead. */
- anchorOnly?: boolean;
- open?: boolean;
- onOpenChange?: (open: boolean) => void;
}
/**
@@ -73,24 +54,17 @@ interface Props {
export function ConnectionPicker({
connectionLocked = false,
className,
- anchorOnly = false,
- open,
- onOpenChange,
}: Props) {
+ const picker = useConnectionPicker();
const {
offers,
active,
- chooseConnection,
tier,
- setTier,
showTiers,
hasConnectionChoice,
- connectChatGPT,
- isConnecting,
- canConnectChatGPT,
isLoading,
isError,
- } = useConnectionPicker();
+ } = picker;
const advancedLock = tierLock(active, "advanced");
const showMaxUpgrade =
active?.auth_method === "deployment" && Boolean(advancedLock);
@@ -141,10 +115,6 @@ export function ConnectionPicker({
return null;
}
- const connectionOptions = offers.map((offer) => ({
- value: offer.offer_id,
- disabled: !isSelectable(offer),
- }));
const runsOnOwnPlan = active ? isLinkedAccount(active) : false;
// With no connection to choose between, naming it says nothing — a hosted
// user would read "AutoGPT Platform" on every chat and learn only that there
@@ -165,12 +135,6 @@ export function ConnectionPicker({
// so.
const triggerLabel =
runsOnOwnPlan && !showsTier ? `${label} · your plan` : label;
- // One runnable row is nothing to choose between. A locked-only row is
- // different: the explanation and unlock link are the entire reason the chip
- // remains visible.
- const showsConnections =
- (!connectionLocked || onlyOfferIsLocked) &&
- (offers.length > 1 || onlyOfferIsLocked);
// Naming only the tier, the chip folds down to its glyph among the other
// quiet icons on the composer's right; the tier and its model wait in the
@@ -221,12 +185,8 @@ export function ConnectionPicker({
);
return (
- <Popover open={open} onOpenChange={onOpenChange}>
- {anchorOnly ? (
- <PopoverAnchor asChild>
- <span aria-hidden className="pointer-events-none absolute inset-0" />
- </PopoverAnchor>
- ) : showsTier ? (
+ <Popover>
+ {showsTier ? (
<Tooltip>
<TooltipTrigger asChild>{trigger}</TooltipTrigger>
<TooltipContent side="top">{tierLabel(active, tier)}</TooltipContent>
@@ -236,149 +196,17 @@ export function ConnectionPicker({
)}
<PopoverContent
- align={anchorOnly ? "start" : "end"}
- side={anchorOnly ? "top" : undefined}
+ align="end"
className={cn(
"max-h-[var(--radix-popover-content-available-height)] w-[24rem] max-w-[calc(100vw-2rem)] overflow-y-auto rounded-2xl border-zinc-200 bg-[#F9F9FA] p-3 pt-4 text-zinc-900 shadow-lg",
showMaxUpgrade && "bg-white",
)}
>
- {showsConnections && (
- <>
- <SectionLabel>Runs on</SectionLabel>
- <div
- role="radiogroup"
- aria-label="Connection this chat runs on"
- // The connections read as plain rows on the sheet: a card around
- // them would frame the choice twice, once here and once around
- // the tiers below.
- className="overflow-hidden rounded-xl"
- onKeyDown={(event) => {
- // `event.key` goes straight into the roving helper, so guard
- // here instead.
- if (isComposingEvent(event)) return;
- const to = nextRovingValue(
- connectionOptions,
- active?.offer_id ?? "",
- event.key,
- );
- if (to === null) return;
- event.preventDefault();
- const target = offers.find((o) => o.offer_id === to);
- if (target) chooseConnection(target);
- event.currentTarget
- .querySelector<HTMLElement>(`[data-offer="${to}"]`)
- ?.focus();
- }}
- >
- {offers.map((offer) => (
- <ChoiceRow
- key={offer.offer_id}
- offerId={offer.offer_id}
- tabIndex={rovingTabIndex(
- connectionOptions,
- { value: offer.offer_id },
- active?.offer_id ?? "",
- )}
- leading={<OfferMark offer={offer} />}
- title={offer.display_name}
- subtitle={offerSubtitle(offer)}
- badge={isLinkedAccount(offer) ? "Connected" : undefined}
- // A selectable row's models are named by the tier toggle
- // right below it, so repeating them here only crowds the
- // choice. A locked row has no toggle, so it keeps them.
- notes={
- offer.lock_reason
- ? [tierSummary(offer), ...offer.limitations].filter(
- Boolean,
- )
- : offer.limitations
- }
- isSelected={offer.offer_id === active?.offer_id}
- onSelect={() => chooseConnection(offer)}
- lock={
- offer.lock_reason
- ? {
- reason: offer.lock_reason,
- href: offer.unlock_href ?? null,
- }
- : undefined
- }
- />
- ))}
- </div>
- </>
- )}
-
- {showTiers && (
- <>
- <SectionLabel>Model tier</SectionLabel>
- <div
- className={cn(
- "overflow-hidden rounded-xl border border-neutral-200 bg-white",
- showMaxUpgrade && "border-0",
- )}
- >
- <TierToggle
- value={tier}
- onSelect={setTier}
- advancedUpgrade={
- showMaxUpgrade && advancedLock?.href ? (
- <MaxUpgradeCard
- label={tierLabel(active, "advanced")}
- name={tierName(active, "advanced")}
- model={tierModel(active, "advanced")}
- reason={advancedLock.reason}
- href={advancedLock.href}
- />
- ) : undefined
- }
- segments={TIERS.map((candidate) => ({
- tier: candidate,
- label: tierLabel(active, candidate),
- name: tierName(active, candidate),
- model: tierModel(active, candidate),
- lock: tierLock(active, candidate),
- }))}
- />
- </div>
- </>
- )}
-
- {canConnectChatGPT && (
- <div
- className={cn(
- "mt-4",
- showMaxUpgrade && "border-t border-zinc-200 pt-4",
- )}
- >
- <SectionLabel>Add a connection</SectionLabel>
- <ConnectAccountRow
- onConnect={connectChatGPT}
- isConnecting={isConnecting}
- />
- </div>
- )}
+ <ConnectionPickerPanel
+ picker={picker}
+ rows={listedConnections(offers, connectionLocked)}
+ />
</PopoverContent>
</Popover>
);
}
-
-/**
- * What a connection is, before its name is read: the provider's own logo where
- * there is one, and the machine it runs on where the route is this deployment.
- */
-function OfferMark({ offer }: { offer: AIConnectionOffer }) {
- if (offer.auth_method === "deployment") {
- return <Icon icon={CloudServerIcon} size={20} className="text-zinc-500" />;
- }
- return <IntegrationLogo provider={offer.provider_family} size={20} />;
-}
-
-function SectionLabel({ children }: { children: React.ReactNode }) {
- return (
- <p className="px-3 pb-1.5 pt-3 text-[11px] font-medium uppercase tracking-[0.06em] text-zinc-500 first:pt-0">
- {children}
- </p>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerDialog.tsx
new file mode 100644
index 0000000000..28c05afa53
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerDialog.tsx
@@ -0,0 +1,78 @@
+"use client";
+
+import { Skeleton } from "@/components/atoms/Skeleton/Skeleton";
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
+import Link from "next/link";
+
+import { ConnectionPickerPanel } from "./ConnectionPickerPanel";
+import { listedConnections } from "./helpers";
+import { useConnectionPicker } from "./useConnectionPicker";
+
+interface Props {
+ /** See `ConnectionPicker`: the connection is fixed, only the tier is open. */
+ connectionLocked?: boolean;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+/** The connection picker's sheet as a dialog, opened from the composer's +. */
+export function ConnectionPickerDialog({
+ connectionLocked = false,
+ open,
+ onOpenChange,
+}: Props) {
+ // Mounted while closed too: the hook also drops a lapsed Advanced tier,
+ // which has to happen whether or not anyone opens the sheet.
+ const picker = useConnectionPicker();
+
+ return (
+ <Dialog
+ title="Model and connection"
+ controlled={{ isOpen: open, set: onOpenChange }}
+ styling={{ maxWidth: "26rem" }}
+ >
+ <Dialog.Content>
+ <DialogBody picker={picker} connectionLocked={connectionLocked} />
+ </Dialog.Content>
+ </Dialog>
+ );
+}
+
+interface BodyProps {
+ picker: ReturnType<typeof useConnectionPicker>;
+ connectionLocked: boolean;
+}
+
+function DialogBody({ picker, connectionLocked }: BodyProps) {
+ const { offers, active, isLoading, isError } = picker;
+
+ if (isLoading && offers.length === 0) {
+ return <Skeleton className="h-32 w-full rounded-xl" />;
+ }
+
+ if (isError) {
+ return (
+ <p className="text-sm text-zinc-600">
+ AI connections are unavailable right now. Try again in a moment.
+ </p>
+ );
+ }
+
+ if (offers.length === 0) {
+ return (
+ <p className="text-sm text-zinc-600">
+ No AI connection is set up yet.{" "}
+ <Link href="/settings/integrations" className="underline">
+ Set one up
+ </Link>
+ </p>
+ );
+ }
+
+ // Asked for from the menu, so the dialog always says what the chat runs
+ // on: with nothing to choose, it still lists the active connection.
+ const listed = listedConnections(offers, connectionLocked);
+ const rows = listed.length > 0 ? listed : active ? [active] : offers;
+
+ return <ConnectionPickerPanel picker={picker} rows={rows} />;
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerPanel.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerPanel.tsx
new file mode 100644
index 0000000000..2eeafd3a84
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/ConnectionPickerPanel.tsx
@@ -0,0 +1,192 @@
+"use client";
+
+import type { AIConnectionOffer } from "@/app/api/__generated__/models/aIConnectionOffer";
+import { Icon } from "@/components/atoms/Icon/Icon";
+import { IntegrationLogo } from "@/components/molecules/IntegrationLogo/IntegrationLogo";
+import { isComposingEvent } from "@/lib/keyboard";
+import { cn } from "@/lib/utils";
+import { CloudServerIcon } from "@hugeicons/core-free-icons";
+
+import { ChoiceRow } from "./ChoiceRow";
+import { ConnectAccountRow } from "./ConnectAccountRow";
+import {
+ isLinkedAccount,
+ isSelectable,
+ offerSubtitle,
+ tierLabel,
+ tierLock,
+ tierModel,
+ tierName,
+ tierSummary,
+} from "./helpers";
+import { MaxUpgradeCard } from "./MaxUpgradeCard";
+import { nextRovingValue, rovingTabIndex } from "./radioKeys";
+import { TierToggle } from "./TierToggle";
+import type { useConnectionPicker } from "./useConnectionPicker";
+
+const TIERS = ["standard", "advanced"] as const;
+
+interface Props {
+ picker: ReturnType<typeof useConnectionPicker>;
+ /** The connections listed under "Runs on"; empty hides the section. */
+ rows: AIConnectionOffer[];
+}
+
+/** The picker's sheet: which connection a turn runs on and at what tier. */
+export function ConnectionPickerPanel({ picker, rows }: Props) {
+ const {
+ active,
+ chooseConnection,
+ tier,
+ setTier,
+ showTiers,
+ connectChatGPT,
+ isConnecting,
+ canConnectChatGPT,
+ } = picker;
+ const advancedLock = tierLock(active, "advanced");
+ const showMaxUpgrade =
+ active?.auth_method === "deployment" && Boolean(advancedLock);
+ const connectionOptions = rows.map((offer) => ({
+ value: offer.offer_id,
+ disabled: !isSelectable(offer),
+ }));
+
+ return (
+ <>
+ {rows.length > 0 && (
+ <>
+ <SectionLabel>Runs on</SectionLabel>
+ <div
+ role="radiogroup"
+ aria-label="Connection this chat runs on"
+ // The connections read as plain rows on the sheet: a card around
+ // them would frame the choice twice, once here and once around
+ // the tiers below.
+ className="overflow-hidden rounded-xl"
+ onKeyDown={(event) => {
+ // `event.key` goes straight into the roving helper, so guard
+ // here instead.
+ if (isComposingEvent(event)) return;
+ const to = nextRovingValue(
+ connectionOptions,
+ active?.offer_id ?? "",
+ event.key,
+ );
+ if (to === null) return;
+ event.preventDefault();
+ const target = rows.find((o) => o.offer_id === to);
+ if (target) chooseConnection(target);
+ event.currentTarget
+ .querySelector<HTMLElement>(`[data-offer="${to}"]`)
+ ?.focus();
+ }}
+ >
+ {rows.map((offer) => (
+ <ChoiceRow
+ key={offer.offer_id}
+ offerId={offer.offer_id}
+ tabIndex={rovingTabIndex(
+ connectionOptions,
+ { value: offer.offer_id },
+ active?.offer_id ?? "",
+ )}
+ leading={<OfferMark offer={offer} />}
+ title={offer.display_name}
+ subtitle={offerSubtitle(offer)}
+ badge={isLinkedAccount(offer) ? "Connected" : undefined}
+ // A selectable row's models are named by the tier toggle
+ // right below it, so repeating them here only crowds the
+ // choice. A locked row has no toggle, so it keeps them.
+ notes={
+ offer.lock_reason
+ ? [tierSummary(offer), ...offer.limitations].filter(Boolean)
+ : offer.limitations
+ }
+ isSelected={offer.offer_id === active?.offer_id}
+ onSelect={() => chooseConnection(offer)}
+ lock={
+ offer.lock_reason
+ ? {
+ reason: offer.lock_reason,
+ href: offer.unlock_href ?? null,
+ }
+ : undefined
+ }
+ />
+ ))}
+ </div>
+ </>
+ )}
+
+ {showTiers && (
+ <>
+ <SectionLabel>Model tier</SectionLabel>
+ <div
+ className={cn(
+ "overflow-hidden rounded-xl border border-neutral-200 bg-white",
+ showMaxUpgrade && "border-0",
+ )}
+ >
+ <TierToggle
+ value={tier}
+ onSelect={setTier}
+ advancedUpgrade={
+ showMaxUpgrade && advancedLock?.href ? (
+ <MaxUpgradeCard
+ label={tierLabel(active, "advanced")}
+ name={tierName(active, "advanced")}
+ model={tierModel(active, "advanced")}
+ reason={advancedLock.reason}
+ href={advancedLock.href}
+ />
+ ) : undefined
+ }
+ segments={TIERS.map((candidate) => ({
+ tier: candidate,
+ label: tierLabel(active, candidate),
+ name: tierName(active, candidate),
+ model: tierModel(active, candidate),
+ lock: tierLock(active, candidate),
+ }))}
+ />
+ </div>
+ </>
+ )}
+
+ {canConnectChatGPT && (
+ <div
+ className={cn(
+ "mt-4",
+ showMaxUpgrade && "border-t border-zinc-200 pt-4",
+ )}
+ >
+ <SectionLabel>Add a connection</SectionLabel>
+ <ConnectAccountRow
+ onConnect={connectChatGPT}
+ isConnecting={isConnecting}
+ />
+ </div>
+ )}
+ </>
+ );
+}
+
+/**
+ * What a connection is, before its name is read: the provider's own logo where
+ * there is one, and the machine it runs on where the route is this deployment.
+ */
+function OfferMark({ offer }: { offer: AIConnectionOffer }) {
+ if (offer.auth_method === "deployment") {
+ return <Icon icon={CloudServerIcon} size={20} className="text-zinc-500" />;
+ }
+ return <IntegrationLogo provider={offer.provider_family} size={20} />;
+}
+
+function SectionLabel({ children }: { children: React.ReactNode }) {
+ return (
+ <p className="px-3 pb-1.5 pt-3 text-[11px] font-medium uppercase tracking-[0.06em] text-zinc-500 first:pt-0">
+ {children}
+ </p>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/helpers.ts
index cee98731ce..8c29e0a573 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ConnectionPicker/helpers.ts
@@ -150,3 +150,22 @@ export function tierLock(
if (!match?.lock_reason) return undefined;
return { reason: match.lock_reason, href: "/settings/billing" };
}
+
+/**
+ * The connections the sheet lists under "Runs on".
+ *
+ * One runnable row is nothing to choose between, and a session's connection
+ * is fixed once it exists. A locked-only row is the exception: its
+ * explanation and unlock link are the reason the control is shown at all.
+ */
+export function listedConnections(
+ offers: AIConnectionOffer[],
+ connectionLocked: boolean,
+): AIConnectionOffer[] {
+ const onlyOfferIsLocked =
+ offers.length === 1 && Boolean(offers[0]?.lock_reason);
+ const shows =
+ (!connectionLocked || onlyOfferIsLocked) &&
+ (offers.length > 1 || onlyOfferIsLocked);
+ return shows ? offers : [];
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
index a6c4bff9d1..d6c4392f60 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
@@ -8,6 +8,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { useCopilotModal } from "../../../../useCopilotModal";
import { MAX_ATTACHMENTS } from "../../../../helpers/workspaceAttachments";
import { ComposerPlusMenu } from "../ComposerPlusMenu";
+import { VoiceIcon } from "@hugeicons/core-free-icons";
let mockWorkspaceFilesFlag = false;
vi.mock("@/services/feature-flags/use-get-flag", () => ({
@@ -32,6 +33,37 @@ function openMenu() {
}
describe("ComposerPlusMenu", () => {
+ it.each([true, false])(
+ "respects the disabled state of an extra item: %s",
+ async (disabled) => {
+ const onStart = vi.fn();
+ render(
+ <ComposerPlusMenu
+ onFilesSelected={vi.fn()}
+ extraItems={[
+ {
+ key: "voice",
+ label: "Voice mode",
+ icon: VoiceIcon,
+ onSelect: onStart,
+ disabled,
+ },
+ ]}
+ />,
+ );
+ openMenu();
+
+ const item = await screen.findByRole("menuitem", { name: "Voice mode" });
+ expect(item.getAttribute("aria-disabled")).toBe(disabled ? "true" : null);
+ fireEvent.click(item);
+ if (disabled) {
+ fireEvent.keyDown(item, { key: "Enter" });
+ fireEvent.keyDown(item, { key: " " });
+ }
+ expect(onStart).toHaveBeenCalledTimes(disabled ? 0 : 1);
+ },
+ );
+
it("lists the four actions in fixed order", async () => {
render(<ComposerPlusMenu onFilesSelected={vi.fn()} />);
openMenu();
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ConnectionPicker.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ConnectionPicker.test.tsx
index 45f33f59dd..2e3498fde2 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ConnectionPicker.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ConnectionPicker.test.tsx
@@ -17,6 +17,7 @@ import { beforeEach, describe, expect, it } from "vitest";
import { useCopilotUIStore } from "../../../../store";
import { ConnectionPicker } from "../ConnectionPicker/ConnectionPicker";
+import { ConnectionPickerDialog } from "../ConnectionPicker/ConnectionPickerDialog";
function tier(
name: ConnectionTier["tier"],
@@ -126,6 +127,35 @@ beforeEach(() => {
});
});
+describe("ConnectionPickerDialog", () => {
+ it.each([false, true])(
+ "shows the active connection beside distinct tiers when connectionLocked is %s",
+ async (connectionLocked) => {
+ mockOffers([offer()]);
+
+ render(
+ <ConnectionPickerDialog
+ open
+ connectionLocked={connectionLocked}
+ onOpenChange={() => {}}
+ />,
+ );
+
+ expect(
+ await screen.findByRole("radiogroup", { name: "Model tier" }),
+ ).toBeDefined();
+ const connections = screen.getByRole("radiogroup", {
+ name: "Connection this chat runs on",
+ });
+ expect(
+ within(connections)
+ .getByRole("radio", { name: /AutoGPT Platform/ })
+ .getAttribute("aria-checked"),
+ ).toBe("true");
+ },
+ );
+});
+
describe("ConnectionPicker", () => {
it("says what backs a run on each connection", async () => {
mockOffers([offer(), chatgpt()]);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/EmptySession/EmptySession.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/EmptySession/EmptySession.tsx
index 60963ab441..11a398b6f1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/EmptySession/EmptySession.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/EmptySession/EmptySession.tsx
@@ -41,8 +41,8 @@ interface Props {
expertName?: string;
/** Expert the new conversation will address; scopes workspace-file pickers. */
expertId?: string | null;
- /** Voice-mode toggle, rendered beside the mic. Absent when the flag is off. */
- voiceToggle?: ReactNode;
+ /** Starts voice mode from the + menu. Absent when the flag is off. */
+ voiceMode?: ComponentProps<typeof ChatInput>["voiceMode"];
/** The chat's approval-mode selector. Absent when the flag is off. */
modeSelector?: ReactNode;
/** Out of AutoPilot budget with a reset ahead: the composer sets the new
@@ -64,7 +64,7 @@ export function EmptySession({
isKickoffStarting,
expertName,
expertId = null,
- voiceToggle,
+ voiceMode,
modeSelector,
atReset,
usageNotice,
@@ -185,7 +185,7 @@ export function EmptySession({
inputId="chat-input-empty"
draftKey={`new:${selectedExpert?.id ?? expertId ?? "default"}`}
stacked
- voiceToggle={voiceToggle}
+ voiceMode={voiceMode}
modeSelector={modeSelector}
onSend={onSend}
disabled={isComposerDisabled}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolBadge.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolBadge.tsx
index 3dda2c3e9c..f677653ee8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolBadge.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolBadge.tsx
@@ -3,35 +3,20 @@
import { Icon } from "@/components/atoms/Icon/Icon";
import {
Popover,
- PopoverAnchor,
PopoverContent,
PopoverTrigger,
} from "@/components/molecules/Popover/Popover";
import { cn } from "@/lib/utils";
import { DashboardSpeed02Icon } from "@hugeicons/core-free-icons";
-import { useState } from "react";
-import { useTokenDevtoolStore } from "../../tokenDevtool/store";
-import {
- AUTOCOMPACT_TOKENS,
- MODEL_CONTEXT_WINDOW,
- breakdownTotal,
- displayContext,
- formatTokenCount,
-} from "../../tokenDevtool/tokenMath";
-import { BreakdownSection } from "./components/BreakdownSection";
-import { ContextBar } from "./components/ContextBar";
-import { TurnRow } from "./components/TurnRow";
+import { formatTokenCount } from "../../tokenDevtool/tokenMath";
+import { TokenDevtoolPanel } from "./components/TokenDevtoolPanel";
+import { useTokenDevtoolBadge } from "./useTokenDevtoolBadge";
interface Props {
sessionId: string;
/** Alignment is the tray's concern — the badge renders into two
* structurally different parents. */
className?: string;
- /** Opened from the composer's + menu: no button of its own, the popover
- * anchors to its parent box instead. */
- anchorOnly?: boolean;
- open?: boolean;
- onOpenChange?: (open: boolean) => void;
}
/** Dev-only context readout in the composer tray. The bar tracks the
@@ -40,96 +25,37 @@ interface Props {
* to summarize. The popover splits the estimate by source and lists
* per-turn usage; ⟲ marks a turn where the stream carried a
* `context_compaction` tool call. */
-export function TokenDevtoolBadge({
- sessionId,
- className,
- anchorOnly = false,
- open: controlledOpen,
- onOpenChange,
-}: Props) {
- const turns = useTokenDevtoolStore((s) => s.turnsBySession[sessionId]);
- const breakdown = useTokenDevtoolStore(
- (s) => s.breakdownBySession[sessionId],
- );
- const liveContext = useTokenDevtoolStore(
- (s) => s.liveContextBySession[sessionId],
- );
- const compacted = useTokenDevtoolStore(
- (s) => s.compactedBySession[sessionId] ?? false,
- );
- const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
- const open = controlledOpen ?? uncontrolledOpen;
- const setOpen = onOpenChange ?? setUncontrolledOpen;
- const seed = breakdown ? breakdownTotal(breakdown) : undefined;
- const context = displayContext(liveContext ?? null, compacted, seed);
- // The rows describe the loaded-history seed, so showing them next to a
- // headline sourced from the live cache-write sum would read as one total
- // that does not add up. Only render them while the seed IS the headline.
- const showBreakdown = breakdown !== undefined && context === seed;
+export function TokenDevtoolBadge({ sessionId, className }: Props) {
+ const devtool = useTokenDevtoolBadge(sessionId);
+ const { context } = devtool;
return (
- <Popover open={open} onOpenChange={setOpen}>
- {anchorOnly ? (
- <PopoverAnchor asChild>
- <span aria-hidden className="pointer-events-none absolute inset-0" />
- </PopoverAnchor>
- ) : (
- <PopoverTrigger asChild>
- <button
- type="button"
- aria-label={`Token devtool, context ${
- context === null ? "unknown" : formatTokenCount(context)
- }`}
- className={cn(
- "flex h-8 w-8 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-700",
- className,
- )}
- >
- <Icon icon={DashboardSpeed02Icon} size={16} />
- <span className="sr-only">
- {context === null ? "ctx —" : `ctx ~${formatTokenCount(context)}`}
- </span>
- </button>
- </PopoverTrigger>
- )}
+ <Popover>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ aria-label={`Token devtool, context ${
+ context === null ? "unknown" : formatTokenCount(context)
+ }`}
+ className={cn(
+ "flex h-8 w-8 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-700",
+ className,
+ )}
+ >
+ <Icon icon={DashboardSpeed02Icon} size={16} />
+ <span className="sr-only">
+ {context === null ? "ctx —" : `ctx ~${formatTokenCount(context)}`}
+ </span>
+ </button>
+ </PopoverTrigger>
<PopoverContent
side="top"
- align={anchorOnly ? "start" : "end"}
+ align="end"
sideOffset={8}
className="w-80 rounded-2xl border-zinc-200/70 p-3 shadow-[0_16px_40px_-24px_rgba(0,0,0,0.25)]"
>
- <div className="flex items-baseline justify-between pb-2">
- <span className="text-sm font-medium text-zinc-800">
- Context window
- </span>
- <span className="font-mono text-xs text-zinc-500">
- {context === null ? "—" : `~${formatTokenCount(context)}`} /{" "}
- {formatTokenCount(MODEL_CONTEXT_WINDOW)}
- </span>
- </div>
- <ContextBar context={context ?? 0} />
- <p className="pt-1 font-mono text-[10px] text-zinc-400">
- assumes a {formatTokenCount(MODEL_CONTEXT_WINDOW)} window; the backend
- threshold is configurable
- </p>
- <p className="pb-2.5 pt-0.5 text-right font-mono text-xs text-amber-500">
- summarizes ~{formatTokenCount(AUTOCOMPACT_TOKENS)}
- </p>
-
- {showBreakdown && <BreakdownSection breakdown={breakdown} />}
-
- {!turns?.length ? (
- <p className="text-sm text-zinc-500">
- Live per-turn data starts with your next message.
- </p>
- ) : (
- <div className="flex max-h-40 flex-col gap-1 overflow-y-auto">
- {turns.map((turn, i) => (
- <TurnRow key={`${turn.at}-${i}`} index={i} turn={turn} />
- ))}
- </div>
- )}
+ <TokenDevtoolPanel {...devtool} />
</PopoverContent>
</Popover>
);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolDialog.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolDialog.tsx
new file mode 100644
index 0000000000..75c353dd12
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/TokenDevtoolDialog.tsx
@@ -0,0 +1,28 @@
+"use client";
+
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
+import { TokenDevtoolPanel } from "./components/TokenDevtoolPanel";
+import { useTokenDevtoolBadge } from "./useTokenDevtoolBadge";
+
+interface Props {
+ sessionId: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+/** The token devtool readout as a dialog, opened from the composer's +. */
+export function TokenDevtoolDialog({ sessionId, open, onOpenChange }: Props) {
+ const devtool = useTokenDevtoolBadge(sessionId);
+
+ return (
+ <Dialog
+ title="Token usage"
+ controlled={{ isOpen: open, set: onOpenChange }}
+ styling={{ maxWidth: "24rem" }}
+ >
+ <Dialog.Content>
+ <TokenDevtoolPanel {...devtool} />
+ </Dialog.Content>
+ </Dialog>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/components/TokenDevtoolPanel.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/components/TokenDevtoolPanel.tsx
new file mode 100644
index 0000000000..4de95d68aa
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/components/TokenDevtoolPanel.tsx
@@ -0,0 +1,49 @@
+import {
+ AUTOCOMPACT_TOKENS,
+ MODEL_CONTEXT_WINDOW,
+ formatTokenCount,
+} from "../../../tokenDevtool/tokenMath";
+import type { useTokenDevtoolBadge } from "../useTokenDevtoolBadge";
+import { BreakdownSection } from "./BreakdownSection";
+import { ContextBar } from "./ContextBar";
+import { TurnRow } from "./TurnRow";
+
+type Props = ReturnType<typeof useTokenDevtoolBadge>;
+
+export function TokenDevtoolPanel({ turns, breakdown, context }: Props) {
+ return (
+ <>
+ <div className="flex items-baseline justify-between pb-2">
+ <span className="text-sm font-medium text-zinc-800">
+ Context window
+ </span>
+ <span className="font-mono text-xs text-zinc-500">
+ {context === null ? "—" : `~${formatTokenCount(context)}`} /{" "}
+ {formatTokenCount(MODEL_CONTEXT_WINDOW)}
+ </span>
+ </div>
+ <ContextBar context={context ?? 0} />
+ <p className="pt-1 font-mono text-[10px] text-zinc-400">
+ assumes a {formatTokenCount(MODEL_CONTEXT_WINDOW)} window; the backend
+ threshold is configurable
+ </p>
+ <p className="pb-2.5 pt-0.5 text-right font-mono text-xs text-amber-500">
+ summarizes ~{formatTokenCount(AUTOCOMPACT_TOKENS)}
+ </p>
+
+ {breakdown && <BreakdownSection breakdown={breakdown} />}
+
+ {!turns?.length ? (
+ <p className="text-sm text-zinc-500">
+ Live per-turn data starts with your next message.
+ </p>
+ ) : (
+ <div className="flex max-h-40 flex-col gap-1 overflow-y-auto">
+ {turns.map((turn, i) => (
+ <TurnRow key={`${turn.at}-${i}`} index={i} turn={turn} />
+ ))}
+ </div>
+ )}
+ </>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/useTokenDevtoolBadge.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/useTokenDevtoolBadge.ts
new file mode 100644
index 0000000000..15a1b2dfbc
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/TokenDevtoolBadge/useTokenDevtoolBadge.ts
@@ -0,0 +1,24 @@
+import { useTokenDevtoolStore } from "../../tokenDevtool/store";
+import { breakdownTotal, displayContext } from "../../tokenDevtool/tokenMath";
+
+export function useTokenDevtoolBadge(sessionId: string) {
+ const turns = useTokenDevtoolStore((s) => s.turnsBySession[sessionId]);
+ const breakdown = useTokenDevtoolStore(
+ (s) => s.breakdownBySession[sessionId],
+ );
+ const liveContext = useTokenDevtoolStore(
+ (s) => s.liveContextBySession[sessionId],
+ );
+ const compacted = useTokenDevtoolStore(
+ (s) => s.compactedBySession[sessionId] ?? false,
+ );
+ const seed = breakdown ? breakdownTotal(breakdown) : undefined;
+ const context = displayContext(liveContext ?? null, compacted, seed);
+ // The rows describe the loaded-history seed, so showing them next to a
+ // headline sourced from the live cache-write sum would read as one total
+ // that does not add up. Only render them while the seed IS the headline.
+ const visibleBreakdown =
+ breakdown !== undefined && context === seed ? breakdown : undefined;
+
+ return { turns, breakdown: visibleBreakdown, context };
+}