myagent-ai 1.15.26 → 1.15.27

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.15.26",
3
+ "version": "1.15.27",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
@@ -333,9 +333,8 @@ function initChat() {
333
333
  if (urlMode === 'chat' || urlMode === 'exec') {
334
334
  state.chatMode = urlMode;
335
335
  }
336
- if (urlAgent) {
337
- state.activeAgent = urlAgent;
338
- }
336
+ // agent 参数先暂存,等 loadAgents() 完成后校验是否存在
337
+ state._pendingUrlAgent = urlAgent;
339
338
 
340
339
  // Popout mode: hide sidebar, collapse agent panel, update title
341
340
  if (isPopout) {
@@ -384,15 +383,25 @@ function initChat() {
384
383
  // 如果 URL 指定了 agent 或 session,等 agent 列表加载后自动选中
385
384
  // 注意:loadSessions() 内部会检查 URL session 参数并自动恢复
386
385
  if (urlAgent) {
387
- const targetAgent = urlAgent || (urlSession ? urlSession.split('_web_')[0] || 'default' : null);
388
386
  setTimeout(function() {
389
- if (targetAgent) selectAgent(targetAgent);
387
+ // 校验 agent 是否真实存在,不存在则回退 default
388
+ var resolved = urlAgent;
389
+ if (!findAgentByPath(resolved)) {
390
+ console.warn('URL agent not found, fallback to default:', resolved);
391
+ resolved = 'default';
392
+ }
393
+ selectAgent(resolved);
390
394
  }, 500);
391
395
  } else if (urlSession) {
392
396
  // 只有 session 没有 agent,尝试从 session ID 推断 agent
393
397
  const targetAgent = urlSession.split('_web_')[0] || 'default';
394
398
  setTimeout(function() {
395
- selectAgent(targetAgent);
399
+ if (!findAgentByPath(targetAgent)) {
400
+ console.warn('Session-inferred agent not found, fallback to default:', targetAgent);
401
+ selectAgent('default');
402
+ } else {
403
+ selectAgent(targetAgent);
404
+ }
396
405
  }, 500);
397
406
  } else {
398
407
  // URL 中没有 session 参数,尝试从 localStorage 恢复上次的会话
@@ -1216,6 +1225,11 @@ function quickChatAgent(agentPath) {
1216
1225
  }
1217
1226
 
1218
1227
  async function selectAgent(agentPath) {
1228
+ // 安全校验:agent 必须在已加载的列表中存在,否则回退 default
1229
+ if (!findAgentByPath(agentPath)) {
1230
+ console.warn('selectAgent: agent not found, fallback to default:', agentPath);
1231
+ agentPath = 'default';
1232
+ }
1219
1233
  // 从群聊视图切换回个人聊天视图
1220
1234
  if (currentView === 'group') {
1221
1235
  currentView = 'chat';