JavaScript / TypeScript SDK
@pulselabs/sdk is the official typed client for the PulseLABS API. It wraps every v1 endpoint in a fluent, namespace-based interface with full TypeScript types, automatic error handling, and an AbortSignal hook on every call.
Installation
Requires Node.js 18+ (uses the native fetch global). No peer dependencies.
Initialization
Namespaces
All methods are grouped under a namespace on the SDK instance. Every method returns a typed Promise.
Conversations & debates
Agents
Simulations
AI Manager (completion + extraction)
Error handling
Every non-2xx response throws a PulseLabsSDKError with a status code and the raw response body. Network failures throw native TypeError (same as fetch).
Cancellation
Every SDK method accepts an optional { signal: AbortSignal } second argument, forwarded directly to the underlying fetch call.
Building and publishing
The SDK lives at sdk/ at the repository root, next to backend/ and frontend/. It is a standalone npm package — it does not depend on any other package in the monorepo.
Step 1 — Install SDK dependencies
cd sdk npm install
Step 2 — Generate types from the live OpenAPI spec
The generate script fetches the OpenAPI 3.1 spec from a running backend, saves it to sdk/openapi.json, then runs @hey-api/openapi-ts to emit type definitions into sdk/src/generated/.
npm run generate. Start it with cd backend && npm run dev in another terminal first.# With default local backend (http://localhost:3001) npm run generate # Against a remote backend API_URL=https://api.pulselabs.ai npm run generate
The saved openapi.json is committed to the repo so that npm run build can succeed without a running server (useful in CI).
Step 3 — Build
npm run build # Compiles sdk/src/ → sdk/dist/ # Emits sdk/dist/index.js (CommonJS) + sdk/dist/index.d.ts (declarations)
Step 4 — Publish to npm
prepublishOnly runs generate then build automatically before every publish. You never need to run them manually before npm publish.# First publish npm publish --access public # Patch release (0.1.0 → 0.1.1) npm version patch && npm publish # Minor release (0.1.x → 0.2.0) npm version minor && npm publish
The package name is @pulselabs/sdk. Publishing requires an npm account in the pulselabs org, or change the name to a personal scope for testing.
Testing the SDK locally
There are two ways to test the SDK against a live backend without publishing it to npm.
Option A — npm link (recommended)
npm link creates a global symlink that other local projects can reference. Any change you make to the SDK is reflected immediately without re-publishing.
# 1. Register the SDK globally
cd sdk
npm run build
npm link
# 2. In your test project, link to it
cd /path/to/your-test-project
npm link @pulselabs/sdk
# 3. Use it like a published package
import { PulseLabsSDK } from '@pulselabs/sdk'
# 4. When done, unlink
npm unlink @pulselabs/sdkOption B — Direct import via relative path
For a quick smoke test inside the same repository, import from the dist/ folder directly. No linking required.
# Build the SDK first
cd sdk && npm run build
# Then from a test script at the repo root:
node -e "
const { PulseLabsSDK } = require('./sdk/dist/index.js')
const pulse = new PulseLabsSDK({
apiKey: 'sk_live_xxx',
baseUrl: 'http://localhost:3001',
})
pulse.conversations.list().then(d => console.log(d))
"Option C — ts-node against the source
If you are developing the SDK itself and want to test without a build step, run TypeScript directly:
cd sdk
npx ts-node -e "
import { PulseLabsSDK } from './src/index'
const pulse = new PulseLabsSDK({
apiKey: 'sk_live_xxx',
baseUrl: 'http://localhost:3001',
})
async function main() {
const { conversations } = await pulse.conversations.list()
console.log('Conversations:', conversations.length)
const { agent } = await pulse.agents.create({
name: 'Test Agent',
role: 'Analyst',
personality: 'Sharp',
mission: 'Test',
decisionStyle: 'data-driven',
systemPrompt: 'You are a test agent.',
})
console.log('Created agent:', agent.id)
await pulse.agents.delete(agent.id)
console.log('Deleted agent')
}
main().catch(console.error)
"Keeping the SDK in sync with the API
Whenever new endpoints are added to the backend, the SDK needs two updates:
openapi.json is the source of truth for what types the SDK ships with. Pin your CI pipeline to regenerate it from the production API URL on every release tag to guarantee it stays current.Quick reference
sdk/
├── package.json # name: @pulselabs/sdk, version: 0.1.0
├── tsconfig.json # targets CommonJS ES2020, emits to dist/
├── openapi.json # committed snapshot of the API spec
├── scripts/
│ └── generate.ts # fetches spec → runs @hey-api/openapi-ts
└── src/
├── index.ts # PulseLabsSDK class + all namespace classes
└── generated/ # auto-generated types (do not edit manually)
Scripts
npm run generate # regenerate types from a running backend
npm run build # tsc → dist/
npm publish # generate + build + publish to npm