Fixed Dozens of Issues with Agent Communication

This commit is contained in:
2025-05-03 06:02:26 -06:00
parent 4d89b8d58c
commit 8116c1b717
3 changed files with 28 additions and 29 deletions

View File

@ -209,11 +209,9 @@ class ScreenshotRegion(QtWidgets.QWidget):
def mouseReleaseEvent(self, e): def mouseReleaseEvent(self, e):
self.resizing = False self.resizing = False
self.drag_offset = None self.drag_offset = None
# Persist geometry on release
x, y, w, h = self.get_geometry() x, y, w, h = self.get_geometry()
CONFIG.data['regions'][self.node_id] = {'x': x, 'y': y, 'w': w, 'h': h} CONFIG.data['regions'][self.node_id] = {'x': x, 'y': y, 'w': w, 'h': h}
CONFIG._write() CONFIG._write()
# Send geometry immediately upstream
asyncio.create_task(sio.emit('agent_screenshot_task', { asyncio.create_task(sio.emit('agent_screenshot_task', {
'agent_id': AGENT_ID, 'agent_id': AGENT_ID,
'node_id': self.node_id, 'node_id': self.node_id,

View File

@ -51,31 +51,34 @@ const ScreenshotInstructionNode = ({ id, data }) => {
if (!socket) return; if (!socket) return;
const handleScreenshot = (payload) => { const handleScreenshot = (payload) => {
if (payload?.node_id !== id || !payload.image_base64) return; if (payload?.node_id !== id) return;
base64Ref.current = payload.image_base64; // image update (optional)
setImageBase64(payload.image_base64); if (payload.image_base64) {
window.BorealisValueBus[id] = payload.image_base64; base64Ref.current = payload.image_base64;
setImageBase64(payload.image_base64);
window.BorealisValueBus[id] = payload.image_base64;
}
// If geometry changed from agent side, sync into UI // geometry update
const { x, y, w, h } = payload; const { x, y, w, h } = payload;
if (x !== undefined && y !== undefined && w !== undefined && h !== undefined) { if (x !== undefined && y !== undefined && w !== undefined && h !== undefined) {
const newRegion = { x, y, w, h }; const newRegion = { x, y, w, h };
const prev = regionRef.current; const prev = regionRef.current;
const changed = Object.entries(newRegion).some(([k, v]) => prev[k] !== v); const changed = Object.entries(newRegion).some(([k, v]) => prev[k] !== v);
if (changed) { if (changed) {
regionRef.current = newRegion; regionRef.current = newRegion;
setRegion(newRegion); setRegion(newRegion);
setNodes(nds => setNodes(nds =>
nds.map(n => nds.map(n =>
n.id === id ? { ...n, data: { ...n.data, ...newRegion } } : n n.id === id ? { ...n, data: { ...n.data, ...newRegion } } : n
) )
); );
}
} }
}
}; };
socket.on("agent_screenshot_task", handleScreenshot); socket.on("agent_screenshot_task", handleScreenshot);
return () => socket.off("agent_screenshot_task", handleScreenshot); return () => socket.off("agent_screenshot_task", handleScreenshot);
}, [id, setNodes]); }, [id, setNodes]);

View File

@ -154,22 +154,20 @@ def screenshot_node_viewer(agent_id, node_id):
def receive_screenshot_task(data): def receive_screenshot_task(data):
agent_id = data.get("agent_id") agent_id = data.get("agent_id")
node_id = data.get("node_id") node_id = data.get("node_id")
image = data.get("image_base64") image = data.get("image_base64", "")
if not agent_id or not node_id or not image: if not agent_id or not node_id:
print("[WS] Screenshot task missing fields.") print("[WS] Screenshot task missing agent_id or node_id.")
return return
latest_images[f"{agent_id}:{node_id}"] = { if image:
"image_base64": image, latest_images[f"{agent_id}:{node_id}"] = {
"timestamp": time.time() "image_base64": image,
} "timestamp": time.time()
}
emit("agent_screenshot_task", { # Emit the full payload, including geometry (even if image is empty)
"agent_id": agent_id, emit("agent_screenshot_task", data, broadcast=True)
"node_id": node_id,
"image_base64": image
}, broadcast=True)
@socketio.on("connect_agent") @socketio.on("connect_agent")
def connect_agent(data): def connect_agent(data):