# Add the Command Center to your app

> Mount the Command Center in a React app with three providers, register its commands, and make each page operable with a co-located *.sommatic.jsx file.

Source: https://docs.sommatic.ai/en/command-center/integration/ (updated 2026-11-26)

At the end of this page your app has the Command Center panel, the 37 built-in commands, and pages that tell the
Command Center what they show and what can be done on them. Everything comes from `@sommatic/react-sdk`.

## Install

```bash
npm install @sommatic/react-sdk @veripass/react-sdk @link-loom/react-sdk
```

The SDK expects React 17 to 19 and React Router 5 to 7 in your app. Point its services at your backend once, before the
first render, as shown in [Configuration](https://docs.sommatic.ai/en/sdks/react/configuration.md).

## Mount the providers

The Command Center needs an identity already established, so it goes inside `AuthProvider` from Veripass. Omnisearch is
independent and usually wraps the layout:

```javascript
import { AuthProvider } from '@veripass/react-sdk';
import { OmniSearchRegistryProvider } from '@link-loom/react-sdk';
import {
  CommandCenterProvider,
  CommandCenterSidebar,
  ConversationExecutionService,
  ConversationManagementService,
  CognitiveInfrastructureLLMProviderService,
  WorkManagementTaskService,
} from '@sommatic/react-sdk';

const executionService = new ConversationExecutionService();
const taskService = new WorkManagementTaskService();

export function App() {
  return (
    <AuthProvider>
      <CommandCenterProvider
        executionService={executionService}
        conversationManagementService={ConversationManagementService}
        llmProviderService={CognitiveInfrastructureLLMProviderService}
        taskService={taskService}
        pageCatalog={pageCatalog}
      >
        <OmniSearchRegistryProvider>
          <Layout />
          <CommandCenterSidebar />
        </OmniSearchRegistryProvider>
      </CommandCenterProvider>
    </AuthProvider>
  );
}
```

Mount `CommandCenterProvider` **once**, near the top of the tree. Mounting it twice resets its registry, and mounting
the sidebar without it throws.

| Prop                            | What it is                                                                                                                                                                                                                                                                                    |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `executionService`              | An instance with `execute(envelope)` and, optionally, `executeStream(envelope, callbacks)`. `ConversationExecutionService` calls `/chat/conversation/execute` and `/chat/conversation/execute/stream`. With `executeStream` the panel streams; without it, it falls back to a single request. |
| `conversationManagementService` | The class that stores conversation history.                                                                                                                                                                                                                                                   |
| `llmProviderService`            | The class that lists the LLM providers the person can pick in the panel.                                                                                                                                                                                                                      |
| `taskService`                   | Optional. The task service used by the task commands.                                                                                                                                                                                                                                         |
| `currentUser`                   | Optional. The signed-in user.                                                                                                                                                                                                                                                                 |
| `commands`                      | Optional. Command definitions to register from the start.                                                                                                                                                                                                                                     |
| `pageCatalog`                   | Optional. `[{ path, description }]`: the pages `/navigate` can resolve from a request in natural language.                                                                                                                                                                                    |
| `appCatalog`                    | Optional. `[{ slug, name, description, tags, default_route }]`: the apps `/open-app` can resolve.                                                                                                                                                                                             |

## Register the commands

Build the built-in commands with `getReadCommands` and `getExecCommands` from a component inside the provider, and
register them with `registerCommands`, which returns a function that unregisters them:

```javascript
import { useEffect, useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useCommandCenter, getReadCommands, getExecCommands } from '@sommatic/react-sdk';

export function CommandCenterCommands({ icons }) {
  const navigate = useNavigate();
  const { registerCommands, getContext, registry } = useCommandCenter();

  const commands = useMemo(
    () => [...getReadCommands({ getContext, icons, registry }), ...getExecCommands({ navigate, icons, registry })],
    [getContext, navigate, registry, icons],
  );

  useEffect(() => registerCommands(commands), [commands, registerCommands]);

  return null;
}
```

## Open the panel from anywhere

The sidebar listens to DOM events in the `sommatic:` namespace. To open it from a button or another feature, optionally
with a first message:

```javascript
window.dispatchEvent(
  new CustomEvent('sommatic:open-command-center', {
    detail: { initialMessage: '/page-outline' },
  }),
);
```

The sidebar broadcasts `sommatic:command-center-opened` and `sommatic:command-center-closed`. `CommandCenterTrigger`
is a ready-made button that opens and closes it.

## Make a page operable with `*.sommatic.jsx`

A page tells the Command Center what it shows and what can be done on it through a small wrapper that sits next to it.
The wrapper renders nothing; it only registers.

### Create the wrapper next to the page

Name it after the page: `OrganizationEdit.sommatic.jsx` next to `OrganizationEdit.jsx`. It receives the page's refs and
handlers as props, never its own state, and returns `null`. Its default export ends in `Sommatic`.

### Publish a context source

`useSommaticContextSource` publishes a snapshot the model can read. Use the id `page-context` for the main one: read
commands fall back to it when no source is named.

### Publish surfaces and targets

`useSommaticSurface` publishes a region (`panel`, `form`, `grid`, `modal`, `list`) with its handlers (`submit`,
`cancel`, `open`, `close`, `setFields`) and its **targets**: the inputs, buttons, links and rows inside it, each with
handlers such as `fill`, `getValue` and `click`.

### Render it from the page

Render the wrapper next to the page's own markup, passing the refs and handlers it needs.

```javascript
import { useSommaticContextSource, useSommaticSurface } from '@sommatic/react-sdk';

function OrganizationEditSommatic({ formDataRef, handleSubmit, setIsOpen }) {
  useSommaticContextSource(
    {
      id: 'page-context',
      description: 'Organization edit form.',
      getData: () => ({ ...formDataRef?.current }),
    },
    [],
  );

  useSommaticSurface(
    {
      id: 'organization-edit-form',
      type: 'form',
      label: 'Edit organization',
      handlers: {
        submit: () => {
          handleSubmit?.();
          return { submitted: true };
        },
        cancel: () => {
          setIsOpen?.(false);
          return { cancelled: true };
        },
      },
      targets: [
        {
          id: 'organization-edit-display-name',
          type: 'input',
          label: 'Display name',
          aliases: ['name', 'nombre', 'business name'],
          handlers: {
            getValue: () => formDataRef?.current?.display_name,
            fill: (value) => formDataRef?.current && (formDataRef.current.display_name = value),
          },
        },
      ],
    },
    [],
  );

  return null;
}

export default OrganizationEditSommatic;
```

A target is addressed as `surface_id::target_id`, here `organization-edit-form::organization-edit-display-name`. The
Command Center finds it by exact id first and then by label and `aliases`, so aliases in other languages help people
who ask in their own words.

> **Tip: Keep ids stable**
>
> Use stable kebab-case ids, never generated ones, and pass a dependency array to every hook so snapshots and handlers
> follow the page's data. `useSommaticSelection` and `useSommaticFocus` publish the current selection and the entity in
> focus the same way.

## Common problems

- **"No LLM Provider ID provided for inference."** The person has not picked a provider in the panel yet.
- **Surfaces lose their handlers between renders.** The provider is mounted twice; keep a single one.
- **Read commands describe the wrong source.** Publish a source with the id `page-context` on every page.

## Next steps

- [Command reference](https://docs.sommatic.ai/en/command-center/commands.md): Arguments and results of every command your pages can receive.
- [React hooks](https://docs.sommatic.ai/en/sdks/react/hooks.md): The registration hooks and the rest of the SDK's hooks.
