kagura-memory 0.1.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 -0
- package/README.md +119 -0
- package/dist/index.cjs +2959 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2234 -0
- package/dist/index.d.ts +2234 -0
- package/dist/index.js +2896 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install kagura-memory
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Node.js >= 18 (native `fetch`). Zero runtime dependencies.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { KaguraClient } from "kagura-memory";
|
|
28
|
+
|
|
29
|
+
// Credentials resolve automatically: explicit apiKey > KAGURA_API_KEY env
|
|
30
|
+
// > OAuth profile (~/.kagura/credentials.json, shared with the Python CLI)
|
|
31
|
+
// > .kagura.json
|
|
32
|
+
const client = new KaguraClient();
|
|
33
|
+
|
|
34
|
+
// Store a memory
|
|
35
|
+
const stored = await client.remember({
|
|
36
|
+
contextId: "your-context-id",
|
|
37
|
+
summary: "User prefers TypeScript strict mode",
|
|
38
|
+
content: "Enabled strict + noUncheckedIndexedAccess in all new projects.",
|
|
39
|
+
type: "note",
|
|
40
|
+
tags: ["typescript", "preferences"],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Search memories (hybrid semantic + keyword)
|
|
44
|
+
const hits = await client.recall({
|
|
45
|
+
contextId: "your-context-id",
|
|
46
|
+
query: "typescript preferences",
|
|
47
|
+
k: 5,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
for (const memory of hits.results as Array<Record<string, unknown>>) {
|
|
51
|
+
console.log(memory.summary);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await client.close();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Authentication
|
|
58
|
+
|
|
59
|
+
Three ways to authenticate, in resolution order:
|
|
60
|
+
|
|
61
|
+
1. **Explicit key** — `new KaguraClient({ apiKey: "kagura_..." })`
|
|
62
|
+
2. **Environment** — `KAGURA_API_KEY` (+ optional `KAGURA_MCP_URL`)
|
|
63
|
+
3. **OAuth profile** — `~/.kagura/credentials.json`, written by the Python
|
|
64
|
+
CLI's `kagura auth login`. Profiles (`KAGURA_PROFILE` env or
|
|
65
|
+
`{ profile: "name" }`) and auto-refresh work exactly like the Python SDK;
|
|
66
|
+
the credentials file is shared between both SDKs.
|
|
67
|
+
4. **Config file** — `.kagura.json` in the working directory or home:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"api_key": "kagura_your_api_key",
|
|
72
|
+
"mcp_url": "https://memory.kagura-ai.com/mcp"
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Error handling
|
|
77
|
+
|
|
78
|
+
All errors extend `KaguraError`:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { KaguraNotFoundError, KaguraRateLimitError } from "kagura-memory";
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await client.recall({ contextId, query: "..." });
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof KaguraNotFoundError) {
|
|
87
|
+
// context or memory missing
|
|
88
|
+
} else if (e instanceof KaguraRateLimitError) {
|
|
89
|
+
console.log(`retry after ${e.retryAfter}s`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Server-side domain errors (`{"status": "error", ...}`) are translated into
|
|
95
|
+
exceptions — `KaguraNotFoundError` for missing contexts/memories/reports,
|
|
96
|
+
`KaguraError` otherwise — so you never need to inspect `result.status`.
|
|
97
|
+
|
|
98
|
+
## Relationship to the Python SDK
|
|
99
|
+
|
|
100
|
+
This package ports the Python SDK's core (client, auth, REST clients,
|
|
101
|
+
models). Not yet ported: the `kagura` CLI, `KaguraAgent` (LLM-driven
|
|
102
|
+
memory), the document-ingestion pipeline (`FileIngestor`), and the
|
|
103
|
+
zero-knowledge secrets client. Use the Python SDK for those; both SDKs
|
|
104
|
+
share the same credential files and server APIs. See
|
|
105
|
+
[`docs/design/2026-07-05-typescript-port-design.md`](docs/design/2026-07-05-typescript-port-design.md)
|
|
106
|
+
for the scope decisions.
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm install
|
|
112
|
+
npm test # vitest
|
|
113
|
+
npm run typecheck # tsc --noEmit
|
|
114
|
+
npm run build # tsup → dist/ (ESM + CJS + d.ts)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|