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.
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. |
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.
Services by area
Each service maps to one group of the API reference.
| 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).
Collection helpers
The helpers take a service class and do the instantiation for you, returning null instead of throwing:
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. |
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.