mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-05 01:50:27 +08:00
feat(websocket): integrate A2UI message handling and answer callback registration
This commit is contained in:
@@ -58,6 +58,23 @@ export class A2UIWebSocketHandler {
|
|||||||
timestamp: number;
|
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
|
* Send A2UI surface to all connected clients
|
||||||
* @param surfaceUpdate - A2UI surface update to send
|
* @param surfaceUpdate - A2UI surface update to send
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import type { IncomingMessage } from 'http';
|
import type { IncomingMessage } from 'http';
|
||||||
import type { Duplex } from 'stream';
|
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
|
// WebSocket clients for real-time notifications
|
||||||
export const wsClients = new Set<Duplex>();
|
export const wsClients = new Set<Duplex>();
|
||||||
@@ -174,6 +176,11 @@ export function handleWebSocketUpgrade(req: IncomingMessage, socket: Duplex, _he
|
|||||||
case 0x1: // Text frame
|
case 0x1: // Text frame
|
||||||
if (payload) {
|
if (payload) {
|
||||||
console.log('[WS] Received:', 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;
|
break;
|
||||||
case 0x8: // Close frame
|
case 0x8: // Close frame
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import type {
|
|||||||
AskQuestionResult,
|
AskQuestionResult,
|
||||||
PendingQuestion,
|
PendingQuestion,
|
||||||
} from '../core/a2ui/A2UITypes.js';
|
} from '../core/a2ui/A2UITypes.js';
|
||||||
|
import { a2uiWebSocketHandler } from '../core/a2ui/A2UIWebSocketHandler.js';
|
||||||
|
|
||||||
// ========== Constants ==========
|
// ========== Constants ==========
|
||||||
|
|
||||||
@@ -332,8 +333,9 @@ export async function execute(params: AskQuestionParams): Promise<ToolResult<Ask
|
|||||||
}, params.timeout || DEFAULT_TIMEOUT_MS);
|
}, params.timeout || DEFAULT_TIMEOUT_MS);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Send A2UI surface via WebSocket
|
// Send A2UI surface via WebSocket to frontend
|
||||||
// This will be handled by A2UIWebSocketHandler
|
const a2uiSurface = createA2UISurface(question, surfaceId);
|
||||||
|
a2uiWebSocketHandler.sendSurface(a2uiSurface.surfaceUpdate);
|
||||||
|
|
||||||
// Wait for answer
|
// Wait for answer
|
||||||
const result = await resultPromise;
|
const result = await resultPromise;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import * as readFileMod from './read-file.js';
|
|||||||
import * as coreMemoryMod from './core-memory.js';
|
import * as coreMemoryMod from './core-memory.js';
|
||||||
import * as contextCacheMod from './context-cache.js';
|
import * as contextCacheMod from './context-cache.js';
|
||||||
import * as skillContextLoaderMod from './skill-context-loader.js';
|
import * as skillContextLoaderMod from './skill-context-loader.js';
|
||||||
|
import * as askQuestionMod from './ask-question.js';
|
||||||
import type { ProgressInfo } from './codex-lens.js';
|
import type { ProgressInfo } from './codex-lens.js';
|
||||||
|
|
||||||
// Import legacy JS tools
|
// Import legacy JS tools
|
||||||
@@ -366,6 +367,7 @@ registerTool(toLegacyTool(readFileMod));
|
|||||||
registerTool(toLegacyTool(coreMemoryMod));
|
registerTool(toLegacyTool(coreMemoryMod));
|
||||||
registerTool(toLegacyTool(contextCacheMod));
|
registerTool(toLegacyTool(contextCacheMod));
|
||||||
registerTool(toLegacyTool(skillContextLoaderMod));
|
registerTool(toLegacyTool(skillContextLoaderMod));
|
||||||
|
registerTool(toLegacyTool(askQuestionMod));
|
||||||
|
|
||||||
// Register legacy JS tools
|
// Register legacy JS tools
|
||||||
registerTool(uiGeneratePreviewTool);
|
registerTool(uiGeneratePreviewTool);
|
||||||
|
|||||||
Reference in New Issue
Block a user