@agentic-robotics/mcp 0.2.0 → 0.2.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/package.json +2 -2
- package/dist/optimized-benchmark.d.ts +0 -74
- package/dist/optimized-benchmark.d.ts.map +0 -1
- package/dist/optimized-benchmark.js +0 -231
- package/dist/optimized-benchmark.js.map +0 -1
- package/src/benchmark.ts +0 -434
- package/src/cli.ts +0 -89
- package/src/enhanced-memory.ts +0 -437
- package/src/enhanced-server.ts +0 -523
- package/src/flow-orchestrator.ts +0 -475
- package/src/hybrid-benchmark.ts +0 -291
- package/src/hybrid-memory.ts +0 -401
- package/src/index.ts +0 -10
- package/src/interface.ts +0 -118
- package/src/memory.ts +0 -315
- package/src/server.ts +0 -213
- package/tsconfig.json +0 -20
package/src/interface.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ROS3 Interface - Mock implementation for demonstration
|
|
3
|
-
* In production, this would interface with the Rust native bindings
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface Pose {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
z: number;
|
|
10
|
-
roll: number;
|
|
11
|
-
pitch: number;
|
|
12
|
-
yaw: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ObjectDetection {
|
|
16
|
-
class: string;
|
|
17
|
-
confidence: number;
|
|
18
|
-
bbox: [number, number, number, number];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LidarData {
|
|
22
|
-
points: Array<{ x: number; y: number; z: number }>;
|
|
23
|
-
intensities: number[];
|
|
24
|
-
timestamp: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class ROS3Interface {
|
|
28
|
-
constructor() {
|
|
29
|
-
// Initialize connection to ROS3 runtime
|
|
30
|
-
console.error('ROS3Interface initialized');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async moveToPose(
|
|
34
|
-
pose: Pose,
|
|
35
|
-
speed: number = 0.5,
|
|
36
|
-
frame: 'base' | 'world' = 'world'
|
|
37
|
-
): Promise<void> {
|
|
38
|
-
console.error(`Moving to pose [${pose.x}, ${pose.y}, ${pose.z}] in ${frame} frame at speed ${speed}`);
|
|
39
|
-
|
|
40
|
-
// Simulate movement time
|
|
41
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async getLidarData(
|
|
45
|
-
filter: 'all' | 'obstacles' | 'ground' = 'all',
|
|
46
|
-
maxPoints: number = 10000
|
|
47
|
-
): Promise<LidarData> {
|
|
48
|
-
console.error(`Getting LIDAR data with filter: ${filter}, max points: ${maxPoints}`);
|
|
49
|
-
|
|
50
|
-
// Generate mock point cloud
|
|
51
|
-
const points = [];
|
|
52
|
-
const intensities = [];
|
|
53
|
-
const numPoints = Math.min(1000, maxPoints);
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < numPoints; i++) {
|
|
56
|
-
points.push({
|
|
57
|
-
x: Math.random() * 10 - 5,
|
|
58
|
-
y: Math.random() * 10 - 5,
|
|
59
|
-
z: Math.random() * 3,
|
|
60
|
-
});
|
|
61
|
-
intensities.push(Math.random());
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
points,
|
|
66
|
-
intensities,
|
|
67
|
-
timestamp: Date.now(),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async detectObjects(
|
|
72
|
-
camera: 'front' | 'left' | 'right' | 'rear',
|
|
73
|
-
confidenceThreshold: number = 0.5
|
|
74
|
-
): Promise<ObjectDetection[]> {
|
|
75
|
-
console.error(`Detecting objects from ${camera} camera with threshold ${confidenceThreshold}`);
|
|
76
|
-
|
|
77
|
-
// Generate mock detections
|
|
78
|
-
const classes = ['person', 'car', 'bicycle', 'traffic_light', 'stop_sign'];
|
|
79
|
-
const detections: ObjectDetection[] = [];
|
|
80
|
-
|
|
81
|
-
const numDetections = Math.floor(Math.random() * 5);
|
|
82
|
-
for (let i = 0; i < numDetections; i++) {
|
|
83
|
-
const confidence = Math.random() * 0.5 + 0.5;
|
|
84
|
-
if (confidence >= confidenceThreshold) {
|
|
85
|
-
detections.push({
|
|
86
|
-
class: classes[Math.floor(Math.random() * classes.length)],
|
|
87
|
-
confidence,
|
|
88
|
-
bbox: [
|
|
89
|
-
Math.random() * 640,
|
|
90
|
-
Math.random() * 480,
|
|
91
|
-
Math.random() * 200,
|
|
92
|
-
Math.random() * 200,
|
|
93
|
-
],
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return detections;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getCurrentPose(): Promise<Pose> {
|
|
102
|
-
return {
|
|
103
|
-
x: 0,
|
|
104
|
-
y: 0,
|
|
105
|
-
z: 0,
|
|
106
|
-
roll: 0,
|
|
107
|
-
pitch: 0,
|
|
108
|
-
yaw: 0,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async getStatus(): Promise<{ status: string; health: string }> {
|
|
113
|
-
return {
|
|
114
|
-
status: 'operational',
|
|
115
|
-
health: 'good',
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
package/src/memory.ts
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentDB Reflexion Memory Integration
|
|
3
|
-
*
|
|
4
|
-
* Enables robot learning from past experiences with secure command execution
|
|
5
|
-
* SECURITY: Uses spawn() with argument arrays to prevent command injection
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { spawn } from 'child_process';
|
|
9
|
-
|
|
10
|
-
export interface Episode {
|
|
11
|
-
sessionId: string;
|
|
12
|
-
taskName: string;
|
|
13
|
-
confidence: number;
|
|
14
|
-
success: boolean;
|
|
15
|
-
outcome: string;
|
|
16
|
-
strategy?: string;
|
|
17
|
-
metadata?: Record<string, any>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface Memory {
|
|
21
|
-
task: string;
|
|
22
|
-
confidence: number;
|
|
23
|
-
success: boolean;
|
|
24
|
-
outcome: string;
|
|
25
|
-
strategy?: string;
|
|
26
|
-
timestamp: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Helper to safely spawn a command and capture output
|
|
31
|
-
* Prevents command injection by using spawn with argument array
|
|
32
|
-
*/
|
|
33
|
-
function spawnAsync(
|
|
34
|
-
command: string,
|
|
35
|
-
args: string[],
|
|
36
|
-
env?: Record<string, string>
|
|
37
|
-
): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
const child = spawn(command, args, {
|
|
40
|
-
env: { ...process.env, ...env },
|
|
41
|
-
shell: false, // Critical: disable shell interpretation
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
let stdout = '';
|
|
45
|
-
let stderr = '';
|
|
46
|
-
|
|
47
|
-
child.stdout?.on('data', (data) => {
|
|
48
|
-
stdout += data.toString();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
child.stderr?.on('data', (data) => {
|
|
52
|
-
stderr += data.toString();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
child.on('close', (code) => {
|
|
56
|
-
resolve({ stdout, stderr, code: code || 0 });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
child.on('error', (error) => {
|
|
60
|
-
reject(error);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class AgentDBMemory {
|
|
66
|
-
private dbPath: string;
|
|
67
|
-
private initialized: boolean = false;
|
|
68
|
-
|
|
69
|
-
constructor(dbPath: string) {
|
|
70
|
-
// Validate dbPath to prevent path traversal
|
|
71
|
-
if (!dbPath || dbPath.includes('..') || dbPath.includes(';') || dbPath.includes('|')) {
|
|
72
|
-
throw new Error('Invalid database path');
|
|
73
|
-
}
|
|
74
|
-
this.dbPath = dbPath;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async initialize(): Promise<void> {
|
|
78
|
-
if (this.initialized) return;
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
// Initialize AgentDB database - use spawn with argument array for security
|
|
82
|
-
const { stdout, stderr, code } = await spawnAsync('npx', [
|
|
83
|
-
'agentdb',
|
|
84
|
-
'init',
|
|
85
|
-
this.dbPath,
|
|
86
|
-
'--dimension',
|
|
87
|
-
'768',
|
|
88
|
-
'--preset',
|
|
89
|
-
'medium',
|
|
90
|
-
]);
|
|
91
|
-
|
|
92
|
-
if (code === 0 || stderr.includes('already exists')) {
|
|
93
|
-
console.error('AgentDB initialized:', this.dbPath);
|
|
94
|
-
this.initialized = true;
|
|
95
|
-
} else {
|
|
96
|
-
throw new Error(`Initialization failed: ${stderr}`);
|
|
97
|
-
}
|
|
98
|
-
} catch (error: any) {
|
|
99
|
-
// Database might already exist
|
|
100
|
-
if (error.message?.includes('already exists')) {
|
|
101
|
-
this.initialized = true;
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error(`Failed to initialize AgentDB: ${error.message}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async storeEpisode(episode: Episode): Promise<void> {
|
|
109
|
-
if (!this.initialized) {
|
|
110
|
-
throw new Error('AgentDB not initialized. Call initialize() first.');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
// Use spawn with argument array to prevent command injection
|
|
115
|
-
const { code, stderr } = await spawnAsync(
|
|
116
|
-
'npx',
|
|
117
|
-
[
|
|
118
|
-
'agentdb',
|
|
119
|
-
'reflexion',
|
|
120
|
-
'store',
|
|
121
|
-
episode.sessionId,
|
|
122
|
-
episode.taskName,
|
|
123
|
-
episode.confidence.toString(),
|
|
124
|
-
episode.success.toString(),
|
|
125
|
-
episode.outcome || '',
|
|
126
|
-
],
|
|
127
|
-
{ AGENTDB_PATH: this.dbPath }
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
if (code !== 0) {
|
|
131
|
-
throw new Error(`Command failed: ${stderr}`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
console.error(`Stored episode: ${episode.taskName} (success: ${episode.success})`);
|
|
135
|
-
} catch (error: any) {
|
|
136
|
-
const errorMsg = `Failed to store episode "${episode.taskName}": ${error.message}`;
|
|
137
|
-
console.error('Error storing episode:', errorMsg);
|
|
138
|
-
throw new Error(errorMsg); // Throw instead of silently failing
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async retrieveMemories(
|
|
143
|
-
query: string,
|
|
144
|
-
k: number = 5,
|
|
145
|
-
options: {
|
|
146
|
-
minReward?: number;
|
|
147
|
-
onlySuccesses?: boolean;
|
|
148
|
-
onlyFailures?: boolean;
|
|
149
|
-
synthesizeContext?: boolean;
|
|
150
|
-
} = {}
|
|
151
|
-
): Promise<Memory[]> {
|
|
152
|
-
if (!this.initialized) {
|
|
153
|
-
throw new Error('AgentDB not initialized. Call initialize() first.');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Build safe argument array
|
|
157
|
-
const args = ['agentdb', 'reflexion', 'retrieve', query, '--k', k.toString()];
|
|
158
|
-
|
|
159
|
-
if (options.minReward !== undefined) {
|
|
160
|
-
args.push('--min-reward', options.minReward.toString());
|
|
161
|
-
}
|
|
162
|
-
if (options.onlySuccesses) {
|
|
163
|
-
args.push('--only-successes');
|
|
164
|
-
}
|
|
165
|
-
if (options.onlyFailures) {
|
|
166
|
-
args.push('--only-failures');
|
|
167
|
-
}
|
|
168
|
-
if (options.synthesizeContext) {
|
|
169
|
-
args.push('--synthesize-context');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
const { stdout, code, stderr } = await spawnAsync('npx', args, {
|
|
174
|
-
AGENTDB_PATH: this.dbPath,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
if (code !== 0) {
|
|
178
|
-
throw new Error(`Command failed: ${stderr}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Parse JSON output
|
|
182
|
-
const lines = stdout.trim().split('\n');
|
|
183
|
-
const jsonLine = lines.find((line) => line.startsWith('[') || line.startsWith('{'));
|
|
184
|
-
|
|
185
|
-
if (jsonLine) {
|
|
186
|
-
const data = JSON.parse(jsonLine);
|
|
187
|
-
return Array.isArray(data) ? data : [data];
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return [];
|
|
191
|
-
} catch (error: any) {
|
|
192
|
-
// Throw error instead of silently returning empty array
|
|
193
|
-
throw new Error(`Failed to retrieve memories for query "${query}": ${error.message}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async queryWithContext(
|
|
198
|
-
query: string,
|
|
199
|
-
options: {
|
|
200
|
-
k?: number;
|
|
201
|
-
minConfidence?: number;
|
|
202
|
-
domain?: string;
|
|
203
|
-
} = {}
|
|
204
|
-
): Promise<{ memories: Memory[]; context?: string }> {
|
|
205
|
-
if (!this.initialized) {
|
|
206
|
-
throw new Error('AgentDB not initialized. Call initialize() first.');
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const { k = 5, minConfidence = 0.0, domain } = options;
|
|
210
|
-
|
|
211
|
-
// Build safe argument array
|
|
212
|
-
const args = [
|
|
213
|
-
'agentdb',
|
|
214
|
-
'query',
|
|
215
|
-
'--query',
|
|
216
|
-
query,
|
|
217
|
-
'--k',
|
|
218
|
-
k.toString(),
|
|
219
|
-
'--min-confidence',
|
|
220
|
-
minConfidence.toString(),
|
|
221
|
-
];
|
|
222
|
-
|
|
223
|
-
if (domain) {
|
|
224
|
-
args.push('--domain', domain);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
args.push('--synthesize-context', '--format', 'json');
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
const { stdout, code, stderr } = await spawnAsync('npx', args, {
|
|
231
|
-
AGENTDB_PATH: this.dbPath,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
if (code !== 0) {
|
|
235
|
-
throw new Error(`Command failed: ${stderr}`);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const lines = stdout.trim().split('\n');
|
|
239
|
-
const jsonLine = lines.find((line) => line.startsWith('[') || line.startsWith('{'));
|
|
240
|
-
|
|
241
|
-
if (jsonLine) {
|
|
242
|
-
const data = JSON.parse(jsonLine);
|
|
243
|
-
return {
|
|
244
|
-
memories: Array.isArray(data) ? data : [data],
|
|
245
|
-
context: data.context || data.summary,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return { memories: [] };
|
|
250
|
-
} catch (error: any) {
|
|
251
|
-
// Throw error instead of silently returning empty array
|
|
252
|
-
throw new Error(`Failed to query with context "${query}": ${error.message}`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async consolidateSkills(options: {
|
|
257
|
-
minAttempts?: number;
|
|
258
|
-
minReward?: number;
|
|
259
|
-
timeWindowDays?: number;
|
|
260
|
-
} = {}): Promise<void> {
|
|
261
|
-
if (!this.initialized) {
|
|
262
|
-
throw new Error('AgentDB not initialized. Call initialize() first.');
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const { minAttempts = 3, minReward = 0.7, timeWindowDays = 7 } = options;
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
const { code, stderr } = await spawnAsync(
|
|
269
|
-
'npx',
|
|
270
|
-
[
|
|
271
|
-
'agentdb',
|
|
272
|
-
'skill',
|
|
273
|
-
'consolidate',
|
|
274
|
-
minAttempts.toString(),
|
|
275
|
-
minReward.toString(),
|
|
276
|
-
timeWindowDays.toString(),
|
|
277
|
-
'true',
|
|
278
|
-
],
|
|
279
|
-
{ AGENTDB_PATH: this.dbPath }
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
if (code !== 0) {
|
|
283
|
-
throw new Error(`Command failed: ${stderr}`);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
console.error('Skills consolidated from successful episodes');
|
|
287
|
-
} catch (error: any) {
|
|
288
|
-
throw new Error(`Failed to consolidate skills: ${error.message}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async getStats(): Promise<any> {
|
|
293
|
-
if (!this.initialized) {
|
|
294
|
-
throw new Error('AgentDB not initialized. Call initialize() first.');
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
try {
|
|
298
|
-
const { stdout, code, stderr } = await spawnAsync('npx', ['agentdb', 'db', 'stats'], {
|
|
299
|
-
AGENTDB_PATH: this.dbPath,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
if (code !== 0) {
|
|
303
|
-
throw new Error(`Command failed: ${stderr}`);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return { stats: stdout.trim() };
|
|
307
|
-
} catch (error: any) {
|
|
308
|
-
throw new Error(`Failed to get stats: ${error.message}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async close(): Promise<void> {
|
|
313
|
-
this.initialized = false;
|
|
314
|
-
}
|
|
315
|
-
}
|
package/src/server.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ROS3 MCP Server implementation - Simplified version
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { ROS3Interface } from './interface.js';
|
|
6
|
-
import { AgentDBMemory } from './memory.js';
|
|
7
|
-
|
|
8
|
-
export interface ROS3McpServerConfig {
|
|
9
|
-
name?: string;
|
|
10
|
-
version?: string;
|
|
11
|
-
dbPath?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class ROS3McpServer {
|
|
15
|
-
private ros3: ROS3Interface;
|
|
16
|
-
private memory: AgentDBMemory;
|
|
17
|
-
private name: string;
|
|
18
|
-
private version: string;
|
|
19
|
-
|
|
20
|
-
constructor(config: ROS3McpServerConfig = {}) {
|
|
21
|
-
const {
|
|
22
|
-
name = 'ros3-mcp-server',
|
|
23
|
-
version = '1.0.0',
|
|
24
|
-
dbPath = './ros3-agentdb.db',
|
|
25
|
-
} = config;
|
|
26
|
-
|
|
27
|
-
this.name = name;
|
|
28
|
-
this.version = version;
|
|
29
|
-
|
|
30
|
-
// Initialize ROS3 interface
|
|
31
|
-
this.ros3 = new ROS3Interface();
|
|
32
|
-
|
|
33
|
-
// Initialize AgentDB memory
|
|
34
|
-
this.memory = new AgentDBMemory(dbPath);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async start(): Promise<void> {
|
|
38
|
-
// Initialize AgentDB
|
|
39
|
-
await this.memory.initialize();
|
|
40
|
-
|
|
41
|
-
console.error(`${this.name} v${this.version} started`);
|
|
42
|
-
console.error('AgentDB initialized and ready');
|
|
43
|
-
console.error('');
|
|
44
|
-
console.error('Available tools:');
|
|
45
|
-
console.error(' - move_robot: Move robot to target pose');
|
|
46
|
-
console.error(' - get_pose: Get current robot pose');
|
|
47
|
-
console.error(' - get_status: Get robot status');
|
|
48
|
-
console.error(' - read_lidar: Read LIDAR data');
|
|
49
|
-
console.error(' - detect_objects: Detect objects from camera');
|
|
50
|
-
console.error(' - query_memory: Query past experiences');
|
|
51
|
-
console.error(' - consolidate_skills: Learn from experiences');
|
|
52
|
-
console.error(' - get_memory_stats: Get memory statistics');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async stop(): Promise<void> {
|
|
56
|
-
await this.memory.close();
|
|
57
|
-
console.error(`${this.name} stopped`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Tool implementations
|
|
61
|
-
async moveRobot(params: {
|
|
62
|
-
x: number;
|
|
63
|
-
y: number;
|
|
64
|
-
z: number;
|
|
65
|
-
roll: number;
|
|
66
|
-
pitch: number;
|
|
67
|
-
yaw: number;
|
|
68
|
-
speed?: number;
|
|
69
|
-
frame?: 'base' | 'world';
|
|
70
|
-
}): Promise<string> {
|
|
71
|
-
const { x, y, z, roll, pitch, yaw, speed = 0.5, frame = 'world' } = params;
|
|
72
|
-
const startTime = Date.now();
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
await this.ros3.moveToPose({ x, y, z, roll, pitch, yaw }, speed, frame);
|
|
76
|
-
const latency = Date.now() - startTime;
|
|
77
|
-
|
|
78
|
-
await this.memory.storeEpisode({
|
|
79
|
-
sessionId: `motion-${Date.now()}`,
|
|
80
|
-
taskName: 'move_robot',
|
|
81
|
-
confidence: 0.9,
|
|
82
|
-
success: true,
|
|
83
|
-
outcome: `Moved to [${x}, ${y}, ${z}] in ${latency}ms`,
|
|
84
|
-
strategy: `speed_${speed}_frame_${frame}`,
|
|
85
|
-
metadata: { x, y, z, roll, pitch, yaw, speed, frame, latency },
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return `Robot moved to [${x}, ${y}, ${z}] in ${frame} frame. Completed in ${latency}ms.`;
|
|
89
|
-
} catch (error: any) {
|
|
90
|
-
await this.memory.storeEpisode({
|
|
91
|
-
sessionId: `motion-${Date.now()}`,
|
|
92
|
-
taskName: 'move_robot',
|
|
93
|
-
confidence: 0.0,
|
|
94
|
-
success: false,
|
|
95
|
-
outcome: `Failed: ${error.message}`,
|
|
96
|
-
metadata: { x, y, z, roll, pitch, yaw, speed, frame },
|
|
97
|
-
});
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async getPose(): Promise<string> {
|
|
103
|
-
const pose = await this.ros3.getCurrentPose();
|
|
104
|
-
return `Current pose: [${pose.x}, ${pose.y}, ${pose.z}] (roll=${pose.roll}, pitch=${pose.pitch}, yaw=${pose.yaw})`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async getStatus(): Promise<string> {
|
|
108
|
-
const status = await this.ros3.getStatus();
|
|
109
|
-
return `Robot status: ${status.status}, Health: ${status.health}`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async readLidar(params: { filter?: string; max_points?: number }): Promise<string> {
|
|
113
|
-
const { filter = 'all', max_points = 10000 } = params;
|
|
114
|
-
const startTime = Date.now();
|
|
115
|
-
|
|
116
|
-
const cloud = await this.ros3.getLidarData(
|
|
117
|
-
filter as 'all' | 'obstacles' | 'ground',
|
|
118
|
-
max_points
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const latency = Date.now() - startTime;
|
|
122
|
-
|
|
123
|
-
await this.memory.storeEpisode({
|
|
124
|
-
sessionId: `lidar-${Date.now()}`,
|
|
125
|
-
taskName: 'read_lidar',
|
|
126
|
-
confidence: 1.0,
|
|
127
|
-
success: true,
|
|
128
|
-
outcome: `Retrieved ${cloud.points.length} points in ${latency}ms`,
|
|
129
|
-
metadata: { filter, max_points, num_points: cloud.points.length, latency },
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return `LIDAR data: ${cloud.points.length} points (filter: ${filter}, latency: ${latency}ms)`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async detectObjects(params: { camera: string; confidence_threshold?: number }): Promise<string> {
|
|
136
|
-
const { camera, confidence_threshold = 0.5 } = params;
|
|
137
|
-
const startTime = Date.now();
|
|
138
|
-
|
|
139
|
-
const detections = await this.ros3.detectObjects(
|
|
140
|
-
camera as 'front' | 'left' | 'right' | 'rear',
|
|
141
|
-
confidence_threshold
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const latency = Date.now() - startTime;
|
|
145
|
-
|
|
146
|
-
await this.memory.storeEpisode({
|
|
147
|
-
sessionId: `vision-${Date.now()}`,
|
|
148
|
-
taskName: 'detect_objects',
|
|
149
|
-
confidence: 0.9,
|
|
150
|
-
success: true,
|
|
151
|
-
outcome: `Detected ${detections.length} objects in ${latency}ms`,
|
|
152
|
-
metadata: { camera, confidence_threshold, num_detections: detections.length, latency },
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return `Detected ${detections.length} objects from ${camera} camera:\n${JSON.stringify(detections, null, 2)}`;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async queryMemory(params: {
|
|
159
|
-
query: string;
|
|
160
|
-
k?: number;
|
|
161
|
-
only_successes?: boolean;
|
|
162
|
-
min_confidence?: number;
|
|
163
|
-
}): Promise<string> {
|
|
164
|
-
const { query, k = 5, only_successes = false, min_confidence = 0.0 } = params;
|
|
165
|
-
|
|
166
|
-
const result = await this.memory.queryWithContext(query, { k, minConfidence: min_confidence });
|
|
167
|
-
|
|
168
|
-
const filteredMemories = only_successes
|
|
169
|
-
? result.memories.filter((m) => m.success)
|
|
170
|
-
: result.memories;
|
|
171
|
-
|
|
172
|
-
return `Found ${filteredMemories.length} memories for "${query}":\n${JSON.stringify(filteredMemories, null, 2)}`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async consolidateSkills(params?: {
|
|
176
|
-
min_attempts?: number;
|
|
177
|
-
min_reward?: number;
|
|
178
|
-
time_window_days?: number;
|
|
179
|
-
}): Promise<string> {
|
|
180
|
-
const { min_attempts = 3, min_reward = 0.7, time_window_days = 7 } = params || {};
|
|
181
|
-
|
|
182
|
-
await this.memory.consolidateSkills({
|
|
183
|
-
minAttempts: min_attempts,
|
|
184
|
-
minReward: min_reward,
|
|
185
|
-
timeWindowDays: time_window_days,
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return `Skills consolidated (min_attempts: ${min_attempts}, min_reward: ${min_reward}, window: ${time_window_days} days)`;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async getMemoryStats(): Promise<string> {
|
|
192
|
-
const stats = await this.memory.getStats();
|
|
193
|
-
return `AgentDB Statistics:\n${stats.stats}`;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Get server info
|
|
197
|
-
getInfo() {
|
|
198
|
-
return {
|
|
199
|
-
name: this.name,
|
|
200
|
-
version: this.version,
|
|
201
|
-
tools: [
|
|
202
|
-
'move_robot',
|
|
203
|
-
'get_pose',
|
|
204
|
-
'get_status',
|
|
205
|
-
'read_lidar',
|
|
206
|
-
'detect_objects',
|
|
207
|
-
'query_memory',
|
|
208
|
-
'consolidate_skills',
|
|
209
|
-
'get_memory_stats',
|
|
210
|
-
],
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ES2022",
|
|
5
|
-
"lib": ["ES2022"],
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"declaration": true,
|
|
12
|
-
"declarationMap": true,
|
|
13
|
-
"sourceMap": true,
|
|
14
|
-
"outDir": "./dist",
|
|
15
|
-
"rootDir": "./src",
|
|
16
|
-
"resolveJsonModule": true
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules", "dist"]
|
|
20
|
-
}
|