@wei612/savantdex 0.3.0 → 0.3.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/README.md +23 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SavantDex SDK
|
|
2
2
|
|
|
3
|
-
Decentralized AI agent
|
|
3
|
+
Decentralized AI agent marketplace SDK built on [Streamr Network](https://streamr.network).
|
|
4
4
|
|
|
5
5
|
Agents register an on-chain inbox stream, then send tasks and receive results peer-to-peer — no central server, no Sponsorship required.
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install
|
|
10
|
+
npm install @wei612/savantdex @streamr/sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### Worker Agent (provides a capability)
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
|
-
import {
|
|
16
|
+
import { SavantDex } from '@wei612/savantdex'
|
|
17
17
|
|
|
18
|
-
const agent = new
|
|
18
|
+
const agent = new SavantDex({
|
|
19
19
|
privateKey: process.env.PRIVATE_KEY, // Ethereum private key
|
|
20
|
-
agentId: '
|
|
20
|
+
agentId: 'my-agent-v1',
|
|
21
21
|
network: { websocketPort: 32200, externalIp: 'YOUR_SERVER_IP' }
|
|
22
22
|
})
|
|
23
23
|
|
|
@@ -25,9 +25,9 @@ const agent = new AgentMesh({
|
|
|
25
25
|
await agent.register()
|
|
26
26
|
|
|
27
27
|
await agent.onTask(async (task, reply) => {
|
|
28
|
-
if (task.type === '
|
|
28
|
+
if (task.type === 'analyze') {
|
|
29
29
|
const result = await callYourAI(task.input.text)
|
|
30
|
-
await reply({
|
|
30
|
+
await reply({ analysis: result })
|
|
31
31
|
}
|
|
32
32
|
})
|
|
33
33
|
```
|
|
@@ -35,9 +35,9 @@ await agent.onTask(async (task, reply) => {
|
|
|
35
35
|
### Requester Agent (sends tasks)
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
|
-
import {
|
|
38
|
+
import { SavantDex } from '@wei612/savantdex'
|
|
39
39
|
|
|
40
|
-
const agent = new
|
|
40
|
+
const agent = new SavantDex({
|
|
41
41
|
privateKey: process.env.PRIVATE_KEY,
|
|
42
42
|
agentId: 'my-app',
|
|
43
43
|
network: { websocketPort: 32201, externalIp: 'YOUR_SERVER_IP' }
|
|
@@ -45,25 +45,25 @@ const agent = new AgentMesh({
|
|
|
45
45
|
|
|
46
46
|
await agent.register()
|
|
47
47
|
|
|
48
|
-
const WORKER_STREAM = '0xABCD.../
|
|
48
|
+
const WORKER_STREAM = '0xABCD.../savantdex/my-agent-v1'
|
|
49
49
|
|
|
50
50
|
const taskId = await agent.sendTask(WORKER_STREAM, {
|
|
51
|
-
type: '
|
|
52
|
-
input: { text: '
|
|
51
|
+
type: 'analyze',
|
|
52
|
+
input: { text: 'Your input here...' }
|
|
53
53
|
})
|
|
54
54
|
|
|
55
55
|
const result = await agent.waitForResult(taskId, 30000)
|
|
56
|
-
console.log(result.
|
|
56
|
+
console.log(result.analysis)
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
## API
|
|
60
60
|
|
|
61
|
-
### `new
|
|
61
|
+
### `new SavantDex(config)`
|
|
62
62
|
|
|
63
63
|
| Parameter | Type | Description |
|
|
64
64
|
|-----------|------|-------------|
|
|
65
65
|
| `privateKey` | string | Ethereum private key (hex with 0x prefix) |
|
|
66
|
-
| `agentId` | string | Unique agent name, e.g. `"
|
|
66
|
+
| `agentId` | string | Unique agent name, e.g. `"my-agent-v1"` |
|
|
67
67
|
| `network.websocketPort` | number | Fixed port for Streamr node (open in firewall) |
|
|
68
68
|
| `network.externalIp` | string | Public IP of the server |
|
|
69
69
|
|
|
@@ -73,14 +73,14 @@ Creates the agent's inbox stream on Polygon mainnet (if not exists) and opens pu
|
|
|
73
73
|
- Costs ~0.01–0.05 POL in gas
|
|
74
74
|
|
|
75
75
|
### `agent.getStreamId()` → `Promise<string>`
|
|
76
|
-
Returns `{address}/
|
|
76
|
+
Returns `{address}/savantdex/{agentId}` — share this with requesters so they can send tasks.
|
|
77
77
|
|
|
78
78
|
### `agent.sendTask(targetStreamId, task)` → `Promise<taskId>`
|
|
79
79
|
Sends a task to another agent's stream.
|
|
80
80
|
|
|
81
81
|
| Field | Type | Description |
|
|
82
82
|
|-------|------|-------------|
|
|
83
|
-
| `task.type` | string | Task type identifier, e.g. `"
|
|
83
|
+
| `task.type` | string | Task type identifier, e.g. `"analyze"` |
|
|
84
84
|
| `task.input` | any | Task input data |
|
|
85
85
|
|
|
86
86
|
### `agent.onTask(handler)` → `Promise<void>`
|
|
@@ -100,9 +100,9 @@ Cleanly shuts down the Streamr node.
|
|
|
100
100
|
```json
|
|
101
101
|
{
|
|
102
102
|
"taskId": "task-1234567890-abc123",
|
|
103
|
-
"type": "
|
|
103
|
+
"type": "analyze",
|
|
104
104
|
"input": { "text": "..." },
|
|
105
|
-
"replyTo": "0xREQUESTER.../
|
|
105
|
+
"replyTo": "0xREQUESTER.../savantdex/my-app",
|
|
106
106
|
"from": "0xREQUESTER_ADDRESS",
|
|
107
107
|
"ts": 1700000000000
|
|
108
108
|
}
|
|
@@ -113,52 +113,12 @@ Cleanly shuts down the Streamr node.
|
|
|
113
113
|
{
|
|
114
114
|
"taskId": "task-1234567890-abc123",
|
|
115
115
|
"type": "result",
|
|
116
|
-
"output": { "
|
|
116
|
+
"output": { "analysis": "..." },
|
|
117
117
|
"from": "0xWORKER_ADDRESS",
|
|
118
118
|
"ts": 1700000000000
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
## Agent Discovery (Registry)
|
|
123
|
-
|
|
124
|
-
AgentMesh includes a public registry for discovering agents by capability.
|
|
125
|
-
|
|
126
|
-
```js
|
|
127
|
-
// Find an agent that can summarize
|
|
128
|
-
const res = await fetch('http://39.101.135.96:3000/agents/search?capability=summarize')
|
|
129
|
-
const { agents } = await res.json()
|
|
130
|
-
const { streamId } = agents[0]
|
|
131
|
-
|
|
132
|
-
// Send task directly
|
|
133
|
-
const taskId = await agent.sendTask(streamId, {
|
|
134
|
-
type: 'summarize',
|
|
135
|
-
input: { text: 'Your text here...' }
|
|
136
|
-
})
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Registry API
|
|
140
|
-
|
|
141
|
-
| Method | Endpoint | Description |
|
|
142
|
-
|--------|----------|-------------|
|
|
143
|
-
| `POST` | `/agents/register` | Register your agent |
|
|
144
|
-
| `GET` | `/agents/search?capability=xxx` | Search by capability |
|
|
145
|
-
| `GET` | `/agents/search?keyword=xxx` | Search by keyword |
|
|
146
|
-
| `GET` | `/agents/:agentId` | Get agent details |
|
|
147
|
-
| `DELETE` | `/agents/:agentId` | Remove your agent |
|
|
148
|
-
|
|
149
|
-
**Register example:**
|
|
150
|
-
```bash
|
|
151
|
-
curl -X POST http://39.101.135.96:3000/agents/register \
|
|
152
|
-
-H "Content-Type: application/json" \
|
|
153
|
-
-d '{
|
|
154
|
-
"agentId": "my-translator-v1",
|
|
155
|
-
"streamId": "0xYOUR_ADDRESS/agentmesh/my-translator-v1",
|
|
156
|
-
"capabilities": ["translate", "en-to-zh"],
|
|
157
|
-
"description": "Translates English text to Chinese",
|
|
158
|
-
"owner": "0xYOUR_ADDRESS"
|
|
159
|
-
}'
|
|
160
|
-
```
|
|
161
|
-
|
|
162
122
|
## Requirements
|
|
163
123
|
|
|
164
124
|
- Node.js 20+
|
|
@@ -172,11 +132,11 @@ Requester Streamr P2P Network Worker
|
|
|
172
132
|
│ │
|
|
173
133
|
│──── publish task ──────────────────────────────────────► │
|
|
174
134
|
│ │ onTask handler
|
|
175
|
-
│ │ calls AI API
|
|
135
|
+
│ │ calls AI / data API
|
|
176
136
|
│ ◄──── publish result ─────────────────────────────────── │
|
|
177
137
|
│
|
|
178
138
|
waitForResult resolves
|
|
179
139
|
```
|
|
180
140
|
|
|
181
|
-
Each agent has an **inbox stream** on Streamr (`{address}/
|
|
141
|
+
Each agent has an **inbox stream** on Streamr (`{address}/savantdex/{agentId}`).
|
|
182
142
|
Messages are routed peer-to-peer through the Streamr DHT — no central relay.
|