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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 10x 10x 183x 183x 183x 183x 2x 2x 61x 10x 15x | import AgentToolsMenu from "@/components/chat/AgentChat/AgentToolsMenu";
import MakerLogo from "@/components/img/MakerLogo/MakerLogo";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Model, modelDisplayName } from "@/objects/Model";
import { modelMaker, modelMakerKey } from "@/objects/modelOrigin";
import { ChevronDown, Cpu, Workflow } from "lucide-react";
import React from "react";
/** The radio value standing for "no override": Radix needs a value, and
* the page's own state reads the agent's default as `""`. */
const AGENT_DEFAULT = "__agent_default__";
export interface AgentChatToolbarProps {
agentId: string;
/** The agent's own model, named beside "Agent default" when known. */
agentModel?: Model;
/** The models this chat may switch to (`selectableModels`). */
models: Model[];
/** The chosen model's id; `""` is the agent's default. */
modelOverrideId: string;
onModelChange: (id: string) => void;
skillsDisabled: boolean;
onSkillsDisabledChange: (disabled: boolean) => void;
}
/**
* The bar above an agent's chat: whether the turn runs the agent's skill
* graph, which model answers it, and the tools it may call โ one row, with
* the model and the tools behind dropdowns. It wraps only where a phone is
* too narrow for all three.
*
* Both dropdowns portal to <body>, so they carry z-[70] to open over the
* full-screen chat (`ChatLayout`, z-[60]).
*/
const AgentChatToolbar: React.FC<AgentChatToolbarProps> = ({
agentId,
agentModel,
models,
modelOverrideId,
onModelChange,
skillsDisabled,
onSkillsDisabledChange,
}) => {
const chosen = models.find((m) => m.id === modelOverrideId);
const modelLabel = chosen ? modelDisplayName(chosen) : "Agent default";
// The model that will answer: the one chosen, else the agent's own.
const answering = chosen ?? agentModel;
return (
<div className="border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 px-3 py-1.5 flex flex-wrap items-center gap-x-1 gap-y-1">
<div className="flex shrink-0 items-center gap-2 px-1 h-7">
<Workflow className="w-3.5 h-3.5 text-gray-400 dark:text-gray-500 shrink-0" />
<span className="text-xs font-medium text-gray-600 dark:text-gray-400">
Skill graph
</span>
<button
type="button"
role="switch"
aria-checked={!skillsDisabled}
aria-label="Skill graph"
onClick={() => onSkillsDisabledChange(!skillsDisabled)}
title={
skillsDisabled
? "Skill graph disabled โ click to enable"
: "Skill graph enabled โ click to disable"
}
className={`relative flex h-4 w-7 shrink-0 items-center rounded-full transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500/40 ${
!skillsDisabled ? "bg-indigo-500" : "bg-gray-300 dark:bg-gray-600"
}`}
>
<span
className={`absolute y-center h-3 w-3 rounded-full bg-white shadow transition-transform ${
!skillsDisabled ? "right-0 mr-1" : "left-0 ml-1"
}`}
/>
</button>
</div>
{models.length > 0 && (
<>
<span className="mx-1 h-3 w-px bg-gray-200 dark:bg-gray-700 shrink-0" />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
type="button"
aria-label="Model for this chat"
title={`Model: ${modelLabel}`}
className="min-w-0 max-w-full inline-flex items-center gap-1.5 h-7 px-2 rounded-md border-0 text-xs font-medium text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 data-[state=open]:bg-gray-100 dark:data-[state=open]:bg-gray-800 transition-colors"
>
{answering ? (
<MakerLogo
maker={modelMakerKey(answering)}
className="w-3.5 h-3.5 shrink-0"
decorative
/>
) : (
<Cpu className="w-3.5 h-3.5 text-gray-400 dark:text-gray-500 shrink-0" />
)}
<span className="min-w-0 truncate">{modelLabel}</span>
{!chosen && agentModel && (
<span className="hidden sm:inline min-w-0 truncate font-normal text-gray-400 dark:text-gray-500">
ยท {modelDisplayName(agentModel)}
</span>
)}
<ChevronDown className="w-3.5 h-3.5 text-gray-400 shrink-0" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="start"
className="z-[70] w-72 max-w-[calc(100vw-2rem)] max-h-80"
>
<DropdownMenuRadioGroup
value={modelOverrideId || AGENT_DEFAULT}
onValueChange={(v) =>
onModelChange(v === AGENT_DEFAULT ? "" : v)
}
>
<DropdownMenuRadioItem value={AGENT_DEFAULT}>
<ModelOption
name="Agent default"
detail={agentModel ? modelDisplayName(agentModel) : undefined}
maker={agentModel ? modelMakerKey(agentModel) : undefined}
/>
</DropdownMenuRadioItem>
<DropdownMenuSeparator />
{models.map((m) => (
<DropdownMenuRadioItem key={m.id} value={m.id}>
<ModelOption
name={modelDisplayName(m)}
detail={modelMaker(m)}
maker={modelMakerKey(m)}
/>
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
</>
)}
<div className="ml-auto">
<AgentToolsMenu agentId={agentId} />
</div>
</div>
);
};
/** A model in a picker: its name, a detail line, and its maker's mark when
* `maker` (a `makerKey`) is given. */
export const ModelOption: React.FC<{
name: string;
detail?: string;
maker?: string;
}> = ({ name, detail, maker }) => (
<span className="flex min-w-0 items-center gap-2">
{maker !== undefined && (
<MakerLogo maker={maker} className="size-4 shrink-0" decorative />
)}
<span className="flex min-w-0 flex-col">
<span className="truncate">{name}</span>
{detail && (
<span className="truncate text-xs text-muted-foreground">{detail}</span>
)}
</span>
</span>
);
export default AgentChatToolbar;
|