1- import type { ServerNotification } from "./app-server" ;
1+ import type {
2+ FuzzyFileSearchSessionCompletedNotification ,
3+ FuzzyFileSearchSessionUpdatedNotification ,
4+ ServerNotification
5+ } from "./app-server" ;
26import type { SessionState } from "./CodexAcpServer" ;
37import * as acp from "@agentclientprotocol/sdk" ;
48import { type PlanEntry , RequestError } from "@agentclientprotocol/sdk" ;
@@ -12,14 +16,19 @@ import type {
1216 ErrorNotification ,
1317 ItemCompletedNotification ,
1418 ItemStartedNotification , ThreadItem ,
19+ ModelReroutedNotification ,
1520 ThreadTokenUsageUpdatedNotification ,
1621 TurnPlanUpdatedNotification
1722} from "./app-server/v2" ;
1823import { toTokenCount } from "./TokenCount" ;
1924import {
2025 createCommandExecutionUpdate ,
26+ createDynamicToolCallUpdate ,
2127 createFileChangeUpdate ,
28+ createFuzzyFileSearchComplete ,
29+ createFuzzyFileSearchStartOrUpdate ,
2230 createMcpToolCallUpdate ,
31+ fuzzyFileSearchToolCallId ,
2332} from "./CodexToolCallMapper" ;
2433import { stripShellPrefix } from "./CommandUtils" ;
2534
@@ -30,6 +39,7 @@ export class CodexEventHandler {
3039 private readonly connection : acp . AgentSideConnection ;
3140 private readonly sessionState : SessionState ;
3241 private failure : RequestError | null = null ;
42+ private readonly activeFuzzyFileSearchSessions = new Set < string > ( ) ;
3343
3444 constructor ( connection : acp . AgentSideConnection , sessionState : SessionState ) {
3545 this . connection = connection ;
@@ -102,6 +112,16 @@ export class CodexEventHandler {
102112 }
103113 } ;
104114 case "windows/worldWritableWarning" :
115+ case "thread/status/changed" :
116+ case "thread/archived" :
117+ case "thread/unarchived" :
118+ case "thread/closed" :
119+ case "thread/realtime/started" :
120+ case "thread/realtime/itemAdded" :
121+ case "thread/realtime/outputAudio/delta" :
122+ case "thread/realtime/error" :
123+ case "thread/realtime/closed" :
124+ case "windowsSandbox/setupCompleted" :
105125 case "account/login/completed" :
106126 case "authStatusChange" :
107127 case "loginChatGptComplete" :
@@ -114,6 +134,12 @@ export class CodexEventHandler {
114134 case "item/plan/delta" :
115135 case "app/list/updated" :
116136 return null ;
137+ case "model/rerouted" :
138+ return this . createModelReroutedEvent ( notification . params ) ;
139+ case "fuzzyFileSearch/sessionUpdated" :
140+ return this . handleFuzzyFileSearchSessionUpdated ( notification . params ) ;
141+ case "fuzzyFileSearch/sessionCompleted" :
142+ return this . handleFuzzyFileSearchSessionCompleted ( notification . params ) ;
117143 }
118144 }
119145
@@ -138,6 +164,16 @@ export class CodexEventHandler {
138164 }
139165 }
140166
167+ private createModelReroutedEvent ( event : ModelReroutedNotification ) : UpdateSessionEvent {
168+ return {
169+ sessionUpdate : "agent_thought_chunk" ,
170+ content : {
171+ type : "text" ,
172+ text : `Model rerouted from ${ event . fromModel } to ${ event . toModel } (${ event . reason } ).\n\n`
173+ }
174+ } ;
175+ }
176+
141177 private async createItemEvent ( event : ItemStartedNotification ) : Promise < UpdateSessionEvent | null > {
142178 switch ( event . item . type ) {
143179 case "fileChange" :
@@ -146,6 +182,8 @@ export class CodexEventHandler {
146182 return await createCommandExecutionUpdate ( event . item ) ;
147183 case "mcpToolCall" :
148184 return await createMcpToolCallUpdate ( event . item ) ;
185+ case "dynamicToolCall" :
186+ return await createDynamicToolCallUpdate ( event . item ) ;
149187 case "collabAgentToolCall" :
150188 case "userMessage" :
151189 case "agentMessage" :
@@ -171,6 +209,12 @@ export class CodexEventHandler {
171209 }
172210 case "commandExecution" :
173211 return this . completeCommandExecutionEvent ( event . item ) ;
212+ case "dynamicToolCall" :
213+ return {
214+ sessionUpdate : "tool_call_update" ,
215+ toolCallId : event . item . id ,
216+ status : event . item . status === "completed" ? "completed" : "failed"
217+ }
174218 case "reasoning" :
175219 const summary = event . item . summary [ 0 ] ;
176220 if ( ! summary ) return null ;
@@ -278,10 +322,28 @@ export class CodexEventHandler {
278322 if ( ! this . sessionState . rateLimits ) {
279323 this . sessionState . rateLimits = new Map ( ) ;
280324 }
281- this . sessionState . rateLimits . set ( params . limitId , {
282- limitId : params . limitId ,
283- limitName : params . limitName ,
325+ const limitId = params . rateLimits . limitId ?? params . rateLimits . limitName ?? "unknown" ;
326+ this . sessionState . rateLimits . set ( limitId , {
327+ limitId : limitId ,
328+ limitName : params . rateLimits . limitName ?? limitId ,
284329 snapshot : params . rateLimits ,
285330 } ) ;
286331 }
332+
333+ private handleFuzzyFileSearchSessionUpdated (
334+ params : FuzzyFileSearchSessionUpdatedNotification
335+ ) : UpdateSessionEvent {
336+ const toolCallId = fuzzyFileSearchToolCallId ( params . sessionId ) ;
337+ const started = ! this . activeFuzzyFileSearchSessions . has ( toolCallId ) ;
338+ this . activeFuzzyFileSearchSessions . add ( toolCallId ) ;
339+ return createFuzzyFileSearchStartOrUpdate ( params , started ) ;
340+ }
341+
342+ private handleFuzzyFileSearchSessionCompleted (
343+ params : FuzzyFileSearchSessionCompletedNotification
344+ ) : UpdateSessionEvent {
345+ const toolCallId = fuzzyFileSearchToolCallId ( params . sessionId ) ;
346+ this . activeFuzzyFileSearchSessions . delete ( toolCallId ) ;
347+ return createFuzzyFileSearchComplete ( params ) ;
348+ }
287349}
0 commit comments