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.
- package/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -130
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -443
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -0
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1831
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
|
@@ -1,154 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Language Detection & Auto-Adaptation Service
|
|
3
|
-
*
|
|
4
|
-
* Detects the language of incoming messages using keyword heuristics,
|
|
5
|
-
* tracks usage statistics per user, and auto-adapts the preferred language
|
|
6
|
-
* when a clear pattern emerges.
|
|
7
|
-
*
|
|
8
|
-
* No external APIs — lightweight, fast, runs on every message.
|
|
9
|
-
*/
|
|
10
|
-
import { loadProfile, saveProfile } from "./users.js";
|
|
11
|
-
// ── Detection Heuristics ─────────────────────────────────
|
|
12
|
-
// Common words that strongly indicate a language
|
|
13
|
-
const DE_MARKERS = new Set([
|
|
14
|
-
// Articles, pronouns, prepositions
|
|
15
|
-
"ich", "du", "er", "sie", "wir", "ihr", "ein", "eine", "der", "die", "das",
|
|
16
|
-
"den", "dem", "des", "ist", "sind", "hat", "haben", "wird", "werden",
|
|
17
|
-
"nicht", "und", "oder", "aber", "auch", "noch", "schon", "nur", "sehr",
|
|
18
|
-
"mit", "von", "für", "auf", "aus", "bei", "nach", "über", "unter",
|
|
19
|
-
"kann", "muss", "soll", "will", "möchte", "bitte", "danke", "ja", "nein",
|
|
20
|
-
"wie", "was", "wer", "wo", "wann", "warum", "welche", "welcher",
|
|
21
|
-
"diese", "dieser", "dieses", "jetzt", "hier", "dort", "heute", "morgen",
|
|
22
|
-
"hallo", "guten", "morgen", "abend", "nacht", "tschüss", "mach", "mache",
|
|
23
|
-
"kannst", "könntest", "würde", "würdest", "gibt", "gib", "zeig", "sag",
|
|
24
|
-
"mir", "dir", "uns", "euch", "mein", "dein", "sein", "kein", "keine",
|
|
25
|
-
"alle", "alles", "etwas", "nichts", "viel", "mehr", "wenig", "gut",
|
|
26
|
-
"neue", "neuen", "neues", "ersten", "letzten", "nächsten",
|
|
27
|
-
]);
|
|
28
|
-
const EN_MARKERS = new Set([
|
|
29
|
-
// Articles, pronouns, prepositions
|
|
30
|
-
"the", "is", "are", "was", "were", "have", "has", "had", "will", "would",
|
|
31
|
-
"can", "could", "should", "must", "shall", "may", "might",
|
|
32
|
-
"not", "and", "but", "also", "still", "already", "only", "very",
|
|
33
|
-
"with", "from", "for", "about", "into", "through", "between",
|
|
34
|
-
"this", "that", "these", "those", "here", "there", "now", "then",
|
|
35
|
-
"what", "who", "where", "when", "why", "which", "how",
|
|
36
|
-
"please", "thanks", "thank", "yes", "hello", "hey", "bye",
|
|
37
|
-
"you", "your", "my", "his", "her", "our", "their",
|
|
38
|
-
"some", "any", "every", "all", "each", "many", "much", "more",
|
|
39
|
-
"just", "really", "actually", "right", "well", "sure", "okay",
|
|
40
|
-
"want", "need", "know", "think", "make", "give", "show", "tell",
|
|
41
|
-
"new", "first", "last", "next", "good", "great",
|
|
42
|
-
"create", "delete", "update", "send", "check", "find", "search",
|
|
43
|
-
"daily", "weekly", "summary", "list", "file", "open", "close",
|
|
44
|
-
"start", "stop", "run", "set", "get", "add", "remove",
|
|
45
|
-
]);
|
|
46
|
-
/**
|
|
47
|
-
* Detect the language of a text message.
|
|
48
|
-
* Returns 'de', 'en', or 'unknown'.
|
|
49
|
-
*/
|
|
50
|
-
export function detectLanguage(text) {
|
|
51
|
-
if (!text || text.length < 3)
|
|
52
|
-
return "unknown";
|
|
53
|
-
// Skip commands, URLs, code blocks
|
|
54
|
-
const cleaned = text
|
|
55
|
-
.replace(/^\/\w+/g, "") // remove /commands
|
|
56
|
-
.replace(/https?:\/\/\S+/g, "") // remove URLs
|
|
57
|
-
.replace(/```[\s\S]*?```/g, "") // remove code blocks
|
|
58
|
-
.replace(/`[^`]+`/g, "") // remove inline code
|
|
59
|
-
.toLowerCase();
|
|
60
|
-
const words = cleaned.split(/[\s,.!?;:()[\]{}'"]+/).filter(w => w.length >= 2);
|
|
61
|
-
if (words.length < 2)
|
|
62
|
-
return "unknown";
|
|
63
|
-
let deScore = 0;
|
|
64
|
-
let enScore = 0;
|
|
65
|
-
for (const word of words) {
|
|
66
|
-
if (DE_MARKERS.has(word))
|
|
67
|
-
deScore++;
|
|
68
|
-
if (EN_MARKERS.has(word))
|
|
69
|
-
enScore++;
|
|
70
|
-
}
|
|
71
|
-
// Umlauts are a very strong German signal
|
|
72
|
-
if (/[äöüß]/i.test(cleaned))
|
|
73
|
-
deScore += 3;
|
|
74
|
-
const total = deScore + enScore;
|
|
75
|
-
if (total < 2)
|
|
76
|
-
return "unknown"; // too few signals
|
|
77
|
-
if (deScore > enScore * 1.3)
|
|
78
|
-
return "de";
|
|
79
|
-
if (enScore > deScore * 1.3)
|
|
80
|
-
return "en";
|
|
81
|
-
return "unknown"; // ambiguous
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Update language statistics for a user and auto-adapt if pattern is clear.
|
|
85
|
-
* Returns the recommended language for this session.
|
|
86
|
-
*
|
|
87
|
-
* Note: auto-detection is intentionally limited to de/en (the two languages
|
|
88
|
-
* our heuristic covers). For es/fr users, the /language command is the only
|
|
89
|
-
* way to set their UI locale — their explicit choice is persisted via
|
|
90
|
-
* profile.langExplicit and trackAndAdapt returns it untouched.
|
|
91
|
-
*/
|
|
92
|
-
export function trackAndAdapt(userId, text, currentSessionLang) {
|
|
93
|
-
const profile = loadProfile(userId);
|
|
94
|
-
if (!profile)
|
|
95
|
-
return currentSessionLang;
|
|
96
|
-
// If user explicitly set language (via /language), honour it and never
|
|
97
|
-
// auto-switch. This is the only way es/fr get persisted.
|
|
98
|
-
if (profile.langExplicit)
|
|
99
|
-
return profile.language;
|
|
100
|
-
const detected = detectLanguage(text);
|
|
101
|
-
if (detected === "unknown")
|
|
102
|
-
return currentSessionLang;
|
|
103
|
-
// Initialize langStats if missing (existing profiles)
|
|
104
|
-
if (!profile.langStats) {
|
|
105
|
-
profile.langStats = { de: 0, en: 0, other: 0 };
|
|
106
|
-
}
|
|
107
|
-
// Update stats
|
|
108
|
-
profile.langStats[detected]++;
|
|
109
|
-
const total = profile.langStats.de + profile.langStats.en;
|
|
110
|
-
// Auto-adapt after enough signal (at least 3 messages)
|
|
111
|
-
if (total >= 3) {
|
|
112
|
-
const deRatio = profile.langStats.de / total;
|
|
113
|
-
const enRatio = profile.langStats.en / total;
|
|
114
|
-
let newLang = profile.language;
|
|
115
|
-
if (deRatio >= 0.6)
|
|
116
|
-
newLang = "de";
|
|
117
|
-
else if (enRatio >= 0.6)
|
|
118
|
-
newLang = "en";
|
|
119
|
-
if (newLang !== profile.language) {
|
|
120
|
-
profile.language = newLang;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// Early phase: follow immediate language for responsiveness.
|
|
125
|
-
// Only overrides es/fr if the user wrote in de/en without having set
|
|
126
|
-
// langExplicit — which can only happen if they changed language via
|
|
127
|
-
// something other than /language (shouldn't happen in practice).
|
|
128
|
-
profile.language = detected;
|
|
129
|
-
}
|
|
130
|
-
saveProfile(profile);
|
|
131
|
-
return profile.language;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Mark language as explicitly set by user (disables auto-detection).
|
|
135
|
-
* Accepts all supported locales including es/fr.
|
|
136
|
-
*/
|
|
137
|
-
export function setExplicitLanguage(userId, lang) {
|
|
138
|
-
const profile = loadProfile(userId);
|
|
139
|
-
if (!profile)
|
|
140
|
-
return;
|
|
141
|
-
profile.language = lang;
|
|
142
|
-
profile.langExplicit = true;
|
|
143
|
-
saveProfile(profile);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Reset to auto-detection mode.
|
|
147
|
-
*/
|
|
148
|
-
export function resetToAutoLanguage(userId) {
|
|
149
|
-
const profile = loadProfile(userId);
|
|
150
|
-
if (!profile)
|
|
151
|
-
return;
|
|
152
|
-
profile.langExplicit = false;
|
|
153
|
-
saveProfile(profile);
|
|
154
|
-
}
|
|
1
|
+
function _0x130e(_0x5cec3e,_0x2c1c9e){_0x5cec3e=_0x5cec3e-(0x78*0x3a+-0x1*0x318+-0x173a);const _0x17d352=_0x2e28();let _0x162706=_0x17d352[_0x5cec3e];if(_0x130e['feOOcr']===undefined){var _0x5bdc44=function(_0x53bcf4){const _0x530c09='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x188f09='',_0x48bf5f='',_0x534dec=_0x188f09+_0x5bdc44;for(let _0x21636a=-0x2217+0x26bb+-0x4a4,_0x172880,_0xbf6a68,_0xe43c21=0x2*0x11b5+-0x1cdd*0x1+-0x81*0xd;_0xbf6a68=_0x53bcf4['charAt'](_0xe43c21++);~_0xbf6a68&&(_0x172880=_0x21636a%(0x5bb+0x4f6+0x3*-0x38f)?_0x172880*(0x77*-0x52+0x14b*-0x19+-0x46b1*-0x1)+_0xbf6a68:_0xbf6a68,_0x21636a++%(-0x8cd+-0x1d33+0xcac*0x3))?_0x188f09+=_0x534dec['charCodeAt'](_0xe43c21+(-0xec2+0xb7d+-0xb*-0x4d))-(0xbb6*-0x1+-0xd8d+0x194d)!==0x1446+0x18e5+-0x2d2b?String['fromCharCode'](0x1705*-0x1+-0x22e1+0x3ae5&_0x172880>>(-(0x1e38+-0x3*0x1d3+-0x3*0x83f)*_0x21636a&-0x1*-0x25a2+0x13f*-0x17+0x1d*-0x4f)):_0x21636a:-0x25*-0x105+0x1912*-0x1+-0x1*0xca7){_0xbf6a68=_0x530c09['indexOf'](_0xbf6a68);}for(let _0x4e2be8=-0x275+0x1b*-0x155+0x266c,_0x370fc0=_0x188f09['length'];_0x4e2be8<_0x370fc0;_0x4e2be8++){_0x48bf5f+='%'+('00'+_0x188f09['charCodeAt'](_0x4e2be8)['toString'](0x3*-0x32d+-0x319+0x74*0x1c))['slice'](-(-0x1*0x1ece+-0x1eb1+0x3d81));}return decodeURIComponent(_0x48bf5f);};_0x130e['hVffXm']=_0x5bdc44,_0x130e['CgJzve']={},_0x130e['feOOcr']=!![];}const _0x2a2d70=_0x17d352[0x17ae+-0x1*0x23d4+0xc26],_0x1ebf1a=_0x5cec3e+_0x2a2d70,_0x88e22a=_0x130e['CgJzve'][_0x1ebf1a];if(!_0x88e22a){const _0x364c28=function(_0x4e832a){this['NyAxYT']=_0x4e832a,this['dzsbzk']=[-0x1c16+-0xfa*0x4+0x1fff*0x1,0x127a+0x211*-0xc+0x329*0x2,0x1*0x2681+-0x1*0x704+-0x1f7d],this['hWAcER']=function(){return'newState';},this['lKHSXA']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['HbvAWL']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x364c28['prototype']['rRJwzW']=function(){const _0x40f4d1=new RegExp(this['lKHSXA']+this['HbvAWL']),_0x2d7dcd=_0x40f4d1['test'](this['hWAcER']['toString']())?--this['dzsbzk'][0x68f*-0x4+-0x94b+0x2388]:--this['dzsbzk'][-0x4*0x7b7+-0x147a*0x1+-0x1*-0x3356];return this['pgkuFB'](_0x2d7dcd);},_0x364c28['prototype']['pgkuFB']=function(_0x128829){if(!Boolean(~_0x128829))return _0x128829;return this['XEZMSM'](this['NyAxYT']);},_0x364c28['prototype']['XEZMSM']=function(_0x4078a2){for(let _0x15c428=0x2134+0x1073*0x2+-0x421a,_0x159613=this['dzsbzk']['length'];_0x15c428<_0x159613;_0x15c428++){this['dzsbzk']['push'](Math['round'](Math['random']())),_0x159613=this['dzsbzk']['length'];}return _0x4078a2(this['dzsbzk'][0x342*0x7+0x1388+-0x2a56]);},new _0x364c28(_0x130e)['rRJwzW'](),_0x162706=_0x130e['hVffXm'](_0x162706),_0x130e['CgJzve'][_0x1ebf1a]=_0x162706;}else _0x162706=_0x88e22a;return _0x162706;}function _0x2e28(){const _0x47a803=['z3v0zw4','ywjLBMq','AgfK','D8o8CMrLC3q','mteZnZK2ndvSz3DQtfi','yxvJAa','C2vPBG','y2fU','AgfIzw4','CMvTB3zL','BwL0','zwLU','AwnO','BgfUz0v4CgXPyW','ywXYzwfKEq','ywjLCG','Aw50BW','ywn0DwfSBhK','nde2otaWmffkEwTkBa','yMvP','yNv0','zNjVBq','z3v0','zgvZ','Ag93','Axn0','BgfUz3vHz2u','z3jLyxq','Bw9Yzq','BMvPBG','DgvZDa','otG1mdy4vfrUtLrZ','C2LUza','BgvUz3rO','BgLZDa','mJuXmZq0mw1NAfffra','mJKZmZr4v1nQue0','yxvM','BwfRzq','C3rPBgW','DxbKyxrL','EMvPzW','mtGWmdCZnw1TwxDXzq','AgLZ','Ew91CG','DgHPCW','A2vPBMu','C2nOB24','zg9YDa','z29Vza','DgHVC2u','D2HHDa','C2HHBgW','DgHL','y3jLyxrL','DgHPBMS','BxvJAa','D2fUDa','C29Tzq','BwvPBG','DgHLC2u','B25SEq','C3rVCa','mtK4ndiZBMTMBuv4','yw55','zxr3yxm','nJzxyKr5v1y','D2vY','ywXZBW','D2vUAwC','AgfSBg8','z2LI','C3vTBwfYEq','B2THEq','ne1uC2TzEq','CgXLyxnL','D2HLCMu','D2vYzq','Dw5RBM93BG','yML0Dgu','C2vHCMnO','zwLUzq','D8o8CMrL','B3vY','AgvSBg8','Dw50zxi','zgfUA2u','DMvYEq','AwHY','BMvLza','A2fUBG','CMvHBgX5','Bw9Yz2vU','BSoKy2HZDgvU','D2H5','Dw5Z','Bgv0ENrLBG','BwLNAhq','BwfUEq','DgHHBMTZ','BMLJAhq','DgHHBMS','BMv1zxm','AgvYzq','BwfJAgu','BMv4Da','Dg9tDhjPBMC','D2HLBG','zgLLC2vY','zgLLC2u','B2rLCG','BwfJAa','D2fYDw0','zxzLCNK','z2LIDa','BMv1zw4','zgvU','y2HLy2S','yxbWBhK','D2L0Aa','AgfZ','D2LY','Ew91','yxjL','BM9JAa','Agf0','B3bLBG','D2HV','BwLY','DMLLBa','BxvZCW','D291Bgq','yNLL','yw5K','z2L2zq','ywXSzq','zgvY','zMLYC3q','zMLUza','D2HPy2G','BMfJAa','zgvSzxrL','D2fZ','BM93','Agf2zq','zgfPBhK','D2LL','y29UC3rYDwn0BW','ywjVDxq','BMfJAhq','EwvZ','Dw5K','BgfUz1n0yxrZ','C2v0','D2vSy2HL','BgfZDa','D2vLA2X5','zM9Y','BMLJAhrZ','zMLSDgvY','ywXSzxm','CMvWBgfJzq','D2LYza','zxjZDgvU','C3vYzq','D2fUBG','BM90','mtb3tMzVz08','DgHHDa','kcGOlISPkYKRkq','C3bSAxq'];_0x2e28=function(){return _0x47a803;};return _0x2e28();}const _0x56300=_0x130e,_0x26fe93=_0x130e;(function(_0x1bbc3d,_0x59ea98){const _0x5b5f67=_0x130e,_0x3c4695=_0x130e,_0x3e186b=_0x1bbc3d();while(!![]){try{const _0x3ac96e=-parseInt(_0x5b5f67(0x157))/(0x1bf0+0x81e+0x1*-0x240d)+parseInt(_0x3c4695(0x15a))/(0x1*0x1ebb+0x1*0x491+-0x234a)*(parseInt(_0x5b5f67(0x13c))/(-0x18bc+0x6ee+0x11d1))+-parseInt(_0x5b5f67(0x162))/(0x2210+-0xcc6+-0x1546)*(-parseInt(_0x3c4695(0x142))/(0x1428+-0x1619*0x1+0x1f6))+parseInt(_0x5b5f67(0x137))/(0x1*0x19bb+-0x5a8+-0x140d*0x1)+parseInt(_0x5b5f67(0x13b))/(-0x7*-0x2ed+-0x110f+-0x365)+parseInt(_0x3c4695(0x12a))/(0x1a06+-0x1*-0x1525+-0x2f23*0x1)+parseInt(_0x3c4695(0x11c))/(-0x1466+0xca5+-0x2*-0x3e5)*(-parseInt(_0x5b5f67(0x114))/(-0x6*0x1ff+-0x86*0x3e+-0x2*-0x163c));if(_0x3ac96e===_0x59ea98)break;else _0x3e186b['push'](_0x3e186b['shift']());}catch(_0x2e8d07){_0x3e186b['push'](_0x3e186b['shift']());}}}(_0x2e28,0x6a70c*0x1+0x13f*0x27a+-0x5b46b));const _0x5cfbd1=(function(){let _0x240ffd=!![];return function(_0x2be8e3,_0x5ec07c){const _0x3ba32c=_0x240ffd?function(){const _0x1e1c7a=_0x130e;if(_0x5ec07c){const _0x94d595=_0x5ec07c[_0x1e1c7a(0xe3)](_0x2be8e3,arguments);return _0x5ec07c=null,_0x94d595;}}:function(){};return _0x240ffd=![],_0x3ba32c;};}()),_0x4a4899=_0x5cfbd1(this,function(){const _0xff90b1=_0x130e,_0x5edc49=_0x130e;return _0x4a4899['toString']()[_0xff90b1(0x168)](_0xff90b1(0x116)+'+$')[_0xff90b1(0x182)]()[_0xff90b1(0x100)+'r'](_0x4a4899)[_0x5edc49(0x168)]('(((.+)+)+)'+'+$');});_0x4a4899();import{loadProfile,saveProfile}from'./users.js';const DE_MARKERS=new Set([_0x56300(0x124),'du','er','sie',_0x56300(0xe6),_0x26fe93(0x170),_0x26fe93(0x123),_0x26fe93(0x169),_0x26fe93(0xf5),'die','das',_0x26fe93(0xe1),'dem',_0x56300(0x12f),_0x26fe93(0x131),_0x26fe93(0x138),_0x56300(0xea),_0x56300(0x120),_0x26fe93(0x10f),'werden',_0x26fe93(0x17c),_0x56300(0x104),_0x26fe93(0x186),_0x56300(0x127),_0x26fe93(0x11d),_0x26fe93(0xe9),_0x56300(0x147),'nur','sehr',_0x26fe93(0x122),'von','für',_0x56300(0x13d),'aus',_0x26fe93(0x12b),_0x26fe93(0xf9),'über',_0x56300(0x16d),_0x56300(0x172),_0x26fe93(0xef),'soll','will','möchte',_0x56300(0x167),_0x26fe93(0x16e),'ja',_0x26fe93(0x135),_0x26fe93(0xff),_0x56300(0xfb),_0x26fe93(0x15b),'wo',_0x56300(0x112),_0x26fe93(0x188),_0x56300(0x107),'welcher',_0x56300(0x185),_0x56300(0x184),'dieses','jetzt','hier',_0x26fe93(0x148),'heute',_0x26fe93(0x174),_0x26fe93(0x15e),_0x56300(0x118),_0x56300(0x174),_0x26fe93(0x119),_0x56300(0x102),'tschüss',_0x26fe93(0x187),_0x26fe93(0x180),'kannst','könntest',_0x26fe93(0x16a),_0x56300(0x11b),_0x26fe93(0xdf),_0x26fe93(0x15f),_0x26fe93(0x141),'sag',_0x56300(0xed),'dir',_0x26fe93(0x177),'euch',_0x56300(0x153),'dein',_0x56300(0x11e),'kein',_0x26fe93(0x146),_0x26fe93(0xf4),_0x26fe93(0x10d),_0x26fe93(0x159),_0x56300(0x10b),_0x56300(0xee),'mehr',_0x56300(0x15d),_0x56300(0x12e),'neue',_0x56300(0xe0),_0x26fe93(0x17e),_0x56300(0x110),_0x26fe93(0x178),_0x26fe93(0x175)]),EN_MARKERS=new Set([_0x26fe93(0x14d),'is',_0x26fe93(0xe8),_0x26fe93(0xfb),_0x56300(0x165),_0x56300(0xfd),_0x26fe93(0xe5),_0x56300(0x11a),'will',_0x56300(0xf0),_0x56300(0x11f),'could','should','must',_0x56300(0x14c),'may',_0x26fe93(0x179),_0x56300(0x113),_0x26fe93(0xf2),_0x56300(0x12c),_0x26fe93(0x15c),_0x56300(0x13f),_0x56300(0x126),_0x56300(0x155),_0x56300(0x16f),_0x56300(0xe4),_0x26fe93(0x12d),_0x56300(0x10a),_0x26fe93(0x101),_0x56300(0x128),'through','between',_0x56300(0x145),_0x56300(0x115),_0x26fe93(0x154),_0x26fe93(0x14a),_0x26fe93(0x17f),'there',_0x26fe93(0xfc),'then',_0x26fe93(0x14b),_0x26fe93(0xec),_0x26fe93(0x164),_0x26fe93(0x183),_0x56300(0x176),_0x26fe93(0xf8),_0x56300(0x130),_0x26fe93(0x163),_0x26fe93(0x17b),_0x26fe93(0x17d),_0x56300(0x103),_0x26fe93(0x16c),'hey',_0x56300(0xf1),_0x26fe93(0xe7),_0x56300(0x144),'my',_0x26fe93(0x143),'her',_0x26fe93(0x16b),'their',_0x56300(0x152),_0x56300(0x158),_0x56300(0xde),'all','each',_0x26fe93(0x17a),_0x56300(0x150),_0x56300(0x134),'just',_0x56300(0x173),_0x56300(0x129),'right','well',_0x26fe93(0x111),_0x26fe93(0x161),_0x56300(0x151),_0x56300(0x171),'know',_0x56300(0x14f),_0x56300(0x13e),_0x56300(0xf3),'show','tell','new',_0x26fe93(0xf6),_0x26fe93(0x108),_0x56300(0x181),_0x56300(0x149),_0x26fe93(0x133),_0x56300(0x14e),_0x26fe93(0xfa),_0x56300(0x140),'send',_0x56300(0xe2),_0x26fe93(0xf7),_0x26fe93(0x168),_0x26fe93(0xfe),_0x26fe93(0x109),_0x26fe93(0x160),_0x26fe93(0x13a),'file',_0x56300(0xeb),'close','start',_0x56300(0x156),'run',_0x26fe93(0x106),'get','add',_0x26fe93(0x121)]);export function detectLanguage(_0x51a02b){const _0x5d73a2=_0x56300,_0x303651=_0x26fe93;if(!_0x51a02b||_0x51a02b['length']<0x1*-0x1cdd+0x26c6+-0x16a*0x7)return'unknown';const _0x4e50b8=_0x51a02b['replace'](/^\/\w+/g,'')[_0x5d73a2(0x10e)](/https?:\/\/\S+/g,'')[_0x303651(0x10e)](/```[\s\S]*?```/g,'')[_0x5d73a2(0x10e)](/`[^`]+`/g,'')['toLowerCas'+'e'](),_0xa17487=_0x4e50b8[_0x5d73a2(0x117)](/[\s,.!?;:()[\]{}'"]+/)[_0x303651(0x10c)](_0x23a2f0=>_0x23a2f0['length']>=0x5bb+0x4f6+0x5*-0x223);if(_0xa17487[_0x303651(0x139)]<0x77*-0x52+0x14b*-0x19+-0x4673*-0x1)return'unknown';let _0xa3abf4=-0x8cd+-0x1d33+0x4c0*0x8,_0x5b5532=-0xec2+0xb7d+-0x1b*-0x1f;for(const _0x13daa1 of _0xa17487){if(DE_MARKERS[_0x303651(0xe5)](_0x13daa1))_0xa3abf4++;if(EN_MARKERS[_0x5d73a2(0xe5)](_0x13daa1))_0x5b5532++;}if(/[äöüß]/i[_0x303651(0x136)](_0x4e50b8))_0xa3abf4+=0xbb6*-0x1+-0xd8d+0x1946;const _0x2b2815=_0xa3abf4+_0x5b5532;if(_0x2b2815<0x1446+0x18e5+-0x2d29)return'unknown';if(_0xa3abf4>_0x5b5532*(0x1705*-0x1+-0x22e1+0x39e7+0.30000000000000004))return'de';if(_0x5b5532>_0xa3abf4*(0x1e38+-0x3*0x1d3+-0x2*0xc5f+0.30000000000000004))return'en';return _0x303651(0x166);}export function trackAndAdapt(_0x4c970c,_0x3f623a,_0x934e2b){const _0x522552=_0x26fe93,_0x1977bd=_0x26fe93,_0x43f139=loadProfile(_0x4c970c);if(!_0x43f139)return _0x934e2b;if(_0x43f139['langExplic'+'it'])return _0x43f139['language'];const _0x2a485e=detectLanguage(_0x3f623a);if(_0x2a485e===_0x522552(0x166))return _0x934e2b;!_0x43f139[_0x522552(0x105)]&&(_0x43f139['langStats']={'de':0x0,'en':0x0,'other':0x0});_0x43f139['langStats'][_0x2a485e]++;const _0x11d77c=_0x43f139[_0x1977bd(0x105)]['de']+_0x43f139[_0x1977bd(0x105)]['en'];if(_0x11d77c>=-0x1*-0x25a2+0x13f*-0x17+0x25*-0x3e){const _0xd6851f=_0x43f139[_0x522552(0x105)]['de']/_0x11d77c,_0x2aeb6b=_0x43f139[_0x522552(0x105)]['en']/_0x11d77c;let _0x16bf0d=_0x43f139[_0x1977bd(0x132)];if(_0xd6851f>=-0x25*-0x105+0x1912*-0x1+-0x1*0xca7+0.6)_0x16bf0d='de';else{if(_0x2aeb6b>=-0x275+0x1b*-0x155+0x266c+0.6)_0x16bf0d='en';}_0x16bf0d!==_0x43f139[_0x1977bd(0x132)]&&(_0x43f139[_0x1977bd(0x132)]=_0x16bf0d);}else _0x43f139[_0x1977bd(0x132)]=_0x2a485e;return saveProfile(_0x43f139),_0x43f139[_0x1977bd(0x132)];}export function setExplicitLanguage(_0x3aa186,_0x8580e4){const _0x1e0632=_0x56300,_0x3a83db=_0x56300,_0x40630d=loadProfile(_0x3aa186);if(!_0x40630d)return;_0x40630d[_0x1e0632(0x132)]=_0x8580e4,_0x40630d[_0x1e0632(0x125)+'it']=!![],saveProfile(_0x40630d);}export function resetToAutoLanguage(_0x4eae47){const _0x463cb9=loadProfile(_0x4eae47);if(!_0x463cb9)return;_0x463cb9['langExplic'+'it']=![],saveProfile(_0x463cb9);}
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Telegram Markdown Sanitizer
|
|
3
|
-
*
|
|
4
|
-
* Telegram's Markdown parser is strict — unbalanced markers crash message sending.
|
|
5
|
-
* This module sanitizes AI-generated markdown to be Telegram-safe.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Sanitize markdown for Telegram compatibility.
|
|
9
|
-
* Fixes common issues:
|
|
10
|
-
* - Unbalanced bold (*), italic (_), code (`) markers
|
|
11
|
-
* - Nested formatting that Telegram doesn't support
|
|
12
|
-
* - Code blocks without closing ```
|
|
13
|
-
*/
|
|
14
|
-
export function sanitizeTelegramMarkdown(text) {
|
|
15
|
-
if (!text)
|
|
16
|
-
return text;
|
|
17
|
-
let result = text;
|
|
18
|
-
// Fix unclosed code blocks (```)
|
|
19
|
-
const codeBlockCount = (result.match(/```/g) || []).length;
|
|
20
|
-
if (codeBlockCount % 2 !== 0) {
|
|
21
|
-
result += "\n```";
|
|
22
|
-
}
|
|
23
|
-
// Fix unclosed inline code (`)
|
|
24
|
-
// Count backticks outside of code blocks
|
|
25
|
-
const withoutCodeBlocks = result.replace(/```[\s\S]*?```/g, "");
|
|
26
|
-
const inlineCodeCount = (withoutCodeBlocks.match(/`/g) || []).length;
|
|
27
|
-
if (inlineCodeCount % 2 !== 0) {
|
|
28
|
-
result += "`";
|
|
29
|
-
}
|
|
30
|
-
// Fix unbalanced bold markers (*) outside code blocks
|
|
31
|
-
// Simple approach: count * outside code, close if unbalanced
|
|
32
|
-
const outsideCode = result.replace(/```[\s\S]*?```/g, "").replace(/`[^`]*`/g, "");
|
|
33
|
-
const boldCount = (outsideCode.match(/\*/g) || []).length;
|
|
34
|
-
if (boldCount % 2 !== 0) {
|
|
35
|
-
// Find the last * and remove it (safer than adding one)
|
|
36
|
-
const lastStarIdx = result.lastIndexOf("*");
|
|
37
|
-
if (lastStarIdx >= 0) {
|
|
38
|
-
result = result.slice(0, lastStarIdx) + result.slice(lastStarIdx + 1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Fix unbalanced italic markers (_) outside code blocks
|
|
42
|
-
const underscoreCount = (outsideCode.match(/_/g) || []).length;
|
|
43
|
-
if (underscoreCount % 2 !== 0) {
|
|
44
|
-
const lastIdx = result.lastIndexOf("_");
|
|
45
|
-
if (lastIdx >= 0) {
|
|
46
|
-
result = result.slice(0, lastIdx) + result.slice(lastIdx + 1);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Attempt to send with Markdown, fallback to plain text.
|
|
53
|
-
* Returns the parse_mode that worked (or undefined for plain).
|
|
54
|
-
*/
|
|
55
|
-
export function getMarkdownSafe(text) {
|
|
56
|
-
try {
|
|
57
|
-
const sanitized = sanitizeTelegramMarkdown(text);
|
|
58
|
-
return { text: sanitized, parseMode: "Markdown" };
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return { text, parseMode: undefined };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
(function(_0x3bef7d,_0x5e46de){const _0x401331=_0x3e98,_0x39b895=_0x3e98,_0x54a9ed=_0x3bef7d();while(!![]){try{const _0x28b6bf=-parseInt(_0x401331(0x119))/(-0x1d9b+0x26e8+-0x94c)+-parseInt(_0x401331(0x117))/(0x1a*-0x46+-0xc7*-0x29+-0x18c1)+parseInt(_0x401331(0x105))/(-0x18*0x16+-0x8d*0x5+0x4d4)*(parseInt(_0x39b895(0x112))/(-0x1*-0x1c0d+-0x4*-0x1ca+-0x2331))+-parseInt(_0x401331(0x106))/(-0x2*0x2c5+0xda6+-0x817)*(-parseInt(_0x401331(0x10a))/(-0x1080+-0x3*0x116+-0x8*-0x279))+-parseInt(_0x39b895(0x108))/(0x6c5+0xd85+0x13*-0x111)*(-parseInt(_0x401331(0x10b))/(0xfb0+-0x4*-0x279+-0x198c*0x1))+-parseInt(_0x401331(0x11a))/(0x1b14+-0x1*0x1865+0x71*-0x6)*(parseInt(_0x39b895(0x113))/(0x1e25+-0x88*0x2b+-0xd*0x8f))+-parseInt(_0x401331(0x10d))/(-0xc*0x6f+-0x7d*-0x19+-0xc6*0x9);if(_0x28b6bf===_0x5e46de)break;else _0x54a9ed['push'](_0x54a9ed['shift']());}catch(_0x463660){_0x54a9ed['push'](_0x54a9ed['shift']());}}}(_0x2b5d,0xbd6b6*0x2+0x67*-0x2cfe+0xb*0xb817));const _0xbab1a6=(function(){let _0x374a7c=!![];return function(_0x168177,_0x6b46e6){const _0x29ea77=_0x374a7c?function(){const _0x9e0d05=_0x3e98;if(_0x6b46e6){const _0x12869e=_0x6b46e6[_0x9e0d05(0x104)](_0x168177,arguments);return _0x6b46e6=null,_0x12869e;}}:function(){};return _0x374a7c=![],_0x29ea77;};}()),_0x31c2f=_0xbab1a6(this,function(){const _0x2b69b1=_0x3e98,_0xc89096=_0x3e98;return _0x31c2f['toString']()[_0x2b69b1(0x109)](_0xc89096(0x10c)+'+$')[_0x2b69b1(0x115)]()[_0xc89096(0x116)+'r'](_0x31c2f)['search']('(((.+)+)+)'+'+$');});function _0x3e98(_0x3efbaf,_0x549295){_0x3efbaf=_0x3efbaf-(-0xa7*0x1+-0x2fc+0x4a7);const _0x231772=_0x2b5d();let _0x4d7376=_0x231772[_0x3efbaf];if(_0x3e98['PCxhaq']===undefined){var _0xfdfcef=function(_0x457f77){const _0x5e7e19='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x38c10c='',_0x1ebda3='',_0x2837ec=_0x38c10c+_0xfdfcef;for(let _0x16a64e=0xc36+0x18b1+-0xc4d*0x3,_0x44b30e,_0x39fa58,_0x20b3d1=0x4b1*0x5+0x20dd*-0x1+0x2b*0x38;_0x39fa58=_0x457f77['charAt'](_0x20b3d1++);~_0x39fa58&&(_0x44b30e=_0x16a64e%(0x1b4a*0x1+-0x325+-0x1821)?_0x44b30e*(0x202c+-0xb3*0x32+0x30a)+_0x39fa58:_0x39fa58,_0x16a64e++%(-0x58b+-0x59*0xe+0x11*0x9d))?_0x38c10c+=_0x2837ec['charCodeAt'](_0x20b3d1+(0x260b*-0x1+0x25*-0xb5+-0x201f*-0x2))-(0x1ffd+-0x609+-0x19ea)!==-0x152d*-0x1+-0x1*0x37c+-0x11b1?String['fromCharCode'](0x737*-0x5+0x2642+-0x130&_0x44b30e>>(-(0x229d+0x220*0x1+0x24bb*-0x1)*_0x16a64e&-0xa36*0x1+0x166c+0x34*-0x3c)):_0x16a64e:-0xab1+0x14d4+-0xa23){_0x39fa58=_0x5e7e19['indexOf'](_0x39fa58);}for(let _0x36f70b=0x11*0x10c+0x177c+-0x2948*0x1,_0x39326e=_0x38c10c['length'];_0x36f70b<_0x39326e;_0x36f70b++){_0x1ebda3+='%'+('00'+_0x38c10c['charCodeAt'](_0x36f70b)['toString'](-0x91c*-0x1+0x1*0x1e5e+-0x7e2*0x5))['slice'](-(0x935*0x2+0x81+0x12e9*-0x1));}return decodeURIComponent(_0x1ebda3);};_0x3e98['uBThtH']=_0xfdfcef,_0x3e98['ZOpnHd']={},_0x3e98['PCxhaq']=!![];}const _0x1c2b6d=_0x231772[0x63b+-0x14a2+0xe67],_0x2ad58a=_0x3efbaf+_0x1c2b6d,_0x13dc71=_0x3e98['ZOpnHd'][_0x2ad58a];if(!_0x13dc71){const _0x14f0e0=function(_0x58db43){this['fBYsga']=_0x58db43,this['qwMJME']=[-0x76d*-0x2+-0x919+-0x2e0*0x2,-0x2317+0x3*0xbe9+-0x1*0xa4,0x56*-0x3b+0x19ce+-0x5fc],this['mnzYVh']=function(){return'newState';},this['RVzzLE']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['KYoWNd']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x14f0e0['prototype']['dMZGIr']=function(){const _0x2e2aae=new RegExp(this['RVzzLE']+this['KYoWNd']),_0xab4701=_0x2e2aae['test'](this['mnzYVh']['toString']())?--this['qwMJME'][0x1cd9*-0x1+0x165a+-0x40*-0x1a]:--this['qwMJME'][0x1164+-0x4b4+-0x70*0x1d];return this['tZIWww'](_0xab4701);},_0x14f0e0['prototype']['tZIWww']=function(_0x334917){if(!Boolean(~_0x334917))return _0x334917;return this['iAjblU'](this['fBYsga']);},_0x14f0e0['prototype']['iAjblU']=function(_0xc32734){for(let _0x19f04b=0x191a+0x20*-0x23+0xe*-0x17b,_0x1f7612=this['qwMJME']['length'];_0x19f04b<_0x1f7612;_0x19f04b++){this['qwMJME']['push'](Math['round'](Math['random']())),_0x1f7612=this['qwMJME']['length'];}return _0xc32734(this['qwMJME'][-0xc7e+-0xb0f*0x1+0x178d]);},new _0x14f0e0(_0x3e98)['dMZGIr'](),_0x4d7376=_0x3e98['uBThtH'](_0x4d7376),_0x3e98['ZOpnHd'][_0x2ad58a]=_0x4d7376;}else _0x4d7376=_0x13dc71;return _0x4d7376;}_0x31c2f();export function sanitizeTelegramMarkdown(_0x41d11c){const _0x8374db=_0x3e98,_0x9cd697=_0x3e98;if(!_0x41d11c)return _0x41d11c;let _0x249537=_0x41d11c;const _0x3b68ef=(_0x249537[_0x8374db(0x111)](/```/g)||[])[_0x8374db(0x10f)];_0x3b68ef%(0x2f*-0xb3+0x3f4*0x5+0x131*0xb)!==-0x1*0x325+0x2296+-0x1f71*0x1&&(_0x249537+=_0x8374db(0x114));const _0xd76467=_0x249537['replace'](/```[\s\S]*?```/g,''),_0x1f2b1d=(_0xd76467[_0x8374db(0x111)](/`/g)||[])[_0x8374db(0x10f)];_0x1f2b1d%(-0x1885+0x1339+0x54e)!==-0x59*0xe+0x1d*-0x96+0x15dc&&(_0x249537+='`');const _0x543049=_0x249537[_0x9cd697(0x107)](/```[\s\S]*?```/g,'')['replace'](/`[^`]*`/g,''),_0x36ed6c=(_0x543049[_0x8374db(0x111)](/\*/g)||[])[_0x8374db(0x10f)];if(_0x36ed6c%(0x1*-0x1a29+0x1756*0x1+0x2d5)!==0x1ffd+-0x609+-0x19f4){const _0x5b4c09=_0x249537['lastIndexO'+'f']('*');_0x5b4c09>=-0x152d*-0x1+-0x1*0x37c+-0x11b1&&(_0x249537=_0x249537[_0x8374db(0x118)](0x737*-0x5+0x2642+-0x22f,_0x5b4c09)+_0x249537[_0x9cd697(0x118)](_0x5b4c09+(0x229d+0x220*0x1+0x92f*-0x4)));}const _0x4dc33b=(_0x543049[_0x9cd697(0x111)](/_/g)||[])['length'];if(_0x4dc33b%(-0xa36*0x1+0x166c+0x2c*-0x47)!==-0xab1+0x14d4+-0xa23){const _0x2abc23=_0x249537[_0x8374db(0x10e)+'f']('_');_0x2abc23>=0x11*0x10c+0x177c+-0x2948*0x1&&(_0x249537=_0x249537[_0x8374db(0x118)](-0x91c*-0x1+0x1*0x1e5e+-0x146*0x1f,_0x2abc23)+_0x249537[_0x8374db(0x118)](_0x2abc23+(0x935*0x2+0x81+0x12ea*-0x1)));}return _0x249537;}export function getMarkdownSafe(_0x49356f){const _0x41f0f6=_0x3e98;try{const _0x3d3ff6=sanitizeTelegramMarkdown(_0x49356f);return{'text':_0x3d3ff6,'parseMode':_0x41f0f6(0x110)};}catch{return{'text':_0x49356f,'parseMode':undefined};}}function _0x2b5d(){const _0x5ebf7f=['BgfZDeLUzgv4tW','BgvUz3rO','twfYA2rVD24','Bwf0y2G','mJKXodC2DffPChHR','otKYmdCWv1PXEeje','cMbGya','Dg9tDhjPBMC','y29UC3rYDwn0BW','mtC5mZuXmeHnvKXYCW','C2XPy2u','mJqWnJGYCKHSuxHZ','ndvvDhrXqMi','yxbWBhK','ndHVq2jSsvu','ndyXote1tfPfCxzT','CMvWBgfJzq','mtiWnJe3v3PMqMDV','C2vHCMnO','odrmrNjerMW','nta0CNzPuKXm','kcGOlISPkYKRkq','mteZmJa5odbKC1jhvge'];_0x2b5d=function(){return _0x5ebf7f;};return _0x2b5d();}
|
package/dist/services/mcp.js
CHANGED
|
@@ -1,263 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP (Model Context Protocol) Client — Connect to any MCP-compatible tool server.
|
|
3
|
-
*
|
|
4
|
-
* Supports:
|
|
5
|
-
* - stdio transport (local processes)
|
|
6
|
-
* - HTTP/SSE transport (remote servers)
|
|
7
|
-
*
|
|
8
|
-
* Configuration via docs/mcp.json:
|
|
9
|
-
* {
|
|
10
|
-
* "servers": {
|
|
11
|
-
* "filesystem": {
|
|
12
|
-
* "command": "npx",
|
|
13
|
-
* "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
|
|
14
|
-
* "env": {}
|
|
15
|
-
* },
|
|
16
|
-
* "remote-server": {
|
|
17
|
-
* "url": "https://mcp.example.com/sse",
|
|
18
|
-
* "headers": { "Authorization": "Bearer ..." }
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*/
|
|
23
|
-
import { spawn } from "child_process";
|
|
24
|
-
import fs from "fs";
|
|
25
|
-
import { MCP_CONFIG } from "../paths.js";
|
|
26
|
-
// ── MCP Client ──────────────────────────────────────────
|
|
27
|
-
const servers = new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Load MCP configuration from docs/mcp.json.
|
|
30
|
-
*/
|
|
31
|
-
function loadConfig() {
|
|
32
|
-
try {
|
|
33
|
-
const raw = fs.readFileSync(MCP_CONFIG, "utf-8");
|
|
34
|
-
return JSON.parse(raw);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return { servers: {} };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Send a JSON-RPC message to a stdio MCP server.
|
|
42
|
-
*/
|
|
43
|
-
function sendMessage(server, method, params) {
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
if (!server.process?.stdin?.writable) {
|
|
46
|
-
reject(new Error(`Server ${server.name} not connected`));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const id = ++server.requestId;
|
|
50
|
-
const message = JSON.stringify({
|
|
51
|
-
jsonrpc: "2.0",
|
|
52
|
-
id,
|
|
53
|
-
method,
|
|
54
|
-
params: params || {},
|
|
55
|
-
});
|
|
56
|
-
server.pendingRequests.set(id, { resolve, reject });
|
|
57
|
-
// Timeout after 30s
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
if (server.pendingRequests.has(id)) {
|
|
60
|
-
server.pendingRequests.delete(id);
|
|
61
|
-
reject(new Error(`Request ${id} timed out`));
|
|
62
|
-
}
|
|
63
|
-
}, 30000);
|
|
64
|
-
server.process.stdin.write(message + "\n");
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Handle incoming JSON-RPC responses from a stdio server.
|
|
69
|
-
*/
|
|
70
|
-
function handleResponse(server, line) {
|
|
71
|
-
try {
|
|
72
|
-
const msg = JSON.parse(line);
|
|
73
|
-
if (msg.id && server.pendingRequests.has(msg.id)) {
|
|
74
|
-
const pending = server.pendingRequests.get(msg.id);
|
|
75
|
-
server.pendingRequests.delete(msg.id);
|
|
76
|
-
if (msg.error) {
|
|
77
|
-
pending.reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
pending.resolve(msg.result);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
// Not valid JSON — skip
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Connect to a stdio MCP server.
|
|
90
|
-
*/
|
|
91
|
-
async function connectStdio(name, config) {
|
|
92
|
-
const server = {
|
|
93
|
-
name,
|
|
94
|
-
config,
|
|
95
|
-
tools: [],
|
|
96
|
-
connected: false,
|
|
97
|
-
requestId: 0,
|
|
98
|
-
pendingRequests: new Map(),
|
|
99
|
-
buffer: "",
|
|
100
|
-
};
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
const proc = spawn(config.command, config.args || [], {
|
|
103
|
-
env: { ...process.env, ...config.env },
|
|
104
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
105
|
-
});
|
|
106
|
-
server.process = proc;
|
|
107
|
-
proc.stdout.on("data", (data) => {
|
|
108
|
-
server.buffer += data.toString();
|
|
109
|
-
const lines = server.buffer.split("\n");
|
|
110
|
-
server.buffer = lines.pop() || "";
|
|
111
|
-
for (const line of lines) {
|
|
112
|
-
if (line.trim())
|
|
113
|
-
handleResponse(server, line.trim());
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
proc.stderr.on("data", (data) => {
|
|
117
|
-
console.error(`MCP ${name} stderr:`, data.toString().trim());
|
|
118
|
-
});
|
|
119
|
-
// Surface stderr stream errors so we don't silently lose the channel
|
|
120
|
-
// (EPIPE, ECONNRESET etc). Without this, unhandled 'error' on the
|
|
121
|
-
// stream would crash the whole Node process.
|
|
122
|
-
proc.stderr.on("error", (err) => {
|
|
123
|
-
console.error(`MCP ${name} stderr stream error:`, err.message);
|
|
124
|
-
server.connected = false;
|
|
125
|
-
});
|
|
126
|
-
proc.stdout?.on("error", (err) => {
|
|
127
|
-
console.error(`MCP ${name} stdout stream error:`, err.message);
|
|
128
|
-
server.connected = false;
|
|
129
|
-
});
|
|
130
|
-
proc.on("error", (err) => {
|
|
131
|
-
console.error(`MCP ${name} process error:`, err);
|
|
132
|
-
server.connected = false;
|
|
133
|
-
});
|
|
134
|
-
proc.on("close", (code) => {
|
|
135
|
-
console.log(`MCP ${name} exited with code ${code}`);
|
|
136
|
-
server.connected = false;
|
|
137
|
-
});
|
|
138
|
-
// Initialize the connection
|
|
139
|
-
setTimeout(async () => {
|
|
140
|
-
try {
|
|
141
|
-
// Send initialize
|
|
142
|
-
await sendMessage(server, "initialize", {
|
|
143
|
-
protocolVersion: "2024-11-05",
|
|
144
|
-
capabilities: {},
|
|
145
|
-
clientInfo: { name: "alvin-bot", version: "2.2.0" },
|
|
146
|
-
});
|
|
147
|
-
// Send initialized notification
|
|
148
|
-
server.process.stdin.write(JSON.stringify({
|
|
149
|
-
jsonrpc: "2.0",
|
|
150
|
-
method: "notifications/initialized",
|
|
151
|
-
}) + "\n");
|
|
152
|
-
// List tools
|
|
153
|
-
const result = await sendMessage(server, "tools/list");
|
|
154
|
-
server.tools = result?.tools || [];
|
|
155
|
-
server.connected = true;
|
|
156
|
-
console.log(`MCP ${name}: connected, ${server.tools.length} tools`);
|
|
157
|
-
resolve(server);
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
reject(err);
|
|
161
|
-
}
|
|
162
|
-
}, 500);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
// ── Public API ──────────────────────────────────────────
|
|
166
|
-
/**
|
|
167
|
-
* Initialize all configured MCP servers.
|
|
168
|
-
*/
|
|
169
|
-
export async function initMCP() {
|
|
170
|
-
const config = loadConfig();
|
|
171
|
-
const connected = [];
|
|
172
|
-
const errors = [];
|
|
173
|
-
for (const [name, serverConfig] of Object.entries(config.servers)) {
|
|
174
|
-
try {
|
|
175
|
-
if (serverConfig.command) {
|
|
176
|
-
const server = await connectStdio(name, serverConfig);
|
|
177
|
-
servers.set(name, server);
|
|
178
|
-
connected.push(name);
|
|
179
|
-
}
|
|
180
|
-
else if (serverConfig.url) {
|
|
181
|
-
// HTTP/SSE transport — not yet implemented
|
|
182
|
-
errors.push({ name, error: "HTTP/SSE transport not yet supported" });
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
187
|
-
errors.push({ name, error: msg });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
return { connected, errors };
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Call a tool on an MCP server.
|
|
194
|
-
*/
|
|
195
|
-
export async function callMCPTool(serverName, toolName, args) {
|
|
196
|
-
const server = servers.get(serverName);
|
|
197
|
-
if (!server)
|
|
198
|
-
throw new Error(`MCP server "${serverName}" not found`);
|
|
199
|
-
if (!server.connected)
|
|
200
|
-
throw new Error(`MCP server "${serverName}" not connected`);
|
|
201
|
-
const result = await sendMessage(server, "tools/call", {
|
|
202
|
-
name: toolName,
|
|
203
|
-
arguments: args,
|
|
204
|
-
});
|
|
205
|
-
// Extract text from content array
|
|
206
|
-
const texts = (result?.content || [])
|
|
207
|
-
.filter((c) => c.type === "text")
|
|
208
|
-
.map((c) => c.text || "");
|
|
209
|
-
return texts.join("\n") || JSON.stringify(result);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Get all available MCP tools across all servers.
|
|
213
|
-
*/
|
|
214
|
-
export function getMCPTools() {
|
|
215
|
-
const tools = [];
|
|
216
|
-
for (const [serverName, server] of servers) {
|
|
217
|
-
for (const tool of server.tools) {
|
|
218
|
-
tools.push({
|
|
219
|
-
server: serverName,
|
|
220
|
-
name: tool.name,
|
|
221
|
-
description: tool.description,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return tools;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Get MCP server status.
|
|
229
|
-
*/
|
|
230
|
-
export function getMCPStatus() {
|
|
231
|
-
const result = [];
|
|
232
|
-
for (const [name, server] of servers) {
|
|
233
|
-
result.push({
|
|
234
|
-
name,
|
|
235
|
-
connected: server.connected,
|
|
236
|
-
tools: server.tools.length,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Disconnect all MCP servers.
|
|
243
|
-
*/
|
|
244
|
-
export async function disconnectMCP() {
|
|
245
|
-
for (const [name, server] of servers) {
|
|
246
|
-
try {
|
|
247
|
-
if (server.process) {
|
|
248
|
-
server.process.kill();
|
|
249
|
-
}
|
|
250
|
-
console.log(`MCP ${name} disconnected`);
|
|
251
|
-
}
|
|
252
|
-
catch (err) {
|
|
253
|
-
console.error(`MCP ${name} disconnect error:`, err);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
servers.clear();
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Check if MCP config exists.
|
|
260
|
-
*/
|
|
261
|
-
export function hasMCPConfig() {
|
|
262
|
-
return fs.existsSync(MCP_CONFIG);
|
|
263
|
-
}
|
|
1
|
+
(function(_0x53fe70,_0x49c9aa){const _0x5746b4=_0x2a07,_0x358622=_0x2a07,_0x1635ff=_0x53fe70();while(!![]){try{const _0x4ae613=-parseInt(_0x5746b4(0x16e))/(0x19dc+0x1*0x22ef+0x1f*-0x1f6)+parseInt(_0x358622(0x181))/(0x1*0x153d+0x991+0x1*-0x1ecc)*(parseInt(_0x5746b4(0x165))/(0x1044*0x1+-0x16d5+0x1a5*0x4))+parseInt(_0x5746b4(0x153))/(-0x1f0d*-0x1+-0x137b+-0x6*0x1ed)*(parseInt(_0x358622(0x14b))/(0x5*0x97+-0x1*-0x1abe+-0x1dac))+parseInt(_0x5746b4(0x174))/(-0x1333+0x2cf*-0x1+0x1608*0x1)+-parseInt(_0x358622(0x15f))/(0xd*-0xa7+0xf25*-0x1+0x17a7)+-parseInt(_0x5746b4(0x142))/(0x647+-0xd69*0x1+0x72a)*(parseInt(_0x358622(0x132))/(0x22bf+0x24bd+0x3*-0x17d1))+parseInt(_0x358622(0x15a))/(0x990+-0x208a+0x1704);if(_0x4ae613===_0x49c9aa)break;else _0x1635ff['push'](_0x1635ff['shift']());}catch(_0x17f39b){_0x1635ff['push'](_0x1635ff['shift']());}}}(_0x4ec7,0x8a094+-0x7ec5e+0x3d585));const _0x5d42b0=(function(){let _0x522433=!![];return function(_0x2fab6a,_0x5ee403){const _0x4e5798=_0x522433?function(){if(_0x5ee403){const _0x172518=_0x5ee403['apply'](_0x2fab6a,arguments);return _0x5ee403=null,_0x172518;}}:function(){};return _0x522433=![],_0x4e5798;};}()),_0x489f87=_0x5d42b0(this,function(){const _0x29af16=_0x2a07,_0x503162=_0x2a07;return _0x489f87[_0x29af16(0x180)]()[_0x503162(0x139)]('(((.+)+)+)'+'+$')['toString']()[_0x29af16(0x159)+'r'](_0x489f87)['search'](_0x29af16(0x141)+'+$');});_0x489f87();import{spawn}from'child_process';import _0x535487 from'fs';import{MCP_CONFIG}from'../paths.js';const servers=new Map();function _0x4ec7(){const _0x5c31d0=['ihn0zgvYCJO','mI4YlJa','u2vYDMvYia','Bg9N','Dg9tDhjPBMC','odiXmgTrruHswa','C2v0','sfruuc9tu0uGDa','DcbLCNjVCJO','ntmXrejpqMDL','ihn0zgvYCIbZDa','CgfYC2u','AgfZ','BgvUz3rO','tunqia','ig5VDcbJB25Uzq','C2vHCMnO','ChjVy2vZCW','igrPC2nVBM5LyW','uMvXDwvZDca','zcWG','zMLSDgvY','yxjNCW','ihbYB2nLC3mGzq','kcGOlISPkYKRkq','nJyWnZjRsfPPy1u','DwvZDhm','zw50CMLLCW','ChvZAa','y29UDgvUDa','y29TBwfUza','zxjYB3i','z2v0','Dg9VBhmVBgLZDa','nwX5wen5Cq','BwvZC2fNzq','Dg9VBhm','ihrVB2XZ','zgvSzxrL','y2XLyxi','ihrPBwvKig91Da','Dgv4Da','nJeZmdC2DMnnzK1g','BMfTzq','CMvQzwn0','CMvZB2X2zq','zgvZy3jPChrPBW','C3bSAxq','y29UC3rYDwn0BW','nJa4nZyYme5IueTttG','D3jPDgu','ywX2Aw4TyM90','B25Zl2LUAxrPyq','B3qGEwv0ihn1Ca','mJi4nJuXnxvfvLLbta','C3rKB3v0','CMfUC3bVCNqGBG','CgLWzq','y2XVC2u','C3rKAw4','nLvzA3zJqW','Cg9YDgvK','CMvZDwX0','C3rYAw5NAwz5','zgf0yq','C3rKzxjY','mJaYnc0Xms0Wnq','CgvUzgLUz1jLCq','tunqihnLCNzLCG','mJm5odCYA0vArK5W','y29UBMvJDgvK','iIbUB3qGy29UBG','zw52','CMvXDwvZDeLK','CMvHBsbLCNjVCG','mZq4ntC2mfDPvwrHwa','iIbUB3qGzM91BG','yNvMzMvY','DhLWzq','mI4W','CMvHzezPBgvtEq','D3jPDgfIBgu','DhjPBq'];_0x4ec7=function(){return _0x5c31d0;};return _0x4ec7();}function loadConfig(){const _0x41568d=_0x2a07,_0x3ea10f=_0x2a07;try{const _0x6ec34c=_0x535487[_0x41568d(0x179)+'nc'](MCP_CONFIG,'utf-8');return JSON[_0x41568d(0x134)](_0x6ec34c);}catch{return{'servers':{}};}}function sendMessage(_0x1f698d,_0xf97d4a,_0x32186e){return new Promise((_0xf9aaa2,_0x2d3c34)=>{const _0x281ccd=_0x2a07,_0x498702=_0x2a07;if(!_0x1f698d['process']?.[_0x281ccd(0x164)]?.[_0x498702(0x17a)]){_0x2d3c34(new Error(_0x281ccd(0x17e)+_0x1f698d[_0x281ccd(0x154)]+(_0x281ccd(0x138)+'cted')));return;}const _0x40d977=++_0x1f698d[_0x281ccd(0x172)],_0x404498=JSON['stringify']({'jsonrpc':_0x498702(0x178),'id':_0x40d977,'method':_0xf97d4a,'params':_0x32186e||{}});_0x1f698d[_0x281ccd(0x16c)+'uests']['set'](_0x40d977,{'resolve':_0xf9aaa2,'reject':_0x2d3c34}),setTimeout(()=>{const _0xa3978c=_0x498702,_0x4835f6=_0x281ccd;_0x1f698d[_0xa3978c(0x16c)+_0x4835f6(0x143)][_0xa3978c(0x135)](_0x40d977)&&(_0x1f698d[_0x4835f6(0x16c)+_0x4835f6(0x143)][_0xa3978c(0x14f)](_0x40d977),_0x2d3c34(new Error(_0x4835f6(0x13c)+_0x40d977+_0xa3978c(0x151))));},-0x7549+0x2*0x1678+0xbd89*0x1),_0x1f698d[_0x498702(0x13a)][_0x498702(0x164)][_0x281ccd(0x15b)](_0x404498+'\x0a');});}function handleResponse(_0x5cdf43,_0x138b6c){const _0x22ee4e=_0x2a07,_0x18fc89=_0x2a07;try{const _0x5841cf=JSON[_0x22ee4e(0x134)](_0x138b6c);if(_0x5841cf['id']&&_0x5cdf43['pendingReq'+_0x18fc89(0x143)][_0x18fc89(0x135)](_0x5841cf['id'])){const _0x245a09=_0x5cdf43[_0x18fc89(0x16c)+_0x18fc89(0x143)][_0x22ee4e(0x149)](_0x5841cf['id']);_0x5cdf43[_0x22ee4e(0x16c)+_0x18fc89(0x143)]['delete'](_0x5841cf['id']),_0x5841cf[_0x18fc89(0x148)]?_0x245a09[_0x22ee4e(0x155)](new Error(_0x5841cf[_0x18fc89(0x148)][_0x22ee4e(0x14c)]||JSON[_0x18fc89(0x168)](_0x5841cf[_0x18fc89(0x148)]))):_0x245a09[_0x22ee4e(0x156)](_0x5841cf[_0x22ee4e(0x167)]);}}catch{}}async function connectStdio(_0x38deeb,_0x2828a0){const _0x3a2091={'name':_0x38deeb,'config':_0x2828a0,'tools':[],'connected':![],'requestId':0x0,'pendingRequests':new Map(),'buffer':''};return new Promise((_0x5eb259,_0x267352)=>{const _0x345be6=_0x2a07,_0x1e39f4=_0x2a07,_0x73ad72=spawn(_0x2828a0[_0x345be6(0x147)],_0x2828a0[_0x345be6(0x13f)]||[],{'env':{...process[_0x345be6(0x171)],..._0x2828a0[_0x345be6(0x171)]},'stdio':[_0x345be6(0x162),'pipe',_0x1e39f4(0x162)]});_0x3a2091['process']=_0x73ad72,_0x73ad72[_0x1e39f4(0x160)]['on'](_0x1e39f4(0x169),_0x41fa60=>{const _0x33ab35=_0x1e39f4,_0x32457b=_0x1e39f4;_0x3a2091[_0x33ab35(0x176)]+=_0x41fa60[_0x33ab35(0x180)]();const _0x53a59c=_0x3a2091[_0x33ab35(0x176)][_0x33ab35(0x158)]('\x0a');_0x3a2091[_0x33ab35(0x176)]=_0x53a59c['pop']()||'';for(const _0x563b19 of _0x53a59c){if(_0x563b19['trim']())handleResponse(_0x3a2091,_0x563b19[_0x32457b(0x17b)]());}}),_0x73ad72[_0x345be6(0x16a)]['on'](_0x1e39f4(0x169),_0x6ace62=>{const _0x249e4d=_0x345be6,_0x1c5a03=_0x345be6;console[_0x249e4d(0x148)](_0x249e4d(0x137)+_0x38deeb+_0x249e4d(0x17c),_0x6ace62['toString']()['trim']());}),_0x73ad72[_0x345be6(0x16a)]['on']('error',_0x139619=>{const _0x517740=_0x345be6,_0xaad03d=_0x345be6;console['error'](_0x517740(0x137)+_0x38deeb+(_0xaad03d(0x133)+_0x517740(0x173)+':'),_0x139619[_0x517740(0x14c)]),_0x3a2091[_0xaad03d(0x16f)]=![];}),_0x73ad72['stdout']?.['on']('error',_0x5b88df=>{const _0x3e25d7=_0x1e39f4,_0x2121ed=_0x345be6;console[_0x3e25d7(0x148)](_0x3e25d7(0x137)+_0x38deeb+('\x20stdout\x20st'+'ream\x20error'+':'),_0x5b88df['message']),_0x3a2091['connected']=![];}),_0x73ad72['on'](_0x345be6(0x148),_0x49b7ba=>{const _0x3cab23=_0x345be6,_0x5c187e=_0x345be6;console[_0x3cab23(0x148)]('MCP\x20'+_0x38deeb+(_0x5c187e(0x140)+'rror:'),_0x49b7ba),_0x3a2091['connected']=![];}),_0x73ad72['on'](_0x345be6(0x163),_0x3f5800=>{const _0x372f6d=_0x345be6,_0x5de84e=_0x1e39f4;console['log'](_0x372f6d(0x137)+_0x38deeb+('\x20exited\x20wi'+'th\x20code\x20')+_0x3f5800),_0x3a2091[_0x5de84e(0x16f)]=![];}),setTimeout(async()=>{const _0x24027d=_0x345be6,_0x4e7187=_0x345be6;try{await sendMessage(_0x3a2091,'initialize',{'protocolVersion':_0x24027d(0x16b),'capabilities':{},'clientInfo':{'name':_0x4e7187(0x15c),'version':_0x4e7187(0x17d)}}),_0x3a2091[_0x24027d(0x13a)][_0x4e7187(0x164)]['write'](JSON[_0x24027d(0x168)]({'jsonrpc':'2.0','method':'notificati'+_0x4e7187(0x15d)+'lized'})+'\x0a');const _0x454ab3=await sendMessage(_0x3a2091,_0x24027d(0x14a));_0x3a2091['tools']=_0x454ab3?.[_0x4e7187(0x14d)]||[],_0x3a2091[_0x4e7187(0x16f)]=!![],console[_0x24027d(0x17f)](_0x24027d(0x137)+_0x38deeb+(':\x20connecte'+_0x24027d(0x13d))+_0x3a2091[_0x4e7187(0x14d)]['length']+_0x4e7187(0x14e)),_0x5eb259(_0x3a2091);}catch(_0x2be8c0){_0x267352(_0x2be8c0);}},-0x103+0x331*-0x1+0x628);});}function _0x2a07(_0x327ad7,_0x4aa989){_0x327ad7=_0x327ad7-(-0x233b*0x1+0xe1*0x25+0x3e5);const _0x32d611=_0x4ec7();let _0xbb7b6b=_0x32d611[_0x327ad7];if(_0x2a07['kjkwOY']===undefined){var _0x84c62d=function(_0x4275a9){const _0x51cc31='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x491f93='',_0x4f3ff8='',_0x5a5322=_0x491f93+_0x84c62d;for(let _0x14f0c9=0x1*0xeda+0x446+-0x1320,_0x304304,_0x32b138,_0x34990b=-0x138c+0x3*0x27f+0xc0f*0x1;_0x32b138=_0x4275a9['charAt'](_0x34990b++);~_0x32b138&&(_0x304304=_0x14f0c9%(-0x103+0x331*-0x1+0x438)?_0x304304*(0x1d34+0xe1d*0x2+-0x392e)+_0x32b138:_0x32b138,_0x14f0c9++%(-0x2166+-0x472*0x3+0x2ec0))?_0x491f93+=_0x5a5322['charCodeAt'](_0x34990b+(-0x3d*-0x3b+-0x5*0x728+-0x1*-0x15c3))-(0x88d+0x2684+0x2f07*-0x1)!==-0x22a8+0xbb*-0x2e+0x2*0x2221?String['fromCharCode'](0x319*-0x1+-0xc9b+0x10b3&_0x304304>>(-(-0x2*0x2af+-0x90e+-0x2*-0x737)*_0x14f0c9&-0x183e+0x168d+0x1b7)):_0x14f0c9:0x43*0x83+-0x1979+-0x8d0){_0x32b138=_0x51cc31['indexOf'](_0x32b138);}for(let _0x3bee14=0x9ff+0x22f1+-0x2cf0,_0x499bdd=_0x491f93['length'];_0x3bee14<_0x499bdd;_0x3bee14++){_0x4f3ff8+='%'+('00'+_0x491f93['charCodeAt'](_0x3bee14)['toString'](-0x17*-0x6+0xa11+-0xa8b))['slice'](-(0x1ae0*0x1+0x1f61+-0x3a3f));}return decodeURIComponent(_0x4f3ff8);};_0x2a07['BFQUHO']=_0x84c62d,_0x2a07['jBERiX']={},_0x2a07['kjkwOY']=!![];}const _0x48034a=_0x32d611[0x13c+-0x1d40+0x1c04*0x1],_0x1fd33a=_0x327ad7+_0x48034a,_0x4ca975=_0x2a07['jBERiX'][_0x1fd33a];if(!_0x4ca975){const _0x3b5d02=function(_0x37fec4){this['SGPkjP']=_0x37fec4,this['gTvDPh']=[0x847+0x1505+0x1*-0x1d4b,0x1f1*0x6+-0x116*-0x18+-0x25b6,-0x235b+0x38d+-0x54d*-0x6],this['nZhtmj']=function(){return'newState';},this['MDklDn']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['gHdsdc']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x3b5d02['prototype']['tRvqEg']=function(){const _0x33ef20=new RegExp(this['MDklDn']+this['gHdsdc']),_0x1aaae8=_0x33ef20['test'](this['nZhtmj']['toString']())?--this['gTvDPh'][0x130d+0x7cf+0x5*-0x55f]:--this['gTvDPh'][-0x57*0x7+-0x718*0x2+0x1091];return this['DqXrRX'](_0x1aaae8);},_0x3b5d02['prototype']['DqXrRX']=function(_0x4ab4f9){if(!Boolean(~_0x4ab4f9))return _0x4ab4f9;return this['IBTNbs'](this['SGPkjP']);},_0x3b5d02['prototype']['IBTNbs']=function(_0x31a8b5){for(let _0x438aa9=0xbca*0x3+0x1*-0x88c+-0xd69*0x2,_0x13d25f=this['gTvDPh']['length'];_0x438aa9<_0x13d25f;_0x438aa9++){this['gTvDPh']['push'](Math['round'](Math['random']())),_0x13d25f=this['gTvDPh']['length'];}return _0x31a8b5(this['gTvDPh'][0xaec+0x25b5+0x1*-0x30a1]);},new _0x3b5d02(_0x2a07)['tRvqEg'](),_0xbb7b6b=_0x2a07['BFQUHO'](_0xbb7b6b),_0x2a07['jBERiX'][_0x1fd33a]=_0xbb7b6b;}else _0xbb7b6b=_0x4ca975;return _0xbb7b6b;}export async function initMCP(){const _0x1a70cf=_0x2a07,_0x2cbfd0=_0x2a07,_0x204dd3=loadConfig(),_0x51d852=[],_0x58da9d=[];for(const [_0x2e4981,_0x10817b]of Object[_0x1a70cf(0x144)](_0x204dd3['servers'])){try{if(_0x10817b[_0x2cbfd0(0x147)]){const _0x2923b7=await connectStdio(_0x2e4981,_0x10817b);servers[_0x1a70cf(0x12f)](_0x2e4981,_0x2923b7),_0x51d852['push'](_0x2e4981);}else _0x10817b['url']&&_0x58da9d[_0x2cbfd0(0x145)]({'name':_0x2e4981,'error':_0x2cbfd0(0x130)+_0x1a70cf(0x161)+_0x1a70cf(0x15e)+_0x1a70cf(0x166)});}catch(_0x24a373){const _0x36150f=_0x24a373 instanceof Error?_0x24a373[_0x2cbfd0(0x14c)]:String(_0x24a373);_0x58da9d['push']({'name':_0x2e4981,'error':_0x36150f});}}return{'connected':_0x51d852,'errors':_0x58da9d};}export async function callMCPTool(_0x26300f,_0x195529,_0x5e8c86){const _0x5cba7b=_0x2a07,_0xc4e1de=_0x2a07,_0x2122c1=servers[_0x5cba7b(0x149)](_0x26300f);if(!_0x2122c1)throw new Error(_0x5cba7b(0x16d)+'\x20\x22'+_0x26300f+(_0xc4e1de(0x175)+'d'));if(!_0x2122c1['connected'])throw new Error(_0xc4e1de(0x16d)+'\x20\x22'+_0x26300f+(_0x5cba7b(0x170)+'ected'));const _0x1219c1=await sendMessage(_0x2122c1,'tools/call',{'name':_0x195529,'arguments':_0x5e8c86}),_0x4b3679=(_0x1219c1?.[_0xc4e1de(0x146)]||[])[_0x5cba7b(0x13e)](_0x1b9bd2=>_0x1b9bd2[_0x5cba7b(0x177)]===_0x5cba7b(0x152))['map'](_0x1c0eff=>_0x1c0eff[_0xc4e1de(0x152)]||'');return _0x4b3679['join']('\x0a')||JSON[_0x5cba7b(0x168)](_0x1219c1);}export function getMCPTools(){const _0x41a29c=_0x2a07,_0x1ebf7d=_0x2a07,_0x231470=[];for(const [_0x59886e,_0x1099a3]of servers){for(const _0x4c8696 of _0x1099a3['tools']){_0x231470[_0x41a29c(0x145)]({'server':_0x59886e,'name':_0x4c8696['name'],'description':_0x4c8696[_0x1ebf7d(0x157)+'n']});}}return _0x231470;}export function getMCPStatus(){const _0x1a6735=_0x2a07,_0x55b803=_0x2a07,_0x45aee5=[];for(const [_0x142fb3,_0x254f61]of servers){_0x45aee5[_0x1a6735(0x145)]({'name':_0x142fb3,'connected':_0x254f61[_0x55b803(0x16f)],'tools':_0x254f61['tools'][_0x1a6735(0x136)]});}return _0x45aee5;}export async function disconnectMCP(){const _0x5d0472=_0x2a07,_0x406265=_0x2a07;for(const [_0x3be3fb,_0x5a559a]of servers){try{_0x5a559a['process']&&_0x5a559a[_0x5d0472(0x13a)]['kill'](),console[_0x406265(0x17f)](_0x5d0472(0x137)+_0x3be3fb+(_0x5d0472(0x13b)+'ted'));}catch(_0x1356b0){console[_0x406265(0x148)](_0x406265(0x137)+_0x3be3fb+(_0x5d0472(0x13b)+_0x5d0472(0x131)),_0x1356b0);}}servers[_0x5d0472(0x150)]();}export function hasMCPConfig(){return _0x535487['existsSync'](MCP_CONFIG);}
|