The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(web): inline_images=false on GET /api/sessions/{id}/messages
Brooklyn Nicholson9cd114b49960
diff --git a/hermes_cli/web_routers/sessions.py b/hermes_cli/web_routers/sessions.pyindex 7be68ec2a73..d93be49fed0 100644--- a/hermes_cli/web_routers/sessions.py+++ b/hermes_cli/web_routers/sessions.py@@ -586,15 +586,29 @@ def _session_files_dir(profile) -> Path:return _history_profile_home(profile) / "sessions"-def _project_for_display(messages: list, *, home=None) -> list:+def _project_for_display(messages: list, *, home=None, inline_images: bool = True) -> list:from agent.compaction_display import project_compaction_message_for_displayfrom agent.context_compressor import is_compaction_summary_messagefrom agent.history_commentary import project_history_commentaryfrom agent.turn_failure_copy import untyped_failed_turn_display_kind+ # inline_images=False (#116511): render content through the gateway's ``_coerce_message_text``+ # projection so a data-URI image part becomes ``[image]`` — the same branch session.resume's+ # ``inline_images=false`` uses, kilobytes instead of re-transmitting every stored attachment.+ coerce = None+ if not inline_images:+ from tui_gateway.session_history import _coerce_message_text++ def coerce(message: dict) -> dict:+ if message.get("content") is not None:+ return {**message, "content": _coerce_message_text(message["content"], image_urls=False)}+ return message+projected_messages = []for message in messages:message = _with_tool_call_labels(message)+ if coerce is not None:+ message = coerce(message)# Same read-side typing as session.resume (tui_gateway/session_history.py).failed_turn = not message.get("display_kind") and untyped_failed_turn_display_kind(message.get("role"), message.get("content"))@@ -622,7 +636,7 @@ def _project_for_display(messages: list, *, home=None) -> list:async def get_session_messages(session_id: str, profile: Optional[str] = None, limit: Optional[int] = Query(None, ge=0),offset: int = Query(0, ge=0), order: Optional[str] = Query(None),- include_compacted: bool = Query(False)):+ include_compacted: bool = Query(False), inline_images: bool = Query(True)):if order not in (None, "oldest", "latest"):raise HTTPException(status_code=400, detail="order must be one of: oldest, latest")@@ -645,7 +659,8 @@ async def get_session_messages(raise HTTPException(status_code=404, detail=_NOT_FOUND)sid, _limit, messages = resultprojected_messages = await asyncio.to_thread(- _project_for_display, messages, home=_history_profile_home(profile))+ _project_for_display, messages, home=_history_profile_home(profile),+ inline_images=inline_images)return {"session_id": sid,# The same stamp list rows carry, so the Desktop keys a page under thediff --git a/tests/hermes_cli/test_session_messages_inline_images.py b/tests/hermes_cli/test_session_messages_inline_images.pynew file mode 100644index 00000000000..adb43d908b9--- /dev/null+++ b/tests/hermes_cli/test_session_messages_inline_images.py@@ -0,0 +1,66 @@+"""``GET /api/sessions/{id}/messages`` honors ``inline_images=false`` (#116511).++The REST pages carry ``content`` verbatim (a parts list with inline ``data:image`` URIs) so+Desktop's ``extractEmbeddedImages`` can pull them out of the text. A client that reads over+a network had no way to ask for less: the measured conversation was 26.33 MiB per page read.+``inline_images=false`` (default ``true``) routes the content through the same+``_coerce_message_text(image_urls=False)`` projection ``session.resume`` uses, rendering+``[image]`` in place of the data URI.+"""++from pathlib import Path++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++DATA_URI = "data:image/png;base64," + "a" * 128+IMAGE_CONTENT = [+ {"type": "text", "text": "what is this?"},+ {"type": "image_url", "image_url": {"url": DATA_URI}},+]+++def client(tmp_path, monkeypatch):+ from hermes_state import SessionDB++ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ home = tmp_path / ".hermes"+ home.mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(home))+ monkeypatch.setattr("hermes_state.DEFAULT_DB_PATH", home / "state.db")++ db = SessionDB(home / "state.db")+ try:+ db.create_session(session_id="img-chat", source="desktop")+ db.append_messages_batch("img-chat", [+ {"role": "user", "content": IMAGE_CONTENT},+ {"role": "assistant", "content": "a chart"},+ ])+ finally:+ db.close()++ from hermes_cli.web_routers.sessions import manage_router++ app = FastAPI()+ app.include_router(manage_router)+ with TestClient(app) as test_client:+ yield test_client+++def test_messages_default_inlines_images(client):+ page = client.get("/api/sessions/img-chat/messages?limit=10&order=oldest").json()+ user_row = next(m for m in page["messages"] if m["role"] == "user")+ assert DATA_URI in str(user_row["content"])+++def test_messages_inline_images_false_renders_placeholder(client):+ page = client.get(+ "/api/sessions/img-chat/messages?limit=10&order=oldest&inline_images=false").json()+ user_row = next(m for m in page["messages"] if m["role"] == "user")+ assert "[image]" in user_row["content"]+ assert DATA_URI not in user_row["content"]+ # Non-image rows are untouched.+ assistant_row = next(m for m in page["messages"] if m["role"] == "assistant")+ assert assistant_row["content"] == "a chart"diff --git a/website/docs/user-guide/features/api-server.md b/website/docs/user-guide/features/api-server.mdindex 1c940e6db42..5752296eb32 100644--- a/website/docs/user-guide/features/api-server.md+++ b/website/docs/user-guide/features/api-server.md@@ -611,7 +611,7 @@ External UIs can manage Hermes sessions over REST without standing up the dashbo| `GET` | `/api/sessions/{id}` | Read session metadata || `PATCH` | `/api/sessions/{id}` | Update title or `end_reason` || `DELETE` | `/api/sessions/{id}` | Delete a session |-| `GET` | `/api/sessions/{id}/messages` | Message history for a session |+| `GET` | `/api/sessions/{id}/messages` | Message history for a session. `inline_images=false` renders image attachments as `[image]` placeholders instead of inline data URIs — the transcript travels in kilobytes, for clients reading over a network || `POST` | `/api/sessions/{id}/fork` | Branch the session via `SessionDB` lineage (matches CLI `/branch` semantics) || `POST` | `/api/sessions/{id}/chat` | Run one synchronous agent turn || `POST` | `/api/sessions/{id}/chat/stream` | SSE wrapper over a single turn — emits `assistant.delta`, `assistant.commentary` (mid-turn commentary: `message_id`, `text`, `already_streamed`; never folded into `assistant.completed`), `tool.started`, `tool.completed`, `tool.failed` (a tool that finished with an error), then a terminal `run.completed` / `run.failed` / `run.cancelled` event that matches how the turn ended (see [Terminal run status](../../developer-guide/programmatic-integration.md#terminal-run-status)) |