JS-Slash-Runner (Tavern-Helper)

repository·main·Indexed 21 days ago

https://github.com/n0vi028/js-slash-runner

A SillyTavern extension, also known as Tavern-Helper, that enables the execution of external JavaScript code within an isolated iframe to mitigate security risks. It provides utilities for AI response generation, including functions like generate() and generateRaw(), input processing with macro substitution and image handling, and compatibility layers for generation parameters across various providers such as Azure OpenAI, Claude, and OpenRouter.

Tokens
15.6K
Snippets
57
Records
78
Agent score
73%

What's inside JS-Slash-Runner

  1. What is Tavern-Helper

    main

    Tavern-Helper is a SillyTavern extension that allows you to run external JavaScript code. Because SillyTavern does not support direct execution of arbitrary JavaScript by default, this extension uses an iframe to isolate and execute scripts, enabling them to run in certain restricted contexts.

    WARNING

    Executing custom JavaScript code carries security risks. Malicious scripts could steal API keys, chat logs, or sensitive information, or modify/damage your SillyTavern settings. Always inspect script content and ensure the source is trusted before execution.

  2. How the Prompt Viewer updates and intercepts prompts

    main

    The Prompt Viewer is designed to always display the most recent prompt. It achieves this by intercepting generation requests within the Tavern environment.

    There are three ways the viewer captures prompt data:

    1. On Opening: When you open the Prompt Viewer, it automatically triggers a 'fake' generation request (simulating a click on the send button). It waits for Tavern to process this request, intercepts the prompt (without actually sending it to the AI), and displays the result.
    2. On Refresh: Clicking the refresh button (<i class="fa-solid fa-rotate-right"></i>) triggers the same 'fake' generation request mechanism described above to fetch the latest state.
    3. During Real Generation: The viewer listens for all actual generation requests. This includes:
      • Clicking the send button (<i class="fa-solid fa-paper-plane"></i>) manually.
      • Using Tavern Assistant functions like generate or generateRaw.
      • Any other method used to send prompts via the Tavern interface.
  3. How Prompt Viewer updates prompts

    main

    The Prompt Viewer is designed to always show the most recent prompts by intercepting generation requests. It updates its view in three scenarios:

    1. Opening the Viewer: Upon opening, the viewer triggers a fake generation request (simulating a click on the send button) to intercept and display the current prompts without actually sending them to the AI.
    2. Manual Refresh: Clicking the refresh button (<i class="fa-solid fa-rotate-right"></i>) triggers a fake generation request to fetch the latest state.
    3. Actual Generation: The viewer listens to all generation requests. It will automatically update whenever a prompt is sent via:
      • Clicking the send button (<i class="fa-solid fa-paper-plane"></i>).
      • Using the generate or generateRaw functions from Tavern Helper.
      • Any other method used to send prompts through SillyTavern.
  4. Recommended Global Settings for Worldbooks

    main

    To ensure compatibility with modern character cards, use the following recommended global settings for Worldbooks. Most current character card authors use these settings by default, so manual modification is generally unnecessary unless you are working with older content.

    Recommended Settings:

    • Scan Depth (扫描深度): 2
    • Context Percentage (上下文百分比): 100
    • Token Budget Cap (Token 预算上限): 0
    • Minimum Activations (最小激活数): 0
    • Max Depth (最大深度): 0
    • Max Recursive Depth (最大递归深度): 0
    • Insertion Strategy (插入策略): Character Worldbook Priority (角色世界书优先)
    • Include Names (包括名称): false
    • Recursive Scan (递归扫描): true
    • Case Sensitive (区分大小写): false
    • Match Whole Word (匹配整个单词): false
    • Use Group Scoring (使用群组评分): false
    • Overflow Alert (溢出警报): false
  5. Optimize message rendering with '# Msg. to Render'

    main

    The # Msg. to Load setting (now referred to as # Msg. to Render) in the top bar controls the maximum number of messages displayed during gameplay. This optimizes performance by ensuring the tavern only renders a specific number of messages at any given time.

    Behavior

    • Limit Enforcement: If set to 5, the page will display at most 5 messages.
    • New Messages/Replies: When a new message or reply is sent, the oldest message is removed from the render queue to make room for the new one (e.g., messages 4,5,6,7,8 become 5,6,7,8,9).
    • Message Deletion: When a message is deleted, the system automatically fills the gap by rendering the next available old message (e.g., messages 5,6,7,8,9 become 4,5,6,7,8).

    Configuration

    • You can set this to any non-negative integer.
    • For example, setting it to 1 will only display the single most recent message.
  6. Install dependencies and build Tavern-Helper

    main

    To build this project from source, you must have Node.js 22+ and pnpm installed.

    Follow these steps to set up the environment and compile the project:

    1. Install pnpm globally:
      npm install -g pnpm
    2. Install project dependencies:
      pnpm install
    3. Build the project:
      pnpm build

    Alternatively, you can use pnpm watch to continuously monitor code changes. After making changes, simply refresh the SillyTavern web page to use the latest plugin code.

    npm install -g pnpm
    pnpm install
    pnpm build
    # or
    pnpm watch
  7. Maximize preset context length to prevent prompt truncation

    main

    Enable the Maximize preset context length feature to lock the Context Size (tokens) setting in the preset panel to its maximum value (200w).

    This prevents SillyTavern from incorrectly truncating prompts. Because SillyTavern's token calculation is often inaccurate—especially when extensions like Tavern helper macros or ST-Prompt-Template are processing the prompt—the calculated token count can be much higher than the actual count. Locking the context size to the maximum ensures that the full prompt is sent to the AI without being prematurely cut off by SillyTavern's internal limits.

  8. Update World Info when using 'Replace/Update Character Card'

    main

    By default, the standard Tavern 'Replace/Update Character Card' feature only updates character-specific metadata (such as avatar, description, and the first message) but fails to update previously imported World Info (Worldbook) data.

    To ensure that World Info is also synchronized when updating a character card, enable the better_character_update optimization. When this option is active, the Replace/Update Character Card function will simultaneously update both the character card information and its associated World Info.

  9. Maximize preset context length

    main

    Enable this feature to lock the Context Length (in tokens) in the preset panel to its maximum value (2,000,000).

    By default, Tavern applies a limit to the number of tokens sent to the AI. If the prompt exceeds this limit, Tavern truncates it. Because Tavern's token calculation is often imprecise and can be inflated by plugin processing (such as Tavern-Helper macro replacements or conditional prompt templates), the calculated token count is frequently much higher than the actual count.

    Locking the context length to the maximum prevents Tavern from incorrectly truncating prompts that could otherwise be sent in full to the AI, and it does not negatively impact gameplay.