feat(api): implement personalities CRUD API with DTOs and Prisma model
All checks were successful
ci/woodpecker/push/api Pipeline was successful

- Add GET /api/personalities?isActive=true|false (list with optional filter)
- Add GET /api/personalities/default (default personality endpoint)
- Add GET /api/personalities/:id (single personality by ID)
- Add POST /api/personalities (create personality)
- Add PATCH /api/personalities/:id (update personality)
- Add DELETE /api/personalities/:id (delete personality)
- Add POST /api/personalities/:id/set-default (convenience set-default)
- Add tone and formalityLevel fields to Prisma Personality model
- Add migration 20260227000000_add_personality_tone_formality
- Map Prisma field names to frontend API contract (systemPrompt->systemPromptTemplate, isEnabled->isActive)
- Apply WorkspaceGuard + PermissionGuard per project patterns
- Return { success: true, data } wrapper for list endpoint
- Add PersonalityQueryDto for isActive filter support
- Update spec files to reflect new field mapping and response shape

Resolves frontend 404 on /api/personalities

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 04:36:55 -06:00
parent dd0568cf15
commit fe5bc4c16a
12 changed files with 444 additions and 358 deletions

View File

@@ -1,59 +1,38 @@
import {
IsString,
IsOptional,
IsBoolean,
IsNumber,
IsInt,
IsUUID,
MinLength,
MaxLength,
Min,
Max,
} from "class-validator";
import { FormalityLevel } from "@prisma/client";
import { IsString, IsEnum, IsOptional, IsBoolean, MinLength, MaxLength } from "class-validator";
/**
* DTO for creating a new personality/assistant configuration
* DTO for creating a new personality
* Field names match the frontend API contract from @mosaic/shared Personality type.
*/
export class CreatePersonalityDto {
@IsString()
@MinLength(1)
@MaxLength(100)
name!: string; // unique identifier slug
@IsString()
@MinLength(1)
@MaxLength(200)
displayName!: string; // human-readable name
@IsString({ message: "name must be a string" })
@MinLength(1, { message: "name must not be empty" })
@MaxLength(255, { message: "name must not exceed 255 characters" })
name!: string;
@IsOptional()
@IsString()
@MaxLength(1000)
@IsString({ message: "description must be a string" })
@MaxLength(2000, { message: "description must not exceed 2000 characters" })
description?: string;
@IsString()
@MinLength(10)
systemPrompt!: string;
@IsString({ message: "tone must be a string" })
@MinLength(1, { message: "tone must not be empty" })
@MaxLength(100, { message: "tone must not exceed 100 characters" })
tone!: string;
@IsEnum(FormalityLevel, { message: "formalityLevel must be a valid FormalityLevel" })
formalityLevel!: FormalityLevel;
@IsString({ message: "systemPromptTemplate must be a string" })
@MinLength(1, { message: "systemPromptTemplate must not be empty" })
systemPromptTemplate!: string;
@IsOptional()
@IsNumber()
@Min(0)
@Max(2)
temperature?: number; // null = use provider default
@IsOptional()
@IsInt()
@Min(1)
maxTokens?: number; // null = use provider default
@IsOptional()
@IsUUID("4")
llmProviderInstanceId?: string; // FK to LlmProviderInstance
@IsOptional()
@IsBoolean()
@IsBoolean({ message: "isDefault must be a boolean" })
isDefault?: boolean;
@IsOptional()
@IsBoolean()
isEnabled?: boolean;
@IsBoolean({ message: "isActive must be a boolean" })
isActive?: boolean;
}