Open History to see the last commit
1import {
2 buildTraitsTriggerDisplay,
3 getDescriptorStringValue,
4 isReasoningControl,
5 selectableProviderOptionChoices,
6} from "@t3tools/client-runtime/model-traits";
7import type { ProviderOptionDescriptor, RuntimeMode } from "@t3tools/contracts";
8import type { EffortDisplay } from "@t3tools/contracts/settings";
9import { getProviderOptionCurrentLabel } from "@t3tools/shared/model";
10import { CheckIcon, ChevronRightIcon, ChevronUpIcon, WorkflowIcon } from "lucide-react";
11import { type KeyboardEvent, type ReactNode, use, useRef, useState } from "react";
12
13import { cn } from "~/lib/utils";
14import {
15 Menu,
16 MenuPopup,
17 MenuRadioGroup,
18 MenuRadioItem,
19 MenuRadioItemIndicator,
20 MenuTrigger,
21} from "../ui/menu";
22import { Switch } from "../ui/switch";
23import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
24import type { ComposerControlSize } from "./ComposerControl";
25import { ComposerPermissionsSection, type RuntimeModeOption } from "./ComposerFooterControls";
26import { composerFloatingLayerProps, focusCheckedPermission } from "./composerEventScope";
27import { EffortGlyph, FastBolt, resolveEffortGlyph } from "./EffortGlyph";
28import { DockedPickerContext } from "./ProviderModelPicker";
29import {
30 getTraitsSectionVisibility,
31 type TraitsSelectionInput,
32 ULTRATHINK_IN_BODY_NOTE,
33 useTraitsSelection,
34} from "./TraitsPicker";
35
36type SelectDescriptor = Extract<ProviderOptionDescriptor, { type: "select" }>;
37type BooleanDescriptor = Extract<ProviderOptionDescriptor, { type: "boolean" }>;
38
39/** Service tiers, Claude's Fast mode, and Ultracode sit in the footer, not the column. */
40function splitSpeed(
41 selects: ReadonlyArray<SelectDescriptor>,
42 toggles: ReadonlyArray<BooleanDescriptor>,
43) {
44 const speedSelect = selects.find((descriptor) => descriptor.id === "serviceTier") ?? null;
45 const fastToggle = toggles.find((descriptor) => descriptor.id === "fastMode") ?? null;
46 const ultracodeToggle = toggles.find((descriptor) => descriptor.id === "ultracode") ?? null;
47 return {
48 speedSelect,
49 fastToggle,
50 ultracodeToggle,
51 columnSelects: selects.filter((descriptor) => descriptor !== speedSelect),
52 columnToggles: toggles.filter(
53 (descriptor) => descriptor !== fastToggle && descriptor !== ultracodeToggle,
54 ),
55 };
56}
57
58type ColumnControl =
59 | { kind: "select"; descriptor: SelectDescriptor }
60 | { kind: "boolean"; descriptor: BooleanDescriptor };
61
62/**
63 * The column lists the model's reasoning levels under the header that names it. Other options,
64 * such as an agent's session mode, sit below as one row each.
65 */
66function columnControls(
67 selects: ReadonlyArray<SelectDescriptor>,
68 toggles: ReadonlyArray<BooleanDescriptor>,
69) {
70 const { columnSelects, columnToggles } = splitSpeed(selects, toggles);
71 const controls: ReadonlyArray<ColumnControl> = [
72 ...columnSelects.map((descriptor) => ({ kind: "select" as const, descriptor })),
73 ...columnToggles.map((descriptor) => ({ kind: "boolean" as const, descriptor })),
74 ];
75 const effort = controls.find((control) => isReasoningControl(control.descriptor)) ?? null;
76 return { effort, others: controls.filter((control) => control !== effort) };
77}
78
79/**
80 * What the model trigger shows after the model name: the effort word (or bars, per the
81 * Appearance setting), a bolt for Fast, a workflow icon for Ultracode, and other traits such as a
82 * context window.
83 */
84export function describeComposerEffort(
85 traits: TraitsSelectionInput | null,
86 effortDisplay: EffortDisplay,
87 size: ComposerControlSize,
88): { suffix: ReactNode; detail: string | null } {
89 if (!traits) return { suffix: null, detail: null };
90 const visibility = getTraitsSectionVisibility(traits);
91 if (!visibility.hasAnyControls) return { suffix: null, detail: null };
92 const modelSelection =
93 traits.instanceId && traits.model
94 ? { instanceId: traits.instanceId, model: traits.model, options: traits.modelOptions ?? [] }
95 : null;
96 const primary = visibility.primarySelectDescriptor;
97 const display = buildTraitsTriggerDisplay({
98 descriptors: visibility.descriptors,
99 primarySelectDescriptorId: primary?.id ?? null,
100 ultrathinkPromptControlled: visibility.ultrathinkPromptControlled,
101 modelSelection,
102 reportedModelSelection: traits.reportedModelSelection,
103 });
104 // The same reasoning control the column lists, wherever the agent put it among its options.
105 const reasoning =
106 columnControls(visibility.selectDescriptors, visibility.booleanDescriptors).effort
107 ?.descriptor ?? null;
108 const ultrathink = visibility.ultrathinkPromptControlled && reasoning === primary;
109 const glyph =
110 reasoning?.type === "select"
111 ? resolveEffortGlyph(
112 reasoning,
113 ultrathink
114 ? "ultrathink"
115 : getDescriptorStringValue(reasoning, modelSelection, traits.reportedModelSelection),
116 )
117 : null;
118 // Workflow levels such as Ultracode always show their name; the setting names every level.
119 const word = glyph
120 ? (glyph.special ?? (effortDisplay === "label" ? glyph.label : null))
121 : !reasoning
122 ? null
123 : reasoning.type === "boolean"
124 ? `${reasoning.label} ${reasoning.currentValue === true ? "On" : "Off"}`
125 : ultrathink
126 ? "Ultrathink"
127 : (getProviderOptionCurrentLabel(
128 reasoning,
129 modelSelection,
130 traits.reportedModelSelection,
131 ) ?? (reasoning.id === "thinking" ? reasoning.label : null));
132 const fast = display.speedLabel === "Fast" || display.speedLabel === "Ultrafast";
133 // Agent options such as modes live in the picker; the trigger adds only the context window.
134 const contextWindow =
135 visibility.contextWindowDescriptor &&
136 getProviderOptionCurrentLabel(
137 visibility.contextWindowDescriptor,
138 modelSelection,
139 traits.reportedModelSelection,
140 );
141 if (!word && !glyph && !fast && !display.ultracode && !contextWindow)
142 return { suffix: null, detail: display.label };
143 return {
144 detail: display.label,
145 suffix: (
146 <span
147 className={cn(
148 "flex shrink-0 items-center gap-1.5 text-muted-foreground group-hover/model-trigger:text-foreground group-data-pressed/model-trigger:text-foreground group-data-popup-open/model-trigger:text-foreground",
149 // A word space after the model name: the regular trigger's gap is wider than one.
150 size === "sm" && "-ms-0.5",
151 )}
152 >
153 {word ? (
154 <span data-composer-control-label className="max-w-24 truncate">
155 {word}
156 </span>
157 ) : glyph ? (
158 <EffortGlyph count={glyph.count} filled={glyph.filled} size={size} />
159 ) : null}
160 {fast ? <FastBolt ultra={display.speedLabel === "Ultrafast"} /> : null}
161 {display.ultracode ? (
162 <WorkflowIcon aria-hidden="true" data-composer-control-icon className="size-3" />
163 ) : null}
164 {contextWindow ? (
165 <span
166 // A label, so icon-only footers drop it; compacted rows drop it before the model.
167 data-composer-control-label
168 data-composer-secondary-trait
169 className="max-w-24 truncate text-xs"
170 >
171 {contextWindow}
172 </span>
173 ) : null}
174 </span>
175 ),
176 };
177}
178
179const COLUMN_ROW =
180 "flex h-8 w-full shrink-0 cursor-pointer items-center gap-2 rounded-sm px-2 text-left text-sm text-foreground outline-none hover:bg-foreground/[0.09] focus-visible:bg-foreground/[0.09] disabled:cursor-not-allowed disabled:opacity-64";
181const COLUMN_LABEL = "px-2 pt-1.5 pb-1 font-medium text-muted-foreground text-xs";
182
183function ColumnRow(props: {
184 label: string;
185 /** Shown on hover; the column is too narrow to print it under the label. */
186 description?: string | undefined;
187 selected: boolean;
188 /** The column's one tab stop: the selected level, else the first when none shows as selected. */
189 tabStop: boolean;
190 isDefault?: boolean | undefined;
191 disabled?: boolean;
192 onPick: () => void;
193}) {
194 const rowProps = {
195 type: "button",
196 role: "radio",
197 "aria-checked": props.selected,
198 disabled: props.disabled,
199 "data-effort-row": true,
200 // Focus lands on a level after a model pick.
201 "data-effort-level": true,
202 // Up and Down move between rows.
203 tabIndex: props.tabStop ? 0 : -1,
204 className: COLUMN_ROW,
205 onClick: props.onPick,
206 } as const;
207 const content = (
208 <>
209 <span className="min-w-0 flex-1 truncate">{props.label}</span>
210 {props.selected ? (
211 <>
212 {props.isDefault ? <span className="sr-only">Default</span> : null}
213 <CheckIcon aria-hidden="true" className="size-3.5" />
214 </>
215 ) : props.isDefault ? (
216 <span className="text-muted-foreground/70 text-xs">Default</span>
217 ) : null}
218 </>
219 );
220 if (!props.description) return <button {...rowProps}>{content}</button>;
221 return (
222 <Tooltip>
223 <TooltipTrigger render={<button {...rowProps} />}>{content}</TooltipTrigger>
224 <TooltipPopup side="right" className="max-w-56">
225 {props.description}
226 </TooltipPopup>
227 </Tooltip>
228 );
229}
230
231function moveBetweenRows(event: KeyboardEvent<HTMLElement>) {
232 if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
233 // An option's side menu is a React child here, but it moves through its own items.
234 if (!event.currentTarget.contains(event.target as Node)) return;
235 const rows = Array.from(
236 event.currentTarget.querySelectorAll<HTMLButtonElement>("[data-effort-row]:not(:disabled)"),
237 );
238 const index = rows.findIndex((row) => row === document.activeElement);
239 const next =
240 rows[Math.min(rows.length - 1, Math.max(0, index + (event.key === "ArrowDown" ? 1 : -1)))];
241 if (!next) return;
242 event.preventDefault();
243 event.stopPropagation();
244 next.focus();
245 next.scrollIntoView({ block: "nearest" });
246}
247
248function EffortLevels(props: { traits: TraitsSelectionInput }) {
249 const traits = useTraitsSelection(props.traits);
250 const { effort, others } = columnControls(traits.selectDescriptors, traits.booleanDescriptors);
251 if (traits.modelIsUnavailable) {
252 return (
253 <>
254 {traits.descriptors.map((descriptor) => {
255 const value = traits.currentLabel(descriptor);
256 return value ? (
257 <div key={descriptor.id}>
258 <div className={COLUMN_LABEL}>{descriptor.label}</div>
259 <div className="px-2 pb-1.5 text-muted-foreground/80 text-xs">{value}</div>
260 </div>
261 ) : null;
262 })}
263 </>
264 );
265 }
266 if (!effort && others.length === 0) return <NoEffortRow />;
267 // Ultrathink in the prompt locks the levels; the first option then holds the tab stop.
268 const locked =
269 effort?.descriptor.id === traits.primarySelectDescriptor?.id && traits.ultrathinkInBodyText;
270 return (
271 <>
272 {effort ? <EffortRows control={effort} traits={traits} locked={locked} /> : null}
273 {others.length > 0 ? (
274 <div
275 className={cn("flex flex-col gap-0.5", effort && "mt-1 border-t border-border/70 pt-1")}
276 >
277 {others.map((control, index) =>
278 control.kind === "boolean" ? (
279 <OptionSwitchRow
280 key={control.descriptor.id}
281 descriptor={control.descriptor}
282 traits={traits}
283 tabStop={(!effort || locked) && index === 0}
284 />
285 ) : (
286 <OptionMenuRow
287 key={control.descriptor.id}
288 descriptor={control.descriptor}
289 traits={traits}
290 tabStop={(!effort || locked) && index === 0}
291 />
292 ),
293 )}
294 </div>
295 ) : null}
296 </>
297 );
298}
299
300type TraitsSelection = ReturnType<typeof useTraitsSelection>;
301
302function EffortRows(props: { control: ColumnControl; traits: TraitsSelection; locked: boolean }) {
303 const { control, traits } = props;
304 const { descriptor } = control;
305 if (control.kind === "boolean") {
306 return (
307 <div role="radiogroup" aria-label={descriptor.label} className="flex flex-col gap-0.5">
308 {([true, false] as const).map((value) => (
309 <ColumnRow
310 key={String(value)}
311 label={value ? "On" : "Off"}
312 selected={(control.descriptor.currentValue === true) === value}
313 tabStop={(control.descriptor.currentValue === true) === value}
314 onPick={() => traits.changeBoolean(descriptor.id, value)}
315 />
316 ))}
317 </div>
318 );
319 }
320 const { locked } = props;
321 const value = traits.selectValue(control.descriptor);
322 const choices = selectableProviderOptionChoices(control.descriptor);
323 // An "Ultrathink:" prefix selects a level the column does not offer.
324 const shown = choices.some((option) => option.id === value);
325 return (
326 <div role="radiogroup" aria-label={descriptor.label} className="flex flex-col gap-0.5">
327 {locked ? (
328 <div className="px-2 pb-1.5 text-muted-foreground/80 text-xs">
329 {ULTRATHINK_IN_BODY_NOTE}
330 </div>
331 ) : null}
332 {choices.map((option, index) => (
333 <ColumnRow
334 key={option.id}
335 label={option.label}
336 selected={option.id === value}
337 tabStop={shown ? option.id === value : index === 0}
338 description={option.description}
339 isDefault={option.isDefault}
340 disabled={locked}
341 onPick={() => traits.changeSelect(control.descriptor, option.id)}
342 />
343 ))}
344 </div>
345 );
346}
347
348const OPTION_ROW = cn(COLUMN_ROW, "h-auto py-1");
349
350/** An option's name over its current value. */
351function OptionRowText(props: { label: string; value: string }) {
352 return (
353 <span className="flex min-w-0 flex-1 flex-col">
354 <span className="truncate text-muted-foreground text-xs">{props.label}</span>
355 <span className="truncate">{props.value}</span>
356 </span>
357 );
358}
359
360/**
361 * One select besides reasoning, such as an agent's session mode. It names the current choice and
362 * opens the rest beside the column, so any number of options leaves the levels in place.
363 */
364function OptionMenuRow(props: {
365 descriptor: SelectDescriptor;
366 traits: TraitsSelection;
367 /** Holds the column's tab stop when the model has no levels. */
368 tabStop: boolean;
369}) {
370 const { descriptor, traits } = props;
371 const [open, setOpen] = useState(false);
372 const popupRef = useRef<HTMLDivElement>(null);
373 const choices = selectableProviderOptionChoices(descriptor);
374 const value = traits.selectValue(descriptor);
375 const current = choices.find((choice) => choice.id === value)?.label ?? "";
376 return (
377 <Menu
378 open={open}
379 // A modal menu would cover the picker, so the next click there would only close it.
380 modal={false}
381 onOpenChange={setOpen}
382 onOpenChangeComplete={(isOpen) => {
383 if (!isOpen) return;
384 const checked = popupRef.current?.querySelector<HTMLElement>(
385 '[role="menuitemradio"][aria-checked="true"]',
386 );
387 checked?.focus({ preventScroll: true });
388 checked?.scrollIntoView({ block: "nearest" });
389 }}
390 >
391 {/* No hover opening: an opened menu takes focus, which would steal typing from search. */}
392 <MenuTrigger
393 render={
394 <button
395 type="button"
396 data-effort-row
397 tabIndex={props.tabStop ? 0 : -1}
398 aria-label={`${descriptor.label}: ${current}`}
399 className={cn(OPTION_ROW, "data-popup-open:bg-foreground/[0.09]")}
400 onKeyDown={(event) => {
401 if (event.key !== "ArrowRight") return;
402 event.preventDefault();
403 event.stopPropagation();
404 setOpen(true);
405 }}
406 />
407 }
408 >
409 <OptionRowText label={descriptor.label} value={current} />
410 <ChevronRightIcon
411 aria-hidden="true"
412 className="-me-1 size-3.5 shrink-0 text-muted-foreground"
413 />
414 </MenuTrigger>
415 <MenuPopup
416 ref={popupRef}
417 side="right"
418 align="start"
419 sideOffset={6}
420 // A full-width column on phones leaves no room beside it, so fall below or above.
421 collisionAvoidance={{ fallbackAxisSide: "end" }}
422 className="max-w-72"
423 data-model-picker-option-menu
424 {...composerFloatingLayerProps}
425 onKeyDown={(event) => {
426 if (event.key !== "ArrowLeft") return;
427 event.preventDefault();
428 event.stopPropagation();
429 setOpen(false);
430 }}
431 >
432 <MenuRadioGroup
433 aria-label={descriptor.label}
434 value={value}
435 onValueChange={(next: string) => {
436 if (next !== value) traits.changeSelect(descriptor, next);
437 }}
438 >
439 {choices.map((choice) => (
440 <MenuRadioItem key={choice.id} value={choice.id} closeOnClick>
441 <span className="flex items-center gap-3">
442 <span className="flex min-w-0 flex-1 flex-col">
443 <span className="truncate">{choice.label}</span>
444 {choice.description ? (
445 <span className="line-clamp-2 text-muted-foreground text-xs">
446 {choice.description}
447 </span>
448 ) : null}
449 </span>
450 {choice.isDefault ? (
451 <span className="text-muted-foreground/70 text-xs">Default</span>
452 ) : null}
453 <MenuRadioItemIndicator />
454 </span>
455 </MenuRadioItem>
456 ))}
457 </MenuRadioGroup>
458 </MenuPopup>
459 </Menu>
460 );
461}
462
463/** A two-state option toggles in place; a menu would add a click for nothing. */
464function OptionSwitchRow(props: {
465 descriptor: BooleanDescriptor;
466 traits: TraitsSelection;
467 tabStop: boolean;
468}) {
469 const { descriptor, traits } = props;
470 const checked = descriptor.currentValue === true;
471 return (
472 <label className={cn(OPTION_ROW, "has-focus-visible:bg-foreground/[0.09]")}>
473 <OptionRowText label={descriptor.label} value={checked ? "On" : "Off"} />
474 <Switch
475 size="sm"
476 checked={checked}
477 onCheckedChange={(next) => traits.changeBoolean(descriptor.id, next)}
478 aria-label={descriptor.label}
479 data-effort-row
480 tabIndex={props.tabStop ? 0 : -1}
481 />
482 </label>
483 );
484}
485
486function NoEffortRow() {
487 return (
488 <div className="flex h-8 items-center px-2 text-muted-foreground text-sm">No effort levels</div>
489 );
490}
491
492/** The model picker's effort column: the selected model's levels and its other options. */
493export function ComposerEffortColumn(props: { traits: TraitsSelectionInput | null }) {
494 const picker = use(DockedPickerContext);
495 const visibility = props.traits ? getTraitsSectionVisibility(props.traits) : null;
496 const controls =
497 props.traits && visibility
498 ? columnControls(visibility.selectDescriptors, visibility.booleanDescriptors)
499 : null;
500 return (
501 <>
502 {/* Matches the search row's box, so one rule runs across the top of the popup. */}
503 <div className="shrink-0 px-3 pt-2.5">
504 <div className="flex h-8.25 -translate-y-px items-center gap-2 border-b border-border/70 pb-1.5 text-sm">
505 <span className="text-muted-foreground">
506 {controls?.effort?.descriptor.label ?? (controls?.others.length ? "Options" : "Effort")}
507 </span>
508 <span className="ms-auto min-w-0 truncate text-muted-foreground text-xs">
509 {picker.modelLabel}
510 </span>
511 </div>
512 </div>
513 {/* pt-2.5 puts the first level on the same line as the first model. */}
514 <div
515 className="flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto overscroll-contain px-2 pt-2.5 pb-1.5"
516 // Capture, so Up and Down on an option row move rows instead of opening its menu.
517 onKeyDownCapture={moveBetweenRows}
518 >
519 {props.traits ? <EffortLevels traits={props.traits} /> : <NoEffortRow />}
520 </div>
521 </>
522 );
523}
524
525const FOOTER_SEGMENT =
526 "flex h-6 cursor-pointer items-center justify-center gap-1 px-2 text-muted-foreground text-xs outline-none first:rounded-l-md last:rounded-r-md hover:text-foreground data-checked:bg-input/72 data-checked:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset";
527
528function SpeedSegment(props: {
529 checked: boolean;
530 label: string;
531 description?: string | undefined;
532 onPick: () => void;
533}) {
534 const buttonProps = {
535 type: "button",
536 role: "radio",
537 "aria-checked": props.checked,
538 "data-checked": props.checked || undefined,
539 className: FOOTER_SEGMENT,
540 onClick: props.onPick,
541 } as const;
542 const content = (
543 <>
544 {props.label === "Fast" || props.label === "Ultrafast" ? (
545 <FastBolt ultra={props.label === "Ultrafast"} />
546 ) : null}
547 {props.label}
548 </>
549 );
550 if (!props.description) return <button {...buttonProps}>{content}</button>;
551 return (
552 <Tooltip>
553 <TooltipTrigger render={<button {...buttonProps} />}>{content}</TooltipTrigger>
554 <TooltipPopup side="top">{props.description}</TooltipPopup>
555 </Tooltip>
556 );
557}
558
559function SpeedControl(props: { traits: TraitsSelectionInput }) {
560 const traits = useTraitsSelection(props.traits);
561 const { speedSelect, fastToggle } = splitSpeed(
562 traits.selectDescriptors,
563 traits.booleanDescriptors,
564 );
565 if (traits.modelIsUnavailable || (!speedSelect && !fastToggle)) return null;
566 return (
567 <div
568 role="radiogroup"
569 aria-label={speedSelect?.label ?? fastToggle?.label}
570 className="flex rounded-lg bg-input/40 p-0.5"
571 >
572 {speedSelect
573 ? selectableProviderOptionChoices(speedSelect).map((option) => (
574 <SpeedSegment
575 key={option.id}
576 checked={option.id === traits.selectValue(speedSelect)}
577 label={option.label}
578 description={option.description}
579 onPick={() => traits.changeSelect(speedSelect, option.id)}
580 />
581 ))
582 : fastToggle
583 ? ([false, true] as const).map((value) => (
584 <SpeedSegment
585 key={String(value)}
586 checked={(fastToggle.currentValue === true) === value}
587 label={value ? "Fast" : "Standard"}
588 onPick={() => traits.changeBoolean(fastToggle.id, value)}
589 />
590 ))
591 : null}
592 </div>
593 );
594}
595
596function UltracodeControl(props: { traits: TraitsSelectionInput }) {
597 const traits = useTraitsSelection(props.traits);
598 const { ultracodeToggle } = splitSpeed(traits.selectDescriptors, traits.booleanDescriptors);
599 if (traits.modelIsUnavailable || !ultracodeToggle) return null;
600 const on = ultracodeToggle.currentValue === true;
601 return (
602 <div className="flex rounded-lg bg-input/40 p-0.5">
603 <button
604 type="button"
605 aria-pressed={on}
606 data-checked={on || undefined}
607 className={FOOTER_SEGMENT}
608 onClick={() => traits.changeBoolean(ultracodeToggle.id, !on)}
609 >
610 <WorkflowIcon aria-hidden="true" className="size-3" />
611 {ultracodeToggle.label}
612 </button>
613 </div>
614 );
615}
616
617/** Permissions change rarely, so the footer names the mode and nests the choice in a menu. */
618function PermissionsMenu(props: {
619 runtimeMode: RuntimeMode;
620 options: ReadonlyArray<RuntimeModeOption>;
621 onChange: (mode: RuntimeMode) => void;
622}) {
623 const triggerRef = useRef<HTMLButtonElement>(null);
624 const current = props.options.find((option) => option.mode === props.runtimeMode);
625 if (!current) return null;
626 const CurrentIcon = current.icon;
627 return (
628 <Menu
629 onOpenChangeComplete={(open) => {
630 if (open) focusCheckedPermission(triggerRef.current);
631 }}
632 >
633 <MenuTrigger
634 render={
635 <button
636 ref={triggerRef}
637 type="button"
638 data-composer-permissions-trigger
639 aria-label={`Permissions: ${current.label}`}
640 className="ms-auto flex h-7 cursor-pointer items-center gap-1.5 rounded-md px-2 text-muted-foreground text-xs outline-none hover:bg-foreground/[0.09] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset data-popup-open:bg-foreground/[0.09] data-popup-open:text-foreground"
641 />
642 }
643 >
644 <CurrentIcon aria-hidden="true" className="size-3.5" />
645 {current.label}
646 <ChevronUpIcon aria-hidden="true" className="size-3" />
647 </MenuTrigger>
648 <MenuPopup side="top" align="end" {...composerFloatingLayerProps}>
649 <ComposerPermissionsSection
650 runtimeMode={props.runtimeMode}
651 runtimeModeOptions={props.options}
652 onRuntimeModeChange={props.onChange}
653 />
654 </MenuPopup>
655 </Menu>
656 );
657}
658
659/** The model picker's footer: speed stays one click away, permissions sit one menu deeper. */
660export function ComposerPickerFooter(props: {
661 traits: TraitsSelectionInput | null;
662 runtimeMode: RuntimeMode;
663 runtimeModeOptions: ReadonlyArray<RuntimeModeOption>;
664 onRuntimeModeChange: (mode: RuntimeMode) => void;
665}) {
666 return (
667 <div className="flex flex-wrap items-center gap-2 border-t border-border/70 bg-muted/40 px-3 py-2">
668 {props.traits ? <SpeedControl traits={props.traits} /> : null}
669 {props.traits ? <UltracodeControl traits={props.traits} /> : null}
670 <PermissionsMenu
671 runtimeMode={props.runtimeMode}
672 options={props.runtimeModeOptions}
673 onChange={props.onRuntimeModeChange}
674 />
675 </div>
676 );
677}