> ## Documentation Index
> Fetch the complete documentation index at: https://trytilde.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Spaces and Live

> Build React spaces in the ontology project, fed only by its reads, actions, and realtime views, and open them in Live under the ontology's policies.

A space is an interactive app built on your ontology: a React page in the project repository that shows live data, runs actions, and can be embedded in your own product, always under the ontology's policies. It gets data only from the ontology's handlers, through a typed client that Tilde generates from your ontology. It never runs SQL. When a page needs new data, add a read to the ontology in the same change.

**Live** is where people use an ontology in Tilde Cloud. It lists the spaces they may open, and their chats with agents.

## Add a space

Spaces live in the ontology's `spaces/` folder, such as `ontologies/crm/spaces/`, a workspace package that depends on `@trytilde/spaces`. Each folder is one space, and its name is the space's id. A page default-exports a React component, and exports a `title`. [Spaces](https://trytilde.ai/docs/project/spaces.md) in the project guide builds a complete one.

```text theme={"system"}
ontologies/crm/spaces/
  package.json
  pipeline/index.tsx
  customers/index.tsx
```

Pages import two packages:

* `@trytilde/spaces` has the hooks, and layout, metric, chart, and data grid components with a Tailwind preset for light and dark themes. List it in `package.json`. `tilde deploy` builds the spaces with it.
* `@tilde/contract` exports one typed reference per read, action, and realtime view. The build generates it from the ontology, so don't list it. Importing a handler that does not exist is a build error.

The hooks:

| Hook | Use it to |
| - | - |
| `useRead(read, request)` | Call a read. It calls again when the request changes, or on `refetch()`. It does not poll. |
| `useRealtime(view, request)` | Subscribe to a [realtime view](https://trytilde.ai/docs/foundry/views-and-actions.md#realtime-views), for live data. |
| `useRealtimeList(view, request)` | Subscribe to a [list view](https://trytilde.ai/docs/foundry/views-and-actions.md#list-views): `rows`, `keys`, `summary`, `more`, `loading`. A larger `limit` widens the window and fetches only the new rows. |
| `useAction(action)` | Get `run(request)`, which resolves with the action's outcome, including **pending approval**. |

```tsx ontologies/crm/spaces/pipeline/index.tsx theme={"system"}
import { customerActivity, pipelineSummary } from "@tilde/contract";
import { MetricTile, Page, useRead, useRealtime } from "@trytilde/spaces";

export const title = "Pipeline";

export default function Pipeline() {
  const summary = useRead(pipelineSummary, { input: {} });
  const acme = useRealtime(customerActivity, { key: "acme", input: {} });
  return (
    <Page title={title}>
      <MetricTile label="Outstanding" value={summary.data?.outstanding} />
      <p>{acme.data?.notes.length} notes on Acme</p>
    </Page>
  );
}
```

A list view's request puts `limit`, the window's size, beside `query`, the view's own input:

```tsx theme={"system"}
const tickets = useRealtimeList(watchTickets, { input: { query: { status: "open" }, limit: 50 } });
// tickets.rows, tickets.more: ask for a larger `limit` to widen the window; only the new rows arrive.
```

Every deploy builds and publishes the spaces with the ontology.

## Who can open a space

Opening a space is a Cedar decision, like any other:

```ts theme={"system"}
import { cedar, space, group, openSpace, policy } from "@trytilde/ontology";

policy("sales-open-pipeline", cedar`permit(principal in ${group("sales")}, action == ${openSpace}, resource == ${space("pipeline")});`);
```

The space id is its folder name. Separately, each call the page makes is decided by that handler's own policies, and a space can call only the handlers its code uses. Removing someone's access takes effect within five minutes.

## Open spaces in Live

**1. Serve the environment in Live**

Switch on **Serve its spaces in Live** when you create the environment.

**2. Grant access**

Give people `view` on the project, and an `openSpace` policy for each space.

**3. Open Live**

People select **Live**, then the space. Tilde opens it for their own identity, so every call is decided as `user:<id>`.

## Roll back a space

The project's **Spaces** tab lists each space's versions per environment. Activate an earlier version to roll back one space without redeploying the ontology. An unchanged space keeps its version across deploys.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.