@@ -1981,7 +1981,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
19811981 const imageTurns = new Map <
19821982 string ,
19831983 {
1984- readonly running : Set < string > ;
1984+ readonly running : Map <
1985+ string ,
1986+ {
1987+ readonly revisedPrompt : string | null ;
1988+ readonly transparentBackground : boolean | null ;
1989+ }
1990+ > ;
19851991 readonly saved : Map < string , string > ;
19861992 pending : boolean ;
19871993 answer ?: { readonly id : string ; readonly text : string } ;
@@ -1990,7 +1996,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
19901996 const imageTurn = ( nativeTurnId : string ) => {
19911997 let state = imageTurns . get ( nativeTurnId ) ;
19921998 if ( state === undefined ) {
1993- state = { running : new Set ( ) , saved : new Map ( ) , pending : false } ;
1999+ state = { running : new Map ( ) , saved : new Map ( ) , pending : false } ;
19942000 imageTurns . set ( nativeTurnId , state ) ;
19952001 }
19962002 return state ;
@@ -2075,6 +2081,19 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
20752081 const clearImageWork = Effect . fn ( "CodexAdapterV2.clearImageWork" ) ( function * (
20762082 context : ActiveCodexTurnContext ,
20772083 ) {
2084+ for ( const [ id , input ] of imageTurns . get ( context . nativeTurnId ) ?. running ?? [ ] ) {
2085+ yield * emitImageGenerationItem (
2086+ context ,
2087+ {
2088+ type : "imageGeneration" ,
2089+ id,
2090+ ...input ,
2091+ status : "cancelled" ,
2092+ result : "" ,
2093+ } ,
2094+ true ,
2095+ ) ;
2096+ }
20782097 yield * emitImageWorkState ( context , false ) ;
20792098 imageTurns . delete ( context . nativeTurnId ) ;
20802099 } ) ;
@@ -3926,6 +3945,56 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
39263945 } ,
39273946 ) ;
39283947
3948+ const emitImageGenerationItem = Effect . fn ( "CodexAdapterV2.emitImageGenerationItem" ) (
3949+ function * (
3950+ context : ActiveCodexTurnContext ,
3951+ item : Extract <
3952+ CodexSchema . V2ItemCompletedNotification__ThreadItem ,
3953+ { type : "imageGeneration" }
3954+ > ,
3955+ completed : boolean ,
3956+ ) {
3957+ const cancelled = completed && item . status === "cancelled" ;
3958+ const failed = item . status === "failed" || item . failure != null ;
3959+ const artifacts = yield * buildDynamicToolArtifacts ( context , {
3960+ type : "dynamicToolCall" ,
3961+ id : item . id ,
3962+ namespace : "image_gen" ,
3963+ tool : "imagegen" ,
3964+ status : completed ? ( failed ? "failed" : "completed" ) : "inProgress" ,
3965+ arguments : {
3966+ ...( item . revisedPrompt == null ? { } : { prompt : item . revisedPrompt } ) ,
3967+ ...( item . transparentBackground == null
3968+ ? { }
3969+ : { transparent_background : item . transparentBackground } ) ,
3970+ } ,
3971+ } ) ;
3972+ yield * emitProviderEvent ( {
3973+ type : "node.updated" ,
3974+ driver : CODEX_PROVIDER ,
3975+ node : { ...artifacts . node , ...( cancelled ? { status : "cancelled" } : { } ) } ,
3976+ } ) ;
3977+ yield * emitProviderEvent ( {
3978+ type : "turn_item.updated" ,
3979+ driver : CODEX_PROVIDER ,
3980+ turnItem : {
3981+ ...artifacts . turnItem ,
3982+ title : "Generate image" ,
3983+ ...( cancelled ? { status : "cancelled" } : { } ) ,
3984+ ...( completed
3985+ ? {
3986+ output : {
3987+ status : item . status ,
3988+ ...( item . savedPath == null ? { } : { savedPath : item . savedPath } ) ,
3989+ ...( item . failure == null ? { } : { failure : item . failure } ) ,
3990+ } ,
3991+ }
3992+ : { } ) ,
3993+ } ,
3994+ } ) ;
3995+ } ,
3996+ ) ;
3997+
39293998 /**
39303999 * The item stays running until then, which keeps the run's event
39314000 * ingestion open past turn/completed; it runs off the notification
@@ -4980,7 +5049,11 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
49805049
49815050 if ( payload . item . type === "imageGeneration" ) {
49825051 if ( ! ( yield * Ref . get ( interruptingNativeTurns ) ) . has ( payload . turnId ) ) {
4983- imageTurn ( payload . turnId ) . running . add ( payload . item . id ) ;
5052+ imageTurn ( payload . turnId ) . running . set ( payload . item . id , {
5053+ revisedPrompt : payload . item . revisedPrompt ?? null ,
5054+ transparentBackground : payload . item . transparentBackground ?? null ,
5055+ } ) ;
5056+ yield * emitImageGenerationItem ( context , payload . item , false ) ;
49845057 yield * emitImageWorkState ( context , true ) ;
49855058 }
49865059 return ;
@@ -5266,6 +5339,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
52665339
52675340 if ( payload . item . type === "imageGeneration" ) {
52685341 if ( ( yield * Ref . get ( interruptingNativeTurns ) ) . has ( payload . turnId ) ) return ;
5342+ yield * emitImageGenerationItem ( context , payload . item , true ) ;
52695343 const { id, savedPath, status, failure } = payload . item ;
52705344 const state = imageTurn ( payload . turnId ) ;
52715345 if ( savedPath ?. trim ( ) && status === "completed" && failure == null ) {
@@ -6182,7 +6256,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
61826256 state . saved . clear ( ) ;
61836257 return ;
61846258 }
6185- const message = { id : finalAnswer ?. id ?? firstImageItemId , text } ;
6259+ const message = {
6260+ id : finalAnswer ?. id ?? `generated-image-message:${ firstImageItemId } ` ,
6261+ text,
6262+ } ;
61866263 state . answer = message ;
61876264 const artifacts = yield * buildAgentMessageArtifacts ( context , message , true ) ;
61886265 yield * emitProviderEvent ( {
0 commit comments