npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@driftos/client

v0.3.2

Published

JavaScript SDK for drift-core - conversation routing and context management

Downloads

80

Readme

@driftos/client

JavaScript SDK for driftos-core - conversation routing and context management for AI applications.

Install

npm install @driftos/client

Quick Start

Self-Hosted

import { 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?' }
  ]
});

Hosted (api.driftos.dev)

import { DriftClient } from '@driftos/client';

// Bare host is fine — the SDK auto-composes /api/v1/<engine>/... for you.
const drift = new DriftClient({
  baseUrl: 'https://api.driftos.dev',
  apiKey: 'your-api-key',
  // engine: 'llm' (default) | 'embed'
});

const result = await drift.route('conv-123', 'I want to plan a trip to Paris');

Or pin to a specific engine by giving the full URL yourself — the SDK sees the engine segment and leaves it alone:

const drift = new DriftClient({
  baseUrl: 'https://api.driftos.dev/api/v1/embed',
  apiKey: 'your-api-key',
});

Configuration

DriftClient Options

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)
  engine?: 'llm' | 'embed';       // Optional: hosted engine (default: 'llm')
  hosted?: boolean;               // Optional: force hosted-gateway mode on/off
})

Hosted mode (gateway at api.driftos.dev):

  • Auto-detected when baseUrl contains api.driftos.dev.
  • If baseUrl doesn't include an engine segment (/api/v1/llm or /api/v1/embed), the SDK appends /api/v1/<engine> automatically. Default engine is llm.
  • If you already include the engine segment in baseUrl, it's left untouched.

Self-hosted mode (direct connection to driftos-core or driftos-embed):

  • Set hosted: false (or use any URL that doesn't contain api.driftos.dev).
  • Paths are composed as <baseUrl>/api/v1/... with no engine prefix.

API

route(conversationId, content, role?)

Route a message to the appropriate branch.

getBranches(conversationId)

List all branches for a conversation.

getContext(branchId)

Get messages and facts for a branch.

extractFacts(branchId)

Extract facts from branch messages.

getFacts(branchId)

Get existing facts for a branch.

buildPrompt(branchId, options?)

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)

deleteConversation(conversationId)

Delete a conversation and every branch, message, and fact belonging to it. Use this to implement client "Clear chat history" flows. Throws on 404.

const { deletedBranches, deletedMessages, deletedFacts } =
  await drift.deleteConversation('conv-123');

Returns: { deletedBranches: number; deletedMessages: number; deletedFacts: number }

deleteBranch(branchId)

Delete a branch and every descendant branch (cascading), including their messages and facts. No re-parenting is performed. Throws on 404.

const { deletedMessages, deletedFacts } = await drift.deleteBranch('branch_abc123');

Returns: { deletedMessages: number; deletedFacts: number }

Pinning a message to a specific branch

By default, route() lets the server decide which branch a message belongs to. If your UI lets the user manually select a branch, pass branchMode: 'PINNED' with targetBranchId to force the write onto that branch instead.

await drift.route('conv-123', 'reply text', {
  branchMode: 'PINNED',
  targetBranchId: 'branch_abc123',
});
// result.pinned === true

License

MIT