beast-agent 0.26.1 → 0.26.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "beast-agent",
3
3
  "productName": "Beast Agent",
4
- "version": "0.26.1",
4
+ "version": "0.26.3",
5
5
  "description": "Ultra-fast local agent shell for Windows.",
6
6
  "author": "algokodcom (AlgoKod)",
7
7
  "license": "MIT",
@@ -20,6 +20,34 @@ const SEND_CHUNK = 1900; // Discord mesaj sınırı 2000 — güvenli pay
20
20
  /* GUILDS(1) | GUILD_MESSAGES(512) | DIRECT_MESSAGES(4096) | MESSAGE_CONTENT(32768) */
21
21
  const INTENTS = 1 | 512 | 4096 | 32768;
22
22
 
23
+ /* AĞ ARA YAZILIMI (antivirüs SSL taraması / proxy / ağ filtresi) Discord
24
+ trafiğine araya girip SELF-SIGNED sertifika sunarsa Node varsayılan olarak
25
+ bağlantıyı reddeder ("self signed certificate") ve bot hiç bağlanamaz.
26
+ Çözüm iki katman:
27
+ 1) REST istekleri ÖNCE Electron/Chromium ağ yığınından (net.fetch) geçer —
28
+ sistem CA + sistem proxy otomatik tanınır (tarayıcının çalıştığı yol).
29
+ 2) Zorlanırsa Node https'e düşülür; self-signed tespit edilirse bu köprü
30
+ için TLS doğrulaması esnetilir — YALNIZ Discord bağlantıları etkilenir. */
31
+ let tlsRelaxed = false;
32
+ const CERT_ERR_RE = /self[ -]?signed|unable to verify the first certificate|depth zero|err_tls|certificate has expired|cert_has_expired|unable_to_get_issuer|self signed certificate/i;
33
+
34
+ function isCertError(e) {
35
+ return CERT_ERR_RE.test(String((e && (e.message || e.code)) || e || ''));
36
+ }
37
+
38
+ /* Electron main process'te Chromium ağ yığını (sistem CA + proxy); düz Node
39
+ (testler) için require('electron') path string döndürür → net tanımsız kalır */
40
+ let _electronNet = null;
41
+ try {
42
+ const el = require('electron');
43
+ if (el && el.net && typeof el.net.fetch === 'function') _electronNet = el.net;
44
+ } catch {}
45
+
46
+ function bodySnippet(data) {
47
+ const s = String(data || '').replace(/\s+/g, ' ').trim();
48
+ return s ? ` — gövde: ${s.slice(0, 140)}` : '';
49
+ }
50
+
23
51
  class DiscordBridge {
24
52
  constructor({ token, emit, onIncoming }) {
25
53
  this.token = String(token || '').trim();
@@ -41,33 +69,75 @@ class DiscordBridge {
41
69
  this.emit({ type: 'status', status, user: user || null });
42
70
  }
43
71
 
44
- /* REST çağrısı — JSON (token: "Bot <token>") */
45
- api(method, path, body) {
72
+ /* REST çağrısı — JSON (token: "Bot <token>").
73
+ Yol 1: Chromium (net.fetch sistem CA/proxy). Yol 2: Node https (+esnek TLS). */
74
+ api(method, path, body, attempt = 0) {
75
+ return this._api(method, path, body).catch((e) => {
76
+ if (isCertError(e) && !tlsRelaxed) {
77
+ tlsRelaxed = true;
78
+ this.emit({
79
+ type: 'warn',
80
+ text: 'ağ ara yazılımı (antivirüs/proxy) self-signed sertifikası tespit edildi — Discord bağlantısı esnek TLS ile devam ediyor',
81
+ });
82
+ if (attempt < 1) return this.api(method, path, body, attempt + 1);
83
+ }
84
+ throw e;
85
+ });
86
+ }
87
+
88
+ async _api(method, path, body) {
89
+ const payload = body ? JSON.stringify(body) : null;
90
+ const headers = { 'Content-Type': 'application/json', Authorization: 'Bot ' + this.token };
91
+ const url = API_BASE + path;
92
+
93
+ /* YOL 1 — Chromium ağ yığını (varsa): sistem sertifikaları + sistem proxy */
94
+ if (_electronNet) {
95
+ try {
96
+ const res = await _electronNet.fetch(url, {
97
+ method,
98
+ headers,
99
+ ...(payload ? { body: payload } : {}),
100
+ });
101
+ const data = await res.text();
102
+ let j = null;
103
+ try { j = data ? JSON.parse(data) : null; } catch {}
104
+ if (res.ok) return j;
105
+ throw new Error(
106
+ `discord ${path}: HTTP ${res.status}${j && j.message ? ' ' + j.message : ''}${bodySnippet(data)}`
107
+ );
108
+ } catch (e) {
109
+ /* kendi formatladığımız API hatasıysa yukarı taşı; transport hatasıysa
110
+ Node https yoluna düş (orada esnek TLS şansı var) */
111
+ if (/^discord /.test(String((e && e.message) || ''))) throw e;
112
+ }
113
+ }
114
+
115
+ /* YOL 2 — Node https (+ gerektiğinde esnek TLS) */
46
116
  return new Promise((resolve, reject) => {
47
- const payload = body ? JSON.stringify(body) : null;
48
117
  const req = https.request(
49
- `${API_BASE}${path}`,
118
+ url,
50
119
  {
51
120
  method,
52
121
  headers: {
53
- 'Content-Type': 'application/json',
54
- Authorization: 'Bot ' + this.token,
122
+ ...headers,
55
123
  ...(payload ? { 'Content-Length': Buffer.byteLength(payload) } : {}),
56
124
  },
57
125
  timeout: 15000,
126
+ rejectUnauthorized: !tlsRelaxed,
58
127
  },
59
128
  (res) => {
60
129
  let data = '';
61
130
  res.setEncoding('utf8');
62
131
  res.on('data', (c) => (data += c));
63
132
  res.on('end', () => {
64
- try {
65
- const j = data ? JSON.parse(data) : null;
66
- if (res.statusCode >= 200 && res.statusCode < 300) resolve(j);
67
- else reject(new Error(`discord ${path}: HTTP ${res.statusCode} ${(j && j.message) || ''}`.trim()));
68
- } catch {
69
- reject(new Error(`discord ${path}: bozuk yanıt`));
133
+ const ctype = String(res.headers['content-type'] || '');
134
+ let j = null;
135
+ try { j = data ? JSON.parse(data) : null; } catch {}
136
+ if (res.statusCode >= 200 && res.statusCode < 300 && j !== null) return resolve(j);
137
+ if (res.statusCode >= 200 && res.statusCode < 300) {
138
+ return reject(new Error(`discord ${path}: bozuk yanıt (HTTP ${res.statusCode}${ctype ? ', ' + ctype : ''})${bodySnippet(data)}`));
70
139
  }
140
+ reject(new Error(`discord ${path}: HTTP ${res.statusCode} ${(j && j.message) || ''}`.trim() + bodySnippet(data)));
71
141
  });
72
142
  }
73
143
  );
@@ -102,7 +172,7 @@ class DiscordBridge {
102
172
  clearInterval(this._hbTimer);
103
173
  this._hbTimer = null;
104
174
  let identified = false;
105
- const ws = new WebSocket(GATEWAY_URL);
175
+ const ws = new WebSocket(GATEWAY_URL, { rejectUnauthorized: !tlsRelaxed });
106
176
  this._ws = ws;
107
177
 
108
178
  ws.on('message', (raw) => {
@@ -193,8 +263,16 @@ class DiscordBridge {
193
263
  setTimeout(() => this._connect(), wait);
194
264
  });
195
265
 
196
- ws.on('error', () => {
197
- /* close tetikleniryeniden bağlanma orada */
266
+ ws.on('error', (e) => {
267
+ /* gateway TLS'i de ara yazılımdan etkilenebilir esnet ve close sonrası
268
+ yeniden bağlanma zaten relaxed ile kurar */
269
+ if (isCertError(e) && !tlsRelaxed) {
270
+ tlsRelaxed = true;
271
+ this.emit({
272
+ type: 'warn',
273
+ text: 'ağ ara yazılımı (antivirüs/proxy) self-signed sertifikası tespit edildi — Discord bağlantısı esnek TLS ile devam ediyor',
274
+ });
275
+ }
198
276
  });
199
277
  }
200
278
 
package/src/main.js CHANGED
@@ -2240,6 +2240,7 @@ function ensureDc() {
2240
2240
  token: settings.dcToken || '',
2241
2241
  emit: (ev) => {
2242
2242
  if (ev.type === 'status') dcLog(`status=${ev.status}${ev.user ? ' user=' + ev.user : ''}`);
2243
+ if (ev.type === 'warn') dcLog('⚠ ' + String(ev.text || ''));
2243
2244
  if (win && !win.isDestroyed()) win.webContents.send('dc:event', ev);
2244
2245
  },
2245
2246
  onIncoming: handleDcIncoming,