@yeaft/webchat-agent 0.0.172 → 0.0.174
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 -4
- package/index.js +1 -1
- package/package.json +1 -1
package/crew.js
CHANGED
|
@@ -313,7 +313,8 @@ async function saveSessionMeta(session) {
|
|
|
313
313
|
status: session.status,
|
|
314
314
|
roles: Array.from(session.roles.values()).map(r => ({
|
|
315
315
|
name: r.name, displayName: r.displayName, icon: r.icon,
|
|
316
|
-
description: r.description, isDecisionMaker: r.isDecisionMaker || false
|
|
316
|
+
description: r.description, isDecisionMaker: r.isDecisionMaker || false,
|
|
317
|
+
groupIndex: r.groupIndex, roleType: r.roleType, model: r.model
|
|
317
318
|
})),
|
|
318
319
|
decisionMaker: session.decisionMaker,
|
|
319
320
|
maxRounds: session.maxRounds,
|
|
@@ -326,7 +327,8 @@ async function saveSessionMeta(session) {
|
|
|
326
327
|
costUsd: session.costUsd,
|
|
327
328
|
totalInputTokens: session.totalInputTokens,
|
|
328
329
|
totalOutputTokens: session.totalOutputTokens,
|
|
329
|
-
features: Array.from(session.features.values())
|
|
330
|
+
features: Array.from(session.features.values()),
|
|
331
|
+
groupNames: session.groupNames || {}
|
|
330
332
|
};
|
|
331
333
|
await fs.writeFile(join(session.sharedDir, 'session.json'), JSON.stringify(meta, null, 2));
|
|
332
334
|
// 保存 UI 消息历史(用于恢复时重放)
|
|
@@ -494,7 +496,8 @@ export async function resumeCrewSession(msg) {
|
|
|
494
496
|
sharedKnowledge: session.sharedKnowledge || '',
|
|
495
497
|
roles: roles.map(r => ({
|
|
496
498
|
name: r.name, displayName: r.displayName, icon: r.icon,
|
|
497
|
-
description: r.description, isDecisionMaker: r.isDecisionMaker || false
|
|
499
|
+
description: r.description, isDecisionMaker: r.isDecisionMaker || false,
|
|
500
|
+
groupIndex: r.groupIndex, roleType: r.roleType, model: r.model
|
|
498
501
|
})),
|
|
499
502
|
decisionMaker: session.decisionMaker,
|
|
500
503
|
maxRounds: session.maxRounds,
|
|
@@ -546,6 +549,7 @@ export async function resumeCrewSession(msg) {
|
|
|
546
549
|
waitingHumanContext: null,
|
|
547
550
|
pendingRoutes: [],
|
|
548
551
|
features: new Map((meta.features || []).map(f => [f.taskId, f])),
|
|
552
|
+
groupNames: meta.groupNames || {},
|
|
549
553
|
userId: userId || meta.userId,
|
|
550
554
|
username: username || meta.username,
|
|
551
555
|
agentId: meta.agentId || ctx.CONFIG?.agentName || null,
|
|
@@ -567,7 +571,8 @@ export async function resumeCrewSession(msg) {
|
|
|
567
571
|
sharedKnowledge: session.sharedKnowledge || '',
|
|
568
572
|
roles: roles.map(r => ({
|
|
569
573
|
name: r.name, displayName: r.displayName, icon: r.icon,
|
|
570
|
-
description: r.description, isDecisionMaker: r.isDecisionMaker || false
|
|
574
|
+
description: r.description, isDecisionMaker: r.isDecisionMaker || false,
|
|
575
|
+
groupIndex: r.groupIndex, roleType: r.roleType, model: r.model
|
|
571
576
|
})),
|
|
572
577
|
decisionMaker,
|
|
573
578
|
maxRounds: session.maxRounds,
|
|
@@ -2074,6 +2079,52 @@ function findActiveRole(session) {
|
|
|
2074
2079
|
// Control Operations
|
|
2075
2080
|
// =====================================================================
|
|
2076
2081
|
|
|
2082
|
+
/**
|
|
2083
|
+
* 清空单个角色的对话(重置为全新状态)
|
|
2084
|
+
*/
|
|
2085
|
+
async function clearSingleRole(session, roleName) {
|
|
2086
|
+
const roleState = session.roleStates.get(roleName);
|
|
2087
|
+
|
|
2088
|
+
// 如果角色正在 streaming,先 abort
|
|
2089
|
+
if (roleState) {
|
|
2090
|
+
if (roleState.abortController) {
|
|
2091
|
+
roleState.abortController.abort();
|
|
2092
|
+
}
|
|
2093
|
+
roleState.query = null;
|
|
2094
|
+
roleState.inputStream = null;
|
|
2095
|
+
roleState.turnActive = false;
|
|
2096
|
+
roleState._compacting = false;
|
|
2097
|
+
roleState._compactSummaryPending = false;
|
|
2098
|
+
roleState._pendingCompactRoutes = null;
|
|
2099
|
+
roleState._pendingDispatch = null;
|
|
2100
|
+
roleState._fromRole = null;
|
|
2101
|
+
roleState.claudeSessionId = null;
|
|
2102
|
+
roleState.consecutiveErrors = 0;
|
|
2103
|
+
roleState.accumulatedText = '';
|
|
2104
|
+
roleState.lastDispatchContent = null;
|
|
2105
|
+
roleState.lastDispatchFrom = null;
|
|
2106
|
+
roleState.lastDispatchTaskId = null;
|
|
2107
|
+
roleState.lastDispatchTaskTitle = null;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
// 清除持久化的 sessionId
|
|
2111
|
+
await clearRoleSessionId(session.sharedDir, roleName);
|
|
2112
|
+
|
|
2113
|
+
sendCrewMessage({
|
|
2114
|
+
type: 'crew_role_compact',
|
|
2115
|
+
sessionId: session.id,
|
|
2116
|
+
role: roleName,
|
|
2117
|
+
status: 'cleared'
|
|
2118
|
+
});
|
|
2119
|
+
|
|
2120
|
+
sendCrewOutput(session, 'system', 'system', {
|
|
2121
|
+
type: 'assistant',
|
|
2122
|
+
message: { role: 'assistant', content: [{ type: 'text', text: `${roleName} 对话已清空` }] }
|
|
2123
|
+
});
|
|
2124
|
+
sendStatusUpdate(session);
|
|
2125
|
+
console.log(`[Crew] Role ${roleName} cleared`);
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2077
2128
|
/**
|
|
2078
2129
|
* 手动压缩指定角色的上下文
|
|
2079
2130
|
* - 无活跃 query → 重建 query 后发 /compact
|
|
@@ -2163,6 +2214,9 @@ export async function handleCrewControl(msg) {
|
|
|
2163
2214
|
case 'compact_role':
|
|
2164
2215
|
if (targetRole) await compactRole(session, targetRole);
|
|
2165
2216
|
break;
|
|
2217
|
+
case 'clear_role':
|
|
2218
|
+
if (targetRole) await clearSingleRole(session, targetRole);
|
|
2219
|
+
break;
|
|
2166
2220
|
case 'stop_all':
|
|
2167
2221
|
await stopAll(session);
|
|
2168
2222
|
break;
|
package/index.js
CHANGED
|
@@ -59,7 +59,7 @@ const fileConfig = loadConfig();
|
|
|
59
59
|
const CONFIG = {
|
|
60
60
|
serverUrl: process.env.SERVER_URL || fileConfig.serverUrl,
|
|
61
61
|
agentName: process.env.AGENT_NAME || fileConfig.agentName,
|
|
62
|
-
workDir: process.env.WORK_DIR || fileConfig.workDir,
|
|
62
|
+
workDir: process.env.WORK_DIR || fileConfig.workDir || process.cwd(),
|
|
63
63
|
reconnectInterval: fileConfig.reconnectInterval,
|
|
64
64
|
agentSecret: process.env.AGENT_SECRET || fileConfig.agentSecret,
|
|
65
65
|
// MCP 白名单:只允许这些 MCP 服务器的工具,其余自动禁用
|