Skip to content

@maxhealth.tech/prefab / renderer / Bridge

Class: Bridge

Defined in: renderer/bridge.ts:100

Constructors

Constructor

ts
new Bridge(hostOrigin?): Bridge;

Defined in: renderer/bridge.ts:117

Parameters

ParameterTypeDefault value
hostOriginstring'*'

Returns

Bridge

Accessors

supportsSubscriptions

Get Signature

ts
get supportsSubscriptions(): boolean;

Defined in: renderer/bridge.ts:320

Whether the host indicated subscription support during handshake.

Returns

boolean


activeProtocol

Get Signature

ts
get activeProtocol(): "prefab" | "jsonrpc";

Defined in: renderer/bridge.ts:354

Which protocol is active after initialize().

Returns

"prefab" | "jsonrpc"

Methods

connect()

ts
connect(): void;

Defined in: renderer/bridge.ts:122

Start listening for messages (prefab:* and JSON-RPC ui/*).

Returns

void


initialize()

ts
initialize(appCapabilities): Promise<HostContext>;

Defined in: renderer/bridge.ts:174

Init handshake. Races prefab:init and ui/initialize JSON-RPC in parallel. Whichever protocol responds first wins.

Parameters

ParameterType
appCapabilitiesAppCapabilities

Returns

Promise<HostContext>


createTransport()

ts
createTransport(): McpTransport;

Defined in: renderer/bridge.ts:190

Create an McpTransport that routes through the active protocol.

Returns

McpTransport


requestMode()

ts
requestMode(mode): void;

Defined in: renderer/bridge.ts:198

Request a display mode change.

Parameters

ParameterType
modeDisplayMode

Returns

void


ts
openLink(url, target?): void;

Defined in: renderer/bridge.ts:207

Request the host to open a URL.

Parameters

ParameterType
urlstring
target?string

Returns

void


updateContext()

ts
updateContext(context): void;

Defined in: renderer/bridge.ts:216

Send context updates to the host.

Parameters

ParameterType
contextRecord<string, unknown>

Returns

void


setupAutoResize()

ts
setupAutoResize(el): () => void;

Defined in: renderer/bridge.ts:233

Observe an element's size and notify the host whenever it changes. Mirrors the ext-apps SDK's autoResize: true behaviour — uses a ResizeObserver on the target element and sends ui/notifications/size-changed (JSON-RPC) or prefab:size-changed (prefab protocol).

Returns a teardown function that disconnects the observer.

Parameters

ParameterType
elHTMLElement

Returns

() => void


notifyPreferredSize()

ts
notifyPreferredSize(layout): void;

Defined in: renderer/bridge.ts:279

Notify the host of declarative layout/size hints from the wire format. Sends once when the UI mounts so the host can pre-allocate space.

Uses ui/notifications/preferred-size (JSON-RPC) or prefab:preferred-size (prefab protocol).

Parameters

ParameterType
layout{ preferredHeight?: number; minHeight?: number; maxHeight?: number; }
layout.preferredHeight?number
layout.minHeight?number
layout.maxHeight?number

Returns

void


subscribe()

ts
subscribe(uri, onData): () => void;

Defined in: renderer/bridge.ts:295

Subscribe to a resource URI for real-time push updates.

Sends ui/resources/subscribe (JSON-RPC) or prefab:subscribe (prefab) to the host and registers a listener for incoming update notifications.

Parameters

ParameterType
uristring
onData(data) => void

Returns

Cleanup function that unsubscribes from the resource.

() => void


on()

ts
on(type, handler): void;

Defined in: renderer/bridge.ts:325

Register a handler for a message type (prefab:* or internal).

Parameters

ParameterType
typestring
handler(payload) => void

Returns

void


off()

ts
off(type, handler): void;

Defined in: renderer/bridge.ts:334

Remove a handler.

Parameters

ParameterType
typestring
handler(payload) => void

Returns

void


disconnect()

ts
disconnect(): void;

Defined in: renderer/bridge.ts:339

Disconnect and clean up.

Returns

void

Released under the MIT License.