### getExtensionInstallationInfo Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html Gets installation information for an extension, including branch, commit hash, update status, and remote URL. ```APIDOC ## getExtensionInstallationInfo ### Description Gets installation information for an extension. ### Signature ```ts function getExtensionInstallationInfo(extension_id: string): Promise; ``` ### Type Definition ```ts type ExtensionInstallationInfo = { current_branch_name: string; current_commit_hash: string; is_up_to_date: boolean; remote_url: string; }; ``` ### Parameters #### `extension_id` - **Type**: `string` - **Required**: Yes - **Description**: The extension ID, usually the extension folder name. ### Return Value - **`ExtensionInstallationInfo`** - If the extension is found, returns the installation information. - **`null`** - If no extension is found for the given `extension_id`. ``` -------------------------------- ### Install project dependencies with pnpm Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.html Installs all project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Install pnpm globally Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.html Installs pnpm globally using npm. Requires Node.js 22+ to be installed first. ```bash npm install -g pnpm ``` -------------------------------- ### installExtension Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html Installs an extension from a URL with a specified type (local or global). Returns a Response. ```APIDOC ## installExtension ### Description Installs an extension. Newly installed extensions require a page refresh (`triggerSlash('/reload-page')`) to take effect. ### Signature ```ts function installExtension(url: string, type: 'local' | 'global'): Promise; ``` ### Parameters #### `url` - **Type**: `string` - **Required**: Yes - **Description**: The extension URL. #### `type` - **Type**: `'local' | 'global'` - **Required**: Yes - **Description**: The extension type. - `'local'`: Local extension, only available to the current user. - `'global'`: Global extension, available to all Tavern users. ### Return Value - **`Response`** - The response from the installation request. ### Example ```ts const response = await installExtension('https://github.com/n0vi028/JS-Slash-Runner', 'local'); if (response.ok) { toastr.success(`成功安装酒馆助手, 准备刷新页面以生效...`); _.delay(() => triggerSlash('/reload-page'), 3000); } ``` ``` -------------------------------- ### Variable structure examples Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%8F%98%E9%87%8F/%E8%8E%B7%E5%8F%96%E5%8F%98%E9%87%8F.html Example variable structures for global, chat, and message floor variables. These are used to illustrate how to reference them in prompts. ```ts const 全局变量 = { 神乐光: { 好感度: 50, }, }; const 聊天变量 = { 商品: [{ 内容: '...' }, { 内容: '...' }], }; const 消息楼层变量 = { 当前剧情阶段: '...', }; ``` -------------------------------- ### Register line-counting macro example Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B%E5%AE%8F.html Example that registers a macro to count lines. The regex matches [count_lines]...[/count_lines] and the replace callback returns the number of lines in the captured content. ```ts registerMacroLike(/[count_lines](.*?)[/count_lines]/gi, (_context, content) => String(content.split('\n').length)); ``` -------------------------------- ### generate Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%AF%B7%E6%B1%82%E7%94%9F%E6%88%90.html Documentation for the generate function, including parameters, return values, and examples. ```APIDOC ## generate ### Description Generates a response from the AI model based on the provided configuration. This is the primary function for requesting generation. ### Method Function call ### Endpoint `generate(config: GenerateConfig)` ### Parameters #### Request Body - **preset_name?** (string) - Optional - The preset name to use; defaults to the currently loaded preset `'in_use'`. If set, uses the selected preset's prompts and parameters, but not its regex or SillyTavern assistant scripts. - **generation_id?** (string) - Optional - Unique identifier for the generation request. If not set, a random identifier is generated. Useful for stopping specific generations with `stopGenerationById` or listening to corresponding generation events. - **user_input?** (string) - Optional - User input. - **should_stream?** (boolean) - Optional - Whether to enable streaming; defaults to `false`. When enabled, additional events are received with full/incremental text. - **should_silence?** (boolean) - Optional - Whether to generate silently; defaults to `false`. Silent generation does not affect the SillyTavern stop button state; clicking stop will not interrupt this generation. - **image?** (File | string | (File | string)[]) - Optional - Image input, supports multiple images as an array. Can be a `File` object, a Base64 string, or a URL string. - **custom_api?** (CustomApiConfig) - Optional - Custom API configuration. See `GenerateConfig` for details. - **overrides?** (Overrides) - Optional - Override options. If set, fields in `overrides` will override corresponding prompts. For example, `overrides.char_description = '覆盖的角色描述';` overrides the character description. - **injects?** (Omit[]) - Optional - Additional prompts to inject. See `InjectionPrompt` for details. - **max_chat_history?** ('all' | number) - Optional - Maximum number of chat history entries to use. - **tools?** (ToolDefinition[]) - Optional - Tool definitions in OpenAI style format. When passed, tool definitions are sent to supported providers during generation; the model may return `tool_calls` instead of plain text. - **tool_choice?** (ToolChoice) - Optional - Controls how the model uses tools. Only meaningful when `tools` is provided. Possible values: `'auto'`, `'required'`, `'none'`, `'any'`, or `{ type: 'function'; function: { name: string } }`. - **json_schema?** (JsonSchema) - Optional - JSON schema to constrain the model output. ### Request Example ```ts const result = await generate({ user_input: "你好" }); ``` ### Response #### Success Response - **普通文本结果** (string) - The generated text. - **工具调用结果** (GenerateToolCallResult) - The result when tool calls are made. #### Response Example ```ts type GenerateToolCallResult = { content: string; tool_calls: { id: string; type: 'function'; function: { name: string; arguments: string; }; thought_signature?: string; }[]; reasoning_signature?: string; }; ``` ### Notes - If no tool calls are used or the model does not actually trigger tool calls, a plain `string` is returned. - When tool calls are used and the model decides to call tools, a `GenerateToolCallResult` is returned. - The `custom_api.source` supports only the following API sources: `openai`, `claude`, `openrouter`, `makersuite`, `vertexai`, `azure_openai`, `custom`, `deepseek`, `xai`. ``` -------------------------------- ### Wait for Mvu interface initialization Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%88%86%E4%BA%AB%E6%8E%A5%E5%8F%A3.html Example of waiting for the Mvu interface to be initialized. After this line, the Mvu interface can be used directly. ```ts await waitGlobalInitialized('Mvu'); // ...此后可以直接使用 Mvu 接口 ``` -------------------------------- ### Rotate messages with rotateChatMessages (example 1) Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Rotate chat messages using rotateChatMessages. This example moves floors 4-6 before floors 2-3. ```typescript // 将 [4, 7) 楼放到 [2, 4) 楼之前, 即, 将 4-6 楼放到 2-3 楼之前 await rotateChatMessages(2, 4, 7); ``` -------------------------------- ### isInstalledExtension Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html Checks whether a specific extension is installed. Returns a boolean. ```APIDOC ## isInstalledExtension ### Description Checks whether a specific extension is installed. ### Signature ```ts function isInstalledExtension(extension_id: string): boolean; ``` ### Parameters #### `extension_id` - **Type**: `string` - **Required**: Yes - **Description**: The extension ID, usually the extension folder name. ### Return Value - **boolean** - `true` if the extension is installed, otherwise `false`. ### Example ```ts const is_installed = isInstalledExtension(getTavernHelperExtensionId()); ``` ``` -------------------------------- ### Copy prompts from preset A to preset B Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E4%BF%AE%E6%94%B9%E9%A2%84%E8%AE%BE.html Copies the prompts from '预设A' to the beginning of '预设B' by retrieving both presets and setting the prompts array to the concatenation of preset_a.prompts and preset_b.prompts. This is the second example in the documentation. ```typescript const preset_a = getPreset('预设A'); const preset_b = getPreset('预设B'); await setPreset('预设B', { prompts: [...preset_a.prompts, ...preset_b.prompts], }); ``` -------------------------------- ### Insert message before floor 10 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E5%88%9B%E5%BB%BA%E6%B6%88%E6%81%AF.html Example: inserts a user message before floor 10. ```ts await createChatMessages([{ role: 'user', message: '你好' }], { insert_before: 10 }); ``` -------------------------------- ### Enable streaming for in-use preset Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E4%BF%AE%E6%94%B9%E9%A2%84%E8%AE%BE.html Enables streaming for the preset currently in use by passing 'in_use' as the preset name and setting should_stream to true. This is the first example in the documentation. ```typescript await setPreset('in_use', { settings: { should_stream: true } }); ``` -------------------------------- ### Get or create chat lorebook with custom name Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Get or create a chat lorebook with a custom name using getOrCreateChatLorebook. The example creates a lorebook named '你好' if it does not exist. ```typescript // 如果聊天世界书不存在, 则尝试创建一个名为 '你好' 的世界书作为聊天世界书 const lorebook = await getOrCreateChatLorebook('你好'); ``` -------------------------------- ### installExtension 使用示例 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html 安装酒馆助手,成功后提示并延迟刷新页面。 ```typescript const response = await installExtension('https://github.com/n0vi028/JS-Slash-Runner', 'local'); if (response.ok) { toastr.success(`成功安装酒馆助手, 准备刷新页面以生效...`); _.delay(() => triggerSlash('/reload-page'), 3000); } ``` -------------------------------- ### getExtensionType Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html Gets the type of an installed extension. Returns 'local', 'global', 'system', or null if not found. ```APIDOC ## getExtensionType ### Description Gets the type of an installed extension. ### Signature ```ts function getExtensionType(extension_id: string): 'local' | 'global' | 'system' | null; ``` ### Parameters #### `extension_id` - **Type**: `string` - **Required**: Yes - **Description**: The extension ID, usually the extension folder name. ### Return Value - **`'local'`** - Local extension, only available to the current user. - **`'global'`** - Global extension, available to all Tavern users. - **`'system'`** - Built-in Tavern extension, such as regex. - **`null`** - No extension found for the given `extension_id`. ``` -------------------------------- ### Import character card from network link Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E5%AF%BC%E5%85%A5%E6%88%96%E6%9B%B4%E6%96%B0%E8%A7%92%E8%89%B2%E5%8D%A1.html Example of importing a character card from a network link. Fetches the card content as a Blob and passes it to importRawCharacter with the card name. ```ts const response = await fetch(角色卡网络链接); await importRawCharacter(角色卡名, await response.blob()); ``` -------------------------------- ### ExtensionInstallationInfo 类型定义 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html 扩展安装信息类型,包含当前分支名、当前提交哈希、是否最新和远程 URL。 ```typescript type ExtensionInstallationInfo = { current_branch_name: string; current_commit_hash: string; is_up_to_date: boolean; remote_url: string; }; ``` -------------------------------- ### Example of formatAsDisplayedMessage Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E6%B8%B2%E6%9F%93%E6%B6%88%E6%81%AF.html Example of formatAsDisplayedMessage: processes a string with macros and returns the HTML-formatted result. The example shows the expected output. ```ts const text = formatAsDisplayedMessage( "{{char}} speaks in {{lastMessageId}}" ); text == "

少女歌剧 speaks in 5

"; ``` -------------------------------- ### Share Mvu interface with initializeGlobal Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%88%86%E4%BA%AB%E6%8E%A5%E5%8F%A3.html Example of sharing the Mvu interface globally. After this call, other frontends or scripts can use `await waitGlobalInitialized('Mvu')` to wait for initialization and then access the interface via the `Mvu` variable. ```ts initializeGlobal('Mvu', Mvu); // ...此后其他前端界面或脚本中可以通过 `await waitGlobalInitialized('Mvu')` 来等待初始化完毕, 从而用 `Mvu` 为变量名访问该接口 ``` -------------------------------- ### substitudeMacros example with macros Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0.html Example usage of substitudeMacros: replaces macros like {{char}} and {{lastMessageId}} in a string. The example shows the expected result after substitution. ```ts const text = substitudeMacros("{{char}} speaks in {{lastMessageId}}"); text === "少女歌剧 speaks in 5"; ``` -------------------------------- ### isPresetSystemPrompt Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E8%8E%B7%E5%8F%96%E9%A2%84%E8%AE%BE.html 判断提供的提示词是否为系统提示词(酒馆所设置的系统提示词,分为 main、nsfw、jailbreak、enhance_definitions)。 ```APIDOC ## isPresetSystemPrompt ### Description 判断 `prompt` 是否为系统提示词 (酒馆所设置的系统提示词, 但其实相比于手动添加的提示词没有任何优势, 分为 `main`、`nsfw`、`jailbreak`、`enhance_definitions`) ### Method function ### Signature ```ts function isPresetSystemPrompt(prompt: PresetPrompt): prompt is PresetSystemPrompt; ``` ### Parameters #### prompt - **类型**: `PresetPrompt` ### Return Value - **是否为系统提示词**: `boolean` ``` -------------------------------- ### getPreset: Get preset content with Preset and PresetPrompt types Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E8%8E%B7%E5%8F%96%E9%A2%84%E8%AE%BE.html Retrieves the content of a preset by name. The function accepts 'in_use' or a preset name and returns a Preset object. The Preset type includes settings, prompts, unused prompts, and extensions. The PresetPrompt type defines the structure of individual prompts, including their id, position, role, and content. ```typescript function getPreset(preset_name: LiteralUnion<'in_use', string>): Preset; ``` ```typescript type Preset = { settings: { /** 最大上下文 token 数 */ max_context: number; /** 最大回复 token 数 */ max_completion_tokens: number; /** 每次生成几个回复 */ reply_count: number; /** 是否流式传输 */ should_stream: boolean; /** 温度 */ temperature: number; /** 频率惩罚 */ frequency_penalty: number; /** 存在惩罚 */ presence_penalty: number; top_p: number; /** 重复惩罚 */ repetition_penalty: number; min_p: number; top_k: number; top_a: number; /** 种子, -1 表示随机 */ seed: number; /** 压缩系统消息: 将连续的系统消息合并为一条消息 */ squash_system_messages: boolean; /** 推理强度, 即内置思维链的投入程度. 例如, 如果酒馆直连 gemini-2.5-flash, 则 `min` 将会不使用内置思维链 */ reasoning_effort: 'auto' | 'min' | 'low' | 'medium' | 'high' | 'max'; /** 请求思维链: 允许模型返回内置思维链的思考过程; 注意这只影响内置思维链显不显示, 不决定模型是否使用内置思维链 */ request_thoughts: boolean; /** 请求图片: 允许模型在回复中返回图片 */ request_images: boolean; /** 启用函数调用: 允许模型使用函数调用功能; 比如 cursor 借此在回复中读写文件、运行命令 */ enable_function_calling: boolean; /** 启用网络搜索: 允许模型使用网络搜索功能 */ enable_web_search: boolean; /** 是否允许发送图片作为提示词 */ allow_images: 'disabled' | 'auto' | 'low' | 'high'; /** 是否允许发送视频作为提示词 */ allow_videos: boolean; /** * 角色名称前缀: 是否要为消息添加角色名称前缀, 以及怎么添加 * - `none`: 不添加 * - `default`: 为与角色卡不同名的消息添加角色名称前缀, 添加到 `content` 字段开头 (即发送的消息内容是 `角色名: 消息内容`) * - `content`: 为所有消息添加角色名称前缀, 添加到 `content` 字段开头 (即发送的消息内容是 `角色名: 消息内容`) * - `completion`: 在发送给模型时, 将角色名称写入到 `name` 字段; 仅支持字母数字和下划线, 不适用于 Claude、Google 等模型 */ character_name_prefix: 'none' | 'default' | 'content' | 'completion'; /** 用引号包裹用户消息: 在发送给模型之前, 将所有用户消息用引号包裹 */ wrap_user_messages_in_quotes: boolean; }; /** 提示词列表里已经添加的提示词 */ prompts: PresetPrompt[]; /** 下拉框里没添加进来的提示词 */ prompts_unused: PresetPrompt[]; /** 额外字段, 用于为预设绑定额外数据 */ extensions: Record; } ``` ```typescript type PresetPrompt = { /** * 根据 id, 预设提示词分为以下三类: * - 普通提示词 (`isPresetNormalPrompt`): 预设界面上可以手动添加的提示词 * - 系统提示词 (`isPresetSystemPrompt`): 酒馆所设置的系统提示词, 但其实相比于手动添加的提示词没有任何优势, 分为 `main`、`nsfw`、`jailbreak`、`enhance_definitions` * - 占位符提示词 (`isPresetPlaceholderPrompt`): 用于表示世界书条目、角色卡、玩家角色、聊天记录等提示词的插入位置, 分为 `world_info_before`、`persona_description`、`char_description`、`char_personality`、`scenario`、`world_info_after`、`dialogue_examples`、`chat_history` */ id: LiteralUnion< | 'main' | 'nsfw' | 'jailbreak' | 'enhanceDefinitions' | 'worldInfoBefore' | 'personaDescription' | 'charDescription' | 'charPersonality' | 'scenario' | 'worldInfoAfter' | 'dialogueExamples' | 'chatHistory', string >; name: string; enabled: boolean; /** * 插入位置, 仅用于普通和占位符提示词 * - `'relative'`: 按提示词相对位置插入 * - `'in_chat'`: 插入到聊天记录的对应深度, 需要设置对应的深度 `depth` 和顺序 `order` */ position: | { type: 'relative'; depth?: never; order?: never; } | { type: 'in_chat'; depth: number; order: number }; role: 'system' | 'user' | 'assistant'; /** 仅用于普通和系统提示词 */ content?: string; } ``` -------------------------------- ### installExtension 函数类型定义 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html 安装扩展,新安装的扩展需要刷新页面 (triggerSlash('/reload-page')) 才生效。 ```typescript function installExtension(url: string, type: 'local' | 'global'): Promise; ``` -------------------------------- ### Build the project with pnpm Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.html Compiles the project. Alternatively, use `pnpm watch` to continuously monitor code changes and automatically update the plugin. ```bash pnpm build ``` -------------------------------- ### isCharacterTavernRegexesEnabled usage example Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%85%92%E9%A6%86%E6%AD%A3%E5%88%99/%E8%8E%B7%E5%8F%96%E6%AD%A3%E5%88%99.html Example usage of isCharacterTavernRegexesEnabled() to check and log whether local tavern regexes are enabled. ```ts const isEnabled = isCharacterTavernRegexesEnabled(); if (isEnabled) { console.log('局部正则已启用'); } else { console.log('局部正则未启用'); } ``` -------------------------------- ### createPreset Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E5%88%9B%E5%BB%BA%E9%A2%84%E8%AE%BE.html 创建预设的 API 文档 ```APIDOC ## createPreset ### Description 新建 `preset_name` 预设, 内容为 `preset`。 ### Method createPreset ### Signature ```ts function createPreset(preset_name: Exclude, preset?: Preset): Promise; ``` ### Parameters - **preset_name** (string) - Required - 预设名称 - **preset** (Preset) - Optional - 预设内容; 不填则使用默认内容 ### Return Value - **boolean** - 是否成功创建, 如果已经存在同名预设或尝试创建名为`'in_use'` 的预设会失败 ### Exceptions - 如果创建的预设内容中存在重复的系统/占位提示词, 将会抛出异常 ``` -------------------------------- ### Get text of message floor 0 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E6%B8%B2%E6%9F%93%E6%B6%88%E6%81%AF.html Gets the text content of message floor 0 using retrieveDisplayedMessage. ```ts const text = retrieveDisplayedMessage(0).text(); ``` -------------------------------- ### getExtensionInstallationInfo 函数类型定义 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html 获取扩展安装信息,返回 Promise。 ```typescript function getExtensionInstallationInfo(extension_id: string): Promise; ``` -------------------------------- ### 进入根目录以查找扩展文件夹 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%AE%89%E8%A3%85%E4%B8%8E%E6%9B%B4%E6%96%B0%E9%97%AE%E9%A2%98.html 在Termux中执行此命令以切换到根目录,为后续查找JS-Slash-Runner文件夹做准备。执行后前缀会变为类似root@localhost:/#的内容。 ```bash cd / ``` -------------------------------- ### Get all messages with swipes Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF.html Gets all floors' messages including all swipe variants (message pages). include_swipes: true returns ChatMessageSwiped[]. ```ts const messages = await getChatMessages("0-{{lastMessageId}}", { include_swipes: true }); ``` -------------------------------- ### Rotate messages with rotateChatMessages (example 4) Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Rotate chat messages using rotateChatMessages. This example moves the first 3 floors to the end. ```typescript // 将前 3 楼放到最后 await rotateChatMessages(0, 3, getLastMessageId() + 1); ``` -------------------------------- ### initializeGlobal 共享接口到全局 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html 在脚本中调用以将接口共享到全局,使其他 iframe 可通过 `await waitGlobalInitialized('Mvu')` 等待初始化后,以 `Mvu` 为变量名访问该接口。 ```typescript initializeGlobal('Mvu', Mvu); ``` -------------------------------- ### Rotate messages with rotateChatMessages (example 2) Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Rotate chat messages using rotateChatMessages. This example moves the last floor before floor 5. ```typescript // 将最后一楼放到第 5 楼之前 await rotateChatMessages(5, getLastMessageId(), getLastMessageId() + 1); ``` -------------------------------- ### createPreset function signature Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E5%88%9B%E5%BB%BA%E9%A2%84%E8%AE%BE.html Creates a new preset with the given name and optional content. Fails if a preset with the same name already exists or if the name is 'in_use'. Throws an exception if the preset content contains duplicate system/placeholder prompts. ```ts function createPreset(preset_name: Exclude, preset?: Preset): Promise; ``` -------------------------------- ### 查找JS-Slash-Runner文件夹 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%AE%89%E8%A3%85%E4%B8%8E%E6%9B%B4%E6%96%B0%E9%97%AE%E9%A2%98.html 在Termux中执行此命令以搜索JS-Slash-Runner文件夹。如果文件夹存在,会输出其路径,供后续删除操作使用。 ```bash find ~ -type d -name "JS-Slash-Runner" ``` -------------------------------- ### Rotate messages with rotateChatMessages (example 3) Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Rotate chat messages using rotateChatMessages. This example moves the last 3 floors before floor 1. ```typescript // 将最后 3 楼放到第 1 楼之前 await rotateChatMessages(1, getLastMessageId() - 2, getLastMessageId() + 1); ``` -------------------------------- ### initializeGlobal Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%88%86%E4%BA%AB%E6%8E%A5%E5%8F%A3.html 将接口共享到全局, 使其可以在其他前端界面或脚本中使用. ```APIDOC ## initializeGlobal ### Description 将接口共享到全局, 使其可以在其他前端界面或脚本中使用. ### Method function ### Signature ```ts function initializeGlobal(global: string, value: any): void; ``` ### Parameters - **global** (`string`) - Required - 要共享的接口名称 - **value** (`any`) - Required - 要共享的接口内容 ### Example ```ts initializeGlobal('Mvu', Mvu); // ...此后其他前端界面或脚本中可以通过 `await waitGlobalInitialized('Mvu')` 来等待初始化完毕, 从而用 `Mvu` 为变量名访问该接口 ``` ``` -------------------------------- ### SillyTavern.executeSlashCommandsWithOptions 函数定义 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%A6%E5%8F%91%E5%BF%AB%E9%80%9F%E5%9B%9E%E5%A4%8D%E5%91%BD%E4%BB%A4.html 酒馆原生的 /STScript 运行函数,返回包含中断、管道、错误等信息的对象。具体内容请参考酒馆接口或其他插件。 ```typescript function executeSlashCommandsWithOptions(command: string, options?: any): Promise<{ interrupt: boolean; pipe: string; isBreak: boolean; isAborted: boolean; isQuietlyAborted: boolean; abortReason: string; isError: boolean; errorMessage: string; }>; ``` -------------------------------- ### Get all messages used by AI Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF.html Gets all floors' messages used by the AI, from floor 0 to the last message. Uses the macro {{lastMessageId}} in the range. ```ts const messages = await getChatMessages("0-{{lastMessageId}}"); ``` -------------------------------- ### Get latest message Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF.html Gets the latest floor's message used by the AI. Uses -1 or the macro {{lastMessageId}} to reference the last message. ```ts const message = getChatMessages(-1)[0]; // 或 getChatMessages('{{lastMessageId}}')[0] ``` -------------------------------- ### getChatMessages: Get all messages with range Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Use a range string '0-{{lastMessageId}}' to get all message floors. The include_swipes option controls whether all swipes are returned. ```typescript // 获取所有楼层被 ai 使用的消息页 const chat_messages = getChatMessages('0-{{lastMessageId}}'); // 获取所有楼层所有的消息页 const chat_messages = getChatMessages('0-{{lastMessageId}}', { include_swipes: true }); ``` -------------------------------- ### SillyTavern 稳定接口类型定义 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%AE%BF%E9%97%AE%E9%85%92%E9%A6%86%E6%8E%A5%E5%8F%A3%E6%88%96%E5%85%B6%E4%BB%96%E6%8F%92%E4%BB%B6.html 定义酒馆提供给插件的稳定接口常量 `SillyTavern`,可从 https://github.com/SillyTavern/SillyTavern/blob/release/public/scripts/st-context.js#L76 查看具体内容,也可在控制台输入 `window.SillyTavern.getContext()` 查看。 ```TypeScript /** * 酒馆提供给插件的稳定接口, 具体内容见于 https://github.com/SillyTavern/SillyTavern/blob/release/public/scripts/st-context.js#L76 * 你也可以在酒馆页面按 f12, 在控制台中输入 `window.SillyTavern.getContext()` 来查看当前酒馆所提供的接口 */ const SillyTavern; ``` -------------------------------- ### getAudioSettings Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%92%AD%E6%94%BE%E9%9F%B3%E9%A2%91/%E6%92%AD%E6%94%BE%E8%AE%BE%E7%BD%AE.html 获取音频设置,返回指定类型(背景音乐或音效)的当前音频设置。 ```APIDOC ## getAudioSettings ### Description 获取音频设置,返回指定类型(背景音乐或音效)的当前音频设置。 ### Function Signature ```ts function getAudioSettings(type: 'bgm' | 'ambient'): AudioSettings; ``` ### Parameters #### `type` - **类型**: `'bgm' | 'ambient'` - **描述**: 背景音乐 ('bgm') 或音效 ('ambient') ### Return Value - **音频设置**: `AudioSettings` ### Type Definition ```ts type AudioSettings = { /** 是否启用 */ enabled: boolean; /** * 当前播放模式 * - repeat_one: 单曲循环 * - repeat_all: 全部循环 * - shuffle: 随机播放 * - play_one_and_stop: 播放一首后停止 */ mode: 'repeat_one' | 'repeat_all' | 'shuffle' | 'play_one_and_stop'; /** 是否静音 */ muted: boolean; /** 当前音量 (0-100) */ volume: number; }; ``` ``` -------------------------------- ### getChatMessages: Get latest message with negative index Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html Use negative indices to get the latest message floor. The template {{lastMessageId}} can be used as an alternative to -1. ```typescript // 获取最新楼层被 ai 使用的消息页 const chat_message = getChatMessages(-1)[0]; // 或 getChatMessages('{{lastMessageId}}')[0] // 获取最新楼层所有的消息页 const chat_message = getChatMessages(-1, { include_swipes: true })[0]; // 或 getChatMessages('{{lastMessageId}}', { include_swipes: true })[0] ``` -------------------------------- ### updateCharacterWith example: change opening lines Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for updateCharacterWith: updates the character's first_messages using an updater function. Throws if the character does not exist or backend access fails. ```ts await updateCharacterWith('角色卡显示名称', character => { character.first_messages = ['新的开场白1', '新的开场白2']; return character; }); ``` -------------------------------- ### SillyTavern.executeSlashCommandsWithOptions(command: string, options?: any): Promise<{ interrupt: boolean; pipe: string; isBreak: boolean; isAborted: boolean; isQuietlyAborted: boolean; abortReason: string; isError: boolean; errorMessage: string; }> Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%A6%E5%8F%91%E5%BF%AB%E9%80%9F%E5%9B%9E%E5%A4%8D%E5%91%BD%E4%BB%A4.html 酒馆原生的 /STScript 运行函数。具体内容请参考访问酒馆接口或其他插件。 ```APIDOC ## SillyTavern.executeSlashCommandsWithOptions(command: string, options?: any): Promise<{ interrupt: boolean; pipe: string; isBreak: boolean; isAborted: boolean; isQuietlyAborted: boolean; abortReason: string; isError: boolean; errorMessage: string; }> ### Description 酒馆原生的 /STScript 运行函数。 ### Method Function ### Signature ```ts function executeSlashCommandsWithOptions(command: string, options?: any): Promise<{ interrupt: boolean; pipe: string; isBreak: boolean; isAborted: boolean; isQuietlyAborted: boolean; abortReason: string; isError: boolean; errorMessage: string; }>; ``` ### Parameters - **command** (string) - Required - 要运行的 /STScript 命令 - **options** (any) - Optional - 选项参数 ### Return Value - **Promise<{ interrupt: boolean; pipe: string; isBreak: boolean; isAborted: boolean; isQuietlyAborted: boolean; abortReason: string; isError: boolean; errorMessage: string; }>** - 执行结果对象 ### Notes 具体内容请参考访问酒馆接口或其他插件。 ``` -------------------------------- ### errorCatched example with thrown error Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0.html Example usage of errorCatched: wraps a function that throws an error, then calls the wrapped function. The error message is displayed via a tavern notification. ```ts function test() { throw Error(`test`); } const error_catched_test = errorCatched(test); error_catched_test(); // 酒馆通知: test ``` -------------------------------- ### 删除JS-Slash-Runner文件夹 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%AE%89%E8%A3%85%E4%B8%8E%E6%9B%B4%E6%96%B0%E9%97%AE%E9%A2%98.html 使用rm -rf命令删除指定路径的JS-Slash-Runner文件夹。注意rf后面要加空格,且此操作不会显示任何提示,请谨慎使用。 ```bash rm -rf /root/SillyTavern/data/default-user/extensions/JS-Slash-Runner ``` -------------------------------- ### updateCharacterWith example: clear local regex Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for updateCharacterWith: clears the character's regex scripts using an updater function. Throws if the character does not exist or backend access fails. ```ts await updateCharacterWith('角色卡头像id.png', character => { character.extensions.regex_scripts = []; return character; }); ``` -------------------------------- ### updateCharacterWith example: change avatar Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for updateCharacterWith: sets the character's avatar to a blob fetched from a URL using an updater function. Throws if the character does not exist or backend access fails. ```ts await updateCharacterWith('角色卡显示名称', character => { character.avatar = await fetch('https://example.com/avatar.png').then(response => response.blob()); return character; }); ``` -------------------------------- ### loadPreset Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%A2%84%E8%AE%BE/%E4%BF%AE%E6%94%B9%E9%A2%84%E8%AE%BE.html 加载指定预设作为当前正在使用的预设。 ```APIDOC ## loadPreset ### Description 加载 `preset_name` 预设作为酒馆正在使用的预设 (`'in_use'`)。 ### Method Function ### Signature ```ts function loadPreset(preset_name: Exclude): boolean; ``` ### Parameters - **preset_name** (`string`) - 预设名称 ### Returns - **boolean** - 是否成功切换, 可能因预设不存在等原因而失败 ``` -------------------------------- ### replaceCharacter example: change opening lines Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for replaceCharacter: fetches a character by display name, updates its first_messages, and replaces the character card. Throws if the character does not exist or backend access fails. ```ts const character = await getCharacter('角色卡显示名称'); character.first_messages = ['新的开场白1', '新的开场白2']; await replaceCharacter('角色卡显示名称', character); ``` -------------------------------- ### 异步更新脚本(updateScriptTreesWith) Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B%E8%84%9A%E6%9C%AC/%E5%88%9B%E5%BB%BA%E5%92%8C%E4%BF%AE%E6%94%B9%E8%84%9A%E6%9C%AC.html 使用 async 回调函数和 fetch 从服务器获取配置,并基于配置启用脚本。type: 'preset' 表示预设脚本。 ```ts await updateScriptTreesWith(async (scripts) => { // 执行异步操作,例如从服务器获取配置 const config = await fetch('/api/script-config').then(r => r.json()); // 根据配置更新脚本 scripts.forEach(item => { if (item.type === 'script' && config.enabledScripts.includes(item.name)) { item.enabled = true; } }); return scripts; }, { type: 'preset' }); ``` -------------------------------- ### replaceCharacter example: clear local regex Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for replaceCharacter: fetches a character by avatar id, clears its regex scripts, and replaces the character card. Throws if the character does not exist or backend access fails. ```ts const character = await getCharacter('角色卡头像id.png'); character.extensions.regex_scripts = []; await replaceCharacter('角色卡头像id.png', character); ``` -------------------------------- ### replaceCharacter example: change avatar Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%A7%92%E8%89%B2%E5%8D%A1/%E4%BF%AE%E6%94%B9%E8%A7%92%E8%89%B2%E5%8D%A1.html Example for replaceCharacter: fetches a character by display name, sets its avatar to a blob fetched from a URL, and replaces the character card. Throws if the character does not exist or backend access fails. ```ts const character = await getCharacter('角色卡显示名称'); character.avatar = await fetch('https://example.com/avatar.png').then(response => response.blob()); await replaceCharacter('角色卡显示名称', character); ``` -------------------------------- ### 更新包管理器 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/%E5%AE%89%E8%A3%85%E4%B8%8E%E6%9B%B4%E6%96%B0%E9%97%AE%E9%A2%98.html 在Termux中执行此命令以更新包管理器,为安装git做准备。 ```bash pkg update ``` -------------------------------- ### reloadIframe example with CHAT_CHANGED event Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%85%B6%E4%BB%96%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0.html Example usage of reloadIframe: listens for the CHAT_CHANGED event and reloads the frontend when the chat file changes. Note that reloadIframe is equivalent to window.location.reload(), so any data that needs to persist after reload must be handled separately. ```ts // 当聊天文件变更时, 重新加载前端界面或脚本 let current_chat_id = SillyTavern.getCurrentChatId(); eventOn(tavern_events.CHAT_CHANGED, chat_id => { if (current_chat_id !== chat_id) { current_chat_id = chat_id; reloadIframe(); } }) ``` -------------------------------- ### getTavernHelperExtensionId Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html Gets the extension ID of the Tavern Helper extension. ```APIDOC ## getTavernHelperExtensionId ### Description Gets the extension ID of the Tavern Helper extension. ### Signature ```ts function getTavernHelperExtensionId(): string; ``` ### Parameters None. ### Return Value - **string** - The extension ID of the Tavern Helper extension. ``` -------------------------------- ### getTavernHelperVersion Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%9F%A5%E8%AF%A2%E7%89%88%E6%9C%AC.html 获取酒馆助手版本号。 ```APIDOC ## getTavernHelperVersion ### Description 获取酒馆助手版本号。 ### Method function ### Signature ```ts function getTavernHelperVersion(): string; ``` ### Return Value - **酒馆助手版本号** (string) - 酒馆助手版本号。 ``` -------------------------------- ### reinstallExtension 使用示例 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%AE%89%E8%A3%85%E9%85%92%E9%A6%86%E6%89%A9%E5%B1%95.html 重新安装酒馆助手,成功后提示并延迟刷新页面。 ```typescript const response = await reinstallExtension(getTavernHelperExtensionId()); if (response.ok) { toastr.success(`成功重新安装酒馆助手, 准备刷新页面以生效...`); _.delay(() => triggerSlash('/reload-page'), 3000); } ``` -------------------------------- ### Get all chat variables Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E5%8F%98%E9%87%8F/%E8%8E%B7%E5%8F%96%E5%8F%98%E9%87%8F.html Retrieves all chat variables and displays them in an alert dialog. ```ts const variables = getVariables({type: 'chat'}); alert(variables); ``` -------------------------------- ### getCurrentAudio Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%92%AD%E6%94%BE%E9%9F%B3%E9%A2%91/%E6%92%AD%E6%94%BE%E7%8A%B6%E6%80%81.html 获取当前播放的音频信息:链接、标题、是否在播、进度。支持背景音乐('bgm')和音效('ambient')两种类型。 ```APIDOC ## getCurrentAudio ### Description 获取当前播放的音频信息:链接、标题、是否在播、进度。 ### Function Signature ```ts function getCurrentAudio(type: 'bgm' | 'ambient'): CurrentAudio; ``` ### Parameters - **type** (`'bgm' | 'ambient'`) - Required - 背景音乐 ('bgm') 或音效 ('ambient') ### Return Value - **当前音频信息** (`CurrentAudio`) - 包含当前音频的链接、标题、播放状态和进度 ### Type Definitions ```ts type CurrentAudio = { /** 当前选中/正在播放的音频链接, 未选中曲目时为空字符串 */ src: string; /** 当前选中音频的标题, 未匹配到时为空字符串 */ title: string; /** 是否正在播放 */ playing: boolean; /** 播放进度 (0-100) */ progress: number; }; ``` ### Example ```ts // 获取当前正在播放的背景音乐信息 const { src, title, playing, progress } = getCurrentAudio('bgm'); ``` ``` -------------------------------- ### Append message at end Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%A5%BC%E5%B1%82%E6%B6%88%E6%81%AF/%E5%88%9B%E5%BB%BA%E6%B6%88%E6%81%AF.html Example: appends a user message at the end (default insert_before). ```ts await createChatMessages([{ role: 'user', message: '你好' }]); ``` -------------------------------- ### getAudioSettings 函数签名 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E6%92%AD%E6%94%BE%E9%9F%B3%E9%A2%91/%E6%92%AD%E6%94%BE%E8%AE%BE%E7%BD%AE.html 获取音频设置, 参数 type 为 'bgm' 或 'ambient', 返回 AudioSettings 对象。 ```ts function getAudioSettings(type: 'bgm' | 'ambient'): AudioSettings; ``` -------------------------------- ### 导入角色卡数据不再需要刷新网页 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%85%B3%E4%BA%8E%E9%85%92%E9%A6%86%E5%8A%A9%E6%89%8B/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.html 在检测到角色卡需要更新时,从网络链接导入新版本的角色卡。导入后不再需要刷新网页,注释掉的 toastr 和 triggerSlash 代码展示了旧方式。 ```typescript if (/** 通过某种方式检测到角色卡应该被更新, 如在一个世界书条目里、在角色卡高级定义里记录版本号, 然后检测到本地版本号比网络最新的版本号低时 */) { // 从链接更新角色卡 await importRawCharacter('角色卡名称', await fetch('最新角色卡的网络链接').then(response => response.blob())); // ⬇️⬇️⬇️不再需要刷新网页 // toastr.success('角色卡自动更新成功, 准备刷新页面以生效...'); // setTimeout(() => triggerSlash('/reload-page'), 3000); // ⬆️⬆️⬆️ } ``` -------------------------------- ### 获取当前角色卡头像路径示例 Source: https://n0vi028.github.io/JS-Slash-Runner-Doc/guide/%E5%8A%9F%E8%83%BD%E8%AF%A6%E6%83%85/%E8%AE%BF%E9%97%AE%E9%85%92%E9%A6%86%E6%8E%A5%E5%8F%A3%E6%88%96%E5%85%B6%E4%BB%96%E6%8F%92%E4%BB%B6.html 通过 `TavernHelper.getCharAvatarPath()` 获取当前角色卡的头像路径并以弹出框显示。注意:未导出到 window 对象的函数(带🚫TavernHelper标记)无法在扩展中直接通过 TavernHelper 调用。 ```TypeScript // 获取当前角色卡的头像路径 alert(TavernHelper.getCharAvatarPath()); ```