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
npm install @unaiverse/gui-kitand import it by the name of the package:
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:
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.jswhen 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 neededDEFAULT_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:
- Install the package or put the file of the kit next to your page (above).
- Serve your page from
localhostwith any local web server (npx serve,python3 -m http.server 8000ornpm run devin a Vite project). - Connect to a fake world described in your page with
connectToHost({ fake: { world } }). - Open the page at its
http://localhost:...address.
The short check below shows "The kit works" when your setup is correct.
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>;
}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}).`;
}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:
// 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:
world.webappis built from your browser instead of the webapp (Pretend the look while you build).setPath,onBackandaskForare accepted and do nothing (links and back, the browser).world.meis the person you describe in the fake world (On a fake world).
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 see | Why | What to do |
|---|---|---|
Cannot use import statement outside a module | The 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{
"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:
/**
* 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
- Project setups: every file of a plain HTML page, of Vite and of Vite with React.
- Thinking in views: the few ideas behind every view.
- Build a view with an AI agent: the skill for Claude Code and Codex, to download.
- Going live: your view on your own server and its address in the Own view field of your world.