11import { Stack , useLocalSearchParams , useRouter } from "expo-router" ;
22import { useCallback , useMemo , useState } from "react" ;
33import * as Option from "effect/Option" ;
4- import {
5- EnvironmentId ,
6- type ModelSelection ,
7- type ProjectScript ,
8- type ProviderInteractionMode ,
9- type RuntimeMode ,
10- } from "@t3tools/contracts" ;
4+ import { EnvironmentId , type ProjectScript } from "@t3tools/contracts" ;
115import { projectScriptCwd , projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts" ;
126import { Pressable , ScrollView , Text as RNText , View } from "react-native" ;
137import { useWorkspaceState } from "../../state/workspace" ;
@@ -79,18 +73,6 @@ export function ThreadRouteScreen() {
7973 const gitState = useSelectedThreadGitState ( ) ;
8074 const gitActions = useSelectedThreadGitActions ( ) ;
8175 const requests = useSelectedThreadRequests ( ) ;
82- const updateThreadMetadata = useAtomCommand (
83- threadEnvironment . updateMetadata ,
84- "thread metadata update" ,
85- ) ;
86- const setThreadRuntimeMode = useAtomCommand (
87- threadEnvironment . setRuntimeMode ,
88- "thread runtime mode" ,
89- ) ;
90- const setThreadInteractionMode = useAtomCommand (
91- threadEnvironment . setInteractionMode ,
92- "thread interaction mode" ,
93- ) ;
9476 const interruptThreadTurn = useAtomCommand ( threadEnvironment . interruptTurn , "thread interrupt" ) ;
9577 const router = useRouter ( ) ;
9678 const params = useLocalSearchParams < {
@@ -105,6 +87,18 @@ export function ThreadRouteScreen() {
10587 const routeConnectionState =
10688 routeEnvironmentRuntime ?. connectionState ?? ( environmentId ? "available" : connectionState ) ;
10789 const routeConnectionError = routeEnvironmentRuntime ?. connectionError ?? null ;
90+ const selectedThreadWithDraftSettings = useMemo (
91+ ( ) =>
92+ selectedThread
93+ ? {
94+ ...selectedThread ,
95+ modelSelection : composer . modelSelection ?? selectedThread . modelSelection ,
96+ runtimeMode : composer . runtimeMode ?? selectedThread . runtimeMode ,
97+ interactionMode : composer . interactionMode ?? selectedThread . interactionMode ,
98+ }
99+ : null ,
100+ [ composer . interactionMode , composer . modelSelection , composer . runtimeMode , selectedThread ] ,
101+ ) ;
108102
109103 /* ─── Native header theming ──────────────────────────────────────── */
110104 const iconColor = String ( useThemeColor ( "--color-icon" ) ) ;
@@ -157,51 +151,6 @@ export function ThreadRouteScreen() {
157151 const handleOpenConnectionEditor = useCallback ( ( ) => {
158152 void router . push ( "/connections" ) ;
159153 } , [ router ] ) ;
160- const handleUpdateThreadModelSelection = useCallback (
161- ( modelSelection : ModelSelection ) => {
162- if ( ! selectedThread ) {
163- return ;
164- }
165- return updateThreadMetadata ( {
166- environmentId : selectedThread . environmentId ,
167- input : {
168- threadId : selectedThread . id ,
169- modelSelection,
170- } ,
171- } ) ;
172- } ,
173- [ selectedThread , updateThreadMetadata ] ,
174- ) ;
175- const handleUpdateThreadRuntimeMode = useCallback (
176- ( runtimeMode : RuntimeMode ) => {
177- if ( ! selectedThread ) {
178- return ;
179- }
180- return setThreadRuntimeMode ( {
181- environmentId : selectedThread . environmentId ,
182- input : {
183- threadId : selectedThread . id ,
184- runtimeMode,
185- } ,
186- } ) ;
187- } ,
188- [ selectedThread , setThreadRuntimeMode ] ,
189- ) ;
190- const handleUpdateThreadInteractionMode = useCallback (
191- ( interactionMode : ProviderInteractionMode ) => {
192- if ( ! selectedThread ) {
193- return ;
194- }
195- return setThreadInteractionMode ( {
196- environmentId : selectedThread . environmentId ,
197- input : {
198- threadId : selectedThread . id ,
199- interactionMode,
200- } ,
201- } ) ;
202- } ,
203- [ selectedThread , setThreadInteractionMode ] ,
204- ) ;
205154 const handleStopThread = useCallback ( ( ) => {
206155 if (
207156 ! selectedThread ||
@@ -435,7 +384,7 @@ export function ThreadRouteScreen() {
435384
436385 < View className = "flex-1 bg-screen" >
437386 < ThreadDetailScreen
438- selectedThread = { selectedThread }
387+ selectedThread = { selectedThreadWithDraftSettings ?? selectedThread }
439388 contentPresentation = { contentPresentation }
440389 screenTone = { connectionTone ( routeConnectionState ) }
441390 connectionError = { routeConnectionError }
@@ -466,9 +415,9 @@ export function ThreadRouteScreen() {
466415 onStopThread = { handleStopThread }
467416 onSendMessage = { composer . onSendMessage }
468417 onReconnectEnvironment = { handleReconnectEnvironment }
469- onUpdateThreadModelSelection = { handleUpdateThreadModelSelection }
470- onUpdateThreadRuntimeMode = { handleUpdateThreadRuntimeMode }
471- onUpdateThreadInteractionMode = { handleUpdateThreadInteractionMode }
418+ onUpdateThreadModelSelection = { composer . onUpdateModelSelection }
419+ onUpdateThreadRuntimeMode = { composer . onUpdateRuntimeMode }
420+ onUpdateThreadInteractionMode = { composer . onUpdateInteractionMode }
472421 onRespondToApproval = { requests . onRespondToApproval }
473422 onSelectUserInputOption = { requests . onSelectUserInputOption }
474423 onChangeUserInputCustomAnswer = { requests . onChangeUserInputCustomAnswer }
0 commit comments