Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(hub): parse BOM-prefixed skill frontmatter (#3119)
Long Jin1fd6e5816dec
diff --git a/src/agentscope/app/hub/_skill/_claw_hub.py b/src/agentscope/app/hub/_skill/_claw_hub.pyindex a009a1c0b..4f703f8d2 100644--- a/src/agentscope/app/hub/_skill/_claw_hub.py+++ b/src/agentscope/app/hub/_skill/_claw_hub.py@@ -641,7 +641,10 @@ class ClawSkillHub(SkillHubBase):item["owner"] = payload.get("owner")card = self._to_card(item)- parsed = await asyncio.to_thread(frontmatter.loads, markdown.text)+ parsed = await asyncio.to_thread(+ frontmatter.loads,+ markdown.text.removeprefix("\ufeff"),+ )card.markdown = parsed.contentif not card.description:card.description = str(parsed.get("description", ""))diff --git a/tests/hub_claw_test.py b/tests/hub_claw_test.pyindex f3f458c12..b92000898 100644--- a/tests/hub_claw_test.py+++ b/tests/hub_claw_test.py@@ -1,10 +1,62 @@# -*- coding: utf-8 -*-"""ClawHub card-building test case, without any network."""-from unittest import TestCase+from unittest import IsolatedAsyncioTestCase, TestCase+from unittest.mock import patch++import httpxfrom agentscope.app.hub import ClawSkillHub+class ClawSkillContentTest(IsolatedAsyncioTestCase):+ """Parsing skill content returned by the ClawHub file endpoint."""++ async def test_skill_frontmatter_with_utf8_bom(self) -> None:+ """A BOM-prefixed ``SKILL.md`` still has its frontmatter parsed."""+ skill_md = (+ "\ufeff---\nname: demo\ndescription: Frontmatter description\n"+ "---\n\n# Demo\nRun the demo."+ )++ def respond(request: httpx.Request) -> httpx.Response:+ if request.url.path.endswith("/file"):+ return httpx.Response(200, text=skill_md)+ return httpx.Response(+ 200,+ json={+ "skill": {"slug": "demo"},+ "owner": {"handle": "alice"},+ "latestVersion": {"version": "1.2.3"},+ },+ )++ client = httpx.AsyncClient(transport=httpx.MockTransport(respond))+ with patch("httpx.AsyncClient", return_value=client):+ async with ClawSkillHub() as hub:+ card = await hub.get_skill("user", "alice/demo")++ self.assertDictEqual(+ card.model_dump(),+ {+ "hub_id": "clawhub",+ "id": "alice/demo",+ "name": "demo",+ "description": "Frontmatter description",+ "display_name": None,+ "tags": [],+ "version": "1.2.3",+ "updated_at": None,+ "author": "alice",+ "icon_url": None,+ "installs": None,+ "downloads": None,+ "url": "https://clawhub.ai/skills/demo",+ "markdown": "# Demo\nRun the demo.",+ "metadata": {},+ },+ )++class ClawCardTest(TestCase):"""Turning an upstream catalog record into a ``SkillCard``."""