Skip to content

Installation ​

The kit is a single JavaScript file (unaiverse-gui.js) with its types in unaiverse-gui.d.ts. Both are published on npm as the package @unaiverse/gui-kit. A project with a bundler such as Vite installs the package. A single HTML page without a bundler uses the same two files downloaded from this site. In every case a view loads the kit with one import and runs on your own computer with a fake world while your editor completes the names of the kit.

With npm ​

In a project with a bundler such as Vite you install the kit with

sh
npm install @unaiverse/gui-kit

and import it by the name of the package:

js
import { connectToHost } from '@unaiverse/gui-kit';

The bundler finds the file and its types in node_modules and your editor reads the types without configuration. The first line of the file names its package and its version (@unaiverse/gui-kit 1.0.0). The code is readable and shows exactly what the kit does. It holds only the code that connects your page to the webapp and the fake worlds for development. Nothing in it runs a world or holds an account.

Build the view with an AI agent

With the skill world-gui, installed by one command, Claude Code and Codex can build the whole view for you. Build a view with an AI agent shows the command and what the agent does.

Download the kit ​

A page without a bundler cannot resolve the name of a package. For a single HTML page download the kit and its types and put both files next to the page that imports the kit:

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

The page then imports the file by its path in place of the name of the package:

js
import { connectToHost } from './unaiverse-gui.js';

The download and the package hold the same file under the same version.

Load the kit ​

Every view starts with one import of the kit, by the name of the package or by the path of the downloaded file. Five facts about this import hold for every project:

  • It is an ES module. A classic <script src="..."> cannot load it. Use it in a <script type="module"> or in a module of your project.
  • A downloaded file is imported by its path. The path goes from your file to the file of the kit, for example ./unaiverse-gui.js when the two files sit side by side. The examples on this site import the package by its name.
  • The kit is part of your view. A bundler such as Vite includes the file in your build like any module of yours. Your visitors download it from your site together with your view and fetch nothing from UNaIVERSE. Project setups shows the kit in a plain page, in Vite and in Vite with React.
  • It exports connectToHost, the one function you need, together with the rarely needed DEFAULT_HOST_ORIGINS.
  • Version 1 of the protocol stays. The kit talks to the webapp through version 1 of a protocol to which UNaIVERSE only adds new features. A view built with this file therefore keeps working when the webapp changes and a newer file brings the additions.

Import the kit in one file only

Keep the import in a single module of your project from which the rest of your code imports. A new version of the kit or the move from the downloaded file to the package then changes one line. In React the useWorld hook is that module.

The license of the kit ​

The kit is open source under the same license as the UNaIVERSE SDK (the Apache License, Version 2.0). The package carries its text as LICENSE. You can read, use, change and redistribute the kit in commercial views too. Every copy keeps the license and the copyright notice (Copyright 2024-2026 UNaIVERSE S.r.l.) and every file you change carries a notice that you changed it.

Try it on your computer ​

A whole view can be built and tried on your own computer without a world, an account or the webapp:

  1. Install the package or put the file of the kit next to your page (above).
  2. Serve your page from localhost with any local web server (npx serve, python3 -m http.server 8000 or npm run dev in a Vite project).
  3. Connect to a fake world described in your page with connectToHost({ fake: { world } }).
  4. Open the page at its http://localhost:... address.

The short check below shows "The kit works" when your setup is correct.

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

// The smallest fake world: just a name.
const sandbox = { name: 'Sandbox' };

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

	if (error) return <p>The kit loaded, but could not connect ({error.code}).</p>;
	// If this line never changes, the kit did not load: look in the browser console.
	if (!world) return <p>Connecting…</p>;
	return <p>The kit works: connected to {world.name}, in the {world.webapp.theme} theme.</p>;
}
js
import { connectToHost } from '@unaiverse/gui-kit';

// The smallest fake world: just a name.
const sandbox = { name: 'Sandbox' };

// If this line never changes, the kit did not load: look in the browser console.
const status = document.createElement('p');
status.textContent = 'Connecting…';
document.body.append(status);

try {
	// While building: the fake world. In the webapp: const world = await connectToHost();
	const world = await connectToHost({ fake: { world: sandbox } });
	// Called at once, then after every change of the world.
	world.subscribe((node) => {
		status.textContent = `The kit works: connected to ${node.name}, in the ${node.webapp.theme} theme.`;
	});
} catch (error) {
	status.textContent = `The kit loaded, but could not connect (${error.code}).`;
}
Live, on a fake world
Open

Not from a file

Browsers refuse to load ES modules into a page opened as a file (file:///..., a double-click on index.html) and such a page cannot load the kit. Serve the page from a web server on your own computer too.

The fake world ​

During development connectToHost({ fake: { world } }) creates a world inside your page. A few lines describe its name, its data, the current state of its rules (now), its members, the person who looks at your view (me) and its answers to a message of the person (onMessage) or to an action they choose (onAction). Your view gets the same fields and functions as in the webapp. The code written against the fake world is therefore the code you ship and moving to the webapp only means removing fake:

js
// While you build: a fake world, in your page.
const world = await connectToHost({
  fake: { world: { name: 'Arena', me: { nickname: 'ada' }, onMessage: (message) => `You said: ${message.text}` } },
});

// In the webapp: the real world.
const world = await connectToHost();

A fake world cannot do everything the webapp does. With fake three parts of the world behave differently:

Testing with fake worlds and the reference page Fake worlds cover all the features of a fake world.

When the kit does not load ​

When the import fails, none of your module runs and the page shows only the content of your HTML. The browser console and the Network tab give the reason.

What you seeWhyWhat to do
Cannot use import statement outside a moduleThe script is not a module.Add type="module" to the <script>.
The request for unaiverse-gui.js fails with 404.The path does not lead to the file of the kit.Write a path that starts with ./ or ../ and leads from your file to the file of the kit.
Failed to resolve module specifier "@unaiverse/gui-kit"The page imports the package by its name and nothing resolved the name to a file (a page without a bundler or a package not installed).Import the downloaded file by its path or install the package and build with a bundler such as Vite.
A CORS error that names the origin null.The page was opened as a file.Serve it from localhost.

Once the kit has loaded, connectToHost() can still reject with 'no-host' when the page is not inside the webapp or with 'unsupported' when the webapp does not accept the version of the kit (Errors and the person's controls).

Completion in your editor ​

The npm package carries its types. Editors that use TypeScript such as VS Code read them on their own and list the fields of the world as you type world.. With the downloaded file keep unaiverse-gui.d.ts next to unaiverse-gui.js and the editor finds the types of ./unaiverse-gui.js in the same way.

To get mistakes such as world.sendd(...) underlined, turn on the TypeScript checks in a jsconfig.json at the root of your project (or in tsconfig.json in a TypeScript project):

my-view/
  jsconfig.json
  package.json
  src/
    main.js
json
{
  "compilerOptions": {
    "target": "es2022",
    "module": "esnext",
    "moduleResolution": "bundler",
    "jsx": "react-jsx",
    "checkJs": true
  },
  "include": ["src"]
}

A project that keeps the downloaded file in src/ also adds "exclude": ["src/unaiverse-gui.js"] in order to leave the file of the kit out of the checks.

Where the editor cannot infer the type of the world (a React component that gets world as a prop, a fake world in its own variable), name the type in a JSDoc comment:

jsx
/**
 * The name of the world, as a title.
 * @param {{ world: import('@unaiverse/gui-kit').GuiNode }} props
 */
function Title({ world }) {
  return <h1>{world.name}</h1>;
}

/** @type {import('@unaiverse/gui-kit').FakeWorld} */
const arena = { name: 'Arena', now: { text: 'Waiting for players' } };

With the downloaded file the path in import('...') goes from your file to the file of the kit as in the import (import('./unaiverse-gui.js').GuiNode). The reference describes every type of the file starting from Types.

Next steps ​

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