# Runtime SDK

> The sdk prop App Engine passes to every app. Session, input, context and identity; data, files, people and notifications; navigation; and the calls that end a session with or without output.

Source: https://docs.sommatic.ai/en/apps/runtime-sdk/ (updated 2026-11-26)

Your app never imports the runtime. App Engine builds an `sdk` object for each session and passes it as a prop to the
entry component. Pass it down through props; do not keep it in a React context or a global.

```jsx
// src/main.jsx
export default function AppEntry({ sdk }) {
  return <App sdk={sdk} />;
}
```

## What the app receives

### `sdk.session`

| Property           | What it is                                                                                    |
| ------------------ | --------------------------------------------------------------------------------------------- |
| `id`               | The session id.                                                                               |
| `appId`, `appSlug` | The app definition id and slug.                                                               |
| `launchMode`       | How the app was opened. See [launch modes](https://docs.sommatic.ai/en/apps/launch-modes.md). |
| `routePath`        | The current route inside the app (`/` by default).                                            |

### `sdk.input`

The payload the app was opened with, shaped by `contracts/input.schema.json`. It is `{}` when there is no input.

```javascript
const input = sdk.input || {};
const hasInput = Object.keys(input).length > 0;
```

### `sdk.context`

| Property        | What it is                                                                            |
| --------------- | ------------------------------------------------------------------------------------- |
| `appDefinition` | The app definition: name, slug, manifest, routes, contracts.                          |
| `appVersion`    | The active version.                                                                   |
| `user`          | The signed-in identity (the same object as `sdk.identity`).                           |
| `task`          | The task metadata (priority, assignee, due date) when the app was opened from a task. |
| `data`          | Extra context from whoever opened the app.                                            |

### `sdk.identity`

The signed-in Veripass identity, or `null` while it loads: `veripassIdentity`, `userId`, `organizationId`,
`displayName`, `username`, `avatarUrl`, `email` and `memberships`.

## Read and write

### `sdk.api`

`get(url, params?, options?)`, `post(url, body?, options?)`, `patch(url, body?, options?)` and
`delete(url, params?, options?)`. Requests are scoped to the endpoints the app is allowed to call. With
`options.withIdentity: true`, the request carries the identity headers (`Authorization: Bearer <token>`, the
organization and the app session).

```javascript
const items = await sdk.api.get('/items', { status: 'active' });
await sdk.api.patch('/items/123', { status: 'active' });
```

### `sdk.data`

The app's own record store. Records are always scoped to the app, so an app never reads another app's records. Writes
are optimistic and survive going offline: they are cached and replayed when the connection returns.

| Scope          | Shared with                                    |
| -------------- | ---------------------------------------------- |
| `app`          | Everyone in the organization who uses the app. |
| `user-appdata` | One person, in one app and one organization.   |
| `user`         | One person, across organizations.              |

```javascript
const note = await sdk.data.create('notes', {
  scope: 'user-appdata',
  title: 'Weekly sync',
  data: { html: '' },
});

await sdk.data.update(note.id, { data: { html: '<p>Agenda</p>' } }, { expectedRevision: note.revision });

const { items } = await sdk.data.list('notes', { scope: 'user-appdata' });
```

It also offers `get`, `search`, `remove`, `restore`, `getKey` and `setKey`, `patch` for atomic field operations,
`batch` for all-or-nothing writes, `subscribe` for changes and `status` for the sync state.

### `sdk.files`

Binary content. `upload(file, { space })` returns the file `id`; store the `id`, not the URL. `getUrl(id)` returns a
short-lived URL to display or download it.

### `sdk.directory`

People of the active organization: `searchPeople(text)`, `listMembers()`, `listTeams()`, `listTeamMembers(teamId)` and
`getUser(identityOrEmail)`.

### `sdk.notify(notification)`

Shows a host notification (`title`, `body`, `severity`, optional `actions`, `deepLink`, `tag`, `duration`), filtered by
the person's notification preferences.

## Move around

- **`sdk.navigate(path)`** switches to another route of the app (`/`, `/list`, `/settings`).
- **`sdk.apps.open({ slug, route, input, mode })`** opens another app of the organization. The app must list the slug
  in `manifest.opens_apps`. It resolves to `{ opened: true }` or `{ opened: false, reason }` with `reason`
  `not_allowed`, `not_found`, `not_entitled` or `invalid_route`. `sdk.apps.canOpen(slug)` and `sdk.apps.list()` tell you
  beforehand.

## End the session

| Call                        | What it does                                                                   |
| --------------------------- | ------------------------------------------------------------------------------ |
| `sdk.submitOutput(payload)` | Stores the final output on the session, marks it completed and closes the app. |
| `sdk.saveDraft(payload)`    | Saves work in progress; the session stays open. Can be called many times.      |
| `sdk.close()`               | Closes the app without output.                                                 |
| `sdk.cancel(reason)`        | Cancels the session without output.                                            |

```javascript
sdk.submitOutput({
  decision: 'approved',
  notes: 'All requirements met.',
  reviewed_at: new Date().toISOString(),
});
```

> **Warning: Validate before you submit**
>
> Send a payload that matches `contracts/output.schema.json`. The session stores the payload as it is sent, so check
> required fields in the app before calling `submitOutput`.

## Good practice

1. Use optional chaining (`sdk?.session?.launchMode`): properties may be undefined while the app initializes.
2. Check the input before you render a view that depends on it.
3. Call `saveDraft` during long reviews so people can leave and come back.
4. Keep the payload of `submitOutput` to what consumers need.

## Next steps

- [Contracts](https://docs.sommatic.ai/en/apps/contracts.md): Shape sdk.input and the output.
- [Launch modes](https://docs.sommatic.ai/en/apps/launch-modes.md): Adapt the layout to where the app opens.
