Files
microdao-daarion/backend/http/assignment.routes.ts
Apple 7b91c8e83c feat(foundation): FOUNDATION_UPDATE implementation
## Documentation (20 files)
- DAARION Ontology Core v1 (Agent → MicroDAO → Node → District)
- User Onboarding & Identity Layer (DAIS)
- Data Model UPDATE, Event Catalog, Governance & Permissions
- Rooms Layer, City/MicroDAO/Agents/Nodes Interface Architecture
- Helper files: ontology-summary, lifecycles, event-schemas

## Database Migration (027)
- DAIS tables: dais_identities, dais_emails, dais_wallets, dais_keys
- agent_assignments table for Assignment Layer
- rooms table for Rooms Layer
- event_outbox for NATS event delivery
- New enums: agent_role, microdao_type, node_kind, node_status, etc.
- Updated agents, microdaos, nodes tables with ontology fields

## Backend
- DAIS service & routes (/api/v1/dais/*)
- Assignment service & routes (/api/v1/assignments/*)
- Domain types for DAIS and Ontology

## Frontend
- Ontology types (Agent, MicroDAO, Node, DAIS, Assignments)
- API clients for DAIS and Assignments
- UI components: DaisProfileCard, AssignmentsPanel, OntologyBadge

Non-breaking update - all existing functionality preserved.
2025-11-29 15:24:38 -08:00

189 lines
4.2 KiB
TypeScript

/**
* Agent Assignment API Routes
* Based on: docs/foundation/microdao_Governance_And_Permissions_v1.md
*/
import { Router, Request, Response } from 'express';
import { assignmentService } from '../services/assignment/assignment.service';
import { logger } from '../infra/logger/logger';
const router = Router();
/**
* POST /api/assignments
* Create a new agent assignment
*/
router.post('/', async (req: Request, res: Response) => {
try {
const { agentId, targetMicrodaoId, scope, role, metadata } = req.body;
const assignment = await assignmentService.createAssignment({
agentId,
targetMicrodaoId,
scope,
role,
metadata,
});
res.status(201).json({
success: true,
data: assignment,
});
} catch (error) {
logger.error('Failed to create assignment', error);
res.status(500).json({
success: false,
error: 'Failed to create assignment',
});
}
});
/**
* DELETE /api/assignments/:id
* End an agent assignment
*/
router.delete('/:id', async (req: Request, res: Response) => {
try {
const { id } = req.params;
await assignmentService.endAssignment(id);
res.json({
success: true,
message: 'Assignment ended',
});
} catch (error) {
logger.error('Failed to end assignment', error);
res.status(500).json({
success: false,
error: 'Failed to end assignment',
});
}
});
/**
* GET /api/assignments/agent/:agentId
* Get all active assignments for an agent
*/
router.get('/agent/:agentId', async (req: Request, res: Response) => {
try {
const { agentId } = req.params;
const assignments = await assignmentService.getAgentAssignments(agentId);
res.json({
success: true,
data: assignments,
});
} catch (error) {
logger.error('Failed to get agent assignments', error);
res.status(500).json({
success: false,
error: 'Failed to get assignments',
});
}
});
/**
* GET /api/assignments/microdao/:microdaoId
* Get all assignments for a MicroDAO
*/
router.get('/microdao/:microdaoId', async (req: Request, res: Response) => {
try {
const { microdaoId } = req.params;
const assignments = await assignmentService.getMicrodaoAssignments(microdaoId);
res.json({
success: true,
data: assignments,
});
} catch (error) {
logger.error('Failed to get microdao assignments', error);
res.status(500).json({
success: false,
error: 'Failed to get assignments',
});
}
});
/**
* GET /api/assignments/citywide
* Get all citywide assignments (DAARION108)
*/
router.get('/citywide', async (req: Request, res: Response) => {
try {
const assignments = await assignmentService.getCitywideAssignments();
res.json({
success: true,
data: assignments,
});
} catch (error) {
logger.error('Failed to get citywide assignments', error);
res.status(500).json({
success: false,
error: 'Failed to get assignments',
});
}
});
/**
* GET /api/assignments/agent/:agentId/scope
* Get agent's effective scope
*/
router.get('/agent/:agentId/scope', async (req: Request, res: Response) => {
try {
const { agentId } = req.params;
const scope = await assignmentService.getAgentScope(agentId);
res.json({
success: true,
data: scope,
});
} catch (error) {
logger.error('Failed to get agent scope', error);
res.status(500).json({
success: false,
error: 'Failed to get scope',
});
}
});
/**
* GET /api/assignments/check
* Check if agent has assignment to target
*/
router.get('/check', async (req: Request, res: Response) => {
try {
const { agentId, targetMicrodaoId } = req.query;
if (!agentId || !targetMicrodaoId) {
return res.status(400).json({
success: false,
error: 'agentId and targetMicrodaoId are required',
});
}
const hasAssignment = await assignmentService.hasAssignment(
agentId as string,
targetMicrodaoId as string
);
res.json({
success: true,
data: { hasAssignment },
});
} catch (error) {
logger.error('Failed to check assignment', error);
res.status(500).json({
success: false,
error: 'Failed to check assignment',
});
}
});
export default router;