Coverage for agentos/desktop/skill_store_server.py: 0%

96 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-06 12:29 +0800

1""" 

2Skill Store Server — Web-based skill marketplace with embedded browser support. 

3 

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. 

6 

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 

12 

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 

17 

18Requirements: pip install fastapi uvicorn aiohttp 

19""" 

20 

21from __future__ import annotations 

22 

23import sys 

24import webbrowser 

25from pathlib import Path 

26 

27try: 

28 import uvicorn 

29 from fastapi import FastAPI 

30 from fastapi.responses import FileResponse, HTMLResponse, JSONResponse 

31 from fastapi.staticfiles import StaticFiles 

32 

33 FASTAPI_AVAILABLE = True 

34except ImportError: 

35 FASTAPI_AVAILABLE = False 

36 

37 

38# ── Constants ── 

39DEFAULT_PORT = 18900 

40STATIC_DIR = Path(__file__).parent / "static" 

41 

42SKILL_SOURCES: list[dict] = [ 

43 { 

44 "id": "openclaw", 

45 "name": "OpenClaw Skill Store", 

46 "url": "https://github.com/nicepkg/openclaw-skill-store", 

47 "web_url": "https://github.com/nicepkg/openclaw-skill-store/tree/main/skills", 

48 "description": "OpenClaw 官方社区技能商店,14+ 核心技能", 

49 "skill_count": "14+", 

50 "icon": "openclaw", 

51 "tags": ["官方", "社区", "文档处理"], 

52 "installable": True, 

53 "source_type": "openclaw", 

54 }, 

55 { 

56 "id": "clawhub", 

57 "name": "ClawHub", 

58 "url": "https://github.com/clawhub-community/skills", 

59 "web_url": "https://github.com/clawhub-community/skills", 

60 "description": "ClawHub 社区技能聚合,5,700+ 技能", 

61 "skill_count": "5,700+", 

62 "icon": "clawhub", 

63 "tags": ["社区", "聚合", "高质量"], 

64 "installable": False, 

65 "source_type": "github", 

66 }, 

67 { 

68 "id": "skillsmp", 

69 "name": "SkillsMP", 

70 "url": "https://skills.mp/", 

71 "web_url": "https://skills.mp/", 

72 "description": "技能界的 Google,164 万技能文件索引", 

73 "skill_count": "164万+", 

74 "icon": "skillsmp", 

75 "tags": ["索引", "搜索", "规模最大"], 

76 "installable": False, 

77 "source_type": "web", 

78 }, 

79 { 

80 "id": "lobehub", 

81 "name": "LobeHub Skills", 

82 "url": "https://lobehub.com/skills", 

83 "web_url": "https://lobehub.com/skills", 

84 "description": "LobeHub 生态精品技能平台,28 万+", 

85 "skill_count": "28万+", 

86 "icon": "lobehub", 

87 "tags": ["精品", "集成", "多模态"], 

88 "installable": False, 

89 "source_type": "web", 

90 }, 

91 { 

92 "id": "skillhub", 

93 "name": "SkillHub Club", 

94 "url": "https://skillhub.club/", 

95 "web_url": "https://skillhub.club/", 

96 "description": "AI 评分驱动的品质筛选市集", 

97 "skill_count": "1.6万+", 

98 "icon": "skillhub", 

99 "tags": ["品质", "AI评分", "精选"], 

100 "installable": False, 

101 "source_type": "web", 

102 }, 

103 { 

104 "id": "skills_sh", 

105 "name": "skills.sh", 

106 "url": "https://skills.sh/", 

107 "web_url": "https://skills.sh/", 

108 "description": "Vercel Labs 运营,npx skills add 一键安装", 

109 "skill_count": "67万+", 

110 "icon": "skills_sh", 

111 "tags": ["一键安装", "CLI", "多平台"], 

112 "installable": False, 

113 "source_type": "web", 

114 }, 

115 { 

116 "id": "awesome_agent_skills", 

117 "name": "awesome-agent-skills", 

118 "url": "https://github.com/nicepkg/awesome-agent-skills", 

119 "web_url": "https://github.com/nicepkg/awesome-agent-skills", 

120 "description": "人工审核的优质技能合集,380+ 精选", 

121 "skill_count": "380+", 

122 "icon": "awesome", 

123 "tags": ["人工审核", "安全", "精选"], 

124 "installable": False, 

125 "source_type": "github", 

126 }, 

127] 

128 

129# Known OpenClaw skills (from importer catalog + community) 

130OPENCLAW_SKILLS: list[dict] = [ 

131 { 

132 "name": "skill-creator", 

133 "description": "Create new skills from templates", 

134 "tags": ["meta", "development"], 

135 }, 

136 { 

137 "name": "pdf-tools", 

138 "description": "PDF manipulation, merge, split, extract text", 

139 "tags": ["document", "pdf"], 

140 }, 

141 { 

142 "name": "xlsx-tools", 

143 "description": "Excel/Spreadsheet creation and editing", 

144 "tags": ["document", "excel"], 

145 }, 

146 {"name": "docx-tools", "description": "Word document processing", "tags": ["document", "word"]}, 

147 { 

148 "name": "pptx-tools", 

149 "description": "PowerPoint presentation generation", 

150 "tags": ["document", "ppt"], 

151 }, 

152 { 

153 "name": "image-tools", 

154 "description": "Image processing, resize, convert, OCR", 

155 "tags": ["media", "image"], 

156 }, 

157 { 

158 "name": "web-search", 

159 "description": "Advanced web search with multiple engines", 

160 "tags": ["search", "web"], 

161 }, 

162 { 

163 "name": "browser-automation", 

164 "description": "Browser automation with Playwright", 

165 "tags": ["browser", "automation"], 

166 }, 

167 { 

168 "name": "code-review", 

169 "description": "Automated code review and suggestions", 

170 "tags": ["code", "quality"], 

171 }, 

172 { 

173 "name": "git-tools", 

174 "description": "Git workflow automation and helpers", 

175 "tags": ["git", "devops"], 

176 }, 

177 { 

178 "name": "file-organizer", 

179 "description": "Automated file organization and cleanup", 

180 "tags": ["files", "automation"], 

181 }, 

182 { 

183 "name": "data-analysis", 

184 "description": "Data analysis and visualization", 

185 "tags": ["data", "analytics"], 

186 }, 

187 { 

188 "name": "api-tester", 

189 "description": "API testing and documentation generation", 

190 "tags": ["api", "testing"], 

191 }, 

192 { 

193 "name": "markdown-tools", 

194 "description": "Markdown editing, preview, and conversion", 

195 "tags": ["document", "markdown"], 

196 }, 

197] 

198 

199 

200# ── Server ── 

201 

202 

203def create_app() -> FastAPI: 

204 """Create the FastAPI application for the skill store.""" 

205 app = FastAPI(title="NexusAgentOS Skill Store", version="1.7.5") 

206 

207 # ── API Routes ── 

208 

209 @app.get("/api/sources") 

210 async def list_sources(): 

211 """List all skill sources (marketplaces).""" 

212 return JSONResponse(SKILL_SOURCES) 

213 

214 @app.get("/api/skills") 

215 async def list_skills(source: str = "openclaw", search: str = ""): 

216 """List skills from a specific source.""" 

217 if source == "openclaw": 

218 skills = OPENCLAW_SKILLS 

219 if search: 

220 skills = [ 

221 s 

222 for s in skills 

223 if search.lower() in s["name"].lower() 

224 or search.lower() in s["description"].lower() 

225 or any(search.lower() in t.lower() for t in s.get("tags", [])) 

226 ] 

227 return JSONResponse( 

228 { 

229 "source": "openclaw", 

230 "source_name": "OpenClaw Skill Store", 

231 "total": len(skills), 

232 "skills": skills, 

233 } 

234 ) 

235 return JSONResponse( 

236 { 

237 "source": source, 

238 "total": 0, 

239 "skills": [], 

240 "message": f"Source '{source}' is not locally installable. Open the marketplace URL to browse.", 

241 } 

242 ) 

243 

244 @app.post("/api/install") 

245 async def install_skill(skill_name: str, source: str = "openclaw"): 

246 """Install a skill from a source. Uses the marketplace importer.""" 

247 try: 

248 # Add agentos to path 

249 agentos_root = str(Path(__file__).parent.parent.parent) 

250 if agentos_root not in sys.path: 

251 sys.path.insert(0, agentos_root) 

252 

253 from agentos.marketplace.importer import OpenClawImporter 

254 from agentos.marketplace.registry import SkillRegistry 

255 

256 install_dir = Path.home() / ".agentos" / "skills" 

257 registry = SkillRegistry(install_dir=str(install_dir)) 

258 

259 if source == "openclaw": 

260 importer = OpenClawImporter(registry) 

261 skill = await importer.import_skill(skill_name) 

262 if skill: 

263 return JSONResponse( 

264 { 

265 "status": "installed", 

266 "skill": skill_name, 

267 "path": ( 

268 str(skill.path) 

269 if hasattr(skill, "path") 

270 else str(install_dir / skill_name) 

271 ), 

272 } 

273 ) 

274 return JSONResponse( 

275 { 

276 "status": "failed", 

277 "skill": skill_name, 

278 "error": "Skill not found in OpenClaw store", 

279 }, 

280 status_code=404, 

281 ) 

282 

283 return JSONResponse( 

284 { 

285 "status": "not_installable", 

286 "skill": skill_name, 

287 "message": f"Source '{source}' requires manual installation.", 

288 } 

289 ) 

290 except Exception as e: 

291 return JSONResponse( 

292 { 

293 "status": "error", 

294 "skill": skill_name, 

295 "error": str(e), 

296 }, 

297 status_code=500, 

298 ) 

299 

300 @app.post("/api/install-all") 

301 async def install_all(source: str = "openclaw"): 

302 """Batch install all skills from a source.""" 

303 try: 

304 agentos_root = str(Path(__file__).parent.parent.parent) 

305 if agentos_root not in sys.path: 

306 sys.path.insert(0, agentos_root) 

307 

308 from agentos.marketplace.importer import OpenClawImporter 

309 from agentos.marketplace.registry import SkillRegistry 

310 

311 install_dir = Path.home() / ".agentos" / "skills" 

312 registry = SkillRegistry(install_dir=str(install_dir)) 

313 

314 if source == "openclaw": 

315 importer = OpenClawImporter(registry) 

316 results = await importer.import_all() 

317 return JSONResponse( 

318 { 

319 "status": "completed", 

320 "total": len(results), 

321 "installed": [r.get("name", "") for r in results], 

322 "failed": [], 

323 } 

324 ) 

325 

326 return JSONResponse( 

327 {"status": "error", "error": f"Cannot batch install from {source}"}, status_code=400 

328 ) 

329 except Exception as e: 

330 return JSONResponse({"status": "error", "error": str(e)}, status_code=500) 

331 

332 @app.get("/api/health") 

333 async def health(): 

334 return {"status": "ok", "version": "1.7.5"} 

335 

336 # ── Static Files ── 

337 if STATIC_DIR.exists(): 

338 app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static") 

339 

340 @app.get("/", response_class=HTMLResponse) 

341 async def index(): 

342 """Serve the skill store web UI.""" 

343 html_path = STATIC_DIR / "index.html" 

344 if html_path.exists(): 

345 return FileResponse(str(html_path), media_type="text/html") 

346 return HTMLResponse(_FALLBACK_HTML) 

347 

348 return app 

349 

350 

351# ── Fallback HTML (when static/index.html is missing) ── 

352_FALLBACK_HTML = """<!DOCTYPE html> 

353<html lang="zh-CN"> 

354<head> 

355<meta charset="UTF-8"> 

356<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

357<title>NexusAgentOS Skill Store</title> 

358<style> 

359 :root { --bg: #0d1117; --card: #161b22; --border: #30363d; --text: #c9d1d9; --accent: #58a6ff; } 

360 * { margin: 0; padding: 0; box-sizing: border-box; } 

361 body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 2rem; } 

362 h1 { font-size: 1.5rem; margin-bottom: 0.5rem; } 

363 .subtitle { color: #8b949e; margin-bottom: 2rem; } 

364 .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; } 

365 .card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; } 

366 .card h2 { font-size: 1rem; color: var(--accent); margin-bottom: 0.5rem; } 

367 .card p { font-size: 0.875rem; color: #8b949e; margin-bottom: 0.75rem; } 

368 .tags { display: flex; gap: 0.375rem; flex-wrap: wrap; margin-bottom: 0.75rem; } 

369 .tag { background: #1f6feb22; color: var(--accent); padding: 0.125rem 0.5rem; border-radius: 12px; font-size: 0.75rem; } 

370 .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; } 

371 .btn-primary { background: #238636; border-color: #238636; color: #fff; } 

372 .btn-outline { background: transparent; color: var(--text); } 

373 .btn-outline:hover { background: #30363d; } 

374 .count { font-size: 0.75rem; color: #8b949e; } 

375</style> 

376</head> 

377<body> 

378<h1>NexusAgentOS Skill Store</h1> 

379<p class="subtitle">从社区市场发现和安装技能。启动完整 UI:pip install textual && agentos tui --market</p> 

380<div class="grid" id="sources"></div> 

381<script> 

382 fetch('/api/sources').then(r => r.json()).then(sources => { 

383 const grid = document.getElementById('sources'); 

384 sources.forEach(s => { 

385 const card = document.createElement('div'); 

386 card.className = 'card'; 

387 card.innerHTML = `<h2>${s.name} <span class="count">(${s.skill_count})</span></h2> 

388 <p>${s.description}</p> 

389 <div class="tags">${s.tags.map(t => `<span class="tag">${t}</span>`).join('')}</div> 

390 ${s.installable 

391 ? `<button class="btn btn-primary" onclick="installAll('${s.id}')">安装全部</button>` 

392 : `<a href="${s.web_url}" target="_blank" class="btn btn-outline">打开市场</a>`}`; 

393 grid.appendChild(card); 

394 }); 

395 }); 

396 function installAll(src) { 

397 fetch('/api/install-all?source=' + src, { method: 'POST' }) 

398 .then(r => r.json()).then(d => alert('安装完成: ' + d.installed?.length + ' 个技能')); 

399 } 

400</script> 

401</body> 

402</html>""" 

403 

404 

405# ── Entry Point ── 

406 

407 

408def launch_skill_store( 

409 port: int = DEFAULT_PORT, 

410 host: str = "127.0.0.1", 

411 open_browser: bool = False, 

412) -> None: 

413 """Launch the skill store web server. 

414 

415 Args: 

416 port: HTTP port to listen on. 

417 host: Host to bind to. 

418 open_browser: Auto-open in system browser. 

419 """ 

420 if not FASTAPI_AVAILABLE: 

421 print("ERROR: fastapi/uvicorn not installed. Run: pip install fastapi uvicorn") 

422 return 

423 

424 app = create_app() 

425 

426 url = f"http://{host}:{port}" 

427 print(f"NexusAgentOS Skill Store starting at {url}") 

428 

429 if open_browser: 

430 webbrowser.open(url) 

431 

432 uvicorn.run(app, host=host, port=port, log_level="info") 

433 

434 

435if __name__ == "__main__": 

436 import argparse 

437 

438 parser = argparse.ArgumentParser(description="NexusAgentOS Skill Store Server") 

439 parser.add_argument("--port", type=int, default=DEFAULT_PORT, help="Server port") 

440 parser.add_argument("--host", default="127.0.0.1", help="Server host") 

441 parser.add_argument("--open", action="store_true", dest="open_browser", help="Open in browser") 

442 args = parser.parse_args() 

443 launch_skill_store(port=args.port, host=args.host, open_browser=args.open_browser)