@alexein/sdk 0.3.2 → 0.3.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.4 - 2026-11-24
4
+
5
+ - `memory.user(id)` takes what the API takes since 2026-11-23: the id your app already has (a UUID, an email,
6
+ `auth0|...`), up to 128 characters with no control character, no space at either end, ASCII only. Before:
7
+ 1 to 35 letters, digits, `.`, `_` and `-`.
8
+
9
+ ## 0.3.3 - 2026-11-20
10
+
11
+ The same version as `alexein` on PyPI, which has the same changes.
12
+
13
+ - `add(text, { id: "diet" })` is typed now, and names the one item added. With several items it is a
14
+ `RangeError`: before, every item was sent with the same id, so they were edits of one another.
15
+ - `SearchResult.searchId`, and `user.feedback(resultOrSearchId, "wrong" | "missing" | "ok", { note })` to
16
+ say how a search went.
17
+ - The API's other routes: `user.subject(name, { limit })`, `user.related(ref)`,
18
+ `user.howTheyWork({ who, surface })`, `user.lessons(task)` and `user.refresh()`, answering `Subject`,
19
+ `Related`, `Ways`, `Lessons` and `Refreshed`.
20
+ - `context()` keeps each memory on one line: an excerpt's text is its header, a blank line, then what was
21
+ said, so its line breaks are made spaces. The memory itself keeps them.
22
+
3
23
  ## 0.3.2 - 2026-11-17
4
24
 
5
25
  - `QuotaExceededError`: a 402, when the organisation has used this month's events (on an add) or retrievals
package/README.md CHANGED
@@ -21,7 +21,13 @@ import { Memory } from "@alexein/sdk";
21
21
  const memory = new Memory(); // reads ALEXEIN_API_KEY
22
22
  const dana = memory.user("dana"); // your own id for one of your app users
23
23
 
24
- await dana.add("I moved to Lisbon for the job at Acme.", { role: "user", session: "onboarding" });
24
+ await dana.add("I moved to Lisbon for the job at Acme.", {
25
+ id: "move", // sent again, it edits this item, never copies it
26
+ role: "user",
27
+ author: { name: "Dana", self: true }, // Dana's own words, and her name
28
+ session: "onboarding",
29
+ wait: true, // searchable once it returns
30
+ });
25
31
  await dana.add(
26
32
  { id: "diet", kind: "note", text: "Vegetarian, allergic to peanuts." },
27
33
  { wait: true },
@@ -32,9 +38,10 @@ console.log(result.context()); // ready to paste into a prompt
32
38
  ```
33
39
 
34
40
  Make a key in the console, under **API keys**. A key belongs to one project; each app user you name
35
- with `memory.user(...)` has a memory of their own inside it. An app user id is 1 to 35 letters,
36
- digits, `.`, `_` and `-`, beginning with a letter or digit; `memory.user()` throws a `RangeError`
37
- for any other, before a request is made.
41
+ with `memory.user(...)` has a memory of their own inside it. An app user id is the id your app
42
+ already has for them (a UUID, an email, `auth0|...`): up to 128 characters, no control characters,
43
+ no space at either end, ASCII only; `memory.user()` throws a `RangeError` for any other, before a
44
+ request is made.
38
45
 
39
46
  ## Settings
40
47
 
@@ -52,7 +59,7 @@ for any other, before a request is made.
52
59
  The base URL is the API's host: `http://localhost:8210`, `http://localhost:8210/` and
53
60
  `http://localhost:8210/v2` all mean the same. The environment is read where there is a
54
61
  `process.env`; elsewhere, pass the options. `integration` adds one lowercase word to the
55
- `User-Agent` (`alexein-js/0.3.0 langgraph`), so the console's request logs show where requests came
62
+ `User-Agent` (`alexein-js/0.3.3 langgraph`), so the console's request logs show where requests came
56
63
  from.
57
64
 
58
65
  Run it on your server: a key in a browser bundle can be copied, and it speaks for every user of the
@@ -71,11 +78,16 @@ await dana.add(
71
78
  { session: "trip-may" },
72
79
  );
73
80
  await dana.add("Moving house on 1 December.", { kind: "note", expires: "2026-12-31" });
81
+ await dana.add("Vegetarian, allergic to peanuts.", { id: "diet", kind: "note" }); // the one item's id
74
82
  ```
75
83
 
76
84
  The item fields are `text` (required), `kind`, `id`, `session`, `role`, `author`, `title`, `about`,
77
- `at`, `expires` and `metadata`. The same `id` again is an edit. `wait: true` answers once the items
78
- are searchable; `redact: true` replaces phone numbers, cards, keys and the like before memory keeps
85
+ `at`, `expires` and `metadata`. The same `id` again is an edit; as an option, `id` names the one item
86
+ added, and with several items it is a `RangeError`. `wait: true` answers once the items
87
+ are searchable, so search straight after an add with `wait: true`. On what the app user says
88
+ themselves, pass `author: { name, self: true }`: memory then knows the words are theirs and what they
89
+ are called, so a question that names them ("Where does Dana live?") finds them. Without an author, a
90
+ message is kept as said by its `role`, not by anyone memory knows. `redact: true` replaces phone numbers, cards, keys and the like before memory keeps
79
91
  them. More than 500 items go as several requests, each with an `Idempotency-Key` its retries send
80
92
  again, so a retry never saves an item twice.
81
93
 
@@ -91,6 +103,12 @@ result.context(4000); // notes, then one memory per line, never longer than 4000
91
103
  for (const ref of result.refs) await dana.open(ref); // each memory whole
92
104
  ```
93
105
 
106
+ `context()` puts each memory on one line: a memory's own line breaks become spaces.
107
+
108
+ When an answer from memory turns out wrong or incomplete, say so with `dana.feedback(result, "wrong",
109
+ { note: "Dana moved to Porto in October." })` (or `"missing"`, `"ok"`): memory answers questions like it
110
+ better. It takes the result or its `result.searchId`, and needs a key that writes.
111
+
94
112
  `fast: true` answers sooner, a little less precisely, and is free. `before` and `after` (ISO dates),
95
113
  `filters`, and `provider`, `source` and `kind` narrow a search.
96
114
 
@@ -104,6 +122,10 @@ for (const ref of result.refs) await dana.open(ref); // each memory whole
104
122
  | `user.latest({ k, place, after, before, filters, ... })` | `latest` |
105
123
  | `user.around(ref, { width })` | `around` |
106
124
  | `user.open(ref)` | `open` |
125
+ | `user.subject(name, { limit })` | `subject` |
126
+ | `user.related(ref)` | `related` |
127
+ | `user.howTheyWork({ who, surface })` | `how_they_work` |
128
+ | `user.lessons(task)` | `lessons` |
107
129
  | `user.history(subject, { attribute })` | `history` |
108
130
  | `user.summary()` | `summary` |
109
131
  | `user.facts({ limit, cursor })`, `user.iterFacts()` | `facts` |
@@ -114,12 +136,16 @@ for (const ref of result.refs) await dana.open(ref); // each memory whole
114
136
  | `user.status(ids)` | `status` |
115
137
  | `user.forget({ items, sessions, refs })` | `forget` |
116
138
  | `user.correct(ref, replacement?)` | `correct` |
139
+ | `user.feedback(search, verdict, { note })` | `feedback` |
140
+ | `user.refresh()` | `refresh` |
117
141
  | `user.versions(itemId)` | `versions` |
118
142
  | `user.export({ limit, cursor })`, `user.iterExport()` | `export` |
119
143
  | `user.delete()` | `users/delete` |
120
144
 
121
145
  Every route but `me` is `POST /v2/memory/<route>`. Results are plain objects with camelCase fields
122
- (`addedAt`, `followUps`, `lastWrite`); each keeps the JSON the API sent as `.raw`. The `iter*`
146
+ (`addedAt`, `followUps`, `lastWrite`); each keeps the JSON the API sent as `.raw`. A read of an app
147
+ user nothing was ever added for throws `NotFoundError`, `item()` included; `item()` answers null for
148
+ an id an app user's memory does not hold. The `iter*`
123
149
  methods are async iterables that follow `next` from page to page:
124
150
 
125
151
  ```ts
@@ -60,12 +60,13 @@ function refsOf(memories) {
60
60
  }
61
61
 
62
62
  // src/search.ts
63
+ var BREAK = /\s*[\r\n]\s*/g;
63
64
  function line(memory) {
64
65
  const dated = memory.type === "excerpt" && memory.date ? `${memory.date.slice(0, 10)}: ` : "";
65
- return `- ${dated}${memory.text}`;
66
+ return `- ${dated}${memory.text.trim().replace(BREAK, " ")}`;
66
67
  }
67
68
  var SearchResult = class _SearchResult {
68
- constructor(query, answerable, notes, memories, sources2, failed, raw) {
69
+ constructor(query, answerable, notes, memories, sources2, failed, raw, searchId = null) {
69
70
  this.query = query;
70
71
  this.answerable = answerable;
71
72
  this.notes = notes;
@@ -73,6 +74,7 @@ var SearchResult = class _SearchResult {
73
74
  this.sources = sources2;
74
75
  this.failed = failed;
75
76
  this.raw = raw;
77
+ this.searchId = searchId;
76
78
  }
77
79
  query;
78
80
  answerable;
@@ -81,6 +83,7 @@ var SearchResult = class _SearchResult {
81
83
  sources;
82
84
  failed;
83
85
  raw;
86
+ searchId;
84
87
  static parse(value) {
85
88
  const raw = object(value);
86
89
  return new _SearchResult(
@@ -90,7 +93,8 @@ var SearchResult = class _SearchResult {
90
93
  parseMemories(raw.memories),
91
94
  Array.isArray(raw.sources) ? list(raw.sources).map(object) : null,
92
95
  false,
93
- raw
96
+ raw,
97
+ maybe(raw.search_id)
94
98
  );
95
99
  }
96
100
  /** What a `failOpen` client answers when memory could not be reached. */
@@ -112,7 +116,8 @@ var SearchResult = class _SearchResult {
112
116
  }
113
117
  /**
114
118
  * The text to paste into a prompt: each note on its own line, a blank line, then each memory on
115
- * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`), cut at a whole
119
+ * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`; a memory's
120
+ * own line breaks made spaces), cut at a whole
116
121
  * memory so it is never longer than `maxChars`. Empty when there are no memories, or when not
117
122
  * even the first fits. The Python client and the n8n node write the same text.
118
123
  */
@@ -240,7 +245,7 @@ function unreached(error, requestId2 = null) {
240
245
  }
241
246
 
242
247
  // src/version.ts
243
- var VERSION = "0.3.2";
248
+ var VERSION = "0.3.4";
244
249
 
245
250
  // src/settings.ts
246
251
  var DEFAULT_BASE_URL = "https://api.alexein.ai";
@@ -248,7 +253,7 @@ var DEFAULT_TIMEOUT_MS = 6e4;
248
253
  var DEFAULT_RETRIES = 2;
249
254
  var KEYS_PAGE = "https://app.alexein.ai/console/keys";
250
255
  var INTEGRATION = /^[a-z0-9][a-z0-9._-]{0,31}$/;
251
- var USER_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,34}$/;
256
+ var USER_ID = /^[!-~](?:[ -~]{0,126}[!-~])?$/;
252
257
  function environment(name) {
253
258
  const env = globalThis.process?.env;
254
259
  return env?.[name] || void 0;
@@ -259,7 +264,7 @@ function normalizeBaseUrl(url) {
259
264
  function checkedUserId(id) {
260
265
  if (typeof id !== "string" || !USER_ID.test(id)) {
261
266
  throw new RangeError(
262
- `not a usable app user id: ${JSON.stringify(id)} (1 to 35 letters, digits, '.', '_' and '-', beginning with a letter or digit)`
267
+ `not a usable app user id: ${JSON.stringify(id)} (up to 128 characters, no control characters, no space at either end, ASCII only)`
263
268
  );
264
269
  }
265
270
  return id;
@@ -465,6 +470,77 @@ async function* paged(page, entries) {
465
470
  } while (cursor);
466
471
  }
467
472
 
473
+ // src/subjects.ts
474
+ var parseLink = (raw) => ({
475
+ link: text(raw.link),
476
+ ref: text(raw.ref),
477
+ date: maybe(raw.date),
478
+ source: maybe(raw.source),
479
+ raw
480
+ });
481
+ function parseSubject(value) {
482
+ const raw = object(value);
483
+ return {
484
+ name: text(raw.name),
485
+ facts: count(raw.facts),
486
+ about: objects(raw.about).map((a) => ({
487
+ text: text(a.text),
488
+ refs: strings(a.refs),
489
+ date: null,
490
+ raw: a
491
+ })),
492
+ values: objects(raw.values).map((v) => ({
493
+ attribute: text(v.attribute),
494
+ value: text(v.value),
495
+ since: maybe(v.since),
496
+ negated: v.negated === true,
497
+ raw: v
498
+ })),
499
+ timeline: objects(raw.timeline).map(parseFact),
500
+ conversations: objects(raw.conversations).map((c) => ({
501
+ text: text(c.text),
502
+ refs: c.ref ? [text(c.ref)] : [],
503
+ date: maybe(c.date),
504
+ raw: c
505
+ })),
506
+ links: objects(raw.links).map(parseLink),
507
+ suggestions: maybeStrings(raw.suggestions),
508
+ raw
509
+ };
510
+ }
511
+ function parseRelated(value) {
512
+ const raw = object(value);
513
+ const links = objects(raw.links).map(parseLink);
514
+ return { links, raw, [Symbol.iterator]: () => links[Symbol.iterator]() };
515
+ }
516
+ var parseCard = (raw) => ({
517
+ kind: text(raw.kind),
518
+ text: text(raw.text),
519
+ refs: strings(raw.refs),
520
+ surface: maybe(raw.surface),
521
+ from: strings(raw.from),
522
+ raw
523
+ });
524
+ function parseWays(value) {
525
+ const raw = object(value);
526
+ return {
527
+ who: text(raw.who),
528
+ cards: objects(raw.cards).map(parseCard),
529
+ procedures: strings(raw.procedures),
530
+ voice: maybe(raw.voice),
531
+ raw
532
+ };
533
+ }
534
+ function parseLessons(value) {
535
+ const raw = object(value);
536
+ return {
537
+ task: text(raw.task),
538
+ cards: objects(raw.cards).map(parseCard),
539
+ lessons: objects(raw.lessons).map(parseCard),
540
+ raw
541
+ };
542
+ }
543
+
468
544
  // src/writes.ts
469
545
  function addResult(items2, waiting, failed, raw) {
470
546
  return { items: items2, waiting, failed, ids: items2.map((i) => i.id), raw };
@@ -540,6 +616,19 @@ function parseDeleted(value) {
540
616
  const raw = object(value);
541
617
  return { user: text(raw.user), deleted: bool(raw.deleted), raw };
542
618
  }
619
+ function parseFeedback(value) {
620
+ const raw = object(value);
621
+ return {
622
+ searchId: text(raw.search_id),
623
+ verdict: text(raw.verdict),
624
+ status: text(raw.status),
625
+ raw
626
+ };
627
+ }
628
+ function parseRefreshed(value) {
629
+ const raw = object(value);
630
+ return { status: text(raw.status), raw };
631
+ }
543
632
 
544
633
  // src/calls.ts
545
634
  var kinds = (kind) => kind === void 0 ? void 0 : Array.isArray(kind) ? kind : [kind];
@@ -585,7 +674,11 @@ var latest = (o) => post("latest", parseMemoriesResult, {
585
674
  });
586
675
  var around = (ref, width) => post("around", parseMemoriesResult, { ref, width });
587
676
  var open = (ref) => post("open", parseOpened, { ref });
588
- var history = (subject, attribute) => post("history", parseHistory, { subject, attribute });
677
+ var subject = (name, limit) => post("subject", parseSubject, { name, limit });
678
+ var related = (ref) => post("related", parseRelated, { ref });
679
+ var howTheyWork = (o) => post("how_they_work", parseWays, { who: o.who, surface: o.surface });
680
+ var lessons = (task) => post("lessons", parseLessons, { task });
681
+ var history = (subject2, attribute) => post("history", parseHistory, { subject: subject2, attribute });
589
682
  var summary = () => post("summary", parseSummary);
590
683
  var facts = (o) => post("facts", parseFactsPage, { limit: o.limit, cursor: o.cursor });
591
684
  var openItems = (o) => post("open_items", parseOpenItems, {
@@ -612,6 +705,11 @@ function forget(named) {
612
705
  return post("forget", parseForgotten, body);
613
706
  }
614
707
  var correct = (ref, replacement) => post("correct", parseCorrection, { ref, replacement });
708
+ function feedback(searchId, verdict, note) {
709
+ if (!searchId) throw new RangeError("feedback needs the searchId a search answered with");
710
+ return post("feedback", parseFeedback, { search_id: searchId, verdict, note });
711
+ }
712
+ var refresh = () => post("refresh", parseRefreshed);
615
713
  var versions = (id) => post("versions", parseVersions, { id });
616
714
  var exportPage = (o) => post("export", parseExportPage, { limit: o.limit, cursor: o.cursor });
617
715
 
@@ -629,6 +727,11 @@ function batches(items2, options) {
629
727
  const { wait, redact, ...fields } = options;
630
728
  const defaults = compact(fields);
631
729
  const given = typeof items2 === "string" || !Array.isArray(items2) ? [items2] : items2;
730
+ if (fields.id !== void 0 && fields.id !== null && given.length > 1) {
731
+ throw new RangeError(
732
+ "id names one item, and this add has several: give each item its own id instead"
733
+ );
734
+ }
632
735
  const shaped = given.map((item2) => shape(item2, defaults));
633
736
  if (!shaped.length) return [];
634
737
  const call = crypto.randomUUID();
@@ -699,9 +802,34 @@ var User = class {
699
802
  open(ref) {
700
803
  return this.send(open(ref));
701
804
  }
805
+ /**
806
+ * One person or thing by name, whole: how it went, its values now, its facts in the order they
807
+ * were said, the conversations about it, and how it relates to others.
808
+ */
809
+ subject(name, options = {}) {
810
+ return this.send(subject(name, options.limit));
811
+ }
812
+ /** What the people and things one fact or excerpt names link to, by its ref. */
813
+ related(ref) {
814
+ return this.send(related(ref));
815
+ }
816
+ /**
817
+ * How the person works - their routines before an action and how they write on each `surface` -
818
+ * for an agent about to act or write for them. `who` names someone else.
819
+ */
820
+ howTheyWork(options = {}) {
821
+ return this.send(howTheyWork(options));
822
+ }
823
+ /**
824
+ * What an assistant should know before `task`: how the person corrected assistants and the notes
825
+ * they left on answers, most like it first.
826
+ */
827
+ lessons(task) {
828
+ return this.send(lessons(task));
829
+ }
702
830
  /** Every value a subject was stated to have, by attribute, oldest first. */
703
- history(subject, options = {}) {
704
- return this.send(history(subject, options.attribute));
831
+ history(subject2, options = {}) {
832
+ return this.send(history(subject2, options.attribute));
705
833
  }
706
834
  /** This memory in brief: its items, their span, the connected sources and the known lines. */
707
835
  summary() {
@@ -753,6 +881,22 @@ var User = class {
753
881
  correct(ref, replacement) {
754
882
  return this.send(correct(ref, replacement));
755
883
  }
884
+ /**
885
+ * Say how a search went - `wrong`, `missing` or `ok` - by its result or its `searchId`, and
886
+ * optionally what was true, so memory answers questions like it better. Kept as a note of this
887
+ * memory. Takes a key that writes.
888
+ */
889
+ async feedback(search2, verdict, options = {}) {
890
+ const searchId = typeof search2 === "string" ? search2 : search2.searchId;
891
+ return this.send(feedback(searchId, verdict, options.note));
892
+ }
893
+ /**
894
+ * Ask memory to bring what it has gathered of this app user up to date soon - after a large
895
+ * import, say. Once an hour per app user. Takes a key that writes.
896
+ */
897
+ refresh() {
898
+ return this.send(refresh());
899
+ }
756
900
  /** Every version of one added item, oldest first. Takes a key that writes. */
757
901
  versions(itemId) {
758
902
  return this.send(versions(itemId));
@@ -893,8 +1037,9 @@ var Memory = class {
893
1037
  return this.#transport.send(me());
894
1038
  }
895
1039
  /**
896
- * The memory of one of your app users, by your own id for them: 1 to 35 letters, digits, `.`,
897
- * `_` and `-`, beginning with a letter or digit. A RangeError otherwise, before any request.
1040
+ * The memory of one of your app users, by the id your app already has for them (a UUID, an
1041
+ * email): up to 128 characters, no control characters, ASCII only. A RangeError otherwise,
1042
+ * before any request.
898
1043
  */
899
1044
  user(id) {
900
1045
  return new User(this.#transport, checkedUserId(id), this.failOpen, this.#settings.log);
@@ -60,12 +60,13 @@ function refsOf(memories) {
60
60
  }
61
61
 
62
62
  // src/search.ts
63
+ var BREAK = /\s*[\r\n]\s*/g;
63
64
  function line(memory) {
64
65
  const dated = memory.type === "excerpt" && memory.date ? `${memory.date.slice(0, 10)}: ` : "";
65
- return `- ${dated}${memory.text}`;
66
+ return `- ${dated}${memory.text.trim().replace(BREAK, " ")}`;
66
67
  }
67
68
  var SearchResult = class _SearchResult {
68
- constructor(query, answerable, notes, memories, sources2, failed, raw) {
69
+ constructor(query, answerable, notes, memories, sources2, failed, raw, searchId = null) {
69
70
  this.query = query;
70
71
  this.answerable = answerable;
71
72
  this.notes = notes;
@@ -73,6 +74,7 @@ var SearchResult = class _SearchResult {
73
74
  this.sources = sources2;
74
75
  this.failed = failed;
75
76
  this.raw = raw;
77
+ this.searchId = searchId;
76
78
  }
77
79
 
78
80
 
@@ -81,6 +83,7 @@ var SearchResult = class _SearchResult {
81
83
 
82
84
 
83
85
 
86
+
84
87
  static parse(value) {
85
88
  const raw = object(value);
86
89
  return new _SearchResult(
@@ -90,7 +93,8 @@ var SearchResult = class _SearchResult {
90
93
  parseMemories(raw.memories),
91
94
  Array.isArray(raw.sources) ? list(raw.sources).map(object) : null,
92
95
  false,
93
- raw
96
+ raw,
97
+ maybe(raw.search_id)
94
98
  );
95
99
  }
96
100
  /** What a `failOpen` client answers when memory could not be reached. */
@@ -112,7 +116,8 @@ var SearchResult = class _SearchResult {
112
116
  }
113
117
  /**
114
118
  * The text to paste into a prompt: each note on its own line, a blank line, then each memory on
115
- * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`), cut at a whole
119
+ * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`; a memory's
120
+ * own line breaks made spaces), cut at a whole
116
121
  * memory so it is never longer than `maxChars`. Empty when there are no memories, or when not
117
122
  * even the first fits. The Python client and the n8n node write the same text.
118
123
  */
@@ -240,7 +245,7 @@ function unreached(error, requestId2 = null) {
240
245
  }
241
246
 
242
247
  // src/version.ts
243
- var VERSION = "0.3.2";
248
+ var VERSION = "0.3.4";
244
249
 
245
250
  // src/settings.ts
246
251
  var DEFAULT_BASE_URL = "https://api.alexein.ai";
@@ -248,7 +253,7 @@ var DEFAULT_TIMEOUT_MS = 6e4;
248
253
  var DEFAULT_RETRIES = 2;
249
254
  var KEYS_PAGE = "https://app.alexein.ai/console/keys";
250
255
  var INTEGRATION = /^[a-z0-9][a-z0-9._-]{0,31}$/;
251
- var USER_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,34}$/;
256
+ var USER_ID = /^[!-~](?:[ -~]{0,126}[!-~])?$/;
252
257
  function environment(name) {
253
258
  const env = _optionalChain([globalThis, 'access', _ => _.process, 'optionalAccess', _2 => _2.env]);
254
259
  return _optionalChain([env, 'optionalAccess', _3 => _3[name]]) || void 0;
@@ -259,7 +264,7 @@ function normalizeBaseUrl(url) {
259
264
  function checkedUserId(id) {
260
265
  if (typeof id !== "string" || !USER_ID.test(id)) {
261
266
  throw new RangeError(
262
- `not a usable app user id: ${JSON.stringify(id)} (1 to 35 letters, digits, '.', '_' and '-', beginning with a letter or digit)`
267
+ `not a usable app user id: ${JSON.stringify(id)} (up to 128 characters, no control characters, no space at either end, ASCII only)`
263
268
  );
264
269
  }
265
270
  return id;
@@ -465,6 +470,77 @@ async function* paged(page, entries) {
465
470
  } while (cursor);
466
471
  }
467
472
 
473
+ // src/subjects.ts
474
+ var parseLink = (raw) => ({
475
+ link: text(raw.link),
476
+ ref: text(raw.ref),
477
+ date: maybe(raw.date),
478
+ source: maybe(raw.source),
479
+ raw
480
+ });
481
+ function parseSubject(value) {
482
+ const raw = object(value);
483
+ return {
484
+ name: text(raw.name),
485
+ facts: count(raw.facts),
486
+ about: objects(raw.about).map((a) => ({
487
+ text: text(a.text),
488
+ refs: strings(a.refs),
489
+ date: null,
490
+ raw: a
491
+ })),
492
+ values: objects(raw.values).map((v) => ({
493
+ attribute: text(v.attribute),
494
+ value: text(v.value),
495
+ since: maybe(v.since),
496
+ negated: v.negated === true,
497
+ raw: v
498
+ })),
499
+ timeline: objects(raw.timeline).map(parseFact),
500
+ conversations: objects(raw.conversations).map((c) => ({
501
+ text: text(c.text),
502
+ refs: c.ref ? [text(c.ref)] : [],
503
+ date: maybe(c.date),
504
+ raw: c
505
+ })),
506
+ links: objects(raw.links).map(parseLink),
507
+ suggestions: maybeStrings(raw.suggestions),
508
+ raw
509
+ };
510
+ }
511
+ function parseRelated(value) {
512
+ const raw = object(value);
513
+ const links = objects(raw.links).map(parseLink);
514
+ return { links, raw, [Symbol.iterator]: () => links[Symbol.iterator]() };
515
+ }
516
+ var parseCard = (raw) => ({
517
+ kind: text(raw.kind),
518
+ text: text(raw.text),
519
+ refs: strings(raw.refs),
520
+ surface: maybe(raw.surface),
521
+ from: strings(raw.from),
522
+ raw
523
+ });
524
+ function parseWays(value) {
525
+ const raw = object(value);
526
+ return {
527
+ who: text(raw.who),
528
+ cards: objects(raw.cards).map(parseCard),
529
+ procedures: strings(raw.procedures),
530
+ voice: maybe(raw.voice),
531
+ raw
532
+ };
533
+ }
534
+ function parseLessons(value) {
535
+ const raw = object(value);
536
+ return {
537
+ task: text(raw.task),
538
+ cards: objects(raw.cards).map(parseCard),
539
+ lessons: objects(raw.lessons).map(parseCard),
540
+ raw
541
+ };
542
+ }
543
+
468
544
  // src/writes.ts
469
545
  function addResult(items2, waiting, failed, raw) {
470
546
  return { items: items2, waiting, failed, ids: items2.map((i) => i.id), raw };
@@ -540,6 +616,19 @@ function parseDeleted(value) {
540
616
  const raw = object(value);
541
617
  return { user: text(raw.user), deleted: bool(raw.deleted), raw };
542
618
  }
619
+ function parseFeedback(value) {
620
+ const raw = object(value);
621
+ return {
622
+ searchId: text(raw.search_id),
623
+ verdict: text(raw.verdict),
624
+ status: text(raw.status),
625
+ raw
626
+ };
627
+ }
628
+ function parseRefreshed(value) {
629
+ const raw = object(value);
630
+ return { status: text(raw.status), raw };
631
+ }
543
632
 
544
633
  // src/calls.ts
545
634
  var kinds = (kind) => kind === void 0 ? void 0 : Array.isArray(kind) ? kind : [kind];
@@ -585,7 +674,11 @@ var latest = (o) => post("latest", parseMemoriesResult, {
585
674
  });
586
675
  var around = (ref, width) => post("around", parseMemoriesResult, { ref, width });
587
676
  var open = (ref) => post("open", parseOpened, { ref });
588
- var history = (subject, attribute) => post("history", parseHistory, { subject, attribute });
677
+ var subject = (name, limit) => post("subject", parseSubject, { name, limit });
678
+ var related = (ref) => post("related", parseRelated, { ref });
679
+ var howTheyWork = (o) => post("how_they_work", parseWays, { who: o.who, surface: o.surface });
680
+ var lessons = (task) => post("lessons", parseLessons, { task });
681
+ var history = (subject2, attribute) => post("history", parseHistory, { subject: subject2, attribute });
589
682
  var summary = () => post("summary", parseSummary);
590
683
  var facts = (o) => post("facts", parseFactsPage, { limit: o.limit, cursor: o.cursor });
591
684
  var openItems = (o) => post("open_items", parseOpenItems, {
@@ -612,6 +705,11 @@ function forget(named) {
612
705
  return post("forget", parseForgotten, body);
613
706
  }
614
707
  var correct = (ref, replacement) => post("correct", parseCorrection, { ref, replacement });
708
+ function feedback(searchId, verdict, note) {
709
+ if (!searchId) throw new RangeError("feedback needs the searchId a search answered with");
710
+ return post("feedback", parseFeedback, { search_id: searchId, verdict, note });
711
+ }
712
+ var refresh = () => post("refresh", parseRefreshed);
615
713
  var versions = (id) => post("versions", parseVersions, { id });
616
714
  var exportPage = (o) => post("export", parseExportPage, { limit: o.limit, cursor: o.cursor });
617
715
 
@@ -629,6 +727,11 @@ function batches(items2, options) {
629
727
  const { wait, redact, ...fields } = options;
630
728
  const defaults = compact(fields);
631
729
  const given = typeof items2 === "string" || !Array.isArray(items2) ? [items2] : items2;
730
+ if (fields.id !== void 0 && fields.id !== null && given.length > 1) {
731
+ throw new RangeError(
732
+ "id names one item, and this add has several: give each item its own id instead"
733
+ );
734
+ }
632
735
  const shaped = given.map((item2) => shape(item2, defaults));
633
736
  if (!shaped.length) return [];
634
737
  const call = crypto.randomUUID();
@@ -699,9 +802,34 @@ var User = class {
699
802
  open(ref) {
700
803
  return this.send(open(ref));
701
804
  }
805
+ /**
806
+ * One person or thing by name, whole: how it went, its values now, its facts in the order they
807
+ * were said, the conversations about it, and how it relates to others.
808
+ */
809
+ subject(name, options = {}) {
810
+ return this.send(subject(name, options.limit));
811
+ }
812
+ /** What the people and things one fact or excerpt names link to, by its ref. */
813
+ related(ref) {
814
+ return this.send(related(ref));
815
+ }
816
+ /**
817
+ * How the person works - their routines before an action and how they write on each `surface` -
818
+ * for an agent about to act or write for them. `who` names someone else.
819
+ */
820
+ howTheyWork(options = {}) {
821
+ return this.send(howTheyWork(options));
822
+ }
823
+ /**
824
+ * What an assistant should know before `task`: how the person corrected assistants and the notes
825
+ * they left on answers, most like it first.
826
+ */
827
+ lessons(task) {
828
+ return this.send(lessons(task));
829
+ }
702
830
  /** Every value a subject was stated to have, by attribute, oldest first. */
703
- history(subject, options = {}) {
704
- return this.send(history(subject, options.attribute));
831
+ history(subject2, options = {}) {
832
+ return this.send(history(subject2, options.attribute));
705
833
  }
706
834
  /** This memory in brief: its items, their span, the connected sources and the known lines. */
707
835
  summary() {
@@ -753,6 +881,22 @@ var User = class {
753
881
  correct(ref, replacement) {
754
882
  return this.send(correct(ref, replacement));
755
883
  }
884
+ /**
885
+ * Say how a search went - `wrong`, `missing` or `ok` - by its result or its `searchId`, and
886
+ * optionally what was true, so memory answers questions like it better. Kept as a note of this
887
+ * memory. Takes a key that writes.
888
+ */
889
+ async feedback(search2, verdict, options = {}) {
890
+ const searchId = typeof search2 === "string" ? search2 : search2.searchId;
891
+ return this.send(feedback(searchId, verdict, options.note));
892
+ }
893
+ /**
894
+ * Ask memory to bring what it has gathered of this app user up to date soon - after a large
895
+ * import, say. Once an hour per app user. Takes a key that writes.
896
+ */
897
+ refresh() {
898
+ return this.send(refresh());
899
+ }
756
900
  /** Every version of one added item, oldest first. Takes a key that writes. */
757
901
  versions(itemId) {
758
902
  return this.send(versions(itemId));
@@ -893,8 +1037,9 @@ var Memory = class {
893
1037
  return this.#transport.send(me());
894
1038
  }
895
1039
  /**
896
- * The memory of one of your app users, by your own id for them: 1 to 35 letters, digits, `.`,
897
- * `_` and `-`, beginning with a letter or digit. A RangeError otherwise, before any request.
1040
+ * The memory of one of your app users, by the id your app already has for them (a UUID, an
1041
+ * email): up to 128 characters, no control characters, ASCII only. A RangeError otherwise,
1042
+ * before any request.
898
1043
  */
899
1044
  user(id) {
900
1045
  return new User(this.#transport, checkedUserId(id), this.failOpen, this.#settings.log);