Reference · bridge v1
Bridge SDK reference.
The typed client for an app running inside rumahl OS. It performs the handshake, binds messages to the parent frame and exposes the complete v1 method surface.
Import the client
@rumahl/bridge-client is a workspace package in the rumahl repository. It is not published to npm today. Inside the frontend workspace, import it directly. A standalone app should vendor the client or copy the protocol from @rumahl/contracts/bridge.
import {
connectRumahlBridge,
applyRumahlTheme,
RumahlBridgeError
} from "@rumahl/bridge-client";
import type {
BridgeAppInfo,
BridgeTheme,
BridgeSettings,
BridgeNetworkRequest,
BridgeCapabilityResult
} from "@rumahl/bridge-client";
Connect and dispose
const rumahl = connectRumahlBridge({
timeoutMs: 5000,
handshakeRetryMs: 600
});
// The shell must acknowledge the handshake before app identity is known.
const welcome = await rumahl.ready();
// { appId: "com.example.notes", methods: ["os.info", "os.theme.get", ...] }
if (!rumahl.available) {
// Standalone browser preview.
}
rumahl.appId; // string | null
// Remove listeners and reject every pending call.
window.addEventListener("pagehide", () => rumahl.dispose(), {once: true});
| Member | Type | Meaning |
|---|---|---|
available | boolean | True when a parent shell frame exists |
appId | string | null | The app ID from the shell welcome message |
ready() | Promise<{appId, methods}> | Resolves after the handshake |
call(method, params?) | Promise<T> | Raw method call; prefer typed helpers |
dispose() | void | Removes the listener and rejects pending calls |
Wire protocol
The client speaks rumahl.bridge.v1 over postMessage. The app is an opaque-origin iframe, so the shell binds the channel to the concrete parent window rather than trusting an origin string.
// app → shell
{ "bridge": "rumahl.bridge.v1", "kind": "hello" }
// shell → app
{
"bridge": "rumahl.bridge.v1",
"kind": "welcome",
"version": 1,
"appId": "com.example.notes",
"methods": ["os.info", "os.theme.get", "os.notification"]
}
// app → shell
{
"bridge": "rumahl.bridge.v1",
"kind": "request",
"id": "m3k2-1",
"method": "os.theme.get"
}
// shell → app
{
"bridge": "rumahl.bridge.v1",
"kind": "response",
"id": "m3k2-1",
"ok": true,
"result": { "scheme": "dark", "accent": "#6cc79b", "reducedMotion": false, "palette": { } }
}
Requests time out after 5 seconds by default. A response with ok: false carries {code, message} and is converted to a RumahlBridgeError.
Methods and required capabilities
A method is refused unless the signed manifest declares the corresponding capability. The welcome message lists the methods the shell will accept for this installation.
| Method | Capability | Purpose |
|---|---|---|
os.info | com.rumahl.os.info | App, account and presentation mode |
os.theme.get | com.rumahl.os.theme | Current semantic palette |
os.notification | com.rumahl.os.notification | Show a toast or notification |
os.window.close / minimize / focus | com.rumahl.os.window | Control the app window |
os.capabilities.invoke | com.rumahl.os.capabilities | Call another app’s capability |
os.settings.get / set | com.rumahl.os.settings | Own manifest settings and secrets |
os.net.request | com.rumahl.os.network | Brokered HTTP(S) request |
os.files.request / read / write | rumahl.files.read / write | User-selected file access |
os.warnings.register / publish / test / clear | com.rumahl.os.warnings | OS weather-warning source |
pets.state / interact / action.register / action.unregister | com.rumahl.pets.interact | Optional pet surface |
An app can also subscribe to events such as os.theme.changed and os.notification.action through on(topic, listener).
App and account information
const info = await rumahl.info();
{
"app": { "id": "com.example.notes", "title": "Notes", "version": "1.4.0" },
"account": { "displayName": "Ada" },
"mode": "desktop"
}
mode is desktop, launcher or mobile. Do not use it as an authorization signal; it only describes the current presentation.
Theme
const theme = await rumahl.theme();
const stop = rumahl.watchTheme((next) => {
applyRumahlTheme(next);
});
{
"scheme": "dark",
"accent": "#6cc79b",
"reducedMotion": false,
"palette": {
"background": "#0f1512",
"surface": "#161f1a",
"text": "#eef4f0",
"textMuted": "#a9bab0",
"border": "#30443a",
"accent": "#6cc79b",
"onAccent": "#0f1512"
}
}
applyRumahlTheme(theme, root) sets --rumahl-background, --rumahl-surface, --rumahl-text, --rumahl-text-muted, --rumahl-border, --rumahl-accent and --rumahl-on-accent. It also sets color-scheme, data-rumahl-theme and data-rumahl-reduced-motion.
.panel {
background: var(--rumahl-surface);
color: var(--rumahl-text);
border: 1px solid var(--rumahl-border);
}
.primary {
background: var(--rumahl-accent);
color: var(--rumahl-on-accent);
}
Notifications
await rumahl.notify({
title: "Backup complete",
message: "42 files copied to the NAS.",
description: "Last run took 18 seconds.",
variant: "success",
progress: 1,
duration: 5000,
buttons: [
{ id: "open", label: "Open folder" },
{ id: "dismiss", label: "Dismiss" }
]
});
| Field | Type | Notes |
|---|---|---|
message | string | Required |
title | string | Optional heading |
variant | success | warning | info | error | loading | Visual tone |
progress | number | 0..1 progress bar |
duration | number | null | Milliseconds; null keeps it persistent |
buttons | {id,label}[] | Actions arrive as os.notification.action events |
emergency | boolean | Requires com.rumahl.os.emergency |
rumahl.on("os.notification.action", (payload) => {
const action = payload as { notificationId: string; actionId: string };
if (action.actionId === "open") openBackupFolder();
});
Settings and secrets
An app reads and writes only its own manifest-declared settings. Secret values are write-only: the read shape tells you which keys are configured, never their plaintext.
"settings": [
{ "key": "server.url", "title": "Server address", "type": "text", "required": true },
{ "key": "server.token", "title": "Access token", "type": "secret", "required": true },
{ "key": "sync.interval", "title": "Sync interval", "type": "number" }
]
const current = await rumahl.settings();
// { values: { "server.url": "https://nas.local" }, secrets: ["server.token"] }
await rumahl.setSettings({
values: {
"server.url": "https://nas.local",
"server.token": "new-token", // sealed by the platform
"sync.interval": 300
}
});
// null clears an optional value.
await rumahl.setSettings({values: {"sync.interval": null}});
| Limit | Value |
|---|---|
| Settings per manifest | 64 |
| Plain value size | 64 KiB |
| Secret value size | 16 KiB |
| Settings per write | 64 |
| Required values | Must be present after the write |
Brokered network requests
The app never receives a socket or a cookie jar. The OS sends the request to an origin the user approved for this installation, attaches an optional secret server-side and returns a bounded response.
const response = await rumahl.requestNetwork({
url: "https://homeassistant.local:8123/api/states",
method: "GET",
headers: {Accept: "application/json"},
secret: "server.token", // attached as Authorization: Bearer …
maxBytes: 512 * 1024
});
if (response.status === 401) {
await showTokenPrompt();
}
const states = JSON.parse(response.body);
{
"status": 200,
"headers": { "content-type": "application/json" },
"body": "[…]",
"truncated": false
}
| Rule | Value |
|---|---|
| Schemes | HTTP and HTTPS only |
| Methods | GET, POST, PUT, PATCH, DELETE, HEAD |
| Redirects | Not followed; a 3xx is returned as-is |
| Request body | 256 KiB maximum |
| Response body | 2 MiB maximum, clamped by maxBytes |
| Timeout | 20 seconds total, 10 seconds connect |
| Headers | 16 maximum; only an allowlist is accepted |
| Forbidden headers | Authorization, Cookie, Host, Origin |
| Cookies | Never sent; Set-Cookie is never exposed |
| WebSocket / SSE | Not available through the bridge yet |
Capabilities
Provide a capability
const unregister = rumahl.provide(
"com.example.notes.search",
async (invocation) => {
const key = invocation.resource?.key ?? "";
return notes
.filter((note) => note.title.toLowerCase().includes(key.toLowerCase()))
.map((note) => ({id: note.id, title: note.title}));
}
);
// Later:
unregister();
Invoke another app
const outcome = await rumahl.invokeCapability(
"com.example.notes.search",
{namespace: "com.example.notes", kind: "query", key: "monstera"}
);
if (outcome.outcome === "invoked") {
console.log(outcome.result);
}
{
"capability": "com.example.notes.search",
"outcome": "invoked",
"result": [{ "id": "2", "title": "Water the monstera" }]
}
The HTTP route behind os.capabilities.invoke returns capabilityVersion, outcome, result and, for a running web provider, a browser delivery instruction. The shell then delivers provider.invoke to the provider frame. Apps never open a direct channel to each other.
Errors
| Code | Meaning | What to do |
|---|---|---|
not-embedded | No parent shell frame | Use the standalone preview path |
timeout | No response within the timeout | Retry or show a reconnect state |
denied | The platform denied the operation | Explain the missing grant or consent |
no-provider | The capability handler is not registered | Open the provider app and retry |
unknown-method | Method not in the v1 surface | Check contracts and manifest declarations |
invalid-params | Malformed request | Fix the payload shape |
failed | The provider or platform operation failed | Surface the message and retry safely |
disposed | The client was disposed | Create a new bridge after remounting |
import {RumahlBridgeError} from "@rumahl/bridge-client";
try {
await rumahl.requestNetwork({url: "https://nas.local/api"});
} catch (error) {
if (error instanceof RumahlBridgeError && error.code === "denied") {
// The origin is not approved for this installation.
showConsentHelp();
} else {
throw error;
}
}
Testing the bridge
Run the app as a normal page for UI tests, then use a parent-frame harness to exercise the protocol. A harness can answer hello with welcome, record requests and return deterministic responses.
// A minimal parent-frame harness for unit tests.
window.addEventListener("message", (event) => {
const message = event.data;
if (message?.kind === "hello") {
event.source?.postMessage({
bridge: "rumahl.bridge.v1",
kind: "welcome",
version: 1,
appId: "com.example.test",
methods: ["os.info", "os.theme.get", "os.settings.get"]
}, "*");
}
if (message?.kind === "request" && message.method === "os.info") {
event.source?.postMessage({
bridge: "rumahl.bridge.v1",
kind: "response",
id: message.id,
ok: true,
result: {
app: {id: "com.example.test", title: "Test", version: "1.0.0"},
account: {displayName: "Test"},
mode: "desktop"
}
}, "*");
}
});
Also test the non-embedded case, a denied request, a timeout, a provider that throws and disposal during a pending call.
Next
- Permissions and capabilities — grants and app-to-app calls.
- Hosting and bridge — leases, isolation and delivery.
- SDKs and npm — packages, contracts and CLI.
- API reference — the HTTP surface.
Was this page helpful?