@bitmacro/relay-agent 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BitMacro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # @bitmacro/relay-agent
2
+
3
+ [![CI](https://github.com/bitmacro/relay-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/bitmacro/relay-agent/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@bitmacro/relay-agent.svg)](https://www.npmjs.com/package/@bitmacro/relay-agent)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **Manage your Nostr relay without touching the terminal.**
8
+
9
+ `relay-agent` is a REST API agent that runs on your relay server and translates HTTP requests into strfry CLI commands. It is part of the [BitMacro Relay Manager](https://bitmacro.io) ecosystem.
10
+
11
+ ---
12
+
13
+ ## Quick Start
14
+
15
+ ### Via npx
16
+
17
+ ```bash
18
+ npx @bitmacro/relay-agent --port 7800 --token your-secret-token
19
+ ```
20
+
21
+ ### Via Docker
22
+
23
+ Multi-arch image (amd64, arm64) at `ghcr.io/bitmacro/relay-agent`. Includes strfry binary. Mount your strfry data volume:
24
+
25
+ ```bash
26
+ docker pull ghcr.io/bitmacro/relay-agent:latest
27
+ docker run -p 7800:7800 \
28
+ -e RELAY_AGENT_TOKEN=your-secret-token \
29
+ -v /path/to/strfry-db:/app/strfry-db \
30
+ -v /path/to/whitelist.txt:/app/whitelist.txt \
31
+ ghcr.io/bitmacro/relay-agent:latest
32
+ ```
33
+
34
+ Or build locally: `docker build -t relay-agent .`
35
+
36
+ **Multiple relays:** Use the compose fragment. Place relay-agent next to your docker-compose.yml.
37
+
38
+ ### Server deployment (complete flow)
39
+
40
+ ```bash
41
+ # 1. Clone (or pull) relay-agent into a subdir next to your docker-compose.yml
42
+ git clone https://github.com/bitmacro/relay-agent.git relay-agent
43
+
44
+ # 2. Configure .env in the directory containing docker-compose.yml
45
+ echo "RELAY_AGENT_TOKEN_PRIVATE=your-secret-token" >> .env
46
+ echo "RELAY_AGENT_TOKEN_PUBLIC=your-secret-token" >> .env
47
+ echo "RELAY_AGENT_TOKEN_PAID=your-secret-token" >> .env
48
+
49
+ # 3. Pull images from GHCR (or build locally if testing before merge)
50
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml pull
51
+
52
+ # 4. Start the services
53
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml up -d relay-agent-private relay-agent-public relay-agent-paid
54
+ ```
55
+
56
+ **Before GHCR has the image:** Use `build` instead of `pull` — the compose includes a build fallback. Run `docker compose ... build` then `up -d`.
57
+
58
+ See `docker-compose.relay-agents.yml` for the full setup (1 agent per relay in v0.1).
59
+
60
+ ---
61
+
62
+ ## Operational Commands
63
+
64
+ For operators using the compose fragment (`docker-compose.yml` + `relay-agent/docker-compose.relay-agents.yml`):
65
+
66
+ ```bash
67
+ # Rebuild and restart a specific agent
68
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml up -d --build relay-agent-public
69
+
70
+ # Rebuild and restart all relay agents
71
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml up -d --build relay-agent-private relay-agent-public relay-agent-paid
72
+
73
+ # Pull latest image and restart (when using GHCR)
74
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml pull
75
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml up -d relay-agent-private relay-agent-public relay-agent-paid
76
+
77
+ # View logs
78
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml logs -f relay-agent-public
79
+
80
+ # Stop all relay agents
81
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml stop relay-agent-private relay-agent-public relay-agent-paid
82
+ ```
83
+
84
+ ### Smoke Test
85
+
86
+ Verify the agent can talk to strfry LMDB:
87
+
88
+ ```bash
89
+ docker exec relay-agent-public sh -c 'curl -s -m 60 -H "Authorization: Bearer $RELAY_AGENT_TOKEN" http://localhost:7800/stats'
90
+ ```
91
+
92
+ Expected response: `{"total_events":...,"db_size":"...","uptime":...,"version":"..."}`
93
+
94
+ ---
95
+
96
+ ## REST API Endpoints
97
+
98
+ | Method | Path | Description | Example Response |
99
+ |--------|------|-------------|------------------|
100
+ | `GET` | `/health` | Health check (no auth) | `{"status":"ok","timestamp":"..."}` |
101
+ | `GET` | `/events` | List events (NIP-01 filter) | `[{id, pubkey, kind, ...}, ...]` |
102
+ | `DELETE` | `/events/:id` | Delete event by id | `{"deleted":"<id>"}` |
103
+ | `GET` | `/stats` | Relay statistics | `{total_events, db_size, uptime, version}` |
104
+ | `POST` | `/policy/block` | Block pubkey | `{"blocked":"<pubkey>"}` |
105
+ | `POST` | `/policy/allow` | Allow pubkey | `{"allowed":"<pubkey>"}` |
106
+ | `GET` | `/users` | List unique pubkeys | `{"users":["<pubkey>", ...]}` |
107
+
108
+ ### Query parameters for `GET /events`
109
+
110
+ | Param | Type | Description |
111
+ |-------|------|-------------|
112
+ | `kinds` | comma-separated | e.g. `1,3` |
113
+ | `authors` | comma-separated | pubkeys |
114
+ | `since` | unix timestamp | |
115
+ | `until` | unix timestamp | |
116
+ | `limit` | number | max events to return |
117
+
118
+ ### Authentication
119
+
120
+ All endpoints except `/health` require:
121
+
122
+ ```
123
+ Authorization: Bearer <your-token>
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Environment Variables
129
+
130
+ | Variable | Default | Description |
131
+ |----------|---------|-------------|
132
+ | `RELAY_AGENT_TOKEN` | — | **Required.** Bearer token for API auth |
133
+ | `STRFRY_BIN` | `strfry` | Path to strfry binary |
134
+ | `STRFRY_DB_PATH` | `./strfry-db` | Path to strfry database directory |
135
+ | `STRFRY_CONFIG` | — | Path to strfry config file (for explicit db path) |
136
+ | `WHITELIST_PATH` | `/etc/strfry/whitelist.txt` | Path to whitelist file |
137
+ | `PORT` | `7800` | HTTP server port |
138
+ | `ALLOWED_ORIGINS` | — | Comma-separated extra CORS origins (defaults include `https://admin.bitmacro.io`, `http://localhost:3000`) |
139
+
140
+ ---
141
+
142
+ ## Compatibility
143
+
144
+ | relay-agent | strfry |
145
+ |-------------|--------|
146
+ | 0.1.x | 1.0.x |
147
+
148
+ ---
149
+
150
+ ## Architecture
151
+
152
+ ```
153
+ bitmacro-api (Vercel)
154
+ │ HTTP REST + Bearer JWT
155
+
156
+ relay-agent ← this package
157
+ │ child_process spawn()
158
+
159
+ strfry (local C++ process / LMDB)
160
+ ```
161
+
162
+ The relay-agent is **stateless** — it has no database. State lives in Supabase, managed by bitmacro-api. The relay-agent only translates HTTP calls into strfry CLI commands.
163
+
164
+ ---
165
+
166
+ ## Troubleshooting
167
+
168
+ ### 503 "relay unavailable"
169
+
170
+ 1. **Capture the error** — run logs in one terminal, then curl in another:
171
+ ```bash
172
+ # Terminal 1
173
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml logs -f relay-agent-private
174
+ # Terminal 2
175
+ curl -H "Authorization: Bearer TOKEN" "http://localhost:7811/events?limit=3"
176
+ ```
177
+ The strfry stderr will appear in the logs.
178
+
179
+ 2. **LMDB "Resource temporarily unavailable"** — relay and relay-agent share the same db. Increase `maxreaders` in your **relay's** strfry.conf (e.g. `./nostr/private/strfry.conf`):
180
+ ```
181
+ dbParams {
182
+ maxreaders = 512
183
+ }
184
+ ```
185
+ Then restart the relay: `docker restart relay_private`
186
+
187
+ 3. **Verify db path** — relay-agent mounts `./nostr/private/data:/app/strfry-db`. Your relay (`relay_private`) must use the **same** host path for its strfry db. Check your main `docker-compose.yml`:
188
+ ```bash
189
+ grep -A5 relay_private docker-compose.yml
190
+ ```
191
+
192
+ 4. **Test strfry inside container**:
193
+ ```bash
194
+ docker compose -f docker-compose.yml -f relay-agent/docker-compose.relay-agents.yml run --rm relay-agent-private sh -c 'ls -la /app/strfry-db && /app/strfry --config /app/strfry.conf scan "{}" | head -3'
195
+ ```
196
+ If `data.mdb` is missing or strfry fails, fix the volume path.
197
+
198
+ ---
199
+
200
+ ## Security
201
+
202
+ - **Run on a private network.** The relay-agent should run on the operator's server and **never be exposed directly to the internet**.
203
+ - Access is controlled by the bitmacro-api, which proxies requests with a shared Bearer token.
204
+ - Use a strong, random token in production. Rotate it if compromised.
205
+
206
+ ---
207
+
208
+ ## Contributing
209
+
210
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setup and PR guidelines.
@@ -0,0 +1,2 @@
1
+
2
+ export { }