-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
107 lines (77 loc) · 3.98 KB
/
example.ts
File metadata and controls
107 lines (77 loc) · 3.98 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Stackme SDK - Usage Examples
*
* This file demonstrates how to use the StackmeClient in various scenarios.
*/
import { StackmeClient } from './src/index';
async function main() {
console.log('=== Stackme SDK Usage Examples ===\n');
// ─── Basic Usage ───────────────────────────────────────────────────────────
console.log('1. Basic Usage');
console.log('---------------');
const client = new StackmeClient({ userId: 'example-user' });
// Add facts
await client.addFact('I run a fintech startup');
await client.addFact('Q3 goal: 10K paying customers');
await client.addFact('My name is John');
// Add user message
await client.addMessage('What should we price our product at?');
// Get relevant context
const context = await client.getRelevant('pricing strategy');
console.log('Relevant context:');
console.log(context);
console.log();
// ─── Search ───────────────────────────────────────────────────────────────
console.log('2. Search');
console.log('---------');
const results = await client.search('fintech');
console.log('Search results:');
results.forEach((r, i) => {
console.log(` ${i + 1}. [${r.type}] ${r.content} (score: ${r.score.toFixed(3)})`);
});
console.log();
// ─── Knowledge Graph ─────────────────────────────────────────────────────
console.log('3. Knowledge Graph');
console.log('------------------');
const graph = await client.getGraph();
console.log('Graph facts:');
graph.forEach(f => {
console.log(` ${f.subject} — ${f.predicate}: ${f.value}`);
});
console.log();
// ─── Get Facts ────────────────────────────────────────────────────────────
console.log('4. Get All Facts');
console.log('-----------------');
const facts = await client.getFacts();
console.log('All facts:');
facts.forEach(f => console.log(` - ${f}`));
console.log();
// ─── Session History ──────────────────────────────────────────────────────
console.log('5. Session History');
console.log('------------------');
const history = client.getSessionHistory();
console.log('Session history:');
history.forEach(h => {
console.log(` [${h.role}]: ${h.content.substring(0, 50)}...`);
});
console.log();
// ─── Count ────────────────────────────────────────────────────────────────
console.log('6. Memory Count');
console.log('---------------');
const count = await client.count();
console.log(`Total memories: ${count}`);
console.log();
// ─── Export ──────────────────────────────────────────────────────────────
console.log('7. Export Data');
console.log('--------------');
const exportData = await client.export();
console.log(`Exported at: ${exportData.exportedAt}`);
console.log(`Memory items: ${exportData.memory.length}`);
console.log(`Graph facts: ${exportData.graph.length}`);
console.log();
// ─── Cleanup ──────────────────────────────────────────────────────────────
await client.close();
console.log('=== Examples Complete ===');
}
// Run if executed directly
main().catch(console.error);