1+ import {
2+ getPromptControlledTraits ,
3+ getTraitSelectChange ,
4+ } from "@t3tools/client-runtime/model-traits" ;
15import { SheetHeader } from "../../components/ui/SheetHeader" ;
26import { Toolbar } from "../../components/ui/Toolbar" ;
37import * as Dialog from "../../components/ui/Dialog" ;
@@ -247,6 +251,8 @@ type ThreadSettingsSessionProps = {
247251 readonly lockedProviderInstanceId ?: ProviderInstanceId ;
248252 readonly providerGroups : ReadonlyArray < ProviderGroup > ;
249253 readonly selectedModel : ModelSelection | null ;
254+ readonly prompt : string ;
255+ readonly onPromptChange : ( prompt : string ) => void ;
250256 readonly reportedModelSelection ?: ModelSelection | null ;
251257 readonly onSelectModel : ( option : ModelOption ) => void ;
252258 readonly restoreSelection ?: ( selection : ModelSelection ) => ModelSelection ;
@@ -311,6 +317,7 @@ type ThreadSettingsSessionValue = {
311317 readonly runtimeModeChoices : ReturnType < typeof runtimeModeChoicesForSupportedModes > ;
312318 readonly onUpdateRuntimeMode : ( mode : RuntimeMode ) => void ;
313319 readonly displayedDescriptors : ReadonlyArray < ProviderOptionDescriptor > ;
320+ readonly promptTraits : ReturnType < typeof getPromptControlledTraits > ;
314321 readonly displayedModelSelection : ModelSelection | null ;
315322 readonly reportedModelSelection : ModelSelection | null ;
316323 readonly providerExpansionOverrides : ReadonlySet < string > ;
@@ -491,6 +498,8 @@ function ThreadSettingsSessionProvider(
491498 ( ) => new Set ( ) ,
492499 ) ;
493500 const [ pendingModel , setPendingModel ] = useState < ModelOption | null > ( null ) ;
501+ const [ pendingPrompt , setPendingPrompt ] = useState < string | null > ( null ) ;
502+ const displayedPrompt = pendingModel ? ( pendingPrompt ?? props . prompt ) : props . prompt ;
494503
495504 const isApplied = ( option : ModelOption ) =>
496505 option . selection . instanceId === props . selectedModel ?. instanceId &&
@@ -506,6 +515,7 @@ function ThreadSettingsSessionProvider(
506515 } )
507516 : [ ]
508517 : props . optionDescriptors ;
518+ const promptTraits = getPromptControlledTraits ( displayedDescriptors , displayedPrompt ) ;
509519 const displayedModel =
510520 pendingModel ??
511521 props . providerGroups . flatMap ( ( group ) => group . models ) . find ( ( option ) => isApplied ( option ) ) ??
@@ -532,12 +542,39 @@ function ThreadSettingsSessionProvider(
532542 }
533543 void Haptics . selectionAsync ( ) ;
534544 props . onSelectModel ( pendingModel ) ;
545+ if ( pendingPrompt !== null && pendingPrompt !== props . prompt ) {
546+ props . onPromptChange ( pendingPrompt ) ;
547+ }
535548 }
536549 return true ;
537550 } ;
538551
539552 const applyOptionChange = ( id : string , value : string | boolean ) => {
540- const next = applyProviderOptionSelection ( displayedDescriptors , { id, value } ) ;
553+ const descriptor = displayedDescriptors . find ( ( entry ) => entry . id === id ) ;
554+ const change =
555+ descriptor ?. type === "select" && typeof value === "string"
556+ ? getTraitSelectChange (
557+ { ...promptTraits , descriptors : displayedDescriptors } ,
558+ descriptor ,
559+ displayedPrompt ,
560+ value ,
561+ )
562+ : null ;
563+ if ( descriptor ?. type === "select" ) {
564+ if ( ! change ) return ;
565+ if ( change . prompt !== displayedPrompt ) {
566+ if ( pendingModel ) {
567+ setPendingPrompt ( change . prompt ) ;
568+ } else {
569+ props . onPromptChange ( change . prompt ) ;
570+ }
571+ }
572+ if ( ! ( "modelOptions" in change ) ) return ;
573+ }
574+ const next =
575+ change && "modelOptions" in change
576+ ? ( change . modelOptions ?? [ ] )
577+ : applyProviderOptionSelection ( displayedDescriptors , { id, value } ) ;
541578 if ( ! next ) {
542579 return ;
543580 }
@@ -564,6 +601,9 @@ function ThreadSettingsSessionProvider(
564601
565602 const pressModel = ( option : ModelOption ) => {
566603 void Haptics . selectionAsync ( ) ;
604+ if ( isApplied ( option ) || option . key !== pendingModel ?. key ) {
605+ setPendingPrompt ( null ) ;
606+ }
567607 setPendingModel ( ( current ) =>
568608 pendingModelAfterPress ( {
569609 current,
@@ -586,6 +626,7 @@ function ThreadSettingsSessionProvider(
586626 runtimeModeChoices,
587627 onUpdateRuntimeMode : props . onUpdateRuntimeMode ,
588628 displayedDescriptors,
629+ promptTraits,
589630 displayedModelSelection : pendingModel ?. selection ?? props . selectedModel ,
590631 reportedModelSelection : pendingModel ? null : ( props . reportedModelSelection ?? null ) ,
591632 favoriteKeys,
@@ -832,11 +873,16 @@ function ThreadSettingsOptionsItem(props: {
832873 >
833874 < DisclosureRow
834875 label = { descriptor . label }
835- value = { getProviderOptionCurrentLabel (
836- descriptor ,
837- session . displayedModelSelection ,
838- session . reportedModelSelection ,
839- ) }
876+ value = {
877+ session . promptTraits . ultrathinkPromptControlled &&
878+ descriptor . id === session . promptTraits . primarySelectDescriptor ?. id
879+ ? "Ultrathink"
880+ : getProviderOptionCurrentLabel (
881+ descriptor ,
882+ session . displayedModelSelection ,
883+ session . reportedModelSelection ,
884+ )
885+ }
840886 onPress = { ( ) => props . onOpenSubmenu ( { kind : "descriptor" , id : descriptor . id } ) }
841887 />
842888 </ Animated . View >
@@ -1076,16 +1122,29 @@ function ThreadSettingsChoiceContent(props: {
10761122 rows : selectableChoices ( activeDescriptor ) . map ( ( choice ) => ( {
10771123 id : choice . id ,
10781124 label : choice . label ,
1079- description : undefined ,
1125+ description : choice . description ,
10801126 selected :
10811127 choice . id ===
1082- getProviderOptionCurrentValue (
1083- activeDescriptor ,
1084- session . displayedModelSelection ,
1085- session . reportedModelSelection ,
1086- ) ,
1128+ ( session . promptTraits . ultrathinkPromptControlled &&
1129+ activeDescriptor . id === session . promptTraits . primarySelectDescriptor ?. id
1130+ ? "ultrathink"
1131+ : getProviderOptionCurrentValue (
1132+ activeDescriptor ,
1133+ session . displayedModelSelection ,
1134+ session . reportedModelSelection ,
1135+ ) ) ,
10871136 onPress : ( ) => {
10881137 void Haptics . selectionAsync ( ) ;
1138+ if (
1139+ session . promptTraits . ultrathinkInBodyText &&
1140+ activeDescriptor . id === session . promptTraits . primarySelectDescriptor ?. id
1141+ ) {
1142+ Dialog . alert (
1143+ "Reasoning controlled by prompt" ,
1144+ 'Your prompt contains "ultrathink" in the text. Remove it to change this option.' ,
1145+ ) ;
1146+ return ;
1147+ }
10891148 session . applyOptionChange ( activeDescriptor . id , choice . id ) ;
10901149 props . onSelected ( ) ;
10911150 } ,
@@ -1482,6 +1541,8 @@ export function NewTaskThreadSettingsRouteScreen() {
14821541 { ...( flow . selectedModel ? { providerInstanceId : flow . selectedModel . instanceId } : { } ) }
14831542 providerGroups = { flow . providerGroups }
14841543 selectedModel = { flow . selectedModel }
1544+ prompt = { flow . prompt }
1545+ onPromptChange = { flow . setPrompt }
14851546 onSelectModel = { ( option ) => flow . setSelectedModelKey ( option . key , option . selection . options ) }
14861547 restoreSelection = { withRememberedModelOptions }
14871548 optionDescriptors = { optionDescriptors }
0 commit comments