[eric] apps: a spawned agent lands on the most-recent dashboard when the app names none, so the card is visible not just real

This commit is contained in:
ciregenz
2026-08-08 02:14:27 -07:00
parent 9541d0cf09
commit ab847fe2c4
2 changed files with 13 additions and 2 deletions
+9 -2
View File
@@ -103,18 +103,25 @@ async def spawn_agent(body: SpawnAgentRequest) -> SpawnAgentReply:
if not body.prompt.strip():
raise HTTPException(status_code=422, detail="prompt is empty")
dashboard_id = body.dashboard_id
if dashboard_id is None:
# An app webview has no idea which dashboard it lives on; without one the canvas lifecycle
# never creates a card, so the spawn is real but invisible. Most-recent dashboard wins.
from backend.apps.dashboards.dashboards import load_all
boards = sorted(load_all(), key=lambda d: d.updated_at, reverse=True)
dashboard_id = boards[0].id if boards else None
config = AgentConfig(
name=body.name,
prompt=body.prompt,
model=body.model or "sonnet",
dashboard_id=body.dashboard_id,
dashboard_id=dashboard_id,
)
session = await agent_manager.launch_agent(config)
asyncio.create_task(agent_manager.send_message(session.id, body.prompt))
if body.x is not None and body.y is not None:
await ws_manager.broadcast_global("apps_sdk:place_agent_card", {
"session_id": session.id,
"dashboard_id": body.dashboard_id,
"dashboard_id": dashboard_id,
"x": body.x,
"y": body.y,
})
+4
View File
@@ -89,10 +89,12 @@ def test_llm_rejects_an_empty_prompt():
def test_spawn_agent_launches_and_broadcasts_position(monkeypatch):
import backend.apps.dashboards.dashboards as dash_mod
from backend.apps.agents import agent_manager as am_mod
from backend.apps.agents.core import ws_manager as ws_mod
from backend.apps.agents.core.models import AgentSession
monkeypatch.setattr(dash_mod, "load_all", lambda: [], raising=True)
launched = []
messaged = []
broadcasts = []
@@ -122,10 +124,12 @@ def test_spawn_agent_launches_and_broadcasts_position(monkeypatch):
def test_spawn_agent_without_position_skips_the_broadcast(monkeypatch):
import backend.apps.dashboards.dashboards as dash_mod
from backend.apps.agents import agent_manager as am_mod
from backend.apps.agents.core import ws_manager as ws_mod
from backend.apps.agents.core.models import AgentSession
monkeypatch.setattr(dash_mod, "load_all", lambda: [], raising=True)
broadcasts = []
async def p_launch(config):