@@ -5,7 +5,13 @@ import {
55 squashAtomCommandFailure ,
66 type AtomCommandResult ,
77} from "@t3tools/client-runtime/state/runtime" ;
8- import { MessageId , ThreadId , type ScopedThreadRef } from "@t3tools/contracts" ;
8+ import {
9+ MessageId ,
10+ ThreadId ,
11+ type ModelSelection ,
12+ type RuntimeMode ,
13+ type ScopedThreadRef ,
14+ } from "@t3tools/contracts" ;
915
1016import * as Dialog from "../../components/ui/Dialog" ;
1117import { uuidv4 } from "../../lib/uuid" ;
@@ -17,11 +23,13 @@ import { useOpenLinkedThread } from "./useOpenLinkedThread";
1723
1824/**
1925 * Forks `source` at its latest stable point into a side chat, sends `prompt` there, and opens
20- * it like any linked thread. Resolves false when the side chat did not start.
26+ * it like any linked thread. Resolves false when the side chat did not start. `settings` are
27+ * what the parent's composer would send, which its thread gets only on its next send.
2128 */
2229export function useStartSideChat ( ) {
2330 const forkSideChat = useAtomCommand ( threadEnvironment . forkSideChat , { reportFailure : false } ) ;
2431 const deleteThread = useAtomCommand ( threadEnvironment . delete , { reportFailure : false } ) ;
32+ const setRuntimeMode = useAtomCommand ( threadEnvironment . setRuntimeMode , { reportFailure : false } ) ;
2533 const startTurn = useAtomCommand ( threadEnvironment . startTurn , { reportFailure : false } ) ;
2634 const openLinkedThread = useOpenLinkedThread ( ) ;
2735
@@ -34,7 +42,11 @@ export function useStartSideChat() {
3442 Dialog . alert ( "Side chat not started" , error instanceof Error ? error . message : fallback ) ;
3543 } ;
3644
37- return async ( source : ScopedThreadRef , prompt : string ) : Promise < boolean > => {
45+ return async (
46+ source : ScopedThreadRef ,
47+ prompt : string ,
48+ settings : { readonly runtimeMode : RuntimeMode ; readonly modelSelection : ModelSelection } ,
49+ ) : Promise < boolean > => {
3850 const targetThreadId = ThreadId . make ( uuidv4 ( ) ) ;
3951 const fork = await forkSideChat ( {
4052 environmentId : source . environmentId ,
@@ -70,6 +82,21 @@ export function useStartSideChat() {
7082 discard ( ) ;
7183 return false ;
7284 }
85+ if ( settings . runtimeMode !== sideChat . runtimeMode ) {
86+ const mode = await setRuntimeMode ( {
87+ environmentId : source . environmentId ,
88+ input : {
89+ threadId : targetThreadId ,
90+ runtimeMode : settings . runtimeMode ,
91+ createdAt : new Date ( ) . toISOString ( ) ,
92+ } ,
93+ } ) ;
94+ if ( mode . _tag === "Failure" ) {
95+ alertFailure ( mode , "Could not set the side chat's permission mode." ) ;
96+ discard ( ) ;
97+ return false ;
98+ }
99+ }
73100 const turn = await startTurn ( {
74101 environmentId : source . environmentId ,
75102 input : {
@@ -80,8 +107,9 @@ export function useStartSideChat() {
80107 text : prompt ,
81108 attachments : [ ] ,
82109 } ,
110+ modelSelection : settings . modelSelection ,
83111 titleSeed : deriveThreadTitleSeed ( { text : prompt , attachments : [ ] } ) ,
84- runtimeMode : sideChat . runtimeMode ,
112+ runtimeMode : settings . runtimeMode ,
85113 interactionMode : "default" ,
86114 createdAt : new Date ( ) . toISOString ( ) ,
87115 } ,
0 commit comments