Compare commits
1 Commits
feat/ms23-
...
feat/ms23-
| Author | SHA1 | Date | |
|---|---|---|---|
| 480bf7b0d4 |
@@ -1,54 +0,0 @@
|
|||||||
import {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Delete,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Patch,
|
|
||||||
Post,
|
|
||||||
UseGuards,
|
|
||||||
UsePipes,
|
|
||||||
ValidationPipe,
|
|
||||||
} from "@nestjs/common";
|
|
||||||
import type { AgentProviderConfig } from "@prisma/client";
|
|
||||||
import { OrchestratorApiKeyGuard } from "../../common/guards/api-key.guard";
|
|
||||||
import { OrchestratorThrottlerGuard } from "../../common/guards/throttler.guard";
|
|
||||||
import { AgentProvidersService } from "./agent-providers.service";
|
|
||||||
import { CreateAgentProviderDto } from "./dto/create-agent-provider.dto";
|
|
||||||
import { UpdateAgentProviderDto } from "./dto/update-agent-provider.dto";
|
|
||||||
|
|
||||||
@Controller("agent-providers")
|
|
||||||
@UseGuards(OrchestratorApiKeyGuard, OrchestratorThrottlerGuard)
|
|
||||||
export class AgentProvidersController {
|
|
||||||
constructor(private readonly agentProvidersService: AgentProvidersService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
async list(): Promise<AgentProviderConfig[]> {
|
|
||||||
return this.agentProvidersService.list();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(":id")
|
|
||||||
async getById(@Param("id") id: string): Promise<AgentProviderConfig> {
|
|
||||||
return this.agentProvidersService.getById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
||||||
async create(@Body() dto: CreateAgentProviderDto): Promise<AgentProviderConfig> {
|
|
||||||
return this.agentProvidersService.create(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Patch(":id")
|
|
||||||
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
||||||
async update(
|
|
||||||
@Param("id") id: string,
|
|
||||||
@Body() dto: UpdateAgentProviderDto
|
|
||||||
): Promise<AgentProviderConfig> {
|
|
||||||
return this.agentProvidersService.update(id, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete(":id")
|
|
||||||
async delete(@Param("id") id: string): Promise<AgentProviderConfig> {
|
|
||||||
return this.agentProvidersService.delete(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { Module } from "@nestjs/common";
|
|
||||||
import { PrismaModule } from "../../prisma/prisma.module";
|
|
||||||
import { OrchestratorApiKeyGuard } from "../../common/guards/api-key.guard";
|
|
||||||
import { AgentProvidersController } from "./agent-providers.controller";
|
|
||||||
import { AgentProvidersService } from "./agent-providers.service";
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [PrismaModule],
|
|
||||||
controllers: [AgentProvidersController],
|
|
||||||
providers: [OrchestratorApiKeyGuard, AgentProvidersService],
|
|
||||||
})
|
|
||||||
export class AgentProvidersModule {}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { NotFoundException } from "@nestjs/common";
|
|
||||||
import { AgentProvidersService } from "./agent-providers.service";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
|
|
||||||
describe("AgentProvidersService", () => {
|
|
||||||
let service: AgentProvidersService;
|
|
||||||
let prisma: {
|
|
||||||
agentProviderConfig: {
|
|
||||||
findMany: ReturnType<typeof vi.fn>;
|
|
||||||
findUnique: ReturnType<typeof vi.fn>;
|
|
||||||
create: ReturnType<typeof vi.fn>;
|
|
||||||
update: ReturnType<typeof vi.fn>;
|
|
||||||
delete: ReturnType<typeof vi.fn>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
prisma = {
|
|
||||||
agentProviderConfig: {
|
|
||||||
findMany: vi.fn(),
|
|
||||||
findUnique: vi.fn(),
|
|
||||||
create: vi.fn(),
|
|
||||||
update: vi.fn(),
|
|
||||||
delete: vi.fn(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
service = new AgentProvidersService(prisma as unknown as PrismaService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("lists all provider configs", async () => {
|
|
||||||
const expected = [
|
|
||||||
{
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Primary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
prisma.agentProviderConfig.findMany.mockResolvedValue(expected);
|
|
||||||
|
|
||||||
const result = await service.list();
|
|
||||||
|
|
||||||
expect(prisma.agentProviderConfig.findMany).toHaveBeenCalledWith({
|
|
||||||
orderBy: [{ createdAt: "desc" }, { id: "desc" }],
|
|
||||||
});
|
|
||||||
expect(result).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a single provider config", async () => {
|
|
||||||
const expected = {
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Primary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: { apiKeyRef: "vault:openai" },
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
};
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue(expected);
|
|
||||||
|
|
||||||
const result = await service.getById("cfg-1");
|
|
||||||
|
|
||||||
expect(prisma.agentProviderConfig.findUnique).toHaveBeenCalledWith({
|
|
||||||
where: { id: "cfg-1" },
|
|
||||||
});
|
|
||||||
expect(result).toEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("throws NotFoundException when provider config is missing", async () => {
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue(null);
|
|
||||||
|
|
||||||
await expect(service.getById("missing")).rejects.toBeInstanceOf(NotFoundException);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("creates a provider config with default credentials", async () => {
|
|
||||||
const created = {
|
|
||||||
id: "cfg-created",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "New Provider",
|
|
||||||
provider: "claude",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
};
|
|
||||||
prisma.agentProviderConfig.create.mockResolvedValue(created);
|
|
||||||
|
|
||||||
const result = await service.create({
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "New Provider",
|
|
||||||
provider: "claude",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(prisma.agentProviderConfig.create).toHaveBeenCalledWith({
|
|
||||||
data: {
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "New Provider",
|
|
||||||
provider: "claude",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(result).toEqual(created);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("updates a provider config", async () => {
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue({
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Primary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
});
|
|
||||||
|
|
||||||
const updated = {
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Secondary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway2.example.com",
|
|
||||||
credentials: { apiKeyRef: "vault:new" },
|
|
||||||
isActive: false,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T19:00:00.000Z"),
|
|
||||||
};
|
|
||||||
prisma.agentProviderConfig.update.mockResolvedValue(updated);
|
|
||||||
|
|
||||||
const result = await service.update("cfg-1", {
|
|
||||||
name: "Secondary",
|
|
||||||
gatewayUrl: "https://gateway2.example.com",
|
|
||||||
credentials: { apiKeyRef: "vault:new" },
|
|
||||||
isActive: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(prisma.agentProviderConfig.update).toHaveBeenCalledWith({
|
|
||||||
where: { id: "cfg-1" },
|
|
||||||
data: {
|
|
||||||
name: "Secondary",
|
|
||||||
gatewayUrl: "https://gateway2.example.com",
|
|
||||||
credentials: { apiKeyRef: "vault:new" },
|
|
||||||
isActive: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
expect(result).toEqual(updated);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("throws NotFoundException when updating a missing provider config", async () => {
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue(null);
|
|
||||||
|
|
||||||
await expect(service.update("missing", { name: "Updated" })).rejects.toBeInstanceOf(
|
|
||||||
NotFoundException
|
|
||||||
);
|
|
||||||
expect(prisma.agentProviderConfig.update).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("deletes a provider config", async () => {
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue({
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Primary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
});
|
|
||||||
|
|
||||||
const deleted = {
|
|
||||||
id: "cfg-1",
|
|
||||||
workspaceId: "8bcd7eda-a122-4d6c-adfd-b152f6f75369",
|
|
||||||
name: "Primary",
|
|
||||||
provider: "openai",
|
|
||||||
gatewayUrl: "https://gateway.example.com",
|
|
||||||
credentials: {},
|
|
||||||
isActive: true,
|
|
||||||
createdAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T18:00:00.000Z"),
|
|
||||||
};
|
|
||||||
prisma.agentProviderConfig.delete.mockResolvedValue(deleted);
|
|
||||||
|
|
||||||
const result = await service.delete("cfg-1");
|
|
||||||
|
|
||||||
expect(prisma.agentProviderConfig.delete).toHaveBeenCalledWith({
|
|
||||||
where: { id: "cfg-1" },
|
|
||||||
});
|
|
||||||
expect(result).toEqual(deleted);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("throws NotFoundException when deleting a missing provider config", async () => {
|
|
||||||
prisma.agentProviderConfig.findUnique.mockResolvedValue(null);
|
|
||||||
|
|
||||||
await expect(service.delete("missing")).rejects.toBeInstanceOf(NotFoundException);
|
|
||||||
expect(prisma.agentProviderConfig.delete).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
|
||||||
import type { AgentProviderConfig, Prisma } from "@prisma/client";
|
|
||||||
import { PrismaService } from "../../prisma/prisma.service";
|
|
||||||
import { CreateAgentProviderDto } from "./dto/create-agent-provider.dto";
|
|
||||||
import { UpdateAgentProviderDto } from "./dto/update-agent-provider.dto";
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AgentProvidersService {
|
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
|
||||||
|
|
||||||
async list(): Promise<AgentProviderConfig[]> {
|
|
||||||
return this.prisma.agentProviderConfig.findMany({
|
|
||||||
orderBy: [{ createdAt: "desc" }, { id: "desc" }],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async getById(id: string): Promise<AgentProviderConfig> {
|
|
||||||
const providerConfig = await this.prisma.agentProviderConfig.findUnique({
|
|
||||||
where: { id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!providerConfig) {
|
|
||||||
throw new NotFoundException(`Agent provider config with id ${id} not found`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return providerConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(dto: CreateAgentProviderDto): Promise<AgentProviderConfig> {
|
|
||||||
return this.prisma.agentProviderConfig.create({
|
|
||||||
data: {
|
|
||||||
workspaceId: dto.workspaceId,
|
|
||||||
name: dto.name,
|
|
||||||
provider: dto.provider,
|
|
||||||
gatewayUrl: dto.gatewayUrl,
|
|
||||||
credentials: this.toJsonValue(dto.credentials ?? {}),
|
|
||||||
...(dto.isActive !== undefined ? { isActive: dto.isActive } : {}),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(id: string, dto: UpdateAgentProviderDto): Promise<AgentProviderConfig> {
|
|
||||||
await this.getById(id);
|
|
||||||
|
|
||||||
const data: Prisma.AgentProviderConfigUpdateInput = {
|
|
||||||
...(dto.workspaceId !== undefined ? { workspaceId: dto.workspaceId } : {}),
|
|
||||||
...(dto.name !== undefined ? { name: dto.name } : {}),
|
|
||||||
...(dto.provider !== undefined ? { provider: dto.provider } : {}),
|
|
||||||
...(dto.gatewayUrl !== undefined ? { gatewayUrl: dto.gatewayUrl } : {}),
|
|
||||||
...(dto.isActive !== undefined ? { isActive: dto.isActive } : {}),
|
|
||||||
...(dto.credentials !== undefined ? { credentials: this.toJsonValue(dto.credentials) } : {}),
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.prisma.agentProviderConfig.update({
|
|
||||||
where: { id },
|
|
||||||
data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(id: string): Promise<AgentProviderConfig> {
|
|
||||||
await this.getById(id);
|
|
||||||
|
|
||||||
return this.prisma.agentProviderConfig.delete({
|
|
||||||
where: { id },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private toJsonValue(value: Record<string, unknown>): Prisma.InputJsonValue {
|
|
||||||
return value as Prisma.InputJsonValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { IsBoolean, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
export class CreateAgentProviderDto {
|
|
||||||
@IsUUID()
|
|
||||||
workspaceId!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
name!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
provider!: string;
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
gatewayUrl!: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsObject()
|
|
||||||
credentials?: Record<string, unknown>;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
isActive?: boolean;
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { IsBoolean, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID } from "class-validator";
|
|
||||||
|
|
||||||
export class UpdateAgentProviderDto {
|
|
||||||
@IsOptional()
|
|
||||||
@IsUUID()
|
|
||||||
workspaceId?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
name?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
provider?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
gatewayUrl?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsObject()
|
|
||||||
credentials?: Record<string, unknown>;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
isActive?: boolean;
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import { ThrottlerModule } from "@nestjs/throttler";
|
|||||||
import { HealthModule } from "./api/health/health.module";
|
import { HealthModule } from "./api/health/health.module";
|
||||||
import { AgentsModule } from "./api/agents/agents.module";
|
import { AgentsModule } from "./api/agents/agents.module";
|
||||||
import { QueueApiModule } from "./api/queue/queue-api.module";
|
import { QueueApiModule } from "./api/queue/queue-api.module";
|
||||||
import { AgentProvidersModule } from "./api/agent-providers/agent-providers.module";
|
|
||||||
import { CoordinatorModule } from "./coordinator/coordinator.module";
|
import { CoordinatorModule } from "./coordinator/coordinator.module";
|
||||||
import { BudgetModule } from "./budget/budget.module";
|
import { BudgetModule } from "./budget/budget.module";
|
||||||
import { CIModule } from "./ci";
|
import { CIModule } from "./ci";
|
||||||
@@ -52,7 +51,6 @@ import { orchestratorConfig } from "./config/orchestrator.config";
|
|||||||
]),
|
]),
|
||||||
HealthModule,
|
HealthModule,
|
||||||
AgentsModule,
|
AgentsModule,
|
||||||
AgentProvidersModule,
|
|
||||||
QueueApiModule,
|
QueueApiModule,
|
||||||
CoordinatorModule,
|
CoordinatorModule,
|
||||||
BudgetModule,
|
BudgetModule,
|
||||||
|
|||||||
Reference in New Issue
Block a user