Operation

Operations: work that outlives a request (a human's answer, a connect link, an agent turn). op.wait() returns the typed outcome for its kind.

class Operation

A long-running piece of work. T is what wait() resolves to.

Attributes
idstring
kindstring
statusOperationStatus
stepOperationStep | null

Where a running operation is: an agent turn on a CLI harness delivering, then working; a number's port submitted, then scheduled. Null otherwise.

resultunknown

The raw result once succeeded.

createdAtDate | null
updatedAtDate | null
summaryTextstring | null

A short line saying what it is (a message preview, an addressee, a command).

userIdstring | null
keyIdstring | null

The key that started it.

agentIdstring | null
inputJsonObject | null

What it was started with (on a single operation's view, for account principals).

startedAtDate | null
finishedAtDate | null
waitMsnumber | null

Time queued before it ran.

runMsnumber | null

Time running.

heldMsnumber | null

Time waiting on a person.

progressOperationProgress | null

What the work reported as it went (null before it reported anything). An agent that started it hears each report as an operation event.

undoableboolean | null

Whether undo() can take it back now: a reversible write (a deletion that went to the trash, a dict's clear, a database migration) not undone yet. null for kinds that record no undo.

undoneAtDate | null

When it was undone, if it was.

transitionsOperationTransition[]

Every status change, oldest first (empty for operations recorded before they were kept).

consoleUrlstring | null

This operation in the developer console (null off the hosted API).

errorNoClickError | null

The failure as a NoClickError (null unless it failed).

doneboolean

Whether the operation reached a terminal status.

liststatic

static list(
  options?: OperationFilters & { limit?: number },
): Promise<Operation[]>

Operations matching the filters, newest first (or the first limit).

Parameters
options.kindstring | readonly string[]
options.statusOperationStatus | "live" | readonly (OperationStatus | "live")[]

Statuses, or "live" for every non-terminal one.

options.statusNotOperationStatus | readonly OperationStatus[]
options.agentstring | ApiObject

An Agent or agent id.

options.keystring

The requesting key: its id or its prefix (nk_live_ab12).

options.createdAfterDate | string
options.createdBeforeDate | string
options.updatedAfterDate | string

Rows changed since (for polling).

options.limitnumber

Return at most this many.

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

Every matching operation, fetched page by page.

listPagestatic

static listPage(
  options?: OperationFilters & PageOptions,
): Promise<Page<Operation>>

One page of matching operations; pass nextCursor back as cursor.

Parameters
options.cursorstring | null

The next_cursor of the page before; omit it for the first page.

options.limitnumber

Return at most this many.

options.kindstring | readonly string[]
options.statusOperationStatus | "live" | readonly (OperationStatus | "live")[]

Statuses, or "live" for every non-terminal one.

options.statusNotOperationStatus | readonly OperationStatus[]
options.agentstring | ApiObject

An Agent or agent id.

options.keystring

The requesting key: its id or its prefix (nk_live_ab12).

options.createdAfterDate | string
options.createdBeforeDate | string
options.updatedAfterDate | string

Rows changed since (for polling).

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

A page whose data holds the operations and whose next_cursor is None on the last page.

summarystatic

static summary(options?: OperationFilters): Promise<OperationSummary>

How many operations match, by status.

Parameters
options.kindstring | readonly string[]
options.statusOperationStatus | "live" | readonly (OperationStatus | "live")[]

Statuses, or "live" for every non-terminal one.

options.statusNotOperationStatus | readonly OperationStatus[]
options.agentstring | ApiObject

An Agent or agent id.

options.keystring

The requesting key: its id or its prefix (nk_live_ab12).

options.createdAfterDate | string
options.createdBeforeDate | string
options.updatedAfterDate | string

Rows changed since (for polling).

options.userFilterUserFilter

Which users the read covers (user_id query), instead of acting as one (user).

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

Returns

The total, and in by_status a count for every status, zeros included.

fromIdstatic

static fromId(operationId: string, options?: CallOptions): Operation<T>

A lazy reference to an operation by id.

Parameters
operationIdstringrequired
options.clientNoClick

The client to send with; defaults to the module client built from NOCLICK_API_KEY.

options.userUserOption

undefined = the ambient user (asUser), null = the account itself.

(defaults to the current user)
Returns

An operation that loads the first time you read a field. Nothing is sent yet.

wait

wait(options?: { timeoutS?: number }): Promise<T>

Wait until the operation finishes and return its outcome (typed per kind: Connection, Answer, boolean, AgentReply, ...). Throws the operation's error if it failed, OperationCanceled / Expired, or OperationTimeout after timeoutS seconds.

Parameters
options.timeoutSnumber
Returns

The outcome, typed for the operation's kind: an AgentReply from agent.send, True or False from human.approve, the connected Connection from a connect link. A kind the client has no type for gives the raw result.

toolCalls

toolCalls(): Promise<ToolCall[]>

The tool calls an agent.message turn made, oldest first (none for other kinds).

Returns

Each call's tool, arguments, status, duration and a preview of its result.

events

async *events(options?: { intervalMs?: number }): AsyncGenerator<OperationEvent>

Yield an event for each status or step change until the operation finishes.

Parameters
options.intervalMsnumberdefault 1000
Returns

The changes, polled every interval seconds: first the status (and step) it has now, last its final one. An event's result is the raw result, not the typed outcome wait() returns.

cancel

cancel(): Promise<this>

Ask the server to cancel; returns the updated operation.

Returns

This operation, now canceled.

undo

undo(): Promise<JsonObject>

Take back a reversible write, once: a deletion comes out of the trash, a dict's cleared keys come back, a migrated database is restored to the moment before. What reached the world (an email sent, a payment) has no undo: that throws Conflict, as does undoing twice. Returns what the undo put back, as its own API shows it.

Returns

What the undo put back, as its own API shows it (a restore of a database is an operation of its own).

OperationEvent

interface OperationEvent

A status or step change observed by Operation.events(): step is where a running operation is (delivering or working for a CLI agent's turn, submitted or scheduled for a port; None otherwise).

Attributes
statusOperationStatus
stepOperationStep | null

Where a running operation is (delivering or working for a CLI agent's turn, submitted or scheduled for a port); null otherwise.

updatedAtDate | null
resultunknown
errorNoClickError | null
rawJsonObject

The response JSON exactly as the API sent it.

OperationSummary

interface OperationSummary

How many operations match, by status.

Attributes
totalnumber
byStatusRecord<OperationStatus, number>
rawJsonObject

The response JSON exactly as the API sent it.

OperationTransition

interface OperationTransition

One status change the server recorded (by names who canceled).

Attributes
statusOperationStatus
atDate | null
bystring | null