Allow editing of global Worldinfo settings (#4921) * create and export updateWorldInfoSettings * Add WorldInfoSettings type and refactor updateWorldInfoSettings function --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

9a1ded52021229e760e90820293b19344a0ce654

Sammy <sammy@sammcheese.net>

Signed
2 files changed, +43 -0Ignore whitespace
public/global.d.ts+2 -0
@@ -8,6 +8,7 @@ import { FileAttachment } from './scripts/chats';
88import { ReasoningMessageExtra } from './scripts/reasoning';
99import { IGNORE_SYMBOL, OVERSWIPE_BEHAVIOR } from './scripts/constants';
1010import { ToolInvocation } from './scripts/tool-calling';
11+import { getWorldInfoSettings } from './scripts/world-info';
1112
1213declare global {
1314 // Custom types
@@ -16,6 +17,7 @@ declare global {
1617 type ReasoningSettings = typeof power_user.reasoning;
1718 type ChatCompletionSettings = typeof oai_settings;
1819 type TextCompletionSettings = typeof textgenerationwebui_settings;
20+ type WorldInfoSettings = ReturnType<typeof getWorldInfoSettings>;
1921 type MessageTimestamp = string | number | Date;
2022 type Character = import('./scripts/char-data').v1CharData;
2123 type ChatMessageExtra = BaseMessageExtra & Partial<ReasoningMessageExtra> & Record<string, any>;
public/scripts/world-info.js+41 -0
@@ -813,6 +813,47 @@ export function getWorldInfoSettings() {
813813 };
814814}
815815
816+/**
817+ * Updates the world info settings.
818+ * @param {WorldInfoSettings} settings - Settings object
819+ * @param {string[]} [activeWorldInfo] - Optional array of active world info names
820+ */
821+export function updateWorldInfoSettings(settings, activeWorldInfo) {
822+ console.debug('[WI] Updating world info settings', settings, activeWorldInfo);
823+
824+ /** @type {Record<keyof WorldInfoSettings, (value: any) => void>} */
825+ const fields = {
826+ world_info_depth: (value) => world_info_depth = Number(value),
827+ world_info_min_activations: (value) => world_info_min_activations = Number(value),
828+ world_info_min_activations_depth_max: (value) => world_info_min_activations_depth_max = Number(value),
829+ world_info_budget: (value) => world_info_budget = Number(value),
830+ world_info_include_names: (value) => world_info_include_names = Boolean(value),
831+ world_info_recursive: (value) => world_info_recursive = Boolean(value),
832+ world_info_overflow_alert: (value) => world_info_overflow_alert = Boolean(value),
833+ world_info_case_sensitive: (value) => world_info_case_sensitive = Boolean(value),
834+ world_info_match_whole_words: (value) => world_info_match_whole_words = Boolean(value),
835+ world_info_character_strategy: (value) => world_info_character_strategy = Number(value),
836+ world_info_budget_cap: (value) => world_info_budget_cap = Number(value),
837+ world_info_use_group_scoring: (value) => world_info_use_group_scoring = Boolean(value),
838+ world_info_max_recursion_steps: (value) => world_info_max_recursion_steps = Number(value),
839+ // Unused
840+ world_info: (_value) => {},
841+ };
842+
843+ for (const [key, setter] of Object.entries(fields)) {
844+ if (Object.hasOwn(settings, key)) {
845+ setter(settings[key]);
846+ }
847+ }
848+
849+ if (Array.isArray(activeWorldInfo)) {
850+ delete settings.world_info;
851+ selected_world_info = activeWorldInfo;
852+ }
853+
854+ saveSettingsDebounced();
855+}
856+
816857export const world_info_position = {
817858 before: 0,
818859 after: 1,