blun-king-cli 9.1.13 → 9.1.15
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/blun.mjs +41 -10
- package/package.json +1 -1
package/blun.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// BLUN_BUILD_INPUT_SHA256:
|
|
2
|
+
// BLUN_BUILD_INPUT_SHA256:627be45f029d1b72cb47b404c8a1ddc8a95362573315cdccd84f3da2691cbd97
|
|
3
3
|
import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname as __cjsShimDirname } from 'node:path';
|
|
5
5
|
const __filename = __cjsShimFileURLToPath(import.meta.url);
|
|
@@ -421301,6 +421301,16 @@ var TelegramAccessMenuComponent = class extends Container {
|
|
|
421301
421301
|
};
|
|
421302
421302
|
this.invalidate();
|
|
421303
421303
|
}
|
|
421304
|
+
setTokenSaved() {
|
|
421305
|
+
if (this.done) return;
|
|
421306
|
+
this.replacementToken = void 0;
|
|
421307
|
+
this.tokenConfigured = true;
|
|
421308
|
+
this.tokenInput.setValue("");
|
|
421309
|
+
this.mode = { kind: "menu" };
|
|
421310
|
+
this.notice = void 0;
|
|
421311
|
+
this.rows = this.createRows();
|
|
421312
|
+
this.invalidate();
|
|
421313
|
+
}
|
|
421304
421314
|
render(width) {
|
|
421305
421315
|
const safeWidth = Math.max(1, width);
|
|
421306
421316
|
this.tokenInput.focused = this.focused && this.mode.kind === "token" && !this.done;
|
|
@@ -421392,12 +421402,9 @@ var TelegramAccessMenuComponent = class extends Container {
|
|
|
421392
421402
|
this.invalidate();
|
|
421393
421403
|
return;
|
|
421394
421404
|
}
|
|
421395
|
-
this.
|
|
421396
|
-
this.tokenConfigured = true;
|
|
421397
|
-
this.tokenInput.setValue("");
|
|
421398
|
-
this.mode = { kind: "menu" };
|
|
421405
|
+
this.mode = { kind: "saving" };
|
|
421399
421406
|
this.notice = void 0;
|
|
421400
|
-
this.
|
|
421407
|
+
this.options.onTokenSave(token);
|
|
421401
421408
|
this.invalidate();
|
|
421402
421409
|
}
|
|
421403
421410
|
openTargetEditor(editIndex) {
|
|
@@ -421778,7 +421785,7 @@ function nextAccessDocument(current, targets) {
|
|
|
421778
421785
|
};
|
|
421779
421786
|
}
|
|
421780
421787
|
function envWithToken(current, token) {
|
|
421781
|
-
const lines = (current ?? "").split(/\r?\n/);
|
|
421788
|
+
const lines = (current ?? "").replace(/^\uFEFF/u, "").split(/\r?\n/);
|
|
421782
421789
|
const next = [];
|
|
421783
421790
|
let replaced = false;
|
|
421784
421791
|
for (const line of lines) if (line.startsWith("BLUN_TELEGRAM_BOT_TOKEN=")) {
|
|
@@ -421832,6 +421839,15 @@ function withAccessLock(dir, action) {
|
|
|
421832
421839
|
rmSync(lock, { force: true });
|
|
421833
421840
|
}
|
|
421834
421841
|
}
|
|
421842
|
+
function saveTelegramBotToken(value, dir = telegramStateDir(), env = process.env) {
|
|
421843
|
+
const token = value.trim();
|
|
421844
|
+
if (!isValidTelegramBotToken(token)) throw new TelegramAccessStorageError("invalid-token");
|
|
421845
|
+
withAccessLock(dir, () => {
|
|
421846
|
+
const currentEnvRaw = readOptionalFile(envPath(dir));
|
|
421847
|
+
atomicWritePrivate(envPath(dir), envWithToken(currentEnvRaw, token));
|
|
421848
|
+
env["BLUN_TELEGRAM_BOT_TOKEN"] = token;
|
|
421849
|
+
});
|
|
421850
|
+
}
|
|
421835
421851
|
function saveTelegramAccessConfiguration(draft, dir = telegramStateDir(), env = process.env) {
|
|
421836
421852
|
const token = draft.token?.trim();
|
|
421837
421853
|
if (token !== void 0 && !isValidTelegramBotToken(token)) throw new TelegramAccessStorageError("invalid-token");
|
|
@@ -421883,6 +421899,7 @@ async function verifyTelegramBotToken(token, fetchImpl = globalThis.fetch) {
|
|
|
421883
421899
|
//#region src/tui/commands/telegram-access.ts
|
|
421884
421900
|
const DEFAULT_DEPENDENCIES = {
|
|
421885
421901
|
readConfiguration: () => readTelegramAccessConfiguration(),
|
|
421902
|
+
saveToken: (token) => saveTelegramBotToken(token),
|
|
421886
421903
|
saveConfiguration: (draft) => {
|
|
421887
421904
|
saveTelegramAccessConfiguration(draft);
|
|
421888
421905
|
},
|
|
@@ -421899,6 +421916,9 @@ function handleTelegramAccessCommand(host, dependencies = DEFAULT_DEPENDENCIES)
|
|
|
421899
421916
|
let component;
|
|
421900
421917
|
component = new TelegramAccessMenuComponent({
|
|
421901
421918
|
configuration,
|
|
421919
|
+
onTokenSave: (token) => {
|
|
421920
|
+
verifyAndSaveTelegramToken(component, token, dependencies);
|
|
421921
|
+
},
|
|
421902
421922
|
onSave: (draft) => {
|
|
421903
421923
|
saveAndConnectTelegramAccess(host, component, draft, dependencies);
|
|
421904
421924
|
},
|
|
@@ -421909,6 +421929,19 @@ function handleTelegramAccessCommand(host, dependencies = DEFAULT_DEPENDENCIES)
|
|
|
421909
421929
|
});
|
|
421910
421930
|
host.mountEditorReplacement(component);
|
|
421911
421931
|
}
|
|
421932
|
+
async function verifyAndSaveTelegramToken(component, token, dependencies = DEFAULT_DEPENDENCIES) {
|
|
421933
|
+
if (!await dependencies.verifyToken(token)) {
|
|
421934
|
+
component.setSaveError(uiText("telegramAccess.error.verify"));
|
|
421935
|
+
return;
|
|
421936
|
+
}
|
|
421937
|
+
try {
|
|
421938
|
+
dependencies.saveToken(token);
|
|
421939
|
+
} catch (error) {
|
|
421940
|
+
component.setSaveError(uiText("telegramAccess.error.save", { error: formatErrorMessage$2(error) }));
|
|
421941
|
+
return;
|
|
421942
|
+
}
|
|
421943
|
+
component.setTokenSaved();
|
|
421944
|
+
}
|
|
421912
421945
|
async function saveAndConnectTelegramAccess(host, component, draft, dependencies = DEFAULT_DEPENDENCIES) {
|
|
421913
421946
|
if (draft.token !== void 0 && !await dependencies.verifyToken(draft.token)) {
|
|
421914
421947
|
component.setSaveError(uiText("telegramAccess.error.verify"));
|
|
@@ -501689,9 +501722,7 @@ function contextMetrics(state) {
|
|
|
501689
501722
|
const responder = state.availableModels[responderAlias];
|
|
501690
501723
|
const responderMax = responder === void 0 ? void 0 : effectiveModelAlias(responder).maxContextSize;
|
|
501691
501724
|
const runtimeMax = Number.isFinite(state.maxContextTokens) ? Math.max(0, state.maxContextTokens) : 0;
|
|
501692
|
-
const
|
|
501693
|
-
const compactionBudget = Number.isFinite(state.compactionBudgetTokens) ? Math.max(0, state.compactionBudgetTokens ?? 0) : 0;
|
|
501694
|
-
const maxTokens = compactionBudget > 0 ? compactionBudget : hardMaxTokens;
|
|
501725
|
+
const maxTokens = runtimeMax > 0 ? runtimeMax : responderMax ?? 0;
|
|
501695
501726
|
return {
|
|
501696
501727
|
tokens,
|
|
501697
501728
|
maxTokens,
|