Commit Graph

460 Commits

Author SHA1 Message Date
Cohee 357da3219b Chore: Add code formatting conventions as eslint rules (#5158)
* Add code formatting conventions as eslint rules

* Improve formatting in addQuickReply
2026-02-15 01:16:34 +02:00
Wolfsblvt 34688f8493 chore(wi): Add logSlashCommandWarn utility and integrate into world-info slash commands (#5096) 2026-02-05 01:04:14 +02:00
Wolfsblvt 9ff9d59672 Macros 2.0 (v0.7.1) - Macro Autocomplete everywhere (#5019)
* Add macro autocomplete for free text inputs

Implements macro autocomplete (`{{`) for textareas and input fields marked with `data-macros` attribute. Extracts shared autocomplete logic into MacroAutoCompleteHelper.js for consistency between slash command and free text contexts. Includes MutationObserver for dynamic element initialization and supports variable shorthands, operators, flags, and scoped macro closing tags.

* fix annoying circular dependency again

* Add `data-macros` attribute to enable macro autocomplete on text inputs

Enables macro autocomplete (`{{`) for various textareas and input fields throughout the UI by adding the `data-macros` attribute. Includes context template fields, instruct mode sequences, character/persona descriptions, world info content, and other prompt-related inputs. Also ensures the attribute is preserved when expanding editors and creating world info entries.

* Allow macro autocomplete in editing messages

Enables macro autocomplete (`{{`) when editing messages by adding the `data-macros` attribute to the dynamically created edit textarea element.

* Add autocomplete visibility setting support for macro autocomplete

Respects the global STScript autocomplete visibility setting (`power_user.stscript.autocomplete.state`) for macro autocomplete in free text inputs. When set to "Input length > 1", macro autocomplete only activates after typing `{{` plus at least 2 characters. Also adds a tooltip to the visibility setting explaining it applies to both slash commands and macros.

* Fix unclosed div tag in STScript autocomplete visibility setting

Closes the `<div>` tag that was incorrectly left open in the autocomplete visibility setting markup.

* Add setting to control macro autocomplete visibility in non-expanded fields

Introduces a new `showInAllMacroFields` setting that controls whether macro autocomplete appears in all macro-enabled fields or only in expanded editors and when pressing Ctrl+Space. Also adds `data-macros-autocomplete` attribute support with `always` and `hide` modes for per-field override. When the setting is off, autocomplete only shows in expanded editors (which now get `data-macros-autocomplete="always"`) and the completion

* Add `data-macros-autocomplete-style` attribute to control macro autocomplete popup size

Introduces a new `data-macros-autocomplete-style` attribute with `small` (33vw, max 700px) and `expanded` (default chat width) modes to control macro autocomplete popup dimensions. The `small` style is now the default for inline fields, while `expanded` is used for expanded editors and prompt manager. Also refactors `getAutocompleteMode` to return `DEFAULT` instead of `null` and adds corresponding `getAutocompleteStyle` helper

* Fix autocomplete details panel alignment when list is constrained by viewport edge

Adjusts the details panel position to align with the actual autocomplete list position when the list is constrained by the right edge of the viewport. Previously, the panel would position based on cursor location even when the list was pushed left, causing misalignment. Now checks if the list's actual position differs from the calculated position (with 5px tolerance) and uses the list's position instead.

* Guard autocomplete details panel alignment check with `isReplaceable` condition

Prevents attempting to read the autocomplete list's bounding rect when the list is not visible. The alignment adjustment for viewport-constrained lists now only runs when `isReplaceable` is true, avoiding potential errors when the list DOM is not rendered.

* Fix macro autocomplete cursor detection to handle nested macros correctly

Updates `findMacroAtCursor` to track nesting depth when searching for opening `{{` and closing `}}` braces. Previously would incorrectly stop at the first brace pair encountered in either direction, breaking autocomplete when cursor was inside nested macros like `{{getvar::{{getvar::name}}}}`. Now properly skips over nested macro boundaries by incrementing/decrementing depth counters until finding the matching braces at depth

* gief me my comments back (and fixes, that were missed)

- Added detailed JSDoc comments to all exported functions explaining parameters, return types, and behavior
- Added inline comments throughout functions explaining logic flow, edge cases, and implementation details
- Documented parser-based vs regex-based unclosed scope detection approaches
- Clarified variable shorthand autocomplete logic including operator filtering, context display, and priority

* refactor(macros): freeze MACRO_AUTOCOMPLETE_MODE and MACRO_AUTOCOMPLETE_STYLE enums

* feat(macros): explicitly set `makeSelectable` flag for non-insertable autocomplete options

- Set `makeSelectable = true` for variable shorthand options in {{if}} conditions (already insertable)
- Set `makeSelectable = false` for already-typed operators in variable shorthand autocomplete
- Set `makeSelectable = false` for already-typed flags in macro autocomplete
- Set `makeSelectable = false` for non-selectable closing block flags when no unclosed scopes exist
- Set `makeSelectable = false` for sc

* refactor(macros): consolidate typedef imports in MacroAutoCompleteHelper

- Fixed typo in MacroDefinition typedef import (removed extra `/` from JSDoc comment)
- Replaced long-form typedef imports with short-form aliases for MacroAutoCompleteContext and MacroDefinition
- Improved code consistency by using imported typedefs throughout function signatures

* refactor(autocomplete): select first selectable item as default instead of always first item

- Extracted default item selection logic into `selectDefaultItem()` method
- Changed default selection to prioritize first selectable item over first item in list
- Falls back to last item when no selectable items exist (preserves context for info-only options)
- Added JSDoc documentation explaining selection behavior

* feat(macros): make already-typed variable names non-selectable in autocomplete

- Set `makeSelectable = false` for variable name options that match the currently typed name
- Set empty `valueProvider` for matched variables to prevent re-insertion
- Prevents redundant selection of variables that are already fully typed in the input

* feat(macros): add value context autocomplete option for variable shorthand operators

- Created `VariableValueContextAutoCompleteOption` class to display context about expected values
- Shows operator name, symbol, and description when typing variable shorthand values
- Displays currently typed value and completion hint
- Non-selectable option (context only) with priority 4
- Added to variable shorthand autocomplete when operator is typed and value is being entered

* fix lint

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-23 23:46:47 +02:00
Wolfsblvt 858b9e684e Enhance world duplication to use current world name as base (#4990)
- Update `getFreeWorldName()` to accept optional `worldName` parameter and `stripIndex` option
- Add JSDoc documentation for `getFreeWorldName()` parameters and return value
- Modify world duplicate handler to pass current world name to `getFreeWorldName()`
- Strip existing numbered suffix from base name before generating new numbered name
- Default to "New World" when no world name is provided
- Make "New World" translatable
2026-01-11 00:01:16 +02:00
DeclineThyself 8372e7bf9d "gradually replacing property access with a dot operator" (#4965)
* "gradually replacing property access with a dot operator"
https://github.com/SillyTavern/SillyTavern/pull/4963#discussion_r2663003561

(?<=\w|\])\['([a-zA-Z]\w+)'\]
My regex found 593 matches across 47 files.
Also, two typos.

* Fixed chat[0].chat_metadata type error.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664275854

* Fixed `swipedElementsDiv[0]?.getAnimations().filter((a) => a.animationName` type error.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664274593

* Fixed config.MESSAGE_SANITIZE and config.MESSAGE_ALLOW_SYSTEM_UI type errors.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664266271

* Fixed group.date_last_chat type error.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664295652

* Reverted SlashCommandParser dot property access.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664310931

* LLM fixed canUseNegativeLookbehind.result; type error.
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664314288

* Reverted chat-completions.js bodyParams and headers dot property access.

https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664317848
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664320088
https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664324438

* Reverted openai.js data dot property access.

https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664326244

* Reverted tests/frontend/MacroEnvBuilder.e2e.js env.dynamicMacros dot property access.

https://github.com/SillyTavern/SillyTavern/pull/4965#discussion_r2664330990

* Partially reverted `window` dot property access.

* Reverted result.json() and settings dot property access.

* Reverted google.js headers dot property access.

* Fixed regex: `(?<=\w|\])\['([a-zA-Z]\w*)'\]`

* Swapped window to globalThis with dot property access.

* LLM fixed canUseNegativeLookbehind type.

* Refactor property access

* Consistency

---------

Co-authored-by: user <user@exmaple.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-08 23:58:21 +02:00
Sammy 9a1ded5202 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>
2025-12-27 20:08:29 +02:00
Wolfsblvt a11abc4273 Add new WORLDINFO_SCAN_DONE event with mutable state for extensions (#4797)
* chore: Add WORLDINFO_SCAN_DONE event with mutable state for extensions

* Fix incorrect scan state reference in world info recursion logic

* Fix typo in world info scan state property name: 'sucessful' → 'successful'

(am i stupid)
2025-11-23 15:59:49 +02:00
DeclineThyself 2df8e52d48 If the world-info has no comment, show it's keys in the placeholder. (#4681)
* Show keys in commentInput's placeholder.

* Fixed.
https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450822592
https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450827302
https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450834282
https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450844011

* Update comment backfill logic

* Don't update placeholder with secondary keys

* Fix MAX_COMMENT_LENGTH to enforce a limit of 100 characters

---------

Co-authored-by: user <user@exmaple.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-10-23 22:10:08 +03:00
Wolfsblvt a65f708fd8 Allow create new world books via /getpersonabook and /getcharbook (#4597)
* feat: allow create new world books via /getpersonabook and /getcharbook

Refactor character world info management into dedicated functions

Extract character world assignment logic from UI handlers into reusable functions
Add support for automatic lorebook creation in slash commands
Improve code maintainability by centralizing world info operations

* refactor: update boolean enum provider from onOffToggle to trueFalse in world info commands

* fix: improve world info name uniqueness check using getUniqueName utility

* Unset current persona WI on file deletion

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-10-05 16:41:54 +03:00
Wolfsblvt 7cba4e88ab Add new WI position 'outlet' to expose WI entries triggered to be placed as macros literally anywhere (#4523)
* feat: add outlet prompt support for world info entries

* feat: add outlet name field with autocomplete for world info entries

* feat: add outlet entries for world info support to WI parsing

* feat: add tooltip and validation for WI outlet name entries

* Trim macro outlet name

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* refactor: consolidate WI injection cleanup and fix strict equality comparison

* fix: update outlet macro regex pattern to use double colon delimiter

* fix: replace carriage returns with newlines in WI entry outlet tooltip

* fix: add null checks and array validation for WI outlet entries handling

* feat: add outletName field to world info entry definition schema (supports /setwientryfield command)

* fix: add outletName field to export of character lore books

* do not remove outlet name on position change, but filter out for auto complete

* Match WI extensions field name

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

* outlet name being used in char WI import too

* docs: add outlet macro documentation to help template

* be explicit about risu/novel/agnai wi not supporting outlets

* Inject A/N and TC sysprompt after populating outlets

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-09-18 21:12:14 +03:00
Yokayo e9e14001e3 Update ru-ru locale (#4449)
* Work on tl

* Small fix

* Fix formatting

---------

Co-authored-by: Yokayo <nonameutubecomm@gmail.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-08-26 20:37:55 +03:00
Cohee 76326344b0 Deep clone of duplicate WI entry
Fixes #4438
2025-08-24 20:13:18 +03:00
Anh Tri Pham 35b1801e6e feat(client): desktop version uses select2 to search, filter, and select (#4359)
* Update UpdateAndStart.bat

* feat(client): desktop version uses select2 to search, filter, and select world info to edit

feat(client): styles for select2 to separate items and highlight

* fix(client): more aligned with current select2

fix(client): removed unecessary functions and styles

* Update WI editor layout

* Add min-width for WI sort and search

* Adjust control styling

* Update option creation logic

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-08-10 14:39:25 +03:00
kallewoof c8612e2ab6 feature: ignore budget switch (#4354)
* feature: ignore budget switch

The budget cap default at 25% is a big gotcha at the start of chats, as a person may assume that a constant lore book entry will always be present, no matter what. This pull request adds a budget ignore switch which ignores the budget cap and includes the lore book entry even if it would exceed the budget cap.

* Move the toggle to entry details

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-08-06 21:30:42 +03:00
Cohee f81e14a2e8 Add copy option to move WI entry (#4335)
* Add copy option to move WI entry
Closes #4334

* Update moveWorldInfoEntry log to indicate copy or move action
2025-08-02 19:45:51 +03:00
zonde306 53d96deaff WORLDINFO_SORTING changed to WORLDINFO_ENTRIES_LOADED 2025-07-25 04:09:33 +08:00
zonde306 ac759e5b7e Allows control of Lore books entries by extensions 2025-07-25 03:36:01 +08:00
Cohee 4177c829d1 Add default global scan data for checkWorldInfo 2025-07-21 01:58:26 +03:00
Cohee c292f64163 Add generation type triggers to world info (#4286)
* Add generation type triggers to world info

* Simplify includes check

* Refactor getEntryField validation and default value handling

* Remove invalid attribute

* Check for a valid trigger
2025-07-20 00:22:54 +03:00
Cohee 96bdc13937 Replace ajax with fetch (#4241)
* Replace ajax with fetch
Fix type errors in power-user / group-chats modules

* Fix single sprite upload

* Return empty object on failed upload
2025-07-06 23:27:53 +03:00
Cohee 780bd1fc65 Add backfill for missing WI entries fields (#4203)
* Add backfill for missing WI entries fields
Fixes #4202

* Backfill before filter/sorting

* Fix array wrapping

* Check if characterFilter is array

* Add console debug for isArray check

* Add isArray check for entry
2025-06-26 20:48:24 +03:00
Cohee 12a54d901e WI: exclude characterFilter fields from new entry template 2025-06-25 10:38:08 +00:00
Wandering Mouse 116bef6c9f Add support for characterFilter to getEntryField and setEntryField (#4185)
* Add support for characterFilter to getEntryField and setEntryField

* No more conflicts between lint and autoformat

* Fix array type default values hint

* Properly capitalize name

* Fix search by name

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-06-21 22:10:56 +03:00
Cohee 14212fb761 Fix type errors 2025-06-09 23:35:10 +03:00
Cohee 4fa7de9c93 Add typing for QR API global 2025-06-09 22:53:34 +03:00
Cohee b3c636fe91 Refactor and fix type errors in WI and script modules (#4123)
* remove unnecessary arg passage from WI helper funcs

* remove some typescript red from script.js

* hide in shame

* Add JSDoc to helper functions

* Fix fav_ch_checked not updating

* Move PWA mode match to firstLoadInit

* Fix more type errors and deprecations

* Fix the rest of type errors in script.js

---------

Co-authored-by: RossAscends <124905043+RossAscends@users.noreply.github.com>
2025-06-08 19:14:03 +03:00
Cohee 70141aa565 Get rid of isSaveWorldInfoDisabled 2025-06-08 03:20:41 +03:00
Cohee 44c73354fd Stop mass WI open if the page was unloaded 2025-06-08 02:36:22 +03:00
Cohee d33b21282e Fix eslint 2025-06-06 09:55:18 +00:00
Cohee aa81b0c5a3 Init key scroll heights immediately 2025-06-06 09:45:55 +00:00
Cohee 6dc2077507 Fix expand/collapse all entries 2025-06-06 09:40:59 +00:00
Cohee e7db61f664 Remove opacity transition 2025-06-06 02:14:33 +03:00
Cohee 9a82b688ba WI: Split entry header and editor 2025-06-06 02:10:49 +03:00
RossAscends edbc257e81 - replace top bar toggle animations with opacity fades
- refactor MovingUI
- refactor getWorldEntry
2025-06-06 05:29:18 +09:00
Cohee e08d1b522c Don't destroy sortable manually 2025-06-05 08:45:31 +00:00
Cohee 62fdce8cad Replace select2 detection 2025-06-05 08:44:55 +00:00
Cohee bbe62527d2 Remove pointless DOM call 2025-06-05 08:40:01 +00:00
Cohee b7323715b2 Prevent saveWorldInfo calls while rendering the list 2025-06-05 08:33:38 +00:00
Cohee 0f9cd5f48d Remove debug logs with DOM queries 2025-06-05 08:25:50 +00:00
RossAscends e1a1fdb0da dont reload editor list on world list tag click if that world is already displayed and open in the editor 2025-06-05 16:13:27 +09:00
RossAscends 42b2637707 await the fade in.. 2025-06-05 15:51:11 +09:00
RossAscends b55de85243 Removes memory heap bloat by improving DOM and JQUI datacache clearing when swapping WI in the editor, and all other 'reloadEditor' calls via slashcommands etc.
Results in a slight delay depending on entries visible via pagination (about 2s for 50 visible entries), but I added a pleasant fade transition to make it feel organic.
2025-06-05 15:32:33 +09:00
omahs d7d20a67fa Fix typos 2025-05-29 11:56:59 +02:00
Cohee c528940a45 Fix WI position selector if entry.position is empty 2025-05-25 21:36:21 +03:00
RossAscends f145dfcb2d fix edge cases, put toastr on a diet 2025-05-21 15:35:12 +09:00
Yokayo 11908f7363 Work on tl 2025-04-28 18:45:16 +07:00
Cohee ed895b7c3e Merge pull request #3889 from BismuthGlass/feature/wi_global_matches
World Info chat-independent data matching
2025-04-27 21:00:57 +03:00
Wolfsblvt 6eb89bd21c fix some linting 2025-04-25 20:58:28 +02:00
Wolfsblvt 05c010223b Move function above init
Well, I like that init is last in nearly all files...
2025-04-25 20:49:47 +02:00
Wolfsblvt a667e14c8b Make global WI placeholder translatable 2025-04-25 20:45:13 +02:00