[codex] add clarify support with response path tests (#972)
* feat: 新增 clarify(澄清/确认)交互支持 * test clarify response bridge path --------- Co-authored-by: GoldenFish123321 <golden_fish@foxmail.com>
This commit is contained in:
@@ -105,6 +105,8 @@ const sessionEventHandlers = new Map<string, {
|
||||
onApprovalRequested?: (event: RunEvent) => void
|
||||
onApprovalResolved?: (event: RunEvent) => void
|
||||
onPeerUserMessage?: (event: RunEvent) => void
|
||||
onClarifyRequested?: (event: RunEvent) => void
|
||||
onClarifyResolved?: (event: RunEvent) => void
|
||||
}>()
|
||||
|
||||
const peerUserMessageHandlers = new Set<(event: RunEvent) => void>()
|
||||
@@ -372,6 +374,26 @@ function globalPeerUserMessageHandler(event: RunEvent): void {
|
||||
}
|
||||
}
|
||||
|
||||
function globalClarifyRequestedHandler(event: RunEvent): void {
|
||||
const sid = event.session_id
|
||||
if (!sid) return
|
||||
|
||||
const handlers = sessionEventHandlers.get(sid)
|
||||
if (handlers?.onClarifyRequested) {
|
||||
handlers.onClarifyRequested(event)
|
||||
}
|
||||
}
|
||||
|
||||
function globalClarifyResolvedHandler(event: RunEvent): void {
|
||||
const sid = event.session_id
|
||||
if (!sid) return
|
||||
|
||||
const handlers = sessionEventHandlers.get(sid)
|
||||
if (handlers?.onClarifyResolved) {
|
||||
handlers.onClarifyResolved(event)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register event handlers for a session
|
||||
* @param sessionId - Session ID
|
||||
@@ -401,6 +423,8 @@ export function registerSessionHandlers(
|
||||
onApprovalRequested?: (event: RunEvent) => void
|
||||
onApprovalResolved?: (event: RunEvent) => void
|
||||
onPeerUserMessage?: (event: RunEvent) => void
|
||||
onClarifyRequested?: (event: RunEvent) => void
|
||||
onClarifyResolved?: (event: RunEvent) => void
|
||||
}
|
||||
): () => void {
|
||||
sessionEventHandlers.set(sessionId, handlers)
|
||||
@@ -426,6 +450,19 @@ export function onPeerUserMessage(handler: (event: RunEvent) => void): () => voi
|
||||
}
|
||||
}
|
||||
|
||||
export function respondClarify(
|
||||
sessionId: string,
|
||||
clarifyId: string,
|
||||
response: string,
|
||||
): void {
|
||||
const socket = connectChatRun()
|
||||
socket.emit('clarify.respond', {
|
||||
session_id: sessionId,
|
||||
clarify_id: clarifyId,
|
||||
response,
|
||||
})
|
||||
}
|
||||
|
||||
export function respondToolApproval(
|
||||
sessionId: string,
|
||||
approvalId: string,
|
||||
@@ -510,6 +547,8 @@ export function connectChatRun(requestedProfile?: string | null): Socket {
|
||||
chatRunSocket.on('approval.requested', globalApprovalRequestedHandler)
|
||||
chatRunSocket.on('approval.resolved', globalApprovalResolvedHandler)
|
||||
chatRunSocket.on('run.peer_user_message', globalPeerUserMessageHandler)
|
||||
chatRunSocket.on('clarify.requested', globalClarifyRequestedHandler)
|
||||
chatRunSocket.on('clarify.resolved', globalClarifyResolvedHandler)
|
||||
|
||||
// Compression events
|
||||
chatRunSocket.on('compression.started', globalCompressionStartedHandler)
|
||||
@@ -708,6 +747,14 @@ export function startRunViaSocket(
|
||||
if (closed) return
|
||||
onEvent(evt)
|
||||
},
|
||||
onClarifyRequested: (evt: RunEvent) => {
|
||||
if (closed) return
|
||||
onEvent(evt)
|
||||
},
|
||||
onClarifyResolved: (evt: RunEvent) => {
|
||||
if (closed) return
|
||||
onEvent(evt)
|
||||
},
|
||||
}
|
||||
|
||||
// Register handlers in the global session map
|
||||
|
||||
Reference in New Issue
Block a user