Implement Personality system backend with database schema, service, controller, and comprehensive tests. Personalities define assistant behavior with system prompts and LLM configuration. Changes: - Update Personality model in schema.prisma with LLM provider relation - Create PersonalitiesService with CRUD and default management - Create PersonalitiesController with REST endpoints - Add DTOs with validation (create/update) - Add entity for type safety - Remove unused PromptFormatterService - Achieve 26 tests with full coverage Endpoints: - GET /personality - List all - GET /personality/default - Get default - GET /personality/by-name/:name - Get by name - GET /personality/:id - Get one - POST /personality - Create - PATCH /personality/:id - Update - DELETE /personality/:id - Delete - POST /personality/:id/set-default - Set default Fixes #130 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
111 lines
2.7 KiB
TypeScript
111 lines
2.7 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
Req,
|
|
HttpCode,
|
|
HttpStatus,
|
|
} from "@nestjs/common";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
import { PersonalitiesService } from "./personalities.service";
|
|
import { CreatePersonalityDto, UpdatePersonalityDto } from "./dto";
|
|
import { Personality } from "./entities/personality.entity";
|
|
|
|
interface AuthenticatedRequest {
|
|
user: { id: string };
|
|
workspaceId: string;
|
|
}
|
|
|
|
/**
|
|
* Controller for managing personality/assistant configurations
|
|
*/
|
|
@Controller("personality")
|
|
@UseGuards(AuthGuard)
|
|
export class PersonalitiesController {
|
|
constructor(private readonly personalitiesService: PersonalitiesService) {}
|
|
|
|
/**
|
|
* List all personalities for the workspace
|
|
*/
|
|
@Get()
|
|
async findAll(@Req() req: AuthenticatedRequest): Promise<Personality[]> {
|
|
return this.personalitiesService.findAll(req.workspaceId);
|
|
}
|
|
|
|
/**
|
|
* Get the default personality for the workspace
|
|
*/
|
|
@Get("default")
|
|
async findDefault(@Req() req: AuthenticatedRequest): Promise<Personality> {
|
|
return this.personalitiesService.findDefault(req.workspaceId);
|
|
}
|
|
|
|
/**
|
|
* Get a personality by its unique name
|
|
*/
|
|
@Get("by-name/:name")
|
|
async findByName(
|
|
@Req() req: AuthenticatedRequest,
|
|
@Param("name") name: string
|
|
): Promise<Personality> {
|
|
return this.personalitiesService.findByName(req.workspaceId, name);
|
|
}
|
|
|
|
/**
|
|
* Get a personality by ID
|
|
*/
|
|
@Get(":id")
|
|
async findOne(@Req() req: AuthenticatedRequest, @Param("id") id: string): Promise<Personality> {
|
|
return this.personalitiesService.findOne(req.workspaceId, id);
|
|
}
|
|
|
|
/**
|
|
* Create a new personality
|
|
*/
|
|
@Post()
|
|
@HttpCode(HttpStatus.CREATED)
|
|
async create(
|
|
@Req() req: AuthenticatedRequest,
|
|
@Body() dto: CreatePersonalityDto
|
|
): Promise<Personality> {
|
|
return this.personalitiesService.create(req.workspaceId, dto);
|
|
}
|
|
|
|
/**
|
|
* Update a personality
|
|
*/
|
|
@Patch(":id")
|
|
async update(
|
|
@Req() req: AuthenticatedRequest,
|
|
@Param("id") id: string,
|
|
@Body() dto: UpdatePersonalityDto
|
|
): Promise<Personality> {
|
|
return this.personalitiesService.update(req.workspaceId, id, dto);
|
|
}
|
|
|
|
/**
|
|
* Delete a personality
|
|
*/
|
|
@Delete(":id")
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
async delete(@Req() req: AuthenticatedRequest, @Param("id") id: string): Promise<void> {
|
|
return this.personalitiesService.delete(req.workspaceId, id);
|
|
}
|
|
|
|
/**
|
|
* Set a personality as the default
|
|
*/
|
|
@Post(":id/set-default")
|
|
async setDefault(
|
|
@Req() req: AuthenticatedRequest,
|
|
@Param("id") id: string
|
|
): Promise<Personality> {
|
|
return this.personalitiesService.setDefault(req.workspaceId, id);
|
|
}
|
|
}
|