@maxhealth.tech/prefab / renderer / Bridge
Class: Bridge
Defined in: renderer/bridge.ts:100
Constructors
Constructor
new Bridge(hostOrigin?): Bridge;Defined in: renderer/bridge.ts:117
Parameters
| Parameter | Type | Default value |
|---|---|---|
hostOrigin | string | '*' |
Returns
Bridge
Accessors
supportsSubscriptions
Get Signature
get supportsSubscriptions(): boolean;Defined in: renderer/bridge.ts:320
Whether the host indicated subscription support during handshake.
Returns
boolean
activeProtocol
Get Signature
get activeProtocol(): "prefab" | "jsonrpc";Defined in: renderer/bridge.ts:354
Which protocol is active after initialize().
Returns
"prefab" | "jsonrpc"
Methods
connect()
connect(): void;Defined in: renderer/bridge.ts:122
Start listening for messages (prefab:* and JSON-RPC ui/*).
Returns
void
initialize()
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
| Parameter | Type |
|---|---|
appCapabilities | AppCapabilities |
Returns
Promise<HostContext>
createTransport()
createTransport(): McpTransport;Defined in: renderer/bridge.ts:190
Create an McpTransport that routes through the active protocol.
Returns
McpTransport
requestMode()
requestMode(mode): void;Defined in: renderer/bridge.ts:198
Request a display mode change.
Parameters
| Parameter | Type |
|---|---|
mode | DisplayMode |
Returns
void
openLink()
openLink(url, target?): void;Defined in: renderer/bridge.ts:207
Request the host to open a URL.
Parameters
| Parameter | Type |
|---|---|
url | string |
target? | string |
Returns
void
updateContext()
updateContext(context): void;Defined in: renderer/bridge.ts:216
Send context updates to the host.
Parameters
| Parameter | Type |
|---|---|
context | Record<string, unknown> |
Returns
void
setupAutoResize()
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
| Parameter | Type |
|---|---|
el | HTMLElement |
Returns
() => void
notifyPreferredSize()
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
| Parameter | Type |
|---|---|
layout | { preferredHeight?: number; minHeight?: number; maxHeight?: number; } |
layout.preferredHeight? | number |
layout.minHeight? | number |
layout.maxHeight? | number |
Returns
void
subscribe()
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
| Parameter | Type |
|---|---|
uri | string |
onData | (data) => void |
Returns
Cleanup function that unsubscribes from the resource.
() => void
on()
on(type, handler): void;Defined in: renderer/bridge.ts:325
Register a handler for a message type (prefab:* or internal).
Parameters
| Parameter | Type |
|---|---|
type | string |
handler | (payload) => void |
Returns
void
off()
off(type, handler): void;Defined in: renderer/bridge.ts:334
Remove a handler.
Parameters
| Parameter | Type |
|---|---|
type | string |
handler | (payload) => void |
Returns
void
disconnect()
disconnect(): void;Defined in: renderer/bridge.ts:339
Disconnect and clean up.
Returns
void