|
1 | | -# 21st SDK — Internal Dev Guide |
| 1 | +# 21st Agents SDK |
2 | 2 |
|
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). |
| 3 | +Open-source SDK, runtime, and service code for building, deploying, and embedding 21st Agents. |
4 | 4 |
|
5 | | -## Packages |
6 | | - |
7 | | -| Directory | Package | What it does | |
8 | | -|---|---|---| |
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 | | -| `python-sdk/` | `21st-sdk` (PyPI) | Python API client | |
15 | | -| `docs/` | — | Documentation (bundled into each package on publish) | |
| 5 | +## Architecture |
16 | 6 |
|
17 | | -> **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. |
18 | | -
|
19 | | -## Day-to-day development |
| 7 | +```text |
| 8 | +Agent source |
| 9 | + -> @21st-sdk/cli bundles and deploys it |
| 10 | + -> apps/agents-web stores configs, API keys, docs, and dashboard state |
| 11 | + -> apps/relay authenticates requests, creates sandboxes, and streams runs |
| 12 | + -> packages/agent-runtime runs inside E2B/OpenSandbox |
| 13 | + -> apps/proxy validates sandbox JWTs and forwards model API calls |
| 14 | + -> @21st-sdk/react/nextjs/node/python embed or call the deployed agent |
| 15 | +``` |
20 | 16 |
|
21 | | -Just work in the monorepo as normal. Edit files, run builds, test locally. |
| 17 | +The runtime sandbox must be able to call both `RELAY_URL` and `CLAUDE_PROXY_URL`. |
| 18 | +If the sandbox runs remotely, `localhost` will not work for those values; expose |
| 19 | +local relay/proxy with ngrok, an AWS tunnel, or another public/internal tunnel. |
22 | 20 |
|
23 | | -```bash |
24 | | -# Build all SDK packages |
25 | | -pnpm --filter "@21st-sdk/*" build |
| 21 | +## Packages |
26 | 22 |
|
27 | | -# Build a specific package |
28 | | -pnpm --filter @21st-sdk/react build |
29 | | -``` |
| 23 | +| Path | Package | Purpose | |
| 24 | +| --- | --- | --- | |
| 25 | +| `packages/agent` | `@21st-sdk/agent` | Agent and tool definition helpers | |
| 26 | +| `packages/react` | `@21st-sdk/react` | React chat UI components and tool renderers | |
| 27 | +| `packages/node` | `@21st-sdk/node` | Server-side API client | |
| 28 | +| `packages/nextjs` | `@21st-sdk/nextjs` | Next.js integration and token handler | |
| 29 | +| `packages/cli` | `@21st-sdk/cli` | Agent deploy and management CLI | |
| 30 | +| `packages/python-sdk` | `21st-sdk` | Python API client | |
| 31 | +| `packages/agent-runtime` | `@21st-sdk/agent-runtime` | Sandbox runtime for executing deployed agents | |
| 32 | +| `packages/sandbox-provider` | `@repo/sandbox-provider` | Stream transformers and sandbox provider helpers | |
| 33 | +| `packages/api-key-security` | `@repo/api-key-security` | Shared API key prefixing and hashing helpers | |
30 | 34 |
|
31 | | -## Publishing to the open-source repo |
| 35 | +## Apps |
32 | 36 |
|
33 | | -When you're ready to push changes to the public [github.com/21st-dev/21st-sdk](https://github.com/21st-dev/21st-sdk): |
| 37 | +| Path | Purpose | |
| 38 | +| --- | --- | |
| 39 | +| `apps/agents-web` | Agents dashboard, docs, deploy API, and web UI | |
| 40 | +| `apps/relay` | Relay service for chat, sandbox lifecycle, streams, and tokens | |
| 41 | +| `apps/proxy` | Model API proxy used by sandbox runtimes | |
34 | 42 |
|
35 | | -### Prerequisites (one-time setup) |
| 43 | +## Local Setup |
36 | 44 |
|
37 | | -Clone the public repo as a sibling of the monorepo: |
| 45 | +Install dependencies: |
38 | 46 |
|
39 | 47 | ```bash |
40 | | -cd /Users/sergeybunas/Develop/21/ |
41 | | -git clone git@github.com:21st-dev/21st-sdk.git |
| 48 | +pnpm install |
42 | 49 | ``` |
43 | 50 |
|
44 | | -So your directory structure looks like: |
| 51 | +For SDK-only work: |
45 | 52 |
|
46 | | -``` |
47 | | -Develop/21/ |
48 | | -├── 21st/ ← monorepo (this repo) |
49 | | -└── 21st-sdk/ ← public repo |
| 53 | +```bash |
| 54 | +pnpm build |
| 55 | +pnpm ts:check |
50 | 56 | ``` |
51 | 57 |
|
52 | | -### Releasing |
| 58 | +Root `build` and `ts:check` are intentionally scoped to `packages/*`. Service |
| 59 | +apps have their own env and deployment requirements. |
53 | 60 |
|
54 | | -From the monorepo root: |
| 61 | +For a full local stack, create `.env` files for each service, then start them in |
| 62 | +separate terminals: |
55 | 63 |
|
56 | 64 | ```bash |
57 | | -# Option 1: Auto-generate commit message from recent monorepo commits |
58 | | -./scripts/release-sdk.sh |
| 65 | +cp apps/agents-web/.env.example apps/agents-web/.env |
| 66 | +cp apps/relay/.env.example apps/relay/.env |
| 67 | +cp apps/proxy/.env.example apps/proxy/.env |
59 | 68 |
|
60 | | -# Option 2: Custom commit message |
61 | | -./scripts/release-sdk.sh -m "feat: add theme customization API to @21st-sdk/react" |
| 69 | +# Optional local Redis, if you are not using a hosted REDIS_URL |
| 70 | +docker run --rm -p 6379:6379 redis:7 |
62 | 71 |
|
63 | | -# Option 3: Tagged release (creates a git tag) |
64 | | -./scripts/release-sdk.sh -t v0.2.0 -m "v0.2.0 — streaming improvements and new tool renderers" |
65 | | -``` |
| 72 | +# Terminal 1: model proxy |
| 73 | +PORT=3003 pnpm --filter proxy dev |
66 | 74 |
|
67 | | -Then push: |
| 75 | +# Terminal 2: relay |
| 76 | +PORT=3002 pnpm --filter relay dev |
68 | 77 |
|
69 | | -```bash |
70 | | -cd ../21st-sdk && git push # regular release |
71 | | -cd ../21st-sdk && git push --tags # if you created a tag |
| 78 | +# Terminal 3: web app |
| 79 | +pnpm --filter agents-web dev |
72 | 80 | ``` |
73 | 81 |
|
74 | | -### What the script does |
75 | | - |
76 | | -1. Copies `agent/`, `react/`, `node/`, `nextjs/`, `cli/`, `python-sdk/`, `docs/` to the public repo |
77 | | -2. Excludes `node_modules/`, `dist/`, `.turbo/`, `CLAUDE.md` (private dev notes) |
78 | | -3. If no `-m` flag, pulls recent commit messages from the monorepo that touched `packages/an-sdk/` and uses them as the commit message |
79 | | -4. Creates a commit in the public repo (skips if nothing changed) |
80 | | -5. Optionally tags the commit with `-t` |
81 | | - |
82 | | -### What NOT to do |
83 | | - |
84 | | -- Don't develop directly in the public repo — always work in the monorepo |
85 | | -- Don't manually copy files — always use the release script |
86 | | -- Don't include `agent-runtime` — the script only copies the 7 listed packages |
| 82 | +Minimum env groups: |
87 | 83 |
|
88 | | -## Publishing to npm |
| 84 | +| Service | Key env vars | |
| 85 | +| --- | --- | |
| 86 | +| `apps/agents-web` | `DATABASE_URL`, `DIRECT_DATABASE_URL`, auth provider env, `NEXT_PUBLIC_APP_URL=http://localhost:3000`, `NEXT_PUBLIC_RELAY_URL=http://localhost:3002` or tunnel URL | |
| 87 | +| `apps/relay` | `PORT=3002`, `DATABASE_URL`, `REDIS_URL`, `AN_JWT_SECRET`, `CLAUDE_PROXY_PRIVATE_JWT`, `CLAUDE_PROXY_URL`, `RELAY_URL`, plus either `E2B_API_KEY`/`RELAY_SANDBOX_TEMPLATE` or `OPENSANDBOX_*` | |
| 88 | +| `apps/proxy` | `PORT=3003`, `DATABASE_URL`, `JWT_PUBLIC_KEY`, `ANTHROPIC_API_KEY`, optional `OPENAI_API_KEY`/`OPENROUTER_API_KEY` | |
89 | 89 |
|
90 | | -npm publishing still happens from the monorepo, not the public repo: |
| 90 | +When using remote E2B/OpenSandbox from a local machine, set: |
91 | 91 |
|
92 | 92 | ```bash |
93 | | -pnpm --filter @21st-sdk/agent build && npm publish --access public |
| 93 | +RELAY_URL=https://<relay-tunnel> |
| 94 | +CLAUDE_PROXY_URL=https://<proxy-tunnel> |
| 95 | +NEXT_PUBLIC_RELAY_URL=https://<relay-tunnel> |
94 | 96 | ``` |
95 | 97 |
|
96 | | -See the [NPM Publishing notes](../../.claude/projects/-Users-sergeybunas-Develop-21-21st/memory/MEMORY.md) for auth details. |
| 98 | +For production-style self-hosting, start from `apps/agents-web/infra`. |
0 commit comments