kagura-memory 0.3.0 → 0.6.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 +21 -21
- package/README.md +392 -164
- package/dist/cli.js +1294 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +429 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +604 -3
- package/dist/index.d.ts +604 -3
- package/dist/index.js +402 -12
- package/dist/index.js.map +1 -1
- package/package.json +66 -63
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 kagura-ai
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kagura-ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,164 +1,392 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<strong>Kagura Memory SDK for TypeScript</strong> — Node.js client for <a href="https://github.com/kagura-ai/memory-cloud">Kagura Memory Cloud</a>
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
## What is this?
|
|
6
|
-
|
|
7
|
-
This SDK connects your TypeScript/JavaScript code to [Kagura Memory Cloud](https://github.com/kagura-ai/memory-cloud), giving AI agents the ability to **remember, search, and learn** from past interactions. It is a TypeScript port of the [Python SDK](https://github.com/kagura-ai/kagura-memory-python-sdk) core:
|
|
8
|
-
|
|
9
|
-
| Client | Protocol | Use Case |
|
|
10
|
-
|--------|----------|----------|
|
|
11
|
-
| **`KaguraClient`** | MCP (JSON-RPC) | Direct memory ops — remember, recall, explore, reference, forget |
|
|
12
|
-
| **`ResourceClient`** | REST API | External data ingestion — push data from Slack, CI/CD, CRM into Kagura |
|
|
13
|
-
| **`FilesClient`** | REST + presigned PUT | File uploads with sha256 integrity binding (R2) |
|
|
14
|
-
| **`WorkspaceClient`** | REST API | Workspace member, invitation, and API key management |
|
|
15
|
-
| **`AgentsClient`** | REST API | Agent bootstrap for API-key-only callers (no MCP session) |
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install kagura-memory
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Requires Node.js >= 18 (native `fetch`). Zero runtime dependencies.
|
|
24
|
-
|
|
25
|
-
## Quick Start
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { KaguraClient } from "kagura-memory";
|
|
29
|
-
|
|
30
|
-
// Credentials resolve automatically: explicit apiKey > KAGURA_API_KEY env
|
|
31
|
-
// > OAuth profile (~/.kagura/credentials.json, shared with the Python CLI)
|
|
32
|
-
// > .kagura.json
|
|
33
|
-
const client = new KaguraClient();
|
|
34
|
-
|
|
35
|
-
// Store a memory
|
|
36
|
-
const stored = await client.remember({
|
|
37
|
-
contextId: "your-context-id",
|
|
38
|
-
summary: "User prefers TypeScript strict mode",
|
|
39
|
-
content: "Enabled strict + noUncheckedIndexedAccess in all new projects.",
|
|
40
|
-
type: "note",
|
|
41
|
-
tags: ["typescript", "preferences"],
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Search memories (hybrid semantic + keyword)
|
|
45
|
-
const hits = await client.recall({
|
|
46
|
-
contextId: "your-context-id",
|
|
47
|
-
query: "typescript preferences",
|
|
48
|
-
k: 5,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
for (const memory of hits.results as Array<Record<string, unknown>>) {
|
|
52
|
-
console.log(memory.summary);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
await client.close();
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Authentication
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
1. **Explicit key** — `new KaguraClient({ apiKey: "kagura_..." })`
|
|
63
|
-
2. **Environment** — `KAGURA_API_KEY` (+ optional `KAGURA_MCP_URL`)
|
|
64
|
-
3. **OAuth profile** — `~/.kagura/credentials.json`, written by
|
|
65
|
-
CLI's `kagura auth login`. Profiles
|
|
66
|
-
`{ profile: "name" }`) and auto-refresh work
|
|
67
|
-
the credentials file is shared between both
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
`
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
both SDKs
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>Kagura Memory SDK for TypeScript</strong> — Node.js client for <a href="https://github.com/kagura-ai/memory-cloud">Kagura Memory Cloud</a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
## What is this?
|
|
6
|
+
|
|
7
|
+
This SDK connects your TypeScript/JavaScript code to [Kagura Memory Cloud](https://github.com/kagura-ai/memory-cloud), giving AI agents the ability to **remember, search, and learn** from past interactions. It is a TypeScript port of the [Python SDK](https://github.com/kagura-ai/kagura-memory-python-sdk) core:
|
|
8
|
+
|
|
9
|
+
| Client | Protocol | Use Case |
|
|
10
|
+
|--------|----------|----------|
|
|
11
|
+
| **`KaguraClient`** | MCP (JSON-RPC) | Direct memory ops — remember, recall, explore, reference, forget |
|
|
12
|
+
| **`ResourceClient`** | REST API | External data ingestion — push data from Slack, CI/CD, CRM into Kagura |
|
|
13
|
+
| **`FilesClient`** | REST + presigned PUT | File uploads with sha256 integrity binding (R2) |
|
|
14
|
+
| **`WorkspaceClient`** | REST API | Workspace member, invitation, and API key management |
|
|
15
|
+
| **`AgentsClient`** | REST API | Agent bootstrap for API-key-only callers (no MCP session) |
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install kagura-memory
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires Node.js >= 18 (native `fetch`). Zero runtime dependencies.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { KaguraClient } from "kagura-memory";
|
|
29
|
+
|
|
30
|
+
// Credentials resolve automatically: explicit apiKey > KAGURA_API_KEY env
|
|
31
|
+
// > OAuth profile (~/.kagura/credentials.json, shared with the Python CLI)
|
|
32
|
+
// > .kagura.json
|
|
33
|
+
const client = new KaguraClient();
|
|
34
|
+
|
|
35
|
+
// Store a memory
|
|
36
|
+
const stored = await client.remember({
|
|
37
|
+
contextId: "your-context-id",
|
|
38
|
+
summary: "User prefers TypeScript strict mode",
|
|
39
|
+
content: "Enabled strict + noUncheckedIndexedAccess in all new projects.",
|
|
40
|
+
type: "note",
|
|
41
|
+
tags: ["typescript", "preferences"],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Search memories (hybrid semantic + keyword)
|
|
45
|
+
const hits = await client.recall({
|
|
46
|
+
contextId: "your-context-id",
|
|
47
|
+
query: "typescript preferences",
|
|
48
|
+
k: 5,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
for (const memory of hits.results as Array<Record<string, unknown>>) {
|
|
52
|
+
console.log(memory.summary);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await client.close();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Authentication
|
|
59
|
+
|
|
60
|
+
Four ways to authenticate, in resolution order:
|
|
61
|
+
|
|
62
|
+
1. **Explicit key** — `new KaguraClient({ apiKey: "kagura_..." })`
|
|
63
|
+
2. **Environment** — `KAGURA_API_KEY` (+ optional `KAGURA_MCP_URL`)
|
|
64
|
+
3. **OAuth profile** — `~/.kagura/credentials.json`, written by `login()`
|
|
65
|
+
(below) or the Python CLI's `kagura auth login`. Profiles
|
|
66
|
+
(`KAGURA_PROFILE` env or `{ profile: "name" }`) and auto-refresh work
|
|
67
|
+
exactly like the Python SDK; the credentials file is shared between both
|
|
68
|
+
SDKs.
|
|
69
|
+
4. **Config file** — `.kagura.json` in the working directory or home:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"api_key": "kagura_your_api_key",
|
|
74
|
+
"mcp_url": "https://memory.kagura-ai.com/mcp"
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Logging in from the terminal
|
|
79
|
+
|
|
80
|
+
To authenticate a machine without writing any code:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npx kagura-memory auth login
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`login` / `refresh` / `status` / `use` / `logout`, with the same flag names
|
|
87
|
+
as the Python CLI's `kagura auth …`, writing the same
|
|
88
|
+
`~/.kagura/credentials.json`. Either tool can create a profile the other
|
|
89
|
+
then uses.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npx kagura-memory auth login --profile work --read-only
|
|
93
|
+
npx kagura-memory auth status
|
|
94
|
+
npx kagura-memory auth use work
|
|
95
|
+
npx kagura-memory auth refresh --scope "memory:read"
|
|
96
|
+
npx kagura-memory auth logout --profile work
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`status` reports whether each profile is `active`, `expired (refreshable)`,
|
|
100
|
+
or `expired` — a profile whose access token lapsed is still usable when it
|
|
101
|
+
can refresh.
|
|
102
|
+
|
|
103
|
+
This bin covers **authentication only**. Memory operations stay
|
|
104
|
+
library-only; use the Python CLI or write TypeScript.
|
|
105
|
+
|
|
106
|
+
#### Logging in from TypeScript
|
|
107
|
+
|
|
108
|
+
`login()` runs the OAuth 2.0 Device Authorization Grant (RFC 8628) and
|
|
109
|
+
writes `~/.kagura/credentials.json` in exactly the format the Python CLI
|
|
110
|
+
writes — no Python install needed, and the profile stays interchangeable
|
|
111
|
+
between both SDKs.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { login, KaguraClient } from "kagura-memory";
|
|
115
|
+
|
|
116
|
+
const creds = await login({
|
|
117
|
+
onUserCode: ({ userCode, verificationUri, verificationUriComplete }) => {
|
|
118
|
+
console.log(`Open ${verificationUri} and enter ${userCode}`);
|
|
119
|
+
// Or, in a desktop app: shell.openExternal(verificationUriComplete)
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
console.log(`Logged in as ${creds.userEmail} (${creds.workspaceName})`);
|
|
124
|
+
|
|
125
|
+
// Subsequent clients pick the profile up automatically.
|
|
126
|
+
const client = new KaguraClient();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
There is no terminal IO and no browser launching inside the SDK —
|
|
130
|
+
`onUserCode` hands the code back and the host app decides how to show it.
|
|
131
|
+
|
|
132
|
+
Scope defaults to `DEFAULT_SCOPE` (`"memory:read memory:write"`) — the same
|
|
133
|
+
default as the CLI's `kagura auth login`, and exactly what the server's
|
|
134
|
+
pre-registered `kagura-cli` client is seeded with. Pass
|
|
135
|
+
`scope: READ_ONLY_SCOPE` for the CLI's `--read-only` behaviour. The two SDKs
|
|
136
|
+
share the credentials file, so a profile should not end up with different
|
|
137
|
+
authority depending on which one created it.
|
|
138
|
+
|
|
139
|
+
The server is resolved as `mcpUrl` > `KAGURA_MCP_URL` > the public default,
|
|
140
|
+
matching the CLI's `--server` chain — so a self-hosted deployment is picked
|
|
141
|
+
up from the environment. Plain HTTP is rejected for non-loopback hosts: the
|
|
142
|
+
flow carries a bearer token.
|
|
143
|
+
|
|
144
|
+
Nothing is written unless the exchange succeeds, so a failed login never
|
|
145
|
+
disturbs an existing profile: a denial throws `KaguraAuthDeniedError` and an
|
|
146
|
+
unapproved expiry throws `KaguraAuthExpiredError`. A response with no
|
|
147
|
+
`refresh_token` warns and still persists — the Python CLI treats a
|
|
148
|
+
non-refreshable profile as a valid degraded state, and the shared file must
|
|
149
|
+
mean the same thing to both SDKs. Check the returned `refreshToken` if you
|
|
150
|
+
need to react.
|
|
151
|
+
|
|
152
|
+
For a custom flow (your own polling UI, multi-profile management), the
|
|
153
|
+
primitives are exported too: `authorizeDevice`, `pollForToken`,
|
|
154
|
+
`refreshAccessToken`, `revokeToken`, plus the credentials store
|
|
155
|
+
(`loadCredentialsFile`, `updateProfile`, `setDefaultProfile`,
|
|
156
|
+
`deleteProfile`, …).
|
|
157
|
+
|
|
158
|
+
#### Refreshing
|
|
159
|
+
|
|
160
|
+
Clients auto-refresh as tokens near expiry, so most code never calls this.
|
|
161
|
+
`refresh()` covers what skew-driven rotation cannot:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import { refresh, READ_ONLY_SCOPE } from "kagura-memory";
|
|
165
|
+
|
|
166
|
+
// Forced rotation — e.g. after an upstream 401, when the token was
|
|
167
|
+
// revoked out-of-band and is not yet inside the skew window.
|
|
168
|
+
await refresh();
|
|
169
|
+
|
|
170
|
+
// Narrow an existing grant, no re-consent needed.
|
|
171
|
+
await refresh({ scope: READ_ONLY_SCOPE });
|
|
172
|
+
|
|
173
|
+
// Widening needs fresh consent, so it re-runs the device flow.
|
|
174
|
+
await refresh({
|
|
175
|
+
scope: "memory:read memory:write profile:read",
|
|
176
|
+
onUserCode: ({ userCode, verificationUri }) =>
|
|
177
|
+
console.log(`Open ${verificationUri} and enter ${userCode}`),
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The stored refresh token, scope, and workspace identity are preserved when
|
|
182
|
+
the server omits them. An expired refresh token throws
|
|
183
|
+
`KaguraAuthExpiredError` and leaves the stored profile untouched.
|
|
184
|
+
|
|
185
|
+
Callers holding their own provider can use `KaguraOAuth` directly — its
|
|
186
|
+
`forceRefresh()` is what `refresh()` builds on, including the
|
|
187
|
+
cross-process lock and the "another process already rotated" dedup.
|
|
188
|
+
|
|
189
|
+
### Error handling
|
|
190
|
+
|
|
191
|
+
All errors extend `KaguraError`:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { KaguraNotFoundError, KaguraRateLimitError } from "kagura-memory";
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
await client.recall({ contextId, query: "..." });
|
|
198
|
+
} catch (e) {
|
|
199
|
+
if (e instanceof KaguraNotFoundError) {
|
|
200
|
+
// context or memory missing
|
|
201
|
+
} else if (e instanceof KaguraRateLimitError) {
|
|
202
|
+
console.log(`retry after ${e.retryAfter}s`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Server-side domain errors (`{"status": "error", ...}`) are translated into
|
|
208
|
+
exceptions — `KaguraNotFoundError` for missing contexts/memories/reports/
|
|
209
|
+
agents/bindings, `KaguraError` otherwise — so you never need to inspect
|
|
210
|
+
`result.status`.
|
|
211
|
+
|
|
212
|
+
## `KaguraClient` method reference
|
|
213
|
+
|
|
214
|
+
Methods return the parsed server response. Most take a single camelCase
|
|
215
|
+
options object; `getAgent`, `deleteAgent`, `listAgentBindings` and
|
|
216
|
+
`deleteContext` take the id directly, and the workspace-wide calls
|
|
217
|
+
(`listContexts`, `listAgents`, `getUsage`, `getServerInfo`,
|
|
218
|
+
`checkServerVersion`, `getEmbeddingStatus`, `listEmbeddingModels`,
|
|
219
|
+
`getToolDefinitions`, `close`) take no arguments. The wire stays
|
|
220
|
+
snake_case; optional fields are omitted from the request when `undefined`.
|
|
221
|
+
|
|
222
|
+
### Memories
|
|
223
|
+
|
|
224
|
+
| Method | What it does |
|
|
225
|
+
|--------|--------------|
|
|
226
|
+
| `remember` | Store a memory. `details` accepts arbitrary JSON (including `location`, see below); `supersedes` declares this the newer version of an existing memory, shadowing the old one from default recall without destroying it; `deliveryMode: "always"` pins it. |
|
|
227
|
+
| `recall` | Hybrid semantic + keyword search. Takes `filters` (`type`, `tags`, `tags_match`, date bounds, `trust_tier`), `searchMode`, `useRerank`, `includeExploreHints`, `includeSuperseded` (read back what `supersedes` shadowed, annotated with `superseded_by`), and `contextIds` for 2–20-context search. |
|
|
228
|
+
| `reference` | Full detail for one memory, under `result.memory`. |
|
|
229
|
+
| `updateMemory` | Update in place by `memoryId`, or upsert by `externalId`. `details` **replaces** the stored object wholesale — round-trip keys you want to keep. |
|
|
230
|
+
| `forget` | Soft-delete (30-day retention) by `memoryId` or by `query`. |
|
|
231
|
+
| `listMemories` | Browse with substring, facet, and time-window filters. Omit `contextId` for the caller's cross-context view. |
|
|
232
|
+
|
|
233
|
+
### Deterministic lanes
|
|
234
|
+
|
|
235
|
+
These bypass ranking entirely — same inputs, same rows, every call. They are
|
|
236
|
+
the counterpart to `recall`'s probabilistic search.
|
|
237
|
+
|
|
238
|
+
| Method | Axis |
|
|
239
|
+
|--------|------|
|
|
240
|
+
| `loadPinned` | The complete, unranked `deliveryMode: "always"` set. Bounded: check `truncated` / `total_available` rather than assuming you got everything. |
|
|
241
|
+
| `recallUpcoming` | WHEN — `type: "time"` memories whose window overlaps `from`/`until`, soonest first. |
|
|
242
|
+
| `recallNearby` | WHERE — memories near a point, nearest first with `distance_m`. See [the WHERE axis](#the-where-axis--geospatial-memories). |
|
|
243
|
+
|
|
244
|
+
### Tags and the neural graph
|
|
245
|
+
|
|
246
|
+
| Method | What it does |
|
|
247
|
+
|--------|--------------|
|
|
248
|
+
| `listTags` | Tag vocabulary with counts and recency. `prefix` narrows by spelling; `withTags` is a multi-tag AND drill-down that also excludes those tags from the result — the two compose into server-side faceted browsing with no local index. |
|
|
249
|
+
| `explore` | Graph traversal from a seed memory (`depth` 1–5, `minWeight`). |
|
|
250
|
+
| `listEdges` | Edges touching a memory, incoming and outgoing, deduplicated. |
|
|
251
|
+
| `createEdge` / `updateEdge` / `deleteEdge` | Manual edge curation. `(sourceId, targetId)` is the identity; self-loops are rejected. |
|
|
252
|
+
| `findDuplicates` | Near-duplicate pairs above `threshold` (0.5–1.0, default 0.90). |
|
|
253
|
+
| `feedback` | Record whether a recalled memory was useful — an append-only signal in its own lane, not a memory edit. |
|
|
254
|
+
|
|
255
|
+
### Contexts
|
|
256
|
+
|
|
257
|
+
| Method | What it does |
|
|
258
|
+
|--------|--------------|
|
|
259
|
+
| `listContexts` | All contexts, with the workspace's `can_create` quota flag. |
|
|
260
|
+
| `createContext` | New context. Throws `KaguraQuotaError` when the workspace limit is reached. `embeddingModel` is immutable afterwards. |
|
|
261
|
+
| `getContextInfo` | Metadata plus, by default, a memory-count breakdown. |
|
|
262
|
+
| `updateContext` | Change display name, summary, usage guide, visibility, lock. |
|
|
263
|
+
| `deleteContext` | Delete by id. Locked contexts are refused. |
|
|
264
|
+
| `mergeContexts` | Move memories between contexts. Both must share an embedding model and workspace. |
|
|
265
|
+
| `updateSearchConfig` | Hybrid-search weights (must sum to 1.0 ±0.01). Owner/editor only. |
|
|
266
|
+
| `setupResource` | Context + resource entity + ingestion token in one transaction. The returned token is plaintext and shown once. |
|
|
267
|
+
|
|
268
|
+
### Agent run-state
|
|
269
|
+
|
|
270
|
+
Ephemeral, TTL-bounded, and excluded from recall — deliberately not memories.
|
|
271
|
+
|
|
272
|
+
| Method | What it does |
|
|
273
|
+
|--------|--------------|
|
|
274
|
+
| `setState` / `getState` | Key/value at `(contextId, key)`. Omit `key` on read to list all live keys. |
|
|
275
|
+
|
|
276
|
+
### Sleep maintenance
|
|
277
|
+
|
|
278
|
+
| Method | What it does |
|
|
279
|
+
|--------|--------------|
|
|
280
|
+
| `getSleepHistory` | Recent runs, newest first. |
|
|
281
|
+
| `getSleepReport` | One run in detail, including the per-action audit log. |
|
|
282
|
+
| `rollbackSleepRun` | Reverse a completed run. The server commits per step, so a partial rollback is possible — read the returned summary. |
|
|
283
|
+
|
|
284
|
+
### Workspace and server
|
|
285
|
+
|
|
286
|
+
| Method | What it does |
|
|
287
|
+
|--------|--------------|
|
|
288
|
+
| `getServerInfo` | Version and capabilities. |
|
|
289
|
+
| `checkServerVersion` | Compare against `MIN_SERVER_VERSION`. Advisory: logs, never throws. |
|
|
290
|
+
| `getUsage` | Workspace quota and usage. |
|
|
291
|
+
| `getMemoryStats` | Per-memory usage stats, sortable and paged. |
|
|
292
|
+
| `getEmbeddingStatus` / `listEmbeddingModels` | Embedding backend state and the models available for `createContext`. |
|
|
293
|
+
| `getToolDefinitions` | Raw MCP `tools/list` output — every tool the server exposes, including any this SDK does not wrap yet. |
|
|
294
|
+
| `close` | Drop the MCP session. The next call re-initializes automatically. |
|
|
295
|
+
|
|
296
|
+
Agent Registry and binding methods are covered in
|
|
297
|
+
[Agent control plane](#agent-control-plane-memory-cloud-v0490) below.
|
|
298
|
+
|
|
299
|
+
## Agent control plane (memory-cloud v0.49.0+)
|
|
300
|
+
|
|
301
|
+
`KaguraClient` wraps the RFC-0002 agent platform: the **Agent Registry**
|
|
302
|
+
(`registerAgent` / `listAgents` / `getAgent` / `updateAgent` /
|
|
303
|
+
`deleteAgent`), subtractive **context bindings** (`bindAgentContext` /
|
|
304
|
+
`listAgentBindings` / `updateAgentBinding` / `unbindAgentContext`), and
|
|
305
|
+
the session-start `getAgentBootstrap` call. Registry and binding methods are
|
|
306
|
+
**owner/admin-gated** server-side; `deleteAgent` is permanent and
|
|
307
|
+
cascades every API key bound to the agent (prefer
|
|
308
|
+
`updateAgent({ status: "retired" })` for operational retirement).
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
// One-time provisioning (owner/admin): register the agent, bind its context
|
|
312
|
+
const agent = await client.registerAgent({ name: "ci-agent", framework: "claude-code" });
|
|
313
|
+
await client.bindAgentContext({ agentId: agent.id, contextId: "ctx-uuid", isDefault: true });
|
|
314
|
+
|
|
315
|
+
// Session start: rehydrate cognitive state in one call
|
|
316
|
+
const bootstrap = await client.getAgentBootstrap({
|
|
317
|
+
agentId: agent.id, // contextId omitted → default binding
|
|
318
|
+
sessionId: "run-42", // echoed in the correlation block
|
|
319
|
+
query: "session summary", // enables the trusted-only recall component
|
|
320
|
+
});
|
|
321
|
+
if (bootstrap.degraded) {
|
|
322
|
+
// some component failed fail-soft; inspect bootstrap.components
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Deployed agents holding only an API key (e.g. an agent-bound member key)
|
|
327
|
+
can bootstrap over REST without an MCP session:
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import { AgentsClient } from "kagura-memory";
|
|
331
|
+
|
|
332
|
+
const agents = AgentsClient.fromMcpUrl();
|
|
333
|
+
const bootstrap = await agents.bootstrap({ agentId: "agent-uuid" });
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Requires memory-cloud **v0.49.0+** — older servers return MCP "tool not
|
|
337
|
+
found" / REST 404 on this surface; everything else in the SDK keeps
|
|
338
|
+
working against `MIN_SERVER_VERSION`.
|
|
339
|
+
|
|
340
|
+
## The WHERE axis — geospatial memories
|
|
341
|
+
|
|
342
|
+
Any memory can carry a location under `details.location`, which makes it
|
|
343
|
+
reachable from `recallNearby()` — a deterministic spatial query (nearest
|
|
344
|
+
first, each result carrying `distance_m`), not semantic search.
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
await client.remember({
|
|
348
|
+
contextId,
|
|
349
|
+
summary: "Coffee shop with reliable wifi",
|
|
350
|
+
content: "...",
|
|
351
|
+
details: { location: { lat: 35.6812, lon: 139.7671, label: "Tokyo Station" } },
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const near = await client.recallNearby({ contextId, lat: 35.68, lon: 139.76, radiusM: 500 });
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`lat`/`lon` must be JSON **numbers** — argument coercion does not recurse
|
|
358
|
+
into `details`, so `"35.68"` is rejected server-side with HTTP 422.
|
|
359
|
+
`recallNearby()` returns a typed `RecallNearbyResponse`
|
|
360
|
+
(`results[].distance_m`); `MemoryLocation` and `NearbyMemory` are exported
|
|
361
|
+
too. Out-of-range coordinates throw locally rather than round-tripping.
|
|
362
|
+
|
|
363
|
+
> **Gotcha:** `updateMemory()` replaces `details` **wholesale** — the
|
|
364
|
+
> server does not deep-merge. Round-trip `location` when updating details
|
|
365
|
+
> or the memory silently drops off the spatial axis.
|
|
366
|
+
|
|
367
|
+
## Relationship to the Python SDK
|
|
368
|
+
|
|
369
|
+
This package ports the Python SDK's core (client, auth, REST clients,
|
|
370
|
+
models). Of the `kagura` CLI only the `auth` subcommands are provided
|
|
371
|
+
(`npx kagura-memory auth …`, above); the memory, context, and ingestion
|
|
372
|
+
commands are not ported, nor are the document-ingestion pipeline
|
|
373
|
+
(`FileIngestor`) and the zero-knowledge secrets client.
|
|
374
|
+
(`KaguraAgent` was removed from the Python SDK in v0.37.0 — the actor
|
|
375
|
+
role lives in the [kagura-agent](https://pypi.org/project/kagura-agent/)
|
|
376
|
+
package, so it will not be ported here.) Use the Python SDK for those;
|
|
377
|
+
both SDKs share the same credential files and server APIs. See
|
|
378
|
+
[`docs/design/2026-07-05-typescript-port-design.md`](docs/design/2026-07-05-typescript-port-design.md)
|
|
379
|
+
for the scope decisions.
|
|
380
|
+
|
|
381
|
+
## Development
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
npm install
|
|
385
|
+
npm test # vitest
|
|
386
|
+
npm run typecheck # tsc --noEmit
|
|
387
|
+
npm run build # tsup → dist/ (ESM + CJS + d.ts)
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
MIT
|