A small client for the hosted ComputerWorld API at https://computaco.ai/v1.
One ES module with no dependencies, for Node 18 or later and browsers, with TypeScript
declarations beside it. The contract is openapi.yaml; the
guide is the hosted API docs, and
the clients guide covers this client and the Python one together.
Get an API key at https://computaco.ai/console/create-account.html.
npm install computerworld-cloud # then: import { Client } from 'computerworld-cloud'Or take the one file, computerworld-cloud.mjs, from a URL (browsers, Deno; pin a tag or commit for anything lasting):
import { Client } from 'https://cdn.jsdelivr.net/gh/ComputaCo/computerworld@main/computerworld-cloud.mjs';pip install computerworld-cloudSee python/README.md.
This repository is where the clients of the hosted API are written, and the home of the engine's release assets
(engine-v0.3.0). The engine's open-core source — the simulator, the SDK and module ABI, the
application catalog, the fidelity tooling — is
ComputaCo/computaco-core-public, MIT.
import { Client } from 'computerworld-cloud';
const client = new Client(); // COMPUTERWORLD_API_KEY / COMPUTERWORLD_API_BASE, or new Client('cw_live_…', { baseUrl })
const simulation = await client.createSimulation('agent-desktop', { seed: 1 });
try {
const agent = await simulation.agent(); // an external agent; holds the actor token
await agent.click({ interaction: 'shell:launch:editor' }); // find in the scene, click its centre
await agent.click({ role: 'textbox', label: 'Document text' });
await agent.typeText('Hello');
const frame = await agent.render(); // { bytes: Uint8Array (PNG), etag, stateHash, tick, ... }
const fork = await simulation.fork(); // same state hash, the agents under new tokens
const run = await fork.run('agent-desktop/legal-engagement', { seed: 1 });
console.log(run.verification.passed, await fork.stateHash());
await fork.delete();
} finally {
await simulation.delete();
}Five words name everything here:
- A template is a world definition you start a simulation from: built in, or one of
your organization's own.
listTemplates,getTemplate,createTemplate,updateTemplate,deleteTemplate,templateTopology,editTemplateTopology; a built-in template's expert procedures (templateProcedures,templateProcedure,instantiate) and societies (templateSocieties,templateSociety);vocabularyandvalidate. - An simulation is one running world.
createSimulation(template, { seed, name, platform, society, idleTtl, place }), or{ definition }in place of a template;listSimulations,getSimulation,importSimulation(bundle, name, { place }).placesays where it runs:'lightning'or'heavy'(or a Lightning place's id:'core','office','media'), or a list tried in order; left out, Lightning first.info.placeanswers where it runs and why,info.refusedthe places that refused it. On anSimulation:rename,delete,readFile/writeFile,clock/stateHash,advance('30s'),reset,inspect,definition,trajectory,serviceState/patchServiceState,asks/answerAsks,topology,addComputer/removeComputer,snapshot/snapshots/restore(the agents and their conversations become the snapshot's) /snapshotAgents(snapshot)/snapshotMessages(snapshot, agent)(what a snapshot kept) /dropSnapshot(resolves to{ snapshots, head }),snapshotFrame(snapshot, machine)(the PNG of a machine's screen at a snapshot),history(the family's snapshots, forks and heads),exportSnapshot, and the expert procedures:stage,project,verify,run. - An agent acts in a simulation.
simulation.agent(config)makes an external one (your code, Computatrum) and returns anAgentholding its actor token, withstep,observe,sceneandrender(PNG bytes;format: 'rgba'for raw).simulation.agents()lists every agent: the external ones and, with a society, its simulated people (kind: 'simulated', no token).simulation.getAgent(id)andsimulation.revoke(agent);simulation.connectAgent(agent, machine)anddisconnectAgent(agent, machine)connect it to a machine and disconnect it (it keeps its id, token and thread);simulation.perform(agent, gesture)does one grounded gesture. - A society is the simulated people of a simulation, chosen when it boots
(
createSimulation('company-2026', { society: { id: 'rumor-cascade', journal: 'builtin' } })).simulation.societyhasinfo,runRounds(count, { askModel }),journal/addJournal,trace({ since })andsummary. - A fork is a simulation copied from another as it is now:
simulation.fork({ name, snapshot, societyOps, place }); left to itself it runs where its parent does. Itsinfo.forked_fromnames the parent and the parent'sforks()lists them; each fork runs its own society rounds, andsociety.summary()on the parent compares the outcomes per round of every fork.
What else is here:
- Accounts.
me,updateMe,setEmail/verifyEmail,usage,listKeys/createKey(name, { scopes })/revokeKey,Client.signup(username, password, { scopes })(makes the account, then one key with its session; resolves to{ client, user, key }), and the agent models on OpenAI's paths (models,chat). A key'sscopesare any ofsimulations,templates,models,accountandresearch, every one when left out. - Finding elements.
agent.find({ label, role, interaction, value, index })resolves to the frontmost interactive element matching every field given (a string matches exactly, aRegExpbytest);findAllto all of them; a miss throwsElementNotFoundnaming what is on screen.agent.click({...})takesx, y, anelement, or the same fields;press('Ctrl+S')andtypeTextround it out. These helpers throwActionFailedon an unsuccessful outcome (check: falseto not).findElements(scene, query)andcenter(element)work on a scene already held. - Agents without the owner's key.
Agent.connect(token, simulationId, agentId)makes a handle from an actor token alone: step, observe, scene and render, nothing else. - Retries. A 429, or a 503 with
Retry-After, is retried for any method; a 500, 502, 504, a 503 withoutRetry-After(a failure on our side) or a network failure only for GET, PUT and DELETE (a POST that may have changed the simulation is not sent twice). The wait isRetry-Afterwhen the API sends one, otherwise an exponential backoff from 500 ms (jittered, at most 30 s); four retries by default (maxRetries), and aRetry-Afterover 120 s is thrown at once instead of waited. - Errors.
ApiErrorcarriesstatus,code(the API's:not_found,rate_limited,quota_exceeded,invalid_definition, …),detail(its message),retryAfter,methodandpath; an answer that is not the API's JSON ishttp_<status>. A request that gets no answer isConnectionFailed. - User-Agent. In Node (and Bun and Deno) every request sends
computerworld-cloud-js/<version>, with youruserAgentin front. A browser sends its own: a cross-originfetchmay not setUser-Agent, and Cloudflare accepts browsers'. - Cleanup.
SimulationimplementsSymbol.asyncDispose, so whereawait usingis available,await using simulation = await client.createSimulation(...)deletes the simulation at the end of the block.
npm test # offline, against a local mock (test/mock-server.mjs)
COMPUTERWORLD_API_KEY=cw_live_… npm run test:live
npm run typecheck # tsc over test/types.check.mts (needs typescript)The live test boots agent-desktop, clicks the editor's launcher, types, renders a PNG,
forks, runs legal-engagement in the fork, deletes both simulations and checks they are gone,
printing client-side timings.