caique/plugin
Every export of caique/plugin, with its signature and doc comment: validate, register, reset, registered, widgets, widgetFor and 4 more, plus 5 types.
import { validate, register, reset, … } from 'caique/plugin';Functions
kinds
Every kind that can be drawn right now: the six, plus whatever is registered.
function kinds(): string[];Returns string[]
projectionOf
The static projection for any kind — the one surface a caller needs.
function projectionOf(spec: PromptSpec): string;| Parameter | Type |
|---|---|
spec | PromptSpec |
Returns string
register
Register a plugin. Later wins, like ESLint flat config: the array is ordered, a caller reads it top to bottom, and the last word on a kind is the one nearest the program.
function register(plugin: unknown): void;| Parameter | Type |
|---|---|
plugin | unknown |
Returns void
registered
The plugins registered, in registration order.
function registered(): readonly Plugin[];Returns readonly Plugin[]
reset
Forget every registered plugin. For tests, and for a program that re-registers at runtime.
function reset(): void;Returns void
validate
Refuse a plugin that cannot contribute a widget, at the door.
function validate(plugin: unknown): asserts plugin is Plugin;| Parameter | Type |
|---|---|
plugin | unknown |
Returns asserts plugin is Plugin
widgetFor
The widget that draws kind, or nothing when no plugin registered one.
function widgetFor(kind: string): Widget | undefined;| Parameter | Type |
|---|---|
kind | string |
Returns Widget \| undefined
widgets
Every kind a plugin contributed, with who won it and who it shadowed.
function widgets(): Contribution[];Returns Contribution[]
Classes
PluginError
A refused plugin says what is wrong and what to do about it — the family's one vocabulary.
class PluginError extends Error {
readonly code: PluginErrorCode;
readonly fix: string;
constructor(code: PluginErrorCode, message: string, fix: string);
}Constants
CONTRACT
The plugin contract version. One number for the family — the same 1 flagstaff and
roundel declare, written out rather than imported for the reason in the file comment.
const CONTRACT = 1;Interfaces
Contribution
Which plugin last contributed each kind — the shadowing a plugin check prints.
interface Contribution {
kind: string;
from: string;
/** Plugins that contributed this kind earlier and were overridden, in order. */
shadowed: string[];
}Plugin
The keys caique reads. Declared structurally: any object with these fields is a plugin here, whatever else it carries.
interface Plugin {
name: string;
contract?: number;
widgets?: Record<string, Widget>;
/**
* A locale pack (`localised-human-surfaces` R6): language tag → message id → translation. caique
* reads the ids that begin `caique.` and leaves the rest to the package that owns them, so the
* one object burgee registers for its own messages carries these too. Checked where it is
* first used — the run whose locale it speaks — and by `caique check`, not here: this door is
* on every entry's startup path, and the check is the catalog's weight.
*/
locales?: Locales;
}Widget
How a plugin draws one kind of prompt.
interface Widget {
static: (spec: PromptSpec) => string;
frame?: (t: number, spec: PromptSpec) => string;
sample?: WidgetSample;
}WidgetSample
Two named states of plain data, which a grader renders a widget with (R7).
interface WidgetSample {
running: unknown;
done: unknown;
}Types
PluginErrorCode
type PluginErrorCode = 'E_PLUGIN_SCHEMA' | 'E_PLUGIN_CONTRACT' | 'E_NO_STATIC_PROJECTION' | 'E_UNKNOWN_KIND' | 'E_NO_CONTRIBUTION';