add mana core

This commit is contained in:
Wuesteon 2025-11-25 18:56:35 +01:00
parent ce71db2fc0
commit 754e87ebc0
112 changed files with 34765 additions and 548 deletions

View file

@ -1,41 +1,99 @@
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
import { ConversationService } from './conversation.service';
import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import { isOk } from '@manacore/shared-errors';
import {
ConversationService,
type Conversation,
type Message,
} from './conversation.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import {
CurrentUser,
CurrentUserData,
} from '../common/decorators/current-user.decorator';
@Controller('conversations')
@UseGuards(JwtAuthGuard)
export class ConversationController {
constructor(private readonly conversationService: ConversationService) {}
@Get()
async getConversations(@Query('userId') userId: string) {
return this.conversationService.getConversations(userId);
async getConversations(
@CurrentUser() user: CurrentUserData,
): Promise<Conversation[]> {
const result = await this.conversationService.getConversations(user.userId);
if (!isOk(result)) {
throw result.error;
}
return result.value;
}
@Get(':id')
async getConversation(@Param('id') id: string) {
return this.conversationService.getConversation(id);
async getConversation(
@Param('id') id: string,
@CurrentUser() user: CurrentUserData,
): Promise<Conversation> {
// TODO: Add ownership check - ensure conversation belongs to user
const result = await this.conversationService.getConversation(id);
if (!isOk(result)) {
throw result.error;
}
return result.value;
}
@Get(':id/messages')
async getMessages(@Param('id') id: string) {
return this.conversationService.getMessages(id);
async getMessages(
@Param('id') id: string,
@CurrentUser() user: CurrentUserData,
): Promise<Message[]> {
// TODO: Add ownership check - ensure conversation belongs to user
const result = await this.conversationService.getMessages(id);
if (!isOk(result)) {
throw result.error;
}
return result.value;
}
@Post()
async createConversation(
@Body() body: { userId: string; modelId: string; title?: string },
) {
return this.conversationService.createConversation(
body.userId,
@Body() body: { modelId: string; title?: string },
@CurrentUser() user: CurrentUserData,
): Promise<Conversation> {
const result = await this.conversationService.createConversation(
user.userId,
body.modelId,
body.title,
);
if (!isOk(result)) {
throw result.error;
}
return result.value;
}
@Post(':id/messages')
async addMessage(
@Param('id') id: string,
@Body() body: { sender: 'user' | 'assistant' | 'system'; messageText: string },
) {
return this.conversationService.addMessage(id, body.sender, body.messageText);
@CurrentUser() user: CurrentUserData,
): Promise<Message> {
// TODO: Add ownership check - ensure conversation belongs to user
const result = await this.conversationService.addMessage(
id,
body.sender,
body.messageText,
);
if (!isOk(result)) {
throw result.error;
}
return result.value;
}
}