Skip to content

Class: WorkflowsClient

@kortexya/reasoninglayer


@kortexya/reasoninglayer / WorkflowsClient

Defined in: src/resources/workflows.ts:96

Workflows: a start step and a map of steps joined by next (a condition branches with then/else), each step calling an engine capability with {{input.<name>}} and {{steps.<id>.…}} placeholders.

The engine checks a definition when it is written (every edge names a step, the start exists, every step is reachable, a placeholder reads a declared input or a step that runs before it) and bumps the version on each replace. A run follows the version it started on, step by step, as the principal who started it; an approval step waits for a decision in the action-review queue, a wait step parks the run, and the tenant’s emergency stop parks it before its next step. With a database, definitions and runs are rows every engine serves, and a run whose engine stopped is taken over by another.

cancelRun(runId, requestOptions?): Promise<WorkflowRun>

Defined in: src/resources/workflows.ts:475

Cancel a run that is running or waiting. A running run stops before its next step; a waiting one is never resumed.

string

The run’s id.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<WorkflowRun>

The run, cancelled.

NotFoundError 404 when the tenant has no run with that id.

ApiError 409 when the run already settled.

POST /api/v1/workflow-runs/{run_id}/cancel.


capture(id, request, requestOptions?): Promise<WorkflowCaptureResponse>

Defined in: src/resources/workflows.ts:158

Persist source-save and processing intent on one native durable run.

string

Private procedure id.

WorkflowCaptureRequest

Reviewed version, stable event id, source identity and bindings.

RequestOptions

Per-call options; retries retain the supplied event id.

Promise<WorkflowCaptureResponse>

A receipt distinguishing source persistence from processing status.

ApiError 409 for changed versions/inputs, 503 without persistence.

POST /api/v1/workflows/{id}/capture; source features use tagged values. Envelope keys map to snake_case; feature names and nested inputs retain their case.

`await client.workflows.capture(id, { eventId, expectedVersion: 1, source });`

completeBrowserRead(runId, request, requestOptions?): Promise<WorkflowRun>

Defined in: src/resources/workflows.ts:450

Commit the selected browser’s actual observation and resume the native graph once.

string

Run that waits for this command and session.

CompleteBrowserReadRequest

Stable command/session ids and bounded literal page data.

RequestOptions

Per-call options; automatic retries are disabled.

Promise<WorkflowRun>

The native receipt, whose graph may still be running.

NotFoundError 404 for another principal or tenant.

ApiError 409 for a changed command, session or authority, 422 for wrong origins or unbounded data.

POST /api/v1/workflow-runs/{run_id}/browser-read; scalar keys use snake_case on the wire. An identical acknowledged observation is idempotent; inspect the native run after a lost response.

`await client.workflows.completeBrowserRead(runId, { commandId, sessionId, url, title, content });`

create(definition, requestOptions?): Promise<Workflow>

Defined in: src/resources/workflows.ts:220

Create a workflow.

WorkflowRequest

Its name, inputs, start and steps.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<Workflow>

The workflow, version 1.

ApiError 409 when this owner has a private procedure of that name.

ApiError 422 for a definition a run could not follow, with the reason.

POST /api/v1/workflows.

const watch = await client.workflows.create({
name: 'pump-watch',
inputs: ['site'],
start: 'find',
steps: {
find: { kind: 'query', rlql: 'MATCH pump(site: {{input.site}}, status: "stopped", name: ?N);', next: 'any' },
any: { kind: 'condition', left: '{{steps.find.count}}', op: 'gt', right: 0, then: 'tell' },
tell: { kind: 'send_message', adapter: 'ops', channelId: 'C-1', content: '{{steps.find.count}} pumps stopped' },
},
});

delete(id, requestOptions?): Promise<void>

Defined in: src/resources/workflows.ts:291

Delete a workflow. Runs in flight finish on their own copy.

string

The workflow’s id.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<void>

NotFoundError 404 when the tenant has no workflow with that id.

DELETE /api/v1/workflows/{id}.


draft(request, requestOptions?): Promise<DraftWorkflowResponse>

Defined in: src/resources/workflows.ts:115

Draft a native procedure through the configured model without executing it.

DraftWorkflowRequest

Original goal, exact inputs, untrusted observations and explicit caller answers.

RequestOptions

Per-call timeout, headers and cancellation.

Promise<DraftWorkflowResponse>

A validated graph to review, or clarification questions.

ApiError 503 when no model is configured, 422 after invalid generation.

POST /api/v1/workflows/draft; opaque JSON keys retain their case. Caller answers use clarifications; source observations remain in context.

`await client.workflows.draft({ description: 'Check the saved source', inputs: { source: {} } });`

enableTrigger(triggerId, requestOptions?): Promise<EnabledWorkflowTrigger>

Defined in: src/resources/workflows.ts:489

Arm a trigger for the task template version its owner reviewed.

string

The trigger.

RequestOptions

Per-call cancellation, timeout and request options.

Promise<EnabledWorkflowTrigger>

The trigger as enabling left it: the version it runs and what an edit must not change.

404 when the caller has no such trigger; 409 when the task template changed since the pinned version; 422 when a condition, an input binding or the template does not fit a triggered run.

Uses POST /api/v1/workflow-triggers/{id}/enable.

const trigger = await client.workflows.enableTrigger(triggerId);

get(id, requestOptions?): Promise<Workflow>

Defined in: src/resources/workflows.ts:251

Read a workflow.

string

The workflow’s id.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<Workflow>

The workflow at its current version.

NotFoundError 404 when the tenant has no workflow with that id.

GET /api/v1/workflows/{id}.


getBrowserRead(runId, requestOptions?): Promise<BrowserReadCommand>

Defined in: src/resources/workflows.ts:431

Read the pending command for the run’s explicitly selected browser session.

string

Private native run waiting at a browser-read step.

RequestOptions

Per-call timeout, headers and cancellation.

Promise<BrowserReadCommand>

The persisted command identity, selected session and exact origin.

NotFoundError 404 for a run of another principal or tenant.

ApiError 409 when not waiting or current authority changed.

GET /api/v1/workflow-runs/{run_id}/browser-read; snake_case fields are mapped to camelCase. Reading a command does not perform a page action.

`const command = await client.workflows.getBrowserRead(runId);`

getRun(runId, requestOptions?): Promise<WorkflowRun>

Defined in: src/resources/workflows.ts:416

Read a run: its status, the context of inputs and step outputs, its log.

string

The run’s id.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<WorkflowRun>

The run.

NotFoundError 404 when the tenant has no run with that id.

GET /api/v1/workflow-runs/{run_id}.


getRunDefinition(runId, requestOptions?): Promise<Workflow>

Defined in: src/resources/workflows.ts:383

Read the exact private graph snapshot retained by a native run.

string

The private run’s identity.

RequestOptions

Per-call namespace, timeout, signal and causal options.

Promise<Workflow>

The executed graph, even when it was never saved as a procedure.

409 when the initiating principal’s authority changed.

GET /api/v1/workflow-runs/{run_id}/definition. Snake_case envelope fields map to camelCase while step identities and nested request data retain their case.

`const definition = await client.workflows.getRunDefinition(runId);`

list(requestOptions?): Promise<WorkflowListResponse>

Defined in: src/resources/workflows.ts:236

List this owner’s private procedures in the selected tenant, by name.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<WorkflowListResponse>

The native envelope containing the workflows.

GET /api/v1/workflows.


listRecentRuns(requestOptions?): Promise<WorkflowRun[]>

Defined in: src/resources/workflows.ts:367

List the current principal’s latest 100 private runs in the same authority scope.

RequestOptions

Per-call namespace, timeout, signal and causal options.

Promise<WorkflowRun[]>

Recent native receipts, including unsaved one-off graphs.

When a native receipt is malformed.

GET /api/v1/workflow-runs. Snake_case receipt fields map to camelCase; context data keeps its original keys. Does not inherit another actor’s outputs.

`const runs = await client.workflows.listRecentRuns();`

listRuns(id, requestOptions?): Promise<WorkflowRunListResponse>

Defined in: src/resources/workflows.ts:401

List a workflow’s runs, newest first.

string

The workflow’s id.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<WorkflowRunListResponse>

The native envelope containing the runs.

NotFoundError 404 when the tenant has no workflow with that id.

GET /api/v1/workflows/{id}/runs.


rehearse(request, requestOptions?): Promise<RehearseWorkflowResponse>

Defined in: src/resources/workflows.ts:136

Rehearse real reads and branch decisions, stopping before the first effect.

RehearseWorkflowRequest

The graph and explicitly bound inputs.

RequestOptions

Per-call options.

Promise<RehearseWorkflowResponse>

Read outputs, selected branches and the unexecuted next effect.

ApiError 422 for an invalid graph or missing inputs.

POST /api/v1/workflows/rehearse; camelCase envelope keys map to snake_case, while graph identities and nested input/effect data retain their case. No durable run or write is created.

`await client.workflows.rehearse({ definition, inputs: { source } });`

replace(id, definition, requestOptions?): Promise<Workflow>

Defined in: src/resources/workflows.ts:269

Replace a workflow’s definition; its version goes up by one.

string

The workflow’s id.

WorkflowRequest

The new definition.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<Workflow>

The workflow at its new version.

NotFoundError 404 when the tenant has no workflow with that id.

ApiError 409 when another of the tenant’s workflows has that name.

ApiError 422 for a definition a run could not follow.

PUT /api/v1/workflows/{id}. Runs in flight keep the version they started on.


replanRun(runId, request?, requestOptions?): Promise<ReplanWorkflowResponse>

Defined in: src/resources/workflows.ts:182

Continue a failed goal with a revised remaining native plan.

string

Failed run of this principal.

ReplanWorkflowRequest = {}

New observations and explicit caller answers within the original goal and effects.

RequestOptions

Per-call options.

Promise<ReplanWorkflowResponse>

A continuation with persisted provenance, or clarification questions.

ApiError 409 for changed authority, settled state or exhausted budget.

POST /api/v1/workflow-runs/{run_id}/replan; repeated calls reuse one child run. Caller answers are serialized at the root; observations remain opaque untrusted JSON with unchanged keys.

`await client.workflows.replanRun(runId, { observations: 'The source was updated.' });`

runOnce(request, requestOptions?): Promise<WorkflowRun>

Defined in: src/resources/workflows.ts:343

Execute a reviewed personal graph once on the native durable runner.

RunWorkflowOnceRequest

The graph, inputs, stable event UUID and reviewing account UUID.

RequestOptions

Per-call namespace, timeout, signal and causal options.

Promise<WorkflowRun>

The private native receipt. No reusable procedure is registered.

When the event or reviewing account is not a UUID.

409 for a changed account, authority, graph or input under the same event.

POST /api/v1/workflow-runs. Performs one HTTP attempt; retain the event across an unknown response and explicitly inspect or retry its original intent. Envelope keys map to snake_case while graph identities and nested inputs retain their case.

`await client.workflows.runOnce({ definition, eventId, expectedOwnerId, inputs });`

saveAndFireTriggers(request, requestOptions?): Promise<WorkflowTriggerSaveResponse>

Defined in: src/resources/workflows.ts:510

Save a source and fire the triggers that watch where it is saved.

WorkflowTriggerSaveRequest

The save: its event id, kind, where it is saved and the source term.

RequestOptions

Per-call cancellation, timeout and request options.

Promise<WorkflowTriggerSaveResponse>

The saved source and each matching trigger’s firing.

409 when the event id already names a different save; 422 for an invalid save; 503 when persistent storage is unavailable.

Uses POST /api/v1/workflow-triggers/saves (202). Retrying with the same eventId fires nothing twice.

await client.workflows.saveAndFireTriggers({ eventId, kind: 'on_save', projectId, source });

startRun(id, request?, requestOptions?): Promise<WorkflowRun>

Defined in: src/resources/workflows.ts:313

Start a run of a workflow.

string

The workflow’s id.

StartWorkflowRunRequest = {}

A value for each declared input; wait: true answers once the run settled or waits (an approval, a wait step, the emergency stop), up to two minutes.

RequestOptions

Per-call options (timeout, retries, signal, headers).

Promise<WorkflowRun>

The run.

NotFoundError 404 when the tenant has no workflow with that id.

ApiError 422 when an input is missing or not declared.

POST /api/v1/workflows/{id}/runs. Envelope keys map to snake_case; nested input keys and explicit null event/version fields are preserved. The run acts as the caller. A null or absent event id disables automatic retries.

`await client.workflows.startRun(id, { expectedVersion: 3, eventId, inputs });`