manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
90 lines • 4.74 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); }
};
var RoutingInvalidationService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RoutingInvalidationService = void 0;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("@nestjs/typeorm");
const typeorm_2 = require("typeorm");
const tier_assignment_entity_1 = require("../../entities/tier-assignment.entity");
const model_pricing_cache_service_1 = require("../../model-prices/model-pricing-cache.service");
const tier_auto_assign_service_1 = require("./tier-auto-assign.service");
const routing_cache_service_1 = require("./routing-cache.service");
let RoutingInvalidationService = RoutingInvalidationService_1 = class RoutingInvalidationService {
tierRepo;
pricingCache;
autoAssign;
routingCache;
logger = new common_1.Logger(RoutingInvalidationService_1.name);
constructor(tierRepo, pricingCache, autoAssign, routingCache) {
this.tierRepo = tierRepo;
this.pricingCache = pricingCache;
this.autoAssign = autoAssign;
this.routingCache = routingCache;
}
async invalidateOverridesForRemovedModels(removedModels) {
if (removedModels.length === 0)
return;
const removedSet = new Set(removedModels);
const affected = await this.tierRepo.find({
where: { override_model: (0, typeorm_2.In)(removedModels) },
});
const agentIds = new Set();
const tiersToSave = [];
for (const tier of affected) {
this.logger.warn(`Clearing override ${tier.override_model} for agent ${tier.agent_id} tier ${tier.tier} (model removed)`);
tier.override_model = null;
tier.override_provider = null;
tier.override_auth_type = null;
tier.updated_at = new Date().toISOString();
tiersToSave.push(tier);
agentIds.add(tier.agent_id);
}
const fallbackTiers = agentIds.size > 0
? await this.tierRepo.find({ where: { agent_id: (0, typeorm_2.In)([...agentIds]) } })
: await this.tierRepo.find();
const savedIds = new Set(tiersToSave.map((t) => t.id));
for (const tier of fallbackTiers) {
if (!tier.fallback_models || tier.fallback_models.length === 0)
continue;
const filtered = tier.fallback_models.filter((m) => !removedSet.has(m));
if (filtered.length !== tier.fallback_models.length) {
tier.fallback_models = filtered.length > 0 ? filtered : null;
tier.updated_at = new Date().toISOString();
if (!savedIds.has(tier.id))
tiersToSave.push(tier);
agentIds.add(tier.agent_id);
}
}
if (tiersToSave.length > 0)
await this.tierRepo.save(tiersToSave);
if (agentIds.size === 0)
return;
await Promise.all([...agentIds].map((agentId) => {
this.routingCache.invalidateAgent(agentId);
return this.autoAssign.recalculate(agentId);
}));
this.logger.log(`Invalidated ${affected.length} overrides for ${agentIds.size} agents (removed models: ${removedModels.join(', ')})`);
}
};
exports.RoutingInvalidationService = RoutingInvalidationService;
exports.RoutingInvalidationService = RoutingInvalidationService = RoutingInvalidationService_1 = __decorate([
(0, common_1.Injectable)(),
__param(0, (0, typeorm_1.InjectRepository)(tier_assignment_entity_1.TierAssignment)),
__metadata("design:paramtypes", [typeorm_2.Repository,
model_pricing_cache_service_1.ModelPricingCacheService,
tier_auto_assign_service_1.TierAutoAssignService,
routing_cache_service_1.RoutingCacheService])
], RoutingInvalidationService);
//# sourceMappingURL=routing-invalidation.service.js.map