kagura-memory 0.8.0 → 0.9.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/README.md +92 -26
- package/dist/cli.js +594 -56
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +607 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +916 -86
- package/dist/index.d.ts +916 -86
- package/dist/index.js +604 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,12 @@ the one optional peer dependency, for
|
|
|
29
29
|
[zero-knowledge secrets](#the-crypto-package-is-opt-in), is never installed
|
|
30
30
|
unless you ask for it.
|
|
31
31
|
|
|
32
|
+
Targets memory-cloud **v0.75.0** (`MIN_SERVER_VERSION`).
|
|
33
|
+
`checkServerVersion()` warns, and never throws, on an older server, which
|
|
34
|
+
still answers: it ignores options it predates, leaves out fields it
|
|
35
|
+
predates, and reports a tool it predates as not found. The method notes
|
|
36
|
+
below say which server version a feature needs.
|
|
37
|
+
|
|
32
38
|
## Quick Start
|
|
33
39
|
|
|
34
40
|
```ts
|
|
@@ -246,29 +252,84 @@ try {
|
|
|
246
252
|
```
|
|
247
253
|
|
|
248
254
|
Server-side domain errors (`{"status": "error", ...}`) are translated into
|
|
249
|
-
exceptions
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
exceptions, so you never need to inspect `result.status`. The class is
|
|
256
|
+
keyed on the error code and the envelope's fields, never on the message:
|
|
257
|
+
|
|
258
|
+
| Class | Raised for | Carries |
|
|
259
|
+
|-------|------------|---------|
|
|
260
|
+
| `KaguraNotFoundError` | missing contexts/memories/reports/agents/bindings (on `updateSearchConfig`, a missing context is a `KaguraPermissionError` instead) | — |
|
|
261
|
+
| `KaguraFeatureNotAvailableError` | MCP `plan_required` / `feature_not_available`; REST 403 `FEAT-001` — the plan lacks a feature, or it is switched off | `feature`, `requiredPlan`, `requiredPlanDisplay`, `currentPlan`, `gate` |
|
|
262
|
+
| `KaguraQuotaError` | MCP `quota_exceeded` / `CONNECTOR-001`; REST `QUOTA-001`, `QUOTA-002` and `CONNECTOR-001` (the resource-token and connector seat caps answer **403**); any other 429 from a REST client but `SecretClient` | `quotaType`, `current`, `limit`, `usedToday`, `resetsAt`, `retryAfter`, and the plan fields above |
|
|
263
|
+
| `KaguraPartialRollbackError` | `rollbackSleepRun` reversed some actions but not all | `reportId`, `summary` |
|
|
264
|
+
| `KaguraPermissionError` | MCP `permission_denied` — usually the caller's role is too low. `updateSearchConfig` also sends it for a context that does not exist or that the caller cannot see. Only some tools send a role — `updateSearchConfig`, `updateContext`, `deleteContext`, the file tools and the analysis tools do not — so `requiredRole` is often `null`, and on `updateSearchConfig` it cannot tell a missing context from a role denial | `requiredRole` |
|
|
265
|
+
| `KaguraError` | any other code | — |
|
|
266
|
+
|
|
267
|
+
memory-cloud v0.75.0+ tags every plan and quota refusal with a `gate`
|
|
268
|
+
(`plan`, `quota`, `allowlist` or `deployment`), and the SDK chooses the
|
|
269
|
+
class from it first, falling back to the code for older servers. The
|
|
270
|
+
payload fields are `null` whenever the server did not send them. Against a
|
|
271
|
+
server older than v0.75.0, `current` and `limit` are read from the legacy
|
|
272
|
+
names the refusal carries instead (`used_today` / `limit_today`,
|
|
273
|
+
`owned_count` / `cap`, `active_connectors` / `max_connectors`).
|
|
274
|
+
|
|
275
|
+
Show `requiredPlanDisplay` (`"XL"`) to a user and decide with
|
|
276
|
+
`requiredPlan`, as long as `gate` is set. With a `gate`, both are `null`
|
|
277
|
+
when no plan lifts the refusal, which is what an `allowlist` or
|
|
278
|
+
`deployment` gate means, and a `quota` gate is set on every typed cap,
|
|
279
|
+
including one no tier raises, so an upgrade helps only when `requiredPlan`
|
|
280
|
+
is non-null. With no `gate`, a `null` `requiredPlan` means the plan is
|
|
281
|
+
unknown, not that no plan lifts it. That covers an older server, and
|
|
282
|
+
`createContext`'s own context-limit check, which reads `listContexts()`
|
|
283
|
+
and so fills in only `quotaType`, `current` and `limit`.
|
|
284
|
+
|
|
285
|
+
`retryAfter` is the `Retry-After` header, else the retry hint in the body
|
|
286
|
+
(REST `details.retry_after`, MCP `retry_after_seconds`, which is all the
|
|
287
|
+
resource events-per-hour quota sends), else it is derived from `resetsAt`
|
|
288
|
+
on a time-windowed quota such as `memories_per_day`. It is `null` on a
|
|
289
|
+
fixed cap that waiting will not lift.
|
|
290
|
+
|
|
291
|
+
An HTTP 429 keeps the class it always had on two surfaces.
|
|
292
|
+
`KaguraClient`'s own transport raises `KaguraRateLimitError` for the
|
|
293
|
+
per-minute rate limit and the daily call quota alike; from v0.75.0 the
|
|
294
|
+
quota also sets the `KaguraQuotaError` fields on it (`quotaType` is
|
|
295
|
+
`api_mcp_daily` or `api_rest_daily`), and they stay `null` on a
|
|
296
|
+
per-minute limit. `SecretClient` renders a 429 as `KaguraConnectionError`.
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import { KaguraFeatureNotAvailableError, KaguraQuotaError } from "kagura-memory";
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
await client.setupResource({ resourceId: "crm" });
|
|
303
|
+
} catch (e) {
|
|
304
|
+
if (e instanceof KaguraFeatureNotAvailableError) {
|
|
305
|
+
// null when no plan lifts it (allowlist / deployment gate) or, with no gate, unknown.
|
|
306
|
+
console.log(e.requiredPlanDisplay ? `upgrade to ${e.requiredPlanDisplay}` : e.message);
|
|
307
|
+
} else if (e instanceof KaguraQuotaError) {
|
|
308
|
+
console.log(`${e.quotaType}: ${e.current}/${e.limit}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
252
312
|
|
|
253
313
|
## `KaguraClient` method reference
|
|
254
314
|
|
|
255
315
|
Methods return the parsed server response. Most take a single camelCase
|
|
256
|
-
options object
|
|
257
|
-
`
|
|
258
|
-
(`
|
|
259
|
-
`
|
|
260
|
-
`getToolDefinitions`, `close`) take no arguments.
|
|
261
|
-
snake_case; optional fields are omitted from the request
|
|
316
|
+
options object (optional for `listContexts` and `listMemories`);
|
|
317
|
+
`getAgent`, `deleteAgent`, `listAgentBindings` and `deleteContext` take
|
|
318
|
+
the id directly, and the workspace-wide calls (`listAgents`, `getUsage`,
|
|
319
|
+
`getServerInfo`, `checkServerVersion`, `getEmbeddingStatus`,
|
|
320
|
+
`listEmbeddingModels`, `getToolDefinitions`, `close`) take no arguments.
|
|
321
|
+
The wire stays snake_case; optional fields are omitted from the request
|
|
322
|
+
when `undefined`.
|
|
262
323
|
|
|
263
324
|
### Memories
|
|
264
325
|
|
|
265
326
|
| Method | What it does |
|
|
266
327
|
|--------|--------------|
|
|
267
|
-
| `remember` | Store a memory. `details` accepts arbitrary JSON
|
|
268
|
-
| `recall` | Hybrid semantic + keyword search. Takes `filters` (`type`, `
|
|
328
|
+
| `remember` | Store a memory. `details` accepts arbitrary JSON, including `location` (see below) and the reserved `tool_trigger`, which marks a tool guardrail and needs context editor or above on a user (not agent) credential; `supersedes` declares this the newer version of an existing memory, shadowing the old one from default recall without destroying it; `deliveryMode: "always"` pins it. |
|
|
329
|
+
| `recall` | Hybrid semantic + keyword search. Takes `filters` (`type`, `scope`, `tags` with `tags_match` and `tags_normalize`, `importance` bounds, created/updated date bounds, `source_uri_prefix`, `source_type`, `trust_tier`, and the `near` / `within` geo filters), `searchMode`, `useRerank`, `includeExploreHints`, `includeSuperseded` (read back what `supersedes` shadowed, annotated with `superseded_by`), and `contextIds` for 2–20-context search. `useRerank` is tri-state (memory-cloud v0.69.0+): omit it to follow the context's search config (the first context's, with `contextIds`), `true` requests reranking where the context allows it, `false` skips it for the call. A tag filter that matches nothing can return `tag_suggestions`. When the semantic half is unavailable, the result is keyword-only and carries `degraded: true` and `degraded_reason` (v0.66.0+) — an empty one then means "search impaired", not "nothing stored". |
|
|
269
330
|
| `reference` | Full detail for one memory, under `result.memory`. |
|
|
270
|
-
| `updateMemory` | Update in place by `memoryId`, or upsert by `externalId`. `details` **replaces** the stored object wholesale — round-trip keys you want to keep. |
|
|
271
|
-
| `forget` | Soft-delete
|
|
331
|
+
| `updateMemory` | Update in place by `memoryId`, or upsert by `externalId`. `details` **replaces** the stored object wholesale — round-trip keys you want to keep; dropping `tool_trigger` turns a guardrail off. `dismissSupersedeCandidate: true` rejects the server's `supersede_candidate` suggestion; it needs `memoryId` and throws locally with `externalId`. |
|
|
332
|
+
| `forget` | Soft-delete by `memoryId` or by `query`. The rows are kept, but not restorable through the API, until the deployment's cleanup window passes (`CLEANUP_DELETED_MEMORIES_RETENTION_DAYS`, default 30 days). For a caller who may write to the workspace, a target it may not delete, or one already gone, is skipped silently — including every guardrail for a caller below context editor or on an agent credential — so `deleted_count` can be 0. A workspace viewer may not delete at all and is refused with `KaguraPermissionError` (`requiredRole: "member"`). |
|
|
272
333
|
| `listMemories` | Browse with substring, facet, and time-window filters. Omit `contextId` for the caller's cross-context view. |
|
|
273
334
|
|
|
274
335
|
### Deterministic lanes
|
|
@@ -279,7 +340,8 @@ the counterpart to `recall`'s probabilistic search.
|
|
|
279
340
|
| Method | Axis |
|
|
280
341
|
|--------|------|
|
|
281
342
|
| `loadPinned` | The complete, unranked `deliveryMode: "always"` set. Bounded: check `truncated` / `total_available` rather than assuming you got everything. |
|
|
282
|
-
| `
|
|
343
|
+
| `loadGuardrails` | The set a client-side tool hook matches against (server v0.74.0+): the pinned set plus every memory carrying `details.tool_trigger`, in two separately capped lanes — `cap` bounds only the tool-triggered one, so pins never crowd guardrails out. Check `tool_triggered_truncated` / `pinned_truncated`. |
|
|
344
|
+
| `recallUpcoming` | WHEN — `type: "time"` memories whose window overlaps `from`/`until`, soonest first. Items carry `trigger`, not `details` (server v0.73.0+); `includeDetails: true` returns the full `details` object instead. |
|
|
283
345
|
| `recallNearby` | WHERE — memories near a point, nearest first with `distance_m`. See [the WHERE axis](#the-where-axis--geospatial-memories). |
|
|
284
346
|
|
|
285
347
|
### Tags and the neural graph
|
|
@@ -297,14 +359,14 @@ the counterpart to `recall`'s probabilistic search.
|
|
|
297
359
|
|
|
298
360
|
| Method | What it does |
|
|
299
361
|
|--------|--------------|
|
|
300
|
-
| `listContexts` |
|
|
301
|
-
| `createContext` | New context. Throws `KaguraQuotaError` when the workspace limit is reached. `embeddingModel`
|
|
302
|
-
| `getContextInfo` | Metadata plus, by default, a memory-count breakdown. |
|
|
303
|
-
| `updateContext` | Change display name, summary, usage guide, visibility, lock. |
|
|
362
|
+
| `listContexts` | The contexts you can see, most recently used first, as a slim name→id directory (`id`, `name`, `is_private`, `is_locked`, `last_used_at`; server v0.73.0+). `nameContains` filters (server v0.73.0+; older servers ignore it and return every context); `includeSummary` (capped at 300 chars), `includeDetails` (full `summary` + `embedding_model`) and `includeStats` (`memory_count`) add fields. `count` is quota usage and `total` the number returned; `can_create` is the quota flag, and `hint` appears when you can see no context. |
|
|
363
|
+
| `createContext` | New context. Throws `KaguraQuotaError` when the workspace limit is reached: the SDK checks `listContexts()` first, so that error carries `quotaType`, `current` and `limit` but no `gate` or plan fields (`requiredPlan` `null` means unknown). Also throws `KaguraFeatureNotAvailableError` for a shared one (`isPrivate: false`) on a plan without shared contexts (server v0.75.0+). `embeddingModel` cannot be changed through the API afterwards (an operator can migrate it server-side, v0.66.0+). |
|
|
364
|
+
| `getContextInfo` | Metadata plus, by default, a memory-count breakdown. On server v0.74.0+ also a trimmed `guardrails` block: absent when the MCP URL carries `?guardrails=off`, `null` when the server's read failed. |
|
|
365
|
+
| `updateContext` | Change display name, summary, usage guide, visibility, lock. `isPublic: true` is plan-gated and throws `KaguraFeatureNotAvailableError` on a plan without public contexts. |
|
|
304
366
|
| `deleteContext` | Delete by id. Locked contexts are refused. |
|
|
305
367
|
| `mergeContexts` | Move memories between contexts. Both must share an embedding model and workspace. |
|
|
306
|
-
| `updateSearchConfig` | Hybrid-search weights (must sum to 1.0 ±0.01). Owner/editor only. |
|
|
307
|
-
| `setupResource` | Context + resource entity + ingestion token in one transaction. The returned token is plaintext and shown once. |
|
|
368
|
+
| `updateSearchConfig` | Hybrid-search weights (must sum to 1.0 ±0.01), reranking (`useRerank`, which a `recall` that omits it follows) and the reranker (`voyage`, `cohere` or `self_hosted`), reinforce re-rank (`reinforceEnabled`, `reinforceMaxBoost`, `reinforceRequireHostArbitration`) and query routing (`routingMode`). Owner/editor only; a context that does not exist, or that the caller cannot see, also throws `KaguraPermissionError`. Returns the whole updated `config`, the only place the reinforce and routing fields come back. |
|
|
369
|
+
| `setupResource` | Context + resource entity + ingestion token in one transaction. The returned token is plaintext and shown once. Plan-gated: throws `KaguraFeatureNotAvailableError` on a plan without resources. |
|
|
308
370
|
|
|
309
371
|
### Agent run-state
|
|
310
372
|
|
|
@@ -320,15 +382,15 @@ Ephemeral, TTL-bounded, and excluded from recall — deliberately not memories.
|
|
|
320
382
|
|--------|--------------|
|
|
321
383
|
| `getSleepHistory` | Recent runs, newest first. |
|
|
322
384
|
| `getSleepReport` | One run in detail, including the per-action audit log. |
|
|
323
|
-
| `rollbackSleepRun` | Reverse a completed run. The server commits per step, so a partial rollback is possible
|
|
385
|
+
| `rollbackSleepRun` | Reverse a completed or degraded run. The server commits per step, so a partial rollback is possible: it throws `KaguraPartialRollbackError` instead of returning, and the steps it did reverse stay reversed. There is no retry: the report is now `failed`, and the server will not roll back a `failed` report again. `err.summary` has the same counts a clean run returns, and the actions in `err.summary.errors` were not reversed and need handling some other way. |
|
|
324
386
|
|
|
325
387
|
### Workspace and server
|
|
326
388
|
|
|
327
389
|
| Method | What it does |
|
|
328
390
|
|--------|--------------|
|
|
329
|
-
| `getServerInfo` | Version and
|
|
330
|
-
| `checkServerVersion` | Compare against `MIN_SERVER_VERSION
|
|
331
|
-
| `getUsage` | Workspace quota and usage. |
|
|
391
|
+
| `getServerInfo` | Version, deployment feature flags, and (v0.69.0+) the reranker defaults new contexts start with, under `search_defaults`. |
|
|
392
|
+
| `checkServerVersion` | Compare against `MIN_SERVER_VERSION` (0.75.0). Advisory: logs, never throws. |
|
|
393
|
+
| `getUsage` | Workspace quota and usage: `used` / `limit` for memories, contexts, members and today's MCP calls. |
|
|
332
394
|
| `getMemoryStats` | Per-memory usage stats, sortable and paged. |
|
|
333
395
|
| `getEmbeddingStatus` / `listEmbeddingModels` | Embedding backend state and the models available for `createContext`. |
|
|
334
396
|
| `getToolDefinitions` | Raw MCP `tools/list` output — every tool the server exposes, including any this SDK does not wrap yet. |
|
|
@@ -363,6 +425,10 @@ const bootstrap = await client.getAgentBootstrap({
|
|
|
363
425
|
if (bootstrap.degraded) {
|
|
364
426
|
// some component failed fail-soft; inspect bootstrap.components
|
|
365
427
|
}
|
|
428
|
+
if (bootstrap.components?.recall?.degraded) {
|
|
429
|
+
// the recall ran keyword-only (degraded_reason says why); this also sets
|
|
430
|
+
// the top-level flag above, since server v0.66.0
|
|
431
|
+
}
|
|
366
432
|
```
|
|
367
433
|
|
|
368
434
|
Deployed agents holding only an API key (e.g. an agent-bound member key)
|
|
@@ -376,8 +442,8 @@ const bootstrap = await agents.bootstrap({ agentId: "agent-uuid" });
|
|
|
376
442
|
```
|
|
377
443
|
|
|
378
444
|
Requires memory-cloud **v0.49.0+** — older servers return MCP "tool not
|
|
379
|
-
found" / REST 404 on this surface
|
|
380
|
-
|
|
445
|
+
found" / REST 404 on this surface. The SDK as a whole targets v0.75.0
|
|
446
|
+
(see [Installation](#installation)).
|
|
381
447
|
|
|
382
448
|
## The WHERE axis — geospatial memories
|
|
383
449
|
|