"""Helpers moved unchanged out of render_pl9_markdown (phase 1).""" def _unwrap(raw_value): # 兼容 packet 字段的 response_envelope 升级: # 真实数据可能直接是 list/dict,也可能被包成 {"result": ..., "response_envelope": {...}}。 if ( isinstance(raw_value, dict) and 'result' in raw_value and 'response_envelope' in raw_value ): return raw_value.get('result') return raw_value def _envelope_list(raw_value): raw_value = _unwrap(raw_value) if isinstance(raw_value, list): return raw_value if isinstance(raw_value, tuple): return list(raw_value) # 期望 list 时,即使只有 result 键也解包,避免 nested planets 被空渲染成 '-'。 if isinstance(raw_value, dict) and 'result' in raw_value: nested = raw_value.get('result') if isinstance(nested, list): return nested if isinstance(nested, tuple): return list(nested) return [] def _envelope_dict(raw_value): raw_value = _unwrap(raw_value) return raw_value if isinstance(raw_value, dict) else {} def _bool_text(value): return '是' if value else '否' def _source_dict(*candidates): for candidate in candidates: if isinstance(candidate, dict) and candidate: return candidate return {} def _has_executed_payload(value) -> bool: if value in (None, '', [], {}): return False if isinstance(value, dict): status = str(value.get('status') or value.get('execution_status') or '').strip().lower() if status in {'blocked', 'missing', 'not_found', 'parameter_sensitive'}: return False return True