korely-memory 0.1.17 → 0.2.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/dist/index.d.ts CHANGED
@@ -92,11 +92,18 @@ interface MemoryPage extends Iterable<Memory> {
92
92
  memories: Memory[];
93
93
  total: number;
94
94
  }
95
+ /**
96
+ * What `delete()` did to one memory. `facts_invalidated` counts the facts it
97
+ * ended; `facts_reopened` the facts that are true again: facts of other
98
+ * memories that this one's facts had closed, given back as new rows
99
+ * (undefined from a server older than Korely 1.0.2, which does not send it).
100
+ */
95
101
  interface DeleteReceipt {
96
102
  id?: string;
97
103
  status?: string;
98
104
  facts_invalidated?: number;
99
105
  audit_id?: string;
106
+ facts_reopened?: number;
100
107
  }
101
108
  /**
102
109
  * What `deleteAll` erased. Every row is physically deleted, and `erasure` is
@@ -155,7 +162,14 @@ interface Context {
155
162
  */
156
163
  interface BatchMemory {
157
164
  content: string;
165
+ /**
166
+ * Whose memory the item is: `user_id`, the end user it belongs to, or
167
+ * `agent_id`, the agent writing it. Korely 1.0.19 and later need one of the
168
+ * two in every item: an item with neither refuses the whole batch with a
169
+ * 422 (`code === "identity_required"`) naming `memories[i]`.
170
+ */
158
171
  user_id?: string;
172
+ /** The agent writing the item; see `user_id`. */
159
173
  agent_id?: string;
160
174
  run_id?: string;
161
175
  metadata?: Record<string, unknown>;
@@ -266,13 +280,18 @@ interface AgentDeleteReceipt {
266
280
  facts_deleted?: number;
267
281
  audit_id?: string;
268
282
  /**
269
- * Whether the agent cap slot is free now. The cap counts a name across the
270
- * account, so it stays taken (false) while another project of the account
271
- * still uses the same agent_id. Undefined when the server does not say: a
272
- * self-hosted install has no cap, and servers before 2026-09-28 did not send
273
- * it.
283
+ * @deprecated Always undefined: no Korely server sends this field, and none
284
+ * ever has. It stays in the type so that code reading it keeps compiling. To see
285
+ * whether a cap slot is free, read `cap` and `used` from `listAgents()`; the
286
+ * cap counts a name across the account, so the slot stays taken while
287
+ * another project of the account still uses the same agent_id.
274
288
  */
275
289
  slot_freed?: boolean;
290
+ /**
291
+ * The facts of other agents that the namespace's facts had closed, true
292
+ * again as new rows (undefined from a server older than Korely 1.0.2).
293
+ */
294
+ facts_reopened?: number;
276
295
  }
277
296
  /** What `ping()` answers: the key works. */
278
297
  interface PingResponse {
@@ -335,7 +354,9 @@ type AuditActor = "rest" | "mcp" | "dashboard" | "manage" | "worker" | string;
335
354
  * What happened, in an audit event. An open string for the same reason as
336
355
  * AuditActor; "tenant_create" is the Self-hosted's only.
337
356
  */
338
- type AuditAction = "read" | "write" | "fact_write" | "fact_invalidate" | "erase" | "key_create" | "key_revoke" | "tenant_create" | string;
357
+ type AuditAction = "read" | "write" | "fact_write" | "fact_invalidate"
358
+ /** A memory forgotten: out of every read, its text kept (Korely 1.0.23; filed as "erase" before). */
359
+ | "forget" | "erase" | "key_create" | "key_revoke" | "tenant_create" | string;
339
360
  /** For a read: what the call returned, by public id, at most 100 of each kind. Ids only, never content. */
340
361
  interface AuditRead {
341
362
  memories: string[];
@@ -357,6 +378,13 @@ interface AuditEvent {
357
378
  ip?: string | null;
358
379
  /** On a read, what it returned; with `known_as_of` on getFacts() or getContext() (Korely Agent 0.1.26) it rebuilds what an agent knew when it decided. */
359
380
  read?: AuditRead | null;
381
+ /**
382
+ * The key that made the call, by the id the dashboard's Keys page lists it
383
+ * with, never the key itself. Null for an act with no key (a person signed
384
+ * in to the dashboard, the command line, the worker); undefined from a
385
+ * server older than Korely 1.0.23.
386
+ */
387
+ api_key_id?: string | null;
360
388
  }
361
389
  /** Iterable page of the audit trail, newest first. `total` counts the matches across every page. */
362
390
  interface AuditPage extends Iterable<AuditEvent> {
@@ -364,7 +392,16 @@ interface AuditPage extends Iterable<AuditEvent> {
364
392
  total: number;
365
393
  }
366
394
  interface AddOptions {
395
+ /** The agent writing the memory; see `user_id`. */
367
396
  agent_id?: string;
397
+ /**
398
+ * Whose memory it is: `user_id`, the end user it belongs to, or `agent_id`,
399
+ * the agent writing it (or both: that agent's memory of that user). Korely
400
+ * 1.0.19 and later refuse a write with neither, and store nothing: a 422
401
+ * APIError with `code === "identity_required"` and the server's message.
402
+ * An older server accepts it. `run_id` alone is not an identity. Optional in
403
+ * the type so that a program talking to an older server still compiles.
404
+ */
368
405
  user_id?: string;
369
406
  run_id?: string;
370
407
  metadata?: Record<string, unknown>;
@@ -489,7 +526,12 @@ interface GetFactsOptions {
489
526
  exclude_sessions?: boolean;
490
527
  }
491
528
  interface AddFactTripleOptions {
529
+ /**
530
+ * Whose fact it is, as on `add()`: `user_id` or `agent_id`. Korely 1.0.19
531
+ * and later refuse a fact with neither (422, `code === "identity_required"`).
532
+ */
492
533
  user_id?: string;
534
+ /** The agent writing the fact; see `user_id`. */
493
535
  agent_id?: string;
494
536
  run_id?: string;
495
537
  subject_type?: string;
@@ -538,7 +580,7 @@ interface ForgetReceipt {
538
580
 
539
581
  /** Must equal `version` in package.json (a test checks). It goes out in the
540
582
  * X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
541
- declare const VERSION = "0.1.17";
583
+ declare const VERSION = "0.2.0";
542
584
  interface KorelyOptions {
543
585
  /** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
544
586
  apiKey?: string;
@@ -588,7 +630,7 @@ declare class Korely {
588
630
  * label of who signed up, kept for your reference. The answer carries the
589
631
  * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
590
632
  * The account it creates has no login: the key is the account, and
591
- * `deleteAccount({ confirm: true })` closes it.
633
+ * `deleteAccount({ confirm: "<the account's id>" })` closes it.
592
634
  *
593
635
  * Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
594
636
  * region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
@@ -610,15 +652,36 @@ declare class Korely {
610
652
  */
611
653
  ping(): Promise<PingResponse>;
612
654
  /**
613
- * DELETE /v1/account?confirm=true: delete the account of this key for good,
614
- * with every key, project, memory, fact and webhook of it; the key stops
615
- * working. Cloud only, for an account made by `Korely.initAgent()` or
616
- * `korely init --agent`, which nobody signs in to: the key is the account,
617
- * and this is how it is closed (GDPR Art. 17).
655
+ * DELETE /v1/account?confirm=<the account's id>: delete the account of this
656
+ * key for good, with every key, project, memory, fact and webhook of it; the
657
+ * key stops working. Cloud only, for an account made by `Korely.initAgent()`
658
+ * or `korely init --agent`, which nobody signs in to: the key is the
659
+ * account, and this is how it is closed (GDPR Art. 17).
660
+ *
661
+ * `confirm` is the account's id, typed by whoever means it, as the
662
+ * dashboard has the email typed: `tenant_id` of GET /admin/whoami, which the
663
+ * error below gives. So a key that leaked, or a script pointed at the wrong
664
+ * key, is not enough with a flag (Korely 1.0.23 asks the same of the
665
+ * server's route). Nothing is deleted, and the DELETE is not sent, unless
666
+ * `confirm` is a UUID equal, spaces trimmed, to the `tenant_id` that GET
667
+ * /admin/whoami gives this key: a missing, `true`, `"true"` or wrong
668
+ * `confirm` rejects with a KorelyError whose `code` is
669
+ * `confirmation_required` (the server's code for the same refusal) and
670
+ * whose message names the id to type when the key may read it. A key that
671
+ * may not read GET /admin/whoami (403, a key without the `admin` scope)
672
+ * deletes nothing: with no id typed it rejects with that same
673
+ * `confirmation_required`, whose message says whoami could not be read;
674
+ * with the id typed, with the server's refusal of the whoami,
675
+ * NamespaceForbiddenError (an APIError, `status` 403, `code` `forbidden`).
618
676
  *
619
- * `{ confirm: true }` is required, and checked here, before anything is
620
- * sent: without it, a KorelyError whose `code` is `confirmation_required`,
621
- * the code the server gives the same refusal.
677
+ * The account is deleted only on the server's answer that says so
678
+ * (`deleted: true`); any other answer, a redirect (never followed: the
679
+ * DELETE is not a GET) or a 2xx without it, rejects, and the account may
680
+ * still be there. A server older
681
+ * than 1.0.23 takes only `?confirm=true` and refuses the id (422): that
682
+ * rejects with an APIError whose `code` is `server_too_old`, nothing is
683
+ * deleted, and the client does not fall back to the flag. Upgrade the
684
+ * server, or use korely-memory 0.1.18.
622
685
  *
623
686
  * An account with a Korely login rejects with 409 `account_has_login`
624
687
  * (ConflictError): a key that ended up in a log must not be able to delete
@@ -627,8 +690,15 @@ declare class Korely {
627
690
  * dashboard. No audit event survives: the trail is part of what goes.
628
691
  */
629
692
  deleteAccount(opts?: {
630
- confirm?: boolean;
693
+ confirm?: string;
631
694
  }): Promise<AccountDeleteReceipt>;
695
+ /** The id of this key's account: `tenant_id` of GET /admin/whoami, checked
696
+ * as an account id (`accountId`). The errors of the call reject as they
697
+ * come. */
698
+ private accountOfThisKey;
699
+ /** The refusal of a deletion not confirmed, naming the id to type when this
700
+ * key may read it. */
701
+ private notConfirmed;
632
702
  /**
633
703
  * GET /v1/audit: what this key's project did, and what its agents read,
634
704
  * newest first (`ts` descending, then the event's id, so paging with
@@ -666,6 +736,11 @@ declare class Korely {
666
736
  * `content` is a string, or a list of chat messages (role/content), joined
667
737
  * into one block before sending. Pass `timestamp` (ISO date/datetime) for
668
738
  * backfill: facts extracted inherit it as `valid_from`.
739
+ *
740
+ * Say whose memory it is with `user_id` or `agent_id` (or both): Korely
741
+ * 1.0.19 and later refuse a write with neither, a 422 APIError with
742
+ * `code === "identity_required"`. This client sends the ids each call names
743
+ * and no others.
669
744
  */
670
745
  add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
671
746
  /**
@@ -702,7 +777,8 @@ declare class Korely {
702
777
  /**
703
778
  * DELETE /v1/memories/:id: forget one memory. It drops out of every default
704
779
  * read, and the facts only it asserted are invalidated (kept as history,
705
- * audited). For erasure use `deleteAll`.
780
+ * audited). The facts its facts had closed are true again: the receipt
781
+ * counts them in `facts_reopened`. For erasure use `deleteAll`.
706
782
  */
707
783
  delete(memoryId: string): Promise<DeleteReceipt>;
708
784
  /**
@@ -745,14 +821,16 @@ declare class Korely {
745
821
  * DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
746
822
  * memory + fact written under this agent_id in this key's project
747
823
  * (soft-forgetting its data does NOT free its cap slot; this does). Resolves
748
- * to the purge counts, an audit id and `slot_freed`.
824
+ * to the purge counts and an audit id. Its `slot_freed` is always
825
+ * undefined: no Korely server sends it, and none ever has. To see whether a
826
+ * cap slot is free, read `cap` and `used` from `listAgents()`.
749
827
  *
750
828
  * The namespace must be one `listAgents()` shows for this key: anything else
751
829
  * rejects with NotFoundError, including a name only another project of the
752
830
  * account uses (the server answered 200 with zero counts for it before
753
831
  * 2026-09-28, and freed nothing). The cap counts a name across the account,
754
832
  * so while another project still uses the same agent_id its rows stay and
755
- * `slot_freed` is false.
833
+ * the slot stays taken.
756
834
  */
757
835
  deleteAgent(agentId: string): Promise<AgentDeleteReceipt>;
758
836
  /**
@@ -768,7 +846,8 @@ declare class Korely {
768
846
  * skipping extraction. The server runs the contradiction check; the fact is
769
847
  * bi-temporal (pass `valid_from` for a historical fact, `tense: "past"` for
770
848
  * one that is over). Resolves to the written Fact, with `invalidated`
771
- * listing any fact ids it superseded.
849
+ * listing any fact ids it superseded. `user_id` or `agent_id` says whose
850
+ * fact it is, as on `add()` (Korely 1.0.19 and later refuse neither).
772
851
  */
773
852
  addFactTriple(subject: string, predicate: string, object: string, opts?: AddFactTripleOptions): Promise<Fact>;
774
853
  /**
@@ -837,7 +916,10 @@ declare class Korely {
837
916
  * POST /v1/batch: bulk import, up to 500 memory objects, processed
838
917
  * asynchronously. Each object is the body of one `add()` (see
839
918
  * `BatchMemory`): `content` and optionally `user_id`, `agent_id`, `run_id`,
840
- * `metadata` and `timestamp`.
919
+ * `metadata` and `timestamp`. On Korely 1.0.19 and later each object needs
920
+ * `user_id` or `agent_id`: one with neither refuses the whole batch before
921
+ * anything is queued, a 422 (`code === "identity_required"`) whose message
922
+ * names it, `memories[3].user_id or memories[3].agent_id is required`.
841
923
  *
842
924
  * `timestamp` means what it means on `add()`: when the events happened.
843
925
  * The facts extracted from the item inherit it as `valid_from`, so a
@@ -887,7 +969,9 @@ declare class KorelyError extends Error {
887
969
  * The server answered with a non-2xx status. `status` is the HTTP status,
888
970
  * `code` the stable error code (`invalid_key`, `not_found`, `quota_exceeded`,
889
971
  * `search_unavailable` and so on). Anything without a subclass below (422
890
- * validation, 503 unavailable, other 5xx) is a plain APIError.
972
+ * validation, 503 unavailable, other 5xx) is a plain APIError. A write that
973
+ * names neither `user_id` nor `agent_id` is a 422 with
974
+ * `code === "identity_required"` on Korely 1.0.19 and later.
891
975
  *
892
976
  * The subclasses were siblings of this class in 0.1.6 and earlier, so the pattern the
893
977
  * public docs teach, `err instanceof APIError` and branch on `err.code`, let a