Coverage for agentos/desktop/skill_store_server.py: 0%
96 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-06 10:59 +0800
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-06 10:59 +0800
1"""
2Skill Store Server — Web-based skill marketplace with embedded browser support.
4Serves a local web UI that lists skills from multiple sources (OpenClaw, ClawHub,
5SkillsMP, LobeHub, etc.) and provides one-click install via the marketplace importer.
7Architecture:
8 - FastAPI server (localhost:18900 by default)
9 - Web UI with embedded iframe links to external skill stores
10 - REST API: GET /api/skills, POST /api/install, GET /api/sources
11 - WebSocket for real-time install progress
13Usage:
14 agentos skill-store # Start skill store server
15 agentos skill-store --port 18900 # Custom port
16 agentos skill-store --open # Auto-open in browser
18Requirements: pip install fastapi uvicorn aiohttp
19"""
21from __future__ import annotations
23import sys
24import webbrowser
25from pathlib import Path
27try:
28 from fastapi import FastAPI, WebSocket, WebSocketDisconnect
29 from fastapi.responses import HTMLResponse, JSONResponse, FileResponse
30 from fastapi.staticfiles import StaticFiles
31 import uvicorn
32 FASTAPI_AVAILABLE = True
33except ImportError:
34 FASTAPI_AVAILABLE = False
37# ── Constants ──
38DEFAULT_PORT = 18900
39STATIC_DIR = Path(__file__).parent / "static"
41SKILL_SOURCES: list[dict] = [
42 {
43 "id": "openclaw",
44 "name": "OpenClaw Skill Store",
45 "url": "https://github.com/nicepkg/openclaw-skill-store",
46 "web_url": "https://github.com/nicepkg/openclaw-skill-store/tree/main/skills",
47 "description": "OpenClaw 官方社区技能商店,14+ 核心技能",
48 "skill_count": "14+",
49 "icon": "openclaw",
50 "tags": ["官方", "社区", "文档处理"],
51 "installable": True,
52 "source_type": "openclaw",
53 },
54 {
55 "id": "clawhub",
56 "name": "ClawHub",
57 "url": "https://github.com/clawhub-community/skills",
58 "web_url": "https://github.com/clawhub-community/skills",
59 "description": "ClawHub 社区技能聚合,5,700+ 技能",
60 "skill_count": "5,700+",
61 "icon": "clawhub",
62 "tags": ["社区", "聚合", "高质量"],
63 "installable": False,
64 "source_type": "github",
65 },
66 {
67 "id": "skillsmp",
68 "name": "SkillsMP",
69 "url": "https://skills.mp/",
70 "web_url": "https://skills.mp/",
71 "description": "技能界的 Google,164 万技能文件索引",
72 "skill_count": "164万+",
73 "icon": "skillsmp",
74 "tags": ["索引", "搜索", "规模最大"],
75 "installable": False,
76 "source_type": "web",
77 },
78 {
79 "id": "lobehub",
80 "name": "LobeHub Skills",
81 "url": "https://lobehub.com/skills",
82 "web_url": "https://lobehub.com/skills",
83 "description": "LobeHub 生态精品技能平台,28 万+",
84 "skill_count": "28万+",
85 "icon": "lobehub",
86 "tags": ["精品", "集成", "多模态"],
87 "installable": False,
88 "source_type": "web",
89 },
90 {
91 "id": "skillhub",
92 "name": "SkillHub Club",
93 "url": "https://skillhub.club/",
94 "web_url": "https://skillhub.club/",
95 "description": "AI 评分驱动的品质筛选市集",
96 "skill_count": "1.6万+",
97 "icon": "skillhub",
98 "tags": ["品质", "AI评分", "精选"],
99 "installable": False,
100 "source_type": "web",
101 },
102 {
103 "id": "skills_sh",
104 "name": "skills.sh",
105 "url": "https://skills.sh/",
106 "web_url": "https://skills.sh/",
107 "description": "Vercel Labs 运营,npx skills add 一键安装",
108 "skill_count": "67万+",
109 "icon": "skills_sh",
110 "tags": ["一键安装", "CLI", "多平台"],
111 "installable": False,
112 "source_type": "web",
113 },
114 {
115 "id": "awesome_agent_skills",
116 "name": "awesome-agent-skills",
117 "url": "https://github.com/nicepkg/awesome-agent-skills",
118 "web_url": "https://github.com/nicepkg/awesome-agent-skills",
119 "description": "人工审核的优质技能合集,380+ 精选",
120 "skill_count": "380+",
121 "icon": "awesome",
122 "tags": ["人工审核", "安全", "精选"],
123 "installable": False,
124 "source_type": "github",
125 },
126]
128# Known OpenClaw skills (from importer catalog + community)
129OPENCLAW_SKILLS: list[dict] = [
130 {"name": "skill-creator", "description": "Create new skills from templates", "tags": ["meta", "development"]},
131 {"name": "pdf-tools", "description": "PDF manipulation, merge, split, extract text", "tags": ["document", "pdf"]},
132 {"name": "xlsx-tools", "description": "Excel/Spreadsheet creation and editing", "tags": ["document", "excel"]},
133 {"name": "docx-tools", "description": "Word document processing", "tags": ["document", "word"]},
134 {"name": "pptx-tools", "description": "PowerPoint presentation generation", "tags": ["document", "ppt"]},
135 {"name": "image-tools", "description": "Image processing, resize, convert, OCR", "tags": ["media", "image"]},
136 {"name": "web-search", "description": "Advanced web search with multiple engines", "tags": ["search", "web"]},
137 {"name": "browser-automation", "description": "Browser automation with Playwright", "tags": ["browser", "automation"]},
138 {"name": "code-review", "description": "Automated code review and suggestions", "tags": ["code", "quality"]},
139 {"name": "git-tools", "description": "Git workflow automation and helpers", "tags": ["git", "devops"]},
140 {"name": "file-organizer", "description": "Automated file organization and cleanup", "tags": ["files", "automation"]},
141 {"name": "data-analysis", "description": "Data analysis and visualization", "tags": ["data", "analytics"]},
142 {"name": "api-tester", "description": "API testing and documentation generation", "tags": ["api", "testing"]},
143 {"name": "markdown-tools", "description": "Markdown editing, preview, and conversion", "tags": ["document", "markdown"]},
144]
147# ── Server ──
149def create_app() -> FastAPI:
150 """Create the FastAPI application for the skill store."""
151 app = FastAPI(title="NexusAgentOS Skill Store", version="1.7.5")
153 # ── API Routes ──
155 @app.get("/api/sources")
156 async def list_sources():
157 """List all skill sources (marketplaces)."""
158 return JSONResponse(SKILL_SOURCES)
160 @app.get("/api/skills")
161 async def list_skills(source: str = "openclaw", search: str = ""):
162 """List skills from a specific source."""
163 if source == "openclaw":
164 skills = OPENCLAW_SKILLS
165 if search:
166 skills = [
167 s for s in skills
168 if search.lower() in s["name"].lower()
169 or search.lower() in s["description"].lower()
170 or any(search.lower() in t.lower() for t in s.get("tags", []))
171 ]
172 return JSONResponse({
173 "source": "openclaw",
174 "source_name": "OpenClaw Skill Store",
175 "total": len(skills),
176 "skills": skills,
177 })
178 return JSONResponse({
179 "source": source,
180 "total": 0,
181 "skills": [],
182 "message": f"Source '{source}' is not locally installable. Open the marketplace URL to browse.",
183 })
185 @app.post("/api/install")
186 async def install_skill(skill_name: str, source: str = "openclaw"):
187 """Install a skill from a source. Uses the marketplace importer."""
188 try:
189 # Add agentos to path
190 agentos_root = str(Path(__file__).parent.parent.parent)
191 if agentos_root not in sys.path:
192 sys.path.insert(0, agentos_root)
194 from agentos.marketplace.importer import OpenClawImporter
195 from agentos.marketplace.registry import SkillRegistry
197 install_dir = Path.home() / ".agentos" / "skills"
198 registry = SkillRegistry(install_dir=str(install_dir))
200 if source == "openclaw":
201 importer = OpenClawImporter(registry)
202 skill = await importer.import_skill(skill_name)
203 if skill:
204 return JSONResponse({
205 "status": "installed",
206 "skill": skill_name,
207 "path": str(skill.path) if hasattr(skill, 'path') else str(install_dir / skill_name),
208 })
209 return JSONResponse({
210 "status": "failed",
211 "skill": skill_name,
212 "error": "Skill not found in OpenClaw store",
213 }, status_code=404)
215 return JSONResponse({
216 "status": "not_installable",
217 "skill": skill_name,
218 "message": f"Source '{source}' requires manual installation.",
219 })
220 except Exception as e:
221 return JSONResponse({
222 "status": "error",
223 "skill": skill_name,
224 "error": str(e),
225 }, status_code=500)
227 @app.post("/api/install-all")
228 async def install_all(source: str = "openclaw"):
229 """Batch install all skills from a source."""
230 try:
231 agentos_root = str(Path(__file__).parent.parent.parent)
232 if agentos_root not in sys.path:
233 sys.path.insert(0, agentos_root)
235 from agentos.marketplace.importer import OpenClawImporter
236 from agentos.marketplace.registry import SkillRegistry
238 install_dir = Path.home() / ".agentos" / "skills"
239 registry = SkillRegistry(install_dir=str(install_dir))
241 if source == "openclaw":
242 importer = OpenClawImporter(registry)
243 results = await importer.import_all()
244 return JSONResponse({
245 "status": "completed",
246 "total": len(results),
247 "installed": [r.get("name", "") for r in results],
248 "failed": [],
249 })
251 return JSONResponse({"status": "error", "error": f"Cannot batch install from {source}"}, status_code=400)
252 except Exception as e:
253 return JSONResponse({"status": "error", "error": str(e)}, status_code=500)
255 @app.get("/api/health")
256 async def health():
257 return {"status": "ok", "version": "1.7.5"}
259 # ── Static Files ──
260 if STATIC_DIR.exists():
261 app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
263 @app.get("/", response_class=HTMLResponse)
264 async def index():
265 """Serve the skill store web UI."""
266 html_path = STATIC_DIR / "index.html"
267 if html_path.exists():
268 return FileResponse(str(html_path), media_type="text/html")
269 return HTMLResponse(_FALLBACK_HTML)
271 return app
274# ── Fallback HTML (when static/index.html is missing) ──
275_FALLBACK_HTML = """<!DOCTYPE html>
276<html lang="zh-CN">
277<head>
278<meta charset="UTF-8">
279<meta name="viewport" content="width=device-width, initial-scale=1.0">
280<title>NexusAgentOS Skill Store</title>
281<style>
282 :root { --bg: #0d1117; --card: #161b22; --border: #30363d; --text: #c9d1d9; --accent: #58a6ff; }
283 * { margin: 0; padding: 0; box-sizing: border-box; }
284 body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 2rem; }
285 h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
286 .subtitle { color: #8b949e; margin-bottom: 2rem; }
287 .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; }
288 .card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; }
289 .card h2 { font-size: 1rem; color: var(--accent); margin-bottom: 0.5rem; }
290 .card p { font-size: 0.875rem; color: #8b949e; margin-bottom: 0.75rem; }
291 .tags { display: flex; gap: 0.375rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
292 .tag { background: #1f6feb22; color: var(--accent); padding: 0.125rem 0.5rem; border-radius: 12px; font-size: 0.75rem; }
293 .btn { display: inline-block; padding: 0.5rem 1rem; border-radius: 6px; font-size: 0.875rem; cursor: pointer; border: 1px solid var(--border); text-decoration: none; }
294 .btn-primary { background: #238636; border-color: #238636; color: #fff; }
295 .btn-outline { background: transparent; color: var(--text); }
296 .btn-outline:hover { background: #30363d; }
297 .count { font-size: 0.75rem; color: #8b949e; }
298</style>
299</head>
300<body>
301<h1>NexusAgentOS Skill Store</h1>
302<p class="subtitle">从社区市场发现和安装技能。启动完整 UI:pip install textual && agentos tui --market</p>
303<div class="grid" id="sources"></div>
304<script>
305 fetch('/api/sources').then(r => r.json()).then(sources => {
306 const grid = document.getElementById('sources');
307 sources.forEach(s => {
308 const card = document.createElement('div');
309 card.className = 'card';
310 card.innerHTML = `<h2>${s.name} <span class="count">(${s.skill_count})</span></h2>
311 <p>${s.description}</p>
312 <div class="tags">${s.tags.map(t => `<span class="tag">${t}</span>`).join('')}</div>
313 ${s.installable
314 ? `<button class="btn btn-primary" onclick="installAll('${s.id}')">安装全部</button>`
315 : `<a href="${s.web_url}" target="_blank" class="btn btn-outline">打开市场</a>`}`;
316 grid.appendChild(card);
317 });
318 });
319 function installAll(src) {
320 fetch('/api/install-all?source=' + src, { method: 'POST' })
321 .then(r => r.json()).then(d => alert('安装完成: ' + d.installed?.length + ' 个技能'));
322 }
323</script>
324</body>
325</html>"""
328# ── Entry Point ──
330def launch_skill_store(
331 port: int = DEFAULT_PORT,
332 host: str = "127.0.0.1",
333 open_browser: bool = False,
334) -> None:
335 """Launch the skill store web server.
337 Args:
338 port: HTTP port to listen on.
339 host: Host to bind to.
340 open_browser: Auto-open in system browser.
341 """
342 if not FASTAPI_AVAILABLE:
343 print("ERROR: fastapi/uvicorn not installed. Run: pip install fastapi uvicorn")
344 return
346 app = create_app()
348 url = f"http://{host}:{port}"
349 print(f"NexusAgentOS Skill Store starting at {url}")
351 if open_browser:
352 webbrowser.open(url)
354 uvicorn.run(app, host=host, port=port, log_level="info")
357if __name__ == "__main__":
358 import argparse
359 parser = argparse.ArgumentParser(description="NexusAgentOS Skill Store Server")
360 parser.add_argument("--port", type=int, default=DEFAULT_PORT, help="Server port")
361 parser.add_argument("--host", default="127.0.0.1", help="Server host")
362 parser.add_argument("--open", action="store_true", dest="open_browser", help="Open in browser")
363 args = parser.parse_args()
364 launch_skill_store(port=args.port, host=args.host, open_browser=args.open_browser)