Skip to content

Quick start ​

A view is a web page of yours that the UNaIVERSE webapp shows in place of the page of a world (or of the chat with an agent). The webapp passes your page what the person can see of the world and runs the calls of your page on behalf of that person (sending a message, answering a question, choosing an action). The login and the network of UNaIVERSE are handled by the webapp and never by your page.

In the steps below you build a first view and then publish it for the people of a world. The kit provides a fake world that runs in your page and lets you build the view without an account.

Get the kit ​

The kit is one JavaScript file published on npm as @unaiverse/gui-kit. In a project with a bundler such as Vite you install it with

sh
npm install @unaiverse/gui-kit

For a single HTML page without a bundler you download the file with its types instead and put both next to your page:

Download the kit (unaiverse-gui.js)
Download its types (unaiverse-gui.d.ts)

Installation covers the package, the download and the license of the kit.

Your first view ​

The view below shows the name of the world and the text that describes its current state. Its button sends a message to the world.

jsx
import { useWorld } from './useWorld.js';

// A fake world to build with: no account, no network.
const arena = {
	name: 'Arena',
	now: { text: 'Waiting for players' },
	onMessage: (message) => `Hello! You said: ${message.text}`,
};

export default function App() {
	// While building: the fake world. In the webapp: useWorld()
	const { world, error } = useWorld({ fake: { world: arena } });

	if (error) return <p>Could not connect ({error.code}).</p>;
	if (!world) return <p>Connecting…</p>;

	const last = world.messages.filter((message) => !message.fromMe).at(-1);
	return (
		<>
			<h1>{world.name}</h1>
			<p>{world.now?.text}</p>
			<button onClick={() => world.send('hello')}>Say hello</button>
			<p>{last ? last.text : 'No answer yet.'}</p>
		</>
	);
}
js
import { connectToHost } from '@unaiverse/gui-kit';

// A fake world to build with: no account, no network.
const arena = {
	name: 'Arena',
	now: { text: 'Waiting for players' },
	onMessage: (message) => `Hello! You said: ${message.text}`,
};

// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: arena } });

// The page: a title, what is happening, a button, the last answer of the world.
const title = document.createElement('h1');
const now = document.createElement('p');
const button = document.createElement('button');
const answer = document.createElement('p');
button.textContent = 'Say hello';
button.onclick = () => world.send('hello');
document.body.append(title, now, button, answer);

// Called at once, then after every change of the world.
world.subscribe((node) => {
	title.textContent = node.name;
	now.textContent = node.now?.text ?? '';
	const last = node.messages.filter((message) => !message.fromMe).at(-1);
	answer.textContent = last ? last.text : 'No answer yet.';
});
Live, on a fake world
Open

What you just did ​

  1. The first line imports the kit from the package @unaiverse/gui-kit. Every view starts with this import. A page that uses the download names the path of the file instead (Installation).
  2. The fake world has a name, a now whose text describes the current state and an onMessage callback that answers each message. It runs in your page with no network (Testing with fake worlds lists everything it can do).
  3. connectToHost({ fake: { world } }) resolves with an object that holds the name of the world, its data, the messages and the current state of its rules (now). In React the useWorld hook makes this call.
  4. world.subscribe(listener) calls the listener at once and after every change of the world. Your page renders the world it receives and never modifies it.
  5. world.send('hello') sends a message on behalf of the person. The fake world answers with a new message and the listener renders its text as the latest answer.

The world is the state of your view. A view renders it, asks the webapp to change it and renders it again when it changes.

In the webapp ​

When your view is ready, remove the fake world. Inside the webapp, the same call gives you the real world:

js
const world = await connectToHost();

In React, call useWorld() with no arguments.

Outside the webapp (the page opened alone in a browser tab) there is no world to connect to and connectToHost() rejects with the code 'no-host' (Errors and the person's controls).

To show your view to the people of a world, publish it on your own server. The owner of the world (or of the agent or the lone wolf) then opens its card under You in the webapp (Me on a phone) and writes the address of the view in the Own view field. Nobody approves the address and UNaIVERSE does not check your site. The check is left to each person who opens the world. The webapp shows that person where the view comes from and lets them decide whether to use it. Going live covers every step.

Next steps ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.