plugin

package
v0.0.1-rc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir(cfg *config.Config, cfgPath string) string

Dir resolves the plugins root directory.

func GetEventsByIDs

func GetEventsByIDs(ctx context.Context, store eventQuerier, ids []string) ([]*nostr.Event, error)

GetEventsByIDs loads events and returns them in the same order as ids. Missing ids are skipped.

func MatchInterceptREQ

func MatchInterceptREQ(subs []sdk.TrafficSubscription, filters []nostr.Filter) bool

MatchInterceptREQ reports whether any subscription wants a sync REQ intercept.

func MatchObserve

func MatchObserve(subs []sdk.TrafficSubscription, msg any) bool

MatchObserve reports whether any subscription wants a listen copy of this inbound message.

func MatchOnStoredEvent

func MatchOnStoredEvent(subs []sdk.TrafficSubscription, kind int) bool

MatchOnStoredEvent reports whether the plugin should be notified of an accepted event.

Types

type InstanceSnapshot

type InstanceSnapshot struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	Version      string   `json:"version"`
	Enabled      bool     `json:"enabled"`
	State        string   `json:"state"`
	Ready        bool     `json:"ready"`
	LastError    string   `json:"last_error,omitempty"`
	Capabilities []string `json:"capabilities,omitempty"`
	SourceURL    string   `json:"source_url,omitempty"`
	SHA256       string   `json:"sha256,omitempty"`
}

InstanceSnapshot is admin JSON for one plugin.

type InterceptAction

type InterceptAction int

InterceptAction mirrors the SDK intercept decision.

const (
	InterceptPassthrough InterceptAction = iota
	InterceptReshapeREQ
	InterceptRespond
)

type InterceptLogEntry

type InterceptLogEntry struct {
	UnixMilli           int64          `json:"unix_milli"`
	DurationMs          int64          `json:"duration_ms"`
	SubID               string         `json:"sub_id"`
	Filters             []nostr.Filter `json:"filters"`
	Action              string         `json:"action"`
	EventIDs            []string       `json:"event_ids,omitempty"`
	ReshapeFilters      []nostr.Filter `json:"reshape_filters,omitempty"`
	SubscriptionFilters []nostr.Filter `json:"subscription_filters,omitempty"`
	Error               string         `json:"error,omitempty"`
}

InterceptLogEntry is one recorded intercept decision for admin UI.

type InterceptLogSnapshot

type InterceptLogSnapshot struct {
	Limit   int                 `json:"limit"`
	Dropped int64               `json:"dropped"`
	Entries []InterceptLogEntry `json:"entries"`
}

InterceptLogSnapshot is the admin JSON for one plugin's intercept log.

type InterceptResult

type InterceptResult struct {
	Action              InterceptAction
	Filters             []nostr.Filter
	EventIDs            []string
	SubscriptionFilters []nostr.Filter
}

InterceptResult is returned to the relay REQ handler.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns plugin processes and implements Runtime.

func NewManager

func NewManager(cfg *config.Config, cfgPath string, store storage.Store, log zerolog.Logger) *Manager

NewManager constructs a plugin manager. Call Start after host.sock is needed.

func (*Manager) AdminAction

func (m *Manager) AdminAction(ctx context.Context, id, name string, payload []byte) ([]byte, error)

AdminAction invokes a plugin action.

func (*Manager) ApplySettings

func (m *Manager) ApplySettings(ctx context.Context, id string, settings []byte) error

ApplySettings pushes settings to a running plugin and persists them on the item.

func (*Manager) Disable

func (m *Manager) Disable(id string) error

Disable stops a running plugin without uninstalling.

func (*Manager) Enable

func (m *Manager) Enable(id string) error

Enable starts a plugin if installed.

func (*Manager) EnqueueStoredEvent

func (m *Manager) EnqueueStoredEvent(ev *nostr.Event, stored bool)

EnqueueStoredEvent implements Runtime.

func (*Manager) InstallLocal

func (m *Manager) InstallLocal(src string, enable bool) (*Manifest, error)

InstallLocal copies a directory that contains plugin.json.

func (*Manager) InstallURL

func (m *Manager) InstallURL(ctx context.Context, url, sha256hex string, enable bool) (*Manifest, error)

InstallURL downloads, verifies sha256, and copies the package into the plugins dir. Re-installing the same plugin id stops the process, replaces bin/ui, keeps data/, runs hooks.update (or install if update is omitted), then optionally starts again.

func (*Manager) InterceptLogSnapshot

func (m *Manager) InterceptLogSnapshot(id string) InterceptLogSnapshot

InterceptLogSnapshot returns newest-first intercept log rows for a plugin.

func (*Manager) InterceptREQ

func (m *Manager) InterceptREQ(ctx context.Context, req *nostr.ReqMessage) InterceptResult

InterceptREQ implements Runtime. First non-passthrough wins (config order).

func (*Manager) MetricsSnapshot

func (m *Manager) MetricsSnapshot() Metrics

func (*Manager) Observe

func (m *Manager) Observe(msg any)

Observe implements Runtime.

func (*Manager) PersistConfig

func (m *Manager) PersistConfig() error

PersistConfig writes cfg to cfgPath if set.

func (*Manager) RecordInterceptLog

func (m *Manager) RecordInterceptLog(pluginID string, req *nostr.ReqMessage, res InterceptResult, fail string)

RecordInterceptLog injects a completed intercept decision. Never blocks. Used by tests.

func (*Manager) SetInterceptLogLimit

func (m *Manager) SetInterceptLogLimit(n int) int

SetInterceptLogLimit updates the host-wide rolling window and trims stored rows.

func (*Manager) Snapshot

func (m *Manager) Snapshot() []InstanceSnapshot

Snapshot implements Runtime.

func (*Manager) Start

func (m *Manager) Start(parent context.Context) error

Start listens on a shared host.sock (under root) and starts enabled plugins.

func (*Manager) StartInterceptLogWorker

func (m *Manager) StartInterceptLogWorker(ctx context.Context)

StartInterceptLogWorker starts the async intercept log goroutine without opening host.sock.

func (*Manager) StatusJSON

func (m *Manager) StatusJSON(ctx context.Context, id string) ([]byte, bool, error)

StatusJSON returns the plugin Status RPC payload.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops all plugins and the host socket.

func (*Manager) UIDir

func (m *Manager) UIDir(id string) string

UIDir is the compiled Svelte UI directory for a plugin, if present.

func (*Manager) Uninstall

func (m *Manager) Uninstall(id string, wipeData bool) error

Uninstall stops the plugin, runs hooks.uninstall, then removes the package. wipeData deletes data/ (index, secrets) as well as bin/ui; otherwise data/ is kept after the uninstall hook has already removed plugin-managed deps (models, runtime libs).

type Manifest

type Manifest struct {
	ID         string            `json:"id"`
	Name       string            `json:"name"`
	Version    string            `json:"version"`
	APIVersion int               `json:"api_version"`
	Exec       map[string]string `json:"exec"`
	Hooks      PluginHooks       `json:"hooks"`
}

Manifest is plugin.json in an installed package.

type Metrics

type Metrics struct {
	ListenEnqueued               int64 `json:"listen_enqueued"`
	ListenDropped                int64 `json:"listen_dropped"`
	InterceptN                   int64 `json:"intercept_n"`
	InterceptPassthroughNotReady int64 `json:"plugin_intercept_passthrough_not_ready"`
	InterceptPassthroughTimeout  int64 `json:"plugin_intercept_passthrough_timeout"`
	InterceptPassthroughError    int64 `json:"plugin_intercept_passthrough_error"`
}

Metrics is a snapshot of plugin host counters.

type PluginHooks

type PluginHooks struct {
	Install   []string `json:"install,omitempty"`
	Update    []string `json:"update,omitempty"`
	Launch    []string `json:"launch,omitempty"`
	Uninstall []string `json:"uninstall,omitempty"`
}

PluginHooks are extra argv passed to the plugin exec after install, on package upgrade, before Serve, and before package delete. Example: "install": ["--hook=install"], "update": ["--hook=update"], "launch": ["--hook=launch"], "uninstall": ["--hook=uninstall"].

type Runtime

type Runtime interface {
	// Observe enqueues a listen-only copy. Never blocks the caller.
	Observe(msg any)
	// InterceptREQ is the only synchronous plugin call on the REQ path.
	InterceptREQ(ctx context.Context, req *nostr.ReqMessage) InterceptResult
	// EnqueueStoredEvent enqueues an accepted EVENT for index plugins. Never blocks.
	// Called for WebSocket EVENT post-hooks and for NIP-77 imported events.
	EnqueueStoredEvent(ev *nostr.Event, stored bool)
	// Snapshot returns admin-facing plugin rows.
	Snapshot() []InstanceSnapshot
}

Runtime is the relay-facing plugin surface. All methods are nil-safe on a nil Runtime.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL