Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

1.7 KB
Raw Blame
// The only bridge between the companion's renderer and the machine.
//
// Context isolation is on and node integration is off, so the renderer (which
// embeds remote content from three.ws in an iframe) can reach exactly these
// calls and nothing else. No fs, no child_process, no ipcRenderer.

const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('companion', {
	// State
	credentials: () => ipcRenderer.invoke('companion:credentials'),
	saveToken: (payload) => ipcRenderer.invoke('companion:save-token', payload),

	// Events from the main process
	onDelivery: (handler) => {
		const listener = (_event, delivery) => handler(delivery);
		ipcRenderer.on('companion:delivery', listener);
		return () => ipcRenderer.removeListener('companion:delivery', listener);
	},
	onStatus: (handler) => {
		const listener = (_event, status) => handler(status);
		ipcRenderer.on('companion:status', listener);
		ipcRenderer.on('companion:connected', listener);
		return () => {
			ipcRenderer.removeListener('companion:status', listener);
			ipcRenderer.removeListener('companion:connected', listener);
		};
	},

	onFace: (handler) => {
		const listener = (_event, face) => handler(face);
		ipcRenderer.on('companion:face', listener);
		return () => ipcRenderer.removeListener('companion:face', listener);
	},

	// Actions
	setInteractive: (interactive) => ipcRenderer.send('companion:set-interactive', Boolean(interactive)),
	sayNative: (text) => ipcRenderer.send('companion:say-native', String(text || '')),
	notifyNative: (delivery) => ipcRenderer.send('companion:notify-native', delivery),
	openExternal: (url) => ipcRenderer.invoke('companion:open-external', url),
});