Project setups
A view is an ordinary web page that any web build setup can produce. The three complete setups below list every file to create: a single HTML page (nothing to install), Vite with plain JavaScript and Vite with React. Each one builds the Quick start view that runs below. We built every setup exactly as written here and opened it in a browser.
Where the kit goes
The two Vite setups install the package @unaiverse/gui-kit (Installation) and load the kit with one line:
import { connectToHost } from '@unaiverse/gui-kit';A single HTML page has no bundler to resolve the name of a package. It uses the downloaded file unaiverse-gui.js with its types next to the page (Installation) and imports it by its path ('./unaiverse-gui.js'). In both cases the import is a standard ES module import and the kit is a module of your project like any other:
- In a plain page the file sits next to your page and the browser downloads it from your site when the page starts.
- In Vite
npm installputs the kit innode_modulesand Vite bundles it with the rest of your code.npm run devserves it andnpm run buildwrites it into the built files. Your visitors download it from your site and nothing comes from UNaIVERSE.
A single HTML page
The quickest setup has one file and needs no build and no installation. It suits small views and prototypes.
my-view/
index.html
unaiverse-gui.js
unaiverse-gui.d.ts<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Arena</title>
</head>
<body>
<!-- type="module": the kit is an ES module, and this allows `import` and top-level `await`. -->
<script type="module">
import { connectToHost } from './unaiverse-gui.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}`,
};
// 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.';
});
</script>
</body>
</html>Run it. Serve the folder with any local web server and open the address it prints:
cd my-view
npx serve # then open http://localhost:3000
# or, with Python:
python3 -m http.server 8000 # then open http://localhost:8000A page opened as a file (with a double-click on index.html) cannot load the kit (Installation).
A script that grows can move to its own file main.js next to unaiverse-gui.js and load with <script type="module" src="./main.js"></script>. The line that imports the kit stays the same.
Vite with plain JavaScript
Vite gives your view npm packages, a production build and a development server that reloads the page on every save. The smallest Vite project for a view has these files:
my-view/
package.json
index.html
src/
main.js{
"name": "my-view",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@unaiverse/gui-kit": "^1.0.0"
},
"devDependencies": {
"vite": "^8.3.6"
}
}Vite starts from index.html and follows its <script> tag to src/main.js:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Arena</title>
</head>
<body>
<script type="module" src="/src/main.js"></script>
</body>
</html>src/main.js is the view of the Quick start:
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.';
});Run it:
cd my-view
npm install
npm run dev # then open http://localhost:5173
npm run build # writes the finished view into dist/
npm run preview # serves dist/, to try the buildVite 6 or older
Vite 7 and newer build the top-level await of main.js as it is. With Vite 6 or older npm run build stops with "Top-level await is not available in the configured target environment" and needs this vite.config.js next to package.json:
import { defineConfig } from 'vite';
// Build for browsers that support top-level await (every current browser does).
export default defineConfig({
build: { target: 'es2022' },
});Vite with React
The same view with React needs React, Vite and the React plugin for Vite:
my-view/
package.json
vite.config.js
index.html
src/
main.jsx
App.jsx
useWorld.js{
"name": "my-view",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@unaiverse/gui-kit": "^1.0.0",
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@vitejs/plugin-react": "^6.2.1",
"vite": "^8.3.6"
}
}vite.config.js enables the React plugin and needs no entry for the kit:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// The React plugin turns your .jsx files into JavaScript.
// The kit needs nothing here: Vite finds the package in node_modules like any other.
export default defineConfig({
plugins: [react()],
});index.html holds the element into which React renders:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Arena</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>src/main.jsx starts React with createRoot:
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
// Draws your view into <div id="root"> of index.html.
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
);src/App.jsx is the React view of the Quick start:
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>
</>
);
}src/useWorld.js is the hook that every React view uses. It connects once and re-renders your component at every change of the world. It is also the only file that imports the kit. Copy it as it is (useWorld):
// useWorld.js: copy this file next to your React components.
// It connects your view to the world it is for and keeps your component up
// to date by rendering it again at every change of the world.
import { useEffect, useState } from 'react';
import { connectToHost } from '@unaiverse/gui-kit';
/**
* Gives a React component the world its view is for.
*
* - `world` is null until the world arrives, then the newest world after every change.
* - `error` holds the error when the view cannot connect (its `code` says why, for example 'no-host').
*
* Pass `{ fake: { world: { ... } } }` while you build (no account, no network),
* and nothing in the webapp.
*
* @param {object} [options] - What `connectToHost` takes, for example `{ fake: { world } }`.
* @returns {{ world: object | null, error: Error | null }}
*/
export function useWorld(options) {
const [state, setState] = useState({ world: null, error: null });
useEffect(() => {
let isActive = true;
let stop = () => {};
connectToHost(options)
.then((world) => {
if (!isActive) return;
// Called at once, then after every change of the world.
stop = world.subscribe((next) => setState({ world: next, error: null }));
})
.catch((error) => {
if (isActive) setState({ world: null, error });
});
return () => {
isActive = false;
stop();
};
// Connect once, when the component appears.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return state;
}Run it with the same commands as above: npm install, npm run dev, npm run build.
Strict mode
In development the StrictMode of React runs every effect twice to expose bugs. useWorld stops the first connection in the cleanup of its effect and keeps the second. In the built view effects run once.
TypeScript
The TypeScript templates of Vite work in the same way with the same import line. TypeScript reads the types of the package in node_modules and finds unaiverse-gui.d.ts next to a downloaded unaiverse-gui.js by itself. Completion in your editor shows how to leave the file of the kit out of the type checks.
Putting it online
Every setup produces plain files to put online (index.html for the single page and the dist/ folder for Vite). Before you upload them:
- remove the fake world by calling
connectToHost()oruseWorld()with no argument - serve them over HTTPS from your own server with the header that lets the webapp show them in an iframe (Going live gives it for nginx, Apache and Express)
- for a view in a subfolder such as
https://your.site/views/arena/, writebase: './'invite.config.jsbecause Vite otherwise writes addresses from the root of the site (/assets/...).
Then write the address of your view in the Own view field of your world (Going live).
What was checked
On 6 November 2026 we built every setup above from its files with Vite 8.3.6, React 19.3.1 and @vitejs/plugin-react 6.2.1 and opened each one in a headless browser. We served the single page with python3 -m http.server and both Vite setups with npm run dev and after npm run build. Each setup ran on the fake world with the kit loaded from the project. The button received its answer and no request reached UNaIVERSE. In that test the two Vite setups imported the downloaded file from src/ instead of the package. The package holds the same file. Vite 6.4.5 built the plain JavaScript setup with build.target at 'es2022'.
Next steps
- Thinking in views: the ideas behind every view in any setup.
- Tutorial: the view of a world: a complete view built one step at a time.
- Installation: completion of the names of the kit in your editor.