refs #732: preserve Select AI results in HMM reports
This commit is contained in:
@@ -2670,6 +2670,28 @@ def _mcp_items(mcp_result: Any) -> list[Any]:
|
||||
return items if isinstance(items, list) else []
|
||||
|
||||
|
||||
def _mcp_structured_rows(value: Any) -> list[Any]:
|
||||
"""Extract row arrays from common MCP wrappers, including JSON strings."""
|
||||
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return _mcp_structured_rows(json.loads(value))
|
||||
except ValueError:
|
||||
return []
|
||||
if isinstance(value, list):
|
||||
return value
|
||||
if not isinstance(value, Mapping):
|
||||
return []
|
||||
|
||||
for key in ("items", "results", "rows", "response", "result"):
|
||||
if key not in value:
|
||||
continue
|
||||
rows = _mcp_structured_rows(value.get(key))
|
||||
if rows:
|
||||
return rows
|
||||
return []
|
||||
|
||||
|
||||
def _mcp_summary(mcp_result: Any) -> dict[str, Any]:
|
||||
if not isinstance(mcp_result, Mapping):
|
||||
return {"type": type(mcp_result).__name__}
|
||||
@@ -2876,14 +2898,7 @@ def _presentation_payload(question: str, steps: list[Mapping[str, Any]]) -> dict
|
||||
{},
|
||||
)
|
||||
raw_result = source.get("mcp_result", {}) if isinstance(source, Mapping) else {}
|
||||
payload = _mcp_response_payload(raw_result)
|
||||
source_rows = _mcp_items(raw_result)
|
||||
if not source_rows:
|
||||
for key in ("results", "rows"):
|
||||
candidate = payload.get(key) if isinstance(payload, Mapping) else None
|
||||
if isinstance(candidate, list):
|
||||
source_rows = candidate
|
||||
break
|
||||
source_rows = _mcp_structured_rows(raw_result)
|
||||
rows = [
|
||||
_normalize_presentation_value(row)
|
||||
for row in source_rows
|
||||
|
||||
Reference in New Issue
Block a user