Feat v0.8.5 extension composability (#72)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-go-pg (push) Successful in 2m44s
CI/CD / test-sqlite (push) Successful in 2m54s
CI/CD / build-and-deploy (push) Successful in 52s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 6s
CI/CD / test-go-pg (push) Successful in 2m44s
CI/CD / test-sqlite (push) Successful in 2m54s
CI/CD / build-and-deploy (push) Successful in 52s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #72.
This commit is contained in:
@@ -77,7 +77,10 @@ Every package has a `manifest.json` at its root. Example for a surface:
|
||||
| `api_schema` | no | OpenAPI documentation for extension API routes (see below) |
|
||||
| `db_tables` | no | Table definitions (see below) |
|
||||
| `settings` | no | User-configurable settings schema |
|
||||
| `exports` | libraries | Functions exported for other packages |
|
||||
| `exports` | no | Functions exported for cross-package calls via `lib.require()` |
|
||||
| `depends` | no | Array of package IDs this package depends on |
|
||||
| `slots` | no | Named UI injection points for host surfaces |
|
||||
| `contributes` | no | Slot contributions into other surfaces |
|
||||
| `hooks` | no | Event bus subscriptions |
|
||||
| `config_section` | no | Settings/Admin panel injection (see below) |
|
||||
| `capabilities` | no | Environment requirements (see below) |
|
||||
@@ -194,6 +197,117 @@ sandbox permission model.
|
||||
In Starlark, check permissions inline via `req["permissions"]` or call
|
||||
`permissions.check(user_id, "image-gen.use")`.
|
||||
|
||||
## Extension Composability
|
||||
|
||||
Extensions compose with each other through three mechanisms: manifest-declared
|
||||
**slots** (UI injection points), **contributions** (UI components injected into
|
||||
those slots), and cross-package **function calls** via `lib.require()`.
|
||||
|
||||
### Slots — Host Surfaces Declare Injection Points
|
||||
|
||||
A surface declares named slots in its manifest where other extensions can
|
||||
inject UI components:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "notes",
|
||||
"type": "surface",
|
||||
"slots": {
|
||||
"toolbar-actions": {
|
||||
"description": "Toolbar action buttons",
|
||||
"context": {
|
||||
"noteId": "string",
|
||||
"getContent": "function — returns note body",
|
||||
"setContent": "function — replaces note body"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The surface renders slot contents using the SDK helper:
|
||||
|
||||
```javascript
|
||||
html`<div class="toolbar">
|
||||
${sw.slots.renderAll('notes:toolbar-actions', {
|
||||
noteId: note.id,
|
||||
getContent: () => editor.getValue(),
|
||||
setContent: (text) => editor.setValue(text),
|
||||
})}
|
||||
</div>`
|
||||
```
|
||||
|
||||
### Contributions — Extensions Inject UI
|
||||
|
||||
An extension declares which slots it contributes to:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "note-dictate",
|
||||
"type": "extension",
|
||||
"contributes": {
|
||||
"notes:toolbar-actions": {
|
||||
"label": "Dictate",
|
||||
"icon": "🎤",
|
||||
"description": "Voice-to-text dictation"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In its JavaScript, it registers the component:
|
||||
|
||||
```javascript
|
||||
sw.slots.register('notes:toolbar-actions', {
|
||||
id: 'note-dictate',
|
||||
priority: 200,
|
||||
component: ({ noteId, setContent, getContent }) => {
|
||||
// ... component implementation
|
||||
return html`<button class="sw-btn sw-btn--ghost">🎤</button>`;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Contributions are soft-coupled — install order doesn't matter. The admin
|
||||
can view all slots and contributors at **Admin > Packages** or via
|
||||
`GET /api/v1/admin/slots`.
|
||||
|
||||
### Cross-Package Function Calls
|
||||
|
||||
Any package that declares `exports` in its manifest can be called by other
|
||||
packages via `lib.require()`. The caller declares the dependency:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "note-ai",
|
||||
"depends": ["llm-bridge"],
|
||||
"permissions": ["api.http"]
|
||||
}
|
||||
```
|
||||
|
||||
In Starlark:
|
||||
|
||||
```python
|
||||
llm = lib.require("llm-bridge")
|
||||
result = llm.complete([{"role": "user", "content": prompt}])
|
||||
```
|
||||
|
||||
The called function runs with the *target* package's permissions, not the
|
||||
caller's. This is the same security model as library packages.
|
||||
|
||||
### Slot Naming Convention
|
||||
|
||||
Slot names follow `{host-package-id}:{slot-name}`. The colon separates the
|
||||
namespace from the slot. Standard slots for first-party packages:
|
||||
|
||||
| Slot | Host | Use Case |
|
||||
|------|------|----------|
|
||||
| `notes:toolbar-actions` | notes | Dictation, AI tools, formatting |
|
||||
| `notes:note-footer` | notes | Related items, AI summary |
|
||||
| `chat:composer-tools` | chat | Image gen, file attach |
|
||||
| `chat:message-actions` | chat | Reactions, translate, bookmark |
|
||||
| `chat:image-actions` | chat | Regen, edit, upscale |
|
||||
|
||||
## Starlark Sandbox API
|
||||
|
||||
Starlark scripts run server-side with a 1M operation budget and no
|
||||
|
||||
Reference in New Issue
Block a user