Post Oak Labs · Platform Infrastructure

How AIN Bridge works

AIN Bridge is the thin client-side JavaScript layer injected into every AINumbers tool before </body>. It gives tools three capabilities without requiring any server, any network call, or any storage write: prefill deep-links (agents hand users a one-click URL with inputs pre-encoded), Policy Mandate intake (drop or paste the output of a prior tool to automatically fill the next), and composer messaging (same-origin parent frames orchestrate tools via postMessage). The bridge is the connective tissue between every composer, every agent handoff, and every tool in the suite.

① Prefill Deep-Links ② Policy Mandate Intake ③ Composer Messaging
Foundation

The problem: 480+ tools, no wiring

Each AINumbers tool is a fully self-contained HTML page with its own inputs and its own computed outputs. That is the security guarantee — no cross-page data leakage, no shared state, no server that could log your inputs. But it creates an integration gap: when an agent wants to chain tools, or when a user finishes one tool and needs to carry its outputs into the next, who does the hand-off?

AIN Bridge is the answer. It runs inside each tool's browser context — never on a server — and provides three channels through which inputs can be populated from the outside world: a URL hash fragment, a JSON file, or a parent frame's postMessage.

Source
Agent / Composer / Deep-link
Knows what inputs the next tool needs
Bridge
AIN Bridge v1.0
Decodes, validates, applies to DOM · zero network · zero storage
Target
Tool Inputs (DOM)
Fields filled, ready to run
Capability 1 of 3

Deep-link URL encoding

The simplest Bridge capability: encode a JSON object of {elementId: value} pairs as base64url, append it to a tool URL as #in=<encoded>, and share the link. When the tool loads in the browser, the Bridge decodes the fragment, fills each matching input, and shows a confirmation notice. Adding &run=1 opts into auto-execution — the tool runs immediately after filling.

This is the mechanism agents use to hand off context to users in a zero-PII way. The encoded data never leaves the browser — the hash fragment is not sent to any server in HTTP requests. The tool URL and its inputs are the only things that cross the wire.

URL format
tool.html#in=<b64url>
Add &run=1 to auto-execute on load.
JSON payload
Keys = DOM element IDs. Values = strings, numbers, or booleans. {fields:{…}} wrapper also accepted.
Encoding
Standard base64url (RFC 4648 §5): +-, /_, padding stripped. btoa(unescape(encodeURIComponent(json))).
Field mapping
Sets .value (text/select/textarea) or .checked (checkbox/radio). Dispatches input + change events so reactive UIs update.
Live Prefill Link Builder

Enter a tool URL and one or more elementId: value pairs. The encoder builds the deep-link in real time. Paste the result into a browser to see the Bridge fill the form.

Tool URL (base)
Fields JSON ({"elementId": value, …})
Generated deep-link
Live Fragment Decoder

Paste a #in= fragment (or just the base64url part) to decode it back to JSON.

Decoded JSON
Capability 2 of 3

Policy Mandate import zone

When a tool is configured with intake: true, the Bridge renders a drop zone above the first panel. Users can drag-and-drop a .policy.json file produced by any prior tool, choose one from disk, or paste raw JSON. The Bridge validates the mandate structure, then maps its payload and source_tool_inputs fields onto matching DOM element IDs — the same mechanism as prefill, but driven by the mandate file rather than a URL.

This is how chaining works in practice. Tool A exports a Policy Mandate. The user opens Tool B. They drop the .policy.json into the intake zone. Relevant fields auto-fill. No copy-pasting, no manual transcription, no re-entry errors.

Mandate structure check
Bridge validates mandate_id, tool_id, and payload before applying. Invalid JSON or wrong shape → amber warning, nothing applied.
Field resolution order
Applies intakeTarget textarea first (full JSON paste), then payload fields, then source_tool_inputs. Total applied count shown in notice.
Three intake paths
Drop — drag file onto zone. Choose — file picker. Paste — expand text area and paste raw JSON.
intakeTarget opt-in
If CFG.intakeTarget is set to a textarea element ID, the full mandate JSON is also pasted there — useful for tools that parse mandates themselves.
Policy Mandate Schema (minimum valid)
{
  "mandate_id": "mnd_20260618_T503_abc123",
  "tool_id": "503-canton-tokenization-readiness-diagnostic",
  "tool_version": "1.0.0",
  "issued_at": "2026-06-18T14:30:00Z",
  "payload": {
    /* keys = element IDs in the RECEIVING tool */
    "entityName": "Apex Clearing Corp",
    "domicile": "US"
  },
  "source_tool_inputs": {
    /* the sending tool's own inputs, for audit trail */
    "entityType": "clearing_member"
  },
  "execution_hash": "a3f8c2…"  /* SHA-256 of sorted canonical JSON */
}

The Bridge checks for mandate_id, tool_id, and payload. All other fields are optional but preserved for downstream tools.

Capability 3 of 3

Composer postMessage protocol

Composer pages (e.g. guides/aml-programme-composer.html) load tools in <iframe> elements. AIN Bridge listens for window.message events from a same-origin parent and responds to three message types. This lets a composer pre-fill a tool, trigger its run function, and collect the resulting Policy Mandate — all without any server round-trip.

Same-origin enforcement is strict: the Bridge checks e.source === window.parent and, where available, verifies e.origin === location.origin. Cross-origin composers cannot drive tools.

Inbound message (parent → tool)Reply (tool → parent)Description
ain:prefill
{fields:{id:value,…}}
ain:prefilled
{applied:N, tool}
Fill N inputs. Returns count of matched fields. Same as prefill deep-link but driven by postMessage instead of URL hash.
ain:run ain:ran
{ok:bool, tool}
Call the tool's run function (declared in CFG.runFn). ok:false if no run function is configured or the call throws.
ain:getMandate ain:mandate
{mandate:{…}, tool}
Return the most recently exported Policy Mandate. Reads window._lastMandate then window.AIN_BUILD_MANDATE() then window._currentMandate.
Composer (parent frame)
guides/aml-programme-composer.html
Sends ain:prefill → waits → sends ain:run → waits → sends ain:getMandate
ain:prefill → ← ain:prefilled ain:run → ← ain:ran ain:getMandate → ← ain:mandate
Tool (child iframe)
tools/110-customer-risk-rating.html
AIN Bridge listens, applies fields, calls runFn, returns mandate JSON
Design Principles

Security posture

AIN Bridge was designed with a strict contract: it can connect tools without creating new attack surfaces. Every design decision — from how values are applied to when functions are invoked — is constrained to prevent injection, data exfiltration, and cross-origin abuse.

🌐
Zero network
The Bridge makes no fetch(), XMLHttpRequest, or WebSocket calls. Data moves only inside the browser context.
💾
Zero storage
No localStorage, sessionStorage, IndexedDB, or cookie writes. State exists only in DOM element values during the session.
🔒
No innerHTML injection
Field values are assigned via .value or .checked only — never via innerHTML or eval. XSS via crafted payload fields is structurally prevented.
📋
Run-function whitelist
Auto-run calls only the function declared in CFG.runFn. Arbitrary function names from URL parameters are never executed.
🛡️
Same-origin messaging
postMessage handler verifies e.source === window.parent and origin match before acting. Cross-origin iframes cannot drive tool inputs.
🔑
Hash-only URL data
The #in= fragment is never sent in HTTP requests. Prefilled data stays in the browser and leaves no server-side trace.
Integration Reference

Adding the Bridge to a tool

Each tool carries one configuration line declaring its Bridge options, followed by the shared Bridge script. The snippet is inserted before </body> by scripts/fix_bridge_t.py during builds. For manual integration:

<!-- 1. Declare config before the Bridge script -->
<script>window.AIN_BRIDGE_CFG = {
  runFn:        "runMyTool",   // global function name; null = no auto-run
  intake:       true,          // show Policy Mandate drop zone?
  intakeTarget: "mandateInput", // textarea id for full JSON paste (optional)
  intakeAnchor: ".pii-notice"  // CSS selector — drop zone inserts before this
};</script>

<!-- 2. Bridge script (minified, from scripts/ain-bridge-v1.snippet.html) -->
<script>(function(){ /* … bridge code … */ })();</script>

Public API — window.AINBridge

Once the Bridge boots, these methods are available to tool code for programmatic use:

MethodSignatureDescription
AINBridge.apply(fields: object) → NApply a {id:value} map to DOM inputs. Returns count of matched fields.
AINBridge.run() → boolCall CFG.runFn. Returns true on success, false if not configured or throws.
AINBridge.intake(json: string) → NParse and apply a Policy Mandate JSON string. Shows notice. Returns applied count.
AINBridge.getMandate() → object|nullReturn the current Policy Mandate (_lastMandateAIN_BUILD_MANDATE()_currentMandate).
AINBridge.makeLink(fields, run?) → stringBuild a prefill deep-link URL for this tool with the given fields. run=true adds &run=1.
AINBridge.versionstringBridge version string — currently "1.0".