feat(#93): implement agent spawn via federation
Implements FED-010: Agent Spawn via Federation feature that enables spawning and managing Claude agents on remote federated Mosaic Stack instances via COMMAND message type. Features: - Federation agent command types (spawn, status, kill) - FederationAgentService for handling agent operations - Integration with orchestrator's agent spawner/lifecycle services - API endpoints for spawning, querying status, and killing agents - Full command routing through federation COMMAND infrastructure - Comprehensive test coverage (12/12 tests passing) Architecture: - Hub → Spoke: Spawn agents on remote instances - Command flow: FederationController → FederationAgentService → CommandService → Remote Orchestrator - Response handling: Remote orchestrator returns agent status/results - Security: Connection validation, signature verification Files created: - apps/api/src/federation/types/federation-agent.types.ts - apps/api/src/federation/federation-agent.service.ts - apps/api/src/federation/federation-agent.service.spec.ts Files modified: - apps/api/src/federation/command.service.ts (agent command routing) - apps/api/src/federation/federation.controller.ts (agent endpoints) - apps/api/src/federation/federation.module.ts (service registration) - apps/orchestrator/src/api/agents/agents.controller.ts (status endpoint) - apps/orchestrator/src/api/agents/agents.module.ts (lifecycle integration) Testing: - 12/12 tests passing for FederationAgentService - All command service tests passing - TypeScript compilation successful - Linting passed Refs #93 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ The Mosaic Stack API is a NestJS-based backend service providing REST endpoints
|
||||
## Overview
|
||||
|
||||
The API serves as the central backend for:
|
||||
|
||||
- **Task Management** - Create, update, track tasks with filtering and sorting
|
||||
- **Event Management** - Calendar events and scheduling
|
||||
- **Project Management** - Organize work into projects
|
||||
@@ -18,20 +19,20 @@ The API serves as the central backend for:
|
||||
|
||||
## Available Modules
|
||||
|
||||
| Module | Base Path | Description |
|
||||
|--------|-----------|-------------|
|
||||
| **Tasks** | `/api/tasks` | CRUD operations for tasks with filtering |
|
||||
| **Events** | `/api/events` | Calendar events and scheduling |
|
||||
| **Projects** | `/api/projects` | Project management |
|
||||
| **Knowledge** | `/api/knowledge/entries` | Wiki entries with markdown support |
|
||||
| **Knowledge Tags** | `/api/knowledge/tags` | Tag management for knowledge entries |
|
||||
| **Ideas** | `/api/ideas` | Quick capture and idea management |
|
||||
| **Domains** | `/api/domains` | Domain categorization |
|
||||
| **Personalities** | `/api/personalities` | AI personality configurations |
|
||||
| **Widgets** | `/api/widgets` | Dashboard widget data |
|
||||
| **Layouts** | `/api/layouts` | Dashboard layout configuration |
|
||||
| **Ollama** | `/api/ollama` | LLM integration (generate, chat, embed) |
|
||||
| **Users** | `/api/users/me/preferences` | User preferences |
|
||||
| Module | Base Path | Description |
|
||||
| ------------------ | --------------------------- | ---------------------------------------- |
|
||||
| **Tasks** | `/api/tasks` | CRUD operations for tasks with filtering |
|
||||
| **Events** | `/api/events` | Calendar events and scheduling |
|
||||
| **Projects** | `/api/projects` | Project management |
|
||||
| **Knowledge** | `/api/knowledge/entries` | Wiki entries with markdown support |
|
||||
| **Knowledge Tags** | `/api/knowledge/tags` | Tag management for knowledge entries |
|
||||
| **Ideas** | `/api/ideas` | Quick capture and idea management |
|
||||
| **Domains** | `/api/domains` | Domain categorization |
|
||||
| **Personalities** | `/api/personalities` | AI personality configurations |
|
||||
| **Widgets** | `/api/widgets` | Dashboard widget data |
|
||||
| **Layouts** | `/api/layouts` | Dashboard layout configuration |
|
||||
| **Ollama** | `/api/ollama` | LLM integration (generate, chat, embed) |
|
||||
| **Users** | `/api/users/me/preferences` | User preferences |
|
||||
|
||||
### Health Check
|
||||
|
||||
@@ -51,11 +52,11 @@ The API uses **BetterAuth** for authentication with the following features:
|
||||
|
||||
The API uses a layered guard system:
|
||||
|
||||
| Guard | Purpose | Applies To |
|
||||
|-------|---------|------------|
|
||||
| **AuthGuard** | Verifies user authentication via Bearer token | Most protected endpoints |
|
||||
| **WorkspaceGuard** | Validates workspace membership and sets Row-Level Security (RLS) context | Workspace-scoped resources |
|
||||
| **PermissionGuard** | Enforces role-based access control | Admin operations |
|
||||
| Guard | Purpose | Applies To |
|
||||
| ------------------- | ------------------------------------------------------------------------ | -------------------------- |
|
||||
| **AuthGuard** | Verifies user authentication via Bearer token | Most protected endpoints |
|
||||
| **WorkspaceGuard** | Validates workspace membership and sets Row-Level Security (RLS) context | Workspace-scoped resources |
|
||||
| **PermissionGuard** | Enforces role-based access control | Admin operations |
|
||||
|
||||
### Workspace Roles
|
||||
|
||||
@@ -69,15 +70,16 @@ The API uses a layered guard system:
|
||||
Used with `@RequirePermission()` decorator:
|
||||
|
||||
```typescript
|
||||
Permission.WORKSPACE_OWNER // Requires OWNER role
|
||||
Permission.WORKSPACE_ADMIN // Requires ADMIN or OWNER
|
||||
Permission.WORKSPACE_MEMBER // Requires MEMBER, ADMIN, or OWNER
|
||||
Permission.WORKSPACE_ANY // Any authenticated member including GUEST
|
||||
Permission.WORKSPACE_OWNER; // Requires OWNER role
|
||||
Permission.WORKSPACE_ADMIN; // Requires ADMIN or OWNER
|
||||
Permission.WORKSPACE_MEMBER; // Requires MEMBER, ADMIN, or OWNER
|
||||
Permission.WORKSPACE_ANY; // Any authenticated member including GUEST
|
||||
```
|
||||
|
||||
### Providing Workspace Context
|
||||
|
||||
Workspace ID can be provided via:
|
||||
|
||||
1. **Header**: `X-Workspace-Id: <workspace-id>` (highest priority)
|
||||
2. **URL Parameter**: `:workspaceId`
|
||||
3. **Request Body**: `workspaceId` field
|
||||
@@ -85,7 +87,7 @@ Workspace ID can be provided via:
|
||||
### Example: Protected Controller
|
||||
|
||||
```typescript
|
||||
@Controller('tasks')
|
||||
@Controller("tasks")
|
||||
@UseGuards(AuthGuard, WorkspaceGuard, PermissionGuard)
|
||||
export class TasksController {
|
||||
@Post()
|
||||
@@ -98,13 +100,13 @@ export class TasksController {
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `PORT` | API server port | `3001` |
|
||||
| `DATABASE_URL` | PostgreSQL connection string | Required |
|
||||
| `NODE_ENV` | Environment (`development`, `production`) | - |
|
||||
| `NEXT_PUBLIC_APP_URL` | Frontend application URL (for CORS) | `http://localhost:3000` |
|
||||
| `WEB_URL` | WebSocket CORS origin | `http://localhost:3000` |
|
||||
| Variable | Description | Default |
|
||||
| --------------------- | ----------------------------------------- | ----------------------- |
|
||||
| `PORT` | API server port | `3001` |
|
||||
| `DATABASE_URL` | PostgreSQL connection string | Required |
|
||||
| `NODE_ENV` | Environment (`development`, `production`) | - |
|
||||
| `NEXT_PUBLIC_APP_URL` | Frontend application URL (for CORS) | `http://localhost:3000` |
|
||||
| `WEB_URL` | WebSocket CORS origin | `http://localhost:3000` |
|
||||
|
||||
## Running Locally
|
||||
|
||||
@@ -117,22 +119,26 @@ export class TasksController {
|
||||
### Setup
|
||||
|
||||
1. **Install dependencies:**
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
2. **Set up environment variables:**
|
||||
|
||||
```bash
|
||||
cp .env.example .env # If available
|
||||
# Edit .env with your DATABASE_URL
|
||||
```
|
||||
|
||||
3. **Generate Prisma client:**
|
||||
|
||||
```bash
|
||||
pnpm prisma:generate
|
||||
```
|
||||
|
||||
4. **Run database migrations:**
|
||||
|
||||
```bash
|
||||
pnpm prisma:migrate
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user