Skip to content

Qoni SDK ​

This page covers installation, all unified SDK method entry points, run and interaction data, and application functions that present requests and submit user responses.

Available SDK ​

The public unified Qoni SDK is the Node.js and TypeScript package @qoniai/qoni. Its source is available in QoniAI/qoni-sdk-node.

ItemCurrent status
npm package@qoniai/qoni
GitHub repositoryQoniAI/qoni-sdk-node
Current public version0.10.1
Example version0.10.1, matching the npm release; bundled with the download
RuntimeNode.js 18 or later with server-side fetch
Module formatsESM, CommonJS, and TypeScript declarations
LicenseMIT

Server-side credentials

Keep the Qoni accessKey and secretKey on a trusted server. Do not bundle them into browsers, mobile apps, public CLI configuration, or untrusted Agent runtimes.

Version

The examples on this page use npm 0.10.1. 0.10.1 adds webAgentGrant and clients without an AccessKey, so a platform can issue one person's Web Agent token to its own apps; see Apps that hold no AccessKey. To upgrade, see Upgrading from 0.10.0 to 0.10.1.

Capability surface ​

The unified SDK exposes these capabilities from Qoni:

NamespacePurpose
genauthDelegate authorization, hosted sign-in, read the current user, and manage GenAuth users
gumemCreate sessions, add messages, recall Memory, and record Actions
doAnythingStart or reattach to general Web Agent tasks, read artifacts, choose a model, recall memory before running; read the person's conversations, the browsers open now and the files on a conversation's computer
webSearchSearch the public web and read results
deepResearchRun long-form research and download artifacts
trackCreate and manage scheduled tracks, list every track and stream its checks live; see Track
proactiveFollow-ups: agree on a time, and the agent comes back to the same conversation then
notificationsTrack findings and marking them read
workspaceThe Credits the workspace can still spend and its Top up page

Runtime product calls use short-lived delegation tokens. The SDK handles runtime discovery and downstream product-token exchange. Application code should not construct internal /api/v3/eak/* routes or internal claims. When a platform serves several apps that hold no AccessKey, its server issues one person's Web Agent token with qoni.webAgentGrant(); see Apps that hold no AccessKey.

Install ​

The downloadable examples and this page use the published 0.10.1 release. Use the commands below to install it in an existing application. Download the examples and run npm ci in examples/qoni to install the bundled SDK of the same version.

bash
npm install @qoniai/qoni@0.10.1

You can also use pnpm or Yarn:

bash
pnpm add @qoniai/qoni@0.10.1
# or
yarn add @qoniai/qoni@0.10.1

Initialize the client ​

Get an AccessKey ​

  1. Open the Qoni Console workspace list and select the workspace that will use the SDK.
  2. Select AccessKey in the sidebar, then Create AccessKey, and configure the permissions needed for your calls.
  3. In the Save AccessKey dialog, select Copy credentials. Store the AccessKey ID and AccessKey Secret as the server-side environment variables QONI_ACCESS_KEY and QONI_SECRET_KEY.

The AccessKey Secret is shown only when the key is created. You can view an existing key's ID in the list, but you cannot retrieve its Secret again. Create a new AccessKey if you did not save the Secret.

ts
import { Qoni, QoniScopes } from "@qoniai/qoni";

// Initialize on the server; AK/SK access the services bound to this workspace.
const qoni = new Qoni({
  accessKey: process.env.QONI_ACCESS_KEY!,
  secretKey: process.env.QONI_SECRET_KEY!,
});

When host is omitted, the SDK uses the hosted gateway https://dashboard.qoni.ai. Private or local deployments can pass host; it must point to the Qoni Console or SDK gateway, not directly to GenAuth, Web Agent, or GUMem.

Qoni accepts the following options:

OptionRequiredDescription
accessKeyYes, unless webAgentHostAccess key created in the Qoni Console
secretKeyYes, unless webAgentHostSecret key created in the Qoni Console
webAgentHostNoWhere Web Agent is. An app that holds no AccessKey passes the webAgentHost from webAgentGrant() instead of the keys
hostNoQoni gateway address for private deployments; overrides runtime discovery
fetchNoCustom fetch implementation for proxies or test environments
timeoutMsNoPer-request timeout, default 30000; event-stream waiting is not limited by it
sseMaxRetriesNoEvent-stream reconnect attempt limit, default 5; set 0 to disable

Obtain a delegation token ​

Web Agent and GUMem products act for an end user. Silent delegation requires a real GenAuth user ID from the user pool bound to the Qoni credential:

ts
// Delegate this research task for the current user from the bound GenAuth pool.
const { token } = await qoni.genauth.delegateAgent({
  userId: process.env.QONI_USER_ID!,
  agentKey: "research-assistant", // Agent audit label for this delegation
  scopes: [
    QoniScopes.WEB_SEARCH_READ, // Read search status and results
    QoniScopes.WEB_SEARCH_MANAGE, // Start or cancel searches
    QoniScopes.GUMEM_MEMORY_READ, // Recall user context
    QoniScopes.GUMEM_MEMORY_WRITE, // Write confirmed demo preferences
  ],
  expiresIn: "15m", // Converted to the server's integer 900 seconds
});

When the user must approve the authorization themselves, use mode: "interactive" so they consent scope by scope in the Qoni Console. Complete interactive authorization on the server with completeDelegateToken({ grantId, code, state }); the browser never receives the delegation token.

Fine-grained permissions are declared with scopes in the <namespace>.<resource>:<verb> format, for example webagent.web_search:read. Each Web Agent product has exactly two verbs, read and manage; products: ["webSearch"] requests the whole product as a shorthand. Site sign-in has two more scopes: webagent.site_login:request (open a controlled login browser) and webagent.site_login:confirm (save the login to the browser profile), exported as QoniScopes.SITE_LOGIN_REQUEST / QoniScopes.SITE_LOGIN_CONFIRM. They are not part of any products shorthand: request them explicitly in scopes, and the AccessKey policy must allow them. The SDK exports the QoniScopes constants and QoniScopeBundles presets (such as GUMEM_SESSION_RECALL) so you avoid hand-writing scope strings; a malformed scope throws QoniValidationError locally. For SDK constants and service availability boundaries, see Requestable scopes.

The silent delegation response does not contain grantedScopes. When you need to record the effective permission boundary, use authoritative introspection:

ts
// Declare the fields this page reads; the SDK types introspection data as unknown by default.
const { data: tokenInfo } = await qoni.genauth.introspectDelegationToken<{
  active: boolean;
  scope?: string[];
}>({ token });
if (!tokenInfo.active) throw new Error("Delegation token is inactive");
const effectiveScopes = tokenInfo.scope ?? []; // Record effective scopes with the audit data

In an interactive response, state is a compatibility alias of the server-generated grantState; it is not an echo of the caller input state. Verify that the authorization URL's grant_id query value equals the response grantId, then save grantId and your business state on the server keyed by grantState. After consent, the GenAuth callback to redirectUri carries code, your business state, and grant_state (equal to grantState), but no grantId: look the record up by grant_state, check the business state, then call completeDelegateToken({ grantId, code, state }) with the saved grantId and the callback's grant_state as state.

Apps that hold no AccessKey ​

A platform that serves many apps keeps the AccessKey on its own server and gives each app only a token for the person using it. The app runs Web Agent with that token and never sees the AccessKey.

On the server that keeps the AccessKey, confirm who the person is with the platform's own sign-in, then issue their token:

ts
// Platform server: userId is a user in the workspace's user pool, confirmed by the platform's own sign-in
const grant = await qoni.webAgentGrant({
  userId: process.env.QONI_USER_ID!,
  products: ["doAnything"],
  scopes: [
    QoniScopes.SITE_LOGIN_REQUEST, // ask the person to sign in to a site
    QoniScopes.SITE_LOGIN_CONFIRM, // save the person's sign-in
    QoniScopes.BROWSER_USE_TAKE_CONTROL, // ask the person to take over the browser
  ],
});
// grant: { token, expiresAt, webAgentHost, userId, scopes } — send it to the app
  • Delegation is silent: no consent page is shown. The person must already be a user in the user pool bound to this workspace, or the request is rejected.
  • The token acts for that one person and carries only the Web Agent scopes asked for; the AccessKey policy must allow them, or the request returns eak.delegation.scope_not_allowed. Only webagent.* scopes can be granted; any other scope throws QoniValidationError locally.
  • The token is accepted until expiresAt (epoch milliseconds, about 14 days later); issue a new grant before then.
  • Every run the token starts is billed to the workspace.

In the app, build the client with webAgentHost instead of the AccessKey:

ts
// App: holds only the grant from the platform, never the AccessKey
const app = new Qoni({ webAgentHost: grant.webAgentHost });
const run = await app.doAnything.run({
  token: grant.token,
  prompt: "Open https://example.com and tell me the page title.",
});
const result = await run.wait();
const { available } = await app.workspace.credits({ token: grant.token });

Such a client calls doAnything, webSearch, deepResearch, track, proactive, notifications and workspace with the token, as long as the token carries that product's scopes. Anything that needs the AccessKey — delegation, token exchange, GenAuth management, GUMem — throws QoniValidationError before a request is sent. A site sign-in or browser takeover a run asks for is completed by the person in the live view, as with any other token.

Requestable scopes ​

A scope passed to delegateToken or genauth.delegateAgent must clear two checks:

  1. The AccessKey policy: a delegation can request only scopes the current AccessKey allows; anything else returns eak.delegation.scope_not_allowed. The permission policies you select when creating or editing the AccessKey in Console define that allowlist.
  2. The product API check: GUMem and Web Agent endpoints admit requests by scope. The "Allows" column below states what each scope actually permits and names the SDK methods that use it.

The tables below list the scopes you can request, by product. The SDK constants live on QoniScopes, for example QoniScopes.GUMEM_MEMORY_READ.

GUMem

ScopeSDK constantAllowsConsole policy
gumem.memory:readGUMEM_MEMORY_READRead session context and the message stream; also satisfies gumem.action:read and gumem.profile:read. SDK method: gumem.recallGUMem Memory
gumem.memory:writeGUMEM_MEMORY_WRITEWrite Memory; also satisfies gumem.session:create, gumem.message:write, and gumem.action:write. SDK methods: gumem.createSession, gumem.addMessagesGUMem Memory
gumem.session:createGUMEM_SESSION_CREATECreate a sessionGUMem Session
gumem.message:writeGUMEM_MESSAGE_WRITEWrite messages to a sessionGUMem Session
gumem.action:writeGUMEM_ACTION_WRITERecord user Actions. SDK method: gumem.actions.recordGUMem Actions
gumem.action:readGUMEM_ACTION_READQuery user Actions and their progress, facts, summaries, and topics; subscribe to the Action stream. SDK methods: gumem.actions.recall, gumem.actions.streamGUMem Actions
gumem.profile:readGUMEM_PROFILE_READRead and recall the user profileGUMem Admin
gumem.admin:manageGUMEM_ADMIN_MANAGECall the GUMem console's project management APIsGUMem Admin

Web Agent

ScopeSDK constantAllowsConsole policy
webagent.do_anything:readDO_ANYTHING_READRead DoAnything run status, events, artifacts, and recordingsWebAgent Do Anything
webagent.do_anything:manageDO_ANYTHING_MANAGEStart and cancel runs, respond to interactions, send messages; includes readWebAgent Do Anything
webagent.web_search:readWEB_SEARCH_READRead search status and resultsWebAgent Web Search
webagent.web_search:manageWEB_SEARCH_MANAGEStart and cancel searches; includes readWebAgent Web Search
webagent.deep_research:readDEEP_RESEARCH_READRead research status, events, and report artifactsWebAgent Deep Research
webagent.deep_research:manageDEEP_RESEARCH_MANAGEStart and cancel research, respond to interactions; includes readWebAgent Deep Research
webagent.track:readTRACK_READRead monitors and their executionsWebAgent Track
webagent.track:manageTRACK_MANAGECreate, update, pause, resume, run now, and delete monitors; includes readWebAgent Track

In the table, manage includes read when the product API checks a product token. The SDK exchanges a separate read product token for status, events, results and artifacts, so the delegation must still explicitly request that read scope. Each product's read + manage pair can also be requested with the products shorthand: doAnything, webSearch, deepResearch, track.

Human takeover of the current run's browser also requires the separate webagent.browser_use:take_control scope (QoniScopes.BROWSER_USE_TAKE_CONTROL); manage does not replace it, and the task must request it explicitly through doAnything.run({ taskScopes }).

Site sign-in and browser takeover

ScopeSDK constantAllowsConsole policy
webagent.site_login:requestSITE_LOGIN_REQUESTopenLogin() opens a controlled login browserWebAgent Site Login
webagent.site_login:confirmSITE_LOGIN_CONFIRMconfirmSignedIn() saves the sign-in to the person's browser profileWebAgent Site Login
webagent.browser_use:take_controlBROWSER_USE_TAKE_CONTROLThe person takes over the current run's browserWebAgent Browser Takeover

No products shorthand includes these three scopes: request them explicitly in scopes. Silent mode has no consent page; interactive authorization has a step where the person approves each scope.

When you request scopes:

  • Separate product permissions from delegated scopes: Web Agent's manage-to-read inclusion and GUMem's broader-to-narrower scope coverage are product API checks; they do not automatically expand the delegation's scope list. With the SDK, explicitly request the scopes each method requires.
  • The SDK exchanges a product token per method: before each GUMem or Web Agent call, the SDK exchanges the delegation for a product token with only the scopes that method needs. If the delegation lacks one, the exchange returns eak.token_exchange.scope_not_delegated. With the SDK, request the scope listed for the SDK method you call. For example, delegating only gumem.session:create still fails gumem.createSession; delegate gumem.memory:write instead.
  • Site sign-in: openLogin() needs webagent.site_login:request, and saving the sign-in in confirmSignedIn() needs webagent.site_login:confirm; the AccessKey policy must include WebAgent Site Login.
  • Legacy verbs: Console's WebAgent policies also list scopes ending in :run, :stop, and :control. These are verbs from earlier versions, not aliases for the current product read and manage scopes or the separate webagent.browser_use:take_control scope. They cannot replace those scopes; do not use them in new code.

SDK method index ​

This page follows the declarations for the bundled @qoniai/qoni 0.10.1 build. Ordinary requests return QoniResponse<T>: data holds the business result and meta holds request, trace, and audit identifiers. The compatible genauth.delegateAgent() entry returns business data directly. Task creation returns a handle for continued reading. Application interaction functions are explained below.

Client and GenAuth ​

MethodInput and purposeReturn
qoni.genauth.delegateAgent(input)Same authorization endpoint as delegateToken; accepts userId, agentKey, explicit scopes, and expiresIn: '15m'Direct grant.token/grantId/auditId in silent mode, or the authorization request in interactive mode
qoni.delegateToken(input)mode, agent, products/scopes, expiresIn, optional idempotencyKey; silent mode uses user, interactive mode uses redirectUri/stateDelegation result or authorization request in data
qoni.delegateAgent(input)Existing root alias of delegateToken; distinct from genauth.delegateAgentRetains QoniResponse, with token at response.data.token
qoni.webAgentGrant({ userId, products?, scopes?, agent? })Silently delegate and exchange one person's Web Agent token for an app that holds no AccessKey; accepts only webagent.* scopes{ token, expiresAt, webAgentHost, userId, scopes }
qoni.completeDelegateToken(input)Server-saved grantId (the callback does not carry it), callback code, and callback grant_state passed as statedata.token, grantId, auditId, and other delegation fields
qoni.currentUser({ accessToken })Read the signed-in user; equivalent to genauth.userInfoQoniResponse<T>
qoni.resolveAnyBoundUser()Pick a bound user for demos; production apps identify the actual current userUser ID string
qoni.genauth.userInfo({ accessToken })Read identity with the user's GenAuth Access TokenQoniResponse<T>
qoni.genauth.discovery() / jwks()Read OIDC discovery configuration / verification keysQoniResponse<T>
qoni.genauth.introspectDelegationToken({ token })Read delegation validity and effective scopesQoniResponse<T>
qoni.genauth.auth.createLoginUrl({ redirectUri, state, screen? })Build the GenAuth hosted sign-up/sign-in URL; redirectUri must match the business app's registered callback{ url, expiresAt }
qoni.genauth.auth.exchangeLoginCode({ code, redirectUri })Exchange the one-time callback code for the user and their session{ user: { id, email?, phone?, name?, isNewUser }, accessToken, idToken, expiresIn }
qoni.genauth.users.list(input?)page, limit, options; list bound-pool usersQoniResponse<T>
qoni.genauth.users.get({ userId }) / getBatch({ userIds })Read one / multiple usersQoniResponse<T>
qoni.genauth.users.create(input) / createBatch(input)User fields / batch users or list; fields follow the GenAuth user APIQoniResponse<T>
qoni.genauth.users.update({ userId, ...fields })Update the specified user's fieldsQoniResponse<T>
qoni.genauth.users.deleteBatch({ userIds })Delete selected users after the application confirms the scopeQoniResponse<T>
qoni.genauth.users.iterate({ limit? })Iterate over the bound pool's users one by one, at most 50 per pageAsyncIterable<User>
qoni.genauth.users.createUser() / getUser() / getUserBatch() / updateUser() / createUsersBatch() / deleteUsersBatch() / isUserExists() / kickUsers() / resignUser() / resignUserBatch() / getUserRoles() / getUserGroups() / getUserDepartments() / getUserAuthorizedResources() / setUserDepartments()User methods named after the GenAuth management API; create / get / update and exists / kick / resign / listRoles above are their short forms. The remaining users.* management methods are in the GenAuth management method referenceQoniResponse<T>

users.* exchanges AK/SK for management access to the bound user pool by default, with optional adminToken/userPoolId overrides. User fields and most GenAuth results are generic data; declare T for the fields your application reads and validate results.

For the values the delegation methods accept in scopes and what each scope allows, see Requestable scopes.

GUMem ​

These methods use a delegated token. Effective Session, Memory, and Action permissions follow the service contract.

MethodMain inputPurpose and return
qoni.gumem.createSession(input)token; optional userId, sessionId, title, metadataCreate a Session; QoniResponse<T>
qoni.gumem.addMessages(input)token, sessionId, messages; optional userId, syncWrite user-confirmed messages; QoniResponse<T>
qoni.gumem.recall(input)token; optional sessionId, query, details, recallConfig, metadataFiltersRecall context; QoniResponse<T>
qoni.gumem.recallContext(input)token, sessionId, queryBounded recall; QoniResponse<MemoryContext> (origin/items/referenceText/truncated)
qoni.gumem.actions.record(input)token, user_id, content, timestamp (ISO 8601); other Action fields are optionalRecord an Action; QoniResponse<T>. Missing required fields return 422
qoni.gumem.actions.recall(input)token and query fieldsQuery Actions; QoniResponse<T>
qoni.gumem.actions.stream(input)token and query fieldsRead the Action stream endpoint result; QoniResponse<T>, not AsyncIterable

Cross-session recall follows the Memory record's scope. User preferences extracted as scope=user can enter user context across Sessions; facts classified as scope=session (such as a task's project name or budget) do not enter another Session's user context by default. Verify message writes, extraction, scope classification, and recall separately; not every session fact automatically becomes long-term user memory.

Web Agent product entry points ​

MethodMain inputReturn and limits
qoni.doAnything.run(input)token, task prompt; optional session, model, taskScopesRunHandle<DoAnythingEvent>
qoni.doAnything.attach(runId, options)Existing run ID, token; optional sessionReattach without creating a new task
qoni.doAnything.runWithMemory(input)token, prompt, memory: { sessionId, query, metadataFilters?, maxItems?, maxContextBytes? }; optional taskScopes, timeoutMs, signalRecall bounded GUMem context first, then start the run; returns { run, memory }
qoni.doAnything.api.listModels({ token })Delegation token{ default_model, items: [{ value, label }] } for run({ model })
qoni.doAnything.artifacts({ token, runId })Delegation token and run ID; optional signalArtifact[] without replaying events
qoni.doAnything.sessions.list({ token, limit? }) / get({ token, sessionId }) / credits({ token, sessionId })The person's conversations (newest first), one conversation, and what each of its runs costSessionSummary[] / SessionSummary / SessionCredits
qoni.doAnything.browsers.list({ token, sessionId }) / control({ token, sessionId, browserId, action })The browsers a conversation has open, the lead agent's first, then each sub-agent's. control acts only on a sub-agent's browser whose need is set (it waits for the person); action is take/release/done/skip. The lead agent's sign-ins and takeovers are its run's interactionsAgentBrowser[] / nothing
qoni.doAnything.files.list/read/watch/upload/move/mkdir/delete({ token, sessionId, … }), files.listAll({ token })The files on a conversation's computer. While it sleeps they are read from the copy kept after each turn (source: "saved"), so looking never wakes it; listAll lists only conversations whose copy has been savedSee Conversations, browsers and files
qoni.webSearch.run(input)token, prompt (string or string array); optional maxResultsPerQuery, siteWhitelist, siteBlacklistRunHandle<WebSearchEvent>; no session/limits support
qoni.webSearch.attach(runId, options)Existing run ID, tokenReattach to the search
qoni.deepResearch.run(input)token, prompt; optional depth, outputFormat, targetAudience, domainWhitelist, domainBlacklist, sessionRunHandle<DeepResearchEvent>
qoni.deepResearch.attach(runId, options)Existing run ID, tokenReattach to the research
qoni.track.create(input)token, prompt (mapped to instructions), title, required schedule ({ kind: 'interval', intervalSeconds } or { kind: 'daily', at, tz })MonitorHandle; creation starts a first_look check immediately
qoni.track.attach(monitorId, { token })Existing monitor ID and delegation tokenReattach to the monitor
qoni.track.list({ token })The person's tracks, each with whether a check is running and its unread findingsJsonObject[]
qoni.proactive.create({ token, sessionId, note, dueAt?, delaySeconds? })Schedule a follow-up in a conversation, at dueAt (ISO 8601) or delaySeconds from now (one of them); the agent then comes back to that conversation and carries on with note. Needs webagent.do_anything:manageProactiveCheck
qoni.proactive.list({ token, sessionId?, status?, limit? }) / get({ token, checkId }) / cancel(…) / runNow(…)Read, cancel or carry out a follow-up now; reading needs webagent.do_anything:read, cancel and runNow need manageProactiveCheck[] / ProactiveCheck
qoni.notifications.list({ token, limit? }) / markRead({ token, ids?, trackId? })Track findings, newest first, with the unread count; markRead without ids or trackId marks all. Need webagent.track:read / manage{ items, unread } / { unread }
qoni.workspace.credits({ token }) / billingUrl({ token, section? })Whole Credits the workspace's runs can still spend (null when not metered); the Qoni Console page that opens Top up or Plan (section: "topup" | "plan"), returned synchronously{ available } / string

session uses { sessionId } and continues the same conversation on the same computer; model values come from api.listModels; taskScopes asks for sign-in or takeover for this run; research depth is light/standard/deep.

Conversations, browsers and files ​

The SDK gives a personal agent app what it shows its person. Every conversation (a DoAnything session) has its own computer. Everything below takes the person's delegation token; reads need webagent.do_anything:read, changes webagent.do_anything:manage.

While a run works, its stream says what to show:

ts
import { QoniEventTypes, type AgentBrowser } from "@qoniai/qoni";

// Your UI: the simplest stand-in, updating one bubble per id and listing live views
const bubbles = new Map<string, string>();
const ui = {
  upsertBubble: (id: string, text: string, state: { done: boolean; final: boolean }) => { bubbles.set(id, text); },
  showScreens: (browsers: AgentBrowser[]) => { for (const b of browsers) console.log(b.id, b.url); },
};

await run.wait({
  onEvent(event) {
    switch (event.type) {
      case QoniEventTypes.Message: // a streamed reply: one id, the whole text so far, the new part
        ui.upsertBubble(event.data.id, event.data.text, { done: event.data.done, final: event.data.final });
        break;
      case QoniEventTypes.Browsers: // every browser open now: the lead's first, then each sub-agent's
        ui.showScreens(event.data); // [{ id, label, url, status, activity, need, userInControl, startedAt }]
        break;
    }
  },
});

url is the browser's interactive live view; put it in an iframe. A sub-agent whose need is set waits for the person (login: sign in there; help: do what prompt says); once they have, answer it with browsers.control({ token, sessionId, browserId, action: "done" }) (or take / release / skip).

A live view shows the computer's desktop scaled down to fit. Where the person does something themselves (a sign-in, a need), add &fit=1 to the address (before any #): while that view is open the browser is laid out in its shape, so a phone held upright gets the phone's pages; when it closes, the browser is back at its own size. The agent works in whatever shape the browser has, so leave it off views that only watch.

Any time, without a run:

ts
const sessionId = run.sessionRef!.sessionId;                    // the conversation the run above is in
const signal = AbortSignal.timeout(60_000);                      // watch file changes for one minute
await qoni.doAnything.sessions.list({ token });                  // conversations, newest first
await qoni.doAnything.sessions.credits({ token, sessionId });    // what each run cost
await qoni.doAnything.browsers.list({ token, sessionId });       // browsers open now (none while it sleeps)

await qoni.doAnything.files.list({ token, sessionId, path: "workspace", depth: 2 });
// → { source: "live" | "saved" | null, items: [{ path, name, type, sizeBytes, modifiedAt }], savedAt }
const bytes = await qoni.doAnything.files.read({ token, sessionId, path: "workspace/outputs/report.md" });
for await (const change of qoni.doAnything.files.watch({ token, sessionId, signal })) {
  // { type: "created" | "changed" | "removed", path } within ~2 s; ends when the computer sleeps
}
await qoni.doAnything.files.upload({ token, sessionId, path: "workspace/uploads/brief.pdf", content: bytes });
await qoni.doAnything.files.move({ token, sessionId, from: "a.md", to: "notes/a.md" });
await qoni.doAnything.files.mkdir({ token, sessionId, path: "notes" });
await qoni.doAnything.files.delete({ token, sessionId, path: "notes/old.md" });
await qoni.doAnything.files.listAll({ token });                  // every conversation's kept files

await qoni.workspace.credits({ token });                         // { available: 123 }, null if unmetered
qoni.workspace.billingUrl({ token });                            // the console page that opens Top up ({ section: "plan" } for Plan)
await qoni.proactive.list({ token });                            // follow-ups the agent scheduled
await qoni.notifications.list({ token });                        // { items, unread }; needs webagent.track:read

Looking never wakes a sleeping computer: it is answered from the copy kept after each turn (source: "saved"). A change wakes it, and it goes back to sleep once idle. Paths are relative to its home folder; hidden runtime state is refused. Uploads never replace a file (409 workspace_file_exists). A run that failed says why in RunResult.failureReason; insufficient_credits means top up.

Run, monitor, and artifact handles ​

MemberUsage
run.id / run.sessionRefRetain the run ID / optional Session reference for queries or follow-up runs
run.status()Read RunStatus: id/status/sessionId/output/raw
run.events(options?)AsyncIterable; accepts lastEventId, signal, onWireEvent, onReconnect
run.wait(options?)Return terminal RunResult; accepts timeoutMs/signal, onEvent/onWireEvent/onReconnect, onInteraction
run.interactionHandle(request)Wrap event request data in a handle bound to this run
run.cancel(reason?)Request cancellation and return status; distinct from stopping client-side waiting
monitor.id / monitor.get()Retain the monitor ID / read its definition
monitor.pause() / resume()Pause / resume monitoring
monitor.refine(patch)Changes only title/schedule, preserving the original intent
monitor.runNow()Returns trackId/sessionId/runId, meaning accepted; first_look or another in-flight check causes 409 task_in_progress
monitor.events({ lastEventId?, signal? })The track's checks, live. Each check is a run of the track's own session that streams progress, message and browsers events and ends with done (its runId is the check's); the stream does not end at a check's done, so abort signal to stop. Needs webagent.do_anything:read as well as track read
monitor.interactionHandle(request)Deprecated: no Track question/intervention endpoint; throws QoniUnsupportedError locally
monitor.runs({ limit?, offset? }) / run(runId)Reads the most recent 50 checks; limit/offset paginate locally within this window; an exact run ID outside it fails
monitor.delete()Soft-deletes and stops future scheduling; it does not cancel a running task
artifact.content()Download bytes (Uint8Array)
artifact.refreshDownloadUrl?.()Refresh a temporary URL when the implementation provides this method

RunResult includes runId/status/output/artifacts/terminalReason/isTaskSuccessful/failureReason/failureDetail/raw; a failureReason of insufficient_credits means the workspace is out of Credits. Validate business output. Artifact metadata is id/name/mime/sizeBytes/createdAt/downloadUrl/expiresIn, all optional except id. Timing out or aborting a client read does not cancel server execution: use attach() to continue reading or cancel() to request cancellation.

Track creation starts first_look immediately; successful checks use done, without mapping to RunResult.status value succeeded. See Track for the contract.

event.type values include core progress/message/interaction/browserLiveUrlChanged/browsers/done, search resultsReady, research phase/sectionReady, and the Track type constants monitorCreated/triggered/checkCompleted. For message fields, see Upgrading from 0.9.x to 0.10.0. Constant keys use PascalCase: for example, QoniEventTypes.Done has the value done. Product handles have different event types; no product emits every type. Original frames are available at event.raw; subscribe to all wire frames with onWireEvent.

Low-level and compatibility entry points ​

Prefer typed methods above. These are actual exposed low-level interfaces; api bodies and results follow the backend and are outside the stable semantic contract.

Entry pointMethods
qoni.doAnything.apicreateSession, createRun, getRun, getTrace, listModels, events, intervene, cancel, listArtifacts, artifactDownloadUrl, readRecording, readArtifacts (deprecated)
qoni.webSearch.apirun, get, events, cancel
qoni.deepResearch.apirun, get, events, followUp, cancel, feedback, listArtifacts, getArtifact
qoni.track.apicreateMonitor, getMonitor, runNow, events (the track session's raw event stream), intervene (deprecated), listRuns, getRun, updateMonitor, deleteMonitor
qoni.unstableRequest(input) / request(input)Gateway request with method/path and optional token/query/body/headers; both use the same implementation
Signing exportsbuildStringToSign(method, path, headers, params), buildSignature(secretKey, stringToSign), buildAuthorization(accessKey, secretKey, stringToSign)

Low-level request bodies use the wire field names: api.createRun takes the task text as instructions; deepResearch.api.followUp takes text, and feedback takes rating and feedbackText; track.api.createMonitor takes schedule as { every_seconds }. doAnything.api.readArtifacts is deprecated and throws QoniUnsupportedError locally without a request; for files use doAnything.artifacts({ token, runId }) and artifact.content().

qoni.qoni.delegateToken/completeDelegateToken are also callable; prefer the client methods. delegateAgent/completeDelegateAgent and old credential/token fields are compatibility entries discussed in migration notes below. QoniScopes exports scope constants, QoniProductScopes maps products to scopes, and QoniScopeBundles supplies presets; exported input, result, event, and error types follow these APIs. Advanced deployments can override individual discovery URLs with genauthHost/gumemHost/webAgentHost; ordinary integrations use host.

Interaction requests and business functions ​

When a task needs the user, the Agent pauses and raises an interaction, then waits for the application to send back the user's decision. Interactions are typed by what the user has to do, not by business: draw one screen per type and the application handles interactions from any task. This section explains each type's data, the SDK methods it offers, and how one application wires them into its own UI. The business functions used by the Quickstart script in the downloadable examples (quickstart.ts) are application code in the downloadable interaction-demo.ts, not exports from @qoniai/qoni.

TypeWhat the user doesSDK methods
site_loginSigns in to a site in the controlled browseropenLogin(), confirmSignedIn()
take_controlOperates the browser by hand for anything other than signing in, such as a CAPTCHAconnectControl(), refreshControl(), releaseControl()
ask_userAnswers a question shaped by answerType and optionsanswer(), skip()
confirmationAllows or rejects an actionconfirm(), reject()
fill_formFills in the ordinary details this task needs, as described by fieldssubmit(), skip()
waitNothing to decide: the system is waiting for a rate limit or an external conditionretry()

Keep three things in mind. For the full Personal Agent scenario, see Personal Agent: run DoAnything and handle interactions.

  • One interaction calls back several times: creation, status changes, and reconnect replays all call onInteraction again. Act only on status pending and dedupe by request.id; update one UI card per request.id.
  • Interactions arrive one at a time: the task pauses at an interaction; the Agent continues, and the next interaction appears, only after the current one is handled.
  • Methods follow the actions the backend offers: do not call a method when handle.can(kind) returns false; doing so throws QoniValidationError.

Handle and request data ​

onInteraction receives an SDK InteractionHandle, named handle here. request = handle.interaction contains data. handle.id/type/status/actions are convenient field accessors; read title/prompt/payload from request. Response methods are already bound to the run and declared action endpoint, so applications do not construct URLs. The second callback argument is event (RunEvent); use event.runId to associate the task. Quickstart uses only the first argument.

request fieldApplication usage
idStable request ID for updates and replay
typeChoose a sign-in, question, approval, or other business view
statuspending, active, resolved, expired, or canceled
title / prompt?Card title / optional explanation
createdAt / resolvedAt? / expiresAt?Creation, resolution, and expiration times
evidence?Optional { artifactId } evidence reference
payloadType-specific business data below
actionsCurrently offered actions, each with kind/label/method/endpoint and optional inputSchema

A question request with demo values, showing only the main fields:

jsonc
{
  "id": "demo-question-1", // Retained across updates to this request
  "type": "ask_user", // The Agent needs the user to answer a question
  "status": "pending", // Waiting for the user's response
  "title": "Please clarify the scope",
  "payload": {
    "question": "Only support issues, or all customer questions?",
    "answerType": "single_choice", // Text box, number, yes/no, single or multiple choice
    "options": [
      { "value": "support", "label": "Support issues only" },
      { "value": "all", "label": "All customer questions" }
    ]
  },
  "actions": [
    { "kind": "answer", "label": "Submit answer" } // method, endpoint, etc. omitted
  ]
}

Data and responses for the five request types ​

typepayloadWhat the application does
site_loginsites: [{ siteId, displayName, loginUrl }], optional monitorIdFinish controlled sign-in, then call handle.confirmSignedIn() to request a recheck; when openLogin() opened the login UI, it saves that login first
ask_userquestion, answerType, optional options: [{ value, label }]Send the actual answer through handle.answer(value), typed by answerType; use skip() only when offered
confirmationsummaryApprove with handle.confirm() or reject with handle.reject()
take_controlliveUrl, optional surface/reasonOpen the browser already handed to the user, then call handle.releaseControl() when finished
waitwaitKind (rate_limit/external/sleep), optional until/retryableShow waiting status; call handle.retry() only when offered and chosen by the user

answerType is text, number, boolean, single_choice, or multiple_choice; answer() takes a string, a number, a boolean, one option value, or an array of option values respectively, and throws QoniValidationError before sending a value that does not fit. The wire still calls this type clarification; the SDK presents it as ask_user, and a question with choices is single_choice. Interaction is a union over type, so switch (request.type) narrows payload in each branch. A request keeps its type for its whole lifecycle; when the backend settles it with an empty shell, the SDK keeps the original payload and only changes status. retryable: true is a data hint; actions still decides whether to enable a retry button.

Example application: five business functions ​

DemoRequestCard describes application display data and button callbacks. Logs show a summary; connect these data to your own card or dialog renderer. demoScreen is local, single-task storage. All five functions return synchronously without waiting for user input: wait() awaits its callbacks before consuming the next event.

ts
// Application demo, not SDK API. Rendering never submits a user decision.
import { QoniValidationError, type ActionKind, type AskUserAnswer, type FormValues, type Interaction, type InteractionHandle,
  type InteractionPayloadByType, type InteractionType, type OpenLoginResult } from '@qoniai/qoni'

type DemoPayload = Interaction['payload'] | undefined
// User input: an answer or form values
type UserInput = AskUserAnswer | FormValues
type Replies = Partial<Record<ActionKind, (input?: UserInput) => Promise<void>>>
ts
export interface DemoRequestCard {
  id: string                     // Stable request ID
  type: string                   // Original business type
  status: string                 // Latest server status
  title: string
  prompt?: string | null
  content: Record<string, unknown> // Application display data
  disabled: boolean              // Disable after close or submission
  buttons: {
    kind: ActionKind
    label: string                // Backend button label
    onUserClick(input?: UserInput): Promise<void> // Triggered by the user
  }[]
}

// Local, single-task demo screen. Scope production storage by user and run.
export const demoScreen = new Map<string, DemoRequestCard>()

1. Request site sign-in ​

Display sites and let the user sign in through a controlled login UI, then click the signed-in button. confirmSignedIn() requests a recheck; it does not prove login success. The controlled login UI can be the deployment's flow, or the app can open it with openLogin({ siteId }) (below).

ts
export function requestUserLogin(payload: DemoPayload, handle: InteractionHandle): void {
  // Each site has siteId, displayName and loginUrl. Integrate the deployment's controlled login UI.
  renderRequest(handle, 'Sign in to the requested sites', () => ({
    sites: payloadFor(payload, handle, 'site_login').sites,
  }), {
    // Click after signing in. The SDK saves the login openLogin() opened, then asks the Agent to recheck.
    confirm_signed_in: () => handle.confirmSignedIn(),
  })
  // Register the opener when open_login is offered; openSiteLogin() calls it only after a user click.
  // A closed or locked request invalidates pending and current logins; same-ID updates are the same request.
  const card = demoScreen.get(handle.id)
  if (card && !card.disabled && handle.can('open_login')) {
    loginOpeners.set(handle.id, (siteId, profileId) => handle.openLogin({ siteId, profileId }))
  } else {
    loginOpeners.delete(handle.id)
    invalidateLogins(handle.id)
  }
}

Open the login browser from the app. When the backend offers open_login, handle.openLogin({ siteId }) starts a controlled login browser for the site the user chose and returns liveUrl and related fields. Show liveUrl only to the current user and never log it. After the user signs in, call confirmSignedIn(): it first saves this login to the browser profile (later tasks reuse it), then asks the Agent to recheck and continue. Sign-in takes these two calls:

SituationWhat confirmSignedIn() does
The user is signed inSaves the login; the Agent rechecks and continues
The user did not actually sign inStill asks the Agent to recheck; the Agent raises a new site_login, which the app shows as a new card under a new request ID
The backend no longer holds the session (HTTP 409 no_pending_login, for example because it already saved the login)Same: asks the Agent to recheck
The backend could not save it yet (probeResult: "release_failed"; the session is kept)Throws a retryable QoniError coded site_login.save_failed and does not notify the Agent; calling it again saves again
Any other save error (for example a missing scope or a network failure)Throws a QoniError and does not notify the Agent

openLogin() and saving the login need QoniScopes.SITE_LOGIN_REQUEST and QoniScopes.SITE_LOGIN_CONFIRM respectively. Request both explicitly in scopes when delegating, and allow them in the AccessKey policy; without either one the SDK's token exchange is rejected. However many times it is called, one login session is saved once and the Agent is asked to recheck once. Handles from the same RunHandle share the login session, so confirmSignedIn() on the handle of a later callback also saves this login; a RunHandle from a new attach() does not. confirm() on the openLogin() result is deprecated and shares the same save with confirmSignedIn().

The two application functions below back the UI's open-login and finished-sign-in buttons. Finishing calls confirmSignedIn() through the same card's signed-in button, so the card's submission lock still applies. If the request has already ended when it is called, or the login session is not the latest one opened for this request, finishSiteLogin() rejects without saving the login or notifying the Agent. It also rejects while another login browser for the request is still opening; finish in the new browser once it is shown.

ts
// The app can open a controlled login browser for the chosen site; after sign-in, confirmSignedIn() saves it and asks the Agent to recheck.
const loginOpeners = new Map<string, (siteId: string, profileId?: string) => Promise<OpenLoginResult>>()
// Each request's current login: replaced only when a newer open succeeds; a failed open keeps it; finish it once.
const currentLogins = new Map<string, { attempt: number; login: OpenLoginResult }>()
// Attempt counter: a late older result never overrides a newer successful one.
const loginAttempts = new Map<string, number>()
// Bumped when the request ends or locks: every open in flight is void.
const loginEpochs = new Map<string, number>()
// Login browsers still opening: finishing meanwhile could save a login the SDK has already replaced.
const loginsOpening = new Map<string, number>()

function invalidateLogins(requestId: string): void {
  loginEpochs.set(requestId, (loginEpochs.get(requestId) ?? 0) + 1)
  currentLogins.delete(requestId)
}

function signedInButton(requestId: string) {
  // Only the current, actionable card can finish sign-in; closed or submitted cards have no button.
  const card = demoScreen.get(requestId)
  return card && !card.disabled ? card.buttons.find(button => button.kind === 'confirm_signed_in') : undefined
}

export async function openSiteLogin(requestId: string, siteId: string, profileId?: string): Promise<OpenLoginResult> {
  // siteId must come from the current card. Show the returned liveUrl only to this user; never log it.
  const card = demoScreen.get(requestId)
  const open = loginOpeners.get(requestId)
  const sites = (card?.content.sites ?? []) as { siteId: string }[]
  if (!card || card.disabled || !open) throw new Error('This request cannot open a login browser')
  if (!sites.some(site => site.siteId === siteId)) throw new Error('Choose a site listed in this request')
  const epoch = loginEpochs.get(requestId) ?? 0
  const attempt = (loginAttempts.get(requestId) ?? 0) + 1
  loginAttempts.set(requestId, attempt)
  loginsOpening.set(requestId, (loginsOpening.get(requestId) ?? 0) + 1)
  let login: OpenLoginResult
  try {
    login = await open(siteId, profileId)
  } finally {
    loginsOpening.set(requestId, (loginsOpening.get(requestId) ?? 1) - 1)
  }
  // The request ended while opening: this session does not become current.
  if ((loginEpochs.get(requestId) ?? 0) !== epoch || !signedInButton(requestId)) {
    throw new Error('This sign-in request is no longer actionable')
  }
  // A newer open already succeeded: this late result does not override it. If the newer one failed, this becomes current.
  const current = currentLogins.get(requestId)
  if (current && current.attempt > attempt) throw new Error('A newer login browser was opened')
  currentLogins.set(requestId, { attempt, login })
  return login
}

export async function finishSiteLogin(requestId: string, login: OpenLoginResult): Promise<void> {
  // Call after the user signs in at liveUrl. Only the request's latest, still-actionable login session is accepted.
  const button = signedInButton(requestId)
  if (currentLogins.get(requestId)?.login !== login || !button) throw new Error('This sign-in request is no longer actionable')
  // The user opened another login browser that is still opening: finish in the newest one once it is shown.
  if ((loginsOpening.get(requestId) ?? 0) > 0) throw new Error('Another login browser is still opening for this request')
  currentLogins.delete(requestId)
  // The "signed in" button calls confirmSignedIn(): the SDK saves this login, then the Agent rechecks and asks again if still signed out.
  await button.onUserClick()
}

2. Ask the user a question ​

Display question in a dialog and render it by answerType as a text box, number input, yes/no switch, single choice, or multiple choice; show each option's label and submit its value. Pass the user's answer to onUserClick(answer), which calls handle.answer(answer). The demo never substitutes a canned answer such as “only support issues.”

ts
export function askForTaskDetails(payload: DemoPayload, handle: InteractionHandle): void {
  // question asks for missing task details; answerType picks the control: text, number, yes/no, single or multiple choice.
  renderRequest(handle, 'Clarify the task scope or requirements', () => {
    const question = payloadFor(payload, handle, 'ask_user')
    // Options are { value, label }: show label, submit value
    return { ...question, choices: (question.options ?? []).map(option => option.value) }
  }, {
    // Submit the user's answer; its type follows answerType. The demo never generates an answer on their behalf.
    answer: value => handle.answer(value as AskUserAnswer),
    skip: () => handle.skip(), // Show only when offered
  })
}

3. Request approval ​

Display summary. Only the user's approve or reject click invokes confirm() or reject(); rendering the card does not approve the plan.

ts
export function requestUserApproval(payload: DemoPayload, handle: InteractionHandle): void {
  // summary describes the proposed operation for the user to review.
  renderRequest(handle, 'Review and approve or reject the plan', () => ({
    summary: payloadFor(payload, handle, 'confirmation').summary,
  }), {
    confirm: () => handle.confirm(), // User approves
    reject: () => handle.reject(),   // User rejects
  })
}

4. Offer browser control ​

Display liveUrl and the manual-step reason. The user clicks finished after completing the operation. The demo keeps the browser URL in card data rather than logs because it may carry access to the current browser.

ts
export function offerBrowserControl(payload: DemoPayload, handle: InteractionHandle): void {
  // liveUrl opens the browser already handed to the user; reason explains the manual step.
  renderRequest(handle, 'Complete a manual step in the browser', () => ({
    ...payloadFor(payload, handle, 'take_control'),
  }), {
    // Click when finished to hand control back. The browser URL is not written to demo logs.
    release_control: () => handle.releaseControl(),
  })
}

5. Show waiting status ​

Explain rate limiting, external conditions, or sleep, plus the optional expected recovery time. Without an offered retry action, the card is informational. When retry is offered, the user decides whether to invoke it.

ts
export function showWaitingStatus(payload: DemoPayload, handle: InteractionHandle): void {
  // waitKind is rate_limit, external or sleep; until is an optional expected end time.
  renderRequest(handle, 'Show why the task is waiting', () => ({
    ...payloadFor(payload, handle, 'wait'),
  }), {
    // Show retry only when offered and invoke it only after the user's choice.
    retry: () => handle.retry(),
  })
}

6. Collect task details ​

Render a form from fields, drawing each field by type as a text, email, phone, number, date, select or address input. Submit the values keyed by field.name; handle.submit() checks types, required fields and options before sending.

ts
export function collectTaskForm(payload: DemoPayload, handle: InteractionHandle): void {
  // fields are { name, label, type, required }: render text, email, phone, number, date, select or address inputs by type; submit values keyed by field.name.
  renderRequest(handle, 'Collect the ordinary details this task needs', () => ({
    ...payloadFor(payload, handle, 'fill_form'),
  }), {
    // Submit after the user fills the form; the SDK checks types, required fields and options before sending. Sensitive fields never go here.
    submit: values => handle.submit(values as FormValues),
    skip: () => handle.skip(), // The user declines to fill it in
  })
}

Connect user actions to SDK methods ​

buttons[].onUserClick is an application callback that invokes an actual SDK method. Pass submitted question text to the answer button callback, or invoke the selected approval button after the user's decision. Display functions never invoke these callbacks themselves.

For a question form, connect the application function submitTaskAnswer(requestId, answer): the request ID comes from the displayed request, and the answer comes from the user's control. It retrieves the latest card button, which invokes the actual handle.answer(answer). This is also application code, not an SDK method.

ts
export async function submitTaskAnswer(requestId: string, answer: AskUserAnswer): Promise<void> {
  // Application form handler: find the current card instead of retaining an old event's button.
  const button = demoScreen.get(requestId)?.buttons.find(button => button.kind === 'answer')
  if (!button) throw new Error('This request is not accepting an answer')
  // answer comes from the user's control. The callback validates it, then calls handle.answer(answer).
  return button.onUserClick(answer)
}

In a Web application, retain callbacks and SDK handles on a trusted server. The frontend displays required data and submits the request ID, action, and input to the application's own business endpoint. The server verifies the current user and run ownership, retrieves the latest request, and responds. Do not expose AK/SK or the SDK client to the browser.

The shared implementation has four responsibilities:

  1. Replace a card by id and rebuild buttons from current actions; stale buttons cannot submit.
  2. Display pending/active requests. Terminal updates clear buttons and retain original content; terminal-only replay creates no card. Closure is final, so later nonterminal replay is ignored.
  3. Validate user input and the offered action, then lock the request against double clicks and replayed submissions.
  4. Propagate submission errors without automatic retries or re-enabling old buttons. The one exception is a local SDK check that fails before sending (QoniValidationError without an HTTP status, such as text for a number question): nothing was sent, so the demo unlocks the card for the user to correct and resubmit. An error with a status came from the server after the request was sent, so the card stays locked. This local demo submits each request only once and does not automatically reopen buttons on later nonterminal events; failure is never treated as success.

One-response demo limit: SDK interaction data has no request revision number or typed method to query one interaction’s current state; updates arrive through interaction events. This demo retains its submission lock, so it cannot reopen sign-in or retry buttons when the same ID is offered again. Use Console or the deployment UI for renewed requests or uncertain submission outcomes. Production apps design recovery from server events and their own idempotency strategy. This limit belongs to the demo, not to SDK methods such as confirmSignedIn().

Shared card updates, payload narrowing, and response implementation
ts
// One-response local demo: a submitted ID stays locked. This is not an SDK restriction.
const submitted = new Set<string>()
const finished = new Set<string>()

function closeFinishedRequest(handle: InteractionHandle): boolean {
  // Closure is final. Old pending/active replay cannot revive even a terminal-only request.
  if (finished.has(handle.id)) return true
  if (handle.status === 'pending' || handle.status === 'active') return false
  finished.add(handle.id)
  const card = demoScreen.get(handle.id)
  // Terminal updates only change status; keep the original content (run handles fold them; hand-built handles may not).
  if (card) { card.status = handle.status; card.disabled = true; card.buttons = [] }
  console.log({ id: handle.id, status: handle.status, actions: [] })
  return true
}

function renderRequest(handle: InteractionHandle, scenario: string,
  content: () => Record<string, unknown>, replies: Replies): void {
  // Handle closure before reading payload; return immediately so the SDK can keep receiving events.
  if (closeFinishedRequest(handle)) return
  const card: DemoRequestCard = {
    id: handle.id, type: handle.type, status: handle.status,
    title: handle.interaction.title, prompt: handle.interaction.prompt,
    content: content(), disabled: submitted.has(handle.id), buttons: [],
  }
  if (!card.disabled) {
    card.buttons = handle.actions.filter(action => replies[action.kind]).map(action => ({
      kind: action.kind, label: action.label,
      onUserClick: input => submitUserChoice(card, handle, action.kind, input, replies[action.kind]!),
    }))
  }
  // Replace the card for this ID and rebuild buttons from the latest offered actions.
  demoScreen.set(handle.id, card)
  console.log({ scenario, id: card.id, type: card.type, status: card.status,
    title: card.title, actions: card.buttons.map(({ kind, label }) => ({ kind, label })) })
}

async function submitUserChoice(card: DemoRequestCard, handle: InteractionHandle,
  kind: ActionKind, input: UserInput | undefined, send: (input?: UserInput) => Promise<void>): Promise<void> {
  // Reject stale cards, closed requests and double clicks; the SDK also checks offered actions.
  if (demoScreen.get(card.id) !== card || card.disabled || submitted.has(card.id) || !handle.can(kind)) {
    throw new Error('This request card is no longer actionable')
  }
  // A login browser for this request is still opening: wait and finish in it (both the card button and finishSiteLogin()).
  if (kind === 'confirm_signed_in' && (loginsOpening.get(card.id) ?? 0) > 0) {
    throw new Error('Another login browser is still opening for this request')
  }
  if (kind === 'answer') {
    // Choices accept option values only (an empty string or an empty selection is legal); free text must not be blank.
    const choices = card.content.choices as string[]
    if (choices.length) {
      const picked = Array.isArray(input) ? input : [input]
      if (picked.some(value => typeof value !== 'string' || !choices.includes(value))) throw new Error('Choose an offered answer')
    } else if (input === undefined || (typeof input === 'string' && !input.trim())) {
      throw new Error('Enter an answer first')
    }
  }
  if (kind === 'submit' && (!input || typeof input !== 'object' || Array.isArray(input))) {
    // A form submission is an object keyed by field.name; the SDK validates each field.
    throw new Error('Fill in the form first')
  }
  submitted.add(card.id)
  card.disabled = true
  try {
    await send(input)
  } catch (error) {
    // A local SDK check failed before sending (QoniValidationError without an HTTP status, say text for a number):
    // nothing was sent, so unlock the card. An error with a status came from the server after sending; keep the lock.
    // Other errors may mean an uncertain POST outcome; do not retry or re-enable old buttons automatically.
    if (error instanceof QoniValidationError && error.status === undefined) { submitted.delete(card.id); card.disabled = false }
    throw error
  }
}

function payloadFor<T extends InteractionType>(payload: DemoPayload, handle: InteractionHandle,
  type: T): InteractionPayloadByType[T] {
  if (handle.type !== type || !payload || payload !== handle.interaction.payload) {
    throw new Error(`Expected a ${type} request with its SDK payload`)
  }
  // switch (request.type) narrows payload directly; these functions are dispatched by type, so check type and identity, then return it.
  return payload as InteractionPayloadByType[T]
}

Types outside the five abstract types, such as the backend's secure_input, have no typed payload. The demo directs them to Console or the deployment's specialized UI. Never treat credential requests as questions or collect passwords through answer().

ts
export function showUnsupportedRequest(_payload: DemoPayload, handle: InteractionHandle): void {
  // Types outside the five (such as the current backend's secure_input): do not read, answer or collect credentials.
  if (closeFinishedRequest(handle)) return
  const previous = demoScreen.get(handle.id)
  if (previous) { previous.status = handle.status; previous.disabled = true; previous.buttons = [] }
  console.log({ id: handle.id, type: handle.type, status: handle.status,
    nextStep: 'Use Qoni Console or the deployment-specific interaction UI' })
}

Complete InteractionHandle method table ​

handle.can(kind) checks whether this request offers an action; invoking an unoffered method throws QoniValidationError. The SDK does not replace user consent, replay handling, or application user authentication.

Methodactions[].kindPurpose and limits
can(kind)—Check whether the current request offers an action
answer(value)answerSubmit the answer to a question, typed by answerType and checked locally before sending; not passwords or new credential-reference objects
submit(values)submitSubmit a fill_form's ordinary fields keyed by field.name; types, required fields, options and address shape are checked before sending
skip()skipSubmit the user's choice to skip
confirm() / reject()confirm / rejectSubmit approval / rejection
openLogin({ siteId?, profileId? })open_loginOpens a controlled login browser for a site in payload.sites and returns an OpenLoginResult (profileId/siteId/sessionId/liveUrl/raw). siteId may be omitted when one site is listed; pass profileId to re-login an existing profile. Needs SITE_LOGIN_REQUEST
confirmSignedIn()confirm_signed_inSaves the login openLogin() opened (needs SITE_LOGIN_CONFIRM), then asks the Agent to recheck login state; without openLogin() it only asks the Agent
login.confirm({ displayLabel? })— (method on the openLogin() result)Deprecated: confirmSignedIn() saves automatically. Saves the login and ends this login session; returns a ConfirmLoginResult (profileId/active/state/probeResult/raw). Needs SITE_LOGIN_CONFIRM
connectControl()connect_controlTakes over the browser and returns a ControlSession (liveUrl/expiresAt?/status?/raw): liveUrl is the signed control URL for the user; show it only to that user
refreshControl()refresh_controlGets a new control URL when the current one expires, also as a ControlSession; later events also carry the new browser URL
releaseControl()release_controlHand browser control back after the user finishes
retry()retryRequest a retry after the user's choice

ActionKinds, InteractionTypes, and InteractionStatuses are exported constants. Controlled login and takeover also require deployment permissions. Merge updates by id; terminal notifications may change type or omit the original payload, so retain earlier business content.

Download all examples, including interaction-demo.ts, tests, and runtime dependencies. Place interaction-demo.ts beside the Quickstart script. The examples run with tsx, so imports use the .js suffix. Page code and application functions are strictly typechecked against installed declarations. Method names and low-level API membership are checked automatically.

Complete runnable example ​

This program calls GenAuth delegation and introspection, Web Search, GUMem write and recall, and DoAnything. It also uses attach() to read the same search run again. Public sources and an isolated demonstration user keep sample preferences separate from business users.

Download the complete examples, or run from the documentation repository:

bash
cd examples/qoni
npm ci
npm run sdk

The downloadable scripts require Node.js 20.11 or later; the SDK itself supports Node.js 18+.

Set server-side QONI_ACCESS_KEY and QONI_SECRET_KEY. Creating an isolated demonstration user requires GenAuth user-management access. Input handling, parsing, file output, and interaction handling are implemented in the package. npm run typecheck checks every source against the installed SDK declarations.

ts
import { QoniScopes } from '@qoniai/qoni'
import { cleanupDemoUser, cliOptions, createContext, delegate, isolateDemoUser, object, parseJsonOutput, readWithRetry, save, saveArtifacts, searchHits, settled, settleRun, withCleanup } from './runtime.js'

// Create a client from server credentials; context belongs to this sample app.
const context = await createContext('sdk', { ...cliOptions(), skipUserResolution: true })
await withCleanup(context, async register => {
  // Keep Memory writes under an isolated demo user and delete that user on exit.
  register('isolated demonstration user', () => cleanupDemoUser(context))
  await isolateDemoUser(context)
  const qoni = context.qoni
  // One delegation covers search, browser tasks, and the demo user's Memory.
  const grant = await delegate(context, 'sdk-demonstration', ['webSearch','doAnything'],
    [QoniScopes.GUMEM_MEMORY_READ, QoniScopes.GUMEM_MEMORY_WRITE, QoniScopes.GUMEM_MESSAGE_WRITE])
  const token = grant.token
  // Query effective scopes for audit; readWithRetry is the sample's read retry helper.
  const { data: tokenInfo } = await readWithRetry(context, 'delegation introspection', () => qoni.genauth.introspectDelegationToken({ token }))
  if (object(tokenInfo).active !== true) throw new Error('The delegation token is not active')

  // Find official Firefox sources, with at most three results per query.
  const search = await qoni.webSearch.run({
    token,
    prompt: 'Mozilla Firefox official features',
    maxResultsPerQuery: 3,
  })
  save(context, 'search-ref.json', { runId: search.id, auditId: grant.auditId })
  register('Web Search run', () => search.cancel('SDK demonstration cleanup'))
  // wait() reads the final result; searchHits() validates the actual results[].
  const result = await settleRun(context, search)
  save(context, 'search-result.json', result)
  settled(result)
  const hits = searchHits(result.output)
  // Reattach by the original run ID to inspect the same search after a restart.
  const attached = await qoni.webSearch.attach(search.id, { token })
  if ((await readWithRetry(context, 'attached run status', () => attached.status())).status !== 'succeeded') throw new Error('The reattached run has not succeeded')

  // Create a session for the demo user; writes and recall share its sessionId.
  const sessionId = `sdk-demonstration-${Date.now()}`
  await qoni.gumem.createSession({
    token,
    userId: context.userId,
    sessionId,
    title: 'SDK demonstration',
  })
  // Write a confirmed demo preference; sync: true requests synchronous processing.
  await qoni.gumem.addMessages({ token, userId: context.userId, sessionId, sync: true,
    messages: [{ role: 'user', content: 'For this demonstration, my confirmed preference is concise explanations.' }] })
  // Recall task-relevant preferences and verify the new concise preference is found.
  const { data: memory } = await readWithRetry(context, 'GUMem recall', () => qoni.gumem.recall({ token, sessionId,
    query: 'What confirmed explanation preference should be used?', details: true }))
  save(context, 'memory.json', { sessionId, memory })
  if (!JSON.stringify(memory).includes('concise')) throw new Error('Recall did not include the demo preference just written')

  // Ask the Agent to read the actual search results and return one sourced fact.
  const run = await qoni.doAnything.run({ token,
    prompt: `Read the actual official sources below and provide one concise, supported Firefox feature with its URL. Return only a JSON object with feature and sourceUrl. Sources: ${JSON.stringify(hits)}` })
  save(context, 'run-ref.json', { runId: run.id, session: run.sessionRef })
  register('DoAnything run', () => run.cancel('SDK demonstration cleanup'))
  // Read the settled result; saveArtifacts() downloads files with Artifact.content().
  const summary = await settleRun(context, run)
  save(context, 'result.json', summary)
  settled(summary)
  await saveArtifacts(context, summary)
  // feature and sourceUrl are app-defined fields parsed and validated here.
  const feature = object(parseJsonOutput(summary.output))
  if (typeof feature.feature !== 'string' || !feature.feature || typeof feature.sourceUrl !== 'string' || !/^https:\/\//.test(feature.sourceUrl)) {
    throw new Error('The SDK example did not return a product fact with a source URL')
  }
  // Link search, browser-task, and delegation audit IDs for source traceability.
  const report = { passed: true, dataset: 'public-demo', runId: run.id, searchRunId: search.id,
    status: summary.status, hits, memorySessionId: sessionId, output: feature,
    auditId: grant.auditId, scopes: object(tokenInfo).scope }
  save(context, 'report.json', report)
  console.log(JSON.stringify(report, null, 2))
})

Outputs and run handles ​

Web Search RunResult.output contains search results[] with fields such as title, url, and snippet; it is not a JSON generator for arbitrary prompts. Pass these results into a subsequent DoAnything task for analysis or drafting.

Current DoAnything output is commonly wrapped as { answer: string }. The application parses JSON from answer and validates required fields and sources. The full response is saved in result.json; invalid output fails instead of producing a fabricated success.

run.wait() returns RunResult with runId, status, output, artifacts, terminalReason, isTaskSuccessful, and raw. Each Artifact exposes content() to download real bytes. downloadUrl is a temporary signed URL and should not be retained or exposed in logs.

See quickstart.ts in the downloadable examples for event and callback consumption: run npm run quickstart in examples/qoni, adding -- --events to use the event stream. onInteraction receives an SDK handle. Request fields, business functions, and user responses are documented in Interaction requests and business functions.

Local verification and evidence ​

bash
npm run verify

The default command runs Quickstart, the SDK program, and 23 browser scenarios, for 25 items. It creates an isolated test user and writes a result matrix. Request statuses, run/monitor IDs, scopes, and business outputs come from real services. Missing data, unsuccessful terminal states, unresolved interactions, or invalid output yield a nonzero exit code. Demonstration execution does not claim access to actual private business accounts.

The verifier also requests every source URL cited in the output. It requests only public HTTPS addresses and checks each redirect hop. A missing or unreachable source fails the sample; an anti-bot refusal (401, 403, or 429) is recorded in the matrix as unverified rather than treated as a missing source. Idempotent reads such as introspection, run status, and Memory recall retry at most twice when the SDK marks an error retryable; creating runs, delegating, writing Memory, and responding to interactions are never retried. wait() retries the same kind of error up to twice when it reads the run detail and artifact list after the run ends; if it still fails, the examples call wait() again without callbacks to read the same run's terminal state; the run is not restarted and callbacks do not fire twice.

Source requests check HTTP reachability, not the returned page content; a challenge page with HTTP 200 can pass. Business facts still need review.

passed-unverified means SDK execution and output structure passed while at least one source could not be independently rechecked. The summary lists these scenarios separately; it does not establish factual accuracy.

The inline code blocks on this page are checked verbatim by the documentation repository's page-code verifier. It assembles the page's code in order, type-checks it strictly and runs it with a real AccessKey.

bash
# Run from the documentation repository root (after npm ci in examples/qoni)
npm run qoni:verify-doc-snippets -- --live

By default, --live runs this page's SDK programs to their verification endpoints.

Error handling ​

All SDK errors extend QoniError and carry code, status, requestId, traceId, auditId, and a retryable flag. Regular HTTP requests are not retried automatically (wait() retries its post-run detail and artifact reads up to twice); your application decides the retry policy for errors with retryable: true. The events() SSE stream reconnects according to sseMaxRetries.

Error classTriggered when
QoniValidationErrorLocal input validation fails, for example a malformed scope, silent delegation without user, or a client without an AccessKey calling a method that needs it
QoniUnsupportedErrorDeprecated operations (such as doAnything.api.readArtifacts and track.api.intervene) throw unsupported.operation locally
QoniAuthErrorThe accessKey / secretKey signature is rejected
QoniPermissionDeniedErrorThe delegation token lacks a required scope (HTTP 403)
QoniConsentRequiredErrorThe person must consent: they never consented, withdrew it, or this request asks for more than they agreed to. It is a QoniPermissionDeniedError and keeps the server's code; send the person through delegateToken({ mode: "interactive", … }) again
QoniTokenExpiredErrorThe delegation token has expired
QoniDelegationRequiredErrorA product call is missing token, or the gateway rejects the token
QoniRateLimitErrorRate limited (HTTP 429)
QoniTimeoutErrorA request or wait() times out; the run continues server-side and can be reattached with attach()
QoniUpstreamErrorA downstream product service fails

Original Quickstart delegation style ​

Since 0.8.0, qoni.genauth.delegateAgent() retains the original delegation style. Tasks still use qoni.doAnything.run({ token: grant.token, prompt }). This compatibility applies to the current @qoniai/qoni package; it does not restore old package names or nonexistent server routes.

Input or resultCurrent behavior
userId / user: { id }Required in silent mode. Existing behavior is retained: a nonempty top-level userId takes precedence, otherwise user.id is used. Supply only one form in application code
agentKey / agentSame Agent audit label. Both must agree; this is not an independent Agent identity credential
expiresIn: '15m' / 900Converted to integer seconds before signing; integer s/m/h/d durations or numeric seconds strings, between 60 and 86400 seconds
scopesExplicit scopes supported by the server. products remains available and is unioned with scopes, not used to narrow them
grant.tokengenauth.delegateAgent() returns the grant directly. Root delegateToken() retains response.data.token and meta
Legacy web.search, web.extract / deniedScopesNot supported by the delegation service; rejected rather than broadened to product permissions

Upgrading from 0.10.0 to 0.10.1 ​

0.10.1 only adds capabilities; existing code keeps working:

  • qoni.webAgentGrant({ userId, products, scopes }): on the server that keeps the AccessKey, issue one person's Web Agent token, returned as { token, expiresAt, webAgentHost, userId, scopes }.
  • new Qoni({ webAgentHost }): a client without an AccessKey that runs Web Agent only with tokens from webAgentGrant(); methods that need the AccessKey throw QoniValidationError locally. Passing only one of accessKey and secretKey still throws at construction.

See Apps that hold no AccessKey.

Upgrading from 0.9.x to 0.10.0 ​

Besides the new methods, 0.10.0 changes one behavior: a streamed reply is one message.

  • Every message event of one reply shares data.id. data.text is the whole text so far (in 0.9.x it was only the newest piece), data.delta is the new piece, and data.done marks the message complete; on completion it carries the model's stopReason, where a reason starting with tool means the agent goes on to use tools.
  • The run's answer comes once with final: true, reusing the shown reply's id when it is that reply.
  • The model's private reasoning and receipts are progress events, no longer message.

Code that concatenated each message's data.text shows the reply repeatedly after upgrading. To show a reply as it streams, update one bubble by data.id; to handle only complete messages, wait for data.done.

Migrating from versions before 0.4.0 ​

0.4.0 (2026-08-18) is a breaking rename release; the server-side wire contract is unchanged:

  • The package was renamed from @eazo/anima to @qoniai/qoni, the recommended primary constructor was consolidated as Qoni, and environment variables moved to the QONI_* prefix. The public 0.4.0 package still includes the old long-form constructor export as a compatibility alias; new code should use only Qoni.
  • Root qoni.delegateAgent / qoni.completeDelegateAgent are deprecated in favor of delegateToken / completeDelegateToken; the exchange must include the server-saved grantId (the browser callback does not carry it) and pass the callback's grant_state as state — the old { code, state } form is no longer supported.
  • Since 0.8.0, both top-level userId and user: { id } are supported; the constructor option accessKeyId is now accessKey.
  • Gateway routes remain under /api/v3/eak/*, and token claims and eak.* error codes are unchanged; applications should not construct these internal values themselves.

Publication status of other SDKs ​

As of August 19, 2026, the QoniAI GitHub organization has one public SDK repository: qoni-sdk-node. No unified Qoni SDK for Python, Java, Go, PHP, or C# is currently visible in that organization.

Product-specific GUMem, Web Agent, or GenAuth SDK references elsewhere in these docs are product integration material or historical SDKs. They do not prove that a corresponding unified SDK has been published by the QoniAI organization. Before selecting a production dependency, verify its package registry entry, source repository, and released version instead of inferring publication from an example package name.

Check the installation ​

Confirm that npm resolves the current package version:

bash
npm view @qoniai/qoni version

Then verify that the application reads QONI_ACCESS_KEY and QONI_SECRET_KEY only on the server and uses a real GenAuth user ID for silent delegation.

Next step ​