@yeaft/webchat-agent 0.1.317 → 0.1.320
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/conversation.js +22 -4
- package/crew/role-output.js +18 -0
- package/package.json +1 -1
package/conversation.js
CHANGED
|
@@ -840,12 +840,30 @@ export function handleAskUserQuestion(conversationId, input, toolCtx) {
|
|
|
840
840
|
|
|
841
841
|
/**
|
|
842
842
|
* 处理 Web UI 的 AskUserQuestion 回答
|
|
843
|
+
*
|
|
844
|
+
* Fallback: 如果 requestId 精确匹配失败(例如页面刷新后 agent 重启,
|
|
845
|
+
* Claude 进程 resume 后重新发起了 AskUserQuestion,产生了新的 requestId),
|
|
846
|
+
* 则按 conversationId 查找该 conversation 下唯一的 pending question 并 resolve。
|
|
843
847
|
*/
|
|
844
848
|
export function handleAskUserAnswer(msg) {
|
|
845
|
-
|
|
849
|
+
let pending = ctx.pendingUserQuestions.get(msg.requestId);
|
|
850
|
+
let matchedRequestId = msg.requestId;
|
|
851
|
+
|
|
852
|
+
if (!pending && msg.conversationId) {
|
|
853
|
+
// Fallback: find any pending question for this conversation
|
|
854
|
+
for (const [reqId, entry] of ctx.pendingUserQuestions) {
|
|
855
|
+
if (entry.conversationId === msg.conversationId) {
|
|
856
|
+
console.log(`[AskUser] Fallback: requestId ${msg.requestId} not found, using pending ${reqId} for conversation ${msg.conversationId}`);
|
|
857
|
+
pending = entry;
|
|
858
|
+
matchedRequestId = reqId;
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
846
864
|
if (pending) {
|
|
847
|
-
console.log(`[AskUser] Received answer for ${
|
|
848
|
-
ctx.pendingUserQuestions.delete(
|
|
865
|
+
console.log(`[AskUser] Received answer for ${matchedRequestId}`);
|
|
866
|
+
ctx.pendingUserQuestions.delete(matchedRequestId);
|
|
849
867
|
pending.resolve({
|
|
850
868
|
behavior: 'allow',
|
|
851
869
|
updatedInput: {
|
|
@@ -854,7 +872,7 @@ export function handleAskUserAnswer(msg) {
|
|
|
854
872
|
}
|
|
855
873
|
});
|
|
856
874
|
} else {
|
|
857
|
-
console.log(`[AskUser] No pending question for requestId: ${msg.requestId}`);
|
|
875
|
+
console.log(`[AskUser] No pending question for requestId: ${msg.requestId}, conversationId: ${msg.conversationId || 'unknown'}`);
|
|
858
876
|
}
|
|
859
877
|
}
|
|
860
878
|
|
package/crew/role-output.js
CHANGED
|
@@ -186,6 +186,15 @@ export async function processRoleOutput(session, roleName, roleQuery, roleState)
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
// 通知前端进入 routing 状态
|
|
190
|
+
sendCrewMessage({
|
|
191
|
+
type: 'crew_routing',
|
|
192
|
+
sessionId: session.id,
|
|
193
|
+
fromRole: roleName,
|
|
194
|
+
routes: routes.map(r => ({ to: r.to, taskId: r.taskId, taskTitle: r.taskTitle })),
|
|
195
|
+
status: 'routing'
|
|
196
|
+
});
|
|
197
|
+
|
|
189
198
|
const results = await Promise.allSettled(routes.map(route =>
|
|
190
199
|
executeRoute(session, roleName, route)
|
|
191
200
|
));
|
|
@@ -194,6 +203,15 @@ export async function processRoleOutput(session, roleName, roleQuery, roleState)
|
|
|
194
203
|
console.warn(`[Crew] Route execution failed:`, r.reason);
|
|
195
204
|
}
|
|
196
205
|
}
|
|
206
|
+
|
|
207
|
+
// routing 完成,通知前端恢复正常状态
|
|
208
|
+
sendCrewMessage({
|
|
209
|
+
type: 'crew_routing',
|
|
210
|
+
sessionId: session.id,
|
|
211
|
+
fromRole: roleName,
|
|
212
|
+
status: 'done'
|
|
213
|
+
});
|
|
214
|
+
sendStatusUpdate(session);
|
|
197
215
|
} else {
|
|
198
216
|
const { processHumanQueue } = await import('./human-interaction.js');
|
|
199
217
|
await processHumanQueue(session);
|