feat(hermes): persist guarded corporate orchestration backend

This commit is contained in:
Canina Automation committed 2026-10-28 11:57:15 +00:00
1 parent 5550c80a75
commit cc365bcda2
13 files changed
+1734

No files matched your search

@@ -0,0 +1,121 @@
import {
Body,
Controller,
Get,
Headers,
Param,
Post,
Query,
Req,
UnauthorizedException,
UseGuards,
} from '@nestjs/common';
import { JwtAuthGuard } from '../../auth/jwt-auth.guard';
import { RolesGuard } from '../../common/guards/roles.guard';
import { Roles } from '../../common/decorators/roles.decorator';
import { CorporateService } from './corporate.service';
import { randomUUID } from 'crypto';
import { text } from './corporate-policy';
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin', 'SUPER_ADMIN')
@Controller('admin/hermes')
export class CorporateController {
constructor(private readonly service: CorporateService) {}
private actor(req: any) {
// API keys must use their authenticated key identity, not an editable worker label.
const user = req.user;
const id = user?.id ?? user?.sub;
if (!id) throw new UnauthorizedException('Authenticated subject required');
return (user.isApiKey ? 'apikey:' : 'user:') + text(String(id), 200);
}
private key(key?: string) {
return text(key, 200);
}
@Get('runtime') runtime() {
return {
mode: 'MANUAL_DORMANT',
schedulesEnabled: false,
externalExecutionEnabled: false,
};
}
@Get('tasks') tasks(@Query() query: Record<string, any>) {
return this.service.tasks(query);
}
@Get('tasks/:id') detail(@Param('id') id: string) {
return this.service.detail(id);
}
@Post('tasks') create(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Body() body: unknown,
) {
return this.service.create(this.actor(req), key ?? randomUUID(), body);
}
@Post('claims') claim(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Body() body: unknown,
) {
return this.service.claim(this.actor(req), this.key(key), body);
}
@Post('tasks/:id/evidence') evidence(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Param('id') id: string,
@Body() body: unknown,
) {
return this.service.submitEvidence(
this.actor(req),
this.key(key),
id,
body,
);
}
@Post('tasks/:id/reviews') review(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Param('id') id: string,
@Body() body: unknown,
) {
return this.service.review(this.actor(req), this.key(key), id, body);
}
@Post('tasks/:id/effects') effect(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Param('id') id: string,
@Body() body: unknown,
) {
return this.service.effect(this.actor(req), this.key(key), id, body);
}
@Get('market-insights') insights(@Query() q: Record<string, any>) {
return this.service.collection('market-insights', q);
}
@Post('market-insights') research(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Body() body: unknown,
) {
return this.service.research(this.actor(req), this.key(key), body);
}
@Get('monthly-roadmap') roadmaps(@Query() q: Record<string, any>) {
return this.service.collection('monthly-roadmap', q);
}
@Post('monthly-roadmap') roadmap(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Body() body: unknown,
) {
return this.service.roadmap(this.actor(req), this.key(key), body);
}
@Get('reports') reports(@Query() q: Record<string, any>) {
return this.service.collection('reports', q);
}
@Post('reports') report(
@Req() req: any,
@Headers('idempotency-key') key: string,
@Body() body: unknown,
) {
return this.service.report(this.actor(req), this.key(key), body);
}
}