korely-memory 0.1.10 → 0.1.11

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 CHANGED
@@ -178,11 +178,21 @@ SDK does not retry on its own.
178
178
  ```ts
179
179
  new Korely({
180
180
  apiKey: "kor_live_...", // or the KORELY_API_KEY env var
181
- region: "eu", // EU only: data stored and processed in the EU
181
+ region: "eu", // the API, api.korely.ai: data stored in the EU
182
182
  timeoutMs: 30000, // covers the whole request, response body included
183
183
  });
184
184
  ```
185
185
 
186
+ The data is stored in the EU (Helsinki). Which model reads a memory, and
187
+ where, is the project's region, chosen per project in the dashboard: Europe
188
+ (gpt-oss-120b on Scaleway, in Paris) or Global (Gemini, by Google), the
189
+ default. A memory written to a Global project is read by Google's model.
190
+
191
+ In Node, `new Korely()` with no key and no `KORELY_API_KEY` reads what
192
+ `korely init` saved (the key and the server, in `~/.korely/config.json`, or
193
+ `$KORELY_CONFIG_HOME/config.json`), as the Python client does. An argument
194
+ comes first, then the environment, then that file.
195
+
186
196
  ### Your own server (korely-agent)
187
197
 
188
198
  Point the client at your install with `baseUrl`, or with the `KORELY_BASE_URL`
package/dist/ai-sdk.cjs CHANGED
@@ -27,6 +27,27 @@ __export(ai_sdk_exports, {
27
27
  module.exports = __toCommonJS(ai_sdk_exports);
28
28
  var import_ai = require("ai");
29
29
  var import_korely_memory = require("korely-memory");
30
+
31
+ // src/options.ts
32
+ function keysOf() {
33
+ return (...keys) => keys;
34
+ }
35
+ function unknownOption(method, opts, known) {
36
+ if (opts === void 0 || opts === null) return void 0;
37
+ if (typeof opts !== "object" || Array.isArray(opts)) {
38
+ return `${method}: the options must be an object, got ${Array.isArray(opts) ? "an array" : typeof opts}.`;
39
+ }
40
+ for (const key of Object.keys(opts)) {
41
+ if (known.includes(key)) continue;
42
+ const snake = key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
43
+ const camel = key.replace(/_([a-z])/g, (_m, c) => c.toUpperCase());
44
+ const meant = known.includes(snake) ? snake : known.includes(camel) ? camel : void 0;
45
+ return `${method}: unknown option ${key}.` + (meant ? ` Did you mean ${meant}?` : "") + ` It takes: ${known.join(", ")}.`;
46
+ }
47
+ return void 0;
48
+ }
49
+
50
+ // src/ai-sdk.ts
30
51
  var QUERY_MAX = 2e3;
31
52
  var CONTENT_MAX = 16e3;
32
53
  var USER_MAX = 6e3;
@@ -36,7 +57,36 @@ var CONTEXT_REUSE_MS = 5 * 6e4;
36
57
  var FAILURE_REUSE_MS = 3e4;
37
58
  var DEFAULT_CONTEXT_TIMEOUT_MS = 5e3;
38
59
  var MAX_TIMER_MS = 2 ** 31 - 1;
39
- function scopeOf(options, caller) {
60
+ var TOOLS_KEYS = keysOf()(
61
+ "userId",
62
+ "agentId",
63
+ "runId",
64
+ "client",
65
+ "tokenBudget",
66
+ "includeDate",
67
+ "timeZone",
68
+ "contextTimeoutMs",
69
+ "onError"
70
+ );
71
+ var MEMORY_KEYS = keysOf()(
72
+ "userId",
73
+ "agentId",
74
+ "runId",
75
+ "client",
76
+ "tokenBudget",
77
+ "includeDate",
78
+ "timeZone",
79
+ "contextTimeoutMs",
80
+ "onError",
81
+ "remember",
82
+ "waitUntil"
83
+ );
84
+ function checkOptions(method, opts, known) {
85
+ const problem = unknownOption(method, opts, known);
86
+ if (problem) throw new import_korely_memory.KorelyError(problem);
87
+ }
88
+ function scopeOf(options, caller, known) {
89
+ checkOptions(caller, options, known);
40
90
  const o = options ?? {};
41
91
  if (typeof o.userId !== "string" || !o.userId.trim()) {
42
92
  throw new import_korely_memory.KorelyError(
@@ -168,7 +218,7 @@ function readWithin(read, limit) {
168
218
  });
169
219
  }
170
220
  function korelyMemoryMiddleware(options) {
171
- const scope = scopeOf(options, "korelyMemoryMiddleware");
221
+ const scope = scopeOf(options, "korelyMemoryMiddleware", MEMORY_KEYS);
172
222
  const remember = options.remember ?? true;
173
223
  const report = scope.report;
174
224
  const waitUntil = options.waitUntil;
@@ -286,7 +336,7 @@ function oneText(value, key, max) {
286
336
  return { success: true, value: { [key]: clip(raw.trim(), max) } };
287
337
  }
288
338
  function korelyTools(options) {
289
- const scope = scopeOf(options, "korelyTools");
339
+ const scope = scopeOf(options, "korelyTools", TOOLS_KEYS);
290
340
  const withDate = (text) => scope.today ? `${scope.today()}
291
341
 
292
342
  ${text}` : text;
package/dist/ai-sdk.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ keysOf,
3
+ unknownOption
4
+ } from "./chunk-6SD5RRK3.js";
5
+
1
6
  // src/ai-sdk.ts
2
7
  import { gateway, jsonSchema, tool, wrapLanguageModel } from "ai";
3
8
  import { Korely, KorelyError } from "korely-memory";
@@ -10,7 +15,36 @@ var CONTEXT_REUSE_MS = 5 * 6e4;
10
15
  var FAILURE_REUSE_MS = 3e4;
11
16
  var DEFAULT_CONTEXT_TIMEOUT_MS = 5e3;
12
17
  var MAX_TIMER_MS = 2 ** 31 - 1;
13
- function scopeOf(options, caller) {
18
+ var TOOLS_KEYS = keysOf()(
19
+ "userId",
20
+ "agentId",
21
+ "runId",
22
+ "client",
23
+ "tokenBudget",
24
+ "includeDate",
25
+ "timeZone",
26
+ "contextTimeoutMs",
27
+ "onError"
28
+ );
29
+ var MEMORY_KEYS = keysOf()(
30
+ "userId",
31
+ "agentId",
32
+ "runId",
33
+ "client",
34
+ "tokenBudget",
35
+ "includeDate",
36
+ "timeZone",
37
+ "contextTimeoutMs",
38
+ "onError",
39
+ "remember",
40
+ "waitUntil"
41
+ );
42
+ function checkOptions(method, opts, known) {
43
+ const problem = unknownOption(method, opts, known);
44
+ if (problem) throw new KorelyError(problem);
45
+ }
46
+ function scopeOf(options, caller, known) {
47
+ checkOptions(caller, options, known);
14
48
  const o = options ?? {};
15
49
  if (typeof o.userId !== "string" || !o.userId.trim()) {
16
50
  throw new KorelyError(
@@ -142,7 +176,7 @@ function readWithin(read, limit) {
142
176
  });
143
177
  }
144
178
  function korelyMemoryMiddleware(options) {
145
- const scope = scopeOf(options, "korelyMemoryMiddleware");
179
+ const scope = scopeOf(options, "korelyMemoryMiddleware", MEMORY_KEYS);
146
180
  const remember = options.remember ?? true;
147
181
  const report = scope.report;
148
182
  const waitUntil = options.waitUntil;
@@ -260,7 +294,7 @@ function oneText(value, key, max) {
260
294
  return { success: true, value: { [key]: clip(raw.trim(), max) } };
261
295
  }
262
296
  function korelyTools(options) {
263
- const scope = scopeOf(options, "korelyTools");
297
+ const scope = scopeOf(options, "korelyTools", TOOLS_KEYS);
264
298
  const withDate = (text) => scope.today ? `${scope.today()}
265
299
 
266
300
  ${text}` : text;
@@ -0,0 +1,31 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/options.ts
9
+ function keysOf() {
10
+ return (...keys) => keys;
11
+ }
12
+ function unknownOption(method, opts, known) {
13
+ if (opts === void 0 || opts === null) return void 0;
14
+ if (typeof opts !== "object" || Array.isArray(opts)) {
15
+ return `${method}: the options must be an object, got ${Array.isArray(opts) ? "an array" : typeof opts}.`;
16
+ }
17
+ for (const key of Object.keys(opts)) {
18
+ if (known.includes(key)) continue;
19
+ const snake = key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
20
+ const camel = key.replace(/_([a-z])/g, (_m, c) => c.toUpperCase());
21
+ const meant = known.includes(snake) ? snake : known.includes(camel) ? camel : void 0;
22
+ return `${method}: unknown option ${key}.` + (meant ? ` Did you mean ${meant}?` : "") + ` It takes: ${known.join(", ")}.`;
23
+ }
24
+ return void 0;
25
+ }
26
+
27
+ export {
28
+ __require,
29
+ keysOf,
30
+ unknownOption
31
+ };
package/dist/index.cjs CHANGED
@@ -102,9 +102,68 @@ var TooManyBatchesError = class _TooManyBatchesError extends QuotaExceededError
102
102
  }
103
103
  };
104
104
 
105
+ // src/options.ts
106
+ function keysOf() {
107
+ return (...keys) => keys;
108
+ }
109
+ function unknownOption(method, opts, known) {
110
+ if (opts === void 0 || opts === null) return void 0;
111
+ if (typeof opts !== "object" || Array.isArray(opts)) {
112
+ return `${method}: the options must be an object, got ${Array.isArray(opts) ? "an array" : typeof opts}.`;
113
+ }
114
+ for (const key of Object.keys(opts)) {
115
+ if (known.includes(key)) continue;
116
+ const snake = key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
117
+ const camel = key.replace(/_([a-z])/g, (_m, c) => c.toUpperCase());
118
+ const meant = known.includes(snake) ? snake : known.includes(camel) ? camel : void 0;
119
+ return `${method}: unknown option ${key}.` + (meant ? ` Did you mean ${meant}?` : "") + ` It takes: ${known.join(", ")}.`;
120
+ }
121
+ return void 0;
122
+ }
123
+
105
124
  // src/client.ts
106
- var VERSION = "0.1.10";
125
+ var VERSION = "0.1.11";
107
126
  var REGIONS = { eu: "https://api.korely.ai" };
127
+ var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch");
128
+ var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
129
+ var ADD_KEYS = keysOf()("agent_id", "user_id", "run_id", "metadata", "timestamp");
130
+ var SEARCH_KEYS = keysOf()("user_id", "agent_id", "run_id", "metadata", "limit");
131
+ var LIST_KEYS = keysOf()("user_id", "agent_id", "run_id", "limit", "offset");
132
+ var UPDATE_KEYS = keysOf()("content", "expected_updated_at");
133
+ var USERS_KEYS = keysOf()("agent_id", "limit", "offset");
134
+ var AGENTS_KEYS = keysOf()("limit", "offset");
135
+ var EVENTS_KEYS = keysOf()("user_id", "status", "limit");
136
+ var AUDIT_KEYS = keysOf()("user_id", "action", "since", "until", "limit", "offset");
137
+ var ITER_AUDIT_KEYS = keysOf()("user_id", "action", "since", "until", "offset", "page_size");
138
+ var FACTS_KEYS = keysOf()(
139
+ "subject",
140
+ "entity",
141
+ "predicate",
142
+ "predicate_family",
143
+ "include_invalidated",
144
+ "as_of",
145
+ "user_id",
146
+ "agent_id",
147
+ "limit",
148
+ "offset"
149
+ );
150
+ var TRIPLE_KEYS = keysOf()(
151
+ "user_id",
152
+ "agent_id",
153
+ "run_id",
154
+ "subject_type",
155
+ "object_is_literal",
156
+ "confidence",
157
+ "valid_from",
158
+ "tense"
159
+ );
160
+ var PROFILE_KEYS = keysOf()("user_id", "agent_id", "as_of");
161
+ var CONTEXT_KEYS = keysOf()("query", "user_id", "agent_id", "token_budget");
162
+ var CONTEXT_EXTRA_KEYS = keysOf()("user_id", "agent_id", "token_budget");
163
+ function checkOptions(method, opts, known) {
164
+ const problem = unknownOption(method, opts, known);
165
+ if (problem) throw new KorelyError(problem);
166
+ }
108
167
  function coerceContent(content) {
109
168
  if (typeof content === "string") return content;
110
169
  if (Array.isArray(content)) {
@@ -173,11 +232,11 @@ function detailLine(detail) {
173
232
  return void 0;
174
233
  }
175
234
  function errorFields(status, body) {
176
- const text = (v) => typeof v === "string" && v.trim() ? v : void 0;
235
+ const text2 = (v) => typeof v === "string" && v.trim() ? v : void 0;
177
236
  const b = body && typeof body === "object" ? body : {};
178
237
  const pair = b.detail && typeof b.detail === "object" && !Array.isArray(b.detail) ? b.detail : {};
179
- const code = text(b.code) ?? text(pair.code);
180
- const message = text(b.message) ?? text(pair.message) ?? detailLine(b.detail) ?? code ?? `HTTP ${status}`;
238
+ const code = text2(b.code) ?? text2(pair.code);
239
+ const message = text2(b.message) ?? text2(pair.message) ?? detailLine(b.detail) ?? code ?? `HTTP ${status}`;
181
240
  return { code, message };
182
241
  }
183
242
  function retryAfterSeconds(raw) {
@@ -250,7 +309,7 @@ async function exchange(t, method, path, opts = {}) {
250
309
  timedOut ? `Request timed out after ${t.timeoutMs} ms (${method} ${path}).` : `Connection error: ${e?.message ?? String(e)}`
251
310
  );
252
311
  let resp;
253
- let text;
312
+ let text2;
254
313
  try {
255
314
  try {
256
315
  resp = await t.fetchImpl(url, {
@@ -263,7 +322,7 @@ async function exchange(t, method, path, opts = {}) {
263
322
  throw failed(e);
264
323
  }
265
324
  try {
266
- text = await resp.text();
325
+ text2 = await resp.text();
267
326
  } catch (e) {
268
327
  throw failed(e);
269
328
  }
@@ -271,17 +330,17 @@ async function exchange(t, method, path, opts = {}) {
271
330
  clearTimeout(timer);
272
331
  }
273
332
  let parsed = {};
274
- if (text) {
333
+ if (text2) {
275
334
  try {
276
- parsed = JSON.parse(text);
335
+ parsed = JSON.parse(text2);
277
336
  } catch {
278
337
  if (resp.ok) {
279
338
  throw new KorelyError(
280
- `The server answered ${resp.status} to ${method} ${path} with a body that is not JSON: ${JSON.stringify(text.slice(0, 200))}`,
339
+ `The server answered ${resp.status} to ${method} ${path} with a body that is not JSON: ${JSON.stringify(text2.slice(0, 200))}`,
281
340
  { status: resp.status }
282
341
  );
283
342
  }
284
- parsed = { message: text };
343
+ parsed = { message: text2 };
285
344
  }
286
345
  }
287
346
  if (!resp.ok) {
@@ -309,26 +368,39 @@ function raiseFor(status, body, retryAfter) {
309
368
  }
310
369
  throw new APIError(msg, opts);
311
370
  }
312
- function refusePythonSpelling(opts) {
313
- if (opts && Object.prototype.hasOwnProperty.call(opts, "base_url")) {
314
- throw new KorelyError(
315
- "Unknown option base_url: the JavaScript SDK takes baseUrl (new Korely({ baseUrl: 'https://...' })) or the KORELY_BASE_URL env var."
316
- );
371
+ function savedConfig() {
372
+ try {
373
+ const proc = typeof process !== "undefined" ? process : void 0;
374
+ if (!proc?.versions?.node) return {};
375
+ const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof require === "function" ? require(id) : void 0;
376
+ const fs = builtin("node:fs");
377
+ const os = builtin("node:os");
378
+ const path = builtin("node:path");
379
+ if (!fs || !os || !path) return {};
380
+ const home = proc.env?.KORELY_CONFIG_HOME || path.join(os.homedir(), ".korely");
381
+ const data = JSON.parse(fs.readFileSync(path.join(home, "config.json"), "utf8"));
382
+ return data && typeof data === "object" ? data : {};
383
+ } catch {
384
+ return {};
317
385
  }
318
386
  }
387
+ function text(v) {
388
+ return typeof v === "string" && v ? v : void 0;
389
+ }
319
390
  var Korely = class {
320
391
  constructor(opts = {}) {
321
- refusePythonSpelling(opts);
392
+ checkOptions("Korely", opts, CLIENT_KEYS);
322
393
  const envKey = typeof process !== "undefined" ? process.env?.KORELY_API_KEY : void 0;
323
- const key = opts.apiKey ?? envKey;
394
+ const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
395
+ const saved = opts.apiKey && (opts.baseUrl || envBase) ? {} : savedConfig();
396
+ const key = opts.apiKey ?? envKey ?? text(saved.api_key);
324
397
  if (!key) {
325
398
  throw new KorelyError(
326
- "No API key. Pass { apiKey: 'kor_live_...' } or set KORELY_API_KEY."
399
+ "No API key. Pass { apiKey: 'kor_live_...' }, set KORELY_API_KEY, or run `korely init`, which saves one to ~/.korely/config.json."
327
400
  );
328
401
  }
329
402
  this.apiKey = key;
330
- const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
331
- this.baseUrl = (opts.baseUrl ?? envBase ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
403
+ this.baseUrl = (opts.baseUrl ?? envBase ?? text(saved.base_url) ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
332
404
  refuseAMismatchedPair(this.apiKey, this.baseUrl);
333
405
  this.timeoutMs = opts.timeoutMs ?? 3e4;
334
406
  const f = opts.fetch ?? globalThis.fetch;
@@ -358,7 +430,11 @@ var Korely = class {
358
430
  * dashboard: its keys come from its own dashboard.
359
431
  */
360
432
  static async initAgent(agentCaller, opts = {}) {
361
- refusePythonSpelling(opts);
433
+ checkOptions("initAgent", opts, INIT_KEYS);
434
+ const where = opts.processingRegion;
435
+ if (where !== void 0 && where !== "eu" && where !== "global") {
436
+ throw new KorelyError(`processingRegion is "eu" or "global", not ${JSON.stringify(where)}.`);
437
+ }
362
438
  if (agentCaller != null && typeof agentCaller !== "string") {
363
439
  throw new KorelyError(
364
440
  `agentCaller is a label, a string, not ${Array.isArray(agentCaller) ? "an array" : `a ${typeof agentCaller}`}: Korely.initAgent('my-app', { baseUrl }).`
@@ -376,7 +452,9 @@ var Korely = class {
376
452
  { baseUrl, timeoutMs: opts.timeoutMs ?? 3e4, fetchImpl },
377
453
  "POST",
378
454
  "/v1/agents/init",
379
- { body: { agent_caller: agentCaller ?? void 0 } }
455
+ {
456
+ body: { agent_caller: agentCaller ?? void 0, processing_region: opts.processingRegion }
457
+ }
380
458
  );
381
459
  }
382
460
  // ── transport ─────────────────────────────────────────────────────────────
@@ -419,6 +497,7 @@ var Korely = class {
419
497
  * dashboard. No audit event survives: the trail is part of what goes.
420
498
  */
421
499
  async deleteAccount(opts = {}) {
500
+ checkOptions("deleteAccount", opts, ["confirm"]);
422
501
  if (opts?.confirm !== true) {
423
502
  throw new KorelyError(
424
503
  "deleteAccount() deletes this key's account, every key, memory and fact of it, for good. Pass { confirm: true } to mean it.",
@@ -444,6 +523,7 @@ var Korely = class {
444
523
  * project, like every read.
445
524
  */
446
525
  async audit(opts = {}) {
526
+ checkOptions("audit", opts, AUDIT_KEYS);
447
527
  const page = await this.request(
448
528
  "GET",
449
529
  "/v1/audit",
@@ -469,6 +549,7 @@ var Korely = class {
469
549
  * `until: new Date()`) and `offset` the number of events already read.
470
550
  */
471
551
  async *iterAudit(opts = {}) {
552
+ checkOptions("iterAudit", opts, ITER_AUDIT_KEYS);
472
553
  const filters = auditFilters(opts);
473
554
  let offset = opts.offset ?? 0;
474
555
  let pin = filters.until === void 0 && offset === 0;
@@ -499,15 +580,16 @@ var Korely = class {
499
580
  * backfill: facts extracted inherit it as `valid_from`.
500
581
  */
501
582
  async add(content, opts = {}) {
502
- const text = coerceContent(content);
503
- if (!text.trim()) {
583
+ checkOptions("add", opts, ADD_KEYS);
584
+ const text2 = coerceContent(content);
585
+ if (!text2.trim()) {
504
586
  throw new KorelyError(
505
587
  "content is empty: pass a non-blank string or messages with content."
506
588
  );
507
589
  }
508
590
  return this.request("POST", "/v1/memories", {
509
591
  body: {
510
- content: text,
592
+ content: text2,
511
593
  agent_id: opts.agent_id,
512
594
  user_id: opts.user_id,
513
595
  run_id: opts.run_id,
@@ -523,6 +605,7 @@ var Korely = class {
523
605
  * the server default (15), max 50.
524
606
  */
525
607
  async search(query, opts = {}) {
608
+ checkOptions("search", opts, SEARCH_KEYS);
526
609
  const body = await this.request("POST", "/v1/memories/search", {
527
610
  body: {
528
611
  query,
@@ -541,6 +624,7 @@ var Korely = class {
541
624
  * `total` and `offset` walk the rest.
542
625
  */
543
626
  async getAll(opts = {}) {
627
+ checkOptions("getAll", opts, LIST_KEYS);
544
628
  const page = await this.request(
545
629
  "GET",
546
630
  "/v1/memories",
@@ -565,6 +649,7 @@ var Korely = class {
565
649
  * for optimistic concurrency (throws StaleWriteError instead of clobbering).
566
650
  */
567
651
  async update(memoryId, opts) {
652
+ checkOptions("update", opts, UPDATE_KEYS);
568
653
  return this.request("PATCH", `/v1/memories/${seg(memoryId, "memoryId")}`, {
569
654
  body: {
570
655
  content: opts.content,
@@ -590,6 +675,7 @@ var Korely = class {
590
675
  * the same numbers; whichever pair the server sends fills both.
591
676
  */
592
677
  async deleteAll(opts) {
678
+ checkOptions("deleteAll", opts, ["user_id"]);
593
679
  const r = await this.request(
594
680
  "DELETE",
595
681
  `/v1/users/${seg(opts.user_id, "user_id")}/memories`
@@ -611,6 +697,7 @@ var Korely = class {
611
697
  * namespaces), each with active memory + fact counts and last-active time.
612
698
  */
613
699
  async users(opts = {}) {
700
+ checkOptions("users", opts, USERS_KEYS);
614
701
  const page = await this.request(
615
702
  "GET",
616
703
  "/v1/users",
@@ -639,6 +726,7 @@ var Korely = class {
639
726
  * sets no cap and answers `cap: 0`.
640
727
  */
641
728
  async listAgents(opts = {}) {
729
+ checkOptions("listAgents", opts, AGENTS_KEYS);
642
730
  const page = await this.request("GET", "/v1/agents", {
643
731
  params: {
644
732
  limit: opts.limit ?? 50,
@@ -670,6 +758,7 @@ var Korely = class {
670
758
  * array that also carries `total`, the matches across all pages.
671
759
  */
672
760
  async getFacts(opts = {}) {
761
+ checkOptions("getFacts", opts, FACTS_KEYS);
673
762
  const params = {
674
763
  subject: opts.subject,
675
764
  entity: opts.entity,
@@ -698,7 +787,8 @@ var Korely = class {
698
787
  * listing any fact ids it superseded.
699
788
  */
700
789
  async addFactTriple(subject, predicate, object, opts = {}) {
701
- return this.request("POST", "/v1/facts", {
790
+ checkOptions("addFactTriple", opts, TRIPLE_KEYS);
791
+ const fact = await this.request("POST", "/v1/facts", {
702
792
  body: {
703
793
  subject,
704
794
  predicate,
@@ -713,6 +803,11 @@ var Korely = class {
713
803
  tense: opts.tense
714
804
  }
715
805
  });
806
+ return {
807
+ ...fact,
808
+ user_id: fact.user_id !== void 0 ? fact.user_id : opts.user_id,
809
+ agent_id: fact.agent_id !== void 0 ? fact.agent_id : opts.agent_id
810
+ };
716
811
  }
717
812
  /**
718
813
  * POST /v1/facts/:id/forget: close a fact; it stops being current and stays
@@ -729,6 +824,7 @@ var Korely = class {
729
824
  * knows a fact is finished says so, and nothing has to infer it.
730
825
  */
731
826
  async forgetFact(factId, opts = {}) {
827
+ checkOptions("forgetFact", opts, ["at"]);
732
828
  return this.request("POST", `/v1/facts/${seg(factId, "factId")}/forget`, {
733
829
  body: { at: opts.at }
734
830
  });
@@ -758,6 +854,7 @@ var Korely = class {
758
854
  * Pass `as_of` (ISO date) for the point-in-time profile.
759
855
  */
760
856
  async getProfile(opts) {
857
+ checkOptions("getProfile", opts, PROFILE_KEYS);
761
858
  return this.request("GET", "/v1/profile", {
762
859
  params: {
763
860
  user_id: opts.user_id,
@@ -772,6 +869,8 @@ var Korely = class {
772
869
  * (profile + relevant facts + memories) within a token budget.
773
870
  */
774
871
  async getContext(opts, extra = {}) {
872
+ if (typeof opts === "string") checkOptions("getContext", extra, CONTEXT_EXTRA_KEYS);
873
+ else checkOptions("getContext", opts, CONTEXT_KEYS);
775
874
  const o = typeof opts === "string" ? { ...extra, query: opts } : opts;
776
875
  if (!o || typeof o.query !== "string" || !o.query.trim()) {
777
876
  throw new KorelyError("getContext needs a query.");
@@ -799,6 +898,7 @@ var Korely = class {
799
898
  * this is how to know.
800
899
  */
801
900
  async events(opts = {}) {
901
+ checkOptions("events", opts, EVENTS_KEYS);
802
902
  return this.request("GET", "/v1/events", {
803
903
  params: {
804
904
  user_id: opts.user_id,
package/dist/index.d.cts CHANGED
@@ -275,10 +275,18 @@ interface PingResponse {
275
275
  */
276
276
  tier: string;
277
277
  /**
278
- * Where the key's data is stored and processed, as the server declares it
279
- * ("eu-hel1" on the Cloud; on the Self-hosted, what its operator set).
278
+ * Where the key's data is stored, as the server declares it ("eu-hel1" on
279
+ * the Cloud; on the Self-hosted, what its operator set). Not where a memory
280
+ * is read by a model: on the Cloud that is the project's region, Europe or
281
+ * Global (Gemini, by Google).
280
282
  */
281
283
  region: string;
284
+ /**
285
+ * Where a memory is read by a model, "eu" or "global": the region of the
286
+ * key's project on the Cloud, of the writer the install uses on the
287
+ * Self-hosted. Absent from a server older than 2026-10-07; null with no writer.
288
+ */
289
+ processing_region?: "eu" | "global" | null;
282
290
  /** What the key may do, e.g. "memories:read". */
283
291
  scopes: string[];
284
292
  }
@@ -288,6 +296,8 @@ interface AgentInitResult {
288
296
  api_key: string;
289
297
  tier: string;
290
298
  region: string;
299
+ /** Where the new project's memories are read by a model. */
300
+ processing_region?: "eu" | "global";
291
301
  scopes: string[];
292
302
  /** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
293
303
  quotas: Record<string, unknown>;
@@ -464,11 +474,16 @@ interface ForgetReceipt {
464
474
 
465
475
  /** Must equal `version` in package.json (a test checks). It goes out in the
466
476
  * X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
467
- declare const VERSION = "0.1.10";
477
+ declare const VERSION = "0.1.11";
468
478
  interface KorelyOptions {
469
479
  /** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
470
480
  apiKey?: string;
471
- /** EU only for now (data stored and processed in the EU). */
481
+ /**
482
+ * The API to call: "eu" (api.korely.ai), the only one today. The data is
483
+ * stored in the EU (Helsinki). The model that reads a memory is the
484
+ * project's region, set per project in the dashboard: Europe (gpt-oss-120b
485
+ * on Scaleway, in Paris) or Global (Gemini, by Google), the default.
486
+ */
472
487
  region?: "eu";
473
488
  /** Override the base URL (a self-hosted install, or testing). */
474
489
  baseUrl?: string;
@@ -479,7 +494,14 @@ interface KorelyOptions {
479
494
  }
480
495
  /** Where and how `Korely.initAgent()` signs up: the client options a call
481
496
  * without a key can use. */
482
- type InitAgentOptions = Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch">;
497
+ interface InitAgentOptions extends Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch"> {
498
+ /**
499
+ * Where the new project's memories are read by a model: "eu" (gpt-oss-120b
500
+ * on Scaleway, Paris) or "global" (Gemini, by Google), the server's default
501
+ * when left out. Sent only when given (servers since 2026-10-07).
502
+ */
503
+ processingRegion?: "eu" | "global";
504
+ }
483
505
  declare class Korely {
484
506
  readonly apiKey: string;
485
507
  readonly baseUrl: string;
package/dist/index.d.ts CHANGED
@@ -275,10 +275,18 @@ interface PingResponse {
275
275
  */
276
276
  tier: string;
277
277
  /**
278
- * Where the key's data is stored and processed, as the server declares it
279
- * ("eu-hel1" on the Cloud; on the Self-hosted, what its operator set).
278
+ * Where the key's data is stored, as the server declares it ("eu-hel1" on
279
+ * the Cloud; on the Self-hosted, what its operator set). Not where a memory
280
+ * is read by a model: on the Cloud that is the project's region, Europe or
281
+ * Global (Gemini, by Google).
280
282
  */
281
283
  region: string;
284
+ /**
285
+ * Where a memory is read by a model, "eu" or "global": the region of the
286
+ * key's project on the Cloud, of the writer the install uses on the
287
+ * Self-hosted. Absent from a server older than 2026-10-07; null with no writer.
288
+ */
289
+ processing_region?: "eu" | "global" | null;
282
290
  /** What the key may do, e.g. "memories:read". */
283
291
  scopes: string[];
284
292
  }
@@ -288,6 +296,8 @@ interface AgentInitResult {
288
296
  api_key: string;
289
297
  tier: string;
290
298
  region: string;
299
+ /** Where the new project's memories are read by a model. */
300
+ processing_region?: "eu" | "global";
291
301
  scopes: string[];
292
302
  /** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
293
303
  quotas: Record<string, unknown>;
@@ -464,11 +474,16 @@ interface ForgetReceipt {
464
474
 
465
475
  /** Must equal `version` in package.json (a test checks). It goes out in the
466
476
  * X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
467
- declare const VERSION = "0.1.10";
477
+ declare const VERSION = "0.1.11";
468
478
  interface KorelyOptions {
469
479
  /** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
470
480
  apiKey?: string;
471
- /** EU only for now (data stored and processed in the EU). */
481
+ /**
482
+ * The API to call: "eu" (api.korely.ai), the only one today. The data is
483
+ * stored in the EU (Helsinki). The model that reads a memory is the
484
+ * project's region, set per project in the dashboard: Europe (gpt-oss-120b
485
+ * on Scaleway, in Paris) or Global (Gemini, by Google), the default.
486
+ */
472
487
  region?: "eu";
473
488
  /** Override the base URL (a self-hosted install, or testing). */
474
489
  baseUrl?: string;
@@ -479,7 +494,14 @@ interface KorelyOptions {
479
494
  }
480
495
  /** Where and how `Korely.initAgent()` signs up: the client options a call
481
496
  * without a key can use. */
482
- type InitAgentOptions = Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch">;
497
+ interface InitAgentOptions extends Pick<KorelyOptions, "region" | "baseUrl" | "timeoutMs" | "fetch"> {
498
+ /**
499
+ * Where the new project's memories are read by a model: "eu" (gpt-oss-120b
500
+ * on Scaleway, Paris) or "global" (Gemini, by Google), the server's default
501
+ * when left out. Sent only when given (servers since 2026-10-07).
502
+ */
503
+ processingRegion?: "eu" | "global";
504
+ }
483
505
  declare class Korely {
484
506
  readonly apiKey: string;
485
507
  readonly baseUrl: string;
package/dist/index.js CHANGED
@@ -1,3 +1,9 @@
1
+ import {
2
+ __require,
3
+ keysOf,
4
+ unknownOption
5
+ } from "./chunk-6SD5RRK3.js";
6
+
1
7
  // src/errors.ts
2
8
  var KorelyError = class extends Error {
3
9
  constructor(message = "", opts = {}) {
@@ -67,8 +73,48 @@ var TooManyBatchesError = class _TooManyBatchesError extends QuotaExceededError
67
73
  };
68
74
 
69
75
  // src/client.ts
70
- var VERSION = "0.1.10";
76
+ var VERSION = "0.1.11";
71
77
  var REGIONS = { eu: "https://api.korely.ai" };
78
+ var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch");
79
+ var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
80
+ var ADD_KEYS = keysOf()("agent_id", "user_id", "run_id", "metadata", "timestamp");
81
+ var SEARCH_KEYS = keysOf()("user_id", "agent_id", "run_id", "metadata", "limit");
82
+ var LIST_KEYS = keysOf()("user_id", "agent_id", "run_id", "limit", "offset");
83
+ var UPDATE_KEYS = keysOf()("content", "expected_updated_at");
84
+ var USERS_KEYS = keysOf()("agent_id", "limit", "offset");
85
+ var AGENTS_KEYS = keysOf()("limit", "offset");
86
+ var EVENTS_KEYS = keysOf()("user_id", "status", "limit");
87
+ var AUDIT_KEYS = keysOf()("user_id", "action", "since", "until", "limit", "offset");
88
+ var ITER_AUDIT_KEYS = keysOf()("user_id", "action", "since", "until", "offset", "page_size");
89
+ var FACTS_KEYS = keysOf()(
90
+ "subject",
91
+ "entity",
92
+ "predicate",
93
+ "predicate_family",
94
+ "include_invalidated",
95
+ "as_of",
96
+ "user_id",
97
+ "agent_id",
98
+ "limit",
99
+ "offset"
100
+ );
101
+ var TRIPLE_KEYS = keysOf()(
102
+ "user_id",
103
+ "agent_id",
104
+ "run_id",
105
+ "subject_type",
106
+ "object_is_literal",
107
+ "confidence",
108
+ "valid_from",
109
+ "tense"
110
+ );
111
+ var PROFILE_KEYS = keysOf()("user_id", "agent_id", "as_of");
112
+ var CONTEXT_KEYS = keysOf()("query", "user_id", "agent_id", "token_budget");
113
+ var CONTEXT_EXTRA_KEYS = keysOf()("user_id", "agent_id", "token_budget");
114
+ function checkOptions(method, opts, known) {
115
+ const problem = unknownOption(method, opts, known);
116
+ if (problem) throw new KorelyError(problem);
117
+ }
72
118
  function coerceContent(content) {
73
119
  if (typeof content === "string") return content;
74
120
  if (Array.isArray(content)) {
@@ -137,11 +183,11 @@ function detailLine(detail) {
137
183
  return void 0;
138
184
  }
139
185
  function errorFields(status, body) {
140
- const text = (v) => typeof v === "string" && v.trim() ? v : void 0;
186
+ const text2 = (v) => typeof v === "string" && v.trim() ? v : void 0;
141
187
  const b = body && typeof body === "object" ? body : {};
142
188
  const pair = b.detail && typeof b.detail === "object" && !Array.isArray(b.detail) ? b.detail : {};
143
- const code = text(b.code) ?? text(pair.code);
144
- const message = text(b.message) ?? text(pair.message) ?? detailLine(b.detail) ?? code ?? `HTTP ${status}`;
189
+ const code = text2(b.code) ?? text2(pair.code);
190
+ const message = text2(b.message) ?? text2(pair.message) ?? detailLine(b.detail) ?? code ?? `HTTP ${status}`;
145
191
  return { code, message };
146
192
  }
147
193
  function retryAfterSeconds(raw) {
@@ -214,7 +260,7 @@ async function exchange(t, method, path, opts = {}) {
214
260
  timedOut ? `Request timed out after ${t.timeoutMs} ms (${method} ${path}).` : `Connection error: ${e?.message ?? String(e)}`
215
261
  );
216
262
  let resp;
217
- let text;
263
+ let text2;
218
264
  try {
219
265
  try {
220
266
  resp = await t.fetchImpl(url, {
@@ -227,7 +273,7 @@ async function exchange(t, method, path, opts = {}) {
227
273
  throw failed(e);
228
274
  }
229
275
  try {
230
- text = await resp.text();
276
+ text2 = await resp.text();
231
277
  } catch (e) {
232
278
  throw failed(e);
233
279
  }
@@ -235,17 +281,17 @@ async function exchange(t, method, path, opts = {}) {
235
281
  clearTimeout(timer);
236
282
  }
237
283
  let parsed = {};
238
- if (text) {
284
+ if (text2) {
239
285
  try {
240
- parsed = JSON.parse(text);
286
+ parsed = JSON.parse(text2);
241
287
  } catch {
242
288
  if (resp.ok) {
243
289
  throw new KorelyError(
244
- `The server answered ${resp.status} to ${method} ${path} with a body that is not JSON: ${JSON.stringify(text.slice(0, 200))}`,
290
+ `The server answered ${resp.status} to ${method} ${path} with a body that is not JSON: ${JSON.stringify(text2.slice(0, 200))}`,
245
291
  { status: resp.status }
246
292
  );
247
293
  }
248
- parsed = { message: text };
294
+ parsed = { message: text2 };
249
295
  }
250
296
  }
251
297
  if (!resp.ok) {
@@ -273,26 +319,39 @@ function raiseFor(status, body, retryAfter) {
273
319
  }
274
320
  throw new APIError(msg, opts);
275
321
  }
276
- function refusePythonSpelling(opts) {
277
- if (opts && Object.prototype.hasOwnProperty.call(opts, "base_url")) {
278
- throw new KorelyError(
279
- "Unknown option base_url: the JavaScript SDK takes baseUrl (new Korely({ baseUrl: 'https://...' })) or the KORELY_BASE_URL env var."
280
- );
322
+ function savedConfig() {
323
+ try {
324
+ const proc = typeof process !== "undefined" ? process : void 0;
325
+ if (!proc?.versions?.node) return {};
326
+ const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof __require === "function" ? __require(id) : void 0;
327
+ const fs = builtin("node:fs");
328
+ const os = builtin("node:os");
329
+ const path = builtin("node:path");
330
+ if (!fs || !os || !path) return {};
331
+ const home = proc.env?.KORELY_CONFIG_HOME || path.join(os.homedir(), ".korely");
332
+ const data = JSON.parse(fs.readFileSync(path.join(home, "config.json"), "utf8"));
333
+ return data && typeof data === "object" ? data : {};
334
+ } catch {
335
+ return {};
281
336
  }
282
337
  }
338
+ function text(v) {
339
+ return typeof v === "string" && v ? v : void 0;
340
+ }
283
341
  var Korely = class {
284
342
  constructor(opts = {}) {
285
- refusePythonSpelling(opts);
343
+ checkOptions("Korely", opts, CLIENT_KEYS);
286
344
  const envKey = typeof process !== "undefined" ? process.env?.KORELY_API_KEY : void 0;
287
- const key = opts.apiKey ?? envKey;
345
+ const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
346
+ const saved = opts.apiKey && (opts.baseUrl || envBase) ? {} : savedConfig();
347
+ const key = opts.apiKey ?? envKey ?? text(saved.api_key);
288
348
  if (!key) {
289
349
  throw new KorelyError(
290
- "No API key. Pass { apiKey: 'kor_live_...' } or set KORELY_API_KEY."
350
+ "No API key. Pass { apiKey: 'kor_live_...' }, set KORELY_API_KEY, or run `korely init`, which saves one to ~/.korely/config.json."
291
351
  );
292
352
  }
293
353
  this.apiKey = key;
294
- const envBase = typeof process !== "undefined" ? process.env?.KORELY_BASE_URL : void 0;
295
- this.baseUrl = (opts.baseUrl ?? envBase ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
354
+ this.baseUrl = (opts.baseUrl ?? envBase ?? text(saved.base_url) ?? REGIONS[opts.region ?? "eu"] ?? REGIONS.eu).replace(/\/+$/, "");
296
355
  refuseAMismatchedPair(this.apiKey, this.baseUrl);
297
356
  this.timeoutMs = opts.timeoutMs ?? 3e4;
298
357
  const f = opts.fetch ?? globalThis.fetch;
@@ -322,7 +381,11 @@ var Korely = class {
322
381
  * dashboard: its keys come from its own dashboard.
323
382
  */
324
383
  static async initAgent(agentCaller, opts = {}) {
325
- refusePythonSpelling(opts);
384
+ checkOptions("initAgent", opts, INIT_KEYS);
385
+ const where = opts.processingRegion;
386
+ if (where !== void 0 && where !== "eu" && where !== "global") {
387
+ throw new KorelyError(`processingRegion is "eu" or "global", not ${JSON.stringify(where)}.`);
388
+ }
326
389
  if (agentCaller != null && typeof agentCaller !== "string") {
327
390
  throw new KorelyError(
328
391
  `agentCaller is a label, a string, not ${Array.isArray(agentCaller) ? "an array" : `a ${typeof agentCaller}`}: Korely.initAgent('my-app', { baseUrl }).`
@@ -340,7 +403,9 @@ var Korely = class {
340
403
  { baseUrl, timeoutMs: opts.timeoutMs ?? 3e4, fetchImpl },
341
404
  "POST",
342
405
  "/v1/agents/init",
343
- { body: { agent_caller: agentCaller ?? void 0 } }
406
+ {
407
+ body: { agent_caller: agentCaller ?? void 0, processing_region: opts.processingRegion }
408
+ }
344
409
  );
345
410
  }
346
411
  // ── transport ─────────────────────────────────────────────────────────────
@@ -383,6 +448,7 @@ var Korely = class {
383
448
  * dashboard. No audit event survives: the trail is part of what goes.
384
449
  */
385
450
  async deleteAccount(opts = {}) {
451
+ checkOptions("deleteAccount", opts, ["confirm"]);
386
452
  if (opts?.confirm !== true) {
387
453
  throw new KorelyError(
388
454
  "deleteAccount() deletes this key's account, every key, memory and fact of it, for good. Pass { confirm: true } to mean it.",
@@ -408,6 +474,7 @@ var Korely = class {
408
474
  * project, like every read.
409
475
  */
410
476
  async audit(opts = {}) {
477
+ checkOptions("audit", opts, AUDIT_KEYS);
411
478
  const page = await this.request(
412
479
  "GET",
413
480
  "/v1/audit",
@@ -433,6 +500,7 @@ var Korely = class {
433
500
  * `until: new Date()`) and `offset` the number of events already read.
434
501
  */
435
502
  async *iterAudit(opts = {}) {
503
+ checkOptions("iterAudit", opts, ITER_AUDIT_KEYS);
436
504
  const filters = auditFilters(opts);
437
505
  let offset = opts.offset ?? 0;
438
506
  let pin = filters.until === void 0 && offset === 0;
@@ -463,15 +531,16 @@ var Korely = class {
463
531
  * backfill: facts extracted inherit it as `valid_from`.
464
532
  */
465
533
  async add(content, opts = {}) {
466
- const text = coerceContent(content);
467
- if (!text.trim()) {
534
+ checkOptions("add", opts, ADD_KEYS);
535
+ const text2 = coerceContent(content);
536
+ if (!text2.trim()) {
468
537
  throw new KorelyError(
469
538
  "content is empty: pass a non-blank string or messages with content."
470
539
  );
471
540
  }
472
541
  return this.request("POST", "/v1/memories", {
473
542
  body: {
474
- content: text,
543
+ content: text2,
475
544
  agent_id: opts.agent_id,
476
545
  user_id: opts.user_id,
477
546
  run_id: opts.run_id,
@@ -487,6 +556,7 @@ var Korely = class {
487
556
  * the server default (15), max 50.
488
557
  */
489
558
  async search(query, opts = {}) {
559
+ checkOptions("search", opts, SEARCH_KEYS);
490
560
  const body = await this.request("POST", "/v1/memories/search", {
491
561
  body: {
492
562
  query,
@@ -505,6 +575,7 @@ var Korely = class {
505
575
  * `total` and `offset` walk the rest.
506
576
  */
507
577
  async getAll(opts = {}) {
578
+ checkOptions("getAll", opts, LIST_KEYS);
508
579
  const page = await this.request(
509
580
  "GET",
510
581
  "/v1/memories",
@@ -529,6 +600,7 @@ var Korely = class {
529
600
  * for optimistic concurrency (throws StaleWriteError instead of clobbering).
530
601
  */
531
602
  async update(memoryId, opts) {
603
+ checkOptions("update", opts, UPDATE_KEYS);
532
604
  return this.request("PATCH", `/v1/memories/${seg(memoryId, "memoryId")}`, {
533
605
  body: {
534
606
  content: opts.content,
@@ -554,6 +626,7 @@ var Korely = class {
554
626
  * the same numbers; whichever pair the server sends fills both.
555
627
  */
556
628
  async deleteAll(opts) {
629
+ checkOptions("deleteAll", opts, ["user_id"]);
557
630
  const r = await this.request(
558
631
  "DELETE",
559
632
  `/v1/users/${seg(opts.user_id, "user_id")}/memories`
@@ -575,6 +648,7 @@ var Korely = class {
575
648
  * namespaces), each with active memory + fact counts and last-active time.
576
649
  */
577
650
  async users(opts = {}) {
651
+ checkOptions("users", opts, USERS_KEYS);
578
652
  const page = await this.request(
579
653
  "GET",
580
654
  "/v1/users",
@@ -603,6 +677,7 @@ var Korely = class {
603
677
  * sets no cap and answers `cap: 0`.
604
678
  */
605
679
  async listAgents(opts = {}) {
680
+ checkOptions("listAgents", opts, AGENTS_KEYS);
606
681
  const page = await this.request("GET", "/v1/agents", {
607
682
  params: {
608
683
  limit: opts.limit ?? 50,
@@ -634,6 +709,7 @@ var Korely = class {
634
709
  * array that also carries `total`, the matches across all pages.
635
710
  */
636
711
  async getFacts(opts = {}) {
712
+ checkOptions("getFacts", opts, FACTS_KEYS);
637
713
  const params = {
638
714
  subject: opts.subject,
639
715
  entity: opts.entity,
@@ -662,7 +738,8 @@ var Korely = class {
662
738
  * listing any fact ids it superseded.
663
739
  */
664
740
  async addFactTriple(subject, predicate, object, opts = {}) {
665
- return this.request("POST", "/v1/facts", {
741
+ checkOptions("addFactTriple", opts, TRIPLE_KEYS);
742
+ const fact = await this.request("POST", "/v1/facts", {
666
743
  body: {
667
744
  subject,
668
745
  predicate,
@@ -677,6 +754,11 @@ var Korely = class {
677
754
  tense: opts.tense
678
755
  }
679
756
  });
757
+ return {
758
+ ...fact,
759
+ user_id: fact.user_id !== void 0 ? fact.user_id : opts.user_id,
760
+ agent_id: fact.agent_id !== void 0 ? fact.agent_id : opts.agent_id
761
+ };
680
762
  }
681
763
  /**
682
764
  * POST /v1/facts/:id/forget: close a fact; it stops being current and stays
@@ -693,6 +775,7 @@ var Korely = class {
693
775
  * knows a fact is finished says so, and nothing has to infer it.
694
776
  */
695
777
  async forgetFact(factId, opts = {}) {
778
+ checkOptions("forgetFact", opts, ["at"]);
696
779
  return this.request("POST", `/v1/facts/${seg(factId, "factId")}/forget`, {
697
780
  body: { at: opts.at }
698
781
  });
@@ -722,6 +805,7 @@ var Korely = class {
722
805
  * Pass `as_of` (ISO date) for the point-in-time profile.
723
806
  */
724
807
  async getProfile(opts) {
808
+ checkOptions("getProfile", opts, PROFILE_KEYS);
725
809
  return this.request("GET", "/v1/profile", {
726
810
  params: {
727
811
  user_id: opts.user_id,
@@ -736,6 +820,8 @@ var Korely = class {
736
820
  * (profile + relevant facts + memories) within a token budget.
737
821
  */
738
822
  async getContext(opts, extra = {}) {
823
+ if (typeof opts === "string") checkOptions("getContext", extra, CONTEXT_EXTRA_KEYS);
824
+ else checkOptions("getContext", opts, CONTEXT_KEYS);
739
825
  const o = typeof opts === "string" ? { ...extra, query: opts } : opts;
740
826
  if (!o || typeof o.query !== "string" || !o.query.trim()) {
741
827
  throw new KorelyError("getContext needs a query.");
@@ -763,6 +849,7 @@ var Korely = class {
763
849
  * this is how to know.
764
850
  */
765
851
  async events(opts = {}) {
852
+ checkOptions("events", opts, EVENTS_KEYS);
766
853
  return this.request("GET", "/v1/events", {
767
854
  params: {
768
855
  user_id: opts.user_id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "korely-memory",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "JavaScript / TypeScript SDK for Korely Agents: memory for AI agents with bi-temporal typed facts.",
5
5
  "keywords": [
6
6
  "ai",
@@ -23,7 +23,7 @@
23
23
  "url": "https://github.com/verdana86/korely-memory/issues"
24
24
  },
25
25
  "license": "MIT",
26
- "author": "Korely <hello@korely.ai>",
26
+ "author": "Korely <info@korely.ai>",
27
27
  "type": "module",
28
28
  "main": "./dist/index.cjs",
29
29
  "module": "./dist/index.js",