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.

903 B
Raw Blame
// In-process fan-out of coordinator events, keyed by run id.
//
// Every event is persisted first (store.appendEvent) and then published here,
// so an SSE response open on this instance sees it live. A decision taken on
// another instance (the approval inbox, a push action, Telegram) still reaches
// the chat: the page's stream endpoint tails the persisted events by id.

const listeners = new Map();

export function subscribe(runId, fn) {
	if (!listeners.has(runId)) listeners.set(runId, new Set());
	listeners.get(runId).add(fn);
	return () => {
		const set = listeners.get(runId);
		if (!set) return;
		set.delete(fn);
		if (!set.size) listeners.delete(runId);
	};
}

export function publish(runId, event) {
	const set = listeners.get(runId);
	if (!set) return;
	for (const fn of set) {
		try {
			fn(event);
		} catch (e) {
			console.warn('[team-chat] listener failed', e?.message);
		}
	}
}