feat(#130): add Personality Prisma schema and backend
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>
This commit is contained in:
@@ -2,20 +2,17 @@ import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Patch,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
Req,
|
||||
ParseBoolPipe,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
} from "@nestjs/common";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
import { PersonalitiesService } from "./personalities.service";
|
||||
import { PromptFormatterService, PromptContext } from "./services/prompt-formatter.service";
|
||||
import { CreatePersonalityDto, UpdatePersonalityDto } from "./dto";
|
||||
import { Personality } from "./entities/personality.entity";
|
||||
|
||||
@@ -24,37 +21,52 @@ interface AuthenticatedRequest {
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
@Controller("personalities")
|
||||
/**
|
||||
* Controller for managing personality/assistant configurations
|
||||
*/
|
||||
@Controller("personality")
|
||||
@UseGuards(AuthGuard)
|
||||
export class PersonalitiesController {
|
||||
constructor(
|
||||
private readonly personalitiesService: PersonalitiesService,
|
||||
private readonly promptFormatter: PromptFormatterService
|
||||
) {}
|
||||
constructor(private readonly personalitiesService: PersonalitiesService) {}
|
||||
|
||||
/**
|
||||
* List all personalities for the workspace
|
||||
*/
|
||||
@Get()
|
||||
async findAll(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Query("isActive", new ParseBoolPipe({ optional: true })) isActive?: boolean
|
||||
): Promise<Personality[]> {
|
||||
return this.personalitiesService.findAll(req.workspaceId, isActive);
|
||||
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("formality-levels")
|
||||
getFormalityLevels(): { level: string; description: string }[] {
|
||||
return this.promptFormatter.getFormalityLevels();
|
||||
/**
|
||||
* 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(
|
||||
@@ -64,7 +76,10 @@ export class PersonalitiesController {
|
||||
return this.personalitiesService.create(req.workspaceId, dto);
|
||||
}
|
||||
|
||||
@Put(":id")
|
||||
/**
|
||||
* Update a personality
|
||||
*/
|
||||
@Patch(":id")
|
||||
async update(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Param("id") id: string,
|
||||
@@ -73,20 +88,23 @@ export class PersonalitiesController {
|
||||
return this.personalitiesService.update(req.workspaceId, id, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a personality
|
||||
*/
|
||||
@Delete(":id")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async remove(@Req() req: AuthenticatedRequest, @Param("id") id: string): Promise<Personality> {
|
||||
return this.personalitiesService.remove(req.workspaceId, id);
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
async delete(@Req() req: AuthenticatedRequest, @Param("id") id: string): Promise<void> {
|
||||
return this.personalitiesService.delete(req.workspaceId, id);
|
||||
}
|
||||
|
||||
@Post(":id/preview")
|
||||
async previewPrompt(
|
||||
/**
|
||||
* Set a personality as the default
|
||||
*/
|
||||
@Post(":id/set-default")
|
||||
async setDefault(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Param("id") id: string,
|
||||
@Body() context?: PromptContext
|
||||
): Promise<{ systemPrompt: string }> {
|
||||
const personality = await this.personalitiesService.findOne(req.workspaceId, id);
|
||||
const { systemPrompt } = this.promptFormatter.formatPrompt(personality, context);
|
||||
return { systemPrompt };
|
||||
@Param("id") id: string
|
||||
): Promise<Personality> {
|
||||
return this.personalitiesService.setDefault(req.workspaceId, id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user