diff --git a/static/koboldai.css b/static/koboldai.css index 5fda3e58..778699f5 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1853,7 +1853,8 @@ body { /* Finder */ -#finder-container { +#finder-container, +#debug-file-container { display: flex; justify-content: center; align-items: center; @@ -1925,6 +1926,49 @@ body { align-items: center; } +/* Debug File */ +#debug-dump { + opacity: 0.7; + font-size: small; + float: right; +} + +#debug-file-prompt { + width: 25%; + max-height: 500px; + height: 30%; + background-color: var(--flyout_background_pinned); + padding: 10px; + border-radius: 4px; + + display: flex; + flex-direction: column; +} + +#debug-file-prompt > div { + display: flex; + text-align: center; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 10px; + cursor: pointer; +} + +#debug-file-prompt > div > .focus { + font-size: 20px; +} + +#debug-file-prompt > #redacted { + background-color: #407497; + flex-grow: 1; +} + +#debug-file-prompt > #unredacted { + margin-top: 8px; + background-color: rgb(158, 2, 2); +} + /*---------------------------------- Global ------------------------------------------------*/ .hidden { display: none; diff --git a/static/koboldai.js b/static/koboldai.js index 8363a622..cedcb75e 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -3183,6 +3183,135 @@ function beep() { snd.play(); } +function downloadString(string, fileName) { + let a = document.createElement("a"); + a.setAttribute("download", fileName); + a.href = URL.createObjectURL(new Blob([string])); + a.click(); +} + +function getRedactedValue(value) { + if (typeof value === "string") return `[Redacted string with length ${value.length}]`; + if (value instanceof Array) return `[Redacted array with length ${value.length}]`; + + if (typeof value === "object") { + if (value === null) return null; + + let built = {}; + for (const key of Object.keys(value)) { + built[getRedactedValue(key)] = getRedactedValue(value[key]); + } + + return built; + } + + return "[Redacted value]" +} + +async function downloadDebugFile(redact=true) { + let r = await fetch("/vars"); + let varsData = await r.json(); + + // Redact sensitive user info + + // [redacted string n characters long] + // [redacted array with n elements] + + let redactables = [ + "model_settings.apikey", + "model_settings.colaburl", + "model_settings.oaiapikey", + "system_settings.story_loads", + "user_settings.username", + "system_settings.savedir", // Can reveal username + "story_settings.last_story_load", + ]; + + if (redact) { + // TODO: genseqs, splist(?) + redactables = redactables.concat([ + "story_settings.authornote", + "story_settings.chatname", + "story_settings.lastact", + "story_settings.lastctx", + "story_settings.memory", + "story_settings.notes", + "story_settings.prompt", + "story_settings.story_name", + "story_settings.submission", + "story_settings.biases", + "story_settings.genseqs", + + // System + "system_settings.spfilename", + "system_settings.spname", + ]); + + // Redact more complex things + + // wifolders_d - name + for (const key of Object.keys(varsData.story_settings.wifolders_d)) { + varsData.story_settings.wifolders_d[key].name = getRedactedValue(varsData.story_settings.wifolders_d[key].name); + } + + // worldinfo - comment, content, key, keysecondary + for (const key of Object.keys(varsData.story_settings.worldinfo)) { + for (const redactKey of ["comment", "content", "key", "keysecondary"]) { + varsData.story_settings.worldinfo[key][redactKey] = getRedactedValue(varsData.story_settings.worldinfo[key][redactKey]); + } + } + + // worldinfo_i - comment, content, key, keysecondary + for (const key of Object.keys(varsData.story_settings.worldinfo_i)) { + for (const redactKey of ["comment", "content", "key", "keysecondary"]) { + varsData.story_settings.worldinfo_i[key][redactKey] = getRedactedValue(varsData.story_settings.worldinfo_i[key][redactKey]); + } + } + + // worldinfo_u - comment, content, key, keysecondary + for (const key of Object.keys(varsData.story_settings.worldinfo_u)) { + for (const redactKey of ["comment", "content", "key", "keysecondary"]) { + varsData.story_settings.worldinfo_u[key][redactKey] = getRedactedValue(varsData.story_settings.worldinfo_u[key][redactKey]); + } + } + + // worldinfo_v2 entries - comment, content, folder, key, keysecondary, manual_text, title, wpp + for (const key of Object.keys(varsData.story_settings.worldinfo_v2.entries)) { + for (const redactKey of ["comment", "content", "folder", "key", "keysecondary", "manual_text", "title", "wpp"]) { + varsData.story_settings.worldinfo_v2.entries[key][redactKey] = getRedactedValue(varsData.story_settings.worldinfo_v2.entries[key][redactKey]); + } + } + + varsData.story_settings.worldinfo_v2.folders = getRedactedValue(varsData.story_settings.worldinfo_v2.folders); + + // actions - "Selected Text", Options, Probabilities + for (const key of Object.keys(varsData.story_settings.actions.actions)) { + for (const redactKey of ["Selected Text", "Options", "Probabilities"]) { + varsData.story_settings.actions.actions[key][redactKey] = getRedactedValue(varsData.story_settings.actions.actions[key][redactKey]); + } + } + + } + + for (const varPath of redactables) { + let ref = varsData; + const parts = varPath.split("."); + + for (const part of parts.slice(0, -1)) { + ref = ref[part]; + } + + const lastPart = parts[parts.length - 1]; + + ref[lastPart] = getRedactedValue(ref[lastPart]); + } + + debug_info.currentVars = varsData; + console.log(debug_info); + + downloadString(JSON.stringify(debug_info, null, 4), "kobold_debug.json"); +} + function loadNAILorebook(data, filename) { let lorebookVersion = data.lorebookVersion; let wi_data = {folders: {[filename]: []}, entries: {}}; @@ -3575,6 +3704,17 @@ $(document).ready(function(){ finder.addEventListener("click", function(e) { e.stopPropagation(); }); + + // Debug file + // TODO: All of this generic backdrop code really sucks. There should be a + // standardised thing for popups that adds the dimmed backdrop and standard + // closing, etc. + + const debugContainer = document.getElementById("debug-file-container"); + + debugContainer.addEventListener("click", function(e) { + debugContainer.classList.add("hidden"); + }); }); document.addEventListener("keydown", function(event) { diff --git a/templates/index_new.html b/templates/index_new.html index e8f27c4d..8498777e 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -1,6 +1,14 @@ + diff --git a/templates/popups.html b/templates/popups.html index 7b98378a..df7835ce 100644 --- a/templates/popups.html +++ b/templates/popups.html @@ -142,4 +142,21 @@
+ + + + \ No newline at end of file diff --git a/templates/settings flyout.html b/templates/settings flyout.html index d58b0a9a..f76ca472 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -104,6 +104,7 @@
+ Download debug dump