korely-memory 0.1.6 → 0.1.7
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 +36 -27
- package/dist/index.cjs +224 -83
- package/dist/index.d.cts +281 -67
- package/dist/index.d.ts +281 -67
- package/dist/index.js +224 -83
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,35 +8,42 @@ var KorelyError = class extends Error {
|
|
|
8
8
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
var
|
|
11
|
+
var APIError = class extends KorelyError {
|
|
12
|
+
constructor(message = "", opts = {}) {
|
|
13
|
+
super(message, opts);
|
|
14
|
+
this.name = "APIError";
|
|
15
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var AuthenticationError = class _AuthenticationError extends APIError {
|
|
12
19
|
constructor(message = "", opts = {}) {
|
|
13
20
|
super(message, opts);
|
|
14
21
|
this.name = "AuthenticationError";
|
|
15
22
|
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
16
23
|
}
|
|
17
24
|
};
|
|
18
|
-
var NamespaceForbiddenError = class _NamespaceForbiddenError extends
|
|
25
|
+
var NamespaceForbiddenError = class _NamespaceForbiddenError extends APIError {
|
|
19
26
|
constructor(message = "", opts = {}) {
|
|
20
27
|
super(message, opts);
|
|
21
28
|
this.name = "NamespaceForbiddenError";
|
|
22
29
|
Object.setPrototypeOf(this, _NamespaceForbiddenError.prototype);
|
|
23
30
|
}
|
|
24
31
|
};
|
|
25
|
-
var NotFoundError = class _NotFoundError extends
|
|
32
|
+
var NotFoundError = class _NotFoundError extends APIError {
|
|
26
33
|
constructor(message = "", opts = {}) {
|
|
27
34
|
super(message, opts);
|
|
28
35
|
this.name = "NotFoundError";
|
|
29
36
|
Object.setPrototypeOf(this, _NotFoundError.prototype);
|
|
30
37
|
}
|
|
31
38
|
};
|
|
32
|
-
var StaleWriteError = class _StaleWriteError extends
|
|
39
|
+
var StaleWriteError = class _StaleWriteError extends APIError {
|
|
33
40
|
constructor(message = "", opts = {}) {
|
|
34
41
|
super(message, opts);
|
|
35
42
|
this.name = "StaleWriteError";
|
|
36
43
|
Object.setPrototypeOf(this, _StaleWriteError.prototype);
|
|
37
44
|
}
|
|
38
45
|
};
|
|
39
|
-
var QuotaExceededError = class _QuotaExceededError extends
|
|
46
|
+
var QuotaExceededError = class _QuotaExceededError extends APIError {
|
|
40
47
|
constructor(message = "", opts = {}) {
|
|
41
48
|
super(message, opts);
|
|
42
49
|
this.name = "QuotaExceededError";
|
|
@@ -44,16 +51,9 @@ var QuotaExceededError = class _QuotaExceededError extends KorelyError {
|
|
|
44
51
|
Object.setPrototypeOf(this, _QuotaExceededError.prototype);
|
|
45
52
|
}
|
|
46
53
|
};
|
|
47
|
-
var APIError = class _APIError extends KorelyError {
|
|
48
|
-
constructor(message = "", opts = {}) {
|
|
49
|
-
super(message, opts);
|
|
50
|
-
this.name = "APIError";
|
|
51
|
-
Object.setPrototypeOf(this, _APIError.prototype);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
54
|
|
|
55
55
|
// src/client.ts
|
|
56
|
-
var VERSION = "0.1.
|
|
56
|
+
var VERSION = "0.1.7";
|
|
57
57
|
var REGIONS = { eu: "https://api.korely.ai" };
|
|
58
58
|
function coerceContent(content) {
|
|
59
59
|
if (typeof content === "string") return content;
|
|
@@ -75,6 +75,38 @@ function coerceContent(content) {
|
|
|
75
75
|
}
|
|
76
76
|
return String(content);
|
|
77
77
|
}
|
|
78
|
+
function seg(value, what) {
|
|
79
|
+
const s = value == null ? "" : String(value);
|
|
80
|
+
if (!s) throw new KorelyError(`${what} is empty.`);
|
|
81
|
+
return encodeURIComponent(s);
|
|
82
|
+
}
|
|
83
|
+
function detailLine(detail) {
|
|
84
|
+
if (typeof detail === "string") return detail.trim() ? detail : void 0;
|
|
85
|
+
if (Array.isArray(detail) && detail.length) {
|
|
86
|
+
const parts = detail.slice(0, 3).map((e) => {
|
|
87
|
+
if (!e || typeof e !== "object") return String(e);
|
|
88
|
+
const loc = Array.isArray(e.loc) ? e.loc : [];
|
|
89
|
+
const where = loc.filter((x) => x !== "body").map(String).join(".");
|
|
90
|
+
const msg = String(e.msg ?? "invalid");
|
|
91
|
+
return where ? `${where}: ${msg}` : msg;
|
|
92
|
+
});
|
|
93
|
+
const more = detail.length - 3;
|
|
94
|
+
return parts.join("; ") + (more > 0 ? ` (and ${more} more)` : "");
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
function errorFields(status, body) {
|
|
99
|
+
const text = (v) => typeof v === "string" && v.trim() ? v : void 0;
|
|
100
|
+
const b = body && typeof body === "object" ? body : {};
|
|
101
|
+
const pair = b.detail && typeof b.detail === "object" && !Array.isArray(b.detail) ? b.detail : {};
|
|
102
|
+
const code = text(b.code) ?? text(pair.code);
|
|
103
|
+
const message = text(b.message) ?? text(pair.message) ?? detailLine(b.detail) ?? code ?? `HTTP ${status}`;
|
|
104
|
+
return { code, message };
|
|
105
|
+
}
|
|
106
|
+
function fillPair(obj, current, deprecated) {
|
|
107
|
+
if (obj[current] == null && obj[deprecated] != null) obj[current] = obj[deprecated];
|
|
108
|
+
if (obj[deprecated] == null && obj[current] != null) obj[deprecated] = obj[current];
|
|
109
|
+
}
|
|
78
110
|
function iterableOver(page, key) {
|
|
79
111
|
const out = page;
|
|
80
112
|
Object.defineProperty(out, Symbol.iterator, {
|
|
@@ -150,26 +182,46 @@ var Korely = class {
|
|
|
150
182
|
headers["Content-Type"] = "application/json";
|
|
151
183
|
}
|
|
152
184
|
const controller = new AbortController();
|
|
153
|
-
|
|
185
|
+
let timedOut = false;
|
|
186
|
+
const timer = setTimeout(() => {
|
|
187
|
+
timedOut = true;
|
|
188
|
+
controller.abort();
|
|
189
|
+
}, this.timeoutMs);
|
|
190
|
+
const failed = (e) => new KorelyError(
|
|
191
|
+
timedOut ? `Request timed out after ${this.timeoutMs} ms (${method} ${path}).` : `Connection error: ${e?.message ?? String(e)}`
|
|
192
|
+
);
|
|
154
193
|
let resp;
|
|
194
|
+
let text;
|
|
155
195
|
try {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
196
|
+
try {
|
|
197
|
+
resp = await this.fetchImpl(url, {
|
|
198
|
+
method,
|
|
199
|
+
headers,
|
|
200
|
+
body,
|
|
201
|
+
signal: controller.signal
|
|
202
|
+
});
|
|
203
|
+
} catch (e) {
|
|
204
|
+
throw failed(e);
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
text = await resp.text();
|
|
208
|
+
} catch (e) {
|
|
209
|
+
throw failed(e);
|
|
210
|
+
}
|
|
164
211
|
} finally {
|
|
165
212
|
clearTimeout(timer);
|
|
166
213
|
}
|
|
167
|
-
const text = await resp.text();
|
|
168
214
|
let parsed = {};
|
|
169
215
|
if (text) {
|
|
170
216
|
try {
|
|
171
217
|
parsed = JSON.parse(text);
|
|
172
218
|
} catch {
|
|
219
|
+
if (resp.ok) {
|
|
220
|
+
throw new KorelyError(
|
|
221
|
+
`The server answered ${resp.status} to ${method} ${path} with a body that is not JSON: ${JSON.stringify(text.slice(0, 200))}`,
|
|
222
|
+
{ status: resp.status }
|
|
223
|
+
);
|
|
224
|
+
}
|
|
173
225
|
parsed = { message: text };
|
|
174
226
|
}
|
|
175
227
|
}
|
|
@@ -179,8 +231,7 @@ var Korely = class {
|
|
|
179
231
|
return parsed && typeof parsed === "object" ? parsed : {};
|
|
180
232
|
}
|
|
181
233
|
raise(status, body, retryAfter) {
|
|
182
|
-
const code = body
|
|
183
|
-
const msg = body?.message || code || `HTTP ${status}`;
|
|
234
|
+
const { code, message: msg } = errorFields(status, body);
|
|
184
235
|
if (status === 401) throw new AuthenticationError(msg, { status, code });
|
|
185
236
|
if (status === 403) throw new NamespaceForbiddenError(msg, { status, code });
|
|
186
237
|
if (status === 404) throw new NotFoundError(msg, { status, code });
|
|
@@ -189,8 +240,8 @@ var Korely = class {
|
|
|
189
240
|
const raw = retryAfter ?? body?.retry_after ?? body?._retry_after;
|
|
190
241
|
let ra;
|
|
191
242
|
if (raw != null) {
|
|
192
|
-
const n =
|
|
193
|
-
ra = Number.
|
|
243
|
+
const n = Math.ceil(Number(raw));
|
|
244
|
+
ra = Number.isFinite(n) && n >= 0 ? n : void 0;
|
|
194
245
|
}
|
|
195
246
|
throw new QuotaExceededError(msg, { status, code, retryAfter: ra });
|
|
196
247
|
}
|
|
@@ -198,7 +249,7 @@ var Korely = class {
|
|
|
198
249
|
}
|
|
199
250
|
// ── memories ────────────────────────────────────────────────────────────
|
|
200
251
|
/**
|
|
201
|
-
* POST /v1/memories
|
|
252
|
+
* POST /v1/memories: store a memory; resolves to it with extracted facts.
|
|
202
253
|
* `content` is a string, or a list of chat messages (role/content), joined
|
|
203
254
|
* into one block before sending. Pass `timestamp` (ISO date/datetime) for
|
|
204
255
|
* backfill: facts extracted inherit it as `valid_from`.
|
|
@@ -207,7 +258,7 @@ var Korely = class {
|
|
|
207
258
|
const text = coerceContent(content);
|
|
208
259
|
if (!text.trim()) {
|
|
209
260
|
throw new KorelyError(
|
|
210
|
-
"content is empty
|
|
261
|
+
"content is empty: pass a non-blank string or messages with content."
|
|
211
262
|
);
|
|
212
263
|
}
|
|
213
264
|
return this.request("POST", "/v1/memories", {
|
|
@@ -222,8 +273,10 @@ var Korely = class {
|
|
|
222
273
|
});
|
|
223
274
|
}
|
|
224
275
|
/**
|
|
225
|
-
* POST /v1/memories/search
|
|
226
|
-
*
|
|
276
|
+
* POST /v1/memories/search: semantic search over raw memories, ranked by
|
|
277
|
+
* score (vector similarity to the query). `run_id` scopes to one session,
|
|
278
|
+
* `metadata` filters on what you stored at write time. `limit` defaults to
|
|
279
|
+
* the server default (15), max 50.
|
|
227
280
|
*/
|
|
228
281
|
async search(query, opts = {}) {
|
|
229
282
|
const body = await this.request("POST", "/v1/memories/search", {
|
|
@@ -231,61 +284,86 @@ var Korely = class {
|
|
|
231
284
|
query,
|
|
232
285
|
user_id: opts.user_id,
|
|
233
286
|
agent_id: opts.agent_id,
|
|
287
|
+
run_id: opts.run_id,
|
|
288
|
+
metadata: opts.metadata,
|
|
234
289
|
limit: opts.limit
|
|
235
290
|
}
|
|
236
291
|
});
|
|
237
292
|
return body.results ?? [];
|
|
238
293
|
}
|
|
239
|
-
/**
|
|
294
|
+
/**
|
|
295
|
+
* GET /v1/memories: list a scope, newest first. The page is iterable.
|
|
296
|
+
* `limit` goes up to 200 (the server capped it at 100 before 2026-09-28);
|
|
297
|
+
* `total` and `offset` walk the rest.
|
|
298
|
+
*/
|
|
240
299
|
async getAll(opts = {}) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
300
|
+
const page = await this.request(
|
|
301
|
+
"GET",
|
|
302
|
+
"/v1/memories",
|
|
303
|
+
{
|
|
304
|
+
params: {
|
|
305
|
+
user_id: opts.user_id,
|
|
306
|
+
agent_id: opts.agent_id,
|
|
307
|
+
run_id: opts.run_id,
|
|
308
|
+
limit: opts.limit ?? 50,
|
|
309
|
+
offset: opts.offset ?? 0
|
|
310
|
+
}
|
|
247
311
|
}
|
|
248
|
-
|
|
312
|
+
);
|
|
313
|
+
return iterableOver(page, "memories");
|
|
249
314
|
}
|
|
250
|
-
/** GET /v1/memories/:id
|
|
315
|
+
/** GET /v1/memories/:id: full content, metadata, extracted facts. */
|
|
251
316
|
async get(memoryId) {
|
|
252
|
-
return this.request("GET", `/v1/memories/${memoryId}`);
|
|
317
|
+
return this.request("GET", `/v1/memories/${seg(memoryId, "memoryId")}`);
|
|
253
318
|
}
|
|
254
319
|
/**
|
|
255
|
-
* PATCH /v1/memories/:id
|
|
320
|
+
* PATCH /v1/memories/:id: re-runs extraction. Pass `expected_updated_at`
|
|
256
321
|
* for optimistic concurrency (throws StaleWriteError instead of clobbering).
|
|
257
322
|
*/
|
|
258
323
|
async update(memoryId, opts) {
|
|
259
|
-
return this.request("PATCH", `/v1/memories/${memoryId}`, {
|
|
324
|
+
return this.request("PATCH", `/v1/memories/${seg(memoryId, "memoryId")}`, {
|
|
260
325
|
body: {
|
|
261
326
|
content: opts.content,
|
|
262
327
|
expected_updated_at: opts.expected_updated_at
|
|
263
328
|
}
|
|
264
329
|
});
|
|
265
330
|
}
|
|
266
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
333
|
+
* read, and the facts only it asserted are invalidated (kept as history,
|
|
334
|
+
* audited). For erasure use `deleteAll`.
|
|
335
|
+
*/
|
|
267
336
|
async delete(memoryId) {
|
|
268
|
-
return this.request("DELETE", `/v1/memories/${memoryId}`);
|
|
337
|
+
return this.request("DELETE", `/v1/memories/${seg(memoryId, "memoryId")}`);
|
|
269
338
|
}
|
|
270
339
|
/**
|
|
271
|
-
* DELETE /v1/users/:user_id/memories
|
|
272
|
-
*
|
|
340
|
+
* DELETE /v1/users/:user_id/memories: ERASE every memory and fact of one end
|
|
341
|
+
* user (GDPR Art. 17). Physical deletion, not a flag: nothing is readable
|
|
342
|
+
* afterwards. The audit row (counts, never content) survives.
|
|
343
|
+
*
|
|
344
|
+
* The receipt counts the rows in `memories_deleted` and `facts_deleted`.
|
|
345
|
+
* `memories_forgotten` and `facts_invalidated` are deprecated aliases with
|
|
346
|
+
* the same numbers; whichever pair the server sends fills both.
|
|
273
347
|
*/
|
|
274
348
|
async deleteAll(opts) {
|
|
275
|
-
|
|
349
|
+
const r = await this.request(
|
|
276
350
|
"DELETE",
|
|
277
|
-
`/v1/users/${opts.user_id}/memories`
|
|
351
|
+
`/v1/users/${seg(opts.user_id, "user_id")}/memories`
|
|
278
352
|
);
|
|
353
|
+
const fields = r;
|
|
354
|
+
fillPair(fields, "memories_deleted", "memories_forgotten");
|
|
355
|
+
fillPair(fields, "facts_deleted", "facts_invalidated");
|
|
356
|
+
return r;
|
|
279
357
|
}
|
|
280
358
|
/**
|
|
281
|
-
* GET /v1/memories/:id/history
|
|
359
|
+
* GET /v1/memories/:id/history: the lifecycle timeline of a memory,
|
|
282
360
|
* created / updated / deleted, plus every typed fact it produced.
|
|
283
361
|
*/
|
|
284
362
|
async history(memoryId) {
|
|
285
|
-
return this.request("GET", `/v1/memories/${memoryId}/history`);
|
|
363
|
+
return this.request("GET", `/v1/memories/${seg(memoryId, "memoryId")}/history`);
|
|
286
364
|
}
|
|
287
365
|
/**
|
|
288
|
-
* GET /v1/users
|
|
366
|
+
* GET /v1/users: the end users you've stored data for (distinct user_id
|
|
289
367
|
* namespaces), each with active memory + fact counts and last-active time.
|
|
290
368
|
*/
|
|
291
369
|
async users(opts = {}) {
|
|
@@ -304,12 +382,17 @@ var Korely = class {
|
|
|
304
382
|
}
|
|
305
383
|
// ── agents ────────────────────────────────────────────────────────────────
|
|
306
384
|
/**
|
|
307
|
-
* GET /v1/agents
|
|
308
|
-
* non-null agent_id values), each with active memory + fact
|
|
309
|
-
* last-active time
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
385
|
+
* GET /v1/agents: the agent namespaces written under in this key's project
|
|
386
|
+
* (the distinct non-null agent_id values), each with active memory + fact
|
|
387
|
+
* counts and last-active time. The antidote to the agent-cap trap: when a
|
|
388
|
+
* write is rejected with `agent_cap_exceeded`, call this to see which
|
|
389
|
+
* namespaces already exist and reuse one instead of minting a new id.
|
|
390
|
+
*
|
|
391
|
+
* `total` counts this project's namespaces (exactly the ones this key can
|
|
392
|
+
* delete); `used` counts the cap slots taken across the whole account, by
|
|
393
|
+
* name, which is what the 403 compares with `cap`. `used` is above `total`
|
|
394
|
+
* when other projects use names this one does not. A self-hosted install
|
|
395
|
+
* sets no cap and answers `cap: 0`.
|
|
313
396
|
*/
|
|
314
397
|
async listAgents(opts = {}) {
|
|
315
398
|
const page = await this.request("GET", "/v1/agents", {
|
|
@@ -321,18 +404,26 @@ var Korely = class {
|
|
|
321
404
|
return iterableOver(page, "agents");
|
|
322
405
|
}
|
|
323
406
|
/**
|
|
324
|
-
* DELETE /v1/agents/:agent_id
|
|
325
|
-
* memory + fact written under this agent_id
|
|
326
|
-
* (soft-forgetting its data does NOT free
|
|
327
|
-
* counts
|
|
407
|
+
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
408
|
+
* memory + fact written under this agent_id in this key's project
|
|
409
|
+
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
410
|
+
* to the purge counts, an audit id and `slot_freed`.
|
|
411
|
+
*
|
|
412
|
+
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
413
|
+
* rejects with NotFoundError, including a name only another project of the
|
|
414
|
+
* account uses (the server answered 200 with zero counts for it before
|
|
415
|
+
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
416
|
+
* so while another project still uses the same agent_id its rows stay and
|
|
417
|
+
* `slot_freed` is false.
|
|
328
418
|
*/
|
|
329
419
|
async deleteAgent(agentId) {
|
|
330
|
-
return this.request("DELETE", `/v1/agents/${agentId}`);
|
|
420
|
+
return this.request("DELETE", `/v1/agents/${seg(agentId, "agentId")}`);
|
|
331
421
|
}
|
|
332
422
|
// ── facts ─────────────────────────────────────────────────────────────────
|
|
333
423
|
/**
|
|
334
|
-
* GET /v1/facts
|
|
335
|
-
* validity. Pass `as_of` (ISO date) for a point-in-time query.
|
|
424
|
+
* GET /v1/facts: typed (subject, predicate, object) triples with bi-temporal
|
|
425
|
+
* validity. Pass `as_of` (ISO date) for a point-in-time query. Resolves to an
|
|
426
|
+
* array that also carries `total`, the matches across all pages.
|
|
336
427
|
*/
|
|
337
428
|
async getFacts(opts = {}) {
|
|
338
429
|
const params = {
|
|
@@ -348,13 +439,19 @@ var Korely = class {
|
|
|
348
439
|
};
|
|
349
440
|
if (opts.include_invalidated) params.include_invalidated = "true";
|
|
350
441
|
const body = await this.request("GET", "/v1/facts", { params });
|
|
351
|
-
|
|
442
|
+
const facts = [...body.facts ?? []];
|
|
443
|
+
Object.defineProperty(facts, "total", {
|
|
444
|
+
value: typeof body.total === "number" ? body.total : facts.length,
|
|
445
|
+
enumerable: false
|
|
446
|
+
});
|
|
447
|
+
return facts;
|
|
352
448
|
}
|
|
353
449
|
/**
|
|
354
|
-
* POST /v1/facts
|
|
450
|
+
* POST /v1/facts: write a typed (subject, predicate, object) triple directly,
|
|
355
451
|
* skipping extraction. The server runs the contradiction check; the fact is
|
|
356
|
-
* bi-temporal (pass `valid_from` for a historical fact
|
|
357
|
-
* written Fact, with `invalidated`
|
|
452
|
+
* bi-temporal (pass `valid_from` for a historical fact, `tense: "past"` for
|
|
453
|
+
* one that is over). Resolves to the written Fact, with `invalidated`
|
|
454
|
+
* listing any fact ids it superseded.
|
|
358
455
|
*/
|
|
359
456
|
async addFactTriple(subject, predicate, object, opts = {}) {
|
|
360
457
|
return this.request("POST", "/v1/facts", {
|
|
@@ -368,17 +465,13 @@ var Korely = class {
|
|
|
368
465
|
subject_type: opts.subject_type ?? "unknown",
|
|
369
466
|
object_is_literal: opts.object_is_literal ?? false,
|
|
370
467
|
confidence: opts.confidence ?? 0.9,
|
|
371
|
-
valid_from: opts.valid_from
|
|
468
|
+
valid_from: opts.valid_from,
|
|
469
|
+
tense: opts.tense
|
|
372
470
|
}
|
|
373
471
|
});
|
|
374
472
|
}
|
|
375
473
|
/**
|
|
376
|
-
*
|
|
377
|
-
* facts known about them, the end user's own facts first, grouped by family.
|
|
378
|
-
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
379
|
-
*/
|
|
380
|
-
/**
|
|
381
|
-
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
474
|
+
* POST /v1/facts/:id/forget: close a fact; it stops being current and stays
|
|
382
475
|
* in history.
|
|
383
476
|
*
|
|
384
477
|
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
@@ -392,22 +485,34 @@ var Korely = class {
|
|
|
392
485
|
* knows a fact is finished says so, and nothing has to infer it.
|
|
393
486
|
*/
|
|
394
487
|
async forgetFact(factId, opts = {}) {
|
|
395
|
-
return this.request("POST", `/v1/facts/${
|
|
488
|
+
return this.request("POST", `/v1/facts/${seg(factId, "factId")}/forget`, {
|
|
396
489
|
body: { at: opts.at }
|
|
397
490
|
});
|
|
398
491
|
}
|
|
399
492
|
/**
|
|
400
|
-
* PATCH /v1/facts/:id
|
|
493
|
+
* PATCH /v1/facts/:id: supersede a fact with a corrected one.
|
|
401
494
|
*
|
|
402
495
|
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
403
496
|
* one, so `as_of` before the correction still returns what you believed then.
|
|
404
497
|
* At least one of the three fields is required.
|
|
498
|
+
*
|
|
499
|
+
* Resolves to the new Fact in the write shape. Its `invalidated` lists every
|
|
500
|
+
* fact the correction superseded: the corrected one first, then any other
|
|
501
|
+
* that the contradiction check on the new fact closed. It is not always one
|
|
502
|
+
* id. A correction that names the fact as it already stands (same subject,
|
|
503
|
+
* predicate and object, still open) supersedes nothing: the server
|
|
504
|
+
* reconfirms the fact and returns it, same `id`, with `invalidated: []`.
|
|
405
505
|
*/
|
|
406
506
|
async correctFact(factId, changes) {
|
|
407
|
-
return this.request("PATCH", `/v1/facts/${
|
|
507
|
+
return this.request("PATCH", `/v1/facts/${seg(factId, "factId")}`, {
|
|
408
508
|
body: changes
|
|
409
509
|
});
|
|
410
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* GET /v1/profile: the assembled profile of one end user, the active typed
|
|
513
|
+
* facts known about them, the end user's own facts first, grouped by family.
|
|
514
|
+
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
515
|
+
*/
|
|
411
516
|
async getProfile(opts) {
|
|
412
517
|
return this.request("GET", "/v1/profile", {
|
|
413
518
|
params: {
|
|
@@ -419,7 +524,7 @@ var Korely = class {
|
|
|
419
524
|
}
|
|
420
525
|
// ── context ─────────────────────────────────────────────────────────────
|
|
421
526
|
/**
|
|
422
|
-
* GET /v1/context
|
|
527
|
+
* GET /v1/context: one call that assembles a prompt-ready context block
|
|
423
528
|
* (profile + relevant facts + memories) within a token budget.
|
|
424
529
|
*/
|
|
425
530
|
async getContext(opts) {
|
|
@@ -432,14 +537,50 @@ var Korely = class {
|
|
|
432
537
|
}
|
|
433
538
|
});
|
|
434
539
|
}
|
|
540
|
+
// ── processing state ───────────────────────────────────────────────────────
|
|
541
|
+
/**
|
|
542
|
+
* GET /v1/events: which writes have finished being processed.
|
|
543
|
+
*
|
|
544
|
+
* `add()` resolves as soon as the memory is stored; fact extraction runs
|
|
545
|
+
* behind it. Each event carries a memory's `status` ("processing", "ready"
|
|
546
|
+
* or "error"), newest first. `status` filters before `limit` (up to 200) is
|
|
547
|
+
* applied, so `{ status: "error" }` returns the latest errors however many
|
|
548
|
+
* ready writes came after them. `processing` counts every write of this
|
|
549
|
+
* key's project still in flight (of `user_id`, when given), whatever
|
|
550
|
+
* `status` and `limit` say. No webhook fires when extraction finishes, so
|
|
551
|
+
* this is how to know.
|
|
552
|
+
*/
|
|
553
|
+
async events(opts = {}) {
|
|
554
|
+
return this.request("GET", "/v1/events", {
|
|
555
|
+
params: {
|
|
556
|
+
user_id: opts.user_id,
|
|
557
|
+
status: opts.status,
|
|
558
|
+
limit: opts.limit ?? 50
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
435
562
|
// ── batch ─────────────────────────────────────────────────────────────────
|
|
436
|
-
/**
|
|
563
|
+
/**
|
|
564
|
+
* POST /v1/batch: bulk import, up to 500 memory objects, processed
|
|
565
|
+
* asynchronously. Each object is the body of one `add()` (see
|
|
566
|
+
* `BatchMemory`): `content` and optionally `user_id`, `agent_id`, `run_id`,
|
|
567
|
+
* `metadata` and `timestamp`.
|
|
568
|
+
*
|
|
569
|
+
* `timestamp` means what it means on `add()`: when the events happened.
|
|
570
|
+
* The facts extracted from the item inherit it as `valid_from`, so a
|
|
571
|
+
* migration keeps its real dates; without it an item is dated when it is
|
|
572
|
+
* imported. A value that is not an ISO 8601 date or datetime refuses the
|
|
573
|
+
* whole batch before anything is queued: a 422 (APIError,
|
|
574
|
+
* `code === "invalid_request"`) whose message names the item, e.g.
|
|
575
|
+
* `memories[3].timestamp`. Any key not listed above is refused the same
|
|
576
|
+
* way. Servers older than 2026-09-28 refuse `timestamp` itself.
|
|
577
|
+
*/
|
|
437
578
|
async batch(memories) {
|
|
438
579
|
return this.request("POST", "/v1/batch", { body: { memories } });
|
|
439
580
|
}
|
|
440
|
-
/** GET /v1/batch/:id
|
|
581
|
+
/** GET /v1/batch/:id: poll an import job. */
|
|
441
582
|
async batchStatus(jobId) {
|
|
442
|
-
return this.request("GET", `/v1/batch/${jobId}`);
|
|
583
|
+
return this.request("GET", `/v1/batch/${seg(jobId, "jobId")}`);
|
|
443
584
|
}
|
|
444
585
|
};
|
|
445
586
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "korely-memory",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "JavaScript / TypeScript SDK for Korely Agents
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "JavaScript / TypeScript SDK for Korely Agents: memory for AI agents with bi-temporal typed facts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
7
7
|
"agents",
|