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