@sovant/sdk 1.0.4 → 1.1.0

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