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.
This commit is contained in:
Apple
2025-11-29 15:24:38 -08:00
parent deeaf26b0b
commit 7b91c8e83c
43 changed files with 5733 additions and 47 deletions

View File

@@ -0,0 +1,188 @@
/**
* 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;

219
backend/http/dais.routes.ts Normal file
View File

@@ -0,0 +1,219 @@
/**
* DAIS API Routes
* Based on: docs/foundation/DAARION_Identity_And_Access_Draft_v1.md
*/
import { Router, Request, Response } from 'express';
import { daisService } from '../services/dais/dais.service';
import { logger } from '../infra/logger/logger';
const router = Router();
/**
* POST /api/dais/identity
* Create a new DAIS identity
*/
router.post('/identity', async (req: Request, res: Response) => {
try {
const { email, walletAddress, network } = req.body;
const result = await daisService.createIdentity({
email,
walletAddress,
network,
});
res.status(201).json({
success: true,
data: result,
});
} catch (error) {
logger.error('Failed to create DAIS identity', error);
res.status(500).json({
success: false,
error: 'Failed to create identity',
});
}
});
/**
* GET /api/dais/:id
* Get DAIS profile
*/
router.get('/:id', async (req: Request, res: Response) => {
try {
const { id } = req.params;
const profile = await daisService.getProfile(id);
if (!profile) {
return res.status(404).json({
success: false,
error: 'DAIS identity not found',
});
}
res.json({
success: true,
data: profile,
});
} catch (error) {
logger.error('Failed to get DAIS profile', error);
res.status(500).json({
success: false,
error: 'Failed to get profile',
});
}
});
/**
* GET /api/dais/agent/:agentId
* Get DAIS profile by agent ID
*/
router.get('/agent/:agentId', async (req: Request, res: Response) => {
try {
const { agentId } = req.params;
const profile = await daisService.getByAgentId(agentId);
if (!profile) {
return res.status(404).json({
success: false,
error: 'DAIS identity not found for agent',
});
}
res.json({
success: true,
data: profile,
});
} catch (error) {
logger.error('Failed to get DAIS by agent', error);
res.status(500).json({
success: false,
error: 'Failed to get profile',
});
}
});
/**
* POST /api/dais/:id/email
* Add email to DAIS
*/
router.post('/:id/email', async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { email } = req.body;
const result = await daisService.addEmail(id, email);
res.status(201).json({
success: true,
data: result,
});
} catch (error) {
logger.error('Failed to add email', error);
res.status(500).json({
success: false,
error: 'Failed to add email',
});
}
});
/**
* POST /api/dais/:id/email/verify
* Verify email
*/
router.post('/:id/email/verify', async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { email, otp } = req.body;
// TODO: Validate OTP
await daisService.verifyEmail(id, email);
res.json({
success: true,
message: 'Email verified',
});
} catch (error) {
logger.error('Failed to verify email', error);
res.status(500).json({
success: false,
error: 'Failed to verify email',
});
}
});
/**
* POST /api/dais/:id/wallet
* Add wallet to DAIS
*/
router.post('/:id/wallet', async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { walletAddress, network } = req.body;
const result = await daisService.addWallet(id, walletAddress, network);
res.status(201).json({
success: true,
data: result,
});
} catch (error) {
logger.error('Failed to add wallet', error);
res.status(500).json({
success: false,
error: 'Failed to add wallet',
});
}
});
/**
* POST /api/dais/:id/wallet/verify
* Verify wallet (SIWE)
*/
router.post('/:id/wallet/verify', async (req: Request, res: Response) => {
try {
const { id } = req.params;
const { walletAddress, signature, message } = req.body;
// TODO: Validate SIWE signature
await daisService.verifyWallet(id, walletAddress);
res.json({
success: true,
message: 'Wallet verified',
});
} catch (error) {
logger.error('Failed to verify wallet', error);
res.status(500).json({
success: false,
error: 'Failed to verify wallet',
});
}
});
/**
* POST /api/dais/:id/promote-to-orchestrator
* Promote DAIS to orchestrator level
*/
router.post('/:id/promote-to-orchestrator', async (req: Request, res: Response) => {
try {
const { id } = req.params;
await daisService.promoteToOrchestrator(id);
res.json({
success: true,
message: 'Promoted to orchestrator',
});
} catch (error) {
logger.error('Failed to promote to orchestrator', error);
res.status(500).json({
success: false,
error: 'Failed to promote',
});
}
});
export default router;