@yeaft/webchat-agent 0.0.204 → 0.0.206
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/crew.js +58 -0
- package/package.json +1 -1
package/crew.js
CHANGED
|
@@ -2657,6 +2657,9 @@ export async function handleCrewControl(msg) {
|
|
|
2657
2657
|
await interruptRole(session, targetRole, msg.content, 'human');
|
|
2658
2658
|
}
|
|
2659
2659
|
break;
|
|
2660
|
+
case 'abort_role':
|
|
2661
|
+
if (targetRole) await abortRole(session, targetRole);
|
|
2662
|
+
break;
|
|
2660
2663
|
case 'compact_role':
|
|
2661
2664
|
if (targetRole) await compactRole(session, targetRole);
|
|
2662
2665
|
break;
|
|
@@ -2800,6 +2803,61 @@ async function interruptRole(session, roleName, newContent, fromSource = 'human'
|
|
|
2800
2803
|
await dispatchToRole(session, roleName, newContent, fromSource);
|
|
2801
2804
|
}
|
|
2802
2805
|
|
|
2806
|
+
/**
|
|
2807
|
+
* 中止角色当前 turn(不删除角色状态,不注入新内容)
|
|
2808
|
+
* 与 stopRole 区别:stopRole 会 delete roleState,abortRole 只中断当前 query
|
|
2809
|
+
* 与 interruptRole 区别:interruptRole 中断后会 dispatch 新消息,abortRole 不会
|
|
2810
|
+
*/
|
|
2811
|
+
async function abortRole(session, roleName) {
|
|
2812
|
+
const roleState = session.roleStates.get(roleName);
|
|
2813
|
+
if (!roleState) {
|
|
2814
|
+
console.warn(`[Crew] Cannot abort ${roleName}: no roleState`);
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
if (!roleState.turnActive) {
|
|
2819
|
+
console.log(`[Crew] ${roleName} is not active, nothing to abort`);
|
|
2820
|
+
return;
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
console.log(`[Crew] Aborting ${roleName}`);
|
|
2824
|
+
|
|
2825
|
+
// 结束 streaming 状态
|
|
2826
|
+
endRoleStreaming(session, roleName);
|
|
2827
|
+
|
|
2828
|
+
// 保存 sessionId 以便后续继续对话
|
|
2829
|
+
if (roleState.claudeSessionId) {
|
|
2830
|
+
await saveRoleSessionId(session.sharedDir, roleName, roleState.claudeSessionId)
|
|
2831
|
+
.catch(e => console.warn(`[Crew] Failed to save sessionId for ${roleName}:`, e.message));
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
// Abort 当前 query
|
|
2835
|
+
if (roleState.abortController) {
|
|
2836
|
+
roleState.abortController.abort();
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
// 清理 turn 状态,角色变为 idle
|
|
2840
|
+
roleState.query = null;
|
|
2841
|
+
roleState.inputStream = null;
|
|
2842
|
+
roleState.turnActive = false;
|
|
2843
|
+
roleState.accumulatedText = '';
|
|
2844
|
+
|
|
2845
|
+
// 通知前端 turn 已完成(中断方式)
|
|
2846
|
+
sendCrewMessage({
|
|
2847
|
+
type: 'crew_turn_completed',
|
|
2848
|
+
sessionId: session.id,
|
|
2849
|
+
role: roleName,
|
|
2850
|
+
interrupted: true
|
|
2851
|
+
});
|
|
2852
|
+
|
|
2853
|
+
sendStatusUpdate(session);
|
|
2854
|
+
|
|
2855
|
+
sendCrewOutput(session, 'system', 'system', {
|
|
2856
|
+
type: 'assistant',
|
|
2857
|
+
message: { role: 'assistant', content: [{ type: 'text', text: `${roleName} 已中止` }] }
|
|
2858
|
+
});
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2803
2861
|
async function stopRole(session, roleName) {
|
|
2804
2862
|
const roleState = session.roleStates.get(roleName);
|
|
2805
2863
|
if (roleState) {
|