korely-memory 0.1.4 → 0.1.6
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/dist/index.cjs +76 -7
- package/dist/index.d.cts +45 -2
- package/dist/index.d.ts +45 -2
- package/dist/index.js +76 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -109,6 +109,37 @@ function coerceContent(content) {
|
|
|
109
109
|
}
|
|
110
110
|
return String(content);
|
|
111
111
|
}
|
|
112
|
+
function iterableOver(page, key) {
|
|
113
|
+
const out = page;
|
|
114
|
+
Object.defineProperty(out, Symbol.iterator, {
|
|
115
|
+
value: () => (page[key] ?? [])[Symbol.iterator](),
|
|
116
|
+
enumerable: false
|
|
117
|
+
});
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
var OUR_HOSTS = ["korely.ai"];
|
|
121
|
+
function isOurs(baseUrl) {
|
|
122
|
+
let host = "";
|
|
123
|
+
try {
|
|
124
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return OUR_HOSTS.some((h) => host === h || host.endsWith("." + h));
|
|
129
|
+
}
|
|
130
|
+
function refuseAMismatchedPair(apiKey, baseUrl) {
|
|
131
|
+
const ours = isOurs(baseUrl);
|
|
132
|
+
if (apiKey.startsWith("kor_self_") && ours) {
|
|
133
|
+
throw new KorelyError(
|
|
134
|
+
`This key was issued by an install you run yourself (kor_self_), and ${baseUrl} is the hosted Korely service. It would be refused there, but the memory would arrive first. Point baseUrl at your own server, or set KORELY_BASE_URL.`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (apiKey.startsWith("kor_live_") && !ours) {
|
|
138
|
+
throw new KorelyError(
|
|
139
|
+
`This key was issued by the hosted Korely service (kor_live_), and ${baseUrl} is not it. Sending it there hands a credential we issued to a machine that is not ours. Use a key minted by that install (kor_self_), or drop baseUrl to reach the hosted service.`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
112
143
|
var Korely = class {
|
|
113
144
|
constructor(opts = {}) {
|
|
114
145
|
const envKey = typeof process !== "undefined" ? process.env?.KORELY_API_KEY : void 0;
|
|
@@ -121,6 +152,7 @@ var Korely = class {
|
|
|
121
152
|
this.apiKey = key;
|
|
122
153
|
const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
|
|
123
154
|
this.baseUrl = (opts.baseUrl ?? envBase ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
|
|
155
|
+
refuseAMismatchedPair(this.apiKey, this.baseUrl);
|
|
124
156
|
this.timeoutMs = opts.timeoutMs ?? 3e4;
|
|
125
157
|
const f = opts.fetch ?? globalThis.fetch;
|
|
126
158
|
if (!f) {
|
|
@@ -291,13 +323,18 @@ var Korely = class {
|
|
|
291
323
|
* namespaces), each with active memory + fact counts and last-active time.
|
|
292
324
|
*/
|
|
293
325
|
async users(opts = {}) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
326
|
+
const page = await this.request(
|
|
327
|
+
"GET",
|
|
328
|
+
"/v1/users",
|
|
329
|
+
{
|
|
330
|
+
params: {
|
|
331
|
+
agent_id: opts.agent_id,
|
|
332
|
+
limit: opts.limit ?? 50,
|
|
333
|
+
offset: opts.offset ?? 0
|
|
334
|
+
}
|
|
299
335
|
}
|
|
300
|
-
|
|
336
|
+
);
|
|
337
|
+
return iterableOver(page, "users");
|
|
301
338
|
}
|
|
302
339
|
// ── agents ────────────────────────────────────────────────────────────────
|
|
303
340
|
/**
|
|
@@ -309,12 +346,13 @@ var Korely = class {
|
|
|
309
346
|
* reuse one instead of minting a new id.
|
|
310
347
|
*/
|
|
311
348
|
async listAgents(opts = {}) {
|
|
312
|
-
|
|
349
|
+
const page = await this.request("GET", "/v1/agents", {
|
|
313
350
|
params: {
|
|
314
351
|
limit: opts.limit ?? 50,
|
|
315
352
|
offset: opts.offset ?? 0
|
|
316
353
|
}
|
|
317
354
|
});
|
|
355
|
+
return iterableOver(page, "agents");
|
|
318
356
|
}
|
|
319
357
|
/**
|
|
320
358
|
* DELETE /v1/agents/:agent_id — hard-delete an agent namespace: purge every
|
|
@@ -373,6 +411,37 @@ var Korely = class {
|
|
|
373
411
|
* facts known about them, the end user's own facts first, grouped by family.
|
|
374
412
|
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
375
413
|
*/
|
|
414
|
+
/**
|
|
415
|
+
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
416
|
+
* in history.
|
|
417
|
+
*
|
|
418
|
+
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
419
|
+
* `as_of` a date before it still returns the fact, which is the reason
|
|
420
|
+
* history is kept rather than rows deleted.
|
|
421
|
+
*
|
|
422
|
+
* Idempotent: closing an already-closed fact changes nothing and comes back
|
|
423
|
+
* with `status === "already_forgotten"`.
|
|
424
|
+
*
|
|
425
|
+
* This is the half that makes a no-model write path possible: an agent that
|
|
426
|
+
* knows a fact is finished says so, and nothing has to infer it.
|
|
427
|
+
*/
|
|
428
|
+
async forgetFact(factId, opts = {}) {
|
|
429
|
+
return this.request("POST", `/v1/facts/${encodeURIComponent(factId)}/forget`, {
|
|
430
|
+
body: { at: opts.at }
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* PATCH /v1/facts/:id — supersede a fact with a corrected one.
|
|
435
|
+
*
|
|
436
|
+
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
437
|
+
* one, so `as_of` before the correction still returns what you believed then.
|
|
438
|
+
* At least one of the three fields is required.
|
|
439
|
+
*/
|
|
440
|
+
async correctFact(factId, changes) {
|
|
441
|
+
return this.request("PATCH", `/v1/facts/${encodeURIComponent(factId)}`, {
|
|
442
|
+
body: changes
|
|
443
|
+
});
|
|
444
|
+
}
|
|
376
445
|
async getProfile(opts) {
|
|
377
446
|
return this.request("GET", "/v1/profile", {
|
|
378
447
|
params: {
|
package/dist/index.d.cts
CHANGED
|
@@ -114,7 +114,12 @@ interface UserScope {
|
|
|
114
114
|
facts: number;
|
|
115
115
|
last_active?: string;
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
/** Iterable, like the Python SDK's UsersPage, so `for (const u of page)`
|
|
118
|
+
* works and `page.users` / `page.total` still do. The two SDKs claim to be
|
|
119
|
+
* "the same idea" and this was the one place a reader could see they were
|
|
120
|
+
* not: Python handed back something you iterate, Node handed back a wrapper.
|
|
121
|
+
* Adding the iterator keeps every existing caller working. */
|
|
122
|
+
interface UsersPage extends Iterable<UserScope> {
|
|
118
123
|
users: UserScope[];
|
|
119
124
|
total: number;
|
|
120
125
|
}
|
|
@@ -124,7 +129,7 @@ interface AgentScope {
|
|
|
124
129
|
facts: number;
|
|
125
130
|
last_active?: string;
|
|
126
131
|
}
|
|
127
|
-
interface AgentsPage {
|
|
132
|
+
interface AgentsPage extends Iterable<AgentScope> {
|
|
128
133
|
agents: AgentScope[];
|
|
129
134
|
/** Distinct agent namespaces == `used` slots. */
|
|
130
135
|
total: number;
|
|
@@ -212,6 +217,15 @@ interface GetContextOptions {
|
|
|
212
217
|
agent_id?: string;
|
|
213
218
|
token_budget?: number;
|
|
214
219
|
}
|
|
220
|
+
/** What `forgetFact` gives back. `status` is "forgotten" the first time and
|
|
221
|
+
* "already_forgotten" afterwards; `invalid_at` is the date it stopped being
|
|
222
|
+
* true, which is the one you passed if you passed one. */
|
|
223
|
+
interface ForgetReceipt {
|
|
224
|
+
id: string;
|
|
225
|
+
status: "forgotten" | "already_forgotten";
|
|
226
|
+
invalid_at?: string | null;
|
|
227
|
+
audit_id?: string | null;
|
|
228
|
+
}
|
|
215
229
|
|
|
216
230
|
declare const VERSION = "0.1.1";
|
|
217
231
|
interface KorelyOptions {
|
|
@@ -307,6 +321,35 @@ declare class Korely {
|
|
|
307
321
|
* facts known about them, the end user's own facts first, grouped by family.
|
|
308
322
|
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
309
323
|
*/
|
|
324
|
+
/**
|
|
325
|
+
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
326
|
+
* in history.
|
|
327
|
+
*
|
|
328
|
+
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
329
|
+
* `as_of` a date before it still returns the fact, which is the reason
|
|
330
|
+
* history is kept rather than rows deleted.
|
|
331
|
+
*
|
|
332
|
+
* Idempotent: closing an already-closed fact changes nothing and comes back
|
|
333
|
+
* with `status === "already_forgotten"`.
|
|
334
|
+
*
|
|
335
|
+
* This is the half that makes a no-model write path possible: an agent that
|
|
336
|
+
* knows a fact is finished says so, and nothing has to infer it.
|
|
337
|
+
*/
|
|
338
|
+
forgetFact(factId: string, opts?: {
|
|
339
|
+
at?: string;
|
|
340
|
+
}): Promise<ForgetReceipt>;
|
|
341
|
+
/**
|
|
342
|
+
* PATCH /v1/facts/:id — supersede a fact with a corrected one.
|
|
343
|
+
*
|
|
344
|
+
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
345
|
+
* one, so `as_of` before the correction still returns what you believed then.
|
|
346
|
+
* At least one of the three fields is required.
|
|
347
|
+
*/
|
|
348
|
+
correctFact(factId: string, changes: {
|
|
349
|
+
subject?: string;
|
|
350
|
+
predicate?: string;
|
|
351
|
+
object?: string;
|
|
352
|
+
}): Promise<Fact>;
|
|
310
353
|
getProfile(opts: GetProfileOptions): Promise<Profile>;
|
|
311
354
|
/**
|
|
312
355
|
* GET /v1/context — one call that assembles a prompt-ready context block
|
package/dist/index.d.ts
CHANGED
|
@@ -114,7 +114,12 @@ interface UserScope {
|
|
|
114
114
|
facts: number;
|
|
115
115
|
last_active?: string;
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
/** Iterable, like the Python SDK's UsersPage, so `for (const u of page)`
|
|
118
|
+
* works and `page.users` / `page.total` still do. The two SDKs claim to be
|
|
119
|
+
* "the same idea" and this was the one place a reader could see they were
|
|
120
|
+
* not: Python handed back something you iterate, Node handed back a wrapper.
|
|
121
|
+
* Adding the iterator keeps every existing caller working. */
|
|
122
|
+
interface UsersPage extends Iterable<UserScope> {
|
|
118
123
|
users: UserScope[];
|
|
119
124
|
total: number;
|
|
120
125
|
}
|
|
@@ -124,7 +129,7 @@ interface AgentScope {
|
|
|
124
129
|
facts: number;
|
|
125
130
|
last_active?: string;
|
|
126
131
|
}
|
|
127
|
-
interface AgentsPage {
|
|
132
|
+
interface AgentsPage extends Iterable<AgentScope> {
|
|
128
133
|
agents: AgentScope[];
|
|
129
134
|
/** Distinct agent namespaces == `used` slots. */
|
|
130
135
|
total: number;
|
|
@@ -212,6 +217,15 @@ interface GetContextOptions {
|
|
|
212
217
|
agent_id?: string;
|
|
213
218
|
token_budget?: number;
|
|
214
219
|
}
|
|
220
|
+
/** What `forgetFact` gives back. `status` is "forgotten" the first time and
|
|
221
|
+
* "already_forgotten" afterwards; `invalid_at` is the date it stopped being
|
|
222
|
+
* true, which is the one you passed if you passed one. */
|
|
223
|
+
interface ForgetReceipt {
|
|
224
|
+
id: string;
|
|
225
|
+
status: "forgotten" | "already_forgotten";
|
|
226
|
+
invalid_at?: string | null;
|
|
227
|
+
audit_id?: string | null;
|
|
228
|
+
}
|
|
215
229
|
|
|
216
230
|
declare const VERSION = "0.1.1";
|
|
217
231
|
interface KorelyOptions {
|
|
@@ -307,6 +321,35 @@ declare class Korely {
|
|
|
307
321
|
* facts known about them, the end user's own facts first, grouped by family.
|
|
308
322
|
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
309
323
|
*/
|
|
324
|
+
/**
|
|
325
|
+
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
326
|
+
* in history.
|
|
327
|
+
*
|
|
328
|
+
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
329
|
+
* `as_of` a date before it still returns the fact, which is the reason
|
|
330
|
+
* history is kept rather than rows deleted.
|
|
331
|
+
*
|
|
332
|
+
* Idempotent: closing an already-closed fact changes nothing and comes back
|
|
333
|
+
* with `status === "already_forgotten"`.
|
|
334
|
+
*
|
|
335
|
+
* This is the half that makes a no-model write path possible: an agent that
|
|
336
|
+
* knows a fact is finished says so, and nothing has to infer it.
|
|
337
|
+
*/
|
|
338
|
+
forgetFact(factId: string, opts?: {
|
|
339
|
+
at?: string;
|
|
340
|
+
}): Promise<ForgetReceipt>;
|
|
341
|
+
/**
|
|
342
|
+
* PATCH /v1/facts/:id — supersede a fact with a corrected one.
|
|
343
|
+
*
|
|
344
|
+
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
345
|
+
* one, so `as_of` before the correction still returns what you believed then.
|
|
346
|
+
* At least one of the three fields is required.
|
|
347
|
+
*/
|
|
348
|
+
correctFact(factId: string, changes: {
|
|
349
|
+
subject?: string;
|
|
350
|
+
predicate?: string;
|
|
351
|
+
object?: string;
|
|
352
|
+
}): Promise<Fact>;
|
|
310
353
|
getProfile(opts: GetProfileOptions): Promise<Profile>;
|
|
311
354
|
/**
|
|
312
355
|
* GET /v1/context — one call that assembles a prompt-ready context block
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,37 @@ function coerceContent(content) {
|
|
|
75
75
|
}
|
|
76
76
|
return String(content);
|
|
77
77
|
}
|
|
78
|
+
function iterableOver(page, key) {
|
|
79
|
+
const out = page;
|
|
80
|
+
Object.defineProperty(out, Symbol.iterator, {
|
|
81
|
+
value: () => (page[key] ?? [])[Symbol.iterator](),
|
|
82
|
+
enumerable: false
|
|
83
|
+
});
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
var OUR_HOSTS = ["korely.ai"];
|
|
87
|
+
function isOurs(baseUrl) {
|
|
88
|
+
let host = "";
|
|
89
|
+
try {
|
|
90
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
91
|
+
} catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return OUR_HOSTS.some((h) => host === h || host.endsWith("." + h));
|
|
95
|
+
}
|
|
96
|
+
function refuseAMismatchedPair(apiKey, baseUrl) {
|
|
97
|
+
const ours = isOurs(baseUrl);
|
|
98
|
+
if (apiKey.startsWith("kor_self_") && ours) {
|
|
99
|
+
throw new KorelyError(
|
|
100
|
+
`This key was issued by an install you run yourself (kor_self_), and ${baseUrl} is the hosted Korely service. It would be refused there, but the memory would arrive first. Point baseUrl at your own server, or set KORELY_BASE_URL.`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (apiKey.startsWith("kor_live_") && !ours) {
|
|
104
|
+
throw new KorelyError(
|
|
105
|
+
`This key was issued by the hosted Korely service (kor_live_), and ${baseUrl} is not it. Sending it there hands a credential we issued to a machine that is not ours. Use a key minted by that install (kor_self_), or drop baseUrl to reach the hosted service.`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
78
109
|
var Korely = class {
|
|
79
110
|
constructor(opts = {}) {
|
|
80
111
|
const envKey = typeof process !== "undefined" ? process.env?.KORELY_API_KEY : void 0;
|
|
@@ -87,6 +118,7 @@ var Korely = class {
|
|
|
87
118
|
this.apiKey = key;
|
|
88
119
|
const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
|
|
89
120
|
this.baseUrl = (opts.baseUrl ?? envBase ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
|
|
121
|
+
refuseAMismatchedPair(this.apiKey, this.baseUrl);
|
|
90
122
|
this.timeoutMs = opts.timeoutMs ?? 3e4;
|
|
91
123
|
const f = opts.fetch ?? globalThis.fetch;
|
|
92
124
|
if (!f) {
|
|
@@ -257,13 +289,18 @@ var Korely = class {
|
|
|
257
289
|
* namespaces), each with active memory + fact counts and last-active time.
|
|
258
290
|
*/
|
|
259
291
|
async users(opts = {}) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
292
|
+
const page = await this.request(
|
|
293
|
+
"GET",
|
|
294
|
+
"/v1/users",
|
|
295
|
+
{
|
|
296
|
+
params: {
|
|
297
|
+
agent_id: opts.agent_id,
|
|
298
|
+
limit: opts.limit ?? 50,
|
|
299
|
+
offset: opts.offset ?? 0
|
|
300
|
+
}
|
|
265
301
|
}
|
|
266
|
-
|
|
302
|
+
);
|
|
303
|
+
return iterableOver(page, "users");
|
|
267
304
|
}
|
|
268
305
|
// ── agents ────────────────────────────────────────────────────────────────
|
|
269
306
|
/**
|
|
@@ -275,12 +312,13 @@ var Korely = class {
|
|
|
275
312
|
* reuse one instead of minting a new id.
|
|
276
313
|
*/
|
|
277
314
|
async listAgents(opts = {}) {
|
|
278
|
-
|
|
315
|
+
const page = await this.request("GET", "/v1/agents", {
|
|
279
316
|
params: {
|
|
280
317
|
limit: opts.limit ?? 50,
|
|
281
318
|
offset: opts.offset ?? 0
|
|
282
319
|
}
|
|
283
320
|
});
|
|
321
|
+
return iterableOver(page, "agents");
|
|
284
322
|
}
|
|
285
323
|
/**
|
|
286
324
|
* DELETE /v1/agents/:agent_id — hard-delete an agent namespace: purge every
|
|
@@ -339,6 +377,37 @@ var Korely = class {
|
|
|
339
377
|
* facts known about them, the end user's own facts first, grouped by family.
|
|
340
378
|
* Pass `as_of` (ISO date) for the point-in-time profile.
|
|
341
379
|
*/
|
|
380
|
+
/**
|
|
381
|
+
* POST /v1/facts/:id/forget — close a fact: it stops being current and stays
|
|
382
|
+
* in history.
|
|
383
|
+
*
|
|
384
|
+
* `at` is the date it STOPPED being true, not the date you noticed. Reading
|
|
385
|
+
* `as_of` a date before it still returns the fact, which is the reason
|
|
386
|
+
* history is kept rather than rows deleted.
|
|
387
|
+
*
|
|
388
|
+
* Idempotent: closing an already-closed fact changes nothing and comes back
|
|
389
|
+
* with `status === "already_forgotten"`.
|
|
390
|
+
*
|
|
391
|
+
* This is the half that makes a no-model write path possible: an agent that
|
|
392
|
+
* knows a fact is finished says so, and nothing has to infer it.
|
|
393
|
+
*/
|
|
394
|
+
async forgetFact(factId, opts = {}) {
|
|
395
|
+
return this.request("POST", `/v1/facts/${encodeURIComponent(factId)}/forget`, {
|
|
396
|
+
body: { at: opts.at }
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* PATCH /v1/facts/:id — supersede a fact with a corrected one.
|
|
401
|
+
*
|
|
402
|
+
* Not an edit: the old row keeps its dates and gains a pointer to the new
|
|
403
|
+
* one, so `as_of` before the correction still returns what you believed then.
|
|
404
|
+
* At least one of the three fields is required.
|
|
405
|
+
*/
|
|
406
|
+
async correctFact(factId, changes) {
|
|
407
|
+
return this.request("PATCH", `/v1/facts/${encodeURIComponent(factId)}`, {
|
|
408
|
+
body: changes
|
|
409
|
+
});
|
|
410
|
+
}
|
|
342
411
|
async getProfile(opts) {
|
|
343
412
|
return this.request("GET", "/v1/profile", {
|
|
344
413
|
params: {
|