myagent-ai 1.32.2 → 1.32.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myagent-ai",
3
- "version": "1.32.2",
3
+ "version": "1.32.3",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
@@ -2136,10 +2136,26 @@ async function loadAllAgentSessions() {
2136
2136
  // 快速对话: 选中 agent + 切换执行模式 + 新建会话
2137
2137
  function quickChatAgent(agentPath) {
2138
2138
  // 选中 agent
2139
+ var _qPrevAgent = state.activeAgent;
2139
2140
  state.activeAgent = agentPath;
2140
2141
  StatePersistence.save('activeAgent', agentPath);
2141
2142
  state.activeSessionId = null;
2142
2143
  state.messages = [];
2144
+ // [fix] 切换到不同 agent 时,清除旧 agent 的待恢复会话 ID
2145
+ if (_qPrevAgent !== agentPath) {
2146
+ state._pendingSessionRestore = null;
2147
+ }
2148
+ // [fix] 切换到不同 agent 时,清除 URL 中旧 agent 的 session 参数
2149
+ if (_qPrevAgent !== agentPath) {
2150
+ try {
2151
+ var _qfixUrl = new URL(window.location.href);
2152
+ _qfixUrl.searchParams.delete('s');
2153
+ _qfixUrl.searchParams.delete('session');
2154
+ var _qAObj = findAgentByPath(agentPath);
2155
+ if (_qAObj && _qAObj.aid) _qfixUrl.searchParams.set('aid', _qAObj.aid);
2156
+ window.history.replaceState({}, '', _qfixUrl.toString());
2157
+ } catch(_) {}
2158
+ }
2143
2159
  // 展开所有父节点
2144
2160
  var parts = agentPath.split('/');
2145
2161
  var cumPath = '';
@@ -2188,10 +2204,29 @@ async function selectAgent(agentPath) {
2188
2204
  // 移动端:立即关闭右侧栏,不要等异步操作完成
2189
2205
  if (isMobile()) closeMobileAgentPanel();
2190
2206
  // Always reload sessions even if clicking the same agent
2207
+ var _prevAgent = state.activeAgent;
2191
2208
  state.activeAgent = agentPath;
2192
2209
  StatePersistence.save('activeAgent', agentPath);
2193
2210
  state.activeSessionId = null;
2194
2211
  state.messages = [];
2212
+ // [fix] 切换到不同 agent 时,清除旧 agent 的待恢复会话 ID,防止 loadSessions 选中旧 agent 的会话
2213
+ // 注意:仅在 agent 确实发生变化时才清除,避免影响 initChat 中同 agent 的会话恢复逻辑
2214
+ if (_prevAgent !== agentPath) {
2215
+ state._pendingSessionRestore = null;
2216
+ }
2217
+ // [fix] 切换到不同 agent 时,清除 URL 中旧 agent 的 session 参数,防止 loadSessions 从 URL 恢复旧会话
2218
+ if (_prevAgent !== agentPath) {
2219
+ try {
2220
+ var _fixUrl = new URL(window.location.href);
2221
+ _fixUrl.searchParams.delete('s');
2222
+ _fixUrl.searchParams.delete('session');
2223
+ var _selAObj = findAgentByPath(agentPath);
2224
+ if (_selAObj && _selAObj.aid) {
2225
+ _fixUrl.searchParams.set('aid', _selAObj.aid);
2226
+ }
2227
+ window.history.replaceState({}, '', _fixUrl.toString());
2228
+ } catch(_) {}
2229
+ }
2195
2230
  // 递增序号,使任何进行中的 selectSession 请求失效
2196
2231
  state._sessionLoadSeq++;
2197
2232
  var parts = agentPath.split('/');
@@ -2220,16 +2255,12 @@ async function selectAgent(agentPath) {
2220
2255
  await loadSessions();
2221
2256
 
2222
2257
  // loadSessions 内部会 auto-select 最新 session;
2223
- // 如果没有 session,则保持 "新对话" 空窗状态
2258
+ // 如果没有 session,则进入"新对话"状态
2224
2259
  // [v1.18.9] 如果 loadSessions 已成功选中了 session,不要覆盖其标题
2225
2260
  if (!state.activeSessionId || state.activeSessionId === '__new__') {
2226
- state._selectedSessionLabel = null;
2227
- var selAgent = findAgentByPath(agentPath);
2228
- var agentLabel = selAgent ? (selAgent.avatar_emoji + ' ' + selAgent.name) : agentPath;
2229
- document.getElementById('headerTitle').textContent = '新对话';
2230
- var details = await loadAgentDetails(agentPath);
2231
- updateWelcomeCard(agentPath, details);
2232
- renderMessages();
2261
+ // [fix] 对于没有历史会话的 agent,直接进入新对话状态
2262
+ // 确保 activeSessionId 被设为 '__new__',左侧栏同步显示空列表
2263
+ newChat();
2233
2264
  }
2234
2265
  // 如果 loadSessions 已经 auto-selected 了 session,UI 已由 selectSession 设置好,不再覆盖
2235
2266
 
@@ -2615,6 +2646,7 @@ async function loadSessions() {
2615
2646
 
2616
2647
  // Auto-select most recent session if none selected
2617
2648
  // 优先级: URL session 参数 > localStorage 持久化的 session > 最新 session
2649
+ // [fix] 所有候选 session ID 必须属于当前 agent 的会话列表,防止错乱到其它 agent 的历史对话
2618
2650
  const urlParams = new URLSearchParams(window.location.search);
2619
2651
  const urlSession = UrlCodec.decode(urlParams.get('s') || '') || UrlCodec.decode(urlParams.get('session') || '');
2620
2652
  var targetSessionId = null;
@@ -2656,16 +2688,10 @@ async function loadSessions() {
2656
2688
  // 默认选中最新 session
2657
2689
  targetSessionId = state.sessions[0].id;
2658
2690
  }
2659
- // [v1.24.1] 强制恢复:如果 URL localStorage 有 session ID,但不在 session 列表中
2660
- // (可能因为 sess_xxx 格式的新会话未匹配到旧格式 LIKE 查询),仍然尝试直接加载
2661
- if (!targetSessionId) {
2662
- var fallbackSession = urlSession || state._pendingSessionRestore;
2663
- if (fallbackSession && fallbackSession !== '__new__') {
2664
- targetSessionId = fallbackSession;
2665
- state._pendingSessionRestore = null;
2666
- console.log('[loadSessions] Session not in list, force restoring:', targetSessionId);
2667
- }
2668
- }
2691
+ // [fix] 移除 v1.24.1 的强制恢复逻辑:不再强制加载不属于当前 agent session ID
2692
+ // 旧逻辑会在 URL/localStorage 残留旧 agent 的 session ID 时,强制加载该会话,
2693
+ // 导致点击新 agent 头像后错乱显示旧 agent 的历史对话。
2694
+ // 对于当前 agent 确实没有匹配 session 的情况,应该进入"新对话"状态,而非加载其它 agent 的会话。
2669
2695
 
2670
2696
  if (targetSessionId) {
2671
2697
  await selectSession(targetSessionId);