diff --git a/aiserver.py b/aiserver.py index fc45d373..8116d89a 100644 --- a/aiserver.py +++ b/aiserver.py @@ -258,7 +258,7 @@ app.secret_key = secrets.token_hex() app.config['SESSION_TYPE'] = 'filesystem' app.config['TEMPLATES_AUTO_RELOAD'] = True Session(app) -socketio = SocketIO(app, async_method="eventlet", manage_session=False, cors_allowed_origins='*') +socketio = SocketIO(app, async_method="eventlet", manage_session=False, cors_allowed_origins='*', max_http_buffer_size=10_000_000) #socketio = SocketIO(app, async_method="eventlet", manage_session=False, cors_allowed_origins='*', logger=True, engineio_logger=True) koboldai_vars = koboldai_settings.koboldai_vars(session, socketio) @@ -918,17 +918,17 @@ def loadsettings(): # Load a soft prompt from a file #==================================================================# -def check_for_sp_change(): - while(True): - time.sleep(0.05) - - if(koboldai_vars.sp_changed): - with app.app_context(): - emit('from_server', {'cmd': 'spstatitems', 'data': {koboldai_vars.spfilename: koboldai_vars.spmeta} if koboldai_vars.allowsp and len(koboldai_vars.spfilename) else {}}, namespace=None, broadcast=True, room="UI_1") - koboldai_vars.sp_changed = False +#def check_for_sp_change(): +# while(True): +# time.sleep(0.05) +# +# if(koboldai_vars.sp_changed): +# with app.app_context(): +# emit('from_server', {'cmd': 'spstatitems', 'data': {koboldai_vars.spfilename: koboldai_vars.spmeta} if koboldai_vars.allowsp and len(koboldai_vars.spfilename) else {}}, namespace=None, broadcast=True, room="UI_1") +# koboldai_vars.sp_changed = False -socketio.start_background_task(check_for_sp_change) +#socketio.start_background_task(check_for_sp_change) def spRequest(filename): if(not koboldai_vars.allowsp): @@ -1040,7 +1040,14 @@ def general_startup(override_args=None): args = parser.parse_args(shlex.split(os.environ["KOBOLDAI_ARGS"])) else: args = parser.parse_args() - + + #load system and user settings + for setting in ['user_settings', 'system_settings']: + if os.path.exists("settings/{}.v2_settings".format(setting)): + with open("settings/{}.v2_settings".format(setting), "r") as settings_file: + getattr(koboldai_vars, "_{}".format(setting)).from_json(settings_file.read()) + + temp = [x for x in vars(args)] for arg in temp: if arg == "path": @@ -1132,11 +1139,6 @@ def general_startup(override_args=None): koboldai_settings.queue = multiprocessing.Queue() socketio.start_background_task(socket_io_relay, koboldai_settings.queue, socketio) - #load system and user settings - for setting in ['user_settings', 'system_settings']: - if os.path.exists("settings/{}.v2_settings".format(setting)): - with open("settings/{}.v2_settings".format(setting), "r") as settings_file: - getattr(koboldai_vars, "_{}".format(setting)).from_json(settings_file.read()) #==================================================================# # Load Model @@ -1794,6 +1796,7 @@ def patch_transformers(): if(koboldai_vars.abort or koboldai_vars.generated_tkns >= koboldai_vars.genamt): self.regeneration_required = False self.halt = False + koboldai_vars.abort = False return True if(koboldai_vars.standalone): return False @@ -2873,7 +2876,7 @@ def lua_compute_context(submission, entries, folders, kwargs): ) if koboldai_vars.alt_gen: txt, _, _ = koboldai_vars.calc_ai_text() - print("Using Alt Gen: {}".format(tokenizer.decode(txt))) + print("Using Alt Gen") else: txt, _, _ = calcsubmitbudget( len(actions), @@ -4481,7 +4484,7 @@ def calcsubmit(txt): if(koboldai_vars.model != "InferKit"): if koboldai_vars.alt_gen: subtxt, min, max = koboldai_vars.calc_ai_text(submitted_text=txt) - print("Using Alt Gen: {}".format(tokenizer.decode(subtxt))) + print("Using Alt Gen") else: subtxt, min, max = calcsubmitbudget(actionlen, winfo, mem, anotetxt, koboldai_vars.actions, submission=txt) if(actionlen == 0): @@ -4629,7 +4632,7 @@ def _generate(txt, minimum, maximum, found_entries): found_entries[i].update(_found_entries) if koboldai_vars.alt_gen: txt, _, _ = koboldai_vars.calc_ai_text(submitted_text=txt) - print("Using Alt Gen: {}".format(tokenizer.decode(txt))) + print("Using Alt Gen") else: txt, _, _ = calcsubmitbudget(len(koboldai_vars.actions), winfo, mem, anotetxt, koboldai_vars.actions, submission=txt) encoded.append(torch.tensor(txt, dtype=torch.long, device=genout.device)) @@ -4710,7 +4713,6 @@ def generate(txt, minimum, maximum, found_entries=None): assert type(genout[-1]["generated_text"]) is str else: genout = [{"generated_text": utils.decodenewlines(tokenizer.decode(tokens[-already_generated:]))} for tokens in genout] - print([applyoutputformatting(x["generated_text"]) for x in genout]) if(len(genout) == 1): genresult(genout[0]["generated_text"]) @@ -6771,7 +6773,7 @@ def new_ui_index(): def ui2_connect(): #Send all variables to client koboldai_vars.send_to_ui() - UI_2_load_tweaks() + UI_2_load_cookies() pass #==================================================================# @@ -6787,10 +6789,12 @@ def ui2_serve_themes(path): #==================================================================# @socketio.on('upload_file') def upload_file(data): - print("upload_file {}".format(data['filename'])) + if koboldai_vars.debug: + print("upload_file {}".format(data['filename'])) if 'current_folder' in session: path = os.path.abspath(os.path.join(session['current_folder'], data['filename']).replace("\\", "/")).replace("\\", "/") - print("Want to save to {}".format(path)) + if koboldai_vars.debug: + print("Want to save to {}".format(path)) if 'popup_jailed_dir' not in session: print("Someone is trying to upload a file to your server. Blocked.") elif session['popup_jailed_dir'] is None: @@ -6810,7 +6814,8 @@ def upload_file(data): @socketio.on('popup_change_folder') def popup_change_folder(data): - print("Doing popup change folder: {}".format(data)) + if koboldai_vars.debug: + print("Doing popup change folder: {}".format(data)) if 'popup_jailed_dir' not in session: print("Someone is trying to get at files in your server. Blocked.") return @@ -7099,7 +7104,8 @@ def UI_2_var_change(data): #==================================================================# @socketio.on('save_story') def UI_2_save_story(data): - print("Saving Story") + if koboldai_vars.debug: + print("Saving Story") if data is None: #We need to check to see if there is a file already and if it's not the same story so we can ask the client if this is OK save_name = koboldai_vars.story_name if koboldai_vars.story_name != "" else "untitled" @@ -7138,7 +7144,8 @@ def UI_2_save_to_json(): #==================================================================# @socketio.on('Set Selected Text') def UI_2_Set_Selected_Text(data): - print("Updating Selected Text: {}".format(data)) + if koboldai_vars.quiet: + print("Updating Selected Text: {}".format(data)) koboldai_vars.actions[int(data['id'])] = data['text'] #==================================================================# @@ -7158,16 +7165,17 @@ def UI_2_Use_Option_Text(data): #==================================================================# @socketio.on('submit') def UI_2_submit(data): - print(data) if not koboldai_vars.noai and data['theme'] != "": - print("doing random prompt") + if koboldai_vars.debug: + print("doing random prompt") memory = koboldai_vars.memory koboldai_vars.memory = "{}\n\nYou generate the following {} story concept :".format(koboldai_vars.memory, data['theme']) koboldai_vars.lua_koboldbridge.feedback = None actionsubmit("", force_submit=True, force_prompt_gen=True) koboldai_vars.memory = memory else: - print("doing normal input") + if koboldai_vars.debug: + print("doing normal input") koboldai_vars.actions.clear_unused_options() koboldai_vars.lua_koboldbridge.feedback = None koboldai_vars.recentrng = koboldai_vars.recentrngm = None @@ -7181,9 +7189,9 @@ def UI_2_submit(data): #==================================================================# @socketio.on('abort') def UI_2_abort(data): - print("got abort") + if koboldai_vars.debug: + print("got abort") koboldai_vars.abort = True - print(koboldai_vars.abort) #==================================================================# @@ -7198,7 +7206,8 @@ def UI_2_Pinning(data): #==================================================================# @socketio.on('back') def UI_2_back(data): - print("back") + if koboldai_vars.debug: + print("back") koboldai_vars.actions.clear_unused_options() ignore = koboldai_vars.actions.pop() @@ -7236,7 +7245,6 @@ def UI_2_load_model_button(data): #==================================================================# @socketio.on('select_model') def UI_2_select_model(data): - print(data) #We've selected a menu if data['model'] in model_menu: @@ -7260,7 +7268,6 @@ def UI_2_select_model(data): #==================================================================# @socketio.on('load_model') def UI_2_load_model(data): - print(data) if not os.path.exists("settings/"): os.mkdir("settings") changed = True @@ -7356,7 +7363,8 @@ def story_sort(base_path, desc=False): #==================================================================# @socketio.on('load_story') def UI_2_load_story(file): - print("loading {}".format(file)) + if koboldai_vars.debug: + print("loading {}".format(file)) loadRequest(file) #==================================================================# @@ -7372,7 +7380,6 @@ def UI_2_new_story(data): #==================================================================# @socketio.on('move_wi') def UI_2_move_wi(data): - print(data) if data['folder'] is None: koboldai_vars.worldinfo_v2.reorder(int(data['dragged_id']), int(data['drop_id'])) else: @@ -7383,7 +7390,6 @@ def UI_2_move_wi(data): #==================================================================# @socketio.on('wi_set_folder') def UI_2_wi_set_folder(data): - print(data) koboldai_vars.worldinfo_v2.add_item_to_folder(int(data['dragged_id']), data['folder']) #==================================================================# @@ -7391,8 +7397,9 @@ def UI_2_wi_set_folder(data): #==================================================================# @socketio.on('Rename_World_Info_Folder') def UI_2_Rename_World_Info_Folder(data): - print("Rename_World_Info_Folder") - print(data) + if koboldai_vars.debug: + print("Rename_World_Info_Folder") + print(data) koboldai_vars.worldinfo_v2.rename_folder(data['old_folder'], data['new_folder']) #==================================================================# @@ -7400,8 +7407,9 @@ def UI_2_Rename_World_Info_Folder(data): #==================================================================# @socketio.on('edit_world_info') def UI_2_edit_world_info(data): - print("edit_world_info") - print(data) + if koboldai_vars.debug: + print("edit_world_info") + print(data) if data['uid'] < 0: koboldai_vars.worldinfo_v2.add_item(data['title'], data['key'], @@ -7534,7 +7542,6 @@ def UI_2_update_wi_attribute(data): #==================================================================# @socketio.on('phrase_bias_update') def UI_2_phrase_bias_update(biases): - print(biases) koboldai_vars.biases = biases @@ -7556,7 +7563,8 @@ def socket_io_relay(queue, socketio): # Event triggered when program errors out #==================================================================# def my_except_hook(exctype, value, traceback): - print("sending error to clients") + if koboldai_vars.debug: + print("sending error to clients") socketio.emit("error", "{}: {}".format(exctype, value), broadcast=True, room="UI_2") sys.__excepthook__(exctype, value, traceback) sys.excepthook = my_except_hook @@ -7570,7 +7578,8 @@ def handle_exception(e): return e # now you're handling non-HTTP exceptions only - print("sending error to clients") + if koboldai_vars.debug: + print("sending error to clients") socketio.emit("error", "{}: {}".format(e.message, e.args), broadcast=True, room="UI_2") return render_template("500_generic.html", e=e), 500 @@ -7613,7 +7622,8 @@ def get_softprompt_desc(item_full_path, item, valid_selection): #==================================================================# @socketio.on('load_softprompt') def UI_2_load_softprompt(data): - print("Load softprompt: {}".format(data)) + if koboldai_vars.debug: + print("Load softprompt: {}".format(data)) spRequest(data) #==================================================================# @@ -7629,7 +7639,8 @@ def UI_2_load_userscripts_list(data): column_widths=['200px', '150px', 'auto']) def valid_userscripts_to_load(file): - print("{} is valid: {}".format(file, file.endswith(".lua") and os.path.basename(file) not in koboldai_vars.userscripts)) + if koboldai_vars.debug: + print("{} is valid: {}".format(file, file.endswith(".lua") and os.path.basename(file) not in koboldai_vars.userscripts)) return file.endswith(".lua") and os.path.basename(file) not in koboldai_vars.userscripts def valid_userscripts_to_unload(file): @@ -7680,7 +7691,8 @@ def get_userscripts_desc(item_full_path, item, valid_selection): #==================================================================# @socketio.on('load_userscripts') def UI_2_load_userscripts(data): - print("Loading Userscripts: {}".format(os.path.basename(data))) + if koboldai_vars.debug: + print("Loading Userscripts: {}".format(os.path.basename(data))) koboldai_vars.userscripts = [x for x in koboldai_vars.userscripts if x != os.path.basename(data)]+[os.path.basename(data)] load_lua_scripts() @@ -7689,7 +7701,8 @@ def UI_2_load_userscripts(data): #==================================================================# @socketio.on('unload_userscripts') def UI_2_unload_userscripts(data): - print("Unloading Userscript: {}".format(data)) + if koboldai_vars.debug: + print("Unloading Userscript: {}".format(data)) koboldai_vars.userscripts = [x for x in koboldai_vars.userscripts if x != data] load_lua_scripts() @@ -7700,7 +7713,8 @@ def UI_2_unload_userscripts(data): #==================================================================# @socketio.on('load_aidg_club') def UI_2_load_aidg_club(data): - print("Load aidg.club: {}".format(data)) + if koboldai_vars.debug: + print("Load aidg.club: {}".format(data)) importAidgRequest(data) @@ -7714,7 +7728,8 @@ def UI_2_theme_change(data): for key, value in data['theme'].items(): f.write("\t{}: {};\n".format(key, value.replace(";", "").replace("--", "-"))) f.write("}") - print("Theme Saved") + if koboldai_vars.debug: + print("Theme Saved") #==================================================================# @@ -7735,19 +7750,23 @@ def UI_2_theme_list_refresh(data): #==================================================================# # Save Tweaks #==================================================================# -@socketio.on('save_tweaks') -def UI_2_save_tweaks(data): - with open("./settings/tweaks.settings", "w") as f: - f.write(data) +@socketio.on('save_cookies') +def UI_2_save_cookies(data): + for key in data: + #Note this won't sync to the client automatically as we're modifying a variable rather than setting it + koboldai_vars.cookies[key] = data[key] + with open("./settings/cookies.settings", "w") as f: + json.dump(koboldai_vars.cookies, f) #==================================================================# # Load Tweaks #==================================================================# -def UI_2_load_tweaks(): +def UI_2_load_cookies(): if koboldai_vars.on_colab: - if os.path.exists("./settings/tweaks.settings"): - with open("./settings/tweaks.settings", "r") as f: - socketio.emit('load_tweaks', f.read(), room="UI2") + if os.path.exists("./settings/cookies.settings"): + with open("./settings/cookies.settings", "r") as f: + data = json.load(f) + socketio.emit('load_cookies', data, room="UI_2") #==================================================================# # Test @@ -10549,7 +10568,6 @@ if __name__ == "__main__": print("{0}Webserver has started, you can now connect to this machine at port {1}{2}" .format(colors.GREEN, port, colors.END)) koboldai_vars.serverstarted = True - socketio.run(app, host='0.0.0.0', port=port) else: if args.unblock: diff --git a/koboldai_settings.py b/koboldai_settings.py index abf0c6fb..48e834bb 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -35,7 +35,8 @@ def process_variable_changes(socketio, classname, name, value, old_value, debug_ #If we got a variable change from a thread other than what the app is run it, eventlet seems to block and no further messages are sent. Instead, we'll rely the message to the app and have the main thread send it if not has_request_context(): data = ["var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, {"include_self":True, "broadcast":True, "room":"UI_2"}] - queue.put(data) + if queue is not None: + queue.put(data) else: socketio.emit("var_changed", {"classname": classname, "name": name, "old_value": clean_var_for_emit(old_value), "value": clean_var_for_emit(value)}, include_self=True, broadcast=True, room="UI_2") @@ -317,7 +318,7 @@ class koboldai_vars(object): # return getattr(self._story_settings[self._sessions['story']], name) else: return getattr(self._story_settings['default'], name) - + class settings(object): def to_json(self): @@ -705,7 +706,7 @@ class user_settings(settings): class system_settings(settings): local_only_variables = ['socketio', 'lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'regex_sl', 'acregex_ai', 'acregex_ui', 'comregex_ai', 'comregex_ui', 'sp', '_horde_pid'] - no_save_variables = ['socketio', 'lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', '_horde_pid', 'horde_share'] + no_save_variables = ['socketio', 'lua_state', 'lua_logname', 'lua_koboldbridge', 'lua_kobold', 'lua_koboldcore', 'sp', '_horde_pid', 'horde_share', 'aibusy', 'serverstarted'] settings_name = "system" def __init__(self, socketio): self.socketio = socketio @@ -782,6 +783,7 @@ class system_settings(settings): print("Colab Check: {}".format(self.on_colab)) self.horde_share = False self._horde_pid = None + self.cookies = {} #cookies for colab since colab's URL changes, cookies are lost def __setattr__(self, name, value): @@ -796,9 +798,14 @@ class system_settings(settings): if name not in self.local_only_variables and name[0] != "_" and not new_variable: process_variable_changes(self.socketio, self.__class__.__name__.replace("_settings", ""), name, value, old_value) - if name == "aibusy" and value == False: - koboldai_vars.abort = False - + #if name == "aibusy" and value == False and self.abort == True: + # koboldai_vars.abort = False + + #for original UI + if name == 'sp_changed': + self.socketio.emit('from_server', {'cmd': 'spstatitems', 'data': {self.spfilename: self.spmeta} if self.allowsp and len(self.spfilename) else {}}, namespace=None, broadcast=True, room="UI_1") + super().__setattr__("sp_changed", False) + if name == 'horde_share': if self.on_colab == False: if os.path.exists("./KoboldAI-Horde"): diff --git a/static/koboldai.css b/static/koboldai.css index 23159cb4..0a10a52f 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1403,6 +1403,11 @@ body { height: 0px; } +.statusbar_outer[system_aibusy="false"] { + display: none; + height: 0px; +} + .statusbar_inner { background-color: var(--statusbar_color); color: var(--statusbar_text_color); @@ -1848,7 +1853,8 @@ body { /* Finder */ -#finder-container { +#finder-container, +#debug-file-container { display: flex; justify-content: center; align-items: center; @@ -2009,6 +2015,48 @@ body { width: 99%; height: 100%; cursor: pointer; + +/* 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 ------------------------------------------------*/ diff --git a/static/koboldai.js b/static/koboldai.js index a476dbce..33e229d2 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -25,6 +25,7 @@ socket.on("world_info_folder", function(data){world_info_folder(data);}); socket.on("delete_new_world_info_entry", function(data){document.getElementById("world_info_-1").remove();}); socket.on("delete_world_info_entry", function(data){document.getElementById("world_info_"+data).remove();}); socket.on("error", function(data){show_error_message(data);}); +socket.on('load_cookies', function(data){load_cookies(data)}); socket.on('load_tweaks', function(data){load_tweaks(data);}); socket.on("wi_results", updateWISearchListings); //socket.onAny(function(event_name, data) {console.log({"event": event_name, "class": data.classname, "data": data});}); @@ -44,6 +45,7 @@ var world_info_folder_data = {}; var saved_settings = {}; var finder_selection_index = -1; var on_colab; +var colab_cookies = null; var wi_finder_data = []; var wi_finder_offset = 0; @@ -288,7 +290,7 @@ function do_story_text_updates(data) { story_area.append(span); clearTimeout(game_text_scroll_timeout); - game_text_scroll_timeout = setTimeout(function() {span.scrollIntoView(false);}, 200); + game_text_scroll_timeout = setTimeout(function() {document.getElementById("Selected Text").scrollTop = document.getElementById("Selected Text").scrollHeight;}, 200); if (span.textContent != "") { assign_world_info_to_action(span, null); } @@ -1872,6 +1874,17 @@ function do_wpp(wpp_area) { send_world_info(uid); } +function load_cookies(data) { + colab_cookies = data; + if (document.readyState === 'complete') { + for (const cookie of Object.keys(colab_cookies)) { + setCookie(cookie, colab_cookies[cookie]); + } + process_cookies(); + colab_cookies = null; + } +} + //--------------------------------------------UI to Server Functions---------------------------------- function unload_userscripts() { files_to_unload = document.getElementById('loaded_userscripts'); @@ -2028,17 +2041,13 @@ function save_tweaks() { let path = tweakContainer.getAttribute("tweak-path"); if (toggle.checked) out.push(path); } - - if (on_colab) { - socket.emit("save_tweaks", JSON.stringify(out)); - } else { - setCookie("enabledTweaks", JSON.stringify(out)); - } + setCookie("enabledTweaks", JSON.stringify(out)); } -function load_tweaks(data) { - let enabledTweaks = JSON.parse(data); +function load_tweaks() { + + let enabledTweaks = JSON.parse(getCookie("enabledTweaks", "[]")); for (const tweakContainer of document.getElementsByClassName("tweak-container")) { let toggle = tweakContainer.querySelector("input"); @@ -3096,6 +3105,9 @@ function setCookie(cname, cvalue, exdays=60) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires="+d.toUTCString(); + if (document.getElementById("on_colab").textContent == "true") { + socket.emit("save_cookies", {[cname]: cvalue}); + } document.cookie = cname + "=" + cvalue + ";" + expires + ";"; } @@ -3175,6 +3187,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: {}}; @@ -3648,25 +3789,47 @@ function open_finder() { finderInput.focus(); } +function process_cookies() { + if (getCookie("Settings_Pin") == "false") { + settings_unpin(); + } else if (getCookie("Settings_Pin") == "true") { + settings_pin(); + } + if (getCookie("Story_Pin") == "true") { + story_pin(); + } else if (getCookie("Story_Pin") == "false") { + story_unpin(); + } + if (getCookie("preserve_game_space") == "false") { + preserve_game_space(false); + } else if (getCookie("preserve_game_space") == "true") { + preserve_game_space(true); + } + if (getCookie("options_on_right") == "false") { + options_on_right(false); + } else if (getCookie("options_on_right") == "true") { + options_on_right(true); + } + + load_tweaks(); +} + $(document).ready(function(){ on_colab = document.getElementById("on_colab").textContent == "true"; + if (colab_cookies != null) { + for (const cookie of Object.keys(colab_cookies)) { + setCookie(cookie, colab_cookies[cookie]); + } + colab_cookies = null; + } + create_theming_elements(); document.onkeydown = detect_key_down; document.onkeyup = detect_key_up; document.getElementById("input_text").onkeydown = detect_enter_submit; - if (getCookie("Settings_Pin") == "false") { - settings_unpin(); - } else { - settings_pin(); - } - if (getCookie("Story_Pin") == "true") { - story_pin(); - } else { - story_unpin(); - } - preserve_game_space(!(getCookie("preserve_game_space") == "false")); - options_on_right(!(getCookie("options_on_right") == "false")); + + process_cookies(); // Tweak registering @@ -3807,6 +3970,17 @@ $(document).ready(function(){ if (e.target !== this) return; finderContainer.classList.add("hidden"); }); + + // 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 ec6884c3..8498777e 100644 --- a/templates/index_new.html +++ b/templates/index_new.html @@ -1,6 +1,14 @@ + @@ -80,7 +88,7 @@ document.getElementById("themetext").value = ""; }' onkeyup="calc_token_usage()"> - - + + + + \ 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