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.
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.
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.
tool.html#in=<b64url>&run=1 to auto-execute on load.{fields:{…}} wrapper also accepted.+→-, /→_, padding stripped. btoa(unescape(encodeURIComponent(json)))..value (text/select/textarea) or .checked (checkbox/radio). Dispatches input + change events so reactive UIs update.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.
Paste a #in= fragment (or just the base64url part) to decode it back to JSON.
—
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_id, tool_id, and payload before applying. Invalid JSON or wrong shape → amber warning, nothing applied.intakeTarget textarea first (full JSON paste), then payload fields, then source_tool_inputs. Total applied count shown in notice.CFG.intakeTarget is set to a textarea element ID, the full mandate JSON is also pasted there — useful for tools that parse mandates themselves.{
"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.
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. |
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.
fetch(), XMLHttpRequest, or WebSocket calls. Data moves only inside the browser context.localStorage, sessionStorage, IndexedDB, or cookie writes. State exists only in DOM element values during the session..value or .checked only — never via innerHTML or eval. XSS via crafted payload fields is structurally prevented.CFG.runFn. Arbitrary function names from URL parameters are never executed.e.source === window.parent and origin match before acting. Cross-origin iframes cannot drive tool inputs.#in= fragment is never sent in HTTP requests. Prefilled data stays in the browser and leaves no server-side trace.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>
window.AINBridgeOnce the Bridge boots, these methods are available to tool code for programmatic use:
| Method | Signature | Description |
|---|---|---|
| AINBridge.apply | (fields: object) → N | Apply a {id:value} map to DOM inputs. Returns count of matched fields. |
| AINBridge.run | () → bool | Call CFG.runFn. Returns true on success, false if not configured or throws. |
| AINBridge.intake | (json: string) → N | Parse and apply a Policy Mandate JSON string. Shows notice. Returns applied count. |
| AINBridge.getMandate | () → object|null | Return the current Policy Mandate (_lastMandate → AIN_BUILD_MANDATE() → _currentMandate). |
| AINBridge.makeLink | (fields, run?) → string | Build a prefill deep-link URL for this tool with the given fields. run=true adds &run=1. |
| AINBridge.version | string | Bridge version string — currently "1.0". |