Human

Humans: ask a person, get an approval, send a notice, request a connection.

class Human

A person to reach. user.human (or new Human(), meaning the user current at each call, or the one a session or user-pinned key acts for) is the user; Human.owner() is your account's owner; new Human({ email }) is anyone else. Every method returns an operation: await req.wait() for the outcome.

via says where a message goes: "auto" (the default), or a list of "web" (only the page: you pass request.url on), "email", and for the owner "whatsapp" and "imessage", sent from NoClick's own numbers to the number they text NoClick from. "auto" is the app the owner last texted NoClick on, else email. "sms" and "call" throw NotAvailable for now. What couldn't be sent is listed in undelivered, never implied.

ownerstatic

static owner(options?: { client?: NoClick }): Human

Your account's owner: the person behind the account, reached by email and on the app they text NoClick from. Only your account reaches them: it always acts as your account, inside asUser too, and a user's session or a key pinned to a user throws PermissionDenied.

await Human.owner().notify("The site is live: https://morrowbakery.com");
Parameters
options.clientNoClick

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

Returns

The owner, to message, ask, put in an agent's tools= or answer_with.

answerWith

answerWith(
  agent: Agent | string | null,
  options?: { conversation?: string },
): Promise<this>

Send what this person texts or says to NoClick's own numbers (its WhatsApp and iMessage numbers and its voice number) to agent (one of your account's). A text's reply goes back on the app they texted on once the agent's turn ends, and texts sent while it's busy go in its next turn, in order; on a call, each thing they say is a turn whose reply is read aloud as it's written. null hands them back to NoClick's assistant. Only Human.owner() reaches NoClick's numbers: your users reach an agent on a number of your own (PhoneNumber.answerWith). conversation is the agent's conversation each text or call lands in, a template over {channel} (whatsapp, imessage or call); omitted, "owner". Give an inbox and a number the same key and the person's email, calls and texts are one conversation.

const assistant = Agent.fromName("assistant");
await Human.owner().answerWith(assistant);
await assistant.message("What's on today?", { conversation: "owner" }); // the same thread
Parameters
agentAgent | string | nullrequired
options.conversationstring
Returns

This person.

answering

answering(): Promise<Agent | null>

The agent this person's texts to NoClick's own numbers go to (answerWith), or null when NoClick's assistant answers them.

Returns

The noclick.Agent, or None.

reach

reach(): Promise<OwnerReach>

NoClick's own numbers the owner texts it on, whether a phone of theirs is linked (never which), and the address they email their assistant at (email, null before it has one). Show a number only once a phone is linked: a text from a phone the account hasn't linked starts an account of its own, and linking one is the owner's, signed in to NoClick. Your account's own key reads it, never a user's.

const { lines, phoneLinked } = await Human.owner().reach();
if (phoneLinked) for (const line of lines) console.log(`${line.app}: ${line.number}`);
Returns

setTimezone

setTimezone(timezone: string): Promise<void>

Where the signed-in owner is, from their browser (an IANA zone such as "Europe/London"): the clock of the account's assistant, and of each of its own agents NoClick placed, moves there; a zone chosen through the API stays. The signed-in owner's alone: a key rejects with PermissionDenied.

await Human.owner().setTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone);
Parameters
timezonestringrequired

claimEmailAddress

claimEmailAddress(): Promise<OwnerEmailAddress | null>

The address the owner emails their assistant at (reach().email), claiming a readable one, from their own address, the first time it's wanted; null where NoClick takes no mail. The signed-in owner's alone: a key rejects with PermissionDenied.

const mail = await Human.owner().claimEmailAddress();
console.log(mail ? `Email your assistant at ${mail.address}` : "No email here");
Returns

renameEmailAddress

renameEmailAddress(name: string): Promise<OwnerEmailAddress>

Renames the address the owner emails their assistant at to name (the part before the

Parameters
namestringrequired
Returns

The noclick.OwnerEmailAddress at its new name.

addEmail

addEmail(email: string): Promise<void>

Send a code to email for the owner of an account made by texting NoClick (which has none); confirmEmail with the code makes it theirs. Throws Conflict when the account already has an email, RateLimited after too many codes.

const owner = Human.owner();
await owner.addEmail("maya@morrowbakery.com");
await owner.confirmEmail(code);
Parameters
emailstringrequired

confirmEmail

confirmEmail(code: string): Promise<OwnerEmail>

The code addEmail sent: on a match the email is the owner's to sign in with, or, when an account already has it, that account takes this one in (merged). Whether an account has the email is said only once the code matches. status is added, or verified when an agent's turn confirmed it (it's added once that turn ends).

const confirmed = await Human.owner().confirmEmail("482913");
Parameters
codestringrequired
Returns

The confirmed email.

only

only(...tools: HumanTool[]): HumanOperations

Some of the tools this person gives an agent, for tools. In an agent's tools a Human gives it three, each addressed only to this person: notify, ask (the turn waits, awaiting_human, and the answer arrives as the next turn) and hand_off (the conversation goes to this person, with a page and an email carrying the transcript and a reply box; their replies post as person messages and the agent stays quiet until agent.handBack(conversation); on a call it's transferred to the person's phone). Policy names them human.notify, human.ask and human.hand_off.

const manager = new Human({ email: "ops@acme.com" });
await Agent.create("support", { instructions: "...", tools: ["search", manager.only("notify", "ask")] });
Parameters
toolsHumanTool[]required
Returns

A ref to just those tools of this person, to list in tools=.

Types
/** The tools a person gives an agent: `notify`, `ask` and `hand_off`. */
type HumanTool = "notify" | "ask" | "hand_off";

ask

ask(message: string, options?: HumanAskOptions): Promise<HumanRequest<Answer>>

Ask a question; wait() resolves to an Answer. pick asks, in place of options, for something in one of their connected accounts, and multiple lets them choose several.

Parameters
messagestringrequired
options.optionsstring[]

The answers they choose from (up to 20); left out, they answer in their own words.

options.pickHumanPick

In place of options: something in a connected account. The choices are read from it, and an account that holds just one answers at once with it.

options.multipleboolean

They may choose several of the options, or of a pick's choices.

options.connectHumanConnectAsk

Asked of the owner: which of the account's connections a workflow step uses. NoClick sets the one they choose as them, and an account holding just one that fits answers at once with it. Needs the workflows scope.

options.secretHumanSecretAsk

A secret's values, typed on NoClick's page (its link carries a key: the request's id alone opens nothing), never shown to you or a model. Needs the secrets scope.

options.viaVia
options.expiresInSnumber
Returns

The request, already sent. wait() blocks until the person answers and gives what they picked (choice, a pick's value beside it; each of several in choices and values) and wrote (text).

Types
/**
 * Something to pick in a connected account (`Human.ask`'s `pick`): the connection (a `Connection`, or
 * its id or name) and the field its lookup lists (`connection.lookup` names them: `repository`,
 * `team_id`, `channel`), with the values that field depends on (a spreadsheet's id for its sheets).
 */
interface HumanPick {
  connection: string | Connection;
  field: string;
  arguments?: JsonObject;
}

type JsonObject = { [key: string]: unknown };

/**
 * Which of the account's connections a workflow step uses (`Human.ask`'s `connect`, asked of the owner): the app or
 * model provider (`integration`) or the one kind of credential (`credentialType`), and the step; `slot` narrows it
 * to one kind the step keys connections by.
 */
interface HumanConnectAsk {
  integration?: string;
  credentialType?: string;
  step: HumanStepRef & { slot?: string };
}

/** A workflow step a question fills in: its workflow (a `Workflow` or its id) and its id in the graph. */
interface HumanStepRef {
  workflow: string | Workflow;
  stepId: string;
}

/**
 * A secret's values (`Human.ask`'s `secret`): typed on NoClick's page and kept as the account's secret `name`, its
 * `keys` each a value; with `step`, an agent step's shell gets it too (the owner's only).
 */
interface HumanSecretAsk {
  name: string;
  keys: string[];
  step?: HumanStepRef;
}

/** `"auto"` or the channels to use, e.g. `["email", "web"]`. */
type Via = "auto" | string | string[];

approve

approve(
  message: string,
  options?: { details?: unknown; via?: Via; expiresInS?: number },
): Promise<HumanRequest<boolean>>

Ask for a yes/no; wait() resolves to true when approved.

Parameters
messagestringrequired
options.detailsunknown
options.viaVia
options.expiresInSnumber
Returns

The request, already sent. wait() gives True if they approve and False if they decline.

Types
/** `"auto"` or the channels to use, e.g. `["email", "web"]`. */
type Via = "auto" | string | string[];

notify

notify(message: string, options?: { via?: Via }): Promise<HumanRequest<null>>

Send a notice (the operation succeeds once it's sent).

Parameters
messagestringrequired
options.viaVia
Returns

The request, already sent and its operation already succeeded, so wait() returns None at once. undelivered names any channel that failed.

Types
/** `"auto"` or the channels to use, e.g. `["email", "web"]`. */
type Via = "auto" | string | string[];

connect

connect(
  connection: string | Connection,
  options?: { reason?: string; redirectUrl?: string },
): Promise<ConnectLink>

Ask this person to connect connection (a Connection or its name, in this person's user); wait() resolves to the connected Connection.

Parameters
connectionstring | Connectionrequired
options.reasonstring
options.redirectUrlstring
Returns

The link, already emailed: its url and when it expires_at. wait() gives the connected Connection.

HumanRequest

class HumanRequest extends Operation

A request to a person; also the operation that finishes when they answer.

Attributes
requestIdstring | null

The request's own id (the operation's is id).

requestStatusHumanRequestStatus | null

pending, answered, delivered, expired or canceled.

requestJsonObject

The request as created: url, delivered_via, undelivered, ...

urlstring | null

The page where the person answers (/h/{id}); embed or send it yourself.

deliveredViastring[]
undeliveredJsonObject[]

Channels that failed, each with a reason.

fileHumanFileAsk | null

A file question's file where the agent works (null for any other request).

notestring | null

What the approver wrote with their answer (null until answered, or if they wrote nothing).

Types
type HumanRequestStatus = "pending" | "answered" | "delivered" | "expired" | "canceled";

type JsonObject = { [key: string]: unknown };

liststatic

static list(
  options?: HumanRequestFilters & { limit?: number },
): Promise<HumanRequest<unknown>[]>

Requests your code and agents sent, newest first (or the first limit).

Parameters
options.statusOneOrMany<HumanRequestStatus>
options.statusNotOneOrMany<HumanRequestStatus>
options.kindOneOrMany<"ask" | "approve" | "notify">
options.answerable"owner" | "code"

"owner": only requests the signed-in account owner may answer; "code": only those your code may answer with approve or decline. A call NoClick holds for the account's owner (a purchase or a deletion, whose request.owner_only is true) is listed only for a key that names the approvals:answer scope, and never one made with that key or one whose terms a person accepts (see Approval).

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 request, fetched page by page. Each is also the operation you can wait() on; request_status is the request's own status.

Types
type HumanRequestStatus = "pending" | "answered" | "delivered" | "expired" | "canceled";

/**
 * 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?: HumanRequestFilters & PageOptions,
): Promise<Page<HumanRequest<unknown>>>

One page of requests; 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.statusOneOrMany<HumanRequestStatus>
options.statusNotOneOrMany<HumanRequestStatus>
options.kindOneOrMany<"ask" | "approve" | "notify">
options.answerable"owner" | "code"

"owner": only requests the signed-in account owner may answer; "code": only those your code may answer with approve or decline. A call NoClick holds for the account's owner (a purchase or a deletion, whose request.owner_only is true) is listed only for a key that names the approvals:answer scope, and never one made with that key or one whose terms a person accepts (see Approval).

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 requests and whose next_cursor is None on the last page.

Types
type HumanRequestStatus = "pending" | "answered" | "delivered" | "expired" | "canceled";

/**
 * 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;

retrievestatic

static retrieve(
  requestId: string,
  options?: { client?: NoClick; user?: UserOption },
): Promise<HumanRequest<unknown>>

One request by its own id (a HumanRequest.requestId, the /h/{id} page's): what it asks, how it stands (requestStatus) and, once answered, the answer. A user reads only their own; throws NotFound for any other. Answer it with answer, approve or decline.

const request = await HumanRequest.retrieve("hr_3f2a1c9e");
if (request.requestStatus === "pending") await request.approve({ note: "Go ahead" });
Parameters
requestIdstringrequired
options.userUserOption

Who the call acts for. Defaults to the user set by noclick.as_user (none: 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 request.

Types
/** `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>;
}

summarystatic

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

How many human-request operations (ask, approve, notify) match, by operation status.

Parameters
options.clientNoClick
options.userUserOption

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

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

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

options.agentstring | ApiObject

An Agent or agent id.

options.statusNotOperationStatus | readonly OperationStatus[]
options.updatedAfterDate | string

Rows changed since (for polling).

options.causestring

The failed ones of one cause (an OperationFailure's cause, from Operation.failures()).

options.keystring

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

options.createdAfterDate | string
options.createdBeforeDate | string
options.userFilterUserFilter

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

Returns

The number that match in total, and per operation status in by_status.

Types
/** `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>;
}

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;

answer

answer(fields: HumanAnswerFields): Promise<this>

Answer a question from your own code, as the person it waits on (who may: as approve says): a choice (or choices) and/or text; a connect question's connection (one of the account's that fits), which NoClick sets on the step as your key, so it needs the workflows scope and a key acting for your whole account, never a user's or an agent's own tools; a secret question's secretValues, kept in the secret and never with the answer, which needs the secrets scope. A file question (file) is the account's owner's alone, signed in: secretValues for its keys, else fileContent, the whole file, written into the asking agent's sandbox or machine while it runs.

Parameters
fieldsHumanAnswerFieldsrequired
Returns

This request, answered: request_status is answered.

Types
/**
 * What `HumanRequest.answer` takes: a question's choice(s) and/or text, a connect question's connection, or a secret
 * or file question's values (or the file itself).
 */
interface HumanAnswerFields {
  choice?: string;
  choices?: string[];
  text?: string;
  /** One of the account's connections that fits (a `Connection`, or its ref or name). */
  connection?: string | Connection;
  /** A value for each of the secret's keys, or of a file question's: kept in the secret or the file, never with the answer. */
  secretValues?: Record<string, string>;
  /** A file question's that names no keys: the file as it's written (text, up to 1 MB), kept in the file and never with the answer. */
  fileContent?: string;
}

approve

approve(options?: { note?: string }): Promise<this>

Approve it from your own code, as the person it waits on: with a key acting for your account, an approval routed to your account; with a user's session or inside asUser, one addressed to that user; a call NoClick holds for the account's owner, only with a key that names the approvals:answer scope, as Approval.approve answers it (anyone else gets PermissionDenied). A held operation call then runs exactly as it was held (a held shell command or other tool, the agent makes again itself), and the agent gets a turn in the same conversation with its result, its reply going out where the conversation lives: on an email thread, the same thread (the inbox agent's reply tool is bound to the thread's latest message).

Parameters
options.notestring
Returns

This request, answered: request_status is answered and note is yours.

decline

decline(options?: { note?: string }): Promise<this>

Decline it: a held call never runs, and the agent gets a turn saying so, with your note.

Parameters
options.notestring
Returns

This request, answered: request_status is answered and note is yours.

HumanOperations

class HumanOperations

Some of a person's tools for an agent (human.only(...)), for tools.

Attributes
humanHuman
toolsHumanTool[]
Types
/** The tools a person gives an agent: `notify`, `ask` and `hand_off`. */
type HumanTool = "notify" | "ask" | "hand_off";

Answer

interface Answer

What the person chose (choice) and/or wrote (text). A pick's answer names the choice in the account too (value: a repository's owner/name, a channel's id); a question asked with multiple names each one they chose (choices, and a pick's values).

Attributes
choicestring | null
textstring | null
rawunknown

The response JSON exactly as the API sent it.

valuestring | null
choicesstring[]
valuesstring[]
connectionstring | null

A connect question's: the connection set on the step, by its ref (also its value; choice is its name).

secretstring | null

A secret question's: the secret its values went into, never the values.

HumanFileAsk

interface HumanFileAsk

A file in the asking agent's sandbox or machine its owner fills in (HumanRequest.file): a local .env, a key file. Only an agent's own ask tool asks one, and only the account's owner answers it: with keys, a value for each (set in the file as KEY=value lines, the rest of it kept); without, the whole file. NoClick writes it there as a file holding secrets, never keeping it anywhere else.

Attributes
pathstring

The file's absolute path where the agent works.

keysstring[] | null

The keys they fill in; null when they write the whole file.

agentIdstring
agentNamestring | null

OwnerEmail

interface OwnerEmail

An email confirmed for the owner (Human.confirmEmail).

Attributes
emailstring
statusstring

added, or verified when an agent's turn confirmed it: it's added once that turn ends.

mergedboolean

An account that already had the email took this one in.

OwnerLine

interface OwnerLine

One of NoClick's own numbers the owner texts it on (Human.reach): app is whatsapp or imessage.

Attributes
appstring
numberstring

OwnerReach

interface OwnerReach

Where the owner texts NoClick (Human.reach).

Attributes
linesOwnerLine[]

NoClick's own numbers, one for each app it answers on.

phoneLinkedboolean

Whether a phone of the owner's is linked to the account; which one is never said.

emailOwnerEmailAddress | null

The address the owner emails their assistant at; null before it has one.

HumanRequestPage

interface HumanRequestPage

A human request as its page shows it (HumanRequestLink.read).

Attributes
idstring
kindstring

ask, approve, notify, hand_off, setup, ...

statusstring

pending until it's answered, then answered, expired, canceled, ...

messagestring | null
expiresAtDate | null
rawJsonObject

Everything the page shows: its options, its brand, a held call's approval, a step question, a hand-off.

Types
type JsonObject = { [key: string]: unknown };

OwnerEmailAddress

interface OwnerEmailAddress

The address the owner emails their assistant at.

Attributes
addressstring
pausedboolean

The owner turned its mail off: the address stays theirs, and mail to it is ignored.

fromAnyoneboolean

Anyone's mail to it reaches the assistant, not only the owner's.