plugin

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package plugin is the host side of tool plugins: a kind=tool binary under plugins/tools/<key>/ registers as an ordinary tool (grid, palette, access rules, config page) whose routes reverse-proxy to the plugin's HTTP server on a unix socket. The process is spawned on first use, held for at most DefaultHold, and idle-killed by the pool sweeper unless keep_warm.

Index

Constants

View Source
const DefaultHold = 10 * time.Second

DefaultHold bounds how long a request waits for a cold plugin to finish its handshake before the host answers 503.

View Source
const DefaultIdle = 10 * time.Minute

DefaultIdle is how long an unused tool plugin stays running; WICK_TOOL_PLUGIN_IDLE (a Go duration) overrides it.

Variables

View Source
var ErrNotReady = errors.New("tool plugin not ready")

ErrNotReady is returned by Acquire when the plugin did not come up within the hold window (or failed to start).

Functions

This section is empty.

Types

type Pool

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

Pool holds every loaded tool plugin's Runner and sweeps idle ones, using the same rule as the connector plugin sweeper: not warm, nothing in flight, unused for longer than the idle TTL.

func NewPool

func NewPool() *Pool

NewPool returns an empty pool; call Start once tools are loaded.

func (*Pool) BuildModule

func (p *Pool) BuildModule(f connplugin.Found) tool.Module

BuildModule turns one discovered kind=tool plugin into a tool.Module whose routes proxy to the plugin, and registers its runner with the pool.

func (*Pool) Inflight

func (p *Pool) Inflight() int

Inflight sums in-flight proxied requests (graceful reload waits on it).

func (*Pool) KillAll

func (p *Pool) KillAll()

KillAll stops the sweeper and every process (app shutdown).

func (*Pool) Load

func (p *Pool) Load(dir string, enabled func(string) bool, record func(key, kind, version string) error, register func(tool.Module)) int

Load registers every enabled, verified kind=tool plugin under dir with register (tools.Register) and returns how many were registered. Call it before tools.All() so the plugin's config rows are seeded like a built-in tool's. record (optional) is told the kind + version of each plugin.

func (*Pool) Remove

func (p *Pool) Remove(key string)

Remove stops the process of tool plugin key and drops it from the pool, ahead of an uninstall deleting its files.

func (*Pool) Start

func (p *Pool) Start()

Start warms keep_warm tools and starts the idle sweeper.

func (*Pool) Sweep

func (p *Pool) Sweep() int

Sweep runs one idle pass and returns how many processes were killed.

func (*Pool) Version

func (p *Pool) Version(key string) (string, bool)

Version returns the installed version of tool plugin key; ok is false for a built-in tool.

type Proxy

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

Proxy forwards /tools/{key}/* to one tool plugin's unix socket.

func (*Proxy) ServeCtx

func (p *Proxy) ServeCtx(c *tool.Ctx, cfgKeys []string)

ServeCtx proxies a session-gated tool route.

func (*Proxy) ServeWebhook

func (p *Proxy) ServeWebhook(c *tool.WebhookCtx, cfgKeys []string)

ServeWebhook proxies a manifest-declared webhook route: no session, no user headers, never wrapped.

type Runner

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

Runner owns the lifecycle of one tool plugin: at most one process, spawned on first use (singleflight, so N concurrent cold requests cause one spawn), idle-killed by the pool sweeper unless keep_warm or a request (including a long-lived SSE/websocket one) is still in flight.

func (*Runner) Acquire

func (r *Runner) Acquire(ctx context.Context, cfg map[string]string) (http.RoundTripper, func(), error)

Acquire returns a transport to the running plugin (spawning it if needed) with cfg pushed, and a release func the caller must call when the request — including any streamed body — is finished. It waits at most the hold window for a cold start; the spawn keeps going in the background so the next request finds it ready.

func (*Runner) Inflight

func (r *Runner) Inflight() int64

Inflight is the number of requests currently being proxied.

func (*Runner) Running

func (r *Runner) Running() bool

Running reports whether a live process is attached.

func (*Runner) Stop

func (r *Runner) Stop()

Stop kills the process unconditionally.

func (*Runner) Warm

func (r *Runner) Warm() error

Warm spawns the process now (keep_warm tools at boot). Errors are returned for logging; the next request retries.

Jump to

Keyboard shortcuts

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