feat: harden intelligence runtime and llm providers

This commit is contained in:
2026-05-16 21:18:34 +02:00
parent 7e85a54c32
commit 85f97bb2a6
22 changed files with 732 additions and 201 deletions

View File

@@ -59,9 +59,6 @@ export class DiscordAlerter {
intents: [GatewayIntentBits.Guilds],
});
// Register slash commands
await this._registerCommands(REST, Routes, SlashCommandBuilder);
// Handle slash command interactions
this._client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
@@ -71,9 +68,10 @@ export class DiscordAlerter {
// Connect
await this._client.login(this.botToken);
this._client.once('ready', () => {
this._client.once('clientReady', async () => {
this._ready = true;
console.log(`[Discord] Bot online as ${this._client.user.tag}`);
await this._registerCommands(REST, Routes, SlashCommandBuilder);
});
} catch (err) {
@@ -123,11 +121,13 @@ export class DiscordAlerter {
try {
if (this.guildId) {
// Guild commands (instant, for development)
await rest.put(Routes.applicationGuildCommands(this._client?.user?.id || 'me', this.guildId), { body: commands });
const appId = this._client?.application?.id || this._client?.user?.id;
if (!appId) throw new Error('Discord application id unavailable after login');
await rest.put(Routes.applicationGuildCommands(appId, this.guildId), { body: commands });
console.log(`[Discord] Registered ${commands.length} guild slash commands`);
} else {
// Global commands (can take up to 1h to propagate)
const appId = this._client?.application?.id;
const appId = this._client?.application?.id || this._client?.user?.id;
if (appId) {
await rest.put(Routes.applicationCommands(appId), { body: commands });
console.log(`[Discord] Registered ${commands.length} global slash commands`);

View File

@@ -41,6 +41,8 @@ export class TelegramAlerter {
this._commandHandlers = {}; // Registered command callbacks
this._pollingInterval = null;
this._botUsername = null;
this._pollFailureCount = 0;
this._lastPollErrorLogAt = 0;
}
get isConfigured() {
@@ -353,6 +355,7 @@ export class TelegramAlerter {
const data = await res.json();
if (!data.ok || !Array.isArray(data.result)) return;
this._pollFailureCount = 0;
for (const update of data.result) {
this._lastUpdateId = Math.max(this._lastUpdateId, update.update_id);
@@ -366,9 +369,14 @@ export class TelegramAlerter {
await this._handleMessage(msg);
}
} catch (err) {
// Silent — polling failures are non-fatal
this._pollFailureCount++;
if (!err.message?.includes('aborted')) {
console.error('[Telegram] Poll error:', err.message);
const now = Date.now();
const quietMs = Math.min(300000, 30000 * this._pollFailureCount);
if (now - this._lastPollErrorLogAt > quietMs) {
this._lastPollErrorLogAt = now;
console.error(`[Telegram] Poll degraded (${this._pollFailureCount} consecutive failures):`, err.message);
}
}
}
}