@yeaft/webchat-agent 0.0.172 → 0.0.173

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.
Files changed (2) hide show
  1. package/crew.js +49 -0
  2. package/package.json +1 -1
package/crew.js CHANGED
@@ -2074,6 +2074,52 @@ function findActiveRole(session) {
2074
2074
  // Control Operations
2075
2075
  // =====================================================================
2076
2076
 
2077
+ /**
2078
+ * 清空单个角色的对话(重置为全新状态)
2079
+ */
2080
+ async function clearSingleRole(session, roleName) {
2081
+ const roleState = session.roleStates.get(roleName);
2082
+
2083
+ // 如果角色正在 streaming,先 abort
2084
+ if (roleState) {
2085
+ if (roleState.abortController) {
2086
+ roleState.abortController.abort();
2087
+ }
2088
+ roleState.query = null;
2089
+ roleState.inputStream = null;
2090
+ roleState.turnActive = false;
2091
+ roleState._compacting = false;
2092
+ roleState._compactSummaryPending = false;
2093
+ roleState._pendingCompactRoutes = null;
2094
+ roleState._pendingDispatch = null;
2095
+ roleState._fromRole = null;
2096
+ roleState.claudeSessionId = null;
2097
+ roleState.consecutiveErrors = 0;
2098
+ roleState.accumulatedText = '';
2099
+ roleState.lastDispatchContent = null;
2100
+ roleState.lastDispatchFrom = null;
2101
+ roleState.lastDispatchTaskId = null;
2102
+ roleState.lastDispatchTaskTitle = null;
2103
+ }
2104
+
2105
+ // 清除持久化的 sessionId
2106
+ await clearRoleSessionId(session.sharedDir, roleName);
2107
+
2108
+ sendCrewMessage({
2109
+ type: 'crew_role_compact',
2110
+ sessionId: session.id,
2111
+ role: roleName,
2112
+ status: 'cleared'
2113
+ });
2114
+
2115
+ sendCrewOutput(session, 'system', 'system', {
2116
+ type: 'assistant',
2117
+ message: { role: 'assistant', content: [{ type: 'text', text: `${roleName} 对话已清空` }] }
2118
+ });
2119
+ sendStatusUpdate(session);
2120
+ console.log(`[Crew] Role ${roleName} cleared`);
2121
+ }
2122
+
2077
2123
  /**
2078
2124
  * 手动压缩指定角色的上下文
2079
2125
  * - 无活跃 query → 重建 query 后发 /compact
@@ -2163,6 +2209,9 @@ export async function handleCrewControl(msg) {
2163
2209
  case 'compact_role':
2164
2210
  if (targetRole) await compactRole(session, targetRole);
2165
2211
  break;
2212
+ case 'clear_role':
2213
+ if (targetRole) await clearSingleRole(session, targetRole);
2214
+ break;
2166
2215
  case 'stop_all':
2167
2216
  await stopAll(session);
2168
2217
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.172",
3
+ "version": "0.0.173",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",