diff --git a/ccw/src/core/a2ui/A2UIWebSocketHandler.ts b/ccw/src/core/a2ui/A2UIWebSocketHandler.ts index b6363e68..08f34bc6 100644 --- a/ccw/src/core/a2ui/A2UIWebSocketHandler.ts +++ b/ccw/src/core/a2ui/A2UIWebSocketHandler.ts @@ -58,6 +58,23 @@ export class A2UIWebSocketHandler { timestamp: number; }>(); + private answerCallback?: (answer: QuestionAnswer) => boolean; + + /** + * Register callback for handling question answers + * @param callback - Function to handle incoming answers + */ + registerAnswerCallback(callback: (answer: QuestionAnswer) => boolean): void { + this.answerCallback = callback; + } + + /** + * Get the registered answer callback + */ + getAnswerCallback(): ((answer: QuestionAnswer) => boolean) | undefined { + return this.answerCallback; + } + /** * Send A2UI surface to all connected clients * @param surfaceUpdate - A2UI surface update to send diff --git a/ccw/src/core/websocket.ts b/ccw/src/core/websocket.ts index 59907e23..88b41ab8 100644 --- a/ccw/src/core/websocket.ts +++ b/ccw/src/core/websocket.ts @@ -1,6 +1,8 @@ import { createHash } from 'crypto'; import type { IncomingMessage } from 'http'; import type { Duplex } from 'stream'; +import { a2uiWebSocketHandler, handleA2UIMessage } from './a2ui/A2UIWebSocketHandler.js'; +import { handleAnswer } from '../tools/ask-question.js'; // WebSocket clients for real-time notifications export const wsClients = new Set(); @@ -174,6 +176,11 @@ export function handleWebSocketUpgrade(req: IncomingMessage, socket: Duplex, _he case 0x1: // Text frame if (payload) { console.log('[WS] Received:', payload); + // Try to handle as A2UI message + const handledAsA2UI = handleA2UIMessage(payload, a2uiWebSocketHandler, handleAnswer); + if (handledAsA2UI) { + console.log('[WS] Handled as A2UI message'); + } } break; case 0x8: // Close frame diff --git a/ccw/src/tools/ask-question.ts b/ccw/src/tools/ask-question.ts index e6a29fe1..b5ed3880 100644 --- a/ccw/src/tools/ask-question.ts +++ b/ccw/src/tools/ask-question.ts @@ -14,6 +14,7 @@ import type { AskQuestionResult, PendingQuestion, } from '../core/a2ui/A2UITypes.js'; +import { a2uiWebSocketHandler } from '../core/a2ui/A2UIWebSocketHandler.js'; // ========== Constants ========== @@ -332,8 +333,9 @@ export async function execute(params: AskQuestionParams): Promise