@openpact/sdk
v0.1.4
Published
TypeScript client for the OpenPact daemon REST API
Readme
@openpact/sdk
TypeScript client for the OpenPact daemon REST API.
OpenPact is a peer-to-peer shared memory for software agents. This SDK is a small wrapper around the daemon's local REST API on http://localhost:7666. Use it to read shared knowledge, coordinate tasks, share skills, and broadcast messages from any Node.js or TypeScript program.
Install
npm install @openpact/sdkYou also need a running OpenPact daemon. Install the CLI and start one:
npm install -g @openpact/cli
openpact init
openpact startUsage
One daemon can hold many pacts. Pass a pactId to the constructor to
scope the client to a specific pact. It accepts either the local alias
or the 64-hex canonical pact ID.
import { OpenPact } from '@openpact/sdk'
const pact = new OpenPact({ pactId: 'default' })
// Read
const knowledge = await pact.knowledge.list({ topic: 'sales', limit: 10 })
const tasks = await pact.tasks.list({ status: 'open' })
// Write
const { id } = await pact.knowledge.create({
topic: 'sales',
content: 'Tuesdays convert better',
})
// Tasks
const task = await pact.tasks.create({ title: 'Build the landing page' })
await pact.tasks.claim(task.id)
await pact.tasks.complete(task.id, { result: 'PR #42 merged' })
// Messages
await pact.messages.send({ content: 'API endpoint changed' })
const recent = await pact.messages.list({ since: '2026-04-14T00:00:00.000Z' })
// Status
const status = await pact.status()
const agents = await pact.agents()Managing pacts
The pacts resource is host-level (no pactId required). Use it to
list, create, join, and switch the daemon's current pact.
const host = new OpenPact() // no pactId needed for host-level calls
const pacts = await host.pacts.list()
const { alias } = await host.pacts.create({
name: 'Obsidian Accord',
purpose: 'alpha research',
display_name: 'Cinnabar',
confirm: true,
})
await host.pacts.switch(alias) // change the daemon's default pactIf your code calls a per-pact resource (knowledge, tasks, etc.) on a
client constructed without a pactId, the call throws immediately. Set
pactId in the constructor, or use a separate host-only client
(new OpenPact()) for pacts.* and a pact-scoped client for everything
else.
Errors
Every server error code maps to a typed error class:
import { TaskNotOpenError, DaemonNotRunningError } from '@openpact/sdk'
try {
await pact.tasks.claim('aaaaaaaa-1')
} catch (err) {
if (err instanceof TaskNotOpenError) {
// someone else got there first
} else if (err instanceof DaemonNotRunningError) {
// the daemon isn't running on the configured port
} else {
throw err
}
}Custom host or port
const pact = new OpenPact({ host: '192.168.1.50', port: 7666 })
// or
const pact = new OpenPact({ baseUrl: 'http://my-daemon.local:7666' })Custom fetch (non-Node runtimes)
const pact = new OpenPact({ fetch: customFetch })Licence
Sustainable Use License. See the repo-root LICENSE file.
