@mnemo-ai/client-ts 3.6.0-alpha.0
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.
- package/LICENSE +19 -0
- package/README.md +176 -0
- package/dist/index.cjs +2047 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2904 -0
- package/dist/index.d.ts +2904 -0
- package/dist/index.js +2041 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
|
|
17
|
+
Copyright 2024-2026 Lucas Mailland and Mnemosyne contributors
|
|
18
|
+
|
|
19
|
+
See the full Apache 2.0 license text at the URL above.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# @mnemo-ai/client-ts
|
|
2
|
+
|
|
3
|
+
> **AI pointer:** Typed TypeScript HTTP client SDK for the Mnemosyne server. No runtime deps beyond fetch.
|
|
4
|
+
>
|
|
5
|
+
> **Depends on:** nothing (uses native fetch)
|
|
6
|
+
>
|
|
7
|
+
> **Exposes:** MnemosyneClient (typed methods matching the HTTP API surface)
|
|
8
|
+
>
|
|
9
|
+
> **Status:** STABLE
|
|
10
|
+
>
|
|
11
|
+
> **See also:** [CLAUDE.md](../../CLAUDE.md) · [docs/INDEX.md](../../docs/INDEX.md) · [docs/architecture/API.md](../../docs/architecture/API.md)
|
|
12
|
+
|
|
13
|
+
Zero runtime dependencies. Works in Node 20+, Bun, Deno, Cloudflare Workers, and modern browsers. Drop-in alternative to `@mnemo-ai/core` when you'd rather talk to a centralized memory server than embed the engine in your app.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @mnemo-ai/client-ts
|
|
19
|
+
# or
|
|
20
|
+
npm i @mnemo-ai/client-ts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 30-second start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { MnemosyneClient } from "@mnemo-ai/client-ts";
|
|
27
|
+
|
|
28
|
+
const memory = new MnemosyneClient({
|
|
29
|
+
url: "https://memory.example.com",
|
|
30
|
+
apiKey: process.env.MNEMOSYNE_API_KEY!,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const { hits } = await memory.recall({ query: "user email preferences" });
|
|
34
|
+
console.log(hits);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Examples
|
|
38
|
+
|
|
39
|
+
### 1. Basic recall
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const result = await memory.recall({
|
|
43
|
+
query: "Acme's preferred communication language",
|
|
44
|
+
topK: 5,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
for (const hit of result.hits) {
|
|
48
|
+
console.log(`${hit.score.toFixed(2)} — ${hit.content}`);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Recall with a pre-embedded vector
|
|
53
|
+
|
|
54
|
+
Useful when you already have the query vector from a shared embedding cache, or you want to use a non-default embedding model. The server skips its own embedding pass when you pass `vector`.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import OpenAI from "openai";
|
|
58
|
+
|
|
59
|
+
const openai = new OpenAI();
|
|
60
|
+
const { data } = await openai.embeddings.create({
|
|
61
|
+
model: "text-embedding-3-small",
|
|
62
|
+
input: "billing escalation policy",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const result = await memory.recall({
|
|
66
|
+
query: "billing escalation policy",
|
|
67
|
+
vector: data[0].embedding,
|
|
68
|
+
topK: 10,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3. Create a fact
|
|
73
|
+
|
|
74
|
+
`createFact` is idempotent via content-hash on the server — re-sending the same content won't duplicate. The response is the created `Fact` (including its assigned `id`).
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const result = await memory.createFact({
|
|
78
|
+
content: "Acme prefers communication in Spanish.",
|
|
79
|
+
attribution: { source: "user_stated" },
|
|
80
|
+
tags: ["client:acme"],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log("stored fact:", result.id);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 4. Time-travel recall with `asOf`
|
|
87
|
+
|
|
88
|
+
Ask what memory knew at a past instant — useful for replaying historical agent decisions and for audit trails.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const snapshot = await memory.recall({
|
|
92
|
+
query: "team escalation owner",
|
|
93
|
+
asOf: "2026-01-15T00:00:00Z",
|
|
94
|
+
topK: 3,
|
|
95
|
+
});
|
|
96
|
+
// `snapshot.hits` reflects facts as they existed on Jan 15, 2026.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 5. Error handling
|
|
100
|
+
|
|
101
|
+
The SDK throws a typed error hierarchy. Branch on the class — not the message — for resilient retry/UX logic.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import {
|
|
105
|
+
MnemosyneAPIError,
|
|
106
|
+
MnemosyneNetworkError,
|
|
107
|
+
MnemosyneTimeoutError,
|
|
108
|
+
} from "@mnemo-ai/client-ts";
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
await memory.recall({ query: "anything" });
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err instanceof MnemosyneTimeoutError) {
|
|
114
|
+
// Server is alive but slow — degrade gracefully.
|
|
115
|
+
} else if (err instanceof MnemosyneAPIError && err.status === 401) {
|
|
116
|
+
// Rotate API key.
|
|
117
|
+
} else if (err instanceof MnemosyneNetworkError) {
|
|
118
|
+
// DNS / TLS / connection refused. Retry or fail open.
|
|
119
|
+
} else if (err instanceof MnemosyneAPIError) {
|
|
120
|
+
console.error(`Mnemosyne ${err.status} [${err.code}] ${err.requestId}`);
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Configuration
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
new MnemosyneClient({
|
|
130
|
+
url: "https://memory.example.com",
|
|
131
|
+
apiKey: process.env.MNEMOSYNE_API_KEY!,
|
|
132
|
+
|
|
133
|
+
// Inject a custom fetch (defaults to global fetch). Useful in tests
|
|
134
|
+
// or when wrapping for tracing.
|
|
135
|
+
fetch: undici.fetch,
|
|
136
|
+
|
|
137
|
+
// Per-request timeout in milliseconds. Default 30_000.
|
|
138
|
+
timeout: 10_000,
|
|
139
|
+
|
|
140
|
+
// Retry policy for transient failures (5xx + network errors).
|
|
141
|
+
// Default: 3 attempts, exponential backoff with full jitter (200ms,
|
|
142
|
+
// 400ms, 800ms). 4xx errors and timeouts are NOT retried by default.
|
|
143
|
+
retry: {
|
|
144
|
+
attempts: 5,
|
|
145
|
+
initialDelayMs: 100,
|
|
146
|
+
shouldRetry: (err, attempt) => attempt < 5,
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
// Optional User-Agent suffix to distinguish traffic in server logs.
|
|
150
|
+
userAgent: "my-app/1.2.3",
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## API
|
|
155
|
+
|
|
156
|
+
| Method | HTTP | Description |
|
|
157
|
+
| ----------------------------------- | -------------------------------------- | -------------------------------------------- |
|
|
158
|
+
| `recall(input)` | `POST /recall` | Top-K relevant facts |
|
|
159
|
+
| `createFact(input)` | `POST /facts` | Persist a new fact (idempotent) |
|
|
160
|
+
| `getFact(id)` | `GET /facts/:id` | Fetch one fact |
|
|
161
|
+
| `pinFact(id)` / `unpinFact(id)` | `POST /facts/:id/pin` (`{ pinned: true/false }`) | Protect from auto-prune; recall boost |
|
|
162
|
+
| `forgetFact(id)` | `DELETE /facts/:id` | Soft-delete (bitemporal close) |
|
|
163
|
+
| `timeline(input)` | `GET /timeline` | Recent fact activity |
|
|
164
|
+
| `health()` | `GET /health` | Liveness + per-component readiness |
|
|
165
|
+
|
|
166
|
+
## When to use this vs. `@mnemo-ai/core`
|
|
167
|
+
|
|
168
|
+
| Pick `@mnemo-ai/client-ts` if… | Pick `@mnemo-ai/core` directly if… |
|
|
169
|
+
| -------------------------------------------------------------------- | --------------------------------------------------------------- |
|
|
170
|
+
| You're talking to a shared memory server from many apps | You want sub-millisecond in-process recall |
|
|
171
|
+
| Your runtime can't host Postgres / pgvector / Drizzle | You already have a Postgres pool and want to reuse it |
|
|
172
|
+
| You need a stable wire contract across engine refactors | You want the full hookable internals (extraction, consolidation) |
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
Apache-2.0 © Lucas Mailland
|