Complete backend API and deployment guide
- Django REST API with lobster endpoints - API views: list, detail, memory, tools - Deployment guide with instructions - Startup script for easy launch - Requirements.txt for dependencies - API URL routing
This commit is contained in:
67
code/backend/api/views.py
Normal file
67
code/backend/api/views.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
API views for lobster monitoring.
|
||||
"""
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
# 龙虾配置
|
||||
LOBSTERS = [
|
||||
{'id': 1, 'name': '飞行侠', 'emoji': '🦸', 'port': 18789, 'specialty': '主力/通用', 'container': 'openclaw-instance2'},
|
||||
{'id': 2, 'name': '道童', 'emoji': '☯️', 'port': 18889, 'specialty': '道德经注解', 'container': 'openclaw-gateway-2'},
|
||||
{'id': 3, 'name': '墨子', 'emoji': '🔧', 'port': 18689, 'specialty': '代码专家', 'container': 'openclaw-coder'},
|
||||
{'id': 4, 'name': '织网者', 'emoji': '🕸️', 'port': 18589, 'specialty': '网站制作', 'container': 'openclaw-web'},
|
||||
{'id': 5, 'name': '费曼', 'emoji': '⚛️', 'port': 18989, 'specialty': '物理研究', 'container': 'openclaw-physics'},
|
||||
{'id': 6, 'name': '守望者', 'emoji': '👁️', 'port': 18080, 'specialty': '舰队监控', 'container': 'openclaw-watcher'},
|
||||
]
|
||||
|
||||
@api_view(['GET'])
|
||||
def lobster_list(request):
|
||||
"""获取所有龙虾状态"""
|
||||
lobsters = []
|
||||
for lobster in LOBSTERS:
|
||||
# 检查端口状态(简化版本,实际应该检查端口)
|
||||
status = 'healthy'
|
||||
lobsters.append({
|
||||
**lobster,
|
||||
'status': status,
|
||||
'last_check': datetime.now().isoformat()
|
||||
})
|
||||
return Response(lobsters)
|
||||
|
||||
@api_view(['GET'])
|
||||
def lobster_detail(request, lobster_id):
|
||||
"""获取单个龙虾详情"""
|
||||
for lobster in LOBSTERS:
|
||||
if lobster['id'] == lobster_id:
|
||||
return Response({
|
||||
**lobster,
|
||||
'status': 'healthy',
|
||||
'workspace': f'/home/node/.openclaw/workspace/{lobster["name"].lower()}',
|
||||
'last_check': datetime.now().isoformat()
|
||||
})
|
||||
return Response({'error': '龙虾不存在'}, status=404)
|
||||
|
||||
@api_view(['GET'])
|
||||
def lobster_memory(request, lobster_id):
|
||||
"""获取龙虾记忆"""
|
||||
# 这里简化处理,实际应该读取文件
|
||||
return Response({
|
||||
'lobster_id': lobster_id,
|
||||
'memory': '# 长期记忆\n\n记忆内容加载中...',
|
||||
'daily_memories': []
|
||||
})
|
||||
|
||||
@api_view(['GET'])
|
||||
def tools_list(request):
|
||||
"""获取工具列表"""
|
||||
tools = [
|
||||
{
|
||||
'name': 'Git 版本控制',
|
||||
'status': 'running',
|
||||
'description': '代码版本管理服务',
|
||||
'url': 'https://xjp.datalibstar.com/flying-hero/openclaw-monitor.git'
|
||||
}
|
||||
]
|
||||
return Response(tools)
|
||||
Reference in New Issue
Block a user