Open beta. Rin Chat is under active development. Expect rough edges, and please tell us what breaks.

Skip to content
Extension guide contents

Getting started

This walks through the kit's template from an empty folder to an extension running in a chat.

1. Install the kit

You need Node.js 22.2 or later. The kit has no other dependencies.

The kit gives you two things:

  • rinext, the command-line tool: keygen, pack, check and test.
  • @rin-chat/extension-api, the TypeScript types for the rin API and the manifest. They work from a plain .js file too, for editor completion and checking.

The commands below are written as rinext <command>. If rinext is not on your PATH, run node <kit>/bin/rinext.mjs <command> instead.

rinext keygen <out-dir>                              make an author key
rinext pack <folder> --key <private-key> [--out f]   check, sign and zip a folder into a .rinext
rinext check <file.rinext>                           what Rin Chat would show for it, or why it refuses it
rinext test <folder> [test-file]                     run it in Rin Chat's sandbox against a fake chat

Exit codes: 0 done, 1 refused or a test failed, 2 usage.

2. Copy the template

The kit's template/ folder holds a complete extension, Mood Tracker:

template/
  extension/          what ships: everything in this folder goes into the package
    manifest.json
    main.js
    README.md
  test/
    mood.test.mjs     tests, kept OUTSIDE extension/ (a package carries one script)

Copy template/ somewhere of your own, for example my-extension/.

3. Make your author key

rinext keygen ../keys

This writes ../keys/rinext-author.key (the private key) and prints a line like:

"author": { "name": "<your name>", "key": "Sn7sRBo_d9wxI4v9b7DfOicryTgX_edWCmVgeA1gEsA" }

Paste the key value into extension/manifest.json as author.key, replacing the placeholder, and set author.name. Also change id (for example com.yourname.mood) and name.

Keep the private key outside every extension folder (keygen refuses to write it inside one, since everything in the folder ships), out of version control, and backed up. Rin Chat ties your extension id to this key on the first install, so a lost key means your users cannot take your updates. See Publishing.

4. Read the template

extension/main.js registers a command, keeps a count in storage, reads its settings form and adds one line to the prompt each turn:

// @ts-check
/// <reference types="@rin-chat/extension-api" />

rin.ui.command("mood", "Set the character's mood, or clear it with no word");

rin.on("onCommand", async ({ name, args }) => {
  if (name !== "mood") return;
  await rin.chat.vars.set({ mood: args });
});

rin.on("onBeforeAssemble", async () => {
  const settings = await rin.settings.get();
  if (!settings.remind) return;
  const vars = await rin.chat.vars.get();
  const mood = vars.mood || String(settings.fallback);
  await rin.prompt.inject({ text: `The character is feeling ${mood} right now.`, depth: Number(settings.depth) });
});

(Abridged; the template's file has a few more lines.) The script's top level runs once when the extension starts in a chat; that is where hooks are registered with rin.on. After that, the script runs only inside hooks. Each permission the script uses is listed in the manifest's permissions.

5. Test it

rinext test extension test/mood.test.mjs
ok   remindsTheModelEachTurn
ok   theMoodCommandSetsAChatVariable
ok   settingsChangeTheReminder
ok   storageSurvivesReopening

4 passed, 0 failed

The tests run your script in Rin Chat's own sandbox and chat runtime, with the app's limits, against a fake chat. Without a test file, rinext test extension opens a sample chat, runs one turn, closes it, and prints the commands, the injected text and the log. Testing covers the harness.

6. Pack and check it

rinext pack extension --key ../keys/rinext-author.key

pack applies every rule Rin Chat applies to a package, checks that author.key matches your private key, signs, zips, and reads the result back the way Rin Chat will. Every problem is listed at once, each as the sentence the app would show. The output is <id>-<version>.rinext in the current directory (or --out); it may not be inside the extension folder.

rinext check com.yourname.mood-0.1.0.rinext

check prints what the install dialog will show: name, version, id, author, the key fingerprint, the SHA-256, the permission sentences and the requested hosts. If Rin Chat would refuse the package, it prints the one sentence the app shows instead.

7. Load it in Rin Chat

All of these are in Settings > Extensions.

While developing: load the folder. Turn on Trust extensions from any source (it asks twice, since nothing from a file or folder has been reviewed), then Developer mode. Press Load folder and choose your extension/ folder. A folder is read again before every hook and command, so a change to main.js or manifest.json takes effect on the next one; when the code changed, the extension restarts (its top level and onChatOpen run again, and in-memory state is gone). A folder is not signed, so author.key is not checked against a private key here.

To try the real package: install the file. With Trust extensions from any source on, press Install from file and choose the .rinext. The install dialog shows the name, version, author, the key fingerprint, the permission sentences and the hosts it asks for, marked Unreviewed. Install from URL takes an HTTPS address of a .rinext and shows the same dialog.

On the extension's row in Settings > Extensions:

  • Run test hook loads the installed script and calls its onTest hook outside any chat, then shows what it returned.
  • The extension's log shows what it wrote with rin.log and console.*. With Developer mode on, the lines also go to the developer console.
  • Its settings form, network level and log, model pick and budget, sound volume, and any theme or sampler ranges it uses are set there too.

8. Turn it on in a chat

Open a chat, open the Session info menu in the chat's top bar, and choose Extensions. Each installed extension can be turned on for This chat or for Every chat with the character (in a group chat, each member is listed). Turning it on shows the permission sentences again and says where it will run.

The extension starts at once: its top level runs, then onChatOpen. Type /mood cheerful, send a message, and open the prompt inspector: the injected line is there, labeled with the extension's name.

The same dialog shows when an extension is paused in this chat after failing three times in a row (with Resume), and offers Use its styling in this chat for one that styles the chat.

Next