The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | ANTIGRAVITY_DEFAULT_MODEL, |
| 3 | type ProviderInstanceId, |
| 4 | type EnvironmentId, |
| 5 | type ProviderDriverKind, |
| 6 | type ResolvedKeybindingsConfig, |
| 7 | } from "@t3tools/contracts"; |
| 8 | import { RegistryContext } from "@effect/atom-react"; |
| 9 | import { T, useGT } from "gt-react"; |
| 10 | import { |
| 11 | createContext, |
| 12 | memo, |
| 13 | type ReactNode, |
| 14 | useContext, |
| 15 | useEffect, |
| 16 | useEffectEvent, |
| 17 | useRef, |
| 18 | useState, |
| 19 | } from "react"; |
| 20 | import { Badge } from "../ui/badge"; |
| 21 | import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover"; |
| 22 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 23 | import { cn } from "~/lib/utils"; |
| 24 | import { useMediaQuery } from "../../hooks/useMediaQuery"; |
| 25 | import { ModelPickerContent, resolveModelPickerSelectedModel } from "./ModelPickerContent"; |
| 26 | import { retainedModelWhileProviderLocked } from "./ProviderModelPicker.logic"; |
| 27 | import { ChatGptSharingControl } from "./ChatGptSharingControl"; |
| 28 | import { ProviderInstanceIcon } from "./ProviderInstanceIcon"; |
| 29 | import { ModelEsque, getDisplayModelName, getTriggerDisplayModelName } from "./providerIconUtils"; |
| 30 | import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances"; |
| 31 | import { ComposerControl, type ComposerControlSize } from "./ComposerControl"; |
| 32 | import { takeOpenTarget, useComposerMenuProps } from "./composerEventScope"; |
| 33 | import { shortcutLabelForCommand } from "../../keybindings"; |
| 34 | import { serverEnvironment } from "../../state/server"; |
| 35 | import { useAtomCommand } from "../../state/use-atom-command"; |
| 36 | |
| 37 | /** Holds the page still behind the open picker; its lifetime is the popup element's. */ |
| 38 | function lockBackgroundScroll(popup: HTMLElement | null) { |
| 39 | if (!popup) return; |
| 40 | const { documentElement, body } = document; |
| 41 | const previousDocumentOverscrollBehavior = documentElement.style.overscrollBehavior; |
| 42 | const previousBodyOverflow = body.style.overflow; |
| 43 | const previousBodyPaddingRight = body.style.paddingRight; |
| 44 | const scrollbarWidth = window.innerWidth - documentElement.clientWidth; |
| 45 | |
| 46 | documentElement.style.overscrollBehavior = "contain"; |
| 47 | body.style.overflow = "hidden"; |
| 48 | if (scrollbarWidth > 0) { |
| 49 | body.style.paddingRight = `${scrollbarWidth}px`; |
| 50 | } |
| 51 | |
| 52 | const shouldAllowOverlayScroll = (target: EventTarget | null) => { |
| 53 | return ( |
| 54 | target instanceof Element && |
| 55 | target.closest( |
| 56 | "[data-model-picker-content], [data-model-picker-effort], [data-model-picker-option-menu]", |
| 57 | ) |
| 58 | ); |
| 59 | }; |
| 60 | const preventBackgroundWheel = (event: WheelEvent) => { |
| 61 | if (shouldAllowOverlayScroll(event.target)) { |
| 62 | return; |
| 63 | } |
| 64 | event.preventDefault(); |
| 65 | }; |
| 66 | const preventBackgroundTouchMove = (event: TouchEvent) => { |
| 67 | if (shouldAllowOverlayScroll(event.target)) { |
| 68 | return; |
| 69 | } |
| 70 | event.preventDefault(); |
| 71 | }; |
| 72 | |
| 73 | document.addEventListener("wheel", preventBackgroundWheel, { capture: true, passive: false }); |
| 74 | document.addEventListener("touchmove", preventBackgroundTouchMove, { |
| 75 | capture: true, |
| 76 | passive: false, |
| 77 | }); |
| 78 | |
| 79 | return () => { |
| 80 | document.removeEventListener("wheel", preventBackgroundWheel, { capture: true }); |
| 81 | document.removeEventListener("touchmove", preventBackgroundTouchMove, { capture: true }); |
| 82 | documentElement.style.overscrollBehavior = previousDocumentOverscrollBehavior; |
| 83 | body.style.overflow = previousBodyOverflow; |
| 84 | body.style.paddingRight = previousBodyPaddingRight; |
| 85 | }; |
| 86 | } |
| 87 | |
| 88 | /** What a docked effort column needs from its picker: the model it serves. */ |
| 89 | export const DockedPickerContext = createContext<{ modelLabel: string }>({ modelLabel: "" }); |
| 90 | |
| 91 | export const ProviderModelPicker = memo(function ProviderModelPicker(props: { |
| 92 | environmentId: EnvironmentId | null; |
| 93 | workspaceCwd?: string | null; |
| 94 | activeInstanceId: ProviderInstanceId; |
| 95 | model: string; |
| 96 | selectedModels?: ReadonlyArray<{ instanceId: ProviderInstanceId; model: string }>; |
| 97 | onToggleModel?: (instanceId: ProviderInstanceId, model: string) => void; |
| 98 | lockedProvider: ProviderDriverKind | null; |
| 99 | lockedContinuationGroupKey?: string | null; |
| 100 | instanceEntries: ReadonlyArray<ProviderInstanceEntry>; |
| 101 | keybindings?: ResolvedKeybindingsConfig; |
| 102 | modelOptionsByInstance: ReadonlyMap<ProviderInstanceId, ReadonlyArray<ModelEsque>>; |
| 103 | activeProviderIconClassName?: string; |
| 104 | instanceIndicatorBackground?: string; |
| 105 | size?: ComposerControlSize; |
| 106 | compact?: boolean; |
| 107 | isComposerOwned?: boolean; |
| 108 | disabled?: boolean; |
| 109 | terminalOpen?: boolean; |
| 110 | open?: boolean; |
| 111 | popupAlign?: "start" | "end"; |
| 112 | triggerClassName?: string; |
| 113 | triggerLabel?: string; |
| 114 | triggerAriaLabel?: string; |
| 115 | onOpenChange?: (open: boolean) => void; |
| 116 | onOpenProviderSetup?: (instanceId: ProviderInstanceId) => void; |
| 117 | getModelDisabledReason?: (instanceId: ProviderInstanceId, model: string) => string | null; |
| 118 | onInstanceModelChange: (instanceId: ProviderInstanceId, model: string) => void; |
| 119 | /** Shown after the model name inside the same trigger, such as the effort level. */ |
| 120 | triggerSuffix?: ReactNode; |
| 121 | /** Names the suffix for the tooltip and screen readers. */ |
| 122 | triggerDetail?: string | null; |
| 123 | /** Composer shortcuts this trigger answers besides the picker's own. */ |
| 124 | triggerShortcuts?: string; |
| 125 | /** |
| 126 | * Docks an effort column beside the list and a footer under both. The popup then stays open |
| 127 | * until Escape or an outside press, and picking a model moves focus to its levels. |
| 128 | */ |
| 129 | effortColumn?: ReactNode; |
| 130 | footer?: ReactNode; |
| 131 | }) { |
| 132 | const composerFloatingLayerProps = useComposerMenuProps(); |
| 133 | const [uncontrolledIsMenuOpen, setUncontrolledIsMenuOpen] = useState(false); |
| 134 | const isMenuOpen = props.open ?? uncontrolledIsMenuOpen; |
| 135 | const registry = useContext(RegistryContext); |
| 136 | const refreshProviders = useAtomCommand(serverEnvironment.refreshProviders, { |
| 137 | reportFailure: false, |
| 138 | }); |
| 139 | const refreshModelCatalog = useEffectEvent(() => { |
| 140 | const environmentId = props.environmentId; |
| 141 | if (environmentId === null) return; |
| 142 | // An older server drops the field and probes every provider. |
| 143 | const config = registry.get(serverEnvironment.configValueAtom(environmentId)); |
| 144 | if (config?.environment.capabilities.modelCatalogRefresh !== true) return; |
| 145 | void refreshProviders({ environmentId, input: { modelCatalogOnly: true } }); |
| 146 | }); |
| 147 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- asks the server for newly released models on every open; a parent, a keybinding or the palette can open the picker, so no one handler sees them all |
| 148 | useEffect(() => { |
| 149 | if (isMenuOpen) refreshModelCatalog(); |
| 150 | }, [isMenuOpen]); |
| 151 | const gt = useGT(); |
| 152 | const searchInputRef = useRef<HTMLInputElement>(null); |
| 153 | const triggerRef = useRef<HTMLButtonElement>(null); |
| 154 | const popupRef = useRef<HTMLDivElement | null>(null); |
| 155 | // Touch opens on the popup itself so the on-screen keyboard stays down until the search is tapped. |
| 156 | const isCoarsePointer = useMediaQuery({ pointer: "coarse" }); |
| 157 | const size = props.size ?? "sm"; |
| 158 | const docked = props.effortColumn !== undefined; |
| 159 | |
| 160 | const activeEntry = |
| 161 | props.instanceEntries.find((entry) => entry.instanceId === props.activeInstanceId) ?? null; |
| 162 | |
| 163 | const activeInstanceId = props.activeInstanceId; |
| 164 | const selectedInstanceOptions = props.modelOptionsByInstance.get(activeInstanceId) ?? []; |
| 165 | const selectedModel = |
| 166 | resolveModelPickerSelectedModel({ |
| 167 | driverKind: activeEntry?.driverKind, |
| 168 | model: props.model, |
| 169 | options: selectedInstanceOptions, |
| 170 | }) ?? |
| 171 | retainedModelWhileProviderLocked(activeEntry, props.model) ?? |
| 172 | (activeEntry?.driverKind === "opencode" || activeEntry?.driverKind === "antigravity" |
| 173 | ? undefined |
| 174 | : selectedInstanceOptions[0]); |
| 175 | const triggerTitle = selectedModel |
| 176 | ? getTriggerDisplayModelName(selectedModel, activeEntry?.driverKind) |
| 177 | : props.model === ANTIGRAVITY_DEFAULT_MODEL |
| 178 | ? gt("Choose model") |
| 179 | : props.model || gt("Choose model"); |
| 180 | const withUnavailable = (model: string, isUnavailable: boolean | undefined) => |
| 181 | isUnavailable ? gt("{model} (Unavailable)", { model }) : model; |
| 182 | const triggerLabel = selectedModel |
| 183 | ? withUnavailable(getDisplayModelName(selectedModel), selectedModel.isUnavailable) |
| 184 | : triggerTitle; |
| 185 | const showInstanceBadge = |
| 186 | activeEntry !== null && shouldShowInstanceBadge(activeEntry, props.instanceEntries); |
| 187 | |
| 188 | const setIsMenuOpen = (open: boolean) => { |
| 189 | props.onOpenChange?.(open); |
| 190 | if (props.open === undefined) { |
| 191 | setUncontrolledIsMenuOpen(open); |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * Focuses the selected reasoning level, else the first level. With `rows: "any"` it falls back |
| 197 | * to the column's first enabled option. False when nothing took focus. |
| 198 | */ |
| 199 | const focusEffort = (rows: "levels" | "any") => { |
| 200 | const column = popupRef.current?.querySelector("[data-model-picker-effort]"); |
| 201 | const level = |
| 202 | column?.querySelector<HTMLElement>( |
| 203 | '[data-effort-level][aria-checked="true"]:not(:disabled)', |
| 204 | ) ?? column?.querySelector<HTMLElement>("[data-effort-level]:not(:disabled)"); |
| 205 | // No aria-checked here: an On switch is checked but is not where focus belongs. |
| 206 | const row = |
| 207 | level ?? |
| 208 | (rows === "any" |
| 209 | ? column?.querySelector<HTMLElement>("[data-effort-row]:not(:disabled)") |
| 210 | : null); |
| 211 | row?.focus({ preventScroll: true }); |
| 212 | row?.scrollIntoView({ block: "nearest" }); |
| 213 | return row != null; |
| 214 | }; |
| 215 | const openTarget = (target: "effort" | "permissions") => { |
| 216 | if (target === "effort") { |
| 217 | focusEffort("any"); |
| 218 | return; |
| 219 | } |
| 220 | popupRef.current |
| 221 | ?.querySelector<HTMLButtonElement>("[data-composer-permissions-trigger]") |
| 222 | ?.click(); |
| 223 | }; |
| 224 | |
| 225 | const handleInstanceModelChange = (instanceId: ProviderInstanceId, model: string) => { |
| 226 | if (props.disabled) return; |
| 227 | props.onInstanceModelChange(instanceId, model); |
| 228 | if (!docked) { |
| 229 | setIsMenuOpen(false); |
| 230 | return; |
| 231 | } |
| 232 | // The column renders the new model's levels on commit. |
| 233 | window.requestAnimationFrame(() => focusEffort("levels")); |
| 234 | }; |
| 235 | |
| 236 | const shortcutLabel = props.keybindings |
| 237 | ? shortcutLabelForCommand(props.keybindings, "modelPicker.toggle") |
| 238 | : null; |
| 239 | const selectedEntries = props.selectedModels?.map((selection) => { |
| 240 | const entry = props.instanceEntries.find( |
| 241 | (candidate) => candidate.instanceId === selection.instanceId, |
| 242 | ); |
| 243 | const model = resolveModelPickerSelectedModel({ |
| 244 | driverKind: entry?.driverKind, |
| 245 | model: selection.model, |
| 246 | options: props.modelOptionsByInstance.get(selection.instanceId) ?? [], |
| 247 | }); |
| 248 | return { |
| 249 | ...selection, |
| 250 | entry, |
| 251 | label: model |
| 252 | ? withUnavailable(getTriggerDisplayModelName(model, entry?.driverKind), model.isUnavailable) |
| 253 | : selection.model, |
| 254 | fullLabel: model |
| 255 | ? withUnavailable(getDisplayModelName(model), model.isUnavailable) |
| 256 | : selection.model, |
| 257 | }; |
| 258 | }); |
| 259 | const multipleLabel = selectedEntries |
| 260 | ? selectedEntries.length === 0 |
| 261 | ? gt("Choose models") |
| 262 | : selectedEntries.length > 2 |
| 263 | ? gt("{count, plural, one {{models}, {count} more} other {{models}, {count} more}}", { |
| 264 | models: selectedEntries |
| 265 | .slice(0, 2) |
| 266 | .map((selection) => selection.label) |
| 267 | .join(", "), |
| 268 | count: selectedEntries.length - 2, |
| 269 | }) |
| 270 | : selectedEntries.map((selection) => selection.label).join(", ") |
| 271 | : undefined; |
| 272 | const allModelNames = selectedEntries |
| 273 | ? selectedEntries.map((selection) => selection.fullLabel).join(", ") || gt("Choose models") |
| 274 | : undefined; |
| 275 | const triggerTooltipContent = [ |
| 276 | props.triggerLabel ?? allModelNames ?? triggerLabel, |
| 277 | props.triggerDetail, |
| 278 | shortcutLabel, |
| 279 | ] |
| 280 | .filter(Boolean) |
| 281 | .join(" · "); |
| 282 | |
| 283 | const triggerText = props.triggerLabel ?? multipleLabel ?? triggerTitle; |
| 284 | const triggerTextProps = { |
| 285 | className: cn( |
| 286 | "min-w-0 flex-1 overflow-hidden truncate", |
| 287 | // Long names such as "Fusion (Claude Opus 5.5 Medium + SWE-2 High)" would push the composer. |
| 288 | props.isComposerOwned && "max-w-56", |
| 289 | ), |
| 290 | "data-chat-provider-model-picker-label": "true", |
| 291 | } as const; |
| 292 | |
| 293 | const picker = ( |
| 294 | <ModelPickerContent |
| 295 | searchInputRef={searchInputRef} |
| 296 | environmentId={props.environmentId} |
| 297 | workspaceCwd={props.workspaceCwd ?? null} |
| 298 | activeInstanceId={activeInstanceId} |
| 299 | model={props.model} |
| 300 | {...(props.selectedModels !== undefined ? { selectedModels: props.selectedModels } : {})} |
| 301 | {...(props.onToggleModel |
| 302 | ? { |
| 303 | onToggleModel: (instanceId: ProviderInstanceId, model: string) => { |
| 304 | if (!props.disabled) props.onToggleModel?.(instanceId, model); |
| 305 | }, |
| 306 | } |
| 307 | : {})} |
| 308 | lockedProvider={props.lockedProvider} |
| 309 | lockedContinuationGroupKey={props.lockedContinuationGroupKey ?? null} |
| 310 | instanceEntries={props.instanceEntries} |
| 311 | {...(props.keybindings ? { keybindings: props.keybindings } : {})} |
| 312 | modelOptionsByInstance={props.modelOptionsByInstance} |
| 313 | terminalOpen={props.terminalOpen ?? false} |
| 314 | onRequestClose={() => setIsMenuOpen(false)} |
| 315 | {...(props.onOpenProviderSetup ? { onOpenProviderSetup: props.onOpenProviderSetup } : {})} |
| 316 | getModelDisabledReason={(instanceId, model) => |
| 317 | props.disabled |
| 318 | ? gt("Model picker is disabled") |
| 319 | : (props.getModelDisabledReason?.(instanceId, model) ?? null) |
| 320 | } |
| 321 | onInstanceModelChange={handleInstanceModelChange} |
| 322 | {...(docked |
| 323 | ? { |
| 324 | docked, |
| 325 | onFocusEffort: () => void focusEffort("any"), |
| 326 | // Inside the fixed height, so switching to or from a ChatGPT plan never resizes it. |
| 327 | ...(props.selectedModels === undefined |
| 328 | ? { listFooter: <ChatGptSharingControl provider={activeEntry?.snapshot ?? null} /> } |
| 329 | : {}), |
| 330 | } |
| 331 | : {})} |
| 332 | /> |
| 333 | ); |
| 334 | |
| 335 | return ( |
| 336 | <Popover |
| 337 | open={isMenuOpen} |
| 338 | onOpenChange={(open) => { |
| 339 | if (props.disabled) { |
| 340 | setIsMenuOpen(false); |
| 341 | return; |
| 342 | } |
| 343 | setIsMenuOpen(open); |
| 344 | }} |
| 345 | onOpenChangeComplete={(open) => { |
| 346 | const target = takeOpenTarget(triggerRef.current); |
| 347 | if (open && docked && target) openTarget(target); |
| 348 | }} |
| 349 | > |
| 350 | <PopoverTrigger |
| 351 | render={ |
| 352 | <ComposerControl |
| 353 | ref={triggerRef} |
| 354 | aria-label={[ |
| 355 | props.triggerAriaLabel ?? props.triggerLabel ?? allModelNames ?? triggerLabel, |
| 356 | props.triggerDetail, |
| 357 | ] |
| 358 | .filter(Boolean) |
| 359 | .join(", ")} |
| 360 | size={size} |
| 361 | data-chat-provider-model-picker="true" |
| 362 | data-composer-shortcut={props.triggerShortcuts} |
| 363 | onClick={(event) => { |
| 364 | if (!isMenuOpen || !docked) return; |
| 365 | const target = takeOpenTarget(triggerRef.current); |
| 366 | if (!target) return; |
| 367 | // A shortcut aimed at the open picker moves within it instead of closing it. |
| 368 | ( |
| 369 | event as typeof event & { preventBaseUIHandler?: () => void } |
| 370 | ).preventBaseUIHandler?.(); |
| 371 | openTarget(target); |
| 372 | }} |
| 373 | className={cn( |
| 374 | "min-w-0 shrink justify-between whitespace-nowrap", |
| 375 | props.compact |
| 376 | ? "max-w-42 shrink-0" |
| 377 | : !props.isComposerOwned && "max-w-48 sm:max-w-56", |
| 378 | props.triggerClassName, |
| 379 | )} |
| 380 | disabled={props.disabled} |
| 381 | /> |
| 382 | } |
| 383 | > |
| 384 | <span |
| 385 | className={cn("flex min-w-0 flex-1 items-center", size === "xs" ? "gap-1" : "gap-1.5")} |
| 386 | > |
| 387 | {selectedEntries && props.triggerLabel === undefined ? ( |
| 388 | <span |
| 389 | data-chat-provider-model-picker-icon |
| 390 | className="flex shrink-0 items-center -space-x-1" |
| 391 | aria-hidden="true" |
| 392 | > |
| 393 | {selectedEntries |
| 394 | .slice(0, 3) |
| 395 | .map((selection) => |
| 396 | selection.entry ? ( |
| 397 | <ProviderInstanceIcon |
| 398 | key={`${selection.instanceId}:${selection.model}`} |
| 399 | driverKind={selection.entry.driverKind} |
| 400 | displayName={selection.entry.displayName} |
| 401 | accentColor={selection.entry.accentColor} |
| 402 | acpRegistryAgentId={selection.entry.acpRegistryAgentId} |
| 403 | acpRegistryIconUrl={selection.entry.acpRegistryIconUrl} |
| 404 | className="size-4 rounded-full bg-(--chat-composer-glass-surface,var(--background)) ring-2 ring-(--chat-composer-glass-surface,var(--background))" |
| 405 | iconClassName="size-4" |
| 406 | /> |
| 407 | ) : null, |
| 408 | )} |
| 409 | {selectedEntries.length > 3 ? ( |
| 410 | <span className="relative z-30 flex size-4 items-center justify-center rounded-full bg-(--chat-composer-glass-surface,var(--background)) text-3xs ring-2 ring-(--chat-composer-glass-surface,var(--background))"> |
| 411 | +{selectedEntries.length - 3} |
| 412 | </span> |
| 413 | ) : null} |
| 414 | </span> |
| 415 | ) : activeEntry && props.triggerLabel === undefined ? ( |
| 416 | // Narrow compacted composers hide the provider icon before truncating the name. |
| 417 | <span data-chat-provider-model-picker-icon className="contents"> |
| 418 | <ProviderInstanceIcon |
| 419 | driverKind={activeEntry.driverKind} |
| 420 | displayName={activeEntry.displayName} |
| 421 | accentColor={activeEntry.accentColor} |
| 422 | acpRegistryAgentId={activeEntry.acpRegistryAgentId} |
| 423 | acpRegistryIconUrl={activeEntry.acpRegistryIconUrl} |
| 424 | showBadge={showInstanceBadge} |
| 425 | className="size-4" |
| 426 | iconClassName={cn("size-4", props.activeProviderIconClassName)} |
| 427 | indicatorBackground={props.instanceIndicatorBackground ?? "var(--contrast-input)"} |
| 428 | badgeClassName={cn( |
| 429 | "right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs", |
| 430 | size === "xs" && "shadow-none", |
| 431 | )} |
| 432 | /> |
| 433 | </span> |
| 434 | ) : null} |
| 435 | {props.isComposerOwned ? ( |
| 436 | <span {...triggerTextProps}>{triggerText}</span> |
| 437 | ) : ( |
| 438 | <Tooltip> |
| 439 | <TooltipTrigger render={<span {...triggerTextProps} />}>{triggerText}</TooltipTrigger> |
| 440 | <TooltipPopup side="top">{triggerTooltipContent}</TooltipPopup> |
| 441 | </Tooltip> |
| 442 | )} |
| 443 | {props.triggerSuffix} |
| 444 | {selectedModel?.isUnavailable && !selectedEntries && props.triggerLabel === undefined ? ( |
| 445 | <Badge variant="outline" size="sm"> |
| 446 | <T context="badge on a model that cannot be selected">Unavailable</T> |
| 447 | </Badge> |
| 448 | ) : null} |
| 449 | </span> |
| 450 | </PopoverTrigger> |
| 451 | <PopoverPopup |
| 452 | {...(props.isComposerOwned ? composerFloatingLayerProps : {})} |
| 453 | ref={(popup) => { |
| 454 | popupRef.current = popup; |
| 455 | const unlock = lockBackgroundScroll(popup); |
| 456 | return () => { |
| 457 | popupRef.current = null; |
| 458 | unlock?.(); |
| 459 | }; |
| 460 | }} |
| 461 | initialFocus={isCoarsePointer ? popupRef : searchInputRef} |
| 462 | align={props.popupAlign ?? "start"} |
| 463 | // Docked, the popup opens above the composer and slides over it when that space is short, |
| 464 | // so a short window gets its full height (Floating UI sizes to the viewport) instead of a sliver. |
| 465 | {...(docked |
| 466 | ? { side: "top" as const, collisionAvoidance: { side: "shift", align: "shift" } as const } |
| 467 | : {})} |
| 468 | className="before:hidden" |
| 469 | padding="none" |
| 470 | touchBackdrop |
| 471 | > |
| 472 | {props.effortColumn ? ( |
| 473 | <DockedPickerContext value={{ modelLabel: triggerTitle }}> |
| 474 | <div className="flex max-h-(--available-height) flex-col"> |
| 475 | {/* One fixed height, so a model with more options never resizes the popup. Short |
| 476 | windows shrink it and keep the footer. */} |
| 477 | <div className="flex h-86.5 min-h-0 max-sm:h-auto max-sm:flex-col"> |
| 478 | {picker} |
| 479 | <div |
| 480 | data-model-picker-effort |
| 481 | className="flex min-h-0 w-48 flex-col sm:shrink-0 border-l border-border/70 bg-muted/40 max-sm:h-64 max-sm:w-full max-sm:border-t max-sm:border-l-0" |
| 482 | onKeyDown={(event) => { |
| 483 | if (event.key !== "ArrowLeft" || event.altKey || event.ctrlKey || event.metaKey) |
| 484 | return; |
| 485 | event.preventDefault(); |
| 486 | event.stopPropagation(); |
| 487 | searchInputRef.current?.focus(); |
| 488 | }} |
| 489 | > |
| 490 | {props.effortColumn} |
| 491 | </div> |
| 492 | </div> |
| 493 | {props.footer} |
| 494 | </div> |
| 495 | </DockedPickerContext> |
| 496 | ) : ( |
| 497 | picker |
| 498 | )} |
| 499 | {props.selectedModels === undefined && !docked ? ( |
| 500 | <ChatGptSharingControl provider={activeEntry?.snapshot ?? null} /> |
| 501 | ) : null} |
| 502 | </PopoverPopup> |
| 503 | </Popover> |
| 504 | ); |
| 505 | }); |