-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-tql-integration.ts
More file actions
91 lines (75 loc) · 2.56 KB
/
simple-tql-integration.ts
File metadata and controls
91 lines (75 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bun
import { Graph } from '../src/graph/graph.js';
import { Engine } from '../src/graph/engine.js';
import { builtinTools } from '../src/graph/tools.js';
console.log('🚀 Simple TQL Integration Test\n');
// Create a simple graph: load data -> query -> end
const g = new Graph();
g.addNode({
id: 'load',
kind: 'Tool',
data: {
name: 'tql_load_data',
args: {
dataUrl: 'https://jsonplaceholder.typicode.com/posts',
key: 'posts'
}
}
});
g.addNode({
id: 'query',
kind: 'Tool',
data: {
name: 'tql_query',
args: {
query: 'FIND post AS ?p WHERE ?p.userId = 1 RETURN ?p, ?p.title LIMIT 3',
entityType: 'post',
idKey: 'id',
state: true
}
}
});
g.addNode({
id: 'end',
kind: 'End',
data: {}
});
// Connect: load -> query -> end
g.addEdge({ id: 'e1', from: 'load', to: 'query', label: 'success' });
g.addEdge({ id: 'e2', from: 'query', to: 'end', label: 'success' });
// Execute
const engine = new Engine(g, { tools: builtinTools });
console.log('📊 Executing graph...');
try {
console.log('Creating generator...');
const gen = engine.run('load', {});
console.log('Consuming generator steps...');
let stepCount = 0;
for await (const step of gen) {
stepCount++;
console.log(` Step ${stepCount}: node ${step.state.traces?.[step.state.traces.length - 1]?.nodeId || 'unknown'}`);
// Check for errors in this step
const lastTrace = step.state.traces?.[step.state.traces.length - 1];
if (lastTrace?.error) {
console.log(` ❌ Error: ${lastTrace.error}`);
}
// Show query results if available
if (lastTrace?.nodeId === 'query' && step.state.output?.result?.results) {
console.log(` 📋 Query returned ${step.state.output.result.count} results:`);
step.state.output.result.results.slice(0, 2).forEach((result: any, i: number) => {
console.log(` ${i + 1}. Post ${result['?p'].id}: "${result['?p.title']}"`);
});
}
}
console.log('Getting final result...');
const finalResult = await gen.next();
console.log('Final result:', finalResult);
const result = finalResult.value;
console.log('Final state:', result ? 'present' : 'missing');
if (result) {
console.log('Memory keys:', Object.keys((result as any).memory || {}));
}
} catch (error: any) {
console.log('❌ Engine error:', error.message);
console.log('Stack:', error.stack);
}