Run Functions
Use this adapter to manage runs.
Importing the adapter
import { runAdapter } from 'epicenter-libs';
The runAdapter namespace exports functions that make calls to the Run API.
For descriptions of the objects used by the Run adapter functions, read Run Entities.
Create
Create run
Call the create() function to create a run.
By default, all runs are created with the user's ID (userKey), except in the case of world-scoped runs.
If no permit is specified, the platform assigns a default determined by the session user's role and the scope boundary. For a participant creating a run, the default readLock/writeLock is USER/USER, unless that run is scoped to a world, in which case PARTICIPANT/FACILITATOR is the default. Admins and facilitators/reviewers have their own defaults.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
POSTrequest to the/runendpoint. - Creates a new run using the provided
modelandscopeparameters. - Automatically assigns
userKeyfrom the current session unless the run is world-scoped. - Optionally includes execution context, model context, permissions, and routing options.
- Returns a
RunReadOutViewrepresenting the newly created run.
export async function create<
V extends object = RunVariables,
M extends object = RunMetadata,
>(
model: string,
scope: { userKey?: string } & GenericScope,
optionals: RunCreateOptions = {},
): Promise<RunReadOutView<V, M>>
Parameters
model: string- The name of your model file.scope: { userKey?: string } & GenericScope- Defines the scope of the run. Can consist ofGenericScopeplus auserKeyfor user specific scope.optionals: RunCreateOptions = {}- (Optional) Additional run creation options.readLock?: keyof typeof ROLE- (Optional) Read lock level. Part of the permit for the run.writeLock?: keyof typeof ROLE- (Optional) Write lock level. Part of the permit for the run.ephemeral?: boolean- (Optional) Iftrue, the run will only exist so long as it is in memory. Nothing is written to the database, history, or variables.trackingKey?: string- (Optional) A string that you can assign to a run as a marker. You can perform a search for runs that have a specifictrackingKey.modelContext?: ModelContext- (Optional) Model context file overrides. Not tracked by clone operations.executionContext?: ExecutionContext- (Optional) Carries arguments for model file worker on model initialization. This is tracked by clone operations.allowChannel?: boolean- (Optional) Opt into push notifications. Applicable to projects with phylogeny >= SILENT.RoutingOptions- Additional routing options for request handling.
Return value
A promise resolving to a RunReadOutView object containing details of the newly created run.
Usage example
import { runAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
await runAdapter.create('model.py', {
scopeBoundary: SCOPE_BOUNDARY.GROUP,
scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461'
});
Clone run
Call the clone() function to create a copy of an existing run.
A cloned run starts with the same state as the source run. You can optionally provide new context overrides and tracking information for the cloned run.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
POSTrequest to the/run/clone/{RUN_KEY}endpoint. - Clones the run identified by
runKey. - Optionally includes execution context, model context, a tracking key, and routing options.
- Returns a
RunReadOutViewobject representing the cloned run.
export async function clone(
runKey: string,
optionals: {
ephemeral?: boolean;
trackingKey?: string;
modelContext?: ModelContext;
executionContext?: ExecutionContext;
} & RoutingOptions = {},
): Promise<RunReadOutView>
Parameters
runKey: string- Run key for the run you want to clone.optionals(Type:{ ephemeral?: boolean; trackingKey?: string; modelContext?: ModelContext; executionContext?: ExecutionContext } & RoutingOptions) - (Optional) Additional clone options.ephemeral?: boolean- (Optional) Iftrue, the run will only exist so long as it is in memory. Nothing is written to the database, history, or variables.trackingKey?: string- (Optional) A string that you can assign to the cloned run as a marker. You can perform a search for runs that have a specific trackingKey.modelContext?: ModelContext- (Optional) Model context file overrides. Not tracked by clone operations.executionContext?: ExecutionContext- (Optional) Carries arguments for model file worker on model initialization. This is tracked by clone operations.RoutingOptions- Additional routing options for request handling.
Return value
A promise resolving to a RunReadOutView object containing details of the cloned run.
Usage example
import { runAdapter } from 'epicenter-libs';
const clonedRun = await runAdapter.clone('00000173078afb05b4ae4c726637167a1a9e');
Retrieve
Use these methods to query the Epicenter API for runs.
Retrieve run
The get() function retrieves a run by the run key.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
GETrequest to the/run/{RUN_KEY}endpoint. - Retrieves the run identified by the provided run key.
- Returns a
RunReadOutViewobject containing the run’s details.
export async function get<
V extends object = RunVariables,
M extends object = RunMetadata,
>(
runKey: string,
optionals: RoutingOptions = {}
): Promise<RunReadOutView<V, M>>
Parameters
runKey(string) – The unique key identifying the run to retrieve.optionals(Type:RoutingOptions = {}) – Additional routing options.
Return value
A promise that resolves to a RunReadOutView<V, M> object representing the requested run.
Usage example
import { runAdapter } from 'epicenter-libs';
const run = await runAdapter.get('00000173078afb05b4ae4c726637167a1a9e');
Start run for world
The retrieveFromWorld() function returns the run associated with the given world key. If the world's run key is null, the function creates a new run and assigns the new run key to the world.
The run gets started and loaded into memory.
Permissions
Requires a role of PARTICIPANT or higher.
Function description
- Constructs a
POSTrequest to the endpoint/run/world/{WORLD_KEY} - Initiates a run using a provided model file and optional execution/model context.
- Optionally applies permission locks, ephemeral state, and notification support.
- Returns the retrieved or newly created run as a
RunReadOutViewobject.
export async function retrieveFromWorld(
worldKey: string,
model: string,
optionals: {
readLock?: keyof typeof ROLE;
writeLock?: keyof typeof ROLE;
ephemeral?: boolean;
trackingKey?: string;
modelContext?: ModelContext;
executionContext?: ExecutionContext;
allowChannel?: boolean;
} & RoutingOptions = {},
): Promise<RunReadOutView>
Parameters
worldKey(string) – The key identifying the world to retrieve the run for.model(string) – Model file name to use when creating the run if it does not already exist.optionals:readLock?: keyof typeof ROLE- (Optional) Read lock level. Part of the permit for the run.writeLock?: keyof typeof ROLE- (Optional) Write lock level. Part of the permit for the run.ephemeral?: boolean- (Optional) Iftrue, the run will only exist so long as its in memory. Nothing is written to the database, history, or variables.trackingKey?: string- (Optional) A string that you can assign to a run as a marker. You can perform a search for runs that have a specifictrackingKey.modelContext?: ModelContext- (Optional) Model context file overrides. Not tracked by clone operations.executionContext?: ExecutionContext- (Optional) Carries arguments for model file worker on model initialization. This is tracked by clone operations.allowChannel?: boolean- (Optional) Opt into push notifications. Applicable to projects with phylogeny >= SILENT.RoutingOptions- Additional routing options for request handling.
Return value
A promise that resolves to a RunReadOutView.
Usage example
import { runAdapter } from 'epicenter-libs';
// Retrieve the run for a world key, or create it if it doesn't exist
const run = await runAdapter.retrieveFromWorld(
'0000017a445032dc38cb2cecd5fc13708314',
'model.py',
);