@@ -35,6 +35,11 @@ export type {
3535
3636export type PiModelSelection = Pick < PiNativeModelInfo , "provider" | "id" > ;
3737
38+ export interface PiDeferredConfig {
39+ model ?: PiModelSelection ;
40+ thinkingLevel ?: PiThinkingLevel ;
41+ }
42+
3843export const PI_SESSION_PROVIDER = Symbol . for ( "posthog.pi.sessionProvider" ) ;
3944export const LOCAL_PI_SESSION_FACTORY = Symbol . for (
4045 "posthog.pi.localSessionFactory" ,
@@ -301,6 +306,7 @@ export class PiSessionController {
301306 text : string ,
302307 isStreaming : boolean ,
303308 messagingMode : PiMessagingMode ,
309+ deferredConfig ?: PiDeferredConfig ,
304310 ) : Promise < PiSubmitResult > {
305311 const message = text . trim ( ) ;
306312 const action = this . getSubmitAction ( message , isStreaming , messagingMode ) ;
@@ -382,6 +388,7 @@ export class PiSessionController {
382388
383389 try {
384390 const session = await this . getWritablePiSession ( taskId ) ;
391+ await this . applyDeferredConfig ( session , deferredConfig ) ;
385392 this . markTurnPending ( taskId ) ;
386393 if ( session . sendUserMessage && messageId ) {
387394 const taskRunId = this . taskRunIds . get ( taskId ) ;
@@ -1088,6 +1095,22 @@ export class PiSessionController {
10881095 } ) ;
10891096 }
10901097
1098+ private async applyDeferredConfig (
1099+ session : PiSession ,
1100+ config : PiDeferredConfig | undefined ,
1101+ ) : Promise < void > {
1102+ if ( ! config ) {
1103+ return ;
1104+ }
1105+
1106+ if ( config . model ) {
1107+ await session . client . setModel ( config . model . provider , config . model . id ) ;
1108+ }
1109+ if ( config . thinkingLevel ) {
1110+ await session . client . setThinkingLevel ( config . thinkingLevel ) ;
1111+ }
1112+ }
1113+
10911114 private async refreshStatus ( taskId : string ) : Promise < void > {
10921115 const session = await this . getPiSession ( taskId ) ;
10931116 const status = await session . client . getState ( ) ;
0 commit comments