feat: Add presence heartbeat for Matrix online status

- matrix-gateway: POST /internal/matrix/presence/online endpoint
- usePresenceHeartbeat hook with activity tracking
- Auto away after 5 min inactivity
- Offline on page close/visibility change
- Integrated in MatrixChatRoom component
This commit is contained in:
Apple
2025-11-27 00:19:40 -08:00
parent 5bed515852
commit 3de3c8cb36
6371 changed files with 1317450 additions and 932 deletions

462
HANDOFF_DOCUMENT.md Normal file
View File

@@ -0,0 +1,462 @@
# 🚀 DAARION PROJECT HANDOFF DOCUMENT
**Date:** 2025-11-24
**Current Phase:** Phase 5 — Agent Hub UI (30% Complete)
**Session:** #4
**Project Path:** `/Users/apple/github-projects/microdao-daarion`
---
## 📋 QUICK STATUS:
```
✅ Phase 1: Messenger Module 100% ✅
✅ Phase 2: Agent Integration 100% ✅
✅ Phase 3: LLM + Memory + Tools 100% ✅
✅ Phase 4: Security Layer 100% ✅
✅ Phase 4.5: Real Passkey Auth 100% ✅
🔄 Phase 5: Agent Hub UI 30% 🔄
Total Progress: 85%
```
---
## 🎯 CURRENT TASK: PHASE 5 — AGENT HUB UI
**Goal:** Створити центральний Agent Hub — головний UI для управління агентами DAARION
**Status:** Backend 80% done, Frontend 0% remaining
### ✅ COMPLETED (30%):
#### Backend — agents-service (Port 7014):
1.**models.py** — All data models (agents, metrics, context, events)
2.**main.py** — FastAPI app with 6 endpoints
3.**requirements.txt** — Dependencies
4.**Dockerfile** — Container config
5.**README.md** — API documentation
**Files:** 5 files, ~600 lines
---
### 🔜 REMAINING (70%):
#### Frontend — Agent Hub UI:
6. 🔜 `src/api/agents.ts` — API client
7. 🔜 `src/features/agentHub/hooks/useAgents.ts`
8. 🔜 `src/features/agentHub/hooks/useAgent.ts`
9. 🔜 `src/features/agentHub/hooks/useAgentMetrics.ts`
10. 🔜 `src/features/agentHub/AgentHubPage.tsx`
11. 🔜 `src/features/agentHub/AgentGallery.tsx`
12. 🔜 `src/features/agentHub/AgentCard.tsx`
13. 🔜 `src/features/agentHub/AgentCabinet.tsx`
14. 🔜 `src/features/agentHub/AgentMetricsPanel.tsx`
15. 🔜 `src/features/agentHub/AgentContextPanel.tsx`
16. 🔜 `src/features/agentHub/AgentSettingsPanel.tsx`
#### Integration:
17. 🔜 Add routes to `src/App.tsx`
18. 🔜 Update `docker-compose` (add agents-service)
19. 🔜 Create `docs/AGENT_HUB_SPEC.md`
**Estimate:** 3-4 hours to complete
---
## 📁 PROJECT STRUCTURE:
```
microdao-daarion/
├── services/
│ ├── auth-service/ ✅ Port 7011 (Phase 4)
│ ├── pdp-service/ ✅ Port 7012 (Phase 4)
│ ├── usage-engine/ ✅ Port 7013 (Phase 4)
│ ├── messaging-service/ ✅ Port 7004 (Phase 1)
│ ├── agent-filter/ ✅ Port 7005 (Phase 2)
│ ├── dagi-router/ ✅ Port 7006 (Phase 2)
│ ├── llm-proxy/ ✅ Port 7007 (Phase 3)
│ ├── memory-orchestrator/ ✅ Port 7008 (Phase 3)
│ ├── toolcore/ ✅ Port 7009 (Phase 3)
│ ├── agent-runtime/ ✅ Port 7010 (Phase 2)
│ └── agents-service/ ✅ Port 7014 (Phase 5) ⭐ NEW
├── src/
│ ├── features/
│ │ ├── onboarding/ ✅ (Phase 1)
│ │ ├── city/ ✅ (Earlier phases)
│ │ ├── space-dashboard/ ✅ (Earlier phases)
│ │ ├── messenger/ ✅ (Phase 1)
│ │ ├── auth/ ✅ (Phase 4.5)
│ │ └── agentHub/ 🔜 TO CREATE (Phase 5)
│ │
│ ├── api/
│ │ ├── auth/passkey.ts ✅ (Phase 4.5)
│ │ └── agents.ts 🔜 TO CREATE
│ │
│ ├── store/
│ │ └── authStore.ts ✅ (Phase 4.5)
│ │
│ └── App.tsx 🔜 UPDATE (add /agent-hub routes)
├── migrations/
│ ├── 001-005_*.sql ✅ (Phases 1-4)
│ └── 006_passkey.sql ✅ (Phase 4.5)
├── docs/
│ ├── PHASE4_READY.md ✅
│ ├── PHASE45_READY.md ✅
│ └── AGENT_HUB_SPEC.md 🔜 TO CREATE
└── docker-compose.phase4.yml 🔜 RENAME to phase5.yml + add agents-service
```
---
## 🔧 TECHNICAL CONTEXT:
### Backend Services (Running):
```
✅ PostgreSQL :5432 (Database)
✅ NATS :4222 (Event bus)
✅ auth-service :7011 (Authentication + Passkey)
✅ pdp-service :7012 (Access control)
✅ usage-engine :7013 (Metrics)
✅ messaging-svc :7004 (Messenger + Matrix)
✅ llm-proxy :7007 (LLM calls)
✅ memory-orch :7008 (Agent memory)
✅ toolcore :7009 (Tools)
✅ agent-runtime :7010 (Agent execution)
✅ agents-service :7014 (Agent management) ⭐ NEW
```
### Frontend Stack:
- React 18 + TypeScript
- Vite (dev server)
- React Router
- Zustand (state management)
- Tailwind CSS
### Authentication:
- WebAuthn Passkey (Phase 4.5)
- Session tokens in Zustand + localStorage
- Route guards via `<RequireAuth>`
---
## 🎯 HOW TO CONTINUE:
### Option 1: Complete Phase 5 Frontend
```
"Продовжуй Phase 5 — створи Agent Hub UI"
Створити:
1. src/api/agents.ts (API client)
2. src/features/agentHub/hooks/ (4 hooks)
3. src/features/agentHub/ (6 components)
4. Update App.tsx (routes)
5. Update docker-compose
6. Create AGENT_HUB_SPEC.md
```
### Option 2: Test Current Progress
```
"Запусти agents-service і протестуй API"
cd services/agents-service
pip install -r requirements.txt
python main.py
# Test:
curl http://localhost:7014/agents
curl http://localhost:7014/agents/agent:sofia
curl http://localhost:7014/health
```
### Option 3: Skip to Next Phase
```
"Перейди до Phase 6 — [наступна фіча]"
```
---
## 📚 KEY DOCUMENTS:
### Must-Read Before Continuing:
1. **INFRASTRUCTURE.md** — Full system architecture
2. **PROJECT_CONTEXT.md** — Quick project overview
3. **PHASE4_READY.md** — Security layer details
4. **PHASE45_READY.md** — Passkey auth details
5. **TASK_PHASE4_5_PASSKEY_AUTH.md** — Auth spec
6. **services/agents-service/README.md** — Agents API
### Phase-Specific:
- **PHASE1-3**: Messenger, Agents, LLM stack
- **PHASE4**: auth-service, pdp-service, usage-engine
- **PHASE4.5**: WebAuthn Passkey integration
- **PHASE5**: agents-service (backend done, frontend pending)
---
## 🧪 TESTING:
### Start All Services:
```bash
cd /Users/apple/github-projects/microdao-daarion
# Run Phase 4 services (includes agents-service in future)
./scripts/start-phase4.sh
# Or manually:
docker-compose -f docker-compose.phase4.yml up -d
# Start agents-service separately (Phase 5):
cd services/agents-service
python main.py
```
### Start Frontend:
```bash
npm run dev
# Open: http://localhost:3000
```
### Test Authentication:
```
1. Navigate to /onboarding
2. Create passkey (WebAuthn)
3. Should redirect to /city
4. Auth guard protects routes
```
---
## 🎨 PHASE 5 IMPLEMENTATION GUIDE:
### Step 1: Create API Client
```typescript
// src/api/agents.ts
export async function getAgents(microdaoId?: string) {
const response = await fetch(`${API_URL}/agents?microdao_id=${microdaoId}`, {
headers: {
'Authorization': `Bearer ${sessionToken}`
}
});
return response.json();
}
export async function getAgent(agentId: string) { ... }
export async function getAgentMetrics(agentId: string) { ... }
export async function updateAgentModel(agentId: string, model: string) { ... }
```
### Step 2: Create Hooks
```typescript
// src/features/agentHub/hooks/useAgents.ts
export function useAgents(microdaoId?: string) {
const [agents, setAgents] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
getAgents(microdaoId).then(setAgents).finally(() => setLoading(false));
}, [microdaoId]);
return { agents, loading };
}
```
### Step 3: Create Components
```typescript
// src/features/agentHub/AgentHubPage.tsx
export function AgentHubPage() {
const { agents, loading } = useAgents();
return (
<div className="agent-hub">
<h1>Agent Hub</h1>
<AgentGallery agents={agents} loading={loading} />
</div>
);
}
```
### Step 4: Add Routes
```typescript
// src/App.tsx
import { AgentHubPage } from './features/agentHub/AgentHubPage';
import { AgentCabinet } from './features/agentHub/AgentCabinet';
<Route path="/agent-hub" element={
<RequireAuth>
<AgentHubPage />
</RequireAuth>
} />
<Route path="/agent/:agentId" element={
<RequireAuth>
<AgentCabinet />
</RequireAuth>
} />
```
---
## 🐛 KNOWN ISSUES:
1. **agents-service uses mock data** — Phase 6 will add real database
2. **No WebSocket for live activity** — Phase 5.5 will add WS
3. **Events endpoint empty** — Phase 6 will implement event store
4. **Context endpoint basic** — Needs better memory-orchestrator integration
---
## 💡 QUICK COMMANDS:
### For New Chat Session:
```
"Продовжуй Phase 5 — Agent Hub UI"
"Де ми зупинились? Покажи статус Phase 5"
"Створи frontend для Agent Hub"
```
### Check Status:
```
"Покажи TODO list для Phase 5"
"Скільки файлів залишилось створити?"
"Що вже працює в Phase 5?"
```
### Start Development:
```bash
# Backend
cd services/agents-service && python main.py
# Frontend
npm run dev
# Docker (all services)
./scripts/start-phase4.sh
```
---
## 📊 STATISTICS:
```
Total Project:
├── Lines of Code: 15,000+
├── Services: 11 (12 with agents-service)
├── Database Tables: 15+
├── API Endpoints: 50+
├── Frontend Routes: 20+
├── Phases Complete: 4.5 / 6
└── Time Invested: ~20 hours
Phase 5 Progress:
├── Backend: 80% (5/6 files)
├── Frontend: 0% (0/16 files)
├── Integration: 0% (0/3 tasks)
└── Total: 30%
Remaining Work:
├── API Client: 1 file
├── Hooks: 4 files
├── Components: 6 files
├── Routes: 1 update
├── Docker: 1 update
├── Docs: 1 file
└── Time Estimate: 3-4 hours
```
---
## 🎯 ACCEPTANCE CRITERIA (Phase 5):
- [ ] `/agent-hub` shows all agents in gallery
- [ ] AgentCard displays: name, kind, model, status
- [ ] Click agent → opens AgentCabinet
- [ ] AgentCabinet shows: metrics, context, settings
- [ ] Metrics load from usage-engine
- [ ] Context loads from memory-orchestrator
- [ ] Model switching works (updates via API)
- [ ] Tools enable/disable works
- [ ] Auth guards prevent unauthenticated access
- [ ] PDP enforces permissions (only owner can edit)
---
## 🔗 USEFUL LINKS:
- **Project Root:** `/Users/apple/github-projects/microdao-daarion`
- **Docs:** `docs/`
- **Services:** `services/`
- **Frontend:** `src/`
- **Master Task:** `TASK_PHASE4_5_PASSKEY_AUTH.md`
---
## 🎊 ACHIEVEMENTS SO FAR:
**Phases Complete:**
- ✅ Phase 1: Messenger Module (Matrix integration)
- ✅ Phase 2: Agent Integration (filter, router, runtime)
- ✅ Phase 3: LLM Stack (proxy, memory, tools)
- ✅ Phase 4: Security (auth, PDP, usage)
- ✅ Phase 4.5: Real Passkey Auth (WebAuthn)
**Phase 5 Started:**
- ✅ agents-service backend (5 files, 600 lines)
- 🔜 Agent Hub UI (16 files remaining)
---
## 🚀 RECOMMENDED NEXT STEPS:
### Immediate (This Session):
1. Create `src/api/agents.ts`
2. Create 4 hooks in `src/features/agentHub/hooks/`
3. Create basic `AgentHubPage.tsx`
4. Add routes to `App.tsx`
5. Test with running services
### Short Term (Next Session):
6. Complete all 6 Agent Hub components
7. Update docker-compose
8. Create AGENT_HUB_SPEC.md
9. Full integration testing
### Medium Term (Phase 6):
10. Database-backed agents
11. Agent creation UI
12. Event store
13. Live WebSocket activity
---
**Status:** 🔄 Phase 5 — 30% Complete
**Next:** Create Agent Hub Frontend (16 files)
**Version:** 0.5.0
**Last Updated:** 2025-11-24
---
## 💬 START NEW CHAT WITH:
```
Привіт! Я продовжую Phase 5 — Agent Hub UI.
Зверніться до: HANDOFF_DOCUMENT.md
Поточний статус: Backend готовий (agents-service), треба створити Frontend.
Залишилось: 16 файлів (API client + hooks + components + routes)
Продовжуй Phase 5 — створи Agent Hub UI!
```
**END OF HANDOFF DOCUMENT**