korely-memory 0.2.0 → 0.2.1

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
@@ -94,8 +94,8 @@ Every method maps to one REST endpoint.
94
94
 
95
95
  | Method | Endpoint | |
96
96
  |---|---|---|
97
- | `add(content, opts?)` | `POST /v1/memories` | Write. `content` is a string or a list of chat messages. `opts.user_id` or `opts.agent_id` says whose memory it is (Korely 1.0.19 and later refuse neither). `opts.timestamp` (ISO) backfills the past: facts inherit it as `valid_from`. |
98
- | `search(query, opts?)` | `POST /v1/memories/search` | Semantic search over memories; filter by `user_id`, `agent_id`, `run_id`, `metadata`; `min_score` (0 to 1) leaves out hits scored below it. |
97
+ | `add(content, opts?)` | `POST /v1/memories` | Write. `content` is a string or a list of chat messages. `opts.user_id` or `opts.agent_id` says whose memory it is (Korely 1.0.19 and later refuse neither). `opts.timestamp` (ISO) backfills the past: facts inherit it as `valid_from`. With `opts.idempotency_key`, the same write sent again with the same key is made once (Korely 1.0.27 and later; an older server ignores it): one new key per write, the same one only to send that write again. The client never retries by itself. |
98
+ | `search(query, opts?)` | `POST /v1/memories/search` | Semantic search over memories; filter by `user_id`, `agent_id`, `run_id`, `metadata`; `min_score` (0 to 1) leaves out hits scored below it. `types: ["memories", "facts"]` searches the facts true now too (`["facts"]` them only), and each hit says its `type`, a fact's with its `fact`; `full_text: true` adds the whole text as `content` (`snippet` is its first 280 characters). Korely 1.0.13 and later; sent only when given. |
99
99
  | `getAll(opts?)` | `GET /v1/memories` | List a scope, newest first. The page is iterable; `limit` up to 200. |
100
100
  | `get(id)` | `GET /v1/memories/:id` | One memory, with its facts. |
101
101
  | `update(id, { content })` | `PATCH /v1/memories/:id` | Re-runs extraction. |
@@ -112,10 +112,10 @@ Every method maps to one REST endpoint.
112
112
  | `getProfile({ user_id, as_of?, known_as_of? })` | `GET /v1/profile` | The assembled profile of one end user. |
113
113
  | `getContext({ query, user_id?, known_as_of? })` | `GET /v1/context` | One call, a prompt-ready context block; `known_as_of` rebuilds it as the store could have built it then. |
114
114
  | `events(opts?)` | `GET /v1/events` | Which writes are still being extracted; `limit` up to 200. |
115
- | `batch(memories)` | `POST /v1/batch` | Bulk import, for migrations. Each item takes `user_id` or `agent_id` and `timestamp`, as `add()` does. |
115
+ | `batch(memories, opts?)` | `POST /v1/batch` | Bulk import, for migrations. Each item takes `user_id` or `agent_id` and `timestamp`, as `add()` does. `opts.idempotency_key` as in `add()`. |
116
116
  | `batchStatus(jobId)` | `GET /v1/batch/:id` | Poll an import job. |
117
117
  | `ping()` | `GET /v1/ping` | Check a key without spending anything (no scope, rate limit or quota): its `tier`, `region` and `scopes`. Both products. |
118
- | `Korely.initAgent(agentCaller?, opts?)` | `POST /v1/agents/init` | Cloud only. Static, no key needed: sign up for a free hobby key (shown once, save it), then `new Korely({ apiKey: result.api_key })`. `opts` takes `baseUrl`, `region`, `timeoutMs`, `fetch`. |
118
+ | `Korely.initAgent(agentCaller?, opts?)` | `POST /v1/agents/init` | Cloud only. Static, no key needed: sign up for a key that costs nothing (shown once, save it), then `new Korely({ apiKey: result.api_key })`. The answer says when the key stops working (`expires_at`) and, in `note`, the trial's limits until the account is adopted and how to adopt it; `quotas` are the monthly numbers once adopted. `opts` takes `baseUrl`, `region`, `timeoutMs`, `fetch`. |
119
119
  | `deleteAccount({ confirm: "<account id>" })` | `DELETE /v1/account` | Cloud only. Delete the key's account for good, every key, memory and fact; for an account `korely init --agent` made, which nobody signs in to. One with a login rejects with `ConflictError` (`account_has_login`). `confirm` is the account's id, typed (`tenant_id` of `GET /admin/whoami`): the DELETE is sent only when it is a UUID equal, spaces trimmed, to the id `GET /admin/whoami` gives the key. Missing, `true`, `"true"` or another id: nothing is sent but that GET, and it rejects with `KorelyError` `confirmation_required`, whose message names the id to type. Only the answer `deleted: true` is a deletion; any other rejects. A server older than 1.0.23 takes only `?confirm=true`: the client does not fall back to it, deletes nothing and rejects with `APIError` `server_too_old` (upgrade the server, or use korely-memory 0.1.18). A key that may not read `GET /admin/whoami` (403, a key without the `admin` scope) deletes nothing: with no id typed it rejects with that `confirmation_required`, whose message says whoami could not be read; with the id typed, with the whoami's refusal, `NamespaceForbiddenError` (an `APIError`, `status` 403, `code` `forbidden`). The Self-hosted, which has no such route, stops at that 403 for a key without the `admin` scope, else answers 404 (405 where it serves its dashboard). |
120
120
  | `audit(opts?)` | `GET /v1/audit` | The trail of the key's project, newest first: `user_id`, `action`, `since` / `until` (ISO text or `Date`), `limit` up to 1000. Ids, never content. Each event's `api_key_id` names the key that made the call (Korely 1.0.23); `action` is `forget` for a memory forgotten with its text kept, `erase` for one gone for good, `fact_invalidate` for a fact closed (a forget was filed as `erase` before 1.0.23). Both products; needs `memories:read`, costs no quota. |
121
121
  | `iterAudit(opts?)` | `GET /v1/audit`, every page | `for await (const e of korely.iterAudit({ user_id }))`: an export, `page_size` events per request, `until` pinned when it starts. |
@@ -205,8 +205,14 @@ default. A memory written to a Global project is read by Google's model.
205
205
  In Node, `new Korely()` with no key and no `KORELY_API_KEY` reads what
206
206
  `korely init` saved (the key and the server, in `~/.korely/config.json`, or
207
207
  `$KORELY_CONFIG_HOME/config.json`), as the Python client does, with `import`
208
- and with `require`, from Node 18. An argument comes first, then the
209
- environment, then that file. A browser or an edge runtime has no such file.
208
+ and with `require`, from Node 18. `korely` is the command of the Python
209
+ package (`pip install korely-memory`); this package has none. An argument
210
+ comes first, then the environment, then that file. A browser or an edge
211
+ runtime has no such file. With no key from any of them it throws
212
+ `KorelyError` "No API key", which says to make a key once, by hand (a cURL
213
+ of `POST /v1/agents/init`, which it gives, or `Korely.initAgent()` run once:
214
+ each call makes a new account), then to set `KORELY_API_KEY`, and names the
215
+ config file it read.
210
216
 
211
217
  ### Your own server (Self-hosted)
212
218
 
@@ -77,11 +77,28 @@ var TooManyBatchesError = class _TooManyBatchesError extends QuotaExceededError
77
77
  };
78
78
 
79
79
  // src/client.ts
80
- var VERSION = "0.2.0";
80
+ var VERSION = "0.2.1";
81
81
  var REGIONS = { eu: "https://api.korely.ai" };
82
82
  var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch", "client");
83
83
  var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
84
- var ADD_KEYS = keysOf()("agent_id", "user_id", "run_id", "metadata", "timestamp", "kind");
84
+ var ADD_KEYS = keysOf()(
85
+ "agent_id",
86
+ "user_id",
87
+ "run_id",
88
+ "metadata",
89
+ "timestamp",
90
+ "kind",
91
+ "idempotency_key"
92
+ );
93
+ function idempotencyHeader(key) {
94
+ if (key === void 0) return void 0;
95
+ if (typeof key !== "string" || !/^[\x20-\x7e]{1,255}$/.test(key)) {
96
+ throw new KorelyError(
97
+ "idempotency_key must be 1 to 255 printable ASCII characters (space to ~), one per write: a UUID will do."
98
+ );
99
+ }
100
+ return { "Idempotency-Key": `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"` };
101
+ }
85
102
  var SEARCH_KEYS = keysOf()(
86
103
  "user_id",
87
104
  "agent_id",
@@ -89,7 +106,9 @@ var SEARCH_KEYS = keysOf()(
89
106
  "metadata",
90
107
  "limit",
91
108
  "min_score",
92
- "exclude_sessions"
109
+ "exclude_sessions",
110
+ "types",
111
+ "full_text"
93
112
  );
94
113
  var LIST_KEYS = keysOf()("user_id", "agent_id", "run_id", "limit", "offset", "exclude_sessions");
95
114
  var NAME_KEYS = keysOf()("user_id", "agent_id");
@@ -307,6 +326,7 @@ async function exchange(t, method, path, opts = {}) {
307
326
  body = JSON.stringify(opts.body);
308
327
  headers["Content-Type"] = "application/json";
309
328
  }
329
+ Object.assign(headers, opts.headers);
310
330
  const controller = new AbortController();
311
331
  let timedOut = false;
312
332
  const timer = setTimeout(() => {
@@ -412,17 +432,33 @@ function useNodeFiles(files) {
412
432
  }
413
433
  function savedConfig() {
414
434
  try {
415
- const proc = typeof process !== "undefined" ? process : void 0;
416
- if (!proc?.versions?.node) return {};
417
- const files = nodeFiles ?? lookedUp(proc);
418
- if (!files) return {};
419
- const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
420
- const data = JSON.parse(files.readFileSync(files.join(home, "config.json"), "utf8"));
435
+ const at = configFile();
436
+ if (!at) return {};
437
+ const data = JSON.parse(at.files.readFileSync(at.path, "utf8"));
421
438
  return data && typeof data === "object" ? data : {};
422
439
  } catch {
423
440
  return {};
424
441
  }
425
442
  }
443
+ function configFile() {
444
+ const proc = typeof process !== "undefined" ? process : void 0;
445
+ if (!proc?.versions?.node) return void 0;
446
+ const files = nodeFiles ?? lookedUp(proc);
447
+ if (!files) return void 0;
448
+ const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
449
+ return { files, path: files.join(home, "config.json") };
450
+ }
451
+ function noKey() {
452
+ let file;
453
+ try {
454
+ file = configFile()?.path;
455
+ } catch {
456
+ file = void 0;
457
+ }
458
+ return new KorelyError(
459
+ `No API key. Pass { apiKey: 'kor_live_...' } or set KORELY_API_KEY. No key yet: make one once, by hand, on Korely Cloud: curl -X POST https://api.korely.ai/v1/agents/init -H 'Content-Type: application/json' -d '{"agent_caller": "your-name-here"}' (or Korely.initAgent() run once), then set KORELY_API_KEY. Each call makes a new account; the answer shows the key once and says when it ends. A Self-hosted install makes its keys in its dashboard.` + (file ? ` On Node a key saved by \`korely init\`, the command of the Python package (pip install korely-memory), is read too, from ${file}.` : "")
460
+ );
461
+ }
426
462
  function lookedUp(proc) {
427
463
  const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof __require === "function" ? __require(id) : void 0;
428
464
  const fs = builtin("node:fs");
@@ -442,9 +478,7 @@ var Korely = class {
442
478
  const saved = opts.apiKey && (opts.baseUrl || envBase) ? {} : savedConfig();
443
479
  const key = opts.apiKey ?? envKey ?? text(saved.api_key);
444
480
  if (!key) {
445
- throw new KorelyError(
446
- "No API key. Pass { apiKey: 'kor_live_...' }, set KORELY_API_KEY, or run `korely init`, which saves one to ~/.korely/config.json."
447
- );
481
+ throw noKey();
448
482
  }
449
483
  this.apiKey = key;
450
484
  const envClient = typeof process !== "undefined" ? process.env?.KORELY_CLIENT : void 0;
@@ -461,13 +495,16 @@ var Korely = class {
461
495
  this.fetchImpl = f;
462
496
  }
463
497
  /**
464
- * POST /v1/agents/init, with no key: sign up for a free hobby key.
498
+ * POST /v1/agents/init, with no key: sign up for a key that costs nothing.
465
499
  *
466
500
  * The one call that runs without a key, because it is how one is obtained,
467
501
  * so it is static: `await Korely.initAgent("my-app")`, then
468
502
  * `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
469
503
  * label of who signed up, kept for your reference. The answer carries the
470
- * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
504
+ * key, shown once (save it), when it stops working (`expires_at`), the
505
+ * trial in words (`note`: its limits until the account is adopted, and how
506
+ * to adopt it), its `tier`, `region`, `scopes` and `quotas` (the monthly
507
+ * numbers once adopted).
471
508
  * The account it creates has no login: the key is the account, and
472
509
  * `deleteAccount({ confirm: "<the account's id>" })` closes it.
473
510
  *
@@ -732,14 +769,17 @@ var Korely = class {
732
769
  metadata: opts.metadata,
733
770
  timestamp: opts.timestamp,
734
771
  kind: opts.kind
735
- }
772
+ },
773
+ headers: idempotencyHeader(opts.idempotency_key)
736
774
  });
737
775
  }
738
776
  /**
739
777
  * POST /v1/memories/search: semantic search over raw memories, ranked by
740
- * score (vector similarity to the query). `run_id` scopes to one session,
741
- * `metadata` filters on what you stored at write time. `limit` defaults to
742
- * the server default (15), max 50.
778
+ * score (vector similarity to the query); with `types`, over the facts too,
779
+ * or the facts only. `run_id` scopes to one session, `metadata` filters on
780
+ * what you stored at write time. `limit` defaults to the server default
781
+ * (15), max 50. `full_text: true` adds each result's whole text as
782
+ * `content`.
743
783
  */
744
784
  async search(query, opts = {}) {
745
785
  checkOptions("search", opts, SEARCH_KEYS);
@@ -753,7 +793,10 @@ var Korely = class {
753
793
  limit: opts.limit,
754
794
  min_score: opts.min_score,
755
795
  // Sent only when true: an older server does not know the field.
756
- exclude_sessions: opts.exclude_sessions ? true : void 0
796
+ exclude_sessions: opts.exclude_sessions ? true : void 0,
797
+ // Sent only when given, as `min_score`: Korely 1.0.13 and later.
798
+ types: opts.types,
799
+ full_text: opts.full_text ? true : void 0
757
800
  }
758
801
  });
759
802
  return body.results ?? [];
@@ -1106,8 +1149,11 @@ var Korely = class {
1106
1149
  * `too_many_batches` (TooManyBatchesError) while three batches are still
1107
1150
  * being imported. The Self-hosted meters nothing and refuses neither.
1108
1151
  */
1109
- async batch(memories) {
1110
- return this.request("POST", "/v1/batch", { body: { memories } });
1152
+ async batch(memories, opts = {}) {
1153
+ return this.request("POST", "/v1/batch", {
1154
+ body: { memories },
1155
+ headers: idempotencyHeader(opts.idempotency_key)
1156
+ });
1111
1157
  }
1112
1158
  /** GET /v1/batch/:id: poll an import job. */
1113
1159
  async batchStatus(jobId) {
package/dist/index.cjs CHANGED
@@ -126,11 +126,28 @@ function unknownOption(method, opts, known) {
126
126
  }
127
127
 
128
128
  // src/client.ts
129
- var VERSION = "0.2.0";
129
+ var VERSION = "0.2.1";
130
130
  var REGIONS = { eu: "https://api.korely.ai" };
131
131
  var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch", "client");
132
132
  var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
133
- var ADD_KEYS = keysOf()("agent_id", "user_id", "run_id", "metadata", "timestamp", "kind");
133
+ var ADD_KEYS = keysOf()(
134
+ "agent_id",
135
+ "user_id",
136
+ "run_id",
137
+ "metadata",
138
+ "timestamp",
139
+ "kind",
140
+ "idempotency_key"
141
+ );
142
+ function idempotencyHeader(key) {
143
+ if (key === void 0) return void 0;
144
+ if (typeof key !== "string" || !/^[\x20-\x7e]{1,255}$/.test(key)) {
145
+ throw new KorelyError(
146
+ "idempotency_key must be 1 to 255 printable ASCII characters (space to ~), one per write: a UUID will do."
147
+ );
148
+ }
149
+ return { "Idempotency-Key": `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"` };
150
+ }
134
151
  var SEARCH_KEYS = keysOf()(
135
152
  "user_id",
136
153
  "agent_id",
@@ -138,7 +155,9 @@ var SEARCH_KEYS = keysOf()(
138
155
  "metadata",
139
156
  "limit",
140
157
  "min_score",
141
- "exclude_sessions"
158
+ "exclude_sessions",
159
+ "types",
160
+ "full_text"
142
161
  );
143
162
  var LIST_KEYS = keysOf()("user_id", "agent_id", "run_id", "limit", "offset", "exclude_sessions");
144
163
  var NAME_KEYS = keysOf()("user_id", "agent_id");
@@ -356,6 +375,7 @@ async function exchange(t, method, path, opts = {}) {
356
375
  body = JSON.stringify(opts.body);
357
376
  headers["Content-Type"] = "application/json";
358
377
  }
378
+ Object.assign(headers, opts.headers);
359
379
  const controller = new AbortController();
360
380
  let timedOut = false;
361
381
  const timer = setTimeout(() => {
@@ -458,17 +478,33 @@ function raiseFor(status, body, retryAfter, redirect, method) {
458
478
  var nodeFiles;
459
479
  function savedConfig() {
460
480
  try {
461
- const proc = typeof process !== "undefined" ? process : void 0;
462
- if (!proc?.versions?.node) return {};
463
- const files = nodeFiles ?? lookedUp(proc);
464
- if (!files) return {};
465
- const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
466
- const data = JSON.parse(files.readFileSync(files.join(home, "config.json"), "utf8"));
481
+ const at = configFile();
482
+ if (!at) return {};
483
+ const data = JSON.parse(at.files.readFileSync(at.path, "utf8"));
467
484
  return data && typeof data === "object" ? data : {};
468
485
  } catch {
469
486
  return {};
470
487
  }
471
488
  }
489
+ function configFile() {
490
+ const proc = typeof process !== "undefined" ? process : void 0;
491
+ if (!proc?.versions?.node) return void 0;
492
+ const files = nodeFiles ?? lookedUp(proc);
493
+ if (!files) return void 0;
494
+ const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
495
+ return { files, path: files.join(home, "config.json") };
496
+ }
497
+ function noKey() {
498
+ let file;
499
+ try {
500
+ file = configFile()?.path;
501
+ } catch {
502
+ file = void 0;
503
+ }
504
+ return new KorelyError(
505
+ `No API key. Pass { apiKey: 'kor_live_...' } or set KORELY_API_KEY. No key yet: make one once, by hand, on Korely Cloud: curl -X POST https://api.korely.ai/v1/agents/init -H 'Content-Type: application/json' -d '{"agent_caller": "your-name-here"}' (or Korely.initAgent() run once), then set KORELY_API_KEY. Each call makes a new account; the answer shows the key once and says when it ends. A Self-hosted install makes its keys in its dashboard.` + (file ? ` On Node a key saved by \`korely init\`, the command of the Python package (pip install korely-memory), is read too, from ${file}.` : "")
506
+ );
507
+ }
472
508
  function lookedUp(proc) {
473
509
  const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof require === "function" ? require(id) : void 0;
474
510
  const fs = builtin("node:fs");
@@ -488,9 +524,7 @@ var Korely = class {
488
524
  const saved = opts.apiKey && (opts.baseUrl || envBase) ? {} : savedConfig();
489
525
  const key = opts.apiKey ?? envKey ?? text(saved.api_key);
490
526
  if (!key) {
491
- throw new KorelyError(
492
- "No API key. Pass { apiKey: 'kor_live_...' }, set KORELY_API_KEY, or run `korely init`, which saves one to ~/.korely/config.json."
493
- );
527
+ throw noKey();
494
528
  }
495
529
  this.apiKey = key;
496
530
  const envClient = typeof process !== "undefined" ? process.env?.KORELY_CLIENT : void 0;
@@ -507,13 +541,16 @@ var Korely = class {
507
541
  this.fetchImpl = f;
508
542
  }
509
543
  /**
510
- * POST /v1/agents/init, with no key: sign up for a free hobby key.
544
+ * POST /v1/agents/init, with no key: sign up for a key that costs nothing.
511
545
  *
512
546
  * The one call that runs without a key, because it is how one is obtained,
513
547
  * so it is static: `await Korely.initAgent("my-app")`, then
514
548
  * `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
515
549
  * label of who signed up, kept for your reference. The answer carries the
516
- * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
550
+ * key, shown once (save it), when it stops working (`expires_at`), the
551
+ * trial in words (`note`: its limits until the account is adopted, and how
552
+ * to adopt it), its `tier`, `region`, `scopes` and `quotas` (the monthly
553
+ * numbers once adopted).
517
554
  * The account it creates has no login: the key is the account, and
518
555
  * `deleteAccount({ confirm: "<the account's id>" })` closes it.
519
556
  *
@@ -778,14 +815,17 @@ var Korely = class {
778
815
  metadata: opts.metadata,
779
816
  timestamp: opts.timestamp,
780
817
  kind: opts.kind
781
- }
818
+ },
819
+ headers: idempotencyHeader(opts.idempotency_key)
782
820
  });
783
821
  }
784
822
  /**
785
823
  * POST /v1/memories/search: semantic search over raw memories, ranked by
786
- * score (vector similarity to the query). `run_id` scopes to one session,
787
- * `metadata` filters on what you stored at write time. `limit` defaults to
788
- * the server default (15), max 50.
824
+ * score (vector similarity to the query); with `types`, over the facts too,
825
+ * or the facts only. `run_id` scopes to one session, `metadata` filters on
826
+ * what you stored at write time. `limit` defaults to the server default
827
+ * (15), max 50. `full_text: true` adds each result's whole text as
828
+ * `content`.
789
829
  */
790
830
  async search(query, opts = {}) {
791
831
  checkOptions("search", opts, SEARCH_KEYS);
@@ -799,7 +839,10 @@ var Korely = class {
799
839
  limit: opts.limit,
800
840
  min_score: opts.min_score,
801
841
  // Sent only when true: an older server does not know the field.
802
- exclude_sessions: opts.exclude_sessions ? true : void 0
842
+ exclude_sessions: opts.exclude_sessions ? true : void 0,
843
+ // Sent only when given, as `min_score`: Korely 1.0.13 and later.
844
+ types: opts.types,
845
+ full_text: opts.full_text ? true : void 0
803
846
  }
804
847
  });
805
848
  return body.results ?? [];
@@ -1152,8 +1195,11 @@ var Korely = class {
1152
1195
  * `too_many_batches` (TooManyBatchesError) while three batches are still
1153
1196
  * being imported. The Self-hosted meters nothing and refuses neither.
1154
1197
  */
1155
- async batch(memories) {
1156
- return this.request("POST", "/v1/batch", { body: { memories } });
1198
+ async batch(memories, opts = {}) {
1199
+ return this.request("POST", "/v1/batch", {
1200
+ body: { memories },
1201
+ headers: idempotencyHeader(opts.idempotency_key)
1202
+ });
1157
1203
  }
1158
1204
  /** GET /v1/batch/:id: poll an import job. */
1159
1205
  async batchStatus(jobId) {
package/dist/index.d.cts CHANGED
@@ -78,13 +78,25 @@ interface Memory {
78
78
  /** "note" or "session" (Korely Agent 0.1.42); absent from an older server. */
79
79
  kind?: "note" | "session";
80
80
  }
81
+ /** What `search()` may search, each once in `types`: the memories, or the
82
+ * facts true now (Korely 1.0.13 and later). */
83
+ type SearchKind = "memories" | "facts";
81
84
  interface SearchHit {
82
85
  id?: string;
83
86
  score?: number;
87
+ /** The first 280 characters of the text. */
84
88
  snippet?: string;
85
89
  user_id?: string;
86
90
  agent_id?: string;
87
91
  metadata?: Record<string, unknown>;
92
+ /** "memory" or "fact": in every result when the search names `types`
93
+ * (Korely 1.0.13 and later), absent otherwise. */
94
+ type?: "memory" | "fact" | string;
95
+ /** The whole text (a memory's as stored, a fact's line): only with
96
+ * `full_text: true` (Korely 1.0.13 and later). */
97
+ content?: string;
98
+ /** A fact's result: the fact as `getFacts()` shows it. Absent for a memory. */
99
+ fact?: Fact;
88
100
  }
89
101
  /** Iterable like the Python SDK's MemoryPage: `for (const m of page)` works,
90
102
  * and `page.memories` / `page.total` still do. */
@@ -318,7 +330,7 @@ interface PingResponse {
318
330
  /** What the key may do, e.g. "memories:read". */
319
331
  scopes: string[];
320
332
  }
321
- /** What `Korely.initAgent()` answers: a new hobby key and what it buys. */
333
+ /** What `Korely.initAgent()` answers: a new key, when it ends, and what the account may do. */
322
334
  interface AgentInitResult {
323
335
  /** The key, shown this once and never again: save it. */
324
336
  api_key: string;
@@ -327,7 +339,16 @@ interface AgentInitResult {
327
339
  /** Where the new project's memories are read by a model. */
328
340
  processing_region?: "eu" | "global";
329
341
  scopes: string[];
330
- /** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
342
+ /** When the key stops working (ISO 8601, with its time zone). Absent from a
343
+ * server older than Korely Agent 1.0.10. */
344
+ expires_at?: string;
345
+ /** The same in the server's words: how long the key lasts, the trial's
346
+ * limits until the account is adopted, and how to adopt it. Absent from a
347
+ * server older than Korely Agent 1.0.10. */
348
+ note?: string;
349
+ /** The free plan's monthly allowance: writes_per_month, queries_per_month,
350
+ * agents, the monthly AI budget. With a `note`, it applies once the account
351
+ * is adopted; until then the trial's limits do. */
331
352
  quotas: Record<string, unknown>;
332
353
  /** The Terms of Service that creating the account accepts. Absent from a
333
354
  * server older than Korely Agent 0.1.27. */
@@ -418,6 +439,14 @@ interface AddOptions {
418
439
  * field with a 422.
419
440
  */
420
441
  kind?: "note" | "session";
442
+ /**
443
+ * Send the same write again with the same key and it is made once (Korely
444
+ * Agent 1.0.27 and later; an older server ignores it). One new key per
445
+ * write, the same one only to send that write again: a write whose answer
446
+ * never came (a timeout, a 502 while the server restarted) may have been
447
+ * made, and without a key a resend makes it twice.
448
+ */
449
+ idempotency_key?: string;
421
450
  }
422
451
  /** What `declareName` declared: in `user_id`'s memory (`agent_id` the
423
452
  * namespace, none for the end user's own) the facts about `name` read as the
@@ -450,6 +479,22 @@ interface SearchOptions {
450
479
  min_score?: number;
451
480
  /** Leave out the work sessions (`kind: "session"`) and what only they stated (Korely Agent 0.1.42). */
452
481
  exclude_sessions?: boolean;
482
+ /**
483
+ * What to search, each kind once: `["memories"]` (what the server searches
484
+ * when it is not sent), `["facts"]`, the facts true now, or both, each kind
485
+ * ranked by its own score and the rankings merged by rank (a fact's score
486
+ * and a memory's are not to be compared). Every result then says its
487
+ * `type`, and a fact's carries `fact`. `run_id`, `metadata` and `min_score`
488
+ * narrow the memories only: with `"facts"` the server answers 422. Sent
489
+ * only when given: Korely 1.0.13 and later; an older server answers 422.
490
+ */
491
+ types?: SearchKind[];
492
+ /**
493
+ * Also return each result's whole text as `content`; `snippet` stays its
494
+ * first 280 characters. A memory can hold 16,000 characters. Sent only
495
+ * when true: Korely 1.0.13 and later; an older server answers 422.
496
+ */
497
+ full_text?: boolean;
453
498
  }
454
499
  interface ListOptions {
455
500
  user_id?: string;
@@ -580,7 +625,7 @@ interface ForgetReceipt {
580
625
 
581
626
  /** Must equal `version` in package.json (a test checks). It goes out in the
582
627
  * X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
583
- declare const VERSION = "0.2.0";
628
+ declare const VERSION = "0.2.1";
584
629
  interface KorelyOptions {
585
630
  /** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
586
631
  apiKey?: string;
@@ -622,13 +667,16 @@ declare class Korely {
622
667
  private readonly fetchImpl;
623
668
  constructor(opts?: KorelyOptions);
624
669
  /**
625
- * POST /v1/agents/init, with no key: sign up for a free hobby key.
670
+ * POST /v1/agents/init, with no key: sign up for a key that costs nothing.
626
671
  *
627
672
  * The one call that runs without a key, because it is how one is obtained,
628
673
  * so it is static: `await Korely.initAgent("my-app")`, then
629
674
  * `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
630
675
  * label of who signed up, kept for your reference. The answer carries the
631
- * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
676
+ * key, shown once (save it), when it stops working (`expires_at`), the
677
+ * trial in words (`note`: its limits until the account is adopted, and how
678
+ * to adopt it), its `tier`, `region`, `scopes` and `quotas` (the monthly
679
+ * numbers once adopted).
632
680
  * The account it creates has no login: the key is the account, and
633
681
  * `deleteAccount({ confirm: "<the account's id>" })` closes it.
634
682
  *
@@ -745,9 +793,11 @@ declare class Korely {
745
793
  add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
746
794
  /**
747
795
  * POST /v1/memories/search: semantic search over raw memories, ranked by
748
- * score (vector similarity to the query). `run_id` scopes to one session,
749
- * `metadata` filters on what you stored at write time. `limit` defaults to
750
- * the server default (15), max 50.
796
+ * score (vector similarity to the query); with `types`, over the facts too,
797
+ * or the facts only. `run_id` scopes to one session, `metadata` filters on
798
+ * what you stored at write time. `limit` defaults to the server default
799
+ * (15), max 50. `full_text: true` adds each result's whole text as
800
+ * `content`.
751
801
  */
752
802
  search(query: string, opts?: SearchOptions): Promise<SearchHit[]>;
753
803
  /**
@@ -936,7 +986,9 @@ declare class Korely {
936
986
  * `too_many_batches` (TooManyBatchesError) while three batches are still
937
987
  * being imported. The Self-hosted meters nothing and refuses neither.
938
988
  */
939
- batch(memories: Array<BatchMemory | Record<string, unknown>>): Promise<BatchJob>;
989
+ batch(memories: Array<BatchMemory | Record<string, unknown>>, opts?: {
990
+ idempotency_key?: string;
991
+ }): Promise<BatchJob>;
940
992
  /** GET /v1/batch/:id: poll an import job. */
941
993
  batchStatus(jobId: string): Promise<BatchJob>;
942
994
  }
@@ -1085,4 +1137,4 @@ declare class TooManyBatchesError extends QuotaExceededError {
1085
1137
  constructor(message?: string, opts?: QuotaErrorOptions);
1086
1138
  }
1087
1139
 
1088
- export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeclareNameOptions, type DeclaredName, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
1140
+ export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeclareNameOptions, type DeclaredName, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchKind, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
package/dist/index.d.ts CHANGED
@@ -78,13 +78,25 @@ interface Memory {
78
78
  /** "note" or "session" (Korely Agent 0.1.42); absent from an older server. */
79
79
  kind?: "note" | "session";
80
80
  }
81
+ /** What `search()` may search, each once in `types`: the memories, or the
82
+ * facts true now (Korely 1.0.13 and later). */
83
+ type SearchKind = "memories" | "facts";
81
84
  interface SearchHit {
82
85
  id?: string;
83
86
  score?: number;
87
+ /** The first 280 characters of the text. */
84
88
  snippet?: string;
85
89
  user_id?: string;
86
90
  agent_id?: string;
87
91
  metadata?: Record<string, unknown>;
92
+ /** "memory" or "fact": in every result when the search names `types`
93
+ * (Korely 1.0.13 and later), absent otherwise. */
94
+ type?: "memory" | "fact" | string;
95
+ /** The whole text (a memory's as stored, a fact's line): only with
96
+ * `full_text: true` (Korely 1.0.13 and later). */
97
+ content?: string;
98
+ /** A fact's result: the fact as `getFacts()` shows it. Absent for a memory. */
99
+ fact?: Fact;
88
100
  }
89
101
  /** Iterable like the Python SDK's MemoryPage: `for (const m of page)` works,
90
102
  * and `page.memories` / `page.total` still do. */
@@ -318,7 +330,7 @@ interface PingResponse {
318
330
  /** What the key may do, e.g. "memories:read". */
319
331
  scopes: string[];
320
332
  }
321
- /** What `Korely.initAgent()` answers: a new hobby key and what it buys. */
333
+ /** What `Korely.initAgent()` answers: a new key, when it ends, and what the account may do. */
322
334
  interface AgentInitResult {
323
335
  /** The key, shown this once and never again: save it. */
324
336
  api_key: string;
@@ -327,7 +339,16 @@ interface AgentInitResult {
327
339
  /** Where the new project's memories are read by a model. */
328
340
  processing_region?: "eu" | "global";
329
341
  scopes: string[];
330
- /** The hobby allowance: writes_per_month, queries_per_month, agents, the monthly AI budget. */
342
+ /** When the key stops working (ISO 8601, with its time zone). Absent from a
343
+ * server older than Korely Agent 1.0.10. */
344
+ expires_at?: string;
345
+ /** The same in the server's words: how long the key lasts, the trial's
346
+ * limits until the account is adopted, and how to adopt it. Absent from a
347
+ * server older than Korely Agent 1.0.10. */
348
+ note?: string;
349
+ /** The free plan's monthly allowance: writes_per_month, queries_per_month,
350
+ * agents, the monthly AI budget. With a `note`, it applies once the account
351
+ * is adopted; until then the trial's limits do. */
331
352
  quotas: Record<string, unknown>;
332
353
  /** The Terms of Service that creating the account accepts. Absent from a
333
354
  * server older than Korely Agent 0.1.27. */
@@ -418,6 +439,14 @@ interface AddOptions {
418
439
  * field with a 422.
419
440
  */
420
441
  kind?: "note" | "session";
442
+ /**
443
+ * Send the same write again with the same key and it is made once (Korely
444
+ * Agent 1.0.27 and later; an older server ignores it). One new key per
445
+ * write, the same one only to send that write again: a write whose answer
446
+ * never came (a timeout, a 502 while the server restarted) may have been
447
+ * made, and without a key a resend makes it twice.
448
+ */
449
+ idempotency_key?: string;
421
450
  }
422
451
  /** What `declareName` declared: in `user_id`'s memory (`agent_id` the
423
452
  * namespace, none for the end user's own) the facts about `name` read as the
@@ -450,6 +479,22 @@ interface SearchOptions {
450
479
  min_score?: number;
451
480
  /** Leave out the work sessions (`kind: "session"`) and what only they stated (Korely Agent 0.1.42). */
452
481
  exclude_sessions?: boolean;
482
+ /**
483
+ * What to search, each kind once: `["memories"]` (what the server searches
484
+ * when it is not sent), `["facts"]`, the facts true now, or both, each kind
485
+ * ranked by its own score and the rankings merged by rank (a fact's score
486
+ * and a memory's are not to be compared). Every result then says its
487
+ * `type`, and a fact's carries `fact`. `run_id`, `metadata` and `min_score`
488
+ * narrow the memories only: with `"facts"` the server answers 422. Sent
489
+ * only when given: Korely 1.0.13 and later; an older server answers 422.
490
+ */
491
+ types?: SearchKind[];
492
+ /**
493
+ * Also return each result's whole text as `content`; `snippet` stays its
494
+ * first 280 characters. A memory can hold 16,000 characters. Sent only
495
+ * when true: Korely 1.0.13 and later; an older server answers 422.
496
+ */
497
+ full_text?: boolean;
453
498
  }
454
499
  interface ListOptions {
455
500
  user_id?: string;
@@ -580,7 +625,7 @@ interface ForgetReceipt {
580
625
 
581
626
  /** Must equal `version` in package.json (a test checks). It goes out in the
582
627
  * X-Korely-Client header, and said 0.1.1 from 0.1.1 to 0.1.6. */
583
- declare const VERSION = "0.2.0";
628
+ declare const VERSION = "0.2.1";
584
629
  interface KorelyOptions {
585
630
  /** Your `kor_live_...` key. Falls back to the KORELY_API_KEY env var. */
586
631
  apiKey?: string;
@@ -622,13 +667,16 @@ declare class Korely {
622
667
  private readonly fetchImpl;
623
668
  constructor(opts?: KorelyOptions);
624
669
  /**
625
- * POST /v1/agents/init, with no key: sign up for a free hobby key.
670
+ * POST /v1/agents/init, with no key: sign up for a key that costs nothing.
626
671
  *
627
672
  * The one call that runs without a key, because it is how one is obtained,
628
673
  * so it is static: `await Korely.initAgent("my-app")`, then
629
674
  * `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
630
675
  * label of who signed up, kept for your reference. The answer carries the
631
- * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
676
+ * key, shown once (save it), when it stops working (`expires_at`), the
677
+ * trial in words (`note`: its limits until the account is adopted, and how
678
+ * to adopt it), its `tier`, `region`, `scopes` and `quotas` (the monthly
679
+ * numbers once adopted).
632
680
  * The account it creates has no login: the key is the account, and
633
681
  * `deleteAccount({ confirm: "<the account's id>" })` closes it.
634
682
  *
@@ -745,9 +793,11 @@ declare class Korely {
745
793
  add(content: string | Message[], opts?: AddOptions): Promise<Memory>;
746
794
  /**
747
795
  * POST /v1/memories/search: semantic search over raw memories, ranked by
748
- * score (vector similarity to the query). `run_id` scopes to one session,
749
- * `metadata` filters on what you stored at write time. `limit` defaults to
750
- * the server default (15), max 50.
796
+ * score (vector similarity to the query); with `types`, over the facts too,
797
+ * or the facts only. `run_id` scopes to one session, `metadata` filters on
798
+ * what you stored at write time. `limit` defaults to the server default
799
+ * (15), max 50. `full_text: true` adds each result's whole text as
800
+ * `content`.
751
801
  */
752
802
  search(query: string, opts?: SearchOptions): Promise<SearchHit[]>;
753
803
  /**
@@ -936,7 +986,9 @@ declare class Korely {
936
986
  * `too_many_batches` (TooManyBatchesError) while three batches are still
937
987
  * being imported. The Self-hosted meters nothing and refuses neither.
938
988
  */
939
- batch(memories: Array<BatchMemory | Record<string, unknown>>): Promise<BatchJob>;
989
+ batch(memories: Array<BatchMemory | Record<string, unknown>>, opts?: {
990
+ idempotency_key?: string;
991
+ }): Promise<BatchJob>;
940
992
  /** GET /v1/batch/:id: poll an import job. */
941
993
  batchStatus(jobId: string): Promise<BatchJob>;
942
994
  }
@@ -1085,4 +1137,4 @@ declare class TooManyBatchesError extends QuotaExceededError {
1085
1137
  constructor(message?: string, opts?: QuotaErrorOptions);
1086
1138
  }
1087
1139
 
1088
- export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeclareNameOptions, type DeclaredName, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
1140
+ export { APIError, type AccountDeleteReceipt, type AddFactTripleOptions, type AddOptions, type AgentDeleteReceipt, type AgentInitResult, type AgentScope, type AgentsPage, type AuditAction, type AuditActor, type AuditEvent, type AuditOptions, type AuditPage, type AuditRead, AuthenticationError, type BatchJob, type BatchMemory, type BulkReceipt, ConflictError, type Context, type DeclareNameOptions, type DeclaredName, type DeleteReceipt, type EventsOptions, type EventsResponse, type Fact, type FactList, type ForgetReceipt, type GetContextOptions, type GetFactsOptions, type GetProfileOptions, type HistoryEvent, type HistoryEventType, type InitAgentOptions, type IterAuditOptions, Korely, KorelyError, type KorelyOptions, type ListAgentsOptions, type ListOptions, type Memory, type MemoryEvent, type MemoryHistory, type MemoryPage, type Message, NamespaceForbiddenError, NotFoundError, type PingResponse, type Profile, QuotaExceededError, type SearchHit, type SearchKind, type SearchOptions, StaleWriteError, TooManyBatchesError, type UpdateOptions, type UserScope, type UsersOptions, type UsersPage, VERSION };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  StaleWriteError,
11
11
  TooManyBatchesError,
12
12
  VERSION
13
- } from "./chunk-VT7GXOPS.js";
13
+ } from "./chunk-MZLXQMBY.js";
14
14
  import "./chunk-6SD5RRK3.js";
15
15
  export {
16
16
  APIError,
@@ -129,11 +129,28 @@ function unknownOption(method, opts, known) {
129
129
  }
130
130
 
131
131
  // src/client.ts
132
- var VERSION = "0.2.0";
132
+ var VERSION = "0.2.1";
133
133
  var REGIONS = { eu: "https://api.korely.ai" };
134
134
  var CLIENT_KEYS = keysOf()("apiKey", "region", "baseUrl", "timeoutMs", "fetch", "client");
135
135
  var INIT_KEYS = keysOf()("region", "baseUrl", "timeoutMs", "fetch", "processingRegion");
136
- var ADD_KEYS = keysOf()("agent_id", "user_id", "run_id", "metadata", "timestamp", "kind");
136
+ var ADD_KEYS = keysOf()(
137
+ "agent_id",
138
+ "user_id",
139
+ "run_id",
140
+ "metadata",
141
+ "timestamp",
142
+ "kind",
143
+ "idempotency_key"
144
+ );
145
+ function idempotencyHeader(key) {
146
+ if (key === void 0) return void 0;
147
+ if (typeof key !== "string" || !/^[\x20-\x7e]{1,255}$/.test(key)) {
148
+ throw new KorelyError(
149
+ "idempotency_key must be 1 to 255 printable ASCII characters (space to ~), one per write: a UUID will do."
150
+ );
151
+ }
152
+ return { "Idempotency-Key": `"${key.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"` };
153
+ }
137
154
  var SEARCH_KEYS = keysOf()(
138
155
  "user_id",
139
156
  "agent_id",
@@ -141,7 +158,9 @@ var SEARCH_KEYS = keysOf()(
141
158
  "metadata",
142
159
  "limit",
143
160
  "min_score",
144
- "exclude_sessions"
161
+ "exclude_sessions",
162
+ "types",
163
+ "full_text"
145
164
  );
146
165
  var LIST_KEYS = keysOf()("user_id", "agent_id", "run_id", "limit", "offset", "exclude_sessions");
147
166
  var NAME_KEYS = keysOf()("user_id", "agent_id");
@@ -359,6 +378,7 @@ async function exchange(t, method, path, opts = {}) {
359
378
  body = JSON.stringify(opts.body);
360
379
  headers["Content-Type"] = "application/json";
361
380
  }
381
+ Object.assign(headers, opts.headers);
362
382
  const controller = new AbortController();
363
383
  let timedOut = false;
364
384
  const timer = setTimeout(() => {
@@ -464,17 +484,33 @@ function useNodeFiles(files) {
464
484
  }
465
485
  function savedConfig() {
466
486
  try {
467
- const proc = typeof process !== "undefined" ? process : void 0;
468
- if (!proc?.versions?.node) return {};
469
- const files = nodeFiles ?? lookedUp(proc);
470
- if (!files) return {};
471
- const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
472
- const data = JSON.parse(files.readFileSync(files.join(home, "config.json"), "utf8"));
487
+ const at = configFile();
488
+ if (!at) return {};
489
+ const data = JSON.parse(at.files.readFileSync(at.path, "utf8"));
473
490
  return data && typeof data === "object" ? data : {};
474
491
  } catch {
475
492
  return {};
476
493
  }
477
494
  }
495
+ function configFile() {
496
+ const proc = typeof process !== "undefined" ? process : void 0;
497
+ if (!proc?.versions?.node) return void 0;
498
+ const files = nodeFiles ?? lookedUp(proc);
499
+ if (!files) return void 0;
500
+ const home = proc.env?.KORELY_CONFIG_HOME || files.join(files.homedir(), ".korely");
501
+ return { files, path: files.join(home, "config.json") };
502
+ }
503
+ function noKey() {
504
+ let file;
505
+ try {
506
+ file = configFile()?.path;
507
+ } catch {
508
+ file = void 0;
509
+ }
510
+ return new KorelyError(
511
+ `No API key. Pass { apiKey: 'kor_live_...' } or set KORELY_API_KEY. No key yet: make one once, by hand, on Korely Cloud: curl -X POST https://api.korely.ai/v1/agents/init -H 'Content-Type: application/json' -d '{"agent_caller": "your-name-here"}' (or Korely.initAgent() run once), then set KORELY_API_KEY. Each call makes a new account; the answer shows the key once and says when it ends. A Self-hosted install makes its keys in its dashboard.` + (file ? ` On Node a key saved by \`korely init\`, the command of the Python package (pip install korely-memory), is read too, from ${file}.` : "")
512
+ );
513
+ }
478
514
  function lookedUp(proc) {
479
515
  const builtin = (id) => typeof proc.getBuiltinModule === "function" ? proc.getBuiltinModule(id) : typeof require === "function" ? require(id) : void 0;
480
516
  const fs = builtin("node:fs");
@@ -494,9 +530,7 @@ var Korely = class {
494
530
  const saved = opts.apiKey && (opts.baseUrl || envBase) ? {} : savedConfig();
495
531
  const key = opts.apiKey ?? envKey ?? text(saved.api_key);
496
532
  if (!key) {
497
- throw new KorelyError(
498
- "No API key. Pass { apiKey: 'kor_live_...' }, set KORELY_API_KEY, or run `korely init`, which saves one to ~/.korely/config.json."
499
- );
533
+ throw noKey();
500
534
  }
501
535
  this.apiKey = key;
502
536
  const envClient = typeof process !== "undefined" ? process.env?.KORELY_CLIENT : void 0;
@@ -513,13 +547,16 @@ var Korely = class {
513
547
  this.fetchImpl = f;
514
548
  }
515
549
  /**
516
- * POST /v1/agents/init, with no key: sign up for a free hobby key.
550
+ * POST /v1/agents/init, with no key: sign up for a key that costs nothing.
517
551
  *
518
552
  * The one call that runs without a key, because it is how one is obtained,
519
553
  * so it is static: `await Korely.initAgent("my-app")`, then
520
554
  * `new Korely({ apiKey: result.api_key })`. `agentCaller` is a free-form
521
555
  * label of who signed up, kept for your reference. The answer carries the
522
- * key, shown once (save it), its `tier`, `region`, `scopes` and `quotas`.
556
+ * key, shown once (save it), when it stops working (`expires_at`), the
557
+ * trial in words (`note`: its limits until the account is adopted, and how
558
+ * to adopt it), its `tier`, `region`, `scopes` and `quotas` (the monthly
559
+ * numbers once adopted).
523
560
  * The account it creates has no login: the key is the account, and
524
561
  * `deleteAccount({ confirm: "<the account's id>" })` closes it.
525
562
  *
@@ -784,14 +821,17 @@ var Korely = class {
784
821
  metadata: opts.metadata,
785
822
  timestamp: opts.timestamp,
786
823
  kind: opts.kind
787
- }
824
+ },
825
+ headers: idempotencyHeader(opts.idempotency_key)
788
826
  });
789
827
  }
790
828
  /**
791
829
  * POST /v1/memories/search: semantic search over raw memories, ranked by
792
- * score (vector similarity to the query). `run_id` scopes to one session,
793
- * `metadata` filters on what you stored at write time. `limit` defaults to
794
- * the server default (15), max 50.
830
+ * score (vector similarity to the query); with `types`, over the facts too,
831
+ * or the facts only. `run_id` scopes to one session, `metadata` filters on
832
+ * what you stored at write time. `limit` defaults to the server default
833
+ * (15), max 50. `full_text: true` adds each result's whole text as
834
+ * `content`.
795
835
  */
796
836
  async search(query, opts = {}) {
797
837
  checkOptions("search", opts, SEARCH_KEYS);
@@ -805,7 +845,10 @@ var Korely = class {
805
845
  limit: opts.limit,
806
846
  min_score: opts.min_score,
807
847
  // Sent only when true: an older server does not know the field.
808
- exclude_sessions: opts.exclude_sessions ? true : void 0
848
+ exclude_sessions: opts.exclude_sessions ? true : void 0,
849
+ // Sent only when given, as `min_score`: Korely 1.0.13 and later.
850
+ types: opts.types,
851
+ full_text: opts.full_text ? true : void 0
809
852
  }
810
853
  });
811
854
  return body.results ?? [];
@@ -1158,8 +1201,11 @@ var Korely = class {
1158
1201
  * `too_many_batches` (TooManyBatchesError) while three batches are still
1159
1202
  * being imported. The Self-hosted meters nothing and refuses neither.
1160
1203
  */
1161
- async batch(memories) {
1162
- return this.request("POST", "/v1/batch", { body: { memories } });
1204
+ async batch(memories, opts = {}) {
1205
+ return this.request("POST", "/v1/batch", {
1206
+ body: { memories },
1207
+ headers: idempotencyHeader(opts.idempotency_key)
1208
+ });
1163
1209
  }
1164
1210
  /** GET /v1/batch/:id: poll an import job. */
1165
1211
  async batchStatus(jobId) {
@@ -11,7 +11,7 @@ import {
11
11
  TooManyBatchesError,
12
12
  VERSION,
13
13
  useNodeFiles
14
- } from "./chunk-VT7GXOPS.js";
14
+ } from "./chunk-MZLXQMBY.js";
15
15
  import "./chunk-6SD5RRK3.js";
16
16
 
17
17
  // src/node.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "korely-memory",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "JavaScript / TypeScript SDK for Korely Agents: memory for AI agents with bi-temporal typed facts.",
5
5
  "keywords": [
6
6
  "ai",