MCPcopy Index your code
hub / github.com/unicity-astrid/sdk-js

github.com/unicity-astrid/sdk-js @v0.1.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.1.0 ↗
543 symbols 1,112 edges 36 files 47 documented · 9% 4 cross-repo links
README

sdk-js

License: MIT OR Apache-2.0 Node: >=20 TypeScript: 5.2+

The JavaScript / TypeScript SDK for building Astrid capsules.

Companion to sdk-rust. Same WIT contract, same wasip2 Component Model output, same .capsule archive format — your kernel can't tell which language built the binary. Where the Rust SDK feels like writing against std, this one feels like writing against node:fs/promises / WHATWG / Node's EventEmitter. Same host ABI, idiom translated.

Packages

Package Role
@unicity-astrid/sdk The capsule author API. Module-by-module mirror of astrid-sdk's preludefs, net, process, env, time, log, plus Astrid-specific ipc, kv, http, hooks, uplink, identity, approval, runtime, elicit, capabilities, interceptors. TypeScript decorators (@capsule, @tool, @interceptor, @command, @install, @upgrade, @run) replace #[capsule].
@unicity-astrid/build Build orchestrator. Runs tsc + esbuild + ComponentizeJS programmatic API. Emits a wasm32-wasip2 component that the Rust-side astrid-build packs into a .capsule archive.
@unicity-astrid/sdk/contracts Auto-generated TS types from astrid-contracts.wit — IPC event types (Message, ToolCall, GenerateRequest, StreamEvent, etc.) usable on both ends of cross-capsule IPC.

Quick start

mkdir my-capsule && cd my-capsule
npm init -y
npm install @unicity-astrid/sdk
npm install --save-dev @unicity-astrid/build typescript

Capsule.toml:

[package]
name = "my-capsule"
version = "0.1.0"

[[component]]
id = "my-capsule"
file = "my-capsule.wasm"
type = "executable"

[capabilities]
ipc_publish = ["tool.v1.execute.*"]
kv = ["*"]

src/index.ts:

import { capsule, tool, install, log, kv } from "@unicity-astrid/sdk";

@capsule
export class MyCapsule {
  greetings = 0;

  @tool("greet", { mutable: true })
  greet({ name }: { name: string }): { message: string; count: number } {
    this.greetings++;
    log.info(`greeting ${name} (#${this.greetings})`);
    return { message: `Hello, ${name}!`, count: this.greetings };
  }

  @install
  onInstall(): void {
    log.info("my-capsule installed");
  }
}

Build:

astrid build           # or: astrid capsule install .

That's it. tsc compiles your TypeScript, esbuild bundles in the SDK, ComponentizeJS produces a wasip2 component, the Rust-side astrid-build packs it into dist/my-capsule.capsule.

Building capsules

End-to-end pipeline:

src/*.ts
   ↓  tsc (typecheck + emit dist/*.js)
   ↓  esbuild (bundle dist/ + @unicity-astrid/sdk into one ESM, mark astrid:* WIT specifiers external)
   ↓  ComponentizeJS programmatic API (StarlingMonkey + your bundle → wasip2 Component)
target/<name>.wasm
   ↓  pack_capsule_archive (Rust side)
dist/<name>.capsule (Capsule.toml + .wasm + wit/, gzipped tar)

tsc and esbuild run from @unicity-astrid/build/src/index.mjs — a small Node CLI invoked by Rust's astrid build when it detects a package.json + Capsule.toml project.

Trade-off: binary size

JS capsules cost ~11 MB raw (3.5 MB gzipped in the .capsule archive). That's the StarlingMonkey embed. Rust capsules are ~200 KB. Acceptable for daemon-mode workloads (capsules load once); if size matters more than ergonomics, write Rust.

The host ABI is identical, so a hot capsule can be ported between languages without kernel changes.

Repository layout

sdk-js/
├── packages/
│   ├── astrid-sdk/        @unicity-astrid/sdk — public API
│   ├── astrid-build/      @unicity-astrid/build — build orchestrator
│   └── ...
├── examples/
│   └── test-capsule/      Minimal end-to-end example mirroring sdk-rust/examples/test-capsule
├── notes/                 Phase-by-phase development notes (Phase 0–3)
├── package.json           npm workspace root
└── tsconfig.base.json

Development

npm install
npm --workspace @unicity-astrid/sdk run build
node packages/astrid-build/src/index.mjs examples/test-capsule

Or, from a kernel checkout with the JS dispatch wired into astrid-build:

cd core
cargo build -p astrid-build
./target/debug/astrid-build ../sdk-js/examples/test-capsule

Status

Alpha. The vertical slice (TypeScript → wasip2 component → .capsule → installed by astrid capsule install → kernel lifecycle hook execution) is proven end-to-end. Daemon-mode tool-dispatch round-trip (/tool greet { "name": "world" }) is on the same code path as install — same wasmtime instantiation, same linker contract — and ready for human-operator smoke testing.

See notes/phase-{0,1,2,3-install}.md for development history, design decisions, and known follow-ups.

License

Dual-licensed under MIT and Apache 2.0.

Copyright (c) 2025-2026 Joshua J. Bouw and Unicity Labs.

Extension points exported contracts — how you extend this code

IpcMessage (Interface)
(no doc) [4 implementers]
packages/astrid-sdk/src/ipc.ts
IpcMessage (Interface)
(no doc) [4 implementers]
packages/astrid-sdk/src/wit-imports.d.ts
StreamStart (Interface)
(no doc)
packages/astrid-sdk/src/http.ts
FetchInit (Interface)
(no doc)
packages/astrid-sdk/src/http.ts
PollResult (Interface)
(no doc)
packages/astrid-sdk/src/ipc.ts

Core symbols most depended-on inside this repo

callHost
called by 115
packages/astrid-sdk/src/errors.ts
expect
called by 39
packages/astrid-build/src/wit-parser.mjs
quote
called by 29
packages/astrid-sdk/src/fs.ts
match
called by 28
packages/astrid-build/src/wit-parser.mjs
#requireInner
called by 22
packages/astrid-sdk/src/net.ts
api
called by 19
packages/astrid-sdk/src/errors.ts
eat
called by 13
packages/astrid-build/src/wit-parser.mjs
die
called by 11
packages/astrid-build/src/index.mjs

Shape

Function 189
Method 150
Interface 142
Class 62

Languages

TypeScript100%

Modules by API surface

packages/astrid-sdk/src/contracts.ts87 symbols
packages/astrid-sdk/src/net.ts77 symbols
packages/astrid-sdk/src/wit-imports.d.ts53 symbols
packages/astrid-sdk/src/fs.ts48 symbols
packages/astrid-sdk/src/http.ts43 symbols
packages/astrid-sdk/src/runtime/bridge.ts28 symbols
packages/astrid-sdk/src/ipc.ts27 symbols
packages/astrid-sdk/src/process.ts22 symbols
packages/astrid-build/src/wit-parser.mjs20 symbols
packages/astrid-sdk/src/runtime/registry.ts16 symbols
packages/astrid-build/src/index.mjs16 symbols
packages/astrid-sdk/src/kv.ts12 symbols

Dependencies from manifests, versioned

@bytecodealliance/componentize-js0.18.0 · 1×
@bytecodealliance/jco1.13.0 · 1×
@unicity-astrid/build* · 1×
@unicity-astrid/sdk* · 1×
esbuild0.24.0 · 1×
typescript5.6.0 · 1×

For agents

$ claude mcp add sdk-js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact