# Open-WebUI plugin protocol (owpp): the guide The pages of https://zmnatz.github.io/open-webui-plugin-protocol/, in menu order. Links inside are relative to the repository https://github.com/zmnatz/open-webui-plugin-protocol. # Install `owpp` is a Python package with one dependency (PyYAML). You do not have to install it: [uv](https://docs.astral.sh/uv/) runs it straight from PyPI. ## Requirements - **[uv](https://docs.astral.sh/uv/getting-started/installation/)**. It brings its own Python, so you need no Python of your own. Without uv, Python 3.10 or newer works with `pip` or `pipx` (below). - **`git`**, for plugins that take code from another repository (`source:`), and for `owpp pull` and `owpp check --since`. - For a deploy, an **Open-WebUI** instance and a way to sign in as an admin: an API key, a user name and password, an OIDC token, or none where the instance allows it (see [signing in](commands/deploy.md#signing-in)). ## Run it ```sh uvx owpp --version # runs the latest release, nothing installed uvx owpp@0.6.1 list # a pinned release (recommended: see below) ``` `uvx owpp ` works from any folder. Every command reads the plugins folder from `--dir`, else [`$OWPP_PLUGINS_DIR`](environment-variables.md#owpp_plugins_dir), else `./plugins`. **Pin the version.** The runtime and the libraries are copied into what you deploy, so a new `owpp` changes your deployed code. Use `uvx owpp@0.6.1 ...` in scripts and CI, and move the pin as a reviewed change, the same way you would move any other dependency. ## The test extra `owpp test` runs each plugin's tests against a mock Open-WebUI. It needs pytest and the packages Open-WebUI ships (FastAPI, httpx, SQLAlchemy, aiohttp), in the `test` extra: ```sh uvx --from 'owpp[test]' owpp test ``` ## Installing it for good To have `owpp` on your `PATH`: ```sh uv tool install owpp==0.6.1 # or: uv tool install 'owpp[test]==0.6.1' pipx install owpp==0.6.1 # or with pipx pip install owpp==0.6.1 # or into a virtual environment ``` `python -m owpp` is the same command as `owpp`. ## An unreleased commit ```sh uvx --from git+https://github.com/zmnatz/open-webui-plugin-protocol@ owpp list ``` ## In GitHub Actions Nothing to install: the [action](tooling.md#github-action) sets up uv and runs `owpp` from its own checkout, so the version is the tag you pin in `uses:`. ```yaml - uses: zmnatz/open-webui-plugin-protocol@v0.6.1 ``` Next: [getting started](getting-started.md). # Getting started From an empty repository to a plugin running in Open-WebUI, deployed from git. It takes about fifteen minutes. You need [uv](install.md#requirements) and `git`. ## 1. A repository for your plugins ```sh mkdir my-plugins && cd my-plugins && git init ``` Plugins live in `plugins/`, one folder each. Nothing else is needed: `owpp` creates the folder. ## 2. Create a plugin ```sh uvx owpp create ``` A [wizard](creating.md) asks what the plugin is, one stage at a time, and writes `plugins//`: the manifest, stubs for the code, tests, a README and a CHANGELOG. Every question has a default, so pressing Enter all the way gives you a small event plugin. Nothing is written until the last stage. ``` plugins/hello/ plugin.yaml the manifest: the function's header, its tool, skills and libraries function.py the function, with every hook a stub to fill in tests/test_hello.py tests that pass against a mock Open-WebUI README.md what it does, and how to test and deploy it CHANGELOG.md one entry per version ``` Already have functions pasted into Open-WebUI? See [adopting](adopting.md) to move them into this layout. ## 3. Check and test it ```sh uvx owpp check --strict # bundle it exactly as a deploy would, compile, lint uvx --from 'owpp[test]' owpp test # its tests, against a mock Open-WebUI uvx owpp bundle hello # print the single file Open-WebUI will store ``` Now write the plugin itself: the [authoring guide](authoring.md) has the conventions, and [libraries](libraries.md) has routes, jobs, per-chat data, pages and the rest. Run `check` and `test` as you go. ## 4. Connect to Open-WebUI The deploy talks to Open-WebUI's admin API as an admin. Give it the URL, and one way to sign in: ```sh export OPEN_WEBUI_URL=https://chat.example.com # an API key: Admin Panel > Settings > General > Enable API Keys, then # Settings > Account > API keys > Create new secret key export OPEN_WEBUI_API_KEY=sk-... # or an admin's email (or LDAP user) and password export OPEN_WEBUI_USERNAME=admin@example.com OPEN_WEBUI_PASSWORD=... # or an OIDC token (the instance must set ENABLE_OAUTH_TOKEN_EXCHANGE=true) export OPEN_WEBUI_OIDC_TOKEN=... OPEN_WEBUI_OAUTH_PROVIDER=oidc ``` With none of them, it tries to sign in without credentials, which works where sign-in is switched off or a proxy adds the trusted email header. See [signing in](commands/deploy.md#signing-in), and each variable in [environment variables](environment-variables.md). Use a dedicated admin account for deploys if you can, and keep credentials out of git: environment variables here, secrets in CI. ## 5. Deploy ```sh uvx owpp deploy --dry-run # what would change, with versions; writes nothing uvx owpp deploy # create or update the functions ``` The deploy creates each function, activates it, and makes a new filter global. It only ever updates or deletes functions it deployed itself (it marks them), never ones made by hand. Then in Open-WebUI, under **Admin Panel > Functions**, your plugin is listed. Its README says what to check by hand. ## 6. Deploy from CI Commit the repository, add the credential as a secret (here a secret named `OPEN_WEBUI_API_KEY` for the `api-key` input; or `username` and `password`, or `oidc-token`; the inputs set the [environment variables](environment-variables.md#signing-in) of step 4), and deploy on every push to `main`: ```yaml # .github/workflows/deploy-plugins.yml on: push: { branches: [main], paths: ["plugins/**"] } workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest concurrency: deploy-plugins steps: - uses: actions/checkout@v5 - uses: zmnatz/open-webui-plugin-protocol@v0.6.1 with: url: https://chat.example.com api-key: ${{ secrets.OPEN_WEBUI_API_KEY }} ``` The action runs `owpp check`, then deploys, and writes the report to the job summary. See [tooling](tooling.md#github-action) for its inputs. ## 7. Change it Every change is a new version: ```sh uvx owpp version hello minor -m "Says hello in French too." # plugin.yaml and CHANGELOG.md uvx owpp check --since origin/main # fails on a change without a new version ``` A deploy refuses to put an older version over a newer one on the instance, unless given `--force`. See [deploying an older version](commands/deploy.md#deploying-an-older-version). For a plugin that takes its code from another repository, pinned to a commit, `owpp pull` moves it to the latest commit for you to review, and `owpp deploy --dry-run --latest` shows what that upgrade would change on the instance. See [`owpp pull`](commands/pull.md). ## Where next | To | Read | | --- | --- | | Pick the right kind of plugin, and see every option the wizard has | [Creating a plugin](creating.md) | | Write it well: conventions and a checklist | [Authoring a plugin](authoring.md) | | Know every key of `plugin.yaml` | [Plugin format](plugin-format.md) | | See working plugins | [Examples](../examples/plugins) | | Know what you are trusting | [Security](../SECURITY.md) | # With an AI agent `owpp` is a command-line tool with plain-text output, so a coding agent (Claude Code, Codex, Cursor and the like) drives it the way a person does: it runs the commands, reads the output and edits the files. Three things help it do that well. ## The owpp skill [`skills/owpp/`](../skills/owpp/SKILL.md) is an [agent skill](https://agentskills.io): instructions an agent loads when a task touches an Open-WebUI plugin. It walks through each kind of task (create, change, a plugin from git, deploy) with the commands to run and when each is done, and lists the rules the code is held to, such as library names being globals with no import, and the deploy waiting for the user's go-ahead. Install it with the [skills CLI](https://skills.sh/): ```sh npx skills add zmnatz/open-webui-plugin-protocol@owpp # this project npx skills add zmnatz/open-webui-plugin-protocol@owpp -g # every project ``` or copy the folder into your agent's skills folder (for Claude Code, `.claude/skills/owpp/` in the repository, or `~/.claude/skills/owpp/`). ## A plugin spec instead of the wizard `owpp create` asks questions at a terminal, which an agent cannot answer. `owpp create --spec ` takes the same answers as a YAML or JSON file (`-` reads stdin), writes the plugin and checks it: ```sh uvx owpp create --spec notes.yaml ``` The format is in [creating a plugin](creating.md#from-a-spec). ## The documentation, for a model The site publishes two files for language models, following [llms.txt](https://llmstxt.org/): - **[`llms.txt`](https://zmnatz.github.io/open-webui-plugin-protocol/llms.txt)**: what owpp is, and every page of this site with its address and a one-line summary. - **[`llms-full.txt`](https://zmnatz.github.io/open-webui-plugin-protocol/llms-full.txt)**: the whole of Getting started and the Guide as one text file, to give a model in one go. Both are generated when the site is built, from the same pages, so they never drift from it. ## In a plugins repository's `AGENTS.md` So that any agent working in the repository finds the skill and the rules, add a few lines to its `AGENTS.md` (or `CLAUDE.md`): ```markdown ## Open-WebUI plugins The plugins in `plugins/` are built, tested, versioned and deployed with owpp (`uvx owpp`). Use the owpp skill (`npx skills add zmnatz/open-webui-plugin-protocol@owpp`); without it, read https://zmnatz.github.io/open-webui-plugin-protocol/llms-full.txt first. Create plugins with `uvx owpp create --spec `, give every change a new version with `uvx owpp version patch|minor|major`, and deploy only after `uvx owpp deploy --dry-run` has been read to me. ``` ## No MCP server There is no MCP server for owpp. An agent that can run commands already has the whole of owpp through its shell, with the same output a person sees, and an MCP server would only wrap those commands again. It would also be a second place to hold deploy credentials, which today come only from the environment. A server would earn its place for an agent with no shell (a chat app with tools, say), which could check plugins or preview a deploy but could not edit a repository either. If that is how you work, [open an issue](https://github.com/zmnatz/open-webui-plugin-protocol/issues). # FAQ Short answers for newcomers. Each one links to the page that covers it in full. ## Do I need to fork Open-WebUI? No. A plugin is deployed as an ordinary Open-WebUI function, through the admin API of an unmodified instance, and that function installs its own tool and skills from inside Open-WebUI. All you need is a way to sign in as an admin. See [install](install.md#requirements) and [runtime](runtime.md). ## Can I keep my existing functions? Yes. A deploy only updates or deletes functions it marked itself (`meta.managed_by`); a function made by hand in the UI is never touched. To bring one under git, give its folder the id it already has: the first deploy updates it in place and marks it, keeping its valves and its active/global state. See [adopting](adopting.md#existing-functions-pasted-into-the-ui) and [the ownership marker](commands/deploy.md#the-ownership-marker). ## What happens when I disable or delete a plugin? In Open-WebUI, disabling or deleting the function removes what it installed: its tool and skills go, its routes and static files answer 404, and its background jobs stop. See [runtime](runtime.md) and [libraries](libraries.md#routes). The next deploy leaves a disabled function disabled, unless its manifest says `global: true`, which keeps it active on every run. A function deleted in the UI whose folder is still in the repository is created again. To remove a plugin for good, delete its folder: the next full deploy deletes the function. [`owpp deploy --only`](commands/deploy.md) never deletes, and deleting more than half of the managed functions in one run needs `--force-prune`. See [what a deploy does](commands/deploy.md#what-a-deploy-does). ## Why are version bumps reviewed? Because what you deploy runs inside Open-WebUI with admin rights. - **Code from another repository** is pinned to a full commit SHA, never a branch or tag, so it changes only when [`owpp pull`](commands/pull.md) moves the SHA. That move is a change to `plugin.yaml` that you review, with the upstream diff it links to, and commit. - **owpp itself** is pinned the same way: the runtime and libraries are copied into every bundle, so a new owpp changes your deployed code. See [upgrading](upgrading.md). - **Your own plugins** get a new version with every change ([`owpp check --since`](commands/check.md) fails on one without), so the deploy report says what moved, and a deploy refuses to go back a version without `--force`. See [versions](commands/version.md#versions). ## Does it work without CI? Yes. Every command runs from a laptop: [`owpp check`](commands/check.md), [`owpp test`](commands/test.md), then [`owpp deploy`](commands/deploy.md) with the instance's URL and an admin credential in the [environment](environment-variables.md). The [GitHub Action](tooling.md#github-action) runs the same check and deploy on every push; it is a convenience, not a requirement. Without it, nothing checks a change for you, so run [`owpp check`](commands/check.md) and [`owpp deploy --dry-run`](commands/deploy.md) before you deploy. See [getting started](getting-started.md#5-deploy). # Creating a plugin `owpp create` is a wizard that scaffolds a plugin. It asks what the plugin is, one stage at a time, and writes a folder that uses owpp with every piece in place and ready to fill in: the manifest, stubs for the code, tests and a README. ```sh uvx owpp create # asks for the id uvx owpp create my_plugin # starts with that id uvx owpp create --dir src # into another plugins folder than ./plugins ``` Its flags, and the default plugins folder ([`OWPP_PLUGINS_DIR`](environment-variables.md#owpp_plugins_dir)): [`owpp create`](commands/create.md). - **Every question has a default.** Enter takes it. Pressing Enter all the way makes a minimal event plugin, the same as `owpp init `. - **Nothing is written until the last stage.** It lists the files and asks before writing them. Ctrl-C, or the end of input, stops without writing anything. A folder that already exists is never overwritten. - **A wrong answer is asked again**, with the reason (an id with a hyphen, an event name that looks like a typo, a git URL that is a local path). - **It ends with `owpp check --strict`** on the new plugin, then lists what is left to write and the commands to run next. It is a scaffold, not a code generator. It writes the structure and the stubs: every hook, handler and tool method is a stub to fill in, and valves are left for you to add (see [what it does not ask](#what-it-does-not-ask)). ## The first branch: where the code lives After the name, the wizard asks where the code lives. The answer decides the rest of the stages. | Answer | What it is | Stages | | --- | --- | --- | | **here** | Code you write in this repository: a function (filter, action, event or pipe), or an [installer](#installers) of a tool and skills | 9 | | **git** | Code from [another git repository](#from-a-git-repository), pinned to a commit: the function itself, or a tool and skills | 6 | ## Code written here ```text ▸ Stage 3/9 · Pick the plugin type (~6 min left) The function is the plugin's parent: its tool and skills come and go with it. What kind of plugin? 1. filter changes chat requests and replies (inlet, stream, outlet) 2. action a button under a message *3. event reacts to Open-WebUI events, runs on a schedule, serves pages 4. pipe appears as a model 5. installer no code of its own: deploys a tool and/or skills 6. help not sure: ask me a few questions Choice [3] filter ``` | Stage | What it asks | What it writes | | --- | --- | --- | | 1. Name the plugin | The id, which is the folder name and the function id in Open-WebUI (lowercase, digits and `_`; it cannot change once deployed), and the title | `plugins//` | | 2. Where the code lives | here | | | 3. Pick the plugin type | filter, action, event, pipe or installer. With **help**, it asks the questions from the [authoring guide](authoring.md#pick-the-function-type-first) and picks one | `class Filter`, `Action`, `Event` or `Pipe` in `function.py`; no `function.py` for an installer | | 4. Describe it | Description, author (from `git config user.name`), version, license, oldest supported Open-WebUI (an installer skips this one) | the `function:` header in `plugin.yaml` | | 5. Type options | Depends on the type: see [below](#type-options) | the class's methods and attributes | | 6. Tool | Whether to add one, then its id, the method names, title, `access: public`, a method that shows a page in the chat, `chat_data` | `tool.py`, `tool:` in `plugin.yaml` | | 7. Skills | Each skill's name (lowercase, hyphens) and when it applies, `access: public` | `skills//SKILL.md` | | 8. Pages and libraries | A page, and who may open it; `chat_data`; a `config.yaml`; for an event, `assets/` and `live_reload` | the files, and `include:` | | 9. Review and write | Yes or no | the folder, then `owpp check --strict` | ### Type options | Type | Asks | Writes | | --- | --- | --- | | **filter** | Which hooks: `inlet` (once per user turn), `request` (every call to the model, tool loops included), `stream` (each chunk), `outlet` (the finished reply). A user toggle. If it is not a toggle, when to make it global. `file_handler`. A `priority` valve | one stub per hook. A toggle sets `self.toggle = True` and `global: false`. `self.file_handler = True` | | **action** | Several buttons, each with an id and a name. Global. A page (HTML) shown above the message. A `priority` valve | `actions = [...]` and an `action()` that branches on `__id__`; status events through `__event_emitter__`; `templates/embed.html` returned as an inline `HTMLResponse` | | **event** | A scheduled sync, and its default interval. The events to handle, from the known list plus any others | `class Event(PluginScheduledSync)` with `sync()`, and `jobs: sync_every_minutes: ${_SYNC_MINUTES:-60}`. One `@on(...)` handler per event (`own=True` for `function.*` events), on `PluginEvents` | | **pipe** | Several models (a manifold), each with an id and a name. Streaming | `pipes()` and `pipe()`, and a chunk generator when it streams | | **installer** | Nothing: its function is generated | nothing | ### Tools A tool written here gets a `tool.py` with one stub per method name. Each stub has a typed `query: str` parameter, a docstring with a `:param` line, and status events, so `owpp check --strict` passes before you change it. Rename the parameters and describe them for the model. The docstring and the type hints are what the model reads. A method that shows a page returns `templates/tool.html`, read with `plugin_template_text()`, as an inline `HTMLResponse`: the tool asks for the templates with `include: [templates]` under `tool:`. `access: public` lets every signed-in user use the tool. Without it, only admins can. ### Skills A skill gets `skills//SKILL.md` with Open-WebUI's front matter (`name`, `description`, and `access` when public) and the sections of its [skill authoring layout](https://docs.openwebui.com/features/workspace/skills): When to Use, Prerequisites, How to Run, Quick Reference, Procedure, Pitfalls, Verification. Put supporting files beside it. The whole folder is installed. ### Pages and libraries | Choice | Writes | | --- | --- | | A page served as it is | `static/index.html`, served at `//` to signed-in users, or with `static: {access: admin \| public}` to admins or to anyone | | A page the function renders | `templates/page.html`, and a route mounted with `plugin_mount` at `//`. The access is marked on the handler (`PluginUser`, `PluginAdmin`) or on the mount (`access="public"`). An event mounts it on startup, enable, update and saved valves. Other types mount it when they load | | `chat_data` | `include: [chat_data]` and a `CHAT_KEY` for `plugin_chat_read` and `plugin_chat_write` | | `config.yaml` | the file, with one setting read from `${_GREETING:-Hello}`, and `_settings()` reading it with `plugin_config()` | | `assets/` (events) | `assets/loader.js` and `assets/custom.css`, `class Event(PluginAssets)`, and `asset_vars()` | | `live_reload` | `include: [live_reload]` | A public page is allowed, with a warning, and `owpp check` lists it as a `note`. See [libraries](libraries.md) for each one. ## Installers An **installer** is a plugin with no code of its own: only a tool, skills, or both. It is how this protocol deploys tools and skills. There is no `function.py`. The bundler generates the parent function, a global filter that installs the tool and skills when it is enabled and removes them when it is disabled or deleted. It has three valves: `INSTALL_TOOLS` and `INSTALL_SKILLS` (off removes that part) and `TOOL_VALVES` (valves to set on the tool). See [runtime](runtime.md). ``` plugins/my_kit/ plugin.yaml function: header and global: true, tool: tool.py skills/my-skill/SKILL.md README.md tests/test_my_kit.py ``` The tool stage defaults to yes for an installer. If it has no tool, the skills stage asks for at least one skill. ## From a git repository ```text ▸ Stage 3/6 · The repository (~3 min left) The plugin takes its files from this repository at one commit, so what is deployed never changes until you move the commit yourself. Git URL (https://, ssh:// or user@host:path) https://github.com/Classic298/open-webui-plugins.git Branch, tag or commit SHA [main] ✓ main is commit 917c88f3029c0c6500139ba7b7b061f358d8aaea Folder in the repository the files are in (Enter for the root) inline-visualizer-v2 ``` | Stage | What it asks | | --- | --- | | 1. Name the plugin | The id and title | | 2. Where the code lives | git | | 3. The repository | The URL (https, ssh or `user@host:path`; never a local path). A branch, tag or commit: a branch or tag is looked up with `git ls-remote` and pinned to its full commit SHA, and recorded as `branch:` or `tag:` for [`owpp pull`](commands/pull.md), whichever the repository says it is (it asks you when it cannot tell); if the lookup fails (offline, a private repository, no such ref) you type the SHA. The folder in the repository the files are in | | 4. What it takes | The function itself (its file, taken verbatim with its header). A tool (its file and id). Skills (each one's id, and its folder or its `SKILL.md`). `access: public` for the tool and each skill | | 5. Describe it, or Global? | Without the function, it is an installer and asks for its header. With the function, the header comes from the file, and the only question is whether to make it global (filters and actions only) | | 6. Review and write | Yes or no | It writes no code, only `plugin.yaml`, a README and tests: ```yaml # plugin.yaml protocol: "0.5" source: git: "https://github.com/Classic298/open-webui-plugins.git" ref: 917c88f3029c0c6500139ba7b7b061f358d8aaea path: inline-visualizer-v2 branch: main function: title: Viz ... global: true # Open-WebUI loads it at startup, so it installs the rest tool: id: viz file: tool.py access: public skills: visualize: file: SKILL.md access: public ``` The README states where the code comes from, the pinned commit and how to upgrade it: `owpp pull ` moves `ref` to the latest commit and lists the files that changed, and you review the diff before committing. The tests fetch the pinned files, so they need the network. The test file says how to load the plugin with stand-ins instead (`owui.load(plugin_dir, sources={...})`), as [`inline_visualizer`](../examples/plugins/inline_visualizer) does. See [bundling: git sources](bundling.md#git-sources). ## What it writes, in every case - **`plugin.yaml`**, with comments that say where each part goes. - **`CHANGELOG.md`**, with an entry for the first version (not for an upstream function, whose versions are the upstream's). [`owpp version`](commands/version.md) adds the next ones. - **`README.md`**, with the sections the [authoring guide](authoring.md#documentation-the-readme-every-plugin-has) requires: a description, settings, `## Test` and `## Deploy`. - **`tests/test_.py`**, with one test per part: the valves, the type's entry point (a chat through the filter, the action's button, the pipe's models, startup), the tool and each method, the skills, the page and who may open it, the config. Each test has the docstring and the `By hand:` steps that [testing](testing/writing.md#describe-every-test) asks for. Every combination is checked in this repository's tests (`tests/test_create.py`): it bundles, compiles, has no `owpp check --strict` warnings, and passes the tests it writes. ## What it does not ask These are left to edit in the files, because they depend on what the plugin does: - **Valves.** `Valves` has `ENABLE` (and `priority` if you chose it), plus a comment pointing to [Open-WebUI's valve docs](https://docs.openwebui.com/features/extensibility/plugin/development/valves) for dropdowns, sliders and masked fields. Filters, actions and pipes also get an empty `UserValves`. Give each valve a description: `owpp check` warns about one without. - **Header keys** such as `icon_url` (an action's button, a toggle's chip), `requirements` (pip packages installed when the function is saved) and `funding_url`. Add them under `function:` in `plugin.yaml`. - **Tool parameters.** Every method starts with `query: str`. - **`shared.py`**, `include:` libraries it did not offer (`jobs` without a sync, `routes` without a page), and `jobs: adopt_markers`. ## After it is written ```sh owpp check my_plugin --strict # clean right away; keep it clean uvx --from 'owpp[test]' owpp test my_plugin # the tests it wrote owpp deploy --only my_plugin --dry-run # then without --dry-run ``` Then follow the [authoring guide](authoring.md): its conventions and its checklist. ## From a spec `owpp create --spec ` asks nothing: the file says what the wizard would have asked, as YAML or JSON (`-` reads it from stdin), and it writes the plugin and checks it. It is for scripts and [AI agents](ai-agents.md). An id on the command line wins over the file's. ```yaml id: notes type: filter # filter | action | event | pipe | installer | upstream description: Keeps notes on the chat. hooks: [inlet, outlet] toggle: false tool: {id: notes, methods: [save, search]} skills: - {id: take-notes, description: Use when the user asks to remember something.} page: rendered page_access: admin chat_data: true ``` The keys are those of `PluginSpec` (below), with `tool`, `skills` and `source` as mappings and `buttons` and `models` as lists of ids or `{id, name}`. `global` may be written for `global_`. A key it does not know is refused, so a typo is never a silent default. The full list, with a plugin from git, is in the [owpp skill's spec reference](../skills/owpp/references/spec.md). ## From code The wizard only collects answers. `owpp.create` writes the folder from a `PluginSpec`, with no questions asked: ```python from owpp.create import PluginSpec, SkillSpec, ToolSpec, write_plugin write_plugin( "plugins", PluginSpec( id="notes", type="filter", hooks=["inlet", "outlet"], tool=ToolSpec("notes", methods=["save", "search"]), skills=[SkillSpec("take-notes", "Use when the user asks to remember something.")], ), ) ``` `render(spec)` returns the files as `{path: text}` without writing them. Both refuse a spec that would not work, such as a hyphen in the id, `global` on an event, or `assets/` on anything but an event, with an `OwppError` that says why. # Authoring a plugin ## Start with `owpp create` ```sh uvx owpp create ``` A wizard that scaffolds the plugin: code written here (a filter, action, event or pipe, or an installer of a tool and skills) or taken from a git repository pinned to a commit, with stubs, tests and a README ready to fill in. See [creating a plugin](creating.md). ## Pick the function type first The type decides how the function runs and whether `global` applies (see the table in [plugin format](plugin-format.md#function-type)). - Does it change a chat request or reply, or add something to a message? **Filter.** - Is it a button the user presses on a message? **Action.** - Does it react to Open-WebUI itself (startup, enable, valve change), run on a schedule, or serve its own routes with no chat involved? **Event.** Events do not use `global`. - Is it a model? **Pipe.** A plugin that serves HTTP routes from a **filter** (Excalidraw) mounts them when the filter loads, which for a global filter is at startup. One that serves routes from an **event** mounts them on `system.startup.completed`, `function.enable_started`, `function.updated` and `function.valves_updated`. ## Conventions every plugin follows 1. **One function class**, one of `Pipe`, `Filter`, `Action`, `Event`. 2. **Every file imports what it uses**, as ordinary Python: the libraries `from owpp.lib import ...`, `shared.py`'s names `from shared import ...` ([bundling](bundling.md#imports-between-the-files)). 3. **Header in the manifest**, not in the code, for code that lives in the repo. Keep long text in a comment, not the header. 4. **Valves are `UPPER_SNAKE`**, each with a description (`owpp check` warns about one without). A sync-style event has `ENABLE` and `SYNC_INTERVAL_MINUTES` (default 60, 0 = only on events) and subclasses `PluginScheduledSync`. 5. **Use the libraries, do not copy them.** Routes go through `plugin_mount`, repeating work through `plugin_every`/`PluginScheduledSync`, per-chat data through `chat_data`, static files through `static/`, pages it renders through `templates/`, "am I still enabled" through `plugin_is_active`, stored valves through `plugin_stored_valves`. 6. **One page means one file.** A page that is just a file, with its assets, goes in `static/` (index at `/`). A page that needs per-request data or a per-resource check is a file in `templates/`, which the function reads with `plugin_template_text()` and renders behind a guarded route; it is never served raw. HTML does not live in Python strings. 7. **Handle events with `@on`.** `include: [events]`, `class Event(PluginEvents)` and `@on("function.valves_updated", own=True)` on a method, not an `event()` of `if __event_name__` checks; `owpp check` catches a mistyped event name. 8. **Stop when disabled.** Routes answer 404 (the `plugin_mount` guard), jobs stop by themselves, installed tools and skills are removed by the runtime. 9. **Own only what you made.** Mark what a sync writes (`managed_by`) and touch only that. 10. **Log with a fixed prefix** (`"My Plugin: ..."`) so a plugin's lines can be found. 11. **Public is deliberate.** Every route needs a signed-in user. Mount with `plugin_mount`, which enforces that, `static/` files included, and mark a route that exposes other users' data `user: PluginAdmin`. Serving people who are not signed in takes `access="public"` on a mount of its own (or `static: {access: public}`), in those exact words; `owpp check` lists each one, so keep them few. An admin route is marked on the handler: `async def purge(user: PluginAdmin)`; a mount where every route is admin-only uses `plugin_mount(..., access="admin")`; the static files use `static: {access: admin}`. A route about one chat takes `chat_id: WritableChat` or `ReadableChat`, which checks that this user can reach that chat. Whatever those cannot express is still the function's, using the `user` it is given. 12. **Third-party code is pinned** by full commit SHA and reviewed before the SHA moves (`owpp pull` moves it; you review and commit). ## Steps 1. `owpp create` (or `owpp init --type event|filter|action|pipe`, or write `plugins//plugin.yaml` with a `function:` section and `function.py` by hand). 2. Add `tool.py`, `shared.py`, `skills/`, `static/`, `templates/` or `include:` only when needed. 3. `owpp check ` until it is clean. 4. Add tests ([writing a test](testing/writing.md): through the mock, or `plugin_source()` for pure logic; keep Open-WebUI imports inside the functions that use them) and note any live checks in the README. 5. Write the README (below). `owpp init` starts one with the required sections. 6. `owpp deploy --only --dry-run`, then deploy (or merge, if CI deploys). ## Documentation: the README every plugin has Required headings (`owpp init` writes them; add a test like the example repo's if you want them enforced): - A description: what it does, which libraries it uses, what it changes in Open-WebUI. - Settings: valves and any environment variable or external setup the deploy cannot do. A plugin that shows a page in the Artifacts panel states that it needs **iframe Sandbox Allow Same Origin**, and what that costs ([libraries](libraries.md#pages-in-the-artifacts-panel-need-iframe-sandbox-allow-same-origin)). - **`## Test`**: how to check it offline (`owpp check `, `owpp bundle `), what your tests cover, and the steps to verify it on a live Open-WebUI. - **`## Deploy`**: its function type, how it gets deployed (CI on merge, or `owpp deploy --only `), and prerequisites. For a plugin taken from git, also say where it comes from, the pinned commit, and how to review an upgrade. ## Checklist - [ ] exactly one function class; `global` only on a filter or action - [ ] header keys in `plugin.yaml`, one line each - [ ] libraries via `include:` and `from owpp.lib import ...`, no pasted copies - [ ] every file imports what it uses - [ ] disabling the function stops its routes and jobs - [ ] `owpp check ` passes - [ ] README has Test and Deploy sections - [ ] data-exposing routes are gated - [ ] a page in the Artifacts panel: README states the same-origin requirement and its cost - [ ] remote code pinned to a full SHA - [ ] a change has a new version (`owpp version patch`, and a CHANGELOG.md entry); `owpp check --since origin/main` passes # Plugin format ## Folder ``` plugins// plugin.yaml required function.py the function (omit it for a plugin that is only a tool and skills) tool.py the tool shared.py code both use: they `from shared import NAME`, and it is placed in front of each skills// SKILL.md plus any supporting files, installed as a whole folder static/ files served as they are, to signed-in users unless `static:` says otherwise; index.html is the plugin's page templates/ files the function (or a tool that includes templates) renders itself; embedded, never served assets/ loader.js and custom.css: this plugin's fragments of the shared /static files config.yaml structured settings shipped with the plugin; read with plugin_config() README.md required in practice: see "Documentation" in the authoring guide ``` A plugin may also be a single `.py` (a function with no tool or skills). The **function id is the folder (or file) name** and must match Open-WebUI's id rule: lowercase, `[a-z_][a-z0-9_]*`. Hyphens are not allowed, so `my-plugin.py` becomes `my_plugin/`. ## `plugin.yaml` All sections are optional except that a tool or skills need a `function:` section: the function is the parent. The current protocol version is `0.5`. ### `protocol:` ```yaml protocol: "0.5" # the version of the plugin format this manifest was written for ``` A quoted major.minor string that tracks owpp's major.minor. It changes only when a release changes what a manifest key means, takes one away, or changes how the plugin's code must be written (0.5: every file imports what it uses); there was no 0.4, because owpp 0.4 changed nothing; `owpp init`, `owpp create` and the examples in this repository write `protocol: "0.5"`. It is a manifest key: unlike `function:`'s keys, it is not copied into the deployed header. - **Write the quotes.** Unquoted `0.5` is a YAML number and is refused, as is a patch version such as `"0.5.0"`. - A **newer** version than the owpp reading the manifest is refused: its keys may mean something else. Upgrade owpp first. - An **older** version is accepted; `owpp check` prints a note pointing at the migration. A manifest with **no key** is a 0.1 plugin, from before the key existed: `owpp check` warns and `owpp check --strict` fails. - [`owpp migrate`](commands/migrate.md) brings old plugins up to 0.5, one version step at a time: 0.1 -> 0.2 adds the `protocol:` line, 0.2 -> 0.3 turns `source: track:` into `branch:` or `tag:`, and 0.3 -> 0.5 gives each file the imports it used to do without. See [upgrading owpp](upgrading.md). ### `function:` Header keys become the docstring Open-WebUI reads as the function's manifest, one `key: value` per line, written in the order given. | Key | Meaning | | --- | --- | | `title`, `author`, `author_url`, `funding_url`, `version`, `license`, `description`, `required_open_webui_version`, ... | Written into the header verbatim. Every value must fit on one line. | | `global` | Read by the deploy script only. `true`: keep the function active and global on every run. `false`: never make it global, and take it out of global on every run: for a filter that each user switches on (a toggle). Left out: a new filter is made global once, on first deploy. Filters and actions only; an event or pipe with `global: true` is refused. | | `valves` | `{name: value}` applied after deploy, for the declared keys only. | | `file` | With `source:`, take the function from the git repo verbatim, header included. Then no header keys are allowed (they come from the file). | Open-WebUI reads the header line by line, split at the first colon. It is not YAML, so `author: @someone` is fine, and a block value such as `description: >` is stored as `>` and the following lines are lost. The loader refuses such a header. ### Function type A function has one type, decided as Open-WebUI decides it, by the class defined at the top level of the code: `class Pipe`, `class Filter`, `class Action` or `class Event`. Defining none or more than one is an error. The type is shown by `owpp list` and in the deploy report, and it governs `global`: | Type | Runs | `global` | Typical use | | --- | --- | --- | --- | | **filter** | On every chat completion (`inlet`/`outlet`/`stream`), for the models it is attached to, or all models when global. May be a user toggle (`self.toggle = True`). | yes | Change the request or reply, add artifacts, attach files | | **action** | A button under a message | yes | User-triggered operations | | **event** | On Open-WebUI lifecycle events (`system.startup.completed`, `function.enable_started`, `function.valves_updated`, ...), not tied to a chat | **no** | Sync jobs, schedulers, routes, dashboards | | **pipe** | Appears as a model | no | Custom model backends | A new filter is made global on first deploy (a filter that is not attached to a model does nothing), unless it says `global: false`; `global: true` additionally re-asserts active+global on every run, and `global: false` keeps it out of global. ### `tool:` | Key | Meaning | | --- | --- | | `id` | Tool id. | | `title`, `description`, and other header keys | Header of the tool bundle (code in `tool.py`). | | `file` | With `source:`, take the tool from the git repo verbatim. | | `from: function` | Install the function's own bundle as the tool (one module serving as both). | | `access` | `public` makes it readable by every signed-in user when first installed (Open-WebUI's `user:*` read grant); later changes in the UI are kept. Without it, only admins can use the tool. | | `valves` | `{name: value}` enforced on every sync, for the declared keys only, validated against the tool's `Valves` class (a value it rejects is logged and skipped). | | `include` | Libraries for the tool bundle (the function's `include:` does not apply to it). | | `templates` | With `include: [templates]`, the files of `templates/` the tool embeds: a path, or a folder written with a trailing `/` (`[launcher/]`). Left out, the tool embeds every template. An entry that matches no file is refused. | ### `skills:` ```yaml skills: my-skill: file: SKILL.md # or: dir: skills/my-skill (the whole folder) access: public ``` Local skills are the folder `skills//`; a local skill sets its `access` in its SKILL.md front matter (`access: public`), as `owpp create` writes it. From a `source:` a skill is a `file:` or a `dir:`. A skill's `access` works like a tool's. **Earlier copies of the runtime (portainer's, before it moved to owpp) granted `public` items to Open-WebUI's `anyone:*` audience.** That is the no-auth audience Open-WebUI uses for shared chats, and its tool and skill access checks ignore it, so only admins could use them. The runtime now swaps exactly that grant for `user:*` on the next sync of an item it installed, and leaves every other grant as the admin set it. ### `source:` ```yaml source: git: https://github.com/owner/repo.git # https, ssh, or user@host:path ref: 917c88f3029c0c6500139ba7b7b061f358d8aaea # full 40-character commit SHA path: subfolder # "" for the repo root branch: main # optional: the branch `owpp pull` follows (or tag:) ``` Makes `tool: {file}`, `function: {file}` and `skills: {: {file|dir}}` read from that repo at that commit. See [bundling](bundling.md#git-sources). `ref` can be left out while writing the manifest: [`owpp pull`](commands/pull.md) looks up the latest commit and adds the line. Until it does, `owpp check` and `owpp deploy` refuse the plugin. `branch` or `tag` (one of them, not both) is read only by [`owpp pull`](commands/pull.md), which moves `ref` to the latest commit of that branch, or to the commit of that tag. With neither, `owpp pull` follows the repository's default branch. They never change what is deployed: only `ref` does. A name is a branch or tag name as git allows it, never something git would read as an option. #### A whole plugin from git When the folder at `path` is an owpp plugin itself (it has a `plugin.yaml`, like the [examples](../examples/plugins)), take all of it with `plugin: true`: ```yaml protocol: "0.5" source: git: https://github.com/zmnatz/open-webui-plugin-protocol.git path: examples/plugins/excalidraw plugin: true # then: owpp pull excalidraw, which adds ref: ``` owpp fetches the folder at the pinned commit and bundles it like a local plugin, with the upstream's `plugin.yaml`. The local folder's name is the plugin's id. Besides `protocol:` and `source:`, the local manifest can only set: | Key | Effect | | --- | --- | | `function: {valves, global}` | `valves` are merged into the upstream's, key by key; `global` replaces it. | | `tool: {id, access, valves}` | Each replaces the upstream's. | | a `config.yaml` file | Used instead of the upstream's. | Anything else is refused, skills included: they are installed as the upstream wrote them. Its versions are the upstream's (`owpp version` refuses to change them), and `owpp pull` moves the commit without bumping one. The upstream manifest's `protocol:` is checked like a local one. An upstream plugin may take files from git itself, which are fetched too, but not a whole plugin. Nothing in the folder is run: no build script, no `package.json` script. Its `tests/` run only with [`owpp test --upstream`](commands/test.md). ### `include:` `include: [core, routes, jobs, events, chat_data, shared_assets, live_reload]`: libraries inserted into the function bundle. `static` by a `static/` folder, `templates` by a `templates/` folder, `assets` by an `assets/` folder and `config` by a `config.yaml`; `core` is added by `routes`, `jobs` and `public`. See [libraries](libraries.md). ### `requires:` ```yaml requires: iframe_sandbox_allow_same_origin: true ``` Instance settings the plugin needs but cannot set itself. `owpp deploy` reads the instance's admin config before writing anything and adds a **warning** to its report when one is missing; it never changes the setting or refuses the deploy. `iframe_sandbox_allow_same_origin: true` means Open-WebUI's **iframe Sandbox Allow Same Origin** must be on: without it a sandboxed artifact sends no session to a plugin page. Why, what turning it on costs, and how: [pages in the Artifacts panel](libraries.md#pages-in-the-artifacts-panel-need-iframe-sandbox-allow-same-origin). Unknown requirement names and values that are not `true`/`false` are refused. ### `jobs:` ```yaml jobs: sync_every_minutes: ${MCPO_SYNC_MINUTES:-60} # a number, or an environment template adopt_markers: [mcpo-sync] # optional: an earlier sync's markers ``` Used with `PluginScheduledSync` (the `jobs` library, which the key brings in). The library adds the `ENABLE` and `SYNC_INTERVAL_MINUTES` valves to the function's `Valves`, and `sync_every_minutes` is the interval's default (`0` repeats nothing: only startup, enable and valve changes). See [libraries: jobs](libraries.md#jobs). `adopt_markers` is for **moving from another sync**. A sync marks what it writes with its function id (`managed_by`) and replaces or prunes only entries with that mark, so entries an earlier sync wrote under another marker would be left behind. Listing that marker here makes them count as this sync's own: `plugin_sync_markers()` returns the function id plus these. It is a list of exact markers, checked by `owpp check`; leave it out to adopt nothing. It belongs here, not in a valve, because which sync this one succeeds is decided by the deployment, in git, and a valve is for an admin to change in the UI: a marker typed there by mistake would make the sync prune another sync's entries. Remove it once the old entries have been taken over, or keep it; it does nothing more once none carry the old mark. ### Environment templates Where a value is data the plugin reads (`jobs.sync_every_minutes`, and any value in `config.yaml`), it may be `${NAME}` or `${NAME:-default}` instead of a literal. Write it in block style (`key: ${NAME:-60}`), because a `}` ends an inline `{...}` mapping. - **Read when the plugin loads inside Open-WebUI, from the container's environment, never when `owpp` bundles or deploys.** The template is embedded as written. A bundle therefore depends only on the plugin folder: the same bundle comes out on every machine whatever it has set, and nothing from a CI environment is baked into the code Open-WebUI stores. The environment variable is set on the Open-WebUI container. - A value that is one template is typed (`${N:-60}` is the number 60, `${FLAG:-true}` a boolean); inside a longer string it is text. `$${` writes a literal `${`. - Unset or empty uses the default. With no default the value is absent (null), with a warning in the Open-WebUI log. A `jobs` interval that is not a whole number of minutes falls back to 60 with a warning. - **It is the way to keep a secret out of git**: write `api_key: ${MY_PLUGIN_API_KEY}` in `config.yaml`, never the key. - `owpp bundle` and `deploy` check the syntax (`${}`, `${N:60}` and similar are refused), and **`owpp check` lists the variables a plugin reads** and their defaults (`env MCPO_SYNC_MINUTES (default 60)`). - Not applied to `function.valves`: those are set by `owpp deploy` through the API, once, with the literal value written. ### `static:` and the `static/` and `templates/` folders ```yaml static: prefix: /my_plugin # default: / access: admin # user (default), admin or public ``` Optional. **`static/`** holds files that are served as they are, at `/`. Every file needs a signed-in user unless `access` says otherwise: `admin` restricts them to admins, and **`public`**, in exactly that word, serves people who are not signed in. Any other value (`none`, `Public`, `true`, ...) is refused. `owpp check` lists a public folder as a `note`. **`templates/`** holds files the function renders itself, such as a page it fills in for the signed-in user. They are embedded and never served, so there is no key for them: read one with `plugin_template_text()`. See [libraries: static](libraries.md#static) and [templates](libraries.md#templates). `public/` and `public:` no longer exist: the folder is `static/`, what `dynamic:` used to list is `templates/`, and a manifest or folder with the old names is refused with a message saying where everything went (silently ignoring `public: {access: admin}` would leave a folder open to every signed-in user). A route's own level is set in code, with a marker on the handler; see [libraries: routes](libraries.md#routes). (Not related to a tool's `access: public`, which is Open-WebUI's own visibility for the installed tool.) **Only the keys listed in this document are accepted at the top level of `plugin.yaml`**; anything else is an error with a suggestion, so a typo cannot be silently ignored (keys starting with `x-` are left alone). ### `assets:` and the `assets/` folder ```yaml assets: order: 0 # lower composes first; in custom.css later plugins win a conflict (default 0) wrap: true # run loader.js in its own strict-mode function with a try/catch (default true); write only its body ``` Optional. The folder is what matters: `assets/loader.js` becomes this plugin's fragment of `/static/loader.js` and `assets/custom.css` its fragment of `/static/custom.css`. Nothing else may be in `assets/`: the [Shared Assets Protocol](https://github.com/Classic298/open-webui-plugins/tree/main/shared-assets-protocol) has just those two files. A `__NAME__` in either file is filled from the function's `asset_vars()`. With no `function.py` an `Event` is generated; with one, it must be `class Event(PluginAssets)`. See [libraries: assets](libraries.md#assets). ### `config.yaml` Structured settings that ship with the plugin, read by the function with `plugin_config()`. See [libraries: config](libraries.md#config). ## Example: a plugin with every part ```yaml protocol: "0.5" function: title: Excalidraw author: you version: 3.1.0 global: true required_open_webui_version: 0.10.0 license: MIT description: A shared drawing per chat, opened in the Artifacts panel. tool: id: excalidraw title: Excalidraw include: [chat_data] access: public include: [routes, chat_data] ``` with the page in `templates/viewer.html`, which needs no manifest entry. # Bundling Open-WebUI keeps a function or tool as one string of code, so the deploy turns a plugin folder into one file per function and per tool. ## Order A bundle is always, in this order, with no numbering or naming scheme to maintain: 1. **Docstring header**, generated from the manifest's `function:` (or `tool:`) keys. (With `function: {file}` the upstream file's own header is kept.) 2. **`from __future__` lines** found anywhere below, hoisted here (they are a SyntaxError after other code). 3. **Libraries** from `include:`, in the library order (`live_reload`, `shared_assets`, `core`, `routes`, `jobs`, `chat_data`, `static`, `templates`, `assets`, `config`; `assets` adds `shared_assets` and `core`). A library is skipped if its end marker is already in the code (an upstream function that ships its own copy). 4. **`shared.py`**, if present. 5. **`function.py`** (or **`tool.py`**). 6. **The plugin runtime**, when the plugin has a tool or skills, with the tools and skills embedded as a JSON literal. A function bundle and a tool bundle are separate Open-WebUI modules. They share code through `shared.py` (each gets a copy) and, where state must be shared, through `sys.modules` (the `chat_data` library does this for temporary chats). ## Imports between the files Each file imports what it uses, as in any Python project, so it reads, lints and type-checks on its own ([why](adr/0002-plugin-source-is-python.md)). That includes the plugin's own code: ```python # function.py import json from shared import PREFIX, _load ``` `from shared import ...` resolves in an editor and in tests. The bundle has no `shared` module: shared.py is already above the file, so the bundler removes the line. The same goes for `from owpp.lib import ...`: the libraries are inlined above, and Open-WebUI has no owpp ([libraries](libraries.md)). Removing an import is only safe for some forms, and the bundler refuses the others, naming the line: - **Only a top-level `from shared import NAME` or `from owpp.lib import NAME`.** Not `import shared` or `import owpp.lib`, not `*`, and not an import inside a function. - **No `as`.** Once the line is gone, an alias would be undefined. - **The name must be defined in shared.py**, or be one owpp.lib exports. A library name also needs its library in the bundle (`include:`, or `tool.include` for the tool), and a name from the [runtime](runtime.md) needs a tool or skills. - **No name both in shared.py and in the file.** They become one namespace, so one would replace the other. Importing the same module in both (`import json`) is fine. - **`function.py` and `tool.py` cannot import each other.** They are bundled into separate modules. Move what both need into shared.py. ## `{{file:NAME}}` (deprecated) In `function.py` or `tool.py`, `{{file:NAME}}` is replaced by the text of the sibling file `NAME`. It still works, but `owpp check` warns about it: it substitutes text into the source, so the file does not read as the Python that runs. Put the file in `templates/` and read it with `plugin_template_text("NAME")` instead ([templates](libraries.md#templates)); a tool adds `include: [templates]` under `tool:`. Files served over HTTP go in `static/`. ## Tool bundles carry the runtime too A tool bundle includes the runtime with **only the ids to remove**, so a tool that loads after a restart can notice its parent function was disabled while Open-WebUI was down, and remove itself. ## Git sources ```yaml source: { git: https://github.com/owner/repo.git, ref: <40-char SHA>, path: dir } ``` - `git` is an https URL, an ssh URL or `user@host:path`, read with the `git` CLI (so any host works and ssh deploy keys need no new secret). Only the `https` and `ssh` protocols are allowed. - `ref` must be a **full commit SHA**. A branch or tag can move, and this code runs with admin rights, so anything else is refused. Upgrading is a reviewed change of the SHA: [`owpp pull`](commands/pull.md) makes it, and lists the files that changed. - The files are fetched before bundling by a shallow fetch of that exact commit into a scratch repository, then embedded, so the deployed bundle is reproducible from the repo, the pinned commit and the owpp version that bundles it. - With `plugin: true` the whole folder at `path` is fetched and bundled as a local plugin would be, by the owpp reading the manifest. See [a whole plugin from git](plugin-format.md#a-whole-plugin-from-git). - Directory entries (`dir:`) list the directory in that commit and take every regular file. Symlinks and submodules are skipped. Limits: 1000 files per skill, 2 MB per file. A file that is not UTF-8 is embedded as base64. Different plugins may pin different commits of the same repo; one fetch is made per `git#sha`. ## Skills A skill is installed as its whole folder, as Open-WebUI stores it (a `files` list: `SKILL.md` plus references, templates, examples). `SKILL.md` is stored verbatim, front matter included; `name` and `description` come from that front matter. An update sends the whole file set with the skill's current version (`expected_version_id`); a skill whose files and name already match is left alone. ## Assets `assets/loader.js` and `assets/custom.css` are this plugin's fragments of the [Shared Assets Protocol](https://github.com/Classic298/open-webui-plugins/tree/main/shared-assets-protocol)'s two shared files. They are embedded in the function bundle as a JSON literal (`__ASSETS_DATA__`), together with the settings from the manifest's `assets:` key, and published by the [`assets` library](libraries.md#assets). The protocol block (`shared_assets`) and `core` are added with it; `live_reload` is opt-in. A plugin with an `assets/` folder and no `function.py` gets a generated `Event(PluginAssets)`. ## Config `config.yaml` is parsed during bundling (a YAML or shape error stops the bundle) and embedded as a JSON literal (`__CONFIG_DATA__`). The [`config` library](libraries.md#config) reads it with `plugin_config()`. ## Static files and templates Files under `static/` are embedded in the function bundle as a JSON literal (`__STATIC_DATA__`, with the prefix and the access level from `static:`) and served by the [`static` library](libraries.md#static). Files under `templates/` are embedded the same way (`__TEMPLATES_DATA__`) and read back with `plugin_template_text()`; nothing serves them. ## What the deploy script does with a bundle For each plugin function: not present is created, activated, and made global if it is a filter; present with different code is updated (comparison ignores line endings and trailing whitespace, and applies Open-WebUI's own import rewriting to the local copy first); identical is left alone. Valves stored in the database are never overwritten except for keys the manifest declares. See [what a deploy does](commands/deploy.md#what-a-deploy-does). # Runtime: the function is the parent `src/owpp/runtime/plugin_runtime.py` is appended to every bundle whose plugin declares a tool or skills. It is what makes enabling a function install its tool and skills, and disabling or deleting it remove them. A plugin with a tool or skills but no `function.py` gets a generated no-op **global Filter** as the parent, so there is always a function to toggle. ## Ownership markers | Object | Marked with | | --- | --- | | Tool | `meta.manifest.parent_function_id = ` | | Skill | tag `plugin:` | The runtime only updates or removes objects carrying its function's marker. A tool or skill with the same id that someone made by hand is left alone. ## When it syncs - at Open-WebUI startup (a global function is loaded then); - on every function lifecycle event (`function.enabled`, `.disabled`, `.updated`, `.deleted`), through `EVENT_SINKS`; - when an admin saves the function's valves (`function.valves_updated`; a user saving their own UserValves does not count), so `INSTALL_TOOLS`, `INSTALL_SKILLS` and `TOOL_VALVES` apply on save; - from a throttled `plugin_ensure()` called in the function's `inlet` (retries a failed startup sync; `from owpp.lib import plugin_ensure`); - when the tool's module loads (`_plugin_check_parent`), for a restart that happened while the function was disabled. A sync **installs and updates** the tool and skills while the function is enabled, and **removes** them when it is disabled or deleted. ## Valves on the parent A function's own valves only reach a running instance when a chat runs it, so the runtime reads the stored valves from the database. | Valve | Default | Effect | | --- | --- | --- | | `INSTALL_TOOLS` | on | Off removes just the tools. | | `INSTALL_SKILLS` | on | Off removes just the skills. | | `TOOL_VALVES` | `{}` | JSON `{"": {"": value}}`, applied to the tool's valves. Wins over the manifest's `tool.valves`. | Only the generated parent declares these, so only it shows them in the Admin UI. A plugin with its own function code reads the same stored values if present. Tool valves are enforced for the declared keys only, on every sync; other valves keep what the admin set. Values are validated against the tool's own `Valves` class first. ## What it never does - It does not manage model presets. - It does not create or delete the function itself (the deploy script does). - It does not touch tools or skills it did not mark. ## Source of truth The runtime is `src/owpp/runtime/plugin_runtime.py` in this package, never edited in a deployed copy. Tests: `tests/plugin_runtime_test.py` (Python, stubbed Open-WebUI). # Libraries Libraries are plain Python files in `src/owpp/runtime/lib/`, inserted into a bundle by `include:` (see [bundling](bundling.md#order)). They are **vendored**: the bundle contains a copy, so a plugin has no runtime dependency on this repository. Public names start with `plugin_`; private helpers start with `__` so nothing collides with plugin code. Each file ends with a marker comment (`# end plugin library`) used to avoid inserting it twice. A plugin imports what it uses from **`owpp.lib`**, which re-exports every library's public names: ```python from owpp.lib import PluginAdmin, plugin_mount ``` The import is for an editor and for tests; owpp is a development dependency, not something Open-WebUI has. The bundler removes the line and inlines the library, so it must be a top-level `from owpp.lib import NAME`, without `as`. The library must also be in the bundle: asked for with `include:`, or turned on by what the plugin holds. The bundler names the library when it is not. The libraries import each other the same way, relatively (`from .plugin_core import plugin_app`), and those imports go too. Each library also gives its data placeholder a default (`__CONFIG_DATA__ = '{}'`), so it imports on its own; in a bundle the plugin's data takes its place. | Library | Adds | | --- | --- | | [`core`](#core) | function id, app, is-enabled, stored valves | | [`routes`](#routes) | mount a FastAPI router that survives reloads | | [`jobs`](#jobs) | background and repeating jobs, one worker per period | | [`chat_data`](#chat_data) | JSON values saved with a chat | | [`events`](#events) | `@on("event.name")` handlers instead of an `event()` full of `if` checks | | [`static`](#static) | files from `static/`, served as they are | | [`templates`](#templates) | files from `templates/`, embedded and rendered by the function, never served | | [`config`](#config) | a `config.yaml` shipped with the plugin, parsed at bundle time, read with `plugin_config()` | | [`assets`](#assets) | `assets/loader.js` and `assets/custom.css` published as this plugin's fragments of the Shared Assets Protocol | | `shared_assets`, `live_reload` | Classic298's Shared Assets Protocol, unmodified | A library brings in the ones it is built on, and some are turned on by what the plugin holds, without `include:`. The table below is generated from the library catalogue (`src/owpp/libraries.py`) when the site is built: | Library | Pulls in | Turned on by | Carries | | --- | --- | --- | --- | | `live_reload` | — (needs `shared_assets` in `include:`) | `include:` only | — | | `shared_assets` | — | `include:` only | — | | `core` | — | `include:` only | — | | `routes` | `core` | a `static/` folder | — | | `events` | `core` | `include:` only | — | | `jobs` | `core`, `events` | a `jobs:` section in `plugin.yaml` | its settings | | `chat_data` | — | `include:` only | — | | `static` | `core`, `routes` | a `static/` folder | a `static/` folder | | `templates` | — | a `templates/` folder | a `templates/` folder | | `assets` | `shared_assets`, `core`, `events` | an `assets/` folder | an `assets/` folder | | `config` | `core` | a `config.yaml` | a `config.yaml` | Updating a vendored library updates every plugin that includes it on its next deploy. ## core - `plugin_function_id()`: this function's id, from the module name `function__<32 hex>`; `None` outside Open-WebUI. - `plugin_app()`: Open-WebUI's FastAPI app, or `None` before import. - `await plugin_is_active(function_id=None)`: still installed and enabled. Returns **True when it cannot tell** (no id, lookup failed): it is used to decide whether to stop work, and stopping on a hiccup is worse than carrying on. - `await plugin_stored_valves(valves_cls, function_id=None, ttl=0)`: the valves as stored in the database. A running instance only has valves applied when it handles an event or a chat, so routes and jobs read them here. `ttl` reuses a read for that many seconds (for a page that polls). - `plugin_env(value)`: resolves **environment templates**, `${NAME}` and `${NAME:-default}`, from the Open-WebUI container's environment, in a string or in the strings of a dict or list (keys are left alone). A string that is *one* template is typed like a YAML scalar (`${N:-60}` is the number 60, `${FLAG:-true}` is `True`); a template inside a longer string is text (`http://${HOST}:8000`). An unset or empty variable uses its default; with no default a whole-string template is `None` and an embedded one is empty, both with a warning. `$${` writes a literal `${`. `plugin.yaml`'s `jobs:` and `config.yaml` use it for you; call it yourself for a value in code. ## routes **Every route requires a signed-in user, unless a mount says `public` in so many words.** A route is open to any signed-in user; one that needs more is **marked** (below), never checked by hand in its handler. The level belongs on the route, or on the mount (`access=`), or, for the `static/` files, on [`static:`](plugin-format.md#static-and-the-static-and-templates-folders). There is no plugin-wide setting. `plugin_mount(app, router, prefix, owner=None, name="", access=None, guard=None) -> int` - **Puts the guard on everything it mounts**, the `static/` files included. Per request: **404** once the function is disabled (before asking who you are, so a disabled plugin reveals nothing), then a signed-in user (below), then **403** for a signed-in non-admin when the access is `admin`. A pending account is not signed in. The session is Open-WebUI's own (a bearer header, else its `token` cookie). - **Someone opening a page with no session is not just turned away.** Many sign-ins happen by themselves when the app's home page loads (a proxy's trusted headers, authentication switched off, an OIDC session at the identity provider), so a person who goes straight to a plugin's address has no cookie yet through no fault of their own. For a browser navigation (a `GET` that asks for HTML) the guard therefore: 1. **tries the sign-ins that need no input**: it calls Open-WebUI's own sign-in endpoint with empty credentials, carrying the request's headers, exactly as its login page does for trusted-header and no-auth setups. The call runs inside the app (no socket, so no host, port or TLS to get wrong). On success it carries on as that user and hands the session cookie to the browser, so the next request has one; 2. **else sends the browser to Open-WebUI's login page** (`/auth?redirect=`, query string included, always a plain path on this site), which handles OIDC, LDAP and passwords and brings them back; 3. but an **iframe** (the Artifacts panel) is signed in if it can be and otherwise gets a 401, never a redirect, since a login page inside a sandboxed panel is no use. Inside the panel it usually *cannot* be: with Open-WebUI's default settings the panel sends no session at all ([below](#pages-in-the-artifacts-panel-need-iframe-sandbox-allow-same-origin)); and an **API call or fetch** (anything not asking for HTML) always gets a plain **401** and never has a session minted for it. OIDC and LDAP cannot be done silently from here (they need a redirect to the identity provider, or a password), which is why the fall back is the login page rather than a failure. - `access` is the mount's level: `"user"` (the default), `"admin"` or `"public"`. Anything else, `"Public"` and `True` included, is a `ValueError`, so a typo can never open a mount. Use `name` for a second mount with a different level. - Drops the routes an earlier load of this same function mounted under `prefix` (Starlette cannot swap a handler in place, so the old page would otherwise keep serving until restart). Only routes whose endpoint belongs to this function are dropped, never Open-WebUI's. - **`name` is a mount's identity.** Mounting a name again replaces the earlier mount of that name *wherever it was* (a configurable path that changed drops the old one by itself, with no state kept), and mounts with different names never replace each other (the static `public/` files, a page, an API). Give each mount of a function its own name; two unnamed mounts count as one. - Moves the new routes ahead of Open-WebUI's catch-all mount at `/`, which otherwise swallows anything added later. - Refuses prefix `/`. - Mounting an **empty** router removes that name's routes. (Matching uses the tags the mount puts on what it adds, because current FastAPI adds one wrapper object per router, not a route per path.) **Marking a route.** To mark one route, type a parameter of its handler: ```python @router.get("/purge") async def purge(user: PluginAdmin): # admin-only; `user` is the signed-in admin ... @router.get("/mine") async def mine(user: PluginUser): # any signed-in user; `user` is that user ... ``` `PluginUser` and `PluginAdmin` are ordinary FastAPI `Annotated` dependencies, and the handler receives the user (an object with `.id` and `.role`). - **`access="public"` serves people who are not signed in.** It is the one level that needs no one: no session lookup, no sign-in attempt, no redirect. It is still switched off with the function (404), and it is **per mount**, because a mount's guard covers every route in it, so a public endpoint (a webhook, an OAuth callback, a health check) gets a mount of its own, with its own `name`. A marker on a route of a public mount still applies (`user: PluginUser` there asks for a signed-in user), and a handler can ask who is there, if anyone, with `plugin_user(request)`. `owpp check` lists every public mount as a `note`, so a reviewer sees them; a plugin should have few. A marker **only tightens** what the mount requires: `PluginAdmin` makes one route admin-only, but `PluginUser` on a route of an `access="admin"` mount does not open it, because the mount's guard still applies. There is no marker for a public route. The session is looked up once per request however many guards ask. **Marking a route by the chat it serves.** For a route about one chat, type the chat's path parameter: ```python @router.get("/view/{chat_id}") async def view(chat_id: WritableChat): # signed in, and can write to this chat; receives the id ... @router.get("/export/{chat_id}") async def export(chat_id: ReadableChat): # signed in, and can read this chat ... ``` `ReadableChat` and `WritableChat` check Open-WebUI's own chat access (`Chats.has_chat_access`) for the signed-in user and hand the handler the chat id. No access answers **404**, not 403, so a chat's existence is not revealed (401 without a signed-in user). A temporary chat (`local:...`) has no stored record, so any signed-in user passes for one: keep nothing private there. `plugin_chat_guard(permission, param="chat_id")` builds the same dependency for another path-parameter name. A route that has no such path parameter fails with a 500, loudly. Excalidraw's page uses `WritableChat`, replacing the check it used to write by hand. Which to use: mark each route that needs more than a signed-in user. If **every** route of a mount is admin-only, mount it with `plugin_mount(..., access="admin")` instead of marking each one, so a route added to it later is admin-only by default. `stale_data` marks its one route `user: PluginAdmin`; Excalidraw's page takes `chat_id: WritableChat`. `await plugin_user(request)`: the signed-in user or `None`, for code that has the request but not a marked parameter. `plugin_user(request, token=None)` also takes a session token to use in place of the request's own. `plugin_guard(access=None)` is the dependency behind the markers and the mount. **The one exception: `guard=`.** A route that cannot carry an Open-WebUI session, such as an API called from a sandboxed iframe (which sends no cookies), can pass its own FastAPI dependency as `guard`, which replaces the sign-in check for that mount only. It must verify a credential that was **minted from a real login**, so keep the page that mints it behind the normal guard. That page needs a session of its own, which inside the Artifacts panel it only gets with **iframe Sandbox Allow Same Origin** on ([below](#pages-in-the-artifacts-panel-need-iframe-sandbox-allow-same-origin)). The function must still be enabled. `guard` and `access` cannot be combined. `plugin_token(subject, hours=12)` and `plugin_check_token(token, subject)` are that credential, ready-made: a short-lived signed token for one subject (a chat id, say), stateless so every worker agrees, scoped to this function (another plugin's tokens never validate here) and expiring. Mint one inside the signed-in page that loads the iframe, and have the API's guard call `plugin_check_token`. Excalidraw does exactly that: its page needs a login and a writable chat, and its API takes the token the page was rendered with. ### Pages in the Artifacts panel need "iframe Sandbox Allow Same Origin" A filter can show a plugin's page in the Artifacts panel by putting an `