@alexein/sdk 0.3.1 → 0.3.3

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.
@@ -38,7 +38,11 @@ interface Excerpt {
38
38
  /** When memory took it. */
39
39
  readonly addedAt: string | null;
40
40
  readonly session: string | null;
41
- /** The roles of who spoke in it: `user`, `assistant`. */
41
+ /**
42
+ * The roles of who spoke in it: `user`, `assistant`, `other` for someone else. A line from
43
+ * grep or latest carries roles only when the person or an assistant spoke, so one without is
44
+ * read as `["other"]`.
45
+ */
42
46
  readonly roles: string[];
43
47
  readonly raw: Json;
44
48
  }
@@ -183,6 +187,11 @@ interface ItemDefaults {
183
187
  }
184
188
  /** Options `add` takes besides the items. */
185
189
  interface AddOptions extends ItemDefaults {
190
+ /**
191
+ * The id of the one item added, so the same id again edits it. With several items, give each
192
+ * its own `id`: here it is a RangeError, since one id would make them edits of one another.
193
+ */
194
+ id?: string;
186
195
  /** Answer once the items are searchable (briefly waited for). */
187
196
  wait?: boolean;
188
197
  /** Replace phone numbers, cards, keys and the like with their kind before memory keeps them. */
@@ -279,7 +288,8 @@ interface Me {
279
288
  * What memory holds for a question. `memories` come in order: known lines, then facts, then
280
289
  * excerpts. `answerable` is false when memory does not seem to hold the answer, and null when it
281
290
  * was not checked. `failed` is true when a `failOpen` client could not reach memory, and the
282
- * result is empty for that reason.
291
+ * result is empty for that reason. `searchId` is what `feedback()` takes to say how the search
292
+ * went (null when failed).
283
293
  */
284
294
  declare class SearchResult {
285
295
  readonly query: string;
@@ -289,7 +299,8 @@ declare class SearchResult {
289
299
  readonly sources: Json[] | null;
290
300
  readonly failed: boolean;
291
301
  readonly raw: Json;
292
- constructor(query: string, answerable: boolean | null, notes: string[], memories: MemoryEntry[], sources: Json[] | null, failed: boolean, raw: Json);
302
+ readonly searchId: string | null;
303
+ constructor(query: string, answerable: boolean | null, notes: string[], memories: MemoryEntry[], sources: Json[] | null, failed: boolean, raw: Json, searchId?: string | null);
293
304
  static parse(value: unknown): SearchResult;
294
305
  /** What a `failOpen` client answers when memory could not be reached. */
295
306
  static unavailable(query: string): SearchResult;
@@ -300,13 +311,100 @@ declare class SearchResult {
300
311
  get refs(): string[];
301
312
  /**
302
313
  * The text to paste into a prompt: each note on its own line, a blank line, then each memory on
303
- * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`), cut at a whole
314
+ * its own line as `- <text>` (an excerpt with a date as `- <YYYY-MM-DD>: <text>`; a memory's
315
+ * own line breaks made spaces), cut at a whole
304
316
  * memory so it is never longer than `maxChars`. Empty when there are no memories, or when not
305
317
  * even the first fits. The Python client and the n8n node write the same text.
306
318
  */
307
319
  context(maxChars?: number): string;
308
320
  }
309
321
 
322
+ /**
323
+ * What the routes about people and things answer: one subject whole, what a memory links to, how
324
+ * the person works, and the lessons they taught assistants. Each keeps its JSON in `raw`.
325
+ */
326
+
327
+ /**
328
+ * How one person or thing relates to another, in words (`link`): the day it was said, the ref of
329
+ * the fact that says it, and the ref of the excerpt that fact was learned from (null when unknown,
330
+ * and on `subject()` links).
331
+ */
332
+ interface Link {
333
+ readonly link: string;
334
+ readonly ref: string;
335
+ readonly date: string | null;
336
+ readonly source: string | null;
337
+ readonly raw: Json;
338
+ }
339
+ /**
340
+ * A line for a model, with the refs of the facts it rests on: a subject's `about`, and a
341
+ * conversation about it (whose one ref is an excerpt of that conversation).
342
+ */
343
+ interface Line {
344
+ readonly text: string;
345
+ readonly refs: string[];
346
+ readonly date: string | null;
347
+ readonly raw: Json;
348
+ }
349
+ /**
350
+ * One person or thing by name, whole: `about`, a few lines on how it went; `values`, each
351
+ * property's newest value; `timeline`, its facts oldest first; `conversations` about it; `links`
352
+ * to other people and things. `facts` is 0 when memory holds nothing by that name, and then
353
+ * `suggestions` names the nearest it does.
354
+ */
355
+ interface Subject {
356
+ readonly name: string;
357
+ readonly facts: number;
358
+ readonly about: Line[];
359
+ readonly values: Value[];
360
+ readonly timeline: Fact[];
361
+ readonly conversations: Line[];
362
+ readonly links: Link[];
363
+ readonly suggestions: string[] | null;
364
+ readonly raw: Json;
365
+ }
366
+ /** What the people and things one memory names link to, newest said first. Iterable. */
367
+ interface Related extends Iterable<Link> {
368
+ readonly links: Link[];
369
+ readonly raw: Json;
370
+ }
371
+ /**
372
+ * A plain line for a model, and the refs of the facts it cites. `kind` says what it is: `routine`
373
+ * or `style` from `howTheyWork()` (`surface` names where a style is for), `lesson` from
374
+ * `lessons()` (`from` says what it came from: `correction`, `feedback` or `said`), or `strategy`,
375
+ * `failure` or `workflow` among a `Lessons`' `lessons`. The counts a card rests on are in `raw`.
376
+ */
377
+ interface Card {
378
+ readonly kind: string;
379
+ readonly text: string;
380
+ readonly refs: string[];
381
+ readonly surface: string | null;
382
+ readonly from: string[];
383
+ readonly raw: Json;
384
+ }
385
+ /**
386
+ * How someone works: `cards`, each a routine or a writing style; `procedures`, each routine's
387
+ * counts written out for a model; `voice`, how they write, or null when memory has too few of
388
+ * their messages to say.
389
+ */
390
+ interface Ways {
391
+ readonly who: string;
392
+ readonly cards: Card[];
393
+ readonly procedures: string[];
394
+ readonly voice: string | null;
395
+ readonly raw: Json;
396
+ }
397
+ /**
398
+ * What an assistant should know before a task like `task`: `cards`, the lessons the person taught,
399
+ * most like it first; `lessons`, what earlier attempts at similar tasks taught.
400
+ */
401
+ interface Lessons {
402
+ readonly task: string;
403
+ readonly cards: Card[];
404
+ readonly lessons: Card[];
405
+ readonly raw: Json;
406
+ }
407
+
310
408
  /** The client's settings: from its options, else the environment, else the defaults. */
311
409
  declare const DEFAULT_BASE_URL = "https://api.alexein.ai";
312
410
  /** Long enough for the slowest search and an add that waits; a caller that cannot wait sets less. */
@@ -456,6 +554,21 @@ interface Deleted {
456
554
  readonly deleted: boolean;
457
555
  readonly raw: Json;
458
556
  }
557
+ /**
558
+ * Feedback on one search, kept as a note of this app user's memory: the search id and verdict as
559
+ * sent, and the note's `status`, `queued` or `stored` as an add answers it.
560
+ */
561
+ interface Feedback {
562
+ readonly searchId: string;
563
+ readonly verdict: string;
564
+ readonly status: string;
565
+ readonly raw: Json;
566
+ }
567
+ /** A refresh asked for: `queued`, or `already_queued` when one was already waiting or under way. */
568
+ interface Refreshed {
569
+ readonly status: string;
570
+ readonly raw: Json;
571
+ }
459
572
 
460
573
  /**
461
574
  * Each route as the request it is: path, body and how to read the answer. Written once here and
@@ -510,6 +623,14 @@ interface PageOptions {
510
623
  interface ItemsOptions extends PageOptions {
511
624
  filters?: Filters;
512
625
  }
626
+ interface HowTheyWorkOptions {
627
+ /** Someone in this memory, by name; absent, the person. */
628
+ who?: string;
629
+ /** Where the writing is for, such as a channel or a repository; absent, where they write most. */
630
+ surface?: string;
631
+ }
632
+ /** How a search went: wrong, the answer missing from it, or fine. */
633
+ type Verdict = "wrong" | "missing" | "ok";
513
634
  interface ForgetOptions {
514
635
  items?: string[];
515
636
  sessions?: string[];
@@ -547,6 +668,25 @@ declare class User {
547
668
  }): Promise<Memories>;
548
669
  /** One memory by its ref, whole: an excerpt, or a fact with the excerpts it came from. */
549
670
  open(ref: string): Promise<Opened>;
671
+ /**
672
+ * One person or thing by name, whole: how it went, its values now, its facts in the order they
673
+ * were said, the conversations about it, and how it relates to others.
674
+ */
675
+ subject(name: string, options?: {
676
+ limit?: number;
677
+ }): Promise<Subject>;
678
+ /** What the people and things one fact or excerpt names link to, by its ref. */
679
+ related(ref: string): Promise<Related>;
680
+ /**
681
+ * How the person works - their routines before an action and how they write on each `surface` -
682
+ * for an agent about to act or write for them. `who` names someone else.
683
+ */
684
+ howTheyWork(options?: HowTheyWorkOptions): Promise<Ways>;
685
+ /**
686
+ * What an assistant should know before `task`: how the person corrected assistants and the notes
687
+ * they left on answers, most like it first.
688
+ */
689
+ lessons(task: string): Promise<Lessons>;
550
690
  /** Every value a subject was stated to have, by attribute, oldest first. */
551
691
  history(subject: string, options?: {
552
692
  attribute?: string;
@@ -578,6 +718,19 @@ declare class User {
578
718
  forget(named: ForgetOptions): Promise<Forgotten>;
579
719
  /** Retract one fact for good, by its ref; a `replacement` is kept as a note. */
580
720
  correct(ref: string, replacement?: string): Promise<Correction>;
721
+ /**
722
+ * Say how a search went - `wrong`, `missing` or `ok` - by its result or its `searchId`, and
723
+ * optionally what was true, so memory answers questions like it better. Kept as a note of this
724
+ * memory. Takes a key that writes.
725
+ */
726
+ feedback(search: SearchResult | string, verdict: Verdict, options?: {
727
+ note?: string;
728
+ }): Promise<Feedback>;
729
+ /**
730
+ * Ask memory to bring what it has gathered of this app user up to date soon - after a large
731
+ * import, say. Once an hour per app user. Takes a key that writes.
732
+ */
733
+ refresh(): Promise<Refreshed>;
581
734
  /** Every version of one added item, oldest first. Takes a key that writes. */
582
735
  versions(itemId: string): Promise<Versions>;
583
736
  /** Everything memory holds for this app user, a page at a time. */
@@ -638,4 +791,4 @@ declare class Memory {
638
791
  close(): void;
639
792
  }
640
793
 
641
- export { type Versions as $, type AddOptions as A, type Opened as B, type Correction as C, DEFAULT_BASE_URL as D, type Erased as E, type Fact as F, type GrepOptions as G, type History as H, type Item as I, type Json as J, type Known as K, type LatestOptions as L, type Me as M, type Origin as N, type OpenItem as O, type PageOptions as P, SearchResult as Q, type Source as R, type SearchOptions as S, type Sources as T, type Statuses as U, type StoredItem as V, type Summary as W, User as X, type UsersPage as Y, type Value as Z, type VersionEntry as _, type AddResult as a, type AddedItem as b, type Adding as c, type AppUser as d, type Author as e, DEFAULT_RETRIES as f, DEFAULT_TIMEOUT_MS as g, type Deleted as h, type Excerpt as i, type ExportPage as j, type ExportRecord as k, type FactsPage as l, type Filters as m, type FollowUp as n, type ForgetOptions as o, type Forgotten as p, type ItemDefaults as q, type ItemStatus as r, type ItemsOptions as s, type ItemsPage as t, type Memories as u, Memory as v, type MemoryEntry as w, type MemoryOptions as x, type OpenItems as y, type OpenItemsOptions as z };
794
+ export { type Sources as $, type AddOptions as A, type Memories as B, type Card as C, DEFAULT_BASE_URL as D, type Erased as E, type Fact as F, type GrepOptions as G, type History as H, type Item as I, type Json as J, type Known as K, type LatestOptions as L, type Me as M, Memory as N, type MemoryEntry as O, type MemoryOptions as P, type OpenItem as Q, type OpenItems as R, type OpenItemsOptions as S, type Opened as T, type Origin as U, type PageOptions as V, type Refreshed as W, type Related as X, type SearchOptions as Y, SearchResult as Z, type Source as _, type AddResult as a, type Statuses as a0, type StoredItem as a1, type Subject as a2, type Summary as a3, User as a4, type UsersPage as a5, type Value as a6, type Verdict as a7, type VersionEntry as a8, type Versions as a9, type Ways as aa, type AddedItem as b, type Adding as c, type AppUser as d, type Author as e, type Correction as f, DEFAULT_RETRIES as g, DEFAULT_TIMEOUT_MS as h, type Deleted as i, type Excerpt as j, type ExportPage as k, type ExportRecord as l, type FactsPage as m, type Feedback as n, type Filters as o, type FollowUp as p, type ForgetOptions as q, type Forgotten as r, type HowTheyWorkOptions as s, type ItemDefaults as t, type ItemStatus as u, type ItemsOptions as v, type ItemsPage as w, type Lessons as x, type Line as y, type Link as z };
package/dist/index.cjs CHANGED
@@ -15,8 +15,8 @@
15
15
 
16
16
 
17
17
 
18
- var _chunkBIGISYZRcjs = require('./chunk-BIGISYZR.cjs');
19
18
 
19
+ var _chunk34W2JJVDcjs = require('./chunk-34W2JJVD.cjs');
20
20
 
21
21
 
22
22
 
@@ -33,4 +33,6 @@ var _chunkBIGISYZRcjs = require('./chunk-BIGISYZR.cjs');
33
33
 
34
34
 
35
35
 
36
- exports.APIConnectionError = _chunkBIGISYZRcjs.APIConnectionError; exports.APITimeoutError = _chunkBIGISYZRcjs.APITimeoutError; exports.AlexeinError = _chunkBIGISYZRcjs.AlexeinError; exports.AuthenticationError = _chunkBIGISYZRcjs.AuthenticationError; exports.DEFAULT_BASE_URL = _chunkBIGISYZRcjs.DEFAULT_BASE_URL; exports.DEFAULT_RETRIES = _chunkBIGISYZRcjs.DEFAULT_RETRIES; exports.DEFAULT_TIMEOUT_MS = _chunkBIGISYZRcjs.DEFAULT_TIMEOUT_MS; exports.InvalidRequestError = _chunkBIGISYZRcjs.InvalidRequestError; exports.Memory = _chunkBIGISYZRcjs.Memory; exports.NotFoundError = _chunkBIGISYZRcjs.NotFoundError; exports.PermissionDeniedError = _chunkBIGISYZRcjs.PermissionDeniedError; exports.RateLimitError = _chunkBIGISYZRcjs.RateLimitError; exports.SearchResult = _chunkBIGISYZRcjs.SearchResult; exports.ServiceUnavailableError = _chunkBIGISYZRcjs.ServiceUnavailableError; exports.User = _chunkBIGISYZRcjs.User; exports.VERSION = _chunkBIGISYZRcjs.VERSION;
36
+
37
+
38
+ exports.APIConnectionError = _chunk34W2JJVDcjs.APIConnectionError; exports.APITimeoutError = _chunk34W2JJVDcjs.APITimeoutError; exports.AlexeinError = _chunk34W2JJVDcjs.AlexeinError; exports.AuthenticationError = _chunk34W2JJVDcjs.AuthenticationError; exports.DEFAULT_BASE_URL = _chunk34W2JJVDcjs.DEFAULT_BASE_URL; exports.DEFAULT_RETRIES = _chunk34W2JJVDcjs.DEFAULT_RETRIES; exports.DEFAULT_TIMEOUT_MS = _chunk34W2JJVDcjs.DEFAULT_TIMEOUT_MS; exports.InvalidRequestError = _chunk34W2JJVDcjs.InvalidRequestError; exports.Memory = _chunk34W2JJVDcjs.Memory; exports.NotFoundError = _chunk34W2JJVDcjs.NotFoundError; exports.PermissionDeniedError = _chunk34W2JJVDcjs.PermissionDeniedError; exports.QuotaExceededError = _chunk34W2JJVDcjs.QuotaExceededError; exports.RateLimitError = _chunk34W2JJVDcjs.RateLimitError; exports.SearchResult = _chunk34W2JJVDcjs.SearchResult; exports.ServiceUnavailableError = _chunk34W2JJVDcjs.ServiceUnavailableError; exports.User = _chunk34W2JJVDcjs.User; exports.VERSION = _chunk34W2JJVDcjs.VERSION;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Correction, D as DEFAULT_BASE_URL, f as DEFAULT_RETRIES, g as DEFAULT_TIMEOUT_MS, h as Deleted, E as Erased, i as Excerpt, j as ExportPage, k as ExportRecord, F as Fact, l as FactsPage, m as Filters, n as FollowUp, o as ForgetOptions, p as Forgotten, G as GrepOptions, H as History, I as Item, q as ItemDefaults, r as ItemStatus, s as ItemsOptions, t as ItemsPage, J as Json, K as Known, L as LatestOptions, M as Me, u as Memories, v as Memory, w as MemoryEntry, x as MemoryOptions, O as OpenItem, y as OpenItems, z as OpenItemsOptions, B as Opened, N as Origin, P as PageOptions, S as SearchOptions, Q as SearchResult, R as Source, T as Sources, U as Statuses, V as StoredItem, W as Summary, X as User, Y as UsersPage, Z as Value, _ as VersionEntry, $ as Versions } from './client-YKZ4fkK-.cjs';
1
+ import { J as Json } from './client-Bz10lVYG.cjs';
2
+ export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Card, f as Correction, D as DEFAULT_BASE_URL, g as DEFAULT_RETRIES, h as DEFAULT_TIMEOUT_MS, i as Deleted, E as Erased, j as Excerpt, k as ExportPage, l as ExportRecord, F as Fact, m as FactsPage, n as Feedback, o as Filters, p as FollowUp, q as ForgetOptions, r as Forgotten, G as GrepOptions, H as History, s as HowTheyWorkOptions, I as Item, t as ItemDefaults, u as ItemStatus, v as ItemsOptions, w as ItemsPage, K as Known, L as LatestOptions, x as Lessons, y as Line, z as Link, M as Me, B as Memories, N as Memory, O as MemoryEntry, P as MemoryOptions, Q as OpenItem, R as OpenItems, S as OpenItemsOptions, T as Opened, U as Origin, V as PageOptions, W as Refreshed, X as Related, Y as SearchOptions, Z as SearchResult, _ as Source, $ as Sources, a0 as Statuses, a1 as StoredItem, a2 as Subject, a3 as Summary, a4 as User, a5 as UsersPage, a6 as Value, a7 as Verdict, a8 as VersionEntry, a9 as Versions, aa as Ways } from './client-Bz10lVYG.cjs';
2
3
 
3
- declare const VERSION = "0.3.1";
4
+ declare const VERSION = "0.3.3";
4
5
 
5
6
  /**
6
7
  * What can go wrong, one class per thing a caller would handle differently: the same classes as
@@ -44,7 +45,7 @@ declare class AlexeinError extends Error {
44
45
  /** 401: no key, or one the service did not issue. */
45
46
  declare class AuthenticationError extends AlexeinError {
46
47
  }
47
- /** 403: the key reads, and the call writes. */
48
+ /** 403: the key reads, and the call writes; or the key's organisation is closed. */
48
49
  declare class PermissionDeniedError extends AlexeinError {
49
50
  }
50
51
  /**
@@ -56,6 +57,21 @@ declare class NotFoundError extends AlexeinError {
56
57
  /** 400, 413, 422 and any other 4xx: the request itself is wrong. Retrying will not help. */
57
58
  declare class InvalidRequestError extends AlexeinError {
58
59
  }
60
+ /**
61
+ * 402: the organisation has used this month's events or retrievals. Only an add (events) and a
62
+ * search (retrievals) throw it; every other read is free and never refused. Never retried, and not an
63
+ * outage, so a `failOpen` client throws it too: it lasts until `resetsAt`, the 1st of next month,
64
+ * or until the plan is upgraded. `limit` is which one ("events" or "retrievals"), `used` and
65
+ * `included` its figures, `upgrade` where to raise it.
66
+ */
67
+ declare class QuotaExceededError extends AlexeinError {
68
+ readonly limit: string | null;
69
+ readonly used: number | null;
70
+ readonly included: number | null;
71
+ readonly resetsAt: string | null;
72
+ readonly upgrade: string | null;
73
+ constructor(message: string, fields?: ErrorFields, body?: Json);
74
+ }
59
75
  /**
60
76
  * 429, after retries: too many requests in flight, or reads too fast. Retried for you, after
61
77
  * `Retry-After` seconds (when at most 60) or with backoff.
@@ -73,4 +89,4 @@ declare class APIConnectionError extends AlexeinError {
73
89
  declare class APITimeoutError extends APIConnectionError {
74
90
  }
75
91
 
76
- export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, NotFoundError, PermissionDeniedError, RateLimitError, ServiceUnavailableError, VERSION };
92
+ export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, Json, NotFoundError, PermissionDeniedError, QuotaExceededError, RateLimitError, ServiceUnavailableError, VERSION };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Correction, D as DEFAULT_BASE_URL, f as DEFAULT_RETRIES, g as DEFAULT_TIMEOUT_MS, h as Deleted, E as Erased, i as Excerpt, j as ExportPage, k as ExportRecord, F as Fact, l as FactsPage, m as Filters, n as FollowUp, o as ForgetOptions, p as Forgotten, G as GrepOptions, H as History, I as Item, q as ItemDefaults, r as ItemStatus, s as ItemsOptions, t as ItemsPage, J as Json, K as Known, L as LatestOptions, M as Me, u as Memories, v as Memory, w as MemoryEntry, x as MemoryOptions, O as OpenItem, y as OpenItems, z as OpenItemsOptions, B as Opened, N as Origin, P as PageOptions, S as SearchOptions, Q as SearchResult, R as Source, T as Sources, U as Statuses, V as StoredItem, W as Summary, X as User, Y as UsersPage, Z as Value, _ as VersionEntry, $ as Versions } from './client-YKZ4fkK-.js';
1
+ import { J as Json } from './client-Bz10lVYG.js';
2
+ export { A as AddOptions, a as AddResult, b as AddedItem, c as Adding, d as AppUser, e as Author, C as Card, f as Correction, D as DEFAULT_BASE_URL, g as DEFAULT_RETRIES, h as DEFAULT_TIMEOUT_MS, i as Deleted, E as Erased, j as Excerpt, k as ExportPage, l as ExportRecord, F as Fact, m as FactsPage, n as Feedback, o as Filters, p as FollowUp, q as ForgetOptions, r as Forgotten, G as GrepOptions, H as History, s as HowTheyWorkOptions, I as Item, t as ItemDefaults, u as ItemStatus, v as ItemsOptions, w as ItemsPage, K as Known, L as LatestOptions, x as Lessons, y as Line, z as Link, M as Me, B as Memories, N as Memory, O as MemoryEntry, P as MemoryOptions, Q as OpenItem, R as OpenItems, S as OpenItemsOptions, T as Opened, U as Origin, V as PageOptions, W as Refreshed, X as Related, Y as SearchOptions, Z as SearchResult, _ as Source, $ as Sources, a0 as Statuses, a1 as StoredItem, a2 as Subject, a3 as Summary, a4 as User, a5 as UsersPage, a6 as Value, a7 as Verdict, a8 as VersionEntry, a9 as Versions, aa as Ways } from './client-Bz10lVYG.js';
2
3
 
3
- declare const VERSION = "0.3.1";
4
+ declare const VERSION = "0.3.3";
4
5
 
5
6
  /**
6
7
  * What can go wrong, one class per thing a caller would handle differently: the same classes as
@@ -44,7 +45,7 @@ declare class AlexeinError extends Error {
44
45
  /** 401: no key, or one the service did not issue. */
45
46
  declare class AuthenticationError extends AlexeinError {
46
47
  }
47
- /** 403: the key reads, and the call writes. */
48
+ /** 403: the key reads, and the call writes; or the key's organisation is closed. */
48
49
  declare class PermissionDeniedError extends AlexeinError {
49
50
  }
50
51
  /**
@@ -56,6 +57,21 @@ declare class NotFoundError extends AlexeinError {
56
57
  /** 400, 413, 422 and any other 4xx: the request itself is wrong. Retrying will not help. */
57
58
  declare class InvalidRequestError extends AlexeinError {
58
59
  }
60
+ /**
61
+ * 402: the organisation has used this month's events or retrievals. Only an add (events) and a
62
+ * search (retrievals) throw it; every other read is free and never refused. Never retried, and not an
63
+ * outage, so a `failOpen` client throws it too: it lasts until `resetsAt`, the 1st of next month,
64
+ * or until the plan is upgraded. `limit` is which one ("events" or "retrievals"), `used` and
65
+ * `included` its figures, `upgrade` where to raise it.
66
+ */
67
+ declare class QuotaExceededError extends AlexeinError {
68
+ readonly limit: string | null;
69
+ readonly used: number | null;
70
+ readonly included: number | null;
71
+ readonly resetsAt: string | null;
72
+ readonly upgrade: string | null;
73
+ constructor(message: string, fields?: ErrorFields, body?: Json);
74
+ }
59
75
  /**
60
76
  * 429, after retries: too many requests in flight, or reads too fast. Retried for you, after
61
77
  * `Retry-After` seconds (when at most 60) or with backoff.
@@ -73,4 +89,4 @@ declare class APIConnectionError extends AlexeinError {
73
89
  declare class APITimeoutError extends APIConnectionError {
74
90
  }
75
91
 
76
- export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, NotFoundError, PermissionDeniedError, RateLimitError, ServiceUnavailableError, VERSION };
92
+ export { APIConnectionError, APITimeoutError, AlexeinError, AuthenticationError, type FieldError, InvalidRequestError, Json, NotFoundError, PermissionDeniedError, QuotaExceededError, RateLimitError, ServiceUnavailableError, VERSION };
package/dist/index.js CHANGED
@@ -10,12 +10,13 @@ import {
10
10
  Memory,
11
11
  NotFoundError,
12
12
  PermissionDeniedError,
13
+ QuotaExceededError,
13
14
  RateLimitError,
14
15
  SearchResult,
15
16
  ServiceUnavailableError,
16
17
  User,
17
18
  VERSION
18
- } from "./chunk-DADXKQLZ.js";
19
+ } from "./chunk-5YIOYX3J.js";
19
20
  export {
20
21
  APIConnectionError,
21
22
  APITimeoutError,
@@ -28,6 +29,7 @@ export {
28
29
  Memory,
29
30
  NotFoundError,
30
31
  PermissionDeniedError,
32
+ QuotaExceededError,
31
33
  RateLimitError,
32
34
  SearchResult,
33
35
  ServiceUnavailableError,
@@ -12,10 +12,10 @@
12
12
 
13
13
 
14
14
 
15
- var _chunkPSATR3NLcjs = require('./chunk-PSATR3NL.cjs');
15
+ var _chunkLWBADF3Fcjs = require('./chunk-LWBADF3F.cjs');
16
16
 
17
17
 
18
- var _chunkBIGISYZRcjs = require('./chunk-BIGISYZR.cjs');
18
+ var _chunk34W2JJVDcjs = require('./chunk-34W2JJVD.cjs');
19
19
 
20
20
  // src/langgraph/index.ts
21
21
  var _messages = require('@langchain/core/messages');
@@ -58,12 +58,12 @@ var AlexeinMemory = (_class = class {
58
58
  #client;
59
59
  /** `client` defaults to one made on first use: fail-open unless strict, a 10 s timeout. */
60
60
  constructor(client, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
61
- const given = _chunkPSATR3NLcjs.isClient.call(void 0, client) ? client : void 0;
62
- const settings = _chunkPSATR3NLcjs.isClient.call(void 0, client) ? options : { ...client, ...options };
61
+ const given = _chunkLWBADF3Fcjs.isClient.call(void 0, client) ? client : void 0;
62
+ const settings = _chunkLWBADF3Fcjs.isClient.call(void 0, client) ? options : { ...client, ...options };
63
63
  this.fast = _nullishCoalesce(settings.fast, () => ( false));
64
64
  this.maxChars = _nullishCoalesce(settings.maxChars, () => ( 4e3));
65
65
  this.strict = _nullishCoalesce(settings.strict, () => ( false));
66
- this.#client = new (0, _chunkPSATR3NLcjs.LazyClient)(given, "langgraph", this.strict, settings.timeout);
66
+ this.#client = new (0, _chunkLWBADF3Fcjs.LazyClient)(given, "langgraph", this.strict, settings.timeout);
67
67
  }
68
68
  get client() {
69
69
  return this.#client.client;
@@ -76,7 +76,7 @@ var AlexeinMemory = (_class = class {
76
76
  const asked = _optionalChain([lastHuman, 'call', _16 => _16(state.messages), 'optionalAccess', _17 => _17.text, 'access', _18 => _18.trim, 'call', _19 => _19()]);
77
77
  const user = this.user(config);
78
78
  if (!asked) return { memory: "" };
79
- const found = await _chunkPSATR3NLcjs.searchFor.call(void 0, user, asked, this.fast);
79
+ const found = await _chunkLWBADF3Fcjs.searchFor.call(void 0, user, asked, this.fast);
80
80
  return { memory: _nullishCoalesce(_optionalChain([found, 'optionalAccess', _20 => _20.context, 'call', _21 => _21(this.maxChars)]), () => ( "")) };
81
81
  }}
82
82
  /**
@@ -96,7 +96,7 @@ var AlexeinMemory = (_class = class {
96
96
  return {};
97
97
  }}
98
98
  /** What `recall` found, as a block for your system prompt; empty when it found nothing. */
99
- __init3() {this.prompt = (state) => _chunkPSATR3NLcjs.promptBlock.call(void 0, _nullishCoalesce(state.memory, () => ( "")))}
99
+ __init3() {this.prompt = (state) => _chunkLWBADF3Fcjs.promptBlock.call(void 0, _nullishCoalesce(state.memory, () => ( "")))}
100
100
  /**
101
101
  * Tools the model calls when it decides to: `memory_search` and `memory_open`, and with
102
102
  * `write`, `memory_add`. The user comes from the run, which a model never sees.
@@ -108,8 +108,8 @@ var AlexeinMemory = (_class = class {
108
108
  searchTool() {
109
109
  return _tools.tool.call(void 0,
110
110
  async ({ query }, config) => {
111
- const found = await _chunkPSATR3NLcjs.searchFor.call(void 0, this.user(config), query, this.fast);
112
- return _chunkPSATR3NLcjs.searchAnswer.call(void 0, found, this.maxChars);
111
+ const found = await _chunkLWBADF3Fcjs.searchFor.call(void 0, this.user(config), query, this.fast);
112
+ return _chunkLWBADF3Fcjs.searchAnswer.call(void 0, found, this.maxChars);
113
113
  },
114
114
  {
115
115
  name: "memory_search",
@@ -123,10 +123,10 @@ var AlexeinMemory = (_class = class {
123
123
  async ({ ref }, config) => {
124
124
  const user = this.user(config);
125
125
  try {
126
- return _chunkPSATR3NLcjs.openAnswer.call(void 0, await user.open(ref));
126
+ return _chunkLWBADF3Fcjs.openAnswer.call(void 0, await user.open(ref));
127
127
  } catch (error) {
128
- if (error instanceof _chunkBIGISYZRcjs.NotFoundError) return _chunkPSATR3NLcjs.notFoundAnswer.call(void 0, error);
129
- return _chunkPSATR3NLcjs.outageAnswer.call(void 0, error, this.strict);
128
+ if (error instanceof _chunk34W2JJVDcjs.NotFoundError) return _chunkLWBADF3Fcjs.notFoundAnswer.call(void 0, error);
129
+ return _chunkLWBADF3Fcjs.outageAnswer.call(void 0, error, this.strict);
130
130
  }
131
131
  },
132
132
  {
@@ -143,7 +143,7 @@ var AlexeinMemory = (_class = class {
143
143
  kind: "note",
144
144
  session: threadOf(config)
145
145
  });
146
- return saved.failed ? _chunkPSATR3NLcjs.UNAVAILABLE : _chunkPSATR3NLcjs.SAVED;
146
+ return saved.failed ? _chunkLWBADF3Fcjs.UNAVAILABLE : _chunkLWBADF3Fcjs.SAVED;
147
147
  },
148
148
  {
149
149
  name: "memory_add",
@@ -156,7 +156,7 @@ var AlexeinMemory = (_class = class {
156
156
  async function item(message, role, thread) {
157
157
  const text = _optionalChain([message, 'optionalAccess', _22 => _22.text]);
158
158
  if (!_optionalChain([text, 'optionalAccess', _23 => _23.trim, 'call', _24 => _24()])) return void 0;
159
- const id = await _asyncNullishCoalesce(await _asyncOptionalChain([message, 'optionalAccess', async _25 => _25.id]), async () => ( await _chunkPSATR3NLcjs.stableId.call(void 0, thread, role, text)));
159
+ const id = await _asyncNullishCoalesce(await _asyncOptionalChain([message, 'optionalAccess', async _25 => _25.id]), async () => ( await _chunkLWBADF3Fcjs.stableId.call(void 0, thread, role, text)));
160
160
  return { id, role, text };
161
161
  }
162
162
  var fallback;
@@ -182,4 +182,4 @@ var memoryTools = (options = {}) => defaultMemory().tools(options);
182
182
 
183
183
 
184
184
 
185
- exports.AlexeinMemory = AlexeinMemory; exports.MemoryAnnotation = MemoryAnnotation; exports.MemoryContext = MemoryContext; exports.MemoryState = MemoryState; exports.NOTHING_FOUND = _chunkPSATR3NLcjs.NOTHING_FOUND; exports.NOTHING_YET = _chunkPSATR3NLcjs.NOTHING_YET; exports.UNAVAILABLE = _chunkPSATR3NLcjs.UNAVAILABLE; exports.defaultMemory = defaultMemory; exports.memoryPrompt = memoryPrompt; exports.memoryTools = memoryTools; exports.recall = recall; exports.remember = remember; exports.userIdOf = userIdOf;
185
+ exports.AlexeinMemory = AlexeinMemory; exports.MemoryAnnotation = MemoryAnnotation; exports.MemoryContext = MemoryContext; exports.MemoryState = MemoryState; exports.NOTHING_FOUND = _chunkLWBADF3Fcjs.NOTHING_FOUND; exports.NOTHING_YET = _chunkLWBADF3Fcjs.NOTHING_YET; exports.UNAVAILABLE = _chunkLWBADF3Fcjs.UNAVAILABLE; exports.defaultMemory = defaultMemory; exports.memoryPrompt = memoryPrompt; exports.memoryTools = memoryTools; exports.recall = recall; exports.remember = remember; exports.userIdOf = userIdOf;
@@ -4,7 +4,7 @@ import * as _langchain_langgraph from '@langchain/langgraph';
4
4
  import { StateSchema } from '@langchain/langgraph';
5
5
  import { StructuredToolInterface } from '@langchain/core/tools';
6
6
  import { z } from 'zod';
7
- import { v as Memory } from './client-YKZ4fkK-.cjs';
7
+ import { N as Memory } from './client-Bz10lVYG.cjs';
8
8
  import { I as IntegrationOptions } from './shared-Btg8LbKC.cjs';
9
9
  export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.cjs';
10
10
 
@@ -4,7 +4,7 @@ import * as _langchain_langgraph from '@langchain/langgraph';
4
4
  import { StateSchema } from '@langchain/langgraph';
5
5
  import { StructuredToolInterface } from '@langchain/core/tools';
6
6
  import { z } from 'zod';
7
- import { v as Memory } from './client-YKZ4fkK-.js';
7
+ import { N as Memory } from './client-Bz10lVYG.js';
8
8
  import { I as IntegrationOptions } from './shared-Btg8LbKC.js';
9
9
  export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.js';
10
10
 
package/dist/langgraph.js CHANGED
@@ -12,10 +12,10 @@ import {
12
12
  searchAnswer,
13
13
  searchFor,
14
14
  stableId
15
- } from "./chunk-3LJEU4WL.js";
15
+ } from "./chunk-HDNKPJS2.js";
16
16
  import {
17
17
  NotFoundError
18
- } from "./chunk-DADXKQLZ.js";
18
+ } from "./chunk-5YIOYX3J.js";
19
19
 
20
20
  // src/langgraph/index.ts
21
21
  import { AIMessage, HumanMessage } from "@langchain/core/messages";
@@ -11,13 +11,13 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkPSATR3NLcjs = require('./chunk-PSATR3NL.cjs');
14
+ var _chunkLWBADF3Fcjs = require('./chunk-LWBADF3F.cjs');
15
15
 
16
16
 
17
17
 
18
18
 
19
19
 
20
- var _chunkBIGISYZRcjs = require('./chunk-BIGISYZR.cjs');
20
+ var _chunk34W2JJVDcjs = require('./chunk-34W2JJVD.cjs');
21
21
 
22
22
  // src/openai-agents/run.ts
23
23
  function userIdOf(context) {
@@ -53,7 +53,7 @@ function answer(output) {
53
53
  }
54
54
  async function item(said, role, turn, author) {
55
55
  if (!said.trim()) return void 0;
56
- const id = await _chunkPSATR3NLcjs.stableId.call(void 0, turn, role, said);
56
+ const id = await _chunkLWBADF3Fcjs.stableId.call(void 0, turn, role, said);
57
57
  return { id, role, text: said, ...author ? { author } : {} };
58
58
  }
59
59
  async function turnItems(result, session) {
@@ -73,13 +73,13 @@ var _agents = require('@openai/agents');
73
73
  var _zod = require('zod');
74
74
  function failed(strict) {
75
75
  return (run, error) => {
76
- const yours = error instanceof _chunkBIGISYZRcjs.AuthenticationError || error instanceof _chunkBIGISYZRcjs.PermissionDeniedError;
77
- const outage = error instanceof _chunkBIGISYZRcjs.AlexeinError && error.outage;
76
+ const yours = error instanceof _chunk34W2JJVDcjs.AuthenticationError || error instanceof _chunk34W2JJVDcjs.PermissionDeniedError;
77
+ const outage = error instanceof _chunk34W2JJVDcjs.AlexeinError && error.outage;
78
78
  const noUser = !_optionalChain([run, 'access', _5 => _5.context, 'optionalAccess', _6 => _6.userId]);
79
79
  if (yours || noUser || strict && outage) throw error;
80
80
  if (outage) {
81
81
  console.warn(`Alexein is unavailable: ${error.message}`);
82
- return _chunkPSATR3NLcjs.UNAVAILABLE;
82
+ return _chunkLWBADF3Fcjs.UNAVAILABLE;
83
83
  }
84
84
  return `That did not work: ${error instanceof Error ? error.message : String(error)}`;
85
85
  };
@@ -92,8 +92,8 @@ function buildTools(memory, write) {
92
92
  parameters: _zod.z.object({ query: _zod.z.string().describe("What to look for") }),
93
93
  errorFunction,
94
94
  async execute({ query }, run) {
95
- const found = await _chunkPSATR3NLcjs.searchFor.call(void 0, memory.userOf(_optionalChain([run, 'optionalAccess', _7 => _7.context])), query, memory.fast);
96
- return _chunkPSATR3NLcjs.searchAnswer.call(void 0, found, memory.maxChars);
95
+ const found = await _chunkLWBADF3Fcjs.searchFor.call(void 0, memory.userOf(_optionalChain([run, 'optionalAccess', _7 => _7.context])), query, memory.fast);
96
+ return _chunkLWBADF3Fcjs.searchAnswer.call(void 0, found, memory.maxChars);
97
97
  }
98
98
  });
99
99
  const open = _agents.tool.call(void 0, {
@@ -103,10 +103,10 @@ function buildTools(memory, write) {
103
103
  errorFunction,
104
104
  async execute({ ref }, run) {
105
105
  try {
106
- return _chunkPSATR3NLcjs.openAnswer.call(void 0, await memory.userOf(_optionalChain([run, 'optionalAccess', _8 => _8.context])).open(ref));
106
+ return _chunkLWBADF3Fcjs.openAnswer.call(void 0, await memory.userOf(_optionalChain([run, 'optionalAccess', _8 => _8.context])).open(ref));
107
107
  } catch (error) {
108
- if (!(error instanceof _chunkBIGISYZRcjs.NotFoundError)) throw error;
109
- return _chunkPSATR3NLcjs.notFoundAnswer.call(void 0, error);
108
+ if (!(error instanceof _chunk34W2JJVDcjs.NotFoundError)) throw error;
109
+ return _chunkLWBADF3Fcjs.notFoundAnswer.call(void 0, error);
110
110
  }
111
111
  }
112
112
  });
@@ -120,7 +120,7 @@ function buildTools(memory, write) {
120
120
  kind: "note",
121
121
  session: sessionIdOf(_optionalChain([run, 'optionalAccess', _10 => _10.context]))
122
122
  });
123
- return saved.failed ? _chunkPSATR3NLcjs.UNAVAILABLE : _chunkPSATR3NLcjs.SAVED;
123
+ return saved.failed ? _chunkLWBADF3Fcjs.UNAVAILABLE : _chunkLWBADF3Fcjs.SAVED;
124
124
  }
125
125
  });
126
126
  return write ? [search, open, add] : [search, open];
@@ -149,12 +149,12 @@ var AlexeinMemory = (_class = class {
149
149
  #recalled = /* @__PURE__ */ new WeakMap();
150
150
  /** `client` defaults to one made on first use: fail-open unless strict, a 10 s timeout. */
151
151
  constructor(client, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
152
- const given = _chunkPSATR3NLcjs.isClient.call(void 0, client) ? client : void 0;
153
- const settings = _chunkPSATR3NLcjs.isClient.call(void 0, client) ? options : { ...client, ...options };
152
+ const given = _chunkLWBADF3Fcjs.isClient.call(void 0, client) ? client : void 0;
153
+ const settings = _chunkLWBADF3Fcjs.isClient.call(void 0, client) ? options : { ...client, ...options };
154
154
  this.fast = _nullishCoalesce(settings.fast, () => ( false));
155
155
  this.maxChars = _nullishCoalesce(settings.maxChars, () => ( 4e3));
156
156
  this.strict = _nullishCoalesce(settings.strict, () => ( false));
157
- this.#client = new (0, _chunkPSATR3NLcjs.LazyClient)(given, "openai-agents", this.strict, settings.timeout);
157
+ this.#client = new (0, _chunkLWBADF3Fcjs.LazyClient)(given, "openai-agents", this.strict, settings.timeout);
158
158
  }
159
159
  get client() {
160
160
  return this.#client.client;
@@ -180,8 +180,8 @@ var AlexeinMemory = (_class = class {
180
180
  question = said && textOf(said).trim();
181
181
  }
182
182
  if (question !== void 0) {
183
- const found = question ? await _chunkPSATR3NLcjs.searchFor.call(void 0, user, question, this.fast) : void 0;
184
- this.#recalled.set(run, _chunkPSATR3NLcjs.promptBlock.call(void 0, _nullishCoalesce(_optionalChain([found, 'optionalAccess', _17 => _17.context, 'call', _18 => _18(this.maxChars)]), () => ( ""))));
183
+ const found = question ? await _chunkLWBADF3Fcjs.searchFor.call(void 0, user, question, this.fast) : void 0;
184
+ this.#recalled.set(run, _chunkLWBADF3Fcjs.promptBlock.call(void 0, _nullishCoalesce(_optionalChain([found, 'optionalAccess', _17 => _17.context, 'call', _18 => _18(this.maxChars)]), () => ( ""))));
185
185
  }
186
186
  const block = this.#recalled.get(run);
187
187
  if (!block) return modelData;
@@ -231,4 +231,4 @@ var memoryTools = (options = {}) => defaultMemory().tools(options);
231
231
 
232
232
 
233
233
 
234
- exports.AlexeinMemory = AlexeinMemory; exports.NOTHING_FOUND = _chunkPSATR3NLcjs.NOTHING_FOUND; exports.NOTHING_YET = _chunkPSATR3NLcjs.NOTHING_YET; exports.UNAVAILABLE = _chunkPSATR3NLcjs.UNAVAILABLE; exports.defaultMemory = defaultMemory; exports.memoryTools = memoryTools; exports.recall = recall; exports.remember = remember; exports.sessionIdOf = sessionIdOf; exports.userIdOf = userIdOf;
234
+ exports.AlexeinMemory = AlexeinMemory; exports.NOTHING_FOUND = _chunkLWBADF3Fcjs.NOTHING_FOUND; exports.NOTHING_YET = _chunkLWBADF3Fcjs.NOTHING_YET; exports.UNAVAILABLE = _chunkLWBADF3Fcjs.UNAVAILABLE; exports.defaultMemory = defaultMemory; exports.memoryTools = memoryTools; exports.recall = recall; exports.remember = remember; exports.sessionIdOf = sessionIdOf; exports.userIdOf = userIdOf;
@@ -1,5 +1,5 @@
1
1
  import { AgentInputItem, CallModelInputFilterArgs, ModelInputData, FunctionTool } from '@openai/agents';
2
- import { v as Memory, X as User } from './client-YKZ4fkK-.cjs';
2
+ import { N as Memory, a4 as User } from './client-Bz10lVYG.cjs';
3
3
  import { I as IntegrationOptions } from './shared-Btg8LbKC.cjs';
4
4
  export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.cjs';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { AgentInputItem, CallModelInputFilterArgs, ModelInputData, FunctionTool } from '@openai/agents';
2
- import { v as Memory, X as User } from './client-YKZ4fkK-.js';
2
+ import { N as Memory, a4 as User } from './client-Bz10lVYG.js';
3
3
  import { I as IntegrationOptions } from './shared-Btg8LbKC.js';
4
4
  export { N as NOTHING_FOUND, a as NOTHING_YET, U as UNAVAILABLE } from './shared-Btg8LbKC.js';
5
5
 
@@ -11,13 +11,13 @@ import {
11
11
  searchAnswer,
12
12
  searchFor,
13
13
  stableId
14
- } from "./chunk-3LJEU4WL.js";
14
+ } from "./chunk-HDNKPJS2.js";
15
15
  import {
16
16
  AlexeinError,
17
17
  AuthenticationError,
18
18
  NotFoundError,
19
19
  PermissionDeniedError
20
- } from "./chunk-DADXKQLZ.js";
20
+ } from "./chunk-5YIOYX3J.js";
21
21
 
22
22
  // src/openai-agents/run.ts
23
23
  function userIdOf(context) {