alvin-bot 5.6.2 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +1 -1
  3. package/dist/claude.js +1 -102
  4. package/dist/config.js +1 -96
  5. package/dist/engine.js +1 -90
  6. package/dist/find-claude-binary.js +1 -98
  7. package/dist/handlers/async-agent-chunk-handler.js +1 -50
  8. package/dist/handlers/background-bypass.js +1 -75
  9. package/dist/handlers/commands.js +1 -2336
  10. package/dist/handlers/cron-progress.js +1 -52
  11. package/dist/handlers/document.js +1 -194
  12. package/dist/handlers/message.js +1 -959
  13. package/dist/handlers/photo.js +1 -154
  14. package/dist/handlers/platform-message.js +1 -360
  15. package/dist/handlers/stuck-timer.js +1 -54
  16. package/dist/handlers/video.js +1 -237
  17. package/dist/handlers/voice.js +1 -148
  18. package/dist/i18n.js +1 -805
  19. package/dist/index.js +1 -697
  20. package/dist/init-data-dir.js +1 -98
  21. package/dist/middleware/auth.js +1 -233
  22. package/dist/migrate.js +1 -162
  23. package/dist/paths.js +1 -146
  24. package/dist/platforms/discord.js +1 -175
  25. package/dist/platforms/index.js +1 -130
  26. package/dist/platforms/signal.js +1 -205
  27. package/dist/platforms/slack-slash-parser.js +1 -32
  28. package/dist/platforms/slack.js +1 -501
  29. package/dist/platforms/telegram.js +1 -111
  30. package/dist/platforms/types.js +1 -8
  31. package/dist/platforms/whatsapp-auth-helpers.js +1 -53
  32. package/dist/platforms/whatsapp.js +1 -707
  33. package/dist/providers/claude-sdk-provider.js +1 -565
  34. package/dist/providers/codex-cli-provider.js +1 -134
  35. package/dist/providers/index.js +1 -7
  36. package/dist/providers/ollama-provider.js +1 -32
  37. package/dist/providers/openai-compatible.js +1 -406
  38. package/dist/providers/registry.js +1 -352
  39. package/dist/providers/runtime-header.js +1 -45
  40. package/dist/providers/tool-executor.js +1 -475
  41. package/dist/providers/types.js +1 -227
  42. package/dist/services/access.js +1 -144
  43. package/dist/services/allowed-users-gate.js +1 -56
  44. package/dist/services/alvin-dispatch.js +1 -130
  45. package/dist/services/alvin-mcp-tools.js +1 -104
  46. package/dist/services/asset-index.js +1 -224
  47. package/dist/services/async-agent-parser.js +1 -418
  48. package/dist/services/async-agent-watcher.js +1 -443
  49. package/dist/services/auto-diagnostic.js +1 -228
  50. package/dist/services/broadcast.js +1 -52
  51. package/dist/services/browser-manager.js +1 -562
  52. package/dist/services/browser-webfetch.js +1 -127
  53. package/dist/services/browser.js +1 -121
  54. package/dist/services/cdp-bootstrap.js +1 -357
  55. package/dist/services/compaction.js +1 -144
  56. package/dist/services/critical-notify.js +1 -203
  57. package/dist/services/cron-resolver.js +1 -58
  58. package/dist/services/cron-scheduling.js +1 -310
  59. package/dist/services/cron.js +1 -861
  60. package/dist/services/custom-tools.js +1 -317
  61. package/dist/services/delivery-queue.js +1 -173
  62. package/dist/services/delivery-registry.js +1 -21
  63. package/dist/services/disk-cleanup.js +1 -203
  64. package/dist/services/elevenlabs.js +1 -58
  65. package/dist/services/embeddings/auto-detect.js +1 -74
  66. package/dist/services/embeddings/fts5.js +1 -108
  67. package/dist/services/embeddings/gemini.js +1 -65
  68. package/dist/services/embeddings/index.js +1 -496
  69. package/dist/services/embeddings/ollama.js +1 -78
  70. package/dist/services/embeddings/openai.js +1 -49
  71. package/dist/services/embeddings/provider.js +1 -22
  72. package/dist/services/embeddings/vector-base.js +1 -113
  73. package/dist/services/embeddings-migration.js +1 -193
  74. package/dist/services/embeddings.js +1 -9
  75. package/dist/services/env-file.js +1 -50
  76. package/dist/services/exec-guard.js +1 -71
  77. package/dist/services/fallback-order.js +1 -154
  78. package/dist/services/file-permissions.js +1 -93
  79. package/dist/services/heartbeat-file.js +1 -65
  80. package/dist/services/heartbeat.js +1 -313
  81. package/dist/services/hooks.js +1 -44
  82. package/dist/services/imagegen.js +1 -72
  83. package/dist/services/language-detect.js +1 -154
  84. package/dist/services/markdown.js +1 -63
  85. package/dist/services/mcp.js +1 -263
  86. package/dist/services/memory-extractor.js +1 -178
  87. package/dist/services/memory-inject-mode.js +1 -43
  88. package/dist/services/memory-layers.js +1 -156
  89. package/dist/services/memory.js +1 -146
  90. package/dist/services/ollama-manager.js +1 -339
  91. package/dist/services/permissions-wizard.js +1 -291
  92. package/dist/services/personality.js +1 -376
  93. package/dist/services/plugins.js +1 -171
  94. package/dist/services/preflight.js +1 -292
  95. package/dist/services/process-manager.js +1 -291
  96. package/dist/services/release-highlights.js +1 -79
  97. package/dist/services/reminders.js +1 -97
  98. package/dist/services/restart.js +1 -48
  99. package/dist/services/security-audit.js +1 -74
  100. package/dist/services/self-diagnosis.js +1 -272
  101. package/dist/services/self-search.js +1 -129
  102. package/dist/services/session-persistence.js +1 -237
  103. package/dist/services/session.js +1 -282
  104. package/dist/services/skills.js +1 -290
  105. package/dist/services/ssrf-guard.js +1 -162
  106. package/dist/services/standing-orders.js +1 -29
  107. package/dist/services/steer-channel.js +1 -46
  108. package/dist/services/stop-controller.js +1 -52
  109. package/dist/services/subagent-dedup.js +1 -0
  110. package/dist/services/subagent-delivery.js +1 -452
  111. package/dist/services/subagent-stats.js +1 -123
  112. package/dist/services/subagents.js +1 -814
  113. package/dist/services/sudo.js +1 -329
  114. package/dist/services/telegram.js +1 -158
  115. package/dist/services/timing-safe-bearer.js +1 -51
  116. package/dist/services/tool-discovery.js +1 -214
  117. package/dist/services/trends.js +1 -580
  118. package/dist/services/updater.js +1 -291
  119. package/dist/services/usage-tracker.js +1 -144
  120. package/dist/services/users.js +1 -271
  121. package/dist/services/voice.js +1 -104
  122. package/dist/services/watchdog-brake.js +1 -154
  123. package/dist/services/watchdog.js +1 -311
  124. package/dist/services/workspaces.js +1 -276
  125. package/dist/tui/index.js +1 -667
  126. package/dist/util/console-formatter.js +1 -109
  127. package/dist/util/debounce.js +1 -24
  128. package/dist/util/telegram-error-filter.js +1 -62
  129. package/dist/version.js +1 -24
  130. package/dist/web/bind-strategy.js +1 -42
  131. package/dist/web/canvas.js +1 -30
  132. package/dist/web/doctor-api.js +1 -604
  133. package/dist/web/openai-compat.js +1 -252
  134. package/dist/web/server.js +1 -1831
  135. package/dist/web/setup-api.js +1 -1101
  136. package/package.json +5 -2
  137. package/dist/.metadata_never_index +0 -0
package/dist/index.js CHANGED
@@ -1,697 +1 @@
1
- // ── Bootstrap: ensure ~/.alvin-bot/ exists + migrate legacy data ────
2
- import { ensureDataDirs, seedDefaults } from "./init-data-dir.js";
3
- import { hasLegacyData, migrateFromLegacy } from "./migrate.js";
4
- import { installConsoleFormatter } from "./util/console-formatter.js";
5
- import { isHarmlessTelegramError } from "./util/telegram-error-filter.js";
6
- // 0. Install timestamp + noise-filter formatters on console.* so every
7
- // line in out.log / err.log carries an ISO timestamp and libsignal's
8
- // SessionEntry dumps stop burying the signal.
9
- installConsoleFormatter();
10
- // 1. Create directory structure (no files yet)
11
- ensureDataDirs();
12
- // 2. Migrate legacy data BEFORE seeding defaults (so real data wins over templates)
13
- if (hasLegacyData()) {
14
- console.log("📦 Legacy data detected in repo — migrating to ~/.alvin-bot/ ...");
15
- const result = migrateFromLegacy();
16
- if (result.copied.length > 0) {
17
- console.log(` Copied: ${result.copied.join(", ")}`);
18
- }
19
- console.log(" Migration done. Old files left in place (clean up manually).");
20
- }
21
- // 3. Seed defaults for any files that don't exist yet (fresh install)
22
- seedDefaults();
23
- // 3b. v4.20 — One-shot migration of legacy .embeddings.json → SQLite (.embeddings.db).
24
- // Idempotent and safe: source JSON is renamed to .bak-pre-sqlite after success.
25
- import { shouldMigrateEmbeddingsToSqlite, migrateEmbeddingsToSqlite } from "./services/embeddings-migration.js";
26
- if (shouldMigrateEmbeddingsToSqlite()) {
27
- try {
28
- migrateEmbeddingsToSqlite();
29
- }
30
- catch (err) {
31
- console.error("❌ Embeddings migration failed — bot will continue with empty SQLite store, JSON kept:", err);
32
- }
33
- }
34
- // 3a. v4.12.2 — Audit + repair permissions on sensitive files. On multi-user
35
- // systems, files written pre-v4.12.2 may have 0o644 / 0o666 mode — i.e.
36
- // readable by other users on the same machine. This routine chmod-repairs
37
- // them to 0o600 (owner read/write only) at every startup. Idempotent for
38
- // already-secure files; silent no-op for missing files.
39
- import { auditSensitiveFiles } from "./services/file-permissions.js";
40
- import { ENV_FILE as SEC_ENV, SESSIONS_STATE_FILE, MEMORY_FILE, CRON_FILE as SEC_CRON } from "./paths.js";
41
- import { readdirSync } from "fs";
42
- import { resolve as pathResolve } from "path";
43
- import { MEMORY_DIR as SEC_MEM_DIR, DATA_DIR as SEC_DATA_DIR } from "./paths.js";
44
- {
45
- const sensitivePaths = [SEC_ENV, SESSIONS_STATE_FILE, MEMORY_FILE, SEC_CRON];
46
- // Also audit every daily-log markdown file — they contain full conversation history
47
- try {
48
- if (readdirSync.length !== undefined) {
49
- for (const entry of readdirSync(SEC_MEM_DIR)) {
50
- if (entry.endsWith(".md") && !entry.startsWith(".")) {
51
- sensitivePaths.push(pathResolve(SEC_MEM_DIR, entry));
52
- }
53
- }
54
- }
55
- }
56
- catch {
57
- // memory dir missing — fine
58
- }
59
- // Also include async-agents state, delivery queue, and sudo credentials
60
- const optionalPaths = [
61
- pathResolve(SEC_DATA_DIR, "state", "async-agents.json"),
62
- pathResolve(SEC_DATA_DIR, "delivery-queue.json"),
63
- pathResolve(SEC_DATA_DIR, "data", ".sudo-enc"),
64
- pathResolve(SEC_DATA_DIR, "data", ".sudo-key"),
65
- pathResolve(SEC_DATA_DIR, "data", "access.json"),
66
- pathResolve(SEC_DATA_DIR, "data", "approved-users.json"),
67
- ];
68
- sensitivePaths.push(...optionalPaths);
69
- const auditResults = auditSensitiveFiles(sensitivePaths);
70
- const repaired = auditResults.filter(r => r.status === "repaired");
71
- if (repaired.length > 0) {
72
- console.log(`🔒 file-permissions: repaired ${repaired.length} sensitive file(s) to 0o600`);
73
- for (const r of repaired) {
74
- console.log(` ${r.path} (was 0o${r.previousMode})`);
75
- }
76
- }
77
- const errors = auditResults.filter(r => r.status === "error");
78
- if (errors.length > 0) {
79
- console.warn(`⚠️ file-permissions: ${errors.length} file(s) could not be repaired:`);
80
- for (const r of errors) {
81
- console.warn(` ${r.path}: ${r.error}`);
82
- }
83
- }
84
- // M5: Ensure DATA_DIR itself is 0700 (owner-only traverse). ensureDataDirs()
85
- // above handles new installs; this belt-and-suspenders catches the case where
86
- // the dir was created by a pre-M5 version with 0755 and the bot is restarting.
87
- if (process.platform !== "win32") {
88
- try {
89
- const { chmodSync } = await import("fs");
90
- chmodSync(SEC_DATA_DIR, 0o700);
91
- }
92
- catch {
93
- // Best-effort — network filesystems may not support chmod
94
- }
95
- }
96
- }
97
- // 4. Crash-loop brake check — if we've crashed N times in a short window,
98
- // refuse to start, write an alert file, and unload our LaunchAgent so
99
- // launchd stops retrying. Runs BEFORE any expensive init so a broken
100
- // state file doesn't tank the whole CPU.
101
- checkCrashLoopBrake();
102
- // ── Normal imports (safe now — DATA_DIR is ready) ──────────────────
103
- import { Bot, InlineKeyboard } from "grammy";
104
- import { config } from "./config.js";
105
- // ── Pre-flight config validation (warnings, not fatal) ──────────────
106
- const hasTelegram = !!config.botToken;
107
- let hasProvider = true;
108
- if (!hasTelegram) {
109
- console.warn("⚠️ BOT_TOKEN not set — Telegram disabled. WebUI + Cron still active.");
110
- console.warn(" Run 'alvin-bot setup' or set BOT_TOKEN in ~/.alvin-bot/.env");
111
- }
112
- // v4.12.2 — ALLOWED_USERS startup gate. Refuses to start when Telegram is
113
- // configured but no user allowlist is set, because that would leave the bot
114
- // open to any Telegram user with full shell/filesystem access via prompt
115
- // injection. See src/services/allowed-users-gate.ts for the pure decision
116
- // function + tests.
117
- {
118
- const { checkAllowedUsersGate } = await import("./services/allowed-users-gate.js");
119
- const gate = checkAllowedUsersGate({
120
- hasTelegram,
121
- allowedUsersCount: config.allowedUsers.length,
122
- authMode: config.authMode,
123
- insecureAcknowledged: process.env.ALVIN_INSECURE_ACKNOWLEDGED === "1",
124
- });
125
- if (!gate.allowed) {
126
- console.error("");
127
- console.error("❌ CRITICAL: Alvin Bot refusing to start.");
128
- console.error("");
129
- console.error(" " + gate.reason);
130
- console.error("");
131
- process.exit(1);
132
- }
133
- if (gate.warning) {
134
- console.warn("⚠️ " + gate.warning);
135
- }
136
- }
137
- // Check if the chosen provider has a corresponding API key.
138
- // Keys here MUST match the registry keys from src/providers/registry.ts
139
- // (createRegistry). Providers that authenticate differently (claude-sdk
140
- // via OAuth, codex-cli/ollama via local binary) are deliberately absent.
141
- // Custom providers from docs/custom-models.json handle their own apiKeyEnv.
142
- const providerKeyMap = {
143
- google: "GOOGLE_API_KEY",
144
- // Legacy custom-model aliases kept so older configs don't break their
145
- // pre-flight warning — if users have these as primary they're coming
146
- // from docs/custom-models.json.
147
- groq: "GROQ_API_KEY",
148
- openai: "OPENAI_API_KEY",
149
- openrouter: "OPENROUTER_API_KEY",
150
- "nvidia-llama-3.3-70b": "NVIDIA_API_KEY",
151
- "nvidia-kimi-k2.5": "NVIDIA_API_KEY",
152
- "gpt-4o": "OPENAI_API_KEY",
153
- };
154
- const requiredKey = providerKeyMap[config.primaryProvider];
155
- if (requiredKey) {
156
- const keyName = requiredKey.replace("_API_KEY", "").toLowerCase();
157
- if (!config.apiKeys[keyName]) {
158
- hasProvider = false;
159
- console.warn(`⚠️ ${requiredKey} is missing — AI chat won't work until configured.`);
160
- console.warn(` Your provider "${config.primaryProvider}" needs this key.`);
161
- console.warn(` Run 'alvin-bot setup' or edit ~/.alvin-bot/.env`);
162
- }
163
- }
164
- import { authMiddleware, addApprovedUser, removePendingPairing } from "./middleware/auth.js";
165
- import { registerCommands } from "./handlers/commands.js";
166
- import { handleMessage } from "./handlers/message.js";
167
- import { handlePhoto } from "./handlers/photo.js";
168
- import { handleVoice } from "./handlers/voice.js";
169
- import { handleDocument } from "./handlers/document.js";
170
- import { handleVideo } from "./handlers/video.js";
171
- import { initEngine } from "./engine.js";
172
- import { loadPlugins, registerPluginCommands, unloadPlugins } from "./services/plugins.js";
173
- import { initMCP, disconnectMCP, hasMCPConfig } from "./services/mcp.js";
174
- import { startWebServer, stopWebServer } from "./web/server.js";
175
- import { startScheduler, stopScheduler, setNotifyCallback } from "./services/cron.js";
176
- import { startWatcher as startAsyncAgentWatcher, stopWatcher as stopAsyncAgentWatcher } from "./services/async-agent-watcher.js";
177
- import { startSessionCleanup, stopSessionCleanup, attachPersistHook } from "./services/session.js";
178
- import { loadPersistedSessions, flushSessions, schedulePersist, } from "./services/session-persistence.js";
179
- import { processQueue, cleanupQueue, setSenders, enqueue } from "./services/delivery-queue.js";
180
- import { discoverTools } from "./services/tool-discovery.js";
181
- import { startHeartbeat, stopHeartbeat } from "./services/heartbeat.js";
182
- import { stopAutoUpdateLoop } from "./services/updater.js";
183
- import { startCleanupLoop, stopCleanupLoop } from "./services/disk-cleanup.js";
184
- import { flushProfiles } from "./services/users.js";
185
- import { initEmbeddings } from "./services/embeddings.js";
186
- import { loadSkills } from "./services/skills.js";
187
- import { loadHooks } from "./services/hooks.js";
188
- import { registerShutdownHandler } from "./services/restart.js";
189
- import { cancelAllSubAgents } from "./services/subagents.js";
190
- import { startWatchdog, stopWatchdog, checkCrashLoopBrake, markExpectedRestart } from "./services/watchdog.js";
191
- import { getRegistry } from "./engine.js";
192
- import { scanAssets } from "./services/asset-index.js";
193
- // Scan asset directory and generate INDEX.json + INDEX.md
194
- const assetScanResult = scanAssets();
195
- if (assetScanResult.assets.length > 0) {
196
- console.log(`📂 Assets: ${assetScanResult.assets.length} files indexed`);
197
- }
198
- // Discover available system tools (cached for prompt injection)
199
- discoverTools();
200
- // Load skill files
201
- loadSkills();
202
- // v4.12.0 — Workspace registry: load per-channel configs and start the
203
- // hot-reload watcher. Safe no-op if no workspaces are configured.
204
- import { initWorkspaces, stopWorkspaceWatcher } from "./services/workspaces.js";
205
- initWorkspaces();
206
- // Load user-defined lifecycle hooks from ~/.alvin-bot/hooks/
207
- const hookCount = loadHooks();
208
- if (hookCount > 0)
209
- console.log(`Hooks: ${hookCount} loaded`);
210
- // Initialize multi-model engine (skip if no provider key)
211
- let registry = null;
212
- if (hasProvider) {
213
- registry = initEngine();
214
- console.log(`Engine initialized. Primary: ${registry.getActiveKey()}`);
215
- }
216
- else {
217
- console.warn("⚠️ Engine not initialized — no AI provider configured.");
218
- }
219
- // Pre-Flight Sanity Check (Self-Preservation Phase 1, feature 1A) —
220
- // runs in parallel, fire-and-forget. Does NOT block startup.
221
- // Catches misconfigurations + degraded state at boot time.
222
- import("./services/preflight.js")
223
- .then(({ runPreFlight, formatPreFlightReport }) => runPreFlight(config.botToken, registry).then((report) => {
224
- console.log(formatPreFlightReport(report));
225
- }))
226
- .catch((err) => {
227
- // Pre-Flight itself must never crash the bot.
228
- console.warn("⚠️ Pre-Flight check threw:", err?.message || err);
229
- });
230
- // AI Self-Diagnosis startup analyzer (Self-Preservation Phase 2, 3I).
231
- // Scans ~/.alvin-bot/diagnostics/ for forensic bundles without a
232
- // .analysis.md sidecar and runs AI analysis on each. Findings land on
233
- // the operator's phone via 1D Telegram channel within ~30 s of the
234
- // bot recovering from a brake. Fire-and-forget, never blocks startup.
235
- // Provider-agnostic: uses the active Provider's query() async generator.
236
- import("./services/self-diagnosis.js")
237
- .then(({ runStartupAnalyzer }) => runStartupAnalyzer(registry))
238
- .catch((err) => {
239
- console.warn("⚠️ Self-diagnosis analyzer threw:", err?.message || err);
240
- });
241
- // Predictive-Maintenance Trends collector (Self-Preservation Phase 2, 3J).
242
- // Snapshots health metrics every 24 h (first one after 60 s warmup).
243
- // After 7 days of data, also runs AI anomaly detection daily.
244
- // If a concerning trend is flagged → DM operator via 1D channel.
245
- import("./services/trends.js")
246
- .then(({ startTrendsCollector }) => startTrendsCollector(registry))
247
- .catch((err) => {
248
- console.warn("⚠️ Trends collector threw:", err?.message || err);
249
- });
250
- // Load plugins
251
- const pluginResult = await loadPlugins();
252
- if (pluginResult.loaded.length > 0) {
253
- console.log(`Plugins loaded: ${pluginResult.loaded.join(", ")}`);
254
- }
255
- if (pluginResult.errors.length > 0) {
256
- for (const err of pluginResult.errors) {
257
- console.error(`Plugin error (${err.name}): ${err.error}`);
258
- }
259
- }
260
- // Initialize MCP servers (if configured)
261
- if (hasMCPConfig()) {
262
- const mcpResult = await initMCP();
263
- if (mcpResult.connected.length > 0) {
264
- console.log(`MCP servers: ${mcpResult.connected.join(", ")}`);
265
- }
266
- if (mcpResult.errors.length > 0) {
267
- for (const err of mcpResult.errors) {
268
- console.error(`MCP error (${err.name}): ${err.error}`);
269
- }
270
- }
271
- }
272
- // Telegram bot instance (null if no BOT_TOKEN)
273
- let bot = null;
274
- if (hasTelegram) {
275
- bot = new Bot(config.botToken);
276
- // Wire the sub-agent delivery router so async agent finals can reach
277
- // Telegram (cron-spawned agents, user-spawned async finals, shutdown
278
- // cancellation notifications). Lazy-import avoids a top-level cycle.
279
- const { attachBotApi } = await import("./services/subagent-delivery.js");
280
- const botRef = bot;
281
- attachBotApi({
282
- sendMessage: (chatId, text, opts) => botRef.api.sendMessage(chatId, text, opts),
283
- sendDocument: (chatId, doc, opts) => botRef.api.sendDocument(chatId, doc, opts),
284
- editMessageText: (chatId, messageId, text, opts) => botRef.api.editMessageText(chatId, messageId, text, opts),
285
- });
286
- // Auth middleware — alle Messages durchlaufen das
287
- bot.use(authMiddleware);
288
- // Commands registrieren
289
- registerCommands(bot);
290
- registerPluginCommands(bot);
291
- // ── WhatsApp Approval Callbacks ──────────────────────────────────────────────
292
- bot.callbackQuery(/^wa:approve:(.+)$/, async (ctx) => {
293
- const approvalId = ctx.match[1];
294
- const { removePendingApproval, getWhatsAppAdapter } = await import("./platforms/whatsapp.js");
295
- const pending = removePendingApproval(approvalId);
296
- if (!pending) {
297
- await ctx.answerCallbackQuery("⏰ Anfrage abgelaufen");
298
- await ctx.editMessageText(ctx.msg?.text + "\n\n⏰ _Abgelaufen_", { parse_mode: "Markdown" }).catch(() => { });
299
- return;
300
- }
301
- await ctx.answerCallbackQuery("✅ Approved");
302
- await ctx.editMessageText(ctx.msg?.text + `\n\n✅ Approved`, { parse_mode: "HTML" }).catch(() => { });
303
- // Process the message through the platform handler
304
- const adapter = getWhatsAppAdapter();
305
- if (adapter) {
306
- adapter.processApprovedMessage(pending.incoming).catch(err => console.error("WhatsApp approved message processing error:", err));
307
- }
308
- });
309
- bot.callbackQuery(/^wa:deny:(.+)$/, async (ctx) => {
310
- const approvalId = ctx.match[1];
311
- const { removePendingApproval } = await import("./platforms/whatsapp.js");
312
- const pending = removePendingApproval(approvalId);
313
- await ctx.answerCallbackQuery("❌ Abgelehnt");
314
- await ctx.editMessageText((ctx.msg?.text || "") + `\n\n❌ Abgelehnt`, { parse_mode: "HTML" }).catch(() => { });
315
- // Clean up temp media files
316
- if (pending?.incoming.media?.path) {
317
- const fs = await import("fs");
318
- fs.unlink(pending.incoming.media.path, () => { });
319
- }
320
- });
321
- // ── DM Pairing Approval Callbacks ───────────────────────────────────────────
322
- bot.callbackQuery(/^pair:(approve|deny):(\d+)$/, async (ctx) => {
323
- const action = ctx.match[1];
324
- const code = ctx.match[2];
325
- const pairing = removePendingPairing(code);
326
- if (!pairing) {
327
- await ctx.answerCallbackQuery("⏰ Request expired or already handled");
328
- await ctx.editMessageText((ctx.msg?.text || "") + "\n\n⏰ _Expired_", { parse_mode: "Markdown" }).catch(() => { });
329
- return;
330
- }
331
- if (action === "approve") {
332
- addApprovedUser(pairing.userId);
333
- await ctx.answerCallbackQuery("✅ User approved");
334
- const userTag = pairing.username ? `@${pairing.username}` : `ID ${pairing.userId}`;
335
- await ctx.editMessageText((ctx.msg?.text || "") + `\n\n✅ Approved — ${userTag} can now chat with the bot.`, { parse_mode: "Markdown" }).catch(() => { });
336
- // Notify the user they've been approved
337
- try {
338
- await ctx.api.sendMessage(pairing.userId, "✅ You've been approved! You can now chat with the bot.");
339
- }
340
- catch { /* user may have blocked the bot */ }
341
- }
342
- else {
343
- await ctx.answerCallbackQuery("❌ User denied");
344
- const userTag = pairing.username ? `@${pairing.username}` : `ID ${pairing.userId}`;
345
- await ctx.editMessageText((ctx.msg?.text || "") + `\n\n❌ Denied — ${userTag} will not be able to chat.`, { parse_mode: "Markdown" }).catch(() => { });
346
- // Notify the user they've been denied
347
- try {
348
- await ctx.api.sendMessage(pairing.userId, "❌ Your access request was denied by the admin.");
349
- }
350
- catch { /* user may have blocked the bot */ }
351
- }
352
- });
353
- // Content handlers (Reihenfolge wichtig: spezifisch vor allgemein)
354
- bot.on("message:voice", handleVoice);
355
- bot.on("message:video", handleVideo);
356
- bot.on("message:video_note", handleVideo);
357
- bot.on("message:photo", handlePhoto);
358
- bot.on("message:document", handleDocument);
359
- bot.on("message:text", handleMessage);
360
- // Error handling — log but don't crash.
361
- bot.catch((err) => {
362
- const ctx = err.ctx;
363
- const e = err.error;
364
- // Swallow the well-known harmless grammy races (message is not
365
- // modified, query too old, message to edit not found …) silently.
366
- // See src/util/telegram-error-filter.ts for the exhaustive list.
367
- if (isHarmlessTelegramError(e))
368
- return;
369
- console.error(`Error handling update ${ctx?.update?.update_id}:`, e);
370
- // Try to notify the user
371
- if (ctx?.chat?.id) {
372
- ctx.reply("⚠️ An internal error occurred. Please try again.").catch(() => { });
373
- }
374
- });
375
- }
376
- // Delivery queue intervals (started later, cleared on shutdown)
377
- let queueInterval = null;
378
- let queueCleanupInterval = null;
379
- // Graceful shutdown
380
- let isShuttingDown = false;
381
- const shutdown = async () => {
382
- if (isShuttingDown)
383
- return;
384
- isShuttingDown = true;
385
- console.log("Graceful shutdown initiated...");
386
- // Mark the imminent exit as an intentional restart so the next boot's
387
- // decideBrakeAction does not count it as a crash. This covers launchctl
388
- // unload/load (SIGTERM from launchd) in addition to /restart and /update
389
- // which call markExpectedRestart() themselves before process.exit(0).
390
- // Must run before stopWatchdog() (which just clears timers, not the beacon).
391
- markExpectedRestart();
392
- // E2: shutdown-notification — await the async cancellation so running
393
- // agents can post a cancellation message to Telegram before the bot
394
- // stops. Capped at 5s internally so a hang can't block shutdown.
395
- await cancelAllSubAgents(true);
396
- stopWatchdog();
397
- stopScheduler();
398
- stopAsyncAgentWatcher();
399
- stopSessionCleanup();
400
- stopWorkspaceWatcher();
401
- stopHeartbeat();
402
- stopAutoUpdateLoop();
403
- stopCleanupLoop();
404
- // v4.11.0 — Final immediate flush of in-memory sessions to disk before exit.
405
- // The debounced timer might be pending; flushSessions() cancels it and writes
406
- // synchronously so the next boot can rehydrate the latest state.
407
- await flushSessions().catch((err) => console.warn("[shutdown] flushSessions failed:", err));
408
- try {
409
- flushProfiles();
410
- }
411
- catch (err) {
412
- console.warn("[shutdown] flushProfiles failed:", err);
413
- }
414
- if (queueInterval)
415
- clearInterval(queueInterval);
416
- if (queueCleanupInterval)
417
- clearInterval(queueCleanupInterval);
418
- // Await grammy's stop so the Telegram update-offset gets committed BEFORE
419
- // we tear down the rest. Without this, the next boot could re-process
420
- // the last batch of messages. See src/services/restart.ts for context.
421
- if (bot) {
422
- await bot.stop().catch((err) => console.warn("[shutdown] bot.stop failed:", err));
423
- }
424
- // Release :3100 so the next launchd boot doesn't hit EADDRINUSE.
425
- // Must happen before exit — see src/web/server.ts stopWebServer() comment.
426
- await stopWebServer().catch((err) => console.warn("[shutdown] stopWebServer failed:", err));
427
- await unloadPlugins().catch(() => { });
428
- await disconnectMCP().catch(() => { });
429
- // Tear down any bot-managed local runners (Ollama, LM Studio, …) so VRAM
430
- // is freed and no daemon outlives the bot as a zombie. Iterates generically
431
- // over every registered provider that exposes a lifecycle.
432
- try {
433
- const registry = getRegistry();
434
- const providers = await registry.listAll();
435
- for (const p of providers) {
436
- const provider = registry.get(p.key);
437
- if (provider?.lifecycle?.isBotManaged()) {
438
- console.log(`Tearing down bot-managed ${p.key}...`);
439
- await provider.lifecycle.ensureStopped().catch((err) => {
440
- console.warn(`${p.key} shutdown teardown failed:`, err);
441
- });
442
- }
443
- }
444
- }
445
- catch (err) {
446
- console.warn("lifecycle teardown failed:", err);
447
- }
448
- console.log("Goodbye! 👋");
449
- process.exit(0);
450
- };
451
- // Register for graceful self-restart (used by tool-executor when AI triggers restart)
452
- registerShutdownHandler(shutdown);
453
- process.on("SIGINT", shutdown);
454
- process.on("SIGTERM", shutdown);
455
- process.on("uncaughtException", (err) => {
456
- console.error("Uncaught exception:", err);
457
- // Don't exit on uncaught exceptions — try to keep running
458
- });
459
- process.on("unhandledRejection", (reason) => {
460
- console.error("Unhandled rejection:", reason);
461
- });
462
- // Start optional platform adapters via Platform Manager
463
- async function startOptionalPlatforms() {
464
- const { handlePlatformMessage } = await import("./handlers/platform-message.js");
465
- const { autoLoadPlatforms, startAllAdapters, getAllAdapters } = await import("./platforms/index.js");
466
- const loaded = await autoLoadPlatforms();
467
- if (loaded.length > 0) {
468
- await startAllAdapters(async (msg) => {
469
- const adapter = getAllAdapters().find(a => a.platform === msg.platform);
470
- if (adapter)
471
- await handlePlatformMessage(msg, adapter);
472
- });
473
- const icons = { whatsapp: "📱", discord: "🎮", signal: "🔒" };
474
- for (const p of loaded) {
475
- console.log(`${icons[p] || "📡"} ${p.charAt(0).toUpperCase() + p.slice(1)} platform started`);
476
- }
477
- // Wire WhatsApp approval flow — routes to best available channel
478
- if (loaded.includes("whatsapp") && bot) {
479
- const { setApprovalRequestFn, setApprovalChannel, getWhatsAppAdapter } = await import("./platforms/whatsapp.js");
480
- const telegramBot = bot; // capture for closure
481
- setApprovalRequestFn(async (pending) => {
482
- const mediaTag = pending.mediaType ? ` [${pending.mediaType}]` : "";
483
- // ── Strategy: Try Telegram first → fallback to WhatsApp DM → Discord → Signal
484
- let sent = false;
485
- // 1. Telegram (preferred — has inline keyboards)
486
- if (!sent && config.botToken && config.allowedUsers.length > 0) {
487
- try {
488
- const ownerChatId = config.allowedUsers[0];
489
- const msgText = `💬 <b>WhatsApp Approval</b>\n\n` +
490
- `<b>Gruppe:</b> ${pending.groupName}\n` +
491
- `<b>Von:</b> ${pending.senderName} (+${pending.senderNumber})\n` +
492
- `<b>Message:</b>${mediaTag}\n` +
493
- `<blockquote>${pending.preview || "(no text)"}</blockquote>`;
494
- const keyboard = new InlineKeyboard()
495
- .text("✅ Approve", `wa:approve:${pending.id}`)
496
- .text("❌ Ablehnen", `wa:deny:${pending.id}`);
497
- await telegramBot.api.sendMessage(ownerChatId, msgText, {
498
- parse_mode: "HTML",
499
- reply_markup: keyboard,
500
- });
501
- setApprovalChannel("telegram");
502
- sent = true;
503
- }
504
- catch (err) {
505
- console.warn("Approval via Telegram failed, trying fallback:", err instanceof Error ? err.message : err);
506
- }
507
- }
508
- // 2. WhatsApp DM (self-chat) — text-based approval
509
- if (!sent) {
510
- try {
511
- const adapter = getWhatsAppAdapter();
512
- const ownerWaId = adapter?.getOwnerChatId();
513
- if (adapter && ownerWaId) {
514
- const plainText = `🔐 *WhatsApp Approval*\n\n` +
515
- `*Gruppe:* ${pending.groupName}\n` +
516
- `*Von:* ${pending.senderName} (+${pending.senderNumber})\n` +
517
- `*Message:*${mediaTag}\n` +
518
- `> ${pending.preview || "(no text)"}\n\n` +
519
- `Antworte *ok* oder *nein*`;
520
- await adapter.sendText(ownerWaId, plainText);
521
- setApprovalChannel("whatsapp");
522
- sent = true;
523
- }
524
- }
525
- catch (err) {
526
- console.warn("Approval via WhatsApp DM failed, trying fallback:", err instanceof Error ? err.message : err);
527
- }
528
- }
529
- // 3. Discord DM
530
- if (!sent) {
531
- try {
532
- const { getAdapter } = await import("./platforms/index.js");
533
- const discord = getAdapter("discord");
534
- if (discord) {
535
- await discord.sendText("owner", `🔐 WhatsApp Approval\n\nGroup: ${pending.groupName}\nFrom: ${pending.senderName} (+${pending.senderNumber})\nMessage:${mediaTag}\n> ${pending.preview || "(no text)"}\n\nReact with ✅ or ❌`);
536
- setApprovalChannel("discord");
537
- sent = true;
538
- }
539
- }
540
- catch { /* Discord not available */ }
541
- }
542
- // 4. Signal
543
- if (!sent) {
544
- try {
545
- const { getAdapter } = await import("./platforms/index.js");
546
- const signal = getAdapter("signal");
547
- if (signal) {
548
- await signal.sendText("owner", `🔐 WhatsApp Approval\n\nGroup: ${pending.groupName}\nFrom: ${pending.senderName}\nMessage: ${pending.preview || "(no text)"}\n\nReply ok or no`);
549
- setApprovalChannel("signal");
550
- sent = true;
551
- }
552
- }
553
- catch { /* Signal not available */ }
554
- }
555
- if (!sent) {
556
- console.error("❌ No channel available for WhatsApp approval! Auto-denying.");
557
- }
558
- });
559
- }
560
- }
561
- }
562
- startOptionalPlatforms().catch(err => console.error("Platform startup error:", err));
563
- // Start Web UI (ALWAYS — regardless of Telegram/AI config).
564
- // startWebServer is now non-blocking and will never throw: if port 3100
565
- // is busy (foreign process, TIME_WAIT, another bot instance), it climbs
566
- // the port ladder up to 3119 and then enters a background retry loop
567
- // at 3100 every 30s. The Telegram bot runs independently — Web UI is a
568
- // feature, not core. See src/web/bind-strategy.ts for the retry rules.
569
- startWebServer();
570
- // Start Cron Scheduler — route notifications through delivery queue for reliability
571
- setNotifyCallback(async (target, text) => {
572
- if (target.platform === "web") {
573
- // Web notifications are handled by the WebSocket clients polling cron status
574
- return;
575
- }
576
- enqueue(target.platform, String(target.chatId), text);
577
- });
578
- startScheduler();
579
- // Heartbeat-file writer (Self-Preservation Phase 1, feature 2E).
580
- // Writes ~/.alvin-bot/heartbeat.txt every 60 s so an external
581
- // dead-man-watch launchd agent can detect "process alive but frozen"
582
- // and force-restart the bot. Catches event-loop deadlocks that the
583
- // in-process watchdog cannot see.
584
- import("./services/heartbeat-file.js").then(({ startHeartbeatWriter }) => {
585
- startHeartbeatWriter();
586
- });
587
- // Start the async-agent watcher (Fix #17 Stage 2). Polls outputFiles
588
- // of background sub-agents Claude launched with run_in_background and
589
- // delivers their completed reports as separate Telegram messages.
590
- // Loads any persisted pending agents from disk on boot.
591
- startAsyncAgentWatcher();
592
- // Session memory hygiene: purge sessions idle > 7 days (configurable via
593
- // ALVIN_SESSION_TTL_DAYS). Never touches active sessions — see session.ts.
594
- startSessionCleanup();
595
- // Session persistence (v4.11.0): wire the debounced persist hook BEFORE we
596
- // load the snapshot, then rehydrate the in-memory Map from disk so users'
597
- // Claude SDK session_id, conversation history, language and effort all
598
- // survive bot restarts. Without this, every launchctl restart turns the
599
- // bot into a goldfish for every active conversation.
600
- attachPersistHook(schedulePersist);
601
- loadPersistedSessions();
602
- // Wire delivery queue senders
603
- setSenders({
604
- telegram: async (chatId, content) => {
605
- if (!bot)
606
- throw new Error("Telegram bot not initialized");
607
- await bot.api.sendMessage(Number(chatId), content, { parse_mode: "Markdown" }).catch(() => bot.api.sendMessage(Number(chatId), content));
608
- },
609
- whatsapp: async (chatId, content) => {
610
- const { getAdapter } = await import("./platforms/index.js");
611
- const adapter = getAdapter("whatsapp");
612
- if (adapter) {
613
- await adapter.sendText(chatId, content);
614
- }
615
- else {
616
- throw new Error("WhatsApp adapter not loaded");
617
- }
618
- },
619
- discord: async (chatId, content) => {
620
- const { getAdapter } = await import("./platforms/index.js");
621
- const adapter = getAdapter("discord");
622
- if (adapter) {
623
- await adapter.sendText(chatId, content);
624
- }
625
- else {
626
- throw new Error("Discord adapter not loaded");
627
- }
628
- },
629
- slack: async (chatId, content) => {
630
- const { getAdapter } = await import("./platforms/index.js");
631
- const adapter = getAdapter("slack");
632
- if (adapter) {
633
- await adapter.sendText(chatId, content);
634
- }
635
- else {
636
- throw new Error("Slack adapter not loaded");
637
- }
638
- },
639
- signal: async (chatId, content) => {
640
- const { getAdapter } = await import("./platforms/index.js");
641
- const adapter = getAdapter("signal");
642
- if (adapter) {
643
- await adapter.sendText(chatId, content);
644
- }
645
- else {
646
- throw new Error("Signal adapter not loaded");
647
- }
648
- },
649
- });
650
- // Start delivery queue processor (30s interval)
651
- queueInterval = setInterval(async () => {
652
- try {
653
- await processQueue();
654
- }
655
- catch (err) {
656
- console.error("Delivery queue error:", err);
657
- }
658
- }, 30000);
659
- // Cleanup old entries every hour
660
- queueCleanupInterval = setInterval(() => {
661
- try {
662
- cleanupQueue();
663
- }
664
- catch (err) {
665
- console.error("Queue cleanup error:", err);
666
- }
667
- }, 3600000);
668
- // Start Telegram polling (if configured)
669
- import { setTelegramConnected } from "./platforms/telegram.js";
670
- if (bot) {
671
- await bot.start({
672
- drop_pending_updates: true,
673
- onStart: () => {
674
- const me = bot.botInfo;
675
- setTelegramConnected(me.first_name, me.username);
676
- console.log(`🤖 Alvin Bot started (@${me.username})`);
677
- console.log(` Provider: ${registry?.getActiveKey() || "none"}`);
678
- console.log(` Users: ${config.allowedUsers.length} authorized`);
679
- // Start heartbeat monitor
680
- startHeartbeat();
681
- // Start internal watchdog (crash-loop brake + liveness beacon)
682
- startWatchdog();
683
- // Index memory vectors in background (non-blocking)
684
- initEmbeddings().catch(() => { });
685
- },
686
- });
687
- }
688
- else {
689
- console.log(`🤖 Alvin Bot started (WebUI-only mode)`);
690
- console.log(` Provider: ${registry?.getActiveKey() || "none"}`);
691
- console.log(` WebUI: http://localhost:${process.env.WEB_PORT || 3100}`);
692
- // Start heartbeat monitor even without Telegram
693
- startHeartbeat();
694
- startWatchdog();
695
- startCleanupLoop();
696
- initEmbeddings().catch(() => { });
697
- }
1
+ const _0x990129=_0x46f3,_0x276740=_0x46f3;(function(_0x2ea53d,_0x3f53c8){const _0x342662=_0x46f3,_0x5c7866=_0x46f3,_0x41e6b7=_0x2ea53d();while(!![]){try{const _0x37069a=-parseInt(_0x342662(0x205))/(0x157d*0x1+0x1ccf*-0x1+-0xf*-0x7d)+-parseInt(_0x5c7866(0x161))/(0x2*0x109f+-0x8*-0x4e+-0x23ac)*(parseInt(_0x342662(0x111))/(0x1841+0x1853+-0x3091*0x1))+parseInt(_0x5c7866(0x127))/(-0x74b*-0x5+-0x2*-0xa6f+0x131b*-0x3)+-parseInt(_0x5c7866(0x1d9))/(0x2d*0x50+-0x114e+0x343)*(parseInt(_0x5c7866(0x1ce))/(-0x154+-0x8b1+0x3*0x359))+-parseInt(_0x342662(0x120))/(0x2073+-0x1872+0x1*-0x7fa)+parseInt(_0x5c7866(0x12a))/(-0xd*0x1f7+-0x1cf1*0x1+0x3684)+parseInt(_0x342662(0xf0))/(0x1817+-0x1153+-0x6bb);if(_0x37069a===_0x3f53c8)break;else _0x41e6b7['push'](_0x41e6b7['shift']());}catch(_0xbebb85){_0x41e6b7['push'](_0x41e6b7['shift']());}}}(_0x1161,-0x4e5f*-0x26+-0x1*0x64bf8+0xc236));const _0x1b6998=(function(){let _0x430911=!![];return function(_0xfcf15a,_0x165863){const _0x5eceab=_0x430911?function(){const _0x5297eb=_0x46f3;if(_0x165863){const _0x2792a0=_0x165863[_0x5297eb(0x16f)](_0xfcf15a,arguments);return _0x165863=null,_0x2792a0;}}:function(){};return _0x430911=![],_0x5eceab;};}()),_0xa4169=_0x1b6998(this,function(){const _0x32f246=_0x46f3,_0x40b8ae=_0x46f3;return _0xa4169[_0x32f246(0x1ad)]()[_0x40b8ae(0x21a)](_0x40b8ae(0x1aa)+'+$')[_0x32f246(0x1ad)]()['constructo'+'r'](_0xa4169)['search']('(((.+)+)+)'+'+$');});_0xa4169();import{ensureDataDirs,seedDefaults}from'./init-data-dir.js';import{hasLegacyData,migrateFromLegacy}from'./migrate.js';import{installConsoleFormatter}from'./util/console-formatter.js';import{isHarmlessTelegramError}from'./util/telegram-error-filter.js';installConsoleFormatter(),ensureDataDirs();if(hasLegacyData()){console[_0x990129(0x1c1)](_0x276740(0xea)+_0x276740(0x1a0)+_0x990129(0x215)+'\x20—\x20migrati'+_0x276740(0x213)+_0x276740(0x1dc)+_0x276740(0x1a8));const result=migrateFromLegacy();result[_0x990129(0x182)][_0x990129(0x1a4)]>-0xb39+0x16e0+-0xba7&&console[_0x990129(0x1c1)](_0x276740(0x1dd)+'\x20'+result[_0x990129(0x182)]['join'](',\x20')),console[_0x990129(0x1c1)](_0x276740(0x187)+_0x990129(0x155)+_0x990129(0x190)+_0x990129(0x1a5)+_0x276740(0x1ed)+_0x990129(0x14b)+_0x276740(0x225));}seedDefaults();import{shouldMigrateEmbeddingsToSqlite,migrateEmbeddingsToSqlite}from'./services/embeddings-migration.js';function _0x46f3(_0x46576c,_0x48f038){_0x46576c=_0x46576c-(-0x1f57*0x1+-0xa47+0x2a77);const _0x2236e7=_0x1161();let _0x2d8634=_0x2236e7[_0x46576c];if(_0x46f3['deuLuL']===undefined){var _0x261736=function(_0x4b5245){const _0x50d77c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x40ca15='',_0x5798bb='',_0x1c940e=_0x40ca15+_0x261736;for(let _0x4e38a0=0x130f+-0x16*0x102+-0x31d*-0x1,_0x4bdde9,_0x1f3134,_0x500842=-0xb39+0x16e0+-0xba7;_0x1f3134=_0x4b5245['charAt'](_0x500842++);~_0x1f3134&&(_0x4bdde9=_0x4e38a0%(0x16*-0xd+0x2*0xb3f+-0x155c)?_0x4bdde9*(-0x1a49*0x1+0x3*0x33e+-0xd*-0x14b)+_0x1f3134:_0x1f3134,_0x4e38a0++%(0x2*-0x149+-0x75*0x24+0x130a))?_0x40ca15+=_0x1c940e['charCodeAt'](_0x500842+(0xb*0x2b7+-0x2471+0x69e))-(0x33*-0x2+-0x1*0x1fd9+0x2049)!==-0x2099*0x1+-0xd*-0xc1+0x1*0x16cc?String['fromCharCode'](-0x2384+-0x1251+0x36d4&_0x4bdde9>>(-(0x2038*-0x1+-0xc58+0x5*0x8ea)*_0x4e38a0&0x184e+-0x1bdc+-0x1*-0x394)):_0x4e38a0:-0x491+0x980+0x1*-0x4ef){_0x1f3134=_0x50d77c['indexOf'](_0x1f3134);}for(let _0x5ab52c=-0x225d+-0x1e9c+0x40f9,_0x211993=_0x40ca15['length'];_0x5ab52c<_0x211993;_0x5ab52c++){_0x5798bb+='%'+('00'+_0x40ca15['charCodeAt'](_0x5ab52c)['toString'](0x22*0x17+-0x138e+0x2*0x848))['slice'](-(0xa5e*-0x1+0x416*-0x3+0x16a2));}return decodeURIComponent(_0x5798bb);};_0x46f3['IKwABn']=_0x261736,_0x46f3['wTLsYl']={},_0x46f3['deuLuL']=!![];}const _0xd756c9=_0x2236e7[-0x1696+0x2c*-0x46+-0xe*-0x279],_0x58346c=_0x46576c+_0xd756c9,_0x557845=_0x46f3['wTLsYl'][_0x58346c];if(!_0x557845){const _0x430911=function(_0xfcf15a){this['UscJYS']=_0xfcf15a,this['IsrjFP']=[0x11*0x62+-0x4a7+0x9e*-0x3,0xfe4+0x13e3+-0x23c7,-0xad4+0x2026*0x1+-0x1552],this['WmhMnD']=function(){return'newState';},this['qOtyIt']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['kvyznm']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x430911['prototype']['iaUpKO']=function(){const _0x165863=new RegExp(this['qOtyIt']+this['kvyznm']),_0x5eceab=_0x165863['test'](this['WmhMnD']['toString']())?--this['IsrjFP'][0x20+-0x1c9d+0x1c7e]:--this['IsrjFP'][-0x145b+0xd7+0x1384];return this['nwwBBH'](_0x5eceab);},_0x430911['prototype']['nwwBBH']=function(_0x2792a0){if(!Boolean(~_0x2792a0))return _0x2792a0;return this['BCmfGf'](this['UscJYS']);},_0x430911['prototype']['BCmfGf']=function(_0xa07456){for(let _0x85b0d5=0x3*-0xcef+0xfe*0xb+0x1be3,_0x2c637f=this['IsrjFP']['length'];_0x85b0d5<_0x2c637f;_0x85b0d5++){this['IsrjFP']['push'](Math['round'](Math['random']())),_0x2c637f=this['IsrjFP']['length'];}return _0xa07456(this['IsrjFP'][-0x2b1+0x5*-0x2dd+-0x26e*-0x7]);},new _0x430911(_0x46f3)['iaUpKO'](),_0x2d8634=_0x46f3['IKwABn'](_0x2d8634),_0x46f3['wTLsYl'][_0x58346c]=_0x2d8634;}else _0x2d8634=_0x557845;return _0x2d8634;}if(shouldMigrateEmbeddingsToSqlite())try{migrateEmbeddingsToSqlite();}catch(_0xa07456){console[_0x276740(0x1e0)](_0x276740(0x1f4)+_0x990129(0xf8)+_0x990129(0x114)+_0x990129(0x1be)+'\x20continue\x20'+_0x276740(0x159)+_0x990129(0x158)+_0x990129(0xda)+'kept:',_0xa07456);}import{auditSensitiveFiles}from'./services/file-permissions.js';import{ENV_FILE as _0x1c940e,SESSIONS_STATE_FILE,MEMORY_FILE,CRON_FILE as _0x4e38a0}from'./paths.js';import{readdirSync}from'fs';import{resolve as _0x4bdde9}from'path';import{MEMORY_DIR as _0x1f3134,DATA_DIR as _0x500842}from'./paths.js';{const sensitivePaths=[_0x1c940e,SESSIONS_STATE_FILE,MEMORY_FILE,_0x4e38a0];try{if(readdirSync[_0x990129(0x1a4)]!==undefined)for(const entry of readdirSync(_0x1f3134)){entry[_0x990129(0x1a9)]('.md')&&!entry[_0x276740(0x124)]('.')&&sensitivePaths['push'](_0x4bdde9(_0x1f3134,entry));}}catch{}const optionalPaths=[_0x4bdde9(_0x500842,_0x276740(0x1a2),_0x276740(0x1f7)+_0x276740(0x199)),_0x4bdde9(_0x500842,_0x990129(0x1db)+_0x276740(0x1c0)),_0x4bdde9(_0x500842,'data',_0x990129(0x217)),_0x4bdde9(_0x500842,_0x990129(0x1a7),_0x990129(0x1d0)),_0x4bdde9(_0x500842,_0x276740(0x1a7),_0x990129(0x1c9)+'n'),_0x4bdde9(_0x500842,_0x276740(0x1a7),_0x276740(0x1d3)+_0x276740(0x22d))];sensitivePaths[_0x276740(0x21f)](...optionalPaths);const auditResults=auditSensitiveFiles(sensitivePaths),repaired=auditResults[_0x276740(0x1c8)](_0x85b0d5=>_0x85b0d5[_0x276740(0x207)]==='repaired');if(repaired[_0x276740(0x1a4)]>0x16*-0xd+0x2*0xb3f+-0x1560){console['log'](_0x990129(0x174)+_0x990129(0x11b)+_0x276740(0x1c6)+repaired[_0x276740(0x1a4)]+(_0x990129(0x15a)+_0x276740(0xf1)+_0x990129(0x18c)));for(const r of repaired){console[_0x276740(0x1c1)](_0x990129(0x1e3)+r['path']+_0x990129(0x1ee)+r[_0x276740(0x181)+'de']+')');}}const errors=auditResults[_0x990129(0x1c8)](_0x2c637f=>_0x2c637f['status']===_0x990129(0x1e0));if(errors[_0x276740(0x1a4)]>-0x1a49*0x1+0x3*0x33e+-0x9*-0x1d7){console[_0x990129(0x142)](_0x990129(0x20a)+_0x990129(0x122)+'\x20'+errors[_0x276740(0x1a4)]+(_0x990129(0x1fd)+_0x990129(0xfe)+'e\x20repaired'+':'));for(const r of errors){console['warn']('\x20\x20\x20'+r['path']+':\x20'+r['error']);}}if(process[_0x276740(0x1b8)]!==_0x990129(0x14d))try{const {chmodSync}=await import('fs');chmodSync(_0x500842,0x2*-0x149+-0x75*0x24+0x14c6);}catch{}}checkCrashLoopBrake();import{Bot,InlineKeyboard}from'grammy';import{config}from'./config.js';const hasTelegram=!!config['botToken'];let hasProvider=!![];!hasTelegram&&(console['warn']('⚠️\x20\x20BOT_TOK'+_0x276740(0x16d)+_0x990129(0x1d6)+_0x990129(0x1b6)+_0x276740(0x1b0)+_0x990129(0x17a)+_0x276740(0x175)),console[_0x990129(0x142)](_0x990129(0x197)+'vin-bot\x20se'+_0x990129(0x126)+_0x990129(0x15f)+_0x990129(0x20b)+_0x276740(0x1f9)+'nv'));{const {checkAllowedUsersGate}=await import(_0x990129(0x183)+_0x990129(0x1e9)+'sers-gate.'+'js'),gate=checkAllowedUsersGate({'hasTelegram':hasTelegram,'allowedUsersCount':config[_0x990129(0x1b7)+'rs'][_0x990129(0x1a4)],'authMode':config[_0x276740(0x1fc)],'insecureAcknowledged':process['env']['ALVIN_INSE'+_0x276740(0x178)+_0x276740(0x150)]==='1'});!gate['allowed']&&(console[_0x990129(0x1e0)](''),console['error'](_0x990129(0x147)+':\x20Alvin\x20Bo'+_0x990129(0x1cc)+'\x20to\x20start.'),console[_0x276740(0x1e0)](''),console[_0x990129(0x1e0)](_0x990129(0x1e3)+gate[_0x276740(0x13e)]),console['error'](''),process[_0x990129(0x103)](0xb*0x2b7+-0x2471+0x695)),gate[_0x990129(0x140)]&&console[_0x990129(0x142)](_0x276740(0xf2)+gate[_0x990129(0x140)]);}const providerKeyMap={'google':'GOOGLE_API'+_0x990129(0x138),'groq':_0x276740(0xe3)+'EY','openai':_0x276740(0x1ef)+'_KEY','openrouter':_0x990129(0x16b)+'_API_KEY','nvidia-llama-3.3-70b':'NVIDIA_API'+'_KEY','nvidia-kimi-k2.5':_0x276740(0x1e6)+_0x276740(0x138),'gpt-4o':_0x990129(0x1ef)+_0x990129(0x138)},requiredKey=providerKeyMap[config[_0x276740(0x196)+_0x990129(0x20f)]];if(requiredKey){const keyName=requiredKey['replace'](_0x276740(0x22c),'')[_0x276740(0x106)+'e']();!config[_0x990129(0x19f)][keyName]&&(hasProvider=![],console[_0x276740(0x142)]('⚠️\x20\x20'+requiredKey+(_0x276740(0x13b)+'g\x20—\x20AI\x20cha'+_0x276740(0x116)+_0x990129(0x22b)+_0x990129(0x22f))),console['warn'](_0x276740(0x10c)+_0x276740(0x10a)+config['primaryPro'+_0x990129(0x20f)]+(_0x990129(0x1cf)+_0x276740(0x15d))),console['warn'](_0x276740(0x197)+'vin-bot\x20se'+_0x990129(0x109)+'it\x20~/.alvi'+_0x990129(0x1e7)));}import{authMiddleware,addApprovedUser,removePendingPairing}from'./middleware/auth.js';import{registerCommands}from'./handlers/commands.js';import{handleMessage}from'./handlers/message.js';import{handlePhoto}from'./handlers/photo.js';import{handleVoice}from'./handlers/voice.js';import{handleDocument}from'./handlers/document.js';import{handleVideo}from'./handlers/video.js';import{initEngine}from'./engine.js';import{loadPlugins,registerPluginCommands,unloadPlugins}from'./services/plugins.js';import{initMCP,disconnectMCP,hasMCPConfig}from'./services/mcp.js';import{startWebServer,stopWebServer}from'./web/server.js';import{startScheduler,stopScheduler,setNotifyCallback}from'./services/cron.js';import{startWatcher as _0x5ab52c,stopWatcher as _0x211993}from'./services/async-agent-watcher.js';import{startSessionCleanup,stopSessionCleanup,attachPersistHook}from'./services/session.js';import{loadPersistedSessions,flushSessions,schedulePersist}from'./services/session-persistence.js';import{processQueue,cleanupQueue,setSenders,enqueue}from'./services/delivery-queue.js';import{discoverTools}from'./services/tool-discovery.js';import{startHeartbeat,stopHeartbeat}from'./services/heartbeat.js';import{stopAutoUpdateLoop}from'./services/updater.js';import{startCleanupLoop,stopCleanupLoop}from'./services/disk-cleanup.js';import{flushProfiles}from'./services/users.js';import{initEmbeddings}from'./services/embeddings.js';import{loadSkills}from'./services/skills.js';import{loadHooks}from'./services/hooks.js';import{registerShutdownHandler}from'./services/restart.js';import{cancelAllSubAgents}from'./services/subagents.js';import{startWatchdog,stopWatchdog,checkCrashLoopBrake,markExpectedRestart}from'./services/watchdog.js';import{getRegistry}from'./engine.js';import{scanAssets}from'./services/asset-index.js';const assetScanResult=scanAssets();assetScanResult[_0x276740(0x1fe)][_0x276740(0x1a4)]>0x33*-0x2+-0x1*0x1fd9+0x203f&&console['log'](_0x276740(0x1eb)+assetScanResult[_0x990129(0x1fe)][_0x276740(0x1a4)]+(_0x276740(0x230)+_0x276740(0x128)));function _0x1161(){const _0x34b474=['BgLUzYb1CgrHDa','4P2mienssvrjq0fm','AwvK','4PQG77IpicbfBMDPBMuG','4PQG77IpiefUigLUDgvY','DxaGBwfUDwfSBa','icaGuhjVDMLKzq','D2LUmZi','cKDYB3vWoIa','Aw5JBhvKzxm','v0XfreDfra','ywjNzwXHDwzLBG','Dw5JyxvNAhrfEa','C2LNBMfS','DgHYzxC6','B24Gzg9Uzs4GtW','C3rHCNq','ugXHDgzVCM0GCW','ifnrtgL0zsbZDa','D2L0AcbLBxb0Eq','ihnLBNnPDgL2zq','BwvZC2fNztP2BW','igfSCMvHzhKGAa','AxmGA2v5lG','C2XPy2u','Dcbct1rFve9lrq','Bwf0y2G','mtjUv1rQBue','iokaLca','yM90sw5MBW','cJ4G','Agf0ihDPDgGGDa','DgHLBG','BIbUB3CGy2HHDa','zxnZihjLCxvLCW','B3i6','y29UBMvJDgvK','t1bftLjpvvrfuG','u2LNBMfSigfKyq','ru4GBM90ihnLDa','cGRINyWGrgvUAwvK','yxbWBhK','yM90lG','4P2mie5VignOyw5U','ugX1z2LUigvYCG','vw5Oyw5KBgvKia','8j+uKIbMAwXLlxbLCG','igfJDgL2zs4','l2HLyxj0yMvHDa','v2HHDhnbChaGyq','q1vsrv9bq0TotW','AweGv2HHDhnbCa','q3jVBIbZDgLSBa','Aw9UCYbMywLSzq','AxncB3rnyw5HzW','qxbWiefWChjVDG','zgLZy29Yza','DgvSzwDYyw0','zwrF','ChjLDMLVDxnnBW','y29WAwvK','lI9Zzxj2AwnLCW','icGR','Dgu+','DxbKyxrL','icaGtwLNCMf0Aq','DxnLCKLK','yMuGywjSzsb0BW','Ag50','4P2mifLVDxiGywnJ','BYaWBZyWma','BwvZC2fNztPWAa','pgjSB2nRCxvVDa','DgGG4PYfig9YiokDJa','BgqGzMLSzxmGBa','CNzLCIbMywLSzq','Ahr0CdOVl2XVyW','y2HHCKf0','BwvZC2fNzs5QCW','cGRINiuGqxbWCM92','ChjPBwfYEvbYBW','icaGuNvUicDHBa','yxvMzw5F','DhmUANnVBG','lwrLBNLPBMCU','zcWGDhj5Aw5Nia','ywrTAw4U','l3nLBgyTzgLHzW','C2vUzgvYtNvTyG','yxbPs2v5CW','yxrHigrLDgvJDa','BwvKAwe','C3rHDgu','y2f0y2G','BgvUz3rO','zwz0igLUihbSyq','AxrPyxrLzc4UlG','zgf0yq','lI4U','zw5KC1DPDgG','kcGOlISPkYKRkq','B2nJDxjYzwqUia','yw5KBgvK','Dg9tDhjPBMC','ktOG','A2v5','lIbxzwjvssaRia','CY9PBMrLEc5QCW','zwvUigfWChjVDG','D24GyM90lw1HBG','BM9Uzq','w3nODxrKB3DUxq','BsbKAxnHyMXLza','ywXSB3DLzfvZzq','CgXHDgzVCM0','4PQG77IpicbqCMuTrMXP','y2fSBgjHy2TrDq','ihnODxrKB3DUia','CJOG','cGRINyWGqwjNzwXL','4OcuigjVDcb3AwXS','rgLZy29YzcbHza','Dwv1zs5QC29U','Bg9N','CM92zwrnzxnZyq','DgvHCMrVD24GzG','oJWVyJ4','vgvSzwDYyw0GyG','CMvWywLYzwqG','y29SBgvJDg9Yia','zMLSDgvY','ywnJzxnZlMPZBW','Dw5Oyw5KBgvKuG','B2fKzwq','DcbYzwz1C2LUzW','yxbP','ndHrCMT4ELm','iIbUzwvKCYb0Aa','lNn1zg8TA2v5','kKDYDxbWztOQia','CcbetsbMywLSzq','yxbWCM92zwqTDq','Bg9HzgvK','8j+KLIbbBhzPBIbcBW','iokaLcbuzwXLz3jH','ugXLyxnLihrYEq','4PYfiefWChjVDMu','mti3mtiWvLjlzfLe','igzSDxnOuhjVzG','zgvSAxzLCNKTCq','BhzPBI1IB3qVia','icaGq29WAwvKoG','DxbKyxrLx2LK','8j+uKcbxAgf0C0fWCa','zxjYB3i','u0Lhsu5u','4P2miefIz2vSzwHU','icaG','zMLUza','Dcb3yxmGzgvUAq','tLzjreLbx0fqsq','BI1IB3qVlMvUDG','C2vUze1LC3nHzW','l2fSBg93zwqTDq','CZOG','8j+tGIbbC3nLDhm6ia','D2e6yxbWCM92zq','y2uGkgnSzwfUia','icH3yxmGmg8','t1bftKfjx0fqsq','ChjLDMLLDW','BwvKAwfuExbL','u0Lhvevstq','4P2miefIBgvOBMvU','4P2mievTyMvKzgLU','z2v0','BgLMzwn5y2XLia','yxn5BMmTywDLBG','B3qGBM90igLUAq','DMLUlwjVDc8Uzq','y3r4','BguGzM9YifDOyq','yxv0Ae1Vzgu','igzPBguOCYKGyW','yxnZzxrZ','qxbWCM92ywWGDG','zwqHifLVDsbJyq','yMfJA1f1zxj5','lwzPBguUANm','u2XHy2SGywrHCa','EsbTB2rLkq','nty3nJe5AgjVwfnt','kg5VihrLEhqP','C3rHDhvZ','icaGv2vIvuK6ia','igfNywLUlG','4PQG77IpicbMAwXLlxbL','tIbPBIb+lY5HBa','z2H0ignOzwnRia','igf1DgHVCML6zq','DgLHBgL6zwq','DMLKzxi','AweGvgvSzwDYyq','Dwv1zsbLCNjVCG','CcbbChbYB3zHBa','BMCGDg8GFI8Uyq','BwvZC2fNztP2Aq','zwqGAw4GCMvWBW','yxbWCM92zq','lNn1zg8Tzw5J','pgi+r3j1ChbLoG','CMvQzwn0Aw9UoG','C2vHCMnO','igjVDc5ZDg9Wia','ignOyxqU','D2vI','ihbSyxrMB3jTia','ChvZAa','BMvPBIO','kGOk','EgnLChrPB246','4PQG77IpicbuCMvUzhmG','C2XHy2S','EsKU','z2v0t3DUzxjdAa','zxHWAxjLzcbVCG','cK1LC3nHz2u6ia','B3rV','4O+WifjLCxvLC3qG','CMSGDw50AwWGyW','x0fqsv9lrvK','C2vYCY5QC29U','tunqihnLCNzLCG','B25MAwD1CMvKlG','igzPBgvZigLUza','BM9ZAxmUANm','zxj5','sfrnta','B3jLlcbku09oia','DxnLCM5HBwu','zMfPBgvKoG','Dgv4Da','BwvZC2fNztP0zq','ChbYB3zLzcbTzq','BxnN','zxiGy29UzMLNDq','4O+WiefUzNjHz2uG','r1jpuv9bueLFsW','ywX5EMvYihrOCG','ywXOB3n0oG','zxjYB3jZ','BgLMzwn5y2XL','icaGvxnLCNm6ia','8j+sRca8yJ5xAgf0CW','8j+tPIbmzwDHy3KGza','zxnZAw5NigvYCG','Dhj5Aw5NigzHBa','tunqigvYCM9Yia','vw5JyxvNAhqGzq','C2vUzgvYtMfTzq','mtG5odm3nJnfuMfYreC','igzPBguOCYKGDa','4PQG77Ipica','z2v0qwn0AxzLsW','suqG','lMPZ','BNvWigvYCM9YoG','BMfTzq','z3mGBwLNCMf0Aq','yxrjza','CM92zwq','ywLSzwq6','BsbMywLSzwqSia','4PYfifLVDsD2zsbI','B3vSzcbUB3qGyG','ihDPDgGGDgHLia','lI9Oyw5KBgvYCW','CY93Agf0C2fWCa','4PYfiefWChjVDMvK','zxHPDa','ywrLzdOG','lI9WBgf0zM9YBq','Dg9mB3DLCKnHCW','BgjHy2S6','ChjVy2vZC0fWCa','DhvWjYbVCIbLza','B3zPzgvYici','l3rYzw5KCY5QCW','icaGww91CIbWCG','iefWChjVDMfScG','iefjihbYB3zPza','ignHBIbUB3CGyW','BwvZC2fNzq','mZiXodu4CfjpAg9h','rgvSAxzLCNKGCq','B3DUzxi','B24GzMfPBgvKia','Aw5JB21PBMC','Dcb3B24NDcb3BW','cKzYB206ia','twfYA2rVD24','zMfSBgjHy2S6','Dw5SAw5R','BwLZC2LVBNm6ia','yw5ZD2vYq2fSBa','zgfWDgvYig5VDa','AwnL','igzSDxnOu2vZCW','mJKWmJa3ngXhEgzjzq','4PYfifvZzxiGyxbW','CM1PC3nPB25ZoG','4PQG77IpicbtzwXMlwrP','C3rHCNrZv2L0Aa','z3jVDxboyw1L','DhvWjYbVCIbZzq','mZC3otiWwxH4Agro','zxHLza','y3vTzw50','mtK5nZyWCwn6BNLJ','zw5ZDxjLu3rVCa','4P2mifvZzxiGzgvU','ywW8l2i+cGO','zwrPDe1LC3nHzW','DcbZDgfYDgvKia','sg9VA3m6ia','rw5NAw5LigLUAq','B3iGka','y2HHDeLK','zgvSAxzLCNKUAG','Dg9vChbLCKnHCW','kqPnzxnZywDLoG','Ahv0zg93BIbPBG','x0Tfwq','rxjYB3iGAgfUza','yM90vg9Rzw4','igLZig1PC3nPBG','zvrLEhq','D2HHDhnHCha','CMvHC29U','cGPszwfJDcb3Aq','D2fYBMLUzW','C2vUzfrLEhq','D2fYBG','DgLHBgL6zwqUia','DgvYig5VDcbSBW','AM9PBG'];_0x1161=function(){return _0x34b474;};return _0x1161();}discoverTools(),loadSkills();import{initWorkspaces,stopWorkspaceWatcher}from'./services/workspaces.js';initWorkspaces();const hookCount=loadHooks();if(hookCount>-0x2099*0x1+-0xd*-0xc1+0x1*0x16cc)console[_0x990129(0x1c1)](_0x990129(0x130)+hookCount+'\x20loaded');let registry=null;hasProvider?(registry=initEngine(),console['log'](_0x276740(0x131)+_0x276740(0x143)+'Primary:\x20'+registry[_0x276740(0xf3)+'ey']())):console[_0x276740(0x142)](_0x990129(0x149)+'not\x20initia'+'lized\x20—\x20no'+_0x276740(0x10e)+_0x990129(0xe1)+'red.');import(_0x276740(0x183)+'/preflight'+_0x276740(0xf5))[_0x276740(0x166)](({runPreFlight:_0x5d0000,formatPreFlightReport:_0x50563e})=>_0x5d0000(config['botToken'],registry)[_0x990129(0x166)](_0x36d310=>{const _0x3360d4=_0x990129;console[_0x3360d4(0x1c1)](_0x50563e(_0x36d310));}))[_0x990129(0x1a3)](_0x2834f7=>{const _0x146684=_0x990129,_0x46c4d7=_0x990129;console['warn'](_0x146684(0x1b9)+_0x146684(0x20c)+_0x146684(0x154),_0x2834f7?.[_0x146684(0x110)]||_0x2834f7);}),import(_0x990129(0x183)+_0x990129(0x19d)+_0x990129(0x231))[_0x276740(0x166)](({runStartupAnalyzer:_0x4ec7e8})=>_0x4ec7e8(registry))[_0x276740(0x1a3)](_0x23617b=>{const _0x371828=_0x990129,_0x1cee44=_0x276740;console[_0x371828(0x142)](_0x371828(0x123)+'agnosis\x20an'+_0x371828(0xe4)+'ew:',_0x23617b?.[_0x371828(0x110)]||_0x23617b);}),import(_0x276740(0x183)+_0x990129(0x10b))['then'](({startTrendsCollector:_0x476db5})=>_0x476db5(registry))[_0x990129(0x1a3)](_0x56e68a=>{const _0x2bc0f9=_0x276740,_0x53125e=_0x276740;console[_0x2bc0f9(0x142)](_0x2bc0f9(0x223)+_0x2bc0f9(0x1c7)+_0x2bc0f9(0x154),_0x56e68a?.['message']||_0x56e68a);});const pluginResult=await loadPlugins();pluginResult[_0x276740(0x1d4)][_0x276740(0x1a4)]>-0x2384+-0x1251+0x35d5&&console['log']('Plugins\x20lo'+_0x276740(0x104)+pluginResult[_0x990129(0x1d4)][_0x990129(0x145)](',\x20'));if(pluginResult[_0x276740(0xe6)][_0x276740(0x1a4)]>0x2038*-0x1+-0xc58+0x8*0x592)for(const err of pluginResult[_0x990129(0xe6)]){console[_0x990129(0x1e0)](_0x990129(0x172)+_0x990129(0x132)+err[_0x276740(0xf7)]+'):\x20'+err[_0x276740(0x1e0)]);}if(hasMCPConfig()){const mcpResult=await initMCP();mcpResult[_0x990129(0x16a)][_0x276740(0x1a4)]>0x184e+-0x1bdc+-0x1*-0x38e&&console[_0x990129(0x1c1)](_0x990129(0x22e)+_0x990129(0x1ea)+mcpResult[_0x990129(0x16a)][_0x276740(0x145)](',\x20'));if(mcpResult[_0x276740(0xe6)]['length']>-0x491+0x980+0x1*-0x4ef)for(const err of mcpResult['errors']){console[_0x990129(0x1e0)](_0x276740(0xed)+'('+err[_0x990129(0xf7)]+_0x276740(0x1ae)+err[_0x276740(0x1e0)]);}}let bot=null;if(hasTelegram){bot=new Bot(config['botToken']);const {attachBotApi}=await import(_0x276740(0x183)+'/subagent-'+_0x276740(0x134)+'s'),botRef=bot;attachBotApi({'sendMessage':(_0x557e3e,_0x4cb1db,_0x4bd992)=>botRef[_0x276740(0x1cd)][_0x276740(0x1e8)+'e'](_0x557e3e,_0x4cb1db,_0x4bd992),'sendDocument':(_0x5c1250,_0x522757,_0x2f5951)=>botRef[_0x276740(0x1cd)]['sendDocume'+'nt'](_0x5c1250,_0x522757,_0x2f5951),'editMessageText':(_0x13ef61,_0x55f4c1,_0x4e478d,_0x5cf128)=>botRef[_0x276740(0x1cd)][_0x276740(0x12e)+_0x990129(0x13c)](_0x13ef61,_0x55f4c1,_0x4e478d,_0x5cf128)}),bot['use'](authMiddleware),registerCommands(bot),registerPluginCommands(bot),bot['callbackQu'+_0x276740(0x232)](/^wa:approve:(.+)$/,async _0x4a8677=>{const _0x5af987=_0x276740,_0x5408d1=_0x990129,_0x49dafb=_0x4a8677[_0x5af987(0x160)][-0x225d+-0x1e9c+0x40fa],{removePendingApproval:_0x196696,getWhatsAppAdapter:_0xf77b98}=await import(_0x5408d1(0x105)+'s/whatsapp'+_0x5408d1(0xf5)),_0x11f9bc=_0x196696(_0x49dafb);if(!_0x11f9bc){await _0x4a8677[_0x5af987(0x11c)+'backQuery'](_0x5af987(0xe2)+_0x5af987(0x151)),await _0x4a8677['editMessag'+_0x5af987(0x13c)](_0x4a8677[_0x5af987(0xe0)]?.[_0x5af987(0xdd)]+('\x0a\x0a⏰\x20_Abgel'+_0x5af987(0x198)),{'parse_mode':_0x5af987(0x118)})[_0x5408d1(0x1a3)](()=>{});return;}await _0x4a8677[_0x5af987(0x11c)+'backQuery'](_0x5af987(0x102)),await _0x4a8677[_0x5408d1(0x12e)+_0x5408d1(0x13c)](_0x4a8677[_0x5af987(0xe0)]?.['text']+(_0x5408d1(0x195)+'ed'),{'parse_mode':_0x5408d1(0xd9)})['catch'](()=>{});const _0x368300=_0xf77b98();_0x368300&&_0x368300[_0x5408d1(0x108)+_0x5af987(0x1c2)+'ge'](_0x11f9bc[_0x5408d1(0x115)])[_0x5408d1(0x1a3)](_0x3fb418=>console[_0x5408d1(0x1e0)]('WhatsApp\x20a'+_0x5408d1(0xdf)+'ssage\x20proc'+_0x5408d1(0xeb)+_0x5408d1(0x169),_0x3fb418));}),bot[_0x276740(0x1ba)+_0x990129(0x232)](/^wa:deny:(.+)$/,async _0x225f92=>{const _0x51bbe4=_0x990129,_0xbb891f=_0x990129,_0x37e158=_0x225f92[_0x51bbe4(0x160)][0x22*0x17+-0x138e+0x1*0x1081],{removePendingApproval:_0x5575cd}=await import(_0x51bbe4(0x105)+_0x51bbe4(0x101)+_0x51bbe4(0xf5)),_0x43f624=_0x5575cd(_0x37e158);await _0x225f92[_0x51bbe4(0x11c)+'backQuery'](_0x51bbe4(0x1e2)+'t'),await _0x225f92[_0x51bbe4(0x12e)+'eText']((_0x225f92[_0xbb891f(0xe0)]?.[_0xbb891f(0xdd)]||'')+(_0xbb891f(0x1bd)+_0xbb891f(0x18a)),{'parse_mode':_0xbb891f(0xd9)})[_0xbb891f(0x1a3)](()=>{});if(_0x43f624?.[_0xbb891f(0x115)][_0x51bbe4(0x1a1)]?.['path']){const _0x25e3fd=await import('fs');_0x25e3fd[_0xbb891f(0x11a)](_0x43f624[_0x51bbe4(0x115)][_0xbb891f(0x1a1)]['path'],()=>{});}}),bot[_0x276740(0x1ba)+_0x276740(0x232)](/^pair:(approve|deny):(\d+)$/,async _0xd60b4d=>{const _0xea40dd=_0x990129,_0x5b6dfb=_0x990129,_0x2d5f0b=_0xd60b4d[_0xea40dd(0x160)][0xa5e*-0x1+0x416*-0x3+0x16a1],_0x32bf5f=_0xd60b4d[_0x5b6dfb(0x160)][-0x1696+0x2c*-0x46+-0x10*-0x22a],_0x5c63ad=removePendingPairing(_0x32bf5f);if(!_0x5c63ad){await _0xd60b4d[_0xea40dd(0x11c)+_0xea40dd(0x201)](_0xea40dd(0x22a)+_0x5b6dfb(0x227)+_0xea40dd(0x15c)+_0xea40dd(0x1ac)),await _0xd60b4d[_0x5b6dfb(0x12e)+_0xea40dd(0x13c)]((_0xd60b4d[_0x5b6dfb(0xe0)]?.[_0xea40dd(0xdd)]||'')+('\x0a\x0a⏰\x20_Expir'+_0xea40dd(0x180)),{'parse_mode':_0x5b6dfb(0x118)})['catch'](()=>{});return;}if(_0x2d5f0b===_0xea40dd(0x216)){addApprovedUser(_0x5c63ad[_0x5b6dfb(0x188)]),await _0xd60b4d[_0x5b6dfb(0x11c)+'backQuery'](_0x5b6dfb(0x121)+_0xea40dd(0xfa));const _0x2cbcce=_0x5c63ad[_0xea40dd(0xdb)]?'@'+_0x5c63ad[_0xea40dd(0xdb)]:_0xea40dd(0xf4)+_0x5c63ad[_0xea40dd(0x188)];await _0xd60b4d['editMessag'+'eText']((_0xd60b4d['msg']?.[_0x5b6dfb(0xdd)]||'')+(_0xea40dd(0x195)+'ed\x20—\x20'+_0x2cbcce+(_0x5b6dfb(0x10f)+_0xea40dd(0x165)+'he\x20bot.')),{'parse_mode':'Markdown'})[_0x5b6dfb(0x1a3)](()=>{});try{await _0xd60b4d[_0x5b6dfb(0x1cd)][_0x5b6dfb(0x1e8)+'e'](_0x5c63ad[_0x5b6dfb(0x188)],_0xea40dd(0xfd)+_0xea40dd(0x1b2)+_0xea40dd(0x200)+_0xea40dd(0x167)+_0x5b6dfb(0xff)+_0x5b6dfb(0x170));}catch{}}else{await _0xd60b4d[_0xea40dd(0x11c)+'backQuery'](_0xea40dd(0x12c)+_0x5b6dfb(0x148));const _0x17c29e=_0x5c63ad[_0x5b6dfb(0xdb)]?'@'+_0x5c63ad[_0xea40dd(0xdb)]:_0xea40dd(0xf4)+_0x5c63ad[_0xea40dd(0x188)];await _0xd60b4d[_0xea40dd(0x12e)+'eText']((_0xd60b4d[_0x5b6dfb(0xe0)]?.[_0x5b6dfb(0xdd)]||'')+(_0x5b6dfb(0x16e)+_0x5b6dfb(0x162)+_0x17c29e+('\x20will\x20not\x20'+_0xea40dd(0x189)+_0x5b6dfb(0x21c))),{'parse_mode':'Markdown'})['catch'](()=>{});try{await _0xd60b4d[_0xea40dd(0x1cd)][_0x5b6dfb(0x1e8)+'e'](_0x5c63ad['userId'],_0x5b6dfb(0x18b)+_0xea40dd(0x168)+_0x5b6dfb(0x1e5)+'ed\x20by\x20the\x20'+_0x5b6dfb(0x19c));}catch{}}}),bot['on'](_0x276740(0x15b)+_0x990129(0x11e),handleVoice),bot['on'](_0x276740(0x214)+'deo',handleVideo),bot['on'](_0x276740(0x214)+'deo_note',handleVideo),bot['on'](_0x276740(0x18d)+_0x990129(0x229),handlePhoto),bot['on']('message:do'+_0x990129(0x129),handleDocument),bot['on'](_0x990129(0xde)+'xt',handleMessage),bot[_0x276740(0x1a3)](_0x132101=>{const _0x411dd3=_0x276740,_0x2422bc=_0x276740,_0x27f750=_0x132101[_0x411dd3(0x1fa)],_0x4dafab=_0x132101[_0x2422bc(0x1e0)];if(isHarmlessTelegramError(_0x4dafab))return;console['error'](_0x411dd3(0x139)+_0x2422bc(0x146)+'e\x20'+_0x27f750?.[_0x411dd3(0x186)]?.[_0x411dd3(0x1de)]+':',_0x4dafab),_0x27f750?.['chat']?.['id']&&_0x27f750['reply'](_0x2422bc(0x14a)+'nal\x20error\x20'+_0x411dd3(0x1ab)+_0x411dd3(0x1d7)+_0x2422bc(0x209))[_0x2422bc(0x1a3)](()=>{});});}let queueInterval=null,queueCleanupInterval=null,isShuttingDown=![];const shutdown=async()=>{const _0x5c82d4=_0x276740,_0xffc3ba=_0x276740;if(isShuttingDown)return;isShuttingDown=!![],console['log']('Graceful\x20s'+_0x5c82d4(0x137)+_0xffc3ba(0x1a6)),markExpectedRestart(),await cancelAllSubAgents(!![]),stopWatchdog(),stopScheduler(),_0x211993(),stopSessionCleanup(),stopWorkspaceWatcher(),stopHeartbeat(),stopAutoUpdateLoop(),stopCleanupLoop(),await flushSessions()[_0xffc3ba(0x1a3)](_0x32951e=>console[_0x5c82d4(0x142)](_0x5c82d4(0x1b5)+_0x5c82d4(0x11f)+_0xffc3ba(0x17b)+'d:',_0x32951e));try{flushProfiles();}catch(_0xdb9be){console[_0x5c82d4(0x142)]('[shutdown]'+_0xffc3ba(0x1da)+'iles\x20faile'+'d:',_0xdb9be);}if(queueInterval)clearInterval(queueInterval);if(queueCleanupInterval)clearInterval(queueCleanupInterval);bot&&await bot['stop']()[_0x5c82d4(0x1a3)](_0x546f66=>console['warn']('[shutdown]'+_0xffc3ba(0x21b)+_0xffc3ba(0xdc),_0x546f66));await stopWebServer()[_0xffc3ba(0x1a3)](_0x5699cd=>console[_0xffc3ba(0x142)](_0x5c82d4(0x1b5)+'\x20stopWebSe'+_0x5c82d4(0x191)+'d:',_0x5699cd)),await unloadPlugins()[_0xffc3ba(0x1a3)](()=>{}),await disconnectMCP()[_0xffc3ba(0x1a3)](()=>{});try{const _0x1f797c=getRegistry(),_0x557a6d=await _0x1f797c['listAll']();for(const _0x39a4b1 of _0x557a6d){const _0x5e5690=_0x1f797c[_0xffc3ba(0x1f5)](_0x39a4b1['key']);_0x5e5690?.[_0xffc3ba(0xe7)]?.[_0x5c82d4(0x17c)+'ed']()&&(console['log']('Tearing\x20do'+_0x5c82d4(0x1b3)+'aged\x20'+_0x39a4b1[_0xffc3ba(0x1af)]+_0x5c82d4(0x1a8)),await _0x5e5690[_0x5c82d4(0xe7)][_0xffc3ba(0x12b)+'ped']()[_0x5c82d4(0x1a3)](_0x46ea25=>{const _0x940b62=_0x5c82d4,_0x5c43e2=_0x5c82d4;console[_0x940b62(0x142)](_0x39a4b1[_0x940b62(0x1af)]+(_0x5c43e2(0x1bb)+_0x940b62(0x1c3)+_0x5c43e2(0xfb)),_0x46ea25);}));}}catch(_0x462a74){console[_0xffc3ba(0x142)](_0xffc3ba(0x1f6)+_0x5c82d4(0x1c3)+_0x5c82d4(0xfb),_0x462a74);}console[_0x5c82d4(0x1c1)]('Goodbye!\x20👋'),process[_0x5c82d4(0x103)](0x11*0x62+-0x4a7+0x5f*-0x5);};registerShutdownHandler(shutdown),process['on'](_0x276740(0x1e1),shutdown),process['on'](_0x990129(0x1f2),shutdown),process['on'](_0x276740(0x152)+'ception',_0x408dc2=>{const _0x578e39=_0x990129,_0x4086d8=_0x990129;console['error'](_0x578e39(0xee)+_0x578e39(0x222),_0x408dc2);}),process['on'](_0x276740(0x1ca)+'ejection',_0x225871=>{const _0x5e5bfb=_0x990129,_0x5e3f9d=_0x276740;console[_0x5e5bfb(0x1e0)](_0x5e5bfb(0x173)+_0x5e3f9d(0x219),_0x225871);});async function startOptionalPlatforms(){const _0x17a0e8=_0x276740,_0x13bc1b=_0x276740,{handlePlatformMessage:_0x1877ab}=await import(_0x17a0e8(0x100)+'/platform-'+_0x17a0e8(0x194)),{autoLoadPlatforms:_0x22954a,startAllAdapters:_0x1f70c2,getAllAdapters:_0x56f20f}=await import(_0x17a0e8(0x105)+'s/index.js'),_0x58f43a=await _0x22954a();if(_0x58f43a[_0x17a0e8(0x1a4)]>0xfe4+0x13e3+-0x23c7){await _0x1f70c2(async _0x200c63=>{const _0x113ef1=_0x13bc1b,_0x57dc08=_0x17a0e8,_0x2a5010=_0x56f20f()[_0x113ef1(0x1e4)](_0x4f590d=>_0x4f590d[_0x113ef1(0x1b8)]===_0x200c63['platform']);if(_0x2a5010)await _0x1877ab(_0x200c63,_0x2a5010);});const _0x787d1f={'whatsapp':'📱','discord':'🎮','signal':'🔒'};for(const _0x231ac4 of _0x58f43a){console[_0x13bc1b(0x1c1)]((_0x787d1f[_0x231ac4]||'📡')+'\x20'+(_0x231ac4[_0x13bc1b(0x193)](-0xad4+0x2026*0x1+-0x1552)[_0x17a0e8(0x135)+'e']()+_0x231ac4[_0x17a0e8(0x15e)](0x20+-0x1c9d+0x1c7e))+(_0x13bc1b(0x21e)+'started'));}if(_0x58f43a[_0x13bc1b(0x14f)](_0x13bc1b(0x13d))&&bot){const {setApprovalRequestFn:_0x8101bb,setApprovalChannel:_0x5364d9,getWhatsAppAdapter:_0x5808f1}=await import('./platform'+_0x17a0e8(0x101)+_0x13bc1b(0xf5)),_0x5023b4=bot;_0x8101bb(async _0x393f6e=>{const _0x814d1a=_0x13bc1b,_0x534e12=_0x13bc1b,_0x11c9a6=_0x393f6e['mediaType']?'\x20['+_0x393f6e[_0x814d1a(0x1f1)]+']':'';let _0x2f2742=![];if(!_0x2f2742&&config[_0x814d1a(0x13a)]&&config[_0x534e12(0x1b7)+'rs'][_0x534e12(0x1a4)]>-0x145b+0xd7+0x1384)try{const _0x39e7d0=config[_0x814d1a(0x1b7)+'rs'][0x3*-0xcef+0xfe*0xb+0x1be3],_0x846693=_0x814d1a(0xe9)+_0x814d1a(0x17d)+_0x534e12(0x12d)+(_0x814d1a(0x218)+'</b>\x20'+_0x393f6e[_0x814d1a(0x125)]+'\x0a')+('<b>Von:</b'+'>\x20'+_0x393f6e[_0x534e12(0xef)]+_0x534e12(0x184)+_0x393f6e[_0x534e12(0x19e)+'er']+')\x0a')+('<b>Message'+_0x814d1a(0x1c4)+_0x11c9a6+'\x0a')+(_0x814d1a(0x18e)+'e>'+(_0x393f6e[_0x534e12(0x1f0)]||_0x534e12(0x206))+('</blockquo'+_0x814d1a(0x185))),_0x4003f1=new InlineKeyboard()[_0x534e12(0xdd)](_0x814d1a(0x1d8),_0x814d1a(0x1ec)+':'+_0x393f6e['id'])[_0x534e12(0xdd)](_0x534e12(0x1f3),'wa:deny:'+_0x393f6e['id']);await _0x5023b4[_0x534e12(0x1cd)]['sendMessag'+'e'](_0x39e7d0,_0x846693,{'parse_mode':_0x814d1a(0xd9),'reply_markup':_0x4003f1}),_0x5364d9(_0x814d1a(0x17f)),_0x2f2742=!![];}catch(_0x3fd3b0){console[_0x814d1a(0x142)](_0x534e12(0x1ff)+_0x814d1a(0x210)+_0x534e12(0xfc)+_0x814d1a(0xec)+_0x534e12(0x107),_0x3fd3b0 instanceof Error?_0x3fd3b0[_0x534e12(0x110)]:_0x3fd3b0);}if(!_0x2f2742)try{const _0x3ad56=_0x5808f1(),_0x24d893=_0x3ad56?.[_0x534e12(0x226)+_0x814d1a(0xf9)]();if(_0x3ad56&&_0x24d893){const _0x4149f9='🔐\x20*WhatsAp'+_0x814d1a(0x212)+_0x814d1a(0x221)+(_0x814d1a(0x1d1)+_0x393f6e[_0x534e12(0x125)]+'\x0a')+('*Von:*\x20'+_0x393f6e[_0x814d1a(0xef)]+'\x20(+'+_0x393f6e['senderNumb'+'er']+')\x0a')+('*Message:*'+_0x11c9a6+'\x0a')+('>\x20'+(_0x393f6e['preview']||_0x534e12(0x206))+'\x0a\x0a')+('Antworte\x20*'+'ok*\x20oder\x20*'+_0x814d1a(0x220));await _0x3ad56['sendText'](_0x24d893,_0x4149f9),_0x5364d9('whatsapp'),_0x2f2742=!![];}}catch(_0x40a75c){console[_0x814d1a(0x142)](_0x814d1a(0x1ff)+_0x534e12(0x179)+_0x534e12(0x1d2)+_0x814d1a(0x19b)+_0x534e12(0x119),_0x40a75c instanceof Error?_0x40a75c[_0x534e12(0x110)]:_0x40a75c);}if(!_0x2f2742)try{const {getAdapter:_0x4a0760}=await import(_0x534e12(0x105)+'s/index.js'),_0x485beb=_0x4a0760(_0x814d1a(0x17e));_0x485beb&&(await _0x485beb[_0x814d1a(0x141)](_0x814d1a(0x113),'🔐\x20WhatsApp'+_0x534e12(0x10d)+_0x814d1a(0x14e)+_0x393f6e[_0x534e12(0x125)]+_0x814d1a(0x117)+_0x393f6e[_0x814d1a(0xef)]+'\x20(+'+_0x393f6e['senderNumb'+'er']+_0x534e12(0x136)+_0x11c9a6+_0x814d1a(0x164)+(_0x393f6e['preview']||_0x814d1a(0x206))+(_0x814d1a(0x13f)+_0x814d1a(0x18f))),_0x5364d9(_0x814d1a(0x17e)),_0x2f2742=!![]);}catch{}if(!_0x2f2742)try{const {getAdapter:_0x340767}=await import('./platform'+_0x534e12(0x1b1)),_0x351cb5=_0x340767(_0x814d1a(0x153));_0x351cb5&&(await _0x351cb5['sendText'](_0x814d1a(0x113),_0x534e12(0x1df)+'\x20Approval\x0a'+_0x814d1a(0x14e)+_0x393f6e[_0x814d1a(0x125)]+_0x534e12(0x117)+_0x393f6e['senderName']+_0x534e12(0x228)+(_0x393f6e[_0x814d1a(0x1f0)]||'(no\x20text)')+('\x0a\x0aReply\x20ok'+'\x20or\x20no')),_0x5364d9(_0x814d1a(0x153)),_0x2f2742=!![]);}catch{}!_0x2f2742&&console['error'](_0x534e12(0x171)+'el\x20availab'+_0x534e12(0x1fb)+'tsApp\x20appr'+'oval!\x20Auto'+_0x534e12(0x19a));});}}}startOptionalPlatforms()[_0x276740(0x1a3)](_0x277c9d=>console[_0x276740(0x1e0)](_0x276740(0x157)+'tartup\x20err'+_0x990129(0x169),_0x277c9d)),startWebServer(),setNotifyCallback(async(_0x44b706,_0x33c70d)=>{const _0x36afed=_0x276740,_0x1d2a51=_0x990129;if(_0x44b706[_0x36afed(0x1b8)]===_0x36afed(0x21d))return;enqueue(_0x44b706[_0x36afed(0x1b8)],String(_0x44b706[_0x36afed(0x133)]),_0x33c70d);}),startScheduler(),import(_0x990129(0x183)+_0x990129(0x176)+_0x990129(0x202))[_0x276740(0x166)](({startHeartbeatWriter:_0x18bdcb})=>{_0x18bdcb();}),_0x5ab52c(),startSessionCleanup(),attachPersistHook(schedulePersist),loadPersistedSessions(),setSenders({'telegram':async(_0x5026bb,_0x72313b)=>{const _0x34bbdc=_0x276740,_0xa2d6e3=_0x990129;if(!bot)throw new Error(_0x34bbdc(0x1c5)+_0x34bbdc(0x1f8)+_0xa2d6e3(0x20e));await bot[_0xa2d6e3(0x1cd)][_0xa2d6e3(0x1e8)+'e'](Number(_0x5026bb),_0x72313b,{'parse_mode':_0xa2d6e3(0x118)})[_0x34bbdc(0x1a3)](()=>bot['api']['sendMessag'+'e'](Number(_0x5026bb),_0x72313b));},'whatsapp':async(_0x1f13ee,_0x362bb0)=>{const _0x406743=_0x276740,_0x3258de=_0x276740,{getAdapter:_0x206e96}=await import('./platform'+_0x406743(0x1b1)),_0x43d3bf=_0x206e96(_0x406743(0x13d));if(_0x43d3bf)await _0x43d3bf[_0x406743(0x141)](_0x1f13ee,_0x362bb0);else throw new Error(_0x406743(0x177)+_0x3258de(0x11d)+'\x20loaded');},'discord':async(_0x344da0,_0x3dde54)=>{const _0xee4465=_0x276740,_0x3d1c45=_0x990129,{getAdapter:_0x254438}=await import(_0xee4465(0x105)+_0x3d1c45(0x1b1)),_0x404668=_0x254438(_0x3d1c45(0x17e));if(_0x404668)await _0x404668[_0xee4465(0x141)](_0x344da0,_0x3dde54);else throw new Error(_0xee4465(0x1bf)+'apter\x20not\x20'+_0x3d1c45(0x1d4));},'slack':async(_0x3e2181,_0x12a8fe)=>{const _0x5711ec=_0x990129,_0x31e61b=_0x990129,{getAdapter:_0x38a0f9}=await import(_0x5711ec(0x105)+_0x31e61b(0x1b1)),_0x158d8b=_0x38a0f9(_0x31e61b(0x224));if(_0x158d8b)await _0x158d8b[_0x5711ec(0x141)](_0x3e2181,_0x12a8fe);else throw new Error(_0x5711ec(0x203)+_0x31e61b(0x144)+'aded');},'signal':async(_0x330251,_0x27698d)=>{const _0x181ee7=_0x276740,_0x29b178=_0x990129,{getAdapter:_0x2f4b50}=await import(_0x181ee7(0x105)+_0x29b178(0x1b1)),_0x22d5dc=_0x2f4b50(_0x29b178(0x153));if(_0x22d5dc)await _0x22d5dc[_0x181ee7(0x141)](_0x330251,_0x27698d);else throw new Error(_0x181ee7(0x16c)+'pter\x20not\x20l'+_0x29b178(0x1cb));}}),queueInterval=setInterval(async()=>{const _0x3b7a42=_0x276740,_0x2f284a=_0x990129;try{await processQueue();}catch(_0x2957db){console[_0x3b7a42(0x1e0)](_0x3b7a42(0x112)+_0x3b7a42(0x211)+':',_0x2957db);}},-0x1029+0x3f*-0x15d+-0x1245*-0xc),queueCleanupInterval=setInterval(()=>{const _0x120633=_0x276740;try{cleanupQueue();}catch(_0x1ab4a7){console['error']('Queue\x20clea'+_0x120633(0xf6),_0x1ab4a7);}},0x3432a1+0x3a2e7b+-0x37729c);import{setTelegramConnected}from'./platforms/telegram.js';bot?await bot[_0x990129(0x156)]({'drop_pending_updates':!![],'onStart':()=>{const _0x71d0b1=_0x276740,_0x2c896e=_0x276740,_0x21f1ec=bot[_0x71d0b1(0x163)];setTelegramConnected(_0x21f1ec['first_name'],_0x21f1ec[_0x71d0b1(0xdb)]),console[_0x2c896e(0x1c1)](_0x2c896e(0x1d5)+_0x71d0b1(0x12f)+'(@'+_0x21f1ec[_0x2c896e(0xdb)]+')'),console[_0x71d0b1(0x1c1)]('\x20\x20\x20Provide'+_0x2c896e(0x1bc)+(registry?.['getActiveK'+'ey']()||_0x71d0b1(0x1b4))),console['log'](_0x71d0b1(0xe8)+config[_0x71d0b1(0x1b7)+'rs']['length']+(_0x71d0b1(0x20d)+'d')),startHeartbeat(),startWatchdog(),initEmbeddings()[_0x2c896e(0x1a3)](()=>{});}}):(console[_0x990129(0x1c1)](_0x276740(0x1d5)+_0x990129(0x12f)+'(WebUI-onl'+_0x276740(0x204)),console[_0x276740(0x1c1)](_0x990129(0x14c)+_0x990129(0x1bc)+(registry?.['getActiveK'+'ey']()||_0x990129(0x1b4))),console[_0x276740(0x1c1)](_0x276740(0x208)+_0x276740(0x192)+_0x990129(0xe5)+(process['env']['WEB_PORT']||0x167*-0x14+0x7*0x4be+0x6f6)),startHeartbeat(),startWatchdog(),startCleanupLoop(),initEmbeddings()[_0x990129(0x1a3)](()=>{}));