@sovant/sdk 1.0.5 → 1.1.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/CHANGELOG.md +118 -0
- package/LICENSE +1 -1
- package/README.md +423 -66
- package/dist/index.d.mts +433 -0
- package/dist/index.d.ts +428 -42
- package/dist/index.js +843 -98
- package/dist/index.mjs +821 -0
- package/package.json +49 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the Sovant JavaScript/TypeScript SDK will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.1.1] - 2025-09-15
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **Robust SSE parsing** - Complete rewrite of SSE parser to handle:
|
|
12
|
+
- Partial chunk reassembly
|
|
13
|
+
- Both `\n\n` and `\r\n\r\n` event boundaries
|
|
14
|
+
- Multi-line `data:` fields
|
|
15
|
+
- Comment lines starting with `:`
|
|
16
|
+
- Optional `event:` and `id:` fields
|
|
17
|
+
- **Chat streaming** - Fixed `sendMessage()` to properly stream delta events with API keys
|
|
18
|
+
- **API headers** - SDK now uses `x-sovant-api-key` header (matching docs) instead of `Authorization: Bearer`
|
|
19
|
+
- **Session creation** - Fixed response parsing to expect session data at root level
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Improved `sendMessage()` to handle both object and string message formats
|
|
23
|
+
- Enhanced SSE event processing to parse JSON `text` fields from API responses
|
|
24
|
+
|
|
25
|
+
## [1.1.0] - 2025-09-15
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
- **Chat namespace** with SSE streaming support for real-time conversations
|
|
29
|
+
- `createSession()` - Create chat sessions with provider/model selection
|
|
30
|
+
- `sendMessage()` - Stream responses with async generator pattern
|
|
31
|
+
- `getMessages()` - Retrieve chat history
|
|
32
|
+
- `getSession()` / `listSessions()` - Session management
|
|
33
|
+
- **Keys namespace** for API key management
|
|
34
|
+
- `list()`, `create()`, `update()`, `revoke()` - Full key lifecycle
|
|
35
|
+
- **Recall namespace** with Phase 1 profile helpers
|
|
36
|
+
- `extractProfile()` - Client-side profile entity detection
|
|
37
|
+
- `getProfileFacts()` - Retrieve canonical profile facts
|
|
38
|
+
- `saveProfileFact()` - Save facts in canonical format
|
|
39
|
+
- **baseUrl** config option for custom endpoints
|
|
40
|
+
- SSE parser utility for streaming responses
|
|
41
|
+
- TypeScript exports for all new types
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
- HttpClient properties now public for namespace access
|
|
45
|
+
- Enhanced README with Chat streaming examples
|
|
46
|
+
|
|
47
|
+
## [0.4.0] - 2025-01-01
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
- Complete alignment with live Sovant Memory API at https://sovant.ai
|
|
51
|
+
- Full TypeScript support with comprehensive type definitions
|
|
52
|
+
- Robust error handling with `SovantError`, `NetworkError`, and `TimeoutError` classes
|
|
53
|
+
- Automatic retry logic with exponential backoff for failed requests
|
|
54
|
+
- Request timeout support using AbortController
|
|
55
|
+
- Debug mode for detailed request/response logging
|
|
56
|
+
- Batch operations support for atomic multi-operation transactions
|
|
57
|
+
- Thread management for organizing related memories
|
|
58
|
+
- Comprehensive README with examples and best practices
|
|
59
|
+
- Smoke test script for API verification
|
|
60
|
+
- Proper ESM and CommonJS dual package support
|
|
61
|
+
|
|
62
|
+
### Changed
|
|
63
|
+
- **BREAKING**: Complete API redesign to match live endpoints
|
|
64
|
+
- **BREAKING**: Removed `userId` from all public method signatures (now derived from API key)
|
|
65
|
+
- **BREAKING**: Changed from `SovantClient` class to `Sovant` class
|
|
66
|
+
- **BREAKING**: Namespace all memory operations under `sovant.memory.*`
|
|
67
|
+
- Updated all endpoints to use new paths:
|
|
68
|
+
- Collection: `/api/v1/memory` (GET list, POST create)
|
|
69
|
+
- By ID: `/api/v1/memories/{id}` (GET, PUT, PATCH, DELETE)
|
|
70
|
+
- Search: `/api/v1/memory/search`
|
|
71
|
+
- Batch: `/api/v1/memory/batch`
|
|
72
|
+
- All response fields now use snake_case to match API format
|
|
73
|
+
- Improved error messages and request ID tracking
|
|
74
|
+
|
|
75
|
+
### Fixed
|
|
76
|
+
- Proper handling of 204 No Content responses
|
|
77
|
+
- Correct content-type detection for response parsing
|
|
78
|
+
- Retry logic for transient network failures
|
|
79
|
+
- Proper timeout handling with clear error messages
|
|
80
|
+
|
|
81
|
+
### Security
|
|
82
|
+
- API keys are now passed as Bearer tokens in Authorization header
|
|
83
|
+
- No longer expose userId in client code
|
|
84
|
+
|
|
85
|
+
## [0.3.0] - 2024-11-15
|
|
86
|
+
|
|
87
|
+
### Added
|
|
88
|
+
- Initial TypeScript SDK implementation
|
|
89
|
+
- Basic CRUD operations for memories
|
|
90
|
+
- Simple search functionality
|
|
91
|
+
- Thread support
|
|
92
|
+
|
|
93
|
+
### Changed
|
|
94
|
+
- Migrated from JavaScript to TypeScript
|
|
95
|
+
|
|
96
|
+
## [0.2.0] - 2024-10-01
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
- Batch operations support
|
|
100
|
+
- Memory metadata fields
|
|
101
|
+
- Emotional tone tracking
|
|
102
|
+
|
|
103
|
+
### Fixed
|
|
104
|
+
- Memory pagination issues
|
|
105
|
+
- Search result relevance scoring
|
|
106
|
+
|
|
107
|
+
## [0.1.0] - 2024-09-01
|
|
108
|
+
|
|
109
|
+
### Added
|
|
110
|
+
- Initial SDK release
|
|
111
|
+
- Basic memory CRUD operations
|
|
112
|
+
- Simple keyword search
|
|
113
|
+
- API key authentication
|
|
114
|
+
|
|
115
|
+
[0.4.0]: https://github.com/sovant-ai/javascript-sdk/compare/v0.3.0...v0.4.0
|
|
116
|
+
[0.3.0]: https://github.com/sovant-ai/javascript-sdk/compare/v0.2.0...v0.3.0
|
|
117
|
+
[0.2.0]: https://github.com/sovant-ai/javascript-sdk/compare/v0.1.0...v0.2.0
|
|
118
|
+
[0.1.0]: https://github.com/sovant-ai/javascript-sdk/releases/tag/v0.1.0
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
# Sovant TypeScript SDK
|
|
1
|
+
# Sovant JavaScript/TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
The official TypeScript/JavaScript client for the Sovant Memory API.
|
|
5
|
-
|
|
6
|
-
[](https://www.npmjs.com/package/@sovant/sdk)
|
|
7
|
-
[](https://sovant.ai/docs)
|
|
8
|
-
[](https://github.com/sovant-ai/sovant)
|
|
9
|
-
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
## What is Sovant?
|
|
13
|
-
|
|
14
|
-
Sovant is an **AI infrastructure company** providing the **memory layer for AI systems**.
|
|
15
|
-
Our platform makes it simple to persist, search, and manage conversational and contextual data securely across sessions, channels, and applications.
|
|
16
|
-
|
|
17
|
-
- **Problem:** Most AI systems forget everything once a session ends. This causes compliance risks, knowledge loss, and poor user experience.
|
|
18
|
-
- **Solution:** Sovant provides a **Memory-as-a-Service API** — a single SDK and API key that lets you store, retrieve, and search memories with audit-ready controls.
|
|
19
|
-
- **Target audience:** Developers, startups, and enterprises building AI agents, copilots, or compliance-driven apps who need context persistence.
|
|
20
|
-
|
|
21
|
-
---
|
|
3
|
+
Official JavaScript/TypeScript SDK for the Sovant Memory API - Universal memory layer for AI applications.
|
|
22
4
|
|
|
23
5
|
## Installation
|
|
24
6
|
|
|
@@ -30,75 +12,450 @@ yarn add @sovant/sdk
|
|
|
30
12
|
pnpm add @sovant/sdk
|
|
31
13
|
```
|
|
32
14
|
|
|
33
|
-
##
|
|
15
|
+
## Quick Start
|
|
34
16
|
|
|
35
17
|
```typescript
|
|
36
|
-
import { Sovant } from
|
|
18
|
+
import { Sovant } from '@sovant/sdk';
|
|
37
19
|
|
|
38
|
-
|
|
20
|
+
// Initialize the client
|
|
21
|
+
const sovant = new Sovant({
|
|
22
|
+
apiKey: 'sk_live_your_api_key_here',
|
|
23
|
+
baseUrl: 'https://sovant.ai', // Optional, defaults to https://sovant.ai
|
|
24
|
+
});
|
|
39
25
|
|
|
40
26
|
// Create a memory
|
|
41
|
-
await
|
|
42
|
-
|
|
43
|
-
type:
|
|
27
|
+
const memory = await sovant.memory.create({
|
|
28
|
+
content: 'User prefers dark mode interfaces',
|
|
29
|
+
type: 'preference',
|
|
30
|
+
tags: ['ui', 'settings'],
|
|
44
31
|
});
|
|
45
32
|
|
|
46
33
|
// Search memories
|
|
47
|
-
const results = await
|
|
48
|
-
query:
|
|
49
|
-
|
|
34
|
+
const results = await sovant.memory.search({
|
|
35
|
+
query: 'user preferences',
|
|
36
|
+
limit: 10,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Update a memory
|
|
40
|
+
const updated = await sovant.memory.update(memory.id, {
|
|
41
|
+
tags: ['ui', 'settings', 'theme'],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Delete a memory
|
|
45
|
+
await sovant.memory.delete(memory.id);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Chat in 60 Seconds
|
|
49
|
+
|
|
50
|
+
Stream real-time chat responses with memory context:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { Sovant } from '@sovant/sdk';
|
|
54
|
+
|
|
55
|
+
const client = new Sovant({ apiKey: process.env.SOVANT_API_KEY, baseUrl: 'https://sovant.ai' });
|
|
56
|
+
|
|
57
|
+
// Create a chat session
|
|
58
|
+
const session = await client.chat.createSession({ title: 'Demo' });
|
|
59
|
+
|
|
60
|
+
// Stream a response
|
|
61
|
+
const stream = await client.chat.sendMessage(session.id, {
|
|
62
|
+
message: 'hello',
|
|
63
|
+
provider: 'openai',
|
|
64
|
+
model: 'gpt-4o-mini',
|
|
65
|
+
stream: true,
|
|
66
|
+
useMemory: true,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
for await (const ev of stream) {
|
|
70
|
+
if (ev.type === 'delta') process.stdout.write(ev.data || '');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Get chat history
|
|
74
|
+
const messages = await client.chat.getMessages(session.id);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Profile Recall Helpers
|
|
78
|
+
|
|
79
|
+
Save and recall user profile facts with canonical patterns:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Extract profile entity from text
|
|
83
|
+
const fact = await client.recall.extractProfile("i'm from kuching");
|
|
84
|
+
// -> { entity: 'location', value: 'kuching' } | null
|
|
85
|
+
|
|
86
|
+
if (fact) {
|
|
87
|
+
await client.recall.saveProfileFact(fact); // canonicalizes and persists
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Get all profile facts
|
|
91
|
+
const profile = await client.recall.getProfileFacts();
|
|
92
|
+
// -> { name?: string, age?: string|number, location?: string, preferences?: string[] }
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Configuration
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
const sovant = new Sovant({
|
|
99
|
+
apiKey: 'sk_live_your_api_key_here', // Required
|
|
100
|
+
baseUrl: 'https://sovant.ai', // Optional, API endpoint
|
|
101
|
+
timeout: 30000, // Optional, request timeout in ms (default: 30000)
|
|
102
|
+
maxRetries: 3, // Optional, max retry attempts (default: 3)
|
|
103
|
+
debug: false, // Optional, enable debug logging (default: false)
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## API Reference
|
|
108
|
+
|
|
109
|
+
### Memory Operations
|
|
110
|
+
|
|
111
|
+
#### Create Memory
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
const memory = await sovant.memory.create({
|
|
115
|
+
content: 'Customer contacted support about billing',
|
|
116
|
+
type: 'observation', // 'journal' | 'insight' | 'observation' | 'task' | 'preference'
|
|
117
|
+
tags: ['support', 'billing'],
|
|
118
|
+
metadata: { ticketId: '12345' },
|
|
119
|
+
thread_id: 'thread_abc123', // Optional thread association
|
|
120
|
+
importance_score: 0.8, // 0-1 importance rating
|
|
121
|
+
emotional_tone: 'frustrated',
|
|
122
|
+
source: 'zendesk',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### List Memories
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
const list = await sovant.memory.list({
|
|
130
|
+
limit: 20, // Max items per page (default: 20)
|
|
131
|
+
offset: 0, // Pagination offset
|
|
132
|
+
tags: ['billing'], // Filter by tags
|
|
133
|
+
type: 'observation', // Filter by type
|
|
134
|
+
is_archived: false, // Filter archived status
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
console.log(list.memories); // Array of memories
|
|
138
|
+
console.log(list.total); // Total count
|
|
139
|
+
console.log(list.has_more); // More pages available
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### Get Memory by ID
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const memory = await sovant.memory.get('mem_123abc');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Update Memory (Partial)
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
const updated = await sovant.memory.update('mem_123abc', {
|
|
152
|
+
tags: ['support', 'billing', 'resolved'],
|
|
153
|
+
metadata: {
|
|
154
|
+
...memory.metadata,
|
|
155
|
+
resolved: true,
|
|
156
|
+
},
|
|
157
|
+
is_archived: true,
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Replace Memory (Full)
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const replaced = await sovant.memory.put('mem_123abc', {
|
|
165
|
+
content: 'Updated content here', // Required for PUT
|
|
166
|
+
type: 'observation',
|
|
167
|
+
tags: ['updated'],
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Delete Memory
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
await sovant.memory.delete('mem_123abc');
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Search Memories
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Semantic search
|
|
181
|
+
const semanticResults = await sovant.memory.search({
|
|
182
|
+
query: 'customer preferences about notifications',
|
|
183
|
+
limit: 10,
|
|
184
|
+
type: 'preference',
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Filter-based search
|
|
188
|
+
const filterResults = await sovant.memory.search({
|
|
189
|
+
tags: ['settings', 'notifications'],
|
|
190
|
+
from_date: '2024-01-01',
|
|
191
|
+
to_date: '2024-12-31',
|
|
192
|
+
emotional_tone: 'positive',
|
|
193
|
+
limit: 20,
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### Batch Operations
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const batch = await sovant.memory.batch({
|
|
201
|
+
operations: [
|
|
202
|
+
{
|
|
203
|
+
op: 'create',
|
|
204
|
+
data: {
|
|
205
|
+
content: 'First memory',
|
|
206
|
+
type: 'journal',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
op: 'update',
|
|
211
|
+
id: 'mem_123abc',
|
|
212
|
+
data: {
|
|
213
|
+
tags: ['updated'],
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
op: 'delete',
|
|
218
|
+
id: 'mem_456def',
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
console.log(batch.ok); // All operations succeeded
|
|
224
|
+
console.log(batch.results); // Individual operation results
|
|
225
|
+
console.log(batch.summary); // Summary statistics
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Memory Types
|
|
229
|
+
|
|
230
|
+
- **journal** - Chronological entries and logs
|
|
231
|
+
- **insight** - Derived patterns and conclusions
|
|
232
|
+
- **observation** - Factual, observed information
|
|
233
|
+
- **task** - Action items and todos
|
|
234
|
+
- **preference** - User preferences and settings
|
|
235
|
+
|
|
236
|
+
## Error Handling
|
|
237
|
+
|
|
238
|
+
The SDK provides typed errors for better error handling:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import { Sovant, SovantError, NetworkError, TimeoutError } from '@sovant/sdk';
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
const memory = await sovant.memory.get('invalid_id');
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (error instanceof SovantError) {
|
|
247
|
+
console.error('API Error:', error.message);
|
|
248
|
+
console.error('Error Code:', error.code);
|
|
249
|
+
console.error('Status:', error.status);
|
|
250
|
+
console.error('Request ID:', error.requestId);
|
|
251
|
+
|
|
252
|
+
switch (error.status) {
|
|
253
|
+
case 401:
|
|
254
|
+
// Handle authentication error
|
|
255
|
+
break;
|
|
256
|
+
case 404:
|
|
257
|
+
// Handle not found
|
|
258
|
+
break;
|
|
259
|
+
case 429:
|
|
260
|
+
// Handle rate limiting
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
} else if (error instanceof TimeoutError) {
|
|
264
|
+
console.error('Request timed out');
|
|
265
|
+
} else if (error instanceof NetworkError) {
|
|
266
|
+
console.error('Network error:', error.message);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Thread Management
|
|
272
|
+
|
|
273
|
+
Associate memories with conversation threads:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
// Create memories within a thread
|
|
277
|
+
const memory1 = await sovant.memory.create({
|
|
278
|
+
content: 'User asked about pricing',
|
|
279
|
+
thread_id: 'thread_conversation_123',
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const memory2 = await sovant.memory.create({
|
|
283
|
+
content: 'User selected enterprise plan',
|
|
284
|
+
thread_id: 'thread_conversation_123',
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// List memories in a thread
|
|
288
|
+
const threadMemories = await sovant.memory.list({
|
|
289
|
+
thread_id: 'thread_conversation_123',
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## API Key Management
|
|
294
|
+
|
|
295
|
+
Manage API keys programmatically:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// List all API keys
|
|
299
|
+
const keys = await client.keys.list();
|
|
300
|
+
console.log(keys); // Array of key objects
|
|
301
|
+
|
|
302
|
+
// Create a new API key
|
|
303
|
+
const newKey = await client.keys.create({ name: 'CI key' });
|
|
304
|
+
console.log(newKey.key); // The actual secret key (only shown once!)
|
|
305
|
+
|
|
306
|
+
// Update key metadata
|
|
307
|
+
await client.keys.update(newKey.id, { name: 'Production key' });
|
|
308
|
+
|
|
309
|
+
// Revoke a key
|
|
310
|
+
await client.keys.revoke(newKey.id);
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Advanced Features
|
|
314
|
+
|
|
315
|
+
### Retry Configuration
|
|
316
|
+
|
|
317
|
+
The SDK automatically retries failed requests with exponential backoff:
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
const sovant = new Sovant({
|
|
321
|
+
apiKey: 'sk_live_...',
|
|
322
|
+
maxRetries: 5, // Increase retry attempts
|
|
323
|
+
timeout: 60000, // Increase timeout for slow connections
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Debug Mode
|
|
328
|
+
|
|
329
|
+
Enable debug logging to see detailed request/response information:
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
const sovant = new Sovant({
|
|
333
|
+
apiKey: 'sk_live_...',
|
|
334
|
+
debug: true, // Enable debug output
|
|
50
335
|
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Custom Base URL
|
|
339
|
+
|
|
340
|
+
Connect to different environments:
|
|
51
341
|
|
|
52
|
-
|
|
342
|
+
```typescript
|
|
343
|
+
const client = new Sovant({
|
|
344
|
+
apiKey: 'sk_live_...',
|
|
345
|
+
baseUrl: 'https://staging.sovant.ai',
|
|
346
|
+
});
|
|
53
347
|
```
|
|
54
348
|
|
|
55
|
-
##
|
|
349
|
+
## TypeScript Support
|
|
56
350
|
|
|
57
|
-
|
|
58
|
-
- **Semantic Search** — query memories with filters and topK ranking
|
|
59
|
-
- **Threads** — link related memories via thread_id (REST API)
|
|
60
|
-
- **Batch Operations (Beta)** — atomic multi-operation support
|
|
61
|
-
- **Compliance-ready** — audit trails, PDPA/GDPR-friendly by design
|
|
62
|
-
- **SDKs** — official TypeScript and Python SDKs, with REST API reference
|
|
351
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
63
352
|
|
|
64
|
-
|
|
353
|
+
```typescript
|
|
354
|
+
import type {
|
|
355
|
+
Memory,
|
|
356
|
+
MemoryType,
|
|
357
|
+
CreateMemoryInput,
|
|
358
|
+
SearchParams,
|
|
359
|
+
SearchResults,
|
|
360
|
+
BatchRequest,
|
|
361
|
+
BatchResponse,
|
|
362
|
+
} from '@sovant/sdk';
|
|
65
363
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
364
|
+
// All types are fully typed
|
|
365
|
+
const createInput: CreateMemoryInput = {
|
|
366
|
+
content: 'Typed content',
|
|
367
|
+
type: 'journal',
|
|
368
|
+
tags: ['typed'],
|
|
369
|
+
};
|
|
70
370
|
|
|
71
|
-
|
|
371
|
+
const memory: Memory = await sovant.memory.create(createInput);
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Best Practices
|
|
375
|
+
|
|
376
|
+
1. **Use appropriate memory types** - Choose the correct type for your use case
|
|
377
|
+
2. **Add meaningful tags** - Tags improve searchability and organization
|
|
378
|
+
3. **Set importance scores** - Help prioritize critical memories
|
|
379
|
+
4. **Use threads** - Group related memories together
|
|
380
|
+
5. **Handle errors gracefully** - Implement proper error handling
|
|
381
|
+
6. **Batch operations** - Use batch API for multiple operations
|
|
382
|
+
7. **Archive don't delete** - Consider archiving instead of deleting
|
|
383
|
+
|
|
384
|
+
## Examples
|
|
385
|
+
|
|
386
|
+
### Customer Support Integration
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
// Track customer interaction
|
|
390
|
+
const interaction = await sovant.memory.create({
|
|
391
|
+
content: 'Customer reported slow dashboard loading',
|
|
392
|
+
type: 'observation',
|
|
393
|
+
thread_id: `ticket_${ticketId}`,
|
|
394
|
+
tags: ['support', 'performance', 'dashboard'],
|
|
395
|
+
metadata: {
|
|
396
|
+
ticketId,
|
|
397
|
+
customerId,
|
|
398
|
+
priority: 'high',
|
|
399
|
+
},
|
|
400
|
+
emotional_tone: 'frustrated',
|
|
401
|
+
source: 'zendesk',
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Record resolution
|
|
405
|
+
const resolution = await sovant.memory.create({
|
|
406
|
+
content: 'Resolved by clearing cache and upgrading plan',
|
|
407
|
+
type: 'insight',
|
|
408
|
+
thread_id: `ticket_${ticketId}`,
|
|
409
|
+
tags: ['support', 'resolved'],
|
|
410
|
+
metadata: {
|
|
411
|
+
ticketId,
|
|
412
|
+
resolutionTime: '2h',
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### User Preference Tracking
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
// Store preference
|
|
421
|
+
const preference = await sovant.memory.create({
|
|
422
|
+
content: 'User prefers email notifications over SMS',
|
|
423
|
+
type: 'preference',
|
|
424
|
+
tags: ['notifications', 'email', 'settings'],
|
|
425
|
+
metadata: {
|
|
426
|
+
userId,
|
|
427
|
+
setting: 'notification_channel',
|
|
428
|
+
value: 'email',
|
|
429
|
+
},
|
|
430
|
+
importance_score: 0.9,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Query preferences
|
|
434
|
+
const preferences = await sovant.memory.search({
|
|
435
|
+
type: 'preference',
|
|
436
|
+
tags: ['notifications'],
|
|
437
|
+
});
|
|
438
|
+
```
|
|
72
439
|
|
|
73
|
-
|
|
74
|
-
- `POST /api/v1/memory` — Create memory
|
|
75
|
-
- `GET /api/v1/memory` — List memories
|
|
76
|
-
- `GET /api/v1/memories/{id}` — Get memory by ID
|
|
77
|
-
- `PATCH|PUT /api/v1/memories/{id}` — Update memory
|
|
78
|
-
- `DELETE /api/v1/memories/{id}` — Delete memory
|
|
79
|
-
- `GET /api/v1/memory/search` — Search memories
|
|
80
|
-
- `POST /api/v1/memory/batch` — Batch operations (Beta)
|
|
440
|
+
## Rate Limiting
|
|
81
441
|
|
|
82
|
-
|
|
442
|
+
The API implements rate limiting. The SDK automatically handles rate limit responses with retries. Rate limit headers are included in responses:
|
|
83
443
|
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
- `subject` is deprecated (ignored by API). Use `thread_id`, `tags`, or `metadata` for grouping.
|
|
444
|
+
- `X-RateLimit-Limit` - Request limit per window
|
|
445
|
+
- `X-RateLimit-Remaining` - Remaining requests
|
|
446
|
+
- `X-RateLimit-Reset` - Reset timestamp
|
|
88
447
|
|
|
89
|
-
##
|
|
448
|
+
## Support
|
|
90
449
|
|
|
91
|
-
-
|
|
92
|
-
-
|
|
93
|
-
-
|
|
450
|
+
- Documentation: [https://docs.sovant.ai](https://docs.sovant.ai)
|
|
451
|
+
- API Reference: [https://docs.sovant.ai/api](https://docs.sovant.ai/api)
|
|
452
|
+
- Issues: [GitHub Issues](https://github.com/sovant-ai/javascript-sdk/issues)
|
|
453
|
+
- Support: support@sovant.ai
|
|
94
454
|
|
|
95
|
-
##
|
|
455
|
+
## Changelog
|
|
96
456
|
|
|
97
|
-
|
|
98
|
-
- Version 1.0.4 fixed critical API endpoint bugs
|
|
99
|
-
- Earlier builds (1.0.0-1.0.3) are deprecated
|
|
100
|
-
- See [CHANGELOG.md](./CHANGELOG.md) for details.
|
|
457
|
+
See [CHANGELOG.md](./CHANGELOG.md) for a detailed history of changes.
|
|
101
458
|
|
|
102
459
|
## License
|
|
103
460
|
|
|
104
|
-
MIT
|
|
461
|
+
MIT - See [LICENSE](LICENSE) file for details.
|