korely-memory 0.1.18 → 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 +14 -7
- package/dist/chunk-VT7GXOPS.js +1131 -0
- package/dist/index.cjs +147 -27
- package/dist/index.d.cts +72 -20
- package/dist/index.d.ts +72 -20
- package/dist/index.js +13 -992
- 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).
|
|
548
589
|
*
|
|
549
|
-
* `
|
|
550
|
-
*
|
|
551
|
-
*
|
|
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`).
|
|
605
|
+
*
|
|
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) {
|
|
631
|
+
throw new KorelyError(
|
|
632
|
+
`The account of this key is ${account}, and the confirmation names ${typed}: nothing was deleted. To delete account ${account}, pass { confirm: "${account}" }.`,
|
|
633
|
+
{ code: "confirmation_required" }
|
|
634
|
+
);
|
|
635
|
+
}
|
|
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) {
|
|
562
649
|
throw new KorelyError(
|
|
563
|
-
"
|
|
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)}`,
|
|
564
678
|
{ code: "confirmation_required" }
|
|
565
679
|
);
|
|
566
680
|
}
|
|
567
|
-
return
|
|
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
|
/**
|
|
@@ -749,7 +866,8 @@ var Korely = class {
|
|
|
749
866
|
/**
|
|
750
867
|
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
751
868
|
* read, and the facts only it asserted are invalidated (kept as history,
|
|
752
|
-
* audited).
|
|
869
|
+
* audited). The facts its facts had closed are true again: the receipt
|
|
870
|
+
* counts them in `facts_reopened`. For erasure use `deleteAll`.
|
|
753
871
|
*/
|
|
754
872
|
async delete(memoryId) {
|
|
755
873
|
return this.request("DELETE", `/v1/memories/${seg(memoryId, "memoryId")}`);
|
|
@@ -828,14 +946,16 @@ var Korely = class {
|
|
|
828
946
|
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
829
947
|
* memory + fact written under this agent_id in this key's project
|
|
830
948
|
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
831
|
-
* 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()`.
|
|
832
952
|
*
|
|
833
953
|
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
834
954
|
* rejects with NotFoundError, including a name only another project of the
|
|
835
955
|
* account uses (the server answered 200 with zero counts for it before
|
|
836
956
|
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
837
957
|
* so while another project still uses the same agent_id its rows stay and
|
|
838
|
-
*
|
|
958
|
+
* the slot stays taken.
|
|
839
959
|
*/
|
|
840
960
|
async deleteAgent(agentId) {
|
|
841
961
|
return this.request("DELETE", `/v1/agents/${seg(agentId, "agentId")}`);
|
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
|
|
@@ -273,13 +280,18 @@ interface AgentDeleteReceipt {
|
|
|
273
280
|
facts_deleted?: number;
|
|
274
281
|
audit_id?: string;
|
|
275
282
|
/**
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
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.
|
|
281
288
|
*/
|
|
282
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;
|
|
283
295
|
}
|
|
284
296
|
/** What `ping()` answers: the key works. */
|
|
285
297
|
interface PingResponse {
|
|
@@ -342,7 +354,9 @@ type AuditActor = "rest" | "mcp" | "dashboard" | "manage" | "worker" | string;
|
|
|
342
354
|
* What happened, in an audit event. An open string for the same reason as
|
|
343
355
|
* AuditActor; "tenant_create" is the Self-hosted's only.
|
|
344
356
|
*/
|
|
345
|
-
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;
|
|
346
360
|
/** For a read: what the call returned, by public id, at most 100 of each kind. Ids only, never content. */
|
|
347
361
|
interface AuditRead {
|
|
348
362
|
memories: string[];
|
|
@@ -364,6 +378,13 @@ interface AuditEvent {
|
|
|
364
378
|
ip?: string | null;
|
|
365
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. */
|
|
366
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;
|
|
367
388
|
}
|
|
368
389
|
/** Iterable page of the audit trail, newest first. `total` counts the matches across every page. */
|
|
369
390
|
interface AuditPage extends Iterable<AuditEvent> {
|
|
@@ -559,7 +580,7 @@ interface ForgetReceipt {
|
|
|
559
580
|
|
|
560
581
|
/** Must equal `version` in package.json (a test checks). It goes out in the
|
|
561
582
|
* X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
|
|
562
|
-
declare const VERSION = "0.
|
|
583
|
+
declare const VERSION = "0.2.0";
|
|
563
584
|
interface KorelyOptions {
|
|
564
585
|
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
565
586
|
apiKey?: string;
|
|
@@ -609,7 +630,7 @@ declare class Korely {
|
|
|
609
630
|
* label of who signed up, kept for your reference. The answer carries the
|
|
610
631
|
* key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
|
|
611
632
|
* The account it creates has no login: the key is the account, and
|
|
612
|
-
* `deleteAccount({ confirm:
|
|
633
|
+
* `deleteAccount({ confirm: "<the account's id>" })` closes it.
|
|
613
634
|
*
|
|
614
635
|
* Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
|
|
615
636
|
* region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
|
|
@@ -631,15 +652,36 @@ declare class Korely {
|
|
|
631
652
|
*/
|
|
632
653
|
ping(): Promise<PingResponse>;
|
|
633
654
|
/**
|
|
634
|
-
* DELETE /v1/account?confirm
|
|
635
|
-
* with every key, project, memory, fact and webhook of it; the
|
|
636
|
-
* working. Cloud only, for an account made by `Korely.initAgent()`
|
|
637
|
-
* `korely init --agent`, which nobody signs in to: the key is the
|
|
638
|
-
* 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`).
|
|
639
676
|
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
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.
|
|
643
685
|
*
|
|
644
686
|
* An account with a Korely login rejects with 409 `account_has_login`
|
|
645
687
|
* (ConflictError): a key that ended up in a log must not be able to delete
|
|
@@ -648,8 +690,15 @@ declare class Korely {
|
|
|
648
690
|
* dashboard. No audit event survives: the trail is part of what goes.
|
|
649
691
|
*/
|
|
650
692
|
deleteAccount(opts?: {
|
|
651
|
-
confirm?:
|
|
693
|
+
confirm?: string;
|
|
652
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;
|
|
653
702
|
/**
|
|
654
703
|
* GET /v1/audit: what this key's project did, and what its agents read,
|
|
655
704
|
* newest first (`ts` descending, then the event's id, so paging with
|
|
@@ -728,7 +777,8 @@ declare class Korely {
|
|
|
728
777
|
/**
|
|
729
778
|
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
730
779
|
* read, and the facts only it asserted are invalidated (kept as history,
|
|
731
|
-
* audited).
|
|
780
|
+
* audited). The facts its facts had closed are true again: the receipt
|
|
781
|
+
* counts them in `facts_reopened`. For erasure use `deleteAll`.
|
|
732
782
|
*/
|
|
733
783
|
delete(memoryId: string): Promise<DeleteReceipt>;
|
|
734
784
|
/**
|
|
@@ -771,14 +821,16 @@ declare class Korely {
|
|
|
771
821
|
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
772
822
|
* memory + fact written under this agent_id in this key's project
|
|
773
823
|
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
774
|
-
* 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()`.
|
|
775
827
|
*
|
|
776
828
|
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
777
829
|
* rejects with NotFoundError, including a name only another project of the
|
|
778
830
|
* account uses (the server answered 200 with zero counts for it before
|
|
779
831
|
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
780
832
|
* so while another project still uses the same agent_id its rows stay and
|
|
781
|
-
*
|
|
833
|
+
* the slot stays taken.
|
|
782
834
|
*/
|
|
783
835
|
deleteAgent(agentId: string): Promise<AgentDeleteReceipt>;
|
|
784
836
|
/**
|
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
|
|
@@ -273,13 +280,18 @@ interface AgentDeleteReceipt {
|
|
|
273
280
|
facts_deleted?: number;
|
|
274
281
|
audit_id?: string;
|
|
275
282
|
/**
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
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.
|
|
281
288
|
*/
|
|
282
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;
|
|
283
295
|
}
|
|
284
296
|
/** What `ping()` answers: the key works. */
|
|
285
297
|
interface PingResponse {
|
|
@@ -342,7 +354,9 @@ type AuditActor = "rest" | "mcp" | "dashboard" | "manage" | "worker" | string;
|
|
|
342
354
|
* What happened, in an audit event. An open string for the same reason as
|
|
343
355
|
* AuditActor; "tenant_create" is the Self-hosted's only.
|
|
344
356
|
*/
|
|
345
|
-
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;
|
|
346
360
|
/** For a read: what the call returned, by public id, at most 100 of each kind. Ids only, never content. */
|
|
347
361
|
interface AuditRead {
|
|
348
362
|
memories: string[];
|
|
@@ -364,6 +378,13 @@ interface AuditEvent {
|
|
|
364
378
|
ip?: string | null;
|
|
365
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. */
|
|
366
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;
|
|
367
388
|
}
|
|
368
389
|
/** Iterable page of the audit trail, newest first. `total` counts the matches across every page. */
|
|
369
390
|
interface AuditPage extends Iterable<AuditEvent> {
|
|
@@ -559,7 +580,7 @@ interface ForgetReceipt {
|
|
|
559
580
|
|
|
560
581
|
/** Must equal `version` in package.json (a test checks). It goes out in the
|
|
561
582
|
* X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
|
|
562
|
-
declare const VERSION = "0.
|
|
583
|
+
declare const VERSION = "0.2.0";
|
|
563
584
|
interface KorelyOptions {
|
|
564
585
|
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
565
586
|
apiKey?: string;
|
|
@@ -609,7 +630,7 @@ declare class Korely {
|
|
|
609
630
|
* label of who signed up, kept for your reference. The answer carries the
|
|
610
631
|
* key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
|
|
611
632
|
* The account it creates has no login: the key is the account, and
|
|
612
|
-
* `deleteAccount({ confirm:
|
|
633
|
+
* `deleteAccount({ confirm: "<the account's id>" })` closes it.
|
|
613
634
|
*
|
|
614
635
|
* Cloud only. The server is `baseUrl`, else KORELY_BASE_URL, else the
|
|
615
636
|
* region's. Refusals: 403 `signup_disabled` (NamespaceForbiddenError) when
|
|
@@ -631,15 +652,36 @@ declare class Korely {
|
|
|
631
652
|
*/
|
|
632
653
|
ping(): Promise<PingResponse>;
|
|
633
654
|
/**
|
|
634
|
-
* DELETE /v1/account?confirm
|
|
635
|
-
* with every key, project, memory, fact and webhook of it; the
|
|
636
|
-
* working. Cloud only, for an account made by `Korely.initAgent()`
|
|
637
|
-
* `korely init --agent`, which nobody signs in to: the key is the
|
|
638
|
-
* 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`).
|
|
639
676
|
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
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.
|
|
643
685
|
*
|
|
644
686
|
* An account with a Korely login rejects with 409 `account_has_login`
|
|
645
687
|
* (ConflictError): a key that ended up in a log must not be able to delete
|
|
@@ -648,8 +690,15 @@ declare class Korely {
|
|
|
648
690
|
* dashboard. No audit event survives: the trail is part of what goes.
|
|
649
691
|
*/
|
|
650
692
|
deleteAccount(opts?: {
|
|
651
|
-
confirm?:
|
|
693
|
+
confirm?: string;
|
|
652
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;
|
|
653
702
|
/**
|
|
654
703
|
* GET /v1/audit: what this key's project did, and what its agents read,
|
|
655
704
|
* newest first (`ts` descending, then the event's id, so paging with
|
|
@@ -728,7 +777,8 @@ declare class Korely {
|
|
|
728
777
|
/**
|
|
729
778
|
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
730
779
|
* read, and the facts only it asserted are invalidated (kept as history,
|
|
731
|
-
* audited).
|
|
780
|
+
* audited). The facts its facts had closed are true again: the receipt
|
|
781
|
+
* counts them in `facts_reopened`. For erasure use `deleteAll`.
|
|
732
782
|
*/
|
|
733
783
|
delete(memoryId: string): Promise<DeleteReceipt>;
|
|
734
784
|
/**
|
|
@@ -771,14 +821,16 @@ declare class Korely {
|
|
|
771
821
|
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
772
822
|
* memory + fact written under this agent_id in this key's project
|
|
773
823
|
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
774
|
-
* 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()`.
|
|
775
827
|
*
|
|
776
828
|
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
777
829
|
* rejects with NotFoundError, including a name only another project of the
|
|
778
830
|
* account uses (the server answered 200 with zero counts for it before
|
|
779
831
|
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
780
832
|
* so while another project still uses the same agent_id its rows stay and
|
|
781
|
-
*
|
|
833
|
+
* the slot stays taken.
|
|
782
834
|
*/
|
|
783
835
|
deleteAgent(agentId: string): Promise<AgentDeleteReceipt>;
|
|
784
836
|
/**
|