blun-king-cli 9.1.181 → 9.1.183
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/bin/launcher-mode.js +8 -1
- package/bin/launcher-runtime.js +2 -1
- package/bin/telegram-media-delivery-policy.cjs +42 -0
- package/blun.mjs +49 -15
- package/package.json +1 -1
package/bin/launcher-mode.js
CHANGED
|
@@ -27,13 +27,19 @@ function launcherModeFromArgv(argv) {
|
|
|
27
27
|
function createLauncherEnvironment(sourceEnv, mode, publicPackageVersion) {
|
|
28
28
|
return {
|
|
29
29
|
...sourceEnv,
|
|
30
|
-
BLUN_NO_AUTO_UPDATE: '1',
|
|
31
30
|
BLUN_PUBLIC_PACKAGE_VERSION: publicPackageVersion,
|
|
32
31
|
BLUN_TELEGRAM_ATTACH: mode === LAUNCHER_MODES.KING ? 'on' : 'off',
|
|
33
32
|
BLUN_TELEGRAM_HEADLESS: 'off',
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
|
|
36
|
+
function createProtectedCoreEnvironment(sourceEnv) {
|
|
37
|
+
return {
|
|
38
|
+
...sourceEnv,
|
|
39
|
+
BLUN_NO_AUTO_UPDATE: '1',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
function isNpmPackageUpdateRequest(args) {
|
|
38
44
|
if (!Array.isArray(args) || args.length !== 1) return false;
|
|
39
45
|
const command = String(args[0] || '').toLowerCase();
|
|
@@ -47,6 +53,7 @@ function launcherHelpText() {
|
|
|
47
53
|
module.exports = {
|
|
48
54
|
LAUNCHER_MODES,
|
|
49
55
|
createLauncherEnvironment,
|
|
56
|
+
createProtectedCoreEnvironment,
|
|
50
57
|
isNpmPackageUpdateRequest,
|
|
51
58
|
launcherHelpText,
|
|
52
59
|
launcherModeFromArgv,
|
package/bin/launcher-runtime.js
CHANGED
|
@@ -11,6 +11,7 @@ const { spawn } = require('node:child_process');
|
|
|
11
11
|
const {
|
|
12
12
|
LAUNCHER_MODES,
|
|
13
13
|
createLauncherEnvironment,
|
|
14
|
+
createProtectedCoreEnvironment,
|
|
14
15
|
isNpmPackageUpdateRequest,
|
|
15
16
|
launcherHelpText,
|
|
16
17
|
launcherModeFromArgv,
|
|
@@ -179,7 +180,7 @@ function spawnProtectedCore(args, env, cwd, options = {}) {
|
|
|
179
180
|
{
|
|
180
181
|
cwd,
|
|
181
182
|
detached: shouldDetachProtectedCore(),
|
|
182
|
-
env,
|
|
183
|
+
env: createProtectedCoreEnvironment(env),
|
|
183
184
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
184
185
|
windowsHide: true,
|
|
185
186
|
},
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_RETRY_DELAYS_MS = Object.freeze([0, 750, 2_500]);
|
|
4
|
+
|
|
5
|
+
function retryableTelegramMediaFailure(status, description = '') {
|
|
6
|
+
if (!Number.isInteger(status)) return true;
|
|
7
|
+
if ([408, 409, 425, 429].includes(status) || status >= 500) return true;
|
|
8
|
+
return /(?:flood|retry|temporar|timeout|too many requests)/i.test(String(description));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function retryTelegramMediaDelivery(sendAttempt, options = {}) {
|
|
12
|
+
const delays = options.delays ?? DEFAULT_RETRY_DELAYS_MS;
|
|
13
|
+
const wait = options.wait ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
|
|
14
|
+
let lastResult = { ok: false, retryable: true };
|
|
15
|
+
|
|
16
|
+
for (let index = 0; index < delays.length; index += 1) {
|
|
17
|
+
const delay = delays[index];
|
|
18
|
+
if (delay > 0) await wait(delay);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
lastResult = await sendAttempt(index + 1);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
lastResult = {
|
|
24
|
+
ok: false,
|
|
25
|
+
retryable: true,
|
|
26
|
+
description: error instanceof Error ? error.message : String(error),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (lastResult.ok === true || lastResult.retryable !== true) {
|
|
31
|
+
return { ...lastResult, attempts: index + 1 };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { ...lastResult, attempts: delays.length };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
DEFAULT_RETRY_DELAYS_MS,
|
|
40
|
+
retryableTelegramMediaFailure,
|
|
41
|
+
retryTelegramMediaDelivery,
|
|
42
|
+
};
|
package/blun.mjs
CHANGED
|
@@ -513711,6 +513711,8 @@ function outboxDeliveredFile(marker, chatId, filePath) {
|
|
|
513711
513711
|
} catch {}
|
|
513712
513712
|
return false;
|
|
513713
513713
|
}
|
|
513714
|
+
var retryTelegramMediaDelivery, retryableTelegramMediaFailure;
|
|
513715
|
+
({ retryTelegramMediaDelivery, retryableTelegramMediaFailure } = createRequire(import.meta.url)("./bin/telegram-media-delivery-policy.cjs"));
|
|
513714
513716
|
const TELEGRAM_TEXT_LIMIT = 4096;
|
|
513715
513717
|
const TELEGRAM_ATTACHMENT_LIMIT = 50 * 1024 * 1024;
|
|
513716
513718
|
function mediaTelegramTarget(filePath) {
|
|
@@ -513837,29 +513839,61 @@ async function sendMediaReplyFallback(chatId, filePath) {
|
|
|
513837
513839
|
const token = botToken();
|
|
513838
513840
|
if (safePath === void 0 || token === void 0) return false;
|
|
513839
513841
|
const target = mediaTelegramTarget(safePath);
|
|
513840
|
-
const
|
|
513841
|
-
|
|
513842
|
-
|
|
513843
|
-
|
|
513844
|
-
|
|
513845
|
-
method: "POST",
|
|
513846
|
-
body: form
|
|
513847
|
-
})).json();
|
|
513848
|
-
if (payload.ok !== true) return false;
|
|
513842
|
+
const fileBytes = new Uint8Array(readFileSync(safePath));
|
|
513843
|
+
const result = await retryTelegramMediaDelivery(async () => {
|
|
513844
|
+
const form = new FormData();
|
|
513845
|
+
form.append("chat_id", chatId);
|
|
513846
|
+
form.append(target.field, new Blob([fileBytes], { type: target.mimeType }), basename(safePath));
|
|
513849
513847
|
try {
|
|
513850
|
-
|
|
513848
|
+
const response = await fetch(`https://api.telegram.org/bot${token}/${target.method}`, {
|
|
513849
|
+
method: "POST",
|
|
513850
|
+
body: form
|
|
513851
|
+
});
|
|
513852
|
+
const payload = await response.json();
|
|
513853
|
+
const description = typeof payload.description === "string" ? payload.description : "";
|
|
513854
|
+
return {
|
|
513855
|
+
ok: payload.ok === true,
|
|
513856
|
+
retryable: retryableTelegramMediaFailure(response.status, description),
|
|
513857
|
+
status: response.status,
|
|
513858
|
+
description,
|
|
513859
|
+
payload
|
|
513860
|
+
};
|
|
513861
|
+
} catch (error) {
|
|
513862
|
+
return {
|
|
513863
|
+
ok: false,
|
|
513864
|
+
retryable: true,
|
|
513865
|
+
description: formatErrorMessage$2(error)
|
|
513866
|
+
};
|
|
513867
|
+
}
|
|
513868
|
+
});
|
|
513869
|
+
if (result.ok !== true) {
|
|
513870
|
+
try {
|
|
513871
|
+
appendFileSync(join$4(channelDir(), "media-delivery-errors.jsonl"), `${JSON.stringify({
|
|
513851
513872
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
513852
513873
|
direction: "out",
|
|
513853
|
-
kind: "media-reply-fallback",
|
|
513874
|
+
kind: "media-reply-fallback-failed",
|
|
513854
513875
|
chat_id: String(chatId),
|
|
513855
|
-
|
|
513856
|
-
|
|
513876
|
+
file: safePath,
|
|
513877
|
+
attempts: result.attempts,
|
|
513878
|
+
status: result.status,
|
|
513879
|
+
error: result.description
|
|
513857
513880
|
})}\n`);
|
|
513858
513881
|
} catch {}
|
|
513859
|
-
return true;
|
|
513860
|
-
} catch {
|
|
513861
513882
|
return false;
|
|
513862
513883
|
}
|
|
513884
|
+
const payload = result.payload;
|
|
513885
|
+
try {
|
|
513886
|
+
appendFileSync(outboxPath(), `${JSON.stringify({
|
|
513887
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
513888
|
+
direction: "out",
|
|
513889
|
+
kind: "media-reply-fallback",
|
|
513890
|
+
chat_id: String(chatId),
|
|
513891
|
+
message_ids: payload.result?.message_id === void 0 ? [] : [payload.result.message_id],
|
|
513892
|
+
files: [safePath],
|
|
513893
|
+
attempts: result.attempts
|
|
513894
|
+
})}\n`);
|
|
513895
|
+
} catch {}
|
|
513896
|
+
return true;
|
|
513863
513897
|
}
|
|
513864
513898
|
//#endregion
|
|
513865
513899
|
//#region src/tui/utils/dead-terminal.ts
|