- 新增'📱 外部应用'卡片,显示飞书应用信息 * 应用名称和图标 * 应用 ID(等宽字体显示) * 一键复制按钮 * 未配置应用显示友好提示 - 优化工作区路径显示 * 代码样式(等宽字体 + 背景色) * 添加'📋 复制'按钮 * 复制成功有提示消息 - 后端添加龙虾应用配置 * 飞行侠:IT 项目推广运营平台 (cli_a92413cfb0791bce) * 道童:道德经新解 (cli_a9439b614f38dbd2) * 其他龙虾:未配置 - 样式优化 * 绿色渐变复制按钮 * 悬停动画效果 * 响应式布局 📱 让重要信息一键可复制
154 lines
5.6 KiB
Python
154 lines
5.6 KiB
Python
"""
|
|
API views for lobster monitoring.
|
|
"""
|
|
from rest_framework.decorators import api_view
|
|
from rest_framework.response import Response
|
|
from datetime import datetime
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
|
|
# 龙虾配置
|
|
LOBSTERS = [
|
|
{'id': 1, 'name': '飞行侠', 'emoji': '🦸', 'port': 18789, 'specialty': '主力/通用', 'container': 'openclaw-instance2', 'app_name': 'IT 项目推广运营平台', 'app_id': 'cli_a92413cfb0791bce'},
|
|
{'id': 2, 'name': '道童', 'emoji': '☯️', 'port': 18889, 'specialty': '道德经注解', 'container': 'openclaw-gateway-2', 'app_name': '道德经新解', 'app_id': 'cli_a9439b614f38dbd2'},
|
|
{'id': 3, 'name': '墨子', 'emoji': '🔧', 'port': 18689, 'specialty': '代码专家', 'container': 'openclaw-coder', 'app_name': '未配置', 'app_id': ''},
|
|
{'id': 4, 'name': '织网者', 'emoji': '🕸️', 'port': 18589, 'specialty': '网站制作', 'container': 'openclaw-web', 'app_name': '未配置', 'app_id': ''},
|
|
{'id': 5, 'name': '费曼', 'emoji': '⚛️', 'port': 18989, 'specialty': '物理研究', 'container': 'openclaw-physics', 'app_name': '未配置', 'app_id': ''},
|
|
{'id': 6, 'name': '守望者', 'emoji': '👁️', 'port': 18080, 'specialty': '舰队监控', 'container': 'openclaw-watcher', 'app_name': '未配置', 'app_id': ''},
|
|
]
|
|
|
|
@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)
|
|
|
|
@api_view(['GET'])
|
|
def lobster_memory_dates(request, lobster_id):
|
|
"""获取龙虾有日记的日期列表"""
|
|
# 获取龙虾工作区
|
|
lobster_map = {
|
|
1: 'flying-hero',
|
|
2: 'daotong',
|
|
3: 'coder',
|
|
4: 'web',
|
|
5: 'physics',
|
|
6: 'watcher',
|
|
}
|
|
|
|
lobster_name = lobster_map.get(lobster_id)
|
|
if not lobster_name:
|
|
return Response({'error': '龙虾不存在'}, status=404)
|
|
|
|
# 记忆文件目录
|
|
memory_dir = Path(f'/home/node/.openclaw/workspace/flying-hero/memory')
|
|
|
|
# 获取所有日记文件
|
|
dates = []
|
|
if memory_dir.exists():
|
|
for file in memory_dir.glob('*.md'):
|
|
# 提取日期 (YYYY-MM-DD.md)
|
|
match = re.match(r'(\d{4}-\d{2}-\d{2})\.md', file.name)
|
|
if match:
|
|
dates.append(match.group(1))
|
|
|
|
dates.sort(reverse=True)
|
|
return Response({'dates': dates})
|
|
|
|
@api_view(['GET'])
|
|
def lobster_memory_detail(request, lobster_id, date):
|
|
"""获取指定日期的日记内容"""
|
|
memory_file = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/{date}.md')
|
|
|
|
if not memory_file.exists():
|
|
return Response({'error': '该日期没有日记'}, status=404)
|
|
|
|
content = memory_file.read_text(encoding='utf-8')
|
|
return Response({
|
|
'date': date,
|
|
'content': content
|
|
})
|
|
|
|
@api_view(['GET'])
|
|
def lobster_diary_dates(request, lobster_id):
|
|
"""获取龙虾有日记(成才之路)的日期列表"""
|
|
# 日记文件目录
|
|
diary_dir = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/成才之路')
|
|
|
|
# 获取所有日记文件
|
|
dates = []
|
|
if diary_dir.exists():
|
|
for file in diary_dir.glob('*.md'):
|
|
# 提取日期 (YYYY-MM-DD.md 或 YYYY-MM-DD-*.md)
|
|
match = re.match(r'(\d{4}-\d{2}-\d{2})(?:-.*)?\.md', file.name)
|
|
if match:
|
|
dates.append(match.group(1))
|
|
|
|
dates = list(set(dates)) # 去重
|
|
dates.sort(reverse=True)
|
|
return Response({'dates': dates})
|
|
|
|
@api_view(['GET'])
|
|
def lobster_diary_detail(request, lobster_id, date):
|
|
"""获取指定日期的日记内容(成才之路)"""
|
|
# 优先查找故事版,其次技术版,再其次普通版
|
|
diary_file = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/成才之路/{date}-故事版.md')
|
|
if not diary_file.exists():
|
|
diary_file = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/成才之路/{date}-技术版.md')
|
|
if not diary_file.exists():
|
|
diary_file = Path(f'/home/node/.openclaw/workspace/flying-hero/memory/成才之路/{date}.md')
|
|
|
|
if not diary_file.exists():
|
|
return Response({'error': '该日期没有日记'}, status=404)
|
|
|
|
content = diary_file.read_text(encoding='utf-8')
|
|
return Response({
|
|
'date': date,
|
|
'content': content
|
|
})
|