feat(core): 实现 ask_user_question 工具的用户输入等待机制
- 创建 UserInputWaiter 管理用户输入等待状态 - 修改 agent-tool-executor 在 requiresUserInput 时等待用户回答 - 添加 onWaitingForInput 回调通知前端显示问题 - Server 端处理 waiting_for_input 广播和 user_input_response 消息 - 前端处理问题显示和用户回答提交 - 修复问题选项在流式输出时被禁用的问题
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
import type { WSContext } from 'hono/ws';
|
||||
import { getSessionManager } from './session/manager.js';
|
||||
import { processMessage, cancelProcessing, getOrCreateAgent } from './agent/index.js';
|
||||
import { processMessage, cancelProcessing, getOrCreateAgent, submitUserInput } from './agent/index.js';
|
||||
import { handlePermissionResponse, setSessionAutoApprove } from './permission/handler.js';
|
||||
import type { ClientMessage, ServerMessage } from './types.js';
|
||||
|
||||
@@ -201,6 +201,33 @@ export async function handleWebSocketMessage(
|
||||
break;
|
||||
}
|
||||
|
||||
case 'user_input_response': {
|
||||
// 处理用户输入响应(用于 ask_user_question 等工具)
|
||||
const toolCallId = message.payload?.toolCallId;
|
||||
const answer = message.payload?.answer;
|
||||
|
||||
if (toolCallId && answer !== undefined) {
|
||||
const handled = submitUserInput(toolCallId, answer);
|
||||
if (!handled) {
|
||||
console.warn(`[WS] User input response for unknown tool call: ${toolCallId}`);
|
||||
broadcastToSession(sessionId, {
|
||||
type: 'error',
|
||||
sessionId,
|
||||
payload: { message: `No pending input request for tool call: ${toolCallId}` },
|
||||
});
|
||||
} else {
|
||||
console.log(`[WS] User input submitted for tool call: ${toolCallId}`);
|
||||
}
|
||||
} else {
|
||||
broadcastToSession(sessionId, {
|
||||
type: 'error',
|
||||
sessionId,
|
||||
payload: { message: 'Missing toolCallId or answer in user_input_response' },
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user