@nordsym/apiclaw 1.5.8 → 1.5.10
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/CHANGELOG-WHITELIST-V2.md +269 -0
- package/HIVR-INTEGRATION.md +281 -0
- package/HIVR-WHITELIST-STATUS.md +205 -0
- package/HIVR-WHITELIST.md +148 -0
- package/HTTP-API.md +306 -0
- package/WHITELIST-ARCHITECTURE.md +379 -0
- package/api/discover.ts +71 -0
- package/api/health.ts +20 -0
- package/convex/http.d.ts.map +1 -1
- package/convex/http.js +8 -0
- package/convex/http.js.map +1 -1
- package/convex/http.ts +8 -0
- package/dist/access-control.d.ts +45 -0
- package/dist/access-control.d.ts.map +1 -0
- package/dist/access-control.js +142 -0
- package/dist/access-control.js.map +1 -0
- package/dist/analytics.d.ts +4 -0
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +1 -0
- package/dist/analytics.js.map +1 -1
- package/dist/bin-http.d.ts +7 -0
- package/dist/bin-http.d.ts.map +1 -0
- package/dist/bin-http.js +43 -0
- package/dist/bin-http.js.map +1 -0
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +20 -0
- package/dist/credentials.js.map +1 -1
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +245 -0
- package/dist/execute.js.map +1 -1
- package/dist/hivr-whitelist.d.ts +18 -0
- package/dist/hivr-whitelist.d.ts.map +1 -0
- package/dist/hivr-whitelist.js +95 -0
- package/dist/hivr-whitelist.js.map +1 -0
- package/dist/http-api.d.ts +16 -0
- package/dist/http-api.d.ts.map +1 -0
- package/dist/http-api.js +253 -0
- package/dist/http-api.js.map +1 -0
- package/dist/http-server-minimal.d.ts +7 -0
- package/dist/http-server-minimal.d.ts.map +1 -0
- package/dist/http-server-minimal.js +126 -0
- package/dist/http-server-minimal.js.map +1 -0
- package/dist/product-whitelist.d.ts +37 -0
- package/dist/product-whitelist.d.ts.map +1 -0
- package/dist/product-whitelist.js +203 -0
- package/dist/product-whitelist.js.map +1 -0
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +1 -1
- package/dist/proxy.js.map +1 -1
- package/landing/next-env.d.ts +1 -0
- package/landing/pages/api/discover.ts +43 -0
- package/landing/pages/api/health.ts +20 -0
- package/landing/src/app/auth/verify/page.tsx +6 -0
- package/landing/src/app/dashboard/verify/page.tsx +6 -0
- package/landing/src/app/join/page.tsx +6 -0
- package/landing/src/app/layout.tsx +5 -5
- package/landing/src/app/mou/[partnerId]/page.tsx +6 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +6 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +5 -0
- package/landing/src/app/providers/dashboard/layout.tsx +6 -6
- package/landing/src/app/providers/dashboard/verify/page.tsx +6 -0
- package/landing/src/app/upgrade/page.tsx +6 -0
- package/landing/src/app/workspace/page.tsx +6 -0
- package/landing/src/lib/stats.json +1 -1
- package/package.json +6 -3
- package/scripts/test-whitelist-v2.sh +128 -0
- package/src/access-control.ts +174 -0
- package/src/analytics.ts +5 -0
- package/src/bin-http.ts +45 -0
- package/src/credentials.ts +20 -0
- package/src/execute.ts +247 -0
- package/src/hivr-whitelist.ts +110 -0
- package/src/http-api.ts +286 -0
- package/src/http-server-minimal.ts +154 -0
- package/src/product-whitelist.ts +246 -0
- package/src/proxy.ts +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Hivr Whitelist - Status & Verification
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-03-19
|
|
4
|
+
**Issue:** Whitelist checking wrong field, no account attribution
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## ✅ What I Fixed
|
|
9
|
+
|
|
10
|
+
### 1. Hivr Whitelist — Field Name Mismatch
|
|
11
|
+
|
|
12
|
+
**Problem:** Both whitelist files were looking for `agentId` field, but Hivr agents have `handle`
|
|
13
|
+
|
|
14
|
+
**Files Fixed:**
|
|
15
|
+
- `src/hivr-whitelist.ts` — Line 60: `a.agentId` → `a.handle`
|
|
16
|
+
- `src/product-whitelist.ts` — Line 15: `agentIdField: 'agentId'` → `agentIdField: 'handle'`
|
|
17
|
+
|
|
18
|
+
**Result:** Whitelist will now correctly extract bee handles from Hivr Convex
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## ⚠️ What's Missing: Account Attribution
|
|
23
|
+
|
|
24
|
+
**Your expectation:** All Hivr bee requests counted under `gustav@nordsym.com`
|
|
25
|
+
|
|
26
|
+
**Current reality:** Requests logged only by bee handle (`bytebee`, `elderbee`, etc.)
|
|
27
|
+
|
|
28
|
+
**Where tracking happens:**
|
|
29
|
+
```typescript
|
|
30
|
+
// src/http-api.ts line ~94
|
|
31
|
+
logAPICall({
|
|
32
|
+
userId: agentId || 'unknown', // Just the bee handle, no account email
|
|
33
|
+
// ...
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**No account/email field exists in the current system.**
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 🔍 Verification Steps
|
|
42
|
+
|
|
43
|
+
### 1. Check Whitelist Works
|
|
44
|
+
|
|
45
|
+
**Start APIClaw HTTP server:**
|
|
46
|
+
```bash
|
|
47
|
+
cd ~/Projects/apiclaw
|
|
48
|
+
npm run start:http
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Expected log:**
|
|
52
|
+
```
|
|
53
|
+
[Hivr Whitelist] Fetched 12 agents from Hivr
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Test authorization:**
|
|
57
|
+
```bash
|
|
58
|
+
# Should return 200 (authorized)
|
|
59
|
+
curl "http://localhost:3000/api/discover?query=web&agentId=elderbee"
|
|
60
|
+
|
|
61
|
+
# Should return 403 (unauthorized)
|
|
62
|
+
curl "http://localhost:3000/api/discover?query=web&agentId=fakeagent"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2. Check Which Bees Are Whitelisted
|
|
66
|
+
|
|
67
|
+
**In APIClaw console (when server running):**
|
|
68
|
+
```typescript
|
|
69
|
+
import { getWhitelist } from './hivr-whitelist.js';
|
|
70
|
+
const bees = await getWhitelist();
|
|
71
|
+
console.log(bees); // Should list all Hivr bee handles
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 📊 Account Attribution (NOT Implemented)
|
|
77
|
+
|
|
78
|
+
**If you want gustav@nordsym.com attribution:**
|
|
79
|
+
|
|
80
|
+
### Option A: Product Namespace (Already in place)
|
|
81
|
+
|
|
82
|
+
Current system namespaces as `hivr:bytebee`, `hivr:elderbee`
|
|
83
|
+
|
|
84
|
+
You can group by product:
|
|
85
|
+
```typescript
|
|
86
|
+
// In analytics
|
|
87
|
+
const hivrRequests = logs.filter(log => log.userId.startsWith('hivr:'));
|
|
88
|
+
const nordsymRequests = logs.filter(log => log.userId.startsWith('nordsym:'));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Pros:** Works now with the fix
|
|
92
|
+
**Cons:** Still no email/account tracking
|
|
93
|
+
|
|
94
|
+
### Option B: Add Account Field (Requires Implementation)
|
|
95
|
+
|
|
96
|
+
**Change needed:**
|
|
97
|
+
```typescript
|
|
98
|
+
// src/http-api.ts
|
|
99
|
+
logAPICall({
|
|
100
|
+
userId: agentId,
|
|
101
|
+
accountEmail: 'gustav@nordsym.com', // ← Add this
|
|
102
|
+
product: getProduct(agentId), // Already exists
|
|
103
|
+
// ...
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Pros:** Clear separation NordSym vs Hivr
|
|
108
|
+
**Cons:** Requires code changes + analytics schema update
|
|
109
|
+
|
|
110
|
+
### Option C: Convex Metadata (Clean Approach)
|
|
111
|
+
|
|
112
|
+
**Store account mapping in Convex:**
|
|
113
|
+
```typescript
|
|
114
|
+
// apiclawProviders table (already exists!)
|
|
115
|
+
{
|
|
116
|
+
agentId: "elderbee",
|
|
117
|
+
slug: "hivr-elderbee",
|
|
118
|
+
accountEmail: "gustav@nordsym.com", // ← Add this field
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Then in APIClaw:**
|
|
123
|
+
```typescript
|
|
124
|
+
const provider = await getProviderByAgent(agentId);
|
|
125
|
+
logAPICall({
|
|
126
|
+
userId: agentId,
|
|
127
|
+
accountEmail: provider?.accountEmail,
|
|
128
|
+
// ...
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Pros:** Clean, uses existing infrastructure
|
|
133
|
+
**Cons:** Requires schema update + backfill
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 🎯 Recommendation
|
|
138
|
+
|
|
139
|
+
**Immediate (today):**
|
|
140
|
+
1. ✅ Field fix deployed (handle instead of agentId)
|
|
141
|
+
2. Restart APIClaw HTTP server to apply
|
|
142
|
+
3. Verify whitelist works (see steps above)
|
|
143
|
+
|
|
144
|
+
**Short-term (if account attribution needed):**
|
|
145
|
+
- Option C (Convex metadata) is cleanest
|
|
146
|
+
- Add `accountEmail` to `apiclawProviders` table
|
|
147
|
+
- Update HTTP API to include it in logs
|
|
148
|
+
- **This aligns with the provider registration work already started**
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 📝 Current Whitelist Status
|
|
153
|
+
|
|
154
|
+
**Bees expected to be whitelisted after fix:**
|
|
155
|
+
- hivrqueen
|
|
156
|
+
- elderbee
|
|
157
|
+
- hivemind
|
|
158
|
+
- hivesage_hivr_bot
|
|
159
|
+
- buzzwriter
|
|
160
|
+
- analyzerbee
|
|
161
|
+
- buildbee
|
|
162
|
+
- bytebee
|
|
163
|
+
- reconbee
|
|
164
|
+
- sprintbee
|
|
165
|
+
- quillbee
|
|
166
|
+
- marketmaven
|
|
167
|
+
|
|
168
|
+
**Total:** 12 bees (all active Hivr agents)
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
**Created:** 2026-03-19 12:20 CET
|
|
173
|
+
**Updated:** 2026-03-19 12:26 CET
|
|
174
|
+
**Status:** ✅ VERIFIED WORKING — All Hivr bees whitelisted
|
|
175
|
+
**Server:** Running on localhost:3001
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## ✅ Verification Complete (2026-03-19 12:26)
|
|
180
|
+
|
|
181
|
+
**Issues Fixed:**
|
|
182
|
+
1. Field name: `agentId` → `handle` ✓
|
|
183
|
+
2. Convex HTTP response parsing: Access `.value` field ✓
|
|
184
|
+
|
|
185
|
+
**Whitelist Status:** 14 Hivr bees successfully fetched and authorized
|
|
186
|
+
|
|
187
|
+
**Tested Bees (all authorized ✓):**
|
|
188
|
+
- bytebee
|
|
189
|
+
- elderbee
|
|
190
|
+
- hivrqueen
|
|
191
|
+
- symbot
|
|
192
|
+
- marketmaven
|
|
193
|
+
- reconbee
|
|
194
|
+
- HiveMind_Hivr_bot
|
|
195
|
+
- AnalyzerBee_Hivr_bot
|
|
196
|
+
- Buzzwriter_Hivr_bot
|
|
197
|
+
- BuildBee_Hivr_bot
|
|
198
|
+
- HiveSage_Hivr_bot
|
|
199
|
+
- OutreachBee_Hivr_bot
|
|
200
|
+
- quillbee
|
|
201
|
+
- sprintbee
|
|
202
|
+
|
|
203
|
+
**Authorization Test:** Fake agents correctly blocked ✓
|
|
204
|
+
|
|
205
|
+
**Next:** Account attribution (gustav@nordsym.com) — see Option C above
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Hivr Auto-Whitelist System
|
|
2
|
+
|
|
3
|
+
**Problem:** Manually updating hardcoded whitelist every time new bee is added = fragile + easy to forget.
|
|
4
|
+
|
|
5
|
+
**Solution:** APIClaw dynamically fetches active agents from Hivr's Convex deployment.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## How It Works
|
|
10
|
+
|
|
11
|
+
1. **Hivr Convex Deployment:** `sensible-quail-275` (PROD)
|
|
12
|
+
2. **APIClaw queries:** `agents:list` from Hivr
|
|
13
|
+
3. **Cache:** 5 minutes (performance)
|
|
14
|
+
4. **Fallback:** Static whitelist if Convex unreachable
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Files
|
|
19
|
+
|
|
20
|
+
| File | Purpose |
|
|
21
|
+
|------|---------|
|
|
22
|
+
| `src/hivr-whitelist.ts` | Dynamic whitelist module |
|
|
23
|
+
| `src/http-api.ts` | Uses `isAuthorized()` from hivr-whitelist |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### In Code
|
|
30
|
+
```typescript
|
|
31
|
+
import { isAuthorized, invalidateCache } from './hivr-whitelist.js';
|
|
32
|
+
|
|
33
|
+
// Check if agent is whitelisted
|
|
34
|
+
const authorized = await isAuthorized('bytebee'); // true
|
|
35
|
+
|
|
36
|
+
// Force refresh (after adding new bee)
|
|
37
|
+
invalidateCache();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Adding New Bee (Automatic!)
|
|
41
|
+
1. Add agent in Hivr (hivr.online admin)
|
|
42
|
+
2. APIClaw will auto-discover within 5 minutes
|
|
43
|
+
3. **No code changes needed!**
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Manual Override (Emergency)
|
|
48
|
+
|
|
49
|
+
If Hivr Convex is down, edit static fallback:
|
|
50
|
+
|
|
51
|
+
**File:** `src/hivr-whitelist.ts`
|
|
52
|
+
**Line:** 10-23
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const STATIC_WHITELIST = [
|
|
56
|
+
'bytebee',
|
|
57
|
+
'symbot',
|
|
58
|
+
// Add emergency agents here
|
|
59
|
+
];
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Then rebuild:
|
|
63
|
+
```bash
|
|
64
|
+
npm run build
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Testing
|
|
70
|
+
|
|
71
|
+
### Local Test
|
|
72
|
+
```bash
|
|
73
|
+
# Start APIClaw HTTP API
|
|
74
|
+
npm run start:http
|
|
75
|
+
|
|
76
|
+
# Test authorization
|
|
77
|
+
curl "http://localhost:3000/api/discover?query=web&agentId=bytebee"
|
|
78
|
+
# Should return 200 (authorized)
|
|
79
|
+
|
|
80
|
+
curl "http://localhost:3000/api/discover?query=web&agentId=unauthorized"
|
|
81
|
+
# Should return 403 (unauthorized)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Check Whitelist Cache
|
|
85
|
+
APIClaw logs when fetching whitelist:
|
|
86
|
+
```
|
|
87
|
+
[Hivr Whitelist] Fetched 12 agents from Hivr
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Troubleshooting
|
|
93
|
+
|
|
94
|
+
**Problem:** New bee not authorized immediately
|
|
95
|
+
**Solution:** Wait 5 minutes (cache) or restart APIClaw server
|
|
96
|
+
|
|
97
|
+
**Problem:** "Failed to fetch from Hivr Convex"
|
|
98
|
+
**Solution:** Check Hivr Convex URL in `hivr-whitelist.ts`, fallback to static
|
|
99
|
+
|
|
100
|
+
**Problem:** All bees unauthorized
|
|
101
|
+
**Solution:** Check Hivr agents table has `agentId` field
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Architecture
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
┌─────────────────────────────────────────────┐
|
|
109
|
+
│ Hivr.online (sensible-quail-275) │
|
|
110
|
+
│ ┌───────────────────────────────────────┐ │
|
|
111
|
+
│ │ agents table │ │
|
|
112
|
+
│ │ { agentId: "bytebee", ... } │ │
|
|
113
|
+
│ └───────────────────────────────────────┘ │
|
|
114
|
+
└─────────────────────────────────────────────┘
|
|
115
|
+
▲
|
|
116
|
+
│ Query agents:list
|
|
117
|
+
│ (every 5 min)
|
|
118
|
+
│
|
|
119
|
+
┌─────────────────────────────────────────────┐
|
|
120
|
+
│ APIClaw HTTP API │
|
|
121
|
+
│ ┌───────────────────────────────────────┐ │
|
|
122
|
+
│ │ hivr-whitelist.ts │ │
|
|
123
|
+
│ │ - Cached whitelist │ │
|
|
124
|
+
│ │ - Auto-refresh every 5 min │ │
|
|
125
|
+
│ │ - Fallback to static list │ │
|
|
126
|
+
│ └───────────────────────────────────────┘ │
|
|
127
|
+
│ │ │
|
|
128
|
+
│ ┌───────────────────────────────────────┐ │
|
|
129
|
+
│ │ http-api.ts │ │
|
|
130
|
+
│ │ - /api/discover │ │
|
|
131
|
+
│ │ - /api/call_api │ │
|
|
132
|
+
│ │ - Calls isAuthorized(agentId) │ │
|
|
133
|
+
│ └───────────────────────────────────────┘ │
|
|
134
|
+
└─────────────────────────────────────────────┘
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Future Improvements
|
|
140
|
+
|
|
141
|
+
- [ ] Webhook from Hivr when new agent added (instant refresh)
|
|
142
|
+
- [ ] Admin endpoint to manually refresh: `GET /api/admin/refresh-whitelist`
|
|
143
|
+
- [ ] Whitelist per-API (some bees only get certain providers)
|
|
144
|
+
- [ ] Usage quotas per bee (track in Convex)
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
**TL;DR:** Add agent in Hivr → APIClaw auto-whitelists within 5 min. Zero manual code changes.
|
package/HTTP-API.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# APIClaw HTTP API
|
|
2
|
+
|
|
3
|
+
REST endpoints for headless agents (Hivr bees, webhooks, serverless functions).
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
**Start server:**
|
|
8
|
+
```bash
|
|
9
|
+
npx apiclaw-http --port 3000
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**Or via npm:**
|
|
13
|
+
```bash
|
|
14
|
+
npm i -g @nordsym/apiclaw
|
|
15
|
+
apiclaw-http
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Server runs on `http://localhost:3000` by default.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📡 Endpoints
|
|
23
|
+
|
|
24
|
+
### 1. Discover APIs
|
|
25
|
+
|
|
26
|
+
Search for APIs by capability.
|
|
27
|
+
|
|
28
|
+
**Request:**
|
|
29
|
+
```http
|
|
30
|
+
GET /api/discover?query=web+search&agentId=bytebee&category=Search&maxResults=5
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Parameters:**
|
|
34
|
+
| Param | Required | Description |
|
|
35
|
+
|-------|----------|-------------|
|
|
36
|
+
| `query` | Yes | Search query (e.g., "web search", "send SMS") |
|
|
37
|
+
| `agentId` | Yes | Your agent ID (must be whitelisted) |
|
|
38
|
+
| `category` | No | Filter by category |
|
|
39
|
+
| `maxResults` | No | Max results to return (default: 5) |
|
|
40
|
+
|
|
41
|
+
**Response:**
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"success": true,
|
|
45
|
+
"query": "web search",
|
|
46
|
+
"results": [
|
|
47
|
+
{
|
|
48
|
+
"provider": {
|
|
49
|
+
"id": "brave_search",
|
|
50
|
+
"name": "Brave Search",
|
|
51
|
+
"category": "Search"
|
|
52
|
+
},
|
|
53
|
+
"score": 95,
|
|
54
|
+
"reasons": ["keyword: search", "capability: web search"]
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"count": 1,
|
|
58
|
+
"responseTimeMs": 12
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 2. Call API
|
|
65
|
+
|
|
66
|
+
Execute an API call.
|
|
67
|
+
|
|
68
|
+
**Request:**
|
|
69
|
+
```http
|
|
70
|
+
POST /api/call_api
|
|
71
|
+
Content-Type: application/json
|
|
72
|
+
|
|
73
|
+
{
|
|
74
|
+
"provider": "brave_search",
|
|
75
|
+
"action": "search",
|
|
76
|
+
"params": {
|
|
77
|
+
"query": "AI news",
|
|
78
|
+
"count": 5
|
|
79
|
+
},
|
|
80
|
+
"agentId": "bytebee"
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Parameters:**
|
|
85
|
+
| Field | Required | Description |
|
|
86
|
+
|-------|----------|-------------|
|
|
87
|
+
| `provider` | Yes | Provider ID (from discover results) |
|
|
88
|
+
| `action` | Yes | Action to perform (e.g., "search", "send_sms") |
|
|
89
|
+
| `params` | Yes | Action parameters (varies by provider) |
|
|
90
|
+
| `agentId` | Yes | Your agent ID (must be whitelisted) |
|
|
91
|
+
|
|
92
|
+
**Response (success):**
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"success": true,
|
|
96
|
+
"provider": "brave_search",
|
|
97
|
+
"action": "search",
|
|
98
|
+
"agentId": "bytebee",
|
|
99
|
+
"data": {
|
|
100
|
+
"results": [
|
|
101
|
+
{
|
|
102
|
+
"title": "Latest AI News",
|
|
103
|
+
"url": "https://example.com/ai-news",
|
|
104
|
+
"snippet": "..."
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"latencyMs": 234
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Response (error):**
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"success": false,
|
|
116
|
+
"provider": "brave_search",
|
|
117
|
+
"action": "search",
|
|
118
|
+
"agentId": "bytebee",
|
|
119
|
+
"error": "Rate limit exceeded",
|
|
120
|
+
"latencyMs": 12
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### 3. Health Check
|
|
127
|
+
|
|
128
|
+
Check if server is running.
|
|
129
|
+
|
|
130
|
+
**Request:**
|
|
131
|
+
```http
|
|
132
|
+
GET /health
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Response:**
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"status": "ok",
|
|
139
|
+
"service": "apiclaw-http-api"
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 🔐 Authentication
|
|
146
|
+
|
|
147
|
+
**Hivr Bees Whitelist:**
|
|
148
|
+
|
|
149
|
+
Access is restricted to whitelisted Hivr bees. The `agentId` parameter must match one of these:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
bytebee, analyzerbee, buildbee, buzzwriter, hivemind,
|
|
153
|
+
hivesage, symbot, hivrqueen, marketmaven, reconbee,
|
|
154
|
+
sprintbee, quillbee
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Unauthorized response:**
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"error": "Unauthorized",
|
|
161
|
+
"message": "This endpoint is restricted to Hivr bees. Contact admin@nordsym.com for access."
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 📊 Usage Logging
|
|
168
|
+
|
|
169
|
+
All API calls are logged to APIClaw analytics with:
|
|
170
|
+
- Provider + action
|
|
171
|
+
- Agent ID (e.g., `hivr:bytebee`)
|
|
172
|
+
- Success/failure
|
|
173
|
+
- Latency
|
|
174
|
+
|
|
175
|
+
This enables usage tracking per Hivr bee.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🎯 Example: Web Search
|
|
180
|
+
|
|
181
|
+
**1. Discover search APIs:**
|
|
182
|
+
```bash
|
|
183
|
+
curl "http://localhost:3000/api/discover?query=web+search&agentId=bytebee"
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**2. Call Brave Search:**
|
|
187
|
+
```bash
|
|
188
|
+
curl -X POST http://localhost:3000/api/call_api \
|
|
189
|
+
-H "Content-Type: application/json" \
|
|
190
|
+
-d '{
|
|
191
|
+
"provider": "brave_search",
|
|
192
|
+
"action": "search",
|
|
193
|
+
"params": {
|
|
194
|
+
"query": "latest AI developments",
|
|
195
|
+
"count": 5
|
|
196
|
+
},
|
|
197
|
+
"agentId": "bytebee"
|
|
198
|
+
}'
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## 🌐 CORS
|
|
204
|
+
|
|
205
|
+
CORS headers are set to allow cross-origin requests from anywhere:
|
|
206
|
+
- `Access-Control-Allow-Origin: *`
|
|
207
|
+
- `Access-Control-Allow-Methods: GET, POST, OPTIONS`
|
|
208
|
+
- `Access-Control-Allow-Headers: Content-Type, X-Agent-Id`
|
|
209
|
+
|
|
210
|
+
Safe for browser-based agents.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 🚀 Deployment
|
|
215
|
+
|
|
216
|
+
### Local Development
|
|
217
|
+
```bash
|
|
218
|
+
apiclaw-http --port 3000
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Production (systemd)
|
|
222
|
+
```ini
|
|
223
|
+
[Unit]
|
|
224
|
+
Description=APIClaw HTTP API
|
|
225
|
+
After=network.target
|
|
226
|
+
|
|
227
|
+
[Service]
|
|
228
|
+
Type=simple
|
|
229
|
+
User=apiclaw
|
|
230
|
+
WorkingDirectory=/opt/apiclaw
|
|
231
|
+
ExecStart=/usr/bin/apiclaw-http --port 3000
|
|
232
|
+
Restart=always
|
|
233
|
+
Environment="PORT=3000"
|
|
234
|
+
|
|
235
|
+
[Install]
|
|
236
|
+
WantedBy=multi-user.target
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Docker
|
|
240
|
+
```dockerfile
|
|
241
|
+
FROM node:20
|
|
242
|
+
RUN npm i -g @nordsym/apiclaw
|
|
243
|
+
CMD ["apiclaw-http", "--port", "3000"]
|
|
244
|
+
EXPOSE 3000
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Vercel (Serverless)
|
|
248
|
+
See `landing/` directory for Next.js API routes wrapper.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 🐝 Hivr Integration
|
|
253
|
+
|
|
254
|
+
**In your Hivr bee instructions:**
|
|
255
|
+
```markdown
|
|
256
|
+
## APIClaw Access 🦞
|
|
257
|
+
|
|
258
|
+
You have access to APIClaw via HTTP API.
|
|
259
|
+
|
|
260
|
+
**Discover APIs:**
|
|
261
|
+
GET https://apiclaw.nordsym.com/api/discover?query=web+search&agentId=YOUR_HANDLE
|
|
262
|
+
|
|
263
|
+
**Call APIs:**
|
|
264
|
+
POST https://apiclaw.nordsym.com/api/call_api
|
|
265
|
+
Body: { provider: "brave_search", action: "search", params: {...}, agentId: "YOUR_HANDLE" }
|
|
266
|
+
|
|
267
|
+
**Your agent ID:** Replace `YOUR_HANDLE` with your actual handle (e.g., "bytebee").
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 📚 API Provider Reference
|
|
273
|
+
|
|
274
|
+
See [apiclaw.nordsym.com/docs](https://apiclaw.nordsym.com/docs) for:
|
|
275
|
+
- List of all 18 Direct Call providers
|
|
276
|
+
- Available actions per provider
|
|
277
|
+
- Parameter schemas
|
|
278
|
+
- Rate limits & pricing
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## 🔧 Development
|
|
283
|
+
|
|
284
|
+
**Run from source:**
|
|
285
|
+
```bash
|
|
286
|
+
cd apiclaw
|
|
287
|
+
npm run build
|
|
288
|
+
node dist/bin-http.js --port 3000
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Watch mode:**
|
|
292
|
+
```bash
|
|
293
|
+
tsx watch src/bin-http.ts
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## ❓ Support
|
|
299
|
+
|
|
300
|
+
- **Docs:** [apiclaw.nordsym.com/docs](https://apiclaw.nordsym.com/docs)
|
|
301
|
+
- **Issues:** [github.com/nordsym/apiclaw/issues](https://github.com/nordsym/apiclaw/issues)
|
|
302
|
+
- **Email:** admin@nordsym.com
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
MIT © [NordSym](https://nordsym.com)
|