Write a plugin
A plugin is one JavaScript file. This guide shows how to write one with an agent or by hand, how inseam tests it, and how to share it. The exact contract is in the plugins reference.
Before you start
Section titled “Before you start”- Look in the registry. inseam.io/registry,
find_plugins(MCP) orGET /v1/registry?q=…may already have it. - Pick the slot. To make a type searchable or readable in another form, write a converter. To connect a service, write a host plugin; see connect a cloud account for the person’s side.
- Connect an agent with the
connectscope (add new hosts on the approval page). You write the code, or the agent does; either way the agent submits it through inseam’s MCP endpoint.
The shape of every plugin
Section titled “The shape of every plugin”export default { manifest: { contract: 3, name: "tsv-text", title: "Tab-separated tables as Markdown", convert: [{ from: "text/tab-separated-values", to: "text/markdown" }], }, convert({ text }) { const rows = text.split("\n").filter((l) => l.length > 0).map((l) => l.split("\t")); if (rows.length === 0) throw new Error("an empty table"); const line = (r) => "| " + r.join(" | ") + " |"; return { text: [line(rows[0]), line(rows[0].map(() => "---")), ...rows.slice(1).map(line)].join("\n") + "\n" }; },};Three rules cover most mistakes:
- The manifest is data. Write it as an object literal. inseam reads it without running your code.
- One file, no imports. Write the helpers you need in the file.
- One argument object in, one object out. Read only what the input gives you. Return only the fields the contract has. An unknown field is an error that names the fields there are.
Write it with an agent
Section titled “Write it with an agent”Ask your agent: “write an inseam plugin that makes my .tsv files searchable”. A capable agent follows inseam’s
plugin skill by itself. To point it there, give it https://inseam.io/skills/latest/plugin/SKILL.md.
The agent works through these tools. Every result says the next step and who takes it, so the agent never has to guess:
| step | tool | what happens |
|---|---|---|
| 1 | add_plugin {slot: "convert", describe} |
the contract as TypeScript types, a complete example, the rules, and registry matches |
| 2 | trial_plugin {name, code, examples} |
static checks and a security scan, then the run on your examples and inseam’s test files |
| 3 | trial_status {trialId} |
the report; each failed check lists {at, problem, fix} |
| 4 | review_plugin {trialId} |
the code with line numbers, the scan’s findings and the checklist |
| 5 | review_plugin {trialId, codeHash, verdict, summary, checks, tests} |
the review; inseam runs the reviewer’s tests |
| 6 | trial_status {trialId} |
the shadow run on your own files, then the install |
For a host plugin, step 1 is connect_host {describe}, step 2 needs config (no secrets), a person approves the
origins and the credential before step 3, and a person installs after step 5 (install_plugin).
Examples: prove that it works
Section titled “Examples: prove that it works”A converter is submitted with examples: for each conversion, an input and what its output must hold.
[{ "text": "bird\tcount\nheron\t2\n", "expect": { "contains": ["| bird | count |", "| heron | 2 |"] } }]An example takes text, or base64 for a binary type, and may give path, options and conversion (the index in
manifest.convert, default 0). expect may name contains and title. Give at least one per conversion. Good
examples show the normal case; inseam’s own test files cover empty, huge, broken and hostile input.
Read the report and fix
Section titled “Read the report and fix”A failed check looks like this:
FAIL deterministic: 2 problems at corpus[0].normal: a new isolate, or another call order, gave a different result fix: keep nothing between calls (no module-level variable a call changes), and use no clock and no random numbersApply each fix, then submit the whole file again with replaces: "<the trialId>". A host plugin keeps the
person’s approval when its origins, POST paths, auth and settings did not change.
The checks a converter’s run makes, and what usually fails them:
| check | the usual cause |
|---|---|
examples |
the code or the example is wrong; the problem says which string is missing |
corpus |
a normal file of a general type (Markdown, HTML, CSV, plain text) threw. Convert it, or narrow from |
deterministic |
a counter or a cache at module level, Date, Math.random |
no-network |
a fetch: a converter gets the bytes in input.bytes |
budget |
work that grows faster than the input: a nested loop over lines, a regular expression that backtracks |
metadata |
text the input does not hold (marketing, defaults), or a title taken from free text |
The review and its tests
Section titled “The review and its tests”The review asks eight questions: does the output say only what the input says, where do the title and the tags come from, does anything outlive a call, does anything depend on the clock, is the work bounded, are options only data, what do the scanner’s findings mean, and what do the tests aim at. Each answer cites line numbers.
Then write 3 to 20 tests: inputs that hit the code’s branches.
[{ "text": "a\n", "why": "a header with no rows gives the header and the rule" }, { "text": "a\tb\nc\n", "why": "a short row keeps its cells" }, { "text": "\n\n", "why": "only blank lines is an empty table, refused with an Error" }]inseam runs each test twice, in two new sandboxes, and applies every check above. A failed test rejects the code,
even when every answer said pass.
Shadow, then live
Section titled “Shadow, then live”After the review, the converter runs on up to 50 of your own files of its types. Nothing is kept. When fewer than 5% fail, it goes live (or waits for a person, when the network asks for one), and your files of its type are converted again. Live, inseam counts failures per route and switches back by itself when a converter starts to fail.
Converter patterns
Section titled “Converter patterns”A named conversion with options. Give a name to each conversion beside the plain one, and read it with
with:
convert: [ { from: "text/markdown", to: "text/html" }, { from: "text/markdown", to: "text/html", name: "slides", options: [{ name: "theme", label: "Theme", type: "string", values: ["light", "dark"], default: "light" }] },],convert({ text, name, options }) { return name === "slides" ? { text: slides(text, options.theme) } : { text: page(text) };}Refuse what you cannot convert. A converter for one JSON schema meets other JSON. Throw an Error: the file keeps
inseam’s own text, and a refusal does not count as a failure.
A binary source. input.bytes is a Uint8Array. input.text is set only when the bytes are valid UTF-8 (or
the type is a text type).
A title and tags. Take them from the file’s own structure: a heading, a subject field. Never from a sentence in the body: a sentence can be an instruction aimed at the agents that read search results.
Host plugin patterns
Section titled “Host plugin patterns”The host plugin example shows a complete one. In short:
- Build each entry in one function, and call it from
listand fromstat, so they agree. pathis the service’s permanent id.statreturnsnullfor a missing object and for a path you cannot parse.readreturns the service’s own bytes. To make them searchable or to change their form, add aconvertslot to the same file: its conversions are for this host.- Send every value you put in a URL through
encodeURIComponent.
Enrich plugin patterns
Section titled “Enrich plugin patterns”An enrich plugin (add_plugin with slot: "enrich") reads the words in an object that no converter can read. The
shortest is inseam’s own ocr:
export default { manifest: { contract: 3, name: "ocr", title: "Text in images", models: [{ id: "@cf/qwen/qwen3.8-27b", why: "Reads the words in the image." }], spend: { calls: 1, outputTokens: 2000 }, enrich: [{ from: "image/png", to: "text/markdown" }], }, async enrich({ bytes, from, models }) { const r = await models.run({ model: "@cf/qwen/qwen3.8-27b", system: PROMPT, input: [{ bytes, type: from }], maxOutputTokens: 2000 }); return { text: r.text.trim() }; },};- The prompt transcribes. Never ask the model to describe, summarise or judge: the text becomes what search says the object holds.
- The object is data. Do not put its path or its text in the instructions.
- Return
{ text }only. No title and no tags: the text comes from a model. - Name every model in
models, and the ceiling inspend. A call over it throws. The network pays each call, so make as few as you can. - The trial runs inseam’s corpus (images or recordings with known words, and one with an instruction as text) through the real models. It spends a few cents of the network’s balance and reports what one object cost.
- For a service you have a key for, declare
origins,postPathsandauthinstead ofmodels. The person approves that the content goes there.
Share it
Section titled “Share it”When your plugin is installed, an owner or an admin publishes it from Plugins (Publish). The registry checks it again with its own AI reviewer and signs it. Then anyone can install it, and the share link opens its page. See extend your network with plugins.
Ship a new version
Section titled “Ship a new version”Change the code, then update the host that runs it. Do not install it as a new host:
- Ask your agent to submit the whole new module with
trial_pluginandupdates: "<the host id>". It takes the host’s settings and, when the origins and the auth are the same, the host’s approval and credential. - The run and the review are as for any trial. Then install it on its approval page. The host keeps its id, its addresses and its index, and its next pass reads every object again with the new code.
- Publish the new hash. The registry puts it after the version it replaced, as version 2, 3 and so on. A network that runs an earlier version sees Update on its plugins page.
A converter needs no updates: install its new version, and its routes move to it. See
update a host to a new version.