Skip to main content

Stateless Messaging API

The kittl.stateless API enables real-time messaging between extensions (or between an extension and the host). This is useful for coordinating actions across multiple extensions or reacting to events from peers.

Sending a Message

Use send to broadcast a message to all subscribers of that message type. The host automatically tags the message with your extension's origin.

const sendResult = await kittl.stateless.send({
type: 'my-extension:item-selected',
payload: {
itemId: '123',
source: 'gallery',
},
});

if (!sendResult.isOk) {
console.error('Failed to send:', sendResult.error);
}

Subscribing to Messages

Use subscribe to listen for messages of a specific type. The handler is called whenever a matching message arrives from a peer.

const subResult = await kittl.stateless.subscribe(
'my-extension:item-selected',
(payload: Record<string, unknown>) => {
// payload is Record<string, unknown> — narrow as needed
const itemId = payload.itemId as string;
console.log('Received item selection:', itemId);
},
);

You can subscribe multiple handlers to the same key — all will be invoked.

Unsubscribing

Use unsubscribe to stop listening for a specific message type. This removes all handlers registered for that key.

const unsubResult = await kittl.stateless.unsubscribe('my-extension:item-selected');

API Reference

See Stateless API Reference for full parameter details.