sutram docs
All pages

Install

One script, no bundler

Load dist/sutram.js from a CDN, or from the package. It registers your commands as WebMCP tools where the browser supports them, and exposes everything as globalThis.Sutram. Mount the console where you want it:

<script type="module">
  import Sutram from
    "https://cdn.jsdelivr.net/npm/@d34dman/sutram@0.8/dist/sutram.js";

  Sutram.register({ /* a command */ });
  Sutram.mountConsole();
</script>

Pin the minor version, as above. dist/sutram.min.js is the same code without comments and indentation, about a quarter smaller. Names are not shortened, so stack traces still read.

npm

npm install @d34dman/sutram

With a bundler, import the registry, the console and WebMCP:

import { getRegistry } from "@d34dman/sutram";
import { mountConsole } from "@d34dman/sutram/console";
import { connectWebMCP } from "@d34dman/sutram/webmcp";

const registry = getRegistry();
registry.register({ /* a command */ });

// The console, for people.
mountConsole();
// The same commands as WebMCP tools, where the browser supports them.
connectWebMCP(registry);

Unlike the one-script build, the modules do nothing until you call them, so remember connectWebMCP(). TypeScript declarations ship with the package (types/), for every entry point and for globalThis.Sutram.

Drupal

composer require drupal/sutram, then enable the module. It ships the package build; nothing is loaded from a CDN. See Drupal.

Details

Entry points

You need the first three, or only the one-script build. The others are for special cases.

ImportWhat it isNeeds a DOM
@d34dman/sutramWhat app authors use: the registry, formats, the policy, commandLine(), agentPrompt()no
@d34dman/sutram/console<sutram-console>, the console, as a web componentyes
@d34dman/sutram/webmcpMirrors the registry into document.modelContext as WebMCP toolsno
@d34dman/sutram/eventsEvents your app declares and emits, and the events list, events recent and events wait commandsno
@d34dman/sutram/clientFor a client of your own: parse and complete command lines, check input, run status, format resultsno
@d34dman/sutram/browserglobalThis.Sutram: the registry and its helpers, with /client as Sutram.clientyes
@d34dman/sutram/dist/sutram.jsThe same as browser, bundled into one file; sutram.min.js strippedyes
@d34dman/sutram/navThe nav kit: nav status, menu, search and go over menus your adapter suppliesno
@d34dman/sutram/dist/nav.jsThe nav kit as a file of its own, for pages that load dist/sutram.js; adds Sutram.kits.navyes
@d34dman/sutram/pageThe page kit: page status from your adapterno
@d34dman/sutram/userThe user kit: user status, login and logoutno
@d34dman/sutram/messagesThe messages kit: messages status and message.shown eventsno
@d34dman/sutram/listsThe lists kit: listing status, rows and go over listings your adapter describesno
@d34dman/sutram/formsThe forms kit: form list, status, fields, get, set, submit and discard, and add, remove, search and upload where your adapter has themno
@d34dman/sutram/dist/page.js · user.js · messages.js · lists.js · forms.jsThose kits as files of their own, like dist/nav.js; add Sutram.kits.page, .user, .messages, .lists and .formsyes
@d34dman/sutram/internalsHelpers Sutram uses itself. No semver promiseno

Several copies on one page

If two scripts each bundle their own copy of Sutram, they still share one registry, one format registry and one event bus, so every command ends up in the same console and the same tool list. That holds for copies of the same registry version: 0.4 and later do not share a registry with 0.3 or earlier, and warn when both are on a page. Load one version.

This page as MarkdownEdit on GitHub