regenerate OpenAPI spec and add model selection components

This commit is contained in:
Chris Scott committed 2026-01-10 18:39:12 -05:00
1 parent 9ed292af2a
commit 17ee96d316
12 files changed
+10266 -3453

No files matched your search

+32 -11
View File
@@ -5,6 +5,7 @@ import { useCommands } from '@/hooks/useCommands'
import { useCommandHandler } from '@/hooks/useCommandHandler'
import { useFileSearch } from '@/hooks/useFileSearch'
import { useModelSelection } from '@/hooks/useModelSelection'
import { useVariants } from '@/hooks/useVariants'
import { useUserBash } from '@/stores/userBashStore'
import { useMobile } from '@/hooks/useMobile'
@@ -16,6 +17,7 @@ import { CommandSuggestions } from '@/components/command/CommandSuggestions'
import { SquareFill } from '@/components/ui/square-fill'
import { MentionSuggestions, type MentionItem } from './MentionSuggestions'
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
import { ModelQuickSelect } from '@/components/model/ModelQuickSelect'
import { detectMentionTrigger, parsePromptToParts, getFilename, filterAgentsByQuery } from '@/lib/promptParser'
@@ -86,6 +88,7 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
const [selectedMentionIndex, setSelectedMentionIndex] = useState(0)
const [selectedCommandIndex, setSelectedCommandIndex] = useState(0)
const [selectedAgent, setSelectedAgent] = useState<string | null>(null)
const [isFocused, setIsFocused] = useState(false)
const textareaRef = useRef<HTMLTextAreaElement>(null)
const fileInputRef = useRef<HTMLInputElement>(null)
@@ -176,7 +179,8 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
sessionID,
parts,
model: currentModel,
agent: selectedAgent || currentMode
agent: selectedAgent || currentMode,
variant: currentVariant
})
setPrompt('')
setAttachedFiles(new Map())
@@ -228,7 +232,8 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
sessionID,
parts,
model: currentModel,
agent: selectedAgent || currentMode
agent: selectedAgent || currentMode,
variant: currentVariant
})
setPrompt('')
@@ -596,6 +601,11 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
if (textareaRef.current) {
textareaRef.current.style.height = 'auto'
}
} else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 't') {
e.preventDefault()
if (hasVariants) {
cycleVariant()
}
}
}
@@ -666,12 +676,13 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
const modeBg = currentMode === 'plan' ? 'bg-yellow-500/20 border-yellow-400 hover:bg-yellow-500/30 hover:border-yellow-300' : 'bg-green-500/20 border-green-400 hover:bg-green-500/30 hover:border-green-300'
const modeShadow = currentMode === 'plan' ? 'shadow-yellow-500/20 hover:shadow-yellow-500/30' : 'shadow-green-500/20 hover:shadow-green-500/30'
const { model, modelString } = useModelSelection(opcodeUrl, directory)
const { model, modelString } = useModelSelection(opcodeUrl, directory)
const currentModel = modelString || ''
const displayModelName = model?.modelID || currentModel
const isMobile = useMobile()
const { setShowDialog, hasPermissionsForSession } = usePermissionContext()
const hasPendingPermissionForSession = hasPermissionsForSession(sessionID)
const { hasVariants, currentVariant, cycleVariant } = useVariants(opcodeUrl, directory)
const sessionStatus = useSessionStatusForSession(sessionID)
const isSessionActive = sessionStatus.type === 'busy' || sessionStatus.type === 'retry'
const hasActiveStream = hasIncompleteMessages && isSessionActive
@@ -694,7 +705,7 @@ export const PromptInput = forwardRef<PromptInputHandle, PromptInputProps>(funct
return (
<div className={`relative backdrop-blur-md bg-background opacity-95 border border-border dark:border-white/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full transition-all ${hasPendingPermissionForSession ? 'border-orange-500/50 ring-1 ring-orange-500/30' : ''}`}>
{showStopButton && (
{showStopButton && !(isFocused && prompt.trim().length > 0) && (
<button
onClick={handleStop}
disabled={disabled}
@@ -720,6 +731,8 @@ return (
: "Send a message..."
}
disabled={disabled}
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
className={`w-full bg-muted/50 pl-2 md:pl-3 pr-3 py-2 text-[16px] text-foreground placeholder-muted-foreground focus:outline-none focus:bg-muted/70 resize-none min-h-[40px] max-h-[120px] disabled:opacity-50 disabled:cursor-not-allowed md:text-sm rounded-lg ${
isBashMode
? 'border-purple-500/50 bg-purple-500/5 focus:bg-purple-500/10'
@@ -766,14 +779,22 @@ return (
</div>
) : (
!hideSecondaryButtons && (
<button
onClick={onShowModelsDialog}
className="px-2.5 py-1.5 md:px-3 h-[36px] rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] truncate dark:border-white/30"
<ModelQuickSelect
opcodeUrl={opcodeUrl}
directory={directory}
onOpenFullDialog={() => onShowModelsDialog?.()}
>
{displayModelName || 'Select model'}
</button>
)
)}
<button
className="px-2.5 py-0.5 md:px-3 min-h-[36px] rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer max-w-[150px] md:max-w-[220px] dark:border-white/30 flex flex-col items-start justify-center"
>
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
{hasVariants && currentVariant && (
<span className="text-[10px] text-orange-500 truncate w-full text-center capitalize">{currentVariant}</span>
)}
</button>
</ModelQuickSelect>
)
)}
</div>
<div className="flex items-center gap-1.5 md:gap-2 flex-shrink-0">
@@ -0,0 +1,148 @@
import { useMemo } from 'react'
import { Check, ChevronRight, Clock, Sparkles } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { useModelSelection } from '@/hooks/useModelSelection'
import { useVariants } from '@/hooks/useVariants'
import { formatModelName } from '@/api/providers'
import { useQuery } from '@tanstack/react-query'
import { useOpenCodeClient } from '@/hooks/useOpenCode'
interface ModelQuickSelectProps {
opcodeUrl: string | null | undefined
directory?: string
onOpenFullDialog: () => void
disabled?: boolean
children: React.ReactNode
}
export function ModelQuickSelect({
opcodeUrl,
directory,
onOpenFullDialog,
disabled,
children,
}: ModelQuickSelectProps) {
const { modelString, recentModels, setModel } = useModelSelection(opcodeUrl, directory)
const { availableVariants, currentVariant, setVariant, clearVariant, hasVariants } = useVariants(opcodeUrl, directory)
const client = useOpenCodeClient(opcodeUrl, directory)
const { data: providersData } = useQuery({
queryKey: ['opencode', 'providers', opcodeUrl, directory],
queryFn: () => client!.getProviders(),
enabled: !!client,
staleTime: 30000,
})
const recentModelsWithNames = useMemo(() => {
if (!providersData?.all || recentModels.length === 0) return []
return recentModels
.filter(recent => {
const key = `${recent.providerID}/${recent.modelID}`
return key !== modelString
})
.slice(0, 5)
.map(recent => {
let displayName = recent.modelID
for (const provider of providersData.all) {
if (provider.id === recent.providerID && provider.models) {
const modelData = provider.models[recent.modelID]
if (modelData) {
displayName = formatModelName(modelData)
break
}
}
}
return {
...recent,
displayName,
key: `${recent.providerID}/${recent.modelID}`,
}
})
}, [recentModels, providersData, modelString])
const handleVariantSelect = (variant: string | undefined) => {
if (variant === undefined) {
clearVariant()
} else {
setVariant(variant)
}
}
const handleModelSelect = (providerID: string, modelID: string) => {
setModel({ providerID, modelID })
}
const hasRecents = recentModelsWithNames.length > 0
return (
<DropdownMenu>
<DropdownMenuTrigger asChild disabled={disabled}>
{children}
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-56">
{hasVariants && (
<>
<DropdownMenuLabel className="flex items-center gap-1.5">
<Sparkles className="h-3 w-3" />
Thinking Effort
</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => handleVariantSelect(undefined)}
className="flex items-center justify-between"
>
<span>Default</span>
{!currentVariant && <Check className="h-4 w-4" />}
</DropdownMenuItem>
{availableVariants.map((variant) => (
<DropdownMenuItem
key={variant}
onClick={() => handleVariantSelect(variant)}
className="flex items-center justify-between"
>
<span className="capitalize text-orange-500 text-center">{variant}</span>
{currentVariant === variant && <Check className="h-4 w-4" />}
</DropdownMenuItem>
))}
{hasRecents && <DropdownMenuSeparator />}
</>
)}
{hasRecents && (
<>
<DropdownMenuLabel className="flex items-center gap-1.5">
<Clock className="h-3 w-3" />
Recent Models
</DropdownMenuLabel>
{recentModelsWithNames.map((recent) => (
<DropdownMenuItem
key={recent.key}
onClick={() => handleModelSelect(recent.providerID, recent.modelID)}
className="flex items-center justify-between"
>
<span className="truncate">{recent.displayName}</span>
{modelString === recent.key && <Check className="h-4 w-4" />}
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
</>
)}
<DropdownMenuItem
onClick={onOpenFullDialog}
className="flex items-center justify-between"
>
<span>All Models...</span>
<ChevronRight className="h-4 w-4" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}