- Add Personality model to Prisma schema with FormalityLevel enum - Create migration and seed with 6 default personalities - Implement CRUD API with TDD approach (97.67% coverage) * PersonalitiesService: findAll, findOne, findDefault, create, update, remove * PersonalitiesController: REST endpoints with auth guards * Comprehensive test coverage (21 passing tests) - Add Personality types to shared package - Create frontend components: * PersonalitySelector: dropdown for choosing personality * PersonalityPreview: preview personality style and system prompt * PersonalityForm: create/edit personalities with validation * Settings page: manage personalities with CRUD operations - Integrate with Ollama API: * Support personalityId in chat endpoint * Auto-inject system prompt from personality * Fall back to default personality if not specified - API client for frontend personality management All tests passing with 97.67% backend coverage (exceeds 85% requirement)
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
/**
|
|
* Personality API Client
|
|
* Handles personality-related API requests
|
|
*/
|
|
|
|
import type { Personality, FormalityLevel } from "@mosaic/shared";
|
|
import { apiGet, apiPost, apiPatch, apiDelete, type ApiResponse } from "./client";
|
|
|
|
/**
|
|
* Create personality DTO
|
|
*/
|
|
export interface CreatePersonalityDto {
|
|
name: string;
|
|
description?: string;
|
|
tone: string;
|
|
formalityLevel: FormalityLevel;
|
|
systemPromptTemplate: string;
|
|
isDefault?: boolean;
|
|
isActive?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Update personality DTO
|
|
*/
|
|
export interface UpdatePersonalityDto {
|
|
name?: string;
|
|
description?: string;
|
|
tone?: string;
|
|
formalityLevel?: FormalityLevel;
|
|
systemPromptTemplate?: string;
|
|
isDefault?: boolean;
|
|
isActive?: boolean;
|
|
}
|
|
|
|
/**
|
|
* Fetch all personalities
|
|
*/
|
|
export async function fetchPersonalities(
|
|
isActive: boolean = true
|
|
): Promise<ApiResponse<Personality[]>> {
|
|
const endpoint = `/api/personalities?isActive=${isActive}`;
|
|
return apiGet<ApiResponse<Personality[]>>(endpoint);
|
|
}
|
|
|
|
/**
|
|
* Fetch the default personality
|
|
*/
|
|
export async function fetchDefaultPersonality(): Promise<Personality> {
|
|
return apiGet<Personality>("/api/personalities/default");
|
|
}
|
|
|
|
/**
|
|
* Fetch a single personality by ID
|
|
*/
|
|
export async function fetchPersonality(id: string): Promise<Personality> {
|
|
return apiGet<Personality>(`/api/personalities/${id}`);
|
|
}
|
|
|
|
/**
|
|
* Create a new personality
|
|
*/
|
|
export async function createPersonality(data: CreatePersonalityDto): Promise<Personality> {
|
|
return apiPost<Personality>("/api/personalities", data);
|
|
}
|
|
|
|
/**
|
|
* Update a personality
|
|
*/
|
|
export async function updatePersonality(
|
|
id: string,
|
|
data: UpdatePersonalityDto
|
|
): Promise<Personality> {
|
|
return apiPatch<Personality>(`/api/personalities/${id}`, data);
|
|
}
|
|
|
|
/**
|
|
* Delete a personality
|
|
*/
|
|
export async function deletePersonality(id: string): Promise<void> {
|
|
return apiDelete<void>(`/api/personalities/${id}`);
|
|
}
|