Appearance
SlashCommandPlugin
Drives the command system from a text input. The user types /command param=value, and the plugin parses it into a CommandInvocation and runs it through CommandRunnerService. It handles autocomplete suggestions, typed parameter parsing, and command chaining with &&.
This is the human-typed counterpart to the LLM-facing command catalog. Both paths run through the same execute/executeBatch methods on CommandRunnerService. See CommandRunnerService.
The class is tagged @internal in source but is exported from src/plugins/index.ts and the SDK entry point, so it is reachable by consumers. Treat it as an optional convenience layer over the command runner.
Usage
Register the plugin (it depends on the commands service), then bind it to an <input> element. Suggestions and results are delivered over the event bus.
ts
import { ViewerCore, SlashCommandPlugin } from "@optellix/xviewr-sdk";
const viewer = new ViewerCore(container, config);
await viewer.ready();
await viewer.loadPlugin(new SlashCommandPlugin());
const slash = viewer.pluginManager.getPlugin("slash-commands") as SlashCommandPlugin;
const input = document.querySelector("#command-input") as HTMLInputElement;
slash.attachToInput(input);
viewer.eventBus.on("slash:suggestions", ({ suggestions }) => renderSuggestions(suggestions));
viewer.eventBus.on("slash:executed", ({ command, result }) => console.log(command, result));Registered name: slash-commands. Service dependencies: commands. The plugin does not declare its own commands; it executes the commands other plugins register with CommandRunnerService.
Public API
| Method | Description |
|---|---|
attachToInput(input) | Bind to an HTMLInputElement. Listens for input (suggestions) and keydown Enter (execute). Detaches any previous element first. |
detachFromInput() | Remove the listeners and clear the bound element. |
getAvailableCommands() | All command definitions currently registered with the runner. Empty if the commands service is unavailable. |
getCurrentSuggestions() | The suggestion list from the last input change. |
execute(commandString) | Run a command string programmatically (same path as pressing Enter). Supports chaining with &&. |
Input syntax
- A command line starts with
/:/set-view preset=top. - Parameters are
key=value. Values parse as number, boolean (true/false), JSON object/array ({...}/[...]), or string. Quotes group values with spaces:name="left side". - Chain commands with
&&:/select-all && /focus-selection. Only the first command in a chain needs the leading/. - Execution runs through
executeBatchwithstopOnError: true. The chain stops at the first failure, and the runner never throws.
Events
| Event | Payload |
|---|---|
slash:suggestions | { suggestions } (command or parameter suggestions for the current segment) |
slash:executed | { command, parameters, result, chainIndex, totalCommands } (per successful command) |
slash:error | { error, command?, parameters?, chainIndex?, totalCommands? } |
slash:chain-completed | { commands, totalCommands } (emitted once on full-chain success) |
Example
ts
const slash = viewer.pluginManager.getPlugin("slash-commands") as SlashCommandPlugin;
// Run a two-step chain without any UI.
await slash.execute('/set-view preset=front && /screenshot width=1920 height=1080');