From 3938b0e42716db1b25c15b689fba62c149a4cf0a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 16 Oct 2023 01:53:01 +0300 Subject: [PATCH] Update Writing-Extensions.md --- For Contributors/Writing-Extensions.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/For Contributors/Writing-Extensions.md b/For Contributors/Writing-Extensions.md index 505e546f6..a12c2c428 100644 --- a/For Contributors/Writing-Extensions.md +++ b/For Contributors/Writing-Extensions.md @@ -6,6 +6,13 @@ icon: file-added Plugins extend the functionality of SillyTavern by hooking into its events and API. You can easily create your own extensions. +## Examples + +See live examples of simple SillyTavern extensions: + +1. https://github.com/city-unit/st-extension-example - basic extension template. Showcases manifest creation, local script imports, adding a settings UI panel, and persistent extension settings usage. +2. https://github.com/SillyTavern/Extension-Variables - very simple plugin. Demonstrates the capabilities of chat metadata and handlebars custom macros. + ### manifest.json Every extension must have a folder in `public/scripts/extensions` and have a manifest.json file which contains metadata about the plugin and a JS script file. @@ -14,13 +21,14 @@ Every extension must have a folder in `public/scripts/extensions` and have a man { "display_name": "The name of the plugin", "loading_order": 1, // Optional. Higher number loads later - "requires": [], // Required Extras modules dependecies - "optional": [], // Optinal Extras dependencies + "requires": [], // Required Extras modules dependencies + "optional": [], // Optional Extras dependencies "js": "index.js", // Main JS file "css": "style.css", // Optional CSS file "author": "Your name", "version": "1.0.0", - "homePage": "https://github.com/your/plugin" + "homePage": "https://github.com/your/plugin", + "auto_update": true // If the extension should auto-update when the version of the ST package changes } ``` @@ -46,7 +54,7 @@ Use this to interact with the main app state. You can import variables and functions from other JS files. -For example, this code snipped will generate a reply from the currently selected API in a background: +For example, this code snipped will generate a reply from the currently selected API in the background: ```js import { generateQuietPrompt } from "../../../script.js"; @@ -72,7 +80,7 @@ function commandFunction(args) { } ``` -### Listening for event types +### Listening to event types Use eventSource.on() to listen for events: @@ -86,12 +94,14 @@ function handleIncomingMessage(data) { } ``` -Main event types are: +The main event types are: * `MESSAGE_RECEIVED` * `MESSAGE_SENT` * `CHAT_CHANGED` +The rest can be found [here](https://github.com/SillyTavern/SillyTavern/blob/release/public/script.js#L268). + ### Do Extras request The `doExtrasFetch()` function allows you to make requests to your SillyTavern Extra server.