Initialized `package.json`, add tsup build config (CJS/ESM/DTS), wire up full Makefile targets (lint/test/check/build), add missing BadRequest response component to OpenAPI spec, generate TypeScript types from spec, configure biome to exclude generated files, and add `@types/ws`
3.4 KiB
3.4 KiB
AGENTS.md
Project
Wrenn JavaScript SDK — a client library for the Wrenn microVM platform. e2b drop-in replacement.
Package name: @wrenn/sdk. Node.js 18+, TypeScript 5.5+, managed with pnpm.
Commands
pnpm install # install deps
make lint # biome check + format check (no auto-fix)
make test # unit tests only (vitest)
make test-integration # all tests including integration (needs live server)
make generate # regenerate types from OpenAPI spec (openapi-typescript)
make check # lint + unit test
make build # tsup build (CJS + ESM + DTS)
make testruns all non-integration tests. To run a specific test file:pnpm vitest run tests/commands.test.ts- No separate typecheck step —
vitestandtsuphandle type checking during test/build.tsc --noEmitis available but not wired up in CI.
Architecture
src/— the library packagecapsule.ts— high-levelCapsuleclass (main user-facing class)client.ts— low-levelWrennClientwithCapsulesResourceandSnapshotsResourcecommands.ts— command execution, streaming, and background process managementfiles.ts— filesystem operationspty.ts— interactive terminal (PTY) over WebSocketexceptions.ts— typed error hierarchy (WrennErrorbase)models/generated.ts— auto-generated from OpenAPI spec viaopenapi-typescript(never edit directly; runmake generate)git/— git operations inside capsules (clone, push, pull, status, branches, etc.)code-interpreter/— specialized capsule for stateful Jupyter kernel execution_shared/http.ts— thinfetchwrapper with auth headers, base URL, and error mapping_shared/websocket.ts— WebSocket helper wrappingwsconfig.ts— constants (DEFAULT_BASE_URL, env var names)
tests/— unit tests usemswto mock HTTP; integration tests are intests/integration/api/openapi.yaml— OpenAPI spec used for type generation
Key Conventions
- Generated types live in
src/models/generated.ts. Never edit them. Runmake generateto update. - No sync/async split — JS is naturally async. One
Capsuleclass, all methods returnPromise. Sandboxis a deprecated alias forCapsule. New code should useCapsule.- Uses native
fetchfor HTTP (Node 18+),wsfor WebSockets,zodfor runtime validation. - Resource disposal via
Symbol.asyncDispose(await using). Also supports manual.close(). - Streaming methods return
AsyncGenerator(e.g.commands.stream(),files.downloadStream()). - Static + instance method pattern:
capsule.destroy()(instance) andCapsule.destroy(id, opts)(static).
Testing
- Unit tests mock HTTP via
msw(Mock Service Worker for Node). - Integration tests require env vars:
WRENN_API_KEY(orWRENN_TOKEN), optionallyWRENN_BASE_URL. - Integration test fixtures in
tests/integration/setup.tscreate real capsules and clean them up. - Tests use
vitest— no@jestglobals. Useimport { describe, it, expect } from 'vitest'.
CI
Woodpecker CI (.woodpecker/check.yml) runs on push to main and dev:
make lintmake testmake test-integration
Dependencies
Runtime: ws (WebSocket), zod (validation). Everything else is dev-only.