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

memory-sdk

v1.1.1

Published

AgentLink Memory API client - CRUD and search with API Key

Readme

memory-sdk

AgentLink Memory API 客户端:使用 API Key 对 /api/agent/v1/memories 进行 CRUD 与列表/搜索,并对 /api/agent/v1/process 进行 Chat 补全(含流式),适用于 Node 与浏览器。

获取 API Key

Memory 设置页 的「API Key」区域创建 Key,格式为 mix_ 开头。请求时需在请求头中携带:Authorization: Bearer <key>X-Api-Key: <key>,本 SDK 使用 Bearer 方式。

安装

npm install memory-sdk

浏览器示例

仓库内提供 example.html,在浏览器中填写 API Key 即可体验列表、搜索、创建、更新、删除。也可通过 CDN 直接使用:

<script type="module">
  import { MemoryClient } from 'https://cdn.jsdelivr.net/npm/memory-sdk/dist/index.mjs';
  const client = new MemoryClient({ apiKey: 'mix_xxx' });
  const list = await client.list();
  console.log(list);
</script>

使用

连接官方站(默认)

不传 baseUrl 时,默认请求 https://www.mixlab.top/api

import { MemoryClient } from 'memory-sdk';

const client = new MemoryClient({ apiKey: 'mix_xxx' });

// 列表
const list = await client.list();
const filtered = await client.list({ category: '笔记', limit: 20, offset: 0 });

// 搜索
const results = await client.search('关键词', 50);

// 单条
const one = await client.get('memory-id'); // 404 时为 null

// 创建
const created = await client.create({
  source: 'https://example.com',
  category: '阅读',
  content: '内容摘要',
  tags: ['tag1'],
});

// 更新
const updated = await client.update(created.id, { content: '更新后的内容' });

// 删除
await client.delete(created.id);

// Chat 补全(非流式)
const res = await client.process({
  messages: [{ role: 'user', content: '今天学了 Next.js' }],
});
console.log(res.choices[0].message.content);

// Chat 补全(流式)
for await (const chunk of await client.processStream({
  messages: [{ role: 'user', content: '你好' }],
})) {
  const text = chunk.choices[0]?.delta?.content;
  if (text) process.stdout.write(text);
}

Chat 补全(process)

client.process()client.processStream() 对应服务端 POST /api/agent/v1/process,鉴权与 Memory 相同(同一 API Key)。

  • process(options):非流式,返回 ProcessResponse(OpenAI chat.completion 风格)。不传 response_format 时,服务端使用内置 systemPrompt 与 Memory 五字段 schema 整理最后一条 user 内容并返回 JSON。
  • processStream(options):流式,返回 AsyncIterable<ProcessChunk>,可逐 chunk 取 choices[0].delta.content
  • 可选参数:modeltemperatureresponse_format{ type: 'json_object' } | { type: 'text' })、llm{ apiUrl, apiKey, model? } 覆盖后端 LLM)。
  • 非 2xx 时解析 { error: { message } } 并抛出 Error

自建或同源

传入 baseUrl 即可:

  • 自建服务:baseUrl: 'https://your-domain.com/api'
  • 浏览器同源:baseUrl: window.location.origin + '/api'
const client = new MemoryClient({
  apiKey: 'mix_xxx',
  baseUrl: 'https://your-domain.com/api',
});

类型

import type {
  Memory,
  CreatePayload,
  UpdatePayload,
  ListParams,
  ProcessMessage,
  ProcessOptions,
  ProcessResponse,
  ProcessChunk,
} from 'memory-sdk';
import { DEFAULT_BASE_URL } from 'memory-sdk';

API

Memory CRUD

  • list(params?: ListParams): Promise<Memory[]> — 列表,支持 categorysourcetaglimitoffset
  • search(q: string, limit?: number): Promise<Memory[]> — 关键词搜索
  • get(id: string): Promise<Memory | null> — 按 id 获取,404 返回 null
  • create(payload: CreatePayload): Promise<Memory> — 创建(sourcecategorycontent 必填)
  • update(id: string, payload: UpdatePayload): Promise<Memory> — 更新
  • delete(id: string): Promise<void> — 删除

Chat 补全(process)

  • process(options: ProcessOptions): Promise<ProcessResponse> — 非流式补全
  • processStream(options: ProcessOptions): Promise<AsyncIterable<ProcessChunk>> — 流式补全

非 2xx 响应会解析 { error?: string }{ error: { message } } 并抛出 Error