Skip to content

TypeScript integration

Use Node 24 or newer, as declared by this release. Install the downloaded aiws-sdk-0.5.0.tgz with npm, or run npm ci and npm run build:sdk in the source workspace. The package is ESM. This is a native Node library; the SQLite/runtime modules are not browser APIs.

The package exports these paths:

Import path Contents
@aiws/sdk Core records and semantics: parseContract, parseCommand, reduce, canonical, AiwsError, graph validation and scheduling, and the protocol-correlation helper
@aiws/sdk/runtime Coordinator and the Authorizer and EffectAdapter boundaries
@aiws/sdk/sqlite SqliteStore and importAudit
@aiws/sdk/observability Event envelopes, operationalSummary, metric payloads and OtlpHttpExporter (observability)
@aiws/sdk/handoff The opt-in handoff profile: HandoffStore, HandoffCoordinator, FileArtifacts and its checked records (handoffs)
@aiws/sdk/limits Opt-in nested limits: LimitStore and LimitCoordinator (budgets)
@aiws/sdk/dynamic-controls The aiws-dynamic-controls/1 client: DynamicClient, dynamicRequest, dynamicHttpsTransport (dynamic controls)
@aiws/sdk/readiness Advisory readiness records: evaluateReadiness, manifestDigest, decodeReadiness (readiness)
@aiws/sdk/access-policy The access-policy contract codec: decodeAccessPolicy, encodeAccessPolicy, accessPolicyDigest (access policy)
@aiws/sdk/protocol The protocol-correlation records alone: protocolCorrelation and validateProtocolCorrelation

Execute an adapter through the trusted coordinator · Executable local adapter demonstration; fixed demo identity and fixture evidence

import { readFileSync, writeFileSync, mkdtempSync, openSync, writeSync, fsyncSync, closeSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { parseContract, parseCommand, canonical, assessSuccess } from '@aiws/sdk';
import { SqliteStore } from '@aiws/sdk/sqlite';
import { Coordinator, type EffectAdapter } from '@aiws/sdk/runtime';
// A local demonstration. Replace this fixed demo identity with authenticated policy.
const demo = JSON.parse(readFileSync('examples/review.json', 'utf8'));
const directory = mkdtempSync(join(tmpdir(), 'aiws-review-'));
const store = new SqliteStore(join(directory, 'mission.db'), parseContract(canonical(demo.contract)));
const coordinator = new Coordinator(store, async () => ({ allowed: true, policy: 'ALLOW', mandatoryChecksOk: true,context:{actor:"demo:operator",policyRevision:"policy:1",decisionClass:"DETERMINISTIC"} }), () => '10');
const adapter: EffectAdapter = {
async execute(operation) {
const file = openSync(join(directory, 'review.txt'), 'wx');
try { writeSync(file, canonical(operation.action.payload)); fsyncSync(file); } finally { closeSync(file); }
return { effect: 'CONFIRMED_APPLIED', actualCost: '3' };
},
async reconcile(operation) { try {
return readFileSync(join(directory, 'review.txt'), 'utf8') === canonical(operation.action.payload) ? { effect: 'CONFIRMED_APPLIED', actualCost: '3' } : { effect: 'UNKNOWN', actualCost: '0' };
}
catch {
return { effect: 'UNKNOWN', actualCost: '0' };
} }
};
try {
for (const raw of demo.commands) {
const command = parseCommand(canonical(raw));
if (command.type === 'dispatch')
await coordinator.dispatch(command.attemptId, adapter, command.nodeId);
else
await coordinator.apply(command);
}
console.log(JSON.stringify({ directory, ...assessSuccess(store.snapshot(), 'r') }));
writeFileSync(join(directory, 'audit.json'), store.exportAudit());
}
finally {
store.close();
}

The full program uses a local adapter, fixed trusted demo identity and fixture evidence. Replace those three boundaries with real identity, a scoped adapter and measured validation evidence before using this pattern in production. The tab set includes equivalent Rust, TypeScript and Python implementations.

SDK 0.5.1 includes a small protocol-correlation helper that the earlier 0.3.0 packages lack. It records the exact Praxis binding revision and remote identity alongside the AIWS work/run/operation/attempt identity. It does not implement MCP, A2A or AG-UI transport behavior and always validates authoritative: false.

Correlate governed work with a protocol binding · Executable source-only SDK correlation example; no protocol client or authority is created

import assert from 'node:assert/strict';
import {createMission,parseContract,reduce,protocolCorrelation,validateProtocolCorrelation} from '@aiws/sdk';
const contract=parseContract(JSON.stringify({id:'contract:protocol',missionId:'mission:protocol',aiwsEdition:'0.4',profile:'finite-v1',budget:'20',deadline:'1000',criteria:['remote-result-reviewed'],actions:['remote.invoke'],resources:['protocol:mcp'],requiresApproval:false,maxAttempts:'2',maxAuthorizationAgeMs:'100',features:[]}));
let state=createMission(contract);
state=reduce(state,{type:'startRun',runId:'run:1'},'10');
state=reduce(state,{type:'grant',grant:{id:'grant:1',subject:'agent:1',profile:'finite-v1',actions:['remote.invoke'],resources:['protocol:mcp'],notBefore:'0',expiresAt:'1000',limit:'20',canDelegate:false,depth:'0'}},'10');
state=reduce(state,{type:'admit',runId:'run:1',operationId:'operation:1',attemptId:'attempt:1',grantId:'grant:1',subject:'agent:1',action:{capability:'remote.invoke',resource:'protocol:mcp',payload:{tool:'echo'},preconditions:{}},amount:'5',authorizationCheckedAt:'10',policy:'ALLOW',mandatoryChecksOk:true},'10');
const correlation=protocolCorrelation(
{bindingId:'mcp:official-v2',bindingRevision:'1',protocol:'MCP',protocolVersion:'2026-07-28',manifestDigest:'a'.repeat(64),capabilityDigest:'b'.repeat(64)},
{workOrderId:'mission:protocol',runId:'run:1',taskId:null,operationId:'operation:1',attemptId:'attempt:1',remoteIdentityRef:'mcp:praxis-m9-fixture@1.0.0',remoteOperationId:null}
);
assert.equal(correlation.operation.operationId,'operation:1');
assert.equal(correlation.authoritative,false);
assert.equal(state.operations['operation:1'].runId,'run:1');
// The record is portable JSON: read back from the wire, it passes the same closed check unchanged.
const wire=JSON.parse(JSON.stringify(correlation));
assert.deepEqual(validateProtocolCorrelation(wire),correlation);
// A record that claims authority, or carries a key the schema does not define, is refused.
const refused=(e:any)=>e.code==='INVALID_PROTOCOL_CORRELATION';
assert.throws(()=>validateProtocolCorrelation({...wire,authoritative:true}),refused);
assert.throws(()=>validateProtocolCorrelation({...wire,approved:true}),refused);
console.log(JSON.stringify(correlation));
console.log('PASS: protocol-correlation');

In current source, after the 0.4.0 archives, validateProtocolCorrelation takes an exact key set at every level of the record and reports the same error codes as Rust and Python, in the same order; see the API mapping.

Use official protocol SDKs and the Praxis adapters for wire behavior. Use this helper only for portable correlation in application code, evidence indexes or integration metadata.

TypeScript annotations do not validate external JSON. Use parseContract and parseCommand on original input text. Preserve amounts and times as strings; convert to BigInt only for local exact calculations, then serialize back to canonical decimal strings. Do not JSON.stringify a BigInt directly.

The Authorizer callback and EffectAdapter methods are asynchronous. The Clock is synchronous, () => string, and returns UTC epoch milliseconds as a canonical decimal string. Current source exports Clock by name from @aiws/sdk/runtime beside Authorizer and EffectAdapter. Await apply, dispatch, reconcile and flushTelemetry, and retain errors at the host boundary. Snapshot and SQLite methods are synchronous. Long-running blocking adapters belong in a suitable worker, and cancellation of a JavaScript promise is not proof that an external effect stopped.

Use AiwsError.code to decide how to report a failure. A REVISION_CONFLICT requires a fresh state/policy decision. An UNKNOWN outcome requires human-controlled reconciliation. Neither should be handled by a generic retry-every-exception wrapper.

The source workspace’s Node 24 examples execute TypeScript directly. Applications may instead compile with their own TypeScript build. The package contains declarations; source example execution and static type checking are separate verification steps.

Use the API mapping to translate native calls without changing camelCase wire keys. Use observability for exporter configuration and recovery for interrupted effects. All examples are included as individual executable source files under examples/guide/.

The package’s aiws CLI offers aiws validate FILE for a contract, aiws graph FILE for a graph, aiws replay FILE for an audit export, aiws fixtures FILE for a shared scenario file, and aiws snapshot FILE and aiws observe FILE for a SQLite mission database. It also provides aiws agents sync to copy the version-matched agent docs pack into .aiws/agent-docs/typescript/ and update the managed AGENTS.md block, and aiws agents check to verify that the pack, the block and the synced skills match the installed SDK version. Sync also installs the aiws skills shipped beside the pack in dist/skills/: it copies each aiws-* skill folder into .claude/skills/ and .agents/skills/, writes a .gitignore containing * inside each copied folder, so the copies are never committed and your own skills beside them are untouched, and records the SDK version in the folder’s .aiws-skill.json. When the installed skills are at another version and another language’s synced pack in .aiws/agent-docs/ also differs from this SDK, sync still syncs the TypeScript pack, leaves the skills unchanged and prints one stderr line naming both versions; aiws agents check exits 1 until the skills match. The installed skills’ version is read from the stamps of the aiws-* skills present in either folder, so the rule holds when this SDK ships a skill the installed set lacks. Sync refuses with FILE_ERROR, before writing anything, when .aiws, AGENTS.md, .claude, .agents, their skills folders or a synced skill folder is a symlink or junction. Its output, error codes and exit statuses match the Rust and Python CLIs (command-line tools). In the 0.4.0 archives it has only validate, graph and replay. Its observe projection uses a fixed test timestamp and is not a live monitoring service. Run operationalSummary with a trusted current timestamp in your application instead.