This commit is contained in:
Arc
2026-02-25 16:20:26 +00:00
parent 3fd7aae10d
commit 4e8a5e050b
10 changed files with 175 additions and 76 deletions
+8
View File
@@ -10,11 +10,13 @@ nav_order: 4
This guide is for AI agents or developers using AI to build **traditional (Python) LNbits extensions**. It defines what to change, what not to change, and the expected structure.
## Hard Rules (Non-Negotiable)
- Do **not** change core LNbits files.
- Only edit files inside your extension folder.
- Do **not** add new Python dependencies unless explicitly approved.
## Extension Folder Layout (Python)
Your extension lives under:
```
@@ -22,6 +24,7 @@ lnbits/extensions/<ext_id>/
```
Typical files to edit:
- `views.py` (HTML routes)
- `views_api.py` (API routes)
- `crud.py` / `models.py` (storage logic + models)
@@ -31,18 +34,22 @@ Typical files to edit:
- `config.json`, `manifest.json`, `README.md`
## What You Can Do
Python extensions can:
- Define their own database schema via `migrations.py`
- Run long-running background tasks via `*_start()` and `*_stop()` hooks
- Access LNbits internal services directly in Python
- Expose custom API routes under `/<ext_id>/api/v1/...`
## What You Must Not Do
- Do not modify core services or routes.
- Do not patch LNbits internals for your extension.
- Avoid direct DB access outside your own schema.
## Background Tasks
Implement background tasks by exposing:
```
@@ -53,6 +60,7 @@ def <ext_id>_stop():
Use `register_invoice_listener` or `wait_for_paid_invoices` if you need to react to payments.
## Testing Checklist
- Extension loads without errors.
- Migrations apply cleanly.
- Routes are registered under `/<ext_id>/...`.
+41 -4
View File
@@ -10,11 +10,13 @@ nav_order: 3
This guide is written for AI agents or developers using AI to build LNbits WASM extensions. It describes what to change, what not to change, and the available capabilities/limits.
## Hard Rules (Non-Negotiable)
- Do **not** change core LNbits files. Only edit files inside your extension folder.
- Do **not** add new Python dependencies.
- Do **not** rely on long-running WASM processes. WASM runs per-call with timeouts.
## Extension Folder Layout (WASM)
Your extension lives under:
```
@@ -22,6 +24,7 @@ lnbits/extensions/<ext_id>/
```
You should only edit files under this folder, typically:
- `config.json` (metadata, permissions, tags, public handlers)
- `wasm/` (your `module.wasm` or `module.wat`)
- `static/` (frontend assets)
@@ -29,7 +32,9 @@ You should only edit files under this folder, typically:
- `manifest.json`, `README.md`, `description.md` (docs and metadata)
## Required Config Fields
In `config.json`:
- `id` / `name`
- `extension_type: "wasm"`
- `permissions` (required API permissions)
@@ -38,6 +43,7 @@ In `config.json`:
- `payment_tags` (list of tags the user may grant for watcher access)
Example:
```json
{
"id": "myext",
@@ -45,19 +51,37 @@ Example:
"extension_type": "wasm",
"permissions": [
{"id": "ext.db.read_write", "label": "DB access", "description": "..."},
{"id": "api.POST:/api/v1/payments", "label": "Create invoices", "description": "..."},
{"id": "ext.payments.watch", "label": "Watch payments", "description": "..."},
{"id": "ext.tasks.schedule", "label": "Schedule tasks", "description": "..."},
{
"id": "api.POST:/api/v1/payments",
"label": "Create invoices",
"description": "..."
},
{
"id": "ext.payments.watch",
"label": "Watch payments",
"description": "..."
},
{
"id": "ext.tasks.schedule",
"label": "Schedule tasks",
"description": "..."
},
{"id": "ext.db.sql", "label": "SQL access", "description": "..."}
],
"public_wasm_functions": ["public_create_invoice", "on_tag_payment", "on_schedule"],
"public_wasm_functions": [
"public_create_invoice",
"on_tag_payment",
"on_schedule"
],
"public_kv_keys": ["public_lists", "public_tasks"],
"payment_tags": ["coinflip", "myext"]
}
```
## What the WASM Host Can Do
WASM runs in a short-lived subprocess. It can:
- Read/write extension KV (`/api/v1/kv/*`)
- Read/write secret KV (`/api/v1/secret/*`)
- Call internal LNbits endpoints (only if declared + granted)
@@ -65,7 +89,9 @@ WASM runs in a short-lived subprocess. It can:
- Run backend tag watchers and scheduled handlers (server-side triggers)
## Permissions Model
Your extension can only call or access what is declared and granted:
- `api.METHOD:/path` for internal endpoints (core or other extensions)
- `ext.db.read_write` for KV access
- `ext.payments.watch` for payment watchers
@@ -75,6 +101,7 @@ Your extension can only call or access what is declared and granted:
If the endpoint doesnt exist, permissions wont save.
## Tag Watchers (Backend)
You can register tag watchers:
```
@@ -88,10 +115,12 @@ POST /<ext_id>/api/v1/watch_tag
```
Constraints:
- Tag must be in `payment_tags` and granted by the user.
- Watchers are persisted and restored on restart.
## Scheduled Tasks (Backend)
You can schedule periodic handlers:
```
@@ -104,32 +133,40 @@ POST /<ext_id>/api/v1/schedule
```
Constraints:
- Requires `ext.tasks.schedule` permission.
- Minimum interval is 5 seconds.
- Stored in extension KV and restored on restart.
## SQL Interface (Limited)
You can run SQL within your extension schema:
- `/api/v1/sql/query` (SELECT only)
- `/api/v1/sql/exec` (limited DDL/DML)
Rules:
- Single statement only
- No `PRAGMA`, no `sqlite_master`
- No cross-schema access
## Public Pages (No Keys)
Public pages must not depend on `window.g` or wallet keys.
They can call:
- `/{ext_id}/api/v1/public/kv/{key}`
- `/{ext_id}/api/v1/public/call/{handler}`
## What Not To Do
- Do not write to core routes or override existing LNbits paths.
- Do not add background threads; use watchers or scheduler instead.
- Do not assume the WASM process persists.
## Testing Checklist
- Permissions show correctly in the extensions UI.
- Public handlers are in `public_wasm_functions`.
- Public KV keys are explicitly listed.