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 OperationA long-running piece of work. T is what wait() resolves to.
- Like every live object, it also has hydrate(), refresh() and raw.
| id | string | |
| kind | string | |
| status | OperationStatus | |
| step | OperationStep | null | Where a running operation is: an agent turn on a CLI harness |
| result | unknown | The raw result once succeeded. |
| createdAt | Date | null | |
| updatedAt | Date | null | |
| summaryText | string | null | A short line saying what it is (a message preview, an addressee, a command). |
| userId | string | null | |
| keyId | string | null | The key that started it. |
| agentId | string | null | |
| input | JsonObject | null | What it was started with (on a single operation's view, for account principals). |
| startedAt | Date | null | |
| finishedAt | Date | null | |
| waitMs | number | null | Time queued before it ran. |
| runMs | number | null | Time running. |
| heldMs | number | null | Time waiting on a person. |
| progress | OperationProgress | null | What the work reported as it went (null before it reported anything). An agent that started it hears each
report as an |
| undoable | boolean | null | Whether |
| undoneAt | Date | null | When it was undone, if it was. |
| transitions | OperationTransition[] | Every status change, oldest first (empty for operations recorded before they were kept). |
| consoleUrl | string | null | This operation in the developer console (null off the hosted API). |
| error | NoClickError | null | The failure as a |
| done | boolean | Whether the operation reached a terminal status. |
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
/** Where a running operation is: an agent turn's `TurnStep`, or a port's `PortStep`. */
type OperationStep = TurnStep | PortStep;
/**
* Where a running turn of an agent on a CLI harness is: `delivering` (starting its sandbox and
* handing it the message) or `working` (the harness is on it).
*/
type TurnStep = "delivering" | "working";
/**
* Invite-only beta. Where a number's port (`phone.port_in`) is: `submitted` (with the
* current carrier) or `scheduled` (it moves at `portAt`).
*/
type PortStep = "submitted" | "scheduled";
type JsonObject = { [key: string]: unknown };
/**
* What an operation's work reported as it went: its `step`, its `stages`, the last 50 `lines` it printed (a build's
* log, a call's turns, an agent's tool calls), `lineCount` (every line so far) and when it last said something.
*/
interface OperationProgress {
step: string | null;
stages: OperationStage[];
lines: string[];
lineCount: number;
updatedAt: Date | null;
raw: JsonObject;
}
/** One stage of what an operation's work planned (a deploy's: Queued, Building, Shipping, Live). */
interface OperationStage {
name: string;
status: "done" | "current" | "pending";
startedAt: Date | null;
endedAt: Date | null;
}liststatic
static list(
options?: OperationFilters & { limit?: number },
): Promise<Operation[]>Operations matching the filters, newest first (or the first limit).
Statuses, or "live" for every non-terminal one.
An Agent or agent id.
The requesting key: its id or its prefix (nk_live_ab12).
Rows changed since (for polling).
Return at most this many.
Which users the read covers (user_id query), instead of acting as one (user).
undefined = the ambient user (asUser), null = the account itself.
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
Every matching operation, fetched page by page.
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
/**
* Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
* `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
*/
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;
/** Anything that can name a user lazily (a `User`). */
interface UserLike {
_userId(): Promise<string>;
}
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;listPagestatic
static listPage(
options?: OperationFilters & PageOptions,
): Promise<Page<Operation>>One page of matching operations; pass nextCursor back as cursor.
The next_cursor of the page before; omit it for the first page.
Return at most this many.
Statuses, or "live" for every non-terminal one.
An Agent or agent id.
The requesting key: its id or its prefix (nk_live_ab12).
Rows changed since (for polling).
Which users the read covers (user_id query), instead of acting as one (user).
undefined = the ambient user (asUser), null = the account itself.
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
A page whose data holds the operations and whose next_cursor is None on the last page.
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
/**
* Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
* `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
*/
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;
/** Anything that can name a user lazily (a `User`). */
interface UserLike {
_userId(): Promise<string>;
}
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;summarystatic
static summary(options?: OperationFilters): Promise<OperationSummary>How many operations match, by status.
Statuses, or "live" for every non-terminal one.
An Agent or agent id.
The requesting key: its id or its prefix (nk_live_ab12).
Rows changed since (for polling).
Which users the read covers (user_id query), instead of acting as one (user).
undefined = the ambient user (asUser), null = the account itself.
The client to send with; defaults to the module client built from NOCLICK_API_KEY.
The total, and in by_status a count for every status, zeros included.
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
/**
* Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
* `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
*/
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;
/** Anything that can name a user lazily (a `User`). */
interface UserLike {
_userId(): Promise<string>;
}
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;fromIdstatic
static fromId(operationId: string, options?: CallOptions): Operation<T>A lazy reference to an operation by id.
An operation that loads the first time you read a field. Nothing is sent yet.
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;
/** Anything that can name a user lazily (a `User`). */
interface UserLike {
_userId(): Promise<string>;
}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.
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).
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.
1000The 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. A coding agent's turn (agent.message on a coding
harness) stops in its sandbox first, its harness going on from the same session, so the next turn never runs
beside it.
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.
What the undo put back, as its own API shows it (a restore of a database is an operation of its own).
type JsonObject = { [key: string]: unknown };OperationEvent
interface OperationEventA 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).
| status | OperationStatus | |
| step | OperationStep | null | Where a running operation is ( |
| updatedAt | Date | null | |
| result | unknown | |
| error | NoClickError | null | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
/** Where a running operation is: an agent turn's `TurnStep`, or a port's `PortStep`. */
type OperationStep = TurnStep | PortStep;
/**
* Where a running turn of an agent on a CLI harness is: `delivering` (starting its sandbox and
* handing it the message) or `working` (the harness is on it).
*/
type TurnStep = "delivering" | "working";
/**
* Invite-only beta. Where a number's port (`phone.port_in`) is: `submitted` (with the
* current carrier) or `scheduled` (it moves at `portAt`).
*/
type PortStep = "submitted" | "scheduled";
type JsonObject = { [key: string]: unknown };OperationSummary
interface OperationSummaryHow many operations match, by status.
| total | number | |
| byStatus | Record<OperationStatus, number> | |
| raw | JsonObject | The response JSON exactly as the API sent it. |
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";
type JsonObject = { [key: string]: unknown };OperationTransition
interface OperationTransitionOne status change the server recorded (by names who canceled).
| status | OperationStatus | |
| at | Date | null | |
| by | string | null |
type OperationStatus =
| "queued" | "running" | "awaiting_human"
| "succeeded" | "failed" | "canceled" | "expired";