@muntin/api
TypeScript API for Muntin commands, surfaces, and themes.
npm install @muntin/api
Add a command
import { defineExtension } from '@muntin/api';
export default defineExtension({
id: 'example.hello',
register({ commands }) {
commands.register('hello', async ({ ui }) => {
await ui.notify('Hello from your extension.');
});
},
});
Declare the matching ID and entry point in package.json:
{
"name": "muntin-hello",
"version": "0.1.0",
"type": "module",
"muntin": {
"id": "example.hello",
"runtime": "./src/index.ts"
}
}
Commit the npm lockfile, then run muntin extension install .. Use muntin extension update example.hello after changes. See the extension guide for single-file installs.
Surfaces and resources
Register surfaces with surfaces.register. Load client views with
lazy(() => import('./view.js')) to keep browser dependencies out of host code.
React views use react from @muntin/api/react. See the bundled
browser and
terminal extensions for examples.
Declare public methods and streams in the surface contract. State is schema-validated
and private to the extension. Keep durable values in state, not the DOM: views can
be hidden, suspended, or recreated while host work continues.
Use the view's lifecycle to pause rendering. Subscriptions are scoped automatically;
use resources.signal for DOM listeners and resources.defer for other cleanup.
Use surface.resources.retain only when a resource must survive view remounts.
For workers, use defineWorker from @muntin/api/workers, declare source entries in
muntin.workers, and create instances with workers.create using an
extension.worker handle. Calls are asynchronous; use onFailure for crash recovery.
Files
Paths refer to the current host. Controllers use normal filesystem APIs.
- Capture drops and pastes synchronously with
files.fromEvent(event) in the view.
Pass inputs to the controller through a fileInputSchema contract.
await using file = await files.materialize(input) gives the controller a usable
file.path. Keep it alive while needed; disposal removes temporary copies,
never originals.
const preview = await files.url(path, { entry: 'index.html' }) gives the view a
preview.url. View closure releases it automatically; disposal or an optional
signal releases it earlier. Keep any underlying temporary file alive separately.
- Use
files.drag(event, { paths }) in dragstart to export copies. Drags between
Muntin views require the same host. Use workspace.links to open another surface.
Persist durable host paths, not import handles, temporary paths, or preview URLs.
Import handles expire when their receiving view closes.