Skip to the content
Gridkiln
Menu
Guide contents

Guide Plugins Generated from the app’s code

Plugin interface reference

What a plugin is written against: the package @gridkiln/plugin-api, the plugin.yaml manifest, the capabilities a plugin can ask for, and the messages between the app and a plugin’s process. For a guided start, read Writing a plugin and the worked example; for how a plugin’s process is started and limited on each operating system, How plugins run.

The package#

A plugin imports from @gridkiln/plugin-api. Inside the app the import always resolves to the app’s own copy, whatever folder the plugin is in, so a plugin needs no node_modules for it. It exports:

Name Kind What it is
PLUGIN_API_VERSION constant The protocol version this runtime speaks. The engine refuses a plugin built for a newer one. (now 1)
DateOnly class A calendar date: a Date at midnight UTC that prints as YYYY-MM-DD.
Decimal class An exact decimal, kept as its text (Number(d) to compute with it).
PluginError class A failure the plugin explains itself: its message is shown to the user as written (“The API key was refused: check it in the connection”). Anything else a plugin throws is shown as the plugin’s own error with its stack.
Timestamp class A date and time that keeps microseconds (micros, 0–999 beyond the milliseconds).
definePlugin function Declares a plugin: the module’s default export. Returns the definition unchanged (typed).
readExchangeTable function A table from the exchange: visible columns decoded, hidden ones (__gk_row) kept aside as text per row.
rowsOf function Columns and rows (as arrays) of anything a plugin may return as a table.
servePlugin function Serves a plugin’s contributions over transport (the loop the plugin’s process runs). Returns a stop function.
writeExchangeTable function Writes a result as out.jsonl and out.schema.json in folder (what the engine reads back).

definePlugin#

definePlugin<D extends PluginDefinition>(definition: D): D

Declares a plugin: the module’s default export. Returns the definition unchanged (typed).

The definition is one object with up to five maps. Each key is a contribution’s name, which must match a name under contributes in plugin.yaml; the manifest gives its title and the JSON Schema of its settings, and the app checks the settings against that schema before calling the plugin, so config is always valid when a function receives it.

In definePlugin({ … }) Each entry is a What it adds
connectors: { name: … } ConnectorContribution a source of data (a source location of kind plugin)
steps: { name: … } StepContribution a step type (custom.plugin in pipelines)
checks: { name: … } CheckContribution a check kind (plugin checks)
outputs: { name: … } OutputContribution an output kind (plugin outputs) that delivers rows itself
actions: { name: … } ActionContribution a workflow action (action: plugin nodes)

PluginDefinition#

Everything a plugin contributes, by name.

Member What it is
connectors?: Record<string, ConnectorContribution<any>> Connectors, by name.
steps?: Record<string, StepContribution<any>> Step types, by name.
checks?: Record<string, CheckContribution<any>> Check kinds, by name.
outputs?: Record<string, OutputContribution<any>> Output kinds, by name.
actions?: Record<string, ActionContribution<any>> Workflow actions, by name.

Contributions#

Every function receives the contribution’s settings first (config) and a PluginContext last. A function may return its result or a promise of it.

ConnectorContribution#

A source of data: a kind: plugin source location reads through it.

Member What it is
list?(config: C, ctx: PluginContext): Awaitable<ListItem[]> What it can read (tables, feeds, folders), for the picker.
schema?(config: C, ctx: PluginContext): Awaitable<ColumnDeclaration[]> The columns read gives, when known without reading.
read(config: C, request: ReadRequest, ctx: PluginContext): Awaitable<TableResult> Reads the rows. request says which columns and how many rows are needed, as a hint.

StepContribution#

A step type (custom.plugin in documents). Give compileSql when the step can be SQL (preferred: it stays inspectable in the SQL tab and runs inside the engine’s query), else transform. schema says the output columns without running; without it they are learnt from the SQL or from the first result.

Member What it is
schema?(config: C, inputs: StepInput[], ctx: PluginContext): Awaitable<ColumnDeclaration[]> The output columns without running, so the editor and later steps know them at once.
compileSql?(config: C, inputs: StepInput[], ctx: PluginContext): Awaitable<string> One SELECT (DuckDB SQL) over the inputs by name (input, input2 …). It may read nothing else: no files, no table functions, no other tables (the engine refuses the SQL otherwise).
transform?(config: C, inputs: Table[], ctx: PluginContext): Awaitable<TableResult> The result table from the input tables (one per input, in order).

CheckContribution#

A check kind (plugin checks in documents).

Member What it is
evaluate(config: C, table: Table, ctx: PluginContext): Awaitable<CheckVerdict> Looks at the table the check is attached to (the rows its where keeps, when it has one) and says how it came out.

OutputContribution#

An output kind (plugin outputs in documents): it delivers the rows itself.

Member What it is
plan(config: C, table: TableShape, ctx: PluginContext): Awaitable<string[] | string | { targets: string[] }> Where the rows will go, in words or addresses (nothing is written).
write(config: C, table: Table, target: string, ctx: PluginContext): Awaitable<WriteResult | string | void> Writes (or sends) the rows to one of the planned targets. Called only on a real run, after every check passed.

ActionContribution#

A workflow action (action: plugin nodes). Throw to fail the node (it is retried only for temporary failures).

Member What it is
run(config: C, run: ActionRun, ctx: PluginContext): Awaitable<ActionResult | string | void> Does the action. Return a sentence for the run record, or { status: "skipped" }; throw to fail the node.

Tables and values#

Tables arrive as { columns, rows } with one object per row (column name → value) and leave the same way, or as an array of row objects, or as { Column: [values] }. Values:

Column type Value in JavaScript
text string
integer number (bigint beyond 2^53)
decimal Decimal (exact; Number(d) to compute)
float number
true/false boolean
date DateOnly (a Date at midnight UTC)
date-time Timestamp (a Date that keeps microseconds)
time, duration string
list, record arrays and objects
bytes Uint8Array
empty null

Returned values decide the column types (whole numbers BIGINT, Decimals exact decimals, …) unless the step or connector declared its columns (schema), whose types are kept when the values fit.

Type Is What it is
type Value string | number | bigint | boolean | null | Decimal | DateOnly | Timestamp | Date | Uint8Array | Value[] | { [key: string]: Value } Any value a cell can hold (see the table above).
type Row Record<string, Value> One row: column name → value.
type TableResult Table | Row[] | Record<string, Value[]> What a plugin may return as a table.
type ColumnTypeName string A column type as a plugin writes it: text, integer, decimal (or decimal(12,2)), float, boolean, date, datetime (or datetime (UTC) for instants), time, duration, binary, list, record.
type Config Record<string, unknown> Settings of a contribution, as validated against its JSON Schema in plugin.yaml.
type Awaitable T | Promise<T> A value, or a promise of it.
type ContributionKind keyof PluginDefinition connectors, steps, checks, outputs or actions.

Exact values#

Decimals, dates and date-times arrive as these classes, so no digit or microsecond is lost on the way. Return them (or plain numbers, strings and Dates) and the app keeps the exact value.

Decimal#

An exact decimal, kept as its text (Number(d) to compute with it).

Member What it is
readonly text: string The exact digits, as text.
new Decimal(text: string | number) From text such as "12.50", or a number. Anything that is not a decimal throws.
toString(): string The exact text.
toJSON(): string The exact text.
valueOf(): number As a JavaScript number, which may round.
toNumber(): number As a JavaScript number, which may round.
get scale: number Digits after the point.
get whole: number Digits before the point (leading zeros dropped).

DateOnly#

A calendar date: a Date at midnight UTC that prints as YYYY-MM-DD.

It extends Date.

Member What it is
new DateOnly(text: string | number | Date) From "YYYY-MM-DD", a time in milliseconds, or a Date.
toString(): string YYYY-MM-DD.
toJSON(): string YYYY-MM-DD.

Timestamp#

A date and time that keeps microseconds (micros, 0–999 beyond the milliseconds).

It extends Date.

Member What it is
micros: number The microseconds beyond the milliseconds, 0 to 999.
new Timestamp(text: string | number | Date) From ISO text (microseconds kept), a time in milliseconds, or a Date.
toISOStringMicro(): string ISO text with microseconds, UTC.
toJSON(): string ISO text with microseconds.

The context and the results#

PluginContext#

What every contribution function receives last.

Member What it is
readonly signal: AbortSignal Aborted when the user cancels: stop and throw (the process is stopped soon after anyway).
readonly pluginDir: string The plugin’s own folder (read-only for it).
readonly dataDir: string A folder the plugin may keep files in between runs (its tokens, caches).
readonly tempDir: string A folder for this call’s temporary files (removed afterwards).
log(...args: unknown[]): void A line in the plugin’s log (shown with its errors; never row values unless the plugin writes them).
progress(progress: { done?: number; total?: number; message?: string }): void Progress for the status bar.

ListItem#

Something a connector can read, for the source picker.

Member What it is
name: string What the connector’s settings name to read it: its own identifier.
title?: string How the source picker shows it.
description?: string One line under the title.

ReadRequest#

Member What it is
columns?: string[] Only these columns are needed (a hint: returning more is fine).
limit?: number Only this many rows are needed (a hint).

StepInput#

An input of a step as schema and compileSql see it: the name the SQL uses and its columns.

Member What it is
name: string input, input2, input3 …: the names compileSql’s SQL reads.
columns: Column[] Its columns, with their types in words.

Column#

A column of a table the plugin receives: its name and its type in words (decimal(10,2), date).

Member What it is
name: string The column’s name.
type: ColumnTypeName Its type in words: text, decimal(10,2), date (see ColumnTypeName).

ColumnDeclaration#

A column a plugin declares (schema): its name and type.

Member What it is
name: string The column’s name.
type: ColumnTypeName Its type in words (see ColumnTypeName).

Table#

Member What it is
columns: Column[] The columns, in order, with their types.
rows: Row[] One object per row: column name → value.

CheckVerdict#

How a check came out.

Member What it is
status: 'pass' | 'warn' | 'fail' pass when the rule holds; warn or fail when it does not. The check’s own severity decides what that does to the run.
observed: string What was seen, in plain words: “3 numbers are not valid VAT numbers”.
expected?: string What the rule asks for, in plain words: “every number is a valid VAT number”.
failing?: number[] Positions (0-based) in table.rows of the rows that break the rule: kept as the offending rows.
failingRows?: number How many rows break it, when failing is not given.
figure?: string | number The figure as exact text, for comparisons with later runs.

TableShape#

The table an output plans for: its columns and how many rows it has.

Member What it is
columns: Column[] The columns the output will receive.
rows: number How many rows it will receive.

WriteResult#

What an output’s write reports.

Member What it is
note?: string Plain sentence for the run record (“Posted 12 rows to the board”).
bytes?: number How many bytes were written, for the run record.

ActionRun#

The workflow run an action runs in.

Member What it is
runId: string The workflow run’s id.
workflowId: string The workflow’s id.
workflowName: string The workflow’s name.
params: Record<string, unknown> The workflow’s parameters.
trigger: string schedule, manual, file …
mode: 'full' | 'dryRun' dryRun in a dry run: deliver nothing for real.
attempt: number 1 the first time; higher when the action is tried again after a temporary failure.

ActionResult#

Member What it is
message?: string Plain words for the run record.
status?: 'succeeded' | 'skipped' skipped records the node as skipped; the default is succeeded.

Errors#

PluginError#

A failure the plugin explains itself: its message is shown to the user as written (“The API key was refused: check it in the connection”). Anything else a plugin throws is shown as the plugin’s own error with its stack.

It extends Error.

Member What it is
readonly code: string A short code of your own (default PLUGIN_ERROR), kept with the error.
readonly details: unknown Anything that helps someone fix it; shown under Details.
readonly temporary: boolean True when trying again later may work (a service that is down): workflow actions are then retried.
new PluginError(message: string, options: { code?: string; details?: unknown; temporary?: boolean } = {}) The message is shown as written. temporary: true marks a failure that trying again may fix.

Anything else a plugin throws is shown as the plugin’s own error, with its stack under Details. A refused permission (a file outside the plugin’s folder, a program it was not allowed to start) names what was refused.

plugin.yaml#

The manifest sits at the top of the plugin’s folder. Its fields, as the app reads them:

Field Takes What it is
gridkiln plugin may be left out Says the file is a plugin manifest.
schemaVersion a whole number may be left out The version of this file’s format: 1.
id text required A unique name in lower case, such as acme.geocoder. It names the plugin’s folder and appears in the pipelines that use it.
name text required The name people see.
version text required Its version, such as 1.2.0.
description text optional One sentence, shown in Settings › Plugins and when installing it.
author text optional Who wrote it.
licence text optional Its licence, such as MIT.
homepage text optional Where to get it and read about it (shown when a project needs it).
requires text optional Minimum app version (semver range).
main text required Entry module (ESM), relative to the plugin folder.
capabilities a list of network, filesystem, process optional What it may do beyond its own folder (Capabilities). Leave it out to ask for nothing.
contributes the lists below required What the plugin adds, by type.
contributes.connectors a list, each with name, title, configSchema optional Connectors: each name as the code exports it, a title, and a configSchema.
contributes.steps a list, each with name, title, family (optional), configSchema optional Step types: name, title, configSchema, and the family (such as clean or calc) it belongs with.
contributes.checks a list, each with name, title, configSchema optional Check kinds: name, title, configSchema.
contributes.outputs a list, each with name, title, configSchema optional Output kinds: name, title, configSchema.
contributes.fileFormats a list, each with name, title, extensions, configSchema optional File formats (name, title, extensions, configSchema). Accepted in the manifest, but plugins cannot read or write file formats yet: no code contribution serves them.
contributes.actions a list, each with name, title, configSchema optional Workflow actions: name, title, configSchema.
contributes.templates a list, each with name, title, file optional Template files it ships: name, title, and file, which must be in the plugin’s folder.

Each configSchema is a JSON Schema for an object (type: object); a contribution without one takes any settings. default values in the schema are filled in before the plugin is called, and settings that do not fit the schema are refused with the reason before the plugin sees them.

Beyond the schema, the app checks:

  • id is lower case letters, digits, dots, dashes and underscores (it names folders and appears in documents)
  • version is semantic (1.2.0, 1.2.0-beta.1); requires is a range the app’s version must meet (>=1.0)
  • main is a file inside the folder, with an extension Node runs as ESM (.mjs, .js, .mts, .ts)
  • contribution names are identifiers, unique within their type, and each settings schema is a valid object schema
  • gridkiln: plugin and schemaVersion: 1 may be left out (they are filled in), so a first plugin needs less

A manifest that fails a check is listed in Settings › Plugins with each problem in one sentence, and the plugin never runs.

Capabilities#

A plugin’s process starts with no network, no access to files outside its own folder and the tables it is handed, and no way to start other programs. capabilities in plugin.yaml asks for more. The install dialog shows each one in these words, and the person installing it must tick “I trust … with this access” before it is installed; a project’s plugin that nobody on this computer confirmed never runs.

Capability The install dialog says And explains
network Uses the network It can send and receive data over the internet or your local network, including the rows it is given. Without this, its process has no network access.
filesystem Reads and writes files outside its folder It can open, change and delete any file you can. Without this, it sees only its own folder and the files Gridkiln hands it.
process Starts other programs It can run programs on this computer, which are not limited the way the plugin itself is.

The protocol#

The app talks to a plugin’s process over its IPC channel with the same request, response, progress and cancel messages the app’s own engine uses. A plugin author never handles these messages: definePlugin’s runtime does. They are listed for anyone hosting plugins elsewhere, or reading a plugin’s log. The runtime speaks protocol version 1; the app refuses a plugin built for a newer one.

Method Sends Answer Notes
plugin.hello { apiVersion: number; pluginDir: string; dataDir: string } { apiVersion: number; contributions: Record<ContributionKind, string[]> } What the module exports, checked against plugin.yaml.
connector.list { name: string; config: Config } & CallFolders ListItem[] The connector’s list.
connector.schema { name: string; config: Config } & CallFolders { columns: ColumnDeclaration[] } | null The connector’s schema; null when it has none.
connector.read { name: string; config: Config; request: ReadRequest } & CallFolders { rows: number } Writes out.jsonl and out.schema.json into tempDir.
step.schema { name: string; config: Config; inputs: StepInput[] } & CallFolders { columns: ColumnDeclaration[] } | null The step’s schema; null when it has none.
step.compileSql { name: string; config: Config; inputs: StepInput[] } & CallFolders { sql: string } | null The step’s compileSql; null when it has none (then step.transform is used).
step.transform { name: string; config: Config; inputs: ExchangeTable[] } & CallFolders { rows: number } Writes out.jsonl and out.schema.json into tempDir.
check.evaluate { name: string; config: Config; input: ExchangeTable } & CallFolders CheckVerdict & { failingIds?: (number | string)[] } failing comes back as the hidden row ids (__gk_row) of the failing rows when the input carried them.
output.plan { name: string; config: Config; table: TableShape } & CallFolders { targets: string[] } The output’s plan, as a list of targets.
output.write { name: string; config: Config; input: ExchangeTable; target: string } & CallFolders WriteResult The output’s write, once per target, on a real run only.
action.run { name: string; config: Config; run: ActionRun } & CallFolders ActionResult The action’s run.

Tables cross as JSON lines in the call’s own folder (tempDir), every value as its exact text; readExchangeTable and writeExchangeTable read and write that format.

ExchangeTable#

A table in a file of the exchange folder: JSON lines, every value as its exact text (or null).

Member What it is
file: string Absolute path.
columns: ExchangeColumnSpec[] Its columns.
rows: number How many rows the file holds.

ExchangeColumnSpec#

A column as the engine hands it over: its name, its kind and the type in words.

Member What it is
name: string The column’s name.
kind: string text, integer, decimal, float, boolean, date, datetime, time, duration, list, record, binary.
label?: string The type in words (decimal(10,2), datetime (UTC)); kind when absent.

servePlugin#

servePlugin(definition: PluginDefinition, transport: PluginTransport, options: ServeOptions = {}): () => void

Serves a plugin’s contributions over transport (the loop the plugin’s process runs). Returns a stop function.

Testing a plugin without the app uses it: see Testing a plugin.

ServeOptions#

Member What it is
pluginDir?: string The plugin’s folder (read-only for it).
dataDir?: string Its folder for files kept between runs.
log?: (line: string) => void Where ctx.log goes (default: standard error).

PluginTransport#

What the server talks over (the shape of core’s RpcTransport).

Member What it is
send(message: Envelope): void Sends one message to the other side.
onMessage(listener: (message: unknown) => void): () => void Calls the listener with every message from the other side; returns a function that stops it.