Skip to content

Commit

Permalink
Update Writing-Extensions.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Cohee1207 authored Oct 15, 2023
1 parent b9f9ed6 commit 3938b0e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions For Contributors/Writing-Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
```

Expand All @@ -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";
Expand All @@ -72,7 +80,7 @@ function commandFunction(args) {
}
```

### Listening for event types
### Listening to event types

Use eventSource.on() to listen for events:

Expand All @@ -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.
Expand Down

0 comments on commit 3938b0e

Please sign in to comment.