How the plugin SDK connects to the player through hosts.
Nuclear exposes player functionality to plugins through the host pattern. Every feature area the plugin system supports follows the same three-layer structure:
Host type - the contract (SDK, no implementation)
API class - what plugins actually call (SDK, wraps the host)
Host implementation - bridges the API to player internals (player)
Plugins call methods on an API class (e.g. api.Queue.addToQueue()), which holds a reference to the host and delegates to it.
The surface plugins interact with. Holds an optional reference to the host and guards every call with #withHost, which throws if the host isn't present (e.g. in a test environment where no player is running).
All API classes are assembled into NuclearAPI in packages/plugin-sdk/src/api/index.ts, which is what plugins receive as their api object.
Lives in the player. Implements the host interface and bridges it to whatever backs the domain - a Zustand store, a provider registry, a Tauri API, etc.
The singleton is passed into NuclearPluginAPI by createPluginAPI (packages/player/src/services/plugins/createPluginAPI.ts) when a plugin loads.
What hosts wrap
Domain
Backed by
Queue, Settings, Favorites
Zustand store
Metadata, Streaming, Dashboard
Plugin provider registry and optional store
HTTP
Fetch wrapper (implemented in Rust)
Shell
Tauri shell API
Logger
Scoped logger
Provider-backed hosts resolve which registered provider to call and check capabilities where the domain supports them. See the Providers doc for how providers register and what kinds exist.
Data flow
When a plugin calls api.Metadata.search({ query: 'Radiohead' }):
Plugin calls api.Metadata.search(params)
MetadataAPI.#withHost checks host is present, calls metadataHost.search(params)
metadataHost resolves the active metadata provider from the registry
metadataHost calls provider.searchArtists(params) (or whatever the provider implements)
Provider calls its external API, returns ArtistRef[]
metadataHost returns SearchResults to the plugin
Adding a new domain
Define the host interface in packages/plugin-sdk/src/types/yourDomain.ts
Create the API class in packages/plugin-sdk/src/api/yourDomain.ts - wraps the host with #withHost
Add the host option and API field to NuclearAPI in packages/plugin-sdk/src/api/index.ts
Implement the host in packages/player/src/services/yourDomainHost.ts
Pass the singleton into NuclearPluginAPI in createPluginAPI.ts