The new package packages/plugin-sdk (@runestone/plugin-sdk) is the one source of the public plugin types. It contains PluginApi and its members, the manifest type, API_VERSION, and feature checks (hasFeature, requireFeature, requireFeatures, missingFeatures). It also contains the action icons and the tooltip helper as DOM functions, because RuneStone has no API for them. Menus stay host-drawn through api.ui.showActionMenu, so the SDK contains only the menu types. The SDK uses the Apache License 2.0. The host imports the SDK with relative paths in src/lib/plugins/sdk.ts, src/lib/ui/actionIcons.ts, and src/lib/ui/tooltip.ts. The completion, Git, background, and contribution contract files export the SDK types. The menu files keep their types, because the Terminal plugin keeps copies of them. A unit test makes sure that those types and the SDK types are the same. The menu inventory now scans the SDK source. pnpm sdk:build compiles the SDK to dist/. pnpm release:sdk --version <v> builds it, then commits and tags v<v> in a local clone of the public repository. It never pushes, and it prints the push commands. It stops before a change in these conditions: - The clone is missing, has changes, or is not on a branch. - The tag exists, or the version is not greater than the current version. - The package has no LICENSE file, or the SDK source has changes that are not committed. A failed attempt restores the version and the clone. pnpm check type checks the SDK and the example plugin. The example plugin now has JSDoc types from the SDK. pnpm test covers the feature checks, the host and SDK parity, and the release script with temporary Git repositories. The plugin development, release, development, and completion guides describe the SDK.
5.6 KiB
Completion plugin API
Plugin development · Plugin API
api.completion (version: 1) lets plugins show autocomplete in RuneStone editors and in their own text fields, and supply the suggestions.
api.completion is optional. Older hosts do not have it, and transport can be absent. Make sure that a member exists before you call it.
The SDK type is CompletionApi. See Install the SDK.
| Member | Contract |
|---|---|
registerInput(element, options) |
Add autocomplete to an <input> or <textarea>. Returns a handle. |
registerSurface(surface) |
Add autocomplete to a custom editor. Returns a handle. |
registerProvider(provider) |
Supply suggestions. Returns a cleanup function. |
invalidate() |
Dismiss all visible suggestions. |
transport(request, signal, onLine) |
Optional. Send a request to a local model server. |
The host adds the plugin ID as a prefix to field and provider IDs. Each field ID must be unique among the active fields. The host disposes all registrations when the plugin stops.
Register a field
const completion = api.completion;
if (completion?.version === 1) {
const field = completion.registerInput(textarea, {
id: "draft",
kind: "prose",
sensitive: false
});
api.onDispose(() => field.dispose());
}
registerInput options are id, kind ("prose" default, or "code"), and sensitive.
The host shows the suggestion in a box below the field. It treats inputs of types other than text and search as sensitive.
| Key | Action |
|---|---|
| Tab | Accept the suggestion. |
| Escape | Dismiss the suggestion. |
| Ctrl+Alt+Space (Cmd+Alt+Space on macOS) | Request a suggestion now. |
| Ctrl+Alt+Right (Cmd+Alt+Right on macOS) | Accept the next word. |
The RuneStone Markdown editor and code editor are also completion surfaces. They show the suggestion as faded italic text at the caret.
Custom editors
registerSurface({ id, snapshot, preview, insert }) connects a custom editor.
snapshot()returns the current state:documentId,revision,text,caret,selectionEnd,focused,composing,sensitive,readOnly,kind, andlanguage.preview(text)shows a suggestion.nullremoves it.insert(text, expected)inserts the accepted text. Do it as one undoable edit. Returnfalsewhen the editor state no longer matchesexpected.
The returned handle has changed(), request(), accept(word?), dismiss(), and dispose(). Call changed() after each edit.
When the host asks for a suggestion
The host asks only when all of these conditions are true:
- The field has focus, and no selection.
- The field is not read-only or sensitive, and no IME composition is in progress.
- The text before the caret contains more than spaces.
- For prose, the caret is not in a table row, a link target, or an HTML tag.
- For prose, the caret is not in inline code, a code fence, or front matter.
Register a provider
const stop = api.completion.registerProvider({
id: "local",
delayMs: 200,
timeoutMs: 1000,
async complete(request, publish) {
const text = await suggest(request.prefix, request.suffix, request.signal);
return text;
}
});
Only one provider can be active in a window. A second registration throws an error.
| Field | Rule |
|---|---|
delayMs |
Wait after the last edit. Default 200, from 100 to 1,000 milliseconds. |
timeoutMs |
Time limit for an automatic request. Default 1,000, from 300 to 5,000 milliseconds. A manual request has 10 seconds. |
complete(request, publish) |
Returns the final text, or null. Call publish(text) to show partial text before the end. |
The request contains surfaceId, documentId, revision, prefix, suffix, kind, language, manual, and an abort signal.
prefix has at most 3,000 characters before the caret. suffix has at most 600 characters after the caret.
The host ignores a suggestion longer than 2,000 characters or one with control characters.
No text goes into the document until the user accepts it. Then the host makes sure that the document revision and the caret did not change.
Call invalidate() when the provider settings or its context change.
Local transport
transport(request, signal, onLine) sends one request to a model server on the same computer, through the desktop host.
It calls onLine once for each response line. It is not a general HTTP API.
| Item | Rule |
|---|---|
endpoint |
http or https on 127.0.0.1, [::1], or localhost, with path / or /v1. No credentials, query, or fragment. |
route |
/v1/models, /v1/chat/completions, /api/tags, or /api/generate. |
body |
Optional JSON text, at most 32 KiB. With a body, the host sends POST. Without one, it sends GET. |
timeoutMs |
Default 5,000, from 100 to 15,000 milliseconds. The connection limit is 2 seconds. |
| Response | At most 64 KiB for each line and 256 KiB in total. |
| Concurrent requests | At most 16 across all windows. |
The host does not follow redirects and does not use a system proxy. It sends no credentials. Abort stops the display at once. A blocked network read can continue until the request timeout.
Trust
Plugins keep full application access. This API does not add a permission sandbox. The API does not include context sources, remote model servers, or credential storage.
For tests, see tests/unit/plugins/completion.spec.ts. For a provider plugin, see the Local Autocomplete trial guide.