58 lines
2.5 KiB
Markdown
58 lines
2.5 KiB
Markdown
# Completion plugin API
|
|
|
|
This source update adds `api.completion`, capability version 1. It is optional in package API version 1.
|
|
|
|
Plugins must feature-detect it. The existing 0.1.7 installer does not contain this source update.
|
|
|
|
## Register a field
|
|
|
|
```javascript
|
|
const completion = api.completion;
|
|
if (completion?.version === 1) {
|
|
const field = completion.registerInput(textarea, {
|
|
id: "draft",
|
|
kind: "prose",
|
|
sensitive: false
|
|
});
|
|
api.onDispose(() => field.dispose());
|
|
}
|
|
```
|
|
|
|
The host prefixes field IDs with the owning plugin ID and disposes registrations when the plugin stops. IDs must be unique per active owner.
|
|
|
|
Inputs and text areas use a preview below the field. Custom editors use `registerSurface` with snapshot, preview, and insert callbacks.
|
|
|
|
Snapshots include document identity, revision, caret, selection, focus, composition, sensitivity, read-only state, and prose or code kind.
|
|
|
|
The host validates the snapshot before acceptance. Custom insert callbacks must make one undoable transaction and reject stale expected text.
|
|
|
|
## Register a provider
|
|
|
|
`registerProvider` accepts an ID, delay, deadline, and an asynchronous completion function. Only one provider can be active in a window.
|
|
|
|
The function receives bounded prefix and suffix text, document and surface identity, language, mode, and an abort signal.
|
|
|
|
It can publish partial text through its callback and return the final insertion. No candidate enters the document before acceptance.
|
|
|
|
Call `invalidate()` when settings or reference context changes.
|
|
|
|
## Local transport
|
|
|
|
`transport(request, signal, onLine)` sends a bounded request through the desktop host. Each callback receives one response line.
|
|
|
|
Supported routes are `/v1/models`, `/v1/chat/completions`, `/api/tags`, and `/api/generate`.
|
|
|
|
Only explicit loopback addresses are allowed. Redirects and system proxies are disabled. Request bodies and responses have size limits.
|
|
|
|
The transport supports no remote credentials in this version. It is not a general HTTP API.
|
|
|
|
The host cancels display immediately. A blocked native read can continue until its bounded timeout.
|
|
|
|
## Current boundaries
|
|
|
|
Surface and provider APIs are available. Automatic context-source registration, remote adapters, and credential storage remain planned.
|
|
|
|
External plugins retain RuneStone's existing full-application trust level. This API does not add a permission sandbox.
|
|
|
|
See [the implementation](../src/lib/completion/contracts.ts), [host tests](../scripts/completion.spec.ts), and the [plugin trial guide](../../RuneStone_Local_Autocomplete/docs/trial-guide.md).
|