@@ -78,7 +78,7 @@ import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
7878import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts" ;
7979import { t3OrchestrationSystemPrompt } from "../../provider/T3OrchestrationInstructions.ts" ;
8080import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens" ;
81- import { getModelSelectionStringOptionValue } from "@t3tools/shared/model" ;
81+ import { getModelSelectionStringOptionValue , modelSelectionsEqual } from "@t3tools/shared/model" ;
8282import { causeErrorTag } from "@t3tools/shared/observability" ;
8383
8484import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts" ;
@@ -1385,6 +1385,27 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
13851385 } ) ;
13861386 } ) ;
13871387
1388+ const withReportedModel = (
1389+ providerThread : OrchestrationV2ProviderThread ,
1390+ model : ModelRef | undefined ,
1391+ ) : OrchestrationV2ProviderThread => {
1392+ if ( model === undefined ) return providerThread ;
1393+ const modelSelection : ModelSelection = {
1394+ instanceId,
1395+ model : `${ model . providerID } /${ model . id } ` ,
1396+ options : model . variant === undefined ? [ ] : [ { id : "variant" , value : model . variant } ] ,
1397+ } ;
1398+ if (
1399+ providerThread . nativeMetadata ?. modelSelection !== undefined &&
1400+ modelSelectionsEqual ( providerThread . nativeMetadata . modelSelection , modelSelection )
1401+ )
1402+ return providerThread ;
1403+ return {
1404+ ...providerThread ,
1405+ nativeMetadata : { ...providerThread . nativeMetadata , modelSelection } ,
1406+ } ;
1407+ } ;
1408+
13881409 /**
13891410 * Gives a subagent call its session once both are known: OpenCode names
13901411 * the session on the call's progress, and announces it just before. The
@@ -1463,7 +1484,8 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
14631484 const child =
14641485 previous ?? newThreadState ( childId , providerThread , call . state . directory , subagent ) ;
14651486 child . subagent = subagent ;
1466- child . providerThread = providerThread ;
1487+ child . model = info ?. model ?? child . model ;
1488+ child . providerThread = withReportedModel ( providerThread , child . model ) ;
14671489 child . directory = call . state . directory ;
14681490 child . agent = info ?. agent ?? call . agent ?? child . agent ;
14691491 // OpenCode gives a new session its parent's rules, which are the thread's.
@@ -1472,7 +1494,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
14721494 childOwners . set ( childId , rootOf ( call . state ) ) ;
14731495 call . child = child ;
14741496 yield * emit ( { type : "app_thread.created" , driver, appThread } ) ;
1475- yield * emit ( { type : "provider_thread.updated" , driver, providerThread } ) ;
1497+ yield * emit ( {
1498+ type : "provider_thread.updated" ,
1499+ driver,
1500+ providerThread : child . providerThread ,
1501+ } ) ;
14761502 yield * emitSubagent ( call ) ;
14771503 // A session called again was not made now, so it may hold the rules of
14781504 // a mode the thread has left. OpenCode applies a rules change to the
@@ -2520,6 +2546,18 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
25202546 if ( sessionId === undefined ) return ;
25212547 const state = threads . get ( sessionId ) ;
25222548 if ( state === undefined ) return ;
2549+ if ( event . type === "session.model.selected" || event . type === "session.step.started" ) {
2550+ if ( event . type === "session.model.selected" ) state . model = event . data . model ;
2551+ const providerThread = withReportedModel ( state . providerThread , event . data . model ) ;
2552+ if ( providerThread !== state . providerThread ) {
2553+ state . providerThread = { ...providerThread , updatedAt : yield * DateTime . now } ;
2554+ yield * emit ( {
2555+ type : "provider_thread.updated" ,
2556+ driver,
2557+ providerThread : state . providerThread ,
2558+ } ) ;
2559+ }
2560+ }
25232561 if (
25242562 event . type === "session.inbox.enqueued" &&
25252563 state . subagent !== undefined &&
@@ -2962,6 +3000,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
29623000 } ,
29633001 directory : string ,
29643002 ) => {
3003+ providerThread = withReportedModel ( providerThread , native . model ) ;
29653004 const existing = threads . get ( native . id ) ;
29663005 if ( existing !== undefined ) {
29673006 existing . providerThread = providerThread ;
@@ -3582,7 +3621,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
35823621 directory ,
35833622 ) ;
35843623 state . policy = policy ;
3585- return providerThread ;
3624+ return state . providerThread ;
35863625 } ) . pipe (
35873626 Effect . mapError ( ( cause ) =>
35883627 isProviderAdapterError ( cause )
@@ -3625,7 +3664,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
36253664 directory : AbsolutePath . make ( cwd ) ,
36263665 } ) ;
36273666 }
3628- return providerThread ;
3667+ return state . providerThread ;
36293668 } ) . pipe (
36303669 Effect . mapError ( ( cause ) =>
36313670 isProviderAdapterError ( cause )
@@ -4183,7 +4222,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
41834222 directory : AbsolutePath . make ( cwd ) ,
41844223 } ) ;
41854224 }
4186- return providerThread ;
4225+ return state . providerThread ;
41874226 } ) . pipe (
41884227 exclusive ( forkInput . sourceProviderThread ) ,
41894228 Effect . mapError ( ( cause ) =>
0 commit comments