create-hybrid 1.4.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -30
- package/dist/index.js +800 -369
- package/package.json +7 -35
- package/dist/index.d.ts +0 -3
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -513
- package/src/types.d.ts +0 -8
package/README.md
CHANGED
|
@@ -1,58 +1,173 @@
|
|
|
1
1
|
# create-hybrid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Project scaffolding tool for Hybrid AI agents. Generates a complete, production-ready agent project using the Cloudflare Containers + Durable Objects architecture.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
See [hybrid.dev](https://hybrid.dev) for more information.
|
|
8
|
-
|
|
9
|
-
## 📦 Quickstart
|
|
10
|
-
|
|
11
|
-
Getting started with Hybrid is simple:
|
|
12
|
-
|
|
13
|
-
### 1. Initialize your project
|
|
5
|
+
## Usage
|
|
14
6
|
|
|
15
7
|
```bash
|
|
16
8
|
npm create hybrid my-agent
|
|
17
|
-
|
|
9
|
+
# or
|
|
10
|
+
npx create-hybrid my-agent
|
|
11
|
+
# or with options
|
|
12
|
+
npx create-hybrid my-agent --env production --agent-name "My Bot"
|
|
18
13
|
```
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
## Options
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
| Flag | Description | Default |
|
|
18
|
+
|------|-------------|---------|
|
|
19
|
+
| `<name>` | Project directory name | Required |
|
|
20
|
+
| `--env` | XMTP environment: `dev` or `production` | Prompted interactively |
|
|
21
|
+
| `--agent-name` | Display name for the agent | Prompted interactively |
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
## Generated Project Structure
|
|
27
24
|
|
|
28
|
-
```
|
|
29
|
-
|
|
25
|
+
```
|
|
26
|
+
my-agent/
|
|
27
|
+
├── src/
|
|
28
|
+
│ ├── gateway/
|
|
29
|
+
│ │ └── index.ts # Cloudflare Worker: routes to container
|
|
30
|
+
│ ├── server/
|
|
31
|
+
│ │ └── index.ts # Agent server: Claude Code SDK + SSE
|
|
32
|
+
│ └── dev-gateway.ts # Local dev proxy to localhost:8454
|
|
33
|
+
├── package.json
|
|
34
|
+
├── tsconfig.json
|
|
35
|
+
├── wrangler.jsonc # Cloudflare Workers + Containers config
|
|
36
|
+
├── Dockerfile # Container image (cloudflare/sandbox base)
|
|
37
|
+
├── build.mjs # esbuild bundler script
|
|
38
|
+
├── start.sh # Container startup: node dist/server/index.js
|
|
39
|
+
├── SOUL.md # Agent personality / identity
|
|
40
|
+
├── INSTRUCTIONS.md # Agent behavioral guidelines
|
|
41
|
+
├── .env.example # Template for required environment variables
|
|
42
|
+
└── .gitignore
|
|
30
43
|
```
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
## Architecture
|
|
46
|
+
|
|
47
|
+
The generated project uses **Cloudflare Containers + Durable Objects**:
|
|
33
48
|
|
|
34
|
-
```bash
|
|
35
|
-
hybrid keys
|
|
36
49
|
```
|
|
50
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
51
|
+
│ Cloudflare Edge │
|
|
52
|
+
│ │
|
|
53
|
+
│ src/gateway/index.ts (Cloudflare Worker) │
|
|
54
|
+
│ │ │
|
|
55
|
+
│ ├── Gets/creates Sandbox Durable Object by teamId │
|
|
56
|
+
│ ├── Calls ensureAgentServer() to start container │
|
|
57
|
+
│ └── sandbox.containerFetch() → port 8454 │
|
|
58
|
+
│ │ │
|
|
59
|
+
│ ┌───────────▼────────────┐ │
|
|
60
|
+
│ │ Docker Container │ │
|
|
61
|
+
│ │ (Sandbox DO) │ │
|
|
62
|
+
│ │ │ │
|
|
63
|
+
│ │ src/server/index.ts │ │
|
|
64
|
+
│ │ Claude Code SDK │ │
|
|
65
|
+
│ │ POST /api/chat → SSE │ │
|
|
66
|
+
│ └────────────────────────┘ │
|
|
67
|
+
└─────────────────────────────────────────────────────────────┘
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Each `teamId` gets its own `Sandbox` Durable Object and container instance.
|
|
71
|
+
|
|
72
|
+
## Generated Files in Detail
|
|
73
|
+
|
|
74
|
+
### `src/gateway/index.ts`
|
|
75
|
+
|
|
76
|
+
The Cloudflare Worker entry point:
|
|
77
|
+
- Routes `GET /health` and `POST /api/chat`
|
|
78
|
+
- Gets or creates a `Sandbox` Durable Object keyed by `teamId`
|
|
79
|
+
- Calls `ensureAgentServer()` which:
|
|
80
|
+
1. Polls `sandbox.listProcesses()` until the container is ready
|
|
81
|
+
2. Checks for a running `server/index.js` process
|
|
82
|
+
3. HTTP health checks port 8454
|
|
83
|
+
4. If unhealthy: kills node processes and starts `node /app/dist/server/index.js`
|
|
84
|
+
- Proxies requests to the container via `sandbox.containerFetch()`
|
|
85
|
+
|
|
86
|
+
### `src/server/index.ts`
|
|
87
|
+
|
|
88
|
+
The agent server (runs inside the container):
|
|
89
|
+
- Hono HTTP server on port 8454
|
|
90
|
+
- `POST /api/chat`: Runs Claude Code SDK via `query()`, streams SSE response
|
|
91
|
+
- `GET /health`: Returns `{ status: "healthy" }`
|
|
92
|
+
- Reads `SOUL.md` and `INSTRUCTIONS.md` for system prompt
|
|
93
|
+
- Supports both Anthropic direct and OpenRouter (auto-detected from `OPENROUTER_API_KEY`)
|
|
37
94
|
|
|
38
|
-
|
|
95
|
+
### `src/dev-gateway.ts`
|
|
96
|
+
|
|
97
|
+
Local development proxy — proxies requests to `http://localhost:8454`:
|
|
39
98
|
|
|
40
99
|
```bash
|
|
41
|
-
|
|
100
|
+
pnpm dev:gateway
|
|
42
101
|
```
|
|
43
102
|
|
|
44
|
-
###
|
|
103
|
+
### `Dockerfile`
|
|
45
104
|
|
|
46
|
-
```
|
|
47
|
-
|
|
105
|
+
```dockerfile
|
|
106
|
+
FROM cloudflare/sandbox:0.7.0
|
|
107
|
+
WORKDIR /app
|
|
108
|
+
COPY dist/server/index.js ./dist/server/
|
|
109
|
+
COPY SOUL.md INSTRUCTIONS.md ./
|
|
110
|
+
RUN npm install
|
|
111
|
+
CMD ["sh", "start.sh"]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### `wrangler.jsonc`
|
|
115
|
+
|
|
116
|
+
```jsonc
|
|
117
|
+
{
|
|
118
|
+
"name": "my-agent",
|
|
119
|
+
"durable_objects": {
|
|
120
|
+
"bindings": [{ "name": "AgentContainer", "class_name": "Sandbox" }]
|
|
121
|
+
},
|
|
122
|
+
"containers": [
|
|
123
|
+
{ "class_name": "Sandbox", "instance_type": "standard-1", "max_instances": 10 }
|
|
124
|
+
]
|
|
125
|
+
}
|
|
48
126
|
```
|
|
49
127
|
|
|
50
|
-
|
|
128
|
+
### `package.json` scripts
|
|
51
129
|
|
|
52
|
-
|
|
130
|
+
| Script | Command |
|
|
131
|
+
|--------|---------|
|
|
132
|
+
| `build` | Runs `build.mjs` (esbuild bundles `src/server/index.ts`) |
|
|
133
|
+
| `dev` | `pnpm build && node dist/server/index.js` |
|
|
134
|
+
| `dev:gateway` | `node src/dev-gateway.ts` |
|
|
135
|
+
| `dev:container` | `wrangler dev` (local container dev) |
|
|
136
|
+
| `deploy` | `pnpm build && wrangler deploy` |
|
|
137
|
+
| `typecheck` | `tsc --noEmit` |
|
|
138
|
+
|
|
139
|
+
## Getting Started
|
|
140
|
+
|
|
141
|
+
After scaffolding:
|
|
53
142
|
|
|
54
143
|
```bash
|
|
55
|
-
|
|
144
|
+
cd my-agent
|
|
145
|
+
|
|
146
|
+
# 1. Install dependencies
|
|
147
|
+
pnpm install
|
|
148
|
+
|
|
149
|
+
# 2. Copy and fill in environment variables
|
|
150
|
+
cp .env.example .env
|
|
151
|
+
# Edit .env: add OPENROUTER_API_KEY (or ANTHROPIC_API_KEY)
|
|
152
|
+
|
|
153
|
+
# 3. Customize your agent
|
|
154
|
+
# Edit SOUL.md for personality
|
|
155
|
+
# Edit INSTRUCTIONS.md for behavioral guidelines
|
|
156
|
+
|
|
157
|
+
# 4. Start local development
|
|
158
|
+
pnpm dev
|
|
159
|
+
|
|
160
|
+
# 5. Deploy to Cloudflare
|
|
161
|
+
pnpm deploy
|
|
56
162
|
```
|
|
57
163
|
|
|
58
|
-
|
|
164
|
+
## Relation to Other Packages
|
|
165
|
+
|
|
166
|
+
- The generated `src/server/index.ts` uses `@anthropic-ai/claude-agent-sdk` directly — same pattern as `packages/agent/src/server/index.ts`
|
|
167
|
+
- The generated `src/gateway/index.ts` is a simplified version of `packages/gateway/src/index.ts` (without XMTP sidecar management)
|
|
168
|
+
- The generated project is standalone — no dependencies on `@hybrd/*` packages
|
|
169
|
+
- `packages/cli`'s `hybrid init` command delegates to this package
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|