Copilotz
One runtime for agents and the apps around them, on Node, Deno, Bun, Cloudflare Workers and the
browser.
An app is plugins: agents that answer with tools and talk to each other and to people, conversations
in shared spaces, memory, skills and routines, a usage ledger, people's computers, sign-in and
connected accounts, a developer API, WhatsApp. Each is a plain object built from the same few
primitives (collections, Actions, Processors, Views, resources and adapters), and the runtime knows
nothing else. Everything durable is an event, a document, an edge, a vector or a blob, written by
one owner to one store (memory, SQLite or PostgreSQL), so every change is on the record and every
screen follows it live: in a terminal, in a browser, or in an agent's prompt.
Install
npm install copilotz # Node 24+ (npm, pnpm, yarn)
bun add copilotz # Bun
deno add jsr:@copilotz/copilotz # Deno (or `deno add npm:copilotz`)
On Deno, name it copilotz in deno.json ("copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.1"), and
the imports below are the same everywhere. Some pieces need a package of their own, installed beside
it: esbuild to bundle the web host on Node, @electric-sql/pglite for PostgreSQL in the process,
and @types/react for the front ends' types.
A first app
import { createRuntime, definePlugin } from "copilotz";
import { memoryStore } from "copilotz/stores/memory";
import { models } from "copilotz/plugins/models";
import { chat, type Message, tool } from "copilotz/plugins/agents";
// An app's own plugin is plain objects: a provider, an agent, a tool.
const app = definePlugin({
name: "app",
resources: {
provider: { openai: { apiKey: process.env.OPENAI_API_KEY } },
// "fake/echo" runs offline (it calls a tool you name); "openai/gpt-5.4-mini" with the key.
agents: { assistant: { instructions: "Be brief.", model: "fake/echo", tools: ["clock"] } },
tools: { clock: tool({ description: "The time now.", run: () => new Date().toString() }) },
},
});
const runtime = await createRuntime({ store: memoryStore(), plugins: [models, chat, app] });
const { thread } = await runtime.call<{ thread: string }>("chat.send", {
text: "What does the clock say?",
});
await runtime.idle();
for (const { from, text } of await runtime.query<Message[]>("message.history", { thread })) {
if (text) console.log(`${from}: ${text}`);
}
await runtime.close();
node app.ts (or bun app.ts, deno run -A app.ts) prints the question and the agent's answer.
Swap memoryStore() for sqliteStore({ path }) or postgresStore({ url }) to keep it, add
history and memory to the plugins for long conversations and recall across them, access for
people and spaces, and serve it to browsers with the web host (below).
The primitives
The runtime knows only these, and plugins are made of them:
- Collections: documents with a JSON Schema, read and written with the MongoDB collection API
(
ctx.db.collection("note").insertOne(…), find, updateOne with $set…), with named queries,
vector fields and indexes. Every write records an event in the same commit.
- Actions: what can be done, with a JSON Schema input and an
allow(actor, input) saying who
may call them. Every call is on the record (action.started, action.completed), retryable by
id, and everything it causes is its caller's.
- Processors: what happens when events happen: ordered per key, at least once, from a durable
cursor, idempotent by deterministic ids.
- Views: a plugin's front end, per medium: text for
llm (the agents' prompt is a View), Ink
elements for terminal, React for web. Observed Views run again when what they read changes.
- Resources: configuration as named plain objects, by kind (
agents, tools, provider,
theme…): a later plugin patches an earlier one's (JSON Merge Patch), so an app changes one
agent's effort without redefining it.
- Adapters: implementations of a port, by name: a model provider's protocol (
openai,
anthropic…), an embeddings or transcription service.
Plugins reach each other only through the runtime, by name: Actions, resource kinds and declared
events. Time is a caller too: schedules call Actions (see Schedules).
Using it
The package's entry points, the same names on npm (copilotz/…) and JSR (@copilotz/copilotz/…):
| Import |
What it has |
copilotz |
the runtime: createRuntime, definePlugin, defineCollection, defineAction… |
copilotz/stores/memory |
memoryStore(): in memory, the reference |
copilotz/stores/sqlite |
sqliteStore({ path }): node:sqlite or bun:sqlite, one file |
copilotz/stores/postgres |
postgresStore({ url, schema, tenant }) (a server, or PGlite in the process), postgresPool, copyTenant… |
copilotz/stores/latency |
withLatency(store, ms): a store with round trips, to measure |
copilotz/blobs/files |
fileBlobs({ dir }): blobs as files |
copilotz/blobs/http |
httpBlobs({ url, headers }): blobs in a bucket (S3, GCS, R2…) |
copilotz/plugins/models |
models: llm, embeddings, transcription, the models.dev catalog |
copilotz/plugins/agents |
chat, history, memory, memoryExtraction, team, skills, routines, tool |
copilotz/plugins/agents/web |
their web front ends: chatWeb, teamWeb, memoryWeb, skillsWeb, routinesWeb |
copilotz/plugins/agents/terminal |
their terminal front ends: chatTerminal, memoryTerminal |
copilotz/plugins/access |
access (spaces, identity), accounts, directory, googleSignIn |
copilotz/plugins/access/web |
spacesWeb, accountsWeb |
copilotz/plugins/access/terminal |
accessTerminal |
copilotz/plugins/billing |
usage: the ledger |
copilotz/plugins/billing/web |
usageWeb |
copilotz/plugins/billing/terminal |
usageTerminal |
copilotz/plugins/compute |
computers: people's computers, where agents work |
copilotz/plugins/compute/web |
computersWeb |
copilotz/plugins/compute/terminal |
computersTerminal |
copilotz/plugins/compute/downloads |
computerDownloads: the computer program's release, served by the app (Node) |
copilotz/plugins/interfaces |
terminalPlugin (the terminal's data), api, whatsapp |
copilotz/plugins/interfaces/web |
webShell (the web's root View), apiWeb, whatsappWeb |
copilotz/plugins/interfaces/terminal |
terminalShell: the terminal's root View |
copilotz/web |
the web host in the browser (web), and its toolkit (Button, Markdown…) |
copilotz/web/server |
its server half: webServer, socket |
copilotz/web/tickets |
createTickets: sessions traded for one-time tickets |
copilotz/web/theme |
themeOf(plugins): the app's theme, for the page's first paint |
copilotz/web/node |
bundle (the browser's code, with esbuild), serve, listen (HTTP, sockets) |
copilotz/orgs |
orgsHost: many orgs behind one address, each a runtime of its own |
copilotz/terminal |
the terminal host: terminal({ runtime, me }), and its toolkit |
copilotz/exporters |
otlp, exposition: metrics out, the OpenTelemetry way |
copilotz/testing |
one test API for Deno, Node and Bun (test, tempDir, serve…) |
The browser loads only copilotz/web, the …/web front ends and what they import; every other
entry point is for the process that runs the runtime (or the terminal). The npm package is
JavaScript with its types beside it, so an app's bundler takes the front ends as they are.
Serve it on the web
The web host runs the app's front ends in the browser, as the person signed in: their reads go to
the owner under the access rules, and every change is pushed to them as it commits. The server half
answers Requests with Responses and nothing else, so it runs on any runtime; the page's code is
the app's own (its front ends), bundled. On Node:
// server.ts
import { createRuntime } from "copilotz";
import { memoryStore } from "copilotz/stores/memory";
import { socket } from "copilotz/web/server";
import { createTickets } from "copilotz/web/tickets";
import { themeOf } from "copilotz/web/theme";
import { bundle, serve } from "copilotz/web/node";
import { plugins } from "./app.ts"; // models, chat, access, … and the app's own
const tickets = createTickets();
const runtime = await createRuntime({
store: memoryStore(),
plugins,
transports: [socket], // browsers connect to the owner here
admit: tickets.admit,
});
const server = await serve({
runtime,
tickets,
code: await bundle(new URL("./browser.tsx", import.meta.url)),
theme: themeOf([]), // Copilotz's look; a brand passes its theme plugins
port: 8080,
dev: true, // sign in by name, from this machine only
});
console.log(`${server.url}`);
// browser.tsx
import { web } from "copilotz/web";
import { webShell } from "copilotz/plugins/interfaces/web";
import { chatWeb, memoryWeb, teamWeb } from "copilotz/plugins/agents/web";
import { spacesWeb } from "copilotz/plugins/access/web";
await web({
root: document.getElementById("app")!,
plugins: [webShell, chatWeb, spacesWeb, teamWeb, memoryWeb],
start: async (client) => ({
space: (await client.call<{ space: string }>("space.personal", {})).space,
}),
});
bundle splits the code where it imports lazily (math, a terminal), and serve takes browsers'
sockets through Oxian's Node adapter; Bun and Deno run it too. On Deno,
Deno.serve(webServer({ …, upgrade: handler(runtime.hypervisor) })) with Oxian's Deno adapter, and
deno bundle for the code (examples/terminal-agent/web.ts). The whole example is in
examples/web-node/ (node examples/web-node/server.ts).
Many orgs behind one address (copilotz/orgs, see design/tenancy.md): a
directory signs people in and knows their orgs, and each org is a runtime of its own, opened when
first used. Node takes a socket before any handler runs, so listen serves the orgs host and hands
each socket to the runtime of the org its request is for:
listen({ fetch: host.serve, hypervisor: (request) => host.openRuntime(request)?.hypervisor })
(examples/web-node/orgs.ts).
Installing a computer
People's computers run the computer program (plugins/compute/computers/program/), a single
executable for macOS, Linux and Windows that an app serves from its own origin once it's built:
node scripts/computer/build.ts # dist/computer/<version>/: a binary per platform (by Bun),
# install.sh, install.ps1, manifest.json (sizes, SHA-256)
import { computerDownloads } from "copilotz/plugins/compute/downloads";
plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.1" })], // /computer/download/
plugins: [...plugins, await computerDownloads({ url: "https://…/releases/download/…/" })], // or elsewhere
A space's Computer tab (or /computer connect) then gives the one line to run on the machine, for
its system, with a one-time code in it (and the binaries, to download instead):
curl -fsSL https://app.example.com/computer/download/install.sh | sh -s -- https://app.example.com --code K7Q-4MZ
& ([scriptblock]::Create((irm https://app.example.com/computer/download/install.ps1))) https://app.example.com -Code K7Q-4MZ
It downloads that machine's binary, checks its SHA-256 against the release's manifest, puts it in
~/.copilotz/bin (%LOCALAPPDATA%\Copilotz\bin) on the PATH, connects it with the code, and keeps
it running from login on: a launchd agent on macOS, a systemd user unit on Linux, a scheduled task
on Windows. On that machine, computer uninstall stops it (computer install starts it again),
computer forget forgets it, and computer run runs it in the foreground instead. Its commands run
in bash, or on Windows in PowerShell (7 when it's there, else 5.1); agents are told which. A
computer older than the app's release updates itself as it connects: the app tells it the version,
and its binary's URL, size and SHA-256; it checks them, and that the new one runs, swaps it in and
starts again. The binaries aren't signed yet, so macOS and Windows warn about one downloaded with a
browser; the line doesn't need that.
Plugins
Plugins come in themes. Every plugin is a plain object, and its settings are a resource under its
own name, which the app patches like any resource:
plugins: [
models,
chat,
history,
memory,
usage,
definePlugin({
name: "app",
resources: { history: { summarizer: "cheap" }, memory: { embedder: "small" }, agents: { … } },
}),
];
Inside a theme, each plugin is laid out by primitive: collections/, actions/, events/,
processors/, views/, resources/, adapters/, one file per declaration, with shared/ for
what several use; its mod.ts only assembles them. Its front ends are its own (web.tsx,
terminal.ts), loaded only where they draw, and the theme gathers them (plugins/agents/web.tsx).
Tests sit next to their theme (plugins/<theme>/tests/).
A plugin reaches another only through the runtime, by name, in three ways:
- ask it to do something: its Actions (
ctx.call("llm.stream", …));
- plug into it: the resource kinds it reads (chat's
tools and context, models' modelUse,
the terminal's commands, the web host's routes);
- hear what it announces: its declared events, with Processors (
message.created,
turn.requested).