refac: tool server data handling

This commit is contained in:
Timothy Jaeryang Baek 2025-09-09 19:00:01 +04:00
parent c299d3fd54
commit 774c0056bd

View file

@ -538,12 +538,23 @@ async def get_tool_server_data(token: str, url: str) -> Dict[str, Any]:
error_body = await response.json() error_body = await response.json()
raise Exception(error_body) raise Exception(error_body)
text_content = None
# Check if URL ends with .yaml or .yml to determine format # Check if URL ends with .yaml or .yml to determine format
if url.lower().endswith((".yaml", ".yml")): if url.lower().endswith((".yaml", ".yml")):
text_content = await response.text() text_content = await response.text()
res = yaml.safe_load(text_content) res = yaml.safe_load(text_content)
else: else:
res = await response.json() text_content = await response.text()
try:
res = json.loads(text_content)
except json.JSONDecodeError:
try:
res = yaml.safe_load(text_content)
except Exception as e:
raise e
except Exception as err: except Exception as err:
log.exception(f"Could not fetch tool server spec from {url}") log.exception(f"Could not fetch tool server spec from {url}")
if isinstance(err, dict) and "detail" in err: if isinstance(err, dict) and "detail" in err: