|
1 | | -# AN SDK |
| 1 | +# 21st SDK — Internal Dev Guide |
2 | 2 |
|
3 | | -The open-source SDK for building, deploying, and embedding AI coding agents. |
4 | | - |
5 | | -**AN** is the "Vercel for agents" — a framework + hosting platform for AI agents. Define agents in code, deploy with one command, embed anywhere. |
| 3 | +This directory contains the 21st SDK packages. Source of truth lives here in the monorepo. The public open-source repo is at [github.com/21st-dev/21st-sdk](https://github.com/21st-dev/21st-sdk). |
6 | 4 |
|
7 | 5 | ## Packages |
8 | 6 |
|
9 | | -| Package | Description | npm | |
| 7 | +| Directory | npm package | What it does | |
10 | 8 | |---|---|---| |
11 | | -| [`@an-sdk/agent`](./packages/agent) | Define agents with full type safety | [](https://www.npmjs.com/package/@an-sdk/agent) | |
12 | | -| [`@an-sdk/react`](./packages/react) | Drop-in React chat UI for agents | [](https://www.npmjs.com/package/@an-sdk/react) | |
13 | | -| [`@an-sdk/node`](./packages/node) | Node.js client for the AN API | [](https://www.npmjs.com/package/@an-sdk/node) | |
14 | | -| [`@an-sdk/nextjs`](./packages/nextjs) | Next.js integration (server + client) | [](https://www.npmjs.com/package/@an-sdk/nextjs) | |
15 | | -| [`@an-sdk/cli`](./packages/cli) | CLI for deploying agents | [](https://www.npmjs.com/package/@an-sdk/cli) | |
16 | | - |
17 | | -## Quickstart |
18 | | - |
19 | | -### 1. Define an agent |
20 | | - |
21 | | -```ts |
22 | | -// agents/my-agent.ts |
23 | | -import { agent, tool } from "@an-sdk/agent" |
24 | | -import { z } from "zod" |
25 | | - |
26 | | -export default agent({ |
27 | | - model: "claude-sonnet-4-6", |
28 | | - systemPrompt: "You are a helpful coding assistant.", |
29 | | - tools: { |
30 | | - greet: tool({ |
31 | | - description: "Greet the user", |
32 | | - inputSchema: z.object({ name: z.string() }), |
33 | | - execute: async ({ name }) => ({ |
34 | | - content: [{ type: "text", text: `Hello, ${name}!` }], |
35 | | - }), |
36 | | - }), |
37 | | - }, |
38 | | -}) |
39 | | -``` |
| 9 | +| `agent/` | `@21st-sdk/agent` | Agent + tool definition (types only) | |
| 10 | +| `react/` | `@21st-sdk/react` | React chat UI components | |
| 11 | +| `node/` | `@21st-sdk/node` | Node.js API client | |
| 12 | +| `nextjs/` | `@21st-sdk/nextjs` | Next.js integration (server + client) | |
| 13 | +| `cli/` | `@21st-sdk/cli` | `an login` + `an deploy` CLI | |
| 14 | +| `docs/` | — | Documentation (bundled into each package on publish) | |
| 15 | + |
| 16 | +> **Note:** `agent-runtime` used to be here but was moved to `packages/agent-runtime/` — it's private and should never be in the public repo. |
40 | 17 |
|
41 | | -### 2. Deploy |
| 18 | +## Day-to-day development |
| 19 | + |
| 20 | +Just work in the monorepo as normal. Edit files, run builds, test locally. |
42 | 21 |
|
43 | 22 | ```bash |
44 | | -npx @an-sdk/cli login |
45 | | -npx @an-sdk/cli deploy |
| 23 | +# Build all SDK packages |
| 24 | +pnpm --filter "@21st-sdk/*" build |
| 25 | + |
| 26 | +# Build a specific package |
| 27 | +pnpm --filter @21st-sdk/react build |
46 | 28 | ``` |
47 | 29 |
|
48 | | -### 3. Embed in your app |
| 30 | +## Publishing to the open-source repo |
49 | 31 |
|
50 | | -```tsx |
51 | | -import { AnAgentChat } from "@an-sdk/react" |
| 32 | +When you're ready to push changes to the public [github.com/21st-dev/21st-sdk](https://github.com/21st-dev/21st-sdk): |
52 | 33 |
|
53 | | -export default function Page() { |
54 | | - return <AnAgentChat agent="your-agent-slug" /> |
55 | | -} |
| 34 | +### Prerequisites (one-time setup) |
| 35 | + |
| 36 | +Clone the public repo as a sibling of the monorepo: |
| 37 | + |
| 38 | +```bash |
| 39 | +cd /Users/sergeybunas/Develop/21/ |
| 40 | +git clone git@github.com:21st-dev/21st-sdk.git |
56 | 41 | ``` |
57 | 42 |
|
58 | | -## Architecture |
| 43 | +So your directory structure looks like: |
59 | 44 |
|
60 | 45 | ``` |
61 | | -Developer → CLI → AN Platform → E2B Sandbox (agent runs here) |
62 | | - ↕ |
63 | | -Client → @an-sdk/react → AN Relay → SSE Streaming |
| 46 | +Develop/21/ |
| 47 | +├── 21st/ ← monorepo (this repo) |
| 48 | +└── an-sdk/ ← public repo |
64 | 49 | ``` |
65 | 50 |
|
66 | | -- **SDK packages** (this repo): Open-source. Define agents, build UIs, deploy. |
67 | | -- **AN Platform**: Managed infrastructure. Runs agents in sandboxes, handles billing, auth, scaling. |
| 51 | +### Releasing |
68 | 52 |
|
69 | | -Same model as Next.js (open-source) + Vercel (managed platform). |
| 53 | +From the monorepo root: |
70 | 54 |
|
71 | | -## Documentation |
| 55 | +```bash |
| 56 | +# Option 1: Auto-generate commit message from recent monorepo commits |
| 57 | +./scripts/release-sdk.sh |
72 | 58 |
|
73 | | -See the [`docs/`](./packages/docs) directory or visit [an.dev/docs](https://an.dev/docs). |
| 59 | +# Option 2: Custom commit message |
| 60 | +./scripts/release-sdk.sh -m "feat: add theme customization API to @21st-sdk/react" |
74 | 61 |
|
75 | | -## Examples |
| 62 | +# Option 3: Tagged release (creates a git tag) |
| 63 | +./scripts/release-sdk.sh -t v0.2.0 -m "v0.2.0 — streaming improvements and new tool renderers" |
| 64 | +``` |
76 | 65 |
|
77 | | -- [`examples/basic-agent`](./examples/basic-agent) — Minimal agent with a custom tool |
| 66 | +Then push: |
78 | 67 |
|
79 | | -## Contributing |
| 68 | +```bash |
| 69 | +cd ../an-sdk && git push # regular release |
| 70 | +cd ../an-sdk && git push --tags # if you created a tag |
| 71 | +``` |
| 72 | + |
| 73 | +### What the script does |
| 74 | + |
| 75 | +1. Copies `agent/`, `react/`, `node/`, `nextjs/`, `cli/`, `docs/` to the public repo |
| 76 | +2. Excludes `node_modules/`, `dist/`, `.turbo/`, `CLAUDE.md` (private dev notes) |
| 77 | +3. If no `-m` flag, pulls recent commit messages from the monorepo that touched `packages/an-sdk/` and uses them as the commit message |
| 78 | +4. Creates a commit in the public repo (skips if nothing changed) |
| 79 | +5. Optionally tags the commit with `-t` |
| 80 | + |
| 81 | +### What NOT to do |
80 | 82 |
|
81 | | -See [CONTRIBUTING.md](./CONTRIBUTING.md). |
| 83 | +- Don't develop directly in the public repo — always work in the monorepo |
| 84 | +- Don't manually copy files — always use the release script |
| 85 | +- Don't include `agent-runtime` — the script only copies the 6 listed packages |
82 | 86 |
|
83 | | -## License |
| 87 | +## Publishing to npm |
| 88 | + |
| 89 | +npm publishing still happens from the monorepo, not the public repo: |
| 90 | + |
| 91 | +```bash |
| 92 | +pnpm --filter @21st-sdk/agent build && npm publish --access public |
| 93 | +``` |
84 | 94 |
|
85 | | -MIT — see [LICENSE](./LICENSE). |
| 95 | +See the [NPM Publishing notes](../../.claude/projects/-Users-sergeybunas-Develop-21-21st/memory/MEMORY.md) for auth details. |
0 commit comments