korely-memory 0.1.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/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/index.cjs +389 -0
- package/dist/index.d.cts +305 -0
- package/dist/index.d.ts +305 -0
- package/dist/index.js +354 -0
- package/package.json +48 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response shapes from the Korely REST API. Field names match the JSON the API
|
|
3
|
+
* returns (the same shapes documented in the API reference), so what you see in
|
|
4
|
+
* the docs is what you get on the object. Interfaces are open: a server that
|
|
5
|
+
* returns extra fields never breaks an old client.
|
|
6
|
+
*/
|
|
7
|
+
/** A chat message, accepted by `add()` as an alternative to a plain string. */
|
|
8
|
+
interface Message {
|
|
9
|
+
role?: string;
|
|
10
|
+
content?: string | null;
|
|
11
|
+
}
|
|
12
|
+
interface Fact {
|
|
13
|
+
id?: string;
|
|
14
|
+
subject?: string;
|
|
15
|
+
predicate?: string;
|
|
16
|
+
object?: string;
|
|
17
|
+
predicate_family?: string;
|
|
18
|
+
subject_type?: string;
|
|
19
|
+
predicate_raw?: string;
|
|
20
|
+
object_is_literal?: boolean;
|
|
21
|
+
confidence?: number;
|
|
22
|
+
user_id?: string;
|
|
23
|
+
agent_id?: string;
|
|
24
|
+
valid_from?: string;
|
|
25
|
+
invalid_at?: string;
|
|
26
|
+
invalidated_by?: string;
|
|
27
|
+
/** Write-shape only: ids this fact superseded (from add()/addFactTriple()). */
|
|
28
|
+
invalidated?: string[];
|
|
29
|
+
source_memory_id?: string;
|
|
30
|
+
created_at?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Memory {
|
|
33
|
+
id?: string;
|
|
34
|
+
content?: string;
|
|
35
|
+
user_id?: string;
|
|
36
|
+
agent_id?: string;
|
|
37
|
+
run_id?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
created_at?: string;
|
|
40
|
+
updated_at?: string;
|
|
41
|
+
/** Facts extracted from this memory on the write path. */
|
|
42
|
+
facts?: Fact[];
|
|
43
|
+
}
|
|
44
|
+
interface SearchHit {
|
|
45
|
+
id?: string;
|
|
46
|
+
score?: number;
|
|
47
|
+
snippet?: string;
|
|
48
|
+
user_id?: string;
|
|
49
|
+
agent_id?: string;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
interface MemoryPage {
|
|
53
|
+
memories: Memory[];
|
|
54
|
+
total: number;
|
|
55
|
+
}
|
|
56
|
+
interface DeleteReceipt {
|
|
57
|
+
id?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
facts_invalidated?: number;
|
|
60
|
+
audit_id?: string;
|
|
61
|
+
}
|
|
62
|
+
interface BulkReceipt {
|
|
63
|
+
user_id?: string;
|
|
64
|
+
memories_forgotten?: number;
|
|
65
|
+
facts_invalidated?: number;
|
|
66
|
+
audit_id?: string;
|
|
67
|
+
}
|
|
68
|
+
interface Context {
|
|
69
|
+
context: string;
|
|
70
|
+
tokens: number;
|
|
71
|
+
sources: string[];
|
|
72
|
+
}
|
|
73
|
+
interface BatchJob {
|
|
74
|
+
id?: string;
|
|
75
|
+
status?: string;
|
|
76
|
+
received?: number;
|
|
77
|
+
imported?: number;
|
|
78
|
+
failed?: number;
|
|
79
|
+
errors?: unknown[];
|
|
80
|
+
}
|
|
81
|
+
interface Profile {
|
|
82
|
+
user_id?: string;
|
|
83
|
+
as_of?: string | null;
|
|
84
|
+
/** The end user's own facts first, then the rest. */
|
|
85
|
+
facts: Fact[];
|
|
86
|
+
/** Facts grouped by predicate family. */
|
|
87
|
+
by_family: Record<string, Fact[]>;
|
|
88
|
+
total: number;
|
|
89
|
+
/** True when `total` exceeds the facts returned (the profile is capped at 200). */
|
|
90
|
+
truncated: boolean;
|
|
91
|
+
}
|
|
92
|
+
type HistoryEventType = "created" | "updated" | "fact_extracted" | "fact_invalidated" | "deleted";
|
|
93
|
+
interface HistoryEvent {
|
|
94
|
+
event?: HistoryEventType;
|
|
95
|
+
at?: string;
|
|
96
|
+
/** "subject predicate object" — set on fact events. */
|
|
97
|
+
fact?: string;
|
|
98
|
+
fact_id?: string;
|
|
99
|
+
}
|
|
100
|
+
interface MemoryHistory {
|
|
101
|
+
id?: string;
|
|
102
|
+
events: HistoryEvent[];
|
|
103
|
+
}
|
|
104
|
+
interface UserScope {
|
|
105
|
+
user_id?: string;
|
|
106
|
+
memories: number;
|
|
107
|
+
facts: number;
|
|
108
|
+
last_active?: string;
|
|
109
|
+
}
|
|
110
|
+
interface UsersPage {
|
|
111
|
+
users: UserScope[];
|
|
112
|
+
total: number;
|
|
113
|
+
}
|
|
114
|
+
interface AddOptions {
|
|
115
|
+
agent_id?: string;
|
|
116
|
+
user_id?: string;
|
|
117
|
+
run_id?: string;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface SearchOptions {
|
|
121
|
+
user_id?: string;
|
|
122
|
+
agent_id?: string;
|
|
123
|
+
limit?: number;
|
|
124
|
+
}
|
|
125
|
+
interface ListOptions {
|
|
126
|
+
user_id?: string;
|
|
127
|
+
agent_id?: string;
|
|
128
|
+
limit?: number;
|
|
129
|
+
offset?: number;
|
|
130
|
+
}
|
|
131
|
+
interface UpdateOptions {
|
|
132
|
+
content: string;
|
|
133
|
+
/** Optimistic concurrency: rejects (StaleWriteError) if it doesn't match. */
|
|
134
|
+
expected_updated_at?: string;
|
|
135
|
+
}
|
|
136
|
+
interface UsersOptions {
|
|
137
|
+
agent_id?: string;
|
|
138
|
+
limit?: number;
|
|
139
|
+
offset?: number;
|
|
140
|
+
}
|
|
141
|
+
interface GetFactsOptions {
|
|
142
|
+
subject?: string;
|
|
143
|
+
/** Matches the subject OR object side. */
|
|
144
|
+
entity?: string;
|
|
145
|
+
predicate?: string;
|
|
146
|
+
predicate_family?: string;
|
|
147
|
+
include_invalidated?: boolean;
|
|
148
|
+
/** ISO date — point-in-time validity ("what was true on 2026-06-01"). */
|
|
149
|
+
as_of?: string;
|
|
150
|
+
user_id?: string;
|
|
151
|
+
agent_id?: string;
|
|
152
|
+
limit?: number;
|
|
153
|
+
offset?: number;
|
|
154
|
+
}
|
|
155
|
+
interface AddFactTripleOptions {
|
|
156
|
+
user_id?: string;
|
|
157
|
+
agent_id?: string;
|
|
158
|
+
run_id?: string;
|
|
159
|
+
subject_type?: string;
|
|
160
|
+
object_is_literal?: boolean;
|
|
161
|
+
confidence?: number;
|
|
162
|
+
/** ISO date — for a historical fact. */
|
|
163
|
+
valid_from?: string;
|
|
164
|
+
}
|
|
165
|
+
interface GetProfileOptions {
|
|
166
|
+
user_id: string;
|
|
167
|
+
agent_id?: string;
|
|
168
|
+
/** ISO date — the profile as it stood on that date. */
|
|
169
|
+
as_of?: string;
|
|
170
|
+
}
|
|
171
|
+
interface GetContextOptions {
|
|
172
|
+
query: string;
|
|
173
|
+
user_id?: string;
|
|
174
|
+
agent_id?: string;
|
|
175
|
+
token_budget?: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare const VERSION = "0.1.0";
|
|
179
|
+
interface KorelyOptions {
|
|
180
|
+
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
181
|
+
apiKey?: string;
|
|
182
|
+
/** EU only for now (data stored and processed in the EU). */
|
|
183
|
+
region?: "eu";
|
|
184
|
+
/** Override the base URL (mainly for testing). */
|
|
185
|
+
baseUrl?: string;
|
|
186
|
+
/** Per-request timeout in milliseconds. Default 30000. */
|
|
187
|
+
timeoutMs?: number;
|
|
188
|
+
/** Inject a fetch implementation (mainly for testing / older runtimes). */
|
|
189
|
+
fetch?: typeof fetch;
|
|
190
|
+
}
|
|
191
|
+
declare class Korely {
|
|
192
|
+
readonly apiKey: string;
|
|
193
|
+
readonly baseUrl: string;
|
|
194
|
+
readonly timeoutMs: number;
|
|
195
|
+
private readonly fetchImpl;
|
|
196
|
+
constructor(opts?: KorelyOptions);
|
|
197
|
+
private request;
|
|
198
|
+
private raise;
|
|
199
|
+
/**
|
|
200
|
+
* POST /v1/memories — store a memory; resolves to it with extracted facts.
|
|
201
|
+
* `content` is a string, or a list of chat messages (role/content), joined
|
|
202
|
+
* into one block before sending.
|
|
203
|
+
*/
|
|
204
|
+
add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
|
|
205
|
+
/** POST /v1/memories/search — hybrid retrieval, ranked by score. */
|
|
206
|
+
search(query: string, opts?: SearchOptions): Promise<SearchHit[]>;
|
|
207
|
+
/** GET /v1/memories — list a scope, newest first. */
|
|
208
|
+
getAll(opts?: ListOptions): Promise<MemoryPage>;
|
|
209
|
+
/** GET /v1/memories/:id — full content, metadata, extracted facts. */
|
|
210
|
+
get(memoryId: string): Promise<Memory>;
|
|
211
|
+
/**
|
|
212
|
+
* PATCH /v1/memories/:id — re-runs extraction. Pass `expected_updated_at`
|
|
213
|
+
* for optimistic concurrency (throws StaleWriteError instead of clobbering).
|
|
214
|
+
*/
|
|
215
|
+
update(memoryId: string, opts: UpdateOptions): Promise<Memory>;
|
|
216
|
+
/** DELETE /v1/memories/:id — forget one memory (audited invalidation). */
|
|
217
|
+
delete(memoryId: string): Promise<DeleteReceipt>;
|
|
218
|
+
/**
|
|
219
|
+
* DELETE /v1/users/:user_id/memories — forget every memory + fact for one
|
|
220
|
+
* end user in a single call.
|
|
221
|
+
*/
|
|
222
|
+
deleteAll(opts: {
|
|
223
|
+
user_id: string;
|
|
224
|
+
}): Promise<BulkReceipt>;
|
|
225
|
+
/**
|
|
226
|
+
* GET /v1/memories/:id/history — the lifecycle timeline of a memory:
|
|
227
|
+
* created / updated / deleted, plus every typed fact it produced.
|
|
228
|
+
*/
|
|
229
|
+
history(memoryId: string): Promise<MemoryHistory>;
|
|
230
|
+
/**
|
|
231
|
+
* GET /v1/users — the end users you've stored data for (distinct user_id
|
|
232
|
+
* namespaces), each with active memory + fact counts and last-active time.
|
|
233
|
+
*/
|
|
234
|
+
users(opts?: UsersOptions): Promise<UsersPage>;
|
|
235
|
+
/**
|
|
236
|
+
* GET /v1/facts — typed (subject, predicate, object) triples with bi-temporal
|
|
237
|
+
* validity. Pass `as_of` (ISO date) for a point-in-time query.
|
|
238
|
+
*/
|
|
239
|
+
getFacts(opts?: GetFactsOptions): Promise<Fact[]>;
|
|
240
|
+
/**
|
|
241
|
+
* POST /v1/facts — write a typed (subject, predicate, object) triple directly,
|
|
242
|
+
* skipping extraction. The server runs the contradiction check; the fact is
|
|
243
|
+
* bi-temporal (pass `valid_from` for a historical fact). Resolves to the
|
|
244
|
+
* written Fact, with `invalidated` listing any fact ids it superseded.
|
|
245
|
+
*/
|
|
246
|
+
addFactTriple(subject: string, predicate: string, object: string, opts?: AddFactTripleOptions): Promise<Fact>;
|
|
247
|
+
/**
|
|
248
|
+
* GET /v1/profile — the assembled profile of one end user: the active typed
|
|
249
|
+
* facts known about them, the end user's own facts first, grouped by family.
|
|
250
|
+
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
251
|
+
*/
|
|
252
|
+
getProfile(opts: GetProfileOptions): Promise<Profile>;
|
|
253
|
+
/**
|
|
254
|
+
* GET /v1/context — one call that assembles a prompt-ready context block
|
|
255
|
+
* (profile + relevant facts + memories) within a token budget.
|
|
256
|
+
*/
|
|
257
|
+
getContext(opts: GetContextOptions): Promise<Context>;
|
|
258
|
+
/** POST /v1/batch — bulk import (up to 500 memory objects), async. */
|
|
259
|
+
batch(memories: Array<Record<string, unknown>>): Promise<BatchJob>;
|
|
260
|
+
/** GET /v1/batch/:id — poll an import job. */
|
|
261
|
+
batchStatus(jobId: string): Promise<BatchJob>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Typed errors mapping 1:1 onto the REST error codes. Every error subclasses
|
|
266
|
+
* KorelyError, so a caller can catch everything with one `catch`.
|
|
267
|
+
*/
|
|
268
|
+
interface KorelyErrorOptions {
|
|
269
|
+
status?: number;
|
|
270
|
+
code?: string;
|
|
271
|
+
}
|
|
272
|
+
declare class KorelyError extends Error {
|
|
273
|
+
readonly status?: number;
|
|
274
|
+
readonly code?: string;
|
|
275
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
276
|
+
}
|
|
277
|
+
/** 401 — missing, malformed, or revoked API key. */
|
|
278
|
+
declare class AuthenticationError extends KorelyError {
|
|
279
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
280
|
+
}
|
|
281
|
+
/** 403 — the key lacks the scope required for this call. */
|
|
282
|
+
declare class NamespaceForbiddenError extends KorelyError {
|
|
283
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
284
|
+
}
|
|
285
|
+
/** 404 — memory or fact id does not exist, or was forgotten. */
|
|
286
|
+
declare class NotFoundError extends KorelyError {
|
|
287
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
288
|
+
}
|
|
289
|
+
/** 409 — update() with an expected_updated_at older than the record. */
|
|
290
|
+
declare class StaleWriteError extends KorelyError {
|
|
291
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
292
|
+
}
|
|
293
|
+
/** 429 — past the soft cap. `retryAfter` is in seconds when the server sent it. */
|
|
294
|
+
declare class QuotaExceededError extends KorelyError {
|
|
295
|
+
readonly retryAfter?: number;
|
|
296
|
+
constructor(message?: string, opts?: KorelyErrorOptions & {
|
|
297
|
+
retryAfter?: number;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/** Any other non-2xx response (validation 422, server 5xx, …). */
|
|
301
|
+
declare class APIError extends KorelyError {
|
|
302
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { APIError, type AddFactTripleOptions, type AddOptions, 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 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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response shapes from the Korely REST API. Field names match the JSON the API
|
|
3
|
+
* returns (the same shapes documented in the API reference), so what you see in
|
|
4
|
+
* the docs is what you get on the object. Interfaces are open: a server that
|
|
5
|
+
* returns extra fields never breaks an old client.
|
|
6
|
+
*/
|
|
7
|
+
/** A chat message, accepted by `add()` as an alternative to a plain string. */
|
|
8
|
+
interface Message {
|
|
9
|
+
role?: string;
|
|
10
|
+
content?: string | null;
|
|
11
|
+
}
|
|
12
|
+
interface Fact {
|
|
13
|
+
id?: string;
|
|
14
|
+
subject?: string;
|
|
15
|
+
predicate?: string;
|
|
16
|
+
object?: string;
|
|
17
|
+
predicate_family?: string;
|
|
18
|
+
subject_type?: string;
|
|
19
|
+
predicate_raw?: string;
|
|
20
|
+
object_is_literal?: boolean;
|
|
21
|
+
confidence?: number;
|
|
22
|
+
user_id?: string;
|
|
23
|
+
agent_id?: string;
|
|
24
|
+
valid_from?: string;
|
|
25
|
+
invalid_at?: string;
|
|
26
|
+
invalidated_by?: string;
|
|
27
|
+
/** Write-shape only: ids this fact superseded (from add()/addFactTriple()). */
|
|
28
|
+
invalidated?: string[];
|
|
29
|
+
source_memory_id?: string;
|
|
30
|
+
created_at?: string;
|
|
31
|
+
}
|
|
32
|
+
interface Memory {
|
|
33
|
+
id?: string;
|
|
34
|
+
content?: string;
|
|
35
|
+
user_id?: string;
|
|
36
|
+
agent_id?: string;
|
|
37
|
+
run_id?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
created_at?: string;
|
|
40
|
+
updated_at?: string;
|
|
41
|
+
/** Facts extracted from this memory on the write path. */
|
|
42
|
+
facts?: Fact[];
|
|
43
|
+
}
|
|
44
|
+
interface SearchHit {
|
|
45
|
+
id?: string;
|
|
46
|
+
score?: number;
|
|
47
|
+
snippet?: string;
|
|
48
|
+
user_id?: string;
|
|
49
|
+
agent_id?: string;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
interface MemoryPage {
|
|
53
|
+
memories: Memory[];
|
|
54
|
+
total: number;
|
|
55
|
+
}
|
|
56
|
+
interface DeleteReceipt {
|
|
57
|
+
id?: string;
|
|
58
|
+
status?: string;
|
|
59
|
+
facts_invalidated?: number;
|
|
60
|
+
audit_id?: string;
|
|
61
|
+
}
|
|
62
|
+
interface BulkReceipt {
|
|
63
|
+
user_id?: string;
|
|
64
|
+
memories_forgotten?: number;
|
|
65
|
+
facts_invalidated?: number;
|
|
66
|
+
audit_id?: string;
|
|
67
|
+
}
|
|
68
|
+
interface Context {
|
|
69
|
+
context: string;
|
|
70
|
+
tokens: number;
|
|
71
|
+
sources: string[];
|
|
72
|
+
}
|
|
73
|
+
interface BatchJob {
|
|
74
|
+
id?: string;
|
|
75
|
+
status?: string;
|
|
76
|
+
received?: number;
|
|
77
|
+
imported?: number;
|
|
78
|
+
failed?: number;
|
|
79
|
+
errors?: unknown[];
|
|
80
|
+
}
|
|
81
|
+
interface Profile {
|
|
82
|
+
user_id?: string;
|
|
83
|
+
as_of?: string | null;
|
|
84
|
+
/** The end user's own facts first, then the rest. */
|
|
85
|
+
facts: Fact[];
|
|
86
|
+
/** Facts grouped by predicate family. */
|
|
87
|
+
by_family: Record<string, Fact[]>;
|
|
88
|
+
total: number;
|
|
89
|
+
/** True when `total` exceeds the facts returned (the profile is capped at 200). */
|
|
90
|
+
truncated: boolean;
|
|
91
|
+
}
|
|
92
|
+
type HistoryEventType = "created" | "updated" | "fact_extracted" | "fact_invalidated" | "deleted";
|
|
93
|
+
interface HistoryEvent {
|
|
94
|
+
event?: HistoryEventType;
|
|
95
|
+
at?: string;
|
|
96
|
+
/** "subject predicate object" — set on fact events. */
|
|
97
|
+
fact?: string;
|
|
98
|
+
fact_id?: string;
|
|
99
|
+
}
|
|
100
|
+
interface MemoryHistory {
|
|
101
|
+
id?: string;
|
|
102
|
+
events: HistoryEvent[];
|
|
103
|
+
}
|
|
104
|
+
interface UserScope {
|
|
105
|
+
user_id?: string;
|
|
106
|
+
memories: number;
|
|
107
|
+
facts: number;
|
|
108
|
+
last_active?: string;
|
|
109
|
+
}
|
|
110
|
+
interface UsersPage {
|
|
111
|
+
users: UserScope[];
|
|
112
|
+
total: number;
|
|
113
|
+
}
|
|
114
|
+
interface AddOptions {
|
|
115
|
+
agent_id?: string;
|
|
116
|
+
user_id?: string;
|
|
117
|
+
run_id?: string;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface SearchOptions {
|
|
121
|
+
user_id?: string;
|
|
122
|
+
agent_id?: string;
|
|
123
|
+
limit?: number;
|
|
124
|
+
}
|
|
125
|
+
interface ListOptions {
|
|
126
|
+
user_id?: string;
|
|
127
|
+
agent_id?: string;
|
|
128
|
+
limit?: number;
|
|
129
|
+
offset?: number;
|
|
130
|
+
}
|
|
131
|
+
interface UpdateOptions {
|
|
132
|
+
content: string;
|
|
133
|
+
/** Optimistic concurrency: rejects (StaleWriteError) if it doesn't match. */
|
|
134
|
+
expected_updated_at?: string;
|
|
135
|
+
}
|
|
136
|
+
interface UsersOptions {
|
|
137
|
+
agent_id?: string;
|
|
138
|
+
limit?: number;
|
|
139
|
+
offset?: number;
|
|
140
|
+
}
|
|
141
|
+
interface GetFactsOptions {
|
|
142
|
+
subject?: string;
|
|
143
|
+
/** Matches the subject OR object side. */
|
|
144
|
+
entity?: string;
|
|
145
|
+
predicate?: string;
|
|
146
|
+
predicate_family?: string;
|
|
147
|
+
include_invalidated?: boolean;
|
|
148
|
+
/** ISO date — point-in-time validity ("what was true on 2026-06-01"). */
|
|
149
|
+
as_of?: string;
|
|
150
|
+
user_id?: string;
|
|
151
|
+
agent_id?: string;
|
|
152
|
+
limit?: number;
|
|
153
|
+
offset?: number;
|
|
154
|
+
}
|
|
155
|
+
interface AddFactTripleOptions {
|
|
156
|
+
user_id?: string;
|
|
157
|
+
agent_id?: string;
|
|
158
|
+
run_id?: string;
|
|
159
|
+
subject_type?: string;
|
|
160
|
+
object_is_literal?: boolean;
|
|
161
|
+
confidence?: number;
|
|
162
|
+
/** ISO date — for a historical fact. */
|
|
163
|
+
valid_from?: string;
|
|
164
|
+
}
|
|
165
|
+
interface GetProfileOptions {
|
|
166
|
+
user_id: string;
|
|
167
|
+
agent_id?: string;
|
|
168
|
+
/** ISO date — the profile as it stood on that date. */
|
|
169
|
+
as_of?: string;
|
|
170
|
+
}
|
|
171
|
+
interface GetContextOptions {
|
|
172
|
+
query: string;
|
|
173
|
+
user_id?: string;
|
|
174
|
+
agent_id?: string;
|
|
175
|
+
token_budget?: number;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare const VERSION = "0.1.0";
|
|
179
|
+
interface KorelyOptions {
|
|
180
|
+
/** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
|
|
181
|
+
apiKey?: string;
|
|
182
|
+
/** EU only for now (data stored and processed in the EU). */
|
|
183
|
+
region?: "eu";
|
|
184
|
+
/** Override the base URL (mainly for testing). */
|
|
185
|
+
baseUrl?: string;
|
|
186
|
+
/** Per-request timeout in milliseconds. Default 30000. */
|
|
187
|
+
timeoutMs?: number;
|
|
188
|
+
/** Inject a fetch implementation (mainly for testing / older runtimes). */
|
|
189
|
+
fetch?: typeof fetch;
|
|
190
|
+
}
|
|
191
|
+
declare class Korely {
|
|
192
|
+
readonly apiKey: string;
|
|
193
|
+
readonly baseUrl: string;
|
|
194
|
+
readonly timeoutMs: number;
|
|
195
|
+
private readonly fetchImpl;
|
|
196
|
+
constructor(opts?: KorelyOptions);
|
|
197
|
+
private request;
|
|
198
|
+
private raise;
|
|
199
|
+
/**
|
|
200
|
+
* POST /v1/memories — store a memory; resolves to it with extracted facts.
|
|
201
|
+
* `content` is a string, or a list of chat messages (role/content), joined
|
|
202
|
+
* into one block before sending.
|
|
203
|
+
*/
|
|
204
|
+
add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
|
|
205
|
+
/** POST /v1/memories/search — hybrid retrieval, ranked by score. */
|
|
206
|
+
search(query: string, opts?: SearchOptions): Promise<SearchHit[]>;
|
|
207
|
+
/** GET /v1/memories — list a scope, newest first. */
|
|
208
|
+
getAll(opts?: ListOptions): Promise<MemoryPage>;
|
|
209
|
+
/** GET /v1/memories/:id — full content, metadata, extracted facts. */
|
|
210
|
+
get(memoryId: string): Promise<Memory>;
|
|
211
|
+
/**
|
|
212
|
+
* PATCH /v1/memories/:id — re-runs extraction. Pass `expected_updated_at`
|
|
213
|
+
* for optimistic concurrency (throws StaleWriteError instead of clobbering).
|
|
214
|
+
*/
|
|
215
|
+
update(memoryId: string, opts: UpdateOptions): Promise<Memory>;
|
|
216
|
+
/** DELETE /v1/memories/:id — forget one memory (audited invalidation). */
|
|
217
|
+
delete(memoryId: string): Promise<DeleteReceipt>;
|
|
218
|
+
/**
|
|
219
|
+
* DELETE /v1/users/:user_id/memories — forget every memory + fact for one
|
|
220
|
+
* end user in a single call.
|
|
221
|
+
*/
|
|
222
|
+
deleteAll(opts: {
|
|
223
|
+
user_id: string;
|
|
224
|
+
}): Promise<BulkReceipt>;
|
|
225
|
+
/**
|
|
226
|
+
* GET /v1/memories/:id/history — the lifecycle timeline of a memory:
|
|
227
|
+
* created / updated / deleted, plus every typed fact it produced.
|
|
228
|
+
*/
|
|
229
|
+
history(memoryId: string): Promise<MemoryHistory>;
|
|
230
|
+
/**
|
|
231
|
+
* GET /v1/users — the end users you've stored data for (distinct user_id
|
|
232
|
+
* namespaces), each with active memory + fact counts and last-active time.
|
|
233
|
+
*/
|
|
234
|
+
users(opts?: UsersOptions): Promise<UsersPage>;
|
|
235
|
+
/**
|
|
236
|
+
* GET /v1/facts — typed (subject, predicate, object) triples with bi-temporal
|
|
237
|
+
* validity. Pass `as_of` (ISO date) for a point-in-time query.
|
|
238
|
+
*/
|
|
239
|
+
getFacts(opts?: GetFactsOptions): Promise<Fact[]>;
|
|
240
|
+
/**
|
|
241
|
+
* POST /v1/facts — write a typed (subject, predicate, object) triple directly,
|
|
242
|
+
* skipping extraction. The server runs the contradiction check; the fact is
|
|
243
|
+
* bi-temporal (pass `valid_from` for a historical fact). Resolves to the
|
|
244
|
+
* written Fact, with `invalidated` listing any fact ids it superseded.
|
|
245
|
+
*/
|
|
246
|
+
addFactTriple(subject: string, predicate: string, object: string, opts?: AddFactTripleOptions): Promise<Fact>;
|
|
247
|
+
/**
|
|
248
|
+
* GET /v1/profile — the assembled profile of one end user: the active typed
|
|
249
|
+
* facts known about them, the end user's own facts first, grouped by family.
|
|
250
|
+
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
251
|
+
*/
|
|
252
|
+
getProfile(opts: GetProfileOptions): Promise<Profile>;
|
|
253
|
+
/**
|
|
254
|
+
* GET /v1/context — one call that assembles a prompt-ready context block
|
|
255
|
+
* (profile + relevant facts + memories) within a token budget.
|
|
256
|
+
*/
|
|
257
|
+
getContext(opts: GetContextOptions): Promise<Context>;
|
|
258
|
+
/** POST /v1/batch — bulk import (up to 500 memory objects), async. */
|
|
259
|
+
batch(memories: Array<Record<string, unknown>>): Promise<BatchJob>;
|
|
260
|
+
/** GET /v1/batch/:id — poll an import job. */
|
|
261
|
+
batchStatus(jobId: string): Promise<BatchJob>;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Typed errors mapping 1:1 onto the REST error codes. Every error subclasses
|
|
266
|
+
* KorelyError, so a caller can catch everything with one `catch`.
|
|
267
|
+
*/
|
|
268
|
+
interface KorelyErrorOptions {
|
|
269
|
+
status?: number;
|
|
270
|
+
code?: string;
|
|
271
|
+
}
|
|
272
|
+
declare class KorelyError extends Error {
|
|
273
|
+
readonly status?: number;
|
|
274
|
+
readonly code?: string;
|
|
275
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
276
|
+
}
|
|
277
|
+
/** 401 — missing, malformed, or revoked API key. */
|
|
278
|
+
declare class AuthenticationError extends KorelyError {
|
|
279
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
280
|
+
}
|
|
281
|
+
/** 403 — the key lacks the scope required for this call. */
|
|
282
|
+
declare class NamespaceForbiddenError extends KorelyError {
|
|
283
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
284
|
+
}
|
|
285
|
+
/** 404 — memory or fact id does not exist, or was forgotten. */
|
|
286
|
+
declare class NotFoundError extends KorelyError {
|
|
287
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
288
|
+
}
|
|
289
|
+
/** 409 — update() with an expected_updated_at older than the record. */
|
|
290
|
+
declare class StaleWriteError extends KorelyError {
|
|
291
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
292
|
+
}
|
|
293
|
+
/** 429 — past the soft cap. `retryAfter` is in seconds when the server sent it. */
|
|
294
|
+
declare class QuotaExceededError extends KorelyError {
|
|
295
|
+
readonly retryAfter?: number;
|
|
296
|
+
constructor(message?: string, opts?: KorelyErrorOptions & {
|
|
297
|
+
retryAfter?: number;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/** Any other non-2xx response (validation 422, server 5xx, …). */
|
|
301
|
+
declare class APIError extends KorelyError {
|
|
302
|
+
constructor(message?: string, opts?: KorelyErrorOptions);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { APIError, type AddFactTripleOptions, type AddOptions, 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 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 };
|