Skip to main content

The official TypeScript / JavaScript library for the Memobase API

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
41%
Published
a month ago (0.0.10)
Shows the Memobase logo

User Profile-Based Memory for GenAI Apps

Memobase TypeScript and JavaScript API Library

This library provides convenient access to the Memobase REST API from TypeScript or JavaScript.

Installation

npm install @memobase/memobase

Installation from JSR

deno add jsr:@memobase/memobase
npx jsr add @memobase/memobase

Usage

The code below shows how to get started using the completions API.

import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase';

const client = new MemoBaseClient(process.env['MEMOBASE_PROJECT_URL'], process.env['MEMOBASE_API_KEY'])

const main = async () => {
    const ping = await client.ping()
    console.log(ping)

    const config = await client.getConfig()
    console.log(config)

    const updateConfig = await client.updateConfig('a: 1')
    console.log(updateConfig)

    let userId = await client.addUser()
    console.log(userId)

    userId = await client.updateUser(userId, { name: 'John Doe' })
    console.log('Updated user id: ', userId)

    let user = await client.getUser(userId)
    console.log(user)

    const blobId = await user.insert(Blob.parse({
        type: BlobType.Enum.chat,
        messages: [{
            role: 'user',
            content: 'Hello, how are you? my name is John Doe'
        }]
    }))
    console.log(blobId)

    const blob = await user.get(blobId)
    console.log(blob)

    const flushSuc = await user.flush(BlobType.Enum.chat)
    console.log('Flush success: ', flushSuc)
    
    const blobs = await user.getAll(BlobType.Enum.chat)
    console.log(blobs)

    user = await client.getOrCreateUser(userId)
    console.log(user)

    const profiles = await user.profile(2000, ['Topic1'], ['SubTopic1'], 200, { Topic1: 200 })
    console.log(profiles)

    const event = await user.event(10, 1000)
    console.log(event)

    const context = await user.context(2000, 1000)
    console.log(context)

    profiles.map((profile) => {
        user.deleteProfile(profile.id).then((isDel) => {
            console.log('Delete profile success: ', isDel)
        })
    })

    const isDel = await client.deleteUser(userId)
    console.log(isDel)
}

main()

Support

Join the community for support and discussions:

Or Just email us ❤️

Contributors

This project exists thanks to all the people who contribute.

And thank you to all our backers! 🙏

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Add Package

deno add jsr:@memobase/memobase

Import symbol

import * as memobase from "@memobase/memobase";

---- OR ----

Import directly with a jsr specifier

import * as memobase from "jsr:@memobase/memobase";

Add Package

npx jsr add @memobase/memobase

Import symbol

import * as memobase from "@memobase/memobase";

Add Package

yarn dlx jsr add @memobase/memobase

Import symbol

import * as memobase from "@memobase/memobase";

Add Package

pnpm dlx jsr add @memobase/memobase

Import symbol

import * as memobase from "@memobase/memobase";

Add Package

bunx jsr add @memobase/memobase

Import symbol

import * as memobase from "@memobase/memobase";