@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,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal example: Claude Agent SDK + Teneo Consumer SDK
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to:
|
|
5
|
+
* 1. Create a Claude Agent with a custom tool
|
|
6
|
+
* 2. Use the tool to call Teneo SDK and fetch X/Twitter timelines
|
|
7
|
+
* 3. Return structured results to Claude
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import 'dotenv/config';
|
|
11
|
+
import { query, tool, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { SDKConfigBuilder, TeneoSDK } from '../../dist/index.js';
|
|
14
|
+
|
|
15
|
+
// Load environment variables
|
|
16
|
+
const WS_URL = process.env.WS_URL || '';
|
|
17
|
+
const PRIVATE_KEY = process.env.PRIVATE_KEY || '';
|
|
18
|
+
const WALLET_ADDRESS = process.env.WALLET_ADDRESS || '';
|
|
19
|
+
const DEFAULT_ROOM = process.env.DEFAULT_ROOM || 'general';
|
|
20
|
+
const LOG_LEVEL = (process.env.LOG_LEVEL || 'info') as 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
21
|
+
const ENABLE_SIG_VERIFICATION = process.env.ENABLE_SIGNATURE_VERIFICATION === 'true';
|
|
22
|
+
const TRUSTED_ADDRESSES = process.env.TRUSTED_ADDRESSES?.split(',').filter(Boolean) || [];
|
|
23
|
+
const ENABLE_CACHE = process.env.ENABLE_CACHE !== 'false';
|
|
24
|
+
const CACHE_TIMEOUT = parseInt(process.env.CACHE_TIMEOUT || '300000');
|
|
25
|
+
const MAX_CACHE_SIZE = parseInt(process.env.MAX_CACHE_SIZE || '100');
|
|
26
|
+
const ENABLE_RECONNECTION = process.env.ENABLE_RECONNECTION !== 'false';
|
|
27
|
+
const RECONNECT_DELAY = parseInt(process.env.RECONNECT_DELAY || '5000');
|
|
28
|
+
const MAX_RECONNECT_ATTEMPTS = parseInt(process.env.MAX_RECONNECT_ATTEMPTS || '10');
|
|
29
|
+
|
|
30
|
+
// Validate required environment variables
|
|
31
|
+
if (!WS_URL || !PRIVATE_KEY) {
|
|
32
|
+
console.error('Missing required environment variables');
|
|
33
|
+
console.error('Required: WS_URL, PRIVATE_KEY');
|
|
34
|
+
console.error('Note: ANTHROPIC_API_KEY is optional if Claude CLI is authenticated');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Initialize Teneo SDK using SDKConfigBuilder pattern
|
|
39
|
+
const config = new SDKConfigBuilder()
|
|
40
|
+
.withWebSocketUrl(WS_URL)
|
|
41
|
+
.withAuthentication(PRIVATE_KEY, WALLET_ADDRESS)
|
|
42
|
+
.withAutoJoinRooms([DEFAULT_ROOM])
|
|
43
|
+
.withReconnection({
|
|
44
|
+
enabled: ENABLE_RECONNECTION,
|
|
45
|
+
delay: RECONNECT_DELAY,
|
|
46
|
+
maxAttempts: MAX_RECONNECT_ATTEMPTS
|
|
47
|
+
})
|
|
48
|
+
.withResponseFormat({ format: 'both', includeMetadata: true })
|
|
49
|
+
.withLogging(LOG_LEVEL)
|
|
50
|
+
.withCache(ENABLE_CACHE, CACHE_TIMEOUT, MAX_CACHE_SIZE)
|
|
51
|
+
.withSignatureVerification({
|
|
52
|
+
enabled: ENABLE_SIG_VERIFICATION,
|
|
53
|
+
trustedAddresses: TRUSTED_ADDRESSES,
|
|
54
|
+
requireFor: ['task_response', 'agent_selected'],
|
|
55
|
+
strictMode: false
|
|
56
|
+
})
|
|
57
|
+
.build();
|
|
58
|
+
|
|
59
|
+
const teneoSDK = new TeneoSDK(config);
|
|
60
|
+
|
|
61
|
+
// Define the tool for Claude Agent
|
|
62
|
+
// Note: Pass Zod shape directly (ZodRawShape), not z.object()
|
|
63
|
+
const getXTimelineTool = tool(
|
|
64
|
+
'get_x_timeline',
|
|
65
|
+
'Fetch X/Twitter timeline for a given username using Teneo X-Agent. Returns recent tweets and engagement data.',
|
|
66
|
+
{
|
|
67
|
+
username: z.string().describe('X/Twitter username (without @)'),
|
|
68
|
+
count: z.number().min(1).max(100).default(20).describe('Number of tweets to fetch')
|
|
69
|
+
},
|
|
70
|
+
async (args) => {
|
|
71
|
+
const { username, count } = args;
|
|
72
|
+
|
|
73
|
+
console.log('\n' + '='.repeat(60));
|
|
74
|
+
console.log('🔧 TOOL INVOKED: get_x_timeline');
|
|
75
|
+
console.log('='.repeat(60));
|
|
76
|
+
console.log(`📥 Input: username="${username}", count=${count}`);
|
|
77
|
+
console.log(`\n🔍 Fetching timeline for @${username} (${count} tweets)...\n`);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
// Get available agents to find the X Platform Agent
|
|
81
|
+
const agents = teneoSDK.getAgents();
|
|
82
|
+
console.log(`📋 Found ${agents.length} available agents`);
|
|
83
|
+
|
|
84
|
+
// Find X Platform Agent by name or ID
|
|
85
|
+
const xAgent = agents.find(a =>
|
|
86
|
+
a.name?.toLowerCase().includes('x platform agent') ||
|
|
87
|
+
a.id?.toLowerCase().includes('x-agent-enterprise-v2')
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (!xAgent) {
|
|
91
|
+
console.error('❌ X Platform Agent not found in available agents');
|
|
92
|
+
console.log('Available agents:', agents.map(a => ({ id: a.id, name: a.name })));
|
|
93
|
+
return {
|
|
94
|
+
content: [{
|
|
95
|
+
type: 'text' as const,
|
|
96
|
+
text: JSON.stringify({
|
|
97
|
+
success: false,
|
|
98
|
+
error: 'X Platform Agent not found. Available agents: ' + agents.map(a => a.name || a.id).join(', ')
|
|
99
|
+
})
|
|
100
|
+
}]
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`🎯 Using agent: ${xAgent.name || xAgent.id}`);
|
|
105
|
+
|
|
106
|
+
// Send direct command to X-Agent (bypasses coordinator)
|
|
107
|
+
// We pre-selected the X Platform Agent, so we use sendDirectCommand()
|
|
108
|
+
// instead of sendMessage() to send directly to this specific agent
|
|
109
|
+
const waitForResponse = true;
|
|
110
|
+
const response = await teneoSDK.sendDirectCommand({
|
|
111
|
+
agent: xAgent.id,
|
|
112
|
+
command: `timeline @${username} ${count}`,
|
|
113
|
+
room: DEFAULT_ROOM
|
|
114
|
+
}, waitForResponse);
|
|
115
|
+
|
|
116
|
+
console.log('📨 Received response from Teneo:', response ? 'Yes' : 'No');
|
|
117
|
+
|
|
118
|
+
if (!response?.humanized) {
|
|
119
|
+
return {
|
|
120
|
+
content: [{
|
|
121
|
+
type: 'text' as const,
|
|
122
|
+
text: JSON.stringify({
|
|
123
|
+
success: false,
|
|
124
|
+
error: 'No response from X-Agent'
|
|
125
|
+
})
|
|
126
|
+
}]
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
console.log(`✅ Successfully fetched timeline for @${username}\n`);
|
|
131
|
+
|
|
132
|
+
// Return the timeline data in Claude's expected format
|
|
133
|
+
return {
|
|
134
|
+
content: [{
|
|
135
|
+
type: 'text' as const,
|
|
136
|
+
text: JSON.stringify({
|
|
137
|
+
success: true,
|
|
138
|
+
username: username,
|
|
139
|
+
count: count,
|
|
140
|
+
timeline: response.humanized,
|
|
141
|
+
raw_data: response.raw
|
|
142
|
+
}, null, 2)
|
|
143
|
+
}]
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error('Error fetching timeline:', error);
|
|
148
|
+
return {
|
|
149
|
+
content: [{
|
|
150
|
+
type: 'text' as const,
|
|
151
|
+
text: JSON.stringify({
|
|
152
|
+
success: false,
|
|
153
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
154
|
+
})
|
|
155
|
+
}]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// Create MCP server with the tool
|
|
162
|
+
const teneoMcpServer = createSdkMcpServer({
|
|
163
|
+
name: 'TeneoXAgent',
|
|
164
|
+
version: '1.0.0',
|
|
165
|
+
tools: [getXTimelineTool]
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Main function
|
|
169
|
+
async function main() {
|
|
170
|
+
console.log('🤖 Claude Agent + Teneo SDK - X Timeline Follower\n');
|
|
171
|
+
|
|
172
|
+
// Connect to Teneo
|
|
173
|
+
console.log('📡 Connecting to Teneo network...');
|
|
174
|
+
await teneoSDK.connect();
|
|
175
|
+
console.log('✅ Connected to Teneo\n');
|
|
176
|
+
|
|
177
|
+
// Get prompt from command line or use default
|
|
178
|
+
const userPrompt = process.argv[2] ||
|
|
179
|
+
'Use the get_x_timeline tool to get the timeline for elonmusk for 5 tweets';
|
|
180
|
+
|
|
181
|
+
console.log(`💬 Prompt: "${userPrompt}"\n`);
|
|
182
|
+
console.log('🧠 Claude is processing...\n');
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
// Query Claude with the custom tool
|
|
186
|
+
// API key is read from ANTHROPIC_API_KEY environment variable
|
|
187
|
+
const result = query({
|
|
188
|
+
prompt: userPrompt,
|
|
189
|
+
options: {
|
|
190
|
+
model: 'claude-3-5-haiku-20241022',
|
|
191
|
+
pathToClaudeCodeExecutable: process.env.HOME + '/.claude/local/claude',
|
|
192
|
+
permissionMode: 'bypassPermissions', // Allow tool use without asking
|
|
193
|
+
mcpServers: {
|
|
194
|
+
teneo: teneoMcpServer
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
console.log('\n' + '='.repeat(60));
|
|
200
|
+
console.log('📝 CLAUDE RESPONSE:');
|
|
201
|
+
console.log('='.repeat(60));
|
|
202
|
+
|
|
203
|
+
// Stream the response
|
|
204
|
+
for await (const message of result) {
|
|
205
|
+
if (message.type === 'result') {
|
|
206
|
+
// Show the final result in a readable format
|
|
207
|
+
console.log('\n📊 Final Result:');
|
|
208
|
+
|
|
209
|
+
// Check if it's an error result
|
|
210
|
+
if (message.is_error) {
|
|
211
|
+
console.log('❌ Error occurred during execution');
|
|
212
|
+
console.log(message);
|
|
213
|
+
} else {
|
|
214
|
+
// Success result - TypeScript narrows the type here
|
|
215
|
+
console.log((message as any).result || 'No result returned');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
console.log(`\n⏱️ Duration: ${message.duration_ms}ms`);
|
|
219
|
+
console.log(`💰 Cost: $${message.total_cost_usd.toFixed(6)}`);
|
|
220
|
+
console.log(`🔄 Turns: ${message.num_turns}`);
|
|
221
|
+
} else {
|
|
222
|
+
// Show other messages for debugging
|
|
223
|
+
console.log(message);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log('='.repeat(60) + '\n');
|
|
228
|
+
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error('\n❌ Claude query error:', error);
|
|
231
|
+
} finally {
|
|
232
|
+
// Cleanup
|
|
233
|
+
teneoSDK.disconnect();
|
|
234
|
+
teneoSDK.destroy();
|
|
235
|
+
console.log('✅ Done!\n');
|
|
236
|
+
|
|
237
|
+
// Force exit to prevent hanging
|
|
238
|
+
setTimeout(() => process.exit(0), 500);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Run with error handling
|
|
243
|
+
main().catch((error) => {
|
|
244
|
+
console.error('\n❌ Error:', error);
|
|
245
|
+
teneoSDK.disconnect();
|
|
246
|
+
teneoSDK.destroy();
|
|
247
|
+
process.exit(1);
|
|
248
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teneo/claude-agent-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Minimal example: Claude Agent SDK + Teneo Consumer SDK integration",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "index.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"start": "tsx index.ts",
|
|
10
|
+
"dev": "tsx watch index.ts"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@anthropic-ai/claude-agent-sdk": "^0.1.15",
|
|
14
|
+
"@teneo-protocol/sdk": "file:../..",
|
|
15
|
+
"dotenv": "^16.4.0",
|
|
16
|
+
"zod": "^3.22.4"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^20.10.5",
|
|
20
|
+
"tsx": "^4.7.0",
|
|
21
|
+
"typescript": "^5.3.3"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"teneo",
|
|
28
|
+
"sdk",
|
|
29
|
+
"claude",
|
|
30
|
+
"anthropic",
|
|
31
|
+
"example",
|
|
32
|
+
"agent",
|
|
33
|
+
"mcp"
|
|
34
|
+
],
|
|
35
|
+
"author": "Teneo Protocol",
|
|
36
|
+
"license": "MIT"
|
|
37
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "./",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"target": "ES2022",
|
|
8
|
+
"lib": ["ES2022"],
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noEmit": true
|
|
17
|
+
},
|
|
18
|
+
"include": ["*.ts"],
|
|
19
|
+
"exclude": ["node_modules", "dist"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# n8n + Teneo Service - Environment Configuration
|
|
2
|
+
# Copy this file to .env and fill in your values
|
|
3
|
+
|
|
4
|
+
# ============================================================================
|
|
5
|
+
# REQUIRED: Teneo Network Connection
|
|
6
|
+
# ============================================================================
|
|
7
|
+
|
|
8
|
+
# WebSocket URL for Teneo AI Network
|
|
9
|
+
# Production: wss://your-production-server.com/ws
|
|
10
|
+
# Development: wss://your-teneo-server.com/ws
|
|
11
|
+
WS_URL=wss://your-teneo-server.com/ws
|
|
12
|
+
|
|
13
|
+
# Ethereum Private Key (with 0x prefix)
|
|
14
|
+
# IMPORTANT: Never commit your actual private key to version control!
|
|
15
|
+
PRIVATE_KEY=0x1234567890123456789012345678901234567890123456789012345678901234
|
|
16
|
+
|
|
17
|
+
# Ethereum Wallet Address (with 0x prefix)
|
|
18
|
+
# If not provided, will be automatically derived from the private key
|
|
19
|
+
WALLET_ADDRESS=
|
|
20
|
+
|
|
21
|
+
# ============================================================================
|
|
22
|
+
# OPTIONAL: Room Configuration
|
|
23
|
+
# ============================================================================
|
|
24
|
+
|
|
25
|
+
# Default room to join on connection
|
|
26
|
+
# general: General purpose room for testing
|
|
27
|
+
# x-agent-enterprise-v2: X-Agent room for Twitter/X features
|
|
28
|
+
DEFAULT_ROOM=general
|
|
29
|
+
|
|
30
|
+
# ============================================================================
|
|
31
|
+
# OPTIONAL: Security Features
|
|
32
|
+
# ============================================================================
|
|
33
|
+
|
|
34
|
+
# Enable message signature verification (true | false)
|
|
35
|
+
# Verifies Ethereum signatures on incoming messages from agents
|
|
36
|
+
# Recommended: true for production
|
|
37
|
+
ENABLE_SIGNATURE_VERIFICATION=false
|
|
38
|
+
|
|
39
|
+
# Comma-separated list of trusted agent Ethereum addresses
|
|
40
|
+
# Only messages signed by these addresses will be accepted (if verification enabled)
|
|
41
|
+
# Leave empty to allow all signed messages
|
|
42
|
+
# Example: 0xAgent1...,0xAgent2...,0xAgent3...
|
|
43
|
+
TRUSTED_ADDRESSES=
|
|
44
|
+
|
|
45
|
+
# ============================================================================
|
|
46
|
+
# OPTIONAL: SDK Performance Tuning
|
|
47
|
+
# ============================================================================
|
|
48
|
+
|
|
49
|
+
# Enable agent caching (true | false)
|
|
50
|
+
ENABLE_CACHE=true
|
|
51
|
+
|
|
52
|
+
# Cache timeout in milliseconds (default: 300000 = 5 minutes)
|
|
53
|
+
CACHE_TIMEOUT=300000
|
|
54
|
+
|
|
55
|
+
# Maximum cache size (default: 100)
|
|
56
|
+
MAX_CACHE_SIZE=100
|
|
57
|
+
|
|
58
|
+
# ============================================================================
|
|
59
|
+
# OPTIONAL: Connection Settings
|
|
60
|
+
# ============================================================================
|
|
61
|
+
|
|
62
|
+
# Enable automatic reconnection (true | false)
|
|
63
|
+
ENABLE_RECONNECTION=true
|
|
64
|
+
|
|
65
|
+
# Reconnection delay in milliseconds (100-60000)
|
|
66
|
+
RECONNECT_DELAY=5000
|
|
67
|
+
|
|
68
|
+
# Maximum reconnection attempts (0-100, 0 = infinite)
|
|
69
|
+
MAX_RECONNECT_ATTEMPTS=10
|
|
70
|
+
|
|
71
|
+
# ============================================================================
|
|
72
|
+
# OPTIONAL: Logging
|
|
73
|
+
# ============================================================================
|
|
74
|
+
|
|
75
|
+
# Log level (debug | info | warn | error | silent)
|
|
76
|
+
# debug: Very verbose, shows all SDK operations
|
|
77
|
+
# info: Normal operations and important events
|
|
78
|
+
# warn: Warnings and potential issues
|
|
79
|
+
# error: Errors only
|
|
80
|
+
# silent: No logging
|
|
81
|
+
LOG_LEVEL=info
|
|
82
|
+
|
|
83
|
+
# ============================================================================
|
|
84
|
+
# OPTIONAL: API Server Configuration
|
|
85
|
+
# ============================================================================
|
|
86
|
+
|
|
87
|
+
# Port for the Teneo Service API (default: 3000)
|
|
88
|
+
PORT=3000
|
|
89
|
+
|
|
90
|
+
# ============================================================================
|
|
91
|
+
# OPTIONAL: n8n Configuration
|
|
92
|
+
# ============================================================================
|
|
93
|
+
|
|
94
|
+
# PostgreSQL password for n8n database
|
|
95
|
+
POSTGRES_PASSWORD=n8npassword
|
|
96
|
+
|
|
97
|
+
# n8n UI login credentials
|
|
98
|
+
N8N_USER=admin
|
|
99
|
+
N8N_PASSWORD=admin
|
|
100
|
+
|
|
101
|
+
# ============================================================================
|
|
102
|
+
# NOTES
|
|
103
|
+
# ============================================================================
|
|
104
|
+
|
|
105
|
+
# 1. Environment Precedence:
|
|
106
|
+
# - Environment variables override .env file values
|
|
107
|
+
# - .env file overrides default SDK values
|
|
108
|
+
#
|
|
109
|
+
# 2. Security Best Practices:
|
|
110
|
+
# - Never commit .env file to git (already in .gitignore)
|
|
111
|
+
# - Use different private keys for dev/prod
|
|
112
|
+
# - Enable signature verification in production
|
|
113
|
+
# - Wallet address is auto-derived if not provided
|
|
114
|
+
#
|
|
115
|
+
# 3. Development Tips:
|
|
116
|
+
# - Set LOG_LEVEL=debug for troubleshooting
|
|
117
|
+
# - Disable signature verification for local testing
|
|
118
|
+
# - Use 'general' room for basic testing
|
|
119
|
+
#
|
|
120
|
+
# 4. Production Checklist:
|
|
121
|
+
# ✓ Use production WebSocket URL
|
|
122
|
+
# ✓ Use secure private key (from secrets manager)
|
|
123
|
+
# ✓ Enable signature verification
|
|
124
|
+
# ✓ Set trusted agent addresses
|
|
125
|
+
# ✓ Set LOG_LEVEL=info or warn
|
|
126
|
+
# ✓ Enable all security features
|
|
127
|
+
# ✓ Use environment variables (not .env file)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
FROM node:20-alpine
|
|
2
|
+
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
|
|
5
|
+
# Install wget for healthcheck
|
|
6
|
+
RUN apk add --no-cache wget
|
|
7
|
+
|
|
8
|
+
# Create SDK directory and copy SDK source files
|
|
9
|
+
WORKDIR /app/teneo-consumer-sdk
|
|
10
|
+
|
|
11
|
+
# Copy SDK files
|
|
12
|
+
COPY package.json ./
|
|
13
|
+
COPY tsconfig.json ./
|
|
14
|
+
COPY src ./src
|
|
15
|
+
|
|
16
|
+
# Install SDK dependencies and build
|
|
17
|
+
RUN npm install && npm run build
|
|
18
|
+
|
|
19
|
+
# Switch to app directory for the service
|
|
20
|
+
WORKDIR /app/service
|
|
21
|
+
|
|
22
|
+
# Copy example service files
|
|
23
|
+
COPY examples/n8n-teneo/package.json examples/n8n-teneo/package-lock.json* ./
|
|
24
|
+
COPY examples/n8n-teneo/index.ts ./
|
|
25
|
+
|
|
26
|
+
# Update package.json to point to local SDK
|
|
27
|
+
RUN sed -i 's|"@teneo-protocol/sdk": "file:../../"|"@teneo-protocol/sdk": "file:../teneo-consumer-sdk"|g' package.json
|
|
28
|
+
|
|
29
|
+
# Fix the import path in index.ts to use the installed package instead of relative path
|
|
30
|
+
RUN sed -i "s|from '../../dist/index.js'|from '@teneo-protocol/sdk'|g" index.ts
|
|
31
|
+
|
|
32
|
+
# Install service dependencies
|
|
33
|
+
RUN npm install
|
|
34
|
+
|
|
35
|
+
# Build service TypeScript (inline, no tsconfig needed)
|
|
36
|
+
RUN npx tsc --module ES2022 --target ES2022 --moduleResolution node --esModuleInterop --skipLibCheck --strict false index.ts
|
|
37
|
+
|
|
38
|
+
# Expose port
|
|
39
|
+
EXPOSE 3000
|
|
40
|
+
|
|
41
|
+
# Run service
|
|
42
|
+
CMD ["node", "index.js"]
|