JavaScript SDK for driftos-core - conversation routing and context management for AI applications.
npm install @driftos/clientimport { createDriftClient } from '@driftos/client';
const drift = createDriftClient('http://localhost:3000');
// Route a message
const result = await drift.route('conv-123', 'I want to plan a trip to Paris');
console.log(result.branchTopic); // "Paris trip planning"
// Get context for LLM
const { system, messages } = await drift.buildPrompt(result.branchId);
// Use with OpenAI
const response = await openai.chat.completions.create({
model: 'gpt-5',
messages: [
{ role: 'system', content: system },
...messages,
{ role: 'user', content: 'What hotels do you recommend?' }
]
});import { DriftClient } from '@driftos/client';
// Automatically detects hosted mode from URL
const drift = new DriftClient({
baseUrl: 'https://api.driftos.dev',
apiKey: 'your-api-key'
});
// Use the same API - hosted mode handles routing automatically
const result = await drift.route('conv-123', 'I want to plan a trip to Paris');new DriftClient({
baseUrl: string; // Required: Base URL of your driftos instance
apiKey?: string; // Optional: API key for authentication
timeout?: number; // Optional: Request timeout in ms (default: 10000)
hosted?: boolean; // Optional: Hosted mode flag (auto-detected for api.driftos.dev)
})The hosted flag controls URL path formatting:
false(default): Paths include/api/v1prefix (for direct driftos-core connections)true: Paths exclude/api/v1prefix (for gateway deployments)- Auto-detected when
baseUrlincludesapi.driftos.dev
Route a message to the appropriate branch.
List all branches for a conversation.
Get messages and facts for a branch.
Extract facts from branch messages.
Get existing facts for a branch.
Build a ready-to-use prompt with context for LLM calls.
Options:
systemPrompt?: string- Base system prompt (default: 'You are a helpful assistant.')includeOtherTopics?: boolean- Mention other discussed topics (default: true)includeFacts?: boolean- Include extracted facts (default: true)factsFromAllBranches?: boolean- Include facts from all branches (default: false)template?: (ctx) => string- Custom template function for system prompt generation
Legacy: Also accepts a plain string for systemPrompt (backwards compatible)
MIT