Build your first plugin
Build a plugin that adds a page and a navigation entry to the workspace, takes a setting from dsui.yaml, and exposes a procedure that you can call over HTTP.
On this page
In this tutorial, you build a plugin named hello-plugin. It adds a Services page that lists the services of your installation, a link to that page in the navigation, and a greet procedure. You write about 80 lines of TypeScript, and DSUI builds and loads them for you.
You need the workspace from the quickstart with at least one service, Node.js 18 or later, and network access. DSUI downloads the Plugin SDK from npm when it builds your plugin. A plugin runs inside the DSUI server, so only load plugins that you trust.
Create the project#
Create a
hello-plugindirectory next to yourdsui.yaml. Inside it, addpackage.json:json{ "name": "hello-plugin", "version": "0.1.0", "private": true, "type": "module", "exports": { ".": "./src/index.ts" }, "dependencies": { "@northgraindata/dsui-plugin-sdk": "0.3.0", "zod": "^3.25.76" } }DSUI reads the entry file from
exports, and the entry must be a TypeScript file. Pin the SDK to an exact version.Define the settings#
A plugin declares its settings with a Zod schema. DSUI validates the
configthat a person writes indsui.yamlagainst it, and it fills in defaults. Createsrc/config.ts:tsimport { z } from "zod"; export const configSchema = z.object({ greeting: z.string().default("Hello"), }); export type HelloConfig = z.output<typeof configSchema>;Build a page#
A page returns a tree of builtin components, the same ones that adapters use.
contextgives the page the plugin’s settings and the host’s capabilities. Herecontext.services.listreturns the connected services without their credentials. Createsrc/page.ts:tsimport { Card, definePage, Grid, PageHeader, type PluginContext, Section, } from "@northgraindata/dsui-plugin-sdk"; import type { HelloConfig } from "./config.js"; export const servicesPage = definePage< "/services", PluginContext<HelloConfig> >({ path: "/services", render: async ({ context }) => { const { items } = await context.services.list({ limit: 24 }); return [ PageHeader({ title: context.config.greeting }), Section({ title: "Services", content: Grid({ columns: 2, content: items.map((service) => Card({ title: service.name, description: service.adapter }), ), }), }), ]; }, });Define the plugin#
definePlugintakes the plugin’s identity, its settings schema, and asetupfunction. Insetup, you register everything that the plugin adds. Createsrc/index.ts:tsimport { definePlugin } from "@northgraindata/dsui-plugin-sdk"; import { z } from "zod"; import { configSchema } from "./config.js"; import { servicesPage } from "./page.js"; export default definePlugin({ metadata: { id: "hello-plugin", name: "Hello plugin", version: "0.1.0", apiVersion: 1, }, configSchema, setup(registry) { registry.page(servicesPage, { id: "services", title: "Services", description: "Lists the services that this installation connects to.", }); registry.navigation({ id: "services-link", area: "primary", label: "Services", pageId: "services", order: 100, }); registry.procedure({ id: "greet", permission: "inspect", input: z.object({ name: z.string().min(1) }), output: z.string(), handler: (context, input) => `${context.config.greeting}, ${input.name}`, }); }, });The
idmust match the key that you use underpluginsindsui.yaml.apiVersionis the plugin API that you built against. A procedure is a validated operation with a permission. Anyone who has that permission can call it.Load the plugin#
Add the plugin to
dsui.yaml. Thepathis relative to the directory where you start DSUI, andconfigsets the plugin’s options:yamlplugins: hello-plugin: source: local path: ./hello-plugin config: greeting: HiDSUI loads plugins once, when it starts, so restart DSUI. The first start takes a moment while DSUI builds the plugin. Open Settings, then Extensions, and check that Hello plugin shows Loaded. If it shows Unavailable, the panel names the reason.
Open the page and call the procedure#
Select Services in the navigation. The page lists your services under the greeting from your settings.
Call the procedure over HTTP. The body is the procedure’s input:
bashcurl --request POST \ --header "Content-Type: application/json" \ --data '{"name": "Ada"}' \ http://localhost:4192/api/v1/plugins/hello-plugin/procedures/greetDSUI answers
{"data":"Hi, Ada"}. An emptynameis rejected with a422, because it doesn’t match the input schema.
How DSUI loads your plugin#
DSUI builds a source: local or source: git plugin the same way it builds an adapter. It copies the source, installs dependencies, and bundles the entry file. It then imports the bundle into the server process. If the build fails, DSUI starts without the plugin and shows it as Unavailable. Add critical: true to refuse to start instead. See plugins.
Next steps#
- Read data and run work in resources, actions and procedures, and jobs
- Keep state in stores and storage
- Read services and other plugins with host capabilities
- Add to the host’s interface with pages and navigation and slots and overlays
- Share your plugin as described in release