fix(gateway): accept output_text suggestion blocks (#1238)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
This commit is contained in:
Ryanba
2026-03-22 19:59:54 +08:00
committed by GitHub
parent 7a90055ede
commit 894875ab1b
2 changed files with 19 additions and 1 deletions

View File

@@ -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)

View File

@@ -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")],