|
1 | | -import asyncio |
2 | 1 | import pathlib |
3 | 2 | import typing as t |
4 | 3 |
|
| 4 | +import requests |
5 | 5 | import typer |
6 | 6 | from termcolor import colored |
7 | 7 |
|
|
20 | 20 |
|
21 | 21 | @cli.command( |
22 | 22 | context_settings={"help_option_names": ["-h", "--help"]}, |
23 | | - help="List the agents available locally in $HOME/.nerve/agents or a custom path.", |
| 23 | + help="List locally installed agents and available ones from the awesomeagents.ai index.", |
24 | 24 | ) |
25 | 25 | def agents( |
26 | 26 | path: t.Annotated[ |
27 | 27 | pathlib.Path, |
28 | 28 | typer.Argument(help="Path to the agent or workflow to create"), |
29 | 29 | ] = DEFAULT_AGENTS_LOAD_PATH, |
| 30 | + offline: t.Annotated[ |
| 31 | + bool, |
| 32 | + typer.Option("--offline", "-o", help="Only show installed agents."), |
| 33 | + ] = False, |
30 | 34 | ) -> None: |
31 | 35 | print(f"🧠 nerve v{nerve.__version__}") |
32 | 36 |
|
33 | | - asyncio.run(show_agents(path)) |
| 37 | + _show_installed_agents(path) |
34 | 38 |
|
| 39 | + if not offline: |
| 40 | + agents = _fetch_awesome_agents() |
| 41 | + if agents: |
| 42 | + _show_awesome_agents(agents) |
35 | 43 |
|
36 | | -async def show_agents(path: pathlib.Path) -> None: |
| 44 | + |
| 45 | +def _fetch_awesome_agents() -> list[dict] | None: |
| 46 | + try: |
| 47 | + response = requests.get("https://api.awesomeagents.ai/index.json") |
| 48 | + response.raise_for_status() |
| 49 | + agents = response.json() |
| 50 | + return [agent for agent in agents if "nerve" in agent.get("stack", [])] |
| 51 | + except Exception: |
| 52 | + return None |
| 53 | + |
| 54 | + |
| 55 | +def _show_awesome_agents(agents: list[dict]) -> None: |
| 56 | + print("🔍 Available from the index:\n") |
| 57 | + for agent in agents: |
| 58 | + repo = agent["repo"] |
| 59 | + # Extract username/repo from the repository URL |
| 60 | + repo_parts = repo.split("/") |
| 61 | + if len(repo_parts) >= 2: |
| 62 | + username_repo = f"{repo_parts[-2]}/{repo_parts[-1]}" |
| 63 | + else: |
| 64 | + username_repo = repo |
| 65 | + print(f" {colored(username_repo, 'white', attrs=['bold'])} - {agent['description']}") |
| 66 | + |
| 67 | + print() |
| 68 | + |
| 69 | + |
| 70 | +def _show_installed_agents(path: pathlib.Path) -> None: |
37 | 71 | anything = False |
38 | 72 |
|
39 | 73 | if path.exists() and path.is_dir(): |
40 | 74 | print() |
41 | | - print(f"📁 agents in {path.absolute()}:") |
| 75 | + print(f"📁 Installed in {path.absolute()}:\n") |
42 | 76 |
|
43 | 77 | for item in path.iterdir(): |
44 | 78 | if Workflow.is_workflow(item): |
|
0 commit comments