Compare commits
1 Commits
feat/ms22-
...
fix/securi
| Author | SHA1 | Date | |
|---|---|---|---|
| dff23d3922 |
@@ -1,47 +0,0 @@
|
|||||||
import {
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Patch,
|
|
||||||
Delete,
|
|
||||||
Body,
|
|
||||||
Param,
|
|
||||||
UseGuards,
|
|
||||||
ParseUUIDPipe,
|
|
||||||
} from "@nestjs/common";
|
|
||||||
import { AgentTemplateService } from "./agent-template.service";
|
|
||||||
import { CreateAgentTemplateDto } from "./dto/create-agent-template.dto";
|
|
||||||
import { UpdateAgentTemplateDto } from "./dto/update-agent-template.dto";
|
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
||||||
import { AdminGuard } from "../auth/guards/admin.guard";
|
|
||||||
|
|
||||||
@Controller("admin/agent-templates")
|
|
||||||
@UseGuards(AuthGuard, AdminGuard)
|
|
||||||
export class AgentTemplateController {
|
|
||||||
constructor(private readonly agentTemplateService: AgentTemplateService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
findAll() {
|
|
||||||
return this.agentTemplateService.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(":id")
|
|
||||||
findOne(@Param("id", ParseUUIDPipe) id: string) {
|
|
||||||
return this.agentTemplateService.findOne(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
create(@Body() dto: CreateAgentTemplateDto) {
|
|
||||||
return this.agentTemplateService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch(":id")
|
|
||||||
update(@Param("id", ParseUUIDPipe) id: string, @Body() dto: UpdateAgentTemplateDto) {
|
|
||||||
return this.agentTemplateService.update(id, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(":id")
|
|
||||||
remove(@Param("id", ParseUUIDPipe) id: string) {
|
|
||||||
return this.agentTemplateService.remove(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { Module } from "@nestjs/common";
|
|
||||||
import { AgentTemplateService } from "./agent-template.service";
|
|
||||||
import { AgentTemplateController } from "./agent-template.controller";
|
|
||||||
import { PrismaModule } from "../prisma/prisma.module";
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [PrismaModule],
|
|
||||||
controllers: [AgentTemplateController],
|
|
||||||
providers: [AgentTemplateService],
|
|
||||||
exports: [AgentTemplateService],
|
|
||||||
})
|
|
||||||
export class AgentTemplateModule {}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import { Injectable, NotFoundException, ConflictException } from "@nestjs/common";
|
|
||||||
import { PrismaService } from "../prisma/prisma.service";
|
|
||||||
import { CreateAgentTemplateDto } from "./dto/create-agent-template.dto";
|
|
||||||
import { UpdateAgentTemplateDto } from "./dto/update-agent-template.dto";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AgentTemplateService {
|
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
|
||||||
|
|
||||||
async findAll() {
|
|
||||||
return this.prisma.agentTemplate.findMany({
|
|
||||||
orderBy: { createdAt: "asc" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOne(id: string) {
|
|
||||||
const template = await this.prisma.agentTemplate.findUnique({ where: { id } });
|
|
||||||
if (!template) throw new NotFoundException(`AgentTemplate ${id} not found`);
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findByName(name: string) {
|
|
||||||
const template = await this.prisma.agentTemplate.findUnique({ where: { name } });
|
|
||||||
if (!template) throw new NotFoundException(`AgentTemplate "${name}" not found`);
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(dto: CreateAgentTemplateDto) {
|
|
||||||
const existing = await this.prisma.agentTemplate.findUnique({ where: { name: dto.name } });
|
|
||||||
if (existing) throw new ConflictException(`AgentTemplate "${dto.name}" already exists`);
|
|
||||||
|
|
||||||
return this.prisma.agentTemplate.create({
|
|
||||||
data: {
|
|
||||||
name: dto.name,
|
|
||||||
displayName: dto.displayName,
|
|
||||||
role: dto.role,
|
|
||||||
personality: dto.personality,
|
|
||||||
primaryModel: dto.primaryModel,
|
|
||||||
fallbackModels: dto.fallbackModels ?? ([] as string[]),
|
|
||||||
toolPermissions: dto.toolPermissions ?? ([] as string[]),
|
|
||||||
...(dto.discordChannel !== undefined && { discordChannel: dto.discordChannel }),
|
|
||||||
isActive: dto.isActive ?? true,
|
|
||||||
isDefault: dto.isDefault ?? false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(id: string, dto: UpdateAgentTemplateDto) {
|
|
||||||
await this.findOne(id);
|
|
||||||
return this.prisma.agentTemplate.update({ where: { id }, data: dto });
|
|
||||||
}
|
|
||||||
|
|
||||||
async remove(id: string) {
|
|
||||||
await this.findOne(id);
|
|
||||||
return this.prisma.agentTemplate.delete({ where: { id } });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
import { IsString, IsBoolean, IsOptional, IsArray, MinLength } from "class-validator";
|
|
||||||
|
|
||||||
export class CreateAgentTemplateDto {
|
|
||||||
@IsString()
|
|
||||||
@MinLength(1)
|
|
||||||
name!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@MinLength(1)
|
|
||||||
displayName!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@MinLength(1)
|
|
||||||
role!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@MinLength(1)
|
|
||||||
personality!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@MinLength(1)
|
|
||||||
primaryModel!: string;
|
|
||||||
|
|
||||||
@IsArray()
|
|
||||||
@IsOptional()
|
|
||||||
fallbackModels?: string[];
|
|
||||||
|
|
||||||
@IsArray()
|
|
||||||
@IsOptional()
|
|
||||||
toolPermissions?: string[];
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
discordChannel?: string;
|
|
||||||
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
isActive?: boolean;
|
|
||||||
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
isDefault?: boolean;
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import { PartialType } from "@nestjs/mapped-types";
|
|
||||||
import { CreateAgentTemplateDto } from "./create-agent-template.dto";
|
|
||||||
|
|
||||||
export class UpdateAgentTemplateDto extends PartialType(CreateAgentTemplateDto) {}
|
|
||||||
@@ -48,7 +48,6 @@ import { TerminalModule } from "./terminal/terminal.module";
|
|||||||
import { PersonalitiesModule } from "./personalities/personalities.module";
|
import { PersonalitiesModule } from "./personalities/personalities.module";
|
||||||
import { WorkspacesModule } from "./workspaces/workspaces.module";
|
import { WorkspacesModule } from "./workspaces/workspaces.module";
|
||||||
import { AdminModule } from "./admin/admin.module";
|
import { AdminModule } from "./admin/admin.module";
|
||||||
import { AgentTemplateModule } from "./agent-template/agent-template.module";
|
|
||||||
import { TeamsModule } from "./teams/teams.module";
|
import { TeamsModule } from "./teams/teams.module";
|
||||||
import { ImportModule } from "./import/import.module";
|
import { ImportModule } from "./import/import.module";
|
||||||
import { ConversationArchiveModule } from "./conversation-archive/conversation-archive.module";
|
import { ConversationArchiveModule } from "./conversation-archive/conversation-archive.module";
|
||||||
@@ -130,7 +129,6 @@ import { OrchestratorModule } from "./orchestrator/orchestrator.module";
|
|||||||
PersonalitiesModule,
|
PersonalitiesModule,
|
||||||
WorkspacesModule,
|
WorkspacesModule,
|
||||||
AdminModule,
|
AdminModule,
|
||||||
AgentTemplateModule,
|
|
||||||
TeamsModule,
|
TeamsModule,
|
||||||
ImportModule,
|
ImportModule,
|
||||||
ConversationArchiveModule,
|
ConversationArchiveModule,
|
||||||
|
|||||||
Reference in New Issue
Block a user