fix session routing and subagent visibility
This commit is contained in:
+16
-1
@@ -1659,7 +1659,10 @@ def create_app(state: AgentState) -> FastAPI:
|
||||
|
||||
# ------------- sessions --------------------------------------------------
|
||||
@app.get('/api/sessions')
|
||||
async def list_sessions(account_id: str | None = None) -> list[dict[str, Any]]:
|
||||
async def list_sessions(
|
||||
account_id: str | None = None,
|
||||
include_children: bool = False,
|
||||
) -> list[dict[str, Any]]:
|
||||
directory = state.account_paths(account_id)['sessions']
|
||||
if not directory.exists():
|
||||
return []
|
||||
@@ -1670,6 +1673,16 @@ def create_app(state: AgentState) -> FastAPI:
|
||||
except (OSError, json.JSONDecodeError):
|
||||
continue
|
||||
session_id = str(data.get('session_id', _session_id_from_path(path)))
|
||||
session_metadata = (
|
||||
data.get('session_metadata')
|
||||
if isinstance(data.get('session_metadata'), dict)
|
||||
else {}
|
||||
)
|
||||
if (
|
||||
not include_children
|
||||
and session_metadata.get('visibility') == 'child'
|
||||
):
|
||||
continue
|
||||
usage = data.get('usage') if isinstance(data.get('usage'), dict) else {}
|
||||
model_config = (
|
||||
data.get('model_config')
|
||||
@@ -1695,6 +1708,7 @@ def create_app(state: AgentState) -> FastAPI:
|
||||
'model': model_config.get('model'),
|
||||
'usage': usage,
|
||||
'is_training': bool(data.get('is_training', False)),
|
||||
'session_metadata': session_metadata,
|
||||
}
|
||||
)
|
||||
return results
|
||||
@@ -2769,6 +2783,7 @@ def _serialize_stored_session(stored: StoredAgentSession) -> dict[str, Any]:
|
||||
'total_cost_usd': stored.total_cost_usd,
|
||||
'model': stored.model_config.get('model'),
|
||||
'is_training': stored.is_training,
|
||||
'session_metadata': stored.session_metadata or {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user