Files
blackroad-operating-system/core_os/adapters/api_client.py
Claude e84407660d feat: scaffold BlackRoad OS Phase 2 infrastructure
Implements complete Phase 2 scaffold across 6 core modules:

## New Modules

### 1. Backend API Enhancements
- Add system router with /version, /config/public, /os/state endpoints
- Register system router in main.py
- Add comprehensive tests for system endpoints

### 2. Core OS Runtime (core_os/)
- Implement UserSession, Window, OSState models
- Add state management functions (open_window, close_window, etc.)
- Create Backend API adapter for communication
- Include full test suite for models and state

### 3. Operator Engine (operator_engine/)
- Build job registry with example jobs
- Implement simple scheduler with lifecycle management
- Optional HTTP server on port 8001
- Complete tests for jobs and scheduler

### 4. Web Client Enhancements
- Add CoreOSClient JavaScript class
- Integrate system API endpoints
- Event-driven architecture for state updates
- Zero dependencies, vanilla JavaScript

### 5. Prism Console (prism-console/)
- Modern dark-themed admin UI
- Multi-tab navigation (Overview, Jobs, Agents, Logs, System)
- Real-time metrics dashboard
- Backend API integration with auto-refresh

### 6. Documentation (codex-docs/)
- Complete MkDocs-based documentation
- Architecture guides and component docs
- Infrastructure setup guides
- API reference documentation

## CI/CD

- Add core-os-tests.yml workflow
- Add operator-tests.yml workflow
- Add docs-build.yml workflow

## Documentation

- Create BLACKROAD_OS_REPO_MAP.md cross-reference
- Add README for each module
- Comprehensive integration documentation

## Summary

- 37 new files created
- ~3,500 lines of new code
- 5 test suites with 15+ tests
- 3 new CI workflows
- 10+ documentation pages

All modules are minimal working skeletons ready for integration.
Designed to be extracted into separate repos if needed.

Phase 2 scaffold complete and ready for review.
2025-11-18 03:47:13 +00:00

67 lines
2.2 KiB
Python

"""API client for communicating with backend"""
import os
from typing import Optional, Dict, Any
import httpx
class BackendAPIClient:
"""
Client for communicating with the BlackRoad backend API
This adapter allows the Core OS to interact with the backend
for authentication, data persistence, and external integrations.
"""
def __init__(self, base_url: Optional[str] = None):
"""
Initialize API client
Args:
base_url: Base URL for the API (defaults to env var or localhost)
"""
self.base_url = base_url or os.getenv(
"BLACKROAD_API_URL", "http://localhost:8000"
)
self.timeout = 30.0
async def get_version(self) -> Dict[str, Any]:
"""Get backend API version"""
async with httpx.AsyncClient(timeout=self.timeout) as client:
response = await client.get(f"{self.base_url}/api/system/version")
response.raise_for_status()
return response.json()
async def get_public_config(self) -> Dict[str, Any]:
"""Get public configuration from backend"""
async with httpx.AsyncClient(timeout=self.timeout) as client:
response = await client.get(f"{self.base_url}/api/system/config/public")
response.raise_for_status()
return response.json()
async def health_check(self) -> bool:
"""Check if backend API is healthy"""
try:
async with httpx.AsyncClient(timeout=5.0) as client:
response = await client.get(f"{self.base_url}/health")
return response.status_code == 200
except Exception:
return False
async def sync_os_state(self, state: Dict[str, Any]) -> Dict[str, Any]:
"""
Sync OS state with backend (stub for now)
Args:
state: OS state dictionary
Returns:
Response from backend
"""
# TODO: Implement actual state sync endpoint
async with httpx.AsyncClient(timeout=self.timeout) as client:
response = await client.post(
f"{self.base_url}/api/system/os/state", json=state
)
response.raise_for_status()
return response.json()