Skip to content

Commit ee38bb0

Browse files
committed
OSS Release
1 parent d486dfa commit ee38bb0

1,582 files changed

Lines changed: 246254 additions & 444 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
node_modules/
22
dist/
3+
build/
4+
.next/
5+
out/
36
.turbo/
7+
.vercel/
8+
.clerk/
49
.env
510
.env.*
11+
!.env.example
12+
!*.env.example
613
.DS_Store
714
*.tgz
815
CLAUDE.md
16+
terraform.tfstate
17+
terraform.tfstate.*
18+
terraform.tfvars
19+
*.auto.tfvars
20+
*.auto.tfvars.json
21+
tfplan*
22+
apps/agents-web/prisma/client/
23+
apps/agents-web/public/an-docs-markdown/
924
__pycache__/
1025
*.py[cod]
1126
.venv/

README.md

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,98 @@
1-
# 21st SDK — Internal Dev Guide
1+
# 21st Agents SDK
22

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.
44

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
166

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+
```
2016

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.
2220

23-
```bash
24-
# Build all SDK packages
25-
pnpm --filter "@21st-sdk/*" build
21+
## Packages
2622

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 |
3034

31-
## Publishing to the open-source repo
35+
## Apps
3236

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 |
3442

35-
### Prerequisites (one-time setup)
43+
## Local Setup
3644

37-
Clone the public repo as a sibling of the monorepo:
45+
Install dependencies:
3846

3947
```bash
40-
cd /Users/sergeybunas/Develop/21/
41-
git clone git@github.com:21st-dev/21st-sdk.git
48+
pnpm install
4249
```
4350

44-
So your directory structure looks like:
51+
For SDK-only work:
4552

46-
```
47-
Develop/21/
48-
├── 21st/ ← monorepo (this repo)
49-
└── 21st-sdk/ ← public repo
53+
```bash
54+
pnpm build
55+
pnpm ts:check
5056
```
5157

52-
### Releasing
58+
Root `build` and `ts:check` are intentionally scoped to `packages/*`. Service
59+
apps have their own env and deployment requirements.
5360

54-
From the monorepo root:
61+
For a full local stack, create `.env` files for each service, then start them in
62+
separate terminals:
5563

5664
```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
5968

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
6271

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
6674

67-
Then push:
75+
# Terminal 2: relay
76+
PORT=3002 pnpm --filter relay dev
6877

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
7280
```
7381

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:
8783

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` |
8989

90-
npm publishing still happens from the monorepo, not the public repo:
90+
When using remote E2B/OpenSandbox from a local machine, set:
9191

9292
```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>
9496
```
9597

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`.

apps/agents-web/.env.example

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# App URLs
2+
NEXT_PUBLIC_APP_URL=http://localhost:3000
3+
NEXT_PUBLIC_AGENTS_WEB_URL=http://localhost:3000
4+
NEXT_PUBLIC_RELAY_URL=http://localhost:3002
5+
NEXT_PUBLIC_IS_STANDALONE_APP=false
6+
NEXT_PUBLIC_AGENTS_AUTH_MODE=clerk
7+
8+
# Database
9+
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/21st_agents?sslmode=disable
10+
DIRECT_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/21st_agents?sslmode=disable
11+
12+
# Auth: Clerk is the default non-standalone mode.
13+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_replace_me
14+
CLERK_SECRET_KEY=sk_test_replace_me
15+
CLERK_WEBHOOK_SECRET=whsec_replace_me
16+
17+
# Supabase-compatible APIs used by search/profile routes.
18+
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321
19+
NEXT_PUBLIC_SUPABASE_KEY=replace_me
20+
SUPABASE_SERVICE_ROLE_KEY=replace_me
21+
22+
# Internal service auth
23+
INTERNAL_API_SECRET=replace_me
24+
API_KEY_21ST=21st_sk_replace_me
25+
AN_API_KEY=21st_sk_replace_me
26+
BUILDER_WIZARD_API_KEY=21st_sk_replace_me
27+
BUILDER_WIZARD_JWT_SECRET=replace_me
28+
CLAUDE_PROXY_PRIVATE_JWT="-----BEGIN PRIVATE KEY-----\nreplace_me\n-----END PRIVATE KEY-----"
29+
30+
# Sandbox/deploy defaults
31+
SANDBOX_PROVIDER=e2b
32+
RELAY_SANDBOX_TEMPLATE=replace_me
33+
OPENSANDBOX_RUNTIME_IMAGE=
34+
35+
# Optional local services and integrations
36+
REDIS_URL=redis://localhost:6379
37+
OPENAI_API_KEY=
38+
OPENROUTER_API_KEY=
39+
RESEND_API_KEY=
40+
STRIPE_SECRET_KEY_V1=
41+
STRIPE_SECRET_KEY_V2=
42+
STRIPE_WEBHOOK_SECRET_V1=
43+
STRIPE_WEBHOOK_SECRET_V2=
44+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_V2=
45+
46+
# Optional storage/CDN
47+
R2_ACCESS_KEY_ID=
48+
R2_SECRET_ACCESS_KEY=
49+
NEXT_PUBLIC_R2_ENDPOINT=
50+
NEXT_PUBLIC_CDN_URL=
51+
52+
# Optional analytics. Keep disabled locally unless you intentionally configure a project.
53+
NEXT_PUBLIC_FORCE_ANALYTICS=false
54+
NEXT_PUBLIC_POSTHOG_KEY=
55+
NEXT_PUBLIC_POSTHOG_HOST=
56+
NEXT_PUBLIC_POSTHOG_AGENTS21ST_KEY=
57+
NEXT_PUBLIC_POSTHOG_AGENTS21ST_HOST=
58+
59+
# Standalone / Better Auth alternative. Uncomment instead of Clerk when self-hosting that mode.
60+
# NEXT_PUBLIC_IS_STANDALONE_APP=true
61+
# NEXT_PUBLIC_AGENTS_AUTH_MODE=better-auth
62+
# BETTER_AUTH_URL=http://localhost:3000
63+
# NEXT_PUBLIC_BETTER_AUTH_URL=http://localhost:3000
64+
# BETTER_AUTH_SECRET=replace_me
65+
# BETTER_AUTH_OKTA_SAML_ISSUER=
66+
# BETTER_AUTH_OKTA_SAML_ENTRY_POINT=
67+
# BETTER_AUTH_OKTA_SAML_CERT=

apps/agents-web/.eslintrc.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/** @type {import("eslint").Linter.Config} */
2+
module.exports = {
3+
root: true,
4+
extends: ["@repo/eslint-config/next.js"],
5+
parser: "@typescript-eslint/parser",
6+
parserOptions: {
7+
project: true,
8+
},
9+
rules: {
10+
"@next/next/no-img-element": "off",
11+
},
12+
overrides: [
13+
{
14+
files: ["tailwind.config.js"],
15+
parser: "espree",
16+
parserOptions: {
17+
ecmaVersion: 2020,
18+
},
19+
},
20+
// Warn about using Clerk's useAuth directly in agents/canvas sections
21+
// Desktop auth requires useCombinedAuth() instead
22+
{
23+
files: [
24+
"app/(alpha)/agents/**/*.{ts,tsx}",
25+
"app/agents/**/*.{ts,tsx}",
26+
"app/(alpha)/canvas/**/*.{ts,tsx}",
27+
],
28+
rules: {
29+
"no-restricted-imports": [
30+
"warn",
31+
{
32+
paths: [
33+
{
34+
name: "@clerk/nextjs",
35+
importNames: ["useAuth"],
36+
message:
37+
"Use useCombinedAuth() from '@/lib/hooks/use-combined-auth' instead for desktop auth support.",
38+
},
39+
],
40+
},
41+
],
42+
},
43+
},
44+
],
45+
}

apps/agents-web/.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# env files (can opt-in for commiting if needed)
29+
.env*
30+
!.env.example
31+
32+
# vercel
33+
.vercel
34+
35+
# typescript
36+
*.tsbuildinfo
37+
next-env.d.ts
38+
39+
# css
40+
css/*
41+
.env*.local
42+
43+
/prisma/client
44+
claude-code-output.log
45+
46+
# Per-developer paste workflow for scripts/generate-mcp-registry.ts
47+
/scripts/raw_html.local.html

0 commit comments

Comments
 (0)