Extensions SDK
Build small apps that run inside a Syncropel workspace. The SDK handles the connection to the workspace, the permissions your app asks for, and writing, querying and subscribing to records.
What this is
@syncropel/extensions is the SDK for building in-workspace apps: tools that run in an iframe inside a Syncropel workspace and work with the user's live records. It lets a third-party panel or mini-app talk to the workspace without either side having to trust the other.
The SDK handles:
- The connection handshake with the workspace
- Permissions: your extension asks for what it needs, and the workspace decides what to grant
- Typed emit, query, subscribe and navigate operations
- iframe behaviour: height, status indicators, and shutdown
- Checking that messages are well formed
Install
npm install @syncropel/extensionsIt has no runtime dependencies and is written in TypeScript.
Hello extension
import { createAdapter } from "@syncropel/extensions";
const adapter = createAdapter({
ext: { name: "MyApp", version: "1.0.0" },
capabilities: ["records.emit", "records.query"],
onInit: ({ actor, namespace, capabilities_granted }) => {
console.log(`Ready as ${actor} in ${namespace}`);
console.log("Granted:", capabilities_granted);
},
onSelectionChange: ({ selection }) => {
console.log("Host selected:", selection);
},
onRecords: ({ subscription_id, records }) => {
console.log(`Sub ${subscription_id} delivered`, records.length, "records");
},
});
// Emit a record
const result = await adapter.emit({
act: "PUT",
body: { title: "Event", at: Date.now() },
thread: "th_app_events",
});The adapter connects to the workspace, sends your list of capabilities, and calls onInit with the capabilities the workspace actually granted.
Capabilities
An extension asks for some of 11 capabilities. The workspace may grant all, some, or none of them, so always check capabilities_granted before using a feature that depends on one.
| Capability | What it grants |
|---|---|
records.emit | adapter.emit() |
records.query | adapter.query() |
records.subscribe | adapter.subscribe() + adapter.unsubscribe() |
navigate | adapter.navigate() to change host view |
permissions.camera | iframe can request navigator.mediaDevices.getUserMedia({ video }) |
permissions.microphone | same for audio |
permissions.clipboard | clipboard read/write in iframe |
permissions.fullscreen | fullscreen API |
permissions.notifications | notification API |
sharedArrayBuffer | Shared memory for WebAssembly threads |
persistent-storage | Storage that the browser keeps |
The adapter API
Records
// Emit a record. Resolves when the workspace confirms it was saved.
const emit = await adapter.emit({
act: "PUT", // "GET" | "PUT" | "CALL" | "MAP" | "INTEND" | "DO" | "KNOW" | "LEARN"
body: { /* your payload */ },
thread: "th_optional",
parents: ["record_id_optional"],
});
if (emit.status === "ok") {
console.log("record id:", emit.result.id);
}
// One-shot query (the workspace validates it)
const q = await adapter.query({ kind: "app.note", limit: 20 });
// Live subscription: records arrive via onRecords hook
const sub = await adapter.subscribe({ kind: "app.notification" });
const subscriptionId = sub.result.subscription_id;
// Stop receiving
await adapter.unsubscribe(subscriptionId);Navigation
await adapter.navigate("/docs/operate/keyring");Takes the workspace to the given URL (the workspace only allows valid routes).
iframe height and status
// Tell the host how tall you need to be (px, clamped 0–10000)
adapter.setHeight(800);
// Update the status pill shown in the host chrome
adapter.setStatus({
label: "Syncing…",
tone: "info", // "info" | "warn" | "error" | "success"
indicator: "pulse", // "pulse" | "static" | null
});Cleanup
// Unbind listeners, stop processing messages. Safe to call from
// a React useEffect cleanup or a web-component disconnectedCallback.
adapter.destroy();Message format (reference)
The adapter handles this for you. You only need it to debug or to build your own host. Messages travel both ways over window.postMessage and are checked on both sides.
Host → Extension: hello, context.update, records.update, action.result, goodbye
Extension → Host: ready, records.emit, records.query, records.subscribe, records.unsubscribe, navigate, height, status
Every envelope has:
{
sap: "0.1", // message format version
kind: "<message-kind>",
id: "<uuid>", // for request/response correlation
ts: "<ISO 8601>", // must be within 5 minutes of the receiver's clock
payload: { /* per-kind */ }
}To build your own host or validate messages yourself, the package exports:
import {
validateMessage, // (raw, direction) => { ok, reason? }
intersectCapabilities, // (requested, policy) => granted
SAP_VERSION, // "0.1"
MAX_CLOCK_SKEW_MS, // 300000
} from "@syncropel/extensions";
import type {
SAPCapability, SAPEnvelope, ActType,
HelloPayload, RecordsEmitPayload, ActionResultPayload,
// ...every payload + message type
} from "@syncropel/extensions";Minimal end-to-end example
A tiny extension that subscribes to one kind and emits an acknowledgment for each record:
import { createAdapter } from "@syncropel/extensions";
const adapter = createAdapter({
ext: { name: "AckBot", version: "0.1.0" },
capabilities: ["records.emit", "records.subscribe"],
onInit: async ({ capabilities_granted }) => {
if (!capabilities_granted.includes("records.subscribe")) {
adapter.setStatus({
label: "No subscribe capability",
tone: "error",
});
return;
}
await adapter.subscribe({ kind: "user.request" });
adapter.setStatus({ label: "Listening", tone: "info", indicator: "pulse" });
},
onRecords: async ({ records }) => {
for (const record of records) {
await adapter.emit({
act: "KNOW",
body: {
kind: "user.request.ack",
acks: record.id,
},
thread: "th_acks",
});
}
},
});
// Tell host the iframe's real content height
const resizeObserver = new ResizeObserver((entries) => {
adapter.setHeight(entries[0].contentRect.height);
});
resizeObserver.observe(document.body);Best practices
- Ask for the minimum capabilities. Users and workspace policies look harder at broad requests. Narrow requests are approved faster and keep working when policies change.
- Handle partial grants. Check
capabilities_grantedinsideonInit. Don't assume every requested capability was given. - Update height accurately. Hosts rely on your
setHeightcall to avoid scroll-within-scroll or clipped content. UseResizeObserver. - Use status for long-running work. A pulsing status with a label tells the user more than a silent spinner inside your iframe.
- Always
destroy()on unmount. Leaked adapters keep processing messages after the user has navigated away.
What's next
- Records concept: what you're emitting from your extension
- TypeScript SDK: the same record model, but from a non-iframe context
- Projections SDK: render declarative UI inside your extension
- React components: component palette for extensions that want a native Syncropel look