forked from davila7/claude-code-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_agents_api.py
More file actions
65 lines (52 loc) · 2.15 KB
/
generate_agents_api.py
File metadata and controls
65 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Generate a lightweight agents API endpoint from components.json
This creates docs/api/agents.json for the CLI tool to use
"""
import json
import os
def generate_agents_api():
"""Generate the agents API file from components.json"""
# Read the components.json file
components_path = 'docs/components.json'
output_path = 'docs/api/agents.json'
if not os.path.exists(components_path):
print(f"Error: {components_path} not found")
return False
try:
with open(components_path, 'r', encoding='utf-8') as f:
components_data = json.load(f)
# Extract agents and format them for the API
agents = []
if 'agents' in components_data:
for agent in components_data['agents']:
# Extract category from path
path_parts = agent['path'].split('/')
category = path_parts[0] if len(path_parts) > 1 else 'root'
name = path_parts[-1]
# Remove .md extension from name if present
if name.endswith('.md'):
name = name[:-3]
agents.append({
'name': name,
'path': agent['path'].replace('.md', ''), # Remove .md from path too
'category': category,
'description': agent.get('description', '')[:100] # Truncate description for size
})
# Create output directory if it doesn't exist
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# Write the API file
with open(output_path, 'w', encoding='utf-8') as f:
json.dump({
'agents': agents,
'version': '1.0.0',
'total': len(agents)
}, f, indent=2)
print(f"✅ Generated agents API with {len(agents)} agents")
print(f"📄 Output: {output_path}")
return True
except Exception as e:
print(f"Error generating agents API: {e}")
return False
if __name__ == '__main__':
generate_agents_api()