Skip to content
Not publicly available.This describes the Loupestack API before launch. Endpoints, limits and fields can still change.

Embedding generated UIs

A generated UI is a self-contained HTML document written by the language model, plus the saved queries it may run. This page is for whoever shows those documents to people: the rules below are what keeps a document from reading your users’ cookies or sending their data anywhere.

  1. Create one with POST /v1/uis and a prompt, or through POST /v1/chat. Both stream; the ui event gives uiId and version.
  2. Change it with POST /v1/uis/{id}/versions: each change is a new version, and older versions keep working.
  3. Fetch a version with GET /v1/uis/{id}/versions/{version}. It returns html and queries: the names and parameters of the queries this version may run. No SQL.

Put the version’s html into a sandboxed iframe:

<iframe sandbox="allow-scripts" srcdoc="..."></iframe>
  • Use exactly sandbox="allow-scripts". Never add allow-same-origin, allow-top-navigation, allow-popups or allow-forms. Without allow-same-origin the document has an opaque origin: it cannot read your page’s cookies or storage, or reach its DOM.
  • The html starts with a Content-Security-Policy that forbids all network access, so the document cannot load or send anything by itself. Do not strip or rewrite it.
  • If the iframe fires a second load event, the document navigated itself: remove the iframe.

The document cannot call the API. It asks your page, by postMessage, through a function the API puts in the document: platform.run(name, params). Your page:

  1. listens for message events whose source is that iframe’s contentWindow and whose data.type is platform:run, and ignores everything else;
  2. checks that data.name is one of the version’s queries (the API checks again);
  3. calls POST /v1/uis/{id}/versions/{version}/run with { "name": data.name, "params": data.params }, with the user’s session;
  4. posts the outcome back to iframe.contentWindow, with target origin '*' (the frame’s origin is opaque): { type: 'platform:result', id: data.id, result } on success, or { type: 'platform:result', id: data.id, error: { code, message } } on failure.
window.addEventListener('message', async (event) => {
if (event.source !== frame.contentWindow || event.data?.type !== 'platform:run') return;
const { id, name, params } = event.data;
if (!queryNames.has(name)) return reply(id, { error: { code: 'not_found', message: 'No such query.' } });
const res = await fetch(`https://api.dev.loupestack.com/v1/uis/${uiId}/versions/${version}/run`, {
method: 'POST',
credentials: 'include',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ name, params }),
});
const body = await res.json();
reply(id, res.ok ? { result: body } : { error: body.error });
});
const reply = (id, outcome) => frame.contentWindow.postMessage({ type: 'platform:result', id, ...outcome }, '*');

A version can only run its own queries: the API refuses any other name, whatever the document sends.

DELETE /v1/uis/{id} removes a UI, all its versions and their saved queries. The member who created it can delete it, and so can owners and admins.