UNPKG

manifest

Version:

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

45 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatTimestamp = formatTimestamp; exports.computeTrend = computeTrend; exports.downsample = downsample; exports.addTenantFilter = addTenantFilter; function formatTimestamp(d) { const p = (n, len = 2) => String(n).padStart(len, '0'); return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}.${p(d.getMilliseconds(), 3)}`; } function computeTrend(current, previous) { const EPS = 1e-6; if (Math.abs(previous) < EPS) return 0; const pct = Math.round(((current - previous) / previous) * 100); return Math.max(-999, Math.min(999, pct)); } function downsample(data, targetLen) { if (data.length <= targetLen) return data; const result = []; const bucketSize = data.length / targetLen; for (let i = 0; i < targetLen; i++) { const start = Math.floor(i * bucketSize); const end = Math.floor((i + 1) * bucketSize); let sum = 0; for (let j = start; j < end; j++) sum += data[j] ?? 0; result.push(sum); } return result; } function addTenantFilter(qb, userId, agentName, tenantId) { if (tenantId) { qb.andWhere('at.tenant_id = :tenantId', { tenantId }); } else { qb.andWhere('at.user_id = :userId', { userId }); } if (agentName) { qb.andWhere('at.agent_name = :agentName', { agentName }); } return qb; } //# sourceMappingURL=query-helpers.js.map