getmnemo-vercel-ai 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +108 -13
  2. package/package.json +6 -3
package/README.md CHANGED
@@ -1,28 +1,28 @@
1
- # @ledgermem/vercel-ai
1
+ # getmnemo-vercel-ai
2
2
 
3
- LedgerMem adapter for the [Vercel AI SDK](https://sdk.vercel.dev). Drop-in
3
+ [Mnemo](https://mnemohq.com) adapter for the [Vercel AI SDK](https://sdk.vercel.dev). Drop-in
4
4
  `tool()` definitions that let any model search and write persistent memory,
5
5
  plus a small React hook for client-side memory views.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```bash
10
- npm install @ledgermem/vercel-ai @ledgermem/memory ai
10
+ npm install getmnemo-vercel-ai ai
11
11
  ```
12
12
 
13
- Set `LEDGERMEM_API_KEY` and `LEDGERMEM_WORKSPACE_ID` in your environment, or
14
- pass them explicitly.
13
+ `getmnemo` (the core SDK) is bundled as a dependency. Set `GETMNEMO_API_KEY`
14
+ and `GETMNEMO_WORKSPACE_ID` in your environment, or pass them explicitly.
15
15
 
16
16
  ## Quickstart (30 seconds)
17
17
 
18
18
  ```ts
19
19
  import { streamText } from "ai";
20
20
  import { openai } from "@ai-sdk/openai";
21
- import { ledgermemTools } from "@ledgermem/vercel-ai";
21
+ import { getmnemoTools } from "getmnemo-vercel-ai";
22
22
 
23
23
  const result = await streamText({
24
24
  model: openai("gpt-4o"),
25
- tools: ledgermemTools, // memorySearch + memoryAdd
25
+ tools: getmnemoTools, // memorySearch + memoryAdd
26
26
  maxSteps: 5,
27
27
  messages: [{ role: "user", content: "What did I tell you about my coffee?" }],
28
28
  });
@@ -30,34 +30,129 @@ const result = await streamText({
30
30
  for await (const chunk of result.textStream) process.stdout.write(chunk);
31
31
  ```
32
32
 
33
+ `getmnemoTools` is lazy — it reads `GETMNEMO_API_KEY` and
34
+ `GETMNEMO_WORKSPACE_ID` from `process.env` the first time a tool runs.
35
+
33
36
  ## Per-user memory (route handler)
34
37
 
38
+ Use `createMnemoTools` when you need per-request scoping. The `metadata` you
39
+ pass is merged into every `memoryAdd` call (and cannot be overwritten by the
40
+ model), so it's the right place for a `userId`:
41
+
35
42
  ```ts
36
- import { createLedgerMemTools } from "@ledgermem/vercel-ai";
43
+ import { streamText } from "ai";
44
+ import { openai } from "@ai-sdk/openai";
45
+ import { createMnemoTools } from "getmnemo-vercel-ai";
37
46
 
38
47
  export async function POST(req: Request) {
39
48
  const { messages, userId } = await req.json();
40
- const tools = createLedgerMemTools({ metadata: { userId } });
41
- return streamText({ model: openai("gpt-4o"), tools, messages }).toDataStreamResponse();
49
+ const tools = createMnemoTools({ metadata: { userId } });
50
+
51
+ const result = streamText({
52
+ model: openai("gpt-4o"),
53
+ tools,
54
+ maxSteps: 5,
55
+ messages,
56
+ });
57
+
58
+ return result.toDataStreamResponse();
42
59
  }
43
60
  ```
44
61
 
62
+ `createMnemoTools` also accepts `apiKey` / `workspaceId` (instead of env vars),
63
+ a pre-built `client`, and a `defaultLimit` for searches the model doesn't size:
64
+
65
+ ```ts
66
+ const tools = createMnemoTools({
67
+ apiKey: process.env.GETMNEMO_API_KEY,
68
+ workspaceId: process.env.GETMNEMO_WORKSPACE_ID,
69
+ defaultLimit: 8,
70
+ });
71
+ ```
72
+
73
+ ## One-shot generation
74
+
75
+ The same tools work with `generateText`:
76
+
77
+ ```ts
78
+ import { generateText } from "ai";
79
+ import { openai } from "@ai-sdk/openai";
80
+ import { getmnemoTools } from "getmnemo-vercel-ai";
81
+
82
+ const { text } = await generateText({
83
+ model: openai("gpt-4o"),
84
+ tools: getmnemoTools,
85
+ maxSteps: 5,
86
+ prompt: "Remember that I'm vegetarian, then suggest a dinner.",
87
+ });
88
+ ```
89
+
90
+ ## Direct SDK access
91
+
92
+ Need to read or write memory outside a model loop? Use the core client
93
+ directly:
94
+
95
+ ```ts
96
+ import { Mnemo } from "getmnemo";
97
+
98
+ const memory = new Mnemo({
99
+ apiKey: process.env.GETMNEMO_API_KEY!,
100
+ workspaceId: process.env.GETMNEMO_WORKSPACE_ID!,
101
+ });
102
+
103
+ await memory.add({ content: "User prefers oat milk." });
104
+ const { hits } = await memory.search({ query: "what milk does the user like?" });
105
+ ```
106
+
45
107
  ## React hook
46
108
 
109
+ For client-side memory views (sidebars, inspectors), use `useMnemo`.
110
+
111
+ > **⚠️ Security: the Mnemo `apiKey` is a full-access credential.**
112
+ > There is exactly **one** API key, and it grants **read, write, and delete**
113
+ > rights over your entire workspace. There is **no** public, scoped, or
114
+ > read-only key. **NEVER** ship it in a browser bundle or any `NEXT_PUBLIC_`
115
+ > variable — anything with that prefix is inlined into client-side JavaScript
116
+ > and exposed to every visitor, handing them a delete-capable credential.
117
+ >
118
+ > `useMnemo` is intended for **trusted internal/admin dashboards only**.
119
+ > Production, public-facing apps must **never** expose the key to the browser:
120
+ > proxy all memory reads/writes through a server route (a Server Action or
121
+ > Route Handler) that holds the key server-side.
122
+
123
+ The hook reads `NEXT_PUBLIC_GETMNEMO_API_KEY` /
124
+ `NEXT_PUBLIC_GETMNEMO_WORKSPACE_ID` by default and returns `SearchHit` objects,
125
+ keyed by `memoryId`. The example below is **internal/admin only — not for
126
+ public-facing apps**:
127
+
47
128
  ```tsx
48
129
  "use client";
49
- import { useLedgerMem } from "@ledgermem/vercel-ai/react";
130
+ import { useMnemo } from "getmnemo-vercel-ai/react";
131
+ import type { SearchHit } from "getmnemo";
50
132
 
51
133
  export function MemorySidebar() {
52
- const { results, search, loading } = useLedgerMem({ initialQuery: "preferences" });
134
+ const { results, search, loading } = useMnemo<SearchHit>({
135
+ initialQuery: "preferences",
136
+ });
137
+
138
+ if (loading) return <p>Loading…</p>;
139
+
53
140
  return (
54
141
  <ul>
55
- {results.map((m: any) => <li key={m.id}>{m.content}</li>)}
142
+ {results.map((m) => (
143
+ <li key={m.memoryId}>{m.content}</li>
144
+ ))}
56
145
  </ul>
57
146
  );
58
147
  }
59
148
  ```
60
149
 
150
+ `useMnemo` also exposes `add(content, metadata?)`, `remove(id)`, and `error`.
151
+
152
+ ## Docs
153
+
154
+ Full documentation at [mnemohq.com](https://mnemohq.com).
155
+
61
156
  ## License
62
157
 
63
158
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getmnemo-vercel-ai",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Mnemo adapter for the Vercel AI SDK — drop-in tools for streamText / generateText / useChat.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,7 +34,10 @@
34
34
  "rag",
35
35
  "tools"
36
36
  ],
37
- "author": "Mnemo <founders@getmnemo.xyz>",
37
+ "author": {
38
+ "name": "Mnemo",
39
+ "url": "https://mnemohq.com"
40
+ },
38
41
  "license": "MIT",
39
42
  "repository": {
40
43
  "type": "git",
@@ -67,5 +70,5 @@
67
70
  "engines": {
68
71
  "node": ">=18.17.0"
69
72
  },
70
- "homepage": "https://getmnemo.xyz"
73
+ "homepage": "https://mnemohq.com"
71
74
  }