# Services

> Service classes of the React SDK - one per API resource, all built on BaseApi - and the stream classes that follow runs and task assignments over server-sent events.

Source: https://docs.sommatic.ai/en/sdks/react/services/ (updated 2026-11-26)

A service is a small class that knows the path of one API resource. You create it, call a method, and get back the
API's envelope. Services are cheap: create one where you need it instead of sharing a global instance.

## The methods every service has

All services extend `BaseApi`:

| Method                    | Request                            | Use                                                                           |
| ------------------------- | ---------------------------------- | ----------------------------------------------------------------------------- |
| `getByParameters(params)` | `GET <resource>/<queryselector>?…` | Reads. `params.queryselector` is required; the rest goes to the query string. |
| `create(payload)`         | `POST <resource>/`                 | Creates a record from the JSON body.                                          |
| `update(payload)`         | `PATCH <resource>/`                | Updates the record whose `id` is in the body.                                 |
| `delete(payload)`         | `DELETE <resource>/`               | Deletes the record whose `id` is in the body.                                 |

```javascript
import { WorkflowOrchestrationFlowDefinitionService } from '@sommatic/react-sdk';

const definitions = new WorkflowOrchestrationFlowDefinitionService({ apiKey: token });

const page = await definitions.getByParameters({
  queryselector: 'organization-id',
  search: organizationId,
  exclude_status: 'deleted',
  page: 1,
  pageSize: 25,
});

await definitions.update({ id: 'wf-flow-definition-…', description: 'Routes inbound requests' });
```

Read selectors, pagination and the response envelope are the same as in the API: see
[Conventions](https://docs.sommatic.ai/en/api/conventions.md).

## Services by area

Each service maps to one group of the [API reference](https://docs.sommatic.ai/en/api/reference/triggers.md).

| Area                     | Services                                                                                                                                                                                                                                                                                                                                                                                       | Extra methods                                                                              |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Workflow design          | `WorkflowOrchestrationFlowDefinitionService`, `WorkflowOrchestrationFlowVersionService`, `WorkflowOrchestrationTriggerService`, `WorkflowOrchestrationOperatorService`, `WorkflowOrchestrationDeploymentService`                                                                                                                                                                               | `publish({ id })` on flow definitions                                                      |
| Triggers                 | `WorkflowOrchestrationIngressBindingService`                                                                                                                                                                                                                                                                                                                                                   |                                                                                            |
| Execution                | `WorkflowOrchestrationExecutionService`, `WorkflowOrchestrationFlowInstanceService`, `WorkflowOrchestrationFlowInstanceResultService`, `WorkflowOrchestrationNodeExecutionService`                                                                                                                                                                                                             | `executeWorkflow(payload)`                                                                 |
| Cognitive infrastructure | `CognitiveInfrastructureLLMProviderService`, `CognitiveInfrastructurePromptTemplateService`, `CognitiveInfrastructureKnowledgeResourceService`, `CognitiveInfrastructureKnowledgeResourceBindingService`, `CognitiveInfrastructureAgentProfileService`, `CognitiveInfrastructureCognitiveToolService`, `CognitiveInfrastructureMemoryStoreService`, `CognitiveInfrastructureDatasourceService` | `publish({ id })` on knowledge resources                                                   |
| Human in the loop        | `WorkManagementTaskService`                                                                                                                                                                                                                                                                                                                                                                    | `transition({ id, transition_name, payload })`                                             |
| Projects                 | `ProjectManagementService`                                                                                                                                                                                                                                                                                                                                                                     |                                                                                            |
| Credentials              | `PlatformInfrastructureCredentialService`                                                                                                                                                                                                                                                                                                                                                      |                                                                                            |
| Git Sync                 | `PlatformInfrastructureGitRepositoryService`, `PlatformInfrastructureGitSyncService`                                                                                                                                                                                                                                                                                                           | `test`, `tree`, `package` on repositories; `preview`, `apply`, `export`, `setLink` on sync |
| Conversations            | `ConversationExecutionService`                                                                                                                                                                                                                                                                                                                                                                 | `execute(envelope)`, `executeStream(envelope, callbacks)`                                  |

Every service is exported by name and also through the `services` map, so `services.WorkManagementTaskService` and
the named import are the same class. Shorter aliases exist for a few of them (`LlmProviderService`,
`WorkflowFlowDefinitionService`, `WorkflowFlowVersionService`, `WorkflowTriggerService`, `WorkflowOperatorService`).

> **Note: Only the public surface is documented**
>
> The package also exports services that the Sommatic AI portal uses internally. They are not part of the public API and
> can change without notice; build on the services listed here.

## Collection helpers

The helpers take a service class and do the instantiation for you, returning `null` instead of throwing:

```javascript
import { fetchEntityCollection, fetchMultipleEntities, ProjectManagementService } from '@sommatic/react-sdk';

const projects = await fetchEntityCollection({
  service: ProjectManagementService,
  payload: { queryselector: 'organization-id', search: organizationId, page: 1, pageSize: 10 },
  apiKey: token,
});
```

`fetchEntityCollection` defaults to `queryselector: 'all'`, `exclude_status: 'deleted'`, `page: 1` and `pageSize: 10`.
`fetchMultipleEntities([...])` runs several of those requests in parallel and returns the answers in order.
`createEntityRecord`, `updateEntityRecord` and `deleteEntityRecord` wrap the write methods the same way.

## Streams

Two classes follow server-sent events with the browser's `EventSource` and reconnect on their own (every 3 seconds by
default):

| Class                                         | Stream                                                                          |
| --------------------------------------------- | ------------------------------------------------------------------------------- |
| `WorkflowOrchestrationExecutionStreamService` | `GET /workflow-orchestration/execution/stream`: progress of runs, node by node. |
| `WorkManagementTaskStreamService`             | `GET /work-management/task/stream`: task events for a person.                   |

```javascript
import { WorkManagementTaskStreamService } from '@sommatic/react-sdk';

const stream = new WorkManagementTaskStreamService();
stream.setParams({ user_identity: userIdentity });
stream.on('task-assigned', (data) => console.log(data.task));
stream.connect();

// later
stream.disconnect();
```

`on(event, callback)` parses each message as JSON and supports several listeners for the same event; `off(event)`
removes them. Both classes extend `BaseStream`.

## Next steps

- [Conventions](https://docs.sommatic.ai/en/api/conventions.md): Query selectors, pagination and the envelope.
- [Hooks](https://docs.sommatic.ai/en/sdks/react/hooks.md): Hooks that use these services and streams for you.
