manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
84 lines • 3.98 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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationLogService = void 0;
exports.formatNotificationTimestamp = formatNotificationTimestamp;
const common_1 = require("@nestjs/common");
const typeorm_1 = require("typeorm");
const uuid_1 = require("uuid");
const manifest_runtime_service_1 = require("../../common/services/manifest-runtime.service");
const sql_dialect_1 = require("../../common/utils/sql-dialect");
const local_mode_constants_1 = require("../../common/constants/local-mode.constants");
function formatNotificationTimestamp() {
return new Date().toISOString().replace('T', ' ').replace('Z', '').slice(0, 19);
}
let NotificationLogService = class NotificationLogService {
ds;
runtime;
dialect;
constructor(ds, runtime) {
this.ds = ds;
this.runtime = runtime;
this.dialect = (0, sql_dialect_1.detectDialect)(ds.options.type);
}
sql(query) {
return (0, sql_dialect_1.portableSql)(query, this.dialect);
}
async hasAlreadySent(ruleId, periodStart) {
const rows = await this.ds.query(this.sql(`SELECT 1 FROM notification_logs WHERE rule_id = $1 AND period_start = $2`), [ruleId, periodStart]);
return rows.length > 0;
}
async insertLog(params) {
await this.ds.query(this.sql(`INSERT INTO notification_logs
(id, rule_id, period_start, period_end, actual_value, threshold_value, metric_type, agent_name, sent_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`), [
(0, uuid_1.v4)(),
params.ruleId,
params.periodStart,
params.periodEnd,
params.actualValue,
params.thresholdValue,
params.metricType,
params.agentName,
params.sentAt,
]);
}
async getLogsForAgent(userId, agentName) {
return this.ds.query(this.sql(`SELECT nl.id, nl.sent_at, nl.actual_value, nl.threshold_value,
nl.metric_type, nl.period_start, nl.period_end, nl.agent_name
FROM notification_logs nl
JOIN notification_rules nr ON nr.id = nl.rule_id
WHERE nr.user_id = $1 AND nl.agent_name = $2
ORDER BY nl.sent_at DESC
LIMIT 50`), [userId, agentName]);
}
async resolveUserEmail(userId, notificationEmail) {
if (notificationEmail)
return notificationEmail;
if (this.runtime.isLocalMode()) {
const configEmail = (0, local_mode_constants_1.readLocalNotificationEmail)();
if (configEmail)
return configEmail;
}
const rows = await this.ds.query(this.sql(`SELECT email FROM "user" WHERE id = $1`), [userId]);
const email = rows[0]?.email ?? null;
if (email === local_mode_constants_1.LOCAL_EMAIL)
return null;
return email;
}
};
exports.NotificationLogService = NotificationLogService;
exports.NotificationLogService = NotificationLogService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [typeorm_1.DataSource,
manifest_runtime_service_1.ManifestRuntimeService])
], NotificationLogService);
//# sourceMappingURL=notification-log.service.js.map