From 894875ab1b1c232698c0ad32ae565f4b3cbbe1d1 Mon Sep 17 00:00:00 2001 From: Ryanba <92616678+Gujiassh@users.noreply.github.com> Date: Sun, 22 Mar 2026 19:59:54 +0800 Subject: [PATCH] fix(gateway): accept output_text suggestion blocks (#1238) Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus Co-authored-by: Willem Jiang --- backend/app/gateway/routers/suggestions.py | 2 +- backend/tests/test_suggestions_router.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/app/gateway/routers/suggestions.py b/backend/app/gateway/routers/suggestions.py index dee985e..3fac15d 100644 --- a/backend/app/gateway/routers/suggestions.py +++ b/backend/app/gateway/routers/suggestions.py @@ -68,7 +68,7 @@ def _extract_response_text(content: object) -> str: for block in content: if isinstance(block, str): parts.append(block) - elif isinstance(block, dict) and block.get("type") == "text": + elif isinstance(block, dict) and block.get("type") in {"text", "output_text"}: text = block.get("text") if isinstance(text, str): parts.append(text) diff --git a/backend/tests/test_suggestions_router.py b/backend/tests/test_suggestions_router.py index 4ff8e09..75237ee 100644 --- a/backend/tests/test_suggestions_router.py +++ b/backend/tests/test_suggestions_router.py @@ -69,6 +69,24 @@ def test_generate_suggestions_parses_list_block_content(monkeypatch): assert result.suggestions == ["Q1", "Q2"] +def test_generate_suggestions_parses_output_text_block_content(monkeypatch): + req = suggestions.SuggestionsRequest( + messages=[ + suggestions.SuggestionMessage(role="user", content="Hi"), + suggestions.SuggestionMessage(role="assistant", content="Hello"), + ], + n=2, + model_name=None, + ) + fake_model = MagicMock() + fake_model.invoke.return_value = MagicMock(content=[{"type": "output_text", "text": '```json\n["Q1", "Q2"]\n```'}]) + monkeypatch.setattr(suggestions, "create_chat_model", lambda **kwargs: fake_model) + + result = asyncio.run(suggestions.generate_suggestions("t1", req)) + + assert result.suggestions == ["Q1", "Q2"] + + def test_generate_suggestions_returns_empty_on_model_error(monkeypatch): req = suggestions.SuggestionsRequest( messages=[suggestions.SuggestionMessage(role="user", content="Hi")],