Typed postMessage bridge between aiNav (iframe) and Rakaposhi (host).
npm install github:SmartOrgDevelopment/bridge-clientimport { createAiNavBridge } from "@smartorg/bridge-client";
const bridge = createAiNavBridge({
allowedOrigins: ["https://app.smartorg.com"],
strictOriginCheck: true,
});
bridge.send("NODE_DATA_UPDATED", {
tool_name: "save_node_description",
node_data: { nodeId: "...", treeId: "...", nodeName: "..." },
});import { createHostBridge } from "@smartorg/bridge-client";
const bridge = createHostBridge({
allowedOrigins: ["https://ainav.smartorg.com"],
strictOriginCheck: true,
});
const unsubscribe = bridge.onMessage({
type: "NODE_DATA_UPDATED",
handler: (payload) => {
// typed payload
},
});
// Cleanup on destroy
unsubscribe();
bridge.destroy();import { z } from "zod";
const NodeDataSchema = z.object({
nodeId: z.string(),
treeId: z.string(),
});
bridge.onMessage({
type: "NODE_DATA_UPDATED",
schema: NodeDataSchema,
handler: (payload) => {
// payload is typed as z.infer<typeof NodeDataSchema>
// schema mismatch logs an error instead of crashing
},
});| Option | Type | Default | Description |
|---|---|---|---|
source |
"ainav-web" | "rakaposhi-host" |
required | Identifies the caller |
allowedOrigins |
string[] |
[] |
Allowed origins (empty = allow all) |
strictOriginCheck |
boolean |
false |
Enable origin validation |
targetOrigin |
string |
"*" |
Target origin for postMessage |
validate |
boolean |
true |
Validate outgoing envelope schema |
Shorthands that set source automatically.
Send a message to the host window.
Register a typed handler. Returns a cleanup function.
Remove listeners and release resources.