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/README.md +19 -10
- package/dist/chunk-VT7GXOPS.js +1131 -0
- package/dist/index.cjs +158 -29
- package/dist/index.d.cts +107 -23
- package/dist/index.d.ts +107 -23
- package/dist/index.js +13 -983
- package/dist/index.node.cjs +1185 -0
- package/dist/index.node.js +34 -0
- package/package.json +10 -2
package/dist/index.cjs
CHANGED
|
@@ -126,7 +126,7 @@ function unknownOption(method, opts, known) {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// src/client.ts
|
|
129
|
-
var VERSION = "0.
|
|
129
|
+
var VERSION = "0.2.0";
|
|
130
130
|
var REGIONS = { eu: "https://api.korely.ai" };
|
|
131
131
|
var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch", "client");
|
|
132
132
|
var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
|
|
@@ -198,6 +198,12 @@ function checkOptions(method, opts, known) {
|
|
|
198
198
|
const problem = unknownOption(method, opts, known);
|
|
199
199
|
if (problem) throw new KorelyError(problem);
|
|
200
200
|
}
|
|
201
|
+
var ACCOUNT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
202
|
+
function accountId(value) {
|
|
203
|
+
if (typeof value !== "string") return void 0;
|
|
204
|
+
const text2 = value.trim();
|
|
205
|
+
return ACCOUNT_ID.test(text2) ? text2 : void 0;
|
|
206
|
+
}
|
|
201
207
|
function coerceContent(content) {
|
|
202
208
|
if (typeof content === "string") return content;
|
|
203
209
|
if (Array.isArray(content)) {
|
|
@@ -367,7 +373,12 @@ async function exchange(t, method, path, opts = {}) {
|
|
|
367
373
|
method,
|
|
368
374
|
headers,
|
|
369
375
|
body,
|
|
370
|
-
signal: controller.signal
|
|
376
|
+
signal: controller.signal,
|
|
377
|
+
// Only a GET follows a redirect. `fetch` follows a POST answered 301,
|
|
378
|
+
// 302 or 303 as a GET with no body, and that GET's answer came back
|
|
379
|
+
// as the POST's; any other call takes the 3xx as its answer (Node
|
|
380
|
+
// gives it whole, a browser as an "opaqueredirect" of status 0).
|
|
381
|
+
redirect: method === "GET" ? "follow" : "manual"
|
|
371
382
|
});
|
|
372
383
|
} catch (e) {
|
|
373
384
|
throw failed(e);
|
|
@@ -395,12 +406,36 @@ async function exchange(t, method, path, opts = {}) {
|
|
|
395
406
|
}
|
|
396
407
|
}
|
|
397
408
|
if (!resp.ok) {
|
|
398
|
-
raiseFor(resp.status, parsed, resp.headers.get("retry-after"));
|
|
409
|
+
raiseFor(resp.status, parsed, resp.headers.get("retry-after"), redirectOf(resp, url), method);
|
|
399
410
|
}
|
|
400
411
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
401
412
|
}
|
|
402
|
-
function
|
|
403
|
-
|
|
413
|
+
function originOf(address, base) {
|
|
414
|
+
try {
|
|
415
|
+
return new URL(address, base).origin;
|
|
416
|
+
} catch {
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
function redirectOf(resp, url) {
|
|
421
|
+
const location = resp.headers.get("location");
|
|
422
|
+
if (resp.status >= 300 && resp.status < 400 && location) return originOf(location, url);
|
|
423
|
+
if (resp.redirected && resp.url) {
|
|
424
|
+
const at = originOf(resp.url);
|
|
425
|
+
if (at && at !== originOf(url)) return at;
|
|
426
|
+
}
|
|
427
|
+
return void 0;
|
|
428
|
+
}
|
|
429
|
+
function raiseFor(status, body, retryAfter, redirect, method) {
|
|
430
|
+
let { code, message: msg } = errorFields(status, body);
|
|
431
|
+
if (status === 401 && redirect) {
|
|
432
|
+
msg += ` The call was redirected to ${redirect}, and fetch does not send the key to another origin: if that is the server, use that address as baseUrl.`;
|
|
433
|
+
}
|
|
434
|
+
if (status >= 300 && status < 400 || status === 0) {
|
|
435
|
+
const answered = status ? `The server answered ${status} to a ${method ?? "call"}, a redirect` : `The server answered a ${method ?? "call"} with a redirect`;
|
|
436
|
+
const to = redirect ? ` to ${redirect}` : "";
|
|
437
|
+
msg = method === "GET" ? `${answered}${to} that fetch did not follow: that is not the answer to the call.` : `${answered}${to} this client does not follow: a call that is not a GET is never redirected, so that is not its answer, and nothing says it was done.`;
|
|
438
|
+
}
|
|
404
439
|
const opts = {
|
|
405
440
|
status,
|
|
406
441
|
code,
|
|
@@ -420,22 +455,28 @@ function raiseFor(status, body, retryAfter) {
|
|
|
420
455
|
}
|
|
421
456
|
throw new APIError(msg, opts);
|
|
422
457
|
}
|
|
458
|
+
var nodeFiles;
|
|
423
459
|
function savedConfig() {
|
|
424
460
|
try {
|
|
425
461
|
const proc = typeof process !== "undefined" ? process : void 0;
|
|
426
462
|
if (!proc?.versions?.node) return {};
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
const
|
|
431
|
-
if (!fs || !os || !path) return {};
|
|
432
|
-
const home = proc.env?.KORELY_CONFIG_HOME || path.join(os.homedir(), ".korely");
|
|
433
|
-
const data = JSON.parse(fs.readFileSync(path.join(home, "config.json"), "utf8"));
|
|
463
|
+
const files = nodeFiles ?? lookedUp(proc);
|
|
464
|
+
if (!files) return {};
|
|
465
|
+
const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
|
|
466
|
+
const data = JSON.parse(files.readFileSync(files.join(home, "config.json"), "utf8"));
|
|
434
467
|
return data && typeof data === "object" ? data : {};
|
|
435
468
|
} catch {
|
|
436
469
|
return {};
|
|
437
470
|
}
|
|
438
471
|
}
|
|
472
|
+
function lookedUp(proc) {
|
|
473
|
+
const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof require === "function" ? require(id) : void 0;
|
|
474
|
+
const fs = builtin("node:fs");
|
|
475
|
+
const os = builtin("node:os");
|
|
476
|
+
const path = builtin("node:path");
|
|
477
|
+
if (!fs || !os || !path) return void 0;
|
|
478
|
+
return { readFileSync: fs.readFileSync, homedir: os.homedir, join: path.join };
|
|
479
|
+
}
|
|
439
480
|
function text(v) {
|
|
440
481
|
return typeof v === "string" && v ? v : void 0;
|
|
441
482
|
}
|
|
@@ -474,7 +515,7 @@ var Korely = class {
|
|
|
474
515
|
* label of who signed up, kept for your reference. The answer carries the
|
|
475
516
|
* key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
|
|
476
517
|
* The account it creates has no login: the key is the account, and
|
|
477
|
-
* `deleteAccount({ confirm:
|
|
518
|
+
* `deleteAccount({ confirm: "<the account's id>" })` closes it.
|
|
478
519
|
*
|
|
479
520
|
* Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
|
|
480
521
|
* region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
|
|
@@ -540,15 +581,36 @@ var Korely = class {
|
|
|
540
581
|
return this.request("GET", "/v1/ping");
|
|
541
582
|
}
|
|
542
583
|
/**
|
|
543
|
-
* DELETE /v1/account?confirm
|
|
544
|
-
* with every key, project, memory, fact and webhook of it; the
|
|
545
|
-
* working. Cloud only, for an account made by `Korely.initAgent()`
|
|
546
|
-
* `korely init --agent`, which nobody signs in to: the key is the
|
|
547
|
-
* and this is how it is closed (GDPR Art. 17).
|
|
584
|
+
* DELETE /v1/account?confirm=<the account's id>: delete the account of this
|
|
585
|
+
* key for good, with every key, project, memory, fact and webhook of it; the
|
|
586
|
+
* key stops working. Cloud only, for an account made by `Korely.initAgent()`
|
|
587
|
+
* or `korely init --agent`, which nobody signs in to: the key is the
|
|
588
|
+
* account, and this is how it is closed (GDPR Art. 17).
|
|
589
|
+
*
|
|
590
|
+
* `confirm` is the account's id, typed by whoever means it, as the
|
|
591
|
+
* dashboard has the email typed: `tenant_id` of GET /admin/whoami, which the
|
|
592
|
+
* error below gives. So a key that leaked, or a script pointed at the wrong
|
|
593
|
+
* key, is not enough with a flag (Korely 1.0.23 asks the same of the
|
|
594
|
+
* server's route). Nothing is deleted, and the DELETE is not sent, unless
|
|
595
|
+
* `confirm` is a UUID equal, spaces trimmed, to the `tenant_id` that GET
|
|
596
|
+
* /admin/whoami gives this key: a missing, `true`, `"true"` or wrong
|
|
597
|
+
* `confirm` rejects with a KorelyError whose `code` is
|
|
598
|
+
* `confirmation_required` (the server's code for the same refusal) and
|
|
599
|
+
* whose message names the id to type when the key may read it. A key that
|
|
600
|
+
* may not read GET /admin/whoami (403, a key without the `admin` scope)
|
|
601
|
+
* deletes nothing: with no id typed it rejects with that same
|
|
602
|
+
* `confirmation_required`, whose message says whoami could not be read;
|
|
603
|
+
* with the id typed, with the server's refusal of the whoami,
|
|
604
|
+
* NamespaceForbiddenError (an APIError, `status` 403, `code` `forbidden`).
|
|
548
605
|
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
606
|
+
* The account is deleted only on the server's answer that says so
|
|
607
|
+
* (`deleted: true`); any other answer, a redirect (never followed: the
|
|
608
|
+
* DELETE is not a GET) or a 2xx without it, rejects, and the account may
|
|
609
|
+
* still be there. A server older
|
|
610
|
+
* than 1.0.23 takes only `?confirm=true` and refuses the id (422): that
|
|
611
|
+
* rejects with an APIError whose `code` is `server_too_old`, nothing is
|
|
612
|
+
* deleted, and the client does not fall back to the flag. Upgrade the
|
|
613
|
+
* server, or use korely-memory 0.1.18.
|
|
552
614
|
*
|
|
553
615
|
* An account with a Korely login rejects with 409 `account_has_login`
|
|
554
616
|
* (ConflictError): a key that ended up in a log must not be able to delete
|
|
@@ -558,13 +620,68 @@ var Korely = class {
|
|
|
558
620
|
*/
|
|
559
621
|
async deleteAccount(opts = {}) {
|
|
560
622
|
checkOptions("deleteAccount", opts, ["confirm"]);
|
|
561
|
-
|
|
623
|
+
const typed = accountId(opts?.confirm);
|
|
624
|
+
if (typed === void 0) {
|
|
625
|
+
throw await this.notConfirmed(
|
|
626
|
+
"This deletes the account of this key for good, every key, project, memory and fact of it, and its id, typed, is the confirmation: a flag is not enough."
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
const account = await this.accountOfThisKey();
|
|
630
|
+
if (typed !== account) {
|
|
562
631
|
throw new KorelyError(
|
|
563
|
-
|
|
632
|
+
`The account of this key is ${account}, and the confirmation names ${typed}: nothing was deleted. To delete account ${account}, pass { confirm: "${account}" }.`,
|
|
564
633
|
{ code: "confirmation_required" }
|
|
565
634
|
);
|
|
566
635
|
}
|
|
567
|
-
|
|
636
|
+
let body;
|
|
637
|
+
try {
|
|
638
|
+
body = await this.request("DELETE", "/v1/account", { params: { confirm: account } });
|
|
639
|
+
} catch (e) {
|
|
640
|
+
if (e instanceof APIError && e.status === 422) {
|
|
641
|
+
throw new APIError(
|
|
642
|
+
"This server is older than Korely 1.0.23: it deletes an account with ?confirm=true, and this client confirms with the account's id and does not fall back to the flag. Nothing was deleted. Upgrade the server to 1.0.23 or later, or delete the account with korely-memory 0.1.18 (npm install korely-memory@0.1.18).",
|
|
643
|
+
{ status: 422, code: "server_too_old" }
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
throw e;
|
|
647
|
+
}
|
|
648
|
+
if (body?.deleted !== true) {
|
|
649
|
+
throw new KorelyError(
|
|
650
|
+
"DELETE /v1/account answered without `deleted: true`, the answer that says the account is gone: it is not counted as deleted, and it may still be there (GET /admin/whoami answers with this key while it is)."
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
return body;
|
|
654
|
+
}
|
|
655
|
+
/** The id of this key's account: `tenant_id` of GET /admin/whoami, checked
|
|
656
|
+
* as an account id (`accountId`). The errors of the call reject as they
|
|
657
|
+
* come. */
|
|
658
|
+
async accountOfThisKey() {
|
|
659
|
+
const who = await this.request("GET", "/admin/whoami");
|
|
660
|
+
const account = accountId(who?.tenant_id);
|
|
661
|
+
if (account === void 0) {
|
|
662
|
+
throw new KorelyError(
|
|
663
|
+
"GET /admin/whoami gave no account id (a UUID) for this key: nothing was deleted.",
|
|
664
|
+
{ code: "confirmation_required" }
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
return account;
|
|
668
|
+
}
|
|
669
|
+
/** The refusal of a deletion not confirmed, naming the id to type when this
|
|
670
|
+
* key may read it. */
|
|
671
|
+
async notConfirmed(why) {
|
|
672
|
+
let account;
|
|
673
|
+
try {
|
|
674
|
+
account = await this.accountOfThisKey();
|
|
675
|
+
} catch (e) {
|
|
676
|
+
return new KorelyError(
|
|
677
|
+
`${why} Nothing was deleted. The id is tenant_id in GET /admin/whoami, which this key could not read: ${e?.message ?? String(e)}`,
|
|
678
|
+
{ code: "confirmation_required" }
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
return new KorelyError(
|
|
682
|
+
`${why} Nothing was deleted. To delete account ${account}, pass { confirm: "${account}" }.`,
|
|
683
|
+
{ code: "confirmation_required" }
|
|
684
|
+
);
|
|
568
685
|
}
|
|
569
686
|
// ── audit ─────────────────────────────────────────────────────────────────
|
|
570
687
|
/**
|
|
@@ -638,6 +755,11 @@ var Korely = class {
|
|
|
638
755
|
* `content` is a string, or a list of chat messages (role/content), joined
|
|
639
756
|
* into one block before sending. Pass `timestamp` (ISO date/datetime) for
|
|
640
757
|
* backfill: facts extracted inherit it as `valid_from`.
|
|
758
|
+
*
|
|
759
|
+
* Say whose memory it is with `user_id` or `agent_id` (or both): Korely
|
|
760
|
+
* 1.0.19 and later refuse a write with neither, a 422 APIError with
|
|
761
|
+
* `code === "identity_required"`. This client sends the ids each call names
|
|
762
|
+
* and no others.
|
|
641
763
|
*/
|
|
642
764
|
async add(content, opts = {}) {
|
|
643
765
|
checkOptions("add", opts, ADD_KEYS);
|
|
@@ -744,7 +866,8 @@ var Korely = class {
|
|
|
744
866
|
/**
|
|
745
867
|
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
746
868
|
* read, and the facts only it asserted are invalidated (kept as history,
|
|
747
|
-
* audited).
|
|
869
|
+
* audited). The facts its facts had closed are true again: the receipt
|
|
870
|
+
* counts them in `facts_reopened`. For erasure use `deleteAll`.
|
|
748
871
|
*/
|
|
749
872
|
async delete(memoryId) {
|
|
750
873
|
return this.request("DELETE", `/v1/memories/${seg(memoryId, "memoryId")}`);
|
|
@@ -823,14 +946,16 @@ var Korely = class {
|
|
|
823
946
|
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
824
947
|
* memory + fact written under this agent_id in this key's project
|
|
825
948
|
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
826
|
-
* to the purge counts
|
|
949
|
+
* to the purge counts and an audit id. Its `slot_freed` is always
|
|
950
|
+
* undefined: no Korely server sends it, and none ever has. To see whether a
|
|
951
|
+
* cap slot is free, read `cap` and `used` from `listAgents()`.
|
|
827
952
|
*
|
|
828
953
|
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
829
954
|
* rejects with NotFoundError, including a name only another project of the
|
|
830
955
|
* account uses (the server answered 200 with zero counts for it before
|
|
831
956
|
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
832
957
|
* so while another project still uses the same agent_id its rows stay and
|
|
833
|
-
*
|
|
958
|
+
* the slot stays taken.
|
|
834
959
|
*/
|
|
835
960
|
async deleteAgent(agentId) {
|
|
836
961
|
return this.request("DELETE", `/v1/agents/${seg(agentId, "agentId")}`);
|
|
@@ -872,7 +997,8 @@ var Korely = class {
|
|
|
872
997
|
* skipping extraction. The server runs the contradiction check; the fact is
|
|
873
998
|
* bi-temporal (pass `valid_from` for a historical fact, `tense: "past"` for
|
|
874
999
|
* one that is over). Resolves to the written Fact, with `invalidated`
|
|
875
|
-
* listing any fact ids it superseded.
|
|
1000
|
+
* listing any fact ids it superseded. `user_id` or `agent_id` says whose
|
|
1001
|
+
* fact it is, as on `add()` (Korely 1.0.19 and later refuse neither).
|
|
876
1002
|
*/
|
|
877
1003
|
async addFactTriple(subject, predicate, object, opts = {}) {
|
|
878
1004
|
checkOptions("addFactTriple", opts, TRIPLE_KEYS);
|
|
@@ -1006,7 +1132,10 @@ var Korely = class {
|
|
|
1006
1132
|
* POST /v1/batch: bulk import, up to 500 memory objects, processed
|
|
1007
1133
|
* asynchronously. Each object is the body of one `add()` (see
|
|
1008
1134
|
* `BatchMemory`): `content` and optionally `user_id`, `agent_id`, `run_id`,
|
|
1009
|
-
* `metadata` and `timestamp`.
|
|
1135
|
+
* `metadata` and `timestamp`. On Korely 1.0.19 and later each object needs
|
|
1136
|
+
* `user_id` or `agent_id`: one with neither refuses the whole batch before
|
|
1137
|
+
* anything is queued, a 422 (`code === "identity_required"`) whose message
|
|
1138
|
+
* names it, `memories[3].user_id or memories[3].agent_id is required`.
|
|
1010
1139
|
*
|
|
1011
1140
|
* `timestamp` means what it means on `add()`: when the events happened.
|
|
1012
1141
|
* The facts extracted from the item inherit it as `valid_from`, so a
|
package/dist/index.d.cts
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
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
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"
|
|
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.
|
|
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:
|
|
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
|
|
614
|
-
* with every key, project, memory, fact and webhook of it; the
|
|
615
|
-
* working. Cloud only, for an account made by `Korely.initAgent()`
|
|
616
|
-
* `korely init --agent`, which nobody signs in to: the key is the
|
|
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
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
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?:
|
|
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).
|
|
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
|
|
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
|
-
*
|
|
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
|