JavaScript SDK

TypeScript-first, JavaScript-friendly 🟨✨

The official JavaScript/TypeScript SDK for Memof.ai. Build intelligent applications with persistent AI memory—now with 100% more type safety!

Why JavaScript SDK?

  • 🔒 Type-Safe - Full TypeScript support (we love autocomplete)
  • Modern - Async/await, ESM, all the good stuff
  • 🎯 Intuitive - Clean API that feels like home
  • 🪝 Framework-Ready - React hooks, Vue composables included
  • 🚀 Production-Tested - Battle-hardened in real apps

Pick your path:

Installation

npm install memofai
# or if you're fancy
pnpm add memofai

30-Second Quick Start

Too excited to read? We get it. 😎

import { createMoaClient } from 'memofai';

const client = createMoaClient({
  apiToken: 'moa_your_token_here'
});

// Create workspace
const workspace = await client.workspaces.create({
  name: "My AI Workspace"
});

// Create bot
const bot = await client.bots.create({
  name: "Assistant Bot",
  workspaceId: workspace.id
});

// Store memory
const memory = await client.memories.create({
  botId: bot.id,
  content: "User loves TypeScript and wants better autocomplete"
});

// Search (the magic happens here ✨)
const results = await client.memories.search({
  botId: bot.id,
  query: "programming preferences",
  limit: 5
});

console.log(`Found ${results.length} relevant memories!`);

TypeScript Support

Full type definitions included:

import {
  createMoaClient,
  Environment,
  WorkspaceData,
  BotData,
  MemoryData,
  SearchRequest
} from 'memofai';

// Your editor will thank you 🙏
const client = createMoaClient({
  apiToken: 'moa_your_token',
  environment: 'production' as Environment
});

// Type-safe all the way down
const workspace: WorkspaceData = await client.workspaces.create({
  name: "Type-Safe Workspace"
});

JavaScript (CommonJS)

Old school? We support that too.

const { createMoaClient } = require('memofai');

const client = createMoaClient({
  apiToken: 'moa_your_token_here'
});

// Same API, no types
// (but hey, it works!)

What Makes It Special?

Clean Namespace API

Everything is organized logically:

client.workspaces.create()   // Workspace operations
client.bots.create()          // Bot operations
client.memories.create()      // Memory operations

No more guessing where things are!

Auto-Retry Logic

Network hiccup? We got you:

const client = createMoaClient({
  apiToken: 'moa_your_token',
  retries: 3,          // Retry up to 3 times
  retryDelay: 1000     // Wait 1s between retries
});

Environment Support

const environments = {
  dev: 'http://127.0.0.1:8000',           // Local development
  alpha: 'https://alpha-api.memof.ai',    // Alpha testing
  beta: 'https://beta-api.memof.ai',      // Beta testing
  sandbox: 'https://sandbox-api.memof.ai', // Safe playground
  production: 'https://api.memof.ai'      // The real deal
};

Framework Support

We play nice with everyone:

React

import { useMemofai } from './hooks/useMemofai';

function MyComponent() {
  const { memories, searchMemories } = useMemofai({
    apiToken: 'moa_token',
    botId: 'bot_123'
  });
  
  // Your component here
}

Next.js

// pages/api/memories/search.ts
import { createMoaClient } from 'memofai';

export default async function handler(req, res) {
  const client = createMoaClient({
    apiToken: process.env.MEMOFAI_API_TOKEN
  });
  
  const results = await client.memories.search(req.body);
  res.json({ results });
}

Express

import express from 'express';
import { createMoaClient } from 'memofai';

const app = express();
const client = createMoaClient({
  apiToken: process.env.MEMOFAI_API_TOKEN
});

app.post('/search', async (req, res) => {
  const results = await client.memories.search(req.body);
  res.json({ results });
});

Browser Support

Works in the browser too! Just needs a little config:

// vite.config.ts
export default {
  resolve: {
    alias: { buffer: 'buffer' }
  }
};

What's Next?

Ready to dive deeper?

  1. Installation Guide - Get set up properly
  2. Workspace Management - Organize like a pro
  3. Bot Operations - Build your bot army
  4. Memory Management - Where the magic happens
  5. Framework Examples - Real-world patterns

Package Info

{
  "name": "memofai",
  "version": "latest",
  "license": "MIT",
  "homepage": "https://memof.ai",
  "repository": "github:memof-ai/memofai-js-sdk"
}

Need Help?

Now go build something amazing! 🚀