Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 122 additions & 51 deletions webview-ui/src/components/chat/ApiConfigSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useMemo, useCallback } from "react"
import { useState, useMemo, useCallback, useEffect, type ReactNode } from "react"
import { Fzf } from "fzf"
import { Brain, ChevronDown } from "lucide-react"

import { cn } from "@/lib/utils"
import { enabledSelectorTriggerClassName, selectorTriggerClassName } from "@/components/ui/selectorTriggerStyles"
Expand All @@ -10,10 +11,14 @@ import { vscode } from "@/utils/vscode"
import { Button } from "@/components/ui"

import { IconButton } from "./IconButton"
import { PickerSearchField } from "./PickerSearchField"

interface ApiConfigSelectorProps {
value: string
displayName: string
modelId?: string
reasoningEffort?: string
quickSettings?: ReactNode | ((onModelSelected: () => void) => ReactNode)
disabled?: boolean
title: string
onChange: (value: string) => void
Expand All @@ -28,6 +33,9 @@ interface ApiConfigSelectorProps {
export const ApiConfigSelector = ({
value,
displayName,
modelId,
reasoningEffort,
quickSettings,
disabled = false,
title,
onChange,
Expand All @@ -41,6 +49,12 @@ export const ApiConfigSelector = ({
const { t } = useAppTranslation()
const [open, setOpen] = useState(false)
const [searchValue, setSearchValue] = useState("")
const [showProfiles, setShowProfiles] = useState(false)
const [pendingProfileId, setPendingProfileId] = useState<string | null>(null)
const isProfileView = !quickSettings || showProfiles
useEffect(() => {
setPendingProfileId(null)
}, [value])
const portalContainer = useRooPortal("roo-portal")

// Create searchable items for fuzzy search.
Expand Down Expand Up @@ -79,10 +93,13 @@ export const ApiConfigSelector = ({
const handleSelect = useCallback(
(configId: string) => {
onChange(configId)
setOpen(false)
if (quickSettings) {
setPendingProfileId(configId === value ? null : configId)
setShowProfiles(false)
} else setOpen(false)
setSearchValue("")
},
[onChange],
[onChange, quickSettings, value],
)

const handleEditClick = useCallback(() => {
Expand All @@ -97,6 +114,10 @@ export const ApiConfigSelector = ({
return (
<div
key={config.id}
tabIndex={quickSettings ? 0 : undefined}
onKeyDown={(event) => {
if (event.key === "Enter" && event.target === event.currentTarget) handleSelect(config.id)
}}
onClick={() => handleSelect(config.id)}
className={cn(
"px-3 py-1.5 text-sm cursor-pointer flex items-center group",
Expand Down Expand Up @@ -143,11 +164,21 @@ export const ApiConfigSelector = ({
</div>
)
},
[value, handleSelect, t, togglePinnedApiConfig],
[value, handleSelect, t, togglePinnedApiConfig, quickSettings],
)

return (
<Popover open={open} onOpenChange={setOpen} data-testid="api-config-selector-root">
<Popover
open={open}
onOpenChange={(nextOpen) => {
setOpen(nextOpen)
if (!nextOpen) {
setShowProfiles(false)
setPendingProfileId(null)
setSearchValue("")
}
}}
data-testid="api-config-selector-root">
<StandardTooltip content={title}>
<PopoverTrigger
disabled={disabled}
Expand All @@ -158,7 +189,22 @@ export const ApiConfigSelector = ({
disabled ? "opacity-50 cursor-not-allowed" : enabledSelectorTriggerClassName,
triggerClassName,
)}>
<span className="truncate">{displayName}</span>
<span className="flex min-w-0 items-center gap-1.5">
<span className="truncate">
<span className="opacity-70">{displayName}</span>
{modelId && <> / {modelId}</>}
</span>
{reasoningEffort && reasoningEffort !== "disable" && (
<span
aria-label={t("chat:modelPicker.reasoningEffortValue", {
effort: t(`chat:modelPicker.effort.${reasoningEffort}`),
})}
className="inline-flex shrink-0 items-center gap-1 rounded border border-vscode-input-border px-1 py-0.5 text-[10px] leading-none">
<Brain aria-hidden="true" className="size-3" />
{t(`chat:modelPicker.effort.${reasoningEffort}`)}
</span>
)}
</span>
</PopoverTrigger>
</StandardTooltip>
<PopoverContent
Expand All @@ -167,60 +213,85 @@ export const ApiConfigSelector = ({
container={portalContainer}
className="p-0 overflow-hidden w-[300px]">
<div className="flex flex-col w-full">
{/* Search input or info blurb */}
{listApiConfigMeta.length > 6 ? (
<div className="relative p-2 border-b border-vscode-dropdown-border">
<input
aria-label={t("common:ui.search_placeholder")}
value={searchValue}
onChange={(e) => setSearchValue(e.target.value)}
placeholder={t("common:ui.search_placeholder")}
className="w-full h-8 px-2 py-1 text-xs bg-vscode-input-background text-vscode-input-foreground border border-vscode-input-border rounded focus:outline-0"
autoFocus
{quickSettings && (
<button
type="button"
aria-label={t("chat:modelPicker.selectProfile")}
aria-expanded={showProfiles}
disabled={disabled}
onClick={() => {
setShowProfiles(!showProfiles)
setSearchValue("")
}}
className="flex w-full min-w-0 cursor-pointer items-center gap-2 border-none border-b border-solid border-vscode-dropdown-border bg-transparent px-3 py-2.5 text-left text-xs text-vscode-foreground hover:bg-vscode-list-hoverBackground focus-visible:ring-1 focus-visible:ring-vscode-focusBorder">
<span className="shrink-0 text-vscode-descriptionForeground">
{t("chat:modelPicker.profile")}
</span>
<span className="min-w-0 flex-1 truncate font-semibold">{displayName}</span>
<ChevronDown
aria-hidden="true"
className={cn("size-3 shrink-0 transition-transform", showProfiles && "rotate-180")}
/>
{searchValue.length > 0 && (
<div className="absolute right-4 top-0 bottom-0 flex items-center justify-center">
<span
className="codicon codicon-close text-vscode-input-foreground opacity-50 hover:opacity-100 text-xs cursor-pointer"
onClick={() => setSearchValue("")}
/>
</button>
)}
{!isProfileView &&
(pendingProfileId && pendingProfileId !== value ? (
<div className="p-3 text-xs text-vscode-descriptionForeground">
{t("chat:modelPicker.loadingProfile")}
</div>
) : typeof quickSettings === "function" ? (
quickSettings(() => setOpen(false))
) : (
quickSettings
))}
{isProfileView && (
<>
{/* Search input or info blurb */}
{quickSettings || listApiConfigMeta.length > 6 ? (
<PickerSearchField
label={t("common:ui.search_placeholder")}
value={searchValue}
onChange={setSearchValue}
disabled={disabled}
/>
) : (
<div className="p-3 border-b border-vscode-dropdown-border">
<p className="text-xs text-vscode-descriptionForeground m-0">
{t("prompts:apiConfiguration.select")}
</p>
</div>
)}
</div>
) : (
<div className="p-3 border-b border-vscode-dropdown-border">
<p className="text-xs text-vscode-descriptionForeground m-0">
{t("prompts:apiConfiguration.select")}
</p>
</div>
)}

{/* Config list - single scroll container */}
{filteredConfigs.length === 0 && searchValue ? (
<div className="py-2 px-3 text-sm text-vscode-foreground/70">{t("common:ui.no_results")}</div>
) : (
<div className="max-h-[300px] overflow-y-auto">
{/* Pinned configs - sticky header */}
{pinnedConfigs.length > 0 && (
<div
className={cn(
"sticky top-0 z-10 bg-vscode-dropdown-background py-1",
unpinnedConfigs.length > 0 && "border-b border-vscode-dropdown-foreground/10",
)}
aria-label="Pinned configurations">
{pinnedConfigs.map((config) => renderConfigItem(config, true))}
{/* Config list - single scroll container */}
{filteredConfigs.length === 0 && searchValue ? (
<div className="px-3 py-2 text-xs text-vscode-descriptionForeground">
{t("common:ui.no_results")}
</div>
)}
) : (
<div className="max-h-[300px] overflow-y-auto">
{/* Pinned configs - sticky header */}
{pinnedConfigs.length > 0 && (
<div
className={cn(
"sticky top-0 z-10 bg-vscode-dropdown-background py-1",
unpinnedConfigs.length > 0 &&
"border-b border-vscode-dropdown-foreground/10",
)}
aria-label="Pinned configurations">
{pinnedConfigs.map((config) => renderConfigItem(config, true))}
</div>
)}

{/* Unpinned configs */}
{unpinnedConfigs.length > 0 && (
<div className="py-1" aria-label="All configurations">
{unpinnedConfigs.map((config) => renderConfigItem(config, false))}
{/* Unpinned configs */}
{unpinnedConfigs.length > 0 && (
<div className="py-1" aria-label="All configurations">
{unpinnedConfigs.map((config) => renderConfigItem(config, false))}
</div>
)}
</div>
)}
</div>
</>
)}

{/* Bottom bar with buttons on left and title on right */}
<div className="flex flex-row items-center justify-between px-2 py-2 border-t border-vscode-dropdown-border">
<div className="flex flex-row gap-1">
Expand Down
30 changes: 29 additions & 1 deletion webview-ui/src/components/chat/ChatTextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEvent } from "react-use"
import DynamicTextArea from "react-textarea-autosize"
import { VolumeX, Image, WandSparkles, SendHorizontal, X, ListEnd, Square } from "lucide-react"

import type { ExtensionMessage } from "@roo-code/types"
import { type ExtensionMessage, providerIdentifiers } from "@roo-code/types"

import { mentionRegex, mentionRegexGlobal, commandRegexGlobal, unescapeSpaces } from "@roo/context-mentions"
import { WebviewMessage } from "@roo/WebviewMessage"
Expand All @@ -23,10 +23,12 @@ import {
import { cn } from "@src/lib/utils"
import { convertToMentionPath } from "@src/utils/path-mentions"
import { StandardTooltip } from "@src/components/ui"
import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel"

import Thumbnails from "../common/Thumbnails"
import { ModeSelector } from "./ModeSelector"
import { ApiConfigSelector } from "./ApiConfigSelector"
import { ProfileQuickSettings } from "./ProfileQuickSettings"
import { AutoApproveDropdown } from "./AutoApproveDropdown"
import { MAX_IMAGES_PER_MESSAGE } from "./constants"
import ContextMenu from "./ContextMenu"
Expand Down Expand Up @@ -90,6 +92,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(

const { t } = useAppTranslation()
const {
apiConfiguration,
filePaths,
openedTabs,
currentApiConfigName,
Expand All @@ -105,6 +108,22 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
enterBehavior,
lockApiConfigAcrossModes,
} = useExtensionState()
const { id: selectedModelId, info: selectedModelInfo } = useSelectedModel(apiConfiguration)
const supportsEffort = selectedModelInfo?.supportsReasoningEffort
const hasEffort =
(apiConfiguration?.apiProvider === providerIdentifiers.openai &&
apiConfiguration.enableReasoningEffort === true) ||
supportsEffort === true ||
(Array.isArray(supportsEffort) && supportsEffort.length > 0)
const selectedEffort =
(apiConfiguration?.apiProvider === providerIdentifiers.openai
? apiConfiguration.openAiCustomModelInfo?.reasoningEffort
: apiConfiguration?.reasoningEffort) ?? selectedModelInfo?.reasoningEffort
const reasoningEffort =
hasEffort &&
(selectedModelInfo?.requiredReasoningEffort || apiConfiguration?.enableReasoningEffort !== false)
? selectedEffort
: undefined

// Find the ID and display text for the currently selected API configuration.
const { currentConfigId, displayName } = useMemo(() => {
Expand Down Expand Up @@ -1309,6 +1328,15 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
<ApiConfigSelector
value={currentConfigId}
displayName={displayName}
modelId={selectedModelId}
reasoningEffort={reasoningEffort}
quickSettings={(onModelSelected) => (
<ProfileQuickSettings
key={currentConfigId}
disabled={selectApiConfigDisabled}
onModelSelected={onModelSelected}
/>
)}
disabled={selectApiConfigDisabled}
title={t("chat:selectApiConfig")}
onChange={handleApiConfigChange}
Expand Down
47 changes: 47 additions & 0 deletions webview-ui/src/components/chat/PickerSearchField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useRef } from "react"
import { Search, X } from "lucide-react"

import { useAppTranslation } from "@src/i18n/TranslationContext"

interface PickerSearchFieldProps {
label: string
value: string
onChange: (value: string) => void
disabled?: boolean
}

/** Shared geometry and interactions for the profile and model views of the picker. */
export function PickerSearchField({ label, value, onChange, disabled = false }: PickerSearchFieldProps) {
const { t } = useAppTranslation()
const inputRef = useRef<HTMLInputElement>(null)
return (
<div className="border-b border-vscode-dropdown-border px-3 py-2">
<div className="flex items-center gap-2 rounded border border-vscode-input-border bg-vscode-input-background px-2 focus-within:ring-1 focus-within:ring-vscode-focusBorder">
<Search aria-hidden="true" className="size-3 shrink-0 text-vscode-input-foreground opacity-60" />
<input
ref={inputRef}
aria-label={label}
placeholder={t("common:ui.search_placeholder")}
value={value}
onChange={(event) => onChange(event.target.value)}
disabled={disabled}
autoFocus
className="h-8 w-full min-w-0 border-none bg-transparent text-xs text-vscode-input-foreground outline-none disabled:opacity-50"
/>
{value && (
<button
type="button"
aria-label={t("chat:modelPicker.clearSearch")}
disabled={disabled}
onClick={() => {
onChange("")
inputRef.current?.focus()
}}
className="flex size-4 shrink-0 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-vscode-input-foreground opacity-60 hover:opacity-100 focus-visible:ring-1 focus-visible:ring-vscode-focusBorder disabled:cursor-not-allowed">
<X aria-hidden="true" className="size-3" />
</button>
)}
</div>
</div>
)
}
Loading
Loading