myagent-ai 1.32.3 → 1.32.4

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.3",
3
+ "version": "1.32.4",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
@@ -2145,17 +2145,7 @@ function quickChatAgent(agentPath) {
2145
2145
  if (_qPrevAgent !== agentPath) {
2146
2146
  state._pendingSessionRestore = null;
2147
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
- }
2148
+ // [fix] 不再清除 URL ?s= 参数,由 loadSessions 中校验 session 归属来防止错乱
2159
2149
  // 展开所有父节点
2160
2150
  var parts = agentPath.split('/');
2161
2151
  var cumPath = '';
@@ -2214,19 +2204,11 @@ async function selectAgent(agentPath) {
2214
2204
  if (_prevAgent !== agentPath) {
2215
2205
  state._pendingSessionRestore = null;
2216
2206
  }
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
- }
2207
+ // [fix] 注意:不再在此处清除 URL 中的 ?s= 参数!
2208
+ // 原因:initChat 恢复场景中,URL 可能同时包含 ?aid=B&s=sess_b1,
2209
+ // 如果在此处删除 s 参数,loadSessions 将无法恢复指定 session。
2210
+ // 正确的做法是在 loadSessions 中校验 URL session 是否属于当前 agent,
2211
+ // 如果不属于则忽略(不选中),从而避免错乱。
2230
2212
  // 递增序号,使任何进行中的 selectSession 请求失效
2231
2213
  state._sessionLoadSeq++;
2232
2214
  var parts = agentPath.split('/');
@@ -2623,9 +2605,25 @@ async function loadSessions() {
2623
2605
 
2624
2606
  // 创建新的 Promise 并缓存
2625
2607
  const loadPromise = (async () => {
2608
+ // [fix] 在闭包入口捕获当前 agent,防止 await 后 state.activeAgent 被其它 selectAgent 改变
2609
+ // 导致 agent B 的 sessions 被错误地写入 state.agentSessions['C']
2610
+ const loadAgent = currentAgent;
2626
2611
  try {
2627
- const url = `/api/sessions?agent=${encodeURIComponent(state.activeAgent)}`;
2612
+ const url = `/api/sessions?agent=${encodeURIComponent(loadAgent)}`;
2628
2613
  const data = await api(url);
2614
+ // [fix] 竞态保护:如果 await 期间 agent 已切换,不更新 state.sessions(避免覆盖新 agent 的数据)
2615
+ if (state.activeAgent !== loadAgent) {
2616
+ // 仅更新缓存,不动 state.sessions
2617
+ const sessions = (data || []).map(s => ({
2618
+ id: s.id,
2619
+ name: s.display_name || formatSessionName(s.id),
2620
+ messages: s.messages || 0,
2621
+ last: s.last || '',
2622
+ preview: s.preview || '',
2623
+ }));
2624
+ state.agentSessions[loadAgent] = sessions;
2625
+ return { sessions: [], selectedId: null, stale: true };
2626
+ }
2629
2627
  state.sessions = (data || []).map(s => ({
2630
2628
  id: s.id,
2631
2629
  name: s.display_name || formatSessionName(s.id),
@@ -2633,11 +2631,18 @@ async function loadSessions() {
2633
2631
  last: s.last || '',
2634
2632
  preview: s.preview || '',
2635
2633
  }));
2636
- // Cache per agent
2637
- state.agentSessions[state.activeAgent] = [...state.sessions];
2634
+ // Cache per agent — 使用闭包捕获的 loadAgent 而非 state.activeAgent
2635
+ state.agentSessions[loadAgent] = [...state.sessions];
2638
2636
  } catch (e) {
2639
- // Offline - try cache
2640
- state.sessions = state.agentSessions[state.activeAgent] || [];
2637
+ // Offline - try cache — 使用 loadAgent
2638
+ if (state.activeAgent === loadAgent) {
2639
+ state.sessions = state.agentSessions[loadAgent] || [];
2640
+ }
2641
+ }
2642
+
2643
+ // [fix] 竞态保护:如果 agent 已切换,不渲染 UI、不选中 session
2644
+ if (state.activeAgent !== loadAgent) {
2645
+ return { sessions: [], selectedId: null, stale: true };
2641
2646
  }
2642
2647
 
2643
2648
  // Always update session list UI