@teneo-protocol/sdk 1.0.0 → 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/.github/workflows/publish-npm.yml +8 -6
- package/CHANGELOG.md +265 -0
- package/README.md +406 -53
- package/dist/core/websocket-client.d.ts +13 -0
- package/dist/core/websocket-client.d.ts.map +1 -1
- package/dist/core/websocket-client.js +34 -3
- package/dist/core/websocket-client.js.map +1 -1
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.d.ts +76 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.js +70 -0
- package/dist/handlers/message-handlers/agent-room-operation-response-handler.js.map +1 -0
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts +92 -38
- package/dist/handlers/message-handlers/agent-selected-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts +904 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.js +51 -0
- package/dist/handlers/message-handlers/agent-status-update-handler.js.map +1 -0
- package/dist/handlers/message-handlers/auth-error-handler.d.ts +45 -31
- package/dist/handlers/message-handlers/auth-error-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-message-handler.js +65 -5
- package/dist/handlers/message-handlers/auth-message-handler.js.map +1 -1
- package/dist/handlers/message-handlers/auth-required-handler.d.ts +49 -31
- package/dist/handlers/message-handlers/auth-required-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.d.ts +6 -0
- package/dist/handlers/message-handlers/auth-success-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/auth-success-handler.js +46 -4
- package/dist/handlers/message-handlers/auth-success-handler.js.map +1 -1
- package/dist/handlers/message-handlers/challenge-handler.d.ts +45 -31
- package/dist/handlers/message-handlers/challenge-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/error-message-handler.d.ts +49 -31
- package/dist/handlers/message-handlers/error-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.d.ts +5 -0
- package/dist/handlers/message-handlers/index.d.ts.map +1 -1
- package/dist/handlers/message-handlers/index.js +23 -1
- package/dist/handlers/message-handlers/index.js.map +1 -1
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts +877 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.js +38 -0
- package/dist/handlers/message-handlers/list-available-agents-handler.js.map +1 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts +886 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.js +51 -0
- package/dist/handlers/message-handlers/list-room-agents-handler.js.map +1 -0
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts +178 -89
- package/dist/handlers/message-handlers/list-rooms-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts +62 -58
- package/dist/handlers/message-handlers/ping-pong-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/regular-message-handler.d.ts +31 -29
- package/dist/handlers/message-handlers/regular-message-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/regular-message-handler.js +1 -0
- package/dist/handlers/message-handlers/regular-message-handler.js.map +1 -1
- package/dist/handlers/message-handlers/room-operation-response-handler.d.ts +328 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.d.ts.map +1 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.js +92 -0
- package/dist/handlers/message-handlers/room-operation-response-handler.js.map +1 -0
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts +53 -31
- package/dist/handlers/message-handlers/subscribe-response-handler.d.ts.map +1 -1
- package/dist/handlers/message-handlers/types.d.ts +2 -0
- package/dist/handlers/message-handlers/types.d.ts.map +1 -1
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts +53 -31
- package/dist/handlers/message-handlers/unsubscribe-response-handler.d.ts.map +1 -1
- package/dist/managers/agent-room-manager.d.ts +222 -0
- package/dist/managers/agent-room-manager.d.ts.map +1 -0
- package/dist/managers/agent-room-manager.js +508 -0
- package/dist/managers/agent-room-manager.js.map +1 -0
- package/dist/managers/index.d.ts +2 -0
- package/dist/managers/index.d.ts.map +1 -1
- package/dist/managers/index.js +5 -1
- package/dist/managers/index.js.map +1 -1
- package/dist/managers/message-router.d.ts +1 -1
- package/dist/managers/message-router.d.ts.map +1 -1
- package/dist/managers/message-router.js +41 -4
- package/dist/managers/message-router.js.map +1 -1
- package/dist/managers/room-management-manager.d.ts +213 -0
- package/dist/managers/room-management-manager.d.ts.map +1 -0
- package/dist/managers/room-management-manager.js +440 -0
- package/dist/managers/room-management-manager.js.map +1 -0
- package/dist/managers/room-manager.d.ts +4 -4
- package/dist/managers/room-manager.d.ts.map +1 -1
- package/dist/managers/room-manager.js +1 -1
- package/dist/managers/room-manager.js.map +1 -1
- package/dist/teneo-sdk.d.ts +362 -14
- package/dist/teneo-sdk.d.ts.map +1 -1
- package/dist/teneo-sdk.js +497 -7
- package/dist/teneo-sdk.js.map +1 -1
- package/dist/types/config.d.ts +63 -54
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +9 -5
- package/dist/types/config.js.map +1 -1
- package/dist/types/error-codes.d.ts +2 -0
- package/dist/types/error-codes.d.ts.map +1 -1
- package/dist/types/error-codes.js +3 -0
- package/dist/types/error-codes.js.map +1 -1
- package/dist/types/events.d.ts +132 -68
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +27 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/messages.d.ts +11396 -2559
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +294 -27
- package/dist/types/messages.js.map +1 -1
- package/dist/types/validation.d.ts.map +1 -1
- package/dist/types/validation.js +1 -1
- package/dist/types/validation.js.map +1 -1
- package/dist/utils/bounded-queue.d.ts +1 -1
- package/dist/utils/bounded-queue.js +6 -6
- package/dist/utils/circuit-breaker.d.ts.map +1 -1
- package/dist/utils/circuit-breaker.js.map +1 -1
- package/dist/utils/event-waiter.d.ts.map +1 -1
- package/dist/utils/event-waiter.js +2 -1
- package/dist/utils/event-waiter.js.map +1 -1
- package/dist/utils/rate-limiter.d.ts.map +1 -1
- package/dist/utils/rate-limiter.js +4 -6
- package/dist/utils/rate-limiter.js.map +1 -1
- package/dist/utils/secure-private-key.d.ts.map +1 -1
- package/dist/utils/secure-private-key.js +9 -15
- package/dist/utils/secure-private-key.js.map +1 -1
- package/dist/utils/signature-verifier.d.ts +2 -2
- package/dist/utils/signature-verifier.d.ts.map +1 -1
- package/dist/utils/signature-verifier.js +5 -5
- package/dist/utils/signature-verifier.js.map +1 -1
- package/examples/.env.example +1 -1
- package/examples/agent-room-management-example.ts +334 -0
- package/examples/claude-agent-x-follower/.env.example +117 -0
- package/examples/claude-agent-x-follower/QUICKSTART.md +243 -0
- package/examples/claude-agent-x-follower/README.md +540 -0
- package/examples/claude-agent-x-follower/index.ts +248 -0
- package/examples/claude-agent-x-follower/package.json +37 -0
- package/examples/claude-agent-x-follower/tsconfig.json +20 -0
- package/examples/n8n-teneo/.env.example +127 -0
- package/examples/n8n-teneo/Dockerfile +42 -0
- package/examples/n8n-teneo/README.md +564 -0
- package/examples/n8n-teneo/docker-compose.yml +71 -0
- package/examples/n8n-teneo/index.ts +177 -0
- package/examples/n8n-teneo/package.json +22 -0
- package/examples/n8n-teneo/tsconfig.json +12 -0
- package/examples/n8n-teneo/workflows/x-timeline.json +66 -0
- package/examples/openai-teneo/.env.example +130 -0
- package/examples/openai-teneo/README.md +635 -0
- package/examples/openai-teneo/index.ts +280 -0
- package/examples/openai-teneo/package.json +24 -0
- package/examples/openai-teneo/tsconfig.json +16 -0
- package/examples/production-dashboard/.env.example +5 -3
- package/examples/production-dashboard/README.md +839 -0
- package/examples/production-dashboard/pnpm-lock.yaml +92 -0
- package/examples/production-dashboard/public/dashboard.html +1150 -504
- package/examples/production-dashboard/server.ts +428 -12
- package/examples/room-management-example.ts +285 -0
- package/examples/usage/.env.example +17 -0
- package/examples/usage/01-connect.ts +116 -0
- package/examples/usage/02-list-agents.ts +153 -0
- package/examples/usage/03-pick-agent.ts +201 -0
- package/examples/usage/04-find-by-capability.ts +237 -0
- package/examples/usage/05-webhook-example.ts +319 -0
- package/examples/usage/06-simple-api-server.ts +396 -0
- package/examples/usage/07-event-listener.ts +402 -0
- package/examples/usage/README.md +383 -0
- package/examples/usage/package.json +42 -0
- package/package.json +13 -3
- package/src/core/websocket-client.ts +43 -9
- package/src/formatters/response-formatter.test.ts +8 -2
- package/src/handlers/message-handlers/agent-room-operation-response-handler.ts +83 -0
- package/src/handlers/message-handlers/agent-status-update-handler.ts +58 -0
- package/src/handlers/message-handlers/auth-message-handler.ts +73 -5
- package/src/handlers/message-handlers/auth-success-handler.ts +58 -6
- package/src/handlers/message-handlers/index.ts +19 -0
- package/src/handlers/message-handlers/list-available-agents-handler.ts +41 -0
- package/src/handlers/message-handlers/list-room-agents-handler.ts +61 -0
- package/src/handlers/message-handlers/regular-message-handler.ts +1 -0
- package/src/handlers/message-handlers/room-operation-response-handler.ts +105 -0
- package/src/handlers/message-handlers/types.ts +6 -0
- package/src/handlers/webhook-handler.test.ts +13 -10
- package/src/managers/agent-room-manager.ts +609 -0
- package/src/managers/index.ts +2 -0
- package/src/managers/message-router.ts +48 -6
- package/src/managers/room-management-manager.ts +523 -0
- package/src/managers/room-manager.ts +12 -6
- package/src/teneo-sdk.ts +543 -10
- package/src/types/config.ts +13 -6
- package/src/types/error-codes.ts +4 -0
- package/src/types/events.ts +24 -0
- package/src/types/index.ts +55 -0
- package/src/types/messages.ts +374 -41
- package/src/types/validation.ts +4 -1
- package/src/utils/bounded-queue.ts +9 -9
- package/src/utils/circuit-breaker.ts +4 -1
- package/src/utils/deduplication-cache.test.ts +2 -6
- package/src/utils/event-waiter.test.ts +4 -1
- package/src/utils/event-waiter.ts +5 -7
- package/src/utils/rate-limiter.test.ts +5 -17
- package/src/utils/rate-limiter.ts +6 -9
- package/src/utils/secure-private-key.test.ts +66 -59
- package/src/utils/secure-private-key.ts +10 -16
- package/src/utils/signature-verifier.test.ts +75 -70
- package/src/utils/signature-verifier.ts +7 -8
- package/src/utils/ssrf-validator.test.ts +3 -3
- package/tests/integration/room-management.test.ts +514 -0
- package/tests/integration/websocket.test.ts +1 -1
- package/tests/unit/handlers/agent-room-operation-response-handler.test.ts +394 -0
- package/tests/unit/handlers/agent-status-update-handler.test.ts +407 -0
- package/tests/unit/handlers/auth-success-handler-rooms.test.ts +699 -0
- package/tests/unit/handlers/list-available-agents-handler.test.ts +256 -0
- package/tests/unit/handlers/list-room-agents-handler.test.ts +294 -0
- package/tests/unit/handlers/room-operation-response-handler.test.ts +527 -0
- package/tests/unit/managers/agent-room-manager.test.ts +534 -0
- package/tests/unit/managers/room-management-manager.test.ts +438 -0
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
# Teneo Consumer SDK + n8n Integration Example
|
|
2
|
+
|
|
3
|
+
**Minimal example** demonstrating how to integrate Teneo Consumer SDK with n8n workflow automation.
|
|
4
|
+
|
|
5
|
+
Similar in scope to the `claude-agent-x-follower` example - simple, focused, and easy to understand.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
This example shows how to:
|
|
12
|
+
1. Wrap Teneo Consumer SDK in a simple Express.js REST API
|
|
13
|
+
2. Deploy the service with n8n using Docker Compose
|
|
14
|
+
3. Create n8n workflows that query Teneo agents
|
|
15
|
+
|
|
16
|
+
### Use Case
|
|
17
|
+
|
|
18
|
+
Query Teneo agents (like X-Agent for Twitter/X data) from visual n8n workflows for social media analysis and automation.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Architecture
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
┌──────────────────────────┐
|
|
26
|
+
│ n8n Workflow │
|
|
27
|
+
│ (Visual Editor) │
|
|
28
|
+
│ - HTTP Request node │
|
|
29
|
+
└──────────┬───────────────┘
|
|
30
|
+
│
|
|
31
|
+
│ POST /query
|
|
32
|
+
│
|
|
33
|
+
┌──────────▼───────────────┐
|
|
34
|
+
│ Teneo Service │
|
|
35
|
+
│ (Express API) │
|
|
36
|
+
│ - GET /health │
|
|
37
|
+
│ - POST /query │
|
|
38
|
+
│ - GET /agents │
|
|
39
|
+
│ ┌────────────────────┐ │
|
|
40
|
+
│ │ Teneo Consumer SDK │ │
|
|
41
|
+
│ └────────────────────┘ │
|
|
42
|
+
└──────────┬───────────────┘
|
|
43
|
+
│
|
|
44
|
+
│ WebSocket
|
|
45
|
+
│
|
|
46
|
+
┌──────────▼───────────────┐
|
|
47
|
+
│ Teneo Network │
|
|
48
|
+
│ (X-Agent, etc.) │
|
|
49
|
+
└──────────────────────────┘
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Services:**
|
|
53
|
+
- **n8n** (port 5678) - Visual workflow automation UI
|
|
54
|
+
- **PostgreSQL** - n8n data persistence
|
|
55
|
+
- **Teneo Service** (port 3000) - REST API wrapper for Teneo SDK
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### Prerequisites
|
|
62
|
+
|
|
63
|
+
- Docker & Docker Compose
|
|
64
|
+
- Teneo account with WebSocket URL and private key
|
|
65
|
+
|
|
66
|
+
### Setup
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# 1. Navigate to this directory
|
|
70
|
+
cd examples/n8n-teneo
|
|
71
|
+
|
|
72
|
+
# 2. Configure environment
|
|
73
|
+
cp .env.example .env
|
|
74
|
+
|
|
75
|
+
# 3. Edit .env with your Teneo credentials
|
|
76
|
+
nano .env # or your preferred editor
|
|
77
|
+
|
|
78
|
+
# Required:
|
|
79
|
+
# WS_URL=wss://your-teneo-server.com/ws
|
|
80
|
+
# PRIVATE_KEY=0x...
|
|
81
|
+
# WALLET_ADDRESS=0x... (optional - auto-derived from private key)
|
|
82
|
+
# DEFAULT_ROOM=general (or x-agent-enterprise-v2 for X features)
|
|
83
|
+
#
|
|
84
|
+
# Optional (all have sensible defaults):
|
|
85
|
+
# ENABLE_SIGNATURE_VERIFICATION=false
|
|
86
|
+
# TRUSTED_ADDRESSES=
|
|
87
|
+
# ENABLE_CACHE=true
|
|
88
|
+
# ENABLE_RECONNECTION=true
|
|
89
|
+
# LOG_LEVEL=info
|
|
90
|
+
|
|
91
|
+
# 4. Start all services
|
|
92
|
+
docker-compose up -d
|
|
93
|
+
|
|
94
|
+
# 5. Watch logs (optional)
|
|
95
|
+
docker-compose logs -f teneo-service
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Verify Setup
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Check Teneo Service health
|
|
102
|
+
curl http://localhost:3000/health
|
|
103
|
+
|
|
104
|
+
# Expected response:
|
|
105
|
+
# {"status":"ok","teneo":{"connected":true,"authenticated":true}}
|
|
106
|
+
|
|
107
|
+
# List available agents
|
|
108
|
+
curl http://localhost:3000/agents
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Access n8n
|
|
112
|
+
|
|
113
|
+
1. Open http://localhost:5678 in your browser
|
|
114
|
+
2. Login with credentials (default: admin / admin)
|
|
115
|
+
3. Import the example workflow from `workflows/x-timeline.json`
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## API Endpoints
|
|
120
|
+
|
|
121
|
+
### GET /health
|
|
122
|
+
|
|
123
|
+
Health check endpoint.
|
|
124
|
+
|
|
125
|
+
**Response:**
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"status": "ok",
|
|
129
|
+
"teneo": {
|
|
130
|
+
"connected": true,
|
|
131
|
+
"authenticated": true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### POST /query
|
|
137
|
+
|
|
138
|
+
Send a message to Teneo coordinator (auto-selects appropriate agent).
|
|
139
|
+
|
|
140
|
+
**Request:**
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"message": "timeline @elonmusk 10",
|
|
144
|
+
"timeout": 30000
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Response:**
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"success": true,
|
|
152
|
+
"data": {
|
|
153
|
+
"humanized": "Here are the latest 10 tweets from @elonmusk...",
|
|
154
|
+
"raw": { /* full agent response */ },
|
|
155
|
+
"metadata": {
|
|
156
|
+
"agentName": "X-Agent",
|
|
157
|
+
"duration": 2500
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Error Response:**
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"success": false,
|
|
167
|
+
"error": "No response from agent"
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### GET /agents
|
|
172
|
+
|
|
173
|
+
List available Teneo agents.
|
|
174
|
+
|
|
175
|
+
**Response:**
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"success": true,
|
|
179
|
+
"agents": [
|
|
180
|
+
{
|
|
181
|
+
"id": "x-agent",
|
|
182
|
+
"name": "X-Agent",
|
|
183
|
+
"description": "Twitter/X data retrieval",
|
|
184
|
+
"capabilities": ["timeline", "search", "user"]
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Creating n8n Workflows
|
|
193
|
+
|
|
194
|
+
### Method 1: Import Example Workflow
|
|
195
|
+
|
|
196
|
+
1. In n8n, go to **Workflows** → **Import from File**
|
|
197
|
+
2. Select `workflows/x-timeline.json`
|
|
198
|
+
3. Click **Test workflow** to execute
|
|
199
|
+
|
|
200
|
+
### Method 2: Create Manually
|
|
201
|
+
|
|
202
|
+
1. Add **Manual Trigger** node
|
|
203
|
+
2. Add **HTTP Request** node:
|
|
204
|
+
- **Method**: POST
|
|
205
|
+
- **URL**: `http://teneo-service:3000/query`
|
|
206
|
+
- **Body**: JSON
|
|
207
|
+
- **JSON Body**:
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"message": "timeline @elonmusk 10"
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
3. Add **Set** node to extract response:
|
|
214
|
+
- Add field: `response` = `{{ $json.data.humanized }}`
|
|
215
|
+
- Add field: `agent` = `{{ $json.data.metadata.agentName }}`
|
|
216
|
+
4. Connect nodes and execute!
|
|
217
|
+
|
|
218
|
+
### Example Queries
|
|
219
|
+
|
|
220
|
+
**X Timeline:**
|
|
221
|
+
```json
|
|
222
|
+
{ "message": "timeline @elonmusk 10" }
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**X User Search:**
|
|
226
|
+
```json
|
|
227
|
+
{ "message": "search user elonmusk" }
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**X Tweet Search:**
|
|
231
|
+
```json
|
|
232
|
+
{ "message": "search tweets AI agents" }
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Development
|
|
238
|
+
|
|
239
|
+
### Local Development (without Docker)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Install dependencies
|
|
243
|
+
npm install
|
|
244
|
+
|
|
245
|
+
# Create .env file with your credentials
|
|
246
|
+
cp .env.example .env
|
|
247
|
+
nano .env
|
|
248
|
+
|
|
249
|
+
# Start in watch mode
|
|
250
|
+
npm run dev
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Testing Locally
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Test health
|
|
257
|
+
curl http://localhost:3000/health
|
|
258
|
+
|
|
259
|
+
# Test query
|
|
260
|
+
curl -X POST http://localhost:3000/query \
|
|
261
|
+
-H "Content-Type: application/json" \
|
|
262
|
+
-d '{"message": "timeline @elonmusk 10"}'
|
|
263
|
+
|
|
264
|
+
# Test agents list
|
|
265
|
+
curl http://localhost:3000/agents
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Troubleshooting
|
|
271
|
+
|
|
272
|
+
### Teneo Service won't connect
|
|
273
|
+
|
|
274
|
+
**Problem:** Teneo Service logs show connection errors
|
|
275
|
+
|
|
276
|
+
**Solutions:**
|
|
277
|
+
- Verify `WS_URL` and `PRIVATE_KEY` in `.env`
|
|
278
|
+
- Ensure `PRIVATE_KEY` starts with `0x` prefix
|
|
279
|
+
- Check if Teneo endpoint is accessible
|
|
280
|
+
- View logs: `docker-compose logs teneo-service`
|
|
281
|
+
- Restart service: `docker-compose restart teneo-service`
|
|
282
|
+
- Set `LOG_LEVEL=debug` in `.env` for detailed diagnostics
|
|
283
|
+
|
|
284
|
+
### Wallet not whitelisted
|
|
285
|
+
|
|
286
|
+
**Problem:** Logs show "Access restricted: Your wallet is not whitelisted"
|
|
287
|
+
|
|
288
|
+
**Solutions:**
|
|
289
|
+
- Contact your Teneo administrator to whitelist your wallet address
|
|
290
|
+
- Verify you're using the correct room in `DEFAULT_ROOM`
|
|
291
|
+
- Check your `WALLET_ADDRESS` (or let it auto-derive from `PRIVATE_KEY`)
|
|
292
|
+
|
|
293
|
+
### Message format errors
|
|
294
|
+
|
|
295
|
+
**Problem:** Server returns "Agents should use TypeTaskResponse instead of TypeMessage" (code: 400)
|
|
296
|
+
|
|
297
|
+
**Solutions:**
|
|
298
|
+
- Try `DEFAULT_ROOM=general` instead of `x-agent-enterprise-v2`
|
|
299
|
+
- This is a server-side protocol error, not an SDK configuration issue
|
|
300
|
+
- Contact your Teneo administrator about room configuration
|
|
301
|
+
|
|
302
|
+
### n8n can't reach Teneo Service
|
|
303
|
+
|
|
304
|
+
**Problem:** HTTP Request node times out or gets connection refused
|
|
305
|
+
|
|
306
|
+
**Solutions:**
|
|
307
|
+
- Use `http://teneo-service:3000` (Docker network name), NOT `localhost`
|
|
308
|
+
- Verify both services are on same network: `docker-compose ps`
|
|
309
|
+
- Check Teneo Service is healthy: `curl http://localhost:3000/health`
|
|
310
|
+
|
|
311
|
+
### Timeout errors
|
|
312
|
+
|
|
313
|
+
**Problem:** Queries timeout before response
|
|
314
|
+
|
|
315
|
+
**Note:** The SDK now includes **intelligent fallback matching** that resolves most timeout issues automatically!
|
|
316
|
+
|
|
317
|
+
**Solutions:**
|
|
318
|
+
- The SDK uses room-based fallback matching when servers don't echo `client_request_id`
|
|
319
|
+
- Typical response time: 2-3 seconds with fallback matching
|
|
320
|
+
- Increase timeout if needed: `{"message": "...", "timeout": 60000}`
|
|
321
|
+
- Check if agent is online: `curl http://localhost:3000/agents`
|
|
322
|
+
- Verify agent responds: Test query directly via curl
|
|
323
|
+
- Enable debug logging: Set `LOG_LEVEL=debug` in `.env` to see fallback matching in action
|
|
324
|
+
|
|
325
|
+
### n8n login issues
|
|
326
|
+
|
|
327
|
+
**Problem:** Can't login to n8n UI
|
|
328
|
+
|
|
329
|
+
**Solutions:**
|
|
330
|
+
- Default credentials: admin / admin
|
|
331
|
+
- Check environment: `docker-compose config | grep N8N_`
|
|
332
|
+
- Reset password: Update `N8N_PASSWORD` in `.env` and restart
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Docker Commands
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# Start services
|
|
340
|
+
docker-compose up -d
|
|
341
|
+
|
|
342
|
+
# Stop services
|
|
343
|
+
docker-compose down
|
|
344
|
+
|
|
345
|
+
# View logs
|
|
346
|
+
docker-compose logs -f
|
|
347
|
+
|
|
348
|
+
# View specific service logs
|
|
349
|
+
docker-compose logs -f teneo-service
|
|
350
|
+
docker-compose logs -f n8n
|
|
351
|
+
|
|
352
|
+
# Restart a service
|
|
353
|
+
docker-compose restart teneo-service
|
|
354
|
+
|
|
355
|
+
# Rebuild after code changes
|
|
356
|
+
docker-compose up -d --build
|
|
357
|
+
|
|
358
|
+
# Stop and remove all data (including workflows!)
|
|
359
|
+
docker-compose down -v
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## Project Structure
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
examples/n8n-teneo/
|
|
368
|
+
├── index.ts # Main Teneo Service (Express + SDK)
|
|
369
|
+
├── docker-compose.yml # Docker setup (n8n + PostgreSQL + Teneo Service)
|
|
370
|
+
├── Dockerfile # Teneo Service Docker image
|
|
371
|
+
├── package.json # Dependencies
|
|
372
|
+
├── tsconfig.json # TypeScript config
|
|
373
|
+
├── .env.example # Environment template
|
|
374
|
+
├── .gitignore # Git ignore rules
|
|
375
|
+
├── README.md # This file
|
|
376
|
+
└── workflows/
|
|
377
|
+
└── x-timeline.json # Example n8n workflow
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## SDK Configuration
|
|
383
|
+
|
|
384
|
+
This example uses the **modern SDKConfigBuilder pattern** for clean, type-safe configuration.
|
|
385
|
+
|
|
386
|
+
### Configuration Pattern
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
import { SDKConfigBuilder, TeneoSDK } from '../../dist/index.js';
|
|
390
|
+
|
|
391
|
+
const config = new SDKConfigBuilder()
|
|
392
|
+
.withWebSocketUrl(WS_URL)
|
|
393
|
+
.withAuthentication(PRIVATE_KEY, WALLET_ADDRESS) // Wallet auto-derived if not provided
|
|
394
|
+
.withRoom(DEFAULT_ROOM)
|
|
395
|
+
.withReconnection({ enabled: true, delay: 5000, maxAttempts: 10 })
|
|
396
|
+
.withResponseFormat({ format: 'both', includeMetadata: true })
|
|
397
|
+
.withLogging(LOG_LEVEL)
|
|
398
|
+
.withCache(true, 300000, 100)
|
|
399
|
+
.withSignatureVerification({
|
|
400
|
+
enabled: ENABLE_SIG_VERIFICATION,
|
|
401
|
+
trustedAddresses: TRUSTED_ADDRESSES,
|
|
402
|
+
requireFor: ['task_response', 'agent_selected'],
|
|
403
|
+
strictMode: false
|
|
404
|
+
})
|
|
405
|
+
.build();
|
|
406
|
+
|
|
407
|
+
const teneoSDK = new TeneoSDK(config);
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Key Features
|
|
411
|
+
|
|
412
|
+
- ✅ **Automatic Wallet Derivation**: Wallet address automatically derived from private key using viem
|
|
413
|
+
- ✅ **Auto-Reconnection**: Automatic reconnection with exponential backoff
|
|
414
|
+
- ✅ **Response Caching**: Agent response caching for better performance
|
|
415
|
+
- ✅ **Signature Verification**: Optional SEC-2 message signature verification
|
|
416
|
+
- ✅ **Flexible Configuration**: Environment-based with sensible defaults
|
|
417
|
+
- ✅ **Type Safety**: Full TypeScript support with Zod validation
|
|
418
|
+
|
|
419
|
+
### Environment Variables
|
|
420
|
+
|
|
421
|
+
All configuration is loaded from environment variables (`.env` file):
|
|
422
|
+
|
|
423
|
+
**Required:**
|
|
424
|
+
- `WS_URL` - Teneo WebSocket endpoint
|
|
425
|
+
- `PRIVATE_KEY` - Ethereum private key (with 0x prefix)
|
|
426
|
+
|
|
427
|
+
**Optional (with defaults):**
|
|
428
|
+
- `WALLET_ADDRESS` - Ethereum wallet (auto-derived if not provided)
|
|
429
|
+
- `DEFAULT_ROOM` - Room to join (default: `general`)
|
|
430
|
+
- `ENABLE_SIGNATURE_VERIFICATION` - Enable SEC-2 verification (default: `false`)
|
|
431
|
+
- `TRUSTED_ADDRESSES` - Comma-separated trusted agent addresses
|
|
432
|
+
- `ENABLE_CACHE` - Enable agent caching (default: `true`)
|
|
433
|
+
- `CACHE_TIMEOUT` - Cache timeout in ms (default: `300000`)
|
|
434
|
+
- `MAX_CACHE_SIZE` - Max cache entries (default: `100`)
|
|
435
|
+
- `ENABLE_RECONNECTION` - Enable auto-reconnect (default: `true`)
|
|
436
|
+
- `RECONNECT_DELAY` - Reconnect delay in ms (default: `5000`)
|
|
437
|
+
- `MAX_RECONNECT_ATTEMPTS` - Max reconnect attempts (default: `10`)
|
|
438
|
+
- `LOG_LEVEL` - Logging level: debug|info|warn|error|silent (default: `info`)
|
|
439
|
+
- `PORT` - API server port (default: `3000`)
|
|
440
|
+
|
|
441
|
+
See `.env.example` for complete documentation.
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
## SDK Improvements
|
|
446
|
+
|
|
447
|
+
This example benefits from recent SDK improvements:
|
|
448
|
+
|
|
449
|
+
### Intelligent Fallback Matching
|
|
450
|
+
|
|
451
|
+
The SDK now includes **two-tier message correlation** for reliable response handling:
|
|
452
|
+
|
|
453
|
+
1. **Primary Matching**: Uses `client_request_id` when server supports it
|
|
454
|
+
2. **Fallback Matching**: Uses room + time window (60s) when server doesn't support request IDs
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
// Both coordinator and direct agent calls use waitForResponse
|
|
458
|
+
if (agent) {
|
|
459
|
+
response = await teneoSDK.sendDirectCommand({
|
|
460
|
+
agent,
|
|
461
|
+
command: message,
|
|
462
|
+
room: DEFAULT_ROOM
|
|
463
|
+
}, true); // waitForResponse = true - SDK handles matching automatically
|
|
464
|
+
} else {
|
|
465
|
+
response = await teneoSDK.sendMessage(message, {
|
|
466
|
+
waitForResponse: true,
|
|
467
|
+
timeout
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**Benefits:**
|
|
473
|
+
- Works with all Teneo server implementations
|
|
474
|
+
- Typical response time: **2-3 seconds**
|
|
475
|
+
- No manual event listener management
|
|
476
|
+
- Automatic retry with exponential backoff
|
|
477
|
+
|
|
478
|
+
### Enhanced Message Handling
|
|
479
|
+
|
|
480
|
+
The SDK properly handles both "message" and "task_response" types from agents:
|
|
481
|
+
|
|
482
|
+
- X-Agent and other agents that send "message" type responses work seamlessly
|
|
483
|
+
- Task-based agents with "task_response" type also work
|
|
484
|
+
- Both types include full metadata and correlation fields
|
|
485
|
+
|
|
486
|
+
## Comparison with Other Examples
|
|
487
|
+
|
|
488
|
+
| Aspect | n8n-teneo | claude-agent-x-follower | openai-teneo |
|
|
489
|
+
|--------|-----------|------------------------|--------------|
|
|
490
|
+
| **Integration** | n8n Workflows | Claude Agent SDK | OpenAI Codex SDK |
|
|
491
|
+
| **Main File** | 1 file (~180 lines) | 1 file (~220 lines) | 1 file (~280 lines) |
|
|
492
|
+
| **Setup** | Docker Compose | npm install + run | npm install + run |
|
|
493
|
+
| **Interface** | Visual Web UI | CLI | REST API |
|
|
494
|
+
| **AI Model** | N/A (HTTP only) | Claude 3.5 | OpenAI Codex |
|
|
495
|
+
| **Use Case** | Visual automation | Developer tool | API integration |
|
|
496
|
+
| **Agent Selection** | Manual | Custom MCP Tool | Intelligent (Codex) |
|
|
497
|
+
| **Complexity** | Minimal | Minimal | Minimal |
|
|
498
|
+
| **Response Time** | 2-3 seconds | 2-3 seconds | 2-3 seconds |
|
|
499
|
+
|
|
500
|
+
All examples use the **modern SDKConfigBuilder pattern** with:
|
|
501
|
+
- ✅ Automatic wallet derivation from private key
|
|
502
|
+
- ✅ Auto-reconnection with exponential backoff
|
|
503
|
+
- ✅ Agent response caching for better performance
|
|
504
|
+
- ✅ Optional SEC-2 signature verification
|
|
505
|
+
- ✅ **SDK-level fallback matching for reliable message correlation**
|
|
506
|
+
- ✅ Comprehensive environment-based configuration with 15+ options
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## Next Steps
|
|
511
|
+
|
|
512
|
+
### Extend the Example
|
|
513
|
+
|
|
514
|
+
1. **Add More Endpoints**
|
|
515
|
+
- Add `/direct` endpoint for direct agent queries
|
|
516
|
+
- Add webhook configuration endpoint
|
|
517
|
+
- Add signature verification status endpoint
|
|
518
|
+
|
|
519
|
+
2. **Advanced Workflows**
|
|
520
|
+
- Schedule periodic X timeline checks
|
|
521
|
+
- Trigger workflows from Teneo events
|
|
522
|
+
- Multi-step agent orchestration
|
|
523
|
+
- Implement circuit breaker for reliability
|
|
524
|
+
|
|
525
|
+
3. **Production Deployment**
|
|
526
|
+
- Add authentication (API keys)
|
|
527
|
+
- Add rate limiting
|
|
528
|
+
- Add monitoring and logging
|
|
529
|
+
- Enable signature verification (SEC-2)
|
|
530
|
+
- Configure trusted agent addresses
|
|
531
|
+
- Deploy to cloud (AWS, GCP, Azure)
|
|
532
|
+
- Use environment variables instead of .env file
|
|
533
|
+
|
|
534
|
+
4. **Leverage New SDK Features**
|
|
535
|
+
- Use auto-reconnection for better reliability
|
|
536
|
+
- Enable response caching for performance
|
|
537
|
+
- Implement signature verification for security
|
|
538
|
+
- Monitor cache hit rates and adjust settings
|
|
539
|
+
- Set up webhook integration for real-time events
|
|
540
|
+
|
|
541
|
+
### Learn More
|
|
542
|
+
|
|
543
|
+
- **Teneo SDK Docs**: See `../../TENEO_CONSUMER_SDK.md`
|
|
544
|
+
- **n8n Documentation**: https://docs.n8n.io/
|
|
545
|
+
- **Docker Compose**: https://docs.docker.com/compose/
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## License
|
|
550
|
+
|
|
551
|
+
MIT
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Support
|
|
556
|
+
|
|
557
|
+
For issues or questions:
|
|
558
|
+
- Teneo SDK: See main repository issues
|
|
559
|
+
- n8n: https://community.n8n.io/
|
|
560
|
+
- This example: Open an issue in the main repository
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
**Happy automating!** 🚀
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
services:
|
|
2
|
+
# PostgreSQL for n8n
|
|
3
|
+
postgres:
|
|
4
|
+
image: postgres:16-alpine
|
|
5
|
+
environment:
|
|
6
|
+
POSTGRES_DB: n8n
|
|
7
|
+
POSTGRES_USER: n8n
|
|
8
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-n8npassword}
|
|
9
|
+
volumes:
|
|
10
|
+
- postgres_data:/var/lib/postgresql/data
|
|
11
|
+
healthcheck:
|
|
12
|
+
test: ["CMD-SHELL", "pg_isready -U n8n"]
|
|
13
|
+
interval: 10s
|
|
14
|
+
timeout: 5s
|
|
15
|
+
retries: 5
|
|
16
|
+
networks:
|
|
17
|
+
- teneo-net
|
|
18
|
+
|
|
19
|
+
# n8n workflow automation
|
|
20
|
+
n8n:
|
|
21
|
+
image: n8nio/n8n:latest
|
|
22
|
+
ports:
|
|
23
|
+
- "5678:5678"
|
|
24
|
+
environment:
|
|
25
|
+
- DB_TYPE=postgresdb
|
|
26
|
+
- DB_POSTGRESDB_HOST=postgres
|
|
27
|
+
- DB_POSTGRESDB_DATABASE=n8n
|
|
28
|
+
- DB_POSTGRESDB_USER=n8n
|
|
29
|
+
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD:-n8npassword}
|
|
30
|
+
- N8N_BASIC_AUTH_ACTIVE=true
|
|
31
|
+
- N8N_BASIC_AUTH_USER=${N8N_USER:-admin}
|
|
32
|
+
- N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD:-admin}
|
|
33
|
+
- WEBHOOK_URL=http://localhost:5678/
|
|
34
|
+
volumes:
|
|
35
|
+
- n8n_data:/home/node/.n8n
|
|
36
|
+
- ./workflows:/workflows:ro
|
|
37
|
+
depends_on:
|
|
38
|
+
postgres:
|
|
39
|
+
condition: service_healthy
|
|
40
|
+
networks:
|
|
41
|
+
- teneo-net
|
|
42
|
+
|
|
43
|
+
# Teneo SDK Service
|
|
44
|
+
teneo-service:
|
|
45
|
+
build:
|
|
46
|
+
context: ../..
|
|
47
|
+
dockerfile: examples/n8n-teneo/Dockerfile
|
|
48
|
+
ports:
|
|
49
|
+
- "3000:3000"
|
|
50
|
+
environment:
|
|
51
|
+
- WS_URL=${WS_URL}
|
|
52
|
+
- PRIVATE_KEY=${PRIVATE_KEY}
|
|
53
|
+
- DEFAULT_ROOM=${DEFAULT_ROOM:-x-agent-enterprise-v2}
|
|
54
|
+
- PORT=3000
|
|
55
|
+
networks:
|
|
56
|
+
- teneo-net
|
|
57
|
+
restart: unless-stopped
|
|
58
|
+
healthcheck:
|
|
59
|
+
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
|
|
60
|
+
interval: 30s
|
|
61
|
+
timeout: 10s
|
|
62
|
+
retries: 3
|
|
63
|
+
start_period: 40s
|
|
64
|
+
|
|
65
|
+
volumes:
|
|
66
|
+
postgres_data:
|
|
67
|
+
n8n_data:
|
|
68
|
+
|
|
69
|
+
networks:
|
|
70
|
+
teneo-net:
|
|
71
|
+
driver: bridge
|