JavaScript/TypeScript SDK
JavaScript/TypeScript SDK
Official SDK for Node.js and browser environments.
Installation
npm install @sovant/sdk@1.1.1
# or
yarn add @sovant/sdk@1.1.1
# or
pnpm add @sovant/sdk@1.1.1
Initialization
import { Sovant } from '@sovant/sdk';
const client = new Sovant({
apiKey: 'sk_live_your_api_key',
baseUrl: 'https://sovant.ai', // optional, this is default
timeout: 30000, // optional, ms
maxRetries: 3, // optional
debug: false // optional
});
Memory Operations
// Create
const memory = await client.memory.create({
content: 'User prefers dark mode',
type: 'preference',
tags: ['ui', 'settings'],
metadata: { source: 'onboarding' }
});
// Get
const mem = await client.memory.get('mem_123');
// Update
const updated = await client.memory.update('mem_123', {
tags: ['ui', 'settings', 'theme']
});
// Delete
await client.memory.delete('mem_123');
// List
const list = await client.memory.list({
limit: 20,
offset: 0,
type: 'preference',
tags: ['settings']
});
// Search
const results = await client.memory.search({
query: 'user preferences',
limit: 10
});
Chat with Streaming (v1.1.0+)
// Create session
const session = await client.chat.createSession({
title: 'Support chat',
provider: 'openai',
model: 'gpt-4o-mini'
});
// Send message with SSE streaming
const stream = await client.chat.sendMessage(session.id, {
message: 'Hello, I need help',
stream: true,
useMemory: true
});
// Process stream
for await (const event of stream) {
switch (event.type) {
case 'delta':
process.stdout.write(event.data || '');
break;
case 'done':
console.log('\nStream complete');
break;
case 'error':
console.error('Stream error:', event.error);
break;
}
}
// Get chat history
const messages = await client.chat.getMessages(session.id);
Profile Recall Helpers (v1.1.0+)
// Extract profile entity from text
const fact = await client.recall.extractProfile("I'm from Seattle");
// Returns: { entity: 'location', value: 'Seattle' } or null
// Save profile fact
if (fact) {
await client.recall.saveProfileFact(fact);
}
// Get all profile facts
const profile = await client.recall.getProfileFacts();
// Returns: {
// name?: string,
// age?: string,
// location?: string,
// preferences?: string[]
// }
Batch Operations
const batch = await client.memory.batch({
operations: [
{
op: 'create',
data: {
content: 'Batch memory 1',
type: 'observation'
}
},
{
op: 'update',
id: 'mem_123',
data: { tags: ['updated'] }
},
{
op: 'delete',
id: 'mem_456'
}
]
});
console.log(batch.summary);
// { total: 3, successful: 3, failed: 0 }
API Key Management
// List all keys
const keys = await client.keys.list();
// Create new key
const newKey = await client.keys.create({
name: 'CI/CD Pipeline'
});
console.log(newKey.key); // Save this!
// Update key
await client.keys.update(keyId, {
name: 'Production'
});
// Revoke key
await client.keys.revoke(keyId);
Error Handling
import { SovantError, NetworkError, TimeoutError } from '@sovant/sdk';
try {
const memory = await client.memory.get('invalid');
} catch (error) {
if (error instanceof SovantError) {
console.error(`API Error ${error.status}: ${error.message}`);
console.error(`Request ID: ${error.requestId}`);
} else if (error instanceof TimeoutError) {
console.error('Request timed out');
} else if (error instanceof NetworkError) {
console.error('Network error:', error.message);
}
}
TypeScript Types
import type {
MemoryResponse,
CreateMemoryInput,
SearchParams,
Session,
Message,
StreamEvent
} from '@sovant/sdk';
Changelog
See npm changelog for version history.
Current stable: v1.1.1 (SSE streaming fixes)