manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
102 lines • 4.44 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentLifecycleService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const agent_entity_1 = require("../../entities/agent.entity");
let AgentLifecycleService = class AgentLifecycleService {
agentRepo;
dataSource;
constructor(agentRepo, dataSource) {
this.agentRepo = agentRepo;
this.dataSource = dataSource;
}
async deleteAgent(userId, agentName) {
const agent = await this.agentRepo
.createQueryBuilder('a')
.leftJoin('a.tenant', 't')
.where('t.name = :userId', { userId })
.andWhere('a.name = :agentName', { agentName })
.getOne();
if (!agent) {
throw new common_1.NotFoundException(`Agent "${agentName}" not found`);
}
await this.agentRepo.delete(agent.id);
}
async renameAgent(userId, currentName, newName, displayName) {
const agent = await this.agentRepo
.createQueryBuilder('a')
.leftJoin('a.tenant', 't')
.where('t.name = :userId', { userId })
.andWhere('a.name = :currentName', { currentName })
.getOne();
if (!agent) {
throw new common_1.NotFoundException(`Agent "${currentName}" not found`);
}
if (newName === currentName) {
if (displayName !== undefined) {
await this.agentRepo
.createQueryBuilder()
.update('agents')
.set({ display_name: displayName })
.where('id = :id', { id: agent.id })
.execute();
}
return;
}
const duplicate = await this.agentRepo
.createQueryBuilder('a')
.leftJoin('a.tenant', 't')
.where('t.name = :userId', { userId })
.andWhere('a.name = :newName', { newName })
.getOne();
if (duplicate) {
throw new common_1.ConflictException(`Agent "${newName}" already exists`);
}
await this.dataSource.transaction(async (manager) => {
const agentUpdate = { name: newName };
if (displayName !== undefined)
agentUpdate['display_name'] = displayName;
await manager
.createQueryBuilder()
.update('agents')
.set(agentUpdate)
.where('id = :id', { id: agent.id })
.execute();
const tables = [
'agent_messages',
'notification_rules',
'notification_logs',
'token_usage_snapshots',
'cost_snapshots',
];
await Promise.all(tables.map((table) => manager
.createQueryBuilder()
.update(table)
.set({ agent_name: newName })
.where('agent_name = :currentName', { currentName })
.execute()));
});
}
};
exports.AgentLifecycleService = AgentLifecycleService;
exports.AgentLifecycleService = AgentLifecycleService = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(agent_entity_1.Agent)),
__metadata("design:paramtypes", [typeorm_2.Repository,
typeorm_2.DataSource])
], AgentLifecycleService);
//# sourceMappingURL=agent-lifecycle.service.js.map