Skip to content

Build and run agents you can see, understand and trust.

fix(hub): accept owner-scoped skill card ids (#2291)

csurongbf9f34785911
diff --git a/src/agentscope/app/_router/_hub.py b/src/agentscope/app/_router/_hub.py
index 4e8c8254c..d7ddaf17a 100644
--- a/src/agentscope/app/_router/_hub.py
+++ b/src/agentscope/app/_router/_hub.py
@@ -231,27 +231,8 @@ async def list_skill_cards(
return await hub.list_skills(user_id, q=q, cursor=cursor, limit=limit)
-@hub_router.get("/skill/{hub_id}/cards/{card_id}")
-async def get_skill_card(
- hub_id: str,
- card_id: str,
- *,
- user_id: str = Depends(get_current_user_id),
- hubs: dict[str, SkillHubBase] = Depends(get_skill_hubs),
-) -> SkillCard:
- """Return one skill card, including its ``SKILL.md`` body."""
- hub = _pick_hub(hubs, hub_id)
- try:
- return await hub.get_skill(user_id, card_id)
- except KeyError as e:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail=f"Hub {hub_id!r} has no skill {card_id!r}.",
- ) from e
-
-
@hub_router.post(
- "/skill/{hub_id}/cards/{card_id}/install",
+ "/skill/{hub_id}/cards/{card_id:path}/install",
status_code=status.HTTP_201_CREATED,
)
async def install_skill(
@@ -306,3 +287,25 @@ async def install_skill(
) from e
return SkillView.from_record(record)
+
+
+# Keep this catch-all path route after the more specific ``/install`` route.
+# This keeps route precedence explicit and protects specific routes from
+# accidental shadowing as more card actions are added.
+@hub_router.get("/skill/{hub_id}/cards/{card_id:path}")
+async def get_skill_card(
+ hub_id: str,
+ card_id: str,
+ *,
+ user_id: str = Depends(get_current_user_id),
+ hubs: dict[str, SkillHubBase] = Depends(get_skill_hubs),
+) -> SkillCard:
+ """Return one skill card, including its ``SKILL.md`` body."""
+ hub = _pick_hub(hubs, hub_id)
+ try:
+ return await hub.get_skill(user_id, card_id)
+ except KeyError as e:
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND,
+ detail=f"Hub {hub_id!r} has no skill {card_id!r}.",
+ ) from e
diff --git a/tests/hub_router_test.py b/tests/hub_router_test.py
index d04f4db4c..a0e074666 100644
--- a/tests/hub_router_test.py
+++ b/tests/hub_router_test.py
@@ -6,6 +6,7 @@ import json
import tempfile
import zipfile
from typing import Any, AsyncIterator
+from urllib.parse import quote
from unittest import IsolatedAsyncioTestCase
import fakeredis.aioredis
@@ -161,6 +162,12 @@ class FakeSkillHub(SkillHubBase):
url="https://hub.invalid/skills/gifgrep",
markdown=SKILL_MD,
)
+ self.owner_scoped_card = SkillCard(
+ hub_id="fakeskills",
+ id="runware/music",
+ name="music",
+ markdown=SKILL_MD,
+ )
self.download_users: list[str] = []
async def list_skills(
@@ -175,6 +182,8 @@ class FakeSkillHub(SkillHubBase):
async def get_skill(self, user_id: str, card_id: str) -> SkillCard:
"""Return the fixture card, or raise for anything else."""
+ if card_id == self.owner_scoped_card.id:
+ return self.owner_scoped_card
if card_id != "gifgrep":
raise KeyError(card_id)
return self.card
@@ -308,6 +317,18 @@ class HubRouterTest(IsolatedAsyncioTestCase):
self.assertEqual(response.status_code, 404)
+ def test_gets_owner_scoped_skill_card(self) -> None:
+ """A slash in an opaque card id stays inside the path parameter."""
+ card_id = quote("runware/music", safe="")
+
+ response = self._client.get(
+ f"/hub/skill/fakeskills/cards/{card_id}",
+ headers=HEADERS,
+ )
+
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.json()["id"], "runware/music")
+
# ── install: MCP ──────────────────────────────────────────────
def _install_mcp(self, card_id: str, **body: Any) -> Any:
@@ -698,6 +719,15 @@ class HubRouterTest(IsolatedAsyncioTestCase):
self.assertEqual(listed[0]["hub_id"], "fakeskills")
self.assertEqual(listed[0]["card_id"], "gifgrep")
+ def test_installs_owner_scoped_skill_card(self) -> None:
+ """An owner-scoped card id is accepted by the install route."""
+ card_id = quote("runware/music", safe="")
+
+ response = self._install_skill(card_id)
+
+ self.assertEqual(response.status_code, 201)
+ self.assertEqual(response.json()["card_id"], "runware/music")
+
def test_install_snapshots_the_display_identity(self) -> None:
"""Author, icon and link survive the install, so the library
does not lose the listing's identity the moment it is added."""