Commit Graph

11572 Commits

Author SHA1 Message Date
Cohee 2d1a96f91d Improve performance of printMessages (#4979)
* Improve performance of printMessages

* Add clarifying comment

* Refactor printMessages into redisplayChat.

* const https://github.com/SillyTavern/SillyTavern/pull/4981#discussion_r2675632422

* Use `toFixed(3)` instead of 17 decimals. https://github.com/SillyTavern/SillyTavern/pull/4981#discussion_r2675647691

* Removed `.find is faster than .children.` comment. https://github.com/SillyTavern/SillyTavern/pull/4981#discussion_r2675625188

* Simplified add 'last_mes'. https://github.com/SillyTavern/SillyTavern/pull/4981#discussion_r2675616734

---------

Co-authored-by: user <user@exmaple.com>
2026-01-11 18:33:23 +02:00
Cohee 1bfabd9b77 Merge branch 'release' into staging 2026-01-11 02:49:11 +02:00
Cohee f861beb244 OpenRouter: Fix fallback model request 2026-01-11 02:48:58 +02:00
Cohee d56011b60f Skip redundant scroll adjustment 2026-01-11 02:05:44 +02:00
Cohee ab164efea6 Fix: don't call append media twice on swipe (#4991) 2026-01-11 01:41:10 +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
Cohee 281c50bb52 Fix: init macros before extensions (#4988)
* Fix: init macros before extensions

* Add an anchor comment for future reference
2026-01-10 23:38:21 +02:00
Cohee 6036ff9a3c Merge branch 'release' into staging 2026-01-10 19:53:16 +02:00
Cohee eb48c5abe2 Fix: show edit textarea for messages with inline media 2026-01-10 19:53:08 +02:00
Cohee d25d97ad5d Merge branch 'release' into staging 2026-01-10 19:37:59 +02:00
Cohee c705cbe698 Fix {{summary}} with experimental engine 2026-01-10 19:37:43 +02:00
Wolfsblvt 5c2a02a128 Fix {{pick}} macro seeding inside delayed-resolution macros like {{if}} (#4986)
- Thread `contextOffset` through `MacroEngine.evaluate()` to preserve global document position
- Update `resolve()` in execution context to pass caller's `globalOffset` as `contextOffset`
- Add `offsetDelta` option to `resolve()` for additional offset customization
- Add regression tests for `{{pick}}` inside `{{if}}` blocks with `delayArgResolution`
- Ensure identical picks at different positions produce different results
2026-01-10 11:50:58 +02:00
Cohee ad860f4447 Z.AI: Add video generation models 2026-01-10 00:59:33 +02:00
Wolfsblvt 3047045d37 Macros 2.0 [Fix] - Fix macro evaluation to allow nested scoped macros in arguments (#4977)
* Fix scoped macro evaluation to allow nested scoped macros in arguments

- Refactor `#evaluateArgumentNode` to re-parse argument content for scoped macro pairs
- Create shared `#evaluateRawContent` helper method for consistent text evaluation
- Update `#evaluateScopedContent` to use the shared helper, reducing duplication
- Add 8 comprehensive test cases for nested scoped macros in arguments
- Enhance JSDoc documentation for EvaluationContext text parameter

* Fix `{{pick}}` macro to use global document offset for deterministic seeding

- Replace `range.startOffset` with `globalOffset` in pick macro handler for consistent position-based seeding
- Add `contextOffset` to EvaluationContext to track base offset from original document (starts at 0 for top-level)
- Calculate `globalOffset` as `contextOffset + range.startOffset` when building MacroCall objects
- Thread `contextOffset` through evaluation pipeline: MacroEngine → MacroCstWalker → all evaluation

* Fix typo in MacroCstWalker JSDoc comment and thread contextOffset through evaluateDocument

- Correct JSDoc typo: "rull macro text" → "full macro text"
- Destructure `contextOffset` from options in `evaluateDocument` method
- Pass `contextOffset` to EvaluationContext instead of hardcoded 0
2026-01-09 23:25:08 +02:00
Cohee 8a32b72dfe Replace $.ajax with fetch (#4978) 2026-01-09 02:28:22 +02:00
Cohee 68d4da1c83 Optimize getGroupPastChats (#4976)
* Optimize getGroupPastChats

* Add return type to getGroupPastChats
2026-01-09 02:17:18 +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
allen9441 f6a2def403 Fix user handle naming logic (#4969)
* Fix user handle naming logic

* Extract slugify logic into a module func

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-08 19:08:37 +02:00
Cohee f797573290 Add OpenRouter headers to image generation requests 2026-01-07 12:31:06 +00:00
Cohee 908368f221 Merge branch 'release' into staging 2026-01-07 08:55:24 +00:00
Cohee bc660b8b91 Fix legacy {{authorsNote}} 2026-01-07 08:54:05 +00:00
DeclineThyself ae5f69585b Removed 87 redundant chat[chat.length - 1] lookups. (#4963)
* Removed redundant `chat[chat.length - 1]` lookups.

* Readability.
Don't chat[chat.push({}) - 1];.

* Chat can't be empty.
https://github.com/SillyTavern/SillyTavern/pull/4963#discussion_r2663006489

* Fixed mixup: https://github.com/SillyTavern/SillyTavern/pull/4963#discussion_r2663000183

* Rename it back to item

* Add early return on empty chat.

* Fix swipe assignment to use item message instead of last message

---------

Co-authored-by: user <user@exmaple.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-07 01:17:54 +02:00
Cohee 1c6d5da1b5 Cut secret input UI messages 2026-01-07 00:26:36 +02:00
Cohee 7320aa948d Audio inlining for OpenAI and Custom-compatible (#4964)
* Audio inlining for OpenAI and Custom-compatible

* Add context sizes

* chatgpt-image-latest

* Add quality control for gpt-image
2026-01-06 13:27:13 +02:00
Cohee 7331dba056 Macros 2.0 (v0.6.6) - STscript compatibility (#4957)
* Bypass REPLACE_GETVAR with experimental parser enabled

* (wip) macro-2.0 replacer in STscript parser

* Add support for MacroDefinitionOptions format in dynamic macros

- Add DynamicMacroValue typedef supporting string, function, or MacroDefinitionOptions object
- Extract macro definition building logic into MacroRegistry.buildMacroDefFromOptions() method
- Update MacroEngine to detect and handle three dynamic macro formats:
  1. string - direct value, no args allowed
  2. function - handler function, no args allowed (legacy)
  3. MacroDefinitionOptions object - full definition with handler, args, type

* Implement dynamic macro replacers

* Remove global typedef

* Use unique closure boundary

* Add e2e tests for MacroSlashCommands

* Update public/scripts/macros/engine/MacroEngine.js

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>

* Use strict args array match

* Update public/scripts/macros/engine/MacroEngine.js

---------

Co-authored-by: Wolfsblvt <wolfsblvt@gmail.com>
2026-01-06 00:57:03 +02:00
Cohee 293ee0a310 Caption: Add custom model input field (#4956) 2026-01-05 02:15:52 +02:00
Wolfsblvt e40b31b06d Macros 2.0 (v0.5.2) - Onboarding for new Macro Engine (#4955)
* Macros 2.0 [Feature] - Add onboarding popup for experimental macro engine features

- Add `onbordingExperimentalMacroEngine()` function in MacroDiagnostics.js to detect and prompt users about experimental features
- Detect experimental macro features in `substituteParamsLegacy()`: {{if}}, scoped macros, macro flags, variable shorthands, nested macros
- Add feature detection in autocomplete parser for macro flags, variable shorthands, and leading whitespace

* Fix typo: rename `onbording` to `onboarding` throughout macro diagnostics system

* Add `void` operator to async onboarding calls and fix typo in comment

- Add `void` operator to all `onboardingExperimentalMacroEngine()` calls to explicitly discard Promise return values
- Fix typo in MacroDiagnostics.js comment: "hat" → "that"

* Fix typo in experimental macro engine onboarding popup: "anytime time" → "any time"

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-05 01:32:13 +02:00
Wolfsblvt b453fdc5d8 Macros 2.0 [Fix] - Macro display override uses alias name if relevant + preserve whitespaces for autocomplete closing tag (#4953)
* Refactor: Move MacroBrowser.js to macros/engine directory and update import paths

* Replace macro name with alias in displayOverride for macro browser

- Import escapeRegex utility for safe regex pattern creation
- Check if macro has aliasOf property when displayOverride is present
- Replace all occurrences of the original macro name with the alias name in displayOverride text
- Use word boundary regex pattern to match macro names in {{macro}}, {{macro::}}, and {{macro }} contexts

* Add whitespace padding preservation for macro closing tag autocomplete

- Extract paddingBefore and paddingAfter from opening macro tags in MacroCstWalker
- Pass padding info through unclosed scope detection in findUnclosedScopes() and findUnclosedScopesRegex()
- Update MacroClosingTagAutoCompleteOption constructor to accept padding options
- Apply same whitespace padding to closing tags as their corresponding opening tags
- Update regex fallback to capture and preserve whitespace from opening tags

* Add replacementStartOffset to AutoCompleteOption for whitespace normalization in closing tags

- Add replacementStartOffset property to AutoCompleteOption class with JSDoc documentation
- Update AutoComplete.select() to apply per-option replacement offset when calculating effectiveStart
- Calculate replacementStartOffset in MacroClosingTagAutoCompleteOption based on currentPadding length
- Pass currentPadding from context.paddingBefore to MacroClosingTagAutoCompleteOption in SlashCommandParser

* Fix closing tag detection regex to correctly autocomplete // macro

* Add flags and fullText to EnhancedMacroAutoCompleteOption context and fix {{//}} autocomplete offset

- Add flags, currentFlag, and fullText properties to EnhancedMacroAutoCompleteOptions JSDoc
- Store options object as #options field in EnhancedMacroAutoCompleteOption for later access
- Pass flags, currentFlag, and fullText from context to macroContext in SlashCommandParser
- Fix {{//}} macro autocomplete to adjust replacementStartOffset when typed after single slash to avoid treating it as flag

* Add unnamedArgs definition to {{//}} comment macro for better documentation

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-05 01:27:06 +02:00
Wolfsblvt cd0627bfec Macros 2.0 [Macros] - Add {{hasExtension}} macro, and refactor extension lookup logic (#4948)
* Add {{hasExtension}} macro and refactor extension lookup logic

- Move findExtension() from extensions-slashcommands.js to extensions.js and export it
- Update findExtension() to return object with name and enabled properties instead of just name string
- Add {{hasExtension}} macro to check if an extension is enabled
- Update /extension-state and /extension-exists commands to use refactored findExtension()
- Remove duplicate findExtension() implementation from extensions-slashcommands.js

* Refactor extension action callbacks to use extension object instead of separate name and enabled properties

* fix eslint
2026-01-04 20:37:27 +02:00
Cohee e6ce84d726 Wrap reloadCurrentChat into SimpleMutex. (#4944)
Supersedes #4943
2026-01-04 19:54:25 +02:00
Cohee 2fb4ab3184 Add Adaptive-P settings (#4945)
* TC: Add Adaptive-P settings and UI elements

* Improve compatibility with sampler select
2026-01-03 22:25:16 +02:00
Wolfsblvt 81414724b0 Macros 2.0 (v0.5.1) - Delayed Macro Argument Resolution for {{if}} Macro (#4934)
* Add variable shorthand syntax support for local and global variables

- Add VariableShorthandType enum and VariableShorthandDefinitions for `.` (local) and `$` (global) prefixes
- Add VariableShorthandAutoCompleteOption class for autocomplete of variable shorthand syntax
- Implement variable expression parsing in MacroCstWalker to handle `{{.varName}}` and `{{$varName}}` syntax
- Add support for variable operations: get, set (=), increment (++), decrement (--), and add (+=)
- Route variable expressions to appropriate macro via handler

* Add variable shorthand autocomplete support for variable names and operators

- Add `isValidVariableShorthandName()` helper to validate variable names against shorthand pattern
- Add `VariableNameAutoCompleteOption` class for suggesting existing and new variable names
- Add `VariableOperatorAutoCompleteOption` class for suggesting operators (=, ++, --, +=)
- Add `VariableOperatorDefinitions` map with operator metadata (symbol, name, description, needsValue)

* Add variable shorthand support to {{if}} macro condition autocomplete

- Add variable shorthand (.var, $var) support to {{if}} condition evaluation in core-macros.js
- Detect and resolve variable shorthands using getvar/getglobalvar macros before condition check
- Update {{if}} description and examples to document variable shorthand syntax
- Add variable shorthand autocomplete options when typing {{if}} condition
- Show variable prefix options (. and $) when no condition is typed yet
- Reuse #buildVariableShorthandOptions

* refactor: Add Object.freeze to lexer constants and improve JSDoc documentation

- Freeze `modes` and `Tokens` objects to prevent accidental mutations
- Convert inline comments to proper JSDoc format for better documentation
- Add JSDoc block for `Def` lexer definition object
- Improve comment clarity and formatting consistency throughout MacroLexer.js
- Remove redundant section separator comments in variable shorthand modes

* Add inversion prefix (!) autocomplete support to {{if}} macro condition

- Add SimpleAutoCompleteOption class for basic autocomplete items with name, symbol, and description
- Add ! inversion prefix as autocomplete option in {{if}} condition with 🔁 icon
- Show ! as selectable option when nothing typed, non-selectable when already present
- Fix condition parsing to handle ! prefix with whitespace (e.g., "! $myvar")
- Update identifier extraction to strip ! and whitespace before detecting variable

* fix lint

* Fix variable shorthand regex in {{if}} macro to properly capture prefix and variable name

* Expand comprehensive e2e tests for variable shorthand syntax in lexer and macro engine

- Add MacroLexer tests for variable shorthand edge cases (whitespace, numbers, underscores, operators)
- Add MacroEngine tests for variable shorthand operations (hyphens, underscores, non-existent vars, chaining)
- Add MacroEngine tests for variable shorthand in {{if}} conditions (truthy/falsy, inversion, else branches)
- Test variable names with hyphens, underscores, and numbers in both get/set and conditional contexts

* Fix macro flags not being allowed inside variable shorthand macros

- Move MANY(flags) block from macroBody to macro rule to parse flags before branching
- Fix MacroCstWalker to extract flags from children.flags instead of bodyChildren.flags
- Ensures flags are available for both variable expressions and regular macros
- Fixes flag extraction in visitMacro and visitBlockMacroClose methods

* Implement delayed argument resolution for {{if}} macro to prevent side effects in non-chosen branches

- Add `delayArgResolution` flag to MacroDefinition to control when nested macros are evaluated
- Modify MacroCstWalker to skip nested macro evaluation when delayArgResolution is true
- Update {{if}} macro to use delayArgResolution and manually resolve only the chosen branch
- Replace ELSE_MARKER splitting with `splitOnTopLevelElse()` that parses CST to find correct {{else}} at depth 0

* Fix delayed resolve on if/else macros being off when a non-scoped if macro was being used inside

- Track argument count in MacroCstWalker.extractMacroInfo() to distinguish inline vs scoped macros
- Update splitOnTopLevelElse() to only track scoped {{if}} blocks (1 arg) when finding {{else}} at depth 0
- Update findClosingMacro() to only increment depth for macros that can accept scoped content
- Add e2e tests for inline {{if::condition::content}} inside scoped {{if}}/{{else}} blocks

* Remove eslint exclusion

* Remove duplicate tests

* Regenerate package-lock.json in /tests

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2026-01-03 19:45:17 +02:00
Wolfsblvt dbc4fe611c Macros 2.0 [Fix] - Make macro name matching case-insensitive throughout the macro system (#4942)
* Make macro name matching case-insensitive throughout the macro system

- Normalize macro names and aliases to lowercase in MacroRegistry storage and lookup
- Update MacroCstWalker to use case-insensitive matching for block macro pairing
- Normalize dynamic macro keys to lowercase in MacroEnvBuilder
- Update MacroEngine to use lowercase keys when checking dynamic macros
- Preserve original casing in macro definitions for display purposes
- Add comments explaining case-insensitive matching behavior

* Make alias validation case-insensitive in MacroRegistry to prevent duplicate names

- Prevents registering aliases that differ only in casing from the macro name
2026-01-03 18:40:32 +02:00
Cohee b774a553f9 Caption: allow duplicate model ids into the list from different sources 2026-01-03 00:44:11 +02:00
Cohee 0c8d74da02 NanoGPT: Enable tool calling
Closes #4930
2026-01-03 00:20:31 +02:00
Cohee f1b11db5f8 Merge branch 'release' into staging 2026-01-02 19:36:25 +02:00
Cohee ce71ca5097 Fix npm audit 2026-01-02 19:35:50 +02:00
ZhenyaPav ef89d0f291 Added regex filter option to TTS extension (#4924)
* Add regex filter option to TTS extension

- Added checkbox to enable/disable regex filtering of TTS text
- Added text input for custom regex patterns
- Default pattern removes emojis and non-English text while preserving letters, numbers, spaces, and punctuation
- Regex is applied after asterisk removal and other text processing
- Includes error handling for invalid regex patterns
- Automatically cleans up extra spaces after regex removal

* reverted the accidental change in tts_skip_tags description
clarified the regex description

* Add regex validation warning to TTS settings

* fixed regex field in UI

* reworked the regex warning

* changed the regex event to change (input might not have worked correctly)

* Apply review comments

* Spacing fix

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-12-31 20:03:04 +02:00
Wolfsblvt 0dcd9906bf Macros 2.0 (v0.5) - Add variable shorthand macros and variable support to {{if}} macro (#4933)
* Add variable shorthand syntax support for local and global variables

- Add VariableShorthandType enum and VariableShorthandDefinitions for `.` (local) and `$` (global) prefixes
- Add VariableShorthandAutoCompleteOption class for autocomplete of variable shorthand syntax
- Implement variable expression parsing in MacroCstWalker to handle `{{.varName}}` and `{{$varName}}` syntax
- Add support for variable operations: get, set (=), increment (++), decrement (--), and add (+=)
- Route variable expressions to appropriate macro via handler

* Add variable shorthand autocomplete support for variable names and operators

- Add `isValidVariableShorthandName()` helper to validate variable names against shorthand pattern
- Add `VariableNameAutoCompleteOption` class for suggesting existing and new variable names
- Add `VariableOperatorAutoCompleteOption` class for suggesting operators (=, ++, --, +=)
- Add `VariableOperatorDefinitions` map with operator metadata (symbol, name, description, needsValue)

* Add variable shorthand support to {{if}} macro condition autocomplete

- Add variable shorthand (.var, $var) support to {{if}} condition evaluation in core-macros.js
- Detect and resolve variable shorthands using getvar/getglobalvar macros before condition check
- Update {{if}} description and examples to document variable shorthand syntax
- Add variable shorthand autocomplete options when typing {{if}} condition
- Show variable prefix options (. and $) when no condition is typed yet
- Reuse #buildVariableShorthandOptions

* refactor: Add Object.freeze to lexer constants and improve JSDoc documentation

- Freeze `modes` and `Tokens` objects to prevent accidental mutations
- Convert inline comments to proper JSDoc format for better documentation
- Add JSDoc block for `Def` lexer definition object
- Improve comment clarity and formatting consistency throughout MacroLexer.js
- Remove redundant section separator comments in variable shorthand modes

* Add inversion prefix (!) autocomplete support to {{if}} macro condition

- Add SimpleAutoCompleteOption class for basic autocomplete items with name, symbol, and description
- Add ! inversion prefix as autocomplete option in {{if}} condition with 🔁 icon
- Show ! as selectable option when nothing typed, non-selectable when already present
- Fix condition parsing to handle ! prefix with whitespace (e.g., "! $myvar")
- Update identifier extraction to strip ! and whitespace before detecting variable

* fix lint

* Fix variable shorthand regex in {{if}} macro to properly capture prefix and variable name

* Expand comprehensive e2e tests for variable shorthand syntax in lexer and macro engine

- Add MacroLexer tests for variable shorthand edge cases (whitespace, numbers, underscores, operators)
- Add MacroEngine tests for variable shorthand operations (hyphens, underscores, non-existent vars, chaining)
- Add MacroEngine tests for variable shorthand in {{if}} conditions (truthy/falsy, inversion, else branches)
- Test variable names with hyphens, underscores, and numbers in both get/set and conditional contexts

* Fix macro flags not being allowed inside variable shorthand macros

- Move MANY(flags) block from macroBody to macro rule to parse flags before branching
- Fix MacroCstWalker to extract flags from children.flags instead of bodyChildren.flags
- Ensures flags are available for both variable expressions and regular macros
- Fixes flag extraction in visitMacro and visitBlockMacroClose methods

* Add SillyTavern global to tests eslintrc

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-12-31 19:38:50 +02:00
Cohee 5dee64e0bc Update description of banned macro 2025-12-29 21:14:20 +02:00
Cohee 316dfaadc7 Update macro category for charAuthorsNote 2025-12-29 21:14:07 +02:00
underscore_x 865e0a60a2 updated claude prompt caching url (#4931) 2025-12-29 13:26:13 +02:00
guoql666 efd87b4759 add new Tts adapter provider (#4915)
* add new provider: gpt-sovits-adapter

* export function getCharacters

* fixed some bugs
2025-12-28 23:55:28 +02:00
Subwolf a8eb154517 Zai moonshot reverse proxy (#4923)
* adding reverse proxy support

* update

* added handling for the image caption extension
2025-12-28 23:52:04 +02:00
Wolfsblvt e9bedadc0b Macros 2.0 (v0.4) - Add scoped macros (last arg can be scoped), {{if}} macro and macro flags (baseline implementation) (#4913)
* Macros: make category optional, default to UNCATEGORIZED

* Tests: Update macro tests to match new error handling behavior

- Change MacroRegistry tests from expecting thrown errors to capturing console.error logs
- Update MacroLexer tests to expect plaintext fallback instead of lexer errors for invalid tokens
- Fix MacroEngine test to use `char` macro instead of `newline` for arity validation
- Update MacroParser test with corrected expected error message for invalid identifiers
- Remove "[Error]" prefixes from test descriptions where lexer no longer errors

* Macros: Implement macro execution flags system

- Add MacroFlags module with flag parsing and validation (!, ?, ~, /, >, ., $, #)
- Update lexer to tokenize flags as separate tokens before macro identifier
- Modify parser to capture flags in CST under 'flags' label
- Update CST walker to parse flag tokens into MacroFlags object
- Pass parsed flags to macro handlers via MacroCall and MacroContext
- Update autocomplete parser to handle flags before identifier
- Add comprehensive tests for flag parsing,

* Macros: Fix autocomplete positioning for macros with flags and whitespace

- Add identifierStart to parseMacroContext to track where identifier begins in macro text
- Update autocomplete to use identifierStart for correct range calculation
- Simplify indexMacros regex to use global flag instead of manual loop
- Use parseMacroContext in indexMacros to extract identifier (handles flags/whitespace)
- Fix autocomplete range starting at wrong position when flags or whitespace present

* Macros: Add autocomplete support for macro execution flags

- Add MacroFlagAutoCompleteOption class for rendering flag options in autocomplete
- Extend parseMacroContext to track currentFlag (flag cursor is on) and isInFlagsArea
- Track flagEndPositions to determine which flag cursor is currently typing
- Update #buildEnhancedMacroOptions to show flag options when cursor is in flags area
- Show current flag first if cursor just typed it, then show remaining available flags
- Add renderItem and renderDetails methods to MacroFlag

* Macros: Implement scoped macro syntax with opening and closing tags

- Add scoped macro processing to MacroCstWalker to find and merge opening/closing pairs
- Parse closing block flag (/) to identify closing macros and match with opening tags
- Extract content between opening and closing tags as the last unnamed argument
- Add `isScoped` property to MacroCall and MacroContext to track scoped invocations
- Implement `#processScopedMacros` to find outermost matching pairs and handle nesting

* Macros: Add autocomplete warnings, scoped content info, and closing tag suggestions

- Add arity warning banners in autocomplete details for invalid argument counts
- Show warning when using space-separated args on multi-arg or no-arg macros
- Add scoped content info banner when cursor is inside unclosed scoped macro
- Implement MacroClosingTagAutoCompleteOption to suggest closing tags for scoped macros
- Add sortPriority property to AutoCompleteOption for controlling sort order

* SlashCommands: Disable unimplemented flags and closing flag when no unclosed scopes in autocomplete

- Set closing block flag as non-selectable when no unclosed scopes exist
- Set unimplemented flags as non-selectable with empty valueProvider
- Lower sort priority (12) for non-selectable flags vs selectable flags (10)

* Autocomplete: Show scoped content info and auto-close no-arg macros

- Show scoped content info when cursor is at closing }} of unclosed scoped macro
- Auto-complete no-arg macros with closing }} using valueProvider
- Trigger autocomplete on select (isSelect) to refresh after choosing an option
- Simplify MacroFlagAutoCompleteOption to use base makeItem for consistent styling
- Change closing tag icon from '{/}' to '{/' for better visual consistency

* Macros: Add scoped trim macro to trim content inside opening/closing tags

- Add scoped usage for {{trim}}content{{/trim}} to trim whitespace from content
- Keep non-scoped {{trim}} behavior (post-processing marker) for backward compatibility
- Add optional unnamed 'content' argument for scoped usage
- Update description to explain both scoped and non-scoped behavior
- Handler checks isScoped flag to determine which behavior to use

* Autocomplete: Fix closing tag parsing to prevent `/` being treated as flag

- Add special case in parseMacroContext to detect closing tags (`/` + identifier char)
- Stop flag parsing when `/` is followed by identifier character (closing tag syntax)
- Simplify MacroClosingTagAutoCompleteOption valueProvider to return full closing tag
- Remove input-based logic since autocomplete replaces entire identifier

* Macros: Add {{if}} conditional macro with auto-resolution of macro names

- Add {{if condition}}content{{/if}} macro to conditionally show content
- Auto-resolve condition if it matches a registered macro name (0 required args)
- Support both scoped content ({{if x}}...{{/if}}) and explicit args ({{if::x::content}})
- Treat empty string, "false", "off", "0" as falsy conditions
- Inherit environment context when resolving macro names
- Update autocomplete warning to allow space-separated syntax

* Macros: Add centralized identifier validation with pattern enforcement

- Export MACRO_IDENTIFIER_PATTERN from MacroLexer for reuse across modules
- Add isIdentifierValid() helper function to validate macro names and aliases
- Enforce identifier pattern: must start with letter, followed by word chars or hyphens
- Update macro registration to validate both primary names and alias identifiers
- Improve error messages to explain identifier requirements
- Add comprehensive e2e tests for valid/invalid identifier patterns

* Macros: Add tests for scoped {{trim}} macro functionality

* SlashCommands: Fix macro indexing to properly handle nested macros with brace depth tracking

- Replace regex-based macro detection with manual brace depth tracking
- Track opening/closing brace pairs to correctly identify macro boundaries
- Ensure nested macros like {{reverse::Hey {{user}}}} are properly indexed
- Index both outer and inner macros by scanning content recursively
- Handle unclosed macros by defaulting to end of text

* Macros: Add {{else}} branch support to {{if}} conditional macro

- Add {{else}} macro as marker to split then/else branches in {{if}} blocks
- Use control character sequence (\u0000\u001FELSE\u001F\u0000) as internal marker
- Split scoped content on else marker and trim both branches independently
- Return then-branch if condition is truthy, else-branch if falsy
- Auto-suggest {{else}} in autocomplete when inside scoped {{if}} block
- Make {{else}} non-selectable in autocomplete when outside {{if}} scope

* Macros: Add negation support to {{if}} conditional macro with ! prefix

- Add ! prefix support to invert condition evaluation in {{if}} macro
- Parse original macro text to detect ! prefix before macro resolution
- Strip ! from condition after detecting inversion to avoid double-negation
- Invert isFalsy result when ! prefix is detected in original condition
- Prevent ! in resolved values from triggering inversion (only original syntax)

* Autocomplete: Add {{if}} condition autocomplete with zero-arg macro suggestions

- Add EnhancedMacroAutoCompleteOptions typedef for noBraces/paddingAfter/closeWithBraces options
- Support options object in EnhancedMacroAutoCompleteOption constructor alongside context
- Add noBraces mode to display macro names without {{ }} braces (for use as values)
- Add paddingAfter option to match opening whitespace style before closing }}

* Autocomplete: Match opening whitespace padding when auto-closing macros

* Fix `{{if}}` example usages

* Macros: Hide `comment` alias from autocomplete suggestions for `//` macro

* Macros: Simplify {{trim}} handler with destructured parameters and clearer content check

* Macros: Use MacroEngine.evaluate for zero-arg macro resolution in {{if}} condition handler

* Macros: Add auto-trim for scoped content with # flag to preserve whitespace

- Auto-trim scoped content by default in MacroCstWalker before passing to handlers
- Add preserveWhitespace flag (# symbol) to prevent auto-trimming when needed
- Rename legacyHash flag to preserveWhitespace across engine and definitions
- Update {{trim}} handler to rely on engine auto-trim for scoped content
- Update {{if}} handler to respect # flag when trimming branches around {{else}} marker

* Macros: Clarify macro name validation error message to use "alphanumeric characters" instead of "word chars"

* Add 'setspriteoverride' optional 'name' argument

* Refactor ElevenLabs TTS API key handling (#4906)

* Refactor ElevenLabs TTS API key handling #4483

* Remove unused connection button and related event handler from ElevenLabs TTS provider

* Add ElevenLabs STT endpoint

* Add caching system prompt feature for OpenRouter Gemini (#4903)

* feat: add caching system prompt for OpenRouter Gemini

* fix: resolve reviews

* Update GitHub links to llama.cpp

* Add model selection support for llama.cpp router mode (#4910)

* Add model selection support for llama.cpp router mode

- Add llamacpp_model setting to textgen-settings.js
- Implement loadLlamaCppModels() function to fetch and populate models
- Add onLlamaCppModelSelect() handler for model selection
- Update status check to load llama.cpp models when connecting
- Update getTextGenModel() to return selected llama.cpp model
- Add model dropdown to HTML UI in llama.cpp section
- Initialize event handlers and Select2 for better UX
- Add llamacpp_model to preset manager for save/load support
- Add llamacpp_model to slash commands support

This implements model selection for llama.cpp router mode, allowing
users to select from multiple models without restarting the server.
Follows the same pattern as Ollama, Tabby, and vLLM implementations.

* Correct spelling

* Fix clear selection position

---------

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

* Add glm-4.7 model option and context mapping for Z.AI

* Add select2 style for NanoGPT list
Closes #4911

* Disable macro engine init traces

* Update type annotations for instruct presets and context presets

* Fix test for new error text

* Add MacroStoryString tests

* Add trimContent utility for consistent indentation dedenting in scoped macros

- Add trimScopedContent method to MacroEngine that trims and dedents scoped content based on first non-empty line indentation
- Pass trimContent utility through evaluation context to all macro handlers
- Update {{if}} macro to use trimContent instead of direct trim() call
- Update auto-trim logic in MacroCstWalker to use trimContent for consistent dedenting
- Add trimContent to MacroExecutionContext type definitions

* Add ELSE_MARKER export and cleanup leftover markers in macro processing

* Update trimContent parameter to use options object pattern in JSDoc

* Add processor registration system to MacroEngine with priority-based execution

- Add MacroProcessor callback and RegisteredProcessor typedef for pre/post processors
- Add addPreProcessor/removePreProcessor and addPostProcessor/removePostProcessor methods with priority-based sorting
- Refactor core legacy syntax handling into registered processors with reserved priorities (0-50)
- Move legacy time syntax, marker replacements, brace unescaping, trim macro, and ELSE_MARKER cleanup to registered processors

* Split core processor registration into separate pre and post processor methods

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-12-28 21:36:13 +02:00
Cohee 1c0e7ea955 Merge pull request #4925 from SillyTavern/staging
Staging
2025-12-28 18:28:51 +02:00
Ngo Dinh Gia Bao 829db7f2d0 [Electron Hub] Prompt Caching Support for Claude models (#4918)
* Prompt Caching support Claude models

* Prompt Caching support Claude models

* Diff clean-up

---------

Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
2025-12-28 17:05:54 +02:00
Cohee bb53da4c09 add missing zai vision models 2025-12-27 23:07:57 +02:00
Cohee 1f0c0ccff4 Add message-role command 2025-12-27 21:21:39 +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