diff --git a/settings.js b/settings.js index 26c0347..d09291e 100644 --- a/settings.js +++ b/settings.js @@ -6,7 +6,7 @@ const settings = { // the mindserver manages all agents and hosts the UI "mindserver_port": 8080, - "auto_open_ui": true, + "auto_open_ui": true, // opens UI in browser on startup "base_profile": "assistant", // survival, assistant, creative, or god_mode "profiles": [ diff --git a/src/agent/mindserver_proxy.js b/src/agent/mindserver_proxy.js index 68024a1..a64fe94 100644 --- a/src/agent/mindserver_proxy.js +++ b/src/agent/mindserver_proxy.js @@ -88,6 +88,7 @@ class MindServerProxy { return reject(new Error(response.error)); } setSettings(response.settings); + this.socket.emit('connect-agent-process', name); resolve(); }); }); diff --git a/src/mindcraft/mindserver.js b/src/mindcraft/mindserver.js index 64af008..0ac976a 100644 --- a/src/mindcraft/mindserver.js +++ b/src/mindcraft/mindserver.js @@ -101,6 +101,13 @@ export function createMindServer(host_public = false, port = 8080) { } }); + socket.on('connect-agent-process', (agentName) => { + if (agent_connections[agentName]) { + agent_connections[agentName].socket = socket; + agentsStatusUpdate(); + } + }); + socket.on('login-agent', (agentName) => { if (agent_connections[agentName]) { agent_connections[agentName].socket = socket; @@ -117,6 +124,7 @@ export function createMindServer(host_public = false, port = 8080) { if (agent_connections[curAgentName]) { console.log(`Agent ${curAgentName} disconnected`); agent_connections[curAgentName].in_game = false; + agent_connections[curAgentName].socket = null; agentsStatusUpdate(); } if (agent_listeners.includes(socket)) { @@ -221,7 +229,8 @@ function agentsStatusUpdate(socket) { agents.push({ name: agentName, in_game: conn.in_game, - viewerPort: conn.viewer_port + viewerPort: conn.viewer_port, + socket_connected: !!conn.socket }); }; socket.emit('agents-status', agents); diff --git a/src/mindcraft/public/index.html b/src/mindcraft/public/index.html index a56f498..8a29c89 100644 --- a/src/mindcraft/public/index.html +++ b/src/mindcraft/public/index.html @@ -759,7 +759,7 @@
- ${agent.name} + ${agent.name}${agent.socket_connected && !agent.in_game ? 'joining...' : ''} @@ -789,7 +789,7 @@ - +
`; @@ -817,7 +817,7 @@ const prevAgents = currentAgents.reduce((acc, a) => ({ ...acc, [a.name]: a }), {}); const changedAgents = agents.filter(a => { const prev = prevAgents[a.name]; - return !prev || prev.in_game !== a.in_game || prev.viewerPort !== a.viewerPort; + return !prev || prev.in_game !== a.in_game || prev.viewerPort !== a.viewerPort || prev.socket_connected !== a.socket_connected; }); // Update only changed agents @@ -859,7 +859,7 @@ const prevAgents = currentAgents.reduce((acc, a) => ({ ...acc, [a.name]: a }), {}); const changedAgents = agents.filter(a => { const prev = prevAgents[a.name]; - return !prev || prev.in_game !== a.in_game || prev.viewerPort !== a.viewerPort; + return !prev || prev.in_game !== a.in_game || prev.viewerPort !== a.viewerPort || prev.socket_connected !== a.socket_connected; }); // Update current agents list @@ -907,6 +907,16 @@ if (btn) { btn.textContent = 'Connecting...'; btn.disabled = true; + // Re-enable after 10s if still disabled (agent failed to connect) + setTimeout(() => { + const retryBtn = document.querySelector(`button[onclick=\\"startAgent('${n}')\\"]`); + const agentState = (window.currentAgents || []).find(a => a.name === n); + const stillWaiting = agentState ? (!agentState.in_game && !agentState.socket_connected) : true; + if (retryBtn && stillWaiting) { + retryBtn.disabled = false; + retryBtn.textContent = 'Connect'; + } + }, 10000); } socket.emit('start-agent', n); }