korely-memory 0.1.5 → 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.d.cts
CHANGED
|
@@ -24,11 +24,36 @@ interface Fact {
|
|
|
24
24
|
valid_from?: string;
|
|
25
25
|
invalid_at?: string;
|
|
26
26
|
invalidated_by?: string;
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Write shape only (add(), update(), addFactTriple(), correctFact()): the ids
|
|
29
|
+
* this write superseded. On correctFact() that is the corrected fact plus any
|
|
30
|
+
* other the contradiction check closed; empty when the correction restated
|
|
31
|
+
* the fact as it stands, which reconfirms it.
|
|
32
|
+
*/
|
|
28
33
|
invalidated?: string[];
|
|
29
34
|
source_memory_id?: string;
|
|
30
35
|
created_at?: string;
|
|
36
|
+
/** What the text said: "current", "past" (history) or "planned" (an intention). */
|
|
37
|
+
tense?: "current" | "past" | "planned" | string;
|
|
38
|
+
/** How many memories stated this fact; above 1 it was reconfirmed, not duplicated. */
|
|
39
|
+
observation_count?: number;
|
|
40
|
+
/** When a memory last restated the fact. */
|
|
41
|
+
last_confirmed_at?: string;
|
|
42
|
+
/** The subject's current name after aliases; `subject` keeps the words as written. */
|
|
43
|
+
subject_canonical?: string;
|
|
44
|
+
/** The object's current name after aliases; `object` keeps the words as written. */
|
|
45
|
+
object_canonical?: string;
|
|
46
|
+
/** Every memory that stated this fact. */
|
|
47
|
+
source_memory_ids?: string[];
|
|
31
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The facts of one `getFacts()` page: a plain array that also carries
|
|
51
|
+
* `total`, how many facts match the filters across all pages. `GET /v1/facts`
|
|
52
|
+
* has always answered with it; `getFacts()` dropped it in 0.1.6 and earlier.
|
|
53
|
+
*/
|
|
54
|
+
type FactList = Fact[] & {
|
|
55
|
+
total: number;
|
|
56
|
+
};
|
|
32
57
|
interface Memory {
|
|
33
58
|
id?: string;
|
|
34
59
|
content?: string;
|
|
@@ -56,7 +81,9 @@ interface SearchHit {
|
|
|
56
81
|
agent_id?: string;
|
|
57
82
|
metadata?: Record<string, unknown>;
|
|
58
83
|
}
|
|
59
|
-
|
|
84
|
+
/** Iterable like the Python SDK's MemoryPage: `for (const m of page)` works,
|
|
85
|
+
* and `page.memories` / `page.total` still do. */
|
|
86
|
+
interface MemoryPage extends Iterable<Memory> {
|
|
60
87
|
memories: Memory[];
|
|
61
88
|
total: number;
|
|
62
89
|
}
|
|
@@ -66,10 +93,29 @@ interface DeleteReceipt {
|
|
|
66
93
|
facts_invalidated?: number;
|
|
67
94
|
audit_id?: string;
|
|
68
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* What `deleteAll` erased. Every row is physically deleted, and `erasure` is
|
|
98
|
+
* "permanent". `memories_deleted` and `facts_deleted` count the rows: read
|
|
99
|
+
* these. `deleteAll()` fills both names from whichever pair the server sends,
|
|
100
|
+
* so they work against an install that predates them too.
|
|
101
|
+
*/
|
|
69
102
|
interface BulkReceipt {
|
|
70
103
|
user_id?: string;
|
|
104
|
+
/** Memories physically deleted. */
|
|
105
|
+
memories_deleted?: number;
|
|
106
|
+
/** Facts physically deleted. */
|
|
107
|
+
facts_deleted?: number;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated Use `memories_deleted`, same number. The only name the server
|
|
110
|
+
* sent until 2026-09-28: nothing was forgotten, it was deleted.
|
|
111
|
+
*/
|
|
71
112
|
memories_forgotten?: number;
|
|
113
|
+
/**
|
|
114
|
+
* @deprecated Use `facts_deleted`, same number. The only name the server
|
|
115
|
+
* sent until 2026-09-28: nothing was invalidated, it was deleted.
|
|
116
|
+
*/
|
|
72
117
|
facts_invalidated?: number;
|
|
118
|
+
erasure?: string;
|
|
73
119
|
audit_id?: string;
|
|
74
120
|
}
|
|
75
121
|
interface Context {
|
|
@@ -77,6 +123,25 @@ interface Context {
|
|
|
77
123
|
tokens: number;
|
|
78
124
|
sources: string[];
|
|
79
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* One item of `batch()`: the body of a single `add()`. `content` is required,
|
|
128
|
+
* every other key optional, and a key not listed here refuses the whole batch
|
|
129
|
+
* with a 422.
|
|
130
|
+
*/
|
|
131
|
+
interface BatchMemory {
|
|
132
|
+
content: string;
|
|
133
|
+
user_id?: string;
|
|
134
|
+
agent_id?: string;
|
|
135
|
+
run_id?: string;
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
/**
|
|
138
|
+
* ISO 8601 date or datetime the item's events happened. Its facts inherit it
|
|
139
|
+
* as `valid_from`, exactly as on `add()`. An unreadable value refuses the
|
|
140
|
+
* whole batch with a 422 naming `memories[i].timestamp`, before anything is
|
|
141
|
+
* queued.
|
|
142
|
+
*/
|
|
143
|
+
timestamp?: string;
|
|
144
|
+
}
|
|
80
145
|
interface BatchJob {
|
|
81
146
|
id?: string;
|
|
82
147
|
status?: string;
|
|
@@ -100,7 +165,7 @@ type HistoryEventType = "created" | "updated" | "fact_extracted" | "fact_invalid
|
|
|
100
165
|
interface HistoryEvent {
|
|
101
166
|
event?: HistoryEventType;
|
|
102
167
|
at?: string;
|
|
103
|
-
/** "subject predicate object"
|
|
168
|
+
/** "subject predicate object", set on fact events. */
|
|
104
169
|
fact?: string;
|
|
105
170
|
fact_id?: string;
|
|
106
171
|
}
|
|
@@ -108,6 +173,26 @@ interface MemoryHistory {
|
|
|
108
173
|
id?: string;
|
|
109
174
|
events: HistoryEvent[];
|
|
110
175
|
}
|
|
176
|
+
/** One memory's processing state, as `events()` reports it. */
|
|
177
|
+
interface MemoryEvent {
|
|
178
|
+
memory_id: string;
|
|
179
|
+
user_id?: string | null;
|
|
180
|
+
agent_id?: string | null;
|
|
181
|
+
/** "processing" | "ready" | "error". */
|
|
182
|
+
status: string;
|
|
183
|
+
created_at?: string | null;
|
|
184
|
+
}
|
|
185
|
+
interface EventsResponse {
|
|
186
|
+
/** Newest first. */
|
|
187
|
+
events: MemoryEvent[];
|
|
188
|
+
/**
|
|
189
|
+
* Every write of this key's project still being extracted (in the `user_id`
|
|
190
|
+
* scope, when given), whatever `status` and `limit` say. A `batch()` job that
|
|
191
|
+
* has not stored its memories yet is not counted: wait for `batchStatus()`
|
|
192
|
+
* first.
|
|
193
|
+
*/
|
|
194
|
+
processing: number;
|
|
195
|
+
}
|
|
111
196
|
interface UserScope {
|
|
112
197
|
user_id?: string;
|
|
113
198
|
memories: number;
|
|
@@ -131,11 +216,19 @@ interface AgentScope {
|
|
|
131
216
|
}
|
|
132
217
|
interface AgentsPage extends Iterable<AgentScope> {
|
|
133
218
|
agents: AgentScope[];
|
|
134
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* The agent namespaces in this key's project, before pagination: exactly
|
|
221
|
+
* the ones this key can delete. (Until 2026-09-28 the server counted the
|
|
222
|
+
* whole account here, so it always equalled `used`.)
|
|
223
|
+
*/
|
|
135
224
|
total: number;
|
|
136
|
-
/** The
|
|
225
|
+
/** The plan's agent cap; 0 on a self-hosted install, which sets no ceiling. */
|
|
137
226
|
cap: number;
|
|
138
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Agent slots taken across the whole account, by name; reconciles with the
|
|
229
|
+
* `agent_cap_exceeded` 403. Above `total` when other projects use names this
|
|
230
|
+
* project does not.
|
|
231
|
+
*/
|
|
139
232
|
used: number;
|
|
140
233
|
}
|
|
141
234
|
interface AgentDeleteReceipt {
|
|
@@ -143,6 +236,14 @@ interface AgentDeleteReceipt {
|
|
|
143
236
|
memories_deleted?: number;
|
|
144
237
|
facts_deleted?: number;
|
|
145
238
|
audit_id?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Whether the agent cap slot is free now. The cap counts a name across the
|
|
241
|
+
* account, so it stays taken (false) while another project of the account
|
|
242
|
+
* still uses the same agent_id. Undefined when the server does not say: a
|
|
243
|
+
* self-hosted install has no cap, and servers before 2026-09-28 did not send
|
|
244
|
+
* it.
|
|
245
|
+
*/
|
|
246
|
+
slot_freed?: boolean;
|
|
146
247
|
}
|
|
147
248
|
interface AddOptions {
|
|
148
249
|
agent_id?: string;
|
|
@@ -159,11 +260,19 @@ interface AddOptions {
|
|
|
159
260
|
interface SearchOptions {
|
|
160
261
|
user_id?: string;
|
|
161
262
|
agent_id?: string;
|
|
263
|
+
/** Scope to one run/session. */
|
|
264
|
+
run_id?: string;
|
|
265
|
+
/** Filter on the metadata stored at write time: keys ANDed, compared as strings. */
|
|
266
|
+
metadata?: Record<string, unknown>;
|
|
267
|
+
/** Server default 15, max 50. */
|
|
162
268
|
limit?: number;
|
|
163
269
|
}
|
|
164
270
|
interface ListOptions {
|
|
165
271
|
user_id?: string;
|
|
166
272
|
agent_id?: string;
|
|
273
|
+
/** Narrow to one run/session. */
|
|
274
|
+
run_id?: string;
|
|
275
|
+
/** Default 50, up to 200. */
|
|
167
276
|
limit?: number;
|
|
168
277
|
offset?: number;
|
|
169
278
|
}
|
|
@@ -181,6 +290,13 @@ interface ListAgentsOptions {
|
|
|
181
290
|
limit?: number;
|
|
182
291
|
offset?: number;
|
|
183
292
|
}
|
|
293
|
+
interface EventsOptions {
|
|
294
|
+
user_id?: string;
|
|
295
|
+
/** Applied before `limit`: the latest events in that state. */
|
|
296
|
+
status?: "processing" | "ready" | "error";
|
|
297
|
+
/** Default 50, up to 200. */
|
|
298
|
+
limit?: number;
|
|
299
|
+
}
|
|
184
300
|
interface GetFactsOptions {
|
|
185
301
|
subject?: string;
|
|
186
302
|
/** Matches the subject OR object side. */
|
|
@@ -188,7 +304,7 @@ interface GetFactsOptions {
|
|
|
188
304
|
predicate?: string;
|
|
189
305
|
predicate_family?: string;
|
|
190
306
|
include_invalidated?: boolean;
|
|
191
|
-
/** ISO date
|
|
307
|
+
/** ISO date: point-in-time validity ("what was true on 2026-06-01"). */
|
|
192
308
|
as_of?: string;
|
|
193
309
|
user_id?: string;
|
|
194
310
|
agent_id?: string;
|
|
@@ -202,13 +318,18 @@ interface AddFactTripleOptions {
|
|
|
202
318
|
subject_type?: string;
|
|
203
319
|
object_is_literal?: boolean;
|
|
204
320
|
confidence?: number;
|
|
205
|
-
/** ISO date
|
|
321
|
+
/** ISO date, for a historical fact. */
|
|
206
322
|
valid_from?: string;
|
|
323
|
+
/**
|
|
324
|
+
* "current" (the server default), "past" (the fact is over, and closes the
|
|
325
|
+
* open fact it restates) or "planned".
|
|
326
|
+
*/
|
|
327
|
+
tense?: "current" | "past" | "planned";
|
|
207
328
|
}
|
|
208
329
|
interface GetProfileOptions {
|
|
209
330
|
user_id: string;
|
|
210
331
|
agent_id?: string;
|
|
211
|
-
/** ISO date
|
|
332
|
+
/** ISO date: the profile as it stood on that date. */
|
|
212
333
|
as_of?: string;
|
|
213
334
|
}
|
|
214
335
|
interface GetContextOptions {
|
|
@@ -227,15 +348,17 @@ interface ForgetReceipt {
|
|
|
227
348
|
audit_id?: string | null;
|
|
228
349
|
}
|
|
229
350
|
|
|
230
|
-
|
|
351
|
+
/** Must equal `version` in package.json (a test checks). It goes out in the
|
|
352
|
+
* X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
|
|
353
|
+
declare const VERSION = "0.1.7";
|
|
231
354
|
interface KorelyOptions {
|
|
232
355
|
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
233
356
|
apiKey?: string;
|
|
234
357
|
/** EU only for now (data stored and processed in the EU). */
|
|
235
358
|
region?: "eu";
|
|
236
|
-
/** Override the base URL (
|
|
359
|
+
/** Override the base URL (a self-hosted install, or testing). */
|
|
237
360
|
baseUrl?: string;
|
|
238
|
-
/** Per-request timeout in milliseconds. Default 30000. */
|
|
361
|
+
/** Per-request timeout in milliseconds, response body included. Default 30000. */
|
|
239
362
|
timeoutMs?: number;
|
|
240
363
|
/** Inject a fetch implementation (mainly for testing / older runtimes). */
|
|
241
364
|
fetch?: typeof fetch;
|
|
@@ -249,80 +372,104 @@ declare class Korely {
|
|
|
249
372
|
private request;
|
|
250
373
|
private raise;
|
|
251
374
|
/**
|
|
252
|
-
* POST /v1/memories
|
|
375
|
+
* POST /v1/memories: store a memory; resolves to it with extracted facts.
|
|
253
376
|
* `content` is a string, or a list of chat messages (role/content), joined
|
|
254
377
|
* into one block before sending. Pass `timestamp` (ISO date/datetime) for
|
|
255
378
|
* backfill: facts extracted inherit it as `valid_from`.
|
|
256
379
|
*/
|
|
257
380
|
add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
|
|
258
381
|
/**
|
|
259
|
-
* POST /v1/memories/search
|
|
260
|
-
*
|
|
382
|
+
* POST /v1/memories/search: semantic search over raw memories, ranked by
|
|
383
|
+
* score (vector similarity to the query). `run_id` scopes to one session,
|
|
384
|
+
* `metadata` filters on what you stored at write time. `limit` defaults to
|
|
385
|
+
* the server default (15), max 50.
|
|
261
386
|
*/
|
|
262
387
|
search(query: string, opts?: SearchOptions): Promise<SearchHit[]>;
|
|
263
|
-
/**
|
|
388
|
+
/**
|
|
389
|
+
* GET /v1/memories: list a scope, newest first. The page is iterable.
|
|
390
|
+
* `limit` goes up to 200 (the server capped it at 100 before 2026-09-28);
|
|
391
|
+
* `total` and `offset` walk the rest.
|
|
392
|
+
*/
|
|
264
393
|
getAll(opts?: ListOptions): Promise<MemoryPage>;
|
|
265
|
-
/** GET /v1/memories/:id
|
|
394
|
+
/** GET /v1/memories/:id: full content, metadata, extracted facts. */
|
|
266
395
|
get(memoryId: string): Promise<Memory>;
|
|
267
396
|
/**
|
|
268
|
-
* PATCH /v1/memories/:id
|
|
397
|
+
* PATCH /v1/memories/:id: re-runs extraction. Pass `expected_updated_at`
|
|
269
398
|
* for optimistic concurrency (throws StaleWriteError instead of clobbering).
|
|
270
399
|
*/
|
|
271
400
|
update(memoryId: string, opts: UpdateOptions): Promise<Memory>;
|
|
272
|
-
/**
|
|
401
|
+
/**
|
|
402
|
+
* DELETE /v1/memories/:id: forget one memory. It drops out of every default
|
|
403
|
+
* read, and the facts only it asserted are invalidated (kept as history,
|
|
404
|
+
* audited). For erasure use `deleteAll`.
|
|
405
|
+
*/
|
|
273
406
|
delete(memoryId: string): Promise<DeleteReceipt>;
|
|
274
407
|
/**
|
|
275
|
-
* DELETE /v1/users/:user_id/memories
|
|
276
|
-
*
|
|
408
|
+
* DELETE /v1/users/:user_id/memories: ERASE every memory and fact of one end
|
|
409
|
+
* user (GDPR Art. 17). Physical deletion, not a flag: nothing is readable
|
|
410
|
+
* afterwards. The audit row (counts, never content) survives.
|
|
411
|
+
*
|
|
412
|
+
* The receipt counts the rows in `memories_deleted` and `facts_deleted`.
|
|
413
|
+
* `memories_forgotten` and `facts_invalidated` are deprecated aliases with
|
|
414
|
+
* the same numbers; whichever pair the server sends fills both.
|
|
277
415
|
*/
|
|
278
416
|
deleteAll(opts: {
|
|
279
417
|
user_id: string;
|
|
280
418
|
}): Promise<BulkReceipt>;
|
|
281
419
|
/**
|
|
282
|
-
* GET /v1/memories/:id/history
|
|
420
|
+
* GET /v1/memories/:id/history: the lifecycle timeline of a memory,
|
|
283
421
|
* created / updated / deleted, plus every typed fact it produced.
|
|
284
422
|
*/
|
|
285
423
|
history(memoryId: string): Promise<MemoryHistory>;
|
|
286
424
|
/**
|
|
287
|
-
* GET /v1/users
|
|
425
|
+
* GET /v1/users: the end users you've stored data for (distinct user_id
|
|
288
426
|
* namespaces), each with active memory + fact counts and last-active time.
|
|
289
427
|
*/
|
|
290
428
|
users(opts?: UsersOptions): Promise<UsersPage>;
|
|
291
429
|
/**
|
|
292
|
-
* GET /v1/agents
|
|
293
|
-
* non-null agent_id values), each with active memory + fact
|
|
294
|
-
* last-active time
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
430
|
+
* GET /v1/agents: the agent namespaces written under in this key's project
|
|
431
|
+
* (the distinct non-null agent_id values), each with active memory + fact
|
|
432
|
+
* counts and last-active time. The antidote to the agent-cap trap: when a
|
|
433
|
+
* write is rejected with `agent_cap_exceeded`, call this to see which
|
|
434
|
+
* namespaces already exist and reuse one instead of minting a new id.
|
|
435
|
+
*
|
|
436
|
+
* `total` counts this project's namespaces (exactly the ones this key can
|
|
437
|
+
* delete); `used` counts the cap slots taken across the whole account, by
|
|
438
|
+
* name, which is what the 403 compares with `cap`. `used` is above `total`
|
|
439
|
+
* when other projects use names this one does not. A self-hosted install
|
|
440
|
+
* sets no cap and answers `cap: 0`.
|
|
298
441
|
*/
|
|
299
442
|
listAgents(opts?: ListAgentsOptions): Promise<AgentsPage>;
|
|
300
443
|
/**
|
|
301
|
-
* DELETE /v1/agents/:agent_id
|
|
302
|
-
* memory + fact written under this agent_id
|
|
303
|
-
* (soft-forgetting its data does NOT free
|
|
304
|
-
* counts
|
|
444
|
+
* DELETE /v1/agents/:agent_id: hard-delete an agent namespace, purging every
|
|
445
|
+
* memory + fact written under this agent_id in this key's project
|
|
446
|
+
* (soft-forgetting its data does NOT free its cap slot; this does). Resolves
|
|
447
|
+
* to the purge counts, an audit id and `slot_freed`.
|
|
448
|
+
*
|
|
449
|
+
* The namespace must be one `listAgents()` shows for this key: anything else
|
|
450
|
+
* rejects with NotFoundError, including a name only another project of the
|
|
451
|
+
* account uses (the server answered 200 with zero counts for it before
|
|
452
|
+
* 2026-09-28, and freed nothing). The cap counts a name across the account,
|
|
453
|
+
* so while another project still uses the same agent_id its rows stay and
|
|
454
|
+
* `slot_freed` is false.
|
|
305
455
|
*/
|
|
306
456
|
deleteAgent(agentId: string): Promise<AgentDeleteReceipt>;
|
|
307
457
|
/**
|
|
308
|
-
* GET /v1/facts
|
|
309
|
-
* validity. Pass `as_of` (ISO date) for a point-in-time query.
|
|
458
|
+
* GET /v1/facts: typed (subject, predicate, object) triples with bi-temporal
|
|
459
|
+
* validity. Pass `as_of` (ISO date) for a point-in-time query. Resolves to an
|
|
460
|
+
* array that also carries `total`, the matches across all pages.
|
|
310
461
|
*/
|
|
311
|
-
getFacts(opts?: GetFactsOptions): Promise<
|
|
462
|
+
getFacts(opts?: GetFactsOptions): Promise<FactList>;
|
|
312
463
|
/**
|
|
313
|
-
* POST /v1/facts
|
|
464
|
+
* POST /v1/facts: write a typed (subject, predicate, object) triple directly,
|
|
314
465
|
* skipping extraction. The server runs the contradiction check; the fact is
|
|
315
|
-
* bi-temporal (pass `valid_from` for a historical fact
|
|
316
|
-
* written Fact, with `invalidated`
|
|
466
|
+
* bi-temporal (pass `valid_from` for a historical fact, `tense: "past"` for
|
|
467
|
+
* one that is over). Resolves to the written Fact, with `invalidated`
|
|
468
|
+
* listing any fact ids it superseded.
|
|
317
469
|
*/
|
|
318
470
|
addFactTriple(subject: string, predicate: string, object: string, opts?: AddFactTripleOptions): Promise<Fact>;
|
|
319
471
|
/**
|
|
320
|
-
*
|
|
321
|
-
* facts known about them, the end user's own facts first, grouped by family.
|
|
322
|
-
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
323
|
-
*/
|
|
324
|
-
/**
|
|
325
|
-
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
472
|
+
* POST /v1/facts/:id/forget: close a fact; it stops being current and stays
|
|
326
473
|
* in history.
|
|
327
474
|
*
|
|
328
475
|
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
@@ -339,32 +486,82 @@ declare class Korely {
|
|
|
339
486
|
at?: string;
|
|
340
487
|
}): Promise<ForgetReceipt>;
|
|
341
488
|
/**
|
|
342
|
-
* PATCH /v1/facts/:id
|
|
489
|
+
* PATCH /v1/facts/:id: supersede a fact with a corrected one.
|
|
343
490
|
*
|
|
344
491
|
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
345
492
|
* one, so `as_of` before the correction still returns what you believed then.
|
|
346
493
|
* At least one of the three fields is required.
|
|
494
|
+
*
|
|
495
|
+
* Resolves to the new Fact in the write shape. Its `invalidated` lists every
|
|
496
|
+
* fact the correction superseded: the corrected one first, then any other
|
|
497
|
+
* that the contradiction check on the new fact closed. It is not always one
|
|
498
|
+
* id. A correction that names the fact as it already stands (same subject,
|
|
499
|
+
* predicate and object, still open) supersedes nothing: the server
|
|
500
|
+
* reconfirms the fact and returns it, same `id`, with `invalidated: []`.
|
|
347
501
|
*/
|
|
348
502
|
correctFact(factId: string, changes: {
|
|
349
503
|
subject?: string;
|
|
350
504
|
predicate?: string;
|
|
351
505
|
object?: string;
|
|
352
506
|
}): Promise<Fact>;
|
|
507
|
+
/**
|
|
508
|
+
* GET /v1/profile: the assembled profile of one end user, the active typed
|
|
509
|
+
* facts known about them, the end user's own facts first, grouped by family.
|
|
510
|
+
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
511
|
+
*/
|
|
353
512
|
getProfile(opts: GetProfileOptions): Promise<Profile>;
|
|
354
513
|
/**
|
|
355
|
-
* GET /v1/context
|
|
514
|
+
* GET /v1/context: one call that assembles a prompt-ready context block
|
|
356
515
|
* (profile + relevant facts + memories) within a token budget.
|
|
357
516
|
*/
|
|
358
517
|
getContext(opts: GetContextOptions): Promise<Context>;
|
|
359
|
-
/**
|
|
360
|
-
|
|
361
|
-
|
|
518
|
+
/**
|
|
519
|
+
* GET /v1/events: which writes have finished being processed.
|
|
520
|
+
*
|
|
521
|
+
* `add()` resolves as soon as the memory is stored; fact extraction runs
|
|
522
|
+
* behind it. Each event carries a memory's `status` ("processing", "ready"
|
|
523
|
+
* or "error"), newest first. `status` filters before `limit` (up to 200) is
|
|
524
|
+
* applied, so `{ status: "error" }` returns the latest errors however many
|
|
525
|
+
* ready writes came after them. `processing` counts every write of this
|
|
526
|
+
* key's project still in flight (of `user_id`, when given), whatever
|
|
527
|
+
* `status` and `limit` say. No webhook fires when extraction finishes, so
|
|
528
|
+
* this is how to know.
|
|
529
|
+
*/
|
|
530
|
+
events(opts?: EventsOptions): Promise<EventsResponse>;
|
|
531
|
+
/**
|
|
532
|
+
* POST /v1/batch: bulk import, up to 500 memory objects, processed
|
|
533
|
+
* asynchronously. Each object is the body of one `add()` (see
|
|
534
|
+
* `BatchMemory`): `content` and optionally `user_id`, `agent_id`, `run_id`,
|
|
535
|
+
* `metadata` and `timestamp`.
|
|
536
|
+
*
|
|
537
|
+
* `timestamp` means what it means on `add()`: when the events happened.
|
|
538
|
+
* The facts extracted from the item inherit it as `valid_from`, so a
|
|
539
|
+
* migration keeps its real dates; without it an item is dated when it is
|
|
540
|
+
* imported. A value that is not an ISO 8601 date or datetime refuses the
|
|
541
|
+
* whole batch before anything is queued: a 422 (APIError,
|
|
542
|
+
* `code === "invalid_request"`) whose message names the item, e.g.
|
|
543
|
+
* `memories[3].timestamp`. Any key not listed above is refused the same
|
|
544
|
+
* way. Servers older than 2026-09-28 refuse `timestamp` itself.
|
|
545
|
+
*/
|
|
546
|
+
batch(memories: Array<BatchMemory | Record<string, unknown>>): Promise<BatchJob>;
|
|
547
|
+
/** GET /v1/batch/:id: poll an import job. */
|
|
362
548
|
batchStatus(jobId: string): Promise<BatchJob>;
|
|
363
549
|
}
|
|
364
550
|
|
|
365
551
|
/**
|
|
366
|
-
* Typed errors
|
|
367
|
-
*
|
|
552
|
+
* Typed errors. Every error subclasses KorelyError, so a caller can catch
|
|
553
|
+
* everything with one `catch`.
|
|
554
|
+
*
|
|
555
|
+
* Every error the server answers with is an `APIError` carrying the stable
|
|
556
|
+
* `code` and the `message` of the REST error envelope; the common statuses
|
|
557
|
+
* also have their own subclass, so both styles work:
|
|
558
|
+
*
|
|
559
|
+
* if (e instanceof NotFoundError) ... // by class
|
|
560
|
+
* if (e instanceof APIError && e.code === "not_found") ... // by code
|
|
561
|
+
*
|
|
562
|
+
* A KorelyError that is not an APIError never reached the server, or got no
|
|
563
|
+
* usable answer: no API key, a key and address that do not belong together,
|
|
564
|
+
* a connection error or a timeout.
|
|
368
565
|
*/
|
|
369
566
|
interface KorelyErrorOptions {
|
|
370
567
|
status?: number;
|
|
@@ -375,32 +572,49 @@ declare class KorelyError extends Error {
|
|
|
375
572
|
readonly code?: string;
|
|
376
573
|
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
377
574
|
}
|
|
378
|
-
/**
|
|
379
|
-
|
|
575
|
+
/**
|
|
576
|
+
* The server answered with a non-2xx status. `status` is the HTTP status,
|
|
577
|
+
* `code` the stable error code (`invalid_key`, `not_found`, `quota_exceeded`,
|
|
578
|
+
* `search_unavailable` and so on). Anything without a subclass below (422
|
|
579
|
+
* validation, 503 unavailable, other 5xx) is a plain APIError.
|
|
580
|
+
*
|
|
581
|
+
* The subclasses were siblings of this class in 0.1.6 and earlier, so the pattern the
|
|
582
|
+
* public docs teach, `err instanceof APIError` and branch on `err.code`, let a
|
|
583
|
+
* 401, a 404 or a 429 through.
|
|
584
|
+
*/
|
|
585
|
+
declare class APIError extends KorelyError {
|
|
586
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
587
|
+
}
|
|
588
|
+
/** 401: missing, malformed, or revoked API key. */
|
|
589
|
+
declare class AuthenticationError extends APIError {
|
|
380
590
|
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
381
591
|
}
|
|
382
|
-
/**
|
|
383
|
-
|
|
592
|
+
/**
|
|
593
|
+
* 403: the key lacks a required scope, or the write would open an agent
|
|
594
|
+
* namespace past the plan's cap (`code === "agent_cap_exceeded"`).
|
|
595
|
+
*/
|
|
596
|
+
declare class NamespaceForbiddenError extends APIError {
|
|
384
597
|
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
385
598
|
}
|
|
386
|
-
/** 404
|
|
387
|
-
declare class NotFoundError extends
|
|
599
|
+
/** 404: memory or fact id does not exist, or was forgotten. */
|
|
600
|
+
declare class NotFoundError extends APIError {
|
|
388
601
|
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
389
602
|
}
|
|
390
|
-
/** 409
|
|
391
|
-
declare class StaleWriteError extends
|
|
603
|
+
/** 409: update() with an expected_updated_at older than the record. */
|
|
604
|
+
declare class StaleWriteError extends APIError {
|
|
392
605
|
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
393
606
|
}
|
|
394
|
-
/**
|
|
395
|
-
|
|
607
|
+
/**
|
|
608
|
+
* 429. `code === "rate_limit_exceeded"`: too many requests in a minute, hour
|
|
609
|
+
* or day, and `retryAfter` holds the seconds the server asked to wait.
|
|
610
|
+
* `code === "quota_exceeded"`: the monthly quota is used up, there is nothing
|
|
611
|
+
* to wait for this month, and `retryAfter` is undefined.
|
|
612
|
+
*/
|
|
613
|
+
declare class QuotaExceededError extends APIError {
|
|
396
614
|
readonly retryAfter?: number;
|
|
397
615
|
constructor(message?: string, opts?: KorelyErrorOptions & {
|
|
398
616
|
retryAfter?: number;
|
|
399
617
|
});
|
|
400
618
|
}
|
|
401
|
-
/** Any other non-2xx response (validation 422, server 5xx, …). */
|
|
402
|
-
declare class APIError extends KorelyError {
|
|
403
|
-
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
404
|
-
}
|
|
405
619
|
|
|
406
|
-
export { APIError, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentScope, type AgentsPage, AuthenticationError, type BatchJob, type BulkReceipt, type Context, type DeleteReceipt, type Fact, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|
|
620
|
+
export { APIError, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentScope, type AgentsPage, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, type Context, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
|