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 -0Showing whitespace changes
public/global.d.ts+2 -0
@@ -8,6 +8,7 @@ import { FileAttachment } from './scripts/chats';
8import { ReasoningMessageExtra } from './scripts/reasoning';8import { ReasoningMessageExtra } from './scripts/reasoning';
9import { IGNORE_SYMBOL, OVERSWIPE_BEHAVIOR } from './scripts/constants';9import { IGNORE_SYMBOL, OVERSWIPE_BEHAVIOR } from './scripts/constants';
10import { ToolInvocation } from './scripts/tool-calling';10import { ToolInvocation } from './scripts/tool-calling';
11import { getWorldInfoSettings } from './scripts/world-info';
1112
12declare global {13declare global {
13 // Custom types14 // Custom types
@@ -16,6 +17,7 @@ declare global {
16 type ReasoningSettings = typeof power_user.reasoning;17 type ReasoningSettings = typeof power_user.reasoning;
17 type ChatCompletionSettings = typeof oai_settings;18 type ChatCompletionSettings = typeof oai_settings;
18 type TextCompletionSettings = typeof textgenerationwebui_settings;19 type TextCompletionSettings = typeof textgenerationwebui_settings;
20 type WorldInfoSettings = ReturnType<typeof getWorldInfoSettings>;
19 type MessageTimestamp = string | number | Date;21 type MessageTimestamp = string | number | Date;
20 type Character = import('./scripts/char-data').v1CharData;22 type Character = import('./scripts/char-data').v1CharData;
21 type ChatMessageExtra = BaseMessageExtra & Partial<ReasoningMessageExtra> & Record<string, any>;23 type ChatMessageExtra = BaseMessageExtra & Partial<ReasoningMessageExtra> & Record<string, any>;
public/scripts/world-info.js+41 -0
@@ -813,6 +813,47 @@ export function getWorldInfoSettings() {
813 };813 };
814}814}
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 */
821export 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
816export const world_info_position = {857export const world_info_position = {
817 before: 0,858 before: 0,
818 after: 1,859 after: 1,