@@ -1641,11 +1641,22 @@ type PendingRuntimeRequest = {
16411641interface SnapshotMessageState {
16421642 readonly order : Array < string > ;
16431643 readonly messages : Map < string , OrchestrationV2ConversationMessage > ;
1644+ /** Messages loaded from thought chunks; `messages` stores them as assistant text. */
1645+ readonly reasoningIds : ReadonlySet < OrchestrationV2ConversationMessage [ "id" ] > ;
16441646 loadingRole : "user" | "assistant" | "thought" | null ;
16451647 loadingMessageId : string | null ;
16461648 loadingIndex : number ;
16471649}
16481650
1651+ const emptySnapshotState = ( ) : SnapshotMessageState => ( {
1652+ order : [ ] ,
1653+ messages : new Map ( ) ,
1654+ reasoningIds : new Set ( ) ,
1655+ loadingRole : null ,
1656+ loadingMessageId : null ,
1657+ loadingIndex : 0 ,
1658+ } ) ;
1659+
16491660/** How long a Stop waits for the agent to confirm before the user is offered Force stop. */
16501661const ACP_STOP_CONFIRM_TIMEOUT_MS = 10_000 ;
16511662const TOOL_UPDATE_PERSIST_EVERY = 10 ;
@@ -1962,13 +1973,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
19621973 options . testHooks ?. onNativeResponseLifecycle ?? ( ( ) => Effect . void ) ;
19631974 const nextElicitationOrdinal = yield * Ref . make ( 0 ) ;
19641975 const providerTurns = yield * Ref . make ( new Map < string , OrchestrationV2ProviderTurn > ( ) ) ;
1965- const snapshot = yield * Ref . make < SnapshotMessageState > ( {
1966- order : [ ] ,
1967- messages : new Map ( ) ,
1968- loadingRole : null ,
1969- loadingMessageId : null ,
1970- loadingIndex : 0 ,
1971- } ) ;
1976+ const snapshot = yield * Ref . make ( emptySnapshotState ( ) ) ;
19721977
19731978 const awaitRuntimeTeardown = Effect . fnUntraced ( function * ( ) {
19741979 const state = yield * Ref . get ( runtimeTeardownState ) ;
@@ -4548,6 +4553,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
45484553 return {
45494554 order : current . order . includes ( key ) ? current . order : [ ...current . order , key ] ,
45504555 messages,
4556+ reasoningIds :
4557+ role === "thought"
4558+ ? new Set ( current . reasoningIds ) . add ( messageId )
4559+ : current . reasoningIds ,
45514560 loadingRole : role ,
45524561 loadingMessageId : sourceMessageId ?? ( startsNew ? null : current . loadingMessageId ) ,
45534562 loadingIndex,
@@ -7105,13 +7114,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
71057114 yield * Ref . set ( promptInstructionStates , new Map ( ) ) ;
71067115 yield * Ref . set ( compactionMarkers , new Map ( ) ) ;
71077116 yield * Ref . set ( providerTurns , new Map ( ) ) ;
7108- yield * Ref . set ( snapshot , {
7109- order : [ ] ,
7110- messages : new Map ( ) ,
7111- loadingRole : null ,
7112- loadingMessageId : null ,
7113- loadingIndex : 0 ,
7114- } ) ;
7117+ yield * Ref . set ( snapshot , emptySnapshotState ( ) ) ;
71157118 yield * continuationPermit . withPermit (
71167119 Effect . gen ( function * ( ) {
71177120 yield * Ref . update ( continuationGeneration , ( value ) => value + 1 ) ;
@@ -8049,13 +8052,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
80498052 yield * Ref . set ( activeSessionSetup , null ) ;
80508053 yield * Ref . set ( activeSelection , null ) ;
80518054 yield * Ref . set ( activeInteractionMode , null ) ;
8052- yield * Ref . set ( snapshot , {
8053- order : [ ] ,
8054- messages : new Map ( ) ,
8055- loadingRole : null ,
8056- loadingMessageId : null ,
8057- loadingIndex : 0 ,
8058- } ) ;
8055+ yield * Ref . set ( snapshot , emptySnapshotState ( ) ) ;
80598056 return true ;
80608057 } ) ;
80618058
@@ -8737,13 +8734,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
87378734 threadInput . providerThread . appThreadId ,
87388735 ) . pipe ( Effect . tapError ( ( ) => restorePreviousItemIdentity ) ) ;
87398736 if ( ( yield * Ref . get ( activeSessionId ) ) !== sessionId || restartAfterInterrupt ) {
8740- yield * Ref . set ( snapshot , {
8741- order : [ ] ,
8742- messages : new Map ( ) ,
8743- loadingRole : null ,
8744- loadingMessageId : null ,
8745- loadingIndex : 0 ,
8746- } ) ;
8737+ yield * Ref . set ( snapshot , emptySnapshotState ( ) ) ;
87478738 const activated = yield * activateSession (
87488739 sessionId ,
87498740 threadInput . providerThread . appThreadId ,
@@ -9241,13 +9232,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
92419232 detail : "ACP driver does not support session/load snapshots" ,
92429233 } ) ;
92439234 }
9244- yield * Ref . set ( snapshot , {
9245- order : [ ] ,
9246- messages : new Map ( ) ,
9247- loadingRole : null ,
9248- loadingMessageId : null ,
9249- loadingIndex : 0 ,
9250- } ) ;
9235+ yield * Ref . set ( snapshot , emptySnapshotState ( ) ) ;
92519236 const mcpContext = yield * readMcpContext (
92529237 snapshotInput . providerThread . appThreadId ,
92539238 ) ;
@@ -9279,6 +9264,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
92799264 const message = state . messages . get ( key ) ;
92809265 return message === undefined ? [ ] : [ message ] ;
92819266 } ) ,
9267+ reasoningMessageIds : [ ...state . reasoningIds ] ,
92829268 runtimeRequests : [ ] ,
92839269 providerPayload : { protocol : ACP_PROTOCOL , sessionId } ,
92849270 } ;
0 commit comments