blun-king-cli 9.1.14 → 9.1.16
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 +56 -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:39e4b4359446de9a47446e631b853adaafc78c8097e76296c6826ec91ee9902d
|
|
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);
|
|
@@ -397833,7 +397833,6 @@ function slashBusyMessage(commandName, reason) {
|
|
|
397833
397833
|
}
|
|
397834
397834
|
//#endregion
|
|
397835
397835
|
//#region src/tui/commands/plugin-commands.ts
|
|
397836
|
-
const REMOVED_PLUGIN_COMMANDS = new Set(["telegram:access"]);
|
|
397837
397836
|
function pluginCommandName(pluginId, name) {
|
|
397838
397837
|
return `${pluginId}:${name}`;
|
|
397839
397838
|
}
|
|
@@ -397842,7 +397841,6 @@ function buildPluginSlashCommands(defs) {
|
|
|
397842
397841
|
const commands = [];
|
|
397843
397842
|
for (const def of defs) {
|
|
397844
397843
|
const commandName = pluginCommandName(def.pluginId, def.name);
|
|
397845
|
-
if (REMOVED_PLUGIN_COMMANDS.has(commandName)) continue;
|
|
397846
397844
|
commandMap.set(commandName, def.body);
|
|
397847
397845
|
commands.push({
|
|
397848
397846
|
name: commandName,
|
|
@@ -421301,6 +421299,16 @@ var TelegramAccessMenuComponent = class extends Container {
|
|
|
421301
421299
|
};
|
|
421302
421300
|
this.invalidate();
|
|
421303
421301
|
}
|
|
421302
|
+
setTokenSaved() {
|
|
421303
|
+
if (this.done) return;
|
|
421304
|
+
this.replacementToken = void 0;
|
|
421305
|
+
this.tokenConfigured = true;
|
|
421306
|
+
this.tokenInput.setValue("");
|
|
421307
|
+
this.mode = { kind: "menu" };
|
|
421308
|
+
this.notice = void 0;
|
|
421309
|
+
this.rows = this.createRows();
|
|
421310
|
+
this.invalidate();
|
|
421311
|
+
}
|
|
421304
421312
|
render(width) {
|
|
421305
421313
|
const safeWidth = Math.max(1, width);
|
|
421306
421314
|
this.tokenInput.focused = this.focused && this.mode.kind === "token" && !this.done;
|
|
@@ -421392,12 +421400,9 @@ var TelegramAccessMenuComponent = class extends Container {
|
|
|
421392
421400
|
this.invalidate();
|
|
421393
421401
|
return;
|
|
421394
421402
|
}
|
|
421395
|
-
this.
|
|
421396
|
-
this.tokenConfigured = true;
|
|
421397
|
-
this.tokenInput.setValue("");
|
|
421398
|
-
this.mode = { kind: "menu" };
|
|
421403
|
+
this.mode = { kind: "saving" };
|
|
421399
421404
|
this.notice = void 0;
|
|
421400
|
-
this.
|
|
421405
|
+
this.options.onTokenSave(token);
|
|
421401
421406
|
this.invalidate();
|
|
421402
421407
|
}
|
|
421403
421408
|
openTargetEditor(editIndex) {
|
|
@@ -421778,7 +421783,7 @@ function nextAccessDocument(current, targets) {
|
|
|
421778
421783
|
};
|
|
421779
421784
|
}
|
|
421780
421785
|
function envWithToken(current, token) {
|
|
421781
|
-
const lines = (current ?? "").split(/\r?\n/);
|
|
421786
|
+
const lines = (current ?? "").replace(/^\uFEFF/u, "").split(/\r?\n/);
|
|
421782
421787
|
const next = [];
|
|
421783
421788
|
let replaced = false;
|
|
421784
421789
|
for (const line of lines) if (line.startsWith("BLUN_TELEGRAM_BOT_TOKEN=")) {
|
|
@@ -421832,6 +421837,15 @@ function withAccessLock(dir, action) {
|
|
|
421832
421837
|
rmSync(lock, { force: true });
|
|
421833
421838
|
}
|
|
421834
421839
|
}
|
|
421840
|
+
function saveTelegramBotToken(value, dir = telegramStateDir(), env = process.env) {
|
|
421841
|
+
const token = value.trim();
|
|
421842
|
+
if (!isValidTelegramBotToken(token)) throw new TelegramAccessStorageError("invalid-token");
|
|
421843
|
+
withAccessLock(dir, () => {
|
|
421844
|
+
const currentEnvRaw = readOptionalFile(envPath(dir));
|
|
421845
|
+
atomicWritePrivate(envPath(dir), envWithToken(currentEnvRaw, token));
|
|
421846
|
+
env["BLUN_TELEGRAM_BOT_TOKEN"] = token;
|
|
421847
|
+
});
|
|
421848
|
+
}
|
|
421835
421849
|
function saveTelegramAccessConfiguration(draft, dir = telegramStateDir(), env = process.env) {
|
|
421836
421850
|
const token = draft.token?.trim();
|
|
421837
421851
|
if (token !== void 0 && !isValidTelegramBotToken(token)) throw new TelegramAccessStorageError("invalid-token");
|
|
@@ -421883,6 +421897,7 @@ async function verifyTelegramBotToken(token, fetchImpl = globalThis.fetch) {
|
|
|
421883
421897
|
//#region src/tui/commands/telegram-access.ts
|
|
421884
421898
|
const DEFAULT_DEPENDENCIES = {
|
|
421885
421899
|
readConfiguration: () => readTelegramAccessConfiguration(),
|
|
421900
|
+
saveToken: (token) => saveTelegramBotToken(token),
|
|
421886
421901
|
saveConfiguration: (draft) => {
|
|
421887
421902
|
saveTelegramAccessConfiguration(draft);
|
|
421888
421903
|
},
|
|
@@ -421899,6 +421914,9 @@ function handleTelegramAccessCommand(host, dependencies = DEFAULT_DEPENDENCIES)
|
|
|
421899
421914
|
let component;
|
|
421900
421915
|
component = new TelegramAccessMenuComponent({
|
|
421901
421916
|
configuration,
|
|
421917
|
+
onTokenSave: (token) => {
|
|
421918
|
+
verifyAndSaveTelegramToken(component, token, dependencies);
|
|
421919
|
+
},
|
|
421902
421920
|
onSave: (draft) => {
|
|
421903
421921
|
saveAndConnectTelegramAccess(host, component, draft, dependencies);
|
|
421904
421922
|
},
|
|
@@ -421909,6 +421927,19 @@ function handleTelegramAccessCommand(host, dependencies = DEFAULT_DEPENDENCIES)
|
|
|
421909
421927
|
});
|
|
421910
421928
|
host.mountEditorReplacement(component);
|
|
421911
421929
|
}
|
|
421930
|
+
async function verifyAndSaveTelegramToken(component, token, dependencies = DEFAULT_DEPENDENCIES) {
|
|
421931
|
+
if (!await dependencies.verifyToken(token)) {
|
|
421932
|
+
component.setSaveError(uiText("telegramAccess.error.verify"));
|
|
421933
|
+
return;
|
|
421934
|
+
}
|
|
421935
|
+
try {
|
|
421936
|
+
dependencies.saveToken(token);
|
|
421937
|
+
} catch (error) {
|
|
421938
|
+
component.setSaveError(uiText("telegramAccess.error.save", { error: formatErrorMessage$2(error) }));
|
|
421939
|
+
return;
|
|
421940
|
+
}
|
|
421941
|
+
component.setTokenSaved();
|
|
421942
|
+
}
|
|
421912
421943
|
async function saveAndConnectTelegramAccess(host, component, draft, dependencies = DEFAULT_DEPENDENCIES) {
|
|
421913
421944
|
if (draft.token !== void 0 && !await dependencies.verifyToken(draft.token)) {
|
|
421914
421945
|
component.setSaveError(uiText("telegramAccess.error.verify"));
|
|
@@ -424681,10 +424712,25 @@ const INTERNAL_TAG_PREFIXES = [
|
|
|
424681
424712
|
"<|dsml|",
|
|
424682
424713
|
"</|dsml|"
|
|
424683
424714
|
];
|
|
424715
|
+
const RUNTIME_INSTRUCTION_OPEN = "Bevor du antwortest:";
|
|
424716
|
+
const RUNTIME_INSTRUCTION_CLOSE = "Die einzige Ausnahme: eine Zahl, die der Nutzer selbst in seiner Nachricht genannt hat - die darfst du uebernehmen und weiterverwenden.";
|
|
424684
424717
|
/** Remove model-only envelopes before assistant text reaches a transcript renderer. */
|
|
424685
424718
|
function sanitizeAssistantDisplayText(text, options = {}) {
|
|
424686
424719
|
const transient = options.transient === true;
|
|
424687
|
-
return stripIncompleteInternalSuffix(stripControlTokens(stripDsmlBlocks(stripSystemReminderBlocks(text, transient))), transient);
|
|
424720
|
+
return stripIncompleteInternalSuffix(stripControlTokens(stripDsmlBlocks(stripSystemReminderBlocks(stripEchoedRuntimeInstructions(text), transient))), transient);
|
|
424721
|
+
}
|
|
424722
|
+
function stripEchoedRuntimeInstructions(text) {
|
|
424723
|
+
let cursor = 0;
|
|
424724
|
+
let output = "";
|
|
424725
|
+
while (cursor < text.length) {
|
|
424726
|
+
const open = text.indexOf(RUNTIME_INSTRUCTION_OPEN, cursor);
|
|
424727
|
+
if (open < 0) break;
|
|
424728
|
+
output += text.slice(cursor, open);
|
|
424729
|
+
const close = text.indexOf(RUNTIME_INSTRUCTION_CLOSE, open + 20);
|
|
424730
|
+
if (close < 0) return output;
|
|
424731
|
+
cursor = close + 135;
|
|
424732
|
+
}
|
|
424733
|
+
return output + text.slice(cursor);
|
|
424688
424734
|
}
|
|
424689
424735
|
function stripSystemReminderBlocks(text, transient) {
|
|
424690
424736
|
let cursor = 0;
|