@@ -269,8 +269,6 @@ import {
269269} from "~/state/pullRequests" ;
270270import { useEnvironmentQuery } from "~/state/query" ;
271271import { useComposerPathSearch , useDebouncedValue } from "~/state/queries" ;
272- import { ProviderModelPicker } from "./ProviderModelPicker" ;
273- import { resolveModelPickerSelectedModel } from "./ModelPickerContent" ;
274272import {
275273 type ComposerCommandItem ,
276274 ComposerCommandMenu ,
@@ -279,14 +277,19 @@ import {
279277import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions" ;
280278import { CompactComposerControlsMenu } from "./CompactComposerControlsMenu" ;
281279import {
280+ ComposerAttachButton ,
282281 ComposerAttachmentFileList ,
283282 ComposerAttachmentMediaRow ,
284283 ComposerFilePreviewDialog ,
285284 ComposerQueuedAttachmentRow ,
286285 ComposerRestingImagePreviews ,
287286} from "./ComposerAttachmentStrip" ;
288287import { ComposerPrimaryActions } from "./ComposerPrimaryActions" ;
289- import { ComposerFooterModeControls , ComposerFooterPrimaryActions } from "./ComposerFooterControls" ;
288+ import {
289+ ComposerFooterModeControls ,
290+ ComposerFooterPrimaryActions ,
291+ ComposerModelPicker ,
292+ } from "./ComposerFooterControls" ;
290293import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel" ;
291294import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel" ;
292295import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner" ;
@@ -965,10 +968,8 @@ function ComposerCommandMenuLayer(props: { anchor: HTMLElement | null; children:
965968 document . body ,
966969 ) ;
967970}
968- import { Button } from "../ui/button" ;
969- import { Tooltip , TooltipPopup , TooltipTrigger } from "../ui/tooltip" ;
970971import { toastManager } from "../ui/toast" ;
971- import { CircleAlertIcon , PaperclipIcon , PlayIcon , ShieldIcon } from "lucide-react" ;
972+ import { CircleAlertIcon , PlayIcon , ShieldIcon } from "lucide-react" ;
972973import { proposedPlanTitle } from "@t3tools/shared/proposedPlanText" ;
973974import { hasProviderSetup } from "./ProviderStatusBanner" ;
974975import {
@@ -2184,7 +2185,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
21842185 targetKey : "" ,
21852186 names : new Set ( ) ,
21862187 } ) ;
2187- const attachmentInputRef = useRef < HTMLInputElement > ( null ) ;
21882188 const composerFormRef = useRef < HTMLFormElement > ( null ) ;
21892189 const composerSurfaceRef = useRef < HTMLDivElement > ( null ) ;
21902190 const providerInputRejectedRef = useRef ( false ) ;
@@ -4785,6 +4785,64 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
47854785 const hiddenRestingBlockIds = restingBlockDefs
47864786 . slice ( restingBlockDefs . length - restingHiddenBlockCount )
47874787 . map ( ( def ) => def . id ) ;
4788+ // Its own element, so typing (which rebuilds the controls around it) leaves it cached.
4789+ const composerModelPicker = (
4790+ < ComposerModelPicker
4791+ environmentId = { environmentId }
4792+ compact = { false }
4793+ isComposerOwned
4794+ disabled = { providerCatalogPending || isSendBusy }
4795+ multipleModelsEnabled = { routeKind === "draft" && supportsMultipleModels }
4796+ multipleModelSelections = { multipleModelSelections }
4797+ onMultipleModelSelectionsChange = { setMultipleModelSelections }
4798+ selectedModelSelection = { selectedModelSelection }
4799+ onProviderModelSelect = { onProviderModelSelect }
4800+ activeInstanceId = {
4801+ providerCatalogPending
4802+ ? ( activeThreadModelSelection ?. instanceId ?? selectedInstanceId )
4803+ : selectedInstanceId
4804+ }
4805+ model = {
4806+ providerCatalogPending
4807+ ? ( activeThreadModelSelection ?. model ?? selectedModelForPickerWithCustomFallback )
4808+ : selectedModelForPickerWithCustomFallback
4809+ }
4810+ lockedProvider = { lockedProvider }
4811+ lockedContinuationGroupKey = { lockedContinuationGroupKey }
4812+ instanceEntries = { providerInstanceEntries }
4813+ keybindings = { keybindings }
4814+ modelOptionsByInstance = { modelOptionsByInstance }
4815+ size = { composerControlsCollapsed ? "xs" : "sm" }
4816+ triggerClassName = {
4817+ composerControlsCollapsed
4818+ ? cn (
4819+ "min-w-13 shrink text-xs!" ,
4820+ ! showInlineRestingControls &&
4821+ "@max-[640px]/composer-surface:[&_[data-chat-provider-model-picker-label]]:w-0 @max-[640px]/composer-surface:[&_[data-chat-provider-model-picker-label]]:flex-none" ,
4822+ )
4823+ : "-ms-2.5 min-w-13"
4824+ }
4825+ terminalOpen = { terminalOpen }
4826+ open = { isComposerModelPickerOpen }
4827+ instanceIndicatorBackground = {
4828+ composerControlsCollapsed
4829+ ? "color-mix(in srgb, var(--chat-composer-glass-surface) var(--glass-opacity), transparent)"
4830+ : "var(--contrast-input)"
4831+ }
4832+ { ...( composerProviderState . modelPickerIconClassName || composerControlsCollapsed
4833+ ? {
4834+ activeProviderIconClassName : cn (
4835+ composerProviderState . modelPickerIconClassName ,
4836+ composerControlsCollapsed &&
4837+ "fill-muted-foreground/70! text-muted-foreground/70! [&_path]:fill-muted-foreground/70! [&_rect]:fill-muted-foreground/70! [&_[data-icon-detail]]:fill-transparent! [&[data-provider-package-icon]]:opacity-70 [&[data-provider-package-icon]_path:not([data-icon-detail])]:fill-muted-foreground!" ,
4838+ ) ,
4839+ }
4840+ : { } ) }
4841+ onOpenChange = { setIsComposerModelPickerOpen }
4842+ getModelDisabledReason = { getModelDisabledReason }
4843+ onOpenProviderSetup = { onOpenProviderSetup }
4844+ />
4845+ ) ;
47884846 const composerControls = showProviderUnavailable ? (
47894847 < ComposerControl
47904848 type = "button"
@@ -4811,95 +4869,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
48114869 data-resting-controls-separator = "true"
48124870 />
48134871 ) : null }
4814- < ProviderModelPicker
4815- environmentId = { environmentId }
4816- compact = { false }
4817- isComposerOwned
4818- disabled = { providerCatalogPending || isSendBusy }
4819- { ...( routeKind === "draft" && supportsMultipleModels
4820- ? {
4821- ...( multipleModelSelections !== null
4822- ? { selectedModels : multipleModelSelections }
4823- : { } ) ,
4824- onToggleModel : ( instanceId : ProviderInstanceId , model : string ) => {
4825- const current = multipleModelSelections ?? [ selectedModelSelection ] ;
4826- const matchesModel = ( selection : ModelSelection ) => {
4827- if ( selection . instanceId !== instanceId ) return false ;
4828- const entry = providerInstanceEntries . find (
4829- ( entry ) => entry . instanceId === selection . instanceId ,
4830- ) ;
4831- const resolvedModel = resolveModelPickerSelectedModel ( {
4832- driverKind : entry ?. driverKind ,
4833- model : selection . model ,
4834- options : modelOptionsByInstance . get ( selection . instanceId ) ?? [ ] ,
4835- } ) ;
4836- return ( resolvedModel ?. slug ?? selection . model ) === model ;
4837- } ;
4838- const exists = current . some ( matchesModel ) ;
4839- const next = exists
4840- ? current . filter ( ( selection ) => ! matchesModel ( selection ) )
4841- : [ ...current , createModelSelection ( instanceId , model ) ] ;
4842- if ( next . length > 1 ) {
4843- setMultipleModelSelections ( next ) ;
4844- } else {
4845- setMultipleModelSelections ( null ) ;
4846- const remaining = next [ 0 ] ?? selectedModelSelection ;
4847- onProviderModelSelect ( remaining . instanceId , remaining . model , {
4848- focusComposer : false ,
4849- } ) ;
4850- }
4851- } ,
4852- }
4853- : { } ) }
4854- activeInstanceId = {
4855- providerCatalogPending
4856- ? ( activeThreadModelSelection ?. instanceId ?? selectedInstanceId )
4857- : selectedInstanceId
4858- }
4859- model = {
4860- providerCatalogPending
4861- ? ( activeThreadModelSelection ?. model ?? selectedModelForPickerWithCustomFallback )
4862- : selectedModelForPickerWithCustomFallback
4863- }
4864- lockedProvider = { lockedProvider }
4865- lockedContinuationGroupKey = { lockedContinuationGroupKey }
4866- instanceEntries = { providerInstanceEntries }
4867- keybindings = { keybindings }
4868- modelOptionsByInstance = { modelOptionsByInstance }
4869- size = { composerControlsCollapsed ? "xs" : "sm" }
4870- triggerClassName = {
4871- composerControlsCollapsed
4872- ? cn (
4873- "min-w-13 shrink text-xs!" ,
4874- ! showInlineRestingControls &&
4875- "@max-[640px]/composer-surface:[&_[data-chat-provider-model-picker-label]]:w-0 @max-[640px]/composer-surface:[&_[data-chat-provider-model-picker-label]]:flex-none" ,
4876- )
4877- : "-ms-2.5 min-w-13"
4878- }
4879- terminalOpen = { terminalOpen }
4880- open = { isComposerModelPickerOpen }
4881- instanceIndicatorBackground = {
4882- composerControlsCollapsed
4883- ? "color-mix(in srgb, var(--chat-composer-glass-surface) var(--glass-opacity), transparent)"
4884- : "var(--contrast-input)"
4885- }
4886- { ...( composerProviderState . modelPickerIconClassName || composerControlsCollapsed
4887- ? {
4888- activeProviderIconClassName : cn (
4889- composerProviderState . modelPickerIconClassName ,
4890- composerControlsCollapsed &&
4891- "fill-muted-foreground/70! text-muted-foreground/70! [&_path]:fill-muted-foreground/70! [&_rect]:fill-muted-foreground/70! [&_[data-icon-detail]]:fill-transparent! [&[data-provider-package-icon]]:opacity-70 [&[data-provider-package-icon]_path:not([data-icon-detail])]:fill-muted-foreground!" ,
4892- ) ,
4893- }
4894- : { } ) }
4895- onOpenChange = { setIsComposerModelPickerOpen }
4896- getModelDisabledReason = { getModelDisabledReason }
4897- onInstanceModelChange = { ( instanceId , model ) => {
4898- setMultipleModelSelections ( null ) ;
4899- onProviderModelSelect ( instanceId , model ) ;
4900- } }
4901- onOpenProviderSetup = { onOpenProviderSetup }
4902- />
4872+ { composerModelPicker }
49034873
49044874 < >
49054875 { restingBlockDefs . map ( ( def , index ) => {
@@ -6081,6 +6051,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
60816051 onRemoveFile = { removeComposerFileFromDraft }
60826052 />
60836053 ) : null ;
6054+ const composerAttachButton = showComposerAttachAction ? (
6055+ < ComposerAttachButton
6056+ addComposerAttachments = { addComposerAttachments }
6057+ focusComposer = { focusComposer }
6058+ />
6059+ ) : null ;
60846060 return (
60856061 < form
60866062 ref = { composerFormRef }
@@ -6570,43 +6546,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
65706546 }
65716547 className = "flex shrink-0 flex-nowrap items-center justify-end gap-2"
65726548 >
6573- { showComposerAttachAction ? (
6574- < >
6575- < input
6576- ref = { attachmentInputRef }
6577- type = "file"
6578- multiple
6579- className = "hidden"
6580- onChange = { ( event ) => {
6581- const files = Array . from ( event . currentTarget . files ?? [ ] ) ;
6582- event . currentTarget . value = "" ;
6583- // Inserting a chip refocuses the editor after the draft renders;
6584- // focusing synchronously here would report the editor's stale text
6585- // over the prompt that was just written.
6586- void addComposerAttachments ( files ) . then ( ( inserted ) => {
6587- if ( ! inserted ) focusComposer ( ) ;
6588- } ) ;
6589- } }
6590- />
6591- < Tooltip >
6592- < TooltipTrigger
6593- render = {
6594- < Button
6595- type = "button"
6596- variant = "ghost"
6597- size = "icon-sm"
6598- onPointerDown = { ( event ) => event . preventDefault ( ) }
6599- onClick = { ( ) => attachmentInputRef . current ?. click ( ) }
6600- aria-label = "Attach files"
6601- />
6602- }
6603- >
6604- < PaperclipIcon />
6605- </ TooltipTrigger >
6606- < TooltipPopup > Attach files</ TooltipPopup >
6607- </ Tooltip >
6608- </ >
6609- ) : null }
6549+ { composerAttachButton }
66106550 < ComposerFooterPrimaryActions
66116551 compact = { isComposerResting || isComposerPrimaryActionsCompact }
66126552 canOperateThread = { canOperateThread }
0 commit comments