Skip to content

Overview

Plugins ​

A plugin gives the assistant new tools, written in JavaScript and run in a WebAssembly sandbox that reaches only what its manifest declares.

The page of the plugin Fuel prices: its tool with the chat's cell, the widgets it brings marked accepted, and Remove from main.The page of the plugin Fuel prices: its tool with the chat's cell, the widgets it brings marked accepted, and Remove from main.
A plugin's page in demo mode.

AskWhat is the weather in Berlin? (with the SDK's weather plugin)

weather_forecast runs in the sandbox and fetches wttr.in. The first request to that host asks, as any http_read does.

AskSearch my mail for the invoice. (with the Gmail plugin)

The plugin calls http_read for gmail.googleapis.com; its Google sign-in is added on the way out, and the code never sees it.

AskSend the forecast to the team chat. (a plugin that declares only http_read)

The plugin cannot: http_write is not in its uses, so a POST from its code is refused.

What it gives you ​

  • A sandbox, not a process. The code runs in QuickJS compiled to WebAssembly, with no files, no network and no environment of its own, 64 MiB of memory and 60 seconds a call.
  • Only what it declares. uses names the built-in tools its code may call, hosts the hosts it may reach. Every call is decided by the permission tree as if the model had made it.
  • Keys it never sees. A credential is declared with its host and header; nocturn adds the value to requests to that host.
  • Typed, with no build. sdk/nocturn.d.ts types the runtime for // @ts-check; TypeScript with a bundler works too.
  • Widgets for Home. A plugin can ship widget templates.

How it works ​

Each call passes two columns: the plugin's own (ext:<name>, what installing granted) and the column of whoever the plugin works for, such as the chat.

Write a plugin ​

Start from the template in sdk/_template/.

1. Declare it ​

A plugin is a folder with plugin.json and plugin.js; the folder's name is the plugin's name.

json
{
  "name": "weather",
  "version": "1",
  "tools": [
    {
      "name": "forecast",
      "description": "Get a short one-line weather forecast for a city.",
      "parameters": {
        "type": "object",
        "properties": { "city": { "type": "string", "description": "City name, e.g. Berlin" } },
        "required": ["city"]
      },
      "target": { "type": "glob", "args": ["/city"] },
      "readOnly": true
    }
  ],
  "uses": ["http_read"],
  "hosts": ["wttr.in"]
}

The tool reaches the model as weather_forecast. target names the argument it acts on, so you can allow some cities and be asked about others.

2. Write the code ​

js
// @ts-check
globalThis.plugin = {
  tools: {
    forecast: async (args) => {
      const r = await fetch("https://wttr.in/" + encodeURIComponent(args.city) + "?format=3");
      if (!r.ok) throw new Error("weather lookup failed: " + r.status);
      return await r.text();
    },
  },
};

A tool is (args, ctx) => result. A string is returned as it is, anything else as JSON; a thrown error fails the call with its message.

3. Load it ​

sh
nocturn reload
nocturn ls -w main

The plugins: line lists weather (weather_forecast). A plugin that does not hold up is skipped, and nocturn ls names it on stderr with the reason.

4. Try it ​

Ask "What is the weather in Berlin?". Agents, voice and paired devices get none of its tools until you allow them under plugin/weather/forecast.

The runtime ​

WhatDoes
fetchGET and HEAD go through http_read, other methods through http_write; only Content-Type is forwarded
nocturn.call(tool, args)calls any tool in uses by its name, synchronously; a denied call throws
nocturn.notify, .remind, .now, .memory, .knowledge, .resolvehelpers over the common tools
fs, nocturn.fsthe workspace's mnt/ folder, through the file_* tools
ctx.settings, ctx.profilethe plugin's settings, and the profile fields it was granted
Buffer, TextEncoder, URL, btoathe usual helpers

A plugin cannot call code_run or its own tools. For TypeScript, write plugin.ts and bundle it: esbuild plugin.ts --bundle --format=iife --outfile=plugin.js.

The manifest ​

FieldMeaning
name, versionthe plugin; the folder's name wins
tools[]name (a-z0-9_-), description, parameters (an object schema), target (type: host, path, address or glob; args: JSON pointers), readOnly
uses[]the built-in tools its code may call; ["*"] for all
hosts[]the exact hosts it reaches, at most 16
credentials[]name, host, and header (with prefix) or query: a key nocturn adds
oauth[]an OAuth account: name, auth_url, token_url, client_id, scopes; connect it with nocturn auth <plugin>
settingsa form schema; each property is a setting (free text needs an enum or a uri or hostname format)
profile[]household profile fields it reads: places, language, units, timeZone
widgets[]widget templates

An unknown field is an error. A key never goes into plugin.js: declare it, then store it with nocturn secret set weather/apikey (Give a server its token).

json
"credentials": [
  { "name": "apikey", "host": "api.example.com", "header": "Authorization", "prefix": "Bearer " }
]

Settings ​

A plugin's settings show on its page under Settings, with Save settings; a credential row waits until the settings it depends on are saved. From the terminal:

sh
nocturn config fuel-prices                 # what it declares, and the values
nocturn config fuel-prices radius=5        # set one

nocturn is open source. Example hosts and people on these pages are made up.