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.

18 min readUpdated 24 November 2026rumahl.bridge.v1

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.

app/bridge.ts
import {
  connectRumahlBridge,
  applyRumahlTheme,
  RumahlBridgeError
} from "@rumahl/bridge-client";

import type {
  BridgeAppInfo,
  BridgeTheme,
  BridgeSettings,
  BridgeNetworkRequest,
  BridgeCapabilityResult
} from "@rumahl/bridge-client";

Connect and dispose

app/connect.ts
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});
MemberTypeMeaning
availablebooleanTrue when a parent shell frame exists
appIdstring | nullThe 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()voidRemoves 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.

wire messages
// 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.

MethodCapabilityPurpose
os.infocom.rumahl.os.infoApp, account and presentation mode
os.theme.getcom.rumahl.os.themeCurrent semantic palette
os.notificationcom.rumahl.os.notificationShow a toast or notification
os.window.close / minimize / focuscom.rumahl.os.windowControl the app window
os.capabilities.invokecom.rumahl.os.capabilitiesCall another app’s capability
os.settings.get / setcom.rumahl.os.settingsOwn manifest settings and secrets
os.net.requestcom.rumahl.os.networkBrokered HTTP(S) request
os.files.request / read / writerumahl.files.read / writeUser-selected file access
os.warnings.register / publish / test / clearcom.rumahl.os.warningsOS weather-warning source
pets.state / interact / action.register / action.unregistercom.rumahl.pets.interactOptional 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

app/info.ts
const info = await rumahl.info();
BridgeAppInfo
{
  "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

app/theme.ts
const theme = await rumahl.theme();

const stop = rumahl.watchTheme((next) => {
  applyRumahlTheme(next);
});
BridgeTheme
{
  "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.

app/theme.css
.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

app/notify.ts
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" }
  ]
});
FieldTypeNotes
messagestringRequired
titlestringOptional heading
variantsuccess | warning | info | error | loadingVisual tone
progressnumber0..1 progress bar
durationnumber | nullMilliseconds; null keeps it persistent
buttons{id,label}[]Actions arrive as os.notification.action events
emergencybooleanRequires com.rumahl.os.emergency
app/notification-events.ts
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.

manifest excerpt
"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" }
]
app/settings.ts
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}});
LimitValue
Settings per manifest64
Plain value size64 KiB
Secret value size16 KiB
Settings per write64
Required valuesMust 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.

app/network.ts
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);
BridgeNetworkResponse
{
  "status": 200,
  "headers": { "content-type": "application/json" },
  "body": "[…]",
  "truncated": false
}
RuleValue
SchemesHTTP and HTTPS only
MethodsGET, POST, PUT, PATCH, DELETE, HEAD
RedirectsNot followed; a 3xx is returned as-is
Request body256 KiB maximum
Response body2 MiB maximum, clamped by maxBytes
Timeout20 seconds total, 10 seconds connect
Headers16 maximum; only an allowlist is accepted
Forbidden headersAuthorization, Cookie, Host, Origin
CookiesNever sent; Set-Cookie is never exposed
WebSocket / SSENot available through the bridge yet

Capabilities

Provide a capability

app/provider.ts
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

app/caller.ts
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);
}
BridgeCapabilityResult
{
  "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

CodeMeaningWhat to do
not-embeddedNo parent shell frameUse the standalone preview path
timeoutNo response within the timeoutRetry or show a reconnect state
deniedThe platform denied the operationExplain the missing grant or consent
no-providerThe capability handler is not registeredOpen the provider app and retry
unknown-methodMethod not in the v1 surfaceCheck contracts and manifest declarations
invalid-paramsMalformed requestFix the payload shape
failedThe provider or platform operation failedSurface the message and retry safely
disposedThe client was disposedCreate a new bridge after remounting
app/errors.ts
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.

test/harness.ts
// 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