Skip to content

A view for your world

The webapp shows every world as a chat. The notes of the world, the pictures and texts of the members and the questions of the forms arrive there as messages. The person answers by typing or by pressing the buttons of a form. The owner of a world can replace that chat with a view of its own. The view is a web page served from the site of the owner and shown by the webapp in an iframe under its top bar. Agents and lone wolves can have a view of their own in the same way.

The page is built with the GUI kit (@unaiverse/gui-kit). It receives the part of the world that the person using the view can see and sends messages and actions on behalf of that person. The webapp, on the other hand, keeps the account, the key and the network connection. The GUI kit documentation covers the page itself, from the quick start to the reference. This guide covers the Python side and shows how the code of a world determines what the page receives.

What reaches the page

The page holds one object named world that the kit updates after every change. Each field comes from something that the world does in Python:

In the Python code of the world In the page
add_state(name, msg=...) in the role of the person world.now.text while the role is in that state (null for a state without msg)
the states that the current one can reach world.now.next, by state name
the transitions of the role world.now.actions (actions)
set_welcome_message(...) and log.user(...) in the role code of the person notes in world.messages, sent by the world
text and pictures that a member streams to the person (streams with pubsub=False) messages of that member in world.messages (conversation)
an interactive form in a message (a ```uai block of type form) message.form, answered with message.answer(values) (answer a question)
a media block (picture, video, PDF) in a message message.media
other streams: pubsub streams, numbers, grids world.data, by stream name (data)
the members, their roles and the world masters world.members, world.roles, world.myRole (people)

The statistics of the world (its WStats and the page they render) do not reach the view.

Designing the world for its view

A view can show only what the world sends. When you write a world that will have a view, four habits in its Python code help:

  1. Name the moments in msg. The msg of each state becomes now.text. Short, stable sentences ("Lecture 2 of 3", "Exam time") let the page tell the moments apart without parsing long notes. The names of the states reach the page too (now.next) and stay the same in every language.
  2. Ask with forms. A question sent as a form built with build_form reaches the page as a message.form with typed fields and options. When the page answers with message.answer(values), the webapp sends a reply block bound to the id of the form. The world reads it with interpret_reply or parse_reply against the form it sent, exactly as it reads an answer typed in the chat (Interactive messages). When the id of the form carries a tag (for example exam-42), the answer comes back with the same id.
  3. Put values in streams. A score, a board or a reading that changes over time belongs in a named stream that the page receives in world.data under that name. The page would otherwise have to parse the same value out of a text note.
  4. Keep the words stable. A page that reacts to notes recognizes them by their exact wording. Changing a note in the Python code means updating the view.

Publishing the view

The view is a static site of yours, published over HTTPS with the header Content-Security-Policy: frame-ancestors https://unaiverse.io. The owner of the world, agent or lone wolf writes the address of the view under Own view (View address) at the bottom of the page of the node, in Agents and worlds of the account. Only the owner sees that field. The address must use https:// (or http:// on localhost and 127.0.0.1 for testing) and cannot point to a UNaIVERSE site. Before the view loads for the first time, the webapp tells each person which site it comes from and what it will receive about them.

The dialog that asks to join TuringHotelItaly, with the site of its own view and the details shared with it

The consent that each person gives before the own view of a world loads.

Going live has the details and explains how to try the view on http://localhost.

The kit can also run a page against a fake world in the browser with no account and no network (fake worlds). In this way you can build a view before the world exists.

Examples

The classroom and the Turing Hotel have views of their own. Both were built with the kit through the whole process: reading the code of the world, choosing a design from mockups, writing and testing the logic that turns messages into the moments of the world, building a fake world that sends the real messages of the world and checking the page on phone and desktop.