Skip to content

Types ​

The declaration file unaiverse-gui.d.ts that ships with the kit declares field by field the type of every value that the kit passes to your view or receives from it. Your editor reads the same file for completion. The world itself has its own page.

GuiMessage ​

Each GuiMessage is one message of the conversation between the world (or agent) and the person. world.messages lists them from the oldest to the newest.

js
for (const message of node.messages) {
  addLine(`${message.from}: ${message.text ?? ''}`);
}

Its fields tell which of four kinds a message belongs to:

KindHow to know it
A message of the personfromMe is true. It has status and retry.
A note of the rules of the worldisSystem is true. These notes carry instructions, results and events.
A questionIt has form (and isAnswered, answer).
An answer to a questionIt has values and answers.

Whatever its kind, a message keeps each part in its own field: the text in text, the images in images, the files in files, the videos, audio, PDFs and links in media and the charts in charts.

Fields added in November 2026

images, files, media, charts, fromId and answers are undefined in a webapp older than November 2026 such as a phone app that has not been updated yet. Read them with a fallback like message.images ?? [] or message.fromId ?? null.

id ​

string. The id of the message. It stays the same after every change and serves as the key of a list item.

jsx
{node.messages.map((message) => <li key={message.id}>{message.text}</li>)}

text ​

string | null. The text alone or null for a message without text (for example an image or a file with no caption). For a question it holds the text shown before the form. For an answer it holds a readable line such as 'direction: left'.

text never repeats a part that has its own field (a form in form, a video in media, a chart in charts). A view that renders the video needs no extra sentence about it. On the other hand, a part of a kind not yet supported by the kit arrives in text as a sentence that describes it. A view that renders text therefore loses no part of the message.

js
line.textContent = message.text ?? '';

image ​

string | null. The first image (the same as images[0]) as a URL or data URI for img.src or null for a message without images. A view that renders one image per message needs only this field.

js
if (message.image) picture.src = message.image;

images ​

string[], missing with an older webapp. Every image of the message in order as data URIs (an empty array for a message without images).

js
for (const source of message.images ?? []) {
  const picture = document.createElement('img');
  picture.src = source;
  picture.alt = '';
  bubble.append(picture);
}

files ​

GuiFile[], missing with an older webapp. The files attached to the message such as the file sent by the person with send({ file }) or the files of an agent. The array is empty for a message without files.

js
for (const file of message.files ?? []) {
  const link = document.createElement('a');
  link.textContent = file.name ?? 'Download the file';
  if (file.url) {
    link.href = file.url;
    link.download = file.name ?? 'file';
  }
  bubble.append(link);
}

media ​

GuiMedia[], missing with an older webapp. The videos, audio, PDFs and links of the message as web addresses (an empty array when there are none).

js
for (const media of message.media ?? []) {
  const link = document.createElement('a');
  link.href = media.url;
  link.target = '_blank';
  link.textContent = media.title ?? media.alt;
  bubble.append(link);
}

charts ​

GuiChart[], missing with an older webapp. The charts of the message as data that your view renders (an empty array when there are none).

js
for (const chart of message.charts ?? []) drawChart(canvas, chart);

from ​

string | null. The display name of the sender (the name of the world for its notes and the name of a member or of the agent for their messages). For the messages of the person it is a fixed placeholder ('me' in the webapp, 'You' with a fake world) and never the nickname of the person that your view finds in me. Test fromMe instead and render your own label for the person. fromId identifies the member who wrote the message.

js
author.textContent = message.fromMe ? 'You' : message.from;

fromId ​

string | null, missing with an older webapp. The id of the author:

  • the id of a member (the same as its id in world.members) for the messages of a member
  • the id of the world (world.id) for the notes and the messages of the world (the id of the agent in the view of an agent)
  • null for the messages of the person. It is never the id of the person because your view does not receive it.
js
const author = node.members?.find((member) => member.id === message.fromId);
label.textContent = author ? `${author.name} · ${author.role}` : message.from;

As in the example, fall back on from for a member who left the world and is no longer in members. openProfile(message.fromId) opens the profile card of the author. When showsSenders is false the world asks views to hide who wrote each message. In that case render no name or picture next to the message.

time ​

number. The time of the message in Unix milliseconds.

js
when.textContent = new Date(message.time).toLocaleTimeString();

fromMe ​

boolean. true for the messages of the person including those your view sent on their behalf.

js
line.style.textAlign = message.fromMe ? 'right' : 'left';

isSystem ​

boolean. true for the notes written by the rules of the world such as instructions, results and events. Render them differently from the messages of people and agents.

js
line.style.fontStyle = message.isSystem ? 'italic' : 'normal';

status ​

'sending' | 'sent' | 'failed', only on the messages of the person (undefined on the others). It is 'sending' while the message is pending and then becomes 'sent' or 'failed'.

js
tick.textContent = { sending: '…', sent: '✓', failed: '!' }[message.status] ?? '';

retry() ​

() => Promise<SendResult>, only on the messages of the person. It sends the message again when its status is 'failed' (message.retry()).

js
if (message.status === 'failed') await message.retry();

form ​

FormSpec, only on questions. The form as the sender wrote it with two normalizations: (1) every option of a 'select' field is a { value, label } object and (2) every 'select' field has a max (1 when the sender gave none).

js
const fields = message.form?.fields ?? [];

isAnswered ​

boolean, only on questions. true once an answer to the question is among the messages.

js
const open = node.messages.filter((message) => message.form && !message.isAnswered);

answer(values) ​

(values: Record<string, unknown>) => Promise<SendResult>, only on questions. It answers the question with an object keyed by field name (message.answer(values)).

js
await message.answer({ direction: 'left' });

values ​

Record<string, unknown>, only on answers. The values chosen by the person (or by the receiver) keyed by field name.

js
if (message.values) summary.textContent = `Chose ${message.values.direction}`;

answers ​

string, only on answers and missing with an older webapp. The id of the question answered by this message. Use it to render the answer next to its question or the question above its answer.

js
const question = node.messages.find((other) => other.id === message.answers);
quote.textContent = question?.text ?? '';

GuiFile ​

The files of a message in message.files have the same shape as a file in the data of the world.

js
const link = document.createElement('a');
link.href = file.url;
link.download = file.name ?? 'file';
link.textContent = `Download ${file.name ?? 'the file'}`;

name ​

string | null. The name of the file such as 'cv.pdf' or null when the sender gave none. Only the files sent by the person keep their name. The files of an agent arrive with name: null and need a label of your own ("Download the file") or a name derived from the type.

js
label.textContent = file.name ?? `A ${file.type ?? 'file'}`;

type ​

string | null. The MIME type of the file ('application/pdf', 'text/plain', ...) or null when it is not known. Use the type to choose an icon or a way to render the file.

js
icon.textContent = file.type === 'application/pdf' ? 'PDF' : 'File';

url ​

string | null. The content of the file as a data URI (data:application/pdf;base64,...). Used as the href of a link with the download attribute it lets the person save the file. After the webapp reloads, url is null for a file sent by the person because the webapp keeps its name and drops its content.

js
if (file.url) link.href = file.url;
else link.textContent = `${file.name} (sent earlier)`;

GuiMedia ​

message.media holds videos, audio files, PDFs and links that are hosted on the web. The message carries only their address.

Its type decides the element that renders it:

typeShow it with
'video/mp4', 'video/webm', ...<video controls preload="none">
'audio/mpeg', 'audio/ogg', ...<audio controls preload="none">
'image/jpeg', 'image/png', ...<img>
'application/pdf'a link that opens it
'video/youtube', 'video/vimeo'the player of that site, only after the person clicks
anything elsea link
js
function mediaElement(media) {
  const isPlayer = media.type === 'video/youtube' || media.type === 'video/vimeo';
  if (!isPlayer && (media.type.startsWith('video/') || media.type.startsWith('audio/'))) {
    const player = document.createElement(media.type.startsWith('audio/') ? 'audio' : 'video');
    player.src = media.url;
    player.controls = true;
    player.preload = 'none'; // nothing loads before the person presses play
    player.setAttribute('aria-label', media.alt);
    return player;
  }
  // A PDF, a link, or a YouTube or Vimeo video: a link here.
  const link = document.createElement('a');
  link.href = media.url;
  link.target = '_blank';
  link.textContent = media.title ?? media.alt;
  return link;
}

Mount a YouTube or Vimeo player only after a click. The player is an iframe from the provider. As soon as it is mounted it loads the scripts of the provider and may store cookies. Do as the UNaIVERSE view does and render the title (or alt) with a play button. Replace them with the player when the person clicks.

url ​

string. The https: address of the resource. For 'video/youtube' and 'video/vimeo' it is the address of the video on that site.

js
link.href = media.url;

type ​

string. A MIME type such as 'video/mp4', 'audio/mpeg', 'image/jpeg' and 'application/pdf' or the provider types 'video/youtube' and 'video/vimeo'. The table above maps each type to its rendering.

js
const isSound = media.type.startsWith('audio/');

title ​

string | null. A caption of the resource or null when the sender gave none.

js
caption.textContent = media.title ?? '';

poster ​

string | null. The https: address of a preview image shown before playback (null when there is none). Like the resource itself, it loads from the web as soon as it is rendered.

js
if (media.poster) video.poster = media.poster;

alt ​

string. A sentence that describes the resource. It is always present and serves screen readers and views that do not render the media.

js
player.setAttribute('aria-label', media.alt);

GuiChart ​

A chart in message.charts holds data instead of an image. Render it with your own code (a <canvas>, an SVG, a chart library) or show its alt.

js
// { kind: 'bar', series: [{ label: 'Steps', points: [['Mon', 4000], ['Tue', 5200]] }], alt: 'Steps per day' }
const chart = message.charts[0];

kind ​

'bar' | 'line' | 'pie'. The kind of chart that your view renders from series.

js
if (chart.kind === 'pie') drawPie(canvas, chart.series[0]);

series ​

Array<{ label: string; points: Array<[string | number, number]> }>. From 1 to 10 series that each have a name (label) and at most 500 points. A point is [x, y] where x is a label ('Mon') or a number and y is a number. Each point of a pie chart is a slice with its label and its value.

js
for (const series of chart.series) {
  for (const [x, y] of series.points) addBar(series.label, x, y);
}

alt ​

string. A sentence that describes the chart. It is always present for screen readers and for views that show it in place of the chart.

js
canvas.setAttribute('aria-label', chart.alt);

GuiMember ​

world.members holds a GuiMember object for each agent and person in the world except the person using your view.

js
for (const member of node.members ?? []) {
  addLine(`${member.name} · ${member.role}${member.isMaster ? ' (master)' : ''}`);
}

id ​

string. The id of the member stays the same at every visit and works as a key.

jsx
<li key={member.id}>{member.name}</li>

name ​

string | null. The name of the member (its role until the member shares its profile).

js
label.textContent = member.name ?? 'Someone';

type ​

'agent' | 'person' | 'world' | 'unknown'. The kind of member ('unknown' until the member shares its profile).

js
icon.textContent = member.type === 'person' ? '🙂' : '🤖';

role ​

string | null. The name of the role of the member (one of the names in world.roles).

js
badge.textContent = member.role ?? '';

isMaster ​

boolean. true for a member that is one of the masters running the world.

js
crown.hidden = !member.isMaster;

status ​

'online' | 'connecting' | 'offline'. Whether the member is reachable now or still connecting.

js
dot.style.background = member.status === 'online' ? 'green' : 'gray';

data ​

Record<string, unknown>. The named values of the member decoded in the same way as the data of the world.

js
score.textContent = member.data.score ?? 0;

GuiMe ​

A GuiMe describes the person using your view. It holds the fields they chose to share when they accepted your view in the webapp. It is in world.me and in the value identity() resolves to. The nickname is always present. Every other field is present only when the person ticked it at the first consent and their profile contains it. All of them are public fields of the profile. Your view never receives the email, the exact position, the other worlds and agents or any credential of the person.

js
const { nickname, city } = world.me ?? {};
greeting.textContent = city ? `Welcome, ${nickname}, from ${city}` : `Welcome, ${nickname ?? 'guest'}`;

nickname ​

string. The public nickname of the person on UNaIVERSE. It can change and a freed nickname can go to someone else. Do not use it alone as the key of data you keep about a person.

js
title.textContent = `${world.me.nickname}'s board`;

name ​

string, optional. The first name of the person.

surname ​

string, optional. The surname of the person.

js
const fullName = [world.me.name, world.me.surname].filter(Boolean).join(' ') || world.me.nickname;

title ​

string, optional. The title of the person as written in their profile ('Dr.', for example).

organization ​

string, optional. The organization they work for or belong to.

city ​

string, optional. The city of the person.

country ​

string, optional. The country of the person.

js
place.textContent = [world.me.city, world.me.country].filter(Boolean).join(', ');

FormSpec ​

Every question carries its form as a FormSpec. Your view reads it in message.form and writes one to ask a question with send({ text, form }).

js
await world.send({
  text: 'Your order?',
  form: {
    fields: [
      { name: 'dish', type: 'select', label: 'Dish', options: ['Pizza', 'Pasta'] },
      { name: 'notes', type: 'text', label: 'Notes' },
    ],
  },
});

id ​

string, optional. The id of the form has at most 32 characters among letters, digits, _ and -. An answer refers to its form by this id. A form without id receives a generated one and each answer still finds its question. Two open questions with the same id cannot be told apart. An answer always goes to the most recent question before it that has that id.

js
form: { id: 'move-3', fields: [...] }

name ​

string, optional. A short name for the form. Without it the form takes the id you gave as its name (or 'form' when there is no id either).

js
form: { name: 'Next move', fields: [...] }

fields ​

From 1 to 20 fields, each with these keys:

KeyWhat it is
nameThe name of the field and the key of its value in the answer. It is a letter or _ followed by letters, digits or _ (at most 64 characters).
type'text', 'textarea', 'number', 'integer', 'bool', 'date' or 'select'. Another type becomes 'text'.
labelOptional label rendered next to the field.
optionsOnly for 'select': from 1 to 50 choices as plain strings or { value, label } objects with distinct labels that contain no commas.
max, minOptional bounds. For 'select' they limit the number of chosen options (max defaults to 1) and for numbers and dates they give the range.

Other optional keys are required, help, placeholder and maxLength (text), unit (numbers) and default.

js
fields: [{ name: 'direction', type: 'select', options: ['left', 'right'] }]

A form that breaks these rules arrives as plain text with no form. A fake world is a quick place to check your forms against them.

SendValue ​

send takes a value in one of four forms:

ValueWhat it sends
stringText.
{ image, text? }An image as a URL or data URI (data:image/jpeg;base64,...) with optional text.
{ file, text? }A file of at most 20 MB (a FileToSend) with optional text.
{ text?, form }A question made of the text and a FormSpec.
js
await world.send('hello');
await world.send({ image: canvas.toDataURL('image/jpeg'), text: 'Look' });
await world.send({ file: input.files[0], text: 'My CV' });
await world.send({ text: 'Which way?', form: { fields: [{ name: 'way', type: 'select', options: ['left', 'right'] }] } });

A message you send holds one image or one file and send resolves 'failed' when it gets both image and file. The answer of a fake world, on the other hand, is a FakeAnswer that can hold more.

FileToSend ​

The file passed to send({ file, text }) takes one of three forms:

ValueWhere it comes from
a FileA file input (input.files[0]) or a file dropped on your view (event.dataTransfer.files[0]). It keeps its name and type.
a BlobContent built in the page (new Blob([text], { type: 'text/plain' })). It is sent with the name 'file'. To name it yourself, wrap it in a File as in the second line below.
{ name, type, url }A name, a MIME type and the content as a base64 data URI (data:application/pdf;base64,...).
js
await world.send({ file: picker.files[0] });
await world.send({ file: new File([csv], 'scores.csv', { type: 'text/csv' }), text: 'The scores' });
await world.send({ file: { name: 'note.txt', type: 'text/plain', url: 'data:text/plain;base64,aGVsbG8=' } });

For a file over 20 MB send rejects with the code 'too-big' and sends nothing. A url that is not a base64 data URI makes send resolve 'failed' instead.

SendResult ​

send, answer and retry resolve to this outcome of sending a message.

ValueWhat it means
'sent'Delivered.
'failed'Sent but not delivered. The message can be retried. (send also returns it without sending anything when it gets an image together with a file or a file that cannot be read.)
'not-allowed'Nothing was sent because canSend is false, the value is empty or an agent could not be reached.
js
const result = await world.send('hello');
if (result === 'failed') showRetry();

FakeAnswer ​

onMessage and onAction return a FakeAnswer in a fake world or fake agent. It is a string or an object with text, images, files, videos, charts and the form of a question. In a fake world it can also name the member who writes it.

js
onMessage: () => ({ from: 'Otto', text: 'Your move', charts: [{ kind: 'bar', series: [{ label: 'Wins', points: [['Otto', 3], ['You', 2]] }], alt: 'Wins so far' }] }),

Fake worlds › FakeAnswer lists every field and what a fake world and a fake agent keep of each.

GuiWebapp ​

world.webapp holds the state of the webapp. A change in any of its fields runs your subscribe listener again.

With a fake world webapp takes the colour scheme of your page and the language of the browser and allows every feature. To try other values, pass them to connectToHost as in connectToHost({ fake, webapp: { theme: 'dark', language: 'it' } }).

theme ​

'light' | 'dark'. The theme of the webapp that your view should match.

js
document.body.style.colorScheme = node.webapp.theme;

language ​

string. The language of the webapp as a two-letter code (today 'en' or 'it'). A fake world gives the language of the browser in the longer form the browser may use ('en-US'). Comparing the first two letters as below works with both.

js
const words = node.webapp.language.slice(0, 2) === 'it' ? italian : english;

insets ​

{ top: number; right: number; bottom: number; left: number }. The safe areas of the phone in pixels (the notch, rounded corners, the home bar) on the sides where your view touches the edge of the screen. Keep buttons out of them on a phone. On a desktop all four are 0.

js
bar.style.paddingBottom = `${node.webapp.insets.bottom}px`;

keyboard ​

number. The height in pixels of the on-screen keyboard over your view. It is 0 when the keyboard is closed and always 0 on a desktop. Lift your message box by this height.

js
messageBox.style.bottom = `${node.webapp.keyboard}px`;

allowed ​

BrowserFeature[]. The features allowed by the person after an askFor.

js
const canFilm = node.webapp.allowed.includes('camera');

BrowserFeature ​

Your view gets these browser features only after the person accepts an askFor request in the webapp. For these features the browser would keep a single consent for the whole UNaIVERSE site and every view in it. The webapp therefore asks the person separately for each view.

ValueWhat it gives
'camera'The camera (getUserMedia({ video: true })).
'microphone'The microphone (getUserMedia({ audio: true })).
'geolocation'The location of the person (navigator.geolocation).
'clipboard-read'Reading the clipboard (navigator.clipboard.readText()). Writing it is always allowed.
'midi'Music devices (Web MIDI).
'usb'USB devices (WebUSB).
'serial'Serial ports (Web Serial).
'hid'Gamepads and other input devices (WebHID).
'bluetooth'Bluetooth devices (Web Bluetooth).
'idle-detection'Detection of when the person is away from the device.
'local-fonts'The fonts installed on the device.
js
await world.askFor(['camera', 'microphone']);

Every other browser feature, from fullscreen to downloads, is available in your view without a request (Everything a web page can do).

See also ​

  • The world (GuiNode): every field and method of the world.
  • Fake worlds: FakeNode, FakeWorld and FakeAnswer for building with no account.
  • identity(): the same GuiMe as world.me for views written for an earlier version of the kit.

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