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