UNPKG

manifest

Version:

Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard

147 lines 6.83 kB
"use strict"; 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.MessageDetailsService = void 0; const common_1 = require("@nestjs/common"); const typeorm_1 = require("@nestjs/typeorm"); const typeorm_2 = require("typeorm"); const agent_message_entity_1 = require("../../entities/agent-message.entity"); const llm_call_entity_1 = require("../../entities/llm-call.entity"); const tool_execution_entity_1 = require("../../entities/tool-execution.entity"); const agent_log_entity_1 = require("../../entities/agent-log.entity"); const tenant_cache_service_1 = require("../../common/services/tenant-cache.service"); let MessageDetailsService = class MessageDetailsService { messageRepo; llmCallRepo; toolRepo; logRepo; tenantCache; constructor(messageRepo, llmCallRepo, toolRepo, logRepo, tenantCache) { this.messageRepo = messageRepo; this.llmCallRepo = llmCallRepo; this.toolRepo = toolRepo; this.logRepo = logRepo; this.tenantCache = tenantCache; } async getDetails(messageId, userId) { const tenantId = await this.tenantCache.resolve(userId); const messageQb = this.messageRepo .createQueryBuilder('m') .where('m.id = :id', { id: messageId }); if (tenantId) { messageQb.andWhere('m.tenant_id = :tenantId', { tenantId }); } else { messageQb.andWhere('m.user_id = :userId', { userId }); } const message = await messageQb.getOne(); if (!message) throw new common_1.NotFoundException('Message not found'); const llmCallsQb = this.llmCallRepo .createQueryBuilder('lc') .where('lc.turn_id = :turnId', { turnId: messageId }) .orderBy('lc.call_index', 'ASC') .addOrderBy('lc.timestamp', 'ASC'); const logsQb = message.trace_id ? this.logRepo .createQueryBuilder('al') .where('al.trace_id = :traceId', { traceId: message.trace_id }) .orderBy('al.timestamp', 'ASC') : null; const [llmCalls, agentLogs] = await Promise.all([ llmCallsQb.getMany(), logsQb ? logsQb.getMany() : Promise.resolve([]), ]); const llmCallIds = llmCalls.map((lc) => lc.id); const toolExecutions = llmCallIds.length > 0 ? await this.toolRepo .createQueryBuilder('te') .where('te.llm_call_id IN (:...ids)', { ids: llmCallIds }) .orderBy('te.llm_call_id', 'ASC') .getMany() : []; return { message: { id: message.id, timestamp: message.timestamp, agent_name: message.agent_name, model: message.model, status: message.status, error_message: message.error_message, error_http_status: message.error_http_status, description: message.description, service_type: message.service_type, input_tokens: message.input_tokens, output_tokens: message.output_tokens, cache_read_tokens: message.cache_read_tokens, cache_creation_tokens: message.cache_creation_tokens, cost_usd: message.cost_usd, duration_ms: message.duration_ms, trace_id: message.trace_id, routing_tier: message.routing_tier, routing_reason: message.routing_reason, auth_type: message.auth_type, skill_name: message.skill_name, fallback_from_model: message.fallback_from_model, fallback_index: message.fallback_index, session_key: message.session_key, }, llm_calls: llmCalls.map((lc) => ({ id: lc.id, call_index: lc.call_index, request_model: lc.request_model, response_model: lc.response_model, gen_ai_system: lc.gen_ai_system, input_tokens: lc.input_tokens, output_tokens: lc.output_tokens, cache_read_tokens: lc.cache_read_tokens, cache_creation_tokens: lc.cache_creation_tokens, duration_ms: lc.duration_ms, ttft_ms: lc.ttft_ms, temperature: lc.temperature, max_output_tokens: lc.max_output_tokens, timestamp: lc.timestamp, })), tool_executions: toolExecutions.map((te) => ({ id: te.id, llm_call_id: te.llm_call_id, tool_name: te.tool_name, duration_ms: te.duration_ms, status: te.status, error_message: te.error_message, })), agent_logs: agentLogs.map((al) => ({ id: al.id, severity: al.severity, body: al.body, timestamp: al.timestamp, span_id: al.span_id, })), }; } }; exports.MessageDetailsService = MessageDetailsService; exports.MessageDetailsService = MessageDetailsService = __decorate([ (0, common_1.Injectable)(), __param(0, (0, typeorm_1.InjectRepository)(agent_message_entity_1.AgentMessage)), __param(1, (0, typeorm_1.InjectRepository)(llm_call_entity_1.LlmCall)), __param(2, (0, typeorm_1.InjectRepository)(tool_execution_entity_1.ToolExecution)), __param(3, (0, typeorm_1.InjectRepository)(agent_log_entity_1.AgentLog)), __metadata("design:paramtypes", [typeorm_2.Repository, typeorm_2.Repository, typeorm_2.Repository, typeorm_2.Repository, tenant_cache_service_1.TenantCacheService]) ], MessageDetailsService); //# sourceMappingURL=message-details.service.js.map