myagent-ai 1.15.82 → 1.15.83
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 +1 -1
- package/web/api_server.py +5 -1
- package/web/ui/chat/chat_main.js +45 -41
- package/web/ui/chat/flow_engine.js +7 -2
package/package.json
CHANGED
package/web/api_server.py
CHANGED
|
@@ -884,7 +884,11 @@ class ApiServer:
|
|
|
884
884
|
|
|
885
885
|
agent_path = data.get("agent_path", "default")
|
|
886
886
|
raw_session_id = data.get("session_id", "web_default")
|
|
887
|
-
session_id
|
|
887
|
+
# Avoid double-prefixing: if the session_id already starts with agent_path_, use it directly
|
|
888
|
+
if raw_session_id.startswith(f"{agent_path}_"):
|
|
889
|
+
session_id = raw_session_id
|
|
890
|
+
else:
|
|
891
|
+
session_id = f"{agent_path}_{raw_session_id}"
|
|
888
892
|
choice = data.get("choice", "queue") # "continue" (插入后继续) 或 "queue" (排队)
|
|
889
893
|
|
|
890
894
|
# 检查会话是否正在运行
|
package/web/ui/chat/chat_main.js
CHANGED
|
@@ -311,6 +311,11 @@ const StatePersistence = {
|
|
|
311
311
|
if (savedRpSections) { Object.assign(rpSections, savedRpSections); }
|
|
312
312
|
const savedNodes = StatePersistence.load('expandedNodes', ['default']);
|
|
313
313
|
state.expandedNodes = new Set(savedNodes);
|
|
314
|
+
// 恢复上次活跃的会话 ID,供 loadSessions() 使用
|
|
315
|
+
var savedSessionId = StatePersistence.load('activeSessionId', null);
|
|
316
|
+
if (savedSessionId) {
|
|
317
|
+
state._pendingSessionRestore = savedSessionId;
|
|
318
|
+
}
|
|
314
319
|
},
|
|
315
320
|
/** 标记 setup 已完成(避免每次刷新弹出向导) */
|
|
316
321
|
markSetupDone() { StatePersistence.save('setupDone', true); },
|
|
@@ -318,7 +323,7 @@ const StatePersistence = {
|
|
|
318
323
|
};
|
|
319
324
|
|
|
320
325
|
// ── Init ──
|
|
321
|
-
function initChat() {
|
|
326
|
+
async function initChat() {
|
|
322
327
|
// Initialize theme
|
|
323
328
|
initTheme();
|
|
324
329
|
// Restore persisted UI state
|
|
@@ -333,8 +338,6 @@ function initChat() {
|
|
|
333
338
|
if (urlMode === 'chat' || urlMode === 'exec') {
|
|
334
339
|
state.chatMode = urlMode;
|
|
335
340
|
}
|
|
336
|
-
// agent 参数先暂存,等 loadAgents() 完成后校验是否存在
|
|
337
|
-
state._pendingUrlAgent = urlAgent;
|
|
338
341
|
|
|
339
342
|
// Popout mode: hide sidebar, collapse agent panel, update title
|
|
340
343
|
if (isPopout) {
|
|
@@ -347,9 +350,7 @@ function initChat() {
|
|
|
347
350
|
if (agentPanel) agentPanel.classList.add('collapsed');
|
|
348
351
|
const agentToggle = document.getElementById('agentToggle');
|
|
349
352
|
if (agentToggle) agentToggle.style.display = 'none';
|
|
350
|
-
// Update page title with agent name
|
|
351
|
-
const agentObj = findAgentByPath(urlAgent);
|
|
352
|
-
document.title = (agentObj ? agentObj.name : urlAgent || 'MyAgent') + ' - MyAgent';
|
|
353
|
+
// Update page title with agent name (after agents load)
|
|
353
354
|
}
|
|
354
355
|
|
|
355
356
|
// Apply restored state to DOM
|
|
@@ -357,7 +358,6 @@ function initChat() {
|
|
|
357
358
|
if (panel) panel.classList.toggle('collapsed', !state.agentPanelOpen);
|
|
358
359
|
if (state.chatMode === 'exec') setMode('exec');
|
|
359
360
|
loadModels();
|
|
360
|
-
loadAgents();
|
|
361
361
|
loadStatus();
|
|
362
362
|
loadChatVersion();
|
|
363
363
|
fetchGroups();
|
|
@@ -380,49 +380,53 @@ function initChat() {
|
|
|
380
380
|
loadTaskPlan();
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
-
//
|
|
384
|
-
|
|
383
|
+
// 页面卸载前保存 UI 状态(包括活跃 session)
|
|
384
|
+
window.addEventListener('beforeunload', function() {
|
|
385
|
+
StatePersistence.saveUIState();
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// ── 核心:先等待 loadAgents 完成(内含 loadSessions),再做 agent/session 选择 ──
|
|
389
|
+
// 这样避免了 setTimeout 竞态条件导致 sendMessage 和 selectAgent 互相干扰
|
|
390
|
+
await loadAgents();
|
|
391
|
+
|
|
392
|
+
// loadAgents 完成后,agent 列表和 sessions 已加载完毕
|
|
393
|
+
// 现在可以安全地做 agent/session 选择(不会再和 sendMessage 竞态)
|
|
394
|
+
if (isPopout) {
|
|
395
|
+
const agentObj = findAgentByPath(urlAgent);
|
|
396
|
+
document.title = (agentObj ? agentObj.name : urlAgent || 'MyAgent') + ' - MyAgent';
|
|
397
|
+
}
|
|
398
|
+
|
|
385
399
|
if (urlAgent) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
400
|
+
// URL 指定了 agent,校验后切换
|
|
401
|
+
var resolved = urlAgent;
|
|
402
|
+
if (!findAgentByPath(resolved)) {
|
|
403
|
+
console.warn('URL agent not found, fallback to default:', resolved);
|
|
404
|
+
resolved = 'default';
|
|
405
|
+
}
|
|
406
|
+
if (resolved !== state.activeAgent) {
|
|
393
407
|
selectAgent(resolved);
|
|
394
|
-
}
|
|
408
|
+
}
|
|
395
409
|
} else if (urlSession) {
|
|
396
410
|
// 只有 session 没有 agent,尝试从 session ID 推断 agent
|
|
397
411
|
const targetAgent = urlSession.split('_web_')[0] || 'default';
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
412
|
+
var target = targetAgent;
|
|
413
|
+
if (!findAgentByPath(target)) {
|
|
414
|
+
console.warn('Session-inferred agent not found, fallback to default:', target);
|
|
415
|
+
target = 'default';
|
|
416
|
+
}
|
|
417
|
+
if (target !== state.activeAgent) {
|
|
418
|
+
selectAgent(target);
|
|
419
|
+
}
|
|
420
|
+
// 如果 agent 已一致,loadSessions 内部已通过 URL session 参数自动恢复了
|
|
406
421
|
} else {
|
|
407
|
-
// URL 中没有 session 参数,尝试从 localStorage 恢复上次的会话
|
|
408
|
-
var savedSessionId = StatePersistence.load('activeSessionId', null);
|
|
422
|
+
// URL 中没有 agent/session 参数,尝试从 localStorage 恢复上次的会话
|
|
409
423
|
var savedSessionAgent = StatePersistence.load('activeSessionAgent', null);
|
|
410
|
-
if (
|
|
411
|
-
//
|
|
412
|
-
|
|
413
|
-
if (savedSessionAgent !== state.activeAgent) {
|
|
414
|
-
setTimeout(function() {
|
|
415
|
-
selectAgent(savedSessionAgent);
|
|
416
|
-
}, 500);
|
|
417
|
-
}
|
|
418
|
-
// 如果 agent 已经一致,loadSessions() 内部会自动处理
|
|
424
|
+
if (savedSessionAgent && savedSessionAgent !== state.activeAgent) {
|
|
425
|
+
// agent 不一致,需要切换(loadSessions 内部已通过 _pendingSessionRestore 处理 session 恢复)
|
|
426
|
+
selectAgent(savedSessionAgent);
|
|
419
427
|
}
|
|
428
|
+
// 如果 agent 一致,loadSessions() 内部已通过 _pendingSessionRestore 自动处理了
|
|
420
429
|
}
|
|
421
|
-
|
|
422
|
-
// 页面卸载前保存 UI 状态(包括活跃 session)
|
|
423
|
-
window.addEventListener('beforeunload', function() {
|
|
424
|
-
StatePersistence.saveUIState();
|
|
425
|
-
});
|
|
426
430
|
}
|
|
427
431
|
|
|
428
432
|
// Run init: if DOMContentLoaded already fired (dynamic script load), run immediately
|
|
@@ -1382,6 +1382,7 @@ async function sendMessage(opts) {
|
|
|
1382
1382
|
let allExecEvents = []; // All exec events (for summary panel at bottom)
|
|
1383
1383
|
let msgIdx = state.messages.length;
|
|
1384
1384
|
let sessionIdReceived = sessionId;
|
|
1385
|
+
let sessionIdOriginal = sessionId; // 保存前端原始 ID,用于后端返回不同 ID 时的回退查找
|
|
1385
1386
|
let fullThought = '';
|
|
1386
1387
|
let _isV2Mode = false; // Track whether V2 structured output events are received
|
|
1387
1388
|
let _v2RawXml = ''; // In V2 mode, accumulate raw XML from text_delta separately
|
|
@@ -1857,8 +1858,11 @@ async function sendMessage(opts) {
|
|
|
1857
1858
|
state.sessions.unshift(existing);
|
|
1858
1859
|
} else {
|
|
1859
1860
|
// 防御:后端返回的 sessionIdReceived 和前端的不一致时,
|
|
1860
|
-
//
|
|
1861
|
-
var localIdx = state.sessions.findIndex(s => s.id ===
|
|
1861
|
+
// 优先用前端原始 ID 查找,再用 activeSessionId 查找
|
|
1862
|
+
var localIdx = state.sessions.findIndex(s => s.id === sessionIdOriginal);
|
|
1863
|
+
if (localIdx < 0) {
|
|
1864
|
+
localIdx = state.sessions.findIndex(s => s.id === state.activeSessionId);
|
|
1865
|
+
}
|
|
1862
1866
|
if (localIdx >= 0) {
|
|
1863
1867
|
var localEntry = state.sessions[localIdx];
|
|
1864
1868
|
localEntry.id = sessionIdReceived;
|
|
@@ -1869,6 +1873,7 @@ async function sendMessage(opts) {
|
|
|
1869
1873
|
state.sessions.unshift(localEntry);
|
|
1870
1874
|
console.warn('[sendMessage] Session ID mismatch, updated local entry:', sessionIdReceived);
|
|
1871
1875
|
} else {
|
|
1876
|
+
// 真正的新会话(本地列表中不存在)
|
|
1872
1877
|
state.sessions.unshift({ id: sessionIdReceived, name: formatSessionName(sessionIdReceived), messages: 2, last: new Date().toISOString() });
|
|
1873
1878
|
}
|
|
1874
1879
|
}
|