# Surfaces

> The UI a Request carries: components, a data model, and the actions that send values back.

A notification has room for a title, a line and a few buttons. When your agent needs more, a form to check or a choice to make, it sends a Surface: a small UI that the Nibify app draws on the phone, in its own style.

This is the Surface of the invoice. `invoice-flow` has read the PDF, and before filing it asks the person to check the amount, the due date and the category:

TypeScript:

```ts
import {
  Button,
  Card,
  CheckBox,
  ChoicePicker,
  Column,
  DateTimeInput,
  Nibify,
  Text,
  TextField,
} from '@nibify/sdk';

const nibify = new Nibify({ apiKey: 'sk_test_…' });

const surface = {
  root: 'root',
  dataModel: {
    amount: '1240',
    due: '2026-10-30',
    category: ['consulting'],
    recurring: false,
  },
  components: [
    Card('root', { child: 'body' }),
    Column('body', {
      children: ['title', 'ask', 'amount', 'due', 'category', 'recurring', 'file'],
    }),
    Text('title', { text: 'Kiwi Studio invoice', variant: 'h4' }),
    Text('ask', { text: 'Check it before I file it.' }),
    TextField('amount', {
      label: 'Amount',
      variant: 'number',
      value: { path: '/amount' },
    }),
    DateTimeInput('due', {
      label: 'Due',
      enableDate: true,
      value: { path: '/due' },
    }),
    ChoicePicker('category', {
      label: 'Category',
      options: [
        { label: 'Software', value: 'software' },
        { label: 'Consulting', value: 'consulting' },
      ],
      value: { path: '/category' },
    }),
    CheckBox('recurring', {
      label: 'Recurring',
      value: { path: '/recurring' },
    }),
    Button('file', {
      variant: 'primary',
      child: 'file-label',
      action: {
        event: {
          name: 'file',
          context: {
            amount: { path: '/amount' },
            due: { path: '/due' },
            category: { path: '/category' },
            recurring: { path: '/recurring' },
          },
        },
      },
    }),
    Text('file-label', { text: 'File it' }),
  ],
};

const result = await nibify.ask(surface, {
  sender: { name: 'invoice-flow' },
  notification: {
    title: 'Kiwi Studio invoice',
    body: 'Check it before I file it.',
  },
});

if (result.status === 'answered') {
  result.response.actionName; // 'file'
  result.response.context; // { amount: '1420', due: '2026-10-30', category: ['consulting'], recurring: false }
}
```

curl:

```bash
curl -X POST https://api.nibify.app/v1/requests \
  -H "Authorization: Bearer sk_test_…" \
  -H "Content-Type: application/json" \
  -d '{
    "sender": { "name": "invoice-flow" },
    "notification": {
      "title": "Kiwi Studio invoice",
      "body": "Check it before I file it."
    },
    "surface": {
      "root": "root",
      "dataModel": {
        "amount": "1240",
        "due": "2026-10-30",
        "category": ["consulting"],
        "recurring": false
      },
      "components": [
        { "id": "root", "component": "Card", "child": "body" },
        {
          "id": "body",
          "component": "Column",
          "children": ["title", "ask", "amount", "due", "category", "recurring", "file"]
        },
        {
          "id": "title",
          "component": "Text",
          "text": "Kiwi Studio invoice",
          "variant": "h4"
        },
        {
          "id": "ask",
          "component": "Text",
          "text": "Check it before I file it."
        },
        {
          "id": "amount",
          "component": "TextField",
          "label": "Amount",
          "variant": "number",
          "value": { "path": "/amount" }
        },
        {
          "id": "due",
          "component": "DateTimeInput",
          "label": "Due",
          "enableDate": true,
          "value": { "path": "/due" }
        },
        {
          "id": "category",
          "component": "ChoicePicker",
          "label": "Category",
          "options": [
            { "label": "Software", "value": "software" },
            { "label": "Consulting", "value": "consulting" }
          ],
          "value": { "path": "/category" }
        },
        {
          "id": "recurring",
          "component": "CheckBox",
          "label": "Recurring",
          "value": { "path": "/recurring" }
        },
        {
          "id": "file",
          "component": "Button",
          "variant": "primary",
          "child": "file-label",
          "action": {
            "event": {
              "name": "file",
              "context": {
                "amount": { "path": "/amount" },
                "due": { "path": "/due" },
                "category": { "path": "/category" },
                "recurring": { "path": "/recurring" }
              }
            }
          }
        },
        { "id": "file-label", "component": "Text", "text": "File it" }
      ]
    }
  }'
```

## The shape

A Surface is [A2UI](https://github.com/a2ui-project/a2ui), the open protocol for agents that send UI, at version 0.9. It has three parts:

- `components`, a flat list. Each one has an `id`, a `component` type and its properties. A container names its children by id: `child` for one, `children` for several.
- `root`, which is always `"root"`: the id of the component drawn first.
- `dataModel`, the values the Surface starts with.

The list is flat and the tree is in the ids. In the invoice, `root` is a `Card` whose `child` is the `Column` called `body`, and the `children` of `body` are the title, the four fields and the button.

The SDK has a constructor for every component, such as `Text('title', { … })`. It builds the same JSON, with the properties of each component typed.

## The components

What each component is, and which properties it takes, is in [the catalog](https://nibify.app/catalog): every component drawn as the phone draws it, with its JSON and what it sends back. It is the reference for them, and this page does not repeat it.

A Surface may use only the components of the catalog. Nibify checks every Surface when you send it, and refuses one the app could not draw with `422 surface_invalid`, naming the component and the property at fault.

## The data model

A field is bound to the `dataModel` by a JSON Pointer: `"value": { "path": "/amount" }` shows `dataModel.amount`, and writes back to it as the person types. The invoice starts from what the agent read in the PDF, `1240`, `2026-10-30` and `consulting`. The person sees those values, corrects what is wrong, and the `dataModel` follows.

Nothing leaves the phone while they do. Values typed and not sent stay on that phone as a Draft, and the Request stays `pending`.

## Actions and context

A `Button` carries an `action`: a `name`, and a `context` that says what to send with it. When the button is pressed, the app sends the `name`, and the `context` with every `{ "path": … }` replaced by what the `dataModel` holds at that moment. In the invoice, **File it** sends the action `file`, and its `context` asks for all four fields.

The person changes the amount to 1420 and presses **File it**. The Request is `answered`, and this is what your agent reads:

```json
{
  "requestId": "msg_…",
  "status": "answered",
  "createdAt": "2026-10-12T09:00:00Z",
  "expiresAt": null,
  "environment": "test",
  "deliveredAt": "2026-10-12T09:00:02Z",
  "readAt": "2026-10-12T09:01:10Z",
  "contentDeletedAt": null,
  "response": {
    "responseId": "res_…",
    "actionName": "file",
    "sourceComponentId": "file",
    "context": {
      "amount": "1420",
      "due": "2026-10-30",
      "category": ["consulting"],
      "recurring": false
    },
    "clientTimestamp": "2026-10-12T09:01:32Z",
    "answeredAt": "2026-10-12T09:01:32Z"
  }
}
```

`context` holds what the action asked for, exactly as it was on the screen: the amount is the string the person typed, and a choice is always a list. The `dataModel` itself never comes back, so if your agent needs a value, the action's `context` must name it. `sourceComponentId` is the `id` of the button that was pressed.

## A Surface with quickActions

A Request can have both: buttons on the notification and a Surface in the app. The `name` of each quickAction must be an action the Surface sends, or the Request is refused: tapping it on the lock screen answers the same question without opening it.

An answer from the lock screen arrives with `"sourceComponentId": "notification"` and an empty `context`, because nothing was filled in. That is how your agent tells a tap on the notification from a button pressed in the app.

## Older apps

Every component records the catalog version it arrived in. From the components a Surface uses, Nibify works out the oldest app that can draw it, and returns it as `minCatalogVersion` in the `201`. If none of the person's phones is that recent, the Request is still created, with a `catalog_version_too_low` entry in `warnings`. The notification and its `quickActions` work on any version: only the Surface asks for an update.

## On a Notification

A Notification can carry a Surface too, to show more than a line, as long as it only shows things. A button with an action is a question, and a question belongs to a Request.

## Next

- [Wait for the answer](https://nibify.app/docs/wait-for-the-answer): Get the answer back by waiting for it with ask() or the long poll, or by a callback when your code cannot wait.
- [Requests API](https://nibify.app/docs/rest/requests): Every /v1/requests endpoint: list the Requests of this Project, create a Request, read a Request, withdraw a Request, re-notify a pending Request, await the outcome of a Request.
