@sovant/sdk 1.0.0 โ 1.0.2
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/LICENSE +1 -1
- package/README.md +17 -357
- package/dist/index.d.ts +45 -367
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +101 -458
- package/dist/index.js.map +1 -0
- package/package.json +20 -38
- package/dist/index.d.mts +0 -369
- package/dist/index.mjs +0 -430
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,370 +1,30 @@
|
|
|
1
|
-
# Sovant
|
|
2
|
-
|
|
3
|
-
Official JavaScript/TypeScript SDK for the Sovant Memory API. Build AI applications with persistent memory, semantic search, and intelligent context management.
|
|
4
|
-
|
|
5
|
-
> **Note: Coming Soon!** This SDK is currently in development and will be available on npm soon. In the meantime, you can use our REST API directly.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
1
|
+
# Sovant TypeScript SDK
|
|
2
|
+
[](https://www.npmjs.com/package/@sovant/sdk)
|
|
8
3
|
|
|
4
|
+
## Install
|
|
9
5
|
```bash
|
|
10
|
-
|
|
11
|
-
npm install @sovant/sdk
|
|
12
|
-
# or
|
|
13
|
-
yarn add @sovant/sdk
|
|
14
|
-
# or
|
|
15
|
-
pnpm add @sovant/sdk
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Quick Start
|
|
19
|
-
|
|
20
|
-
```javascript
|
|
21
|
-
import { SovantClient } from "@sovant/sdk";
|
|
22
|
-
|
|
23
|
-
// Initialize the client
|
|
24
|
-
const client = new SovantClient("YOUR_API_KEY");
|
|
25
|
-
|
|
26
|
-
// Create a memory
|
|
27
|
-
const memory = await client.memories.create({
|
|
28
|
-
content: "User prefers dark mode interfaces",
|
|
29
|
-
type: "preference",
|
|
30
|
-
metadata: {
|
|
31
|
-
category: "ui_preferences",
|
|
32
|
-
confidence: 0.95,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
console.log("Created memory:", memory.id);
|
|
37
|
-
|
|
38
|
-
// Search memories
|
|
39
|
-
const results = await client.memories.search({
|
|
40
|
-
query: "What are the user's UI preferences?",
|
|
41
|
-
limit: 5,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
results.forEach((result) => {
|
|
45
|
-
console.log(`- ${result.content} (relevance: ${result.relevance_score})`);
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Features
|
|
50
|
-
|
|
51
|
-
- ๐ **Full TypeScript Support** - Complete type definitions for all methods
|
|
52
|
-
- ๐ **Async/Await** - Modern promise-based API
|
|
53
|
-
- ๐ **Automatic Retries** - Built-in retry logic for network failures
|
|
54
|
-
- ๐ฆ **Batch Operations** - Efficient bulk create/delete operations
|
|
55
|
-
- ๐ฏ **Smart Search** - Semantic, keyword, and hybrid search modes
|
|
56
|
-
- ๐งต **Thread Management** - Organize memories into contextual threads
|
|
57
|
-
- ๐ **Analytics** - Built-in insights and statistics
|
|
58
|
-
- โก **Tree-Shakeable** - Only import what you need
|
|
59
|
-
|
|
60
|
-
## Configuration
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
const client = new SovantClient({
|
|
64
|
-
apiKey: "YOUR_API_KEY",
|
|
65
|
-
baseUrl: "https://api.sovant.ai/v1", // Optional
|
|
66
|
-
timeout: 30000, // Request timeout in ms
|
|
67
|
-
maxRetries: 3, // Number of retries for failed requests
|
|
68
|
-
retryDelay: 1000, // Delay between retries in ms
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
You can also use environment variables:
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
export SOVANT_API_KEY="YOUR_API_KEY"
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
const client = new SovantClient(process.env.SOVANT_API_KEY);
|
|
6
|
+
npm i @sovant/sdk
|
|
80
7
|
```
|
|
81
8
|
|
|
82
|
-
##
|
|
83
|
-
|
|
84
|
-
### Create a Memory
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
const memory = await client.memories.create({
|
|
88
|
-
content: "The user completed the onboarding tutorial",
|
|
89
|
-
type: "event",
|
|
90
|
-
importance: 0.8,
|
|
91
|
-
metadata: {
|
|
92
|
-
step_completed: "tutorial",
|
|
93
|
-
duration_seconds: 180,
|
|
94
|
-
},
|
|
95
|
-
tags: ["onboarding", "milestone"],
|
|
96
|
-
emotion: {
|
|
97
|
-
type: "positive",
|
|
98
|
-
intensity: 0.7,
|
|
99
|
-
},
|
|
100
|
-
action_items: ["Send welcome email", "Unlock advanced features"],
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Update a Memory
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
const updated = await client.memories.update(memory.id, {
|
|
108
|
-
importance: 0.9,
|
|
109
|
-
follow_up_required: true,
|
|
110
|
-
follow_up_due: "2024-12-31T23:59:59Z",
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Search Memories
|
|
115
|
-
|
|
116
|
-
```javascript
|
|
117
|
-
// Semantic search
|
|
118
|
-
const semanticResults = await client.memories.search({
|
|
119
|
-
query: "user achievements and milestones",
|
|
120
|
-
search_type: "semantic",
|
|
121
|
-
limit: 10,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Filtered search
|
|
125
|
-
const filteredResults = await client.memories.search({
|
|
126
|
-
query: "preferences",
|
|
127
|
-
type: ["preference", "decision"],
|
|
128
|
-
tags: ["important"],
|
|
129
|
-
created_after: "2024-01-01",
|
|
130
|
-
sort_by: "importance",
|
|
131
|
-
sort_order: "desc",
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Batch Operations
|
|
136
|
-
|
|
137
|
-
```javascript
|
|
138
|
-
// Batch create
|
|
139
|
-
const batchResult = await client.memories.createBatch([
|
|
140
|
-
{ content: "Memory 1", type: "observation" },
|
|
141
|
-
{ content: "Memory 2", type: "reflection" },
|
|
142
|
-
{ content: "Memory 3", type: "learning" },
|
|
143
|
-
]);
|
|
144
|
-
|
|
145
|
-
console.log(`Created ${batchResult.success_count} memories`);
|
|
146
|
-
console.log(`Failed ${batchResult.failed_count} memories`);
|
|
147
|
-
|
|
148
|
-
// Batch delete
|
|
149
|
-
const deleteResult = await client.memories.deleteBatch([
|
|
150
|
-
"mem_123",
|
|
151
|
-
"mem_456",
|
|
152
|
-
"mem_789",
|
|
153
|
-
]);
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Thread Management
|
|
157
|
-
|
|
158
|
-
### Create a Thread
|
|
159
|
-
|
|
160
|
-
```javascript
|
|
161
|
-
const thread = await client.threads.create({
|
|
162
|
-
name: "Project Planning Discussion",
|
|
163
|
-
description: "Capturing all decisions and ideas for Q1 project",
|
|
164
|
-
tags: ["project", "planning", "q1-2024"],
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Add Memories to Thread
|
|
169
|
-
|
|
170
|
-
```javascript
|
|
171
|
-
// Add existing memories
|
|
172
|
-
await client.threads.addMemories(thread.id, [memory1.id, memory2.id]);
|
|
173
|
-
|
|
174
|
-
// Create and add in one operation
|
|
175
|
-
const newMemory = await client.memories.create({
|
|
176
|
-
content: "Decided to use TypeScript for the project",
|
|
177
|
-
type: "decision",
|
|
178
|
-
thread_ids: [thread.id],
|
|
179
|
-
});
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Get Thread with Memories
|
|
183
|
-
|
|
184
|
-
```javascript
|
|
185
|
-
const threadWithMemories = await client.threads.get(thread.id, true);
|
|
186
|
-
|
|
187
|
-
console.log(`Thread: ${threadWithMemories.name}`);
|
|
188
|
-
console.log(`Memories: ${threadWithMemories.memories.length}`);
|
|
189
|
-
|
|
190
|
-
threadWithMemories.memories.forEach((memory) => {
|
|
191
|
-
console.log(`- ${memory.content}`);
|
|
192
|
-
});
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Thread Analytics
|
|
196
|
-
|
|
197
|
-
```javascript
|
|
198
|
-
const stats = await client.threads.getStats(thread.id);
|
|
199
|
-
|
|
200
|
-
console.log(`Total memories: ${stats.memory_count}`);
|
|
201
|
-
console.log(`Average importance: ${stats.avg_importance}`);
|
|
202
|
-
console.log(`Decisions made: ${stats.total_decisions}`);
|
|
203
|
-
console.log(`Open questions: ${stats.total_questions}`);
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
## Error Handling
|
|
207
|
-
|
|
208
|
-
The SDK provides typed error classes for different scenarios:
|
|
209
|
-
|
|
210
|
-
```javascript
|
|
211
|
-
import {
|
|
212
|
-
AuthenticationError,
|
|
213
|
-
RateLimitError,
|
|
214
|
-
ValidationError,
|
|
215
|
-
NotFoundError,
|
|
216
|
-
} from "@sovant/sdk";
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
const memory = await client.memories.get("invalid_id");
|
|
220
|
-
} catch (error) {
|
|
221
|
-
if (error instanceof NotFoundError) {
|
|
222
|
-
console.error("Memory not found");
|
|
223
|
-
} else if (error instanceof RateLimitError) {
|
|
224
|
-
console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
225
|
-
} else if (error instanceof ValidationError) {
|
|
226
|
-
console.error("Validation errors:", error.errors);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
## TypeScript Support
|
|
232
|
-
|
|
233
|
-
The SDK is written in TypeScript and provides comprehensive type definitions:
|
|
234
|
-
|
|
9
|
+
## 60s Quickstart
|
|
235
10
|
```typescript
|
|
236
|
-
import {
|
|
237
|
-
Memory,
|
|
238
|
-
Thread,
|
|
239
|
-
SearchResult,
|
|
240
|
-
MemoryType,
|
|
241
|
-
EmotionType,
|
|
242
|
-
} from "@sovant/sdk";
|
|
243
|
-
|
|
244
|
-
// All methods are fully typed
|
|
245
|
-
const createMemory = async (
|
|
246
|
-
content: string,
|
|
247
|
-
type: MemoryType,
|
|
248
|
-
): Promise<Memory> => {
|
|
249
|
-
return client.memories.create({ content, type });
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// Type-safe emotion handling
|
|
253
|
-
const emotions: EmotionType[] = ["happy", "excited", "calm"];
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
## Advanced Usage
|
|
257
|
-
|
|
258
|
-
### Memory Insights
|
|
11
|
+
import { Sovant } from "@sovant/sdk";
|
|
259
12
|
|
|
260
|
-
|
|
261
|
-
const insights = await client.memories.getInsights({
|
|
262
|
-
time_range: "last_30_days",
|
|
263
|
-
group_by: "type",
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
console.log("Memory distribution:", insights.type_distribution);
|
|
267
|
-
console.log("Emotion distribution:", insights.emotion_distribution);
|
|
268
|
-
console.log("Growth rate:", `${insights.growth_rate}%`);
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### Related Memories
|
|
13
|
+
const sv = new Sovant({ apiKey: process.env.SOVANT_API_KEY! });
|
|
272
14
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
15
|
+
await sv.memory.create({
|
|
16
|
+
data: { note: "hello" },
|
|
17
|
+
type: "preference",
|
|
18
|
+
ttl: "30d"
|
|
277
19
|
});
|
|
278
20
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
21
|
+
const res = await sv.memory.search({
|
|
22
|
+
query: "hello",
|
|
23
|
+
topK: 3
|
|
282
24
|
});
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Thread Merging
|
|
286
|
-
|
|
287
|
-
```javascript
|
|
288
|
-
// Merge multiple threads into one
|
|
289
|
-
const mergedThread = await client.threads.merge(mainThread.id, [
|
|
290
|
-
thread2.id,
|
|
291
|
-
thread3.id,
|
|
292
|
-
]);
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
## React Hooks (Coming Soon)
|
|
296
|
-
|
|
297
|
-
```javascript
|
|
298
|
-
import { useMemory, useThread, useSearch } from "@sovant/sdk/react";
|
|
299
|
-
|
|
300
|
-
function MyComponent() {
|
|
301
|
-
const { memories, loading, error } = useMemory({
|
|
302
|
-
type: "preference",
|
|
303
|
-
limit: 10,
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
const { results, search } = useSearch();
|
|
307
25
|
|
|
308
|
-
|
|
309
|
-
}
|
|
26
|
+
console.log(res);
|
|
310
27
|
```
|
|
311
28
|
|
|
312
|
-
##
|
|
313
|
-
|
|
314
|
-
### Client Methods
|
|
315
|
-
|
|
316
|
-
- `new SovantClient(apiKey)` - Create a new client instance
|
|
317
|
-
- `client.ping()` - Test API connection
|
|
318
|
-
- `client.getUsage()` - Get current API usage and quota
|
|
319
|
-
|
|
320
|
-
### Memory Methods
|
|
321
|
-
|
|
322
|
-
- `client.memories.create(data)` - Create a new memory
|
|
323
|
-
- `client.memories.get(id)` - Get a memory by ID
|
|
324
|
-
- `client.memories.update(id, data)` - Update a memory
|
|
325
|
-
- `client.memories.delete(id)` - Delete a memory
|
|
326
|
-
- `client.memories.list(options)` - List memories with pagination
|
|
327
|
-
- `client.memories.search(options)` - Search memories
|
|
328
|
-
- `client.memories.createBatch(memories)` - Batch create memories
|
|
329
|
-
- `client.memories.deleteBatch(ids)` - Batch delete memories
|
|
330
|
-
- `client.memories.getInsights(options)` - Get memory analytics
|
|
331
|
-
- `client.memories.archive(id)` - Archive a memory
|
|
332
|
-
- `client.memories.pin(id)` - Pin a memory
|
|
333
|
-
- `client.memories.getRelated(id, options)` - Get related memories
|
|
334
|
-
|
|
335
|
-
### Thread Methods
|
|
336
|
-
|
|
337
|
-
- `client.threads.create(data)` - Create a new thread
|
|
338
|
-
- `client.threads.get(id, includeMemories)` - Get a thread
|
|
339
|
-
- `client.threads.update(id, data)` - Update a thread
|
|
340
|
-
- `client.threads.delete(id, deleteMemories)` - Delete a thread
|
|
341
|
-
- `client.threads.list(options)` - List threads with pagination
|
|
342
|
-
- `client.threads.addMemories(id, memoryIds)` - Add memories to thread
|
|
343
|
-
- `client.threads.removeMemories(id, memoryIds)` - Remove memories from thread
|
|
344
|
-
- `client.threads.getMemories(id, options)` - Get memories in thread
|
|
345
|
-
- `client.threads.getStats(id)` - Get thread statistics
|
|
346
|
-
- `client.threads.search(options)` - Search threads
|
|
347
|
-
- `client.threads.merge(targetId, sourceIds)` - Merge threads
|
|
348
|
-
- `client.threads.clone(id, options)` - Clone a thread
|
|
349
|
-
|
|
350
|
-
## Examples
|
|
351
|
-
|
|
352
|
-
Check out the [examples directory](https://github.com/sovant-ai/javascript-sdk/tree/main/examples) for complete working examples:
|
|
353
|
-
|
|
354
|
-
- Basic CRUD operations
|
|
355
|
-
- Advanced search techniques
|
|
356
|
-
- Thread management workflows
|
|
357
|
-
- Error handling patterns
|
|
358
|
-
- TypeScript usage
|
|
359
|
-
- React integration
|
|
360
|
-
|
|
361
|
-
## Support
|
|
362
|
-
|
|
363
|
-
- ๐ [Documentation](https://docs.sovant.ai)
|
|
364
|
-
- ๐ฌ [Discord Community](https://discord.gg/sovant)
|
|
365
|
-
- ๐ [Issue Tracker](https://github.com/sovant-ai/javascript-sdk/issues)
|
|
366
|
-
- ๐ง [Email Support](mailto:support@sovant.ai)
|
|
367
|
-
|
|
368
|
-
## License
|
|
369
|
-
|
|
370
|
-
MIT ยฉ Sovant AI
|
|
29
|
+
## Errors
|
|
30
|
+
Throws `SovantError(code, status, details)`.
|