Skip to content

TypeScript SDK

Full API reference for the @configure/memory-sdk package.

Installation

bash
npm install @configure/memory-sdk

MemoryClient

Main entry point for the SDK.

typescript
import { MemoryClient } from '@configure/memory-sdk';

const client = new MemoryClient(apiKey: string, options?: MemoryClientOptions);

Options

OptionTypeDefaultDescription
baseUrlstringhttps://api.configure.devAPI base URL
timeoutnumber-Request timeout in ms
fetchtypeof fetchglobal fetchCustom fetch implementation

Example

typescript
import { MemoryClient } from '@configure/memory-sdk';

// Basic initialization
const client = new MemoryClient('your-api-key');

// With options
const client = new MemoryClient('your-api-key', {
  baseUrl: 'https://api.configure.dev',
  timeout: 30000
});

// For Node.js < 18
import fetch from 'node-fetch';
const client = new MemoryClient('api-key', {
  fetch: fetch as unknown as typeof globalThis.fetch
});

Authentication (client.auth)

sendOtp

Send OTP to a phone number.

typescript
await client.auth.sendOtp(phone: string): Promise<void>

Parameters:

  • phone - Phone number in E.164 format (e.g., +14155551234)

Example:

typescript
await client.auth.sendOtp('+14155551234');

verifyOtp

Verify OTP and get auth token.

typescript
await client.auth.verifyOtp(
  phone: string,
  code: string
): Promise<{ token: string; userId: string }>

Parameters:

  • phone - Phone number in E.164 format
  • code - 6-digit OTP code

Returns:

  • token - JWT token valid for 30 days
  • userId - Unique user identifier (UUID)

Example:

typescript
const { token, userId } = await client.auth.verifyOtp('+14155551234', '123456');

getDemo

Get a demo token for development.

typescript
await client.auth.getDemo(): Promise<string>

Returns:

  • Demo JWT token

Memory (client.memory)

getProfile

Get the user's Memory Profile - their centralized context store.

typescript
await client.memory.getProfile(
  token: string,
  userId: string,
  options?: { path?: string; appScope?: string }
): Promise<MemoryProfile>

Parameters:

  • token - JWT token from authentication
  • userId - User ID
  • options.path - Dot-notation path (e.g., "user", "apps.myapp")
  • options.appScope - Filter to data relevant for this app

Returns:

  • MemoryProfile object with user data

Example:

typescript
// Get full profile
const profile = await client.memory.getProfile(token, userId);

// Get specific path
const userData = await client.memory.getProfile(token, userId, { path: 'user' });

// Get app-scoped data
const appData = await client.memory.getProfile(token, userId, { appScope: 'myapp' });

remember

Save a memory to the user's profile.

typescript
await client.memory.remember(
  token: string,
  userId: string,
  key: string,
  value: string
): Promise<{ saved: boolean; app: string; key: string; value: string }>

Parameters:

  • token - JWT token
  • userId - User ID
  • key - Memory key (snake_case recommended)
  • value - Memory value (string)

Example:

typescript
await client.memory.remember(token, userId, 'dietary_restrictions', 'vegetarian');
await client.memory.remember(token, userId, 'timezone', 'America/Los_Angeles');

ingest

Evaluate a message for memory extraction.

typescript
await client.memory.ingest(
  token: string,
  userId: string,
  message: ConversationMessage,
  memoryCriteria: string
): Promise<IngestResult>

Parameters:

  • token - JWT token
  • userId - User ID
  • message - Message to evaluate { role: 'user' | 'assistant', content: string }
  • memoryCriteria - What memories to look for

Returns:

  • relevant - Whether memories were found
  • memoriesWritten - Array of extracted memories

Example:

typescript
const result = await client.memory.ingest(
  token,
  userId,
  { role: 'user', content: 'I prefer window seats on flights' },
  'Travel preferences, dietary restrictions'
);

if (result.relevant) {
  console.log('Memories saved:', result.memoriesWritten);
}

syncTools

Sync connected tools to update profile data.

typescript
await client.memory.syncTools(
  token: string,
  userId: string,
  tools?: ToolType[]
): Promise<SyncResult>

Tools (client.tools)

list

List available tools and their connection status.

typescript
await client.tools.list(token: string): Promise<{ tools: Tool[] }>

Example:

typescript
const { tools } = await client.tools.list(token);
// tools: [{ id: 'gmail', name: 'Gmail', connected: true }, ...]

connect

Start OAuth flow to connect a tool.

typescript
await client.tools.connect(
  token: string,
  tool: ToolType,
  callbackUrl?: string
): Promise<{ url: string; connectionRequestId: string }>

Parameters:

  • token - JWT token
  • tool - Tool type: 'gmail' | 'calendar' | 'drive' | 'notion'
  • callbackUrl - URL to redirect after OAuth

Returns:

  • url - OAuth URL to redirect user to
  • connectionRequestId - ID to use in confirm endpoint

confirm

Confirm tool connection after OAuth callback.

typescript
await client.tools.confirm(
  token: string,
  tool: ToolType,
  connectionRequestId: string
): Promise<{ connected: boolean; sync?: object }>

sync

Manually sync a connected tool.

typescript
await client.tools.sync(token: string, tool: ToolType): Promise<void>

disconnect

Disconnect a tool.

typescript
await client.tools.disconnect(token: string, tool: ToolType): Promise<void>

disconnectAll

Disconnect all tools.

typescript
await client.tools.disconnectAll(token: string): Promise<void>

searchEmails

Search user's Gmail.

typescript
await client.tools.searchEmails(
  token: string,
  userId: string,
  query: string,
  maxResults?: number
): Promise<EmailSearchResult>

Example:

typescript
const results = await client.tools.searchEmails(token, userId, 'from:boss@company.com');
console.log(results.emails);

searchCalendar

Get user's calendar events.

typescript
await client.tools.searchCalendar(
  token: string,
  userId: string,
  range?: 'today' | 'tomorrow' | 'week' | 'month'
): Promise<CalendarSearchResult>

searchFiles

Search user's Google Drive.

typescript
await client.tools.searchFiles(
  token: string,
  userId: string,
  query: string,
  maxResults?: number
): Promise<FileSearchResult>

searchNotes

Search user's Notion.

typescript
await client.tools.searchNotes(
  token: string,
  userId: string,
  query: string,
  maxResults?: number
): Promise<NotesSearchResult>

Streaming (client.streaming)

chatStream

Streaming chat with memory-aware AI.

typescript
await client.streaming.chatStream(
  token: string,
  userId: string,
  message: string,
  conversationHistory: ConversationMessage[],
  appContext: AppContext,
  callbacks: StreamCallbacks,
  options?: StreamOptions
): Promise<void>

Parameters:

  • token - JWT token
  • userId - User ID
  • message - User message
  • conversationHistory - Previous messages
  • appContext - App info { appName: string, appDescription: string }
  • callbacks - Stream event handlers
  • options - Optional settings

Callbacks:

typescript
interface StreamCallbacks {
  onToken?: (token: string) => void;
  onDone?: (toolsAccessed?: string[]) => void;
  onMemoryUpdated?: (memories: Memory[]) => void;
  onToolsAccessed?: (tools: string[]) => void;
  onError?: (error: Error) => void;
}

Example:

typescript
await client.streaming.chatStream(
  token,
  userId,
  'What meetings do I have today?',
  conversationHistory,
  { appName: 'MyApp', appDescription: 'Personal assistant' },
  {
    onToken: (token) => process.stdout.write(token),
    onDone: (toolsAccessed) => console.log('\nTools used:', toolsAccessed),
    onMemoryUpdated: (memories) => console.log('Memories saved:', memories),
    onError: (error) => console.error('Error:', error)
  },
  { fastMode: false }
);

chatSimple

Simple non-streaming chat.

typescript
await client.streaming.chatSimple(
  token: string,
  userId: string,
  message: string,
  conversationHistory: ConversationMessage[],
  appContext: AppContext
): Promise<{ message: string; memoryBadge?: object }>

generate

Simple text generation without tool access.

typescript
await client.streaming.generate(
  token: string,
  userId: string,
  prompt: string,
  appContext: AppContext,
  options?: { context?: string; system?: string },
  callbacks?: { onToken?: (token: string) => void }
): Promise<string>

Types

MemoryProfile

typescript
interface MemoryProfile {
  user?: {
    name?: string;
    email?: string;
    phone?: string;
    location?: string;
    timezone?: string;
    occupation?: string;
    interests?: string[];
    summary?: string;
  };
  connected_tools: ToolType[];
  apps: string[];
  apps_data: Record<string, AppData>;
  prefs: Record<string, any>;
}

ConversationMessage

typescript
interface ConversationMessage {
  role: 'user' | 'assistant';
  content: string;
}

ToolType

typescript
type ToolType = 'gmail' | 'calendar' | 'drive' | 'notion';

AppContext

typescript
interface AppContext {
  appName: string;
  appDescription: string;
}

Environment Compatibility

The SDK works in:

  • Node.js 18+ - Uses native fetch
  • Modern browsers - Uses native fetch
  • Older Node.js - Pass a fetch polyfill in options
typescript
// For Node.js < 18
import fetch from 'node-fetch';

const client = new MemoryClient('api-key', {
  fetch: fetch as unknown as typeof globalThis.fetch
});

AI Memory Infrastructure